*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
b6ba6518 2@c Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
7d51c7de 3@c 1999, 2000, 2001, 2002, 2003, 2004, 2005
c906108c
SS
4@c Free Software Foundation, Inc.
5@c
5d161b24 6@c %**start of header
c906108c
SS
7@c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
8@c of @set vars. However, you can override filename with makeinfo -o.
9@setfilename gdb.info
10@c
11@include gdb-cfg.texi
12@c
c906108c 13@settitle Debugging with @value{GDBN}
c906108c
SS
14@setchapternewpage odd
15@c %**end of header
16
17@iftex
18@c @smallbook
19@c @cropmarks
20@end iftex
21
22@finalout
23@syncodeindex ky cp
24
41afff9a 25@c readline appendices use @vindex, @findex and @ftable,
48e934c6 26@c annotate.texi and gdbmi use @findex.
c906108c 27@syncodeindex vr cp
41afff9a 28@syncodeindex fn cp
c906108c
SS
29
30@c !!set GDB manual's edition---not the same as GDB version!
9fe8321b 31@c This is updated by GNU Press.
e9c75b65 32@set EDITION Ninth
c906108c 33
87885426
FN
34@c !!set GDB edit command default editor
35@set EDITOR /bin/ex
c906108c 36
6c0e9fb3 37@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
c906108c 38
c906108c 39@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 40@c manuals to an info tree.
03727ca6 41@dircategory Software development
96a2c332 42@direntry
03727ca6 43* Gdb: (gdb). The GNU debugger.
96a2c332
SS
44@end direntry
45
c906108c
SS
46@ifinfo
47This file documents the @sc{gnu} debugger @value{GDBN}.
48
49
9fe8321b
AC
50This is the @value{EDITION} Edition, of @cite{Debugging with
51@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
52Version @value{GDBVN}.
c906108c 53
8a037dd7 54Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,@*
7d51c7de
BR
55 1999, 2000, 2001, 2002, 2003, 2004, 2005@*
56 Free Software Foundation, Inc.
c906108c 57
e9c75b65
EZ
58Permission is granted to copy, distribute and/or modify this document
59under the terms of the GNU Free Documentation License, Version 1.1 or
60any later version published by the Free Software Foundation; with the
959acfd1
EZ
61Invariant Sections being ``Free Software'' and ``Free Software Needs
62Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
63and with the Back-Cover Texts as in (a) below.
c906108c 64
6826cf00
EZ
65(a) The Free Software Foundation's Back-Cover Text is: ``You have
66freedom to copy and modify this GNU Manual, like GNU software. Copies
67published by the Free Software Foundation raise funds for GNU
68development.''
c906108c
SS
69@end ifinfo
70
71@titlepage
72@title Debugging with @value{GDBN}
73@subtitle The @sc{gnu} Source-Level Debugger
c906108c 74@sp 1
c906108c 75@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
9e9c5ae7 76@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 77@page
c906108c
SS
78@tex
79{\parskip=0pt
53a5351d 80\hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
c906108c
SS
81\hfill {\it Debugging with @value{GDBN}}\par
82\hfill \TeX{}info \texinfoversion\par
83}
84@end tex
53a5351d 85
c906108c 86@vskip 0pt plus 1filll
8a037dd7 87Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
7d51c7de
BR
881996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
89Free Software Foundation, Inc.
c906108c 90@sp 2
c906108c
SS
91Published by the Free Software Foundation @*
9259 Temple Place - Suite 330, @*
93Boston, MA 02111-1307 USA @*
6d2ebf8b 94ISBN 1-882114-77-9 @*
e9c75b65
EZ
95
96Permission is granted to copy, distribute and/or modify this document
97under the terms of the GNU Free Documentation License, Version 1.1 or
98any later version published by the Free Software Foundation; with the
959acfd1
EZ
99Invariant Sections being ``Free Software'' and ``Free Software Needs
100Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
101and with the Back-Cover Texts as in (a) below.
e9c75b65 102
6826cf00
EZ
103(a) The Free Software Foundation's Back-Cover Text is: ``You have
104freedom to copy and modify this GNU Manual, like GNU software. Copies
105published by the Free Software Foundation raise funds for GNU
106development.''
c906108c
SS
107@end titlepage
108@page
109
6c0e9fb3 110@ifnottex
6d2ebf8b
SS
111@node Top, Summary, (dir), (dir)
112
c906108c
SS
113@top Debugging with @value{GDBN}
114
115This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
9fe8321b 117This is the @value{EDITION} Edition, for @value{GDBN} Version
c906108c
SS
118@value{GDBVN}.
119
7d51c7de 120Copyright (C) 1988-2005 Free Software Foundation, Inc.
6d2ebf8b
SS
121
122@menu
123* Summary:: Summary of @value{GDBN}
124* Sample Session:: A sample @value{GDBN} session
125
126* Invocation:: Getting in and out of @value{GDBN}
127* Commands:: @value{GDBN} commands
128* Running:: Running programs under @value{GDBN}
129* Stopping:: Stopping and continuing
130* Stack:: Examining the stack
131* Source:: Examining source files
132* Data:: Examining data
e2e0bcd1 133* Macros:: Preprocessor Macros
b37052ae 134* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 135* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
136
137* Languages:: Using @value{GDBN} with different languages
138
139* Symbols:: Examining the symbol table
140* Altering:: Altering execution
141* GDB Files:: @value{GDBN} files
142* Targets:: Specifying a debugging target
6b2f586d 143* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
144* Configurations:: Configuration-specific information
145* Controlling GDB:: Controlling @value{GDBN}
146* Sequences:: Canned sequences of commands
c4555f82 147* TUI:: @value{GDBN} Text User Interface
21c294e6 148* Interpreters:: Command Interpreters
6d2ebf8b
SS
149* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
150* Annotations:: @value{GDBN}'s annotation interface.
7162c0ca 151* GDB/MI:: @value{GDBN}'s Machine Interface.
6d2ebf8b
SS
152
153* GDB Bugs:: Reporting bugs in @value{GDBN}
154* Formatting Documentation:: How to format and print @value{GDBN} documentation
155
156* Command Line Editing:: Command Line Editing
157* Using History Interactively:: Using History Interactively
158* Installing GDB:: Installing GDB
eb12ee30 159* Maintenance Commands:: Maintenance Commands
e0ce93ac 160* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 161* Agent Expressions:: The GDB Agent Expression Mechanism
aab4e0ec
AC
162* Copying:: GNU General Public License says
163 how you can copy and share GDB
6826cf00 164* GNU Free Documentation License:: The license for this documentation
6d2ebf8b
SS
165* Index:: Index
166@end menu
167
6c0e9fb3 168@end ifnottex
c906108c 169
449f3b6c 170@contents
449f3b6c 171
6d2ebf8b 172@node Summary
c906108c
SS
173@unnumbered Summary of @value{GDBN}
174
175The purpose of a debugger such as @value{GDBN} is to allow you to see what is
176going on ``inside'' another program while it executes---or what another
177program was doing at the moment it crashed.
178
179@value{GDBN} can do four main kinds of things (plus other things in support of
180these) to help you catch bugs in the act:
181
182@itemize @bullet
183@item
184Start your program, specifying anything that might affect its behavior.
185
186@item
187Make your program stop on specified conditions.
188
189@item
190Examine what has happened, when your program has stopped.
191
192@item
193Change things in your program, so you can experiment with correcting the
194effects of one bug and go on to learn about another.
195@end itemize
196
49efadf5 197You can use @value{GDBN} to debug programs written in C and C@t{++}.
9c16f35a 198For more information, see @ref{Supported languages,,Supported languages}.
c906108c
SS
199For more information, see @ref{C,,C and C++}.
200
cce74817 201@cindex Modula-2
e632838e
AC
202Support for Modula-2 is partial. For information on Modula-2, see
203@ref{Modula-2,,Modula-2}.
c906108c 204
cce74817
JM
205@cindex Pascal
206Debugging Pascal programs which use sets, subranges, file variables, or
207nested functions does not currently work. @value{GDBN} does not support
208entering expressions, printing values, or similar features using Pascal
209syntax.
c906108c 210
c906108c
SS
211@cindex Fortran
212@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 213it may be necessary to refer to some variables with a trailing
cce74817 214underscore.
c906108c 215
b37303ee
AF
216@value{GDBN} can be used to debug programs written in Objective-C,
217using either the Apple/NeXT or the GNU Objective-C runtime.
218
c906108c
SS
219@menu
220* Free Software:: Freely redistributable software
221* Contributors:: Contributors to GDB
222@end menu
223
6d2ebf8b 224@node Free Software
c906108c
SS
225@unnumberedsec Free software
226
5d161b24 227@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
228General Public License
229(GPL). The GPL gives you the freedom to copy or adapt a licensed
230program---but every person getting a copy also gets with it the
231freedom to modify that copy (which means that they must get access to
232the source code), and the freedom to distribute further copies.
233Typical software companies use copyrights to limit your freedoms; the
234Free Software Foundation uses the GPL to preserve these freedoms.
235
236Fundamentally, the General Public License is a license which says that
237you have these freedoms and that you cannot take these freedoms away
238from anyone else.
239
2666264b 240@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
241
242The biggest deficiency in the free software community today is not in
243the software---it is the lack of good free documentation that we can
244include with the free software. Many of our most important
245programs do not come with free reference manuals and free introductory
246texts. Documentation is an essential part of any software package;
247when an important free software package does not come with a free
248manual and a free tutorial, that is a major gap. We have many such
249gaps today.
250
251Consider Perl, for instance. The tutorial manuals that people
252normally use are non-free. How did this come about? Because the
253authors of those manuals published them with restrictive terms---no
254copying, no modification, source files not available---which exclude
255them from the free software world.
256
257That wasn't the first time this sort of thing happened, and it was far
258from the last. Many times we have heard a GNU user eagerly describe a
259manual that he is writing, his intended contribution to the community,
260only to learn that he had ruined everything by signing a publication
261contract to make it non-free.
262
263Free documentation, like free software, is a matter of freedom, not
264price. The problem with the non-free manual is not that publishers
265charge a price for printed copies---that in itself is fine. (The Free
266Software Foundation sells printed copies of manuals, too.) The
267problem is the restrictions on the use of the manual. Free manuals
268are available in source code form, and give you permission to copy and
269modify. Non-free manuals do not allow this.
270
271The criteria of freedom for a free manual are roughly the same as for
272free software. Redistribution (including the normal kinds of
273commercial redistribution) must be permitted, so that the manual can
274accompany every copy of the program, both on-line and on paper.
275
276Permission for modification of the technical content is crucial too.
277When people modify the software, adding or changing features, if they
278are conscientious they will change the manual too---so they can
279provide accurate and clear documentation for the modified program. A
280manual that leaves you no choice but to write a new manual to document
281a changed version of the program is not really available to our
282community.
283
284Some kinds of limits on the way modification is handled are
285acceptable. For example, requirements to preserve the original
286author's copyright notice, the distribution terms, or the list of
287authors, are ok. It is also no problem to require modified versions
288to include notice that they were modified. Even entire sections that
289may not be deleted or changed are acceptable, as long as they deal
290with nontechnical topics (like this one). These kinds of restrictions
291are acceptable because they don't obstruct the community's normal use
292of the manual.
293
294However, it must be possible to modify all the @emph{technical}
295content of the manual, and then distribute the result in all the usual
296media, through all the usual channels. Otherwise, the restrictions
297obstruct the use of the manual, it is not free, and we need another
298manual to replace it.
299
300Please spread the word about this issue. Our community continues to
301lose manuals to proprietary publishing. If we spread the word that
302free software needs free reference manuals and free tutorials, perhaps
303the next person who wants to contribute by writing documentation will
304realize, before it is too late, that only free manuals contribute to
305the free software community.
306
307If you are writing documentation, please insist on publishing it under
308the GNU Free Documentation License or another free documentation
309license. Remember that this decision requires your approval---you
310don't have to let the publisher decide. Some commercial publishers
311will use a free license if you insist, but they will not propose the
312option; it is up to you to raise the issue and say firmly that this is
313what you want. If the publisher you are dealing with refuses, please
314try other publishers. If you're not sure whether a proposed license
42584a72 315is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
316
317You can encourage commercial publishers to sell more free, copylefted
318manuals and tutorials by buying them, and particularly by buying
319copies from the publishers that paid for their writing or for major
320improvements. Meanwhile, try to avoid buying non-free documentation
321at all. Check the distribution terms of a manual before you buy it,
322and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
323Check the history of the book, and try to reward the publishers that
324have paid or pay the authors to work on it.
959acfd1
EZ
325
326The Free Software Foundation maintains a list of free documentation
327published by other publishers, at
328@url{http://www.fsf.org/doc/other-free-books.html}.
329
6d2ebf8b 330@node Contributors
96a2c332
SS
331@unnumberedsec Contributors to @value{GDBN}
332
333Richard Stallman was the original author of @value{GDBN}, and of many
334other @sc{gnu} programs. Many others have contributed to its
335development. This section attempts to credit major contributors. One
336of the virtues of free software is that everyone is free to contribute
337to it; with regret, we cannot actually acknowledge everyone here. The
338file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
339blow-by-blow account.
340
341Changes much prior to version 2.0 are lost in the mists of time.
342
343@quotation
344@emph{Plea:} Additions to this section are particularly welcome. If you
345or your friends (or enemies, to be evenhanded) have been unfairly
346omitted from this list, we would like to add your names!
347@end quotation
348
349So that they may not regard their many labors as thankless, we
350particularly thank those who shepherded @value{GDBN} through major
351releases:
faae5abe 352Andrew Cagney (releases 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
353Jim Blandy (release 4.18);
354Jason Molenda (release 4.17);
355Stan Shebs (release 4.14);
356Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
357Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
358John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
359Jim Kingdon (releases 3.5, 3.4, and 3.3);
360and Randy Smith (releases 3.2, 3.1, and 3.0).
361
362Richard Stallman, assisted at various times by Peter TerMaat, Chris
363Hanson, and Richard Mlynarik, handled releases through 2.8.
364
b37052ae
EZ
365Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
366in @value{GDBN}, with significant additional contributions from Per
367Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
368demangler. Early work on C@t{++} was by Peter TerMaat (who also did
369much general update work leading to release 3.0).
c906108c 370
b37052ae 371@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
372object-file formats; BFD was a joint project of David V.
373Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
374
375David Johnson wrote the original COFF support; Pace Willison did
376the original support for encapsulated COFF.
377
0179ffac 378Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
379
380Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
381Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
382support.
383Jean-Daniel Fekete contributed Sun 386i support.
384Chris Hanson improved the HP9000 support.
385Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
386David Johnson contributed Encore Umax support.
387Jyrki Kuoppala contributed Altos 3068 support.
388Jeff Law contributed HP PA and SOM support.
389Keith Packard contributed NS32K support.
390Doug Rabson contributed Acorn Risc Machine support.
391Bob Rusk contributed Harris Nighthawk CX-UX support.
392Chris Smith contributed Convex support (and Fortran debugging).
393Jonathan Stone contributed Pyramid support.
394Michael Tiemann contributed SPARC support.
395Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
396Pace Willison contributed Intel 386 support.
397Jay Vosburgh contributed Symmetry support.
a37295f9 398Marko Mlinar contributed OpenRISC 1000 support.
c906108c 399
1104b9e7 400Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
401
402Rich Schaefer and Peter Schauer helped with support of SunOS shared
403libraries.
404
405Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
406about several machine instruction sets.
407
408Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
409remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
410contributed remote debugging modules for the i960, VxWorks, A29K UDI,
411and RDI targets, respectively.
412
413Brian Fox is the author of the readline libraries providing
414command-line editing and command history.
415
7a292a7a
SS
416Andrew Beers of SUNY Buffalo wrote the language-switching code, the
417Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 418
5d161b24 419Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 420He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 421symbols.
c906108c 422
f24c5e49
KI
423Hitachi America (now Renesas America), Ltd. sponsored the support for
424H8/300, H8/500, and Super-H processors.
c906108c
SS
425
426NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
427
f24c5e49
KI
428Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
429processors.
c906108c
SS
430
431Toshiba sponsored the support for the TX39 Mips processor.
432
433Matsushita sponsored the support for the MN10200 and MN10300 processors.
434
96a2c332 435Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
436
437Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
438watchpoints.
439
440Michael Snyder added support for tracepoints.
441
442Stu Grossman wrote gdbserver.
443
444Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 445nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
446
447The following people at the Hewlett-Packard Company contributed
448support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 449(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
d0d5df6f
AC
450compiler, and the Text User Interface (nee Terminal User Interface):
451Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
452Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
453provided HP-specific information in this manual.
c906108c 454
b37052ae
EZ
455DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
456Robert Hoehne made significant contributions to the DJGPP port.
457
96a2c332
SS
458Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
459development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
460fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
461Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
462Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
463Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
464Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
465addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
466JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
467Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
468Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
469Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
470Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
471Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
472Zuhn have made contributions both large and small.
c906108c 473
ffed4509
AC
474Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
475Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
476
e2e0bcd1
JB
477Jim Blandy added support for preprocessor macros, while working for Red
478Hat.
c906108c 479
a9967aef
AC
480Andrew Cagney designed @value{GDBN}'s architecture vector. Many
481people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
482Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
483Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
484Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
485with the migration of old architectures to this new framework.
486
6d2ebf8b 487@node Sample Session
c906108c
SS
488@chapter A Sample @value{GDBN} Session
489
490You can use this manual at your leisure to read all about @value{GDBN}.
491However, a handful of commands are enough to get started using the
492debugger. This chapter illustrates those commands.
493
494@iftex
495In this sample session, we emphasize user input like this: @b{input},
496to make it easier to pick out from the surrounding output.
497@end iftex
498
499@c FIXME: this example may not be appropriate for some configs, where
500@c FIXME...primary interest is in remote use.
501
502One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
503processor) exhibits the following bug: sometimes, when we change its
504quote strings from the default, the commands used to capture one macro
505definition within another stop working. In the following short @code{m4}
506session, we define a macro @code{foo} which expands to @code{0000}; we
507then use the @code{m4} built-in @code{defn} to define @code{bar} as the
508same thing. However, when we change the open quote string to
509@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
510procedure fails to define a new synonym @code{baz}:
511
512@smallexample
513$ @b{cd gnu/m4}
514$ @b{./m4}
515@b{define(foo,0000)}
516
517@b{foo}
5180000
519@b{define(bar,defn(`foo'))}
520
521@b{bar}
5220000
523@b{changequote(<QUOTE>,<UNQUOTE>)}
524
525@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
526@b{baz}
527@b{C-d}
528m4: End of input: 0: fatal error: EOF in string
529@end smallexample
530
531@noindent
532Let us use @value{GDBN} to try to see what is going on.
533
c906108c
SS
534@smallexample
535$ @b{@value{GDBP} m4}
536@c FIXME: this falsifies the exact text played out, to permit smallbook
537@c FIXME... format to come out better.
538@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 539 of it under certain conditions; type "show copying" to see
c906108c 540 the conditions.
5d161b24 541There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
542 for details.
543
544@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
545(@value{GDBP})
546@end smallexample
c906108c
SS
547
548@noindent
549@value{GDBN} reads only enough symbol data to know where to find the
550rest when needed; as a result, the first prompt comes up very quickly.
551We now tell @value{GDBN} to use a narrower display width than usual, so
552that examples fit in this manual.
553
554@smallexample
555(@value{GDBP}) @b{set width 70}
556@end smallexample
557
558@noindent
559We need to see how the @code{m4} built-in @code{changequote} works.
560Having looked at the source, we know the relevant subroutine is
561@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
562@code{break} command.
563
564@smallexample
565(@value{GDBP}) @b{break m4_changequote}
566Breakpoint 1 at 0x62f4: file builtin.c, line 879.
567@end smallexample
568
569@noindent
570Using the @code{run} command, we start @code{m4} running under @value{GDBN}
571control; as long as control does not reach the @code{m4_changequote}
572subroutine, the program runs as usual:
573
574@smallexample
575(@value{GDBP}) @b{run}
576Starting program: /work/Editorial/gdb/gnu/m4/m4
577@b{define(foo,0000)}
578
579@b{foo}
5800000
581@end smallexample
582
583@noindent
584To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
585suspends execution of @code{m4}, displaying information about the
586context where it stops.
587
588@smallexample
589@b{changequote(<QUOTE>,<UNQUOTE>)}
590
5d161b24 591Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
592 at builtin.c:879
593879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
594@end smallexample
595
596@noindent
597Now we use the command @code{n} (@code{next}) to advance execution to
598the next line of the current function.
599
600@smallexample
601(@value{GDBP}) @b{n}
602882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
603 : nil,
604@end smallexample
605
606@noindent
607@code{set_quotes} looks like a promising subroutine. We can go into it
608by using the command @code{s} (@code{step}) instead of @code{next}.
609@code{step} goes to the next line to be executed in @emph{any}
610subroutine, so it steps into @code{set_quotes}.
611
612@smallexample
613(@value{GDBP}) @b{s}
614set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
615 at input.c:530
616530 if (lquote != def_lquote)
617@end smallexample
618
619@noindent
620The display that shows the subroutine where @code{m4} is now
621suspended (and its arguments) is called a stack frame display. It
622shows a summary of the stack. We can use the @code{backtrace}
623command (which can also be spelled @code{bt}), to see where we are
624in the stack as a whole: the @code{backtrace} command displays a
625stack frame for each active subroutine.
626
627@smallexample
628(@value{GDBP}) @b{bt}
629#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
630 at input.c:530
5d161b24 631#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
632 at builtin.c:882
633#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
634#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
635 at macro.c:71
636#4 0x79dc in expand_input () at macro.c:40
637#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
638@end smallexample
639
640@noindent
641We step through a few more lines to see what happens. The first two
642times, we can use @samp{s}; the next two times we use @code{n} to avoid
643falling into the @code{xstrdup} subroutine.
644
645@smallexample
646(@value{GDBP}) @b{s}
6470x3b5c 532 if (rquote != def_rquote)
648(@value{GDBP}) @b{s}
6490x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
650def_lquote : xstrdup(lq);
651(@value{GDBP}) @b{n}
652536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
653 : xstrdup(rq);
654(@value{GDBP}) @b{n}
655538 len_lquote = strlen(rquote);
656@end smallexample
657
658@noindent
659The last line displayed looks a little odd; we can examine the variables
660@code{lquote} and @code{rquote} to see if they are in fact the new left
661and right quotes we specified. We use the command @code{p}
662(@code{print}) to see their values.
663
664@smallexample
665(@value{GDBP}) @b{p lquote}
666$1 = 0x35d40 "<QUOTE>"
667(@value{GDBP}) @b{p rquote}
668$2 = 0x35d50 "<UNQUOTE>"
669@end smallexample
670
671@noindent
672@code{lquote} and @code{rquote} are indeed the new left and right quotes.
673To look at some context, we can display ten lines of source
674surrounding the current line with the @code{l} (@code{list}) command.
675
676@smallexample
677(@value{GDBP}) @b{l}
678533 xfree(rquote);
679534
680535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
681 : xstrdup (lq);
682536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
683 : xstrdup (rq);
684537
685538 len_lquote = strlen(rquote);
686539 len_rquote = strlen(lquote);
687540 @}
688541
689542 void
690@end smallexample
691
692@noindent
693Let us step past the two lines that set @code{len_lquote} and
694@code{len_rquote}, and then examine the values of those variables.
695
696@smallexample
697(@value{GDBP}) @b{n}
698539 len_rquote = strlen(lquote);
699(@value{GDBP}) @b{n}
700540 @}
701(@value{GDBP}) @b{p len_lquote}
702$3 = 9
703(@value{GDBP}) @b{p len_rquote}
704$4 = 7
705@end smallexample
706
707@noindent
708That certainly looks wrong, assuming @code{len_lquote} and
709@code{len_rquote} are meant to be the lengths of @code{lquote} and
710@code{rquote} respectively. We can set them to better values using
711the @code{p} command, since it can print the value of
712any expression---and that expression can include subroutine calls and
713assignments.
714
715@smallexample
716(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
717$5 = 7
718(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
719$6 = 9
720@end smallexample
721
722@noindent
723Is that enough to fix the problem of using the new quotes with the
724@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
725executing with the @code{c} (@code{continue}) command, and then try the
726example that caused trouble initially:
727
728@smallexample
729(@value{GDBP}) @b{c}
730Continuing.
731
732@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
733
734baz
7350000
736@end smallexample
737
738@noindent
739Success! The new quotes now work just as well as the default ones. The
740problem seems to have been just the two typos defining the wrong
741lengths. We allow @code{m4} exit by giving it an EOF as input:
742
743@smallexample
744@b{C-d}
745Program exited normally.
746@end smallexample
747
748@noindent
749The message @samp{Program exited normally.} is from @value{GDBN}; it
750indicates @code{m4} has finished executing. We can end our @value{GDBN}
751session with the @value{GDBN} @code{quit} command.
752
753@smallexample
754(@value{GDBP}) @b{quit}
755@end smallexample
c906108c 756
6d2ebf8b 757@node Invocation
c906108c
SS
758@chapter Getting In and Out of @value{GDBN}
759
760This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 761The essentials are:
c906108c 762@itemize @bullet
5d161b24 763@item
53a5351d 764type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 765@item
c906108c
SS
766type @kbd{quit} or @kbd{C-d} to exit.
767@end itemize
768
769@menu
770* Invoking GDB:: How to start @value{GDBN}
771* Quitting GDB:: How to quit @value{GDBN}
772* Shell Commands:: How to use shell commands inside @value{GDBN}
0fac0b41 773* Logging output:: How to log @value{GDBN}'s output to a file
c906108c
SS
774@end menu
775
6d2ebf8b 776@node Invoking GDB
c906108c
SS
777@section Invoking @value{GDBN}
778
c906108c
SS
779Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
780@value{GDBN} reads commands from the terminal until you tell it to exit.
781
782You can also run @code{@value{GDBP}} with a variety of arguments and options,
783to specify more of your debugging environment at the outset.
784
c906108c
SS
785The command-line options described here are designed
786to cover a variety of situations; in some environments, some of these
5d161b24 787options may effectively be unavailable.
c906108c
SS
788
789The most usual way to start @value{GDBN} is with one argument,
790specifying an executable program:
791
474c8240 792@smallexample
c906108c 793@value{GDBP} @var{program}
474c8240 794@end smallexample
c906108c 795
c906108c
SS
796@noindent
797You can also start with both an executable program and a core file
798specified:
799
474c8240 800@smallexample
c906108c 801@value{GDBP} @var{program} @var{core}
474c8240 802@end smallexample
c906108c
SS
803
804You can, instead, specify a process ID as a second argument, if you want
805to debug a running process:
806
474c8240 807@smallexample
c906108c 808@value{GDBP} @var{program} 1234
474c8240 809@end smallexample
c906108c
SS
810
811@noindent
812would attach @value{GDBN} to process @code{1234} (unless you also have a file
813named @file{1234}; @value{GDBN} does check for a core file first).
814
c906108c 815Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
816complete operating system; when you use @value{GDBN} as a remote
817debugger attached to a bare board, there may not be any notion of
818``process'', and there is often no way to get a core dump. @value{GDBN}
819will warn you if it is unable to attach or to read core dumps.
c906108c 820
aa26fa3a
TT
821You can optionally have @code{@value{GDBP}} pass any arguments after the
822executable file to the inferior using @code{--args}. This option stops
823option processing.
474c8240 824@smallexample
aa26fa3a 825gdb --args gcc -O2 -c foo.c
474c8240 826@end smallexample
aa26fa3a
TT
827This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
828@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
829
96a2c332 830You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
831@value{GDBN}'s non-warranty, by specifying @code{-silent}:
832
833@smallexample
834@value{GDBP} -silent
835@end smallexample
836
837@noindent
838You can further control how @value{GDBN} starts up by using command-line
839options. @value{GDBN} itself can remind you of the options available.
840
841@noindent
842Type
843
474c8240 844@smallexample
c906108c 845@value{GDBP} -help
474c8240 846@end smallexample
c906108c
SS
847
848@noindent
849to display all available options and briefly describe their use
850(@samp{@value{GDBP} -h} is a shorter equivalent).
851
852All options and command line arguments you give are processed
853in sequential order. The order makes a difference when the
854@samp{-x} option is used.
855
856
857@menu
c906108c
SS
858* File Options:: Choosing files
859* Mode Options:: Choosing modes
6fc08d32 860* Startup:: What @value{GDBN} does during startup
c906108c
SS
861@end menu
862
6d2ebf8b 863@node File Options
c906108c
SS
864@subsection Choosing files
865
2df3850c 866When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
867specifying an executable file and core file (or process ID). This is
868the same as if the arguments were specified by the @samp{-se} and
19837790
MS
869@samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
870first argument that does not have an associated option flag as
871equivalent to the @samp{-se} option followed by that argument; and the
872second argument that does not have an associated option flag, if any, as
873equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
874If the second argument begins with a decimal digit, @value{GDBN} will
875first attempt to attach to it as a process, and if that fails, attempt
876to open it as a corefile. If you have a corefile whose name begins with
b383017d 877a digit, you can prevent @value{GDBN} from treating it as a pid by
79f12247 878prefixing it with @file{./}, eg. @file{./12345}.
7a292a7a
SS
879
880If @value{GDBN} has not been configured to included core file support,
881such as for most embedded targets, then it will complain about a second
882argument and ignore it.
c906108c
SS
883
884Many options have both long and short forms; both are shown in the
885following list. @value{GDBN} also recognizes the long forms if you truncate
886them, so long as enough of the option is present to be unambiguous.
887(If you prefer, you can flag option arguments with @samp{--} rather
888than @samp{-}, though we illustrate the more usual convention.)
889
d700128c
EZ
890@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
891@c way, both those who look for -foo and --foo in the index, will find
892@c it.
893
c906108c
SS
894@table @code
895@item -symbols @var{file}
896@itemx -s @var{file}
d700128c
EZ
897@cindex @code{--symbols}
898@cindex @code{-s}
c906108c
SS
899Read symbol table from file @var{file}.
900
901@item -exec @var{file}
902@itemx -e @var{file}
d700128c
EZ
903@cindex @code{--exec}
904@cindex @code{-e}
7a292a7a
SS
905Use file @var{file} as the executable file to execute when appropriate,
906and for examining pure data in conjunction with a core dump.
c906108c
SS
907
908@item -se @var{file}
d700128c 909@cindex @code{--se}
c906108c
SS
910Read symbol table from file @var{file} and use it as the executable
911file.
912
c906108c
SS
913@item -core @var{file}
914@itemx -c @var{file}
d700128c
EZ
915@cindex @code{--core}
916@cindex @code{-c}
b383017d 917Use file @var{file} as a core dump to examine.
c906108c
SS
918
919@item -c @var{number}
19837790
MS
920@item -pid @var{number}
921@itemx -p @var{number}
922@cindex @code{--pid}
923@cindex @code{-p}
924Connect to process ID @var{number}, as with the @code{attach} command.
925If there is no such process, @value{GDBN} will attempt to open a core
926file named @var{number}.
c906108c
SS
927
928@item -command @var{file}
929@itemx -x @var{file}
d700128c
EZ
930@cindex @code{--command}
931@cindex @code{-x}
c906108c
SS
932Execute @value{GDBN} commands from file @var{file}. @xref{Command
933Files,, Command files}.
934
935@item -directory @var{directory}
936@itemx -d @var{directory}
d700128c
EZ
937@cindex @code{--directory}
938@cindex @code{-d}
c906108c
SS
939Add @var{directory} to the path to search for source files.
940
c906108c
SS
941@item -m
942@itemx -mapped
d700128c
EZ
943@cindex @code{--mapped}
944@cindex @code{-m}
c906108c
SS
945@emph{Warning: this option depends on operating system facilities that are not
946supported on all systems.}@*
947If memory-mapped files are available on your system through the @code{mmap}
5d161b24 948system call, you can use this option
c906108c
SS
949to have @value{GDBN} write the symbols from your
950program into a reusable file in the current directory. If the program you are debugging is
96a2c332 951called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
c906108c
SS
952Future @value{GDBN} debugging sessions notice the presence of this file,
953and can quickly map in symbol information from it, rather than reading
954the symbol table from the executable program.
955
956The @file{.syms} file is specific to the host machine where @value{GDBN}
957is run. It holds an exact image of the internal @value{GDBN} symbol
958table. It cannot be shared across multiple host platforms.
c906108c 959
c906108c
SS
960@item -r
961@itemx -readnow
d700128c
EZ
962@cindex @code{--readnow}
963@cindex @code{-r}
c906108c
SS
964Read each symbol file's entire symbol table immediately, rather than
965the default, which is to read it incrementally as it is needed.
966This makes startup slower, but makes future operations faster.
53a5351d 967
c906108c
SS
968@end table
969
2df3850c 970You typically combine the @code{-mapped} and @code{-readnow} options in
c906108c 971order to build a @file{.syms} file that contains complete symbol
2df3850c
JM
972information. (@xref{Files,,Commands to specify files}, for information
973on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
974but build a @file{.syms} file for future use is:
c906108c 975
474c8240 976@smallexample
2df3850c 977gdb -batch -nx -mapped -readnow programname
474c8240 978@end smallexample
c906108c 979
6d2ebf8b 980@node Mode Options
c906108c
SS
981@subsection Choosing modes
982
983You can run @value{GDBN} in various alternative modes---for example, in
984batch mode or quiet mode.
985
986@table @code
987@item -nx
988@itemx -n
d700128c
EZ
989@cindex @code{--nx}
990@cindex @code{-n}
96565e91 991Do not execute commands found in any initialization files. Normally,
2df3850c
JM
992@value{GDBN} executes the commands in these files after all the command
993options and arguments have been processed. @xref{Command Files,,Command
994files}.
c906108c
SS
995
996@item -quiet
d700128c 997@itemx -silent
c906108c 998@itemx -q
d700128c
EZ
999@cindex @code{--quiet}
1000@cindex @code{--silent}
1001@cindex @code{-q}
c906108c
SS
1002``Quiet''. Do not print the introductory and copyright messages. These
1003messages are also suppressed in batch mode.
1004
1005@item -batch
d700128c 1006@cindex @code{--batch}
c906108c
SS
1007Run in batch mode. Exit with status @code{0} after processing all the
1008command files specified with @samp{-x} (and all commands from
1009initialization files, if not inhibited with @samp{-n}). Exit with
1010nonzero status if an error occurs in executing the @value{GDBN} commands
1011in the command files.
1012
2df3850c
JM
1013Batch mode may be useful for running @value{GDBN} as a filter, for
1014example to download and run a program on another computer; in order to
1015make this more useful, the message
c906108c 1016
474c8240 1017@smallexample
c906108c 1018Program exited normally.
474c8240 1019@end smallexample
c906108c
SS
1020
1021@noindent
2df3850c
JM
1022(which is ordinarily issued whenever a program running under
1023@value{GDBN} control terminates) is not issued when running in batch
1024mode.
1025
1026@item -nowindows
1027@itemx -nw
d700128c
EZ
1028@cindex @code{--nowindows}
1029@cindex @code{-nw}
2df3850c 1030``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1031(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1032interface. If no GUI is available, this option has no effect.
1033
1034@item -windows
1035@itemx -w
d700128c
EZ
1036@cindex @code{--windows}
1037@cindex @code{-w}
2df3850c
JM
1038If @value{GDBN} includes a GUI, then this option requires it to be
1039used if possible.
c906108c
SS
1040
1041@item -cd @var{directory}
d700128c 1042@cindex @code{--cd}
c906108c
SS
1043Run @value{GDBN} using @var{directory} as its working directory,
1044instead of the current directory.
1045
c906108c
SS
1046@item -fullname
1047@itemx -f
d700128c
EZ
1048@cindex @code{--fullname}
1049@cindex @code{-f}
7a292a7a
SS
1050@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1051subprocess. It tells @value{GDBN} to output the full file name and line
1052number in a standard, recognizable fashion each time a stack frame is
1053displayed (which includes each time your program stops). This
1054recognizable format looks like two @samp{\032} characters, followed by
1055the file name, line number and character position separated by colons,
1056and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1057@samp{\032} characters as a signal to display the source code for the
1058frame.
c906108c 1059
d700128c
EZ
1060@item -epoch
1061@cindex @code{--epoch}
1062The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1063@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1064routines so as to allow Epoch to display values of expressions in a
1065separate window.
1066
1067@item -annotate @var{level}
1068@cindex @code{--annotate}
1069This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1070effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1071(@pxref{Annotations}). The annotation @var{level} controls how much
1072information @value{GDBN} prints together with its prompt, values of
1073expressions, source lines, and other types of output. Level 0 is the
1074normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1075@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1076that control @value{GDBN}, and level 2 has been deprecated.
1077
1078The annotation mechanism has largely been superseeded by @sc{gdb/mi}
1079(@pxref{GDB/MI}).
d700128c 1080
aa26fa3a
TT
1081@item --args
1082@cindex @code{--args}
1083Change interpretation of command line so that arguments following the
1084executable file are passed as command line arguments to the inferior.
1085This option stops option processing.
1086
2df3850c
JM
1087@item -baud @var{bps}
1088@itemx -b @var{bps}
d700128c
EZ
1089@cindex @code{--baud}
1090@cindex @code{-b}
c906108c
SS
1091Set the line speed (baud rate or bits per second) of any serial
1092interface used by @value{GDBN} for remote debugging.
c906108c 1093
f47b1503
AS
1094@item -l @var{timeout}
1095@cindex @code{-l}
1096Set the timeout (in seconds) of any communication used by @value{GDBN}
1097for remote debugging.
1098
c906108c 1099@item -tty @var{device}
d700128c
EZ
1100@itemx -t @var{device}
1101@cindex @code{--tty}
1102@cindex @code{-t}
c906108c
SS
1103Run using @var{device} for your program's standard input and output.
1104@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1105
53a5351d 1106@c resolve the situation of these eventually
c4555f82
SC
1107@item -tui
1108@cindex @code{--tui}
d0d5df6f
AC
1109Activate the @dfn{Text User Interface} when starting. The Text User
1110Interface manages several text windows on the terminal, showing
1111source, assembly, registers and @value{GDBN} command outputs
1112(@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1113Text User Interface can be enabled by invoking the program
1114@samp{gdbtui}. Do not use this option if you run @value{GDBN} from
1115Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1116
1117@c @item -xdb
d700128c 1118@c @cindex @code{--xdb}
53a5351d
JM
1119@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1120@c For information, see the file @file{xdb_trans.html}, which is usually
1121@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1122@c systems.
1123
d700128c
EZ
1124@item -interpreter @var{interp}
1125@cindex @code{--interpreter}
1126Use the interpreter @var{interp} for interface with the controlling
1127program or device. This option is meant to be set by programs which
94bbb2c0 1128communicate with @value{GDBN} using it as a back end.
21c294e6 1129@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1130
da0f9dcd 1131@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1132@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1133The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1134previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1135selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1136@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1137
1138@item -write
1139@cindex @code{--write}
1140Open the executable and core files for both reading and writing. This
1141is equivalent to the @samp{set write on} command inside @value{GDBN}
1142(@pxref{Patching}).
1143
1144@item -statistics
1145@cindex @code{--statistics}
1146This option causes @value{GDBN} to print statistics about time and
1147memory usage after it completes each command and returns to the prompt.
1148
1149@item -version
1150@cindex @code{--version}
1151This option causes @value{GDBN} to print its version number and
1152no-warranty blurb, and exit.
1153
c906108c
SS
1154@end table
1155
6fc08d32
EZ
1156@node Startup
1157@subsection What @value{GDBN} does during startup
1158@cindex @value{GDBN} startup
1159
1160Here's the description of what @value{GDBN} does during session startup:
1161
1162@enumerate
1163@item
1164Sets up the command interpreter as specified by the command line
1165(@pxref{Mode Options, interpreter}).
1166
1167@item
1168@cindex init file
1169Reads the @dfn{init file} (if any) in your home directory@footnote{On
1170DOS/Windows systems, the home directory is the one pointed to by the
1171@code{HOME} environment variable.} and executes all the commands in
1172that file.
1173
1174@item
1175Processes command line options and operands.
1176
1177@item
1178Reads and executes the commands from init file (if any) in the current
119b882a
EZ
1179working directory. This is only done if the current directory is
1180different from your home directory. Thus, you can have more than one
1181init file, one generic in your home directory, and another, specific
1182to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1183@value{GDBN}.
1184
1185@item
1186Reads command files specified by the @samp{-x} option. @xref{Command
1187Files}, for more details about @value{GDBN} command files.
1188
1189@item
1190Reads the command history recorded in the @dfn{history file}.
d620b259 1191@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1192files where @value{GDBN} records it.
1193@end enumerate
1194
1195Init files use the same syntax as @dfn{command files} (@pxref{Command
1196Files}) and are processed by @value{GDBN} in the same way. The init
1197file in your home directory can set options (such as @samp{set
1198complaints}) that affect subsequent processing of command line options
1199and operands. Init files are not executed if you use the @samp{-nx}
1200option (@pxref{Mode Options, ,Choosing modes}).
1201
1202@cindex init file name
1203@cindex @file{.gdbinit}
119b882a 1204The @value{GDBN} init files are normally called @file{.gdbinit}.
6fc08d32
EZ
1205On some configurations of @value{GDBN}, the init file is known by a
1206different name (these are typically environments where a specialized
1207form of @value{GDBN} may need to coexist with other forms, hence a
1208different name for the specialized version's init file). These are the
1209environments with special init file names:
1210
6fc08d32 1211@itemize @bullet
119b882a
EZ
1212@cindex @file{gdb.ini}
1213@item
1214The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1215the limitations of file names imposed by DOS filesystems. The Windows
1216ports of @value{GDBN} use the standard name, but if they find a
1217@file{gdb.ini} file, they warn you about that and suggest to rename
1218the file to the standard name.
1219
1220@cindex @file{.vxgdbinit}
6fc08d32
EZ
1221@item
1222VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
1223
1224@cindex @file{.os68gdbinit}
1225@item
1226OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
1227
1228@cindex @file{.esgdbinit}
1229@item
1230ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
1231
1232@item
1233CISCO 68k: @file{.cisco-gdbinit}
1234@end itemize
1235
1236
6d2ebf8b 1237@node Quitting GDB
c906108c
SS
1238@section Quitting @value{GDBN}
1239@cindex exiting @value{GDBN}
1240@cindex leaving @value{GDBN}
1241
1242@table @code
1243@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1244@kindex q @r{(@code{quit})}
96a2c332
SS
1245@item quit @r{[}@var{expression}@r{]}
1246@itemx q
1247To exit @value{GDBN}, use the @code{quit} command (abbreviated
1248@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1249do not supply @var{expression}, @value{GDBN} will terminate normally;
1250otherwise it will terminate using the result of @var{expression} as the
1251error code.
c906108c
SS
1252@end table
1253
1254@cindex interrupt
1255An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1256terminates the action of any @value{GDBN} command that is in progress and
1257returns to @value{GDBN} command level. It is safe to type the interrupt
1258character at any time because @value{GDBN} does not allow it to take effect
1259until a time when it is safe.
1260
c906108c
SS
1261If you have been using @value{GDBN} to control an attached process or
1262device, you can release it with the @code{detach} command
1263(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1264
6d2ebf8b 1265@node Shell Commands
c906108c
SS
1266@section Shell commands
1267
1268If you need to execute occasional shell commands during your
1269debugging session, there is no need to leave or suspend @value{GDBN}; you can
1270just use the @code{shell} command.
1271
1272@table @code
1273@kindex shell
1274@cindex shell escape
1275@item shell @var{command string}
1276Invoke a standard shell to execute @var{command string}.
c906108c 1277If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1278shell to run. Otherwise @value{GDBN} uses the default shell
1279(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1280@end table
1281
1282The utility @code{make} is often needed in development environments.
1283You do not have to use the @code{shell} command for this purpose in
1284@value{GDBN}:
1285
1286@table @code
1287@kindex make
1288@cindex calling make
1289@item make @var{make-args}
1290Execute the @code{make} program with the specified
1291arguments. This is equivalent to @samp{shell make @var{make-args}}.
1292@end table
1293
0fac0b41
DJ
1294@node Logging output
1295@section Logging output
1296@cindex logging @value{GDBN} output
9c16f35a 1297@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1298
1299You may want to save the output of @value{GDBN} commands to a file.
1300There are several commands to control @value{GDBN}'s logging.
1301
1302@table @code
1303@kindex set logging
1304@item set logging on
1305Enable logging.
1306@item set logging off
1307Disable logging.
9c16f35a 1308@cindex logging file name
0fac0b41
DJ
1309@item set logging file @var{file}
1310Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1311@item set logging overwrite [on|off]
1312By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1313you want @code{set logging on} to overwrite the logfile instead.
1314@item set logging redirect [on|off]
1315By default, @value{GDBN} output will go to both the terminal and the logfile.
1316Set @code{redirect} if you want output to go only to the log file.
1317@kindex show logging
1318@item show logging
1319Show the current values of the logging settings.
1320@end table
1321
6d2ebf8b 1322@node Commands
c906108c
SS
1323@chapter @value{GDBN} Commands
1324
1325You can abbreviate a @value{GDBN} command to the first few letters of the command
1326name, if that abbreviation is unambiguous; and you can repeat certain
1327@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1328key to get @value{GDBN} to fill out the rest of a word in a command (or to
1329show you the alternatives available, if there is more than one possibility).
1330
1331@menu
1332* Command Syntax:: How to give commands to @value{GDBN}
1333* Completion:: Command completion
1334* Help:: How to ask @value{GDBN} for help
1335@end menu
1336
6d2ebf8b 1337@node Command Syntax
c906108c
SS
1338@section Command syntax
1339
1340A @value{GDBN} command is a single line of input. There is no limit on
1341how long it can be. It starts with a command name, which is followed by
1342arguments whose meaning depends on the command name. For example, the
1343command @code{step} accepts an argument which is the number of times to
1344step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1345with no arguments. Some commands do not allow any arguments.
c906108c
SS
1346
1347@cindex abbreviation
1348@value{GDBN} command names may always be truncated if that abbreviation is
1349unambiguous. Other possible command abbreviations are listed in the
1350documentation for individual commands. In some cases, even ambiguous
1351abbreviations are allowed; for example, @code{s} is specially defined as
1352equivalent to @code{step} even though there are other commands whose
1353names start with @code{s}. You can test abbreviations by using them as
1354arguments to the @code{help} command.
1355
1356@cindex repeating commands
41afff9a 1357@kindex RET @r{(repeat last command)}
c906108c 1358A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1359repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1360will not repeat this way; these are commands whose unintentional
1361repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1362repeat. User-defined commands can disable this feature; see
1363@ref{Define, dont-repeat}.
c906108c
SS
1364
1365The @code{list} and @code{x} commands, when you repeat them with
1366@key{RET}, construct new arguments rather than repeating
1367exactly as typed. This permits easy scanning of source or memory.
1368
1369@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1370output, in a way similar to the common utility @code{more}
1371(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1372@key{RET} too many in this situation, @value{GDBN} disables command
1373repetition after any command that generates this sort of display.
1374
41afff9a 1375@kindex # @r{(a comment)}
c906108c
SS
1376@cindex comment
1377Any text from a @kbd{#} to the end of the line is a comment; it does
1378nothing. This is useful mainly in command files (@pxref{Command
1379Files,,Command files}).
1380
88118b3a
TT
1381@cindex repeating command sequences
1382@kindex C-o @r{(operate-and-get-next)}
1383The @kbd{C-o} binding is useful for repeating a complex sequence of
1384commands. This command accepts the current line, like @kbd{RET}, and
1385then fetches the next line relative to the current line from the history
1386for editing.
1387
6d2ebf8b 1388@node Completion
c906108c
SS
1389@section Command completion
1390
1391@cindex completion
1392@cindex word completion
1393@value{GDBN} can fill in the rest of a word in a command for you, if there is
1394only one possibility; it can also show you what the valid possibilities
1395are for the next word in a command, at any time. This works for @value{GDBN}
1396commands, @value{GDBN} subcommands, and the names of symbols in your program.
1397
1398Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1399of a word. If there is only one possibility, @value{GDBN} fills in the
1400word, and waits for you to finish the command (or press @key{RET} to
1401enter it). For example, if you type
1402
1403@c FIXME "@key" does not distinguish its argument sufficiently to permit
1404@c complete accuracy in these examples; space introduced for clarity.
1405@c If texinfo enhancements make it unnecessary, it would be nice to
1406@c replace " @key" by "@key" in the following...
474c8240 1407@smallexample
c906108c 1408(@value{GDBP}) info bre @key{TAB}
474c8240 1409@end smallexample
c906108c
SS
1410
1411@noindent
1412@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1413the only @code{info} subcommand beginning with @samp{bre}:
1414
474c8240 1415@smallexample
c906108c 1416(@value{GDBP}) info breakpoints
474c8240 1417@end smallexample
c906108c
SS
1418
1419@noindent
1420You can either press @key{RET} at this point, to run the @code{info
1421breakpoints} command, or backspace and enter something else, if
1422@samp{breakpoints} does not look like the command you expected. (If you
1423were sure you wanted @code{info breakpoints} in the first place, you
1424might as well just type @key{RET} immediately after @samp{info bre},
1425to exploit command abbreviations rather than command completion).
1426
1427If there is more than one possibility for the next word when you press
1428@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1429characters and try again, or just press @key{TAB} a second time;
1430@value{GDBN} displays all the possible completions for that word. For
1431example, you might want to set a breakpoint on a subroutine whose name
1432begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1433just sounds the bell. Typing @key{TAB} again displays all the
1434function names in your program that begin with those characters, for
1435example:
1436
474c8240 1437@smallexample
c906108c
SS
1438(@value{GDBP}) b make_ @key{TAB}
1439@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1440make_a_section_from_file make_environ
1441make_abs_section make_function_type
1442make_blockvector make_pointer_type
1443make_cleanup make_reference_type
c906108c
SS
1444make_command make_symbol_completion_list
1445(@value{GDBP}) b make_
474c8240 1446@end smallexample
c906108c
SS
1447
1448@noindent
1449After displaying the available possibilities, @value{GDBN} copies your
1450partial input (@samp{b make_} in the example) so you can finish the
1451command.
1452
1453If you just want to see the list of alternatives in the first place, you
b37052ae 1454can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1455means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1456key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1457one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1458
1459@cindex quotes in commands
1460@cindex completion of quoted strings
1461Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1462parentheses or other characters that @value{GDBN} normally excludes from
1463its notion of a word. To permit word completion to work in this
1464situation, you may enclose words in @code{'} (single quote marks) in
1465@value{GDBN} commands.
c906108c 1466
c906108c 1467The most likely situation where you might need this is in typing the
b37052ae
EZ
1468name of a C@t{++} function. This is because C@t{++} allows function
1469overloading (multiple definitions of the same function, distinguished
1470by argument type). For example, when you want to set a breakpoint you
1471may need to distinguish whether you mean the version of @code{name}
1472that takes an @code{int} parameter, @code{name(int)}, or the version
1473that takes a @code{float} parameter, @code{name(float)}. To use the
1474word-completion facilities in this situation, type a single quote
1475@code{'} at the beginning of the function name. This alerts
1476@value{GDBN} that it may need to consider more information than usual
1477when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1478
474c8240 1479@smallexample
96a2c332 1480(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1481bubble(double,double) bubble(int,int)
1482(@value{GDBP}) b 'bubble(
474c8240 1483@end smallexample
c906108c
SS
1484
1485In some cases, @value{GDBN} can tell that completing a name requires using
1486quotes. When this happens, @value{GDBN} inserts the quote for you (while
1487completing as much as it can) if you do not type the quote in the first
1488place:
1489
474c8240 1490@smallexample
c906108c
SS
1491(@value{GDBP}) b bub @key{TAB}
1492@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1493(@value{GDBP}) b 'bubble(
474c8240 1494@end smallexample
c906108c
SS
1495
1496@noindent
1497In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1498you have not yet started typing the argument list when you ask for
1499completion on an overloaded symbol.
1500
d4f3574e 1501For more information about overloaded functions, see @ref{C plus plus
b37052ae 1502expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1503overload-resolution off} to disable overload resolution;
b37052ae 1504see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1505
1506
6d2ebf8b 1507@node Help
c906108c
SS
1508@section Getting help
1509@cindex online documentation
1510@kindex help
1511
5d161b24 1512You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1513using the command @code{help}.
1514
1515@table @code
41afff9a 1516@kindex h @r{(@code{help})}
c906108c
SS
1517@item help
1518@itemx h
1519You can use @code{help} (abbreviated @code{h}) with no arguments to
1520display a short list of named classes of commands:
1521
1522@smallexample
1523(@value{GDBP}) help
1524List of classes of commands:
1525
2df3850c 1526aliases -- Aliases of other commands
c906108c 1527breakpoints -- Making program stop at certain points
2df3850c 1528data -- Examining data
c906108c 1529files -- Specifying and examining files
2df3850c
JM
1530internals -- Maintenance commands
1531obscure -- Obscure features
1532running -- Running the program
1533stack -- Examining the stack
c906108c
SS
1534status -- Status inquiries
1535support -- Support facilities
96a2c332
SS
1536tracepoints -- Tracing of program execution without@*
1537 stopping the program
c906108c 1538user-defined -- User-defined commands
c906108c 1539
5d161b24 1540Type "help" followed by a class name for a list of
c906108c 1541commands in that class.
5d161b24 1542Type "help" followed by command name for full
c906108c
SS
1543documentation.
1544Command name abbreviations are allowed if unambiguous.
1545(@value{GDBP})
1546@end smallexample
96a2c332 1547@c the above line break eliminates huge line overfull...
c906108c
SS
1548
1549@item help @var{class}
1550Using one of the general help classes as an argument, you can get a
1551list of the individual commands in that class. For example, here is the
1552help display for the class @code{status}:
1553
1554@smallexample
1555(@value{GDBP}) help status
1556Status inquiries.
1557
1558List of commands:
1559
1560@c Line break in "show" line falsifies real output, but needed
1561@c to fit in smallbook page size.
2df3850c
JM
1562info -- Generic command for showing things
1563 about the program being debugged
1564show -- Generic command for showing things
1565 about the debugger
c906108c 1566
5d161b24 1567Type "help" followed by command name for full
c906108c
SS
1568documentation.
1569Command name abbreviations are allowed if unambiguous.
1570(@value{GDBP})
1571@end smallexample
1572
1573@item help @var{command}
1574With a command name as @code{help} argument, @value{GDBN} displays a
1575short paragraph on how to use that command.
1576
6837a0a2
DB
1577@kindex apropos
1578@item apropos @var{args}
09d4efe1 1579The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2
DB
1580commands, and their documentation, for the regular expression specified in
1581@var{args}. It prints out all matches found. For example:
1582
1583@smallexample
1584apropos reload
1585@end smallexample
1586
b37052ae
EZ
1587@noindent
1588results in:
6837a0a2
DB
1589
1590@smallexample
6d2ebf8b
SS
1591@c @group
1592set symbol-reloading -- Set dynamic symbol table reloading
1593 multiple times in one run
1594show symbol-reloading -- Show dynamic symbol table reloading
1595 multiple times in one run
1596@c @end group
6837a0a2
DB
1597@end smallexample
1598
c906108c
SS
1599@kindex complete
1600@item complete @var{args}
1601The @code{complete @var{args}} command lists all the possible completions
1602for the beginning of a command. Use @var{args} to specify the beginning of the
1603command you want completed. For example:
1604
1605@smallexample
1606complete i
1607@end smallexample
1608
1609@noindent results in:
1610
1611@smallexample
1612@group
2df3850c
JM
1613if
1614ignore
c906108c
SS
1615info
1616inspect
c906108c
SS
1617@end group
1618@end smallexample
1619
1620@noindent This is intended for use by @sc{gnu} Emacs.
1621@end table
1622
1623In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1624and @code{show} to inquire about the state of your program, or the state
1625of @value{GDBN} itself. Each command supports many topics of inquiry; this
1626manual introduces each of them in the appropriate context. The listings
1627under @code{info} and under @code{show} in the Index point to
1628all the sub-commands. @xref{Index}.
1629
1630@c @group
1631@table @code
1632@kindex info
41afff9a 1633@kindex i @r{(@code{info})}
c906108c
SS
1634@item info
1635This command (abbreviated @code{i}) is for describing the state of your
1636program. For example, you can list the arguments given to your program
1637with @code{info args}, list the registers currently in use with @code{info
1638registers}, or list the breakpoints you have set with @code{info breakpoints}.
1639You can get a complete list of the @code{info} sub-commands with
1640@w{@code{help info}}.
1641
1642@kindex set
1643@item set
5d161b24 1644You can assign the result of an expression to an environment variable with
c906108c
SS
1645@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1646@code{set prompt $}.
1647
1648@kindex show
1649@item show
5d161b24 1650In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1651@value{GDBN} itself.
1652You can change most of the things you can @code{show}, by using the
1653related command @code{set}; for example, you can control what number
1654system is used for displays with @code{set radix}, or simply inquire
1655which is currently in use with @code{show radix}.
1656
1657@kindex info set
1658To display all the settable parameters and their current
1659values, you can use @code{show} with no arguments; you may also use
1660@code{info set}. Both commands produce the same display.
1661@c FIXME: "info set" violates the rule that "info" is for state of
1662@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1663@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1664@end table
1665@c @end group
1666
1667Here are three miscellaneous @code{show} subcommands, all of which are
1668exceptional in lacking corresponding @code{set} commands:
1669
1670@table @code
1671@kindex show version
9c16f35a 1672@cindex @value{GDBN} version number
c906108c
SS
1673@item show version
1674Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1675information in @value{GDBN} bug-reports. If multiple versions of
1676@value{GDBN} are in use at your site, you may need to determine which
1677version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1678commands are introduced, and old ones may wither away. Also, many
1679system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1680variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1681The version number is the same as the one announced when you start
1682@value{GDBN}.
c906108c
SS
1683
1684@kindex show copying
09d4efe1 1685@kindex info copying
9c16f35a 1686@cindex display @value{GDBN} copyright
c906108c 1687@item show copying
09d4efe1 1688@itemx info copying
c906108c
SS
1689Display information about permission for copying @value{GDBN}.
1690
1691@kindex show warranty
09d4efe1 1692@kindex info warranty
c906108c 1693@item show warranty
09d4efe1 1694@itemx info warranty
2df3850c 1695Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1696if your version of @value{GDBN} comes with one.
2df3850c 1697
c906108c
SS
1698@end table
1699
6d2ebf8b 1700@node Running
c906108c
SS
1701@chapter Running Programs Under @value{GDBN}
1702
1703When you run a program under @value{GDBN}, you must first generate
1704debugging information when you compile it.
7a292a7a
SS
1705
1706You may start @value{GDBN} with its arguments, if any, in an environment
1707of your choice. If you are doing native debugging, you may redirect
1708your program's input and output, debug an already running process, or
1709kill a child process.
c906108c
SS
1710
1711@menu
1712* Compilation:: Compiling for debugging
1713* Starting:: Starting your program
c906108c
SS
1714* Arguments:: Your program's arguments
1715* Environment:: Your program's environment
c906108c
SS
1716
1717* Working Directory:: Your program's working directory
1718* Input/Output:: Your program's input and output
1719* Attach:: Debugging an already-running process
1720* Kill Process:: Killing the child process
c906108c
SS
1721
1722* Threads:: Debugging programs with multiple threads
1723* Processes:: Debugging programs with multiple processes
1724@end menu
1725
6d2ebf8b 1726@node Compilation
c906108c
SS
1727@section Compiling for debugging
1728
1729In order to debug a program effectively, you need to generate
1730debugging information when you compile it. This debugging information
1731is stored in the object file; it describes the data type of each
1732variable or function and the correspondence between source line numbers
1733and addresses in the executable code.
1734
1735To request debugging information, specify the @samp{-g} option when you run
1736the compiler.
1737
514c4d71
EZ
1738Programs that are to be shipped to your customers are compiled with
1739optimizations, using the @samp{-O} compiler option. However, many
1740compilers are unable to handle the @samp{-g} and @samp{-O} options
1741together. Using those compilers, you cannot generate optimized
c906108c
SS
1742executables containing debugging information.
1743
514c4d71 1744@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1745without @samp{-O}, making it possible to debug optimized code. We
1746recommend that you @emph{always} use @samp{-g} whenever you compile a
1747program. You may think your program is correct, but there is no sense
1748in pushing your luck.
c906108c
SS
1749
1750@cindex optimized code, debugging
1751@cindex debugging optimized code
1752When you debug a program compiled with @samp{-g -O}, remember that the
1753optimizer is rearranging your code; the debugger shows you what is
1754really there. Do not be too surprised when the execution path does not
1755exactly match your source file! An extreme example: if you define a
1756variable, but never use it, @value{GDBN} never sees that
1757variable---because the compiler optimizes it out of existence.
1758
1759Some things do not work as well with @samp{-g -O} as with just
1760@samp{-g}, particularly on machines with instruction scheduling. If in
1761doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1762please report it to us as a bug (including a test case!).
15387254 1763@xref{Variables}, for more information about debugging optimized code.
c906108c
SS
1764
1765Older versions of the @sc{gnu} C compiler permitted a variant option
1766@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1767format; if your @sc{gnu} C compiler has this option, do not use it.
1768
514c4d71
EZ
1769@value{GDBN} knows about preprocessor macros and can show you their
1770expansion (@pxref{Macros}). Most compilers do not include information
1771about preprocessor macros in the debugging information if you specify
1772the @option{-g} flag alone, because this information is rather large.
1773Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1774provides macro information if you specify the options
1775@option{-gdwarf-2} and @option{-g3}; the former option requests
1776debugging information in the Dwarf 2 format, and the latter requests
1777``extra information''. In the future, we hope to find more compact
1778ways to represent macro information, so that it can be included with
1779@option{-g} alone.
1780
c906108c 1781@need 2000
6d2ebf8b 1782@node Starting
c906108c
SS
1783@section Starting your program
1784@cindex starting
1785@cindex running
1786
1787@table @code
1788@kindex run
41afff9a 1789@kindex r @r{(@code{run})}
c906108c
SS
1790@item run
1791@itemx r
7a292a7a
SS
1792Use the @code{run} command to start your program under @value{GDBN}.
1793You must first specify the program name (except on VxWorks) with an
1794argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1795@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1796(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1797
1798@end table
1799
c906108c
SS
1800If you are running your program in an execution environment that
1801supports processes, @code{run} creates an inferior process and makes
1802that process run your program. (In environments without processes,
1803@code{run} jumps to the start of your program.)
1804
1805The execution of a program is affected by certain information it
1806receives from its superior. @value{GDBN} provides ways to specify this
1807information, which you must do @emph{before} starting your program. (You
1808can change it after starting your program, but such changes only affect
1809your program the next time you start it.) This information may be
1810divided into four categories:
1811
1812@table @asis
1813@item The @emph{arguments.}
1814Specify the arguments to give your program as the arguments of the
1815@code{run} command. If a shell is available on your target, the shell
1816is used to pass the arguments, so that you may use normal conventions
1817(such as wildcard expansion or variable substitution) in describing
1818the arguments.
1819In Unix systems, you can control which shell is used with the
1820@code{SHELL} environment variable.
1821@xref{Arguments, ,Your program's arguments}.
1822
1823@item The @emph{environment.}
1824Your program normally inherits its environment from @value{GDBN}, but you can
1825use the @value{GDBN} commands @code{set environment} and @code{unset
1826environment} to change parts of the environment that affect
1827your program. @xref{Environment, ,Your program's environment}.
1828
1829@item The @emph{working directory.}
1830Your program inherits its working directory from @value{GDBN}. You can set
1831the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1832@xref{Working Directory, ,Your program's working directory}.
1833
1834@item The @emph{standard input and output.}
1835Your program normally uses the same device for standard input and
1836standard output as @value{GDBN} is using. You can redirect input and output
1837in the @code{run} command line, or you can use the @code{tty} command to
1838set a different device for your program.
1839@xref{Input/Output, ,Your program's input and output}.
1840
1841@cindex pipes
1842@emph{Warning:} While input and output redirection work, you cannot use
1843pipes to pass the output of the program you are debugging to another
1844program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1845wrong program.
1846@end table
c906108c
SS
1847
1848When you issue the @code{run} command, your program begins to execute
1849immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1850of how to arrange for your program to stop. Once your program has
1851stopped, you may call functions in your program, using the @code{print}
1852or @code{call} commands. @xref{Data, ,Examining Data}.
1853
1854If the modification time of your symbol file has changed since the last
1855time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1856table, and reads it again. When it does this, @value{GDBN} tries to retain
1857your current breakpoints.
1858
4e8b0763
JB
1859@table @code
1860@kindex start
1861@item start
1862@cindex run to main procedure
1863The name of the main procedure can vary from language to language.
1864With C or C@t{++}, the main procedure name is always @code{main}, but
1865other languages such as Ada do not require a specific name for their
1866main procedure. The debugger provides a convenient way to start the
1867execution of the program and to stop at the beginning of the main
1868procedure, depending on the language used.
1869
1870The @samp{start} command does the equivalent of setting a temporary
1871breakpoint at the beginning of the main procedure and then invoking
1872the @samp{run} command.
1873
f018e82f
EZ
1874@cindex elaboration phase
1875Some programs contain an @dfn{elaboration} phase where some startup code is
1876executed before the main procedure is called. This depends on the
1877languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1878constructors for static and global objects are executed before
1879@code{main} is called. It is therefore possible that the debugger stops
1880before reaching the main procedure. However, the temporary breakpoint
1881will remain to halt execution.
1882
1883Specify the arguments to give to your program as arguments to the
1884@samp{start} command. These arguments will be given verbatim to the
1885underlying @samp{run} command. Note that the same arguments will be
1886reused if no argument is provided during subsequent calls to
1887@samp{start} or @samp{run}.
1888
1889It is sometimes necessary to debug the program during elaboration. In
1890these cases, using the @code{start} command would stop the execution of
1891your program too late, as the program would have already completed the
1892elaboration phase. Under these circumstances, insert breakpoints in your
1893elaboration code before running your program.
1894@end table
1895
6d2ebf8b 1896@node Arguments
c906108c
SS
1897@section Your program's arguments
1898
1899@cindex arguments (to your program)
1900The arguments to your program can be specified by the arguments of the
5d161b24 1901@code{run} command.
c906108c
SS
1902They are passed to a shell, which expands wildcard characters and
1903performs redirection of I/O, and thence to your program. Your
1904@code{SHELL} environment variable (if it exists) specifies what shell
1905@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1906the default shell (@file{/bin/sh} on Unix).
1907
1908On non-Unix systems, the program is usually invoked directly by
1909@value{GDBN}, which emulates I/O redirection via the appropriate system
1910calls, and the wildcard characters are expanded by the startup code of
1911the program, not by the shell.
c906108c
SS
1912
1913@code{run} with no arguments uses the same arguments used by the previous
1914@code{run}, or those set by the @code{set args} command.
1915
c906108c 1916@table @code
41afff9a 1917@kindex set args
c906108c
SS
1918@item set args
1919Specify the arguments to be used the next time your program is run. If
1920@code{set args} has no arguments, @code{run} executes your program
1921with no arguments. Once you have run your program with arguments,
1922using @code{set args} before the next @code{run} is the only way to run
1923it again without arguments.
1924
1925@kindex show args
1926@item show args
1927Show the arguments to give your program when it is started.
1928@end table
1929
6d2ebf8b 1930@node Environment
c906108c
SS
1931@section Your program's environment
1932
1933@cindex environment (of your program)
1934The @dfn{environment} consists of a set of environment variables and
1935their values. Environment variables conventionally record such things as
1936your user name, your home directory, your terminal type, and your search
1937path for programs to run. Usually you set up environment variables with
1938the shell and they are inherited by all the other programs you run. When
1939debugging, it can be useful to try running your program with a modified
1940environment without having to start @value{GDBN} over again.
1941
1942@table @code
1943@kindex path
1944@item path @var{directory}
1945Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1946(the search path for executables) that will be passed to your program.
1947The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1948You may specify several directory names, separated by whitespace or by a
1949system-dependent separator character (@samp{:} on Unix, @samp{;} on
1950MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1951is moved to the front, so it is searched sooner.
c906108c
SS
1952
1953You can use the string @samp{$cwd} to refer to whatever is the current
1954working directory at the time @value{GDBN} searches the path. If you
1955use @samp{.} instead, it refers to the directory where you executed the
1956@code{path} command. @value{GDBN} replaces @samp{.} in the
1957@var{directory} argument (with the current path) before adding
1958@var{directory} to the search path.
1959@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1960@c document that, since repeating it would be a no-op.
1961
1962@kindex show paths
1963@item show paths
1964Display the list of search paths for executables (the @code{PATH}
1965environment variable).
1966
1967@kindex show environment
1968@item show environment @r{[}@var{varname}@r{]}
1969Print the value of environment variable @var{varname} to be given to
1970your program when it starts. If you do not supply @var{varname},
1971print the names and values of all environment variables to be given to
1972your program. You can abbreviate @code{environment} as @code{env}.
1973
1974@kindex set environment
53a5351d 1975@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1976Set environment variable @var{varname} to @var{value}. The value
1977changes for your program only, not for @value{GDBN} itself. @var{value} may
1978be any string; the values of environment variables are just strings, and
1979any interpretation is supplied by your program itself. The @var{value}
1980parameter is optional; if it is eliminated, the variable is set to a
1981null value.
1982@c "any string" here does not include leading, trailing
1983@c blanks. Gnu asks: does anyone care?
1984
1985For example, this command:
1986
474c8240 1987@smallexample
c906108c 1988set env USER = foo
474c8240 1989@end smallexample
c906108c
SS
1990
1991@noindent
d4f3574e 1992tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1993@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1994are not actually required.)
1995
1996@kindex unset environment
1997@item unset environment @var{varname}
1998Remove variable @var{varname} from the environment to be passed to your
1999program. This is different from @samp{set env @var{varname} =};
2000@code{unset environment} removes the variable from the environment,
2001rather than assigning it an empty value.
2002@end table
2003
d4f3574e
SS
2004@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2005the shell indicated
c906108c
SS
2006by your @code{SHELL} environment variable if it exists (or
2007@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2008that runs an initialization file---such as @file{.cshrc} for C-shell, or
2009@file{.bashrc} for BASH---any variables you set in that file affect
2010your program. You may wish to move setting of environment variables to
2011files that are only run when you sign on, such as @file{.login} or
2012@file{.profile}.
2013
6d2ebf8b 2014@node Working Directory
c906108c
SS
2015@section Your program's working directory
2016
2017@cindex working directory (of your program)
2018Each time you start your program with @code{run}, it inherits its
2019working directory from the current working directory of @value{GDBN}.
2020The @value{GDBN} working directory is initially whatever it inherited
2021from its parent process (typically the shell), but you can specify a new
2022working directory in @value{GDBN} with the @code{cd} command.
2023
2024The @value{GDBN} working directory also serves as a default for the commands
2025that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
2026specify files}.
2027
2028@table @code
2029@kindex cd
721c2651 2030@cindex change working directory
c906108c
SS
2031@item cd @var{directory}
2032Set the @value{GDBN} working directory to @var{directory}.
2033
2034@kindex pwd
2035@item pwd
2036Print the @value{GDBN} working directory.
2037@end table
2038
60bf7e09
EZ
2039It is generally impossible to find the current working directory of
2040the process being debugged (since a program can change its directory
2041during its run). If you work on a system where @value{GDBN} is
2042configured with the @file{/proc} support, you can use the @code{info
2043proc} command (@pxref{SVR4 Process Information}) to find out the
2044current working directory of the debuggee.
2045
6d2ebf8b 2046@node Input/Output
c906108c
SS
2047@section Your program's input and output
2048
2049@cindex redirection
2050@cindex i/o
2051@cindex terminal
2052By default, the program you run under @value{GDBN} does input and output to
5d161b24 2053the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2054to its own terminal modes to interact with you, but it records the terminal
2055modes your program was using and switches back to them when you continue
2056running your program.
2057
2058@table @code
2059@kindex info terminal
2060@item info terminal
2061Displays information recorded by @value{GDBN} about the terminal modes your
2062program is using.
2063@end table
2064
2065You can redirect your program's input and/or output using shell
2066redirection with the @code{run} command. For example,
2067
474c8240 2068@smallexample
c906108c 2069run > outfile
474c8240 2070@end smallexample
c906108c
SS
2071
2072@noindent
2073starts your program, diverting its output to the file @file{outfile}.
2074
2075@kindex tty
2076@cindex controlling terminal
2077Another way to specify where your program should do input and output is
2078with the @code{tty} command. This command accepts a file name as
2079argument, and causes this file to be the default for future @code{run}
2080commands. It also resets the controlling terminal for the child
2081process, for future @code{run} commands. For example,
2082
474c8240 2083@smallexample
c906108c 2084tty /dev/ttyb
474c8240 2085@end smallexample
c906108c
SS
2086
2087@noindent
2088directs that processes started with subsequent @code{run} commands
2089default to do input and output on the terminal @file{/dev/ttyb} and have
2090that as their controlling terminal.
2091
2092An explicit redirection in @code{run} overrides the @code{tty} command's
2093effect on the input/output device, but not its effect on the controlling
2094terminal.
2095
2096When you use the @code{tty} command or redirect input in the @code{run}
2097command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2098for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2099for @code{set inferior-tty}.
2100
2101@cindex inferior tty
2102@cindex set inferior controlling terminal
2103You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2104display the name of the terminal that will be used for future runs of your
2105program.
2106
2107@table @code
2108@item set inferior-tty /dev/ttyb
2109@kindex set inferior-tty
2110Set the tty for the program being debugged to /dev/ttyb.
2111
2112@item show inferior-tty
2113@kindex show inferior-tty
2114Show the current tty for the program being debugged.
2115@end table
c906108c 2116
6d2ebf8b 2117@node Attach
c906108c
SS
2118@section Debugging an already-running process
2119@kindex attach
2120@cindex attach
2121
2122@table @code
2123@item attach @var{process-id}
2124This command attaches to a running process---one that was started
2125outside @value{GDBN}. (@code{info files} shows your active
2126targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2127find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2128or with the @samp{jobs -l} shell command.
2129
2130@code{attach} does not repeat if you press @key{RET} a second time after
2131executing the command.
2132@end table
2133
2134To use @code{attach}, your program must be running in an environment
2135which supports processes; for example, @code{attach} does not work for
2136programs on bare-board targets that lack an operating system. You must
2137also have permission to send the process a signal.
2138
2139When you use @code{attach}, the debugger finds the program running in
2140the process first by looking in the current working directory, then (if
2141the program is not found) by using the source file search path
2142(@pxref{Source Path, ,Specifying source directories}). You can also use
2143the @code{file} command to load the program. @xref{Files, ,Commands to
2144Specify Files}.
2145
2146The first thing @value{GDBN} does after arranging to debug the specified
2147process is to stop it. You can examine and modify an attached process
53a5351d
JM
2148with all the @value{GDBN} commands that are ordinarily available when
2149you start processes with @code{run}. You can insert breakpoints; you
2150can step and continue; you can modify storage. If you would rather the
2151process continue running, you may use the @code{continue} command after
c906108c
SS
2152attaching @value{GDBN} to the process.
2153
2154@table @code
2155@kindex detach
2156@item detach
2157When you have finished debugging the attached process, you can use the
2158@code{detach} command to release it from @value{GDBN} control. Detaching
2159the process continues its execution. After the @code{detach} command,
2160that process and @value{GDBN} become completely independent once more, and you
2161are ready to @code{attach} another process or start one with @code{run}.
2162@code{detach} does not repeat if you press @key{RET} again after
2163executing the command.
2164@end table
2165
2166If you exit @value{GDBN} or use the @code{run} command while you have an
2167attached process, you kill that process. By default, @value{GDBN} asks
2168for confirmation if you try to do either of these things; you can
2169control whether or not you need to confirm by using the @code{set
2170confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2171messages}).
2172
6d2ebf8b 2173@node Kill Process
c906108c 2174@section Killing the child process
c906108c
SS
2175
2176@table @code
2177@kindex kill
2178@item kill
2179Kill the child process in which your program is running under @value{GDBN}.
2180@end table
2181
2182This command is useful if you wish to debug a core dump instead of a
2183running process. @value{GDBN} ignores any core dump file while your program
2184is running.
2185
2186On some operating systems, a program cannot be executed outside @value{GDBN}
2187while you have breakpoints set on it inside @value{GDBN}. You can use the
2188@code{kill} command in this situation to permit running your program
2189outside the debugger.
2190
2191The @code{kill} command is also useful if you wish to recompile and
2192relink your program, since on many systems it is impossible to modify an
2193executable file while it is running in a process. In this case, when you
2194next type @code{run}, @value{GDBN} notices that the file has changed, and
2195reads the symbol table again (while trying to preserve your current
2196breakpoint settings).
2197
6d2ebf8b 2198@node Threads
c906108c 2199@section Debugging programs with multiple threads
c906108c
SS
2200
2201@cindex threads of execution
2202@cindex multiple threads
2203@cindex switching threads
2204In some operating systems, such as HP-UX and Solaris, a single program
2205may have more than one @dfn{thread} of execution. The precise semantics
2206of threads differ from one operating system to another, but in general
2207the threads of a single program are akin to multiple processes---except
2208that they share one address space (that is, they can all examine and
2209modify the same variables). On the other hand, each thread has its own
2210registers and execution stack, and perhaps private memory.
2211
2212@value{GDBN} provides these facilities for debugging multi-thread
2213programs:
2214
2215@itemize @bullet
2216@item automatic notification of new threads
2217@item @samp{thread @var{threadno}}, a command to switch among threads
2218@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2219@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2220a command to apply a command to a list of threads
2221@item thread-specific breakpoints
2222@end itemize
2223
c906108c
SS
2224@quotation
2225@emph{Warning:} These facilities are not yet available on every
2226@value{GDBN} configuration where the operating system supports threads.
2227If your @value{GDBN} does not support threads, these commands have no
2228effect. For example, a system without thread support shows no output
2229from @samp{info threads}, and always rejects the @code{thread} command,
2230like this:
2231
2232@smallexample
2233(@value{GDBP}) info threads
2234(@value{GDBP}) thread 1
2235Thread ID 1 not known. Use the "info threads" command to
2236see the IDs of currently known threads.
2237@end smallexample
2238@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2239@c doesn't support threads"?
2240@end quotation
c906108c
SS
2241
2242@cindex focus of debugging
2243@cindex current thread
2244The @value{GDBN} thread debugging facility allows you to observe all
2245threads while your program runs---but whenever @value{GDBN} takes
2246control, one thread in particular is always the focus of debugging.
2247This thread is called the @dfn{current thread}. Debugging commands show
2248program information from the perspective of the current thread.
2249
41afff9a 2250@cindex @code{New} @var{systag} message
c906108c
SS
2251@cindex thread identifier (system)
2252@c FIXME-implementors!! It would be more helpful if the [New...] message
2253@c included GDB's numeric thread handle, so you could just go to that
2254@c thread without first checking `info threads'.
2255Whenever @value{GDBN} detects a new thread in your program, it displays
2256the target system's identification for the thread with a message in the
2257form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2258whose form varies depending on the particular system. For example, on
2259LynxOS, you might see
2260
474c8240 2261@smallexample
c906108c 2262[New process 35 thread 27]
474c8240 2263@end smallexample
c906108c
SS
2264
2265@noindent
2266when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2267the @var{systag} is simply something like @samp{process 368}, with no
2268further qualifier.
2269
2270@c FIXME!! (1) Does the [New...] message appear even for the very first
2271@c thread of a program, or does it only appear for the
6ca652b0 2272@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2273@c program?
2274@c (2) *Is* there necessarily a first thread always? Or do some
2275@c multithread systems permit starting a program with multiple
5d161b24 2276@c threads ab initio?
c906108c
SS
2277
2278@cindex thread number
2279@cindex thread identifier (GDB)
2280For debugging purposes, @value{GDBN} associates its own thread
2281number---always a single integer---with each thread in your program.
2282
2283@table @code
2284@kindex info threads
2285@item info threads
2286Display a summary of all threads currently in your
2287program. @value{GDBN} displays for each thread (in this order):
2288
2289@enumerate
09d4efe1
EZ
2290@item
2291the thread number assigned by @value{GDBN}
c906108c 2292
09d4efe1
EZ
2293@item
2294the target system's thread identifier (@var{systag})
c906108c 2295
09d4efe1
EZ
2296@item
2297the current stack frame summary for that thread
c906108c
SS
2298@end enumerate
2299
2300@noindent
2301An asterisk @samp{*} to the left of the @value{GDBN} thread number
2302indicates the current thread.
2303
5d161b24 2304For example,
c906108c
SS
2305@end table
2306@c end table here to get a little more width for example
2307
2308@smallexample
2309(@value{GDBP}) info threads
2310 3 process 35 thread 27 0x34e5 in sigpause ()
2311 2 process 35 thread 23 0x34e5 in sigpause ()
2312* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2313 at threadtest.c:68
2314@end smallexample
53a5351d
JM
2315
2316On HP-UX systems:
c906108c 2317
4644b6e3
EZ
2318@cindex debugging multithreaded programs (on HP-UX)
2319@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2320For debugging purposes, @value{GDBN} associates its own thread
2321number---a small integer assigned in thread-creation order---with each
2322thread in your program.
2323
41afff9a
EZ
2324@cindex @code{New} @var{systag} message, on HP-UX
2325@cindex thread identifier (system), on HP-UX
c906108c
SS
2326@c FIXME-implementors!! It would be more helpful if the [New...] message
2327@c included GDB's numeric thread handle, so you could just go to that
2328@c thread without first checking `info threads'.
2329Whenever @value{GDBN} detects a new thread in your program, it displays
2330both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2331form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2332whose form varies depending on the particular system. For example, on
2333HP-UX, you see
2334
474c8240 2335@smallexample
c906108c 2336[New thread 2 (system thread 26594)]
474c8240 2337@end smallexample
c906108c
SS
2338
2339@noindent
5d161b24 2340when @value{GDBN} notices a new thread.
c906108c
SS
2341
2342@table @code
4644b6e3 2343@kindex info threads (HP-UX)
c906108c
SS
2344@item info threads
2345Display a summary of all threads currently in your
2346program. @value{GDBN} displays for each thread (in this order):
2347
2348@enumerate
2349@item the thread number assigned by @value{GDBN}
2350
2351@item the target system's thread identifier (@var{systag})
2352
2353@item the current stack frame summary for that thread
2354@end enumerate
2355
2356@noindent
2357An asterisk @samp{*} to the left of the @value{GDBN} thread number
2358indicates the current thread.
2359
5d161b24 2360For example,
c906108c
SS
2361@end table
2362@c end table here to get a little more width for example
2363
474c8240 2364@smallexample
c906108c 2365(@value{GDBP}) info threads
6d2ebf8b
SS
2366 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2367 at quicksort.c:137
2368 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2369 from /usr/lib/libc.2
2370 1 system thread 27905 0x7b003498 in _brk () \@*
2371 from /usr/lib/libc.2
474c8240 2372@end smallexample
c906108c 2373
c45da7e6
EZ
2374On Solaris, you can display more information about user threads with a
2375Solaris-specific command:
2376
2377@table @code
2378@item maint info sol-threads
2379@kindex maint info sol-threads
2380@cindex thread info (Solaris)
2381Display info on Solaris user threads.
2382@end table
2383
c906108c
SS
2384@table @code
2385@kindex thread @var{threadno}
2386@item thread @var{threadno}
2387Make thread number @var{threadno} the current thread. The command
2388argument @var{threadno} is the internal @value{GDBN} thread number, as
2389shown in the first field of the @samp{info threads} display.
2390@value{GDBN} responds by displaying the system identifier of the thread
2391you selected, and its current stack frame summary:
2392
2393@smallexample
2394@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2395(@value{GDBP}) thread 2
c906108c 2396[Switching to process 35 thread 23]
c906108c
SS
23970x34e5 in sigpause ()
2398@end smallexample
2399
2400@noindent
2401As with the @samp{[New @dots{}]} message, the form of the text after
2402@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2403threads.
c906108c 2404
9c16f35a 2405@kindex thread apply
638ac427 2406@cindex apply command to several threads
c906108c
SS
2407@item thread apply [@var{threadno}] [@var{all}] @var{args}
2408The @code{thread apply} command allows you to apply a command to one or
2409more threads. Specify the numbers of the threads that you want affected
2410with the command argument @var{threadno}. @var{threadno} is the internal
2411@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2412threads} display. To apply a command to all threads, use
2413@code{thread apply all} @var{args}.
c906108c
SS
2414@end table
2415
2416@cindex automatic thread selection
2417@cindex switching threads automatically
2418@cindex threads, automatic switching
2419Whenever @value{GDBN} stops your program, due to a breakpoint or a
2420signal, it automatically selects the thread where that breakpoint or
2421signal happened. @value{GDBN} alerts you to the context switch with a
2422message of the form @samp{[Switching to @var{systag}]} to identify the
2423thread.
2424
2425@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2426more information about how @value{GDBN} behaves when you stop and start
2427programs with multiple threads.
2428
2429@xref{Set Watchpoints,,Setting watchpoints}, for information about
2430watchpoints in programs with multiple threads.
c906108c 2431
6d2ebf8b 2432@node Processes
c906108c
SS
2433@section Debugging programs with multiple processes
2434
2435@cindex fork, debugging programs which call
2436@cindex multiple processes
2437@cindex processes, multiple
53a5351d
JM
2438On most systems, @value{GDBN} has no special support for debugging
2439programs which create additional processes using the @code{fork}
2440function. When a program forks, @value{GDBN} will continue to debug the
2441parent process and the child process will run unimpeded. If you have
2442set a breakpoint in any code which the child then executes, the child
2443will get a @code{SIGTRAP} signal which (unless it catches the signal)
2444will cause it to terminate.
c906108c
SS
2445
2446However, if you want to debug the child process there is a workaround
2447which isn't too painful. Put a call to @code{sleep} in the code which
2448the child process executes after the fork. It may be useful to sleep
2449only if a certain environment variable is set, or a certain file exists,
2450so that the delay need not occur when you don't want to run @value{GDBN}
2451on the child. While the child is sleeping, use the @code{ps} program to
2452get its process ID. Then tell @value{GDBN} (a new invocation of
2453@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2454the child process (@pxref{Attach}). From that point on you can debug
c906108c 2455the child process just like any other process which you attached to.
c906108c 2456
b51970ac
DJ
2457On some systems, @value{GDBN} provides support for debugging programs that
2458create additional processes using the @code{fork} or @code{vfork} functions.
2459Currently, the only platforms with this feature are HP-UX (11.x and later
2460only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2461
2462By default, when a program forks, @value{GDBN} will continue to debug
2463the parent process and the child process will run unimpeded.
2464
2465If you want to follow the child process instead of the parent process,
2466use the command @w{@code{set follow-fork-mode}}.
2467
2468@table @code
2469@kindex set follow-fork-mode
2470@item set follow-fork-mode @var{mode}
2471Set the debugger response to a program call of @code{fork} or
2472@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 2473process. The @var{mode} argument can be:
c906108c
SS
2474
2475@table @code
2476@item parent
2477The original process is debugged after a fork. The child process runs
2df3850c 2478unimpeded. This is the default.
c906108c
SS
2479
2480@item child
2481The new process is debugged after a fork. The parent process runs
2482unimpeded.
2483
c906108c
SS
2484@end table
2485
9c16f35a 2486@kindex show follow-fork-mode
c906108c 2487@item show follow-fork-mode
2df3850c 2488Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2489@end table
2490
2491If you ask to debug a child process and a @code{vfork} is followed by an
2492@code{exec}, @value{GDBN} executes the new target up to the first
2493breakpoint in the new target. If you have a breakpoint set on
2494@code{main} in your original program, the breakpoint will also be set on
2495the child process's @code{main}.
2496
2497When a child process is spawned by @code{vfork}, you cannot debug the
2498child or parent until an @code{exec} call completes.
2499
2500If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2501call executes, the new target restarts. To restart the parent process,
2502use the @code{file} command with the parent executable name as its
2503argument.
2504
2505You can use the @code{catch} command to make @value{GDBN} stop whenever
2506a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2507Catchpoints, ,Setting catchpoints}.
c906108c 2508
6d2ebf8b 2509@node Stopping
c906108c
SS
2510@chapter Stopping and Continuing
2511
2512The principal purposes of using a debugger are so that you can stop your
2513program before it terminates; or so that, if your program runs into
2514trouble, you can investigate and find out why.
2515
7a292a7a
SS
2516Inside @value{GDBN}, your program may stop for any of several reasons,
2517such as a signal, a breakpoint, or reaching a new line after a
2518@value{GDBN} command such as @code{step}. You may then examine and
2519change variables, set new breakpoints or remove old ones, and then
2520continue execution. Usually, the messages shown by @value{GDBN} provide
2521ample explanation of the status of your program---but you can also
2522explicitly request this information at any time.
c906108c
SS
2523
2524@table @code
2525@kindex info program
2526@item info program
2527Display information about the status of your program: whether it is
7a292a7a 2528running or not, what process it is, and why it stopped.
c906108c
SS
2529@end table
2530
2531@menu
2532* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2533* Continuing and Stepping:: Resuming execution
c906108c 2534* Signals:: Signals
c906108c 2535* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2536@end menu
2537
6d2ebf8b 2538@node Breakpoints
c906108c
SS
2539@section Breakpoints, watchpoints, and catchpoints
2540
2541@cindex breakpoints
2542A @dfn{breakpoint} makes your program stop whenever a certain point in
2543the program is reached. For each breakpoint, you can add conditions to
2544control in finer detail whether your program stops. You can set
2545breakpoints with the @code{break} command and its variants (@pxref{Set
2546Breaks, ,Setting breakpoints}), to specify the place where your program
2547should stop by line number, function name or exact address in the
2548program.
2549
09d4efe1
EZ
2550On some systems, you can set breakpoints in shared libraries before
2551the executable is run. There is a minor limitation on HP-UX systems:
2552you must wait until the executable is run in order to set breakpoints
2553in shared library routines that are not called directly by the program
2554(for example, routines that are arguments in a @code{pthread_create}
2555call).
c906108c
SS
2556
2557@cindex watchpoints
2558@cindex memory tracing
2559@cindex breakpoint on memory address
2560@cindex breakpoint on variable modification
2561A @dfn{watchpoint} is a special breakpoint that stops your program
2562when the value of an expression changes. You must use a different
2563command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2564watchpoints}), but aside from that, you can manage a watchpoint like
2565any other breakpoint: you enable, disable, and delete both breakpoints
2566and watchpoints using the same commands.
2567
2568You can arrange to have values from your program displayed automatically
2569whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2570Automatic display}.
2571
2572@cindex catchpoints
2573@cindex breakpoint on events
2574A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2575when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2576exception or the loading of a library. As with watchpoints, you use a
2577different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2578catchpoints}), but aside from that, you can manage a catchpoint like any
2579other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2580@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2581
2582@cindex breakpoint numbers
2583@cindex numbers for breakpoints
2584@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2585catchpoint when you create it; these numbers are successive integers
2586starting with one. In many of the commands for controlling various
2587features of breakpoints you use the breakpoint number to say which
2588breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2589@dfn{disabled}; if disabled, it has no effect on your program until you
2590enable it again.
2591
c5394b80
JM
2592@cindex breakpoint ranges
2593@cindex ranges of breakpoints
2594Some @value{GDBN} commands accept a range of breakpoints on which to
2595operate. A breakpoint range is either a single breakpoint number, like
2596@samp{5}, or two such numbers, in increasing order, separated by a
2597hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2598all breakpoint in that range are operated on.
2599
c906108c
SS
2600@menu
2601* Set Breaks:: Setting breakpoints
2602* Set Watchpoints:: Setting watchpoints
2603* Set Catchpoints:: Setting catchpoints
2604* Delete Breaks:: Deleting breakpoints
2605* Disabling:: Disabling breakpoints
2606* Conditions:: Break conditions
2607* Break Commands:: Breakpoint command lists
c906108c 2608* Breakpoint Menus:: Breakpoint menus
d4f3574e 2609* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2610* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2611@end menu
2612
6d2ebf8b 2613@node Set Breaks
c906108c
SS
2614@subsection Setting breakpoints
2615
5d161b24 2616@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2617@c consider in particular declaration with/without initialization.
2618@c
2619@c FIXME 2 is there stuff on this already? break at fun start, already init?
2620
2621@kindex break
41afff9a
EZ
2622@kindex b @r{(@code{break})}
2623@vindex $bpnum@r{, convenience variable}
c906108c
SS
2624@cindex latest breakpoint
2625Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2626@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2627number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2628Vars,, Convenience variables}, for a discussion of what you can do with
2629convenience variables.
2630
2631You have several ways to say where the breakpoint should go.
2632
2633@table @code
2634@item break @var{function}
5d161b24 2635Set a breakpoint at entry to function @var{function}.
c906108c 2636When using source languages that permit overloading of symbols, such as
b37052ae 2637C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2638@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2639
2640@item break +@var{offset}
2641@itemx break -@var{offset}
2642Set a breakpoint some number of lines forward or back from the position
d4f3574e 2643at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2644(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2645
2646@item break @var{linenum}
2647Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2648The current source file is the last file whose source text was printed.
2649The breakpoint will stop your program just before it executes any of the
c906108c
SS
2650code on that line.
2651
2652@item break @var{filename}:@var{linenum}
2653Set a breakpoint at line @var{linenum} in source file @var{filename}.
2654
2655@item break @var{filename}:@var{function}
2656Set a breakpoint at entry to function @var{function} found in file
2657@var{filename}. Specifying a file name as well as a function name is
2658superfluous except when multiple files contain similarly named
2659functions.
2660
2661@item break *@var{address}
2662Set a breakpoint at address @var{address}. You can use this to set
2663breakpoints in parts of your program which do not have debugging
2664information or source files.
2665
2666@item break
2667When called without any arguments, @code{break} sets a breakpoint at
2668the next instruction to be executed in the selected stack frame
2669(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2670innermost, this makes your program stop as soon as control
2671returns to that frame. This is similar to the effect of a
2672@code{finish} command in the frame inside the selected frame---except
2673that @code{finish} does not leave an active breakpoint. If you use
2674@code{break} without an argument in the innermost frame, @value{GDBN} stops
2675the next time it reaches the current location; this may be useful
2676inside loops.
2677
2678@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2679least one instruction has been executed. If it did not do this, you
2680would be unable to proceed past a breakpoint without first disabling the
2681breakpoint. This rule applies whether or not the breakpoint already
2682existed when your program stopped.
2683
2684@item break @dots{} if @var{cond}
2685Set a breakpoint with condition @var{cond}; evaluate the expression
2686@var{cond} each time the breakpoint is reached, and stop only if the
2687value is nonzero---that is, if @var{cond} evaluates as true.
2688@samp{@dots{}} stands for one of the possible arguments described
2689above (or no argument) specifying where to break. @xref{Conditions,
2690,Break conditions}, for more information on breakpoint conditions.
2691
2692@kindex tbreak
2693@item tbreak @var{args}
2694Set a breakpoint enabled only for one stop. @var{args} are the
2695same as for the @code{break} command, and the breakpoint is set in the same
2696way, but the breakpoint is automatically deleted after the first time your
2697program stops there. @xref{Disabling, ,Disabling breakpoints}.
2698
c906108c 2699@kindex hbreak
ba04e063 2700@cindex hardware breakpoints
c906108c 2701@item hbreak @var{args}
d4f3574e
SS
2702Set a hardware-assisted breakpoint. @var{args} are the same as for the
2703@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2704breakpoint requires hardware support and some target hardware may not
2705have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2706debugging, so you can set a breakpoint at an instruction without
2707changing the instruction. This can be used with the new trap-generation
09d4efe1 2708provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
2709will generate traps when a program accesses some data or instruction
2710address that is assigned to the debug registers. However the hardware
2711breakpoint registers can take a limited number of breakpoints. For
2712example, on the DSU, only two data breakpoints can be set at a time, and
2713@value{GDBN} will reject this command if more than two are used. Delete
2714or disable unused hardware breakpoints before setting new ones
2715(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
9c16f35a
EZ
2716For remote targets, you can restrict the number of hardware
2717breakpoints @value{GDBN} will use, see @ref{set remote
2718hardware-breakpoint-limit}.
501eef12 2719
c906108c
SS
2720
2721@kindex thbreak
2722@item thbreak @var{args}
2723Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2724are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2725the same way. However, like the @code{tbreak} command,
c906108c
SS
2726the breakpoint is automatically deleted after the
2727first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2728command, the breakpoint requires hardware support and some target hardware
2729may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2730See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2731
2732@kindex rbreak
2733@cindex regular expression
c45da7e6
EZ
2734@cindex breakpoints in functions matching a regexp
2735@cindex set breakpoints in many functions
c906108c 2736@item rbreak @var{regex}
c906108c 2737Set breakpoints on all functions matching the regular expression
11cf8741
JM
2738@var{regex}. This command sets an unconditional breakpoint on all
2739matches, printing a list of all breakpoints it set. Once these
2740breakpoints are set, they are treated just like the breakpoints set with
2741the @code{break} command. You can delete them, disable them, or make
2742them conditional the same way as any other breakpoint.
2743
2744The syntax of the regular expression is the standard one used with tools
2745like @file{grep}. Note that this is different from the syntax used by
2746shells, so for instance @code{foo*} matches all functions that include
2747an @code{fo} followed by zero or more @code{o}s. There is an implicit
2748@code{.*} leading and trailing the regular expression you supply, so to
2749match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2750
f7dc1244 2751@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2752When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2753breakpoints on overloaded functions that are not members of any special
2754classes.
c906108c 2755
f7dc1244
EZ
2756@cindex set breakpoints on all functions
2757The @code{rbreak} command can be used to set breakpoints in
2758@strong{all} the functions in a program, like this:
2759
2760@smallexample
2761(@value{GDBP}) rbreak .
2762@end smallexample
2763
c906108c
SS
2764@kindex info breakpoints
2765@cindex @code{$_} and @code{info breakpoints}
2766@item info breakpoints @r{[}@var{n}@r{]}
2767@itemx info break @r{[}@var{n}@r{]}
2768@itemx info watchpoints @r{[}@var{n}@r{]}
2769Print a table of all breakpoints, watchpoints, and catchpoints set and
2770not deleted, with the following columns for each breakpoint:
2771
2772@table @emph
2773@item Breakpoint Numbers
2774@item Type
2775Breakpoint, watchpoint, or catchpoint.
2776@item Disposition
2777Whether the breakpoint is marked to be disabled or deleted when hit.
2778@item Enabled or Disabled
2779Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2780that are not enabled.
2781@item Address
2650777c
JJ
2782Where the breakpoint is in your program, as a memory address. If the
2783breakpoint is pending (see below for details) on a future load of a shared library, the address
2784will be listed as @samp{<PENDING>}.
c906108c
SS
2785@item What
2786Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
2787line number. For a pending breakpoint, the original string passed to
2788the breakpoint command will be listed as it cannot be resolved until
2789the appropriate shared library is loaded in the future.
c906108c
SS
2790@end table
2791
2792@noindent
2793If a breakpoint is conditional, @code{info break} shows the condition on
2794the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
2795are listed after that. A pending breakpoint is allowed to have a condition
2796specified for it. The condition is not parsed for validity until a shared
2797library is loaded that allows the pending breakpoint to resolve to a
2798valid location.
c906108c
SS
2799
2800@noindent
2801@code{info break} with a breakpoint
2802number @var{n} as argument lists only that breakpoint. The
2803convenience variable @code{$_} and the default examining-address for
2804the @code{x} command are set to the address of the last breakpoint
5d161b24 2805listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2806
2807@noindent
2808@code{info break} displays a count of the number of times the breakpoint
2809has been hit. This is especially useful in conjunction with the
2810@code{ignore} command. You can ignore a large number of breakpoint
2811hits, look at the breakpoint info to see how many times the breakpoint
2812was hit, and then run again, ignoring one less than that number. This
2813will get you quickly to the last hit of that breakpoint.
2814@end table
2815
2816@value{GDBN} allows you to set any number of breakpoints at the same place in
2817your program. There is nothing silly or meaningless about this. When
2818the breakpoints are conditional, this is even useful
2819(@pxref{Conditions, ,Break conditions}).
2820
2650777c 2821@cindex pending breakpoints
dd79a6cf
JJ
2822If a specified breakpoint location cannot be found, it may be due to the fact
2823that the location is in a shared library that is yet to be loaded. In such
2824a case, you may want @value{GDBN} to create a special breakpoint (known as
2825a @dfn{pending breakpoint}) that
2826attempts to resolve itself in the future when an appropriate shared library
2827gets loaded.
2828
2829Pending breakpoints are useful to set at the start of your
2650777c
JJ
2830@value{GDBN} session for locations that you know will be dynamically loaded
2831later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
2832a check is made to see if the load resolves any pending breakpoint locations.
2833If a pending breakpoint location gets resolved,
2834a regular breakpoint is created and the original pending breakpoint is removed.
2835
2836@value{GDBN} provides some additional commands for controlling pending
2837breakpoint support:
2838
2839@kindex set breakpoint pending
2840@kindex show breakpoint pending
2841@table @code
2842@item set breakpoint pending auto
2843This is the default behavior. When @value{GDBN} cannot find the breakpoint
2844location, it queries you whether a pending breakpoint should be created.
2845
2846@item set breakpoint pending on
2847This indicates that an unrecognized breakpoint location should automatically
2848result in a pending breakpoint being created.
2849
2850@item set breakpoint pending off
2851This indicates that pending breakpoints are not to be created. Any
2852unrecognized breakpoint location results in an error. This setting does
2853not affect any pending breakpoints previously created.
2854
2855@item show breakpoint pending
2856Show the current behavior setting for creating pending breakpoints.
2857@end table
2650777c 2858
649e03f6
RM
2859@cindex operations allowed on pending breakpoints
2860Normal breakpoint operations apply to pending breakpoints as well. You may
2861specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
2862breakpoint is reached. You can also enable or disable
2863the pending breakpoint. When you specify a condition for a pending breakpoint,
2864the parsing of the condition will be deferred until the point where the
2865pending breakpoint location is resolved. Disabling a pending breakpoint
2866tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
2867shared library load. When a pending breakpoint is re-enabled,
649e03f6 2868@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
2869This is done because any number of shared library loads could have
2870occurred since the time the breakpoint was disabled and one or more
2871of these loads could resolve the location.
2872
c906108c
SS
2873@cindex negative breakpoint numbers
2874@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2875@value{GDBN} itself sometimes sets breakpoints in your program for
2876special purposes, such as proper handling of @code{longjmp} (in C
2877programs). These internal breakpoints are assigned negative numbers,
2878starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2879You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2880@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2881
2882
6d2ebf8b 2883@node Set Watchpoints
c906108c
SS
2884@subsection Setting watchpoints
2885
2886@cindex setting watchpoints
c906108c
SS
2887You can use a watchpoint to stop execution whenever the value of an
2888expression changes, without having to predict a particular place where
2889this may happen.
2890
82f2d802
EZ
2891@cindex software watchpoints
2892@cindex hardware watchpoints
c906108c 2893Depending on your system, watchpoints may be implemented in software or
2df3850c 2894hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2895program and testing the variable's value each time, which is hundreds of
2896times slower than normal execution. (But this may still be worth it, to
2897catch errors where you have no clue what part of your program is the
2898culprit.)
2899
82f2d802
EZ
2900On some systems, such as HP-UX, @sc{gnu}/Linux and most other
2901x86-based targets, @value{GDBN} includes support for hardware
2902watchpoints, which do not slow down the running of your program.
c906108c
SS
2903
2904@table @code
2905@kindex watch
2906@item watch @var{expr}
2907Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2908is written into by the program and its value changes.
2909
2910@kindex rwatch
2911@item rwatch @var{expr}
09d4efe1
EZ
2912Set a watchpoint that will break when the value of @var{expr} is read
2913by the program.
c906108c
SS
2914
2915@kindex awatch
2916@item awatch @var{expr}
09d4efe1
EZ
2917Set a watchpoint that will break when @var{expr} is either read from
2918or written into by the program.
c906108c
SS
2919
2920@kindex info watchpoints
2921@item info watchpoints
2922This command prints a list of watchpoints, breakpoints, and catchpoints;
09d4efe1 2923it is the same as @code{info break} (@pxref{Set Breaks}).
c906108c
SS
2924@end table
2925
2926@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2927watchpoints execute very quickly, and the debugger reports a change in
2928value at the exact instruction where the change occurs. If @value{GDBN}
2929cannot set a hardware watchpoint, it sets a software watchpoint, which
2930executes more slowly and reports the change in value at the next
82f2d802
EZ
2931@emph{statement}, not the instruction, after the change occurs.
2932
82f2d802
EZ
2933@cindex use only software watchpoints
2934You can force @value{GDBN} to use only software watchpoints with the
2935@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
2936zero, @value{GDBN} will never try to use hardware watchpoints, even if
2937the underlying system supports them. (Note that hardware-assisted
2938watchpoints that were set @emph{before} setting
2939@code{can-use-hw-watchpoints} to zero will still use the hardware
2940mechanism of watching expressiion values.)
c906108c 2941
9c16f35a
EZ
2942@table @code
2943@item set can-use-hw-watchpoints
2944@kindex set can-use-hw-watchpoints
2945Set whether or not to use hardware watchpoints.
2946
2947@item show can-use-hw-watchpoints
2948@kindex show can-use-hw-watchpoints
2949Show the current mode of using hardware watchpoints.
2950@end table
2951
2952For remote targets, you can restrict the number of hardware
2953watchpoints @value{GDBN} will use, see @ref{set remote
2954hardware-breakpoint-limit}.
2955
c906108c
SS
2956When you issue the @code{watch} command, @value{GDBN} reports
2957
474c8240 2958@smallexample
c906108c 2959Hardware watchpoint @var{num}: @var{expr}
474c8240 2960@end smallexample
c906108c
SS
2961
2962@noindent
2963if it was able to set a hardware watchpoint.
2964
7be570e7
JM
2965Currently, the @code{awatch} and @code{rwatch} commands can only set
2966hardware watchpoints, because accesses to data that don't change the
2967value of the watched expression cannot be detected without examining
2968every instruction as it is being executed, and @value{GDBN} does not do
2969that currently. If @value{GDBN} finds that it is unable to set a
2970hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2971will print a message like this:
2972
2973@smallexample
2974Expression cannot be implemented with read/access watchpoint.
2975@end smallexample
2976
2977Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2978data type of the watched expression is wider than what a hardware
2979watchpoint on the target machine can handle. For example, some systems
2980can only watch regions that are up to 4 bytes wide; on such systems you
2981cannot set hardware watchpoints for an expression that yields a
2982double-precision floating-point number (which is typically 8 bytes
2983wide). As a work-around, it might be possible to break the large region
2984into a series of smaller ones and watch them with separate watchpoints.
2985
2986If you set too many hardware watchpoints, @value{GDBN} might be unable
2987to insert all of them when you resume the execution of your program.
2988Since the precise number of active watchpoints is unknown until such
2989time as the program is about to be resumed, @value{GDBN} might not be
2990able to warn you about this when you set the watchpoints, and the
2991warning will be printed only when the program is resumed:
2992
2993@smallexample
2994Hardware watchpoint @var{num}: Could not insert watchpoint
2995@end smallexample
2996
2997@noindent
2998If this happens, delete or disable some of the watchpoints.
2999
3000The SPARClite DSU will generate traps when a program accesses some data
3001or instruction address that is assigned to the debug registers. For the
3002data addresses, DSU facilitates the @code{watch} command. However the
3003hardware breakpoint registers can only take two data watchpoints, and
3004both watchpoints must be the same kind. For example, you can set two
3005watchpoints with @code{watch} commands, two with @code{rwatch} commands,
3006@strong{or} two with @code{awatch} commands, but you cannot set one
3007watchpoint with one command and the other with a different command.
c906108c
SS
3008@value{GDBN} will reject the command if you try to mix watchpoints.
3009Delete or disable unused watchpoint commands before setting new ones.
3010
3011If you call a function interactively using @code{print} or @code{call},
2df3850c 3012any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
3013kind of breakpoint or the call completes.
3014
7be570e7
JM
3015@value{GDBN} automatically deletes watchpoints that watch local
3016(automatic) variables, or expressions that involve such variables, when
3017they go out of scope, that is, when the execution leaves the block in
3018which these variables were defined. In particular, when the program
3019being debugged terminates, @emph{all} local variables go out of scope,
3020and so only watchpoints that watch global variables remain set. If you
3021rerun the program, you will need to set all such watchpoints again. One
3022way of doing that would be to set a code breakpoint at the entry to the
3023@code{main} function and when it breaks, set all the watchpoints.
3024
c906108c
SS
3025@quotation
3026@cindex watchpoints and threads
3027@cindex threads and watchpoints
c906108c
SS
3028@emph{Warning:} In multi-thread programs, watchpoints have only limited
3029usefulness. With the current watchpoint implementation, @value{GDBN}
3030can only watch the value of an expression @emph{in a single thread}. If
3031you are confident that the expression can only change due to the current
3032thread's activity (and if you are also confident that no other thread
3033can become current), then you can use watchpoints as usual. However,
3034@value{GDBN} may not notice when a non-current thread's activity changes
3035the expression.
53a5351d 3036
d4f3574e 3037@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
3038@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
3039have only limited usefulness. If @value{GDBN} creates a software
3040watchpoint, it can only watch the value of an expression @emph{in a
3041single thread}. If you are confident that the expression can only
3042change due to the current thread's activity (and if you are also
3043confident that no other thread can become current), then you can use
3044software watchpoints as usual. However, @value{GDBN} may not notice
3045when a non-current thread's activity changes the expression. (Hardware
3046watchpoints, in contrast, watch an expression in all threads.)
c906108c 3047@end quotation
c906108c 3048
501eef12
AC
3049@xref{set remote hardware-watchpoint-limit}.
3050
6d2ebf8b 3051@node Set Catchpoints
c906108c 3052@subsection Setting catchpoints
d4f3574e 3053@cindex catchpoints, setting
c906108c
SS
3054@cindex exception handlers
3055@cindex event handling
3056
3057You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 3058kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
3059shared library. Use the @code{catch} command to set a catchpoint.
3060
3061@table @code
3062@kindex catch
3063@item catch @var{event}
3064Stop when @var{event} occurs. @var{event} can be any of the following:
3065@table @code
3066@item throw
4644b6e3 3067@cindex stop on C@t{++} exceptions
b37052ae 3068The throwing of a C@t{++} exception.
c906108c
SS
3069
3070@item catch
b37052ae 3071The catching of a C@t{++} exception.
c906108c
SS
3072
3073@item exec
4644b6e3 3074@cindex break on fork/exec
c906108c
SS
3075A call to @code{exec}. This is currently only available for HP-UX.
3076
3077@item fork
c906108c
SS
3078A call to @code{fork}. This is currently only available for HP-UX.
3079
3080@item vfork
c906108c
SS
3081A call to @code{vfork}. This is currently only available for HP-UX.
3082
3083@item load
3084@itemx load @var{libname}
4644b6e3 3085@cindex break on load/unload of shared library
c906108c
SS
3086The dynamic loading of any shared library, or the loading of the library
3087@var{libname}. This is currently only available for HP-UX.
3088
3089@item unload
3090@itemx unload @var{libname}
c906108c
SS
3091The unloading of any dynamically loaded shared library, or the unloading
3092of the library @var{libname}. This is currently only available for HP-UX.
3093@end table
3094
3095@item tcatch @var{event}
3096Set a catchpoint that is enabled only for one stop. The catchpoint is
3097automatically deleted after the first time the event is caught.
3098
3099@end table
3100
3101Use the @code{info break} command to list the current catchpoints.
3102
b37052ae 3103There are currently some limitations to C@t{++} exception handling
c906108c
SS
3104(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3105
3106@itemize @bullet
3107@item
3108If you call a function interactively, @value{GDBN} normally returns
3109control to you when the function has finished executing. If the call
3110raises an exception, however, the call may bypass the mechanism that
3111returns control to you and cause your program either to abort or to
3112simply continue running until it hits a breakpoint, catches a signal
3113that @value{GDBN} is listening for, or exits. This is the case even if
3114you set a catchpoint for the exception; catchpoints on exceptions are
3115disabled within interactive calls.
3116
3117@item
3118You cannot raise an exception interactively.
3119
3120@item
3121You cannot install an exception handler interactively.
3122@end itemize
3123
3124@cindex raise exceptions
3125Sometimes @code{catch} is not the best way to debug exception handling:
3126if you need to know exactly where an exception is raised, it is better to
3127stop @emph{before} the exception handler is called, since that way you
3128can see the stack before any unwinding takes place. If you set a
3129breakpoint in an exception handler instead, it may not be easy to find
3130out where the exception was raised.
3131
3132To stop just before an exception handler is called, you need some
b37052ae 3133knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
3134raised by calling a library function named @code{__raise_exception}
3135which has the following ANSI C interface:
3136
474c8240 3137@smallexample
c906108c 3138 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
3139 @var{id} is the exception identifier. */
3140 void __raise_exception (void **addr, void *id);
474c8240 3141@end smallexample
c906108c
SS
3142
3143@noindent
3144To make the debugger catch all exceptions before any stack
3145unwinding takes place, set a breakpoint on @code{__raise_exception}
3146(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
3147
3148With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
3149that depends on the value of @var{id}, you can stop your program when
3150a specific exception is raised. You can use multiple conditional
3151breakpoints to stop your program when any of a number of exceptions are
3152raised.
3153
3154
6d2ebf8b 3155@node Delete Breaks
c906108c
SS
3156@subsection Deleting breakpoints
3157
3158@cindex clearing breakpoints, watchpoints, catchpoints
3159@cindex deleting breakpoints, watchpoints, catchpoints
3160It is often necessary to eliminate a breakpoint, watchpoint, or
3161catchpoint once it has done its job and you no longer want your program
3162to stop there. This is called @dfn{deleting} the breakpoint. A
3163breakpoint that has been deleted no longer exists; it is forgotten.
3164
3165With the @code{clear} command you can delete breakpoints according to
3166where they are in your program. With the @code{delete} command you can
3167delete individual breakpoints, watchpoints, or catchpoints by specifying
3168their breakpoint numbers.
3169
3170It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3171automatically ignores breakpoints on the first instruction to be executed
3172when you continue execution without changing the execution address.
3173
3174@table @code
3175@kindex clear
3176@item clear
3177Delete any breakpoints at the next instruction to be executed in the
3178selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3179the innermost frame is selected, this is a good way to delete a
3180breakpoint where your program just stopped.
3181
3182@item clear @var{function}
3183@itemx clear @var{filename}:@var{function}
09d4efe1 3184Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
3185
3186@item clear @var{linenum}
3187@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
3188Delete any breakpoints set at or within the code of the specified
3189@var{linenum} of the specified @var{filename}.
c906108c
SS
3190
3191@cindex delete breakpoints
3192@kindex delete
41afff9a 3193@kindex d @r{(@code{delete})}
c5394b80
JM
3194@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3195Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3196ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3197breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3198confirm off}). You can abbreviate this command as @code{d}.
3199@end table
3200
6d2ebf8b 3201@node Disabling
c906108c
SS
3202@subsection Disabling breakpoints
3203
4644b6e3 3204@cindex enable/disable a breakpoint
c906108c
SS
3205Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3206prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3207it had been deleted, but remembers the information on the breakpoint so
3208that you can @dfn{enable} it again later.
3209
3210You disable and enable breakpoints, watchpoints, and catchpoints with
3211the @code{enable} and @code{disable} commands, optionally specifying one
3212or more breakpoint numbers as arguments. Use @code{info break} or
3213@code{info watch} to print a list of breakpoints, watchpoints, and
3214catchpoints if you do not know which numbers to use.
3215
3216A breakpoint, watchpoint, or catchpoint can have any of four different
3217states of enablement:
3218
3219@itemize @bullet
3220@item
3221Enabled. The breakpoint stops your program. A breakpoint set
3222with the @code{break} command starts out in this state.
3223@item
3224Disabled. The breakpoint has no effect on your program.
3225@item
3226Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3227disabled.
c906108c
SS
3228@item
3229Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3230immediately after it does so it is deleted permanently. A breakpoint
3231set with the @code{tbreak} command starts out in this state.
c906108c
SS
3232@end itemize
3233
3234You can use the following commands to enable or disable breakpoints,
3235watchpoints, and catchpoints:
3236
3237@table @code
c906108c 3238@kindex disable
41afff9a 3239@kindex dis @r{(@code{disable})}
c5394b80 3240@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3241Disable the specified breakpoints---or all breakpoints, if none are
3242listed. A disabled breakpoint has no effect but is not forgotten. All
3243options such as ignore-counts, conditions and commands are remembered in
3244case the breakpoint is enabled again later. You may abbreviate
3245@code{disable} as @code{dis}.
3246
c906108c 3247@kindex enable
c5394b80 3248@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3249Enable the specified breakpoints (or all defined breakpoints). They
3250become effective once again in stopping your program.
3251
c5394b80 3252@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3253Enable the specified breakpoints temporarily. @value{GDBN} disables any
3254of these breakpoints immediately after stopping your program.
3255
c5394b80 3256@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3257Enable the specified breakpoints to work once, then die. @value{GDBN}
3258deletes any of these breakpoints as soon as your program stops there.
09d4efe1 3259Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
3260@end table
3261
d4f3574e
SS
3262@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3263@c confusing: tbreak is also initially enabled.
c906108c
SS
3264Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3265,Setting breakpoints}), breakpoints that you set are initially enabled;
3266subsequently, they become disabled or enabled only when you use one of
3267the commands above. (The command @code{until} can set and delete a
3268breakpoint of its own, but it does not change the state of your other
3269breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3270stepping}.)
3271
6d2ebf8b 3272@node Conditions
c906108c
SS
3273@subsection Break conditions
3274@cindex conditional breakpoints
3275@cindex breakpoint conditions
3276
3277@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3278@c in particular for a watchpoint?
c906108c
SS
3279The simplest sort of breakpoint breaks every time your program reaches a
3280specified place. You can also specify a @dfn{condition} for a
3281breakpoint. A condition is just a Boolean expression in your
3282programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3283a condition evaluates the expression each time your program reaches it,
3284and your program stops only if the condition is @emph{true}.
3285
3286This is the converse of using assertions for program validation; in that
3287situation, you want to stop when the assertion is violated---that is,
3288when the condition is false. In C, if you want to test an assertion expressed
3289by the condition @var{assert}, you should set the condition
3290@samp{! @var{assert}} on the appropriate breakpoint.
3291
3292Conditions are also accepted for watchpoints; you may not need them,
3293since a watchpoint is inspecting the value of an expression anyhow---but
3294it might be simpler, say, to just set a watchpoint on a variable name,
3295and specify a condition that tests whether the new value is an interesting
3296one.
3297
3298Break conditions can have side effects, and may even call functions in
3299your program. This can be useful, for example, to activate functions
3300that log program progress, or to use your own print functions to
3301format special data structures. The effects are completely predictable
3302unless there is another enabled breakpoint at the same address. (In
3303that case, @value{GDBN} might see the other breakpoint first and stop your
3304program without checking the condition of this one.) Note that
d4f3574e
SS
3305breakpoint commands are usually more convenient and flexible than break
3306conditions for the
c906108c
SS
3307purpose of performing side effects when a breakpoint is reached
3308(@pxref{Break Commands, ,Breakpoint command lists}).
3309
3310Break conditions can be specified when a breakpoint is set, by using
3311@samp{if} in the arguments to the @code{break} command. @xref{Set
3312Breaks, ,Setting breakpoints}. They can also be changed at any time
3313with the @code{condition} command.
53a5351d 3314
c906108c
SS
3315You can also use the @code{if} keyword with the @code{watch} command.
3316The @code{catch} command does not recognize the @code{if} keyword;
3317@code{condition} is the only way to impose a further condition on a
3318catchpoint.
c906108c
SS
3319
3320@table @code
3321@kindex condition
3322@item condition @var{bnum} @var{expression}
3323Specify @var{expression} as the break condition for breakpoint,
3324watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3325breakpoint @var{bnum} stops your program only if the value of
3326@var{expression} is true (nonzero, in C). When you use
3327@code{condition}, @value{GDBN} checks @var{expression} immediately for
3328syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3329referents in the context of your breakpoint. If @var{expression} uses
3330symbols not referenced in the context of the breakpoint, @value{GDBN}
3331prints an error message:
3332
474c8240 3333@smallexample
d4f3574e 3334No symbol "foo" in current context.
474c8240 3335@end smallexample
d4f3574e
SS
3336
3337@noindent
c906108c
SS
3338@value{GDBN} does
3339not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3340command (or a command that sets a breakpoint with a condition, like
3341@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3342
3343@item condition @var{bnum}
3344Remove the condition from breakpoint number @var{bnum}. It becomes
3345an ordinary unconditional breakpoint.
3346@end table
3347
3348@cindex ignore count (of breakpoint)
3349A special case of a breakpoint condition is to stop only when the
3350breakpoint has been reached a certain number of times. This is so
3351useful that there is a special way to do it, using the @dfn{ignore
3352count} of the breakpoint. Every breakpoint has an ignore count, which
3353is an integer. Most of the time, the ignore count is zero, and
3354therefore has no effect. But if your program reaches a breakpoint whose
3355ignore count is positive, then instead of stopping, it just decrements
3356the ignore count by one and continues. As a result, if the ignore count
3357value is @var{n}, the breakpoint does not stop the next @var{n} times
3358your program reaches it.
3359
3360@table @code
3361@kindex ignore
3362@item ignore @var{bnum} @var{count}
3363Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3364The next @var{count} times the breakpoint is reached, your program's
3365execution does not stop; other than to decrement the ignore count, @value{GDBN}
3366takes no action.
3367
3368To make the breakpoint stop the next time it is reached, specify
3369a count of zero.
3370
3371When you use @code{continue} to resume execution of your program from a
3372breakpoint, you can specify an ignore count directly as an argument to
3373@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3374Stepping,,Continuing and stepping}.
3375
3376If a breakpoint has a positive ignore count and a condition, the
3377condition is not checked. Once the ignore count reaches zero,
3378@value{GDBN} resumes checking the condition.
3379
3380You could achieve the effect of the ignore count with a condition such
3381as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3382is decremented each time. @xref{Convenience Vars, ,Convenience
3383variables}.
3384@end table
3385
3386Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3387
3388
6d2ebf8b 3389@node Break Commands
c906108c
SS
3390@subsection Breakpoint command lists
3391
3392@cindex breakpoint commands
3393You can give any breakpoint (or watchpoint or catchpoint) a series of
3394commands to execute when your program stops due to that breakpoint. For
3395example, you might want to print the values of certain expressions, or
3396enable other breakpoints.
3397
3398@table @code
3399@kindex commands
3400@kindex end
3401@item commands @r{[}@var{bnum}@r{]}
3402@itemx @dots{} @var{command-list} @dots{}
3403@itemx end
3404Specify a list of commands for breakpoint number @var{bnum}. The commands
3405themselves appear on the following lines. Type a line containing just
3406@code{end} to terminate the commands.
3407
3408To remove all commands from a breakpoint, type @code{commands} and
3409follow it immediately with @code{end}; that is, give no commands.
3410
3411With no @var{bnum} argument, @code{commands} refers to the last
3412breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3413recently encountered).
3414@end table
3415
3416Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3417disabled within a @var{command-list}.
3418
3419You can use breakpoint commands to start your program up again. Simply
3420use the @code{continue} command, or @code{step}, or any other command
3421that resumes execution.
3422
3423Any other commands in the command list, after a command that resumes
3424execution, are ignored. This is because any time you resume execution
3425(even with a simple @code{next} or @code{step}), you may encounter
3426another breakpoint---which could have its own command list, leading to
3427ambiguities about which list to execute.
3428
3429@kindex silent
3430If the first command you specify in a command list is @code{silent}, the
3431usual message about stopping at a breakpoint is not printed. This may
3432be desirable for breakpoints that are to print a specific message and
3433then continue. If none of the remaining commands print anything, you
3434see no sign that the breakpoint was reached. @code{silent} is
3435meaningful only at the beginning of a breakpoint command list.
3436
3437The commands @code{echo}, @code{output}, and @code{printf} allow you to
3438print precisely controlled output, and are often useful in silent
3439breakpoints. @xref{Output, ,Commands for controlled output}.
3440
3441For example, here is how you could use breakpoint commands to print the
3442value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3443
474c8240 3444@smallexample
c906108c
SS
3445break foo if x>0
3446commands
3447silent
3448printf "x is %d\n",x
3449cont
3450end
474c8240 3451@end smallexample
c906108c
SS
3452
3453One application for breakpoint commands is to compensate for one bug so
3454you can test for another. Put a breakpoint just after the erroneous line
3455of code, give it a condition to detect the case in which something
3456erroneous has been done, and give it commands to assign correct values
3457to any variables that need them. End with the @code{continue} command
3458so that your program does not stop, and start with the @code{silent}
3459command so that no output is produced. Here is an example:
3460
474c8240 3461@smallexample
c906108c
SS
3462break 403
3463commands
3464silent
3465set x = y + 4
3466cont
3467end
474c8240 3468@end smallexample
c906108c 3469
6d2ebf8b 3470@node Breakpoint Menus
c906108c
SS
3471@subsection Breakpoint menus
3472@cindex overloading
3473@cindex symbol overloading
3474
b383017d 3475Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3476single function name
c906108c
SS
3477to be defined several times, for application in different contexts.
3478This is called @dfn{overloading}. When a function name is overloaded,
3479@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3480a breakpoint. If you realize this is a problem, you can use
3481something like @samp{break @var{function}(@var{types})} to specify which
3482particular version of the function you want. Otherwise, @value{GDBN} offers
3483you a menu of numbered choices for different possible breakpoints, and
3484waits for your selection with the prompt @samp{>}. The first two
3485options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3486sets a breakpoint at each definition of @var{function}, and typing
3487@kbd{0} aborts the @code{break} command without setting any new
3488breakpoints.
3489
3490For example, the following session excerpt shows an attempt to set a
3491breakpoint at the overloaded symbol @code{String::after}.
3492We choose three particular definitions of that function name:
3493
3494@c FIXME! This is likely to change to show arg type lists, at least
3495@smallexample
3496@group
3497(@value{GDBP}) b String::after
3498[0] cancel
3499[1] all
3500[2] file:String.cc; line number:867
3501[3] file:String.cc; line number:860
3502[4] file:String.cc; line number:875
3503[5] file:String.cc; line number:853
3504[6] file:String.cc; line number:846
3505[7] file:String.cc; line number:735
3506> 2 4 6
3507Breakpoint 1 at 0xb26c: file String.cc, line 867.
3508Breakpoint 2 at 0xb344: file String.cc, line 875.
3509Breakpoint 3 at 0xafcc: file String.cc, line 846.
3510Multiple breakpoints were set.
3511Use the "delete" command to delete unwanted
3512 breakpoints.
3513(@value{GDBP})
3514@end group
3515@end smallexample
c906108c
SS
3516
3517@c @ifclear BARETARGET
6d2ebf8b 3518@node Error in Breakpoints
d4f3574e 3519@subsection ``Cannot insert breakpoints''
c906108c
SS
3520@c
3521@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3522@c
d4f3574e
SS
3523Under some operating systems, breakpoints cannot be used in a program if
3524any other process is running that program. In this situation,
5d161b24 3525attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3526@value{GDBN} to print an error message:
3527
474c8240 3528@smallexample
d4f3574e
SS
3529Cannot insert breakpoints.
3530The same program may be running in another process.
474c8240 3531@end smallexample
d4f3574e
SS
3532
3533When this happens, you have three ways to proceed:
3534
3535@enumerate
3536@item
3537Remove or disable the breakpoints, then continue.
3538
3539@item
5d161b24 3540Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3541name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3542that @value{GDBN} should run your program under that name.
d4f3574e
SS
3543Then start your program again.
3544
3545@item
3546Relink your program so that the text segment is nonsharable, using the
3547linker option @samp{-N}. The operating system limitation may not apply
3548to nonsharable executables.
3549@end enumerate
c906108c
SS
3550@c @end ifclear
3551
d4f3574e
SS
3552A similar message can be printed if you request too many active
3553hardware-assisted breakpoints and watchpoints:
3554
3555@c FIXME: the precise wording of this message may change; the relevant
3556@c source change is not committed yet (Sep 3, 1999).
3557@smallexample
3558Stopped; cannot insert breakpoints.
3559You may have requested too many hardware breakpoints and watchpoints.
3560@end smallexample
3561
3562@noindent
3563This message is printed when you attempt to resume the program, since
3564only then @value{GDBN} knows exactly how many hardware breakpoints and
3565watchpoints it needs to insert.
3566
3567When this message is printed, you need to disable or remove some of the
3568hardware-assisted breakpoints and watchpoints, and then continue.
3569
1485d690
KB
3570@node Breakpoint related warnings
3571@subsection ``Breakpoint address adjusted...''
3572@cindex breakpoint address adjusted
3573
3574Some processor architectures place constraints on the addresses at
3575which breakpoints may be placed. For architectures thus constrained,
3576@value{GDBN} will attempt to adjust the breakpoint's address to comply
3577with the constraints dictated by the architecture.
3578
3579One example of such an architecture is the Fujitsu FR-V. The FR-V is
3580a VLIW architecture in which a number of RISC-like instructions may be
3581bundled together for parallel execution. The FR-V architecture
3582constrains the location of a breakpoint instruction within such a
3583bundle to the instruction with the lowest address. @value{GDBN}
3584honors this constraint by adjusting a breakpoint's address to the
3585first in the bundle.
3586
3587It is not uncommon for optimized code to have bundles which contain
3588instructions from different source statements, thus it may happen that
3589a breakpoint's address will be adjusted from one source statement to
3590another. Since this adjustment may significantly alter @value{GDBN}'s
3591breakpoint related behavior from what the user expects, a warning is
3592printed when the breakpoint is first set and also when the breakpoint
3593is hit.
3594
3595A warning like the one below is printed when setting a breakpoint
3596that's been subject to address adjustment:
3597
3598@smallexample
3599warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3600@end smallexample
3601
3602Such warnings are printed both for user settable and @value{GDBN}'s
3603internal breakpoints. If you see one of these warnings, you should
3604verify that a breakpoint set at the adjusted address will have the
3605desired affect. If not, the breakpoint in question may be removed and
b383017d 3606other breakpoints may be set which will have the desired behavior.
1485d690
KB
3607E.g., it may be sufficient to place the breakpoint at a later
3608instruction. A conditional breakpoint may also be useful in some
3609cases to prevent the breakpoint from triggering too often.
3610
3611@value{GDBN} will also issue a warning when stopping at one of these
3612adjusted breakpoints:
3613
3614@smallexample
3615warning: Breakpoint 1 address previously adjusted from 0x00010414
3616to 0x00010410.
3617@end smallexample
3618
3619When this warning is encountered, it may be too late to take remedial
3620action except in cases where the breakpoint is hit earlier or more
3621frequently than expected.
d4f3574e 3622
6d2ebf8b 3623@node Continuing and Stepping
c906108c
SS
3624@section Continuing and stepping
3625
3626@cindex stepping
3627@cindex continuing
3628@cindex resuming execution
3629@dfn{Continuing} means resuming program execution until your program
3630completes normally. In contrast, @dfn{stepping} means executing just
3631one more ``step'' of your program, where ``step'' may mean either one
3632line of source code, or one machine instruction (depending on what
7a292a7a
SS
3633particular command you use). Either when continuing or when stepping,
3634your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3635it stops due to a signal, you may want to use @code{handle}, or use
3636@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3637
3638@table @code
3639@kindex continue
41afff9a
EZ
3640@kindex c @r{(@code{continue})}
3641@kindex fg @r{(resume foreground execution)}
c906108c
SS
3642@item continue @r{[}@var{ignore-count}@r{]}
3643@itemx c @r{[}@var{ignore-count}@r{]}
3644@itemx fg @r{[}@var{ignore-count}@r{]}
3645Resume program execution, at the address where your program last stopped;
3646any breakpoints set at that address are bypassed. The optional argument
3647@var{ignore-count} allows you to specify a further number of times to
3648ignore a breakpoint at this location; its effect is like that of
3649@code{ignore} (@pxref{Conditions, ,Break conditions}).
3650
3651The argument @var{ignore-count} is meaningful only when your program
3652stopped due to a breakpoint. At other times, the argument to
3653@code{continue} is ignored.
3654
d4f3574e
SS
3655The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3656debugged program is deemed to be the foreground program) are provided
3657purely for convenience, and have exactly the same behavior as
3658@code{continue}.
c906108c
SS
3659@end table
3660
3661To resume execution at a different place, you can use @code{return}
3662(@pxref{Returning, ,Returning from a function}) to go back to the
3663calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3664different address}) to go to an arbitrary location in your program.
3665
3666A typical technique for using stepping is to set a breakpoint
3667(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3668beginning of the function or the section of your program where a problem
3669is believed to lie, run your program until it stops at that breakpoint,
3670and then step through the suspect area, examining the variables that are
3671interesting, until you see the problem happen.
3672
3673@table @code
3674@kindex step
41afff9a 3675@kindex s @r{(@code{step})}
c906108c
SS
3676@item step
3677Continue running your program until control reaches a different source
3678line, then stop it and return control to @value{GDBN}. This command is
3679abbreviated @code{s}.
3680
3681@quotation
3682@c "without debugging information" is imprecise; actually "without line
3683@c numbers in the debugging information". (gcc -g1 has debugging info but
3684@c not line numbers). But it seems complex to try to make that
3685@c distinction here.
3686@emph{Warning:} If you use the @code{step} command while control is
3687within a function that was compiled without debugging information,
3688execution proceeds until control reaches a function that does have
3689debugging information. Likewise, it will not step into a function which
3690is compiled without debugging information. To step through functions
3691without debugging information, use the @code{stepi} command, described
3692below.
3693@end quotation
3694
4a92d011
EZ
3695The @code{step} command only stops at the first instruction of a source
3696line. This prevents the multiple stops that could otherwise occur in
3697@code{switch} statements, @code{for} loops, etc. @code{step} continues
3698to stop if a function that has debugging information is called within
3699the line. In other words, @code{step} @emph{steps inside} any functions
3700called within the line.
c906108c 3701
d4f3574e
SS
3702Also, the @code{step} command only enters a function if there is line
3703number information for the function. Otherwise it acts like the
5d161b24 3704@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3705on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3706was any debugging information about the routine.
c906108c
SS
3707
3708@item step @var{count}
3709Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3710breakpoint is reached, or a signal not related to stepping occurs before
3711@var{count} steps, stepping stops right away.
c906108c
SS
3712
3713@kindex next
41afff9a 3714@kindex n @r{(@code{next})}
c906108c
SS
3715@item next @r{[}@var{count}@r{]}
3716Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3717This is similar to @code{step}, but function calls that appear within
3718the line of code are executed without stopping. Execution stops when
3719control reaches a different line of code at the original stack level
3720that was executing when you gave the @code{next} command. This command
3721is abbreviated @code{n}.
c906108c
SS
3722
3723An argument @var{count} is a repeat count, as for @code{step}.
3724
3725
3726@c FIX ME!! Do we delete this, or is there a way it fits in with
3727@c the following paragraph? --- Vctoria
3728@c
3729@c @code{next} within a function that lacks debugging information acts like
3730@c @code{step}, but any function calls appearing within the code of the
3731@c function are executed without stopping.
3732
d4f3574e
SS
3733The @code{next} command only stops at the first instruction of a
3734source line. This prevents multiple stops that could otherwise occur in
4a92d011 3735@code{switch} statements, @code{for} loops, etc.
c906108c 3736
b90a5f51
CF
3737@kindex set step-mode
3738@item set step-mode
3739@cindex functions without line info, and stepping
3740@cindex stepping into functions with no line info
3741@itemx set step-mode on
4a92d011 3742The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3743stop at the first instruction of a function which contains no debug line
3744information rather than stepping over it.
3745
4a92d011
EZ
3746This is useful in cases where you may be interested in inspecting the
3747machine instructions of a function which has no symbolic info and do not
3748want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3749
3750@item set step-mode off
4a92d011 3751Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3752debug information. This is the default.
3753
9c16f35a
EZ
3754@item show step-mode
3755Show whether @value{GDBN} will stop in or step over functions without
3756source line debug information.
3757
c906108c
SS
3758@kindex finish
3759@item finish
3760Continue running until just after function in the selected stack frame
3761returns. Print the returned value (if any).
3762
3763Contrast this with the @code{return} command (@pxref{Returning,
3764,Returning from a function}).
3765
3766@kindex until
41afff9a 3767@kindex u @r{(@code{until})}
09d4efe1 3768@cindex run until specified location
c906108c
SS
3769@item until
3770@itemx u
3771Continue running until a source line past the current line, in the
3772current stack frame, is reached. This command is used to avoid single
3773stepping through a loop more than once. It is like the @code{next}
3774command, except that when @code{until} encounters a jump, it
3775automatically continues execution until the program counter is greater
3776than the address of the jump.
3777
3778This means that when you reach the end of a loop after single stepping
3779though it, @code{until} makes your program continue execution until it
3780exits the loop. In contrast, a @code{next} command at the end of a loop
3781simply steps back to the beginning of the loop, which forces you to step
3782through the next iteration.
3783
3784@code{until} always stops your program if it attempts to exit the current
3785stack frame.
3786
3787@code{until} may produce somewhat counterintuitive results if the order
3788of machine code does not match the order of the source lines. For
3789example, in the following excerpt from a debugging session, the @code{f}
3790(@code{frame}) command shows that execution is stopped at line
3791@code{206}; yet when we use @code{until}, we get to line @code{195}:
3792
474c8240 3793@smallexample
c906108c
SS
3794(@value{GDBP}) f
3795#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3796206 expand_input();
3797(@value{GDBP}) until
3798195 for ( ; argc > 0; NEXTARG) @{
474c8240 3799@end smallexample
c906108c
SS
3800
3801This happened because, for execution efficiency, the compiler had
3802generated code for the loop closure test at the end, rather than the
3803start, of the loop---even though the test in a C @code{for}-loop is
3804written before the body of the loop. The @code{until} command appeared
3805to step back to the beginning of the loop when it advanced to this
3806expression; however, it has not really gone to an earlier
3807statement---not in terms of the actual machine code.
3808
3809@code{until} with no argument works by means of single
3810instruction stepping, and hence is slower than @code{until} with an
3811argument.
3812
3813@item until @var{location}
3814@itemx u @var{location}
3815Continue running your program until either the specified location is
3816reached, or the current stack frame returns. @var{location} is any of
3817the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
3818,Setting breakpoints}). This form of the command uses breakpoints, and
3819hence is quicker than @code{until} without an argument. The specified
3820location is actually reached only if it is in the current frame. This
3821implies that @code{until} can be used to skip over recursive function
3822invocations. For instance in the code below, if the current location is
3823line @code{96}, issuing @code{until 99} will execute the program up to
3824line @code{99} in the same invocation of factorial, i.e. after the inner
3825invocations have returned.
3826
3827@smallexample
382894 int factorial (int value)
382995 @{
383096 if (value > 1) @{
383197 value *= factorial (value - 1);
383298 @}
383399 return (value);
3834100 @}
3835@end smallexample
3836
3837
3838@kindex advance @var{location}
3839@itemx advance @var{location}
09d4efe1
EZ
3840Continue running the program up to the given @var{location}. An argument is
3841required, which should be of the same form as arguments for the @code{break}
c60eb6f1
EZ
3842command. Execution will also stop upon exit from the current stack
3843frame. This command is similar to @code{until}, but @code{advance} will
3844not skip over recursive function calls, and the target location doesn't
3845have to be in the same frame as the current one.
3846
c906108c
SS
3847
3848@kindex stepi
41afff9a 3849@kindex si @r{(@code{stepi})}
c906108c 3850@item stepi
96a2c332 3851@itemx stepi @var{arg}
c906108c
SS
3852@itemx si
3853Execute one machine instruction, then stop and return to the debugger.
3854
3855It is often useful to do @samp{display/i $pc} when stepping by machine
3856instructions. This makes @value{GDBN} automatically display the next
3857instruction to be executed, each time your program stops. @xref{Auto
3858Display,, Automatic display}.
3859
3860An argument is a repeat count, as in @code{step}.
3861
3862@need 750
3863@kindex nexti
41afff9a 3864@kindex ni @r{(@code{nexti})}
c906108c 3865@item nexti
96a2c332 3866@itemx nexti @var{arg}
c906108c
SS
3867@itemx ni
3868Execute one machine instruction, but if it is a function call,
3869proceed until the function returns.
3870
3871An argument is a repeat count, as in @code{next}.
3872@end table
3873
6d2ebf8b 3874@node Signals
c906108c
SS
3875@section Signals
3876@cindex signals
3877
3878A signal is an asynchronous event that can happen in a program. The
3879operating system defines the possible kinds of signals, and gives each
3880kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3881signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3882@code{SIGSEGV} is the signal a program gets from referencing a place in
3883memory far away from all the areas in use; @code{SIGALRM} occurs when
3884the alarm clock timer goes off (which happens only if your program has
3885requested an alarm).
3886
3887@cindex fatal signals
3888Some signals, including @code{SIGALRM}, are a normal part of the
3889functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3890errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3891program has not specified in advance some other way to handle the signal.
3892@code{SIGINT} does not indicate an error in your program, but it is normally
3893fatal so it can carry out the purpose of the interrupt: to kill the program.
3894
3895@value{GDBN} has the ability to detect any occurrence of a signal in your
3896program. You can tell @value{GDBN} in advance what to do for each kind of
3897signal.
3898
3899@cindex handling signals
24f93129
EZ
3900Normally, @value{GDBN} is set up to let the non-erroneous signals like
3901@code{SIGALRM} be silently passed to your program
3902(so as not to interfere with their role in the program's functioning)
c906108c
SS
3903but to stop your program immediately whenever an error signal happens.
3904You can change these settings with the @code{handle} command.
3905
3906@table @code
3907@kindex info signals
09d4efe1 3908@kindex info handle
c906108c 3909@item info signals
96a2c332 3910@itemx info handle
c906108c
SS
3911Print a table of all the kinds of signals and how @value{GDBN} has been told to
3912handle each one. You can use this to see the signal numbers of all
3913the defined types of signals.
3914
d4f3574e 3915@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3916
3917@kindex handle
3918@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3919Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3920can be the number of a signal or its name (with or without the
24f93129 3921@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3922@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3923known signals. The @var{keywords} say what change to make.
c906108c
SS
3924@end table
3925
3926@c @group
3927The keywords allowed by the @code{handle} command can be abbreviated.
3928Their full names are:
3929
3930@table @code
3931@item nostop
3932@value{GDBN} should not stop your program when this signal happens. It may
3933still print a message telling you that the signal has come in.
3934
3935@item stop
3936@value{GDBN} should stop your program when this signal happens. This implies
3937the @code{print} keyword as well.
3938
3939@item print
3940@value{GDBN} should print a message when this signal happens.
3941
3942@item noprint
3943@value{GDBN} should not mention the occurrence of the signal at all. This
3944implies the @code{nostop} keyword as well.
3945
3946@item pass
5ece1a18 3947@itemx noignore
c906108c
SS
3948@value{GDBN} should allow your program to see this signal; your program
3949can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3950and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3951
3952@item nopass
5ece1a18 3953@itemx ignore
c906108c 3954@value{GDBN} should not allow your program to see this signal.
5ece1a18 3955@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3956@end table
3957@c @end group
3958
d4f3574e
SS
3959When a signal stops your program, the signal is not visible to the
3960program until you
c906108c
SS
3961continue. Your program sees the signal then, if @code{pass} is in
3962effect for the signal in question @emph{at that time}. In other words,
3963after @value{GDBN} reports a signal, you can use the @code{handle}
3964command with @code{pass} or @code{nopass} to control whether your
3965program sees that signal when you continue.
3966
24f93129
EZ
3967The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3968non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3969@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3970erroneous signals.
3971
c906108c
SS
3972You can also use the @code{signal} command to prevent your program from
3973seeing a signal, or cause it to see a signal it normally would not see,
3974or to give it any signal at any time. For example, if your program stopped
3975due to some sort of memory reference error, you might store correct
3976values into the erroneous variables and continue, hoping to see more
3977execution; but your program would probably terminate immediately as
3978a result of the fatal signal once it saw the signal. To prevent this,
3979you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3980program a signal}.
c906108c 3981
6d2ebf8b 3982@node Thread Stops
c906108c
SS
3983@section Stopping and starting multi-thread programs
3984
3985When your program has multiple threads (@pxref{Threads,, Debugging
3986programs with multiple threads}), you can choose whether to set
3987breakpoints on all threads, or on a particular thread.
3988
3989@table @code
3990@cindex breakpoints and threads
3991@cindex thread breakpoints
3992@kindex break @dots{} thread @var{threadno}
3993@item break @var{linespec} thread @var{threadno}
3994@itemx break @var{linespec} thread @var{threadno} if @dots{}
3995@var{linespec} specifies source lines; there are several ways of
3996writing them, but the effect is always to specify some source line.
3997
3998Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3999to specify that you only want @value{GDBN} to stop the program when a
4000particular thread reaches this breakpoint. @var{threadno} is one of the
4001numeric thread identifiers assigned by @value{GDBN}, shown in the first
4002column of the @samp{info threads} display.
4003
4004If you do not specify @samp{thread @var{threadno}} when you set a
4005breakpoint, the breakpoint applies to @emph{all} threads of your
4006program.
4007
4008You can use the @code{thread} qualifier on conditional breakpoints as
4009well; in this case, place @samp{thread @var{threadno}} before the
4010breakpoint condition, like this:
4011
4012@smallexample
2df3850c 4013(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
4014@end smallexample
4015
4016@end table
4017
4018@cindex stopped threads
4019@cindex threads, stopped
4020Whenever your program stops under @value{GDBN} for any reason,
4021@emph{all} threads of execution stop, not just the current thread. This
4022allows you to examine the overall state of the program, including
4023switching between threads, without worrying that things may change
4024underfoot.
4025
36d86913
MC
4026@cindex thread breakpoints and system calls
4027@cindex system calls and thread breakpoints
4028@cindex premature return from system calls
4029There is an unfortunate side effect. If one thread stops for a
4030breakpoint, or for some other reason, and another thread is blocked in a
4031system call, then the system call may return prematurely. This is a
4032consequence of the interaction between multiple threads and the signals
4033that @value{GDBN} uses to implement breakpoints and other events that
4034stop execution.
4035
4036To handle this problem, your program should check the return value of
4037each system call and react appropriately. This is good programming
4038style anyways.
4039
4040For example, do not write code like this:
4041
4042@smallexample
4043 sleep (10);
4044@end smallexample
4045
4046The call to @code{sleep} will return early if a different thread stops
4047at a breakpoint or for some other reason.
4048
4049Instead, write this:
4050
4051@smallexample
4052 int unslept = 10;
4053 while (unslept > 0)
4054 unslept = sleep (unslept);
4055@end smallexample
4056
4057A system call is allowed to return early, so the system is still
4058conforming to its specification. But @value{GDBN} does cause your
4059multi-threaded program to behave differently than it would without
4060@value{GDBN}.
4061
4062Also, @value{GDBN} uses internal breakpoints in the thread library to
4063monitor certain events such as thread creation and thread destruction.
4064When such an event happens, a system call in another thread may return
4065prematurely, even though your program does not appear to stop.
4066
c906108c
SS
4067@cindex continuing threads
4068@cindex threads, continuing
4069Conversely, whenever you restart the program, @emph{all} threads start
4070executing. @emph{This is true even when single-stepping} with commands
5d161b24 4071like @code{step} or @code{next}.
c906108c
SS
4072
4073In particular, @value{GDBN} cannot single-step all threads in lockstep.
4074Since thread scheduling is up to your debugging target's operating
4075system (not controlled by @value{GDBN}), other threads may
4076execute more than one statement while the current thread completes a
4077single step. Moreover, in general other threads stop in the middle of a
4078statement, rather than at a clean statement boundary, when the program
4079stops.
4080
4081You might even find your program stopped in another thread after
4082continuing or even single-stepping. This happens whenever some other
4083thread runs into a breakpoint, a signal, or an exception before the
4084first thread completes whatever you requested.
4085
4086On some OSes, you can lock the OS scheduler and thus allow only a single
4087thread to run.
4088
4089@table @code
4090@item set scheduler-locking @var{mode}
9c16f35a
EZ
4091@cindex scheduler locking mode
4092@cindex lock scheduler
c906108c
SS
4093Set the scheduler locking mode. If it is @code{off}, then there is no
4094locking and any thread may run at any time. If @code{on}, then only the
4095current thread may run when the inferior is resumed. The @code{step}
4096mode optimizes for single-stepping. It stops other threads from
4097``seizing the prompt'' by preempting the current thread while you are
4098stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 4099when you step. They are more likely to run when you @samp{next} over a
c906108c 4100function call, and they are completely free to run when you use commands
d4f3574e 4101like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 4102thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 4103@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
4104
4105@item show scheduler-locking
4106Display the current scheduler locking mode.
4107@end table
4108
c906108c 4109
6d2ebf8b 4110@node Stack
c906108c
SS
4111@chapter Examining the Stack
4112
4113When your program has stopped, the first thing you need to know is where it
4114stopped and how it got there.
4115
4116@cindex call stack
5d161b24
DB
4117Each time your program performs a function call, information about the call
4118is generated.
4119That information includes the location of the call in your program,
4120the arguments of the call,
c906108c 4121and the local variables of the function being called.
5d161b24 4122The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
4123The stack frames are allocated in a region of memory called the @dfn{call
4124stack}.
4125
4126When your program stops, the @value{GDBN} commands for examining the
4127stack allow you to see all of this information.
4128
4129@cindex selected frame
4130One of the stack frames is @dfn{selected} by @value{GDBN} and many
4131@value{GDBN} commands refer implicitly to the selected frame. In
4132particular, whenever you ask @value{GDBN} for the value of a variable in
4133your program, the value is found in the selected frame. There are
4134special @value{GDBN} commands to select whichever frame you are
4135interested in. @xref{Selection, ,Selecting a frame}.
4136
4137When your program stops, @value{GDBN} automatically selects the
5d161b24 4138currently executing frame and describes it briefly, similar to the
c906108c
SS
4139@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
4140
4141@menu
4142* Frames:: Stack frames
4143* Backtrace:: Backtraces
4144* Selection:: Selecting a frame
4145* Frame Info:: Information on a frame
c906108c
SS
4146
4147@end menu
4148
6d2ebf8b 4149@node Frames
c906108c
SS
4150@section Stack frames
4151
d4f3574e 4152@cindex frame, definition
c906108c
SS
4153@cindex stack frame
4154The call stack is divided up into contiguous pieces called @dfn{stack
4155frames}, or @dfn{frames} for short; each frame is the data associated
4156with one call to one function. The frame contains the arguments given
4157to the function, the function's local variables, and the address at
4158which the function is executing.
4159
4160@cindex initial frame
4161@cindex outermost frame
4162@cindex innermost frame
4163When your program is started, the stack has only one frame, that of the
4164function @code{main}. This is called the @dfn{initial} frame or the
4165@dfn{outermost} frame. Each time a function is called, a new frame is
4166made. Each time a function returns, the frame for that function invocation
4167is eliminated. If a function is recursive, there can be many frames for
4168the same function. The frame for the function in which execution is
4169actually occurring is called the @dfn{innermost} frame. This is the most
4170recently created of all the stack frames that still exist.
4171
4172@cindex frame pointer
4173Inside your program, stack frames are identified by their addresses. A
4174stack frame consists of many bytes, each of which has its own address; each
4175kind of computer has a convention for choosing one byte whose
4176address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
4177in a register called the @dfn{frame pointer register}
4178(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
4179
4180@cindex frame number
4181@value{GDBN} assigns numbers to all existing stack frames, starting with
4182zero for the innermost frame, one for the frame that called it,
4183and so on upward. These numbers do not really exist in your program;
4184they are assigned by @value{GDBN} to give you a way of designating stack
4185frames in @value{GDBN} commands.
4186
6d2ebf8b
SS
4187@c The -fomit-frame-pointer below perennially causes hbox overflow
4188@c underflow problems.
c906108c
SS
4189@cindex frameless execution
4190Some compilers provide a way to compile functions so that they operate
6d2ebf8b 4191without stack frames. (For example, the @value{GCC} option
474c8240 4192@smallexample
6d2ebf8b 4193@samp{-fomit-frame-pointer}
474c8240 4194@end smallexample
6d2ebf8b 4195generates functions without a frame.)
c906108c
SS
4196This is occasionally done with heavily used library functions to save
4197the frame setup time. @value{GDBN} has limited facilities for dealing
4198with these function invocations. If the innermost function invocation
4199has no stack frame, @value{GDBN} nevertheless regards it as though
4200it had a separate frame, which is numbered zero as usual, allowing
4201correct tracing of the function call chain. However, @value{GDBN} has
4202no provision for frameless functions elsewhere in the stack.
4203
4204@table @code
d4f3574e 4205@kindex frame@r{, command}
41afff9a 4206@cindex current stack frame
c906108c 4207@item frame @var{args}
5d161b24 4208The @code{frame} command allows you to move from one stack frame to another,
c906108c 4209and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4210address of the frame or the stack frame number. Without an argument,
4211@code{frame} prints the current stack frame.
c906108c
SS
4212
4213@kindex select-frame
41afff9a 4214@cindex selecting frame silently
c906108c
SS
4215@item select-frame
4216The @code{select-frame} command allows you to move from one stack frame
4217to another without printing the frame. This is the silent version of
4218@code{frame}.
4219@end table
4220
6d2ebf8b 4221@node Backtrace
c906108c
SS
4222@section Backtraces
4223
09d4efe1
EZ
4224@cindex traceback
4225@cindex call stack traces
c906108c
SS
4226A backtrace is a summary of how your program got where it is. It shows one
4227line per frame, for many frames, starting with the currently executing
4228frame (frame zero), followed by its caller (frame one), and on up the
4229stack.
4230
4231@table @code
4232@kindex backtrace
41afff9a 4233@kindex bt @r{(@code{backtrace})}
c906108c
SS
4234@item backtrace
4235@itemx bt
4236Print a backtrace of the entire stack: one line per frame for all
4237frames in the stack.
4238
4239You can stop the backtrace at any time by typing the system interrupt
4240character, normally @kbd{C-c}.
4241
4242@item backtrace @var{n}
4243@itemx bt @var{n}
4244Similar, but print only the innermost @var{n} frames.
4245
4246@item backtrace -@var{n}
4247@itemx bt -@var{n}
4248Similar, but print only the outermost @var{n} frames.
0f061b69
NR
4249
4250@item backtrace full
4251Print the values of the local variables also.
4252@itemx bt full
c906108c
SS
4253@end table
4254
4255@kindex where
4256@kindex info stack
c906108c
SS
4257The names @code{where} and @code{info stack} (abbreviated @code{info s})
4258are additional aliases for @code{backtrace}.
4259
4260Each line in the backtrace shows the frame number and the function name.
4261The program counter value is also shown---unless you use @code{set
4262print address off}. The backtrace also shows the source file name and
4263line number, as well as the arguments to the function. The program
4264counter value is omitted if it is at the beginning of the code for that
4265line number.
4266
4267Here is an example of a backtrace. It was made with the command
4268@samp{bt 3}, so it shows the innermost three frames.
4269
4270@smallexample
4271@group
5d161b24 4272#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4273 at builtin.c:993
4274#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4275#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4276 at macro.c:71
4277(More stack frames follow...)
4278@end group
4279@end smallexample
4280
4281@noindent
4282The display for frame zero does not begin with a program counter
4283value, indicating that your program has stopped at the beginning of the
4284code for line @code{993} of @code{builtin.c}.
4285
18999be5
EZ
4286@cindex value optimized out, in backtrace
4287@cindex function call arguments, optimized out
4288If your program was compiled with optimizations, some compilers will
4289optimize away arguments passed to functions if those arguments are
4290never used after the call. Such optimizations generate code that
4291passes arguments through registers, but doesn't store those arguments
4292in the stack frame. @value{GDBN} has no way of displaying such
4293arguments in stack frames other than the innermost one. Here's what
4294such a backtrace might look like:
4295
4296@smallexample
4297@group
4298#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4299 at builtin.c:993
4300#1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
4301#2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
4302 at macro.c:71
4303(More stack frames follow...)
4304@end group
4305@end smallexample
4306
4307@noindent
4308The values of arguments that were not saved in their stack frames are
4309shown as @samp{<value optimized out>}.
4310
4311If you need to display the values of such optimized-out arguments,
4312either deduce that from other variables whose values depend on the one
4313you are interested in, or recompile without optimizations.
4314
a8f24a35
EZ
4315@cindex backtrace beyond @code{main} function
4316@cindex program entry point
4317@cindex startup code, and backtrace
25d29d70
AC
4318Most programs have a standard user entry point---a place where system
4319libraries and startup code transition into user code. For C this is
d416eeec
EZ
4320@code{main}@footnote{
4321Note that embedded programs (the so-called ``free-standing''
4322environment) are not required to have a @code{main} function as the
4323entry point. They could even have multiple entry points.}.
4324When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
4325it will terminate the backtrace, to avoid tracing into highly
4326system-specific (and generally uninteresting) code.
4327
4328If you need to examine the startup code, or limit the number of levels
4329in a backtrace, you can change this behavior:
95f90d25
DJ
4330
4331@table @code
25d29d70
AC
4332@item set backtrace past-main
4333@itemx set backtrace past-main on
4644b6e3 4334@kindex set backtrace
25d29d70
AC
4335Backtraces will continue past the user entry point.
4336
4337@item set backtrace past-main off
95f90d25
DJ
4338Backtraces will stop when they encounter the user entry point. This is the
4339default.
4340
25d29d70 4341@item show backtrace past-main
4644b6e3 4342@kindex show backtrace
25d29d70
AC
4343Display the current user entry point backtrace policy.
4344
2315ffec
RC
4345@item set backtrace past-entry
4346@itemx set backtrace past-entry on
a8f24a35 4347Backtraces will continue past the internal entry point of an application.
2315ffec
RC
4348This entry point is encoded by the linker when the application is built,
4349and is likely before the user entry point @code{main} (or equivalent) is called.
4350
4351@item set backtrace past-entry off
4352Backtraces will stop when they encouter the internal entry point of an
4353application. This is the default.
4354
4355@item show backtrace past-entry
4356Display the current internal entry point backtrace policy.
4357
25d29d70
AC
4358@item set backtrace limit @var{n}
4359@itemx set backtrace limit 0
4360@cindex backtrace limit
4361Limit the backtrace to @var{n} levels. A value of zero means
4362unlimited.
95f90d25 4363
25d29d70
AC
4364@item show backtrace limit
4365Display the current limit on backtrace levels.
95f90d25
DJ
4366@end table
4367
6d2ebf8b 4368@node Selection
c906108c
SS
4369@section Selecting a frame
4370
4371Most commands for examining the stack and other data in your program work on
4372whichever stack frame is selected at the moment. Here are the commands for
4373selecting a stack frame; all of them finish by printing a brief description
4374of the stack frame just selected.
4375
4376@table @code
d4f3574e 4377@kindex frame@r{, selecting}
41afff9a 4378@kindex f @r{(@code{frame})}
c906108c
SS
4379@item frame @var{n}
4380@itemx f @var{n}
4381Select frame number @var{n}. Recall that frame zero is the innermost
4382(currently executing) frame, frame one is the frame that called the
4383innermost one, and so on. The highest-numbered frame is the one for
4384@code{main}.
4385
4386@item frame @var{addr}
4387@itemx f @var{addr}
4388Select the frame at address @var{addr}. This is useful mainly if the
4389chaining of stack frames has been damaged by a bug, making it
4390impossible for @value{GDBN} to assign numbers properly to all frames. In
4391addition, this can be useful when your program has multiple stacks and
4392switches between them.
4393
c906108c
SS
4394On the SPARC architecture, @code{frame} needs two addresses to
4395select an arbitrary frame: a frame pointer and a stack pointer.
4396
4397On the MIPS and Alpha architecture, it needs two addresses: a stack
4398pointer and a program counter.
4399
4400On the 29k architecture, it needs three addresses: a register stack
4401pointer, a program counter, and a memory stack pointer.
4402@c note to future updaters: this is conditioned on a flag
4403@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
4404@c as of 27 Jan 1994.
c906108c
SS
4405
4406@kindex up
4407@item up @var{n}
4408Move @var{n} frames up the stack. For positive numbers @var{n}, this
4409advances toward the outermost frame, to higher frame numbers, to frames
4410that have existed longer. @var{n} defaults to one.
4411
4412@kindex down
41afff9a 4413@kindex do @r{(@code{down})}
c906108c
SS
4414@item down @var{n}
4415Move @var{n} frames down the stack. For positive numbers @var{n}, this
4416advances toward the innermost frame, to lower frame numbers, to frames
4417that were created more recently. @var{n} defaults to one. You may
4418abbreviate @code{down} as @code{do}.
4419@end table
4420
4421All of these commands end by printing two lines of output describing the
4422frame. The first line shows the frame number, the function name, the
4423arguments, and the source file and line number of execution in that
5d161b24 4424frame. The second line shows the text of that source line.
c906108c
SS
4425
4426@need 1000
4427For example:
4428
4429@smallexample
4430@group
4431(@value{GDBP}) up
4432#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4433 at env.c:10
443410 read_input_file (argv[i]);
4435@end group
4436@end smallexample
4437
4438After such a printout, the @code{list} command with no arguments
4439prints ten lines centered on the point of execution in the frame.
87885426
FN
4440You can also edit the program at the point of execution with your favorite
4441editing program by typing @code{edit}.
4442@xref{List, ,Printing source lines},
4443for details.
c906108c
SS
4444
4445@table @code
4446@kindex down-silently
4447@kindex up-silently
4448@item up-silently @var{n}
4449@itemx down-silently @var{n}
4450These two commands are variants of @code{up} and @code{down},
4451respectively; they differ in that they do their work silently, without
4452causing display of the new frame. They are intended primarily for use
4453in @value{GDBN} command scripts, where the output might be unnecessary and
4454distracting.
4455@end table
4456
6d2ebf8b 4457@node Frame Info
c906108c
SS
4458@section Information about a frame
4459
4460There are several other commands to print information about the selected
4461stack frame.
4462
4463@table @code
4464@item frame
4465@itemx f
4466When used without any argument, this command does not change which
4467frame is selected, but prints a brief description of the currently
4468selected stack frame. It can be abbreviated @code{f}. With an
4469argument, this command is used to select a stack frame.
4470@xref{Selection, ,Selecting a frame}.
4471
4472@kindex info frame
41afff9a 4473@kindex info f @r{(@code{info frame})}
c906108c
SS
4474@item info frame
4475@itemx info f
4476This command prints a verbose description of the selected stack frame,
4477including:
4478
4479@itemize @bullet
5d161b24
DB
4480@item
4481the address of the frame
c906108c
SS
4482@item
4483the address of the next frame down (called by this frame)
4484@item
4485the address of the next frame up (caller of this frame)
4486@item
4487the language in which the source code corresponding to this frame is written
4488@item
4489the address of the frame's arguments
4490@item
d4f3574e
SS
4491the address of the frame's local variables
4492@item
c906108c
SS
4493the program counter saved in it (the address of execution in the caller frame)
4494@item
4495which registers were saved in the frame
4496@end itemize
4497
4498@noindent The verbose description is useful when
4499something has gone wrong that has made the stack format fail to fit
4500the usual conventions.
4501
4502@item info frame @var{addr}
4503@itemx info f @var{addr}
4504Print a verbose description of the frame at address @var{addr}, without
4505selecting that frame. The selected frame remains unchanged by this
4506command. This requires the same kind of address (more than one for some
4507architectures) that you specify in the @code{frame} command.
4508@xref{Selection, ,Selecting a frame}.
4509
4510@kindex info args
4511@item info args
4512Print the arguments of the selected frame, each on a separate line.
4513
4514@item info locals
4515@kindex info locals
4516Print the local variables of the selected frame, each on a separate
4517line. These are all variables (declared either static or automatic)
4518accessible at the point of execution of the selected frame.
4519
c906108c 4520@kindex info catch
d4f3574e
SS
4521@cindex catch exceptions, list active handlers
4522@cindex exception handlers, how to list
c906108c
SS
4523@item info catch
4524Print a list of all the exception handlers that are active in the
4525current stack frame at the current point of execution. To see other
4526exception handlers, visit the associated frame (using the @code{up},
4527@code{down}, or @code{frame} commands); then type @code{info catch}.
4528@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4529
c906108c
SS
4530@end table
4531
c906108c 4532
6d2ebf8b 4533@node Source
c906108c
SS
4534@chapter Examining Source Files
4535
4536@value{GDBN} can print parts of your program's source, since the debugging
4537information recorded in the program tells @value{GDBN} what source files were
4538used to build it. When your program stops, @value{GDBN} spontaneously prints
4539the line where it stopped. Likewise, when you select a stack frame
4540(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4541execution in that frame has stopped. You can print other portions of
4542source files by explicit command.
4543
7a292a7a 4544If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4545prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4546@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4547
4548@menu
4549* List:: Printing source lines
87885426 4550* Edit:: Editing source files
c906108c 4551* Search:: Searching source files
c906108c
SS
4552* Source Path:: Specifying source directories
4553* Machine Code:: Source and machine code
4554@end menu
4555
6d2ebf8b 4556@node List
c906108c
SS
4557@section Printing source lines
4558
4559@kindex list
41afff9a 4560@kindex l @r{(@code{list})}
c906108c 4561To print lines from a source file, use the @code{list} command
5d161b24 4562(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4563There are several ways to specify what part of the file you want to print.
4564
4565Here are the forms of the @code{list} command most commonly used:
4566
4567@table @code
4568@item list @var{linenum}
4569Print lines centered around line number @var{linenum} in the
4570current source file.
4571
4572@item list @var{function}
4573Print lines centered around the beginning of function
4574@var{function}.
4575
4576@item list
4577Print more lines. If the last lines printed were printed with a
4578@code{list} command, this prints lines following the last lines
4579printed; however, if the last line printed was a solitary line printed
4580as part of displaying a stack frame (@pxref{Stack, ,Examining the
4581Stack}), this prints lines centered around that line.
4582
4583@item list -
4584Print lines just before the lines last printed.
4585@end table
4586
9c16f35a 4587@cindex @code{list}, how many lines to display
c906108c
SS
4588By default, @value{GDBN} prints ten source lines with any of these forms of
4589the @code{list} command. You can change this using @code{set listsize}:
4590
4591@table @code
4592@kindex set listsize
4593@item set listsize @var{count}
4594Make the @code{list} command display @var{count} source lines (unless
4595the @code{list} argument explicitly specifies some other number).
4596
4597@kindex show listsize
4598@item show listsize
4599Display the number of lines that @code{list} prints.
4600@end table
4601
4602Repeating a @code{list} command with @key{RET} discards the argument,
4603so it is equivalent to typing just @code{list}. This is more useful
4604than listing the same lines again. An exception is made for an
4605argument of @samp{-}; that argument is preserved in repetition so that
4606each repetition moves up in the source file.
4607
4608@cindex linespec
4609In general, the @code{list} command expects you to supply zero, one or two
4610@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4611of writing them, but the effect is always to specify some source line.
c906108c
SS
4612Here is a complete description of the possible arguments for @code{list}:
4613
4614@table @code
4615@item list @var{linespec}
4616Print lines centered around the line specified by @var{linespec}.
4617
4618@item list @var{first},@var{last}
4619Print lines from @var{first} to @var{last}. Both arguments are
4620linespecs.
4621
4622@item list ,@var{last}
4623Print lines ending with @var{last}.
4624
4625@item list @var{first},
4626Print lines starting with @var{first}.
4627
4628@item list +
4629Print lines just after the lines last printed.
4630
4631@item list -
4632Print lines just before the lines last printed.
4633
4634@item list
4635As described in the preceding table.
4636@end table
4637
4638Here are the ways of specifying a single source line---all the
4639kinds of linespec.
4640
4641@table @code
4642@item @var{number}
4643Specifies line @var{number} of the current source file.
4644When a @code{list} command has two linespecs, this refers to
4645the same source file as the first linespec.
4646
4647@item +@var{offset}
4648Specifies the line @var{offset} lines after the last line printed.
4649When used as the second linespec in a @code{list} command that has
4650two, this specifies the line @var{offset} lines down from the
4651first linespec.
4652
4653@item -@var{offset}
4654Specifies the line @var{offset} lines before the last line printed.
4655
4656@item @var{filename}:@var{number}
4657Specifies line @var{number} in the source file @var{filename}.
4658
4659@item @var{function}
4660Specifies the line that begins the body of the function @var{function}.
4661For example: in C, this is the line with the open brace.
4662
4663@item @var{filename}:@var{function}
4664Specifies the line of the open-brace that begins the body of the
4665function @var{function} in the file @var{filename}. You only need the
4666file name with a function name to avoid ambiguity when there are
4667identically named functions in different source files.
4668
4669@item *@var{address}
4670Specifies the line containing the program address @var{address}.
4671@var{address} may be any expression.
4672@end table
4673
87885426
FN
4674@node Edit
4675@section Editing source files
4676@cindex editing source files
4677
4678@kindex edit
4679@kindex e @r{(@code{edit})}
4680To edit the lines in a source file, use the @code{edit} command.
4681The editing program of your choice
4682is invoked with the current line set to
4683the active line in the program.
4684Alternatively, there are several ways to specify what part of the file you
4685want to print if you want to see other parts of the program.
4686
4687Here are the forms of the @code{edit} command most commonly used:
4688
4689@table @code
4690@item edit
4691Edit the current source file at the active line number in the program.
4692
4693@item edit @var{number}
4694Edit the current source file with @var{number} as the active line number.
4695
4696@item edit @var{function}
4697Edit the file containing @var{function} at the beginning of its definition.
4698
4699@item edit @var{filename}:@var{number}
4700Specifies line @var{number} in the source file @var{filename}.
4701
4702@item edit @var{filename}:@var{function}
4703Specifies the line that begins the body of the
4704function @var{function} in the file @var{filename}. You only need the
4705file name with a function name to avoid ambiguity when there are
4706identically named functions in different source files.
4707
4708@item edit *@var{address}
4709Specifies the line containing the program address @var{address}.
4710@var{address} may be any expression.
4711@end table
4712
4713@subsection Choosing your editor
4714You can customize @value{GDBN} to use any editor you want
4715@footnote{
4716The only restriction is that your editor (say @code{ex}), recognizes the
4717following command-line syntax:
10998722 4718@smallexample
87885426 4719ex +@var{number} file
10998722 4720@end smallexample
15387254
EZ
4721The optional numeric value +@var{number} specifies the number of the line in
4722the file where to start editing.}.
4723By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4724by setting the environment variable @code{EDITOR} before using
4725@value{GDBN}. For example, to configure @value{GDBN} to use the
4726@code{vi} editor, you could use these commands with the @code{sh} shell:
4727@smallexample
87885426
FN
4728EDITOR=/usr/bin/vi
4729export EDITOR
15387254 4730gdb @dots{}
10998722 4731@end smallexample
87885426 4732or in the @code{csh} shell,
10998722 4733@smallexample
87885426 4734setenv EDITOR /usr/bin/vi
15387254 4735gdb @dots{}
10998722 4736@end smallexample
87885426 4737
6d2ebf8b 4738@node Search
c906108c 4739@section Searching source files
15387254 4740@cindex searching source files
c906108c
SS
4741
4742There are two commands for searching through the current source file for a
4743regular expression.
4744
4745@table @code
4746@kindex search
4747@kindex forward-search
4748@item forward-search @var{regexp}
4749@itemx search @var{regexp}
4750The command @samp{forward-search @var{regexp}} checks each line,
4751starting with the one following the last line listed, for a match for
5d161b24 4752@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4753synonym @samp{search @var{regexp}} or abbreviate the command name as
4754@code{fo}.
4755
09d4efe1 4756@kindex reverse-search
c906108c
SS
4757@item reverse-search @var{regexp}
4758The command @samp{reverse-search @var{regexp}} checks each line, starting
4759with the one before the last line listed and going backward, for a match
4760for @var{regexp}. It lists the line that is found. You can abbreviate
4761this command as @code{rev}.
4762@end table
c906108c 4763
6d2ebf8b 4764@node Source Path
c906108c
SS
4765@section Specifying source directories
4766
4767@cindex source path
4768@cindex directories for source files
4769Executable programs sometimes do not record the directories of the source
4770files from which they were compiled, just the names. Even when they do,
4771the directories could be moved between the compilation and your debugging
4772session. @value{GDBN} has a list of directories to search for source files;
4773this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4774it tries all the directories in the list, in the order they are present
0b66e38c
EZ
4775in the list, until it finds a file with the desired name.
4776
4777For example, suppose an executable references the file
4778@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4779@file{/mnt/cross}. The file is first looked up literally; if this
4780fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4781fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4782message is printed. @value{GDBN} does not look up the parts of the
4783source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4784Likewise, the subdirectories of the source path are not searched: if
4785the source path is @file{/mnt/cross}, and the binary refers to
4786@file{foo.c}, @value{GDBN} would not find it under
4787@file{/mnt/cross/usr/src/foo-1.0/lib}.
4788
4789Plain file names, relative file names with leading directories, file
4790names containing dots, etc.@: are all treated as described above; for
4791instance, if the source path is @file{/mnt/cross}, and the source file
4792is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4793@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4794that---@file{/mnt/cross/foo.c}.
4795
4796Note that the executable search path is @emph{not} used to locate the
4797source files. Neither is the current working directory, unless it
4798happens to be in the source path.
c906108c
SS
4799
4800Whenever you reset or rearrange the source path, @value{GDBN} clears out
4801any information it has cached about where source files are found and where
4802each line is in the file.
4803
4804@kindex directory
4805@kindex dir
d4f3574e
SS
4806When you start @value{GDBN}, its source path includes only @samp{cdir}
4807and @samp{cwd}, in that order.
c906108c
SS
4808To add other directories, use the @code{directory} command.
4809
4810@table @code
4811@item directory @var{dirname} @dots{}
4812@item dir @var{dirname} @dots{}
4813Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4814directory names may be given to this command, separated by @samp{:}
4815(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4816part of absolute file names) or
c906108c
SS
4817whitespace. You may specify a directory that is already in the source
4818path; this moves it forward, so @value{GDBN} searches it sooner.
4819
4820@kindex cdir
4821@kindex cwd
41afff9a
EZ
4822@vindex $cdir@r{, convenience variable}
4823@vindex $cwdr@r{, convenience variable}
c906108c
SS
4824@cindex compilation directory
4825@cindex current directory
4826@cindex working directory
4827@cindex directory, current
4828@cindex directory, compilation
4829You can use the string @samp{$cdir} to refer to the compilation
4830directory (if one is recorded), and @samp{$cwd} to refer to the current
4831working directory. @samp{$cwd} is not the same as @samp{.}---the former
4832tracks the current working directory as it changes during your @value{GDBN}
4833session, while the latter is immediately expanded to the current
4834directory at the time you add an entry to the source path.
4835
4836@item directory
4837Reset the source path to empty again. This requires confirmation.
4838
4839@c RET-repeat for @code{directory} is explicitly disabled, but since
4840@c repeating it would be a no-op we do not say that. (thanks to RMS)
4841
4842@item show directories
4843@kindex show directories
4844Print the source path: show which directories it contains.
4845@end table
4846
4847If your source path is cluttered with directories that are no longer of
4848interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4849versions of source. You can correct the situation as follows:
4850
4851@enumerate
4852@item
4853Use @code{directory} with no argument to reset the source path to empty.
4854
4855@item
4856Use @code{directory} with suitable arguments to reinstall the
4857directories you want in the source path. You can add all the
4858directories in one command.
4859@end enumerate
4860
6d2ebf8b 4861@node Machine Code
c906108c 4862@section Source and machine code
15387254 4863@cindex source line and its code address
c906108c
SS
4864
4865You can use the command @code{info line} to map source lines to program
4866addresses (and vice versa), and the command @code{disassemble} to display
4867a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4868mode, the @code{info line} command causes the arrow to point to the
5d161b24 4869line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4870well as hex.
4871
4872@table @code
4873@kindex info line
4874@item info line @var{linespec}
4875Print the starting and ending addresses of the compiled code for
4876source line @var{linespec}. You can specify source lines in any of
4877the ways understood by the @code{list} command (@pxref{List, ,Printing
4878source lines}).
4879@end table
4880
4881For example, we can use @code{info line} to discover the location of
4882the object code for the first line of function
4883@code{m4_changequote}:
4884
d4f3574e
SS
4885@c FIXME: I think this example should also show the addresses in
4886@c symbolic form, as they usually would be displayed.
c906108c 4887@smallexample
96a2c332 4888(@value{GDBP}) info line m4_changequote
c906108c
SS
4889Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4890@end smallexample
4891
4892@noindent
15387254 4893@cindex code address and its source line
c906108c
SS
4894We can also inquire (using @code{*@var{addr}} as the form for
4895@var{linespec}) what source line covers a particular address:
4896@smallexample
4897(@value{GDBP}) info line *0x63ff
4898Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4899@end smallexample
4900
4901@cindex @code{$_} and @code{info line}
15387254 4902@cindex @code{x} command, default address
41afff9a 4903@kindex x@r{(examine), and} info line
c906108c
SS
4904After @code{info line}, the default address for the @code{x} command
4905is changed to the starting address of the line, so that @samp{x/i} is
4906sufficient to begin examining the machine code (@pxref{Memory,
4907,Examining memory}). Also, this address is saved as the value of the
4908convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4909variables}).
4910
4911@table @code
4912@kindex disassemble
4913@cindex assembly instructions
4914@cindex instructions, assembly
4915@cindex machine instructions
4916@cindex listing machine instructions
4917@item disassemble
4918This specialized command dumps a range of memory as machine
4919instructions. The default memory range is the function surrounding the
4920program counter of the selected frame. A single argument to this
4921command is a program counter value; @value{GDBN} dumps the function
4922surrounding this value. Two arguments specify a range of addresses
4923(first inclusive, second exclusive) to dump.
4924@end table
4925
c906108c
SS
4926The following example shows the disassembly of a range of addresses of
4927HP PA-RISC 2.0 code:
4928
4929@smallexample
4930(@value{GDBP}) disas 0x32c4 0x32e4
4931Dump of assembler code from 0x32c4 to 0x32e4:
49320x32c4 <main+204>: addil 0,dp
49330x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
49340x32cc <main+212>: ldil 0x3000,r31
49350x32d0 <main+216>: ble 0x3f8(sr4,r31)
49360x32d4 <main+220>: ldo 0(r31),rp
49370x32d8 <main+224>: addil -0x800,dp
49380x32dc <main+228>: ldo 0x588(r1),r26
49390x32e0 <main+232>: ldil 0x3000,r31
4940End of assembler dump.
4941@end smallexample
c906108c
SS
4942
4943Some architectures have more than one commonly-used set of instruction
4944mnemonics or other syntax.
4945
76d17f34
EZ
4946For programs that were dynamically linked and use shared libraries,
4947instructions that call functions or branch to locations in the shared
4948libraries might show a seemingly bogus location---it's actually a
4949location of the relocation table. On some architectures, @value{GDBN}
4950might be able to resolve these to actual function names.
4951
c906108c 4952@table @code
d4f3574e 4953@kindex set disassembly-flavor
d4f3574e
SS
4954@cindex Intel disassembly flavor
4955@cindex AT&T disassembly flavor
4956@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4957Select the instruction set to use when disassembling the
4958program via the @code{disassemble} or @code{x/i} commands.
4959
4960Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4961can set @var{instruction-set} to either @code{intel} or @code{att}.
4962The default is @code{att}, the AT&T flavor used by default by Unix
4963assemblers for x86-based targets.
9c16f35a
EZ
4964
4965@kindex show disassembly-flavor
4966@item show disassembly-flavor
4967Show the current setting of the disassembly flavor.
c906108c
SS
4968@end table
4969
4970
6d2ebf8b 4971@node Data
c906108c
SS
4972@chapter Examining Data
4973
4974@cindex printing data
4975@cindex examining data
4976@kindex print
4977@kindex inspect
4978@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4979@c document because it is nonstandard... Under Epoch it displays in a
4980@c different window or something like that.
4981The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4982command (abbreviated @code{p}), or its synonym @code{inspect}. It
4983evaluates and prints the value of an expression of the language your
4984program is written in (@pxref{Languages, ,Using @value{GDBN} with
4985Different Languages}).
c906108c
SS
4986
4987@table @code
d4f3574e
SS
4988@item print @var{expr}
4989@itemx print /@var{f} @var{expr}
4990@var{expr} is an expression (in the source language). By default the
4991value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4992you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4993@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4994formats}.
4995
4996@item print
4997@itemx print /@var{f}
15387254 4998@cindex reprint the last value
d4f3574e 4999If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
5000@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
5001conveniently inspect the same value in an alternative format.
5002@end table
5003
5004A more low-level way of examining data is with the @code{x} command.
5005It examines data in memory at a specified address and prints it in a
5006specified format. @xref{Memory, ,Examining memory}.
5007
7a292a7a 5008If you are interested in information about types, or about how the
d4f3574e
SS
5009fields of a struct or a class are declared, use the @code{ptype @var{exp}}
5010command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 5011Table}.
c906108c
SS
5012
5013@menu
5014* Expressions:: Expressions
5015* Variables:: Program variables
5016* Arrays:: Artificial arrays
5017* Output Formats:: Output formats
5018* Memory:: Examining memory
5019* Auto Display:: Automatic display
5020* Print Settings:: Print settings
5021* Value History:: Value history
5022* Convenience Vars:: Convenience variables
5023* Registers:: Registers
c906108c 5024* Floating Point Hardware:: Floating point hardware
53c69bd7 5025* Vector Unit:: Vector Unit
721c2651 5026* OS Information:: Auxiliary data provided by operating system
29e57380 5027* Memory Region Attributes:: Memory region attributes
16d9dec6 5028* Dump/Restore Files:: Copy between memory and a file
384ee23f 5029* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
5030* Character Sets:: Debugging programs that use a different
5031 character set than GDB does
09d4efe1 5032* Caching Remote Data:: Data caching for remote targets
c906108c
SS
5033@end menu
5034
6d2ebf8b 5035@node Expressions
c906108c
SS
5036@section Expressions
5037
5038@cindex expressions
5039@code{print} and many other @value{GDBN} commands accept an expression and
5040compute its value. Any kind of constant, variable or operator defined
5041by the programming language you are using is valid in an expression in
e2e0bcd1
JB
5042@value{GDBN}. This includes conditional expressions, function calls,
5043casts, and string constants. It also includes preprocessor macros, if
5044you compiled your program to include this information; see
5045@ref{Compilation}.
c906108c 5046
15387254 5047@cindex arrays in expressions
d4f3574e
SS
5048@value{GDBN} supports array constants in expressions input by
5049the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 5050you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 5051memory that is @code{malloc}ed in the target program.
c906108c 5052
c906108c
SS
5053Because C is so widespread, most of the expressions shown in examples in
5054this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
5055Languages}, for information on how to use expressions in other
5056languages.
5057
5058In this section, we discuss operators that you can use in @value{GDBN}
5059expressions regardless of your programming language.
5060
15387254 5061@cindex casts, in expressions
c906108c
SS
5062Casts are supported in all languages, not just in C, because it is so
5063useful to cast a number into a pointer in order to examine a structure
5064at that address in memory.
5065@c FIXME: casts supported---Mod2 true?
c906108c
SS
5066
5067@value{GDBN} supports these operators, in addition to those common
5068to programming languages:
5069
5070@table @code
5071@item @@
5072@samp{@@} is a binary operator for treating parts of memory as arrays.
5073@xref{Arrays, ,Artificial arrays}, for more information.
5074
5075@item ::
5076@samp{::} allows you to specify a variable in terms of the file or
5077function where it is defined. @xref{Variables, ,Program variables}.
5078
5079@cindex @{@var{type}@}
5080@cindex type casting memory
5081@cindex memory, viewing as typed object
5082@cindex casts, to view memory
5083@item @{@var{type}@} @var{addr}
5084Refers to an object of type @var{type} stored at address @var{addr} in
5085memory. @var{addr} may be any expression whose value is an integer or
5086pointer (but parentheses are required around binary operators, just as in
5087a cast). This construct is allowed regardless of what kind of data is
5088normally supposed to reside at @var{addr}.
5089@end table
5090
6d2ebf8b 5091@node Variables
c906108c
SS
5092@section Program variables
5093
5094The most common kind of expression to use is the name of a variable
5095in your program.
5096
5097Variables in expressions are understood in the selected stack frame
5098(@pxref{Selection, ,Selecting a frame}); they must be either:
5099
5100@itemize @bullet
5101@item
5102global (or file-static)
5103@end itemize
5104
5d161b24 5105@noindent or
c906108c
SS
5106
5107@itemize @bullet
5108@item
5109visible according to the scope rules of the
5110programming language from the point of execution in that frame
5d161b24 5111@end itemize
c906108c
SS
5112
5113@noindent This means that in the function
5114
474c8240 5115@smallexample
c906108c
SS
5116foo (a)
5117 int a;
5118@{
5119 bar (a);
5120 @{
5121 int b = test ();
5122 bar (b);
5123 @}
5124@}
474c8240 5125@end smallexample
c906108c
SS
5126
5127@noindent
5128you can examine and use the variable @code{a} whenever your program is
5129executing within the function @code{foo}, but you can only use or
5130examine the variable @code{b} while your program is executing inside
5131the block where @code{b} is declared.
5132
5133@cindex variable name conflict
5134There is an exception: you can refer to a variable or function whose
5135scope is a single source file even if the current execution point is not
5136in this file. But it is possible to have more than one such variable or
5137function with the same name (in different source files). If that
5138happens, referring to that name has unpredictable effects. If you wish,
5139you can specify a static variable in a particular function or file,
15387254 5140using the colon-colon (@code{::}) notation:
c906108c 5141
d4f3574e 5142@cindex colon-colon, context for variables/functions
c906108c
SS
5143@iftex
5144@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 5145@cindex @code{::}, context for variables/functions
c906108c 5146@end iftex
474c8240 5147@smallexample
c906108c
SS
5148@var{file}::@var{variable}
5149@var{function}::@var{variable}
474c8240 5150@end smallexample
c906108c
SS
5151
5152@noindent
5153Here @var{file} or @var{function} is the name of the context for the
5154static @var{variable}. In the case of file names, you can use quotes to
5155make sure @value{GDBN} parses the file name as a single word---for example,
5156to print a global value of @code{x} defined in @file{f2.c}:
5157
474c8240 5158@smallexample
c906108c 5159(@value{GDBP}) p 'f2.c'::x
474c8240 5160@end smallexample
c906108c 5161
b37052ae 5162@cindex C@t{++} scope resolution
c906108c 5163This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 5164use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
5165scope resolution operator in @value{GDBN} expressions.
5166@c FIXME: Um, so what happens in one of those rare cases where it's in
5167@c conflict?? --mew
c906108c
SS
5168
5169@cindex wrong values
5170@cindex variable values, wrong
15387254
EZ
5171@cindex function entry/exit, wrong values of variables
5172@cindex optimized code, wrong values of variables
c906108c
SS
5173@quotation
5174@emph{Warning:} Occasionally, a local variable may appear to have the
5175wrong value at certain points in a function---just after entry to a new
5176scope, and just before exit.
5177@end quotation
5178You may see this problem when you are stepping by machine instructions.
5179This is because, on most machines, it takes more than one instruction to
5180set up a stack frame (including local variable definitions); if you are
5181stepping by machine instructions, variables may appear to have the wrong
5182values until the stack frame is completely built. On exit, it usually
5183also takes more than one machine instruction to destroy a stack frame;
5184after you begin stepping through that group of instructions, local
5185variable definitions may be gone.
5186
5187This may also happen when the compiler does significant optimizations.
5188To be sure of always seeing accurate values, turn off all optimization
5189when compiling.
5190
d4f3574e
SS
5191@cindex ``No symbol "foo" in current context''
5192Another possible effect of compiler optimizations is to optimize
5193unused variables out of existence, or assign variables to registers (as
5194opposed to memory addresses). Depending on the support for such cases
5195offered by the debug info format used by the compiler, @value{GDBN}
5196might not be able to display values for such local variables. If that
5197happens, @value{GDBN} will print a message like this:
5198
474c8240 5199@smallexample
d4f3574e 5200No symbol "foo" in current context.
474c8240 5201@end smallexample
d4f3574e
SS
5202
5203To solve such problems, either recompile without optimizations, or use a
5204different debug info format, if the compiler supports several such
15387254 5205formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
5206usually supports the @option{-gstabs+} option. @option{-gstabs+}
5207produces debug info in a format that is superior to formats such as
5208COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5209an effective form for debug info. @xref{Debugging Options,,Options
5210for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
5211@xref{C, , Debugging C++}, for more info about debug info formats
5212that are best suited to C@t{++} programs.
d4f3574e 5213
6d2ebf8b 5214@node Arrays
c906108c
SS
5215@section Artificial arrays
5216
5217@cindex artificial array
15387254 5218@cindex arrays
41afff9a 5219@kindex @@@r{, referencing memory as an array}
c906108c
SS
5220It is often useful to print out several successive objects of the
5221same type in memory; a section of an array, or an array of
5222dynamically determined size for which only a pointer exists in the
5223program.
5224
5225You can do this by referring to a contiguous span of memory as an
5226@dfn{artificial array}, using the binary operator @samp{@@}. The left
5227operand of @samp{@@} should be the first element of the desired array
5228and be an individual object. The right operand should be the desired length
5229of the array. The result is an array value whose elements are all of
5230the type of the left argument. The first element is actually the left
5231argument; the second element comes from bytes of memory immediately
5232following those that hold the first element, and so on. Here is an
5233example. If a program says
5234
474c8240 5235@smallexample
c906108c 5236int *array = (int *) malloc (len * sizeof (int));
474c8240 5237@end smallexample
c906108c
SS
5238
5239@noindent
5240you can print the contents of @code{array} with
5241
474c8240 5242@smallexample
c906108c 5243p *array@@len
474c8240 5244@end smallexample
c906108c
SS
5245
5246The left operand of @samp{@@} must reside in memory. Array values made
5247with @samp{@@} in this way behave just like other arrays in terms of
5248subscripting, and are coerced to pointers when used in expressions.
5249Artificial arrays most often appear in expressions via the value history
5250(@pxref{Value History, ,Value history}), after printing one out.
5251
5252Another way to create an artificial array is to use a cast.
5253This re-interprets a value as if it were an array.
5254The value need not be in memory:
474c8240 5255@smallexample
c906108c
SS
5256(@value{GDBP}) p/x (short[2])0x12345678
5257$1 = @{0x1234, 0x5678@}
474c8240 5258@end smallexample
c906108c
SS
5259
5260As a convenience, if you leave the array length out (as in
c3f6f71d 5261@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5262the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5263@smallexample
c906108c
SS
5264(@value{GDBP}) p/x (short[])0x12345678
5265$2 = @{0x1234, 0x5678@}
474c8240 5266@end smallexample
c906108c
SS
5267
5268Sometimes the artificial array mechanism is not quite enough; in
5269moderately complex data structures, the elements of interest may not
5270actually be adjacent---for example, if you are interested in the values
5271of pointers in an array. One useful work-around in this situation is
5272to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5273variables}) as a counter in an expression that prints the first
5274interesting value, and then repeat that expression via @key{RET}. For
5275instance, suppose you have an array @code{dtab} of pointers to
5276structures, and you are interested in the values of a field @code{fv}
5277in each structure. Here is an example of what you might type:
5278
474c8240 5279@smallexample
c906108c
SS
5280set $i = 0
5281p dtab[$i++]->fv
5282@key{RET}
5283@key{RET}
5284@dots{}
474c8240 5285@end smallexample
c906108c 5286
6d2ebf8b 5287@node Output Formats
c906108c
SS
5288@section Output formats
5289
5290@cindex formatted output
5291@cindex output formats
5292By default, @value{GDBN} prints a value according to its data type. Sometimes
5293this is not what you want. For example, you might want to print a number
5294in hex, or a pointer in decimal. Or you might want to view data in memory
5295at a certain address as a character string or as an instruction. To do
5296these things, specify an @dfn{output format} when you print a value.
5297
5298The simplest use of output formats is to say how to print a value
5299already computed. This is done by starting the arguments of the
5300@code{print} command with a slash and a format letter. The format
5301letters supported are:
5302
5303@table @code
5304@item x
5305Regard the bits of the value as an integer, and print the integer in
5306hexadecimal.
5307
5308@item d
5309Print as integer in signed decimal.
5310
5311@item u
5312Print as integer in unsigned decimal.
5313
5314@item o
5315Print as integer in octal.
5316
5317@item t
5318Print as integer in binary. The letter @samp{t} stands for ``two''.
5319@footnote{@samp{b} cannot be used because these format letters are also
5320used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5321see @ref{Memory,,Examining memory}.}
c906108c
SS
5322
5323@item a
5324@cindex unknown address, locating
3d67e040 5325@cindex locate address
c906108c
SS
5326Print as an address, both absolute in hexadecimal and as an offset from
5327the nearest preceding symbol. You can use this format used to discover
5328where (in what function) an unknown address is located:
5329
474c8240 5330@smallexample
c906108c
SS
5331(@value{GDBP}) p/a 0x54320
5332$3 = 0x54320 <_initialize_vx+396>
474c8240 5333@end smallexample
c906108c 5334
3d67e040
EZ
5335@noindent
5336The command @code{info symbol 0x54320} yields similar results.
5337@xref{Symbols, info symbol}.
5338
c906108c 5339@item c
51274035
EZ
5340Regard as an integer and print it as a character constant. This
5341prints both the numerical value and its character representation. The
5342character representation is replaced with the octal escape @samp{\nnn}
5343for characters outside the 7-bit @sc{ascii} range.
c906108c
SS
5344
5345@item f
5346Regard the bits of the value as a floating point number and print
5347using typical floating point syntax.
5348@end table
5349
5350For example, to print the program counter in hex (@pxref{Registers}), type
5351
474c8240 5352@smallexample
c906108c 5353p/x $pc
474c8240 5354@end smallexample
c906108c
SS
5355
5356@noindent
5357Note that no space is required before the slash; this is because command
5358names in @value{GDBN} cannot contain a slash.
5359
5360To reprint the last value in the value history with a different format,
5361you can use the @code{print} command with just a format and no
5362expression. For example, @samp{p/x} reprints the last value in hex.
5363
6d2ebf8b 5364@node Memory
c906108c
SS
5365@section Examining memory
5366
5367You can use the command @code{x} (for ``examine'') to examine memory in
5368any of several formats, independently of your program's data types.
5369
5370@cindex examining memory
5371@table @code
41afff9a 5372@kindex x @r{(examine memory)}
c906108c
SS
5373@item x/@var{nfu} @var{addr}
5374@itemx x @var{addr}
5375@itemx x
5376Use the @code{x} command to examine memory.
5377@end table
5378
5379@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5380much memory to display and how to format it; @var{addr} is an
5381expression giving the address where you want to start displaying memory.
5382If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5383Several commands set convenient defaults for @var{addr}.
5384
5385@table @r
5386@item @var{n}, the repeat count
5387The repeat count is a decimal integer; the default is 1. It specifies
5388how much memory (counting by units @var{u}) to display.
5389@c This really is **decimal**; unaffected by 'set radix' as of GDB
5390@c 4.1.2.
5391
5392@item @var{f}, the display format
51274035
EZ
5393The display format is one of the formats used by @code{print}
5394(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
5395@samp{f}), and in addition @samp{s} (for null-terminated strings) and
5396@samp{i} (for machine instructions). The default is @samp{x}
5397(hexadecimal) initially. The default changes each time you use either
5398@code{x} or @code{print}.
c906108c
SS
5399
5400@item @var{u}, the unit size
5401The unit size is any of
5402
5403@table @code
5404@item b
5405Bytes.
5406@item h
5407Halfwords (two bytes).
5408@item w
5409Words (four bytes). This is the initial default.
5410@item g
5411Giant words (eight bytes).
5412@end table
5413
5414Each time you specify a unit size with @code{x}, that size becomes the
5415default unit the next time you use @code{x}. (For the @samp{s} and
5416@samp{i} formats, the unit size is ignored and is normally not written.)
5417
5418@item @var{addr}, starting display address
5419@var{addr} is the address where you want @value{GDBN} to begin displaying
5420memory. The expression need not have a pointer value (though it may);
5421it is always interpreted as an integer address of a byte of memory.
5422@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5423@var{addr} is usually just after the last address examined---but several
5424other commands also set the default address: @code{info breakpoints} (to
5425the address of the last breakpoint listed), @code{info line} (to the
5426starting address of a line), and @code{print} (if you use it to display
5427a value from memory).
5428@end table
5429
5430For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5431(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5432starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5433words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5434@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5435
5436Since the letters indicating unit sizes are all distinct from the
5437letters specifying output formats, you do not have to remember whether
5438unit size or format comes first; either order works. The output
5439specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5440(However, the count @var{n} must come first; @samp{wx4} does not work.)
5441
5442Even though the unit size @var{u} is ignored for the formats @samp{s}
5443and @samp{i}, you might still want to use a count @var{n}; for example,
5444@samp{3i} specifies that you want to see three machine instructions,
5445including any operands. The command @code{disassemble} gives an
d4f3574e 5446alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5447Code,,Source and machine code}.
5448
5449All the defaults for the arguments to @code{x} are designed to make it
5450easy to continue scanning memory with minimal specifications each time
5451you use @code{x}. For example, after you have inspected three machine
5452instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5453with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5454the repeat count @var{n} is used again; the other arguments default as
5455for successive uses of @code{x}.
5456
5457@cindex @code{$_}, @code{$__}, and value history
5458The addresses and contents printed by the @code{x} command are not saved
5459in the value history because there is often too much of them and they
5460would get in the way. Instead, @value{GDBN} makes these values available for
5461subsequent use in expressions as values of the convenience variables
5462@code{$_} and @code{$__}. After an @code{x} command, the last address
5463examined is available for use in expressions in the convenience variable
5464@code{$_}. The contents of that address, as examined, are available in
5465the convenience variable @code{$__}.
5466
5467If the @code{x} command has a repeat count, the address and contents saved
5468are from the last memory unit printed; this is not the same as the last
5469address printed if several units were printed on the last line of output.
5470
09d4efe1
EZ
5471@cindex remote memory comparison
5472@cindex verify remote memory image
5473When you are debugging a program running on a remote target machine
5474(@pxref{Remote}), you may wish to verify the program's image in the
5475remote machine's memory against the executable file you downloaded to
5476the target. The @code{compare-sections} command is provided for such
5477situations.
5478
5479@table @code
5480@kindex compare-sections
5481@item compare-sections @r{[}@var{section-name}@r{]}
5482Compare the data of a loadable section @var{section-name} in the
5483executable file of the program being debugged with the same section in
5484the remote machine's memory, and report any mismatches. With no
5485arguments, compares all loadable sections. This command's
5486availability depends on the target's support for the @code{"qCRC"}
5487remote request.
5488@end table
5489
6d2ebf8b 5490@node Auto Display
c906108c
SS
5491@section Automatic display
5492@cindex automatic display
5493@cindex display of expressions
5494
5495If you find that you want to print the value of an expression frequently
5496(to see how it changes), you might want to add it to the @dfn{automatic
5497display list} so that @value{GDBN} prints its value each time your program stops.
5498Each expression added to the list is given a number to identify it;
5499to remove an expression from the list, you specify that number.
5500The automatic display looks like this:
5501
474c8240 5502@smallexample
c906108c
SS
55032: foo = 38
55043: bar[5] = (struct hack *) 0x3804
474c8240 5505@end smallexample
c906108c
SS
5506
5507@noindent
5508This display shows item numbers, expressions and their current values. As with
5509displays you request manually using @code{x} or @code{print}, you can
5510specify the output format you prefer; in fact, @code{display} decides
5511whether to use @code{print} or @code{x} depending on how elaborate your
5512format specification is---it uses @code{x} if you specify a unit size,
5513or one of the two formats (@samp{i} and @samp{s}) that are only
5514supported by @code{x}; otherwise it uses @code{print}.
5515
5516@table @code
5517@kindex display
d4f3574e
SS
5518@item display @var{expr}
5519Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5520each time your program stops. @xref{Expressions, ,Expressions}.
5521
5522@code{display} does not repeat if you press @key{RET} again after using it.
5523
d4f3574e 5524@item display/@var{fmt} @var{expr}
c906108c 5525For @var{fmt} specifying only a display format and not a size or
d4f3574e 5526count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5527arrange to display it each time in the specified format @var{fmt}.
5528@xref{Output Formats,,Output formats}.
5529
5530@item display/@var{fmt} @var{addr}
5531For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5532number of units, add the expression @var{addr} as a memory address to
5533be examined each time your program stops. Examining means in effect
5534doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5535@end table
5536
5537For example, @samp{display/i $pc} can be helpful, to see the machine
5538instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5539is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5540
5541@table @code
5542@kindex delete display
5543@kindex undisplay
5544@item undisplay @var{dnums}@dots{}
5545@itemx delete display @var{dnums}@dots{}
5546Remove item numbers @var{dnums} from the list of expressions to display.
5547
5548@code{undisplay} does not repeat if you press @key{RET} after using it.
5549(Otherwise you would just get the error @samp{No display number @dots{}}.)
5550
5551@kindex disable display
5552@item disable display @var{dnums}@dots{}
5553Disable the display of item numbers @var{dnums}. A disabled display
5554item is not printed automatically, but is not forgotten. It may be
5555enabled again later.
5556
5557@kindex enable display
5558@item enable display @var{dnums}@dots{}
5559Enable display of item numbers @var{dnums}. It becomes effective once
5560again in auto display of its expression, until you specify otherwise.
5561
5562@item display
5563Display the current values of the expressions on the list, just as is
5564done when your program stops.
5565
5566@kindex info display
5567@item info display
5568Print the list of expressions previously set up to display
5569automatically, each one with its item number, but without showing the
5570values. This includes disabled expressions, which are marked as such.
5571It also includes expressions which would not be displayed right now
5572because they refer to automatic variables not currently available.
5573@end table
5574
15387254 5575@cindex display disabled out of scope
c906108c
SS
5576If a display expression refers to local variables, then it does not make
5577sense outside the lexical context for which it was set up. Such an
5578expression is disabled when execution enters a context where one of its
5579variables is not defined. For example, if you give the command
5580@code{display last_char} while inside a function with an argument
5581@code{last_char}, @value{GDBN} displays this argument while your program
5582continues to stop inside that function. When it stops elsewhere---where
5583there is no variable @code{last_char}---the display is disabled
5584automatically. The next time your program stops where @code{last_char}
5585is meaningful, you can enable the display expression once again.
5586
6d2ebf8b 5587@node Print Settings
c906108c
SS
5588@section Print settings
5589
5590@cindex format options
5591@cindex print settings
5592@value{GDBN} provides the following ways to control how arrays, structures,
5593and symbols are printed.
5594
5595@noindent
5596These settings are useful for debugging programs in any language:
5597
5598@table @code
4644b6e3 5599@kindex set print
c906108c
SS
5600@item set print address
5601@itemx set print address on
4644b6e3 5602@cindex print/don't print memory addresses
c906108c
SS
5603@value{GDBN} prints memory addresses showing the location of stack
5604traces, structure values, pointer values, breakpoints, and so forth,
5605even when it also displays the contents of those addresses. The default
5606is @code{on}. For example, this is what a stack frame display looks like with
5607@code{set print address on}:
5608
5609@smallexample
5610@group
5611(@value{GDBP}) f
5612#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5613 at input.c:530
5614530 if (lquote != def_lquote)
5615@end group
5616@end smallexample
5617
5618@item set print address off
5619Do not print addresses when displaying their contents. For example,
5620this is the same stack frame displayed with @code{set print address off}:
5621
5622@smallexample
5623@group
5624(@value{GDBP}) set print addr off
5625(@value{GDBP}) f
5626#0 set_quotes (lq="<<", rq=">>") at input.c:530
5627530 if (lquote != def_lquote)
5628@end group
5629@end smallexample
5630
5631You can use @samp{set print address off} to eliminate all machine
5632dependent displays from the @value{GDBN} interface. For example, with
5633@code{print address off}, you should get the same text for backtraces on
5634all machines---whether or not they involve pointer arguments.
5635
4644b6e3 5636@kindex show print
c906108c
SS
5637@item show print address
5638Show whether or not addresses are to be printed.
5639@end table
5640
5641When @value{GDBN} prints a symbolic address, it normally prints the
5642closest earlier symbol plus an offset. If that symbol does not uniquely
5643identify the address (for example, it is a name whose scope is a single
5644source file), you may need to clarify. One way to do this is with
5645@code{info line}, for example @samp{info line *0x4537}. Alternately,
5646you can set @value{GDBN} to print the source file and line number when
5647it prints a symbolic address:
5648
5649@table @code
c906108c 5650@item set print symbol-filename on
9c16f35a
EZ
5651@cindex source file and line of a symbol
5652@cindex symbol, source file and line
c906108c
SS
5653Tell @value{GDBN} to print the source file name and line number of a
5654symbol in the symbolic form of an address.
5655
5656@item set print symbol-filename off
5657Do not print source file name and line number of a symbol. This is the
5658default.
5659
c906108c
SS
5660@item show print symbol-filename
5661Show whether or not @value{GDBN} will print the source file name and
5662line number of a symbol in the symbolic form of an address.
5663@end table
5664
5665Another situation where it is helpful to show symbol filenames and line
5666numbers is when disassembling code; @value{GDBN} shows you the line
5667number and source file that corresponds to each instruction.
5668
5669Also, you may wish to see the symbolic form only if the address being
5670printed is reasonably close to the closest earlier symbol:
5671
5672@table @code
c906108c 5673@item set print max-symbolic-offset @var{max-offset}
4644b6e3 5674@cindex maximum value for offset of closest symbol
c906108c
SS
5675Tell @value{GDBN} to only display the symbolic form of an address if the
5676offset between the closest earlier symbol and the address is less than
5d161b24 5677@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5678to always print the symbolic form of an address if any symbol precedes it.
5679
c906108c
SS
5680@item show print max-symbolic-offset
5681Ask how large the maximum offset is that @value{GDBN} prints in a
5682symbolic address.
5683@end table
5684
5685@cindex wild pointer, interpreting
5686@cindex pointer, finding referent
5687If you have a pointer and you are not sure where it points, try
5688@samp{set print symbol-filename on}. Then you can determine the name
5689and source file location of the variable where it points, using
5690@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5691For example, here @value{GDBN} shows that a variable @code{ptt} points
5692at another variable @code{t}, defined in @file{hi2.c}:
5693
474c8240 5694@smallexample
c906108c
SS
5695(@value{GDBP}) set print symbol-filename on
5696(@value{GDBP}) p/a ptt
5697$4 = 0xe008 <t in hi2.c>
474c8240 5698@end smallexample
c906108c
SS
5699
5700@quotation
5701@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5702does not show the symbol name and filename of the referent, even with
5703the appropriate @code{set print} options turned on.
5704@end quotation
5705
5706Other settings control how different kinds of objects are printed:
5707
5708@table @code
c906108c
SS
5709@item set print array
5710@itemx set print array on
4644b6e3 5711@cindex pretty print arrays
c906108c
SS
5712Pretty print arrays. This format is more convenient to read,
5713but uses more space. The default is off.
5714
5715@item set print array off
5716Return to compressed format for arrays.
5717
c906108c
SS
5718@item show print array
5719Show whether compressed or pretty format is selected for displaying
5720arrays.
5721
c906108c 5722@item set print elements @var{number-of-elements}
4644b6e3 5723@cindex number of array elements to print
9c16f35a 5724@cindex limit on number of printed array elements
c906108c
SS
5725Set a limit on how many elements of an array @value{GDBN} will print.
5726If @value{GDBN} is printing a large array, it stops printing after it has
5727printed the number of elements set by the @code{set print elements} command.
5728This limit also applies to the display of strings.
d4f3574e 5729When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5730Setting @var{number-of-elements} to zero means that the printing is unlimited.
5731
c906108c
SS
5732@item show print elements
5733Display the number of elements of a large array that @value{GDBN} will print.
5734If the number is 0, then the printing is unlimited.
5735
9c16f35a
EZ
5736@item set print repeats
5737@cindex repeated array elements
5738Set the threshold for suppressing display of repeated array
5739elelments. When the number of consecutive identical elements of an
5740array exceeds the threshold, @value{GDBN} prints the string
5741@code{"<repeats @var{n} times>"}, where @var{n} is the number of
5742identical repetitions, instead of displaying the identical elements
5743themselves. Setting the threshold to zero will cause all elements to
5744be individually printed. The default threshold is 10.
5745
5746@item show print repeats
5747Display the current threshold for printing repeated identical
5748elements.
5749
c906108c 5750@item set print null-stop
4644b6e3 5751@cindex @sc{null} elements in arrays
c906108c 5752Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5753@sc{null} is encountered. This is useful when large arrays actually
c906108c 5754contain only short strings.
d4f3574e 5755The default is off.
c906108c 5756
9c16f35a
EZ
5757@item show print null-stop
5758Show whether @value{GDBN} stops printing an array on the first
5759@sc{null} character.
5760
c906108c 5761@item set print pretty on
9c16f35a
EZ
5762@cindex print structures in indented form
5763@cindex indentation in structure display
5d161b24 5764Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5765per line, like this:
5766
5767@smallexample
5768@group
5769$1 = @{
5770 next = 0x0,
5771 flags = @{
5772 sweet = 1,
5773 sour = 1
5774 @},
5775 meat = 0x54 "Pork"
5776@}
5777@end group
5778@end smallexample
5779
5780@item set print pretty off
5781Cause @value{GDBN} to print structures in a compact format, like this:
5782
5783@smallexample
5784@group
5785$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5786meat = 0x54 "Pork"@}
5787@end group
5788@end smallexample
5789
5790@noindent
5791This is the default format.
5792
c906108c
SS
5793@item show print pretty
5794Show which format @value{GDBN} is using to print structures.
5795
c906108c 5796@item set print sevenbit-strings on
4644b6e3
EZ
5797@cindex eight-bit characters in strings
5798@cindex octal escapes in strings
c906108c
SS
5799Print using only seven-bit characters; if this option is set,
5800@value{GDBN} displays any eight-bit characters (in strings or
5801character values) using the notation @code{\}@var{nnn}. This setting is
5802best if you are working in English (@sc{ascii}) and you use the
5803high-order bit of characters as a marker or ``meta'' bit.
5804
5805@item set print sevenbit-strings off
5806Print full eight-bit characters. This allows the use of more
5807international character sets, and is the default.
5808
c906108c
SS
5809@item show print sevenbit-strings
5810Show whether or not @value{GDBN} is printing only seven-bit characters.
5811
c906108c 5812@item set print union on
4644b6e3 5813@cindex unions in structures, printing
9c16f35a
EZ
5814Tell @value{GDBN} to print unions which are contained in structures
5815and other unions. This is the default setting.
c906108c
SS
5816
5817@item set print union off
9c16f35a
EZ
5818Tell @value{GDBN} not to print unions which are contained in
5819structures and other unions. @value{GDBN} will print @code{"@{...@}"}
5820instead.
c906108c 5821
c906108c
SS
5822@item show print union
5823Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 5824structures and other unions.
c906108c
SS
5825
5826For example, given the declarations
5827
5828@smallexample
5829typedef enum @{Tree, Bug@} Species;
5830typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5831typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5832 Bug_forms;
5833
5834struct thing @{
5835 Species it;
5836 union @{
5837 Tree_forms tree;
5838 Bug_forms bug;
5839 @} form;
5840@};
5841
5842struct thing foo = @{Tree, @{Acorn@}@};
5843@end smallexample
5844
5845@noindent
5846with @code{set print union on} in effect @samp{p foo} would print
5847
5848@smallexample
5849$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5850@end smallexample
5851
5852@noindent
5853and with @code{set print union off} in effect it would print
5854
5855@smallexample
5856$1 = @{it = Tree, form = @{...@}@}
5857@end smallexample
9c16f35a
EZ
5858
5859@noindent
5860@code{set print union} affects programs written in C-like languages
5861and in Pascal.
c906108c
SS
5862@end table
5863
c906108c
SS
5864@need 1000
5865@noindent
b37052ae 5866These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5867
5868@table @code
4644b6e3 5869@cindex demangling C@t{++} names
c906108c
SS
5870@item set print demangle
5871@itemx set print demangle on
b37052ae 5872Print C@t{++} names in their source form rather than in the encoded
c906108c 5873(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5874linkage. The default is on.
c906108c 5875
c906108c 5876@item show print demangle
b37052ae 5877Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 5878
c906108c
SS
5879@item set print asm-demangle
5880@itemx set print asm-demangle on
b37052ae 5881Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5882in assembler code printouts such as instruction disassemblies.
5883The default is off.
5884
c906108c 5885@item show print asm-demangle
b37052ae 5886Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5887or demangled form.
5888
b37052ae
EZ
5889@cindex C@t{++} symbol decoding style
5890@cindex symbol decoding style, C@t{++}
a8f24a35 5891@kindex set demangle-style
c906108c
SS
5892@item set demangle-style @var{style}
5893Choose among several encoding schemes used by different compilers to
b37052ae 5894represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5895
5896@table @code
5897@item auto
5898Allow @value{GDBN} to choose a decoding style by inspecting your program.
5899
5900@item gnu
b37052ae 5901Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5902This is the default.
c906108c
SS
5903
5904@item hp
b37052ae 5905Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5906
5907@item lucid
b37052ae 5908Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5909
5910@item arm
b37052ae 5911Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5912@strong{Warning:} this setting alone is not sufficient to allow
5913debugging @code{cfront}-generated executables. @value{GDBN} would
5914require further enhancement to permit that.
5915
5916@end table
5917If you omit @var{style}, you will see a list of possible formats.
5918
c906108c 5919@item show demangle-style
b37052ae 5920Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 5921
c906108c
SS
5922@item set print object
5923@itemx set print object on
4644b6e3 5924@cindex derived type of an object, printing
9c16f35a 5925@cindex display derived types
c906108c
SS
5926When displaying a pointer to an object, identify the @emph{actual}
5927(derived) type of the object rather than the @emph{declared} type, using
5928the virtual function table.
5929
5930@item set print object off
5931Display only the declared type of objects, without reference to the
5932virtual function table. This is the default setting.
5933
c906108c
SS
5934@item show print object
5935Show whether actual, or declared, object types are displayed.
5936
c906108c
SS
5937@item set print static-members
5938@itemx set print static-members on
4644b6e3 5939@cindex static members of C@t{++} objects
b37052ae 5940Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5941
5942@item set print static-members off
b37052ae 5943Do not print static members when displaying a C@t{++} object.
c906108c 5944
c906108c 5945@item show print static-members
9c16f35a
EZ
5946Show whether C@t{++} static members are printed or not.
5947
5948@item set print pascal_static-members
5949@itemx set print pascal_static-members on
5950@cindex static members of Pacal objects
5951@cindex Pacal objects, static members display
5952Print static members when displaying a Pascal object. The default is on.
5953
5954@item set print pascal_static-members off
5955Do not print static members when displaying a Pascal object.
5956
5957@item show print pascal_static-members
5958Show whether Pascal static members are printed or not.
c906108c
SS
5959
5960@c These don't work with HP ANSI C++ yet.
c906108c
SS
5961@item set print vtbl
5962@itemx set print vtbl on
4644b6e3 5963@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
5964@cindex virtual functions (C@t{++}) display
5965@cindex VTBL display
b37052ae 5966Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5967(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5968ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5969
5970@item set print vtbl off
b37052ae 5971Do not pretty print C@t{++} virtual function tables.
c906108c 5972
c906108c 5973@item show print vtbl
b37052ae 5974Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5975@end table
c906108c 5976
6d2ebf8b 5977@node Value History
c906108c
SS
5978@section Value history
5979
5980@cindex value history
9c16f35a 5981@cindex history of values printed by @value{GDBN}
5d161b24
DB
5982Values printed by the @code{print} command are saved in the @value{GDBN}
5983@dfn{value history}. This allows you to refer to them in other expressions.
5984Values are kept until the symbol table is re-read or discarded
5985(for example with the @code{file} or @code{symbol-file} commands).
5986When the symbol table changes, the value history is discarded,
5987since the values may contain pointers back to the types defined in the
c906108c
SS
5988symbol table.
5989
5990@cindex @code{$}
5991@cindex @code{$$}
5992@cindex history number
5993The values printed are given @dfn{history numbers} by which you can
5994refer to them. These are successive integers starting with one.
5995@code{print} shows you the history number assigned to a value by
5996printing @samp{$@var{num} = } before the value; here @var{num} is the
5997history number.
5998
5999To refer to any previous value, use @samp{$} followed by the value's
6000history number. The way @code{print} labels its output is designed to
6001remind you of this. Just @code{$} refers to the most recent value in
6002the history, and @code{$$} refers to the value before that.
6003@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
6004is the value just prior to @code{$$}, @code{$$1} is equivalent to
6005@code{$$}, and @code{$$0} is equivalent to @code{$}.
6006
6007For example, suppose you have just printed a pointer to a structure and
6008want to see the contents of the structure. It suffices to type
6009
474c8240 6010@smallexample
c906108c 6011p *$
474c8240 6012@end smallexample
c906108c
SS
6013
6014If you have a chain of structures where the component @code{next} points
6015to the next one, you can print the contents of the next one with this:
6016
474c8240 6017@smallexample
c906108c 6018p *$.next
474c8240 6019@end smallexample
c906108c
SS
6020
6021@noindent
6022You can print successive links in the chain by repeating this
6023command---which you can do by just typing @key{RET}.
6024
6025Note that the history records values, not expressions. If the value of
6026@code{x} is 4 and you type these commands:
6027
474c8240 6028@smallexample
c906108c
SS
6029print x
6030set x=5
474c8240 6031@end smallexample
c906108c
SS
6032
6033@noindent
6034then the value recorded in the value history by the @code{print} command
6035remains 4 even though the value of @code{x} has changed.
6036
6037@table @code
6038@kindex show values
6039@item show values
6040Print the last ten values in the value history, with their item numbers.
6041This is like @samp{p@ $$9} repeated ten times, except that @code{show
6042values} does not change the history.
6043
6044@item show values @var{n}
6045Print ten history values centered on history item number @var{n}.
6046
6047@item show values +
6048Print ten history values just after the values last printed. If no more
6049values are available, @code{show values +} produces no display.
6050@end table
6051
6052Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
6053same effect as @samp{show values +}.
6054
6d2ebf8b 6055@node Convenience Vars
c906108c
SS
6056@section Convenience variables
6057
6058@cindex convenience variables
9c16f35a 6059@cindex user-defined variables
c906108c
SS
6060@value{GDBN} provides @dfn{convenience variables} that you can use within
6061@value{GDBN} to hold on to a value and refer to it later. These variables
6062exist entirely within @value{GDBN}; they are not part of your program, and
6063setting a convenience variable has no direct effect on further execution
6064of your program. That is why you can use them freely.
6065
6066Convenience variables are prefixed with @samp{$}. Any name preceded by
6067@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 6068the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
6069(Value history references, in contrast, are @emph{numbers} preceded
6070by @samp{$}. @xref{Value History, ,Value history}.)
6071
6072You can save a value in a convenience variable with an assignment
6073expression, just as you would set a variable in your program.
6074For example:
6075
474c8240 6076@smallexample
c906108c 6077set $foo = *object_ptr
474c8240 6078@end smallexample
c906108c
SS
6079
6080@noindent
6081would save in @code{$foo} the value contained in the object pointed to by
6082@code{object_ptr}.
6083
6084Using a convenience variable for the first time creates it, but its
6085value is @code{void} until you assign a new value. You can alter the
6086value with another assignment at any time.
6087
6088Convenience variables have no fixed types. You can assign a convenience
6089variable any type of value, including structures and arrays, even if
6090that variable already has a value of a different type. The convenience
6091variable, when used as an expression, has the type of its current value.
6092
6093@table @code
6094@kindex show convenience
9c16f35a 6095@cindex show all user variables
c906108c
SS
6096@item show convenience
6097Print a list of convenience variables used so far, and their values.
d4f3574e 6098Abbreviated @code{show conv}.
c906108c
SS
6099@end table
6100
6101One of the ways to use a convenience variable is as a counter to be
6102incremented or a pointer to be advanced. For example, to print
6103a field from successive elements of an array of structures:
6104
474c8240 6105@smallexample
c906108c
SS
6106set $i = 0
6107print bar[$i++]->contents
474c8240 6108@end smallexample
c906108c 6109
d4f3574e
SS
6110@noindent
6111Repeat that command by typing @key{RET}.
c906108c
SS
6112
6113Some convenience variables are created automatically by @value{GDBN} and given
6114values likely to be useful.
6115
6116@table @code
41afff9a 6117@vindex $_@r{, convenience variable}
c906108c
SS
6118@item $_
6119The variable @code{$_} is automatically set by the @code{x} command to
6120the last address examined (@pxref{Memory, ,Examining memory}). Other
6121commands which provide a default address for @code{x} to examine also
6122set @code{$_} to that address; these commands include @code{info line}
6123and @code{info breakpoint}. The type of @code{$_} is @code{void *}
6124except when set by the @code{x} command, in which case it is a pointer
6125to the type of @code{$__}.
6126
41afff9a 6127@vindex $__@r{, convenience variable}
c906108c
SS
6128@item $__
6129The variable @code{$__} is automatically set by the @code{x} command
6130to the value found in the last address examined. Its type is chosen
6131to match the format in which the data was printed.
6132
6133@item $_exitcode
41afff9a 6134@vindex $_exitcode@r{, convenience variable}
c906108c
SS
6135The variable @code{$_exitcode} is automatically set to the exit code when
6136the program being debugged terminates.
6137@end table
6138
53a5351d
JM
6139On HP-UX systems, if you refer to a function or variable name that
6140begins with a dollar sign, @value{GDBN} searches for a user or system
6141name first, before it searches for a convenience variable.
c906108c 6142
6d2ebf8b 6143@node Registers
c906108c
SS
6144@section Registers
6145
6146@cindex registers
6147You can refer to machine register contents, in expressions, as variables
6148with names starting with @samp{$}. The names of registers are different
6149for each machine; use @code{info registers} to see the names used on
6150your machine.
6151
6152@table @code
6153@kindex info registers
6154@item info registers
6155Print the names and values of all registers except floating-point
c85508ee 6156and vector registers (in the selected stack frame).
c906108c
SS
6157
6158@kindex info all-registers
6159@cindex floating point registers
6160@item info all-registers
6161Print the names and values of all registers, including floating-point
c85508ee 6162and vector registers (in the selected stack frame).
c906108c
SS
6163
6164@item info registers @var{regname} @dots{}
6165Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
6166As discussed in detail below, register values are normally relative to
6167the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
6168the machine you are using, with or without the initial @samp{$}.
6169@end table
6170
e09f16f9
EZ
6171@cindex stack pointer register
6172@cindex program counter register
6173@cindex process status register
6174@cindex frame pointer register
6175@cindex standard registers
c906108c
SS
6176@value{GDBN} has four ``standard'' register names that are available (in
6177expressions) on most machines---whenever they do not conflict with an
6178architecture's canonical mnemonics for registers. The register names
6179@code{$pc} and @code{$sp} are used for the program counter register and
6180the stack pointer. @code{$fp} is used for a register that contains a
6181pointer to the current stack frame, and @code{$ps} is used for a
6182register that contains the processor status. For example,
6183you could print the program counter in hex with
6184
474c8240 6185@smallexample
c906108c 6186p/x $pc
474c8240 6187@end smallexample
c906108c
SS
6188
6189@noindent
6190or print the instruction to be executed next with
6191
474c8240 6192@smallexample
c906108c 6193x/i $pc
474c8240 6194@end smallexample
c906108c
SS
6195
6196@noindent
6197or add four to the stack pointer@footnote{This is a way of removing
6198one word from the stack, on machines where stacks grow downward in
6199memory (most machines, nowadays). This assumes that the innermost
6200stack frame is selected; setting @code{$sp} is not allowed when other
6201stack frames are selected. To pop entire frames off the stack,
6202regardless of machine architecture, use @code{return};
d4f3574e 6203see @ref{Returning, ,Returning from a function}.} with
c906108c 6204
474c8240 6205@smallexample
c906108c 6206set $sp += 4
474c8240 6207@end smallexample
c906108c
SS
6208
6209Whenever possible, these four standard register names are available on
6210your machine even though the machine has different canonical mnemonics,
6211so long as there is no conflict. The @code{info registers} command
6212shows the canonical names. For example, on the SPARC, @code{info
6213registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
6214can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6215is an alias for the @sc{eflags} register.
c906108c
SS
6216
6217@value{GDBN} always considers the contents of an ordinary register as an
6218integer when the register is examined in this way. Some machines have
6219special registers which can hold nothing but floating point; these
6220registers are considered to have floating point values. There is no way
6221to refer to the contents of an ordinary register as floating point value
6222(although you can @emph{print} it as a floating point value with
6223@samp{print/f $@var{regname}}).
6224
6225Some registers have distinct ``raw'' and ``virtual'' data formats. This
6226means that the data format in which the register contents are saved by
6227the operating system is not the same one that your program normally
6228sees. For example, the registers of the 68881 floating point
6229coprocessor are always saved in ``extended'' (raw) format, but all C
6230programs expect to work with ``double'' (virtual) format. In such
5d161b24 6231cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
6232that makes sense for your program), but the @code{info registers} command
6233prints the data in both formats.
6234
6235Normally, register values are relative to the selected stack frame
6236(@pxref{Selection, ,Selecting a frame}). This means that you get the
6237value that the register would contain if all stack frames farther in
6238were exited and their saved registers restored. In order to see the
6239true contents of hardware registers, you must select the innermost
6240frame (with @samp{frame 0}).
6241
6242However, @value{GDBN} must deduce where registers are saved, from the machine
6243code generated by your compiler. If some registers are not saved, or if
6244@value{GDBN} is unable to locate the saved registers, the selected stack
6245frame makes no difference.
6246
6d2ebf8b 6247@node Floating Point Hardware
c906108c
SS
6248@section Floating point hardware
6249@cindex floating point
6250
6251Depending on the configuration, @value{GDBN} may be able to give
6252you more information about the status of the floating point hardware.
6253
6254@table @code
6255@kindex info float
6256@item info float
6257Display hardware-dependent information about the floating
6258point unit. The exact contents and layout vary depending on the
6259floating point chip. Currently, @samp{info float} is supported on
6260the ARM and x86 machines.
6261@end table
c906108c 6262
e76f1f2e
AC
6263@node Vector Unit
6264@section Vector Unit
6265@cindex vector unit
6266
6267Depending on the configuration, @value{GDBN} may be able to give you
6268more information about the status of the vector unit.
6269
6270@table @code
6271@kindex info vector
6272@item info vector
6273Display information about the vector unit. The exact contents and
6274layout vary depending on the hardware.
6275@end table
6276
721c2651
EZ
6277@node OS Information
6278@section Operating system auxiliary information
6279@cindex OS information
6280
6281@value{GDBN} provides interfaces to useful OS facilities that can help
6282you debug your program.
6283
6284@cindex @code{ptrace} system call
6285@cindex @code{struct user} contents
6286When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6287machines), it interfaces with the inferior via the @code{ptrace}
6288system call. The operating system creates a special sata structure,
6289called @code{struct user}, for this interface. You can use the
6290command @code{info udot} to display the contents of this data
6291structure.
6292
6293@table @code
6294@item info udot
6295@kindex info udot
6296Display the contents of the @code{struct user} maintained by the OS
6297kernel for the program being debugged. @value{GDBN} displays the
6298contents of @code{struct user} as a list of hex numbers, similar to
6299the @code{examine} command.
6300@end table
6301
b383017d
RM
6302@cindex auxiliary vector
6303@cindex vector, auxiliary
b383017d
RM
6304Some operating systems supply an @dfn{auxiliary vector} to programs at
6305startup. This is akin to the arguments and environment that you
6306specify for a program, but contains a system-dependent variety of
6307binary values that tell system libraries important details about the
6308hardware, operating system, and process. Each value's purpose is
6309identified by an integer tag; the meanings are well-known but system-specific.
6310Depending on the configuration and operating system facilities,
9c16f35a
EZ
6311@value{GDBN} may be able to show you this information. For remote
6312targets, this functionality may further depend on the remote stub's
6313support of the @samp{qPart:auxv:read} packet, see @ref{Remote
6314configuration, auxiliary vector}.
b383017d
RM
6315
6316@table @code
6317@kindex info auxv
6318@item info auxv
6319Display the auxiliary vector of the inferior, which can be either a
e4937fc1 6320live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
6321numerically, and also shows names and text descriptions for recognized
6322tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 6323pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
6324most appropriate form for a recognized tag, and in hexadecimal for
6325an unrecognized tag.
6326@end table
6327
721c2651 6328
29e57380 6329@node Memory Region Attributes
b383017d 6330@section Memory region attributes
29e57380
C
6331@cindex memory region attributes
6332
b383017d
RM
6333@dfn{Memory region attributes} allow you to describe special handling
6334required by regions of your target's memory. @value{GDBN} uses attributes
29e57380
C
6335to determine whether to allow certain types of memory accesses; whether to
6336use specific width accesses; and whether to cache target memory.
6337
6338Defined memory regions can be individually enabled and disabled. When a
6339memory region is disabled, @value{GDBN} uses the default attributes when
6340accessing memory in that region. Similarly, if no memory regions have
6341been defined, @value{GDBN} uses the default attributes when accessing
6342all memory.
6343
b383017d 6344When a memory region is defined, it is given a number to identify it;
29e57380
C
6345to enable, disable, or remove a memory region, you specify that number.
6346
6347@table @code
6348@kindex mem
bfac230e 6349@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
6350Define a memory region bounded by @var{lower} and @var{upper} with
6351attributes @var{attributes}@dots{}, and add it to the list of regions
6352monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
6353case: it is treated as the the target's maximum memory address.
bfac230e 6354(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
6355
6356@kindex delete mem
6357@item delete mem @var{nums}@dots{}
09d4efe1
EZ
6358Remove memory regions @var{nums}@dots{} from the list of regions
6359monitored by @value{GDBN}.
29e57380
C
6360
6361@kindex disable mem
6362@item disable mem @var{nums}@dots{}
09d4efe1 6363Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 6364A disabled memory region is not forgotten.
29e57380
C
6365It may be enabled again later.
6366
6367@kindex enable mem
6368@item enable mem @var{nums}@dots{}
09d4efe1 6369Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
6370
6371@kindex info mem
6372@item info mem
6373Print a table of all defined memory regions, with the following columns
09d4efe1 6374for each region:
29e57380
C
6375
6376@table @emph
6377@item Memory Region Number
6378@item Enabled or Disabled.
b383017d 6379Enabled memory regions are marked with @samp{y}.
29e57380
C
6380Disabled memory regions are marked with @samp{n}.
6381
6382@item Lo Address
6383The address defining the inclusive lower bound of the memory region.
6384
6385@item Hi Address
6386The address defining the exclusive upper bound of the memory region.
6387
6388@item Attributes
6389The list of attributes set for this memory region.
6390@end table
6391@end table
6392
6393
6394@subsection Attributes
6395
b383017d 6396@subsubsection Memory Access Mode
29e57380
C
6397The access mode attributes set whether @value{GDBN} may make read or
6398write accesses to a memory region.
6399
6400While these attributes prevent @value{GDBN} from performing invalid
6401memory accesses, they do nothing to prevent the target system, I/O DMA,
6402etc. from accessing memory.
6403
6404@table @code
6405@item ro
6406Memory is read only.
6407@item wo
6408Memory is write only.
6409@item rw
6ca652b0 6410Memory is read/write. This is the default.
29e57380
C
6411@end table
6412
6413@subsubsection Memory Access Size
6414The acccess size attributes tells @value{GDBN} to use specific sized
6415accesses in the memory region. Often memory mapped device registers
6416require specific sized accesses. If no access size attribute is
6417specified, @value{GDBN} may use accesses of any size.
6418
6419@table @code
6420@item 8
6421Use 8 bit memory accesses.
6422@item 16
6423Use 16 bit memory accesses.
6424@item 32
6425Use 32 bit memory accesses.
6426@item 64
6427Use 64 bit memory accesses.
6428@end table
6429
6430@c @subsubsection Hardware/Software Breakpoints
6431@c The hardware/software breakpoint attributes set whether @value{GDBN}
6432@c will use hardware or software breakpoints for the internal breakpoints
6433@c used by the step, next, finish, until, etc. commands.
6434@c
6435@c @table @code
6436@c @item hwbreak
b383017d 6437@c Always use hardware breakpoints
29e57380
C
6438@c @item swbreak (default)
6439@c @end table
6440
6441@subsubsection Data Cache
6442The data cache attributes set whether @value{GDBN} will cache target
6443memory. While this generally improves performance by reducing debug
6444protocol overhead, it can lead to incorrect results because @value{GDBN}
6445does not know about volatile variables or memory mapped device
6446registers.
6447
6448@table @code
6449@item cache
b383017d 6450Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6451@item nocache
6452Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6453@end table
6454
6455@c @subsubsection Memory Write Verification
b383017d 6456@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6457@c will re-reads data after each write to verify the write was successful.
6458@c
6459@c @table @code
6460@c @item verify
6461@c @item noverify (default)
6462@c @end table
6463
16d9dec6
MS
6464@node Dump/Restore Files
6465@section Copy between memory and a file
6466@cindex dump/restore files
6467@cindex append data to a file
6468@cindex dump data to a file
6469@cindex restore data from a file
16d9dec6 6470
df5215a6
JB
6471You can use the commands @code{dump}, @code{append}, and
6472@code{restore} to copy data between target memory and a file. The
6473@code{dump} and @code{append} commands write data to a file, and the
6474@code{restore} command reads data from a file back into the inferior's
6475memory. Files may be in binary, Motorola S-record, Intel hex, or
6476Tektronix Hex format; however, @value{GDBN} can only append to binary
6477files.
6478
6479@table @code
6480
6481@kindex dump
6482@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6483@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6484Dump the contents of memory from @var{start_addr} to @var{end_addr},
6485or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6486
df5215a6 6487The @var{format} parameter may be any one of:
16d9dec6 6488@table @code
df5215a6
JB
6489@item binary
6490Raw binary form.
6491@item ihex
6492Intel hex format.
6493@item srec
6494Motorola S-record format.
6495@item tekhex
6496Tektronix Hex format.
6497@end table
6498
6499@value{GDBN} uses the same definitions of these formats as the
6500@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6501@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6502form.
6503
6504@kindex append
6505@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6506@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6507Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 6508or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
6509(@value{GDBN} can only append data to files in raw binary form.)
6510
6511@kindex restore
6512@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6513Restore the contents of file @var{filename} into memory. The
6514@code{restore} command can automatically recognize any known @sc{bfd}
6515file format, except for raw binary. To restore a raw binary file you
6516must specify the optional keyword @code{binary} after the filename.
16d9dec6 6517
b383017d 6518If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6519contained in the file. Binary files always start at address zero, so
6520they will be restored at address @var{bias}. Other bfd files have
6521a built-in location; they will be restored at offset @var{bias}
6522from that location.
6523
6524If @var{start} and/or @var{end} are non-zero, then only data between
6525file offset @var{start} and file offset @var{end} will be restored.
b383017d 6526These offsets are relative to the addresses in the file, before
16d9dec6
MS
6527the @var{bias} argument is applied.
6528
6529@end table
6530
384ee23f
EZ
6531@node Core File Generation
6532@section How to Produce a Core File from Your Program
6533@cindex dump core from inferior
6534
6535A @dfn{core file} or @dfn{core dump} is a file that records the memory
6536image of a running process and its process status (register values
6537etc.). Its primary use is post-mortem debugging of a program that
6538crashed while it ran outside a debugger. A program that crashes
6539automatically produces a core file, unless this feature is disabled by
6540the user. @xref{Files}, for information on invoking @value{GDBN} in
6541the post-mortem debugging mode.
6542
6543Occasionally, you may wish to produce a core file of the program you
6544are debugging in order to preserve a snapshot of its state.
6545@value{GDBN} has a special command for that.
6546
6547@table @code
6548@kindex gcore
6549@kindex generate-core-file
6550@item generate-core-file [@var{file}]
6551@itemx gcore [@var{file}]
6552Produce a core dump of the inferior process. The optional argument
6553@var{file} specifies the file name where to put the core dump. If not
6554specified, the file name defaults to @file{core.@var{pid}}, where
6555@var{pid} is the inferior process ID.
6556
6557Note that this command is implemented only for some systems (as of
6558this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6559@end table
6560
a0eb71c5
KB
6561@node Character Sets
6562@section Character Sets
6563@cindex character sets
6564@cindex charset
6565@cindex translating between character sets
6566@cindex host character set
6567@cindex target character set
6568
6569If the program you are debugging uses a different character set to
6570represent characters and strings than the one @value{GDBN} uses itself,
6571@value{GDBN} can automatically translate between the character sets for
6572you. The character set @value{GDBN} uses we call the @dfn{host
6573character set}; the one the inferior program uses we call the
6574@dfn{target character set}.
6575
6576For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6577uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6578remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6579running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6580then the host character set is Latin-1, and the target character set is
6581@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6582target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6583@sc{ebcdic} and Latin 1 as you print character or string values, or use
6584character and string literals in expressions.
6585
6586@value{GDBN} has no way to automatically recognize which character set
6587the inferior program uses; you must tell it, using the @code{set
6588target-charset} command, described below.
6589
6590Here are the commands for controlling @value{GDBN}'s character set
6591support:
6592
6593@table @code
6594@item set target-charset @var{charset}
6595@kindex set target-charset
6596Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6597character set names @value{GDBN} recognizes below, but if you type
6598@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6599list the target character sets it supports.
a0eb71c5
KB
6600@end table
6601
6602@table @code
6603@item set host-charset @var{charset}
6604@kindex set host-charset
6605Set the current host character set to @var{charset}.
6606
6607By default, @value{GDBN} uses a host character set appropriate to the
6608system it is running on; you can override that default using the
6609@code{set host-charset} command.
6610
6611@value{GDBN} can only use certain character sets as its host character
6612set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6613indicate which can be host character sets, but if you type
6614@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6615list the host character sets it supports.
a0eb71c5
KB
6616
6617@item set charset @var{charset}
6618@kindex set charset
e33d66ec
EZ
6619Set the current host and target character sets to @var{charset}. As
6620above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6621@value{GDBN} will list the name of the character sets that can be used
6622for both host and target.
6623
a0eb71c5
KB
6624
6625@item show charset
a0eb71c5 6626@kindex show charset
b383017d 6627Show the names of the current host and target charsets.
e33d66ec
EZ
6628
6629@itemx show host-charset
a0eb71c5 6630@kindex show host-charset
b383017d 6631Show the name of the current host charset.
e33d66ec
EZ
6632
6633@itemx show target-charset
a0eb71c5 6634@kindex show target-charset
b383017d 6635Show the name of the current target charset.
a0eb71c5
KB
6636
6637@end table
6638
6639@value{GDBN} currently includes support for the following character
6640sets:
6641
6642@table @code
6643
6644@item ASCII
6645@cindex ASCII character set
6646Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6647character set.
6648
6649@item ISO-8859-1
6650@cindex ISO 8859-1 character set
6651@cindex ISO Latin 1 character set
e33d66ec 6652The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6653characters needed for French, German, and Spanish. @value{GDBN} can use
6654this as its host character set.
6655
6656@item EBCDIC-US
6657@itemx IBM1047
6658@cindex EBCDIC character set
6659@cindex IBM1047 character set
6660Variants of the @sc{ebcdic} character set, used on some of IBM's
6661mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6662@value{GDBN} cannot use these as its host character set.
6663
6664@end table
6665
6666Note that these are all single-byte character sets. More work inside
6667GDB is needed to support multi-byte or variable-width character
6668encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6669
6670Here is an example of @value{GDBN}'s character set support in action.
6671Assume that the following source code has been placed in the file
6672@file{charset-test.c}:
6673
6674@smallexample
6675#include <stdio.h>
6676
6677char ascii_hello[]
6678 = @{72, 101, 108, 108, 111, 44, 32, 119,
6679 111, 114, 108, 100, 33, 10, 0@};
6680char ibm1047_hello[]
6681 = @{200, 133, 147, 147, 150, 107, 64, 166,
6682 150, 153, 147, 132, 90, 37, 0@};
6683
6684main ()
6685@{
6686 printf ("Hello, world!\n");
6687@}
10998722 6688@end smallexample
a0eb71c5
KB
6689
6690In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6691containing the string @samp{Hello, world!} followed by a newline,
6692encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6693
6694We compile the program, and invoke the debugger on it:
6695
6696@smallexample
6697$ gcc -g charset-test.c -o charset-test
6698$ gdb -nw charset-test
6699GNU gdb 2001-12-19-cvs
6700Copyright 2001 Free Software Foundation, Inc.
6701@dots{}
f7dc1244 6702(@value{GDBP})
10998722 6703@end smallexample
a0eb71c5
KB
6704
6705We can use the @code{show charset} command to see what character sets
6706@value{GDBN} is currently using to interpret and display characters and
6707strings:
6708
6709@smallexample
f7dc1244 6710(@value{GDBP}) show charset
e33d66ec 6711The current host and target character set is `ISO-8859-1'.
f7dc1244 6712(@value{GDBP})
10998722 6713@end smallexample
a0eb71c5
KB
6714
6715For the sake of printing this manual, let's use @sc{ascii} as our
6716initial character set:
6717@smallexample
f7dc1244
EZ
6718(@value{GDBP}) set charset ASCII
6719(@value{GDBP}) show charset
e33d66ec 6720The current host and target character set is `ASCII'.
f7dc1244 6721(@value{GDBP})
10998722 6722@end smallexample
a0eb71c5
KB
6723
6724Let's assume that @sc{ascii} is indeed the correct character set for our
6725host system --- in other words, let's assume that if @value{GDBN} prints
6726characters using the @sc{ascii} character set, our terminal will display
6727them properly. Since our current target character set is also
6728@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6729
6730@smallexample
f7dc1244 6731(@value{GDBP}) print ascii_hello
a0eb71c5 6732$1 = 0x401698 "Hello, world!\n"
f7dc1244 6733(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6734$2 = 72 'H'
f7dc1244 6735(@value{GDBP})
10998722 6736@end smallexample
a0eb71c5
KB
6737
6738@value{GDBN} uses the target character set for character and string
6739literals you use in expressions:
6740
6741@smallexample
f7dc1244 6742(@value{GDBP}) print '+'
a0eb71c5 6743$3 = 43 '+'
f7dc1244 6744(@value{GDBP})
10998722 6745@end smallexample
a0eb71c5
KB
6746
6747The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6748character.
6749
6750@value{GDBN} relies on the user to tell it which character set the
6751target program uses. If we print @code{ibm1047_hello} while our target
6752character set is still @sc{ascii}, we get jibberish:
6753
6754@smallexample
f7dc1244 6755(@value{GDBP}) print ibm1047_hello
a0eb71c5 6756$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 6757(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6758$5 = 200 '\310'
f7dc1244 6759(@value{GDBP})
10998722 6760@end smallexample
a0eb71c5 6761
e33d66ec 6762If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6763@value{GDBN} tells us the character sets it supports:
6764
6765@smallexample
f7dc1244 6766(@value{GDBP}) set target-charset
b383017d 6767ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 6768(@value{GDBP}) set target-charset
10998722 6769@end smallexample
a0eb71c5
KB
6770
6771We can select @sc{ibm1047} as our target character set, and examine the
6772program's strings again. Now the @sc{ascii} string is wrong, but
6773@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6774target character set, @sc{ibm1047}, to the host character set,
6775@sc{ascii}, and they display correctly:
6776
6777@smallexample
f7dc1244
EZ
6778(@value{GDBP}) set target-charset IBM1047
6779(@value{GDBP}) show charset
e33d66ec
EZ
6780The current host character set is `ASCII'.
6781The current target character set is `IBM1047'.
f7dc1244 6782(@value{GDBP}) print ascii_hello
a0eb71c5 6783$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 6784(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6785$7 = 72 '\110'
f7dc1244 6786(@value{GDBP}) print ibm1047_hello
a0eb71c5 6787$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 6788(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6789$9 = 200 'H'
f7dc1244 6790(@value{GDBP})
10998722 6791@end smallexample
a0eb71c5
KB
6792
6793As above, @value{GDBN} uses the target character set for character and
6794string literals you use in expressions:
6795
6796@smallexample
f7dc1244 6797(@value{GDBP}) print '+'
a0eb71c5 6798$10 = 78 '+'
f7dc1244 6799(@value{GDBP})
10998722 6800@end smallexample
a0eb71c5 6801
e33d66ec 6802The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6803character.
6804
09d4efe1
EZ
6805@node Caching Remote Data
6806@section Caching Data of Remote Targets
6807@cindex caching data of remote targets
6808
6809@value{GDBN} can cache data exchanged between the debugger and a
6810remote target (@pxref{Remote}). Such caching generally improves
6811performance, because it reduces the overhead of the remote protocol by
6812bundling memory reads and writes into large chunks. Unfortunately,
6813@value{GDBN} does not currently know anything about volatile
6814registers, and thus data caching will produce incorrect results when
6815volatile registers are in use.
6816
6817@table @code
6818@kindex set remotecache
6819@item set remotecache on
6820@itemx set remotecache off
6821Set caching state for remote targets. When @code{ON}, use data
6822caching. By default, this option is @code{OFF}.
6823
6824@kindex show remotecache
6825@item show remotecache
6826Show the current state of data caching for remote targets.
6827
6828@kindex info dcache
6829@item info dcache
6830Print the information about the data cache performance. The
6831information displayed includes: the dcache width and depth; and for
6832each cache line, how many times it was referenced, and its data and
6833state (dirty, bad, ok, etc.). This command is useful for debugging
6834the data cache operation.
6835@end table
6836
a0eb71c5 6837
e2e0bcd1
JB
6838@node Macros
6839@chapter C Preprocessor Macros
6840
49efadf5 6841Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
6842``preprocessor macros'' which expand into strings of tokens.
6843@value{GDBN} can evaluate expressions containing macro invocations, show
6844the result of macro expansion, and show a macro's definition, including
6845where it was defined.
6846
6847You may need to compile your program specially to provide @value{GDBN}
6848with information about preprocessor macros. Most compilers do not
6849include macros in their debugging information, even when you compile
6850with the @option{-g} flag. @xref{Compilation}.
6851
6852A program may define a macro at one point, remove that definition later,
6853and then provide a different definition after that. Thus, at different
6854points in the program, a macro may have different definitions, or have
6855no definition at all. If there is a current stack frame, @value{GDBN}
6856uses the macros in scope at that frame's source code line. Otherwise,
6857@value{GDBN} uses the macros in scope at the current listing location;
6858see @ref{List}.
6859
6860At the moment, @value{GDBN} does not support the @code{##}
6861token-splicing operator, the @code{#} stringification operator, or
6862variable-arity macros.
6863
6864Whenever @value{GDBN} evaluates an expression, it always expands any
6865macro invocations present in the expression. @value{GDBN} also provides
6866the following commands for working with macros explicitly.
6867
6868@table @code
6869
6870@kindex macro expand
6871@cindex macro expansion, showing the results of preprocessor
6872@cindex preprocessor macro expansion, showing the results of
6873@cindex expanding preprocessor macros
6874@item macro expand @var{expression}
6875@itemx macro exp @var{expression}
6876Show the results of expanding all preprocessor macro invocations in
6877@var{expression}. Since @value{GDBN} simply expands macros, but does
6878not parse the result, @var{expression} need not be a valid expression;
6879it can be any string of tokens.
6880
09d4efe1 6881@kindex macro exp1
e2e0bcd1
JB
6882@item macro expand-once @var{expression}
6883@itemx macro exp1 @var{expression}
4644b6e3 6884@cindex expand macro once
e2e0bcd1
JB
6885@i{(This command is not yet implemented.)} Show the results of
6886expanding those preprocessor macro invocations that appear explicitly in
6887@var{expression}. Macro invocations appearing in that expansion are
6888left unchanged. This command allows you to see the effect of a
6889particular macro more clearly, without being confused by further
6890expansions. Since @value{GDBN} simply expands macros, but does not
6891parse the result, @var{expression} need not be a valid expression; it
6892can be any string of tokens.
6893
475b0867 6894@kindex info macro
e2e0bcd1
JB
6895@cindex macro definition, showing
6896@cindex definition, showing a macro's
475b0867 6897@item info macro @var{macro}
e2e0bcd1
JB
6898Show the definition of the macro named @var{macro}, and describe the
6899source location where that definition was established.
6900
6901@kindex macro define
6902@cindex user-defined macros
6903@cindex defining macros interactively
6904@cindex macros, user-defined
6905@item macro define @var{macro} @var{replacement-list}
6906@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6907@i{(This command is not yet implemented.)} Introduce a definition for a
6908preprocessor macro named @var{macro}, invocations of which are replaced
6909by the tokens given in @var{replacement-list}. The first form of this
6910command defines an ``object-like'' macro, which takes no arguments; the
6911second form defines a ``function-like'' macro, which takes the arguments
6912given in @var{arglist}.
6913
6914A definition introduced by this command is in scope in every expression
6915evaluated in @value{GDBN}, until it is removed with the @command{macro
6916undef} command, described below. The definition overrides all
6917definitions for @var{macro} present in the program being debugged, as
6918well as any previous user-supplied definition.
6919
6920@kindex macro undef
6921@item macro undef @var{macro}
6922@i{(This command is not yet implemented.)} Remove any user-supplied
6923definition for the macro named @var{macro}. This command only affects
6924definitions provided with the @command{macro define} command, described
6925above; it cannot remove definitions present in the program being
6926debugged.
6927
09d4efe1
EZ
6928@kindex macro list
6929@item macro list
6930@i{(This command is not yet implemented.)} List all the macros
6931defined using the @code{macro define} command.
e2e0bcd1
JB
6932@end table
6933
6934@cindex macros, example of debugging with
6935Here is a transcript showing the above commands in action. First, we
6936show our source files:
6937
6938@smallexample
6939$ cat sample.c
6940#include <stdio.h>
6941#include "sample.h"
6942
6943#define M 42
6944#define ADD(x) (M + x)
6945
6946main ()
6947@{
6948#define N 28
6949 printf ("Hello, world!\n");
6950#undef N
6951 printf ("We're so creative.\n");
6952#define N 1729
6953 printf ("Goodbye, world!\n");
6954@}
6955$ cat sample.h
6956#define Q <
6957$
6958@end smallexample
6959
6960Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6961We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6962compiler includes information about preprocessor macros in the debugging
6963information.
6964
6965@smallexample
6966$ gcc -gdwarf-2 -g3 sample.c -o sample
6967$
6968@end smallexample
6969
6970Now, we start @value{GDBN} on our sample program:
6971
6972@smallexample
6973$ gdb -nw sample
6974GNU gdb 2002-05-06-cvs
6975Copyright 2002 Free Software Foundation, Inc.
6976GDB is free software, @dots{}
f7dc1244 6977(@value{GDBP})
e2e0bcd1
JB
6978@end smallexample
6979
6980We can expand macros and examine their definitions, even when the
6981program is not running. @value{GDBN} uses the current listing position
6982to decide which macro definitions are in scope:
6983
6984@smallexample
f7dc1244 6985(@value{GDBP}) list main
e2e0bcd1
JB
69863
69874 #define M 42
69885 #define ADD(x) (M + x)
69896
69907 main ()
69918 @{
69929 #define N 28
699310 printf ("Hello, world!\n");
699411 #undef N
699512 printf ("We're so creative.\n");
f7dc1244 6996(@value{GDBP}) info macro ADD
e2e0bcd1
JB
6997Defined at /home/jimb/gdb/macros/play/sample.c:5
6998#define ADD(x) (M + x)
f7dc1244 6999(@value{GDBP}) info macro Q
e2e0bcd1
JB
7000Defined at /home/jimb/gdb/macros/play/sample.h:1
7001 included at /home/jimb/gdb/macros/play/sample.c:2
7002#define Q <
f7dc1244 7003(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 7004expands to: (42 + 1)
f7dc1244 7005(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 7006expands to: once (M + 1)
f7dc1244 7007(@value{GDBP})
e2e0bcd1
JB
7008@end smallexample
7009
7010In the example above, note that @command{macro expand-once} expands only
7011the macro invocation explicit in the original text --- the invocation of
7012@code{ADD} --- but does not expand the invocation of the macro @code{M},
7013which was introduced by @code{ADD}.
7014
7015Once the program is running, GDB uses the macro definitions in force at
7016the source line of the current stack frame:
7017
7018@smallexample
f7dc1244 7019(@value{GDBP}) break main
e2e0bcd1 7020Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 7021(@value{GDBP}) run
b383017d 7022Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
7023
7024Breakpoint 1, main () at sample.c:10
702510 printf ("Hello, world!\n");
f7dc1244 7026(@value{GDBP})
e2e0bcd1
JB
7027@end smallexample
7028
7029At line 10, the definition of the macro @code{N} at line 9 is in force:
7030
7031@smallexample
f7dc1244 7032(@value{GDBP}) info macro N
e2e0bcd1
JB
7033Defined at /home/jimb/gdb/macros/play/sample.c:9
7034#define N 28
f7dc1244 7035(@value{GDBP}) macro expand N Q M
e2e0bcd1 7036expands to: 28 < 42
f7dc1244 7037(@value{GDBP}) print N Q M
e2e0bcd1 7038$1 = 1
f7dc1244 7039(@value{GDBP})
e2e0bcd1
JB
7040@end smallexample
7041
7042As we step over directives that remove @code{N}'s definition, and then
7043give it a new definition, @value{GDBN} finds the definition (or lack
7044thereof) in force at each point:
7045
7046@smallexample
f7dc1244 7047(@value{GDBP}) next
e2e0bcd1
JB
7048Hello, world!
704912 printf ("We're so creative.\n");
f7dc1244 7050(@value{GDBP}) info macro N
e2e0bcd1
JB
7051The symbol `N' has no definition as a C/C++ preprocessor macro
7052at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 7053(@value{GDBP}) next
e2e0bcd1
JB
7054We're so creative.
705514 printf ("Goodbye, world!\n");
f7dc1244 7056(@value{GDBP}) info macro N
e2e0bcd1
JB
7057Defined at /home/jimb/gdb/macros/play/sample.c:13
7058#define N 1729
f7dc1244 7059(@value{GDBP}) macro expand N Q M
e2e0bcd1 7060expands to: 1729 < 42
f7dc1244 7061(@value{GDBP}) print N Q M
e2e0bcd1 7062$2 = 0
f7dc1244 7063(@value{GDBP})
e2e0bcd1
JB
7064@end smallexample
7065
7066
b37052ae
EZ
7067@node Tracepoints
7068@chapter Tracepoints
7069@c This chapter is based on the documentation written by Michael
7070@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
7071
7072@cindex tracepoints
7073In some applications, it is not feasible for the debugger to interrupt
7074the program's execution long enough for the developer to learn
7075anything helpful about its behavior. If the program's correctness
7076depends on its real-time behavior, delays introduced by a debugger
7077might cause the program to change its behavior drastically, or perhaps
7078fail, even when the code itself is correct. It is useful to be able
7079to observe the program's behavior without interrupting it.
7080
7081Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
7082specify locations in the program, called @dfn{tracepoints}, and
7083arbitrary expressions to evaluate when those tracepoints are reached.
7084Later, using the @code{tfind} command, you can examine the values
7085those expressions had when the program hit the tracepoints. The
7086expressions may also denote objects in memory---structures or arrays,
7087for example---whose values @value{GDBN} should record; while visiting
7088a particular tracepoint, you may inspect those objects as if they were
7089in memory at that moment. However, because @value{GDBN} records these
7090values without interacting with you, it can do so quickly and
7091unobtrusively, hopefully not disturbing the program's behavior.
7092
7093The tracepoint facility is currently available only for remote
2c0069bb
EZ
7094targets. @xref{Targets}. In addition, your remote target must know how
7095to collect trace data. This functionality is implemented in the remote
7096stub; however, none of the stubs distributed with @value{GDBN} support
7097tracepoints as of this writing.
b37052ae
EZ
7098
7099This chapter describes the tracepoint commands and features.
7100
7101@menu
b383017d
RM
7102* Set Tracepoints::
7103* Analyze Collected Data::
7104* Tracepoint Variables::
b37052ae
EZ
7105@end menu
7106
7107@node Set Tracepoints
7108@section Commands to Set Tracepoints
7109
7110Before running such a @dfn{trace experiment}, an arbitrary number of
7111tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
7112tracepoint has a number assigned to it by @value{GDBN}. Like with
7113breakpoints, tracepoint numbers are successive integers starting from
7114one. Many of the commands associated with tracepoints take the
7115tracepoint number as their argument, to identify which tracepoint to
7116work on.
7117
7118For each tracepoint, you can specify, in advance, some arbitrary set
7119of data that you want the target to collect in the trace buffer when
7120it hits that tracepoint. The collected data can include registers,
7121local variables, or global data. Later, you can use @value{GDBN}
7122commands to examine the values these data had at the time the
7123tracepoint was hit.
7124
7125This section describes commands to set tracepoints and associated
7126conditions and actions.
7127
7128@menu
b383017d
RM
7129* Create and Delete Tracepoints::
7130* Enable and Disable Tracepoints::
7131* Tracepoint Passcounts::
7132* Tracepoint Actions::
7133* Listing Tracepoints::
7134* Starting and Stopping Trace Experiment::
b37052ae
EZ
7135@end menu
7136
7137@node Create and Delete Tracepoints
7138@subsection Create and Delete Tracepoints
7139
7140@table @code
7141@cindex set tracepoint
7142@kindex trace
7143@item trace
7144The @code{trace} command is very similar to the @code{break} command.
7145Its argument can be a source line, a function name, or an address in
7146the target program. @xref{Set Breaks}. The @code{trace} command
7147defines a tracepoint, which is a point in the target program where the
7148debugger will briefly stop, collect some data, and then allow the
7149program to continue. Setting a tracepoint or changing its commands
7150doesn't take effect until the next @code{tstart} command; thus, you
7151cannot change the tracepoint attributes once a trace experiment is
7152running.
7153
7154Here are some examples of using the @code{trace} command:
7155
7156@smallexample
7157(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
7158
7159(@value{GDBP}) @b{trace +2} // 2 lines forward
7160
7161(@value{GDBP}) @b{trace my_function} // first source line of function
7162
7163(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
7164
7165(@value{GDBP}) @b{trace *0x2117c4} // an address
7166@end smallexample
7167
7168@noindent
7169You can abbreviate @code{trace} as @code{tr}.
7170
7171@vindex $tpnum
7172@cindex last tracepoint number
7173@cindex recent tracepoint number
7174@cindex tracepoint number
7175The convenience variable @code{$tpnum} records the tracepoint number
7176of the most recently set tracepoint.
7177
7178@kindex delete tracepoint
7179@cindex tracepoint deletion
7180@item delete tracepoint @r{[}@var{num}@r{]}
7181Permanently delete one or more tracepoints. With no argument, the
7182default is to delete all tracepoints.
7183
7184Examples:
7185
7186@smallexample
7187(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7188
7189(@value{GDBP}) @b{delete trace} // remove all tracepoints
7190@end smallexample
7191
7192@noindent
7193You can abbreviate this command as @code{del tr}.
7194@end table
7195
7196@node Enable and Disable Tracepoints
7197@subsection Enable and Disable Tracepoints
7198
7199@table @code
7200@kindex disable tracepoint
7201@item disable tracepoint @r{[}@var{num}@r{]}
7202Disable tracepoint @var{num}, or all tracepoints if no argument
7203@var{num} is given. A disabled tracepoint will have no effect during
7204the next trace experiment, but it is not forgotten. You can re-enable
7205a disabled tracepoint using the @code{enable tracepoint} command.
7206
7207@kindex enable tracepoint
7208@item enable tracepoint @r{[}@var{num}@r{]}
7209Enable tracepoint @var{num}, or all tracepoints. The enabled
7210tracepoints will become effective the next time a trace experiment is
7211run.
7212@end table
7213
7214@node Tracepoint Passcounts
7215@subsection Tracepoint Passcounts
7216
7217@table @code
7218@kindex passcount
7219@cindex tracepoint pass count
7220@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7221Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7222automatically stop a trace experiment. If a tracepoint's passcount is
7223@var{n}, then the trace experiment will be automatically stopped on
7224the @var{n}'th time that tracepoint is hit. If the tracepoint number
7225@var{num} is not specified, the @code{passcount} command sets the
7226passcount of the most recently defined tracepoint. If no passcount is
7227given, the trace experiment will run until stopped explicitly by the
7228user.
7229
7230Examples:
7231
7232@smallexample
b383017d 7233(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 7234@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
7235
7236(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 7237@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
7238(@value{GDBP}) @b{trace foo}
7239(@value{GDBP}) @b{pass 3}
7240(@value{GDBP}) @b{trace bar}
7241(@value{GDBP}) @b{pass 2}
7242(@value{GDBP}) @b{trace baz}
7243(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
7244@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7245@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7246@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
7247@end smallexample
7248@end table
7249
7250@node Tracepoint Actions
7251@subsection Tracepoint Action Lists
7252
7253@table @code
7254@kindex actions
7255@cindex tracepoint actions
7256@item actions @r{[}@var{num}@r{]}
7257This command will prompt for a list of actions to be taken when the
7258tracepoint is hit. If the tracepoint number @var{num} is not
7259specified, this command sets the actions for the one that was most
7260recently defined (so that you can define a tracepoint and then say
7261@code{actions} without bothering about its number). You specify the
7262actions themselves on the following lines, one action at a time, and
7263terminate the actions list with a line containing just @code{end}. So
7264far, the only defined actions are @code{collect} and
7265@code{while-stepping}.
7266
7267@cindex remove actions from a tracepoint
7268To remove all actions from a tracepoint, type @samp{actions @var{num}}
7269and follow it immediately with @samp{end}.
7270
7271@smallexample
7272(@value{GDBP}) @b{collect @var{data}} // collect some data
7273
6826cf00 7274(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 7275
6826cf00 7276(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
7277@end smallexample
7278
7279In the following example, the action list begins with @code{collect}
7280commands indicating the things to be collected when the tracepoint is
7281hit. Then, in order to single-step and collect additional data
7282following the tracepoint, a @code{while-stepping} command is used,
7283followed by the list of things to be collected while stepping. The
7284@code{while-stepping} command is terminated by its own separate
7285@code{end} command. Lastly, the action list is terminated by an
7286@code{end} command.
7287
7288@smallexample
7289(@value{GDBP}) @b{trace foo}
7290(@value{GDBP}) @b{actions}
7291Enter actions for tracepoint 1, one per line:
7292> collect bar,baz
7293> collect $regs
7294> while-stepping 12
7295 > collect $fp, $sp
7296 > end
7297end
7298@end smallexample
7299
7300@kindex collect @r{(tracepoints)}
7301@item collect @var{expr1}, @var{expr2}, @dots{}
7302Collect values of the given expressions when the tracepoint is hit.
7303This command accepts a comma-separated list of any valid expressions.
7304In addition to global, static, or local variables, the following
7305special arguments are supported:
7306
7307@table @code
7308@item $regs
7309collect all registers
7310
7311@item $args
7312collect all function arguments
7313
7314@item $locals
7315collect all local variables.
7316@end table
7317
7318You can give several consecutive @code{collect} commands, each one
7319with a single argument, or one @code{collect} command with several
7320arguments separated by commas: the effect is the same.
7321
f5c37c66
EZ
7322The command @code{info scope} (@pxref{Symbols, info scope}) is
7323particularly useful for figuring out what data to collect.
7324
b37052ae
EZ
7325@kindex while-stepping @r{(tracepoints)}
7326@item while-stepping @var{n}
7327Perform @var{n} single-step traces after the tracepoint, collecting
7328new data at each step. The @code{while-stepping} command is
7329followed by the list of what to collect while stepping (followed by
7330its own @code{end} command):
7331
7332@smallexample
7333> while-stepping 12
7334 > collect $regs, myglobal
7335 > end
7336>
7337@end smallexample
7338
7339@noindent
7340You may abbreviate @code{while-stepping} as @code{ws} or
7341@code{stepping}.
7342@end table
7343
7344@node Listing Tracepoints
7345@subsection Listing Tracepoints
7346
7347@table @code
7348@kindex info tracepoints
09d4efe1 7349@kindex info tp
b37052ae
EZ
7350@cindex information about tracepoints
7351@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 7352Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 7353a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
7354defined so far. For each tracepoint, the following information is
7355shown:
7356
7357@itemize @bullet
7358@item
7359its number
7360@item
7361whether it is enabled or disabled
7362@item
7363its address
7364@item
7365its passcount as given by the @code{passcount @var{n}} command
7366@item
7367its step count as given by the @code{while-stepping @var{n}} command
7368@item
7369where in the source files is the tracepoint set
7370@item
7371its action list as given by the @code{actions} command
7372@end itemize
7373
7374@smallexample
7375(@value{GDBP}) @b{info trace}
7376Num Enb Address PassC StepC What
73771 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
73782 y 0x0020dc64 0 0 in g_test at g_test.c:1375
73793 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
7380(@value{GDBP})
7381@end smallexample
7382
7383@noindent
7384This command can be abbreviated @code{info tp}.
7385@end table
7386
7387@node Starting and Stopping Trace Experiment
7388@subsection Starting and Stopping Trace Experiment
7389
7390@table @code
7391@kindex tstart
7392@cindex start a new trace experiment
7393@cindex collected data discarded
7394@item tstart
7395This command takes no arguments. It starts the trace experiment, and
7396begins collecting data. This has the side effect of discarding all
7397the data collected in the trace buffer during the previous trace
7398experiment.
7399
7400@kindex tstop
7401@cindex stop a running trace experiment
7402@item tstop
7403This command takes no arguments. It ends the trace experiment, and
7404stops collecting data.
7405
68c71a2e 7406@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
7407automatically if any tracepoint's passcount is reached
7408(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7409
7410@kindex tstatus
7411@cindex status of trace data collection
7412@cindex trace experiment, status of
7413@item tstatus
7414This command displays the status of the current trace data
7415collection.
7416@end table
7417
7418Here is an example of the commands we described so far:
7419
7420@smallexample
7421(@value{GDBP}) @b{trace gdb_c_test}
7422(@value{GDBP}) @b{actions}
7423Enter actions for tracepoint #1, one per line.
7424> collect $regs,$locals,$args
7425> while-stepping 11
7426 > collect $regs
7427 > end
7428> end
7429(@value{GDBP}) @b{tstart}
7430 [time passes @dots{}]
7431(@value{GDBP}) @b{tstop}
7432@end smallexample
7433
7434
7435@node Analyze Collected Data
7436@section Using the collected data
7437
7438After the tracepoint experiment ends, you use @value{GDBN} commands
7439for examining the trace data. The basic idea is that each tracepoint
7440collects a trace @dfn{snapshot} every time it is hit and another
7441snapshot every time it single-steps. All these snapshots are
7442consecutively numbered from zero and go into a buffer, and you can
7443examine them later. The way you examine them is to @dfn{focus} on a
7444specific trace snapshot. When the remote stub is focused on a trace
7445snapshot, it will respond to all @value{GDBN} requests for memory and
7446registers by reading from the buffer which belongs to that snapshot,
7447rather than from @emph{real} memory or registers of the program being
7448debugged. This means that @strong{all} @value{GDBN} commands
7449(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7450behave as if we were currently debugging the program state as it was
7451when the tracepoint occurred. Any requests for data that are not in
7452the buffer will fail.
7453
7454@menu
7455* tfind:: How to select a trace snapshot
7456* tdump:: How to display all data for a snapshot
7457* save-tracepoints:: How to save tracepoints for a future run
7458@end menu
7459
7460@node tfind
7461@subsection @code{tfind @var{n}}
7462
7463@kindex tfind
7464@cindex select trace snapshot
7465@cindex find trace snapshot
7466The basic command for selecting a trace snapshot from the buffer is
7467@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7468counting from zero. If no argument @var{n} is given, the next
7469snapshot is selected.
7470
7471Here are the various forms of using the @code{tfind} command.
7472
7473@table @code
7474@item tfind start
7475Find the first snapshot in the buffer. This is a synonym for
7476@code{tfind 0} (since 0 is the number of the first snapshot).
7477
7478@item tfind none
7479Stop debugging trace snapshots, resume @emph{live} debugging.
7480
7481@item tfind end
7482Same as @samp{tfind none}.
7483
7484@item tfind
7485No argument means find the next trace snapshot.
7486
7487@item tfind -
7488Find the previous trace snapshot before the current one. This permits
7489retracing earlier steps.
7490
7491@item tfind tracepoint @var{num}
7492Find the next snapshot associated with tracepoint @var{num}. Search
7493proceeds forward from the last examined trace snapshot. If no
7494argument @var{num} is given, it means find the next snapshot collected
7495for the same tracepoint as the current snapshot.
7496
7497@item tfind pc @var{addr}
7498Find the next snapshot associated with the value @var{addr} of the
7499program counter. Search proceeds forward from the last examined trace
7500snapshot. If no argument @var{addr} is given, it means find the next
7501snapshot with the same value of PC as the current snapshot.
7502
7503@item tfind outside @var{addr1}, @var{addr2}
7504Find the next snapshot whose PC is outside the given range of
7505addresses.
7506
7507@item tfind range @var{addr1}, @var{addr2}
7508Find the next snapshot whose PC is between @var{addr1} and
7509@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7510
7511@item tfind line @r{[}@var{file}:@r{]}@var{n}
7512Find the next snapshot associated with the source line @var{n}. If
7513the optional argument @var{file} is given, refer to line @var{n} in
7514that source file. Search proceeds forward from the last examined
7515trace snapshot. If no argument @var{n} is given, it means find the
7516next line other than the one currently being examined; thus saying
7517@code{tfind line} repeatedly can appear to have the same effect as
7518stepping from line to line in a @emph{live} debugging session.
7519@end table
7520
7521The default arguments for the @code{tfind} commands are specifically
7522designed to make it easy to scan through the trace buffer. For
7523instance, @code{tfind} with no argument selects the next trace
7524snapshot, and @code{tfind -} with no argument selects the previous
7525trace snapshot. So, by giving one @code{tfind} command, and then
7526simply hitting @key{RET} repeatedly you can examine all the trace
7527snapshots in order. Or, by saying @code{tfind -} and then hitting
7528@key{RET} repeatedly you can examine the snapshots in reverse order.
7529The @code{tfind line} command with no argument selects the snapshot
7530for the next source line executed. The @code{tfind pc} command with
7531no argument selects the next snapshot with the same program counter
7532(PC) as the current frame. The @code{tfind tracepoint} command with
7533no argument selects the next trace snapshot collected by the same
7534tracepoint as the current one.
7535
7536In addition to letting you scan through the trace buffer manually,
7537these commands make it easy to construct @value{GDBN} scripts that
7538scan through the trace buffer and print out whatever collected data
7539you are interested in. Thus, if we want to examine the PC, FP, and SP
7540registers from each trace frame in the buffer, we can say this:
7541
7542@smallexample
7543(@value{GDBP}) @b{tfind start}
7544(@value{GDBP}) @b{while ($trace_frame != -1)}
7545> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7546 $trace_frame, $pc, $sp, $fp
7547> tfind
7548> end
7549
7550Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7551Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7552Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7553Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7554Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7555Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7556Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7557Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7558Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7559Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7560Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7561@end smallexample
7562
7563Or, if we want to examine the variable @code{X} at each source line in
7564the buffer:
7565
7566@smallexample
7567(@value{GDBP}) @b{tfind start}
7568(@value{GDBP}) @b{while ($trace_frame != -1)}
7569> printf "Frame %d, X == %d\n", $trace_frame, X
7570> tfind line
7571> end
7572
7573Frame 0, X = 1
7574Frame 7, X = 2
7575Frame 13, X = 255
7576@end smallexample
7577
7578@node tdump
7579@subsection @code{tdump}
7580@kindex tdump
7581@cindex dump all data collected at tracepoint
7582@cindex tracepoint data, display
7583
7584This command takes no arguments. It prints all the data collected at
7585the current trace snapshot.
7586
7587@smallexample
7588(@value{GDBP}) @b{trace 444}
7589(@value{GDBP}) @b{actions}
7590Enter actions for tracepoint #2, one per line:
7591> collect $regs, $locals, $args, gdb_long_test
7592> end
7593
7594(@value{GDBP}) @b{tstart}
7595
7596(@value{GDBP}) @b{tfind line 444}
7597#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7598at gdb_test.c:444
7599444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7600
7601(@value{GDBP}) @b{tdump}
7602Data collected at tracepoint 2, trace frame 1:
7603d0 0xc4aa0085 -995491707
7604d1 0x18 24
7605d2 0x80 128
7606d3 0x33 51
7607d4 0x71aea3d 119204413
7608d5 0x22 34
7609d6 0xe0 224
7610d7 0x380035 3670069
7611a0 0x19e24a 1696330
7612a1 0x3000668 50333288
7613a2 0x100 256
7614a3 0x322000 3284992
7615a4 0x3000698 50333336
7616a5 0x1ad3cc 1758156
7617fp 0x30bf3c 0x30bf3c
7618sp 0x30bf34 0x30bf34
7619ps 0x0 0
7620pc 0x20b2c8 0x20b2c8
7621fpcontrol 0x0 0
7622fpstatus 0x0 0
7623fpiaddr 0x0 0
7624p = 0x20e5b4 "gdb-test"
7625p1 = (void *) 0x11
7626p2 = (void *) 0x22
7627p3 = (void *) 0x33
7628p4 = (void *) 0x44
7629p5 = (void *) 0x55
7630p6 = (void *) 0x66
7631gdb_long_test = 17 '\021'
7632
7633(@value{GDBP})
7634@end smallexample
7635
7636@node save-tracepoints
7637@subsection @code{save-tracepoints @var{filename}}
7638@kindex save-tracepoints
7639@cindex save tracepoints for future sessions
7640
7641This command saves all current tracepoint definitions together with
7642their actions and passcounts, into a file @file{@var{filename}}
7643suitable for use in a later debugging session. To read the saved
7644tracepoint definitions, use the @code{source} command (@pxref{Command
7645Files}).
7646
7647@node Tracepoint Variables
7648@section Convenience Variables for Tracepoints
7649@cindex tracepoint variables
7650@cindex convenience variables for tracepoints
7651
7652@table @code
7653@vindex $trace_frame
7654@item (int) $trace_frame
7655The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7656snapshot is selected.
7657
7658@vindex $tracepoint
7659@item (int) $tracepoint
7660The tracepoint for the current trace snapshot.
7661
7662@vindex $trace_line
7663@item (int) $trace_line
7664The line number for the current trace snapshot.
7665
7666@vindex $trace_file
7667@item (char []) $trace_file
7668The source file for the current trace snapshot.
7669
7670@vindex $trace_func
7671@item (char []) $trace_func
7672The name of the function containing @code{$tracepoint}.
7673@end table
7674
7675Note: @code{$trace_file} is not suitable for use in @code{printf},
7676use @code{output} instead.
7677
7678Here's a simple example of using these convenience variables for
7679stepping through all the trace snapshots and printing some of their
7680data.
7681
7682@smallexample
7683(@value{GDBP}) @b{tfind start}
7684
7685(@value{GDBP}) @b{while $trace_frame != -1}
7686> output $trace_file
7687> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7688> tfind
7689> end
7690@end smallexample
7691
df0cd8c5
JB
7692@node Overlays
7693@chapter Debugging Programs That Use Overlays
7694@cindex overlays
7695
7696If your program is too large to fit completely in your target system's
7697memory, you can sometimes use @dfn{overlays} to work around this
7698problem. @value{GDBN} provides some support for debugging programs that
7699use overlays.
7700
7701@menu
7702* How Overlays Work:: A general explanation of overlays.
7703* Overlay Commands:: Managing overlays in @value{GDBN}.
7704* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7705 mapped by asking the inferior.
7706* Overlay Sample Program:: A sample program using overlays.
7707@end menu
7708
7709@node How Overlays Work
7710@section How Overlays Work
7711@cindex mapped overlays
7712@cindex unmapped overlays
7713@cindex load address, overlay's
7714@cindex mapped address
7715@cindex overlay area
7716
7717Suppose you have a computer whose instruction address space is only 64
7718kilobytes long, but which has much more memory which can be accessed by
7719other means: special instructions, segment registers, or memory
7720management hardware, for example. Suppose further that you want to
7721adapt a program which is larger than 64 kilobytes to run on this system.
7722
7723One solution is to identify modules of your program which are relatively
7724independent, and need not call each other directly; call these modules
7725@dfn{overlays}. Separate the overlays from the main program, and place
7726their machine code in the larger memory. Place your main program in
7727instruction memory, but leave at least enough space there to hold the
7728largest overlay as well.
7729
7730Now, to call a function located in an overlay, you must first copy that
7731overlay's machine code from the large memory into the space set aside
7732for it in the instruction memory, and then jump to its entry point
7733there.
7734
c928edc0
AC
7735@c NB: In the below the mapped area's size is greater or equal to the
7736@c size of all overlays. This is intentional to remind the developer
7737@c that overlays don't necessarily need to be the same size.
7738
474c8240 7739@smallexample
df0cd8c5 7740@group
c928edc0
AC
7741 Data Instruction Larger
7742Address Space Address Space Address Space
7743+-----------+ +-----------+ +-----------+
7744| | | | | |
7745+-----------+ +-----------+ +-----------+<-- overlay 1
7746| program | | main | .----| overlay 1 | load address
7747| variables | | program | | +-----------+
7748| and heap | | | | | |
7749+-----------+ | | | +-----------+<-- overlay 2
7750| | +-----------+ | | | load address
7751+-----------+ | | | .-| overlay 2 |
7752 | | | | | |
7753 mapped --->+-----------+ | | +-----------+
7754 address | | | | | |
7755 | overlay | <-' | | |
7756 | area | <---' +-----------+<-- overlay 3
7757 | | <---. | | load address
7758 +-----------+ `--| overlay 3 |
7759 | | | |
7760 +-----------+ | |
7761 +-----------+
7762 | |
7763 +-----------+
7764
7765 @anchor{A code overlay}A code overlay
df0cd8c5 7766@end group
474c8240 7767@end smallexample
df0cd8c5 7768
c928edc0
AC
7769The diagram (@pxref{A code overlay}) shows a system with separate data
7770and instruction address spaces. To map an overlay, the program copies
7771its code from the larger address space to the instruction address space.
7772Since the overlays shown here all use the same mapped address, only one
7773may be mapped at a time. For a system with a single address space for
7774data and instructions, the diagram would be similar, except that the
7775program variables and heap would share an address space with the main
7776program and the overlay area.
df0cd8c5
JB
7777
7778An overlay loaded into instruction memory and ready for use is called a
7779@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7780instruction memory. An overlay not present (or only partially present)
7781in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7782is its address in the larger memory. The mapped address is also called
7783the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7784called the @dfn{load memory address}, or @dfn{LMA}.
7785
7786Unfortunately, overlays are not a completely transparent way to adapt a
7787program to limited instruction memory. They introduce a new set of
7788global constraints you must keep in mind as you design your program:
7789
7790@itemize @bullet
7791
7792@item
7793Before calling or returning to a function in an overlay, your program
7794must make sure that overlay is actually mapped. Otherwise, the call or
7795return will transfer control to the right address, but in the wrong
7796overlay, and your program will probably crash.
7797
7798@item
7799If the process of mapping an overlay is expensive on your system, you
7800will need to choose your overlays carefully to minimize their effect on
7801your program's performance.
7802
7803@item
7804The executable file you load onto your system must contain each
7805overlay's instructions, appearing at the overlay's load address, not its
7806mapped address. However, each overlay's instructions must be relocated
7807and its symbols defined as if the overlay were at its mapped address.
7808You can use GNU linker scripts to specify different load and relocation
7809addresses for pieces of your program; see @ref{Overlay Description,,,
7810ld.info, Using ld: the GNU linker}.
7811
7812@item
7813The procedure for loading executable files onto your system must be able
7814to load their contents into the larger address space as well as the
7815instruction and data spaces.
7816
7817@end itemize
7818
7819The overlay system described above is rather simple, and could be
7820improved in many ways:
7821
7822@itemize @bullet
7823
7824@item
7825If your system has suitable bank switch registers or memory management
7826hardware, you could use those facilities to make an overlay's load area
7827contents simply appear at their mapped address in instruction space.
7828This would probably be faster than copying the overlay to its mapped
7829area in the usual way.
7830
7831@item
7832If your overlays are small enough, you could set aside more than one
7833overlay area, and have more than one overlay mapped at a time.
7834
7835@item
7836You can use overlays to manage data, as well as instructions. In
7837general, data overlays are even less transparent to your design than
7838code overlays: whereas code overlays only require care when you call or
7839return to functions, data overlays require care every time you access
7840the data. Also, if you change the contents of a data overlay, you
7841must copy its contents back out to its load address before you can copy a
7842different data overlay into the same mapped area.
7843
7844@end itemize
7845
7846
7847@node Overlay Commands
7848@section Overlay Commands
7849
7850To use @value{GDBN}'s overlay support, each overlay in your program must
7851correspond to a separate section of the executable file. The section's
7852virtual memory address and load memory address must be the overlay's
7853mapped and load addresses. Identifying overlays with sections allows
7854@value{GDBN} to determine the appropriate address of a function or
7855variable, depending on whether the overlay is mapped or not.
7856
7857@value{GDBN}'s overlay commands all start with the word @code{overlay};
7858you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7859
7860@table @code
7861@item overlay off
4644b6e3 7862@kindex overlay
df0cd8c5
JB
7863Disable @value{GDBN}'s overlay support. When overlay support is
7864disabled, @value{GDBN} assumes that all functions and variables are
7865always present at their mapped addresses. By default, @value{GDBN}'s
7866overlay support is disabled.
7867
7868@item overlay manual
df0cd8c5
JB
7869@cindex manual overlay debugging
7870Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7871relies on you to tell it which overlays are mapped, and which are not,
7872using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7873commands described below.
7874
7875@item overlay map-overlay @var{overlay}
7876@itemx overlay map @var{overlay}
df0cd8c5
JB
7877@cindex map an overlay
7878Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7879be the name of the object file section containing the overlay. When an
7880overlay is mapped, @value{GDBN} assumes it can find the overlay's
7881functions and variables at their mapped addresses. @value{GDBN} assumes
7882that any other overlays whose mapped ranges overlap that of
7883@var{overlay} are now unmapped.
7884
7885@item overlay unmap-overlay @var{overlay}
7886@itemx overlay unmap @var{overlay}
df0cd8c5
JB
7887@cindex unmap an overlay
7888Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7889must be the name of the object file section containing the overlay.
7890When an overlay is unmapped, @value{GDBN} assumes it can find the
7891overlay's functions and variables at their load addresses.
7892
7893@item overlay auto
df0cd8c5
JB
7894Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7895consults a data structure the overlay manager maintains in the inferior
7896to see which overlays are mapped. For details, see @ref{Automatic
7897Overlay Debugging}.
7898
7899@item overlay load-target
7900@itemx overlay load
df0cd8c5
JB
7901@cindex reloading the overlay table
7902Re-read the overlay table from the inferior. Normally, @value{GDBN}
7903re-reads the table @value{GDBN} automatically each time the inferior
7904stops, so this command should only be necessary if you have changed the
7905overlay mapping yourself using @value{GDBN}. This command is only
7906useful when using automatic overlay debugging.
7907
7908@item overlay list-overlays
7909@itemx overlay list
7910@cindex listing mapped overlays
7911Display a list of the overlays currently mapped, along with their mapped
7912addresses, load addresses, and sizes.
7913
7914@end table
7915
7916Normally, when @value{GDBN} prints a code address, it includes the name
7917of the function the address falls in:
7918
474c8240 7919@smallexample
f7dc1244 7920(@value{GDBP}) print main
df0cd8c5 7921$3 = @{int ()@} 0x11a0 <main>
474c8240 7922@end smallexample
df0cd8c5
JB
7923@noindent
7924When overlay debugging is enabled, @value{GDBN} recognizes code in
7925unmapped overlays, and prints the names of unmapped functions with
7926asterisks around them. For example, if @code{foo} is a function in an
7927unmapped overlay, @value{GDBN} prints it this way:
7928
474c8240 7929@smallexample
f7dc1244 7930(@value{GDBP}) overlay list
df0cd8c5 7931No sections are mapped.
f7dc1244 7932(@value{GDBP}) print foo
df0cd8c5 7933$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7934@end smallexample
df0cd8c5
JB
7935@noindent
7936When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7937name normally:
7938
474c8240 7939@smallexample
f7dc1244 7940(@value{GDBP}) overlay list
b383017d 7941Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 7942 mapped at 0x1016 - 0x104a
f7dc1244 7943(@value{GDBP}) print foo
df0cd8c5 7944$6 = @{int (int)@} 0x1016 <foo>
474c8240 7945@end smallexample
df0cd8c5
JB
7946
7947When overlay debugging is enabled, @value{GDBN} can find the correct
7948address for functions and variables in an overlay, whether or not the
7949overlay is mapped. This allows most @value{GDBN} commands, like
7950@code{break} and @code{disassemble}, to work normally, even on unmapped
7951code. However, @value{GDBN}'s breakpoint support has some limitations:
7952
7953@itemize @bullet
7954@item
7955@cindex breakpoints in overlays
7956@cindex overlays, setting breakpoints in
7957You can set breakpoints in functions in unmapped overlays, as long as
7958@value{GDBN} can write to the overlay at its load address.
7959@item
7960@value{GDBN} can not set hardware or simulator-based breakpoints in
7961unmapped overlays. However, if you set a breakpoint at the end of your
7962overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7963you are using manual overlay management), @value{GDBN} will re-set its
7964breakpoints properly.
7965@end itemize
7966
7967
7968@node Automatic Overlay Debugging
7969@section Automatic Overlay Debugging
7970@cindex automatic overlay debugging
7971
7972@value{GDBN} can automatically track which overlays are mapped and which
7973are not, given some simple co-operation from the overlay manager in the
7974inferior. If you enable automatic overlay debugging with the
7975@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7976looks in the inferior's memory for certain variables describing the
7977current state of the overlays.
7978
7979Here are the variables your overlay manager must define to support
7980@value{GDBN}'s automatic overlay debugging:
7981
7982@table @asis
7983
7984@item @code{_ovly_table}:
7985This variable must be an array of the following structures:
7986
474c8240 7987@smallexample
df0cd8c5
JB
7988struct
7989@{
7990 /* The overlay's mapped address. */
7991 unsigned long vma;
7992
7993 /* The size of the overlay, in bytes. */
7994 unsigned long size;
7995
7996 /* The overlay's load address. */
7997 unsigned long lma;
7998
7999 /* Non-zero if the overlay is currently mapped;
8000 zero otherwise. */
8001 unsigned long mapped;
8002@}
474c8240 8003@end smallexample
df0cd8c5
JB
8004
8005@item @code{_novlys}:
8006This variable must be a four-byte signed integer, holding the total
8007number of elements in @code{_ovly_table}.
8008
8009@end table
8010
8011To decide whether a particular overlay is mapped or not, @value{GDBN}
8012looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
8013@code{lma} members equal the VMA and LMA of the overlay's section in the
8014executable file. When @value{GDBN} finds a matching entry, it consults
8015the entry's @code{mapped} member to determine whether the overlay is
8016currently mapped.
8017
81d46470 8018In addition, your overlay manager may define a function called
def71bfa 8019@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
8020will silently set a breakpoint there. If the overlay manager then
8021calls this function whenever it has changed the overlay table, this
8022will enable @value{GDBN} to accurately keep track of which overlays
8023are in program memory, and update any breakpoints that may be set
b383017d 8024in overlays. This will allow breakpoints to work even if the
81d46470
MS
8025overlays are kept in ROM or other non-writable memory while they
8026are not being executed.
df0cd8c5
JB
8027
8028@node Overlay Sample Program
8029@section Overlay Sample Program
8030@cindex overlay example program
8031
8032When linking a program which uses overlays, you must place the overlays
8033at their load addresses, while relocating them to run at their mapped
8034addresses. To do this, you must write a linker script (@pxref{Overlay
8035Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
8036since linker scripts are specific to a particular host system, target
8037architecture, and target memory layout, this manual cannot provide
8038portable sample code demonstrating @value{GDBN}'s overlay support.
8039
8040However, the @value{GDBN} source distribution does contain an overlaid
8041program, with linker scripts for a few systems, as part of its test
8042suite. The program consists of the following files from
8043@file{gdb/testsuite/gdb.base}:
8044
8045@table @file
8046@item overlays.c
8047The main program file.
8048@item ovlymgr.c
8049A simple overlay manager, used by @file{overlays.c}.
8050@item foo.c
8051@itemx bar.c
8052@itemx baz.c
8053@itemx grbx.c
8054Overlay modules, loaded and used by @file{overlays.c}.
8055@item d10v.ld
8056@itemx m32r.ld
8057Linker scripts for linking the test program on the @code{d10v-elf}
8058and @code{m32r-elf} targets.
8059@end table
8060
8061You can build the test program using the @code{d10v-elf} GCC
8062cross-compiler like this:
8063
474c8240 8064@smallexample
df0cd8c5
JB
8065$ d10v-elf-gcc -g -c overlays.c
8066$ d10v-elf-gcc -g -c ovlymgr.c
8067$ d10v-elf-gcc -g -c foo.c
8068$ d10v-elf-gcc -g -c bar.c
8069$ d10v-elf-gcc -g -c baz.c
8070$ d10v-elf-gcc -g -c grbx.c
8071$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
8072 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 8073@end smallexample
df0cd8c5
JB
8074
8075The build process is identical for any other architecture, except that
8076you must substitute the appropriate compiler and linker script for the
8077target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
8078
8079
6d2ebf8b 8080@node Languages
c906108c
SS
8081@chapter Using @value{GDBN} with Different Languages
8082@cindex languages
8083
c906108c
SS
8084Although programming languages generally have common aspects, they are
8085rarely expressed in the same manner. For instance, in ANSI C,
8086dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
8087Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 8088represented (and displayed) differently. Hex numbers in C appear as
c906108c 8089@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
8090
8091@cindex working language
8092Language-specific information is built into @value{GDBN} for some languages,
8093allowing you to express operations like the above in your program's
8094native language, and allowing @value{GDBN} to output values in a manner
8095consistent with the syntax of your program's native language. The
8096language you use to build expressions is called the @dfn{working
8097language}.
8098
8099@menu
8100* Setting:: Switching between source languages
8101* Show:: Displaying the language
c906108c 8102* Checks:: Type and range checks
9c16f35a 8103* Supported languages:: Supported languages
4e562065 8104* Unsupported languages:: Unsupported languages
c906108c
SS
8105@end menu
8106
6d2ebf8b 8107@node Setting
c906108c
SS
8108@section Switching between source languages
8109
8110There are two ways to control the working language---either have @value{GDBN}
8111set it automatically, or select it manually yourself. You can use the
8112@code{set language} command for either purpose. On startup, @value{GDBN}
8113defaults to setting the language automatically. The working language is
8114used to determine how expressions you type are interpreted, how values
8115are printed, etc.
8116
8117In addition to the working language, every source file that
8118@value{GDBN} knows about has its own working language. For some object
8119file formats, the compiler might indicate which language a particular
8120source file is in. However, most of the time @value{GDBN} infers the
8121language from the name of the file. The language of a source file
b37052ae 8122controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 8123show each frame appropriately for its own language. There is no way to
d4f3574e
SS
8124set the language of a source file from within @value{GDBN}, but you can
8125set the language associated with a filename extension. @xref{Show, ,
8126Displaying the language}.
c906108c
SS
8127
8128This is most commonly a problem when you use a program, such
5d161b24 8129as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
8130another language. In that case, make the
8131program use @code{#line} directives in its C output; that way
8132@value{GDBN} will know the correct language of the source code of the original
8133program, and will display that source code, not the generated C code.
8134
8135@menu
8136* Filenames:: Filename extensions and languages.
8137* Manually:: Setting the working language manually
8138* Automatically:: Having @value{GDBN} infer the source language
8139@end menu
8140
6d2ebf8b 8141@node Filenames
c906108c
SS
8142@subsection List of filename extensions and languages
8143
8144If a source file name ends in one of the following extensions, then
8145@value{GDBN} infers that its language is the one indicated.
8146
8147@table @file
e07c999f
PH
8148@item .ada
8149@itemx .ads
8150@itemx .adb
8151@itemx .a
8152Ada source file.
c906108c
SS
8153
8154@item .c
8155C source file
8156
8157@item .C
8158@itemx .cc
8159@itemx .cp
8160@itemx .cpp
8161@itemx .cxx
8162@itemx .c++
b37052ae 8163C@t{++} source file
c906108c 8164
b37303ee
AF
8165@item .m
8166Objective-C source file
8167
c906108c
SS
8168@item .f
8169@itemx .F
8170Fortran source file
8171
c906108c
SS
8172@item .mod
8173Modula-2 source file
c906108c
SS
8174
8175@item .s
8176@itemx .S
8177Assembler source file. This actually behaves almost like C, but
8178@value{GDBN} does not skip over function prologues when stepping.
8179@end table
8180
8181In addition, you may set the language associated with a filename
8182extension. @xref{Show, , Displaying the language}.
8183
6d2ebf8b 8184@node Manually
c906108c
SS
8185@subsection Setting the working language
8186
8187If you allow @value{GDBN} to set the language automatically,
8188expressions are interpreted the same way in your debugging session and
8189your program.
8190
8191@kindex set language
8192If you wish, you may set the language manually. To do this, issue the
8193command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 8194a language, such as
c906108c 8195@code{c} or @code{modula-2}.
c906108c
SS
8196For a list of the supported languages, type @samp{set language}.
8197
c906108c
SS
8198Setting the language manually prevents @value{GDBN} from updating the working
8199language automatically. This can lead to confusion if you try
8200to debug a program when the working language is not the same as the
8201source language, when an expression is acceptable to both
8202languages---but means different things. For instance, if the current
8203source file were written in C, and @value{GDBN} was parsing Modula-2, a
8204command such as:
8205
474c8240 8206@smallexample
c906108c 8207print a = b + c
474c8240 8208@end smallexample
c906108c
SS
8209
8210@noindent
8211might not have the effect you intended. In C, this means to add
8212@code{b} and @code{c} and place the result in @code{a}. The result
8213printed would be the value of @code{a}. In Modula-2, this means to compare
8214@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 8215
6d2ebf8b 8216@node Automatically
c906108c
SS
8217@subsection Having @value{GDBN} infer the source language
8218
8219To have @value{GDBN} set the working language automatically, use
8220@samp{set language local} or @samp{set language auto}. @value{GDBN}
8221then infers the working language. That is, when your program stops in a
8222frame (usually by encountering a breakpoint), @value{GDBN} sets the
8223working language to the language recorded for the function in that
8224frame. If the language for a frame is unknown (that is, if the function
8225or block corresponding to the frame was defined in a source file that
8226does not have a recognized extension), the current working language is
8227not changed, and @value{GDBN} issues a warning.
8228
8229This may not seem necessary for most programs, which are written
8230entirely in one source language. However, program modules and libraries
8231written in one source language can be used by a main program written in
8232a different source language. Using @samp{set language auto} in this
8233case frees you from having to set the working language manually.
8234
6d2ebf8b 8235@node Show
c906108c 8236@section Displaying the language
c906108c
SS
8237
8238The following commands help you find out which language is the
8239working language, and also what language source files were written in.
8240
c906108c
SS
8241@table @code
8242@item show language
9c16f35a 8243@kindex show language
c906108c
SS
8244Display the current working language. This is the
8245language you can use with commands such as @code{print} to
8246build and compute expressions that may involve variables in your program.
8247
8248@item info frame
4644b6e3 8249@kindex info frame@r{, show the source language}
5d161b24 8250Display the source language for this frame. This language becomes the
c906108c 8251working language if you use an identifier from this frame.
5d161b24 8252@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
8253information listed here.
8254
8255@item info source
4644b6e3 8256@kindex info source@r{, show the source language}
c906108c 8257Display the source language of this source file.
5d161b24 8258@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
8259information listed here.
8260@end table
8261
8262In unusual circumstances, you may have source files with extensions
8263not in the standard list. You can then set the extension associated
8264with a language explicitly:
8265
c906108c 8266@table @code
09d4efe1 8267@item set extension-language @var{ext} @var{language}
9c16f35a 8268@kindex set extension-language
09d4efe1
EZ
8269Tell @value{GDBN} that source files with extension @var{ext} are to be
8270assumed as written in the source language @var{language}.
c906108c
SS
8271
8272@item info extensions
9c16f35a 8273@kindex info extensions
c906108c
SS
8274List all the filename extensions and the associated languages.
8275@end table
8276
6d2ebf8b 8277@node Checks
c906108c
SS
8278@section Type and range checking
8279
8280@quotation
8281@emph{Warning:} In this release, the @value{GDBN} commands for type and range
8282checking are included, but they do not yet have any effect. This
8283section documents the intended facilities.
8284@end quotation
8285@c FIXME remove warning when type/range code added
8286
8287Some languages are designed to guard you against making seemingly common
8288errors through a series of compile- and run-time checks. These include
8289checking the type of arguments to functions and operators, and making
8290sure mathematical overflows are caught at run time. Checks such as
8291these help to ensure a program's correctness once it has been compiled
8292by eliminating type mismatches, and providing active checks for range
8293errors when your program is running.
8294
8295@value{GDBN} can check for conditions like the above if you wish.
9c16f35a
EZ
8296Although @value{GDBN} does not check the statements in your program,
8297it can check expressions entered directly into @value{GDBN} for
8298evaluation via the @code{print} command, for example. As with the
8299working language, @value{GDBN} can also decide whether or not to check
8300automatically based on your program's source language.
8301@xref{Supported languages, ,Supported languages}, for the default
8302settings of supported languages.
c906108c
SS
8303
8304@menu
8305* Type Checking:: An overview of type checking
8306* Range Checking:: An overview of range checking
8307@end menu
8308
8309@cindex type checking
8310@cindex checks, type
6d2ebf8b 8311@node Type Checking
c906108c
SS
8312@subsection An overview of type checking
8313
8314Some languages, such as Modula-2, are strongly typed, meaning that the
8315arguments to operators and functions have to be of the correct type,
8316otherwise an error occurs. These checks prevent type mismatch
8317errors from ever causing any run-time problems. For example,
8318
8319@smallexample
83201 + 2 @result{} 3
8321@exdent but
8322@error{} 1 + 2.3
8323@end smallexample
8324
8325The second example fails because the @code{CARDINAL} 1 is not
8326type-compatible with the @code{REAL} 2.3.
8327
5d161b24
DB
8328For the expressions you use in @value{GDBN} commands, you can tell the
8329@value{GDBN} type checker to skip checking;
8330to treat any mismatches as errors and abandon the expression;
8331or to only issue warnings when type mismatches occur,
c906108c
SS
8332but evaluate the expression anyway. When you choose the last of
8333these, @value{GDBN} evaluates expressions like the second example above, but
8334also issues a warning.
8335
5d161b24
DB
8336Even if you turn type checking off, there may be other reasons
8337related to type that prevent @value{GDBN} from evaluating an expression.
8338For instance, @value{GDBN} does not know how to add an @code{int} and
8339a @code{struct foo}. These particular type errors have nothing to do
8340with the language in use, and usually arise from expressions, such as
c906108c
SS
8341the one described above, which make little sense to evaluate anyway.
8342
8343Each language defines to what degree it is strict about type. For
8344instance, both Modula-2 and C require the arguments to arithmetical
8345operators to be numbers. In C, enumerated types and pointers can be
8346represented as numbers, so that they are valid arguments to mathematical
9c16f35a 8347operators. @xref{Supported languages, ,Supported languages}, for further
c906108c
SS
8348details on specific languages.
8349
8350@value{GDBN} provides some additional commands for controlling the type checker:
8351
c906108c
SS
8352@kindex set check type
8353@kindex show check type
8354@table @code
8355@item set check type auto
8356Set type checking on or off based on the current working language.
9c16f35a 8357@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8358each language.
8359
8360@item set check type on
8361@itemx set check type off
8362Set type checking on or off, overriding the default setting for the
8363current working language. Issue a warning if the setting does not
8364match the language default. If any type mismatches occur in
d4f3574e 8365evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
8366message and aborts evaluation of the expression.
8367
8368@item set check type warn
8369Cause the type checker to issue warnings, but to always attempt to
8370evaluate the expression. Evaluating the expression may still
8371be impossible for other reasons. For example, @value{GDBN} cannot add
8372numbers and structures.
8373
8374@item show type
5d161b24 8375Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
8376is setting it automatically.
8377@end table
8378
8379@cindex range checking
8380@cindex checks, range
6d2ebf8b 8381@node Range Checking
c906108c
SS
8382@subsection An overview of range checking
8383
8384In some languages (such as Modula-2), it is an error to exceed the
8385bounds of a type; this is enforced with run-time checks. Such range
8386checking is meant to ensure program correctness by making sure
8387computations do not overflow, or indices on an array element access do
8388not exceed the bounds of the array.
8389
8390For expressions you use in @value{GDBN} commands, you can tell
8391@value{GDBN} to treat range errors in one of three ways: ignore them,
8392always treat them as errors and abandon the expression, or issue
8393warnings but evaluate the expression anyway.
8394
8395A range error can result from numerical overflow, from exceeding an
8396array index bound, or when you type a constant that is not a member
8397of any type. Some languages, however, do not treat overflows as an
8398error. In many implementations of C, mathematical overflow causes the
8399result to ``wrap around'' to lower values---for example, if @var{m} is
8400the largest integer value, and @var{s} is the smallest, then
8401
474c8240 8402@smallexample
c906108c 8403@var{m} + 1 @result{} @var{s}
474c8240 8404@end smallexample
c906108c
SS
8405
8406This, too, is specific to individual languages, and in some cases
9c16f35a 8407specific to individual compilers or machines. @xref{Supported languages, ,
c906108c
SS
8408Supported languages}, for further details on specific languages.
8409
8410@value{GDBN} provides some additional commands for controlling the range checker:
8411
c906108c
SS
8412@kindex set check range
8413@kindex show check range
8414@table @code
8415@item set check range auto
8416Set range checking on or off based on the current working language.
9c16f35a 8417@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8418each language.
8419
8420@item set check range on
8421@itemx set check range off
8422Set range checking on or off, overriding the default setting for the
8423current working language. A warning is issued if the setting does not
c3f6f71d
JM
8424match the language default. If a range error occurs and range checking is on,
8425then a message is printed and evaluation of the expression is aborted.
c906108c
SS
8426
8427@item set check range warn
8428Output messages when the @value{GDBN} range checker detects a range error,
8429but attempt to evaluate the expression anyway. Evaluating the
8430expression may still be impossible for other reasons, such as accessing
8431memory that the process does not own (a typical example from many Unix
8432systems).
8433
8434@item show range
8435Show the current setting of the range checker, and whether or not it is
8436being set automatically by @value{GDBN}.
8437@end table
c906108c 8438
9c16f35a 8439@node Supported languages
c906108c 8440@section Supported languages
c906108c 8441
9c16f35a
EZ
8442@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
8443assembly, Modula-2, and Ada.
cce74817 8444@c This is false ...
c906108c
SS
8445Some @value{GDBN} features may be used in expressions regardless of the
8446language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8447and the @samp{@{type@}addr} construct (@pxref{Expressions,
8448,Expressions}) can be used with the constructs of any supported
8449language.
8450
8451The following sections detail to what degree each source language is
8452supported by @value{GDBN}. These sections are not meant to be language
8453tutorials or references, but serve only as a reference guide to what the
8454@value{GDBN} expression parser accepts, and what input and output
8455formats should look like for different languages. There are many good
8456books written on each of these languages; please look to these for a
8457language reference or tutorial.
8458
c906108c 8459@menu
b37303ee 8460* C:: C and C@t{++}
b383017d 8461* Objective-C:: Objective-C
09d4efe1 8462* Fortran:: Fortran
9c16f35a 8463* Pascal:: Pascal
b37303ee 8464* Modula-2:: Modula-2
e07c999f 8465* Ada:: Ada
c906108c
SS
8466@end menu
8467
6d2ebf8b 8468@node C
b37052ae 8469@subsection C and C@t{++}
7a292a7a 8470
b37052ae
EZ
8471@cindex C and C@t{++}
8472@cindex expressions in C or C@t{++}
c906108c 8473
b37052ae 8474Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8475to both languages. Whenever this is the case, we discuss those languages
8476together.
8477
41afff9a
EZ
8478@cindex C@t{++}
8479@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8480@cindex @sc{gnu} C@t{++}
8481The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8482compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8483effectively, you must compile your C@t{++} programs with a supported
8484C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8485compiler (@code{aCC}).
8486
0179ffac
DC
8487For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8488format; if it doesn't work on your system, try the stabs+ debugging
8489format. You can select those formats explicitly with the @code{g++}
8490command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8491@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8492CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8493
c906108c 8494@menu
b37052ae
EZ
8495* C Operators:: C and C@t{++} operators
8496* C Constants:: C and C@t{++} constants
8497* C plus plus expressions:: C@t{++} expressions
8498* C Defaults:: Default settings for C and C@t{++}
8499* C Checks:: C and C@t{++} type and range checks
c906108c 8500* Debugging C:: @value{GDBN} and C
b37052ae 8501* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8502@end menu
c906108c 8503
6d2ebf8b 8504@node C Operators
b37052ae 8505@subsubsection C and C@t{++} operators
7a292a7a 8506
b37052ae 8507@cindex C and C@t{++} operators
c906108c
SS
8508
8509Operators must be defined on values of specific types. For instance,
8510@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8511often defined on groups of types.
c906108c 8512
b37052ae 8513For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8514
8515@itemize @bullet
53a5351d 8516
c906108c 8517@item
c906108c 8518@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8519specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8520
8521@item
d4f3574e
SS
8522@emph{Floating-point types} include @code{float}, @code{double}, and
8523@code{long double} (if supported by the target platform).
c906108c
SS
8524
8525@item
53a5351d 8526@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8527
8528@item
8529@emph{Scalar types} include all of the above.
53a5351d 8530
c906108c
SS
8531@end itemize
8532
8533@noindent
8534The following operators are supported. They are listed here
8535in order of increasing precedence:
8536
8537@table @code
8538@item ,
8539The comma or sequencing operator. Expressions in a comma-separated list
8540are evaluated from left to right, with the result of the entire
8541expression being the last expression evaluated.
8542
8543@item =
8544Assignment. The value of an assignment expression is the value
8545assigned. Defined on scalar types.
8546
8547@item @var{op}=
8548Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8549and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8550@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8551@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8552@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8553
8554@item ?:
8555The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8556of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8557integral type.
8558
8559@item ||
8560Logical @sc{or}. Defined on integral types.
8561
8562@item &&
8563Logical @sc{and}. Defined on integral types.
8564
8565@item |
8566Bitwise @sc{or}. Defined on integral types.
8567
8568@item ^
8569Bitwise exclusive-@sc{or}. Defined on integral types.
8570
8571@item &
8572Bitwise @sc{and}. Defined on integral types.
8573
8574@item ==@r{, }!=
8575Equality and inequality. Defined on scalar types. The value of these
8576expressions is 0 for false and non-zero for true.
8577
8578@item <@r{, }>@r{, }<=@r{, }>=
8579Less than, greater than, less than or equal, greater than or equal.
8580Defined on scalar types. The value of these expressions is 0 for false
8581and non-zero for true.
8582
8583@item <<@r{, }>>
8584left shift, and right shift. Defined on integral types.
8585
8586@item @@
8587The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8588
8589@item +@r{, }-
8590Addition and subtraction. Defined on integral types, floating-point types and
8591pointer types.
8592
8593@item *@r{, }/@r{, }%
8594Multiplication, division, and modulus. Multiplication and division are
8595defined on integral and floating-point types. Modulus is defined on
8596integral types.
8597
8598@item ++@r{, }--
8599Increment and decrement. When appearing before a variable, the
8600operation is performed before the variable is used in an expression;
8601when appearing after it, the variable's value is used before the
8602operation takes place.
8603
8604@item *
8605Pointer dereferencing. Defined on pointer types. Same precedence as
8606@code{++}.
8607
8608@item &
8609Address operator. Defined on variables. Same precedence as @code{++}.
8610
b37052ae
EZ
8611For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8612allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8613(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8614where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8615stored.
c906108c
SS
8616
8617@item -
8618Negative. Defined on integral and floating-point types. Same
8619precedence as @code{++}.
8620
8621@item !
8622Logical negation. Defined on integral types. Same precedence as
8623@code{++}.
8624
8625@item ~
8626Bitwise complement operator. Defined on integral types. Same precedence as
8627@code{++}.
8628
8629
8630@item .@r{, }->
8631Structure member, and pointer-to-structure member. For convenience,
8632@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8633pointer based on the stored type information.
8634Defined on @code{struct} and @code{union} data.
8635
c906108c
SS
8636@item .*@r{, }->*
8637Dereferences of pointers to members.
c906108c
SS
8638
8639@item []
8640Array indexing. @code{@var{a}[@var{i}]} is defined as
8641@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8642
8643@item ()
8644Function parameter list. Same precedence as @code{->}.
8645
c906108c 8646@item ::
b37052ae 8647C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8648and @code{class} types.
c906108c
SS
8649
8650@item ::
7a292a7a
SS
8651Doubled colons also represent the @value{GDBN} scope operator
8652(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8653above.
c906108c
SS
8654@end table
8655
c906108c
SS
8656If an operator is redefined in the user code, @value{GDBN} usually
8657attempts to invoke the redefined version instead of using the operator's
8658predefined meaning.
c906108c 8659
c906108c 8660@menu
5d161b24 8661* C Constants::
c906108c
SS
8662@end menu
8663
6d2ebf8b 8664@node C Constants
b37052ae 8665@subsubsection C and C@t{++} constants
c906108c 8666
b37052ae 8667@cindex C and C@t{++} constants
c906108c 8668
b37052ae 8669@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8670following ways:
c906108c
SS
8671
8672@itemize @bullet
8673@item
8674Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8675specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8676by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8677@samp{l}, specifying that the constant should be treated as a
8678@code{long} value.
8679
8680@item
8681Floating point constants are a sequence of digits, followed by a decimal
8682point, followed by a sequence of digits, and optionally followed by an
8683exponent. An exponent is of the form:
8684@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8685sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8686A floating-point constant may also end with a letter @samp{f} or
8687@samp{F}, specifying that the constant should be treated as being of
8688the @code{float} (as opposed to the default @code{double}) type; or with
8689a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8690constant.
c906108c
SS
8691
8692@item
8693Enumerated constants consist of enumerated identifiers, or their
8694integral equivalents.
8695
8696@item
8697Character constants are a single character surrounded by single quotes
8698(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8699(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8700be represented by a letter or by @dfn{escape sequences}, which are of
8701the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8702of the character's ordinal value; or of the form @samp{\@var{x}}, where
8703@samp{@var{x}} is a predefined special character---for example,
8704@samp{\n} for newline.
8705
8706@item
96a2c332
SS
8707String constants are a sequence of character constants surrounded by
8708double quotes (@code{"}). Any valid character constant (as described
8709above) may appear. Double quotes within the string must be preceded by
8710a backslash, so for instance @samp{"a\"b'c"} is a string of five
8711characters.
c906108c
SS
8712
8713@item
8714Pointer constants are an integral value. You can also write pointers
8715to constants using the C operator @samp{&}.
8716
8717@item
8718Array constants are comma-separated lists surrounded by braces @samp{@{}
8719and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8720integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8721and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8722@end itemize
8723
c906108c 8724@menu
5d161b24
DB
8725* C plus plus expressions::
8726* C Defaults::
8727* C Checks::
c906108c 8728
5d161b24 8729* Debugging C::
c906108c
SS
8730@end menu
8731
6d2ebf8b 8732@node C plus plus expressions
b37052ae
EZ
8733@subsubsection C@t{++} expressions
8734
8735@cindex expressions in C@t{++}
8736@value{GDBN} expression handling can interpret most C@t{++} expressions.
8737
0179ffac
DC
8738@cindex debugging C@t{++} programs
8739@cindex C@t{++} compilers
8740@cindex debug formats and C@t{++}
8741@cindex @value{NGCC} and C@t{++}
c906108c 8742@quotation
b37052ae 8743@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8744proper compiler and the proper debug format. Currently, @value{GDBN}
8745works best when debugging C@t{++} code that is compiled with
8746@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8747@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8748stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8749stabs+ as their default debug format, so you usually don't need to
8750specify a debug format explicitly. Other compilers and/or debug formats
8751are likely to work badly or not at all when using @value{GDBN} to debug
8752C@t{++} code.
c906108c 8753@end quotation
c906108c
SS
8754
8755@enumerate
8756
8757@cindex member functions
8758@item
8759Member function calls are allowed; you can use expressions like
8760
474c8240 8761@smallexample
c906108c 8762count = aml->GetOriginal(x, y)
474c8240 8763@end smallexample
c906108c 8764
41afff9a 8765@vindex this@r{, inside C@t{++} member functions}
b37052ae 8766@cindex namespace in C@t{++}
c906108c
SS
8767@item
8768While a member function is active (in the selected stack frame), your
8769expressions have the same namespace available as the member function;
8770that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8771pointer @code{this} following the same rules as C@t{++}.
c906108c 8772
c906108c 8773@cindex call overloaded functions
d4f3574e 8774@cindex overloaded functions, calling
b37052ae 8775@cindex type conversions in C@t{++}
c906108c
SS
8776@item
8777You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8778call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8779perform overload resolution involving user-defined type conversions,
8780calls to constructors, or instantiations of templates that do not exist
8781in the program. It also cannot handle ellipsis argument lists or
8782default arguments.
8783
8784It does perform integral conversions and promotions, floating-point
8785promotions, arithmetic conversions, pointer conversions, conversions of
8786class objects to base classes, and standard conversions such as those of
8787functions or arrays to pointers; it requires an exact match on the
8788number of function arguments.
8789
8790Overload resolution is always performed, unless you have specified
8791@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8792,@value{GDBN} features for C@t{++}}.
c906108c 8793
d4f3574e 8794You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8795explicit function signature to call an overloaded function, as in
8796@smallexample
8797p 'foo(char,int)'('x', 13)
8798@end smallexample
d4f3574e 8799
c906108c 8800The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8801see @ref{Completion, ,Command completion}.
c906108c 8802
c906108c
SS
8803@cindex reference declarations
8804@item
b37052ae
EZ
8805@value{GDBN} understands variables declared as C@t{++} references; you can use
8806them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8807dereferenced.
8808
8809In the parameter list shown when @value{GDBN} displays a frame, the values of
8810reference variables are not displayed (unlike other variables); this
8811avoids clutter, since references are often used for large structures.
8812The @emph{address} of a reference variable is always shown, unless
8813you have specified @samp{set print address off}.
8814
8815@item
b37052ae 8816@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8817expressions can use it just as expressions in your program do. Since
8818one scope may be defined in another, you can use @code{::} repeatedly if
8819necessary, for example in an expression like
8820@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8821resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8822debugging (@pxref{Variables, ,Program variables}).
8823@end enumerate
8824
b37052ae 8825In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8826calling virtual functions correctly, printing out virtual bases of
8827objects, calling functions in a base subobject, casting objects, and
8828invoking user-defined operators.
c906108c 8829
6d2ebf8b 8830@node C Defaults
b37052ae 8831@subsubsection C and C@t{++} defaults
7a292a7a 8832
b37052ae 8833@cindex C and C@t{++} defaults
c906108c 8834
c906108c
SS
8835If you allow @value{GDBN} to set type and range checking automatically, they
8836both default to @code{off} whenever the working language changes to
b37052ae 8837C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8838selects the working language.
c906108c
SS
8839
8840If you allow @value{GDBN} to set the language automatically, it
8841recognizes source files whose names end with @file{.c}, @file{.C}, or
8842@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8843these files, it sets the working language to C or C@t{++}.
c906108c
SS
8844@xref{Automatically, ,Having @value{GDBN} infer the source language},
8845for further details.
8846
c906108c
SS
8847@c Type checking is (a) primarily motivated by Modula-2, and (b)
8848@c unimplemented. If (b) changes, it might make sense to let this node
8849@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8850
6d2ebf8b 8851@node C Checks
b37052ae 8852@subsubsection C and C@t{++} type and range checks
7a292a7a 8853
b37052ae 8854@cindex C and C@t{++} checks
c906108c 8855
b37052ae 8856By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8857is not used. However, if you turn type checking on, @value{GDBN}
8858considers two variables type equivalent if:
8859
8860@itemize @bullet
8861@item
8862The two variables are structured and have the same structure, union, or
8863enumerated tag.
8864
8865@item
8866The two variables have the same type name, or types that have been
8867declared equivalent through @code{typedef}.
8868
8869@ignore
8870@c leaving this out because neither J Gilmore nor R Pesch understand it.
8871@c FIXME--beers?
8872@item
8873The two @code{struct}, @code{union}, or @code{enum} variables are
8874declared in the same declaration. (Note: this may not be true for all C
8875compilers.)
8876@end ignore
8877@end itemize
8878
8879Range checking, if turned on, is done on mathematical operations. Array
8880indices are not checked, since they are often used to index a pointer
8881that is not itself an array.
c906108c 8882
6d2ebf8b 8883@node Debugging C
c906108c 8884@subsubsection @value{GDBN} and C
c906108c
SS
8885
8886The @code{set print union} and @code{show print union} commands apply to
8887the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8888inside a @code{struct} or @code{class} is also printed. Otherwise, it
8889appears as @samp{@{...@}}.
c906108c
SS
8890
8891The @code{@@} operator aids in the debugging of dynamic arrays, formed
8892with pointers and a memory allocation function. @xref{Expressions,
8893,Expressions}.
8894
c906108c 8895@menu
5d161b24 8896* Debugging C plus plus::
c906108c
SS
8897@end menu
8898
6d2ebf8b 8899@node Debugging C plus plus
b37052ae 8900@subsubsection @value{GDBN} features for C@t{++}
c906108c 8901
b37052ae 8902@cindex commands for C@t{++}
7a292a7a 8903
b37052ae
EZ
8904Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8905designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8906
8907@table @code
8908@cindex break in overloaded functions
8909@item @r{breakpoint menus}
8910When you want a breakpoint in a function whose name is overloaded,
8911@value{GDBN} breakpoint menus help you specify which function definition
8912you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8913
b37052ae 8914@cindex overloading in C@t{++}
c906108c
SS
8915@item rbreak @var{regex}
8916Setting breakpoints using regular expressions is helpful for setting
8917breakpoints on overloaded functions that are not members of any special
8918classes.
8919@xref{Set Breaks, ,Setting breakpoints}.
8920
b37052ae 8921@cindex C@t{++} exception handling
c906108c
SS
8922@item catch throw
8923@itemx catch catch
b37052ae 8924Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8925Catchpoints, , Setting catchpoints}.
8926
8927@cindex inheritance
8928@item ptype @var{typename}
8929Print inheritance relationships as well as other information for type
8930@var{typename}.
8931@xref{Symbols, ,Examining the Symbol Table}.
8932
b37052ae 8933@cindex C@t{++} symbol display
c906108c
SS
8934@item set print demangle
8935@itemx show print demangle
8936@itemx set print asm-demangle
8937@itemx show print asm-demangle
b37052ae
EZ
8938Control whether C@t{++} symbols display in their source form, both when
8939displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8940@xref{Print Settings, ,Print settings}.
8941
8942@item set print object
8943@itemx show print object
8944Choose whether to print derived (actual) or declared types of objects.
8945@xref{Print Settings, ,Print settings}.
8946
8947@item set print vtbl
8948@itemx show print vtbl
8949Control the format for printing virtual function tables.
8950@xref{Print Settings, ,Print settings}.
c906108c 8951(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8952ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8953
8954@kindex set overload-resolution
d4f3574e 8955@cindex overloaded functions, overload resolution
c906108c 8956@item set overload-resolution on
b37052ae 8957Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8958is on. For overloaded functions, @value{GDBN} evaluates the arguments
8959and searches for a function whose signature matches the argument types,
b37052ae 8960using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8961expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8962message.
8963
8964@item set overload-resolution off
b37052ae 8965Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8966overloaded functions that are not class member functions, @value{GDBN}
8967chooses the first function of the specified name that it finds in the
8968symbol table, whether or not its arguments are of the correct type. For
8969overloaded functions that are class member functions, @value{GDBN}
8970searches for a function whose signature @emph{exactly} matches the
8971argument types.
c906108c 8972
9c16f35a
EZ
8973@kindex show overload-resolution
8974@item show overload-resolution
8975Show the current setting of overload resolution.
8976
c906108c
SS
8977@item @r{Overloaded symbol names}
8978You can specify a particular definition of an overloaded symbol, using
b37052ae 8979the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
8980@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8981also use the @value{GDBN} command-line word completion facilities to list the
8982available choices, or to finish the type list for you.
8983@xref{Completion,, Command completion}, for details on how to do this.
8984@end table
c906108c 8985
b37303ee
AF
8986@node Objective-C
8987@subsection Objective-C
8988
8989@cindex Objective-C
8990This section provides information about some commands and command
721c2651
EZ
8991options that are useful for debugging Objective-C code. See also
8992@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
8993few more commands specific to Objective-C support.
b37303ee
AF
8994
8995@menu
b383017d
RM
8996* Method Names in Commands::
8997* The Print Command with Objective-C::
b37303ee
AF
8998@end menu
8999
9000@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
9001@subsubsection Method Names in Commands
9002
9003The following commands have been extended to accept Objective-C method
9004names as line specifications:
9005
9006@kindex clear@r{, and Objective-C}
9007@kindex break@r{, and Objective-C}
9008@kindex info line@r{, and Objective-C}
9009@kindex jump@r{, and Objective-C}
9010@kindex list@r{, and Objective-C}
9011@itemize
9012@item @code{clear}
9013@item @code{break}
9014@item @code{info line}
9015@item @code{jump}
9016@item @code{list}
9017@end itemize
9018
9019A fully qualified Objective-C method name is specified as
9020
9021@smallexample
9022-[@var{Class} @var{methodName}]
9023@end smallexample
9024
c552b3bb
JM
9025where the minus sign is used to indicate an instance method and a
9026plus sign (not shown) is used to indicate a class method. The class
9027name @var{Class} and method name @var{methodName} are enclosed in
9028brackets, similar to the way messages are specified in Objective-C
9029source code. For example, to set a breakpoint at the @code{create}
9030instance method of class @code{Fruit} in the program currently being
9031debugged, enter:
b37303ee
AF
9032
9033@smallexample
9034break -[Fruit create]
9035@end smallexample
9036
9037To list ten program lines around the @code{initialize} class method,
9038enter:
9039
9040@smallexample
9041list +[NSText initialize]
9042@end smallexample
9043
c552b3bb
JM
9044In the current version of @value{GDBN}, the plus or minus sign is
9045required. In future versions of @value{GDBN}, the plus or minus
9046sign will be optional, but you can use it to narrow the search. It
9047is also possible to specify just a method name:
b37303ee
AF
9048
9049@smallexample
9050break create
9051@end smallexample
9052
9053You must specify the complete method name, including any colons. If
9054your program's source files contain more than one @code{create} method,
9055you'll be presented with a numbered list of classes that implement that
9056method. Indicate your choice by number, or type @samp{0} to exit if
9057none apply.
9058
9059As another example, to clear a breakpoint established at the
9060@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
9061
9062@smallexample
9063clear -[NSWindow makeKeyAndOrderFront:]
9064@end smallexample
9065
9066@node The Print Command with Objective-C
9067@subsubsection The Print Command With Objective-C
721c2651 9068@cindex Objective-C, print objects
c552b3bb
JM
9069@kindex print-object
9070@kindex po @r{(@code{print-object})}
b37303ee 9071
c552b3bb 9072The print command has also been extended to accept methods. For example:
b37303ee
AF
9073
9074@smallexample
c552b3bb 9075print -[@var{object} hash]
b37303ee
AF
9076@end smallexample
9077
9078@cindex print an Objective-C object description
c552b3bb
JM
9079@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
9080@noindent
9081will tell @value{GDBN} to send the @code{hash} message to @var{object}
9082and print the result. Also, an additional command has been added,
9083@code{print-object} or @code{po} for short, which is meant to print
9084the description of an object. However, this command may only work
9085with certain Objective-C libraries that have a particular hook
9086function, @code{_NSPrintForDebugger}, defined.
b37303ee 9087
09d4efe1
EZ
9088@node Fortran
9089@subsection Fortran
9090@cindex Fortran-specific support in @value{GDBN}
9091
9092@table @code
9093@cindex @code{COMMON} blocks, Fortran
9094@kindex info common
9095@item info common @r{[}@var{common-name}@r{]}
9096This command prints the values contained in the Fortran @code{COMMON}
9097block whose name is @var{common-name}. With no argument, the names of
9098all @code{COMMON} blocks visible at current program location are
9099printed.
9100@end table
9101
a8f24a35
EZ
9102Fortran symbols are usually case-insensitive, so @value{GDBN} by
9103default uses case-insensitive matches for Fortran symbols. You can
9104change that with the @samp{set case-insensitive} command, see
9105@ref{Symbols}, for the details.
9106
9c16f35a
EZ
9107@node Pascal
9108@subsection Pascal
9109
9110@cindex Pascal support in @value{GDBN}, limitations
9111Debugging Pascal programs which use sets, subranges, file variables, or
9112nested functions does not currently work. @value{GDBN} does not support
9113entering expressions, printing values, or similar features using Pascal
9114syntax.
9115
9116The Pascal-specific command @code{set print pascal_static-members}
9117controls whether static members of Pascal objects are displayed.
9118@xref{Print Settings, pascal_static-members}.
9119
09d4efe1 9120@node Modula-2
c906108c 9121@subsection Modula-2
7a292a7a 9122
d4f3574e 9123@cindex Modula-2, @value{GDBN} support
c906108c
SS
9124
9125The extensions made to @value{GDBN} to support Modula-2 only support
9126output from the @sc{gnu} Modula-2 compiler (which is currently being
9127developed). Other Modula-2 compilers are not currently supported, and
9128attempting to debug executables produced by them is most likely
9129to give an error as @value{GDBN} reads in the executable's symbol
9130table.
9131
9132@cindex expressions in Modula-2
9133@menu
9134* M2 Operators:: Built-in operators
9135* Built-In Func/Proc:: Built-in functions and procedures
9136* M2 Constants:: Modula-2 constants
9137* M2 Defaults:: Default settings for Modula-2
9138* Deviations:: Deviations from standard Modula-2
9139* M2 Checks:: Modula-2 type and range checks
9140* M2 Scope:: The scope operators @code{::} and @code{.}
9141* GDB/M2:: @value{GDBN} and Modula-2
9142@end menu
9143
6d2ebf8b 9144@node M2 Operators
c906108c
SS
9145@subsubsection Operators
9146@cindex Modula-2 operators
9147
9148Operators must be defined on values of specific types. For instance,
9149@code{+} is defined on numbers, but not on structures. Operators are
9150often defined on groups of types. For the purposes of Modula-2, the
9151following definitions hold:
9152
9153@itemize @bullet
9154
9155@item
9156@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
9157their subranges.
9158
9159@item
9160@emph{Character types} consist of @code{CHAR} and its subranges.
9161
9162@item
9163@emph{Floating-point types} consist of @code{REAL}.
9164
9165@item
9166@emph{Pointer types} consist of anything declared as @code{POINTER TO
9167@var{type}}.
9168
9169@item
9170@emph{Scalar types} consist of all of the above.
9171
9172@item
9173@emph{Set types} consist of @code{SET} and @code{BITSET} types.
9174
9175@item
9176@emph{Boolean types} consist of @code{BOOLEAN}.
9177@end itemize
9178
9179@noindent
9180The following operators are supported, and appear in order of
9181increasing precedence:
9182
9183@table @code
9184@item ,
9185Function argument or array index separator.
9186
9187@item :=
9188Assignment. The value of @var{var} @code{:=} @var{value} is
9189@var{value}.
9190
9191@item <@r{, }>
9192Less than, greater than on integral, floating-point, or enumerated
9193types.
9194
9195@item <=@r{, }>=
96a2c332 9196Less than or equal to, greater than or equal to
c906108c
SS
9197on integral, floating-point and enumerated types, or set inclusion on
9198set types. Same precedence as @code{<}.
9199
9200@item =@r{, }<>@r{, }#
9201Equality and two ways of expressing inequality, valid on scalar types.
9202Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9203available for inequality, since @code{#} conflicts with the script
9204comment character.
9205
9206@item IN
9207Set membership. Defined on set types and the types of their members.
9208Same precedence as @code{<}.
9209
9210@item OR
9211Boolean disjunction. Defined on boolean types.
9212
9213@item AND@r{, }&
d4f3574e 9214Boolean conjunction. Defined on boolean types.
c906108c
SS
9215
9216@item @@
9217The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9218
9219@item +@r{, }-
9220Addition and subtraction on integral and floating-point types, or union
9221and difference on set types.
9222
9223@item *
9224Multiplication on integral and floating-point types, or set intersection
9225on set types.
9226
9227@item /
9228Division on floating-point types, or symmetric set difference on set
9229types. Same precedence as @code{*}.
9230
9231@item DIV@r{, }MOD
9232Integer division and remainder. Defined on integral types. Same
9233precedence as @code{*}.
9234
9235@item -
9236Negative. Defined on @code{INTEGER} and @code{REAL} data.
9237
9238@item ^
9239Pointer dereferencing. Defined on pointer types.
9240
9241@item NOT
9242Boolean negation. Defined on boolean types. Same precedence as
9243@code{^}.
9244
9245@item .
9246@code{RECORD} field selector. Defined on @code{RECORD} data. Same
9247precedence as @code{^}.
9248
9249@item []
9250Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
9251
9252@item ()
9253Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
9254as @code{^}.
9255
9256@item ::@r{, }.
9257@value{GDBN} and Modula-2 scope operators.
9258@end table
9259
9260@quotation
9261@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
9262treats the use of the operator @code{IN}, or the use of operators
9263@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
9264@code{<=}, and @code{>=} on sets as an error.
9265@end quotation
9266
cb51c4e0 9267
6d2ebf8b 9268@node Built-In Func/Proc
c906108c 9269@subsubsection Built-in functions and procedures
cb51c4e0 9270@cindex Modula-2 built-ins
c906108c
SS
9271
9272Modula-2 also makes available several built-in procedures and functions.
9273In describing these, the following metavariables are used:
9274
9275@table @var
9276
9277@item a
9278represents an @code{ARRAY} variable.
9279
9280@item c
9281represents a @code{CHAR} constant or variable.
9282
9283@item i
9284represents a variable or constant of integral type.
9285
9286@item m
9287represents an identifier that belongs to a set. Generally used in the
9288same function with the metavariable @var{s}. The type of @var{s} should
9289be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
9290
9291@item n
9292represents a variable or constant of integral or floating-point type.
9293
9294@item r
9295represents a variable or constant of floating-point type.
9296
9297@item t
9298represents a type.
9299
9300@item v
9301represents a variable.
9302
9303@item x
9304represents a variable or constant of one of many types. See the
9305explanation of the function for details.
9306@end table
9307
9308All Modula-2 built-in procedures also return a result, described below.
9309
9310@table @code
9311@item ABS(@var{n})
9312Returns the absolute value of @var{n}.
9313
9314@item CAP(@var{c})
9315If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 9316equivalent, otherwise it returns its argument.
c906108c
SS
9317
9318@item CHR(@var{i})
9319Returns the character whose ordinal value is @var{i}.
9320
9321@item DEC(@var{v})
c3f6f71d 9322Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9323
9324@item DEC(@var{v},@var{i})
9325Decrements the value in the variable @var{v} by @var{i}. Returns the
9326new value.
9327
9328@item EXCL(@var{m},@var{s})
9329Removes the element @var{m} from the set @var{s}. Returns the new
9330set.
9331
9332@item FLOAT(@var{i})
9333Returns the floating point equivalent of the integer @var{i}.
9334
9335@item HIGH(@var{a})
9336Returns the index of the last member of @var{a}.
9337
9338@item INC(@var{v})
c3f6f71d 9339Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9340
9341@item INC(@var{v},@var{i})
9342Increments the value in the variable @var{v} by @var{i}. Returns the
9343new value.
9344
9345@item INCL(@var{m},@var{s})
9346Adds the element @var{m} to the set @var{s} if it is not already
9347there. Returns the new set.
9348
9349@item MAX(@var{t})
9350Returns the maximum value of the type @var{t}.
9351
9352@item MIN(@var{t})
9353Returns the minimum value of the type @var{t}.
9354
9355@item ODD(@var{i})
9356Returns boolean TRUE if @var{i} is an odd number.
9357
9358@item ORD(@var{x})
9359Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
9360value of a character is its @sc{ascii} value (on machines supporting the
9361@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
9362integral, character and enumerated types.
9363
9364@item SIZE(@var{x})
9365Returns the size of its argument. @var{x} can be a variable or a type.
9366
9367@item TRUNC(@var{r})
9368Returns the integral part of @var{r}.
9369
9370@item VAL(@var{t},@var{i})
9371Returns the member of the type @var{t} whose ordinal value is @var{i}.
9372@end table
9373
9374@quotation
9375@emph{Warning:} Sets and their operations are not yet supported, so
9376@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
9377an error.
9378@end quotation
9379
9380@cindex Modula-2 constants
6d2ebf8b 9381@node M2 Constants
c906108c
SS
9382@subsubsection Constants
9383
9384@value{GDBN} allows you to express the constants of Modula-2 in the following
9385ways:
9386
9387@itemize @bullet
9388
9389@item
9390Integer constants are simply a sequence of digits. When used in an
9391expression, a constant is interpreted to be type-compatible with the
9392rest of the expression. Hexadecimal integers are specified by a
9393trailing @samp{H}, and octal integers by a trailing @samp{B}.
9394
9395@item
9396Floating point constants appear as a sequence of digits, followed by a
9397decimal point and another sequence of digits. An optional exponent can
9398then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
9399@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
9400digits of the floating point constant must be valid decimal (base 10)
9401digits.
9402
9403@item
9404Character constants consist of a single character enclosed by a pair of
9405like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 9406also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
9407followed by a @samp{C}.
9408
9409@item
9410String constants consist of a sequence of characters enclosed by a
9411pair of like quotes, either single (@code{'}) or double (@code{"}).
9412Escape sequences in the style of C are also allowed. @xref{C
b37052ae 9413Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
9414sequences.
9415
9416@item
9417Enumerated constants consist of an enumerated identifier.
9418
9419@item
9420Boolean constants consist of the identifiers @code{TRUE} and
9421@code{FALSE}.
9422
9423@item
9424Pointer constants consist of integral values only.
9425
9426@item
9427Set constants are not yet supported.
9428@end itemize
9429
6d2ebf8b 9430@node M2 Defaults
c906108c
SS
9431@subsubsection Modula-2 defaults
9432@cindex Modula-2 defaults
9433
9434If type and range checking are set automatically by @value{GDBN}, they
9435both default to @code{on} whenever the working language changes to
d4f3574e 9436Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
9437selected the working language.
9438
9439If you allow @value{GDBN} to set the language automatically, then entering
9440code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 9441working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
9442the language automatically}, for further details.
9443
6d2ebf8b 9444@node Deviations
c906108c
SS
9445@subsubsection Deviations from standard Modula-2
9446@cindex Modula-2, deviations from
9447
9448A few changes have been made to make Modula-2 programs easier to debug.
9449This is done primarily via loosening its type strictness:
9450
9451@itemize @bullet
9452@item
9453Unlike in standard Modula-2, pointer constants can be formed by
9454integers. This allows you to modify pointer variables during
9455debugging. (In standard Modula-2, the actual address contained in a
9456pointer variable is hidden from you; it can only be modified
9457through direct assignment to another pointer variable or expression that
9458returned a pointer.)
9459
9460@item
9461C escape sequences can be used in strings and characters to represent
9462non-printable characters. @value{GDBN} prints out strings with these
9463escape sequences embedded. Single non-printable characters are
9464printed using the @samp{CHR(@var{nnn})} format.
9465
9466@item
9467The assignment operator (@code{:=}) returns the value of its right-hand
9468argument.
9469
9470@item
9471All built-in procedures both modify @emph{and} return their argument.
9472@end itemize
9473
6d2ebf8b 9474@node M2 Checks
c906108c
SS
9475@subsubsection Modula-2 type and range checks
9476@cindex Modula-2 checks
9477
9478@quotation
9479@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9480range checking.
9481@end quotation
9482@c FIXME remove warning when type/range checks added
9483
9484@value{GDBN} considers two Modula-2 variables type equivalent if:
9485
9486@itemize @bullet
9487@item
9488They are of types that have been declared equivalent via a @code{TYPE
9489@var{t1} = @var{t2}} statement
9490
9491@item
9492They have been declared on the same line. (Note: This is true of the
9493@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9494@end itemize
9495
9496As long as type checking is enabled, any attempt to combine variables
9497whose types are not equivalent is an error.
9498
9499Range checking is done on all mathematical operations, assignment, array
9500index bounds, and all built-in functions and procedures.
9501
6d2ebf8b 9502@node M2 Scope
c906108c
SS
9503@subsubsection The scope operators @code{::} and @code{.}
9504@cindex scope
41afff9a 9505@cindex @code{.}, Modula-2 scope operator
c906108c
SS
9506@cindex colon, doubled as scope operator
9507@ifinfo
41afff9a 9508@vindex colon-colon@r{, in Modula-2}
c906108c
SS
9509@c Info cannot handle :: but TeX can.
9510@end ifinfo
9511@iftex
41afff9a 9512@vindex ::@r{, in Modula-2}
c906108c
SS
9513@end iftex
9514
9515There are a few subtle differences between the Modula-2 scope operator
9516(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9517similar syntax:
9518
474c8240 9519@smallexample
c906108c
SS
9520
9521@var{module} . @var{id}
9522@var{scope} :: @var{id}
474c8240 9523@end smallexample
c906108c
SS
9524
9525@noindent
9526where @var{scope} is the name of a module or a procedure,
9527@var{module} the name of a module, and @var{id} is any declared
9528identifier within your program, except another module.
9529
9530Using the @code{::} operator makes @value{GDBN} search the scope
9531specified by @var{scope} for the identifier @var{id}. If it is not
9532found in the specified scope, then @value{GDBN} searches all scopes
9533enclosing the one specified by @var{scope}.
9534
9535Using the @code{.} operator makes @value{GDBN} search the current scope for
9536the identifier specified by @var{id} that was imported from the
9537definition module specified by @var{module}. With this operator, it is
9538an error if the identifier @var{id} was not imported from definition
9539module @var{module}, or if @var{id} is not an identifier in
9540@var{module}.
9541
6d2ebf8b 9542@node GDB/M2
c906108c
SS
9543@subsubsection @value{GDBN} and Modula-2
9544
9545Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9546Five subcommands of @code{set print} and @code{show print} apply
b37052ae 9547specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 9548@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 9549apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
9550analogue in Modula-2.
9551
9552The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 9553with any language, is not useful with Modula-2. Its
c906108c 9554intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 9555created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 9556address can be specified by an integral constant, the construct
d4f3574e 9557@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
9558
9559@cindex @code{#} in Modula-2
9560In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9561interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 9562
e07c999f
PH
9563@node Ada
9564@subsection Ada
9565@cindex Ada
9566
9567The extensions made to @value{GDBN} for Ada only support
9568output from the @sc{gnu} Ada (GNAT) compiler.
9569Other Ada compilers are not currently supported, and
9570attempting to debug executables produced by them is most likely
9571to be difficult.
9572
9573
9574@cindex expressions in Ada
9575@menu
9576* Ada Mode Intro:: General remarks on the Ada syntax
9577 and semantics supported by Ada mode
9578 in @value{GDBN}.
9579* Omissions from Ada:: Restrictions on the Ada expression syntax.
9580* Additions to Ada:: Extensions of the Ada expression syntax.
9581* Stopping Before Main Program:: Debugging the program during elaboration.
9582* Ada Glitches:: Known peculiarities of Ada mode.
9583@end menu
9584
9585@node Ada Mode Intro
9586@subsubsection Introduction
9587@cindex Ada mode, general
9588
9589The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9590syntax, with some extensions.
9591The philosophy behind the design of this subset is
9592
9593@itemize @bullet
9594@item
9595That @value{GDBN} should provide basic literals and access to operations for
9596arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9597leaving more sophisticated computations to subprograms written into the
9598program (which therefore may be called from @value{GDBN}).
9599
9600@item
9601That type safety and strict adherence to Ada language restrictions
9602are not particularly important to the @value{GDBN} user.
9603
9604@item
9605That brevity is important to the @value{GDBN} user.
9606@end itemize
9607
9608Thus, for brevity, the debugger acts as if there were
9609implicit @code{with} and @code{use} clauses in effect for all user-written
9610packages, making it unnecessary to fully qualify most names with
9611their packages, regardless of context. Where this causes ambiguity,
9612@value{GDBN} asks the user's intent.
9613
9614The debugger will start in Ada mode if it detects an Ada main program.
9615As for other languages, it will enter Ada mode when stopped in a program that
9616was translated from an Ada source file.
9617
9618While in Ada mode, you may use `@t{--}' for comments. This is useful
9619mostly for documenting command files. The standard @value{GDBN} comment
9620(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9621middle (to allow based literals).
9622
9623The debugger supports limited overloading. Given a subprogram call in which
9624the function symbol has multiple definitions, it will use the number of
9625actual parameters and some information about their types to attempt to narrow
9626the set of definitions. It also makes very limited use of context, preferring
9627procedures to functions in the context of the @code{call} command, and
9628functions to procedures elsewhere.
9629
9630@node Omissions from Ada
9631@subsubsection Omissions from Ada
9632@cindex Ada, omissions from
9633
9634Here are the notable omissions from the subset:
9635
9636@itemize @bullet
9637@item
9638Only a subset of the attributes are supported:
9639
9640@itemize @minus
9641@item
9642@t{'First}, @t{'Last}, and @t{'Length}
9643 on array objects (not on types and subtypes).
9644
9645@item
9646@t{'Min} and @t{'Max}.
9647
9648@item
9649@t{'Pos} and @t{'Val}.
9650
9651@item
9652@t{'Tag}.
9653
9654@item
9655@t{'Range} on array objects (not subtypes), but only as the right
9656operand of the membership (@code{in}) operator.
9657
9658@item
9659@t{'Access}, @t{'Unchecked_Access}, and
9660@t{'Unrestricted_Access} (a GNAT extension).
9661
9662@item
9663@t{'Address}.
9664@end itemize
9665
9666@item
9667The names in
9668@code{Characters.Latin_1} are not available and
9669concatenation is not implemented. Thus, escape characters in strings are
9670not currently available.
9671
9672@item
9673Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9674equality of representations. They will generally work correctly
9675for strings and arrays whose elements have integer or enumeration types.
9676They may not work correctly for arrays whose element
9677types have user-defined equality, for arrays of real values
9678(in particular, IEEE-conformant floating point, because of negative
9679zeroes and NaNs), and for arrays whose elements contain unused bits with
9680indeterminate values.
9681
9682@item
9683The other component-by-component array operations (@code{and}, @code{or},
9684@code{xor}, @code{not}, and relational tests other than equality)
9685are not implemented.
9686
9687@item
9688There are no record or array aggregates.
9689
9690@item
9691Calls to dispatching subprograms are not implemented.
9692
9693@item
9694The overloading algorithm is much more limited (i.e., less selective)
9695than that of real Ada. It makes only limited use of the context in which a subexpression
9696appears to resolve its meaning, and it is much looser in its rules for allowing
9697type matches. As a result, some function calls will be ambiguous, and the user
9698will be asked to choose the proper resolution.
9699
9700@item
9701The @code{new} operator is not implemented.
9702
9703@item
9704Entry calls are not implemented.
9705
9706@item
9707Aside from printing, arithmetic operations on the native VAX floating-point
9708formats are not supported.
9709
9710@item
9711It is not possible to slice a packed array.
9712@end itemize
9713
9714@node Additions to Ada
9715@subsubsection Additions to Ada
9716@cindex Ada, deviations from
9717
9718As it does for other languages, @value{GDBN} makes certain generic
9719extensions to Ada (@pxref{Expressions}):
9720
9721@itemize @bullet
9722@item
9723If the expression @var{E} is a variable residing in memory
9724(typically a local variable or array element) and @var{N} is
9725a positive integer, then @code{@var{E}@@@var{N}} displays the values of
9726@var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
9727In Ada, this operator is generally not necessary, since its prime use
9728is in displaying parts of an array, and slicing will usually do this in Ada.
9729However, there are occasional uses when debugging programs
9730in which certain debugging information has been optimized away.
9731
9732@item
9733@code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
9734in function or file @var{B}.'' When @var{B} is a file name, you must typically
9735surround it in single quotes.
9736
9737@item
9738The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
9739@var{type} that appears at address @var{addr}.''
9740
9741@item
9742A name starting with @samp{$} is a convenience variable
9743(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
9744@end itemize
9745
9746In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
9747to Ada:
9748
9749@itemize @bullet
9750@item
9751The assignment statement is allowed as an expression, returning
9752its right-hand operand as its value. Thus, you may enter
9753
9754@smallexample
9755set x := y + 3
9756print A(tmp := y + 1)
9757@end smallexample
9758
9759@item
9760The semicolon is allowed as an ``operator,'' returning as its value
9761the value of its right-hand operand.
9762This allows, for example,
9763complex conditional breaks:
9764
9765@smallexample
9766break f
9767condition 1 (report(i); k += 1; A(k) > 100)
9768@end smallexample
9769
9770@item
9771Rather than use catenation and symbolic character names to introduce special
9772characters into strings, one may instead use a special bracket notation,
9773which is also used to print strings. A sequence of characters of the form
9774@samp{["@var{XX}"]} within a string or character literal denotes the
9775(single) character whose numeric encoding is @var{XX} in hexadecimal. The
9776sequence of characters @samp{["""]} also denotes a single quotation mark
9777in strings. For example,
9778@smallexample
9779 "One line.["0a"]Next line.["0a"]"
9780@end smallexample
9781@noindent
9782contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
9783period.
9784
9785@item
9786The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
9787@t{'Max} is optional (and is ignored in any case). For example, it is valid
9788to write
9789
9790@smallexample
9791print 'max(x, y)
9792@end smallexample
9793
9794@item
9795When printing arrays, @value{GDBN} uses positional notation when the
9796array has a lower bound of 1, and uses a modified named notation otherwise.
9797For example, a one-dimensional array of three integers with a lower bound of 3 might print as
9798
9799@smallexample
9800(3 => 10, 17, 1)
9801@end smallexample
9802
9803@noindent
9804That is, in contrast to valid Ada, only the first component has a @code{=>}
9805clause.
9806
9807@item
9808You may abbreviate attributes in expressions with any unique,
9809multi-character subsequence of
9810their names (an exact match gets preference).
9811For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
9812in place of @t{a'length}.
9813
9814@item
9815@cindex quoting Ada internal identifiers
9816Since Ada is case-insensitive, the debugger normally maps identifiers you type
9817to lower case. The GNAT compiler uses upper-case characters for
9818some of its internal identifiers, which are normally of no interest to users.
9819For the rare occasions when you actually have to look at them,
9820enclose them in angle brackets to avoid the lower-case mapping.
9821For example,
9822@smallexample
9823@value{GDBP} print <JMPBUF_SAVE>[0]
9824@end smallexample
9825
9826@item
9827Printing an object of class-wide type or dereferencing an
9828access-to-class-wide value will display all the components of the object's
9829specific type (as indicated by its run-time tag). Likewise, component
9830selection on such a value will operate on the specific type of the
9831object.
9832
9833@end itemize
9834
9835@node Stopping Before Main Program
9836@subsubsection Stopping at the Very Beginning
9837
9838@cindex breakpointing Ada elaboration code
9839It is sometimes necessary to debug the program during elaboration, and
9840before reaching the main procedure.
9841As defined in the Ada Reference
9842Manual, the elaboration code is invoked from a procedure called
9843@code{adainit}. To run your program up to the beginning of
9844elaboration, simply use the following two commands:
9845@code{tbreak adainit} and @code{run}.
9846
9847@node Ada Glitches
9848@subsubsection Known Peculiarities of Ada Mode
9849@cindex Ada, problems
9850
9851Besides the omissions listed previously (@pxref{Omissions from Ada}),
9852we know of several problems with and limitations of Ada mode in
9853@value{GDBN},
9854some of which will be fixed with planned future releases of the debugger
9855and the GNU Ada compiler.
9856
9857@itemize @bullet
9858@item
9859Currently, the debugger
9860has insufficient information to determine whether certain pointers represent
9861pointers to objects or the objects themselves.
9862Thus, the user may have to tack an extra @code{.all} after an expression
9863to get it printed properly.
9864
9865@item
9866Static constants that the compiler chooses not to materialize as objects in
9867storage are invisible to the debugger.
9868
9869@item
9870Named parameter associations in function argument lists are ignored (the
9871argument lists are treated as positional).
9872
9873@item
9874Many useful library packages are currently invisible to the debugger.
9875
9876@item
9877Fixed-point arithmetic, conversions, input, and output is carried out using
9878floating-point arithmetic, and may give results that only approximate those on
9879the host machine.
9880
9881@item
9882The type of the @t{'Address} attribute may not be @code{System.Address}.
9883
9884@item
9885The GNAT compiler never generates the prefix @code{Standard} for any of
9886the standard symbols defined by the Ada language. @value{GDBN} knows about
9887this: it will strip the prefix from names when you use it, and will never
9888look for a name you have so qualified among local symbols, nor match against
9889symbols in other packages or subprograms. If you have
9890defined entities anywhere in your program other than parameters and
9891local variables whose simple names match names in @code{Standard},
9892GNAT's lack of qualification here can cause confusion. When this happens,
9893you can usually resolve the confusion
9894by qualifying the problematic names with package
9895@code{Standard} explicitly.
9896@end itemize
9897
4e562065
JB
9898@node Unsupported languages
9899@section Unsupported languages
9900
9901@cindex unsupported languages
9902@cindex minimal language
9903In addition to the other fully-supported programming languages,
9904@value{GDBN} also provides a pseudo-language, called @code{minimal}.
9905It does not represent a real programming language, but provides a set
9906of capabilities close to what the C or assembly languages provide.
9907This should allow most simple operations to be performed while debugging
9908an application that uses a language currently not supported by @value{GDBN}.
9909
9910If the language is set to @code{auto}, @value{GDBN} will automatically
9911select this language if the current frame corresponds to an unsupported
9912language.
9913
6d2ebf8b 9914@node Symbols
c906108c
SS
9915@chapter Examining the Symbol Table
9916
d4f3574e 9917The commands described in this chapter allow you to inquire about the
c906108c
SS
9918symbols (names of variables, functions and types) defined in your
9919program. This information is inherent in the text of your program and
9920does not change as your program executes. @value{GDBN} finds it in your
9921program's symbol table, in the file indicated when you started @value{GDBN}
9922(@pxref{File Options, ,Choosing files}), or by one of the
9923file-management commands (@pxref{Files, ,Commands to specify files}).
9924
9925@cindex symbol names
9926@cindex names of symbols
9927@cindex quoting names
9928Occasionally, you may need to refer to symbols that contain unusual
9929characters, which @value{GDBN} ordinarily treats as word delimiters. The
9930most frequent case is in referring to static variables in other
9931source files (@pxref{Variables,,Program variables}). File names
9932are recorded in object files as debugging symbols, but @value{GDBN} would
9933ordinarily parse a typical file name, like @file{foo.c}, as the three words
9934@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
9935@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
9936
474c8240 9937@smallexample
c906108c 9938p 'foo.c'::x
474c8240 9939@end smallexample
c906108c
SS
9940
9941@noindent
9942looks up the value of @code{x} in the scope of the file @file{foo.c}.
9943
9944@table @code
a8f24a35
EZ
9945@cindex case-insensitive symbol names
9946@cindex case sensitivity in symbol names
9947@kindex set case-sensitive
9948@item set case-sensitive on
9949@itemx set case-sensitive off
9950@itemx set case-sensitive auto
9951Normally, when @value{GDBN} looks up symbols, it matches their names
9952with case sensitivity determined by the current source language.
9953Occasionally, you may wish to control that. The command @code{set
9954case-sensitive} lets you do that by specifying @code{on} for
9955case-sensitive matches or @code{off} for case-insensitive ones. If
9956you specify @code{auto}, case sensitivity is reset to the default
9957suitable for the source language. The default is case-sensitive
9958matches for all languages except for Fortran, for which the default is
9959case-insensitive matches.
9960
9c16f35a
EZ
9961@kindex show case-sensitive
9962@item show case-sensitive
a8f24a35
EZ
9963This command shows the current setting of case sensitivity for symbols
9964lookups.
9965
c906108c 9966@kindex info address
b37052ae 9967@cindex address of a symbol
c906108c
SS
9968@item info address @var{symbol}
9969Describe where the data for @var{symbol} is stored. For a register
9970variable, this says which register it is kept in. For a non-register
9971local variable, this prints the stack-frame offset at which the variable
9972is always stored.
9973
9974Note the contrast with @samp{print &@var{symbol}}, which does not work
9975at all for a register variable, and for a stack local variable prints
9976the exact address of the current instantiation of the variable.
9977
3d67e040 9978@kindex info symbol
b37052ae 9979@cindex symbol from address
9c16f35a 9980@cindex closest symbol and offset for an address
3d67e040
EZ
9981@item info symbol @var{addr}
9982Print the name of a symbol which is stored at the address @var{addr}.
9983If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
9984nearest symbol and an offset from it:
9985
474c8240 9986@smallexample
3d67e040
EZ
9987(@value{GDBP}) info symbol 0x54320
9988_initialize_vx + 396 in section .text
474c8240 9989@end smallexample
3d67e040
EZ
9990
9991@noindent
9992This is the opposite of the @code{info address} command. You can use
9993it to find out the name of a variable or a function given its address.
9994
c906108c 9995@kindex whatis
d4f3574e
SS
9996@item whatis @var{expr}
9997Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
9998actually evaluated, and any side-effecting operations (such as
9999assignments or function calls) inside it do not take place.
10000@xref{Expressions, ,Expressions}.
10001
10002@item whatis
10003Print the data type of @code{$}, the last value in the value history.
10004
10005@kindex ptype
10006@item ptype @var{typename}
10007Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
10008the name of a type, or for C code it may have the form @samp{class
10009@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
10010@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 10011
d4f3574e 10012@item ptype @var{expr}
c906108c 10013@itemx ptype
d4f3574e 10014Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
10015differs from @code{whatis} by printing a detailed description, instead
10016of just the name of the type.
10017
10018For example, for this variable declaration:
10019
474c8240 10020@smallexample
c906108c 10021struct complex @{double real; double imag;@} v;
474c8240 10022@end smallexample
c906108c
SS
10023
10024@noindent
10025the two commands give this output:
10026
474c8240 10027@smallexample
c906108c
SS
10028@group
10029(@value{GDBP}) whatis v
10030type = struct complex
10031(@value{GDBP}) ptype v
10032type = struct complex @{
10033 double real;
10034 double imag;
10035@}
10036@end group
474c8240 10037@end smallexample
c906108c
SS
10038
10039@noindent
10040As with @code{whatis}, using @code{ptype} without an argument refers to
10041the type of @code{$}, the last value in the value history.
10042
10043@kindex info types
10044@item info types @var{regexp}
10045@itemx info types
09d4efe1
EZ
10046Print a brief description of all types whose names match the regular
10047expression @var{regexp} (or all types in your program, if you supply
10048no argument). Each complete typename is matched as though it were a
10049complete line; thus, @samp{i type value} gives information on all
10050types in your program whose names include the string @code{value}, but
10051@samp{i type ^value$} gives information only on types whose complete
10052name is @code{value}.
c906108c
SS
10053
10054This command differs from @code{ptype} in two ways: first, like
10055@code{whatis}, it does not print a detailed description; second, it
10056lists all source files where a type is defined.
10057
b37052ae
EZ
10058@kindex info scope
10059@cindex local variables
09d4efe1 10060@item info scope @var{location}
b37052ae 10061List all the variables local to a particular scope. This command
09d4efe1
EZ
10062accepts a @var{location} argument---a function name, a source line, or
10063an address preceded by a @samp{*}, and prints all the variables local
10064to the scope defined by that location. For example:
b37052ae
EZ
10065
10066@smallexample
10067(@value{GDBP}) @b{info scope command_line_handler}
10068Scope for command_line_handler:
10069Symbol rl is an argument at stack/frame offset 8, length 4.
10070Symbol linebuffer is in static storage at address 0x150a18, length 4.
10071Symbol linelength is in static storage at address 0x150a1c, length 4.
10072Symbol p is a local variable in register $esi, length 4.
10073Symbol p1 is a local variable in register $ebx, length 4.
10074Symbol nline is a local variable in register $edx, length 4.
10075Symbol repeat is a local variable at frame offset -8, length 4.
10076@end smallexample
10077
f5c37c66
EZ
10078@noindent
10079This command is especially useful for determining what data to collect
10080during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
10081collect}.
10082
c906108c
SS
10083@kindex info source
10084@item info source
919d772c
JB
10085Show information about the current source file---that is, the source file for
10086the function containing the current point of execution:
10087@itemize @bullet
10088@item
10089the name of the source file, and the directory containing it,
10090@item
10091the directory it was compiled in,
10092@item
10093its length, in lines,
10094@item
10095which programming language it is written in,
10096@item
10097whether the executable includes debugging information for that file, and
10098if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
10099@item
10100whether the debugging information includes information about
10101preprocessor macros.
10102@end itemize
10103
c906108c
SS
10104
10105@kindex info sources
10106@item info sources
10107Print the names of all source files in your program for which there is
10108debugging information, organized into two lists: files whose symbols
10109have already been read, and files whose symbols will be read when needed.
10110
10111@kindex info functions
10112@item info functions
10113Print the names and data types of all defined functions.
10114
10115@item info functions @var{regexp}
10116Print the names and data types of all defined functions
10117whose names contain a match for regular expression @var{regexp}.
10118Thus, @samp{info fun step} finds all functions whose names
10119include @code{step}; @samp{info fun ^step} finds those whose names
b383017d
RM
10120start with @code{step}. If a function name contains characters
10121that conflict with the regular expression language (eg.
1c5dfdad 10122@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
10123
10124@kindex info variables
10125@item info variables
10126Print the names and data types of all variables that are declared
6ca652b0 10127outside of functions (i.e.@: excluding local variables).
c906108c
SS
10128
10129@item info variables @var{regexp}
10130Print the names and data types of all variables (except for local
10131variables) whose names contain a match for regular expression
10132@var{regexp}.
10133
b37303ee 10134@kindex info classes
721c2651 10135@cindex Objective-C, classes and selectors
b37303ee
AF
10136@item info classes
10137@itemx info classes @var{regexp}
10138Display all Objective-C classes in your program, or
10139(with the @var{regexp} argument) all those matching a particular regular
10140expression.
10141
10142@kindex info selectors
10143@item info selectors
10144@itemx info selectors @var{regexp}
10145Display all Objective-C selectors in your program, or
10146(with the @var{regexp} argument) all those matching a particular regular
10147expression.
10148
c906108c
SS
10149@ignore
10150This was never implemented.
10151@kindex info methods
10152@item info methods
10153@itemx info methods @var{regexp}
10154The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
10155methods within C@t{++} program, or (with the @var{regexp} argument) a
10156specific set of methods found in the various C@t{++} classes. Many
10157C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
10158from the @code{ptype} command can be overwhelming and hard to use. The
10159@code{info-methods} command filters the methods, printing only those
10160which match the regular-expression @var{regexp}.
10161@end ignore
10162
c906108c
SS
10163@cindex reloading symbols
10164Some systems allow individual object files that make up your program to
7a292a7a
SS
10165be replaced without stopping and restarting your program. For example,
10166in VxWorks you can simply recompile a defective object file and keep on
10167running. If you are running on one of these systems, you can allow
10168@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
10169
10170@table @code
10171@kindex set symbol-reloading
10172@item set symbol-reloading on
10173Replace symbol definitions for the corresponding source file when an
10174object file with a particular name is seen again.
10175
10176@item set symbol-reloading off
6d2ebf8b
SS
10177Do not replace symbol definitions when encountering object files of the
10178same name more than once. This is the default state; if you are not
10179running on a system that permits automatic relinking of modules, you
10180should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
10181may discard symbols when linking large programs, that may contain
10182several modules (from different directories or libraries) with the same
10183name.
c906108c
SS
10184
10185@kindex show symbol-reloading
10186@item show symbol-reloading
10187Show the current @code{on} or @code{off} setting.
10188@end table
c906108c 10189
9c16f35a 10190@cindex opaque data types
c906108c
SS
10191@kindex set opaque-type-resolution
10192@item set opaque-type-resolution on
10193Tell @value{GDBN} to resolve opaque types. An opaque type is a type
10194declared as a pointer to a @code{struct}, @code{class}, or
10195@code{union}---for example, @code{struct MyType *}---that is used in one
10196source file although the full declaration of @code{struct MyType} is in
10197another source file. The default is on.
10198
10199A change in the setting of this subcommand will not take effect until
10200the next time symbols for a file are loaded.
10201
10202@item set opaque-type-resolution off
10203Tell @value{GDBN} not to resolve opaque types. In this case, the type
10204is printed as follows:
10205@smallexample
10206@{<no data fields>@}
10207@end smallexample
10208
10209@kindex show opaque-type-resolution
10210@item show opaque-type-resolution
10211Show whether opaque types are resolved or not.
c906108c
SS
10212
10213@kindex maint print symbols
10214@cindex symbol dump
10215@kindex maint print psymbols
10216@cindex partial symbol dump
10217@item maint print symbols @var{filename}
10218@itemx maint print psymbols @var{filename}
10219@itemx maint print msymbols @var{filename}
10220Write a dump of debugging symbol data into the file @var{filename}.
10221These commands are used to debug the @value{GDBN} symbol-reading code. Only
10222symbols with debugging data are included. If you use @samp{maint print
10223symbols}, @value{GDBN} includes all the symbols for which it has already
10224collected full details: that is, @var{filename} reflects symbols for
10225only those files whose symbols @value{GDBN} has read. You can use the
10226command @code{info sources} to find out which files these are. If you
10227use @samp{maint print psymbols} instead, the dump shows information about
10228symbols that @value{GDBN} only knows partially---that is, symbols defined in
10229files that @value{GDBN} has skimmed, but not yet read completely. Finally,
10230@samp{maint print msymbols} dumps just the minimal symbol information
10231required for each object file from which @value{GDBN} has read some symbols.
10232@xref{Files, ,Commands to specify files}, for a discussion of how
10233@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 10234
5e7b2f39
JB
10235@kindex maint info symtabs
10236@kindex maint info psymtabs
44ea7b70
JB
10237@cindex listing @value{GDBN}'s internal symbol tables
10238@cindex symbol tables, listing @value{GDBN}'s internal
10239@cindex full symbol tables, listing @value{GDBN}'s internal
10240@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
10241@item maint info symtabs @r{[} @var{regexp} @r{]}
10242@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
10243
10244List the @code{struct symtab} or @code{struct partial_symtab}
10245structures whose names match @var{regexp}. If @var{regexp} is not
10246given, list them all. The output includes expressions which you can
10247copy into a @value{GDBN} debugging this one to examine a particular
10248structure in more detail. For example:
10249
10250@smallexample
5e7b2f39 10251(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
10252@{ objfile /home/gnu/build/gdb/gdb
10253 ((struct objfile *) 0x82e69d0)
b383017d 10254 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10255 ((struct partial_symtab *) 0x8474b10)
10256 readin no
10257 fullname (null)
10258 text addresses 0x814d3c8 -- 0x8158074
10259 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
10260 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
10261 dependencies (none)
10262 @}
10263@}
5e7b2f39 10264(@value{GDBP}) maint info symtabs
44ea7b70
JB
10265(@value{GDBP})
10266@end smallexample
10267@noindent
10268We see that there is one partial symbol table whose filename contains
10269the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
10270and we see that @value{GDBN} has not read in any symtabs yet at all.
10271If we set a breakpoint on a function, that will cause @value{GDBN} to
10272read the symtab for the compilation unit containing that function:
10273
10274@smallexample
10275(@value{GDBP}) break dwarf2_psymtab_to_symtab
10276Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
10277line 1574.
5e7b2f39 10278(@value{GDBP}) maint info symtabs
b383017d 10279@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 10280 ((struct objfile *) 0x82e69d0)
b383017d 10281 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10282 ((struct symtab *) 0x86c1f38)
10283 dirname (null)
10284 fullname (null)
10285 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
10286 debugformat DWARF 2
10287 @}
10288@}
b383017d 10289(@value{GDBP})
44ea7b70 10290@end smallexample
c906108c
SS
10291@end table
10292
44ea7b70 10293
6d2ebf8b 10294@node Altering
c906108c
SS
10295@chapter Altering Execution
10296
10297Once you think you have found an error in your program, you might want to
10298find out for certain whether correcting the apparent error would lead to
10299correct results in the rest of the run. You can find the answer by
10300experiment, using the @value{GDBN} features for altering execution of the
10301program.
10302
10303For example, you can store new values into variables or memory
7a292a7a
SS
10304locations, give your program a signal, restart it at a different
10305address, or even return prematurely from a function.
c906108c
SS
10306
10307@menu
10308* Assignment:: Assignment to variables
10309* Jumping:: Continuing at a different address
c906108c 10310* Signaling:: Giving your program a signal
c906108c
SS
10311* Returning:: Returning from a function
10312* Calling:: Calling your program's functions
10313* Patching:: Patching your program
10314@end menu
10315
6d2ebf8b 10316@node Assignment
c906108c
SS
10317@section Assignment to variables
10318
10319@cindex assignment
10320@cindex setting variables
10321To alter the value of a variable, evaluate an assignment expression.
10322@xref{Expressions, ,Expressions}. For example,
10323
474c8240 10324@smallexample
c906108c 10325print x=4
474c8240 10326@end smallexample
c906108c
SS
10327
10328@noindent
10329stores the value 4 into the variable @code{x}, and then prints the
5d161b24 10330value of the assignment expression (which is 4).
c906108c
SS
10331@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
10332information on operators in supported languages.
c906108c
SS
10333
10334@kindex set variable
10335@cindex variables, setting
10336If you are not interested in seeing the value of the assignment, use the
10337@code{set} command instead of the @code{print} command. @code{set} is
10338really the same as @code{print} except that the expression's value is
10339not printed and is not put in the value history (@pxref{Value History,
10340,Value history}). The expression is evaluated only for its effects.
10341
c906108c
SS
10342If the beginning of the argument string of the @code{set} command
10343appears identical to a @code{set} subcommand, use the @code{set
10344variable} command instead of just @code{set}. This command is identical
10345to @code{set} except for its lack of subcommands. For example, if your
10346program has a variable @code{width}, you get an error if you try to set
10347a new value with just @samp{set width=13}, because @value{GDBN} has the
10348command @code{set width}:
10349
474c8240 10350@smallexample
c906108c
SS
10351(@value{GDBP}) whatis width
10352type = double
10353(@value{GDBP}) p width
10354$4 = 13
10355(@value{GDBP}) set width=47
10356Invalid syntax in expression.
474c8240 10357@end smallexample
c906108c
SS
10358
10359@noindent
10360The invalid expression, of course, is @samp{=47}. In
10361order to actually set the program's variable @code{width}, use
10362
474c8240 10363@smallexample
c906108c 10364(@value{GDBP}) set var width=47
474c8240 10365@end smallexample
53a5351d 10366
c906108c
SS
10367Because the @code{set} command has many subcommands that can conflict
10368with the names of program variables, it is a good idea to use the
10369@code{set variable} command instead of just @code{set}. For example, if
10370your program has a variable @code{g}, you run into problems if you try
10371to set a new value with just @samp{set g=4}, because @value{GDBN} has
10372the command @code{set gnutarget}, abbreviated @code{set g}:
10373
474c8240 10374@smallexample
c906108c
SS
10375@group
10376(@value{GDBP}) whatis g
10377type = double
10378(@value{GDBP}) p g
10379$1 = 1
10380(@value{GDBP}) set g=4
2df3850c 10381(@value{GDBP}) p g
c906108c
SS
10382$2 = 1
10383(@value{GDBP}) r
10384The program being debugged has been started already.
10385Start it from the beginning? (y or n) y
10386Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
10387"/home/smith/cc_progs/a.out": can't open to read symbols:
10388 Invalid bfd target.
c906108c
SS
10389(@value{GDBP}) show g
10390The current BFD target is "=4".
10391@end group
474c8240 10392@end smallexample
c906108c
SS
10393
10394@noindent
10395The program variable @code{g} did not change, and you silently set the
10396@code{gnutarget} to an invalid value. In order to set the variable
10397@code{g}, use
10398
474c8240 10399@smallexample
c906108c 10400(@value{GDBP}) set var g=4
474c8240 10401@end smallexample
c906108c
SS
10402
10403@value{GDBN} allows more implicit conversions in assignments than C; you can
10404freely store an integer value into a pointer variable or vice versa,
10405and you can convert any structure to any other structure that is the
10406same length or shorter.
10407@comment FIXME: how do structs align/pad in these conversions?
10408@comment /doc@cygnus.com 18dec1990
10409
10410To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
10411construct to generate a value of specified type at a specified address
10412(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
10413to memory location @code{0x83040} as an integer (which implies a certain size
10414and representation in memory), and
10415
474c8240 10416@smallexample
c906108c 10417set @{int@}0x83040 = 4
474c8240 10418@end smallexample
c906108c
SS
10419
10420@noindent
10421stores the value 4 into that memory location.
10422
6d2ebf8b 10423@node Jumping
c906108c
SS
10424@section Continuing at a different address
10425
10426Ordinarily, when you continue your program, you do so at the place where
10427it stopped, with the @code{continue} command. You can instead continue at
10428an address of your own choosing, with the following commands:
10429
10430@table @code
10431@kindex jump
10432@item jump @var{linespec}
10433Resume execution at line @var{linespec}. Execution stops again
10434immediately if there is a breakpoint there. @xref{List, ,Printing
10435source lines}, for a description of the different forms of
10436@var{linespec}. It is common practice to use the @code{tbreak} command
10437in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
10438breakpoints}.
10439
10440The @code{jump} command does not change the current stack frame, or
10441the stack pointer, or the contents of any memory location or any
10442register other than the program counter. If line @var{linespec} is in
10443a different function from the one currently executing, the results may
10444be bizarre if the two functions expect different patterns of arguments or
10445of local variables. For this reason, the @code{jump} command requests
10446confirmation if the specified line is not in the function currently
10447executing. However, even bizarre results are predictable if you are
10448well acquainted with the machine-language code of your program.
10449
10450@item jump *@var{address}
10451Resume execution at the instruction at address @var{address}.
10452@end table
10453
c906108c 10454@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
10455On many systems, you can get much the same effect as the @code{jump}
10456command by storing a new value into the register @code{$pc}. The
10457difference is that this does not start your program running; it only
10458changes the address of where it @emph{will} run when you continue. For
10459example,
c906108c 10460
474c8240 10461@smallexample
c906108c 10462set $pc = 0x485
474c8240 10463@end smallexample
c906108c
SS
10464
10465@noindent
10466makes the next @code{continue} command or stepping command execute at
10467address @code{0x485}, rather than at the address where your program stopped.
10468@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
10469
10470The most common occasion to use the @code{jump} command is to back
10471up---perhaps with more breakpoints set---over a portion of a program
10472that has already executed, in order to examine its execution in more
10473detail.
10474
c906108c 10475@c @group
6d2ebf8b 10476@node Signaling
c906108c 10477@section Giving your program a signal
9c16f35a 10478@cindex deliver a signal to a program
c906108c
SS
10479
10480@table @code
10481@kindex signal
10482@item signal @var{signal}
10483Resume execution where your program stopped, but immediately give it the
10484signal @var{signal}. @var{signal} can be the name or the number of a
10485signal. For example, on many systems @code{signal 2} and @code{signal
10486SIGINT} are both ways of sending an interrupt signal.
10487
10488Alternatively, if @var{signal} is zero, continue execution without
10489giving a signal. This is useful when your program stopped on account of
10490a signal and would ordinary see the signal when resumed with the
10491@code{continue} command; @samp{signal 0} causes it to resume without a
10492signal.
10493
10494@code{signal} does not repeat when you press @key{RET} a second time
10495after executing the command.
10496@end table
10497@c @end group
10498
10499Invoking the @code{signal} command is not the same as invoking the
10500@code{kill} utility from the shell. Sending a signal with @code{kill}
10501causes @value{GDBN} to decide what to do with the signal depending on
10502the signal handling tables (@pxref{Signals}). The @code{signal} command
10503passes the signal directly to your program.
10504
c906108c 10505
6d2ebf8b 10506@node Returning
c906108c
SS
10507@section Returning from a function
10508
10509@table @code
10510@cindex returning from a function
10511@kindex return
10512@item return
10513@itemx return @var{expression}
10514You can cancel execution of a function call with the @code{return}
10515command. If you give an
10516@var{expression} argument, its value is used as the function's return
10517value.
10518@end table
10519
10520When you use @code{return}, @value{GDBN} discards the selected stack frame
10521(and all frames within it). You can think of this as making the
10522discarded frame return prematurely. If you wish to specify a value to
10523be returned, give that value as the argument to @code{return}.
10524
10525This pops the selected stack frame (@pxref{Selection, ,Selecting a
10526frame}), and any other frames inside of it, leaving its caller as the
10527innermost remaining frame. That frame becomes selected. The
10528specified value is stored in the registers used for returning values
10529of functions.
10530
10531The @code{return} command does not resume execution; it leaves the
10532program stopped in the state that would exist if the function had just
10533returned. In contrast, the @code{finish} command (@pxref{Continuing
10534and Stepping, ,Continuing and stepping}) resumes execution until the
10535selected stack frame returns naturally.
10536
6d2ebf8b 10537@node Calling
c906108c
SS
10538@section Calling program functions
10539
f8568604 10540@table @code
c906108c 10541@cindex calling functions
f8568604
EZ
10542@cindex inferior functions, calling
10543@item print @var{expr}
9c16f35a 10544Evaluate the expression @var{expr} and display the resuling value.
f8568604
EZ
10545@var{expr} may include calls to functions in the program being
10546debugged.
10547
c906108c 10548@kindex call
c906108c
SS
10549@item call @var{expr}
10550Evaluate the expression @var{expr} without displaying @code{void}
10551returned values.
c906108c
SS
10552
10553You can use this variant of the @code{print} command if you want to
f8568604
EZ
10554execute a function from your program that does not return anything
10555(a.k.a.@: @dfn{a void function}), but without cluttering the output
10556with @code{void} returned values that @value{GDBN} will otherwise
10557print. If the result is not void, it is printed and saved in the
10558value history.
10559@end table
10560
9c16f35a
EZ
10561It is possible for the function you call via the @code{print} or
10562@code{call} command to generate a signal (e.g., if there's a bug in
10563the function, or if you passed it incorrect arguments). What happens
10564in that case is controlled by the @code{set unwindonsignal} command.
10565
10566@table @code
10567@item set unwindonsignal
10568@kindex set unwindonsignal
10569@cindex unwind stack in called functions
10570@cindex call dummy stack unwinding
10571Set unwinding of the stack if a signal is received while in a function
10572that @value{GDBN} called in the program being debugged. If set to on,
10573@value{GDBN} unwinds the stack it created for the call and restores
10574the context to what it was before the call. If set to off (the
10575default), @value{GDBN} stops in the frame where the signal was
10576received.
10577
10578@item show unwindonsignal
10579@kindex show unwindonsignal
10580Show the current setting of stack unwinding in the functions called by
10581@value{GDBN}.
10582@end table
10583
f8568604
EZ
10584@cindex weak alias functions
10585Sometimes, a function you wish to call is actually a @dfn{weak alias}
10586for another function. In such case, @value{GDBN} might not pick up
10587the type information, including the types of the function arguments,
10588which causes @value{GDBN} to call the inferior function incorrectly.
10589As a result, the called function will function erroneously and may
10590even crash. A solution to that is to use the name of the aliased
10591function instead.
c906108c 10592
6d2ebf8b 10593@node Patching
c906108c 10594@section Patching programs
7a292a7a 10595
c906108c
SS
10596@cindex patching binaries
10597@cindex writing into executables
c906108c 10598@cindex writing into corefiles
c906108c 10599
7a292a7a
SS
10600By default, @value{GDBN} opens the file containing your program's
10601executable code (or the corefile) read-only. This prevents accidental
10602alterations to machine code; but it also prevents you from intentionally
10603patching your program's binary.
c906108c
SS
10604
10605If you'd like to be able to patch the binary, you can specify that
10606explicitly with the @code{set write} command. For example, you might
10607want to turn on internal debugging flags, or even to make emergency
10608repairs.
10609
10610@table @code
10611@kindex set write
10612@item set write on
10613@itemx set write off
7a292a7a
SS
10614If you specify @samp{set write on}, @value{GDBN} opens executable and
10615core files for both reading and writing; if you specify @samp{set write
c906108c
SS
10616off} (the default), @value{GDBN} opens them read-only.
10617
10618If you have already loaded a file, you must load it again (using the
7a292a7a
SS
10619@code{exec-file} or @code{core-file} command) after changing @code{set
10620write}, for your new setting to take effect.
c906108c
SS
10621
10622@item show write
10623@kindex show write
7a292a7a
SS
10624Display whether executable files and core files are opened for writing
10625as well as reading.
c906108c
SS
10626@end table
10627
6d2ebf8b 10628@node GDB Files
c906108c
SS
10629@chapter @value{GDBN} Files
10630
7a292a7a
SS
10631@value{GDBN} needs to know the file name of the program to be debugged,
10632both in order to read its symbol table and in order to start your
10633program. To debug a core dump of a previous run, you must also tell
10634@value{GDBN} the name of the core dump file.
c906108c
SS
10635
10636@menu
10637* Files:: Commands to specify files
5b5d99cf 10638* Separate Debug Files:: Debugging information in separate files
c906108c
SS
10639* Symbol Errors:: Errors reading symbol files
10640@end menu
10641
6d2ebf8b 10642@node Files
c906108c 10643@section Commands to specify files
c906108c 10644
7a292a7a 10645@cindex symbol table
c906108c 10646@cindex core dump file
7a292a7a
SS
10647
10648You may want to specify executable and core dump file names. The usual
10649way to do this is at start-up time, using the arguments to
10650@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
10651Out of @value{GDBN}}).
c906108c
SS
10652
10653Occasionally it is necessary to change to a different file during a
397ca115
EZ
10654@value{GDBN} session. Or you may run @value{GDBN} and forget to
10655specify a file you want to use. Or you are debugging a remote target
10656via @code{gdbserver} (@pxref{Server, file}). In these situations the
10657@value{GDBN} commands to specify new files are useful.
c906108c
SS
10658
10659@table @code
10660@cindex executable file
10661@kindex file
10662@item file @var{filename}
10663Use @var{filename} as the program to be debugged. It is read for its
10664symbols and for the contents of pure memory. It is also the program
10665executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
10666directory and the file is not found in the @value{GDBN} working directory,
10667@value{GDBN} uses the environment variable @code{PATH} as a list of
10668directories to search, just as the shell does when looking for a program
10669to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
10670and your program, using the @code{path} command.
10671
6d2ebf8b 10672On systems with memory-mapped files, an auxiliary file named
c906108c
SS
10673@file{@var{filename}.syms} may hold symbol table information for
10674@var{filename}. If so, @value{GDBN} maps in the symbol table from
10675@file{@var{filename}.syms}, starting up more quickly. See the
10676descriptions of the file options @samp{-mapped} and @samp{-readnow}
7b5ba0cc
EZ
10677(available on the command line, see @ref{File Options, , -readnow},
10678and with the commands @code{file}, @code{symbol-file}, or
10679@code{add-symbol-file}, described below), for more information.
c906108c 10680
fc8be69e
EZ
10681@cindex unlinked object files
10682@cindex patching object files
10683You can load unlinked object @file{.o} files into @value{GDBN} using
10684the @code{file} command. You will not be able to ``run'' an object
10685file, but you can disassemble functions and inspect variables. Also,
10686if the underlying BFD functionality supports it, you could use
10687@kbd{gdb -write} to patch object files using this technique. Note
10688that @value{GDBN} can neither interpret nor modify relocations in this
10689case, so branches and some initialized variables will appear to go to
10690the wrong place. But this feature is still handy from time to time.
10691
c906108c
SS
10692@item file
10693@code{file} with no argument makes @value{GDBN} discard any information it
10694has on both executable file and the symbol table.
10695
10696@kindex exec-file
10697@item exec-file @r{[} @var{filename} @r{]}
10698Specify that the program to be run (but not the symbol table) is found
10699in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
10700if necessary to locate your program. Omitting @var{filename} means to
10701discard information on the executable file.
10702
10703@kindex symbol-file
10704@item symbol-file @r{[} @var{filename} @r{]}
10705Read symbol table information from file @var{filename}. @code{PATH} is
10706searched when necessary. Use the @code{file} command to get both symbol
10707table and program to run from the same file.
10708
10709@code{symbol-file} with no argument clears out @value{GDBN} information on your
10710program's symbol table.
10711
5d161b24 10712The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
10713of its convenience variables, the value history, and all breakpoints and
10714auto-display expressions. This is because they may contain pointers to
10715the internal data recording symbols and data types, which are part of
10716the old symbol table data being discarded inside @value{GDBN}.
10717
10718@code{symbol-file} does not repeat if you press @key{RET} again after
10719executing it once.
10720
10721When @value{GDBN} is configured for a particular environment, it
10722understands debugging information in whatever format is the standard
10723generated for that environment; you may use either a @sc{gnu} compiler, or
10724other compilers that adhere to the local conventions.
c906108c
SS
10725Best results are usually obtained from @sc{gnu} compilers; for example,
10726using @code{@value{GCC}} you can generate debugging information for
10727optimized code.
c906108c
SS
10728
10729For most kinds of object files, with the exception of old SVR3 systems
10730using COFF, the @code{symbol-file} command does not normally read the
10731symbol table in full right away. Instead, it scans the symbol table
10732quickly to find which source files and which symbols are present. The
10733details are read later, one source file at a time, as they are needed.
10734
10735The purpose of this two-stage reading strategy is to make @value{GDBN}
10736start up faster. For the most part, it is invisible except for
10737occasional pauses while the symbol table details for a particular source
10738file are being read. (The @code{set verbose} command can turn these
10739pauses into messages if desired. @xref{Messages/Warnings, ,Optional
10740warnings and messages}.)
10741
c906108c
SS
10742We have not implemented the two-stage strategy for COFF yet. When the
10743symbol table is stored in COFF format, @code{symbol-file} reads the
10744symbol table data in full right away. Note that ``stabs-in-COFF''
10745still does the two-stage strategy, since the debug info is actually
10746in stabs format.
10747
10748@kindex readnow
10749@cindex reading symbols immediately
10750@cindex symbols, reading immediately
10751@kindex mapped
10752@cindex memory-mapped symbol file
10753@cindex saving symbol table
10754@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10755@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10756You can override the @value{GDBN} two-stage strategy for reading symbol
10757tables by using the @samp{-readnow} option with any of the commands that
10758load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 10759entire symbol table available.
c906108c 10760
c906108c
SS
10761If memory-mapped files are available on your system through the
10762@code{mmap} system call, you can use another option, @samp{-mapped}, to
10763cause @value{GDBN} to write the symbols for your program into a reusable
10764file. Future @value{GDBN} debugging sessions map in symbol information
10765from this auxiliary symbol file (if the program has not changed), rather
10766than spending time reading the symbol table from the executable
10767program. Using the @samp{-mapped} option has the same effect as
10768starting @value{GDBN} with the @samp{-mapped} command-line option.
10769
10770You can use both options together, to make sure the auxiliary symbol
10771file has all the symbol information for your program.
10772
10773The auxiliary symbol file for a program called @var{myprog} is called
10774@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
10775than the corresponding executable), @value{GDBN} always attempts to use
10776it when you debug @var{myprog}; no special options or commands are
10777needed.
10778
10779The @file{.syms} file is specific to the host machine where you run
10780@value{GDBN}. It holds an exact image of the internal @value{GDBN}
10781symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
10782
10783@c FIXME: for now no mention of directories, since this seems to be in
10784@c flux. 13mar1992 status is that in theory GDB would look either in
10785@c current dir or in same dir as myprog; but issues like competing
10786@c GDB's, or clutter in system dirs, mean that in practice right now
10787@c only current dir is used. FFish says maybe a special GDB hierarchy
10788@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
10789@c files.
10790
c906108c 10791@kindex core-file
09d4efe1 10792@item core-file @r{[}@var{filename}@r{]}
4644b6e3 10793@itemx core
c906108c
SS
10794Specify the whereabouts of a core dump file to be used as the ``contents
10795of memory''. Traditionally, core files contain only some parts of the
10796address space of the process that generated them; @value{GDBN} can access the
10797executable file itself for other parts.
10798
10799@code{core-file} with no argument specifies that no core file is
10800to be used.
10801
10802Note that the core file is ignored when your program is actually running
7a292a7a
SS
10803under @value{GDBN}. So, if you have been running your program and you
10804wish to debug a core file instead, you must kill the subprocess in which
10805the program is running. To do this, use the @code{kill} command
c906108c 10806(@pxref{Kill Process, ,Killing the child process}).
c906108c 10807
c906108c
SS
10808@kindex add-symbol-file
10809@cindex dynamic linking
10810@item add-symbol-file @var{filename} @var{address}
10811@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
17d9d558 10812@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
10813The @code{add-symbol-file} command reads additional symbol table
10814information from the file @var{filename}. You would use this command
10815when @var{filename} has been dynamically loaded (by some other means)
10816into the program that is running. @var{address} should be the memory
10817address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
10818this out for itself. You can additionally specify an arbitrary number
10819of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
10820section name and base address for that section. You can specify any
10821@var{address} as an expression.
c906108c
SS
10822
10823The symbol table of the file @var{filename} is added to the symbol table
10824originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
10825@code{add-symbol-file} command any number of times; the new symbol data
10826thus read keeps adding to the old. To discard all old symbol data
10827instead, use the @code{symbol-file} command without any arguments.
c906108c 10828
17d9d558
JB
10829@cindex relocatable object files, reading symbols from
10830@cindex object files, relocatable, reading symbols from
10831@cindex reading symbols from relocatable object files
10832@cindex symbols, reading from relocatable object files
10833@cindex @file{.o} files, reading symbols from
10834Although @var{filename} is typically a shared library file, an
10835executable file, or some other object file which has been fully
10836relocated for loading into a process, you can also load symbolic
10837information from relocatable @file{.o} files, as long as:
10838
10839@itemize @bullet
10840@item
10841the file's symbolic information refers only to linker symbols defined in
10842that file, not to symbols defined by other object files,
10843@item
10844every section the file's symbolic information refers to has actually
10845been loaded into the inferior, as it appears in the file, and
10846@item
10847you can determine the address at which every section was loaded, and
10848provide these to the @code{add-symbol-file} command.
10849@end itemize
10850
10851@noindent
10852Some embedded operating systems, like Sun Chorus and VxWorks, can load
10853relocatable files into an already running program; such systems
10854typically make the requirements above easy to meet. However, it's
10855important to recognize that many native systems use complex link
49efadf5 10856procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
10857assembly, for example) that make the requirements difficult to meet. In
10858general, one cannot assume that using @code{add-symbol-file} to read a
10859relocatable object file's symbolic information will have the same effect
10860as linking the relocatable object file into the program in the normal
10861way.
10862
c906108c
SS
10863@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
10864
10865You can use the @samp{-mapped} and @samp{-readnow} options just as with
10866the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
10867table information for @var{filename}.
10868
c45da7e6
EZ
10869@kindex add-symbol-file-from-memory
10870@cindex @code{syscall DSO}
10871@cindex load symbols from memory
10872@item add-symbol-file-from-memory @var{address}
10873Load symbols from the given @var{address} in a dynamically loaded
10874object file whose image is mapped directly into the inferior's memory.
10875For example, the Linux kernel maps a @code{syscall DSO} into each
10876process's address space; this DSO provides kernel-specific code for
10877some system calls. The argument can be any expression whose
10878evaluation yields the address of the file's shared object file header.
10879For this command to work, you must have used @code{symbol-file} or
10880@code{exec-file} commands in advance.
10881
09d4efe1
EZ
10882@kindex add-shared-symbol-files
10883@kindex assf
10884@item add-shared-symbol-files @var{library-file}
10885@itemx assf @var{library-file}
10886The @code{add-shared-symbol-files} command can currently be used only
10887in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
10888alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
10889@value{GDBN} automatically looks for shared libraries, however if
10890@value{GDBN} does not find yours, you can invoke
10891@code{add-shared-symbol-files}. It takes one argument: the shared
10892library's file name. @code{assf} is a shorthand alias for
10893@code{add-shared-symbol-files}.
c906108c 10894
c906108c 10895@kindex section
09d4efe1
EZ
10896@item section @var{section} @var{addr}
10897The @code{section} command changes the base address of the named
10898@var{section} of the exec file to @var{addr}. This can be used if the
10899exec file does not contain section addresses, (such as in the
10900@code{a.out} format), or when the addresses specified in the file
10901itself are wrong. Each section must be changed separately. The
10902@code{info files} command, described below, lists all the sections and
10903their addresses.
c906108c
SS
10904
10905@kindex info files
10906@kindex info target
10907@item info files
10908@itemx info target
7a292a7a
SS
10909@code{info files} and @code{info target} are synonymous; both print the
10910current target (@pxref{Targets, ,Specifying a Debugging Target}),
10911including the names of the executable and core dump files currently in
10912use by @value{GDBN}, and the files from which symbols were loaded. The
10913command @code{help target} lists all possible targets rather than
10914current ones.
10915
fe95c787
MS
10916@kindex maint info sections
10917@item maint info sections
10918Another command that can give you extra information about program sections
10919is @code{maint info sections}. In addition to the section information
10920displayed by @code{info files}, this command displays the flags and file
10921offset of each section in the executable and core dump files. In addition,
10922@code{maint info sections} provides the following command options (which
10923may be arbitrarily combined):
10924
10925@table @code
10926@item ALLOBJ
10927Display sections for all loaded object files, including shared libraries.
10928@item @var{sections}
6600abed 10929Display info only for named @var{sections}.
fe95c787
MS
10930@item @var{section-flags}
10931Display info only for sections for which @var{section-flags} are true.
10932The section flags that @value{GDBN} currently knows about are:
10933@table @code
10934@item ALLOC
10935Section will have space allocated in the process when loaded.
10936Set for all sections except those containing debug information.
10937@item LOAD
10938Section will be loaded from the file into the child process memory.
10939Set for pre-initialized code and data, clear for @code{.bss} sections.
10940@item RELOC
10941Section needs to be relocated before loading.
10942@item READONLY
10943Section cannot be modified by the child process.
10944@item CODE
10945Section contains executable code only.
6600abed 10946@item DATA
fe95c787
MS
10947Section contains data only (no executable code).
10948@item ROM
10949Section will reside in ROM.
10950@item CONSTRUCTOR
10951Section contains data for constructor/destructor lists.
10952@item HAS_CONTENTS
10953Section is not empty.
10954@item NEVER_LOAD
10955An instruction to the linker to not output the section.
10956@item COFF_SHARED_LIBRARY
10957A notification to the linker that the section contains
10958COFF shared library information.
10959@item IS_COMMON
10960Section contains common symbols.
10961@end table
10962@end table
6763aef9 10963@kindex set trust-readonly-sections
9c16f35a 10964@cindex read-only sections
6763aef9
MS
10965@item set trust-readonly-sections on
10966Tell @value{GDBN} that readonly sections in your object file
6ca652b0 10967really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
10968In that case, @value{GDBN} can fetch values from these sections
10969out of the object file, rather than from the target program.
10970For some targets (notably embedded ones), this can be a significant
10971enhancement to debugging performance.
10972
10973The default is off.
10974
10975@item set trust-readonly-sections off
15110bc3 10976Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
10977the contents of the section might change while the program is running,
10978and must therefore be fetched from the target when needed.
9c16f35a
EZ
10979
10980@item show trust-readonly-sections
10981Show the current setting of trusting readonly sections.
c906108c
SS
10982@end table
10983
10984All file-specifying commands allow both absolute and relative file names
10985as arguments. @value{GDBN} always converts the file name to an absolute file
10986name and remembers it that way.
10987
c906108c 10988@cindex shared libraries
9c16f35a
EZ
10989@value{GDBN} supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
10990and IBM RS/6000 AIX shared libraries.
53a5351d 10991
c906108c
SS
10992@value{GDBN} automatically loads symbol definitions from shared libraries
10993when you use the @code{run} command, or when you examine a core file.
10994(Before you issue the @code{run} command, @value{GDBN} does not understand
10995references to a function in a shared library, however---unless you are
10996debugging a core file).
53a5351d
JM
10997
10998On HP-UX, if the program loads a library explicitly, @value{GDBN}
10999automatically loads the symbols at the time of the @code{shl_load} call.
11000
c906108c
SS
11001@c FIXME: some @value{GDBN} release may permit some refs to undef
11002@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
11003@c FIXME...lib; check this from time to time when updating manual
11004
b7209cb4
FF
11005There are times, however, when you may wish to not automatically load
11006symbol definitions from shared libraries, such as when they are
11007particularly large or there are many of them.
11008
11009To control the automatic loading of shared library symbols, use the
11010commands:
11011
11012@table @code
11013@kindex set auto-solib-add
11014@item set auto-solib-add @var{mode}
11015If @var{mode} is @code{on}, symbols from all shared object libraries
11016will be loaded automatically when the inferior begins execution, you
11017attach to an independently started inferior, or when the dynamic linker
11018informs @value{GDBN} that a new library has been loaded. If @var{mode}
11019is @code{off}, symbols must be loaded manually, using the
11020@code{sharedlibrary} command. The default value is @code{on}.
11021
dcaf7c2c
EZ
11022@cindex memory used for symbol tables
11023If your program uses lots of shared libraries with debug info that
11024takes large amounts of memory, you can decrease the @value{GDBN}
11025memory footprint by preventing it from automatically loading the
11026symbols from shared libraries. To that end, type @kbd{set
11027auto-solib-add off} before running the inferior, then load each
11028library whose debug symbols you do need with @kbd{sharedlibrary
11029@var{regexp}}, where @var{regexp} is a regular expresion that matches
11030the libraries whose symbols you want to be loaded.
11031
b7209cb4
FF
11032@kindex show auto-solib-add
11033@item show auto-solib-add
11034Display the current autoloading mode.
11035@end table
11036
c45da7e6 11037@cindex load shared library
b7209cb4
FF
11038To explicitly load shared library symbols, use the @code{sharedlibrary}
11039command:
11040
c906108c
SS
11041@table @code
11042@kindex info sharedlibrary
11043@kindex info share
11044@item info share
11045@itemx info sharedlibrary
11046Print the names of the shared libraries which are currently loaded.
11047
11048@kindex sharedlibrary
11049@kindex share
11050@item sharedlibrary @var{regex}
11051@itemx share @var{regex}
c906108c
SS
11052Load shared object library symbols for files matching a
11053Unix regular expression.
11054As with files loaded automatically, it only loads shared libraries
11055required by your program for a core file or after typing @code{run}. If
11056@var{regex} is omitted all shared libraries required by your program are
11057loaded.
c45da7e6
EZ
11058
11059@item nosharedlibrary
11060@kindex nosharedlibrary
11061@cindex unload symbols from shared libraries
11062Unload all shared object library symbols. This discards all symbols
11063that have been loaded from all shared libraries. Symbols from shared
11064libraries that were loaded by explicit user requests are not
11065discarded.
c906108c
SS
11066@end table
11067
721c2651
EZ
11068Sometimes you may wish that @value{GDBN} stops and gives you control
11069when any of shared library events happen. Use the @code{set
11070stop-on-solib-events} command for this:
11071
11072@table @code
11073@item set stop-on-solib-events
11074@kindex set stop-on-solib-events
11075This command controls whether @value{GDBN} should give you control
11076when the dynamic linker notifies it about some shared library event.
11077The most common event of interest is loading or unloading of a new
11078shared library.
11079
11080@item show stop-on-solib-events
11081@kindex show stop-on-solib-events
11082Show whether @value{GDBN} stops and gives you control when shared
11083library events happen.
11084@end table
11085
f5ebfba0
DJ
11086Shared libraries are also supported in many cross or remote debugging
11087configurations. A copy of the target's libraries need to be present on the
11088host system; they need to be the same as the target libraries, although the
11089copies on the target can be stripped as long as the copies on the host are
11090not.
11091
59b7b46f
EZ
11092@cindex where to look for shared libraries
11093For remote debugging, you need to tell @value{GDBN} where the target
11094libraries are, so that it can load the correct copies---otherwise, it
11095may try to load the host's libraries. @value{GDBN} has two variables
11096to specify the search directories for target libraries.
f5ebfba0
DJ
11097
11098@table @code
59b7b46f 11099@cindex prefix for shared library file names
f5ebfba0
DJ
11100@kindex set solib-absolute-prefix
11101@item set solib-absolute-prefix @var{path}
11102If this variable is set, @var{path} will be used as a prefix for any
11103absolute shared library paths; many runtime loaders store the absolute
11104paths to the shared library in the target program's memory. If you use
11105@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
11106out in the same way that they are on the target, with e.g.@: a
11107@file{/usr/lib} hierarchy under @var{path}.
11108
59b7b46f
EZ
11109@cindex default value of @samp{solib-absolute-prefix}
11110@cindex @samp{--with-sysroot}
f5ebfba0
DJ
11111You can set the default value of @samp{solib-absolute-prefix} by using the
11112configure-time @samp{--with-sysroot} option.
11113
11114@kindex show solib-absolute-prefix
11115@item show solib-absolute-prefix
11116Display the current shared library prefix.
11117
11118@kindex set solib-search-path
11119@item set solib-search-path @var{path}
11120If this variable is set, @var{path} is a colon-separated list of directories
11121to search for shared libraries. @samp{solib-search-path} is used after
11122@samp{solib-absolute-prefix} fails to locate the library, or if the path to
11123the library is relative instead of absolute. If you want to use
11124@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
11125set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
11126@value{GDBN} from finding your host's libraries.
11127
11128@kindex show solib-search-path
11129@item show solib-search-path
11130Display the current shared library search path.
11131@end table
11132
5b5d99cf
JB
11133
11134@node Separate Debug Files
11135@section Debugging Information in Separate Files
11136@cindex separate debugging information files
11137@cindex debugging information in separate files
11138@cindex @file{.debug} subdirectories
11139@cindex debugging information directory, global
11140@cindex global debugging information directory
11141
11142@value{GDBN} allows you to put a program's debugging information in a
11143file separate from the executable itself, in a way that allows
11144@value{GDBN} to find and load the debugging information automatically.
11145Since debugging information can be very large --- sometimes larger
11146than the executable code itself --- some systems distribute debugging
11147information for their executables in separate files, which users can
11148install only when they need to debug a problem.
11149
11150If an executable's debugging information has been extracted to a
11151separate file, the executable should contain a @dfn{debug link} giving
11152the name of the debugging information file (with no directory
11153components), and a checksum of its contents. (The exact form of a
11154debug link is described below.) If the full name of the directory
11155containing the executable is @var{execdir}, and the executable has a
11156debug link that specifies the name @var{debugfile}, then @value{GDBN}
11157will automatically search for the debugging information file in three
11158places:
11159
11160@itemize @bullet
11161@item
11162the directory containing the executable file (that is, it will look
11163for a file named @file{@var{execdir}/@var{debugfile}},
11164@item
11165a subdirectory of that directory named @file{.debug} (that is, the
11166file @file{@var{execdir}/.debug/@var{debugfile}}, and
11167@item
11168a subdirectory of the global debug file directory that includes the
11169executable's full path, and the name from the link (that is, the file
11170@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
11171@var{globaldebugdir} is the global debug file directory, and
11172@var{execdir} has been turned into a relative path).
11173@end itemize
11174@noindent
11175@value{GDBN} checks under each of these names for a debugging
11176information file whose checksum matches that given in the link, and
11177reads the debugging information from the first one it finds.
11178
11179So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
11180which has a link containing the name @file{ls.debug}, and the global
11181debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
11182for debug information in @file{/usr/bin/ls.debug},
11183@file{/usr/bin/.debug/ls.debug}, and
11184@file{/usr/lib/debug/usr/bin/ls.debug}.
11185
11186You can set the global debugging info directory's name, and view the
11187name @value{GDBN} is currently using.
11188
11189@table @code
11190
11191@kindex set debug-file-directory
11192@item set debug-file-directory @var{directory}
11193Set the directory which @value{GDBN} searches for separate debugging
11194information files to @var{directory}.
11195
11196@kindex show debug-file-directory
11197@item show debug-file-directory
11198Show the directory @value{GDBN} searches for separate debugging
11199information files.
11200
11201@end table
11202
11203@cindex @code{.gnu_debuglink} sections
11204@cindex debug links
11205A debug link is a special section of the executable file named
11206@code{.gnu_debuglink}. The section must contain:
11207
11208@itemize
11209@item
11210A filename, with any leading directory components removed, followed by
11211a zero byte,
11212@item
11213zero to three bytes of padding, as needed to reach the next four-byte
11214boundary within the section, and
11215@item
11216a four-byte CRC checksum, stored in the same endianness used for the
11217executable file itself. The checksum is computed on the debugging
11218information file's full contents by the function given below, passing
11219zero as the @var{crc} argument.
11220@end itemize
11221
11222Any executable file format can carry a debug link, as long as it can
11223contain a section named @code{.gnu_debuglink} with the contents
11224described above.
11225
11226The debugging information file itself should be an ordinary
11227executable, containing a full set of linker symbols, sections, and
11228debugging information. The sections of the debugging information file
11229should have the same names, addresses and sizes as the original file,
11230but they need not contain any data --- much like a @code{.bss} section
11231in an ordinary executable.
11232
11233As of December 2002, there is no standard GNU utility to produce
11234separated executable / debugging information file pairs. Ulrich
11235Drepper's @file{elfutils} package, starting with version 0.53,
11236contains a version of the @code{strip} command such that the command
11237@kbd{strip foo -f foo.debug} removes the debugging information from
11238the executable file @file{foo}, places it in the file
11239@file{foo.debug}, and leaves behind a debug link in @file{foo}.
11240
11241Since there are many different ways to compute CRC's (different
11242polynomials, reversals, byte ordering, etc.), the simplest way to
11243describe the CRC used in @code{.gnu_debuglink} sections is to give the
11244complete code for a function that computes it:
11245
4644b6e3 11246@kindex gnu_debuglink_crc32
5b5d99cf
JB
11247@smallexample
11248unsigned long
11249gnu_debuglink_crc32 (unsigned long crc,
11250 unsigned char *buf, size_t len)
11251@{
11252 static const unsigned long crc32_table[256] =
11253 @{
11254 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11255 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11256 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11257 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11258 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11259 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11260 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11261 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11262 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11263 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11264 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11265 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11266 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11267 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11268 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11269 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11270 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11271 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11272 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11273 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11274 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11275 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11276 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11277 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11278 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11279 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11280 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11281 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11282 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11283 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11284 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11285 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11286 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11287 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11288 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11289 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11290 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11291 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11292 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11293 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11294 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11295 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11296 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11297 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11298 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11299 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11300 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11301 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11302 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11303 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11304 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11305 0x2d02ef8d
11306 @};
11307 unsigned char *end;
11308
11309 crc = ~crc & 0xffffffff;
11310 for (end = buf + len; buf < end; ++buf)
11311 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 11312 return ~crc & 0xffffffff;
5b5d99cf
JB
11313@}
11314@end smallexample
11315
11316
6d2ebf8b 11317@node Symbol Errors
c906108c
SS
11318@section Errors reading symbol files
11319
11320While reading a symbol file, @value{GDBN} occasionally encounters problems,
11321such as symbol types it does not recognize, or known bugs in compiler
11322output. By default, @value{GDBN} does not notify you of such problems, since
11323they are relatively common and primarily of interest to people
11324debugging compilers. If you are interested in seeing information
11325about ill-constructed symbol tables, you can either ask @value{GDBN} to print
11326only one message about each such type of problem, no matter how many
11327times the problem occurs; or you can ask @value{GDBN} to print more messages,
11328to see how many times the problems occur, with the @code{set
11329complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
11330messages}).
11331
11332The messages currently printed, and their meanings, include:
11333
11334@table @code
11335@item inner block not inside outer block in @var{symbol}
11336
11337The symbol information shows where symbol scopes begin and end
11338(such as at the start of a function or a block of statements). This
11339error indicates that an inner scope block is not fully contained
11340in its outer scope blocks.
11341
11342@value{GDBN} circumvents the problem by treating the inner block as if it had
11343the same scope as the outer block. In the error message, @var{symbol}
11344may be shown as ``@code{(don't know)}'' if the outer block is not a
11345function.
11346
11347@item block at @var{address} out of order
11348
11349The symbol information for symbol scope blocks should occur in
11350order of increasing addresses. This error indicates that it does not
11351do so.
11352
11353@value{GDBN} does not circumvent this problem, and has trouble
11354locating symbols in the source file whose symbols it is reading. (You
11355can often determine what source file is affected by specifying
11356@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
11357messages}.)
11358
11359@item bad block start address patched
11360
11361The symbol information for a symbol scope block has a start address
11362smaller than the address of the preceding source line. This is known
11363to occur in the SunOS 4.1.1 (and earlier) C compiler.
11364
11365@value{GDBN} circumvents the problem by treating the symbol scope block as
11366starting on the previous source line.
11367
11368@item bad string table offset in symbol @var{n}
11369
11370@cindex foo
11371Symbol number @var{n} contains a pointer into the string table which is
11372larger than the size of the string table.
11373
11374@value{GDBN} circumvents the problem by considering the symbol to have the
11375name @code{foo}, which may cause other problems if many symbols end up
11376with this name.
11377
11378@item unknown symbol type @code{0x@var{nn}}
11379
7a292a7a
SS
11380The symbol information contains new data types that @value{GDBN} does
11381not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 11382uncomprehended information, in hexadecimal.
c906108c 11383
7a292a7a
SS
11384@value{GDBN} circumvents the error by ignoring this symbol information.
11385This usually allows you to debug your program, though certain symbols
c906108c 11386are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
11387debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
11388on @code{complain}, then go up to the function @code{read_dbx_symtab}
11389and examine @code{*bufp} to see the symbol.
c906108c
SS
11390
11391@item stub type has NULL name
c906108c 11392
7a292a7a 11393@value{GDBN} could not find the full definition for a struct or class.
c906108c 11394
7a292a7a 11395@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 11396The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
11397information that recent versions of the compiler should have output for
11398it.
c906108c
SS
11399
11400@item info mismatch between compiler and debugger
11401
11402@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 11403
c906108c
SS
11404@end table
11405
6d2ebf8b 11406@node Targets
c906108c 11407@chapter Specifying a Debugging Target
7a292a7a 11408
c906108c 11409@cindex debugging target
c906108c 11410A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
11411
11412Often, @value{GDBN} runs in the same host environment as your program;
11413in that case, the debugging target is specified as a side effect when
11414you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
11415flexibility---for example, running @value{GDBN} on a physically separate
11416host, or controlling a standalone system over a serial port or a
53a5351d
JM
11417realtime system over a TCP/IP connection---you can use the @code{target}
11418command to specify one of the target types configured for @value{GDBN}
11419(@pxref{Target Commands, ,Commands for managing targets}).
c906108c 11420
a8f24a35
EZ
11421@cindex target architecture
11422It is possible to build @value{GDBN} for several different @dfn{target
11423architectures}. When @value{GDBN} is built like that, you can choose
11424one of the available architectures with the @kbd{set architecture}
11425command.
11426
11427@table @code
11428@kindex set architecture
11429@kindex show architecture
11430@item set architecture @var{arch}
11431This command sets the current target architecture to @var{arch}. The
11432value of @var{arch} can be @code{"auto"}, in addition to one of the
11433supported architectures.
11434
11435@item show architecture
11436Show the current target architecture.
9c16f35a
EZ
11437
11438@item set processor
11439@itemx processor
11440@kindex set processor
11441@kindex show processor
11442These are alias commands for, respectively, @code{set architecture}
11443and @code{show architecture}.
a8f24a35
EZ
11444@end table
11445
c906108c
SS
11446@menu
11447* Active Targets:: Active targets
11448* Target Commands:: Commands for managing targets
c906108c
SS
11449* Byte Order:: Choosing target byte order
11450* Remote:: Remote debugging
96baa820 11451* KOD:: Kernel Object Display
c906108c
SS
11452
11453@end menu
11454
6d2ebf8b 11455@node Active Targets
c906108c 11456@section Active targets
7a292a7a 11457
c906108c
SS
11458@cindex stacking targets
11459@cindex active targets
11460@cindex multiple targets
11461
c906108c 11462There are three classes of targets: processes, core files, and
7a292a7a
SS
11463executable files. @value{GDBN} can work concurrently on up to three
11464active targets, one in each class. This allows you to (for example)
11465start a process and inspect its activity without abandoning your work on
11466a core file.
c906108c
SS
11467
11468For example, if you execute @samp{gdb a.out}, then the executable file
11469@code{a.out} is the only active target. If you designate a core file as
11470well---presumably from a prior run that crashed and coredumped---then
11471@value{GDBN} has two active targets and uses them in tandem, looking
11472first in the corefile target, then in the executable file, to satisfy
11473requests for memory addresses. (Typically, these two classes of target
11474are complementary, since core files contain only a program's
11475read-write memory---variables and so on---plus machine status, while
11476executable files contain only the program text and initialized data.)
c906108c
SS
11477
11478When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
11479target as well. When a process target is active, all @value{GDBN}
11480commands requesting memory addresses refer to that target; addresses in
11481an active core file or executable file target are obscured while the
11482process target is active.
c906108c 11483
7a292a7a
SS
11484Use the @code{core-file} and @code{exec-file} commands to select a new
11485core file or executable target (@pxref{Files, ,Commands to specify
c906108c 11486files}). To specify as a target a process that is already running, use
7a292a7a
SS
11487the @code{attach} command (@pxref{Attach, ,Debugging an already-running
11488process}).
c906108c 11489
6d2ebf8b 11490@node Target Commands
c906108c
SS
11491@section Commands for managing targets
11492
11493@table @code
11494@item target @var{type} @var{parameters}
7a292a7a
SS
11495Connects the @value{GDBN} host environment to a target machine or
11496process. A target is typically a protocol for talking to debugging
11497facilities. You use the argument @var{type} to specify the type or
11498protocol of the target machine.
c906108c
SS
11499
11500Further @var{parameters} are interpreted by the target protocol, but
11501typically include things like device names or host names to connect
11502with, process numbers, and baud rates.
c906108c
SS
11503
11504The @code{target} command does not repeat if you press @key{RET} again
11505after executing the command.
11506
11507@kindex help target
11508@item help target
11509Displays the names of all targets available. To display targets
11510currently selected, use either @code{info target} or @code{info files}
11511(@pxref{Files, ,Commands to specify files}).
11512
11513@item help target @var{name}
11514Describe a particular target, including any parameters necessary to
11515select it.
11516
11517@kindex set gnutarget
11518@item set gnutarget @var{args}
5d161b24 11519@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 11520knows whether it is reading an @dfn{executable},
5d161b24
DB
11521a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
11522with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
11523with @code{gnutarget} the @code{target} refers to a program, not a machine.
11524
d4f3574e 11525@quotation
c906108c
SS
11526@emph{Warning:} To specify a file format with @code{set gnutarget},
11527you must know the actual BFD name.
d4f3574e 11528@end quotation
c906108c 11529
d4f3574e
SS
11530@noindent
11531@xref{Files, , Commands to specify files}.
c906108c 11532
5d161b24 11533@kindex show gnutarget
c906108c
SS
11534@item show gnutarget
11535Use the @code{show gnutarget} command to display what file format
11536@code{gnutarget} is set to read. If you have not set @code{gnutarget},
11537@value{GDBN} will determine the file format for each file automatically,
11538and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11539@end table
11540
4644b6e3 11541@cindex common targets
c906108c
SS
11542Here are some common targets (available, or not, depending on the GDB
11543configuration):
c906108c
SS
11544
11545@table @code
4644b6e3 11546@kindex target
c906108c 11547@item target exec @var{program}
4644b6e3 11548@cindex executable file target
c906108c
SS
11549An executable file. @samp{target exec @var{program}} is the same as
11550@samp{exec-file @var{program}}.
11551
c906108c 11552@item target core @var{filename}
4644b6e3 11553@cindex core dump file target
c906108c
SS
11554A core dump file. @samp{target core @var{filename}} is the same as
11555@samp{core-file @var{filename}}.
c906108c 11556
c906108c 11557@item target remote @var{dev}
4644b6e3 11558@cindex remote target
c906108c
SS
11559Remote serial target in GDB-specific protocol. The argument @var{dev}
11560specifies what serial device to use for the connection (e.g.
11561@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 11562supports the @code{load} command. This is only useful if you have
c906108c
SS
11563some other way of getting the stub to the target system, and you can put
11564it somewhere in memory where it won't get clobbered by the download.
11565
c906108c 11566@item target sim
4644b6e3 11567@cindex built-in simulator target
2df3850c 11568Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 11569In general,
474c8240 11570@smallexample
104c1213
JM
11571 target sim
11572 load
11573 run
474c8240 11574@end smallexample
d4f3574e 11575@noindent
104c1213 11576works; however, you cannot assume that a specific memory map, device
d4f3574e 11577drivers, or even basic I/O is available, although some simulators do
104c1213
JM
11578provide these. For info about any processor-specific simulator details,
11579see the appropriate section in @ref{Embedded Processors, ,Embedded
11580Processors}.
11581
c906108c
SS
11582@end table
11583
104c1213 11584Some configurations may include these targets as well:
c906108c
SS
11585
11586@table @code
11587
c906108c 11588@item target nrom @var{dev}
4644b6e3 11589@cindex NetROM ROM emulator target
c906108c
SS
11590NetROM ROM emulator. This target only supports downloading.
11591
c906108c
SS
11592@end table
11593
5d161b24 11594Different targets are available on different configurations of @value{GDBN};
c906108c 11595your configuration may have more or fewer targets.
c906108c 11596
721c2651
EZ
11597Many remote targets require you to download the executable's code once
11598you've successfully established a connection. You may wish to control
11599various aspects of this process, such as the size of the data chunks
11600used by @value{GDBN} to download program parts to the remote target.
a8f24a35
EZ
11601
11602@table @code
11603@kindex set download-write-size
11604@item set download-write-size @var{size}
11605Set the write size used when downloading a program. Only used when
11606downloading a program onto a remote target. Specify zero or a
11607negative value to disable blocked writes. The actual size of each
11608transfer is also limited by the size of the target packet and the
11609memory cache.
11610
11611@kindex show download-write-size
11612@item show download-write-size
721c2651 11613@kindex show download-write-size
a8f24a35 11614Show the current value of the write size.
721c2651
EZ
11615
11616@item set hash
11617@kindex set hash@r{, for remote monitors}
11618@cindex hash mark while downloading
11619This command controls whether a hash mark @samp{#} is displayed while
11620downloading a file to the remote monitor. If on, a hash mark is
11621displayed after each S-record is successfully downloaded to the
11622monitor.
11623
11624@item show hash
11625@kindex show hash@r{, for remote monitors}
11626Show the current status of displaying the hash mark.
11627
11628@item set debug monitor
11629@kindex set debug monitor
11630@cindex display remote monitor communications
11631Enable or disable display of communications messages between
11632@value{GDBN} and the remote monitor.
11633
11634@item show debug monitor
11635@kindex show debug monitor
11636Show the current status of displaying communications between
11637@value{GDBN} and the remote monitor.
a8f24a35 11638@end table
c906108c
SS
11639
11640@table @code
11641
11642@kindex load @var{filename}
11643@item load @var{filename}
c906108c
SS
11644Depending on what remote debugging facilities are configured into
11645@value{GDBN}, the @code{load} command may be available. Where it exists, it
11646is meant to make @var{filename} (an executable) available for debugging
11647on the remote system---by downloading, or dynamic linking, for example.
11648@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
11649the @code{add-symbol-file} command.
11650
11651If your @value{GDBN} does not have a @code{load} command, attempting to
11652execute it gets the error message ``@code{You can't do that when your
11653target is @dots{}}''
c906108c
SS
11654
11655The file is loaded at whatever address is specified in the executable.
11656For some object file formats, you can specify the load address when you
11657link the program; for other formats, like a.out, the object file format
11658specifies a fixed address.
11659@c FIXME! This would be a good place for an xref to the GNU linker doc.
11660
c906108c
SS
11661@code{load} does not repeat if you press @key{RET} again after using it.
11662@end table
11663
6d2ebf8b 11664@node Byte Order
c906108c 11665@section Choosing target byte order
7a292a7a 11666
c906108c
SS
11667@cindex choosing target byte order
11668@cindex target byte order
c906108c 11669
172c2a43 11670Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
11671offer the ability to run either big-endian or little-endian byte
11672orders. Usually the executable or symbol will include a bit to
11673designate the endian-ness, and you will not need to worry about
11674which to use. However, you may still find it useful to adjust
d4f3574e 11675@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
11676
11677@table @code
4644b6e3 11678@kindex set endian
c906108c
SS
11679@item set endian big
11680Instruct @value{GDBN} to assume the target is big-endian.
11681
c906108c
SS
11682@item set endian little
11683Instruct @value{GDBN} to assume the target is little-endian.
11684
c906108c
SS
11685@item set endian auto
11686Instruct @value{GDBN} to use the byte order associated with the
11687executable.
11688
11689@item show endian
11690Display @value{GDBN}'s current idea of the target byte order.
11691
11692@end table
11693
11694Note that these commands merely adjust interpretation of symbolic
11695data on the host, and that they have absolutely no effect on the
11696target system.
11697
6d2ebf8b 11698@node Remote
c906108c
SS
11699@section Remote debugging
11700@cindex remote debugging
11701
11702If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
11703@value{GDBN} in the usual way, it is often useful to use remote debugging.
11704For example, you might use remote debugging on an operating system kernel,
c906108c
SS
11705or on a small system which does not have a general purpose operating system
11706powerful enough to run a full-featured debugger.
11707
11708Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
11709to make this work with particular debugging targets. In addition,
5d161b24 11710@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
11711but not specific to any particular target system) which you can use if you
11712write the remote stubs---the code that runs on the remote system to
11713communicate with @value{GDBN}.
11714
11715Other remote targets may be available in your
11716configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 11717
c45da7e6
EZ
11718Once you've connected to the remote target, @value{GDBN} allows you to
11719send arbitrary commands to the remote monitor:
11720
11721@table @code
11722@item remote @var{command}
11723@kindex remote@r{, a command}
11724@cindex send command to remote monitor
11725Send an arbitrary @var{command} string to the remote monitor.
11726@end table
11727
11728
6f05cf9f
AC
11729@node KOD
11730@section Kernel Object Display
6f05cf9f 11731@cindex kernel object display
6f05cf9f
AC
11732@cindex KOD
11733
11734Some targets support kernel object display. Using this facility,
11735@value{GDBN} communicates specially with the underlying operating system
11736and can display information about operating system-level objects such as
11737mutexes and other synchronization objects. Exactly which objects can be
11738displayed is determined on a per-OS basis.
11739
3bbe9696 11740@kindex set os
6f05cf9f
AC
11741Use the @code{set os} command to set the operating system. This tells
11742@value{GDBN} which kernel object display module to initialize:
11743
474c8240 11744@smallexample
6f05cf9f 11745(@value{GDBP}) set os cisco
474c8240 11746@end smallexample
6f05cf9f 11747
3bbe9696
EZ
11748@kindex show os
11749The associated command @code{show os} displays the operating system
11750set with the @code{set os} command; if no operating system has been
11751set, @code{show os} will display an empty string @samp{""}.
11752
6f05cf9f
AC
11753If @code{set os} succeeds, @value{GDBN} will display some information
11754about the operating system, and will create a new @code{info} command
11755which can be used to query the target. The @code{info} command is named
11756after the operating system:
c906108c 11757
3bbe9696 11758@kindex info cisco
474c8240 11759@smallexample
6f05cf9f
AC
11760(@value{GDBP}) info cisco
11761List of Cisco Kernel Objects
11762Object Description
11763any Any and all objects
474c8240 11764@end smallexample
6f05cf9f
AC
11765
11766Further subcommands can be used to query about particular objects known
11767by the kernel.
11768
3bbe9696
EZ
11769There is currently no way to determine whether a given operating
11770system is supported other than to try setting it with @kbd{set os
11771@var{name}}, where @var{name} is the name of the operating system you
11772want to try.
6f05cf9f
AC
11773
11774
11775@node Remote Debugging
11776@chapter Debugging remote programs
11777
6b2f586d 11778@menu
07f31aa6 11779* Connecting:: Connecting to a remote target
6b2f586d
AC
11780* Server:: Using the gdbserver program
11781* NetWare:: Using the gdbserve.nlm program
501eef12 11782* Remote configuration:: Remote configuration
6b2f586d 11783* remote stub:: Implementing a remote stub
6b2f586d
AC
11784@end menu
11785
07f31aa6
DJ
11786@node Connecting
11787@section Connecting to a remote target
11788
11789On the @value{GDBN} host machine, you will need an unstripped copy of
11790your program, since @value{GDBN} needs symobl and debugging information.
11791Start up @value{GDBN} as usual, using the name of the local copy of your
11792program as the first argument.
11793
11794@cindex serial line, @code{target remote}
11795If you're using a serial line, you may want to give @value{GDBN} the
11796@w{@samp{--baud}} option, or use the @code{set remotebaud} command
9c16f35a
EZ
11797(@pxref{Remote configuration, set remotebaud}) before the
11798@code{target} command.
07f31aa6
DJ
11799
11800After that, use @code{target remote} to establish communications with
11801the target machine. Its argument specifies how to communicate---either
11802via a devicename attached to a direct serial line, or a TCP or UDP port
11803(possibly to a terminal server which in turn has a serial line to the
11804target). For example, to use a serial line connected to the device
11805named @file{/dev/ttyb}:
11806
11807@smallexample
11808target remote /dev/ttyb
11809@end smallexample
11810
11811@cindex TCP port, @code{target remote}
11812To use a TCP connection, use an argument of the form
11813@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
11814For example, to connect to port 2828 on a
11815terminal server named @code{manyfarms}:
11816
11817@smallexample
11818target remote manyfarms:2828
11819@end smallexample
11820
11821If your remote target is actually running on the same machine as
11822your debugger session (e.g.@: a simulator of your target running on
11823the same host), you can omit the hostname. For example, to connect
11824to port 1234 on your local machine:
11825
11826@smallexample
11827target remote :1234
11828@end smallexample
11829@noindent
11830
11831Note that the colon is still required here.
11832
11833@cindex UDP port, @code{target remote}
11834To use a UDP connection, use an argument of the form
11835@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
11836on a terminal server named @code{manyfarms}:
11837
11838@smallexample
11839target remote udp:manyfarms:2828
11840@end smallexample
11841
11842When using a UDP connection for remote debugging, you should keep in mind
11843that the `U' stands for ``Unreliable''. UDP can silently drop packets on
11844busy or unreliable networks, which will cause havoc with your debugging
11845session.
11846
11847Now you can use all the usual commands to examine and change data and to
11848step and continue the remote program.
11849
11850@cindex interrupting remote programs
11851@cindex remote programs, interrupting
11852Whenever @value{GDBN} is waiting for the remote program, if you type the
11853interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
11854program. This may or may not succeed, depending in part on the hardware
11855and the serial drivers the remote system uses. If you type the
11856interrupt character once again, @value{GDBN} displays this prompt:
11857
11858@smallexample
11859Interrupted while waiting for the program.
11860Give up (and stop debugging it)? (y or n)
11861@end smallexample
11862
11863If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
11864(If you decide you want to try again later, you can use @samp{target
11865remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
11866goes back to waiting.
11867
11868@table @code
11869@kindex detach (remote)
11870@item detach
11871When you have finished debugging the remote program, you can use the
11872@code{detach} command to release it from @value{GDBN} control.
11873Detaching from the target normally resumes its execution, but the results
11874will depend on your particular remote stub. After the @code{detach}
11875command, @value{GDBN} is free to connect to another target.
11876
11877@kindex disconnect
11878@item disconnect
11879The @code{disconnect} command behaves like @code{detach}, except that
11880the target is generally not resumed. It will wait for @value{GDBN}
11881(this instance or another one) to connect and continue debugging. After
11882the @code{disconnect} command, @value{GDBN} is again free to connect to
11883another target.
09d4efe1
EZ
11884
11885@cindex send command to remote monitor
11886@kindex monitor
11887@item monitor @var{cmd}
11888This command allows you to send commands directly to the remote
11889monitor.
07f31aa6
DJ
11890@end table
11891
6f05cf9f
AC
11892@node Server
11893@section Using the @code{gdbserver} program
11894
11895@kindex gdbserver
11896@cindex remote connection without stubs
11897@code{gdbserver} is a control program for Unix-like systems, which
11898allows you to connect your program with a remote @value{GDBN} via
11899@code{target remote}---but without linking in the usual debugging stub.
11900
11901@code{gdbserver} is not a complete replacement for the debugging stubs,
11902because it requires essentially the same operating-system facilities
11903that @value{GDBN} itself does. In fact, a system that can run
11904@code{gdbserver} to connect to a remote @value{GDBN} could also run
11905@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
11906because it is a much smaller program than @value{GDBN} itself. It is
11907also easier to port than all of @value{GDBN}, so you may be able to get
11908started more quickly on a new system by using @code{gdbserver}.
11909Finally, if you develop code for real-time systems, you may find that
11910the tradeoffs involved in real-time operation make it more convenient to
11911do as much development work as possible on another system, for example
11912by cross-compiling. You can use @code{gdbserver} to make a similar
11913choice for debugging.
11914
11915@value{GDBN} and @code{gdbserver} communicate via either a serial line
11916or a TCP connection, using the standard @value{GDBN} remote serial
11917protocol.
11918
11919@table @emph
11920@item On the target machine,
11921you need to have a copy of the program you want to debug.
11922@code{gdbserver} does not need your program's symbol table, so you can
11923strip the program if necessary to save space. @value{GDBN} on the host
11924system does all the symbol handling.
11925
11926To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 11927the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
11928syntax is:
11929
11930@smallexample
11931target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
11932@end smallexample
11933
11934@var{comm} is either a device name (to use a serial line) or a TCP
11935hostname and portnumber. For example, to debug Emacs with the argument
11936@samp{foo.txt} and communicate with @value{GDBN} over the serial port
11937@file{/dev/com1}:
11938
11939@smallexample
11940target> gdbserver /dev/com1 emacs foo.txt
11941@end smallexample
11942
11943@code{gdbserver} waits passively for the host @value{GDBN} to communicate
11944with it.
11945
11946To use a TCP connection instead of a serial line:
11947
11948@smallexample
11949target> gdbserver host:2345 emacs foo.txt
11950@end smallexample
11951
11952The only difference from the previous example is the first argument,
11953specifying that you are communicating with the host @value{GDBN} via
11954TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
11955expect a TCP connection from machine @samp{host} to local TCP port 2345.
11956(Currently, the @samp{host} part is ignored.) You can choose any number
11957you want for the port number as long as it does not conflict with any
11958TCP ports already in use on the target system (for example, @code{23} is
11959reserved for @code{telnet}).@footnote{If you choose a port number that
11960conflicts with another service, @code{gdbserver} prints an error message
11961and exits.} You must use the same port number with the host @value{GDBN}
11962@code{target remote} command.
11963
56460a61
DJ
11964On some targets, @code{gdbserver} can also attach to running programs.
11965This is accomplished via the @code{--attach} argument. The syntax is:
11966
11967@smallexample
11968target> gdbserver @var{comm} --attach @var{pid}
11969@end smallexample
11970
11971@var{pid} is the process ID of a currently running process. It isn't necessary
11972to point @code{gdbserver} at a binary for the running process.
11973
b1fe9455
DJ
11974@pindex pidof
11975@cindex attach to a program by name
11976You can debug processes by name instead of process ID if your target has the
11977@code{pidof} utility:
11978
11979@smallexample
11980target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
11981@end smallexample
11982
11983In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
11984has multiple threads, most versions of @code{pidof} support the
11985@code{-s} option to only return the first process ID.
11986
07f31aa6
DJ
11987@item On the host machine,
11988connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
11989For TCP connections, you must start up @code{gdbserver} prior to using
11990the @code{target remote} command. Otherwise you may get an error whose
11991text depends on the host system, but which usually looks something like
07f31aa6 11992@samp{Connection refused}. You don't need to use the @code{load}
397ca115
EZ
11993command in @value{GDBN} when using @code{gdbserver}, since the program is
11994already on the target. However, if you want to load the symbols (as
11995you normally would), do that with the @code{file} command, and issue
11996it @emph{before} connecting to the server; otherwise, you will get an
11997error message saying @code{"Program is already running"}, since the
11998program is considered running after the connection.
07f31aa6 11999
6f05cf9f
AC
12000@end table
12001
12002@node NetWare
12003@section Using the @code{gdbserve.nlm} program
12004
12005@kindex gdbserve.nlm
12006@code{gdbserve.nlm} is a control program for NetWare systems, which
12007allows you to connect your program with a remote @value{GDBN} via
12008@code{target remote}.
12009
12010@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
12011using the standard @value{GDBN} remote serial protocol.
12012
12013@table @emph
12014@item On the target machine,
12015you need to have a copy of the program you want to debug.
12016@code{gdbserve.nlm} does not need your program's symbol table, so you
12017can strip the program if necessary to save space. @value{GDBN} on the
12018host system does all the symbol handling.
12019
12020To use the server, you must tell it how to communicate with
12021@value{GDBN}; the name of your program; and the arguments for your
12022program. The syntax is:
12023
12024@smallexample
12025load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
12026 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
12027@end smallexample
12028
12029@var{board} and @var{port} specify the serial line; @var{baud} specifies
12030the baud rate used by the connection. @var{port} and @var{node} default
12031to 0, @var{baud} defaults to 9600@dmn{bps}.
12032
12033For example, to debug Emacs with the argument @samp{foo.txt}and
12034communicate with @value{GDBN} over serial port number 2 or board 1
12035using a 19200@dmn{bps} connection:
12036
12037@smallexample
12038load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
12039@end smallexample
12040
07f31aa6
DJ
12041@item
12042On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
12043Connecting to a remote target}).
6f05cf9f 12044
6f05cf9f
AC
12045@end table
12046
501eef12
AC
12047@node Remote configuration
12048@section Remote configuration
12049
9c16f35a
EZ
12050@kindex set remote
12051@kindex show remote
12052This section documents the configuration options available when
12053debugging remote programs. For the options related to the File I/O
12054extensions of the remote protocol, see @ref{The system call,
12055system-call-allowed}.
501eef12
AC
12056
12057@table @code
9c16f35a
EZ
12058@item set remoteaddresssize @var{bits}
12059@cindex adress size for remote targets
12060@cindex bits in remote address
12061Set the maximum size of address in a memory packet to the specified
12062number of bits. @value{GDBN} will mask off the address bits above
12063that number, when it passes addresses to the remote target. The
12064default value is the number of bits in the target's address.
12065
12066@item show remoteaddresssize
12067Show the current value of remote address size in bits.
12068
12069@item set remotebaud @var{n}
12070@cindex baud rate for remote targets
12071Set the baud rate for the remote serial I/O to @var{n} baud. The
12072value is used to set the speed of the serial port used for debugging
12073remote targets.
12074
12075@item show remotebaud
12076Show the current speed of the remote connection.
12077
12078@item set remotebreak
12079@cindex interrupt remote programs
12080@cindex BREAK signal instead of Ctrl-C
12081If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
12082when you press the @key{Ctrl-C} key to interrupt the program running
12083on the remote. If set to off, @value{GDBN} sends the @samp{Strl-C}
12084character instead. The default is off, since most remote systems
12085expect to see @samp{Ctrl-C} as the interrupt signal.
12086
12087@item show remotebreak
12088Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
12089interrupt the remote program.
12090
12091@item set remotedebug
12092@cindex debug remote protocol
12093@cindex remote protocol debugging
12094@cindex display remote packets
12095Control the debugging of the remote protocol. When enabled, each
12096packet sent to or received from the remote target is displayed. The
12097defaults is off.
12098
12099@item show remotedebug
12100Show the current setting of the remote protocol debugging.
12101
12102@item set remotedevice @var{device}
12103@cindex serial port name
12104Set the name of the serial port through which to communicate to the
12105remote target to @var{device}. This is the device used by
12106@value{GDBN} to open the serial communications line to the remote
12107target. There's no default, so you must set a valid port name for the
12108remote serial communications to work. (Some varieties of the
12109@code{target} command accept the port name as part of their
12110arguments.)
12111
12112@item show remotedevice
12113Show the current name of the serial port.
12114
12115@item set remotelogbase @var{base}
12116Set the base (a.k.a.@: radix) of logging serial protocol
12117communications to @var{base}. Supported values of @var{base} are:
12118@code{ascii}, @code{octal}, and @code{hex}. The default is
12119@code{ascii}.
12120
12121@item show remotelogbase
12122Show the current setting of the radix for logging remote serial
12123protocol.
12124
12125@item set remotelogfile @var{file}
12126@cindex record serial communications on file
12127Record remote serial communications on the named @var{file}. The
12128default is not to record at all.
12129
12130@item show remotelogfile.
12131Show the current setting of the file name on which to record the
12132serial communications.
12133
12134@item set remotetimeout @var{num}
12135@cindex timeout for serial communications
12136@cindex remote timeout
12137Set the timeout limit to wait for the remote target to respond to
12138@var{num} seconds. The default is 2 seconds.
12139
12140@item show remotetimeout
12141Show the current number of seconds to wait for the remote target
12142responses.
12143
12144@cindex limit hardware breakpoints and watchpoints
12145@cindex remote target, limit break- and watchpoints
501eef12
AC
12146@anchor{set remote hardware-watchpoint-limit}
12147@anchor{set remote hardware-breakpoint-limit}
12148@item set remote hardware-watchpoint-limit @var{limit}
12149@itemx set remote hardware-breakpoint-limit @var{limit}
12150Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
12151watchpoints. A limit of -1, the default, is treated as unlimited.
9c16f35a
EZ
12152
12153@item set remote fetch-register-packet
12154@itemx set remote set-register-packet
12155@itemx set remote P-packet
12156@itemx set remote p-packet
12157@cindex P-packet
12158@cindex fetch registers from remote targets
12159@cindex set registers in remote targets
12160Determine whether @value{GDBN} can set and fetch registers from the
12161remote target using the @samp{P} packets. The default depends on the
12162remote stub's support of the @samp{P} packets (@value{GDBN} queries
12163the stub when this packet is first required).
12164
12165@item show remote fetch-register-packet
12166@itemx show remote set-register-packet
12167@itemx show remote P-packet
12168@itemx show remote p-packet
12169Show the current setting of using the @samp{P} packets for setting and
12170fetching registers from the remote target.
12171
12172@cindex binary downloads
12173@cindex X-packet
12174@item set remote binary-download-packet
12175@itemx set remote X-packet
12176Determine whether @value{GDBN} sends downloads in binary mode using
12177the @samp{X} packets. The default is on.
12178
12179@item show remote binary-download-packet
12180@itemx show remote X-packet
12181Show the current setting of using the @samp{X} packets for binary
12182downloads.
12183
12184@item set remote read-aux-vector-packet
12185@cindex auxiliary vector of remote target
12186@cindex @code{auxv}, and remote targets
12187Set the use of the remote protocol's @samp{qPart:auxv:read} (target
12188auxiliary vector read) request. This request is used to fetch the
721c2651
EZ
12189remote target's @dfn{auxiliary vector}, see @ref{OS Information,
12190Auxiliary Vector}. The default setting depends on the remote stub's
12191support of this request (@value{GDBN} queries the stub when this
12192request is first required). @xref{General Query Packets, qPart}, for
12193more information about this request.
9c16f35a
EZ
12194
12195@item show remote read-aux-vector-packet
12196Show the current setting of use of the @samp{qPart:auxv:read} request.
12197
12198@item set remote symbol-lookup-packet
12199@cindex remote symbol lookup request
12200Set the use of the remote protocol's @samp{qSymbol} (target symbol
12201lookup) request. This request is used to communicate symbol
12202information to the remote target, e.g., whenever a new shared library
12203is loaded by the remote (@pxref{Files, shared libraries}). The
12204default setting depends on the remote stub's support of this request
12205(@value{GDBN} queries the stub when this request is first required).
12206@xref{General Query Packets, qSymbol}, for more information about this
12207request.
12208
12209@item show remote symbol-lookup-packet
12210Show the current setting of use of the @samp{qSymbol} request.
12211
12212@item set remote verbose-resume-packet
12213@cindex resume remote target
12214@cindex signal thread, and remote targets
12215@cindex single-step thread, and remote targets
12216@cindex thread-specific operations on remote targets
12217Set the use of the remote protocol's @samp{vCont} (descriptive resume)
12218request. This request is used to resume specific threads in the
12219remote target, and to single-step or signal them. The default setting
12220depends on the remote stub's support of this request (@value{GDBN}
12221queries the stub when this request is first required). This setting
12222affects debugging of multithreaded programs: if @samp{vCont} cannot be
12223used, @value{GDBN} might be unable to single-step a specific thread,
12224especially under @code{set scheduler-locking off}; it is also
12225impossible to pause a specific thread. @xref{Packets, vCont}, for
12226more details.
12227
12228@item show remote verbose-resume-packet
12229Show the current setting of use of the @samp{vCont} request
12230
12231@item set remote software-breakpoint-packet
12232@itemx set remote hardware-breakpoint-packet
12233@itemx set remote write-watchpoint-packet
12234@itemx set remote read-watchpoint-packet
12235@itemx set remote access-watchpoint-packet
12236@itemx set remote Z-packet
12237@cindex Z-packet
12238@cindex remote hardware breakpoints and watchpoints
12239These commands enable or disable the use of @samp{Z} packets for
12240setting breakpoints and watchpoints in the remote target. The default
12241depends on the remote stub's support of the @samp{Z} packets
12242(@value{GDBN} queries the stub when each packet is first required).
12243The command @code{set remote Z-packet}, kept for back-compatibility,
12244turns on or off all the features that require the use of @samp{Z}
12245packets.
12246
12247@item show remote software-breakpoint-packet
12248@itemx show remote hardware-breakpoint-packet
12249@itemx show remote write-watchpoint-packet
12250@itemx show remote read-watchpoint-packet
12251@itemx show remote access-watchpoint-packet
12252@itemx show remote Z-packet
12253Show the current setting of @samp{Z} packets usage.
0abb7bc7
EZ
12254
12255@item set remote get-thread-local-storage-address
12256@kindex set remote get-thread-local-storage-address
12257@cindex thread local storage of remote targets
12258This command enables or disables the use of the @samp{qGetTLSAddr}
12259(Get Thread Local Storage Address) request packet. The default
12260depends on whether the remote stub supports this request.
12261@xref{General Query Packets, qGetTLSAddr}, for more details about this
12262packet.
12263
12264@item show remote get-thread-local-storage-address
12265@kindex show remote get-thread-local-storage-address
12266Show the current setting of @samp{qGetTLSAddr} packet usage.
501eef12
AC
12267@end table
12268
6f05cf9f
AC
12269@node remote stub
12270@section Implementing a remote stub
7a292a7a 12271
8e04817f
AC
12272@cindex debugging stub, example
12273@cindex remote stub, example
12274@cindex stub example, remote debugging
12275The stub files provided with @value{GDBN} implement the target side of the
12276communication protocol, and the @value{GDBN} side is implemented in the
12277@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
12278these subroutines to communicate, and ignore the details. (If you're
12279implementing your own stub file, you can still ignore the details: start
12280with one of the existing stub files. @file{sparc-stub.c} is the best
12281organized, and therefore the easiest to read.)
12282
104c1213
JM
12283@cindex remote serial debugging, overview
12284To debug a program running on another machine (the debugging
12285@dfn{target} machine), you must first arrange for all the usual
12286prerequisites for the program to run by itself. For example, for a C
12287program, you need:
c906108c 12288
104c1213
JM
12289@enumerate
12290@item
12291A startup routine to set up the C runtime environment; these usually
12292have a name like @file{crt0}. The startup routine may be supplied by
12293your hardware supplier, or you may have to write your own.
96baa820 12294
5d161b24 12295@item
d4f3574e 12296A C subroutine library to support your program's
104c1213 12297subroutine calls, notably managing input and output.
96baa820 12298
104c1213
JM
12299@item
12300A way of getting your program to the other machine---for example, a
12301download program. These are often supplied by the hardware
12302manufacturer, but you may have to write your own from hardware
12303documentation.
12304@end enumerate
96baa820 12305
104c1213
JM
12306The next step is to arrange for your program to use a serial port to
12307communicate with the machine where @value{GDBN} is running (the @dfn{host}
12308machine). In general terms, the scheme looks like this:
96baa820 12309
104c1213
JM
12310@table @emph
12311@item On the host,
12312@value{GDBN} already understands how to use this protocol; when everything
12313else is set up, you can simply use the @samp{target remote} command
12314(@pxref{Targets,,Specifying a Debugging Target}).
12315
12316@item On the target,
12317you must link with your program a few special-purpose subroutines that
12318implement the @value{GDBN} remote serial protocol. The file containing these
12319subroutines is called a @dfn{debugging stub}.
12320
12321On certain remote targets, you can use an auxiliary program
12322@code{gdbserver} instead of linking a stub into your program.
12323@xref{Server,,Using the @code{gdbserver} program}, for details.
12324@end table
96baa820 12325
104c1213
JM
12326The debugging stub is specific to the architecture of the remote
12327machine; for example, use @file{sparc-stub.c} to debug programs on
12328@sc{sparc} boards.
96baa820 12329
104c1213
JM
12330@cindex remote serial stub list
12331These working remote stubs are distributed with @value{GDBN}:
96baa820 12332
104c1213
JM
12333@table @code
12334
12335@item i386-stub.c
41afff9a 12336@cindex @file{i386-stub.c}
104c1213
JM
12337@cindex Intel
12338@cindex i386
12339For Intel 386 and compatible architectures.
12340
12341@item m68k-stub.c
41afff9a 12342@cindex @file{m68k-stub.c}
104c1213
JM
12343@cindex Motorola 680x0
12344@cindex m680x0
12345For Motorola 680x0 architectures.
12346
12347@item sh-stub.c
41afff9a 12348@cindex @file{sh-stub.c}
172c2a43 12349@cindex Renesas
104c1213 12350@cindex SH
172c2a43 12351For Renesas SH architectures.
104c1213
JM
12352
12353@item sparc-stub.c
41afff9a 12354@cindex @file{sparc-stub.c}
104c1213
JM
12355@cindex Sparc
12356For @sc{sparc} architectures.
12357
12358@item sparcl-stub.c
41afff9a 12359@cindex @file{sparcl-stub.c}
104c1213
JM
12360@cindex Fujitsu
12361@cindex SparcLite
12362For Fujitsu @sc{sparclite} architectures.
12363
12364@end table
12365
12366The @file{README} file in the @value{GDBN} distribution may list other
12367recently added stubs.
12368
12369@menu
12370* Stub Contents:: What the stub can do for you
12371* Bootstrapping:: What you must do for the stub
12372* Debug Session:: Putting it all together
104c1213
JM
12373@end menu
12374
6d2ebf8b 12375@node Stub Contents
6f05cf9f 12376@subsection What the stub can do for you
104c1213
JM
12377
12378@cindex remote serial stub
12379The debugging stub for your architecture supplies these three
12380subroutines:
12381
12382@table @code
12383@item set_debug_traps
4644b6e3 12384@findex set_debug_traps
104c1213
JM
12385@cindex remote serial stub, initialization
12386This routine arranges for @code{handle_exception} to run when your
12387program stops. You must call this subroutine explicitly near the
12388beginning of your program.
12389
12390@item handle_exception
4644b6e3 12391@findex handle_exception
104c1213
JM
12392@cindex remote serial stub, main routine
12393This is the central workhorse, but your program never calls it
12394explicitly---the setup code arranges for @code{handle_exception} to
12395run when a trap is triggered.
12396
12397@code{handle_exception} takes control when your program stops during
12398execution (for example, on a breakpoint), and mediates communications
12399with @value{GDBN} on the host machine. This is where the communications
12400protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 12401representative on the target machine. It begins by sending summary
104c1213
JM
12402information on the state of your program, then continues to execute,
12403retrieving and transmitting any information @value{GDBN} needs, until you
12404execute a @value{GDBN} command that makes your program resume; at that point,
12405@code{handle_exception} returns control to your own code on the target
5d161b24 12406machine.
104c1213
JM
12407
12408@item breakpoint
12409@cindex @code{breakpoint} subroutine, remote
12410Use this auxiliary subroutine to make your program contain a
12411breakpoint. Depending on the particular situation, this may be the only
12412way for @value{GDBN} to get control. For instance, if your target
12413machine has some sort of interrupt button, you won't need to call this;
12414pressing the interrupt button transfers control to
12415@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
12416simply receiving characters on the serial port may also trigger a trap;
12417again, in that situation, you don't need to call @code{breakpoint} from
12418your own program---simply running @samp{target remote} from the host
5d161b24 12419@value{GDBN} session gets control.
104c1213
JM
12420
12421Call @code{breakpoint} if none of these is true, or if you simply want
12422to make certain your program stops at a predetermined point for the
12423start of your debugging session.
12424@end table
12425
6d2ebf8b 12426@node Bootstrapping
6f05cf9f 12427@subsection What you must do for the stub
104c1213
JM
12428
12429@cindex remote stub, support routines
12430The debugging stubs that come with @value{GDBN} are set up for a particular
12431chip architecture, but they have no information about the rest of your
12432debugging target machine.
12433
12434First of all you need to tell the stub how to communicate with the
12435serial port.
12436
12437@table @code
12438@item int getDebugChar()
4644b6e3 12439@findex getDebugChar
104c1213
JM
12440Write this subroutine to read a single character from the serial port.
12441It may be identical to @code{getchar} for your target system; a
12442different name is used to allow you to distinguish the two if you wish.
12443
12444@item void putDebugChar(int)
4644b6e3 12445@findex putDebugChar
104c1213 12446Write this subroutine to write a single character to the serial port.
5d161b24 12447It may be identical to @code{putchar} for your target system; a
104c1213
JM
12448different name is used to allow you to distinguish the two if you wish.
12449@end table
12450
12451@cindex control C, and remote debugging
12452@cindex interrupting remote targets
12453If you want @value{GDBN} to be able to stop your program while it is
12454running, you need to use an interrupt-driven serial driver, and arrange
12455for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
12456character). That is the character which @value{GDBN} uses to tell the
12457remote system to stop.
12458
12459Getting the debugging target to return the proper status to @value{GDBN}
12460probably requires changes to the standard stub; one quick and dirty way
12461is to just execute a breakpoint instruction (the ``dirty'' part is that
12462@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
12463
12464Other routines you need to supply are:
12465
12466@table @code
12467@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 12468@findex exceptionHandler
104c1213
JM
12469Write this function to install @var{exception_address} in the exception
12470handling tables. You need to do this because the stub does not have any
12471way of knowing what the exception handling tables on your target system
12472are like (for example, the processor's table might be in @sc{rom},
12473containing entries which point to a table in @sc{ram}).
12474@var{exception_number} is the exception number which should be changed;
12475its meaning is architecture-dependent (for example, different numbers
12476might represent divide by zero, misaligned access, etc). When this
12477exception occurs, control should be transferred directly to
12478@var{exception_address}, and the processor state (stack, registers,
12479and so on) should be just as it is when a processor exception occurs. So if
12480you want to use a jump instruction to reach @var{exception_address}, it
12481should be a simple jump, not a jump to subroutine.
12482
12483For the 386, @var{exception_address} should be installed as an interrupt
12484gate so that interrupts are masked while the handler runs. The gate
12485should be at privilege level 0 (the most privileged level). The
12486@sc{sparc} and 68k stubs are able to mask interrupts themselves without
12487help from @code{exceptionHandler}.
12488
12489@item void flush_i_cache()
4644b6e3 12490@findex flush_i_cache
d4f3574e 12491On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
12492instruction cache, if any, on your target machine. If there is no
12493instruction cache, this subroutine may be a no-op.
12494
12495On target machines that have instruction caches, @value{GDBN} requires this
12496function to make certain that the state of your program is stable.
12497@end table
12498
12499@noindent
12500You must also make sure this library routine is available:
12501
12502@table @code
12503@item void *memset(void *, int, int)
4644b6e3 12504@findex memset
104c1213
JM
12505This is the standard library function @code{memset} that sets an area of
12506memory to a known value. If you have one of the free versions of
12507@code{libc.a}, @code{memset} can be found there; otherwise, you must
12508either obtain it from your hardware manufacturer, or write your own.
12509@end table
12510
12511If you do not use the GNU C compiler, you may need other standard
12512library subroutines as well; this varies from one stub to another,
12513but in general the stubs are likely to use any of the common library
d4f3574e 12514subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
12515
12516
6d2ebf8b 12517@node Debug Session
6f05cf9f 12518@subsection Putting it all together
104c1213
JM
12519
12520@cindex remote serial debugging summary
12521In summary, when your program is ready to debug, you must follow these
12522steps.
12523
12524@enumerate
12525@item
6d2ebf8b 12526Make sure you have defined the supporting low-level routines
104c1213
JM
12527(@pxref{Bootstrapping,,What you must do for the stub}):
12528@display
12529@code{getDebugChar}, @code{putDebugChar},
12530@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
12531@end display
12532
12533@item
12534Insert these lines near the top of your program:
12535
474c8240 12536@smallexample
104c1213
JM
12537set_debug_traps();
12538breakpoint();
474c8240 12539@end smallexample
104c1213
JM
12540
12541@item
12542For the 680x0 stub only, you need to provide a variable called
12543@code{exceptionHook}. Normally you just use:
12544
474c8240 12545@smallexample
104c1213 12546void (*exceptionHook)() = 0;
474c8240 12547@end smallexample
104c1213 12548
d4f3574e 12549@noindent
104c1213 12550but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 12551function in your program, that function is called when
104c1213
JM
12552@code{@value{GDBN}} continues after stopping on a trap (for example, bus
12553error). The function indicated by @code{exceptionHook} is called with
12554one parameter: an @code{int} which is the exception number.
12555
12556@item
12557Compile and link together: your program, the @value{GDBN} debugging stub for
12558your target architecture, and the supporting subroutines.
12559
12560@item
12561Make sure you have a serial connection between your target machine and
12562the @value{GDBN} host, and identify the serial port on the host.
12563
12564@item
12565@c The "remote" target now provides a `load' command, so we should
12566@c document that. FIXME.
12567Download your program to your target machine (or get it there by
12568whatever means the manufacturer provides), and start it.
12569
12570@item
07f31aa6
DJ
12571Start @value{GDBN} on the host, and connect to the target
12572(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 12573
104c1213
JM
12574@end enumerate
12575
8e04817f
AC
12576@node Configurations
12577@chapter Configuration-Specific Information
104c1213 12578
8e04817f
AC
12579While nearly all @value{GDBN} commands are available for all native and
12580cross versions of the debugger, there are some exceptions. This chapter
12581describes things that are only available in certain configurations.
104c1213 12582
8e04817f
AC
12583There are three major categories of configurations: native
12584configurations, where the host and target are the same, embedded
12585operating system configurations, which are usually the same for several
12586different processor architectures, and bare embedded processors, which
12587are quite different from each other.
104c1213 12588
8e04817f
AC
12589@menu
12590* Native::
12591* Embedded OS::
12592* Embedded Processors::
12593* Architectures::
12594@end menu
104c1213 12595
8e04817f
AC
12596@node Native
12597@section Native
104c1213 12598
8e04817f
AC
12599This section describes details specific to particular native
12600configurations.
6cf7e474 12601
8e04817f
AC
12602@menu
12603* HP-UX:: HP-UX
7561d450 12604* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
12605* SVR4 Process Information:: SVR4 process information
12606* DJGPP Native:: Features specific to the DJGPP port
78c47bea 12607* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 12608* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 12609* Neutrino:: Features specific to QNX Neutrino
8e04817f 12610@end menu
6cf7e474 12611
8e04817f
AC
12612@node HP-UX
12613@subsection HP-UX
104c1213 12614
8e04817f
AC
12615On HP-UX systems, if you refer to a function or variable name that
12616begins with a dollar sign, @value{GDBN} searches for a user or system
12617name first, before it searches for a convenience variable.
104c1213 12618
9c16f35a 12619
7561d450
MK
12620@node BSD libkvm Interface
12621@subsection BSD libkvm Interface
12622
12623@cindex libkvm
12624@cindex kernel memory image
12625@cindex kernel crash dump
12626
12627BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
12628interface that provides a uniform interface for accessing kernel virtual
12629memory images, including live systems and crash dumps. @value{GDBN}
12630uses this interface to allow you to debug live kernels and kernel crash
12631dumps on many native BSD configurations. This is implemented as a
12632special @code{kvm} debugging target. For debugging a live system, load
12633the currently running kernel into @value{GDBN} and connect to the
12634@code{kvm} target:
12635
12636@smallexample
12637(@value{GDBP}) @b{target kvm}
12638@end smallexample
12639
12640For debugging crash dumps, provide the file name of the crash dump as an
12641argument:
12642
12643@smallexample
12644(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
12645@end smallexample
12646
12647Once connected to the @code{kvm} target, the following commands are
12648available:
12649
12650@table @code
12651@kindex kvm
12652@item kvm pcb
721c2651 12653Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
12654
12655@item kvm proc
12656Set current context from proc address. This command isn't available on
12657modern FreeBSD systems.
12658@end table
12659
8e04817f
AC
12660@node SVR4 Process Information
12661@subsection SVR4 process information
60bf7e09
EZ
12662@cindex /proc
12663@cindex examine process image
12664@cindex process info via @file{/proc}
104c1213 12665
60bf7e09
EZ
12666Many versions of SVR4 and compatible systems provide a facility called
12667@samp{/proc} that can be used to examine the image of a running
12668process using file-system subroutines. If @value{GDBN} is configured
12669for an operating system with this facility, the command @code{info
12670proc} is available to report information about the process running
12671your program, or about any process running on your system. @code{info
12672proc} works only on SVR4 systems that include the @code{procfs} code.
12673This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
12674Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 12675
8e04817f
AC
12676@table @code
12677@kindex info proc
60bf7e09 12678@cindex process ID
8e04817f 12679@item info proc
60bf7e09
EZ
12680@itemx info proc @var{process-id}
12681Summarize available information about any running process. If a
12682process ID is specified by @var{process-id}, display information about
12683that process; otherwise display information about the program being
12684debugged. The summary includes the debugged process ID, the command
12685line used to invoke it, its current working directory, and its
12686executable file's absolute file name.
12687
12688On some systems, @var{process-id} can be of the form
12689@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
12690within a process. If the optional @var{pid} part is missing, it means
12691a thread from the process being debugged (the leading @samp{/} still
12692needs to be present, or else @value{GDBN} will interpret the number as
12693a process ID rather than a thread ID).
6cf7e474 12694
8e04817f 12695@item info proc mappings
60bf7e09
EZ
12696@cindex memory address space mappings
12697Report the memory address space ranges accessible in the program, with
12698information on whether the process has read, write, or execute access
12699rights to each range. On @sc{gnu}/Linux systems, each memory range
12700includes the object file which is mapped to that range, instead of the
12701memory access rights to that range.
12702
12703@item info proc stat
12704@itemx info proc status
12705@cindex process detailed status information
12706These subcommands are specific to @sc{gnu}/Linux systems. They show
12707the process-related information, including the user ID and group ID;
12708how many threads are there in the process; its virtual memory usage;
12709the signals that are pending, blocked, and ignored; its TTY; its
12710consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 12711value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
12712(type @kbd{man 5 proc} from your shell prompt).
12713
12714@item info proc all
12715Show all the information about the process described under all of the
12716above @code{info proc} subcommands.
12717
8e04817f
AC
12718@ignore
12719@comment These sub-options of 'info proc' were not included when
12720@comment procfs.c was re-written. Keep their descriptions around
12721@comment against the day when someone finds the time to put them back in.
12722@kindex info proc times
12723@item info proc times
12724Starting time, user CPU time, and system CPU time for your program and
12725its children.
6cf7e474 12726
8e04817f
AC
12727@kindex info proc id
12728@item info proc id
12729Report on the process IDs related to your program: its own process ID,
12730the ID of its parent, the process group ID, and the session ID.
8e04817f 12731@end ignore
721c2651
EZ
12732
12733@item set procfs-trace
12734@kindex set procfs-trace
12735@cindex @code{procfs} API calls
12736This command enables and disables tracing of @code{procfs} API calls.
12737
12738@item show procfs-trace
12739@kindex show procfs-trace
12740Show the current state of @code{procfs} API call tracing.
12741
12742@item set procfs-file @var{file}
12743@kindex set procfs-file
12744Tell @value{GDBN} to write @code{procfs} API trace to the named
12745@var{file}. @value{GDBN} appends the trace info to the previous
12746contents of the file. The default is to display the trace on the
12747standard output.
12748
12749@item show procfs-file
12750@kindex show procfs-file
12751Show the file to which @code{procfs} API trace is written.
12752
12753@item proc-trace-entry
12754@itemx proc-trace-exit
12755@itemx proc-untrace-entry
12756@itemx proc-untrace-exit
12757@kindex proc-trace-entry
12758@kindex proc-trace-exit
12759@kindex proc-untrace-entry
12760@kindex proc-untrace-exit
12761These commands enable and disable tracing of entries into and exits
12762from the @code{syscall} interface.
12763
12764@item info pidlist
12765@kindex info pidlist
12766@cindex process list, QNX Neutrino
12767For QNX Neutrino only, this command displays the list of all the
12768processes and all the threads within each process.
12769
12770@item info meminfo
12771@kindex info meminfo
12772@cindex mapinfo list, QNX Neutrino
12773For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 12774@end table
104c1213 12775
8e04817f
AC
12776@node DJGPP Native
12777@subsection Features for Debugging @sc{djgpp} Programs
12778@cindex @sc{djgpp} debugging
12779@cindex native @sc{djgpp} debugging
12780@cindex MS-DOS-specific commands
104c1213 12781
514c4d71
EZ
12782@cindex DPMI
12783@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
12784MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
12785that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
12786top of real-mode DOS systems and their emulations.
104c1213 12787
8e04817f
AC
12788@value{GDBN} supports native debugging of @sc{djgpp} programs, and
12789defines a few commands specific to the @sc{djgpp} port. This
12790subsection describes those commands.
104c1213 12791
8e04817f
AC
12792@table @code
12793@kindex info dos
12794@item info dos
12795This is a prefix of @sc{djgpp}-specific commands which print
12796information about the target system and important OS structures.
f1251bdd 12797
8e04817f
AC
12798@kindex sysinfo
12799@cindex MS-DOS system info
12800@cindex free memory information (MS-DOS)
12801@item info dos sysinfo
12802This command displays assorted information about the underlying
12803platform: the CPU type and features, the OS version and flavor, the
12804DPMI version, and the available conventional and DPMI memory.
104c1213 12805
8e04817f
AC
12806@cindex GDT
12807@cindex LDT
12808@cindex IDT
12809@cindex segment descriptor tables
12810@cindex descriptor tables display
12811@item info dos gdt
12812@itemx info dos ldt
12813@itemx info dos idt
12814These 3 commands display entries from, respectively, Global, Local,
12815and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
12816tables are data structures which store a descriptor for each segment
12817that is currently in use. The segment's selector is an index into a
12818descriptor table; the table entry for that index holds the
12819descriptor's base address and limit, and its attributes and access
12820rights.
104c1213 12821
8e04817f
AC
12822A typical @sc{djgpp} program uses 3 segments: a code segment, a data
12823segment (used for both data and the stack), and a DOS segment (which
12824allows access to DOS/BIOS data structures and absolute addresses in
12825conventional memory). However, the DPMI host will usually define
12826additional segments in order to support the DPMI environment.
d4f3574e 12827
8e04817f
AC
12828@cindex garbled pointers
12829These commands allow to display entries from the descriptor tables.
12830Without an argument, all entries from the specified table are
12831displayed. An argument, which should be an integer expression, means
12832display a single entry whose index is given by the argument. For
12833example, here's a convenient way to display information about the
12834debugged program's data segment:
104c1213 12835
8e04817f
AC
12836@smallexample
12837@exdent @code{(@value{GDBP}) info dos ldt $ds}
12838@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
12839@end smallexample
104c1213 12840
8e04817f
AC
12841@noindent
12842This comes in handy when you want to see whether a pointer is outside
12843the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 12844
8e04817f
AC
12845@cindex page tables display (MS-DOS)
12846@item info dos pde
12847@itemx info dos pte
12848These two commands display entries from, respectively, the Page
12849Directory and the Page Tables. Page Directories and Page Tables are
12850data structures which control how virtual memory addresses are mapped
12851into physical addresses. A Page Table includes an entry for every
12852page of memory that is mapped into the program's address space; there
12853may be several Page Tables, each one holding up to 4096 entries. A
12854Page Directory has up to 4096 entries, one each for every Page Table
12855that is currently in use.
104c1213 12856
8e04817f
AC
12857Without an argument, @kbd{info dos pde} displays the entire Page
12858Directory, and @kbd{info dos pte} displays all the entries in all of
12859the Page Tables. An argument, an integer expression, given to the
12860@kbd{info dos pde} command means display only that entry from the Page
12861Directory table. An argument given to the @kbd{info dos pte} command
12862means display entries from a single Page Table, the one pointed to by
12863the specified entry in the Page Directory.
104c1213 12864
8e04817f
AC
12865@cindex direct memory access (DMA) on MS-DOS
12866These commands are useful when your program uses @dfn{DMA} (Direct
12867Memory Access), which needs physical addresses to program the DMA
12868controller.
104c1213 12869
8e04817f 12870These commands are supported only with some DPMI servers.
104c1213 12871
8e04817f
AC
12872@cindex physical address from linear address
12873@item info dos address-pte @var{addr}
12874This command displays the Page Table entry for a specified linear
514c4d71
EZ
12875address. The argument @var{addr} is a linear address which should
12876already have the appropriate segment's base address added to it,
12877because this command accepts addresses which may belong to @emph{any}
12878segment. For example, here's how to display the Page Table entry for
12879the page where a variable @code{i} is stored:
104c1213 12880
b383017d 12881@smallexample
8e04817f
AC
12882@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
12883@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 12884@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 12885@end smallexample
104c1213 12886
8e04817f
AC
12887@noindent
12888This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 12889whose physical base address is @code{0x02698000}, and shows all the
8e04817f 12890attributes of that page.
104c1213 12891
8e04817f
AC
12892Note that you must cast the addresses of variables to a @code{char *},
12893since otherwise the value of @code{__djgpp_base_address}, the base
12894address of all variables and functions in a @sc{djgpp} program, will
12895be added using the rules of C pointer arithmetics: if @code{i} is
12896declared an @code{int}, @value{GDBN} will add 4 times the value of
12897@code{__djgpp_base_address} to the address of @code{i}.
104c1213 12898
8e04817f
AC
12899Here's another example, it displays the Page Table entry for the
12900transfer buffer:
104c1213 12901
8e04817f
AC
12902@smallexample
12903@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
12904@exdent @code{Page Table entry for address 0x29110:}
12905@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
12906@end smallexample
104c1213 12907
8e04817f
AC
12908@noindent
12909(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
129103rd member of the @code{_go32_info_block} structure.) The output
12911clearly shows that this DPMI server maps the addresses in conventional
12912memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
12913linear (@code{0x29110}) addresses are identical.
104c1213 12914
8e04817f
AC
12915This command is supported only with some DPMI servers.
12916@end table
104c1213 12917
c45da7e6 12918@cindex DOS serial data link, remote debugging
a8f24a35
EZ
12919In addition to native debugging, the DJGPP port supports remote
12920debugging via a serial data link. The following commands are specific
12921to remote serial debugging in the DJGPP port of @value{GDBN}.
12922
12923@table @code
12924@kindex set com1base
12925@kindex set com1irq
12926@kindex set com2base
12927@kindex set com2irq
12928@kindex set com3base
12929@kindex set com3irq
12930@kindex set com4base
12931@kindex set com4irq
12932@item set com1base @var{addr}
12933This command sets the base I/O port address of the @file{COM1} serial
12934port.
12935
12936@item set com1irq @var{irq}
12937This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
12938for the @file{COM1} serial port.
12939
12940There are similar commands @samp{set com2base}, @samp{set com3irq},
12941etc.@: for setting the port address and the @code{IRQ} lines for the
12942other 3 COM ports.
12943
12944@kindex show com1base
12945@kindex show com1irq
12946@kindex show com2base
12947@kindex show com2irq
12948@kindex show com3base
12949@kindex show com3irq
12950@kindex show com4base
12951@kindex show com4irq
12952The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
12953display the current settings of the base address and the @code{IRQ}
12954lines used by the COM ports.
c45da7e6
EZ
12955
12956@item info serial
12957@kindex info serial
12958@cindex DOS serial port status
12959This command prints the status of the 4 DOS serial ports. For each
12960port, it prints whether it's active or not, its I/O base address and
12961IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
12962counts of various errors encountered so far.
a8f24a35
EZ
12963@end table
12964
12965
78c47bea
PM
12966@node Cygwin Native
12967@subsection Features for Debugging MS Windows PE executables
12968@cindex MS Windows debugging
12969@cindex native Cygwin debugging
12970@cindex Cygwin-specific commands
12971
be448670
CF
12972@value{GDBN} supports native debugging of MS Windows programs, including
12973DLLs with and without symbolic debugging information. There are various
12974additional Cygwin-specific commands, described in this subsection. The
12975subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
12976that have no debugging symbols.
12977
78c47bea
PM
12978
12979@table @code
12980@kindex info w32
12981@item info w32
12982This is a prefix of MS Windows specific commands which print
12983information about the target system and important OS structures.
12984
12985@item info w32 selector
12986This command displays information returned by
12987the Win32 API @code{GetThreadSelectorEntry} function.
12988It takes an optional argument that is evaluated to
12989a long value to give the information about this given selector.
12990Without argument, this command displays information
12991about the the six segment registers.
12992
12993@kindex info dll
12994@item info dll
12995This is a Cygwin specific alias of info shared.
12996
12997@kindex dll-symbols
12998@item dll-symbols
12999This command loads symbols from a dll similarly to
13000add-sym command but without the need to specify a base address.
13001
b383017d 13002@kindex set new-console
78c47bea 13003@item set new-console @var{mode}
b383017d 13004If @var{mode} is @code{on} the debuggee will
78c47bea
PM
13005be started in a new console on next start.
13006If @var{mode} is @code{off}i, the debuggee will
13007be started in the same console as the debugger.
13008
13009@kindex show new-console
13010@item show new-console
13011Displays whether a new console is used
13012when the debuggee is started.
13013
13014@kindex set new-group
13015@item set new-group @var{mode}
13016This boolean value controls whether the debuggee should
13017start a new group or stay in the same group as the debugger.
13018This affects the way the Windows OS handles
13019Ctrl-C.
13020
13021@kindex show new-group
13022@item show new-group
13023Displays current value of new-group boolean.
13024
13025@kindex set debugevents
13026@item set debugevents
13027This boolean value adds debug output concerning events seen by the debugger.
13028
13029@kindex set debugexec
13030@item set debugexec
b383017d 13031This boolean value adds debug output concerning execute events
78c47bea
PM
13032seen by the debugger.
13033
13034@kindex set debugexceptions
13035@item set debugexceptions
b383017d 13036This boolean value adds debug ouptut concerning exception events
78c47bea
PM
13037seen by the debugger.
13038
13039@kindex set debugmemory
13040@item set debugmemory
b383017d 13041This boolean value adds debug ouptut concerning memory events
78c47bea
PM
13042seen by the debugger.
13043
13044@kindex set shell
13045@item set shell
13046This boolean values specifies whether the debuggee is called
13047via a shell or directly (default value is on).
13048
13049@kindex show shell
13050@item show shell
13051Displays if the debuggee will be started with a shell.
13052
13053@end table
13054
be448670
CF
13055@menu
13056* Non-debug DLL symbols:: Support for DLLs without debugging symbols
13057@end menu
13058
13059@node Non-debug DLL symbols
13060@subsubsection Support for DLLs without debugging symbols
13061@cindex DLLs with no debugging symbols
13062@cindex Minimal symbols and DLLs
13063
13064Very often on windows, some of the DLLs that your program relies on do
13065not include symbolic debugging information (for example,
13066@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
13067symbols in a DLL, it relies on the minimal amount of symbolic
13068information contained in the DLL's export table. This subsubsection
13069describes working with such symbols, known internally to @value{GDBN} as
13070``minimal symbols''.
13071
13072Note that before the debugged program has started execution, no DLLs
13073will have been loaded. The easiest way around this problem is simply to
13074start the program --- either by setting a breakpoint or letting the
13075program run once to completion. It is also possible to force
13076@value{GDBN} to load a particular DLL before starting the executable ---
13077see the shared library information in @pxref{Files} or the
13078@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
13079explicitly loading symbols from a DLL with no debugging information will
13080cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
13081which may adversely affect symbol lookup performance.
13082
13083@subsubsection DLL name prefixes
13084
13085In keeping with the naming conventions used by the Microsoft debugging
13086tools, DLL export symbols are made available with a prefix based on the
13087DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
13088also entered into the symbol table, so @code{CreateFileA} is often
13089sufficient. In some cases there will be name clashes within a program
13090(particularly if the executable itself includes full debugging symbols)
13091necessitating the use of the fully qualified name when referring to the
13092contents of the DLL. Use single-quotes around the name to avoid the
13093exclamation mark (``!'') being interpreted as a language operator.
13094
13095Note that the internal name of the DLL may be all upper-case, even
13096though the file name of the DLL is lower-case, or vice-versa. Since
13097symbols within @value{GDBN} are @emph{case-sensitive} this may cause
13098some confusion. If in doubt, try the @code{info functions} and
13099@code{info variables} commands or even @code{maint print msymbols} (see
13100@pxref{Symbols}). Here's an example:
13101
13102@smallexample
f7dc1244 13103(@value{GDBP}) info function CreateFileA
be448670
CF
13104All functions matching regular expression "CreateFileA":
13105
13106Non-debugging symbols:
131070x77e885f4 CreateFileA
131080x77e885f4 KERNEL32!CreateFileA
13109@end smallexample
13110
13111@smallexample
f7dc1244 13112(@value{GDBP}) info function !
be448670
CF
13113All functions matching regular expression "!":
13114
13115Non-debugging symbols:
131160x6100114c cygwin1!__assert
131170x61004034 cygwin1!_dll_crt0@@0
131180x61004240 cygwin1!dll_crt0(per_process *)
13119[etc...]
13120@end smallexample
13121
13122@subsubsection Working with minimal symbols
13123
13124Symbols extracted from a DLL's export table do not contain very much
13125type information. All that @value{GDBN} can do is guess whether a symbol
13126refers to a function or variable depending on the linker section that
13127contains the symbol. Also note that the actual contents of the memory
13128contained in a DLL are not available unless the program is running. This
13129means that you cannot examine the contents of a variable or disassemble
13130a function within a DLL without a running program.
13131
13132Variables are generally treated as pointers and dereferenced
13133automatically. For this reason, it is often necessary to prefix a
13134variable name with the address-of operator (``&'') and provide explicit
13135type information in the command. Here's an example of the type of
13136problem:
13137
13138@smallexample
f7dc1244 13139(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
13140$1 = 268572168
13141@end smallexample
13142
13143@smallexample
f7dc1244 13144(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
131450x10021610: "\230y\""
13146@end smallexample
13147
13148And two possible solutions:
13149
13150@smallexample
f7dc1244 13151(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
13152$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
13153@end smallexample
13154
13155@smallexample
f7dc1244 13156(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 131570x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 13158(@value{GDBP}) x/x 0x10021608
be448670 131590x10021608: 0x0022fd98
f7dc1244 13160(@value{GDBP}) x/s 0x0022fd98
be448670
CF
131610x22fd98: "/cygdrive/c/mydirectory/myprogram"
13162@end smallexample
13163
13164Setting a break point within a DLL is possible even before the program
13165starts execution. However, under these circumstances, @value{GDBN} can't
13166examine the initial instructions of the function in order to skip the
13167function's frame set-up code. You can work around this by using ``*&''
13168to set the breakpoint at a raw memory address:
13169
13170@smallexample
f7dc1244 13171(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
13172Breakpoint 1 at 0x1e04eff0
13173@end smallexample
13174
13175The author of these extensions is not entirely convinced that setting a
13176break point within a shared DLL like @file{kernel32.dll} is completely
13177safe.
13178
14d6dd68
EZ
13179@node Hurd Native
13180@subsection Commands specific to @sc{gnu} Hurd systems
13181@cindex @sc{gnu} Hurd debugging
13182
13183This subsection describes @value{GDBN} commands specific to the
13184@sc{gnu} Hurd native debugging.
13185
13186@table @code
13187@item set signals
13188@itemx set sigs
13189@kindex set signals@r{, Hurd command}
13190@kindex set sigs@r{, Hurd command}
13191This command toggles the state of inferior signal interception by
13192@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
13193affected by this command. @code{sigs} is a shorthand alias for
13194@code{signals}.
13195
13196@item show signals
13197@itemx show sigs
13198@kindex show signals@r{, Hurd command}
13199@kindex show sigs@r{, Hurd command}
13200Show the current state of intercepting inferior's signals.
13201
13202@item set signal-thread
13203@itemx set sigthread
13204@kindex set signal-thread
13205@kindex set sigthread
13206This command tells @value{GDBN} which thread is the @code{libc} signal
13207thread. That thread is run when a signal is delivered to a running
13208process. @code{set sigthread} is the shorthand alias of @code{set
13209signal-thread}.
13210
13211@item show signal-thread
13212@itemx show sigthread
13213@kindex show signal-thread
13214@kindex show sigthread
13215These two commands show which thread will run when the inferior is
13216delivered a signal.
13217
13218@item set stopped
13219@kindex set stopped@r{, Hurd command}
13220This commands tells @value{GDBN} that the inferior process is stopped,
13221as with the @code{SIGSTOP} signal. The stopped process can be
13222continued by delivering a signal to it.
13223
13224@item show stopped
13225@kindex show stopped@r{, Hurd command}
13226This command shows whether @value{GDBN} thinks the debuggee is
13227stopped.
13228
13229@item set exceptions
13230@kindex set exceptions@r{, Hurd command}
13231Use this command to turn off trapping of exceptions in the inferior.
13232When exception trapping is off, neither breakpoints nor
13233single-stepping will work. To restore the default, set exception
13234trapping on.
13235
13236@item show exceptions
13237@kindex show exceptions@r{, Hurd command}
13238Show the current state of trapping exceptions in the inferior.
13239
13240@item set task pause
13241@kindex set task@r{, Hurd commands}
13242@cindex task attributes (@sc{gnu} Hurd)
13243@cindex pause current task (@sc{gnu} Hurd)
13244This command toggles task suspension when @value{GDBN} has control.
13245Setting it to on takes effect immediately, and the task is suspended
13246whenever @value{GDBN} gets control. Setting it to off will take
13247effect the next time the inferior is continued. If this option is set
13248to off, you can use @code{set thread default pause on} or @code{set
13249thread pause on} (see below) to pause individual threads.
13250
13251@item show task pause
13252@kindex show task@r{, Hurd commands}
13253Show the current state of task suspension.
13254
13255@item set task detach-suspend-count
13256@cindex task suspend count
13257@cindex detach from task, @sc{gnu} Hurd
13258This command sets the suspend count the task will be left with when
13259@value{GDBN} detaches from it.
13260
13261@item show task detach-suspend-count
13262Show the suspend count the task will be left with when detaching.
13263
13264@item set task exception-port
13265@itemx set task excp
13266@cindex task exception port, @sc{gnu} Hurd
13267This command sets the task exception port to which @value{GDBN} will
13268forward exceptions. The argument should be the value of the @dfn{send
13269rights} of the task. @code{set task excp} is a shorthand alias.
13270
13271@item set noninvasive
13272@cindex noninvasive task options
13273This command switches @value{GDBN} to a mode that is the least
13274invasive as far as interfering with the inferior is concerned. This
13275is the same as using @code{set task pause}, @code{set exceptions}, and
13276@code{set signals} to values opposite to the defaults.
13277
13278@item info send-rights
13279@itemx info receive-rights
13280@itemx info port-rights
13281@itemx info port-sets
13282@itemx info dead-names
13283@itemx info ports
13284@itemx info psets
13285@cindex send rights, @sc{gnu} Hurd
13286@cindex receive rights, @sc{gnu} Hurd
13287@cindex port rights, @sc{gnu} Hurd
13288@cindex port sets, @sc{gnu} Hurd
13289@cindex dead names, @sc{gnu} Hurd
13290These commands display information about, respectively, send rights,
13291receive rights, port rights, port sets, and dead names of a task.
13292There are also shorthand aliases: @code{info ports} for @code{info
13293port-rights} and @code{info psets} for @code{info port-sets}.
13294
13295@item set thread pause
13296@kindex set thread@r{, Hurd command}
13297@cindex thread properties, @sc{gnu} Hurd
13298@cindex pause current thread (@sc{gnu} Hurd)
13299This command toggles current thread suspension when @value{GDBN} has
13300control. Setting it to on takes effect immediately, and the current
13301thread is suspended whenever @value{GDBN} gets control. Setting it to
13302off will take effect the next time the inferior is continued.
13303Normally, this command has no effect, since when @value{GDBN} has
13304control, the whole task is suspended. However, if you used @code{set
13305task pause off} (see above), this command comes in handy to suspend
13306only the current thread.
13307
13308@item show thread pause
13309@kindex show thread@r{, Hurd command}
13310This command shows the state of current thread suspension.
13311
13312@item set thread run
13313This comamnd sets whether the current thread is allowed to run.
13314
13315@item show thread run
13316Show whether the current thread is allowed to run.
13317
13318@item set thread detach-suspend-count
13319@cindex thread suspend count, @sc{gnu} Hurd
13320@cindex detach from thread, @sc{gnu} Hurd
13321This command sets the suspend count @value{GDBN} will leave on a
13322thread when detaching. This number is relative to the suspend count
13323found by @value{GDBN} when it notices the thread; use @code{set thread
13324takeover-suspend-count} to force it to an absolute value.
13325
13326@item show thread detach-suspend-count
13327Show the suspend count @value{GDBN} will leave on the thread when
13328detaching.
13329
13330@item set thread exception-port
13331@itemx set thread excp
13332Set the thread exception port to which to forward exceptions. This
13333overrides the port set by @code{set task exception-port} (see above).
13334@code{set thread excp} is the shorthand alias.
13335
13336@item set thread takeover-suspend-count
13337Normally, @value{GDBN}'s thread suspend counts are relative to the
13338value @value{GDBN} finds when it notices each thread. This command
13339changes the suspend counts to be absolute instead.
13340
13341@item set thread default
13342@itemx show thread default
13343@cindex thread default settings, @sc{gnu} Hurd
13344Each of the above @code{set thread} commands has a @code{set thread
13345default} counterpart (e.g., @code{set thread default pause}, @code{set
13346thread default exception-port}, etc.). The @code{thread default}
13347variety of commands sets the default thread properties for all
13348threads; you can then change the properties of individual threads with
13349the non-default commands.
13350@end table
13351
13352
a64548ea
EZ
13353@node Neutrino
13354@subsection QNX Neutrino
13355@cindex QNX Neutrino
13356
13357@value{GDBN} provides the following commands specific to the QNX
13358Neutrino target:
13359
13360@table @code
13361@item set debug nto-debug
13362@kindex set debug nto-debug
13363When set to on, enables debugging messages specific to the QNX
13364Neutrino support.
13365
13366@item show debug nto-debug
13367@kindex show debug nto-debug
13368Show the current state of QNX Neutrino messages.
13369@end table
13370
13371
8e04817f
AC
13372@node Embedded OS
13373@section Embedded Operating Systems
104c1213 13374
8e04817f
AC
13375This section describes configurations involving the debugging of
13376embedded operating systems that are available for several different
13377architectures.
d4f3574e 13378
8e04817f
AC
13379@menu
13380* VxWorks:: Using @value{GDBN} with VxWorks
13381@end menu
104c1213 13382
8e04817f
AC
13383@value{GDBN} includes the ability to debug programs running on
13384various real-time operating systems.
104c1213 13385
8e04817f
AC
13386@node VxWorks
13387@subsection Using @value{GDBN} with VxWorks
104c1213 13388
8e04817f 13389@cindex VxWorks
104c1213 13390
8e04817f 13391@table @code
104c1213 13392
8e04817f
AC
13393@kindex target vxworks
13394@item target vxworks @var{machinename}
13395A VxWorks system, attached via TCP/IP. The argument @var{machinename}
13396is the target system's machine name or IP address.
104c1213 13397
8e04817f 13398@end table
104c1213 13399
8e04817f
AC
13400On VxWorks, @code{load} links @var{filename} dynamically on the
13401current target system as well as adding its symbols in @value{GDBN}.
104c1213 13402
8e04817f
AC
13403@value{GDBN} enables developers to spawn and debug tasks running on networked
13404VxWorks targets from a Unix host. Already-running tasks spawned from
13405the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
13406both the Unix host and on the VxWorks target. The program
13407@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
13408installed with the name @code{vxgdb}, to distinguish it from a
13409@value{GDBN} for debugging programs on the host itself.)
104c1213 13410
8e04817f
AC
13411@table @code
13412@item VxWorks-timeout @var{args}
13413@kindex vxworks-timeout
13414All VxWorks-based targets now support the option @code{vxworks-timeout}.
13415This option is set by the user, and @var{args} represents the number of
13416seconds @value{GDBN} waits for responses to rpc's. You might use this if
13417your VxWorks target is a slow software simulator or is on the far side
13418of a thin network line.
13419@end table
104c1213 13420
8e04817f
AC
13421The following information on connecting to VxWorks was current when
13422this manual was produced; newer releases of VxWorks may use revised
13423procedures.
104c1213 13424
4644b6e3 13425@findex INCLUDE_RDB
8e04817f
AC
13426To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
13427to include the remote debugging interface routines in the VxWorks
13428library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
13429VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
13430kernel. The resulting kernel contains @file{rdb.a}, and spawns the
13431source debugging task @code{tRdbTask} when VxWorks is booted. For more
13432information on configuring and remaking VxWorks, see the manufacturer's
13433manual.
13434@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 13435
8e04817f
AC
13436Once you have included @file{rdb.a} in your VxWorks system image and set
13437your Unix execution search path to find @value{GDBN}, you are ready to
13438run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
13439@code{vxgdb}, depending on your installation).
104c1213 13440
8e04817f 13441@value{GDBN} comes up showing the prompt:
104c1213 13442
474c8240 13443@smallexample
8e04817f 13444(vxgdb)
474c8240 13445@end smallexample
104c1213 13446
8e04817f
AC
13447@menu
13448* VxWorks Connection:: Connecting to VxWorks
13449* VxWorks Download:: VxWorks download
13450* VxWorks Attach:: Running tasks
13451@end menu
104c1213 13452
8e04817f
AC
13453@node VxWorks Connection
13454@subsubsection Connecting to VxWorks
104c1213 13455
8e04817f
AC
13456The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
13457network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 13458
474c8240 13459@smallexample
8e04817f 13460(vxgdb) target vxworks tt
474c8240 13461@end smallexample
104c1213 13462
8e04817f
AC
13463@need 750
13464@value{GDBN} displays messages like these:
104c1213 13465
8e04817f
AC
13466@smallexample
13467Attaching remote machine across net...
13468Connected to tt.
13469@end smallexample
104c1213 13470
8e04817f
AC
13471@need 1000
13472@value{GDBN} then attempts to read the symbol tables of any object modules
13473loaded into the VxWorks target since it was last booted. @value{GDBN} locates
13474these files by searching the directories listed in the command search
13475path (@pxref{Environment, ,Your program's environment}); if it fails
13476to find an object file, it displays a message such as:
5d161b24 13477
474c8240 13478@smallexample
8e04817f 13479prog.o: No such file or directory.
474c8240 13480@end smallexample
104c1213 13481
8e04817f
AC
13482When this happens, add the appropriate directory to the search path with
13483the @value{GDBN} command @code{path}, and execute the @code{target}
13484command again.
104c1213 13485
8e04817f
AC
13486@node VxWorks Download
13487@subsubsection VxWorks download
104c1213 13488
8e04817f
AC
13489@cindex download to VxWorks
13490If you have connected to the VxWorks target and you want to debug an
13491object that has not yet been loaded, you can use the @value{GDBN}
13492@code{load} command to download a file from Unix to VxWorks
13493incrementally. The object file given as an argument to the @code{load}
13494command is actually opened twice: first by the VxWorks target in order
13495to download the code, then by @value{GDBN} in order to read the symbol
13496table. This can lead to problems if the current working directories on
13497the two systems differ. If both systems have NFS mounted the same
13498filesystems, you can avoid these problems by using absolute paths.
13499Otherwise, it is simplest to set the working directory on both systems
13500to the directory in which the object file resides, and then to reference
13501the file by its name, without any path. For instance, a program
13502@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
13503and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
13504program, type this on VxWorks:
104c1213 13505
474c8240 13506@smallexample
8e04817f 13507-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 13508@end smallexample
104c1213 13509
8e04817f
AC
13510@noindent
13511Then, in @value{GDBN}, type:
104c1213 13512
474c8240 13513@smallexample
8e04817f
AC
13514(vxgdb) cd @var{hostpath}/vw/demo/rdb
13515(vxgdb) load prog.o
474c8240 13516@end smallexample
104c1213 13517
8e04817f 13518@value{GDBN} displays a response similar to this:
104c1213 13519
8e04817f
AC
13520@smallexample
13521Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
13522@end smallexample
104c1213 13523
8e04817f
AC
13524You can also use the @code{load} command to reload an object module
13525after editing and recompiling the corresponding source file. Note that
13526this makes @value{GDBN} delete all currently-defined breakpoints,
13527auto-displays, and convenience variables, and to clear the value
13528history. (This is necessary in order to preserve the integrity of
13529debugger's data structures that reference the target system's symbol
13530table.)
104c1213 13531
8e04817f
AC
13532@node VxWorks Attach
13533@subsubsection Running tasks
104c1213
JM
13534
13535@cindex running VxWorks tasks
13536You can also attach to an existing task using the @code{attach} command as
13537follows:
13538
474c8240 13539@smallexample
104c1213 13540(vxgdb) attach @var{task}
474c8240 13541@end smallexample
104c1213
JM
13542
13543@noindent
13544where @var{task} is the VxWorks hexadecimal task ID. The task can be running
13545or suspended when you attach to it. Running tasks are suspended at
13546the time of attachment.
13547
6d2ebf8b 13548@node Embedded Processors
104c1213
JM
13549@section Embedded Processors
13550
13551This section goes into details specific to particular embedded
13552configurations.
13553
c45da7e6
EZ
13554@cindex send command to simulator
13555Whenever a specific embedded processor has a simulator, @value{GDBN}
13556allows to send an arbitrary command to the simulator.
13557
13558@table @code
13559@item sim @var{command}
13560@kindex sim@r{, a command}
13561Send an arbitrary @var{command} string to the simulator. Consult the
13562documentation for the specific simulator in use for information about
13563acceptable commands.
13564@end table
13565
7d86b5d5 13566
104c1213 13567@menu
c45da7e6 13568* ARM:: ARM RDI
172c2a43
KI
13569* H8/300:: Renesas H8/300
13570* H8/500:: Renesas H8/500
13571* M32R/D:: Renesas M32R/D
104c1213 13572* M68K:: Motorola M68K
104c1213 13573* MIPS Embedded:: MIPS Embedded
a37295f9 13574* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
13575* PA:: HP PA Embedded
13576* PowerPC: PowerPC
172c2a43 13577* SH:: Renesas SH
104c1213
JM
13578* Sparclet:: Tsqware Sparclet
13579* Sparclite:: Fujitsu Sparclite
13580* ST2000:: Tandem ST2000
13581* Z8000:: Zilog Z8000
a64548ea
EZ
13582* AVR:: Atmel AVR
13583* CRIS:: CRIS
13584* Super-H:: Renesas Super-H
c45da7e6 13585* WinCE:: Windows CE child processes
104c1213
JM
13586@end menu
13587
6d2ebf8b 13588@node ARM
104c1213 13589@subsection ARM
c45da7e6 13590@cindex ARM RDI
104c1213
JM
13591
13592@table @code
8e04817f
AC
13593@kindex target rdi
13594@item target rdi @var{dev}
13595ARM Angel monitor, via RDI library interface to ADP protocol. You may
13596use this target to communicate with both boards running the Angel
13597monitor, or with the EmbeddedICE JTAG debug device.
13598
13599@kindex target rdp
13600@item target rdp @var{dev}
13601ARM Demon monitor.
13602
13603@end table
13604
e2f4edfd
EZ
13605@value{GDBN} provides the following ARM-specific commands:
13606
13607@table @code
13608@item set arm disassembler
13609@kindex set arm
13610This commands selects from a list of disassembly styles. The
13611@code{"std"} style is the standard style.
13612
13613@item show arm disassembler
13614@kindex show arm
13615Show the current disassembly style.
13616
13617@item set arm apcs32
13618@cindex ARM 32-bit mode
13619This command toggles ARM operation mode between 32-bit and 26-bit.
13620
13621@item show arm apcs32
13622Display the current usage of the ARM 32-bit mode.
13623
13624@item set arm fpu @var{fputype}
13625This command sets the ARM floating-point unit (FPU) type. The
13626argument @var{fputype} can be one of these:
13627
13628@table @code
13629@item auto
13630Determine the FPU type by querying the OS ABI.
13631@item softfpa
13632Software FPU, with mixed-endian doubles on little-endian ARM
13633processors.
13634@item fpa
13635GCC-compiled FPA co-processor.
13636@item softvfp
13637Software FPU with pure-endian doubles.
13638@item vfp
13639VFP co-processor.
13640@end table
13641
13642@item show arm fpu
13643Show the current type of the FPU.
13644
13645@item set arm abi
13646This command forces @value{GDBN} to use the specified ABI.
13647
13648@item show arm abi
13649Show the currently used ABI.
13650
13651@item set debug arm
13652Toggle whether to display ARM-specific debugging messages from the ARM
13653target support subsystem.
13654
13655@item show debug arm
13656Show whether ARM-specific debugging messages are enabled.
13657@end table
13658
c45da7e6
EZ
13659The following commands are available when an ARM target is debugged
13660using the RDI interface:
13661
13662@table @code
13663@item rdilogfile @r{[}@var{file}@r{]}
13664@kindex rdilogfile
13665@cindex ADP (Angel Debugger Protocol) logging
13666Set the filename for the ADP (Angel Debugger Protocol) packet log.
13667With an argument, sets the log file to the specified @var{file}. With
13668no argument, show the current log file name. The default log file is
13669@file{rdi.log}.
13670
13671@item rdilogenable @r{[}@var{arg}@r{]}
13672@kindex rdilogenable
13673Control logging of ADP packets. With an argument of 1 or @code{"yes"}
13674enables logging, with an argument 0 or @code{"no"} disables it. With
13675no arguments displays the current setting. When logging is enabled,
13676ADP packets exchanged between @value{GDBN} and the RDI target device
13677are logged to a file.
13678
13679@item set rdiromatzero
13680@kindex set rdiromatzero
13681@cindex ROM at zero address, RDI
13682Tell @value{GDBN} whether the target has ROM at address 0. If on,
13683vector catching is disabled, so that zero address can be used. If off
13684(the default), vector catching is enabled. For this command to take
13685effect, it needs to be invoked prior to the @code{target rdi} command.
13686
13687@item show rdiromatzero
13688@kindex show rdiromatzero
13689Show the current setting of ROM at zero address.
13690
13691@item set rdiheartbeat
13692@kindex set rdiheartbeat
13693@cindex RDI heartbeat
13694Enable or disable RDI heartbeat packets. It is not recommended to
13695turn on this option, since it confuses ARM and EPI JTAG interface, as
13696well as the Angel monitor.
13697
13698@item show rdiheartbeat
13699@kindex show rdiheartbeat
13700Show the setting of RDI heartbeat packets.
13701@end table
13702
e2f4edfd 13703
8e04817f 13704@node H8/300
172c2a43 13705@subsection Renesas H8/300
8e04817f
AC
13706
13707@table @code
13708
13709@kindex target hms@r{, with H8/300}
13710@item target hms @var{dev}
172c2a43 13711A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
13712Use special commands @code{device} and @code{speed} to control the serial
13713line and the communications speed used.
13714
13715@kindex target e7000@r{, with H8/300}
13716@item target e7000 @var{dev}
172c2a43 13717E7000 emulator for Renesas H8 and SH.
8e04817f
AC
13718
13719@kindex target sh3@r{, with H8/300}
13720@kindex target sh3e@r{, with H8/300}
13721@item target sh3 @var{dev}
13722@itemx target sh3e @var{dev}
172c2a43 13723Renesas SH-3 and SH-3E target systems.
8e04817f
AC
13724
13725@end table
13726
13727@cindex download to H8/300 or H8/500
13728@cindex H8/300 or H8/500 download
172c2a43
KI
13729@cindex download to Renesas SH
13730@cindex Renesas SH download
13731When you select remote debugging to a Renesas SH, H8/300, or H8/500
13732board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
13733board and also opens it as the current executable target for
13734@value{GDBN} on your host (like the @code{file} command).
13735
13736@value{GDBN} needs to know these things to talk to your
172c2a43 13737Renesas SH, H8/300, or H8/500:
8e04817f
AC
13738
13739@enumerate
13740@item
13741that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
13742for Renesas microprocessors, or @samp{target e7000}, the in-circuit
13743emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
13744the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
13745H8/300, or H8/500.)
13746
13747@item
172c2a43 13748what serial device connects your host to your Renesas board (the first
8e04817f
AC
13749serial device available on your host is the default).
13750
13751@item
13752what speed to use over the serial device.
13753@end enumerate
13754
13755@menu
172c2a43
KI
13756* Renesas Boards:: Connecting to Renesas boards.
13757* Renesas ICE:: Using the E7000 In-Circuit Emulator.
13758* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
13759@end menu
13760
172c2a43
KI
13761@node Renesas Boards
13762@subsubsection Connecting to Renesas boards
8e04817f
AC
13763
13764@c only for Unix hosts
13765@kindex device
172c2a43 13766@cindex serial device, Renesas micros
8e04817f
AC
13767Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
13768need to explicitly set the serial device. The default @var{port} is the
13769first available port on your host. This is only necessary on Unix
13770hosts, where it is typically something like @file{/dev/ttya}.
13771
13772@kindex speed
172c2a43 13773@cindex serial line speed, Renesas micros
8e04817f
AC
13774@code{@value{GDBN}} has another special command to set the communications
13775speed: @samp{speed @var{bps}}. This command also is only used from Unix
13776hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
13777the DOS @code{mode} command (for instance,
13778@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
13779
13780The @samp{device} and @samp{speed} commands are available only when you
172c2a43 13781use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
13782use a DOS host,
13783@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
13784called @code{asynctsr} to communicate with the development board
13785through a PC serial port. You must also use the DOS @code{mode} command
13786to set up the serial port on the DOS side.
13787
13788The following sample session illustrates the steps needed to start a
13789program under @value{GDBN} control on an H8/300. The example uses a
13790sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 13791the Renesas SH and the H8/500.
8e04817f
AC
13792
13793First hook up your development board. In this example, we use a
13794board attached to serial port @code{COM2}; if you use a different serial
13795port, substitute its name in the argument of the @code{mode} command.
13796When you call @code{asynctsr}, the auxiliary comms program used by the
13797debugger, you give it just the numeric part of the serial port's name;
13798for example, @samp{asyncstr 2} below runs @code{asyncstr} on
13799@code{COM2}.
13800
474c8240 13801@smallexample
8e04817f
AC
13802C:\H8300\TEST> asynctsr 2
13803C:\H8300\TEST> mode com2:9600,n,8,1,p
13804
13805Resident portion of MODE loaded
13806
13807COM2: 9600, n, 8, 1, p
13808
474c8240 13809@end smallexample
8e04817f
AC
13810
13811@quotation
13812@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
13813@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
13814disable it, or even boot without it, to use @code{asynctsr} to control
13815your development board.
13816@end quotation
13817
13818@kindex target hms@r{, and serial protocol}
13819Now that serial communications are set up, and the development board is
9c16f35a 13820connected, you can start up @value{GDBN}. Call @code{@value{GDBN}} with
8e04817f
AC
13821the name of your program as the argument. @code{@value{GDBN}} prompts
13822you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
13823commands to begin your debugging session: @samp{target hms} to specify
172c2a43 13824cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
13825download your program to the board. @code{load} displays the names of
13826the program's sections, and a @samp{*} for each 2K of data downloaded.
13827(If you want to refresh @value{GDBN} data on symbols or on the
13828executable file without downloading, use the @value{GDBN} commands
13829@code{file} or @code{symbol-file}. These commands, and @code{load}
13830itself, are described in @ref{Files,,Commands to specify files}.)
13831
13832@smallexample
13833(eg-C:\H8300\TEST) @value{GDBP} t.x
13834@value{GDBN} is free software and you are welcome to distribute copies
13835 of it under certain conditions; type "show copying" to see
13836 the conditions.
13837There is absolutely no warranty for @value{GDBN}; type "show warranty"
13838for details.
13839@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
13840(@value{GDBP}) target hms
13841Connected to remote H8/300 HMS system.
13842(@value{GDBP}) load t.x
13843.text : 0x8000 .. 0xabde ***********
13844.data : 0xabde .. 0xad30 *
13845.stack : 0xf000 .. 0xf014 *
13846@end smallexample
13847
13848At this point, you're ready to run or debug your program. From here on,
13849you can use all the usual @value{GDBN} commands. The @code{break} command
13850sets breakpoints; the @code{run} command starts your program;
13851@code{print} or @code{x} display data; the @code{continue} command
13852resumes execution after stopping at a breakpoint. You can use the
13853@code{help} command at any time to find out more about @value{GDBN} commands.
13854
13855Remember, however, that @emph{operating system} facilities aren't
13856available on your development board; for example, if your program hangs,
13857you can't send an interrupt---but you can press the @sc{reset} switch!
13858
13859Use the @sc{reset} button on the development board
13860@itemize @bullet
13861@item
13862to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
13863no way to pass an interrupt signal to the development board); and
13864
13865@item
13866to return to the @value{GDBN} command prompt after your program finishes
13867normally. The communications protocol provides no other way for @value{GDBN}
13868to detect program completion.
13869@end itemize
13870
13871In either case, @value{GDBN} sees the effect of a @sc{reset} on the
13872development board as a ``normal exit'' of your program.
13873
172c2a43 13874@node Renesas ICE
8e04817f
AC
13875@subsubsection Using the E7000 in-circuit emulator
13876
172c2a43 13877@kindex target e7000@r{, with Renesas ICE}
8e04817f 13878You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 13879Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
13880e7000} command to connect @value{GDBN} to your E7000:
13881
13882@table @code
13883@item target e7000 @var{port} @var{speed}
13884Use this form if your E7000 is connected to a serial port. The
13885@var{port} argument identifies what serial port to use (for example,
13886@samp{com2}). The third argument is the line speed in bits per second
13887(for example, @samp{9600}).
13888
13889@item target e7000 @var{hostname}
13890If your E7000 is installed as a host on a TCP/IP network, you can just
13891specify its hostname; @value{GDBN} uses @code{telnet} to connect.
13892@end table
13893
ba04e063
EZ
13894The following special commands are available when debugging with the
13895Renesas E7000 ICE:
13896
13897@table @code
13898@item e7000 @var{command}
13899@kindex e7000
13900@cindex send command to E7000 monitor
13901This sends the specified @var{command} to the E7000 monitor.
13902
13903@item ftplogin @var{machine} @var{username} @var{password} @var{dir}
13904@kindex ftplogin@r{, E7000}
13905This command records information for subsequent interface with the
13906E7000 monitor via the FTP protocol: @value{GDBN} will log into the
13907named @var{machine} using specified @var{username} and @var{password},
13908and then chdir to the named directory @var{dir}.
13909
13910@item ftpload @var{file}
13911@kindex ftpload@r{, E7000}
13912This command uses credentials recorded by @code{ftplogin} to fetch and
13913load the named @var{file} from the E7000 monitor.
13914
13915@item drain
13916@kindex drain@r{, E7000}
13917This command drains any pending text buffers stored on the E7000.
13918
13919@item set usehardbreakpoints
13920@itemx show usehardbreakpoints
13921@kindex set usehardbreakpoints@r{, E7000}
13922@kindex show usehardbreakpoints@r{, E7000}
13923@cindex hardware breakpoints, and E7000
13924These commands set and show the use of hardware breakpoints for all
13925breakpoints. @xref{Set Breaks, hardware-assisted breakpoint}, for
13926more information about using hardware breakpoints selectively.
13927@end table
13928
172c2a43
KI
13929@node Renesas Special
13930@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
13931
13932Some @value{GDBN} commands are available only for the H8/300:
13933
13934@table @code
13935
13936@kindex set machine
13937@kindex show machine
13938@item set machine h8300
13939@itemx set machine h8300h
13940Condition @value{GDBN} for one of the two variants of the H8/300
13941architecture with @samp{set machine}. You can use @samp{show machine}
13942to check which variant is currently in effect.
104c1213
JM
13943
13944@end table
13945
8e04817f
AC
13946@node H8/500
13947@subsection H8/500
104c1213
JM
13948
13949@table @code
13950
8e04817f
AC
13951@kindex set memory @var{mod}
13952@cindex memory models, H8/500
13953@item set memory @var{mod}
13954@itemx show memory
13955Specify which H8/500 memory model (@var{mod}) you are using with
13956@samp{set memory}; check which memory model is in effect with @samp{show
13957memory}. The accepted values for @var{mod} are @code{small},
13958@code{big}, @code{medium}, and @code{compact}.
104c1213 13959
8e04817f 13960@end table
104c1213 13961
8e04817f 13962@node M32R/D
ba04e063 13963@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
13964
13965@table @code
8e04817f
AC
13966@kindex target m32r
13967@item target m32r @var{dev}
172c2a43 13968Renesas M32R/D ROM monitor.
8e04817f 13969
fb3e19c0
KI
13970@kindex target m32rsdi
13971@item target m32rsdi @var{dev}
13972Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
13973@end table
13974
13975The following @value{GDBN} commands are specific to the M32R monitor:
13976
13977@table @code
13978@item set download-path @var{path}
13979@kindex set download-path
13980@cindex find downloadable @sc{srec} files (M32R)
13981Set the default path for finding donwloadable @sc{srec} files.
13982
13983@item show download-path
13984@kindex show download-path
13985Show the default path for downloadable @sc{srec} files.
fb3e19c0 13986
721c2651
EZ
13987@item set board-address @var{addr}
13988@kindex set board-address
13989@cindex M32-EVA target board address
13990Set the IP address for the M32R-EVA target board.
13991
13992@item show board-address
13993@kindex show board-address
13994Show the current IP address of the target board.
13995
13996@item set server-address @var{addr}
13997@kindex set server-address
13998@cindex download server address (M32R)
13999Set the IP address for the download server, which is the @value{GDBN}'s
14000host machine.
14001
14002@item show server-address
14003@kindex show server-address
14004Display the IP address of the download server.
14005
14006@item upload @r{[}@var{file}@r{]}
14007@kindex upload@r{, M32R}
14008Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
14009upload capability. If no @var{file} argument is given, the current
14010executable file is uploaded.
14011
14012@item tload @r{[}@var{file}@r{]}
14013@kindex tload@r{, M32R}
14014Test the @code{upload} command.
8e04817f
AC
14015@end table
14016
ba04e063
EZ
14017The following commands are available for M32R/SDI:
14018
14019@table @code
14020@item sdireset
14021@kindex sdireset
14022@cindex reset SDI connection, M32R
14023This command resets the SDI connection.
14024
14025@item sdistatus
14026@kindex sdistatus
14027This command shows the SDI connection status.
14028
14029@item debug_chaos
14030@kindex debug_chaos
14031@cindex M32R/Chaos debugging
14032Instructs the remote that M32R/Chaos debugging is to be used.
14033
14034@item use_debug_dma
14035@kindex use_debug_dma
14036Instructs the remote to use the DEBUG_DMA method of accessing memory.
14037
14038@item use_mon_code
14039@kindex use_mon_code
14040Instructs the remote to use the MON_CODE method of accessing memory.
14041
14042@item use_ib_break
14043@kindex use_ib_break
14044Instructs the remote to set breakpoints by IB break.
14045
14046@item use_dbt_break
14047@kindex use_dbt_break
14048Instructs the remote to set breakpoints by DBT.
14049@end table
14050
8e04817f
AC
14051@node M68K
14052@subsection M68k
14053
14054The Motorola m68k configuration includes ColdFire support, and
14055target command for the following ROM monitors.
14056
14057@table @code
14058
14059@kindex target abug
14060@item target abug @var{dev}
14061ABug ROM monitor for M68K.
14062
14063@kindex target cpu32bug
14064@item target cpu32bug @var{dev}
14065CPU32BUG monitor, running on a CPU32 (M68K) board.
14066
14067@kindex target dbug
14068@item target dbug @var{dev}
14069dBUG ROM monitor for Motorola ColdFire.
14070
14071@kindex target est
14072@item target est @var{dev}
14073EST-300 ICE monitor, running on a CPU32 (M68K) board.
14074
14075@kindex target rom68k
14076@item target rom68k @var{dev}
14077ROM 68K monitor, running on an M68K IDP board.
14078
14079@end table
14080
8e04817f
AC
14081@table @code
14082
14083@kindex target rombug
14084@item target rombug @var{dev}
14085ROMBUG ROM monitor for OS/9000.
14086
14087@end table
14088
8e04817f
AC
14089@node MIPS Embedded
14090@subsection MIPS Embedded
14091
14092@cindex MIPS boards
14093@value{GDBN} can use the MIPS remote debugging protocol to talk to a
14094MIPS board attached to a serial line. This is available when
14095you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 14096
8e04817f
AC
14097@need 1000
14098Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 14099
8e04817f
AC
14100@table @code
14101@item target mips @var{port}
14102@kindex target mips @var{port}
14103To run a program on the board, start up @code{@value{GDBP}} with the
14104name of your program as the argument. To connect to the board, use the
14105command @samp{target mips @var{port}}, where @var{port} is the name of
14106the serial port connected to the board. If the program has not already
14107been downloaded to the board, you may use the @code{load} command to
14108download it. You can then use all the usual @value{GDBN} commands.
104c1213 14109
8e04817f
AC
14110For example, this sequence connects to the target board through a serial
14111port, and loads and runs a program called @var{prog} through the
14112debugger:
104c1213 14113
474c8240 14114@smallexample
8e04817f
AC
14115host$ @value{GDBP} @var{prog}
14116@value{GDBN} is free software and @dots{}
14117(@value{GDBP}) target mips /dev/ttyb
14118(@value{GDBP}) load @var{prog}
14119(@value{GDBP}) run
474c8240 14120@end smallexample
104c1213 14121
8e04817f
AC
14122@item target mips @var{hostname}:@var{portnumber}
14123On some @value{GDBN} host configurations, you can specify a TCP
14124connection (for instance, to a serial line managed by a terminal
14125concentrator) instead of a serial port, using the syntax
14126@samp{@var{hostname}:@var{portnumber}}.
104c1213 14127
8e04817f
AC
14128@item target pmon @var{port}
14129@kindex target pmon @var{port}
14130PMON ROM monitor.
104c1213 14131
8e04817f
AC
14132@item target ddb @var{port}
14133@kindex target ddb @var{port}
14134NEC's DDB variant of PMON for Vr4300.
104c1213 14135
8e04817f
AC
14136@item target lsi @var{port}
14137@kindex target lsi @var{port}
14138LSI variant of PMON.
104c1213 14139
8e04817f
AC
14140@kindex target r3900
14141@item target r3900 @var{dev}
14142Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 14143
8e04817f
AC
14144@kindex target array
14145@item target array @var{dev}
14146Array Tech LSI33K RAID controller board.
104c1213 14147
8e04817f 14148@end table
104c1213 14149
104c1213 14150
8e04817f
AC
14151@noindent
14152@value{GDBN} also supports these special commands for MIPS targets:
104c1213 14153
8e04817f 14154@table @code
8e04817f
AC
14155@item set mipsfpu double
14156@itemx set mipsfpu single
14157@itemx set mipsfpu none
a64548ea 14158@itemx set mipsfpu auto
8e04817f
AC
14159@itemx show mipsfpu
14160@kindex set mipsfpu
14161@kindex show mipsfpu
14162@cindex MIPS remote floating point
14163@cindex floating point, MIPS remote
14164If your target board does not support the MIPS floating point
14165coprocessor, you should use the command @samp{set mipsfpu none} (if you
14166need this, you may wish to put the command in your @value{GDBN} init
14167file). This tells @value{GDBN} how to find the return value of
14168functions which return floating point values. It also allows
14169@value{GDBN} to avoid saving the floating point registers when calling
14170functions on the board. If you are using a floating point coprocessor
14171with only single precision floating point support, as on the @sc{r4650}
14172processor, use the command @samp{set mipsfpu single}. The default
14173double precision floating point coprocessor may be selected using
14174@samp{set mipsfpu double}.
104c1213 14175
8e04817f
AC
14176In previous versions the only choices were double precision or no
14177floating point, so @samp{set mipsfpu on} will select double precision
14178and @samp{set mipsfpu off} will select no floating point.
104c1213 14179
8e04817f
AC
14180As usual, you can inquire about the @code{mipsfpu} variable with
14181@samp{show mipsfpu}.
104c1213 14182
8e04817f
AC
14183@item set timeout @var{seconds}
14184@itemx set retransmit-timeout @var{seconds}
14185@itemx show timeout
14186@itemx show retransmit-timeout
14187@cindex @code{timeout}, MIPS protocol
14188@cindex @code{retransmit-timeout}, MIPS protocol
14189@kindex set timeout
14190@kindex show timeout
14191@kindex set retransmit-timeout
14192@kindex show retransmit-timeout
14193You can control the timeout used while waiting for a packet, in the MIPS
14194remote protocol, with the @code{set timeout @var{seconds}} command. The
14195default is 5 seconds. Similarly, you can control the timeout used while
14196waiting for an acknowledgement of a packet with the @code{set
14197retransmit-timeout @var{seconds}} command. The default is 3 seconds.
14198You can inspect both values with @code{show timeout} and @code{show
14199retransmit-timeout}. (These commands are @emph{only} available when
14200@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 14201
8e04817f
AC
14202The timeout set by @code{set timeout} does not apply when @value{GDBN}
14203is waiting for your program to stop. In that case, @value{GDBN} waits
14204forever because it has no way of knowing how long the program is going
14205to run before stopping.
ba04e063
EZ
14206
14207@item set syn-garbage-limit @var{num}
14208@kindex set syn-garbage-limit@r{, MIPS remote}
14209@cindex synchronize with remote MIPS target
14210Limit the maximum number of characters @value{GDBN} should ignore when
14211it tries to synchronize with the remote target. The default is 10
14212characters. Setting the limit to -1 means there's no limit.
14213
14214@item show syn-garbage-limit
14215@kindex show syn-garbage-limit@r{, MIPS remote}
14216Show the current limit on the number of characters to ignore when
14217trying to synchronize with the remote system.
14218
14219@item set monitor-prompt @var{prompt}
14220@kindex set monitor-prompt@r{, MIPS remote}
14221@cindex remote monitor prompt
14222Tell @value{GDBN} to expect the specified @var{prompt} string from the
14223remote monitor. The default depends on the target:
14224@table @asis
14225@item pmon target
14226@samp{PMON}
14227@item ddb target
14228@samp{NEC010}
14229@item lsi target
14230@samp{PMON>}
14231@end table
14232
14233@item show monitor-prompt
14234@kindex show monitor-prompt@r{, MIPS remote}
14235Show the current strings @value{GDBN} expects as the prompt from the
14236remote monitor.
14237
14238@item set monitor-warnings
14239@kindex set monitor-warnings@r{, MIPS remote}
14240Enable or disable monitor warnings about hardware breakpoints. This
14241has effect only for the @code{lsi} target. When on, @value{GDBN} will
14242display warning messages whose codes are returned by the @code{lsi}
14243PMON monitor for breakpoint commands.
14244
14245@item show monitor-warnings
14246@kindex show monitor-warnings@r{, MIPS remote}
14247Show the current setting of printing monitor warnings.
14248
14249@item pmon @var{command}
14250@kindex pmon@r{, MIPS remote}
14251@cindex send PMON command
14252This command allows sending an arbitrary @var{command} string to the
14253monitor. The monitor must be in debug mode for this to work.
8e04817f 14254@end table
104c1213 14255
a37295f9
MM
14256@node OpenRISC 1000
14257@subsection OpenRISC 1000
14258@cindex OpenRISC 1000
14259
14260@cindex or1k boards
14261See OR1k Architecture document (@uref{www.opencores.org}) for more information
14262about platform and commands.
14263
14264@table @code
14265
14266@kindex target jtag
14267@item target jtag jtag://@var{host}:@var{port}
14268
14269Connects to remote JTAG server.
14270JTAG remote server can be either an or1ksim or JTAG server,
14271connected via parallel port to the board.
14272
14273Example: @code{target jtag jtag://localhost:9999}
14274
14275@kindex or1ksim
14276@item or1ksim @var{command}
14277If connected to @code{or1ksim} OpenRISC 1000 Architectural
14278Simulator, proprietary commands can be executed.
14279
14280@kindex info or1k spr
14281@item info or1k spr
14282Displays spr groups.
14283
14284@item info or1k spr @var{group}
14285@itemx info or1k spr @var{groupno}
14286Displays register names in selected group.
14287
14288@item info or1k spr @var{group} @var{register}
14289@itemx info or1k spr @var{register}
14290@itemx info or1k spr @var{groupno} @var{registerno}
14291@itemx info or1k spr @var{registerno}
14292Shows information about specified spr register.
14293
14294@kindex spr
14295@item spr @var{group} @var{register} @var{value}
14296@itemx spr @var{register @var{value}}
14297@itemx spr @var{groupno} @var{registerno @var{value}}
14298@itemx spr @var{registerno @var{value}}
14299Writes @var{value} to specified spr register.
14300@end table
14301
14302Some implementations of OpenRISC 1000 Architecture also have hardware trace.
14303It is very similar to @value{GDBN} trace, except it does not interfere with normal
14304program execution and is thus much faster. Hardware breakpoints/watchpoint
14305triggers can be set using:
14306@table @code
14307@item $LEA/$LDATA
14308Load effective address/data
14309@item $SEA/$SDATA
14310Store effective address/data
14311@item $AEA/$ADATA
14312Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
14313@item $FETCH
14314Fetch data
14315@end table
14316
14317When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
14318@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
14319
14320@code{htrace} commands:
14321@cindex OpenRISC 1000 htrace
14322@table @code
14323@kindex hwatch
14324@item hwatch @var{conditional}
14325Set hardware watchpoint on combination of Load/Store Effecive Address(es)
14326or Data. For example:
14327
14328@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14329
14330@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14331
4644b6e3 14332@kindex htrace
a37295f9
MM
14333@item htrace info
14334Display information about current HW trace configuration.
14335
a37295f9
MM
14336@item htrace trigger @var{conditional}
14337Set starting criteria for HW trace.
14338
a37295f9
MM
14339@item htrace qualifier @var{conditional}
14340Set acquisition qualifier for HW trace.
14341
a37295f9
MM
14342@item htrace stop @var{conditional}
14343Set HW trace stopping criteria.
14344
f153cc92 14345@item htrace record [@var{data}]*
a37295f9
MM
14346Selects the data to be recorded, when qualifier is met and HW trace was
14347triggered.
14348
a37295f9 14349@item htrace enable
a37295f9
MM
14350@itemx htrace disable
14351Enables/disables the HW trace.
14352
f153cc92 14353@item htrace rewind [@var{filename}]
a37295f9
MM
14354Clears currently recorded trace data.
14355
14356If filename is specified, new trace file is made and any newly collected data
14357will be written there.
14358
f153cc92 14359@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
14360Prints trace buffer, using current record configuration.
14361
a37295f9
MM
14362@item htrace mode continuous
14363Set continuous trace mode.
14364
a37295f9
MM
14365@item htrace mode suspend
14366Set suspend trace mode.
14367
14368@end table
14369
8e04817f
AC
14370@node PowerPC
14371@subsection PowerPC
104c1213
JM
14372
14373@table @code
8e04817f
AC
14374@kindex target dink32
14375@item target dink32 @var{dev}
14376DINK32 ROM monitor.
104c1213 14377
8e04817f
AC
14378@kindex target ppcbug
14379@item target ppcbug @var{dev}
14380@kindex target ppcbug1
14381@item target ppcbug1 @var{dev}
14382PPCBUG ROM monitor for PowerPC.
104c1213 14383
8e04817f
AC
14384@kindex target sds
14385@item target sds @var{dev}
14386SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 14387@end table
8e04817f 14388
c45da7e6
EZ
14389@cindex SDS protocol
14390The following commands specifi to the SDS protocol are supported
14391by@value{GDBN}:
14392
14393@table @code
14394@item set sdstimeout @var{nsec}
14395@kindex set sdstimeout
14396Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
14397default is 2 seconds.
14398
14399@item show sdstimeout
14400@kindex show sdstimeout
14401Show the current value of the SDS timeout.
14402
14403@item sds @var{command}
14404@kindex sds@r{, a command}
14405Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
14406@end table
14407
c45da7e6 14408
8e04817f
AC
14409@node PA
14410@subsection HP PA Embedded
104c1213
JM
14411
14412@table @code
14413
8e04817f
AC
14414@kindex target op50n
14415@item target op50n @var{dev}
14416OP50N monitor, running on an OKI HPPA board.
14417
14418@kindex target w89k
14419@item target w89k @var{dev}
14420W89K monitor, running on a Winbond HPPA board.
104c1213
JM
14421
14422@end table
14423
8e04817f 14424@node SH
172c2a43 14425@subsection Renesas SH
104c1213
JM
14426
14427@table @code
14428
172c2a43 14429@kindex target hms@r{, with Renesas SH}
8e04817f 14430@item target hms @var{dev}
172c2a43 14431A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
14432commands @code{device} and @code{speed} to control the serial line and
14433the communications speed used.
104c1213 14434
172c2a43 14435@kindex target e7000@r{, with Renesas SH}
8e04817f 14436@item target e7000 @var{dev}
172c2a43 14437E7000 emulator for Renesas SH.
104c1213 14438
8e04817f
AC
14439@kindex target sh3@r{, with SH}
14440@kindex target sh3e@r{, with SH}
14441@item target sh3 @var{dev}
14442@item target sh3e @var{dev}
172c2a43 14443Renesas SH-3 and SH-3E target systems.
104c1213 14444
8e04817f 14445@end table
104c1213 14446
8e04817f
AC
14447@node Sparclet
14448@subsection Tsqware Sparclet
104c1213 14449
8e04817f
AC
14450@cindex Sparclet
14451
14452@value{GDBN} enables developers to debug tasks running on
14453Sparclet targets from a Unix host.
14454@value{GDBN} uses code that runs on
14455both the Unix host and on the Sparclet target. The program
14456@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 14457
8e04817f
AC
14458@table @code
14459@item remotetimeout @var{args}
14460@kindex remotetimeout
14461@value{GDBN} supports the option @code{remotetimeout}.
14462This option is set by the user, and @var{args} represents the number of
14463seconds @value{GDBN} waits for responses.
104c1213
JM
14464@end table
14465
8e04817f
AC
14466@cindex compiling, on Sparclet
14467When compiling for debugging, include the options @samp{-g} to get debug
14468information and @samp{-Ttext} to relocate the program to where you wish to
14469load it on the target. You may also want to add the options @samp{-n} or
14470@samp{-N} in order to reduce the size of the sections. Example:
104c1213 14471
474c8240 14472@smallexample
8e04817f 14473sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 14474@end smallexample
104c1213 14475
8e04817f 14476You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 14477
474c8240 14478@smallexample
8e04817f 14479sparclet-aout-objdump --headers --syms prog
474c8240 14480@end smallexample
104c1213 14481
8e04817f
AC
14482@cindex running, on Sparclet
14483Once you have set
14484your Unix execution search path to find @value{GDBN}, you are ready to
14485run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
14486(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 14487
8e04817f
AC
14488@value{GDBN} comes up showing the prompt:
14489
474c8240 14490@smallexample
8e04817f 14491(gdbslet)
474c8240 14492@end smallexample
104c1213
JM
14493
14494@menu
8e04817f
AC
14495* Sparclet File:: Setting the file to debug
14496* Sparclet Connection:: Connecting to Sparclet
14497* Sparclet Download:: Sparclet download
14498* Sparclet Execution:: Running and debugging
104c1213
JM
14499@end menu
14500
8e04817f
AC
14501@node Sparclet File
14502@subsubsection Setting file to debug
104c1213 14503
8e04817f 14504The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 14505
474c8240 14506@smallexample
8e04817f 14507(gdbslet) file prog
474c8240 14508@end smallexample
104c1213 14509
8e04817f
AC
14510@need 1000
14511@value{GDBN} then attempts to read the symbol table of @file{prog}.
14512@value{GDBN} locates
14513the file by searching the directories listed in the command search
14514path.
14515If the file was compiled with debug information (option "-g"), source
14516files will be searched as well.
14517@value{GDBN} locates
14518the source files by searching the directories listed in the directory search
14519path (@pxref{Environment, ,Your program's environment}).
14520If it fails
14521to find a file, it displays a message such as:
104c1213 14522
474c8240 14523@smallexample
8e04817f 14524prog: No such file or directory.
474c8240 14525@end smallexample
104c1213 14526
8e04817f
AC
14527When this happens, add the appropriate directories to the search paths with
14528the @value{GDBN} commands @code{path} and @code{dir}, and execute the
14529@code{target} command again.
104c1213 14530
8e04817f
AC
14531@node Sparclet Connection
14532@subsubsection Connecting to Sparclet
104c1213 14533
8e04817f
AC
14534The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
14535To connect to a target on serial port ``@code{ttya}'', type:
104c1213 14536
474c8240 14537@smallexample
8e04817f
AC
14538(gdbslet) target sparclet /dev/ttya
14539Remote target sparclet connected to /dev/ttya
14540main () at ../prog.c:3
474c8240 14541@end smallexample
104c1213 14542
8e04817f
AC
14543@need 750
14544@value{GDBN} displays messages like these:
104c1213 14545
474c8240 14546@smallexample
8e04817f 14547Connected to ttya.
474c8240 14548@end smallexample
104c1213 14549
8e04817f
AC
14550@node Sparclet Download
14551@subsubsection Sparclet download
104c1213 14552
8e04817f
AC
14553@cindex download to Sparclet
14554Once connected to the Sparclet target,
14555you can use the @value{GDBN}
14556@code{load} command to download the file from the host to the target.
14557The file name and load offset should be given as arguments to the @code{load}
14558command.
14559Since the file format is aout, the program must be loaded to the starting
14560address. You can use @code{objdump} to find out what this value is. The load
14561offset is an offset which is added to the VMA (virtual memory address)
14562of each of the file's sections.
14563For instance, if the program
14564@file{prog} was linked to text address 0x1201000, with data at 0x12010160
14565and bss at 0x12010170, in @value{GDBN}, type:
104c1213 14566
474c8240 14567@smallexample
8e04817f
AC
14568(gdbslet) load prog 0x12010000
14569Loading section .text, size 0xdb0 vma 0x12010000
474c8240 14570@end smallexample
104c1213 14571
8e04817f
AC
14572If the code is loaded at a different address then what the program was linked
14573to, you may need to use the @code{section} and @code{add-symbol-file} commands
14574to tell @value{GDBN} where to map the symbol table.
14575
14576@node Sparclet Execution
14577@subsubsection Running and debugging
14578
14579@cindex running and debugging Sparclet programs
14580You can now begin debugging the task using @value{GDBN}'s execution control
14581commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
14582manual for the list of commands.
14583
474c8240 14584@smallexample
8e04817f
AC
14585(gdbslet) b main
14586Breakpoint 1 at 0x12010000: file prog.c, line 3.
14587(gdbslet) run
14588Starting program: prog
14589Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
145903 char *symarg = 0;
14591(gdbslet) step
145924 char *execarg = "hello!";
14593(gdbslet)
474c8240 14594@end smallexample
8e04817f
AC
14595
14596@node Sparclite
14597@subsection Fujitsu Sparclite
104c1213
JM
14598
14599@table @code
14600
8e04817f
AC
14601@kindex target sparclite
14602@item target sparclite @var{dev}
14603Fujitsu sparclite boards, used only for the purpose of loading.
14604You must use an additional command to debug the program.
14605For example: target remote @var{dev} using @value{GDBN} standard
14606remote protocol.
104c1213
JM
14607
14608@end table
14609
8e04817f
AC
14610@node ST2000
14611@subsection Tandem ST2000
104c1213 14612
8e04817f
AC
14613@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
14614STDBUG protocol.
104c1213 14615
8e04817f
AC
14616To connect your ST2000 to the host system, see the manufacturer's
14617manual. Once the ST2000 is physically attached, you can run:
104c1213 14618
474c8240 14619@smallexample
8e04817f 14620target st2000 @var{dev} @var{speed}
474c8240 14621@end smallexample
104c1213 14622
8e04817f
AC
14623@noindent
14624to establish it as your debugging environment. @var{dev} is normally
14625the name of a serial device, such as @file{/dev/ttya}, connected to the
14626ST2000 via a serial line. You can instead specify @var{dev} as a TCP
14627connection (for example, to a serial line attached via a terminal
14628concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 14629
8e04817f
AC
14630The @code{load} and @code{attach} commands are @emph{not} defined for
14631this target; you must load your program into the ST2000 as you normally
14632would for standalone operation. @value{GDBN} reads debugging information
14633(such as symbols) from a separate, debugging version of the program
14634available on your host computer.
14635@c FIXME!! This is terribly vague; what little content is here is
14636@c basically hearsay.
104c1213 14637
8e04817f
AC
14638@cindex ST2000 auxiliary commands
14639These auxiliary @value{GDBN} commands are available to help you with the ST2000
14640environment:
104c1213 14641
8e04817f
AC
14642@table @code
14643@item st2000 @var{command}
14644@kindex st2000 @var{cmd}
14645@cindex STDBUG commands (ST2000)
14646@cindex commands to STDBUG (ST2000)
14647Send a @var{command} to the STDBUG monitor. See the manufacturer's
14648manual for available commands.
104c1213 14649
8e04817f
AC
14650@item connect
14651@cindex connect (to STDBUG)
14652Connect the controlling terminal to the STDBUG command monitor. When
14653you are done interacting with STDBUG, typing either of two character
14654sequences gets you back to the @value{GDBN} command prompt:
14655@kbd{@key{RET}~.} (Return, followed by tilde and period) or
14656@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
14657@end table
14658
8e04817f
AC
14659@node Z8000
14660@subsection Zilog Z8000
104c1213 14661
8e04817f
AC
14662@cindex Z8000
14663@cindex simulator, Z8000
14664@cindex Zilog Z8000 simulator
104c1213 14665
8e04817f
AC
14666When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
14667a Z8000 simulator.
14668
14669For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
14670unsegmented variant of the Z8000 architecture) or the Z8001 (the
14671segmented variant). The simulator recognizes which architecture is
14672appropriate by inspecting the object code.
104c1213 14673
8e04817f
AC
14674@table @code
14675@item target sim @var{args}
14676@kindex sim
14677@kindex target sim@r{, with Z8000}
14678Debug programs on a simulated CPU. If the simulator supports setup
14679options, specify them via @var{args}.
104c1213
JM
14680@end table
14681
8e04817f
AC
14682@noindent
14683After specifying this target, you can debug programs for the simulated
14684CPU in the same style as programs for your host computer; use the
14685@code{file} command to load a new program image, the @code{run} command
14686to run your program, and so on.
14687
14688As well as making available all the usual machine registers
14689(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
14690additional items of information as specially named registers:
104c1213
JM
14691
14692@table @code
14693
8e04817f
AC
14694@item cycles
14695Counts clock-ticks in the simulator.
104c1213 14696
8e04817f
AC
14697@item insts
14698Counts instructions run in the simulator.
104c1213 14699
8e04817f
AC
14700@item time
14701Execution time in 60ths of a second.
104c1213 14702
8e04817f 14703@end table
104c1213 14704
8e04817f
AC
14705You can refer to these values in @value{GDBN} expressions with the usual
14706conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
14707conditional breakpoint that suspends only after at least 5000
14708simulated clock ticks.
104c1213 14709
a64548ea
EZ
14710@node AVR
14711@subsection Atmel AVR
14712@cindex AVR
14713
14714When configured for debugging the Atmel AVR, @value{GDBN} supports the
14715following AVR-specific commands:
14716
14717@table @code
14718@item info io_registers
14719@kindex info io_registers@r{, AVR}
14720@cindex I/O registers (Atmel AVR)
14721This command displays information about the AVR I/O registers. For
14722each register, @value{GDBN} prints its number and value.
14723@end table
14724
14725@node CRIS
14726@subsection CRIS
14727@cindex CRIS
14728
14729When configured for debugging CRIS, @value{GDBN} provides the
14730following CRIS-specific commands:
14731
14732@table @code
14733@item set cris-version @var{ver}
14734@cindex CRIS version
e22e55c9
OF
14735Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
14736The CRIS version affects register names and sizes. This command is useful in
14737case autodetection of the CRIS version fails.
a64548ea
EZ
14738
14739@item show cris-version
14740Show the current CRIS version.
14741
14742@item set cris-dwarf2-cfi
14743@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
14744Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
14745Change to @samp{off} when using @code{gcc-cris} whose version is below
14746@code{R59}.
a64548ea
EZ
14747
14748@item show cris-dwarf2-cfi
14749Show the current state of using DWARF-2 CFI.
e22e55c9
OF
14750
14751@item set cris-mode @var{mode}
14752@cindex CRIS mode
14753Set the current CRIS mode to @var{mode}. It should only be changed when
14754debugging in guru mode, in which case it should be set to
14755@samp{guru} (the default is @samp{normal}).
14756
14757@item show cris-mode
14758Show the current CRIS mode.
a64548ea
EZ
14759@end table
14760
14761@node Super-H
14762@subsection Renesas Super-H
14763@cindex Super-H
14764
14765For the Renesas Super-H processor, @value{GDBN} provides these
14766commands:
14767
14768@table @code
14769@item regs
14770@kindex regs@r{, Super-H}
14771Show the values of all Super-H registers.
14772@end table
14773
c45da7e6
EZ
14774@node WinCE
14775@subsection Windows CE
14776@cindex Windows CE
14777
14778The following commands are available for Windows CE:
14779
14780@table @code
14781@item set remotedirectory @var{dir}
14782@kindex set remotedirectory
14783Tell @value{GDBN} to upload files from the named directory @var{dir}.
14784The default is @file{/gdb}, i.e.@: the root directory on the current
14785drive.
14786
14787@item show remotedirectory
14788@kindex show remotedirectory
14789Show the current value of the upload directory.
14790
14791@item set remoteupload @var{method}
14792@kindex set remoteupload
14793Set the method used to upload files to remote device. Valid values
14794for @var{method} are @samp{always}, @samp{newer}, and @samp{never}.
14795The default is @samp{newer}.
14796
14797@item show remoteupload
14798@kindex show remoteupload
14799Show the current setting of the upload method.
14800
14801@item set remoteaddhost
14802@kindex set remoteaddhost
14803Tell @value{GDBN} whether to add this host to the remote stub's
14804arguments when you debug over a network.
14805
14806@item show remoteaddhost
14807@kindex show remoteaddhost
14808Show whether to add this host to remote stub's arguments when
14809debugging over a network.
14810@end table
14811
a64548ea 14812
8e04817f
AC
14813@node Architectures
14814@section Architectures
104c1213 14815
8e04817f
AC
14816This section describes characteristics of architectures that affect
14817all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 14818
8e04817f 14819@menu
9c16f35a 14820* i386::
8e04817f
AC
14821* A29K::
14822* Alpha::
14823* MIPS::
a64548ea 14824* HPPA:: HP PA architecture
8e04817f 14825@end menu
104c1213 14826
9c16f35a
EZ
14827@node i386
14828@subsection x86 Architecture-specific issues.
14829
14830@table @code
14831@item set struct-convention @var{mode}
14832@kindex set struct-convention
14833@cindex struct return convention
14834@cindex struct/union returned in registers
14835Set the convention used by the inferior to return @code{struct}s and
14836@code{union}s from functions to @var{mode}. Possible values of
14837@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
14838default). @code{"default"} or @code{"pcc"} means that @code{struct}s
14839are returned on the stack, while @code{"reg"} means that a
14840@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
14841be returned in a register.
14842
14843@item show struct-convention
14844@kindex show struct-convention
14845Show the current setting of the convention to return @code{struct}s
14846from functions.
14847@end table
14848
8e04817f
AC
14849@node A29K
14850@subsection A29K
104c1213
JM
14851
14852@table @code
104c1213 14853
8e04817f
AC
14854@kindex set rstack_high_address
14855@cindex AMD 29K register stack
14856@cindex register stack, AMD29K
14857@item set rstack_high_address @var{address}
14858On AMD 29000 family processors, registers are saved in a separate
14859@dfn{register stack}. There is no way for @value{GDBN} to determine the
14860extent of this stack. Normally, @value{GDBN} just assumes that the
14861stack is ``large enough''. This may result in @value{GDBN} referencing
14862memory locations that do not exist. If necessary, you can get around
14863this problem by specifying the ending address of the register stack with
14864the @code{set rstack_high_address} command. The argument should be an
14865address, which you probably want to precede with @samp{0x} to specify in
14866hexadecimal.
104c1213 14867
8e04817f
AC
14868@kindex show rstack_high_address
14869@item show rstack_high_address
14870Display the current limit of the register stack, on AMD 29000 family
14871processors.
104c1213 14872
8e04817f 14873@end table
104c1213 14874
8e04817f
AC
14875@node Alpha
14876@subsection Alpha
104c1213 14877
8e04817f 14878See the following section.
104c1213 14879
8e04817f
AC
14880@node MIPS
14881@subsection MIPS
104c1213 14882
8e04817f
AC
14883@cindex stack on Alpha
14884@cindex stack on MIPS
14885@cindex Alpha stack
14886@cindex MIPS stack
14887Alpha- and MIPS-based computers use an unusual stack frame, which
14888sometimes requires @value{GDBN} to search backward in the object code to
14889find the beginning of a function.
104c1213 14890
8e04817f
AC
14891@cindex response time, MIPS debugging
14892To improve response time (especially for embedded applications, where
14893@value{GDBN} may be restricted to a slow serial line for this search)
14894you may want to limit the size of this search, using one of these
14895commands:
104c1213 14896
8e04817f
AC
14897@table @code
14898@cindex @code{heuristic-fence-post} (Alpha, MIPS)
14899@item set heuristic-fence-post @var{limit}
14900Restrict @value{GDBN} to examining at most @var{limit} bytes in its
14901search for the beginning of a function. A value of @var{0} (the
14902default) means there is no limit. However, except for @var{0}, the
14903larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
14904and therefore the longer it takes to run. You should only need to use
14905this command when debugging a stripped executable.
104c1213 14906
8e04817f
AC
14907@item show heuristic-fence-post
14908Display the current limit.
14909@end table
104c1213
JM
14910
14911@noindent
8e04817f
AC
14912These commands are available @emph{only} when @value{GDBN} is configured
14913for debugging programs on Alpha or MIPS processors.
104c1213 14914
a64548ea
EZ
14915Several MIPS-specific commands are available when debugging MIPS
14916programs:
14917
14918@table @code
14919@item set mips saved-gpreg-size @var{size}
14920@kindex set mips saved-gpreg-size
14921@cindex MIPS GP register size on stack
14922Set the size of MIPS general-purpose registers saved on the stack.
14923The argument @var{size} can be one of the following:
14924
14925@table @samp
14926@item 32
1492732-bit GP registers
14928@item 64
1492964-bit GP registers
14930@item auto
14931Use the target's default setting or autodetect the saved size from the
14932information contained in the executable. This is the default
14933@end table
14934
14935@item show mips saved-gpreg-size
14936@kindex show mips saved-gpreg-size
14937Show the current size of MIPS GP registers on the stack.
14938
14939@item set mips stack-arg-size @var{size}
14940@kindex set mips stack-arg-size
14941@cindex MIPS stack space for arguments
14942Set the amount of stack space reserved for arguments to functions.
14943The argument can be one of @code{"32"}, @code{"64"} or @code{"auto"}
14944(the default).
14945
14946@item set mips abi @var{arg}
14947@kindex set mips abi
14948@cindex set ABI for MIPS
14949Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
14950values of @var{arg} are:
14951
14952@table @samp
14953@item auto
14954The default ABI associated with the current binary (this is the
14955default).
14956@item o32
14957@item o64
14958@item n32
14959@item n64
14960@item eabi32
14961@item eabi64
14962@item auto
14963@end table
14964
14965@item show mips abi
14966@kindex show mips abi
14967Show the MIPS ABI used by @value{GDBN} to debug the inferior.
14968
14969@item set mipsfpu
14970@itemx show mipsfpu
14971@xref{MIPS Embedded, set mipsfpu}.
14972
14973@item set mips mask-address @var{arg}
14974@kindex set mips mask-address
14975@cindex MIPS addresses, masking
14976This command determines whether the most-significant 32 bits of 64-bit
14977MIPS addresses are masked off. The argument @var{arg} can be
14978@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
14979setting, which lets @value{GDBN} determine the correct value.
14980
14981@item show mips mask-address
14982@kindex show mips mask-address
14983Show whether the upper 32 bits of MIPS addresses are masked off or
14984not.
14985
14986@item set remote-mips64-transfers-32bit-regs
14987@kindex set remote-mips64-transfers-32bit-regs
14988This command controls compatibility with 64-bit MIPS targets that
14989transfer data in 32-bit quantities. If you have an old MIPS 64 target
14990that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
14991and 64 bits for other registers, set this option to @samp{on}.
14992
14993@item show remote-mips64-transfers-32bit-regs
14994@kindex show remote-mips64-transfers-32bit-regs
14995Show the current setting of compatibility with older MIPS 64 targets.
14996
14997@item set debug mips
14998@kindex set debug mips
14999This command turns on and off debugging messages for the MIPS-specific
15000target code in @value{GDBN}.
15001
15002@item show debug mips
15003@kindex show debug mips
15004Show the current setting of MIPS debugging messages.
15005@end table
15006
15007
15008@node HPPA
15009@subsection HPPA
15010@cindex HPPA support
15011
15012When @value{GDBN} is debugging te HP PA architecture, it provides the
15013following special commands:
15014
15015@table @code
15016@item set debug hppa
15017@kindex set debug hppa
15018THis command determines whether HPPA architecture specific debugging
15019messages are to be displayed.
15020
15021@item show debug hppa
15022Show whether HPPA debugging messages are displayed.
15023
15024@item maint print unwind @var{address}
15025@kindex maint print unwind@r{, HPPA}
15026This command displays the contents of the unwind table entry at the
15027given @var{address}.
15028
15029@end table
15030
104c1213 15031
8e04817f
AC
15032@node Controlling GDB
15033@chapter Controlling @value{GDBN}
15034
15035You can alter the way @value{GDBN} interacts with you by using the
15036@code{set} command. For commands controlling how @value{GDBN} displays
15037data, see @ref{Print Settings, ,Print settings}. Other settings are
15038described here.
15039
15040@menu
15041* Prompt:: Prompt
15042* Editing:: Command editing
d620b259 15043* Command History:: Command history
8e04817f
AC
15044* Screen Size:: Screen size
15045* Numbers:: Numbers
1e698235 15046* ABI:: Configuring the current ABI
8e04817f
AC
15047* Messages/Warnings:: Optional warnings and messages
15048* Debugging Output:: Optional messages about internal happenings
15049@end menu
15050
15051@node Prompt
15052@section Prompt
104c1213 15053
8e04817f 15054@cindex prompt
104c1213 15055
8e04817f
AC
15056@value{GDBN} indicates its readiness to read a command by printing a string
15057called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
15058can change the prompt string with the @code{set prompt} command. For
15059instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
15060the prompt in one of the @value{GDBN} sessions so that you can always tell
15061which one you are talking to.
104c1213 15062
8e04817f
AC
15063@emph{Note:} @code{set prompt} does not add a space for you after the
15064prompt you set. This allows you to set a prompt which ends in a space
15065or a prompt that does not.
104c1213 15066
8e04817f
AC
15067@table @code
15068@kindex set prompt
15069@item set prompt @var{newprompt}
15070Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 15071
8e04817f
AC
15072@kindex show prompt
15073@item show prompt
15074Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
15075@end table
15076
8e04817f
AC
15077@node Editing
15078@section Command editing
15079@cindex readline
15080@cindex command line editing
104c1213 15081
703663ab 15082@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
15083@sc{gnu} library provides consistent behavior for programs which provide a
15084command line interface to the user. Advantages are @sc{gnu} Emacs-style
15085or @dfn{vi}-style inline editing of commands, @code{csh}-like history
15086substitution, and a storage and recall of command history across
15087debugging sessions.
104c1213 15088
8e04817f
AC
15089You may control the behavior of command line editing in @value{GDBN} with the
15090command @code{set}.
104c1213 15091
8e04817f
AC
15092@table @code
15093@kindex set editing
15094@cindex editing
15095@item set editing
15096@itemx set editing on
15097Enable command line editing (enabled by default).
104c1213 15098
8e04817f
AC
15099@item set editing off
15100Disable command line editing.
104c1213 15101
8e04817f
AC
15102@kindex show editing
15103@item show editing
15104Show whether command line editing is enabled.
104c1213
JM
15105@end table
15106
703663ab
EZ
15107@xref{Command Line Editing}, for more details about the Readline
15108interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
15109encouraged to read that chapter.
15110
d620b259 15111@node Command History
8e04817f 15112@section Command history
703663ab 15113@cindex command history
8e04817f
AC
15114
15115@value{GDBN} can keep track of the commands you type during your
15116debugging sessions, so that you can be certain of precisely what
15117happened. Use these commands to manage the @value{GDBN} command
15118history facility.
104c1213 15119
703663ab
EZ
15120@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
15121package, to provide the history facility. @xref{Using History
15122Interactively}, for the detailed description of the History library.
15123
d620b259
NR
15124To issue a command to @value{GDBN} without affecting certain aspects of
15125the state which is seen by users, prefix it with @samp{server }. This
15126means that this command will not affect the command history, nor will it
15127affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
15128pressed on a line by itself.
15129
15130@cindex @code{server}, command prefix
15131The server prefix does not affect the recording of values into the value
15132history; to print a value without recording it into the value history,
15133use the @code{output} command instead of the @code{print} command.
15134
703663ab
EZ
15135Here is the description of @value{GDBN} commands related to command
15136history.
15137
104c1213 15138@table @code
8e04817f
AC
15139@cindex history substitution
15140@cindex history file
15141@kindex set history filename
4644b6e3 15142@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
15143@item set history filename @var{fname}
15144Set the name of the @value{GDBN} command history file to @var{fname}.
15145This is the file where @value{GDBN} reads an initial command history
15146list, and where it writes the command history from this session when it
15147exits. You can access this list through history expansion or through
15148the history command editing characters listed below. This file defaults
15149to the value of the environment variable @code{GDBHISTFILE}, or to
15150@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
15151is not set.
104c1213 15152
9c16f35a
EZ
15153@cindex save command history
15154@kindex set history save
8e04817f
AC
15155@item set history save
15156@itemx set history save on
15157Record command history in a file, whose name may be specified with the
15158@code{set history filename} command. By default, this option is disabled.
104c1213 15159
8e04817f
AC
15160@item set history save off
15161Stop recording command history in a file.
104c1213 15162
8e04817f 15163@cindex history size
9c16f35a 15164@kindex set history size
6fc08d32 15165@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
15166@item set history size @var{size}
15167Set the number of commands which @value{GDBN} keeps in its history list.
15168This defaults to the value of the environment variable
15169@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
15170@end table
15171
8e04817f 15172History expansion assigns special meaning to the character @kbd{!}.
703663ab 15173@xref{Event Designators}, for more details.
8e04817f 15174
703663ab 15175@cindex history expansion, turn on/off
8e04817f
AC
15176Since @kbd{!} is also the logical not operator in C, history expansion
15177is off by default. If you decide to enable history expansion with the
15178@code{set history expansion on} command, you may sometimes need to
15179follow @kbd{!} (when it is used as logical not, in an expression) with
15180a space or a tab to prevent it from being expanded. The readline
15181history facilities do not attempt substitution on the strings
15182@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
15183
15184The commands to control history expansion are:
104c1213
JM
15185
15186@table @code
8e04817f
AC
15187@item set history expansion on
15188@itemx set history expansion
703663ab 15189@kindex set history expansion
8e04817f 15190Enable history expansion. History expansion is off by default.
104c1213 15191
8e04817f
AC
15192@item set history expansion off
15193Disable history expansion.
104c1213 15194
8e04817f
AC
15195@c @group
15196@kindex show history
15197@item show history
15198@itemx show history filename
15199@itemx show history save
15200@itemx show history size
15201@itemx show history expansion
15202These commands display the state of the @value{GDBN} history parameters.
15203@code{show history} by itself displays all four states.
15204@c @end group
15205@end table
15206
15207@table @code
9c16f35a
EZ
15208@kindex show commands
15209@cindex show last commands
15210@cindex display command history
8e04817f
AC
15211@item show commands
15212Display the last ten commands in the command history.
104c1213 15213
8e04817f
AC
15214@item show commands @var{n}
15215Print ten commands centered on command number @var{n}.
15216
15217@item show commands +
15218Print ten commands just after the commands last printed.
104c1213
JM
15219@end table
15220
8e04817f
AC
15221@node Screen Size
15222@section Screen size
15223@cindex size of screen
15224@cindex pauses in output
104c1213 15225
8e04817f
AC
15226Certain commands to @value{GDBN} may produce large amounts of
15227information output to the screen. To help you read all of it,
15228@value{GDBN} pauses and asks you for input at the end of each page of
15229output. Type @key{RET} when you want to continue the output, or @kbd{q}
15230to discard the remaining output. Also, the screen width setting
15231determines when to wrap lines of output. Depending on what is being
15232printed, @value{GDBN} tries to break the line at a readable place,
15233rather than simply letting it overflow onto the following line.
15234
15235Normally @value{GDBN} knows the size of the screen from the terminal
15236driver software. For example, on Unix @value{GDBN} uses the termcap data base
15237together with the value of the @code{TERM} environment variable and the
15238@code{stty rows} and @code{stty cols} settings. If this is not correct,
15239you can override it with the @code{set height} and @code{set
15240width} commands:
15241
15242@table @code
15243@kindex set height
15244@kindex set width
15245@kindex show width
15246@kindex show height
15247@item set height @var{lpp}
15248@itemx show height
15249@itemx set width @var{cpl}
15250@itemx show width
15251These @code{set} commands specify a screen height of @var{lpp} lines and
15252a screen width of @var{cpl} characters. The associated @code{show}
15253commands display the current settings.
104c1213 15254
8e04817f
AC
15255If you specify a height of zero lines, @value{GDBN} does not pause during
15256output no matter how long the output is. This is useful if output is to a
15257file or to an editor buffer.
104c1213 15258
8e04817f
AC
15259Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
15260from wrapping its output.
9c16f35a
EZ
15261
15262@item set pagination on
15263@itemx set pagination off
15264@kindex set pagination
15265Turn the output pagination on or off; the default is on. Turning
15266pagination off is the alternative to @code{set height 0}.
15267
15268@item show pagination
15269@kindex show pagination
15270Show the current pagination mode.
104c1213
JM
15271@end table
15272
8e04817f
AC
15273@node Numbers
15274@section Numbers
15275@cindex number representation
15276@cindex entering numbers
104c1213 15277
8e04817f
AC
15278You can always enter numbers in octal, decimal, or hexadecimal in
15279@value{GDBN} by the usual conventions: octal numbers begin with
15280@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
15281begin with @samp{0x}. Numbers that neither begin with @samp{0} or
15282@samp{0x}, nor end with a @samp{.} are, by default, entered in base
1528310; likewise, the default display for numbers---when no particular
15284format is specified---is base 10. You can change the default base for
15285both input and output with the commands described below.
104c1213 15286
8e04817f
AC
15287@table @code
15288@kindex set input-radix
15289@item set input-radix @var{base}
15290Set the default base for numeric input. Supported choices
15291for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15292specified either unambiguously or using the current input radix; for
8e04817f 15293example, any of
104c1213 15294
8e04817f 15295@smallexample
9c16f35a
EZ
15296set input-radix 012
15297set input-radix 10.
15298set input-radix 0xa
8e04817f 15299@end smallexample
104c1213 15300
8e04817f 15301@noindent
9c16f35a 15302sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
15303leaves the input radix unchanged, no matter what it was, since
15304@samp{10}, being without any leading or trailing signs of its base, is
15305interpreted in the current radix. Thus, if the current radix is 16,
15306@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
15307change the radix.
104c1213 15308
8e04817f
AC
15309@kindex set output-radix
15310@item set output-radix @var{base}
15311Set the default base for numeric display. Supported choices
15312for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15313specified either unambiguously or using the current input radix.
104c1213 15314
8e04817f
AC
15315@kindex show input-radix
15316@item show input-radix
15317Display the current default base for numeric input.
104c1213 15318
8e04817f
AC
15319@kindex show output-radix
15320@item show output-radix
15321Display the current default base for numeric display.
9c16f35a
EZ
15322
15323@item set radix @r{[}@var{base}@r{]}
15324@itemx show radix
15325@kindex set radix
15326@kindex show radix
15327These commands set and show the default base for both input and output
15328of numbers. @code{set radix} sets the radix of input and output to
15329the same base; without an argument, it resets the radix back to its
15330default value of 10.
15331
8e04817f 15332@end table
104c1213 15333
1e698235
DJ
15334@node ABI
15335@section Configuring the current ABI
15336
15337@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
15338application automatically. However, sometimes you need to override its
15339conclusions. Use these commands to manage @value{GDBN}'s view of the
15340current ABI.
15341
98b45e30
DJ
15342@cindex OS ABI
15343@kindex set osabi
b4e9345d 15344@kindex show osabi
98b45e30
DJ
15345
15346One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 15347system targets, either via remote debugging or native emulation.
98b45e30
DJ
15348@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
15349but you can override its conclusion using the @code{set osabi} command.
15350One example where this is useful is in debugging of binaries which use
15351an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
15352not have the same identifying marks that the standard C library for your
15353platform provides.
15354
15355@table @code
15356@item show osabi
15357Show the OS ABI currently in use.
15358
15359@item set osabi
15360With no argument, show the list of registered available OS ABI's.
15361
15362@item set osabi @var{abi}
15363Set the current OS ABI to @var{abi}.
15364@end table
15365
1e698235 15366@cindex float promotion
1e698235
DJ
15367
15368Generally, the way that an argument of type @code{float} is passed to a
15369function depends on whether the function is prototyped. For a prototyped
15370(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
15371according to the architecture's convention for @code{float}. For unprototyped
15372(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
15373@code{double} and then passed.
15374
15375Unfortunately, some forms of debug information do not reliably indicate whether
15376a function is prototyped. If @value{GDBN} calls a function that is not marked
15377as prototyped, it consults @kbd{set coerce-float-to-double}.
15378
15379@table @code
a8f24a35 15380@kindex set coerce-float-to-double
1e698235
DJ
15381@item set coerce-float-to-double
15382@itemx set coerce-float-to-double on
15383Arguments of type @code{float} will be promoted to @code{double} when passed
15384to an unprototyped function. This is the default setting.
15385
15386@item set coerce-float-to-double off
15387Arguments of type @code{float} will be passed directly to unprototyped
15388functions.
9c16f35a
EZ
15389
15390@kindex show coerce-float-to-double
15391@item show coerce-float-to-double
15392Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
15393@end table
15394
f1212245
DJ
15395@kindex set cp-abi
15396@kindex show cp-abi
15397@value{GDBN} needs to know the ABI used for your program's C@t{++}
15398objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
15399used to build your application. @value{GDBN} only fully supports
15400programs with a single C@t{++} ABI; if your program contains code using
15401multiple C@t{++} ABI's or if @value{GDBN} can not identify your
15402program's ABI correctly, you can tell @value{GDBN} which ABI to use.
15403Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
15404before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
15405``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
15406use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
15407``auto''.
15408
15409@table @code
15410@item show cp-abi
15411Show the C@t{++} ABI currently in use.
15412
15413@item set cp-abi
15414With no argument, show the list of supported C@t{++} ABI's.
15415
15416@item set cp-abi @var{abi}
15417@itemx set cp-abi auto
15418Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
15419@end table
15420
8e04817f
AC
15421@node Messages/Warnings
15422@section Optional warnings and messages
104c1213 15423
9c16f35a
EZ
15424@cindex verbose operation
15425@cindex optional warnings
8e04817f
AC
15426By default, @value{GDBN} is silent about its inner workings. If you are
15427running on a slow machine, you may want to use the @code{set verbose}
15428command. This makes @value{GDBN} tell you when it does a lengthy
15429internal operation, so you will not think it has crashed.
104c1213 15430
8e04817f
AC
15431Currently, the messages controlled by @code{set verbose} are those
15432which announce that the symbol table for a source file is being read;
15433see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 15434
8e04817f
AC
15435@table @code
15436@kindex set verbose
15437@item set verbose on
15438Enables @value{GDBN} output of certain informational messages.
104c1213 15439
8e04817f
AC
15440@item set verbose off
15441Disables @value{GDBN} output of certain informational messages.
104c1213 15442
8e04817f
AC
15443@kindex show verbose
15444@item show verbose
15445Displays whether @code{set verbose} is on or off.
15446@end table
104c1213 15447
8e04817f
AC
15448By default, if @value{GDBN} encounters bugs in the symbol table of an
15449object file, it is silent; but if you are debugging a compiler, you may
15450find this information useful (@pxref{Symbol Errors, ,Errors reading
15451symbol files}).
104c1213 15452
8e04817f 15453@table @code
104c1213 15454
8e04817f
AC
15455@kindex set complaints
15456@item set complaints @var{limit}
15457Permits @value{GDBN} to output @var{limit} complaints about each type of
15458unusual symbols before becoming silent about the problem. Set
15459@var{limit} to zero to suppress all complaints; set it to a large number
15460to prevent complaints from being suppressed.
104c1213 15461
8e04817f
AC
15462@kindex show complaints
15463@item show complaints
15464Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 15465
8e04817f 15466@end table
104c1213 15467
8e04817f
AC
15468By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
15469lot of stupid questions to confirm certain commands. For example, if
15470you try to run a program which is already running:
104c1213 15471
474c8240 15472@smallexample
8e04817f
AC
15473(@value{GDBP}) run
15474The program being debugged has been started already.
15475Start it from the beginning? (y or n)
474c8240 15476@end smallexample
104c1213 15477
8e04817f
AC
15478If you are willing to unflinchingly face the consequences of your own
15479commands, you can disable this ``feature'':
104c1213 15480
8e04817f 15481@table @code
104c1213 15482
8e04817f
AC
15483@kindex set confirm
15484@cindex flinching
15485@cindex confirmation
15486@cindex stupid questions
15487@item set confirm off
15488Disables confirmation requests.
104c1213 15489
8e04817f
AC
15490@item set confirm on
15491Enables confirmation requests (the default).
104c1213 15492
8e04817f
AC
15493@kindex show confirm
15494@item show confirm
15495Displays state of confirmation requests.
15496
15497@end table
104c1213 15498
8e04817f
AC
15499@node Debugging Output
15500@section Optional messages about internal happenings
4644b6e3
EZ
15501@cindex optional debugging messages
15502
da316a69
EZ
15503@value{GDBN} has commands that enable optional debugging messages from
15504various @value{GDBN} subsystems; normally these commands are of
15505interest to @value{GDBN} maintainers, or when reporting a bug. This
15506section documents those commands.
15507
104c1213 15508@table @code
a8f24a35
EZ
15509@kindex set exec-done-display
15510@item set exec-done-display
15511Turns on or off the notification of asynchronous commands'
15512completion. When on, @value{GDBN} will print a message when an
15513asynchronous command finishes its execution. The default is off.
15514@kindex show exec-done-display
15515@item show exec-done-display
15516Displays the current setting of asynchronous command completion
15517notification.
4644b6e3
EZ
15518@kindex set debug
15519@cindex gdbarch debugging info
a8f24a35 15520@cindex architecture debugging info
8e04817f 15521@item set debug arch
a8f24a35 15522Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 15523@kindex show debug
8e04817f
AC
15524@item show debug arch
15525Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
15526@item set debug aix-thread
15527@cindex AIX threads
15528Display debugging messages about inner workings of the AIX thread
15529module.
15530@item show debug aix-thread
15531Show the current state of AIX thread debugging info display.
8e04817f 15532@item set debug event
4644b6e3 15533@cindex event debugging info
a8f24a35 15534Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 15535default is off.
8e04817f
AC
15536@item show debug event
15537Displays the current state of displaying @value{GDBN} event debugging
15538info.
8e04817f 15539@item set debug expression
4644b6e3 15540@cindex expression debugging info
721c2651
EZ
15541Turns on or off display of debugging info about @value{GDBN}
15542expression parsing. The default is off.
8e04817f 15543@item show debug expression
721c2651
EZ
15544Displays the current state of displaying debugging info about
15545@value{GDBN} expression parsing.
7453dc06 15546@item set debug frame
4644b6e3 15547@cindex frame debugging info
7453dc06
AC
15548Turns on or off display of @value{GDBN} frame debugging info. The
15549default is off.
7453dc06
AC
15550@item show debug frame
15551Displays the current state of displaying @value{GDBN} frame debugging
15552info.
30e91e0b
RC
15553@item set debug infrun
15554@cindex inferior debugging info
15555Turns on or off display of @value{GDBN} debugging info for running the inferior.
15556The default is off. @file{infrun.c} contains GDB's runtime state machine used
15557for implementing operations such as single-stepping the inferior.
15558@item show debug infrun
15559Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
15560@item set debug lin-lwp
15561@cindex @sc{gnu}/Linux LWP debug messages
15562@cindex Linux lightweight processes
721c2651 15563Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
15564@item show debug lin-lwp
15565Show the current state of Linux LWP debugging messages.
2b4855ab 15566@item set debug observer
4644b6e3 15567@cindex observer debugging info
2b4855ab
AC
15568Turns on or off display of @value{GDBN} observer debugging. This
15569includes info such as the notification of observable events.
2b4855ab
AC
15570@item show debug observer
15571Displays the current state of observer debugging.
8e04817f 15572@item set debug overload
4644b6e3 15573@cindex C@t{++} overload debugging info
8e04817f
AC
15574Turns on or off display of @value{GDBN} C@t{++} overload debugging
15575info. This includes info such as ranking of functions, etc. The default
15576is off.
8e04817f
AC
15577@item show debug overload
15578Displays the current state of displaying @value{GDBN} C@t{++} overload
15579debugging info.
8e04817f
AC
15580@cindex packets, reporting on stdout
15581@cindex serial connections, debugging
15582@item set debug remote
15583Turns on or off display of reports on all packets sent back and forth across
15584the serial line to the remote machine. The info is printed on the
15585@value{GDBN} standard output stream. The default is off.
8e04817f
AC
15586@item show debug remote
15587Displays the state of display of remote packets.
8e04817f
AC
15588@item set debug serial
15589Turns on or off display of @value{GDBN} serial debugging info. The
15590default is off.
8e04817f
AC
15591@item show debug serial
15592Displays the current state of displaying @value{GDBN} serial debugging
15593info.
c45da7e6
EZ
15594@item set debug solib-frv
15595@cindex FR-V shared-library debugging
15596Turns on or off debugging messages for FR-V shared-library code.
15597@item show debug solib-frv
15598Display the current state of FR-V shared-library code debugging
15599messages.
8e04817f 15600@item set debug target
4644b6e3 15601@cindex target debugging info
8e04817f
AC
15602Turns on or off display of @value{GDBN} target debugging info. This info
15603includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
15604default is 0. Set it to 1 to track events, and to 2 to also track the
15605value of large memory transfers. Changes to this flag do not take effect
15606until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
15607@item show debug target
15608Displays the current state of displaying @value{GDBN} target debugging
15609info.
c45da7e6 15610@item set debugvarobj
4644b6e3 15611@cindex variable object debugging info
8e04817f
AC
15612Turns on or off display of @value{GDBN} variable object debugging
15613info. The default is off.
c45da7e6 15614@item show debugvarobj
8e04817f
AC
15615Displays the current state of displaying @value{GDBN} variable object
15616debugging info.
15617@end table
104c1213 15618
8e04817f
AC
15619@node Sequences
15620@chapter Canned Sequences of Commands
104c1213 15621
8e04817f
AC
15622Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
15623command lists}), @value{GDBN} provides two ways to store sequences of
15624commands for execution as a unit: user-defined commands and command
15625files.
104c1213 15626
8e04817f
AC
15627@menu
15628* Define:: User-defined commands
15629* Hooks:: User-defined command hooks
15630* Command Files:: Command files
15631* Output:: Commands for controlled output
15632@end menu
104c1213 15633
8e04817f
AC
15634@node Define
15635@section User-defined commands
104c1213 15636
8e04817f
AC
15637@cindex user-defined command
15638A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
15639which you assign a new name as a command. This is done with the
15640@code{define} command. User commands may accept up to 10 arguments
15641separated by whitespace. Arguments are accessed within the user command
15642via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 15643
8e04817f
AC
15644@smallexample
15645define adder
15646 print $arg0 + $arg1 + $arg2
15647@end smallexample
104c1213
JM
15648
15649@noindent
8e04817f 15650To execute the command use:
104c1213 15651
8e04817f
AC
15652@smallexample
15653adder 1 2 3
15654@end smallexample
104c1213 15655
8e04817f
AC
15656@noindent
15657This defines the command @code{adder}, which prints the sum of
15658its three arguments. Note the arguments are text substitutions, so they may
15659reference variables, use complex expressions, or even perform inferior
15660functions calls.
104c1213
JM
15661
15662@table @code
104c1213 15663
8e04817f
AC
15664@kindex define
15665@item define @var{commandname}
15666Define a command named @var{commandname}. If there is already a command
15667by that name, you are asked to confirm that you want to redefine it.
104c1213 15668
8e04817f
AC
15669The definition of the command is made up of other @value{GDBN} command lines,
15670which are given following the @code{define} command. The end of these
15671commands is marked by a line containing @code{end}.
104c1213 15672
8e04817f
AC
15673@kindex if
15674@kindex else
15675@item if
09d4efe1 15676@itemx else
8e04817f
AC
15677Takes a single argument, which is an expression to evaluate.
15678It is followed by a series of commands that are executed
15679only if the expression is true (nonzero).
15680There can then optionally be a line @code{else}, followed
15681by a series of commands that are only executed if the expression
15682was false. The end of the list is marked by a line containing @code{end}.
104c1213 15683
8e04817f
AC
15684@kindex while
15685@item while
15686The syntax is similar to @code{if}: the command takes a single argument,
15687which is an expression to evaluate, and must be followed by the commands to
15688execute, one per line, terminated by an @code{end}.
15689The commands are executed repeatedly as long as the expression
15690evaluates to true.
104c1213 15691
8e04817f
AC
15692@kindex document
15693@item document @var{commandname}
15694Document the user-defined command @var{commandname}, so that it can be
15695accessed by @code{help}. The command @var{commandname} must already be
15696defined. This command reads lines of documentation just as @code{define}
15697reads the lines of the command definition, ending with @code{end}.
15698After the @code{document} command is finished, @code{help} on command
15699@var{commandname} displays the documentation you have written.
104c1213 15700
8e04817f
AC
15701You may use the @code{document} command again to change the
15702documentation of a command. Redefining the command with @code{define}
15703does not change the documentation.
104c1213 15704
c45da7e6
EZ
15705@kindex dont-repeat
15706@cindex don't repeat command
15707@item dont-repeat
15708Used inside a user-defined command, this tells @value{GDBN} that this
15709command should not be repeated when the user hits @key{RET}
15710(@pxref{Command Syntax, repeat last command}).
15711
8e04817f
AC
15712@kindex help user-defined
15713@item help user-defined
15714List all user-defined commands, with the first line of the documentation
15715(if any) for each.
104c1213 15716
8e04817f
AC
15717@kindex show user
15718@item show user
15719@itemx show user @var{commandname}
15720Display the @value{GDBN} commands used to define @var{commandname} (but
15721not its documentation). If no @var{commandname} is given, display the
15722definitions for all user-defined commands.
104c1213 15723
9c16f35a 15724@cindex infinite recusrion in user-defined commands
20f01a46
DH
15725@kindex show max-user-call-depth
15726@kindex set max-user-call-depth
15727@item show max-user-call-depth
5ca0cb28
DH
15728@itemx set max-user-call-depth
15729The value of @code{max-user-call-depth} controls how many recursion
15730levels are allowed in user-defined commands before GDB suspects an
15731infinite recursion and aborts the command.
20f01a46 15732
104c1213
JM
15733@end table
15734
8e04817f
AC
15735When user-defined commands are executed, the
15736commands of the definition are not printed. An error in any command
15737stops execution of the user-defined command.
104c1213 15738
8e04817f
AC
15739If used interactively, commands that would ask for confirmation proceed
15740without asking when used inside a user-defined command. Many @value{GDBN}
15741commands that normally print messages to say what they are doing omit the
15742messages when used in a user-defined command.
104c1213 15743
8e04817f
AC
15744@node Hooks
15745@section User-defined command hooks
15746@cindex command hooks
15747@cindex hooks, for commands
15748@cindex hooks, pre-command
104c1213 15749
8e04817f 15750@kindex hook
8e04817f
AC
15751You may define @dfn{hooks}, which are a special kind of user-defined
15752command. Whenever you run the command @samp{foo}, if the user-defined
15753command @samp{hook-foo} exists, it is executed (with no arguments)
15754before that command.
104c1213 15755
8e04817f
AC
15756@cindex hooks, post-command
15757@kindex hookpost
8e04817f
AC
15758A hook may also be defined which is run after the command you executed.
15759Whenever you run the command @samp{foo}, if the user-defined command
15760@samp{hookpost-foo} exists, it is executed (with no arguments) after
15761that command. Post-execution hooks may exist simultaneously with
15762pre-execution hooks, for the same command.
104c1213 15763
8e04817f 15764It is valid for a hook to call the command which it hooks. If this
9f1c6395 15765occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 15766
8e04817f
AC
15767@c It would be nice if hookpost could be passed a parameter indicating
15768@c if the command it hooks executed properly or not. FIXME!
104c1213 15769
8e04817f
AC
15770@kindex stop@r{, a pseudo-command}
15771In addition, a pseudo-command, @samp{stop} exists. Defining
15772(@samp{hook-stop}) makes the associated commands execute every time
15773execution stops in your program: before breakpoint commands are run,
15774displays are printed, or the stack frame is printed.
104c1213 15775
8e04817f
AC
15776For example, to ignore @code{SIGALRM} signals while
15777single-stepping, but treat them normally during normal execution,
15778you could define:
104c1213 15779
474c8240 15780@smallexample
8e04817f
AC
15781define hook-stop
15782handle SIGALRM nopass
15783end
104c1213 15784
8e04817f
AC
15785define hook-run
15786handle SIGALRM pass
15787end
104c1213 15788
8e04817f
AC
15789define hook-continue
15790handle SIGLARM pass
15791end
474c8240 15792@end smallexample
104c1213 15793
8e04817f 15794As a further example, to hook at the begining and end of the @code{echo}
b383017d 15795command, and to add extra text to the beginning and end of the message,
8e04817f 15796you could define:
104c1213 15797
474c8240 15798@smallexample
8e04817f
AC
15799define hook-echo
15800echo <<<---
15801end
104c1213 15802
8e04817f
AC
15803define hookpost-echo
15804echo --->>>\n
15805end
104c1213 15806
8e04817f
AC
15807(@value{GDBP}) echo Hello World
15808<<<---Hello World--->>>
15809(@value{GDBP})
104c1213 15810
474c8240 15811@end smallexample
104c1213 15812
8e04817f
AC
15813You can define a hook for any single-word command in @value{GDBN}, but
15814not for command aliases; you should define a hook for the basic command
15815name, e.g. @code{backtrace} rather than @code{bt}.
15816@c FIXME! So how does Joe User discover whether a command is an alias
15817@c or not?
15818If an error occurs during the execution of your hook, execution of
15819@value{GDBN} commands stops and @value{GDBN} issues a prompt
15820(before the command that you actually typed had a chance to run).
104c1213 15821
8e04817f
AC
15822If you try to define a hook which does not match any known command, you
15823get a warning from the @code{define} command.
c906108c 15824
8e04817f
AC
15825@node Command Files
15826@section Command files
c906108c 15827
8e04817f 15828@cindex command files
6fc08d32
EZ
15829A command file for @value{GDBN} is a text file made of lines that are
15830@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
15831also be included. An empty line in a command file does nothing; it
15832does not mean to repeat the last command, as it would from the
15833terminal.
c906108c 15834
6fc08d32
EZ
15835You can request the execution of a command file with the @code{source}
15836command:
c906108c 15837
8e04817f
AC
15838@table @code
15839@kindex source
15840@item source @var{filename}
15841Execute the command file @var{filename}.
c906108c
SS
15842@end table
15843
8e04817f 15844The lines in a command file are executed sequentially. They are not
a71ec265
DH
15845printed as they are executed. An error in any command terminates
15846execution of the command file and control is returned to the console.
c906108c 15847
8e04817f
AC
15848Commands that would ask for confirmation if used interactively proceed
15849without asking when used in a command file. Many @value{GDBN} commands that
15850normally print messages to say what they are doing omit the messages
15851when called from command files.
c906108c 15852
8e04817f
AC
15853@value{GDBN} also accepts command input from standard input. In this
15854mode, normal output goes to standard output and error output goes to
15855standard error. Errors in a command file supplied on standard input do
6fc08d32 15856not terminate execution of the command file---execution continues with
8e04817f 15857the next command.
c906108c 15858
474c8240 15859@smallexample
8e04817f 15860gdb < cmds > log 2>&1
474c8240 15861@end smallexample
c906108c 15862
8e04817f
AC
15863(The syntax above will vary depending on the shell used.) This example
15864will execute commands from the file @file{cmds}. All output and errors
15865would be directed to @file{log}.
c906108c 15866
8e04817f
AC
15867@node Output
15868@section Commands for controlled output
c906108c 15869
8e04817f
AC
15870During the execution of a command file or a user-defined command, normal
15871@value{GDBN} output is suppressed; the only output that appears is what is
15872explicitly printed by the commands in the definition. This section
15873describes three commands useful for generating exactly the output you
15874want.
c906108c
SS
15875
15876@table @code
8e04817f
AC
15877@kindex echo
15878@item echo @var{text}
15879@c I do not consider backslash-space a standard C escape sequence
15880@c because it is not in ANSI.
15881Print @var{text}. Nonprinting characters can be included in
15882@var{text} using C escape sequences, such as @samp{\n} to print a
15883newline. @strong{No newline is printed unless you specify one.}
15884In addition to the standard C escape sequences, a backslash followed
15885by a space stands for a space. This is useful for displaying a
15886string with spaces at the beginning or the end, since leading and
15887trailing spaces are otherwise trimmed from all arguments.
15888To print @samp{@w{ }and foo =@w{ }}, use the command
15889@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 15890
8e04817f
AC
15891A backslash at the end of @var{text} can be used, as in C, to continue
15892the command onto subsequent lines. For example,
c906108c 15893
474c8240 15894@smallexample
8e04817f
AC
15895echo This is some text\n\
15896which is continued\n\
15897onto several lines.\n
474c8240 15898@end smallexample
c906108c 15899
8e04817f 15900produces the same output as
c906108c 15901
474c8240 15902@smallexample
8e04817f
AC
15903echo This is some text\n
15904echo which is continued\n
15905echo onto several lines.\n
474c8240 15906@end smallexample
c906108c 15907
8e04817f
AC
15908@kindex output
15909@item output @var{expression}
15910Print the value of @var{expression} and nothing but that value: no
15911newlines, no @samp{$@var{nn} = }. The value is not entered in the
15912value history either. @xref{Expressions, ,Expressions}, for more information
15913on expressions.
c906108c 15914
8e04817f
AC
15915@item output/@var{fmt} @var{expression}
15916Print the value of @var{expression} in format @var{fmt}. You can use
15917the same formats as for @code{print}. @xref{Output Formats,,Output
15918formats}, for more information.
c906108c 15919
8e04817f
AC
15920@kindex printf
15921@item printf @var{string}, @var{expressions}@dots{}
15922Print the values of the @var{expressions} under the control of
15923@var{string}. The @var{expressions} are separated by commas and may be
15924either numbers or pointers. Their values are printed as specified by
15925@var{string}, exactly as if your program were to execute the C
15926subroutine
15927@c FIXME: the above implies that at least all ANSI C formats are
15928@c supported, but it isn't true: %E and %G don't work (or so it seems).
15929@c Either this is a bug, or the manual should document what formats are
15930@c supported.
c906108c 15931
474c8240 15932@smallexample
8e04817f 15933printf (@var{string}, @var{expressions}@dots{});
474c8240 15934@end smallexample
c906108c 15935
8e04817f 15936For example, you can print two values in hex like this:
c906108c 15937
8e04817f
AC
15938@smallexample
15939printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
15940@end smallexample
c906108c 15941
8e04817f
AC
15942The only backslash-escape sequences that you can use in the format
15943string are the simple ones that consist of backslash followed by a
15944letter.
c906108c
SS
15945@end table
15946
21c294e6
AC
15947@node Interpreters
15948@chapter Command Interpreters
15949@cindex command interpreters
15950
15951@value{GDBN} supports multiple command interpreters, and some command
15952infrastructure to allow users or user interface writers to switch
15953between interpreters or run commands in other interpreters.
15954
15955@value{GDBN} currently supports two command interpreters, the console
15956interpreter (sometimes called the command-line interpreter or @sc{cli})
15957and the machine interface interpreter (or @sc{gdb/mi}). This manual
15958describes both of these interfaces in great detail.
15959
15960By default, @value{GDBN} will start with the console interpreter.
15961However, the user may choose to start @value{GDBN} with another
15962interpreter by specifying the @option{-i} or @option{--interpreter}
15963startup options. Defined interpreters include:
15964
15965@table @code
15966@item console
15967@cindex console interpreter
15968The traditional console or command-line interpreter. This is the most often
15969used interpreter with @value{GDBN}. With no interpreter specified at runtime,
15970@value{GDBN} will use this interpreter.
15971
15972@item mi
15973@cindex mi interpreter
15974The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
15975by programs wishing to use @value{GDBN} as a backend for a debugger GUI
15976or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
15977Interface}.
15978
15979@item mi2
15980@cindex mi2 interpreter
15981The current @sc{gdb/mi} interface.
15982
15983@item mi1
15984@cindex mi1 interpreter
15985The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
15986
15987@end table
15988
15989@cindex invoke another interpreter
15990The interpreter being used by @value{GDBN} may not be dynamically
15991switched at runtime. Although possible, this could lead to a very
15992precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
15993enters the command "interpreter-set console" in a console view,
15994@value{GDBN} would switch to using the console interpreter, rendering
15995the IDE inoperable!
15996
15997@kindex interpreter-exec
15998Although you may only choose a single interpreter at startup, you may execute
15999commands in any interpreter from the current interpreter using the appropriate
16000command. If you are running the console interpreter, simply use the
16001@code{interpreter-exec} command:
16002
16003@smallexample
16004interpreter-exec mi "-data-list-register-names"
16005@end smallexample
16006
16007@sc{gdb/mi} has a similar command, although it is only available in versions of
16008@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
16009
8e04817f
AC
16010@node TUI
16011@chapter @value{GDBN} Text User Interface
16012@cindex TUI
d0d5df6f 16013@cindex Text User Interface
c906108c 16014
8e04817f
AC
16015@menu
16016* TUI Overview:: TUI overview
16017* TUI Keys:: TUI key bindings
7cf36c78 16018* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
16019* TUI Commands:: TUI specific commands
16020* TUI Configuration:: TUI configuration variables
16021@end menu
c906108c 16022
d0d5df6f
AC
16023The @value{GDBN} Text User Interface, TUI in short, is a terminal
16024interface which uses the @code{curses} library to show the source
16025file, the assembly output, the program registers and @value{GDBN}
16026commands in separate text windows.
16027
16028The TUI is enabled by invoking @value{GDBN} using either
16029@pindex gdbtui
16030@samp{gdbtui} or @samp{gdb -tui}.
c906108c 16031
8e04817f
AC
16032@node TUI Overview
16033@section TUI overview
c906108c 16034
8e04817f
AC
16035The TUI has two display modes that can be switched while
16036@value{GDBN} runs:
c906108c 16037
8e04817f
AC
16038@itemize @bullet
16039@item
16040A curses (or TUI) mode in which it displays several text
16041windows on the terminal.
c906108c 16042
8e04817f
AC
16043@item
16044A standard mode which corresponds to the @value{GDBN} configured without
16045the TUI.
16046@end itemize
c906108c 16047
8e04817f
AC
16048In the TUI mode, @value{GDBN} can display several text window
16049on the terminal:
c906108c 16050
8e04817f
AC
16051@table @emph
16052@item command
16053This window is the @value{GDBN} command window with the @value{GDBN}
16054prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
16055managed using readline but through the TUI. The @emph{command}
16056window is always visible.
c906108c 16057
8e04817f
AC
16058@item source
16059The source window shows the source file of the program. The current
16060line as well as active breakpoints are displayed in this window.
c906108c 16061
8e04817f
AC
16062@item assembly
16063The assembly window shows the disassembly output of the program.
c906108c 16064
8e04817f
AC
16065@item register
16066This window shows the processor registers. It detects when
16067a register is changed and when this is the case, registers that have
6a1b180d 16068changed are highlighted.
c906108c 16069
c906108c
SS
16070@end table
16071
269c21fe
SC
16072The source and assembly windows show the current program position
16073by highlighting the current line and marking them with the @samp{>} marker.
16074Breakpoints are also indicated with two markers. A first one
16075indicates the breakpoint type:
16076
16077@table @code
16078@item B
16079Breakpoint which was hit at least once.
16080
16081@item b
16082Breakpoint which was never hit.
16083
16084@item H
16085Hardware breakpoint which was hit at least once.
16086
16087@item h
16088Hardware breakpoint which was never hit.
16089
16090@end table
16091
16092The second marker indicates whether the breakpoint is enabled or not:
16093
16094@table @code
16095@item +
16096Breakpoint is enabled.
16097
16098@item -
16099Breakpoint is disabled.
16100
16101@end table
16102
8e04817f
AC
16103The source, assembly and register windows are attached to the thread
16104and the frame position. They are updated when the current thread
16105changes, when the frame changes or when the program counter changes.
16106These three windows are arranged by the TUI according to several
16107layouts. The layout defines which of these three windows are visible.
16108The following layouts are available:
c906108c 16109
8e04817f
AC
16110@itemize @bullet
16111@item
16112source
2df3850c 16113
8e04817f
AC
16114@item
16115assembly
16116
16117@item
16118source and assembly
16119
16120@item
16121source and registers
c906108c 16122
8e04817f
AC
16123@item
16124assembly and registers
2df3850c 16125
8e04817f 16126@end itemize
c906108c 16127
b7bb15bc
SC
16128On top of the command window a status line gives various information
16129concerning the current process begin debugged. The status line is
16130updated when the information it shows changes. The following fields
16131are displayed:
16132
16133@table @emph
16134@item target
16135Indicates the current gdb target
16136(@pxref{Targets, ,Specifying a Debugging Target}).
16137
16138@item process
16139Gives information about the current process or thread number.
16140When no process is being debugged, this field is set to @code{No process}.
16141
16142@item function
16143Gives the current function name for the selected frame.
16144The name is demangled if demangling is turned on (@pxref{Print Settings}).
16145When there is no symbol corresponding to the current program counter
16146the string @code{??} is displayed.
16147
16148@item line
16149Indicates the current line number for the selected frame.
16150When the current line number is not known the string @code{??} is displayed.
16151
16152@item pc
16153Indicates the current program counter address.
16154
16155@end table
16156
8e04817f
AC
16157@node TUI Keys
16158@section TUI Key Bindings
16159@cindex TUI key bindings
c906108c 16160
8e04817f
AC
16161The TUI installs several key bindings in the readline keymaps
16162(@pxref{Command Line Editing}).
16163They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
16164directly on the TUI layout and windows. The TUI also provides
16165a @emph{SingleKey} keymap which binds several keys directly to
16166@value{GDBN} commands. The following key bindings
8e04817f 16167are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 16168
8e04817f
AC
16169@table @kbd
16170@kindex C-x C-a
16171@item C-x C-a
16172@kindex C-x a
16173@itemx C-x a
16174@kindex C-x A
16175@itemx C-x A
16176Enter or leave the TUI mode. When the TUI mode is left,
16177the curses window management is left and @value{GDBN} operates using
16178its standard mode writing on the terminal directly. When the TUI
16179mode is entered, the control is given back to the curses windows.
16180The screen is then refreshed.
c906108c 16181
8e04817f
AC
16182@kindex C-x 1
16183@item C-x 1
16184Use a TUI layout with only one window. The layout will
16185either be @samp{source} or @samp{assembly}. When the TUI mode
16186is not active, it will switch to the TUI mode.
2df3850c 16187
8e04817f 16188Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 16189
8e04817f
AC
16190@kindex C-x 2
16191@item C-x 2
16192Use a TUI layout with at least two windows. When the current
16193layout shows already two windows, a next layout with two windows is used.
16194When a new layout is chosen, one window will always be common to the
16195previous layout and the new one.
c906108c 16196
8e04817f 16197Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 16198
72ffddc9
SC
16199@kindex C-x o
16200@item C-x o
16201Change the active window. The TUI associates several key bindings
16202(like scrolling and arrow keys) to the active window. This command
16203gives the focus to the next TUI window.
16204
16205Think of it as the Emacs @kbd{C-x o} binding.
16206
7cf36c78
SC
16207@kindex C-x s
16208@item C-x s
16209Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
16210(@pxref{TUI Single Key Mode}).
16211
c906108c
SS
16212@end table
16213
8e04817f 16214The following key bindings are handled only by the TUI mode:
5d161b24 16215
8e04817f
AC
16216@table @key
16217@kindex PgUp
16218@item PgUp
16219Scroll the active window one page up.
c906108c 16220
8e04817f
AC
16221@kindex PgDn
16222@item PgDn
16223Scroll the active window one page down.
c906108c 16224
8e04817f
AC
16225@kindex Up
16226@item Up
16227Scroll the active window one line up.
c906108c 16228
8e04817f
AC
16229@kindex Down
16230@item Down
16231Scroll the active window one line down.
c906108c 16232
8e04817f
AC
16233@kindex Left
16234@item Left
16235Scroll the active window one column left.
c906108c 16236
8e04817f
AC
16237@kindex Right
16238@item Right
16239Scroll the active window one column right.
c906108c 16240
8e04817f
AC
16241@kindex C-L
16242@item C-L
16243Refresh the screen.
c906108c 16244
8e04817f 16245@end table
c906108c 16246
8e04817f 16247In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
16248for scrolling. This means they are available for readline when the
16249active window is the command window. When the command window
16250does not have the focus, it is necessary to use other readline
16251key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 16252
7cf36c78
SC
16253@node TUI Single Key Mode
16254@section TUI Single Key Mode
16255@cindex TUI single key mode
16256
16257The TUI provides a @emph{SingleKey} mode in which it installs a particular
16258key binding in the readline keymaps to connect single keys to
b383017d 16259some gdb commands.
7cf36c78
SC
16260
16261@table @kbd
16262@kindex c @r{(SingleKey TUI key)}
16263@item c
16264continue
16265
16266@kindex d @r{(SingleKey TUI key)}
16267@item d
16268down
16269
16270@kindex f @r{(SingleKey TUI key)}
16271@item f
16272finish
16273
16274@kindex n @r{(SingleKey TUI key)}
16275@item n
16276next
16277
16278@kindex q @r{(SingleKey TUI key)}
16279@item q
16280exit the @emph{SingleKey} mode.
16281
16282@kindex r @r{(SingleKey TUI key)}
16283@item r
16284run
16285
16286@kindex s @r{(SingleKey TUI key)}
16287@item s
16288step
16289
16290@kindex u @r{(SingleKey TUI key)}
16291@item u
16292up
16293
16294@kindex v @r{(SingleKey TUI key)}
16295@item v
16296info locals
16297
16298@kindex w @r{(SingleKey TUI key)}
16299@item w
16300where
16301
16302@end table
16303
16304Other keys temporarily switch to the @value{GDBN} command prompt.
16305The key that was pressed is inserted in the editing buffer so that
16306it is possible to type most @value{GDBN} commands without interaction
16307with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
16308@emph{SingleKey} mode is restored. The only way to permanently leave
16309this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
16310
16311
8e04817f
AC
16312@node TUI Commands
16313@section TUI specific commands
16314@cindex TUI commands
16315
16316The TUI has specific commands to control the text windows.
16317These commands are always available, that is they do not depend on
16318the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
16319is in the standard mode, using these commands will automatically switch
16320in the TUI mode.
c906108c
SS
16321
16322@table @code
3d757584
SC
16323@item info win
16324@kindex info win
16325List and give the size of all displayed windows.
16326
8e04817f 16327@item layout next
4644b6e3 16328@kindex layout
8e04817f 16329Display the next layout.
2df3850c 16330
8e04817f 16331@item layout prev
8e04817f 16332Display the previous layout.
c906108c 16333
8e04817f 16334@item layout src
8e04817f 16335Display the source window only.
c906108c 16336
8e04817f 16337@item layout asm
8e04817f 16338Display the assembly window only.
c906108c 16339
8e04817f 16340@item layout split
8e04817f 16341Display the source and assembly window.
c906108c 16342
8e04817f 16343@item layout regs
8e04817f
AC
16344Display the register window together with the source or assembly window.
16345
16346@item focus next | prev | src | asm | regs | split
16347@kindex focus
16348Set the focus to the named window.
16349This command allows to change the active window so that scrolling keys
16350can be affected to another window.
c906108c 16351
8e04817f
AC
16352@item refresh
16353@kindex refresh
16354Refresh the screen. This is similar to using @key{C-L} key.
c906108c 16355
6a1b180d
SC
16356@item tui reg float
16357@kindex tui reg
16358Show the floating point registers in the register window.
16359
16360@item tui reg general
16361Show the general registers in the register window.
16362
16363@item tui reg next
16364Show the next register group. The list of register groups as well as
16365their order is target specific. The predefined register groups are the
16366following: @code{general}, @code{float}, @code{system}, @code{vector},
16367@code{all}, @code{save}, @code{restore}.
16368
16369@item tui reg system
16370Show the system registers in the register window.
16371
8e04817f
AC
16372@item update
16373@kindex update
16374Update the source window and the current execution point.
c906108c 16375
8e04817f
AC
16376@item winheight @var{name} +@var{count}
16377@itemx winheight @var{name} -@var{count}
16378@kindex winheight
16379Change the height of the window @var{name} by @var{count}
16380lines. Positive counts increase the height, while negative counts
16381decrease it.
2df3850c 16382
c45da7e6
EZ
16383@item tabset
16384@kindex tabset @var{nchars}
16385Set the width of tab stops to be @var{nchars} characters.
16386
c906108c
SS
16387@end table
16388
8e04817f
AC
16389@node TUI Configuration
16390@section TUI configuration variables
16391@cindex TUI configuration variables
c906108c 16392
8e04817f
AC
16393The TUI has several configuration variables that control the
16394appearance of windows on the terminal.
c906108c 16395
8e04817f
AC
16396@table @code
16397@item set tui border-kind @var{kind}
16398@kindex set tui border-kind
16399Select the border appearance for the source, assembly and register windows.
16400The possible values are the following:
16401@table @code
16402@item space
16403Use a space character to draw the border.
c906108c 16404
8e04817f
AC
16405@item ascii
16406Use ascii characters + - and | to draw the border.
c906108c 16407
8e04817f
AC
16408@item acs
16409Use the Alternate Character Set to draw the border. The border is
16410drawn using character line graphics if the terminal supports them.
c78b4128 16411
8e04817f 16412@end table
c78b4128 16413
8e04817f
AC
16414@item set tui active-border-mode @var{mode}
16415@kindex set tui active-border-mode
16416Select the attributes to display the border of the active window.
16417The possible values are @code{normal}, @code{standout}, @code{reverse},
16418@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 16419
8e04817f
AC
16420@item set tui border-mode @var{mode}
16421@kindex set tui border-mode
16422Select the attributes to display the border of other windows.
16423The @var{mode} can be one of the following:
16424@table @code
16425@item normal
16426Use normal attributes to display the border.
c906108c 16427
8e04817f
AC
16428@item standout
16429Use standout mode.
c906108c 16430
8e04817f
AC
16431@item reverse
16432Use reverse video mode.
c906108c 16433
8e04817f
AC
16434@item half
16435Use half bright mode.
c906108c 16436
8e04817f
AC
16437@item half-standout
16438Use half bright and standout mode.
c906108c 16439
8e04817f
AC
16440@item bold
16441Use extra bright or bold mode.
c78b4128 16442
8e04817f
AC
16443@item bold-standout
16444Use extra bright or bold and standout mode.
c78b4128 16445
8e04817f 16446@end table
c78b4128 16447
8e04817f 16448@end table
c78b4128 16449
8e04817f
AC
16450@node Emacs
16451@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 16452
8e04817f
AC
16453@cindex Emacs
16454@cindex @sc{gnu} Emacs
16455A special interface allows you to use @sc{gnu} Emacs to view (and
16456edit) the source files for the program you are debugging with
16457@value{GDBN}.
c906108c 16458
8e04817f
AC
16459To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
16460executable file you want to debug as an argument. This command starts
16461@value{GDBN} as a subprocess of Emacs, with input and output through a newly
16462created Emacs buffer.
16463@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 16464
8e04817f
AC
16465Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
16466things:
c906108c 16467
8e04817f
AC
16468@itemize @bullet
16469@item
16470All ``terminal'' input and output goes through the Emacs buffer.
16471@end itemize
c906108c 16472
8e04817f
AC
16473This applies both to @value{GDBN} commands and their output, and to the input
16474and output done by the program you are debugging.
bf0184be 16475
8e04817f
AC
16476This is useful because it means that you can copy the text of previous
16477commands and input them again; you can even use parts of the output
16478in this way.
bf0184be 16479
8e04817f
AC
16480All the facilities of Emacs' Shell mode are available for interacting
16481with your program. In particular, you can send signals the usual
16482way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
16483stop.
bf0184be 16484
8e04817f 16485@itemize @bullet
bf0184be 16486@item
8e04817f
AC
16487@value{GDBN} displays source code through Emacs.
16488@end itemize
bf0184be 16489
8e04817f
AC
16490Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
16491source file for that frame and puts an arrow (@samp{=>}) at the
16492left margin of the current line. Emacs uses a separate buffer for
16493source display, and splits the screen to show both your @value{GDBN} session
16494and the source.
bf0184be 16495
8e04817f
AC
16496Explicit @value{GDBN} @code{list} or search commands still produce output as
16497usual, but you probably have no reason to use them from Emacs.
c906108c 16498
64fabec2
AC
16499If you specify an absolute file name when prompted for the @kbd{M-x
16500gdb} argument, then Emacs sets your current working directory to where
16501your program resides. If you only specify the file name, then Emacs
16502sets your current working directory to to the directory associated
16503with the previous buffer. In this case, @value{GDBN} may find your
16504program by searching your environment's @code{PATH} variable, but on
16505some operating systems it might not find the source. So, although the
16506@value{GDBN} input and output session proceeds normally, the auxiliary
16507buffer does not display the current source and line of execution.
16508
16509The initial working directory of @value{GDBN} is printed on the top
16510line of the @value{GDBN} I/O buffer and this serves as a default for
16511the commands that specify files for @value{GDBN} to operate
16512on. @xref{Files, ,Commands to specify files}.
16513
16514By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
16515need to call @value{GDBN} by a different name (for example, if you
16516keep several configurations around, with different names) you can
16517customize the Emacs variable @code{gud-gdb-command-name} to run the
16518one you want.
8e04817f
AC
16519
16520In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
16521addition to the standard Shell mode commands:
c906108c 16522
8e04817f
AC
16523@table @kbd
16524@item C-h m
16525Describe the features of Emacs' @value{GDBN} Mode.
c906108c 16526
64fabec2 16527@item C-c C-s
8e04817f
AC
16528Execute to another source line, like the @value{GDBN} @code{step} command; also
16529update the display window to show the current file and location.
c906108c 16530
64fabec2 16531@item C-c C-n
8e04817f
AC
16532Execute to next source line in this function, skipping all function
16533calls, like the @value{GDBN} @code{next} command. Then update the display window
16534to show the current file and location.
c906108c 16535
64fabec2 16536@item C-c C-i
8e04817f
AC
16537Execute one instruction, like the @value{GDBN} @code{stepi} command; update
16538display window accordingly.
c906108c 16539
8e04817f
AC
16540@item C-c C-f
16541Execute until exit from the selected stack frame, like the @value{GDBN}
16542@code{finish} command.
c906108c 16543
64fabec2 16544@item C-c C-r
8e04817f
AC
16545Continue execution of your program, like the @value{GDBN} @code{continue}
16546command.
b433d00b 16547
64fabec2 16548@item C-c <
8e04817f
AC
16549Go up the number of frames indicated by the numeric argument
16550(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
16551like the @value{GDBN} @code{up} command.
b433d00b 16552
64fabec2 16553@item C-c >
8e04817f
AC
16554Go down the number of frames indicated by the numeric argument, like the
16555@value{GDBN} @code{down} command.
8e04817f 16556@end table
c906108c 16557
64fabec2 16558In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 16559tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 16560
64fabec2
AC
16561If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
16562shows a backtrace when the @value{GDBN} I/O buffer is current. Move
16563point to any frame in the stack and type @key{RET} to make it become the
16564current frame and display the associated source in the source buffer.
16565Alternatively, click @kbd{Mouse-2} to make the selected frame become the
16566current one.
16567
8e04817f
AC
16568If you accidentally delete the source-display buffer, an easy way to get
16569it back is to type the command @code{f} in the @value{GDBN} buffer, to
16570request a frame display; when you run under Emacs, this recreates
16571the source buffer if necessary to show you the context of the current
16572frame.
c906108c 16573
8e04817f
AC
16574The source files displayed in Emacs are in ordinary Emacs buffers
16575which are visiting the source files in the usual way. You can edit
16576the files with these buffers if you wish; but keep in mind that @value{GDBN}
16577communicates with Emacs in terms of line numbers. If you add or
16578delete lines from the text, the line numbers that @value{GDBN} knows cease
16579to correspond properly with the code.
b383017d 16580
64fabec2
AC
16581The description given here is for GNU Emacs version 21.3 and a more
16582detailed description of its interaction with @value{GDBN} is given in
16583the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 16584
8e04817f
AC
16585@c The following dropped because Epoch is nonstandard. Reactivate
16586@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
16587@ignore
16588@kindex Emacs Epoch environment
16589@kindex Epoch
16590@kindex inspect
c906108c 16591
8e04817f
AC
16592Version 18 of @sc{gnu} Emacs has a built-in window system
16593called the @code{epoch}
16594environment. Users of this environment can use a new command,
16595@code{inspect} which performs identically to @code{print} except that
16596each value is printed in its own window.
16597@end ignore
c906108c 16598
922fbb7b
AC
16599
16600@node GDB/MI
16601@chapter The @sc{gdb/mi} Interface
16602
16603@unnumberedsec Function and Purpose
16604
16605@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
16606@sc{gdb/mi} is a line based machine oriented text interface to
16607@value{GDBN} and is activated by specifying using the
16608@option{--interpreter} command line option (@pxref{Mode Options}). It
16609is specifically intended to support the development of systems which
16610use the debugger as just one small component of a larger system.
922fbb7b
AC
16611
16612This chapter is a specification of the @sc{gdb/mi} interface. It is written
16613in the form of a reference manual.
16614
16615Note that @sc{gdb/mi} is still under construction, so some of the
16616features described below are incomplete and subject to change.
16617
16618@unnumberedsec Notation and Terminology
16619
16620@cindex notational conventions, for @sc{gdb/mi}
16621This chapter uses the following notation:
16622
16623@itemize @bullet
16624@item
16625@code{|} separates two alternatives.
16626
16627@item
16628@code{[ @var{something} ]} indicates that @var{something} is optional:
16629it may or may not be given.
16630
16631@item
16632@code{( @var{group} )*} means that @var{group} inside the parentheses
16633may repeat zero or more times.
16634
16635@item
16636@code{( @var{group} )+} means that @var{group} inside the parentheses
16637may repeat one or more times.
16638
16639@item
16640@code{"@var{string}"} means a literal @var{string}.
16641@end itemize
16642
16643@ignore
16644@heading Dependencies
16645@end ignore
16646
16647@heading Acknowledgments
16648
16649In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
16650Elena Zannoni.
16651
16652@menu
16653* GDB/MI Command Syntax::
16654* GDB/MI Compatibility with CLI::
16655* GDB/MI Output Records::
16656* GDB/MI Command Description Format::
16657* GDB/MI Breakpoint Table Commands::
16658* GDB/MI Data Manipulation::
16659* GDB/MI Program Control::
16660* GDB/MI Miscellaneous Commands::
16661@ignore
16662* GDB/MI Kod Commands::
16663* GDB/MI Memory Overlay Commands::
16664* GDB/MI Signal Handling Commands::
16665@end ignore
16666* GDB/MI Stack Manipulation::
16667* GDB/MI Symbol Query::
16668* GDB/MI Target Manipulation::
16669* GDB/MI Thread Commands::
16670* GDB/MI Tracepoint Commands::
16671* GDB/MI Variable Objects::
16672@end menu
16673
16674@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16675@node GDB/MI Command Syntax
16676@section @sc{gdb/mi} Command Syntax
16677
16678@menu
16679* GDB/MI Input Syntax::
16680* GDB/MI Output Syntax::
16681* GDB/MI Simple Examples::
16682@end menu
16683
16684@node GDB/MI Input Syntax
16685@subsection @sc{gdb/mi} Input Syntax
16686
16687@cindex input syntax for @sc{gdb/mi}
16688@cindex @sc{gdb/mi}, input syntax
16689@table @code
16690@item @var{command} @expansion{}
16691@code{@var{cli-command} | @var{mi-command}}
16692
16693@item @var{cli-command} @expansion{}
16694@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
16695@var{cli-command} is any existing @value{GDBN} CLI command.
16696
16697@item @var{mi-command} @expansion{}
16698@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
16699@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
16700
16701@item @var{token} @expansion{}
16702"any sequence of digits"
16703
16704@item @var{option} @expansion{}
16705@code{"-" @var{parameter} [ " " @var{parameter} ]}
16706
16707@item @var{parameter} @expansion{}
16708@code{@var{non-blank-sequence} | @var{c-string}}
16709
16710@item @var{operation} @expansion{}
16711@emph{any of the operations described in this chapter}
16712
16713@item @var{non-blank-sequence} @expansion{}
16714@emph{anything, provided it doesn't contain special characters such as
16715"-", @var{nl}, """ and of course " "}
16716
16717@item @var{c-string} @expansion{}
16718@code{""" @var{seven-bit-iso-c-string-content} """}
16719
16720@item @var{nl} @expansion{}
16721@code{CR | CR-LF}
16722@end table
16723
16724@noindent
16725Notes:
16726
16727@itemize @bullet
16728@item
16729The CLI commands are still handled by the @sc{mi} interpreter; their
16730output is described below.
16731
16732@item
16733The @code{@var{token}}, when present, is passed back when the command
16734finishes.
16735
16736@item
16737Some @sc{mi} commands accept optional arguments as part of the parameter
16738list. Each option is identified by a leading @samp{-} (dash) and may be
16739followed by an optional argument parameter. Options occur first in the
16740parameter list and can be delimited from normal parameters using
16741@samp{--} (this is useful when some parameters begin with a dash).
16742@end itemize
16743
16744Pragmatics:
16745
16746@itemize @bullet
16747@item
16748We want easy access to the existing CLI syntax (for debugging).
16749
16750@item
16751We want it to be easy to spot a @sc{mi} operation.
16752@end itemize
16753
16754@node GDB/MI Output Syntax
16755@subsection @sc{gdb/mi} Output Syntax
16756
16757@cindex output syntax of @sc{gdb/mi}
16758@cindex @sc{gdb/mi}, output syntax
16759The output from @sc{gdb/mi} consists of zero or more out-of-band records
16760followed, optionally, by a single result record. This result record
16761is for the most recent command. The sequence of output records is
16762terminated by @samp{(@value{GDBP})}.
16763
16764If an input command was prefixed with a @code{@var{token}} then the
16765corresponding output for that command will also be prefixed by that same
16766@var{token}.
16767
16768@table @code
16769@item @var{output} @expansion{}
f7dc1244 16770@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
922fbb7b
AC
16771
16772@item @var{result-record} @expansion{}
16773@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
16774
16775@item @var{out-of-band-record} @expansion{}
16776@code{@var{async-record} | @var{stream-record}}
16777
16778@item @var{async-record} @expansion{}
16779@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
16780
16781@item @var{exec-async-output} @expansion{}
16782@code{[ @var{token} ] "*" @var{async-output}}
16783
16784@item @var{status-async-output} @expansion{}
16785@code{[ @var{token} ] "+" @var{async-output}}
16786
16787@item @var{notify-async-output} @expansion{}
16788@code{[ @var{token} ] "=" @var{async-output}}
16789
16790@item @var{async-output} @expansion{}
16791@code{@var{async-class} ( "," @var{result} )* @var{nl}}
16792
16793@item @var{result-class} @expansion{}
16794@code{"done" | "running" | "connected" | "error" | "exit"}
16795
16796@item @var{async-class} @expansion{}
16797@code{"stopped" | @var{others}} (where @var{others} will be added
16798depending on the needs---this is still in development).
16799
16800@item @var{result} @expansion{}
16801@code{ @var{variable} "=" @var{value}}
16802
16803@item @var{variable} @expansion{}
16804@code{ @var{string} }
16805
16806@item @var{value} @expansion{}
16807@code{ @var{const} | @var{tuple} | @var{list} }
16808
16809@item @var{const} @expansion{}
16810@code{@var{c-string}}
16811
16812@item @var{tuple} @expansion{}
16813@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
16814
16815@item @var{list} @expansion{}
16816@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
16817@var{result} ( "," @var{result} )* "]" }
16818
16819@item @var{stream-record} @expansion{}
16820@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
16821
16822@item @var{console-stream-output} @expansion{}
16823@code{"~" @var{c-string}}
16824
16825@item @var{target-stream-output} @expansion{}
16826@code{"@@" @var{c-string}}
16827
16828@item @var{log-stream-output} @expansion{}
16829@code{"&" @var{c-string}}
16830
16831@item @var{nl} @expansion{}
16832@code{CR | CR-LF}
16833
16834@item @var{token} @expansion{}
16835@emph{any sequence of digits}.
16836@end table
16837
16838@noindent
16839Notes:
16840
16841@itemize @bullet
16842@item
16843All output sequences end in a single line containing a period.
16844
16845@item
16846The @code{@var{token}} is from the corresponding request. If an execution
16847command is interrupted by the @samp{-exec-interrupt} command, the
16848@var{token} associated with the @samp{*stopped} message is the one of the
16849original execution command, not the one of the interrupt command.
16850
16851@item
16852@cindex status output in @sc{gdb/mi}
16853@var{status-async-output} contains on-going status information about the
16854progress of a slow operation. It can be discarded. All status output is
16855prefixed by @samp{+}.
16856
16857@item
16858@cindex async output in @sc{gdb/mi}
16859@var{exec-async-output} contains asynchronous state change on the target
16860(stopped, started, disappeared). All async output is prefixed by
16861@samp{*}.
16862
16863@item
16864@cindex notify output in @sc{gdb/mi}
16865@var{notify-async-output} contains supplementary information that the
16866client should handle (e.g., a new breakpoint information). All notify
16867output is prefixed by @samp{=}.
16868
16869@item
16870@cindex console output in @sc{gdb/mi}
16871@var{console-stream-output} is output that should be displayed as is in the
16872console. It is the textual response to a CLI command. All the console
16873output is prefixed by @samp{~}.
16874
16875@item
16876@cindex target output in @sc{gdb/mi}
16877@var{target-stream-output} is the output produced by the target program.
16878All the target output is prefixed by @samp{@@}.
16879
16880@item
16881@cindex log output in @sc{gdb/mi}
16882@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
16883instance messages that should be displayed as part of an error log. All
16884the log output is prefixed by @samp{&}.
16885
16886@item
16887@cindex list output in @sc{gdb/mi}
16888New @sc{gdb/mi} commands should only output @var{lists} containing
16889@var{values}.
16890
16891
16892@end itemize
16893
16894@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
16895details about the various output records.
16896
16897@node GDB/MI Simple Examples
16898@subsection Simple Examples of @sc{gdb/mi} Interaction
16899@cindex @sc{gdb/mi}, simple examples
16900
16901This subsection presents several simple examples of interaction using
16902the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
16903following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
16904the output received from @sc{gdb/mi}.
16905
16906@subsubheading Target Stop
16907@c Ummm... There is no "-stop" command. This assumes async, no?
16908Here's an example of stopping the inferior process:
16909
16910@smallexample
16911-> -stop
16912<- (@value{GDBP})
16913@end smallexample
16914
16915@noindent
16916and later:
16917
16918@smallexample
16919<- *stop,reason="stop",address="0x123",source="a.c:123"
16920<- (@value{GDBP})
16921@end smallexample
16922
16923@subsubheading Simple CLI Command
16924
16925Here's an example of a simple CLI command being passed through
16926@sc{gdb/mi} and on to the CLI.
16927
16928@smallexample
16929-> print 1+2
16930<- &"print 1+2\n"
16931<- ~"$1 = 3\n"
16932<- ^done
16933<- (@value{GDBP})
16934@end smallexample
16935
16936@subsubheading Command With Side Effects
16937
16938@smallexample
16939-> -symbol-file xyz.exe
16940<- *breakpoint,nr="3",address="0x123",source="a.c:123"
16941<- (@value{GDBP})
16942@end smallexample
16943
16944@subsubheading A Bad Command
16945
16946Here's what happens if you pass a non-existent command:
16947
16948@smallexample
16949-> -rubbish
16950<- ^error,msg="Undefined MI command: rubbish"
16951<- (@value{GDBP})
16952@end smallexample
16953
16954@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16955@node GDB/MI Compatibility with CLI
16956@section @sc{gdb/mi} Compatibility with CLI
16957
16958@cindex compatibility, @sc{gdb/mi} and CLI
16959@cindex @sc{gdb/mi}, compatibility with CLI
16960To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
16961accepts existing CLI commands. As specified by the syntax, such
16962commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
16963respond.
16964
16965This mechanism is provided as an aid to developers of @sc{gdb/mi}
16966clients and not as a reliable interface into the CLI. Since the command
16967is being interpreteted in an environment that assumes @sc{gdb/mi}
16968behaviour, the exact output of such commands is likely to end up being
16969an un-supported hybrid of @sc{gdb/mi} and CLI output.
16970
16971@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16972@node GDB/MI Output Records
16973@section @sc{gdb/mi} Output Records
16974
16975@menu
16976* GDB/MI Result Records::
16977* GDB/MI Stream Records::
16978* GDB/MI Out-of-band Records::
16979@end menu
16980
16981@node GDB/MI Result Records
16982@subsection @sc{gdb/mi} Result Records
16983
16984@cindex result records in @sc{gdb/mi}
16985@cindex @sc{gdb/mi}, result records
16986In addition to a number of out-of-band notifications, the response to a
16987@sc{gdb/mi} command includes one of the following result indications:
16988
16989@table @code
16990@findex ^done
16991@item "^done" [ "," @var{results} ]
16992The synchronous operation was successful, @code{@var{results}} are the return
16993values.
16994
16995@item "^running"
16996@findex ^running
16997@c Is this one correct? Should it be an out-of-band notification?
16998The asynchronous operation was successfully started. The target is
16999running.
17000
17001@item "^error" "," @var{c-string}
17002@findex ^error
17003The operation failed. The @code{@var{c-string}} contains the corresponding
17004error message.
17005@end table
17006
17007@node GDB/MI Stream Records
17008@subsection @sc{gdb/mi} Stream Records
17009
17010@cindex @sc{gdb/mi}, stream records
17011@cindex stream records in @sc{gdb/mi}
17012@value{GDBN} internally maintains a number of output streams: the console, the
17013target, and the log. The output intended for each of these streams is
17014funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
17015
17016Each stream record begins with a unique @dfn{prefix character} which
17017identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
17018Syntax}). In addition to the prefix, each stream record contains a
17019@code{@var{string-output}}. This is either raw text (with an implicit new
17020line) or a quoted C string (which does not contain an implicit newline).
17021
17022@table @code
17023@item "~" @var{string-output}
17024The console output stream contains text that should be displayed in the
17025CLI console window. It contains the textual responses to CLI commands.
17026
17027@item "@@" @var{string-output}
17028The target output stream contains any textual output from the running
17029target.
17030
17031@item "&" @var{string-output}
17032The log stream contains debugging messages being produced by @value{GDBN}'s
17033internals.
17034@end table
17035
17036@node GDB/MI Out-of-band Records
17037@subsection @sc{gdb/mi} Out-of-band Records
17038
17039@cindex out-of-band records in @sc{gdb/mi}
17040@cindex @sc{gdb/mi}, out-of-band records
17041@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
17042additional changes that have occurred. Those changes can either be a
17043consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
17044target activity (e.g., target stopped).
17045
17046The following is a preliminary list of possible out-of-band records.
034dad6f 17047In particular, the @var{exec-async-output} records.
922fbb7b
AC
17048
17049@table @code
034dad6f
BR
17050@item *stopped,reason="@var{reason}"
17051@end table
17052
17053@var{reason} can be one of the following:
17054
17055@table @code
17056@item breakpoint-hit
17057A breakpoint was reached.
17058@item watchpoint-trigger
17059A watchpoint was triggered.
17060@item read-watchpoint-trigger
17061A read watchpoint was triggered.
17062@item access-watchpoint-trigger
17063An access watchpoint was triggered.
17064@item function-finished
17065An -exec-finish or similar CLI command was accomplished.
17066@item location-reached
17067An -exec-until or similar CLI command was accomplished.
17068@item watchpoint-scope
17069A watchpoint has gone out of scope.
17070@item end-stepping-range
17071An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
17072similar CLI command was accomplished.
17073@item exited-signalled
17074The inferior exited because of a signal.
17075@item exited
17076The inferior exited.
17077@item exited-normally
17078The inferior exited normally.
17079@item signal-received
17080A signal was received by the inferior.
922fbb7b
AC
17081@end table
17082
17083
17084@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17085@node GDB/MI Command Description Format
17086@section @sc{gdb/mi} Command Description Format
17087
17088The remaining sections describe blocks of commands. Each block of
17089commands is laid out in a fashion similar to this section.
17090
17091Note the the line breaks shown in the examples are here only for
17092readability. They don't appear in the real output.
17093Also note that the commands with a non-available example (N.A.@:) are
17094not yet implemented.
17095
17096@subheading Motivation
17097
17098The motivation for this collection of commands.
17099
17100@subheading Introduction
17101
17102A brief introduction to this collection of commands as a whole.
17103
17104@subheading Commands
17105
17106For each command in the block, the following is described:
17107
17108@subsubheading Synopsis
17109
17110@smallexample
17111 -command @var{args}@dots{}
17112@end smallexample
17113
17114@subsubheading @value{GDBN} Command
17115
17116The corresponding @value{GDBN} CLI command.
17117
17118@subsubheading Result
17119
17120@subsubheading Out-of-band
17121
17122@subsubheading Notes
17123
17124@subsubheading Example
17125
17126
17127@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17128@node GDB/MI Breakpoint Table Commands
17129@section @sc{gdb/mi} Breakpoint table commands
17130
17131@cindex breakpoint commands for @sc{gdb/mi}
17132@cindex @sc{gdb/mi}, breakpoint commands
17133This section documents @sc{gdb/mi} commands for manipulating
17134breakpoints.
17135
17136@subheading The @code{-break-after} Command
17137@findex -break-after
17138
17139@subsubheading Synopsis
17140
17141@smallexample
17142 -break-after @var{number} @var{count}
17143@end smallexample
17144
17145The breakpoint number @var{number} is not in effect until it has been
17146hit @var{count} times. To see how this is reflected in the output of
17147the @samp{-break-list} command, see the description of the
17148@samp{-break-list} command below.
17149
17150@subsubheading @value{GDBN} Command
17151
17152The corresponding @value{GDBN} command is @samp{ignore}.
17153
17154@subsubheading Example
17155
17156@smallexample
17157(@value{GDBP})
17158-break-insert main
17159^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
17160(@value{GDBP})
17161-break-after 1 3
17162~
17163^done
17164(@value{GDBP})
17165-break-list
17166^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17167hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17168@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17169@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17170@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17171@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17172@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17173body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17174addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
17175ignore="3"@}]@}
17176(@value{GDBP})
17177@end smallexample
17178
17179@ignore
17180@subheading The @code{-break-catch} Command
17181@findex -break-catch
17182
17183@subheading The @code{-break-commands} Command
17184@findex -break-commands
17185@end ignore
17186
17187
17188@subheading The @code{-break-condition} Command
17189@findex -break-condition
17190
17191@subsubheading Synopsis
17192
17193@smallexample
17194 -break-condition @var{number} @var{expr}
17195@end smallexample
17196
17197Breakpoint @var{number} will stop the program only if the condition in
17198@var{expr} is true. The condition becomes part of the
17199@samp{-break-list} output (see the description of the @samp{-break-list}
17200command below).
17201
17202@subsubheading @value{GDBN} Command
17203
17204The corresponding @value{GDBN} command is @samp{condition}.
17205
17206@subsubheading Example
17207
17208@smallexample
17209(@value{GDBP})
17210-break-condition 1 1
17211^done
17212(@value{GDBP})
17213-break-list
17214^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17215hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17216@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17217@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17218@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17219@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17220@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17221body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17222addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
17223times="0",ignore="3"@}]@}
17224(@value{GDBP})
17225@end smallexample
17226
17227@subheading The @code{-break-delete} Command
17228@findex -break-delete
17229
17230@subsubheading Synopsis
17231
17232@smallexample
17233 -break-delete ( @var{breakpoint} )+
17234@end smallexample
17235
17236Delete the breakpoint(s) whose number(s) are specified in the argument
17237list. This is obviously reflected in the breakpoint list.
17238
17239@subsubheading @value{GDBN} command
17240
17241The corresponding @value{GDBN} command is @samp{delete}.
17242
17243@subsubheading Example
17244
17245@smallexample
17246(@value{GDBP})
17247-break-delete 1
17248^done
17249(@value{GDBP})
17250-break-list
17251^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17252hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17253@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17254@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17255@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17256@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17257@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17258body=[]@}
17259(@value{GDBP})
17260@end smallexample
17261
17262@subheading The @code{-break-disable} Command
17263@findex -break-disable
17264
17265@subsubheading Synopsis
17266
17267@smallexample
17268 -break-disable ( @var{breakpoint} )+
17269@end smallexample
17270
17271Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
17272break list is now set to @samp{n} for the named @var{breakpoint}(s).
17273
17274@subsubheading @value{GDBN} Command
17275
17276The corresponding @value{GDBN} command is @samp{disable}.
17277
17278@subsubheading Example
17279
17280@smallexample
17281(@value{GDBP})
17282-break-disable 2
17283^done
17284(@value{GDBP})
17285-break-list
17286^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17287hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17288@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17289@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17290@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17291@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17292@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17293body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
17294addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17295(@value{GDBP})
17296@end smallexample
17297
17298@subheading The @code{-break-enable} Command
17299@findex -break-enable
17300
17301@subsubheading Synopsis
17302
17303@smallexample
17304 -break-enable ( @var{breakpoint} )+
17305@end smallexample
17306
17307Enable (previously disabled) @var{breakpoint}(s).
17308
17309@subsubheading @value{GDBN} Command
17310
17311The corresponding @value{GDBN} command is @samp{enable}.
17312
17313@subsubheading Example
17314
17315@smallexample
17316(@value{GDBP})
17317-break-enable 2
17318^done
17319(@value{GDBP})
17320-break-list
17321^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17322hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17323@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17324@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17325@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17326@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17327@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17328body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17329addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17330(@value{GDBP})
17331@end smallexample
17332
17333@subheading The @code{-break-info} Command
17334@findex -break-info
17335
17336@subsubheading Synopsis
17337
17338@smallexample
17339 -break-info @var{breakpoint}
17340@end smallexample
17341
17342@c REDUNDANT???
17343Get information about a single breakpoint.
17344
17345@subsubheading @value{GDBN} command
17346
17347The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
17348
17349@subsubheading Example
17350N.A.
17351
17352@subheading The @code{-break-insert} Command
17353@findex -break-insert
17354
17355@subsubheading Synopsis
17356
17357@smallexample
17358 -break-insert [ -t ] [ -h ] [ -r ]
17359 [ -c @var{condition} ] [ -i @var{ignore-count} ]
17360 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
17361@end smallexample
17362
17363@noindent
17364If specified, @var{line}, can be one of:
17365
17366@itemize @bullet
17367@item function
17368@c @item +offset
17369@c @item -offset
17370@c @item linenum
17371@item filename:linenum
17372@item filename:function
17373@item *address
17374@end itemize
17375
17376The possible optional parameters of this command are:
17377
17378@table @samp
17379@item -t
17380Insert a tempoary breakpoint.
17381@item -h
17382Insert a hardware breakpoint.
17383@item -c @var{condition}
17384Make the breakpoint conditional on @var{condition}.
17385@item -i @var{ignore-count}
17386Initialize the @var{ignore-count}.
17387@item -r
17388Insert a regular breakpoint in all the functions whose names match the
17389given regular expression. Other flags are not applicable to regular
17390expresson.
17391@end table
17392
17393@subsubheading Result
17394
17395The result is in the form:
17396
17397@smallexample
17398 ^done,bkptno="@var{number}",func="@var{funcname}",
17399 file="@var{filename}",line="@var{lineno}"
17400@end smallexample
17401
17402@noindent
17403where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
17404is the name of the function where the breakpoint was inserted,
17405@var{filename} is the name of the source file which contains this
17406function, and @var{lineno} is the source line number within that file.
17407
17408Note: this format is open to change.
17409@c An out-of-band breakpoint instead of part of the result?
17410
17411@subsubheading @value{GDBN} Command
17412
17413The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
17414@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
17415
17416@subsubheading Example
17417
17418@smallexample
17419(@value{GDBP})
17420-break-insert main
17421^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17422(@value{GDBP})
17423-break-insert -t foo
17424^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
17425(@value{GDBP})
17426-break-list
17427^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17428hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17429@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17430@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17431@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17432@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17433@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17434body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17435addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
17436bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
17437addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
17438(@value{GDBP})
17439-break-insert -r foo.*
17440~int foo(int, int);
17441^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
17442(@value{GDBP})
17443@end smallexample
17444
17445@subheading The @code{-break-list} Command
17446@findex -break-list
17447
17448@subsubheading Synopsis
17449
17450@smallexample
17451 -break-list
17452@end smallexample
17453
17454Displays the list of inserted breakpoints, showing the following fields:
17455
17456@table @samp
17457@item Number
17458number of the breakpoint
17459@item Type
17460type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
17461@item Disposition
17462should the breakpoint be deleted or disabled when it is hit: @samp{keep}
17463or @samp{nokeep}
17464@item Enabled
17465is the breakpoint enabled or no: @samp{y} or @samp{n}
17466@item Address
17467memory location at which the breakpoint is set
17468@item What
17469logical location of the breakpoint, expressed by function name, file
17470name, line number
17471@item Times
17472number of times the breakpoint has been hit
17473@end table
17474
17475If there are no breakpoints or watchpoints, the @code{BreakpointTable}
17476@code{body} field is an empty list.
17477
17478@subsubheading @value{GDBN} Command
17479
17480The corresponding @value{GDBN} command is @samp{info break}.
17481
17482@subsubheading Example
17483
17484@smallexample
17485(@value{GDBP})
17486-break-list
17487^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17488hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17489@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17490@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17491@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17492@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17493@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17494body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17495addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
17496bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17497addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
17498(@value{GDBP})
17499@end smallexample
17500
17501Here's an example of the result when there are no breakpoints:
17502
17503@smallexample
17504(@value{GDBP})
17505-break-list
17506^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17507hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17508@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17509@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17510@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17511@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17512@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17513body=[]@}
17514(@value{GDBP})
17515@end smallexample
17516
17517@subheading The @code{-break-watch} Command
17518@findex -break-watch
17519
17520@subsubheading Synopsis
17521
17522@smallexample
17523 -break-watch [ -a | -r ]
17524@end smallexample
17525
17526Create a watchpoint. With the @samp{-a} option it will create an
17527@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
17528read from or on a write to the memory location. With the @samp{-r}
17529option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
17530trigger only when the memory location is accessed for reading. Without
17531either of the options, the watchpoint created is a regular watchpoint,
17532i.e. it will trigger when the memory location is accessed for writing.
17533@xref{Set Watchpoints, , Setting watchpoints}.
17534
17535Note that @samp{-break-list} will report a single list of watchpoints and
17536breakpoints inserted.
17537
17538@subsubheading @value{GDBN} Command
17539
17540The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
17541@samp{rwatch}.
17542
17543@subsubheading Example
17544
17545Setting a watchpoint on a variable in the @code{main} function:
17546
17547@smallexample
17548(@value{GDBP})
17549-break-watch x
17550^done,wpt=@{number="2",exp="x"@}
17551(@value{GDBP})
17552-exec-continue
17553^running
17554^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
17555value=@{old="-268439212",new="55"@},
76ff342d
DJ
17556frame=@{func="main",args=[],file="recursive2.c",
17557fullname="/home/foo/bar/devo/myproject/recursive2.c",line="5"@}
922fbb7b
AC
17558(@value{GDBP})
17559@end smallexample
17560
17561Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
17562the program execution twice: first for the variable changing value, then
17563for the watchpoint going out of scope.
17564
17565@smallexample
17566(@value{GDBP})
17567-break-watch C
17568^done,wpt=@{number="5",exp="C"@}
17569(@value{GDBP})
17570-exec-continue
17571^running
17572^done,reason="watchpoint-trigger",
17573wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
17574frame=@{func="callee4",args=[],
76ff342d
DJ
17575file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17576fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17577(@value{GDBP})
17578-exec-continue
17579^running
17580^done,reason="watchpoint-scope",wpnum="5",
17581frame=@{func="callee3",args=[@{name="strarg",
17582value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17583file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17584fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17585(@value{GDBP})
17586@end smallexample
17587
17588Listing breakpoints and watchpoints, at different points in the program
17589execution. Note that once the watchpoint goes out of scope, it is
17590deleted.
17591
17592@smallexample
17593(@value{GDBP})
17594-break-watch C
17595^done,wpt=@{number="2",exp="C"@}
17596(@value{GDBP})
17597-break-list
17598^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17599hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17600@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17601@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17602@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17603@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17604@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17605body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17606addr="0x00010734",func="callee4",
17607file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17608bkpt=@{number="2",type="watchpoint",disp="keep",
17609enabled="y",addr="",what="C",times="0"@}]@}
17610(@value{GDBP})
17611-exec-continue
17612^running
17613^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
17614value=@{old="-276895068",new="3"@},
17615frame=@{func="callee4",args=[],
76ff342d
DJ
17616file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17617fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17618(@value{GDBP})
17619-break-list
17620^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17621hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17622@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17623@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17624@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17625@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17626@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17627body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17628addr="0x00010734",func="callee4",
17629file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17630bkpt=@{number="2",type="watchpoint",disp="keep",
17631enabled="y",addr="",what="C",times="-5"@}]@}
17632(@value{GDBP})
17633-exec-continue
17634^running
17635^done,reason="watchpoint-scope",wpnum="2",
17636frame=@{func="callee3",args=[@{name="strarg",
17637value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17638file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17639fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17640(@value{GDBP})
17641-break-list
17642^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17643hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17644@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17645@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17646@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17647@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17648@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17649body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17650addr="0x00010734",func="callee4",
17651file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
17652(@value{GDBP})
17653@end smallexample
17654
17655@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17656@node GDB/MI Data Manipulation
17657@section @sc{gdb/mi} Data Manipulation
17658
17659@cindex data manipulation, in @sc{gdb/mi}
17660@cindex @sc{gdb/mi}, data manipulation
17661This section describes the @sc{gdb/mi} commands that manipulate data:
17662examine memory and registers, evaluate expressions, etc.
17663
17664@c REMOVED FROM THE INTERFACE.
17665@c @subheading -data-assign
17666@c Change the value of a program variable. Plenty of side effects.
17667@c @subsubheading GDB command
17668@c set variable
17669@c @subsubheading Example
17670@c N.A.
17671
17672@subheading The @code{-data-disassemble} Command
17673@findex -data-disassemble
17674
17675@subsubheading Synopsis
17676
17677@smallexample
17678 -data-disassemble
17679 [ -s @var{start-addr} -e @var{end-addr} ]
17680 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
17681 -- @var{mode}
17682@end smallexample
17683
17684@noindent
17685Where:
17686
17687@table @samp
17688@item @var{start-addr}
17689is the beginning address (or @code{$pc})
17690@item @var{end-addr}
17691is the end address
17692@item @var{filename}
17693is the name of the file to disassemble
17694@item @var{linenum}
17695is the line number to disassemble around
17696@item @var{lines}
17697is the the number of disassembly lines to be produced. If it is -1,
17698the whole function will be disassembled, in case no @var{end-addr} is
17699specified. If @var{end-addr} is specified as a non-zero value, and
17700@var{lines} is lower than the number of disassembly lines between
17701@var{start-addr} and @var{end-addr}, only @var{lines} lines are
17702displayed; if @var{lines} is higher than the number of lines between
17703@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
17704are displayed.
17705@item @var{mode}
17706is either 0 (meaning only disassembly) or 1 (meaning mixed source and
17707disassembly).
17708@end table
17709
17710@subsubheading Result
17711
17712The output for each instruction is composed of four fields:
17713
17714@itemize @bullet
17715@item Address
17716@item Func-name
17717@item Offset
17718@item Instruction
17719@end itemize
17720
17721Note that whatever included in the instruction field, is not manipulated
17722directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
17723
17724@subsubheading @value{GDBN} Command
17725
17726There's no direct mapping from this command to the CLI.
17727
17728@subsubheading Example
17729
17730Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
17731
17732@smallexample
17733(@value{GDBP})
17734-data-disassemble -s $pc -e "$pc + 20" -- 0
17735^done,
17736asm_insns=[
17737@{address="0x000107c0",func-name="main",offset="4",
17738inst="mov 2, %o0"@},
17739@{address="0x000107c4",func-name="main",offset="8",
17740inst="sethi %hi(0x11800), %o2"@},
17741@{address="0x000107c8",func-name="main",offset="12",
17742inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
17743@{address="0x000107cc",func-name="main",offset="16",
17744inst="sethi %hi(0x11800), %o2"@},
17745@{address="0x000107d0",func-name="main",offset="20",
17746inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
17747(@value{GDBP})
17748@end smallexample
17749
17750Disassemble the whole @code{main} function. Line 32 is part of
17751@code{main}.
17752
17753@smallexample
17754-data-disassemble -f basics.c -l 32 -- 0
17755^done,asm_insns=[
17756@{address="0x000107bc",func-name="main",offset="0",
17757inst="save %sp, -112, %sp"@},
17758@{address="0x000107c0",func-name="main",offset="4",
17759inst="mov 2, %o0"@},
17760@{address="0x000107c4",func-name="main",offset="8",
17761inst="sethi %hi(0x11800), %o2"@},
17762[@dots{}]
17763@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
17764@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
17765(@value{GDBP})
17766@end smallexample
17767
17768Disassemble 3 instructions from the start of @code{main}:
17769
17770@smallexample
17771(@value{GDBP})
17772-data-disassemble -f basics.c -l 32 -n 3 -- 0
17773^done,asm_insns=[
17774@{address="0x000107bc",func-name="main",offset="0",
17775inst="save %sp, -112, %sp"@},
17776@{address="0x000107c0",func-name="main",offset="4",
17777inst="mov 2, %o0"@},
17778@{address="0x000107c4",func-name="main",offset="8",
17779inst="sethi %hi(0x11800), %o2"@}]
17780(@value{GDBP})
17781@end smallexample
17782
17783Disassemble 3 instructions from the start of @code{main} in mixed mode:
17784
17785@smallexample
17786(@value{GDBP})
17787-data-disassemble -f basics.c -l 32 -n 3 -- 1
17788^done,asm_insns=[
17789src_and_asm_line=@{line="31",
17790file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17791 testsuite/gdb.mi/basics.c",line_asm_insn=[
17792@{address="0x000107bc",func-name="main",offset="0",
17793inst="save %sp, -112, %sp"@}]@},
17794src_and_asm_line=@{line="32",
17795file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17796 testsuite/gdb.mi/basics.c",line_asm_insn=[
17797@{address="0x000107c0",func-name="main",offset="4",
17798inst="mov 2, %o0"@},
17799@{address="0x000107c4",func-name="main",offset="8",
17800inst="sethi %hi(0x11800), %o2"@}]@}]
17801(@value{GDBP})
17802@end smallexample
17803
17804
17805@subheading The @code{-data-evaluate-expression} Command
17806@findex -data-evaluate-expression
17807
17808@subsubheading Synopsis
17809
17810@smallexample
17811 -data-evaluate-expression @var{expr}
17812@end smallexample
17813
17814Evaluate @var{expr} as an expression. The expression could contain an
17815inferior function call. The function call will execute synchronously.
17816If the expression contains spaces, it must be enclosed in double quotes.
17817
17818@subsubheading @value{GDBN} Command
17819
17820The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
17821@samp{call}. In @code{gdbtk} only, there's a corresponding
17822@samp{gdb_eval} command.
17823
17824@subsubheading Example
17825
17826In the following example, the numbers that precede the commands are the
17827@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
17828Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
17829output.
17830
17831@smallexample
17832211-data-evaluate-expression A
17833211^done,value="1"
17834(@value{GDBP})
17835311-data-evaluate-expression &A
17836311^done,value="0xefffeb7c"
17837(@value{GDBP})
17838411-data-evaluate-expression A+3
17839411^done,value="4"
17840(@value{GDBP})
17841511-data-evaluate-expression "A + 3"
17842511^done,value="4"
17843(@value{GDBP})
17844@end smallexample
17845
17846
17847@subheading The @code{-data-list-changed-registers} Command
17848@findex -data-list-changed-registers
17849
17850@subsubheading Synopsis
17851
17852@smallexample
17853 -data-list-changed-registers
17854@end smallexample
17855
17856Display a list of the registers that have changed.
17857
17858@subsubheading @value{GDBN} Command
17859
17860@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
17861has the corresponding command @samp{gdb_changed_register_list}.
17862
17863@subsubheading Example
17864
17865On a PPC MBX board:
17866
17867@smallexample
17868(@value{GDBP})
17869-exec-continue
17870^running
17871
17872(@value{GDBP})
17873*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
76ff342d 17874args=[],file="try.c",fullname="/home/foo/bar/devo/myproject/try.c",line="5"@}
922fbb7b
AC
17875(@value{GDBP})
17876-data-list-changed-registers
17877^done,changed-registers=["0","1","2","4","5","6","7","8","9",
17878"10","11","13","14","15","16","17","18","19","20","21","22","23",
17879"24","25","26","27","28","30","31","64","65","66","67","69"]
17880(@value{GDBP})
17881@end smallexample
17882
17883
17884@subheading The @code{-data-list-register-names} Command
17885@findex -data-list-register-names
17886
17887@subsubheading Synopsis
17888
17889@smallexample
17890 -data-list-register-names [ ( @var{regno} )+ ]
17891@end smallexample
17892
17893Show a list of register names for the current target. If no arguments
17894are given, it shows a list of the names of all the registers. If
17895integer numbers are given as arguments, it will print a list of the
17896names of the registers corresponding to the arguments. To ensure
17897consistency between a register name and its number, the output list may
17898include empty register names.
17899
17900@subsubheading @value{GDBN} Command
17901
17902@value{GDBN} does not have a command which corresponds to
17903@samp{-data-list-register-names}. In @code{gdbtk} there is a
17904corresponding command @samp{gdb_regnames}.
17905
17906@subsubheading Example
17907
17908For the PPC MBX board:
17909@smallexample
17910(@value{GDBP})
17911-data-list-register-names
17912^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
17913"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
17914"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
17915"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
17916"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
17917"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
17918"", "pc","ps","cr","lr","ctr","xer"]
17919(@value{GDBP})
17920-data-list-register-names 1 2 3
17921^done,register-names=["r1","r2","r3"]
17922(@value{GDBP})
17923@end smallexample
17924
17925@subheading The @code{-data-list-register-values} Command
17926@findex -data-list-register-values
17927
17928@subsubheading Synopsis
17929
17930@smallexample
17931 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
17932@end smallexample
17933
17934Display the registers' contents. @var{fmt} is the format according to
17935which the registers' contents are to be returned, followed by an optional
17936list of numbers specifying the registers to display. A missing list of
17937numbers indicates that the contents of all the registers must be returned.
17938
17939Allowed formats for @var{fmt} are:
17940
17941@table @code
17942@item x
17943Hexadecimal
17944@item o
17945Octal
17946@item t
17947Binary
17948@item d
17949Decimal
17950@item r
17951Raw
17952@item N
17953Natural
17954@end table
17955
17956@subsubheading @value{GDBN} Command
17957
17958The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
17959all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
17960
17961@subsubheading Example
17962
17963For a PPC MBX board (note: line breaks are for readability only, they
17964don't appear in the actual output):
17965
17966@smallexample
17967(@value{GDBP})
17968-data-list-register-values r 64 65
17969^done,register-values=[@{number="64",value="0xfe00a300"@},
17970@{number="65",value="0x00029002"@}]
17971(@value{GDBP})
17972-data-list-register-values x
17973^done,register-values=[@{number="0",value="0xfe0043c8"@},
17974@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
17975@{number="3",value="0x0"@},@{number="4",value="0xa"@},
17976@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
17977@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
17978@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
17979@{number="11",value="0x1"@},@{number="12",value="0x0"@},
17980@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
17981@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
17982@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
17983@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
17984@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
17985@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
17986@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
17987@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
17988@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
17989@{number="31",value="0x0"@},@{number="32",value="0x0"@},
17990@{number="33",value="0x0"@},@{number="34",value="0x0"@},
17991@{number="35",value="0x0"@},@{number="36",value="0x0"@},
17992@{number="37",value="0x0"@},@{number="38",value="0x0"@},
17993@{number="39",value="0x0"@},@{number="40",value="0x0"@},
17994@{number="41",value="0x0"@},@{number="42",value="0x0"@},
17995@{number="43",value="0x0"@},@{number="44",value="0x0"@},
17996@{number="45",value="0x0"@},@{number="46",value="0x0"@},
17997@{number="47",value="0x0"@},@{number="48",value="0x0"@},
17998@{number="49",value="0x0"@},@{number="50",value="0x0"@},
17999@{number="51",value="0x0"@},@{number="52",value="0x0"@},
18000@{number="53",value="0x0"@},@{number="54",value="0x0"@},
18001@{number="55",value="0x0"@},@{number="56",value="0x0"@},
18002@{number="57",value="0x0"@},@{number="58",value="0x0"@},
18003@{number="59",value="0x0"@},@{number="60",value="0x0"@},
18004@{number="61",value="0x0"@},@{number="62",value="0x0"@},
18005@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
18006@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
18007@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
18008@{number="69",value="0x20002b03"@}]
18009(@value{GDBP})
18010@end smallexample
18011
18012
18013@subheading The @code{-data-read-memory} Command
18014@findex -data-read-memory
18015
18016@subsubheading Synopsis
18017
18018@smallexample
18019 -data-read-memory [ -o @var{byte-offset} ]
18020 @var{address} @var{word-format} @var{word-size}
18021 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
18022@end smallexample
18023
18024@noindent
18025where:
18026
18027@table @samp
18028@item @var{address}
18029An expression specifying the address of the first memory word to be
18030read. Complex expressions containing embedded white space should be
18031quoted using the C convention.
18032
18033@item @var{word-format}
18034The format to be used to print the memory words. The notation is the
18035same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
18036,Output formats}).
18037
18038@item @var{word-size}
18039The size of each memory word in bytes.
18040
18041@item @var{nr-rows}
18042The number of rows in the output table.
18043
18044@item @var{nr-cols}
18045The number of columns in the output table.
18046
18047@item @var{aschar}
18048If present, indicates that each row should include an @sc{ascii} dump. The
18049value of @var{aschar} is used as a padding character when a byte is not a
18050member of the printable @sc{ascii} character set (printable @sc{ascii}
18051characters are those whose code is between 32 and 126, inclusively).
18052
18053@item @var{byte-offset}
18054An offset to add to the @var{address} before fetching memory.
18055@end table
18056
18057This command displays memory contents as a table of @var{nr-rows} by
18058@var{nr-cols} words, each word being @var{word-size} bytes. In total,
18059@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
18060(returned as @samp{total-bytes}). Should less than the requested number
18061of bytes be returned by the target, the missing words are identified
18062using @samp{N/A}. The number of bytes read from the target is returned
18063in @samp{nr-bytes} and the starting address used to read memory in
18064@samp{addr}.
18065
18066The address of the next/previous row or page is available in
18067@samp{next-row} and @samp{prev-row}, @samp{next-page} and
18068@samp{prev-page}.
18069
18070@subsubheading @value{GDBN} Command
18071
18072The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
18073@samp{gdb_get_mem} memory read command.
18074
18075@subsubheading Example
18076
18077Read six bytes of memory starting at @code{bytes+6} but then offset by
18078@code{-6} bytes. Format as three rows of two columns. One byte per
18079word. Display each word in hex.
18080
18081@smallexample
18082(@value{GDBP})
180839-data-read-memory -o -6 -- bytes+6 x 1 3 2
180849^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
18085next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
18086prev-page="0x0000138a",memory=[
18087@{addr="0x00001390",data=["0x00","0x01"]@},
18088@{addr="0x00001392",data=["0x02","0x03"]@},
18089@{addr="0x00001394",data=["0x04","0x05"]@}]
18090(@value{GDBP})
18091@end smallexample
18092
18093Read two bytes of memory starting at address @code{shorts + 64} and
18094display as a single word formatted in decimal.
18095
18096@smallexample
18097(@value{GDBP})
180985-data-read-memory shorts+64 d 2 1 1
180995^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
18100next-row="0x00001512",prev-row="0x0000150e",
18101next-page="0x00001512",prev-page="0x0000150e",memory=[
18102@{addr="0x00001510",data=["128"]@}]
18103(@value{GDBP})
18104@end smallexample
18105
18106Read thirty two bytes of memory starting at @code{bytes+16} and format
18107as eight rows of four columns. Include a string encoding with @samp{x}
18108used as the non-printable character.
18109
18110@smallexample
18111(@value{GDBP})
181124-data-read-memory bytes+16 x 1 8 4 x
181134^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
18114next-row="0x000013c0",prev-row="0x0000139c",
18115next-page="0x000013c0",prev-page="0x00001380",memory=[
18116@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
18117@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
18118@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
18119@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
18120@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
18121@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
18122@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
18123@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
18124(@value{GDBP})
18125@end smallexample
18126
18127@subheading The @code{-display-delete} Command
18128@findex -display-delete
18129
18130@subsubheading Synopsis
18131
18132@smallexample
18133 -display-delete @var{number}
18134@end smallexample
18135
18136Delete the display @var{number}.
18137
18138@subsubheading @value{GDBN} Command
18139
18140The corresponding @value{GDBN} command is @samp{delete display}.
18141
18142@subsubheading Example
18143N.A.
18144
18145
18146@subheading The @code{-display-disable} Command
18147@findex -display-disable
18148
18149@subsubheading Synopsis
18150
18151@smallexample
18152 -display-disable @var{number}
18153@end smallexample
18154
18155Disable display @var{number}.
18156
18157@subsubheading @value{GDBN} Command
18158
18159The corresponding @value{GDBN} command is @samp{disable display}.
18160
18161@subsubheading Example
18162N.A.
18163
18164
18165@subheading The @code{-display-enable} Command
18166@findex -display-enable
18167
18168@subsubheading Synopsis
18169
18170@smallexample
18171 -display-enable @var{number}
18172@end smallexample
18173
18174Enable display @var{number}.
18175
18176@subsubheading @value{GDBN} Command
18177
18178The corresponding @value{GDBN} command is @samp{enable display}.
18179
18180@subsubheading Example
18181N.A.
18182
18183
18184@subheading The @code{-display-insert} Command
18185@findex -display-insert
18186
18187@subsubheading Synopsis
18188
18189@smallexample
18190 -display-insert @var{expression}
18191@end smallexample
18192
18193Display @var{expression} every time the program stops.
18194
18195@subsubheading @value{GDBN} Command
18196
18197The corresponding @value{GDBN} command is @samp{display}.
18198
18199@subsubheading Example
18200N.A.
18201
18202
18203@subheading The @code{-display-list} Command
18204@findex -display-list
18205
18206@subsubheading Synopsis
18207
18208@smallexample
18209 -display-list
18210@end smallexample
18211
18212List the displays. Do not show the current values.
18213
18214@subsubheading @value{GDBN} Command
18215
18216The corresponding @value{GDBN} command is @samp{info display}.
18217
18218@subsubheading Example
18219N.A.
18220
18221
18222@subheading The @code{-environment-cd} Command
18223@findex -environment-cd
18224
18225@subsubheading Synopsis
18226
18227@smallexample
18228 -environment-cd @var{pathdir}
18229@end smallexample
18230
18231Set @value{GDBN}'s working directory.
18232
18233@subsubheading @value{GDBN} Command
18234
18235The corresponding @value{GDBN} command is @samp{cd}.
18236
18237@subsubheading Example
18238
18239@smallexample
18240(@value{GDBP})
18241-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18242^done
18243(@value{GDBP})
18244@end smallexample
18245
18246
18247@subheading The @code{-environment-directory} Command
18248@findex -environment-directory
18249
18250@subsubheading Synopsis
18251
18252@smallexample
18253 -environment-directory [ -r ] [ @var{pathdir} ]+
18254@end smallexample
18255
18256Add directories @var{pathdir} to beginning of search path for source files.
18257If the @samp{-r} option is used, the search path is reset to the default
b383017d 18258search path. If directories @var{pathdir} are supplied in addition to the
922fbb7b
AC
18259@samp{-r} option, the search path is first reset and then addition
18260occurs as normal.
b383017d 18261Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18262multiple directories in a single command
18263results in the directories added to the beginning of the
18264search path in the same order they were presented in the command.
18265If blanks are needed as
18266part of a directory name, double-quotes should be used around
18267the name. In the command output, the path will show up separated
b383017d 18268by the system directory-separator character. The directory-seperator
922fbb7b
AC
18269character must not be used
18270in any directory name.
18271If no directories are specified, the current search path is displayed.
18272
18273@subsubheading @value{GDBN} Command
18274
18275The corresponding @value{GDBN} command is @samp{dir}.
18276
18277@subsubheading Example
18278
18279@smallexample
18280(@value{GDBP})
18281-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18282^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18283(@value{GDBP})
18284-environment-directory ""
18285^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18286(@value{GDBP})
18287-environment-directory -r /home/jjohnstn/src/gdb /usr/src
18288^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
18289(@value{GDBP})
18290-environment-directory -r
18291^done,source-path="$cdir:$cwd"
18292(@value{GDBP})
18293@end smallexample
18294
18295
18296@subheading The @code{-environment-path} Command
18297@findex -environment-path
18298
18299@subsubheading Synopsis
18300
18301@smallexample
18302 -environment-path [ -r ] [ @var{pathdir} ]+
18303@end smallexample
18304
18305Add directories @var{pathdir} to beginning of search path for object files.
18306If the @samp{-r} option is used, the search path is reset to the original
b383017d
RM
18307search path that existed at gdb start-up. If directories @var{pathdir} are
18308supplied in addition to the
922fbb7b
AC
18309@samp{-r} option, the search path is first reset and then addition
18310occurs as normal.
b383017d 18311Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18312multiple directories in a single command
18313results in the directories added to the beginning of the
18314search path in the same order they were presented in the command.
18315If blanks are needed as
18316part of a directory name, double-quotes should be used around
18317the name. In the command output, the path will show up separated
b383017d 18318by the system directory-separator character. The directory-seperator
922fbb7b
AC
18319character must not be used
18320in any directory name.
18321If no directories are specified, the current path is displayed.
18322
18323
18324@subsubheading @value{GDBN} Command
18325
18326The corresponding @value{GDBN} command is @samp{path}.
18327
18328@subsubheading Example
18329
18330@smallexample
18331(@value{GDBP})
b383017d 18332-environment-path
922fbb7b
AC
18333^done,path="/usr/bin"
18334(@value{GDBP})
18335-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
18336^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
18337(@value{GDBP})
18338-environment-path -r /usr/local/bin
18339^done,path="/usr/local/bin:/usr/bin"
18340(@value{GDBP})
18341@end smallexample
18342
18343
18344@subheading The @code{-environment-pwd} Command
18345@findex -environment-pwd
18346
18347@subsubheading Synopsis
18348
18349@smallexample
18350 -environment-pwd
18351@end smallexample
18352
18353Show the current working directory.
18354
18355@subsubheading @value{GDBN} command
18356
18357The corresponding @value{GDBN} command is @samp{pwd}.
18358
18359@subsubheading Example
18360
18361@smallexample
18362(@value{GDBP})
18363-environment-pwd
18364^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
18365(@value{GDBP})
18366@end smallexample
18367
18368@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18369@node GDB/MI Program Control
18370@section @sc{gdb/mi} Program control
18371
18372@subsubheading Program termination
18373
18374As a result of execution, the inferior program can run to completion, if
18375it doesn't encounter any breakpoints. In this case the output will
18376include an exit code, if the program has exited exceptionally.
18377
18378@subsubheading Examples
18379
18380@noindent
18381Program exited normally:
18382
18383@smallexample
18384(@value{GDBP})
18385-exec-run
18386^running
18387(@value{GDBP})
18388x = 55
18389*stopped,reason="exited-normally"
18390(@value{GDBP})
18391@end smallexample
18392
18393@noindent
18394Program exited exceptionally:
18395
18396@smallexample
18397(@value{GDBP})
18398-exec-run
18399^running
18400(@value{GDBP})
18401x = 55
18402*stopped,reason="exited",exit-code="01"
18403(@value{GDBP})
18404@end smallexample
18405
18406Another way the program can terminate is if it receives a signal such as
18407@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
18408
18409@smallexample
18410(@value{GDBP})
18411*stopped,reason="exited-signalled",signal-name="SIGINT",
18412signal-meaning="Interrupt"
18413@end smallexample
18414
18415
18416@subheading The @code{-exec-abort} Command
18417@findex -exec-abort
18418
18419@subsubheading Synopsis
18420
18421@smallexample
18422 -exec-abort
18423@end smallexample
18424
18425Kill the inferior running program.
18426
18427@subsubheading @value{GDBN} Command
18428
18429The corresponding @value{GDBN} command is @samp{kill}.
18430
18431@subsubheading Example
18432N.A.
18433
18434
18435@subheading The @code{-exec-arguments} Command
18436@findex -exec-arguments
18437
18438@subsubheading Synopsis
18439
18440@smallexample
18441 -exec-arguments @var{args}
18442@end smallexample
18443
18444Set the inferior program arguments, to be used in the next
18445@samp{-exec-run}.
18446
18447@subsubheading @value{GDBN} Command
18448
18449The corresponding @value{GDBN} command is @samp{set args}.
18450
18451@subsubheading Example
18452
18453@c FIXME!
18454Don't have one around.
18455
18456
18457@subheading The @code{-exec-continue} Command
18458@findex -exec-continue
18459
18460@subsubheading Synopsis
18461
18462@smallexample
18463 -exec-continue
18464@end smallexample
18465
18466Asynchronous command. Resumes the execution of the inferior program
18467until a breakpoint is encountered, or until the inferior exits.
18468
18469@subsubheading @value{GDBN} Command
18470
18471The corresponding @value{GDBN} corresponding is @samp{continue}.
18472
18473@subsubheading Example
18474
18475@smallexample
18476-exec-continue
18477^running
18478(@value{GDBP})
18479@@Hello world
18480*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
76ff342d 18481file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="13"@}
922fbb7b
AC
18482(@value{GDBP})
18483@end smallexample
18484
18485
18486@subheading The @code{-exec-finish} Command
18487@findex -exec-finish
18488
18489@subsubheading Synopsis
18490
18491@smallexample
18492 -exec-finish
18493@end smallexample
18494
18495Asynchronous command. Resumes the execution of the inferior program
18496until the current function is exited. Displays the results returned by
18497the function.
18498
18499@subsubheading @value{GDBN} Command
18500
18501The corresponding @value{GDBN} command is @samp{finish}.
18502
18503@subsubheading Example
18504
18505Function returning @code{void}.
18506
18507@smallexample
18508-exec-finish
18509^running
18510(@value{GDBP})
18511@@hello from foo
18512*stopped,reason="function-finished",frame=@{func="main",args=[],
76ff342d 18513file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="7"@}
922fbb7b
AC
18514(@value{GDBP})
18515@end smallexample
18516
18517Function returning other than @code{void}. The name of the internal
18518@value{GDBN} variable storing the result is printed, together with the
18519value itself.
18520
18521@smallexample
18522-exec-finish
18523^running
18524(@value{GDBP})
18525*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
18526args=[@{name="a",value="1"],@{name="b",value="9"@}@},
76ff342d 18527file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b
AC
18528gdb-result-var="$1",return-value="0"
18529(@value{GDBP})
18530@end smallexample
18531
18532
18533@subheading The @code{-exec-interrupt} Command
18534@findex -exec-interrupt
18535
18536@subsubheading Synopsis
18537
18538@smallexample
18539 -exec-interrupt
18540@end smallexample
18541
18542Asynchronous command. Interrupts the background execution of the target.
18543Note how the token associated with the stop message is the one for the
18544execution command that has been interrupted. The token for the interrupt
18545itself only appears in the @samp{^done} output. If the user is trying to
18546interrupt a non-running program, an error message will be printed.
18547
18548@subsubheading @value{GDBN} Command
18549
18550The corresponding @value{GDBN} command is @samp{interrupt}.
18551
18552@subsubheading Example
18553
18554@smallexample
18555(@value{GDBP})
18556111-exec-continue
18557111^running
18558
18559(@value{GDBP})
18560222-exec-interrupt
18561222^done
18562(@value{GDBP})
18563111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d
DJ
18564frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
18565fullname="/home/foo/bar/devo/myproject/try.c",line="13"@}
922fbb7b
AC
18566(@value{GDBP})
18567
18568(@value{GDBP})
18569-exec-interrupt
18570^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
18571(@value{GDBP})
18572@end smallexample
18573
18574
18575@subheading The @code{-exec-next} Command
18576@findex -exec-next
18577
18578@subsubheading Synopsis
18579
18580@smallexample
18581 -exec-next
18582@end smallexample
18583
18584Asynchronous command. Resumes execution of the inferior program, stopping
18585when the beginning of the next source line is reached.
18586
18587@subsubheading @value{GDBN} Command
18588
18589The corresponding @value{GDBN} command is @samp{next}.
18590
18591@subsubheading Example
18592
18593@smallexample
18594-exec-next
18595^running
18596(@value{GDBP})
18597*stopped,reason="end-stepping-range",line="8",file="hello.c"
18598(@value{GDBP})
18599@end smallexample
18600
18601
18602@subheading The @code{-exec-next-instruction} Command
18603@findex -exec-next-instruction
18604
18605@subsubheading Synopsis
18606
18607@smallexample
18608 -exec-next-instruction
18609@end smallexample
18610
18611Asynchronous command. Executes one machine instruction. If the
18612instruction is a function call continues until the function returns. If
18613the program stops at an instruction in the middle of a source line, the
18614address will be printed as well.
18615
18616@subsubheading @value{GDBN} Command
18617
18618The corresponding @value{GDBN} command is @samp{nexti}.
18619
18620@subsubheading Example
18621
18622@smallexample
18623(@value{GDBP})
18624-exec-next-instruction
18625^running
18626
18627(@value{GDBP})
18628*stopped,reason="end-stepping-range",
18629addr="0x000100d4",line="5",file="hello.c"
18630(@value{GDBP})
18631@end smallexample
18632
18633
18634@subheading The @code{-exec-return} Command
18635@findex -exec-return
18636
18637@subsubheading Synopsis
18638
18639@smallexample
18640 -exec-return
18641@end smallexample
18642
18643Makes current function return immediately. Doesn't execute the inferior.
18644Displays the new current frame.
18645
18646@subsubheading @value{GDBN} Command
18647
18648The corresponding @value{GDBN} command is @samp{return}.
18649
18650@subsubheading Example
18651
18652@smallexample
18653(@value{GDBP})
18654200-break-insert callee4
18655200^done,bkpt=@{number="1",addr="0x00010734",
18656file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
18657(@value{GDBP})
18658000-exec-run
18659000^running
18660(@value{GDBP})
18661000*stopped,reason="breakpoint-hit",bkptno="1",
18662frame=@{func="callee4",args=[],
76ff342d
DJ
18663file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18664fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
922fbb7b
AC
18665(@value{GDBP})
18666205-break-delete
18667205^done
18668(@value{GDBP})
18669111-exec-return
18670111^done,frame=@{level="0",func="callee3",
18671args=[@{name="strarg",
18672value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
18673file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18674fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
18675(@value{GDBP})
18676@end smallexample
18677
18678
18679@subheading The @code{-exec-run} Command
18680@findex -exec-run
18681
18682@subsubheading Synopsis
18683
18684@smallexample
18685 -exec-run
18686@end smallexample
18687
18688Asynchronous command. Starts execution of the inferior from the
18689beginning. The inferior executes until either a breakpoint is
18690encountered or the program exits.
18691
18692@subsubheading @value{GDBN} Command
18693
18694The corresponding @value{GDBN} command is @samp{run}.
18695
18696@subsubheading Example
18697
18698@smallexample
18699(@value{GDBP})
18700-break-insert main
18701^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
18702(@value{GDBP})
18703-exec-run
18704^running
18705(@value{GDBP})
18706*stopped,reason="breakpoint-hit",bkptno="1",
76ff342d
DJ
18707frame=@{func="main",args=[],file="recursive2.c",
18708fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}
922fbb7b
AC
18709(@value{GDBP})
18710@end smallexample
18711
18712
18713@subheading The @code{-exec-show-arguments} Command
18714@findex -exec-show-arguments
18715
18716@subsubheading Synopsis
18717
18718@smallexample
18719 -exec-show-arguments
18720@end smallexample
18721
18722Print the arguments of the program.
18723
18724@subsubheading @value{GDBN} Command
18725
18726The corresponding @value{GDBN} command is @samp{show args}.
18727
18728@subsubheading Example
18729N.A.
18730
18731@c @subheading -exec-signal
18732
18733@subheading The @code{-exec-step} Command
18734@findex -exec-step
18735
18736@subsubheading Synopsis
18737
18738@smallexample
18739 -exec-step
18740@end smallexample
18741
18742Asynchronous command. Resumes execution of the inferior program, stopping
18743when the beginning of the next source line is reached, if the next
18744source line is not a function call. If it is, stop at the first
18745instruction of the called function.
18746
18747@subsubheading @value{GDBN} Command
18748
18749The corresponding @value{GDBN} command is @samp{step}.
18750
18751@subsubheading Example
18752
18753Stepping into a function:
18754
18755@smallexample
18756-exec-step
18757^running
18758(@value{GDBP})
18759*stopped,reason="end-stepping-range",
18760frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d
DJ
18761@{name="b",value="0"@}],file="recursive2.c",
18762fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@}
922fbb7b
AC
18763(@value{GDBP})
18764@end smallexample
18765
18766Regular stepping:
18767
18768@smallexample
18769-exec-step
18770^running
18771(@value{GDBP})
18772*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
18773(@value{GDBP})
18774@end smallexample
18775
18776
18777@subheading The @code{-exec-step-instruction} Command
18778@findex -exec-step-instruction
18779
18780@subsubheading Synopsis
18781
18782@smallexample
18783 -exec-step-instruction
18784@end smallexample
18785
18786Asynchronous command. Resumes the inferior which executes one machine
18787instruction. The output, once @value{GDBN} has stopped, will vary depending on
18788whether we have stopped in the middle of a source line or not. In the
18789former case, the address at which the program stopped will be printed as
18790well.
18791
18792@subsubheading @value{GDBN} Command
18793
18794The corresponding @value{GDBN} command is @samp{stepi}.
18795
18796@subsubheading Example
18797
18798@smallexample
18799(@value{GDBP})
18800-exec-step-instruction
18801^running
18802
18803(@value{GDBP})
18804*stopped,reason="end-stepping-range",
76ff342d
DJ
18805frame=@{func="foo",args=[],file="try.c",
18806fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18807(@value{GDBP})
18808-exec-step-instruction
18809^running
18810
18811(@value{GDBP})
18812*stopped,reason="end-stepping-range",
76ff342d
DJ
18813frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
18814fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18815(@value{GDBP})
18816@end smallexample
18817
18818
18819@subheading The @code{-exec-until} Command
18820@findex -exec-until
18821
18822@subsubheading Synopsis
18823
18824@smallexample
18825 -exec-until [ @var{location} ]
18826@end smallexample
18827
18828Asynchronous command. Executes the inferior until the @var{location}
18829specified in the argument is reached. If there is no argument, the inferior
18830executes until a source line greater than the current one is reached.
18831The reason for stopping in this case will be @samp{location-reached}.
18832
18833@subsubheading @value{GDBN} Command
18834
18835The corresponding @value{GDBN} command is @samp{until}.
18836
18837@subsubheading Example
18838
18839@smallexample
18840(@value{GDBP})
18841-exec-until recursive2.c:6
18842^running
18843(@value{GDBP})
18844x = 55
18845*stopped,reason="location-reached",frame=@{func="main",args=[],
76ff342d 18846file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="6"@}
922fbb7b
AC
18847(@value{GDBP})
18848@end smallexample
18849
18850@ignore
18851@subheading -file-clear
18852Is this going away????
18853@end ignore
18854
18855
18856@subheading The @code{-file-exec-and-symbols} Command
18857@findex -file-exec-and-symbols
18858
18859@subsubheading Synopsis
18860
18861@smallexample
18862 -file-exec-and-symbols @var{file}
18863@end smallexample
18864
18865Specify the executable file to be debugged. This file is the one from
18866which the symbol table is also read. If no file is specified, the
18867command clears the executable and symbol information. If breakpoints
18868are set when using this command with no arguments, @value{GDBN} will produce
18869error messages. Otherwise, no output is produced, except a completion
18870notification.
18871
18872@subsubheading @value{GDBN} Command
18873
18874The corresponding @value{GDBN} command is @samp{file}.
18875
18876@subsubheading Example
18877
18878@smallexample
18879(@value{GDBP})
18880-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18881^done
18882(@value{GDBP})
18883@end smallexample
18884
18885
18886@subheading The @code{-file-exec-file} Command
18887@findex -file-exec-file
18888
18889@subsubheading Synopsis
18890
18891@smallexample
18892 -file-exec-file @var{file}
18893@end smallexample
18894
18895Specify the executable file to be debugged. Unlike
18896@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
18897from this file. If used without argument, @value{GDBN} clears the information
18898about the executable file. No output is produced, except a completion
18899notification.
18900
18901@subsubheading @value{GDBN} Command
18902
18903The corresponding @value{GDBN} command is @samp{exec-file}.
18904
18905@subsubheading Example
18906
18907@smallexample
18908(@value{GDBP})
18909-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18910^done
18911(@value{GDBP})
18912@end smallexample
18913
18914
18915@subheading The @code{-file-list-exec-sections} Command
18916@findex -file-list-exec-sections
18917
18918@subsubheading Synopsis
18919
18920@smallexample
18921 -file-list-exec-sections
18922@end smallexample
18923
18924List the sections of the current executable file.
18925
18926@subsubheading @value{GDBN} Command
18927
18928The @value{GDBN} command @samp{info file} shows, among the rest, the same
18929information as this command. @code{gdbtk} has a corresponding command
18930@samp{gdb_load_info}.
18931
18932@subsubheading Example
18933N.A.
18934
18935
1abaf70c
BR
18936@subheading The @code{-file-list-exec-source-file} Command
18937@findex -file-list-exec-source-file
18938
18939@subsubheading Synopsis
18940
18941@smallexample
18942 -file-list-exec-source-file
18943@end smallexample
18944
b383017d 18945List the line number, the current source file, and the absolute path
1abaf70c
BR
18946to the current source file for the current executable.
18947
18948@subsubheading @value{GDBN} Command
18949
18950There's no @value{GDBN} command which directly corresponds to this one.
18951
18952@subsubheading Example
18953
18954@smallexample
18955(@value{GDBP})
18956123-file-list-exec-source-file
18957123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
18958(@value{GDBP})
18959@end smallexample
18960
18961
922fbb7b
AC
18962@subheading The @code{-file-list-exec-source-files} Command
18963@findex -file-list-exec-source-files
18964
18965@subsubheading Synopsis
18966
18967@smallexample
18968 -file-list-exec-source-files
18969@end smallexample
18970
18971List the source files for the current executable.
18972
57c22c6c
BR
18973It will always output the filename, but only when GDB can find the absolute
18974file name of a source file, will it output the fullname.
18975
922fbb7b
AC
18976@subsubheading @value{GDBN} Command
18977
18978There's no @value{GDBN} command which directly corresponds to this one.
18979@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
18980
18981@subsubheading Example
57c22c6c
BR
18982@smallexample
18983(@value{GDBP})
18984-file-list-exec-source-files
18985^done,files=[
18986@{file=foo.c,fullname=/home/foo.c@},
18987@{file=/home/bar.c,fullname=/home/bar.c@},
18988@{file=gdb_could_not_find_fullpath.c@}]
18989(@value{GDBP})
18990@end smallexample
922fbb7b
AC
18991
18992@subheading The @code{-file-list-shared-libraries} Command
18993@findex -file-list-shared-libraries
18994
18995@subsubheading Synopsis
18996
18997@smallexample
18998 -file-list-shared-libraries
18999@end smallexample
19000
19001List the shared libraries in the program.
19002
19003@subsubheading @value{GDBN} Command
19004
19005The corresponding @value{GDBN} command is @samp{info shared}.
19006
19007@subsubheading Example
19008N.A.
19009
19010
19011@subheading The @code{-file-list-symbol-files} Command
19012@findex -file-list-symbol-files
19013
19014@subsubheading Synopsis
19015
19016@smallexample
19017 -file-list-symbol-files
19018@end smallexample
19019
19020List symbol files.
19021
19022@subsubheading @value{GDBN} Command
19023
19024The corresponding @value{GDBN} command is @samp{info file} (part of it).
19025
19026@subsubheading Example
19027N.A.
19028
19029
19030@subheading The @code{-file-symbol-file} Command
19031@findex -file-symbol-file
19032
19033@subsubheading Synopsis
19034
19035@smallexample
19036 -file-symbol-file @var{file}
19037@end smallexample
19038
19039Read symbol table info from the specified @var{file} argument. When
19040used without arguments, clears @value{GDBN}'s symbol table info. No output is
19041produced, except for a completion notification.
19042
19043@subsubheading @value{GDBN} Command
19044
19045The corresponding @value{GDBN} command is @samp{symbol-file}.
19046
19047@subsubheading Example
19048
19049@smallexample
19050(@value{GDBP})
19051-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
19052^done
19053(@value{GDBP})
19054@end smallexample
19055
19056@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19057@node GDB/MI Miscellaneous Commands
19058@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
19059
19060@c @subheading -gdb-complete
19061
19062@subheading The @code{-gdb-exit} Command
19063@findex -gdb-exit
19064
19065@subsubheading Synopsis
19066
19067@smallexample
19068 -gdb-exit
19069@end smallexample
19070
19071Exit @value{GDBN} immediately.
19072
19073@subsubheading @value{GDBN} Command
19074
19075Approximately corresponds to @samp{quit}.
19076
19077@subsubheading Example
19078
19079@smallexample
19080(@value{GDBP})
19081-gdb-exit
19082@end smallexample
19083
19084@subheading The @code{-gdb-set} Command
19085@findex -gdb-set
19086
19087@subsubheading Synopsis
19088
19089@smallexample
19090 -gdb-set
19091@end smallexample
19092
19093Set an internal @value{GDBN} variable.
19094@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
19095
19096@subsubheading @value{GDBN} Command
19097
19098The corresponding @value{GDBN} command is @samp{set}.
19099
19100@subsubheading Example
19101
19102@smallexample
19103(@value{GDBP})
19104-gdb-set $foo=3
19105^done
19106(@value{GDBP})
19107@end smallexample
19108
19109
19110@subheading The @code{-gdb-show} Command
19111@findex -gdb-show
19112
19113@subsubheading Synopsis
19114
19115@smallexample
19116 -gdb-show
19117@end smallexample
19118
19119Show the current value of a @value{GDBN} variable.
19120
19121@subsubheading @value{GDBN} command
19122
19123The corresponding @value{GDBN} command is @samp{show}.
19124
19125@subsubheading Example
19126
19127@smallexample
19128(@value{GDBP})
19129-gdb-show annotate
19130^done,value="0"
19131(@value{GDBP})
19132@end smallexample
19133
19134@c @subheading -gdb-source
19135
19136
19137@subheading The @code{-gdb-version} Command
19138@findex -gdb-version
19139
19140@subsubheading Synopsis
19141
19142@smallexample
19143 -gdb-version
19144@end smallexample
19145
19146Show version information for @value{GDBN}. Used mostly in testing.
19147
19148@subsubheading @value{GDBN} Command
19149
19150There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
19151information when you start an interactive session.
19152
19153@subsubheading Example
19154
19155@c This example modifies the actual output from GDB to avoid overfull
19156@c box in TeX.
19157@smallexample
19158(@value{GDBP})
19159-gdb-version
19160~GNU gdb 5.2.1
19161~Copyright 2000 Free Software Foundation, Inc.
19162~GDB is free software, covered by the GNU General Public License, and
19163~you are welcome to change it and/or distribute copies of it under
19164~ certain conditions.
19165~Type "show copying" to see the conditions.
19166~There is absolutely no warranty for GDB. Type "show warranty" for
19167~ details.
b383017d 19168~This GDB was configured as
922fbb7b
AC
19169 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
19170^done
19171(@value{GDBP})
19172@end smallexample
19173
19174@subheading The @code{-interpreter-exec} Command
19175@findex -interpreter-exec
19176
19177@subheading Synopsis
19178
19179@smallexample
19180-interpreter-exec @var{interpreter} @var{command}
19181@end smallexample
19182
19183Execute the specified @var{command} in the given @var{interpreter}.
19184
19185@subheading @value{GDBN} Command
19186
19187The corresponding @value{GDBN} command is @samp{interpreter-exec}.
19188
19189@subheading Example
19190
19191@smallexample
19192(@value{GDBP})
19193-interpreter-exec console "break main"
19194&"During symbol reading, couldn't parse type; debugger out of date?.\n"
19195&"During symbol reading, bad structure-type format.\n"
19196~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
19197^done
19198(@value{GDBP})
19199@end smallexample
19200
3cb3b8df
BR
19201@subheading The @code{-inferior-tty-set} Command
19202@findex -inferior-tty-set
19203
19204@subheading Synopsis
19205
19206@smallexample
19207-inferior-tty-set /dev/pts/1
19208@end smallexample
19209
19210Set terminal for future runs of the program being debugged.
19211
19212@subheading @value{GDBN} Command
19213
19214The corresponding @value{GDBN} command is @samp{set inferior-tty /dev/pts/1}.
19215
19216@subheading Example
19217
19218@smallexample
19219(@value{GDBP})
19220-inferior-tty-set /dev/pts/1
19221^done
19222(@value{GDBP})
19223@end smallexample
19224
19225@subheading The @code{-inferior-tty-show} Command
19226@findex -inferior-tty-show
19227
19228@subheading Synopsis
19229
19230@smallexample
19231-inferior-tty-show
19232@end smallexample
19233
19234Show terminal for future runs of program being debugged.
19235
19236@subheading @value{GDBN} Command
19237
38f1196a 19238The corresponding @value{GDBN} command is @samp{show inferior-tty}.
3cb3b8df
BR
19239
19240@subheading Example
19241
19242@smallexample
19243(@value{GDBP})
19244-inferior-tty-set /dev/pts/1
19245^done
19246(@value{GDBP})
19247-inferior-tty-show
19248^done,inferior_tty_terminal="/dev/pts/1"
19249(@value{GDBP})
19250@end smallexample
19251
922fbb7b
AC
19252@ignore
19253@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19254@node GDB/MI Kod Commands
19255@section @sc{gdb/mi} Kod Commands
19256
19257The Kod commands are not implemented.
19258
19259@c @subheading -kod-info
19260
19261@c @subheading -kod-list
19262
19263@c @subheading -kod-list-object-types
19264
19265@c @subheading -kod-show
19266
19267@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19268@node GDB/MI Memory Overlay Commands
19269@section @sc{gdb/mi} Memory Overlay Commands
19270
19271The memory overlay commands are not implemented.
19272
19273@c @subheading -overlay-auto
19274
19275@c @subheading -overlay-list-mapping-state
19276
19277@c @subheading -overlay-list-overlays
19278
19279@c @subheading -overlay-map
19280
19281@c @subheading -overlay-off
19282
19283@c @subheading -overlay-on
19284
19285@c @subheading -overlay-unmap
19286
19287@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19288@node GDB/MI Signal Handling Commands
19289@section @sc{gdb/mi} Signal Handling Commands
19290
19291Signal handling commands are not implemented.
19292
19293@c @subheading -signal-handle
19294
19295@c @subheading -signal-list-handle-actions
19296
19297@c @subheading -signal-list-signal-types
19298@end ignore
19299
19300
19301@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19302@node GDB/MI Stack Manipulation
19303@section @sc{gdb/mi} Stack Manipulation Commands
19304
dcaaae04
NR
19305
19306@subheading The @code{-stack-info-frame} Command
19307@findex -stack-info-frame
19308
19309@subsubheading Synopsis
19310
19311@smallexample
19312 -stack-info-frame
19313@end smallexample
19314
19315Get info on the selected frame.
19316
19317@subsubheading @value{GDBN} Command
19318
19319The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
19320(without arguments).
19321
19322@subsubheading Example
19323
19324@smallexample
19325(@value{GDBP})
19326-stack-info-frame
19327^done,frame=@{level="1",addr="0x0001076c",func="callee3",
19328file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19329fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
19330(@value{GDBP})
19331@end smallexample
19332
922fbb7b
AC
19333@subheading The @code{-stack-info-depth} Command
19334@findex -stack-info-depth
19335
19336@subsubheading Synopsis
19337
19338@smallexample
19339 -stack-info-depth [ @var{max-depth} ]
19340@end smallexample
19341
19342Return the depth of the stack. If the integer argument @var{max-depth}
19343is specified, do not count beyond @var{max-depth} frames.
19344
19345@subsubheading @value{GDBN} Command
19346
19347There's no equivalent @value{GDBN} command.
19348
19349@subsubheading Example
19350
19351For a stack with frame levels 0 through 11:
19352
19353@smallexample
19354(@value{GDBP})
19355-stack-info-depth
19356^done,depth="12"
19357(@value{GDBP})
19358-stack-info-depth 4
19359^done,depth="4"
19360(@value{GDBP})
19361-stack-info-depth 12
19362^done,depth="12"
19363(@value{GDBP})
19364-stack-info-depth 11
19365^done,depth="11"
19366(@value{GDBP})
19367-stack-info-depth 13
19368^done,depth="12"
19369(@value{GDBP})
19370@end smallexample
19371
19372@subheading The @code{-stack-list-arguments} Command
19373@findex -stack-list-arguments
19374
19375@subsubheading Synopsis
19376
19377@smallexample
19378 -stack-list-arguments @var{show-values}
19379 [ @var{low-frame} @var{high-frame} ]
19380@end smallexample
19381
19382Display a list of the arguments for the frames between @var{low-frame}
19383and @var{high-frame} (inclusive). If @var{low-frame} and
19384@var{high-frame} are not provided, list the arguments for the whole call
19385stack.
19386
19387The @var{show-values} argument must have a value of 0 or 1. A value of
193880 means that only the names of the arguments are listed, a value of 1
19389means that both names and values of the arguments are printed.
19390
19391@subsubheading @value{GDBN} Command
19392
19393@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
19394@samp{gdb_get_args} command which partially overlaps with the
19395functionality of @samp{-stack-list-arguments}.
19396
19397@subsubheading Example
19398
19399@smallexample
19400(@value{GDBP})
19401-stack-list-frames
19402^done,
19403stack=[
19404frame=@{level="0",addr="0x00010734",func="callee4",
76ff342d
DJ
19405file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19406fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
922fbb7b 19407frame=@{level="1",addr="0x0001076c",func="callee3",
76ff342d
DJ
19408file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19409fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
922fbb7b 19410frame=@{level="2",addr="0x0001078c",func="callee2",
76ff342d
DJ
19411file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19412fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
922fbb7b 19413frame=@{level="3",addr="0x000107b4",func="callee1",
76ff342d
DJ
19414file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19415fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
922fbb7b 19416frame=@{level="4",addr="0x000107e0",func="main",
76ff342d
DJ
19417file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19418fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
922fbb7b
AC
19419(@value{GDBP})
19420-stack-list-arguments 0
19421^done,
19422stack-args=[
19423frame=@{level="0",args=[]@},
19424frame=@{level="1",args=[name="strarg"]@},
19425frame=@{level="2",args=[name="intarg",name="strarg"]@},
19426frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
19427frame=@{level="4",args=[]@}]
19428(@value{GDBP})
19429-stack-list-arguments 1
19430^done,
19431stack-args=[
19432frame=@{level="0",args=[]@},
19433frame=@{level="1",
19434 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19435frame=@{level="2",args=[
19436@{name="intarg",value="2"@},
19437@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19438@{frame=@{level="3",args=[
19439@{name="intarg",value="2"@},
19440@{name="strarg",value="0x11940 \"A string argument.\""@},
19441@{name="fltarg",value="3.5"@}]@},
19442frame=@{level="4",args=[]@}]
19443(@value{GDBP})
19444-stack-list-arguments 0 2 2
19445^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
19446(@value{GDBP})
19447-stack-list-arguments 1 2 2
19448^done,stack-args=[frame=@{level="2",
19449args=[@{name="intarg",value="2"@},
19450@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
19451(@value{GDBP})
19452@end smallexample
19453
19454@c @subheading -stack-list-exception-handlers
19455
19456
19457@subheading The @code{-stack-list-frames} Command
19458@findex -stack-list-frames
19459
19460@subsubheading Synopsis
19461
19462@smallexample
19463 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
19464@end smallexample
19465
19466List the frames currently on the stack. For each frame it displays the
19467following info:
19468
19469@table @samp
19470@item @var{level}
19471The frame number, 0 being the topmost frame, i.e. the innermost function.
19472@item @var{addr}
19473The @code{$pc} value for that frame.
19474@item @var{func}
19475Function name.
19476@item @var{file}
19477File name of the source file where the function lives.
19478@item @var{line}
19479Line number corresponding to the @code{$pc}.
19480@end table
19481
19482If invoked without arguments, this command prints a backtrace for the
19483whole stack. If given two integer arguments, it shows the frames whose
19484levels are between the two arguments (inclusive). If the two arguments
19485are equal, it shows the single frame at the corresponding level.
19486
19487@subsubheading @value{GDBN} Command
19488
19489The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
19490
19491@subsubheading Example
19492
19493Full stack backtrace:
19494
19495@smallexample
19496(@value{GDBP})
19497-stack-list-frames
19498^done,stack=
19499[frame=@{level="0",addr="0x0001076c",func="foo",
76ff342d 19500 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@},
922fbb7b 19501frame=@{level="1",addr="0x000107a4",func="foo",
76ff342d 19502 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19503frame=@{level="2",addr="0x000107a4",func="foo",
76ff342d 19504 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19505frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19506 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19507frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19508 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19509frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19510 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19511frame=@{level="6",addr="0x000107a4",func="foo",
76ff342d 19512 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19513frame=@{level="7",addr="0x000107a4",func="foo",
76ff342d 19514 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19515frame=@{level="8",addr="0x000107a4",func="foo",
76ff342d 19516 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19517frame=@{level="9",addr="0x000107a4",func="foo",
76ff342d 19518 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19519frame=@{level="10",addr="0x000107a4",func="foo",
76ff342d 19520 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19521frame=@{level="11",addr="0x00010738",func="main",
76ff342d 19522 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}]
922fbb7b
AC
19523(@value{GDBP})
19524@end smallexample
19525
19526Show frames between @var{low_frame} and @var{high_frame}:
19527
19528@smallexample
19529(@value{GDBP})
19530-stack-list-frames 3 5
19531^done,stack=
19532[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19533 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19534frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19535 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19536frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19537 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19538(@value{GDBP})
19539@end smallexample
19540
19541Show a single frame:
19542
19543@smallexample
19544(@value{GDBP})
19545-stack-list-frames 3 3
19546^done,stack=
19547[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19548 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19549(@value{GDBP})
19550@end smallexample
19551
19552
19553@subheading The @code{-stack-list-locals} Command
19554@findex -stack-list-locals
19555
19556@subsubheading Synopsis
19557
19558@smallexample
19559 -stack-list-locals @var{print-values}
19560@end smallexample
19561
19562Display the local variable names for the current frame. With an
bc8ced35
NR
19563argument of 0 or @code{--no-values}, prints only the names of the variables.
19564With argument of 1 or @code{--all-values}, prints also their values. With
19565argument of 2 or @code{--simple-values}, prints the name, type and value for
19566simple data types and the name and type for arrays, structures and
19567unions. In this last case, the idea is that the user can see the
19568value of simple data types immediately and he can create variable
19569objects for other data types if he wishes to explore their values in
19570more detail.
922fbb7b
AC
19571
19572@subsubheading @value{GDBN} Command
19573
19574@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
19575
19576@subsubheading Example
19577
19578@smallexample
19579(@value{GDBP})
19580-stack-list-locals 0
19581^done,locals=[name="A",name="B",name="C"]
19582(@value{GDBP})
bc8ced35 19583-stack-list-locals --all-values
922fbb7b 19584^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
bc8ced35
NR
19585 @{name="C",value="@{1, 2, 3@}"@}]
19586-stack-list-locals --simple-values
19587^done,locals=[@{name="A",type="int",value="1"@},
19588 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
922fbb7b
AC
19589(@value{GDBP})
19590@end smallexample
19591
19592
19593@subheading The @code{-stack-select-frame} Command
19594@findex -stack-select-frame
19595
19596@subsubheading Synopsis
19597
19598@smallexample
19599 -stack-select-frame @var{framenum}
19600@end smallexample
19601
19602Change the current frame. Select a different frame @var{framenum} on
19603the stack.
19604
19605@subsubheading @value{GDBN} Command
19606
19607The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
19608@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
19609
19610@subsubheading Example
19611
19612@smallexample
19613(@value{GDBP})
19614-stack-select-frame 2
19615^done
19616(@value{GDBP})
19617@end smallexample
19618
19619@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19620@node GDB/MI Symbol Query
19621@section @sc{gdb/mi} Symbol Query Commands
19622
19623
19624@subheading The @code{-symbol-info-address} Command
19625@findex -symbol-info-address
19626
19627@subsubheading Synopsis
19628
19629@smallexample
19630 -symbol-info-address @var{symbol}
19631@end smallexample
19632
19633Describe where @var{symbol} is stored.
19634
19635@subsubheading @value{GDBN} Command
19636
19637The corresponding @value{GDBN} command is @samp{info address}.
19638
19639@subsubheading Example
19640N.A.
19641
19642
19643@subheading The @code{-symbol-info-file} Command
19644@findex -symbol-info-file
19645
19646@subsubheading Synopsis
19647
19648@smallexample
19649 -symbol-info-file
19650@end smallexample
19651
19652Show the file for the symbol.
19653
19654@subsubheading @value{GDBN} Command
19655
19656There's no equivalent @value{GDBN} command. @code{gdbtk} has
19657@samp{gdb_find_file}.
19658
19659@subsubheading Example
19660N.A.
19661
19662
19663@subheading The @code{-symbol-info-function} Command
19664@findex -symbol-info-function
19665
19666@subsubheading Synopsis
19667
19668@smallexample
19669 -symbol-info-function
19670@end smallexample
19671
19672Show which function the symbol lives in.
19673
19674@subsubheading @value{GDBN} Command
19675
19676@samp{gdb_get_function} in @code{gdbtk}.
19677
19678@subsubheading Example
19679N.A.
19680
19681
19682@subheading The @code{-symbol-info-line} Command
19683@findex -symbol-info-line
19684
19685@subsubheading Synopsis
19686
19687@smallexample
19688 -symbol-info-line
19689@end smallexample
19690
19691Show the core addresses of the code for a source line.
19692
19693@subsubheading @value{GDBN} Command
19694
71952f4c 19695The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
19696@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
19697
19698@subsubheading Example
19699N.A.
19700
19701
19702@subheading The @code{-symbol-info-symbol} Command
19703@findex -symbol-info-symbol
19704
19705@subsubheading Synopsis
19706
19707@smallexample
19708 -symbol-info-symbol @var{addr}
19709@end smallexample
19710
19711Describe what symbol is at location @var{addr}.
19712
19713@subsubheading @value{GDBN} Command
19714
19715The corresponding @value{GDBN} command is @samp{info symbol}.
19716
19717@subsubheading Example
19718N.A.
19719
19720
19721@subheading The @code{-symbol-list-functions} Command
19722@findex -symbol-list-functions
19723
19724@subsubheading Synopsis
19725
19726@smallexample
19727 -symbol-list-functions
19728@end smallexample
19729
19730List the functions in the executable.
19731
19732@subsubheading @value{GDBN} Command
19733
19734@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
19735@samp{gdb_search} in @code{gdbtk}.
19736
19737@subsubheading Example
19738N.A.
19739
19740
32e7087d
JB
19741@subheading The @code{-symbol-list-lines} Command
19742@findex -symbol-list-lines
19743
19744@subsubheading Synopsis
19745
19746@smallexample
19747 -symbol-list-lines @var{filename}
19748@end smallexample
19749
19750Print the list of lines that contain code and their associated program
19751addresses for the given source filename. The entries are sorted in
19752ascending PC order.
19753
19754@subsubheading @value{GDBN} Command
19755
19756There is no corresponding @value{GDBN} command.
19757
19758@subsubheading Example
19759@smallexample
19760(@value{GDBP})
19761-symbol-list-lines basics.c
54ff5908 19762^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
19763(@value{GDBP})
19764@end smallexample
19765
19766
922fbb7b
AC
19767@subheading The @code{-symbol-list-types} Command
19768@findex -symbol-list-types
19769
19770@subsubheading Synopsis
19771
19772@smallexample
19773 -symbol-list-types
19774@end smallexample
19775
19776List all the type names.
19777
19778@subsubheading @value{GDBN} Command
19779
19780The corresponding commands are @samp{info types} in @value{GDBN},
19781@samp{gdb_search} in @code{gdbtk}.
19782
19783@subsubheading Example
19784N.A.
19785
19786
19787@subheading The @code{-symbol-list-variables} Command
19788@findex -symbol-list-variables
19789
19790@subsubheading Synopsis
19791
19792@smallexample
19793 -symbol-list-variables
19794@end smallexample
19795
19796List all the global and static variable names.
19797
19798@subsubheading @value{GDBN} Command
19799
19800@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
19801
19802@subsubheading Example
19803N.A.
19804
19805
19806@subheading The @code{-symbol-locate} Command
19807@findex -symbol-locate
19808
19809@subsubheading Synopsis
19810
19811@smallexample
19812 -symbol-locate
19813@end smallexample
19814
19815@subsubheading @value{GDBN} Command
19816
19817@samp{gdb_loc} in @code{gdbtk}.
19818
19819@subsubheading Example
19820N.A.
19821
19822
19823@subheading The @code{-symbol-type} Command
19824@findex -symbol-type
19825
19826@subsubheading Synopsis
19827
19828@smallexample
19829 -symbol-type @var{variable}
19830@end smallexample
19831
19832Show type of @var{variable}.
19833
19834@subsubheading @value{GDBN} Command
19835
19836The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
19837@samp{gdb_obj_variable}.
19838
19839@subsubheading Example
19840N.A.
19841
19842
19843@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19844@node GDB/MI Target Manipulation
19845@section @sc{gdb/mi} Target Manipulation Commands
19846
19847
19848@subheading The @code{-target-attach} Command
19849@findex -target-attach
19850
19851@subsubheading Synopsis
19852
19853@smallexample
19854 -target-attach @var{pid} | @var{file}
19855@end smallexample
19856
19857Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
19858
19859@subsubheading @value{GDBN} command
19860
19861The corresponding @value{GDBN} command is @samp{attach}.
19862
19863@subsubheading Example
19864N.A.
19865
19866
19867@subheading The @code{-target-compare-sections} Command
19868@findex -target-compare-sections
19869
19870@subsubheading Synopsis
19871
19872@smallexample
19873 -target-compare-sections [ @var{section} ]
19874@end smallexample
19875
19876Compare data of section @var{section} on target to the exec file.
19877Without the argument, all sections are compared.
19878
19879@subsubheading @value{GDBN} Command
19880
19881The @value{GDBN} equivalent is @samp{compare-sections}.
19882
19883@subsubheading Example
19884N.A.
19885
19886
19887@subheading The @code{-target-detach} Command
19888@findex -target-detach
19889
19890@subsubheading Synopsis
19891
19892@smallexample
19893 -target-detach
19894@end smallexample
19895
19896Disconnect from the remote target. There's no output.
19897
19898@subsubheading @value{GDBN} command
19899
19900The corresponding @value{GDBN} command is @samp{detach}.
19901
19902@subsubheading Example
19903
19904@smallexample
19905(@value{GDBP})
19906-target-detach
19907^done
19908(@value{GDBP})
19909@end smallexample
19910
19911
07f31aa6
DJ
19912@subheading The @code{-target-disconnect} Command
19913@findex -target-disconnect
19914
19915@subsubheading Synopsis
19916
19917@example
19918 -target-disconnect
19919@end example
19920
19921Disconnect from the remote target. There's no output.
19922
19923@subsubheading @value{GDBN} command
19924
19925The corresponding @value{GDBN} command is @samp{disconnect}.
19926
19927@subsubheading Example
19928
19929@smallexample
19930(@value{GDBP})
19931-target-disconnect
19932^done
19933(@value{GDBP})
19934@end smallexample
19935
19936
922fbb7b
AC
19937@subheading The @code{-target-download} Command
19938@findex -target-download
19939
19940@subsubheading Synopsis
19941
19942@smallexample
19943 -target-download
19944@end smallexample
19945
19946Loads the executable onto the remote target.
19947It prints out an update message every half second, which includes the fields:
19948
19949@table @samp
19950@item section
19951The name of the section.
19952@item section-sent
19953The size of what has been sent so far for that section.
19954@item section-size
19955The size of the section.
19956@item total-sent
19957The total size of what was sent so far (the current and the previous sections).
19958@item total-size
19959The size of the overall executable to download.
19960@end table
19961
19962@noindent
19963Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
19964@sc{gdb/mi} Output Syntax}).
19965
19966In addition, it prints the name and size of the sections, as they are
19967downloaded. These messages include the following fields:
19968
19969@table @samp
19970@item section
19971The name of the section.
19972@item section-size
19973The size of the section.
19974@item total-size
19975The size of the overall executable to download.
19976@end table
19977
19978@noindent
19979At the end, a summary is printed.
19980
19981@subsubheading @value{GDBN} Command
19982
19983The corresponding @value{GDBN} command is @samp{load}.
19984
19985@subsubheading Example
19986
19987Note: each status message appears on a single line. Here the messages
19988have been broken down so that they can fit onto a page.
19989
19990@smallexample
19991(@value{GDBP})
19992-target-download
19993+download,@{section=".text",section-size="6668",total-size="9880"@}
19994+download,@{section=".text",section-sent="512",section-size="6668",
19995total-sent="512",total-size="9880"@}
19996+download,@{section=".text",section-sent="1024",section-size="6668",
19997total-sent="1024",total-size="9880"@}
19998+download,@{section=".text",section-sent="1536",section-size="6668",
19999total-sent="1536",total-size="9880"@}
20000+download,@{section=".text",section-sent="2048",section-size="6668",
20001total-sent="2048",total-size="9880"@}
20002+download,@{section=".text",section-sent="2560",section-size="6668",
20003total-sent="2560",total-size="9880"@}
20004+download,@{section=".text",section-sent="3072",section-size="6668",
20005total-sent="3072",total-size="9880"@}
20006+download,@{section=".text",section-sent="3584",section-size="6668",
20007total-sent="3584",total-size="9880"@}
20008+download,@{section=".text",section-sent="4096",section-size="6668",
20009total-sent="4096",total-size="9880"@}
20010+download,@{section=".text",section-sent="4608",section-size="6668",
20011total-sent="4608",total-size="9880"@}
20012+download,@{section=".text",section-sent="5120",section-size="6668",
20013total-sent="5120",total-size="9880"@}
20014+download,@{section=".text",section-sent="5632",section-size="6668",
20015total-sent="5632",total-size="9880"@}
20016+download,@{section=".text",section-sent="6144",section-size="6668",
20017total-sent="6144",total-size="9880"@}
20018+download,@{section=".text",section-sent="6656",section-size="6668",
20019total-sent="6656",total-size="9880"@}
20020+download,@{section=".init",section-size="28",total-size="9880"@}
20021+download,@{section=".fini",section-size="28",total-size="9880"@}
20022+download,@{section=".data",section-size="3156",total-size="9880"@}
20023+download,@{section=".data",section-sent="512",section-size="3156",
20024total-sent="7236",total-size="9880"@}
20025+download,@{section=".data",section-sent="1024",section-size="3156",
20026total-sent="7748",total-size="9880"@}
20027+download,@{section=".data",section-sent="1536",section-size="3156",
20028total-sent="8260",total-size="9880"@}
20029+download,@{section=".data",section-sent="2048",section-size="3156",
20030total-sent="8772",total-size="9880"@}
20031+download,@{section=".data",section-sent="2560",section-size="3156",
20032total-sent="9284",total-size="9880"@}
20033+download,@{section=".data",section-sent="3072",section-size="3156",
20034total-sent="9796",total-size="9880"@}
20035^done,address="0x10004",load-size="9880",transfer-rate="6586",
20036write-rate="429"
20037(@value{GDBP})
20038@end smallexample
20039
20040
20041@subheading The @code{-target-exec-status} Command
20042@findex -target-exec-status
20043
20044@subsubheading Synopsis
20045
20046@smallexample
20047 -target-exec-status
20048@end smallexample
20049
20050Provide information on the state of the target (whether it is running or
20051not, for instance).
20052
20053@subsubheading @value{GDBN} Command
20054
20055There's no equivalent @value{GDBN} command.
20056
20057@subsubheading Example
20058N.A.
20059
20060
20061@subheading The @code{-target-list-available-targets} Command
20062@findex -target-list-available-targets
20063
20064@subsubheading Synopsis
20065
20066@smallexample
20067 -target-list-available-targets
20068@end smallexample
20069
20070List the possible targets to connect to.
20071
20072@subsubheading @value{GDBN} Command
20073
20074The corresponding @value{GDBN} command is @samp{help target}.
20075
20076@subsubheading Example
20077N.A.
20078
20079
20080@subheading The @code{-target-list-current-targets} Command
20081@findex -target-list-current-targets
20082
20083@subsubheading Synopsis
20084
20085@smallexample
20086 -target-list-current-targets
20087@end smallexample
20088
20089Describe the current target.
20090
20091@subsubheading @value{GDBN} Command
20092
20093The corresponding information is printed by @samp{info file} (among
20094other things).
20095
20096@subsubheading Example
20097N.A.
20098
20099
20100@subheading The @code{-target-list-parameters} Command
20101@findex -target-list-parameters
20102
20103@subsubheading Synopsis
20104
20105@smallexample
20106 -target-list-parameters
20107@end smallexample
20108
20109@c ????
20110
20111@subsubheading @value{GDBN} Command
20112
20113No equivalent.
20114
20115@subsubheading Example
20116N.A.
20117
20118
20119@subheading The @code{-target-select} Command
20120@findex -target-select
20121
20122@subsubheading Synopsis
20123
20124@smallexample
20125 -target-select @var{type} @var{parameters @dots{}}
20126@end smallexample
20127
20128Connect @value{GDBN} to the remote target. This command takes two args:
20129
20130@table @samp
20131@item @var{type}
20132The type of target, for instance @samp{async}, @samp{remote}, etc.
20133@item @var{parameters}
20134Device names, host names and the like. @xref{Target Commands, ,
20135Commands for managing targets}, for more details.
20136@end table
20137
20138The output is a connection notification, followed by the address at
20139which the target program is, in the following form:
20140
20141@smallexample
20142^connected,addr="@var{address}",func="@var{function name}",
20143 args=[@var{arg list}]
20144@end smallexample
20145
20146@subsubheading @value{GDBN} Command
20147
20148The corresponding @value{GDBN} command is @samp{target}.
20149
20150@subsubheading Example
20151
20152@smallexample
20153(@value{GDBP})
20154-target-select async /dev/ttya
20155^connected,addr="0xfe00a300",func="??",args=[]
20156(@value{GDBP})
20157@end smallexample
20158
20159@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20160@node GDB/MI Thread Commands
20161@section @sc{gdb/mi} Thread Commands
20162
20163
20164@subheading The @code{-thread-info} Command
20165@findex -thread-info
20166
20167@subsubheading Synopsis
20168
20169@smallexample
20170 -thread-info
20171@end smallexample
20172
20173@subsubheading @value{GDBN} command
20174
20175No equivalent.
20176
20177@subsubheading Example
20178N.A.
20179
20180
20181@subheading The @code{-thread-list-all-threads} Command
20182@findex -thread-list-all-threads
20183
20184@subsubheading Synopsis
20185
20186@smallexample
20187 -thread-list-all-threads
20188@end smallexample
20189
20190@subsubheading @value{GDBN} Command
20191
20192The equivalent @value{GDBN} command is @samp{info threads}.
20193
20194@subsubheading Example
20195N.A.
20196
20197
20198@subheading The @code{-thread-list-ids} Command
20199@findex -thread-list-ids
20200
20201@subsubheading Synopsis
20202
20203@smallexample
20204 -thread-list-ids
20205@end smallexample
20206
20207Produces a list of the currently known @value{GDBN} thread ids. At the
20208end of the list it also prints the total number of such threads.
20209
20210@subsubheading @value{GDBN} Command
20211
20212Part of @samp{info threads} supplies the same information.
20213
20214@subsubheading Example
20215
20216No threads present, besides the main process:
20217
20218@smallexample
20219(@value{GDBP})
20220-thread-list-ids
20221^done,thread-ids=@{@},number-of-threads="0"
20222(@value{GDBP})
20223@end smallexample
20224
20225
20226Several threads:
20227
20228@smallexample
20229(@value{GDBP})
20230-thread-list-ids
20231^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20232number-of-threads="3"
20233(@value{GDBP})
20234@end smallexample
20235
20236
20237@subheading The @code{-thread-select} Command
20238@findex -thread-select
20239
20240@subsubheading Synopsis
20241
20242@smallexample
20243 -thread-select @var{threadnum}
20244@end smallexample
20245
20246Make @var{threadnum} the current thread. It prints the number of the new
20247current thread, and the topmost frame for that thread.
20248
20249@subsubheading @value{GDBN} Command
20250
20251The corresponding @value{GDBN} command is @samp{thread}.
20252
20253@subsubheading Example
20254
20255@smallexample
20256(@value{GDBP})
20257-exec-next
20258^running
20259(@value{GDBP})
20260*stopped,reason="end-stepping-range",thread-id="2",line="187",
20261file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
20262(@value{GDBP})
20263-thread-list-ids
20264^done,
20265thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20266number-of-threads="3"
20267(@value{GDBP})
20268-thread-select 3
20269^done,new-thread-id="3",
20270frame=@{level="0",func="vprintf",
20271args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
20272@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
20273(@value{GDBP})
20274@end smallexample
20275
20276@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20277@node GDB/MI Tracepoint Commands
20278@section @sc{gdb/mi} Tracepoint Commands
20279
20280The tracepoint commands are not yet implemented.
20281
20282@c @subheading -trace-actions
20283
20284@c @subheading -trace-delete
20285
20286@c @subheading -trace-disable
20287
20288@c @subheading -trace-dump
20289
20290@c @subheading -trace-enable
20291
20292@c @subheading -trace-exists
20293
20294@c @subheading -trace-find
20295
20296@c @subheading -trace-frame-number
20297
20298@c @subheading -trace-info
20299
20300@c @subheading -trace-insert
20301
20302@c @subheading -trace-list
20303
20304@c @subheading -trace-pass-count
20305
20306@c @subheading -trace-save
20307
20308@c @subheading -trace-start
20309
20310@c @subheading -trace-stop
20311
20312
20313@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20314@node GDB/MI Variable Objects
20315@section @sc{gdb/mi} Variable Objects
20316
20317
20318@subheading Motivation for Variable Objects in @sc{gdb/mi}
20319
20320For the implementation of a variable debugger window (locals, watched
20321expressions, etc.), we are proposing the adaptation of the existing code
20322used by @code{Insight}.
20323
20324The two main reasons for that are:
20325
20326@enumerate 1
20327@item
20328It has been proven in practice (it is already on its second generation).
20329
20330@item
20331It will shorten development time (needless to say how important it is
20332now).
20333@end enumerate
20334
20335The original interface was designed to be used by Tcl code, so it was
20336slightly changed so it could be used through @sc{gdb/mi}. This section
20337describes the @sc{gdb/mi} operations that will be available and gives some
20338hints about their use.
20339
20340@emph{Note}: In addition to the set of operations described here, we
20341expect the @sc{gui} implementation of a variable window to require, at
20342least, the following operations:
20343
20344@itemize @bullet
20345@item @code{-gdb-show} @code{output-radix}
20346@item @code{-stack-list-arguments}
20347@item @code{-stack-list-locals}
20348@item @code{-stack-select-frame}
20349@end itemize
20350
20351@subheading Introduction to Variable Objects in @sc{gdb/mi}
20352
20353@cindex variable objects in @sc{gdb/mi}
20354The basic idea behind variable objects is the creation of a named object
20355to represent a variable, an expression, a memory location or even a CPU
20356register. For each object created, a set of operations is available for
20357examining or changing its properties.
20358
20359Furthermore, complex data types, such as C structures, are represented
20360in a tree format. For instance, the @code{struct} type variable is the
20361root and the children will represent the struct members. If a child
20362is itself of a complex type, it will also have children of its own.
20363Appropriate language differences are handled for C, C@t{++} and Java.
20364
20365When returning the actual values of the objects, this facility allows
20366for the individual selection of the display format used in the result
20367creation. It can be chosen among: binary, decimal, hexadecimal, octal
20368and natural. Natural refers to a default format automatically
20369chosen based on the variable type (like decimal for an @code{int}, hex
20370for pointers, etc.).
20371
20372The following is the complete set of @sc{gdb/mi} operations defined to
20373access this functionality:
20374
20375@multitable @columnfractions .4 .6
20376@item @strong{Operation}
20377@tab @strong{Description}
20378
20379@item @code{-var-create}
20380@tab create a variable object
20381@item @code{-var-delete}
20382@tab delete the variable object and its children
20383@item @code{-var-set-format}
20384@tab set the display format of this variable
20385@item @code{-var-show-format}
20386@tab show the display format of this variable
20387@item @code{-var-info-num-children}
20388@tab tells how many children this object has
20389@item @code{-var-list-children}
20390@tab return a list of the object's children
20391@item @code{-var-info-type}
20392@tab show the type of this variable object
20393@item @code{-var-info-expression}
20394@tab print what this variable object represents
20395@item @code{-var-show-attributes}
20396@tab is this variable editable? does it exist here?
20397@item @code{-var-evaluate-expression}
20398@tab get the value of this variable
20399@item @code{-var-assign}
20400@tab set the value of this variable
20401@item @code{-var-update}
20402@tab update the variable and its children
20403@end multitable
20404
20405In the next subsection we describe each operation in detail and suggest
20406how it can be used.
20407
20408@subheading Description And Use of Operations on Variable Objects
20409
20410@subheading The @code{-var-create} Command
20411@findex -var-create
20412
20413@subsubheading Synopsis
20414
20415@smallexample
20416 -var-create @{@var{name} | "-"@}
20417 @{@var{frame-addr} | "*"@} @var{expression}
20418@end smallexample
20419
20420This operation creates a variable object, which allows the monitoring of
20421a variable, the result of an expression, a memory cell or a CPU
20422register.
20423
20424The @var{name} parameter is the string by which the object can be
20425referenced. It must be unique. If @samp{-} is specified, the varobj
20426system will generate a string ``varNNNNNN'' automatically. It will be
20427unique provided that one does not specify @var{name} on that format.
20428The command fails if a duplicate name is found.
20429
20430The frame under which the expression should be evaluated can be
20431specified by @var{frame-addr}. A @samp{*} indicates that the current
20432frame should be used.
20433
20434@var{expression} is any expression valid on the current language set (must not
20435begin with a @samp{*}), or one of the following:
20436
20437@itemize @bullet
20438@item
20439@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
20440
20441@item
20442@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
20443
20444@item
20445@samp{$@var{regname}} --- a CPU register name
20446@end itemize
20447
20448@subsubheading Result
20449
20450This operation returns the name, number of children and the type of the
20451object created. Type is returned as a string as the ones generated by
20452the @value{GDBN} CLI:
20453
20454@smallexample
20455 name="@var{name}",numchild="N",type="@var{type}"
20456@end smallexample
20457
20458
20459@subheading The @code{-var-delete} Command
20460@findex -var-delete
20461
20462@subsubheading Synopsis
20463
20464@smallexample
20465 -var-delete @var{name}
20466@end smallexample
20467
20468Deletes a previously created variable object and all of its children.
20469
20470Returns an error if the object @var{name} is not found.
20471
20472
20473@subheading The @code{-var-set-format} Command
20474@findex -var-set-format
20475
20476@subsubheading Synopsis
20477
20478@smallexample
20479 -var-set-format @var{name} @var{format-spec}
20480@end smallexample
20481
20482Sets the output format for the value of the object @var{name} to be
20483@var{format-spec}.
20484
20485The syntax for the @var{format-spec} is as follows:
20486
20487@smallexample
20488 @var{format-spec} @expansion{}
20489 @{binary | decimal | hexadecimal | octal | natural@}
20490@end smallexample
20491
20492
20493@subheading The @code{-var-show-format} Command
20494@findex -var-show-format
20495
20496@subsubheading Synopsis
20497
20498@smallexample
20499 -var-show-format @var{name}
20500@end smallexample
20501
20502Returns the format used to display the value of the object @var{name}.
20503
20504@smallexample
20505 @var{format} @expansion{}
20506 @var{format-spec}
20507@end smallexample
20508
20509
20510@subheading The @code{-var-info-num-children} Command
20511@findex -var-info-num-children
20512
20513@subsubheading Synopsis
20514
20515@smallexample
20516 -var-info-num-children @var{name}
20517@end smallexample
20518
20519Returns the number of children of a variable object @var{name}:
20520
20521@smallexample
20522 numchild=@var{n}
20523@end smallexample
20524
20525
20526@subheading The @code{-var-list-children} Command
20527@findex -var-list-children
20528
20529@subsubheading Synopsis
20530
20531@smallexample
bc8ced35 20532 -var-list-children [@var{print-values}] @var{name}
922fbb7b
AC
20533@end smallexample
20534
bc8ced35
NR
20535Returns a list of the children of the specified variable object. With
20536just the variable object name as an argument or with an optional
20537preceding argument of 0 or @code{--no-values}, prints only the names of the
20538variables. With an optional preceding argument of 1 or @code{--all-values},
20539also prints their values.
20540
20541@subsubheading Example
922fbb7b
AC
20542
20543@smallexample
bc8ced35
NR
20544(@value{GDBP})
20545 -var-list-children n
922fbb7b
AC
20546 numchild=@var{n},children=[@{name=@var{name},
20547 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
bc8ced35
NR
20548(@value{GDBP})
20549 -var-list-children --all-values n
20550 numchild=@var{n},children=[@{name=@var{name},
20551 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
20552@end smallexample
20553
20554
20555@subheading The @code{-var-info-type} Command
20556@findex -var-info-type
20557
20558@subsubheading Synopsis
20559
20560@smallexample
20561 -var-info-type @var{name}
20562@end smallexample
20563
20564Returns the type of the specified variable @var{name}. The type is
20565returned as a string in the same format as it is output by the
20566@value{GDBN} CLI:
20567
20568@smallexample
20569 type=@var{typename}
20570@end smallexample
20571
20572
20573@subheading The @code{-var-info-expression} Command
20574@findex -var-info-expression
20575
20576@subsubheading Synopsis
20577
20578@smallexample
20579 -var-info-expression @var{name}
20580@end smallexample
20581
20582Returns what is represented by the variable object @var{name}:
20583
20584@smallexample
20585 lang=@var{lang-spec},exp=@var{expression}
20586@end smallexample
20587
20588@noindent
20589where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
20590
20591@subheading The @code{-var-show-attributes} Command
20592@findex -var-show-attributes
20593
20594@subsubheading Synopsis
20595
20596@smallexample
20597 -var-show-attributes @var{name}
20598@end smallexample
20599
20600List attributes of the specified variable object @var{name}:
20601
20602@smallexample
20603 status=@var{attr} [ ( ,@var{attr} )* ]
20604@end smallexample
20605
20606@noindent
20607where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
20608
20609@subheading The @code{-var-evaluate-expression} Command
20610@findex -var-evaluate-expression
20611
20612@subsubheading Synopsis
20613
20614@smallexample
20615 -var-evaluate-expression @var{name}
20616@end smallexample
20617
20618Evaluates the expression that is represented by the specified variable
20619object and returns its value as a string in the current format specified
20620for the object:
20621
20622@smallexample
20623 value=@var{value}
20624@end smallexample
20625
20626Note that one must invoke @code{-var-list-children} for a variable
20627before the value of a child variable can be evaluated.
20628
20629@subheading The @code{-var-assign} Command
20630@findex -var-assign
20631
20632@subsubheading Synopsis
20633
20634@smallexample
20635 -var-assign @var{name} @var{expression}
20636@end smallexample
20637
20638Assigns the value of @var{expression} to the variable object specified
20639by @var{name}. The object must be @samp{editable}. If the variable's
b383017d 20640value is altered by the assign, the variable will show up in any
922fbb7b
AC
20641subsequent @code{-var-update} list.
20642
20643@subsubheading Example
20644
20645@smallexample
20646(@value{GDBP})
20647-var-assign var1 3
20648^done,value="3"
20649(@value{GDBP})
20650-var-update *
20651^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
20652(@value{GDBP})
20653@end smallexample
20654
20655@subheading The @code{-var-update} Command
20656@findex -var-update
20657
20658@subsubheading Synopsis
20659
20660@smallexample
20661 -var-update @{@var{name} | "*"@}
20662@end smallexample
20663
20664Update the value of the variable object @var{name} by evaluating its
20665expression after fetching all the new values from memory or registers.
20666A @samp{*} causes all existing variable objects to be updated.
20667
20668
20669@node Annotations
20670@chapter @value{GDBN} Annotations
20671
086432e2
AC
20672This chapter describes annotations in @value{GDBN}. Annotations were
20673designed to interface @value{GDBN} to graphical user interfaces or other
20674similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
20675relatively high level.
20676
086432e2
AC
20677The annotation mechanism has largely been superseeded by @sc{gdb/mi}
20678(@pxref{GDB/MI}).
20679
922fbb7b
AC
20680@ignore
20681This is Edition @value{EDITION}, @value{DATE}.
20682@end ignore
20683
20684@menu
20685* Annotations Overview:: What annotations are; the general syntax.
922fbb7b
AC
20686* Prompting:: Annotations marking @value{GDBN}'s need for input.
20687* Errors:: Annotations for error messages.
922fbb7b
AC
20688* Invalidation:: Some annotations describe things now invalid.
20689* Annotations for Running::
20690 Whether the program is running, how it stopped, etc.
20691* Source Annotations:: Annotations describing source code.
922fbb7b
AC
20692@end menu
20693
20694@node Annotations Overview
20695@section What is an Annotation?
20696@cindex annotations
20697
922fbb7b
AC
20698Annotations start with a newline character, two @samp{control-z}
20699characters, and the name of the annotation. If there is no additional
20700information associated with this annotation, the name of the annotation
20701is followed immediately by a newline. If there is additional
20702information, the name of the annotation is followed by a space, the
20703additional information, and a newline. The additional information
20704cannot contain newline characters.
20705
20706Any output not beginning with a newline and two @samp{control-z}
20707characters denotes literal output from @value{GDBN}. Currently there is
20708no need for @value{GDBN} to output a newline followed by two
20709@samp{control-z} characters, but if there was such a need, the
20710annotations could be extended with an @samp{escape} annotation which
20711means those three characters as output.
20712
086432e2
AC
20713The annotation @var{level}, which is specified using the
20714@option{--annotate} command line option (@pxref{Mode Options}), controls
20715how much information @value{GDBN} prints together with its prompt,
20716values of expressions, source lines, and other types of output. Level 0
20717is for no anntations, level 1 is for use when @value{GDBN} is run as a
20718subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
20719for programs that control @value{GDBN}, and level 2 annotations have
20720been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
20721Interface, annotate, GDB's Obsolete Annotations}).
20722
20723@table @code
20724@kindex set annotate
20725@item set annotate @var{level}
e09f16f9 20726The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 20727annotations to the specified @var{level}.
9c16f35a
EZ
20728
20729@item show annotate
20730@kindex show annotate
20731Show the current annotation level.
09d4efe1
EZ
20732@end table
20733
20734This chapter describes level 3 annotations.
086432e2 20735
922fbb7b
AC
20736A simple example of starting up @value{GDBN} with annotations is:
20737
20738@smallexample
086432e2
AC
20739$ @kbd{gdb --annotate=3}
20740GNU gdb 6.0
20741Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
20742GDB is free software, covered by the GNU General Public License,
20743and you are welcome to change it and/or distribute copies of it
20744under certain conditions.
20745Type "show copying" to see the conditions.
20746There is absolutely no warranty for GDB. Type "show warranty"
20747for details.
086432e2 20748This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
20749
20750^Z^Zpre-prompt
f7dc1244 20751(@value{GDBP})
922fbb7b 20752^Z^Zprompt
086432e2 20753@kbd{quit}
922fbb7b
AC
20754
20755^Z^Zpost-prompt
b383017d 20756$
922fbb7b
AC
20757@end smallexample
20758
20759Here @samp{quit} is input to @value{GDBN}; the rest is output from
20760@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
20761denotes a @samp{control-z} character) are annotations; the rest is
20762output from @value{GDBN}.
20763
922fbb7b
AC
20764@node Prompting
20765@section Annotation for @value{GDBN} Input
20766
20767@cindex annotations for prompts
20768When @value{GDBN} prompts for input, it annotates this fact so it is possible
20769to know when to send output, when the output from a given command is
20770over, etc.
20771
20772Different kinds of input each have a different @dfn{input type}. Each
20773input type has three annotations: a @code{pre-} annotation, which
20774denotes the beginning of any prompt which is being output, a plain
20775annotation, which denotes the end of the prompt, and then a @code{post-}
20776annotation which denotes the end of any echo which may (or may not) be
20777associated with the input. For example, the @code{prompt} input type
20778features the following annotations:
20779
20780@smallexample
20781^Z^Zpre-prompt
20782^Z^Zprompt
20783^Z^Zpost-prompt
20784@end smallexample
20785
20786The input types are
20787
20788@table @code
20789@findex pre-prompt
20790@findex prompt
20791@findex post-prompt
20792@item prompt
20793When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
20794
20795@findex pre-commands
20796@findex commands
20797@findex post-commands
20798@item commands
20799When @value{GDBN} prompts for a set of commands, like in the @code{commands}
20800command. The annotations are repeated for each command which is input.
20801
20802@findex pre-overload-choice
20803@findex overload-choice
20804@findex post-overload-choice
20805@item overload-choice
20806When @value{GDBN} wants the user to select between various overloaded functions.
20807
20808@findex pre-query
20809@findex query
20810@findex post-query
20811@item query
20812When @value{GDBN} wants the user to confirm a potentially dangerous operation.
20813
20814@findex pre-prompt-for-continue
20815@findex prompt-for-continue
20816@findex post-prompt-for-continue
20817@item prompt-for-continue
20818When @value{GDBN} is asking the user to press return to continue. Note: Don't
20819expect this to work well; instead use @code{set height 0} to disable
20820prompting. This is because the counting of lines is buggy in the
20821presence of annotations.
20822@end table
20823
20824@node Errors
20825@section Errors
20826@cindex annotations for errors, warnings and interrupts
20827
20828@findex quit
20829@smallexample
20830^Z^Zquit
20831@end smallexample
20832
20833This annotation occurs right before @value{GDBN} responds to an interrupt.
20834
20835@findex error
20836@smallexample
20837^Z^Zerror
20838@end smallexample
20839
20840This annotation occurs right before @value{GDBN} responds to an error.
20841
20842Quit and error annotations indicate that any annotations which @value{GDBN} was
20843in the middle of may end abruptly. For example, if a
20844@code{value-history-begin} annotation is followed by a @code{error}, one
20845cannot expect to receive the matching @code{value-history-end}. One
20846cannot expect not to receive it either, however; an error annotation
20847does not necessarily mean that @value{GDBN} is immediately returning all the way
20848to the top level.
20849
20850@findex error-begin
20851A quit or error annotation may be preceded by
20852
20853@smallexample
20854^Z^Zerror-begin
20855@end smallexample
20856
20857Any output between that and the quit or error annotation is the error
20858message.
20859
20860Warning messages are not yet annotated.
20861@c If we want to change that, need to fix warning(), type_error(),
20862@c range_error(), and possibly other places.
20863
922fbb7b
AC
20864@node Invalidation
20865@section Invalidation Notices
20866
20867@cindex annotations for invalidation messages
20868The following annotations say that certain pieces of state may have
20869changed.
20870
20871@table @code
20872@findex frames-invalid
20873@item ^Z^Zframes-invalid
20874
20875The frames (for example, output from the @code{backtrace} command) may
20876have changed.
20877
20878@findex breakpoints-invalid
20879@item ^Z^Zbreakpoints-invalid
20880
20881The breakpoints may have changed. For example, the user just added or
20882deleted a breakpoint.
20883@end table
20884
20885@node Annotations for Running
20886@section Running the Program
20887@cindex annotations for running programs
20888
20889@findex starting
20890@findex stopping
20891When the program starts executing due to a @value{GDBN} command such as
b383017d 20892@code{step} or @code{continue},
922fbb7b
AC
20893
20894@smallexample
20895^Z^Zstarting
20896@end smallexample
20897
b383017d 20898is output. When the program stops,
922fbb7b
AC
20899
20900@smallexample
20901^Z^Zstopped
20902@end smallexample
20903
20904is output. Before the @code{stopped} annotation, a variety of
20905annotations describe how the program stopped.
20906
20907@table @code
20908@findex exited
20909@item ^Z^Zexited @var{exit-status}
20910The program exited, and @var{exit-status} is the exit status (zero for
20911successful exit, otherwise nonzero).
20912
20913@findex signalled
20914@findex signal-name
20915@findex signal-name-end
20916@findex signal-string
20917@findex signal-string-end
20918@item ^Z^Zsignalled
20919The program exited with a signal. After the @code{^Z^Zsignalled}, the
20920annotation continues:
20921
20922@smallexample
20923@var{intro-text}
20924^Z^Zsignal-name
20925@var{name}
20926^Z^Zsignal-name-end
20927@var{middle-text}
20928^Z^Zsignal-string
20929@var{string}
20930^Z^Zsignal-string-end
20931@var{end-text}
20932@end smallexample
20933
20934@noindent
20935where @var{name} is the name of the signal, such as @code{SIGILL} or
20936@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
20937as @code{Illegal Instruction} or @code{Segmentation fault}.
20938@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
20939user's benefit and have no particular format.
20940
20941@findex signal
20942@item ^Z^Zsignal
20943The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
20944just saying that the program received the signal, not that it was
20945terminated with it.
20946
20947@findex breakpoint
20948@item ^Z^Zbreakpoint @var{number}
20949The program hit breakpoint number @var{number}.
20950
20951@findex watchpoint
20952@item ^Z^Zwatchpoint @var{number}
20953The program hit watchpoint number @var{number}.
20954@end table
20955
20956@node Source Annotations
20957@section Displaying Source
20958@cindex annotations for source display
20959
20960@findex source
20961The following annotation is used instead of displaying source code:
20962
20963@smallexample
20964^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
20965@end smallexample
20966
20967where @var{filename} is an absolute file name indicating which source
20968file, @var{line} is the line number within that file (where 1 is the
20969first line in the file), @var{character} is the character position
20970within the file (where 0 is the first character in the file) (for most
20971debug formats this will necessarily point to the beginning of a line),
20972@var{middle} is @samp{middle} if @var{addr} is in the middle of the
20973line, or @samp{beg} if @var{addr} is at the beginning of the line, and
20974@var{addr} is the address in the target program associated with the
20975source which is being displayed. @var{addr} is in the form @samp{0x}
20976followed by one or more lowercase hex digits (note that this does not
20977depend on the language).
20978
8e04817f
AC
20979@node GDB Bugs
20980@chapter Reporting Bugs in @value{GDBN}
20981@cindex bugs in @value{GDBN}
20982@cindex reporting bugs in @value{GDBN}
c906108c 20983
8e04817f 20984Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 20985
8e04817f
AC
20986Reporting a bug may help you by bringing a solution to your problem, or it
20987may not. But in any case the principal function of a bug report is to help
20988the entire community by making the next version of @value{GDBN} work better. Bug
20989reports are your contribution to the maintenance of @value{GDBN}.
c906108c 20990
8e04817f
AC
20991In order for a bug report to serve its purpose, you must include the
20992information that enables us to fix the bug.
c4555f82
SC
20993
20994@menu
8e04817f
AC
20995* Bug Criteria:: Have you found a bug?
20996* Bug Reporting:: How to report bugs
c4555f82
SC
20997@end menu
20998
8e04817f
AC
20999@node Bug Criteria
21000@section Have you found a bug?
21001@cindex bug criteria
c4555f82 21002
8e04817f 21003If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
21004
21005@itemize @bullet
8e04817f
AC
21006@cindex fatal signal
21007@cindex debugger crash
21008@cindex crash of debugger
c4555f82 21009@item
8e04817f
AC
21010If the debugger gets a fatal signal, for any input whatever, that is a
21011@value{GDBN} bug. Reliable debuggers never crash.
21012
21013@cindex error on valid input
21014@item
21015If @value{GDBN} produces an error message for valid input, that is a
21016bug. (Note that if you're cross debugging, the problem may also be
21017somewhere in the connection to the target.)
c4555f82 21018
8e04817f 21019@cindex invalid input
c4555f82 21020@item
8e04817f
AC
21021If @value{GDBN} does not produce an error message for invalid input,
21022that is a bug. However, you should note that your idea of
21023``invalid input'' might be our idea of ``an extension'' or ``support
21024for traditional practice''.
21025
21026@item
21027If you are an experienced user of debugging tools, your suggestions
21028for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
21029@end itemize
21030
8e04817f
AC
21031@node Bug Reporting
21032@section How to report bugs
21033@cindex bug reports
21034@cindex @value{GDBN} bugs, reporting
21035
21036A number of companies and individuals offer support for @sc{gnu} products.
21037If you obtained @value{GDBN} from a support organization, we recommend you
21038contact that organization first.
21039
21040You can find contact information for many support companies and
21041individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
21042distribution.
21043@c should add a web page ref...
21044
129188f6
AC
21045In any event, we also recommend that you submit bug reports for
21046@value{GDBN}. The prefered method is to submit them directly using
21047@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
21048page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
21049be used.
8e04817f
AC
21050
21051@strong{Do not send bug reports to @samp{info-gdb}, or to
21052@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
21053not want to receive bug reports. Those that do have arranged to receive
21054@samp{bug-gdb}.
21055
21056The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
21057serves as a repeater. The mailing list and the newsgroup carry exactly
21058the same messages. Often people think of posting bug reports to the
21059newsgroup instead of mailing them. This appears to work, but it has one
21060problem which can be crucial: a newsgroup posting often lacks a mail
21061path back to the sender. Thus, if we need to ask for more information,
21062we may be unable to reach you. For this reason, it is better to send
21063bug reports to the mailing list.
c4555f82 21064
8e04817f
AC
21065The fundamental principle of reporting bugs usefully is this:
21066@strong{report all the facts}. If you are not sure whether to state a
21067fact or leave it out, state it!
c4555f82 21068
8e04817f
AC
21069Often people omit facts because they think they know what causes the
21070problem and assume that some details do not matter. Thus, you might
21071assume that the name of the variable you use in an example does not matter.
21072Well, probably it does not, but one cannot be sure. Perhaps the bug is a
21073stray memory reference which happens to fetch from the location where that
21074name is stored in memory; perhaps, if the name were different, the contents
21075of that location would fool the debugger into doing the right thing despite
21076the bug. Play it safe and give a specific, complete example. That is the
21077easiest thing for you to do, and the most helpful.
c4555f82 21078
8e04817f
AC
21079Keep in mind that the purpose of a bug report is to enable us to fix the
21080bug. It may be that the bug has been reported previously, but neither
21081you nor we can know that unless your bug report is complete and
21082self-contained.
c4555f82 21083
8e04817f
AC
21084Sometimes people give a few sketchy facts and ask, ``Does this ring a
21085bell?'' Those bug reports are useless, and we urge everyone to
21086@emph{refuse to respond to them} except to chide the sender to report
21087bugs properly.
21088
21089To enable us to fix the bug, you should include all these things:
c4555f82
SC
21090
21091@itemize @bullet
21092@item
8e04817f
AC
21093The version of @value{GDBN}. @value{GDBN} announces it if you start
21094with no arguments; you can also print it at any time using @code{show
21095version}.
c4555f82 21096
8e04817f
AC
21097Without this, we will not know whether there is any point in looking for
21098the bug in the current version of @value{GDBN}.
c4555f82
SC
21099
21100@item
8e04817f
AC
21101The type of machine you are using, and the operating system name and
21102version number.
c4555f82
SC
21103
21104@item
8e04817f
AC
21105What compiler (and its version) was used to compile @value{GDBN}---e.g.
21106``@value{GCC}--2.8.1''.
c4555f82
SC
21107
21108@item
8e04817f
AC
21109What compiler (and its version) was used to compile the program you are
21110debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
21111C Compiler''. For GCC, you can say @code{gcc --version} to get this
21112information; for other compilers, see the documentation for those
21113compilers.
c4555f82 21114
8e04817f
AC
21115@item
21116The command arguments you gave the compiler to compile your example and
21117observe the bug. For example, did you use @samp{-O}? To guarantee
21118you will not omit something important, list them all. A copy of the
21119Makefile (or the output from make) is sufficient.
c4555f82 21120
8e04817f
AC
21121If we were to try to guess the arguments, we would probably guess wrong
21122and then we might not encounter the bug.
c4555f82 21123
8e04817f
AC
21124@item
21125A complete input script, and all necessary source files, that will
21126reproduce the bug.
c4555f82 21127
8e04817f
AC
21128@item
21129A description of what behavior you observe that you believe is
21130incorrect. For example, ``It gets a fatal signal.''
c4555f82 21131
8e04817f
AC
21132Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
21133will certainly notice it. But if the bug is incorrect output, we might
21134not notice unless it is glaringly wrong. You might as well not give us
21135a chance to make a mistake.
c4555f82 21136
8e04817f
AC
21137Even if the problem you experience is a fatal signal, you should still
21138say so explicitly. Suppose something strange is going on, such as, your
21139copy of @value{GDBN} is out of synch, or you have encountered a bug in
21140the C library on your system. (This has happened!) Your copy might
21141crash and ours would not. If you told us to expect a crash, then when
21142ours fails to crash, we would know that the bug was not happening for
21143us. If you had not told us to expect a crash, then we would not be able
21144to draw any conclusion from our observations.
c4555f82 21145
e0c07bf0
MC
21146@pindex script
21147@cindex recording a session script
21148To collect all this information, you can use a session recording program
21149such as @command{script}, which is available on many Unix systems.
21150Just run your @value{GDBN} session inside @command{script} and then
21151include the @file{typescript} file with your bug report.
21152
21153Another way to record a @value{GDBN} session is to run @value{GDBN}
21154inside Emacs and then save the entire buffer to a file.
21155
8e04817f
AC
21156@item
21157If you wish to suggest changes to the @value{GDBN} source, send us context
21158diffs. If you even discuss something in the @value{GDBN} source, refer to
21159it by context, not by line number.
c4555f82 21160
8e04817f
AC
21161The line numbers in our development sources will not match those in your
21162sources. Your line numbers would convey no useful information to us.
c4555f82 21163
8e04817f 21164@end itemize
c4555f82 21165
8e04817f 21166Here are some things that are not necessary:
c4555f82 21167
8e04817f
AC
21168@itemize @bullet
21169@item
21170A description of the envelope of the bug.
c4555f82 21171
8e04817f
AC
21172Often people who encounter a bug spend a lot of time investigating
21173which changes to the input file will make the bug go away and which
21174changes will not affect it.
c4555f82 21175
8e04817f
AC
21176This is often time consuming and not very useful, because the way we
21177will find the bug is by running a single example under the debugger
21178with breakpoints, not by pure deduction from a series of examples.
21179We recommend that you save your time for something else.
c4555f82 21180
8e04817f
AC
21181Of course, if you can find a simpler example to report @emph{instead}
21182of the original one, that is a convenience for us. Errors in the
21183output will be easier to spot, running under the debugger will take
21184less time, and so on.
c4555f82 21185
8e04817f
AC
21186However, simplification is not vital; if you do not want to do this,
21187report the bug anyway and send us the entire test case you used.
c4555f82 21188
8e04817f
AC
21189@item
21190A patch for the bug.
c4555f82 21191
8e04817f
AC
21192A patch for the bug does help us if it is a good one. But do not omit
21193the necessary information, such as the test case, on the assumption that
21194a patch is all we need. We might see problems with your patch and decide
21195to fix the problem another way, or we might not understand it at all.
c4555f82 21196
8e04817f
AC
21197Sometimes with a program as complicated as @value{GDBN} it is very hard to
21198construct an example that will make the program follow a certain path
21199through the code. If you do not send us the example, we will not be able
21200to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 21201
8e04817f
AC
21202And if we cannot understand what bug you are trying to fix, or why your
21203patch should be an improvement, we will not install it. A test case will
21204help us to understand.
c4555f82 21205
8e04817f
AC
21206@item
21207A guess about what the bug is or what it depends on.
c4555f82 21208
8e04817f
AC
21209Such guesses are usually wrong. Even we cannot guess right about such
21210things without first using the debugger to find the facts.
21211@end itemize
c4555f82 21212
8e04817f
AC
21213@c The readline documentation is distributed with the readline code
21214@c and consists of the two following files:
21215@c rluser.texinfo
21216@c inc-hist.texinfo
21217@c Use -I with makeinfo to point to the appropriate directory,
21218@c environment var TEXINPUTS with TeX.
21219@include rluser.texinfo
21220@include inc-hist.texinfo
c4555f82 21221
c4555f82 21222
8e04817f
AC
21223@node Formatting Documentation
21224@appendix Formatting Documentation
c4555f82 21225
8e04817f
AC
21226@cindex @value{GDBN} reference card
21227@cindex reference card
21228The @value{GDBN} 4 release includes an already-formatted reference card, ready
21229for printing with PostScript or Ghostscript, in the @file{gdb}
21230subdirectory of the main source directory@footnote{In
21231@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
21232release.}. If you can use PostScript or Ghostscript with your printer,
21233you can print the reference card immediately with @file{refcard.ps}.
c4555f82 21234
8e04817f
AC
21235The release also includes the source for the reference card. You
21236can format it, using @TeX{}, by typing:
c4555f82 21237
474c8240 21238@smallexample
8e04817f 21239make refcard.dvi
474c8240 21240@end smallexample
c4555f82 21241
8e04817f
AC
21242The @value{GDBN} reference card is designed to print in @dfn{landscape}
21243mode on US ``letter'' size paper;
21244that is, on a sheet 11 inches wide by 8.5 inches
21245high. You will need to specify this form of printing as an option to
21246your @sc{dvi} output program.
c4555f82 21247
8e04817f 21248@cindex documentation
c4555f82 21249
8e04817f
AC
21250All the documentation for @value{GDBN} comes as part of the machine-readable
21251distribution. The documentation is written in Texinfo format, which is
21252a documentation system that uses a single source file to produce both
21253on-line information and a printed manual. You can use one of the Info
21254formatting commands to create the on-line version of the documentation
21255and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 21256
8e04817f
AC
21257@value{GDBN} includes an already formatted copy of the on-line Info
21258version of this manual in the @file{gdb} subdirectory. The main Info
21259file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
21260subordinate files matching @samp{gdb.info*} in the same directory. If
21261necessary, you can print out these files, or read them with any editor;
21262but they are easier to read using the @code{info} subsystem in @sc{gnu}
21263Emacs or the standalone @code{info} program, available as part of the
21264@sc{gnu} Texinfo distribution.
c4555f82 21265
8e04817f
AC
21266If you want to format these Info files yourself, you need one of the
21267Info formatting programs, such as @code{texinfo-format-buffer} or
21268@code{makeinfo}.
c4555f82 21269
8e04817f
AC
21270If you have @code{makeinfo} installed, and are in the top level
21271@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
21272version @value{GDBVN}), you can make the Info file by typing:
c4555f82 21273
474c8240 21274@smallexample
8e04817f
AC
21275cd gdb
21276make gdb.info
474c8240 21277@end smallexample
c4555f82 21278
8e04817f
AC
21279If you want to typeset and print copies of this manual, you need @TeX{},
21280a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
21281Texinfo definitions file.
c4555f82 21282
8e04817f
AC
21283@TeX{} is a typesetting program; it does not print files directly, but
21284produces output files called @sc{dvi} files. To print a typeset
21285document, you need a program to print @sc{dvi} files. If your system
21286has @TeX{} installed, chances are it has such a program. The precise
21287command to use depends on your system; @kbd{lpr -d} is common; another
21288(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
21289require a file name without any extension or a @samp{.dvi} extension.
c4555f82 21290
8e04817f
AC
21291@TeX{} also requires a macro definitions file called
21292@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
21293written in Texinfo format. On its own, @TeX{} cannot either read or
21294typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
21295and is located in the @file{gdb-@var{version-number}/texinfo}
21296directory.
c4555f82 21297
8e04817f
AC
21298If you have @TeX{} and a @sc{dvi} printer program installed, you can
21299typeset and print this manual. First switch to the the @file{gdb}
21300subdirectory of the main source directory (for example, to
21301@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 21302
474c8240 21303@smallexample
8e04817f 21304make gdb.dvi
474c8240 21305@end smallexample
c4555f82 21306
8e04817f 21307Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 21308
8e04817f
AC
21309@node Installing GDB
21310@appendix Installing @value{GDBN}
21311@cindex configuring @value{GDBN}
21312@cindex installation
94e91d6d 21313@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 21314
8e04817f
AC
21315@value{GDBN} comes with a @code{configure} script that automates the process
21316of preparing @value{GDBN} for installation; you can then use @code{make} to
21317build the @code{gdb} program.
21318@iftex
21319@c irrelevant in info file; it's as current as the code it lives with.
21320@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
21321look at the @file{README} file in the sources; we may have improved the
21322installation procedures since publishing this manual.}
21323@end iftex
c4555f82 21324
8e04817f
AC
21325The @value{GDBN} distribution includes all the source code you need for
21326@value{GDBN} in a single directory, whose name is usually composed by
21327appending the version number to @samp{gdb}.
c4555f82 21328
8e04817f
AC
21329For example, the @value{GDBN} version @value{GDBVN} distribution is in the
21330@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 21331
8e04817f
AC
21332@table @code
21333@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
21334script for configuring @value{GDBN} and all its supporting libraries
c4555f82 21335
8e04817f
AC
21336@item gdb-@value{GDBVN}/gdb
21337the source specific to @value{GDBN} itself
c4555f82 21338
8e04817f
AC
21339@item gdb-@value{GDBVN}/bfd
21340source for the Binary File Descriptor library
c906108c 21341
8e04817f
AC
21342@item gdb-@value{GDBVN}/include
21343@sc{gnu} include files
c906108c 21344
8e04817f
AC
21345@item gdb-@value{GDBVN}/libiberty
21346source for the @samp{-liberty} free software library
c906108c 21347
8e04817f
AC
21348@item gdb-@value{GDBVN}/opcodes
21349source for the library of opcode tables and disassemblers
c906108c 21350
8e04817f
AC
21351@item gdb-@value{GDBVN}/readline
21352source for the @sc{gnu} command-line interface
c906108c 21353
8e04817f
AC
21354@item gdb-@value{GDBVN}/glob
21355source for the @sc{gnu} filename pattern-matching subroutine
c906108c 21356
8e04817f
AC
21357@item gdb-@value{GDBVN}/mmalloc
21358source for the @sc{gnu} memory-mapped malloc package
21359@end table
c906108c 21360
8e04817f
AC
21361The simplest way to configure and build @value{GDBN} is to run @code{configure}
21362from the @file{gdb-@var{version-number}} source directory, which in
21363this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 21364
8e04817f
AC
21365First switch to the @file{gdb-@var{version-number}} source directory
21366if you are not already in it; then run @code{configure}. Pass the
21367identifier for the platform on which @value{GDBN} will run as an
21368argument.
c906108c 21369
8e04817f 21370For example:
c906108c 21371
474c8240 21372@smallexample
8e04817f
AC
21373cd gdb-@value{GDBVN}
21374./configure @var{host}
21375make
474c8240 21376@end smallexample
c906108c 21377
8e04817f
AC
21378@noindent
21379where @var{host} is an identifier such as @samp{sun4} or
21380@samp{decstation}, that identifies the platform where @value{GDBN} will run.
21381(You can often leave off @var{host}; @code{configure} tries to guess the
21382correct value by examining your system.)
c906108c 21383
8e04817f
AC
21384Running @samp{configure @var{host}} and then running @code{make} builds the
21385@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
21386libraries, then @code{gdb} itself. The configured source files, and the
21387binaries, are left in the corresponding source directories.
c906108c 21388
8e04817f
AC
21389@need 750
21390@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
21391system does not recognize this automatically when you run a different
21392shell, you may need to run @code{sh} on it explicitly:
c906108c 21393
474c8240 21394@smallexample
8e04817f 21395sh configure @var{host}
474c8240 21396@end smallexample
c906108c 21397
8e04817f
AC
21398If you run @code{configure} from a directory that contains source
21399directories for multiple libraries or programs, such as the
21400@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
21401creates configuration files for every directory level underneath (unless
21402you tell it not to, with the @samp{--norecursion} option).
21403
94e91d6d
MC
21404You should run the @code{configure} script from the top directory in the
21405source tree, the @file{gdb-@var{version-number}} directory. If you run
21406@code{configure} from one of the subdirectories, you will configure only
21407that subdirectory. That is usually not what you want. In particular,
21408if you run the first @code{configure} from the @file{gdb} subdirectory
21409of the @file{gdb-@var{version-number}} directory, you will omit the
21410configuration of @file{bfd}, @file{readline}, and other sibling
21411directories of the @file{gdb} subdirectory. This leads to build errors
21412about missing include files such as @file{bfd/bfd.h}.
c906108c 21413
8e04817f
AC
21414You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
21415However, you should make sure that the shell on your path (named by
21416the @samp{SHELL} environment variable) is publicly readable. Remember
21417that @value{GDBN} uses the shell to start your program---some systems refuse to
21418let @value{GDBN} debug child processes whose programs are not readable.
c906108c 21419
8e04817f
AC
21420@menu
21421* Separate Objdir:: Compiling @value{GDBN} in another directory
21422* Config Names:: Specifying names for hosts and targets
21423* Configure Options:: Summary of options for configure
21424@end menu
c906108c 21425
8e04817f
AC
21426@node Separate Objdir
21427@section Compiling @value{GDBN} in another directory
c906108c 21428
8e04817f
AC
21429If you want to run @value{GDBN} versions for several host or target machines,
21430you need a different @code{gdb} compiled for each combination of
21431host and target. @code{configure} is designed to make this easy by
21432allowing you to generate each configuration in a separate subdirectory,
21433rather than in the source directory. If your @code{make} program
21434handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
21435@code{make} in each of these directories builds the @code{gdb}
21436program specified there.
c906108c 21437
8e04817f
AC
21438To build @code{gdb} in a separate directory, run @code{configure}
21439with the @samp{--srcdir} option to specify where to find the source.
21440(You also need to specify a path to find @code{configure}
21441itself from your working directory. If the path to @code{configure}
21442would be the same as the argument to @samp{--srcdir}, you can leave out
21443the @samp{--srcdir} option; it is assumed.)
c906108c 21444
8e04817f
AC
21445For example, with version @value{GDBVN}, you can build @value{GDBN} in a
21446separate directory for a Sun 4 like this:
c906108c 21447
474c8240 21448@smallexample
8e04817f
AC
21449@group
21450cd gdb-@value{GDBVN}
21451mkdir ../gdb-sun4
21452cd ../gdb-sun4
21453../gdb-@value{GDBVN}/configure sun4
21454make
21455@end group
474c8240 21456@end smallexample
c906108c 21457
8e04817f
AC
21458When @code{configure} builds a configuration using a remote source
21459directory, it creates a tree for the binaries with the same structure
21460(and using the same names) as the tree under the source directory. In
21461the example, you'd find the Sun 4 library @file{libiberty.a} in the
21462directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
21463@file{gdb-sun4/gdb}.
c906108c 21464
94e91d6d
MC
21465Make sure that your path to the @file{configure} script has just one
21466instance of @file{gdb} in it. If your path to @file{configure} looks
21467like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
21468one subdirectory of @value{GDBN}, not the whole package. This leads to
21469build errors about missing include files such as @file{bfd/bfd.h}.
21470
8e04817f
AC
21471One popular reason to build several @value{GDBN} configurations in separate
21472directories is to configure @value{GDBN} for cross-compiling (where
21473@value{GDBN} runs on one machine---the @dfn{host}---while debugging
21474programs that run on another machine---the @dfn{target}).
21475You specify a cross-debugging target by
21476giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 21477
8e04817f
AC
21478When you run @code{make} to build a program or library, you must run
21479it in a configured directory---whatever directory you were in when you
21480called @code{configure} (or one of its subdirectories).
c906108c 21481
8e04817f
AC
21482The @code{Makefile} that @code{configure} generates in each source
21483directory also runs recursively. If you type @code{make} in a source
21484directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
21485directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
21486will build all the required libraries, and then build GDB.
c906108c 21487
8e04817f
AC
21488When you have multiple hosts or targets configured in separate
21489directories, you can run @code{make} on them in parallel (for example,
21490if they are NFS-mounted on each of the hosts); they will not interfere
21491with each other.
c906108c 21492
8e04817f
AC
21493@node Config Names
21494@section Specifying names for hosts and targets
c906108c 21495
8e04817f
AC
21496The specifications used for hosts and targets in the @code{configure}
21497script are based on a three-part naming scheme, but some short predefined
21498aliases are also supported. The full naming scheme encodes three pieces
21499of information in the following pattern:
c906108c 21500
474c8240 21501@smallexample
8e04817f 21502@var{architecture}-@var{vendor}-@var{os}
474c8240 21503@end smallexample
c906108c 21504
8e04817f
AC
21505For example, you can use the alias @code{sun4} as a @var{host} argument,
21506or as the value for @var{target} in a @code{--target=@var{target}}
21507option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 21508
8e04817f
AC
21509The @code{configure} script accompanying @value{GDBN} does not provide
21510any query facility to list all supported host and target names or
21511aliases. @code{configure} calls the Bourne shell script
21512@code{config.sub} to map abbreviations to full names; you can read the
21513script, if you wish, or you can use it to test your guesses on
21514abbreviations---for example:
c906108c 21515
8e04817f
AC
21516@smallexample
21517% sh config.sub i386-linux
21518i386-pc-linux-gnu
21519% sh config.sub alpha-linux
21520alpha-unknown-linux-gnu
21521% sh config.sub hp9k700
21522hppa1.1-hp-hpux
21523% sh config.sub sun4
21524sparc-sun-sunos4.1.1
21525% sh config.sub sun3
21526m68k-sun-sunos4.1.1
21527% sh config.sub i986v
21528Invalid configuration `i986v': machine `i986v' not recognized
21529@end smallexample
c906108c 21530
8e04817f
AC
21531@noindent
21532@code{config.sub} is also distributed in the @value{GDBN} source
21533directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 21534
8e04817f
AC
21535@node Configure Options
21536@section @code{configure} options
c906108c 21537
8e04817f
AC
21538Here is a summary of the @code{configure} options and arguments that
21539are most often useful for building @value{GDBN}. @code{configure} also has
21540several other options not listed here. @inforef{What Configure
21541Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 21542
474c8240 21543@smallexample
8e04817f
AC
21544configure @r{[}--help@r{]}
21545 @r{[}--prefix=@var{dir}@r{]}
21546 @r{[}--exec-prefix=@var{dir}@r{]}
21547 @r{[}--srcdir=@var{dirname}@r{]}
21548 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
21549 @r{[}--target=@var{target}@r{]}
21550 @var{host}
474c8240 21551@end smallexample
c906108c 21552
8e04817f
AC
21553@noindent
21554You may introduce options with a single @samp{-} rather than
21555@samp{--} if you prefer; but you may abbreviate option names if you use
21556@samp{--}.
c906108c 21557
8e04817f
AC
21558@table @code
21559@item --help
21560Display a quick summary of how to invoke @code{configure}.
c906108c 21561
8e04817f
AC
21562@item --prefix=@var{dir}
21563Configure the source to install programs and files under directory
21564@file{@var{dir}}.
c906108c 21565
8e04817f
AC
21566@item --exec-prefix=@var{dir}
21567Configure the source to install programs under directory
21568@file{@var{dir}}.
c906108c 21569
8e04817f
AC
21570@c avoid splitting the warning from the explanation:
21571@need 2000
21572@item --srcdir=@var{dirname}
21573@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
21574@code{make} that implements the @code{VPATH} feature.}@*
21575Use this option to make configurations in directories separate from the
21576@value{GDBN} source directories. Among other things, you can use this to
21577build (or maintain) several configurations simultaneously, in separate
21578directories. @code{configure} writes configuration specific files in
21579the current directory, but arranges for them to use the source in the
21580directory @var{dirname}. @code{configure} creates directories under
21581the working directory in parallel to the source directories below
21582@var{dirname}.
c906108c 21583
8e04817f
AC
21584@item --norecursion
21585Configure only the directory level where @code{configure} is executed; do not
21586propagate configuration to subdirectories.
c906108c 21587
8e04817f
AC
21588@item --target=@var{target}
21589Configure @value{GDBN} for cross-debugging programs running on the specified
21590@var{target}. Without this option, @value{GDBN} is configured to debug
21591programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 21592
8e04817f 21593There is no convenient way to generate a list of all available targets.
c906108c 21594
8e04817f
AC
21595@item @var{host} @dots{}
21596Configure @value{GDBN} to run on the specified @var{host}.
c906108c 21597
8e04817f
AC
21598There is no convenient way to generate a list of all available hosts.
21599@end table
c906108c 21600
8e04817f
AC
21601There are many other options available as well, but they are generally
21602needed for special purposes only.
c906108c 21603
8e04817f
AC
21604@node Maintenance Commands
21605@appendix Maintenance Commands
21606@cindex maintenance commands
21607@cindex internal commands
c906108c 21608
8e04817f 21609In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
21610includes a number of commands intended for @value{GDBN} developers,
21611that are not documented elsewhere in this manual. These commands are
da316a69
EZ
21612provided here for reference. (For commands that turn on debugging
21613messages, see @ref{Debugging Output}.)
c906108c 21614
8e04817f 21615@table @code
09d4efe1
EZ
21616@kindex maint agent
21617@item maint agent @var{expression}
21618Translate the given @var{expression} into remote agent bytecodes.
21619This command is useful for debugging the Agent Expression mechanism
21620(@pxref{Agent Expressions}).
21621
8e04817f
AC
21622@kindex maint info breakpoints
21623@item @anchor{maint info breakpoints}maint info breakpoints
21624Using the same format as @samp{info breakpoints}, display both the
21625breakpoints you've set explicitly, and those @value{GDBN} is using for
21626internal purposes. Internal breakpoints are shown with negative
21627breakpoint numbers. The type column identifies what kind of breakpoint
21628is shown:
c906108c 21629
8e04817f
AC
21630@table @code
21631@item breakpoint
21632Normal, explicitly set breakpoint.
c906108c 21633
8e04817f
AC
21634@item watchpoint
21635Normal, explicitly set watchpoint.
c906108c 21636
8e04817f
AC
21637@item longjmp
21638Internal breakpoint, used to handle correctly stepping through
21639@code{longjmp} calls.
c906108c 21640
8e04817f
AC
21641@item longjmp resume
21642Internal breakpoint at the target of a @code{longjmp}.
c906108c 21643
8e04817f
AC
21644@item until
21645Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 21646
8e04817f
AC
21647@item finish
21648Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 21649
8e04817f
AC
21650@item shlib events
21651Shared library events.
c906108c 21652
8e04817f 21653@end table
c906108c 21654
09d4efe1
EZ
21655@kindex maint check-symtabs
21656@item maint check-symtabs
21657Check the consistency of psymtabs and symtabs.
21658
21659@kindex maint cplus first_component
21660@item maint cplus first_component @var{name}
21661Print the first C@t{++} class/namespace component of @var{name}.
21662
21663@kindex maint cplus namespace
21664@item maint cplus namespace
21665Print the list of possible C@t{++} namespaces.
21666
21667@kindex maint demangle
21668@item maint demangle @var{name}
21669Demangle a C@t{++} or Objective-C manled @var{name}.
21670
21671@kindex maint deprecate
21672@kindex maint undeprecate
21673@cindex deprecated commands
21674@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
21675@itemx maint undeprecate @var{command}
21676Deprecate or undeprecate the named @var{command}. Deprecated commands
21677cause @value{GDBN} to issue a warning when you use them. The optional
21678argument @var{replacement} says which newer command should be used in
21679favor of the deprecated one; if it is given, @value{GDBN} will mention
21680the replacement as part of the warning.
21681
21682@kindex maint dump-me
21683@item maint dump-me
721c2651 21684@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 21685Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
21686This is supported only on systems which support aborting a program
21687with the @code{SIGQUIT} signal.
09d4efe1 21688
8d30a00d
AC
21689@kindex maint internal-error
21690@kindex maint internal-warning
09d4efe1
EZ
21691@item maint internal-error @r{[}@var{message-text}@r{]}
21692@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
21693Cause @value{GDBN} to call the internal function @code{internal_error}
21694or @code{internal_warning} and hence behave as though an internal error
21695or internal warning has been detected. In addition to reporting the
21696internal problem, these functions give the user the opportunity to
21697either quit @value{GDBN} or create a core file of the current
21698@value{GDBN} session.
21699
09d4efe1
EZ
21700These commands take an optional parameter @var{message-text} that is
21701used as the text of the error or warning message.
21702
21703Here's an example of using @code{indernal-error}:
21704
8d30a00d 21705@smallexample
f7dc1244 21706(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
21707@dots{}/maint.c:121: internal-error: testing, 1, 2
21708A problem internal to GDB has been detected. Further
21709debugging may prove unreliable.
21710Quit this debugging session? (y or n) @kbd{n}
21711Create a core file? (y or n) @kbd{n}
f7dc1244 21712(@value{GDBP})
8d30a00d
AC
21713@end smallexample
21714
09d4efe1
EZ
21715@kindex maint packet
21716@item maint packet @var{text}
21717If @value{GDBN} is talking to an inferior via the serial protocol,
21718then this command sends the string @var{text} to the inferior, and
21719displays the response packet. @value{GDBN} supplies the initial
21720@samp{$} character, the terminating @samp{#} character, and the
21721checksum.
21722
21723@kindex maint print architecture
21724@item maint print architecture @r{[}@var{file}@r{]}
21725Print the entire architecture configuration. The optional argument
21726@var{file} names the file where the output goes.
8d30a00d 21727
00905d52
AC
21728@kindex maint print dummy-frames
21729@item maint print dummy-frames
00905d52
AC
21730Prints the contents of @value{GDBN}'s internal dummy-frame stack.
21731
21732@smallexample
f7dc1244 21733(@value{GDBP}) @kbd{b add}
00905d52 21734@dots{}
f7dc1244 21735(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
21736Breakpoint 2, add (a=2, b=3) at @dots{}
2173758 return (a + b);
21738The program being debugged stopped while in a function called from GDB.
21739@dots{}
f7dc1244 21740(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
217410x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
21742 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
21743 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 21744(@value{GDBP})
00905d52
AC
21745@end smallexample
21746
21747Takes an optional file parameter.
21748
0680b120
AC
21749@kindex maint print registers
21750@kindex maint print raw-registers
21751@kindex maint print cooked-registers
617073a9 21752@kindex maint print register-groups
09d4efe1
EZ
21753@item maint print registers @r{[}@var{file}@r{]}
21754@itemx maint print raw-registers @r{[}@var{file}@r{]}
21755@itemx maint print cooked-registers @r{[}@var{file}@r{]}
21756@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
21757Print @value{GDBN}'s internal register data structures.
21758
617073a9
AC
21759The command @code{maint print raw-registers} includes the contents of
21760the raw register cache; the command @code{maint print cooked-registers}
21761includes the (cooked) value of all registers; and the command
21762@code{maint print register-groups} includes the groups that each
21763register is a member of. @xref{Registers,, Registers, gdbint,
21764@value{GDBN} Internals}.
0680b120 21765
09d4efe1
EZ
21766These commands take an optional parameter, a file name to which to
21767write the information.
0680b120 21768
617073a9 21769@kindex maint print reggroups
09d4efe1
EZ
21770@item maint print reggroups @r{[}@var{file}@r{]}
21771Print @value{GDBN}'s internal register group data structures. The
21772optional argument @var{file} tells to what file to write the
21773information.
617073a9 21774
09d4efe1 21775The register groups info looks like this:
617073a9
AC
21776
21777@smallexample
f7dc1244 21778(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
21779 Group Type
21780 general user
21781 float user
21782 all user
21783 vector user
21784 system user
21785 save internal
21786 restore internal
617073a9
AC
21787@end smallexample
21788
09d4efe1
EZ
21789@kindex flushregs
21790@item flushregs
21791This command forces @value{GDBN} to flush its internal register cache.
21792
21793@kindex maint print objfiles
21794@cindex info for known object files
21795@item maint print objfiles
21796Print a dump of all known object files. For each object file, this
21797command prints its name, address in memory, and all of its psymtabs
21798and symtabs.
21799
21800@kindex maint print statistics
21801@cindex bcache statistics
21802@item maint print statistics
21803This command prints, for each object file in the program, various data
21804about that object file followed by the byte cache (@dfn{bcache})
21805statistics for the object file. The objfile data includes the number
21806of minimal, partical, full, and stabs symbols, the number of types
21807defined by the objfile, the number of as yet unexpanded psym tables,
21808the number of line tables and string tables, and the amount of memory
21809used by the various tables. The bcache statistics include the counts,
21810sizes, and counts of duplicates of all and unique objects, max,
21811average, and median entry size, total memory used and its overhead and
21812savings, and various measures of the hash table size and chain
21813lengths.
21814
21815@kindex maint print type
21816@cindex type chain of a data type
21817@item maint print type @var{expr}
21818Print the type chain for a type specified by @var{expr}. The argument
21819can be either a type name or a symbol. If it is a symbol, the type of
21820that symbol is described. The type chain produced by this command is
21821a recursive definition of the data type as stored in @value{GDBN}'s
21822data structures, including its flags and contained types.
21823
21824@kindex maint set dwarf2 max-cache-age
21825@kindex maint show dwarf2 max-cache-age
21826@item maint set dwarf2 max-cache-age
21827@itemx maint show dwarf2 max-cache-age
21828Control the DWARF 2 compilation unit cache.
21829
21830@cindex DWARF 2 compilation units cache
21831In object files with inter-compilation-unit references, such as those
21832produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
21833reader needs to frequently refer to previously read compilation units.
21834This setting controls how long a compilation unit will remain in the
21835cache if it is not referenced. A higher limit means that cached
21836compilation units will be stored in memory longer, and more total
21837memory will be used. Setting it to zero disables caching, which will
21838slow down @value{GDBN} startup, but reduce memory consumption.
21839
e7ba9c65
DJ
21840@kindex maint set profile
21841@kindex maint show profile
21842@cindex profiling GDB
21843@item maint set profile
21844@itemx maint show profile
21845Control profiling of @value{GDBN}.
21846
21847Profiling will be disabled until you use the @samp{maint set profile}
21848command to enable it. When you enable profiling, the system will begin
21849collecting timing and execution count data; when you disable profiling or
21850exit @value{GDBN}, the results will be written to a log file. Remember that
21851if you use profiling, @value{GDBN} will overwrite the profiling log file
21852(often called @file{gmon.out}). If you have a record of important profiling
21853data in a @file{gmon.out} file, be sure to move it to a safe location.
21854
21855Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 21856compiled with the @samp{-pg} compiler option.
e7ba9c65 21857
09d4efe1
EZ
21858@kindex maint show-debug-regs
21859@cindex x86 hardware debug registers
21860@item maint show-debug-regs
21861Control whether to show variables that mirror the x86 hardware debug
21862registers. Use @code{ON} to enable, @code{OFF} to disable. If
21863enabled, the debug registers values are shown when GDB inserts or
21864removes a hardware breakpoint or watchpoint, and when the inferior
21865triggers a hardware-assisted breakpoint or watchpoint.
21866
21867@kindex maint space
21868@cindex memory used by commands
21869@item maint space
21870Control whether to display memory usage for each command. If set to a
21871nonzero value, @value{GDBN} will display how much memory each command
21872took, following the command's own output. This can also be requested
21873by invoking @value{GDBN} with the @option{--statistics} command-line
21874switch (@pxref{Mode Options}).
21875
21876@kindex maint time
21877@cindex time of command execution
21878@item maint time
21879Control whether to display the execution time for each command. If
21880set to a nonzero value, @value{GDBN} will display how much time it
21881took to execute each command, following the command's own output.
21882This can also be requested by invoking @value{GDBN} with the
21883@option{--statistics} command-line switch (@pxref{Mode Options}).
21884
21885@kindex maint translate-address
21886@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
21887Find the symbol stored at the location specified by the address
21888@var{addr} and an optional section name @var{section}. If found,
21889@value{GDBN} prints the name of the closest symbol and an offset from
21890the symbol's location to the specified address. This is similar to
21891the @code{info address} command (@pxref{Symbols}), except that this
21892command also allows to find symbols in other sections.
ae038cb0 21893
8e04817f 21894@end table
c906108c 21895
9c16f35a
EZ
21896The following command is useful for non-interactive invocations of
21897@value{GDBN}, such as in the test suite.
21898
21899@table @code
21900@item set watchdog @var{nsec}
21901@kindex set watchdog
21902@cindex watchdog timer
21903@cindex timeout for commands
21904Set the maximum number of seconds @value{GDBN} will wait for the
21905target operation to finish. If this time expires, @value{GDBN}
21906reports and error and the command is aborted.
21907
21908@item show watchdog
21909Show the current setting of the target wait timeout.
21910@end table
c906108c 21911
e0ce93ac 21912@node Remote Protocol
8e04817f 21913@appendix @value{GDBN} Remote Serial Protocol
c906108c 21914
ee2d5c50
AC
21915@menu
21916* Overview::
21917* Packets::
21918* Stop Reply Packets::
21919* General Query Packets::
21920* Register Packet Format::
21921* Examples::
0ce1b118 21922* File-I/O remote protocol extension::
ee2d5c50
AC
21923@end menu
21924
21925@node Overview
21926@section Overview
21927
8e04817f
AC
21928There may be occasions when you need to know something about the
21929protocol---for example, if there is only one serial port to your target
21930machine, you might want your program to do something special if it
21931recognizes a packet meant for @value{GDBN}.
c906108c 21932
d2c6833e 21933In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 21934transmitted and received data respectfully.
c906108c 21935
8e04817f
AC
21936@cindex protocol, @value{GDBN} remote serial
21937@cindex serial protocol, @value{GDBN} remote
21938@cindex remote serial protocol
21939All @value{GDBN} commands and responses (other than acknowledgments) are
21940sent as a @var{packet}. A @var{packet} is introduced with the character
21941@samp{$}, the actual @var{packet-data}, and the terminating character
21942@samp{#} followed by a two-digit @var{checksum}:
c906108c 21943
474c8240 21944@smallexample
8e04817f 21945@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 21946@end smallexample
8e04817f 21947@noindent
c906108c 21948
8e04817f
AC
21949@cindex checksum, for @value{GDBN} remote
21950@noindent
21951The two-digit @var{checksum} is computed as the modulo 256 sum of all
21952characters between the leading @samp{$} and the trailing @samp{#} (an
21953eight bit unsigned checksum).
c906108c 21954
8e04817f
AC
21955Implementors should note that prior to @value{GDBN} 5.0 the protocol
21956specification also included an optional two-digit @var{sequence-id}:
c906108c 21957
474c8240 21958@smallexample
8e04817f 21959@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 21960@end smallexample
c906108c 21961
8e04817f
AC
21962@cindex sequence-id, for @value{GDBN} remote
21963@noindent
21964That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
21965has never output @var{sequence-id}s. Stubs that handle packets added
21966since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 21967
8e04817f
AC
21968@cindex acknowledgment, for @value{GDBN} remote
21969When either the host or the target machine receives a packet, the first
21970response expected is an acknowledgment: either @samp{+} (to indicate
21971the package was received correctly) or @samp{-} (to request
21972retransmission):
c906108c 21973
474c8240 21974@smallexample
d2c6833e
AC
21975-> @code{$}@var{packet-data}@code{#}@var{checksum}
21976<- @code{+}
474c8240 21977@end smallexample
8e04817f 21978@noindent
53a5351d 21979
8e04817f
AC
21980The host (@value{GDBN}) sends @var{command}s, and the target (the
21981debugging stub incorporated in your program) sends a @var{response}. In
21982the case of step and continue @var{command}s, the response is only sent
21983when the operation has completed (the target has again stopped).
c906108c 21984
8e04817f
AC
21985@var{packet-data} consists of a sequence of characters with the
21986exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
21987exceptions).
c906108c 21988
8e04817f 21989Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 21990@cindex remote protocol, field separator
8e04817f 21991@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 21992@sc{hex} with leading zeros suppressed.
c906108c 21993
8e04817f
AC
21994Implementors should note that prior to @value{GDBN} 5.0, the character
21995@samp{:} could not appear as the third character in a packet (as it
21996would potentially conflict with the @var{sequence-id}).
c906108c 21997
8e04817f
AC
21998Response @var{data} can be run-length encoded to save space. A @samp{*}
21999means that the next character is an @sc{ascii} encoding giving a repeat count
22000which stands for that many repetitions of the character preceding the
22001@samp{*}. The encoding is @code{n+29}, yielding a printable character
22002where @code{n >=3} (which is where rle starts to win). The printable
22003characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
22004value greater than 126 should not be used.
c906108c 22005
8e04817f 22006So:
474c8240 22007@smallexample
8e04817f 22008"@code{0* }"
474c8240 22009@end smallexample
8e04817f
AC
22010@noindent
22011means the same as "0000".
c906108c 22012
8e04817f
AC
22013The error response returned for some packets includes a two character
22014error number. That number is not well defined.
c906108c 22015
8e04817f
AC
22016For any @var{command} not supported by the stub, an empty response
22017(@samp{$#00}) should be returned. That way it is possible to extend the
22018protocol. A newer @value{GDBN} can tell if a packet is supported based
22019on that response.
c906108c 22020
b383017d
RM
22021A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
22022@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 22023optional.
c906108c 22024
ee2d5c50
AC
22025@node Packets
22026@section Packets
22027
22028The following table provides a complete list of all currently defined
22029@var{command}s and their corresponding response @var{data}.
9c16f35a
EZ
22030@xref{File-I/O remote protocol extension}, for details about the File
22031I/O extension of the remote protocol.
ee2d5c50
AC
22032
22033@table @r
22034
22035@item @code{!} --- extended mode
22036@cindex @code{!} packet
22037
8e04817f
AC
22038Enable extended mode. In extended mode, the remote server is made
22039persistent. The @samp{R} packet is used to restart the program being
22040debugged.
ee2d5c50
AC
22041
22042Reply:
22043@table @samp
22044@item OK
8e04817f 22045The remote target both supports and has enabled extended mode.
ee2d5c50 22046@end table
c906108c 22047
ee2d5c50
AC
22048@item @code{?} --- last signal
22049@cindex @code{?} packet
c906108c 22050
ee2d5c50
AC
22051Indicate the reason the target halted. The reply is the same as for
22052step and continue.
c906108c 22053
ee2d5c50
AC
22054Reply:
22055@xref{Stop Reply Packets}, for the reply specifications.
22056
22057@item @code{a} --- reserved
22058
22059Reserved for future use.
22060
22061@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
22062@cindex @code{A} packet
c906108c 22063
8e04817f
AC
22064Initialized @samp{argv[]} array passed into program. @var{arglen}
22065specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
22066See @code{gdbserver} for more details.
22067
22068Reply:
22069@table @samp
22070@item OK
22071@item E@var{NN}
22072@end table
22073
22074@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
22075@cindex @code{b} packet
22076
22077Change the serial line speed to @var{baud}.
22078
22079JTC: @emph{When does the transport layer state change? When it's
22080received, or after the ACK is transmitted. In either case, there are
22081problems if the command or the acknowledgment packet is dropped.}
22082
22083Stan: @emph{If people really wanted to add something like this, and get
22084it working for the first time, they ought to modify ser-unix.c to send
22085some kind of out-of-band message to a specially-setup stub and have the
22086switch happen "in between" packets, so that from remote protocol's point
22087of view, nothing actually happened.}
22088
22089@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
22090@cindex @code{B} packet
22091
8e04817f 22092Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
22093breakpoint at @var{addr}.
22094
22095This packet has been replaced by the @samp{Z} and @samp{z} packets
22096(@pxref{insert breakpoint or watchpoint packet}).
c906108c 22097
ee2d5c50
AC
22098@item @code{c}@var{addr} --- continue
22099@cindex @code{c} packet
22100
22101@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 22102current address.
c906108c 22103
ee2d5c50
AC
22104Reply:
22105@xref{Stop Reply Packets}, for the reply specifications.
22106
22107@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
22108@cindex @code{C} packet
22109
8e04817f
AC
22110Continue with signal @var{sig} (hex signal number). If
22111@code{;}@var{addr} is omitted, resume at same address.
c906108c 22112
ee2d5c50
AC
22113Reply:
22114@xref{Stop Reply Packets}, for the reply specifications.
c906108c 22115
ee2d5c50
AC
22116@item @code{d} --- toggle debug @strong{(deprecated)}
22117@cindex @code{d} packet
22118
22119Toggle debug flag.
22120
22121@item @code{D} --- detach
22122@cindex @code{D} packet
22123
22124Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 22125before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
22126
22127Reply:
22128@table @samp
10fac096
NW
22129@item OK
22130for success
22131@item E@var{NN}
22132for an error
ee2d5c50 22133@end table
c906108c 22134
ee2d5c50 22135@item @code{e} --- reserved
c906108c 22136
ee2d5c50 22137Reserved for future use.
c906108c 22138
ee2d5c50 22139@item @code{E} --- reserved
c906108c 22140
ee2d5c50 22141Reserved for future use.
c906108c 22142
ee2d5c50
AC
22143@item @code{f} --- reserved
22144
22145Reserved for future use.
22146
0ce1b118
CV
22147@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
22148@cindex @code{F} packet
ee2d5c50 22149
0ce1b118
CV
22150This packet is send by @value{GDBN} as reply to a @code{F} request packet
22151sent by the target. This is part of the File-I/O protocol extension.
22152@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
22153
22154@item @code{g} --- read registers
22155@anchor{read registers packet}
22156@cindex @code{g} packet
22157
22158Read general registers.
22159
22160Reply:
22161@table @samp
22162@item @var{XX@dots{}}
8e04817f
AC
22163Each byte of register data is described by two hex digits. The bytes
22164with the register are transmitted in target byte order. The size of
22165each register and their position within the @samp{g} @var{packet} are
12c266ea
AC
22166determined by the @value{GDBN} internal macros
22167@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
22168specification of several standard @code{g} packets is specified below.
ee2d5c50
AC
22169@item E@var{NN}
22170for an error.
22171@end table
c906108c 22172
ee2d5c50
AC
22173@item @code{G}@var{XX@dots{}} --- write regs
22174@cindex @code{G} packet
c906108c 22175
ee2d5c50
AC
22176@xref{read registers packet}, for a description of the @var{XX@dots{}}
22177data.
22178
22179Reply:
22180@table @samp
22181@item OK
22182for success
22183@item E@var{NN}
22184for an error
22185@end table
22186
22187@item @code{h} --- reserved
22188
22189Reserved for future use.
22190
b383017d 22191@item @code{H}@var{c}@var{t@dots{}} --- set thread
ee2d5c50 22192@cindex @code{H} packet
c906108c 22193
8e04817f 22194Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
22195@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
22196should be @samp{c} for step and continue operations, @samp{g} for other
22197operations. The thread designator @var{t@dots{}} may be -1, meaning all
22198the threads, a thread number, or zero which means pick any thread.
22199
22200Reply:
22201@table @samp
22202@item OK
22203for success
22204@item E@var{NN}
22205for an error
22206@end table
c906108c 22207
8e04817f
AC
22208@c FIXME: JTC:
22209@c 'H': How restrictive (or permissive) is the thread model. If a
22210@c thread is selected and stopped, are other threads allowed
22211@c to continue to execute? As I mentioned above, I think the
22212@c semantics of each command when a thread is selected must be
22213@c described. For example:
22214@c
22215@c 'g': If the stub supports threads and a specific thread is
22216@c selected, returns the register block from that thread;
22217@c otherwise returns current registers.
22218@c
22219@c 'G' If the stub supports threads and a specific thread is
22220@c selected, sets the registers of the register block of
22221@c that thread; otherwise sets current registers.
c906108c 22222
ee2d5c50
AC
22223@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
22224@anchor{cycle step packet}
22225@cindex @code{i} packet
22226
8e04817f
AC
22227Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
22228present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
22229step starting at that address.
c906108c 22230
ee2d5c50
AC
22231@item @code{I} --- signal then cycle step @strong{(reserved)}
22232@cindex @code{I} packet
22233
22234@xref{step with signal packet}. @xref{cycle step packet}.
22235
22236@item @code{j} --- reserved
22237
22238Reserved for future use.
22239
22240@item @code{J} --- reserved
c906108c 22241
ee2d5c50 22242Reserved for future use.
c906108c 22243
ee2d5c50
AC
22244@item @code{k} --- kill request
22245@cindex @code{k} packet
c906108c 22246
ac282366 22247FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
22248thread context has been selected (i.e.@: does 'k' kill only that
22249thread?)}.
c906108c 22250
ee2d5c50 22251@item @code{K} --- reserved
c906108c 22252
ee2d5c50
AC
22253Reserved for future use.
22254
22255@item @code{l} --- reserved
22256
22257Reserved for future use.
22258
22259@item @code{L} --- reserved
22260
22261Reserved for future use.
22262
22263@item @code{m}@var{addr}@code{,}@var{length} --- read memory
22264@cindex @code{m} packet
c906108c 22265
8e04817f 22266Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 22267Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 22268assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 22269transfer mechanism is needed.}
c906108c 22270
ee2d5c50
AC
22271Reply:
22272@table @samp
22273@item @var{XX@dots{}}
22274@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
22275to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 22276that sized memory transfers are assumed using word aligned
ee2d5c50
AC
22277accesses. FIXME: @emph{A word aligned memory transfer mechanism is
22278needed.}
22279@item E@var{NN}
22280@var{NN} is errno
22281@end table
22282
22283@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
22284@cindex @code{M} packet
22285
8e04817f 22286Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
22287@var{XX@dots{}} is the data.
22288
22289Reply:
22290@table @samp
22291@item OK
22292for success
22293@item E@var{NN}
8e04817f
AC
22294for an error (this includes the case where only part of the data was
22295written).
ee2d5c50 22296@end table
c906108c 22297
ee2d5c50 22298@item @code{n} --- reserved
c906108c 22299
ee2d5c50 22300Reserved for future use.
c906108c 22301
ee2d5c50 22302@item @code{N} --- reserved
c906108c 22303
ee2d5c50 22304Reserved for future use.
c906108c 22305
ee2d5c50
AC
22306@item @code{o} --- reserved
22307
22308Reserved for future use.
22309
22310@item @code{O} --- reserved
22311
2e868123 22312@item @code{p}@var{hex number of register} --- read register packet
ee2d5c50
AC
22313@cindex @code{p} packet
22314
2e868123
AC
22315@xref{read registers packet}, for a description of how the returned
22316register value is encoded.
ee2d5c50
AC
22317
22318Reply:
22319@table @samp
2e868123
AC
22320@item @var{XX@dots{}}
22321the register's value
22322@item E@var{NN}
22323for an error
22324@item
22325Indicating an unrecognized @var{query}.
ee2d5c50
AC
22326@end table
22327
22328@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
22329@anchor{write register packet}
22330@cindex @code{P} packet
22331
22332Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 22333digits for each byte in the register (target byte order).
c906108c 22334
ee2d5c50
AC
22335Reply:
22336@table @samp
22337@item OK
22338for success
22339@item E@var{NN}
22340for an error
22341@end table
22342
22343@item @code{q}@var{query} --- general query
22344@anchor{general query packet}
22345@cindex @code{q} packet
22346
22347Request info about @var{query}. In general @value{GDBN} queries have a
22348leading upper case letter. Custom vendor queries should use a company
22349prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
22350be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
22351that they match the full @var{query} name.
22352
22353Reply:
22354@table @samp
22355@item @var{XX@dots{}}
22356Hex encoded data from query. The reply can not be empty.
22357@item E@var{NN}
22358error reply
8e04817f 22359@item
ee2d5c50
AC
22360Indicating an unrecognized @var{query}.
22361@end table
22362
22363@item @code{Q}@var{var}@code{=}@var{val} --- general set
22364@cindex @code{Q} packet
22365
22366Set value of @var{var} to @var{val}.
22367
22368@xref{general query packet}, for a discussion of naming conventions.
c906108c 22369
ee2d5c50
AC
22370@item @code{r} --- reset @strong{(deprecated)}
22371@cindex @code{r} packet
c906108c 22372
8e04817f 22373Reset the entire system.
c906108c 22374
ee2d5c50
AC
22375@item @code{R}@var{XX} --- remote restart
22376@cindex @code{R} packet
22377
8e04817f
AC
22378Restart the program being debugged. @var{XX}, while needed, is ignored.
22379This packet is only available in extended mode.
ee2d5c50
AC
22380
22381Reply:
22382@table @samp
22383@item @emph{no reply}
8e04817f 22384The @samp{R} packet has no reply.
ee2d5c50
AC
22385@end table
22386
22387@item @code{s}@var{addr} --- step
22388@cindex @code{s} packet
c906108c 22389
8e04817f
AC
22390@var{addr} is address to resume. If @var{addr} is omitted, resume at
22391same address.
c906108c 22392
ee2d5c50
AC
22393Reply:
22394@xref{Stop Reply Packets}, for the reply specifications.
22395
22396@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
22397@anchor{step with signal packet}
22398@cindex @code{S} packet
22399
8e04817f 22400Like @samp{C} but step not continue.
c906108c 22401
ee2d5c50
AC
22402Reply:
22403@xref{Stop Reply Packets}, for the reply specifications.
22404
b383017d 22405@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
ee2d5c50
AC
22406@cindex @code{t} packet
22407
8e04817f 22408Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
22409@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
22410@var{addr} must be at least 3 digits.
c906108c 22411
ee2d5c50
AC
22412@item @code{T}@var{XX} --- thread alive
22413@cindex @code{T} packet
c906108c 22414
ee2d5c50 22415Find out if the thread XX is alive.
c906108c 22416
ee2d5c50
AC
22417Reply:
22418@table @samp
22419@item OK
22420thread is still alive
22421@item E@var{NN}
22422thread is dead
22423@end table
22424
22425@item @code{u} --- reserved
22426
22427Reserved for future use.
22428
22429@item @code{U} --- reserved
22430
22431Reserved for future use.
22432
86d30acc 22433@item @code{v} --- verbose packet prefix
ee2d5c50 22434
86d30acc
DJ
22435Packets starting with @code{v} are identified by a multi-letter name,
22436up to the first @code{;} or @code{?} (or the end of the packet).
22437
22438@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
22439@cindex @code{vCont} packet
22440
22441Resume the inferior. Different actions may be specified for each thread.
22442If an action is specified with no @var{tid}, then it is applied to any
22443threads that don't have a specific action specified; if no default action is
22444specified then other threads should remain stopped. Specifying multiple
22445default actions is an error; specifying no actions is also an error.
22446Thread IDs are specified in hexadecimal. Currently supported actions are:
22447
22448@table @code
22449@item c
22450Continue.
22451@item C@var{sig}
22452Continue with signal @var{sig}. @var{sig} should be two hex digits.
22453@item s
22454Step.
22455@item S@var{sig}
22456Step with signal @var{sig}. @var{sig} should be two hex digits.
22457@end table
22458
22459The optional @var{addr} argument normally associated with these packets is
22460not supported in @code{vCont}.
22461
22462Reply:
22463@xref{Stop Reply Packets}, for the reply specifications.
22464
22465@item @code{vCont?} --- extended resume query
22466@cindex @code{vCont?} packet
22467
22468Query support for the @code{vCont} packet.
22469
22470Reply:
22471@table @samp
22472@item @code{vCont}[;@var{action}]...
22473The @code{vCont} packet is supported. Each @var{action} is a supported
22474command in the @code{vCont} packet.
22475@item
22476The @code{vCont} packet is not supported.
22477@end table
ee2d5c50
AC
22478
22479@item @code{V} --- reserved
c906108c 22480
ee2d5c50 22481Reserved for future use.
c906108c 22482
ee2d5c50 22483@item @code{w} --- reserved
c906108c 22484
ee2d5c50 22485Reserved for future use.
c906108c 22486
ee2d5c50 22487@item @code{W} --- reserved
c906108c 22488
ee2d5c50 22489Reserved for future use.
c906108c 22490
ee2d5c50
AC
22491@item @code{x} --- reserved
22492
22493Reserved for future use.
22494
22495@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
22496@cindex @code{X} packet
22497
22498@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
22499is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
69065f5d
AC
22500escaped using @code{0x7d}, and then XORed with @code{0x20}.
22501For example, @code{0x7d} would be transmitted as @code{0x7d 0x5d}.
c906108c 22502
ee2d5c50
AC
22503Reply:
22504@table @samp
22505@item OK
22506for success
22507@item E@var{NN}
22508for an error
22509@end table
22510
22511@item @code{y} --- reserved
c906108c 22512
ee2d5c50 22513Reserved for future use.
c906108c 22514
ee2d5c50
AC
22515@item @code{Y} reserved
22516
22517Reserved for future use.
22518
2f870471
AC
22519@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
22520@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
22521@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 22522@cindex @code{z} packet
2f870471 22523@cindex @code{Z} packets
ee2d5c50 22524
2f870471
AC
22525Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
22526watchpoint starting at address @var{address} and covering the next
22527@var{length} bytes.
ee2d5c50 22528
2f870471
AC
22529Each breakpoint and watchpoint packet @var{type} is documented
22530separately.
22531
512217c7
AC
22532@emph{Implementation notes: A remote target shall return an empty string
22533for an unrecognized breakpoint or watchpoint packet @var{type}. A
22534remote target shall support either both or neither of a given
2f870471
AC
22535@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
22536avoid potential problems with duplicate packets, the operations should
22537be implemented in an idempotent way.}
22538
22539@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
22540@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
22541@cindex @code{z0} packet
22542@cindex @code{Z0} packet
22543
22544Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
22545@code{addr} of size @code{length}.
22546
22547A memory breakpoint is implemented by replacing the instruction at
22548@var{addr} with a software breakpoint or trap instruction. The
22549@code{length} is used by targets that indicates the size of the
22550breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
22551@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 22552
2f870471
AC
22553@emph{Implementation note: It is possible for a target to copy or move
22554code that contains memory breakpoints (e.g., when implementing
22555overlays). The behavior of this packet, in the presence of such a
22556target, is not defined.}
c906108c 22557
ee2d5c50
AC
22558Reply:
22559@table @samp
2f870471
AC
22560@item OK
22561success
22562@item
22563not supported
ee2d5c50
AC
22564@item E@var{NN}
22565for an error
2f870471
AC
22566@end table
22567
22568@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
22569@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
22570@cindex @code{z1} packet
22571@cindex @code{Z1} packet
22572
22573Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
22574address @code{addr} of size @code{length}.
22575
22576A hardware breakpoint is implemented using a mechanism that is not
22577dependant on being able to modify the target's memory.
22578
22579@emph{Implementation note: A hardware breakpoint is not affected by code
22580movement.}
22581
22582Reply:
22583@table @samp
ee2d5c50 22584@item OK
2f870471
AC
22585success
22586@item
22587not supported
22588@item E@var{NN}
22589for an error
22590@end table
22591
22592@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
22593@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
22594@cindex @code{z2} packet
22595@cindex @code{Z2} packet
22596
22597Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
22598
22599Reply:
22600@table @samp
22601@item OK
22602success
22603@item
22604not supported
22605@item E@var{NN}
22606for an error
22607@end table
22608
22609@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
22610@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
22611@cindex @code{z3} packet
22612@cindex @code{Z3} packet
22613
2e834e49 22614Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
22615
22616Reply:
22617@table @samp
22618@item OK
22619success
22620@item
22621not supported
22622@item E@var{NN}
22623for an error
22624@end table
22625
2e834e49
HPN
22626@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
22627@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
22628@cindex @code{z4} packet
22629@cindex @code{Z4} packet
22630
22631Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
22632
22633Reply:
22634@table @samp
22635@item OK
22636success
22637@item
22638not supported
22639@item E@var{NN}
22640for an error
ee2d5c50
AC
22641@end table
22642
22643@end table
c906108c 22644
ee2d5c50
AC
22645@node Stop Reply Packets
22646@section Stop Reply Packets
22647@cindex stop reply packets
c906108c 22648
8e04817f
AC
22649The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
22650receive any of the below as a reply. In the case of the @samp{C},
22651@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
22652when the target halts. In the below the exact meaning of @samp{signal
22653number} is poorly defined. In general one of the UNIX signal numbering
22654conventions is used.
c906108c 22655
ee2d5c50 22656@table @samp
c906108c 22657
ee2d5c50
AC
22658@item S@var{AA}
22659@var{AA} is the signal number
c906108c 22660
8e04817f 22661@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
22662@cindex @code{T} packet reply
22663
8e04817f
AC
22664@var{AA} = two hex digit signal number; @var{n...} = register number
22665(hex), @var{r...} = target byte ordered register contents, size defined
12c266ea
AC
22666by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
22667@var{r...} = thread process ID, this is a hex integer; @var{n...} =
22668(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
22669address, this is a hex integer; @var{n...} = other string not starting
22670with valid hex digit. @value{GDBN} should ignore this @var{n...},
22671@var{r...} pair and go on to the next. This way we can extend the
22672protocol.
c906108c 22673
ee2d5c50
AC
22674@item W@var{AA}
22675
8e04817f 22676The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
22677applicable to certain targets.
22678
22679@item X@var{AA}
c906108c 22680
8e04817f 22681The process terminated with signal @var{AA}.
c906108c 22682
ee2d5c50 22683@item O@var{XX@dots{}}
c906108c 22684
ee2d5c50
AC
22685@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
22686any time while the program is running and the debugger should continue
22687to wait for @samp{W}, @samp{T}, etc.
22688
0ce1b118
CV
22689@item F@var{call-id}@code{,}@var{parameter@dots{}}
22690
22691@var{call-id} is the identifier which says which host system call should
22692be called. This is just the name of the function. Translation into the
22693correct system call is only applicable as it's defined in @value{GDBN}.
22694@xref{File-I/O remote protocol extension}, for a list of implemented
22695system calls.
22696
22697@var{parameter@dots{}} is a list of parameters as defined for this very
22698system call.
22699
22700The target replies with this packet when it expects @value{GDBN} to call
22701a host system call on behalf of the target. @value{GDBN} replies with
22702an appropriate @code{F} packet and keeps up waiting for the next reply
22703packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
22704@samp{s} action is expected to be continued.
22705@xref{File-I/O remote protocol extension}, for more details.
22706
ee2d5c50
AC
22707@end table
22708
22709@node General Query Packets
22710@section General Query Packets
9c16f35a 22711@cindex remote query requests
c906108c 22712
8e04817f 22713The following set and query packets have already been defined.
c906108c 22714
ee2d5c50 22715@table @r
c906108c 22716
ee2d5c50 22717@item @code{q}@code{C} --- current thread
9c16f35a
EZ
22718@cindex current thread, remote request
22719@cindex @code{qC} packet
ee2d5c50
AC
22720Return the current thread id.
22721
22722Reply:
22723@table @samp
22724@item @code{QC}@var{pid}
e1aac25b 22725Where @var{pid} is an unsigned hexidecimal process id.
ee2d5c50
AC
22726@item *
22727Any other reply implies the old pid.
22728@end table
22729
22730@item @code{q}@code{fThreadInfo} -- all thread ids
9c16f35a
EZ
22731@cindex list active threads, remote request
22732@cindex @code{qfThreadInfo} packet
ee2d5c50 22733@code{q}@code{sThreadInfo}
c906108c 22734
8e04817f
AC
22735Obtain a list of active thread ids from the target (OS). Since there
22736may be too many active threads to fit into one reply packet, this query
22737works iteratively: it may require more than one query/reply sequence to
22738obtain the entire list of threads. The first query of the sequence will
22739be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
22740sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
22741
22742NOTE: replaces the @code{qL} query (see below).
22743
22744Reply:
22745@table @samp
22746@item @code{m}@var{id}
22747A single thread id
22748@item @code{m}@var{id},@var{id}@dots{}
22749a comma-separated list of thread ids
22750@item @code{l}
22751(lower case 'el') denotes end of list.
22752@end table
22753
22754In response to each query, the target will reply with a list of one or
e1aac25b
JB
22755more thread ids, in big-endian unsigned hex, separated by commas.
22756@value{GDBN} will respond to each reply with a request for more thread
22757ids (using the @code{qs} form of the query), until the target responds
22758with @code{l} (lower-case el, for @code{'last'}).
c906108c 22759
ee2d5c50 22760@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
9c16f35a
EZ
22761@cindex thread attributes info, remote request
22762@cindex @code{qThreadExtraInfo} packet
ee2d5c50
AC
22763Where @var{id} is a thread-id in big-endian hex. Obtain a printable
22764string description of a thread's attributes from the target OS. This
22765string may contain anything that the target OS thinks is interesting for
22766@value{GDBN} to tell the user about the thread. The string is displayed
22767in @value{GDBN}'s @samp{info threads} display. Some examples of
22768possible thread extra info strings are ``Runnable'', or ``Blocked on
22769Mutex''.
22770
22771Reply:
22772@table @samp
22773@item @var{XX@dots{}}
22774Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
22775the printable string containing the extra information about the thread's
8e04817f 22776attributes.
ee2d5c50
AC
22777@end table
22778
22779@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 22780
8e04817f
AC
22781Obtain thread information from RTOS. Where: @var{startflag} (one hex
22782digit) is one to indicate the first query and zero to indicate a
22783subsequent query; @var{threadcount} (two hex digits) is the maximum
22784number of threads the response packet can contain; and @var{nextthread}
22785(eight hex digits), for subsequent queries (@var{startflag} is zero), is
22786returned in the response as @var{argthread}.
ee2d5c50
AC
22787
22788NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
22789(see above).
22790
22791Reply:
22792@table @samp
22793@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
22794Where: @var{count} (two hex digits) is the number of threads being
22795returned; @var{done} (one hex digit) is zero to indicate more threads
22796and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
22797digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
22798is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 22799digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 22800@end table
c906108c 22801
ee2d5c50 22802@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
9c16f35a
EZ
22803@cindex CRC of memory block, remote request
22804@cindex @code{qCRC} packet
ee2d5c50
AC
22805Reply:
22806@table @samp
22807@item @code{E}@var{NN}
22808An error (such as memory fault)
22809@item @code{C}@var{CRC32}
22810A 32 bit cyclic redundancy check of the specified memory region.
22811@end table
22812
22813@item @code{q}@code{Offsets} --- query sect offs
9c16f35a
EZ
22814@cindex section offsets, remote request
22815@cindex @code{qOffsets} packet
8e04817f
AC
22816Get section offsets that the target used when re-locating the downloaded
22817image. @emph{Note: while a @code{Bss} offset is included in the
22818response, @value{GDBN} ignores this and instead applies the @code{Data}
22819offset to the @code{Bss} section.}
c906108c 22820
ee2d5c50
AC
22821Reply:
22822@table @samp
22823@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
22824@end table
22825
22826@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
9c16f35a
EZ
22827@cindex thread information, remote request
22828@cindex @code{qP} packet
8e04817f
AC
22829Returns information on @var{threadid}. Where: @var{mode} is a hex
22830encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
22831
22832Reply:
22833@table @samp
22834@item *
22835@end table
22836
8e04817f 22837See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 22838
ee2d5c50 22839@item @code{q}@code{Rcmd,}@var{command} --- remote command
9c16f35a
EZ
22840@cindex execute remote command, remote request
22841@cindex @code{qRcmd} packet
ee2d5c50 22842@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
22843execution. Invalid commands should be reported using the output string.
22844Before the final result packet, the target may also respond with a
ee2d5c50
AC
22845number of intermediate @code{O}@var{output} console output packets.
22846@emph{Implementors should note that providing access to a stubs's
22847interpreter may have security implications}.
22848
22849Reply:
22850@table @samp
22851@item OK
8e04817f 22852A command response with no output.
ee2d5c50 22853@item @var{OUTPUT}
8e04817f 22854A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 22855@item @code{E}@var{NN}
8e04817f 22856Indicate a badly formed request.
ee2d5c50 22857@item @samp{}
8e04817f 22858When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50 22859@end table
9c16f35a 22860z
ee2d5c50 22861@item @code{qSymbol::} --- symbol lookup
9c16f35a
EZ
22862@cindex symbol lookup, remote request
22863@cindex @code{qSymbol} packet
8e04817f
AC
22864Notify the target that @value{GDBN} is prepared to serve symbol lookup
22865requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
22866
22867Reply:
22868@table @samp
22869@item @code{OK}
8e04817f 22870The target does not need to look up any (more) symbols.
ee2d5c50
AC
22871@item @code{qSymbol:}@var{sym_name}
22872The target requests the value of symbol @var{sym_name} (hex encoded).
22873@value{GDBN} may provide the value by using the
22874@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
22875@end table
22876
22877@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
22878
22879Set the value of @var{sym_name} to @var{sym_value}.
22880
22881@var{sym_name} (hex encoded) is the name of a symbol whose value the
22882target has previously requested.
22883
22884@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
22885@value{GDBN} cannot supply a value for @var{sym_name}, then this field
22886will be empty.
22887
22888Reply:
22889@table @samp
22890@item @code{OK}
8e04817f 22891The target does not need to look up any (more) symbols.
ee2d5c50
AC
22892@item @code{qSymbol:}@var{sym_name}
22893The target requests the value of a new symbol @var{sym_name} (hex
22894encoded). @value{GDBN} will continue to supply the values of symbols
22895(if available), until the target ceases to request them.
22896@end table
eb12ee30 22897
649e03f6 22898@item @code{qPart}:@var{object}:@code{read}:@var{annex}:@var{offset},@var{length} --- read special data
9c16f35a
EZ
22899@cindex read special object, remote request
22900@cindex @code{qPart} packet
649e03f6
RM
22901Read uninterpreted bytes from the target's special data area
22902identified by the keyword @code{object}.
22903Request @var{length} bytes starting at @var{offset} bytes into the data.
22904The content and encoding of @var{annex} is specific to the object;
22905it can supply additional details about what data to access.
22906
22907Here are the specific requests of this form defined so far.
22908All @samp{@code{qPart}:@var{object}:@code{read}:@dots{}}
22909requests use the same reply formats, listed below.
22910
22911@table @asis
22912@item @code{qPart}:@code{auxv}:@code{read}::@var{offset},@var{length}
721c2651
EZ
22913Access the target's @dfn{auxiliary vector}. @xref{OS Information,
22914auxiliary vector}, and see @ref{Remote configuration,
22915read-aux-vector-packet}. Note @var{annex} must be empty.
649e03f6
RM
22916@end table
22917
22918Reply:
22919@table @asis
22920@item @code{OK}
22921The @var{offset} in the request is at the end of the data.
22922There is no more data to be read.
22923
22924@item @var{XX@dots{}}
22925Hex encoded data bytes read.
22926This may be fewer bytes than the @var{length} in the request.
22927
22928@item @code{E00}
22929The request was malformed, or @var{annex} was invalid.
22930
22931@item @code{E}@var{nn}
22932The offset was invalid, or there was an error encountered reading the data.
22933@var{nn} is a hex-encoded @code{errno} value.
22934
22935@item @code{""} (empty)
22936An empty reply indicates the @var{object} or @var{annex} string was not
22937recognized by the stub.
22938@end table
22939
22940@item @code{qPart}:@var{object}:@code{write}:@var{annex}:@var{offset}:@var{data@dots{}}
9c16f35a 22941@cindex write data into object, remote request
649e03f6
RM
22942Write uninterpreted bytes into the target's special data area
22943identified by the keyword @code{object},
22944starting at @var{offset} bytes into the data.
22945@var{data@dots{}} is the hex-encoded data to be written.
22946The content and encoding of @var{annex} is specific to the object;
22947it can supply additional details about what data to access.
22948
22949No requests of this form are presently in use. This specification
22950serves as a placeholder to document the common format that new
22951specific request specifications ought to use.
22952
22953Reply:
22954@table @asis
22955@item @var{nn}
22956@var{nn} (hex encoded) is the number of bytes written.
22957This may be fewer bytes than supplied in the request.
22958
22959@item @code{E00}
22960The request was malformed, or @var{annex} was invalid.
22961
22962@item @code{E}@var{nn}
22963The offset was invalid, or there was an error encountered writing the data.
22964@var{nn} is a hex-encoded @code{errno} value.
22965
22966@item @code{""} (empty)
22967An empty reply indicates the @var{object} or @var{annex} string was not
22968recognized by the stub, or that the object does not support writing.
22969@end table
22970
22971@item @code{qPart}:@var{object}:@var{operation}:@dots{}
22972Requests of this form may be added in the future. When a stub does
22973not recognize the @var{object} keyword, or its support for
22974@var{object} does not recognize the @var{operation} keyword,
22975the stub must respond with an empty packet.
83761cbd
KB
22976
22977@item @code{qGetTLSAddr}:@var{thread-id},@var{offset},@var{lm} --- get thread local storage address
9c16f35a
EZ
22978@cindex get thread-local storage address, remote request
22979@cindex @code{qGetTLSAddr} packet
83761cbd
KB
22980Fetch the address associated with thread local storage specified
22981by @var{thread-id}, @var{offset}, and @var{lm}.
22982
22983@var{thread-id} is the (big endian, hex encoded) thread id associated with the
22984thread for which to fetch the TLS address.
22985
22986@var{offset} is the (big endian, hex encoded) offset associated with the
22987thread local variable. (This offset is obtained from the debug
22988information associated with the variable.)
22989
22990@var{lm} is the (big endian, hex encoded) OS/ABI specific encoding of the
22991the load module associated with the thread local storage. For example,
22992a @sc{gnu}/Linux system will pass the link map address of the shared
22993object associated with the thread local storage under consideration.
22994Other operating environments may choose to represent the load module
22995differently, so the precise meaning of this parameter will vary.
22996
22997Reply:
22998@table @asis
68c71a2e 22999@item @var{XX@dots{}}
83761cbd
KB
23000Hex encoded (big endian) bytes representing the address of the thread
23001local storage requested.
23002
23003@item @code{E}@var{nn} (where @var{nn} are hex digits)
23004An error occurred.
23005
23006@item @code{""} (empty)
23007An empty reply indicates that @code{qGetTLSAddr} is not supported by the stub.
23008@end table
23009
0abb7bc7
EZ
23010Use of this request packet is controlled by the @code{set remote
23011get-thread-local-storage-address} command (@pxref{Remote
23012configuration, set remote get-thread-local-storage-address}).
23013
ee2d5c50
AC
23014@end table
23015
23016@node Register Packet Format
23017@section Register Packet Format
eb12ee30 23018
8e04817f 23019The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
23020In the below, some thirty-two bit registers are transferred as
23021sixty-four bits. Those registers should be zero/sign extended (which?)
23022to fill the space allocated. Register bytes are transfered in target
23023byte order. The two nibbles within a register byte are transfered
23024most-significant - least-significant.
eb12ee30 23025
ee2d5c50 23026@table @r
eb12ee30 23027
8e04817f 23028@item MIPS32
ee2d5c50 23029
8e04817f
AC
23030All registers are transfered as thirty-two bit quantities in the order:
2303132 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
23032registers; fsr; fir; fp.
eb12ee30 23033
8e04817f 23034@item MIPS64
ee2d5c50 23035
8e04817f
AC
23036All registers are transfered as sixty-four bit quantities (including
23037thirty-two bit registers such as @code{sr}). The ordering is the same
23038as @code{MIPS32}.
eb12ee30 23039
ee2d5c50
AC
23040@end table
23041
23042@node Examples
23043@section Examples
eb12ee30 23044
8e04817f
AC
23045Example sequence of a target being re-started. Notice how the restart
23046does not get any direct output:
eb12ee30 23047
474c8240 23048@smallexample
d2c6833e
AC
23049-> @code{R00}
23050<- @code{+}
8e04817f 23051@emph{target restarts}
d2c6833e 23052-> @code{?}
8e04817f 23053<- @code{+}
d2c6833e
AC
23054<- @code{T001:1234123412341234}
23055-> @code{+}
474c8240 23056@end smallexample
eb12ee30 23057
8e04817f 23058Example sequence of a target being stepped by a single instruction:
eb12ee30 23059
474c8240 23060@smallexample
d2c6833e 23061-> @code{G1445@dots{}}
8e04817f 23062<- @code{+}
d2c6833e
AC
23063-> @code{s}
23064<- @code{+}
23065@emph{time passes}
23066<- @code{T001:1234123412341234}
8e04817f 23067-> @code{+}
d2c6833e 23068-> @code{g}
8e04817f 23069<- @code{+}
d2c6833e
AC
23070<- @code{1455@dots{}}
23071-> @code{+}
474c8240 23072@end smallexample
eb12ee30 23073
0ce1b118
CV
23074@node File-I/O remote protocol extension
23075@section File-I/O remote protocol extension
23076@cindex File-I/O remote protocol extension
23077
23078@menu
23079* File-I/O Overview::
23080* Protocol basics::
1d8b2f28
JB
23081* The F request packet::
23082* The F reply packet::
0ce1b118
CV
23083* Memory transfer::
23084* The Ctrl-C message::
23085* Console I/O::
23086* The isatty call::
23087* The system call::
23088* List of supported calls::
23089* Protocol specific representation of datatypes::
23090* Constants::
23091* File-I/O Examples::
23092@end menu
23093
23094@node File-I/O Overview
23095@subsection File-I/O Overview
23096@cindex file-i/o overview
23097
9c16f35a
EZ
23098The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
23099target to use the host's file system and console I/O when calling various
0ce1b118
CV
23100system calls. System calls on the target system are translated into a
23101remote protocol packet to the host system which then performs the needed
23102actions and returns with an adequate response packet to the target system.
23103This simulates file system operations even on targets that lack file systems.
23104
23105The protocol is defined host- and target-system independent. It uses
9c16f35a 23106its own independent representation of datatypes and values. Both,
0ce1b118
CV
23107@value{GDBN} and the target's @value{GDBN} stub are responsible for
23108translating the system dependent values into the unified protocol values
23109when data is transmitted.
23110
23111The communication is synchronous. A system call is possible only
23112when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
23113packets. While @value{GDBN} handles the request for a system call,
23114the target is stopped to allow deterministic access to the target's
23115memory. Therefore File-I/O is not interuptible by target signals. It
23116is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
23117
23118The target's request to perform a host system call does not finish
23119the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
23120after finishing the system call, the target returns to continuing the
23121previous activity (continue, step). No additional continue or step
23122request from @value{GDBN} is required.
23123
23124@smallexample
f7dc1244 23125(@value{GDBP}) continue
0ce1b118
CV
23126 <- target requests 'system call X'
23127 target is stopped, @value{GDBN} executes system call
23128 -> GDB returns result
23129 ... target continues, GDB returns to wait for the target
23130 <- target hits breakpoint and sends a Txx packet
23131@end smallexample
23132
23133The protocol is only used for files on the host file system and
23134for I/O on the console. Character or block special devices, pipes,
23135named pipes or sockets or any other communication method on the host
23136system are not supported by this protocol.
23137
23138@node Protocol basics
23139@subsection Protocol basics
23140@cindex protocol basics, file-i/o
23141
23142The File-I/O protocol uses the @code{F} packet, as request as well
23143as as reply packet. Since a File-I/O system call can only occur when
b383017d 23144@value{GDBN} is waiting for the continuing or stepping target, the
0ce1b118
CV
23145File-I/O request is a reply that @value{GDBN} has to expect as a result
23146of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
23147This @code{F} packet contains all information needed to allow @value{GDBN}
23148to call the appropriate host system call:
23149
23150@itemize @bullet
b383017d 23151@item
0ce1b118
CV
23152A unique identifier for the requested system call.
23153
23154@item
23155All parameters to the system call. Pointers are given as addresses
23156in the target memory address space. Pointers to strings are given as
b383017d 23157pointer/length pair. Numerical values are given as they are.
0ce1b118
CV
23158Numerical control values are given in a protocol specific representation.
23159
23160@end itemize
23161
23162At that point @value{GDBN} has to perform the following actions.
23163
23164@itemize @bullet
b383017d 23165@item
0ce1b118
CV
23166If parameter pointer values are given, which point to data needed as input
23167to a system call, @value{GDBN} requests this data from the target with a
23168standard @code{m} packet request. This additional communication has to be
23169expected by the target implementation and is handled as any other @code{m}
23170packet.
23171
23172@item
23173@value{GDBN} translates all value from protocol representation to host
23174representation as needed. Datatypes are coerced into the host types.
23175
23176@item
23177@value{GDBN} calls the system call
23178
23179@item
23180It then coerces datatypes back to protocol representation.
23181
23182@item
23183If pointer parameters in the request packet point to buffer space in which
23184a system call is expected to copy data to, the data is transmitted to the
23185target using a @code{M} or @code{X} packet. This packet has to be expected
23186by the target implementation and is handled as any other @code{M} or @code{X}
23187packet.
23188
23189@end itemize
23190
23191Eventually @value{GDBN} replies with another @code{F} packet which contains all
23192necessary information for the target to continue. This at least contains
23193
23194@itemize @bullet
23195@item
23196Return value.
23197
23198@item
23199@code{errno}, if has been changed by the system call.
23200
23201@item
23202``Ctrl-C'' flag.
23203
23204@end itemize
23205
23206After having done the needed type and value coercion, the target continues
23207the latest continue or step action.
23208
1d8b2f28 23209@node The F request packet
0ce1b118
CV
23210@subsection The @code{F} request packet
23211@cindex file-i/o request packet
23212@cindex @code{F} request packet
23213
23214The @code{F} request packet has the following format:
23215
23216@table @samp
23217
23218@smallexample
23219@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
23220@end smallexample
23221
23222@var{call-id} is the identifier to indicate the host system call to be called.
23223This is just the name of the function.
23224
23225@var{parameter@dots{}} are the parameters to the system call.
23226
b383017d 23227@end table
0ce1b118
CV
23228
23229Parameters are hexadecimal integer values, either the real values in case
23230of scalar datatypes, as pointers to target buffer space in case of compound
23231datatypes and unspecified memory areas or as pointer/length pairs in case
23232of string parameters. These are appended to the call-id, each separated
23233from its predecessor by a comma. All values are transmitted in ASCII
23234string representation, pointer/length pairs separated by a slash.
23235
1d8b2f28 23236@node The F reply packet
0ce1b118
CV
23237@subsection The @code{F} reply packet
23238@cindex file-i/o reply packet
23239@cindex @code{F} reply packet
23240
23241The @code{F} reply packet has the following format:
23242
23243@table @samp
23244
23245@smallexample
23246@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
23247@end smallexample
23248
23249@var{retcode} is the return code of the system call as hexadecimal value.
23250
23251@var{errno} is the errno set by the call, in protocol specific representation.
23252This parameter can be omitted if the call was successful.
23253
23254@var{Ctrl-C flag} is only send if the user requested a break. In this
23255case, @var{errno} must be send as well, even if the call was successful.
23256The @var{Ctrl-C flag} itself consists of the character 'C':
23257
23258@smallexample
23259F0,0,C
23260@end smallexample
23261
23262@noindent
23263or, if the call was interupted before the host call has been performed:
23264
23265@smallexample
23266F-1,4,C
23267@end smallexample
23268
23269@noindent
23270assuming 4 is the protocol specific representation of @code{EINTR}.
23271
23272@end table
23273
23274@node Memory transfer
23275@subsection Memory transfer
23276@cindex memory transfer, in file-i/o protocol
23277
23278Structured data which is transferred using a memory read or write as e.g.@:
23279a @code{struct stat} is expected to be in a protocol specific format with
23280all scalar multibyte datatypes being big endian. This should be done by
23281the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
23282it transfers memory to the target. Transferred pointers to structured
23283data should point to the already coerced data at any time.
23284
23285@node The Ctrl-C message
23286@subsection The Ctrl-C message
23287@cindex ctrl-c message, in file-i/o protocol
23288
23289A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
23290reply packet. In this case the target should behave, as if it had
23291gotten a break message. The meaning for the target is ``system call
23292interupted by @code{SIGINT}''. Consequentially, the target should actually stop
23293(as with a break message) and return to @value{GDBN} with a @code{T02}
b383017d 23294packet. In this case, it's important for the target to know, in which
0ce1b118
CV
23295state the system call was interrupted. Since this action is by design
23296not an atomic operation, we have to differ between two cases:
23297
23298@itemize @bullet
23299@item
23300The system call hasn't been performed on the host yet.
23301
23302@item
23303The system call on the host has been finished.
23304
23305@end itemize
23306
23307These two states can be distinguished by the target by the value of the
23308returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
23309call hasn't been performed. This is equivalent to the @code{EINTR} handling
23310on POSIX systems. In any other case, the target may presume that the
23311system call has been finished --- successful or not --- and should behave
23312as if the break message arrived right after the system call.
23313
23314@value{GDBN} must behave reliable. If the system call has not been called
23315yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
23316@code{errno} in the packet. If the system call on the host has been finished
23317before the user requests a break, the full action must be finshed by
23318@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
23319The @code{F} packet may only be send when either nothing has happened
23320or the full action has been completed.
23321
23322@node Console I/O
23323@subsection Console I/O
23324@cindex console i/o as part of file-i/o
23325
23326By default and if not explicitely closed by the target system, the file
23327descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
23328on the @value{GDBN} console is handled as any other file output operation
23329(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
23330by @value{GDBN} so that after the target read request from file descriptor
233310 all following typing is buffered until either one of the following
23332conditions is met:
23333
23334@itemize @bullet
23335@item
23336The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
23337@code{read}
23338system call is treated as finished.
23339
23340@item
23341The user presses @kbd{Enter}. This is treated as end of input with a trailing
23342line feed.
23343
23344@item
23345The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
23346character, especially no Ctrl-D is appended to the input.
23347
23348@end itemize
23349
23350If the user has typed more characters as fit in the buffer given to
23351the read call, the trailing characters are buffered in @value{GDBN} until
23352either another @code{read(0, @dots{})} is requested by the target or debugging
23353is stopped on users request.
23354
23355@node The isatty call
2eecc4ab 23356@subsection The @samp{isatty} function call
0ce1b118
CV
23357@cindex isatty call, file-i/o protocol
23358
23359A special case in this protocol is the library call @code{isatty} which
9c16f35a 23360is implemented as its own call inside of this protocol. It returns
0ce1b118
CV
233611 to the target if the file descriptor given as parameter is attached
23362to the @value{GDBN} console, 0 otherwise. Implementing through system calls
23363would require implementing @code{ioctl} and would be more complex than
23364needed.
23365
23366@node The system call
2eecc4ab 23367@subsection The @samp{system} function call
0ce1b118
CV
23368@cindex system call, file-i/o protocol
23369
23370The other special case in this protocol is the @code{system} call which
9c16f35a 23371is implemented as its own call, too. @value{GDBN} is taking over the full
0ce1b118
CV
23372task of calling the necessary host calls to perform the @code{system}
23373call. The return value of @code{system} is simplified before it's returned
23374to the target. Basically, the only signal transmitted back is @code{EINTR}
23375in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
23376entirely of the exit status of the called command.
23377
9c16f35a
EZ
23378Due to security concerns, the @code{system} call is by default refused
23379by @value{GDBN}. The user has to allow this call explicitly with the
23380@kbd{set remote system-call-allowed 1} command.
0ce1b118 23381
9c16f35a
EZ
23382@table @code
23383@item set remote system-call-allowed
23384@kindex set remote system-call-allowed
23385Control whether to allow the @code{system} calls in the File I/O
23386protocol for the remote target. The default is zero (disabled).
0ce1b118 23387
9c16f35a 23388@item show remote system-call-allowed
0ce1b118 23389@kindex show remote system-call-allowed
9c16f35a
EZ
23390Show the current setting of system calls for the remote File I/O
23391protocol.
0ce1b118
CV
23392@end table
23393
23394@node List of supported calls
23395@subsection List of supported calls
23396@cindex list of supported file-i/o calls
23397
23398@menu
23399* open::
23400* close::
23401* read::
23402* write::
23403* lseek::
23404* rename::
23405* unlink::
23406* stat/fstat::
23407* gettimeofday::
23408* isatty::
23409* system::
23410@end menu
23411
23412@node open
23413@unnumberedsubsubsec open
23414@cindex open, file-i/o system call
23415
23416@smallexample
23417@exdent Synopsis:
23418int open(const char *pathname, int flags);
23419int open(const char *pathname, int flags, mode_t mode);
23420
b383017d 23421@exdent Request:
0ce1b118
CV
23422Fopen,pathptr/len,flags,mode
23423@end smallexample
23424
23425@noindent
23426@code{flags} is the bitwise or of the following values:
23427
23428@table @code
b383017d 23429@item O_CREAT
0ce1b118
CV
23430If the file does not exist it will be created. The host
23431rules apply as far as file ownership and time stamps
23432are concerned.
23433
b383017d 23434@item O_EXCL
0ce1b118
CV
23435When used with O_CREAT, if the file already exists it is
23436an error and open() fails.
23437
b383017d 23438@item O_TRUNC
0ce1b118
CV
23439If the file already exists and the open mode allows
23440writing (O_RDWR or O_WRONLY is given) it will be
23441truncated to length 0.
23442
b383017d 23443@item O_APPEND
0ce1b118
CV
23444The file is opened in append mode.
23445
b383017d 23446@item O_RDONLY
0ce1b118
CV
23447The file is opened for reading only.
23448
b383017d 23449@item O_WRONLY
0ce1b118
CV
23450The file is opened for writing only.
23451
b383017d 23452@item O_RDWR
0ce1b118
CV
23453The file is opened for reading and writing.
23454
23455@noindent
23456Each other bit is silently ignored.
23457
23458@end table
23459
23460@noindent
23461@code{mode} is the bitwise or of the following values:
23462
23463@table @code
b383017d 23464@item S_IRUSR
0ce1b118
CV
23465User has read permission.
23466
b383017d 23467@item S_IWUSR
0ce1b118
CV
23468User has write permission.
23469
b383017d 23470@item S_IRGRP
0ce1b118
CV
23471Group has read permission.
23472
b383017d 23473@item S_IWGRP
0ce1b118
CV
23474Group has write permission.
23475
b383017d 23476@item S_IROTH
0ce1b118
CV
23477Others have read permission.
23478
b383017d 23479@item S_IWOTH
0ce1b118
CV
23480Others have write permission.
23481
23482@noindent
23483Each other bit is silently ignored.
23484
23485@end table
23486
23487@smallexample
23488@exdent Return value:
23489open returns the new file descriptor or -1 if an error
23490occured.
23491
23492@exdent Errors:
23493@end smallexample
23494
23495@table @code
b383017d 23496@item EEXIST
0ce1b118
CV
23497pathname already exists and O_CREAT and O_EXCL were used.
23498
b383017d 23499@item EISDIR
0ce1b118
CV
23500pathname refers to a directory.
23501
b383017d 23502@item EACCES
0ce1b118
CV
23503The requested access is not allowed.
23504
23505@item ENAMETOOLONG
23506pathname was too long.
23507
b383017d 23508@item ENOENT
0ce1b118
CV
23509A directory component in pathname does not exist.
23510
b383017d 23511@item ENODEV
0ce1b118
CV
23512pathname refers to a device, pipe, named pipe or socket.
23513
b383017d 23514@item EROFS
0ce1b118
CV
23515pathname refers to a file on a read-only filesystem and
23516write access was requested.
23517
b383017d 23518@item EFAULT
0ce1b118
CV
23519pathname is an invalid pointer value.
23520
b383017d 23521@item ENOSPC
0ce1b118
CV
23522No space on device to create the file.
23523
b383017d 23524@item EMFILE
0ce1b118
CV
23525The process already has the maximum number of files open.
23526
b383017d 23527@item ENFILE
0ce1b118
CV
23528The limit on the total number of files open on the system
23529has been reached.
23530
b383017d 23531@item EINTR
0ce1b118
CV
23532The call was interrupted by the user.
23533@end table
23534
23535@node close
23536@unnumberedsubsubsec close
23537@cindex close, file-i/o system call
23538
23539@smallexample
b383017d 23540@exdent Synopsis:
0ce1b118
CV
23541int close(int fd);
23542
b383017d 23543@exdent Request:
0ce1b118
CV
23544Fclose,fd
23545
23546@exdent Return value:
23547close returns zero on success, or -1 if an error occurred.
23548
23549@exdent Errors:
23550@end smallexample
23551
23552@table @code
b383017d 23553@item EBADF
0ce1b118
CV
23554fd isn't a valid open file descriptor.
23555
b383017d 23556@item EINTR
0ce1b118
CV
23557The call was interrupted by the user.
23558@end table
23559
23560@node read
23561@unnumberedsubsubsec read
23562@cindex read, file-i/o system call
23563
23564@smallexample
b383017d 23565@exdent Synopsis:
0ce1b118
CV
23566int read(int fd, void *buf, unsigned int count);
23567
b383017d 23568@exdent Request:
0ce1b118
CV
23569Fread,fd,bufptr,count
23570
23571@exdent Return value:
23572On success, the number of bytes read is returned.
23573Zero indicates end of file. If count is zero, read
b383017d 23574returns zero as well. On error, -1 is returned.
0ce1b118
CV
23575
23576@exdent Errors:
23577@end smallexample
23578
23579@table @code
b383017d 23580@item EBADF
0ce1b118
CV
23581fd is not a valid file descriptor or is not open for
23582reading.
23583
b383017d 23584@item EFAULT
0ce1b118
CV
23585buf is an invalid pointer value.
23586
b383017d 23587@item EINTR
0ce1b118
CV
23588The call was interrupted by the user.
23589@end table
23590
23591@node write
23592@unnumberedsubsubsec write
23593@cindex write, file-i/o system call
23594
23595@smallexample
b383017d 23596@exdent Synopsis:
0ce1b118
CV
23597int write(int fd, const void *buf, unsigned int count);
23598
b383017d 23599@exdent Request:
0ce1b118
CV
23600Fwrite,fd,bufptr,count
23601
23602@exdent Return value:
23603On success, the number of bytes written are returned.
23604Zero indicates nothing was written. On error, -1
23605is returned.
23606
23607@exdent Errors:
23608@end smallexample
23609
23610@table @code
b383017d 23611@item EBADF
0ce1b118
CV
23612fd is not a valid file descriptor or is not open for
23613writing.
23614
b383017d 23615@item EFAULT
0ce1b118
CV
23616buf is an invalid pointer value.
23617
b383017d 23618@item EFBIG
0ce1b118
CV
23619An attempt was made to write a file that exceeds the
23620host specific maximum file size allowed.
23621
b383017d 23622@item ENOSPC
0ce1b118
CV
23623No space on device to write the data.
23624
b383017d 23625@item EINTR
0ce1b118
CV
23626The call was interrupted by the user.
23627@end table
23628
23629@node lseek
23630@unnumberedsubsubsec lseek
23631@cindex lseek, file-i/o system call
23632
23633@smallexample
b383017d 23634@exdent Synopsis:
0ce1b118
CV
23635long lseek (int fd, long offset, int flag);
23636
b383017d 23637@exdent Request:
0ce1b118
CV
23638Flseek,fd,offset,flag
23639@end smallexample
23640
23641@code{flag} is one of:
23642
23643@table @code
b383017d 23644@item SEEK_SET
0ce1b118
CV
23645The offset is set to offset bytes.
23646
b383017d 23647@item SEEK_CUR
0ce1b118
CV
23648The offset is set to its current location plus offset
23649bytes.
23650
b383017d 23651@item SEEK_END
0ce1b118
CV
23652The offset is set to the size of the file plus offset
23653bytes.
23654@end table
23655
23656@smallexample
23657@exdent Return value:
23658On success, the resulting unsigned offset in bytes from
23659the beginning of the file is returned. Otherwise, a
23660value of -1 is returned.
23661
23662@exdent Errors:
23663@end smallexample
23664
23665@table @code
b383017d 23666@item EBADF
0ce1b118
CV
23667fd is not a valid open file descriptor.
23668
b383017d 23669@item ESPIPE
0ce1b118
CV
23670fd is associated with the @value{GDBN} console.
23671
b383017d 23672@item EINVAL
0ce1b118
CV
23673flag is not a proper value.
23674
b383017d 23675@item EINTR
0ce1b118
CV
23676The call was interrupted by the user.
23677@end table
23678
23679@node rename
23680@unnumberedsubsubsec rename
23681@cindex rename, file-i/o system call
23682
23683@smallexample
b383017d 23684@exdent Synopsis:
0ce1b118
CV
23685int rename(const char *oldpath, const char *newpath);
23686
b383017d 23687@exdent Request:
0ce1b118
CV
23688Frename,oldpathptr/len,newpathptr/len
23689
23690@exdent Return value:
23691On success, zero is returned. On error, -1 is returned.
23692
23693@exdent Errors:
23694@end smallexample
23695
23696@table @code
b383017d 23697@item EISDIR
0ce1b118
CV
23698newpath is an existing directory, but oldpath is not a
23699directory.
23700
b383017d 23701@item EEXIST
0ce1b118
CV
23702newpath is a non-empty directory.
23703
b383017d 23704@item EBUSY
0ce1b118
CV
23705oldpath or newpath is a directory that is in use by some
23706process.
23707
b383017d 23708@item EINVAL
0ce1b118
CV
23709An attempt was made to make a directory a subdirectory
23710of itself.
23711
b383017d 23712@item ENOTDIR
0ce1b118
CV
23713A component used as a directory in oldpath or new
23714path is not a directory. Or oldpath is a directory
23715and newpath exists but is not a directory.
23716
b383017d 23717@item EFAULT
0ce1b118
CV
23718oldpathptr or newpathptr are invalid pointer values.
23719
b383017d 23720@item EACCES
0ce1b118
CV
23721No access to the file or the path of the file.
23722
23723@item ENAMETOOLONG
b383017d 23724
0ce1b118
CV
23725oldpath or newpath was too long.
23726
b383017d 23727@item ENOENT
0ce1b118
CV
23728A directory component in oldpath or newpath does not exist.
23729
b383017d 23730@item EROFS
0ce1b118
CV
23731The file is on a read-only filesystem.
23732
b383017d 23733@item ENOSPC
0ce1b118
CV
23734The device containing the file has no room for the new
23735directory entry.
23736
b383017d 23737@item EINTR
0ce1b118
CV
23738The call was interrupted by the user.
23739@end table
23740
23741@node unlink
23742@unnumberedsubsubsec unlink
23743@cindex unlink, file-i/o system call
23744
23745@smallexample
b383017d 23746@exdent Synopsis:
0ce1b118
CV
23747int unlink(const char *pathname);
23748
b383017d 23749@exdent Request:
0ce1b118
CV
23750Funlink,pathnameptr/len
23751
23752@exdent Return value:
23753On success, zero is returned. On error, -1 is returned.
23754
23755@exdent Errors:
23756@end smallexample
23757
23758@table @code
b383017d 23759@item EACCES
0ce1b118
CV
23760No access to the file or the path of the file.
23761
b383017d 23762@item EPERM
0ce1b118
CV
23763The system does not allow unlinking of directories.
23764
b383017d 23765@item EBUSY
0ce1b118
CV
23766The file pathname cannot be unlinked because it's
23767being used by another process.
23768
b383017d 23769@item EFAULT
0ce1b118
CV
23770pathnameptr is an invalid pointer value.
23771
23772@item ENAMETOOLONG
23773pathname was too long.
23774
b383017d 23775@item ENOENT
0ce1b118
CV
23776A directory component in pathname does not exist.
23777
b383017d 23778@item ENOTDIR
0ce1b118
CV
23779A component of the path is not a directory.
23780
b383017d 23781@item EROFS
0ce1b118
CV
23782The file is on a read-only filesystem.
23783
b383017d 23784@item EINTR
0ce1b118
CV
23785The call was interrupted by the user.
23786@end table
23787
23788@node stat/fstat
23789@unnumberedsubsubsec stat/fstat
23790@cindex fstat, file-i/o system call
23791@cindex stat, file-i/o system call
23792
23793@smallexample
b383017d 23794@exdent Synopsis:
0ce1b118
CV
23795int stat(const char *pathname, struct stat *buf);
23796int fstat(int fd, struct stat *buf);
23797
b383017d 23798@exdent Request:
0ce1b118
CV
23799Fstat,pathnameptr/len,bufptr
23800Ffstat,fd,bufptr
23801
23802@exdent Return value:
23803On success, zero is returned. On error, -1 is returned.
23804
23805@exdent Errors:
23806@end smallexample
23807
23808@table @code
b383017d 23809@item EBADF
0ce1b118
CV
23810fd is not a valid open file.
23811
b383017d 23812@item ENOENT
0ce1b118
CV
23813A directory component in pathname does not exist or the
23814path is an empty string.
23815
b383017d 23816@item ENOTDIR
0ce1b118
CV
23817A component of the path is not a directory.
23818
b383017d 23819@item EFAULT
0ce1b118
CV
23820pathnameptr is an invalid pointer value.
23821
b383017d 23822@item EACCES
0ce1b118
CV
23823No access to the file or the path of the file.
23824
23825@item ENAMETOOLONG
23826pathname was too long.
23827
b383017d 23828@item EINTR
0ce1b118
CV
23829The call was interrupted by the user.
23830@end table
23831
23832@node gettimeofday
23833@unnumberedsubsubsec gettimeofday
23834@cindex gettimeofday, file-i/o system call
23835
23836@smallexample
b383017d 23837@exdent Synopsis:
0ce1b118
CV
23838int gettimeofday(struct timeval *tv, void *tz);
23839
b383017d 23840@exdent Request:
0ce1b118
CV
23841Fgettimeofday,tvptr,tzptr
23842
23843@exdent Return value:
23844On success, 0 is returned, -1 otherwise.
23845
23846@exdent Errors:
23847@end smallexample
23848
23849@table @code
b383017d 23850@item EINVAL
0ce1b118
CV
23851tz is a non-NULL pointer.
23852
b383017d 23853@item EFAULT
0ce1b118
CV
23854tvptr and/or tzptr is an invalid pointer value.
23855@end table
23856
23857@node isatty
23858@unnumberedsubsubsec isatty
23859@cindex isatty, file-i/o system call
23860
23861@smallexample
b383017d 23862@exdent Synopsis:
0ce1b118
CV
23863int isatty(int fd);
23864
b383017d 23865@exdent Request:
0ce1b118
CV
23866Fisatty,fd
23867
23868@exdent Return value:
23869Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
23870
23871@exdent Errors:
23872@end smallexample
23873
23874@table @code
b383017d 23875@item EINTR
0ce1b118
CV
23876The call was interrupted by the user.
23877@end table
23878
23879@node system
23880@unnumberedsubsubsec system
23881@cindex system, file-i/o system call
23882
23883@smallexample
b383017d 23884@exdent Synopsis:
0ce1b118
CV
23885int system(const char *command);
23886
b383017d 23887@exdent Request:
0ce1b118
CV
23888Fsystem,commandptr/len
23889
23890@exdent Return value:
23891The value returned is -1 on error and the return status
23892of the command otherwise. Only the exit status of the
23893command is returned, which is extracted from the hosts
23894system return value by calling WEXITSTATUS(retval).
23895In case /bin/sh could not be executed, 127 is returned.
23896
23897@exdent Errors:
23898@end smallexample
23899
23900@table @code
b383017d 23901@item EINTR
0ce1b118
CV
23902The call was interrupted by the user.
23903@end table
23904
23905@node Protocol specific representation of datatypes
23906@subsection Protocol specific representation of datatypes
23907@cindex protocol specific representation of datatypes, in file-i/o protocol
23908
23909@menu
23910* Integral datatypes::
23911* Pointer values::
23912* struct stat::
23913* struct timeval::
23914@end menu
23915
23916@node Integral datatypes
23917@unnumberedsubsubsec Integral datatypes
23918@cindex integral datatypes, in file-i/o protocol
23919
23920The integral datatypes used in the system calls are
23921
23922@smallexample
23923int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
23924@end smallexample
23925
23926@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
23927implemented as 32 bit values in this protocol.
23928
b383017d
RM
23929@code{Long} and @code{unsigned long} are implemented as 64 bit types.
23930
0ce1b118
CV
23931@xref{Limits}, for corresponding MIN and MAX values (similar to those
23932in @file{limits.h}) to allow range checking on host and target.
23933
23934@code{time_t} datatypes are defined as seconds since the Epoch.
23935
23936All integral datatypes transferred as part of a memory read or write of a
23937structured datatype e.g.@: a @code{struct stat} have to be given in big endian
23938byte order.
23939
23940@node Pointer values
23941@unnumberedsubsubsec Pointer values
23942@cindex pointer values, in file-i/o protocol
23943
23944Pointers to target data are transmitted as they are. An exception
23945is made for pointers to buffers for which the length isn't
23946transmitted as part of the function call, namely strings. Strings
23947are transmitted as a pointer/length pair, both as hex values, e.g.@:
23948
23949@smallexample
23950@code{1aaf/12}
23951@end smallexample
23952
23953@noindent
23954which is a pointer to data of length 18 bytes at position 0x1aaf.
23955The length is defined as the full string length in bytes, including
23956the trailing null byte. Example:
23957
23958@smallexample
23959``hello, world'' at address 0x123456
23960@end smallexample
23961
23962@noindent
23963is transmitted as
23964
23965@smallexample
23966@code{123456/d}
23967@end smallexample
23968
23969@node struct stat
23970@unnumberedsubsubsec struct stat
23971@cindex struct stat, in file-i/o protocol
23972
23973The buffer of type struct stat used by the target and @value{GDBN} is defined
23974as follows:
23975
23976@smallexample
23977struct stat @{
23978 unsigned int st_dev; /* device */
23979 unsigned int st_ino; /* inode */
23980 mode_t st_mode; /* protection */
23981 unsigned int st_nlink; /* number of hard links */
23982 unsigned int st_uid; /* user ID of owner */
23983 unsigned int st_gid; /* group ID of owner */
23984 unsigned int st_rdev; /* device type (if inode device) */
23985 unsigned long st_size; /* total size, in bytes */
23986 unsigned long st_blksize; /* blocksize for filesystem I/O */
23987 unsigned long st_blocks; /* number of blocks allocated */
23988 time_t st_atime; /* time of last access */
23989 time_t st_mtime; /* time of last modification */
23990 time_t st_ctime; /* time of last change */
23991@};
23992@end smallexample
23993
23994The integral datatypes are conforming to the definitions given in the
23995approriate section (see @ref{Integral datatypes}, for details) so this
23996structure is of size 64 bytes.
23997
23998The values of several fields have a restricted meaning and/or
23999range of values.
24000
24001@smallexample
24002st_dev: 0 file
24003 1 console
24004
24005st_ino: No valid meaning for the target. Transmitted unchanged.
24006
24007st_mode: Valid mode bits are described in Appendix C. Any other
24008 bits have currently no meaning for the target.
24009
24010st_uid: No valid meaning for the target. Transmitted unchanged.
24011
24012st_gid: No valid meaning for the target. Transmitted unchanged.
24013
24014st_rdev: No valid meaning for the target. Transmitted unchanged.
24015
24016st_atime, st_mtime, st_ctime:
24017 These values have a host and file system dependent
24018 accuracy. Especially on Windows hosts the file systems
24019 don't support exact timing values.
24020@end smallexample
24021
24022The target gets a struct stat of the above representation and is
24023responsible to coerce it to the target representation before
24024continuing.
24025
24026Note that due to size differences between the host and target
24027representation of stat members, these members could eventually
24028get truncated on the target.
24029
24030@node struct timeval
24031@unnumberedsubsubsec struct timeval
24032@cindex struct timeval, in file-i/o protocol
24033
24034The buffer of type struct timeval used by the target and @value{GDBN}
24035is defined as follows:
24036
24037@smallexample
b383017d 24038struct timeval @{
0ce1b118
CV
24039 time_t tv_sec; /* second */
24040 long tv_usec; /* microsecond */
24041@};
24042@end smallexample
24043
24044The integral datatypes are conforming to the definitions given in the
24045approriate section (see @ref{Integral datatypes}, for details) so this
24046structure is of size 8 bytes.
24047
24048@node Constants
24049@subsection Constants
24050@cindex constants, in file-i/o protocol
24051
24052The following values are used for the constants inside of the
24053protocol. @value{GDBN} and target are resposible to translate these
24054values before and after the call as needed.
24055
24056@menu
24057* Open flags::
24058* mode_t values::
24059* Errno values::
24060* Lseek flags::
24061* Limits::
24062@end menu
24063
24064@node Open flags
24065@unnumberedsubsubsec Open flags
24066@cindex open flags, in file-i/o protocol
24067
24068All values are given in hexadecimal representation.
24069
24070@smallexample
24071 O_RDONLY 0x0
24072 O_WRONLY 0x1
24073 O_RDWR 0x2
24074 O_APPEND 0x8
24075 O_CREAT 0x200
24076 O_TRUNC 0x400
24077 O_EXCL 0x800
24078@end smallexample
24079
24080@node mode_t values
24081@unnumberedsubsubsec mode_t values
24082@cindex mode_t values, in file-i/o protocol
24083
24084All values are given in octal representation.
24085
24086@smallexample
24087 S_IFREG 0100000
24088 S_IFDIR 040000
24089 S_IRUSR 0400
24090 S_IWUSR 0200
24091 S_IXUSR 0100
24092 S_IRGRP 040
24093 S_IWGRP 020
24094 S_IXGRP 010
24095 S_IROTH 04
24096 S_IWOTH 02
24097 S_IXOTH 01
24098@end smallexample
24099
24100@node Errno values
24101@unnumberedsubsubsec Errno values
24102@cindex errno values, in file-i/o protocol
24103
24104All values are given in decimal representation.
24105
24106@smallexample
24107 EPERM 1
24108 ENOENT 2
24109 EINTR 4
24110 EBADF 9
24111 EACCES 13
24112 EFAULT 14
24113 EBUSY 16
24114 EEXIST 17
24115 ENODEV 19
24116 ENOTDIR 20
24117 EISDIR 21
24118 EINVAL 22
24119 ENFILE 23
24120 EMFILE 24
24121 EFBIG 27
24122 ENOSPC 28
24123 ESPIPE 29
24124 EROFS 30
24125 ENAMETOOLONG 91
24126 EUNKNOWN 9999
24127@end smallexample
24128
24129 EUNKNOWN is used as a fallback error value if a host system returns
24130 any error value not in the list of supported error numbers.
24131
24132@node Lseek flags
24133@unnumberedsubsubsec Lseek flags
24134@cindex lseek flags, in file-i/o protocol
24135
24136@smallexample
24137 SEEK_SET 0
24138 SEEK_CUR 1
24139 SEEK_END 2
24140@end smallexample
24141
24142@node Limits
24143@unnumberedsubsubsec Limits
24144@cindex limits, in file-i/o protocol
24145
24146All values are given in decimal representation.
24147
24148@smallexample
24149 INT_MIN -2147483648
24150 INT_MAX 2147483647
24151 UINT_MAX 4294967295
24152 LONG_MIN -9223372036854775808
24153 LONG_MAX 9223372036854775807
24154 ULONG_MAX 18446744073709551615
24155@end smallexample
24156
24157@node File-I/O Examples
24158@subsection File-I/O Examples
24159@cindex file-i/o examples
24160
24161Example sequence of a write call, file descriptor 3, buffer is at target
24162address 0x1234, 6 bytes should be written:
24163
24164@smallexample
24165<- @code{Fwrite,3,1234,6}
24166@emph{request memory read from target}
24167-> @code{m1234,6}
24168<- XXXXXX
24169@emph{return "6 bytes written"}
24170-> @code{F6}
24171@end smallexample
24172
24173Example sequence of a read call, file descriptor 3, buffer is at target
24174address 0x1234, 6 bytes should be read:
24175
24176@smallexample
24177<- @code{Fread,3,1234,6}
24178@emph{request memory write to target}
24179-> @code{X1234,6:XXXXXX}
24180@emph{return "6 bytes read"}
24181-> @code{F6}
24182@end smallexample
24183
24184Example sequence of a read call, call fails on the host due to invalid
24185file descriptor (EBADF):
24186
24187@smallexample
24188<- @code{Fread,3,1234,6}
24189-> @code{F-1,9}
24190@end smallexample
24191
24192Example sequence of a read call, user presses Ctrl-C before syscall on
24193host is called:
24194
24195@smallexample
24196<- @code{Fread,3,1234,6}
24197-> @code{F-1,4,C}
24198<- @code{T02}
24199@end smallexample
24200
24201Example sequence of a read call, user presses Ctrl-C after syscall on
24202host is called:
24203
24204@smallexample
24205<- @code{Fread,3,1234,6}
24206-> @code{X1234,6:XXXXXX}
24207<- @code{T02}
24208@end smallexample
24209
f418dd93
DJ
24210@include agentexpr.texi
24211
aab4e0ec 24212@include gpl.texi
eb12ee30 24213
2154891a 24214@raisesections
6826cf00 24215@include fdl.texi
2154891a 24216@lowersections
6826cf00 24217
6d2ebf8b 24218@node Index
c906108c
SS
24219@unnumbered Index
24220
24221@printindex cp
24222
24223@tex
24224% I think something like @colophon should be in texinfo. In the
24225% meantime:
24226\long\def\colophon{\hbox to0pt{}\vfill
24227\centerline{The body of this manual is set in}
24228\centerline{\fontname\tenrm,}
24229\centerline{with headings in {\bf\fontname\tenbf}}
24230\centerline{and examples in {\tt\fontname\tentt}.}
24231\centerline{{\it\fontname\tenit\/},}
24232\centerline{{\bf\fontname\tenbf}, and}
24233\centerline{{\sl\fontname\tensl\/}}
24234\centerline{are used for emphasis.}\vfill}
24235\page\colophon
24236% Blame: doc@cygnus.com, 1991.
24237@end tex
24238
c906108c 24239@bye
This page took 2.272664 seconds and 4 git commands to generate.