(Files): Document the possibility of loading unlinked object files.
[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}.
1191@xref{History}, for more details about the command history and the
1192files where @value{GDBN} records it.
1193@end enumerate
1194
1195Init files use the same syntax as @dfn{command files} (@pxref{Command
1196Files}) and are processed by @value{GDBN} in the same way. The init
1197file in your home directory can set options (such as @samp{set
1198complaints}) that affect subsequent processing of command line options
1199and operands. Init files are not executed if you use the @samp{-nx}
1200option (@pxref{Mode Options, ,Choosing modes}).
1201
1202@cindex init file name
1203@cindex @file{.gdbinit}
119b882a 1204The @value{GDBN} init files are normally called @file{.gdbinit}.
6fc08d32
EZ
1205On some configurations of @value{GDBN}, the init file is known by a
1206different name (these are typically environments where a specialized
1207form of @value{GDBN} may need to coexist with other forms, hence a
1208different name for the specialized version's init file). These are the
1209environments with special init file names:
1210
6fc08d32 1211@itemize @bullet
119b882a
EZ
1212@cindex @file{gdb.ini}
1213@item
1214The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1215the limitations of file names imposed by DOS filesystems. The Windows
1216ports of @value{GDBN} use the standard name, but if they find a
1217@file{gdb.ini} file, they warn you about that and suggest to rename
1218the file to the standard name.
1219
1220@cindex @file{.vxgdbinit}
6fc08d32
EZ
1221@item
1222VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
1223
1224@cindex @file{.os68gdbinit}
1225@item
1226OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
1227
1228@cindex @file{.esgdbinit}
1229@item
1230ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
1231
1232@item
1233CISCO 68k: @file{.cisco-gdbinit}
1234@end itemize
1235
1236
6d2ebf8b 1237@node Quitting GDB
c906108c
SS
1238@section Quitting @value{GDBN}
1239@cindex exiting @value{GDBN}
1240@cindex leaving @value{GDBN}
1241
1242@table @code
1243@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1244@kindex q @r{(@code{quit})}
96a2c332
SS
1245@item quit @r{[}@var{expression}@r{]}
1246@itemx q
1247To exit @value{GDBN}, use the @code{quit} command (abbreviated
1248@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1249do not supply @var{expression}, @value{GDBN} will terminate normally;
1250otherwise it will terminate using the result of @var{expression} as the
1251error code.
c906108c
SS
1252@end table
1253
1254@cindex interrupt
1255An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1256terminates the action of any @value{GDBN} command that is in progress and
1257returns to @value{GDBN} command level. It is safe to type the interrupt
1258character at any time because @value{GDBN} does not allow it to take effect
1259until a time when it is safe.
1260
c906108c
SS
1261If you have been using @value{GDBN} to control an attached process or
1262device, you can release it with the @code{detach} command
1263(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1264
6d2ebf8b 1265@node Shell Commands
c906108c
SS
1266@section Shell commands
1267
1268If you need to execute occasional shell commands during your
1269debugging session, there is no need to leave or suspend @value{GDBN}; you can
1270just use the @code{shell} command.
1271
1272@table @code
1273@kindex shell
1274@cindex shell escape
1275@item shell @var{command string}
1276Invoke a standard shell to execute @var{command string}.
c906108c 1277If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1278shell to run. Otherwise @value{GDBN} uses the default shell
1279(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1280@end table
1281
1282The utility @code{make} is often needed in development environments.
1283You do not have to use the @code{shell} command for this purpose in
1284@value{GDBN}:
1285
1286@table @code
1287@kindex make
1288@cindex calling make
1289@item make @var{make-args}
1290Execute the @code{make} program with the specified
1291arguments. This is equivalent to @samp{shell make @var{make-args}}.
1292@end table
1293
0fac0b41
DJ
1294@node Logging output
1295@section Logging output
1296@cindex logging @value{GDBN} output
9c16f35a 1297@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1298
1299You may want to save the output of @value{GDBN} commands to a file.
1300There are several commands to control @value{GDBN}'s logging.
1301
1302@table @code
1303@kindex set logging
1304@item set logging on
1305Enable logging.
1306@item set logging off
1307Disable logging.
9c16f35a 1308@cindex logging file name
0fac0b41
DJ
1309@item set logging file @var{file}
1310Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1311@item set logging overwrite [on|off]
1312By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1313you want @code{set logging on} to overwrite the logfile instead.
1314@item set logging redirect [on|off]
1315By default, @value{GDBN} output will go to both the terminal and the logfile.
1316Set @code{redirect} if you want output to go only to the log file.
1317@kindex show logging
1318@item show logging
1319Show the current values of the logging settings.
1320@end table
1321
6d2ebf8b 1322@node Commands
c906108c
SS
1323@chapter @value{GDBN} Commands
1324
1325You can abbreviate a @value{GDBN} command to the first few letters of the command
1326name, if that abbreviation is unambiguous; and you can repeat certain
1327@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1328key to get @value{GDBN} to fill out the rest of a word in a command (or to
1329show you the alternatives available, if there is more than one possibility).
1330
1331@menu
1332* Command Syntax:: How to give commands to @value{GDBN}
1333* Completion:: Command completion
1334* Help:: How to ask @value{GDBN} for help
1335@end menu
1336
6d2ebf8b 1337@node Command Syntax
c906108c
SS
1338@section Command syntax
1339
1340A @value{GDBN} command is a single line of input. There is no limit on
1341how long it can be. It starts with a command name, which is followed by
1342arguments whose meaning depends on the command name. For example, the
1343command @code{step} accepts an argument which is the number of times to
1344step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1345with no arguments. Some commands do not allow any arguments.
c906108c
SS
1346
1347@cindex abbreviation
1348@value{GDBN} command names may always be truncated if that abbreviation is
1349unambiguous. Other possible command abbreviations are listed in the
1350documentation for individual commands. In some cases, even ambiguous
1351abbreviations are allowed; for example, @code{s} is specially defined as
1352equivalent to @code{step} even though there are other commands whose
1353names start with @code{s}. You can test abbreviations by using them as
1354arguments to the @code{help} command.
1355
1356@cindex repeating commands
41afff9a 1357@kindex RET @r{(repeat last command)}
c906108c 1358A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1359repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1360will not repeat this way; these are commands whose unintentional
1361repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1362repeat. User-defined commands can disable this feature; see
1363@ref{Define, dont-repeat}.
c906108c
SS
1364
1365The @code{list} and @code{x} commands, when you repeat them with
1366@key{RET}, construct new arguments rather than repeating
1367exactly as typed. This permits easy scanning of source or memory.
1368
1369@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1370output, in a way similar to the common utility @code{more}
1371(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1372@key{RET} too many in this situation, @value{GDBN} disables command
1373repetition after any command that generates this sort of display.
1374
41afff9a 1375@kindex # @r{(a comment)}
c906108c
SS
1376@cindex comment
1377Any text from a @kbd{#} to the end of the line is a comment; it does
1378nothing. This is useful mainly in command files (@pxref{Command
1379Files,,Command files}).
1380
88118b3a
TT
1381@cindex repeating command sequences
1382@kindex C-o @r{(operate-and-get-next)}
1383The @kbd{C-o} binding is useful for repeating a complex sequence of
1384commands. This command accepts the current line, like @kbd{RET}, and
1385then fetches the next line relative to the current line from the history
1386for editing.
1387
6d2ebf8b 1388@node Completion
c906108c
SS
1389@section Command completion
1390
1391@cindex completion
1392@cindex word completion
1393@value{GDBN} can fill in the rest of a word in a command for you, if there is
1394only one possibility; it can also show you what the valid possibilities
1395are for the next word in a command, at any time. This works for @value{GDBN}
1396commands, @value{GDBN} subcommands, and the names of symbols in your program.
1397
1398Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1399of a word. If there is only one possibility, @value{GDBN} fills in the
1400word, and waits for you to finish the command (or press @key{RET} to
1401enter it). For example, if you type
1402
1403@c FIXME "@key" does not distinguish its argument sufficiently to permit
1404@c complete accuracy in these examples; space introduced for clarity.
1405@c If texinfo enhancements make it unnecessary, it would be nice to
1406@c replace " @key" by "@key" in the following...
474c8240 1407@smallexample
c906108c 1408(@value{GDBP}) info bre @key{TAB}
474c8240 1409@end smallexample
c906108c
SS
1410
1411@noindent
1412@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1413the only @code{info} subcommand beginning with @samp{bre}:
1414
474c8240 1415@smallexample
c906108c 1416(@value{GDBP}) info breakpoints
474c8240 1417@end smallexample
c906108c
SS
1418
1419@noindent
1420You can either press @key{RET} at this point, to run the @code{info
1421breakpoints} command, or backspace and enter something else, if
1422@samp{breakpoints} does not look like the command you expected. (If you
1423were sure you wanted @code{info breakpoints} in the first place, you
1424might as well just type @key{RET} immediately after @samp{info bre},
1425to exploit command abbreviations rather than command completion).
1426
1427If there is more than one possibility for the next word when you press
1428@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1429characters and try again, or just press @key{TAB} a second time;
1430@value{GDBN} displays all the possible completions for that word. For
1431example, you might want to set a breakpoint on a subroutine whose name
1432begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1433just sounds the bell. Typing @key{TAB} again displays all the
1434function names in your program that begin with those characters, for
1435example:
1436
474c8240 1437@smallexample
c906108c
SS
1438(@value{GDBP}) b make_ @key{TAB}
1439@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1440make_a_section_from_file make_environ
1441make_abs_section make_function_type
1442make_blockvector make_pointer_type
1443make_cleanup make_reference_type
c906108c
SS
1444make_command make_symbol_completion_list
1445(@value{GDBP}) b make_
474c8240 1446@end smallexample
c906108c
SS
1447
1448@noindent
1449After displaying the available possibilities, @value{GDBN} copies your
1450partial input (@samp{b make_} in the example) so you can finish the
1451command.
1452
1453If you just want to see the list of alternatives in the first place, you
b37052ae 1454can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1455means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1456key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1457one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1458
1459@cindex quotes in commands
1460@cindex completion of quoted strings
1461Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1462parentheses or other characters that @value{GDBN} normally excludes from
1463its notion of a word. To permit word completion to work in this
1464situation, you may enclose words in @code{'} (single quote marks) in
1465@value{GDBN} commands.
c906108c 1466
c906108c 1467The most likely situation where you might need this is in typing the
b37052ae
EZ
1468name of a C@t{++} function. This is because C@t{++} allows function
1469overloading (multiple definitions of the same function, distinguished
1470by argument type). For example, when you want to set a breakpoint you
1471may need to distinguish whether you mean the version of @code{name}
1472that takes an @code{int} parameter, @code{name(int)}, or the version
1473that takes a @code{float} parameter, @code{name(float)}. To use the
1474word-completion facilities in this situation, type a single quote
1475@code{'} at the beginning of the function name. This alerts
1476@value{GDBN} that it may need to consider more information than usual
1477when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1478
474c8240 1479@smallexample
96a2c332 1480(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1481bubble(double,double) bubble(int,int)
1482(@value{GDBP}) b 'bubble(
474c8240 1483@end smallexample
c906108c
SS
1484
1485In some cases, @value{GDBN} can tell that completing a name requires using
1486quotes. When this happens, @value{GDBN} inserts the quote for you (while
1487completing as much as it can) if you do not type the quote in the first
1488place:
1489
474c8240 1490@smallexample
c906108c
SS
1491(@value{GDBP}) b bub @key{TAB}
1492@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1493(@value{GDBP}) b 'bubble(
474c8240 1494@end smallexample
c906108c
SS
1495
1496@noindent
1497In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1498you have not yet started typing the argument list when you ask for
1499completion on an overloaded symbol.
1500
d4f3574e 1501For more information about overloaded functions, see @ref{C plus plus
b37052ae 1502expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1503overload-resolution off} to disable overload resolution;
b37052ae 1504see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1505
1506
6d2ebf8b 1507@node Help
c906108c
SS
1508@section Getting help
1509@cindex online documentation
1510@kindex help
1511
5d161b24 1512You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1513using the command @code{help}.
1514
1515@table @code
41afff9a 1516@kindex h @r{(@code{help})}
c906108c
SS
1517@item help
1518@itemx h
1519You can use @code{help} (abbreviated @code{h}) with no arguments to
1520display a short list of named classes of commands:
1521
1522@smallexample
1523(@value{GDBP}) help
1524List of classes of commands:
1525
2df3850c 1526aliases -- Aliases of other commands
c906108c 1527breakpoints -- Making program stop at certain points
2df3850c 1528data -- Examining data
c906108c 1529files -- Specifying and examining files
2df3850c
JM
1530internals -- Maintenance commands
1531obscure -- Obscure features
1532running -- Running the program
1533stack -- Examining the stack
c906108c
SS
1534status -- Status inquiries
1535support -- Support facilities
96a2c332
SS
1536tracepoints -- Tracing of program execution without@*
1537 stopping the program
c906108c 1538user-defined -- User-defined commands
c906108c 1539
5d161b24 1540Type "help" followed by a class name for a list of
c906108c 1541commands in that class.
5d161b24 1542Type "help" followed by command name for full
c906108c
SS
1543documentation.
1544Command name abbreviations are allowed if unambiguous.
1545(@value{GDBP})
1546@end smallexample
96a2c332 1547@c the above line break eliminates huge line overfull...
c906108c
SS
1548
1549@item help @var{class}
1550Using one of the general help classes as an argument, you can get a
1551list of the individual commands in that class. For example, here is the
1552help display for the class @code{status}:
1553
1554@smallexample
1555(@value{GDBP}) help status
1556Status inquiries.
1557
1558List of commands:
1559
1560@c Line break in "show" line falsifies real output, but needed
1561@c to fit in smallbook page size.
2df3850c
JM
1562info -- Generic command for showing things
1563 about the program being debugged
1564show -- Generic command for showing things
1565 about the debugger
c906108c 1566
5d161b24 1567Type "help" followed by command name for full
c906108c
SS
1568documentation.
1569Command name abbreviations are allowed if unambiguous.
1570(@value{GDBP})
1571@end smallexample
1572
1573@item help @var{command}
1574With a command name as @code{help} argument, @value{GDBN} displays a
1575short paragraph on how to use that command.
1576
6837a0a2
DB
1577@kindex apropos
1578@item apropos @var{args}
09d4efe1 1579The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2
DB
1580commands, and their documentation, for the regular expression specified in
1581@var{args}. It prints out all matches found. For example:
1582
1583@smallexample
1584apropos reload
1585@end smallexample
1586
b37052ae
EZ
1587@noindent
1588results in:
6837a0a2
DB
1589
1590@smallexample
6d2ebf8b
SS
1591@c @group
1592set symbol-reloading -- Set dynamic symbol table reloading
1593 multiple times in one run
1594show symbol-reloading -- Show dynamic symbol table reloading
1595 multiple times in one run
1596@c @end group
6837a0a2
DB
1597@end smallexample
1598
c906108c
SS
1599@kindex complete
1600@item complete @var{args}
1601The @code{complete @var{args}} command lists all the possible completions
1602for the beginning of a command. Use @var{args} to specify the beginning of the
1603command you want completed. For example:
1604
1605@smallexample
1606complete i
1607@end smallexample
1608
1609@noindent results in:
1610
1611@smallexample
1612@group
2df3850c
JM
1613if
1614ignore
c906108c
SS
1615info
1616inspect
c906108c
SS
1617@end group
1618@end smallexample
1619
1620@noindent This is intended for use by @sc{gnu} Emacs.
1621@end table
1622
1623In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1624and @code{show} to inquire about the state of your program, or the state
1625of @value{GDBN} itself. Each command supports many topics of inquiry; this
1626manual introduces each of them in the appropriate context. The listings
1627under @code{info} and under @code{show} in the Index point to
1628all the sub-commands. @xref{Index}.
1629
1630@c @group
1631@table @code
1632@kindex info
41afff9a 1633@kindex i @r{(@code{info})}
c906108c
SS
1634@item info
1635This command (abbreviated @code{i}) is for describing the state of your
1636program. For example, you can list the arguments given to your program
1637with @code{info args}, list the registers currently in use with @code{info
1638registers}, or list the breakpoints you have set with @code{info breakpoints}.
1639You can get a complete list of the @code{info} sub-commands with
1640@w{@code{help info}}.
1641
1642@kindex set
1643@item set
5d161b24 1644You can assign the result of an expression to an environment variable with
c906108c
SS
1645@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1646@code{set prompt $}.
1647
1648@kindex show
1649@item show
5d161b24 1650In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1651@value{GDBN} itself.
1652You can change most of the things you can @code{show}, by using the
1653related command @code{set}; for example, you can control what number
1654system is used for displays with @code{set radix}, or simply inquire
1655which is currently in use with @code{show radix}.
1656
1657@kindex info set
1658To display all the settable parameters and their current
1659values, you can use @code{show} with no arguments; you may also use
1660@code{info set}. Both commands produce the same display.
1661@c FIXME: "info set" violates the rule that "info" is for state of
1662@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1663@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1664@end table
1665@c @end group
1666
1667Here are three miscellaneous @code{show} subcommands, all of which are
1668exceptional in lacking corresponding @code{set} commands:
1669
1670@table @code
1671@kindex show version
9c16f35a 1672@cindex @value{GDBN} version number
c906108c
SS
1673@item show version
1674Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1675information in @value{GDBN} bug-reports. If multiple versions of
1676@value{GDBN} are in use at your site, you may need to determine which
1677version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1678commands are introduced, and old ones may wither away. Also, many
1679system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1680variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1681The version number is the same as the one announced when you start
1682@value{GDBN}.
c906108c
SS
1683
1684@kindex show copying
09d4efe1 1685@kindex info copying
9c16f35a 1686@cindex display @value{GDBN} copyright
c906108c 1687@item show copying
09d4efe1 1688@itemx info copying
c906108c
SS
1689Display information about permission for copying @value{GDBN}.
1690
1691@kindex show warranty
09d4efe1 1692@kindex info warranty
c906108c 1693@item show warranty
09d4efe1 1694@itemx info warranty
2df3850c 1695Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1696if your version of @value{GDBN} comes with one.
2df3850c 1697
c906108c
SS
1698@end table
1699
6d2ebf8b 1700@node Running
c906108c
SS
1701@chapter Running Programs Under @value{GDBN}
1702
1703When you run a program under @value{GDBN}, you must first generate
1704debugging information when you compile it.
7a292a7a
SS
1705
1706You may start @value{GDBN} with its arguments, if any, in an environment
1707of your choice. If you are doing native debugging, you may redirect
1708your program's input and output, debug an already running process, or
1709kill a child process.
c906108c
SS
1710
1711@menu
1712* Compilation:: Compiling for debugging
1713* Starting:: Starting your program
c906108c
SS
1714* Arguments:: Your program's arguments
1715* Environment:: Your program's environment
c906108c
SS
1716
1717* Working Directory:: Your program's working directory
1718* Input/Output:: Your program's input and output
1719* Attach:: Debugging an already-running process
1720* Kill Process:: Killing the child process
c906108c
SS
1721
1722* Threads:: Debugging programs with multiple threads
1723* Processes:: Debugging programs with multiple processes
1724@end menu
1725
6d2ebf8b 1726@node Compilation
c906108c
SS
1727@section Compiling for debugging
1728
1729In order to debug a program effectively, you need to generate
1730debugging information when you compile it. This debugging information
1731is stored in the object file; it describes the data type of each
1732variable or function and the correspondence between source line numbers
1733and addresses in the executable code.
1734
1735To request debugging information, specify the @samp{-g} option when you run
1736the compiler.
1737
514c4d71
EZ
1738Programs that are to be shipped to your customers are compiled with
1739optimizations, using the @samp{-O} compiler option. However, many
1740compilers are unable to handle the @samp{-g} and @samp{-O} options
1741together. Using those compilers, you cannot generate optimized
c906108c
SS
1742executables containing debugging information.
1743
514c4d71 1744@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1745without @samp{-O}, making it possible to debug optimized code. We
1746recommend that you @emph{always} use @samp{-g} whenever you compile a
1747program. You may think your program is correct, but there is no sense
1748in pushing your luck.
c906108c
SS
1749
1750@cindex optimized code, debugging
1751@cindex debugging optimized code
1752When you debug a program compiled with @samp{-g -O}, remember that the
1753optimizer is rearranging your code; the debugger shows you what is
1754really there. Do not be too surprised when the execution path does not
1755exactly match your source file! An extreme example: if you define a
1756variable, but never use it, @value{GDBN} never sees that
1757variable---because the compiler optimizes it out of existence.
1758
1759Some things do not work as well with @samp{-g -O} as with just
1760@samp{-g}, particularly on machines with instruction scheduling. If in
1761doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1762please report it to us as a bug (including a test case!).
15387254 1763@xref{Variables}, for more information about debugging optimized code.
c906108c
SS
1764
1765Older versions of the @sc{gnu} C compiler permitted a variant option
1766@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1767format; if your @sc{gnu} C compiler has this option, do not use it.
1768
514c4d71
EZ
1769@value{GDBN} knows about preprocessor macros and can show you their
1770expansion (@pxref{Macros}). Most compilers do not include information
1771about preprocessor macros in the debugging information if you specify
1772the @option{-g} flag alone, because this information is rather large.
1773Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1774provides macro information if you specify the options
1775@option{-gdwarf-2} and @option{-g3}; the former option requests
1776debugging information in the Dwarf 2 format, and the latter requests
1777``extra information''. In the future, we hope to find more compact
1778ways to represent macro information, so that it can be included with
1779@option{-g} alone.
1780
c906108c 1781@need 2000
6d2ebf8b 1782@node Starting
c906108c
SS
1783@section Starting your program
1784@cindex starting
1785@cindex running
1786
1787@table @code
1788@kindex run
41afff9a 1789@kindex r @r{(@code{run})}
c906108c
SS
1790@item run
1791@itemx r
7a292a7a
SS
1792Use the @code{run} command to start your program under @value{GDBN}.
1793You must first specify the program name (except on VxWorks) with an
1794argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1795@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1796(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1797
1798@end table
1799
c906108c
SS
1800If you are running your program in an execution environment that
1801supports processes, @code{run} creates an inferior process and makes
1802that process run your program. (In environments without processes,
1803@code{run} jumps to the start of your program.)
1804
1805The execution of a program is affected by certain information it
1806receives from its superior. @value{GDBN} provides ways to specify this
1807information, which you must do @emph{before} starting your program. (You
1808can change it after starting your program, but such changes only affect
1809your program the next time you start it.) This information may be
1810divided into four categories:
1811
1812@table @asis
1813@item The @emph{arguments.}
1814Specify the arguments to give your program as the arguments of the
1815@code{run} command. If a shell is available on your target, the shell
1816is used to pass the arguments, so that you may use normal conventions
1817(such as wildcard expansion or variable substitution) in describing
1818the arguments.
1819In Unix systems, you can control which shell is used with the
1820@code{SHELL} environment variable.
1821@xref{Arguments, ,Your program's arguments}.
1822
1823@item The @emph{environment.}
1824Your program normally inherits its environment from @value{GDBN}, but you can
1825use the @value{GDBN} commands @code{set environment} and @code{unset
1826environment} to change parts of the environment that affect
1827your program. @xref{Environment, ,Your program's environment}.
1828
1829@item The @emph{working directory.}
1830Your program inherits its working directory from @value{GDBN}. You can set
1831the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1832@xref{Working Directory, ,Your program's working directory}.
1833
1834@item The @emph{standard input and output.}
1835Your program normally uses the same device for standard input and
1836standard output as @value{GDBN} is using. You can redirect input and output
1837in the @code{run} command line, or you can use the @code{tty} command to
1838set a different device for your program.
1839@xref{Input/Output, ,Your program's input and output}.
1840
1841@cindex pipes
1842@emph{Warning:} While input and output redirection work, you cannot use
1843pipes to pass the output of the program you are debugging to another
1844program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1845wrong program.
1846@end table
c906108c
SS
1847
1848When you issue the @code{run} command, your program begins to execute
1849immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1850of how to arrange for your program to stop. Once your program has
1851stopped, you may call functions in your program, using the @code{print}
1852or @code{call} commands. @xref{Data, ,Examining Data}.
1853
1854If the modification time of your symbol file has changed since the last
1855time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1856table, and reads it again. When it does this, @value{GDBN} tries to retain
1857your current breakpoints.
1858
4e8b0763
JB
1859@table @code
1860@kindex start
1861@item start
1862@cindex run to main procedure
1863The name of the main procedure can vary from language to language.
1864With C or C@t{++}, the main procedure name is always @code{main}, but
1865other languages such as Ada do not require a specific name for their
1866main procedure. The debugger provides a convenient way to start the
1867execution of the program and to stop at the beginning of the main
1868procedure, depending on the language used.
1869
1870The @samp{start} command does the equivalent of setting a temporary
1871breakpoint at the beginning of the main procedure and then invoking
1872the @samp{run} command.
1873
f018e82f
EZ
1874@cindex elaboration phase
1875Some programs contain an @dfn{elaboration} phase where some startup code is
1876executed before the main procedure is called. This depends on the
1877languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1878constructors for static and global objects are executed before
1879@code{main} is called. It is therefore possible that the debugger stops
1880before reaching the main procedure. However, the temporary breakpoint
1881will remain to halt execution.
1882
1883Specify the arguments to give to your program as arguments to the
1884@samp{start} command. These arguments will be given verbatim to the
1885underlying @samp{run} command. Note that the same arguments will be
1886reused if no argument is provided during subsequent calls to
1887@samp{start} or @samp{run}.
1888
1889It is sometimes necessary to debug the program during elaboration. In
1890these cases, using the @code{start} command would stop the execution of
1891your program too late, as the program would have already completed the
1892elaboration phase. Under these circumstances, insert breakpoints in your
1893elaboration code before running your program.
1894@end table
1895
6d2ebf8b 1896@node Arguments
c906108c
SS
1897@section Your program's arguments
1898
1899@cindex arguments (to your program)
1900The arguments to your program can be specified by the arguments of the
5d161b24 1901@code{run} command.
c906108c
SS
1902They are passed to a shell, which expands wildcard characters and
1903performs redirection of I/O, and thence to your program. Your
1904@code{SHELL} environment variable (if it exists) specifies what shell
1905@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1906the default shell (@file{/bin/sh} on Unix).
1907
1908On non-Unix systems, the program is usually invoked directly by
1909@value{GDBN}, which emulates I/O redirection via the appropriate system
1910calls, and the wildcard characters are expanded by the startup code of
1911the program, not by the shell.
c906108c
SS
1912
1913@code{run} with no arguments uses the same arguments used by the previous
1914@code{run}, or those set by the @code{set args} command.
1915
c906108c 1916@table @code
41afff9a 1917@kindex set args
c906108c
SS
1918@item set args
1919Specify the arguments to be used the next time your program is run. If
1920@code{set args} has no arguments, @code{run} executes your program
1921with no arguments. Once you have run your program with arguments,
1922using @code{set args} before the next @code{run} is the only way to run
1923it again without arguments.
1924
1925@kindex show args
1926@item show args
1927Show the arguments to give your program when it is started.
1928@end table
1929
6d2ebf8b 1930@node Environment
c906108c
SS
1931@section Your program's environment
1932
1933@cindex environment (of your program)
1934The @dfn{environment} consists of a set of environment variables and
1935their values. Environment variables conventionally record such things as
1936your user name, your home directory, your terminal type, and your search
1937path for programs to run. Usually you set up environment variables with
1938the shell and they are inherited by all the other programs you run. When
1939debugging, it can be useful to try running your program with a modified
1940environment without having to start @value{GDBN} over again.
1941
1942@table @code
1943@kindex path
1944@item path @var{directory}
1945Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1946(the search path for executables) that will be passed to your program.
1947The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1948You may specify several directory names, separated by whitespace or by a
1949system-dependent separator character (@samp{:} on Unix, @samp{;} on
1950MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1951is moved to the front, so it is searched sooner.
c906108c
SS
1952
1953You can use the string @samp{$cwd} to refer to whatever is the current
1954working directory at the time @value{GDBN} searches the path. If you
1955use @samp{.} instead, it refers to the directory where you executed the
1956@code{path} command. @value{GDBN} replaces @samp{.} in the
1957@var{directory} argument (with the current path) before adding
1958@var{directory} to the search path.
1959@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1960@c document that, since repeating it would be a no-op.
1961
1962@kindex show paths
1963@item show paths
1964Display the list of search paths for executables (the @code{PATH}
1965environment variable).
1966
1967@kindex show environment
1968@item show environment @r{[}@var{varname}@r{]}
1969Print the value of environment variable @var{varname} to be given to
1970your program when it starts. If you do not supply @var{varname},
1971print the names and values of all environment variables to be given to
1972your program. You can abbreviate @code{environment} as @code{env}.
1973
1974@kindex set environment
53a5351d 1975@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1976Set environment variable @var{varname} to @var{value}. The value
1977changes for your program only, not for @value{GDBN} itself. @var{value} may
1978be any string; the values of environment variables are just strings, and
1979any interpretation is supplied by your program itself. The @var{value}
1980parameter is optional; if it is eliminated, the variable is set to a
1981null value.
1982@c "any string" here does not include leading, trailing
1983@c blanks. Gnu asks: does anyone care?
1984
1985For example, this command:
1986
474c8240 1987@smallexample
c906108c 1988set env USER = foo
474c8240 1989@end smallexample
c906108c
SS
1990
1991@noindent
d4f3574e 1992tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1993@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1994are not actually required.)
1995
1996@kindex unset environment
1997@item unset environment @var{varname}
1998Remove variable @var{varname} from the environment to be passed to your
1999program. This is different from @samp{set env @var{varname} =};
2000@code{unset environment} removes the variable from the environment,
2001rather than assigning it an empty value.
2002@end table
2003
d4f3574e
SS
2004@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2005the shell indicated
c906108c
SS
2006by your @code{SHELL} environment variable if it exists (or
2007@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2008that runs an initialization file---such as @file{.cshrc} for C-shell, or
2009@file{.bashrc} for BASH---any variables you set in that file affect
2010your program. You may wish to move setting of environment variables to
2011files that are only run when you sign on, such as @file{.login} or
2012@file{.profile}.
2013
6d2ebf8b 2014@node Working Directory
c906108c
SS
2015@section Your program's working directory
2016
2017@cindex working directory (of your program)
2018Each time you start your program with @code{run}, it inherits its
2019working directory from the current working directory of @value{GDBN}.
2020The @value{GDBN} working directory is initially whatever it inherited
2021from its parent process (typically the shell), but you can specify a new
2022working directory in @value{GDBN} with the @code{cd} command.
2023
2024The @value{GDBN} working directory also serves as a default for the commands
2025that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
2026specify files}.
2027
2028@table @code
2029@kindex cd
721c2651 2030@cindex change working directory
c906108c
SS
2031@item cd @var{directory}
2032Set the @value{GDBN} working directory to @var{directory}.
2033
2034@kindex pwd
2035@item pwd
2036Print the @value{GDBN} working directory.
2037@end table
2038
60bf7e09
EZ
2039It is generally impossible to find the current working directory of
2040the process being debugged (since a program can change its directory
2041during its run). If you work on a system where @value{GDBN} is
2042configured with the @file{/proc} support, you can use the @code{info
2043proc} command (@pxref{SVR4 Process Information}) to find out the
2044current working directory of the debuggee.
2045
6d2ebf8b 2046@node Input/Output
c906108c
SS
2047@section Your program's input and output
2048
2049@cindex redirection
2050@cindex i/o
2051@cindex terminal
2052By default, the program you run under @value{GDBN} does input and output to
5d161b24 2053the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2054to its own terminal modes to interact with you, but it records the terminal
2055modes your program was using and switches back to them when you continue
2056running your program.
2057
2058@table @code
2059@kindex info terminal
2060@item info terminal
2061Displays information recorded by @value{GDBN} about the terminal modes your
2062program is using.
2063@end table
2064
2065You can redirect your program's input and/or output using shell
2066redirection with the @code{run} command. For example,
2067
474c8240 2068@smallexample
c906108c 2069run > outfile
474c8240 2070@end smallexample
c906108c
SS
2071
2072@noindent
2073starts your program, diverting its output to the file @file{outfile}.
2074
2075@kindex tty
2076@cindex controlling terminal
2077Another way to specify where your program should do input and output is
2078with the @code{tty} command. This command accepts a file name as
2079argument, and causes this file to be the default for future @code{run}
2080commands. It also resets the controlling terminal for the child
2081process, for future @code{run} commands. For example,
2082
474c8240 2083@smallexample
c906108c 2084tty /dev/ttyb
474c8240 2085@end smallexample
c906108c
SS
2086
2087@noindent
2088directs that processes started with subsequent @code{run} commands
2089default to do input and output on the terminal @file{/dev/ttyb} and have
2090that as their controlling terminal.
2091
2092An explicit redirection in @code{run} overrides the @code{tty} command's
2093effect on the input/output device, but not its effect on the controlling
2094terminal.
2095
2096When you use the @code{tty} command or redirect input in the @code{run}
2097command, only the input @emph{for your program} is affected. The input
2098for @value{GDBN} still comes from your terminal.
2099
6d2ebf8b 2100@node Attach
c906108c
SS
2101@section Debugging an already-running process
2102@kindex attach
2103@cindex attach
2104
2105@table @code
2106@item attach @var{process-id}
2107This command attaches to a running process---one that was started
2108outside @value{GDBN}. (@code{info files} shows your active
2109targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2110find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2111or with the @samp{jobs -l} shell command.
2112
2113@code{attach} does not repeat if you press @key{RET} a second time after
2114executing the command.
2115@end table
2116
2117To use @code{attach}, your program must be running in an environment
2118which supports processes; for example, @code{attach} does not work for
2119programs on bare-board targets that lack an operating system. You must
2120also have permission to send the process a signal.
2121
2122When you use @code{attach}, the debugger finds the program running in
2123the process first by looking in the current working directory, then (if
2124the program is not found) by using the source file search path
2125(@pxref{Source Path, ,Specifying source directories}). You can also use
2126the @code{file} command to load the program. @xref{Files, ,Commands to
2127Specify Files}.
2128
2129The first thing @value{GDBN} does after arranging to debug the specified
2130process is to stop it. You can examine and modify an attached process
53a5351d
JM
2131with all the @value{GDBN} commands that are ordinarily available when
2132you start processes with @code{run}. You can insert breakpoints; you
2133can step and continue; you can modify storage. If you would rather the
2134process continue running, you may use the @code{continue} command after
c906108c
SS
2135attaching @value{GDBN} to the process.
2136
2137@table @code
2138@kindex detach
2139@item detach
2140When you have finished debugging the attached process, you can use the
2141@code{detach} command to release it from @value{GDBN} control. Detaching
2142the process continues its execution. After the @code{detach} command,
2143that process and @value{GDBN} become completely independent once more, and you
2144are ready to @code{attach} another process or start one with @code{run}.
2145@code{detach} does not repeat if you press @key{RET} again after
2146executing the command.
2147@end table
2148
2149If you exit @value{GDBN} or use the @code{run} command while you have an
2150attached process, you kill that process. By default, @value{GDBN} asks
2151for confirmation if you try to do either of these things; you can
2152control whether or not you need to confirm by using the @code{set
2153confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2154messages}).
2155
6d2ebf8b 2156@node Kill Process
c906108c 2157@section Killing the child process
c906108c
SS
2158
2159@table @code
2160@kindex kill
2161@item kill
2162Kill the child process in which your program is running under @value{GDBN}.
2163@end table
2164
2165This command is useful if you wish to debug a core dump instead of a
2166running process. @value{GDBN} ignores any core dump file while your program
2167is running.
2168
2169On some operating systems, a program cannot be executed outside @value{GDBN}
2170while you have breakpoints set on it inside @value{GDBN}. You can use the
2171@code{kill} command in this situation to permit running your program
2172outside the debugger.
2173
2174The @code{kill} command is also useful if you wish to recompile and
2175relink your program, since on many systems it is impossible to modify an
2176executable file while it is running in a process. In this case, when you
2177next type @code{run}, @value{GDBN} notices that the file has changed, and
2178reads the symbol table again (while trying to preserve your current
2179breakpoint settings).
2180
6d2ebf8b 2181@node Threads
c906108c 2182@section Debugging programs with multiple threads
c906108c
SS
2183
2184@cindex threads of execution
2185@cindex multiple threads
2186@cindex switching threads
2187In some operating systems, such as HP-UX and Solaris, a single program
2188may have more than one @dfn{thread} of execution. The precise semantics
2189of threads differ from one operating system to another, but in general
2190the threads of a single program are akin to multiple processes---except
2191that they share one address space (that is, they can all examine and
2192modify the same variables). On the other hand, each thread has its own
2193registers and execution stack, and perhaps private memory.
2194
2195@value{GDBN} provides these facilities for debugging multi-thread
2196programs:
2197
2198@itemize @bullet
2199@item automatic notification of new threads
2200@item @samp{thread @var{threadno}}, a command to switch among threads
2201@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2202@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2203a command to apply a command to a list of threads
2204@item thread-specific breakpoints
2205@end itemize
2206
c906108c
SS
2207@quotation
2208@emph{Warning:} These facilities are not yet available on every
2209@value{GDBN} configuration where the operating system supports threads.
2210If your @value{GDBN} does not support threads, these commands have no
2211effect. For example, a system without thread support shows no output
2212from @samp{info threads}, and always rejects the @code{thread} command,
2213like this:
2214
2215@smallexample
2216(@value{GDBP}) info threads
2217(@value{GDBP}) thread 1
2218Thread ID 1 not known. Use the "info threads" command to
2219see the IDs of currently known threads.
2220@end smallexample
2221@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2222@c doesn't support threads"?
2223@end quotation
c906108c
SS
2224
2225@cindex focus of debugging
2226@cindex current thread
2227The @value{GDBN} thread debugging facility allows you to observe all
2228threads while your program runs---but whenever @value{GDBN} takes
2229control, one thread in particular is always the focus of debugging.
2230This thread is called the @dfn{current thread}. Debugging commands show
2231program information from the perspective of the current thread.
2232
41afff9a 2233@cindex @code{New} @var{systag} message
c906108c
SS
2234@cindex thread identifier (system)
2235@c FIXME-implementors!! It would be more helpful if the [New...] message
2236@c included GDB's numeric thread handle, so you could just go to that
2237@c thread without first checking `info threads'.
2238Whenever @value{GDBN} detects a new thread in your program, it displays
2239the target system's identification for the thread with a message in the
2240form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2241whose form varies depending on the particular system. For example, on
2242LynxOS, you might see
2243
474c8240 2244@smallexample
c906108c 2245[New process 35 thread 27]
474c8240 2246@end smallexample
c906108c
SS
2247
2248@noindent
2249when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2250the @var{systag} is simply something like @samp{process 368}, with no
2251further qualifier.
2252
2253@c FIXME!! (1) Does the [New...] message appear even for the very first
2254@c thread of a program, or does it only appear for the
6ca652b0 2255@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2256@c program?
2257@c (2) *Is* there necessarily a first thread always? Or do some
2258@c multithread systems permit starting a program with multiple
5d161b24 2259@c threads ab initio?
c906108c
SS
2260
2261@cindex thread number
2262@cindex thread identifier (GDB)
2263For debugging purposes, @value{GDBN} associates its own thread
2264number---always a single integer---with each thread in your program.
2265
2266@table @code
2267@kindex info threads
2268@item info threads
2269Display a summary of all threads currently in your
2270program. @value{GDBN} displays for each thread (in this order):
2271
2272@enumerate
09d4efe1
EZ
2273@item
2274the thread number assigned by @value{GDBN}
c906108c 2275
09d4efe1
EZ
2276@item
2277the target system's thread identifier (@var{systag})
c906108c 2278
09d4efe1
EZ
2279@item
2280the current stack frame summary for that thread
c906108c
SS
2281@end enumerate
2282
2283@noindent
2284An asterisk @samp{*} to the left of the @value{GDBN} thread number
2285indicates the current thread.
2286
5d161b24 2287For example,
c906108c
SS
2288@end table
2289@c end table here to get a little more width for example
2290
2291@smallexample
2292(@value{GDBP}) info threads
2293 3 process 35 thread 27 0x34e5 in sigpause ()
2294 2 process 35 thread 23 0x34e5 in sigpause ()
2295* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2296 at threadtest.c:68
2297@end smallexample
53a5351d
JM
2298
2299On HP-UX systems:
c906108c 2300
4644b6e3
EZ
2301@cindex debugging multithreaded programs (on HP-UX)
2302@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2303For debugging purposes, @value{GDBN} associates its own thread
2304number---a small integer assigned in thread-creation order---with each
2305thread in your program.
2306
41afff9a
EZ
2307@cindex @code{New} @var{systag} message, on HP-UX
2308@cindex thread identifier (system), on HP-UX
c906108c
SS
2309@c FIXME-implementors!! It would be more helpful if the [New...] message
2310@c included GDB's numeric thread handle, so you could just go to that
2311@c thread without first checking `info threads'.
2312Whenever @value{GDBN} detects a new thread in your program, it displays
2313both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2314form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2315whose form varies depending on the particular system. For example, on
2316HP-UX, you see
2317
474c8240 2318@smallexample
c906108c 2319[New thread 2 (system thread 26594)]
474c8240 2320@end smallexample
c906108c
SS
2321
2322@noindent
5d161b24 2323when @value{GDBN} notices a new thread.
c906108c
SS
2324
2325@table @code
4644b6e3 2326@kindex info threads (HP-UX)
c906108c
SS
2327@item info threads
2328Display a summary of all threads currently in your
2329program. @value{GDBN} displays for each thread (in this order):
2330
2331@enumerate
2332@item the thread number assigned by @value{GDBN}
2333
2334@item the target system's thread identifier (@var{systag})
2335
2336@item the current stack frame summary for that thread
2337@end enumerate
2338
2339@noindent
2340An asterisk @samp{*} to the left of the @value{GDBN} thread number
2341indicates the current thread.
2342
5d161b24 2343For example,
c906108c
SS
2344@end table
2345@c end table here to get a little more width for example
2346
474c8240 2347@smallexample
c906108c 2348(@value{GDBP}) info threads
6d2ebf8b
SS
2349 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2350 at quicksort.c:137
2351 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2352 from /usr/lib/libc.2
2353 1 system thread 27905 0x7b003498 in _brk () \@*
2354 from /usr/lib/libc.2
474c8240 2355@end smallexample
c906108c 2356
c45da7e6
EZ
2357On Solaris, you can display more information about user threads with a
2358Solaris-specific command:
2359
2360@table @code
2361@item maint info sol-threads
2362@kindex maint info sol-threads
2363@cindex thread info (Solaris)
2364Display info on Solaris user threads.
2365@end table
2366
c906108c
SS
2367@table @code
2368@kindex thread @var{threadno}
2369@item thread @var{threadno}
2370Make thread number @var{threadno} the current thread. The command
2371argument @var{threadno} is the internal @value{GDBN} thread number, as
2372shown in the first field of the @samp{info threads} display.
2373@value{GDBN} responds by displaying the system identifier of the thread
2374you selected, and its current stack frame summary:
2375
2376@smallexample
2377@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2378(@value{GDBP}) thread 2
c906108c 2379[Switching to process 35 thread 23]
c906108c
SS
23800x34e5 in sigpause ()
2381@end smallexample
2382
2383@noindent
2384As with the @samp{[New @dots{}]} message, the form of the text after
2385@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2386threads.
c906108c 2387
9c16f35a 2388@kindex thread apply
638ac427 2389@cindex apply command to several threads
c906108c
SS
2390@item thread apply [@var{threadno}] [@var{all}] @var{args}
2391The @code{thread apply} command allows you to apply a command to one or
2392more threads. Specify the numbers of the threads that you want affected
2393with the command argument @var{threadno}. @var{threadno} is the internal
2394@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2395threads} display. To apply a command to all threads, use
2396@code{thread apply all} @var{args}.
c906108c
SS
2397@end table
2398
2399@cindex automatic thread selection
2400@cindex switching threads automatically
2401@cindex threads, automatic switching
2402Whenever @value{GDBN} stops your program, due to a breakpoint or a
2403signal, it automatically selects the thread where that breakpoint or
2404signal happened. @value{GDBN} alerts you to the context switch with a
2405message of the form @samp{[Switching to @var{systag}]} to identify the
2406thread.
2407
2408@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2409more information about how @value{GDBN} behaves when you stop and start
2410programs with multiple threads.
2411
2412@xref{Set Watchpoints,,Setting watchpoints}, for information about
2413watchpoints in programs with multiple threads.
c906108c 2414
6d2ebf8b 2415@node Processes
c906108c
SS
2416@section Debugging programs with multiple processes
2417
2418@cindex fork, debugging programs which call
2419@cindex multiple processes
2420@cindex processes, multiple
53a5351d
JM
2421On most systems, @value{GDBN} has no special support for debugging
2422programs which create additional processes using the @code{fork}
2423function. When a program forks, @value{GDBN} will continue to debug the
2424parent process and the child process will run unimpeded. If you have
2425set a breakpoint in any code which the child then executes, the child
2426will get a @code{SIGTRAP} signal which (unless it catches the signal)
2427will cause it to terminate.
c906108c
SS
2428
2429However, if you want to debug the child process there is a workaround
2430which isn't too painful. Put a call to @code{sleep} in the code which
2431the child process executes after the fork. It may be useful to sleep
2432only if a certain environment variable is set, or a certain file exists,
2433so that the delay need not occur when you don't want to run @value{GDBN}
2434on the child. While the child is sleeping, use the @code{ps} program to
2435get its process ID. Then tell @value{GDBN} (a new invocation of
2436@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2437the child process (@pxref{Attach}). From that point on you can debug
c906108c 2438the child process just like any other process which you attached to.
c906108c 2439
b51970ac
DJ
2440On some systems, @value{GDBN} provides support for debugging programs that
2441create additional processes using the @code{fork} or @code{vfork} functions.
2442Currently, the only platforms with this feature are HP-UX (11.x and later
2443only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2444
2445By default, when a program forks, @value{GDBN} will continue to debug
2446the parent process and the child process will run unimpeded.
2447
2448If you want to follow the child process instead of the parent process,
2449use the command @w{@code{set follow-fork-mode}}.
2450
2451@table @code
2452@kindex set follow-fork-mode
2453@item set follow-fork-mode @var{mode}
2454Set the debugger response to a program call of @code{fork} or
2455@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 2456process. The @var{mode} argument can be:
c906108c
SS
2457
2458@table @code
2459@item parent
2460The original process is debugged after a fork. The child process runs
2df3850c 2461unimpeded. This is the default.
c906108c
SS
2462
2463@item child
2464The new process is debugged after a fork. The parent process runs
2465unimpeded.
2466
c906108c
SS
2467@end table
2468
9c16f35a 2469@kindex show follow-fork-mode
c906108c 2470@item show follow-fork-mode
2df3850c 2471Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2472@end table
2473
2474If you ask to debug a child process and a @code{vfork} is followed by an
2475@code{exec}, @value{GDBN} executes the new target up to the first
2476breakpoint in the new target. If you have a breakpoint set on
2477@code{main} in your original program, the breakpoint will also be set on
2478the child process's @code{main}.
2479
2480When a child process is spawned by @code{vfork}, you cannot debug the
2481child or parent until an @code{exec} call completes.
2482
2483If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2484call executes, the new target restarts. To restart the parent process,
2485use the @code{file} command with the parent executable name as its
2486argument.
2487
2488You can use the @code{catch} command to make @value{GDBN} stop whenever
2489a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2490Catchpoints, ,Setting catchpoints}.
c906108c 2491
6d2ebf8b 2492@node Stopping
c906108c
SS
2493@chapter Stopping and Continuing
2494
2495The principal purposes of using a debugger are so that you can stop your
2496program before it terminates; or so that, if your program runs into
2497trouble, you can investigate and find out why.
2498
7a292a7a
SS
2499Inside @value{GDBN}, your program may stop for any of several reasons,
2500such as a signal, a breakpoint, or reaching a new line after a
2501@value{GDBN} command such as @code{step}. You may then examine and
2502change variables, set new breakpoints or remove old ones, and then
2503continue execution. Usually, the messages shown by @value{GDBN} provide
2504ample explanation of the status of your program---but you can also
2505explicitly request this information at any time.
c906108c
SS
2506
2507@table @code
2508@kindex info program
2509@item info program
2510Display information about the status of your program: whether it is
7a292a7a 2511running or not, what process it is, and why it stopped.
c906108c
SS
2512@end table
2513
2514@menu
2515* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2516* Continuing and Stepping:: Resuming execution
c906108c 2517* Signals:: Signals
c906108c 2518* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2519@end menu
2520
6d2ebf8b 2521@node Breakpoints
c906108c
SS
2522@section Breakpoints, watchpoints, and catchpoints
2523
2524@cindex breakpoints
2525A @dfn{breakpoint} makes your program stop whenever a certain point in
2526the program is reached. For each breakpoint, you can add conditions to
2527control in finer detail whether your program stops. You can set
2528breakpoints with the @code{break} command and its variants (@pxref{Set
2529Breaks, ,Setting breakpoints}), to specify the place where your program
2530should stop by line number, function name or exact address in the
2531program.
2532
09d4efe1
EZ
2533On some systems, you can set breakpoints in shared libraries before
2534the executable is run. There is a minor limitation on HP-UX systems:
2535you must wait until the executable is run in order to set breakpoints
2536in shared library routines that are not called directly by the program
2537(for example, routines that are arguments in a @code{pthread_create}
2538call).
c906108c
SS
2539
2540@cindex watchpoints
2541@cindex memory tracing
2542@cindex breakpoint on memory address
2543@cindex breakpoint on variable modification
2544A @dfn{watchpoint} is a special breakpoint that stops your program
2545when the value of an expression changes. You must use a different
2546command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2547watchpoints}), but aside from that, you can manage a watchpoint like
2548any other breakpoint: you enable, disable, and delete both breakpoints
2549and watchpoints using the same commands.
2550
2551You can arrange to have values from your program displayed automatically
2552whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2553Automatic display}.
2554
2555@cindex catchpoints
2556@cindex breakpoint on events
2557A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2558when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2559exception or the loading of a library. As with watchpoints, you use a
2560different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2561catchpoints}), but aside from that, you can manage a catchpoint like any
2562other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2563@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2564
2565@cindex breakpoint numbers
2566@cindex numbers for breakpoints
2567@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2568catchpoint when you create it; these numbers are successive integers
2569starting with one. In many of the commands for controlling various
2570features of breakpoints you use the breakpoint number to say which
2571breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2572@dfn{disabled}; if disabled, it has no effect on your program until you
2573enable it again.
2574
c5394b80
JM
2575@cindex breakpoint ranges
2576@cindex ranges of breakpoints
2577Some @value{GDBN} commands accept a range of breakpoints on which to
2578operate. A breakpoint range is either a single breakpoint number, like
2579@samp{5}, or two such numbers, in increasing order, separated by a
2580hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2581all breakpoint in that range are operated on.
2582
c906108c
SS
2583@menu
2584* Set Breaks:: Setting breakpoints
2585* Set Watchpoints:: Setting watchpoints
2586* Set Catchpoints:: Setting catchpoints
2587* Delete Breaks:: Deleting breakpoints
2588* Disabling:: Disabling breakpoints
2589* Conditions:: Break conditions
2590* Break Commands:: Breakpoint command lists
c906108c 2591* Breakpoint Menus:: Breakpoint menus
d4f3574e 2592* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2593* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2594@end menu
2595
6d2ebf8b 2596@node Set Breaks
c906108c
SS
2597@subsection Setting breakpoints
2598
5d161b24 2599@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2600@c consider in particular declaration with/without initialization.
2601@c
2602@c FIXME 2 is there stuff on this already? break at fun start, already init?
2603
2604@kindex break
41afff9a
EZ
2605@kindex b @r{(@code{break})}
2606@vindex $bpnum@r{, convenience variable}
c906108c
SS
2607@cindex latest breakpoint
2608Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2609@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2610number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2611Vars,, Convenience variables}, for a discussion of what you can do with
2612convenience variables.
2613
2614You have several ways to say where the breakpoint should go.
2615
2616@table @code
2617@item break @var{function}
5d161b24 2618Set a breakpoint at entry to function @var{function}.
c906108c 2619When using source languages that permit overloading of symbols, such as
b37052ae 2620C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2621@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2622
2623@item break +@var{offset}
2624@itemx break -@var{offset}
2625Set a breakpoint some number of lines forward or back from the position
d4f3574e 2626at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2627(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2628
2629@item break @var{linenum}
2630Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2631The current source file is the last file whose source text was printed.
2632The breakpoint will stop your program just before it executes any of the
c906108c
SS
2633code on that line.
2634
2635@item break @var{filename}:@var{linenum}
2636Set a breakpoint at line @var{linenum} in source file @var{filename}.
2637
2638@item break @var{filename}:@var{function}
2639Set a breakpoint at entry to function @var{function} found in file
2640@var{filename}. Specifying a file name as well as a function name is
2641superfluous except when multiple files contain similarly named
2642functions.
2643
2644@item break *@var{address}
2645Set a breakpoint at address @var{address}. You can use this to set
2646breakpoints in parts of your program which do not have debugging
2647information or source files.
2648
2649@item break
2650When called without any arguments, @code{break} sets a breakpoint at
2651the next instruction to be executed in the selected stack frame
2652(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2653innermost, this makes your program stop as soon as control
2654returns to that frame. This is similar to the effect of a
2655@code{finish} command in the frame inside the selected frame---except
2656that @code{finish} does not leave an active breakpoint. If you use
2657@code{break} without an argument in the innermost frame, @value{GDBN} stops
2658the next time it reaches the current location; this may be useful
2659inside loops.
2660
2661@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2662least one instruction has been executed. If it did not do this, you
2663would be unable to proceed past a breakpoint without first disabling the
2664breakpoint. This rule applies whether or not the breakpoint already
2665existed when your program stopped.
2666
2667@item break @dots{} if @var{cond}
2668Set a breakpoint with condition @var{cond}; evaluate the expression
2669@var{cond} each time the breakpoint is reached, and stop only if the
2670value is nonzero---that is, if @var{cond} evaluates as true.
2671@samp{@dots{}} stands for one of the possible arguments described
2672above (or no argument) specifying where to break. @xref{Conditions,
2673,Break conditions}, for more information on breakpoint conditions.
2674
2675@kindex tbreak
2676@item tbreak @var{args}
2677Set a breakpoint enabled only for one stop. @var{args} are the
2678same as for the @code{break} command, and the breakpoint is set in the same
2679way, but the breakpoint is automatically deleted after the first time your
2680program stops there. @xref{Disabling, ,Disabling breakpoints}.
2681
c906108c 2682@kindex hbreak
ba04e063 2683@cindex hardware breakpoints
c906108c 2684@item hbreak @var{args}
d4f3574e
SS
2685Set a hardware-assisted breakpoint. @var{args} are the same as for the
2686@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2687breakpoint requires hardware support and some target hardware may not
2688have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2689debugging, so you can set a breakpoint at an instruction without
2690changing the instruction. This can be used with the new trap-generation
09d4efe1 2691provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
2692will generate traps when a program accesses some data or instruction
2693address that is assigned to the debug registers. However the hardware
2694breakpoint registers can take a limited number of breakpoints. For
2695example, on the DSU, only two data breakpoints can be set at a time, and
2696@value{GDBN} will reject this command if more than two are used. Delete
2697or disable unused hardware breakpoints before setting new ones
2698(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
9c16f35a
EZ
2699For remote targets, you can restrict the number of hardware
2700breakpoints @value{GDBN} will use, see @ref{set remote
2701hardware-breakpoint-limit}.
501eef12 2702
c906108c
SS
2703
2704@kindex thbreak
2705@item thbreak @var{args}
2706Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2707are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2708the same way. However, like the @code{tbreak} command,
c906108c
SS
2709the breakpoint is automatically deleted after the
2710first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2711command, the breakpoint requires hardware support and some target hardware
2712may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2713See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2714
2715@kindex rbreak
2716@cindex regular expression
c45da7e6
EZ
2717@cindex breakpoints in functions matching a regexp
2718@cindex set breakpoints in many functions
c906108c 2719@item rbreak @var{regex}
c906108c 2720Set breakpoints on all functions matching the regular expression
11cf8741
JM
2721@var{regex}. This command sets an unconditional breakpoint on all
2722matches, printing a list of all breakpoints it set. Once these
2723breakpoints are set, they are treated just like the breakpoints set with
2724the @code{break} command. You can delete them, disable them, or make
2725them conditional the same way as any other breakpoint.
2726
2727The syntax of the regular expression is the standard one used with tools
2728like @file{grep}. Note that this is different from the syntax used by
2729shells, so for instance @code{foo*} matches all functions that include
2730an @code{fo} followed by zero or more @code{o}s. There is an implicit
2731@code{.*} leading and trailing the regular expression you supply, so to
2732match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2733
f7dc1244 2734@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2735When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2736breakpoints on overloaded functions that are not members of any special
2737classes.
c906108c 2738
f7dc1244
EZ
2739@cindex set breakpoints on all functions
2740The @code{rbreak} command can be used to set breakpoints in
2741@strong{all} the functions in a program, like this:
2742
2743@smallexample
2744(@value{GDBP}) rbreak .
2745@end smallexample
2746
c906108c
SS
2747@kindex info breakpoints
2748@cindex @code{$_} and @code{info breakpoints}
2749@item info breakpoints @r{[}@var{n}@r{]}
2750@itemx info break @r{[}@var{n}@r{]}
2751@itemx info watchpoints @r{[}@var{n}@r{]}
2752Print a table of all breakpoints, watchpoints, and catchpoints set and
2753not deleted, with the following columns for each breakpoint:
2754
2755@table @emph
2756@item Breakpoint Numbers
2757@item Type
2758Breakpoint, watchpoint, or catchpoint.
2759@item Disposition
2760Whether the breakpoint is marked to be disabled or deleted when hit.
2761@item Enabled or Disabled
2762Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2763that are not enabled.
2764@item Address
2650777c
JJ
2765Where the breakpoint is in your program, as a memory address. If the
2766breakpoint is pending (see below for details) on a future load of a shared library, the address
2767will be listed as @samp{<PENDING>}.
c906108c
SS
2768@item What
2769Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
2770line number. For a pending breakpoint, the original string passed to
2771the breakpoint command will be listed as it cannot be resolved until
2772the appropriate shared library is loaded in the future.
c906108c
SS
2773@end table
2774
2775@noindent
2776If a breakpoint is conditional, @code{info break} shows the condition on
2777the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
2778are listed after that. A pending breakpoint is allowed to have a condition
2779specified for it. The condition is not parsed for validity until a shared
2780library is loaded that allows the pending breakpoint to resolve to a
2781valid location.
c906108c
SS
2782
2783@noindent
2784@code{info break} with a breakpoint
2785number @var{n} as argument lists only that breakpoint. The
2786convenience variable @code{$_} and the default examining-address for
2787the @code{x} command are set to the address of the last breakpoint
5d161b24 2788listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2789
2790@noindent
2791@code{info break} displays a count of the number of times the breakpoint
2792has been hit. This is especially useful in conjunction with the
2793@code{ignore} command. You can ignore a large number of breakpoint
2794hits, look at the breakpoint info to see how many times the breakpoint
2795was hit, and then run again, ignoring one less than that number. This
2796will get you quickly to the last hit of that breakpoint.
2797@end table
2798
2799@value{GDBN} allows you to set any number of breakpoints at the same place in
2800your program. There is nothing silly or meaningless about this. When
2801the breakpoints are conditional, this is even useful
2802(@pxref{Conditions, ,Break conditions}).
2803
2650777c 2804@cindex pending breakpoints
dd79a6cf
JJ
2805If a specified breakpoint location cannot be found, it may be due to the fact
2806that the location is in a shared library that is yet to be loaded. In such
2807a case, you may want @value{GDBN} to create a special breakpoint (known as
2808a @dfn{pending breakpoint}) that
2809attempts to resolve itself in the future when an appropriate shared library
2810gets loaded.
2811
2812Pending breakpoints are useful to set at the start of your
2650777c
JJ
2813@value{GDBN} session for locations that you know will be dynamically loaded
2814later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
2815a check is made to see if the load resolves any pending breakpoint locations.
2816If a pending breakpoint location gets resolved,
2817a regular breakpoint is created and the original pending breakpoint is removed.
2818
2819@value{GDBN} provides some additional commands for controlling pending
2820breakpoint support:
2821
2822@kindex set breakpoint pending
2823@kindex show breakpoint pending
2824@table @code
2825@item set breakpoint pending auto
2826This is the default behavior. When @value{GDBN} cannot find the breakpoint
2827location, it queries you whether a pending breakpoint should be created.
2828
2829@item set breakpoint pending on
2830This indicates that an unrecognized breakpoint location should automatically
2831result in a pending breakpoint being created.
2832
2833@item set breakpoint pending off
2834This indicates that pending breakpoints are not to be created. Any
2835unrecognized breakpoint location results in an error. This setting does
2836not affect any pending breakpoints previously created.
2837
2838@item show breakpoint pending
2839Show the current behavior setting for creating pending breakpoints.
2840@end table
2650777c 2841
649e03f6
RM
2842@cindex operations allowed on pending breakpoints
2843Normal breakpoint operations apply to pending breakpoints as well. You may
2844specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
2845breakpoint is reached. You can also enable or disable
2846the pending breakpoint. When you specify a condition for a pending breakpoint,
2847the parsing of the condition will be deferred until the point where the
2848pending breakpoint location is resolved. Disabling a pending breakpoint
2849tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
2850shared library load. When a pending breakpoint is re-enabled,
649e03f6 2851@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
2852This is done because any number of shared library loads could have
2853occurred since the time the breakpoint was disabled and one or more
2854of these loads could resolve the location.
2855
c906108c
SS
2856@cindex negative breakpoint numbers
2857@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2858@value{GDBN} itself sometimes sets breakpoints in your program for
2859special purposes, such as proper handling of @code{longjmp} (in C
2860programs). These internal breakpoints are assigned negative numbers,
2861starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2862You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2863@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2864
2865
6d2ebf8b 2866@node Set Watchpoints
c906108c
SS
2867@subsection Setting watchpoints
2868
2869@cindex setting watchpoints
c906108c
SS
2870You can use a watchpoint to stop execution whenever the value of an
2871expression changes, without having to predict a particular place where
2872this may happen.
2873
82f2d802
EZ
2874@cindex software watchpoints
2875@cindex hardware watchpoints
c906108c 2876Depending on your system, watchpoints may be implemented in software or
2df3850c 2877hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2878program and testing the variable's value each time, which is hundreds of
2879times slower than normal execution. (But this may still be worth it, to
2880catch errors where you have no clue what part of your program is the
2881culprit.)
2882
82f2d802
EZ
2883On some systems, such as HP-UX, @sc{gnu}/Linux and most other
2884x86-based targets, @value{GDBN} includes support for hardware
2885watchpoints, which do not slow down the running of your program.
c906108c
SS
2886
2887@table @code
2888@kindex watch
2889@item watch @var{expr}
2890Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2891is written into by the program and its value changes.
2892
2893@kindex rwatch
2894@item rwatch @var{expr}
09d4efe1
EZ
2895Set a watchpoint that will break when the value of @var{expr} is read
2896by the program.
c906108c
SS
2897
2898@kindex awatch
2899@item awatch @var{expr}
09d4efe1
EZ
2900Set a watchpoint that will break when @var{expr} is either read from
2901or written into by the program.
c906108c
SS
2902
2903@kindex info watchpoints
2904@item info watchpoints
2905This command prints a list of watchpoints, breakpoints, and catchpoints;
09d4efe1 2906it is the same as @code{info break} (@pxref{Set Breaks}).
c906108c
SS
2907@end table
2908
2909@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2910watchpoints execute very quickly, and the debugger reports a change in
2911value at the exact instruction where the change occurs. If @value{GDBN}
2912cannot set a hardware watchpoint, it sets a software watchpoint, which
2913executes more slowly and reports the change in value at the next
82f2d802
EZ
2914@emph{statement}, not the instruction, after the change occurs.
2915
82f2d802
EZ
2916@cindex use only software watchpoints
2917You can force @value{GDBN} to use only software watchpoints with the
2918@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
2919zero, @value{GDBN} will never try to use hardware watchpoints, even if
2920the underlying system supports them. (Note that hardware-assisted
2921watchpoints that were set @emph{before} setting
2922@code{can-use-hw-watchpoints} to zero will still use the hardware
2923mechanism of watching expressiion values.)
c906108c 2924
9c16f35a
EZ
2925@table @code
2926@item set can-use-hw-watchpoints
2927@kindex set can-use-hw-watchpoints
2928Set whether or not to use hardware watchpoints.
2929
2930@item show can-use-hw-watchpoints
2931@kindex show can-use-hw-watchpoints
2932Show the current mode of using hardware watchpoints.
2933@end table
2934
2935For remote targets, you can restrict the number of hardware
2936watchpoints @value{GDBN} will use, see @ref{set remote
2937hardware-breakpoint-limit}.
2938
c906108c
SS
2939When you issue the @code{watch} command, @value{GDBN} reports
2940
474c8240 2941@smallexample
c906108c 2942Hardware watchpoint @var{num}: @var{expr}
474c8240 2943@end smallexample
c906108c
SS
2944
2945@noindent
2946if it was able to set a hardware watchpoint.
2947
7be570e7
JM
2948Currently, the @code{awatch} and @code{rwatch} commands can only set
2949hardware watchpoints, because accesses to data that don't change the
2950value of the watched expression cannot be detected without examining
2951every instruction as it is being executed, and @value{GDBN} does not do
2952that currently. If @value{GDBN} finds that it is unable to set a
2953hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2954will print a message like this:
2955
2956@smallexample
2957Expression cannot be implemented with read/access watchpoint.
2958@end smallexample
2959
2960Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2961data type of the watched expression is wider than what a hardware
2962watchpoint on the target machine can handle. For example, some systems
2963can only watch regions that are up to 4 bytes wide; on such systems you
2964cannot set hardware watchpoints for an expression that yields a
2965double-precision floating-point number (which is typically 8 bytes
2966wide). As a work-around, it might be possible to break the large region
2967into a series of smaller ones and watch them with separate watchpoints.
2968
2969If you set too many hardware watchpoints, @value{GDBN} might be unable
2970to insert all of them when you resume the execution of your program.
2971Since the precise number of active watchpoints is unknown until such
2972time as the program is about to be resumed, @value{GDBN} might not be
2973able to warn you about this when you set the watchpoints, and the
2974warning will be printed only when the program is resumed:
2975
2976@smallexample
2977Hardware watchpoint @var{num}: Could not insert watchpoint
2978@end smallexample
2979
2980@noindent
2981If this happens, delete or disable some of the watchpoints.
2982
2983The SPARClite DSU will generate traps when a program accesses some data
2984or instruction address that is assigned to the debug registers. For the
2985data addresses, DSU facilitates the @code{watch} command. However the
2986hardware breakpoint registers can only take two data watchpoints, and
2987both watchpoints must be the same kind. For example, you can set two
2988watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2989@strong{or} two with @code{awatch} commands, but you cannot set one
2990watchpoint with one command and the other with a different command.
c906108c
SS
2991@value{GDBN} will reject the command if you try to mix watchpoints.
2992Delete or disable unused watchpoint commands before setting new ones.
2993
2994If you call a function interactively using @code{print} or @code{call},
2df3850c 2995any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2996kind of breakpoint or the call completes.
2997
7be570e7
JM
2998@value{GDBN} automatically deletes watchpoints that watch local
2999(automatic) variables, or expressions that involve such variables, when
3000they go out of scope, that is, when the execution leaves the block in
3001which these variables were defined. In particular, when the program
3002being debugged terminates, @emph{all} local variables go out of scope,
3003and so only watchpoints that watch global variables remain set. If you
3004rerun the program, you will need to set all such watchpoints again. One
3005way of doing that would be to set a code breakpoint at the entry to the
3006@code{main} function and when it breaks, set all the watchpoints.
3007
c906108c
SS
3008@quotation
3009@cindex watchpoints and threads
3010@cindex threads and watchpoints
c906108c
SS
3011@emph{Warning:} In multi-thread programs, watchpoints have only limited
3012usefulness. With the current watchpoint implementation, @value{GDBN}
3013can only watch the value of an expression @emph{in a single thread}. If
3014you are confident that the expression can only change due to the current
3015thread's activity (and if you are also confident that no other thread
3016can become current), then you can use watchpoints as usual. However,
3017@value{GDBN} may not notice when a non-current thread's activity changes
3018the expression.
53a5351d 3019
d4f3574e 3020@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
3021@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
3022have only limited usefulness. If @value{GDBN} creates a software
3023watchpoint, it can only watch the value of an expression @emph{in a
3024single thread}. If you are confident that the expression can only
3025change due to the current thread's activity (and if you are also
3026confident that no other thread can become current), then you can use
3027software watchpoints as usual. However, @value{GDBN} may not notice
3028when a non-current thread's activity changes the expression. (Hardware
3029watchpoints, in contrast, watch an expression in all threads.)
c906108c 3030@end quotation
c906108c 3031
501eef12
AC
3032@xref{set remote hardware-watchpoint-limit}.
3033
6d2ebf8b 3034@node Set Catchpoints
c906108c 3035@subsection Setting catchpoints
d4f3574e 3036@cindex catchpoints, setting
c906108c
SS
3037@cindex exception handlers
3038@cindex event handling
3039
3040You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 3041kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
3042shared library. Use the @code{catch} command to set a catchpoint.
3043
3044@table @code
3045@kindex catch
3046@item catch @var{event}
3047Stop when @var{event} occurs. @var{event} can be any of the following:
3048@table @code
3049@item throw
4644b6e3 3050@cindex stop on C@t{++} exceptions
b37052ae 3051The throwing of a C@t{++} exception.
c906108c
SS
3052
3053@item catch
b37052ae 3054The catching of a C@t{++} exception.
c906108c
SS
3055
3056@item exec
4644b6e3 3057@cindex break on fork/exec
c906108c
SS
3058A call to @code{exec}. This is currently only available for HP-UX.
3059
3060@item fork
c906108c
SS
3061A call to @code{fork}. This is currently only available for HP-UX.
3062
3063@item vfork
c906108c
SS
3064A call to @code{vfork}. This is currently only available for HP-UX.
3065
3066@item load
3067@itemx load @var{libname}
4644b6e3 3068@cindex break on load/unload of shared library
c906108c
SS
3069The dynamic loading of any shared library, or the loading of the library
3070@var{libname}. This is currently only available for HP-UX.
3071
3072@item unload
3073@itemx unload @var{libname}
c906108c
SS
3074The unloading of any dynamically loaded shared library, or the unloading
3075of the library @var{libname}. This is currently only available for HP-UX.
3076@end table
3077
3078@item tcatch @var{event}
3079Set a catchpoint that is enabled only for one stop. The catchpoint is
3080automatically deleted after the first time the event is caught.
3081
3082@end table
3083
3084Use the @code{info break} command to list the current catchpoints.
3085
b37052ae 3086There are currently some limitations to C@t{++} exception handling
c906108c
SS
3087(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3088
3089@itemize @bullet
3090@item
3091If you call a function interactively, @value{GDBN} normally returns
3092control to you when the function has finished executing. If the call
3093raises an exception, however, the call may bypass the mechanism that
3094returns control to you and cause your program either to abort or to
3095simply continue running until it hits a breakpoint, catches a signal
3096that @value{GDBN} is listening for, or exits. This is the case even if
3097you set a catchpoint for the exception; catchpoints on exceptions are
3098disabled within interactive calls.
3099
3100@item
3101You cannot raise an exception interactively.
3102
3103@item
3104You cannot install an exception handler interactively.
3105@end itemize
3106
3107@cindex raise exceptions
3108Sometimes @code{catch} is not the best way to debug exception handling:
3109if you need to know exactly where an exception is raised, it is better to
3110stop @emph{before} the exception handler is called, since that way you
3111can see the stack before any unwinding takes place. If you set a
3112breakpoint in an exception handler instead, it may not be easy to find
3113out where the exception was raised.
3114
3115To stop just before an exception handler is called, you need some
b37052ae 3116knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
3117raised by calling a library function named @code{__raise_exception}
3118which has the following ANSI C interface:
3119
474c8240 3120@smallexample
c906108c 3121 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
3122 @var{id} is the exception identifier. */
3123 void __raise_exception (void **addr, void *id);
474c8240 3124@end smallexample
c906108c
SS
3125
3126@noindent
3127To make the debugger catch all exceptions before any stack
3128unwinding takes place, set a breakpoint on @code{__raise_exception}
3129(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
3130
3131With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
3132that depends on the value of @var{id}, you can stop your program when
3133a specific exception is raised. You can use multiple conditional
3134breakpoints to stop your program when any of a number of exceptions are
3135raised.
3136
3137
6d2ebf8b 3138@node Delete Breaks
c906108c
SS
3139@subsection Deleting breakpoints
3140
3141@cindex clearing breakpoints, watchpoints, catchpoints
3142@cindex deleting breakpoints, watchpoints, catchpoints
3143It is often necessary to eliminate a breakpoint, watchpoint, or
3144catchpoint once it has done its job and you no longer want your program
3145to stop there. This is called @dfn{deleting} the breakpoint. A
3146breakpoint that has been deleted no longer exists; it is forgotten.
3147
3148With the @code{clear} command you can delete breakpoints according to
3149where they are in your program. With the @code{delete} command you can
3150delete individual breakpoints, watchpoints, or catchpoints by specifying
3151their breakpoint numbers.
3152
3153It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3154automatically ignores breakpoints on the first instruction to be executed
3155when you continue execution without changing the execution address.
3156
3157@table @code
3158@kindex clear
3159@item clear
3160Delete any breakpoints at the next instruction to be executed in the
3161selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3162the innermost frame is selected, this is a good way to delete a
3163breakpoint where your program just stopped.
3164
3165@item clear @var{function}
3166@itemx clear @var{filename}:@var{function}
09d4efe1 3167Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
3168
3169@item clear @var{linenum}
3170@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
3171Delete any breakpoints set at or within the code of the specified
3172@var{linenum} of the specified @var{filename}.
c906108c
SS
3173
3174@cindex delete breakpoints
3175@kindex delete
41afff9a 3176@kindex d @r{(@code{delete})}
c5394b80
JM
3177@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3178Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3179ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3180breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3181confirm off}). You can abbreviate this command as @code{d}.
3182@end table
3183
6d2ebf8b 3184@node Disabling
c906108c
SS
3185@subsection Disabling breakpoints
3186
4644b6e3 3187@cindex enable/disable a breakpoint
c906108c
SS
3188Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3189prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3190it had been deleted, but remembers the information on the breakpoint so
3191that you can @dfn{enable} it again later.
3192
3193You disable and enable breakpoints, watchpoints, and catchpoints with
3194the @code{enable} and @code{disable} commands, optionally specifying one
3195or more breakpoint numbers as arguments. Use @code{info break} or
3196@code{info watch} to print a list of breakpoints, watchpoints, and
3197catchpoints if you do not know which numbers to use.
3198
3199A breakpoint, watchpoint, or catchpoint can have any of four different
3200states of enablement:
3201
3202@itemize @bullet
3203@item
3204Enabled. The breakpoint stops your program. A breakpoint set
3205with the @code{break} command starts out in this state.
3206@item
3207Disabled. The breakpoint has no effect on your program.
3208@item
3209Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3210disabled.
c906108c
SS
3211@item
3212Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3213immediately after it does so it is deleted permanently. A breakpoint
3214set with the @code{tbreak} command starts out in this state.
c906108c
SS
3215@end itemize
3216
3217You can use the following commands to enable or disable breakpoints,
3218watchpoints, and catchpoints:
3219
3220@table @code
c906108c 3221@kindex disable
41afff9a 3222@kindex dis @r{(@code{disable})}
c5394b80 3223@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3224Disable the specified breakpoints---or all breakpoints, if none are
3225listed. A disabled breakpoint has no effect but is not forgotten. All
3226options such as ignore-counts, conditions and commands are remembered in
3227case the breakpoint is enabled again later. You may abbreviate
3228@code{disable} as @code{dis}.
3229
c906108c 3230@kindex enable
c5394b80 3231@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3232Enable the specified breakpoints (or all defined breakpoints). They
3233become effective once again in stopping your program.
3234
c5394b80 3235@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3236Enable the specified breakpoints temporarily. @value{GDBN} disables any
3237of these breakpoints immediately after stopping your program.
3238
c5394b80 3239@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3240Enable the specified breakpoints to work once, then die. @value{GDBN}
3241deletes any of these breakpoints as soon as your program stops there.
09d4efe1 3242Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
3243@end table
3244
d4f3574e
SS
3245@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3246@c confusing: tbreak is also initially enabled.
c906108c
SS
3247Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3248,Setting breakpoints}), breakpoints that you set are initially enabled;
3249subsequently, they become disabled or enabled only when you use one of
3250the commands above. (The command @code{until} can set and delete a
3251breakpoint of its own, but it does not change the state of your other
3252breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3253stepping}.)
3254
6d2ebf8b 3255@node Conditions
c906108c
SS
3256@subsection Break conditions
3257@cindex conditional breakpoints
3258@cindex breakpoint conditions
3259
3260@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3261@c in particular for a watchpoint?
c906108c
SS
3262The simplest sort of breakpoint breaks every time your program reaches a
3263specified place. You can also specify a @dfn{condition} for a
3264breakpoint. A condition is just a Boolean expression in your
3265programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3266a condition evaluates the expression each time your program reaches it,
3267and your program stops only if the condition is @emph{true}.
3268
3269This is the converse of using assertions for program validation; in that
3270situation, you want to stop when the assertion is violated---that is,
3271when the condition is false. In C, if you want to test an assertion expressed
3272by the condition @var{assert}, you should set the condition
3273@samp{! @var{assert}} on the appropriate breakpoint.
3274
3275Conditions are also accepted for watchpoints; you may not need them,
3276since a watchpoint is inspecting the value of an expression anyhow---but
3277it might be simpler, say, to just set a watchpoint on a variable name,
3278and specify a condition that tests whether the new value is an interesting
3279one.
3280
3281Break conditions can have side effects, and may even call functions in
3282your program. This can be useful, for example, to activate functions
3283that log program progress, or to use your own print functions to
3284format special data structures. The effects are completely predictable
3285unless there is another enabled breakpoint at the same address. (In
3286that case, @value{GDBN} might see the other breakpoint first and stop your
3287program without checking the condition of this one.) Note that
d4f3574e
SS
3288breakpoint commands are usually more convenient and flexible than break
3289conditions for the
c906108c
SS
3290purpose of performing side effects when a breakpoint is reached
3291(@pxref{Break Commands, ,Breakpoint command lists}).
3292
3293Break conditions can be specified when a breakpoint is set, by using
3294@samp{if} in the arguments to the @code{break} command. @xref{Set
3295Breaks, ,Setting breakpoints}. They can also be changed at any time
3296with the @code{condition} command.
53a5351d 3297
c906108c
SS
3298You can also use the @code{if} keyword with the @code{watch} command.
3299The @code{catch} command does not recognize the @code{if} keyword;
3300@code{condition} is the only way to impose a further condition on a
3301catchpoint.
c906108c
SS
3302
3303@table @code
3304@kindex condition
3305@item condition @var{bnum} @var{expression}
3306Specify @var{expression} as the break condition for breakpoint,
3307watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3308breakpoint @var{bnum} stops your program only if the value of
3309@var{expression} is true (nonzero, in C). When you use
3310@code{condition}, @value{GDBN} checks @var{expression} immediately for
3311syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3312referents in the context of your breakpoint. If @var{expression} uses
3313symbols not referenced in the context of the breakpoint, @value{GDBN}
3314prints an error message:
3315
474c8240 3316@smallexample
d4f3574e 3317No symbol "foo" in current context.
474c8240 3318@end smallexample
d4f3574e
SS
3319
3320@noindent
c906108c
SS
3321@value{GDBN} does
3322not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3323command (or a command that sets a breakpoint with a condition, like
3324@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3325
3326@item condition @var{bnum}
3327Remove the condition from breakpoint number @var{bnum}. It becomes
3328an ordinary unconditional breakpoint.
3329@end table
3330
3331@cindex ignore count (of breakpoint)
3332A special case of a breakpoint condition is to stop only when the
3333breakpoint has been reached a certain number of times. This is so
3334useful that there is a special way to do it, using the @dfn{ignore
3335count} of the breakpoint. Every breakpoint has an ignore count, which
3336is an integer. Most of the time, the ignore count is zero, and
3337therefore has no effect. But if your program reaches a breakpoint whose
3338ignore count is positive, then instead of stopping, it just decrements
3339the ignore count by one and continues. As a result, if the ignore count
3340value is @var{n}, the breakpoint does not stop the next @var{n} times
3341your program reaches it.
3342
3343@table @code
3344@kindex ignore
3345@item ignore @var{bnum} @var{count}
3346Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3347The next @var{count} times the breakpoint is reached, your program's
3348execution does not stop; other than to decrement the ignore count, @value{GDBN}
3349takes no action.
3350
3351To make the breakpoint stop the next time it is reached, specify
3352a count of zero.
3353
3354When you use @code{continue} to resume execution of your program from a
3355breakpoint, you can specify an ignore count directly as an argument to
3356@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3357Stepping,,Continuing and stepping}.
3358
3359If a breakpoint has a positive ignore count and a condition, the
3360condition is not checked. Once the ignore count reaches zero,
3361@value{GDBN} resumes checking the condition.
3362
3363You could achieve the effect of the ignore count with a condition such
3364as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3365is decremented each time. @xref{Convenience Vars, ,Convenience
3366variables}.
3367@end table
3368
3369Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3370
3371
6d2ebf8b 3372@node Break Commands
c906108c
SS
3373@subsection Breakpoint command lists
3374
3375@cindex breakpoint commands
3376You can give any breakpoint (or watchpoint or catchpoint) a series of
3377commands to execute when your program stops due to that breakpoint. For
3378example, you might want to print the values of certain expressions, or
3379enable other breakpoints.
3380
3381@table @code
3382@kindex commands
3383@kindex end
3384@item commands @r{[}@var{bnum}@r{]}
3385@itemx @dots{} @var{command-list} @dots{}
3386@itemx end
3387Specify a list of commands for breakpoint number @var{bnum}. The commands
3388themselves appear on the following lines. Type a line containing just
3389@code{end} to terminate the commands.
3390
3391To remove all commands from a breakpoint, type @code{commands} and
3392follow it immediately with @code{end}; that is, give no commands.
3393
3394With no @var{bnum} argument, @code{commands} refers to the last
3395breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3396recently encountered).
3397@end table
3398
3399Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3400disabled within a @var{command-list}.
3401
3402You can use breakpoint commands to start your program up again. Simply
3403use the @code{continue} command, or @code{step}, or any other command
3404that resumes execution.
3405
3406Any other commands in the command list, after a command that resumes
3407execution, are ignored. This is because any time you resume execution
3408(even with a simple @code{next} or @code{step}), you may encounter
3409another breakpoint---which could have its own command list, leading to
3410ambiguities about which list to execute.
3411
3412@kindex silent
3413If the first command you specify in a command list is @code{silent}, the
3414usual message about stopping at a breakpoint is not printed. This may
3415be desirable for breakpoints that are to print a specific message and
3416then continue. If none of the remaining commands print anything, you
3417see no sign that the breakpoint was reached. @code{silent} is
3418meaningful only at the beginning of a breakpoint command list.
3419
3420The commands @code{echo}, @code{output}, and @code{printf} allow you to
3421print precisely controlled output, and are often useful in silent
3422breakpoints. @xref{Output, ,Commands for controlled output}.
3423
3424For example, here is how you could use breakpoint commands to print the
3425value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3426
474c8240 3427@smallexample
c906108c
SS
3428break foo if x>0
3429commands
3430silent
3431printf "x is %d\n",x
3432cont
3433end
474c8240 3434@end smallexample
c906108c
SS
3435
3436One application for breakpoint commands is to compensate for one bug so
3437you can test for another. Put a breakpoint just after the erroneous line
3438of code, give it a condition to detect the case in which something
3439erroneous has been done, and give it commands to assign correct values
3440to any variables that need them. End with the @code{continue} command
3441so that your program does not stop, and start with the @code{silent}
3442command so that no output is produced. Here is an example:
3443
474c8240 3444@smallexample
c906108c
SS
3445break 403
3446commands
3447silent
3448set x = y + 4
3449cont
3450end
474c8240 3451@end smallexample
c906108c 3452
6d2ebf8b 3453@node Breakpoint Menus
c906108c
SS
3454@subsection Breakpoint menus
3455@cindex overloading
3456@cindex symbol overloading
3457
b383017d 3458Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3459single function name
c906108c
SS
3460to be defined several times, for application in different contexts.
3461This is called @dfn{overloading}. When a function name is overloaded,
3462@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3463a breakpoint. If you realize this is a problem, you can use
3464something like @samp{break @var{function}(@var{types})} to specify which
3465particular version of the function you want. Otherwise, @value{GDBN} offers
3466you a menu of numbered choices for different possible breakpoints, and
3467waits for your selection with the prompt @samp{>}. The first two
3468options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3469sets a breakpoint at each definition of @var{function}, and typing
3470@kbd{0} aborts the @code{break} command without setting any new
3471breakpoints.
3472
3473For example, the following session excerpt shows an attempt to set a
3474breakpoint at the overloaded symbol @code{String::after}.
3475We choose three particular definitions of that function name:
3476
3477@c FIXME! This is likely to change to show arg type lists, at least
3478@smallexample
3479@group
3480(@value{GDBP}) b String::after
3481[0] cancel
3482[1] all
3483[2] file:String.cc; line number:867
3484[3] file:String.cc; line number:860
3485[4] file:String.cc; line number:875
3486[5] file:String.cc; line number:853
3487[6] file:String.cc; line number:846
3488[7] file:String.cc; line number:735
3489> 2 4 6
3490Breakpoint 1 at 0xb26c: file String.cc, line 867.
3491Breakpoint 2 at 0xb344: file String.cc, line 875.
3492Breakpoint 3 at 0xafcc: file String.cc, line 846.
3493Multiple breakpoints were set.
3494Use the "delete" command to delete unwanted
3495 breakpoints.
3496(@value{GDBP})
3497@end group
3498@end smallexample
c906108c
SS
3499
3500@c @ifclear BARETARGET
6d2ebf8b 3501@node Error in Breakpoints
d4f3574e 3502@subsection ``Cannot insert breakpoints''
c906108c
SS
3503@c
3504@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3505@c
d4f3574e
SS
3506Under some operating systems, breakpoints cannot be used in a program if
3507any other process is running that program. In this situation,
5d161b24 3508attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3509@value{GDBN} to print an error message:
3510
474c8240 3511@smallexample
d4f3574e
SS
3512Cannot insert breakpoints.
3513The same program may be running in another process.
474c8240 3514@end smallexample
d4f3574e
SS
3515
3516When this happens, you have three ways to proceed:
3517
3518@enumerate
3519@item
3520Remove or disable the breakpoints, then continue.
3521
3522@item
5d161b24 3523Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3524name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3525that @value{GDBN} should run your program under that name.
d4f3574e
SS
3526Then start your program again.
3527
3528@item
3529Relink your program so that the text segment is nonsharable, using the
3530linker option @samp{-N}. The operating system limitation may not apply
3531to nonsharable executables.
3532@end enumerate
c906108c
SS
3533@c @end ifclear
3534
d4f3574e
SS
3535A similar message can be printed if you request too many active
3536hardware-assisted breakpoints and watchpoints:
3537
3538@c FIXME: the precise wording of this message may change; the relevant
3539@c source change is not committed yet (Sep 3, 1999).
3540@smallexample
3541Stopped; cannot insert breakpoints.
3542You may have requested too many hardware breakpoints and watchpoints.
3543@end smallexample
3544
3545@noindent
3546This message is printed when you attempt to resume the program, since
3547only then @value{GDBN} knows exactly how many hardware breakpoints and
3548watchpoints it needs to insert.
3549
3550When this message is printed, you need to disable or remove some of the
3551hardware-assisted breakpoints and watchpoints, and then continue.
3552
1485d690
KB
3553@node Breakpoint related warnings
3554@subsection ``Breakpoint address adjusted...''
3555@cindex breakpoint address adjusted
3556
3557Some processor architectures place constraints on the addresses at
3558which breakpoints may be placed. For architectures thus constrained,
3559@value{GDBN} will attempt to adjust the breakpoint's address to comply
3560with the constraints dictated by the architecture.
3561
3562One example of such an architecture is the Fujitsu FR-V. The FR-V is
3563a VLIW architecture in which a number of RISC-like instructions may be
3564bundled together for parallel execution. The FR-V architecture
3565constrains the location of a breakpoint instruction within such a
3566bundle to the instruction with the lowest address. @value{GDBN}
3567honors this constraint by adjusting a breakpoint's address to the
3568first in the bundle.
3569
3570It is not uncommon for optimized code to have bundles which contain
3571instructions from different source statements, thus it may happen that
3572a breakpoint's address will be adjusted from one source statement to
3573another. Since this adjustment may significantly alter @value{GDBN}'s
3574breakpoint related behavior from what the user expects, a warning is
3575printed when the breakpoint is first set and also when the breakpoint
3576is hit.
3577
3578A warning like the one below is printed when setting a breakpoint
3579that's been subject to address adjustment:
3580
3581@smallexample
3582warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3583@end smallexample
3584
3585Such warnings are printed both for user settable and @value{GDBN}'s
3586internal breakpoints. If you see one of these warnings, you should
3587verify that a breakpoint set at the adjusted address will have the
3588desired affect. If not, the breakpoint in question may be removed and
b383017d 3589other breakpoints may be set which will have the desired behavior.
1485d690
KB
3590E.g., it may be sufficient to place the breakpoint at a later
3591instruction. A conditional breakpoint may also be useful in some
3592cases to prevent the breakpoint from triggering too often.
3593
3594@value{GDBN} will also issue a warning when stopping at one of these
3595adjusted breakpoints:
3596
3597@smallexample
3598warning: Breakpoint 1 address previously adjusted from 0x00010414
3599to 0x00010410.
3600@end smallexample
3601
3602When this warning is encountered, it may be too late to take remedial
3603action except in cases where the breakpoint is hit earlier or more
3604frequently than expected.
d4f3574e 3605
6d2ebf8b 3606@node Continuing and Stepping
c906108c
SS
3607@section Continuing and stepping
3608
3609@cindex stepping
3610@cindex continuing
3611@cindex resuming execution
3612@dfn{Continuing} means resuming program execution until your program
3613completes normally. In contrast, @dfn{stepping} means executing just
3614one more ``step'' of your program, where ``step'' may mean either one
3615line of source code, or one machine instruction (depending on what
7a292a7a
SS
3616particular command you use). Either when continuing or when stepping,
3617your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3618it stops due to a signal, you may want to use @code{handle}, or use
3619@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3620
3621@table @code
3622@kindex continue
41afff9a
EZ
3623@kindex c @r{(@code{continue})}
3624@kindex fg @r{(resume foreground execution)}
c906108c
SS
3625@item continue @r{[}@var{ignore-count}@r{]}
3626@itemx c @r{[}@var{ignore-count}@r{]}
3627@itemx fg @r{[}@var{ignore-count}@r{]}
3628Resume program execution, at the address where your program last stopped;
3629any breakpoints set at that address are bypassed. The optional argument
3630@var{ignore-count} allows you to specify a further number of times to
3631ignore a breakpoint at this location; its effect is like that of
3632@code{ignore} (@pxref{Conditions, ,Break conditions}).
3633
3634The argument @var{ignore-count} is meaningful only when your program
3635stopped due to a breakpoint. At other times, the argument to
3636@code{continue} is ignored.
3637
d4f3574e
SS
3638The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3639debugged program is deemed to be the foreground program) are provided
3640purely for convenience, and have exactly the same behavior as
3641@code{continue}.
c906108c
SS
3642@end table
3643
3644To resume execution at a different place, you can use @code{return}
3645(@pxref{Returning, ,Returning from a function}) to go back to the
3646calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3647different address}) to go to an arbitrary location in your program.
3648
3649A typical technique for using stepping is to set a breakpoint
3650(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3651beginning of the function or the section of your program where a problem
3652is believed to lie, run your program until it stops at that breakpoint,
3653and then step through the suspect area, examining the variables that are
3654interesting, until you see the problem happen.
3655
3656@table @code
3657@kindex step
41afff9a 3658@kindex s @r{(@code{step})}
c906108c
SS
3659@item step
3660Continue running your program until control reaches a different source
3661line, then stop it and return control to @value{GDBN}. This command is
3662abbreviated @code{s}.
3663
3664@quotation
3665@c "without debugging information" is imprecise; actually "without line
3666@c numbers in the debugging information". (gcc -g1 has debugging info but
3667@c not line numbers). But it seems complex to try to make that
3668@c distinction here.
3669@emph{Warning:} If you use the @code{step} command while control is
3670within a function that was compiled without debugging information,
3671execution proceeds until control reaches a function that does have
3672debugging information. Likewise, it will not step into a function which
3673is compiled without debugging information. To step through functions
3674without debugging information, use the @code{stepi} command, described
3675below.
3676@end quotation
3677
4a92d011
EZ
3678The @code{step} command only stops at the first instruction of a source
3679line. This prevents the multiple stops that could otherwise occur in
3680@code{switch} statements, @code{for} loops, etc. @code{step} continues
3681to stop if a function that has debugging information is called within
3682the line. In other words, @code{step} @emph{steps inside} any functions
3683called within the line.
c906108c 3684
d4f3574e
SS
3685Also, the @code{step} command only enters a function if there is line
3686number information for the function. Otherwise it acts like the
5d161b24 3687@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3688on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3689was any debugging information about the routine.
c906108c
SS
3690
3691@item step @var{count}
3692Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3693breakpoint is reached, or a signal not related to stepping occurs before
3694@var{count} steps, stepping stops right away.
c906108c
SS
3695
3696@kindex next
41afff9a 3697@kindex n @r{(@code{next})}
c906108c
SS
3698@item next @r{[}@var{count}@r{]}
3699Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3700This is similar to @code{step}, but function calls that appear within
3701the line of code are executed without stopping. Execution stops when
3702control reaches a different line of code at the original stack level
3703that was executing when you gave the @code{next} command. This command
3704is abbreviated @code{n}.
c906108c
SS
3705
3706An argument @var{count} is a repeat count, as for @code{step}.
3707
3708
3709@c FIX ME!! Do we delete this, or is there a way it fits in with
3710@c the following paragraph? --- Vctoria
3711@c
3712@c @code{next} within a function that lacks debugging information acts like
3713@c @code{step}, but any function calls appearing within the code of the
3714@c function are executed without stopping.
3715
d4f3574e
SS
3716The @code{next} command only stops at the first instruction of a
3717source line. This prevents multiple stops that could otherwise occur in
4a92d011 3718@code{switch} statements, @code{for} loops, etc.
c906108c 3719
b90a5f51
CF
3720@kindex set step-mode
3721@item set step-mode
3722@cindex functions without line info, and stepping
3723@cindex stepping into functions with no line info
3724@itemx set step-mode on
4a92d011 3725The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3726stop at the first instruction of a function which contains no debug line
3727information rather than stepping over it.
3728
4a92d011
EZ
3729This is useful in cases where you may be interested in inspecting the
3730machine instructions of a function which has no symbolic info and do not
3731want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3732
3733@item set step-mode off
4a92d011 3734Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3735debug information. This is the default.
3736
9c16f35a
EZ
3737@item show step-mode
3738Show whether @value{GDBN} will stop in or step over functions without
3739source line debug information.
3740
c906108c
SS
3741@kindex finish
3742@item finish
3743Continue running until just after function in the selected stack frame
3744returns. Print the returned value (if any).
3745
3746Contrast this with the @code{return} command (@pxref{Returning,
3747,Returning from a function}).
3748
3749@kindex until
41afff9a 3750@kindex u @r{(@code{until})}
09d4efe1 3751@cindex run until specified location
c906108c
SS
3752@item until
3753@itemx u
3754Continue running until a source line past the current line, in the
3755current stack frame, is reached. This command is used to avoid single
3756stepping through a loop more than once. It is like the @code{next}
3757command, except that when @code{until} encounters a jump, it
3758automatically continues execution until the program counter is greater
3759than the address of the jump.
3760
3761This means that when you reach the end of a loop after single stepping
3762though it, @code{until} makes your program continue execution until it
3763exits the loop. In contrast, a @code{next} command at the end of a loop
3764simply steps back to the beginning of the loop, which forces you to step
3765through the next iteration.
3766
3767@code{until} always stops your program if it attempts to exit the current
3768stack frame.
3769
3770@code{until} may produce somewhat counterintuitive results if the order
3771of machine code does not match the order of the source lines. For
3772example, in the following excerpt from a debugging session, the @code{f}
3773(@code{frame}) command shows that execution is stopped at line
3774@code{206}; yet when we use @code{until}, we get to line @code{195}:
3775
474c8240 3776@smallexample
c906108c
SS
3777(@value{GDBP}) f
3778#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3779206 expand_input();
3780(@value{GDBP}) until
3781195 for ( ; argc > 0; NEXTARG) @{
474c8240 3782@end smallexample
c906108c
SS
3783
3784This happened because, for execution efficiency, the compiler had
3785generated code for the loop closure test at the end, rather than the
3786start, of the loop---even though the test in a C @code{for}-loop is
3787written before the body of the loop. The @code{until} command appeared
3788to step back to the beginning of the loop when it advanced to this
3789expression; however, it has not really gone to an earlier
3790statement---not in terms of the actual machine code.
3791
3792@code{until} with no argument works by means of single
3793instruction stepping, and hence is slower than @code{until} with an
3794argument.
3795
3796@item until @var{location}
3797@itemx u @var{location}
3798Continue running your program until either the specified location is
3799reached, or the current stack frame returns. @var{location} is any of
3800the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
3801,Setting breakpoints}). This form of the command uses breakpoints, and
3802hence is quicker than @code{until} without an argument. The specified
3803location is actually reached only if it is in the current frame. This
3804implies that @code{until} can be used to skip over recursive function
3805invocations. For instance in the code below, if the current location is
3806line @code{96}, issuing @code{until 99} will execute the program up to
3807line @code{99} in the same invocation of factorial, i.e. after the inner
3808invocations have returned.
3809
3810@smallexample
381194 int factorial (int value)
381295 @{
381396 if (value > 1) @{
381497 value *= factorial (value - 1);
381598 @}
381699 return (value);
3817100 @}
3818@end smallexample
3819
3820
3821@kindex advance @var{location}
3822@itemx advance @var{location}
09d4efe1
EZ
3823Continue running the program up to the given @var{location}. An argument is
3824required, which should be of the same form as arguments for the @code{break}
c60eb6f1
EZ
3825command. Execution will also stop upon exit from the current stack
3826frame. This command is similar to @code{until}, but @code{advance} will
3827not skip over recursive function calls, and the target location doesn't
3828have to be in the same frame as the current one.
3829
c906108c
SS
3830
3831@kindex stepi
41afff9a 3832@kindex si @r{(@code{stepi})}
c906108c 3833@item stepi
96a2c332 3834@itemx stepi @var{arg}
c906108c
SS
3835@itemx si
3836Execute one machine instruction, then stop and return to the debugger.
3837
3838It is often useful to do @samp{display/i $pc} when stepping by machine
3839instructions. This makes @value{GDBN} automatically display the next
3840instruction to be executed, each time your program stops. @xref{Auto
3841Display,, Automatic display}.
3842
3843An argument is a repeat count, as in @code{step}.
3844
3845@need 750
3846@kindex nexti
41afff9a 3847@kindex ni @r{(@code{nexti})}
c906108c 3848@item nexti
96a2c332 3849@itemx nexti @var{arg}
c906108c
SS
3850@itemx ni
3851Execute one machine instruction, but if it is a function call,
3852proceed until the function returns.
3853
3854An argument is a repeat count, as in @code{next}.
3855@end table
3856
6d2ebf8b 3857@node Signals
c906108c
SS
3858@section Signals
3859@cindex signals
3860
3861A signal is an asynchronous event that can happen in a program. The
3862operating system defines the possible kinds of signals, and gives each
3863kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3864signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3865@code{SIGSEGV} is the signal a program gets from referencing a place in
3866memory far away from all the areas in use; @code{SIGALRM} occurs when
3867the alarm clock timer goes off (which happens only if your program has
3868requested an alarm).
3869
3870@cindex fatal signals
3871Some signals, including @code{SIGALRM}, are a normal part of the
3872functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3873errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3874program has not specified in advance some other way to handle the signal.
3875@code{SIGINT} does not indicate an error in your program, but it is normally
3876fatal so it can carry out the purpose of the interrupt: to kill the program.
3877
3878@value{GDBN} has the ability to detect any occurrence of a signal in your
3879program. You can tell @value{GDBN} in advance what to do for each kind of
3880signal.
3881
3882@cindex handling signals
24f93129
EZ
3883Normally, @value{GDBN} is set up to let the non-erroneous signals like
3884@code{SIGALRM} be silently passed to your program
3885(so as not to interfere with their role in the program's functioning)
c906108c
SS
3886but to stop your program immediately whenever an error signal happens.
3887You can change these settings with the @code{handle} command.
3888
3889@table @code
3890@kindex info signals
09d4efe1 3891@kindex info handle
c906108c 3892@item info signals
96a2c332 3893@itemx info handle
c906108c
SS
3894Print a table of all the kinds of signals and how @value{GDBN} has been told to
3895handle each one. You can use this to see the signal numbers of all
3896the defined types of signals.
3897
d4f3574e 3898@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3899
3900@kindex handle
3901@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3902Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3903can be the number of a signal or its name (with or without the
24f93129 3904@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3905@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3906known signals. The @var{keywords} say what change to make.
c906108c
SS
3907@end table
3908
3909@c @group
3910The keywords allowed by the @code{handle} command can be abbreviated.
3911Their full names are:
3912
3913@table @code
3914@item nostop
3915@value{GDBN} should not stop your program when this signal happens. It may
3916still print a message telling you that the signal has come in.
3917
3918@item stop
3919@value{GDBN} should stop your program when this signal happens. This implies
3920the @code{print} keyword as well.
3921
3922@item print
3923@value{GDBN} should print a message when this signal happens.
3924
3925@item noprint
3926@value{GDBN} should not mention the occurrence of the signal at all. This
3927implies the @code{nostop} keyword as well.
3928
3929@item pass
5ece1a18 3930@itemx noignore
c906108c
SS
3931@value{GDBN} should allow your program to see this signal; your program
3932can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3933and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3934
3935@item nopass
5ece1a18 3936@itemx ignore
c906108c 3937@value{GDBN} should not allow your program to see this signal.
5ece1a18 3938@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3939@end table
3940@c @end group
3941
d4f3574e
SS
3942When a signal stops your program, the signal is not visible to the
3943program until you
c906108c
SS
3944continue. Your program sees the signal then, if @code{pass} is in
3945effect for the signal in question @emph{at that time}. In other words,
3946after @value{GDBN} reports a signal, you can use the @code{handle}
3947command with @code{pass} or @code{nopass} to control whether your
3948program sees that signal when you continue.
3949
24f93129
EZ
3950The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3951non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3952@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3953erroneous signals.
3954
c906108c
SS
3955You can also use the @code{signal} command to prevent your program from
3956seeing a signal, or cause it to see a signal it normally would not see,
3957or to give it any signal at any time. For example, if your program stopped
3958due to some sort of memory reference error, you might store correct
3959values into the erroneous variables and continue, hoping to see more
3960execution; but your program would probably terminate immediately as
3961a result of the fatal signal once it saw the signal. To prevent this,
3962you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3963program a signal}.
c906108c 3964
6d2ebf8b 3965@node Thread Stops
c906108c
SS
3966@section Stopping and starting multi-thread programs
3967
3968When your program has multiple threads (@pxref{Threads,, Debugging
3969programs with multiple threads}), you can choose whether to set
3970breakpoints on all threads, or on a particular thread.
3971
3972@table @code
3973@cindex breakpoints and threads
3974@cindex thread breakpoints
3975@kindex break @dots{} thread @var{threadno}
3976@item break @var{linespec} thread @var{threadno}
3977@itemx break @var{linespec} thread @var{threadno} if @dots{}
3978@var{linespec} specifies source lines; there are several ways of
3979writing them, but the effect is always to specify some source line.
3980
3981Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3982to specify that you only want @value{GDBN} to stop the program when a
3983particular thread reaches this breakpoint. @var{threadno} is one of the
3984numeric thread identifiers assigned by @value{GDBN}, shown in the first
3985column of the @samp{info threads} display.
3986
3987If you do not specify @samp{thread @var{threadno}} when you set a
3988breakpoint, the breakpoint applies to @emph{all} threads of your
3989program.
3990
3991You can use the @code{thread} qualifier on conditional breakpoints as
3992well; in this case, place @samp{thread @var{threadno}} before the
3993breakpoint condition, like this:
3994
3995@smallexample
2df3850c 3996(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3997@end smallexample
3998
3999@end table
4000
4001@cindex stopped threads
4002@cindex threads, stopped
4003Whenever your program stops under @value{GDBN} for any reason,
4004@emph{all} threads of execution stop, not just the current thread. This
4005allows you to examine the overall state of the program, including
4006switching between threads, without worrying that things may change
4007underfoot.
4008
36d86913
MC
4009@cindex thread breakpoints and system calls
4010@cindex system calls and thread breakpoints
4011@cindex premature return from system calls
4012There is an unfortunate side effect. If one thread stops for a
4013breakpoint, or for some other reason, and another thread is blocked in a
4014system call, then the system call may return prematurely. This is a
4015consequence of the interaction between multiple threads and the signals
4016that @value{GDBN} uses to implement breakpoints and other events that
4017stop execution.
4018
4019To handle this problem, your program should check the return value of
4020each system call and react appropriately. This is good programming
4021style anyways.
4022
4023For example, do not write code like this:
4024
4025@smallexample
4026 sleep (10);
4027@end smallexample
4028
4029The call to @code{sleep} will return early if a different thread stops
4030at a breakpoint or for some other reason.
4031
4032Instead, write this:
4033
4034@smallexample
4035 int unslept = 10;
4036 while (unslept > 0)
4037 unslept = sleep (unslept);
4038@end smallexample
4039
4040A system call is allowed to return early, so the system is still
4041conforming to its specification. But @value{GDBN} does cause your
4042multi-threaded program to behave differently than it would without
4043@value{GDBN}.
4044
4045Also, @value{GDBN} uses internal breakpoints in the thread library to
4046monitor certain events such as thread creation and thread destruction.
4047When such an event happens, a system call in another thread may return
4048prematurely, even though your program does not appear to stop.
4049
c906108c
SS
4050@cindex continuing threads
4051@cindex threads, continuing
4052Conversely, whenever you restart the program, @emph{all} threads start
4053executing. @emph{This is true even when single-stepping} with commands
5d161b24 4054like @code{step} or @code{next}.
c906108c
SS
4055
4056In particular, @value{GDBN} cannot single-step all threads in lockstep.
4057Since thread scheduling is up to your debugging target's operating
4058system (not controlled by @value{GDBN}), other threads may
4059execute more than one statement while the current thread completes a
4060single step. Moreover, in general other threads stop in the middle of a
4061statement, rather than at a clean statement boundary, when the program
4062stops.
4063
4064You might even find your program stopped in another thread after
4065continuing or even single-stepping. This happens whenever some other
4066thread runs into a breakpoint, a signal, or an exception before the
4067first thread completes whatever you requested.
4068
4069On some OSes, you can lock the OS scheduler and thus allow only a single
4070thread to run.
4071
4072@table @code
4073@item set scheduler-locking @var{mode}
9c16f35a
EZ
4074@cindex scheduler locking mode
4075@cindex lock scheduler
c906108c
SS
4076Set the scheduler locking mode. If it is @code{off}, then there is no
4077locking and any thread may run at any time. If @code{on}, then only the
4078current thread may run when the inferior is resumed. The @code{step}
4079mode optimizes for single-stepping. It stops other threads from
4080``seizing the prompt'' by preempting the current thread while you are
4081stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 4082when you step. They are more likely to run when you @samp{next} over a
c906108c 4083function call, and they are completely free to run when you use commands
d4f3574e 4084like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 4085thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 4086@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
4087
4088@item show scheduler-locking
4089Display the current scheduler locking mode.
4090@end table
4091
c906108c 4092
6d2ebf8b 4093@node Stack
c906108c
SS
4094@chapter Examining the Stack
4095
4096When your program has stopped, the first thing you need to know is where it
4097stopped and how it got there.
4098
4099@cindex call stack
5d161b24
DB
4100Each time your program performs a function call, information about the call
4101is generated.
4102That information includes the location of the call in your program,
4103the arguments of the call,
c906108c 4104and the local variables of the function being called.
5d161b24 4105The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
4106The stack frames are allocated in a region of memory called the @dfn{call
4107stack}.
4108
4109When your program stops, the @value{GDBN} commands for examining the
4110stack allow you to see all of this information.
4111
4112@cindex selected frame
4113One of the stack frames is @dfn{selected} by @value{GDBN} and many
4114@value{GDBN} commands refer implicitly to the selected frame. In
4115particular, whenever you ask @value{GDBN} for the value of a variable in
4116your program, the value is found in the selected frame. There are
4117special @value{GDBN} commands to select whichever frame you are
4118interested in. @xref{Selection, ,Selecting a frame}.
4119
4120When your program stops, @value{GDBN} automatically selects the
5d161b24 4121currently executing frame and describes it briefly, similar to the
c906108c
SS
4122@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
4123
4124@menu
4125* Frames:: Stack frames
4126* Backtrace:: Backtraces
4127* Selection:: Selecting a frame
4128* Frame Info:: Information on a frame
c906108c
SS
4129
4130@end menu
4131
6d2ebf8b 4132@node Frames
c906108c
SS
4133@section Stack frames
4134
d4f3574e 4135@cindex frame, definition
c906108c
SS
4136@cindex stack frame
4137The call stack is divided up into contiguous pieces called @dfn{stack
4138frames}, or @dfn{frames} for short; each frame is the data associated
4139with one call to one function. The frame contains the arguments given
4140to the function, the function's local variables, and the address at
4141which the function is executing.
4142
4143@cindex initial frame
4144@cindex outermost frame
4145@cindex innermost frame
4146When your program is started, the stack has only one frame, that of the
4147function @code{main}. This is called the @dfn{initial} frame or the
4148@dfn{outermost} frame. Each time a function is called, a new frame is
4149made. Each time a function returns, the frame for that function invocation
4150is eliminated. If a function is recursive, there can be many frames for
4151the same function. The frame for the function in which execution is
4152actually occurring is called the @dfn{innermost} frame. This is the most
4153recently created of all the stack frames that still exist.
4154
4155@cindex frame pointer
4156Inside your program, stack frames are identified by their addresses. A
4157stack frame consists of many bytes, each of which has its own address; each
4158kind of computer has a convention for choosing one byte whose
4159address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
4160in a register called the @dfn{frame pointer register}
4161(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
4162
4163@cindex frame number
4164@value{GDBN} assigns numbers to all existing stack frames, starting with
4165zero for the innermost frame, one for the frame that called it,
4166and so on upward. These numbers do not really exist in your program;
4167they are assigned by @value{GDBN} to give you a way of designating stack
4168frames in @value{GDBN} commands.
4169
6d2ebf8b
SS
4170@c The -fomit-frame-pointer below perennially causes hbox overflow
4171@c underflow problems.
c906108c
SS
4172@cindex frameless execution
4173Some compilers provide a way to compile functions so that they operate
6d2ebf8b 4174without stack frames. (For example, the @value{GCC} option
474c8240 4175@smallexample
6d2ebf8b 4176@samp{-fomit-frame-pointer}
474c8240 4177@end smallexample
6d2ebf8b 4178generates functions without a frame.)
c906108c
SS
4179This is occasionally done with heavily used library functions to save
4180the frame setup time. @value{GDBN} has limited facilities for dealing
4181with these function invocations. If the innermost function invocation
4182has no stack frame, @value{GDBN} nevertheless regards it as though
4183it had a separate frame, which is numbered zero as usual, allowing
4184correct tracing of the function call chain. However, @value{GDBN} has
4185no provision for frameless functions elsewhere in the stack.
4186
4187@table @code
d4f3574e 4188@kindex frame@r{, command}
41afff9a 4189@cindex current stack frame
c906108c 4190@item frame @var{args}
5d161b24 4191The @code{frame} command allows you to move from one stack frame to another,
c906108c 4192and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4193address of the frame or the stack frame number. Without an argument,
4194@code{frame} prints the current stack frame.
c906108c
SS
4195
4196@kindex select-frame
41afff9a 4197@cindex selecting frame silently
c906108c
SS
4198@item select-frame
4199The @code{select-frame} command allows you to move from one stack frame
4200to another without printing the frame. This is the silent version of
4201@code{frame}.
4202@end table
4203
6d2ebf8b 4204@node Backtrace
c906108c
SS
4205@section Backtraces
4206
09d4efe1
EZ
4207@cindex traceback
4208@cindex call stack traces
c906108c
SS
4209A backtrace is a summary of how your program got where it is. It shows one
4210line per frame, for many frames, starting with the currently executing
4211frame (frame zero), followed by its caller (frame one), and on up the
4212stack.
4213
4214@table @code
4215@kindex backtrace
41afff9a 4216@kindex bt @r{(@code{backtrace})}
c906108c
SS
4217@item backtrace
4218@itemx bt
4219Print a backtrace of the entire stack: one line per frame for all
4220frames in the stack.
4221
4222You can stop the backtrace at any time by typing the system interrupt
4223character, normally @kbd{C-c}.
4224
4225@item backtrace @var{n}
4226@itemx bt @var{n}
4227Similar, but print only the innermost @var{n} frames.
4228
4229@item backtrace -@var{n}
4230@itemx bt -@var{n}
4231Similar, but print only the outermost @var{n} frames.
0f061b69
NR
4232
4233@item backtrace full
4234Print the values of the local variables also.
4235@itemx bt full
c906108c
SS
4236@end table
4237
4238@kindex where
4239@kindex info stack
c906108c
SS
4240The names @code{where} and @code{info stack} (abbreviated @code{info s})
4241are additional aliases for @code{backtrace}.
4242
4243Each line in the backtrace shows the frame number and the function name.
4244The program counter value is also shown---unless you use @code{set
4245print address off}. The backtrace also shows the source file name and
4246line number, as well as the arguments to the function. The program
4247counter value is omitted if it is at the beginning of the code for that
4248line number.
4249
4250Here is an example of a backtrace. It was made with the command
4251@samp{bt 3}, so it shows the innermost three frames.
4252
4253@smallexample
4254@group
5d161b24 4255#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4256 at builtin.c:993
4257#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4258#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4259 at macro.c:71
4260(More stack frames follow...)
4261@end group
4262@end smallexample
4263
4264@noindent
4265The display for frame zero does not begin with a program counter
4266value, indicating that your program has stopped at the beginning of the
4267code for line @code{993} of @code{builtin.c}.
4268
18999be5
EZ
4269@cindex value optimized out, in backtrace
4270@cindex function call arguments, optimized out
4271If your program was compiled with optimizations, some compilers will
4272optimize away arguments passed to functions if those arguments are
4273never used after the call. Such optimizations generate code that
4274passes arguments through registers, but doesn't store those arguments
4275in the stack frame. @value{GDBN} has no way of displaying such
4276arguments in stack frames other than the innermost one. Here's what
4277such a backtrace might look like:
4278
4279@smallexample
4280@group
4281#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4282 at builtin.c:993
4283#1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
4284#2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
4285 at macro.c:71
4286(More stack frames follow...)
4287@end group
4288@end smallexample
4289
4290@noindent
4291The values of arguments that were not saved in their stack frames are
4292shown as @samp{<value optimized out>}.
4293
4294If you need to display the values of such optimized-out arguments,
4295either deduce that from other variables whose values depend on the one
4296you are interested in, or recompile without optimizations.
4297
a8f24a35
EZ
4298@cindex backtrace beyond @code{main} function
4299@cindex program entry point
4300@cindex startup code, and backtrace
25d29d70
AC
4301Most programs have a standard user entry point---a place where system
4302libraries and startup code transition into user code. For C this is
4303@code{main}. When @value{GDBN} finds the entry function in a backtrace
4304it will terminate the backtrace, to avoid tracing into highly
4305system-specific (and generally uninteresting) code.
4306
4307If you need to examine the startup code, or limit the number of levels
4308in a backtrace, you can change this behavior:
95f90d25
DJ
4309
4310@table @code
25d29d70
AC
4311@item set backtrace past-main
4312@itemx set backtrace past-main on
4644b6e3 4313@kindex set backtrace
25d29d70
AC
4314Backtraces will continue past the user entry point.
4315
4316@item set backtrace past-main off
95f90d25
DJ
4317Backtraces will stop when they encounter the user entry point. This is the
4318default.
4319
25d29d70 4320@item show backtrace past-main
4644b6e3 4321@kindex show backtrace
25d29d70
AC
4322Display the current user entry point backtrace policy.
4323
2315ffec
RC
4324@item set backtrace past-entry
4325@itemx set backtrace past-entry on
a8f24a35 4326Backtraces will continue past the internal entry point of an application.
2315ffec
RC
4327This entry point is encoded by the linker when the application is built,
4328and is likely before the user entry point @code{main} (or equivalent) is called.
4329
4330@item set backtrace past-entry off
4331Backtraces will stop when they encouter the internal entry point of an
4332application. This is the default.
4333
4334@item show backtrace past-entry
4335Display the current internal entry point backtrace policy.
4336
25d29d70
AC
4337@item set backtrace limit @var{n}
4338@itemx set backtrace limit 0
4339@cindex backtrace limit
4340Limit the backtrace to @var{n} levels. A value of zero means
4341unlimited.
95f90d25 4342
25d29d70
AC
4343@item show backtrace limit
4344Display the current limit on backtrace levels.
95f90d25
DJ
4345@end table
4346
6d2ebf8b 4347@node Selection
c906108c
SS
4348@section Selecting a frame
4349
4350Most commands for examining the stack and other data in your program work on
4351whichever stack frame is selected at the moment. Here are the commands for
4352selecting a stack frame; all of them finish by printing a brief description
4353of the stack frame just selected.
4354
4355@table @code
d4f3574e 4356@kindex frame@r{, selecting}
41afff9a 4357@kindex f @r{(@code{frame})}
c906108c
SS
4358@item frame @var{n}
4359@itemx f @var{n}
4360Select frame number @var{n}. Recall that frame zero is the innermost
4361(currently executing) frame, frame one is the frame that called the
4362innermost one, and so on. The highest-numbered frame is the one for
4363@code{main}.
4364
4365@item frame @var{addr}
4366@itemx f @var{addr}
4367Select the frame at address @var{addr}. This is useful mainly if the
4368chaining of stack frames has been damaged by a bug, making it
4369impossible for @value{GDBN} to assign numbers properly to all frames. In
4370addition, this can be useful when your program has multiple stacks and
4371switches between them.
4372
c906108c
SS
4373On the SPARC architecture, @code{frame} needs two addresses to
4374select an arbitrary frame: a frame pointer and a stack pointer.
4375
4376On the MIPS and Alpha architecture, it needs two addresses: a stack
4377pointer and a program counter.
4378
4379On the 29k architecture, it needs three addresses: a register stack
4380pointer, a program counter, and a memory stack pointer.
4381@c note to future updaters: this is conditioned on a flag
4382@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
4383@c as of 27 Jan 1994.
c906108c
SS
4384
4385@kindex up
4386@item up @var{n}
4387Move @var{n} frames up the stack. For positive numbers @var{n}, this
4388advances toward the outermost frame, to higher frame numbers, to frames
4389that have existed longer. @var{n} defaults to one.
4390
4391@kindex down
41afff9a 4392@kindex do @r{(@code{down})}
c906108c
SS
4393@item down @var{n}
4394Move @var{n} frames down the stack. For positive numbers @var{n}, this
4395advances toward the innermost frame, to lower frame numbers, to frames
4396that were created more recently. @var{n} defaults to one. You may
4397abbreviate @code{down} as @code{do}.
4398@end table
4399
4400All of these commands end by printing two lines of output describing the
4401frame. The first line shows the frame number, the function name, the
4402arguments, and the source file and line number of execution in that
5d161b24 4403frame. The second line shows the text of that source line.
c906108c
SS
4404
4405@need 1000
4406For example:
4407
4408@smallexample
4409@group
4410(@value{GDBP}) up
4411#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4412 at env.c:10
441310 read_input_file (argv[i]);
4414@end group
4415@end smallexample
4416
4417After such a printout, the @code{list} command with no arguments
4418prints ten lines centered on the point of execution in the frame.
87885426
FN
4419You can also edit the program at the point of execution with your favorite
4420editing program by typing @code{edit}.
4421@xref{List, ,Printing source lines},
4422for details.
c906108c
SS
4423
4424@table @code
4425@kindex down-silently
4426@kindex up-silently
4427@item up-silently @var{n}
4428@itemx down-silently @var{n}
4429These two commands are variants of @code{up} and @code{down},
4430respectively; they differ in that they do their work silently, without
4431causing display of the new frame. They are intended primarily for use
4432in @value{GDBN} command scripts, where the output might be unnecessary and
4433distracting.
4434@end table
4435
6d2ebf8b 4436@node Frame Info
c906108c
SS
4437@section Information about a frame
4438
4439There are several other commands to print information about the selected
4440stack frame.
4441
4442@table @code
4443@item frame
4444@itemx f
4445When used without any argument, this command does not change which
4446frame is selected, but prints a brief description of the currently
4447selected stack frame. It can be abbreviated @code{f}. With an
4448argument, this command is used to select a stack frame.
4449@xref{Selection, ,Selecting a frame}.
4450
4451@kindex info frame
41afff9a 4452@kindex info f @r{(@code{info frame})}
c906108c
SS
4453@item info frame
4454@itemx info f
4455This command prints a verbose description of the selected stack frame,
4456including:
4457
4458@itemize @bullet
5d161b24
DB
4459@item
4460the address of the frame
c906108c
SS
4461@item
4462the address of the next frame down (called by this frame)
4463@item
4464the address of the next frame up (caller of this frame)
4465@item
4466the language in which the source code corresponding to this frame is written
4467@item
4468the address of the frame's arguments
4469@item
d4f3574e
SS
4470the address of the frame's local variables
4471@item
c906108c
SS
4472the program counter saved in it (the address of execution in the caller frame)
4473@item
4474which registers were saved in the frame
4475@end itemize
4476
4477@noindent The verbose description is useful when
4478something has gone wrong that has made the stack format fail to fit
4479the usual conventions.
4480
4481@item info frame @var{addr}
4482@itemx info f @var{addr}
4483Print a verbose description of the frame at address @var{addr}, without
4484selecting that frame. The selected frame remains unchanged by this
4485command. This requires the same kind of address (more than one for some
4486architectures) that you specify in the @code{frame} command.
4487@xref{Selection, ,Selecting a frame}.
4488
4489@kindex info args
4490@item info args
4491Print the arguments of the selected frame, each on a separate line.
4492
4493@item info locals
4494@kindex info locals
4495Print the local variables of the selected frame, each on a separate
4496line. These are all variables (declared either static or automatic)
4497accessible at the point of execution of the selected frame.
4498
c906108c 4499@kindex info catch
d4f3574e
SS
4500@cindex catch exceptions, list active handlers
4501@cindex exception handlers, how to list
c906108c
SS
4502@item info catch
4503Print a list of all the exception handlers that are active in the
4504current stack frame at the current point of execution. To see other
4505exception handlers, visit the associated frame (using the @code{up},
4506@code{down}, or @code{frame} commands); then type @code{info catch}.
4507@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4508
c906108c
SS
4509@end table
4510
c906108c 4511
6d2ebf8b 4512@node Source
c906108c
SS
4513@chapter Examining Source Files
4514
4515@value{GDBN} can print parts of your program's source, since the debugging
4516information recorded in the program tells @value{GDBN} what source files were
4517used to build it. When your program stops, @value{GDBN} spontaneously prints
4518the line where it stopped. Likewise, when you select a stack frame
4519(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4520execution in that frame has stopped. You can print other portions of
4521source files by explicit command.
4522
7a292a7a 4523If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4524prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4525@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4526
4527@menu
4528* List:: Printing source lines
87885426 4529* Edit:: Editing source files
c906108c 4530* Search:: Searching source files
c906108c
SS
4531* Source Path:: Specifying source directories
4532* Machine Code:: Source and machine code
4533@end menu
4534
6d2ebf8b 4535@node List
c906108c
SS
4536@section Printing source lines
4537
4538@kindex list
41afff9a 4539@kindex l @r{(@code{list})}
c906108c 4540To print lines from a source file, use the @code{list} command
5d161b24 4541(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4542There are several ways to specify what part of the file you want to print.
4543
4544Here are the forms of the @code{list} command most commonly used:
4545
4546@table @code
4547@item list @var{linenum}
4548Print lines centered around line number @var{linenum} in the
4549current source file.
4550
4551@item list @var{function}
4552Print lines centered around the beginning of function
4553@var{function}.
4554
4555@item list
4556Print more lines. If the last lines printed were printed with a
4557@code{list} command, this prints lines following the last lines
4558printed; however, if the last line printed was a solitary line printed
4559as part of displaying a stack frame (@pxref{Stack, ,Examining the
4560Stack}), this prints lines centered around that line.
4561
4562@item list -
4563Print lines just before the lines last printed.
4564@end table
4565
9c16f35a 4566@cindex @code{list}, how many lines to display
c906108c
SS
4567By default, @value{GDBN} prints ten source lines with any of these forms of
4568the @code{list} command. You can change this using @code{set listsize}:
4569
4570@table @code
4571@kindex set listsize
4572@item set listsize @var{count}
4573Make the @code{list} command display @var{count} source lines (unless
4574the @code{list} argument explicitly specifies some other number).
4575
4576@kindex show listsize
4577@item show listsize
4578Display the number of lines that @code{list} prints.
4579@end table
4580
4581Repeating a @code{list} command with @key{RET} discards the argument,
4582so it is equivalent to typing just @code{list}. This is more useful
4583than listing the same lines again. An exception is made for an
4584argument of @samp{-}; that argument is preserved in repetition so that
4585each repetition moves up in the source file.
4586
4587@cindex linespec
4588In general, the @code{list} command expects you to supply zero, one or two
4589@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4590of writing them, but the effect is always to specify some source line.
c906108c
SS
4591Here is a complete description of the possible arguments for @code{list}:
4592
4593@table @code
4594@item list @var{linespec}
4595Print lines centered around the line specified by @var{linespec}.
4596
4597@item list @var{first},@var{last}
4598Print lines from @var{first} to @var{last}. Both arguments are
4599linespecs.
4600
4601@item list ,@var{last}
4602Print lines ending with @var{last}.
4603
4604@item list @var{first},
4605Print lines starting with @var{first}.
4606
4607@item list +
4608Print lines just after the lines last printed.
4609
4610@item list -
4611Print lines just before the lines last printed.
4612
4613@item list
4614As described in the preceding table.
4615@end table
4616
4617Here are the ways of specifying a single source line---all the
4618kinds of linespec.
4619
4620@table @code
4621@item @var{number}
4622Specifies line @var{number} of the current source file.
4623When a @code{list} command has two linespecs, this refers to
4624the same source file as the first linespec.
4625
4626@item +@var{offset}
4627Specifies the line @var{offset} lines after the last line printed.
4628When used as the second linespec in a @code{list} command that has
4629two, this specifies the line @var{offset} lines down from the
4630first linespec.
4631
4632@item -@var{offset}
4633Specifies the line @var{offset} lines before the last line printed.
4634
4635@item @var{filename}:@var{number}
4636Specifies line @var{number} in the source file @var{filename}.
4637
4638@item @var{function}
4639Specifies the line that begins the body of the function @var{function}.
4640For example: in C, this is the line with the open brace.
4641
4642@item @var{filename}:@var{function}
4643Specifies the line of the open-brace that begins the body of the
4644function @var{function} in the file @var{filename}. You only need the
4645file name with a function name to avoid ambiguity when there are
4646identically named functions in different source files.
4647
4648@item *@var{address}
4649Specifies the line containing the program address @var{address}.
4650@var{address} may be any expression.
4651@end table
4652
87885426
FN
4653@node Edit
4654@section Editing source files
4655@cindex editing source files
4656
4657@kindex edit
4658@kindex e @r{(@code{edit})}
4659To edit the lines in a source file, use the @code{edit} command.
4660The editing program of your choice
4661is invoked with the current line set to
4662the active line in the program.
4663Alternatively, there are several ways to specify what part of the file you
4664want to print if you want to see other parts of the program.
4665
4666Here are the forms of the @code{edit} command most commonly used:
4667
4668@table @code
4669@item edit
4670Edit the current source file at the active line number in the program.
4671
4672@item edit @var{number}
4673Edit the current source file with @var{number} as the active line number.
4674
4675@item edit @var{function}
4676Edit the file containing @var{function} at the beginning of its definition.
4677
4678@item edit @var{filename}:@var{number}
4679Specifies line @var{number} in the source file @var{filename}.
4680
4681@item edit @var{filename}:@var{function}
4682Specifies the line that begins the body of the
4683function @var{function} in the file @var{filename}. You only need the
4684file name with a function name to avoid ambiguity when there are
4685identically named functions in different source files.
4686
4687@item edit *@var{address}
4688Specifies the line containing the program address @var{address}.
4689@var{address} may be any expression.
4690@end table
4691
4692@subsection Choosing your editor
4693You can customize @value{GDBN} to use any editor you want
4694@footnote{
4695The only restriction is that your editor (say @code{ex}), recognizes the
4696following command-line syntax:
10998722 4697@smallexample
87885426 4698ex +@var{number} file
10998722 4699@end smallexample
15387254
EZ
4700The optional numeric value +@var{number} specifies the number of the line in
4701the file where to start editing.}.
4702By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4703by setting the environment variable @code{EDITOR} before using
4704@value{GDBN}. For example, to configure @value{GDBN} to use the
4705@code{vi} editor, you could use these commands with the @code{sh} shell:
4706@smallexample
87885426
FN
4707EDITOR=/usr/bin/vi
4708export EDITOR
15387254 4709gdb @dots{}
10998722 4710@end smallexample
87885426 4711or in the @code{csh} shell,
10998722 4712@smallexample
87885426 4713setenv EDITOR /usr/bin/vi
15387254 4714gdb @dots{}
10998722 4715@end smallexample
87885426 4716
6d2ebf8b 4717@node Search
c906108c 4718@section Searching source files
15387254 4719@cindex searching source files
c906108c
SS
4720
4721There are two commands for searching through the current source file for a
4722regular expression.
4723
4724@table @code
4725@kindex search
4726@kindex forward-search
4727@item forward-search @var{regexp}
4728@itemx search @var{regexp}
4729The command @samp{forward-search @var{regexp}} checks each line,
4730starting with the one following the last line listed, for a match for
5d161b24 4731@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4732synonym @samp{search @var{regexp}} or abbreviate the command name as
4733@code{fo}.
4734
09d4efe1 4735@kindex reverse-search
c906108c
SS
4736@item reverse-search @var{regexp}
4737The command @samp{reverse-search @var{regexp}} checks each line, starting
4738with the one before the last line listed and going backward, for a match
4739for @var{regexp}. It lists the line that is found. You can abbreviate
4740this command as @code{rev}.
4741@end table
c906108c 4742
6d2ebf8b 4743@node Source Path
c906108c
SS
4744@section Specifying source directories
4745
4746@cindex source path
4747@cindex directories for source files
4748Executable programs sometimes do not record the directories of the source
4749files from which they were compiled, just the names. Even when they do,
4750the directories could be moved between the compilation and your debugging
4751session. @value{GDBN} has a list of directories to search for source files;
4752this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4753it tries all the directories in the list, in the order they are present
0b66e38c
EZ
4754in the list, until it finds a file with the desired name.
4755
4756For example, suppose an executable references the file
4757@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4758@file{/mnt/cross}. The file is first looked up literally; if this
4759fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4760fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4761message is printed. @value{GDBN} does not look up the parts of the
4762source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4763Likewise, the subdirectories of the source path are not searched: if
4764the source path is @file{/mnt/cross}, and the binary refers to
4765@file{foo.c}, @value{GDBN} would not find it under
4766@file{/mnt/cross/usr/src/foo-1.0/lib}.
4767
4768Plain file names, relative file names with leading directories, file
4769names containing dots, etc.@: are all treated as described above; for
4770instance, if the source path is @file{/mnt/cross}, and the source file
4771is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4772@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4773that---@file{/mnt/cross/foo.c}.
4774
4775Note that the executable search path is @emph{not} used to locate the
4776source files. Neither is the current working directory, unless it
4777happens to be in the source path.
c906108c
SS
4778
4779Whenever you reset or rearrange the source path, @value{GDBN} clears out
4780any information it has cached about where source files are found and where
4781each line is in the file.
4782
4783@kindex directory
4784@kindex dir
d4f3574e
SS
4785When you start @value{GDBN}, its source path includes only @samp{cdir}
4786and @samp{cwd}, in that order.
c906108c
SS
4787To add other directories, use the @code{directory} command.
4788
4789@table @code
4790@item directory @var{dirname} @dots{}
4791@item dir @var{dirname} @dots{}
4792Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4793directory names may be given to this command, separated by @samp{:}
4794(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4795part of absolute file names) or
c906108c
SS
4796whitespace. You may specify a directory that is already in the source
4797path; this moves it forward, so @value{GDBN} searches it sooner.
4798
4799@kindex cdir
4800@kindex cwd
41afff9a
EZ
4801@vindex $cdir@r{, convenience variable}
4802@vindex $cwdr@r{, convenience variable}
c906108c
SS
4803@cindex compilation directory
4804@cindex current directory
4805@cindex working directory
4806@cindex directory, current
4807@cindex directory, compilation
4808You can use the string @samp{$cdir} to refer to the compilation
4809directory (if one is recorded), and @samp{$cwd} to refer to the current
4810working directory. @samp{$cwd} is not the same as @samp{.}---the former
4811tracks the current working directory as it changes during your @value{GDBN}
4812session, while the latter is immediately expanded to the current
4813directory at the time you add an entry to the source path.
4814
4815@item directory
4816Reset the source path to empty again. This requires confirmation.
4817
4818@c RET-repeat for @code{directory} is explicitly disabled, but since
4819@c repeating it would be a no-op we do not say that. (thanks to RMS)
4820
4821@item show directories
4822@kindex show directories
4823Print the source path: show which directories it contains.
4824@end table
4825
4826If your source path is cluttered with directories that are no longer of
4827interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4828versions of source. You can correct the situation as follows:
4829
4830@enumerate
4831@item
4832Use @code{directory} with no argument to reset the source path to empty.
4833
4834@item
4835Use @code{directory} with suitable arguments to reinstall the
4836directories you want in the source path. You can add all the
4837directories in one command.
4838@end enumerate
4839
6d2ebf8b 4840@node Machine Code
c906108c 4841@section Source and machine code
15387254 4842@cindex source line and its code address
c906108c
SS
4843
4844You can use the command @code{info line} to map source lines to program
4845addresses (and vice versa), and the command @code{disassemble} to display
4846a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4847mode, the @code{info line} command causes the arrow to point to the
5d161b24 4848line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4849well as hex.
4850
4851@table @code
4852@kindex info line
4853@item info line @var{linespec}
4854Print the starting and ending addresses of the compiled code for
4855source line @var{linespec}. You can specify source lines in any of
4856the ways understood by the @code{list} command (@pxref{List, ,Printing
4857source lines}).
4858@end table
4859
4860For example, we can use @code{info line} to discover the location of
4861the object code for the first line of function
4862@code{m4_changequote}:
4863
d4f3574e
SS
4864@c FIXME: I think this example should also show the addresses in
4865@c symbolic form, as they usually would be displayed.
c906108c 4866@smallexample
96a2c332 4867(@value{GDBP}) info line m4_changequote
c906108c
SS
4868Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4869@end smallexample
4870
4871@noindent
15387254 4872@cindex code address and its source line
c906108c
SS
4873We can also inquire (using @code{*@var{addr}} as the form for
4874@var{linespec}) what source line covers a particular address:
4875@smallexample
4876(@value{GDBP}) info line *0x63ff
4877Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4878@end smallexample
4879
4880@cindex @code{$_} and @code{info line}
15387254 4881@cindex @code{x} command, default address
41afff9a 4882@kindex x@r{(examine), and} info line
c906108c
SS
4883After @code{info line}, the default address for the @code{x} command
4884is changed to the starting address of the line, so that @samp{x/i} is
4885sufficient to begin examining the machine code (@pxref{Memory,
4886,Examining memory}). Also, this address is saved as the value of the
4887convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4888variables}).
4889
4890@table @code
4891@kindex disassemble
4892@cindex assembly instructions
4893@cindex instructions, assembly
4894@cindex machine instructions
4895@cindex listing machine instructions
4896@item disassemble
4897This specialized command dumps a range of memory as machine
4898instructions. The default memory range is the function surrounding the
4899program counter of the selected frame. A single argument to this
4900command is a program counter value; @value{GDBN} dumps the function
4901surrounding this value. Two arguments specify a range of addresses
4902(first inclusive, second exclusive) to dump.
4903@end table
4904
c906108c
SS
4905The following example shows the disassembly of a range of addresses of
4906HP PA-RISC 2.0 code:
4907
4908@smallexample
4909(@value{GDBP}) disas 0x32c4 0x32e4
4910Dump of assembler code from 0x32c4 to 0x32e4:
49110x32c4 <main+204>: addil 0,dp
49120x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
49130x32cc <main+212>: ldil 0x3000,r31
49140x32d0 <main+216>: ble 0x3f8(sr4,r31)
49150x32d4 <main+220>: ldo 0(r31),rp
49160x32d8 <main+224>: addil -0x800,dp
49170x32dc <main+228>: ldo 0x588(r1),r26
49180x32e0 <main+232>: ldil 0x3000,r31
4919End of assembler dump.
4920@end smallexample
c906108c
SS
4921
4922Some architectures have more than one commonly-used set of instruction
4923mnemonics or other syntax.
4924
4925@table @code
d4f3574e 4926@kindex set disassembly-flavor
d4f3574e
SS
4927@cindex Intel disassembly flavor
4928@cindex AT&T disassembly flavor
4929@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4930Select the instruction set to use when disassembling the
4931program via the @code{disassemble} or @code{x/i} commands.
4932
4933Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4934can set @var{instruction-set} to either @code{intel} or @code{att}.
4935The default is @code{att}, the AT&T flavor used by default by Unix
4936assemblers for x86-based targets.
9c16f35a
EZ
4937
4938@kindex show disassembly-flavor
4939@item show disassembly-flavor
4940Show the current setting of the disassembly flavor.
c906108c
SS
4941@end table
4942
4943
6d2ebf8b 4944@node Data
c906108c
SS
4945@chapter Examining Data
4946
4947@cindex printing data
4948@cindex examining data
4949@kindex print
4950@kindex inspect
4951@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4952@c document because it is nonstandard... Under Epoch it displays in a
4953@c different window or something like that.
4954The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4955command (abbreviated @code{p}), or its synonym @code{inspect}. It
4956evaluates and prints the value of an expression of the language your
4957program is written in (@pxref{Languages, ,Using @value{GDBN} with
4958Different Languages}).
c906108c
SS
4959
4960@table @code
d4f3574e
SS
4961@item print @var{expr}
4962@itemx print /@var{f} @var{expr}
4963@var{expr} is an expression (in the source language). By default the
4964value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4965you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4966@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4967formats}.
4968
4969@item print
4970@itemx print /@var{f}
15387254 4971@cindex reprint the last value
d4f3574e 4972If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4973@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4974conveniently inspect the same value in an alternative format.
4975@end table
4976
4977A more low-level way of examining data is with the @code{x} command.
4978It examines data in memory at a specified address and prints it in a
4979specified format. @xref{Memory, ,Examining memory}.
4980
7a292a7a 4981If you are interested in information about types, or about how the
d4f3574e
SS
4982fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4983command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4984Table}.
c906108c
SS
4985
4986@menu
4987* Expressions:: Expressions
4988* Variables:: Program variables
4989* Arrays:: Artificial arrays
4990* Output Formats:: Output formats
4991* Memory:: Examining memory
4992* Auto Display:: Automatic display
4993* Print Settings:: Print settings
4994* Value History:: Value history
4995* Convenience Vars:: Convenience variables
4996* Registers:: Registers
c906108c 4997* Floating Point Hardware:: Floating point hardware
53c69bd7 4998* Vector Unit:: Vector Unit
721c2651 4999* OS Information:: Auxiliary data provided by operating system
29e57380 5000* Memory Region Attributes:: Memory region attributes
16d9dec6 5001* Dump/Restore Files:: Copy between memory and a file
384ee23f 5002* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
5003* Character Sets:: Debugging programs that use a different
5004 character set than GDB does
09d4efe1 5005* Caching Remote Data:: Data caching for remote targets
c906108c
SS
5006@end menu
5007
6d2ebf8b 5008@node Expressions
c906108c
SS
5009@section Expressions
5010
5011@cindex expressions
5012@code{print} and many other @value{GDBN} commands accept an expression and
5013compute its value. Any kind of constant, variable or operator defined
5014by the programming language you are using is valid in an expression in
e2e0bcd1
JB
5015@value{GDBN}. This includes conditional expressions, function calls,
5016casts, and string constants. It also includes preprocessor macros, if
5017you compiled your program to include this information; see
5018@ref{Compilation}.
c906108c 5019
15387254 5020@cindex arrays in expressions
d4f3574e
SS
5021@value{GDBN} supports array constants in expressions input by
5022the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 5023you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 5024memory that is @code{malloc}ed in the target program.
c906108c 5025
c906108c
SS
5026Because C is so widespread, most of the expressions shown in examples in
5027this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
5028Languages}, for information on how to use expressions in other
5029languages.
5030
5031In this section, we discuss operators that you can use in @value{GDBN}
5032expressions regardless of your programming language.
5033
15387254 5034@cindex casts, in expressions
c906108c
SS
5035Casts are supported in all languages, not just in C, because it is so
5036useful to cast a number into a pointer in order to examine a structure
5037at that address in memory.
5038@c FIXME: casts supported---Mod2 true?
c906108c
SS
5039
5040@value{GDBN} supports these operators, in addition to those common
5041to programming languages:
5042
5043@table @code
5044@item @@
5045@samp{@@} is a binary operator for treating parts of memory as arrays.
5046@xref{Arrays, ,Artificial arrays}, for more information.
5047
5048@item ::
5049@samp{::} allows you to specify a variable in terms of the file or
5050function where it is defined. @xref{Variables, ,Program variables}.
5051
5052@cindex @{@var{type}@}
5053@cindex type casting memory
5054@cindex memory, viewing as typed object
5055@cindex casts, to view memory
5056@item @{@var{type}@} @var{addr}
5057Refers to an object of type @var{type} stored at address @var{addr} in
5058memory. @var{addr} may be any expression whose value is an integer or
5059pointer (but parentheses are required around binary operators, just as in
5060a cast). This construct is allowed regardless of what kind of data is
5061normally supposed to reside at @var{addr}.
5062@end table
5063
6d2ebf8b 5064@node Variables
c906108c
SS
5065@section Program variables
5066
5067The most common kind of expression to use is the name of a variable
5068in your program.
5069
5070Variables in expressions are understood in the selected stack frame
5071(@pxref{Selection, ,Selecting a frame}); they must be either:
5072
5073@itemize @bullet
5074@item
5075global (or file-static)
5076@end itemize
5077
5d161b24 5078@noindent or
c906108c
SS
5079
5080@itemize @bullet
5081@item
5082visible according to the scope rules of the
5083programming language from the point of execution in that frame
5d161b24 5084@end itemize
c906108c
SS
5085
5086@noindent This means that in the function
5087
474c8240 5088@smallexample
c906108c
SS
5089foo (a)
5090 int a;
5091@{
5092 bar (a);
5093 @{
5094 int b = test ();
5095 bar (b);
5096 @}
5097@}
474c8240 5098@end smallexample
c906108c
SS
5099
5100@noindent
5101you can examine and use the variable @code{a} whenever your program is
5102executing within the function @code{foo}, but you can only use or
5103examine the variable @code{b} while your program is executing inside
5104the block where @code{b} is declared.
5105
5106@cindex variable name conflict
5107There is an exception: you can refer to a variable or function whose
5108scope is a single source file even if the current execution point is not
5109in this file. But it is possible to have more than one such variable or
5110function with the same name (in different source files). If that
5111happens, referring to that name has unpredictable effects. If you wish,
5112you can specify a static variable in a particular function or file,
15387254 5113using the colon-colon (@code{::}) notation:
c906108c 5114
d4f3574e 5115@cindex colon-colon, context for variables/functions
c906108c
SS
5116@iftex
5117@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 5118@cindex @code{::}, context for variables/functions
c906108c 5119@end iftex
474c8240 5120@smallexample
c906108c
SS
5121@var{file}::@var{variable}
5122@var{function}::@var{variable}
474c8240 5123@end smallexample
c906108c
SS
5124
5125@noindent
5126Here @var{file} or @var{function} is the name of the context for the
5127static @var{variable}. In the case of file names, you can use quotes to
5128make sure @value{GDBN} parses the file name as a single word---for example,
5129to print a global value of @code{x} defined in @file{f2.c}:
5130
474c8240 5131@smallexample
c906108c 5132(@value{GDBP}) p 'f2.c'::x
474c8240 5133@end smallexample
c906108c 5134
b37052ae 5135@cindex C@t{++} scope resolution
c906108c 5136This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 5137use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
5138scope resolution operator in @value{GDBN} expressions.
5139@c FIXME: Um, so what happens in one of those rare cases where it's in
5140@c conflict?? --mew
c906108c
SS
5141
5142@cindex wrong values
5143@cindex variable values, wrong
15387254
EZ
5144@cindex function entry/exit, wrong values of variables
5145@cindex optimized code, wrong values of variables
c906108c
SS
5146@quotation
5147@emph{Warning:} Occasionally, a local variable may appear to have the
5148wrong value at certain points in a function---just after entry to a new
5149scope, and just before exit.
5150@end quotation
5151You may see this problem when you are stepping by machine instructions.
5152This is because, on most machines, it takes more than one instruction to
5153set up a stack frame (including local variable definitions); if you are
5154stepping by machine instructions, variables may appear to have the wrong
5155values until the stack frame is completely built. On exit, it usually
5156also takes more than one machine instruction to destroy a stack frame;
5157after you begin stepping through that group of instructions, local
5158variable definitions may be gone.
5159
5160This may also happen when the compiler does significant optimizations.
5161To be sure of always seeing accurate values, turn off all optimization
5162when compiling.
5163
d4f3574e
SS
5164@cindex ``No symbol "foo" in current context''
5165Another possible effect of compiler optimizations is to optimize
5166unused variables out of existence, or assign variables to registers (as
5167opposed to memory addresses). Depending on the support for such cases
5168offered by the debug info format used by the compiler, @value{GDBN}
5169might not be able to display values for such local variables. If that
5170happens, @value{GDBN} will print a message like this:
5171
474c8240 5172@smallexample
d4f3574e 5173No symbol "foo" in current context.
474c8240 5174@end smallexample
d4f3574e
SS
5175
5176To solve such problems, either recompile without optimizations, or use a
5177different debug info format, if the compiler supports several such
15387254 5178formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
5179usually supports the @option{-gstabs+} option. @option{-gstabs+}
5180produces debug info in a format that is superior to formats such as
5181COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5182an effective form for debug info. @xref{Debugging Options,,Options
5183for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
5184@xref{C, , Debugging C++}, for more info about debug info formats
5185that are best suited to C@t{++} programs.
d4f3574e 5186
6d2ebf8b 5187@node Arrays
c906108c
SS
5188@section Artificial arrays
5189
5190@cindex artificial array
15387254 5191@cindex arrays
41afff9a 5192@kindex @@@r{, referencing memory as an array}
c906108c
SS
5193It is often useful to print out several successive objects of the
5194same type in memory; a section of an array, or an array of
5195dynamically determined size for which only a pointer exists in the
5196program.
5197
5198You can do this by referring to a contiguous span of memory as an
5199@dfn{artificial array}, using the binary operator @samp{@@}. The left
5200operand of @samp{@@} should be the first element of the desired array
5201and be an individual object. The right operand should be the desired length
5202of the array. The result is an array value whose elements are all of
5203the type of the left argument. The first element is actually the left
5204argument; the second element comes from bytes of memory immediately
5205following those that hold the first element, and so on. Here is an
5206example. If a program says
5207
474c8240 5208@smallexample
c906108c 5209int *array = (int *) malloc (len * sizeof (int));
474c8240 5210@end smallexample
c906108c
SS
5211
5212@noindent
5213you can print the contents of @code{array} with
5214
474c8240 5215@smallexample
c906108c 5216p *array@@len
474c8240 5217@end smallexample
c906108c
SS
5218
5219The left operand of @samp{@@} must reside in memory. Array values made
5220with @samp{@@} in this way behave just like other arrays in terms of
5221subscripting, and are coerced to pointers when used in expressions.
5222Artificial arrays most often appear in expressions via the value history
5223(@pxref{Value History, ,Value history}), after printing one out.
5224
5225Another way to create an artificial array is to use a cast.
5226This re-interprets a value as if it were an array.
5227The value need not be in memory:
474c8240 5228@smallexample
c906108c
SS
5229(@value{GDBP}) p/x (short[2])0x12345678
5230$1 = @{0x1234, 0x5678@}
474c8240 5231@end smallexample
c906108c
SS
5232
5233As a convenience, if you leave the array length out (as in
c3f6f71d 5234@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5235the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5236@smallexample
c906108c
SS
5237(@value{GDBP}) p/x (short[])0x12345678
5238$2 = @{0x1234, 0x5678@}
474c8240 5239@end smallexample
c906108c
SS
5240
5241Sometimes the artificial array mechanism is not quite enough; in
5242moderately complex data structures, the elements of interest may not
5243actually be adjacent---for example, if you are interested in the values
5244of pointers in an array. One useful work-around in this situation is
5245to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5246variables}) as a counter in an expression that prints the first
5247interesting value, and then repeat that expression via @key{RET}. For
5248instance, suppose you have an array @code{dtab} of pointers to
5249structures, and you are interested in the values of a field @code{fv}
5250in each structure. Here is an example of what you might type:
5251
474c8240 5252@smallexample
c906108c
SS
5253set $i = 0
5254p dtab[$i++]->fv
5255@key{RET}
5256@key{RET}
5257@dots{}
474c8240 5258@end smallexample
c906108c 5259
6d2ebf8b 5260@node Output Formats
c906108c
SS
5261@section Output formats
5262
5263@cindex formatted output
5264@cindex output formats
5265By default, @value{GDBN} prints a value according to its data type. Sometimes
5266this is not what you want. For example, you might want to print a number
5267in hex, or a pointer in decimal. Or you might want to view data in memory
5268at a certain address as a character string or as an instruction. To do
5269these things, specify an @dfn{output format} when you print a value.
5270
5271The simplest use of output formats is to say how to print a value
5272already computed. This is done by starting the arguments of the
5273@code{print} command with a slash and a format letter. The format
5274letters supported are:
5275
5276@table @code
5277@item x
5278Regard the bits of the value as an integer, and print the integer in
5279hexadecimal.
5280
5281@item d
5282Print as integer in signed decimal.
5283
5284@item u
5285Print as integer in unsigned decimal.
5286
5287@item o
5288Print as integer in octal.
5289
5290@item t
5291Print as integer in binary. The letter @samp{t} stands for ``two''.
5292@footnote{@samp{b} cannot be used because these format letters are also
5293used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5294see @ref{Memory,,Examining memory}.}
c906108c
SS
5295
5296@item a
5297@cindex unknown address, locating
3d67e040 5298@cindex locate address
c906108c
SS
5299Print as an address, both absolute in hexadecimal and as an offset from
5300the nearest preceding symbol. You can use this format used to discover
5301where (in what function) an unknown address is located:
5302
474c8240 5303@smallexample
c906108c
SS
5304(@value{GDBP}) p/a 0x54320
5305$3 = 0x54320 <_initialize_vx+396>
474c8240 5306@end smallexample
c906108c 5307
3d67e040
EZ
5308@noindent
5309The command @code{info symbol 0x54320} yields similar results.
5310@xref{Symbols, info symbol}.
5311
c906108c 5312@item c
51274035
EZ
5313Regard as an integer and print it as a character constant. This
5314prints both the numerical value and its character representation. The
5315character representation is replaced with the octal escape @samp{\nnn}
5316for characters outside the 7-bit @sc{ascii} range.
c906108c
SS
5317
5318@item f
5319Regard the bits of the value as a floating point number and print
5320using typical floating point syntax.
5321@end table
5322
5323For example, to print the program counter in hex (@pxref{Registers}), type
5324
474c8240 5325@smallexample
c906108c 5326p/x $pc
474c8240 5327@end smallexample
c906108c
SS
5328
5329@noindent
5330Note that no space is required before the slash; this is because command
5331names in @value{GDBN} cannot contain a slash.
5332
5333To reprint the last value in the value history with a different format,
5334you can use the @code{print} command with just a format and no
5335expression. For example, @samp{p/x} reprints the last value in hex.
5336
6d2ebf8b 5337@node Memory
c906108c
SS
5338@section Examining memory
5339
5340You can use the command @code{x} (for ``examine'') to examine memory in
5341any of several formats, independently of your program's data types.
5342
5343@cindex examining memory
5344@table @code
41afff9a 5345@kindex x @r{(examine memory)}
c906108c
SS
5346@item x/@var{nfu} @var{addr}
5347@itemx x @var{addr}
5348@itemx x
5349Use the @code{x} command to examine memory.
5350@end table
5351
5352@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5353much memory to display and how to format it; @var{addr} is an
5354expression giving the address where you want to start displaying memory.
5355If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5356Several commands set convenient defaults for @var{addr}.
5357
5358@table @r
5359@item @var{n}, the repeat count
5360The repeat count is a decimal integer; the default is 1. It specifies
5361how much memory (counting by units @var{u}) to display.
5362@c This really is **decimal**; unaffected by 'set radix' as of GDB
5363@c 4.1.2.
5364
5365@item @var{f}, the display format
51274035
EZ
5366The display format is one of the formats used by @code{print}
5367(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
5368@samp{f}), and in addition @samp{s} (for null-terminated strings) and
5369@samp{i} (for machine instructions). The default is @samp{x}
5370(hexadecimal) initially. The default changes each time you use either
5371@code{x} or @code{print}.
c906108c
SS
5372
5373@item @var{u}, the unit size
5374The unit size is any of
5375
5376@table @code
5377@item b
5378Bytes.
5379@item h
5380Halfwords (two bytes).
5381@item w
5382Words (four bytes). This is the initial default.
5383@item g
5384Giant words (eight bytes).
5385@end table
5386
5387Each time you specify a unit size with @code{x}, that size becomes the
5388default unit the next time you use @code{x}. (For the @samp{s} and
5389@samp{i} formats, the unit size is ignored and is normally not written.)
5390
5391@item @var{addr}, starting display address
5392@var{addr} is the address where you want @value{GDBN} to begin displaying
5393memory. The expression need not have a pointer value (though it may);
5394it is always interpreted as an integer address of a byte of memory.
5395@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5396@var{addr} is usually just after the last address examined---but several
5397other commands also set the default address: @code{info breakpoints} (to
5398the address of the last breakpoint listed), @code{info line} (to the
5399starting address of a line), and @code{print} (if you use it to display
5400a value from memory).
5401@end table
5402
5403For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5404(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5405starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5406words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5407@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5408
5409Since the letters indicating unit sizes are all distinct from the
5410letters specifying output formats, you do not have to remember whether
5411unit size or format comes first; either order works. The output
5412specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5413(However, the count @var{n} must come first; @samp{wx4} does not work.)
5414
5415Even though the unit size @var{u} is ignored for the formats @samp{s}
5416and @samp{i}, you might still want to use a count @var{n}; for example,
5417@samp{3i} specifies that you want to see three machine instructions,
5418including any operands. The command @code{disassemble} gives an
d4f3574e 5419alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5420Code,,Source and machine code}.
5421
5422All the defaults for the arguments to @code{x} are designed to make it
5423easy to continue scanning memory with minimal specifications each time
5424you use @code{x}. For example, after you have inspected three machine
5425instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5426with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5427the repeat count @var{n} is used again; the other arguments default as
5428for successive uses of @code{x}.
5429
5430@cindex @code{$_}, @code{$__}, and value history
5431The addresses and contents printed by the @code{x} command are not saved
5432in the value history because there is often too much of them and they
5433would get in the way. Instead, @value{GDBN} makes these values available for
5434subsequent use in expressions as values of the convenience variables
5435@code{$_} and @code{$__}. After an @code{x} command, the last address
5436examined is available for use in expressions in the convenience variable
5437@code{$_}. The contents of that address, as examined, are available in
5438the convenience variable @code{$__}.
5439
5440If the @code{x} command has a repeat count, the address and contents saved
5441are from the last memory unit printed; this is not the same as the last
5442address printed if several units were printed on the last line of output.
5443
09d4efe1
EZ
5444@cindex remote memory comparison
5445@cindex verify remote memory image
5446When you are debugging a program running on a remote target machine
5447(@pxref{Remote}), you may wish to verify the program's image in the
5448remote machine's memory against the executable file you downloaded to
5449the target. The @code{compare-sections} command is provided for such
5450situations.
5451
5452@table @code
5453@kindex compare-sections
5454@item compare-sections @r{[}@var{section-name}@r{]}
5455Compare the data of a loadable section @var{section-name} in the
5456executable file of the program being debugged with the same section in
5457the remote machine's memory, and report any mismatches. With no
5458arguments, compares all loadable sections. This command's
5459availability depends on the target's support for the @code{"qCRC"}
5460remote request.
5461@end table
5462
6d2ebf8b 5463@node Auto Display
c906108c
SS
5464@section Automatic display
5465@cindex automatic display
5466@cindex display of expressions
5467
5468If you find that you want to print the value of an expression frequently
5469(to see how it changes), you might want to add it to the @dfn{automatic
5470display list} so that @value{GDBN} prints its value each time your program stops.
5471Each expression added to the list is given a number to identify it;
5472to remove an expression from the list, you specify that number.
5473The automatic display looks like this:
5474
474c8240 5475@smallexample
c906108c
SS
54762: foo = 38
54773: bar[5] = (struct hack *) 0x3804
474c8240 5478@end smallexample
c906108c
SS
5479
5480@noindent
5481This display shows item numbers, expressions and their current values. As with
5482displays you request manually using @code{x} or @code{print}, you can
5483specify the output format you prefer; in fact, @code{display} decides
5484whether to use @code{print} or @code{x} depending on how elaborate your
5485format specification is---it uses @code{x} if you specify a unit size,
5486or one of the two formats (@samp{i} and @samp{s}) that are only
5487supported by @code{x}; otherwise it uses @code{print}.
5488
5489@table @code
5490@kindex display
d4f3574e
SS
5491@item display @var{expr}
5492Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5493each time your program stops. @xref{Expressions, ,Expressions}.
5494
5495@code{display} does not repeat if you press @key{RET} again after using it.
5496
d4f3574e 5497@item display/@var{fmt} @var{expr}
c906108c 5498For @var{fmt} specifying only a display format and not a size or
d4f3574e 5499count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5500arrange to display it each time in the specified format @var{fmt}.
5501@xref{Output Formats,,Output formats}.
5502
5503@item display/@var{fmt} @var{addr}
5504For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5505number of units, add the expression @var{addr} as a memory address to
5506be examined each time your program stops. Examining means in effect
5507doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5508@end table
5509
5510For example, @samp{display/i $pc} can be helpful, to see the machine
5511instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5512is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5513
5514@table @code
5515@kindex delete display
5516@kindex undisplay
5517@item undisplay @var{dnums}@dots{}
5518@itemx delete display @var{dnums}@dots{}
5519Remove item numbers @var{dnums} from the list of expressions to display.
5520
5521@code{undisplay} does not repeat if you press @key{RET} after using it.
5522(Otherwise you would just get the error @samp{No display number @dots{}}.)
5523
5524@kindex disable display
5525@item disable display @var{dnums}@dots{}
5526Disable the display of item numbers @var{dnums}. A disabled display
5527item is not printed automatically, but is not forgotten. It may be
5528enabled again later.
5529
5530@kindex enable display
5531@item enable display @var{dnums}@dots{}
5532Enable display of item numbers @var{dnums}. It becomes effective once
5533again in auto display of its expression, until you specify otherwise.
5534
5535@item display
5536Display the current values of the expressions on the list, just as is
5537done when your program stops.
5538
5539@kindex info display
5540@item info display
5541Print the list of expressions previously set up to display
5542automatically, each one with its item number, but without showing the
5543values. This includes disabled expressions, which are marked as such.
5544It also includes expressions which would not be displayed right now
5545because they refer to automatic variables not currently available.
5546@end table
5547
15387254 5548@cindex display disabled out of scope
c906108c
SS
5549If a display expression refers to local variables, then it does not make
5550sense outside the lexical context for which it was set up. Such an
5551expression is disabled when execution enters a context where one of its
5552variables is not defined. For example, if you give the command
5553@code{display last_char} while inside a function with an argument
5554@code{last_char}, @value{GDBN} displays this argument while your program
5555continues to stop inside that function. When it stops elsewhere---where
5556there is no variable @code{last_char}---the display is disabled
5557automatically. The next time your program stops where @code{last_char}
5558is meaningful, you can enable the display expression once again.
5559
6d2ebf8b 5560@node Print Settings
c906108c
SS
5561@section Print settings
5562
5563@cindex format options
5564@cindex print settings
5565@value{GDBN} provides the following ways to control how arrays, structures,
5566and symbols are printed.
5567
5568@noindent
5569These settings are useful for debugging programs in any language:
5570
5571@table @code
4644b6e3 5572@kindex set print
c906108c
SS
5573@item set print address
5574@itemx set print address on
4644b6e3 5575@cindex print/don't print memory addresses
c906108c
SS
5576@value{GDBN} prints memory addresses showing the location of stack
5577traces, structure values, pointer values, breakpoints, and so forth,
5578even when it also displays the contents of those addresses. The default
5579is @code{on}. For example, this is what a stack frame display looks like with
5580@code{set print address on}:
5581
5582@smallexample
5583@group
5584(@value{GDBP}) f
5585#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5586 at input.c:530
5587530 if (lquote != def_lquote)
5588@end group
5589@end smallexample
5590
5591@item set print address off
5592Do not print addresses when displaying their contents. For example,
5593this is the same stack frame displayed with @code{set print address off}:
5594
5595@smallexample
5596@group
5597(@value{GDBP}) set print addr off
5598(@value{GDBP}) f
5599#0 set_quotes (lq="<<", rq=">>") at input.c:530
5600530 if (lquote != def_lquote)
5601@end group
5602@end smallexample
5603
5604You can use @samp{set print address off} to eliminate all machine
5605dependent displays from the @value{GDBN} interface. For example, with
5606@code{print address off}, you should get the same text for backtraces on
5607all machines---whether or not they involve pointer arguments.
5608
4644b6e3 5609@kindex show print
c906108c
SS
5610@item show print address
5611Show whether or not addresses are to be printed.
5612@end table
5613
5614When @value{GDBN} prints a symbolic address, it normally prints the
5615closest earlier symbol plus an offset. If that symbol does not uniquely
5616identify the address (for example, it is a name whose scope is a single
5617source file), you may need to clarify. One way to do this is with
5618@code{info line}, for example @samp{info line *0x4537}. Alternately,
5619you can set @value{GDBN} to print the source file and line number when
5620it prints a symbolic address:
5621
5622@table @code
c906108c 5623@item set print symbol-filename on
9c16f35a
EZ
5624@cindex source file and line of a symbol
5625@cindex symbol, source file and line
c906108c
SS
5626Tell @value{GDBN} to print the source file name and line number of a
5627symbol in the symbolic form of an address.
5628
5629@item set print symbol-filename off
5630Do not print source file name and line number of a symbol. This is the
5631default.
5632
c906108c
SS
5633@item show print symbol-filename
5634Show whether or not @value{GDBN} will print the source file name and
5635line number of a symbol in the symbolic form of an address.
5636@end table
5637
5638Another situation where it is helpful to show symbol filenames and line
5639numbers is when disassembling code; @value{GDBN} shows you the line
5640number and source file that corresponds to each instruction.
5641
5642Also, you may wish to see the symbolic form only if the address being
5643printed is reasonably close to the closest earlier symbol:
5644
5645@table @code
c906108c 5646@item set print max-symbolic-offset @var{max-offset}
4644b6e3 5647@cindex maximum value for offset of closest symbol
c906108c
SS
5648Tell @value{GDBN} to only display the symbolic form of an address if the
5649offset between the closest earlier symbol and the address is less than
5d161b24 5650@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5651to always print the symbolic form of an address if any symbol precedes it.
5652
c906108c
SS
5653@item show print max-symbolic-offset
5654Ask how large the maximum offset is that @value{GDBN} prints in a
5655symbolic address.
5656@end table
5657
5658@cindex wild pointer, interpreting
5659@cindex pointer, finding referent
5660If you have a pointer and you are not sure where it points, try
5661@samp{set print symbol-filename on}. Then you can determine the name
5662and source file location of the variable where it points, using
5663@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5664For example, here @value{GDBN} shows that a variable @code{ptt} points
5665at another variable @code{t}, defined in @file{hi2.c}:
5666
474c8240 5667@smallexample
c906108c
SS
5668(@value{GDBP}) set print symbol-filename on
5669(@value{GDBP}) p/a ptt
5670$4 = 0xe008 <t in hi2.c>
474c8240 5671@end smallexample
c906108c
SS
5672
5673@quotation
5674@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5675does not show the symbol name and filename of the referent, even with
5676the appropriate @code{set print} options turned on.
5677@end quotation
5678
5679Other settings control how different kinds of objects are printed:
5680
5681@table @code
c906108c
SS
5682@item set print array
5683@itemx set print array on
4644b6e3 5684@cindex pretty print arrays
c906108c
SS
5685Pretty print arrays. This format is more convenient to read,
5686but uses more space. The default is off.
5687
5688@item set print array off
5689Return to compressed format for arrays.
5690
c906108c
SS
5691@item show print array
5692Show whether compressed or pretty format is selected for displaying
5693arrays.
5694
c906108c 5695@item set print elements @var{number-of-elements}
4644b6e3 5696@cindex number of array elements to print
9c16f35a 5697@cindex limit on number of printed array elements
c906108c
SS
5698Set a limit on how many elements of an array @value{GDBN} will print.
5699If @value{GDBN} is printing a large array, it stops printing after it has
5700printed the number of elements set by the @code{set print elements} command.
5701This limit also applies to the display of strings.
d4f3574e 5702When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5703Setting @var{number-of-elements} to zero means that the printing is unlimited.
5704
c906108c
SS
5705@item show print elements
5706Display the number of elements of a large array that @value{GDBN} will print.
5707If the number is 0, then the printing is unlimited.
5708
9c16f35a
EZ
5709@item set print repeats
5710@cindex repeated array elements
5711Set the threshold for suppressing display of repeated array
5712elelments. When the number of consecutive identical elements of an
5713array exceeds the threshold, @value{GDBN} prints the string
5714@code{"<repeats @var{n} times>"}, where @var{n} is the number of
5715identical repetitions, instead of displaying the identical elements
5716themselves. Setting the threshold to zero will cause all elements to
5717be individually printed. The default threshold is 10.
5718
5719@item show print repeats
5720Display the current threshold for printing repeated identical
5721elements.
5722
c906108c 5723@item set print null-stop
4644b6e3 5724@cindex @sc{null} elements in arrays
c906108c 5725Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5726@sc{null} is encountered. This is useful when large arrays actually
c906108c 5727contain only short strings.
d4f3574e 5728The default is off.
c906108c 5729
9c16f35a
EZ
5730@item show print null-stop
5731Show whether @value{GDBN} stops printing an array on the first
5732@sc{null} character.
5733
c906108c 5734@item set print pretty on
9c16f35a
EZ
5735@cindex print structures in indented form
5736@cindex indentation in structure display
5d161b24 5737Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5738per line, like this:
5739
5740@smallexample
5741@group
5742$1 = @{
5743 next = 0x0,
5744 flags = @{
5745 sweet = 1,
5746 sour = 1
5747 @},
5748 meat = 0x54 "Pork"
5749@}
5750@end group
5751@end smallexample
5752
5753@item set print pretty off
5754Cause @value{GDBN} to print structures in a compact format, like this:
5755
5756@smallexample
5757@group
5758$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5759meat = 0x54 "Pork"@}
5760@end group
5761@end smallexample
5762
5763@noindent
5764This is the default format.
5765
c906108c
SS
5766@item show print pretty
5767Show which format @value{GDBN} is using to print structures.
5768
c906108c 5769@item set print sevenbit-strings on
4644b6e3
EZ
5770@cindex eight-bit characters in strings
5771@cindex octal escapes in strings
c906108c
SS
5772Print using only seven-bit characters; if this option is set,
5773@value{GDBN} displays any eight-bit characters (in strings or
5774character values) using the notation @code{\}@var{nnn}. This setting is
5775best if you are working in English (@sc{ascii}) and you use the
5776high-order bit of characters as a marker or ``meta'' bit.
5777
5778@item set print sevenbit-strings off
5779Print full eight-bit characters. This allows the use of more
5780international character sets, and is the default.
5781
c906108c
SS
5782@item show print sevenbit-strings
5783Show whether or not @value{GDBN} is printing only seven-bit characters.
5784
c906108c 5785@item set print union on
4644b6e3 5786@cindex unions in structures, printing
9c16f35a
EZ
5787Tell @value{GDBN} to print unions which are contained in structures
5788and other unions. This is the default setting.
c906108c
SS
5789
5790@item set print union off
9c16f35a
EZ
5791Tell @value{GDBN} not to print unions which are contained in
5792structures and other unions. @value{GDBN} will print @code{"@{...@}"}
5793instead.
c906108c 5794
c906108c
SS
5795@item show print union
5796Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 5797structures and other unions.
c906108c
SS
5798
5799For example, given the declarations
5800
5801@smallexample
5802typedef enum @{Tree, Bug@} Species;
5803typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5804typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5805 Bug_forms;
5806
5807struct thing @{
5808 Species it;
5809 union @{
5810 Tree_forms tree;
5811 Bug_forms bug;
5812 @} form;
5813@};
5814
5815struct thing foo = @{Tree, @{Acorn@}@};
5816@end smallexample
5817
5818@noindent
5819with @code{set print union on} in effect @samp{p foo} would print
5820
5821@smallexample
5822$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5823@end smallexample
5824
5825@noindent
5826and with @code{set print union off} in effect it would print
5827
5828@smallexample
5829$1 = @{it = Tree, form = @{...@}@}
5830@end smallexample
9c16f35a
EZ
5831
5832@noindent
5833@code{set print union} affects programs written in C-like languages
5834and in Pascal.
c906108c
SS
5835@end table
5836
c906108c
SS
5837@need 1000
5838@noindent
b37052ae 5839These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5840
5841@table @code
4644b6e3 5842@cindex demangling C@t{++} names
c906108c
SS
5843@item set print demangle
5844@itemx set print demangle on
b37052ae 5845Print C@t{++} names in their source form rather than in the encoded
c906108c 5846(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5847linkage. The default is on.
c906108c 5848
c906108c 5849@item show print demangle
b37052ae 5850Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 5851
c906108c
SS
5852@item set print asm-demangle
5853@itemx set print asm-demangle on
b37052ae 5854Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5855in assembler code printouts such as instruction disassemblies.
5856The default is off.
5857
c906108c 5858@item show print asm-demangle
b37052ae 5859Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5860or demangled form.
5861
b37052ae
EZ
5862@cindex C@t{++} symbol decoding style
5863@cindex symbol decoding style, C@t{++}
a8f24a35 5864@kindex set demangle-style
c906108c
SS
5865@item set demangle-style @var{style}
5866Choose among several encoding schemes used by different compilers to
b37052ae 5867represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5868
5869@table @code
5870@item auto
5871Allow @value{GDBN} to choose a decoding style by inspecting your program.
5872
5873@item gnu
b37052ae 5874Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5875This is the default.
c906108c
SS
5876
5877@item hp
b37052ae 5878Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5879
5880@item lucid
b37052ae 5881Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5882
5883@item arm
b37052ae 5884Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5885@strong{Warning:} this setting alone is not sufficient to allow
5886debugging @code{cfront}-generated executables. @value{GDBN} would
5887require further enhancement to permit that.
5888
5889@end table
5890If you omit @var{style}, you will see a list of possible formats.
5891
c906108c 5892@item show demangle-style
b37052ae 5893Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 5894
c906108c
SS
5895@item set print object
5896@itemx set print object on
4644b6e3 5897@cindex derived type of an object, printing
9c16f35a 5898@cindex display derived types
c906108c
SS
5899When displaying a pointer to an object, identify the @emph{actual}
5900(derived) type of the object rather than the @emph{declared} type, using
5901the virtual function table.
5902
5903@item set print object off
5904Display only the declared type of objects, without reference to the
5905virtual function table. This is the default setting.
5906
c906108c
SS
5907@item show print object
5908Show whether actual, or declared, object types are displayed.
5909
c906108c
SS
5910@item set print static-members
5911@itemx set print static-members on
4644b6e3 5912@cindex static members of C@t{++} objects
b37052ae 5913Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5914
5915@item set print static-members off
b37052ae 5916Do not print static members when displaying a C@t{++} object.
c906108c 5917
c906108c 5918@item show print static-members
9c16f35a
EZ
5919Show whether C@t{++} static members are printed or not.
5920
5921@item set print pascal_static-members
5922@itemx set print pascal_static-members on
5923@cindex static members of Pacal objects
5924@cindex Pacal objects, static members display
5925Print static members when displaying a Pascal object. The default is on.
5926
5927@item set print pascal_static-members off
5928Do not print static members when displaying a Pascal object.
5929
5930@item show print pascal_static-members
5931Show whether Pascal static members are printed or not.
c906108c
SS
5932
5933@c These don't work with HP ANSI C++ yet.
c906108c
SS
5934@item set print vtbl
5935@itemx set print vtbl on
4644b6e3 5936@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
5937@cindex virtual functions (C@t{++}) display
5938@cindex VTBL display
b37052ae 5939Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5940(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5941ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5942
5943@item set print vtbl off
b37052ae 5944Do not pretty print C@t{++} virtual function tables.
c906108c 5945
c906108c 5946@item show print vtbl
b37052ae 5947Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5948@end table
c906108c 5949
6d2ebf8b 5950@node Value History
c906108c
SS
5951@section Value history
5952
5953@cindex value history
9c16f35a 5954@cindex history of values printed by @value{GDBN}
5d161b24
DB
5955Values printed by the @code{print} command are saved in the @value{GDBN}
5956@dfn{value history}. This allows you to refer to them in other expressions.
5957Values are kept until the symbol table is re-read or discarded
5958(for example with the @code{file} or @code{symbol-file} commands).
5959When the symbol table changes, the value history is discarded,
5960since the values may contain pointers back to the types defined in the
c906108c
SS
5961symbol table.
5962
5963@cindex @code{$}
5964@cindex @code{$$}
5965@cindex history number
5966The values printed are given @dfn{history numbers} by which you can
5967refer to them. These are successive integers starting with one.
5968@code{print} shows you the history number assigned to a value by
5969printing @samp{$@var{num} = } before the value; here @var{num} is the
5970history number.
5971
5972To refer to any previous value, use @samp{$} followed by the value's
5973history number. The way @code{print} labels its output is designed to
5974remind you of this. Just @code{$} refers to the most recent value in
5975the history, and @code{$$} refers to the value before that.
5976@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5977is the value just prior to @code{$$}, @code{$$1} is equivalent to
5978@code{$$}, and @code{$$0} is equivalent to @code{$}.
5979
5980For example, suppose you have just printed a pointer to a structure and
5981want to see the contents of the structure. It suffices to type
5982
474c8240 5983@smallexample
c906108c 5984p *$
474c8240 5985@end smallexample
c906108c
SS
5986
5987If you have a chain of structures where the component @code{next} points
5988to the next one, you can print the contents of the next one with this:
5989
474c8240 5990@smallexample
c906108c 5991p *$.next
474c8240 5992@end smallexample
c906108c
SS
5993
5994@noindent
5995You can print successive links in the chain by repeating this
5996command---which you can do by just typing @key{RET}.
5997
5998Note that the history records values, not expressions. If the value of
5999@code{x} is 4 and you type these commands:
6000
474c8240 6001@smallexample
c906108c
SS
6002print x
6003set x=5
474c8240 6004@end smallexample
c906108c
SS
6005
6006@noindent
6007then the value recorded in the value history by the @code{print} command
6008remains 4 even though the value of @code{x} has changed.
6009
6010@table @code
6011@kindex show values
6012@item show values
6013Print the last ten values in the value history, with their item numbers.
6014This is like @samp{p@ $$9} repeated ten times, except that @code{show
6015values} does not change the history.
6016
6017@item show values @var{n}
6018Print ten history values centered on history item number @var{n}.
6019
6020@item show values +
6021Print ten history values just after the values last printed. If no more
6022values are available, @code{show values +} produces no display.
6023@end table
6024
6025Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
6026same effect as @samp{show values +}.
6027
6d2ebf8b 6028@node Convenience Vars
c906108c
SS
6029@section Convenience variables
6030
6031@cindex convenience variables
9c16f35a 6032@cindex user-defined variables
c906108c
SS
6033@value{GDBN} provides @dfn{convenience variables} that you can use within
6034@value{GDBN} to hold on to a value and refer to it later. These variables
6035exist entirely within @value{GDBN}; they are not part of your program, and
6036setting a convenience variable has no direct effect on further execution
6037of your program. That is why you can use them freely.
6038
6039Convenience variables are prefixed with @samp{$}. Any name preceded by
6040@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 6041the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
6042(Value history references, in contrast, are @emph{numbers} preceded
6043by @samp{$}. @xref{Value History, ,Value history}.)
6044
6045You can save a value in a convenience variable with an assignment
6046expression, just as you would set a variable in your program.
6047For example:
6048
474c8240 6049@smallexample
c906108c 6050set $foo = *object_ptr
474c8240 6051@end smallexample
c906108c
SS
6052
6053@noindent
6054would save in @code{$foo} the value contained in the object pointed to by
6055@code{object_ptr}.
6056
6057Using a convenience variable for the first time creates it, but its
6058value is @code{void} until you assign a new value. You can alter the
6059value with another assignment at any time.
6060
6061Convenience variables have no fixed types. You can assign a convenience
6062variable any type of value, including structures and arrays, even if
6063that variable already has a value of a different type. The convenience
6064variable, when used as an expression, has the type of its current value.
6065
6066@table @code
6067@kindex show convenience
9c16f35a 6068@cindex show all user variables
c906108c
SS
6069@item show convenience
6070Print a list of convenience variables used so far, and their values.
d4f3574e 6071Abbreviated @code{show conv}.
c906108c
SS
6072@end table
6073
6074One of the ways to use a convenience variable is as a counter to be
6075incremented or a pointer to be advanced. For example, to print
6076a field from successive elements of an array of structures:
6077
474c8240 6078@smallexample
c906108c
SS
6079set $i = 0
6080print bar[$i++]->contents
474c8240 6081@end smallexample
c906108c 6082
d4f3574e
SS
6083@noindent
6084Repeat that command by typing @key{RET}.
c906108c
SS
6085
6086Some convenience variables are created automatically by @value{GDBN} and given
6087values likely to be useful.
6088
6089@table @code
41afff9a 6090@vindex $_@r{, convenience variable}
c906108c
SS
6091@item $_
6092The variable @code{$_} is automatically set by the @code{x} command to
6093the last address examined (@pxref{Memory, ,Examining memory}). Other
6094commands which provide a default address for @code{x} to examine also
6095set @code{$_} to that address; these commands include @code{info line}
6096and @code{info breakpoint}. The type of @code{$_} is @code{void *}
6097except when set by the @code{x} command, in which case it is a pointer
6098to the type of @code{$__}.
6099
41afff9a 6100@vindex $__@r{, convenience variable}
c906108c
SS
6101@item $__
6102The variable @code{$__} is automatically set by the @code{x} command
6103to the value found in the last address examined. Its type is chosen
6104to match the format in which the data was printed.
6105
6106@item $_exitcode
41afff9a 6107@vindex $_exitcode@r{, convenience variable}
c906108c
SS
6108The variable @code{$_exitcode} is automatically set to the exit code when
6109the program being debugged terminates.
6110@end table
6111
53a5351d
JM
6112On HP-UX systems, if you refer to a function or variable name that
6113begins with a dollar sign, @value{GDBN} searches for a user or system
6114name first, before it searches for a convenience variable.
c906108c 6115
6d2ebf8b 6116@node Registers
c906108c
SS
6117@section Registers
6118
6119@cindex registers
6120You can refer to machine register contents, in expressions, as variables
6121with names starting with @samp{$}. The names of registers are different
6122for each machine; use @code{info registers} to see the names used on
6123your machine.
6124
6125@table @code
6126@kindex info registers
6127@item info registers
6128Print the names and values of all registers except floating-point
c85508ee 6129and vector registers (in the selected stack frame).
c906108c
SS
6130
6131@kindex info all-registers
6132@cindex floating point registers
6133@item info all-registers
6134Print the names and values of all registers, including floating-point
c85508ee 6135and vector registers (in the selected stack frame).
c906108c
SS
6136
6137@item info registers @var{regname} @dots{}
6138Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
6139As discussed in detail below, register values are normally relative to
6140the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
6141the machine you are using, with or without the initial @samp{$}.
6142@end table
6143
e09f16f9
EZ
6144@cindex stack pointer register
6145@cindex program counter register
6146@cindex process status register
6147@cindex frame pointer register
6148@cindex standard registers
c906108c
SS
6149@value{GDBN} has four ``standard'' register names that are available (in
6150expressions) on most machines---whenever they do not conflict with an
6151architecture's canonical mnemonics for registers. The register names
6152@code{$pc} and @code{$sp} are used for the program counter register and
6153the stack pointer. @code{$fp} is used for a register that contains a
6154pointer to the current stack frame, and @code{$ps} is used for a
6155register that contains the processor status. For example,
6156you could print the program counter in hex with
6157
474c8240 6158@smallexample
c906108c 6159p/x $pc
474c8240 6160@end smallexample
c906108c
SS
6161
6162@noindent
6163or print the instruction to be executed next with
6164
474c8240 6165@smallexample
c906108c 6166x/i $pc
474c8240 6167@end smallexample
c906108c
SS
6168
6169@noindent
6170or add four to the stack pointer@footnote{This is a way of removing
6171one word from the stack, on machines where stacks grow downward in
6172memory (most machines, nowadays). This assumes that the innermost
6173stack frame is selected; setting @code{$sp} is not allowed when other
6174stack frames are selected. To pop entire frames off the stack,
6175regardless of machine architecture, use @code{return};
d4f3574e 6176see @ref{Returning, ,Returning from a function}.} with
c906108c 6177
474c8240 6178@smallexample
c906108c 6179set $sp += 4
474c8240 6180@end smallexample
c906108c
SS
6181
6182Whenever possible, these four standard register names are available on
6183your machine even though the machine has different canonical mnemonics,
6184so long as there is no conflict. The @code{info registers} command
6185shows the canonical names. For example, on the SPARC, @code{info
6186registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
6187can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6188is an alias for the @sc{eflags} register.
c906108c
SS
6189
6190@value{GDBN} always considers the contents of an ordinary register as an
6191integer when the register is examined in this way. Some machines have
6192special registers which can hold nothing but floating point; these
6193registers are considered to have floating point values. There is no way
6194to refer to the contents of an ordinary register as floating point value
6195(although you can @emph{print} it as a floating point value with
6196@samp{print/f $@var{regname}}).
6197
6198Some registers have distinct ``raw'' and ``virtual'' data formats. This
6199means that the data format in which the register contents are saved by
6200the operating system is not the same one that your program normally
6201sees. For example, the registers of the 68881 floating point
6202coprocessor are always saved in ``extended'' (raw) format, but all C
6203programs expect to work with ``double'' (virtual) format. In such
5d161b24 6204cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
6205that makes sense for your program), but the @code{info registers} command
6206prints the data in both formats.
6207
6208Normally, register values are relative to the selected stack frame
6209(@pxref{Selection, ,Selecting a frame}). This means that you get the
6210value that the register would contain if all stack frames farther in
6211were exited and their saved registers restored. In order to see the
6212true contents of hardware registers, you must select the innermost
6213frame (with @samp{frame 0}).
6214
6215However, @value{GDBN} must deduce where registers are saved, from the machine
6216code generated by your compiler. If some registers are not saved, or if
6217@value{GDBN} is unable to locate the saved registers, the selected stack
6218frame makes no difference.
6219
6d2ebf8b 6220@node Floating Point Hardware
c906108c
SS
6221@section Floating point hardware
6222@cindex floating point
6223
6224Depending on the configuration, @value{GDBN} may be able to give
6225you more information about the status of the floating point hardware.
6226
6227@table @code
6228@kindex info float
6229@item info float
6230Display hardware-dependent information about the floating
6231point unit. The exact contents and layout vary depending on the
6232floating point chip. Currently, @samp{info float} is supported on
6233the ARM and x86 machines.
6234@end table
c906108c 6235
e76f1f2e
AC
6236@node Vector Unit
6237@section Vector Unit
6238@cindex vector unit
6239
6240Depending on the configuration, @value{GDBN} may be able to give you
6241more information about the status of the vector unit.
6242
6243@table @code
6244@kindex info vector
6245@item info vector
6246Display information about the vector unit. The exact contents and
6247layout vary depending on the hardware.
6248@end table
6249
721c2651
EZ
6250@node OS Information
6251@section Operating system auxiliary information
6252@cindex OS information
6253
6254@value{GDBN} provides interfaces to useful OS facilities that can help
6255you debug your program.
6256
6257@cindex @code{ptrace} system call
6258@cindex @code{struct user} contents
6259When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6260machines), it interfaces with the inferior via the @code{ptrace}
6261system call. The operating system creates a special sata structure,
6262called @code{struct user}, for this interface. You can use the
6263command @code{info udot} to display the contents of this data
6264structure.
6265
6266@table @code
6267@item info udot
6268@kindex info udot
6269Display the contents of the @code{struct user} maintained by the OS
6270kernel for the program being debugged. @value{GDBN} displays the
6271contents of @code{struct user} as a list of hex numbers, similar to
6272the @code{examine} command.
6273@end table
6274
b383017d
RM
6275@cindex auxiliary vector
6276@cindex vector, auxiliary
b383017d
RM
6277Some operating systems supply an @dfn{auxiliary vector} to programs at
6278startup. This is akin to the arguments and environment that you
6279specify for a program, but contains a system-dependent variety of
6280binary values that tell system libraries important details about the
6281hardware, operating system, and process. Each value's purpose is
6282identified by an integer tag; the meanings are well-known but system-specific.
6283Depending on the configuration and operating system facilities,
9c16f35a
EZ
6284@value{GDBN} may be able to show you this information. For remote
6285targets, this functionality may further depend on the remote stub's
6286support of the @samp{qPart:auxv:read} packet, see @ref{Remote
6287configuration, auxiliary vector}.
b383017d
RM
6288
6289@table @code
6290@kindex info auxv
6291@item info auxv
6292Display the auxiliary vector of the inferior, which can be either a
e4937fc1 6293live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
6294numerically, and also shows names and text descriptions for recognized
6295tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 6296pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
6297most appropriate form for a recognized tag, and in hexadecimal for
6298an unrecognized tag.
6299@end table
6300
721c2651 6301
29e57380 6302@node Memory Region Attributes
b383017d 6303@section Memory region attributes
29e57380
C
6304@cindex memory region attributes
6305
b383017d
RM
6306@dfn{Memory region attributes} allow you to describe special handling
6307required by regions of your target's memory. @value{GDBN} uses attributes
29e57380
C
6308to determine whether to allow certain types of memory accesses; whether to
6309use specific width accesses; and whether to cache target memory.
6310
6311Defined memory regions can be individually enabled and disabled. When a
6312memory region is disabled, @value{GDBN} uses the default attributes when
6313accessing memory in that region. Similarly, if no memory regions have
6314been defined, @value{GDBN} uses the default attributes when accessing
6315all memory.
6316
b383017d 6317When a memory region is defined, it is given a number to identify it;
29e57380
C
6318to enable, disable, or remove a memory region, you specify that number.
6319
6320@table @code
6321@kindex mem
bfac230e 6322@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
6323Define a memory region bounded by @var{lower} and @var{upper} with
6324attributes @var{attributes}@dots{}, and add it to the list of regions
6325monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
6326case: it is treated as the the target's maximum memory address.
bfac230e 6327(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
6328
6329@kindex delete mem
6330@item delete mem @var{nums}@dots{}
09d4efe1
EZ
6331Remove memory regions @var{nums}@dots{} from the list of regions
6332monitored by @value{GDBN}.
29e57380
C
6333
6334@kindex disable mem
6335@item disable mem @var{nums}@dots{}
09d4efe1 6336Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 6337A disabled memory region is not forgotten.
29e57380
C
6338It may be enabled again later.
6339
6340@kindex enable mem
6341@item enable mem @var{nums}@dots{}
09d4efe1 6342Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
6343
6344@kindex info mem
6345@item info mem
6346Print a table of all defined memory regions, with the following columns
09d4efe1 6347for each region:
29e57380
C
6348
6349@table @emph
6350@item Memory Region Number
6351@item Enabled or Disabled.
b383017d 6352Enabled memory regions are marked with @samp{y}.
29e57380
C
6353Disabled memory regions are marked with @samp{n}.
6354
6355@item Lo Address
6356The address defining the inclusive lower bound of the memory region.
6357
6358@item Hi Address
6359The address defining the exclusive upper bound of the memory region.
6360
6361@item Attributes
6362The list of attributes set for this memory region.
6363@end table
6364@end table
6365
6366
6367@subsection Attributes
6368
b383017d 6369@subsubsection Memory Access Mode
29e57380
C
6370The access mode attributes set whether @value{GDBN} may make read or
6371write accesses to a memory region.
6372
6373While these attributes prevent @value{GDBN} from performing invalid
6374memory accesses, they do nothing to prevent the target system, I/O DMA,
6375etc. from accessing memory.
6376
6377@table @code
6378@item ro
6379Memory is read only.
6380@item wo
6381Memory is write only.
6382@item rw
6ca652b0 6383Memory is read/write. This is the default.
29e57380
C
6384@end table
6385
6386@subsubsection Memory Access Size
6387The acccess size attributes tells @value{GDBN} to use specific sized
6388accesses in the memory region. Often memory mapped device registers
6389require specific sized accesses. If no access size attribute is
6390specified, @value{GDBN} may use accesses of any size.
6391
6392@table @code
6393@item 8
6394Use 8 bit memory accesses.
6395@item 16
6396Use 16 bit memory accesses.
6397@item 32
6398Use 32 bit memory accesses.
6399@item 64
6400Use 64 bit memory accesses.
6401@end table
6402
6403@c @subsubsection Hardware/Software Breakpoints
6404@c The hardware/software breakpoint attributes set whether @value{GDBN}
6405@c will use hardware or software breakpoints for the internal breakpoints
6406@c used by the step, next, finish, until, etc. commands.
6407@c
6408@c @table @code
6409@c @item hwbreak
b383017d 6410@c Always use hardware breakpoints
29e57380
C
6411@c @item swbreak (default)
6412@c @end table
6413
6414@subsubsection Data Cache
6415The data cache attributes set whether @value{GDBN} will cache target
6416memory. While this generally improves performance by reducing debug
6417protocol overhead, it can lead to incorrect results because @value{GDBN}
6418does not know about volatile variables or memory mapped device
6419registers.
6420
6421@table @code
6422@item cache
b383017d 6423Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6424@item nocache
6425Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6426@end table
6427
6428@c @subsubsection Memory Write Verification
b383017d 6429@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6430@c will re-reads data after each write to verify the write was successful.
6431@c
6432@c @table @code
6433@c @item verify
6434@c @item noverify (default)
6435@c @end table
6436
16d9dec6
MS
6437@node Dump/Restore Files
6438@section Copy between memory and a file
6439@cindex dump/restore files
6440@cindex append data to a file
6441@cindex dump data to a file
6442@cindex restore data from a file
16d9dec6 6443
df5215a6
JB
6444You can use the commands @code{dump}, @code{append}, and
6445@code{restore} to copy data between target memory and a file. The
6446@code{dump} and @code{append} commands write data to a file, and the
6447@code{restore} command reads data from a file back into the inferior's
6448memory. Files may be in binary, Motorola S-record, Intel hex, or
6449Tektronix Hex format; however, @value{GDBN} can only append to binary
6450files.
6451
6452@table @code
6453
6454@kindex dump
6455@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6456@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6457Dump the contents of memory from @var{start_addr} to @var{end_addr},
6458or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6459
df5215a6 6460The @var{format} parameter may be any one of:
16d9dec6 6461@table @code
df5215a6
JB
6462@item binary
6463Raw binary form.
6464@item ihex
6465Intel hex format.
6466@item srec
6467Motorola S-record format.
6468@item tekhex
6469Tektronix Hex format.
6470@end table
6471
6472@value{GDBN} uses the same definitions of these formats as the
6473@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6474@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6475form.
6476
6477@kindex append
6478@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6479@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6480Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 6481or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
6482(@value{GDBN} can only append data to files in raw binary form.)
6483
6484@kindex restore
6485@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6486Restore the contents of file @var{filename} into memory. The
6487@code{restore} command can automatically recognize any known @sc{bfd}
6488file format, except for raw binary. To restore a raw binary file you
6489must specify the optional keyword @code{binary} after the filename.
16d9dec6 6490
b383017d 6491If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6492contained in the file. Binary files always start at address zero, so
6493they will be restored at address @var{bias}. Other bfd files have
6494a built-in location; they will be restored at offset @var{bias}
6495from that location.
6496
6497If @var{start} and/or @var{end} are non-zero, then only data between
6498file offset @var{start} and file offset @var{end} will be restored.
b383017d 6499These offsets are relative to the addresses in the file, before
16d9dec6
MS
6500the @var{bias} argument is applied.
6501
6502@end table
6503
384ee23f
EZ
6504@node Core File Generation
6505@section How to Produce a Core File from Your Program
6506@cindex dump core from inferior
6507
6508A @dfn{core file} or @dfn{core dump} is a file that records the memory
6509image of a running process and its process status (register values
6510etc.). Its primary use is post-mortem debugging of a program that
6511crashed while it ran outside a debugger. A program that crashes
6512automatically produces a core file, unless this feature is disabled by
6513the user. @xref{Files}, for information on invoking @value{GDBN} in
6514the post-mortem debugging mode.
6515
6516Occasionally, you may wish to produce a core file of the program you
6517are debugging in order to preserve a snapshot of its state.
6518@value{GDBN} has a special command for that.
6519
6520@table @code
6521@kindex gcore
6522@kindex generate-core-file
6523@item generate-core-file [@var{file}]
6524@itemx gcore [@var{file}]
6525Produce a core dump of the inferior process. The optional argument
6526@var{file} specifies the file name where to put the core dump. If not
6527specified, the file name defaults to @file{core.@var{pid}}, where
6528@var{pid} is the inferior process ID.
6529
6530Note that this command is implemented only for some systems (as of
6531this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6532@end table
6533
a0eb71c5
KB
6534@node Character Sets
6535@section Character Sets
6536@cindex character sets
6537@cindex charset
6538@cindex translating between character sets
6539@cindex host character set
6540@cindex target character set
6541
6542If the program you are debugging uses a different character set to
6543represent characters and strings than the one @value{GDBN} uses itself,
6544@value{GDBN} can automatically translate between the character sets for
6545you. The character set @value{GDBN} uses we call the @dfn{host
6546character set}; the one the inferior program uses we call the
6547@dfn{target character set}.
6548
6549For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6550uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6551remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6552running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6553then the host character set is Latin-1, and the target character set is
6554@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6555target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6556@sc{ebcdic} and Latin 1 as you print character or string values, or use
6557character and string literals in expressions.
6558
6559@value{GDBN} has no way to automatically recognize which character set
6560the inferior program uses; you must tell it, using the @code{set
6561target-charset} command, described below.
6562
6563Here are the commands for controlling @value{GDBN}'s character set
6564support:
6565
6566@table @code
6567@item set target-charset @var{charset}
6568@kindex set target-charset
6569Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6570character set names @value{GDBN} recognizes below, but if you type
6571@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6572list the target character sets it supports.
a0eb71c5
KB
6573@end table
6574
6575@table @code
6576@item set host-charset @var{charset}
6577@kindex set host-charset
6578Set the current host character set to @var{charset}.
6579
6580By default, @value{GDBN} uses a host character set appropriate to the
6581system it is running on; you can override that default using the
6582@code{set host-charset} command.
6583
6584@value{GDBN} can only use certain character sets as its host character
6585set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6586indicate which can be host character sets, but if you type
6587@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6588list the host character sets it supports.
a0eb71c5
KB
6589
6590@item set charset @var{charset}
6591@kindex set charset
e33d66ec
EZ
6592Set the current host and target character sets to @var{charset}. As
6593above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6594@value{GDBN} will list the name of the character sets that can be used
6595for both host and target.
6596
a0eb71c5
KB
6597
6598@item show charset
a0eb71c5 6599@kindex show charset
b383017d 6600Show the names of the current host and target charsets.
e33d66ec
EZ
6601
6602@itemx show host-charset
a0eb71c5 6603@kindex show host-charset
b383017d 6604Show the name of the current host charset.
e33d66ec
EZ
6605
6606@itemx show target-charset
a0eb71c5 6607@kindex show target-charset
b383017d 6608Show the name of the current target charset.
a0eb71c5
KB
6609
6610@end table
6611
6612@value{GDBN} currently includes support for the following character
6613sets:
6614
6615@table @code
6616
6617@item ASCII
6618@cindex ASCII character set
6619Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6620character set.
6621
6622@item ISO-8859-1
6623@cindex ISO 8859-1 character set
6624@cindex ISO Latin 1 character set
e33d66ec 6625The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6626characters needed for French, German, and Spanish. @value{GDBN} can use
6627this as its host character set.
6628
6629@item EBCDIC-US
6630@itemx IBM1047
6631@cindex EBCDIC character set
6632@cindex IBM1047 character set
6633Variants of the @sc{ebcdic} character set, used on some of IBM's
6634mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6635@value{GDBN} cannot use these as its host character set.
6636
6637@end table
6638
6639Note that these are all single-byte character sets. More work inside
6640GDB is needed to support multi-byte or variable-width character
6641encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6642
6643Here is an example of @value{GDBN}'s character set support in action.
6644Assume that the following source code has been placed in the file
6645@file{charset-test.c}:
6646
6647@smallexample
6648#include <stdio.h>
6649
6650char ascii_hello[]
6651 = @{72, 101, 108, 108, 111, 44, 32, 119,
6652 111, 114, 108, 100, 33, 10, 0@};
6653char ibm1047_hello[]
6654 = @{200, 133, 147, 147, 150, 107, 64, 166,
6655 150, 153, 147, 132, 90, 37, 0@};
6656
6657main ()
6658@{
6659 printf ("Hello, world!\n");
6660@}
10998722 6661@end smallexample
a0eb71c5
KB
6662
6663In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6664containing the string @samp{Hello, world!} followed by a newline,
6665encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6666
6667We compile the program, and invoke the debugger on it:
6668
6669@smallexample
6670$ gcc -g charset-test.c -o charset-test
6671$ gdb -nw charset-test
6672GNU gdb 2001-12-19-cvs
6673Copyright 2001 Free Software Foundation, Inc.
6674@dots{}
f7dc1244 6675(@value{GDBP})
10998722 6676@end smallexample
a0eb71c5
KB
6677
6678We can use the @code{show charset} command to see what character sets
6679@value{GDBN} is currently using to interpret and display characters and
6680strings:
6681
6682@smallexample
f7dc1244 6683(@value{GDBP}) show charset
e33d66ec 6684The current host and target character set is `ISO-8859-1'.
f7dc1244 6685(@value{GDBP})
10998722 6686@end smallexample
a0eb71c5
KB
6687
6688For the sake of printing this manual, let's use @sc{ascii} as our
6689initial character set:
6690@smallexample
f7dc1244
EZ
6691(@value{GDBP}) set charset ASCII
6692(@value{GDBP}) show charset
e33d66ec 6693The current host and target character set is `ASCII'.
f7dc1244 6694(@value{GDBP})
10998722 6695@end smallexample
a0eb71c5
KB
6696
6697Let's assume that @sc{ascii} is indeed the correct character set for our
6698host system --- in other words, let's assume that if @value{GDBN} prints
6699characters using the @sc{ascii} character set, our terminal will display
6700them properly. Since our current target character set is also
6701@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6702
6703@smallexample
f7dc1244 6704(@value{GDBP}) print ascii_hello
a0eb71c5 6705$1 = 0x401698 "Hello, world!\n"
f7dc1244 6706(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6707$2 = 72 'H'
f7dc1244 6708(@value{GDBP})
10998722 6709@end smallexample
a0eb71c5
KB
6710
6711@value{GDBN} uses the target character set for character and string
6712literals you use in expressions:
6713
6714@smallexample
f7dc1244 6715(@value{GDBP}) print '+'
a0eb71c5 6716$3 = 43 '+'
f7dc1244 6717(@value{GDBP})
10998722 6718@end smallexample
a0eb71c5
KB
6719
6720The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6721character.
6722
6723@value{GDBN} relies on the user to tell it which character set the
6724target program uses. If we print @code{ibm1047_hello} while our target
6725character set is still @sc{ascii}, we get jibberish:
6726
6727@smallexample
f7dc1244 6728(@value{GDBP}) print ibm1047_hello
a0eb71c5 6729$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 6730(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6731$5 = 200 '\310'
f7dc1244 6732(@value{GDBP})
10998722 6733@end smallexample
a0eb71c5 6734
e33d66ec 6735If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6736@value{GDBN} tells us the character sets it supports:
6737
6738@smallexample
f7dc1244 6739(@value{GDBP}) set target-charset
b383017d 6740ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 6741(@value{GDBP}) set target-charset
10998722 6742@end smallexample
a0eb71c5
KB
6743
6744We can select @sc{ibm1047} as our target character set, and examine the
6745program's strings again. Now the @sc{ascii} string is wrong, but
6746@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6747target character set, @sc{ibm1047}, to the host character set,
6748@sc{ascii}, and they display correctly:
6749
6750@smallexample
f7dc1244
EZ
6751(@value{GDBP}) set target-charset IBM1047
6752(@value{GDBP}) show charset
e33d66ec
EZ
6753The current host character set is `ASCII'.
6754The current target character set is `IBM1047'.
f7dc1244 6755(@value{GDBP}) print ascii_hello
a0eb71c5 6756$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 6757(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6758$7 = 72 '\110'
f7dc1244 6759(@value{GDBP}) print ibm1047_hello
a0eb71c5 6760$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 6761(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6762$9 = 200 'H'
f7dc1244 6763(@value{GDBP})
10998722 6764@end smallexample
a0eb71c5
KB
6765
6766As above, @value{GDBN} uses the target character set for character and
6767string literals you use in expressions:
6768
6769@smallexample
f7dc1244 6770(@value{GDBP}) print '+'
a0eb71c5 6771$10 = 78 '+'
f7dc1244 6772(@value{GDBP})
10998722 6773@end smallexample
a0eb71c5 6774
e33d66ec 6775The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6776character.
6777
09d4efe1
EZ
6778@node Caching Remote Data
6779@section Caching Data of Remote Targets
6780@cindex caching data of remote targets
6781
6782@value{GDBN} can cache data exchanged between the debugger and a
6783remote target (@pxref{Remote}). Such caching generally improves
6784performance, because it reduces the overhead of the remote protocol by
6785bundling memory reads and writes into large chunks. Unfortunately,
6786@value{GDBN} does not currently know anything about volatile
6787registers, and thus data caching will produce incorrect results when
6788volatile registers are in use.
6789
6790@table @code
6791@kindex set remotecache
6792@item set remotecache on
6793@itemx set remotecache off
6794Set caching state for remote targets. When @code{ON}, use data
6795caching. By default, this option is @code{OFF}.
6796
6797@kindex show remotecache
6798@item show remotecache
6799Show the current state of data caching for remote targets.
6800
6801@kindex info dcache
6802@item info dcache
6803Print the information about the data cache performance. The
6804information displayed includes: the dcache width and depth; and for
6805each cache line, how many times it was referenced, and its data and
6806state (dirty, bad, ok, etc.). This command is useful for debugging
6807the data cache operation.
6808@end table
6809
a0eb71c5 6810
e2e0bcd1
JB
6811@node Macros
6812@chapter C Preprocessor Macros
6813
49efadf5 6814Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
6815``preprocessor macros'' which expand into strings of tokens.
6816@value{GDBN} can evaluate expressions containing macro invocations, show
6817the result of macro expansion, and show a macro's definition, including
6818where it was defined.
6819
6820You may need to compile your program specially to provide @value{GDBN}
6821with information about preprocessor macros. Most compilers do not
6822include macros in their debugging information, even when you compile
6823with the @option{-g} flag. @xref{Compilation}.
6824
6825A program may define a macro at one point, remove that definition later,
6826and then provide a different definition after that. Thus, at different
6827points in the program, a macro may have different definitions, or have
6828no definition at all. If there is a current stack frame, @value{GDBN}
6829uses the macros in scope at that frame's source code line. Otherwise,
6830@value{GDBN} uses the macros in scope at the current listing location;
6831see @ref{List}.
6832
6833At the moment, @value{GDBN} does not support the @code{##}
6834token-splicing operator, the @code{#} stringification operator, or
6835variable-arity macros.
6836
6837Whenever @value{GDBN} evaluates an expression, it always expands any
6838macro invocations present in the expression. @value{GDBN} also provides
6839the following commands for working with macros explicitly.
6840
6841@table @code
6842
6843@kindex macro expand
6844@cindex macro expansion, showing the results of preprocessor
6845@cindex preprocessor macro expansion, showing the results of
6846@cindex expanding preprocessor macros
6847@item macro expand @var{expression}
6848@itemx macro exp @var{expression}
6849Show the results of expanding all preprocessor macro invocations in
6850@var{expression}. Since @value{GDBN} simply expands macros, but does
6851not parse the result, @var{expression} need not be a valid expression;
6852it can be any string of tokens.
6853
09d4efe1 6854@kindex macro exp1
e2e0bcd1
JB
6855@item macro expand-once @var{expression}
6856@itemx macro exp1 @var{expression}
4644b6e3 6857@cindex expand macro once
e2e0bcd1
JB
6858@i{(This command is not yet implemented.)} Show the results of
6859expanding those preprocessor macro invocations that appear explicitly in
6860@var{expression}. Macro invocations appearing in that expansion are
6861left unchanged. This command allows you to see the effect of a
6862particular macro more clearly, without being confused by further
6863expansions. Since @value{GDBN} simply expands macros, but does not
6864parse the result, @var{expression} need not be a valid expression; it
6865can be any string of tokens.
6866
475b0867 6867@kindex info macro
e2e0bcd1
JB
6868@cindex macro definition, showing
6869@cindex definition, showing a macro's
475b0867 6870@item info macro @var{macro}
e2e0bcd1
JB
6871Show the definition of the macro named @var{macro}, and describe the
6872source location where that definition was established.
6873
6874@kindex macro define
6875@cindex user-defined macros
6876@cindex defining macros interactively
6877@cindex macros, user-defined
6878@item macro define @var{macro} @var{replacement-list}
6879@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6880@i{(This command is not yet implemented.)} Introduce a definition for a
6881preprocessor macro named @var{macro}, invocations of which are replaced
6882by the tokens given in @var{replacement-list}. The first form of this
6883command defines an ``object-like'' macro, which takes no arguments; the
6884second form defines a ``function-like'' macro, which takes the arguments
6885given in @var{arglist}.
6886
6887A definition introduced by this command is in scope in every expression
6888evaluated in @value{GDBN}, until it is removed with the @command{macro
6889undef} command, described below. The definition overrides all
6890definitions for @var{macro} present in the program being debugged, as
6891well as any previous user-supplied definition.
6892
6893@kindex macro undef
6894@item macro undef @var{macro}
6895@i{(This command is not yet implemented.)} Remove any user-supplied
6896definition for the macro named @var{macro}. This command only affects
6897definitions provided with the @command{macro define} command, described
6898above; it cannot remove definitions present in the program being
6899debugged.
6900
09d4efe1
EZ
6901@kindex macro list
6902@item macro list
6903@i{(This command is not yet implemented.)} List all the macros
6904defined using the @code{macro define} command.
e2e0bcd1
JB
6905@end table
6906
6907@cindex macros, example of debugging with
6908Here is a transcript showing the above commands in action. First, we
6909show our source files:
6910
6911@smallexample
6912$ cat sample.c
6913#include <stdio.h>
6914#include "sample.h"
6915
6916#define M 42
6917#define ADD(x) (M + x)
6918
6919main ()
6920@{
6921#define N 28
6922 printf ("Hello, world!\n");
6923#undef N
6924 printf ("We're so creative.\n");
6925#define N 1729
6926 printf ("Goodbye, world!\n");
6927@}
6928$ cat sample.h
6929#define Q <
6930$
6931@end smallexample
6932
6933Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6934We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6935compiler includes information about preprocessor macros in the debugging
6936information.
6937
6938@smallexample
6939$ gcc -gdwarf-2 -g3 sample.c -o sample
6940$
6941@end smallexample
6942
6943Now, we start @value{GDBN} on our sample program:
6944
6945@smallexample
6946$ gdb -nw sample
6947GNU gdb 2002-05-06-cvs
6948Copyright 2002 Free Software Foundation, Inc.
6949GDB is free software, @dots{}
f7dc1244 6950(@value{GDBP})
e2e0bcd1
JB
6951@end smallexample
6952
6953We can expand macros and examine their definitions, even when the
6954program is not running. @value{GDBN} uses the current listing position
6955to decide which macro definitions are in scope:
6956
6957@smallexample
f7dc1244 6958(@value{GDBP}) list main
e2e0bcd1
JB
69593
69604 #define M 42
69615 #define ADD(x) (M + x)
69626
69637 main ()
69648 @{
69659 #define N 28
696610 printf ("Hello, world!\n");
696711 #undef N
696812 printf ("We're so creative.\n");
f7dc1244 6969(@value{GDBP}) info macro ADD
e2e0bcd1
JB
6970Defined at /home/jimb/gdb/macros/play/sample.c:5
6971#define ADD(x) (M + x)
f7dc1244 6972(@value{GDBP}) info macro Q
e2e0bcd1
JB
6973Defined at /home/jimb/gdb/macros/play/sample.h:1
6974 included at /home/jimb/gdb/macros/play/sample.c:2
6975#define Q <
f7dc1244 6976(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 6977expands to: (42 + 1)
f7dc1244 6978(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 6979expands to: once (M + 1)
f7dc1244 6980(@value{GDBP})
e2e0bcd1
JB
6981@end smallexample
6982
6983In the example above, note that @command{macro expand-once} expands only
6984the macro invocation explicit in the original text --- the invocation of
6985@code{ADD} --- but does not expand the invocation of the macro @code{M},
6986which was introduced by @code{ADD}.
6987
6988Once the program is running, GDB uses the macro definitions in force at
6989the source line of the current stack frame:
6990
6991@smallexample
f7dc1244 6992(@value{GDBP}) break main
e2e0bcd1 6993Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 6994(@value{GDBP}) run
b383017d 6995Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
6996
6997Breakpoint 1, main () at sample.c:10
699810 printf ("Hello, world!\n");
f7dc1244 6999(@value{GDBP})
e2e0bcd1
JB
7000@end smallexample
7001
7002At line 10, the definition of the macro @code{N} at line 9 is in force:
7003
7004@smallexample
f7dc1244 7005(@value{GDBP}) info macro N
e2e0bcd1
JB
7006Defined at /home/jimb/gdb/macros/play/sample.c:9
7007#define N 28
f7dc1244 7008(@value{GDBP}) macro expand N Q M
e2e0bcd1 7009expands to: 28 < 42
f7dc1244 7010(@value{GDBP}) print N Q M
e2e0bcd1 7011$1 = 1
f7dc1244 7012(@value{GDBP})
e2e0bcd1
JB
7013@end smallexample
7014
7015As we step over directives that remove @code{N}'s definition, and then
7016give it a new definition, @value{GDBN} finds the definition (or lack
7017thereof) in force at each point:
7018
7019@smallexample
f7dc1244 7020(@value{GDBP}) next
e2e0bcd1
JB
7021Hello, world!
702212 printf ("We're so creative.\n");
f7dc1244 7023(@value{GDBP}) info macro N
e2e0bcd1
JB
7024The symbol `N' has no definition as a C/C++ preprocessor macro
7025at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 7026(@value{GDBP}) next
e2e0bcd1
JB
7027We're so creative.
702814 printf ("Goodbye, world!\n");
f7dc1244 7029(@value{GDBP}) info macro N
e2e0bcd1
JB
7030Defined at /home/jimb/gdb/macros/play/sample.c:13
7031#define N 1729
f7dc1244 7032(@value{GDBP}) macro expand N Q M
e2e0bcd1 7033expands to: 1729 < 42
f7dc1244 7034(@value{GDBP}) print N Q M
e2e0bcd1 7035$2 = 0
f7dc1244 7036(@value{GDBP})
e2e0bcd1
JB
7037@end smallexample
7038
7039
b37052ae
EZ
7040@node Tracepoints
7041@chapter Tracepoints
7042@c This chapter is based on the documentation written by Michael
7043@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
7044
7045@cindex tracepoints
7046In some applications, it is not feasible for the debugger to interrupt
7047the program's execution long enough for the developer to learn
7048anything helpful about its behavior. If the program's correctness
7049depends on its real-time behavior, delays introduced by a debugger
7050might cause the program to change its behavior drastically, or perhaps
7051fail, even when the code itself is correct. It is useful to be able
7052to observe the program's behavior without interrupting it.
7053
7054Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
7055specify locations in the program, called @dfn{tracepoints}, and
7056arbitrary expressions to evaluate when those tracepoints are reached.
7057Later, using the @code{tfind} command, you can examine the values
7058those expressions had when the program hit the tracepoints. The
7059expressions may also denote objects in memory---structures or arrays,
7060for example---whose values @value{GDBN} should record; while visiting
7061a particular tracepoint, you may inspect those objects as if they were
7062in memory at that moment. However, because @value{GDBN} records these
7063values without interacting with you, it can do so quickly and
7064unobtrusively, hopefully not disturbing the program's behavior.
7065
7066The tracepoint facility is currently available only for remote
2c0069bb
EZ
7067targets. @xref{Targets}. In addition, your remote target must know how
7068to collect trace data. This functionality is implemented in the remote
7069stub; however, none of the stubs distributed with @value{GDBN} support
7070tracepoints as of this writing.
b37052ae
EZ
7071
7072This chapter describes the tracepoint commands and features.
7073
7074@menu
b383017d
RM
7075* Set Tracepoints::
7076* Analyze Collected Data::
7077* Tracepoint Variables::
b37052ae
EZ
7078@end menu
7079
7080@node Set Tracepoints
7081@section Commands to Set Tracepoints
7082
7083Before running such a @dfn{trace experiment}, an arbitrary number of
7084tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
7085tracepoint has a number assigned to it by @value{GDBN}. Like with
7086breakpoints, tracepoint numbers are successive integers starting from
7087one. Many of the commands associated with tracepoints take the
7088tracepoint number as their argument, to identify which tracepoint to
7089work on.
7090
7091For each tracepoint, you can specify, in advance, some arbitrary set
7092of data that you want the target to collect in the trace buffer when
7093it hits that tracepoint. The collected data can include registers,
7094local variables, or global data. Later, you can use @value{GDBN}
7095commands to examine the values these data had at the time the
7096tracepoint was hit.
7097
7098This section describes commands to set tracepoints and associated
7099conditions and actions.
7100
7101@menu
b383017d
RM
7102* Create and Delete Tracepoints::
7103* Enable and Disable Tracepoints::
7104* Tracepoint Passcounts::
7105* Tracepoint Actions::
7106* Listing Tracepoints::
7107* Starting and Stopping Trace Experiment::
b37052ae
EZ
7108@end menu
7109
7110@node Create and Delete Tracepoints
7111@subsection Create and Delete Tracepoints
7112
7113@table @code
7114@cindex set tracepoint
7115@kindex trace
7116@item trace
7117The @code{trace} command is very similar to the @code{break} command.
7118Its argument can be a source line, a function name, or an address in
7119the target program. @xref{Set Breaks}. The @code{trace} command
7120defines a tracepoint, which is a point in the target program where the
7121debugger will briefly stop, collect some data, and then allow the
7122program to continue. Setting a tracepoint or changing its commands
7123doesn't take effect until the next @code{tstart} command; thus, you
7124cannot change the tracepoint attributes once a trace experiment is
7125running.
7126
7127Here are some examples of using the @code{trace} command:
7128
7129@smallexample
7130(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
7131
7132(@value{GDBP}) @b{trace +2} // 2 lines forward
7133
7134(@value{GDBP}) @b{trace my_function} // first source line of function
7135
7136(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
7137
7138(@value{GDBP}) @b{trace *0x2117c4} // an address
7139@end smallexample
7140
7141@noindent
7142You can abbreviate @code{trace} as @code{tr}.
7143
7144@vindex $tpnum
7145@cindex last tracepoint number
7146@cindex recent tracepoint number
7147@cindex tracepoint number
7148The convenience variable @code{$tpnum} records the tracepoint number
7149of the most recently set tracepoint.
7150
7151@kindex delete tracepoint
7152@cindex tracepoint deletion
7153@item delete tracepoint @r{[}@var{num}@r{]}
7154Permanently delete one or more tracepoints. With no argument, the
7155default is to delete all tracepoints.
7156
7157Examples:
7158
7159@smallexample
7160(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7161
7162(@value{GDBP}) @b{delete trace} // remove all tracepoints
7163@end smallexample
7164
7165@noindent
7166You can abbreviate this command as @code{del tr}.
7167@end table
7168
7169@node Enable and Disable Tracepoints
7170@subsection Enable and Disable Tracepoints
7171
7172@table @code
7173@kindex disable tracepoint
7174@item disable tracepoint @r{[}@var{num}@r{]}
7175Disable tracepoint @var{num}, or all tracepoints if no argument
7176@var{num} is given. A disabled tracepoint will have no effect during
7177the next trace experiment, but it is not forgotten. You can re-enable
7178a disabled tracepoint using the @code{enable tracepoint} command.
7179
7180@kindex enable tracepoint
7181@item enable tracepoint @r{[}@var{num}@r{]}
7182Enable tracepoint @var{num}, or all tracepoints. The enabled
7183tracepoints will become effective the next time a trace experiment is
7184run.
7185@end table
7186
7187@node Tracepoint Passcounts
7188@subsection Tracepoint Passcounts
7189
7190@table @code
7191@kindex passcount
7192@cindex tracepoint pass count
7193@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7194Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7195automatically stop a trace experiment. If a tracepoint's passcount is
7196@var{n}, then the trace experiment will be automatically stopped on
7197the @var{n}'th time that tracepoint is hit. If the tracepoint number
7198@var{num} is not specified, the @code{passcount} command sets the
7199passcount of the most recently defined tracepoint. If no passcount is
7200given, the trace experiment will run until stopped explicitly by the
7201user.
7202
7203Examples:
7204
7205@smallexample
b383017d 7206(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 7207@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
7208
7209(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 7210@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
7211(@value{GDBP}) @b{trace foo}
7212(@value{GDBP}) @b{pass 3}
7213(@value{GDBP}) @b{trace bar}
7214(@value{GDBP}) @b{pass 2}
7215(@value{GDBP}) @b{trace baz}
7216(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
7217@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7218@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7219@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
7220@end smallexample
7221@end table
7222
7223@node Tracepoint Actions
7224@subsection Tracepoint Action Lists
7225
7226@table @code
7227@kindex actions
7228@cindex tracepoint actions
7229@item actions @r{[}@var{num}@r{]}
7230This command will prompt for a list of actions to be taken when the
7231tracepoint is hit. If the tracepoint number @var{num} is not
7232specified, this command sets the actions for the one that was most
7233recently defined (so that you can define a tracepoint and then say
7234@code{actions} without bothering about its number). You specify the
7235actions themselves on the following lines, one action at a time, and
7236terminate the actions list with a line containing just @code{end}. So
7237far, the only defined actions are @code{collect} and
7238@code{while-stepping}.
7239
7240@cindex remove actions from a tracepoint
7241To remove all actions from a tracepoint, type @samp{actions @var{num}}
7242and follow it immediately with @samp{end}.
7243
7244@smallexample
7245(@value{GDBP}) @b{collect @var{data}} // collect some data
7246
6826cf00 7247(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 7248
6826cf00 7249(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
7250@end smallexample
7251
7252In the following example, the action list begins with @code{collect}
7253commands indicating the things to be collected when the tracepoint is
7254hit. Then, in order to single-step and collect additional data
7255following the tracepoint, a @code{while-stepping} command is used,
7256followed by the list of things to be collected while stepping. The
7257@code{while-stepping} command is terminated by its own separate
7258@code{end} command. Lastly, the action list is terminated by an
7259@code{end} command.
7260
7261@smallexample
7262(@value{GDBP}) @b{trace foo}
7263(@value{GDBP}) @b{actions}
7264Enter actions for tracepoint 1, one per line:
7265> collect bar,baz
7266> collect $regs
7267> while-stepping 12
7268 > collect $fp, $sp
7269 > end
7270end
7271@end smallexample
7272
7273@kindex collect @r{(tracepoints)}
7274@item collect @var{expr1}, @var{expr2}, @dots{}
7275Collect values of the given expressions when the tracepoint is hit.
7276This command accepts a comma-separated list of any valid expressions.
7277In addition to global, static, or local variables, the following
7278special arguments are supported:
7279
7280@table @code
7281@item $regs
7282collect all registers
7283
7284@item $args
7285collect all function arguments
7286
7287@item $locals
7288collect all local variables.
7289@end table
7290
7291You can give several consecutive @code{collect} commands, each one
7292with a single argument, or one @code{collect} command with several
7293arguments separated by commas: the effect is the same.
7294
f5c37c66
EZ
7295The command @code{info scope} (@pxref{Symbols, info scope}) is
7296particularly useful for figuring out what data to collect.
7297
b37052ae
EZ
7298@kindex while-stepping @r{(tracepoints)}
7299@item while-stepping @var{n}
7300Perform @var{n} single-step traces after the tracepoint, collecting
7301new data at each step. The @code{while-stepping} command is
7302followed by the list of what to collect while stepping (followed by
7303its own @code{end} command):
7304
7305@smallexample
7306> while-stepping 12
7307 > collect $regs, myglobal
7308 > end
7309>
7310@end smallexample
7311
7312@noindent
7313You may abbreviate @code{while-stepping} as @code{ws} or
7314@code{stepping}.
7315@end table
7316
7317@node Listing Tracepoints
7318@subsection Listing Tracepoints
7319
7320@table @code
7321@kindex info tracepoints
09d4efe1 7322@kindex info tp
b37052ae
EZ
7323@cindex information about tracepoints
7324@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 7325Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 7326a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
7327defined so far. For each tracepoint, the following information is
7328shown:
7329
7330@itemize @bullet
7331@item
7332its number
7333@item
7334whether it is enabled or disabled
7335@item
7336its address
7337@item
7338its passcount as given by the @code{passcount @var{n}} command
7339@item
7340its step count as given by the @code{while-stepping @var{n}} command
7341@item
7342where in the source files is the tracepoint set
7343@item
7344its action list as given by the @code{actions} command
7345@end itemize
7346
7347@smallexample
7348(@value{GDBP}) @b{info trace}
7349Num Enb Address PassC StepC What
73501 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
73512 y 0x0020dc64 0 0 in g_test at g_test.c:1375
73523 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
7353(@value{GDBP})
7354@end smallexample
7355
7356@noindent
7357This command can be abbreviated @code{info tp}.
7358@end table
7359
7360@node Starting and Stopping Trace Experiment
7361@subsection Starting and Stopping Trace Experiment
7362
7363@table @code
7364@kindex tstart
7365@cindex start a new trace experiment
7366@cindex collected data discarded
7367@item tstart
7368This command takes no arguments. It starts the trace experiment, and
7369begins collecting data. This has the side effect of discarding all
7370the data collected in the trace buffer during the previous trace
7371experiment.
7372
7373@kindex tstop
7374@cindex stop a running trace experiment
7375@item tstop
7376This command takes no arguments. It ends the trace experiment, and
7377stops collecting data.
7378
68c71a2e 7379@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
7380automatically if any tracepoint's passcount is reached
7381(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7382
7383@kindex tstatus
7384@cindex status of trace data collection
7385@cindex trace experiment, status of
7386@item tstatus
7387This command displays the status of the current trace data
7388collection.
7389@end table
7390
7391Here is an example of the commands we described so far:
7392
7393@smallexample
7394(@value{GDBP}) @b{trace gdb_c_test}
7395(@value{GDBP}) @b{actions}
7396Enter actions for tracepoint #1, one per line.
7397> collect $regs,$locals,$args
7398> while-stepping 11
7399 > collect $regs
7400 > end
7401> end
7402(@value{GDBP}) @b{tstart}
7403 [time passes @dots{}]
7404(@value{GDBP}) @b{tstop}
7405@end smallexample
7406
7407
7408@node Analyze Collected Data
7409@section Using the collected data
7410
7411After the tracepoint experiment ends, you use @value{GDBN} commands
7412for examining the trace data. The basic idea is that each tracepoint
7413collects a trace @dfn{snapshot} every time it is hit and another
7414snapshot every time it single-steps. All these snapshots are
7415consecutively numbered from zero and go into a buffer, and you can
7416examine them later. The way you examine them is to @dfn{focus} on a
7417specific trace snapshot. When the remote stub is focused on a trace
7418snapshot, it will respond to all @value{GDBN} requests for memory and
7419registers by reading from the buffer which belongs to that snapshot,
7420rather than from @emph{real} memory or registers of the program being
7421debugged. This means that @strong{all} @value{GDBN} commands
7422(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7423behave as if we were currently debugging the program state as it was
7424when the tracepoint occurred. Any requests for data that are not in
7425the buffer will fail.
7426
7427@menu
7428* tfind:: How to select a trace snapshot
7429* tdump:: How to display all data for a snapshot
7430* save-tracepoints:: How to save tracepoints for a future run
7431@end menu
7432
7433@node tfind
7434@subsection @code{tfind @var{n}}
7435
7436@kindex tfind
7437@cindex select trace snapshot
7438@cindex find trace snapshot
7439The basic command for selecting a trace snapshot from the buffer is
7440@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7441counting from zero. If no argument @var{n} is given, the next
7442snapshot is selected.
7443
7444Here are the various forms of using the @code{tfind} command.
7445
7446@table @code
7447@item tfind start
7448Find the first snapshot in the buffer. This is a synonym for
7449@code{tfind 0} (since 0 is the number of the first snapshot).
7450
7451@item tfind none
7452Stop debugging trace snapshots, resume @emph{live} debugging.
7453
7454@item tfind end
7455Same as @samp{tfind none}.
7456
7457@item tfind
7458No argument means find the next trace snapshot.
7459
7460@item tfind -
7461Find the previous trace snapshot before the current one. This permits
7462retracing earlier steps.
7463
7464@item tfind tracepoint @var{num}
7465Find the next snapshot associated with tracepoint @var{num}. Search
7466proceeds forward from the last examined trace snapshot. If no
7467argument @var{num} is given, it means find the next snapshot collected
7468for the same tracepoint as the current snapshot.
7469
7470@item tfind pc @var{addr}
7471Find the next snapshot associated with the value @var{addr} of the
7472program counter. Search proceeds forward from the last examined trace
7473snapshot. If no argument @var{addr} is given, it means find the next
7474snapshot with the same value of PC as the current snapshot.
7475
7476@item tfind outside @var{addr1}, @var{addr2}
7477Find the next snapshot whose PC is outside the given range of
7478addresses.
7479
7480@item tfind range @var{addr1}, @var{addr2}
7481Find the next snapshot whose PC is between @var{addr1} and
7482@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7483
7484@item tfind line @r{[}@var{file}:@r{]}@var{n}
7485Find the next snapshot associated with the source line @var{n}. If
7486the optional argument @var{file} is given, refer to line @var{n} in
7487that source file. Search proceeds forward from the last examined
7488trace snapshot. If no argument @var{n} is given, it means find the
7489next line other than the one currently being examined; thus saying
7490@code{tfind line} repeatedly can appear to have the same effect as
7491stepping from line to line in a @emph{live} debugging session.
7492@end table
7493
7494The default arguments for the @code{tfind} commands are specifically
7495designed to make it easy to scan through the trace buffer. For
7496instance, @code{tfind} with no argument selects the next trace
7497snapshot, and @code{tfind -} with no argument selects the previous
7498trace snapshot. So, by giving one @code{tfind} command, and then
7499simply hitting @key{RET} repeatedly you can examine all the trace
7500snapshots in order. Or, by saying @code{tfind -} and then hitting
7501@key{RET} repeatedly you can examine the snapshots in reverse order.
7502The @code{tfind line} command with no argument selects the snapshot
7503for the next source line executed. The @code{tfind pc} command with
7504no argument selects the next snapshot with the same program counter
7505(PC) as the current frame. The @code{tfind tracepoint} command with
7506no argument selects the next trace snapshot collected by the same
7507tracepoint as the current one.
7508
7509In addition to letting you scan through the trace buffer manually,
7510these commands make it easy to construct @value{GDBN} scripts that
7511scan through the trace buffer and print out whatever collected data
7512you are interested in. Thus, if we want to examine the PC, FP, and SP
7513registers from each trace frame in the buffer, we can say this:
7514
7515@smallexample
7516(@value{GDBP}) @b{tfind start}
7517(@value{GDBP}) @b{while ($trace_frame != -1)}
7518> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7519 $trace_frame, $pc, $sp, $fp
7520> tfind
7521> end
7522
7523Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7524Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7525Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7526Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7527Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7528Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7529Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7530Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7531Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7532Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7533Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7534@end smallexample
7535
7536Or, if we want to examine the variable @code{X} at each source line in
7537the buffer:
7538
7539@smallexample
7540(@value{GDBP}) @b{tfind start}
7541(@value{GDBP}) @b{while ($trace_frame != -1)}
7542> printf "Frame %d, X == %d\n", $trace_frame, X
7543> tfind line
7544> end
7545
7546Frame 0, X = 1
7547Frame 7, X = 2
7548Frame 13, X = 255
7549@end smallexample
7550
7551@node tdump
7552@subsection @code{tdump}
7553@kindex tdump
7554@cindex dump all data collected at tracepoint
7555@cindex tracepoint data, display
7556
7557This command takes no arguments. It prints all the data collected at
7558the current trace snapshot.
7559
7560@smallexample
7561(@value{GDBP}) @b{trace 444}
7562(@value{GDBP}) @b{actions}
7563Enter actions for tracepoint #2, one per line:
7564> collect $regs, $locals, $args, gdb_long_test
7565> end
7566
7567(@value{GDBP}) @b{tstart}
7568
7569(@value{GDBP}) @b{tfind line 444}
7570#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7571at gdb_test.c:444
7572444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7573
7574(@value{GDBP}) @b{tdump}
7575Data collected at tracepoint 2, trace frame 1:
7576d0 0xc4aa0085 -995491707
7577d1 0x18 24
7578d2 0x80 128
7579d3 0x33 51
7580d4 0x71aea3d 119204413
7581d5 0x22 34
7582d6 0xe0 224
7583d7 0x380035 3670069
7584a0 0x19e24a 1696330
7585a1 0x3000668 50333288
7586a2 0x100 256
7587a3 0x322000 3284992
7588a4 0x3000698 50333336
7589a5 0x1ad3cc 1758156
7590fp 0x30bf3c 0x30bf3c
7591sp 0x30bf34 0x30bf34
7592ps 0x0 0
7593pc 0x20b2c8 0x20b2c8
7594fpcontrol 0x0 0
7595fpstatus 0x0 0
7596fpiaddr 0x0 0
7597p = 0x20e5b4 "gdb-test"
7598p1 = (void *) 0x11
7599p2 = (void *) 0x22
7600p3 = (void *) 0x33
7601p4 = (void *) 0x44
7602p5 = (void *) 0x55
7603p6 = (void *) 0x66
7604gdb_long_test = 17 '\021'
7605
7606(@value{GDBP})
7607@end smallexample
7608
7609@node save-tracepoints
7610@subsection @code{save-tracepoints @var{filename}}
7611@kindex save-tracepoints
7612@cindex save tracepoints for future sessions
7613
7614This command saves all current tracepoint definitions together with
7615their actions and passcounts, into a file @file{@var{filename}}
7616suitable for use in a later debugging session. To read the saved
7617tracepoint definitions, use the @code{source} command (@pxref{Command
7618Files}).
7619
7620@node Tracepoint Variables
7621@section Convenience Variables for Tracepoints
7622@cindex tracepoint variables
7623@cindex convenience variables for tracepoints
7624
7625@table @code
7626@vindex $trace_frame
7627@item (int) $trace_frame
7628The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7629snapshot is selected.
7630
7631@vindex $tracepoint
7632@item (int) $tracepoint
7633The tracepoint for the current trace snapshot.
7634
7635@vindex $trace_line
7636@item (int) $trace_line
7637The line number for the current trace snapshot.
7638
7639@vindex $trace_file
7640@item (char []) $trace_file
7641The source file for the current trace snapshot.
7642
7643@vindex $trace_func
7644@item (char []) $trace_func
7645The name of the function containing @code{$tracepoint}.
7646@end table
7647
7648Note: @code{$trace_file} is not suitable for use in @code{printf},
7649use @code{output} instead.
7650
7651Here's a simple example of using these convenience variables for
7652stepping through all the trace snapshots and printing some of their
7653data.
7654
7655@smallexample
7656(@value{GDBP}) @b{tfind start}
7657
7658(@value{GDBP}) @b{while $trace_frame != -1}
7659> output $trace_file
7660> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7661> tfind
7662> end
7663@end smallexample
7664
df0cd8c5
JB
7665@node Overlays
7666@chapter Debugging Programs That Use Overlays
7667@cindex overlays
7668
7669If your program is too large to fit completely in your target system's
7670memory, you can sometimes use @dfn{overlays} to work around this
7671problem. @value{GDBN} provides some support for debugging programs that
7672use overlays.
7673
7674@menu
7675* How Overlays Work:: A general explanation of overlays.
7676* Overlay Commands:: Managing overlays in @value{GDBN}.
7677* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7678 mapped by asking the inferior.
7679* Overlay Sample Program:: A sample program using overlays.
7680@end menu
7681
7682@node How Overlays Work
7683@section How Overlays Work
7684@cindex mapped overlays
7685@cindex unmapped overlays
7686@cindex load address, overlay's
7687@cindex mapped address
7688@cindex overlay area
7689
7690Suppose you have a computer whose instruction address space is only 64
7691kilobytes long, but which has much more memory which can be accessed by
7692other means: special instructions, segment registers, or memory
7693management hardware, for example. Suppose further that you want to
7694adapt a program which is larger than 64 kilobytes to run on this system.
7695
7696One solution is to identify modules of your program which are relatively
7697independent, and need not call each other directly; call these modules
7698@dfn{overlays}. Separate the overlays from the main program, and place
7699their machine code in the larger memory. Place your main program in
7700instruction memory, but leave at least enough space there to hold the
7701largest overlay as well.
7702
7703Now, to call a function located in an overlay, you must first copy that
7704overlay's machine code from the large memory into the space set aside
7705for it in the instruction memory, and then jump to its entry point
7706there.
7707
c928edc0
AC
7708@c NB: In the below the mapped area's size is greater or equal to the
7709@c size of all overlays. This is intentional to remind the developer
7710@c that overlays don't necessarily need to be the same size.
7711
474c8240 7712@smallexample
df0cd8c5 7713@group
c928edc0
AC
7714 Data Instruction Larger
7715Address Space Address Space Address Space
7716+-----------+ +-----------+ +-----------+
7717| | | | | |
7718+-----------+ +-----------+ +-----------+<-- overlay 1
7719| program | | main | .----| overlay 1 | load address
7720| variables | | program | | +-----------+
7721| and heap | | | | | |
7722+-----------+ | | | +-----------+<-- overlay 2
7723| | +-----------+ | | | load address
7724+-----------+ | | | .-| overlay 2 |
7725 | | | | | |
7726 mapped --->+-----------+ | | +-----------+
7727 address | | | | | |
7728 | overlay | <-' | | |
7729 | area | <---' +-----------+<-- overlay 3
7730 | | <---. | | load address
7731 +-----------+ `--| overlay 3 |
7732 | | | |
7733 +-----------+ | |
7734 +-----------+
7735 | |
7736 +-----------+
7737
7738 @anchor{A code overlay}A code overlay
df0cd8c5 7739@end group
474c8240 7740@end smallexample
df0cd8c5 7741
c928edc0
AC
7742The diagram (@pxref{A code overlay}) shows a system with separate data
7743and instruction address spaces. To map an overlay, the program copies
7744its code from the larger address space to the instruction address space.
7745Since the overlays shown here all use the same mapped address, only one
7746may be mapped at a time. For a system with a single address space for
7747data and instructions, the diagram would be similar, except that the
7748program variables and heap would share an address space with the main
7749program and the overlay area.
df0cd8c5
JB
7750
7751An overlay loaded into instruction memory and ready for use is called a
7752@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7753instruction memory. An overlay not present (or only partially present)
7754in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7755is its address in the larger memory. The mapped address is also called
7756the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7757called the @dfn{load memory address}, or @dfn{LMA}.
7758
7759Unfortunately, overlays are not a completely transparent way to adapt a
7760program to limited instruction memory. They introduce a new set of
7761global constraints you must keep in mind as you design your program:
7762
7763@itemize @bullet
7764
7765@item
7766Before calling or returning to a function in an overlay, your program
7767must make sure that overlay is actually mapped. Otherwise, the call or
7768return will transfer control to the right address, but in the wrong
7769overlay, and your program will probably crash.
7770
7771@item
7772If the process of mapping an overlay is expensive on your system, you
7773will need to choose your overlays carefully to minimize their effect on
7774your program's performance.
7775
7776@item
7777The executable file you load onto your system must contain each
7778overlay's instructions, appearing at the overlay's load address, not its
7779mapped address. However, each overlay's instructions must be relocated
7780and its symbols defined as if the overlay were at its mapped address.
7781You can use GNU linker scripts to specify different load and relocation
7782addresses for pieces of your program; see @ref{Overlay Description,,,
7783ld.info, Using ld: the GNU linker}.
7784
7785@item
7786The procedure for loading executable files onto your system must be able
7787to load their contents into the larger address space as well as the
7788instruction and data spaces.
7789
7790@end itemize
7791
7792The overlay system described above is rather simple, and could be
7793improved in many ways:
7794
7795@itemize @bullet
7796
7797@item
7798If your system has suitable bank switch registers or memory management
7799hardware, you could use those facilities to make an overlay's load area
7800contents simply appear at their mapped address in instruction space.
7801This would probably be faster than copying the overlay to its mapped
7802area in the usual way.
7803
7804@item
7805If your overlays are small enough, you could set aside more than one
7806overlay area, and have more than one overlay mapped at a time.
7807
7808@item
7809You can use overlays to manage data, as well as instructions. In
7810general, data overlays are even less transparent to your design than
7811code overlays: whereas code overlays only require care when you call or
7812return to functions, data overlays require care every time you access
7813the data. Also, if you change the contents of a data overlay, you
7814must copy its contents back out to its load address before you can copy a
7815different data overlay into the same mapped area.
7816
7817@end itemize
7818
7819
7820@node Overlay Commands
7821@section Overlay Commands
7822
7823To use @value{GDBN}'s overlay support, each overlay in your program must
7824correspond to a separate section of the executable file. The section's
7825virtual memory address and load memory address must be the overlay's
7826mapped and load addresses. Identifying overlays with sections allows
7827@value{GDBN} to determine the appropriate address of a function or
7828variable, depending on whether the overlay is mapped or not.
7829
7830@value{GDBN}'s overlay commands all start with the word @code{overlay};
7831you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7832
7833@table @code
7834@item overlay off
4644b6e3 7835@kindex overlay
df0cd8c5
JB
7836Disable @value{GDBN}'s overlay support. When overlay support is
7837disabled, @value{GDBN} assumes that all functions and variables are
7838always present at their mapped addresses. By default, @value{GDBN}'s
7839overlay support is disabled.
7840
7841@item overlay manual
df0cd8c5
JB
7842@cindex manual overlay debugging
7843Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7844relies on you to tell it which overlays are mapped, and which are not,
7845using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7846commands described below.
7847
7848@item overlay map-overlay @var{overlay}
7849@itemx overlay map @var{overlay}
df0cd8c5
JB
7850@cindex map an overlay
7851Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7852be the name of the object file section containing the overlay. When an
7853overlay is mapped, @value{GDBN} assumes it can find the overlay's
7854functions and variables at their mapped addresses. @value{GDBN} assumes
7855that any other overlays whose mapped ranges overlap that of
7856@var{overlay} are now unmapped.
7857
7858@item overlay unmap-overlay @var{overlay}
7859@itemx overlay unmap @var{overlay}
df0cd8c5
JB
7860@cindex unmap an overlay
7861Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7862must be the name of the object file section containing the overlay.
7863When an overlay is unmapped, @value{GDBN} assumes it can find the
7864overlay's functions and variables at their load addresses.
7865
7866@item overlay auto
df0cd8c5
JB
7867Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7868consults a data structure the overlay manager maintains in the inferior
7869to see which overlays are mapped. For details, see @ref{Automatic
7870Overlay Debugging}.
7871
7872@item overlay load-target
7873@itemx overlay load
df0cd8c5
JB
7874@cindex reloading the overlay table
7875Re-read the overlay table from the inferior. Normally, @value{GDBN}
7876re-reads the table @value{GDBN} automatically each time the inferior
7877stops, so this command should only be necessary if you have changed the
7878overlay mapping yourself using @value{GDBN}. This command is only
7879useful when using automatic overlay debugging.
7880
7881@item overlay list-overlays
7882@itemx overlay list
7883@cindex listing mapped overlays
7884Display a list of the overlays currently mapped, along with their mapped
7885addresses, load addresses, and sizes.
7886
7887@end table
7888
7889Normally, when @value{GDBN} prints a code address, it includes the name
7890of the function the address falls in:
7891
474c8240 7892@smallexample
f7dc1244 7893(@value{GDBP}) print main
df0cd8c5 7894$3 = @{int ()@} 0x11a0 <main>
474c8240 7895@end smallexample
df0cd8c5
JB
7896@noindent
7897When overlay debugging is enabled, @value{GDBN} recognizes code in
7898unmapped overlays, and prints the names of unmapped functions with
7899asterisks around them. For example, if @code{foo} is a function in an
7900unmapped overlay, @value{GDBN} prints it this way:
7901
474c8240 7902@smallexample
f7dc1244 7903(@value{GDBP}) overlay list
df0cd8c5 7904No sections are mapped.
f7dc1244 7905(@value{GDBP}) print foo
df0cd8c5 7906$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7907@end smallexample
df0cd8c5
JB
7908@noindent
7909When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7910name normally:
7911
474c8240 7912@smallexample
f7dc1244 7913(@value{GDBP}) overlay list
b383017d 7914Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 7915 mapped at 0x1016 - 0x104a
f7dc1244 7916(@value{GDBP}) print foo
df0cd8c5 7917$6 = @{int (int)@} 0x1016 <foo>
474c8240 7918@end smallexample
df0cd8c5
JB
7919
7920When overlay debugging is enabled, @value{GDBN} can find the correct
7921address for functions and variables in an overlay, whether or not the
7922overlay is mapped. This allows most @value{GDBN} commands, like
7923@code{break} and @code{disassemble}, to work normally, even on unmapped
7924code. However, @value{GDBN}'s breakpoint support has some limitations:
7925
7926@itemize @bullet
7927@item
7928@cindex breakpoints in overlays
7929@cindex overlays, setting breakpoints in
7930You can set breakpoints in functions in unmapped overlays, as long as
7931@value{GDBN} can write to the overlay at its load address.
7932@item
7933@value{GDBN} can not set hardware or simulator-based breakpoints in
7934unmapped overlays. However, if you set a breakpoint at the end of your
7935overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7936you are using manual overlay management), @value{GDBN} will re-set its
7937breakpoints properly.
7938@end itemize
7939
7940
7941@node Automatic Overlay Debugging
7942@section Automatic Overlay Debugging
7943@cindex automatic overlay debugging
7944
7945@value{GDBN} can automatically track which overlays are mapped and which
7946are not, given some simple co-operation from the overlay manager in the
7947inferior. If you enable automatic overlay debugging with the
7948@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7949looks in the inferior's memory for certain variables describing the
7950current state of the overlays.
7951
7952Here are the variables your overlay manager must define to support
7953@value{GDBN}'s automatic overlay debugging:
7954
7955@table @asis
7956
7957@item @code{_ovly_table}:
7958This variable must be an array of the following structures:
7959
474c8240 7960@smallexample
df0cd8c5
JB
7961struct
7962@{
7963 /* The overlay's mapped address. */
7964 unsigned long vma;
7965
7966 /* The size of the overlay, in bytes. */
7967 unsigned long size;
7968
7969 /* The overlay's load address. */
7970 unsigned long lma;
7971
7972 /* Non-zero if the overlay is currently mapped;
7973 zero otherwise. */
7974 unsigned long mapped;
7975@}
474c8240 7976@end smallexample
df0cd8c5
JB
7977
7978@item @code{_novlys}:
7979This variable must be a four-byte signed integer, holding the total
7980number of elements in @code{_ovly_table}.
7981
7982@end table
7983
7984To decide whether a particular overlay is mapped or not, @value{GDBN}
7985looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
7986@code{lma} members equal the VMA and LMA of the overlay's section in the
7987executable file. When @value{GDBN} finds a matching entry, it consults
7988the entry's @code{mapped} member to determine whether the overlay is
7989currently mapped.
7990
81d46470 7991In addition, your overlay manager may define a function called
def71bfa 7992@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
7993will silently set a breakpoint there. If the overlay manager then
7994calls this function whenever it has changed the overlay table, this
7995will enable @value{GDBN} to accurately keep track of which overlays
7996are in program memory, and update any breakpoints that may be set
b383017d 7997in overlays. This will allow breakpoints to work even if the
81d46470
MS
7998overlays are kept in ROM or other non-writable memory while they
7999are not being executed.
df0cd8c5
JB
8000
8001@node Overlay Sample Program
8002@section Overlay Sample Program
8003@cindex overlay example program
8004
8005When linking a program which uses overlays, you must place the overlays
8006at their load addresses, while relocating them to run at their mapped
8007addresses. To do this, you must write a linker script (@pxref{Overlay
8008Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
8009since linker scripts are specific to a particular host system, target
8010architecture, and target memory layout, this manual cannot provide
8011portable sample code demonstrating @value{GDBN}'s overlay support.
8012
8013However, the @value{GDBN} source distribution does contain an overlaid
8014program, with linker scripts for a few systems, as part of its test
8015suite. The program consists of the following files from
8016@file{gdb/testsuite/gdb.base}:
8017
8018@table @file
8019@item overlays.c
8020The main program file.
8021@item ovlymgr.c
8022A simple overlay manager, used by @file{overlays.c}.
8023@item foo.c
8024@itemx bar.c
8025@itemx baz.c
8026@itemx grbx.c
8027Overlay modules, loaded and used by @file{overlays.c}.
8028@item d10v.ld
8029@itemx m32r.ld
8030Linker scripts for linking the test program on the @code{d10v-elf}
8031and @code{m32r-elf} targets.
8032@end table
8033
8034You can build the test program using the @code{d10v-elf} GCC
8035cross-compiler like this:
8036
474c8240 8037@smallexample
df0cd8c5
JB
8038$ d10v-elf-gcc -g -c overlays.c
8039$ d10v-elf-gcc -g -c ovlymgr.c
8040$ d10v-elf-gcc -g -c foo.c
8041$ d10v-elf-gcc -g -c bar.c
8042$ d10v-elf-gcc -g -c baz.c
8043$ d10v-elf-gcc -g -c grbx.c
8044$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
8045 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 8046@end smallexample
df0cd8c5
JB
8047
8048The build process is identical for any other architecture, except that
8049you must substitute the appropriate compiler and linker script for the
8050target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
8051
8052
6d2ebf8b 8053@node Languages
c906108c
SS
8054@chapter Using @value{GDBN} with Different Languages
8055@cindex languages
8056
c906108c
SS
8057Although programming languages generally have common aspects, they are
8058rarely expressed in the same manner. For instance, in ANSI C,
8059dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
8060Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 8061represented (and displayed) differently. Hex numbers in C appear as
c906108c 8062@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
8063
8064@cindex working language
8065Language-specific information is built into @value{GDBN} for some languages,
8066allowing you to express operations like the above in your program's
8067native language, and allowing @value{GDBN} to output values in a manner
8068consistent with the syntax of your program's native language. The
8069language you use to build expressions is called the @dfn{working
8070language}.
8071
8072@menu
8073* Setting:: Switching between source languages
8074* Show:: Displaying the language
c906108c 8075* Checks:: Type and range checks
9c16f35a 8076* Supported languages:: Supported languages
4e562065 8077* Unsupported languages:: Unsupported languages
c906108c
SS
8078@end menu
8079
6d2ebf8b 8080@node Setting
c906108c
SS
8081@section Switching between source languages
8082
8083There are two ways to control the working language---either have @value{GDBN}
8084set it automatically, or select it manually yourself. You can use the
8085@code{set language} command for either purpose. On startup, @value{GDBN}
8086defaults to setting the language automatically. The working language is
8087used to determine how expressions you type are interpreted, how values
8088are printed, etc.
8089
8090In addition to the working language, every source file that
8091@value{GDBN} knows about has its own working language. For some object
8092file formats, the compiler might indicate which language a particular
8093source file is in. However, most of the time @value{GDBN} infers the
8094language from the name of the file. The language of a source file
b37052ae 8095controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 8096show each frame appropriately for its own language. There is no way to
d4f3574e
SS
8097set the language of a source file from within @value{GDBN}, but you can
8098set the language associated with a filename extension. @xref{Show, ,
8099Displaying the language}.
c906108c
SS
8100
8101This is most commonly a problem when you use a program, such
5d161b24 8102as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
8103another language. In that case, make the
8104program use @code{#line} directives in its C output; that way
8105@value{GDBN} will know the correct language of the source code of the original
8106program, and will display that source code, not the generated C code.
8107
8108@menu
8109* Filenames:: Filename extensions and languages.
8110* Manually:: Setting the working language manually
8111* Automatically:: Having @value{GDBN} infer the source language
8112@end menu
8113
6d2ebf8b 8114@node Filenames
c906108c
SS
8115@subsection List of filename extensions and languages
8116
8117If a source file name ends in one of the following extensions, then
8118@value{GDBN} infers that its language is the one indicated.
8119
8120@table @file
e07c999f
PH
8121@item .ada
8122@itemx .ads
8123@itemx .adb
8124@itemx .a
8125Ada source file.
c906108c
SS
8126
8127@item .c
8128C source file
8129
8130@item .C
8131@itemx .cc
8132@itemx .cp
8133@itemx .cpp
8134@itemx .cxx
8135@itemx .c++
b37052ae 8136C@t{++} source file
c906108c 8137
b37303ee
AF
8138@item .m
8139Objective-C source file
8140
c906108c
SS
8141@item .f
8142@itemx .F
8143Fortran source file
8144
c906108c
SS
8145@item .mod
8146Modula-2 source file
c906108c
SS
8147
8148@item .s
8149@itemx .S
8150Assembler source file. This actually behaves almost like C, but
8151@value{GDBN} does not skip over function prologues when stepping.
8152@end table
8153
8154In addition, you may set the language associated with a filename
8155extension. @xref{Show, , Displaying the language}.
8156
6d2ebf8b 8157@node Manually
c906108c
SS
8158@subsection Setting the working language
8159
8160If you allow @value{GDBN} to set the language automatically,
8161expressions are interpreted the same way in your debugging session and
8162your program.
8163
8164@kindex set language
8165If you wish, you may set the language manually. To do this, issue the
8166command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 8167a language, such as
c906108c 8168@code{c} or @code{modula-2}.
c906108c
SS
8169For a list of the supported languages, type @samp{set language}.
8170
c906108c
SS
8171Setting the language manually prevents @value{GDBN} from updating the working
8172language automatically. This can lead to confusion if you try
8173to debug a program when the working language is not the same as the
8174source language, when an expression is acceptable to both
8175languages---but means different things. For instance, if the current
8176source file were written in C, and @value{GDBN} was parsing Modula-2, a
8177command such as:
8178
474c8240 8179@smallexample
c906108c 8180print a = b + c
474c8240 8181@end smallexample
c906108c
SS
8182
8183@noindent
8184might not have the effect you intended. In C, this means to add
8185@code{b} and @code{c} and place the result in @code{a}. The result
8186printed would be the value of @code{a}. In Modula-2, this means to compare
8187@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 8188
6d2ebf8b 8189@node Automatically
c906108c
SS
8190@subsection Having @value{GDBN} infer the source language
8191
8192To have @value{GDBN} set the working language automatically, use
8193@samp{set language local} or @samp{set language auto}. @value{GDBN}
8194then infers the working language. That is, when your program stops in a
8195frame (usually by encountering a breakpoint), @value{GDBN} sets the
8196working language to the language recorded for the function in that
8197frame. If the language for a frame is unknown (that is, if the function
8198or block corresponding to the frame was defined in a source file that
8199does not have a recognized extension), the current working language is
8200not changed, and @value{GDBN} issues a warning.
8201
8202This may not seem necessary for most programs, which are written
8203entirely in one source language. However, program modules and libraries
8204written in one source language can be used by a main program written in
8205a different source language. Using @samp{set language auto} in this
8206case frees you from having to set the working language manually.
8207
6d2ebf8b 8208@node Show
c906108c 8209@section Displaying the language
c906108c
SS
8210
8211The following commands help you find out which language is the
8212working language, and also what language source files were written in.
8213
c906108c
SS
8214@table @code
8215@item show language
9c16f35a 8216@kindex show language
c906108c
SS
8217Display the current working language. This is the
8218language you can use with commands such as @code{print} to
8219build and compute expressions that may involve variables in your program.
8220
8221@item info frame
4644b6e3 8222@kindex info frame@r{, show the source language}
5d161b24 8223Display the source language for this frame. This language becomes the
c906108c 8224working language if you use an identifier from this frame.
5d161b24 8225@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
8226information listed here.
8227
8228@item info source
4644b6e3 8229@kindex info source@r{, show the source language}
c906108c 8230Display the source language of this source file.
5d161b24 8231@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
8232information listed here.
8233@end table
8234
8235In unusual circumstances, you may have source files with extensions
8236not in the standard list. You can then set the extension associated
8237with a language explicitly:
8238
c906108c 8239@table @code
09d4efe1 8240@item set extension-language @var{ext} @var{language}
9c16f35a 8241@kindex set extension-language
09d4efe1
EZ
8242Tell @value{GDBN} that source files with extension @var{ext} are to be
8243assumed as written in the source language @var{language}.
c906108c
SS
8244
8245@item info extensions
9c16f35a 8246@kindex info extensions
c906108c
SS
8247List all the filename extensions and the associated languages.
8248@end table
8249
6d2ebf8b 8250@node Checks
c906108c
SS
8251@section Type and range checking
8252
8253@quotation
8254@emph{Warning:} In this release, the @value{GDBN} commands for type and range
8255checking are included, but they do not yet have any effect. This
8256section documents the intended facilities.
8257@end quotation
8258@c FIXME remove warning when type/range code added
8259
8260Some languages are designed to guard you against making seemingly common
8261errors through a series of compile- and run-time checks. These include
8262checking the type of arguments to functions and operators, and making
8263sure mathematical overflows are caught at run time. Checks such as
8264these help to ensure a program's correctness once it has been compiled
8265by eliminating type mismatches, and providing active checks for range
8266errors when your program is running.
8267
8268@value{GDBN} can check for conditions like the above if you wish.
9c16f35a
EZ
8269Although @value{GDBN} does not check the statements in your program,
8270it can check expressions entered directly into @value{GDBN} for
8271evaluation via the @code{print} command, for example. As with the
8272working language, @value{GDBN} can also decide whether or not to check
8273automatically based on your program's source language.
8274@xref{Supported languages, ,Supported languages}, for the default
8275settings of supported languages.
c906108c
SS
8276
8277@menu
8278* Type Checking:: An overview of type checking
8279* Range Checking:: An overview of range checking
8280@end menu
8281
8282@cindex type checking
8283@cindex checks, type
6d2ebf8b 8284@node Type Checking
c906108c
SS
8285@subsection An overview of type checking
8286
8287Some languages, such as Modula-2, are strongly typed, meaning that the
8288arguments to operators and functions have to be of the correct type,
8289otherwise an error occurs. These checks prevent type mismatch
8290errors from ever causing any run-time problems. For example,
8291
8292@smallexample
82931 + 2 @result{} 3
8294@exdent but
8295@error{} 1 + 2.3
8296@end smallexample
8297
8298The second example fails because the @code{CARDINAL} 1 is not
8299type-compatible with the @code{REAL} 2.3.
8300
5d161b24
DB
8301For the expressions you use in @value{GDBN} commands, you can tell the
8302@value{GDBN} type checker to skip checking;
8303to treat any mismatches as errors and abandon the expression;
8304or to only issue warnings when type mismatches occur,
c906108c
SS
8305but evaluate the expression anyway. When you choose the last of
8306these, @value{GDBN} evaluates expressions like the second example above, but
8307also issues a warning.
8308
5d161b24
DB
8309Even if you turn type checking off, there may be other reasons
8310related to type that prevent @value{GDBN} from evaluating an expression.
8311For instance, @value{GDBN} does not know how to add an @code{int} and
8312a @code{struct foo}. These particular type errors have nothing to do
8313with the language in use, and usually arise from expressions, such as
c906108c
SS
8314the one described above, which make little sense to evaluate anyway.
8315
8316Each language defines to what degree it is strict about type. For
8317instance, both Modula-2 and C require the arguments to arithmetical
8318operators to be numbers. In C, enumerated types and pointers can be
8319represented as numbers, so that they are valid arguments to mathematical
9c16f35a 8320operators. @xref{Supported languages, ,Supported languages}, for further
c906108c
SS
8321details on specific languages.
8322
8323@value{GDBN} provides some additional commands for controlling the type checker:
8324
c906108c
SS
8325@kindex set check type
8326@kindex show check type
8327@table @code
8328@item set check type auto
8329Set type checking on or off based on the current working language.
9c16f35a 8330@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8331each language.
8332
8333@item set check type on
8334@itemx set check type off
8335Set type checking on or off, overriding the default setting for the
8336current working language. Issue a warning if the setting does not
8337match the language default. If any type mismatches occur in
d4f3574e 8338evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
8339message and aborts evaluation of the expression.
8340
8341@item set check type warn
8342Cause the type checker to issue warnings, but to always attempt to
8343evaluate the expression. Evaluating the expression may still
8344be impossible for other reasons. For example, @value{GDBN} cannot add
8345numbers and structures.
8346
8347@item show type
5d161b24 8348Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
8349is setting it automatically.
8350@end table
8351
8352@cindex range checking
8353@cindex checks, range
6d2ebf8b 8354@node Range Checking
c906108c
SS
8355@subsection An overview of range checking
8356
8357In some languages (such as Modula-2), it is an error to exceed the
8358bounds of a type; this is enforced with run-time checks. Such range
8359checking is meant to ensure program correctness by making sure
8360computations do not overflow, or indices on an array element access do
8361not exceed the bounds of the array.
8362
8363For expressions you use in @value{GDBN} commands, you can tell
8364@value{GDBN} to treat range errors in one of three ways: ignore them,
8365always treat them as errors and abandon the expression, or issue
8366warnings but evaluate the expression anyway.
8367
8368A range error can result from numerical overflow, from exceeding an
8369array index bound, or when you type a constant that is not a member
8370of any type. Some languages, however, do not treat overflows as an
8371error. In many implementations of C, mathematical overflow causes the
8372result to ``wrap around'' to lower values---for example, if @var{m} is
8373the largest integer value, and @var{s} is the smallest, then
8374
474c8240 8375@smallexample
c906108c 8376@var{m} + 1 @result{} @var{s}
474c8240 8377@end smallexample
c906108c
SS
8378
8379This, too, is specific to individual languages, and in some cases
9c16f35a 8380specific to individual compilers or machines. @xref{Supported languages, ,
c906108c
SS
8381Supported languages}, for further details on specific languages.
8382
8383@value{GDBN} provides some additional commands for controlling the range checker:
8384
c906108c
SS
8385@kindex set check range
8386@kindex show check range
8387@table @code
8388@item set check range auto
8389Set range checking on or off based on the current working language.
9c16f35a 8390@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8391each language.
8392
8393@item set check range on
8394@itemx set check range off
8395Set range checking on or off, overriding the default setting for the
8396current working language. A warning is issued if the setting does not
c3f6f71d
JM
8397match the language default. If a range error occurs and range checking is on,
8398then a message is printed and evaluation of the expression is aborted.
c906108c
SS
8399
8400@item set check range warn
8401Output messages when the @value{GDBN} range checker detects a range error,
8402but attempt to evaluate the expression anyway. Evaluating the
8403expression may still be impossible for other reasons, such as accessing
8404memory that the process does not own (a typical example from many Unix
8405systems).
8406
8407@item show range
8408Show the current setting of the range checker, and whether or not it is
8409being set automatically by @value{GDBN}.
8410@end table
c906108c 8411
9c16f35a 8412@node Supported languages
c906108c 8413@section Supported languages
c906108c 8414
9c16f35a
EZ
8415@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
8416assembly, Modula-2, and Ada.
cce74817 8417@c This is false ...
c906108c
SS
8418Some @value{GDBN} features may be used in expressions regardless of the
8419language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8420and the @samp{@{type@}addr} construct (@pxref{Expressions,
8421,Expressions}) can be used with the constructs of any supported
8422language.
8423
8424The following sections detail to what degree each source language is
8425supported by @value{GDBN}. These sections are not meant to be language
8426tutorials or references, but serve only as a reference guide to what the
8427@value{GDBN} expression parser accepts, and what input and output
8428formats should look like for different languages. There are many good
8429books written on each of these languages; please look to these for a
8430language reference or tutorial.
8431
c906108c 8432@menu
b37303ee 8433* C:: C and C@t{++}
b383017d 8434* Objective-C:: Objective-C
09d4efe1 8435* Fortran:: Fortran
9c16f35a 8436* Pascal:: Pascal
b37303ee 8437* Modula-2:: Modula-2
e07c999f 8438* Ada:: Ada
c906108c
SS
8439@end menu
8440
6d2ebf8b 8441@node C
b37052ae 8442@subsection C and C@t{++}
7a292a7a 8443
b37052ae
EZ
8444@cindex C and C@t{++}
8445@cindex expressions in C or C@t{++}
c906108c 8446
b37052ae 8447Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8448to both languages. Whenever this is the case, we discuss those languages
8449together.
8450
41afff9a
EZ
8451@cindex C@t{++}
8452@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8453@cindex @sc{gnu} C@t{++}
8454The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8455compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8456effectively, you must compile your C@t{++} programs with a supported
8457C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8458compiler (@code{aCC}).
8459
0179ffac
DC
8460For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8461format; if it doesn't work on your system, try the stabs+ debugging
8462format. You can select those formats explicitly with the @code{g++}
8463command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8464@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8465CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8466
c906108c 8467@menu
b37052ae
EZ
8468* C Operators:: C and C@t{++} operators
8469* C Constants:: C and C@t{++} constants
8470* C plus plus expressions:: C@t{++} expressions
8471* C Defaults:: Default settings for C and C@t{++}
8472* C Checks:: C and C@t{++} type and range checks
c906108c 8473* Debugging C:: @value{GDBN} and C
b37052ae 8474* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8475@end menu
c906108c 8476
6d2ebf8b 8477@node C Operators
b37052ae 8478@subsubsection C and C@t{++} operators
7a292a7a 8479
b37052ae 8480@cindex C and C@t{++} operators
c906108c
SS
8481
8482Operators must be defined on values of specific types. For instance,
8483@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8484often defined on groups of types.
c906108c 8485
b37052ae 8486For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8487
8488@itemize @bullet
53a5351d 8489
c906108c 8490@item
c906108c 8491@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8492specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8493
8494@item
d4f3574e
SS
8495@emph{Floating-point types} include @code{float}, @code{double}, and
8496@code{long double} (if supported by the target platform).
c906108c
SS
8497
8498@item
53a5351d 8499@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8500
8501@item
8502@emph{Scalar types} include all of the above.
53a5351d 8503
c906108c
SS
8504@end itemize
8505
8506@noindent
8507The following operators are supported. They are listed here
8508in order of increasing precedence:
8509
8510@table @code
8511@item ,
8512The comma or sequencing operator. Expressions in a comma-separated list
8513are evaluated from left to right, with the result of the entire
8514expression being the last expression evaluated.
8515
8516@item =
8517Assignment. The value of an assignment expression is the value
8518assigned. Defined on scalar types.
8519
8520@item @var{op}=
8521Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8522and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8523@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8524@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8525@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8526
8527@item ?:
8528The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8529of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8530integral type.
8531
8532@item ||
8533Logical @sc{or}. Defined on integral types.
8534
8535@item &&
8536Logical @sc{and}. Defined on integral types.
8537
8538@item |
8539Bitwise @sc{or}. Defined on integral types.
8540
8541@item ^
8542Bitwise exclusive-@sc{or}. Defined on integral types.
8543
8544@item &
8545Bitwise @sc{and}. Defined on integral types.
8546
8547@item ==@r{, }!=
8548Equality and inequality. Defined on scalar types. The value of these
8549expressions is 0 for false and non-zero for true.
8550
8551@item <@r{, }>@r{, }<=@r{, }>=
8552Less than, greater than, less than or equal, greater than or equal.
8553Defined on scalar types. The value of these expressions is 0 for false
8554and non-zero for true.
8555
8556@item <<@r{, }>>
8557left shift, and right shift. Defined on integral types.
8558
8559@item @@
8560The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8561
8562@item +@r{, }-
8563Addition and subtraction. Defined on integral types, floating-point types and
8564pointer types.
8565
8566@item *@r{, }/@r{, }%
8567Multiplication, division, and modulus. Multiplication and division are
8568defined on integral and floating-point types. Modulus is defined on
8569integral types.
8570
8571@item ++@r{, }--
8572Increment and decrement. When appearing before a variable, the
8573operation is performed before the variable is used in an expression;
8574when appearing after it, the variable's value is used before the
8575operation takes place.
8576
8577@item *
8578Pointer dereferencing. Defined on pointer types. Same precedence as
8579@code{++}.
8580
8581@item &
8582Address operator. Defined on variables. Same precedence as @code{++}.
8583
b37052ae
EZ
8584For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8585allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8586(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8587where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8588stored.
c906108c
SS
8589
8590@item -
8591Negative. Defined on integral and floating-point types. Same
8592precedence as @code{++}.
8593
8594@item !
8595Logical negation. Defined on integral types. Same precedence as
8596@code{++}.
8597
8598@item ~
8599Bitwise complement operator. Defined on integral types. Same precedence as
8600@code{++}.
8601
8602
8603@item .@r{, }->
8604Structure member, and pointer-to-structure member. For convenience,
8605@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8606pointer based on the stored type information.
8607Defined on @code{struct} and @code{union} data.
8608
c906108c
SS
8609@item .*@r{, }->*
8610Dereferences of pointers to members.
c906108c
SS
8611
8612@item []
8613Array indexing. @code{@var{a}[@var{i}]} is defined as
8614@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8615
8616@item ()
8617Function parameter list. Same precedence as @code{->}.
8618
c906108c 8619@item ::
b37052ae 8620C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8621and @code{class} types.
c906108c
SS
8622
8623@item ::
7a292a7a
SS
8624Doubled colons also represent the @value{GDBN} scope operator
8625(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8626above.
c906108c
SS
8627@end table
8628
c906108c
SS
8629If an operator is redefined in the user code, @value{GDBN} usually
8630attempts to invoke the redefined version instead of using the operator's
8631predefined meaning.
c906108c 8632
c906108c 8633@menu
5d161b24 8634* C Constants::
c906108c
SS
8635@end menu
8636
6d2ebf8b 8637@node C Constants
b37052ae 8638@subsubsection C and C@t{++} constants
c906108c 8639
b37052ae 8640@cindex C and C@t{++} constants
c906108c 8641
b37052ae 8642@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8643following ways:
c906108c
SS
8644
8645@itemize @bullet
8646@item
8647Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8648specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8649by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8650@samp{l}, specifying that the constant should be treated as a
8651@code{long} value.
8652
8653@item
8654Floating point constants are a sequence of digits, followed by a decimal
8655point, followed by a sequence of digits, and optionally followed by an
8656exponent. An exponent is of the form:
8657@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8658sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8659A floating-point constant may also end with a letter @samp{f} or
8660@samp{F}, specifying that the constant should be treated as being of
8661the @code{float} (as opposed to the default @code{double}) type; or with
8662a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8663constant.
c906108c
SS
8664
8665@item
8666Enumerated constants consist of enumerated identifiers, or their
8667integral equivalents.
8668
8669@item
8670Character constants are a single character surrounded by single quotes
8671(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8672(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8673be represented by a letter or by @dfn{escape sequences}, which are of
8674the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8675of the character's ordinal value; or of the form @samp{\@var{x}}, where
8676@samp{@var{x}} is a predefined special character---for example,
8677@samp{\n} for newline.
8678
8679@item
96a2c332
SS
8680String constants are a sequence of character constants surrounded by
8681double quotes (@code{"}). Any valid character constant (as described
8682above) may appear. Double quotes within the string must be preceded by
8683a backslash, so for instance @samp{"a\"b'c"} is a string of five
8684characters.
c906108c
SS
8685
8686@item
8687Pointer constants are an integral value. You can also write pointers
8688to constants using the C operator @samp{&}.
8689
8690@item
8691Array constants are comma-separated lists surrounded by braces @samp{@{}
8692and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8693integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8694and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8695@end itemize
8696
c906108c 8697@menu
5d161b24
DB
8698* C plus plus expressions::
8699* C Defaults::
8700* C Checks::
c906108c 8701
5d161b24 8702* Debugging C::
c906108c
SS
8703@end menu
8704
6d2ebf8b 8705@node C plus plus expressions
b37052ae
EZ
8706@subsubsection C@t{++} expressions
8707
8708@cindex expressions in C@t{++}
8709@value{GDBN} expression handling can interpret most C@t{++} expressions.
8710
0179ffac
DC
8711@cindex debugging C@t{++} programs
8712@cindex C@t{++} compilers
8713@cindex debug formats and C@t{++}
8714@cindex @value{NGCC} and C@t{++}
c906108c 8715@quotation
b37052ae 8716@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8717proper compiler and the proper debug format. Currently, @value{GDBN}
8718works best when debugging C@t{++} code that is compiled with
8719@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8720@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8721stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8722stabs+ as their default debug format, so you usually don't need to
8723specify a debug format explicitly. Other compilers and/or debug formats
8724are likely to work badly or not at all when using @value{GDBN} to debug
8725C@t{++} code.
c906108c 8726@end quotation
c906108c
SS
8727
8728@enumerate
8729
8730@cindex member functions
8731@item
8732Member function calls are allowed; you can use expressions like
8733
474c8240 8734@smallexample
c906108c 8735count = aml->GetOriginal(x, y)
474c8240 8736@end smallexample
c906108c 8737
41afff9a 8738@vindex this@r{, inside C@t{++} member functions}
b37052ae 8739@cindex namespace in C@t{++}
c906108c
SS
8740@item
8741While a member function is active (in the selected stack frame), your
8742expressions have the same namespace available as the member function;
8743that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8744pointer @code{this} following the same rules as C@t{++}.
c906108c 8745
c906108c 8746@cindex call overloaded functions
d4f3574e 8747@cindex overloaded functions, calling
b37052ae 8748@cindex type conversions in C@t{++}
c906108c
SS
8749@item
8750You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8751call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8752perform overload resolution involving user-defined type conversions,
8753calls to constructors, or instantiations of templates that do not exist
8754in the program. It also cannot handle ellipsis argument lists or
8755default arguments.
8756
8757It does perform integral conversions and promotions, floating-point
8758promotions, arithmetic conversions, pointer conversions, conversions of
8759class objects to base classes, and standard conversions such as those of
8760functions or arrays to pointers; it requires an exact match on the
8761number of function arguments.
8762
8763Overload resolution is always performed, unless you have specified
8764@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8765,@value{GDBN} features for C@t{++}}.
c906108c 8766
d4f3574e 8767You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8768explicit function signature to call an overloaded function, as in
8769@smallexample
8770p 'foo(char,int)'('x', 13)
8771@end smallexample
d4f3574e 8772
c906108c 8773The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8774see @ref{Completion, ,Command completion}.
c906108c 8775
c906108c
SS
8776@cindex reference declarations
8777@item
b37052ae
EZ
8778@value{GDBN} understands variables declared as C@t{++} references; you can use
8779them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8780dereferenced.
8781
8782In the parameter list shown when @value{GDBN} displays a frame, the values of
8783reference variables are not displayed (unlike other variables); this
8784avoids clutter, since references are often used for large structures.
8785The @emph{address} of a reference variable is always shown, unless
8786you have specified @samp{set print address off}.
8787
8788@item
b37052ae 8789@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8790expressions can use it just as expressions in your program do. Since
8791one scope may be defined in another, you can use @code{::} repeatedly if
8792necessary, for example in an expression like
8793@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8794resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8795debugging (@pxref{Variables, ,Program variables}).
8796@end enumerate
8797
b37052ae 8798In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8799calling virtual functions correctly, printing out virtual bases of
8800objects, calling functions in a base subobject, casting objects, and
8801invoking user-defined operators.
c906108c 8802
6d2ebf8b 8803@node C Defaults
b37052ae 8804@subsubsection C and C@t{++} defaults
7a292a7a 8805
b37052ae 8806@cindex C and C@t{++} defaults
c906108c 8807
c906108c
SS
8808If you allow @value{GDBN} to set type and range checking automatically, they
8809both default to @code{off} whenever the working language changes to
b37052ae 8810C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8811selects the working language.
c906108c
SS
8812
8813If you allow @value{GDBN} to set the language automatically, it
8814recognizes source files whose names end with @file{.c}, @file{.C}, or
8815@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8816these files, it sets the working language to C or C@t{++}.
c906108c
SS
8817@xref{Automatically, ,Having @value{GDBN} infer the source language},
8818for further details.
8819
c906108c
SS
8820@c Type checking is (a) primarily motivated by Modula-2, and (b)
8821@c unimplemented. If (b) changes, it might make sense to let this node
8822@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8823
6d2ebf8b 8824@node C Checks
b37052ae 8825@subsubsection C and C@t{++} type and range checks
7a292a7a 8826
b37052ae 8827@cindex C and C@t{++} checks
c906108c 8828
b37052ae 8829By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8830is not used. However, if you turn type checking on, @value{GDBN}
8831considers two variables type equivalent if:
8832
8833@itemize @bullet
8834@item
8835The two variables are structured and have the same structure, union, or
8836enumerated tag.
8837
8838@item
8839The two variables have the same type name, or types that have been
8840declared equivalent through @code{typedef}.
8841
8842@ignore
8843@c leaving this out because neither J Gilmore nor R Pesch understand it.
8844@c FIXME--beers?
8845@item
8846The two @code{struct}, @code{union}, or @code{enum} variables are
8847declared in the same declaration. (Note: this may not be true for all C
8848compilers.)
8849@end ignore
8850@end itemize
8851
8852Range checking, if turned on, is done on mathematical operations. Array
8853indices are not checked, since they are often used to index a pointer
8854that is not itself an array.
c906108c 8855
6d2ebf8b 8856@node Debugging C
c906108c 8857@subsubsection @value{GDBN} and C
c906108c
SS
8858
8859The @code{set print union} and @code{show print union} commands apply to
8860the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8861inside a @code{struct} or @code{class} is also printed. Otherwise, it
8862appears as @samp{@{...@}}.
c906108c
SS
8863
8864The @code{@@} operator aids in the debugging of dynamic arrays, formed
8865with pointers and a memory allocation function. @xref{Expressions,
8866,Expressions}.
8867
c906108c 8868@menu
5d161b24 8869* Debugging C plus plus::
c906108c
SS
8870@end menu
8871
6d2ebf8b 8872@node Debugging C plus plus
b37052ae 8873@subsubsection @value{GDBN} features for C@t{++}
c906108c 8874
b37052ae 8875@cindex commands for C@t{++}
7a292a7a 8876
b37052ae
EZ
8877Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8878designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8879
8880@table @code
8881@cindex break in overloaded functions
8882@item @r{breakpoint menus}
8883When you want a breakpoint in a function whose name is overloaded,
8884@value{GDBN} breakpoint menus help you specify which function definition
8885you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8886
b37052ae 8887@cindex overloading in C@t{++}
c906108c
SS
8888@item rbreak @var{regex}
8889Setting breakpoints using regular expressions is helpful for setting
8890breakpoints on overloaded functions that are not members of any special
8891classes.
8892@xref{Set Breaks, ,Setting breakpoints}.
8893
b37052ae 8894@cindex C@t{++} exception handling
c906108c
SS
8895@item catch throw
8896@itemx catch catch
b37052ae 8897Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8898Catchpoints, , Setting catchpoints}.
8899
8900@cindex inheritance
8901@item ptype @var{typename}
8902Print inheritance relationships as well as other information for type
8903@var{typename}.
8904@xref{Symbols, ,Examining the Symbol Table}.
8905
b37052ae 8906@cindex C@t{++} symbol display
c906108c
SS
8907@item set print demangle
8908@itemx show print demangle
8909@itemx set print asm-demangle
8910@itemx show print asm-demangle
b37052ae
EZ
8911Control whether C@t{++} symbols display in their source form, both when
8912displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8913@xref{Print Settings, ,Print settings}.
8914
8915@item set print object
8916@itemx show print object
8917Choose whether to print derived (actual) or declared types of objects.
8918@xref{Print Settings, ,Print settings}.
8919
8920@item set print vtbl
8921@itemx show print vtbl
8922Control the format for printing virtual function tables.
8923@xref{Print Settings, ,Print settings}.
c906108c 8924(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8925ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8926
8927@kindex set overload-resolution
d4f3574e 8928@cindex overloaded functions, overload resolution
c906108c 8929@item set overload-resolution on
b37052ae 8930Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8931is on. For overloaded functions, @value{GDBN} evaluates the arguments
8932and searches for a function whose signature matches the argument types,
b37052ae 8933using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8934expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8935message.
8936
8937@item set overload-resolution off
b37052ae 8938Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8939overloaded functions that are not class member functions, @value{GDBN}
8940chooses the first function of the specified name that it finds in the
8941symbol table, whether or not its arguments are of the correct type. For
8942overloaded functions that are class member functions, @value{GDBN}
8943searches for a function whose signature @emph{exactly} matches the
8944argument types.
c906108c 8945
9c16f35a
EZ
8946@kindex show overload-resolution
8947@item show overload-resolution
8948Show the current setting of overload resolution.
8949
c906108c
SS
8950@item @r{Overloaded symbol names}
8951You can specify a particular definition of an overloaded symbol, using
b37052ae 8952the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
8953@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8954also use the @value{GDBN} command-line word completion facilities to list the
8955available choices, or to finish the type list for you.
8956@xref{Completion,, Command completion}, for details on how to do this.
8957@end table
c906108c 8958
b37303ee
AF
8959@node Objective-C
8960@subsection Objective-C
8961
8962@cindex Objective-C
8963This section provides information about some commands and command
721c2651
EZ
8964options that are useful for debugging Objective-C code. See also
8965@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
8966few more commands specific to Objective-C support.
b37303ee
AF
8967
8968@menu
b383017d
RM
8969* Method Names in Commands::
8970* The Print Command with Objective-C::
b37303ee
AF
8971@end menu
8972
8973@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
8974@subsubsection Method Names in Commands
8975
8976The following commands have been extended to accept Objective-C method
8977names as line specifications:
8978
8979@kindex clear@r{, and Objective-C}
8980@kindex break@r{, and Objective-C}
8981@kindex info line@r{, and Objective-C}
8982@kindex jump@r{, and Objective-C}
8983@kindex list@r{, and Objective-C}
8984@itemize
8985@item @code{clear}
8986@item @code{break}
8987@item @code{info line}
8988@item @code{jump}
8989@item @code{list}
8990@end itemize
8991
8992A fully qualified Objective-C method name is specified as
8993
8994@smallexample
8995-[@var{Class} @var{methodName}]
8996@end smallexample
8997
c552b3bb
JM
8998where the minus sign is used to indicate an instance method and a
8999plus sign (not shown) is used to indicate a class method. The class
9000name @var{Class} and method name @var{methodName} are enclosed in
9001brackets, similar to the way messages are specified in Objective-C
9002source code. For example, to set a breakpoint at the @code{create}
9003instance method of class @code{Fruit} in the program currently being
9004debugged, enter:
b37303ee
AF
9005
9006@smallexample
9007break -[Fruit create]
9008@end smallexample
9009
9010To list ten program lines around the @code{initialize} class method,
9011enter:
9012
9013@smallexample
9014list +[NSText initialize]
9015@end smallexample
9016
c552b3bb
JM
9017In the current version of @value{GDBN}, the plus or minus sign is
9018required. In future versions of @value{GDBN}, the plus or minus
9019sign will be optional, but you can use it to narrow the search. It
9020is also possible to specify just a method name:
b37303ee
AF
9021
9022@smallexample
9023break create
9024@end smallexample
9025
9026You must specify the complete method name, including any colons. If
9027your program's source files contain more than one @code{create} method,
9028you'll be presented with a numbered list of classes that implement that
9029method. Indicate your choice by number, or type @samp{0} to exit if
9030none apply.
9031
9032As another example, to clear a breakpoint established at the
9033@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
9034
9035@smallexample
9036clear -[NSWindow makeKeyAndOrderFront:]
9037@end smallexample
9038
9039@node The Print Command with Objective-C
9040@subsubsection The Print Command With Objective-C
721c2651 9041@cindex Objective-C, print objects
c552b3bb
JM
9042@kindex print-object
9043@kindex po @r{(@code{print-object})}
b37303ee 9044
c552b3bb 9045The print command has also been extended to accept methods. For example:
b37303ee
AF
9046
9047@smallexample
c552b3bb 9048print -[@var{object} hash]
b37303ee
AF
9049@end smallexample
9050
9051@cindex print an Objective-C object description
c552b3bb
JM
9052@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
9053@noindent
9054will tell @value{GDBN} to send the @code{hash} message to @var{object}
9055and print the result. Also, an additional command has been added,
9056@code{print-object} or @code{po} for short, which is meant to print
9057the description of an object. However, this command may only work
9058with certain Objective-C libraries that have a particular hook
9059function, @code{_NSPrintForDebugger}, defined.
b37303ee 9060
09d4efe1
EZ
9061@node Fortran
9062@subsection Fortran
9063@cindex Fortran-specific support in @value{GDBN}
9064
9065@table @code
9066@cindex @code{COMMON} blocks, Fortran
9067@kindex info common
9068@item info common @r{[}@var{common-name}@r{]}
9069This command prints the values contained in the Fortran @code{COMMON}
9070block whose name is @var{common-name}. With no argument, the names of
9071all @code{COMMON} blocks visible at current program location are
9072printed.
9073@end table
9074
a8f24a35
EZ
9075Fortran symbols are usually case-insensitive, so @value{GDBN} by
9076default uses case-insensitive matches for Fortran symbols. You can
9077change that with the @samp{set case-insensitive} command, see
9078@ref{Symbols}, for the details.
9079
9c16f35a
EZ
9080@node Pascal
9081@subsection Pascal
9082
9083@cindex Pascal support in @value{GDBN}, limitations
9084Debugging Pascal programs which use sets, subranges, file variables, or
9085nested functions does not currently work. @value{GDBN} does not support
9086entering expressions, printing values, or similar features using Pascal
9087syntax.
9088
9089The Pascal-specific command @code{set print pascal_static-members}
9090controls whether static members of Pascal objects are displayed.
9091@xref{Print Settings, pascal_static-members}.
9092
09d4efe1 9093@node Modula-2
c906108c 9094@subsection Modula-2
7a292a7a 9095
d4f3574e 9096@cindex Modula-2, @value{GDBN} support
c906108c
SS
9097
9098The extensions made to @value{GDBN} to support Modula-2 only support
9099output from the @sc{gnu} Modula-2 compiler (which is currently being
9100developed). Other Modula-2 compilers are not currently supported, and
9101attempting to debug executables produced by them is most likely
9102to give an error as @value{GDBN} reads in the executable's symbol
9103table.
9104
9105@cindex expressions in Modula-2
9106@menu
9107* M2 Operators:: Built-in operators
9108* Built-In Func/Proc:: Built-in functions and procedures
9109* M2 Constants:: Modula-2 constants
9110* M2 Defaults:: Default settings for Modula-2
9111* Deviations:: Deviations from standard Modula-2
9112* M2 Checks:: Modula-2 type and range checks
9113* M2 Scope:: The scope operators @code{::} and @code{.}
9114* GDB/M2:: @value{GDBN} and Modula-2
9115@end menu
9116
6d2ebf8b 9117@node M2 Operators
c906108c
SS
9118@subsubsection Operators
9119@cindex Modula-2 operators
9120
9121Operators must be defined on values of specific types. For instance,
9122@code{+} is defined on numbers, but not on structures. Operators are
9123often defined on groups of types. For the purposes of Modula-2, the
9124following definitions hold:
9125
9126@itemize @bullet
9127
9128@item
9129@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
9130their subranges.
9131
9132@item
9133@emph{Character types} consist of @code{CHAR} and its subranges.
9134
9135@item
9136@emph{Floating-point types} consist of @code{REAL}.
9137
9138@item
9139@emph{Pointer types} consist of anything declared as @code{POINTER TO
9140@var{type}}.
9141
9142@item
9143@emph{Scalar types} consist of all of the above.
9144
9145@item
9146@emph{Set types} consist of @code{SET} and @code{BITSET} types.
9147
9148@item
9149@emph{Boolean types} consist of @code{BOOLEAN}.
9150@end itemize
9151
9152@noindent
9153The following operators are supported, and appear in order of
9154increasing precedence:
9155
9156@table @code
9157@item ,
9158Function argument or array index separator.
9159
9160@item :=
9161Assignment. The value of @var{var} @code{:=} @var{value} is
9162@var{value}.
9163
9164@item <@r{, }>
9165Less than, greater than on integral, floating-point, or enumerated
9166types.
9167
9168@item <=@r{, }>=
96a2c332 9169Less than or equal to, greater than or equal to
c906108c
SS
9170on integral, floating-point and enumerated types, or set inclusion on
9171set types. Same precedence as @code{<}.
9172
9173@item =@r{, }<>@r{, }#
9174Equality and two ways of expressing inequality, valid on scalar types.
9175Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9176available for inequality, since @code{#} conflicts with the script
9177comment character.
9178
9179@item IN
9180Set membership. Defined on set types and the types of their members.
9181Same precedence as @code{<}.
9182
9183@item OR
9184Boolean disjunction. Defined on boolean types.
9185
9186@item AND@r{, }&
d4f3574e 9187Boolean conjunction. Defined on boolean types.
c906108c
SS
9188
9189@item @@
9190The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9191
9192@item +@r{, }-
9193Addition and subtraction on integral and floating-point types, or union
9194and difference on set types.
9195
9196@item *
9197Multiplication on integral and floating-point types, or set intersection
9198on set types.
9199
9200@item /
9201Division on floating-point types, or symmetric set difference on set
9202types. Same precedence as @code{*}.
9203
9204@item DIV@r{, }MOD
9205Integer division and remainder. Defined on integral types. Same
9206precedence as @code{*}.
9207
9208@item -
9209Negative. Defined on @code{INTEGER} and @code{REAL} data.
9210
9211@item ^
9212Pointer dereferencing. Defined on pointer types.
9213
9214@item NOT
9215Boolean negation. Defined on boolean types. Same precedence as
9216@code{^}.
9217
9218@item .
9219@code{RECORD} field selector. Defined on @code{RECORD} data. Same
9220precedence as @code{^}.
9221
9222@item []
9223Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
9224
9225@item ()
9226Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
9227as @code{^}.
9228
9229@item ::@r{, }.
9230@value{GDBN} and Modula-2 scope operators.
9231@end table
9232
9233@quotation
9234@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
9235treats the use of the operator @code{IN}, or the use of operators
9236@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
9237@code{<=}, and @code{>=} on sets as an error.
9238@end quotation
9239
cb51c4e0 9240
6d2ebf8b 9241@node Built-In Func/Proc
c906108c 9242@subsubsection Built-in functions and procedures
cb51c4e0 9243@cindex Modula-2 built-ins
c906108c
SS
9244
9245Modula-2 also makes available several built-in procedures and functions.
9246In describing these, the following metavariables are used:
9247
9248@table @var
9249
9250@item a
9251represents an @code{ARRAY} variable.
9252
9253@item c
9254represents a @code{CHAR} constant or variable.
9255
9256@item i
9257represents a variable or constant of integral type.
9258
9259@item m
9260represents an identifier that belongs to a set. Generally used in the
9261same function with the metavariable @var{s}. The type of @var{s} should
9262be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
9263
9264@item n
9265represents a variable or constant of integral or floating-point type.
9266
9267@item r
9268represents a variable or constant of floating-point type.
9269
9270@item t
9271represents a type.
9272
9273@item v
9274represents a variable.
9275
9276@item x
9277represents a variable or constant of one of many types. See the
9278explanation of the function for details.
9279@end table
9280
9281All Modula-2 built-in procedures also return a result, described below.
9282
9283@table @code
9284@item ABS(@var{n})
9285Returns the absolute value of @var{n}.
9286
9287@item CAP(@var{c})
9288If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 9289equivalent, otherwise it returns its argument.
c906108c
SS
9290
9291@item CHR(@var{i})
9292Returns the character whose ordinal value is @var{i}.
9293
9294@item DEC(@var{v})
c3f6f71d 9295Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9296
9297@item DEC(@var{v},@var{i})
9298Decrements the value in the variable @var{v} by @var{i}. Returns the
9299new value.
9300
9301@item EXCL(@var{m},@var{s})
9302Removes the element @var{m} from the set @var{s}. Returns the new
9303set.
9304
9305@item FLOAT(@var{i})
9306Returns the floating point equivalent of the integer @var{i}.
9307
9308@item HIGH(@var{a})
9309Returns the index of the last member of @var{a}.
9310
9311@item INC(@var{v})
c3f6f71d 9312Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9313
9314@item INC(@var{v},@var{i})
9315Increments the value in the variable @var{v} by @var{i}. Returns the
9316new value.
9317
9318@item INCL(@var{m},@var{s})
9319Adds the element @var{m} to the set @var{s} if it is not already
9320there. Returns the new set.
9321
9322@item MAX(@var{t})
9323Returns the maximum value of the type @var{t}.
9324
9325@item MIN(@var{t})
9326Returns the minimum value of the type @var{t}.
9327
9328@item ODD(@var{i})
9329Returns boolean TRUE if @var{i} is an odd number.
9330
9331@item ORD(@var{x})
9332Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
9333value of a character is its @sc{ascii} value (on machines supporting the
9334@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
9335integral, character and enumerated types.
9336
9337@item SIZE(@var{x})
9338Returns the size of its argument. @var{x} can be a variable or a type.
9339
9340@item TRUNC(@var{r})
9341Returns the integral part of @var{r}.
9342
9343@item VAL(@var{t},@var{i})
9344Returns the member of the type @var{t} whose ordinal value is @var{i}.
9345@end table
9346
9347@quotation
9348@emph{Warning:} Sets and their operations are not yet supported, so
9349@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
9350an error.
9351@end quotation
9352
9353@cindex Modula-2 constants
6d2ebf8b 9354@node M2 Constants
c906108c
SS
9355@subsubsection Constants
9356
9357@value{GDBN} allows you to express the constants of Modula-2 in the following
9358ways:
9359
9360@itemize @bullet
9361
9362@item
9363Integer constants are simply a sequence of digits. When used in an
9364expression, a constant is interpreted to be type-compatible with the
9365rest of the expression. Hexadecimal integers are specified by a
9366trailing @samp{H}, and octal integers by a trailing @samp{B}.
9367
9368@item
9369Floating point constants appear as a sequence of digits, followed by a
9370decimal point and another sequence of digits. An optional exponent can
9371then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
9372@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
9373digits of the floating point constant must be valid decimal (base 10)
9374digits.
9375
9376@item
9377Character constants consist of a single character enclosed by a pair of
9378like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 9379also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
9380followed by a @samp{C}.
9381
9382@item
9383String constants consist of a sequence of characters enclosed by a
9384pair of like quotes, either single (@code{'}) or double (@code{"}).
9385Escape sequences in the style of C are also allowed. @xref{C
b37052ae 9386Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
9387sequences.
9388
9389@item
9390Enumerated constants consist of an enumerated identifier.
9391
9392@item
9393Boolean constants consist of the identifiers @code{TRUE} and
9394@code{FALSE}.
9395
9396@item
9397Pointer constants consist of integral values only.
9398
9399@item
9400Set constants are not yet supported.
9401@end itemize
9402
6d2ebf8b 9403@node M2 Defaults
c906108c
SS
9404@subsubsection Modula-2 defaults
9405@cindex Modula-2 defaults
9406
9407If type and range checking are set automatically by @value{GDBN}, they
9408both default to @code{on} whenever the working language changes to
d4f3574e 9409Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
9410selected the working language.
9411
9412If you allow @value{GDBN} to set the language automatically, then entering
9413code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 9414working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
9415the language automatically}, for further details.
9416
6d2ebf8b 9417@node Deviations
c906108c
SS
9418@subsubsection Deviations from standard Modula-2
9419@cindex Modula-2, deviations from
9420
9421A few changes have been made to make Modula-2 programs easier to debug.
9422This is done primarily via loosening its type strictness:
9423
9424@itemize @bullet
9425@item
9426Unlike in standard Modula-2, pointer constants can be formed by
9427integers. This allows you to modify pointer variables during
9428debugging. (In standard Modula-2, the actual address contained in a
9429pointer variable is hidden from you; it can only be modified
9430through direct assignment to another pointer variable or expression that
9431returned a pointer.)
9432
9433@item
9434C escape sequences can be used in strings and characters to represent
9435non-printable characters. @value{GDBN} prints out strings with these
9436escape sequences embedded. Single non-printable characters are
9437printed using the @samp{CHR(@var{nnn})} format.
9438
9439@item
9440The assignment operator (@code{:=}) returns the value of its right-hand
9441argument.
9442
9443@item
9444All built-in procedures both modify @emph{and} return their argument.
9445@end itemize
9446
6d2ebf8b 9447@node M2 Checks
c906108c
SS
9448@subsubsection Modula-2 type and range checks
9449@cindex Modula-2 checks
9450
9451@quotation
9452@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9453range checking.
9454@end quotation
9455@c FIXME remove warning when type/range checks added
9456
9457@value{GDBN} considers two Modula-2 variables type equivalent if:
9458
9459@itemize @bullet
9460@item
9461They are of types that have been declared equivalent via a @code{TYPE
9462@var{t1} = @var{t2}} statement
9463
9464@item
9465They have been declared on the same line. (Note: This is true of the
9466@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9467@end itemize
9468
9469As long as type checking is enabled, any attempt to combine variables
9470whose types are not equivalent is an error.
9471
9472Range checking is done on all mathematical operations, assignment, array
9473index bounds, and all built-in functions and procedures.
9474
6d2ebf8b 9475@node M2 Scope
c906108c
SS
9476@subsubsection The scope operators @code{::} and @code{.}
9477@cindex scope
41afff9a 9478@cindex @code{.}, Modula-2 scope operator
c906108c
SS
9479@cindex colon, doubled as scope operator
9480@ifinfo
41afff9a 9481@vindex colon-colon@r{, in Modula-2}
c906108c
SS
9482@c Info cannot handle :: but TeX can.
9483@end ifinfo
9484@iftex
41afff9a 9485@vindex ::@r{, in Modula-2}
c906108c
SS
9486@end iftex
9487
9488There are a few subtle differences between the Modula-2 scope operator
9489(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9490similar syntax:
9491
474c8240 9492@smallexample
c906108c
SS
9493
9494@var{module} . @var{id}
9495@var{scope} :: @var{id}
474c8240 9496@end smallexample
c906108c
SS
9497
9498@noindent
9499where @var{scope} is the name of a module or a procedure,
9500@var{module} the name of a module, and @var{id} is any declared
9501identifier within your program, except another module.
9502
9503Using the @code{::} operator makes @value{GDBN} search the scope
9504specified by @var{scope} for the identifier @var{id}. If it is not
9505found in the specified scope, then @value{GDBN} searches all scopes
9506enclosing the one specified by @var{scope}.
9507
9508Using the @code{.} operator makes @value{GDBN} search the current scope for
9509the identifier specified by @var{id} that was imported from the
9510definition module specified by @var{module}. With this operator, it is
9511an error if the identifier @var{id} was not imported from definition
9512module @var{module}, or if @var{id} is not an identifier in
9513@var{module}.
9514
6d2ebf8b 9515@node GDB/M2
c906108c
SS
9516@subsubsection @value{GDBN} and Modula-2
9517
9518Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9519Five subcommands of @code{set print} and @code{show print} apply
b37052ae 9520specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 9521@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 9522apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
9523analogue in Modula-2.
9524
9525The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 9526with any language, is not useful with Modula-2. Its
c906108c 9527intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 9528created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 9529address can be specified by an integral constant, the construct
d4f3574e 9530@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
9531
9532@cindex @code{#} in Modula-2
9533In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9534interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 9535
e07c999f
PH
9536@node Ada
9537@subsection Ada
9538@cindex Ada
9539
9540The extensions made to @value{GDBN} for Ada only support
9541output from the @sc{gnu} Ada (GNAT) compiler.
9542Other Ada compilers are not currently supported, and
9543attempting to debug executables produced by them is most likely
9544to be difficult.
9545
9546
9547@cindex expressions in Ada
9548@menu
9549* Ada Mode Intro:: General remarks on the Ada syntax
9550 and semantics supported by Ada mode
9551 in @value{GDBN}.
9552* Omissions from Ada:: Restrictions on the Ada expression syntax.
9553* Additions to Ada:: Extensions of the Ada expression syntax.
9554* Stopping Before Main Program:: Debugging the program during elaboration.
9555* Ada Glitches:: Known peculiarities of Ada mode.
9556@end menu
9557
9558@node Ada Mode Intro
9559@subsubsection Introduction
9560@cindex Ada mode, general
9561
9562The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9563syntax, with some extensions.
9564The philosophy behind the design of this subset is
9565
9566@itemize @bullet
9567@item
9568That @value{GDBN} should provide basic literals and access to operations for
9569arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9570leaving more sophisticated computations to subprograms written into the
9571program (which therefore may be called from @value{GDBN}).
9572
9573@item
9574That type safety and strict adherence to Ada language restrictions
9575are not particularly important to the @value{GDBN} user.
9576
9577@item
9578That brevity is important to the @value{GDBN} user.
9579@end itemize
9580
9581Thus, for brevity, the debugger acts as if there were
9582implicit @code{with} and @code{use} clauses in effect for all user-written
9583packages, making it unnecessary to fully qualify most names with
9584their packages, regardless of context. Where this causes ambiguity,
9585@value{GDBN} asks the user's intent.
9586
9587The debugger will start in Ada mode if it detects an Ada main program.
9588As for other languages, it will enter Ada mode when stopped in a program that
9589was translated from an Ada source file.
9590
9591While in Ada mode, you may use `@t{--}' for comments. This is useful
9592mostly for documenting command files. The standard @value{GDBN} comment
9593(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9594middle (to allow based literals).
9595
9596The debugger supports limited overloading. Given a subprogram call in which
9597the function symbol has multiple definitions, it will use the number of
9598actual parameters and some information about their types to attempt to narrow
9599the set of definitions. It also makes very limited use of context, preferring
9600procedures to functions in the context of the @code{call} command, and
9601functions to procedures elsewhere.
9602
9603@node Omissions from Ada
9604@subsubsection Omissions from Ada
9605@cindex Ada, omissions from
9606
9607Here are the notable omissions from the subset:
9608
9609@itemize @bullet
9610@item
9611Only a subset of the attributes are supported:
9612
9613@itemize @minus
9614@item
9615@t{'First}, @t{'Last}, and @t{'Length}
9616 on array objects (not on types and subtypes).
9617
9618@item
9619@t{'Min} and @t{'Max}.
9620
9621@item
9622@t{'Pos} and @t{'Val}.
9623
9624@item
9625@t{'Tag}.
9626
9627@item
9628@t{'Range} on array objects (not subtypes), but only as the right
9629operand of the membership (@code{in}) operator.
9630
9631@item
9632@t{'Access}, @t{'Unchecked_Access}, and
9633@t{'Unrestricted_Access} (a GNAT extension).
9634
9635@item
9636@t{'Address}.
9637@end itemize
9638
9639@item
9640The names in
9641@code{Characters.Latin_1} are not available and
9642concatenation is not implemented. Thus, escape characters in strings are
9643not currently available.
9644
9645@item
9646Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9647equality of representations. They will generally work correctly
9648for strings and arrays whose elements have integer or enumeration types.
9649They may not work correctly for arrays whose element
9650types have user-defined equality, for arrays of real values
9651(in particular, IEEE-conformant floating point, because of negative
9652zeroes and NaNs), and for arrays whose elements contain unused bits with
9653indeterminate values.
9654
9655@item
9656The other component-by-component array operations (@code{and}, @code{or},
9657@code{xor}, @code{not}, and relational tests other than equality)
9658are not implemented.
9659
9660@item
9661There are no record or array aggregates.
9662
9663@item
9664Calls to dispatching subprograms are not implemented.
9665
9666@item
9667The overloading algorithm is much more limited (i.e., less selective)
9668than that of real Ada. It makes only limited use of the context in which a subexpression
9669appears to resolve its meaning, and it is much looser in its rules for allowing
9670type matches. As a result, some function calls will be ambiguous, and the user
9671will be asked to choose the proper resolution.
9672
9673@item
9674The @code{new} operator is not implemented.
9675
9676@item
9677Entry calls are not implemented.
9678
9679@item
9680Aside from printing, arithmetic operations on the native VAX floating-point
9681formats are not supported.
9682
9683@item
9684It is not possible to slice a packed array.
9685@end itemize
9686
9687@node Additions to Ada
9688@subsubsection Additions to Ada
9689@cindex Ada, deviations from
9690
9691As it does for other languages, @value{GDBN} makes certain generic
9692extensions to Ada (@pxref{Expressions}):
9693
9694@itemize @bullet
9695@item
9696If the expression @var{E} is a variable residing in memory
9697(typically a local variable or array element) and @var{N} is
9698a positive integer, then @code{@var{E}@@@var{N}} displays the values of
9699@var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
9700In Ada, this operator is generally not necessary, since its prime use
9701is in displaying parts of an array, and slicing will usually do this in Ada.
9702However, there are occasional uses when debugging programs
9703in which certain debugging information has been optimized away.
9704
9705@item
9706@code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
9707in function or file @var{B}.'' When @var{B} is a file name, you must typically
9708surround it in single quotes.
9709
9710@item
9711The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
9712@var{type} that appears at address @var{addr}.''
9713
9714@item
9715A name starting with @samp{$} is a convenience variable
9716(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
9717@end itemize
9718
9719In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
9720to Ada:
9721
9722@itemize @bullet
9723@item
9724The assignment statement is allowed as an expression, returning
9725its right-hand operand as its value. Thus, you may enter
9726
9727@smallexample
9728set x := y + 3
9729print A(tmp := y + 1)
9730@end smallexample
9731
9732@item
9733The semicolon is allowed as an ``operator,'' returning as its value
9734the value of its right-hand operand.
9735This allows, for example,
9736complex conditional breaks:
9737
9738@smallexample
9739break f
9740condition 1 (report(i); k += 1; A(k) > 100)
9741@end smallexample
9742
9743@item
9744Rather than use catenation and symbolic character names to introduce special
9745characters into strings, one may instead use a special bracket notation,
9746which is also used to print strings. A sequence of characters of the form
9747@samp{["@var{XX}"]} within a string or character literal denotes the
9748(single) character whose numeric encoding is @var{XX} in hexadecimal. The
9749sequence of characters @samp{["""]} also denotes a single quotation mark
9750in strings. For example,
9751@smallexample
9752 "One line.["0a"]Next line.["0a"]"
9753@end smallexample
9754@noindent
9755contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
9756period.
9757
9758@item
9759The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
9760@t{'Max} is optional (and is ignored in any case). For example, it is valid
9761to write
9762
9763@smallexample
9764print 'max(x, y)
9765@end smallexample
9766
9767@item
9768When printing arrays, @value{GDBN} uses positional notation when the
9769array has a lower bound of 1, and uses a modified named notation otherwise.
9770For example, a one-dimensional array of three integers with a lower bound of 3 might print as
9771
9772@smallexample
9773(3 => 10, 17, 1)
9774@end smallexample
9775
9776@noindent
9777That is, in contrast to valid Ada, only the first component has a @code{=>}
9778clause.
9779
9780@item
9781You may abbreviate attributes in expressions with any unique,
9782multi-character subsequence of
9783their names (an exact match gets preference).
9784For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
9785in place of @t{a'length}.
9786
9787@item
9788@cindex quoting Ada internal identifiers
9789Since Ada is case-insensitive, the debugger normally maps identifiers you type
9790to lower case. The GNAT compiler uses upper-case characters for
9791some of its internal identifiers, which are normally of no interest to users.
9792For the rare occasions when you actually have to look at them,
9793enclose them in angle brackets to avoid the lower-case mapping.
9794For example,
9795@smallexample
9796@value{GDBP} print <JMPBUF_SAVE>[0]
9797@end smallexample
9798
9799@item
9800Printing an object of class-wide type or dereferencing an
9801access-to-class-wide value will display all the components of the object's
9802specific type (as indicated by its run-time tag). Likewise, component
9803selection on such a value will operate on the specific type of the
9804object.
9805
9806@end itemize
9807
9808@node Stopping Before Main Program
9809@subsubsection Stopping at the Very Beginning
9810
9811@cindex breakpointing Ada elaboration code
9812It is sometimes necessary to debug the program during elaboration, and
9813before reaching the main procedure.
9814As defined in the Ada Reference
9815Manual, the elaboration code is invoked from a procedure called
9816@code{adainit}. To run your program up to the beginning of
9817elaboration, simply use the following two commands:
9818@code{tbreak adainit} and @code{run}.
9819
9820@node Ada Glitches
9821@subsubsection Known Peculiarities of Ada Mode
9822@cindex Ada, problems
9823
9824Besides the omissions listed previously (@pxref{Omissions from Ada}),
9825we know of several problems with and limitations of Ada mode in
9826@value{GDBN},
9827some of which will be fixed with planned future releases of the debugger
9828and the GNU Ada compiler.
9829
9830@itemize @bullet
9831@item
9832Currently, the debugger
9833has insufficient information to determine whether certain pointers represent
9834pointers to objects or the objects themselves.
9835Thus, the user may have to tack an extra @code{.all} after an expression
9836to get it printed properly.
9837
9838@item
9839Static constants that the compiler chooses not to materialize as objects in
9840storage are invisible to the debugger.
9841
9842@item
9843Named parameter associations in function argument lists are ignored (the
9844argument lists are treated as positional).
9845
9846@item
9847Many useful library packages are currently invisible to the debugger.
9848
9849@item
9850Fixed-point arithmetic, conversions, input, and output is carried out using
9851floating-point arithmetic, and may give results that only approximate those on
9852the host machine.
9853
9854@item
9855The type of the @t{'Address} attribute may not be @code{System.Address}.
9856
9857@item
9858The GNAT compiler never generates the prefix @code{Standard} for any of
9859the standard symbols defined by the Ada language. @value{GDBN} knows about
9860this: it will strip the prefix from names when you use it, and will never
9861look for a name you have so qualified among local symbols, nor match against
9862symbols in other packages or subprograms. If you have
9863defined entities anywhere in your program other than parameters and
9864local variables whose simple names match names in @code{Standard},
9865GNAT's lack of qualification here can cause confusion. When this happens,
9866you can usually resolve the confusion
9867by qualifying the problematic names with package
9868@code{Standard} explicitly.
9869@end itemize
9870
4e562065
JB
9871@node Unsupported languages
9872@section Unsupported languages
9873
9874@cindex unsupported languages
9875@cindex minimal language
9876In addition to the other fully-supported programming languages,
9877@value{GDBN} also provides a pseudo-language, called @code{minimal}.
9878It does not represent a real programming language, but provides a set
9879of capabilities close to what the C or assembly languages provide.
9880This should allow most simple operations to be performed while debugging
9881an application that uses a language currently not supported by @value{GDBN}.
9882
9883If the language is set to @code{auto}, @value{GDBN} will automatically
9884select this language if the current frame corresponds to an unsupported
9885language.
9886
6d2ebf8b 9887@node Symbols
c906108c
SS
9888@chapter Examining the Symbol Table
9889
d4f3574e 9890The commands described in this chapter allow you to inquire about the
c906108c
SS
9891symbols (names of variables, functions and types) defined in your
9892program. This information is inherent in the text of your program and
9893does not change as your program executes. @value{GDBN} finds it in your
9894program's symbol table, in the file indicated when you started @value{GDBN}
9895(@pxref{File Options, ,Choosing files}), or by one of the
9896file-management commands (@pxref{Files, ,Commands to specify files}).
9897
9898@cindex symbol names
9899@cindex names of symbols
9900@cindex quoting names
9901Occasionally, you may need to refer to symbols that contain unusual
9902characters, which @value{GDBN} ordinarily treats as word delimiters. The
9903most frequent case is in referring to static variables in other
9904source files (@pxref{Variables,,Program variables}). File names
9905are recorded in object files as debugging symbols, but @value{GDBN} would
9906ordinarily parse a typical file name, like @file{foo.c}, as the three words
9907@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
9908@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
9909
474c8240 9910@smallexample
c906108c 9911p 'foo.c'::x
474c8240 9912@end smallexample
c906108c
SS
9913
9914@noindent
9915looks up the value of @code{x} in the scope of the file @file{foo.c}.
9916
9917@table @code
a8f24a35
EZ
9918@cindex case-insensitive symbol names
9919@cindex case sensitivity in symbol names
9920@kindex set case-sensitive
9921@item set case-sensitive on
9922@itemx set case-sensitive off
9923@itemx set case-sensitive auto
9924Normally, when @value{GDBN} looks up symbols, it matches their names
9925with case sensitivity determined by the current source language.
9926Occasionally, you may wish to control that. The command @code{set
9927case-sensitive} lets you do that by specifying @code{on} for
9928case-sensitive matches or @code{off} for case-insensitive ones. If
9929you specify @code{auto}, case sensitivity is reset to the default
9930suitable for the source language. The default is case-sensitive
9931matches for all languages except for Fortran, for which the default is
9932case-insensitive matches.
9933
9c16f35a
EZ
9934@kindex show case-sensitive
9935@item show case-sensitive
a8f24a35
EZ
9936This command shows the current setting of case sensitivity for symbols
9937lookups.
9938
c906108c 9939@kindex info address
b37052ae 9940@cindex address of a symbol
c906108c
SS
9941@item info address @var{symbol}
9942Describe where the data for @var{symbol} is stored. For a register
9943variable, this says which register it is kept in. For a non-register
9944local variable, this prints the stack-frame offset at which the variable
9945is always stored.
9946
9947Note the contrast with @samp{print &@var{symbol}}, which does not work
9948at all for a register variable, and for a stack local variable prints
9949the exact address of the current instantiation of the variable.
9950
3d67e040 9951@kindex info symbol
b37052ae 9952@cindex symbol from address
9c16f35a 9953@cindex closest symbol and offset for an address
3d67e040
EZ
9954@item info symbol @var{addr}
9955Print the name of a symbol which is stored at the address @var{addr}.
9956If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
9957nearest symbol and an offset from it:
9958
474c8240 9959@smallexample
3d67e040
EZ
9960(@value{GDBP}) info symbol 0x54320
9961_initialize_vx + 396 in section .text
474c8240 9962@end smallexample
3d67e040
EZ
9963
9964@noindent
9965This is the opposite of the @code{info address} command. You can use
9966it to find out the name of a variable or a function given its address.
9967
c906108c 9968@kindex whatis
d4f3574e
SS
9969@item whatis @var{expr}
9970Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
9971actually evaluated, and any side-effecting operations (such as
9972assignments or function calls) inside it do not take place.
9973@xref{Expressions, ,Expressions}.
9974
9975@item whatis
9976Print the data type of @code{$}, the last value in the value history.
9977
9978@kindex ptype
9979@item ptype @var{typename}
9980Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
9981the name of a type, or for C code it may have the form @samp{class
9982@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
9983@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 9984
d4f3574e 9985@item ptype @var{expr}
c906108c 9986@itemx ptype
d4f3574e 9987Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
9988differs from @code{whatis} by printing a detailed description, instead
9989of just the name of the type.
9990
9991For example, for this variable declaration:
9992
474c8240 9993@smallexample
c906108c 9994struct complex @{double real; double imag;@} v;
474c8240 9995@end smallexample
c906108c
SS
9996
9997@noindent
9998the two commands give this output:
9999
474c8240 10000@smallexample
c906108c
SS
10001@group
10002(@value{GDBP}) whatis v
10003type = struct complex
10004(@value{GDBP}) ptype v
10005type = struct complex @{
10006 double real;
10007 double imag;
10008@}
10009@end group
474c8240 10010@end smallexample
c906108c
SS
10011
10012@noindent
10013As with @code{whatis}, using @code{ptype} without an argument refers to
10014the type of @code{$}, the last value in the value history.
10015
10016@kindex info types
10017@item info types @var{regexp}
10018@itemx info types
09d4efe1
EZ
10019Print a brief description of all types whose names match the regular
10020expression @var{regexp} (or all types in your program, if you supply
10021no argument). Each complete typename is matched as though it were a
10022complete line; thus, @samp{i type value} gives information on all
10023types in your program whose names include the string @code{value}, but
10024@samp{i type ^value$} gives information only on types whose complete
10025name is @code{value}.
c906108c
SS
10026
10027This command differs from @code{ptype} in two ways: first, like
10028@code{whatis}, it does not print a detailed description; second, it
10029lists all source files where a type is defined.
10030
b37052ae
EZ
10031@kindex info scope
10032@cindex local variables
09d4efe1 10033@item info scope @var{location}
b37052ae 10034List all the variables local to a particular scope. This command
09d4efe1
EZ
10035accepts a @var{location} argument---a function name, a source line, or
10036an address preceded by a @samp{*}, and prints all the variables local
10037to the scope defined by that location. For example:
b37052ae
EZ
10038
10039@smallexample
10040(@value{GDBP}) @b{info scope command_line_handler}
10041Scope for command_line_handler:
10042Symbol rl is an argument at stack/frame offset 8, length 4.
10043Symbol linebuffer is in static storage at address 0x150a18, length 4.
10044Symbol linelength is in static storage at address 0x150a1c, length 4.
10045Symbol p is a local variable in register $esi, length 4.
10046Symbol p1 is a local variable in register $ebx, length 4.
10047Symbol nline is a local variable in register $edx, length 4.
10048Symbol repeat is a local variable at frame offset -8, length 4.
10049@end smallexample
10050
f5c37c66
EZ
10051@noindent
10052This command is especially useful for determining what data to collect
10053during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
10054collect}.
10055
c906108c
SS
10056@kindex info source
10057@item info source
919d772c
JB
10058Show information about the current source file---that is, the source file for
10059the function containing the current point of execution:
10060@itemize @bullet
10061@item
10062the name of the source file, and the directory containing it,
10063@item
10064the directory it was compiled in,
10065@item
10066its length, in lines,
10067@item
10068which programming language it is written in,
10069@item
10070whether the executable includes debugging information for that file, and
10071if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
10072@item
10073whether the debugging information includes information about
10074preprocessor macros.
10075@end itemize
10076
c906108c
SS
10077
10078@kindex info sources
10079@item info sources
10080Print the names of all source files in your program for which there is
10081debugging information, organized into two lists: files whose symbols
10082have already been read, and files whose symbols will be read when needed.
10083
10084@kindex info functions
10085@item info functions
10086Print the names and data types of all defined functions.
10087
10088@item info functions @var{regexp}
10089Print the names and data types of all defined functions
10090whose names contain a match for regular expression @var{regexp}.
10091Thus, @samp{info fun step} finds all functions whose names
10092include @code{step}; @samp{info fun ^step} finds those whose names
b383017d
RM
10093start with @code{step}. If a function name contains characters
10094that conflict with the regular expression language (eg.
1c5dfdad 10095@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
10096
10097@kindex info variables
10098@item info variables
10099Print the names and data types of all variables that are declared
6ca652b0 10100outside of functions (i.e.@: excluding local variables).
c906108c
SS
10101
10102@item info variables @var{regexp}
10103Print the names and data types of all variables (except for local
10104variables) whose names contain a match for regular expression
10105@var{regexp}.
10106
b37303ee 10107@kindex info classes
721c2651 10108@cindex Objective-C, classes and selectors
b37303ee
AF
10109@item info classes
10110@itemx info classes @var{regexp}
10111Display all Objective-C classes in your program, or
10112(with the @var{regexp} argument) all those matching a particular regular
10113expression.
10114
10115@kindex info selectors
10116@item info selectors
10117@itemx info selectors @var{regexp}
10118Display all Objective-C selectors in your program, or
10119(with the @var{regexp} argument) all those matching a particular regular
10120expression.
10121
c906108c
SS
10122@ignore
10123This was never implemented.
10124@kindex info methods
10125@item info methods
10126@itemx info methods @var{regexp}
10127The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
10128methods within C@t{++} program, or (with the @var{regexp} argument) a
10129specific set of methods found in the various C@t{++} classes. Many
10130C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
10131from the @code{ptype} command can be overwhelming and hard to use. The
10132@code{info-methods} command filters the methods, printing only those
10133which match the regular-expression @var{regexp}.
10134@end ignore
10135
c906108c
SS
10136@cindex reloading symbols
10137Some systems allow individual object files that make up your program to
7a292a7a
SS
10138be replaced without stopping and restarting your program. For example,
10139in VxWorks you can simply recompile a defective object file and keep on
10140running. If you are running on one of these systems, you can allow
10141@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
10142
10143@table @code
10144@kindex set symbol-reloading
10145@item set symbol-reloading on
10146Replace symbol definitions for the corresponding source file when an
10147object file with a particular name is seen again.
10148
10149@item set symbol-reloading off
6d2ebf8b
SS
10150Do not replace symbol definitions when encountering object files of the
10151same name more than once. This is the default state; if you are not
10152running on a system that permits automatic relinking of modules, you
10153should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
10154may discard symbols when linking large programs, that may contain
10155several modules (from different directories or libraries) with the same
10156name.
c906108c
SS
10157
10158@kindex show symbol-reloading
10159@item show symbol-reloading
10160Show the current @code{on} or @code{off} setting.
10161@end table
c906108c 10162
9c16f35a 10163@cindex opaque data types
c906108c
SS
10164@kindex set opaque-type-resolution
10165@item set opaque-type-resolution on
10166Tell @value{GDBN} to resolve opaque types. An opaque type is a type
10167declared as a pointer to a @code{struct}, @code{class}, or
10168@code{union}---for example, @code{struct MyType *}---that is used in one
10169source file although the full declaration of @code{struct MyType} is in
10170another source file. The default is on.
10171
10172A change in the setting of this subcommand will not take effect until
10173the next time symbols for a file are loaded.
10174
10175@item set opaque-type-resolution off
10176Tell @value{GDBN} not to resolve opaque types. In this case, the type
10177is printed as follows:
10178@smallexample
10179@{<no data fields>@}
10180@end smallexample
10181
10182@kindex show opaque-type-resolution
10183@item show opaque-type-resolution
10184Show whether opaque types are resolved or not.
c906108c
SS
10185
10186@kindex maint print symbols
10187@cindex symbol dump
10188@kindex maint print psymbols
10189@cindex partial symbol dump
10190@item maint print symbols @var{filename}
10191@itemx maint print psymbols @var{filename}
10192@itemx maint print msymbols @var{filename}
10193Write a dump of debugging symbol data into the file @var{filename}.
10194These commands are used to debug the @value{GDBN} symbol-reading code. Only
10195symbols with debugging data are included. If you use @samp{maint print
10196symbols}, @value{GDBN} includes all the symbols for which it has already
10197collected full details: that is, @var{filename} reflects symbols for
10198only those files whose symbols @value{GDBN} has read. You can use the
10199command @code{info sources} to find out which files these are. If you
10200use @samp{maint print psymbols} instead, the dump shows information about
10201symbols that @value{GDBN} only knows partially---that is, symbols defined in
10202files that @value{GDBN} has skimmed, but not yet read completely. Finally,
10203@samp{maint print msymbols} dumps just the minimal symbol information
10204required for each object file from which @value{GDBN} has read some symbols.
10205@xref{Files, ,Commands to specify files}, for a discussion of how
10206@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 10207
5e7b2f39
JB
10208@kindex maint info symtabs
10209@kindex maint info psymtabs
44ea7b70
JB
10210@cindex listing @value{GDBN}'s internal symbol tables
10211@cindex symbol tables, listing @value{GDBN}'s internal
10212@cindex full symbol tables, listing @value{GDBN}'s internal
10213@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
10214@item maint info symtabs @r{[} @var{regexp} @r{]}
10215@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
10216
10217List the @code{struct symtab} or @code{struct partial_symtab}
10218structures whose names match @var{regexp}. If @var{regexp} is not
10219given, list them all. The output includes expressions which you can
10220copy into a @value{GDBN} debugging this one to examine a particular
10221structure in more detail. For example:
10222
10223@smallexample
5e7b2f39 10224(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
10225@{ objfile /home/gnu/build/gdb/gdb
10226 ((struct objfile *) 0x82e69d0)
b383017d 10227 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10228 ((struct partial_symtab *) 0x8474b10)
10229 readin no
10230 fullname (null)
10231 text addresses 0x814d3c8 -- 0x8158074
10232 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
10233 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
10234 dependencies (none)
10235 @}
10236@}
5e7b2f39 10237(@value{GDBP}) maint info symtabs
44ea7b70
JB
10238(@value{GDBP})
10239@end smallexample
10240@noindent
10241We see that there is one partial symbol table whose filename contains
10242the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
10243and we see that @value{GDBN} has not read in any symtabs yet at all.
10244If we set a breakpoint on a function, that will cause @value{GDBN} to
10245read the symtab for the compilation unit containing that function:
10246
10247@smallexample
10248(@value{GDBP}) break dwarf2_psymtab_to_symtab
10249Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
10250line 1574.
5e7b2f39 10251(@value{GDBP}) maint info symtabs
b383017d 10252@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 10253 ((struct objfile *) 0x82e69d0)
b383017d 10254 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10255 ((struct symtab *) 0x86c1f38)
10256 dirname (null)
10257 fullname (null)
10258 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
10259 debugformat DWARF 2
10260 @}
10261@}
b383017d 10262(@value{GDBP})
44ea7b70 10263@end smallexample
c906108c
SS
10264@end table
10265
44ea7b70 10266
6d2ebf8b 10267@node Altering
c906108c
SS
10268@chapter Altering Execution
10269
10270Once you think you have found an error in your program, you might want to
10271find out for certain whether correcting the apparent error would lead to
10272correct results in the rest of the run. You can find the answer by
10273experiment, using the @value{GDBN} features for altering execution of the
10274program.
10275
10276For example, you can store new values into variables or memory
7a292a7a
SS
10277locations, give your program a signal, restart it at a different
10278address, or even return prematurely from a function.
c906108c
SS
10279
10280@menu
10281* Assignment:: Assignment to variables
10282* Jumping:: Continuing at a different address
c906108c 10283* Signaling:: Giving your program a signal
c906108c
SS
10284* Returning:: Returning from a function
10285* Calling:: Calling your program's functions
10286* Patching:: Patching your program
10287@end menu
10288
6d2ebf8b 10289@node Assignment
c906108c
SS
10290@section Assignment to variables
10291
10292@cindex assignment
10293@cindex setting variables
10294To alter the value of a variable, evaluate an assignment expression.
10295@xref{Expressions, ,Expressions}. For example,
10296
474c8240 10297@smallexample
c906108c 10298print x=4
474c8240 10299@end smallexample
c906108c
SS
10300
10301@noindent
10302stores the value 4 into the variable @code{x}, and then prints the
5d161b24 10303value of the assignment expression (which is 4).
c906108c
SS
10304@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
10305information on operators in supported languages.
c906108c
SS
10306
10307@kindex set variable
10308@cindex variables, setting
10309If you are not interested in seeing the value of the assignment, use the
10310@code{set} command instead of the @code{print} command. @code{set} is
10311really the same as @code{print} except that the expression's value is
10312not printed and is not put in the value history (@pxref{Value History,
10313,Value history}). The expression is evaluated only for its effects.
10314
c906108c
SS
10315If the beginning of the argument string of the @code{set} command
10316appears identical to a @code{set} subcommand, use the @code{set
10317variable} command instead of just @code{set}. This command is identical
10318to @code{set} except for its lack of subcommands. For example, if your
10319program has a variable @code{width}, you get an error if you try to set
10320a new value with just @samp{set width=13}, because @value{GDBN} has the
10321command @code{set width}:
10322
474c8240 10323@smallexample
c906108c
SS
10324(@value{GDBP}) whatis width
10325type = double
10326(@value{GDBP}) p width
10327$4 = 13
10328(@value{GDBP}) set width=47
10329Invalid syntax in expression.
474c8240 10330@end smallexample
c906108c
SS
10331
10332@noindent
10333The invalid expression, of course, is @samp{=47}. In
10334order to actually set the program's variable @code{width}, use
10335
474c8240 10336@smallexample
c906108c 10337(@value{GDBP}) set var width=47
474c8240 10338@end smallexample
53a5351d 10339
c906108c
SS
10340Because the @code{set} command has many subcommands that can conflict
10341with the names of program variables, it is a good idea to use the
10342@code{set variable} command instead of just @code{set}. For example, if
10343your program has a variable @code{g}, you run into problems if you try
10344to set a new value with just @samp{set g=4}, because @value{GDBN} has
10345the command @code{set gnutarget}, abbreviated @code{set g}:
10346
474c8240 10347@smallexample
c906108c
SS
10348@group
10349(@value{GDBP}) whatis g
10350type = double
10351(@value{GDBP}) p g
10352$1 = 1
10353(@value{GDBP}) set g=4
2df3850c 10354(@value{GDBP}) p g
c906108c
SS
10355$2 = 1
10356(@value{GDBP}) r
10357The program being debugged has been started already.
10358Start it from the beginning? (y or n) y
10359Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
10360"/home/smith/cc_progs/a.out": can't open to read symbols:
10361 Invalid bfd target.
c906108c
SS
10362(@value{GDBP}) show g
10363The current BFD target is "=4".
10364@end group
474c8240 10365@end smallexample
c906108c
SS
10366
10367@noindent
10368The program variable @code{g} did not change, and you silently set the
10369@code{gnutarget} to an invalid value. In order to set the variable
10370@code{g}, use
10371
474c8240 10372@smallexample
c906108c 10373(@value{GDBP}) set var g=4
474c8240 10374@end smallexample
c906108c
SS
10375
10376@value{GDBN} allows more implicit conversions in assignments than C; you can
10377freely store an integer value into a pointer variable or vice versa,
10378and you can convert any structure to any other structure that is the
10379same length or shorter.
10380@comment FIXME: how do structs align/pad in these conversions?
10381@comment /doc@cygnus.com 18dec1990
10382
10383To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
10384construct to generate a value of specified type at a specified address
10385(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
10386to memory location @code{0x83040} as an integer (which implies a certain size
10387and representation in memory), and
10388
474c8240 10389@smallexample
c906108c 10390set @{int@}0x83040 = 4
474c8240 10391@end smallexample
c906108c
SS
10392
10393@noindent
10394stores the value 4 into that memory location.
10395
6d2ebf8b 10396@node Jumping
c906108c
SS
10397@section Continuing at a different address
10398
10399Ordinarily, when you continue your program, you do so at the place where
10400it stopped, with the @code{continue} command. You can instead continue at
10401an address of your own choosing, with the following commands:
10402
10403@table @code
10404@kindex jump
10405@item jump @var{linespec}
10406Resume execution at line @var{linespec}. Execution stops again
10407immediately if there is a breakpoint there. @xref{List, ,Printing
10408source lines}, for a description of the different forms of
10409@var{linespec}. It is common practice to use the @code{tbreak} command
10410in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
10411breakpoints}.
10412
10413The @code{jump} command does not change the current stack frame, or
10414the stack pointer, or the contents of any memory location or any
10415register other than the program counter. If line @var{linespec} is in
10416a different function from the one currently executing, the results may
10417be bizarre if the two functions expect different patterns of arguments or
10418of local variables. For this reason, the @code{jump} command requests
10419confirmation if the specified line is not in the function currently
10420executing. However, even bizarre results are predictable if you are
10421well acquainted with the machine-language code of your program.
10422
10423@item jump *@var{address}
10424Resume execution at the instruction at address @var{address}.
10425@end table
10426
c906108c 10427@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
10428On many systems, you can get much the same effect as the @code{jump}
10429command by storing a new value into the register @code{$pc}. The
10430difference is that this does not start your program running; it only
10431changes the address of where it @emph{will} run when you continue. For
10432example,
c906108c 10433
474c8240 10434@smallexample
c906108c 10435set $pc = 0x485
474c8240 10436@end smallexample
c906108c
SS
10437
10438@noindent
10439makes the next @code{continue} command or stepping command execute at
10440address @code{0x485}, rather than at the address where your program stopped.
10441@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
10442
10443The most common occasion to use the @code{jump} command is to back
10444up---perhaps with more breakpoints set---over a portion of a program
10445that has already executed, in order to examine its execution in more
10446detail.
10447
c906108c 10448@c @group
6d2ebf8b 10449@node Signaling
c906108c 10450@section Giving your program a signal
9c16f35a 10451@cindex deliver a signal to a program
c906108c
SS
10452
10453@table @code
10454@kindex signal
10455@item signal @var{signal}
10456Resume execution where your program stopped, but immediately give it the
10457signal @var{signal}. @var{signal} can be the name or the number of a
10458signal. For example, on many systems @code{signal 2} and @code{signal
10459SIGINT} are both ways of sending an interrupt signal.
10460
10461Alternatively, if @var{signal} is zero, continue execution without
10462giving a signal. This is useful when your program stopped on account of
10463a signal and would ordinary see the signal when resumed with the
10464@code{continue} command; @samp{signal 0} causes it to resume without a
10465signal.
10466
10467@code{signal} does not repeat when you press @key{RET} a second time
10468after executing the command.
10469@end table
10470@c @end group
10471
10472Invoking the @code{signal} command is not the same as invoking the
10473@code{kill} utility from the shell. Sending a signal with @code{kill}
10474causes @value{GDBN} to decide what to do with the signal depending on
10475the signal handling tables (@pxref{Signals}). The @code{signal} command
10476passes the signal directly to your program.
10477
c906108c 10478
6d2ebf8b 10479@node Returning
c906108c
SS
10480@section Returning from a function
10481
10482@table @code
10483@cindex returning from a function
10484@kindex return
10485@item return
10486@itemx return @var{expression}
10487You can cancel execution of a function call with the @code{return}
10488command. If you give an
10489@var{expression} argument, its value is used as the function's return
10490value.
10491@end table
10492
10493When you use @code{return}, @value{GDBN} discards the selected stack frame
10494(and all frames within it). You can think of this as making the
10495discarded frame return prematurely. If you wish to specify a value to
10496be returned, give that value as the argument to @code{return}.
10497
10498This pops the selected stack frame (@pxref{Selection, ,Selecting a
10499frame}), and any other frames inside of it, leaving its caller as the
10500innermost remaining frame. That frame becomes selected. The
10501specified value is stored in the registers used for returning values
10502of functions.
10503
10504The @code{return} command does not resume execution; it leaves the
10505program stopped in the state that would exist if the function had just
10506returned. In contrast, the @code{finish} command (@pxref{Continuing
10507and Stepping, ,Continuing and stepping}) resumes execution until the
10508selected stack frame returns naturally.
10509
6d2ebf8b 10510@node Calling
c906108c
SS
10511@section Calling program functions
10512
f8568604 10513@table @code
c906108c 10514@cindex calling functions
f8568604
EZ
10515@cindex inferior functions, calling
10516@item print @var{expr}
9c16f35a 10517Evaluate the expression @var{expr} and display the resuling value.
f8568604
EZ
10518@var{expr} may include calls to functions in the program being
10519debugged.
10520
c906108c 10521@kindex call
c906108c
SS
10522@item call @var{expr}
10523Evaluate the expression @var{expr} without displaying @code{void}
10524returned values.
c906108c
SS
10525
10526You can use this variant of the @code{print} command if you want to
f8568604
EZ
10527execute a function from your program that does not return anything
10528(a.k.a.@: @dfn{a void function}), but without cluttering the output
10529with @code{void} returned values that @value{GDBN} will otherwise
10530print. If the result is not void, it is printed and saved in the
10531value history.
10532@end table
10533
9c16f35a
EZ
10534It is possible for the function you call via the @code{print} or
10535@code{call} command to generate a signal (e.g., if there's a bug in
10536the function, or if you passed it incorrect arguments). What happens
10537in that case is controlled by the @code{set unwindonsignal} command.
10538
10539@table @code
10540@item set unwindonsignal
10541@kindex set unwindonsignal
10542@cindex unwind stack in called functions
10543@cindex call dummy stack unwinding
10544Set unwinding of the stack if a signal is received while in a function
10545that @value{GDBN} called in the program being debugged. If set to on,
10546@value{GDBN} unwinds the stack it created for the call and restores
10547the context to what it was before the call. If set to off (the
10548default), @value{GDBN} stops in the frame where the signal was
10549received.
10550
10551@item show unwindonsignal
10552@kindex show unwindonsignal
10553Show the current setting of stack unwinding in the functions called by
10554@value{GDBN}.
10555@end table
10556
f8568604
EZ
10557@cindex weak alias functions
10558Sometimes, a function you wish to call is actually a @dfn{weak alias}
10559for another function. In such case, @value{GDBN} might not pick up
10560the type information, including the types of the function arguments,
10561which causes @value{GDBN} to call the inferior function incorrectly.
10562As a result, the called function will function erroneously and may
10563even crash. A solution to that is to use the name of the aliased
10564function instead.
c906108c 10565
6d2ebf8b 10566@node Patching
c906108c 10567@section Patching programs
7a292a7a 10568
c906108c
SS
10569@cindex patching binaries
10570@cindex writing into executables
c906108c 10571@cindex writing into corefiles
c906108c 10572
7a292a7a
SS
10573By default, @value{GDBN} opens the file containing your program's
10574executable code (or the corefile) read-only. This prevents accidental
10575alterations to machine code; but it also prevents you from intentionally
10576patching your program's binary.
c906108c
SS
10577
10578If you'd like to be able to patch the binary, you can specify that
10579explicitly with the @code{set write} command. For example, you might
10580want to turn on internal debugging flags, or even to make emergency
10581repairs.
10582
10583@table @code
10584@kindex set write
10585@item set write on
10586@itemx set write off
7a292a7a
SS
10587If you specify @samp{set write on}, @value{GDBN} opens executable and
10588core files for both reading and writing; if you specify @samp{set write
c906108c
SS
10589off} (the default), @value{GDBN} opens them read-only.
10590
10591If you have already loaded a file, you must load it again (using the
7a292a7a
SS
10592@code{exec-file} or @code{core-file} command) after changing @code{set
10593write}, for your new setting to take effect.
c906108c
SS
10594
10595@item show write
10596@kindex show write
7a292a7a
SS
10597Display whether executable files and core files are opened for writing
10598as well as reading.
c906108c
SS
10599@end table
10600
6d2ebf8b 10601@node GDB Files
c906108c
SS
10602@chapter @value{GDBN} Files
10603
7a292a7a
SS
10604@value{GDBN} needs to know the file name of the program to be debugged,
10605both in order to read its symbol table and in order to start your
10606program. To debug a core dump of a previous run, you must also tell
10607@value{GDBN} the name of the core dump file.
c906108c
SS
10608
10609@menu
10610* Files:: Commands to specify files
5b5d99cf 10611* Separate Debug Files:: Debugging information in separate files
c906108c
SS
10612* Symbol Errors:: Errors reading symbol files
10613@end menu
10614
6d2ebf8b 10615@node Files
c906108c 10616@section Commands to specify files
c906108c 10617
7a292a7a 10618@cindex symbol table
c906108c 10619@cindex core dump file
7a292a7a
SS
10620
10621You may want to specify executable and core dump file names. The usual
10622way to do this is at start-up time, using the arguments to
10623@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
10624Out of @value{GDBN}}).
c906108c
SS
10625
10626Occasionally it is necessary to change to a different file during a
397ca115
EZ
10627@value{GDBN} session. Or you may run @value{GDBN} and forget to
10628specify a file you want to use. Or you are debugging a remote target
10629via @code{gdbserver} (@pxref{Server, file}). In these situations the
10630@value{GDBN} commands to specify new files are useful.
c906108c
SS
10631
10632@table @code
10633@cindex executable file
10634@kindex file
10635@item file @var{filename}
10636Use @var{filename} as the program to be debugged. It is read for its
10637symbols and for the contents of pure memory. It is also the program
10638executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
10639directory and the file is not found in the @value{GDBN} working directory,
10640@value{GDBN} uses the environment variable @code{PATH} as a list of
10641directories to search, just as the shell does when looking for a program
10642to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
10643and your program, using the @code{path} command.
10644
6d2ebf8b 10645On systems with memory-mapped files, an auxiliary file named
c906108c
SS
10646@file{@var{filename}.syms} may hold symbol table information for
10647@var{filename}. If so, @value{GDBN} maps in the symbol table from
10648@file{@var{filename}.syms}, starting up more quickly. See the
10649descriptions of the file options @samp{-mapped} and @samp{-readnow}
7b5ba0cc
EZ
10650(available on the command line, see @ref{File Options, , -readnow},
10651and with the commands @code{file}, @code{symbol-file}, or
10652@code{add-symbol-file}, described below), for more information.
c906108c 10653
fc8be69e
EZ
10654@cindex unlinked object files
10655@cindex patching object files
10656You can load unlinked object @file{.o} files into @value{GDBN} using
10657the @code{file} command. You will not be able to ``run'' an object
10658file, but you can disassemble functions and inspect variables. Also,
10659if the underlying BFD functionality supports it, you could use
10660@kbd{gdb -write} to patch object files using this technique. Note
10661that @value{GDBN} can neither interpret nor modify relocations in this
10662case, so branches and some initialized variables will appear to go to
10663the wrong place. But this feature is still handy from time to time.
10664
c906108c
SS
10665@item file
10666@code{file} with no argument makes @value{GDBN} discard any information it
10667has on both executable file and the symbol table.
10668
10669@kindex exec-file
10670@item exec-file @r{[} @var{filename} @r{]}
10671Specify that the program to be run (but not the symbol table) is found
10672in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
10673if necessary to locate your program. Omitting @var{filename} means to
10674discard information on the executable file.
10675
10676@kindex symbol-file
10677@item symbol-file @r{[} @var{filename} @r{]}
10678Read symbol table information from file @var{filename}. @code{PATH} is
10679searched when necessary. Use the @code{file} command to get both symbol
10680table and program to run from the same file.
10681
10682@code{symbol-file} with no argument clears out @value{GDBN} information on your
10683program's symbol table.
10684
5d161b24 10685The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
10686of its convenience variables, the value history, and all breakpoints and
10687auto-display expressions. This is because they may contain pointers to
10688the internal data recording symbols and data types, which are part of
10689the old symbol table data being discarded inside @value{GDBN}.
10690
10691@code{symbol-file} does not repeat if you press @key{RET} again after
10692executing it once.
10693
10694When @value{GDBN} is configured for a particular environment, it
10695understands debugging information in whatever format is the standard
10696generated for that environment; you may use either a @sc{gnu} compiler, or
10697other compilers that adhere to the local conventions.
c906108c
SS
10698Best results are usually obtained from @sc{gnu} compilers; for example,
10699using @code{@value{GCC}} you can generate debugging information for
10700optimized code.
c906108c
SS
10701
10702For most kinds of object files, with the exception of old SVR3 systems
10703using COFF, the @code{symbol-file} command does not normally read the
10704symbol table in full right away. Instead, it scans the symbol table
10705quickly to find which source files and which symbols are present. The
10706details are read later, one source file at a time, as they are needed.
10707
10708The purpose of this two-stage reading strategy is to make @value{GDBN}
10709start up faster. For the most part, it is invisible except for
10710occasional pauses while the symbol table details for a particular source
10711file are being read. (The @code{set verbose} command can turn these
10712pauses into messages if desired. @xref{Messages/Warnings, ,Optional
10713warnings and messages}.)
10714
c906108c
SS
10715We have not implemented the two-stage strategy for COFF yet. When the
10716symbol table is stored in COFF format, @code{symbol-file} reads the
10717symbol table data in full right away. Note that ``stabs-in-COFF''
10718still does the two-stage strategy, since the debug info is actually
10719in stabs format.
10720
10721@kindex readnow
10722@cindex reading symbols immediately
10723@cindex symbols, reading immediately
10724@kindex mapped
10725@cindex memory-mapped symbol file
10726@cindex saving symbol table
10727@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10728@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10729You can override the @value{GDBN} two-stage strategy for reading symbol
10730tables by using the @samp{-readnow} option with any of the commands that
10731load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 10732entire symbol table available.
c906108c 10733
c906108c
SS
10734If memory-mapped files are available on your system through the
10735@code{mmap} system call, you can use another option, @samp{-mapped}, to
10736cause @value{GDBN} to write the symbols for your program into a reusable
10737file. Future @value{GDBN} debugging sessions map in symbol information
10738from this auxiliary symbol file (if the program has not changed), rather
10739than spending time reading the symbol table from the executable
10740program. Using the @samp{-mapped} option has the same effect as
10741starting @value{GDBN} with the @samp{-mapped} command-line option.
10742
10743You can use both options together, to make sure the auxiliary symbol
10744file has all the symbol information for your program.
10745
10746The auxiliary symbol file for a program called @var{myprog} is called
10747@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
10748than the corresponding executable), @value{GDBN} always attempts to use
10749it when you debug @var{myprog}; no special options or commands are
10750needed.
10751
10752The @file{.syms} file is specific to the host machine where you run
10753@value{GDBN}. It holds an exact image of the internal @value{GDBN}
10754symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
10755
10756@c FIXME: for now no mention of directories, since this seems to be in
10757@c flux. 13mar1992 status is that in theory GDB would look either in
10758@c current dir or in same dir as myprog; but issues like competing
10759@c GDB's, or clutter in system dirs, mean that in practice right now
10760@c only current dir is used. FFish says maybe a special GDB hierarchy
10761@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
10762@c files.
10763
c906108c 10764@kindex core-file
09d4efe1 10765@item core-file @r{[}@var{filename}@r{]}
4644b6e3 10766@itemx core
c906108c
SS
10767Specify the whereabouts of a core dump file to be used as the ``contents
10768of memory''. Traditionally, core files contain only some parts of the
10769address space of the process that generated them; @value{GDBN} can access the
10770executable file itself for other parts.
10771
10772@code{core-file} with no argument specifies that no core file is
10773to be used.
10774
10775Note that the core file is ignored when your program is actually running
7a292a7a
SS
10776under @value{GDBN}. So, if you have been running your program and you
10777wish to debug a core file instead, you must kill the subprocess in which
10778the program is running. To do this, use the @code{kill} command
c906108c 10779(@pxref{Kill Process, ,Killing the child process}).
c906108c 10780
c906108c
SS
10781@kindex add-symbol-file
10782@cindex dynamic linking
10783@item add-symbol-file @var{filename} @var{address}
10784@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
17d9d558 10785@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
10786The @code{add-symbol-file} command reads additional symbol table
10787information from the file @var{filename}. You would use this command
10788when @var{filename} has been dynamically loaded (by some other means)
10789into the program that is running. @var{address} should be the memory
10790address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
10791this out for itself. You can additionally specify an arbitrary number
10792of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
10793section name and base address for that section. You can specify any
10794@var{address} as an expression.
c906108c
SS
10795
10796The symbol table of the file @var{filename} is added to the symbol table
10797originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
10798@code{add-symbol-file} command any number of times; the new symbol data
10799thus read keeps adding to the old. To discard all old symbol data
10800instead, use the @code{symbol-file} command without any arguments.
c906108c 10801
17d9d558
JB
10802@cindex relocatable object files, reading symbols from
10803@cindex object files, relocatable, reading symbols from
10804@cindex reading symbols from relocatable object files
10805@cindex symbols, reading from relocatable object files
10806@cindex @file{.o} files, reading symbols from
10807Although @var{filename} is typically a shared library file, an
10808executable file, or some other object file which has been fully
10809relocated for loading into a process, you can also load symbolic
10810information from relocatable @file{.o} files, as long as:
10811
10812@itemize @bullet
10813@item
10814the file's symbolic information refers only to linker symbols defined in
10815that file, not to symbols defined by other object files,
10816@item
10817every section the file's symbolic information refers to has actually
10818been loaded into the inferior, as it appears in the file, and
10819@item
10820you can determine the address at which every section was loaded, and
10821provide these to the @code{add-symbol-file} command.
10822@end itemize
10823
10824@noindent
10825Some embedded operating systems, like Sun Chorus and VxWorks, can load
10826relocatable files into an already running program; such systems
10827typically make the requirements above easy to meet. However, it's
10828important to recognize that many native systems use complex link
49efadf5 10829procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
10830assembly, for example) that make the requirements difficult to meet. In
10831general, one cannot assume that using @code{add-symbol-file} to read a
10832relocatable object file's symbolic information will have the same effect
10833as linking the relocatable object file into the program in the normal
10834way.
10835
c906108c
SS
10836@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
10837
10838You can use the @samp{-mapped} and @samp{-readnow} options just as with
10839the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
10840table information for @var{filename}.
10841
c45da7e6
EZ
10842@kindex add-symbol-file-from-memory
10843@cindex @code{syscall DSO}
10844@cindex load symbols from memory
10845@item add-symbol-file-from-memory @var{address}
10846Load symbols from the given @var{address} in a dynamically loaded
10847object file whose image is mapped directly into the inferior's memory.
10848For example, the Linux kernel maps a @code{syscall DSO} into each
10849process's address space; this DSO provides kernel-specific code for
10850some system calls. The argument can be any expression whose
10851evaluation yields the address of the file's shared object file header.
10852For this command to work, you must have used @code{symbol-file} or
10853@code{exec-file} commands in advance.
10854
09d4efe1
EZ
10855@kindex add-shared-symbol-files
10856@kindex assf
10857@item add-shared-symbol-files @var{library-file}
10858@itemx assf @var{library-file}
10859The @code{add-shared-symbol-files} command can currently be used only
10860in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
10861alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
10862@value{GDBN} automatically looks for shared libraries, however if
10863@value{GDBN} does not find yours, you can invoke
10864@code{add-shared-symbol-files}. It takes one argument: the shared
10865library's file name. @code{assf} is a shorthand alias for
10866@code{add-shared-symbol-files}.
c906108c 10867
c906108c 10868@kindex section
09d4efe1
EZ
10869@item section @var{section} @var{addr}
10870The @code{section} command changes the base address of the named
10871@var{section} of the exec file to @var{addr}. This can be used if the
10872exec file does not contain section addresses, (such as in the
10873@code{a.out} format), or when the addresses specified in the file
10874itself are wrong. Each section must be changed separately. The
10875@code{info files} command, described below, lists all the sections and
10876their addresses.
c906108c
SS
10877
10878@kindex info files
10879@kindex info target
10880@item info files
10881@itemx info target
7a292a7a
SS
10882@code{info files} and @code{info target} are synonymous; both print the
10883current target (@pxref{Targets, ,Specifying a Debugging Target}),
10884including the names of the executable and core dump files currently in
10885use by @value{GDBN}, and the files from which symbols were loaded. The
10886command @code{help target} lists all possible targets rather than
10887current ones.
10888
fe95c787
MS
10889@kindex maint info sections
10890@item maint info sections
10891Another command that can give you extra information about program sections
10892is @code{maint info sections}. In addition to the section information
10893displayed by @code{info files}, this command displays the flags and file
10894offset of each section in the executable and core dump files. In addition,
10895@code{maint info sections} provides the following command options (which
10896may be arbitrarily combined):
10897
10898@table @code
10899@item ALLOBJ
10900Display sections for all loaded object files, including shared libraries.
10901@item @var{sections}
6600abed 10902Display info only for named @var{sections}.
fe95c787
MS
10903@item @var{section-flags}
10904Display info only for sections for which @var{section-flags} are true.
10905The section flags that @value{GDBN} currently knows about are:
10906@table @code
10907@item ALLOC
10908Section will have space allocated in the process when loaded.
10909Set for all sections except those containing debug information.
10910@item LOAD
10911Section will be loaded from the file into the child process memory.
10912Set for pre-initialized code and data, clear for @code{.bss} sections.
10913@item RELOC
10914Section needs to be relocated before loading.
10915@item READONLY
10916Section cannot be modified by the child process.
10917@item CODE
10918Section contains executable code only.
6600abed 10919@item DATA
fe95c787
MS
10920Section contains data only (no executable code).
10921@item ROM
10922Section will reside in ROM.
10923@item CONSTRUCTOR
10924Section contains data for constructor/destructor lists.
10925@item HAS_CONTENTS
10926Section is not empty.
10927@item NEVER_LOAD
10928An instruction to the linker to not output the section.
10929@item COFF_SHARED_LIBRARY
10930A notification to the linker that the section contains
10931COFF shared library information.
10932@item IS_COMMON
10933Section contains common symbols.
10934@end table
10935@end table
6763aef9 10936@kindex set trust-readonly-sections
9c16f35a 10937@cindex read-only sections
6763aef9
MS
10938@item set trust-readonly-sections on
10939Tell @value{GDBN} that readonly sections in your object file
6ca652b0 10940really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
10941In that case, @value{GDBN} can fetch values from these sections
10942out of the object file, rather than from the target program.
10943For some targets (notably embedded ones), this can be a significant
10944enhancement to debugging performance.
10945
10946The default is off.
10947
10948@item set trust-readonly-sections off
15110bc3 10949Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
10950the contents of the section might change while the program is running,
10951and must therefore be fetched from the target when needed.
9c16f35a
EZ
10952
10953@item show trust-readonly-sections
10954Show the current setting of trusting readonly sections.
c906108c
SS
10955@end table
10956
10957All file-specifying commands allow both absolute and relative file names
10958as arguments. @value{GDBN} always converts the file name to an absolute file
10959name and remembers it that way.
10960
c906108c 10961@cindex shared libraries
9c16f35a
EZ
10962@value{GDBN} supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
10963and IBM RS/6000 AIX shared libraries.
53a5351d 10964
c906108c
SS
10965@value{GDBN} automatically loads symbol definitions from shared libraries
10966when you use the @code{run} command, or when you examine a core file.
10967(Before you issue the @code{run} command, @value{GDBN} does not understand
10968references to a function in a shared library, however---unless you are
10969debugging a core file).
53a5351d
JM
10970
10971On HP-UX, if the program loads a library explicitly, @value{GDBN}
10972automatically loads the symbols at the time of the @code{shl_load} call.
10973
c906108c
SS
10974@c FIXME: some @value{GDBN} release may permit some refs to undef
10975@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
10976@c FIXME...lib; check this from time to time when updating manual
10977
b7209cb4
FF
10978There are times, however, when you may wish to not automatically load
10979symbol definitions from shared libraries, such as when they are
10980particularly large or there are many of them.
10981
10982To control the automatic loading of shared library symbols, use the
10983commands:
10984
10985@table @code
10986@kindex set auto-solib-add
10987@item set auto-solib-add @var{mode}
10988If @var{mode} is @code{on}, symbols from all shared object libraries
10989will be loaded automatically when the inferior begins execution, you
10990attach to an independently started inferior, or when the dynamic linker
10991informs @value{GDBN} that a new library has been loaded. If @var{mode}
10992is @code{off}, symbols must be loaded manually, using the
10993@code{sharedlibrary} command. The default value is @code{on}.
10994
dcaf7c2c
EZ
10995@cindex memory used for symbol tables
10996If your program uses lots of shared libraries with debug info that
10997takes large amounts of memory, you can decrease the @value{GDBN}
10998memory footprint by preventing it from automatically loading the
10999symbols from shared libraries. To that end, type @kbd{set
11000auto-solib-add off} before running the inferior, then load each
11001library whose debug symbols you do need with @kbd{sharedlibrary
11002@var{regexp}}, where @var{regexp} is a regular expresion that matches
11003the libraries whose symbols you want to be loaded.
11004
b7209cb4
FF
11005@kindex show auto-solib-add
11006@item show auto-solib-add
11007Display the current autoloading mode.
11008@end table
11009
c45da7e6 11010@cindex load shared library
b7209cb4
FF
11011To explicitly load shared library symbols, use the @code{sharedlibrary}
11012command:
11013
c906108c
SS
11014@table @code
11015@kindex info sharedlibrary
11016@kindex info share
11017@item info share
11018@itemx info sharedlibrary
11019Print the names of the shared libraries which are currently loaded.
11020
11021@kindex sharedlibrary
11022@kindex share
11023@item sharedlibrary @var{regex}
11024@itemx share @var{regex}
c906108c
SS
11025Load shared object library symbols for files matching a
11026Unix regular expression.
11027As with files loaded automatically, it only loads shared libraries
11028required by your program for a core file or after typing @code{run}. If
11029@var{regex} is omitted all shared libraries required by your program are
11030loaded.
c45da7e6
EZ
11031
11032@item nosharedlibrary
11033@kindex nosharedlibrary
11034@cindex unload symbols from shared libraries
11035Unload all shared object library symbols. This discards all symbols
11036that have been loaded from all shared libraries. Symbols from shared
11037libraries that were loaded by explicit user requests are not
11038discarded.
c906108c
SS
11039@end table
11040
721c2651
EZ
11041Sometimes you may wish that @value{GDBN} stops and gives you control
11042when any of shared library events happen. Use the @code{set
11043stop-on-solib-events} command for this:
11044
11045@table @code
11046@item set stop-on-solib-events
11047@kindex set stop-on-solib-events
11048This command controls whether @value{GDBN} should give you control
11049when the dynamic linker notifies it about some shared library event.
11050The most common event of interest is loading or unloading of a new
11051shared library.
11052
11053@item show stop-on-solib-events
11054@kindex show stop-on-solib-events
11055Show whether @value{GDBN} stops and gives you control when shared
11056library events happen.
11057@end table
11058
f5ebfba0
DJ
11059Shared libraries are also supported in many cross or remote debugging
11060configurations. A copy of the target's libraries need to be present on the
11061host system; they need to be the same as the target libraries, although the
11062copies on the target can be stripped as long as the copies on the host are
11063not.
11064
11065You need to tell @value{GDBN} where the target libraries are, so that it can
11066load the correct copies---otherwise, it may try to load the host's libraries.
11067@value{GDBN} has two variables to specify the search directories for target
11068libraries.
11069
11070@table @code
11071@kindex set solib-absolute-prefix
11072@item set solib-absolute-prefix @var{path}
11073If this variable is set, @var{path} will be used as a prefix for any
11074absolute shared library paths; many runtime loaders store the absolute
11075paths to the shared library in the target program's memory. If you use
11076@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
11077out in the same way that they are on the target, with e.g.@: a
11078@file{/usr/lib} hierarchy under @var{path}.
11079
11080You can set the default value of @samp{solib-absolute-prefix} by using the
11081configure-time @samp{--with-sysroot} option.
11082
11083@kindex show solib-absolute-prefix
11084@item show solib-absolute-prefix
11085Display the current shared library prefix.
11086
11087@kindex set solib-search-path
11088@item set solib-search-path @var{path}
11089If this variable is set, @var{path} is a colon-separated list of directories
11090to search for shared libraries. @samp{solib-search-path} is used after
11091@samp{solib-absolute-prefix} fails to locate the library, or if the path to
11092the library is relative instead of absolute. If you want to use
11093@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
11094set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
11095@value{GDBN} from finding your host's libraries.
11096
11097@kindex show solib-search-path
11098@item show solib-search-path
11099Display the current shared library search path.
11100@end table
11101
5b5d99cf
JB
11102
11103@node Separate Debug Files
11104@section Debugging Information in Separate Files
11105@cindex separate debugging information files
11106@cindex debugging information in separate files
11107@cindex @file{.debug} subdirectories
11108@cindex debugging information directory, global
11109@cindex global debugging information directory
11110
11111@value{GDBN} allows you to put a program's debugging information in a
11112file separate from the executable itself, in a way that allows
11113@value{GDBN} to find and load the debugging information automatically.
11114Since debugging information can be very large --- sometimes larger
11115than the executable code itself --- some systems distribute debugging
11116information for their executables in separate files, which users can
11117install only when they need to debug a problem.
11118
11119If an executable's debugging information has been extracted to a
11120separate file, the executable should contain a @dfn{debug link} giving
11121the name of the debugging information file (with no directory
11122components), and a checksum of its contents. (The exact form of a
11123debug link is described below.) If the full name of the directory
11124containing the executable is @var{execdir}, and the executable has a
11125debug link that specifies the name @var{debugfile}, then @value{GDBN}
11126will automatically search for the debugging information file in three
11127places:
11128
11129@itemize @bullet
11130@item
11131the directory containing the executable file (that is, it will look
11132for a file named @file{@var{execdir}/@var{debugfile}},
11133@item
11134a subdirectory of that directory named @file{.debug} (that is, the
11135file @file{@var{execdir}/.debug/@var{debugfile}}, and
11136@item
11137a subdirectory of the global debug file directory that includes the
11138executable's full path, and the name from the link (that is, the file
11139@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
11140@var{globaldebugdir} is the global debug file directory, and
11141@var{execdir} has been turned into a relative path).
11142@end itemize
11143@noindent
11144@value{GDBN} checks under each of these names for a debugging
11145information file whose checksum matches that given in the link, and
11146reads the debugging information from the first one it finds.
11147
11148So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
11149which has a link containing the name @file{ls.debug}, and the global
11150debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
11151for debug information in @file{/usr/bin/ls.debug},
11152@file{/usr/bin/.debug/ls.debug}, and
11153@file{/usr/lib/debug/usr/bin/ls.debug}.
11154
11155You can set the global debugging info directory's name, and view the
11156name @value{GDBN} is currently using.
11157
11158@table @code
11159
11160@kindex set debug-file-directory
11161@item set debug-file-directory @var{directory}
11162Set the directory which @value{GDBN} searches for separate debugging
11163information files to @var{directory}.
11164
11165@kindex show debug-file-directory
11166@item show debug-file-directory
11167Show the directory @value{GDBN} searches for separate debugging
11168information files.
11169
11170@end table
11171
11172@cindex @code{.gnu_debuglink} sections
11173@cindex debug links
11174A debug link is a special section of the executable file named
11175@code{.gnu_debuglink}. The section must contain:
11176
11177@itemize
11178@item
11179A filename, with any leading directory components removed, followed by
11180a zero byte,
11181@item
11182zero to three bytes of padding, as needed to reach the next four-byte
11183boundary within the section, and
11184@item
11185a four-byte CRC checksum, stored in the same endianness used for the
11186executable file itself. The checksum is computed on the debugging
11187information file's full contents by the function given below, passing
11188zero as the @var{crc} argument.
11189@end itemize
11190
11191Any executable file format can carry a debug link, as long as it can
11192contain a section named @code{.gnu_debuglink} with the contents
11193described above.
11194
11195The debugging information file itself should be an ordinary
11196executable, containing a full set of linker symbols, sections, and
11197debugging information. The sections of the debugging information file
11198should have the same names, addresses and sizes as the original file,
11199but they need not contain any data --- much like a @code{.bss} section
11200in an ordinary executable.
11201
11202As of December 2002, there is no standard GNU utility to produce
11203separated executable / debugging information file pairs. Ulrich
11204Drepper's @file{elfutils} package, starting with version 0.53,
11205contains a version of the @code{strip} command such that the command
11206@kbd{strip foo -f foo.debug} removes the debugging information from
11207the executable file @file{foo}, places it in the file
11208@file{foo.debug}, and leaves behind a debug link in @file{foo}.
11209
11210Since there are many different ways to compute CRC's (different
11211polynomials, reversals, byte ordering, etc.), the simplest way to
11212describe the CRC used in @code{.gnu_debuglink} sections is to give the
11213complete code for a function that computes it:
11214
4644b6e3 11215@kindex gnu_debuglink_crc32
5b5d99cf
JB
11216@smallexample
11217unsigned long
11218gnu_debuglink_crc32 (unsigned long crc,
11219 unsigned char *buf, size_t len)
11220@{
11221 static const unsigned long crc32_table[256] =
11222 @{
11223 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11224 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11225 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11226 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11227 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11228 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11229 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11230 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11231 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11232 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11233 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11234 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11235 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11236 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11237 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11238 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11239 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11240 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11241 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11242 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11243 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11244 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11245 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11246 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11247 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11248 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11249 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11250 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11251 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11252 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11253 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11254 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11255 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11256 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11257 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11258 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11259 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11260 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11261 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11262 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11263 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11264 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11265 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11266 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11267 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11268 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11269 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11270 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11271 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11272 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11273 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11274 0x2d02ef8d
11275 @};
11276 unsigned char *end;
11277
11278 crc = ~crc & 0xffffffff;
11279 for (end = buf + len; buf < end; ++buf)
11280 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 11281 return ~crc & 0xffffffff;
5b5d99cf
JB
11282@}
11283@end smallexample
11284
11285
6d2ebf8b 11286@node Symbol Errors
c906108c
SS
11287@section Errors reading symbol files
11288
11289While reading a symbol file, @value{GDBN} occasionally encounters problems,
11290such as symbol types it does not recognize, or known bugs in compiler
11291output. By default, @value{GDBN} does not notify you of such problems, since
11292they are relatively common and primarily of interest to people
11293debugging compilers. If you are interested in seeing information
11294about ill-constructed symbol tables, you can either ask @value{GDBN} to print
11295only one message about each such type of problem, no matter how many
11296times the problem occurs; or you can ask @value{GDBN} to print more messages,
11297to see how many times the problems occur, with the @code{set
11298complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
11299messages}).
11300
11301The messages currently printed, and their meanings, include:
11302
11303@table @code
11304@item inner block not inside outer block in @var{symbol}
11305
11306The symbol information shows where symbol scopes begin and end
11307(such as at the start of a function or a block of statements). This
11308error indicates that an inner scope block is not fully contained
11309in its outer scope blocks.
11310
11311@value{GDBN} circumvents the problem by treating the inner block as if it had
11312the same scope as the outer block. In the error message, @var{symbol}
11313may be shown as ``@code{(don't know)}'' if the outer block is not a
11314function.
11315
11316@item block at @var{address} out of order
11317
11318The symbol information for symbol scope blocks should occur in
11319order of increasing addresses. This error indicates that it does not
11320do so.
11321
11322@value{GDBN} does not circumvent this problem, and has trouble
11323locating symbols in the source file whose symbols it is reading. (You
11324can often determine what source file is affected by specifying
11325@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
11326messages}.)
11327
11328@item bad block start address patched
11329
11330The symbol information for a symbol scope block has a start address
11331smaller than the address of the preceding source line. This is known
11332to occur in the SunOS 4.1.1 (and earlier) C compiler.
11333
11334@value{GDBN} circumvents the problem by treating the symbol scope block as
11335starting on the previous source line.
11336
11337@item bad string table offset in symbol @var{n}
11338
11339@cindex foo
11340Symbol number @var{n} contains a pointer into the string table which is
11341larger than the size of the string table.
11342
11343@value{GDBN} circumvents the problem by considering the symbol to have the
11344name @code{foo}, which may cause other problems if many symbols end up
11345with this name.
11346
11347@item unknown symbol type @code{0x@var{nn}}
11348
7a292a7a
SS
11349The symbol information contains new data types that @value{GDBN} does
11350not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 11351uncomprehended information, in hexadecimal.
c906108c 11352
7a292a7a
SS
11353@value{GDBN} circumvents the error by ignoring this symbol information.
11354This usually allows you to debug your program, though certain symbols
c906108c 11355are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
11356debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
11357on @code{complain}, then go up to the function @code{read_dbx_symtab}
11358and examine @code{*bufp} to see the symbol.
c906108c
SS
11359
11360@item stub type has NULL name
c906108c 11361
7a292a7a 11362@value{GDBN} could not find the full definition for a struct or class.
c906108c 11363
7a292a7a 11364@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 11365The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
11366information that recent versions of the compiler should have output for
11367it.
c906108c
SS
11368
11369@item info mismatch between compiler and debugger
11370
11371@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 11372
c906108c
SS
11373@end table
11374
6d2ebf8b 11375@node Targets
c906108c 11376@chapter Specifying a Debugging Target
7a292a7a 11377
c906108c 11378@cindex debugging target
c906108c 11379A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
11380
11381Often, @value{GDBN} runs in the same host environment as your program;
11382in that case, the debugging target is specified as a side effect when
11383you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
11384flexibility---for example, running @value{GDBN} on a physically separate
11385host, or controlling a standalone system over a serial port or a
53a5351d
JM
11386realtime system over a TCP/IP connection---you can use the @code{target}
11387command to specify one of the target types configured for @value{GDBN}
11388(@pxref{Target Commands, ,Commands for managing targets}).
c906108c 11389
a8f24a35
EZ
11390@cindex target architecture
11391It is possible to build @value{GDBN} for several different @dfn{target
11392architectures}. When @value{GDBN} is built like that, you can choose
11393one of the available architectures with the @kbd{set architecture}
11394command.
11395
11396@table @code
11397@kindex set architecture
11398@kindex show architecture
11399@item set architecture @var{arch}
11400This command sets the current target architecture to @var{arch}. The
11401value of @var{arch} can be @code{"auto"}, in addition to one of the
11402supported architectures.
11403
11404@item show architecture
11405Show the current target architecture.
9c16f35a
EZ
11406
11407@item set processor
11408@itemx processor
11409@kindex set processor
11410@kindex show processor
11411These are alias commands for, respectively, @code{set architecture}
11412and @code{show architecture}.
a8f24a35
EZ
11413@end table
11414
c906108c
SS
11415@menu
11416* Active Targets:: Active targets
11417* Target Commands:: Commands for managing targets
c906108c
SS
11418* Byte Order:: Choosing target byte order
11419* Remote:: Remote debugging
96baa820 11420* KOD:: Kernel Object Display
c906108c
SS
11421
11422@end menu
11423
6d2ebf8b 11424@node Active Targets
c906108c 11425@section Active targets
7a292a7a 11426
c906108c
SS
11427@cindex stacking targets
11428@cindex active targets
11429@cindex multiple targets
11430
c906108c 11431There are three classes of targets: processes, core files, and
7a292a7a
SS
11432executable files. @value{GDBN} can work concurrently on up to three
11433active targets, one in each class. This allows you to (for example)
11434start a process and inspect its activity without abandoning your work on
11435a core file.
c906108c
SS
11436
11437For example, if you execute @samp{gdb a.out}, then the executable file
11438@code{a.out} is the only active target. If you designate a core file as
11439well---presumably from a prior run that crashed and coredumped---then
11440@value{GDBN} has two active targets and uses them in tandem, looking
11441first in the corefile target, then in the executable file, to satisfy
11442requests for memory addresses. (Typically, these two classes of target
11443are complementary, since core files contain only a program's
11444read-write memory---variables and so on---plus machine status, while
11445executable files contain only the program text and initialized data.)
c906108c
SS
11446
11447When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
11448target as well. When a process target is active, all @value{GDBN}
11449commands requesting memory addresses refer to that target; addresses in
11450an active core file or executable file target are obscured while the
11451process target is active.
c906108c 11452
7a292a7a
SS
11453Use the @code{core-file} and @code{exec-file} commands to select a new
11454core file or executable target (@pxref{Files, ,Commands to specify
c906108c 11455files}). To specify as a target a process that is already running, use
7a292a7a
SS
11456the @code{attach} command (@pxref{Attach, ,Debugging an already-running
11457process}).
c906108c 11458
6d2ebf8b 11459@node Target Commands
c906108c
SS
11460@section Commands for managing targets
11461
11462@table @code
11463@item target @var{type} @var{parameters}
7a292a7a
SS
11464Connects the @value{GDBN} host environment to a target machine or
11465process. A target is typically a protocol for talking to debugging
11466facilities. You use the argument @var{type} to specify the type or
11467protocol of the target machine.
c906108c
SS
11468
11469Further @var{parameters} are interpreted by the target protocol, but
11470typically include things like device names or host names to connect
11471with, process numbers, and baud rates.
c906108c
SS
11472
11473The @code{target} command does not repeat if you press @key{RET} again
11474after executing the command.
11475
11476@kindex help target
11477@item help target
11478Displays the names of all targets available. To display targets
11479currently selected, use either @code{info target} or @code{info files}
11480(@pxref{Files, ,Commands to specify files}).
11481
11482@item help target @var{name}
11483Describe a particular target, including any parameters necessary to
11484select it.
11485
11486@kindex set gnutarget
11487@item set gnutarget @var{args}
5d161b24 11488@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 11489knows whether it is reading an @dfn{executable},
5d161b24
DB
11490a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
11491with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
11492with @code{gnutarget} the @code{target} refers to a program, not a machine.
11493
d4f3574e 11494@quotation
c906108c
SS
11495@emph{Warning:} To specify a file format with @code{set gnutarget},
11496you must know the actual BFD name.
d4f3574e 11497@end quotation
c906108c 11498
d4f3574e
SS
11499@noindent
11500@xref{Files, , Commands to specify files}.
c906108c 11501
5d161b24 11502@kindex show gnutarget
c906108c
SS
11503@item show gnutarget
11504Use the @code{show gnutarget} command to display what file format
11505@code{gnutarget} is set to read. If you have not set @code{gnutarget},
11506@value{GDBN} will determine the file format for each file automatically,
11507and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11508@end table
11509
4644b6e3 11510@cindex common targets
c906108c
SS
11511Here are some common targets (available, or not, depending on the GDB
11512configuration):
c906108c
SS
11513
11514@table @code
4644b6e3 11515@kindex target
c906108c 11516@item target exec @var{program}
4644b6e3 11517@cindex executable file target
c906108c
SS
11518An executable file. @samp{target exec @var{program}} is the same as
11519@samp{exec-file @var{program}}.
11520
c906108c 11521@item target core @var{filename}
4644b6e3 11522@cindex core dump file target
c906108c
SS
11523A core dump file. @samp{target core @var{filename}} is the same as
11524@samp{core-file @var{filename}}.
c906108c 11525
c906108c 11526@item target remote @var{dev}
4644b6e3 11527@cindex remote target
c906108c
SS
11528Remote serial target in GDB-specific protocol. The argument @var{dev}
11529specifies what serial device to use for the connection (e.g.
11530@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 11531supports the @code{load} command. This is only useful if you have
c906108c
SS
11532some other way of getting the stub to the target system, and you can put
11533it somewhere in memory where it won't get clobbered by the download.
11534
c906108c 11535@item target sim
4644b6e3 11536@cindex built-in simulator target
2df3850c 11537Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 11538In general,
474c8240 11539@smallexample
104c1213
JM
11540 target sim
11541 load
11542 run
474c8240 11543@end smallexample
d4f3574e 11544@noindent
104c1213 11545works; however, you cannot assume that a specific memory map, device
d4f3574e 11546drivers, or even basic I/O is available, although some simulators do
104c1213
JM
11547provide these. For info about any processor-specific simulator details,
11548see the appropriate section in @ref{Embedded Processors, ,Embedded
11549Processors}.
11550
c906108c
SS
11551@end table
11552
104c1213 11553Some configurations may include these targets as well:
c906108c
SS
11554
11555@table @code
11556
c906108c 11557@item target nrom @var{dev}
4644b6e3 11558@cindex NetROM ROM emulator target
c906108c
SS
11559NetROM ROM emulator. This target only supports downloading.
11560
c906108c
SS
11561@end table
11562
5d161b24 11563Different targets are available on different configurations of @value{GDBN};
c906108c 11564your configuration may have more or fewer targets.
c906108c 11565
721c2651
EZ
11566Many remote targets require you to download the executable's code once
11567you've successfully established a connection. You may wish to control
11568various aspects of this process, such as the size of the data chunks
11569used by @value{GDBN} to download program parts to the remote target.
a8f24a35
EZ
11570
11571@table @code
11572@kindex set download-write-size
11573@item set download-write-size @var{size}
11574Set the write size used when downloading a program. Only used when
11575downloading a program onto a remote target. Specify zero or a
11576negative value to disable blocked writes. The actual size of each
11577transfer is also limited by the size of the target packet and the
11578memory cache.
11579
11580@kindex show download-write-size
11581@item show download-write-size
721c2651 11582@kindex show download-write-size
a8f24a35 11583Show the current value of the write size.
721c2651
EZ
11584
11585@item set hash
11586@kindex set hash@r{, for remote monitors}
11587@cindex hash mark while downloading
11588This command controls whether a hash mark @samp{#} is displayed while
11589downloading a file to the remote monitor. If on, a hash mark is
11590displayed after each S-record is successfully downloaded to the
11591monitor.
11592
11593@item show hash
11594@kindex show hash@r{, for remote monitors}
11595Show the current status of displaying the hash mark.
11596
11597@item set debug monitor
11598@kindex set debug monitor
11599@cindex display remote monitor communications
11600Enable or disable display of communications messages between
11601@value{GDBN} and the remote monitor.
11602
11603@item show debug monitor
11604@kindex show debug monitor
11605Show the current status of displaying communications between
11606@value{GDBN} and the remote monitor.
a8f24a35 11607@end table
c906108c
SS
11608
11609@table @code
11610
11611@kindex load @var{filename}
11612@item load @var{filename}
c906108c
SS
11613Depending on what remote debugging facilities are configured into
11614@value{GDBN}, the @code{load} command may be available. Where it exists, it
11615is meant to make @var{filename} (an executable) available for debugging
11616on the remote system---by downloading, or dynamic linking, for example.
11617@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
11618the @code{add-symbol-file} command.
11619
11620If your @value{GDBN} does not have a @code{load} command, attempting to
11621execute it gets the error message ``@code{You can't do that when your
11622target is @dots{}}''
c906108c
SS
11623
11624The file is loaded at whatever address is specified in the executable.
11625For some object file formats, you can specify the load address when you
11626link the program; for other formats, like a.out, the object file format
11627specifies a fixed address.
11628@c FIXME! This would be a good place for an xref to the GNU linker doc.
11629
c906108c
SS
11630@code{load} does not repeat if you press @key{RET} again after using it.
11631@end table
11632
6d2ebf8b 11633@node Byte Order
c906108c 11634@section Choosing target byte order
7a292a7a 11635
c906108c
SS
11636@cindex choosing target byte order
11637@cindex target byte order
c906108c 11638
172c2a43 11639Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
11640offer the ability to run either big-endian or little-endian byte
11641orders. Usually the executable or symbol will include a bit to
11642designate the endian-ness, and you will not need to worry about
11643which to use. However, you may still find it useful to adjust
d4f3574e 11644@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
11645
11646@table @code
4644b6e3 11647@kindex set endian
c906108c
SS
11648@item set endian big
11649Instruct @value{GDBN} to assume the target is big-endian.
11650
c906108c
SS
11651@item set endian little
11652Instruct @value{GDBN} to assume the target is little-endian.
11653
c906108c
SS
11654@item set endian auto
11655Instruct @value{GDBN} to use the byte order associated with the
11656executable.
11657
11658@item show endian
11659Display @value{GDBN}'s current idea of the target byte order.
11660
11661@end table
11662
11663Note that these commands merely adjust interpretation of symbolic
11664data on the host, and that they have absolutely no effect on the
11665target system.
11666
6d2ebf8b 11667@node Remote
c906108c
SS
11668@section Remote debugging
11669@cindex remote debugging
11670
11671If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
11672@value{GDBN} in the usual way, it is often useful to use remote debugging.
11673For example, you might use remote debugging on an operating system kernel,
c906108c
SS
11674or on a small system which does not have a general purpose operating system
11675powerful enough to run a full-featured debugger.
11676
11677Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
11678to make this work with particular debugging targets. In addition,
5d161b24 11679@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
11680but not specific to any particular target system) which you can use if you
11681write the remote stubs---the code that runs on the remote system to
11682communicate with @value{GDBN}.
11683
11684Other remote targets may be available in your
11685configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 11686
c45da7e6
EZ
11687Once you've connected to the remote target, @value{GDBN} allows you to
11688send arbitrary commands to the remote monitor:
11689
11690@table @code
11691@item remote @var{command}
11692@kindex remote@r{, a command}
11693@cindex send command to remote monitor
11694Send an arbitrary @var{command} string to the remote monitor.
11695@end table
11696
11697
6f05cf9f
AC
11698@node KOD
11699@section Kernel Object Display
6f05cf9f 11700@cindex kernel object display
6f05cf9f
AC
11701@cindex KOD
11702
11703Some targets support kernel object display. Using this facility,
11704@value{GDBN} communicates specially with the underlying operating system
11705and can display information about operating system-level objects such as
11706mutexes and other synchronization objects. Exactly which objects can be
11707displayed is determined on a per-OS basis.
11708
3bbe9696 11709@kindex set os
6f05cf9f
AC
11710Use the @code{set os} command to set the operating system. This tells
11711@value{GDBN} which kernel object display module to initialize:
11712
474c8240 11713@smallexample
6f05cf9f 11714(@value{GDBP}) set os cisco
474c8240 11715@end smallexample
6f05cf9f 11716
3bbe9696
EZ
11717@kindex show os
11718The associated command @code{show os} displays the operating system
11719set with the @code{set os} command; if no operating system has been
11720set, @code{show os} will display an empty string @samp{""}.
11721
6f05cf9f
AC
11722If @code{set os} succeeds, @value{GDBN} will display some information
11723about the operating system, and will create a new @code{info} command
11724which can be used to query the target. The @code{info} command is named
11725after the operating system:
c906108c 11726
3bbe9696 11727@kindex info cisco
474c8240 11728@smallexample
6f05cf9f
AC
11729(@value{GDBP}) info cisco
11730List of Cisco Kernel Objects
11731Object Description
11732any Any and all objects
474c8240 11733@end smallexample
6f05cf9f
AC
11734
11735Further subcommands can be used to query about particular objects known
11736by the kernel.
11737
3bbe9696
EZ
11738There is currently no way to determine whether a given operating
11739system is supported other than to try setting it with @kbd{set os
11740@var{name}}, where @var{name} is the name of the operating system you
11741want to try.
6f05cf9f
AC
11742
11743
11744@node Remote Debugging
11745@chapter Debugging remote programs
11746
6b2f586d 11747@menu
07f31aa6 11748* Connecting:: Connecting to a remote target
6b2f586d
AC
11749* Server:: Using the gdbserver program
11750* NetWare:: Using the gdbserve.nlm program
501eef12 11751* Remote configuration:: Remote configuration
6b2f586d 11752* remote stub:: Implementing a remote stub
6b2f586d
AC
11753@end menu
11754
07f31aa6
DJ
11755@node Connecting
11756@section Connecting to a remote target
11757
11758On the @value{GDBN} host machine, you will need an unstripped copy of
11759your program, since @value{GDBN} needs symobl and debugging information.
11760Start up @value{GDBN} as usual, using the name of the local copy of your
11761program as the first argument.
11762
11763@cindex serial line, @code{target remote}
11764If you're using a serial line, you may want to give @value{GDBN} the
11765@w{@samp{--baud}} option, or use the @code{set remotebaud} command
9c16f35a
EZ
11766(@pxref{Remote configuration, set remotebaud}) before the
11767@code{target} command.
07f31aa6
DJ
11768
11769After that, use @code{target remote} to establish communications with
11770the target machine. Its argument specifies how to communicate---either
11771via a devicename attached to a direct serial line, or a TCP or UDP port
11772(possibly to a terminal server which in turn has a serial line to the
11773target). For example, to use a serial line connected to the device
11774named @file{/dev/ttyb}:
11775
11776@smallexample
11777target remote /dev/ttyb
11778@end smallexample
11779
11780@cindex TCP port, @code{target remote}
11781To use a TCP connection, use an argument of the form
11782@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
11783For example, to connect to port 2828 on a
11784terminal server named @code{manyfarms}:
11785
11786@smallexample
11787target remote manyfarms:2828
11788@end smallexample
11789
11790If your remote target is actually running on the same machine as
11791your debugger session (e.g.@: a simulator of your target running on
11792the same host), you can omit the hostname. For example, to connect
11793to port 1234 on your local machine:
11794
11795@smallexample
11796target remote :1234
11797@end smallexample
11798@noindent
11799
11800Note that the colon is still required here.
11801
11802@cindex UDP port, @code{target remote}
11803To use a UDP connection, use an argument of the form
11804@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
11805on a terminal server named @code{manyfarms}:
11806
11807@smallexample
11808target remote udp:manyfarms:2828
11809@end smallexample
11810
11811When using a UDP connection for remote debugging, you should keep in mind
11812that the `U' stands for ``Unreliable''. UDP can silently drop packets on
11813busy or unreliable networks, which will cause havoc with your debugging
11814session.
11815
11816Now you can use all the usual commands to examine and change data and to
11817step and continue the remote program.
11818
11819@cindex interrupting remote programs
11820@cindex remote programs, interrupting
11821Whenever @value{GDBN} is waiting for the remote program, if you type the
11822interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
11823program. This may or may not succeed, depending in part on the hardware
11824and the serial drivers the remote system uses. If you type the
11825interrupt character once again, @value{GDBN} displays this prompt:
11826
11827@smallexample
11828Interrupted while waiting for the program.
11829Give up (and stop debugging it)? (y or n)
11830@end smallexample
11831
11832If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
11833(If you decide you want to try again later, you can use @samp{target
11834remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
11835goes back to waiting.
11836
11837@table @code
11838@kindex detach (remote)
11839@item detach
11840When you have finished debugging the remote program, you can use the
11841@code{detach} command to release it from @value{GDBN} control.
11842Detaching from the target normally resumes its execution, but the results
11843will depend on your particular remote stub. After the @code{detach}
11844command, @value{GDBN} is free to connect to another target.
11845
11846@kindex disconnect
11847@item disconnect
11848The @code{disconnect} command behaves like @code{detach}, except that
11849the target is generally not resumed. It will wait for @value{GDBN}
11850(this instance or another one) to connect and continue debugging. After
11851the @code{disconnect} command, @value{GDBN} is again free to connect to
11852another target.
09d4efe1
EZ
11853
11854@cindex send command to remote monitor
11855@kindex monitor
11856@item monitor @var{cmd}
11857This command allows you to send commands directly to the remote
11858monitor.
07f31aa6
DJ
11859@end table
11860
6f05cf9f
AC
11861@node Server
11862@section Using the @code{gdbserver} program
11863
11864@kindex gdbserver
11865@cindex remote connection without stubs
11866@code{gdbserver} is a control program for Unix-like systems, which
11867allows you to connect your program with a remote @value{GDBN} via
11868@code{target remote}---but without linking in the usual debugging stub.
11869
11870@code{gdbserver} is not a complete replacement for the debugging stubs,
11871because it requires essentially the same operating-system facilities
11872that @value{GDBN} itself does. In fact, a system that can run
11873@code{gdbserver} to connect to a remote @value{GDBN} could also run
11874@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
11875because it is a much smaller program than @value{GDBN} itself. It is
11876also easier to port than all of @value{GDBN}, so you may be able to get
11877started more quickly on a new system by using @code{gdbserver}.
11878Finally, if you develop code for real-time systems, you may find that
11879the tradeoffs involved in real-time operation make it more convenient to
11880do as much development work as possible on another system, for example
11881by cross-compiling. You can use @code{gdbserver} to make a similar
11882choice for debugging.
11883
11884@value{GDBN} and @code{gdbserver} communicate via either a serial line
11885or a TCP connection, using the standard @value{GDBN} remote serial
11886protocol.
11887
11888@table @emph
11889@item On the target machine,
11890you need to have a copy of the program you want to debug.
11891@code{gdbserver} does not need your program's symbol table, so you can
11892strip the program if necessary to save space. @value{GDBN} on the host
11893system does all the symbol handling.
11894
11895To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 11896the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
11897syntax is:
11898
11899@smallexample
11900target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
11901@end smallexample
11902
11903@var{comm} is either a device name (to use a serial line) or a TCP
11904hostname and portnumber. For example, to debug Emacs with the argument
11905@samp{foo.txt} and communicate with @value{GDBN} over the serial port
11906@file{/dev/com1}:
11907
11908@smallexample
11909target> gdbserver /dev/com1 emacs foo.txt
11910@end smallexample
11911
11912@code{gdbserver} waits passively for the host @value{GDBN} to communicate
11913with it.
11914
11915To use a TCP connection instead of a serial line:
11916
11917@smallexample
11918target> gdbserver host:2345 emacs foo.txt
11919@end smallexample
11920
11921The only difference from the previous example is the first argument,
11922specifying that you are communicating with the host @value{GDBN} via
11923TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
11924expect a TCP connection from machine @samp{host} to local TCP port 2345.
11925(Currently, the @samp{host} part is ignored.) You can choose any number
11926you want for the port number as long as it does not conflict with any
11927TCP ports already in use on the target system (for example, @code{23} is
11928reserved for @code{telnet}).@footnote{If you choose a port number that
11929conflicts with another service, @code{gdbserver} prints an error message
11930and exits.} You must use the same port number with the host @value{GDBN}
11931@code{target remote} command.
11932
56460a61
DJ
11933On some targets, @code{gdbserver} can also attach to running programs.
11934This is accomplished via the @code{--attach} argument. The syntax is:
11935
11936@smallexample
11937target> gdbserver @var{comm} --attach @var{pid}
11938@end smallexample
11939
11940@var{pid} is the process ID of a currently running process. It isn't necessary
11941to point @code{gdbserver} at a binary for the running process.
11942
b1fe9455
DJ
11943@pindex pidof
11944@cindex attach to a program by name
11945You can debug processes by name instead of process ID if your target has the
11946@code{pidof} utility:
11947
11948@smallexample
11949target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
11950@end smallexample
11951
11952In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
11953has multiple threads, most versions of @code{pidof} support the
11954@code{-s} option to only return the first process ID.
11955
07f31aa6
DJ
11956@item On the host machine,
11957connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
11958For TCP connections, you must start up @code{gdbserver} prior to using
11959the @code{target remote} command. Otherwise you may get an error whose
11960text depends on the host system, but which usually looks something like
07f31aa6 11961@samp{Connection refused}. You don't need to use the @code{load}
397ca115
EZ
11962command in @value{GDBN} when using @code{gdbserver}, since the program is
11963already on the target. However, if you want to load the symbols (as
11964you normally would), do that with the @code{file} command, and issue
11965it @emph{before} connecting to the server; otherwise, you will get an
11966error message saying @code{"Program is already running"}, since the
11967program is considered running after the connection.
07f31aa6 11968
6f05cf9f
AC
11969@end table
11970
11971@node NetWare
11972@section Using the @code{gdbserve.nlm} program
11973
11974@kindex gdbserve.nlm
11975@code{gdbserve.nlm} is a control program for NetWare systems, which
11976allows you to connect your program with a remote @value{GDBN} via
11977@code{target remote}.
11978
11979@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
11980using the standard @value{GDBN} remote serial protocol.
11981
11982@table @emph
11983@item On the target machine,
11984you need to have a copy of the program you want to debug.
11985@code{gdbserve.nlm} does not need your program's symbol table, so you
11986can strip the program if necessary to save space. @value{GDBN} on the
11987host system does all the symbol handling.
11988
11989To use the server, you must tell it how to communicate with
11990@value{GDBN}; the name of your program; and the arguments for your
11991program. The syntax is:
11992
11993@smallexample
11994load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
11995 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
11996@end smallexample
11997
11998@var{board} and @var{port} specify the serial line; @var{baud} specifies
11999the baud rate used by the connection. @var{port} and @var{node} default
12000to 0, @var{baud} defaults to 9600@dmn{bps}.
12001
12002For example, to debug Emacs with the argument @samp{foo.txt}and
12003communicate with @value{GDBN} over serial port number 2 or board 1
12004using a 19200@dmn{bps} connection:
12005
12006@smallexample
12007load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
12008@end smallexample
12009
07f31aa6
DJ
12010@item
12011On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
12012Connecting to a remote target}).
6f05cf9f 12013
6f05cf9f
AC
12014@end table
12015
501eef12
AC
12016@node Remote configuration
12017@section Remote configuration
12018
9c16f35a
EZ
12019@kindex set remote
12020@kindex show remote
12021This section documents the configuration options available when
12022debugging remote programs. For the options related to the File I/O
12023extensions of the remote protocol, see @ref{The system call,
12024system-call-allowed}.
501eef12
AC
12025
12026@table @code
9c16f35a
EZ
12027@item set remoteaddresssize @var{bits}
12028@cindex adress size for remote targets
12029@cindex bits in remote address
12030Set the maximum size of address in a memory packet to the specified
12031number of bits. @value{GDBN} will mask off the address bits above
12032that number, when it passes addresses to the remote target. The
12033default value is the number of bits in the target's address.
12034
12035@item show remoteaddresssize
12036Show the current value of remote address size in bits.
12037
12038@item set remotebaud @var{n}
12039@cindex baud rate for remote targets
12040Set the baud rate for the remote serial I/O to @var{n} baud. The
12041value is used to set the speed of the serial port used for debugging
12042remote targets.
12043
12044@item show remotebaud
12045Show the current speed of the remote connection.
12046
12047@item set remotebreak
12048@cindex interrupt remote programs
12049@cindex BREAK signal instead of Ctrl-C
12050If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
12051when you press the @key{Ctrl-C} key to interrupt the program running
12052on the remote. If set to off, @value{GDBN} sends the @samp{Strl-C}
12053character instead. The default is off, since most remote systems
12054expect to see @samp{Ctrl-C} as the interrupt signal.
12055
12056@item show remotebreak
12057Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
12058interrupt the remote program.
12059
12060@item set remotedebug
12061@cindex debug remote protocol
12062@cindex remote protocol debugging
12063@cindex display remote packets
12064Control the debugging of the remote protocol. When enabled, each
12065packet sent to or received from the remote target is displayed. The
12066defaults is off.
12067
12068@item show remotedebug
12069Show the current setting of the remote protocol debugging.
12070
12071@item set remotedevice @var{device}
12072@cindex serial port name
12073Set the name of the serial port through which to communicate to the
12074remote target to @var{device}. This is the device used by
12075@value{GDBN} to open the serial communications line to the remote
12076target. There's no default, so you must set a valid port name for the
12077remote serial communications to work. (Some varieties of the
12078@code{target} command accept the port name as part of their
12079arguments.)
12080
12081@item show remotedevice
12082Show the current name of the serial port.
12083
12084@item set remotelogbase @var{base}
12085Set the base (a.k.a.@: radix) of logging serial protocol
12086communications to @var{base}. Supported values of @var{base} are:
12087@code{ascii}, @code{octal}, and @code{hex}. The default is
12088@code{ascii}.
12089
12090@item show remotelogbase
12091Show the current setting of the radix for logging remote serial
12092protocol.
12093
12094@item set remotelogfile @var{file}
12095@cindex record serial communications on file
12096Record remote serial communications on the named @var{file}. The
12097default is not to record at all.
12098
12099@item show remotelogfile.
12100Show the current setting of the file name on which to record the
12101serial communications.
12102
12103@item set remotetimeout @var{num}
12104@cindex timeout for serial communications
12105@cindex remote timeout
12106Set the timeout limit to wait for the remote target to respond to
12107@var{num} seconds. The default is 2 seconds.
12108
12109@item show remotetimeout
12110Show the current number of seconds to wait for the remote target
12111responses.
12112
12113@cindex limit hardware breakpoints and watchpoints
12114@cindex remote target, limit break- and watchpoints
501eef12
AC
12115@anchor{set remote hardware-watchpoint-limit}
12116@anchor{set remote hardware-breakpoint-limit}
12117@item set remote hardware-watchpoint-limit @var{limit}
12118@itemx set remote hardware-breakpoint-limit @var{limit}
12119Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
12120watchpoints. A limit of -1, the default, is treated as unlimited.
9c16f35a
EZ
12121
12122@item set remote fetch-register-packet
12123@itemx set remote set-register-packet
12124@itemx set remote P-packet
12125@itemx set remote p-packet
12126@cindex P-packet
12127@cindex fetch registers from remote targets
12128@cindex set registers in remote targets
12129Determine whether @value{GDBN} can set and fetch registers from the
12130remote target using the @samp{P} packets. The default depends on the
12131remote stub's support of the @samp{P} packets (@value{GDBN} queries
12132the stub when this packet is first required).
12133
12134@item show remote fetch-register-packet
12135@itemx show remote set-register-packet
12136@itemx show remote P-packet
12137@itemx show remote p-packet
12138Show the current setting of using the @samp{P} packets for setting and
12139fetching registers from the remote target.
12140
12141@cindex binary downloads
12142@cindex X-packet
12143@item set remote binary-download-packet
12144@itemx set remote X-packet
12145Determine whether @value{GDBN} sends downloads in binary mode using
12146the @samp{X} packets. The default is on.
12147
12148@item show remote binary-download-packet
12149@itemx show remote X-packet
12150Show the current setting of using the @samp{X} packets for binary
12151downloads.
12152
12153@item set remote read-aux-vector-packet
12154@cindex auxiliary vector of remote target
12155@cindex @code{auxv}, and remote targets
12156Set the use of the remote protocol's @samp{qPart:auxv:read} (target
12157auxiliary vector read) request. This request is used to fetch the
721c2651
EZ
12158remote target's @dfn{auxiliary vector}, see @ref{OS Information,
12159Auxiliary Vector}. The default setting depends on the remote stub's
12160support of this request (@value{GDBN} queries the stub when this
12161request is first required). @xref{General Query Packets, qPart}, for
12162more information about this request.
9c16f35a
EZ
12163
12164@item show remote read-aux-vector-packet
12165Show the current setting of use of the @samp{qPart:auxv:read} request.
12166
12167@item set remote symbol-lookup-packet
12168@cindex remote symbol lookup request
12169Set the use of the remote protocol's @samp{qSymbol} (target symbol
12170lookup) request. This request is used to communicate symbol
12171information to the remote target, e.g., whenever a new shared library
12172is loaded by the remote (@pxref{Files, shared libraries}). The
12173default setting depends on the remote stub's support of this request
12174(@value{GDBN} queries the stub when this request is first required).
12175@xref{General Query Packets, qSymbol}, for more information about this
12176request.
12177
12178@item show remote symbol-lookup-packet
12179Show the current setting of use of the @samp{qSymbol} request.
12180
12181@item set remote verbose-resume-packet
12182@cindex resume remote target
12183@cindex signal thread, and remote targets
12184@cindex single-step thread, and remote targets
12185@cindex thread-specific operations on remote targets
12186Set the use of the remote protocol's @samp{vCont} (descriptive resume)
12187request. This request is used to resume specific threads in the
12188remote target, and to single-step or signal them. The default setting
12189depends on the remote stub's support of this request (@value{GDBN}
12190queries the stub when this request is first required). This setting
12191affects debugging of multithreaded programs: if @samp{vCont} cannot be
12192used, @value{GDBN} might be unable to single-step a specific thread,
12193especially under @code{set scheduler-locking off}; it is also
12194impossible to pause a specific thread. @xref{Packets, vCont}, for
12195more details.
12196
12197@item show remote verbose-resume-packet
12198Show the current setting of use of the @samp{vCont} request
12199
12200@item set remote software-breakpoint-packet
12201@itemx set remote hardware-breakpoint-packet
12202@itemx set remote write-watchpoint-packet
12203@itemx set remote read-watchpoint-packet
12204@itemx set remote access-watchpoint-packet
12205@itemx set remote Z-packet
12206@cindex Z-packet
12207@cindex remote hardware breakpoints and watchpoints
12208These commands enable or disable the use of @samp{Z} packets for
12209setting breakpoints and watchpoints in the remote target. The default
12210depends on the remote stub's support of the @samp{Z} packets
12211(@value{GDBN} queries the stub when each packet is first required).
12212The command @code{set remote Z-packet}, kept for back-compatibility,
12213turns on or off all the features that require the use of @samp{Z}
12214packets.
12215
12216@item show remote software-breakpoint-packet
12217@itemx show remote hardware-breakpoint-packet
12218@itemx show remote write-watchpoint-packet
12219@itemx show remote read-watchpoint-packet
12220@itemx show remote access-watchpoint-packet
12221@itemx show remote Z-packet
12222Show the current setting of @samp{Z} packets usage.
0abb7bc7
EZ
12223
12224@item set remote get-thread-local-storage-address
12225@kindex set remote get-thread-local-storage-address
12226@cindex thread local storage of remote targets
12227This command enables or disables the use of the @samp{qGetTLSAddr}
12228(Get Thread Local Storage Address) request packet. The default
12229depends on whether the remote stub supports this request.
12230@xref{General Query Packets, qGetTLSAddr}, for more details about this
12231packet.
12232
12233@item show remote get-thread-local-storage-address
12234@kindex show remote get-thread-local-storage-address
12235Show the current setting of @samp{qGetTLSAddr} packet usage.
501eef12
AC
12236@end table
12237
6f05cf9f
AC
12238@node remote stub
12239@section Implementing a remote stub
7a292a7a 12240
8e04817f
AC
12241@cindex debugging stub, example
12242@cindex remote stub, example
12243@cindex stub example, remote debugging
12244The stub files provided with @value{GDBN} implement the target side of the
12245communication protocol, and the @value{GDBN} side is implemented in the
12246@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
12247these subroutines to communicate, and ignore the details. (If you're
12248implementing your own stub file, you can still ignore the details: start
12249with one of the existing stub files. @file{sparc-stub.c} is the best
12250organized, and therefore the easiest to read.)
12251
104c1213
JM
12252@cindex remote serial debugging, overview
12253To debug a program running on another machine (the debugging
12254@dfn{target} machine), you must first arrange for all the usual
12255prerequisites for the program to run by itself. For example, for a C
12256program, you need:
c906108c 12257
104c1213
JM
12258@enumerate
12259@item
12260A startup routine to set up the C runtime environment; these usually
12261have a name like @file{crt0}. The startup routine may be supplied by
12262your hardware supplier, or you may have to write your own.
96baa820 12263
5d161b24 12264@item
d4f3574e 12265A C subroutine library to support your program's
104c1213 12266subroutine calls, notably managing input and output.
96baa820 12267
104c1213
JM
12268@item
12269A way of getting your program to the other machine---for example, a
12270download program. These are often supplied by the hardware
12271manufacturer, but you may have to write your own from hardware
12272documentation.
12273@end enumerate
96baa820 12274
104c1213
JM
12275The next step is to arrange for your program to use a serial port to
12276communicate with the machine where @value{GDBN} is running (the @dfn{host}
12277machine). In general terms, the scheme looks like this:
96baa820 12278
104c1213
JM
12279@table @emph
12280@item On the host,
12281@value{GDBN} already understands how to use this protocol; when everything
12282else is set up, you can simply use the @samp{target remote} command
12283(@pxref{Targets,,Specifying a Debugging Target}).
12284
12285@item On the target,
12286you must link with your program a few special-purpose subroutines that
12287implement the @value{GDBN} remote serial protocol. The file containing these
12288subroutines is called a @dfn{debugging stub}.
12289
12290On certain remote targets, you can use an auxiliary program
12291@code{gdbserver} instead of linking a stub into your program.
12292@xref{Server,,Using the @code{gdbserver} program}, for details.
12293@end table
96baa820 12294
104c1213
JM
12295The debugging stub is specific to the architecture of the remote
12296machine; for example, use @file{sparc-stub.c} to debug programs on
12297@sc{sparc} boards.
96baa820 12298
104c1213
JM
12299@cindex remote serial stub list
12300These working remote stubs are distributed with @value{GDBN}:
96baa820 12301
104c1213
JM
12302@table @code
12303
12304@item i386-stub.c
41afff9a 12305@cindex @file{i386-stub.c}
104c1213
JM
12306@cindex Intel
12307@cindex i386
12308For Intel 386 and compatible architectures.
12309
12310@item m68k-stub.c
41afff9a 12311@cindex @file{m68k-stub.c}
104c1213
JM
12312@cindex Motorola 680x0
12313@cindex m680x0
12314For Motorola 680x0 architectures.
12315
12316@item sh-stub.c
41afff9a 12317@cindex @file{sh-stub.c}
172c2a43 12318@cindex Renesas
104c1213 12319@cindex SH
172c2a43 12320For Renesas SH architectures.
104c1213
JM
12321
12322@item sparc-stub.c
41afff9a 12323@cindex @file{sparc-stub.c}
104c1213
JM
12324@cindex Sparc
12325For @sc{sparc} architectures.
12326
12327@item sparcl-stub.c
41afff9a 12328@cindex @file{sparcl-stub.c}
104c1213
JM
12329@cindex Fujitsu
12330@cindex SparcLite
12331For Fujitsu @sc{sparclite} architectures.
12332
12333@end table
12334
12335The @file{README} file in the @value{GDBN} distribution may list other
12336recently added stubs.
12337
12338@menu
12339* Stub Contents:: What the stub can do for you
12340* Bootstrapping:: What you must do for the stub
12341* Debug Session:: Putting it all together
104c1213
JM
12342@end menu
12343
6d2ebf8b 12344@node Stub Contents
6f05cf9f 12345@subsection What the stub can do for you
104c1213
JM
12346
12347@cindex remote serial stub
12348The debugging stub for your architecture supplies these three
12349subroutines:
12350
12351@table @code
12352@item set_debug_traps
4644b6e3 12353@findex set_debug_traps
104c1213
JM
12354@cindex remote serial stub, initialization
12355This routine arranges for @code{handle_exception} to run when your
12356program stops. You must call this subroutine explicitly near the
12357beginning of your program.
12358
12359@item handle_exception
4644b6e3 12360@findex handle_exception
104c1213
JM
12361@cindex remote serial stub, main routine
12362This is the central workhorse, but your program never calls it
12363explicitly---the setup code arranges for @code{handle_exception} to
12364run when a trap is triggered.
12365
12366@code{handle_exception} takes control when your program stops during
12367execution (for example, on a breakpoint), and mediates communications
12368with @value{GDBN} on the host machine. This is where the communications
12369protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 12370representative on the target machine. It begins by sending summary
104c1213
JM
12371information on the state of your program, then continues to execute,
12372retrieving and transmitting any information @value{GDBN} needs, until you
12373execute a @value{GDBN} command that makes your program resume; at that point,
12374@code{handle_exception} returns control to your own code on the target
5d161b24 12375machine.
104c1213
JM
12376
12377@item breakpoint
12378@cindex @code{breakpoint} subroutine, remote
12379Use this auxiliary subroutine to make your program contain a
12380breakpoint. Depending on the particular situation, this may be the only
12381way for @value{GDBN} to get control. For instance, if your target
12382machine has some sort of interrupt button, you won't need to call this;
12383pressing the interrupt button transfers control to
12384@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
12385simply receiving characters on the serial port may also trigger a trap;
12386again, in that situation, you don't need to call @code{breakpoint} from
12387your own program---simply running @samp{target remote} from the host
5d161b24 12388@value{GDBN} session gets control.
104c1213
JM
12389
12390Call @code{breakpoint} if none of these is true, or if you simply want
12391to make certain your program stops at a predetermined point for the
12392start of your debugging session.
12393@end table
12394
6d2ebf8b 12395@node Bootstrapping
6f05cf9f 12396@subsection What you must do for the stub
104c1213
JM
12397
12398@cindex remote stub, support routines
12399The debugging stubs that come with @value{GDBN} are set up for a particular
12400chip architecture, but they have no information about the rest of your
12401debugging target machine.
12402
12403First of all you need to tell the stub how to communicate with the
12404serial port.
12405
12406@table @code
12407@item int getDebugChar()
4644b6e3 12408@findex getDebugChar
104c1213
JM
12409Write this subroutine to read a single character from the serial port.
12410It may be identical to @code{getchar} for your target system; a
12411different name is used to allow you to distinguish the two if you wish.
12412
12413@item void putDebugChar(int)
4644b6e3 12414@findex putDebugChar
104c1213 12415Write this subroutine to write a single character to the serial port.
5d161b24 12416It may be identical to @code{putchar} for your target system; a
104c1213
JM
12417different name is used to allow you to distinguish the two if you wish.
12418@end table
12419
12420@cindex control C, and remote debugging
12421@cindex interrupting remote targets
12422If you want @value{GDBN} to be able to stop your program while it is
12423running, you need to use an interrupt-driven serial driver, and arrange
12424for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
12425character). That is the character which @value{GDBN} uses to tell the
12426remote system to stop.
12427
12428Getting the debugging target to return the proper status to @value{GDBN}
12429probably requires changes to the standard stub; one quick and dirty way
12430is to just execute a breakpoint instruction (the ``dirty'' part is that
12431@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
12432
12433Other routines you need to supply are:
12434
12435@table @code
12436@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 12437@findex exceptionHandler
104c1213
JM
12438Write this function to install @var{exception_address} in the exception
12439handling tables. You need to do this because the stub does not have any
12440way of knowing what the exception handling tables on your target system
12441are like (for example, the processor's table might be in @sc{rom},
12442containing entries which point to a table in @sc{ram}).
12443@var{exception_number} is the exception number which should be changed;
12444its meaning is architecture-dependent (for example, different numbers
12445might represent divide by zero, misaligned access, etc). When this
12446exception occurs, control should be transferred directly to
12447@var{exception_address}, and the processor state (stack, registers,
12448and so on) should be just as it is when a processor exception occurs. So if
12449you want to use a jump instruction to reach @var{exception_address}, it
12450should be a simple jump, not a jump to subroutine.
12451
12452For the 386, @var{exception_address} should be installed as an interrupt
12453gate so that interrupts are masked while the handler runs. The gate
12454should be at privilege level 0 (the most privileged level). The
12455@sc{sparc} and 68k stubs are able to mask interrupts themselves without
12456help from @code{exceptionHandler}.
12457
12458@item void flush_i_cache()
4644b6e3 12459@findex flush_i_cache
d4f3574e 12460On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
12461instruction cache, if any, on your target machine. If there is no
12462instruction cache, this subroutine may be a no-op.
12463
12464On target machines that have instruction caches, @value{GDBN} requires this
12465function to make certain that the state of your program is stable.
12466@end table
12467
12468@noindent
12469You must also make sure this library routine is available:
12470
12471@table @code
12472@item void *memset(void *, int, int)
4644b6e3 12473@findex memset
104c1213
JM
12474This is the standard library function @code{memset} that sets an area of
12475memory to a known value. If you have one of the free versions of
12476@code{libc.a}, @code{memset} can be found there; otherwise, you must
12477either obtain it from your hardware manufacturer, or write your own.
12478@end table
12479
12480If you do not use the GNU C compiler, you may need other standard
12481library subroutines as well; this varies from one stub to another,
12482but in general the stubs are likely to use any of the common library
d4f3574e 12483subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
12484
12485
6d2ebf8b 12486@node Debug Session
6f05cf9f 12487@subsection Putting it all together
104c1213
JM
12488
12489@cindex remote serial debugging summary
12490In summary, when your program is ready to debug, you must follow these
12491steps.
12492
12493@enumerate
12494@item
6d2ebf8b 12495Make sure you have defined the supporting low-level routines
104c1213
JM
12496(@pxref{Bootstrapping,,What you must do for the stub}):
12497@display
12498@code{getDebugChar}, @code{putDebugChar},
12499@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
12500@end display
12501
12502@item
12503Insert these lines near the top of your program:
12504
474c8240 12505@smallexample
104c1213
JM
12506set_debug_traps();
12507breakpoint();
474c8240 12508@end smallexample
104c1213
JM
12509
12510@item
12511For the 680x0 stub only, you need to provide a variable called
12512@code{exceptionHook}. Normally you just use:
12513
474c8240 12514@smallexample
104c1213 12515void (*exceptionHook)() = 0;
474c8240 12516@end smallexample
104c1213 12517
d4f3574e 12518@noindent
104c1213 12519but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 12520function in your program, that function is called when
104c1213
JM
12521@code{@value{GDBN}} continues after stopping on a trap (for example, bus
12522error). The function indicated by @code{exceptionHook} is called with
12523one parameter: an @code{int} which is the exception number.
12524
12525@item
12526Compile and link together: your program, the @value{GDBN} debugging stub for
12527your target architecture, and the supporting subroutines.
12528
12529@item
12530Make sure you have a serial connection between your target machine and
12531the @value{GDBN} host, and identify the serial port on the host.
12532
12533@item
12534@c The "remote" target now provides a `load' command, so we should
12535@c document that. FIXME.
12536Download your program to your target machine (or get it there by
12537whatever means the manufacturer provides), and start it.
12538
12539@item
07f31aa6
DJ
12540Start @value{GDBN} on the host, and connect to the target
12541(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 12542
104c1213
JM
12543@end enumerate
12544
8e04817f
AC
12545@node Configurations
12546@chapter Configuration-Specific Information
104c1213 12547
8e04817f
AC
12548While nearly all @value{GDBN} commands are available for all native and
12549cross versions of the debugger, there are some exceptions. This chapter
12550describes things that are only available in certain configurations.
104c1213 12551
8e04817f
AC
12552There are three major categories of configurations: native
12553configurations, where the host and target are the same, embedded
12554operating system configurations, which are usually the same for several
12555different processor architectures, and bare embedded processors, which
12556are quite different from each other.
104c1213 12557
8e04817f
AC
12558@menu
12559* Native::
12560* Embedded OS::
12561* Embedded Processors::
12562* Architectures::
12563@end menu
104c1213 12564
8e04817f
AC
12565@node Native
12566@section Native
104c1213 12567
8e04817f
AC
12568This section describes details specific to particular native
12569configurations.
6cf7e474 12570
8e04817f
AC
12571@menu
12572* HP-UX:: HP-UX
7561d450 12573* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
12574* SVR4 Process Information:: SVR4 process information
12575* DJGPP Native:: Features specific to the DJGPP port
78c47bea 12576* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 12577* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 12578* Neutrino:: Features specific to QNX Neutrino
8e04817f 12579@end menu
6cf7e474 12580
8e04817f
AC
12581@node HP-UX
12582@subsection HP-UX
104c1213 12583
8e04817f
AC
12584On HP-UX systems, if you refer to a function or variable name that
12585begins with a dollar sign, @value{GDBN} searches for a user or system
12586name first, before it searches for a convenience variable.
104c1213 12587
9c16f35a 12588
7561d450
MK
12589@node BSD libkvm Interface
12590@subsection BSD libkvm Interface
12591
12592@cindex libkvm
12593@cindex kernel memory image
12594@cindex kernel crash dump
12595
12596BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
12597interface that provides a uniform interface for accessing kernel virtual
12598memory images, including live systems and crash dumps. @value{GDBN}
12599uses this interface to allow you to debug live kernels and kernel crash
12600dumps on many native BSD configurations. This is implemented as a
12601special @code{kvm} debugging target. For debugging a live system, load
12602the currently running kernel into @value{GDBN} and connect to the
12603@code{kvm} target:
12604
12605@smallexample
12606(@value{GDBP}) @b{target kvm}
12607@end smallexample
12608
12609For debugging crash dumps, provide the file name of the crash dump as an
12610argument:
12611
12612@smallexample
12613(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
12614@end smallexample
12615
12616Once connected to the @code{kvm} target, the following commands are
12617available:
12618
12619@table @code
12620@kindex kvm
12621@item kvm pcb
721c2651 12622Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
12623
12624@item kvm proc
12625Set current context from proc address. This command isn't available on
12626modern FreeBSD systems.
12627@end table
12628
8e04817f
AC
12629@node SVR4 Process Information
12630@subsection SVR4 process information
60bf7e09
EZ
12631@cindex /proc
12632@cindex examine process image
12633@cindex process info via @file{/proc}
104c1213 12634
60bf7e09
EZ
12635Many versions of SVR4 and compatible systems provide a facility called
12636@samp{/proc} that can be used to examine the image of a running
12637process using file-system subroutines. If @value{GDBN} is configured
12638for an operating system with this facility, the command @code{info
12639proc} is available to report information about the process running
12640your program, or about any process running on your system. @code{info
12641proc} works only on SVR4 systems that include the @code{procfs} code.
12642This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
12643Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 12644
8e04817f
AC
12645@table @code
12646@kindex info proc
60bf7e09 12647@cindex process ID
8e04817f 12648@item info proc
60bf7e09
EZ
12649@itemx info proc @var{process-id}
12650Summarize available information about any running process. If a
12651process ID is specified by @var{process-id}, display information about
12652that process; otherwise display information about the program being
12653debugged. The summary includes the debugged process ID, the command
12654line used to invoke it, its current working directory, and its
12655executable file's absolute file name.
12656
12657On some systems, @var{process-id} can be of the form
12658@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
12659within a process. If the optional @var{pid} part is missing, it means
12660a thread from the process being debugged (the leading @samp{/} still
12661needs to be present, or else @value{GDBN} will interpret the number as
12662a process ID rather than a thread ID).
6cf7e474 12663
8e04817f 12664@item info proc mappings
60bf7e09
EZ
12665@cindex memory address space mappings
12666Report the memory address space ranges accessible in the program, with
12667information on whether the process has read, write, or execute access
12668rights to each range. On @sc{gnu}/Linux systems, each memory range
12669includes the object file which is mapped to that range, instead of the
12670memory access rights to that range.
12671
12672@item info proc stat
12673@itemx info proc status
12674@cindex process detailed status information
12675These subcommands are specific to @sc{gnu}/Linux systems. They show
12676the process-related information, including the user ID and group ID;
12677how many threads are there in the process; its virtual memory usage;
12678the signals that are pending, blocked, and ignored; its TTY; its
12679consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 12680value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
12681(type @kbd{man 5 proc} from your shell prompt).
12682
12683@item info proc all
12684Show all the information about the process described under all of the
12685above @code{info proc} subcommands.
12686
8e04817f
AC
12687@ignore
12688@comment These sub-options of 'info proc' were not included when
12689@comment procfs.c was re-written. Keep their descriptions around
12690@comment against the day when someone finds the time to put them back in.
12691@kindex info proc times
12692@item info proc times
12693Starting time, user CPU time, and system CPU time for your program and
12694its children.
6cf7e474 12695
8e04817f
AC
12696@kindex info proc id
12697@item info proc id
12698Report on the process IDs related to your program: its own process ID,
12699the ID of its parent, the process group ID, and the session ID.
8e04817f 12700@end ignore
721c2651
EZ
12701
12702@item set procfs-trace
12703@kindex set procfs-trace
12704@cindex @code{procfs} API calls
12705This command enables and disables tracing of @code{procfs} API calls.
12706
12707@item show procfs-trace
12708@kindex show procfs-trace
12709Show the current state of @code{procfs} API call tracing.
12710
12711@item set procfs-file @var{file}
12712@kindex set procfs-file
12713Tell @value{GDBN} to write @code{procfs} API trace to the named
12714@var{file}. @value{GDBN} appends the trace info to the previous
12715contents of the file. The default is to display the trace on the
12716standard output.
12717
12718@item show procfs-file
12719@kindex show procfs-file
12720Show the file to which @code{procfs} API trace is written.
12721
12722@item proc-trace-entry
12723@itemx proc-trace-exit
12724@itemx proc-untrace-entry
12725@itemx proc-untrace-exit
12726@kindex proc-trace-entry
12727@kindex proc-trace-exit
12728@kindex proc-untrace-entry
12729@kindex proc-untrace-exit
12730These commands enable and disable tracing of entries into and exits
12731from the @code{syscall} interface.
12732
12733@item info pidlist
12734@kindex info pidlist
12735@cindex process list, QNX Neutrino
12736For QNX Neutrino only, this command displays the list of all the
12737processes and all the threads within each process.
12738
12739@item info meminfo
12740@kindex info meminfo
12741@cindex mapinfo list, QNX Neutrino
12742For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 12743@end table
104c1213 12744
8e04817f
AC
12745@node DJGPP Native
12746@subsection Features for Debugging @sc{djgpp} Programs
12747@cindex @sc{djgpp} debugging
12748@cindex native @sc{djgpp} debugging
12749@cindex MS-DOS-specific commands
104c1213 12750
514c4d71
EZ
12751@cindex DPMI
12752@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
12753MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
12754that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
12755top of real-mode DOS systems and their emulations.
104c1213 12756
8e04817f
AC
12757@value{GDBN} supports native debugging of @sc{djgpp} programs, and
12758defines a few commands specific to the @sc{djgpp} port. This
12759subsection describes those commands.
104c1213 12760
8e04817f
AC
12761@table @code
12762@kindex info dos
12763@item info dos
12764This is a prefix of @sc{djgpp}-specific commands which print
12765information about the target system and important OS structures.
f1251bdd 12766
8e04817f
AC
12767@kindex sysinfo
12768@cindex MS-DOS system info
12769@cindex free memory information (MS-DOS)
12770@item info dos sysinfo
12771This command displays assorted information about the underlying
12772platform: the CPU type and features, the OS version and flavor, the
12773DPMI version, and the available conventional and DPMI memory.
104c1213 12774
8e04817f
AC
12775@cindex GDT
12776@cindex LDT
12777@cindex IDT
12778@cindex segment descriptor tables
12779@cindex descriptor tables display
12780@item info dos gdt
12781@itemx info dos ldt
12782@itemx info dos idt
12783These 3 commands display entries from, respectively, Global, Local,
12784and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
12785tables are data structures which store a descriptor for each segment
12786that is currently in use. The segment's selector is an index into a
12787descriptor table; the table entry for that index holds the
12788descriptor's base address and limit, and its attributes and access
12789rights.
104c1213 12790
8e04817f
AC
12791A typical @sc{djgpp} program uses 3 segments: a code segment, a data
12792segment (used for both data and the stack), and a DOS segment (which
12793allows access to DOS/BIOS data structures and absolute addresses in
12794conventional memory). However, the DPMI host will usually define
12795additional segments in order to support the DPMI environment.
d4f3574e 12796
8e04817f
AC
12797@cindex garbled pointers
12798These commands allow to display entries from the descriptor tables.
12799Without an argument, all entries from the specified table are
12800displayed. An argument, which should be an integer expression, means
12801display a single entry whose index is given by the argument. For
12802example, here's a convenient way to display information about the
12803debugged program's data segment:
104c1213 12804
8e04817f
AC
12805@smallexample
12806@exdent @code{(@value{GDBP}) info dos ldt $ds}
12807@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
12808@end smallexample
104c1213 12809
8e04817f
AC
12810@noindent
12811This comes in handy when you want to see whether a pointer is outside
12812the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 12813
8e04817f
AC
12814@cindex page tables display (MS-DOS)
12815@item info dos pde
12816@itemx info dos pte
12817These two commands display entries from, respectively, the Page
12818Directory and the Page Tables. Page Directories and Page Tables are
12819data structures which control how virtual memory addresses are mapped
12820into physical addresses. A Page Table includes an entry for every
12821page of memory that is mapped into the program's address space; there
12822may be several Page Tables, each one holding up to 4096 entries. A
12823Page Directory has up to 4096 entries, one each for every Page Table
12824that is currently in use.
104c1213 12825
8e04817f
AC
12826Without an argument, @kbd{info dos pde} displays the entire Page
12827Directory, and @kbd{info dos pte} displays all the entries in all of
12828the Page Tables. An argument, an integer expression, given to the
12829@kbd{info dos pde} command means display only that entry from the Page
12830Directory table. An argument given to the @kbd{info dos pte} command
12831means display entries from a single Page Table, the one pointed to by
12832the specified entry in the Page Directory.
104c1213 12833
8e04817f
AC
12834@cindex direct memory access (DMA) on MS-DOS
12835These commands are useful when your program uses @dfn{DMA} (Direct
12836Memory Access), which needs physical addresses to program the DMA
12837controller.
104c1213 12838
8e04817f 12839These commands are supported only with some DPMI servers.
104c1213 12840
8e04817f
AC
12841@cindex physical address from linear address
12842@item info dos address-pte @var{addr}
12843This command displays the Page Table entry for a specified linear
514c4d71
EZ
12844address. The argument @var{addr} is a linear address which should
12845already have the appropriate segment's base address added to it,
12846because this command accepts addresses which may belong to @emph{any}
12847segment. For example, here's how to display the Page Table entry for
12848the page where a variable @code{i} is stored:
104c1213 12849
b383017d 12850@smallexample
8e04817f
AC
12851@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
12852@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 12853@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 12854@end smallexample
104c1213 12855
8e04817f
AC
12856@noindent
12857This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 12858whose physical base address is @code{0x02698000}, and shows all the
8e04817f 12859attributes of that page.
104c1213 12860
8e04817f
AC
12861Note that you must cast the addresses of variables to a @code{char *},
12862since otherwise the value of @code{__djgpp_base_address}, the base
12863address of all variables and functions in a @sc{djgpp} program, will
12864be added using the rules of C pointer arithmetics: if @code{i} is
12865declared an @code{int}, @value{GDBN} will add 4 times the value of
12866@code{__djgpp_base_address} to the address of @code{i}.
104c1213 12867
8e04817f
AC
12868Here's another example, it displays the Page Table entry for the
12869transfer buffer:
104c1213 12870
8e04817f
AC
12871@smallexample
12872@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
12873@exdent @code{Page Table entry for address 0x29110:}
12874@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
12875@end smallexample
104c1213 12876
8e04817f
AC
12877@noindent
12878(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
128793rd member of the @code{_go32_info_block} structure.) The output
12880clearly shows that this DPMI server maps the addresses in conventional
12881memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
12882linear (@code{0x29110}) addresses are identical.
104c1213 12883
8e04817f
AC
12884This command is supported only with some DPMI servers.
12885@end table
104c1213 12886
c45da7e6 12887@cindex DOS serial data link, remote debugging
a8f24a35
EZ
12888In addition to native debugging, the DJGPP port supports remote
12889debugging via a serial data link. The following commands are specific
12890to remote serial debugging in the DJGPP port of @value{GDBN}.
12891
12892@table @code
12893@kindex set com1base
12894@kindex set com1irq
12895@kindex set com2base
12896@kindex set com2irq
12897@kindex set com3base
12898@kindex set com3irq
12899@kindex set com4base
12900@kindex set com4irq
12901@item set com1base @var{addr}
12902This command sets the base I/O port address of the @file{COM1} serial
12903port.
12904
12905@item set com1irq @var{irq}
12906This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
12907for the @file{COM1} serial port.
12908
12909There are similar commands @samp{set com2base}, @samp{set com3irq},
12910etc.@: for setting the port address and the @code{IRQ} lines for the
12911other 3 COM ports.
12912
12913@kindex show com1base
12914@kindex show com1irq
12915@kindex show com2base
12916@kindex show com2irq
12917@kindex show com3base
12918@kindex show com3irq
12919@kindex show com4base
12920@kindex show com4irq
12921The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
12922display the current settings of the base address and the @code{IRQ}
12923lines used by the COM ports.
c45da7e6
EZ
12924
12925@item info serial
12926@kindex info serial
12927@cindex DOS serial port status
12928This command prints the status of the 4 DOS serial ports. For each
12929port, it prints whether it's active or not, its I/O base address and
12930IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
12931counts of various errors encountered so far.
a8f24a35
EZ
12932@end table
12933
12934
78c47bea
PM
12935@node Cygwin Native
12936@subsection Features for Debugging MS Windows PE executables
12937@cindex MS Windows debugging
12938@cindex native Cygwin debugging
12939@cindex Cygwin-specific commands
12940
be448670
CF
12941@value{GDBN} supports native debugging of MS Windows programs, including
12942DLLs with and without symbolic debugging information. There are various
12943additional Cygwin-specific commands, described in this subsection. The
12944subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
12945that have no debugging symbols.
12946
78c47bea
PM
12947
12948@table @code
12949@kindex info w32
12950@item info w32
12951This is a prefix of MS Windows specific commands which print
12952information about the target system and important OS structures.
12953
12954@item info w32 selector
12955This command displays information returned by
12956the Win32 API @code{GetThreadSelectorEntry} function.
12957It takes an optional argument that is evaluated to
12958a long value to give the information about this given selector.
12959Without argument, this command displays information
12960about the the six segment registers.
12961
12962@kindex info dll
12963@item info dll
12964This is a Cygwin specific alias of info shared.
12965
12966@kindex dll-symbols
12967@item dll-symbols
12968This command loads symbols from a dll similarly to
12969add-sym command but without the need to specify a base address.
12970
b383017d 12971@kindex set new-console
78c47bea 12972@item set new-console @var{mode}
b383017d 12973If @var{mode} is @code{on} the debuggee will
78c47bea
PM
12974be started in a new console on next start.
12975If @var{mode} is @code{off}i, the debuggee will
12976be started in the same console as the debugger.
12977
12978@kindex show new-console
12979@item show new-console
12980Displays whether a new console is used
12981when the debuggee is started.
12982
12983@kindex set new-group
12984@item set new-group @var{mode}
12985This boolean value controls whether the debuggee should
12986start a new group or stay in the same group as the debugger.
12987This affects the way the Windows OS handles
12988Ctrl-C.
12989
12990@kindex show new-group
12991@item show new-group
12992Displays current value of new-group boolean.
12993
12994@kindex set debugevents
12995@item set debugevents
12996This boolean value adds debug output concerning events seen by the debugger.
12997
12998@kindex set debugexec
12999@item set debugexec
b383017d 13000This boolean value adds debug output concerning execute events
78c47bea
PM
13001seen by the debugger.
13002
13003@kindex set debugexceptions
13004@item set debugexceptions
b383017d 13005This boolean value adds debug ouptut concerning exception events
78c47bea
PM
13006seen by the debugger.
13007
13008@kindex set debugmemory
13009@item set debugmemory
b383017d 13010This boolean value adds debug ouptut concerning memory events
78c47bea
PM
13011seen by the debugger.
13012
13013@kindex set shell
13014@item set shell
13015This boolean values specifies whether the debuggee is called
13016via a shell or directly (default value is on).
13017
13018@kindex show shell
13019@item show shell
13020Displays if the debuggee will be started with a shell.
13021
13022@end table
13023
be448670
CF
13024@menu
13025* Non-debug DLL symbols:: Support for DLLs without debugging symbols
13026@end menu
13027
13028@node Non-debug DLL symbols
13029@subsubsection Support for DLLs without debugging symbols
13030@cindex DLLs with no debugging symbols
13031@cindex Minimal symbols and DLLs
13032
13033Very often on windows, some of the DLLs that your program relies on do
13034not include symbolic debugging information (for example,
13035@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
13036symbols in a DLL, it relies on the minimal amount of symbolic
13037information contained in the DLL's export table. This subsubsection
13038describes working with such symbols, known internally to @value{GDBN} as
13039``minimal symbols''.
13040
13041Note that before the debugged program has started execution, no DLLs
13042will have been loaded. The easiest way around this problem is simply to
13043start the program --- either by setting a breakpoint or letting the
13044program run once to completion. It is also possible to force
13045@value{GDBN} to load a particular DLL before starting the executable ---
13046see the shared library information in @pxref{Files} or the
13047@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
13048explicitly loading symbols from a DLL with no debugging information will
13049cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
13050which may adversely affect symbol lookup performance.
13051
13052@subsubsection DLL name prefixes
13053
13054In keeping with the naming conventions used by the Microsoft debugging
13055tools, DLL export symbols are made available with a prefix based on the
13056DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
13057also entered into the symbol table, so @code{CreateFileA} is often
13058sufficient. In some cases there will be name clashes within a program
13059(particularly if the executable itself includes full debugging symbols)
13060necessitating the use of the fully qualified name when referring to the
13061contents of the DLL. Use single-quotes around the name to avoid the
13062exclamation mark (``!'') being interpreted as a language operator.
13063
13064Note that the internal name of the DLL may be all upper-case, even
13065though the file name of the DLL is lower-case, or vice-versa. Since
13066symbols within @value{GDBN} are @emph{case-sensitive} this may cause
13067some confusion. If in doubt, try the @code{info functions} and
13068@code{info variables} commands or even @code{maint print msymbols} (see
13069@pxref{Symbols}). Here's an example:
13070
13071@smallexample
f7dc1244 13072(@value{GDBP}) info function CreateFileA
be448670
CF
13073All functions matching regular expression "CreateFileA":
13074
13075Non-debugging symbols:
130760x77e885f4 CreateFileA
130770x77e885f4 KERNEL32!CreateFileA
13078@end smallexample
13079
13080@smallexample
f7dc1244 13081(@value{GDBP}) info function !
be448670
CF
13082All functions matching regular expression "!":
13083
13084Non-debugging symbols:
130850x6100114c cygwin1!__assert
130860x61004034 cygwin1!_dll_crt0@@0
130870x61004240 cygwin1!dll_crt0(per_process *)
13088[etc...]
13089@end smallexample
13090
13091@subsubsection Working with minimal symbols
13092
13093Symbols extracted from a DLL's export table do not contain very much
13094type information. All that @value{GDBN} can do is guess whether a symbol
13095refers to a function or variable depending on the linker section that
13096contains the symbol. Also note that the actual contents of the memory
13097contained in a DLL are not available unless the program is running. This
13098means that you cannot examine the contents of a variable or disassemble
13099a function within a DLL without a running program.
13100
13101Variables are generally treated as pointers and dereferenced
13102automatically. For this reason, it is often necessary to prefix a
13103variable name with the address-of operator (``&'') and provide explicit
13104type information in the command. Here's an example of the type of
13105problem:
13106
13107@smallexample
f7dc1244 13108(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
13109$1 = 268572168
13110@end smallexample
13111
13112@smallexample
f7dc1244 13113(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
131140x10021610: "\230y\""
13115@end smallexample
13116
13117And two possible solutions:
13118
13119@smallexample
f7dc1244 13120(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
13121$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
13122@end smallexample
13123
13124@smallexample
f7dc1244 13125(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 131260x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 13127(@value{GDBP}) x/x 0x10021608
be448670 131280x10021608: 0x0022fd98
f7dc1244 13129(@value{GDBP}) x/s 0x0022fd98
be448670
CF
131300x22fd98: "/cygdrive/c/mydirectory/myprogram"
13131@end smallexample
13132
13133Setting a break point within a DLL is possible even before the program
13134starts execution. However, under these circumstances, @value{GDBN} can't
13135examine the initial instructions of the function in order to skip the
13136function's frame set-up code. You can work around this by using ``*&''
13137to set the breakpoint at a raw memory address:
13138
13139@smallexample
f7dc1244 13140(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
13141Breakpoint 1 at 0x1e04eff0
13142@end smallexample
13143
13144The author of these extensions is not entirely convinced that setting a
13145break point within a shared DLL like @file{kernel32.dll} is completely
13146safe.
13147
14d6dd68
EZ
13148@node Hurd Native
13149@subsection Commands specific to @sc{gnu} Hurd systems
13150@cindex @sc{gnu} Hurd debugging
13151
13152This subsection describes @value{GDBN} commands specific to the
13153@sc{gnu} Hurd native debugging.
13154
13155@table @code
13156@item set signals
13157@itemx set sigs
13158@kindex set signals@r{, Hurd command}
13159@kindex set sigs@r{, Hurd command}
13160This command toggles the state of inferior signal interception by
13161@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
13162affected by this command. @code{sigs} is a shorthand alias for
13163@code{signals}.
13164
13165@item show signals
13166@itemx show sigs
13167@kindex show signals@r{, Hurd command}
13168@kindex show sigs@r{, Hurd command}
13169Show the current state of intercepting inferior's signals.
13170
13171@item set signal-thread
13172@itemx set sigthread
13173@kindex set signal-thread
13174@kindex set sigthread
13175This command tells @value{GDBN} which thread is the @code{libc} signal
13176thread. That thread is run when a signal is delivered to a running
13177process. @code{set sigthread} is the shorthand alias of @code{set
13178signal-thread}.
13179
13180@item show signal-thread
13181@itemx show sigthread
13182@kindex show signal-thread
13183@kindex show sigthread
13184These two commands show which thread will run when the inferior is
13185delivered a signal.
13186
13187@item set stopped
13188@kindex set stopped@r{, Hurd command}
13189This commands tells @value{GDBN} that the inferior process is stopped,
13190as with the @code{SIGSTOP} signal. The stopped process can be
13191continued by delivering a signal to it.
13192
13193@item show stopped
13194@kindex show stopped@r{, Hurd command}
13195This command shows whether @value{GDBN} thinks the debuggee is
13196stopped.
13197
13198@item set exceptions
13199@kindex set exceptions@r{, Hurd command}
13200Use this command to turn off trapping of exceptions in the inferior.
13201When exception trapping is off, neither breakpoints nor
13202single-stepping will work. To restore the default, set exception
13203trapping on.
13204
13205@item show exceptions
13206@kindex show exceptions@r{, Hurd command}
13207Show the current state of trapping exceptions in the inferior.
13208
13209@item set task pause
13210@kindex set task@r{, Hurd commands}
13211@cindex task attributes (@sc{gnu} Hurd)
13212@cindex pause current task (@sc{gnu} Hurd)
13213This command toggles task suspension when @value{GDBN} has control.
13214Setting it to on takes effect immediately, and the task is suspended
13215whenever @value{GDBN} gets control. Setting it to off will take
13216effect the next time the inferior is continued. If this option is set
13217to off, you can use @code{set thread default pause on} or @code{set
13218thread pause on} (see below) to pause individual threads.
13219
13220@item show task pause
13221@kindex show task@r{, Hurd commands}
13222Show the current state of task suspension.
13223
13224@item set task detach-suspend-count
13225@cindex task suspend count
13226@cindex detach from task, @sc{gnu} Hurd
13227This command sets the suspend count the task will be left with when
13228@value{GDBN} detaches from it.
13229
13230@item show task detach-suspend-count
13231Show the suspend count the task will be left with when detaching.
13232
13233@item set task exception-port
13234@itemx set task excp
13235@cindex task exception port, @sc{gnu} Hurd
13236This command sets the task exception port to which @value{GDBN} will
13237forward exceptions. The argument should be the value of the @dfn{send
13238rights} of the task. @code{set task excp} is a shorthand alias.
13239
13240@item set noninvasive
13241@cindex noninvasive task options
13242This command switches @value{GDBN} to a mode that is the least
13243invasive as far as interfering with the inferior is concerned. This
13244is the same as using @code{set task pause}, @code{set exceptions}, and
13245@code{set signals} to values opposite to the defaults.
13246
13247@item info send-rights
13248@itemx info receive-rights
13249@itemx info port-rights
13250@itemx info port-sets
13251@itemx info dead-names
13252@itemx info ports
13253@itemx info psets
13254@cindex send rights, @sc{gnu} Hurd
13255@cindex receive rights, @sc{gnu} Hurd
13256@cindex port rights, @sc{gnu} Hurd
13257@cindex port sets, @sc{gnu} Hurd
13258@cindex dead names, @sc{gnu} Hurd
13259These commands display information about, respectively, send rights,
13260receive rights, port rights, port sets, and dead names of a task.
13261There are also shorthand aliases: @code{info ports} for @code{info
13262port-rights} and @code{info psets} for @code{info port-sets}.
13263
13264@item set thread pause
13265@kindex set thread@r{, Hurd command}
13266@cindex thread properties, @sc{gnu} Hurd
13267@cindex pause current thread (@sc{gnu} Hurd)
13268This command toggles current thread suspension when @value{GDBN} has
13269control. Setting it to on takes effect immediately, and the current
13270thread is suspended whenever @value{GDBN} gets control. Setting it to
13271off will take effect the next time the inferior is continued.
13272Normally, this command has no effect, since when @value{GDBN} has
13273control, the whole task is suspended. However, if you used @code{set
13274task pause off} (see above), this command comes in handy to suspend
13275only the current thread.
13276
13277@item show thread pause
13278@kindex show thread@r{, Hurd command}
13279This command shows the state of current thread suspension.
13280
13281@item set thread run
13282This comamnd sets whether the current thread is allowed to run.
13283
13284@item show thread run
13285Show whether the current thread is allowed to run.
13286
13287@item set thread detach-suspend-count
13288@cindex thread suspend count, @sc{gnu} Hurd
13289@cindex detach from thread, @sc{gnu} Hurd
13290This command sets the suspend count @value{GDBN} will leave on a
13291thread when detaching. This number is relative to the suspend count
13292found by @value{GDBN} when it notices the thread; use @code{set thread
13293takeover-suspend-count} to force it to an absolute value.
13294
13295@item show thread detach-suspend-count
13296Show the suspend count @value{GDBN} will leave on the thread when
13297detaching.
13298
13299@item set thread exception-port
13300@itemx set thread excp
13301Set the thread exception port to which to forward exceptions. This
13302overrides the port set by @code{set task exception-port} (see above).
13303@code{set thread excp} is the shorthand alias.
13304
13305@item set thread takeover-suspend-count
13306Normally, @value{GDBN}'s thread suspend counts are relative to the
13307value @value{GDBN} finds when it notices each thread. This command
13308changes the suspend counts to be absolute instead.
13309
13310@item set thread default
13311@itemx show thread default
13312@cindex thread default settings, @sc{gnu} Hurd
13313Each of the above @code{set thread} commands has a @code{set thread
13314default} counterpart (e.g., @code{set thread default pause}, @code{set
13315thread default exception-port}, etc.). The @code{thread default}
13316variety of commands sets the default thread properties for all
13317threads; you can then change the properties of individual threads with
13318the non-default commands.
13319@end table
13320
13321
a64548ea
EZ
13322@node Neutrino
13323@subsection QNX Neutrino
13324@cindex QNX Neutrino
13325
13326@value{GDBN} provides the following commands specific to the QNX
13327Neutrino target:
13328
13329@table @code
13330@item set debug nto-debug
13331@kindex set debug nto-debug
13332When set to on, enables debugging messages specific to the QNX
13333Neutrino support.
13334
13335@item show debug nto-debug
13336@kindex show debug nto-debug
13337Show the current state of QNX Neutrino messages.
13338@end table
13339
13340
8e04817f
AC
13341@node Embedded OS
13342@section Embedded Operating Systems
104c1213 13343
8e04817f
AC
13344This section describes configurations involving the debugging of
13345embedded operating systems that are available for several different
13346architectures.
d4f3574e 13347
8e04817f
AC
13348@menu
13349* VxWorks:: Using @value{GDBN} with VxWorks
13350@end menu
104c1213 13351
8e04817f
AC
13352@value{GDBN} includes the ability to debug programs running on
13353various real-time operating systems.
104c1213 13354
8e04817f
AC
13355@node VxWorks
13356@subsection Using @value{GDBN} with VxWorks
104c1213 13357
8e04817f 13358@cindex VxWorks
104c1213 13359
8e04817f 13360@table @code
104c1213 13361
8e04817f
AC
13362@kindex target vxworks
13363@item target vxworks @var{machinename}
13364A VxWorks system, attached via TCP/IP. The argument @var{machinename}
13365is the target system's machine name or IP address.
104c1213 13366
8e04817f 13367@end table
104c1213 13368
8e04817f
AC
13369On VxWorks, @code{load} links @var{filename} dynamically on the
13370current target system as well as adding its symbols in @value{GDBN}.
104c1213 13371
8e04817f
AC
13372@value{GDBN} enables developers to spawn and debug tasks running on networked
13373VxWorks targets from a Unix host. Already-running tasks spawned from
13374the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
13375both the Unix host and on the VxWorks target. The program
13376@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
13377installed with the name @code{vxgdb}, to distinguish it from a
13378@value{GDBN} for debugging programs on the host itself.)
104c1213 13379
8e04817f
AC
13380@table @code
13381@item VxWorks-timeout @var{args}
13382@kindex vxworks-timeout
13383All VxWorks-based targets now support the option @code{vxworks-timeout}.
13384This option is set by the user, and @var{args} represents the number of
13385seconds @value{GDBN} waits for responses to rpc's. You might use this if
13386your VxWorks target is a slow software simulator or is on the far side
13387of a thin network line.
13388@end table
104c1213 13389
8e04817f
AC
13390The following information on connecting to VxWorks was current when
13391this manual was produced; newer releases of VxWorks may use revised
13392procedures.
104c1213 13393
4644b6e3 13394@findex INCLUDE_RDB
8e04817f
AC
13395To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
13396to include the remote debugging interface routines in the VxWorks
13397library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
13398VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
13399kernel. The resulting kernel contains @file{rdb.a}, and spawns the
13400source debugging task @code{tRdbTask} when VxWorks is booted. For more
13401information on configuring and remaking VxWorks, see the manufacturer's
13402manual.
13403@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 13404
8e04817f
AC
13405Once you have included @file{rdb.a} in your VxWorks system image and set
13406your Unix execution search path to find @value{GDBN}, you are ready to
13407run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
13408@code{vxgdb}, depending on your installation).
104c1213 13409
8e04817f 13410@value{GDBN} comes up showing the prompt:
104c1213 13411
474c8240 13412@smallexample
8e04817f 13413(vxgdb)
474c8240 13414@end smallexample
104c1213 13415
8e04817f
AC
13416@menu
13417* VxWorks Connection:: Connecting to VxWorks
13418* VxWorks Download:: VxWorks download
13419* VxWorks Attach:: Running tasks
13420@end menu
104c1213 13421
8e04817f
AC
13422@node VxWorks Connection
13423@subsubsection Connecting to VxWorks
104c1213 13424
8e04817f
AC
13425The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
13426network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 13427
474c8240 13428@smallexample
8e04817f 13429(vxgdb) target vxworks tt
474c8240 13430@end smallexample
104c1213 13431
8e04817f
AC
13432@need 750
13433@value{GDBN} displays messages like these:
104c1213 13434
8e04817f
AC
13435@smallexample
13436Attaching remote machine across net...
13437Connected to tt.
13438@end smallexample
104c1213 13439
8e04817f
AC
13440@need 1000
13441@value{GDBN} then attempts to read the symbol tables of any object modules
13442loaded into the VxWorks target since it was last booted. @value{GDBN} locates
13443these files by searching the directories listed in the command search
13444path (@pxref{Environment, ,Your program's environment}); if it fails
13445to find an object file, it displays a message such as:
5d161b24 13446
474c8240 13447@smallexample
8e04817f 13448prog.o: No such file or directory.
474c8240 13449@end smallexample
104c1213 13450
8e04817f
AC
13451When this happens, add the appropriate directory to the search path with
13452the @value{GDBN} command @code{path}, and execute the @code{target}
13453command again.
104c1213 13454
8e04817f
AC
13455@node VxWorks Download
13456@subsubsection VxWorks download
104c1213 13457
8e04817f
AC
13458@cindex download to VxWorks
13459If you have connected to the VxWorks target and you want to debug an
13460object that has not yet been loaded, you can use the @value{GDBN}
13461@code{load} command to download a file from Unix to VxWorks
13462incrementally. The object file given as an argument to the @code{load}
13463command is actually opened twice: first by the VxWorks target in order
13464to download the code, then by @value{GDBN} in order to read the symbol
13465table. This can lead to problems if the current working directories on
13466the two systems differ. If both systems have NFS mounted the same
13467filesystems, you can avoid these problems by using absolute paths.
13468Otherwise, it is simplest to set the working directory on both systems
13469to the directory in which the object file resides, and then to reference
13470the file by its name, without any path. For instance, a program
13471@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
13472and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
13473program, type this on VxWorks:
104c1213 13474
474c8240 13475@smallexample
8e04817f 13476-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 13477@end smallexample
104c1213 13478
8e04817f
AC
13479@noindent
13480Then, in @value{GDBN}, type:
104c1213 13481
474c8240 13482@smallexample
8e04817f
AC
13483(vxgdb) cd @var{hostpath}/vw/demo/rdb
13484(vxgdb) load prog.o
474c8240 13485@end smallexample
104c1213 13486
8e04817f 13487@value{GDBN} displays a response similar to this:
104c1213 13488
8e04817f
AC
13489@smallexample
13490Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
13491@end smallexample
104c1213 13492
8e04817f
AC
13493You can also use the @code{load} command to reload an object module
13494after editing and recompiling the corresponding source file. Note that
13495this makes @value{GDBN} delete all currently-defined breakpoints,
13496auto-displays, and convenience variables, and to clear the value
13497history. (This is necessary in order to preserve the integrity of
13498debugger's data structures that reference the target system's symbol
13499table.)
104c1213 13500
8e04817f
AC
13501@node VxWorks Attach
13502@subsubsection Running tasks
104c1213
JM
13503
13504@cindex running VxWorks tasks
13505You can also attach to an existing task using the @code{attach} command as
13506follows:
13507
474c8240 13508@smallexample
104c1213 13509(vxgdb) attach @var{task}
474c8240 13510@end smallexample
104c1213
JM
13511
13512@noindent
13513where @var{task} is the VxWorks hexadecimal task ID. The task can be running
13514or suspended when you attach to it. Running tasks are suspended at
13515the time of attachment.
13516
6d2ebf8b 13517@node Embedded Processors
104c1213
JM
13518@section Embedded Processors
13519
13520This section goes into details specific to particular embedded
13521configurations.
13522
c45da7e6
EZ
13523@cindex send command to simulator
13524Whenever a specific embedded processor has a simulator, @value{GDBN}
13525allows to send an arbitrary command to the simulator.
13526
13527@table @code
13528@item sim @var{command}
13529@kindex sim@r{, a command}
13530Send an arbitrary @var{command} string to the simulator. Consult the
13531documentation for the specific simulator in use for information about
13532acceptable commands.
13533@end table
13534
7d86b5d5 13535
104c1213 13536@menu
c45da7e6 13537* ARM:: ARM RDI
172c2a43
KI
13538* H8/300:: Renesas H8/300
13539* H8/500:: Renesas H8/500
13540* M32R/D:: Renesas M32R/D
104c1213 13541* M68K:: Motorola M68K
104c1213 13542* MIPS Embedded:: MIPS Embedded
a37295f9 13543* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
13544* PA:: HP PA Embedded
13545* PowerPC: PowerPC
172c2a43 13546* SH:: Renesas SH
104c1213
JM
13547* Sparclet:: Tsqware Sparclet
13548* Sparclite:: Fujitsu Sparclite
13549* ST2000:: Tandem ST2000
13550* Z8000:: Zilog Z8000
a64548ea
EZ
13551* AVR:: Atmel AVR
13552* CRIS:: CRIS
13553* Super-H:: Renesas Super-H
c45da7e6 13554* WinCE:: Windows CE child processes
104c1213
JM
13555@end menu
13556
6d2ebf8b 13557@node ARM
104c1213 13558@subsection ARM
c45da7e6 13559@cindex ARM RDI
104c1213
JM
13560
13561@table @code
8e04817f
AC
13562@kindex target rdi
13563@item target rdi @var{dev}
13564ARM Angel monitor, via RDI library interface to ADP protocol. You may
13565use this target to communicate with both boards running the Angel
13566monitor, or with the EmbeddedICE JTAG debug device.
13567
13568@kindex target rdp
13569@item target rdp @var{dev}
13570ARM Demon monitor.
13571
13572@end table
13573
e2f4edfd
EZ
13574@value{GDBN} provides the following ARM-specific commands:
13575
13576@table @code
13577@item set arm disassembler
13578@kindex set arm
13579This commands selects from a list of disassembly styles. The
13580@code{"std"} style is the standard style.
13581
13582@item show arm disassembler
13583@kindex show arm
13584Show the current disassembly style.
13585
13586@item set arm apcs32
13587@cindex ARM 32-bit mode
13588This command toggles ARM operation mode between 32-bit and 26-bit.
13589
13590@item show arm apcs32
13591Display the current usage of the ARM 32-bit mode.
13592
13593@item set arm fpu @var{fputype}
13594This command sets the ARM floating-point unit (FPU) type. The
13595argument @var{fputype} can be one of these:
13596
13597@table @code
13598@item auto
13599Determine the FPU type by querying the OS ABI.
13600@item softfpa
13601Software FPU, with mixed-endian doubles on little-endian ARM
13602processors.
13603@item fpa
13604GCC-compiled FPA co-processor.
13605@item softvfp
13606Software FPU with pure-endian doubles.
13607@item vfp
13608VFP co-processor.
13609@end table
13610
13611@item show arm fpu
13612Show the current type of the FPU.
13613
13614@item set arm abi
13615This command forces @value{GDBN} to use the specified ABI.
13616
13617@item show arm abi
13618Show the currently used ABI.
13619
13620@item set debug arm
13621Toggle whether to display ARM-specific debugging messages from the ARM
13622target support subsystem.
13623
13624@item show debug arm
13625Show whether ARM-specific debugging messages are enabled.
13626@end table
13627
c45da7e6
EZ
13628The following commands are available when an ARM target is debugged
13629using the RDI interface:
13630
13631@table @code
13632@item rdilogfile @r{[}@var{file}@r{]}
13633@kindex rdilogfile
13634@cindex ADP (Angel Debugger Protocol) logging
13635Set the filename for the ADP (Angel Debugger Protocol) packet log.
13636With an argument, sets the log file to the specified @var{file}. With
13637no argument, show the current log file name. The default log file is
13638@file{rdi.log}.
13639
13640@item rdilogenable @r{[}@var{arg}@r{]}
13641@kindex rdilogenable
13642Control logging of ADP packets. With an argument of 1 or @code{"yes"}
13643enables logging, with an argument 0 or @code{"no"} disables it. With
13644no arguments displays the current setting. When logging is enabled,
13645ADP packets exchanged between @value{GDBN} and the RDI target device
13646are logged to a file.
13647
13648@item set rdiromatzero
13649@kindex set rdiromatzero
13650@cindex ROM at zero address, RDI
13651Tell @value{GDBN} whether the target has ROM at address 0. If on,
13652vector catching is disabled, so that zero address can be used. If off
13653(the default), vector catching is enabled. For this command to take
13654effect, it needs to be invoked prior to the @code{target rdi} command.
13655
13656@item show rdiromatzero
13657@kindex show rdiromatzero
13658Show the current setting of ROM at zero address.
13659
13660@item set rdiheartbeat
13661@kindex set rdiheartbeat
13662@cindex RDI heartbeat
13663Enable or disable RDI heartbeat packets. It is not recommended to
13664turn on this option, since it confuses ARM and EPI JTAG interface, as
13665well as the Angel monitor.
13666
13667@item show rdiheartbeat
13668@kindex show rdiheartbeat
13669Show the setting of RDI heartbeat packets.
13670@end table
13671
e2f4edfd 13672
8e04817f 13673@node H8/300
172c2a43 13674@subsection Renesas H8/300
8e04817f
AC
13675
13676@table @code
13677
13678@kindex target hms@r{, with H8/300}
13679@item target hms @var{dev}
172c2a43 13680A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
13681Use special commands @code{device} and @code{speed} to control the serial
13682line and the communications speed used.
13683
13684@kindex target e7000@r{, with H8/300}
13685@item target e7000 @var{dev}
172c2a43 13686E7000 emulator for Renesas H8 and SH.
8e04817f
AC
13687
13688@kindex target sh3@r{, with H8/300}
13689@kindex target sh3e@r{, with H8/300}
13690@item target sh3 @var{dev}
13691@itemx target sh3e @var{dev}
172c2a43 13692Renesas SH-3 and SH-3E target systems.
8e04817f
AC
13693
13694@end table
13695
13696@cindex download to H8/300 or H8/500
13697@cindex H8/300 or H8/500 download
172c2a43
KI
13698@cindex download to Renesas SH
13699@cindex Renesas SH download
13700When you select remote debugging to a Renesas SH, H8/300, or H8/500
13701board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
13702board and also opens it as the current executable target for
13703@value{GDBN} on your host (like the @code{file} command).
13704
13705@value{GDBN} needs to know these things to talk to your
172c2a43 13706Renesas SH, H8/300, or H8/500:
8e04817f
AC
13707
13708@enumerate
13709@item
13710that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
13711for Renesas microprocessors, or @samp{target e7000}, the in-circuit
13712emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
13713the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
13714H8/300, or H8/500.)
13715
13716@item
172c2a43 13717what serial device connects your host to your Renesas board (the first
8e04817f
AC
13718serial device available on your host is the default).
13719
13720@item
13721what speed to use over the serial device.
13722@end enumerate
13723
13724@menu
172c2a43
KI
13725* Renesas Boards:: Connecting to Renesas boards.
13726* Renesas ICE:: Using the E7000 In-Circuit Emulator.
13727* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
13728@end menu
13729
172c2a43
KI
13730@node Renesas Boards
13731@subsubsection Connecting to Renesas boards
8e04817f
AC
13732
13733@c only for Unix hosts
13734@kindex device
172c2a43 13735@cindex serial device, Renesas micros
8e04817f
AC
13736Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
13737need to explicitly set the serial device. The default @var{port} is the
13738first available port on your host. This is only necessary on Unix
13739hosts, where it is typically something like @file{/dev/ttya}.
13740
13741@kindex speed
172c2a43 13742@cindex serial line speed, Renesas micros
8e04817f
AC
13743@code{@value{GDBN}} has another special command to set the communications
13744speed: @samp{speed @var{bps}}. This command also is only used from Unix
13745hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
13746the DOS @code{mode} command (for instance,
13747@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
13748
13749The @samp{device} and @samp{speed} commands are available only when you
172c2a43 13750use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
13751use a DOS host,
13752@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
13753called @code{asynctsr} to communicate with the development board
13754through a PC serial port. You must also use the DOS @code{mode} command
13755to set up the serial port on the DOS side.
13756
13757The following sample session illustrates the steps needed to start a
13758program under @value{GDBN} control on an H8/300. The example uses a
13759sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 13760the Renesas SH and the H8/500.
8e04817f
AC
13761
13762First hook up your development board. In this example, we use a
13763board attached to serial port @code{COM2}; if you use a different serial
13764port, substitute its name in the argument of the @code{mode} command.
13765When you call @code{asynctsr}, the auxiliary comms program used by the
13766debugger, you give it just the numeric part of the serial port's name;
13767for example, @samp{asyncstr 2} below runs @code{asyncstr} on
13768@code{COM2}.
13769
474c8240 13770@smallexample
8e04817f
AC
13771C:\H8300\TEST> asynctsr 2
13772C:\H8300\TEST> mode com2:9600,n,8,1,p
13773
13774Resident portion of MODE loaded
13775
13776COM2: 9600, n, 8, 1, p
13777
474c8240 13778@end smallexample
8e04817f
AC
13779
13780@quotation
13781@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
13782@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
13783disable it, or even boot without it, to use @code{asynctsr} to control
13784your development board.
13785@end quotation
13786
13787@kindex target hms@r{, and serial protocol}
13788Now that serial communications are set up, and the development board is
9c16f35a 13789connected, you can start up @value{GDBN}. Call @code{@value{GDBN}} with
8e04817f
AC
13790the name of your program as the argument. @code{@value{GDBN}} prompts
13791you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
13792commands to begin your debugging session: @samp{target hms} to specify
172c2a43 13793cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
13794download your program to the board. @code{load} displays the names of
13795the program's sections, and a @samp{*} for each 2K of data downloaded.
13796(If you want to refresh @value{GDBN} data on symbols or on the
13797executable file without downloading, use the @value{GDBN} commands
13798@code{file} or @code{symbol-file}. These commands, and @code{load}
13799itself, are described in @ref{Files,,Commands to specify files}.)
13800
13801@smallexample
13802(eg-C:\H8300\TEST) @value{GDBP} t.x
13803@value{GDBN} is free software and you are welcome to distribute copies
13804 of it under certain conditions; type "show copying" to see
13805 the conditions.
13806There is absolutely no warranty for @value{GDBN}; type "show warranty"
13807for details.
13808@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
13809(@value{GDBP}) target hms
13810Connected to remote H8/300 HMS system.
13811(@value{GDBP}) load t.x
13812.text : 0x8000 .. 0xabde ***********
13813.data : 0xabde .. 0xad30 *
13814.stack : 0xf000 .. 0xf014 *
13815@end smallexample
13816
13817At this point, you're ready to run or debug your program. From here on,
13818you can use all the usual @value{GDBN} commands. The @code{break} command
13819sets breakpoints; the @code{run} command starts your program;
13820@code{print} or @code{x} display data; the @code{continue} command
13821resumes execution after stopping at a breakpoint. You can use the
13822@code{help} command at any time to find out more about @value{GDBN} commands.
13823
13824Remember, however, that @emph{operating system} facilities aren't
13825available on your development board; for example, if your program hangs,
13826you can't send an interrupt---but you can press the @sc{reset} switch!
13827
13828Use the @sc{reset} button on the development board
13829@itemize @bullet
13830@item
13831to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
13832no way to pass an interrupt signal to the development board); and
13833
13834@item
13835to return to the @value{GDBN} command prompt after your program finishes
13836normally. The communications protocol provides no other way for @value{GDBN}
13837to detect program completion.
13838@end itemize
13839
13840In either case, @value{GDBN} sees the effect of a @sc{reset} on the
13841development board as a ``normal exit'' of your program.
13842
172c2a43 13843@node Renesas ICE
8e04817f
AC
13844@subsubsection Using the E7000 in-circuit emulator
13845
172c2a43 13846@kindex target e7000@r{, with Renesas ICE}
8e04817f 13847You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 13848Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
13849e7000} command to connect @value{GDBN} to your E7000:
13850
13851@table @code
13852@item target e7000 @var{port} @var{speed}
13853Use this form if your E7000 is connected to a serial port. The
13854@var{port} argument identifies what serial port to use (for example,
13855@samp{com2}). The third argument is the line speed in bits per second
13856(for example, @samp{9600}).
13857
13858@item target e7000 @var{hostname}
13859If your E7000 is installed as a host on a TCP/IP network, you can just
13860specify its hostname; @value{GDBN} uses @code{telnet} to connect.
13861@end table
13862
ba04e063
EZ
13863The following special commands are available when debugging with the
13864Renesas E7000 ICE:
13865
13866@table @code
13867@item e7000 @var{command}
13868@kindex e7000
13869@cindex send command to E7000 monitor
13870This sends the specified @var{command} to the E7000 monitor.
13871
13872@item ftplogin @var{machine} @var{username} @var{password} @var{dir}
13873@kindex ftplogin@r{, E7000}
13874This command records information for subsequent interface with the
13875E7000 monitor via the FTP protocol: @value{GDBN} will log into the
13876named @var{machine} using specified @var{username} and @var{password},
13877and then chdir to the named directory @var{dir}.
13878
13879@item ftpload @var{file}
13880@kindex ftpload@r{, E7000}
13881This command uses credentials recorded by @code{ftplogin} to fetch and
13882load the named @var{file} from the E7000 monitor.
13883
13884@item drain
13885@kindex drain@r{, E7000}
13886This command drains any pending text buffers stored on the E7000.
13887
13888@item set usehardbreakpoints
13889@itemx show usehardbreakpoints
13890@kindex set usehardbreakpoints@r{, E7000}
13891@kindex show usehardbreakpoints@r{, E7000}
13892@cindex hardware breakpoints, and E7000
13893These commands set and show the use of hardware breakpoints for all
13894breakpoints. @xref{Set Breaks, hardware-assisted breakpoint}, for
13895more information about using hardware breakpoints selectively.
13896@end table
13897
172c2a43
KI
13898@node Renesas Special
13899@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
13900
13901Some @value{GDBN} commands are available only for the H8/300:
13902
13903@table @code
13904
13905@kindex set machine
13906@kindex show machine
13907@item set machine h8300
13908@itemx set machine h8300h
13909Condition @value{GDBN} for one of the two variants of the H8/300
13910architecture with @samp{set machine}. You can use @samp{show machine}
13911to check which variant is currently in effect.
104c1213
JM
13912
13913@end table
13914
8e04817f
AC
13915@node H8/500
13916@subsection H8/500
104c1213
JM
13917
13918@table @code
13919
8e04817f
AC
13920@kindex set memory @var{mod}
13921@cindex memory models, H8/500
13922@item set memory @var{mod}
13923@itemx show memory
13924Specify which H8/500 memory model (@var{mod}) you are using with
13925@samp{set memory}; check which memory model is in effect with @samp{show
13926memory}. The accepted values for @var{mod} are @code{small},
13927@code{big}, @code{medium}, and @code{compact}.
104c1213 13928
8e04817f 13929@end table
104c1213 13930
8e04817f 13931@node M32R/D
ba04e063 13932@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
13933
13934@table @code
8e04817f
AC
13935@kindex target m32r
13936@item target m32r @var{dev}
172c2a43 13937Renesas M32R/D ROM monitor.
8e04817f 13938
fb3e19c0
KI
13939@kindex target m32rsdi
13940@item target m32rsdi @var{dev}
13941Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
13942@end table
13943
13944The following @value{GDBN} commands are specific to the M32R monitor:
13945
13946@table @code
13947@item set download-path @var{path}
13948@kindex set download-path
13949@cindex find downloadable @sc{srec} files (M32R)
13950Set the default path for finding donwloadable @sc{srec} files.
13951
13952@item show download-path
13953@kindex show download-path
13954Show the default path for downloadable @sc{srec} files.
fb3e19c0 13955
721c2651
EZ
13956@item set board-address @var{addr}
13957@kindex set board-address
13958@cindex M32-EVA target board address
13959Set the IP address for the M32R-EVA target board.
13960
13961@item show board-address
13962@kindex show board-address
13963Show the current IP address of the target board.
13964
13965@item set server-address @var{addr}
13966@kindex set server-address
13967@cindex download server address (M32R)
13968Set the IP address for the download server, which is the @value{GDBN}'s
13969host machine.
13970
13971@item show server-address
13972@kindex show server-address
13973Display the IP address of the download server.
13974
13975@item upload @r{[}@var{file}@r{]}
13976@kindex upload@r{, M32R}
13977Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
13978upload capability. If no @var{file} argument is given, the current
13979executable file is uploaded.
13980
13981@item tload @r{[}@var{file}@r{]}
13982@kindex tload@r{, M32R}
13983Test the @code{upload} command.
8e04817f
AC
13984@end table
13985
ba04e063
EZ
13986The following commands are available for M32R/SDI:
13987
13988@table @code
13989@item sdireset
13990@kindex sdireset
13991@cindex reset SDI connection, M32R
13992This command resets the SDI connection.
13993
13994@item sdistatus
13995@kindex sdistatus
13996This command shows the SDI connection status.
13997
13998@item debug_chaos
13999@kindex debug_chaos
14000@cindex M32R/Chaos debugging
14001Instructs the remote that M32R/Chaos debugging is to be used.
14002
14003@item use_debug_dma
14004@kindex use_debug_dma
14005Instructs the remote to use the DEBUG_DMA method of accessing memory.
14006
14007@item use_mon_code
14008@kindex use_mon_code
14009Instructs the remote to use the MON_CODE method of accessing memory.
14010
14011@item use_ib_break
14012@kindex use_ib_break
14013Instructs the remote to set breakpoints by IB break.
14014
14015@item use_dbt_break
14016@kindex use_dbt_break
14017Instructs the remote to set breakpoints by DBT.
14018@end table
14019
8e04817f
AC
14020@node M68K
14021@subsection M68k
14022
14023The Motorola m68k configuration includes ColdFire support, and
14024target command for the following ROM monitors.
14025
14026@table @code
14027
14028@kindex target abug
14029@item target abug @var{dev}
14030ABug ROM monitor for M68K.
14031
14032@kindex target cpu32bug
14033@item target cpu32bug @var{dev}
14034CPU32BUG monitor, running on a CPU32 (M68K) board.
14035
14036@kindex target dbug
14037@item target dbug @var{dev}
14038dBUG ROM monitor for Motorola ColdFire.
14039
14040@kindex target est
14041@item target est @var{dev}
14042EST-300 ICE monitor, running on a CPU32 (M68K) board.
14043
14044@kindex target rom68k
14045@item target rom68k @var{dev}
14046ROM 68K monitor, running on an M68K IDP board.
14047
14048@end table
14049
8e04817f
AC
14050@table @code
14051
14052@kindex target rombug
14053@item target rombug @var{dev}
14054ROMBUG ROM monitor for OS/9000.
14055
14056@end table
14057
8e04817f
AC
14058@node MIPS Embedded
14059@subsection MIPS Embedded
14060
14061@cindex MIPS boards
14062@value{GDBN} can use the MIPS remote debugging protocol to talk to a
14063MIPS board attached to a serial line. This is available when
14064you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 14065
8e04817f
AC
14066@need 1000
14067Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 14068
8e04817f
AC
14069@table @code
14070@item target mips @var{port}
14071@kindex target mips @var{port}
14072To run a program on the board, start up @code{@value{GDBP}} with the
14073name of your program as the argument. To connect to the board, use the
14074command @samp{target mips @var{port}}, where @var{port} is the name of
14075the serial port connected to the board. If the program has not already
14076been downloaded to the board, you may use the @code{load} command to
14077download it. You can then use all the usual @value{GDBN} commands.
104c1213 14078
8e04817f
AC
14079For example, this sequence connects to the target board through a serial
14080port, and loads and runs a program called @var{prog} through the
14081debugger:
104c1213 14082
474c8240 14083@smallexample
8e04817f
AC
14084host$ @value{GDBP} @var{prog}
14085@value{GDBN} is free software and @dots{}
14086(@value{GDBP}) target mips /dev/ttyb
14087(@value{GDBP}) load @var{prog}
14088(@value{GDBP}) run
474c8240 14089@end smallexample
104c1213 14090
8e04817f
AC
14091@item target mips @var{hostname}:@var{portnumber}
14092On some @value{GDBN} host configurations, you can specify a TCP
14093connection (for instance, to a serial line managed by a terminal
14094concentrator) instead of a serial port, using the syntax
14095@samp{@var{hostname}:@var{portnumber}}.
104c1213 14096
8e04817f
AC
14097@item target pmon @var{port}
14098@kindex target pmon @var{port}
14099PMON ROM monitor.
104c1213 14100
8e04817f
AC
14101@item target ddb @var{port}
14102@kindex target ddb @var{port}
14103NEC's DDB variant of PMON for Vr4300.
104c1213 14104
8e04817f
AC
14105@item target lsi @var{port}
14106@kindex target lsi @var{port}
14107LSI variant of PMON.
104c1213 14108
8e04817f
AC
14109@kindex target r3900
14110@item target r3900 @var{dev}
14111Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 14112
8e04817f
AC
14113@kindex target array
14114@item target array @var{dev}
14115Array Tech LSI33K RAID controller board.
104c1213 14116
8e04817f 14117@end table
104c1213 14118
104c1213 14119
8e04817f
AC
14120@noindent
14121@value{GDBN} also supports these special commands for MIPS targets:
104c1213 14122
8e04817f 14123@table @code
8e04817f
AC
14124@item set mipsfpu double
14125@itemx set mipsfpu single
14126@itemx set mipsfpu none
a64548ea 14127@itemx set mipsfpu auto
8e04817f
AC
14128@itemx show mipsfpu
14129@kindex set mipsfpu
14130@kindex show mipsfpu
14131@cindex MIPS remote floating point
14132@cindex floating point, MIPS remote
14133If your target board does not support the MIPS floating point
14134coprocessor, you should use the command @samp{set mipsfpu none} (if you
14135need this, you may wish to put the command in your @value{GDBN} init
14136file). This tells @value{GDBN} how to find the return value of
14137functions which return floating point values. It also allows
14138@value{GDBN} to avoid saving the floating point registers when calling
14139functions on the board. If you are using a floating point coprocessor
14140with only single precision floating point support, as on the @sc{r4650}
14141processor, use the command @samp{set mipsfpu single}. The default
14142double precision floating point coprocessor may be selected using
14143@samp{set mipsfpu double}.
104c1213 14144
8e04817f
AC
14145In previous versions the only choices were double precision or no
14146floating point, so @samp{set mipsfpu on} will select double precision
14147and @samp{set mipsfpu off} will select no floating point.
104c1213 14148
8e04817f
AC
14149As usual, you can inquire about the @code{mipsfpu} variable with
14150@samp{show mipsfpu}.
104c1213 14151
8e04817f
AC
14152@item set timeout @var{seconds}
14153@itemx set retransmit-timeout @var{seconds}
14154@itemx show timeout
14155@itemx show retransmit-timeout
14156@cindex @code{timeout}, MIPS protocol
14157@cindex @code{retransmit-timeout}, MIPS protocol
14158@kindex set timeout
14159@kindex show timeout
14160@kindex set retransmit-timeout
14161@kindex show retransmit-timeout
14162You can control the timeout used while waiting for a packet, in the MIPS
14163remote protocol, with the @code{set timeout @var{seconds}} command. The
14164default is 5 seconds. Similarly, you can control the timeout used while
14165waiting for an acknowledgement of a packet with the @code{set
14166retransmit-timeout @var{seconds}} command. The default is 3 seconds.
14167You can inspect both values with @code{show timeout} and @code{show
14168retransmit-timeout}. (These commands are @emph{only} available when
14169@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 14170
8e04817f
AC
14171The timeout set by @code{set timeout} does not apply when @value{GDBN}
14172is waiting for your program to stop. In that case, @value{GDBN} waits
14173forever because it has no way of knowing how long the program is going
14174to run before stopping.
ba04e063
EZ
14175
14176@item set syn-garbage-limit @var{num}
14177@kindex set syn-garbage-limit@r{, MIPS remote}
14178@cindex synchronize with remote MIPS target
14179Limit the maximum number of characters @value{GDBN} should ignore when
14180it tries to synchronize with the remote target. The default is 10
14181characters. Setting the limit to -1 means there's no limit.
14182
14183@item show syn-garbage-limit
14184@kindex show syn-garbage-limit@r{, MIPS remote}
14185Show the current limit on the number of characters to ignore when
14186trying to synchronize with the remote system.
14187
14188@item set monitor-prompt @var{prompt}
14189@kindex set monitor-prompt@r{, MIPS remote}
14190@cindex remote monitor prompt
14191Tell @value{GDBN} to expect the specified @var{prompt} string from the
14192remote monitor. The default depends on the target:
14193@table @asis
14194@item pmon target
14195@samp{PMON}
14196@item ddb target
14197@samp{NEC010}
14198@item lsi target
14199@samp{PMON>}
14200@end table
14201
14202@item show monitor-prompt
14203@kindex show monitor-prompt@r{, MIPS remote}
14204Show the current strings @value{GDBN} expects as the prompt from the
14205remote monitor.
14206
14207@item set monitor-warnings
14208@kindex set monitor-warnings@r{, MIPS remote}
14209Enable or disable monitor warnings about hardware breakpoints. This
14210has effect only for the @code{lsi} target. When on, @value{GDBN} will
14211display warning messages whose codes are returned by the @code{lsi}
14212PMON monitor for breakpoint commands.
14213
14214@item show monitor-warnings
14215@kindex show monitor-warnings@r{, MIPS remote}
14216Show the current setting of printing monitor warnings.
14217
14218@item pmon @var{command}
14219@kindex pmon@r{, MIPS remote}
14220@cindex send PMON command
14221This command allows sending an arbitrary @var{command} string to the
14222monitor. The monitor must be in debug mode for this to work.
8e04817f 14223@end table
104c1213 14224
a37295f9
MM
14225@node OpenRISC 1000
14226@subsection OpenRISC 1000
14227@cindex OpenRISC 1000
14228
14229@cindex or1k boards
14230See OR1k Architecture document (@uref{www.opencores.org}) for more information
14231about platform and commands.
14232
14233@table @code
14234
14235@kindex target jtag
14236@item target jtag jtag://@var{host}:@var{port}
14237
14238Connects to remote JTAG server.
14239JTAG remote server can be either an or1ksim or JTAG server,
14240connected via parallel port to the board.
14241
14242Example: @code{target jtag jtag://localhost:9999}
14243
14244@kindex or1ksim
14245@item or1ksim @var{command}
14246If connected to @code{or1ksim} OpenRISC 1000 Architectural
14247Simulator, proprietary commands can be executed.
14248
14249@kindex info or1k spr
14250@item info or1k spr
14251Displays spr groups.
14252
14253@item info or1k spr @var{group}
14254@itemx info or1k spr @var{groupno}
14255Displays register names in selected group.
14256
14257@item info or1k spr @var{group} @var{register}
14258@itemx info or1k spr @var{register}
14259@itemx info or1k spr @var{groupno} @var{registerno}
14260@itemx info or1k spr @var{registerno}
14261Shows information about specified spr register.
14262
14263@kindex spr
14264@item spr @var{group} @var{register} @var{value}
14265@itemx spr @var{register @var{value}}
14266@itemx spr @var{groupno} @var{registerno @var{value}}
14267@itemx spr @var{registerno @var{value}}
14268Writes @var{value} to specified spr register.
14269@end table
14270
14271Some implementations of OpenRISC 1000 Architecture also have hardware trace.
14272It is very similar to @value{GDBN} trace, except it does not interfere with normal
14273program execution and is thus much faster. Hardware breakpoints/watchpoint
14274triggers can be set using:
14275@table @code
14276@item $LEA/$LDATA
14277Load effective address/data
14278@item $SEA/$SDATA
14279Store effective address/data
14280@item $AEA/$ADATA
14281Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
14282@item $FETCH
14283Fetch data
14284@end table
14285
14286When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
14287@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
14288
14289@code{htrace} commands:
14290@cindex OpenRISC 1000 htrace
14291@table @code
14292@kindex hwatch
14293@item hwatch @var{conditional}
14294Set hardware watchpoint on combination of Load/Store Effecive Address(es)
14295or Data. For example:
14296
14297@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14298
14299@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14300
4644b6e3 14301@kindex htrace
a37295f9
MM
14302@item htrace info
14303Display information about current HW trace configuration.
14304
a37295f9
MM
14305@item htrace trigger @var{conditional}
14306Set starting criteria for HW trace.
14307
a37295f9
MM
14308@item htrace qualifier @var{conditional}
14309Set acquisition qualifier for HW trace.
14310
a37295f9
MM
14311@item htrace stop @var{conditional}
14312Set HW trace stopping criteria.
14313
f153cc92 14314@item htrace record [@var{data}]*
a37295f9
MM
14315Selects the data to be recorded, when qualifier is met and HW trace was
14316triggered.
14317
a37295f9 14318@item htrace enable
a37295f9
MM
14319@itemx htrace disable
14320Enables/disables the HW trace.
14321
f153cc92 14322@item htrace rewind [@var{filename}]
a37295f9
MM
14323Clears currently recorded trace data.
14324
14325If filename is specified, new trace file is made and any newly collected data
14326will be written there.
14327
f153cc92 14328@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
14329Prints trace buffer, using current record configuration.
14330
a37295f9
MM
14331@item htrace mode continuous
14332Set continuous trace mode.
14333
a37295f9
MM
14334@item htrace mode suspend
14335Set suspend trace mode.
14336
14337@end table
14338
8e04817f
AC
14339@node PowerPC
14340@subsection PowerPC
104c1213
JM
14341
14342@table @code
8e04817f
AC
14343@kindex target dink32
14344@item target dink32 @var{dev}
14345DINK32 ROM monitor.
104c1213 14346
8e04817f
AC
14347@kindex target ppcbug
14348@item target ppcbug @var{dev}
14349@kindex target ppcbug1
14350@item target ppcbug1 @var{dev}
14351PPCBUG ROM monitor for PowerPC.
104c1213 14352
8e04817f
AC
14353@kindex target sds
14354@item target sds @var{dev}
14355SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 14356@end table
8e04817f 14357
c45da7e6
EZ
14358@cindex SDS protocol
14359The following commands specifi to the SDS protocol are supported
14360by@value{GDBN}:
14361
14362@table @code
14363@item set sdstimeout @var{nsec}
14364@kindex set sdstimeout
14365Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
14366default is 2 seconds.
14367
14368@item show sdstimeout
14369@kindex show sdstimeout
14370Show the current value of the SDS timeout.
14371
14372@item sds @var{command}
14373@kindex sds@r{, a command}
14374Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
14375@end table
14376
c45da7e6 14377
8e04817f
AC
14378@node PA
14379@subsection HP PA Embedded
104c1213
JM
14380
14381@table @code
14382
8e04817f
AC
14383@kindex target op50n
14384@item target op50n @var{dev}
14385OP50N monitor, running on an OKI HPPA board.
14386
14387@kindex target w89k
14388@item target w89k @var{dev}
14389W89K monitor, running on a Winbond HPPA board.
104c1213
JM
14390
14391@end table
14392
8e04817f 14393@node SH
172c2a43 14394@subsection Renesas SH
104c1213
JM
14395
14396@table @code
14397
172c2a43 14398@kindex target hms@r{, with Renesas SH}
8e04817f 14399@item target hms @var{dev}
172c2a43 14400A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
14401commands @code{device} and @code{speed} to control the serial line and
14402the communications speed used.
104c1213 14403
172c2a43 14404@kindex target e7000@r{, with Renesas SH}
8e04817f 14405@item target e7000 @var{dev}
172c2a43 14406E7000 emulator for Renesas SH.
104c1213 14407
8e04817f
AC
14408@kindex target sh3@r{, with SH}
14409@kindex target sh3e@r{, with SH}
14410@item target sh3 @var{dev}
14411@item target sh3e @var{dev}
172c2a43 14412Renesas SH-3 and SH-3E target systems.
104c1213 14413
8e04817f 14414@end table
104c1213 14415
8e04817f
AC
14416@node Sparclet
14417@subsection Tsqware Sparclet
104c1213 14418
8e04817f
AC
14419@cindex Sparclet
14420
14421@value{GDBN} enables developers to debug tasks running on
14422Sparclet targets from a Unix host.
14423@value{GDBN} uses code that runs on
14424both the Unix host and on the Sparclet target. The program
14425@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 14426
8e04817f
AC
14427@table @code
14428@item remotetimeout @var{args}
14429@kindex remotetimeout
14430@value{GDBN} supports the option @code{remotetimeout}.
14431This option is set by the user, and @var{args} represents the number of
14432seconds @value{GDBN} waits for responses.
104c1213
JM
14433@end table
14434
8e04817f
AC
14435@cindex compiling, on Sparclet
14436When compiling for debugging, include the options @samp{-g} to get debug
14437information and @samp{-Ttext} to relocate the program to where you wish to
14438load it on the target. You may also want to add the options @samp{-n} or
14439@samp{-N} in order to reduce the size of the sections. Example:
104c1213 14440
474c8240 14441@smallexample
8e04817f 14442sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 14443@end smallexample
104c1213 14444
8e04817f 14445You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 14446
474c8240 14447@smallexample
8e04817f 14448sparclet-aout-objdump --headers --syms prog
474c8240 14449@end smallexample
104c1213 14450
8e04817f
AC
14451@cindex running, on Sparclet
14452Once you have set
14453your Unix execution search path to find @value{GDBN}, you are ready to
14454run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
14455(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 14456
8e04817f
AC
14457@value{GDBN} comes up showing the prompt:
14458
474c8240 14459@smallexample
8e04817f 14460(gdbslet)
474c8240 14461@end smallexample
104c1213
JM
14462
14463@menu
8e04817f
AC
14464* Sparclet File:: Setting the file to debug
14465* Sparclet Connection:: Connecting to Sparclet
14466* Sparclet Download:: Sparclet download
14467* Sparclet Execution:: Running and debugging
104c1213
JM
14468@end menu
14469
8e04817f
AC
14470@node Sparclet File
14471@subsubsection Setting file to debug
104c1213 14472
8e04817f 14473The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 14474
474c8240 14475@smallexample
8e04817f 14476(gdbslet) file prog
474c8240 14477@end smallexample
104c1213 14478
8e04817f
AC
14479@need 1000
14480@value{GDBN} then attempts to read the symbol table of @file{prog}.
14481@value{GDBN} locates
14482the file by searching the directories listed in the command search
14483path.
14484If the file was compiled with debug information (option "-g"), source
14485files will be searched as well.
14486@value{GDBN} locates
14487the source files by searching the directories listed in the directory search
14488path (@pxref{Environment, ,Your program's environment}).
14489If it fails
14490to find a file, it displays a message such as:
104c1213 14491
474c8240 14492@smallexample
8e04817f 14493prog: No such file or directory.
474c8240 14494@end smallexample
104c1213 14495
8e04817f
AC
14496When this happens, add the appropriate directories to the search paths with
14497the @value{GDBN} commands @code{path} and @code{dir}, and execute the
14498@code{target} command again.
104c1213 14499
8e04817f
AC
14500@node Sparclet Connection
14501@subsubsection Connecting to Sparclet
104c1213 14502
8e04817f
AC
14503The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
14504To connect to a target on serial port ``@code{ttya}'', type:
104c1213 14505
474c8240 14506@smallexample
8e04817f
AC
14507(gdbslet) target sparclet /dev/ttya
14508Remote target sparclet connected to /dev/ttya
14509main () at ../prog.c:3
474c8240 14510@end smallexample
104c1213 14511
8e04817f
AC
14512@need 750
14513@value{GDBN} displays messages like these:
104c1213 14514
474c8240 14515@smallexample
8e04817f 14516Connected to ttya.
474c8240 14517@end smallexample
104c1213 14518
8e04817f
AC
14519@node Sparclet Download
14520@subsubsection Sparclet download
104c1213 14521
8e04817f
AC
14522@cindex download to Sparclet
14523Once connected to the Sparclet target,
14524you can use the @value{GDBN}
14525@code{load} command to download the file from the host to the target.
14526The file name and load offset should be given as arguments to the @code{load}
14527command.
14528Since the file format is aout, the program must be loaded to the starting
14529address. You can use @code{objdump} to find out what this value is. The load
14530offset is an offset which is added to the VMA (virtual memory address)
14531of each of the file's sections.
14532For instance, if the program
14533@file{prog} was linked to text address 0x1201000, with data at 0x12010160
14534and bss at 0x12010170, in @value{GDBN}, type:
104c1213 14535
474c8240 14536@smallexample
8e04817f
AC
14537(gdbslet) load prog 0x12010000
14538Loading section .text, size 0xdb0 vma 0x12010000
474c8240 14539@end smallexample
104c1213 14540
8e04817f
AC
14541If the code is loaded at a different address then what the program was linked
14542to, you may need to use the @code{section} and @code{add-symbol-file} commands
14543to tell @value{GDBN} where to map the symbol table.
14544
14545@node Sparclet Execution
14546@subsubsection Running and debugging
14547
14548@cindex running and debugging Sparclet programs
14549You can now begin debugging the task using @value{GDBN}'s execution control
14550commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
14551manual for the list of commands.
14552
474c8240 14553@smallexample
8e04817f
AC
14554(gdbslet) b main
14555Breakpoint 1 at 0x12010000: file prog.c, line 3.
14556(gdbslet) run
14557Starting program: prog
14558Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
145593 char *symarg = 0;
14560(gdbslet) step
145614 char *execarg = "hello!";
14562(gdbslet)
474c8240 14563@end smallexample
8e04817f
AC
14564
14565@node Sparclite
14566@subsection Fujitsu Sparclite
104c1213
JM
14567
14568@table @code
14569
8e04817f
AC
14570@kindex target sparclite
14571@item target sparclite @var{dev}
14572Fujitsu sparclite boards, used only for the purpose of loading.
14573You must use an additional command to debug the program.
14574For example: target remote @var{dev} using @value{GDBN} standard
14575remote protocol.
104c1213
JM
14576
14577@end table
14578
8e04817f
AC
14579@node ST2000
14580@subsection Tandem ST2000
104c1213 14581
8e04817f
AC
14582@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
14583STDBUG protocol.
104c1213 14584
8e04817f
AC
14585To connect your ST2000 to the host system, see the manufacturer's
14586manual. Once the ST2000 is physically attached, you can run:
104c1213 14587
474c8240 14588@smallexample
8e04817f 14589target st2000 @var{dev} @var{speed}
474c8240 14590@end smallexample
104c1213 14591
8e04817f
AC
14592@noindent
14593to establish it as your debugging environment. @var{dev} is normally
14594the name of a serial device, such as @file{/dev/ttya}, connected to the
14595ST2000 via a serial line. You can instead specify @var{dev} as a TCP
14596connection (for example, to a serial line attached via a terminal
14597concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 14598
8e04817f
AC
14599The @code{load} and @code{attach} commands are @emph{not} defined for
14600this target; you must load your program into the ST2000 as you normally
14601would for standalone operation. @value{GDBN} reads debugging information
14602(such as symbols) from a separate, debugging version of the program
14603available on your host computer.
14604@c FIXME!! This is terribly vague; what little content is here is
14605@c basically hearsay.
104c1213 14606
8e04817f
AC
14607@cindex ST2000 auxiliary commands
14608These auxiliary @value{GDBN} commands are available to help you with the ST2000
14609environment:
104c1213 14610
8e04817f
AC
14611@table @code
14612@item st2000 @var{command}
14613@kindex st2000 @var{cmd}
14614@cindex STDBUG commands (ST2000)
14615@cindex commands to STDBUG (ST2000)
14616Send a @var{command} to the STDBUG monitor. See the manufacturer's
14617manual for available commands.
104c1213 14618
8e04817f
AC
14619@item connect
14620@cindex connect (to STDBUG)
14621Connect the controlling terminal to the STDBUG command monitor. When
14622you are done interacting with STDBUG, typing either of two character
14623sequences gets you back to the @value{GDBN} command prompt:
14624@kbd{@key{RET}~.} (Return, followed by tilde and period) or
14625@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
14626@end table
14627
8e04817f
AC
14628@node Z8000
14629@subsection Zilog Z8000
104c1213 14630
8e04817f
AC
14631@cindex Z8000
14632@cindex simulator, Z8000
14633@cindex Zilog Z8000 simulator
104c1213 14634
8e04817f
AC
14635When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
14636a Z8000 simulator.
14637
14638For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
14639unsegmented variant of the Z8000 architecture) or the Z8001 (the
14640segmented variant). The simulator recognizes which architecture is
14641appropriate by inspecting the object code.
104c1213 14642
8e04817f
AC
14643@table @code
14644@item target sim @var{args}
14645@kindex sim
14646@kindex target sim@r{, with Z8000}
14647Debug programs on a simulated CPU. If the simulator supports setup
14648options, specify them via @var{args}.
104c1213
JM
14649@end table
14650
8e04817f
AC
14651@noindent
14652After specifying this target, you can debug programs for the simulated
14653CPU in the same style as programs for your host computer; use the
14654@code{file} command to load a new program image, the @code{run} command
14655to run your program, and so on.
14656
14657As well as making available all the usual machine registers
14658(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
14659additional items of information as specially named registers:
104c1213
JM
14660
14661@table @code
14662
8e04817f
AC
14663@item cycles
14664Counts clock-ticks in the simulator.
104c1213 14665
8e04817f
AC
14666@item insts
14667Counts instructions run in the simulator.
104c1213 14668
8e04817f
AC
14669@item time
14670Execution time in 60ths of a second.
104c1213 14671
8e04817f 14672@end table
104c1213 14673
8e04817f
AC
14674You can refer to these values in @value{GDBN} expressions with the usual
14675conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
14676conditional breakpoint that suspends only after at least 5000
14677simulated clock ticks.
104c1213 14678
a64548ea
EZ
14679@node AVR
14680@subsection Atmel AVR
14681@cindex AVR
14682
14683When configured for debugging the Atmel AVR, @value{GDBN} supports the
14684following AVR-specific commands:
14685
14686@table @code
14687@item info io_registers
14688@kindex info io_registers@r{, AVR}
14689@cindex I/O registers (Atmel AVR)
14690This command displays information about the AVR I/O registers. For
14691each register, @value{GDBN} prints its number and value.
14692@end table
14693
14694@node CRIS
14695@subsection CRIS
14696@cindex CRIS
14697
14698When configured for debugging CRIS, @value{GDBN} provides the
14699following CRIS-specific commands:
14700
14701@table @code
14702@item set cris-version @var{ver}
14703@cindex CRIS version
e22e55c9
OF
14704Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
14705The CRIS version affects register names and sizes. This command is useful in
14706case autodetection of the CRIS version fails.
a64548ea
EZ
14707
14708@item show cris-version
14709Show the current CRIS version.
14710
14711@item set cris-dwarf2-cfi
14712@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
14713Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
14714Change to @samp{off} when using @code{gcc-cris} whose version is below
14715@code{R59}.
a64548ea
EZ
14716
14717@item show cris-dwarf2-cfi
14718Show the current state of using DWARF-2 CFI.
e22e55c9
OF
14719
14720@item set cris-mode @var{mode}
14721@cindex CRIS mode
14722Set the current CRIS mode to @var{mode}. It should only be changed when
14723debugging in guru mode, in which case it should be set to
14724@samp{guru} (the default is @samp{normal}).
14725
14726@item show cris-mode
14727Show the current CRIS mode.
a64548ea
EZ
14728@end table
14729
14730@node Super-H
14731@subsection Renesas Super-H
14732@cindex Super-H
14733
14734For the Renesas Super-H processor, @value{GDBN} provides these
14735commands:
14736
14737@table @code
14738@item regs
14739@kindex regs@r{, Super-H}
14740Show the values of all Super-H registers.
14741@end table
14742
c45da7e6
EZ
14743@node WinCE
14744@subsection Windows CE
14745@cindex Windows CE
14746
14747The following commands are available for Windows CE:
14748
14749@table @code
14750@item set remotedirectory @var{dir}
14751@kindex set remotedirectory
14752Tell @value{GDBN} to upload files from the named directory @var{dir}.
14753The default is @file{/gdb}, i.e.@: the root directory on the current
14754drive.
14755
14756@item show remotedirectory
14757@kindex show remotedirectory
14758Show the current value of the upload directory.
14759
14760@item set remoteupload @var{method}
14761@kindex set remoteupload
14762Set the method used to upload files to remote device. Valid values
14763for @var{method} are @samp{always}, @samp{newer}, and @samp{never}.
14764The default is @samp{newer}.
14765
14766@item show remoteupload
14767@kindex show remoteupload
14768Show the current setting of the upload method.
14769
14770@item set remoteaddhost
14771@kindex set remoteaddhost
14772Tell @value{GDBN} whether to add this host to the remote stub's
14773arguments when you debug over a network.
14774
14775@item show remoteaddhost
14776@kindex show remoteaddhost
14777Show whether to add this host to remote stub's arguments when
14778debugging over a network.
14779@end table
14780
a64548ea 14781
8e04817f
AC
14782@node Architectures
14783@section Architectures
104c1213 14784
8e04817f
AC
14785This section describes characteristics of architectures that affect
14786all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 14787
8e04817f 14788@menu
9c16f35a 14789* i386::
8e04817f
AC
14790* A29K::
14791* Alpha::
14792* MIPS::
a64548ea 14793* HPPA:: HP PA architecture
8e04817f 14794@end menu
104c1213 14795
9c16f35a
EZ
14796@node i386
14797@subsection x86 Architecture-specific issues.
14798
14799@table @code
14800@item set struct-convention @var{mode}
14801@kindex set struct-convention
14802@cindex struct return convention
14803@cindex struct/union returned in registers
14804Set the convention used by the inferior to return @code{struct}s and
14805@code{union}s from functions to @var{mode}. Possible values of
14806@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
14807default). @code{"default"} or @code{"pcc"} means that @code{struct}s
14808are returned on the stack, while @code{"reg"} means that a
14809@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
14810be returned in a register.
14811
14812@item show struct-convention
14813@kindex show struct-convention
14814Show the current setting of the convention to return @code{struct}s
14815from functions.
14816@end table
14817
8e04817f
AC
14818@node A29K
14819@subsection A29K
104c1213
JM
14820
14821@table @code
104c1213 14822
8e04817f
AC
14823@kindex set rstack_high_address
14824@cindex AMD 29K register stack
14825@cindex register stack, AMD29K
14826@item set rstack_high_address @var{address}
14827On AMD 29000 family processors, registers are saved in a separate
14828@dfn{register stack}. There is no way for @value{GDBN} to determine the
14829extent of this stack. Normally, @value{GDBN} just assumes that the
14830stack is ``large enough''. This may result in @value{GDBN} referencing
14831memory locations that do not exist. If necessary, you can get around
14832this problem by specifying the ending address of the register stack with
14833the @code{set rstack_high_address} command. The argument should be an
14834address, which you probably want to precede with @samp{0x} to specify in
14835hexadecimal.
104c1213 14836
8e04817f
AC
14837@kindex show rstack_high_address
14838@item show rstack_high_address
14839Display the current limit of the register stack, on AMD 29000 family
14840processors.
104c1213 14841
8e04817f 14842@end table
104c1213 14843
8e04817f
AC
14844@node Alpha
14845@subsection Alpha
104c1213 14846
8e04817f 14847See the following section.
104c1213 14848
8e04817f
AC
14849@node MIPS
14850@subsection MIPS
104c1213 14851
8e04817f
AC
14852@cindex stack on Alpha
14853@cindex stack on MIPS
14854@cindex Alpha stack
14855@cindex MIPS stack
14856Alpha- and MIPS-based computers use an unusual stack frame, which
14857sometimes requires @value{GDBN} to search backward in the object code to
14858find the beginning of a function.
104c1213 14859
8e04817f
AC
14860@cindex response time, MIPS debugging
14861To improve response time (especially for embedded applications, where
14862@value{GDBN} may be restricted to a slow serial line for this search)
14863you may want to limit the size of this search, using one of these
14864commands:
104c1213 14865
8e04817f
AC
14866@table @code
14867@cindex @code{heuristic-fence-post} (Alpha, MIPS)
14868@item set heuristic-fence-post @var{limit}
14869Restrict @value{GDBN} to examining at most @var{limit} bytes in its
14870search for the beginning of a function. A value of @var{0} (the
14871default) means there is no limit. However, except for @var{0}, the
14872larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
14873and therefore the longer it takes to run. You should only need to use
14874this command when debugging a stripped executable.
104c1213 14875
8e04817f
AC
14876@item show heuristic-fence-post
14877Display the current limit.
14878@end table
104c1213
JM
14879
14880@noindent
8e04817f
AC
14881These commands are available @emph{only} when @value{GDBN} is configured
14882for debugging programs on Alpha or MIPS processors.
104c1213 14883
a64548ea
EZ
14884Several MIPS-specific commands are available when debugging MIPS
14885programs:
14886
14887@table @code
14888@item set mips saved-gpreg-size @var{size}
14889@kindex set mips saved-gpreg-size
14890@cindex MIPS GP register size on stack
14891Set the size of MIPS general-purpose registers saved on the stack.
14892The argument @var{size} can be one of the following:
14893
14894@table @samp
14895@item 32
1489632-bit GP registers
14897@item 64
1489864-bit GP registers
14899@item auto
14900Use the target's default setting or autodetect the saved size from the
14901information contained in the executable. This is the default
14902@end table
14903
14904@item show mips saved-gpreg-size
14905@kindex show mips saved-gpreg-size
14906Show the current size of MIPS GP registers on the stack.
14907
14908@item set mips stack-arg-size @var{size}
14909@kindex set mips stack-arg-size
14910@cindex MIPS stack space for arguments
14911Set the amount of stack space reserved for arguments to functions.
14912The argument can be one of @code{"32"}, @code{"64"} or @code{"auto"}
14913(the default).
14914
14915@item set mips abi @var{arg}
14916@kindex set mips abi
14917@cindex set ABI for MIPS
14918Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
14919values of @var{arg} are:
14920
14921@table @samp
14922@item auto
14923The default ABI associated with the current binary (this is the
14924default).
14925@item o32
14926@item o64
14927@item n32
14928@item n64
14929@item eabi32
14930@item eabi64
14931@item auto
14932@end table
14933
14934@item show mips abi
14935@kindex show mips abi
14936Show the MIPS ABI used by @value{GDBN} to debug the inferior.
14937
14938@item set mipsfpu
14939@itemx show mipsfpu
14940@xref{MIPS Embedded, set mipsfpu}.
14941
14942@item set mips mask-address @var{arg}
14943@kindex set mips mask-address
14944@cindex MIPS addresses, masking
14945This command determines whether the most-significant 32 bits of 64-bit
14946MIPS addresses are masked off. The argument @var{arg} can be
14947@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
14948setting, which lets @value{GDBN} determine the correct value.
14949
14950@item show mips mask-address
14951@kindex show mips mask-address
14952Show whether the upper 32 bits of MIPS addresses are masked off or
14953not.
14954
14955@item set remote-mips64-transfers-32bit-regs
14956@kindex set remote-mips64-transfers-32bit-regs
14957This command controls compatibility with 64-bit MIPS targets that
14958transfer data in 32-bit quantities. If you have an old MIPS 64 target
14959that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
14960and 64 bits for other registers, set this option to @samp{on}.
14961
14962@item show remote-mips64-transfers-32bit-regs
14963@kindex show remote-mips64-transfers-32bit-regs
14964Show the current setting of compatibility with older MIPS 64 targets.
14965
14966@item set debug mips
14967@kindex set debug mips
14968This command turns on and off debugging messages for the MIPS-specific
14969target code in @value{GDBN}.
14970
14971@item show debug mips
14972@kindex show debug mips
14973Show the current setting of MIPS debugging messages.
14974@end table
14975
14976
14977@node HPPA
14978@subsection HPPA
14979@cindex HPPA support
14980
14981When @value{GDBN} is debugging te HP PA architecture, it provides the
14982following special commands:
14983
14984@table @code
14985@item set debug hppa
14986@kindex set debug hppa
14987THis command determines whether HPPA architecture specific debugging
14988messages are to be displayed.
14989
14990@item show debug hppa
14991Show whether HPPA debugging messages are displayed.
14992
14993@item maint print unwind @var{address}
14994@kindex maint print unwind@r{, HPPA}
14995This command displays the contents of the unwind table entry at the
14996given @var{address}.
14997
14998@end table
14999
104c1213 15000
8e04817f
AC
15001@node Controlling GDB
15002@chapter Controlling @value{GDBN}
15003
15004You can alter the way @value{GDBN} interacts with you by using the
15005@code{set} command. For commands controlling how @value{GDBN} displays
15006data, see @ref{Print Settings, ,Print settings}. Other settings are
15007described here.
15008
15009@menu
15010* Prompt:: Prompt
15011* Editing:: Command editing
15012* History:: Command history
15013* Screen Size:: Screen size
15014* Numbers:: Numbers
1e698235 15015* ABI:: Configuring the current ABI
8e04817f
AC
15016* Messages/Warnings:: Optional warnings and messages
15017* Debugging Output:: Optional messages about internal happenings
15018@end menu
15019
15020@node Prompt
15021@section Prompt
104c1213 15022
8e04817f 15023@cindex prompt
104c1213 15024
8e04817f
AC
15025@value{GDBN} indicates its readiness to read a command by printing a string
15026called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
15027can change the prompt string with the @code{set prompt} command. For
15028instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
15029the prompt in one of the @value{GDBN} sessions so that you can always tell
15030which one you are talking to.
104c1213 15031
8e04817f
AC
15032@emph{Note:} @code{set prompt} does not add a space for you after the
15033prompt you set. This allows you to set a prompt which ends in a space
15034or a prompt that does not.
104c1213 15035
8e04817f
AC
15036@table @code
15037@kindex set prompt
15038@item set prompt @var{newprompt}
15039Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 15040
8e04817f
AC
15041@kindex show prompt
15042@item show prompt
15043Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
15044@end table
15045
8e04817f
AC
15046@node Editing
15047@section Command editing
15048@cindex readline
15049@cindex command line editing
104c1213 15050
703663ab 15051@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
15052@sc{gnu} library provides consistent behavior for programs which provide a
15053command line interface to the user. Advantages are @sc{gnu} Emacs-style
15054or @dfn{vi}-style inline editing of commands, @code{csh}-like history
15055substitution, and a storage and recall of command history across
15056debugging sessions.
104c1213 15057
8e04817f
AC
15058You may control the behavior of command line editing in @value{GDBN} with the
15059command @code{set}.
104c1213 15060
8e04817f
AC
15061@table @code
15062@kindex set editing
15063@cindex editing
15064@item set editing
15065@itemx set editing on
15066Enable command line editing (enabled by default).
104c1213 15067
8e04817f
AC
15068@item set editing off
15069Disable command line editing.
104c1213 15070
8e04817f
AC
15071@kindex show editing
15072@item show editing
15073Show whether command line editing is enabled.
104c1213
JM
15074@end table
15075
703663ab
EZ
15076@xref{Command Line Editing}, for more details about the Readline
15077interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
15078encouraged to read that chapter.
15079
8e04817f
AC
15080@node History
15081@section Command history
703663ab 15082@cindex command history
8e04817f
AC
15083
15084@value{GDBN} can keep track of the commands you type during your
15085debugging sessions, so that you can be certain of precisely what
15086happened. Use these commands to manage the @value{GDBN} command
15087history facility.
104c1213 15088
703663ab
EZ
15089@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
15090package, to provide the history facility. @xref{Using History
15091Interactively}, for the detailed description of the History library.
15092
15093Here is the description of @value{GDBN} commands related to command
15094history.
15095
104c1213 15096@table @code
8e04817f
AC
15097@cindex history substitution
15098@cindex history file
15099@kindex set history filename
4644b6e3 15100@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
15101@item set history filename @var{fname}
15102Set the name of the @value{GDBN} command history file to @var{fname}.
15103This is the file where @value{GDBN} reads an initial command history
15104list, and where it writes the command history from this session when it
15105exits. You can access this list through history expansion or through
15106the history command editing characters listed below. This file defaults
15107to the value of the environment variable @code{GDBHISTFILE}, or to
15108@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
15109is not set.
104c1213 15110
9c16f35a
EZ
15111@cindex save command history
15112@kindex set history save
8e04817f
AC
15113@item set history save
15114@itemx set history save on
15115Record command history in a file, whose name may be specified with the
15116@code{set history filename} command. By default, this option is disabled.
104c1213 15117
8e04817f
AC
15118@item set history save off
15119Stop recording command history in a file.
104c1213 15120
8e04817f 15121@cindex history size
9c16f35a 15122@kindex set history size
6fc08d32 15123@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
15124@item set history size @var{size}
15125Set the number of commands which @value{GDBN} keeps in its history list.
15126This defaults to the value of the environment variable
15127@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
15128@end table
15129
8e04817f 15130History expansion assigns special meaning to the character @kbd{!}.
703663ab 15131@xref{Event Designators}, for more details.
8e04817f 15132
703663ab 15133@cindex history expansion, turn on/off
8e04817f
AC
15134Since @kbd{!} is also the logical not operator in C, history expansion
15135is off by default. If you decide to enable history expansion with the
15136@code{set history expansion on} command, you may sometimes need to
15137follow @kbd{!} (when it is used as logical not, in an expression) with
15138a space or a tab to prevent it from being expanded. The readline
15139history facilities do not attempt substitution on the strings
15140@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
15141
15142The commands to control history expansion are:
104c1213
JM
15143
15144@table @code
8e04817f
AC
15145@item set history expansion on
15146@itemx set history expansion
703663ab 15147@kindex set history expansion
8e04817f 15148Enable history expansion. History expansion is off by default.
104c1213 15149
8e04817f
AC
15150@item set history expansion off
15151Disable history expansion.
104c1213 15152
8e04817f
AC
15153@c @group
15154@kindex show history
15155@item show history
15156@itemx show history filename
15157@itemx show history save
15158@itemx show history size
15159@itemx show history expansion
15160These commands display the state of the @value{GDBN} history parameters.
15161@code{show history} by itself displays all four states.
15162@c @end group
15163@end table
15164
15165@table @code
9c16f35a
EZ
15166@kindex show commands
15167@cindex show last commands
15168@cindex display command history
8e04817f
AC
15169@item show commands
15170Display the last ten commands in the command history.
104c1213 15171
8e04817f
AC
15172@item show commands @var{n}
15173Print ten commands centered on command number @var{n}.
15174
15175@item show commands +
15176Print ten commands just after the commands last printed.
104c1213
JM
15177@end table
15178
8e04817f
AC
15179@node Screen Size
15180@section Screen size
15181@cindex size of screen
15182@cindex pauses in output
104c1213 15183
8e04817f
AC
15184Certain commands to @value{GDBN} may produce large amounts of
15185information output to the screen. To help you read all of it,
15186@value{GDBN} pauses and asks you for input at the end of each page of
15187output. Type @key{RET} when you want to continue the output, or @kbd{q}
15188to discard the remaining output. Also, the screen width setting
15189determines when to wrap lines of output. Depending on what is being
15190printed, @value{GDBN} tries to break the line at a readable place,
15191rather than simply letting it overflow onto the following line.
15192
15193Normally @value{GDBN} knows the size of the screen from the terminal
15194driver software. For example, on Unix @value{GDBN} uses the termcap data base
15195together with the value of the @code{TERM} environment variable and the
15196@code{stty rows} and @code{stty cols} settings. If this is not correct,
15197you can override it with the @code{set height} and @code{set
15198width} commands:
15199
15200@table @code
15201@kindex set height
15202@kindex set width
15203@kindex show width
15204@kindex show height
15205@item set height @var{lpp}
15206@itemx show height
15207@itemx set width @var{cpl}
15208@itemx show width
15209These @code{set} commands specify a screen height of @var{lpp} lines and
15210a screen width of @var{cpl} characters. The associated @code{show}
15211commands display the current settings.
104c1213 15212
8e04817f
AC
15213If you specify a height of zero lines, @value{GDBN} does not pause during
15214output no matter how long the output is. This is useful if output is to a
15215file or to an editor buffer.
104c1213 15216
8e04817f
AC
15217Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
15218from wrapping its output.
9c16f35a
EZ
15219
15220@item set pagination on
15221@itemx set pagination off
15222@kindex set pagination
15223Turn the output pagination on or off; the default is on. Turning
15224pagination off is the alternative to @code{set height 0}.
15225
15226@item show pagination
15227@kindex show pagination
15228Show the current pagination mode.
104c1213
JM
15229@end table
15230
8e04817f
AC
15231@node Numbers
15232@section Numbers
15233@cindex number representation
15234@cindex entering numbers
104c1213 15235
8e04817f
AC
15236You can always enter numbers in octal, decimal, or hexadecimal in
15237@value{GDBN} by the usual conventions: octal numbers begin with
15238@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
15239begin with @samp{0x}. Numbers that neither begin with @samp{0} or
15240@samp{0x}, nor end with a @samp{.} are, by default, entered in base
1524110; likewise, the default display for numbers---when no particular
15242format is specified---is base 10. You can change the default base for
15243both input and output with the commands described below.
104c1213 15244
8e04817f
AC
15245@table @code
15246@kindex set input-radix
15247@item set input-radix @var{base}
15248Set the default base for numeric input. Supported choices
15249for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15250specified either unambiguously or using the current input radix; for
8e04817f 15251example, any of
104c1213 15252
8e04817f 15253@smallexample
9c16f35a
EZ
15254set input-radix 012
15255set input-radix 10.
15256set input-radix 0xa
8e04817f 15257@end smallexample
104c1213 15258
8e04817f 15259@noindent
9c16f35a 15260sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
15261leaves the input radix unchanged, no matter what it was, since
15262@samp{10}, being without any leading or trailing signs of its base, is
15263interpreted in the current radix. Thus, if the current radix is 16,
15264@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
15265change the radix.
104c1213 15266
8e04817f
AC
15267@kindex set output-radix
15268@item set output-radix @var{base}
15269Set the default base for numeric display. Supported choices
15270for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15271specified either unambiguously or using the current input radix.
104c1213 15272
8e04817f
AC
15273@kindex show input-radix
15274@item show input-radix
15275Display the current default base for numeric input.
104c1213 15276
8e04817f
AC
15277@kindex show output-radix
15278@item show output-radix
15279Display the current default base for numeric display.
9c16f35a
EZ
15280
15281@item set radix @r{[}@var{base}@r{]}
15282@itemx show radix
15283@kindex set radix
15284@kindex show radix
15285These commands set and show the default base for both input and output
15286of numbers. @code{set radix} sets the radix of input and output to
15287the same base; without an argument, it resets the radix back to its
15288default value of 10.
15289
8e04817f 15290@end table
104c1213 15291
1e698235
DJ
15292@node ABI
15293@section Configuring the current ABI
15294
15295@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
15296application automatically. However, sometimes you need to override its
15297conclusions. Use these commands to manage @value{GDBN}'s view of the
15298current ABI.
15299
98b45e30
DJ
15300@cindex OS ABI
15301@kindex set osabi
b4e9345d 15302@kindex show osabi
98b45e30
DJ
15303
15304One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 15305system targets, either via remote debugging or native emulation.
98b45e30
DJ
15306@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
15307but you can override its conclusion using the @code{set osabi} command.
15308One example where this is useful is in debugging of binaries which use
15309an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
15310not have the same identifying marks that the standard C library for your
15311platform provides.
15312
15313@table @code
15314@item show osabi
15315Show the OS ABI currently in use.
15316
15317@item set osabi
15318With no argument, show the list of registered available OS ABI's.
15319
15320@item set osabi @var{abi}
15321Set the current OS ABI to @var{abi}.
15322@end table
15323
1e698235 15324@cindex float promotion
1e698235
DJ
15325
15326Generally, the way that an argument of type @code{float} is passed to a
15327function depends on whether the function is prototyped. For a prototyped
15328(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
15329according to the architecture's convention for @code{float}. For unprototyped
15330(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
15331@code{double} and then passed.
15332
15333Unfortunately, some forms of debug information do not reliably indicate whether
15334a function is prototyped. If @value{GDBN} calls a function that is not marked
15335as prototyped, it consults @kbd{set coerce-float-to-double}.
15336
15337@table @code
a8f24a35 15338@kindex set coerce-float-to-double
1e698235
DJ
15339@item set coerce-float-to-double
15340@itemx set coerce-float-to-double on
15341Arguments of type @code{float} will be promoted to @code{double} when passed
15342to an unprototyped function. This is the default setting.
15343
15344@item set coerce-float-to-double off
15345Arguments of type @code{float} will be passed directly to unprototyped
15346functions.
9c16f35a
EZ
15347
15348@kindex show coerce-float-to-double
15349@item show coerce-float-to-double
15350Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
15351@end table
15352
f1212245
DJ
15353@kindex set cp-abi
15354@kindex show cp-abi
15355@value{GDBN} needs to know the ABI used for your program's C@t{++}
15356objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
15357used to build your application. @value{GDBN} only fully supports
15358programs with a single C@t{++} ABI; if your program contains code using
15359multiple C@t{++} ABI's or if @value{GDBN} can not identify your
15360program's ABI correctly, you can tell @value{GDBN} which ABI to use.
15361Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
15362before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
15363``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
15364use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
15365``auto''.
15366
15367@table @code
15368@item show cp-abi
15369Show the C@t{++} ABI currently in use.
15370
15371@item set cp-abi
15372With no argument, show the list of supported C@t{++} ABI's.
15373
15374@item set cp-abi @var{abi}
15375@itemx set cp-abi auto
15376Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
15377@end table
15378
8e04817f
AC
15379@node Messages/Warnings
15380@section Optional warnings and messages
104c1213 15381
9c16f35a
EZ
15382@cindex verbose operation
15383@cindex optional warnings
8e04817f
AC
15384By default, @value{GDBN} is silent about its inner workings. If you are
15385running on a slow machine, you may want to use the @code{set verbose}
15386command. This makes @value{GDBN} tell you when it does a lengthy
15387internal operation, so you will not think it has crashed.
104c1213 15388
8e04817f
AC
15389Currently, the messages controlled by @code{set verbose} are those
15390which announce that the symbol table for a source file is being read;
15391see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 15392
8e04817f
AC
15393@table @code
15394@kindex set verbose
15395@item set verbose on
15396Enables @value{GDBN} output of certain informational messages.
104c1213 15397
8e04817f
AC
15398@item set verbose off
15399Disables @value{GDBN} output of certain informational messages.
104c1213 15400
8e04817f
AC
15401@kindex show verbose
15402@item show verbose
15403Displays whether @code{set verbose} is on or off.
15404@end table
104c1213 15405
8e04817f
AC
15406By default, if @value{GDBN} encounters bugs in the symbol table of an
15407object file, it is silent; but if you are debugging a compiler, you may
15408find this information useful (@pxref{Symbol Errors, ,Errors reading
15409symbol files}).
104c1213 15410
8e04817f 15411@table @code
104c1213 15412
8e04817f
AC
15413@kindex set complaints
15414@item set complaints @var{limit}
15415Permits @value{GDBN} to output @var{limit} complaints about each type of
15416unusual symbols before becoming silent about the problem. Set
15417@var{limit} to zero to suppress all complaints; set it to a large number
15418to prevent complaints from being suppressed.
104c1213 15419
8e04817f
AC
15420@kindex show complaints
15421@item show complaints
15422Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 15423
8e04817f 15424@end table
104c1213 15425
8e04817f
AC
15426By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
15427lot of stupid questions to confirm certain commands. For example, if
15428you try to run a program which is already running:
104c1213 15429
474c8240 15430@smallexample
8e04817f
AC
15431(@value{GDBP}) run
15432The program being debugged has been started already.
15433Start it from the beginning? (y or n)
474c8240 15434@end smallexample
104c1213 15435
8e04817f
AC
15436If you are willing to unflinchingly face the consequences of your own
15437commands, you can disable this ``feature'':
104c1213 15438
8e04817f 15439@table @code
104c1213 15440
8e04817f
AC
15441@kindex set confirm
15442@cindex flinching
15443@cindex confirmation
15444@cindex stupid questions
15445@item set confirm off
15446Disables confirmation requests.
104c1213 15447
8e04817f
AC
15448@item set confirm on
15449Enables confirmation requests (the default).
104c1213 15450
8e04817f
AC
15451@kindex show confirm
15452@item show confirm
15453Displays state of confirmation requests.
15454
15455@end table
104c1213 15456
8e04817f
AC
15457@node Debugging Output
15458@section Optional messages about internal happenings
4644b6e3
EZ
15459@cindex optional debugging messages
15460
da316a69
EZ
15461@value{GDBN} has commands that enable optional debugging messages from
15462various @value{GDBN} subsystems; normally these commands are of
15463interest to @value{GDBN} maintainers, or when reporting a bug. This
15464section documents those commands.
15465
104c1213 15466@table @code
a8f24a35
EZ
15467@kindex set exec-done-display
15468@item set exec-done-display
15469Turns on or off the notification of asynchronous commands'
15470completion. When on, @value{GDBN} will print a message when an
15471asynchronous command finishes its execution. The default is off.
15472@kindex show exec-done-display
15473@item show exec-done-display
15474Displays the current setting of asynchronous command completion
15475notification.
4644b6e3
EZ
15476@kindex set debug
15477@cindex gdbarch debugging info
a8f24a35 15478@cindex architecture debugging info
8e04817f 15479@item set debug arch
a8f24a35 15480Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 15481@kindex show debug
8e04817f
AC
15482@item show debug arch
15483Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
15484@item set debug aix-thread
15485@cindex AIX threads
15486Display debugging messages about inner workings of the AIX thread
15487module.
15488@item show debug aix-thread
15489Show the current state of AIX thread debugging info display.
8e04817f 15490@item set debug event
4644b6e3 15491@cindex event debugging info
a8f24a35 15492Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 15493default is off.
8e04817f
AC
15494@item show debug event
15495Displays the current state of displaying @value{GDBN} event debugging
15496info.
8e04817f 15497@item set debug expression
4644b6e3 15498@cindex expression debugging info
721c2651
EZ
15499Turns on or off display of debugging info about @value{GDBN}
15500expression parsing. The default is off.
8e04817f 15501@item show debug expression
721c2651
EZ
15502Displays the current state of displaying debugging info about
15503@value{GDBN} expression parsing.
7453dc06 15504@item set debug frame
4644b6e3 15505@cindex frame debugging info
7453dc06
AC
15506Turns on or off display of @value{GDBN} frame debugging info. The
15507default is off.
7453dc06
AC
15508@item show debug frame
15509Displays the current state of displaying @value{GDBN} frame debugging
15510info.
30e91e0b
RC
15511@item set debug infrun
15512@cindex inferior debugging info
15513Turns on or off display of @value{GDBN} debugging info for running the inferior.
15514The default is off. @file{infrun.c} contains GDB's runtime state machine used
15515for implementing operations such as single-stepping the inferior.
15516@item show debug infrun
15517Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
15518@item set debug lin-lwp
15519@cindex @sc{gnu}/Linux LWP debug messages
15520@cindex Linux lightweight processes
721c2651 15521Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
15522@item show debug lin-lwp
15523Show the current state of Linux LWP debugging messages.
2b4855ab 15524@item set debug observer
4644b6e3 15525@cindex observer debugging info
2b4855ab
AC
15526Turns on or off display of @value{GDBN} observer debugging. This
15527includes info such as the notification of observable events.
2b4855ab
AC
15528@item show debug observer
15529Displays the current state of observer debugging.
8e04817f 15530@item set debug overload
4644b6e3 15531@cindex C@t{++} overload debugging info
8e04817f
AC
15532Turns on or off display of @value{GDBN} C@t{++} overload debugging
15533info. This includes info such as ranking of functions, etc. The default
15534is off.
8e04817f
AC
15535@item show debug overload
15536Displays the current state of displaying @value{GDBN} C@t{++} overload
15537debugging info.
8e04817f
AC
15538@cindex packets, reporting on stdout
15539@cindex serial connections, debugging
15540@item set debug remote
15541Turns on or off display of reports on all packets sent back and forth across
15542the serial line to the remote machine. The info is printed on the
15543@value{GDBN} standard output stream. The default is off.
8e04817f
AC
15544@item show debug remote
15545Displays the state of display of remote packets.
8e04817f
AC
15546@item set debug serial
15547Turns on or off display of @value{GDBN} serial debugging info. The
15548default is off.
8e04817f
AC
15549@item show debug serial
15550Displays the current state of displaying @value{GDBN} serial debugging
15551info.
c45da7e6
EZ
15552@item set debug solib-frv
15553@cindex FR-V shared-library debugging
15554Turns on or off debugging messages for FR-V shared-library code.
15555@item show debug solib-frv
15556Display the current state of FR-V shared-library code debugging
15557messages.
8e04817f 15558@item set debug target
4644b6e3 15559@cindex target debugging info
8e04817f
AC
15560Turns on or off display of @value{GDBN} target debugging info. This info
15561includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
15562default is 0. Set it to 1 to track events, and to 2 to also track the
15563value of large memory transfers. Changes to this flag do not take effect
15564until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
15565@item show debug target
15566Displays the current state of displaying @value{GDBN} target debugging
15567info.
c45da7e6 15568@item set debugvarobj
4644b6e3 15569@cindex variable object debugging info
8e04817f
AC
15570Turns on or off display of @value{GDBN} variable object debugging
15571info. The default is off.
c45da7e6 15572@item show debugvarobj
8e04817f
AC
15573Displays the current state of displaying @value{GDBN} variable object
15574debugging info.
15575@end table
104c1213 15576
8e04817f
AC
15577@node Sequences
15578@chapter Canned Sequences of Commands
104c1213 15579
8e04817f
AC
15580Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
15581command lists}), @value{GDBN} provides two ways to store sequences of
15582commands for execution as a unit: user-defined commands and command
15583files.
104c1213 15584
8e04817f
AC
15585@menu
15586* Define:: User-defined commands
15587* Hooks:: User-defined command hooks
15588* Command Files:: Command files
15589* Output:: Commands for controlled output
15590@end menu
104c1213 15591
8e04817f
AC
15592@node Define
15593@section User-defined commands
104c1213 15594
8e04817f
AC
15595@cindex user-defined command
15596A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
15597which you assign a new name as a command. This is done with the
15598@code{define} command. User commands may accept up to 10 arguments
15599separated by whitespace. Arguments are accessed within the user command
15600via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 15601
8e04817f
AC
15602@smallexample
15603define adder
15604 print $arg0 + $arg1 + $arg2
15605@end smallexample
104c1213
JM
15606
15607@noindent
8e04817f 15608To execute the command use:
104c1213 15609
8e04817f
AC
15610@smallexample
15611adder 1 2 3
15612@end smallexample
104c1213 15613
8e04817f
AC
15614@noindent
15615This defines the command @code{adder}, which prints the sum of
15616its three arguments. Note the arguments are text substitutions, so they may
15617reference variables, use complex expressions, or even perform inferior
15618functions calls.
104c1213
JM
15619
15620@table @code
104c1213 15621
8e04817f
AC
15622@kindex define
15623@item define @var{commandname}
15624Define a command named @var{commandname}. If there is already a command
15625by that name, you are asked to confirm that you want to redefine it.
104c1213 15626
8e04817f
AC
15627The definition of the command is made up of other @value{GDBN} command lines,
15628which are given following the @code{define} command. The end of these
15629commands is marked by a line containing @code{end}.
104c1213 15630
8e04817f
AC
15631@kindex if
15632@kindex else
15633@item if
09d4efe1 15634@itemx else
8e04817f
AC
15635Takes a single argument, which is an expression to evaluate.
15636It is followed by a series of commands that are executed
15637only if the expression is true (nonzero).
15638There can then optionally be a line @code{else}, followed
15639by a series of commands that are only executed if the expression
15640was false. The end of the list is marked by a line containing @code{end}.
104c1213 15641
8e04817f
AC
15642@kindex while
15643@item while
15644The syntax is similar to @code{if}: the command takes a single argument,
15645which is an expression to evaluate, and must be followed by the commands to
15646execute, one per line, terminated by an @code{end}.
15647The commands are executed repeatedly as long as the expression
15648evaluates to true.
104c1213 15649
8e04817f
AC
15650@kindex document
15651@item document @var{commandname}
15652Document the user-defined command @var{commandname}, so that it can be
15653accessed by @code{help}. The command @var{commandname} must already be
15654defined. This command reads lines of documentation just as @code{define}
15655reads the lines of the command definition, ending with @code{end}.
15656After the @code{document} command is finished, @code{help} on command
15657@var{commandname} displays the documentation you have written.
104c1213 15658
8e04817f
AC
15659You may use the @code{document} command again to change the
15660documentation of a command. Redefining the command with @code{define}
15661does not change the documentation.
104c1213 15662
c45da7e6
EZ
15663@kindex dont-repeat
15664@cindex don't repeat command
15665@item dont-repeat
15666Used inside a user-defined command, this tells @value{GDBN} that this
15667command should not be repeated when the user hits @key{RET}
15668(@pxref{Command Syntax, repeat last command}).
15669
8e04817f
AC
15670@kindex help user-defined
15671@item help user-defined
15672List all user-defined commands, with the first line of the documentation
15673(if any) for each.
104c1213 15674
8e04817f
AC
15675@kindex show user
15676@item show user
15677@itemx show user @var{commandname}
15678Display the @value{GDBN} commands used to define @var{commandname} (but
15679not its documentation). If no @var{commandname} is given, display the
15680definitions for all user-defined commands.
104c1213 15681
9c16f35a 15682@cindex infinite recusrion in user-defined commands
20f01a46
DH
15683@kindex show max-user-call-depth
15684@kindex set max-user-call-depth
15685@item show max-user-call-depth
5ca0cb28
DH
15686@itemx set max-user-call-depth
15687The value of @code{max-user-call-depth} controls how many recursion
15688levels are allowed in user-defined commands before GDB suspects an
15689infinite recursion and aborts the command.
20f01a46 15690
104c1213
JM
15691@end table
15692
8e04817f
AC
15693When user-defined commands are executed, the
15694commands of the definition are not printed. An error in any command
15695stops execution of the user-defined command.
104c1213 15696
8e04817f
AC
15697If used interactively, commands that would ask for confirmation proceed
15698without asking when used inside a user-defined command. Many @value{GDBN}
15699commands that normally print messages to say what they are doing omit the
15700messages when used in a user-defined command.
104c1213 15701
8e04817f
AC
15702@node Hooks
15703@section User-defined command hooks
15704@cindex command hooks
15705@cindex hooks, for commands
15706@cindex hooks, pre-command
104c1213 15707
8e04817f 15708@kindex hook
8e04817f
AC
15709You may define @dfn{hooks}, which are a special kind of user-defined
15710command. Whenever you run the command @samp{foo}, if the user-defined
15711command @samp{hook-foo} exists, it is executed (with no arguments)
15712before that command.
104c1213 15713
8e04817f
AC
15714@cindex hooks, post-command
15715@kindex hookpost
8e04817f
AC
15716A hook may also be defined which is run after the command you executed.
15717Whenever you run the command @samp{foo}, if the user-defined command
15718@samp{hookpost-foo} exists, it is executed (with no arguments) after
15719that command. Post-execution hooks may exist simultaneously with
15720pre-execution hooks, for the same command.
104c1213 15721
8e04817f 15722It is valid for a hook to call the command which it hooks. If this
9f1c6395 15723occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 15724
8e04817f
AC
15725@c It would be nice if hookpost could be passed a parameter indicating
15726@c if the command it hooks executed properly or not. FIXME!
104c1213 15727
8e04817f
AC
15728@kindex stop@r{, a pseudo-command}
15729In addition, a pseudo-command, @samp{stop} exists. Defining
15730(@samp{hook-stop}) makes the associated commands execute every time
15731execution stops in your program: before breakpoint commands are run,
15732displays are printed, or the stack frame is printed.
104c1213 15733
8e04817f
AC
15734For example, to ignore @code{SIGALRM} signals while
15735single-stepping, but treat them normally during normal execution,
15736you could define:
104c1213 15737
474c8240 15738@smallexample
8e04817f
AC
15739define hook-stop
15740handle SIGALRM nopass
15741end
104c1213 15742
8e04817f
AC
15743define hook-run
15744handle SIGALRM pass
15745end
104c1213 15746
8e04817f
AC
15747define hook-continue
15748handle SIGLARM pass
15749end
474c8240 15750@end smallexample
104c1213 15751
8e04817f 15752As a further example, to hook at the begining and end of the @code{echo}
b383017d 15753command, and to add extra text to the beginning and end of the message,
8e04817f 15754you could define:
104c1213 15755
474c8240 15756@smallexample
8e04817f
AC
15757define hook-echo
15758echo <<<---
15759end
104c1213 15760
8e04817f
AC
15761define hookpost-echo
15762echo --->>>\n
15763end
104c1213 15764
8e04817f
AC
15765(@value{GDBP}) echo Hello World
15766<<<---Hello World--->>>
15767(@value{GDBP})
104c1213 15768
474c8240 15769@end smallexample
104c1213 15770
8e04817f
AC
15771You can define a hook for any single-word command in @value{GDBN}, but
15772not for command aliases; you should define a hook for the basic command
15773name, e.g. @code{backtrace} rather than @code{bt}.
15774@c FIXME! So how does Joe User discover whether a command is an alias
15775@c or not?
15776If an error occurs during the execution of your hook, execution of
15777@value{GDBN} commands stops and @value{GDBN} issues a prompt
15778(before the command that you actually typed had a chance to run).
104c1213 15779
8e04817f
AC
15780If you try to define a hook which does not match any known command, you
15781get a warning from the @code{define} command.
c906108c 15782
8e04817f
AC
15783@node Command Files
15784@section Command files
c906108c 15785
8e04817f 15786@cindex command files
6fc08d32
EZ
15787A command file for @value{GDBN} is a text file made of lines that are
15788@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
15789also be included. An empty line in a command file does nothing; it
15790does not mean to repeat the last command, as it would from the
15791terminal.
c906108c 15792
6fc08d32
EZ
15793You can request the execution of a command file with the @code{source}
15794command:
c906108c 15795
8e04817f
AC
15796@table @code
15797@kindex source
15798@item source @var{filename}
15799Execute the command file @var{filename}.
c906108c
SS
15800@end table
15801
8e04817f 15802The lines in a command file are executed sequentially. They are not
a71ec265
DH
15803printed as they are executed. An error in any command terminates
15804execution of the command file and control is returned to the console.
c906108c 15805
8e04817f
AC
15806Commands that would ask for confirmation if used interactively proceed
15807without asking when used in a command file. Many @value{GDBN} commands that
15808normally print messages to say what they are doing omit the messages
15809when called from command files.
c906108c 15810
8e04817f
AC
15811@value{GDBN} also accepts command input from standard input. In this
15812mode, normal output goes to standard output and error output goes to
15813standard error. Errors in a command file supplied on standard input do
6fc08d32 15814not terminate execution of the command file---execution continues with
8e04817f 15815the next command.
c906108c 15816
474c8240 15817@smallexample
8e04817f 15818gdb < cmds > log 2>&1
474c8240 15819@end smallexample
c906108c 15820
8e04817f
AC
15821(The syntax above will vary depending on the shell used.) This example
15822will execute commands from the file @file{cmds}. All output and errors
15823would be directed to @file{log}.
c906108c 15824
8e04817f
AC
15825@node Output
15826@section Commands for controlled output
c906108c 15827
8e04817f
AC
15828During the execution of a command file or a user-defined command, normal
15829@value{GDBN} output is suppressed; the only output that appears is what is
15830explicitly printed by the commands in the definition. This section
15831describes three commands useful for generating exactly the output you
15832want.
c906108c
SS
15833
15834@table @code
8e04817f
AC
15835@kindex echo
15836@item echo @var{text}
15837@c I do not consider backslash-space a standard C escape sequence
15838@c because it is not in ANSI.
15839Print @var{text}. Nonprinting characters can be included in
15840@var{text} using C escape sequences, such as @samp{\n} to print a
15841newline. @strong{No newline is printed unless you specify one.}
15842In addition to the standard C escape sequences, a backslash followed
15843by a space stands for a space. This is useful for displaying a
15844string with spaces at the beginning or the end, since leading and
15845trailing spaces are otherwise trimmed from all arguments.
15846To print @samp{@w{ }and foo =@w{ }}, use the command
15847@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 15848
8e04817f
AC
15849A backslash at the end of @var{text} can be used, as in C, to continue
15850the command onto subsequent lines. For example,
c906108c 15851
474c8240 15852@smallexample
8e04817f
AC
15853echo This is some text\n\
15854which is continued\n\
15855onto several lines.\n
474c8240 15856@end smallexample
c906108c 15857
8e04817f 15858produces the same output as
c906108c 15859
474c8240 15860@smallexample
8e04817f
AC
15861echo This is some text\n
15862echo which is continued\n
15863echo onto several lines.\n
474c8240 15864@end smallexample
c906108c 15865
8e04817f
AC
15866@kindex output
15867@item output @var{expression}
15868Print the value of @var{expression} and nothing but that value: no
15869newlines, no @samp{$@var{nn} = }. The value is not entered in the
15870value history either. @xref{Expressions, ,Expressions}, for more information
15871on expressions.
c906108c 15872
8e04817f
AC
15873@item output/@var{fmt} @var{expression}
15874Print the value of @var{expression} in format @var{fmt}. You can use
15875the same formats as for @code{print}. @xref{Output Formats,,Output
15876formats}, for more information.
c906108c 15877
8e04817f
AC
15878@kindex printf
15879@item printf @var{string}, @var{expressions}@dots{}
15880Print the values of the @var{expressions} under the control of
15881@var{string}. The @var{expressions} are separated by commas and may be
15882either numbers or pointers. Their values are printed as specified by
15883@var{string}, exactly as if your program were to execute the C
15884subroutine
15885@c FIXME: the above implies that at least all ANSI C formats are
15886@c supported, but it isn't true: %E and %G don't work (or so it seems).
15887@c Either this is a bug, or the manual should document what formats are
15888@c supported.
c906108c 15889
474c8240 15890@smallexample
8e04817f 15891printf (@var{string}, @var{expressions}@dots{});
474c8240 15892@end smallexample
c906108c 15893
8e04817f 15894For example, you can print two values in hex like this:
c906108c 15895
8e04817f
AC
15896@smallexample
15897printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
15898@end smallexample
c906108c 15899
8e04817f
AC
15900The only backslash-escape sequences that you can use in the format
15901string are the simple ones that consist of backslash followed by a
15902letter.
c906108c
SS
15903@end table
15904
21c294e6
AC
15905@node Interpreters
15906@chapter Command Interpreters
15907@cindex command interpreters
15908
15909@value{GDBN} supports multiple command interpreters, and some command
15910infrastructure to allow users or user interface writers to switch
15911between interpreters or run commands in other interpreters.
15912
15913@value{GDBN} currently supports two command interpreters, the console
15914interpreter (sometimes called the command-line interpreter or @sc{cli})
15915and the machine interface interpreter (or @sc{gdb/mi}). This manual
15916describes both of these interfaces in great detail.
15917
15918By default, @value{GDBN} will start with the console interpreter.
15919However, the user may choose to start @value{GDBN} with another
15920interpreter by specifying the @option{-i} or @option{--interpreter}
15921startup options. Defined interpreters include:
15922
15923@table @code
15924@item console
15925@cindex console interpreter
15926The traditional console or command-line interpreter. This is the most often
15927used interpreter with @value{GDBN}. With no interpreter specified at runtime,
15928@value{GDBN} will use this interpreter.
15929
15930@item mi
15931@cindex mi interpreter
15932The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
15933by programs wishing to use @value{GDBN} as a backend for a debugger GUI
15934or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
15935Interface}.
15936
15937@item mi2
15938@cindex mi2 interpreter
15939The current @sc{gdb/mi} interface.
15940
15941@item mi1
15942@cindex mi1 interpreter
15943The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
15944
15945@end table
15946
15947@cindex invoke another interpreter
15948The interpreter being used by @value{GDBN} may not be dynamically
15949switched at runtime. Although possible, this could lead to a very
15950precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
15951enters the command "interpreter-set console" in a console view,
15952@value{GDBN} would switch to using the console interpreter, rendering
15953the IDE inoperable!
15954
15955@kindex interpreter-exec
15956Although you may only choose a single interpreter at startup, you may execute
15957commands in any interpreter from the current interpreter using the appropriate
15958command. If you are running the console interpreter, simply use the
15959@code{interpreter-exec} command:
15960
15961@smallexample
15962interpreter-exec mi "-data-list-register-names"
15963@end smallexample
15964
15965@sc{gdb/mi} has a similar command, although it is only available in versions of
15966@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
15967
8e04817f
AC
15968@node TUI
15969@chapter @value{GDBN} Text User Interface
15970@cindex TUI
d0d5df6f 15971@cindex Text User Interface
c906108c 15972
8e04817f
AC
15973@menu
15974* TUI Overview:: TUI overview
15975* TUI Keys:: TUI key bindings
7cf36c78 15976* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
15977* TUI Commands:: TUI specific commands
15978* TUI Configuration:: TUI configuration variables
15979@end menu
c906108c 15980
d0d5df6f
AC
15981The @value{GDBN} Text User Interface, TUI in short, is a terminal
15982interface which uses the @code{curses} library to show the source
15983file, the assembly output, the program registers and @value{GDBN}
15984commands in separate text windows.
15985
15986The TUI is enabled by invoking @value{GDBN} using either
15987@pindex gdbtui
15988@samp{gdbtui} or @samp{gdb -tui}.
c906108c 15989
8e04817f
AC
15990@node TUI Overview
15991@section TUI overview
c906108c 15992
8e04817f
AC
15993The TUI has two display modes that can be switched while
15994@value{GDBN} runs:
c906108c 15995
8e04817f
AC
15996@itemize @bullet
15997@item
15998A curses (or TUI) mode in which it displays several text
15999windows on the terminal.
c906108c 16000
8e04817f
AC
16001@item
16002A standard mode which corresponds to the @value{GDBN} configured without
16003the TUI.
16004@end itemize
c906108c 16005
8e04817f
AC
16006In the TUI mode, @value{GDBN} can display several text window
16007on the terminal:
c906108c 16008
8e04817f
AC
16009@table @emph
16010@item command
16011This window is the @value{GDBN} command window with the @value{GDBN}
16012prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
16013managed using readline but through the TUI. The @emph{command}
16014window is always visible.
c906108c 16015
8e04817f
AC
16016@item source
16017The source window shows the source file of the program. The current
16018line as well as active breakpoints are displayed in this window.
c906108c 16019
8e04817f
AC
16020@item assembly
16021The assembly window shows the disassembly output of the program.
c906108c 16022
8e04817f
AC
16023@item register
16024This window shows the processor registers. It detects when
16025a register is changed and when this is the case, registers that have
6a1b180d 16026changed are highlighted.
c906108c 16027
c906108c
SS
16028@end table
16029
269c21fe
SC
16030The source and assembly windows show the current program position
16031by highlighting the current line and marking them with the @samp{>} marker.
16032Breakpoints are also indicated with two markers. A first one
16033indicates the breakpoint type:
16034
16035@table @code
16036@item B
16037Breakpoint which was hit at least once.
16038
16039@item b
16040Breakpoint which was never hit.
16041
16042@item H
16043Hardware breakpoint which was hit at least once.
16044
16045@item h
16046Hardware breakpoint which was never hit.
16047
16048@end table
16049
16050The second marker indicates whether the breakpoint is enabled or not:
16051
16052@table @code
16053@item +
16054Breakpoint is enabled.
16055
16056@item -
16057Breakpoint is disabled.
16058
16059@end table
16060
8e04817f
AC
16061The source, assembly and register windows are attached to the thread
16062and the frame position. They are updated when the current thread
16063changes, when the frame changes or when the program counter changes.
16064These three windows are arranged by the TUI according to several
16065layouts. The layout defines which of these three windows are visible.
16066The following layouts are available:
c906108c 16067
8e04817f
AC
16068@itemize @bullet
16069@item
16070source
2df3850c 16071
8e04817f
AC
16072@item
16073assembly
16074
16075@item
16076source and assembly
16077
16078@item
16079source and registers
c906108c 16080
8e04817f
AC
16081@item
16082assembly and registers
2df3850c 16083
8e04817f 16084@end itemize
c906108c 16085
b7bb15bc
SC
16086On top of the command window a status line gives various information
16087concerning the current process begin debugged. The status line is
16088updated when the information it shows changes. The following fields
16089are displayed:
16090
16091@table @emph
16092@item target
16093Indicates the current gdb target
16094(@pxref{Targets, ,Specifying a Debugging Target}).
16095
16096@item process
16097Gives information about the current process or thread number.
16098When no process is being debugged, this field is set to @code{No process}.
16099
16100@item function
16101Gives the current function name for the selected frame.
16102The name is demangled if demangling is turned on (@pxref{Print Settings}).
16103When there is no symbol corresponding to the current program counter
16104the string @code{??} is displayed.
16105
16106@item line
16107Indicates the current line number for the selected frame.
16108When the current line number is not known the string @code{??} is displayed.
16109
16110@item pc
16111Indicates the current program counter address.
16112
16113@end table
16114
8e04817f
AC
16115@node TUI Keys
16116@section TUI Key Bindings
16117@cindex TUI key bindings
c906108c 16118
8e04817f
AC
16119The TUI installs several key bindings in the readline keymaps
16120(@pxref{Command Line Editing}).
16121They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
16122directly on the TUI layout and windows. The TUI also provides
16123a @emph{SingleKey} keymap which binds several keys directly to
16124@value{GDBN} commands. The following key bindings
8e04817f 16125are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 16126
8e04817f
AC
16127@table @kbd
16128@kindex C-x C-a
16129@item C-x C-a
16130@kindex C-x a
16131@itemx C-x a
16132@kindex C-x A
16133@itemx C-x A
16134Enter or leave the TUI mode. When the TUI mode is left,
16135the curses window management is left and @value{GDBN} operates using
16136its standard mode writing on the terminal directly. When the TUI
16137mode is entered, the control is given back to the curses windows.
16138The screen is then refreshed.
c906108c 16139
8e04817f
AC
16140@kindex C-x 1
16141@item C-x 1
16142Use a TUI layout with only one window. The layout will
16143either be @samp{source} or @samp{assembly}. When the TUI mode
16144is not active, it will switch to the TUI mode.
2df3850c 16145
8e04817f 16146Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 16147
8e04817f
AC
16148@kindex C-x 2
16149@item C-x 2
16150Use a TUI layout with at least two windows. When the current
16151layout shows already two windows, a next layout with two windows is used.
16152When a new layout is chosen, one window will always be common to the
16153previous layout and the new one.
c906108c 16154
8e04817f 16155Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 16156
72ffddc9
SC
16157@kindex C-x o
16158@item C-x o
16159Change the active window. The TUI associates several key bindings
16160(like scrolling and arrow keys) to the active window. This command
16161gives the focus to the next TUI window.
16162
16163Think of it as the Emacs @kbd{C-x o} binding.
16164
7cf36c78
SC
16165@kindex C-x s
16166@item C-x s
16167Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
16168(@pxref{TUI Single Key Mode}).
16169
c906108c
SS
16170@end table
16171
8e04817f 16172The following key bindings are handled only by the TUI mode:
5d161b24 16173
8e04817f
AC
16174@table @key
16175@kindex PgUp
16176@item PgUp
16177Scroll the active window one page up.
c906108c 16178
8e04817f
AC
16179@kindex PgDn
16180@item PgDn
16181Scroll the active window one page down.
c906108c 16182
8e04817f
AC
16183@kindex Up
16184@item Up
16185Scroll the active window one line up.
c906108c 16186
8e04817f
AC
16187@kindex Down
16188@item Down
16189Scroll the active window one line down.
c906108c 16190
8e04817f
AC
16191@kindex Left
16192@item Left
16193Scroll the active window one column left.
c906108c 16194
8e04817f
AC
16195@kindex Right
16196@item Right
16197Scroll the active window one column right.
c906108c 16198
8e04817f
AC
16199@kindex C-L
16200@item C-L
16201Refresh the screen.
c906108c 16202
8e04817f 16203@end table
c906108c 16204
8e04817f 16205In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
16206for scrolling. This means they are available for readline when the
16207active window is the command window. When the command window
16208does not have the focus, it is necessary to use other readline
16209key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 16210
7cf36c78
SC
16211@node TUI Single Key Mode
16212@section TUI Single Key Mode
16213@cindex TUI single key mode
16214
16215The TUI provides a @emph{SingleKey} mode in which it installs a particular
16216key binding in the readline keymaps to connect single keys to
b383017d 16217some gdb commands.
7cf36c78
SC
16218
16219@table @kbd
16220@kindex c @r{(SingleKey TUI key)}
16221@item c
16222continue
16223
16224@kindex d @r{(SingleKey TUI key)}
16225@item d
16226down
16227
16228@kindex f @r{(SingleKey TUI key)}
16229@item f
16230finish
16231
16232@kindex n @r{(SingleKey TUI key)}
16233@item n
16234next
16235
16236@kindex q @r{(SingleKey TUI key)}
16237@item q
16238exit the @emph{SingleKey} mode.
16239
16240@kindex r @r{(SingleKey TUI key)}
16241@item r
16242run
16243
16244@kindex s @r{(SingleKey TUI key)}
16245@item s
16246step
16247
16248@kindex u @r{(SingleKey TUI key)}
16249@item u
16250up
16251
16252@kindex v @r{(SingleKey TUI key)}
16253@item v
16254info locals
16255
16256@kindex w @r{(SingleKey TUI key)}
16257@item w
16258where
16259
16260@end table
16261
16262Other keys temporarily switch to the @value{GDBN} command prompt.
16263The key that was pressed is inserted in the editing buffer so that
16264it is possible to type most @value{GDBN} commands without interaction
16265with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
16266@emph{SingleKey} mode is restored. The only way to permanently leave
16267this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
16268
16269
8e04817f
AC
16270@node TUI Commands
16271@section TUI specific commands
16272@cindex TUI commands
16273
16274The TUI has specific commands to control the text windows.
16275These commands are always available, that is they do not depend on
16276the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
16277is in the standard mode, using these commands will automatically switch
16278in the TUI mode.
c906108c
SS
16279
16280@table @code
3d757584
SC
16281@item info win
16282@kindex info win
16283List and give the size of all displayed windows.
16284
8e04817f 16285@item layout next
4644b6e3 16286@kindex layout
8e04817f 16287Display the next layout.
2df3850c 16288
8e04817f 16289@item layout prev
8e04817f 16290Display the previous layout.
c906108c 16291
8e04817f 16292@item layout src
8e04817f 16293Display the source window only.
c906108c 16294
8e04817f 16295@item layout asm
8e04817f 16296Display the assembly window only.
c906108c 16297
8e04817f 16298@item layout split
8e04817f 16299Display the source and assembly window.
c906108c 16300
8e04817f 16301@item layout regs
8e04817f
AC
16302Display the register window together with the source or assembly window.
16303
16304@item focus next | prev | src | asm | regs | split
16305@kindex focus
16306Set the focus to the named window.
16307This command allows to change the active window so that scrolling keys
16308can be affected to another window.
c906108c 16309
8e04817f
AC
16310@item refresh
16311@kindex refresh
16312Refresh the screen. This is similar to using @key{C-L} key.
c906108c 16313
6a1b180d
SC
16314@item tui reg float
16315@kindex tui reg
16316Show the floating point registers in the register window.
16317
16318@item tui reg general
16319Show the general registers in the register window.
16320
16321@item tui reg next
16322Show the next register group. The list of register groups as well as
16323their order is target specific. The predefined register groups are the
16324following: @code{general}, @code{float}, @code{system}, @code{vector},
16325@code{all}, @code{save}, @code{restore}.
16326
16327@item tui reg system
16328Show the system registers in the register window.
16329
8e04817f
AC
16330@item update
16331@kindex update
16332Update the source window and the current execution point.
c906108c 16333
8e04817f
AC
16334@item winheight @var{name} +@var{count}
16335@itemx winheight @var{name} -@var{count}
16336@kindex winheight
16337Change the height of the window @var{name} by @var{count}
16338lines. Positive counts increase the height, while negative counts
16339decrease it.
2df3850c 16340
c45da7e6
EZ
16341@item tabset
16342@kindex tabset @var{nchars}
16343Set the width of tab stops to be @var{nchars} characters.
16344
c906108c
SS
16345@end table
16346
8e04817f
AC
16347@node TUI Configuration
16348@section TUI configuration variables
16349@cindex TUI configuration variables
c906108c 16350
8e04817f
AC
16351The TUI has several configuration variables that control the
16352appearance of windows on the terminal.
c906108c 16353
8e04817f
AC
16354@table @code
16355@item set tui border-kind @var{kind}
16356@kindex set tui border-kind
16357Select the border appearance for the source, assembly and register windows.
16358The possible values are the following:
16359@table @code
16360@item space
16361Use a space character to draw the border.
c906108c 16362
8e04817f
AC
16363@item ascii
16364Use ascii characters + - and | to draw the border.
c906108c 16365
8e04817f
AC
16366@item acs
16367Use the Alternate Character Set to draw the border. The border is
16368drawn using character line graphics if the terminal supports them.
c78b4128 16369
8e04817f 16370@end table
c78b4128 16371
8e04817f
AC
16372@item set tui active-border-mode @var{mode}
16373@kindex set tui active-border-mode
16374Select the attributes to display the border of the active window.
16375The possible values are @code{normal}, @code{standout}, @code{reverse},
16376@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 16377
8e04817f
AC
16378@item set tui border-mode @var{mode}
16379@kindex set tui border-mode
16380Select the attributes to display the border of other windows.
16381The @var{mode} can be one of the following:
16382@table @code
16383@item normal
16384Use normal attributes to display the border.
c906108c 16385
8e04817f
AC
16386@item standout
16387Use standout mode.
c906108c 16388
8e04817f
AC
16389@item reverse
16390Use reverse video mode.
c906108c 16391
8e04817f
AC
16392@item half
16393Use half bright mode.
c906108c 16394
8e04817f
AC
16395@item half-standout
16396Use half bright and standout mode.
c906108c 16397
8e04817f
AC
16398@item bold
16399Use extra bright or bold mode.
c78b4128 16400
8e04817f
AC
16401@item bold-standout
16402Use extra bright or bold and standout mode.
c78b4128 16403
8e04817f 16404@end table
c78b4128 16405
8e04817f 16406@end table
c78b4128 16407
8e04817f
AC
16408@node Emacs
16409@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 16410
8e04817f
AC
16411@cindex Emacs
16412@cindex @sc{gnu} Emacs
16413A special interface allows you to use @sc{gnu} Emacs to view (and
16414edit) the source files for the program you are debugging with
16415@value{GDBN}.
c906108c 16416
8e04817f
AC
16417To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
16418executable file you want to debug as an argument. This command starts
16419@value{GDBN} as a subprocess of Emacs, with input and output through a newly
16420created Emacs buffer.
16421@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 16422
8e04817f
AC
16423Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
16424things:
c906108c 16425
8e04817f
AC
16426@itemize @bullet
16427@item
16428All ``terminal'' input and output goes through the Emacs buffer.
16429@end itemize
c906108c 16430
8e04817f
AC
16431This applies both to @value{GDBN} commands and their output, and to the input
16432and output done by the program you are debugging.
bf0184be 16433
8e04817f
AC
16434This is useful because it means that you can copy the text of previous
16435commands and input them again; you can even use parts of the output
16436in this way.
bf0184be 16437
8e04817f
AC
16438All the facilities of Emacs' Shell mode are available for interacting
16439with your program. In particular, you can send signals the usual
16440way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
16441stop.
bf0184be 16442
8e04817f 16443@itemize @bullet
bf0184be 16444@item
8e04817f
AC
16445@value{GDBN} displays source code through Emacs.
16446@end itemize
bf0184be 16447
8e04817f
AC
16448Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
16449source file for that frame and puts an arrow (@samp{=>}) at the
16450left margin of the current line. Emacs uses a separate buffer for
16451source display, and splits the screen to show both your @value{GDBN} session
16452and the source.
bf0184be 16453
8e04817f
AC
16454Explicit @value{GDBN} @code{list} or search commands still produce output as
16455usual, but you probably have no reason to use them from Emacs.
c906108c 16456
64fabec2
AC
16457If you specify an absolute file name when prompted for the @kbd{M-x
16458gdb} argument, then Emacs sets your current working directory to where
16459your program resides. If you only specify the file name, then Emacs
16460sets your current working directory to to the directory associated
16461with the previous buffer. In this case, @value{GDBN} may find your
16462program by searching your environment's @code{PATH} variable, but on
16463some operating systems it might not find the source. So, although the
16464@value{GDBN} input and output session proceeds normally, the auxiliary
16465buffer does not display the current source and line of execution.
16466
16467The initial working directory of @value{GDBN} is printed on the top
16468line of the @value{GDBN} I/O buffer and this serves as a default for
16469the commands that specify files for @value{GDBN} to operate
16470on. @xref{Files, ,Commands to specify files}.
16471
16472By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
16473need to call @value{GDBN} by a different name (for example, if you
16474keep several configurations around, with different names) you can
16475customize the Emacs variable @code{gud-gdb-command-name} to run the
16476one you want.
8e04817f
AC
16477
16478In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
16479addition to the standard Shell mode commands:
c906108c 16480
8e04817f
AC
16481@table @kbd
16482@item C-h m
16483Describe the features of Emacs' @value{GDBN} Mode.
c906108c 16484
64fabec2 16485@item C-c C-s
8e04817f
AC
16486Execute to another source line, like the @value{GDBN} @code{step} command; also
16487update the display window to show the current file and location.
c906108c 16488
64fabec2 16489@item C-c C-n
8e04817f
AC
16490Execute to next source line in this function, skipping all function
16491calls, like the @value{GDBN} @code{next} command. Then update the display window
16492to show the current file and location.
c906108c 16493
64fabec2 16494@item C-c C-i
8e04817f
AC
16495Execute one instruction, like the @value{GDBN} @code{stepi} command; update
16496display window accordingly.
c906108c 16497
8e04817f
AC
16498@item C-c C-f
16499Execute until exit from the selected stack frame, like the @value{GDBN}
16500@code{finish} command.
c906108c 16501
64fabec2 16502@item C-c C-r
8e04817f
AC
16503Continue execution of your program, like the @value{GDBN} @code{continue}
16504command.
b433d00b 16505
64fabec2 16506@item C-c <
8e04817f
AC
16507Go up the number of frames indicated by the numeric argument
16508(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
16509like the @value{GDBN} @code{up} command.
b433d00b 16510
64fabec2 16511@item C-c >
8e04817f
AC
16512Go down the number of frames indicated by the numeric argument, like the
16513@value{GDBN} @code{down} command.
8e04817f 16514@end table
c906108c 16515
64fabec2 16516In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 16517tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 16518
64fabec2
AC
16519If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
16520shows a backtrace when the @value{GDBN} I/O buffer is current. Move
16521point to any frame in the stack and type @key{RET} to make it become the
16522current frame and display the associated source in the source buffer.
16523Alternatively, click @kbd{Mouse-2} to make the selected frame become the
16524current one.
16525
8e04817f
AC
16526If you accidentally delete the source-display buffer, an easy way to get
16527it back is to type the command @code{f} in the @value{GDBN} buffer, to
16528request a frame display; when you run under Emacs, this recreates
16529the source buffer if necessary to show you the context of the current
16530frame.
c906108c 16531
8e04817f
AC
16532The source files displayed in Emacs are in ordinary Emacs buffers
16533which are visiting the source files in the usual way. You can edit
16534the files with these buffers if you wish; but keep in mind that @value{GDBN}
16535communicates with Emacs in terms of line numbers. If you add or
16536delete lines from the text, the line numbers that @value{GDBN} knows cease
16537to correspond properly with the code.
b383017d 16538
64fabec2
AC
16539The description given here is for GNU Emacs version 21.3 and a more
16540detailed description of its interaction with @value{GDBN} is given in
16541the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 16542
8e04817f
AC
16543@c The following dropped because Epoch is nonstandard. Reactivate
16544@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
16545@ignore
16546@kindex Emacs Epoch environment
16547@kindex Epoch
16548@kindex inspect
c906108c 16549
8e04817f
AC
16550Version 18 of @sc{gnu} Emacs has a built-in window system
16551called the @code{epoch}
16552environment. Users of this environment can use a new command,
16553@code{inspect} which performs identically to @code{print} except that
16554each value is printed in its own window.
16555@end ignore
c906108c 16556
922fbb7b
AC
16557
16558@node GDB/MI
16559@chapter The @sc{gdb/mi} Interface
16560
16561@unnumberedsec Function and Purpose
16562
16563@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
16564@sc{gdb/mi} is a line based machine oriented text interface to
16565@value{GDBN} and is activated by specifying using the
16566@option{--interpreter} command line option (@pxref{Mode Options}). It
16567is specifically intended to support the development of systems which
16568use the debugger as just one small component of a larger system.
922fbb7b
AC
16569
16570This chapter is a specification of the @sc{gdb/mi} interface. It is written
16571in the form of a reference manual.
16572
16573Note that @sc{gdb/mi} is still under construction, so some of the
16574features described below are incomplete and subject to change.
16575
16576@unnumberedsec Notation and Terminology
16577
16578@cindex notational conventions, for @sc{gdb/mi}
16579This chapter uses the following notation:
16580
16581@itemize @bullet
16582@item
16583@code{|} separates two alternatives.
16584
16585@item
16586@code{[ @var{something} ]} indicates that @var{something} is optional:
16587it may or may not be given.
16588
16589@item
16590@code{( @var{group} )*} means that @var{group} inside the parentheses
16591may repeat zero or more times.
16592
16593@item
16594@code{( @var{group} )+} means that @var{group} inside the parentheses
16595may repeat one or more times.
16596
16597@item
16598@code{"@var{string}"} means a literal @var{string}.
16599@end itemize
16600
16601@ignore
16602@heading Dependencies
16603@end ignore
16604
16605@heading Acknowledgments
16606
16607In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
16608Elena Zannoni.
16609
16610@menu
16611* GDB/MI Command Syntax::
16612* GDB/MI Compatibility with CLI::
16613* GDB/MI Output Records::
16614* GDB/MI Command Description Format::
16615* GDB/MI Breakpoint Table Commands::
16616* GDB/MI Data Manipulation::
16617* GDB/MI Program Control::
16618* GDB/MI Miscellaneous Commands::
16619@ignore
16620* GDB/MI Kod Commands::
16621* GDB/MI Memory Overlay Commands::
16622* GDB/MI Signal Handling Commands::
16623@end ignore
16624* GDB/MI Stack Manipulation::
16625* GDB/MI Symbol Query::
16626* GDB/MI Target Manipulation::
16627* GDB/MI Thread Commands::
16628* GDB/MI Tracepoint Commands::
16629* GDB/MI Variable Objects::
16630@end menu
16631
16632@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16633@node GDB/MI Command Syntax
16634@section @sc{gdb/mi} Command Syntax
16635
16636@menu
16637* GDB/MI Input Syntax::
16638* GDB/MI Output Syntax::
16639* GDB/MI Simple Examples::
16640@end menu
16641
16642@node GDB/MI Input Syntax
16643@subsection @sc{gdb/mi} Input Syntax
16644
16645@cindex input syntax for @sc{gdb/mi}
16646@cindex @sc{gdb/mi}, input syntax
16647@table @code
16648@item @var{command} @expansion{}
16649@code{@var{cli-command} | @var{mi-command}}
16650
16651@item @var{cli-command} @expansion{}
16652@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
16653@var{cli-command} is any existing @value{GDBN} CLI command.
16654
16655@item @var{mi-command} @expansion{}
16656@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
16657@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
16658
16659@item @var{token} @expansion{}
16660"any sequence of digits"
16661
16662@item @var{option} @expansion{}
16663@code{"-" @var{parameter} [ " " @var{parameter} ]}
16664
16665@item @var{parameter} @expansion{}
16666@code{@var{non-blank-sequence} | @var{c-string}}
16667
16668@item @var{operation} @expansion{}
16669@emph{any of the operations described in this chapter}
16670
16671@item @var{non-blank-sequence} @expansion{}
16672@emph{anything, provided it doesn't contain special characters such as
16673"-", @var{nl}, """ and of course " "}
16674
16675@item @var{c-string} @expansion{}
16676@code{""" @var{seven-bit-iso-c-string-content} """}
16677
16678@item @var{nl} @expansion{}
16679@code{CR | CR-LF}
16680@end table
16681
16682@noindent
16683Notes:
16684
16685@itemize @bullet
16686@item
16687The CLI commands are still handled by the @sc{mi} interpreter; their
16688output is described below.
16689
16690@item
16691The @code{@var{token}}, when present, is passed back when the command
16692finishes.
16693
16694@item
16695Some @sc{mi} commands accept optional arguments as part of the parameter
16696list. Each option is identified by a leading @samp{-} (dash) and may be
16697followed by an optional argument parameter. Options occur first in the
16698parameter list and can be delimited from normal parameters using
16699@samp{--} (this is useful when some parameters begin with a dash).
16700@end itemize
16701
16702Pragmatics:
16703
16704@itemize @bullet
16705@item
16706We want easy access to the existing CLI syntax (for debugging).
16707
16708@item
16709We want it to be easy to spot a @sc{mi} operation.
16710@end itemize
16711
16712@node GDB/MI Output Syntax
16713@subsection @sc{gdb/mi} Output Syntax
16714
16715@cindex output syntax of @sc{gdb/mi}
16716@cindex @sc{gdb/mi}, output syntax
16717The output from @sc{gdb/mi} consists of zero or more out-of-band records
16718followed, optionally, by a single result record. This result record
16719is for the most recent command. The sequence of output records is
16720terminated by @samp{(@value{GDBP})}.
16721
16722If an input command was prefixed with a @code{@var{token}} then the
16723corresponding output for that command will also be prefixed by that same
16724@var{token}.
16725
16726@table @code
16727@item @var{output} @expansion{}
f7dc1244 16728@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
922fbb7b
AC
16729
16730@item @var{result-record} @expansion{}
16731@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
16732
16733@item @var{out-of-band-record} @expansion{}
16734@code{@var{async-record} | @var{stream-record}}
16735
16736@item @var{async-record} @expansion{}
16737@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
16738
16739@item @var{exec-async-output} @expansion{}
16740@code{[ @var{token} ] "*" @var{async-output}}
16741
16742@item @var{status-async-output} @expansion{}
16743@code{[ @var{token} ] "+" @var{async-output}}
16744
16745@item @var{notify-async-output} @expansion{}
16746@code{[ @var{token} ] "=" @var{async-output}}
16747
16748@item @var{async-output} @expansion{}
16749@code{@var{async-class} ( "," @var{result} )* @var{nl}}
16750
16751@item @var{result-class} @expansion{}
16752@code{"done" | "running" | "connected" | "error" | "exit"}
16753
16754@item @var{async-class} @expansion{}
16755@code{"stopped" | @var{others}} (where @var{others} will be added
16756depending on the needs---this is still in development).
16757
16758@item @var{result} @expansion{}
16759@code{ @var{variable} "=" @var{value}}
16760
16761@item @var{variable} @expansion{}
16762@code{ @var{string} }
16763
16764@item @var{value} @expansion{}
16765@code{ @var{const} | @var{tuple} | @var{list} }
16766
16767@item @var{const} @expansion{}
16768@code{@var{c-string}}
16769
16770@item @var{tuple} @expansion{}
16771@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
16772
16773@item @var{list} @expansion{}
16774@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
16775@var{result} ( "," @var{result} )* "]" }
16776
16777@item @var{stream-record} @expansion{}
16778@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
16779
16780@item @var{console-stream-output} @expansion{}
16781@code{"~" @var{c-string}}
16782
16783@item @var{target-stream-output} @expansion{}
16784@code{"@@" @var{c-string}}
16785
16786@item @var{log-stream-output} @expansion{}
16787@code{"&" @var{c-string}}
16788
16789@item @var{nl} @expansion{}
16790@code{CR | CR-LF}
16791
16792@item @var{token} @expansion{}
16793@emph{any sequence of digits}.
16794@end table
16795
16796@noindent
16797Notes:
16798
16799@itemize @bullet
16800@item
16801All output sequences end in a single line containing a period.
16802
16803@item
16804The @code{@var{token}} is from the corresponding request. If an execution
16805command is interrupted by the @samp{-exec-interrupt} command, the
16806@var{token} associated with the @samp{*stopped} message is the one of the
16807original execution command, not the one of the interrupt command.
16808
16809@item
16810@cindex status output in @sc{gdb/mi}
16811@var{status-async-output} contains on-going status information about the
16812progress of a slow operation. It can be discarded. All status output is
16813prefixed by @samp{+}.
16814
16815@item
16816@cindex async output in @sc{gdb/mi}
16817@var{exec-async-output} contains asynchronous state change on the target
16818(stopped, started, disappeared). All async output is prefixed by
16819@samp{*}.
16820
16821@item
16822@cindex notify output in @sc{gdb/mi}
16823@var{notify-async-output} contains supplementary information that the
16824client should handle (e.g., a new breakpoint information). All notify
16825output is prefixed by @samp{=}.
16826
16827@item
16828@cindex console output in @sc{gdb/mi}
16829@var{console-stream-output} is output that should be displayed as is in the
16830console. It is the textual response to a CLI command. All the console
16831output is prefixed by @samp{~}.
16832
16833@item
16834@cindex target output in @sc{gdb/mi}
16835@var{target-stream-output} is the output produced by the target program.
16836All the target output is prefixed by @samp{@@}.
16837
16838@item
16839@cindex log output in @sc{gdb/mi}
16840@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
16841instance messages that should be displayed as part of an error log. All
16842the log output is prefixed by @samp{&}.
16843
16844@item
16845@cindex list output in @sc{gdb/mi}
16846New @sc{gdb/mi} commands should only output @var{lists} containing
16847@var{values}.
16848
16849
16850@end itemize
16851
16852@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
16853details about the various output records.
16854
16855@node GDB/MI Simple Examples
16856@subsection Simple Examples of @sc{gdb/mi} Interaction
16857@cindex @sc{gdb/mi}, simple examples
16858
16859This subsection presents several simple examples of interaction using
16860the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
16861following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
16862the output received from @sc{gdb/mi}.
16863
16864@subsubheading Target Stop
16865@c Ummm... There is no "-stop" command. This assumes async, no?
16866Here's an example of stopping the inferior process:
16867
16868@smallexample
16869-> -stop
16870<- (@value{GDBP})
16871@end smallexample
16872
16873@noindent
16874and later:
16875
16876@smallexample
16877<- *stop,reason="stop",address="0x123",source="a.c:123"
16878<- (@value{GDBP})
16879@end smallexample
16880
16881@subsubheading Simple CLI Command
16882
16883Here's an example of a simple CLI command being passed through
16884@sc{gdb/mi} and on to the CLI.
16885
16886@smallexample
16887-> print 1+2
16888<- &"print 1+2\n"
16889<- ~"$1 = 3\n"
16890<- ^done
16891<- (@value{GDBP})
16892@end smallexample
16893
16894@subsubheading Command With Side Effects
16895
16896@smallexample
16897-> -symbol-file xyz.exe
16898<- *breakpoint,nr="3",address="0x123",source="a.c:123"
16899<- (@value{GDBP})
16900@end smallexample
16901
16902@subsubheading A Bad Command
16903
16904Here's what happens if you pass a non-existent command:
16905
16906@smallexample
16907-> -rubbish
16908<- ^error,msg="Undefined MI command: rubbish"
16909<- (@value{GDBP})
16910@end smallexample
16911
16912@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16913@node GDB/MI Compatibility with CLI
16914@section @sc{gdb/mi} Compatibility with CLI
16915
16916@cindex compatibility, @sc{gdb/mi} and CLI
16917@cindex @sc{gdb/mi}, compatibility with CLI
16918To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
16919accepts existing CLI commands. As specified by the syntax, such
16920commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
16921respond.
16922
16923This mechanism is provided as an aid to developers of @sc{gdb/mi}
16924clients and not as a reliable interface into the CLI. Since the command
16925is being interpreteted in an environment that assumes @sc{gdb/mi}
16926behaviour, the exact output of such commands is likely to end up being
16927an un-supported hybrid of @sc{gdb/mi} and CLI output.
16928
16929@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16930@node GDB/MI Output Records
16931@section @sc{gdb/mi} Output Records
16932
16933@menu
16934* GDB/MI Result Records::
16935* GDB/MI Stream Records::
16936* GDB/MI Out-of-band Records::
16937@end menu
16938
16939@node GDB/MI Result Records
16940@subsection @sc{gdb/mi} Result Records
16941
16942@cindex result records in @sc{gdb/mi}
16943@cindex @sc{gdb/mi}, result records
16944In addition to a number of out-of-band notifications, the response to a
16945@sc{gdb/mi} command includes one of the following result indications:
16946
16947@table @code
16948@findex ^done
16949@item "^done" [ "," @var{results} ]
16950The synchronous operation was successful, @code{@var{results}} are the return
16951values.
16952
16953@item "^running"
16954@findex ^running
16955@c Is this one correct? Should it be an out-of-band notification?
16956The asynchronous operation was successfully started. The target is
16957running.
16958
16959@item "^error" "," @var{c-string}
16960@findex ^error
16961The operation failed. The @code{@var{c-string}} contains the corresponding
16962error message.
16963@end table
16964
16965@node GDB/MI Stream Records
16966@subsection @sc{gdb/mi} Stream Records
16967
16968@cindex @sc{gdb/mi}, stream records
16969@cindex stream records in @sc{gdb/mi}
16970@value{GDBN} internally maintains a number of output streams: the console, the
16971target, and the log. The output intended for each of these streams is
16972funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
16973
16974Each stream record begins with a unique @dfn{prefix character} which
16975identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
16976Syntax}). In addition to the prefix, each stream record contains a
16977@code{@var{string-output}}. This is either raw text (with an implicit new
16978line) or a quoted C string (which does not contain an implicit newline).
16979
16980@table @code
16981@item "~" @var{string-output}
16982The console output stream contains text that should be displayed in the
16983CLI console window. It contains the textual responses to CLI commands.
16984
16985@item "@@" @var{string-output}
16986The target output stream contains any textual output from the running
16987target.
16988
16989@item "&" @var{string-output}
16990The log stream contains debugging messages being produced by @value{GDBN}'s
16991internals.
16992@end table
16993
16994@node GDB/MI Out-of-band Records
16995@subsection @sc{gdb/mi} Out-of-band Records
16996
16997@cindex out-of-band records in @sc{gdb/mi}
16998@cindex @sc{gdb/mi}, out-of-band records
16999@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
17000additional changes that have occurred. Those changes can either be a
17001consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
17002target activity (e.g., target stopped).
17003
17004The following is a preliminary list of possible out-of-band records.
034dad6f 17005In particular, the @var{exec-async-output} records.
922fbb7b
AC
17006
17007@table @code
034dad6f
BR
17008@item *stopped,reason="@var{reason}"
17009@end table
17010
17011@var{reason} can be one of the following:
17012
17013@table @code
17014@item breakpoint-hit
17015A breakpoint was reached.
17016@item watchpoint-trigger
17017A watchpoint was triggered.
17018@item read-watchpoint-trigger
17019A read watchpoint was triggered.
17020@item access-watchpoint-trigger
17021An access watchpoint was triggered.
17022@item function-finished
17023An -exec-finish or similar CLI command was accomplished.
17024@item location-reached
17025An -exec-until or similar CLI command was accomplished.
17026@item watchpoint-scope
17027A watchpoint has gone out of scope.
17028@item end-stepping-range
17029An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
17030similar CLI command was accomplished.
17031@item exited-signalled
17032The inferior exited because of a signal.
17033@item exited
17034The inferior exited.
17035@item exited-normally
17036The inferior exited normally.
17037@item signal-received
17038A signal was received by the inferior.
922fbb7b
AC
17039@end table
17040
17041
17042@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17043@node GDB/MI Command Description Format
17044@section @sc{gdb/mi} Command Description Format
17045
17046The remaining sections describe blocks of commands. Each block of
17047commands is laid out in a fashion similar to this section.
17048
17049Note the the line breaks shown in the examples are here only for
17050readability. They don't appear in the real output.
17051Also note that the commands with a non-available example (N.A.@:) are
17052not yet implemented.
17053
17054@subheading Motivation
17055
17056The motivation for this collection of commands.
17057
17058@subheading Introduction
17059
17060A brief introduction to this collection of commands as a whole.
17061
17062@subheading Commands
17063
17064For each command in the block, the following is described:
17065
17066@subsubheading Synopsis
17067
17068@smallexample
17069 -command @var{args}@dots{}
17070@end smallexample
17071
17072@subsubheading @value{GDBN} Command
17073
17074The corresponding @value{GDBN} CLI command.
17075
17076@subsubheading Result
17077
17078@subsubheading Out-of-band
17079
17080@subsubheading Notes
17081
17082@subsubheading Example
17083
17084
17085@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17086@node GDB/MI Breakpoint Table Commands
17087@section @sc{gdb/mi} Breakpoint table commands
17088
17089@cindex breakpoint commands for @sc{gdb/mi}
17090@cindex @sc{gdb/mi}, breakpoint commands
17091This section documents @sc{gdb/mi} commands for manipulating
17092breakpoints.
17093
17094@subheading The @code{-break-after} Command
17095@findex -break-after
17096
17097@subsubheading Synopsis
17098
17099@smallexample
17100 -break-after @var{number} @var{count}
17101@end smallexample
17102
17103The breakpoint number @var{number} is not in effect until it has been
17104hit @var{count} times. To see how this is reflected in the output of
17105the @samp{-break-list} command, see the description of the
17106@samp{-break-list} command below.
17107
17108@subsubheading @value{GDBN} Command
17109
17110The corresponding @value{GDBN} command is @samp{ignore}.
17111
17112@subsubheading Example
17113
17114@smallexample
17115(@value{GDBP})
17116-break-insert main
17117^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
17118(@value{GDBP})
17119-break-after 1 3
17120~
17121^done
17122(@value{GDBP})
17123-break-list
17124^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17125hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17126@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17127@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17128@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17129@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17130@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17131body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17132addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
17133ignore="3"@}]@}
17134(@value{GDBP})
17135@end smallexample
17136
17137@ignore
17138@subheading The @code{-break-catch} Command
17139@findex -break-catch
17140
17141@subheading The @code{-break-commands} Command
17142@findex -break-commands
17143@end ignore
17144
17145
17146@subheading The @code{-break-condition} Command
17147@findex -break-condition
17148
17149@subsubheading Synopsis
17150
17151@smallexample
17152 -break-condition @var{number} @var{expr}
17153@end smallexample
17154
17155Breakpoint @var{number} will stop the program only if the condition in
17156@var{expr} is true. The condition becomes part of the
17157@samp{-break-list} output (see the description of the @samp{-break-list}
17158command below).
17159
17160@subsubheading @value{GDBN} Command
17161
17162The corresponding @value{GDBN} command is @samp{condition}.
17163
17164@subsubheading Example
17165
17166@smallexample
17167(@value{GDBP})
17168-break-condition 1 1
17169^done
17170(@value{GDBP})
17171-break-list
17172^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17173hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17174@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17175@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17176@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17177@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17178@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17179body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17180addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
17181times="0",ignore="3"@}]@}
17182(@value{GDBP})
17183@end smallexample
17184
17185@subheading The @code{-break-delete} Command
17186@findex -break-delete
17187
17188@subsubheading Synopsis
17189
17190@smallexample
17191 -break-delete ( @var{breakpoint} )+
17192@end smallexample
17193
17194Delete the breakpoint(s) whose number(s) are specified in the argument
17195list. This is obviously reflected in the breakpoint list.
17196
17197@subsubheading @value{GDBN} command
17198
17199The corresponding @value{GDBN} command is @samp{delete}.
17200
17201@subsubheading Example
17202
17203@smallexample
17204(@value{GDBP})
17205-break-delete 1
17206^done
17207(@value{GDBP})
17208-break-list
17209^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17210hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17211@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17212@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17213@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17214@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17215@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17216body=[]@}
17217(@value{GDBP})
17218@end smallexample
17219
17220@subheading The @code{-break-disable} Command
17221@findex -break-disable
17222
17223@subsubheading Synopsis
17224
17225@smallexample
17226 -break-disable ( @var{breakpoint} )+
17227@end smallexample
17228
17229Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
17230break list is now set to @samp{n} for the named @var{breakpoint}(s).
17231
17232@subsubheading @value{GDBN} Command
17233
17234The corresponding @value{GDBN} command is @samp{disable}.
17235
17236@subsubheading Example
17237
17238@smallexample
17239(@value{GDBP})
17240-break-disable 2
17241^done
17242(@value{GDBP})
17243-break-list
17244^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17245hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17246@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17247@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17248@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17249@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17250@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17251body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
17252addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17253(@value{GDBP})
17254@end smallexample
17255
17256@subheading The @code{-break-enable} Command
17257@findex -break-enable
17258
17259@subsubheading Synopsis
17260
17261@smallexample
17262 -break-enable ( @var{breakpoint} )+
17263@end smallexample
17264
17265Enable (previously disabled) @var{breakpoint}(s).
17266
17267@subsubheading @value{GDBN} Command
17268
17269The corresponding @value{GDBN} command is @samp{enable}.
17270
17271@subsubheading Example
17272
17273@smallexample
17274(@value{GDBP})
17275-break-enable 2
17276^done
17277(@value{GDBP})
17278-break-list
17279^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17280hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17281@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17282@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17283@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17284@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17285@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17286body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17287addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17288(@value{GDBP})
17289@end smallexample
17290
17291@subheading The @code{-break-info} Command
17292@findex -break-info
17293
17294@subsubheading Synopsis
17295
17296@smallexample
17297 -break-info @var{breakpoint}
17298@end smallexample
17299
17300@c REDUNDANT???
17301Get information about a single breakpoint.
17302
17303@subsubheading @value{GDBN} command
17304
17305The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
17306
17307@subsubheading Example
17308N.A.
17309
17310@subheading The @code{-break-insert} Command
17311@findex -break-insert
17312
17313@subsubheading Synopsis
17314
17315@smallexample
17316 -break-insert [ -t ] [ -h ] [ -r ]
17317 [ -c @var{condition} ] [ -i @var{ignore-count} ]
17318 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
17319@end smallexample
17320
17321@noindent
17322If specified, @var{line}, can be one of:
17323
17324@itemize @bullet
17325@item function
17326@c @item +offset
17327@c @item -offset
17328@c @item linenum
17329@item filename:linenum
17330@item filename:function
17331@item *address
17332@end itemize
17333
17334The possible optional parameters of this command are:
17335
17336@table @samp
17337@item -t
17338Insert a tempoary breakpoint.
17339@item -h
17340Insert a hardware breakpoint.
17341@item -c @var{condition}
17342Make the breakpoint conditional on @var{condition}.
17343@item -i @var{ignore-count}
17344Initialize the @var{ignore-count}.
17345@item -r
17346Insert a regular breakpoint in all the functions whose names match the
17347given regular expression. Other flags are not applicable to regular
17348expresson.
17349@end table
17350
17351@subsubheading Result
17352
17353The result is in the form:
17354
17355@smallexample
17356 ^done,bkptno="@var{number}",func="@var{funcname}",
17357 file="@var{filename}",line="@var{lineno}"
17358@end smallexample
17359
17360@noindent
17361where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
17362is the name of the function where the breakpoint was inserted,
17363@var{filename} is the name of the source file which contains this
17364function, and @var{lineno} is the source line number within that file.
17365
17366Note: this format is open to change.
17367@c An out-of-band breakpoint instead of part of the result?
17368
17369@subsubheading @value{GDBN} Command
17370
17371The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
17372@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
17373
17374@subsubheading Example
17375
17376@smallexample
17377(@value{GDBP})
17378-break-insert main
17379^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17380(@value{GDBP})
17381-break-insert -t foo
17382^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
17383(@value{GDBP})
17384-break-list
17385^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17386hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17387@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17388@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17389@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17390@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17391@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17392body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17393addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
17394bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
17395addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
17396(@value{GDBP})
17397-break-insert -r foo.*
17398~int foo(int, int);
17399^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
17400(@value{GDBP})
17401@end smallexample
17402
17403@subheading The @code{-break-list} Command
17404@findex -break-list
17405
17406@subsubheading Synopsis
17407
17408@smallexample
17409 -break-list
17410@end smallexample
17411
17412Displays the list of inserted breakpoints, showing the following fields:
17413
17414@table @samp
17415@item Number
17416number of the breakpoint
17417@item Type
17418type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
17419@item Disposition
17420should the breakpoint be deleted or disabled when it is hit: @samp{keep}
17421or @samp{nokeep}
17422@item Enabled
17423is the breakpoint enabled or no: @samp{y} or @samp{n}
17424@item Address
17425memory location at which the breakpoint is set
17426@item What
17427logical location of the breakpoint, expressed by function name, file
17428name, line number
17429@item Times
17430number of times the breakpoint has been hit
17431@end table
17432
17433If there are no breakpoints or watchpoints, the @code{BreakpointTable}
17434@code{body} field is an empty list.
17435
17436@subsubheading @value{GDBN} Command
17437
17438The corresponding @value{GDBN} command is @samp{info break}.
17439
17440@subsubheading Example
17441
17442@smallexample
17443(@value{GDBP})
17444-break-list
17445^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17446hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17447@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17448@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17449@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17450@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17451@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17452body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17453addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
17454bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17455addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
17456(@value{GDBP})
17457@end smallexample
17458
17459Here's an example of the result when there are no breakpoints:
17460
17461@smallexample
17462(@value{GDBP})
17463-break-list
17464^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17465hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17466@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17467@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17468@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17469@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17470@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17471body=[]@}
17472(@value{GDBP})
17473@end smallexample
17474
17475@subheading The @code{-break-watch} Command
17476@findex -break-watch
17477
17478@subsubheading Synopsis
17479
17480@smallexample
17481 -break-watch [ -a | -r ]
17482@end smallexample
17483
17484Create a watchpoint. With the @samp{-a} option it will create an
17485@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
17486read from or on a write to the memory location. With the @samp{-r}
17487option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
17488trigger only when the memory location is accessed for reading. Without
17489either of the options, the watchpoint created is a regular watchpoint,
17490i.e. it will trigger when the memory location is accessed for writing.
17491@xref{Set Watchpoints, , Setting watchpoints}.
17492
17493Note that @samp{-break-list} will report a single list of watchpoints and
17494breakpoints inserted.
17495
17496@subsubheading @value{GDBN} Command
17497
17498The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
17499@samp{rwatch}.
17500
17501@subsubheading Example
17502
17503Setting a watchpoint on a variable in the @code{main} function:
17504
17505@smallexample
17506(@value{GDBP})
17507-break-watch x
17508^done,wpt=@{number="2",exp="x"@}
17509(@value{GDBP})
17510-exec-continue
17511^running
17512^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
17513value=@{old="-268439212",new="55"@},
76ff342d
DJ
17514frame=@{func="main",args=[],file="recursive2.c",
17515fullname="/home/foo/bar/devo/myproject/recursive2.c",line="5"@}
922fbb7b
AC
17516(@value{GDBP})
17517@end smallexample
17518
17519Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
17520the program execution twice: first for the variable changing value, then
17521for the watchpoint going out of scope.
17522
17523@smallexample
17524(@value{GDBP})
17525-break-watch C
17526^done,wpt=@{number="5",exp="C"@}
17527(@value{GDBP})
17528-exec-continue
17529^running
17530^done,reason="watchpoint-trigger",
17531wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
17532frame=@{func="callee4",args=[],
76ff342d
DJ
17533file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17534fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17535(@value{GDBP})
17536-exec-continue
17537^running
17538^done,reason="watchpoint-scope",wpnum="5",
17539frame=@{func="callee3",args=[@{name="strarg",
17540value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17541file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17542fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17543(@value{GDBP})
17544@end smallexample
17545
17546Listing breakpoints and watchpoints, at different points in the program
17547execution. Note that once the watchpoint goes out of scope, it is
17548deleted.
17549
17550@smallexample
17551(@value{GDBP})
17552-break-watch C
17553^done,wpt=@{number="2",exp="C"@}
17554(@value{GDBP})
17555-break-list
17556^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17557hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17558@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17559@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17560@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17561@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17562@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17563body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17564addr="0x00010734",func="callee4",
17565file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17566bkpt=@{number="2",type="watchpoint",disp="keep",
17567enabled="y",addr="",what="C",times="0"@}]@}
17568(@value{GDBP})
17569-exec-continue
17570^running
17571^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
17572value=@{old="-276895068",new="3"@},
17573frame=@{func="callee4",args=[],
76ff342d
DJ
17574file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17575fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17576(@value{GDBP})
17577-break-list
17578^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17579hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17580@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17581@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17582@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17583@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17584@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17585body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17586addr="0x00010734",func="callee4",
17587file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17588bkpt=@{number="2",type="watchpoint",disp="keep",
17589enabled="y",addr="",what="C",times="-5"@}]@}
17590(@value{GDBP})
17591-exec-continue
17592^running
17593^done,reason="watchpoint-scope",wpnum="2",
17594frame=@{func="callee3",args=[@{name="strarg",
17595value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17596file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17597fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17598(@value{GDBP})
17599-break-list
17600^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17601hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17602@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17603@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17604@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17605@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17606@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17607body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17608addr="0x00010734",func="callee4",
17609file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
17610(@value{GDBP})
17611@end smallexample
17612
17613@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17614@node GDB/MI Data Manipulation
17615@section @sc{gdb/mi} Data Manipulation
17616
17617@cindex data manipulation, in @sc{gdb/mi}
17618@cindex @sc{gdb/mi}, data manipulation
17619This section describes the @sc{gdb/mi} commands that manipulate data:
17620examine memory and registers, evaluate expressions, etc.
17621
17622@c REMOVED FROM THE INTERFACE.
17623@c @subheading -data-assign
17624@c Change the value of a program variable. Plenty of side effects.
17625@c @subsubheading GDB command
17626@c set variable
17627@c @subsubheading Example
17628@c N.A.
17629
17630@subheading The @code{-data-disassemble} Command
17631@findex -data-disassemble
17632
17633@subsubheading Synopsis
17634
17635@smallexample
17636 -data-disassemble
17637 [ -s @var{start-addr} -e @var{end-addr} ]
17638 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
17639 -- @var{mode}
17640@end smallexample
17641
17642@noindent
17643Where:
17644
17645@table @samp
17646@item @var{start-addr}
17647is the beginning address (or @code{$pc})
17648@item @var{end-addr}
17649is the end address
17650@item @var{filename}
17651is the name of the file to disassemble
17652@item @var{linenum}
17653is the line number to disassemble around
17654@item @var{lines}
17655is the the number of disassembly lines to be produced. If it is -1,
17656the whole function will be disassembled, in case no @var{end-addr} is
17657specified. If @var{end-addr} is specified as a non-zero value, and
17658@var{lines} is lower than the number of disassembly lines between
17659@var{start-addr} and @var{end-addr}, only @var{lines} lines are
17660displayed; if @var{lines} is higher than the number of lines between
17661@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
17662are displayed.
17663@item @var{mode}
17664is either 0 (meaning only disassembly) or 1 (meaning mixed source and
17665disassembly).
17666@end table
17667
17668@subsubheading Result
17669
17670The output for each instruction is composed of four fields:
17671
17672@itemize @bullet
17673@item Address
17674@item Func-name
17675@item Offset
17676@item Instruction
17677@end itemize
17678
17679Note that whatever included in the instruction field, is not manipulated
17680directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
17681
17682@subsubheading @value{GDBN} Command
17683
17684There's no direct mapping from this command to the CLI.
17685
17686@subsubheading Example
17687
17688Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
17689
17690@smallexample
17691(@value{GDBP})
17692-data-disassemble -s $pc -e "$pc + 20" -- 0
17693^done,
17694asm_insns=[
17695@{address="0x000107c0",func-name="main",offset="4",
17696inst="mov 2, %o0"@},
17697@{address="0x000107c4",func-name="main",offset="8",
17698inst="sethi %hi(0x11800), %o2"@},
17699@{address="0x000107c8",func-name="main",offset="12",
17700inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
17701@{address="0x000107cc",func-name="main",offset="16",
17702inst="sethi %hi(0x11800), %o2"@},
17703@{address="0x000107d0",func-name="main",offset="20",
17704inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
17705(@value{GDBP})
17706@end smallexample
17707
17708Disassemble the whole @code{main} function. Line 32 is part of
17709@code{main}.
17710
17711@smallexample
17712-data-disassemble -f basics.c -l 32 -- 0
17713^done,asm_insns=[
17714@{address="0x000107bc",func-name="main",offset="0",
17715inst="save %sp, -112, %sp"@},
17716@{address="0x000107c0",func-name="main",offset="4",
17717inst="mov 2, %o0"@},
17718@{address="0x000107c4",func-name="main",offset="8",
17719inst="sethi %hi(0x11800), %o2"@},
17720[@dots{}]
17721@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
17722@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
17723(@value{GDBP})
17724@end smallexample
17725
17726Disassemble 3 instructions from the start of @code{main}:
17727
17728@smallexample
17729(@value{GDBP})
17730-data-disassemble -f basics.c -l 32 -n 3 -- 0
17731^done,asm_insns=[
17732@{address="0x000107bc",func-name="main",offset="0",
17733inst="save %sp, -112, %sp"@},
17734@{address="0x000107c0",func-name="main",offset="4",
17735inst="mov 2, %o0"@},
17736@{address="0x000107c4",func-name="main",offset="8",
17737inst="sethi %hi(0x11800), %o2"@}]
17738(@value{GDBP})
17739@end smallexample
17740
17741Disassemble 3 instructions from the start of @code{main} in mixed mode:
17742
17743@smallexample
17744(@value{GDBP})
17745-data-disassemble -f basics.c -l 32 -n 3 -- 1
17746^done,asm_insns=[
17747src_and_asm_line=@{line="31",
17748file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17749 testsuite/gdb.mi/basics.c",line_asm_insn=[
17750@{address="0x000107bc",func-name="main",offset="0",
17751inst="save %sp, -112, %sp"@}]@},
17752src_and_asm_line=@{line="32",
17753file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17754 testsuite/gdb.mi/basics.c",line_asm_insn=[
17755@{address="0x000107c0",func-name="main",offset="4",
17756inst="mov 2, %o0"@},
17757@{address="0x000107c4",func-name="main",offset="8",
17758inst="sethi %hi(0x11800), %o2"@}]@}]
17759(@value{GDBP})
17760@end smallexample
17761
17762
17763@subheading The @code{-data-evaluate-expression} Command
17764@findex -data-evaluate-expression
17765
17766@subsubheading Synopsis
17767
17768@smallexample
17769 -data-evaluate-expression @var{expr}
17770@end smallexample
17771
17772Evaluate @var{expr} as an expression. The expression could contain an
17773inferior function call. The function call will execute synchronously.
17774If the expression contains spaces, it must be enclosed in double quotes.
17775
17776@subsubheading @value{GDBN} Command
17777
17778The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
17779@samp{call}. In @code{gdbtk} only, there's a corresponding
17780@samp{gdb_eval} command.
17781
17782@subsubheading Example
17783
17784In the following example, the numbers that precede the commands are the
17785@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
17786Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
17787output.
17788
17789@smallexample
17790211-data-evaluate-expression A
17791211^done,value="1"
17792(@value{GDBP})
17793311-data-evaluate-expression &A
17794311^done,value="0xefffeb7c"
17795(@value{GDBP})
17796411-data-evaluate-expression A+3
17797411^done,value="4"
17798(@value{GDBP})
17799511-data-evaluate-expression "A + 3"
17800511^done,value="4"
17801(@value{GDBP})
17802@end smallexample
17803
17804
17805@subheading The @code{-data-list-changed-registers} Command
17806@findex -data-list-changed-registers
17807
17808@subsubheading Synopsis
17809
17810@smallexample
17811 -data-list-changed-registers
17812@end smallexample
17813
17814Display a list of the registers that have changed.
17815
17816@subsubheading @value{GDBN} Command
17817
17818@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
17819has the corresponding command @samp{gdb_changed_register_list}.
17820
17821@subsubheading Example
17822
17823On a PPC MBX board:
17824
17825@smallexample
17826(@value{GDBP})
17827-exec-continue
17828^running
17829
17830(@value{GDBP})
17831*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
76ff342d 17832args=[],file="try.c",fullname="/home/foo/bar/devo/myproject/try.c",line="5"@}
922fbb7b
AC
17833(@value{GDBP})
17834-data-list-changed-registers
17835^done,changed-registers=["0","1","2","4","5","6","7","8","9",
17836"10","11","13","14","15","16","17","18","19","20","21","22","23",
17837"24","25","26","27","28","30","31","64","65","66","67","69"]
17838(@value{GDBP})
17839@end smallexample
17840
17841
17842@subheading The @code{-data-list-register-names} Command
17843@findex -data-list-register-names
17844
17845@subsubheading Synopsis
17846
17847@smallexample
17848 -data-list-register-names [ ( @var{regno} )+ ]
17849@end smallexample
17850
17851Show a list of register names for the current target. If no arguments
17852are given, it shows a list of the names of all the registers. If
17853integer numbers are given as arguments, it will print a list of the
17854names of the registers corresponding to the arguments. To ensure
17855consistency between a register name and its number, the output list may
17856include empty register names.
17857
17858@subsubheading @value{GDBN} Command
17859
17860@value{GDBN} does not have a command which corresponds to
17861@samp{-data-list-register-names}. In @code{gdbtk} there is a
17862corresponding command @samp{gdb_regnames}.
17863
17864@subsubheading Example
17865
17866For the PPC MBX board:
17867@smallexample
17868(@value{GDBP})
17869-data-list-register-names
17870^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
17871"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
17872"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
17873"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
17874"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
17875"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
17876"", "pc","ps","cr","lr","ctr","xer"]
17877(@value{GDBP})
17878-data-list-register-names 1 2 3
17879^done,register-names=["r1","r2","r3"]
17880(@value{GDBP})
17881@end smallexample
17882
17883@subheading The @code{-data-list-register-values} Command
17884@findex -data-list-register-values
17885
17886@subsubheading Synopsis
17887
17888@smallexample
17889 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
17890@end smallexample
17891
17892Display the registers' contents. @var{fmt} is the format according to
17893which the registers' contents are to be returned, followed by an optional
17894list of numbers specifying the registers to display. A missing list of
17895numbers indicates that the contents of all the registers must be returned.
17896
17897Allowed formats for @var{fmt} are:
17898
17899@table @code
17900@item x
17901Hexadecimal
17902@item o
17903Octal
17904@item t
17905Binary
17906@item d
17907Decimal
17908@item r
17909Raw
17910@item N
17911Natural
17912@end table
17913
17914@subsubheading @value{GDBN} Command
17915
17916The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
17917all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
17918
17919@subsubheading Example
17920
17921For a PPC MBX board (note: line breaks are for readability only, they
17922don't appear in the actual output):
17923
17924@smallexample
17925(@value{GDBP})
17926-data-list-register-values r 64 65
17927^done,register-values=[@{number="64",value="0xfe00a300"@},
17928@{number="65",value="0x00029002"@}]
17929(@value{GDBP})
17930-data-list-register-values x
17931^done,register-values=[@{number="0",value="0xfe0043c8"@},
17932@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
17933@{number="3",value="0x0"@},@{number="4",value="0xa"@},
17934@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
17935@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
17936@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
17937@{number="11",value="0x1"@},@{number="12",value="0x0"@},
17938@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
17939@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
17940@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
17941@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
17942@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
17943@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
17944@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
17945@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
17946@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
17947@{number="31",value="0x0"@},@{number="32",value="0x0"@},
17948@{number="33",value="0x0"@},@{number="34",value="0x0"@},
17949@{number="35",value="0x0"@},@{number="36",value="0x0"@},
17950@{number="37",value="0x0"@},@{number="38",value="0x0"@},
17951@{number="39",value="0x0"@},@{number="40",value="0x0"@},
17952@{number="41",value="0x0"@},@{number="42",value="0x0"@},
17953@{number="43",value="0x0"@},@{number="44",value="0x0"@},
17954@{number="45",value="0x0"@},@{number="46",value="0x0"@},
17955@{number="47",value="0x0"@},@{number="48",value="0x0"@},
17956@{number="49",value="0x0"@},@{number="50",value="0x0"@},
17957@{number="51",value="0x0"@},@{number="52",value="0x0"@},
17958@{number="53",value="0x0"@},@{number="54",value="0x0"@},
17959@{number="55",value="0x0"@},@{number="56",value="0x0"@},
17960@{number="57",value="0x0"@},@{number="58",value="0x0"@},
17961@{number="59",value="0x0"@},@{number="60",value="0x0"@},
17962@{number="61",value="0x0"@},@{number="62",value="0x0"@},
17963@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
17964@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
17965@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
17966@{number="69",value="0x20002b03"@}]
17967(@value{GDBP})
17968@end smallexample
17969
17970
17971@subheading The @code{-data-read-memory} Command
17972@findex -data-read-memory
17973
17974@subsubheading Synopsis
17975
17976@smallexample
17977 -data-read-memory [ -o @var{byte-offset} ]
17978 @var{address} @var{word-format} @var{word-size}
17979 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
17980@end smallexample
17981
17982@noindent
17983where:
17984
17985@table @samp
17986@item @var{address}
17987An expression specifying the address of the first memory word to be
17988read. Complex expressions containing embedded white space should be
17989quoted using the C convention.
17990
17991@item @var{word-format}
17992The format to be used to print the memory words. The notation is the
17993same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
17994,Output formats}).
17995
17996@item @var{word-size}
17997The size of each memory word in bytes.
17998
17999@item @var{nr-rows}
18000The number of rows in the output table.
18001
18002@item @var{nr-cols}
18003The number of columns in the output table.
18004
18005@item @var{aschar}
18006If present, indicates that each row should include an @sc{ascii} dump. The
18007value of @var{aschar} is used as a padding character when a byte is not a
18008member of the printable @sc{ascii} character set (printable @sc{ascii}
18009characters are those whose code is between 32 and 126, inclusively).
18010
18011@item @var{byte-offset}
18012An offset to add to the @var{address} before fetching memory.
18013@end table
18014
18015This command displays memory contents as a table of @var{nr-rows} by
18016@var{nr-cols} words, each word being @var{word-size} bytes. In total,
18017@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
18018(returned as @samp{total-bytes}). Should less than the requested number
18019of bytes be returned by the target, the missing words are identified
18020using @samp{N/A}. The number of bytes read from the target is returned
18021in @samp{nr-bytes} and the starting address used to read memory in
18022@samp{addr}.
18023
18024The address of the next/previous row or page is available in
18025@samp{next-row} and @samp{prev-row}, @samp{next-page} and
18026@samp{prev-page}.
18027
18028@subsubheading @value{GDBN} Command
18029
18030The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
18031@samp{gdb_get_mem} memory read command.
18032
18033@subsubheading Example
18034
18035Read six bytes of memory starting at @code{bytes+6} but then offset by
18036@code{-6} bytes. Format as three rows of two columns. One byte per
18037word. Display each word in hex.
18038
18039@smallexample
18040(@value{GDBP})
180419-data-read-memory -o -6 -- bytes+6 x 1 3 2
180429^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
18043next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
18044prev-page="0x0000138a",memory=[
18045@{addr="0x00001390",data=["0x00","0x01"]@},
18046@{addr="0x00001392",data=["0x02","0x03"]@},
18047@{addr="0x00001394",data=["0x04","0x05"]@}]
18048(@value{GDBP})
18049@end smallexample
18050
18051Read two bytes of memory starting at address @code{shorts + 64} and
18052display as a single word formatted in decimal.
18053
18054@smallexample
18055(@value{GDBP})
180565-data-read-memory shorts+64 d 2 1 1
180575^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
18058next-row="0x00001512",prev-row="0x0000150e",
18059next-page="0x00001512",prev-page="0x0000150e",memory=[
18060@{addr="0x00001510",data=["128"]@}]
18061(@value{GDBP})
18062@end smallexample
18063
18064Read thirty two bytes of memory starting at @code{bytes+16} and format
18065as eight rows of four columns. Include a string encoding with @samp{x}
18066used as the non-printable character.
18067
18068@smallexample
18069(@value{GDBP})
180704-data-read-memory bytes+16 x 1 8 4 x
180714^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
18072next-row="0x000013c0",prev-row="0x0000139c",
18073next-page="0x000013c0",prev-page="0x00001380",memory=[
18074@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
18075@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
18076@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
18077@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
18078@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
18079@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
18080@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
18081@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
18082(@value{GDBP})
18083@end smallexample
18084
18085@subheading The @code{-display-delete} Command
18086@findex -display-delete
18087
18088@subsubheading Synopsis
18089
18090@smallexample
18091 -display-delete @var{number}
18092@end smallexample
18093
18094Delete the display @var{number}.
18095
18096@subsubheading @value{GDBN} Command
18097
18098The corresponding @value{GDBN} command is @samp{delete display}.
18099
18100@subsubheading Example
18101N.A.
18102
18103
18104@subheading The @code{-display-disable} Command
18105@findex -display-disable
18106
18107@subsubheading Synopsis
18108
18109@smallexample
18110 -display-disable @var{number}
18111@end smallexample
18112
18113Disable display @var{number}.
18114
18115@subsubheading @value{GDBN} Command
18116
18117The corresponding @value{GDBN} command is @samp{disable display}.
18118
18119@subsubheading Example
18120N.A.
18121
18122
18123@subheading The @code{-display-enable} Command
18124@findex -display-enable
18125
18126@subsubheading Synopsis
18127
18128@smallexample
18129 -display-enable @var{number}
18130@end smallexample
18131
18132Enable display @var{number}.
18133
18134@subsubheading @value{GDBN} Command
18135
18136The corresponding @value{GDBN} command is @samp{enable display}.
18137
18138@subsubheading Example
18139N.A.
18140
18141
18142@subheading The @code{-display-insert} Command
18143@findex -display-insert
18144
18145@subsubheading Synopsis
18146
18147@smallexample
18148 -display-insert @var{expression}
18149@end smallexample
18150
18151Display @var{expression} every time the program stops.
18152
18153@subsubheading @value{GDBN} Command
18154
18155The corresponding @value{GDBN} command is @samp{display}.
18156
18157@subsubheading Example
18158N.A.
18159
18160
18161@subheading The @code{-display-list} Command
18162@findex -display-list
18163
18164@subsubheading Synopsis
18165
18166@smallexample
18167 -display-list
18168@end smallexample
18169
18170List the displays. Do not show the current values.
18171
18172@subsubheading @value{GDBN} Command
18173
18174The corresponding @value{GDBN} command is @samp{info display}.
18175
18176@subsubheading Example
18177N.A.
18178
18179
18180@subheading The @code{-environment-cd} Command
18181@findex -environment-cd
18182
18183@subsubheading Synopsis
18184
18185@smallexample
18186 -environment-cd @var{pathdir}
18187@end smallexample
18188
18189Set @value{GDBN}'s working directory.
18190
18191@subsubheading @value{GDBN} Command
18192
18193The corresponding @value{GDBN} command is @samp{cd}.
18194
18195@subsubheading Example
18196
18197@smallexample
18198(@value{GDBP})
18199-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18200^done
18201(@value{GDBP})
18202@end smallexample
18203
18204
18205@subheading The @code{-environment-directory} Command
18206@findex -environment-directory
18207
18208@subsubheading Synopsis
18209
18210@smallexample
18211 -environment-directory [ -r ] [ @var{pathdir} ]+
18212@end smallexample
18213
18214Add directories @var{pathdir} to beginning of search path for source files.
18215If the @samp{-r} option is used, the search path is reset to the default
b383017d 18216search path. If directories @var{pathdir} are supplied in addition to the
922fbb7b
AC
18217@samp{-r} option, the search path is first reset and then addition
18218occurs as normal.
b383017d 18219Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18220multiple directories in a single command
18221results in the directories added to the beginning of the
18222search path in the same order they were presented in the command.
18223If blanks are needed as
18224part of a directory name, double-quotes should be used around
18225the name. In the command output, the path will show up separated
b383017d 18226by the system directory-separator character. The directory-seperator
922fbb7b
AC
18227character must not be used
18228in any directory name.
18229If no directories are specified, the current search path is displayed.
18230
18231@subsubheading @value{GDBN} Command
18232
18233The corresponding @value{GDBN} command is @samp{dir}.
18234
18235@subsubheading Example
18236
18237@smallexample
18238(@value{GDBP})
18239-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18240^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18241(@value{GDBP})
18242-environment-directory ""
18243^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18244(@value{GDBP})
18245-environment-directory -r /home/jjohnstn/src/gdb /usr/src
18246^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
18247(@value{GDBP})
18248-environment-directory -r
18249^done,source-path="$cdir:$cwd"
18250(@value{GDBP})
18251@end smallexample
18252
18253
18254@subheading The @code{-environment-path} Command
18255@findex -environment-path
18256
18257@subsubheading Synopsis
18258
18259@smallexample
18260 -environment-path [ -r ] [ @var{pathdir} ]+
18261@end smallexample
18262
18263Add directories @var{pathdir} to beginning of search path for object files.
18264If the @samp{-r} option is used, the search path is reset to the original
b383017d
RM
18265search path that existed at gdb start-up. If directories @var{pathdir} are
18266supplied in addition to the
922fbb7b
AC
18267@samp{-r} option, the search path is first reset and then addition
18268occurs as normal.
b383017d 18269Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18270multiple directories in a single command
18271results in the directories added to the beginning of the
18272search path in the same order they were presented in the command.
18273If blanks are needed as
18274part of a directory name, double-quotes should be used around
18275the name. In the command output, the path will show up separated
b383017d 18276by the system directory-separator character. The directory-seperator
922fbb7b
AC
18277character must not be used
18278in any directory name.
18279If no directories are specified, the current path is displayed.
18280
18281
18282@subsubheading @value{GDBN} Command
18283
18284The corresponding @value{GDBN} command is @samp{path}.
18285
18286@subsubheading Example
18287
18288@smallexample
18289(@value{GDBP})
b383017d 18290-environment-path
922fbb7b
AC
18291^done,path="/usr/bin"
18292(@value{GDBP})
18293-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
18294^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
18295(@value{GDBP})
18296-environment-path -r /usr/local/bin
18297^done,path="/usr/local/bin:/usr/bin"
18298(@value{GDBP})
18299@end smallexample
18300
18301
18302@subheading The @code{-environment-pwd} Command
18303@findex -environment-pwd
18304
18305@subsubheading Synopsis
18306
18307@smallexample
18308 -environment-pwd
18309@end smallexample
18310
18311Show the current working directory.
18312
18313@subsubheading @value{GDBN} command
18314
18315The corresponding @value{GDBN} command is @samp{pwd}.
18316
18317@subsubheading Example
18318
18319@smallexample
18320(@value{GDBP})
18321-environment-pwd
18322^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
18323(@value{GDBP})
18324@end smallexample
18325
18326@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18327@node GDB/MI Program Control
18328@section @sc{gdb/mi} Program control
18329
18330@subsubheading Program termination
18331
18332As a result of execution, the inferior program can run to completion, if
18333it doesn't encounter any breakpoints. In this case the output will
18334include an exit code, if the program has exited exceptionally.
18335
18336@subsubheading Examples
18337
18338@noindent
18339Program exited normally:
18340
18341@smallexample
18342(@value{GDBP})
18343-exec-run
18344^running
18345(@value{GDBP})
18346x = 55
18347*stopped,reason="exited-normally"
18348(@value{GDBP})
18349@end smallexample
18350
18351@noindent
18352Program exited exceptionally:
18353
18354@smallexample
18355(@value{GDBP})
18356-exec-run
18357^running
18358(@value{GDBP})
18359x = 55
18360*stopped,reason="exited",exit-code="01"
18361(@value{GDBP})
18362@end smallexample
18363
18364Another way the program can terminate is if it receives a signal such as
18365@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
18366
18367@smallexample
18368(@value{GDBP})
18369*stopped,reason="exited-signalled",signal-name="SIGINT",
18370signal-meaning="Interrupt"
18371@end smallexample
18372
18373
18374@subheading The @code{-exec-abort} Command
18375@findex -exec-abort
18376
18377@subsubheading Synopsis
18378
18379@smallexample
18380 -exec-abort
18381@end smallexample
18382
18383Kill the inferior running program.
18384
18385@subsubheading @value{GDBN} Command
18386
18387The corresponding @value{GDBN} command is @samp{kill}.
18388
18389@subsubheading Example
18390N.A.
18391
18392
18393@subheading The @code{-exec-arguments} Command
18394@findex -exec-arguments
18395
18396@subsubheading Synopsis
18397
18398@smallexample
18399 -exec-arguments @var{args}
18400@end smallexample
18401
18402Set the inferior program arguments, to be used in the next
18403@samp{-exec-run}.
18404
18405@subsubheading @value{GDBN} Command
18406
18407The corresponding @value{GDBN} command is @samp{set args}.
18408
18409@subsubheading Example
18410
18411@c FIXME!
18412Don't have one around.
18413
18414
18415@subheading The @code{-exec-continue} Command
18416@findex -exec-continue
18417
18418@subsubheading Synopsis
18419
18420@smallexample
18421 -exec-continue
18422@end smallexample
18423
18424Asynchronous command. Resumes the execution of the inferior program
18425until a breakpoint is encountered, or until the inferior exits.
18426
18427@subsubheading @value{GDBN} Command
18428
18429The corresponding @value{GDBN} corresponding is @samp{continue}.
18430
18431@subsubheading Example
18432
18433@smallexample
18434-exec-continue
18435^running
18436(@value{GDBP})
18437@@Hello world
18438*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
76ff342d 18439file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="13"@}
922fbb7b
AC
18440(@value{GDBP})
18441@end smallexample
18442
18443
18444@subheading The @code{-exec-finish} Command
18445@findex -exec-finish
18446
18447@subsubheading Synopsis
18448
18449@smallexample
18450 -exec-finish
18451@end smallexample
18452
18453Asynchronous command. Resumes the execution of the inferior program
18454until the current function is exited. Displays the results returned by
18455the function.
18456
18457@subsubheading @value{GDBN} Command
18458
18459The corresponding @value{GDBN} command is @samp{finish}.
18460
18461@subsubheading Example
18462
18463Function returning @code{void}.
18464
18465@smallexample
18466-exec-finish
18467^running
18468(@value{GDBP})
18469@@hello from foo
18470*stopped,reason="function-finished",frame=@{func="main",args=[],
76ff342d 18471file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="7"@}
922fbb7b
AC
18472(@value{GDBP})
18473@end smallexample
18474
18475Function returning other than @code{void}. The name of the internal
18476@value{GDBN} variable storing the result is printed, together with the
18477value itself.
18478
18479@smallexample
18480-exec-finish
18481^running
18482(@value{GDBP})
18483*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
18484args=[@{name="a",value="1"],@{name="b",value="9"@}@},
76ff342d 18485file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b
AC
18486gdb-result-var="$1",return-value="0"
18487(@value{GDBP})
18488@end smallexample
18489
18490
18491@subheading The @code{-exec-interrupt} Command
18492@findex -exec-interrupt
18493
18494@subsubheading Synopsis
18495
18496@smallexample
18497 -exec-interrupt
18498@end smallexample
18499
18500Asynchronous command. Interrupts the background execution of the target.
18501Note how the token associated with the stop message is the one for the
18502execution command that has been interrupted. The token for the interrupt
18503itself only appears in the @samp{^done} output. If the user is trying to
18504interrupt a non-running program, an error message will be printed.
18505
18506@subsubheading @value{GDBN} Command
18507
18508The corresponding @value{GDBN} command is @samp{interrupt}.
18509
18510@subsubheading Example
18511
18512@smallexample
18513(@value{GDBP})
18514111-exec-continue
18515111^running
18516
18517(@value{GDBP})
18518222-exec-interrupt
18519222^done
18520(@value{GDBP})
18521111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d
DJ
18522frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
18523fullname="/home/foo/bar/devo/myproject/try.c",line="13"@}
922fbb7b
AC
18524(@value{GDBP})
18525
18526(@value{GDBP})
18527-exec-interrupt
18528^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
18529(@value{GDBP})
18530@end smallexample
18531
18532
18533@subheading The @code{-exec-next} Command
18534@findex -exec-next
18535
18536@subsubheading Synopsis
18537
18538@smallexample
18539 -exec-next
18540@end smallexample
18541
18542Asynchronous command. Resumes execution of the inferior program, stopping
18543when the beginning of the next source line is reached.
18544
18545@subsubheading @value{GDBN} Command
18546
18547The corresponding @value{GDBN} command is @samp{next}.
18548
18549@subsubheading Example
18550
18551@smallexample
18552-exec-next
18553^running
18554(@value{GDBP})
18555*stopped,reason="end-stepping-range",line="8",file="hello.c"
18556(@value{GDBP})
18557@end smallexample
18558
18559
18560@subheading The @code{-exec-next-instruction} Command
18561@findex -exec-next-instruction
18562
18563@subsubheading Synopsis
18564
18565@smallexample
18566 -exec-next-instruction
18567@end smallexample
18568
18569Asynchronous command. Executes one machine instruction. If the
18570instruction is a function call continues until the function returns. If
18571the program stops at an instruction in the middle of a source line, the
18572address will be printed as well.
18573
18574@subsubheading @value{GDBN} Command
18575
18576The corresponding @value{GDBN} command is @samp{nexti}.
18577
18578@subsubheading Example
18579
18580@smallexample
18581(@value{GDBP})
18582-exec-next-instruction
18583^running
18584
18585(@value{GDBP})
18586*stopped,reason="end-stepping-range",
18587addr="0x000100d4",line="5",file="hello.c"
18588(@value{GDBP})
18589@end smallexample
18590
18591
18592@subheading The @code{-exec-return} Command
18593@findex -exec-return
18594
18595@subsubheading Synopsis
18596
18597@smallexample
18598 -exec-return
18599@end smallexample
18600
18601Makes current function return immediately. Doesn't execute the inferior.
18602Displays the new current frame.
18603
18604@subsubheading @value{GDBN} Command
18605
18606The corresponding @value{GDBN} command is @samp{return}.
18607
18608@subsubheading Example
18609
18610@smallexample
18611(@value{GDBP})
18612200-break-insert callee4
18613200^done,bkpt=@{number="1",addr="0x00010734",
18614file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
18615(@value{GDBP})
18616000-exec-run
18617000^running
18618(@value{GDBP})
18619000*stopped,reason="breakpoint-hit",bkptno="1",
18620frame=@{func="callee4",args=[],
76ff342d
DJ
18621file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18622fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
922fbb7b
AC
18623(@value{GDBP})
18624205-break-delete
18625205^done
18626(@value{GDBP})
18627111-exec-return
18628111^done,frame=@{level="0",func="callee3",
18629args=[@{name="strarg",
18630value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
18631file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18632fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
18633(@value{GDBP})
18634@end smallexample
18635
18636
18637@subheading The @code{-exec-run} Command
18638@findex -exec-run
18639
18640@subsubheading Synopsis
18641
18642@smallexample
18643 -exec-run
18644@end smallexample
18645
18646Asynchronous command. Starts execution of the inferior from the
18647beginning. The inferior executes until either a breakpoint is
18648encountered or the program exits.
18649
18650@subsubheading @value{GDBN} Command
18651
18652The corresponding @value{GDBN} command is @samp{run}.
18653
18654@subsubheading Example
18655
18656@smallexample
18657(@value{GDBP})
18658-break-insert main
18659^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
18660(@value{GDBP})
18661-exec-run
18662^running
18663(@value{GDBP})
18664*stopped,reason="breakpoint-hit",bkptno="1",
76ff342d
DJ
18665frame=@{func="main",args=[],file="recursive2.c",
18666fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}
922fbb7b
AC
18667(@value{GDBP})
18668@end smallexample
18669
18670
18671@subheading The @code{-exec-show-arguments} Command
18672@findex -exec-show-arguments
18673
18674@subsubheading Synopsis
18675
18676@smallexample
18677 -exec-show-arguments
18678@end smallexample
18679
18680Print the arguments of the program.
18681
18682@subsubheading @value{GDBN} Command
18683
18684The corresponding @value{GDBN} command is @samp{show args}.
18685
18686@subsubheading Example
18687N.A.
18688
18689@c @subheading -exec-signal
18690
18691@subheading The @code{-exec-step} Command
18692@findex -exec-step
18693
18694@subsubheading Synopsis
18695
18696@smallexample
18697 -exec-step
18698@end smallexample
18699
18700Asynchronous command. Resumes execution of the inferior program, stopping
18701when the beginning of the next source line is reached, if the next
18702source line is not a function call. If it is, stop at the first
18703instruction of the called function.
18704
18705@subsubheading @value{GDBN} Command
18706
18707The corresponding @value{GDBN} command is @samp{step}.
18708
18709@subsubheading Example
18710
18711Stepping into a function:
18712
18713@smallexample
18714-exec-step
18715^running
18716(@value{GDBP})
18717*stopped,reason="end-stepping-range",
18718frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d
DJ
18719@{name="b",value="0"@}],file="recursive2.c",
18720fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@}
922fbb7b
AC
18721(@value{GDBP})
18722@end smallexample
18723
18724Regular stepping:
18725
18726@smallexample
18727-exec-step
18728^running
18729(@value{GDBP})
18730*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
18731(@value{GDBP})
18732@end smallexample
18733
18734
18735@subheading The @code{-exec-step-instruction} Command
18736@findex -exec-step-instruction
18737
18738@subsubheading Synopsis
18739
18740@smallexample
18741 -exec-step-instruction
18742@end smallexample
18743
18744Asynchronous command. Resumes the inferior which executes one machine
18745instruction. The output, once @value{GDBN} has stopped, will vary depending on
18746whether we have stopped in the middle of a source line or not. In the
18747former case, the address at which the program stopped will be printed as
18748well.
18749
18750@subsubheading @value{GDBN} Command
18751
18752The corresponding @value{GDBN} command is @samp{stepi}.
18753
18754@subsubheading Example
18755
18756@smallexample
18757(@value{GDBP})
18758-exec-step-instruction
18759^running
18760
18761(@value{GDBP})
18762*stopped,reason="end-stepping-range",
76ff342d
DJ
18763frame=@{func="foo",args=[],file="try.c",
18764fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18765(@value{GDBP})
18766-exec-step-instruction
18767^running
18768
18769(@value{GDBP})
18770*stopped,reason="end-stepping-range",
76ff342d
DJ
18771frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
18772fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18773(@value{GDBP})
18774@end smallexample
18775
18776
18777@subheading The @code{-exec-until} Command
18778@findex -exec-until
18779
18780@subsubheading Synopsis
18781
18782@smallexample
18783 -exec-until [ @var{location} ]
18784@end smallexample
18785
18786Asynchronous command. Executes the inferior until the @var{location}
18787specified in the argument is reached. If there is no argument, the inferior
18788executes until a source line greater than the current one is reached.
18789The reason for stopping in this case will be @samp{location-reached}.
18790
18791@subsubheading @value{GDBN} Command
18792
18793The corresponding @value{GDBN} command is @samp{until}.
18794
18795@subsubheading Example
18796
18797@smallexample
18798(@value{GDBP})
18799-exec-until recursive2.c:6
18800^running
18801(@value{GDBP})
18802x = 55
18803*stopped,reason="location-reached",frame=@{func="main",args=[],
76ff342d 18804file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="6"@}
922fbb7b
AC
18805(@value{GDBP})
18806@end smallexample
18807
18808@ignore
18809@subheading -file-clear
18810Is this going away????
18811@end ignore
18812
18813
18814@subheading The @code{-file-exec-and-symbols} Command
18815@findex -file-exec-and-symbols
18816
18817@subsubheading Synopsis
18818
18819@smallexample
18820 -file-exec-and-symbols @var{file}
18821@end smallexample
18822
18823Specify the executable file to be debugged. This file is the one from
18824which the symbol table is also read. If no file is specified, the
18825command clears the executable and symbol information. If breakpoints
18826are set when using this command with no arguments, @value{GDBN} will produce
18827error messages. Otherwise, no output is produced, except a completion
18828notification.
18829
18830@subsubheading @value{GDBN} Command
18831
18832The corresponding @value{GDBN} command is @samp{file}.
18833
18834@subsubheading Example
18835
18836@smallexample
18837(@value{GDBP})
18838-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18839^done
18840(@value{GDBP})
18841@end smallexample
18842
18843
18844@subheading The @code{-file-exec-file} Command
18845@findex -file-exec-file
18846
18847@subsubheading Synopsis
18848
18849@smallexample
18850 -file-exec-file @var{file}
18851@end smallexample
18852
18853Specify the executable file to be debugged. Unlike
18854@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
18855from this file. If used without argument, @value{GDBN} clears the information
18856about the executable file. No output is produced, except a completion
18857notification.
18858
18859@subsubheading @value{GDBN} Command
18860
18861The corresponding @value{GDBN} command is @samp{exec-file}.
18862
18863@subsubheading Example
18864
18865@smallexample
18866(@value{GDBP})
18867-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18868^done
18869(@value{GDBP})
18870@end smallexample
18871
18872
18873@subheading The @code{-file-list-exec-sections} Command
18874@findex -file-list-exec-sections
18875
18876@subsubheading Synopsis
18877
18878@smallexample
18879 -file-list-exec-sections
18880@end smallexample
18881
18882List the sections of the current executable file.
18883
18884@subsubheading @value{GDBN} Command
18885
18886The @value{GDBN} command @samp{info file} shows, among the rest, the same
18887information as this command. @code{gdbtk} has a corresponding command
18888@samp{gdb_load_info}.
18889
18890@subsubheading Example
18891N.A.
18892
18893
1abaf70c
BR
18894@subheading The @code{-file-list-exec-source-file} Command
18895@findex -file-list-exec-source-file
18896
18897@subsubheading Synopsis
18898
18899@smallexample
18900 -file-list-exec-source-file
18901@end smallexample
18902
b383017d 18903List the line number, the current source file, and the absolute path
1abaf70c
BR
18904to the current source file for the current executable.
18905
18906@subsubheading @value{GDBN} Command
18907
18908There's no @value{GDBN} command which directly corresponds to this one.
18909
18910@subsubheading Example
18911
18912@smallexample
18913(@value{GDBP})
18914123-file-list-exec-source-file
18915123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
18916(@value{GDBP})
18917@end smallexample
18918
18919
922fbb7b
AC
18920@subheading The @code{-file-list-exec-source-files} Command
18921@findex -file-list-exec-source-files
18922
18923@subsubheading Synopsis
18924
18925@smallexample
18926 -file-list-exec-source-files
18927@end smallexample
18928
18929List the source files for the current executable.
18930
57c22c6c
BR
18931It will always output the filename, but only when GDB can find the absolute
18932file name of a source file, will it output the fullname.
18933
922fbb7b
AC
18934@subsubheading @value{GDBN} Command
18935
18936There's no @value{GDBN} command which directly corresponds to this one.
18937@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
18938
18939@subsubheading Example
57c22c6c
BR
18940@smallexample
18941(@value{GDBP})
18942-file-list-exec-source-files
18943^done,files=[
18944@{file=foo.c,fullname=/home/foo.c@},
18945@{file=/home/bar.c,fullname=/home/bar.c@},
18946@{file=gdb_could_not_find_fullpath.c@}]
18947(@value{GDBP})
18948@end smallexample
922fbb7b
AC
18949
18950@subheading The @code{-file-list-shared-libraries} Command
18951@findex -file-list-shared-libraries
18952
18953@subsubheading Synopsis
18954
18955@smallexample
18956 -file-list-shared-libraries
18957@end smallexample
18958
18959List the shared libraries in the program.
18960
18961@subsubheading @value{GDBN} Command
18962
18963The corresponding @value{GDBN} command is @samp{info shared}.
18964
18965@subsubheading Example
18966N.A.
18967
18968
18969@subheading The @code{-file-list-symbol-files} Command
18970@findex -file-list-symbol-files
18971
18972@subsubheading Synopsis
18973
18974@smallexample
18975 -file-list-symbol-files
18976@end smallexample
18977
18978List symbol files.
18979
18980@subsubheading @value{GDBN} Command
18981
18982The corresponding @value{GDBN} command is @samp{info file} (part of it).
18983
18984@subsubheading Example
18985N.A.
18986
18987
18988@subheading The @code{-file-symbol-file} Command
18989@findex -file-symbol-file
18990
18991@subsubheading Synopsis
18992
18993@smallexample
18994 -file-symbol-file @var{file}
18995@end smallexample
18996
18997Read symbol table info from the specified @var{file} argument. When
18998used without arguments, clears @value{GDBN}'s symbol table info. No output is
18999produced, except for a completion notification.
19000
19001@subsubheading @value{GDBN} Command
19002
19003The corresponding @value{GDBN} command is @samp{symbol-file}.
19004
19005@subsubheading Example
19006
19007@smallexample
19008(@value{GDBP})
19009-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
19010^done
19011(@value{GDBP})
19012@end smallexample
19013
19014@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19015@node GDB/MI Miscellaneous Commands
19016@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
19017
19018@c @subheading -gdb-complete
19019
19020@subheading The @code{-gdb-exit} Command
19021@findex -gdb-exit
19022
19023@subsubheading Synopsis
19024
19025@smallexample
19026 -gdb-exit
19027@end smallexample
19028
19029Exit @value{GDBN} immediately.
19030
19031@subsubheading @value{GDBN} Command
19032
19033Approximately corresponds to @samp{quit}.
19034
19035@subsubheading Example
19036
19037@smallexample
19038(@value{GDBP})
19039-gdb-exit
19040@end smallexample
19041
19042@subheading The @code{-gdb-set} Command
19043@findex -gdb-set
19044
19045@subsubheading Synopsis
19046
19047@smallexample
19048 -gdb-set
19049@end smallexample
19050
19051Set an internal @value{GDBN} variable.
19052@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
19053
19054@subsubheading @value{GDBN} Command
19055
19056The corresponding @value{GDBN} command is @samp{set}.
19057
19058@subsubheading Example
19059
19060@smallexample
19061(@value{GDBP})
19062-gdb-set $foo=3
19063^done
19064(@value{GDBP})
19065@end smallexample
19066
19067
19068@subheading The @code{-gdb-show} Command
19069@findex -gdb-show
19070
19071@subsubheading Synopsis
19072
19073@smallexample
19074 -gdb-show
19075@end smallexample
19076
19077Show the current value of a @value{GDBN} variable.
19078
19079@subsubheading @value{GDBN} command
19080
19081The corresponding @value{GDBN} command is @samp{show}.
19082
19083@subsubheading Example
19084
19085@smallexample
19086(@value{GDBP})
19087-gdb-show annotate
19088^done,value="0"
19089(@value{GDBP})
19090@end smallexample
19091
19092@c @subheading -gdb-source
19093
19094
19095@subheading The @code{-gdb-version} Command
19096@findex -gdb-version
19097
19098@subsubheading Synopsis
19099
19100@smallexample
19101 -gdb-version
19102@end smallexample
19103
19104Show version information for @value{GDBN}. Used mostly in testing.
19105
19106@subsubheading @value{GDBN} Command
19107
19108There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
19109information when you start an interactive session.
19110
19111@subsubheading Example
19112
19113@c This example modifies the actual output from GDB to avoid overfull
19114@c box in TeX.
19115@smallexample
19116(@value{GDBP})
19117-gdb-version
19118~GNU gdb 5.2.1
19119~Copyright 2000 Free Software Foundation, Inc.
19120~GDB is free software, covered by the GNU General Public License, and
19121~you are welcome to change it and/or distribute copies of it under
19122~ certain conditions.
19123~Type "show copying" to see the conditions.
19124~There is absolutely no warranty for GDB. Type "show warranty" for
19125~ details.
b383017d 19126~This GDB was configured as
922fbb7b
AC
19127 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
19128^done
19129(@value{GDBP})
19130@end smallexample
19131
19132@subheading The @code{-interpreter-exec} Command
19133@findex -interpreter-exec
19134
19135@subheading Synopsis
19136
19137@smallexample
19138-interpreter-exec @var{interpreter} @var{command}
19139@end smallexample
19140
19141Execute the specified @var{command} in the given @var{interpreter}.
19142
19143@subheading @value{GDBN} Command
19144
19145The corresponding @value{GDBN} command is @samp{interpreter-exec}.
19146
19147@subheading Example
19148
19149@smallexample
19150(@value{GDBP})
19151-interpreter-exec console "break main"
19152&"During symbol reading, couldn't parse type; debugger out of date?.\n"
19153&"During symbol reading, bad structure-type format.\n"
19154~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
19155^done
19156(@value{GDBP})
19157@end smallexample
19158
19159@ignore
19160@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19161@node GDB/MI Kod Commands
19162@section @sc{gdb/mi} Kod Commands
19163
19164The Kod commands are not implemented.
19165
19166@c @subheading -kod-info
19167
19168@c @subheading -kod-list
19169
19170@c @subheading -kod-list-object-types
19171
19172@c @subheading -kod-show
19173
19174@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19175@node GDB/MI Memory Overlay Commands
19176@section @sc{gdb/mi} Memory Overlay Commands
19177
19178The memory overlay commands are not implemented.
19179
19180@c @subheading -overlay-auto
19181
19182@c @subheading -overlay-list-mapping-state
19183
19184@c @subheading -overlay-list-overlays
19185
19186@c @subheading -overlay-map
19187
19188@c @subheading -overlay-off
19189
19190@c @subheading -overlay-on
19191
19192@c @subheading -overlay-unmap
19193
19194@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19195@node GDB/MI Signal Handling Commands
19196@section @sc{gdb/mi} Signal Handling Commands
19197
19198Signal handling commands are not implemented.
19199
19200@c @subheading -signal-handle
19201
19202@c @subheading -signal-list-handle-actions
19203
19204@c @subheading -signal-list-signal-types
19205@end ignore
19206
19207
19208@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19209@node GDB/MI Stack Manipulation
19210@section @sc{gdb/mi} Stack Manipulation Commands
19211
922fbb7b
AC
19212@subheading The @code{-stack-info-depth} Command
19213@findex -stack-info-depth
19214
19215@subsubheading Synopsis
19216
19217@smallexample
19218 -stack-info-depth [ @var{max-depth} ]
19219@end smallexample
19220
19221Return the depth of the stack. If the integer argument @var{max-depth}
19222is specified, do not count beyond @var{max-depth} frames.
19223
19224@subsubheading @value{GDBN} Command
19225
19226There's no equivalent @value{GDBN} command.
19227
19228@subsubheading Example
19229
19230For a stack with frame levels 0 through 11:
19231
19232@smallexample
19233(@value{GDBP})
19234-stack-info-depth
19235^done,depth="12"
19236(@value{GDBP})
19237-stack-info-depth 4
19238^done,depth="4"
19239(@value{GDBP})
19240-stack-info-depth 12
19241^done,depth="12"
19242(@value{GDBP})
19243-stack-info-depth 11
19244^done,depth="11"
19245(@value{GDBP})
19246-stack-info-depth 13
19247^done,depth="12"
19248(@value{GDBP})
19249@end smallexample
19250
19251@subheading The @code{-stack-list-arguments} Command
19252@findex -stack-list-arguments
19253
19254@subsubheading Synopsis
19255
19256@smallexample
19257 -stack-list-arguments @var{show-values}
19258 [ @var{low-frame} @var{high-frame} ]
19259@end smallexample
19260
19261Display a list of the arguments for the frames between @var{low-frame}
19262and @var{high-frame} (inclusive). If @var{low-frame} and
19263@var{high-frame} are not provided, list the arguments for the whole call
19264stack.
19265
19266The @var{show-values} argument must have a value of 0 or 1. A value of
192670 means that only the names of the arguments are listed, a value of 1
19268means that both names and values of the arguments are printed.
19269
19270@subsubheading @value{GDBN} Command
19271
19272@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
19273@samp{gdb_get_args} command which partially overlaps with the
19274functionality of @samp{-stack-list-arguments}.
19275
19276@subsubheading Example
19277
19278@smallexample
19279(@value{GDBP})
19280-stack-list-frames
19281^done,
19282stack=[
19283frame=@{level="0",addr="0x00010734",func="callee4",
76ff342d
DJ
19284file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19285fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
922fbb7b 19286frame=@{level="1",addr="0x0001076c",func="callee3",
76ff342d
DJ
19287file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19288fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
922fbb7b 19289frame=@{level="2",addr="0x0001078c",func="callee2",
76ff342d
DJ
19290file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19291fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
922fbb7b 19292frame=@{level="3",addr="0x000107b4",func="callee1",
76ff342d
DJ
19293file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19294fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
922fbb7b 19295frame=@{level="4",addr="0x000107e0",func="main",
76ff342d
DJ
19296file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19297fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
922fbb7b
AC
19298(@value{GDBP})
19299-stack-list-arguments 0
19300^done,
19301stack-args=[
19302frame=@{level="0",args=[]@},
19303frame=@{level="1",args=[name="strarg"]@},
19304frame=@{level="2",args=[name="intarg",name="strarg"]@},
19305frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
19306frame=@{level="4",args=[]@}]
19307(@value{GDBP})
19308-stack-list-arguments 1
19309^done,
19310stack-args=[
19311frame=@{level="0",args=[]@},
19312frame=@{level="1",
19313 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19314frame=@{level="2",args=[
19315@{name="intarg",value="2"@},
19316@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19317@{frame=@{level="3",args=[
19318@{name="intarg",value="2"@},
19319@{name="strarg",value="0x11940 \"A string argument.\""@},
19320@{name="fltarg",value="3.5"@}]@},
19321frame=@{level="4",args=[]@}]
19322(@value{GDBP})
19323-stack-list-arguments 0 2 2
19324^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
19325(@value{GDBP})
19326-stack-list-arguments 1 2 2
19327^done,stack-args=[frame=@{level="2",
19328args=[@{name="intarg",value="2"@},
19329@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
19330(@value{GDBP})
19331@end smallexample
19332
19333@c @subheading -stack-list-exception-handlers
19334
19335
19336@subheading The @code{-stack-list-frames} Command
19337@findex -stack-list-frames
19338
19339@subsubheading Synopsis
19340
19341@smallexample
19342 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
19343@end smallexample
19344
19345List the frames currently on the stack. For each frame it displays the
19346following info:
19347
19348@table @samp
19349@item @var{level}
19350The frame number, 0 being the topmost frame, i.e. the innermost function.
19351@item @var{addr}
19352The @code{$pc} value for that frame.
19353@item @var{func}
19354Function name.
19355@item @var{file}
19356File name of the source file where the function lives.
19357@item @var{line}
19358Line number corresponding to the @code{$pc}.
19359@end table
19360
19361If invoked without arguments, this command prints a backtrace for the
19362whole stack. If given two integer arguments, it shows the frames whose
19363levels are between the two arguments (inclusive). If the two arguments
19364are equal, it shows the single frame at the corresponding level.
19365
19366@subsubheading @value{GDBN} Command
19367
19368The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
19369
19370@subsubheading Example
19371
19372Full stack backtrace:
19373
19374@smallexample
19375(@value{GDBP})
19376-stack-list-frames
19377^done,stack=
19378[frame=@{level="0",addr="0x0001076c",func="foo",
76ff342d 19379 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@},
922fbb7b 19380frame=@{level="1",addr="0x000107a4",func="foo",
76ff342d 19381 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19382frame=@{level="2",addr="0x000107a4",func="foo",
76ff342d 19383 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19384frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19385 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19386frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19387 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19388frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19389 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19390frame=@{level="6",addr="0x000107a4",func="foo",
76ff342d 19391 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19392frame=@{level="7",addr="0x000107a4",func="foo",
76ff342d 19393 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19394frame=@{level="8",addr="0x000107a4",func="foo",
76ff342d 19395 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19396frame=@{level="9",addr="0x000107a4",func="foo",
76ff342d 19397 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19398frame=@{level="10",addr="0x000107a4",func="foo",
76ff342d 19399 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19400frame=@{level="11",addr="0x00010738",func="main",
76ff342d 19401 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}]
922fbb7b
AC
19402(@value{GDBP})
19403@end smallexample
19404
19405Show frames between @var{low_frame} and @var{high_frame}:
19406
19407@smallexample
19408(@value{GDBP})
19409-stack-list-frames 3 5
19410^done,stack=
19411[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19412 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19413frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19414 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19415frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19416 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19417(@value{GDBP})
19418@end smallexample
19419
19420Show a single frame:
19421
19422@smallexample
19423(@value{GDBP})
19424-stack-list-frames 3 3
19425^done,stack=
19426[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19427 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19428(@value{GDBP})
19429@end smallexample
19430
19431
19432@subheading The @code{-stack-list-locals} Command
19433@findex -stack-list-locals
19434
19435@subsubheading Synopsis
19436
19437@smallexample
19438 -stack-list-locals @var{print-values}
19439@end smallexample
19440
19441Display the local variable names for the current frame. With an
bc8ced35
NR
19442argument of 0 or @code{--no-values}, prints only the names of the variables.
19443With argument of 1 or @code{--all-values}, prints also their values. With
19444argument of 2 or @code{--simple-values}, prints the name, type and value for
19445simple data types and the name and type for arrays, structures and
19446unions. In this last case, the idea is that the user can see the
19447value of simple data types immediately and he can create variable
19448objects for other data types if he wishes to explore their values in
19449more detail.
922fbb7b
AC
19450
19451@subsubheading @value{GDBN} Command
19452
19453@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
19454
19455@subsubheading Example
19456
19457@smallexample
19458(@value{GDBP})
19459-stack-list-locals 0
19460^done,locals=[name="A",name="B",name="C"]
19461(@value{GDBP})
bc8ced35 19462-stack-list-locals --all-values
922fbb7b 19463^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
bc8ced35
NR
19464 @{name="C",value="@{1, 2, 3@}"@}]
19465-stack-list-locals --simple-values
19466^done,locals=[@{name="A",type="int",value="1"@},
19467 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
922fbb7b
AC
19468(@value{GDBP})
19469@end smallexample
19470
19471
19472@subheading The @code{-stack-select-frame} Command
19473@findex -stack-select-frame
19474
19475@subsubheading Synopsis
19476
19477@smallexample
19478 -stack-select-frame @var{framenum}
19479@end smallexample
19480
19481Change the current frame. Select a different frame @var{framenum} on
19482the stack.
19483
19484@subsubheading @value{GDBN} Command
19485
19486The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
19487@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
19488
19489@subsubheading Example
19490
19491@smallexample
19492(@value{GDBP})
19493-stack-select-frame 2
19494^done
19495(@value{GDBP})
19496@end smallexample
19497
19498@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19499@node GDB/MI Symbol Query
19500@section @sc{gdb/mi} Symbol Query Commands
19501
19502
19503@subheading The @code{-symbol-info-address} Command
19504@findex -symbol-info-address
19505
19506@subsubheading Synopsis
19507
19508@smallexample
19509 -symbol-info-address @var{symbol}
19510@end smallexample
19511
19512Describe where @var{symbol} is stored.
19513
19514@subsubheading @value{GDBN} Command
19515
19516The corresponding @value{GDBN} command is @samp{info address}.
19517
19518@subsubheading Example
19519N.A.
19520
19521
19522@subheading The @code{-symbol-info-file} Command
19523@findex -symbol-info-file
19524
19525@subsubheading Synopsis
19526
19527@smallexample
19528 -symbol-info-file
19529@end smallexample
19530
19531Show the file for the symbol.
19532
19533@subsubheading @value{GDBN} Command
19534
19535There's no equivalent @value{GDBN} command. @code{gdbtk} has
19536@samp{gdb_find_file}.
19537
19538@subsubheading Example
19539N.A.
19540
19541
19542@subheading The @code{-symbol-info-function} Command
19543@findex -symbol-info-function
19544
19545@subsubheading Synopsis
19546
19547@smallexample
19548 -symbol-info-function
19549@end smallexample
19550
19551Show which function the symbol lives in.
19552
19553@subsubheading @value{GDBN} Command
19554
19555@samp{gdb_get_function} in @code{gdbtk}.
19556
19557@subsubheading Example
19558N.A.
19559
19560
19561@subheading The @code{-symbol-info-line} Command
19562@findex -symbol-info-line
19563
19564@subsubheading Synopsis
19565
19566@smallexample
19567 -symbol-info-line
19568@end smallexample
19569
19570Show the core addresses of the code for a source line.
19571
19572@subsubheading @value{GDBN} Command
19573
71952f4c 19574The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
19575@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
19576
19577@subsubheading Example
19578N.A.
19579
19580
19581@subheading The @code{-symbol-info-symbol} Command
19582@findex -symbol-info-symbol
19583
19584@subsubheading Synopsis
19585
19586@smallexample
19587 -symbol-info-symbol @var{addr}
19588@end smallexample
19589
19590Describe what symbol is at location @var{addr}.
19591
19592@subsubheading @value{GDBN} Command
19593
19594The corresponding @value{GDBN} command is @samp{info symbol}.
19595
19596@subsubheading Example
19597N.A.
19598
19599
19600@subheading The @code{-symbol-list-functions} Command
19601@findex -symbol-list-functions
19602
19603@subsubheading Synopsis
19604
19605@smallexample
19606 -symbol-list-functions
19607@end smallexample
19608
19609List the functions in the executable.
19610
19611@subsubheading @value{GDBN} Command
19612
19613@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
19614@samp{gdb_search} in @code{gdbtk}.
19615
19616@subsubheading Example
19617N.A.
19618
19619
32e7087d
JB
19620@subheading The @code{-symbol-list-lines} Command
19621@findex -symbol-list-lines
19622
19623@subsubheading Synopsis
19624
19625@smallexample
19626 -symbol-list-lines @var{filename}
19627@end smallexample
19628
19629Print the list of lines that contain code and their associated program
19630addresses for the given source filename. The entries are sorted in
19631ascending PC order.
19632
19633@subsubheading @value{GDBN} Command
19634
19635There is no corresponding @value{GDBN} command.
19636
19637@subsubheading Example
19638@smallexample
19639(@value{GDBP})
19640-symbol-list-lines basics.c
54ff5908 19641^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
19642(@value{GDBP})
19643@end smallexample
19644
19645
922fbb7b
AC
19646@subheading The @code{-symbol-list-types} Command
19647@findex -symbol-list-types
19648
19649@subsubheading Synopsis
19650
19651@smallexample
19652 -symbol-list-types
19653@end smallexample
19654
19655List all the type names.
19656
19657@subsubheading @value{GDBN} Command
19658
19659The corresponding commands are @samp{info types} in @value{GDBN},
19660@samp{gdb_search} in @code{gdbtk}.
19661
19662@subsubheading Example
19663N.A.
19664
19665
19666@subheading The @code{-symbol-list-variables} Command
19667@findex -symbol-list-variables
19668
19669@subsubheading Synopsis
19670
19671@smallexample
19672 -symbol-list-variables
19673@end smallexample
19674
19675List all the global and static variable names.
19676
19677@subsubheading @value{GDBN} Command
19678
19679@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
19680
19681@subsubheading Example
19682N.A.
19683
19684
19685@subheading The @code{-symbol-locate} Command
19686@findex -symbol-locate
19687
19688@subsubheading Synopsis
19689
19690@smallexample
19691 -symbol-locate
19692@end smallexample
19693
19694@subsubheading @value{GDBN} Command
19695
19696@samp{gdb_loc} in @code{gdbtk}.
19697
19698@subsubheading Example
19699N.A.
19700
19701
19702@subheading The @code{-symbol-type} Command
19703@findex -symbol-type
19704
19705@subsubheading Synopsis
19706
19707@smallexample
19708 -symbol-type @var{variable}
19709@end smallexample
19710
19711Show type of @var{variable}.
19712
19713@subsubheading @value{GDBN} Command
19714
19715The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
19716@samp{gdb_obj_variable}.
19717
19718@subsubheading Example
19719N.A.
19720
19721
19722@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19723@node GDB/MI Target Manipulation
19724@section @sc{gdb/mi} Target Manipulation Commands
19725
19726
19727@subheading The @code{-target-attach} Command
19728@findex -target-attach
19729
19730@subsubheading Synopsis
19731
19732@smallexample
19733 -target-attach @var{pid} | @var{file}
19734@end smallexample
19735
19736Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
19737
19738@subsubheading @value{GDBN} command
19739
19740The corresponding @value{GDBN} command is @samp{attach}.
19741
19742@subsubheading Example
19743N.A.
19744
19745
19746@subheading The @code{-target-compare-sections} Command
19747@findex -target-compare-sections
19748
19749@subsubheading Synopsis
19750
19751@smallexample
19752 -target-compare-sections [ @var{section} ]
19753@end smallexample
19754
19755Compare data of section @var{section} on target to the exec file.
19756Without the argument, all sections are compared.
19757
19758@subsubheading @value{GDBN} Command
19759
19760The @value{GDBN} equivalent is @samp{compare-sections}.
19761
19762@subsubheading Example
19763N.A.
19764
19765
19766@subheading The @code{-target-detach} Command
19767@findex -target-detach
19768
19769@subsubheading Synopsis
19770
19771@smallexample
19772 -target-detach
19773@end smallexample
19774
19775Disconnect from the remote target. There's no output.
19776
19777@subsubheading @value{GDBN} command
19778
19779The corresponding @value{GDBN} command is @samp{detach}.
19780
19781@subsubheading Example
19782
19783@smallexample
19784(@value{GDBP})
19785-target-detach
19786^done
19787(@value{GDBP})
19788@end smallexample
19789
19790
07f31aa6
DJ
19791@subheading The @code{-target-disconnect} Command
19792@findex -target-disconnect
19793
19794@subsubheading Synopsis
19795
19796@example
19797 -target-disconnect
19798@end example
19799
19800Disconnect from the remote target. There's no output.
19801
19802@subsubheading @value{GDBN} command
19803
19804The corresponding @value{GDBN} command is @samp{disconnect}.
19805
19806@subsubheading Example
19807
19808@smallexample
19809(@value{GDBP})
19810-target-disconnect
19811^done
19812(@value{GDBP})
19813@end smallexample
19814
19815
922fbb7b
AC
19816@subheading The @code{-target-download} Command
19817@findex -target-download
19818
19819@subsubheading Synopsis
19820
19821@smallexample
19822 -target-download
19823@end smallexample
19824
19825Loads the executable onto the remote target.
19826It prints out an update message every half second, which includes the fields:
19827
19828@table @samp
19829@item section
19830The name of the section.
19831@item section-sent
19832The size of what has been sent so far for that section.
19833@item section-size
19834The size of the section.
19835@item total-sent
19836The total size of what was sent so far (the current and the previous sections).
19837@item total-size
19838The size of the overall executable to download.
19839@end table
19840
19841@noindent
19842Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
19843@sc{gdb/mi} Output Syntax}).
19844
19845In addition, it prints the name and size of the sections, as they are
19846downloaded. These messages include the following fields:
19847
19848@table @samp
19849@item section
19850The name of the section.
19851@item section-size
19852The size of the section.
19853@item total-size
19854The size of the overall executable to download.
19855@end table
19856
19857@noindent
19858At the end, a summary is printed.
19859
19860@subsubheading @value{GDBN} Command
19861
19862The corresponding @value{GDBN} command is @samp{load}.
19863
19864@subsubheading Example
19865
19866Note: each status message appears on a single line. Here the messages
19867have been broken down so that they can fit onto a page.
19868
19869@smallexample
19870(@value{GDBP})
19871-target-download
19872+download,@{section=".text",section-size="6668",total-size="9880"@}
19873+download,@{section=".text",section-sent="512",section-size="6668",
19874total-sent="512",total-size="9880"@}
19875+download,@{section=".text",section-sent="1024",section-size="6668",
19876total-sent="1024",total-size="9880"@}
19877+download,@{section=".text",section-sent="1536",section-size="6668",
19878total-sent="1536",total-size="9880"@}
19879+download,@{section=".text",section-sent="2048",section-size="6668",
19880total-sent="2048",total-size="9880"@}
19881+download,@{section=".text",section-sent="2560",section-size="6668",
19882total-sent="2560",total-size="9880"@}
19883+download,@{section=".text",section-sent="3072",section-size="6668",
19884total-sent="3072",total-size="9880"@}
19885+download,@{section=".text",section-sent="3584",section-size="6668",
19886total-sent="3584",total-size="9880"@}
19887+download,@{section=".text",section-sent="4096",section-size="6668",
19888total-sent="4096",total-size="9880"@}
19889+download,@{section=".text",section-sent="4608",section-size="6668",
19890total-sent="4608",total-size="9880"@}
19891+download,@{section=".text",section-sent="5120",section-size="6668",
19892total-sent="5120",total-size="9880"@}
19893+download,@{section=".text",section-sent="5632",section-size="6668",
19894total-sent="5632",total-size="9880"@}
19895+download,@{section=".text",section-sent="6144",section-size="6668",
19896total-sent="6144",total-size="9880"@}
19897+download,@{section=".text",section-sent="6656",section-size="6668",
19898total-sent="6656",total-size="9880"@}
19899+download,@{section=".init",section-size="28",total-size="9880"@}
19900+download,@{section=".fini",section-size="28",total-size="9880"@}
19901+download,@{section=".data",section-size="3156",total-size="9880"@}
19902+download,@{section=".data",section-sent="512",section-size="3156",
19903total-sent="7236",total-size="9880"@}
19904+download,@{section=".data",section-sent="1024",section-size="3156",
19905total-sent="7748",total-size="9880"@}
19906+download,@{section=".data",section-sent="1536",section-size="3156",
19907total-sent="8260",total-size="9880"@}
19908+download,@{section=".data",section-sent="2048",section-size="3156",
19909total-sent="8772",total-size="9880"@}
19910+download,@{section=".data",section-sent="2560",section-size="3156",
19911total-sent="9284",total-size="9880"@}
19912+download,@{section=".data",section-sent="3072",section-size="3156",
19913total-sent="9796",total-size="9880"@}
19914^done,address="0x10004",load-size="9880",transfer-rate="6586",
19915write-rate="429"
19916(@value{GDBP})
19917@end smallexample
19918
19919
19920@subheading The @code{-target-exec-status} Command
19921@findex -target-exec-status
19922
19923@subsubheading Synopsis
19924
19925@smallexample
19926 -target-exec-status
19927@end smallexample
19928
19929Provide information on the state of the target (whether it is running or
19930not, for instance).
19931
19932@subsubheading @value{GDBN} Command
19933
19934There's no equivalent @value{GDBN} command.
19935
19936@subsubheading Example
19937N.A.
19938
19939
19940@subheading The @code{-target-list-available-targets} Command
19941@findex -target-list-available-targets
19942
19943@subsubheading Synopsis
19944
19945@smallexample
19946 -target-list-available-targets
19947@end smallexample
19948
19949List the possible targets to connect to.
19950
19951@subsubheading @value{GDBN} Command
19952
19953The corresponding @value{GDBN} command is @samp{help target}.
19954
19955@subsubheading Example
19956N.A.
19957
19958
19959@subheading The @code{-target-list-current-targets} Command
19960@findex -target-list-current-targets
19961
19962@subsubheading Synopsis
19963
19964@smallexample
19965 -target-list-current-targets
19966@end smallexample
19967
19968Describe the current target.
19969
19970@subsubheading @value{GDBN} Command
19971
19972The corresponding information is printed by @samp{info file} (among
19973other things).
19974
19975@subsubheading Example
19976N.A.
19977
19978
19979@subheading The @code{-target-list-parameters} Command
19980@findex -target-list-parameters
19981
19982@subsubheading Synopsis
19983
19984@smallexample
19985 -target-list-parameters
19986@end smallexample
19987
19988@c ????
19989
19990@subsubheading @value{GDBN} Command
19991
19992No equivalent.
19993
19994@subsubheading Example
19995N.A.
19996
19997
19998@subheading The @code{-target-select} Command
19999@findex -target-select
20000
20001@subsubheading Synopsis
20002
20003@smallexample
20004 -target-select @var{type} @var{parameters @dots{}}
20005@end smallexample
20006
20007Connect @value{GDBN} to the remote target. This command takes two args:
20008
20009@table @samp
20010@item @var{type}
20011The type of target, for instance @samp{async}, @samp{remote}, etc.
20012@item @var{parameters}
20013Device names, host names and the like. @xref{Target Commands, ,
20014Commands for managing targets}, for more details.
20015@end table
20016
20017The output is a connection notification, followed by the address at
20018which the target program is, in the following form:
20019
20020@smallexample
20021^connected,addr="@var{address}",func="@var{function name}",
20022 args=[@var{arg list}]
20023@end smallexample
20024
20025@subsubheading @value{GDBN} Command
20026
20027The corresponding @value{GDBN} command is @samp{target}.
20028
20029@subsubheading Example
20030
20031@smallexample
20032(@value{GDBP})
20033-target-select async /dev/ttya
20034^connected,addr="0xfe00a300",func="??",args=[]
20035(@value{GDBP})
20036@end smallexample
20037
20038@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20039@node GDB/MI Thread Commands
20040@section @sc{gdb/mi} Thread Commands
20041
20042
20043@subheading The @code{-thread-info} Command
20044@findex -thread-info
20045
20046@subsubheading Synopsis
20047
20048@smallexample
20049 -thread-info
20050@end smallexample
20051
20052@subsubheading @value{GDBN} command
20053
20054No equivalent.
20055
20056@subsubheading Example
20057N.A.
20058
20059
20060@subheading The @code{-thread-list-all-threads} Command
20061@findex -thread-list-all-threads
20062
20063@subsubheading Synopsis
20064
20065@smallexample
20066 -thread-list-all-threads
20067@end smallexample
20068
20069@subsubheading @value{GDBN} Command
20070
20071The equivalent @value{GDBN} command is @samp{info threads}.
20072
20073@subsubheading Example
20074N.A.
20075
20076
20077@subheading The @code{-thread-list-ids} Command
20078@findex -thread-list-ids
20079
20080@subsubheading Synopsis
20081
20082@smallexample
20083 -thread-list-ids
20084@end smallexample
20085
20086Produces a list of the currently known @value{GDBN} thread ids. At the
20087end of the list it also prints the total number of such threads.
20088
20089@subsubheading @value{GDBN} Command
20090
20091Part of @samp{info threads} supplies the same information.
20092
20093@subsubheading Example
20094
20095No threads present, besides the main process:
20096
20097@smallexample
20098(@value{GDBP})
20099-thread-list-ids
20100^done,thread-ids=@{@},number-of-threads="0"
20101(@value{GDBP})
20102@end smallexample
20103
20104
20105Several threads:
20106
20107@smallexample
20108(@value{GDBP})
20109-thread-list-ids
20110^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20111number-of-threads="3"
20112(@value{GDBP})
20113@end smallexample
20114
20115
20116@subheading The @code{-thread-select} Command
20117@findex -thread-select
20118
20119@subsubheading Synopsis
20120
20121@smallexample
20122 -thread-select @var{threadnum}
20123@end smallexample
20124
20125Make @var{threadnum} the current thread. It prints the number of the new
20126current thread, and the topmost frame for that thread.
20127
20128@subsubheading @value{GDBN} Command
20129
20130The corresponding @value{GDBN} command is @samp{thread}.
20131
20132@subsubheading Example
20133
20134@smallexample
20135(@value{GDBP})
20136-exec-next
20137^running
20138(@value{GDBP})
20139*stopped,reason="end-stepping-range",thread-id="2",line="187",
20140file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
20141(@value{GDBP})
20142-thread-list-ids
20143^done,
20144thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20145number-of-threads="3"
20146(@value{GDBP})
20147-thread-select 3
20148^done,new-thread-id="3",
20149frame=@{level="0",func="vprintf",
20150args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
20151@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
20152(@value{GDBP})
20153@end smallexample
20154
20155@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20156@node GDB/MI Tracepoint Commands
20157@section @sc{gdb/mi} Tracepoint Commands
20158
20159The tracepoint commands are not yet implemented.
20160
20161@c @subheading -trace-actions
20162
20163@c @subheading -trace-delete
20164
20165@c @subheading -trace-disable
20166
20167@c @subheading -trace-dump
20168
20169@c @subheading -trace-enable
20170
20171@c @subheading -trace-exists
20172
20173@c @subheading -trace-find
20174
20175@c @subheading -trace-frame-number
20176
20177@c @subheading -trace-info
20178
20179@c @subheading -trace-insert
20180
20181@c @subheading -trace-list
20182
20183@c @subheading -trace-pass-count
20184
20185@c @subheading -trace-save
20186
20187@c @subheading -trace-start
20188
20189@c @subheading -trace-stop
20190
20191
20192@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20193@node GDB/MI Variable Objects
20194@section @sc{gdb/mi} Variable Objects
20195
20196
20197@subheading Motivation for Variable Objects in @sc{gdb/mi}
20198
20199For the implementation of a variable debugger window (locals, watched
20200expressions, etc.), we are proposing the adaptation of the existing code
20201used by @code{Insight}.
20202
20203The two main reasons for that are:
20204
20205@enumerate 1
20206@item
20207It has been proven in practice (it is already on its second generation).
20208
20209@item
20210It will shorten development time (needless to say how important it is
20211now).
20212@end enumerate
20213
20214The original interface was designed to be used by Tcl code, so it was
20215slightly changed so it could be used through @sc{gdb/mi}. This section
20216describes the @sc{gdb/mi} operations that will be available and gives some
20217hints about their use.
20218
20219@emph{Note}: In addition to the set of operations described here, we
20220expect the @sc{gui} implementation of a variable window to require, at
20221least, the following operations:
20222
20223@itemize @bullet
20224@item @code{-gdb-show} @code{output-radix}
20225@item @code{-stack-list-arguments}
20226@item @code{-stack-list-locals}
20227@item @code{-stack-select-frame}
20228@end itemize
20229
20230@subheading Introduction to Variable Objects in @sc{gdb/mi}
20231
20232@cindex variable objects in @sc{gdb/mi}
20233The basic idea behind variable objects is the creation of a named object
20234to represent a variable, an expression, a memory location or even a CPU
20235register. For each object created, a set of operations is available for
20236examining or changing its properties.
20237
20238Furthermore, complex data types, such as C structures, are represented
20239in a tree format. For instance, the @code{struct} type variable is the
20240root and the children will represent the struct members. If a child
20241is itself of a complex type, it will also have children of its own.
20242Appropriate language differences are handled for C, C@t{++} and Java.
20243
20244When returning the actual values of the objects, this facility allows
20245for the individual selection of the display format used in the result
20246creation. It can be chosen among: binary, decimal, hexadecimal, octal
20247and natural. Natural refers to a default format automatically
20248chosen based on the variable type (like decimal for an @code{int}, hex
20249for pointers, etc.).
20250
20251The following is the complete set of @sc{gdb/mi} operations defined to
20252access this functionality:
20253
20254@multitable @columnfractions .4 .6
20255@item @strong{Operation}
20256@tab @strong{Description}
20257
20258@item @code{-var-create}
20259@tab create a variable object
20260@item @code{-var-delete}
20261@tab delete the variable object and its children
20262@item @code{-var-set-format}
20263@tab set the display format of this variable
20264@item @code{-var-show-format}
20265@tab show the display format of this variable
20266@item @code{-var-info-num-children}
20267@tab tells how many children this object has
20268@item @code{-var-list-children}
20269@tab return a list of the object's children
20270@item @code{-var-info-type}
20271@tab show the type of this variable object
20272@item @code{-var-info-expression}
20273@tab print what this variable object represents
20274@item @code{-var-show-attributes}
20275@tab is this variable editable? does it exist here?
20276@item @code{-var-evaluate-expression}
20277@tab get the value of this variable
20278@item @code{-var-assign}
20279@tab set the value of this variable
20280@item @code{-var-update}
20281@tab update the variable and its children
20282@end multitable
20283
20284In the next subsection we describe each operation in detail and suggest
20285how it can be used.
20286
20287@subheading Description And Use of Operations on Variable Objects
20288
20289@subheading The @code{-var-create} Command
20290@findex -var-create
20291
20292@subsubheading Synopsis
20293
20294@smallexample
20295 -var-create @{@var{name} | "-"@}
20296 @{@var{frame-addr} | "*"@} @var{expression}
20297@end smallexample
20298
20299This operation creates a variable object, which allows the monitoring of
20300a variable, the result of an expression, a memory cell or a CPU
20301register.
20302
20303The @var{name} parameter is the string by which the object can be
20304referenced. It must be unique. If @samp{-} is specified, the varobj
20305system will generate a string ``varNNNNNN'' automatically. It will be
20306unique provided that one does not specify @var{name} on that format.
20307The command fails if a duplicate name is found.
20308
20309The frame under which the expression should be evaluated can be
20310specified by @var{frame-addr}. A @samp{*} indicates that the current
20311frame should be used.
20312
20313@var{expression} is any expression valid on the current language set (must not
20314begin with a @samp{*}), or one of the following:
20315
20316@itemize @bullet
20317@item
20318@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
20319
20320@item
20321@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
20322
20323@item
20324@samp{$@var{regname}} --- a CPU register name
20325@end itemize
20326
20327@subsubheading Result
20328
20329This operation returns the name, number of children and the type of the
20330object created. Type is returned as a string as the ones generated by
20331the @value{GDBN} CLI:
20332
20333@smallexample
20334 name="@var{name}",numchild="N",type="@var{type}"
20335@end smallexample
20336
20337
20338@subheading The @code{-var-delete} Command
20339@findex -var-delete
20340
20341@subsubheading Synopsis
20342
20343@smallexample
20344 -var-delete @var{name}
20345@end smallexample
20346
20347Deletes a previously created variable object and all of its children.
20348
20349Returns an error if the object @var{name} is not found.
20350
20351
20352@subheading The @code{-var-set-format} Command
20353@findex -var-set-format
20354
20355@subsubheading Synopsis
20356
20357@smallexample
20358 -var-set-format @var{name} @var{format-spec}
20359@end smallexample
20360
20361Sets the output format for the value of the object @var{name} to be
20362@var{format-spec}.
20363
20364The syntax for the @var{format-spec} is as follows:
20365
20366@smallexample
20367 @var{format-spec} @expansion{}
20368 @{binary | decimal | hexadecimal | octal | natural@}
20369@end smallexample
20370
20371
20372@subheading The @code{-var-show-format} Command
20373@findex -var-show-format
20374
20375@subsubheading Synopsis
20376
20377@smallexample
20378 -var-show-format @var{name}
20379@end smallexample
20380
20381Returns the format used to display the value of the object @var{name}.
20382
20383@smallexample
20384 @var{format} @expansion{}
20385 @var{format-spec}
20386@end smallexample
20387
20388
20389@subheading The @code{-var-info-num-children} Command
20390@findex -var-info-num-children
20391
20392@subsubheading Synopsis
20393
20394@smallexample
20395 -var-info-num-children @var{name}
20396@end smallexample
20397
20398Returns the number of children of a variable object @var{name}:
20399
20400@smallexample
20401 numchild=@var{n}
20402@end smallexample
20403
20404
20405@subheading The @code{-var-list-children} Command
20406@findex -var-list-children
20407
20408@subsubheading Synopsis
20409
20410@smallexample
bc8ced35 20411 -var-list-children [@var{print-values}] @var{name}
922fbb7b
AC
20412@end smallexample
20413
bc8ced35
NR
20414Returns a list of the children of the specified variable object. With
20415just the variable object name as an argument or with an optional
20416preceding argument of 0 or @code{--no-values}, prints only the names of the
20417variables. With an optional preceding argument of 1 or @code{--all-values},
20418also prints their values.
20419
20420@subsubheading Example
922fbb7b
AC
20421
20422@smallexample
bc8ced35
NR
20423(@value{GDBP})
20424 -var-list-children n
922fbb7b
AC
20425 numchild=@var{n},children=[@{name=@var{name},
20426 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
bc8ced35
NR
20427(@value{GDBP})
20428 -var-list-children --all-values n
20429 numchild=@var{n},children=[@{name=@var{name},
20430 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
20431@end smallexample
20432
20433
20434@subheading The @code{-var-info-type} Command
20435@findex -var-info-type
20436
20437@subsubheading Synopsis
20438
20439@smallexample
20440 -var-info-type @var{name}
20441@end smallexample
20442
20443Returns the type of the specified variable @var{name}. The type is
20444returned as a string in the same format as it is output by the
20445@value{GDBN} CLI:
20446
20447@smallexample
20448 type=@var{typename}
20449@end smallexample
20450
20451
20452@subheading The @code{-var-info-expression} Command
20453@findex -var-info-expression
20454
20455@subsubheading Synopsis
20456
20457@smallexample
20458 -var-info-expression @var{name}
20459@end smallexample
20460
20461Returns what is represented by the variable object @var{name}:
20462
20463@smallexample
20464 lang=@var{lang-spec},exp=@var{expression}
20465@end smallexample
20466
20467@noindent
20468where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
20469
20470@subheading The @code{-var-show-attributes} Command
20471@findex -var-show-attributes
20472
20473@subsubheading Synopsis
20474
20475@smallexample
20476 -var-show-attributes @var{name}
20477@end smallexample
20478
20479List attributes of the specified variable object @var{name}:
20480
20481@smallexample
20482 status=@var{attr} [ ( ,@var{attr} )* ]
20483@end smallexample
20484
20485@noindent
20486where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
20487
20488@subheading The @code{-var-evaluate-expression} Command
20489@findex -var-evaluate-expression
20490
20491@subsubheading Synopsis
20492
20493@smallexample
20494 -var-evaluate-expression @var{name}
20495@end smallexample
20496
20497Evaluates the expression that is represented by the specified variable
20498object and returns its value as a string in the current format specified
20499for the object:
20500
20501@smallexample
20502 value=@var{value}
20503@end smallexample
20504
20505Note that one must invoke @code{-var-list-children} for a variable
20506before the value of a child variable can be evaluated.
20507
20508@subheading The @code{-var-assign} Command
20509@findex -var-assign
20510
20511@subsubheading Synopsis
20512
20513@smallexample
20514 -var-assign @var{name} @var{expression}
20515@end smallexample
20516
20517Assigns the value of @var{expression} to the variable object specified
20518by @var{name}. The object must be @samp{editable}. If the variable's
b383017d 20519value is altered by the assign, the variable will show up in any
922fbb7b
AC
20520subsequent @code{-var-update} list.
20521
20522@subsubheading Example
20523
20524@smallexample
20525(@value{GDBP})
20526-var-assign var1 3
20527^done,value="3"
20528(@value{GDBP})
20529-var-update *
20530^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
20531(@value{GDBP})
20532@end smallexample
20533
20534@subheading The @code{-var-update} Command
20535@findex -var-update
20536
20537@subsubheading Synopsis
20538
20539@smallexample
20540 -var-update @{@var{name} | "*"@}
20541@end smallexample
20542
20543Update the value of the variable object @var{name} by evaluating its
20544expression after fetching all the new values from memory or registers.
20545A @samp{*} causes all existing variable objects to be updated.
20546
20547
20548@node Annotations
20549@chapter @value{GDBN} Annotations
20550
086432e2
AC
20551This chapter describes annotations in @value{GDBN}. Annotations were
20552designed to interface @value{GDBN} to graphical user interfaces or other
20553similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
20554relatively high level.
20555
086432e2
AC
20556The annotation mechanism has largely been superseeded by @sc{gdb/mi}
20557(@pxref{GDB/MI}).
20558
922fbb7b
AC
20559@ignore
20560This is Edition @value{EDITION}, @value{DATE}.
20561@end ignore
20562
20563@menu
20564* Annotations Overview:: What annotations are; the general syntax.
20565* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
20566* Prompting:: Annotations marking @value{GDBN}'s need for input.
20567* Errors:: Annotations for error messages.
922fbb7b
AC
20568* Invalidation:: Some annotations describe things now invalid.
20569* Annotations for Running::
20570 Whether the program is running, how it stopped, etc.
20571* Source Annotations:: Annotations describing source code.
922fbb7b
AC
20572@end menu
20573
20574@node Annotations Overview
20575@section What is an Annotation?
20576@cindex annotations
20577
922fbb7b
AC
20578Annotations start with a newline character, two @samp{control-z}
20579characters, and the name of the annotation. If there is no additional
20580information associated with this annotation, the name of the annotation
20581is followed immediately by a newline. If there is additional
20582information, the name of the annotation is followed by a space, the
20583additional information, and a newline. The additional information
20584cannot contain newline characters.
20585
20586Any output not beginning with a newline and two @samp{control-z}
20587characters denotes literal output from @value{GDBN}. Currently there is
20588no need for @value{GDBN} to output a newline followed by two
20589@samp{control-z} characters, but if there was such a need, the
20590annotations could be extended with an @samp{escape} annotation which
20591means those three characters as output.
20592
086432e2
AC
20593The annotation @var{level}, which is specified using the
20594@option{--annotate} command line option (@pxref{Mode Options}), controls
20595how much information @value{GDBN} prints together with its prompt,
20596values of expressions, source lines, and other types of output. Level 0
20597is for no anntations, level 1 is for use when @value{GDBN} is run as a
20598subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
20599for programs that control @value{GDBN}, and level 2 annotations have
20600been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
20601Interface, annotate, GDB's Obsolete Annotations}).
20602
20603@table @code
20604@kindex set annotate
20605@item set annotate @var{level}
e09f16f9 20606The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 20607annotations to the specified @var{level}.
9c16f35a
EZ
20608
20609@item show annotate
20610@kindex show annotate
20611Show the current annotation level.
09d4efe1
EZ
20612@end table
20613
20614This chapter describes level 3 annotations.
086432e2 20615
922fbb7b
AC
20616A simple example of starting up @value{GDBN} with annotations is:
20617
20618@smallexample
086432e2
AC
20619$ @kbd{gdb --annotate=3}
20620GNU gdb 6.0
20621Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
20622GDB is free software, covered by the GNU General Public License,
20623and you are welcome to change it and/or distribute copies of it
20624under certain conditions.
20625Type "show copying" to see the conditions.
20626There is absolutely no warranty for GDB. Type "show warranty"
20627for details.
086432e2 20628This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
20629
20630^Z^Zpre-prompt
f7dc1244 20631(@value{GDBP})
922fbb7b 20632^Z^Zprompt
086432e2 20633@kbd{quit}
922fbb7b
AC
20634
20635^Z^Zpost-prompt
b383017d 20636$
922fbb7b
AC
20637@end smallexample
20638
20639Here @samp{quit} is input to @value{GDBN}; the rest is output from
20640@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
20641denotes a @samp{control-z} character) are annotations; the rest is
20642output from @value{GDBN}.
20643
20644@node Server Prefix
20645@section The Server Prefix
20646@cindex server prefix for annotations
20647
20648To issue a command to @value{GDBN} without affecting certain aspects of
20649the state which is seen by users, prefix it with @samp{server }. This
20650means that this command will not affect the command history, nor will it
20651affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
20652pressed on a line by itself.
20653
20654The server prefix does not affect the recording of values into the value
20655history; to print a value without recording it into the value history,
20656use the @code{output} command instead of the @code{print} command.
20657
922fbb7b
AC
20658@node Prompting
20659@section Annotation for @value{GDBN} Input
20660
20661@cindex annotations for prompts
20662When @value{GDBN} prompts for input, it annotates this fact so it is possible
20663to know when to send output, when the output from a given command is
20664over, etc.
20665
20666Different kinds of input each have a different @dfn{input type}. Each
20667input type has three annotations: a @code{pre-} annotation, which
20668denotes the beginning of any prompt which is being output, a plain
20669annotation, which denotes the end of the prompt, and then a @code{post-}
20670annotation which denotes the end of any echo which may (or may not) be
20671associated with the input. For example, the @code{prompt} input type
20672features the following annotations:
20673
20674@smallexample
20675^Z^Zpre-prompt
20676^Z^Zprompt
20677^Z^Zpost-prompt
20678@end smallexample
20679
20680The input types are
20681
20682@table @code
20683@findex pre-prompt
20684@findex prompt
20685@findex post-prompt
20686@item prompt
20687When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
20688
20689@findex pre-commands
20690@findex commands
20691@findex post-commands
20692@item commands
20693When @value{GDBN} prompts for a set of commands, like in the @code{commands}
20694command. The annotations are repeated for each command which is input.
20695
20696@findex pre-overload-choice
20697@findex overload-choice
20698@findex post-overload-choice
20699@item overload-choice
20700When @value{GDBN} wants the user to select between various overloaded functions.
20701
20702@findex pre-query
20703@findex query
20704@findex post-query
20705@item query
20706When @value{GDBN} wants the user to confirm a potentially dangerous operation.
20707
20708@findex pre-prompt-for-continue
20709@findex prompt-for-continue
20710@findex post-prompt-for-continue
20711@item prompt-for-continue
20712When @value{GDBN} is asking the user to press return to continue. Note: Don't
20713expect this to work well; instead use @code{set height 0} to disable
20714prompting. This is because the counting of lines is buggy in the
20715presence of annotations.
20716@end table
20717
20718@node Errors
20719@section Errors
20720@cindex annotations for errors, warnings and interrupts
20721
20722@findex quit
20723@smallexample
20724^Z^Zquit
20725@end smallexample
20726
20727This annotation occurs right before @value{GDBN} responds to an interrupt.
20728
20729@findex error
20730@smallexample
20731^Z^Zerror
20732@end smallexample
20733
20734This annotation occurs right before @value{GDBN} responds to an error.
20735
20736Quit and error annotations indicate that any annotations which @value{GDBN} was
20737in the middle of may end abruptly. For example, if a
20738@code{value-history-begin} annotation is followed by a @code{error}, one
20739cannot expect to receive the matching @code{value-history-end}. One
20740cannot expect not to receive it either, however; an error annotation
20741does not necessarily mean that @value{GDBN} is immediately returning all the way
20742to the top level.
20743
20744@findex error-begin
20745A quit or error annotation may be preceded by
20746
20747@smallexample
20748^Z^Zerror-begin
20749@end smallexample
20750
20751Any output between that and the quit or error annotation is the error
20752message.
20753
20754Warning messages are not yet annotated.
20755@c If we want to change that, need to fix warning(), type_error(),
20756@c range_error(), and possibly other places.
20757
922fbb7b
AC
20758@node Invalidation
20759@section Invalidation Notices
20760
20761@cindex annotations for invalidation messages
20762The following annotations say that certain pieces of state may have
20763changed.
20764
20765@table @code
20766@findex frames-invalid
20767@item ^Z^Zframes-invalid
20768
20769The frames (for example, output from the @code{backtrace} command) may
20770have changed.
20771
20772@findex breakpoints-invalid
20773@item ^Z^Zbreakpoints-invalid
20774
20775The breakpoints may have changed. For example, the user just added or
20776deleted a breakpoint.
20777@end table
20778
20779@node Annotations for Running
20780@section Running the Program
20781@cindex annotations for running programs
20782
20783@findex starting
20784@findex stopping
20785When the program starts executing due to a @value{GDBN} command such as
b383017d 20786@code{step} or @code{continue},
922fbb7b
AC
20787
20788@smallexample
20789^Z^Zstarting
20790@end smallexample
20791
b383017d 20792is output. When the program stops,
922fbb7b
AC
20793
20794@smallexample
20795^Z^Zstopped
20796@end smallexample
20797
20798is output. Before the @code{stopped} annotation, a variety of
20799annotations describe how the program stopped.
20800
20801@table @code
20802@findex exited
20803@item ^Z^Zexited @var{exit-status}
20804The program exited, and @var{exit-status} is the exit status (zero for
20805successful exit, otherwise nonzero).
20806
20807@findex signalled
20808@findex signal-name
20809@findex signal-name-end
20810@findex signal-string
20811@findex signal-string-end
20812@item ^Z^Zsignalled
20813The program exited with a signal. After the @code{^Z^Zsignalled}, the
20814annotation continues:
20815
20816@smallexample
20817@var{intro-text}
20818^Z^Zsignal-name
20819@var{name}
20820^Z^Zsignal-name-end
20821@var{middle-text}
20822^Z^Zsignal-string
20823@var{string}
20824^Z^Zsignal-string-end
20825@var{end-text}
20826@end smallexample
20827
20828@noindent
20829where @var{name} is the name of the signal, such as @code{SIGILL} or
20830@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
20831as @code{Illegal Instruction} or @code{Segmentation fault}.
20832@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
20833user's benefit and have no particular format.
20834
20835@findex signal
20836@item ^Z^Zsignal
20837The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
20838just saying that the program received the signal, not that it was
20839terminated with it.
20840
20841@findex breakpoint
20842@item ^Z^Zbreakpoint @var{number}
20843The program hit breakpoint number @var{number}.
20844
20845@findex watchpoint
20846@item ^Z^Zwatchpoint @var{number}
20847The program hit watchpoint number @var{number}.
20848@end table
20849
20850@node Source Annotations
20851@section Displaying Source
20852@cindex annotations for source display
20853
20854@findex source
20855The following annotation is used instead of displaying source code:
20856
20857@smallexample
20858^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
20859@end smallexample
20860
20861where @var{filename} is an absolute file name indicating which source
20862file, @var{line} is the line number within that file (where 1 is the
20863first line in the file), @var{character} is the character position
20864within the file (where 0 is the first character in the file) (for most
20865debug formats this will necessarily point to the beginning of a line),
20866@var{middle} is @samp{middle} if @var{addr} is in the middle of the
20867line, or @samp{beg} if @var{addr} is at the beginning of the line, and
20868@var{addr} is the address in the target program associated with the
20869source which is being displayed. @var{addr} is in the form @samp{0x}
20870followed by one or more lowercase hex digits (note that this does not
20871depend on the language).
20872
8e04817f
AC
20873@node GDB Bugs
20874@chapter Reporting Bugs in @value{GDBN}
20875@cindex bugs in @value{GDBN}
20876@cindex reporting bugs in @value{GDBN}
c906108c 20877
8e04817f 20878Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 20879
8e04817f
AC
20880Reporting a bug may help you by bringing a solution to your problem, or it
20881may not. But in any case the principal function of a bug report is to help
20882the entire community by making the next version of @value{GDBN} work better. Bug
20883reports are your contribution to the maintenance of @value{GDBN}.
c906108c 20884
8e04817f
AC
20885In order for a bug report to serve its purpose, you must include the
20886information that enables us to fix the bug.
c4555f82
SC
20887
20888@menu
8e04817f
AC
20889* Bug Criteria:: Have you found a bug?
20890* Bug Reporting:: How to report bugs
c4555f82
SC
20891@end menu
20892
8e04817f
AC
20893@node Bug Criteria
20894@section Have you found a bug?
20895@cindex bug criteria
c4555f82 20896
8e04817f 20897If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
20898
20899@itemize @bullet
8e04817f
AC
20900@cindex fatal signal
20901@cindex debugger crash
20902@cindex crash of debugger
c4555f82 20903@item
8e04817f
AC
20904If the debugger gets a fatal signal, for any input whatever, that is a
20905@value{GDBN} bug. Reliable debuggers never crash.
20906
20907@cindex error on valid input
20908@item
20909If @value{GDBN} produces an error message for valid input, that is a
20910bug. (Note that if you're cross debugging, the problem may also be
20911somewhere in the connection to the target.)
c4555f82 20912
8e04817f 20913@cindex invalid input
c4555f82 20914@item
8e04817f
AC
20915If @value{GDBN} does not produce an error message for invalid input,
20916that is a bug. However, you should note that your idea of
20917``invalid input'' might be our idea of ``an extension'' or ``support
20918for traditional practice''.
20919
20920@item
20921If you are an experienced user of debugging tools, your suggestions
20922for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
20923@end itemize
20924
8e04817f
AC
20925@node Bug Reporting
20926@section How to report bugs
20927@cindex bug reports
20928@cindex @value{GDBN} bugs, reporting
20929
20930A number of companies and individuals offer support for @sc{gnu} products.
20931If you obtained @value{GDBN} from a support organization, we recommend you
20932contact that organization first.
20933
20934You can find contact information for many support companies and
20935individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
20936distribution.
20937@c should add a web page ref...
20938
129188f6
AC
20939In any event, we also recommend that you submit bug reports for
20940@value{GDBN}. The prefered method is to submit them directly using
20941@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
20942page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
20943be used.
8e04817f
AC
20944
20945@strong{Do not send bug reports to @samp{info-gdb}, or to
20946@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
20947not want to receive bug reports. Those that do have arranged to receive
20948@samp{bug-gdb}.
20949
20950The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
20951serves as a repeater. The mailing list and the newsgroup carry exactly
20952the same messages. Often people think of posting bug reports to the
20953newsgroup instead of mailing them. This appears to work, but it has one
20954problem which can be crucial: a newsgroup posting often lacks a mail
20955path back to the sender. Thus, if we need to ask for more information,
20956we may be unable to reach you. For this reason, it is better to send
20957bug reports to the mailing list.
c4555f82 20958
8e04817f
AC
20959The fundamental principle of reporting bugs usefully is this:
20960@strong{report all the facts}. If you are not sure whether to state a
20961fact or leave it out, state it!
c4555f82 20962
8e04817f
AC
20963Often people omit facts because they think they know what causes the
20964problem and assume that some details do not matter. Thus, you might
20965assume that the name of the variable you use in an example does not matter.
20966Well, probably it does not, but one cannot be sure. Perhaps the bug is a
20967stray memory reference which happens to fetch from the location where that
20968name is stored in memory; perhaps, if the name were different, the contents
20969of that location would fool the debugger into doing the right thing despite
20970the bug. Play it safe and give a specific, complete example. That is the
20971easiest thing for you to do, and the most helpful.
c4555f82 20972
8e04817f
AC
20973Keep in mind that the purpose of a bug report is to enable us to fix the
20974bug. It may be that the bug has been reported previously, but neither
20975you nor we can know that unless your bug report is complete and
20976self-contained.
c4555f82 20977
8e04817f
AC
20978Sometimes people give a few sketchy facts and ask, ``Does this ring a
20979bell?'' Those bug reports are useless, and we urge everyone to
20980@emph{refuse to respond to them} except to chide the sender to report
20981bugs properly.
20982
20983To enable us to fix the bug, you should include all these things:
c4555f82
SC
20984
20985@itemize @bullet
20986@item
8e04817f
AC
20987The version of @value{GDBN}. @value{GDBN} announces it if you start
20988with no arguments; you can also print it at any time using @code{show
20989version}.
c4555f82 20990
8e04817f
AC
20991Without this, we will not know whether there is any point in looking for
20992the bug in the current version of @value{GDBN}.
c4555f82
SC
20993
20994@item
8e04817f
AC
20995The type of machine you are using, and the operating system name and
20996version number.
c4555f82
SC
20997
20998@item
8e04817f
AC
20999What compiler (and its version) was used to compile @value{GDBN}---e.g.
21000``@value{GCC}--2.8.1''.
c4555f82
SC
21001
21002@item
8e04817f
AC
21003What compiler (and its version) was used to compile the program you are
21004debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
21005C Compiler''. For GCC, you can say @code{gcc --version} to get this
21006information; for other compilers, see the documentation for those
21007compilers.
c4555f82 21008
8e04817f
AC
21009@item
21010The command arguments you gave the compiler to compile your example and
21011observe the bug. For example, did you use @samp{-O}? To guarantee
21012you will not omit something important, list them all. A copy of the
21013Makefile (or the output from make) is sufficient.
c4555f82 21014
8e04817f
AC
21015If we were to try to guess the arguments, we would probably guess wrong
21016and then we might not encounter the bug.
c4555f82 21017
8e04817f
AC
21018@item
21019A complete input script, and all necessary source files, that will
21020reproduce the bug.
c4555f82 21021
8e04817f
AC
21022@item
21023A description of what behavior you observe that you believe is
21024incorrect. For example, ``It gets a fatal signal.''
c4555f82 21025
8e04817f
AC
21026Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
21027will certainly notice it. But if the bug is incorrect output, we might
21028not notice unless it is glaringly wrong. You might as well not give us
21029a chance to make a mistake.
c4555f82 21030
8e04817f
AC
21031Even if the problem you experience is a fatal signal, you should still
21032say so explicitly. Suppose something strange is going on, such as, your
21033copy of @value{GDBN} is out of synch, or you have encountered a bug in
21034the C library on your system. (This has happened!) Your copy might
21035crash and ours would not. If you told us to expect a crash, then when
21036ours fails to crash, we would know that the bug was not happening for
21037us. If you had not told us to expect a crash, then we would not be able
21038to draw any conclusion from our observations.
c4555f82 21039
e0c07bf0
MC
21040@pindex script
21041@cindex recording a session script
21042To collect all this information, you can use a session recording program
21043such as @command{script}, which is available on many Unix systems.
21044Just run your @value{GDBN} session inside @command{script} and then
21045include the @file{typescript} file with your bug report.
21046
21047Another way to record a @value{GDBN} session is to run @value{GDBN}
21048inside Emacs and then save the entire buffer to a file.
21049
8e04817f
AC
21050@item
21051If you wish to suggest changes to the @value{GDBN} source, send us context
21052diffs. If you even discuss something in the @value{GDBN} source, refer to
21053it by context, not by line number.
c4555f82 21054
8e04817f
AC
21055The line numbers in our development sources will not match those in your
21056sources. Your line numbers would convey no useful information to us.
c4555f82 21057
8e04817f 21058@end itemize
c4555f82 21059
8e04817f 21060Here are some things that are not necessary:
c4555f82 21061
8e04817f
AC
21062@itemize @bullet
21063@item
21064A description of the envelope of the bug.
c4555f82 21065
8e04817f
AC
21066Often people who encounter a bug spend a lot of time investigating
21067which changes to the input file will make the bug go away and which
21068changes will not affect it.
c4555f82 21069
8e04817f
AC
21070This is often time consuming and not very useful, because the way we
21071will find the bug is by running a single example under the debugger
21072with breakpoints, not by pure deduction from a series of examples.
21073We recommend that you save your time for something else.
c4555f82 21074
8e04817f
AC
21075Of course, if you can find a simpler example to report @emph{instead}
21076of the original one, that is a convenience for us. Errors in the
21077output will be easier to spot, running under the debugger will take
21078less time, and so on.
c4555f82 21079
8e04817f
AC
21080However, simplification is not vital; if you do not want to do this,
21081report the bug anyway and send us the entire test case you used.
c4555f82 21082
8e04817f
AC
21083@item
21084A patch for the bug.
c4555f82 21085
8e04817f
AC
21086A patch for the bug does help us if it is a good one. But do not omit
21087the necessary information, such as the test case, on the assumption that
21088a patch is all we need. We might see problems with your patch and decide
21089to fix the problem another way, or we might not understand it at all.
c4555f82 21090
8e04817f
AC
21091Sometimes with a program as complicated as @value{GDBN} it is very hard to
21092construct an example that will make the program follow a certain path
21093through the code. If you do not send us the example, we will not be able
21094to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 21095
8e04817f
AC
21096And if we cannot understand what bug you are trying to fix, or why your
21097patch should be an improvement, we will not install it. A test case will
21098help us to understand.
c4555f82 21099
8e04817f
AC
21100@item
21101A guess about what the bug is or what it depends on.
c4555f82 21102
8e04817f
AC
21103Such guesses are usually wrong. Even we cannot guess right about such
21104things without first using the debugger to find the facts.
21105@end itemize
c4555f82 21106
8e04817f
AC
21107@c The readline documentation is distributed with the readline code
21108@c and consists of the two following files:
21109@c rluser.texinfo
21110@c inc-hist.texinfo
21111@c Use -I with makeinfo to point to the appropriate directory,
21112@c environment var TEXINPUTS with TeX.
21113@include rluser.texinfo
21114@include inc-hist.texinfo
c4555f82 21115
c4555f82 21116
8e04817f
AC
21117@node Formatting Documentation
21118@appendix Formatting Documentation
c4555f82 21119
8e04817f
AC
21120@cindex @value{GDBN} reference card
21121@cindex reference card
21122The @value{GDBN} 4 release includes an already-formatted reference card, ready
21123for printing with PostScript or Ghostscript, in the @file{gdb}
21124subdirectory of the main source directory@footnote{In
21125@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
21126release.}. If you can use PostScript or Ghostscript with your printer,
21127you can print the reference card immediately with @file{refcard.ps}.
c4555f82 21128
8e04817f
AC
21129The release also includes the source for the reference card. You
21130can format it, using @TeX{}, by typing:
c4555f82 21131
474c8240 21132@smallexample
8e04817f 21133make refcard.dvi
474c8240 21134@end smallexample
c4555f82 21135
8e04817f
AC
21136The @value{GDBN} reference card is designed to print in @dfn{landscape}
21137mode on US ``letter'' size paper;
21138that is, on a sheet 11 inches wide by 8.5 inches
21139high. You will need to specify this form of printing as an option to
21140your @sc{dvi} output program.
c4555f82 21141
8e04817f 21142@cindex documentation
c4555f82 21143
8e04817f
AC
21144All the documentation for @value{GDBN} comes as part of the machine-readable
21145distribution. The documentation is written in Texinfo format, which is
21146a documentation system that uses a single source file to produce both
21147on-line information and a printed manual. You can use one of the Info
21148formatting commands to create the on-line version of the documentation
21149and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 21150
8e04817f
AC
21151@value{GDBN} includes an already formatted copy of the on-line Info
21152version of this manual in the @file{gdb} subdirectory. The main Info
21153file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
21154subordinate files matching @samp{gdb.info*} in the same directory. If
21155necessary, you can print out these files, or read them with any editor;
21156but they are easier to read using the @code{info} subsystem in @sc{gnu}
21157Emacs or the standalone @code{info} program, available as part of the
21158@sc{gnu} Texinfo distribution.
c4555f82 21159
8e04817f
AC
21160If you want to format these Info files yourself, you need one of the
21161Info formatting programs, such as @code{texinfo-format-buffer} or
21162@code{makeinfo}.
c4555f82 21163
8e04817f
AC
21164If you have @code{makeinfo} installed, and are in the top level
21165@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
21166version @value{GDBVN}), you can make the Info file by typing:
c4555f82 21167
474c8240 21168@smallexample
8e04817f
AC
21169cd gdb
21170make gdb.info
474c8240 21171@end smallexample
c4555f82 21172
8e04817f
AC
21173If you want to typeset and print copies of this manual, you need @TeX{},
21174a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
21175Texinfo definitions file.
c4555f82 21176
8e04817f
AC
21177@TeX{} is a typesetting program; it does not print files directly, but
21178produces output files called @sc{dvi} files. To print a typeset
21179document, you need a program to print @sc{dvi} files. If your system
21180has @TeX{} installed, chances are it has such a program. The precise
21181command to use depends on your system; @kbd{lpr -d} is common; another
21182(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
21183require a file name without any extension or a @samp{.dvi} extension.
c4555f82 21184
8e04817f
AC
21185@TeX{} also requires a macro definitions file called
21186@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
21187written in Texinfo format. On its own, @TeX{} cannot either read or
21188typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
21189and is located in the @file{gdb-@var{version-number}/texinfo}
21190directory.
c4555f82 21191
8e04817f
AC
21192If you have @TeX{} and a @sc{dvi} printer program installed, you can
21193typeset and print this manual. First switch to the the @file{gdb}
21194subdirectory of the main source directory (for example, to
21195@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 21196
474c8240 21197@smallexample
8e04817f 21198make gdb.dvi
474c8240 21199@end smallexample
c4555f82 21200
8e04817f 21201Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 21202
8e04817f
AC
21203@node Installing GDB
21204@appendix Installing @value{GDBN}
21205@cindex configuring @value{GDBN}
21206@cindex installation
94e91d6d 21207@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 21208
8e04817f
AC
21209@value{GDBN} comes with a @code{configure} script that automates the process
21210of preparing @value{GDBN} for installation; you can then use @code{make} to
21211build the @code{gdb} program.
21212@iftex
21213@c irrelevant in info file; it's as current as the code it lives with.
21214@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
21215look at the @file{README} file in the sources; we may have improved the
21216installation procedures since publishing this manual.}
21217@end iftex
c4555f82 21218
8e04817f
AC
21219The @value{GDBN} distribution includes all the source code you need for
21220@value{GDBN} in a single directory, whose name is usually composed by
21221appending the version number to @samp{gdb}.
c4555f82 21222
8e04817f
AC
21223For example, the @value{GDBN} version @value{GDBVN} distribution is in the
21224@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 21225
8e04817f
AC
21226@table @code
21227@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
21228script for configuring @value{GDBN} and all its supporting libraries
c4555f82 21229
8e04817f
AC
21230@item gdb-@value{GDBVN}/gdb
21231the source specific to @value{GDBN} itself
c4555f82 21232
8e04817f
AC
21233@item gdb-@value{GDBVN}/bfd
21234source for the Binary File Descriptor library
c906108c 21235
8e04817f
AC
21236@item gdb-@value{GDBVN}/include
21237@sc{gnu} include files
c906108c 21238
8e04817f
AC
21239@item gdb-@value{GDBVN}/libiberty
21240source for the @samp{-liberty} free software library
c906108c 21241
8e04817f
AC
21242@item gdb-@value{GDBVN}/opcodes
21243source for the library of opcode tables and disassemblers
c906108c 21244
8e04817f
AC
21245@item gdb-@value{GDBVN}/readline
21246source for the @sc{gnu} command-line interface
c906108c 21247
8e04817f
AC
21248@item gdb-@value{GDBVN}/glob
21249source for the @sc{gnu} filename pattern-matching subroutine
c906108c 21250
8e04817f
AC
21251@item gdb-@value{GDBVN}/mmalloc
21252source for the @sc{gnu} memory-mapped malloc package
21253@end table
c906108c 21254
8e04817f
AC
21255The simplest way to configure and build @value{GDBN} is to run @code{configure}
21256from the @file{gdb-@var{version-number}} source directory, which in
21257this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 21258
8e04817f
AC
21259First switch to the @file{gdb-@var{version-number}} source directory
21260if you are not already in it; then run @code{configure}. Pass the
21261identifier for the platform on which @value{GDBN} will run as an
21262argument.
c906108c 21263
8e04817f 21264For example:
c906108c 21265
474c8240 21266@smallexample
8e04817f
AC
21267cd gdb-@value{GDBVN}
21268./configure @var{host}
21269make
474c8240 21270@end smallexample
c906108c 21271
8e04817f
AC
21272@noindent
21273where @var{host} is an identifier such as @samp{sun4} or
21274@samp{decstation}, that identifies the platform where @value{GDBN} will run.
21275(You can often leave off @var{host}; @code{configure} tries to guess the
21276correct value by examining your system.)
c906108c 21277
8e04817f
AC
21278Running @samp{configure @var{host}} and then running @code{make} builds the
21279@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
21280libraries, then @code{gdb} itself. The configured source files, and the
21281binaries, are left in the corresponding source directories.
c906108c 21282
8e04817f
AC
21283@need 750
21284@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
21285system does not recognize this automatically when you run a different
21286shell, you may need to run @code{sh} on it explicitly:
c906108c 21287
474c8240 21288@smallexample
8e04817f 21289sh configure @var{host}
474c8240 21290@end smallexample
c906108c 21291
8e04817f
AC
21292If you run @code{configure} from a directory that contains source
21293directories for multiple libraries or programs, such as the
21294@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
21295creates configuration files for every directory level underneath (unless
21296you tell it not to, with the @samp{--norecursion} option).
21297
94e91d6d
MC
21298You should run the @code{configure} script from the top directory in the
21299source tree, the @file{gdb-@var{version-number}} directory. If you run
21300@code{configure} from one of the subdirectories, you will configure only
21301that subdirectory. That is usually not what you want. In particular,
21302if you run the first @code{configure} from the @file{gdb} subdirectory
21303of the @file{gdb-@var{version-number}} directory, you will omit the
21304configuration of @file{bfd}, @file{readline}, and other sibling
21305directories of the @file{gdb} subdirectory. This leads to build errors
21306about missing include files such as @file{bfd/bfd.h}.
c906108c 21307
8e04817f
AC
21308You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
21309However, you should make sure that the shell on your path (named by
21310the @samp{SHELL} environment variable) is publicly readable. Remember
21311that @value{GDBN} uses the shell to start your program---some systems refuse to
21312let @value{GDBN} debug child processes whose programs are not readable.
c906108c 21313
8e04817f
AC
21314@menu
21315* Separate Objdir:: Compiling @value{GDBN} in another directory
21316* Config Names:: Specifying names for hosts and targets
21317* Configure Options:: Summary of options for configure
21318@end menu
c906108c 21319
8e04817f
AC
21320@node Separate Objdir
21321@section Compiling @value{GDBN} in another directory
c906108c 21322
8e04817f
AC
21323If you want to run @value{GDBN} versions for several host or target machines,
21324you need a different @code{gdb} compiled for each combination of
21325host and target. @code{configure} is designed to make this easy by
21326allowing you to generate each configuration in a separate subdirectory,
21327rather than in the source directory. If your @code{make} program
21328handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
21329@code{make} in each of these directories builds the @code{gdb}
21330program specified there.
c906108c 21331
8e04817f
AC
21332To build @code{gdb} in a separate directory, run @code{configure}
21333with the @samp{--srcdir} option to specify where to find the source.
21334(You also need to specify a path to find @code{configure}
21335itself from your working directory. If the path to @code{configure}
21336would be the same as the argument to @samp{--srcdir}, you can leave out
21337the @samp{--srcdir} option; it is assumed.)
c906108c 21338
8e04817f
AC
21339For example, with version @value{GDBVN}, you can build @value{GDBN} in a
21340separate directory for a Sun 4 like this:
c906108c 21341
474c8240 21342@smallexample
8e04817f
AC
21343@group
21344cd gdb-@value{GDBVN}
21345mkdir ../gdb-sun4
21346cd ../gdb-sun4
21347../gdb-@value{GDBVN}/configure sun4
21348make
21349@end group
474c8240 21350@end smallexample
c906108c 21351
8e04817f
AC
21352When @code{configure} builds a configuration using a remote source
21353directory, it creates a tree for the binaries with the same structure
21354(and using the same names) as the tree under the source directory. In
21355the example, you'd find the Sun 4 library @file{libiberty.a} in the
21356directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
21357@file{gdb-sun4/gdb}.
c906108c 21358
94e91d6d
MC
21359Make sure that your path to the @file{configure} script has just one
21360instance of @file{gdb} in it. If your path to @file{configure} looks
21361like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
21362one subdirectory of @value{GDBN}, not the whole package. This leads to
21363build errors about missing include files such as @file{bfd/bfd.h}.
21364
8e04817f
AC
21365One popular reason to build several @value{GDBN} configurations in separate
21366directories is to configure @value{GDBN} for cross-compiling (where
21367@value{GDBN} runs on one machine---the @dfn{host}---while debugging
21368programs that run on another machine---the @dfn{target}).
21369You specify a cross-debugging target by
21370giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 21371
8e04817f
AC
21372When you run @code{make} to build a program or library, you must run
21373it in a configured directory---whatever directory you were in when you
21374called @code{configure} (or one of its subdirectories).
c906108c 21375
8e04817f
AC
21376The @code{Makefile} that @code{configure} generates in each source
21377directory also runs recursively. If you type @code{make} in a source
21378directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
21379directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
21380will build all the required libraries, and then build GDB.
c906108c 21381
8e04817f
AC
21382When you have multiple hosts or targets configured in separate
21383directories, you can run @code{make} on them in parallel (for example,
21384if they are NFS-mounted on each of the hosts); they will not interfere
21385with each other.
c906108c 21386
8e04817f
AC
21387@node Config Names
21388@section Specifying names for hosts and targets
c906108c 21389
8e04817f
AC
21390The specifications used for hosts and targets in the @code{configure}
21391script are based on a three-part naming scheme, but some short predefined
21392aliases are also supported. The full naming scheme encodes three pieces
21393of information in the following pattern:
c906108c 21394
474c8240 21395@smallexample
8e04817f 21396@var{architecture}-@var{vendor}-@var{os}
474c8240 21397@end smallexample
c906108c 21398
8e04817f
AC
21399For example, you can use the alias @code{sun4} as a @var{host} argument,
21400or as the value for @var{target} in a @code{--target=@var{target}}
21401option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 21402
8e04817f
AC
21403The @code{configure} script accompanying @value{GDBN} does not provide
21404any query facility to list all supported host and target names or
21405aliases. @code{configure} calls the Bourne shell script
21406@code{config.sub} to map abbreviations to full names; you can read the
21407script, if you wish, or you can use it to test your guesses on
21408abbreviations---for example:
c906108c 21409
8e04817f
AC
21410@smallexample
21411% sh config.sub i386-linux
21412i386-pc-linux-gnu
21413% sh config.sub alpha-linux
21414alpha-unknown-linux-gnu
21415% sh config.sub hp9k700
21416hppa1.1-hp-hpux
21417% sh config.sub sun4
21418sparc-sun-sunos4.1.1
21419% sh config.sub sun3
21420m68k-sun-sunos4.1.1
21421% sh config.sub i986v
21422Invalid configuration `i986v': machine `i986v' not recognized
21423@end smallexample
c906108c 21424
8e04817f
AC
21425@noindent
21426@code{config.sub} is also distributed in the @value{GDBN} source
21427directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 21428
8e04817f
AC
21429@node Configure Options
21430@section @code{configure} options
c906108c 21431
8e04817f
AC
21432Here is a summary of the @code{configure} options and arguments that
21433are most often useful for building @value{GDBN}. @code{configure} also has
21434several other options not listed here. @inforef{What Configure
21435Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 21436
474c8240 21437@smallexample
8e04817f
AC
21438configure @r{[}--help@r{]}
21439 @r{[}--prefix=@var{dir}@r{]}
21440 @r{[}--exec-prefix=@var{dir}@r{]}
21441 @r{[}--srcdir=@var{dirname}@r{]}
21442 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
21443 @r{[}--target=@var{target}@r{]}
21444 @var{host}
474c8240 21445@end smallexample
c906108c 21446
8e04817f
AC
21447@noindent
21448You may introduce options with a single @samp{-} rather than
21449@samp{--} if you prefer; but you may abbreviate option names if you use
21450@samp{--}.
c906108c 21451
8e04817f
AC
21452@table @code
21453@item --help
21454Display a quick summary of how to invoke @code{configure}.
c906108c 21455
8e04817f
AC
21456@item --prefix=@var{dir}
21457Configure the source to install programs and files under directory
21458@file{@var{dir}}.
c906108c 21459
8e04817f
AC
21460@item --exec-prefix=@var{dir}
21461Configure the source to install programs under directory
21462@file{@var{dir}}.
c906108c 21463
8e04817f
AC
21464@c avoid splitting the warning from the explanation:
21465@need 2000
21466@item --srcdir=@var{dirname}
21467@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
21468@code{make} that implements the @code{VPATH} feature.}@*
21469Use this option to make configurations in directories separate from the
21470@value{GDBN} source directories. Among other things, you can use this to
21471build (or maintain) several configurations simultaneously, in separate
21472directories. @code{configure} writes configuration specific files in
21473the current directory, but arranges for them to use the source in the
21474directory @var{dirname}. @code{configure} creates directories under
21475the working directory in parallel to the source directories below
21476@var{dirname}.
c906108c 21477
8e04817f
AC
21478@item --norecursion
21479Configure only the directory level where @code{configure} is executed; do not
21480propagate configuration to subdirectories.
c906108c 21481
8e04817f
AC
21482@item --target=@var{target}
21483Configure @value{GDBN} for cross-debugging programs running on the specified
21484@var{target}. Without this option, @value{GDBN} is configured to debug
21485programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 21486
8e04817f 21487There is no convenient way to generate a list of all available targets.
c906108c 21488
8e04817f
AC
21489@item @var{host} @dots{}
21490Configure @value{GDBN} to run on the specified @var{host}.
c906108c 21491
8e04817f
AC
21492There is no convenient way to generate a list of all available hosts.
21493@end table
c906108c 21494
8e04817f
AC
21495There are many other options available as well, but they are generally
21496needed for special purposes only.
c906108c 21497
8e04817f
AC
21498@node Maintenance Commands
21499@appendix Maintenance Commands
21500@cindex maintenance commands
21501@cindex internal commands
c906108c 21502
8e04817f 21503In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
21504includes a number of commands intended for @value{GDBN} developers,
21505that are not documented elsewhere in this manual. These commands are
da316a69
EZ
21506provided here for reference. (For commands that turn on debugging
21507messages, see @ref{Debugging Output}.)
c906108c 21508
8e04817f 21509@table @code
09d4efe1
EZ
21510@kindex maint agent
21511@item maint agent @var{expression}
21512Translate the given @var{expression} into remote agent bytecodes.
21513This command is useful for debugging the Agent Expression mechanism
21514(@pxref{Agent Expressions}).
21515
8e04817f
AC
21516@kindex maint info breakpoints
21517@item @anchor{maint info breakpoints}maint info breakpoints
21518Using the same format as @samp{info breakpoints}, display both the
21519breakpoints you've set explicitly, and those @value{GDBN} is using for
21520internal purposes. Internal breakpoints are shown with negative
21521breakpoint numbers. The type column identifies what kind of breakpoint
21522is shown:
c906108c 21523
8e04817f
AC
21524@table @code
21525@item breakpoint
21526Normal, explicitly set breakpoint.
c906108c 21527
8e04817f
AC
21528@item watchpoint
21529Normal, explicitly set watchpoint.
c906108c 21530
8e04817f
AC
21531@item longjmp
21532Internal breakpoint, used to handle correctly stepping through
21533@code{longjmp} calls.
c906108c 21534
8e04817f
AC
21535@item longjmp resume
21536Internal breakpoint at the target of a @code{longjmp}.
c906108c 21537
8e04817f
AC
21538@item until
21539Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 21540
8e04817f
AC
21541@item finish
21542Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 21543
8e04817f
AC
21544@item shlib events
21545Shared library events.
c906108c 21546
8e04817f 21547@end table
c906108c 21548
09d4efe1
EZ
21549@kindex maint check-symtabs
21550@item maint check-symtabs
21551Check the consistency of psymtabs and symtabs.
21552
21553@kindex maint cplus first_component
21554@item maint cplus first_component @var{name}
21555Print the first C@t{++} class/namespace component of @var{name}.
21556
21557@kindex maint cplus namespace
21558@item maint cplus namespace
21559Print the list of possible C@t{++} namespaces.
21560
21561@kindex maint demangle
21562@item maint demangle @var{name}
21563Demangle a C@t{++} or Objective-C manled @var{name}.
21564
21565@kindex maint deprecate
21566@kindex maint undeprecate
21567@cindex deprecated commands
21568@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
21569@itemx maint undeprecate @var{command}
21570Deprecate or undeprecate the named @var{command}. Deprecated commands
21571cause @value{GDBN} to issue a warning when you use them. The optional
21572argument @var{replacement} says which newer command should be used in
21573favor of the deprecated one; if it is given, @value{GDBN} will mention
21574the replacement as part of the warning.
21575
21576@kindex maint dump-me
21577@item maint dump-me
721c2651 21578@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 21579Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
21580This is supported only on systems which support aborting a program
21581with the @code{SIGQUIT} signal.
09d4efe1 21582
8d30a00d
AC
21583@kindex maint internal-error
21584@kindex maint internal-warning
09d4efe1
EZ
21585@item maint internal-error @r{[}@var{message-text}@r{]}
21586@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
21587Cause @value{GDBN} to call the internal function @code{internal_error}
21588or @code{internal_warning} and hence behave as though an internal error
21589or internal warning has been detected. In addition to reporting the
21590internal problem, these functions give the user the opportunity to
21591either quit @value{GDBN} or create a core file of the current
21592@value{GDBN} session.
21593
09d4efe1
EZ
21594These commands take an optional parameter @var{message-text} that is
21595used as the text of the error or warning message.
21596
21597Here's an example of using @code{indernal-error}:
21598
8d30a00d 21599@smallexample
f7dc1244 21600(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
21601@dots{}/maint.c:121: internal-error: testing, 1, 2
21602A problem internal to GDB has been detected. Further
21603debugging may prove unreliable.
21604Quit this debugging session? (y or n) @kbd{n}
21605Create a core file? (y or n) @kbd{n}
f7dc1244 21606(@value{GDBP})
8d30a00d
AC
21607@end smallexample
21608
09d4efe1
EZ
21609@kindex maint packet
21610@item maint packet @var{text}
21611If @value{GDBN} is talking to an inferior via the serial protocol,
21612then this command sends the string @var{text} to the inferior, and
21613displays the response packet. @value{GDBN} supplies the initial
21614@samp{$} character, the terminating @samp{#} character, and the
21615checksum.
21616
21617@kindex maint print architecture
21618@item maint print architecture @r{[}@var{file}@r{]}
21619Print the entire architecture configuration. The optional argument
21620@var{file} names the file where the output goes.
8d30a00d 21621
00905d52
AC
21622@kindex maint print dummy-frames
21623@item maint print dummy-frames
00905d52
AC
21624Prints the contents of @value{GDBN}'s internal dummy-frame stack.
21625
21626@smallexample
f7dc1244 21627(@value{GDBP}) @kbd{b add}
00905d52 21628@dots{}
f7dc1244 21629(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
21630Breakpoint 2, add (a=2, b=3) at @dots{}
2163158 return (a + b);
21632The program being debugged stopped while in a function called from GDB.
21633@dots{}
f7dc1244 21634(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
216350x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
21636 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
21637 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 21638(@value{GDBP})
00905d52
AC
21639@end smallexample
21640
21641Takes an optional file parameter.
21642
0680b120
AC
21643@kindex maint print registers
21644@kindex maint print raw-registers
21645@kindex maint print cooked-registers
617073a9 21646@kindex maint print register-groups
09d4efe1
EZ
21647@item maint print registers @r{[}@var{file}@r{]}
21648@itemx maint print raw-registers @r{[}@var{file}@r{]}
21649@itemx maint print cooked-registers @r{[}@var{file}@r{]}
21650@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
21651Print @value{GDBN}'s internal register data structures.
21652
617073a9
AC
21653The command @code{maint print raw-registers} includes the contents of
21654the raw register cache; the command @code{maint print cooked-registers}
21655includes the (cooked) value of all registers; and the command
21656@code{maint print register-groups} includes the groups that each
21657register is a member of. @xref{Registers,, Registers, gdbint,
21658@value{GDBN} Internals}.
0680b120 21659
09d4efe1
EZ
21660These commands take an optional parameter, a file name to which to
21661write the information.
0680b120 21662
617073a9 21663@kindex maint print reggroups
09d4efe1
EZ
21664@item maint print reggroups @r{[}@var{file}@r{]}
21665Print @value{GDBN}'s internal register group data structures. The
21666optional argument @var{file} tells to what file to write the
21667information.
617073a9 21668
09d4efe1 21669The register groups info looks like this:
617073a9
AC
21670
21671@smallexample
f7dc1244 21672(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
21673 Group Type
21674 general user
21675 float user
21676 all user
21677 vector user
21678 system user
21679 save internal
21680 restore internal
617073a9
AC
21681@end smallexample
21682
09d4efe1
EZ
21683@kindex flushregs
21684@item flushregs
21685This command forces @value{GDBN} to flush its internal register cache.
21686
21687@kindex maint print objfiles
21688@cindex info for known object files
21689@item maint print objfiles
21690Print a dump of all known object files. For each object file, this
21691command prints its name, address in memory, and all of its psymtabs
21692and symtabs.
21693
21694@kindex maint print statistics
21695@cindex bcache statistics
21696@item maint print statistics
21697This command prints, for each object file in the program, various data
21698about that object file followed by the byte cache (@dfn{bcache})
21699statistics for the object file. The objfile data includes the number
21700of minimal, partical, full, and stabs symbols, the number of types
21701defined by the objfile, the number of as yet unexpanded psym tables,
21702the number of line tables and string tables, and the amount of memory
21703used by the various tables. The bcache statistics include the counts,
21704sizes, and counts of duplicates of all and unique objects, max,
21705average, and median entry size, total memory used and its overhead and
21706savings, and various measures of the hash table size and chain
21707lengths.
21708
21709@kindex maint print type
21710@cindex type chain of a data type
21711@item maint print type @var{expr}
21712Print the type chain for a type specified by @var{expr}. The argument
21713can be either a type name or a symbol. If it is a symbol, the type of
21714that symbol is described. The type chain produced by this command is
21715a recursive definition of the data type as stored in @value{GDBN}'s
21716data structures, including its flags and contained types.
21717
21718@kindex maint set dwarf2 max-cache-age
21719@kindex maint show dwarf2 max-cache-age
21720@item maint set dwarf2 max-cache-age
21721@itemx maint show dwarf2 max-cache-age
21722Control the DWARF 2 compilation unit cache.
21723
21724@cindex DWARF 2 compilation units cache
21725In object files with inter-compilation-unit references, such as those
21726produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
21727reader needs to frequently refer to previously read compilation units.
21728This setting controls how long a compilation unit will remain in the
21729cache if it is not referenced. A higher limit means that cached
21730compilation units will be stored in memory longer, and more total
21731memory will be used. Setting it to zero disables caching, which will
21732slow down @value{GDBN} startup, but reduce memory consumption.
21733
e7ba9c65
DJ
21734@kindex maint set profile
21735@kindex maint show profile
21736@cindex profiling GDB
21737@item maint set profile
21738@itemx maint show profile
21739Control profiling of @value{GDBN}.
21740
21741Profiling will be disabled until you use the @samp{maint set profile}
21742command to enable it. When you enable profiling, the system will begin
21743collecting timing and execution count data; when you disable profiling or
21744exit @value{GDBN}, the results will be written to a log file. Remember that
21745if you use profiling, @value{GDBN} will overwrite the profiling log file
21746(often called @file{gmon.out}). If you have a record of important profiling
21747data in a @file{gmon.out} file, be sure to move it to a safe location.
21748
21749Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 21750compiled with the @samp{-pg} compiler option.
e7ba9c65 21751
09d4efe1
EZ
21752@kindex maint show-debug-regs
21753@cindex x86 hardware debug registers
21754@item maint show-debug-regs
21755Control whether to show variables that mirror the x86 hardware debug
21756registers. Use @code{ON} to enable, @code{OFF} to disable. If
21757enabled, the debug registers values are shown when GDB inserts or
21758removes a hardware breakpoint or watchpoint, and when the inferior
21759triggers a hardware-assisted breakpoint or watchpoint.
21760
21761@kindex maint space
21762@cindex memory used by commands
21763@item maint space
21764Control whether to display memory usage for each command. If set to a
21765nonzero value, @value{GDBN} will display how much memory each command
21766took, following the command's own output. This can also be requested
21767by invoking @value{GDBN} with the @option{--statistics} command-line
21768switch (@pxref{Mode Options}).
21769
21770@kindex maint time
21771@cindex time of command execution
21772@item maint time
21773Control whether to display the execution time for each command. If
21774set to a nonzero value, @value{GDBN} will display how much time it
21775took to execute each command, following the command's own output.
21776This can also be requested by invoking @value{GDBN} with the
21777@option{--statistics} command-line switch (@pxref{Mode Options}).
21778
21779@kindex maint translate-address
21780@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
21781Find the symbol stored at the location specified by the address
21782@var{addr} and an optional section name @var{section}. If found,
21783@value{GDBN} prints the name of the closest symbol and an offset from
21784the symbol's location to the specified address. This is similar to
21785the @code{info address} command (@pxref{Symbols}), except that this
21786command also allows to find symbols in other sections.
ae038cb0 21787
8e04817f 21788@end table
c906108c 21789
9c16f35a
EZ
21790The following command is useful for non-interactive invocations of
21791@value{GDBN}, such as in the test suite.
21792
21793@table @code
21794@item set watchdog @var{nsec}
21795@kindex set watchdog
21796@cindex watchdog timer
21797@cindex timeout for commands
21798Set the maximum number of seconds @value{GDBN} will wait for the
21799target operation to finish. If this time expires, @value{GDBN}
21800reports and error and the command is aborted.
21801
21802@item show watchdog
21803Show the current setting of the target wait timeout.
21804@end table
c906108c 21805
e0ce93ac 21806@node Remote Protocol
8e04817f 21807@appendix @value{GDBN} Remote Serial Protocol
c906108c 21808
ee2d5c50
AC
21809@menu
21810* Overview::
21811* Packets::
21812* Stop Reply Packets::
21813* General Query Packets::
21814* Register Packet Format::
21815* Examples::
0ce1b118 21816* File-I/O remote protocol extension::
ee2d5c50
AC
21817@end menu
21818
21819@node Overview
21820@section Overview
21821
8e04817f
AC
21822There may be occasions when you need to know something about the
21823protocol---for example, if there is only one serial port to your target
21824machine, you might want your program to do something special if it
21825recognizes a packet meant for @value{GDBN}.
c906108c 21826
d2c6833e 21827In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 21828transmitted and received data respectfully.
c906108c 21829
8e04817f
AC
21830@cindex protocol, @value{GDBN} remote serial
21831@cindex serial protocol, @value{GDBN} remote
21832@cindex remote serial protocol
21833All @value{GDBN} commands and responses (other than acknowledgments) are
21834sent as a @var{packet}. A @var{packet} is introduced with the character
21835@samp{$}, the actual @var{packet-data}, and the terminating character
21836@samp{#} followed by a two-digit @var{checksum}:
c906108c 21837
474c8240 21838@smallexample
8e04817f 21839@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 21840@end smallexample
8e04817f 21841@noindent
c906108c 21842
8e04817f
AC
21843@cindex checksum, for @value{GDBN} remote
21844@noindent
21845The two-digit @var{checksum} is computed as the modulo 256 sum of all
21846characters between the leading @samp{$} and the trailing @samp{#} (an
21847eight bit unsigned checksum).
c906108c 21848
8e04817f
AC
21849Implementors should note that prior to @value{GDBN} 5.0 the protocol
21850specification also included an optional two-digit @var{sequence-id}:
c906108c 21851
474c8240 21852@smallexample
8e04817f 21853@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 21854@end smallexample
c906108c 21855
8e04817f
AC
21856@cindex sequence-id, for @value{GDBN} remote
21857@noindent
21858That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
21859has never output @var{sequence-id}s. Stubs that handle packets added
21860since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 21861
8e04817f
AC
21862@cindex acknowledgment, for @value{GDBN} remote
21863When either the host or the target machine receives a packet, the first
21864response expected is an acknowledgment: either @samp{+} (to indicate
21865the package was received correctly) or @samp{-} (to request
21866retransmission):
c906108c 21867
474c8240 21868@smallexample
d2c6833e
AC
21869-> @code{$}@var{packet-data}@code{#}@var{checksum}
21870<- @code{+}
474c8240 21871@end smallexample
8e04817f 21872@noindent
53a5351d 21873
8e04817f
AC
21874The host (@value{GDBN}) sends @var{command}s, and the target (the
21875debugging stub incorporated in your program) sends a @var{response}. In
21876the case of step and continue @var{command}s, the response is only sent
21877when the operation has completed (the target has again stopped).
c906108c 21878
8e04817f
AC
21879@var{packet-data} consists of a sequence of characters with the
21880exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
21881exceptions).
c906108c 21882
8e04817f 21883Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 21884@cindex remote protocol, field separator
8e04817f 21885@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 21886@sc{hex} with leading zeros suppressed.
c906108c 21887
8e04817f
AC
21888Implementors should note that prior to @value{GDBN} 5.0, the character
21889@samp{:} could not appear as the third character in a packet (as it
21890would potentially conflict with the @var{sequence-id}).
c906108c 21891
8e04817f
AC
21892Response @var{data} can be run-length encoded to save space. A @samp{*}
21893means that the next character is an @sc{ascii} encoding giving a repeat count
21894which stands for that many repetitions of the character preceding the
21895@samp{*}. The encoding is @code{n+29}, yielding a printable character
21896where @code{n >=3} (which is where rle starts to win). The printable
21897characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
21898value greater than 126 should not be used.
c906108c 21899
8e04817f 21900So:
474c8240 21901@smallexample
8e04817f 21902"@code{0* }"
474c8240 21903@end smallexample
8e04817f
AC
21904@noindent
21905means the same as "0000".
c906108c 21906
8e04817f
AC
21907The error response returned for some packets includes a two character
21908error number. That number is not well defined.
c906108c 21909
8e04817f
AC
21910For any @var{command} not supported by the stub, an empty response
21911(@samp{$#00}) should be returned. That way it is possible to extend the
21912protocol. A newer @value{GDBN} can tell if a packet is supported based
21913on that response.
c906108c 21914
b383017d
RM
21915A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
21916@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 21917optional.
c906108c 21918
ee2d5c50
AC
21919@node Packets
21920@section Packets
21921
21922The following table provides a complete list of all currently defined
21923@var{command}s and their corresponding response @var{data}.
9c16f35a
EZ
21924@xref{File-I/O remote protocol extension}, for details about the File
21925I/O extension of the remote protocol.
ee2d5c50
AC
21926
21927@table @r
21928
21929@item @code{!} --- extended mode
21930@cindex @code{!} packet
21931
8e04817f
AC
21932Enable extended mode. In extended mode, the remote server is made
21933persistent. The @samp{R} packet is used to restart the program being
21934debugged.
ee2d5c50
AC
21935
21936Reply:
21937@table @samp
21938@item OK
8e04817f 21939The remote target both supports and has enabled extended mode.
ee2d5c50 21940@end table
c906108c 21941
ee2d5c50
AC
21942@item @code{?} --- last signal
21943@cindex @code{?} packet
c906108c 21944
ee2d5c50
AC
21945Indicate the reason the target halted. The reply is the same as for
21946step and continue.
c906108c 21947
ee2d5c50
AC
21948Reply:
21949@xref{Stop Reply Packets}, for the reply specifications.
21950
21951@item @code{a} --- reserved
21952
21953Reserved for future use.
21954
21955@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
21956@cindex @code{A} packet
c906108c 21957
8e04817f
AC
21958Initialized @samp{argv[]} array passed into program. @var{arglen}
21959specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
21960See @code{gdbserver} for more details.
21961
21962Reply:
21963@table @samp
21964@item OK
21965@item E@var{NN}
21966@end table
21967
21968@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
21969@cindex @code{b} packet
21970
21971Change the serial line speed to @var{baud}.
21972
21973JTC: @emph{When does the transport layer state change? When it's
21974received, or after the ACK is transmitted. In either case, there are
21975problems if the command or the acknowledgment packet is dropped.}
21976
21977Stan: @emph{If people really wanted to add something like this, and get
21978it working for the first time, they ought to modify ser-unix.c to send
21979some kind of out-of-band message to a specially-setup stub and have the
21980switch happen "in between" packets, so that from remote protocol's point
21981of view, nothing actually happened.}
21982
21983@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
21984@cindex @code{B} packet
21985
8e04817f 21986Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
21987breakpoint at @var{addr}.
21988
21989This packet has been replaced by the @samp{Z} and @samp{z} packets
21990(@pxref{insert breakpoint or watchpoint packet}).
c906108c 21991
ee2d5c50
AC
21992@item @code{c}@var{addr} --- continue
21993@cindex @code{c} packet
21994
21995@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 21996current address.
c906108c 21997
ee2d5c50
AC
21998Reply:
21999@xref{Stop Reply Packets}, for the reply specifications.
22000
22001@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
22002@cindex @code{C} packet
22003
8e04817f
AC
22004Continue with signal @var{sig} (hex signal number). If
22005@code{;}@var{addr} is omitted, resume at same address.
c906108c 22006
ee2d5c50
AC
22007Reply:
22008@xref{Stop Reply Packets}, for the reply specifications.
c906108c 22009
ee2d5c50
AC
22010@item @code{d} --- toggle debug @strong{(deprecated)}
22011@cindex @code{d} packet
22012
22013Toggle debug flag.
22014
22015@item @code{D} --- detach
22016@cindex @code{D} packet
22017
22018Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 22019before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
22020
22021Reply:
22022@table @samp
22023@item @emph{no response}
8e04817f 22024@value{GDBN} does not check for any response after sending this packet.
ee2d5c50 22025@end table
c906108c 22026
ee2d5c50 22027@item @code{e} --- reserved
c906108c 22028
ee2d5c50 22029Reserved for future use.
c906108c 22030
ee2d5c50 22031@item @code{E} --- reserved
c906108c 22032
ee2d5c50 22033Reserved for future use.
c906108c 22034
ee2d5c50
AC
22035@item @code{f} --- reserved
22036
22037Reserved for future use.
22038
0ce1b118
CV
22039@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
22040@cindex @code{F} packet
ee2d5c50 22041
0ce1b118
CV
22042This packet is send by @value{GDBN} as reply to a @code{F} request packet
22043sent by the target. This is part of the File-I/O protocol extension.
22044@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
22045
22046@item @code{g} --- read registers
22047@anchor{read registers packet}
22048@cindex @code{g} packet
22049
22050Read general registers.
22051
22052Reply:
22053@table @samp
22054@item @var{XX@dots{}}
8e04817f
AC
22055Each byte of register data is described by two hex digits. The bytes
22056with the register are transmitted in target byte order. The size of
22057each register and their position within the @samp{g} @var{packet} are
12c266ea
AC
22058determined by the @value{GDBN} internal macros
22059@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
22060specification of several standard @code{g} packets is specified below.
ee2d5c50
AC
22061@item E@var{NN}
22062for an error.
22063@end table
c906108c 22064
ee2d5c50
AC
22065@item @code{G}@var{XX@dots{}} --- write regs
22066@cindex @code{G} packet
c906108c 22067
ee2d5c50
AC
22068@xref{read registers packet}, for a description of the @var{XX@dots{}}
22069data.
22070
22071Reply:
22072@table @samp
22073@item OK
22074for success
22075@item E@var{NN}
22076for an error
22077@end table
22078
22079@item @code{h} --- reserved
22080
22081Reserved for future use.
22082
b383017d 22083@item @code{H}@var{c}@var{t@dots{}} --- set thread
ee2d5c50 22084@cindex @code{H} packet
c906108c 22085
8e04817f 22086Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
22087@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
22088should be @samp{c} for step and continue operations, @samp{g} for other
22089operations. The thread designator @var{t@dots{}} may be -1, meaning all
22090the threads, a thread number, or zero which means pick any thread.
22091
22092Reply:
22093@table @samp
22094@item OK
22095for success
22096@item E@var{NN}
22097for an error
22098@end table
c906108c 22099
8e04817f
AC
22100@c FIXME: JTC:
22101@c 'H': How restrictive (or permissive) is the thread model. If a
22102@c thread is selected and stopped, are other threads allowed
22103@c to continue to execute? As I mentioned above, I think the
22104@c semantics of each command when a thread is selected must be
22105@c described. For example:
22106@c
22107@c 'g': If the stub supports threads and a specific thread is
22108@c selected, returns the register block from that thread;
22109@c otherwise returns current registers.
22110@c
22111@c 'G' If the stub supports threads and a specific thread is
22112@c selected, sets the registers of the register block of
22113@c that thread; otherwise sets current registers.
c906108c 22114
ee2d5c50
AC
22115@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
22116@anchor{cycle step packet}
22117@cindex @code{i} packet
22118
8e04817f
AC
22119Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
22120present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
22121step starting at that address.
c906108c 22122
ee2d5c50
AC
22123@item @code{I} --- signal then cycle step @strong{(reserved)}
22124@cindex @code{I} packet
22125
22126@xref{step with signal packet}. @xref{cycle step packet}.
22127
22128@item @code{j} --- reserved
22129
22130Reserved for future use.
22131
22132@item @code{J} --- reserved
c906108c 22133
ee2d5c50 22134Reserved for future use.
c906108c 22135
ee2d5c50
AC
22136@item @code{k} --- kill request
22137@cindex @code{k} packet
c906108c 22138
ac282366 22139FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
22140thread context has been selected (i.e.@: does 'k' kill only that
22141thread?)}.
c906108c 22142
ee2d5c50 22143@item @code{K} --- reserved
c906108c 22144
ee2d5c50
AC
22145Reserved for future use.
22146
22147@item @code{l} --- reserved
22148
22149Reserved for future use.
22150
22151@item @code{L} --- reserved
22152
22153Reserved for future use.
22154
22155@item @code{m}@var{addr}@code{,}@var{length} --- read memory
22156@cindex @code{m} packet
c906108c 22157
8e04817f 22158Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 22159Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 22160assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 22161transfer mechanism is needed.}
c906108c 22162
ee2d5c50
AC
22163Reply:
22164@table @samp
22165@item @var{XX@dots{}}
22166@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
22167to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 22168that sized memory transfers are assumed using word aligned
ee2d5c50
AC
22169accesses. FIXME: @emph{A word aligned memory transfer mechanism is
22170needed.}
22171@item E@var{NN}
22172@var{NN} is errno
22173@end table
22174
22175@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
22176@cindex @code{M} packet
22177
8e04817f 22178Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
22179@var{XX@dots{}} is the data.
22180
22181Reply:
22182@table @samp
22183@item OK
22184for success
22185@item E@var{NN}
8e04817f
AC
22186for an error (this includes the case where only part of the data was
22187written).
ee2d5c50 22188@end table
c906108c 22189
ee2d5c50 22190@item @code{n} --- reserved
c906108c 22191
ee2d5c50 22192Reserved for future use.
c906108c 22193
ee2d5c50 22194@item @code{N} --- reserved
c906108c 22195
ee2d5c50 22196Reserved for future use.
c906108c 22197
ee2d5c50
AC
22198@item @code{o} --- reserved
22199
22200Reserved for future use.
22201
22202@item @code{O} --- reserved
22203
2e868123 22204@item @code{p}@var{hex number of register} --- read register packet
ee2d5c50
AC
22205@cindex @code{p} packet
22206
2e868123
AC
22207@xref{read registers packet}, for a description of how the returned
22208register value is encoded.
ee2d5c50
AC
22209
22210Reply:
22211@table @samp
2e868123
AC
22212@item @var{XX@dots{}}
22213the register's value
22214@item E@var{NN}
22215for an error
22216@item
22217Indicating an unrecognized @var{query}.
ee2d5c50
AC
22218@end table
22219
22220@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
22221@anchor{write register packet}
22222@cindex @code{P} packet
22223
22224Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 22225digits for each byte in the register (target byte order).
c906108c 22226
ee2d5c50
AC
22227Reply:
22228@table @samp
22229@item OK
22230for success
22231@item E@var{NN}
22232for an error
22233@end table
22234
22235@item @code{q}@var{query} --- general query
22236@anchor{general query packet}
22237@cindex @code{q} packet
22238
22239Request info about @var{query}. In general @value{GDBN} queries have a
22240leading upper case letter. Custom vendor queries should use a company
22241prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
22242be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
22243that they match the full @var{query} name.
22244
22245Reply:
22246@table @samp
22247@item @var{XX@dots{}}
22248Hex encoded data from query. The reply can not be empty.
22249@item E@var{NN}
22250error reply
8e04817f 22251@item
ee2d5c50
AC
22252Indicating an unrecognized @var{query}.
22253@end table
22254
22255@item @code{Q}@var{var}@code{=}@var{val} --- general set
22256@cindex @code{Q} packet
22257
22258Set value of @var{var} to @var{val}.
22259
22260@xref{general query packet}, for a discussion of naming conventions.
c906108c 22261
ee2d5c50
AC
22262@item @code{r} --- reset @strong{(deprecated)}
22263@cindex @code{r} packet
c906108c 22264
8e04817f 22265Reset the entire system.
c906108c 22266
ee2d5c50
AC
22267@item @code{R}@var{XX} --- remote restart
22268@cindex @code{R} packet
22269
8e04817f
AC
22270Restart the program being debugged. @var{XX}, while needed, is ignored.
22271This packet is only available in extended mode.
ee2d5c50
AC
22272
22273Reply:
22274@table @samp
22275@item @emph{no reply}
8e04817f 22276The @samp{R} packet has no reply.
ee2d5c50
AC
22277@end table
22278
22279@item @code{s}@var{addr} --- step
22280@cindex @code{s} packet
c906108c 22281
8e04817f
AC
22282@var{addr} is address to resume. If @var{addr} is omitted, resume at
22283same address.
c906108c 22284
ee2d5c50
AC
22285Reply:
22286@xref{Stop Reply Packets}, for the reply specifications.
22287
22288@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
22289@anchor{step with signal packet}
22290@cindex @code{S} packet
22291
8e04817f 22292Like @samp{C} but step not continue.
c906108c 22293
ee2d5c50
AC
22294Reply:
22295@xref{Stop Reply Packets}, for the reply specifications.
22296
b383017d 22297@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
ee2d5c50
AC
22298@cindex @code{t} packet
22299
8e04817f 22300Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
22301@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
22302@var{addr} must be at least 3 digits.
c906108c 22303
ee2d5c50
AC
22304@item @code{T}@var{XX} --- thread alive
22305@cindex @code{T} packet
c906108c 22306
ee2d5c50 22307Find out if the thread XX is alive.
c906108c 22308
ee2d5c50
AC
22309Reply:
22310@table @samp
22311@item OK
22312thread is still alive
22313@item E@var{NN}
22314thread is dead
22315@end table
22316
22317@item @code{u} --- reserved
22318
22319Reserved for future use.
22320
22321@item @code{U} --- reserved
22322
22323Reserved for future use.
22324
86d30acc 22325@item @code{v} --- verbose packet prefix
ee2d5c50 22326
86d30acc
DJ
22327Packets starting with @code{v} are identified by a multi-letter name,
22328up to the first @code{;} or @code{?} (or the end of the packet).
22329
22330@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
22331@cindex @code{vCont} packet
22332
22333Resume the inferior. Different actions may be specified for each thread.
22334If an action is specified with no @var{tid}, then it is applied to any
22335threads that don't have a specific action specified; if no default action is
22336specified then other threads should remain stopped. Specifying multiple
22337default actions is an error; specifying no actions is also an error.
22338Thread IDs are specified in hexadecimal. Currently supported actions are:
22339
22340@table @code
22341@item c
22342Continue.
22343@item C@var{sig}
22344Continue with signal @var{sig}. @var{sig} should be two hex digits.
22345@item s
22346Step.
22347@item S@var{sig}
22348Step with signal @var{sig}. @var{sig} should be two hex digits.
22349@end table
22350
22351The optional @var{addr} argument normally associated with these packets is
22352not supported in @code{vCont}.
22353
22354Reply:
22355@xref{Stop Reply Packets}, for the reply specifications.
22356
22357@item @code{vCont?} --- extended resume query
22358@cindex @code{vCont?} packet
22359
22360Query support for the @code{vCont} packet.
22361
22362Reply:
22363@table @samp
22364@item @code{vCont}[;@var{action}]...
22365The @code{vCont} packet is supported. Each @var{action} is a supported
22366command in the @code{vCont} packet.
22367@item
22368The @code{vCont} packet is not supported.
22369@end table
ee2d5c50
AC
22370
22371@item @code{V} --- reserved
c906108c 22372
ee2d5c50 22373Reserved for future use.
c906108c 22374
ee2d5c50 22375@item @code{w} --- reserved
c906108c 22376
ee2d5c50 22377Reserved for future use.
c906108c 22378
ee2d5c50 22379@item @code{W} --- reserved
c906108c 22380
ee2d5c50 22381Reserved for future use.
c906108c 22382
ee2d5c50
AC
22383@item @code{x} --- reserved
22384
22385Reserved for future use.
22386
22387@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
22388@cindex @code{X} packet
22389
22390@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
22391is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
69065f5d
AC
22392escaped using @code{0x7d}, and then XORed with @code{0x20}.
22393For example, @code{0x7d} would be transmitted as @code{0x7d 0x5d}.
c906108c 22394
ee2d5c50
AC
22395Reply:
22396@table @samp
22397@item OK
22398for success
22399@item E@var{NN}
22400for an error
22401@end table
22402
22403@item @code{y} --- reserved
c906108c 22404
ee2d5c50 22405Reserved for future use.
c906108c 22406
ee2d5c50
AC
22407@item @code{Y} reserved
22408
22409Reserved for future use.
22410
2f870471
AC
22411@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
22412@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
22413@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 22414@cindex @code{z} packet
2f870471 22415@cindex @code{Z} packets
ee2d5c50 22416
2f870471
AC
22417Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
22418watchpoint starting at address @var{address} and covering the next
22419@var{length} bytes.
ee2d5c50 22420
2f870471
AC
22421Each breakpoint and watchpoint packet @var{type} is documented
22422separately.
22423
512217c7
AC
22424@emph{Implementation notes: A remote target shall return an empty string
22425for an unrecognized breakpoint or watchpoint packet @var{type}. A
22426remote target shall support either both or neither of a given
2f870471
AC
22427@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
22428avoid potential problems with duplicate packets, the operations should
22429be implemented in an idempotent way.}
22430
22431@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
22432@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
22433@cindex @code{z0} packet
22434@cindex @code{Z0} packet
22435
22436Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
22437@code{addr} of size @code{length}.
22438
22439A memory breakpoint is implemented by replacing the instruction at
22440@var{addr} with a software breakpoint or trap instruction. The
22441@code{length} is used by targets that indicates the size of the
22442breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
22443@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 22444
2f870471
AC
22445@emph{Implementation note: It is possible for a target to copy or move
22446code that contains memory breakpoints (e.g., when implementing
22447overlays). The behavior of this packet, in the presence of such a
22448target, is not defined.}
c906108c 22449
ee2d5c50
AC
22450Reply:
22451@table @samp
2f870471
AC
22452@item OK
22453success
22454@item
22455not supported
ee2d5c50
AC
22456@item E@var{NN}
22457for an error
2f870471
AC
22458@end table
22459
22460@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
22461@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
22462@cindex @code{z1} packet
22463@cindex @code{Z1} packet
22464
22465Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
22466address @code{addr} of size @code{length}.
22467
22468A hardware breakpoint is implemented using a mechanism that is not
22469dependant on being able to modify the target's memory.
22470
22471@emph{Implementation note: A hardware breakpoint is not affected by code
22472movement.}
22473
22474Reply:
22475@table @samp
ee2d5c50 22476@item OK
2f870471
AC
22477success
22478@item
22479not supported
22480@item E@var{NN}
22481for an error
22482@end table
22483
22484@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
22485@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
22486@cindex @code{z2} packet
22487@cindex @code{Z2} packet
22488
22489Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
22490
22491Reply:
22492@table @samp
22493@item OK
22494success
22495@item
22496not supported
22497@item E@var{NN}
22498for an error
22499@end table
22500
22501@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
22502@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
22503@cindex @code{z3} packet
22504@cindex @code{Z3} packet
22505
2e834e49 22506Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
22507
22508Reply:
22509@table @samp
22510@item OK
22511success
22512@item
22513not supported
22514@item E@var{NN}
22515for an error
22516@end table
22517
2e834e49
HPN
22518@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
22519@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
22520@cindex @code{z4} packet
22521@cindex @code{Z4} packet
22522
22523Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
22524
22525Reply:
22526@table @samp
22527@item OK
22528success
22529@item
22530not supported
22531@item E@var{NN}
22532for an error
ee2d5c50
AC
22533@end table
22534
22535@end table
c906108c 22536
ee2d5c50
AC
22537@node Stop Reply Packets
22538@section Stop Reply Packets
22539@cindex stop reply packets
c906108c 22540
8e04817f
AC
22541The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
22542receive any of the below as a reply. In the case of the @samp{C},
22543@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
22544when the target halts. In the below the exact meaning of @samp{signal
22545number} is poorly defined. In general one of the UNIX signal numbering
22546conventions is used.
c906108c 22547
ee2d5c50 22548@table @samp
c906108c 22549
ee2d5c50
AC
22550@item S@var{AA}
22551@var{AA} is the signal number
c906108c 22552
8e04817f 22553@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
22554@cindex @code{T} packet reply
22555
8e04817f
AC
22556@var{AA} = two hex digit signal number; @var{n...} = register number
22557(hex), @var{r...} = target byte ordered register contents, size defined
12c266ea
AC
22558by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
22559@var{r...} = thread process ID, this is a hex integer; @var{n...} =
22560(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
22561address, this is a hex integer; @var{n...} = other string not starting
22562with valid hex digit. @value{GDBN} should ignore this @var{n...},
22563@var{r...} pair and go on to the next. This way we can extend the
22564protocol.
c906108c 22565
ee2d5c50
AC
22566@item W@var{AA}
22567
8e04817f 22568The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
22569applicable to certain targets.
22570
22571@item X@var{AA}
c906108c 22572
8e04817f 22573The process terminated with signal @var{AA}.
c906108c 22574
ee2d5c50 22575@item O@var{XX@dots{}}
c906108c 22576
ee2d5c50
AC
22577@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
22578any time while the program is running and the debugger should continue
22579to wait for @samp{W}, @samp{T}, etc.
22580
0ce1b118
CV
22581@item F@var{call-id}@code{,}@var{parameter@dots{}}
22582
22583@var{call-id} is the identifier which says which host system call should
22584be called. This is just the name of the function. Translation into the
22585correct system call is only applicable as it's defined in @value{GDBN}.
22586@xref{File-I/O remote protocol extension}, for a list of implemented
22587system calls.
22588
22589@var{parameter@dots{}} is a list of parameters as defined for this very
22590system call.
22591
22592The target replies with this packet when it expects @value{GDBN} to call
22593a host system call on behalf of the target. @value{GDBN} replies with
22594an appropriate @code{F} packet and keeps up waiting for the next reply
22595packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
22596@samp{s} action is expected to be continued.
22597@xref{File-I/O remote protocol extension}, for more details.
22598
ee2d5c50
AC
22599@end table
22600
22601@node General Query Packets
22602@section General Query Packets
9c16f35a 22603@cindex remote query requests
c906108c 22604
8e04817f 22605The following set and query packets have already been defined.
c906108c 22606
ee2d5c50 22607@table @r
c906108c 22608
ee2d5c50 22609@item @code{q}@code{C} --- current thread
9c16f35a
EZ
22610@cindex current thread, remote request
22611@cindex @code{qC} packet
ee2d5c50
AC
22612Return the current thread id.
22613
22614Reply:
22615@table @samp
22616@item @code{QC}@var{pid}
e1aac25b 22617Where @var{pid} is an unsigned hexidecimal process id.
ee2d5c50
AC
22618@item *
22619Any other reply implies the old pid.
22620@end table
22621
22622@item @code{q}@code{fThreadInfo} -- all thread ids
9c16f35a
EZ
22623@cindex list active threads, remote request
22624@cindex @code{qfThreadInfo} packet
ee2d5c50 22625@code{q}@code{sThreadInfo}
c906108c 22626
8e04817f
AC
22627Obtain a list of active thread ids from the target (OS). Since there
22628may be too many active threads to fit into one reply packet, this query
22629works iteratively: it may require more than one query/reply sequence to
22630obtain the entire list of threads. The first query of the sequence will
22631be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
22632sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
22633
22634NOTE: replaces the @code{qL} query (see below).
22635
22636Reply:
22637@table @samp
22638@item @code{m}@var{id}
22639A single thread id
22640@item @code{m}@var{id},@var{id}@dots{}
22641a comma-separated list of thread ids
22642@item @code{l}
22643(lower case 'el') denotes end of list.
22644@end table
22645
22646In response to each query, the target will reply with a list of one or
e1aac25b
JB
22647more thread ids, in big-endian unsigned hex, separated by commas.
22648@value{GDBN} will respond to each reply with a request for more thread
22649ids (using the @code{qs} form of the query), until the target responds
22650with @code{l} (lower-case el, for @code{'last'}).
c906108c 22651
ee2d5c50 22652@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
9c16f35a
EZ
22653@cindex thread attributes info, remote request
22654@cindex @code{qThreadExtraInfo} packet
ee2d5c50
AC
22655Where @var{id} is a thread-id in big-endian hex. Obtain a printable
22656string description of a thread's attributes from the target OS. This
22657string may contain anything that the target OS thinks is interesting for
22658@value{GDBN} to tell the user about the thread. The string is displayed
22659in @value{GDBN}'s @samp{info threads} display. Some examples of
22660possible thread extra info strings are ``Runnable'', or ``Blocked on
22661Mutex''.
22662
22663Reply:
22664@table @samp
22665@item @var{XX@dots{}}
22666Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
22667the printable string containing the extra information about the thread's
8e04817f 22668attributes.
ee2d5c50
AC
22669@end table
22670
22671@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 22672
8e04817f
AC
22673Obtain thread information from RTOS. Where: @var{startflag} (one hex
22674digit) is one to indicate the first query and zero to indicate a
22675subsequent query; @var{threadcount} (two hex digits) is the maximum
22676number of threads the response packet can contain; and @var{nextthread}
22677(eight hex digits), for subsequent queries (@var{startflag} is zero), is
22678returned in the response as @var{argthread}.
ee2d5c50
AC
22679
22680NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
22681(see above).
22682
22683Reply:
22684@table @samp
22685@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
22686Where: @var{count} (two hex digits) is the number of threads being
22687returned; @var{done} (one hex digit) is zero to indicate more threads
22688and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
22689digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
22690is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 22691digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 22692@end table
c906108c 22693
ee2d5c50 22694@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
9c16f35a
EZ
22695@cindex CRC of memory block, remote request
22696@cindex @code{qCRC} packet
ee2d5c50
AC
22697Reply:
22698@table @samp
22699@item @code{E}@var{NN}
22700An error (such as memory fault)
22701@item @code{C}@var{CRC32}
22702A 32 bit cyclic redundancy check of the specified memory region.
22703@end table
22704
22705@item @code{q}@code{Offsets} --- query sect offs
9c16f35a
EZ
22706@cindex section offsets, remote request
22707@cindex @code{qOffsets} packet
8e04817f
AC
22708Get section offsets that the target used when re-locating the downloaded
22709image. @emph{Note: while a @code{Bss} offset is included in the
22710response, @value{GDBN} ignores this and instead applies the @code{Data}
22711offset to the @code{Bss} section.}
c906108c 22712
ee2d5c50
AC
22713Reply:
22714@table @samp
22715@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
22716@end table
22717
22718@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
9c16f35a
EZ
22719@cindex thread information, remote request
22720@cindex @code{qP} packet
8e04817f
AC
22721Returns information on @var{threadid}. Where: @var{mode} is a hex
22722encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
22723
22724Reply:
22725@table @samp
22726@item *
22727@end table
22728
8e04817f 22729See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 22730
ee2d5c50 22731@item @code{q}@code{Rcmd,}@var{command} --- remote command
9c16f35a
EZ
22732@cindex execute remote command, remote request
22733@cindex @code{qRcmd} packet
ee2d5c50 22734@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
22735execution. Invalid commands should be reported using the output string.
22736Before the final result packet, the target may also respond with a
ee2d5c50
AC
22737number of intermediate @code{O}@var{output} console output packets.
22738@emph{Implementors should note that providing access to a stubs's
22739interpreter may have security implications}.
22740
22741Reply:
22742@table @samp
22743@item OK
8e04817f 22744A command response with no output.
ee2d5c50 22745@item @var{OUTPUT}
8e04817f 22746A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 22747@item @code{E}@var{NN}
8e04817f 22748Indicate a badly formed request.
ee2d5c50 22749@item @samp{}
8e04817f 22750When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50 22751@end table
9c16f35a 22752z
ee2d5c50 22753@item @code{qSymbol::} --- symbol lookup
9c16f35a
EZ
22754@cindex symbol lookup, remote request
22755@cindex @code{qSymbol} packet
8e04817f
AC
22756Notify the target that @value{GDBN} is prepared to serve symbol lookup
22757requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
22758
22759Reply:
22760@table @samp
22761@item @code{OK}
8e04817f 22762The target does not need to look up any (more) symbols.
ee2d5c50
AC
22763@item @code{qSymbol:}@var{sym_name}
22764The target requests the value of symbol @var{sym_name} (hex encoded).
22765@value{GDBN} may provide the value by using the
22766@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
22767@end table
22768
22769@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
22770
22771Set the value of @var{sym_name} to @var{sym_value}.
22772
22773@var{sym_name} (hex encoded) is the name of a symbol whose value the
22774target has previously requested.
22775
22776@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
22777@value{GDBN} cannot supply a value for @var{sym_name}, then this field
22778will be empty.
22779
22780Reply:
22781@table @samp
22782@item @code{OK}
8e04817f 22783The target does not need to look up any (more) symbols.
ee2d5c50
AC
22784@item @code{qSymbol:}@var{sym_name}
22785The target requests the value of a new symbol @var{sym_name} (hex
22786encoded). @value{GDBN} will continue to supply the values of symbols
22787(if available), until the target ceases to request them.
22788@end table
eb12ee30 22789
649e03f6 22790@item @code{qPart}:@var{object}:@code{read}:@var{annex}:@var{offset},@var{length} --- read special data
9c16f35a
EZ
22791@cindex read special object, remote request
22792@cindex @code{qPart} packet
649e03f6
RM
22793Read uninterpreted bytes from the target's special data area
22794identified by the keyword @code{object}.
22795Request @var{length} bytes starting at @var{offset} bytes into the data.
22796The content and encoding of @var{annex} is specific to the object;
22797it can supply additional details about what data to access.
22798
22799Here are the specific requests of this form defined so far.
22800All @samp{@code{qPart}:@var{object}:@code{read}:@dots{}}
22801requests use the same reply formats, listed below.
22802
22803@table @asis
22804@item @code{qPart}:@code{auxv}:@code{read}::@var{offset},@var{length}
721c2651
EZ
22805Access the target's @dfn{auxiliary vector}. @xref{OS Information,
22806auxiliary vector}, and see @ref{Remote configuration,
22807read-aux-vector-packet}. Note @var{annex} must be empty.
649e03f6
RM
22808@end table
22809
22810Reply:
22811@table @asis
22812@item @code{OK}
22813The @var{offset} in the request is at the end of the data.
22814There is no more data to be read.
22815
22816@item @var{XX@dots{}}
22817Hex encoded data bytes read.
22818This may be fewer bytes than the @var{length} in the request.
22819
22820@item @code{E00}
22821The request was malformed, or @var{annex} was invalid.
22822
22823@item @code{E}@var{nn}
22824The offset was invalid, or there was an error encountered reading the data.
22825@var{nn} is a hex-encoded @code{errno} value.
22826
22827@item @code{""} (empty)
22828An empty reply indicates the @var{object} or @var{annex} string was not
22829recognized by the stub.
22830@end table
22831
22832@item @code{qPart}:@var{object}:@code{write}:@var{annex}:@var{offset}:@var{data@dots{}}
9c16f35a 22833@cindex write data into object, remote request
649e03f6
RM
22834Write uninterpreted bytes into the target's special data area
22835identified by the keyword @code{object},
22836starting at @var{offset} bytes into the data.
22837@var{data@dots{}} is the hex-encoded data to be written.
22838The content and encoding of @var{annex} is specific to the object;
22839it can supply additional details about what data to access.
22840
22841No requests of this form are presently in use. This specification
22842serves as a placeholder to document the common format that new
22843specific request specifications ought to use.
22844
22845Reply:
22846@table @asis
22847@item @var{nn}
22848@var{nn} (hex encoded) is the number of bytes written.
22849This may be fewer bytes than supplied in the request.
22850
22851@item @code{E00}
22852The request was malformed, or @var{annex} was invalid.
22853
22854@item @code{E}@var{nn}
22855The offset was invalid, or there was an error encountered writing the data.
22856@var{nn} is a hex-encoded @code{errno} value.
22857
22858@item @code{""} (empty)
22859An empty reply indicates the @var{object} or @var{annex} string was not
22860recognized by the stub, or that the object does not support writing.
22861@end table
22862
22863@item @code{qPart}:@var{object}:@var{operation}:@dots{}
22864Requests of this form may be added in the future. When a stub does
22865not recognize the @var{object} keyword, or its support for
22866@var{object} does not recognize the @var{operation} keyword,
22867the stub must respond with an empty packet.
83761cbd
KB
22868
22869@item @code{qGetTLSAddr}:@var{thread-id},@var{offset},@var{lm} --- get thread local storage address
9c16f35a
EZ
22870@cindex get thread-local storage address, remote request
22871@cindex @code{qGetTLSAddr} packet
83761cbd
KB
22872Fetch the address associated with thread local storage specified
22873by @var{thread-id}, @var{offset}, and @var{lm}.
22874
22875@var{thread-id} is the (big endian, hex encoded) thread id associated with the
22876thread for which to fetch the TLS address.
22877
22878@var{offset} is the (big endian, hex encoded) offset associated with the
22879thread local variable. (This offset is obtained from the debug
22880information associated with the variable.)
22881
22882@var{lm} is the (big endian, hex encoded) OS/ABI specific encoding of the
22883the load module associated with the thread local storage. For example,
22884a @sc{gnu}/Linux system will pass the link map address of the shared
22885object associated with the thread local storage under consideration.
22886Other operating environments may choose to represent the load module
22887differently, so the precise meaning of this parameter will vary.
22888
22889Reply:
22890@table @asis
68c71a2e 22891@item @var{XX@dots{}}
83761cbd
KB
22892Hex encoded (big endian) bytes representing the address of the thread
22893local storage requested.
22894
22895@item @code{E}@var{nn} (where @var{nn} are hex digits)
22896An error occurred.
22897
22898@item @code{""} (empty)
22899An empty reply indicates that @code{qGetTLSAddr} is not supported by the stub.
22900@end table
22901
0abb7bc7
EZ
22902Use of this request packet is controlled by the @code{set remote
22903get-thread-local-storage-address} command (@pxref{Remote
22904configuration, set remote get-thread-local-storage-address}).
22905
ee2d5c50
AC
22906@end table
22907
22908@node Register Packet Format
22909@section Register Packet Format
eb12ee30 22910
8e04817f 22911The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
22912In the below, some thirty-two bit registers are transferred as
22913sixty-four bits. Those registers should be zero/sign extended (which?)
22914to fill the space allocated. Register bytes are transfered in target
22915byte order. The two nibbles within a register byte are transfered
22916most-significant - least-significant.
eb12ee30 22917
ee2d5c50 22918@table @r
eb12ee30 22919
8e04817f 22920@item MIPS32
ee2d5c50 22921
8e04817f
AC
22922All registers are transfered as thirty-two bit quantities in the order:
2292332 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
22924registers; fsr; fir; fp.
eb12ee30 22925
8e04817f 22926@item MIPS64
ee2d5c50 22927
8e04817f
AC
22928All registers are transfered as sixty-four bit quantities (including
22929thirty-two bit registers such as @code{sr}). The ordering is the same
22930as @code{MIPS32}.
eb12ee30 22931
ee2d5c50
AC
22932@end table
22933
22934@node Examples
22935@section Examples
eb12ee30 22936
8e04817f
AC
22937Example sequence of a target being re-started. Notice how the restart
22938does not get any direct output:
eb12ee30 22939
474c8240 22940@smallexample
d2c6833e
AC
22941-> @code{R00}
22942<- @code{+}
8e04817f 22943@emph{target restarts}
d2c6833e 22944-> @code{?}
8e04817f 22945<- @code{+}
d2c6833e
AC
22946<- @code{T001:1234123412341234}
22947-> @code{+}
474c8240 22948@end smallexample
eb12ee30 22949
8e04817f 22950Example sequence of a target being stepped by a single instruction:
eb12ee30 22951
474c8240 22952@smallexample
d2c6833e 22953-> @code{G1445@dots{}}
8e04817f 22954<- @code{+}
d2c6833e
AC
22955-> @code{s}
22956<- @code{+}
22957@emph{time passes}
22958<- @code{T001:1234123412341234}
8e04817f 22959-> @code{+}
d2c6833e 22960-> @code{g}
8e04817f 22961<- @code{+}
d2c6833e
AC
22962<- @code{1455@dots{}}
22963-> @code{+}
474c8240 22964@end smallexample
eb12ee30 22965
0ce1b118
CV
22966@node File-I/O remote protocol extension
22967@section File-I/O remote protocol extension
22968@cindex File-I/O remote protocol extension
22969
22970@menu
22971* File-I/O Overview::
22972* Protocol basics::
1d8b2f28
JB
22973* The F request packet::
22974* The F reply packet::
0ce1b118
CV
22975* Memory transfer::
22976* The Ctrl-C message::
22977* Console I/O::
22978* The isatty call::
22979* The system call::
22980* List of supported calls::
22981* Protocol specific representation of datatypes::
22982* Constants::
22983* File-I/O Examples::
22984@end menu
22985
22986@node File-I/O Overview
22987@subsection File-I/O Overview
22988@cindex file-i/o overview
22989
9c16f35a
EZ
22990The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
22991target to use the host's file system and console I/O when calling various
0ce1b118
CV
22992system calls. System calls on the target system are translated into a
22993remote protocol packet to the host system which then performs the needed
22994actions and returns with an adequate response packet to the target system.
22995This simulates file system operations even on targets that lack file systems.
22996
22997The protocol is defined host- and target-system independent. It uses
9c16f35a 22998its own independent representation of datatypes and values. Both,
0ce1b118
CV
22999@value{GDBN} and the target's @value{GDBN} stub are responsible for
23000translating the system dependent values into the unified protocol values
23001when data is transmitted.
23002
23003The communication is synchronous. A system call is possible only
23004when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
23005packets. While @value{GDBN} handles the request for a system call,
23006the target is stopped to allow deterministic access to the target's
23007memory. Therefore File-I/O is not interuptible by target signals. It
23008is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
23009
23010The target's request to perform a host system call does not finish
23011the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
23012after finishing the system call, the target returns to continuing the
23013previous activity (continue, step). No additional continue or step
23014request from @value{GDBN} is required.
23015
23016@smallexample
f7dc1244 23017(@value{GDBP}) continue
0ce1b118
CV
23018 <- target requests 'system call X'
23019 target is stopped, @value{GDBN} executes system call
23020 -> GDB returns result
23021 ... target continues, GDB returns to wait for the target
23022 <- target hits breakpoint and sends a Txx packet
23023@end smallexample
23024
23025The protocol is only used for files on the host file system and
23026for I/O on the console. Character or block special devices, pipes,
23027named pipes or sockets or any other communication method on the host
23028system are not supported by this protocol.
23029
23030@node Protocol basics
23031@subsection Protocol basics
23032@cindex protocol basics, file-i/o
23033
23034The File-I/O protocol uses the @code{F} packet, as request as well
23035as as reply packet. Since a File-I/O system call can only occur when
b383017d 23036@value{GDBN} is waiting for the continuing or stepping target, the
0ce1b118
CV
23037File-I/O request is a reply that @value{GDBN} has to expect as a result
23038of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
23039This @code{F} packet contains all information needed to allow @value{GDBN}
23040to call the appropriate host system call:
23041
23042@itemize @bullet
b383017d 23043@item
0ce1b118
CV
23044A unique identifier for the requested system call.
23045
23046@item
23047All parameters to the system call. Pointers are given as addresses
23048in the target memory address space. Pointers to strings are given as
b383017d 23049pointer/length pair. Numerical values are given as they are.
0ce1b118
CV
23050Numerical control values are given in a protocol specific representation.
23051
23052@end itemize
23053
23054At that point @value{GDBN} has to perform the following actions.
23055
23056@itemize @bullet
b383017d 23057@item
0ce1b118
CV
23058If parameter pointer values are given, which point to data needed as input
23059to a system call, @value{GDBN} requests this data from the target with a
23060standard @code{m} packet request. This additional communication has to be
23061expected by the target implementation and is handled as any other @code{m}
23062packet.
23063
23064@item
23065@value{GDBN} translates all value from protocol representation to host
23066representation as needed. Datatypes are coerced into the host types.
23067
23068@item
23069@value{GDBN} calls the system call
23070
23071@item
23072It then coerces datatypes back to protocol representation.
23073
23074@item
23075If pointer parameters in the request packet point to buffer space in which
23076a system call is expected to copy data to, the data is transmitted to the
23077target using a @code{M} or @code{X} packet. This packet has to be expected
23078by the target implementation and is handled as any other @code{M} or @code{X}
23079packet.
23080
23081@end itemize
23082
23083Eventually @value{GDBN} replies with another @code{F} packet which contains all
23084necessary information for the target to continue. This at least contains
23085
23086@itemize @bullet
23087@item
23088Return value.
23089
23090@item
23091@code{errno}, if has been changed by the system call.
23092
23093@item
23094``Ctrl-C'' flag.
23095
23096@end itemize
23097
23098After having done the needed type and value coercion, the target continues
23099the latest continue or step action.
23100
1d8b2f28 23101@node The F request packet
0ce1b118
CV
23102@subsection The @code{F} request packet
23103@cindex file-i/o request packet
23104@cindex @code{F} request packet
23105
23106The @code{F} request packet has the following format:
23107
23108@table @samp
23109
23110@smallexample
23111@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
23112@end smallexample
23113
23114@var{call-id} is the identifier to indicate the host system call to be called.
23115This is just the name of the function.
23116
23117@var{parameter@dots{}} are the parameters to the system call.
23118
b383017d 23119@end table
0ce1b118
CV
23120
23121Parameters are hexadecimal integer values, either the real values in case
23122of scalar datatypes, as pointers to target buffer space in case of compound
23123datatypes and unspecified memory areas or as pointer/length pairs in case
23124of string parameters. These are appended to the call-id, each separated
23125from its predecessor by a comma. All values are transmitted in ASCII
23126string representation, pointer/length pairs separated by a slash.
23127
1d8b2f28 23128@node The F reply packet
0ce1b118
CV
23129@subsection The @code{F} reply packet
23130@cindex file-i/o reply packet
23131@cindex @code{F} reply packet
23132
23133The @code{F} reply packet has the following format:
23134
23135@table @samp
23136
23137@smallexample
23138@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
23139@end smallexample
23140
23141@var{retcode} is the return code of the system call as hexadecimal value.
23142
23143@var{errno} is the errno set by the call, in protocol specific representation.
23144This parameter can be omitted if the call was successful.
23145
23146@var{Ctrl-C flag} is only send if the user requested a break. In this
23147case, @var{errno} must be send as well, even if the call was successful.
23148The @var{Ctrl-C flag} itself consists of the character 'C':
23149
23150@smallexample
23151F0,0,C
23152@end smallexample
23153
23154@noindent
23155or, if the call was interupted before the host call has been performed:
23156
23157@smallexample
23158F-1,4,C
23159@end smallexample
23160
23161@noindent
23162assuming 4 is the protocol specific representation of @code{EINTR}.
23163
23164@end table
23165
23166@node Memory transfer
23167@subsection Memory transfer
23168@cindex memory transfer, in file-i/o protocol
23169
23170Structured data which is transferred using a memory read or write as e.g.@:
23171a @code{struct stat} is expected to be in a protocol specific format with
23172all scalar multibyte datatypes being big endian. This should be done by
23173the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
23174it transfers memory to the target. Transferred pointers to structured
23175data should point to the already coerced data at any time.
23176
23177@node The Ctrl-C message
23178@subsection The Ctrl-C message
23179@cindex ctrl-c message, in file-i/o protocol
23180
23181A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
23182reply packet. In this case the target should behave, as if it had
23183gotten a break message. The meaning for the target is ``system call
23184interupted by @code{SIGINT}''. Consequentially, the target should actually stop
23185(as with a break message) and return to @value{GDBN} with a @code{T02}
b383017d 23186packet. In this case, it's important for the target to know, in which
0ce1b118
CV
23187state the system call was interrupted. Since this action is by design
23188not an atomic operation, we have to differ between two cases:
23189
23190@itemize @bullet
23191@item
23192The system call hasn't been performed on the host yet.
23193
23194@item
23195The system call on the host has been finished.
23196
23197@end itemize
23198
23199These two states can be distinguished by the target by the value of the
23200returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
23201call hasn't been performed. This is equivalent to the @code{EINTR} handling
23202on POSIX systems. In any other case, the target may presume that the
23203system call has been finished --- successful or not --- and should behave
23204as if the break message arrived right after the system call.
23205
23206@value{GDBN} must behave reliable. If the system call has not been called
23207yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
23208@code{errno} in the packet. If the system call on the host has been finished
23209before the user requests a break, the full action must be finshed by
23210@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
23211The @code{F} packet may only be send when either nothing has happened
23212or the full action has been completed.
23213
23214@node Console I/O
23215@subsection Console I/O
23216@cindex console i/o as part of file-i/o
23217
23218By default and if not explicitely closed by the target system, the file
23219descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
23220on the @value{GDBN} console is handled as any other file output operation
23221(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
23222by @value{GDBN} so that after the target read request from file descriptor
232230 all following typing is buffered until either one of the following
23224conditions is met:
23225
23226@itemize @bullet
23227@item
23228The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
23229@code{read}
23230system call is treated as finished.
23231
23232@item
23233The user presses @kbd{Enter}. This is treated as end of input with a trailing
23234line feed.
23235
23236@item
23237The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
23238character, especially no Ctrl-D is appended to the input.
23239
23240@end itemize
23241
23242If the user has typed more characters as fit in the buffer given to
23243the read call, the trailing characters are buffered in @value{GDBN} until
23244either another @code{read(0, @dots{})} is requested by the target or debugging
23245is stopped on users request.
23246
23247@node The isatty call
2eecc4ab 23248@subsection The @samp{isatty} function call
0ce1b118
CV
23249@cindex isatty call, file-i/o protocol
23250
23251A special case in this protocol is the library call @code{isatty} which
9c16f35a 23252is implemented as its own call inside of this protocol. It returns
0ce1b118
CV
232531 to the target if the file descriptor given as parameter is attached
23254to the @value{GDBN} console, 0 otherwise. Implementing through system calls
23255would require implementing @code{ioctl} and would be more complex than
23256needed.
23257
23258@node The system call
2eecc4ab 23259@subsection The @samp{system} function call
0ce1b118
CV
23260@cindex system call, file-i/o protocol
23261
23262The other special case in this protocol is the @code{system} call which
9c16f35a 23263is implemented as its own call, too. @value{GDBN} is taking over the full
0ce1b118
CV
23264task of calling the necessary host calls to perform the @code{system}
23265call. The return value of @code{system} is simplified before it's returned
23266to the target. Basically, the only signal transmitted back is @code{EINTR}
23267in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
23268entirely of the exit status of the called command.
23269
9c16f35a
EZ
23270Due to security concerns, the @code{system} call is by default refused
23271by @value{GDBN}. The user has to allow this call explicitly with the
23272@kbd{set remote system-call-allowed 1} command.
0ce1b118 23273
9c16f35a
EZ
23274@table @code
23275@item set remote system-call-allowed
23276@kindex set remote system-call-allowed
23277Control whether to allow the @code{system} calls in the File I/O
23278protocol for the remote target. The default is zero (disabled).
0ce1b118 23279
9c16f35a 23280@item show remote system-call-allowed
0ce1b118 23281@kindex show remote system-call-allowed
9c16f35a
EZ
23282Show the current setting of system calls for the remote File I/O
23283protocol.
0ce1b118
CV
23284@end table
23285
23286@node List of supported calls
23287@subsection List of supported calls
23288@cindex list of supported file-i/o calls
23289
23290@menu
23291* open::
23292* close::
23293* read::
23294* write::
23295* lseek::
23296* rename::
23297* unlink::
23298* stat/fstat::
23299* gettimeofday::
23300* isatty::
23301* system::
23302@end menu
23303
23304@node open
23305@unnumberedsubsubsec open
23306@cindex open, file-i/o system call
23307
23308@smallexample
23309@exdent Synopsis:
23310int open(const char *pathname, int flags);
23311int open(const char *pathname, int flags, mode_t mode);
23312
b383017d 23313@exdent Request:
0ce1b118
CV
23314Fopen,pathptr/len,flags,mode
23315@end smallexample
23316
23317@noindent
23318@code{flags} is the bitwise or of the following values:
23319
23320@table @code
b383017d 23321@item O_CREAT
0ce1b118
CV
23322If the file does not exist it will be created. The host
23323rules apply as far as file ownership and time stamps
23324are concerned.
23325
b383017d 23326@item O_EXCL
0ce1b118
CV
23327When used with O_CREAT, if the file already exists it is
23328an error and open() fails.
23329
b383017d 23330@item O_TRUNC
0ce1b118
CV
23331If the file already exists and the open mode allows
23332writing (O_RDWR or O_WRONLY is given) it will be
23333truncated to length 0.
23334
b383017d 23335@item O_APPEND
0ce1b118
CV
23336The file is opened in append mode.
23337
b383017d 23338@item O_RDONLY
0ce1b118
CV
23339The file is opened for reading only.
23340
b383017d 23341@item O_WRONLY
0ce1b118
CV
23342The file is opened for writing only.
23343
b383017d 23344@item O_RDWR
0ce1b118
CV
23345The file is opened for reading and writing.
23346
23347@noindent
23348Each other bit is silently ignored.
23349
23350@end table
23351
23352@noindent
23353@code{mode} is the bitwise or of the following values:
23354
23355@table @code
b383017d 23356@item S_IRUSR
0ce1b118
CV
23357User has read permission.
23358
b383017d 23359@item S_IWUSR
0ce1b118
CV
23360User has write permission.
23361
b383017d 23362@item S_IRGRP
0ce1b118
CV
23363Group has read permission.
23364
b383017d 23365@item S_IWGRP
0ce1b118
CV
23366Group has write permission.
23367
b383017d 23368@item S_IROTH
0ce1b118
CV
23369Others have read permission.
23370
b383017d 23371@item S_IWOTH
0ce1b118
CV
23372Others have write permission.
23373
23374@noindent
23375Each other bit is silently ignored.
23376
23377@end table
23378
23379@smallexample
23380@exdent Return value:
23381open returns the new file descriptor or -1 if an error
23382occured.
23383
23384@exdent Errors:
23385@end smallexample
23386
23387@table @code
b383017d 23388@item EEXIST
0ce1b118
CV
23389pathname already exists and O_CREAT and O_EXCL were used.
23390
b383017d 23391@item EISDIR
0ce1b118
CV
23392pathname refers to a directory.
23393
b383017d 23394@item EACCES
0ce1b118
CV
23395The requested access is not allowed.
23396
23397@item ENAMETOOLONG
23398pathname was too long.
23399
b383017d 23400@item ENOENT
0ce1b118
CV
23401A directory component in pathname does not exist.
23402
b383017d 23403@item ENODEV
0ce1b118
CV
23404pathname refers to a device, pipe, named pipe or socket.
23405
b383017d 23406@item EROFS
0ce1b118
CV
23407pathname refers to a file on a read-only filesystem and
23408write access was requested.
23409
b383017d 23410@item EFAULT
0ce1b118
CV
23411pathname is an invalid pointer value.
23412
b383017d 23413@item ENOSPC
0ce1b118
CV
23414No space on device to create the file.
23415
b383017d 23416@item EMFILE
0ce1b118
CV
23417The process already has the maximum number of files open.
23418
b383017d 23419@item ENFILE
0ce1b118
CV
23420The limit on the total number of files open on the system
23421has been reached.
23422
b383017d 23423@item EINTR
0ce1b118
CV
23424The call was interrupted by the user.
23425@end table
23426
23427@node close
23428@unnumberedsubsubsec close
23429@cindex close, file-i/o system call
23430
23431@smallexample
b383017d 23432@exdent Synopsis:
0ce1b118
CV
23433int close(int fd);
23434
b383017d 23435@exdent Request:
0ce1b118
CV
23436Fclose,fd
23437
23438@exdent Return value:
23439close returns zero on success, or -1 if an error occurred.
23440
23441@exdent Errors:
23442@end smallexample
23443
23444@table @code
b383017d 23445@item EBADF
0ce1b118
CV
23446fd isn't a valid open file descriptor.
23447
b383017d 23448@item EINTR
0ce1b118
CV
23449The call was interrupted by the user.
23450@end table
23451
23452@node read
23453@unnumberedsubsubsec read
23454@cindex read, file-i/o system call
23455
23456@smallexample
b383017d 23457@exdent Synopsis:
0ce1b118
CV
23458int read(int fd, void *buf, unsigned int count);
23459
b383017d 23460@exdent Request:
0ce1b118
CV
23461Fread,fd,bufptr,count
23462
23463@exdent Return value:
23464On success, the number of bytes read is returned.
23465Zero indicates end of file. If count is zero, read
b383017d 23466returns zero as well. On error, -1 is returned.
0ce1b118
CV
23467
23468@exdent Errors:
23469@end smallexample
23470
23471@table @code
b383017d 23472@item EBADF
0ce1b118
CV
23473fd is not a valid file descriptor or is not open for
23474reading.
23475
b383017d 23476@item EFAULT
0ce1b118
CV
23477buf is an invalid pointer value.
23478
b383017d 23479@item EINTR
0ce1b118
CV
23480The call was interrupted by the user.
23481@end table
23482
23483@node write
23484@unnumberedsubsubsec write
23485@cindex write, file-i/o system call
23486
23487@smallexample
b383017d 23488@exdent Synopsis:
0ce1b118
CV
23489int write(int fd, const void *buf, unsigned int count);
23490
b383017d 23491@exdent Request:
0ce1b118
CV
23492Fwrite,fd,bufptr,count
23493
23494@exdent Return value:
23495On success, the number of bytes written are returned.
23496Zero indicates nothing was written. On error, -1
23497is returned.
23498
23499@exdent Errors:
23500@end smallexample
23501
23502@table @code
b383017d 23503@item EBADF
0ce1b118
CV
23504fd is not a valid file descriptor or is not open for
23505writing.
23506
b383017d 23507@item EFAULT
0ce1b118
CV
23508buf is an invalid pointer value.
23509
b383017d 23510@item EFBIG
0ce1b118
CV
23511An attempt was made to write a file that exceeds the
23512host specific maximum file size allowed.
23513
b383017d 23514@item ENOSPC
0ce1b118
CV
23515No space on device to write the data.
23516
b383017d 23517@item EINTR
0ce1b118
CV
23518The call was interrupted by the user.
23519@end table
23520
23521@node lseek
23522@unnumberedsubsubsec lseek
23523@cindex lseek, file-i/o system call
23524
23525@smallexample
b383017d 23526@exdent Synopsis:
0ce1b118
CV
23527long lseek (int fd, long offset, int flag);
23528
b383017d 23529@exdent Request:
0ce1b118
CV
23530Flseek,fd,offset,flag
23531@end smallexample
23532
23533@code{flag} is one of:
23534
23535@table @code
b383017d 23536@item SEEK_SET
0ce1b118
CV
23537The offset is set to offset bytes.
23538
b383017d 23539@item SEEK_CUR
0ce1b118
CV
23540The offset is set to its current location plus offset
23541bytes.
23542
b383017d 23543@item SEEK_END
0ce1b118
CV
23544The offset is set to the size of the file plus offset
23545bytes.
23546@end table
23547
23548@smallexample
23549@exdent Return value:
23550On success, the resulting unsigned offset in bytes from
23551the beginning of the file is returned. Otherwise, a
23552value of -1 is returned.
23553
23554@exdent Errors:
23555@end smallexample
23556
23557@table @code
b383017d 23558@item EBADF
0ce1b118
CV
23559fd is not a valid open file descriptor.
23560
b383017d 23561@item ESPIPE
0ce1b118
CV
23562fd is associated with the @value{GDBN} console.
23563
b383017d 23564@item EINVAL
0ce1b118
CV
23565flag is not a proper value.
23566
b383017d 23567@item EINTR
0ce1b118
CV
23568The call was interrupted by the user.
23569@end table
23570
23571@node rename
23572@unnumberedsubsubsec rename
23573@cindex rename, file-i/o system call
23574
23575@smallexample
b383017d 23576@exdent Synopsis:
0ce1b118
CV
23577int rename(const char *oldpath, const char *newpath);
23578
b383017d 23579@exdent Request:
0ce1b118
CV
23580Frename,oldpathptr/len,newpathptr/len
23581
23582@exdent Return value:
23583On success, zero is returned. On error, -1 is returned.
23584
23585@exdent Errors:
23586@end smallexample
23587
23588@table @code
b383017d 23589@item EISDIR
0ce1b118
CV
23590newpath is an existing directory, but oldpath is not a
23591directory.
23592
b383017d 23593@item EEXIST
0ce1b118
CV
23594newpath is a non-empty directory.
23595
b383017d 23596@item EBUSY
0ce1b118
CV
23597oldpath or newpath is a directory that is in use by some
23598process.
23599
b383017d 23600@item EINVAL
0ce1b118
CV
23601An attempt was made to make a directory a subdirectory
23602of itself.
23603
b383017d 23604@item ENOTDIR
0ce1b118
CV
23605A component used as a directory in oldpath or new
23606path is not a directory. Or oldpath is a directory
23607and newpath exists but is not a directory.
23608
b383017d 23609@item EFAULT
0ce1b118
CV
23610oldpathptr or newpathptr are invalid pointer values.
23611
b383017d 23612@item EACCES
0ce1b118
CV
23613No access to the file or the path of the file.
23614
23615@item ENAMETOOLONG
b383017d 23616
0ce1b118
CV
23617oldpath or newpath was too long.
23618
b383017d 23619@item ENOENT
0ce1b118
CV
23620A directory component in oldpath or newpath does not exist.
23621
b383017d 23622@item EROFS
0ce1b118
CV
23623The file is on a read-only filesystem.
23624
b383017d 23625@item ENOSPC
0ce1b118
CV
23626The device containing the file has no room for the new
23627directory entry.
23628
b383017d 23629@item EINTR
0ce1b118
CV
23630The call was interrupted by the user.
23631@end table
23632
23633@node unlink
23634@unnumberedsubsubsec unlink
23635@cindex unlink, file-i/o system call
23636
23637@smallexample
b383017d 23638@exdent Synopsis:
0ce1b118
CV
23639int unlink(const char *pathname);
23640
b383017d 23641@exdent Request:
0ce1b118
CV
23642Funlink,pathnameptr/len
23643
23644@exdent Return value:
23645On success, zero is returned. On error, -1 is returned.
23646
23647@exdent Errors:
23648@end smallexample
23649
23650@table @code
b383017d 23651@item EACCES
0ce1b118
CV
23652No access to the file or the path of the file.
23653
b383017d 23654@item EPERM
0ce1b118
CV
23655The system does not allow unlinking of directories.
23656
b383017d 23657@item EBUSY
0ce1b118
CV
23658The file pathname cannot be unlinked because it's
23659being used by another process.
23660
b383017d 23661@item EFAULT
0ce1b118
CV
23662pathnameptr is an invalid pointer value.
23663
23664@item ENAMETOOLONG
23665pathname was too long.
23666
b383017d 23667@item ENOENT
0ce1b118
CV
23668A directory component in pathname does not exist.
23669
b383017d 23670@item ENOTDIR
0ce1b118
CV
23671A component of the path is not a directory.
23672
b383017d 23673@item EROFS
0ce1b118
CV
23674The file is on a read-only filesystem.
23675
b383017d 23676@item EINTR
0ce1b118
CV
23677The call was interrupted by the user.
23678@end table
23679
23680@node stat/fstat
23681@unnumberedsubsubsec stat/fstat
23682@cindex fstat, file-i/o system call
23683@cindex stat, file-i/o system call
23684
23685@smallexample
b383017d 23686@exdent Synopsis:
0ce1b118
CV
23687int stat(const char *pathname, struct stat *buf);
23688int fstat(int fd, struct stat *buf);
23689
b383017d 23690@exdent Request:
0ce1b118
CV
23691Fstat,pathnameptr/len,bufptr
23692Ffstat,fd,bufptr
23693
23694@exdent Return value:
23695On success, zero is returned. On error, -1 is returned.
23696
23697@exdent Errors:
23698@end smallexample
23699
23700@table @code
b383017d 23701@item EBADF
0ce1b118
CV
23702fd is not a valid open file.
23703
b383017d 23704@item ENOENT
0ce1b118
CV
23705A directory component in pathname does not exist or the
23706path is an empty string.
23707
b383017d 23708@item ENOTDIR
0ce1b118
CV
23709A component of the path is not a directory.
23710
b383017d 23711@item EFAULT
0ce1b118
CV
23712pathnameptr is an invalid pointer value.
23713
b383017d 23714@item EACCES
0ce1b118
CV
23715No access to the file or the path of the file.
23716
23717@item ENAMETOOLONG
23718pathname was too long.
23719
b383017d 23720@item EINTR
0ce1b118
CV
23721The call was interrupted by the user.
23722@end table
23723
23724@node gettimeofday
23725@unnumberedsubsubsec gettimeofday
23726@cindex gettimeofday, file-i/o system call
23727
23728@smallexample
b383017d 23729@exdent Synopsis:
0ce1b118
CV
23730int gettimeofday(struct timeval *tv, void *tz);
23731
b383017d 23732@exdent Request:
0ce1b118
CV
23733Fgettimeofday,tvptr,tzptr
23734
23735@exdent Return value:
23736On success, 0 is returned, -1 otherwise.
23737
23738@exdent Errors:
23739@end smallexample
23740
23741@table @code
b383017d 23742@item EINVAL
0ce1b118
CV
23743tz is a non-NULL pointer.
23744
b383017d 23745@item EFAULT
0ce1b118
CV
23746tvptr and/or tzptr is an invalid pointer value.
23747@end table
23748
23749@node isatty
23750@unnumberedsubsubsec isatty
23751@cindex isatty, file-i/o system call
23752
23753@smallexample
b383017d 23754@exdent Synopsis:
0ce1b118
CV
23755int isatty(int fd);
23756
b383017d 23757@exdent Request:
0ce1b118
CV
23758Fisatty,fd
23759
23760@exdent Return value:
23761Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
23762
23763@exdent Errors:
23764@end smallexample
23765
23766@table @code
b383017d 23767@item EINTR
0ce1b118
CV
23768The call was interrupted by the user.
23769@end table
23770
23771@node system
23772@unnumberedsubsubsec system
23773@cindex system, file-i/o system call
23774
23775@smallexample
b383017d 23776@exdent Synopsis:
0ce1b118
CV
23777int system(const char *command);
23778
b383017d 23779@exdent Request:
0ce1b118
CV
23780Fsystem,commandptr/len
23781
23782@exdent Return value:
23783The value returned is -1 on error and the return status
23784of the command otherwise. Only the exit status of the
23785command is returned, which is extracted from the hosts
23786system return value by calling WEXITSTATUS(retval).
23787In case /bin/sh could not be executed, 127 is returned.
23788
23789@exdent Errors:
23790@end smallexample
23791
23792@table @code
b383017d 23793@item EINTR
0ce1b118
CV
23794The call was interrupted by the user.
23795@end table
23796
23797@node Protocol specific representation of datatypes
23798@subsection Protocol specific representation of datatypes
23799@cindex protocol specific representation of datatypes, in file-i/o protocol
23800
23801@menu
23802* Integral datatypes::
23803* Pointer values::
23804* struct stat::
23805* struct timeval::
23806@end menu
23807
23808@node Integral datatypes
23809@unnumberedsubsubsec Integral datatypes
23810@cindex integral datatypes, in file-i/o protocol
23811
23812The integral datatypes used in the system calls are
23813
23814@smallexample
23815int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
23816@end smallexample
23817
23818@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
23819implemented as 32 bit values in this protocol.
23820
b383017d
RM
23821@code{Long} and @code{unsigned long} are implemented as 64 bit types.
23822
0ce1b118
CV
23823@xref{Limits}, for corresponding MIN and MAX values (similar to those
23824in @file{limits.h}) to allow range checking on host and target.
23825
23826@code{time_t} datatypes are defined as seconds since the Epoch.
23827
23828All integral datatypes transferred as part of a memory read or write of a
23829structured datatype e.g.@: a @code{struct stat} have to be given in big endian
23830byte order.
23831
23832@node Pointer values
23833@unnumberedsubsubsec Pointer values
23834@cindex pointer values, in file-i/o protocol
23835
23836Pointers to target data are transmitted as they are. An exception
23837is made for pointers to buffers for which the length isn't
23838transmitted as part of the function call, namely strings. Strings
23839are transmitted as a pointer/length pair, both as hex values, e.g.@:
23840
23841@smallexample
23842@code{1aaf/12}
23843@end smallexample
23844
23845@noindent
23846which is a pointer to data of length 18 bytes at position 0x1aaf.
23847The length is defined as the full string length in bytes, including
23848the trailing null byte. Example:
23849
23850@smallexample
23851``hello, world'' at address 0x123456
23852@end smallexample
23853
23854@noindent
23855is transmitted as
23856
23857@smallexample
23858@code{123456/d}
23859@end smallexample
23860
23861@node struct stat
23862@unnumberedsubsubsec struct stat
23863@cindex struct stat, in file-i/o protocol
23864
23865The buffer of type struct stat used by the target and @value{GDBN} is defined
23866as follows:
23867
23868@smallexample
23869struct stat @{
23870 unsigned int st_dev; /* device */
23871 unsigned int st_ino; /* inode */
23872 mode_t st_mode; /* protection */
23873 unsigned int st_nlink; /* number of hard links */
23874 unsigned int st_uid; /* user ID of owner */
23875 unsigned int st_gid; /* group ID of owner */
23876 unsigned int st_rdev; /* device type (if inode device) */
23877 unsigned long st_size; /* total size, in bytes */
23878 unsigned long st_blksize; /* blocksize for filesystem I/O */
23879 unsigned long st_blocks; /* number of blocks allocated */
23880 time_t st_atime; /* time of last access */
23881 time_t st_mtime; /* time of last modification */
23882 time_t st_ctime; /* time of last change */
23883@};
23884@end smallexample
23885
23886The integral datatypes are conforming to the definitions given in the
23887approriate section (see @ref{Integral datatypes}, for details) so this
23888structure is of size 64 bytes.
23889
23890The values of several fields have a restricted meaning and/or
23891range of values.
23892
23893@smallexample
23894st_dev: 0 file
23895 1 console
23896
23897st_ino: No valid meaning for the target. Transmitted unchanged.
23898
23899st_mode: Valid mode bits are described in Appendix C. Any other
23900 bits have currently no meaning for the target.
23901
23902st_uid: No valid meaning for the target. Transmitted unchanged.
23903
23904st_gid: No valid meaning for the target. Transmitted unchanged.
23905
23906st_rdev: No valid meaning for the target. Transmitted unchanged.
23907
23908st_atime, st_mtime, st_ctime:
23909 These values have a host and file system dependent
23910 accuracy. Especially on Windows hosts the file systems
23911 don't support exact timing values.
23912@end smallexample
23913
23914The target gets a struct stat of the above representation and is
23915responsible to coerce it to the target representation before
23916continuing.
23917
23918Note that due to size differences between the host and target
23919representation of stat members, these members could eventually
23920get truncated on the target.
23921
23922@node struct timeval
23923@unnumberedsubsubsec struct timeval
23924@cindex struct timeval, in file-i/o protocol
23925
23926The buffer of type struct timeval used by the target and @value{GDBN}
23927is defined as follows:
23928
23929@smallexample
b383017d 23930struct timeval @{
0ce1b118
CV
23931 time_t tv_sec; /* second */
23932 long tv_usec; /* microsecond */
23933@};
23934@end smallexample
23935
23936The integral datatypes are conforming to the definitions given in the
23937approriate section (see @ref{Integral datatypes}, for details) so this
23938structure is of size 8 bytes.
23939
23940@node Constants
23941@subsection Constants
23942@cindex constants, in file-i/o protocol
23943
23944The following values are used for the constants inside of the
23945protocol. @value{GDBN} and target are resposible to translate these
23946values before and after the call as needed.
23947
23948@menu
23949* Open flags::
23950* mode_t values::
23951* Errno values::
23952* Lseek flags::
23953* Limits::
23954@end menu
23955
23956@node Open flags
23957@unnumberedsubsubsec Open flags
23958@cindex open flags, in file-i/o protocol
23959
23960All values are given in hexadecimal representation.
23961
23962@smallexample
23963 O_RDONLY 0x0
23964 O_WRONLY 0x1
23965 O_RDWR 0x2
23966 O_APPEND 0x8
23967 O_CREAT 0x200
23968 O_TRUNC 0x400
23969 O_EXCL 0x800
23970@end smallexample
23971
23972@node mode_t values
23973@unnumberedsubsubsec mode_t values
23974@cindex mode_t values, in file-i/o protocol
23975
23976All values are given in octal representation.
23977
23978@smallexample
23979 S_IFREG 0100000
23980 S_IFDIR 040000
23981 S_IRUSR 0400
23982 S_IWUSR 0200
23983 S_IXUSR 0100
23984 S_IRGRP 040
23985 S_IWGRP 020
23986 S_IXGRP 010
23987 S_IROTH 04
23988 S_IWOTH 02
23989 S_IXOTH 01
23990@end smallexample
23991
23992@node Errno values
23993@unnumberedsubsubsec Errno values
23994@cindex errno values, in file-i/o protocol
23995
23996All values are given in decimal representation.
23997
23998@smallexample
23999 EPERM 1
24000 ENOENT 2
24001 EINTR 4
24002 EBADF 9
24003 EACCES 13
24004 EFAULT 14
24005 EBUSY 16
24006 EEXIST 17
24007 ENODEV 19
24008 ENOTDIR 20
24009 EISDIR 21
24010 EINVAL 22
24011 ENFILE 23
24012 EMFILE 24
24013 EFBIG 27
24014 ENOSPC 28
24015 ESPIPE 29
24016 EROFS 30
24017 ENAMETOOLONG 91
24018 EUNKNOWN 9999
24019@end smallexample
24020
24021 EUNKNOWN is used as a fallback error value if a host system returns
24022 any error value not in the list of supported error numbers.
24023
24024@node Lseek flags
24025@unnumberedsubsubsec Lseek flags
24026@cindex lseek flags, in file-i/o protocol
24027
24028@smallexample
24029 SEEK_SET 0
24030 SEEK_CUR 1
24031 SEEK_END 2
24032@end smallexample
24033
24034@node Limits
24035@unnumberedsubsubsec Limits
24036@cindex limits, in file-i/o protocol
24037
24038All values are given in decimal representation.
24039
24040@smallexample
24041 INT_MIN -2147483648
24042 INT_MAX 2147483647
24043 UINT_MAX 4294967295
24044 LONG_MIN -9223372036854775808
24045 LONG_MAX 9223372036854775807
24046 ULONG_MAX 18446744073709551615
24047@end smallexample
24048
24049@node File-I/O Examples
24050@subsection File-I/O Examples
24051@cindex file-i/o examples
24052
24053Example sequence of a write call, file descriptor 3, buffer is at target
24054address 0x1234, 6 bytes should be written:
24055
24056@smallexample
24057<- @code{Fwrite,3,1234,6}
24058@emph{request memory read from target}
24059-> @code{m1234,6}
24060<- XXXXXX
24061@emph{return "6 bytes written"}
24062-> @code{F6}
24063@end smallexample
24064
24065Example sequence of a read call, file descriptor 3, buffer is at target
24066address 0x1234, 6 bytes should be read:
24067
24068@smallexample
24069<- @code{Fread,3,1234,6}
24070@emph{request memory write to target}
24071-> @code{X1234,6:XXXXXX}
24072@emph{return "6 bytes read"}
24073-> @code{F6}
24074@end smallexample
24075
24076Example sequence of a read call, call fails on the host due to invalid
24077file descriptor (EBADF):
24078
24079@smallexample
24080<- @code{Fread,3,1234,6}
24081-> @code{F-1,9}
24082@end smallexample
24083
24084Example sequence of a read call, user presses Ctrl-C before syscall on
24085host is called:
24086
24087@smallexample
24088<- @code{Fread,3,1234,6}
24089-> @code{F-1,4,C}
24090<- @code{T02}
24091@end smallexample
24092
24093Example sequence of a read call, user presses Ctrl-C after syscall on
24094host is called:
24095
24096@smallexample
24097<- @code{Fread,3,1234,6}
24098-> @code{X1234,6:XXXXXX}
24099<- @code{T02}
24100@end smallexample
24101
f418dd93
DJ
24102@include agentexpr.texi
24103
aab4e0ec 24104@include gpl.texi
eb12ee30 24105
2154891a 24106@raisesections
6826cf00 24107@include fdl.texi
2154891a 24108@lowersections
6826cf00 24109
6d2ebf8b 24110@node Index
c906108c
SS
24111@unnumbered Index
24112
24113@printindex cp
24114
24115@tex
24116% I think something like @colophon should be in texinfo. In the
24117% meantime:
24118\long\def\colophon{\hbox to0pt{}\vfill
24119\centerline{The body of this manual is set in}
24120\centerline{\fontname\tenrm,}
24121\centerline{with headings in {\bf\fontname\tenbf}}
24122\centerline{and examples in {\tt\fontname\tentt}.}
24123\centerline{{\it\fontname\tenit\/},}
24124\centerline{{\bf\fontname\tenbf}, and}
24125\centerline{{\sl\fontname\tensl\/}}
24126\centerline{are used for emphasis.}\vfill}
24127\page\colophon
24128% Blame: doc@cygnus.com, 1991.
24129@end tex
24130
c906108c 24131@bye
This page took 2.505481 seconds and 4 git commands to generate.