(Output Formats): More detailed description of the `c' format.
[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
c906108c
SS
2389@item thread apply [@var{threadno}] [@var{all}] @var{args}
2390The @code{thread apply} command allows you to apply a command to one or
2391more threads. Specify the numbers of the threads that you want affected
2392with the command argument @var{threadno}. @var{threadno} is the internal
2393@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2394threads} display. To apply a command to all threads, use
2395@code{thread apply all} @var{args}.
c906108c
SS
2396@end table
2397
2398@cindex automatic thread selection
2399@cindex switching threads automatically
2400@cindex threads, automatic switching
2401Whenever @value{GDBN} stops your program, due to a breakpoint or a
2402signal, it automatically selects the thread where that breakpoint or
2403signal happened. @value{GDBN} alerts you to the context switch with a
2404message of the form @samp{[Switching to @var{systag}]} to identify the
2405thread.
2406
2407@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2408more information about how @value{GDBN} behaves when you stop and start
2409programs with multiple threads.
2410
2411@xref{Set Watchpoints,,Setting watchpoints}, for information about
2412watchpoints in programs with multiple threads.
c906108c 2413
6d2ebf8b 2414@node Processes
c906108c
SS
2415@section Debugging programs with multiple processes
2416
2417@cindex fork, debugging programs which call
2418@cindex multiple processes
2419@cindex processes, multiple
53a5351d
JM
2420On most systems, @value{GDBN} has no special support for debugging
2421programs which create additional processes using the @code{fork}
2422function. When a program forks, @value{GDBN} will continue to debug the
2423parent process and the child process will run unimpeded. If you have
2424set a breakpoint in any code which the child then executes, the child
2425will get a @code{SIGTRAP} signal which (unless it catches the signal)
2426will cause it to terminate.
c906108c
SS
2427
2428However, if you want to debug the child process there is a workaround
2429which isn't too painful. Put a call to @code{sleep} in the code which
2430the child process executes after the fork. It may be useful to sleep
2431only if a certain environment variable is set, or a certain file exists,
2432so that the delay need not occur when you don't want to run @value{GDBN}
2433on the child. While the child is sleeping, use the @code{ps} program to
2434get its process ID. Then tell @value{GDBN} (a new invocation of
2435@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2436the child process (@pxref{Attach}). From that point on you can debug
c906108c 2437the child process just like any other process which you attached to.
c906108c 2438
b51970ac
DJ
2439On some systems, @value{GDBN} provides support for debugging programs that
2440create additional processes using the @code{fork} or @code{vfork} functions.
2441Currently, the only platforms with this feature are HP-UX (11.x and later
2442only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2443
2444By default, when a program forks, @value{GDBN} will continue to debug
2445the parent process and the child process will run unimpeded.
2446
2447If you want to follow the child process instead of the parent process,
2448use the command @w{@code{set follow-fork-mode}}.
2449
2450@table @code
2451@kindex set follow-fork-mode
2452@item set follow-fork-mode @var{mode}
2453Set the debugger response to a program call of @code{fork} or
2454@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 2455process. The @var{mode} argument can be:
c906108c
SS
2456
2457@table @code
2458@item parent
2459The original process is debugged after a fork. The child process runs
2df3850c 2460unimpeded. This is the default.
c906108c
SS
2461
2462@item child
2463The new process is debugged after a fork. The parent process runs
2464unimpeded.
2465
c906108c
SS
2466@end table
2467
9c16f35a 2468@kindex show follow-fork-mode
c906108c 2469@item show follow-fork-mode
2df3850c 2470Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2471@end table
2472
2473If you ask to debug a child process and a @code{vfork} is followed by an
2474@code{exec}, @value{GDBN} executes the new target up to the first
2475breakpoint in the new target. If you have a breakpoint set on
2476@code{main} in your original program, the breakpoint will also be set on
2477the child process's @code{main}.
2478
2479When a child process is spawned by @code{vfork}, you cannot debug the
2480child or parent until an @code{exec} call completes.
2481
2482If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2483call executes, the new target restarts. To restart the parent process,
2484use the @code{file} command with the parent executable name as its
2485argument.
2486
2487You can use the @code{catch} command to make @value{GDBN} stop whenever
2488a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2489Catchpoints, ,Setting catchpoints}.
c906108c 2490
6d2ebf8b 2491@node Stopping
c906108c
SS
2492@chapter Stopping and Continuing
2493
2494The principal purposes of using a debugger are so that you can stop your
2495program before it terminates; or so that, if your program runs into
2496trouble, you can investigate and find out why.
2497
7a292a7a
SS
2498Inside @value{GDBN}, your program may stop for any of several reasons,
2499such as a signal, a breakpoint, or reaching a new line after a
2500@value{GDBN} command such as @code{step}. You may then examine and
2501change variables, set new breakpoints or remove old ones, and then
2502continue execution. Usually, the messages shown by @value{GDBN} provide
2503ample explanation of the status of your program---but you can also
2504explicitly request this information at any time.
c906108c
SS
2505
2506@table @code
2507@kindex info program
2508@item info program
2509Display information about the status of your program: whether it is
7a292a7a 2510running or not, what process it is, and why it stopped.
c906108c
SS
2511@end table
2512
2513@menu
2514* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2515* Continuing and Stepping:: Resuming execution
c906108c 2516* Signals:: Signals
c906108c 2517* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2518@end menu
2519
6d2ebf8b 2520@node Breakpoints
c906108c
SS
2521@section Breakpoints, watchpoints, and catchpoints
2522
2523@cindex breakpoints
2524A @dfn{breakpoint} makes your program stop whenever a certain point in
2525the program is reached. For each breakpoint, you can add conditions to
2526control in finer detail whether your program stops. You can set
2527breakpoints with the @code{break} command and its variants (@pxref{Set
2528Breaks, ,Setting breakpoints}), to specify the place where your program
2529should stop by line number, function name or exact address in the
2530program.
2531
09d4efe1
EZ
2532On some systems, you can set breakpoints in shared libraries before
2533the executable is run. There is a minor limitation on HP-UX systems:
2534you must wait until the executable is run in order to set breakpoints
2535in shared library routines that are not called directly by the program
2536(for example, routines that are arguments in a @code{pthread_create}
2537call).
c906108c
SS
2538
2539@cindex watchpoints
2540@cindex memory tracing
2541@cindex breakpoint on memory address
2542@cindex breakpoint on variable modification
2543A @dfn{watchpoint} is a special breakpoint that stops your program
2544when the value of an expression changes. You must use a different
2545command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2546watchpoints}), but aside from that, you can manage a watchpoint like
2547any other breakpoint: you enable, disable, and delete both breakpoints
2548and watchpoints using the same commands.
2549
2550You can arrange to have values from your program displayed automatically
2551whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2552Automatic display}.
2553
2554@cindex catchpoints
2555@cindex breakpoint on events
2556A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2557when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2558exception or the loading of a library. As with watchpoints, you use a
2559different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2560catchpoints}), but aside from that, you can manage a catchpoint like any
2561other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2562@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2563
2564@cindex breakpoint numbers
2565@cindex numbers for breakpoints
2566@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2567catchpoint when you create it; these numbers are successive integers
2568starting with one. In many of the commands for controlling various
2569features of breakpoints you use the breakpoint number to say which
2570breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2571@dfn{disabled}; if disabled, it has no effect on your program until you
2572enable it again.
2573
c5394b80
JM
2574@cindex breakpoint ranges
2575@cindex ranges of breakpoints
2576Some @value{GDBN} commands accept a range of breakpoints on which to
2577operate. A breakpoint range is either a single breakpoint number, like
2578@samp{5}, or two such numbers, in increasing order, separated by a
2579hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2580all breakpoint in that range are operated on.
2581
c906108c
SS
2582@menu
2583* Set Breaks:: Setting breakpoints
2584* Set Watchpoints:: Setting watchpoints
2585* Set Catchpoints:: Setting catchpoints
2586* Delete Breaks:: Deleting breakpoints
2587* Disabling:: Disabling breakpoints
2588* Conditions:: Break conditions
2589* Break Commands:: Breakpoint command lists
c906108c 2590* Breakpoint Menus:: Breakpoint menus
d4f3574e 2591* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2592* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2593@end menu
2594
6d2ebf8b 2595@node Set Breaks
c906108c
SS
2596@subsection Setting breakpoints
2597
5d161b24 2598@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2599@c consider in particular declaration with/without initialization.
2600@c
2601@c FIXME 2 is there stuff on this already? break at fun start, already init?
2602
2603@kindex break
41afff9a
EZ
2604@kindex b @r{(@code{break})}
2605@vindex $bpnum@r{, convenience variable}
c906108c
SS
2606@cindex latest breakpoint
2607Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2608@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2609number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2610Vars,, Convenience variables}, for a discussion of what you can do with
2611convenience variables.
2612
2613You have several ways to say where the breakpoint should go.
2614
2615@table @code
2616@item break @var{function}
5d161b24 2617Set a breakpoint at entry to function @var{function}.
c906108c 2618When using source languages that permit overloading of symbols, such as
b37052ae 2619C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2620@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2621
2622@item break +@var{offset}
2623@itemx break -@var{offset}
2624Set a breakpoint some number of lines forward or back from the position
d4f3574e 2625at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2626(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2627
2628@item break @var{linenum}
2629Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2630The current source file is the last file whose source text was printed.
2631The breakpoint will stop your program just before it executes any of the
c906108c
SS
2632code on that line.
2633
2634@item break @var{filename}:@var{linenum}
2635Set a breakpoint at line @var{linenum} in source file @var{filename}.
2636
2637@item break @var{filename}:@var{function}
2638Set a breakpoint at entry to function @var{function} found in file
2639@var{filename}. Specifying a file name as well as a function name is
2640superfluous except when multiple files contain similarly named
2641functions.
2642
2643@item break *@var{address}
2644Set a breakpoint at address @var{address}. You can use this to set
2645breakpoints in parts of your program which do not have debugging
2646information or source files.
2647
2648@item break
2649When called without any arguments, @code{break} sets a breakpoint at
2650the next instruction to be executed in the selected stack frame
2651(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2652innermost, this makes your program stop as soon as control
2653returns to that frame. This is similar to the effect of a
2654@code{finish} command in the frame inside the selected frame---except
2655that @code{finish} does not leave an active breakpoint. If you use
2656@code{break} without an argument in the innermost frame, @value{GDBN} stops
2657the next time it reaches the current location; this may be useful
2658inside loops.
2659
2660@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2661least one instruction has been executed. If it did not do this, you
2662would be unable to proceed past a breakpoint without first disabling the
2663breakpoint. This rule applies whether or not the breakpoint already
2664existed when your program stopped.
2665
2666@item break @dots{} if @var{cond}
2667Set a breakpoint with condition @var{cond}; evaluate the expression
2668@var{cond} each time the breakpoint is reached, and stop only if the
2669value is nonzero---that is, if @var{cond} evaluates as true.
2670@samp{@dots{}} stands for one of the possible arguments described
2671above (or no argument) specifying where to break. @xref{Conditions,
2672,Break conditions}, for more information on breakpoint conditions.
2673
2674@kindex tbreak
2675@item tbreak @var{args}
2676Set a breakpoint enabled only for one stop. @var{args} are the
2677same as for the @code{break} command, and the breakpoint is set in the same
2678way, but the breakpoint is automatically deleted after the first time your
2679program stops there. @xref{Disabling, ,Disabling breakpoints}.
2680
c906108c 2681@kindex hbreak
ba04e063 2682@cindex hardware breakpoints
c906108c 2683@item hbreak @var{args}
d4f3574e
SS
2684Set a hardware-assisted breakpoint. @var{args} are the same as for the
2685@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2686breakpoint requires hardware support and some target hardware may not
2687have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2688debugging, so you can set a breakpoint at an instruction without
2689changing the instruction. This can be used with the new trap-generation
09d4efe1 2690provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
2691will generate traps when a program accesses some data or instruction
2692address that is assigned to the debug registers. However the hardware
2693breakpoint registers can take a limited number of breakpoints. For
2694example, on the DSU, only two data breakpoints can be set at a time, and
2695@value{GDBN} will reject this command if more than two are used. Delete
2696or disable unused hardware breakpoints before setting new ones
2697(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
9c16f35a
EZ
2698For remote targets, you can restrict the number of hardware
2699breakpoints @value{GDBN} will use, see @ref{set remote
2700hardware-breakpoint-limit}.
501eef12 2701
c906108c
SS
2702
2703@kindex thbreak
2704@item thbreak @var{args}
2705Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2706are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2707the same way. However, like the @code{tbreak} command,
c906108c
SS
2708the breakpoint is automatically deleted after the
2709first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2710command, the breakpoint requires hardware support and some target hardware
2711may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2712See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2713
2714@kindex rbreak
2715@cindex regular expression
c45da7e6
EZ
2716@cindex breakpoints in functions matching a regexp
2717@cindex set breakpoints in many functions
c906108c 2718@item rbreak @var{regex}
c906108c 2719Set breakpoints on all functions matching the regular expression
11cf8741
JM
2720@var{regex}. This command sets an unconditional breakpoint on all
2721matches, printing a list of all breakpoints it set. Once these
2722breakpoints are set, they are treated just like the breakpoints set with
2723the @code{break} command. You can delete them, disable them, or make
2724them conditional the same way as any other breakpoint.
2725
2726The syntax of the regular expression is the standard one used with tools
2727like @file{grep}. Note that this is different from the syntax used by
2728shells, so for instance @code{foo*} matches all functions that include
2729an @code{fo} followed by zero or more @code{o}s. There is an implicit
2730@code{.*} leading and trailing the regular expression you supply, so to
2731match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2732
f7dc1244 2733@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2734When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2735breakpoints on overloaded functions that are not members of any special
2736classes.
c906108c 2737
f7dc1244
EZ
2738@cindex set breakpoints on all functions
2739The @code{rbreak} command can be used to set breakpoints in
2740@strong{all} the functions in a program, like this:
2741
2742@smallexample
2743(@value{GDBP}) rbreak .
2744@end smallexample
2745
c906108c
SS
2746@kindex info breakpoints
2747@cindex @code{$_} and @code{info breakpoints}
2748@item info breakpoints @r{[}@var{n}@r{]}
2749@itemx info break @r{[}@var{n}@r{]}
2750@itemx info watchpoints @r{[}@var{n}@r{]}
2751Print a table of all breakpoints, watchpoints, and catchpoints set and
2752not deleted, with the following columns for each breakpoint:
2753
2754@table @emph
2755@item Breakpoint Numbers
2756@item Type
2757Breakpoint, watchpoint, or catchpoint.
2758@item Disposition
2759Whether the breakpoint is marked to be disabled or deleted when hit.
2760@item Enabled or Disabled
2761Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2762that are not enabled.
2763@item Address
2650777c
JJ
2764Where the breakpoint is in your program, as a memory address. If the
2765breakpoint is pending (see below for details) on a future load of a shared library, the address
2766will be listed as @samp{<PENDING>}.
c906108c
SS
2767@item What
2768Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
2769line number. For a pending breakpoint, the original string passed to
2770the breakpoint command will be listed as it cannot be resolved until
2771the appropriate shared library is loaded in the future.
c906108c
SS
2772@end table
2773
2774@noindent
2775If a breakpoint is conditional, @code{info break} shows the condition on
2776the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
2777are listed after that. A pending breakpoint is allowed to have a condition
2778specified for it. The condition is not parsed for validity until a shared
2779library is loaded that allows the pending breakpoint to resolve to a
2780valid location.
c906108c
SS
2781
2782@noindent
2783@code{info break} with a breakpoint
2784number @var{n} as argument lists only that breakpoint. The
2785convenience variable @code{$_} and the default examining-address for
2786the @code{x} command are set to the address of the last breakpoint
5d161b24 2787listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2788
2789@noindent
2790@code{info break} displays a count of the number of times the breakpoint
2791has been hit. This is especially useful in conjunction with the
2792@code{ignore} command. You can ignore a large number of breakpoint
2793hits, look at the breakpoint info to see how many times the breakpoint
2794was hit, and then run again, ignoring one less than that number. This
2795will get you quickly to the last hit of that breakpoint.
2796@end table
2797
2798@value{GDBN} allows you to set any number of breakpoints at the same place in
2799your program. There is nothing silly or meaningless about this. When
2800the breakpoints are conditional, this is even useful
2801(@pxref{Conditions, ,Break conditions}).
2802
2650777c 2803@cindex pending breakpoints
dd79a6cf
JJ
2804If a specified breakpoint location cannot be found, it may be due to the fact
2805that the location is in a shared library that is yet to be loaded. In such
2806a case, you may want @value{GDBN} to create a special breakpoint (known as
2807a @dfn{pending breakpoint}) that
2808attempts to resolve itself in the future when an appropriate shared library
2809gets loaded.
2810
2811Pending breakpoints are useful to set at the start of your
2650777c
JJ
2812@value{GDBN} session for locations that you know will be dynamically loaded
2813later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
2814a check is made to see if the load resolves any pending breakpoint locations.
2815If a pending breakpoint location gets resolved,
2816a regular breakpoint is created and the original pending breakpoint is removed.
2817
2818@value{GDBN} provides some additional commands for controlling pending
2819breakpoint support:
2820
2821@kindex set breakpoint pending
2822@kindex show breakpoint pending
2823@table @code
2824@item set breakpoint pending auto
2825This is the default behavior. When @value{GDBN} cannot find the breakpoint
2826location, it queries you whether a pending breakpoint should be created.
2827
2828@item set breakpoint pending on
2829This indicates that an unrecognized breakpoint location should automatically
2830result in a pending breakpoint being created.
2831
2832@item set breakpoint pending off
2833This indicates that pending breakpoints are not to be created. Any
2834unrecognized breakpoint location results in an error. This setting does
2835not affect any pending breakpoints previously created.
2836
2837@item show breakpoint pending
2838Show the current behavior setting for creating pending breakpoints.
2839@end table
2650777c 2840
649e03f6
RM
2841@cindex operations allowed on pending breakpoints
2842Normal breakpoint operations apply to pending breakpoints as well. You may
2843specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
2844breakpoint is reached. You can also enable or disable
2845the pending breakpoint. When you specify a condition for a pending breakpoint,
2846the parsing of the condition will be deferred until the point where the
2847pending breakpoint location is resolved. Disabling a pending breakpoint
2848tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
2849shared library load. When a pending breakpoint is re-enabled,
649e03f6 2850@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
2851This is done because any number of shared library loads could have
2852occurred since the time the breakpoint was disabled and one or more
2853of these loads could resolve the location.
2854
c906108c
SS
2855@cindex negative breakpoint numbers
2856@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2857@value{GDBN} itself sometimes sets breakpoints in your program for
2858special purposes, such as proper handling of @code{longjmp} (in C
2859programs). These internal breakpoints are assigned negative numbers,
2860starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2861You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2862@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2863
2864
6d2ebf8b 2865@node Set Watchpoints
c906108c
SS
2866@subsection Setting watchpoints
2867
2868@cindex setting watchpoints
c906108c
SS
2869You can use a watchpoint to stop execution whenever the value of an
2870expression changes, without having to predict a particular place where
2871this may happen.
2872
82f2d802
EZ
2873@cindex software watchpoints
2874@cindex hardware watchpoints
c906108c 2875Depending on your system, watchpoints may be implemented in software or
2df3850c 2876hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2877program and testing the variable's value each time, which is hundreds of
2878times slower than normal execution. (But this may still be worth it, to
2879catch errors where you have no clue what part of your program is the
2880culprit.)
2881
82f2d802
EZ
2882On some systems, such as HP-UX, @sc{gnu}/Linux and most other
2883x86-based targets, @value{GDBN} includes support for hardware
2884watchpoints, which do not slow down the running of your program.
c906108c
SS
2885
2886@table @code
2887@kindex watch
2888@item watch @var{expr}
2889Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2890is written into by the program and its value changes.
2891
2892@kindex rwatch
2893@item rwatch @var{expr}
09d4efe1
EZ
2894Set a watchpoint that will break when the value of @var{expr} is read
2895by the program.
c906108c
SS
2896
2897@kindex awatch
2898@item awatch @var{expr}
09d4efe1
EZ
2899Set a watchpoint that will break when @var{expr} is either read from
2900or written into by the program.
c906108c
SS
2901
2902@kindex info watchpoints
2903@item info watchpoints
2904This command prints a list of watchpoints, breakpoints, and catchpoints;
09d4efe1 2905it is the same as @code{info break} (@pxref{Set Breaks}).
c906108c
SS
2906@end table
2907
2908@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2909watchpoints execute very quickly, and the debugger reports a change in
2910value at the exact instruction where the change occurs. If @value{GDBN}
2911cannot set a hardware watchpoint, it sets a software watchpoint, which
2912executes more slowly and reports the change in value at the next
82f2d802
EZ
2913@emph{statement}, not the instruction, after the change occurs.
2914
82f2d802
EZ
2915@cindex use only software watchpoints
2916You can force @value{GDBN} to use only software watchpoints with the
2917@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
2918zero, @value{GDBN} will never try to use hardware watchpoints, even if
2919the underlying system supports them. (Note that hardware-assisted
2920watchpoints that were set @emph{before} setting
2921@code{can-use-hw-watchpoints} to zero will still use the hardware
2922mechanism of watching expressiion values.)
c906108c 2923
9c16f35a
EZ
2924@table @code
2925@item set can-use-hw-watchpoints
2926@kindex set can-use-hw-watchpoints
2927Set whether or not to use hardware watchpoints.
2928
2929@item show can-use-hw-watchpoints
2930@kindex show can-use-hw-watchpoints
2931Show the current mode of using hardware watchpoints.
2932@end table
2933
2934For remote targets, you can restrict the number of hardware
2935watchpoints @value{GDBN} will use, see @ref{set remote
2936hardware-breakpoint-limit}.
2937
c906108c
SS
2938When you issue the @code{watch} command, @value{GDBN} reports
2939
474c8240 2940@smallexample
c906108c 2941Hardware watchpoint @var{num}: @var{expr}
474c8240 2942@end smallexample
c906108c
SS
2943
2944@noindent
2945if it was able to set a hardware watchpoint.
2946
7be570e7
JM
2947Currently, the @code{awatch} and @code{rwatch} commands can only set
2948hardware watchpoints, because accesses to data that don't change the
2949value of the watched expression cannot be detected without examining
2950every instruction as it is being executed, and @value{GDBN} does not do
2951that currently. If @value{GDBN} finds that it is unable to set a
2952hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2953will print a message like this:
2954
2955@smallexample
2956Expression cannot be implemented with read/access watchpoint.
2957@end smallexample
2958
2959Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2960data type of the watched expression is wider than what a hardware
2961watchpoint on the target machine can handle. For example, some systems
2962can only watch regions that are up to 4 bytes wide; on such systems you
2963cannot set hardware watchpoints for an expression that yields a
2964double-precision floating-point number (which is typically 8 bytes
2965wide). As a work-around, it might be possible to break the large region
2966into a series of smaller ones and watch them with separate watchpoints.
2967
2968If you set too many hardware watchpoints, @value{GDBN} might be unable
2969to insert all of them when you resume the execution of your program.
2970Since the precise number of active watchpoints is unknown until such
2971time as the program is about to be resumed, @value{GDBN} might not be
2972able to warn you about this when you set the watchpoints, and the
2973warning will be printed only when the program is resumed:
2974
2975@smallexample
2976Hardware watchpoint @var{num}: Could not insert watchpoint
2977@end smallexample
2978
2979@noindent
2980If this happens, delete or disable some of the watchpoints.
2981
2982The SPARClite DSU will generate traps when a program accesses some data
2983or instruction address that is assigned to the debug registers. For the
2984data addresses, DSU facilitates the @code{watch} command. However the
2985hardware breakpoint registers can only take two data watchpoints, and
2986both watchpoints must be the same kind. For example, you can set two
2987watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2988@strong{or} two with @code{awatch} commands, but you cannot set one
2989watchpoint with one command and the other with a different command.
c906108c
SS
2990@value{GDBN} will reject the command if you try to mix watchpoints.
2991Delete or disable unused watchpoint commands before setting new ones.
2992
2993If you call a function interactively using @code{print} or @code{call},
2df3850c 2994any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2995kind of breakpoint or the call completes.
2996
7be570e7
JM
2997@value{GDBN} automatically deletes watchpoints that watch local
2998(automatic) variables, or expressions that involve such variables, when
2999they go out of scope, that is, when the execution leaves the block in
3000which these variables were defined. In particular, when the program
3001being debugged terminates, @emph{all} local variables go out of scope,
3002and so only watchpoints that watch global variables remain set. If you
3003rerun the program, you will need to set all such watchpoints again. One
3004way of doing that would be to set a code breakpoint at the entry to the
3005@code{main} function and when it breaks, set all the watchpoints.
3006
c906108c
SS
3007@quotation
3008@cindex watchpoints and threads
3009@cindex threads and watchpoints
c906108c
SS
3010@emph{Warning:} In multi-thread programs, watchpoints have only limited
3011usefulness. With the current watchpoint implementation, @value{GDBN}
3012can only watch the value of an expression @emph{in a single thread}. If
3013you are confident that the expression can only change due to the current
3014thread's activity (and if you are also confident that no other thread
3015can become current), then you can use watchpoints as usual. However,
3016@value{GDBN} may not notice when a non-current thread's activity changes
3017the expression.
53a5351d 3018
d4f3574e 3019@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
3020@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
3021have only limited usefulness. If @value{GDBN} creates a software
3022watchpoint, it can only watch the value of an expression @emph{in a
3023single thread}. If you are confident that the expression can only
3024change due to the current thread's activity (and if you are also
3025confident that no other thread can become current), then you can use
3026software watchpoints as usual. However, @value{GDBN} may not notice
3027when a non-current thread's activity changes the expression. (Hardware
3028watchpoints, in contrast, watch an expression in all threads.)
c906108c 3029@end quotation
c906108c 3030
501eef12
AC
3031@xref{set remote hardware-watchpoint-limit}.
3032
6d2ebf8b 3033@node Set Catchpoints
c906108c 3034@subsection Setting catchpoints
d4f3574e 3035@cindex catchpoints, setting
c906108c
SS
3036@cindex exception handlers
3037@cindex event handling
3038
3039You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 3040kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
3041shared library. Use the @code{catch} command to set a catchpoint.
3042
3043@table @code
3044@kindex catch
3045@item catch @var{event}
3046Stop when @var{event} occurs. @var{event} can be any of the following:
3047@table @code
3048@item throw
4644b6e3 3049@cindex stop on C@t{++} exceptions
b37052ae 3050The throwing of a C@t{++} exception.
c906108c
SS
3051
3052@item catch
b37052ae 3053The catching of a C@t{++} exception.
c906108c
SS
3054
3055@item exec
4644b6e3 3056@cindex break on fork/exec
c906108c
SS
3057A call to @code{exec}. This is currently only available for HP-UX.
3058
3059@item fork
c906108c
SS
3060A call to @code{fork}. This is currently only available for HP-UX.
3061
3062@item vfork
c906108c
SS
3063A call to @code{vfork}. This is currently only available for HP-UX.
3064
3065@item load
3066@itemx load @var{libname}
4644b6e3 3067@cindex break on load/unload of shared library
c906108c
SS
3068The dynamic loading of any shared library, or the loading of the library
3069@var{libname}. This is currently only available for HP-UX.
3070
3071@item unload
3072@itemx unload @var{libname}
c906108c
SS
3073The unloading of any dynamically loaded shared library, or the unloading
3074of the library @var{libname}. This is currently only available for HP-UX.
3075@end table
3076
3077@item tcatch @var{event}
3078Set a catchpoint that is enabled only for one stop. The catchpoint is
3079automatically deleted after the first time the event is caught.
3080
3081@end table
3082
3083Use the @code{info break} command to list the current catchpoints.
3084
b37052ae 3085There are currently some limitations to C@t{++} exception handling
c906108c
SS
3086(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3087
3088@itemize @bullet
3089@item
3090If you call a function interactively, @value{GDBN} normally returns
3091control to you when the function has finished executing. If the call
3092raises an exception, however, the call may bypass the mechanism that
3093returns control to you and cause your program either to abort or to
3094simply continue running until it hits a breakpoint, catches a signal
3095that @value{GDBN} is listening for, or exits. This is the case even if
3096you set a catchpoint for the exception; catchpoints on exceptions are
3097disabled within interactive calls.
3098
3099@item
3100You cannot raise an exception interactively.
3101
3102@item
3103You cannot install an exception handler interactively.
3104@end itemize
3105
3106@cindex raise exceptions
3107Sometimes @code{catch} is not the best way to debug exception handling:
3108if you need to know exactly where an exception is raised, it is better to
3109stop @emph{before} the exception handler is called, since that way you
3110can see the stack before any unwinding takes place. If you set a
3111breakpoint in an exception handler instead, it may not be easy to find
3112out where the exception was raised.
3113
3114To stop just before an exception handler is called, you need some
b37052ae 3115knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
3116raised by calling a library function named @code{__raise_exception}
3117which has the following ANSI C interface:
3118
474c8240 3119@smallexample
c906108c 3120 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
3121 @var{id} is the exception identifier. */
3122 void __raise_exception (void **addr, void *id);
474c8240 3123@end smallexample
c906108c
SS
3124
3125@noindent
3126To make the debugger catch all exceptions before any stack
3127unwinding takes place, set a breakpoint on @code{__raise_exception}
3128(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
3129
3130With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
3131that depends on the value of @var{id}, you can stop your program when
3132a specific exception is raised. You can use multiple conditional
3133breakpoints to stop your program when any of a number of exceptions are
3134raised.
3135
3136
6d2ebf8b 3137@node Delete Breaks
c906108c
SS
3138@subsection Deleting breakpoints
3139
3140@cindex clearing breakpoints, watchpoints, catchpoints
3141@cindex deleting breakpoints, watchpoints, catchpoints
3142It is often necessary to eliminate a breakpoint, watchpoint, or
3143catchpoint once it has done its job and you no longer want your program
3144to stop there. This is called @dfn{deleting} the breakpoint. A
3145breakpoint that has been deleted no longer exists; it is forgotten.
3146
3147With the @code{clear} command you can delete breakpoints according to
3148where they are in your program. With the @code{delete} command you can
3149delete individual breakpoints, watchpoints, or catchpoints by specifying
3150their breakpoint numbers.
3151
3152It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3153automatically ignores breakpoints on the first instruction to be executed
3154when you continue execution without changing the execution address.
3155
3156@table @code
3157@kindex clear
3158@item clear
3159Delete any breakpoints at the next instruction to be executed in the
3160selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3161the innermost frame is selected, this is a good way to delete a
3162breakpoint where your program just stopped.
3163
3164@item clear @var{function}
3165@itemx clear @var{filename}:@var{function}
09d4efe1 3166Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
3167
3168@item clear @var{linenum}
3169@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
3170Delete any breakpoints set at or within the code of the specified
3171@var{linenum} of the specified @var{filename}.
c906108c
SS
3172
3173@cindex delete breakpoints
3174@kindex delete
41afff9a 3175@kindex d @r{(@code{delete})}
c5394b80
JM
3176@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3177Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3178ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3179breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3180confirm off}). You can abbreviate this command as @code{d}.
3181@end table
3182
6d2ebf8b 3183@node Disabling
c906108c
SS
3184@subsection Disabling breakpoints
3185
4644b6e3 3186@cindex enable/disable a breakpoint
c906108c
SS
3187Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3188prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3189it had been deleted, but remembers the information on the breakpoint so
3190that you can @dfn{enable} it again later.
3191
3192You disable and enable breakpoints, watchpoints, and catchpoints with
3193the @code{enable} and @code{disable} commands, optionally specifying one
3194or more breakpoint numbers as arguments. Use @code{info break} or
3195@code{info watch} to print a list of breakpoints, watchpoints, and
3196catchpoints if you do not know which numbers to use.
3197
3198A breakpoint, watchpoint, or catchpoint can have any of four different
3199states of enablement:
3200
3201@itemize @bullet
3202@item
3203Enabled. The breakpoint stops your program. A breakpoint set
3204with the @code{break} command starts out in this state.
3205@item
3206Disabled. The breakpoint has no effect on your program.
3207@item
3208Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3209disabled.
c906108c
SS
3210@item
3211Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3212immediately after it does so it is deleted permanently. A breakpoint
3213set with the @code{tbreak} command starts out in this state.
c906108c
SS
3214@end itemize
3215
3216You can use the following commands to enable or disable breakpoints,
3217watchpoints, and catchpoints:
3218
3219@table @code
c906108c 3220@kindex disable
41afff9a 3221@kindex dis @r{(@code{disable})}
c5394b80 3222@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3223Disable the specified breakpoints---or all breakpoints, if none are
3224listed. A disabled breakpoint has no effect but is not forgotten. All
3225options such as ignore-counts, conditions and commands are remembered in
3226case the breakpoint is enabled again later. You may abbreviate
3227@code{disable} as @code{dis}.
3228
c906108c 3229@kindex enable
c5394b80 3230@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3231Enable the specified breakpoints (or all defined breakpoints). They
3232become effective once again in stopping your program.
3233
c5394b80 3234@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3235Enable the specified breakpoints temporarily. @value{GDBN} disables any
3236of these breakpoints immediately after stopping your program.
3237
c5394b80 3238@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3239Enable the specified breakpoints to work once, then die. @value{GDBN}
3240deletes any of these breakpoints as soon as your program stops there.
09d4efe1 3241Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
3242@end table
3243
d4f3574e
SS
3244@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3245@c confusing: tbreak is also initially enabled.
c906108c
SS
3246Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3247,Setting breakpoints}), breakpoints that you set are initially enabled;
3248subsequently, they become disabled or enabled only when you use one of
3249the commands above. (The command @code{until} can set and delete a
3250breakpoint of its own, but it does not change the state of your other
3251breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3252stepping}.)
3253
6d2ebf8b 3254@node Conditions
c906108c
SS
3255@subsection Break conditions
3256@cindex conditional breakpoints
3257@cindex breakpoint conditions
3258
3259@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3260@c in particular for a watchpoint?
c906108c
SS
3261The simplest sort of breakpoint breaks every time your program reaches a
3262specified place. You can also specify a @dfn{condition} for a
3263breakpoint. A condition is just a Boolean expression in your
3264programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3265a condition evaluates the expression each time your program reaches it,
3266and your program stops only if the condition is @emph{true}.
3267
3268This is the converse of using assertions for program validation; in that
3269situation, you want to stop when the assertion is violated---that is,
3270when the condition is false. In C, if you want to test an assertion expressed
3271by the condition @var{assert}, you should set the condition
3272@samp{! @var{assert}} on the appropriate breakpoint.
3273
3274Conditions are also accepted for watchpoints; you may not need them,
3275since a watchpoint is inspecting the value of an expression anyhow---but
3276it might be simpler, say, to just set a watchpoint on a variable name,
3277and specify a condition that tests whether the new value is an interesting
3278one.
3279
3280Break conditions can have side effects, and may even call functions in
3281your program. This can be useful, for example, to activate functions
3282that log program progress, or to use your own print functions to
3283format special data structures. The effects are completely predictable
3284unless there is another enabled breakpoint at the same address. (In
3285that case, @value{GDBN} might see the other breakpoint first and stop your
3286program without checking the condition of this one.) Note that
d4f3574e
SS
3287breakpoint commands are usually more convenient and flexible than break
3288conditions for the
c906108c
SS
3289purpose of performing side effects when a breakpoint is reached
3290(@pxref{Break Commands, ,Breakpoint command lists}).
3291
3292Break conditions can be specified when a breakpoint is set, by using
3293@samp{if} in the arguments to the @code{break} command. @xref{Set
3294Breaks, ,Setting breakpoints}. They can also be changed at any time
3295with the @code{condition} command.
53a5351d 3296
c906108c
SS
3297You can also use the @code{if} keyword with the @code{watch} command.
3298The @code{catch} command does not recognize the @code{if} keyword;
3299@code{condition} is the only way to impose a further condition on a
3300catchpoint.
c906108c
SS
3301
3302@table @code
3303@kindex condition
3304@item condition @var{bnum} @var{expression}
3305Specify @var{expression} as the break condition for breakpoint,
3306watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3307breakpoint @var{bnum} stops your program only if the value of
3308@var{expression} is true (nonzero, in C). When you use
3309@code{condition}, @value{GDBN} checks @var{expression} immediately for
3310syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3311referents in the context of your breakpoint. If @var{expression} uses
3312symbols not referenced in the context of the breakpoint, @value{GDBN}
3313prints an error message:
3314
474c8240 3315@smallexample
d4f3574e 3316No symbol "foo" in current context.
474c8240 3317@end smallexample
d4f3574e
SS
3318
3319@noindent
c906108c
SS
3320@value{GDBN} does
3321not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3322command (or a command that sets a breakpoint with a condition, like
3323@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3324
3325@item condition @var{bnum}
3326Remove the condition from breakpoint number @var{bnum}. It becomes
3327an ordinary unconditional breakpoint.
3328@end table
3329
3330@cindex ignore count (of breakpoint)
3331A special case of a breakpoint condition is to stop only when the
3332breakpoint has been reached a certain number of times. This is so
3333useful that there is a special way to do it, using the @dfn{ignore
3334count} of the breakpoint. Every breakpoint has an ignore count, which
3335is an integer. Most of the time, the ignore count is zero, and
3336therefore has no effect. But if your program reaches a breakpoint whose
3337ignore count is positive, then instead of stopping, it just decrements
3338the ignore count by one and continues. As a result, if the ignore count
3339value is @var{n}, the breakpoint does not stop the next @var{n} times
3340your program reaches it.
3341
3342@table @code
3343@kindex ignore
3344@item ignore @var{bnum} @var{count}
3345Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3346The next @var{count} times the breakpoint is reached, your program's
3347execution does not stop; other than to decrement the ignore count, @value{GDBN}
3348takes no action.
3349
3350To make the breakpoint stop the next time it is reached, specify
3351a count of zero.
3352
3353When you use @code{continue} to resume execution of your program from a
3354breakpoint, you can specify an ignore count directly as an argument to
3355@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3356Stepping,,Continuing and stepping}.
3357
3358If a breakpoint has a positive ignore count and a condition, the
3359condition is not checked. Once the ignore count reaches zero,
3360@value{GDBN} resumes checking the condition.
3361
3362You could achieve the effect of the ignore count with a condition such
3363as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3364is decremented each time. @xref{Convenience Vars, ,Convenience
3365variables}.
3366@end table
3367
3368Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3369
3370
6d2ebf8b 3371@node Break Commands
c906108c
SS
3372@subsection Breakpoint command lists
3373
3374@cindex breakpoint commands
3375You can give any breakpoint (or watchpoint or catchpoint) a series of
3376commands to execute when your program stops due to that breakpoint. For
3377example, you might want to print the values of certain expressions, or
3378enable other breakpoints.
3379
3380@table @code
3381@kindex commands
3382@kindex end
3383@item commands @r{[}@var{bnum}@r{]}
3384@itemx @dots{} @var{command-list} @dots{}
3385@itemx end
3386Specify a list of commands for breakpoint number @var{bnum}. The commands
3387themselves appear on the following lines. Type a line containing just
3388@code{end} to terminate the commands.
3389
3390To remove all commands from a breakpoint, type @code{commands} and
3391follow it immediately with @code{end}; that is, give no commands.
3392
3393With no @var{bnum} argument, @code{commands} refers to the last
3394breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3395recently encountered).
3396@end table
3397
3398Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3399disabled within a @var{command-list}.
3400
3401You can use breakpoint commands to start your program up again. Simply
3402use the @code{continue} command, or @code{step}, or any other command
3403that resumes execution.
3404
3405Any other commands in the command list, after a command that resumes
3406execution, are ignored. This is because any time you resume execution
3407(even with a simple @code{next} or @code{step}), you may encounter
3408another breakpoint---which could have its own command list, leading to
3409ambiguities about which list to execute.
3410
3411@kindex silent
3412If the first command you specify in a command list is @code{silent}, the
3413usual message about stopping at a breakpoint is not printed. This may
3414be desirable for breakpoints that are to print a specific message and
3415then continue. If none of the remaining commands print anything, you
3416see no sign that the breakpoint was reached. @code{silent} is
3417meaningful only at the beginning of a breakpoint command list.
3418
3419The commands @code{echo}, @code{output}, and @code{printf} allow you to
3420print precisely controlled output, and are often useful in silent
3421breakpoints. @xref{Output, ,Commands for controlled output}.
3422
3423For example, here is how you could use breakpoint commands to print the
3424value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3425
474c8240 3426@smallexample
c906108c
SS
3427break foo if x>0
3428commands
3429silent
3430printf "x is %d\n",x
3431cont
3432end
474c8240 3433@end smallexample
c906108c
SS
3434
3435One application for breakpoint commands is to compensate for one bug so
3436you can test for another. Put a breakpoint just after the erroneous line
3437of code, give it a condition to detect the case in which something
3438erroneous has been done, and give it commands to assign correct values
3439to any variables that need them. End with the @code{continue} command
3440so that your program does not stop, and start with the @code{silent}
3441command so that no output is produced. Here is an example:
3442
474c8240 3443@smallexample
c906108c
SS
3444break 403
3445commands
3446silent
3447set x = y + 4
3448cont
3449end
474c8240 3450@end smallexample
c906108c 3451
6d2ebf8b 3452@node Breakpoint Menus
c906108c
SS
3453@subsection Breakpoint menus
3454@cindex overloading
3455@cindex symbol overloading
3456
b383017d 3457Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3458single function name
c906108c
SS
3459to be defined several times, for application in different contexts.
3460This is called @dfn{overloading}. When a function name is overloaded,
3461@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3462a breakpoint. If you realize this is a problem, you can use
3463something like @samp{break @var{function}(@var{types})} to specify which
3464particular version of the function you want. Otherwise, @value{GDBN} offers
3465you a menu of numbered choices for different possible breakpoints, and
3466waits for your selection with the prompt @samp{>}. The first two
3467options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3468sets a breakpoint at each definition of @var{function}, and typing
3469@kbd{0} aborts the @code{break} command without setting any new
3470breakpoints.
3471
3472For example, the following session excerpt shows an attempt to set a
3473breakpoint at the overloaded symbol @code{String::after}.
3474We choose three particular definitions of that function name:
3475
3476@c FIXME! This is likely to change to show arg type lists, at least
3477@smallexample
3478@group
3479(@value{GDBP}) b String::after
3480[0] cancel
3481[1] all
3482[2] file:String.cc; line number:867
3483[3] file:String.cc; line number:860
3484[4] file:String.cc; line number:875
3485[5] file:String.cc; line number:853
3486[6] file:String.cc; line number:846
3487[7] file:String.cc; line number:735
3488> 2 4 6
3489Breakpoint 1 at 0xb26c: file String.cc, line 867.
3490Breakpoint 2 at 0xb344: file String.cc, line 875.
3491Breakpoint 3 at 0xafcc: file String.cc, line 846.
3492Multiple breakpoints were set.
3493Use the "delete" command to delete unwanted
3494 breakpoints.
3495(@value{GDBP})
3496@end group
3497@end smallexample
c906108c
SS
3498
3499@c @ifclear BARETARGET
6d2ebf8b 3500@node Error in Breakpoints
d4f3574e 3501@subsection ``Cannot insert breakpoints''
c906108c
SS
3502@c
3503@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3504@c
d4f3574e
SS
3505Under some operating systems, breakpoints cannot be used in a program if
3506any other process is running that program. In this situation,
5d161b24 3507attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3508@value{GDBN} to print an error message:
3509
474c8240 3510@smallexample
d4f3574e
SS
3511Cannot insert breakpoints.
3512The same program may be running in another process.
474c8240 3513@end smallexample
d4f3574e
SS
3514
3515When this happens, you have three ways to proceed:
3516
3517@enumerate
3518@item
3519Remove or disable the breakpoints, then continue.
3520
3521@item
5d161b24 3522Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3523name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3524that @value{GDBN} should run your program under that name.
d4f3574e
SS
3525Then start your program again.
3526
3527@item
3528Relink your program so that the text segment is nonsharable, using the
3529linker option @samp{-N}. The operating system limitation may not apply
3530to nonsharable executables.
3531@end enumerate
c906108c
SS
3532@c @end ifclear
3533
d4f3574e
SS
3534A similar message can be printed if you request too many active
3535hardware-assisted breakpoints and watchpoints:
3536
3537@c FIXME: the precise wording of this message may change; the relevant
3538@c source change is not committed yet (Sep 3, 1999).
3539@smallexample
3540Stopped; cannot insert breakpoints.
3541You may have requested too many hardware breakpoints and watchpoints.
3542@end smallexample
3543
3544@noindent
3545This message is printed when you attempt to resume the program, since
3546only then @value{GDBN} knows exactly how many hardware breakpoints and
3547watchpoints it needs to insert.
3548
3549When this message is printed, you need to disable or remove some of the
3550hardware-assisted breakpoints and watchpoints, and then continue.
3551
1485d690
KB
3552@node Breakpoint related warnings
3553@subsection ``Breakpoint address adjusted...''
3554@cindex breakpoint address adjusted
3555
3556Some processor architectures place constraints on the addresses at
3557which breakpoints may be placed. For architectures thus constrained,
3558@value{GDBN} will attempt to adjust the breakpoint's address to comply
3559with the constraints dictated by the architecture.
3560
3561One example of such an architecture is the Fujitsu FR-V. The FR-V is
3562a VLIW architecture in which a number of RISC-like instructions may be
3563bundled together for parallel execution. The FR-V architecture
3564constrains the location of a breakpoint instruction within such a
3565bundle to the instruction with the lowest address. @value{GDBN}
3566honors this constraint by adjusting a breakpoint's address to the
3567first in the bundle.
3568
3569It is not uncommon for optimized code to have bundles which contain
3570instructions from different source statements, thus it may happen that
3571a breakpoint's address will be adjusted from one source statement to
3572another. Since this adjustment may significantly alter @value{GDBN}'s
3573breakpoint related behavior from what the user expects, a warning is
3574printed when the breakpoint is first set and also when the breakpoint
3575is hit.
3576
3577A warning like the one below is printed when setting a breakpoint
3578that's been subject to address adjustment:
3579
3580@smallexample
3581warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3582@end smallexample
3583
3584Such warnings are printed both for user settable and @value{GDBN}'s
3585internal breakpoints. If you see one of these warnings, you should
3586verify that a breakpoint set at the adjusted address will have the
3587desired affect. If not, the breakpoint in question may be removed and
b383017d 3588other breakpoints may be set which will have the desired behavior.
1485d690
KB
3589E.g., it may be sufficient to place the breakpoint at a later
3590instruction. A conditional breakpoint may also be useful in some
3591cases to prevent the breakpoint from triggering too often.
3592
3593@value{GDBN} will also issue a warning when stopping at one of these
3594adjusted breakpoints:
3595
3596@smallexample
3597warning: Breakpoint 1 address previously adjusted from 0x00010414
3598to 0x00010410.
3599@end smallexample
3600
3601When this warning is encountered, it may be too late to take remedial
3602action except in cases where the breakpoint is hit earlier or more
3603frequently than expected.
d4f3574e 3604
6d2ebf8b 3605@node Continuing and Stepping
c906108c
SS
3606@section Continuing and stepping
3607
3608@cindex stepping
3609@cindex continuing
3610@cindex resuming execution
3611@dfn{Continuing} means resuming program execution until your program
3612completes normally. In contrast, @dfn{stepping} means executing just
3613one more ``step'' of your program, where ``step'' may mean either one
3614line of source code, or one machine instruction (depending on what
7a292a7a
SS
3615particular command you use). Either when continuing or when stepping,
3616your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3617it stops due to a signal, you may want to use @code{handle}, or use
3618@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3619
3620@table @code
3621@kindex continue
41afff9a
EZ
3622@kindex c @r{(@code{continue})}
3623@kindex fg @r{(resume foreground execution)}
c906108c
SS
3624@item continue @r{[}@var{ignore-count}@r{]}
3625@itemx c @r{[}@var{ignore-count}@r{]}
3626@itemx fg @r{[}@var{ignore-count}@r{]}
3627Resume program execution, at the address where your program last stopped;
3628any breakpoints set at that address are bypassed. The optional argument
3629@var{ignore-count} allows you to specify a further number of times to
3630ignore a breakpoint at this location; its effect is like that of
3631@code{ignore} (@pxref{Conditions, ,Break conditions}).
3632
3633The argument @var{ignore-count} is meaningful only when your program
3634stopped due to a breakpoint. At other times, the argument to
3635@code{continue} is ignored.
3636
d4f3574e
SS
3637The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3638debugged program is deemed to be the foreground program) are provided
3639purely for convenience, and have exactly the same behavior as
3640@code{continue}.
c906108c
SS
3641@end table
3642
3643To resume execution at a different place, you can use @code{return}
3644(@pxref{Returning, ,Returning from a function}) to go back to the
3645calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3646different address}) to go to an arbitrary location in your program.
3647
3648A typical technique for using stepping is to set a breakpoint
3649(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3650beginning of the function or the section of your program where a problem
3651is believed to lie, run your program until it stops at that breakpoint,
3652and then step through the suspect area, examining the variables that are
3653interesting, until you see the problem happen.
3654
3655@table @code
3656@kindex step
41afff9a 3657@kindex s @r{(@code{step})}
c906108c
SS
3658@item step
3659Continue running your program until control reaches a different source
3660line, then stop it and return control to @value{GDBN}. This command is
3661abbreviated @code{s}.
3662
3663@quotation
3664@c "without debugging information" is imprecise; actually "without line
3665@c numbers in the debugging information". (gcc -g1 has debugging info but
3666@c not line numbers). But it seems complex to try to make that
3667@c distinction here.
3668@emph{Warning:} If you use the @code{step} command while control is
3669within a function that was compiled without debugging information,
3670execution proceeds until control reaches a function that does have
3671debugging information. Likewise, it will not step into a function which
3672is compiled without debugging information. To step through functions
3673without debugging information, use the @code{stepi} command, described
3674below.
3675@end quotation
3676
4a92d011
EZ
3677The @code{step} command only stops at the first instruction of a source
3678line. This prevents the multiple stops that could otherwise occur in
3679@code{switch} statements, @code{for} loops, etc. @code{step} continues
3680to stop if a function that has debugging information is called within
3681the line. In other words, @code{step} @emph{steps inside} any functions
3682called within the line.
c906108c 3683
d4f3574e
SS
3684Also, the @code{step} command only enters a function if there is line
3685number information for the function. Otherwise it acts like the
5d161b24 3686@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3687on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3688was any debugging information about the routine.
c906108c
SS
3689
3690@item step @var{count}
3691Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3692breakpoint is reached, or a signal not related to stepping occurs before
3693@var{count} steps, stepping stops right away.
c906108c
SS
3694
3695@kindex next
41afff9a 3696@kindex n @r{(@code{next})}
c906108c
SS
3697@item next @r{[}@var{count}@r{]}
3698Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3699This is similar to @code{step}, but function calls that appear within
3700the line of code are executed without stopping. Execution stops when
3701control reaches a different line of code at the original stack level
3702that was executing when you gave the @code{next} command. This command
3703is abbreviated @code{n}.
c906108c
SS
3704
3705An argument @var{count} is a repeat count, as for @code{step}.
3706
3707
3708@c FIX ME!! Do we delete this, or is there a way it fits in with
3709@c the following paragraph? --- Vctoria
3710@c
3711@c @code{next} within a function that lacks debugging information acts like
3712@c @code{step}, but any function calls appearing within the code of the
3713@c function are executed without stopping.
3714
d4f3574e
SS
3715The @code{next} command only stops at the first instruction of a
3716source line. This prevents multiple stops that could otherwise occur in
4a92d011 3717@code{switch} statements, @code{for} loops, etc.
c906108c 3718
b90a5f51
CF
3719@kindex set step-mode
3720@item set step-mode
3721@cindex functions without line info, and stepping
3722@cindex stepping into functions with no line info
3723@itemx set step-mode on
4a92d011 3724The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3725stop at the first instruction of a function which contains no debug line
3726information rather than stepping over it.
3727
4a92d011
EZ
3728This is useful in cases where you may be interested in inspecting the
3729machine instructions of a function which has no symbolic info and do not
3730want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3731
3732@item set step-mode off
4a92d011 3733Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3734debug information. This is the default.
3735
9c16f35a
EZ
3736@item show step-mode
3737Show whether @value{GDBN} will stop in or step over functions without
3738source line debug information.
3739
c906108c
SS
3740@kindex finish
3741@item finish
3742Continue running until just after function in the selected stack frame
3743returns. Print the returned value (if any).
3744
3745Contrast this with the @code{return} command (@pxref{Returning,
3746,Returning from a function}).
3747
3748@kindex until
41afff9a 3749@kindex u @r{(@code{until})}
09d4efe1 3750@cindex run until specified location
c906108c
SS
3751@item until
3752@itemx u
3753Continue running until a source line past the current line, in the
3754current stack frame, is reached. This command is used to avoid single
3755stepping through a loop more than once. It is like the @code{next}
3756command, except that when @code{until} encounters a jump, it
3757automatically continues execution until the program counter is greater
3758than the address of the jump.
3759
3760This means that when you reach the end of a loop after single stepping
3761though it, @code{until} makes your program continue execution until it
3762exits the loop. In contrast, a @code{next} command at the end of a loop
3763simply steps back to the beginning of the loop, which forces you to step
3764through the next iteration.
3765
3766@code{until} always stops your program if it attempts to exit the current
3767stack frame.
3768
3769@code{until} may produce somewhat counterintuitive results if the order
3770of machine code does not match the order of the source lines. For
3771example, in the following excerpt from a debugging session, the @code{f}
3772(@code{frame}) command shows that execution is stopped at line
3773@code{206}; yet when we use @code{until}, we get to line @code{195}:
3774
474c8240 3775@smallexample
c906108c
SS
3776(@value{GDBP}) f
3777#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3778206 expand_input();
3779(@value{GDBP}) until
3780195 for ( ; argc > 0; NEXTARG) @{
474c8240 3781@end smallexample
c906108c
SS
3782
3783This happened because, for execution efficiency, the compiler had
3784generated code for the loop closure test at the end, rather than the
3785start, of the loop---even though the test in a C @code{for}-loop is
3786written before the body of the loop. The @code{until} command appeared
3787to step back to the beginning of the loop when it advanced to this
3788expression; however, it has not really gone to an earlier
3789statement---not in terms of the actual machine code.
3790
3791@code{until} with no argument works by means of single
3792instruction stepping, and hence is slower than @code{until} with an
3793argument.
3794
3795@item until @var{location}
3796@itemx u @var{location}
3797Continue running your program until either the specified location is
3798reached, or the current stack frame returns. @var{location} is any of
3799the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
3800,Setting breakpoints}). This form of the command uses breakpoints, and
3801hence is quicker than @code{until} without an argument. The specified
3802location is actually reached only if it is in the current frame. This
3803implies that @code{until} can be used to skip over recursive function
3804invocations. For instance in the code below, if the current location is
3805line @code{96}, issuing @code{until 99} will execute the program up to
3806line @code{99} in the same invocation of factorial, i.e. after the inner
3807invocations have returned.
3808
3809@smallexample
381094 int factorial (int value)
381195 @{
381296 if (value > 1) @{
381397 value *= factorial (value - 1);
381498 @}
381599 return (value);
3816100 @}
3817@end smallexample
3818
3819
3820@kindex advance @var{location}
3821@itemx advance @var{location}
09d4efe1
EZ
3822Continue running the program up to the given @var{location}. An argument is
3823required, which should be of the same form as arguments for the @code{break}
c60eb6f1
EZ
3824command. Execution will also stop upon exit from the current stack
3825frame. This command is similar to @code{until}, but @code{advance} will
3826not skip over recursive function calls, and the target location doesn't
3827have to be in the same frame as the current one.
3828
c906108c
SS
3829
3830@kindex stepi
41afff9a 3831@kindex si @r{(@code{stepi})}
c906108c 3832@item stepi
96a2c332 3833@itemx stepi @var{arg}
c906108c
SS
3834@itemx si
3835Execute one machine instruction, then stop and return to the debugger.
3836
3837It is often useful to do @samp{display/i $pc} when stepping by machine
3838instructions. This makes @value{GDBN} automatically display the next
3839instruction to be executed, each time your program stops. @xref{Auto
3840Display,, Automatic display}.
3841
3842An argument is a repeat count, as in @code{step}.
3843
3844@need 750
3845@kindex nexti
41afff9a 3846@kindex ni @r{(@code{nexti})}
c906108c 3847@item nexti
96a2c332 3848@itemx nexti @var{arg}
c906108c
SS
3849@itemx ni
3850Execute one machine instruction, but if it is a function call,
3851proceed until the function returns.
3852
3853An argument is a repeat count, as in @code{next}.
3854@end table
3855
6d2ebf8b 3856@node Signals
c906108c
SS
3857@section Signals
3858@cindex signals
3859
3860A signal is an asynchronous event that can happen in a program. The
3861operating system defines the possible kinds of signals, and gives each
3862kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3863signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3864@code{SIGSEGV} is the signal a program gets from referencing a place in
3865memory far away from all the areas in use; @code{SIGALRM} occurs when
3866the alarm clock timer goes off (which happens only if your program has
3867requested an alarm).
3868
3869@cindex fatal signals
3870Some signals, including @code{SIGALRM}, are a normal part of the
3871functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3872errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3873program has not specified in advance some other way to handle the signal.
3874@code{SIGINT} does not indicate an error in your program, but it is normally
3875fatal so it can carry out the purpose of the interrupt: to kill the program.
3876
3877@value{GDBN} has the ability to detect any occurrence of a signal in your
3878program. You can tell @value{GDBN} in advance what to do for each kind of
3879signal.
3880
3881@cindex handling signals
24f93129
EZ
3882Normally, @value{GDBN} is set up to let the non-erroneous signals like
3883@code{SIGALRM} be silently passed to your program
3884(so as not to interfere with their role in the program's functioning)
c906108c
SS
3885but to stop your program immediately whenever an error signal happens.
3886You can change these settings with the @code{handle} command.
3887
3888@table @code
3889@kindex info signals
09d4efe1 3890@kindex info handle
c906108c 3891@item info signals
96a2c332 3892@itemx info handle
c906108c
SS
3893Print a table of all the kinds of signals and how @value{GDBN} has been told to
3894handle each one. You can use this to see the signal numbers of all
3895the defined types of signals.
3896
d4f3574e 3897@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3898
3899@kindex handle
3900@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3901Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3902can be the number of a signal or its name (with or without the
24f93129 3903@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3904@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3905known signals. The @var{keywords} say what change to make.
c906108c
SS
3906@end table
3907
3908@c @group
3909The keywords allowed by the @code{handle} command can be abbreviated.
3910Their full names are:
3911
3912@table @code
3913@item nostop
3914@value{GDBN} should not stop your program when this signal happens. It may
3915still print a message telling you that the signal has come in.
3916
3917@item stop
3918@value{GDBN} should stop your program when this signal happens. This implies
3919the @code{print} keyword as well.
3920
3921@item print
3922@value{GDBN} should print a message when this signal happens.
3923
3924@item noprint
3925@value{GDBN} should not mention the occurrence of the signal at all. This
3926implies the @code{nostop} keyword as well.
3927
3928@item pass
5ece1a18 3929@itemx noignore
c906108c
SS
3930@value{GDBN} should allow your program to see this signal; your program
3931can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3932and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3933
3934@item nopass
5ece1a18 3935@itemx ignore
c906108c 3936@value{GDBN} should not allow your program to see this signal.
5ece1a18 3937@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3938@end table
3939@c @end group
3940
d4f3574e
SS
3941When a signal stops your program, the signal is not visible to the
3942program until you
c906108c
SS
3943continue. Your program sees the signal then, if @code{pass} is in
3944effect for the signal in question @emph{at that time}. In other words,
3945after @value{GDBN} reports a signal, you can use the @code{handle}
3946command with @code{pass} or @code{nopass} to control whether your
3947program sees that signal when you continue.
3948
24f93129
EZ
3949The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3950non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3951@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3952erroneous signals.
3953
c906108c
SS
3954You can also use the @code{signal} command to prevent your program from
3955seeing a signal, or cause it to see a signal it normally would not see,
3956or to give it any signal at any time. For example, if your program stopped
3957due to some sort of memory reference error, you might store correct
3958values into the erroneous variables and continue, hoping to see more
3959execution; but your program would probably terminate immediately as
3960a result of the fatal signal once it saw the signal. To prevent this,
3961you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3962program a signal}.
c906108c 3963
6d2ebf8b 3964@node Thread Stops
c906108c
SS
3965@section Stopping and starting multi-thread programs
3966
3967When your program has multiple threads (@pxref{Threads,, Debugging
3968programs with multiple threads}), you can choose whether to set
3969breakpoints on all threads, or on a particular thread.
3970
3971@table @code
3972@cindex breakpoints and threads
3973@cindex thread breakpoints
3974@kindex break @dots{} thread @var{threadno}
3975@item break @var{linespec} thread @var{threadno}
3976@itemx break @var{linespec} thread @var{threadno} if @dots{}
3977@var{linespec} specifies source lines; there are several ways of
3978writing them, but the effect is always to specify some source line.
3979
3980Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3981to specify that you only want @value{GDBN} to stop the program when a
3982particular thread reaches this breakpoint. @var{threadno} is one of the
3983numeric thread identifiers assigned by @value{GDBN}, shown in the first
3984column of the @samp{info threads} display.
3985
3986If you do not specify @samp{thread @var{threadno}} when you set a
3987breakpoint, the breakpoint applies to @emph{all} threads of your
3988program.
3989
3990You can use the @code{thread} qualifier on conditional breakpoints as
3991well; in this case, place @samp{thread @var{threadno}} before the
3992breakpoint condition, like this:
3993
3994@smallexample
2df3850c 3995(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3996@end smallexample
3997
3998@end table
3999
4000@cindex stopped threads
4001@cindex threads, stopped
4002Whenever your program stops under @value{GDBN} for any reason,
4003@emph{all} threads of execution stop, not just the current thread. This
4004allows you to examine the overall state of the program, including
4005switching between threads, without worrying that things may change
4006underfoot.
4007
36d86913
MC
4008@cindex thread breakpoints and system calls
4009@cindex system calls and thread breakpoints
4010@cindex premature return from system calls
4011There is an unfortunate side effect. If one thread stops for a
4012breakpoint, or for some other reason, and another thread is blocked in a
4013system call, then the system call may return prematurely. This is a
4014consequence of the interaction between multiple threads and the signals
4015that @value{GDBN} uses to implement breakpoints and other events that
4016stop execution.
4017
4018To handle this problem, your program should check the return value of
4019each system call and react appropriately. This is good programming
4020style anyways.
4021
4022For example, do not write code like this:
4023
4024@smallexample
4025 sleep (10);
4026@end smallexample
4027
4028The call to @code{sleep} will return early if a different thread stops
4029at a breakpoint or for some other reason.
4030
4031Instead, write this:
4032
4033@smallexample
4034 int unslept = 10;
4035 while (unslept > 0)
4036 unslept = sleep (unslept);
4037@end smallexample
4038
4039A system call is allowed to return early, so the system is still
4040conforming to its specification. But @value{GDBN} does cause your
4041multi-threaded program to behave differently than it would without
4042@value{GDBN}.
4043
4044Also, @value{GDBN} uses internal breakpoints in the thread library to
4045monitor certain events such as thread creation and thread destruction.
4046When such an event happens, a system call in another thread may return
4047prematurely, even though your program does not appear to stop.
4048
c906108c
SS
4049@cindex continuing threads
4050@cindex threads, continuing
4051Conversely, whenever you restart the program, @emph{all} threads start
4052executing. @emph{This is true even when single-stepping} with commands
5d161b24 4053like @code{step} or @code{next}.
c906108c
SS
4054
4055In particular, @value{GDBN} cannot single-step all threads in lockstep.
4056Since thread scheduling is up to your debugging target's operating
4057system (not controlled by @value{GDBN}), other threads may
4058execute more than one statement while the current thread completes a
4059single step. Moreover, in general other threads stop in the middle of a
4060statement, rather than at a clean statement boundary, when the program
4061stops.
4062
4063You might even find your program stopped in another thread after
4064continuing or even single-stepping. This happens whenever some other
4065thread runs into a breakpoint, a signal, or an exception before the
4066first thread completes whatever you requested.
4067
4068On some OSes, you can lock the OS scheduler and thus allow only a single
4069thread to run.
4070
4071@table @code
4072@item set scheduler-locking @var{mode}
9c16f35a
EZ
4073@cindex scheduler locking mode
4074@cindex lock scheduler
c906108c
SS
4075Set the scheduler locking mode. If it is @code{off}, then there is no
4076locking and any thread may run at any time. If @code{on}, then only the
4077current thread may run when the inferior is resumed. The @code{step}
4078mode optimizes for single-stepping. It stops other threads from
4079``seizing the prompt'' by preempting the current thread while you are
4080stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 4081when you step. They are more likely to run when you @samp{next} over a
c906108c 4082function call, and they are completely free to run when you use commands
d4f3574e 4083like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 4084thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 4085@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
4086
4087@item show scheduler-locking
4088Display the current scheduler locking mode.
4089@end table
4090
c906108c 4091
6d2ebf8b 4092@node Stack
c906108c
SS
4093@chapter Examining the Stack
4094
4095When your program has stopped, the first thing you need to know is where it
4096stopped and how it got there.
4097
4098@cindex call stack
5d161b24
DB
4099Each time your program performs a function call, information about the call
4100is generated.
4101That information includes the location of the call in your program,
4102the arguments of the call,
c906108c 4103and the local variables of the function being called.
5d161b24 4104The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
4105The stack frames are allocated in a region of memory called the @dfn{call
4106stack}.
4107
4108When your program stops, the @value{GDBN} commands for examining the
4109stack allow you to see all of this information.
4110
4111@cindex selected frame
4112One of the stack frames is @dfn{selected} by @value{GDBN} and many
4113@value{GDBN} commands refer implicitly to the selected frame. In
4114particular, whenever you ask @value{GDBN} for the value of a variable in
4115your program, the value is found in the selected frame. There are
4116special @value{GDBN} commands to select whichever frame you are
4117interested in. @xref{Selection, ,Selecting a frame}.
4118
4119When your program stops, @value{GDBN} automatically selects the
5d161b24 4120currently executing frame and describes it briefly, similar to the
c906108c
SS
4121@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
4122
4123@menu
4124* Frames:: Stack frames
4125* Backtrace:: Backtraces
4126* Selection:: Selecting a frame
4127* Frame Info:: Information on a frame
c906108c
SS
4128
4129@end menu
4130
6d2ebf8b 4131@node Frames
c906108c
SS
4132@section Stack frames
4133
d4f3574e 4134@cindex frame, definition
c906108c
SS
4135@cindex stack frame
4136The call stack is divided up into contiguous pieces called @dfn{stack
4137frames}, or @dfn{frames} for short; each frame is the data associated
4138with one call to one function. The frame contains the arguments given
4139to the function, the function's local variables, and the address at
4140which the function is executing.
4141
4142@cindex initial frame
4143@cindex outermost frame
4144@cindex innermost frame
4145When your program is started, the stack has only one frame, that of the
4146function @code{main}. This is called the @dfn{initial} frame or the
4147@dfn{outermost} frame. Each time a function is called, a new frame is
4148made. Each time a function returns, the frame for that function invocation
4149is eliminated. If a function is recursive, there can be many frames for
4150the same function. The frame for the function in which execution is
4151actually occurring is called the @dfn{innermost} frame. This is the most
4152recently created of all the stack frames that still exist.
4153
4154@cindex frame pointer
4155Inside your program, stack frames are identified by their addresses. A
4156stack frame consists of many bytes, each of which has its own address; each
4157kind of computer has a convention for choosing one byte whose
4158address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
4159in a register called the @dfn{frame pointer register}
4160(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
4161
4162@cindex frame number
4163@value{GDBN} assigns numbers to all existing stack frames, starting with
4164zero for the innermost frame, one for the frame that called it,
4165and so on upward. These numbers do not really exist in your program;
4166they are assigned by @value{GDBN} to give you a way of designating stack
4167frames in @value{GDBN} commands.
4168
6d2ebf8b
SS
4169@c The -fomit-frame-pointer below perennially causes hbox overflow
4170@c underflow problems.
c906108c
SS
4171@cindex frameless execution
4172Some compilers provide a way to compile functions so that they operate
6d2ebf8b 4173without stack frames. (For example, the @value{GCC} option
474c8240 4174@smallexample
6d2ebf8b 4175@samp{-fomit-frame-pointer}
474c8240 4176@end smallexample
6d2ebf8b 4177generates functions without a frame.)
c906108c
SS
4178This is occasionally done with heavily used library functions to save
4179the frame setup time. @value{GDBN} has limited facilities for dealing
4180with these function invocations. If the innermost function invocation
4181has no stack frame, @value{GDBN} nevertheless regards it as though
4182it had a separate frame, which is numbered zero as usual, allowing
4183correct tracing of the function call chain. However, @value{GDBN} has
4184no provision for frameless functions elsewhere in the stack.
4185
4186@table @code
d4f3574e 4187@kindex frame@r{, command}
41afff9a 4188@cindex current stack frame
c906108c 4189@item frame @var{args}
5d161b24 4190The @code{frame} command allows you to move from one stack frame to another,
c906108c 4191and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4192address of the frame or the stack frame number. Without an argument,
4193@code{frame} prints the current stack frame.
c906108c
SS
4194
4195@kindex select-frame
41afff9a 4196@cindex selecting frame silently
c906108c
SS
4197@item select-frame
4198The @code{select-frame} command allows you to move from one stack frame
4199to another without printing the frame. This is the silent version of
4200@code{frame}.
4201@end table
4202
6d2ebf8b 4203@node Backtrace
c906108c
SS
4204@section Backtraces
4205
09d4efe1
EZ
4206@cindex traceback
4207@cindex call stack traces
c906108c
SS
4208A backtrace is a summary of how your program got where it is. It shows one
4209line per frame, for many frames, starting with the currently executing
4210frame (frame zero), followed by its caller (frame one), and on up the
4211stack.
4212
4213@table @code
4214@kindex backtrace
41afff9a 4215@kindex bt @r{(@code{backtrace})}
c906108c
SS
4216@item backtrace
4217@itemx bt
4218Print a backtrace of the entire stack: one line per frame for all
4219frames in the stack.
4220
4221You can stop the backtrace at any time by typing the system interrupt
4222character, normally @kbd{C-c}.
4223
4224@item backtrace @var{n}
4225@itemx bt @var{n}
4226Similar, but print only the innermost @var{n} frames.
4227
4228@item backtrace -@var{n}
4229@itemx bt -@var{n}
4230Similar, but print only the outermost @var{n} frames.
0f061b69
NR
4231
4232@item backtrace full
4233Print the values of the local variables also.
4234@itemx bt full
c906108c
SS
4235@end table
4236
4237@kindex where
4238@kindex info stack
c906108c
SS
4239The names @code{where} and @code{info stack} (abbreviated @code{info s})
4240are additional aliases for @code{backtrace}.
4241
4242Each line in the backtrace shows the frame number and the function name.
4243The program counter value is also shown---unless you use @code{set
4244print address off}. The backtrace also shows the source file name and
4245line number, as well as the arguments to the function. The program
4246counter value is omitted if it is at the beginning of the code for that
4247line number.
4248
4249Here is an example of a backtrace. It was made with the command
4250@samp{bt 3}, so it shows the innermost three frames.
4251
4252@smallexample
4253@group
5d161b24 4254#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4255 at builtin.c:993
4256#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4257#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4258 at macro.c:71
4259(More stack frames follow...)
4260@end group
4261@end smallexample
4262
4263@noindent
4264The display for frame zero does not begin with a program counter
4265value, indicating that your program has stopped at the beginning of the
4266code for line @code{993} of @code{builtin.c}.
4267
18999be5
EZ
4268@cindex value optimized out, in backtrace
4269@cindex function call arguments, optimized out
4270If your program was compiled with optimizations, some compilers will
4271optimize away arguments passed to functions if those arguments are
4272never used after the call. Such optimizations generate code that
4273passes arguments through registers, but doesn't store those arguments
4274in the stack frame. @value{GDBN} has no way of displaying such
4275arguments in stack frames other than the innermost one. Here's what
4276such a backtrace might look like:
4277
4278@smallexample
4279@group
4280#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4281 at builtin.c:993
4282#1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
4283#2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
4284 at macro.c:71
4285(More stack frames follow...)
4286@end group
4287@end smallexample
4288
4289@noindent
4290The values of arguments that were not saved in their stack frames are
4291shown as @samp{<value optimized out>}.
4292
4293If you need to display the values of such optimized-out arguments,
4294either deduce that from other variables whose values depend on the one
4295you are interested in, or recompile without optimizations.
4296
a8f24a35
EZ
4297@cindex backtrace beyond @code{main} function
4298@cindex program entry point
4299@cindex startup code, and backtrace
25d29d70
AC
4300Most programs have a standard user entry point---a place where system
4301libraries and startup code transition into user code. For C this is
4302@code{main}. When @value{GDBN} finds the entry function in a backtrace
4303it will terminate the backtrace, to avoid tracing into highly
4304system-specific (and generally uninteresting) code.
4305
4306If you need to examine the startup code, or limit the number of levels
4307in a backtrace, you can change this behavior:
95f90d25
DJ
4308
4309@table @code
25d29d70
AC
4310@item set backtrace past-main
4311@itemx set backtrace past-main on
4644b6e3 4312@kindex set backtrace
25d29d70
AC
4313Backtraces will continue past the user entry point.
4314
4315@item set backtrace past-main off
95f90d25
DJ
4316Backtraces will stop when they encounter the user entry point. This is the
4317default.
4318
25d29d70 4319@item show backtrace past-main
4644b6e3 4320@kindex show backtrace
25d29d70
AC
4321Display the current user entry point backtrace policy.
4322
2315ffec
RC
4323@item set backtrace past-entry
4324@itemx set backtrace past-entry on
a8f24a35 4325Backtraces will continue past the internal entry point of an application.
2315ffec
RC
4326This entry point is encoded by the linker when the application is built,
4327and is likely before the user entry point @code{main} (or equivalent) is called.
4328
4329@item set backtrace past-entry off
4330Backtraces will stop when they encouter the internal entry point of an
4331application. This is the default.
4332
4333@item show backtrace past-entry
4334Display the current internal entry point backtrace policy.
4335
25d29d70
AC
4336@item set backtrace limit @var{n}
4337@itemx set backtrace limit 0
4338@cindex backtrace limit
4339Limit the backtrace to @var{n} levels. A value of zero means
4340unlimited.
95f90d25 4341
25d29d70
AC
4342@item show backtrace limit
4343Display the current limit on backtrace levels.
95f90d25
DJ
4344@end table
4345
6d2ebf8b 4346@node Selection
c906108c
SS
4347@section Selecting a frame
4348
4349Most commands for examining the stack and other data in your program work on
4350whichever stack frame is selected at the moment. Here are the commands for
4351selecting a stack frame; all of them finish by printing a brief description
4352of the stack frame just selected.
4353
4354@table @code
d4f3574e 4355@kindex frame@r{, selecting}
41afff9a 4356@kindex f @r{(@code{frame})}
c906108c
SS
4357@item frame @var{n}
4358@itemx f @var{n}
4359Select frame number @var{n}. Recall that frame zero is the innermost
4360(currently executing) frame, frame one is the frame that called the
4361innermost one, and so on. The highest-numbered frame is the one for
4362@code{main}.
4363
4364@item frame @var{addr}
4365@itemx f @var{addr}
4366Select the frame at address @var{addr}. This is useful mainly if the
4367chaining of stack frames has been damaged by a bug, making it
4368impossible for @value{GDBN} to assign numbers properly to all frames. In
4369addition, this can be useful when your program has multiple stacks and
4370switches between them.
4371
c906108c
SS
4372On the SPARC architecture, @code{frame} needs two addresses to
4373select an arbitrary frame: a frame pointer and a stack pointer.
4374
4375On the MIPS and Alpha architecture, it needs two addresses: a stack
4376pointer and a program counter.
4377
4378On the 29k architecture, it needs three addresses: a register stack
4379pointer, a program counter, and a memory stack pointer.
4380@c note to future updaters: this is conditioned on a flag
4381@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
4382@c as of 27 Jan 1994.
c906108c
SS
4383
4384@kindex up
4385@item up @var{n}
4386Move @var{n} frames up the stack. For positive numbers @var{n}, this
4387advances toward the outermost frame, to higher frame numbers, to frames
4388that have existed longer. @var{n} defaults to one.
4389
4390@kindex down
41afff9a 4391@kindex do @r{(@code{down})}
c906108c
SS
4392@item down @var{n}
4393Move @var{n} frames down the stack. For positive numbers @var{n}, this
4394advances toward the innermost frame, to lower frame numbers, to frames
4395that were created more recently. @var{n} defaults to one. You may
4396abbreviate @code{down} as @code{do}.
4397@end table
4398
4399All of these commands end by printing two lines of output describing the
4400frame. The first line shows the frame number, the function name, the
4401arguments, and the source file and line number of execution in that
5d161b24 4402frame. The second line shows the text of that source line.
c906108c
SS
4403
4404@need 1000
4405For example:
4406
4407@smallexample
4408@group
4409(@value{GDBP}) up
4410#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4411 at env.c:10
441210 read_input_file (argv[i]);
4413@end group
4414@end smallexample
4415
4416After such a printout, the @code{list} command with no arguments
4417prints ten lines centered on the point of execution in the frame.
87885426
FN
4418You can also edit the program at the point of execution with your favorite
4419editing program by typing @code{edit}.
4420@xref{List, ,Printing source lines},
4421for details.
c906108c
SS
4422
4423@table @code
4424@kindex down-silently
4425@kindex up-silently
4426@item up-silently @var{n}
4427@itemx down-silently @var{n}
4428These two commands are variants of @code{up} and @code{down},
4429respectively; they differ in that they do their work silently, without
4430causing display of the new frame. They are intended primarily for use
4431in @value{GDBN} command scripts, where the output might be unnecessary and
4432distracting.
4433@end table
4434
6d2ebf8b 4435@node Frame Info
c906108c
SS
4436@section Information about a frame
4437
4438There are several other commands to print information about the selected
4439stack frame.
4440
4441@table @code
4442@item frame
4443@itemx f
4444When used without any argument, this command does not change which
4445frame is selected, but prints a brief description of the currently
4446selected stack frame. It can be abbreviated @code{f}. With an
4447argument, this command is used to select a stack frame.
4448@xref{Selection, ,Selecting a frame}.
4449
4450@kindex info frame
41afff9a 4451@kindex info f @r{(@code{info frame})}
c906108c
SS
4452@item info frame
4453@itemx info f
4454This command prints a verbose description of the selected stack frame,
4455including:
4456
4457@itemize @bullet
5d161b24
DB
4458@item
4459the address of the frame
c906108c
SS
4460@item
4461the address of the next frame down (called by this frame)
4462@item
4463the address of the next frame up (caller of this frame)
4464@item
4465the language in which the source code corresponding to this frame is written
4466@item
4467the address of the frame's arguments
4468@item
d4f3574e
SS
4469the address of the frame's local variables
4470@item
c906108c
SS
4471the program counter saved in it (the address of execution in the caller frame)
4472@item
4473which registers were saved in the frame
4474@end itemize
4475
4476@noindent The verbose description is useful when
4477something has gone wrong that has made the stack format fail to fit
4478the usual conventions.
4479
4480@item info frame @var{addr}
4481@itemx info f @var{addr}
4482Print a verbose description of the frame at address @var{addr}, without
4483selecting that frame. The selected frame remains unchanged by this
4484command. This requires the same kind of address (more than one for some
4485architectures) that you specify in the @code{frame} command.
4486@xref{Selection, ,Selecting a frame}.
4487
4488@kindex info args
4489@item info args
4490Print the arguments of the selected frame, each on a separate line.
4491
4492@item info locals
4493@kindex info locals
4494Print the local variables of the selected frame, each on a separate
4495line. These are all variables (declared either static or automatic)
4496accessible at the point of execution of the selected frame.
4497
c906108c 4498@kindex info catch
d4f3574e
SS
4499@cindex catch exceptions, list active handlers
4500@cindex exception handlers, how to list
c906108c
SS
4501@item info catch
4502Print a list of all the exception handlers that are active in the
4503current stack frame at the current point of execution. To see other
4504exception handlers, visit the associated frame (using the @code{up},
4505@code{down}, or @code{frame} commands); then type @code{info catch}.
4506@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4507
c906108c
SS
4508@end table
4509
c906108c 4510
6d2ebf8b 4511@node Source
c906108c
SS
4512@chapter Examining Source Files
4513
4514@value{GDBN} can print parts of your program's source, since the debugging
4515information recorded in the program tells @value{GDBN} what source files were
4516used to build it. When your program stops, @value{GDBN} spontaneously prints
4517the line where it stopped. Likewise, when you select a stack frame
4518(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4519execution in that frame has stopped. You can print other portions of
4520source files by explicit command.
4521
7a292a7a 4522If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4523prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4524@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4525
4526@menu
4527* List:: Printing source lines
87885426 4528* Edit:: Editing source files
c906108c 4529* Search:: Searching source files
c906108c
SS
4530* Source Path:: Specifying source directories
4531* Machine Code:: Source and machine code
4532@end menu
4533
6d2ebf8b 4534@node List
c906108c
SS
4535@section Printing source lines
4536
4537@kindex list
41afff9a 4538@kindex l @r{(@code{list})}
c906108c 4539To print lines from a source file, use the @code{list} command
5d161b24 4540(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4541There are several ways to specify what part of the file you want to print.
4542
4543Here are the forms of the @code{list} command most commonly used:
4544
4545@table @code
4546@item list @var{linenum}
4547Print lines centered around line number @var{linenum} in the
4548current source file.
4549
4550@item list @var{function}
4551Print lines centered around the beginning of function
4552@var{function}.
4553
4554@item list
4555Print more lines. If the last lines printed were printed with a
4556@code{list} command, this prints lines following the last lines
4557printed; however, if the last line printed was a solitary line printed
4558as part of displaying a stack frame (@pxref{Stack, ,Examining the
4559Stack}), this prints lines centered around that line.
4560
4561@item list -
4562Print lines just before the lines last printed.
4563@end table
4564
9c16f35a 4565@cindex @code{list}, how many lines to display
c906108c
SS
4566By default, @value{GDBN} prints ten source lines with any of these forms of
4567the @code{list} command. You can change this using @code{set listsize}:
4568
4569@table @code
4570@kindex set listsize
4571@item set listsize @var{count}
4572Make the @code{list} command display @var{count} source lines (unless
4573the @code{list} argument explicitly specifies some other number).
4574
4575@kindex show listsize
4576@item show listsize
4577Display the number of lines that @code{list} prints.
4578@end table
4579
4580Repeating a @code{list} command with @key{RET} discards the argument,
4581so it is equivalent to typing just @code{list}. This is more useful
4582than listing the same lines again. An exception is made for an
4583argument of @samp{-}; that argument is preserved in repetition so that
4584each repetition moves up in the source file.
4585
4586@cindex linespec
4587In general, the @code{list} command expects you to supply zero, one or two
4588@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4589of writing them, but the effect is always to specify some source line.
c906108c
SS
4590Here is a complete description of the possible arguments for @code{list}:
4591
4592@table @code
4593@item list @var{linespec}
4594Print lines centered around the line specified by @var{linespec}.
4595
4596@item list @var{first},@var{last}
4597Print lines from @var{first} to @var{last}. Both arguments are
4598linespecs.
4599
4600@item list ,@var{last}
4601Print lines ending with @var{last}.
4602
4603@item list @var{first},
4604Print lines starting with @var{first}.
4605
4606@item list +
4607Print lines just after the lines last printed.
4608
4609@item list -
4610Print lines just before the lines last printed.
4611
4612@item list
4613As described in the preceding table.
4614@end table
4615
4616Here are the ways of specifying a single source line---all the
4617kinds of linespec.
4618
4619@table @code
4620@item @var{number}
4621Specifies line @var{number} of the current source file.
4622When a @code{list} command has two linespecs, this refers to
4623the same source file as the first linespec.
4624
4625@item +@var{offset}
4626Specifies the line @var{offset} lines after the last line printed.
4627When used as the second linespec in a @code{list} command that has
4628two, this specifies the line @var{offset} lines down from the
4629first linespec.
4630
4631@item -@var{offset}
4632Specifies the line @var{offset} lines before the last line printed.
4633
4634@item @var{filename}:@var{number}
4635Specifies line @var{number} in the source file @var{filename}.
4636
4637@item @var{function}
4638Specifies the line that begins the body of the function @var{function}.
4639For example: in C, this is the line with the open brace.
4640
4641@item @var{filename}:@var{function}
4642Specifies the line of the open-brace that begins the body of the
4643function @var{function} in the file @var{filename}. You only need the
4644file name with a function name to avoid ambiguity when there are
4645identically named functions in different source files.
4646
4647@item *@var{address}
4648Specifies the line containing the program address @var{address}.
4649@var{address} may be any expression.
4650@end table
4651
87885426
FN
4652@node Edit
4653@section Editing source files
4654@cindex editing source files
4655
4656@kindex edit
4657@kindex e @r{(@code{edit})}
4658To edit the lines in a source file, use the @code{edit} command.
4659The editing program of your choice
4660is invoked with the current line set to
4661the active line in the program.
4662Alternatively, there are several ways to specify what part of the file you
4663want to print if you want to see other parts of the program.
4664
4665Here are the forms of the @code{edit} command most commonly used:
4666
4667@table @code
4668@item edit
4669Edit the current source file at the active line number in the program.
4670
4671@item edit @var{number}
4672Edit the current source file with @var{number} as the active line number.
4673
4674@item edit @var{function}
4675Edit the file containing @var{function} at the beginning of its definition.
4676
4677@item edit @var{filename}:@var{number}
4678Specifies line @var{number} in the source file @var{filename}.
4679
4680@item edit @var{filename}:@var{function}
4681Specifies the line that begins the body of the
4682function @var{function} in the file @var{filename}. You only need the
4683file name with a function name to avoid ambiguity when there are
4684identically named functions in different source files.
4685
4686@item edit *@var{address}
4687Specifies the line containing the program address @var{address}.
4688@var{address} may be any expression.
4689@end table
4690
4691@subsection Choosing your editor
4692You can customize @value{GDBN} to use any editor you want
4693@footnote{
4694The only restriction is that your editor (say @code{ex}), recognizes the
4695following command-line syntax:
10998722 4696@smallexample
87885426 4697ex +@var{number} file
10998722 4698@end smallexample
15387254
EZ
4699The optional numeric value +@var{number} specifies the number of the line in
4700the file where to start editing.}.
4701By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4702by setting the environment variable @code{EDITOR} before using
4703@value{GDBN}. For example, to configure @value{GDBN} to use the
4704@code{vi} editor, you could use these commands with the @code{sh} shell:
4705@smallexample
87885426
FN
4706EDITOR=/usr/bin/vi
4707export EDITOR
15387254 4708gdb @dots{}
10998722 4709@end smallexample
87885426 4710or in the @code{csh} shell,
10998722 4711@smallexample
87885426 4712setenv EDITOR /usr/bin/vi
15387254 4713gdb @dots{}
10998722 4714@end smallexample
87885426 4715
6d2ebf8b 4716@node Search
c906108c 4717@section Searching source files
15387254 4718@cindex searching source files
c906108c
SS
4719
4720There are two commands for searching through the current source file for a
4721regular expression.
4722
4723@table @code
4724@kindex search
4725@kindex forward-search
4726@item forward-search @var{regexp}
4727@itemx search @var{regexp}
4728The command @samp{forward-search @var{regexp}} checks each line,
4729starting with the one following the last line listed, for a match for
5d161b24 4730@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4731synonym @samp{search @var{regexp}} or abbreviate the command name as
4732@code{fo}.
4733
09d4efe1 4734@kindex reverse-search
c906108c
SS
4735@item reverse-search @var{regexp}
4736The command @samp{reverse-search @var{regexp}} checks each line, starting
4737with the one before the last line listed and going backward, for a match
4738for @var{regexp}. It lists the line that is found. You can abbreviate
4739this command as @code{rev}.
4740@end table
c906108c 4741
6d2ebf8b 4742@node Source Path
c906108c
SS
4743@section Specifying source directories
4744
4745@cindex source path
4746@cindex directories for source files
4747Executable programs sometimes do not record the directories of the source
4748files from which they were compiled, just the names. Even when they do,
4749the directories could be moved between the compilation and your debugging
4750session. @value{GDBN} has a list of directories to search for source files;
4751this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4752it tries all the directories in the list, in the order they are present
0b66e38c
EZ
4753in the list, until it finds a file with the desired name.
4754
4755For example, suppose an executable references the file
4756@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4757@file{/mnt/cross}. The file is first looked up literally; if this
4758fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4759fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4760message is printed. @value{GDBN} does not look up the parts of the
4761source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4762Likewise, the subdirectories of the source path are not searched: if
4763the source path is @file{/mnt/cross}, and the binary refers to
4764@file{foo.c}, @value{GDBN} would not find it under
4765@file{/mnt/cross/usr/src/foo-1.0/lib}.
4766
4767Plain file names, relative file names with leading directories, file
4768names containing dots, etc.@: are all treated as described above; for
4769instance, if the source path is @file{/mnt/cross}, and the source file
4770is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4771@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4772that---@file{/mnt/cross/foo.c}.
4773
4774Note that the executable search path is @emph{not} used to locate the
4775source files. Neither is the current working directory, unless it
4776happens to be in the source path.
c906108c
SS
4777
4778Whenever you reset or rearrange the source path, @value{GDBN} clears out
4779any information it has cached about where source files are found and where
4780each line is in the file.
4781
4782@kindex directory
4783@kindex dir
d4f3574e
SS
4784When you start @value{GDBN}, its source path includes only @samp{cdir}
4785and @samp{cwd}, in that order.
c906108c
SS
4786To add other directories, use the @code{directory} command.
4787
4788@table @code
4789@item directory @var{dirname} @dots{}
4790@item dir @var{dirname} @dots{}
4791Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4792directory names may be given to this command, separated by @samp{:}
4793(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4794part of absolute file names) or
c906108c
SS
4795whitespace. You may specify a directory that is already in the source
4796path; this moves it forward, so @value{GDBN} searches it sooner.
4797
4798@kindex cdir
4799@kindex cwd
41afff9a
EZ
4800@vindex $cdir@r{, convenience variable}
4801@vindex $cwdr@r{, convenience variable}
c906108c
SS
4802@cindex compilation directory
4803@cindex current directory
4804@cindex working directory
4805@cindex directory, current
4806@cindex directory, compilation
4807You can use the string @samp{$cdir} to refer to the compilation
4808directory (if one is recorded), and @samp{$cwd} to refer to the current
4809working directory. @samp{$cwd} is not the same as @samp{.}---the former
4810tracks the current working directory as it changes during your @value{GDBN}
4811session, while the latter is immediately expanded to the current
4812directory at the time you add an entry to the source path.
4813
4814@item directory
4815Reset the source path to empty again. This requires confirmation.
4816
4817@c RET-repeat for @code{directory} is explicitly disabled, but since
4818@c repeating it would be a no-op we do not say that. (thanks to RMS)
4819
4820@item show directories
4821@kindex show directories
4822Print the source path: show which directories it contains.
4823@end table
4824
4825If your source path is cluttered with directories that are no longer of
4826interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4827versions of source. You can correct the situation as follows:
4828
4829@enumerate
4830@item
4831Use @code{directory} with no argument to reset the source path to empty.
4832
4833@item
4834Use @code{directory} with suitable arguments to reinstall the
4835directories you want in the source path. You can add all the
4836directories in one command.
4837@end enumerate
4838
6d2ebf8b 4839@node Machine Code
c906108c 4840@section Source and machine code
15387254 4841@cindex source line and its code address
c906108c
SS
4842
4843You can use the command @code{info line} to map source lines to program
4844addresses (and vice versa), and the command @code{disassemble} to display
4845a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4846mode, the @code{info line} command causes the arrow to point to the
5d161b24 4847line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4848well as hex.
4849
4850@table @code
4851@kindex info line
4852@item info line @var{linespec}
4853Print the starting and ending addresses of the compiled code for
4854source line @var{linespec}. You can specify source lines in any of
4855the ways understood by the @code{list} command (@pxref{List, ,Printing
4856source lines}).
4857@end table
4858
4859For example, we can use @code{info line} to discover the location of
4860the object code for the first line of function
4861@code{m4_changequote}:
4862
d4f3574e
SS
4863@c FIXME: I think this example should also show the addresses in
4864@c symbolic form, as they usually would be displayed.
c906108c 4865@smallexample
96a2c332 4866(@value{GDBP}) info line m4_changequote
c906108c
SS
4867Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4868@end smallexample
4869
4870@noindent
15387254 4871@cindex code address and its source line
c906108c
SS
4872We can also inquire (using @code{*@var{addr}} as the form for
4873@var{linespec}) what source line covers a particular address:
4874@smallexample
4875(@value{GDBP}) info line *0x63ff
4876Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4877@end smallexample
4878
4879@cindex @code{$_} and @code{info line}
15387254 4880@cindex @code{x} command, default address
41afff9a 4881@kindex x@r{(examine), and} info line
c906108c
SS
4882After @code{info line}, the default address for the @code{x} command
4883is changed to the starting address of the line, so that @samp{x/i} is
4884sufficient to begin examining the machine code (@pxref{Memory,
4885,Examining memory}). Also, this address is saved as the value of the
4886convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4887variables}).
4888
4889@table @code
4890@kindex disassemble
4891@cindex assembly instructions
4892@cindex instructions, assembly
4893@cindex machine instructions
4894@cindex listing machine instructions
4895@item disassemble
4896This specialized command dumps a range of memory as machine
4897instructions. The default memory range is the function surrounding the
4898program counter of the selected frame. A single argument to this
4899command is a program counter value; @value{GDBN} dumps the function
4900surrounding this value. Two arguments specify a range of addresses
4901(first inclusive, second exclusive) to dump.
4902@end table
4903
c906108c
SS
4904The following example shows the disassembly of a range of addresses of
4905HP PA-RISC 2.0 code:
4906
4907@smallexample
4908(@value{GDBP}) disas 0x32c4 0x32e4
4909Dump of assembler code from 0x32c4 to 0x32e4:
49100x32c4 <main+204>: addil 0,dp
49110x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
49120x32cc <main+212>: ldil 0x3000,r31
49130x32d0 <main+216>: ble 0x3f8(sr4,r31)
49140x32d4 <main+220>: ldo 0(r31),rp
49150x32d8 <main+224>: addil -0x800,dp
49160x32dc <main+228>: ldo 0x588(r1),r26
49170x32e0 <main+232>: ldil 0x3000,r31
4918End of assembler dump.
4919@end smallexample
c906108c
SS
4920
4921Some architectures have more than one commonly-used set of instruction
4922mnemonics or other syntax.
4923
4924@table @code
d4f3574e 4925@kindex set disassembly-flavor
d4f3574e
SS
4926@cindex Intel disassembly flavor
4927@cindex AT&T disassembly flavor
4928@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4929Select the instruction set to use when disassembling the
4930program via the @code{disassemble} or @code{x/i} commands.
4931
4932Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4933can set @var{instruction-set} to either @code{intel} or @code{att}.
4934The default is @code{att}, the AT&T flavor used by default by Unix
4935assemblers for x86-based targets.
9c16f35a
EZ
4936
4937@kindex show disassembly-flavor
4938@item show disassembly-flavor
4939Show the current setting of the disassembly flavor.
c906108c
SS
4940@end table
4941
4942
6d2ebf8b 4943@node Data
c906108c
SS
4944@chapter Examining Data
4945
4946@cindex printing data
4947@cindex examining data
4948@kindex print
4949@kindex inspect
4950@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4951@c document because it is nonstandard... Under Epoch it displays in a
4952@c different window or something like that.
4953The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4954command (abbreviated @code{p}), or its synonym @code{inspect}. It
4955evaluates and prints the value of an expression of the language your
4956program is written in (@pxref{Languages, ,Using @value{GDBN} with
4957Different Languages}).
c906108c
SS
4958
4959@table @code
d4f3574e
SS
4960@item print @var{expr}
4961@itemx print /@var{f} @var{expr}
4962@var{expr} is an expression (in the source language). By default the
4963value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4964you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4965@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4966formats}.
4967
4968@item print
4969@itemx print /@var{f}
15387254 4970@cindex reprint the last value
d4f3574e 4971If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4972@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4973conveniently inspect the same value in an alternative format.
4974@end table
4975
4976A more low-level way of examining data is with the @code{x} command.
4977It examines data in memory at a specified address and prints it in a
4978specified format. @xref{Memory, ,Examining memory}.
4979
7a292a7a 4980If you are interested in information about types, or about how the
d4f3574e
SS
4981fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4982command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4983Table}.
c906108c
SS
4984
4985@menu
4986* Expressions:: Expressions
4987* Variables:: Program variables
4988* Arrays:: Artificial arrays
4989* Output Formats:: Output formats
4990* Memory:: Examining memory
4991* Auto Display:: Automatic display
4992* Print Settings:: Print settings
4993* Value History:: Value history
4994* Convenience Vars:: Convenience variables
4995* Registers:: Registers
c906108c 4996* Floating Point Hardware:: Floating point hardware
53c69bd7 4997* Vector Unit:: Vector Unit
721c2651 4998* OS Information:: Auxiliary data provided by operating system
29e57380 4999* Memory Region Attributes:: Memory region attributes
16d9dec6 5000* Dump/Restore Files:: Copy between memory and a file
384ee23f 5001* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
5002* Character Sets:: Debugging programs that use a different
5003 character set than GDB does
09d4efe1 5004* Caching Remote Data:: Data caching for remote targets
c906108c
SS
5005@end menu
5006
6d2ebf8b 5007@node Expressions
c906108c
SS
5008@section Expressions
5009
5010@cindex expressions
5011@code{print} and many other @value{GDBN} commands accept an expression and
5012compute its value. Any kind of constant, variable or operator defined
5013by the programming language you are using is valid in an expression in
e2e0bcd1
JB
5014@value{GDBN}. This includes conditional expressions, function calls,
5015casts, and string constants. It also includes preprocessor macros, if
5016you compiled your program to include this information; see
5017@ref{Compilation}.
c906108c 5018
15387254 5019@cindex arrays in expressions
d4f3574e
SS
5020@value{GDBN} supports array constants in expressions input by
5021the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 5022you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 5023memory that is @code{malloc}ed in the target program.
c906108c 5024
c906108c
SS
5025Because C is so widespread, most of the expressions shown in examples in
5026this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
5027Languages}, for information on how to use expressions in other
5028languages.
5029
5030In this section, we discuss operators that you can use in @value{GDBN}
5031expressions regardless of your programming language.
5032
15387254 5033@cindex casts, in expressions
c906108c
SS
5034Casts are supported in all languages, not just in C, because it is so
5035useful to cast a number into a pointer in order to examine a structure
5036at that address in memory.
5037@c FIXME: casts supported---Mod2 true?
c906108c
SS
5038
5039@value{GDBN} supports these operators, in addition to those common
5040to programming languages:
5041
5042@table @code
5043@item @@
5044@samp{@@} is a binary operator for treating parts of memory as arrays.
5045@xref{Arrays, ,Artificial arrays}, for more information.
5046
5047@item ::
5048@samp{::} allows you to specify a variable in terms of the file or
5049function where it is defined. @xref{Variables, ,Program variables}.
5050
5051@cindex @{@var{type}@}
5052@cindex type casting memory
5053@cindex memory, viewing as typed object
5054@cindex casts, to view memory
5055@item @{@var{type}@} @var{addr}
5056Refers to an object of type @var{type} stored at address @var{addr} in
5057memory. @var{addr} may be any expression whose value is an integer or
5058pointer (but parentheses are required around binary operators, just as in
5059a cast). This construct is allowed regardless of what kind of data is
5060normally supposed to reside at @var{addr}.
5061@end table
5062
6d2ebf8b 5063@node Variables
c906108c
SS
5064@section Program variables
5065
5066The most common kind of expression to use is the name of a variable
5067in your program.
5068
5069Variables in expressions are understood in the selected stack frame
5070(@pxref{Selection, ,Selecting a frame}); they must be either:
5071
5072@itemize @bullet
5073@item
5074global (or file-static)
5075@end itemize
5076
5d161b24 5077@noindent or
c906108c
SS
5078
5079@itemize @bullet
5080@item
5081visible according to the scope rules of the
5082programming language from the point of execution in that frame
5d161b24 5083@end itemize
c906108c
SS
5084
5085@noindent This means that in the function
5086
474c8240 5087@smallexample
c906108c
SS
5088foo (a)
5089 int a;
5090@{
5091 bar (a);
5092 @{
5093 int b = test ();
5094 bar (b);
5095 @}
5096@}
474c8240 5097@end smallexample
c906108c
SS
5098
5099@noindent
5100you can examine and use the variable @code{a} whenever your program is
5101executing within the function @code{foo}, but you can only use or
5102examine the variable @code{b} while your program is executing inside
5103the block where @code{b} is declared.
5104
5105@cindex variable name conflict
5106There is an exception: you can refer to a variable or function whose
5107scope is a single source file even if the current execution point is not
5108in this file. But it is possible to have more than one such variable or
5109function with the same name (in different source files). If that
5110happens, referring to that name has unpredictable effects. If you wish,
5111you can specify a static variable in a particular function or file,
15387254 5112using the colon-colon (@code{::}) notation:
c906108c 5113
d4f3574e 5114@cindex colon-colon, context for variables/functions
c906108c
SS
5115@iftex
5116@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 5117@cindex @code{::}, context for variables/functions
c906108c 5118@end iftex
474c8240 5119@smallexample
c906108c
SS
5120@var{file}::@var{variable}
5121@var{function}::@var{variable}
474c8240 5122@end smallexample
c906108c
SS
5123
5124@noindent
5125Here @var{file} or @var{function} is the name of the context for the
5126static @var{variable}. In the case of file names, you can use quotes to
5127make sure @value{GDBN} parses the file name as a single word---for example,
5128to print a global value of @code{x} defined in @file{f2.c}:
5129
474c8240 5130@smallexample
c906108c 5131(@value{GDBP}) p 'f2.c'::x
474c8240 5132@end smallexample
c906108c 5133
b37052ae 5134@cindex C@t{++} scope resolution
c906108c 5135This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 5136use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
5137scope resolution operator in @value{GDBN} expressions.
5138@c FIXME: Um, so what happens in one of those rare cases where it's in
5139@c conflict?? --mew
c906108c
SS
5140
5141@cindex wrong values
5142@cindex variable values, wrong
15387254
EZ
5143@cindex function entry/exit, wrong values of variables
5144@cindex optimized code, wrong values of variables
c906108c
SS
5145@quotation
5146@emph{Warning:} Occasionally, a local variable may appear to have the
5147wrong value at certain points in a function---just after entry to a new
5148scope, and just before exit.
5149@end quotation
5150You may see this problem when you are stepping by machine instructions.
5151This is because, on most machines, it takes more than one instruction to
5152set up a stack frame (including local variable definitions); if you are
5153stepping by machine instructions, variables may appear to have the wrong
5154values until the stack frame is completely built. On exit, it usually
5155also takes more than one machine instruction to destroy a stack frame;
5156after you begin stepping through that group of instructions, local
5157variable definitions may be gone.
5158
5159This may also happen when the compiler does significant optimizations.
5160To be sure of always seeing accurate values, turn off all optimization
5161when compiling.
5162
d4f3574e
SS
5163@cindex ``No symbol "foo" in current context''
5164Another possible effect of compiler optimizations is to optimize
5165unused variables out of existence, or assign variables to registers (as
5166opposed to memory addresses). Depending on the support for such cases
5167offered by the debug info format used by the compiler, @value{GDBN}
5168might not be able to display values for such local variables. If that
5169happens, @value{GDBN} will print a message like this:
5170
474c8240 5171@smallexample
d4f3574e 5172No symbol "foo" in current context.
474c8240 5173@end smallexample
d4f3574e
SS
5174
5175To solve such problems, either recompile without optimizations, or use a
5176different debug info format, if the compiler supports several such
15387254 5177formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
5178usually supports the @option{-gstabs+} option. @option{-gstabs+}
5179produces debug info in a format that is superior to formats such as
5180COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5181an effective form for debug info. @xref{Debugging Options,,Options
5182for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
5183@xref{C, , Debugging C++}, for more info about debug info formats
5184that are best suited to C@t{++} programs.
d4f3574e 5185
6d2ebf8b 5186@node Arrays
c906108c
SS
5187@section Artificial arrays
5188
5189@cindex artificial array
15387254 5190@cindex arrays
41afff9a 5191@kindex @@@r{, referencing memory as an array}
c906108c
SS
5192It is often useful to print out several successive objects of the
5193same type in memory; a section of an array, or an array of
5194dynamically determined size for which only a pointer exists in the
5195program.
5196
5197You can do this by referring to a contiguous span of memory as an
5198@dfn{artificial array}, using the binary operator @samp{@@}. The left
5199operand of @samp{@@} should be the first element of the desired array
5200and be an individual object. The right operand should be the desired length
5201of the array. The result is an array value whose elements are all of
5202the type of the left argument. The first element is actually the left
5203argument; the second element comes from bytes of memory immediately
5204following those that hold the first element, and so on. Here is an
5205example. If a program says
5206
474c8240 5207@smallexample
c906108c 5208int *array = (int *) malloc (len * sizeof (int));
474c8240 5209@end smallexample
c906108c
SS
5210
5211@noindent
5212you can print the contents of @code{array} with
5213
474c8240 5214@smallexample
c906108c 5215p *array@@len
474c8240 5216@end smallexample
c906108c
SS
5217
5218The left operand of @samp{@@} must reside in memory. Array values made
5219with @samp{@@} in this way behave just like other arrays in terms of
5220subscripting, and are coerced to pointers when used in expressions.
5221Artificial arrays most often appear in expressions via the value history
5222(@pxref{Value History, ,Value history}), after printing one out.
5223
5224Another way to create an artificial array is to use a cast.
5225This re-interprets a value as if it were an array.
5226The value need not be in memory:
474c8240 5227@smallexample
c906108c
SS
5228(@value{GDBP}) p/x (short[2])0x12345678
5229$1 = @{0x1234, 0x5678@}
474c8240 5230@end smallexample
c906108c
SS
5231
5232As a convenience, if you leave the array length out (as in
c3f6f71d 5233@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5234the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5235@smallexample
c906108c
SS
5236(@value{GDBP}) p/x (short[])0x12345678
5237$2 = @{0x1234, 0x5678@}
474c8240 5238@end smallexample
c906108c
SS
5239
5240Sometimes the artificial array mechanism is not quite enough; in
5241moderately complex data structures, the elements of interest may not
5242actually be adjacent---for example, if you are interested in the values
5243of pointers in an array. One useful work-around in this situation is
5244to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5245variables}) as a counter in an expression that prints the first
5246interesting value, and then repeat that expression via @key{RET}. For
5247instance, suppose you have an array @code{dtab} of pointers to
5248structures, and you are interested in the values of a field @code{fv}
5249in each structure. Here is an example of what you might type:
5250
474c8240 5251@smallexample
c906108c
SS
5252set $i = 0
5253p dtab[$i++]->fv
5254@key{RET}
5255@key{RET}
5256@dots{}
474c8240 5257@end smallexample
c906108c 5258
6d2ebf8b 5259@node Output Formats
c906108c
SS
5260@section Output formats
5261
5262@cindex formatted output
5263@cindex output formats
5264By default, @value{GDBN} prints a value according to its data type. Sometimes
5265this is not what you want. For example, you might want to print a number
5266in hex, or a pointer in decimal. Or you might want to view data in memory
5267at a certain address as a character string or as an instruction. To do
5268these things, specify an @dfn{output format} when you print a value.
5269
5270The simplest use of output formats is to say how to print a value
5271already computed. This is done by starting the arguments of the
5272@code{print} command with a slash and a format letter. The format
5273letters supported are:
5274
5275@table @code
5276@item x
5277Regard the bits of the value as an integer, and print the integer in
5278hexadecimal.
5279
5280@item d
5281Print as integer in signed decimal.
5282
5283@item u
5284Print as integer in unsigned decimal.
5285
5286@item o
5287Print as integer in octal.
5288
5289@item t
5290Print as integer in binary. The letter @samp{t} stands for ``two''.
5291@footnote{@samp{b} cannot be used because these format letters are also
5292used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5293see @ref{Memory,,Examining memory}.}
c906108c
SS
5294
5295@item a
5296@cindex unknown address, locating
3d67e040 5297@cindex locate address
c906108c
SS
5298Print as an address, both absolute in hexadecimal and as an offset from
5299the nearest preceding symbol. You can use this format used to discover
5300where (in what function) an unknown address is located:
5301
474c8240 5302@smallexample
c906108c
SS
5303(@value{GDBP}) p/a 0x54320
5304$3 = 0x54320 <_initialize_vx+396>
474c8240 5305@end smallexample
c906108c 5306
3d67e040
EZ
5307@noindent
5308The command @code{info symbol 0x54320} yields similar results.
5309@xref{Symbols, info symbol}.
5310
c906108c 5311@item c
51274035
EZ
5312Regard as an integer and print it as a character constant. This
5313prints both the numerical value and its character representation. The
5314character representation is replaced with the octal escape @samp{\nnn}
5315for characters outside the 7-bit @sc{ascii} range.
c906108c
SS
5316
5317@item f
5318Regard the bits of the value as a floating point number and print
5319using typical floating point syntax.
5320@end table
5321
5322For example, to print the program counter in hex (@pxref{Registers}), type
5323
474c8240 5324@smallexample
c906108c 5325p/x $pc
474c8240 5326@end smallexample
c906108c
SS
5327
5328@noindent
5329Note that no space is required before the slash; this is because command
5330names in @value{GDBN} cannot contain a slash.
5331
5332To reprint the last value in the value history with a different format,
5333you can use the @code{print} command with just a format and no
5334expression. For example, @samp{p/x} reprints the last value in hex.
5335
6d2ebf8b 5336@node Memory
c906108c
SS
5337@section Examining memory
5338
5339You can use the command @code{x} (for ``examine'') to examine memory in
5340any of several formats, independently of your program's data types.
5341
5342@cindex examining memory
5343@table @code
41afff9a 5344@kindex x @r{(examine memory)}
c906108c
SS
5345@item x/@var{nfu} @var{addr}
5346@itemx x @var{addr}
5347@itemx x
5348Use the @code{x} command to examine memory.
5349@end table
5350
5351@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5352much memory to display and how to format it; @var{addr} is an
5353expression giving the address where you want to start displaying memory.
5354If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5355Several commands set convenient defaults for @var{addr}.
5356
5357@table @r
5358@item @var{n}, the repeat count
5359The repeat count is a decimal integer; the default is 1. It specifies
5360how much memory (counting by units @var{u}) to display.
5361@c This really is **decimal**; unaffected by 'set radix' as of GDB
5362@c 4.1.2.
5363
5364@item @var{f}, the display format
51274035
EZ
5365The display format is one of the formats used by @code{print}
5366(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
5367@samp{f}), and in addition @samp{s} (for null-terminated strings) and
5368@samp{i} (for machine instructions). The default is @samp{x}
5369(hexadecimal) initially. The default changes each time you use either
5370@code{x} or @code{print}.
c906108c
SS
5371
5372@item @var{u}, the unit size
5373The unit size is any of
5374
5375@table @code
5376@item b
5377Bytes.
5378@item h
5379Halfwords (two bytes).
5380@item w
5381Words (four bytes). This is the initial default.
5382@item g
5383Giant words (eight bytes).
5384@end table
5385
5386Each time you specify a unit size with @code{x}, that size becomes the
5387default unit the next time you use @code{x}. (For the @samp{s} and
5388@samp{i} formats, the unit size is ignored and is normally not written.)
5389
5390@item @var{addr}, starting display address
5391@var{addr} is the address where you want @value{GDBN} to begin displaying
5392memory. The expression need not have a pointer value (though it may);
5393it is always interpreted as an integer address of a byte of memory.
5394@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5395@var{addr} is usually just after the last address examined---but several
5396other commands also set the default address: @code{info breakpoints} (to
5397the address of the last breakpoint listed), @code{info line} (to the
5398starting address of a line), and @code{print} (if you use it to display
5399a value from memory).
5400@end table
5401
5402For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5403(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5404starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5405words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5406@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5407
5408Since the letters indicating unit sizes are all distinct from the
5409letters specifying output formats, you do not have to remember whether
5410unit size or format comes first; either order works. The output
5411specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5412(However, the count @var{n} must come first; @samp{wx4} does not work.)
5413
5414Even though the unit size @var{u} is ignored for the formats @samp{s}
5415and @samp{i}, you might still want to use a count @var{n}; for example,
5416@samp{3i} specifies that you want to see three machine instructions,
5417including any operands. The command @code{disassemble} gives an
d4f3574e 5418alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5419Code,,Source and machine code}.
5420
5421All the defaults for the arguments to @code{x} are designed to make it
5422easy to continue scanning memory with minimal specifications each time
5423you use @code{x}. For example, after you have inspected three machine
5424instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5425with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5426the repeat count @var{n} is used again; the other arguments default as
5427for successive uses of @code{x}.
5428
5429@cindex @code{$_}, @code{$__}, and value history
5430The addresses and contents printed by the @code{x} command are not saved
5431in the value history because there is often too much of them and they
5432would get in the way. Instead, @value{GDBN} makes these values available for
5433subsequent use in expressions as values of the convenience variables
5434@code{$_} and @code{$__}. After an @code{x} command, the last address
5435examined is available for use in expressions in the convenience variable
5436@code{$_}. The contents of that address, as examined, are available in
5437the convenience variable @code{$__}.
5438
5439If the @code{x} command has a repeat count, the address and contents saved
5440are from the last memory unit printed; this is not the same as the last
5441address printed if several units were printed on the last line of output.
5442
09d4efe1
EZ
5443@cindex remote memory comparison
5444@cindex verify remote memory image
5445When you are debugging a program running on a remote target machine
5446(@pxref{Remote}), you may wish to verify the program's image in the
5447remote machine's memory against the executable file you downloaded to
5448the target. The @code{compare-sections} command is provided for such
5449situations.
5450
5451@table @code
5452@kindex compare-sections
5453@item compare-sections @r{[}@var{section-name}@r{]}
5454Compare the data of a loadable section @var{section-name} in the
5455executable file of the program being debugged with the same section in
5456the remote machine's memory, and report any mismatches. With no
5457arguments, compares all loadable sections. This command's
5458availability depends on the target's support for the @code{"qCRC"}
5459remote request.
5460@end table
5461
6d2ebf8b 5462@node Auto Display
c906108c
SS
5463@section Automatic display
5464@cindex automatic display
5465@cindex display of expressions
5466
5467If you find that you want to print the value of an expression frequently
5468(to see how it changes), you might want to add it to the @dfn{automatic
5469display list} so that @value{GDBN} prints its value each time your program stops.
5470Each expression added to the list is given a number to identify it;
5471to remove an expression from the list, you specify that number.
5472The automatic display looks like this:
5473
474c8240 5474@smallexample
c906108c
SS
54752: foo = 38
54763: bar[5] = (struct hack *) 0x3804
474c8240 5477@end smallexample
c906108c
SS
5478
5479@noindent
5480This display shows item numbers, expressions and their current values. As with
5481displays you request manually using @code{x} or @code{print}, you can
5482specify the output format you prefer; in fact, @code{display} decides
5483whether to use @code{print} or @code{x} depending on how elaborate your
5484format specification is---it uses @code{x} if you specify a unit size,
5485or one of the two formats (@samp{i} and @samp{s}) that are only
5486supported by @code{x}; otherwise it uses @code{print}.
5487
5488@table @code
5489@kindex display
d4f3574e
SS
5490@item display @var{expr}
5491Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5492each time your program stops. @xref{Expressions, ,Expressions}.
5493
5494@code{display} does not repeat if you press @key{RET} again after using it.
5495
d4f3574e 5496@item display/@var{fmt} @var{expr}
c906108c 5497For @var{fmt} specifying only a display format and not a size or
d4f3574e 5498count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5499arrange to display it each time in the specified format @var{fmt}.
5500@xref{Output Formats,,Output formats}.
5501
5502@item display/@var{fmt} @var{addr}
5503For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5504number of units, add the expression @var{addr} as a memory address to
5505be examined each time your program stops. Examining means in effect
5506doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5507@end table
5508
5509For example, @samp{display/i $pc} can be helpful, to see the machine
5510instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5511is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5512
5513@table @code
5514@kindex delete display
5515@kindex undisplay
5516@item undisplay @var{dnums}@dots{}
5517@itemx delete display @var{dnums}@dots{}
5518Remove item numbers @var{dnums} from the list of expressions to display.
5519
5520@code{undisplay} does not repeat if you press @key{RET} after using it.
5521(Otherwise you would just get the error @samp{No display number @dots{}}.)
5522
5523@kindex disable display
5524@item disable display @var{dnums}@dots{}
5525Disable the display of item numbers @var{dnums}. A disabled display
5526item is not printed automatically, but is not forgotten. It may be
5527enabled again later.
5528
5529@kindex enable display
5530@item enable display @var{dnums}@dots{}
5531Enable display of item numbers @var{dnums}. It becomes effective once
5532again in auto display of its expression, until you specify otherwise.
5533
5534@item display
5535Display the current values of the expressions on the list, just as is
5536done when your program stops.
5537
5538@kindex info display
5539@item info display
5540Print the list of expressions previously set up to display
5541automatically, each one with its item number, but without showing the
5542values. This includes disabled expressions, which are marked as such.
5543It also includes expressions which would not be displayed right now
5544because they refer to automatic variables not currently available.
5545@end table
5546
15387254 5547@cindex display disabled out of scope
c906108c
SS
5548If a display expression refers to local variables, then it does not make
5549sense outside the lexical context for which it was set up. Such an
5550expression is disabled when execution enters a context where one of its
5551variables is not defined. For example, if you give the command
5552@code{display last_char} while inside a function with an argument
5553@code{last_char}, @value{GDBN} displays this argument while your program
5554continues to stop inside that function. When it stops elsewhere---where
5555there is no variable @code{last_char}---the display is disabled
5556automatically. The next time your program stops where @code{last_char}
5557is meaningful, you can enable the display expression once again.
5558
6d2ebf8b 5559@node Print Settings
c906108c
SS
5560@section Print settings
5561
5562@cindex format options
5563@cindex print settings
5564@value{GDBN} provides the following ways to control how arrays, structures,
5565and symbols are printed.
5566
5567@noindent
5568These settings are useful for debugging programs in any language:
5569
5570@table @code
4644b6e3 5571@kindex set print
c906108c
SS
5572@item set print address
5573@itemx set print address on
4644b6e3 5574@cindex print/don't print memory addresses
c906108c
SS
5575@value{GDBN} prints memory addresses showing the location of stack
5576traces, structure values, pointer values, breakpoints, and so forth,
5577even when it also displays the contents of those addresses. The default
5578is @code{on}. For example, this is what a stack frame display looks like with
5579@code{set print address on}:
5580
5581@smallexample
5582@group
5583(@value{GDBP}) f
5584#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5585 at input.c:530
5586530 if (lquote != def_lquote)
5587@end group
5588@end smallexample
5589
5590@item set print address off
5591Do not print addresses when displaying their contents. For example,
5592this is the same stack frame displayed with @code{set print address off}:
5593
5594@smallexample
5595@group
5596(@value{GDBP}) set print addr off
5597(@value{GDBP}) f
5598#0 set_quotes (lq="<<", rq=">>") at input.c:530
5599530 if (lquote != def_lquote)
5600@end group
5601@end smallexample
5602
5603You can use @samp{set print address off} to eliminate all machine
5604dependent displays from the @value{GDBN} interface. For example, with
5605@code{print address off}, you should get the same text for backtraces on
5606all machines---whether or not they involve pointer arguments.
5607
4644b6e3 5608@kindex show print
c906108c
SS
5609@item show print address
5610Show whether or not addresses are to be printed.
5611@end table
5612
5613When @value{GDBN} prints a symbolic address, it normally prints the
5614closest earlier symbol plus an offset. If that symbol does not uniquely
5615identify the address (for example, it is a name whose scope is a single
5616source file), you may need to clarify. One way to do this is with
5617@code{info line}, for example @samp{info line *0x4537}. Alternately,
5618you can set @value{GDBN} to print the source file and line number when
5619it prints a symbolic address:
5620
5621@table @code
c906108c 5622@item set print symbol-filename on
9c16f35a
EZ
5623@cindex source file and line of a symbol
5624@cindex symbol, source file and line
c906108c
SS
5625Tell @value{GDBN} to print the source file name and line number of a
5626symbol in the symbolic form of an address.
5627
5628@item set print symbol-filename off
5629Do not print source file name and line number of a symbol. This is the
5630default.
5631
c906108c
SS
5632@item show print symbol-filename
5633Show whether or not @value{GDBN} will print the source file name and
5634line number of a symbol in the symbolic form of an address.
5635@end table
5636
5637Another situation where it is helpful to show symbol filenames and line
5638numbers is when disassembling code; @value{GDBN} shows you the line
5639number and source file that corresponds to each instruction.
5640
5641Also, you may wish to see the symbolic form only if the address being
5642printed is reasonably close to the closest earlier symbol:
5643
5644@table @code
c906108c 5645@item set print max-symbolic-offset @var{max-offset}
4644b6e3 5646@cindex maximum value for offset of closest symbol
c906108c
SS
5647Tell @value{GDBN} to only display the symbolic form of an address if the
5648offset between the closest earlier symbol and the address is less than
5d161b24 5649@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5650to always print the symbolic form of an address if any symbol precedes it.
5651
c906108c
SS
5652@item show print max-symbolic-offset
5653Ask how large the maximum offset is that @value{GDBN} prints in a
5654symbolic address.
5655@end table
5656
5657@cindex wild pointer, interpreting
5658@cindex pointer, finding referent
5659If you have a pointer and you are not sure where it points, try
5660@samp{set print symbol-filename on}. Then you can determine the name
5661and source file location of the variable where it points, using
5662@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5663For example, here @value{GDBN} shows that a variable @code{ptt} points
5664at another variable @code{t}, defined in @file{hi2.c}:
5665
474c8240 5666@smallexample
c906108c
SS
5667(@value{GDBP}) set print symbol-filename on
5668(@value{GDBP}) p/a ptt
5669$4 = 0xe008 <t in hi2.c>
474c8240 5670@end smallexample
c906108c
SS
5671
5672@quotation
5673@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5674does not show the symbol name and filename of the referent, even with
5675the appropriate @code{set print} options turned on.
5676@end quotation
5677
5678Other settings control how different kinds of objects are printed:
5679
5680@table @code
c906108c
SS
5681@item set print array
5682@itemx set print array on
4644b6e3 5683@cindex pretty print arrays
c906108c
SS
5684Pretty print arrays. This format is more convenient to read,
5685but uses more space. The default is off.
5686
5687@item set print array off
5688Return to compressed format for arrays.
5689
c906108c
SS
5690@item show print array
5691Show whether compressed or pretty format is selected for displaying
5692arrays.
5693
c906108c 5694@item set print elements @var{number-of-elements}
4644b6e3 5695@cindex number of array elements to print
9c16f35a 5696@cindex limit on number of printed array elements
c906108c
SS
5697Set a limit on how many elements of an array @value{GDBN} will print.
5698If @value{GDBN} is printing a large array, it stops printing after it has
5699printed the number of elements set by the @code{set print elements} command.
5700This limit also applies to the display of strings.
d4f3574e 5701When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5702Setting @var{number-of-elements} to zero means that the printing is unlimited.
5703
c906108c
SS
5704@item show print elements
5705Display the number of elements of a large array that @value{GDBN} will print.
5706If the number is 0, then the printing is unlimited.
5707
9c16f35a
EZ
5708@item set print repeats
5709@cindex repeated array elements
5710Set the threshold for suppressing display of repeated array
5711elelments. When the number of consecutive identical elements of an
5712array exceeds the threshold, @value{GDBN} prints the string
5713@code{"<repeats @var{n} times>"}, where @var{n} is the number of
5714identical repetitions, instead of displaying the identical elements
5715themselves. Setting the threshold to zero will cause all elements to
5716be individually printed. The default threshold is 10.
5717
5718@item show print repeats
5719Display the current threshold for printing repeated identical
5720elements.
5721
c906108c 5722@item set print null-stop
4644b6e3 5723@cindex @sc{null} elements in arrays
c906108c 5724Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5725@sc{null} is encountered. This is useful when large arrays actually
c906108c 5726contain only short strings.
d4f3574e 5727The default is off.
c906108c 5728
9c16f35a
EZ
5729@item show print null-stop
5730Show whether @value{GDBN} stops printing an array on the first
5731@sc{null} character.
5732
c906108c 5733@item set print pretty on
9c16f35a
EZ
5734@cindex print structures in indented form
5735@cindex indentation in structure display
5d161b24 5736Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5737per line, like this:
5738
5739@smallexample
5740@group
5741$1 = @{
5742 next = 0x0,
5743 flags = @{
5744 sweet = 1,
5745 sour = 1
5746 @},
5747 meat = 0x54 "Pork"
5748@}
5749@end group
5750@end smallexample
5751
5752@item set print pretty off
5753Cause @value{GDBN} to print structures in a compact format, like this:
5754
5755@smallexample
5756@group
5757$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5758meat = 0x54 "Pork"@}
5759@end group
5760@end smallexample
5761
5762@noindent
5763This is the default format.
5764
c906108c
SS
5765@item show print pretty
5766Show which format @value{GDBN} is using to print structures.
5767
c906108c 5768@item set print sevenbit-strings on
4644b6e3
EZ
5769@cindex eight-bit characters in strings
5770@cindex octal escapes in strings
c906108c
SS
5771Print using only seven-bit characters; if this option is set,
5772@value{GDBN} displays any eight-bit characters (in strings or
5773character values) using the notation @code{\}@var{nnn}. This setting is
5774best if you are working in English (@sc{ascii}) and you use the
5775high-order bit of characters as a marker or ``meta'' bit.
5776
5777@item set print sevenbit-strings off
5778Print full eight-bit characters. This allows the use of more
5779international character sets, and is the default.
5780
c906108c
SS
5781@item show print sevenbit-strings
5782Show whether or not @value{GDBN} is printing only seven-bit characters.
5783
c906108c 5784@item set print union on
4644b6e3 5785@cindex unions in structures, printing
9c16f35a
EZ
5786Tell @value{GDBN} to print unions which are contained in structures
5787and other unions. This is the default setting.
c906108c
SS
5788
5789@item set print union off
9c16f35a
EZ
5790Tell @value{GDBN} not to print unions which are contained in
5791structures and other unions. @value{GDBN} will print @code{"@{...@}"}
5792instead.
c906108c 5793
c906108c
SS
5794@item show print union
5795Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 5796structures and other unions.
c906108c
SS
5797
5798For example, given the declarations
5799
5800@smallexample
5801typedef enum @{Tree, Bug@} Species;
5802typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5803typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5804 Bug_forms;
5805
5806struct thing @{
5807 Species it;
5808 union @{
5809 Tree_forms tree;
5810 Bug_forms bug;
5811 @} form;
5812@};
5813
5814struct thing foo = @{Tree, @{Acorn@}@};
5815@end smallexample
5816
5817@noindent
5818with @code{set print union on} in effect @samp{p foo} would print
5819
5820@smallexample
5821$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5822@end smallexample
5823
5824@noindent
5825and with @code{set print union off} in effect it would print
5826
5827@smallexample
5828$1 = @{it = Tree, form = @{...@}@}
5829@end smallexample
9c16f35a
EZ
5830
5831@noindent
5832@code{set print union} affects programs written in C-like languages
5833and in Pascal.
c906108c
SS
5834@end table
5835
c906108c
SS
5836@need 1000
5837@noindent
b37052ae 5838These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5839
5840@table @code
4644b6e3 5841@cindex demangling C@t{++} names
c906108c
SS
5842@item set print demangle
5843@itemx set print demangle on
b37052ae 5844Print C@t{++} names in their source form rather than in the encoded
c906108c 5845(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5846linkage. The default is on.
c906108c 5847
c906108c 5848@item show print demangle
b37052ae 5849Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 5850
c906108c
SS
5851@item set print asm-demangle
5852@itemx set print asm-demangle on
b37052ae 5853Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5854in assembler code printouts such as instruction disassemblies.
5855The default is off.
5856
c906108c 5857@item show print asm-demangle
b37052ae 5858Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5859or demangled form.
5860
b37052ae
EZ
5861@cindex C@t{++} symbol decoding style
5862@cindex symbol decoding style, C@t{++}
a8f24a35 5863@kindex set demangle-style
c906108c
SS
5864@item set demangle-style @var{style}
5865Choose among several encoding schemes used by different compilers to
b37052ae 5866represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5867
5868@table @code
5869@item auto
5870Allow @value{GDBN} to choose a decoding style by inspecting your program.
5871
5872@item gnu
b37052ae 5873Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5874This is the default.
c906108c
SS
5875
5876@item hp
b37052ae 5877Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5878
5879@item lucid
b37052ae 5880Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5881
5882@item arm
b37052ae 5883Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5884@strong{Warning:} this setting alone is not sufficient to allow
5885debugging @code{cfront}-generated executables. @value{GDBN} would
5886require further enhancement to permit that.
5887
5888@end table
5889If you omit @var{style}, you will see a list of possible formats.
5890
c906108c 5891@item show demangle-style
b37052ae 5892Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 5893
c906108c
SS
5894@item set print object
5895@itemx set print object on
4644b6e3 5896@cindex derived type of an object, printing
9c16f35a 5897@cindex display derived types
c906108c
SS
5898When displaying a pointer to an object, identify the @emph{actual}
5899(derived) type of the object rather than the @emph{declared} type, using
5900the virtual function table.
5901
5902@item set print object off
5903Display only the declared type of objects, without reference to the
5904virtual function table. This is the default setting.
5905
c906108c
SS
5906@item show print object
5907Show whether actual, or declared, object types are displayed.
5908
c906108c
SS
5909@item set print static-members
5910@itemx set print static-members on
4644b6e3 5911@cindex static members of C@t{++} objects
b37052ae 5912Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5913
5914@item set print static-members off
b37052ae 5915Do not print static members when displaying a C@t{++} object.
c906108c 5916
c906108c 5917@item show print static-members
9c16f35a
EZ
5918Show whether C@t{++} static members are printed or not.
5919
5920@item set print pascal_static-members
5921@itemx set print pascal_static-members on
5922@cindex static members of Pacal objects
5923@cindex Pacal objects, static members display
5924Print static members when displaying a Pascal object. The default is on.
5925
5926@item set print pascal_static-members off
5927Do not print static members when displaying a Pascal object.
5928
5929@item show print pascal_static-members
5930Show whether Pascal static members are printed or not.
c906108c
SS
5931
5932@c These don't work with HP ANSI C++ yet.
c906108c
SS
5933@item set print vtbl
5934@itemx set print vtbl on
4644b6e3 5935@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
5936@cindex virtual functions (C@t{++}) display
5937@cindex VTBL display
b37052ae 5938Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5939(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5940ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5941
5942@item set print vtbl off
b37052ae 5943Do not pretty print C@t{++} virtual function tables.
c906108c 5944
c906108c 5945@item show print vtbl
b37052ae 5946Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5947@end table
c906108c 5948
6d2ebf8b 5949@node Value History
c906108c
SS
5950@section Value history
5951
5952@cindex value history
9c16f35a 5953@cindex history of values printed by @value{GDBN}
5d161b24
DB
5954Values printed by the @code{print} command are saved in the @value{GDBN}
5955@dfn{value history}. This allows you to refer to them in other expressions.
5956Values are kept until the symbol table is re-read or discarded
5957(for example with the @code{file} or @code{symbol-file} commands).
5958When the symbol table changes, the value history is discarded,
5959since the values may contain pointers back to the types defined in the
c906108c
SS
5960symbol table.
5961
5962@cindex @code{$}
5963@cindex @code{$$}
5964@cindex history number
5965The values printed are given @dfn{history numbers} by which you can
5966refer to them. These are successive integers starting with one.
5967@code{print} shows you the history number assigned to a value by
5968printing @samp{$@var{num} = } before the value; here @var{num} is the
5969history number.
5970
5971To refer to any previous value, use @samp{$} followed by the value's
5972history number. The way @code{print} labels its output is designed to
5973remind you of this. Just @code{$} refers to the most recent value in
5974the history, and @code{$$} refers to the value before that.
5975@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5976is the value just prior to @code{$$}, @code{$$1} is equivalent to
5977@code{$$}, and @code{$$0} is equivalent to @code{$}.
5978
5979For example, suppose you have just printed a pointer to a structure and
5980want to see the contents of the structure. It suffices to type
5981
474c8240 5982@smallexample
c906108c 5983p *$
474c8240 5984@end smallexample
c906108c
SS
5985
5986If you have a chain of structures where the component @code{next} points
5987to the next one, you can print the contents of the next one with this:
5988
474c8240 5989@smallexample
c906108c 5990p *$.next
474c8240 5991@end smallexample
c906108c
SS
5992
5993@noindent
5994You can print successive links in the chain by repeating this
5995command---which you can do by just typing @key{RET}.
5996
5997Note that the history records values, not expressions. If the value of
5998@code{x} is 4 and you type these commands:
5999
474c8240 6000@smallexample
c906108c
SS
6001print x
6002set x=5
474c8240 6003@end smallexample
c906108c
SS
6004
6005@noindent
6006then the value recorded in the value history by the @code{print} command
6007remains 4 even though the value of @code{x} has changed.
6008
6009@table @code
6010@kindex show values
6011@item show values
6012Print the last ten values in the value history, with their item numbers.
6013This is like @samp{p@ $$9} repeated ten times, except that @code{show
6014values} does not change the history.
6015
6016@item show values @var{n}
6017Print ten history values centered on history item number @var{n}.
6018
6019@item show values +
6020Print ten history values just after the values last printed. If no more
6021values are available, @code{show values +} produces no display.
6022@end table
6023
6024Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
6025same effect as @samp{show values +}.
6026
6d2ebf8b 6027@node Convenience Vars
c906108c
SS
6028@section Convenience variables
6029
6030@cindex convenience variables
9c16f35a 6031@cindex user-defined variables
c906108c
SS
6032@value{GDBN} provides @dfn{convenience variables} that you can use within
6033@value{GDBN} to hold on to a value and refer to it later. These variables
6034exist entirely within @value{GDBN}; they are not part of your program, and
6035setting a convenience variable has no direct effect on further execution
6036of your program. That is why you can use them freely.
6037
6038Convenience variables are prefixed with @samp{$}. Any name preceded by
6039@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 6040the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
6041(Value history references, in contrast, are @emph{numbers} preceded
6042by @samp{$}. @xref{Value History, ,Value history}.)
6043
6044You can save a value in a convenience variable with an assignment
6045expression, just as you would set a variable in your program.
6046For example:
6047
474c8240 6048@smallexample
c906108c 6049set $foo = *object_ptr
474c8240 6050@end smallexample
c906108c
SS
6051
6052@noindent
6053would save in @code{$foo} the value contained in the object pointed to by
6054@code{object_ptr}.
6055
6056Using a convenience variable for the first time creates it, but its
6057value is @code{void} until you assign a new value. You can alter the
6058value with another assignment at any time.
6059
6060Convenience variables have no fixed types. You can assign a convenience
6061variable any type of value, including structures and arrays, even if
6062that variable already has a value of a different type. The convenience
6063variable, when used as an expression, has the type of its current value.
6064
6065@table @code
6066@kindex show convenience
9c16f35a 6067@cindex show all user variables
c906108c
SS
6068@item show convenience
6069Print a list of convenience variables used so far, and their values.
d4f3574e 6070Abbreviated @code{show conv}.
c906108c
SS
6071@end table
6072
6073One of the ways to use a convenience variable is as a counter to be
6074incremented or a pointer to be advanced. For example, to print
6075a field from successive elements of an array of structures:
6076
474c8240 6077@smallexample
c906108c
SS
6078set $i = 0
6079print bar[$i++]->contents
474c8240 6080@end smallexample
c906108c 6081
d4f3574e
SS
6082@noindent
6083Repeat that command by typing @key{RET}.
c906108c
SS
6084
6085Some convenience variables are created automatically by @value{GDBN} and given
6086values likely to be useful.
6087
6088@table @code
41afff9a 6089@vindex $_@r{, convenience variable}
c906108c
SS
6090@item $_
6091The variable @code{$_} is automatically set by the @code{x} command to
6092the last address examined (@pxref{Memory, ,Examining memory}). Other
6093commands which provide a default address for @code{x} to examine also
6094set @code{$_} to that address; these commands include @code{info line}
6095and @code{info breakpoint}. The type of @code{$_} is @code{void *}
6096except when set by the @code{x} command, in which case it is a pointer
6097to the type of @code{$__}.
6098
41afff9a 6099@vindex $__@r{, convenience variable}
c906108c
SS
6100@item $__
6101The variable @code{$__} is automatically set by the @code{x} command
6102to the value found in the last address examined. Its type is chosen
6103to match the format in which the data was printed.
6104
6105@item $_exitcode
41afff9a 6106@vindex $_exitcode@r{, convenience variable}
c906108c
SS
6107The variable @code{$_exitcode} is automatically set to the exit code when
6108the program being debugged terminates.
6109@end table
6110
53a5351d
JM
6111On HP-UX systems, if you refer to a function or variable name that
6112begins with a dollar sign, @value{GDBN} searches for a user or system
6113name first, before it searches for a convenience variable.
c906108c 6114
6d2ebf8b 6115@node Registers
c906108c
SS
6116@section Registers
6117
6118@cindex registers
6119You can refer to machine register contents, in expressions, as variables
6120with names starting with @samp{$}. The names of registers are different
6121for each machine; use @code{info registers} to see the names used on
6122your machine.
6123
6124@table @code
6125@kindex info registers
6126@item info registers
6127Print the names and values of all registers except floating-point
c85508ee 6128and vector registers (in the selected stack frame).
c906108c
SS
6129
6130@kindex info all-registers
6131@cindex floating point registers
6132@item info all-registers
6133Print the names and values of all registers, including floating-point
c85508ee 6134and vector registers (in the selected stack frame).
c906108c
SS
6135
6136@item info registers @var{regname} @dots{}
6137Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
6138As discussed in detail below, register values are normally relative to
6139the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
6140the machine you are using, with or without the initial @samp{$}.
6141@end table
6142
e09f16f9
EZ
6143@cindex stack pointer register
6144@cindex program counter register
6145@cindex process status register
6146@cindex frame pointer register
6147@cindex standard registers
c906108c
SS
6148@value{GDBN} has four ``standard'' register names that are available (in
6149expressions) on most machines---whenever they do not conflict with an
6150architecture's canonical mnemonics for registers. The register names
6151@code{$pc} and @code{$sp} are used for the program counter register and
6152the stack pointer. @code{$fp} is used for a register that contains a
6153pointer to the current stack frame, and @code{$ps} is used for a
6154register that contains the processor status. For example,
6155you could print the program counter in hex with
6156
474c8240 6157@smallexample
c906108c 6158p/x $pc
474c8240 6159@end smallexample
c906108c
SS
6160
6161@noindent
6162or print the instruction to be executed next with
6163
474c8240 6164@smallexample
c906108c 6165x/i $pc
474c8240 6166@end smallexample
c906108c
SS
6167
6168@noindent
6169or add four to the stack pointer@footnote{This is a way of removing
6170one word from the stack, on machines where stacks grow downward in
6171memory (most machines, nowadays). This assumes that the innermost
6172stack frame is selected; setting @code{$sp} is not allowed when other
6173stack frames are selected. To pop entire frames off the stack,
6174regardless of machine architecture, use @code{return};
d4f3574e 6175see @ref{Returning, ,Returning from a function}.} with
c906108c 6176
474c8240 6177@smallexample
c906108c 6178set $sp += 4
474c8240 6179@end smallexample
c906108c
SS
6180
6181Whenever possible, these four standard register names are available on
6182your machine even though the machine has different canonical mnemonics,
6183so long as there is no conflict. The @code{info registers} command
6184shows the canonical names. For example, on the SPARC, @code{info
6185registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
6186can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6187is an alias for the @sc{eflags} register.
c906108c
SS
6188
6189@value{GDBN} always considers the contents of an ordinary register as an
6190integer when the register is examined in this way. Some machines have
6191special registers which can hold nothing but floating point; these
6192registers are considered to have floating point values. There is no way
6193to refer to the contents of an ordinary register as floating point value
6194(although you can @emph{print} it as a floating point value with
6195@samp{print/f $@var{regname}}).
6196
6197Some registers have distinct ``raw'' and ``virtual'' data formats. This
6198means that the data format in which the register contents are saved by
6199the operating system is not the same one that your program normally
6200sees. For example, the registers of the 68881 floating point
6201coprocessor are always saved in ``extended'' (raw) format, but all C
6202programs expect to work with ``double'' (virtual) format. In such
5d161b24 6203cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
6204that makes sense for your program), but the @code{info registers} command
6205prints the data in both formats.
6206
6207Normally, register values are relative to the selected stack frame
6208(@pxref{Selection, ,Selecting a frame}). This means that you get the
6209value that the register would contain if all stack frames farther in
6210were exited and their saved registers restored. In order to see the
6211true contents of hardware registers, you must select the innermost
6212frame (with @samp{frame 0}).
6213
6214However, @value{GDBN} must deduce where registers are saved, from the machine
6215code generated by your compiler. If some registers are not saved, or if
6216@value{GDBN} is unable to locate the saved registers, the selected stack
6217frame makes no difference.
6218
6d2ebf8b 6219@node Floating Point Hardware
c906108c
SS
6220@section Floating point hardware
6221@cindex floating point
6222
6223Depending on the configuration, @value{GDBN} may be able to give
6224you more information about the status of the floating point hardware.
6225
6226@table @code
6227@kindex info float
6228@item info float
6229Display hardware-dependent information about the floating
6230point unit. The exact contents and layout vary depending on the
6231floating point chip. Currently, @samp{info float} is supported on
6232the ARM and x86 machines.
6233@end table
c906108c 6234
e76f1f2e
AC
6235@node Vector Unit
6236@section Vector Unit
6237@cindex vector unit
6238
6239Depending on the configuration, @value{GDBN} may be able to give you
6240more information about the status of the vector unit.
6241
6242@table @code
6243@kindex info vector
6244@item info vector
6245Display information about the vector unit. The exact contents and
6246layout vary depending on the hardware.
6247@end table
6248
721c2651
EZ
6249@node OS Information
6250@section Operating system auxiliary information
6251@cindex OS information
6252
6253@value{GDBN} provides interfaces to useful OS facilities that can help
6254you debug your program.
6255
6256@cindex @code{ptrace} system call
6257@cindex @code{struct user} contents
6258When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6259machines), it interfaces with the inferior via the @code{ptrace}
6260system call. The operating system creates a special sata structure,
6261called @code{struct user}, for this interface. You can use the
6262command @code{info udot} to display the contents of this data
6263structure.
6264
6265@table @code
6266@item info udot
6267@kindex info udot
6268Display the contents of the @code{struct user} maintained by the OS
6269kernel for the program being debugged. @value{GDBN} displays the
6270contents of @code{struct user} as a list of hex numbers, similar to
6271the @code{examine} command.
6272@end table
6273
b383017d
RM
6274@cindex auxiliary vector
6275@cindex vector, auxiliary
b383017d
RM
6276Some operating systems supply an @dfn{auxiliary vector} to programs at
6277startup. This is akin to the arguments and environment that you
6278specify for a program, but contains a system-dependent variety of
6279binary values that tell system libraries important details about the
6280hardware, operating system, and process. Each value's purpose is
6281identified by an integer tag; the meanings are well-known but system-specific.
6282Depending on the configuration and operating system facilities,
9c16f35a
EZ
6283@value{GDBN} may be able to show you this information. For remote
6284targets, this functionality may further depend on the remote stub's
6285support of the @samp{qPart:auxv:read} packet, see @ref{Remote
6286configuration, auxiliary vector}.
b383017d
RM
6287
6288@table @code
6289@kindex info auxv
6290@item info auxv
6291Display the auxiliary vector of the inferior, which can be either a
e4937fc1 6292live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
6293numerically, and also shows names and text descriptions for recognized
6294tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 6295pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
6296most appropriate form for a recognized tag, and in hexadecimal for
6297an unrecognized tag.
6298@end table
6299
721c2651 6300
29e57380 6301@node Memory Region Attributes
b383017d 6302@section Memory region attributes
29e57380
C
6303@cindex memory region attributes
6304
b383017d
RM
6305@dfn{Memory region attributes} allow you to describe special handling
6306required by regions of your target's memory. @value{GDBN} uses attributes
29e57380
C
6307to determine whether to allow certain types of memory accesses; whether to
6308use specific width accesses; and whether to cache target memory.
6309
6310Defined memory regions can be individually enabled and disabled. When a
6311memory region is disabled, @value{GDBN} uses the default attributes when
6312accessing memory in that region. Similarly, if no memory regions have
6313been defined, @value{GDBN} uses the default attributes when accessing
6314all memory.
6315
b383017d 6316When a memory region is defined, it is given a number to identify it;
29e57380
C
6317to enable, disable, or remove a memory region, you specify that number.
6318
6319@table @code
6320@kindex mem
bfac230e 6321@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
6322Define a memory region bounded by @var{lower} and @var{upper} with
6323attributes @var{attributes}@dots{}, and add it to the list of regions
6324monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
6325case: it is treated as the the target's maximum memory address.
bfac230e 6326(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
6327
6328@kindex delete mem
6329@item delete mem @var{nums}@dots{}
09d4efe1
EZ
6330Remove memory regions @var{nums}@dots{} from the list of regions
6331monitored by @value{GDBN}.
29e57380
C
6332
6333@kindex disable mem
6334@item disable mem @var{nums}@dots{}
09d4efe1 6335Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 6336A disabled memory region is not forgotten.
29e57380
C
6337It may be enabled again later.
6338
6339@kindex enable mem
6340@item enable mem @var{nums}@dots{}
09d4efe1 6341Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
6342
6343@kindex info mem
6344@item info mem
6345Print a table of all defined memory regions, with the following columns
09d4efe1 6346for each region:
29e57380
C
6347
6348@table @emph
6349@item Memory Region Number
6350@item Enabled or Disabled.
b383017d 6351Enabled memory regions are marked with @samp{y}.
29e57380
C
6352Disabled memory regions are marked with @samp{n}.
6353
6354@item Lo Address
6355The address defining the inclusive lower bound of the memory region.
6356
6357@item Hi Address
6358The address defining the exclusive upper bound of the memory region.
6359
6360@item Attributes
6361The list of attributes set for this memory region.
6362@end table
6363@end table
6364
6365
6366@subsection Attributes
6367
b383017d 6368@subsubsection Memory Access Mode
29e57380
C
6369The access mode attributes set whether @value{GDBN} may make read or
6370write accesses to a memory region.
6371
6372While these attributes prevent @value{GDBN} from performing invalid
6373memory accesses, they do nothing to prevent the target system, I/O DMA,
6374etc. from accessing memory.
6375
6376@table @code
6377@item ro
6378Memory is read only.
6379@item wo
6380Memory is write only.
6381@item rw
6ca652b0 6382Memory is read/write. This is the default.
29e57380
C
6383@end table
6384
6385@subsubsection Memory Access Size
6386The acccess size attributes tells @value{GDBN} to use specific sized
6387accesses in the memory region. Often memory mapped device registers
6388require specific sized accesses. If no access size attribute is
6389specified, @value{GDBN} may use accesses of any size.
6390
6391@table @code
6392@item 8
6393Use 8 bit memory accesses.
6394@item 16
6395Use 16 bit memory accesses.
6396@item 32
6397Use 32 bit memory accesses.
6398@item 64
6399Use 64 bit memory accesses.
6400@end table
6401
6402@c @subsubsection Hardware/Software Breakpoints
6403@c The hardware/software breakpoint attributes set whether @value{GDBN}
6404@c will use hardware or software breakpoints for the internal breakpoints
6405@c used by the step, next, finish, until, etc. commands.
6406@c
6407@c @table @code
6408@c @item hwbreak
b383017d 6409@c Always use hardware breakpoints
29e57380
C
6410@c @item swbreak (default)
6411@c @end table
6412
6413@subsubsection Data Cache
6414The data cache attributes set whether @value{GDBN} will cache target
6415memory. While this generally improves performance by reducing debug
6416protocol overhead, it can lead to incorrect results because @value{GDBN}
6417does not know about volatile variables or memory mapped device
6418registers.
6419
6420@table @code
6421@item cache
b383017d 6422Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6423@item nocache
6424Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6425@end table
6426
6427@c @subsubsection Memory Write Verification
b383017d 6428@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6429@c will re-reads data after each write to verify the write was successful.
6430@c
6431@c @table @code
6432@c @item verify
6433@c @item noverify (default)
6434@c @end table
6435
16d9dec6
MS
6436@node Dump/Restore Files
6437@section Copy between memory and a file
6438@cindex dump/restore files
6439@cindex append data to a file
6440@cindex dump data to a file
6441@cindex restore data from a file
16d9dec6 6442
df5215a6
JB
6443You can use the commands @code{dump}, @code{append}, and
6444@code{restore} to copy data between target memory and a file. The
6445@code{dump} and @code{append} commands write data to a file, and the
6446@code{restore} command reads data from a file back into the inferior's
6447memory. Files may be in binary, Motorola S-record, Intel hex, or
6448Tektronix Hex format; however, @value{GDBN} can only append to binary
6449files.
6450
6451@table @code
6452
6453@kindex dump
6454@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6455@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6456Dump the contents of memory from @var{start_addr} to @var{end_addr},
6457or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6458
df5215a6 6459The @var{format} parameter may be any one of:
16d9dec6 6460@table @code
df5215a6
JB
6461@item binary
6462Raw binary form.
6463@item ihex
6464Intel hex format.
6465@item srec
6466Motorola S-record format.
6467@item tekhex
6468Tektronix Hex format.
6469@end table
6470
6471@value{GDBN} uses the same definitions of these formats as the
6472@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6473@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6474form.
6475
6476@kindex append
6477@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6478@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6479Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 6480or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
6481(@value{GDBN} can only append data to files in raw binary form.)
6482
6483@kindex restore
6484@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6485Restore the contents of file @var{filename} into memory. The
6486@code{restore} command can automatically recognize any known @sc{bfd}
6487file format, except for raw binary. To restore a raw binary file you
6488must specify the optional keyword @code{binary} after the filename.
16d9dec6 6489
b383017d 6490If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6491contained in the file. Binary files always start at address zero, so
6492they will be restored at address @var{bias}. Other bfd files have
6493a built-in location; they will be restored at offset @var{bias}
6494from that location.
6495
6496If @var{start} and/or @var{end} are non-zero, then only data between
6497file offset @var{start} and file offset @var{end} will be restored.
b383017d 6498These offsets are relative to the addresses in the file, before
16d9dec6
MS
6499the @var{bias} argument is applied.
6500
6501@end table
6502
384ee23f
EZ
6503@node Core File Generation
6504@section How to Produce a Core File from Your Program
6505@cindex dump core from inferior
6506
6507A @dfn{core file} or @dfn{core dump} is a file that records the memory
6508image of a running process and its process status (register values
6509etc.). Its primary use is post-mortem debugging of a program that
6510crashed while it ran outside a debugger. A program that crashes
6511automatically produces a core file, unless this feature is disabled by
6512the user. @xref{Files}, for information on invoking @value{GDBN} in
6513the post-mortem debugging mode.
6514
6515Occasionally, you may wish to produce a core file of the program you
6516are debugging in order to preserve a snapshot of its state.
6517@value{GDBN} has a special command for that.
6518
6519@table @code
6520@kindex gcore
6521@kindex generate-core-file
6522@item generate-core-file [@var{file}]
6523@itemx gcore [@var{file}]
6524Produce a core dump of the inferior process. The optional argument
6525@var{file} specifies the file name where to put the core dump. If not
6526specified, the file name defaults to @file{core.@var{pid}}, where
6527@var{pid} is the inferior process ID.
6528
6529Note that this command is implemented only for some systems (as of
6530this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6531@end table
6532
a0eb71c5
KB
6533@node Character Sets
6534@section Character Sets
6535@cindex character sets
6536@cindex charset
6537@cindex translating between character sets
6538@cindex host character set
6539@cindex target character set
6540
6541If the program you are debugging uses a different character set to
6542represent characters and strings than the one @value{GDBN} uses itself,
6543@value{GDBN} can automatically translate between the character sets for
6544you. The character set @value{GDBN} uses we call the @dfn{host
6545character set}; the one the inferior program uses we call the
6546@dfn{target character set}.
6547
6548For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6549uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6550remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6551running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6552then the host character set is Latin-1, and the target character set is
6553@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6554target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6555@sc{ebcdic} and Latin 1 as you print character or string values, or use
6556character and string literals in expressions.
6557
6558@value{GDBN} has no way to automatically recognize which character set
6559the inferior program uses; you must tell it, using the @code{set
6560target-charset} command, described below.
6561
6562Here are the commands for controlling @value{GDBN}'s character set
6563support:
6564
6565@table @code
6566@item set target-charset @var{charset}
6567@kindex set target-charset
6568Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6569character set names @value{GDBN} recognizes below, but if you type
6570@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6571list the target character sets it supports.
a0eb71c5
KB
6572@end table
6573
6574@table @code
6575@item set host-charset @var{charset}
6576@kindex set host-charset
6577Set the current host character set to @var{charset}.
6578
6579By default, @value{GDBN} uses a host character set appropriate to the
6580system it is running on; you can override that default using the
6581@code{set host-charset} command.
6582
6583@value{GDBN} can only use certain character sets as its host character
6584set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6585indicate which can be host character sets, but if you type
6586@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6587list the host character sets it supports.
a0eb71c5
KB
6588
6589@item set charset @var{charset}
6590@kindex set charset
e33d66ec
EZ
6591Set the current host and target character sets to @var{charset}. As
6592above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6593@value{GDBN} will list the name of the character sets that can be used
6594for both host and target.
6595
a0eb71c5
KB
6596
6597@item show charset
a0eb71c5 6598@kindex show charset
b383017d 6599Show the names of the current host and target charsets.
e33d66ec
EZ
6600
6601@itemx show host-charset
a0eb71c5 6602@kindex show host-charset
b383017d 6603Show the name of the current host charset.
e33d66ec
EZ
6604
6605@itemx show target-charset
a0eb71c5 6606@kindex show target-charset
b383017d 6607Show the name of the current target charset.
a0eb71c5
KB
6608
6609@end table
6610
6611@value{GDBN} currently includes support for the following character
6612sets:
6613
6614@table @code
6615
6616@item ASCII
6617@cindex ASCII character set
6618Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6619character set.
6620
6621@item ISO-8859-1
6622@cindex ISO 8859-1 character set
6623@cindex ISO Latin 1 character set
e33d66ec 6624The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6625characters needed for French, German, and Spanish. @value{GDBN} can use
6626this as its host character set.
6627
6628@item EBCDIC-US
6629@itemx IBM1047
6630@cindex EBCDIC character set
6631@cindex IBM1047 character set
6632Variants of the @sc{ebcdic} character set, used on some of IBM's
6633mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6634@value{GDBN} cannot use these as its host character set.
6635
6636@end table
6637
6638Note that these are all single-byte character sets. More work inside
6639GDB is needed to support multi-byte or variable-width character
6640encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6641
6642Here is an example of @value{GDBN}'s character set support in action.
6643Assume that the following source code has been placed in the file
6644@file{charset-test.c}:
6645
6646@smallexample
6647#include <stdio.h>
6648
6649char ascii_hello[]
6650 = @{72, 101, 108, 108, 111, 44, 32, 119,
6651 111, 114, 108, 100, 33, 10, 0@};
6652char ibm1047_hello[]
6653 = @{200, 133, 147, 147, 150, 107, 64, 166,
6654 150, 153, 147, 132, 90, 37, 0@};
6655
6656main ()
6657@{
6658 printf ("Hello, world!\n");
6659@}
10998722 6660@end smallexample
a0eb71c5
KB
6661
6662In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6663containing the string @samp{Hello, world!} followed by a newline,
6664encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6665
6666We compile the program, and invoke the debugger on it:
6667
6668@smallexample
6669$ gcc -g charset-test.c -o charset-test
6670$ gdb -nw charset-test
6671GNU gdb 2001-12-19-cvs
6672Copyright 2001 Free Software Foundation, Inc.
6673@dots{}
f7dc1244 6674(@value{GDBP})
10998722 6675@end smallexample
a0eb71c5
KB
6676
6677We can use the @code{show charset} command to see what character sets
6678@value{GDBN} is currently using to interpret and display characters and
6679strings:
6680
6681@smallexample
f7dc1244 6682(@value{GDBP}) show charset
e33d66ec 6683The current host and target character set is `ISO-8859-1'.
f7dc1244 6684(@value{GDBP})
10998722 6685@end smallexample
a0eb71c5
KB
6686
6687For the sake of printing this manual, let's use @sc{ascii} as our
6688initial character set:
6689@smallexample
f7dc1244
EZ
6690(@value{GDBP}) set charset ASCII
6691(@value{GDBP}) show charset
e33d66ec 6692The current host and target character set is `ASCII'.
f7dc1244 6693(@value{GDBP})
10998722 6694@end smallexample
a0eb71c5
KB
6695
6696Let's assume that @sc{ascii} is indeed the correct character set for our
6697host system --- in other words, let's assume that if @value{GDBN} prints
6698characters using the @sc{ascii} character set, our terminal will display
6699them properly. Since our current target character set is also
6700@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6701
6702@smallexample
f7dc1244 6703(@value{GDBP}) print ascii_hello
a0eb71c5 6704$1 = 0x401698 "Hello, world!\n"
f7dc1244 6705(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6706$2 = 72 'H'
f7dc1244 6707(@value{GDBP})
10998722 6708@end smallexample
a0eb71c5
KB
6709
6710@value{GDBN} uses the target character set for character and string
6711literals you use in expressions:
6712
6713@smallexample
f7dc1244 6714(@value{GDBP}) print '+'
a0eb71c5 6715$3 = 43 '+'
f7dc1244 6716(@value{GDBP})
10998722 6717@end smallexample
a0eb71c5
KB
6718
6719The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6720character.
6721
6722@value{GDBN} relies on the user to tell it which character set the
6723target program uses. If we print @code{ibm1047_hello} while our target
6724character set is still @sc{ascii}, we get jibberish:
6725
6726@smallexample
f7dc1244 6727(@value{GDBP}) print ibm1047_hello
a0eb71c5 6728$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 6729(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6730$5 = 200 '\310'
f7dc1244 6731(@value{GDBP})
10998722 6732@end smallexample
a0eb71c5 6733
e33d66ec 6734If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6735@value{GDBN} tells us the character sets it supports:
6736
6737@smallexample
f7dc1244 6738(@value{GDBP}) set target-charset
b383017d 6739ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 6740(@value{GDBP}) set target-charset
10998722 6741@end smallexample
a0eb71c5
KB
6742
6743We can select @sc{ibm1047} as our target character set, and examine the
6744program's strings again. Now the @sc{ascii} string is wrong, but
6745@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6746target character set, @sc{ibm1047}, to the host character set,
6747@sc{ascii}, and they display correctly:
6748
6749@smallexample
f7dc1244
EZ
6750(@value{GDBP}) set target-charset IBM1047
6751(@value{GDBP}) show charset
e33d66ec
EZ
6752The current host character set is `ASCII'.
6753The current target character set is `IBM1047'.
f7dc1244 6754(@value{GDBP}) print ascii_hello
a0eb71c5 6755$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 6756(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6757$7 = 72 '\110'
f7dc1244 6758(@value{GDBP}) print ibm1047_hello
a0eb71c5 6759$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 6760(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6761$9 = 200 'H'
f7dc1244 6762(@value{GDBP})
10998722 6763@end smallexample
a0eb71c5
KB
6764
6765As above, @value{GDBN} uses the target character set for character and
6766string literals you use in expressions:
6767
6768@smallexample
f7dc1244 6769(@value{GDBP}) print '+'
a0eb71c5 6770$10 = 78 '+'
f7dc1244 6771(@value{GDBP})
10998722 6772@end smallexample
a0eb71c5 6773
e33d66ec 6774The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6775character.
6776
09d4efe1
EZ
6777@node Caching Remote Data
6778@section Caching Data of Remote Targets
6779@cindex caching data of remote targets
6780
6781@value{GDBN} can cache data exchanged between the debugger and a
6782remote target (@pxref{Remote}). Such caching generally improves
6783performance, because it reduces the overhead of the remote protocol by
6784bundling memory reads and writes into large chunks. Unfortunately,
6785@value{GDBN} does not currently know anything about volatile
6786registers, and thus data caching will produce incorrect results when
6787volatile registers are in use.
6788
6789@table @code
6790@kindex set remotecache
6791@item set remotecache on
6792@itemx set remotecache off
6793Set caching state for remote targets. When @code{ON}, use data
6794caching. By default, this option is @code{OFF}.
6795
6796@kindex show remotecache
6797@item show remotecache
6798Show the current state of data caching for remote targets.
6799
6800@kindex info dcache
6801@item info dcache
6802Print the information about the data cache performance. The
6803information displayed includes: the dcache width and depth; and for
6804each cache line, how many times it was referenced, and its data and
6805state (dirty, bad, ok, etc.). This command is useful for debugging
6806the data cache operation.
6807@end table
6808
a0eb71c5 6809
e2e0bcd1
JB
6810@node Macros
6811@chapter C Preprocessor Macros
6812
49efadf5 6813Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
6814``preprocessor macros'' which expand into strings of tokens.
6815@value{GDBN} can evaluate expressions containing macro invocations, show
6816the result of macro expansion, and show a macro's definition, including
6817where it was defined.
6818
6819You may need to compile your program specially to provide @value{GDBN}
6820with information about preprocessor macros. Most compilers do not
6821include macros in their debugging information, even when you compile
6822with the @option{-g} flag. @xref{Compilation}.
6823
6824A program may define a macro at one point, remove that definition later,
6825and then provide a different definition after that. Thus, at different
6826points in the program, a macro may have different definitions, or have
6827no definition at all. If there is a current stack frame, @value{GDBN}
6828uses the macros in scope at that frame's source code line. Otherwise,
6829@value{GDBN} uses the macros in scope at the current listing location;
6830see @ref{List}.
6831
6832At the moment, @value{GDBN} does not support the @code{##}
6833token-splicing operator, the @code{#} stringification operator, or
6834variable-arity macros.
6835
6836Whenever @value{GDBN} evaluates an expression, it always expands any
6837macro invocations present in the expression. @value{GDBN} also provides
6838the following commands for working with macros explicitly.
6839
6840@table @code
6841
6842@kindex macro expand
6843@cindex macro expansion, showing the results of preprocessor
6844@cindex preprocessor macro expansion, showing the results of
6845@cindex expanding preprocessor macros
6846@item macro expand @var{expression}
6847@itemx macro exp @var{expression}
6848Show the results of expanding all preprocessor macro invocations in
6849@var{expression}. Since @value{GDBN} simply expands macros, but does
6850not parse the result, @var{expression} need not be a valid expression;
6851it can be any string of tokens.
6852
09d4efe1 6853@kindex macro exp1
e2e0bcd1
JB
6854@item macro expand-once @var{expression}
6855@itemx macro exp1 @var{expression}
4644b6e3 6856@cindex expand macro once
e2e0bcd1
JB
6857@i{(This command is not yet implemented.)} Show the results of
6858expanding those preprocessor macro invocations that appear explicitly in
6859@var{expression}. Macro invocations appearing in that expansion are
6860left unchanged. This command allows you to see the effect of a
6861particular macro more clearly, without being confused by further
6862expansions. Since @value{GDBN} simply expands macros, but does not
6863parse the result, @var{expression} need not be a valid expression; it
6864can be any string of tokens.
6865
475b0867 6866@kindex info macro
e2e0bcd1
JB
6867@cindex macro definition, showing
6868@cindex definition, showing a macro's
475b0867 6869@item info macro @var{macro}
e2e0bcd1
JB
6870Show the definition of the macro named @var{macro}, and describe the
6871source location where that definition was established.
6872
6873@kindex macro define
6874@cindex user-defined macros
6875@cindex defining macros interactively
6876@cindex macros, user-defined
6877@item macro define @var{macro} @var{replacement-list}
6878@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6879@i{(This command is not yet implemented.)} Introduce a definition for a
6880preprocessor macro named @var{macro}, invocations of which are replaced
6881by the tokens given in @var{replacement-list}. The first form of this
6882command defines an ``object-like'' macro, which takes no arguments; the
6883second form defines a ``function-like'' macro, which takes the arguments
6884given in @var{arglist}.
6885
6886A definition introduced by this command is in scope in every expression
6887evaluated in @value{GDBN}, until it is removed with the @command{macro
6888undef} command, described below. The definition overrides all
6889definitions for @var{macro} present in the program being debugged, as
6890well as any previous user-supplied definition.
6891
6892@kindex macro undef
6893@item macro undef @var{macro}
6894@i{(This command is not yet implemented.)} Remove any user-supplied
6895definition for the macro named @var{macro}. This command only affects
6896definitions provided with the @command{macro define} command, described
6897above; it cannot remove definitions present in the program being
6898debugged.
6899
09d4efe1
EZ
6900@kindex macro list
6901@item macro list
6902@i{(This command is not yet implemented.)} List all the macros
6903defined using the @code{macro define} command.
e2e0bcd1
JB
6904@end table
6905
6906@cindex macros, example of debugging with
6907Here is a transcript showing the above commands in action. First, we
6908show our source files:
6909
6910@smallexample
6911$ cat sample.c
6912#include <stdio.h>
6913#include "sample.h"
6914
6915#define M 42
6916#define ADD(x) (M + x)
6917
6918main ()
6919@{
6920#define N 28
6921 printf ("Hello, world!\n");
6922#undef N
6923 printf ("We're so creative.\n");
6924#define N 1729
6925 printf ("Goodbye, world!\n");
6926@}
6927$ cat sample.h
6928#define Q <
6929$
6930@end smallexample
6931
6932Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6933We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6934compiler includes information about preprocessor macros in the debugging
6935information.
6936
6937@smallexample
6938$ gcc -gdwarf-2 -g3 sample.c -o sample
6939$
6940@end smallexample
6941
6942Now, we start @value{GDBN} on our sample program:
6943
6944@smallexample
6945$ gdb -nw sample
6946GNU gdb 2002-05-06-cvs
6947Copyright 2002 Free Software Foundation, Inc.
6948GDB is free software, @dots{}
f7dc1244 6949(@value{GDBP})
e2e0bcd1
JB
6950@end smallexample
6951
6952We can expand macros and examine their definitions, even when the
6953program is not running. @value{GDBN} uses the current listing position
6954to decide which macro definitions are in scope:
6955
6956@smallexample
f7dc1244 6957(@value{GDBP}) list main
e2e0bcd1
JB
69583
69594 #define M 42
69605 #define ADD(x) (M + x)
69616
69627 main ()
69638 @{
69649 #define N 28
696510 printf ("Hello, world!\n");
696611 #undef N
696712 printf ("We're so creative.\n");
f7dc1244 6968(@value{GDBP}) info macro ADD
e2e0bcd1
JB
6969Defined at /home/jimb/gdb/macros/play/sample.c:5
6970#define ADD(x) (M + x)
f7dc1244 6971(@value{GDBP}) info macro Q
e2e0bcd1
JB
6972Defined at /home/jimb/gdb/macros/play/sample.h:1
6973 included at /home/jimb/gdb/macros/play/sample.c:2
6974#define Q <
f7dc1244 6975(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 6976expands to: (42 + 1)
f7dc1244 6977(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 6978expands to: once (M + 1)
f7dc1244 6979(@value{GDBP})
e2e0bcd1
JB
6980@end smallexample
6981
6982In the example above, note that @command{macro expand-once} expands only
6983the macro invocation explicit in the original text --- the invocation of
6984@code{ADD} --- but does not expand the invocation of the macro @code{M},
6985which was introduced by @code{ADD}.
6986
6987Once the program is running, GDB uses the macro definitions in force at
6988the source line of the current stack frame:
6989
6990@smallexample
f7dc1244 6991(@value{GDBP}) break main
e2e0bcd1 6992Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 6993(@value{GDBP}) run
b383017d 6994Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
6995
6996Breakpoint 1, main () at sample.c:10
699710 printf ("Hello, world!\n");
f7dc1244 6998(@value{GDBP})
e2e0bcd1
JB
6999@end smallexample
7000
7001At line 10, the definition of the macro @code{N} at line 9 is in force:
7002
7003@smallexample
f7dc1244 7004(@value{GDBP}) info macro N
e2e0bcd1
JB
7005Defined at /home/jimb/gdb/macros/play/sample.c:9
7006#define N 28
f7dc1244 7007(@value{GDBP}) macro expand N Q M
e2e0bcd1 7008expands to: 28 < 42
f7dc1244 7009(@value{GDBP}) print N Q M
e2e0bcd1 7010$1 = 1
f7dc1244 7011(@value{GDBP})
e2e0bcd1
JB
7012@end smallexample
7013
7014As we step over directives that remove @code{N}'s definition, and then
7015give it a new definition, @value{GDBN} finds the definition (or lack
7016thereof) in force at each point:
7017
7018@smallexample
f7dc1244 7019(@value{GDBP}) next
e2e0bcd1
JB
7020Hello, world!
702112 printf ("We're so creative.\n");
f7dc1244 7022(@value{GDBP}) info macro N
e2e0bcd1
JB
7023The symbol `N' has no definition as a C/C++ preprocessor macro
7024at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 7025(@value{GDBP}) next
e2e0bcd1
JB
7026We're so creative.
702714 printf ("Goodbye, world!\n");
f7dc1244 7028(@value{GDBP}) info macro N
e2e0bcd1
JB
7029Defined at /home/jimb/gdb/macros/play/sample.c:13
7030#define N 1729
f7dc1244 7031(@value{GDBP}) macro expand N Q M
e2e0bcd1 7032expands to: 1729 < 42
f7dc1244 7033(@value{GDBP}) print N Q M
e2e0bcd1 7034$2 = 0
f7dc1244 7035(@value{GDBP})
e2e0bcd1
JB
7036@end smallexample
7037
7038
b37052ae
EZ
7039@node Tracepoints
7040@chapter Tracepoints
7041@c This chapter is based on the documentation written by Michael
7042@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
7043
7044@cindex tracepoints
7045In some applications, it is not feasible for the debugger to interrupt
7046the program's execution long enough for the developer to learn
7047anything helpful about its behavior. If the program's correctness
7048depends on its real-time behavior, delays introduced by a debugger
7049might cause the program to change its behavior drastically, or perhaps
7050fail, even when the code itself is correct. It is useful to be able
7051to observe the program's behavior without interrupting it.
7052
7053Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
7054specify locations in the program, called @dfn{tracepoints}, and
7055arbitrary expressions to evaluate when those tracepoints are reached.
7056Later, using the @code{tfind} command, you can examine the values
7057those expressions had when the program hit the tracepoints. The
7058expressions may also denote objects in memory---structures or arrays,
7059for example---whose values @value{GDBN} should record; while visiting
7060a particular tracepoint, you may inspect those objects as if they were
7061in memory at that moment. However, because @value{GDBN} records these
7062values without interacting with you, it can do so quickly and
7063unobtrusively, hopefully not disturbing the program's behavior.
7064
7065The tracepoint facility is currently available only for remote
2c0069bb
EZ
7066targets. @xref{Targets}. In addition, your remote target must know how
7067to collect trace data. This functionality is implemented in the remote
7068stub; however, none of the stubs distributed with @value{GDBN} support
7069tracepoints as of this writing.
b37052ae
EZ
7070
7071This chapter describes the tracepoint commands and features.
7072
7073@menu
b383017d
RM
7074* Set Tracepoints::
7075* Analyze Collected Data::
7076* Tracepoint Variables::
b37052ae
EZ
7077@end menu
7078
7079@node Set Tracepoints
7080@section Commands to Set Tracepoints
7081
7082Before running such a @dfn{trace experiment}, an arbitrary number of
7083tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
7084tracepoint has a number assigned to it by @value{GDBN}. Like with
7085breakpoints, tracepoint numbers are successive integers starting from
7086one. Many of the commands associated with tracepoints take the
7087tracepoint number as their argument, to identify which tracepoint to
7088work on.
7089
7090For each tracepoint, you can specify, in advance, some arbitrary set
7091of data that you want the target to collect in the trace buffer when
7092it hits that tracepoint. The collected data can include registers,
7093local variables, or global data. Later, you can use @value{GDBN}
7094commands to examine the values these data had at the time the
7095tracepoint was hit.
7096
7097This section describes commands to set tracepoints and associated
7098conditions and actions.
7099
7100@menu
b383017d
RM
7101* Create and Delete Tracepoints::
7102* Enable and Disable Tracepoints::
7103* Tracepoint Passcounts::
7104* Tracepoint Actions::
7105* Listing Tracepoints::
7106* Starting and Stopping Trace Experiment::
b37052ae
EZ
7107@end menu
7108
7109@node Create and Delete Tracepoints
7110@subsection Create and Delete Tracepoints
7111
7112@table @code
7113@cindex set tracepoint
7114@kindex trace
7115@item trace
7116The @code{trace} command is very similar to the @code{break} command.
7117Its argument can be a source line, a function name, or an address in
7118the target program. @xref{Set Breaks}. The @code{trace} command
7119defines a tracepoint, which is a point in the target program where the
7120debugger will briefly stop, collect some data, and then allow the
7121program to continue. Setting a tracepoint or changing its commands
7122doesn't take effect until the next @code{tstart} command; thus, you
7123cannot change the tracepoint attributes once a trace experiment is
7124running.
7125
7126Here are some examples of using the @code{trace} command:
7127
7128@smallexample
7129(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
7130
7131(@value{GDBP}) @b{trace +2} // 2 lines forward
7132
7133(@value{GDBP}) @b{trace my_function} // first source line of function
7134
7135(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
7136
7137(@value{GDBP}) @b{trace *0x2117c4} // an address
7138@end smallexample
7139
7140@noindent
7141You can abbreviate @code{trace} as @code{tr}.
7142
7143@vindex $tpnum
7144@cindex last tracepoint number
7145@cindex recent tracepoint number
7146@cindex tracepoint number
7147The convenience variable @code{$tpnum} records the tracepoint number
7148of the most recently set tracepoint.
7149
7150@kindex delete tracepoint
7151@cindex tracepoint deletion
7152@item delete tracepoint @r{[}@var{num}@r{]}
7153Permanently delete one or more tracepoints. With no argument, the
7154default is to delete all tracepoints.
7155
7156Examples:
7157
7158@smallexample
7159(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7160
7161(@value{GDBP}) @b{delete trace} // remove all tracepoints
7162@end smallexample
7163
7164@noindent
7165You can abbreviate this command as @code{del tr}.
7166@end table
7167
7168@node Enable and Disable Tracepoints
7169@subsection Enable and Disable Tracepoints
7170
7171@table @code
7172@kindex disable tracepoint
7173@item disable tracepoint @r{[}@var{num}@r{]}
7174Disable tracepoint @var{num}, or all tracepoints if no argument
7175@var{num} is given. A disabled tracepoint will have no effect during
7176the next trace experiment, but it is not forgotten. You can re-enable
7177a disabled tracepoint using the @code{enable tracepoint} command.
7178
7179@kindex enable tracepoint
7180@item enable tracepoint @r{[}@var{num}@r{]}
7181Enable tracepoint @var{num}, or all tracepoints. The enabled
7182tracepoints will become effective the next time a trace experiment is
7183run.
7184@end table
7185
7186@node Tracepoint Passcounts
7187@subsection Tracepoint Passcounts
7188
7189@table @code
7190@kindex passcount
7191@cindex tracepoint pass count
7192@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7193Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7194automatically stop a trace experiment. If a tracepoint's passcount is
7195@var{n}, then the trace experiment will be automatically stopped on
7196the @var{n}'th time that tracepoint is hit. If the tracepoint number
7197@var{num} is not specified, the @code{passcount} command sets the
7198passcount of the most recently defined tracepoint. If no passcount is
7199given, the trace experiment will run until stopped explicitly by the
7200user.
7201
7202Examples:
7203
7204@smallexample
b383017d 7205(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 7206@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
7207
7208(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 7209@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
7210(@value{GDBP}) @b{trace foo}
7211(@value{GDBP}) @b{pass 3}
7212(@value{GDBP}) @b{trace bar}
7213(@value{GDBP}) @b{pass 2}
7214(@value{GDBP}) @b{trace baz}
7215(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
7216@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7217@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7218@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
7219@end smallexample
7220@end table
7221
7222@node Tracepoint Actions
7223@subsection Tracepoint Action Lists
7224
7225@table @code
7226@kindex actions
7227@cindex tracepoint actions
7228@item actions @r{[}@var{num}@r{]}
7229This command will prompt for a list of actions to be taken when the
7230tracepoint is hit. If the tracepoint number @var{num} is not
7231specified, this command sets the actions for the one that was most
7232recently defined (so that you can define a tracepoint and then say
7233@code{actions} without bothering about its number). You specify the
7234actions themselves on the following lines, one action at a time, and
7235terminate the actions list with a line containing just @code{end}. So
7236far, the only defined actions are @code{collect} and
7237@code{while-stepping}.
7238
7239@cindex remove actions from a tracepoint
7240To remove all actions from a tracepoint, type @samp{actions @var{num}}
7241and follow it immediately with @samp{end}.
7242
7243@smallexample
7244(@value{GDBP}) @b{collect @var{data}} // collect some data
7245
6826cf00 7246(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 7247
6826cf00 7248(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
7249@end smallexample
7250
7251In the following example, the action list begins with @code{collect}
7252commands indicating the things to be collected when the tracepoint is
7253hit. Then, in order to single-step and collect additional data
7254following the tracepoint, a @code{while-stepping} command is used,
7255followed by the list of things to be collected while stepping. The
7256@code{while-stepping} command is terminated by its own separate
7257@code{end} command. Lastly, the action list is terminated by an
7258@code{end} command.
7259
7260@smallexample
7261(@value{GDBP}) @b{trace foo}
7262(@value{GDBP}) @b{actions}
7263Enter actions for tracepoint 1, one per line:
7264> collect bar,baz
7265> collect $regs
7266> while-stepping 12
7267 > collect $fp, $sp
7268 > end
7269end
7270@end smallexample
7271
7272@kindex collect @r{(tracepoints)}
7273@item collect @var{expr1}, @var{expr2}, @dots{}
7274Collect values of the given expressions when the tracepoint is hit.
7275This command accepts a comma-separated list of any valid expressions.
7276In addition to global, static, or local variables, the following
7277special arguments are supported:
7278
7279@table @code
7280@item $regs
7281collect all registers
7282
7283@item $args
7284collect all function arguments
7285
7286@item $locals
7287collect all local variables.
7288@end table
7289
7290You can give several consecutive @code{collect} commands, each one
7291with a single argument, or one @code{collect} command with several
7292arguments separated by commas: the effect is the same.
7293
f5c37c66
EZ
7294The command @code{info scope} (@pxref{Symbols, info scope}) is
7295particularly useful for figuring out what data to collect.
7296
b37052ae
EZ
7297@kindex while-stepping @r{(tracepoints)}
7298@item while-stepping @var{n}
7299Perform @var{n} single-step traces after the tracepoint, collecting
7300new data at each step. The @code{while-stepping} command is
7301followed by the list of what to collect while stepping (followed by
7302its own @code{end} command):
7303
7304@smallexample
7305> while-stepping 12
7306 > collect $regs, myglobal
7307 > end
7308>
7309@end smallexample
7310
7311@noindent
7312You may abbreviate @code{while-stepping} as @code{ws} or
7313@code{stepping}.
7314@end table
7315
7316@node Listing Tracepoints
7317@subsection Listing Tracepoints
7318
7319@table @code
7320@kindex info tracepoints
09d4efe1 7321@kindex info tp
b37052ae
EZ
7322@cindex information about tracepoints
7323@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 7324Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 7325a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
7326defined so far. For each tracepoint, the following information is
7327shown:
7328
7329@itemize @bullet
7330@item
7331its number
7332@item
7333whether it is enabled or disabled
7334@item
7335its address
7336@item
7337its passcount as given by the @code{passcount @var{n}} command
7338@item
7339its step count as given by the @code{while-stepping @var{n}} command
7340@item
7341where in the source files is the tracepoint set
7342@item
7343its action list as given by the @code{actions} command
7344@end itemize
7345
7346@smallexample
7347(@value{GDBP}) @b{info trace}
7348Num Enb Address PassC StepC What
73491 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
73502 y 0x0020dc64 0 0 in g_test at g_test.c:1375
73513 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
7352(@value{GDBP})
7353@end smallexample
7354
7355@noindent
7356This command can be abbreviated @code{info tp}.
7357@end table
7358
7359@node Starting and Stopping Trace Experiment
7360@subsection Starting and Stopping Trace Experiment
7361
7362@table @code
7363@kindex tstart
7364@cindex start a new trace experiment
7365@cindex collected data discarded
7366@item tstart
7367This command takes no arguments. It starts the trace experiment, and
7368begins collecting data. This has the side effect of discarding all
7369the data collected in the trace buffer during the previous trace
7370experiment.
7371
7372@kindex tstop
7373@cindex stop a running trace experiment
7374@item tstop
7375This command takes no arguments. It ends the trace experiment, and
7376stops collecting data.
7377
68c71a2e 7378@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
7379automatically if any tracepoint's passcount is reached
7380(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7381
7382@kindex tstatus
7383@cindex status of trace data collection
7384@cindex trace experiment, status of
7385@item tstatus
7386This command displays the status of the current trace data
7387collection.
7388@end table
7389
7390Here is an example of the commands we described so far:
7391
7392@smallexample
7393(@value{GDBP}) @b{trace gdb_c_test}
7394(@value{GDBP}) @b{actions}
7395Enter actions for tracepoint #1, one per line.
7396> collect $regs,$locals,$args
7397> while-stepping 11
7398 > collect $regs
7399 > end
7400> end
7401(@value{GDBP}) @b{tstart}
7402 [time passes @dots{}]
7403(@value{GDBP}) @b{tstop}
7404@end smallexample
7405
7406
7407@node Analyze Collected Data
7408@section Using the collected data
7409
7410After the tracepoint experiment ends, you use @value{GDBN} commands
7411for examining the trace data. The basic idea is that each tracepoint
7412collects a trace @dfn{snapshot} every time it is hit and another
7413snapshot every time it single-steps. All these snapshots are
7414consecutively numbered from zero and go into a buffer, and you can
7415examine them later. The way you examine them is to @dfn{focus} on a
7416specific trace snapshot. When the remote stub is focused on a trace
7417snapshot, it will respond to all @value{GDBN} requests for memory and
7418registers by reading from the buffer which belongs to that snapshot,
7419rather than from @emph{real} memory or registers of the program being
7420debugged. This means that @strong{all} @value{GDBN} commands
7421(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7422behave as if we were currently debugging the program state as it was
7423when the tracepoint occurred. Any requests for data that are not in
7424the buffer will fail.
7425
7426@menu
7427* tfind:: How to select a trace snapshot
7428* tdump:: How to display all data for a snapshot
7429* save-tracepoints:: How to save tracepoints for a future run
7430@end menu
7431
7432@node tfind
7433@subsection @code{tfind @var{n}}
7434
7435@kindex tfind
7436@cindex select trace snapshot
7437@cindex find trace snapshot
7438The basic command for selecting a trace snapshot from the buffer is
7439@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7440counting from zero. If no argument @var{n} is given, the next
7441snapshot is selected.
7442
7443Here are the various forms of using the @code{tfind} command.
7444
7445@table @code
7446@item tfind start
7447Find the first snapshot in the buffer. This is a synonym for
7448@code{tfind 0} (since 0 is the number of the first snapshot).
7449
7450@item tfind none
7451Stop debugging trace snapshots, resume @emph{live} debugging.
7452
7453@item tfind end
7454Same as @samp{tfind none}.
7455
7456@item tfind
7457No argument means find the next trace snapshot.
7458
7459@item tfind -
7460Find the previous trace snapshot before the current one. This permits
7461retracing earlier steps.
7462
7463@item tfind tracepoint @var{num}
7464Find the next snapshot associated with tracepoint @var{num}. Search
7465proceeds forward from the last examined trace snapshot. If no
7466argument @var{num} is given, it means find the next snapshot collected
7467for the same tracepoint as the current snapshot.
7468
7469@item tfind pc @var{addr}
7470Find the next snapshot associated with the value @var{addr} of the
7471program counter. Search proceeds forward from the last examined trace
7472snapshot. If no argument @var{addr} is given, it means find the next
7473snapshot with the same value of PC as the current snapshot.
7474
7475@item tfind outside @var{addr1}, @var{addr2}
7476Find the next snapshot whose PC is outside the given range of
7477addresses.
7478
7479@item tfind range @var{addr1}, @var{addr2}
7480Find the next snapshot whose PC is between @var{addr1} and
7481@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7482
7483@item tfind line @r{[}@var{file}:@r{]}@var{n}
7484Find the next snapshot associated with the source line @var{n}. If
7485the optional argument @var{file} is given, refer to line @var{n} in
7486that source file. Search proceeds forward from the last examined
7487trace snapshot. If no argument @var{n} is given, it means find the
7488next line other than the one currently being examined; thus saying
7489@code{tfind line} repeatedly can appear to have the same effect as
7490stepping from line to line in a @emph{live} debugging session.
7491@end table
7492
7493The default arguments for the @code{tfind} commands are specifically
7494designed to make it easy to scan through the trace buffer. For
7495instance, @code{tfind} with no argument selects the next trace
7496snapshot, and @code{tfind -} with no argument selects the previous
7497trace snapshot. So, by giving one @code{tfind} command, and then
7498simply hitting @key{RET} repeatedly you can examine all the trace
7499snapshots in order. Or, by saying @code{tfind -} and then hitting
7500@key{RET} repeatedly you can examine the snapshots in reverse order.
7501The @code{tfind line} command with no argument selects the snapshot
7502for the next source line executed. The @code{tfind pc} command with
7503no argument selects the next snapshot with the same program counter
7504(PC) as the current frame. The @code{tfind tracepoint} command with
7505no argument selects the next trace snapshot collected by the same
7506tracepoint as the current one.
7507
7508In addition to letting you scan through the trace buffer manually,
7509these commands make it easy to construct @value{GDBN} scripts that
7510scan through the trace buffer and print out whatever collected data
7511you are interested in. Thus, if we want to examine the PC, FP, and SP
7512registers from each trace frame in the buffer, we can say this:
7513
7514@smallexample
7515(@value{GDBP}) @b{tfind start}
7516(@value{GDBP}) @b{while ($trace_frame != -1)}
7517> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7518 $trace_frame, $pc, $sp, $fp
7519> tfind
7520> end
7521
7522Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7523Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7524Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7525Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7526Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7527Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7528Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7529Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7530Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7531Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7532Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7533@end smallexample
7534
7535Or, if we want to examine the variable @code{X} at each source line in
7536the buffer:
7537
7538@smallexample
7539(@value{GDBP}) @b{tfind start}
7540(@value{GDBP}) @b{while ($trace_frame != -1)}
7541> printf "Frame %d, X == %d\n", $trace_frame, X
7542> tfind line
7543> end
7544
7545Frame 0, X = 1
7546Frame 7, X = 2
7547Frame 13, X = 255
7548@end smallexample
7549
7550@node tdump
7551@subsection @code{tdump}
7552@kindex tdump
7553@cindex dump all data collected at tracepoint
7554@cindex tracepoint data, display
7555
7556This command takes no arguments. It prints all the data collected at
7557the current trace snapshot.
7558
7559@smallexample
7560(@value{GDBP}) @b{trace 444}
7561(@value{GDBP}) @b{actions}
7562Enter actions for tracepoint #2, one per line:
7563> collect $regs, $locals, $args, gdb_long_test
7564> end
7565
7566(@value{GDBP}) @b{tstart}
7567
7568(@value{GDBP}) @b{tfind line 444}
7569#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7570at gdb_test.c:444
7571444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7572
7573(@value{GDBP}) @b{tdump}
7574Data collected at tracepoint 2, trace frame 1:
7575d0 0xc4aa0085 -995491707
7576d1 0x18 24
7577d2 0x80 128
7578d3 0x33 51
7579d4 0x71aea3d 119204413
7580d5 0x22 34
7581d6 0xe0 224
7582d7 0x380035 3670069
7583a0 0x19e24a 1696330
7584a1 0x3000668 50333288
7585a2 0x100 256
7586a3 0x322000 3284992
7587a4 0x3000698 50333336
7588a5 0x1ad3cc 1758156
7589fp 0x30bf3c 0x30bf3c
7590sp 0x30bf34 0x30bf34
7591ps 0x0 0
7592pc 0x20b2c8 0x20b2c8
7593fpcontrol 0x0 0
7594fpstatus 0x0 0
7595fpiaddr 0x0 0
7596p = 0x20e5b4 "gdb-test"
7597p1 = (void *) 0x11
7598p2 = (void *) 0x22
7599p3 = (void *) 0x33
7600p4 = (void *) 0x44
7601p5 = (void *) 0x55
7602p6 = (void *) 0x66
7603gdb_long_test = 17 '\021'
7604
7605(@value{GDBP})
7606@end smallexample
7607
7608@node save-tracepoints
7609@subsection @code{save-tracepoints @var{filename}}
7610@kindex save-tracepoints
7611@cindex save tracepoints for future sessions
7612
7613This command saves all current tracepoint definitions together with
7614their actions and passcounts, into a file @file{@var{filename}}
7615suitable for use in a later debugging session. To read the saved
7616tracepoint definitions, use the @code{source} command (@pxref{Command
7617Files}).
7618
7619@node Tracepoint Variables
7620@section Convenience Variables for Tracepoints
7621@cindex tracepoint variables
7622@cindex convenience variables for tracepoints
7623
7624@table @code
7625@vindex $trace_frame
7626@item (int) $trace_frame
7627The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7628snapshot is selected.
7629
7630@vindex $tracepoint
7631@item (int) $tracepoint
7632The tracepoint for the current trace snapshot.
7633
7634@vindex $trace_line
7635@item (int) $trace_line
7636The line number for the current trace snapshot.
7637
7638@vindex $trace_file
7639@item (char []) $trace_file
7640The source file for the current trace snapshot.
7641
7642@vindex $trace_func
7643@item (char []) $trace_func
7644The name of the function containing @code{$tracepoint}.
7645@end table
7646
7647Note: @code{$trace_file} is not suitable for use in @code{printf},
7648use @code{output} instead.
7649
7650Here's a simple example of using these convenience variables for
7651stepping through all the trace snapshots and printing some of their
7652data.
7653
7654@smallexample
7655(@value{GDBP}) @b{tfind start}
7656
7657(@value{GDBP}) @b{while $trace_frame != -1}
7658> output $trace_file
7659> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7660> tfind
7661> end
7662@end smallexample
7663
df0cd8c5
JB
7664@node Overlays
7665@chapter Debugging Programs That Use Overlays
7666@cindex overlays
7667
7668If your program is too large to fit completely in your target system's
7669memory, you can sometimes use @dfn{overlays} to work around this
7670problem. @value{GDBN} provides some support for debugging programs that
7671use overlays.
7672
7673@menu
7674* How Overlays Work:: A general explanation of overlays.
7675* Overlay Commands:: Managing overlays in @value{GDBN}.
7676* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7677 mapped by asking the inferior.
7678* Overlay Sample Program:: A sample program using overlays.
7679@end menu
7680
7681@node How Overlays Work
7682@section How Overlays Work
7683@cindex mapped overlays
7684@cindex unmapped overlays
7685@cindex load address, overlay's
7686@cindex mapped address
7687@cindex overlay area
7688
7689Suppose you have a computer whose instruction address space is only 64
7690kilobytes long, but which has much more memory which can be accessed by
7691other means: special instructions, segment registers, or memory
7692management hardware, for example. Suppose further that you want to
7693adapt a program which is larger than 64 kilobytes to run on this system.
7694
7695One solution is to identify modules of your program which are relatively
7696independent, and need not call each other directly; call these modules
7697@dfn{overlays}. Separate the overlays from the main program, and place
7698their machine code in the larger memory. Place your main program in
7699instruction memory, but leave at least enough space there to hold the
7700largest overlay as well.
7701
7702Now, to call a function located in an overlay, you must first copy that
7703overlay's machine code from the large memory into the space set aside
7704for it in the instruction memory, and then jump to its entry point
7705there.
7706
c928edc0
AC
7707@c NB: In the below the mapped area's size is greater or equal to the
7708@c size of all overlays. This is intentional to remind the developer
7709@c that overlays don't necessarily need to be the same size.
7710
474c8240 7711@smallexample
df0cd8c5 7712@group
c928edc0
AC
7713 Data Instruction Larger
7714Address Space Address Space Address Space
7715+-----------+ +-----------+ +-----------+
7716| | | | | |
7717+-----------+ +-----------+ +-----------+<-- overlay 1
7718| program | | main | .----| overlay 1 | load address
7719| variables | | program | | +-----------+
7720| and heap | | | | | |
7721+-----------+ | | | +-----------+<-- overlay 2
7722| | +-----------+ | | | load address
7723+-----------+ | | | .-| overlay 2 |
7724 | | | | | |
7725 mapped --->+-----------+ | | +-----------+
7726 address | | | | | |
7727 | overlay | <-' | | |
7728 | area | <---' +-----------+<-- overlay 3
7729 | | <---. | | load address
7730 +-----------+ `--| overlay 3 |
7731 | | | |
7732 +-----------+ | |
7733 +-----------+
7734 | |
7735 +-----------+
7736
7737 @anchor{A code overlay}A code overlay
df0cd8c5 7738@end group
474c8240 7739@end smallexample
df0cd8c5 7740
c928edc0
AC
7741The diagram (@pxref{A code overlay}) shows a system with separate data
7742and instruction address spaces. To map an overlay, the program copies
7743its code from the larger address space to the instruction address space.
7744Since the overlays shown here all use the same mapped address, only one
7745may be mapped at a time. For a system with a single address space for
7746data and instructions, the diagram would be similar, except that the
7747program variables and heap would share an address space with the main
7748program and the overlay area.
df0cd8c5
JB
7749
7750An overlay loaded into instruction memory and ready for use is called a
7751@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7752instruction memory. An overlay not present (or only partially present)
7753in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7754is its address in the larger memory. The mapped address is also called
7755the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7756called the @dfn{load memory address}, or @dfn{LMA}.
7757
7758Unfortunately, overlays are not a completely transparent way to adapt a
7759program to limited instruction memory. They introduce a new set of
7760global constraints you must keep in mind as you design your program:
7761
7762@itemize @bullet
7763
7764@item
7765Before calling or returning to a function in an overlay, your program
7766must make sure that overlay is actually mapped. Otherwise, the call or
7767return will transfer control to the right address, but in the wrong
7768overlay, and your program will probably crash.
7769
7770@item
7771If the process of mapping an overlay is expensive on your system, you
7772will need to choose your overlays carefully to minimize their effect on
7773your program's performance.
7774
7775@item
7776The executable file you load onto your system must contain each
7777overlay's instructions, appearing at the overlay's load address, not its
7778mapped address. However, each overlay's instructions must be relocated
7779and its symbols defined as if the overlay were at its mapped address.
7780You can use GNU linker scripts to specify different load and relocation
7781addresses for pieces of your program; see @ref{Overlay Description,,,
7782ld.info, Using ld: the GNU linker}.
7783
7784@item
7785The procedure for loading executable files onto your system must be able
7786to load their contents into the larger address space as well as the
7787instruction and data spaces.
7788
7789@end itemize
7790
7791The overlay system described above is rather simple, and could be
7792improved in many ways:
7793
7794@itemize @bullet
7795
7796@item
7797If your system has suitable bank switch registers or memory management
7798hardware, you could use those facilities to make an overlay's load area
7799contents simply appear at their mapped address in instruction space.
7800This would probably be faster than copying the overlay to its mapped
7801area in the usual way.
7802
7803@item
7804If your overlays are small enough, you could set aside more than one
7805overlay area, and have more than one overlay mapped at a time.
7806
7807@item
7808You can use overlays to manage data, as well as instructions. In
7809general, data overlays are even less transparent to your design than
7810code overlays: whereas code overlays only require care when you call or
7811return to functions, data overlays require care every time you access
7812the data. Also, if you change the contents of a data overlay, you
7813must copy its contents back out to its load address before you can copy a
7814different data overlay into the same mapped area.
7815
7816@end itemize
7817
7818
7819@node Overlay Commands
7820@section Overlay Commands
7821
7822To use @value{GDBN}'s overlay support, each overlay in your program must
7823correspond to a separate section of the executable file. The section's
7824virtual memory address and load memory address must be the overlay's
7825mapped and load addresses. Identifying overlays with sections allows
7826@value{GDBN} to determine the appropriate address of a function or
7827variable, depending on whether the overlay is mapped or not.
7828
7829@value{GDBN}'s overlay commands all start with the word @code{overlay};
7830you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7831
7832@table @code
7833@item overlay off
4644b6e3 7834@kindex overlay
df0cd8c5
JB
7835Disable @value{GDBN}'s overlay support. When overlay support is
7836disabled, @value{GDBN} assumes that all functions and variables are
7837always present at their mapped addresses. By default, @value{GDBN}'s
7838overlay support is disabled.
7839
7840@item overlay manual
df0cd8c5
JB
7841@cindex manual overlay debugging
7842Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7843relies on you to tell it which overlays are mapped, and which are not,
7844using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7845commands described below.
7846
7847@item overlay map-overlay @var{overlay}
7848@itemx overlay map @var{overlay}
df0cd8c5
JB
7849@cindex map an overlay
7850Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7851be the name of the object file section containing the overlay. When an
7852overlay is mapped, @value{GDBN} assumes it can find the overlay's
7853functions and variables at their mapped addresses. @value{GDBN} assumes
7854that any other overlays whose mapped ranges overlap that of
7855@var{overlay} are now unmapped.
7856
7857@item overlay unmap-overlay @var{overlay}
7858@itemx overlay unmap @var{overlay}
df0cd8c5
JB
7859@cindex unmap an overlay
7860Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7861must be the name of the object file section containing the overlay.
7862When an overlay is unmapped, @value{GDBN} assumes it can find the
7863overlay's functions and variables at their load addresses.
7864
7865@item overlay auto
df0cd8c5
JB
7866Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7867consults a data structure the overlay manager maintains in the inferior
7868to see which overlays are mapped. For details, see @ref{Automatic
7869Overlay Debugging}.
7870
7871@item overlay load-target
7872@itemx overlay load
df0cd8c5
JB
7873@cindex reloading the overlay table
7874Re-read the overlay table from the inferior. Normally, @value{GDBN}
7875re-reads the table @value{GDBN} automatically each time the inferior
7876stops, so this command should only be necessary if you have changed the
7877overlay mapping yourself using @value{GDBN}. This command is only
7878useful when using automatic overlay debugging.
7879
7880@item overlay list-overlays
7881@itemx overlay list
7882@cindex listing mapped overlays
7883Display a list of the overlays currently mapped, along with their mapped
7884addresses, load addresses, and sizes.
7885
7886@end table
7887
7888Normally, when @value{GDBN} prints a code address, it includes the name
7889of the function the address falls in:
7890
474c8240 7891@smallexample
f7dc1244 7892(@value{GDBP}) print main
df0cd8c5 7893$3 = @{int ()@} 0x11a0 <main>
474c8240 7894@end smallexample
df0cd8c5
JB
7895@noindent
7896When overlay debugging is enabled, @value{GDBN} recognizes code in
7897unmapped overlays, and prints the names of unmapped functions with
7898asterisks around them. For example, if @code{foo} is a function in an
7899unmapped overlay, @value{GDBN} prints it this way:
7900
474c8240 7901@smallexample
f7dc1244 7902(@value{GDBP}) overlay list
df0cd8c5 7903No sections are mapped.
f7dc1244 7904(@value{GDBP}) print foo
df0cd8c5 7905$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7906@end smallexample
df0cd8c5
JB
7907@noindent
7908When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7909name normally:
7910
474c8240 7911@smallexample
f7dc1244 7912(@value{GDBP}) overlay list
b383017d 7913Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 7914 mapped at 0x1016 - 0x104a
f7dc1244 7915(@value{GDBP}) print foo
df0cd8c5 7916$6 = @{int (int)@} 0x1016 <foo>
474c8240 7917@end smallexample
df0cd8c5
JB
7918
7919When overlay debugging is enabled, @value{GDBN} can find the correct
7920address for functions and variables in an overlay, whether or not the
7921overlay is mapped. This allows most @value{GDBN} commands, like
7922@code{break} and @code{disassemble}, to work normally, even on unmapped
7923code. However, @value{GDBN}'s breakpoint support has some limitations:
7924
7925@itemize @bullet
7926@item
7927@cindex breakpoints in overlays
7928@cindex overlays, setting breakpoints in
7929You can set breakpoints in functions in unmapped overlays, as long as
7930@value{GDBN} can write to the overlay at its load address.
7931@item
7932@value{GDBN} can not set hardware or simulator-based breakpoints in
7933unmapped overlays. However, if you set a breakpoint at the end of your
7934overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7935you are using manual overlay management), @value{GDBN} will re-set its
7936breakpoints properly.
7937@end itemize
7938
7939
7940@node Automatic Overlay Debugging
7941@section Automatic Overlay Debugging
7942@cindex automatic overlay debugging
7943
7944@value{GDBN} can automatically track which overlays are mapped and which
7945are not, given some simple co-operation from the overlay manager in the
7946inferior. If you enable automatic overlay debugging with the
7947@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7948looks in the inferior's memory for certain variables describing the
7949current state of the overlays.
7950
7951Here are the variables your overlay manager must define to support
7952@value{GDBN}'s automatic overlay debugging:
7953
7954@table @asis
7955
7956@item @code{_ovly_table}:
7957This variable must be an array of the following structures:
7958
474c8240 7959@smallexample
df0cd8c5
JB
7960struct
7961@{
7962 /* The overlay's mapped address. */
7963 unsigned long vma;
7964
7965 /* The size of the overlay, in bytes. */
7966 unsigned long size;
7967
7968 /* The overlay's load address. */
7969 unsigned long lma;
7970
7971 /* Non-zero if the overlay is currently mapped;
7972 zero otherwise. */
7973 unsigned long mapped;
7974@}
474c8240 7975@end smallexample
df0cd8c5
JB
7976
7977@item @code{_novlys}:
7978This variable must be a four-byte signed integer, holding the total
7979number of elements in @code{_ovly_table}.
7980
7981@end table
7982
7983To decide whether a particular overlay is mapped or not, @value{GDBN}
7984looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
7985@code{lma} members equal the VMA and LMA of the overlay's section in the
7986executable file. When @value{GDBN} finds a matching entry, it consults
7987the entry's @code{mapped} member to determine whether the overlay is
7988currently mapped.
7989
81d46470 7990In addition, your overlay manager may define a function called
def71bfa 7991@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
7992will silently set a breakpoint there. If the overlay manager then
7993calls this function whenever it has changed the overlay table, this
7994will enable @value{GDBN} to accurately keep track of which overlays
7995are in program memory, and update any breakpoints that may be set
b383017d 7996in overlays. This will allow breakpoints to work even if the
81d46470
MS
7997overlays are kept in ROM or other non-writable memory while they
7998are not being executed.
df0cd8c5
JB
7999
8000@node Overlay Sample Program
8001@section Overlay Sample Program
8002@cindex overlay example program
8003
8004When linking a program which uses overlays, you must place the overlays
8005at their load addresses, while relocating them to run at their mapped
8006addresses. To do this, you must write a linker script (@pxref{Overlay
8007Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
8008since linker scripts are specific to a particular host system, target
8009architecture, and target memory layout, this manual cannot provide
8010portable sample code demonstrating @value{GDBN}'s overlay support.
8011
8012However, the @value{GDBN} source distribution does contain an overlaid
8013program, with linker scripts for a few systems, as part of its test
8014suite. The program consists of the following files from
8015@file{gdb/testsuite/gdb.base}:
8016
8017@table @file
8018@item overlays.c
8019The main program file.
8020@item ovlymgr.c
8021A simple overlay manager, used by @file{overlays.c}.
8022@item foo.c
8023@itemx bar.c
8024@itemx baz.c
8025@itemx grbx.c
8026Overlay modules, loaded and used by @file{overlays.c}.
8027@item d10v.ld
8028@itemx m32r.ld
8029Linker scripts for linking the test program on the @code{d10v-elf}
8030and @code{m32r-elf} targets.
8031@end table
8032
8033You can build the test program using the @code{d10v-elf} GCC
8034cross-compiler like this:
8035
474c8240 8036@smallexample
df0cd8c5
JB
8037$ d10v-elf-gcc -g -c overlays.c
8038$ d10v-elf-gcc -g -c ovlymgr.c
8039$ d10v-elf-gcc -g -c foo.c
8040$ d10v-elf-gcc -g -c bar.c
8041$ d10v-elf-gcc -g -c baz.c
8042$ d10v-elf-gcc -g -c grbx.c
8043$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
8044 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 8045@end smallexample
df0cd8c5
JB
8046
8047The build process is identical for any other architecture, except that
8048you must substitute the appropriate compiler and linker script for the
8049target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
8050
8051
6d2ebf8b 8052@node Languages
c906108c
SS
8053@chapter Using @value{GDBN} with Different Languages
8054@cindex languages
8055
c906108c
SS
8056Although programming languages generally have common aspects, they are
8057rarely expressed in the same manner. For instance, in ANSI C,
8058dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
8059Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 8060represented (and displayed) differently. Hex numbers in C appear as
c906108c 8061@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
8062
8063@cindex working language
8064Language-specific information is built into @value{GDBN} for some languages,
8065allowing you to express operations like the above in your program's
8066native language, and allowing @value{GDBN} to output values in a manner
8067consistent with the syntax of your program's native language. The
8068language you use to build expressions is called the @dfn{working
8069language}.
8070
8071@menu
8072* Setting:: Switching between source languages
8073* Show:: Displaying the language
c906108c 8074* Checks:: Type and range checks
9c16f35a 8075* Supported languages:: Supported languages
4e562065 8076* Unsupported languages:: Unsupported languages
c906108c
SS
8077@end menu
8078
6d2ebf8b 8079@node Setting
c906108c
SS
8080@section Switching between source languages
8081
8082There are two ways to control the working language---either have @value{GDBN}
8083set it automatically, or select it manually yourself. You can use the
8084@code{set language} command for either purpose. On startup, @value{GDBN}
8085defaults to setting the language automatically. The working language is
8086used to determine how expressions you type are interpreted, how values
8087are printed, etc.
8088
8089In addition to the working language, every source file that
8090@value{GDBN} knows about has its own working language. For some object
8091file formats, the compiler might indicate which language a particular
8092source file is in. However, most of the time @value{GDBN} infers the
8093language from the name of the file. The language of a source file
b37052ae 8094controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 8095show each frame appropriately for its own language. There is no way to
d4f3574e
SS
8096set the language of a source file from within @value{GDBN}, but you can
8097set the language associated with a filename extension. @xref{Show, ,
8098Displaying the language}.
c906108c
SS
8099
8100This is most commonly a problem when you use a program, such
5d161b24 8101as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
8102another language. In that case, make the
8103program use @code{#line} directives in its C output; that way
8104@value{GDBN} will know the correct language of the source code of the original
8105program, and will display that source code, not the generated C code.
8106
8107@menu
8108* Filenames:: Filename extensions and languages.
8109* Manually:: Setting the working language manually
8110* Automatically:: Having @value{GDBN} infer the source language
8111@end menu
8112
6d2ebf8b 8113@node Filenames
c906108c
SS
8114@subsection List of filename extensions and languages
8115
8116If a source file name ends in one of the following extensions, then
8117@value{GDBN} infers that its language is the one indicated.
8118
8119@table @file
e07c999f
PH
8120@item .ada
8121@itemx .ads
8122@itemx .adb
8123@itemx .a
8124Ada source file.
c906108c
SS
8125
8126@item .c
8127C source file
8128
8129@item .C
8130@itemx .cc
8131@itemx .cp
8132@itemx .cpp
8133@itemx .cxx
8134@itemx .c++
b37052ae 8135C@t{++} source file
c906108c 8136
b37303ee
AF
8137@item .m
8138Objective-C source file
8139
c906108c
SS
8140@item .f
8141@itemx .F
8142Fortran source file
8143
c906108c
SS
8144@item .mod
8145Modula-2 source file
c906108c
SS
8146
8147@item .s
8148@itemx .S
8149Assembler source file. This actually behaves almost like C, but
8150@value{GDBN} does not skip over function prologues when stepping.
8151@end table
8152
8153In addition, you may set the language associated with a filename
8154extension. @xref{Show, , Displaying the language}.
8155
6d2ebf8b 8156@node Manually
c906108c
SS
8157@subsection Setting the working language
8158
8159If you allow @value{GDBN} to set the language automatically,
8160expressions are interpreted the same way in your debugging session and
8161your program.
8162
8163@kindex set language
8164If you wish, you may set the language manually. To do this, issue the
8165command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 8166a language, such as
c906108c 8167@code{c} or @code{modula-2}.
c906108c
SS
8168For a list of the supported languages, type @samp{set language}.
8169
c906108c
SS
8170Setting the language manually prevents @value{GDBN} from updating the working
8171language automatically. This can lead to confusion if you try
8172to debug a program when the working language is not the same as the
8173source language, when an expression is acceptable to both
8174languages---but means different things. For instance, if the current
8175source file were written in C, and @value{GDBN} was parsing Modula-2, a
8176command such as:
8177
474c8240 8178@smallexample
c906108c 8179print a = b + c
474c8240 8180@end smallexample
c906108c
SS
8181
8182@noindent
8183might not have the effect you intended. In C, this means to add
8184@code{b} and @code{c} and place the result in @code{a}. The result
8185printed would be the value of @code{a}. In Modula-2, this means to compare
8186@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 8187
6d2ebf8b 8188@node Automatically
c906108c
SS
8189@subsection Having @value{GDBN} infer the source language
8190
8191To have @value{GDBN} set the working language automatically, use
8192@samp{set language local} or @samp{set language auto}. @value{GDBN}
8193then infers the working language. That is, when your program stops in a
8194frame (usually by encountering a breakpoint), @value{GDBN} sets the
8195working language to the language recorded for the function in that
8196frame. If the language for a frame is unknown (that is, if the function
8197or block corresponding to the frame was defined in a source file that
8198does not have a recognized extension), the current working language is
8199not changed, and @value{GDBN} issues a warning.
8200
8201This may not seem necessary for most programs, which are written
8202entirely in one source language. However, program modules and libraries
8203written in one source language can be used by a main program written in
8204a different source language. Using @samp{set language auto} in this
8205case frees you from having to set the working language manually.
8206
6d2ebf8b 8207@node Show
c906108c 8208@section Displaying the language
c906108c
SS
8209
8210The following commands help you find out which language is the
8211working language, and also what language source files were written in.
8212
c906108c
SS
8213@table @code
8214@item show language
9c16f35a 8215@kindex show language
c906108c
SS
8216Display the current working language. This is the
8217language you can use with commands such as @code{print} to
8218build and compute expressions that may involve variables in your program.
8219
8220@item info frame
4644b6e3 8221@kindex info frame@r{, show the source language}
5d161b24 8222Display the source language for this frame. This language becomes the
c906108c 8223working language if you use an identifier from this frame.
5d161b24 8224@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
8225information listed here.
8226
8227@item info source
4644b6e3 8228@kindex info source@r{, show the source language}
c906108c 8229Display the source language of this source file.
5d161b24 8230@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
8231information listed here.
8232@end table
8233
8234In unusual circumstances, you may have source files with extensions
8235not in the standard list. You can then set the extension associated
8236with a language explicitly:
8237
c906108c 8238@table @code
09d4efe1 8239@item set extension-language @var{ext} @var{language}
9c16f35a 8240@kindex set extension-language
09d4efe1
EZ
8241Tell @value{GDBN} that source files with extension @var{ext} are to be
8242assumed as written in the source language @var{language}.
c906108c
SS
8243
8244@item info extensions
9c16f35a 8245@kindex info extensions
c906108c
SS
8246List all the filename extensions and the associated languages.
8247@end table
8248
6d2ebf8b 8249@node Checks
c906108c
SS
8250@section Type and range checking
8251
8252@quotation
8253@emph{Warning:} In this release, the @value{GDBN} commands for type and range
8254checking are included, but they do not yet have any effect. This
8255section documents the intended facilities.
8256@end quotation
8257@c FIXME remove warning when type/range code added
8258
8259Some languages are designed to guard you against making seemingly common
8260errors through a series of compile- and run-time checks. These include
8261checking the type of arguments to functions and operators, and making
8262sure mathematical overflows are caught at run time. Checks such as
8263these help to ensure a program's correctness once it has been compiled
8264by eliminating type mismatches, and providing active checks for range
8265errors when your program is running.
8266
8267@value{GDBN} can check for conditions like the above if you wish.
9c16f35a
EZ
8268Although @value{GDBN} does not check the statements in your program,
8269it can check expressions entered directly into @value{GDBN} for
8270evaluation via the @code{print} command, for example. As with the
8271working language, @value{GDBN} can also decide whether or not to check
8272automatically based on your program's source language.
8273@xref{Supported languages, ,Supported languages}, for the default
8274settings of supported languages.
c906108c
SS
8275
8276@menu
8277* Type Checking:: An overview of type checking
8278* Range Checking:: An overview of range checking
8279@end menu
8280
8281@cindex type checking
8282@cindex checks, type
6d2ebf8b 8283@node Type Checking
c906108c
SS
8284@subsection An overview of type checking
8285
8286Some languages, such as Modula-2, are strongly typed, meaning that the
8287arguments to operators and functions have to be of the correct type,
8288otherwise an error occurs. These checks prevent type mismatch
8289errors from ever causing any run-time problems. For example,
8290
8291@smallexample
82921 + 2 @result{} 3
8293@exdent but
8294@error{} 1 + 2.3
8295@end smallexample
8296
8297The second example fails because the @code{CARDINAL} 1 is not
8298type-compatible with the @code{REAL} 2.3.
8299
5d161b24
DB
8300For the expressions you use in @value{GDBN} commands, you can tell the
8301@value{GDBN} type checker to skip checking;
8302to treat any mismatches as errors and abandon the expression;
8303or to only issue warnings when type mismatches occur,
c906108c
SS
8304but evaluate the expression anyway. When you choose the last of
8305these, @value{GDBN} evaluates expressions like the second example above, but
8306also issues a warning.
8307
5d161b24
DB
8308Even if you turn type checking off, there may be other reasons
8309related to type that prevent @value{GDBN} from evaluating an expression.
8310For instance, @value{GDBN} does not know how to add an @code{int} and
8311a @code{struct foo}. These particular type errors have nothing to do
8312with the language in use, and usually arise from expressions, such as
c906108c
SS
8313the one described above, which make little sense to evaluate anyway.
8314
8315Each language defines to what degree it is strict about type. For
8316instance, both Modula-2 and C require the arguments to arithmetical
8317operators to be numbers. In C, enumerated types and pointers can be
8318represented as numbers, so that they are valid arguments to mathematical
9c16f35a 8319operators. @xref{Supported languages, ,Supported languages}, for further
c906108c
SS
8320details on specific languages.
8321
8322@value{GDBN} provides some additional commands for controlling the type checker:
8323
c906108c
SS
8324@kindex set check type
8325@kindex show check type
8326@table @code
8327@item set check type auto
8328Set type checking on or off based on the current working language.
9c16f35a 8329@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8330each language.
8331
8332@item set check type on
8333@itemx set check type off
8334Set type checking on or off, overriding the default setting for the
8335current working language. Issue a warning if the setting does not
8336match the language default. If any type mismatches occur in
d4f3574e 8337evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
8338message and aborts evaluation of the expression.
8339
8340@item set check type warn
8341Cause the type checker to issue warnings, but to always attempt to
8342evaluate the expression. Evaluating the expression may still
8343be impossible for other reasons. For example, @value{GDBN} cannot add
8344numbers and structures.
8345
8346@item show type
5d161b24 8347Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
8348is setting it automatically.
8349@end table
8350
8351@cindex range checking
8352@cindex checks, range
6d2ebf8b 8353@node Range Checking
c906108c
SS
8354@subsection An overview of range checking
8355
8356In some languages (such as Modula-2), it is an error to exceed the
8357bounds of a type; this is enforced with run-time checks. Such range
8358checking is meant to ensure program correctness by making sure
8359computations do not overflow, or indices on an array element access do
8360not exceed the bounds of the array.
8361
8362For expressions you use in @value{GDBN} commands, you can tell
8363@value{GDBN} to treat range errors in one of three ways: ignore them,
8364always treat them as errors and abandon the expression, or issue
8365warnings but evaluate the expression anyway.
8366
8367A range error can result from numerical overflow, from exceeding an
8368array index bound, or when you type a constant that is not a member
8369of any type. Some languages, however, do not treat overflows as an
8370error. In many implementations of C, mathematical overflow causes the
8371result to ``wrap around'' to lower values---for example, if @var{m} is
8372the largest integer value, and @var{s} is the smallest, then
8373
474c8240 8374@smallexample
c906108c 8375@var{m} + 1 @result{} @var{s}
474c8240 8376@end smallexample
c906108c
SS
8377
8378This, too, is specific to individual languages, and in some cases
9c16f35a 8379specific to individual compilers or machines. @xref{Supported languages, ,
c906108c
SS
8380Supported languages}, for further details on specific languages.
8381
8382@value{GDBN} provides some additional commands for controlling the range checker:
8383
c906108c
SS
8384@kindex set check range
8385@kindex show check range
8386@table @code
8387@item set check range auto
8388Set range checking on or off based on the current working language.
9c16f35a 8389@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8390each language.
8391
8392@item set check range on
8393@itemx set check range off
8394Set range checking on or off, overriding the default setting for the
8395current working language. A warning is issued if the setting does not
c3f6f71d
JM
8396match the language default. If a range error occurs and range checking is on,
8397then a message is printed and evaluation of the expression is aborted.
c906108c
SS
8398
8399@item set check range warn
8400Output messages when the @value{GDBN} range checker detects a range error,
8401but attempt to evaluate the expression anyway. Evaluating the
8402expression may still be impossible for other reasons, such as accessing
8403memory that the process does not own (a typical example from many Unix
8404systems).
8405
8406@item show range
8407Show the current setting of the range checker, and whether or not it is
8408being set automatically by @value{GDBN}.
8409@end table
c906108c 8410
9c16f35a 8411@node Supported languages
c906108c 8412@section Supported languages
c906108c 8413
9c16f35a
EZ
8414@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
8415assembly, Modula-2, and Ada.
cce74817 8416@c This is false ...
c906108c
SS
8417Some @value{GDBN} features may be used in expressions regardless of the
8418language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8419and the @samp{@{type@}addr} construct (@pxref{Expressions,
8420,Expressions}) can be used with the constructs of any supported
8421language.
8422
8423The following sections detail to what degree each source language is
8424supported by @value{GDBN}. These sections are not meant to be language
8425tutorials or references, but serve only as a reference guide to what the
8426@value{GDBN} expression parser accepts, and what input and output
8427formats should look like for different languages. There are many good
8428books written on each of these languages; please look to these for a
8429language reference or tutorial.
8430
c906108c 8431@menu
b37303ee 8432* C:: C and C@t{++}
b383017d 8433* Objective-C:: Objective-C
09d4efe1 8434* Fortran:: Fortran
9c16f35a 8435* Pascal:: Pascal
b37303ee 8436* Modula-2:: Modula-2
e07c999f 8437* Ada:: Ada
c906108c
SS
8438@end menu
8439
6d2ebf8b 8440@node C
b37052ae 8441@subsection C and C@t{++}
7a292a7a 8442
b37052ae
EZ
8443@cindex C and C@t{++}
8444@cindex expressions in C or C@t{++}
c906108c 8445
b37052ae 8446Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8447to both languages. Whenever this is the case, we discuss those languages
8448together.
8449
41afff9a
EZ
8450@cindex C@t{++}
8451@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8452@cindex @sc{gnu} C@t{++}
8453The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8454compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8455effectively, you must compile your C@t{++} programs with a supported
8456C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8457compiler (@code{aCC}).
8458
0179ffac
DC
8459For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8460format; if it doesn't work on your system, try the stabs+ debugging
8461format. You can select those formats explicitly with the @code{g++}
8462command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8463@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8464CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8465
c906108c 8466@menu
b37052ae
EZ
8467* C Operators:: C and C@t{++} operators
8468* C Constants:: C and C@t{++} constants
8469* C plus plus expressions:: C@t{++} expressions
8470* C Defaults:: Default settings for C and C@t{++}
8471* C Checks:: C and C@t{++} type and range checks
c906108c 8472* Debugging C:: @value{GDBN} and C
b37052ae 8473* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8474@end menu
c906108c 8475
6d2ebf8b 8476@node C Operators
b37052ae 8477@subsubsection C and C@t{++} operators
7a292a7a 8478
b37052ae 8479@cindex C and C@t{++} operators
c906108c
SS
8480
8481Operators must be defined on values of specific types. For instance,
8482@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8483often defined on groups of types.
c906108c 8484
b37052ae 8485For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8486
8487@itemize @bullet
53a5351d 8488
c906108c 8489@item
c906108c 8490@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8491specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8492
8493@item
d4f3574e
SS
8494@emph{Floating-point types} include @code{float}, @code{double}, and
8495@code{long double} (if supported by the target platform).
c906108c
SS
8496
8497@item
53a5351d 8498@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8499
8500@item
8501@emph{Scalar types} include all of the above.
53a5351d 8502
c906108c
SS
8503@end itemize
8504
8505@noindent
8506The following operators are supported. They are listed here
8507in order of increasing precedence:
8508
8509@table @code
8510@item ,
8511The comma or sequencing operator. Expressions in a comma-separated list
8512are evaluated from left to right, with the result of the entire
8513expression being the last expression evaluated.
8514
8515@item =
8516Assignment. The value of an assignment expression is the value
8517assigned. Defined on scalar types.
8518
8519@item @var{op}=
8520Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8521and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8522@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8523@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8524@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8525
8526@item ?:
8527The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8528of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8529integral type.
8530
8531@item ||
8532Logical @sc{or}. Defined on integral types.
8533
8534@item &&
8535Logical @sc{and}. Defined on integral types.
8536
8537@item |
8538Bitwise @sc{or}. Defined on integral types.
8539
8540@item ^
8541Bitwise exclusive-@sc{or}. Defined on integral types.
8542
8543@item &
8544Bitwise @sc{and}. Defined on integral types.
8545
8546@item ==@r{, }!=
8547Equality and inequality. Defined on scalar types. The value of these
8548expressions is 0 for false and non-zero for true.
8549
8550@item <@r{, }>@r{, }<=@r{, }>=
8551Less than, greater than, less than or equal, greater than or equal.
8552Defined on scalar types. The value of these expressions is 0 for false
8553and non-zero for true.
8554
8555@item <<@r{, }>>
8556left shift, and right shift. Defined on integral types.
8557
8558@item @@
8559The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8560
8561@item +@r{, }-
8562Addition and subtraction. Defined on integral types, floating-point types and
8563pointer types.
8564
8565@item *@r{, }/@r{, }%
8566Multiplication, division, and modulus. Multiplication and division are
8567defined on integral and floating-point types. Modulus is defined on
8568integral types.
8569
8570@item ++@r{, }--
8571Increment and decrement. When appearing before a variable, the
8572operation is performed before the variable is used in an expression;
8573when appearing after it, the variable's value is used before the
8574operation takes place.
8575
8576@item *
8577Pointer dereferencing. Defined on pointer types. Same precedence as
8578@code{++}.
8579
8580@item &
8581Address operator. Defined on variables. Same precedence as @code{++}.
8582
b37052ae
EZ
8583For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8584allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8585(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8586where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8587stored.
c906108c
SS
8588
8589@item -
8590Negative. Defined on integral and floating-point types. Same
8591precedence as @code{++}.
8592
8593@item !
8594Logical negation. Defined on integral types. Same precedence as
8595@code{++}.
8596
8597@item ~
8598Bitwise complement operator. Defined on integral types. Same precedence as
8599@code{++}.
8600
8601
8602@item .@r{, }->
8603Structure member, and pointer-to-structure member. For convenience,
8604@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8605pointer based on the stored type information.
8606Defined on @code{struct} and @code{union} data.
8607
c906108c
SS
8608@item .*@r{, }->*
8609Dereferences of pointers to members.
c906108c
SS
8610
8611@item []
8612Array indexing. @code{@var{a}[@var{i}]} is defined as
8613@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8614
8615@item ()
8616Function parameter list. Same precedence as @code{->}.
8617
c906108c 8618@item ::
b37052ae 8619C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8620and @code{class} types.
c906108c
SS
8621
8622@item ::
7a292a7a
SS
8623Doubled colons also represent the @value{GDBN} scope operator
8624(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8625above.
c906108c
SS
8626@end table
8627
c906108c
SS
8628If an operator is redefined in the user code, @value{GDBN} usually
8629attempts to invoke the redefined version instead of using the operator's
8630predefined meaning.
c906108c 8631
c906108c 8632@menu
5d161b24 8633* C Constants::
c906108c
SS
8634@end menu
8635
6d2ebf8b 8636@node C Constants
b37052ae 8637@subsubsection C and C@t{++} constants
c906108c 8638
b37052ae 8639@cindex C and C@t{++} constants
c906108c 8640
b37052ae 8641@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8642following ways:
c906108c
SS
8643
8644@itemize @bullet
8645@item
8646Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8647specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8648by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8649@samp{l}, specifying that the constant should be treated as a
8650@code{long} value.
8651
8652@item
8653Floating point constants are a sequence of digits, followed by a decimal
8654point, followed by a sequence of digits, and optionally followed by an
8655exponent. An exponent is of the form:
8656@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8657sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8658A floating-point constant may also end with a letter @samp{f} or
8659@samp{F}, specifying that the constant should be treated as being of
8660the @code{float} (as opposed to the default @code{double}) type; or with
8661a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8662constant.
c906108c
SS
8663
8664@item
8665Enumerated constants consist of enumerated identifiers, or their
8666integral equivalents.
8667
8668@item
8669Character constants are a single character surrounded by single quotes
8670(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8671(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8672be represented by a letter or by @dfn{escape sequences}, which are of
8673the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8674of the character's ordinal value; or of the form @samp{\@var{x}}, where
8675@samp{@var{x}} is a predefined special character---for example,
8676@samp{\n} for newline.
8677
8678@item
96a2c332
SS
8679String constants are a sequence of character constants surrounded by
8680double quotes (@code{"}). Any valid character constant (as described
8681above) may appear. Double quotes within the string must be preceded by
8682a backslash, so for instance @samp{"a\"b'c"} is a string of five
8683characters.
c906108c
SS
8684
8685@item
8686Pointer constants are an integral value. You can also write pointers
8687to constants using the C operator @samp{&}.
8688
8689@item
8690Array constants are comma-separated lists surrounded by braces @samp{@{}
8691and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8692integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8693and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8694@end itemize
8695
c906108c 8696@menu
5d161b24
DB
8697* C plus plus expressions::
8698* C Defaults::
8699* C Checks::
c906108c 8700
5d161b24 8701* Debugging C::
c906108c
SS
8702@end menu
8703
6d2ebf8b 8704@node C plus plus expressions
b37052ae
EZ
8705@subsubsection C@t{++} expressions
8706
8707@cindex expressions in C@t{++}
8708@value{GDBN} expression handling can interpret most C@t{++} expressions.
8709
0179ffac
DC
8710@cindex debugging C@t{++} programs
8711@cindex C@t{++} compilers
8712@cindex debug formats and C@t{++}
8713@cindex @value{NGCC} and C@t{++}
c906108c 8714@quotation
b37052ae 8715@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8716proper compiler and the proper debug format. Currently, @value{GDBN}
8717works best when debugging C@t{++} code that is compiled with
8718@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8719@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8720stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8721stabs+ as their default debug format, so you usually don't need to
8722specify a debug format explicitly. Other compilers and/or debug formats
8723are likely to work badly or not at all when using @value{GDBN} to debug
8724C@t{++} code.
c906108c 8725@end quotation
c906108c
SS
8726
8727@enumerate
8728
8729@cindex member functions
8730@item
8731Member function calls are allowed; you can use expressions like
8732
474c8240 8733@smallexample
c906108c 8734count = aml->GetOriginal(x, y)
474c8240 8735@end smallexample
c906108c 8736
41afff9a 8737@vindex this@r{, inside C@t{++} member functions}
b37052ae 8738@cindex namespace in C@t{++}
c906108c
SS
8739@item
8740While a member function is active (in the selected stack frame), your
8741expressions have the same namespace available as the member function;
8742that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8743pointer @code{this} following the same rules as C@t{++}.
c906108c 8744
c906108c 8745@cindex call overloaded functions
d4f3574e 8746@cindex overloaded functions, calling
b37052ae 8747@cindex type conversions in C@t{++}
c906108c
SS
8748@item
8749You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8750call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8751perform overload resolution involving user-defined type conversions,
8752calls to constructors, or instantiations of templates that do not exist
8753in the program. It also cannot handle ellipsis argument lists or
8754default arguments.
8755
8756It does perform integral conversions and promotions, floating-point
8757promotions, arithmetic conversions, pointer conversions, conversions of
8758class objects to base classes, and standard conversions such as those of
8759functions or arrays to pointers; it requires an exact match on the
8760number of function arguments.
8761
8762Overload resolution is always performed, unless you have specified
8763@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8764,@value{GDBN} features for C@t{++}}.
c906108c 8765
d4f3574e 8766You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8767explicit function signature to call an overloaded function, as in
8768@smallexample
8769p 'foo(char,int)'('x', 13)
8770@end smallexample
d4f3574e 8771
c906108c 8772The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8773see @ref{Completion, ,Command completion}.
c906108c 8774
c906108c
SS
8775@cindex reference declarations
8776@item
b37052ae
EZ
8777@value{GDBN} understands variables declared as C@t{++} references; you can use
8778them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8779dereferenced.
8780
8781In the parameter list shown when @value{GDBN} displays a frame, the values of
8782reference variables are not displayed (unlike other variables); this
8783avoids clutter, since references are often used for large structures.
8784The @emph{address} of a reference variable is always shown, unless
8785you have specified @samp{set print address off}.
8786
8787@item
b37052ae 8788@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8789expressions can use it just as expressions in your program do. Since
8790one scope may be defined in another, you can use @code{::} repeatedly if
8791necessary, for example in an expression like
8792@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8793resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8794debugging (@pxref{Variables, ,Program variables}).
8795@end enumerate
8796
b37052ae 8797In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8798calling virtual functions correctly, printing out virtual bases of
8799objects, calling functions in a base subobject, casting objects, and
8800invoking user-defined operators.
c906108c 8801
6d2ebf8b 8802@node C Defaults
b37052ae 8803@subsubsection C and C@t{++} defaults
7a292a7a 8804
b37052ae 8805@cindex C and C@t{++} defaults
c906108c 8806
c906108c
SS
8807If you allow @value{GDBN} to set type and range checking automatically, they
8808both default to @code{off} whenever the working language changes to
b37052ae 8809C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8810selects the working language.
c906108c
SS
8811
8812If you allow @value{GDBN} to set the language automatically, it
8813recognizes source files whose names end with @file{.c}, @file{.C}, or
8814@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8815these files, it sets the working language to C or C@t{++}.
c906108c
SS
8816@xref{Automatically, ,Having @value{GDBN} infer the source language},
8817for further details.
8818
c906108c
SS
8819@c Type checking is (a) primarily motivated by Modula-2, and (b)
8820@c unimplemented. If (b) changes, it might make sense to let this node
8821@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8822
6d2ebf8b 8823@node C Checks
b37052ae 8824@subsubsection C and C@t{++} type and range checks
7a292a7a 8825
b37052ae 8826@cindex C and C@t{++} checks
c906108c 8827
b37052ae 8828By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8829is not used. However, if you turn type checking on, @value{GDBN}
8830considers two variables type equivalent if:
8831
8832@itemize @bullet
8833@item
8834The two variables are structured and have the same structure, union, or
8835enumerated tag.
8836
8837@item
8838The two variables have the same type name, or types that have been
8839declared equivalent through @code{typedef}.
8840
8841@ignore
8842@c leaving this out because neither J Gilmore nor R Pesch understand it.
8843@c FIXME--beers?
8844@item
8845The two @code{struct}, @code{union}, or @code{enum} variables are
8846declared in the same declaration. (Note: this may not be true for all C
8847compilers.)
8848@end ignore
8849@end itemize
8850
8851Range checking, if turned on, is done on mathematical operations. Array
8852indices are not checked, since they are often used to index a pointer
8853that is not itself an array.
c906108c 8854
6d2ebf8b 8855@node Debugging C
c906108c 8856@subsubsection @value{GDBN} and C
c906108c
SS
8857
8858The @code{set print union} and @code{show print union} commands apply to
8859the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8860inside a @code{struct} or @code{class} is also printed. Otherwise, it
8861appears as @samp{@{...@}}.
c906108c
SS
8862
8863The @code{@@} operator aids in the debugging of dynamic arrays, formed
8864with pointers and a memory allocation function. @xref{Expressions,
8865,Expressions}.
8866
c906108c 8867@menu
5d161b24 8868* Debugging C plus plus::
c906108c
SS
8869@end menu
8870
6d2ebf8b 8871@node Debugging C plus plus
b37052ae 8872@subsubsection @value{GDBN} features for C@t{++}
c906108c 8873
b37052ae 8874@cindex commands for C@t{++}
7a292a7a 8875
b37052ae
EZ
8876Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8877designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8878
8879@table @code
8880@cindex break in overloaded functions
8881@item @r{breakpoint menus}
8882When you want a breakpoint in a function whose name is overloaded,
8883@value{GDBN} breakpoint menus help you specify which function definition
8884you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8885
b37052ae 8886@cindex overloading in C@t{++}
c906108c
SS
8887@item rbreak @var{regex}
8888Setting breakpoints using regular expressions is helpful for setting
8889breakpoints on overloaded functions that are not members of any special
8890classes.
8891@xref{Set Breaks, ,Setting breakpoints}.
8892
b37052ae 8893@cindex C@t{++} exception handling
c906108c
SS
8894@item catch throw
8895@itemx catch catch
b37052ae 8896Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8897Catchpoints, , Setting catchpoints}.
8898
8899@cindex inheritance
8900@item ptype @var{typename}
8901Print inheritance relationships as well as other information for type
8902@var{typename}.
8903@xref{Symbols, ,Examining the Symbol Table}.
8904
b37052ae 8905@cindex C@t{++} symbol display
c906108c
SS
8906@item set print demangle
8907@itemx show print demangle
8908@itemx set print asm-demangle
8909@itemx show print asm-demangle
b37052ae
EZ
8910Control whether C@t{++} symbols display in their source form, both when
8911displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8912@xref{Print Settings, ,Print settings}.
8913
8914@item set print object
8915@itemx show print object
8916Choose whether to print derived (actual) or declared types of objects.
8917@xref{Print Settings, ,Print settings}.
8918
8919@item set print vtbl
8920@itemx show print vtbl
8921Control the format for printing virtual function tables.
8922@xref{Print Settings, ,Print settings}.
c906108c 8923(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8924ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8925
8926@kindex set overload-resolution
d4f3574e 8927@cindex overloaded functions, overload resolution
c906108c 8928@item set overload-resolution on
b37052ae 8929Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8930is on. For overloaded functions, @value{GDBN} evaluates the arguments
8931and searches for a function whose signature matches the argument types,
b37052ae 8932using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8933expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8934message.
8935
8936@item set overload-resolution off
b37052ae 8937Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8938overloaded functions that are not class member functions, @value{GDBN}
8939chooses the first function of the specified name that it finds in the
8940symbol table, whether or not its arguments are of the correct type. For
8941overloaded functions that are class member functions, @value{GDBN}
8942searches for a function whose signature @emph{exactly} matches the
8943argument types.
c906108c 8944
9c16f35a
EZ
8945@kindex show overload-resolution
8946@item show overload-resolution
8947Show the current setting of overload resolution.
8948
c906108c
SS
8949@item @r{Overloaded symbol names}
8950You can specify a particular definition of an overloaded symbol, using
b37052ae 8951the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
8952@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8953also use the @value{GDBN} command-line word completion facilities to list the
8954available choices, or to finish the type list for you.
8955@xref{Completion,, Command completion}, for details on how to do this.
8956@end table
c906108c 8957
b37303ee
AF
8958@node Objective-C
8959@subsection Objective-C
8960
8961@cindex Objective-C
8962This section provides information about some commands and command
721c2651
EZ
8963options that are useful for debugging Objective-C code. See also
8964@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
8965few more commands specific to Objective-C support.
b37303ee
AF
8966
8967@menu
b383017d
RM
8968* Method Names in Commands::
8969* The Print Command with Objective-C::
b37303ee
AF
8970@end menu
8971
8972@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
8973@subsubsection Method Names in Commands
8974
8975The following commands have been extended to accept Objective-C method
8976names as line specifications:
8977
8978@kindex clear@r{, and Objective-C}
8979@kindex break@r{, and Objective-C}
8980@kindex info line@r{, and Objective-C}
8981@kindex jump@r{, and Objective-C}
8982@kindex list@r{, and Objective-C}
8983@itemize
8984@item @code{clear}
8985@item @code{break}
8986@item @code{info line}
8987@item @code{jump}
8988@item @code{list}
8989@end itemize
8990
8991A fully qualified Objective-C method name is specified as
8992
8993@smallexample
8994-[@var{Class} @var{methodName}]
8995@end smallexample
8996
c552b3bb
JM
8997where the minus sign is used to indicate an instance method and a
8998plus sign (not shown) is used to indicate a class method. The class
8999name @var{Class} and method name @var{methodName} are enclosed in
9000brackets, similar to the way messages are specified in Objective-C
9001source code. For example, to set a breakpoint at the @code{create}
9002instance method of class @code{Fruit} in the program currently being
9003debugged, enter:
b37303ee
AF
9004
9005@smallexample
9006break -[Fruit create]
9007@end smallexample
9008
9009To list ten program lines around the @code{initialize} class method,
9010enter:
9011
9012@smallexample
9013list +[NSText initialize]
9014@end smallexample
9015
c552b3bb
JM
9016In the current version of @value{GDBN}, the plus or minus sign is
9017required. In future versions of @value{GDBN}, the plus or minus
9018sign will be optional, but you can use it to narrow the search. It
9019is also possible to specify just a method name:
b37303ee
AF
9020
9021@smallexample
9022break create
9023@end smallexample
9024
9025You must specify the complete method name, including any colons. If
9026your program's source files contain more than one @code{create} method,
9027you'll be presented with a numbered list of classes that implement that
9028method. Indicate your choice by number, or type @samp{0} to exit if
9029none apply.
9030
9031As another example, to clear a breakpoint established at the
9032@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
9033
9034@smallexample
9035clear -[NSWindow makeKeyAndOrderFront:]
9036@end smallexample
9037
9038@node The Print Command with Objective-C
9039@subsubsection The Print Command With Objective-C
721c2651 9040@cindex Objective-C, print objects
c552b3bb
JM
9041@kindex print-object
9042@kindex po @r{(@code{print-object})}
b37303ee 9043
c552b3bb 9044The print command has also been extended to accept methods. For example:
b37303ee
AF
9045
9046@smallexample
c552b3bb 9047print -[@var{object} hash]
b37303ee
AF
9048@end smallexample
9049
9050@cindex print an Objective-C object description
c552b3bb
JM
9051@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
9052@noindent
9053will tell @value{GDBN} to send the @code{hash} message to @var{object}
9054and print the result. Also, an additional command has been added,
9055@code{print-object} or @code{po} for short, which is meant to print
9056the description of an object. However, this command may only work
9057with certain Objective-C libraries that have a particular hook
9058function, @code{_NSPrintForDebugger}, defined.
b37303ee 9059
09d4efe1
EZ
9060@node Fortran
9061@subsection Fortran
9062@cindex Fortran-specific support in @value{GDBN}
9063
9064@table @code
9065@cindex @code{COMMON} blocks, Fortran
9066@kindex info common
9067@item info common @r{[}@var{common-name}@r{]}
9068This command prints the values contained in the Fortran @code{COMMON}
9069block whose name is @var{common-name}. With no argument, the names of
9070all @code{COMMON} blocks visible at current program location are
9071printed.
9072@end table
9073
a8f24a35
EZ
9074Fortran symbols are usually case-insensitive, so @value{GDBN} by
9075default uses case-insensitive matches for Fortran symbols. You can
9076change that with the @samp{set case-insensitive} command, see
9077@ref{Symbols}, for the details.
9078
9c16f35a
EZ
9079@node Pascal
9080@subsection Pascal
9081
9082@cindex Pascal support in @value{GDBN}, limitations
9083Debugging Pascal programs which use sets, subranges, file variables, or
9084nested functions does not currently work. @value{GDBN} does not support
9085entering expressions, printing values, or similar features using Pascal
9086syntax.
9087
9088The Pascal-specific command @code{set print pascal_static-members}
9089controls whether static members of Pascal objects are displayed.
9090@xref{Print Settings, pascal_static-members}.
9091
09d4efe1 9092@node Modula-2
c906108c 9093@subsection Modula-2
7a292a7a 9094
d4f3574e 9095@cindex Modula-2, @value{GDBN} support
c906108c
SS
9096
9097The extensions made to @value{GDBN} to support Modula-2 only support
9098output from the @sc{gnu} Modula-2 compiler (which is currently being
9099developed). Other Modula-2 compilers are not currently supported, and
9100attempting to debug executables produced by them is most likely
9101to give an error as @value{GDBN} reads in the executable's symbol
9102table.
9103
9104@cindex expressions in Modula-2
9105@menu
9106* M2 Operators:: Built-in operators
9107* Built-In Func/Proc:: Built-in functions and procedures
9108* M2 Constants:: Modula-2 constants
9109* M2 Defaults:: Default settings for Modula-2
9110* Deviations:: Deviations from standard Modula-2
9111* M2 Checks:: Modula-2 type and range checks
9112* M2 Scope:: The scope operators @code{::} and @code{.}
9113* GDB/M2:: @value{GDBN} and Modula-2
9114@end menu
9115
6d2ebf8b 9116@node M2 Operators
c906108c
SS
9117@subsubsection Operators
9118@cindex Modula-2 operators
9119
9120Operators must be defined on values of specific types. For instance,
9121@code{+} is defined on numbers, but not on structures. Operators are
9122often defined on groups of types. For the purposes of Modula-2, the
9123following definitions hold:
9124
9125@itemize @bullet
9126
9127@item
9128@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
9129their subranges.
9130
9131@item
9132@emph{Character types} consist of @code{CHAR} and its subranges.
9133
9134@item
9135@emph{Floating-point types} consist of @code{REAL}.
9136
9137@item
9138@emph{Pointer types} consist of anything declared as @code{POINTER TO
9139@var{type}}.
9140
9141@item
9142@emph{Scalar types} consist of all of the above.
9143
9144@item
9145@emph{Set types} consist of @code{SET} and @code{BITSET} types.
9146
9147@item
9148@emph{Boolean types} consist of @code{BOOLEAN}.
9149@end itemize
9150
9151@noindent
9152The following operators are supported, and appear in order of
9153increasing precedence:
9154
9155@table @code
9156@item ,
9157Function argument or array index separator.
9158
9159@item :=
9160Assignment. The value of @var{var} @code{:=} @var{value} is
9161@var{value}.
9162
9163@item <@r{, }>
9164Less than, greater than on integral, floating-point, or enumerated
9165types.
9166
9167@item <=@r{, }>=
96a2c332 9168Less than or equal to, greater than or equal to
c906108c
SS
9169on integral, floating-point and enumerated types, or set inclusion on
9170set types. Same precedence as @code{<}.
9171
9172@item =@r{, }<>@r{, }#
9173Equality and two ways of expressing inequality, valid on scalar types.
9174Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9175available for inequality, since @code{#} conflicts with the script
9176comment character.
9177
9178@item IN
9179Set membership. Defined on set types and the types of their members.
9180Same precedence as @code{<}.
9181
9182@item OR
9183Boolean disjunction. Defined on boolean types.
9184
9185@item AND@r{, }&
d4f3574e 9186Boolean conjunction. Defined on boolean types.
c906108c
SS
9187
9188@item @@
9189The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9190
9191@item +@r{, }-
9192Addition and subtraction on integral and floating-point types, or union
9193and difference on set types.
9194
9195@item *
9196Multiplication on integral and floating-point types, or set intersection
9197on set types.
9198
9199@item /
9200Division on floating-point types, or symmetric set difference on set
9201types. Same precedence as @code{*}.
9202
9203@item DIV@r{, }MOD
9204Integer division and remainder. Defined on integral types. Same
9205precedence as @code{*}.
9206
9207@item -
9208Negative. Defined on @code{INTEGER} and @code{REAL} data.
9209
9210@item ^
9211Pointer dereferencing. Defined on pointer types.
9212
9213@item NOT
9214Boolean negation. Defined on boolean types. Same precedence as
9215@code{^}.
9216
9217@item .
9218@code{RECORD} field selector. Defined on @code{RECORD} data. Same
9219precedence as @code{^}.
9220
9221@item []
9222Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
9223
9224@item ()
9225Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
9226as @code{^}.
9227
9228@item ::@r{, }.
9229@value{GDBN} and Modula-2 scope operators.
9230@end table
9231
9232@quotation
9233@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
9234treats the use of the operator @code{IN}, or the use of operators
9235@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
9236@code{<=}, and @code{>=} on sets as an error.
9237@end quotation
9238
cb51c4e0 9239
6d2ebf8b 9240@node Built-In Func/Proc
c906108c 9241@subsubsection Built-in functions and procedures
cb51c4e0 9242@cindex Modula-2 built-ins
c906108c
SS
9243
9244Modula-2 also makes available several built-in procedures and functions.
9245In describing these, the following metavariables are used:
9246
9247@table @var
9248
9249@item a
9250represents an @code{ARRAY} variable.
9251
9252@item c
9253represents a @code{CHAR} constant or variable.
9254
9255@item i
9256represents a variable or constant of integral type.
9257
9258@item m
9259represents an identifier that belongs to a set. Generally used in the
9260same function with the metavariable @var{s}. The type of @var{s} should
9261be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
9262
9263@item n
9264represents a variable or constant of integral or floating-point type.
9265
9266@item r
9267represents a variable or constant of floating-point type.
9268
9269@item t
9270represents a type.
9271
9272@item v
9273represents a variable.
9274
9275@item x
9276represents a variable or constant of one of many types. See the
9277explanation of the function for details.
9278@end table
9279
9280All Modula-2 built-in procedures also return a result, described below.
9281
9282@table @code
9283@item ABS(@var{n})
9284Returns the absolute value of @var{n}.
9285
9286@item CAP(@var{c})
9287If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 9288equivalent, otherwise it returns its argument.
c906108c
SS
9289
9290@item CHR(@var{i})
9291Returns the character whose ordinal value is @var{i}.
9292
9293@item DEC(@var{v})
c3f6f71d 9294Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9295
9296@item DEC(@var{v},@var{i})
9297Decrements the value in the variable @var{v} by @var{i}. Returns the
9298new value.
9299
9300@item EXCL(@var{m},@var{s})
9301Removes the element @var{m} from the set @var{s}. Returns the new
9302set.
9303
9304@item FLOAT(@var{i})
9305Returns the floating point equivalent of the integer @var{i}.
9306
9307@item HIGH(@var{a})
9308Returns the index of the last member of @var{a}.
9309
9310@item INC(@var{v})
c3f6f71d 9311Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9312
9313@item INC(@var{v},@var{i})
9314Increments the value in the variable @var{v} by @var{i}. Returns the
9315new value.
9316
9317@item INCL(@var{m},@var{s})
9318Adds the element @var{m} to the set @var{s} if it is not already
9319there. Returns the new set.
9320
9321@item MAX(@var{t})
9322Returns the maximum value of the type @var{t}.
9323
9324@item MIN(@var{t})
9325Returns the minimum value of the type @var{t}.
9326
9327@item ODD(@var{i})
9328Returns boolean TRUE if @var{i} is an odd number.
9329
9330@item ORD(@var{x})
9331Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
9332value of a character is its @sc{ascii} value (on machines supporting the
9333@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
9334integral, character and enumerated types.
9335
9336@item SIZE(@var{x})
9337Returns the size of its argument. @var{x} can be a variable or a type.
9338
9339@item TRUNC(@var{r})
9340Returns the integral part of @var{r}.
9341
9342@item VAL(@var{t},@var{i})
9343Returns the member of the type @var{t} whose ordinal value is @var{i}.
9344@end table
9345
9346@quotation
9347@emph{Warning:} Sets and their operations are not yet supported, so
9348@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
9349an error.
9350@end quotation
9351
9352@cindex Modula-2 constants
6d2ebf8b 9353@node M2 Constants
c906108c
SS
9354@subsubsection Constants
9355
9356@value{GDBN} allows you to express the constants of Modula-2 in the following
9357ways:
9358
9359@itemize @bullet
9360
9361@item
9362Integer constants are simply a sequence of digits. When used in an
9363expression, a constant is interpreted to be type-compatible with the
9364rest of the expression. Hexadecimal integers are specified by a
9365trailing @samp{H}, and octal integers by a trailing @samp{B}.
9366
9367@item
9368Floating point constants appear as a sequence of digits, followed by a
9369decimal point and another sequence of digits. An optional exponent can
9370then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
9371@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
9372digits of the floating point constant must be valid decimal (base 10)
9373digits.
9374
9375@item
9376Character constants consist of a single character enclosed by a pair of
9377like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 9378also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
9379followed by a @samp{C}.
9380
9381@item
9382String constants consist of a sequence of characters enclosed by a
9383pair of like quotes, either single (@code{'}) or double (@code{"}).
9384Escape sequences in the style of C are also allowed. @xref{C
b37052ae 9385Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
9386sequences.
9387
9388@item
9389Enumerated constants consist of an enumerated identifier.
9390
9391@item
9392Boolean constants consist of the identifiers @code{TRUE} and
9393@code{FALSE}.
9394
9395@item
9396Pointer constants consist of integral values only.
9397
9398@item
9399Set constants are not yet supported.
9400@end itemize
9401
6d2ebf8b 9402@node M2 Defaults
c906108c
SS
9403@subsubsection Modula-2 defaults
9404@cindex Modula-2 defaults
9405
9406If type and range checking are set automatically by @value{GDBN}, they
9407both default to @code{on} whenever the working language changes to
d4f3574e 9408Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
9409selected the working language.
9410
9411If you allow @value{GDBN} to set the language automatically, then entering
9412code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 9413working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
9414the language automatically}, for further details.
9415
6d2ebf8b 9416@node Deviations
c906108c
SS
9417@subsubsection Deviations from standard Modula-2
9418@cindex Modula-2, deviations from
9419
9420A few changes have been made to make Modula-2 programs easier to debug.
9421This is done primarily via loosening its type strictness:
9422
9423@itemize @bullet
9424@item
9425Unlike in standard Modula-2, pointer constants can be formed by
9426integers. This allows you to modify pointer variables during
9427debugging. (In standard Modula-2, the actual address contained in a
9428pointer variable is hidden from you; it can only be modified
9429through direct assignment to another pointer variable or expression that
9430returned a pointer.)
9431
9432@item
9433C escape sequences can be used in strings and characters to represent
9434non-printable characters. @value{GDBN} prints out strings with these
9435escape sequences embedded. Single non-printable characters are
9436printed using the @samp{CHR(@var{nnn})} format.
9437
9438@item
9439The assignment operator (@code{:=}) returns the value of its right-hand
9440argument.
9441
9442@item
9443All built-in procedures both modify @emph{and} return their argument.
9444@end itemize
9445
6d2ebf8b 9446@node M2 Checks
c906108c
SS
9447@subsubsection Modula-2 type and range checks
9448@cindex Modula-2 checks
9449
9450@quotation
9451@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9452range checking.
9453@end quotation
9454@c FIXME remove warning when type/range checks added
9455
9456@value{GDBN} considers two Modula-2 variables type equivalent if:
9457
9458@itemize @bullet
9459@item
9460They are of types that have been declared equivalent via a @code{TYPE
9461@var{t1} = @var{t2}} statement
9462
9463@item
9464They have been declared on the same line. (Note: This is true of the
9465@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9466@end itemize
9467
9468As long as type checking is enabled, any attempt to combine variables
9469whose types are not equivalent is an error.
9470
9471Range checking is done on all mathematical operations, assignment, array
9472index bounds, and all built-in functions and procedures.
9473
6d2ebf8b 9474@node M2 Scope
c906108c
SS
9475@subsubsection The scope operators @code{::} and @code{.}
9476@cindex scope
41afff9a 9477@cindex @code{.}, Modula-2 scope operator
c906108c
SS
9478@cindex colon, doubled as scope operator
9479@ifinfo
41afff9a 9480@vindex colon-colon@r{, in Modula-2}
c906108c
SS
9481@c Info cannot handle :: but TeX can.
9482@end ifinfo
9483@iftex
41afff9a 9484@vindex ::@r{, in Modula-2}
c906108c
SS
9485@end iftex
9486
9487There are a few subtle differences between the Modula-2 scope operator
9488(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9489similar syntax:
9490
474c8240 9491@smallexample
c906108c
SS
9492
9493@var{module} . @var{id}
9494@var{scope} :: @var{id}
474c8240 9495@end smallexample
c906108c
SS
9496
9497@noindent
9498where @var{scope} is the name of a module or a procedure,
9499@var{module} the name of a module, and @var{id} is any declared
9500identifier within your program, except another module.
9501
9502Using the @code{::} operator makes @value{GDBN} search the scope
9503specified by @var{scope} for the identifier @var{id}. If it is not
9504found in the specified scope, then @value{GDBN} searches all scopes
9505enclosing the one specified by @var{scope}.
9506
9507Using the @code{.} operator makes @value{GDBN} search the current scope for
9508the identifier specified by @var{id} that was imported from the
9509definition module specified by @var{module}. With this operator, it is
9510an error if the identifier @var{id} was not imported from definition
9511module @var{module}, or if @var{id} is not an identifier in
9512@var{module}.
9513
6d2ebf8b 9514@node GDB/M2
c906108c
SS
9515@subsubsection @value{GDBN} and Modula-2
9516
9517Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9518Five subcommands of @code{set print} and @code{show print} apply
b37052ae 9519specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 9520@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 9521apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
9522analogue in Modula-2.
9523
9524The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 9525with any language, is not useful with Modula-2. Its
c906108c 9526intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 9527created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 9528address can be specified by an integral constant, the construct
d4f3574e 9529@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
9530
9531@cindex @code{#} in Modula-2
9532In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9533interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 9534
e07c999f
PH
9535@node Ada
9536@subsection Ada
9537@cindex Ada
9538
9539The extensions made to @value{GDBN} for Ada only support
9540output from the @sc{gnu} Ada (GNAT) compiler.
9541Other Ada compilers are not currently supported, and
9542attempting to debug executables produced by them is most likely
9543to be difficult.
9544
9545
9546@cindex expressions in Ada
9547@menu
9548* Ada Mode Intro:: General remarks on the Ada syntax
9549 and semantics supported by Ada mode
9550 in @value{GDBN}.
9551* Omissions from Ada:: Restrictions on the Ada expression syntax.
9552* Additions to Ada:: Extensions of the Ada expression syntax.
9553* Stopping Before Main Program:: Debugging the program during elaboration.
9554* Ada Glitches:: Known peculiarities of Ada mode.
9555@end menu
9556
9557@node Ada Mode Intro
9558@subsubsection Introduction
9559@cindex Ada mode, general
9560
9561The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9562syntax, with some extensions.
9563The philosophy behind the design of this subset is
9564
9565@itemize @bullet
9566@item
9567That @value{GDBN} should provide basic literals and access to operations for
9568arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9569leaving more sophisticated computations to subprograms written into the
9570program (which therefore may be called from @value{GDBN}).
9571
9572@item
9573That type safety and strict adherence to Ada language restrictions
9574are not particularly important to the @value{GDBN} user.
9575
9576@item
9577That brevity is important to the @value{GDBN} user.
9578@end itemize
9579
9580Thus, for brevity, the debugger acts as if there were
9581implicit @code{with} and @code{use} clauses in effect for all user-written
9582packages, making it unnecessary to fully qualify most names with
9583their packages, regardless of context. Where this causes ambiguity,
9584@value{GDBN} asks the user's intent.
9585
9586The debugger will start in Ada mode if it detects an Ada main program.
9587As for other languages, it will enter Ada mode when stopped in a program that
9588was translated from an Ada source file.
9589
9590While in Ada mode, you may use `@t{--}' for comments. This is useful
9591mostly for documenting command files. The standard @value{GDBN} comment
9592(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9593middle (to allow based literals).
9594
9595The debugger supports limited overloading. Given a subprogram call in which
9596the function symbol has multiple definitions, it will use the number of
9597actual parameters and some information about their types to attempt to narrow
9598the set of definitions. It also makes very limited use of context, preferring
9599procedures to functions in the context of the @code{call} command, and
9600functions to procedures elsewhere.
9601
9602@node Omissions from Ada
9603@subsubsection Omissions from Ada
9604@cindex Ada, omissions from
9605
9606Here are the notable omissions from the subset:
9607
9608@itemize @bullet
9609@item
9610Only a subset of the attributes are supported:
9611
9612@itemize @minus
9613@item
9614@t{'First}, @t{'Last}, and @t{'Length}
9615 on array objects (not on types and subtypes).
9616
9617@item
9618@t{'Min} and @t{'Max}.
9619
9620@item
9621@t{'Pos} and @t{'Val}.
9622
9623@item
9624@t{'Tag}.
9625
9626@item
9627@t{'Range} on array objects (not subtypes), but only as the right
9628operand of the membership (@code{in}) operator.
9629
9630@item
9631@t{'Access}, @t{'Unchecked_Access}, and
9632@t{'Unrestricted_Access} (a GNAT extension).
9633
9634@item
9635@t{'Address}.
9636@end itemize
9637
9638@item
9639The names in
9640@code{Characters.Latin_1} are not available and
9641concatenation is not implemented. Thus, escape characters in strings are
9642not currently available.
9643
9644@item
9645Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9646equality of representations. They will generally work correctly
9647for strings and arrays whose elements have integer or enumeration types.
9648They may not work correctly for arrays whose element
9649types have user-defined equality, for arrays of real values
9650(in particular, IEEE-conformant floating point, because of negative
9651zeroes and NaNs), and for arrays whose elements contain unused bits with
9652indeterminate values.
9653
9654@item
9655The other component-by-component array operations (@code{and}, @code{or},
9656@code{xor}, @code{not}, and relational tests other than equality)
9657are not implemented.
9658
9659@item
9660There are no record or array aggregates.
9661
9662@item
9663Calls to dispatching subprograms are not implemented.
9664
9665@item
9666The overloading algorithm is much more limited (i.e., less selective)
9667than that of real Ada. It makes only limited use of the context in which a subexpression
9668appears to resolve its meaning, and it is much looser in its rules for allowing
9669type matches. As a result, some function calls will be ambiguous, and the user
9670will be asked to choose the proper resolution.
9671
9672@item
9673The @code{new} operator is not implemented.
9674
9675@item
9676Entry calls are not implemented.
9677
9678@item
9679Aside from printing, arithmetic operations on the native VAX floating-point
9680formats are not supported.
9681
9682@item
9683It is not possible to slice a packed array.
9684@end itemize
9685
9686@node Additions to Ada
9687@subsubsection Additions to Ada
9688@cindex Ada, deviations from
9689
9690As it does for other languages, @value{GDBN} makes certain generic
9691extensions to Ada (@pxref{Expressions}):
9692
9693@itemize @bullet
9694@item
9695If the expression @var{E} is a variable residing in memory
9696(typically a local variable or array element) and @var{N} is
9697a positive integer, then @code{@var{E}@@@var{N}} displays the values of
9698@var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
9699In Ada, this operator is generally not necessary, since its prime use
9700is in displaying parts of an array, and slicing will usually do this in Ada.
9701However, there are occasional uses when debugging programs
9702in which certain debugging information has been optimized away.
9703
9704@item
9705@code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
9706in function or file @var{B}.'' When @var{B} is a file name, you must typically
9707surround it in single quotes.
9708
9709@item
9710The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
9711@var{type} that appears at address @var{addr}.''
9712
9713@item
9714A name starting with @samp{$} is a convenience variable
9715(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
9716@end itemize
9717
9718In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
9719to Ada:
9720
9721@itemize @bullet
9722@item
9723The assignment statement is allowed as an expression, returning
9724its right-hand operand as its value. Thus, you may enter
9725
9726@smallexample
9727set x := y + 3
9728print A(tmp := y + 1)
9729@end smallexample
9730
9731@item
9732The semicolon is allowed as an ``operator,'' returning as its value
9733the value of its right-hand operand.
9734This allows, for example,
9735complex conditional breaks:
9736
9737@smallexample
9738break f
9739condition 1 (report(i); k += 1; A(k) > 100)
9740@end smallexample
9741
9742@item
9743Rather than use catenation and symbolic character names to introduce special
9744characters into strings, one may instead use a special bracket notation,
9745which is also used to print strings. A sequence of characters of the form
9746@samp{["@var{XX}"]} within a string or character literal denotes the
9747(single) character whose numeric encoding is @var{XX} in hexadecimal. The
9748sequence of characters @samp{["""]} also denotes a single quotation mark
9749in strings. For example,
9750@smallexample
9751 "One line.["0a"]Next line.["0a"]"
9752@end smallexample
9753@noindent
9754contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
9755period.
9756
9757@item
9758The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
9759@t{'Max} is optional (and is ignored in any case). For example, it is valid
9760to write
9761
9762@smallexample
9763print 'max(x, y)
9764@end smallexample
9765
9766@item
9767When printing arrays, @value{GDBN} uses positional notation when the
9768array has a lower bound of 1, and uses a modified named notation otherwise.
9769For example, a one-dimensional array of three integers with a lower bound of 3 might print as
9770
9771@smallexample
9772(3 => 10, 17, 1)
9773@end smallexample
9774
9775@noindent
9776That is, in contrast to valid Ada, only the first component has a @code{=>}
9777clause.
9778
9779@item
9780You may abbreviate attributes in expressions with any unique,
9781multi-character subsequence of
9782their names (an exact match gets preference).
9783For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
9784in place of @t{a'length}.
9785
9786@item
9787@cindex quoting Ada internal identifiers
9788Since Ada is case-insensitive, the debugger normally maps identifiers you type
9789to lower case. The GNAT compiler uses upper-case characters for
9790some of its internal identifiers, which are normally of no interest to users.
9791For the rare occasions when you actually have to look at them,
9792enclose them in angle brackets to avoid the lower-case mapping.
9793For example,
9794@smallexample
9795@value{GDBP} print <JMPBUF_SAVE>[0]
9796@end smallexample
9797
9798@item
9799Printing an object of class-wide type or dereferencing an
9800access-to-class-wide value will display all the components of the object's
9801specific type (as indicated by its run-time tag). Likewise, component
9802selection on such a value will operate on the specific type of the
9803object.
9804
9805@end itemize
9806
9807@node Stopping Before Main Program
9808@subsubsection Stopping at the Very Beginning
9809
9810@cindex breakpointing Ada elaboration code
9811It is sometimes necessary to debug the program during elaboration, and
9812before reaching the main procedure.
9813As defined in the Ada Reference
9814Manual, the elaboration code is invoked from a procedure called
9815@code{adainit}. To run your program up to the beginning of
9816elaboration, simply use the following two commands:
9817@code{tbreak adainit} and @code{run}.
9818
9819@node Ada Glitches
9820@subsubsection Known Peculiarities of Ada Mode
9821@cindex Ada, problems
9822
9823Besides the omissions listed previously (@pxref{Omissions from Ada}),
9824we know of several problems with and limitations of Ada mode in
9825@value{GDBN},
9826some of which will be fixed with planned future releases of the debugger
9827and the GNU Ada compiler.
9828
9829@itemize @bullet
9830@item
9831Currently, the debugger
9832has insufficient information to determine whether certain pointers represent
9833pointers to objects or the objects themselves.
9834Thus, the user may have to tack an extra @code{.all} after an expression
9835to get it printed properly.
9836
9837@item
9838Static constants that the compiler chooses not to materialize as objects in
9839storage are invisible to the debugger.
9840
9841@item
9842Named parameter associations in function argument lists are ignored (the
9843argument lists are treated as positional).
9844
9845@item
9846Many useful library packages are currently invisible to the debugger.
9847
9848@item
9849Fixed-point arithmetic, conversions, input, and output is carried out using
9850floating-point arithmetic, and may give results that only approximate those on
9851the host machine.
9852
9853@item
9854The type of the @t{'Address} attribute may not be @code{System.Address}.
9855
9856@item
9857The GNAT compiler never generates the prefix @code{Standard} for any of
9858the standard symbols defined by the Ada language. @value{GDBN} knows about
9859this: it will strip the prefix from names when you use it, and will never
9860look for a name you have so qualified among local symbols, nor match against
9861symbols in other packages or subprograms. If you have
9862defined entities anywhere in your program other than parameters and
9863local variables whose simple names match names in @code{Standard},
9864GNAT's lack of qualification here can cause confusion. When this happens,
9865you can usually resolve the confusion
9866by qualifying the problematic names with package
9867@code{Standard} explicitly.
9868@end itemize
9869
4e562065
JB
9870@node Unsupported languages
9871@section Unsupported languages
9872
9873@cindex unsupported languages
9874@cindex minimal language
9875In addition to the other fully-supported programming languages,
9876@value{GDBN} also provides a pseudo-language, called @code{minimal}.
9877It does not represent a real programming language, but provides a set
9878of capabilities close to what the C or assembly languages provide.
9879This should allow most simple operations to be performed while debugging
9880an application that uses a language currently not supported by @value{GDBN}.
9881
9882If the language is set to @code{auto}, @value{GDBN} will automatically
9883select this language if the current frame corresponds to an unsupported
9884language.
9885
6d2ebf8b 9886@node Symbols
c906108c
SS
9887@chapter Examining the Symbol Table
9888
d4f3574e 9889The commands described in this chapter allow you to inquire about the
c906108c
SS
9890symbols (names of variables, functions and types) defined in your
9891program. This information is inherent in the text of your program and
9892does not change as your program executes. @value{GDBN} finds it in your
9893program's symbol table, in the file indicated when you started @value{GDBN}
9894(@pxref{File Options, ,Choosing files}), or by one of the
9895file-management commands (@pxref{Files, ,Commands to specify files}).
9896
9897@cindex symbol names
9898@cindex names of symbols
9899@cindex quoting names
9900Occasionally, you may need to refer to symbols that contain unusual
9901characters, which @value{GDBN} ordinarily treats as word delimiters. The
9902most frequent case is in referring to static variables in other
9903source files (@pxref{Variables,,Program variables}). File names
9904are recorded in object files as debugging symbols, but @value{GDBN} would
9905ordinarily parse a typical file name, like @file{foo.c}, as the three words
9906@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
9907@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
9908
474c8240 9909@smallexample
c906108c 9910p 'foo.c'::x
474c8240 9911@end smallexample
c906108c
SS
9912
9913@noindent
9914looks up the value of @code{x} in the scope of the file @file{foo.c}.
9915
9916@table @code
a8f24a35
EZ
9917@cindex case-insensitive symbol names
9918@cindex case sensitivity in symbol names
9919@kindex set case-sensitive
9920@item set case-sensitive on
9921@itemx set case-sensitive off
9922@itemx set case-sensitive auto
9923Normally, when @value{GDBN} looks up symbols, it matches their names
9924with case sensitivity determined by the current source language.
9925Occasionally, you may wish to control that. The command @code{set
9926case-sensitive} lets you do that by specifying @code{on} for
9927case-sensitive matches or @code{off} for case-insensitive ones. If
9928you specify @code{auto}, case sensitivity is reset to the default
9929suitable for the source language. The default is case-sensitive
9930matches for all languages except for Fortran, for which the default is
9931case-insensitive matches.
9932
9c16f35a
EZ
9933@kindex show case-sensitive
9934@item show case-sensitive
a8f24a35
EZ
9935This command shows the current setting of case sensitivity for symbols
9936lookups.
9937
c906108c 9938@kindex info address
b37052ae 9939@cindex address of a symbol
c906108c
SS
9940@item info address @var{symbol}
9941Describe where the data for @var{symbol} is stored. For a register
9942variable, this says which register it is kept in. For a non-register
9943local variable, this prints the stack-frame offset at which the variable
9944is always stored.
9945
9946Note the contrast with @samp{print &@var{symbol}}, which does not work
9947at all for a register variable, and for a stack local variable prints
9948the exact address of the current instantiation of the variable.
9949
3d67e040 9950@kindex info symbol
b37052ae 9951@cindex symbol from address
9c16f35a 9952@cindex closest symbol and offset for an address
3d67e040
EZ
9953@item info symbol @var{addr}
9954Print the name of a symbol which is stored at the address @var{addr}.
9955If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
9956nearest symbol and an offset from it:
9957
474c8240 9958@smallexample
3d67e040
EZ
9959(@value{GDBP}) info symbol 0x54320
9960_initialize_vx + 396 in section .text
474c8240 9961@end smallexample
3d67e040
EZ
9962
9963@noindent
9964This is the opposite of the @code{info address} command. You can use
9965it to find out the name of a variable or a function given its address.
9966
c906108c 9967@kindex whatis
d4f3574e
SS
9968@item whatis @var{expr}
9969Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
9970actually evaluated, and any side-effecting operations (such as
9971assignments or function calls) inside it do not take place.
9972@xref{Expressions, ,Expressions}.
9973
9974@item whatis
9975Print the data type of @code{$}, the last value in the value history.
9976
9977@kindex ptype
9978@item ptype @var{typename}
9979Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
9980the name of a type, or for C code it may have the form @samp{class
9981@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
9982@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 9983
d4f3574e 9984@item ptype @var{expr}
c906108c 9985@itemx ptype
d4f3574e 9986Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
9987differs from @code{whatis} by printing a detailed description, instead
9988of just the name of the type.
9989
9990For example, for this variable declaration:
9991
474c8240 9992@smallexample
c906108c 9993struct complex @{double real; double imag;@} v;
474c8240 9994@end smallexample
c906108c
SS
9995
9996@noindent
9997the two commands give this output:
9998
474c8240 9999@smallexample
c906108c
SS
10000@group
10001(@value{GDBP}) whatis v
10002type = struct complex
10003(@value{GDBP}) ptype v
10004type = struct complex @{
10005 double real;
10006 double imag;
10007@}
10008@end group
474c8240 10009@end smallexample
c906108c
SS
10010
10011@noindent
10012As with @code{whatis}, using @code{ptype} without an argument refers to
10013the type of @code{$}, the last value in the value history.
10014
10015@kindex info types
10016@item info types @var{regexp}
10017@itemx info types
09d4efe1
EZ
10018Print a brief description of all types whose names match the regular
10019expression @var{regexp} (or all types in your program, if you supply
10020no argument). Each complete typename is matched as though it were a
10021complete line; thus, @samp{i type value} gives information on all
10022types in your program whose names include the string @code{value}, but
10023@samp{i type ^value$} gives information only on types whose complete
10024name is @code{value}.
c906108c
SS
10025
10026This command differs from @code{ptype} in two ways: first, like
10027@code{whatis}, it does not print a detailed description; second, it
10028lists all source files where a type is defined.
10029
b37052ae
EZ
10030@kindex info scope
10031@cindex local variables
09d4efe1 10032@item info scope @var{location}
b37052ae 10033List all the variables local to a particular scope. This command
09d4efe1
EZ
10034accepts a @var{location} argument---a function name, a source line, or
10035an address preceded by a @samp{*}, and prints all the variables local
10036to the scope defined by that location. For example:
b37052ae
EZ
10037
10038@smallexample
10039(@value{GDBP}) @b{info scope command_line_handler}
10040Scope for command_line_handler:
10041Symbol rl is an argument at stack/frame offset 8, length 4.
10042Symbol linebuffer is in static storage at address 0x150a18, length 4.
10043Symbol linelength is in static storage at address 0x150a1c, length 4.
10044Symbol p is a local variable in register $esi, length 4.
10045Symbol p1 is a local variable in register $ebx, length 4.
10046Symbol nline is a local variable in register $edx, length 4.
10047Symbol repeat is a local variable at frame offset -8, length 4.
10048@end smallexample
10049
f5c37c66
EZ
10050@noindent
10051This command is especially useful for determining what data to collect
10052during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
10053collect}.
10054
c906108c
SS
10055@kindex info source
10056@item info source
919d772c
JB
10057Show information about the current source file---that is, the source file for
10058the function containing the current point of execution:
10059@itemize @bullet
10060@item
10061the name of the source file, and the directory containing it,
10062@item
10063the directory it was compiled in,
10064@item
10065its length, in lines,
10066@item
10067which programming language it is written in,
10068@item
10069whether the executable includes debugging information for that file, and
10070if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
10071@item
10072whether the debugging information includes information about
10073preprocessor macros.
10074@end itemize
10075
c906108c
SS
10076
10077@kindex info sources
10078@item info sources
10079Print the names of all source files in your program for which there is
10080debugging information, organized into two lists: files whose symbols
10081have already been read, and files whose symbols will be read when needed.
10082
10083@kindex info functions
10084@item info functions
10085Print the names and data types of all defined functions.
10086
10087@item info functions @var{regexp}
10088Print the names and data types of all defined functions
10089whose names contain a match for regular expression @var{regexp}.
10090Thus, @samp{info fun step} finds all functions whose names
10091include @code{step}; @samp{info fun ^step} finds those whose names
b383017d
RM
10092start with @code{step}. If a function name contains characters
10093that conflict with the regular expression language (eg.
1c5dfdad 10094@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
10095
10096@kindex info variables
10097@item info variables
10098Print the names and data types of all variables that are declared
6ca652b0 10099outside of functions (i.e.@: excluding local variables).
c906108c
SS
10100
10101@item info variables @var{regexp}
10102Print the names and data types of all variables (except for local
10103variables) whose names contain a match for regular expression
10104@var{regexp}.
10105
b37303ee 10106@kindex info classes
721c2651 10107@cindex Objective-C, classes and selectors
b37303ee
AF
10108@item info classes
10109@itemx info classes @var{regexp}
10110Display all Objective-C classes in your program, or
10111(with the @var{regexp} argument) all those matching a particular regular
10112expression.
10113
10114@kindex info selectors
10115@item info selectors
10116@itemx info selectors @var{regexp}
10117Display all Objective-C selectors in your program, or
10118(with the @var{regexp} argument) all those matching a particular regular
10119expression.
10120
c906108c
SS
10121@ignore
10122This was never implemented.
10123@kindex info methods
10124@item info methods
10125@itemx info methods @var{regexp}
10126The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
10127methods within C@t{++} program, or (with the @var{regexp} argument) a
10128specific set of methods found in the various C@t{++} classes. Many
10129C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
10130from the @code{ptype} command can be overwhelming and hard to use. The
10131@code{info-methods} command filters the methods, printing only those
10132which match the regular-expression @var{regexp}.
10133@end ignore
10134
c906108c
SS
10135@cindex reloading symbols
10136Some systems allow individual object files that make up your program to
7a292a7a
SS
10137be replaced without stopping and restarting your program. For example,
10138in VxWorks you can simply recompile a defective object file and keep on
10139running. If you are running on one of these systems, you can allow
10140@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
10141
10142@table @code
10143@kindex set symbol-reloading
10144@item set symbol-reloading on
10145Replace symbol definitions for the corresponding source file when an
10146object file with a particular name is seen again.
10147
10148@item set symbol-reloading off
6d2ebf8b
SS
10149Do not replace symbol definitions when encountering object files of the
10150same name more than once. This is the default state; if you are not
10151running on a system that permits automatic relinking of modules, you
10152should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
10153may discard symbols when linking large programs, that may contain
10154several modules (from different directories or libraries) with the same
10155name.
c906108c
SS
10156
10157@kindex show symbol-reloading
10158@item show symbol-reloading
10159Show the current @code{on} or @code{off} setting.
10160@end table
c906108c 10161
9c16f35a 10162@cindex opaque data types
c906108c
SS
10163@kindex set opaque-type-resolution
10164@item set opaque-type-resolution on
10165Tell @value{GDBN} to resolve opaque types. An opaque type is a type
10166declared as a pointer to a @code{struct}, @code{class}, or
10167@code{union}---for example, @code{struct MyType *}---that is used in one
10168source file although the full declaration of @code{struct MyType} is in
10169another source file. The default is on.
10170
10171A change in the setting of this subcommand will not take effect until
10172the next time symbols for a file are loaded.
10173
10174@item set opaque-type-resolution off
10175Tell @value{GDBN} not to resolve opaque types. In this case, the type
10176is printed as follows:
10177@smallexample
10178@{<no data fields>@}
10179@end smallexample
10180
10181@kindex show opaque-type-resolution
10182@item show opaque-type-resolution
10183Show whether opaque types are resolved or not.
c906108c
SS
10184
10185@kindex maint print symbols
10186@cindex symbol dump
10187@kindex maint print psymbols
10188@cindex partial symbol dump
10189@item maint print symbols @var{filename}
10190@itemx maint print psymbols @var{filename}
10191@itemx maint print msymbols @var{filename}
10192Write a dump of debugging symbol data into the file @var{filename}.
10193These commands are used to debug the @value{GDBN} symbol-reading code. Only
10194symbols with debugging data are included. If you use @samp{maint print
10195symbols}, @value{GDBN} includes all the symbols for which it has already
10196collected full details: that is, @var{filename} reflects symbols for
10197only those files whose symbols @value{GDBN} has read. You can use the
10198command @code{info sources} to find out which files these are. If you
10199use @samp{maint print psymbols} instead, the dump shows information about
10200symbols that @value{GDBN} only knows partially---that is, symbols defined in
10201files that @value{GDBN} has skimmed, but not yet read completely. Finally,
10202@samp{maint print msymbols} dumps just the minimal symbol information
10203required for each object file from which @value{GDBN} has read some symbols.
10204@xref{Files, ,Commands to specify files}, for a discussion of how
10205@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 10206
5e7b2f39
JB
10207@kindex maint info symtabs
10208@kindex maint info psymtabs
44ea7b70
JB
10209@cindex listing @value{GDBN}'s internal symbol tables
10210@cindex symbol tables, listing @value{GDBN}'s internal
10211@cindex full symbol tables, listing @value{GDBN}'s internal
10212@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
10213@item maint info symtabs @r{[} @var{regexp} @r{]}
10214@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
10215
10216List the @code{struct symtab} or @code{struct partial_symtab}
10217structures whose names match @var{regexp}. If @var{regexp} is not
10218given, list them all. The output includes expressions which you can
10219copy into a @value{GDBN} debugging this one to examine a particular
10220structure in more detail. For example:
10221
10222@smallexample
5e7b2f39 10223(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
10224@{ objfile /home/gnu/build/gdb/gdb
10225 ((struct objfile *) 0x82e69d0)
b383017d 10226 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10227 ((struct partial_symtab *) 0x8474b10)
10228 readin no
10229 fullname (null)
10230 text addresses 0x814d3c8 -- 0x8158074
10231 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
10232 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
10233 dependencies (none)
10234 @}
10235@}
5e7b2f39 10236(@value{GDBP}) maint info symtabs
44ea7b70
JB
10237(@value{GDBP})
10238@end smallexample
10239@noindent
10240We see that there is one partial symbol table whose filename contains
10241the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
10242and we see that @value{GDBN} has not read in any symtabs yet at all.
10243If we set a breakpoint on a function, that will cause @value{GDBN} to
10244read the symtab for the compilation unit containing that function:
10245
10246@smallexample
10247(@value{GDBP}) break dwarf2_psymtab_to_symtab
10248Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
10249line 1574.
5e7b2f39 10250(@value{GDBP}) maint info symtabs
b383017d 10251@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 10252 ((struct objfile *) 0x82e69d0)
b383017d 10253 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10254 ((struct symtab *) 0x86c1f38)
10255 dirname (null)
10256 fullname (null)
10257 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
10258 debugformat DWARF 2
10259 @}
10260@}
b383017d 10261(@value{GDBP})
44ea7b70 10262@end smallexample
c906108c
SS
10263@end table
10264
44ea7b70 10265
6d2ebf8b 10266@node Altering
c906108c
SS
10267@chapter Altering Execution
10268
10269Once you think you have found an error in your program, you might want to
10270find out for certain whether correcting the apparent error would lead to
10271correct results in the rest of the run. You can find the answer by
10272experiment, using the @value{GDBN} features for altering execution of the
10273program.
10274
10275For example, you can store new values into variables or memory
7a292a7a
SS
10276locations, give your program a signal, restart it at a different
10277address, or even return prematurely from a function.
c906108c
SS
10278
10279@menu
10280* Assignment:: Assignment to variables
10281* Jumping:: Continuing at a different address
c906108c 10282* Signaling:: Giving your program a signal
c906108c
SS
10283* Returning:: Returning from a function
10284* Calling:: Calling your program's functions
10285* Patching:: Patching your program
10286@end menu
10287
6d2ebf8b 10288@node Assignment
c906108c
SS
10289@section Assignment to variables
10290
10291@cindex assignment
10292@cindex setting variables
10293To alter the value of a variable, evaluate an assignment expression.
10294@xref{Expressions, ,Expressions}. For example,
10295
474c8240 10296@smallexample
c906108c 10297print x=4
474c8240 10298@end smallexample
c906108c
SS
10299
10300@noindent
10301stores the value 4 into the variable @code{x}, and then prints the
5d161b24 10302value of the assignment expression (which is 4).
c906108c
SS
10303@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
10304information on operators in supported languages.
c906108c
SS
10305
10306@kindex set variable
10307@cindex variables, setting
10308If you are not interested in seeing the value of the assignment, use the
10309@code{set} command instead of the @code{print} command. @code{set} is
10310really the same as @code{print} except that the expression's value is
10311not printed and is not put in the value history (@pxref{Value History,
10312,Value history}). The expression is evaluated only for its effects.
10313
c906108c
SS
10314If the beginning of the argument string of the @code{set} command
10315appears identical to a @code{set} subcommand, use the @code{set
10316variable} command instead of just @code{set}. This command is identical
10317to @code{set} except for its lack of subcommands. For example, if your
10318program has a variable @code{width}, you get an error if you try to set
10319a new value with just @samp{set width=13}, because @value{GDBN} has the
10320command @code{set width}:
10321
474c8240 10322@smallexample
c906108c
SS
10323(@value{GDBP}) whatis width
10324type = double
10325(@value{GDBP}) p width
10326$4 = 13
10327(@value{GDBP}) set width=47
10328Invalid syntax in expression.
474c8240 10329@end smallexample
c906108c
SS
10330
10331@noindent
10332The invalid expression, of course, is @samp{=47}. In
10333order to actually set the program's variable @code{width}, use
10334
474c8240 10335@smallexample
c906108c 10336(@value{GDBP}) set var width=47
474c8240 10337@end smallexample
53a5351d 10338
c906108c
SS
10339Because the @code{set} command has many subcommands that can conflict
10340with the names of program variables, it is a good idea to use the
10341@code{set variable} command instead of just @code{set}. For example, if
10342your program has a variable @code{g}, you run into problems if you try
10343to set a new value with just @samp{set g=4}, because @value{GDBN} has
10344the command @code{set gnutarget}, abbreviated @code{set g}:
10345
474c8240 10346@smallexample
c906108c
SS
10347@group
10348(@value{GDBP}) whatis g
10349type = double
10350(@value{GDBP}) p g
10351$1 = 1
10352(@value{GDBP}) set g=4
2df3850c 10353(@value{GDBP}) p g
c906108c
SS
10354$2 = 1
10355(@value{GDBP}) r
10356The program being debugged has been started already.
10357Start it from the beginning? (y or n) y
10358Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
10359"/home/smith/cc_progs/a.out": can't open to read symbols:
10360 Invalid bfd target.
c906108c
SS
10361(@value{GDBP}) show g
10362The current BFD target is "=4".
10363@end group
474c8240 10364@end smallexample
c906108c
SS
10365
10366@noindent
10367The program variable @code{g} did not change, and you silently set the
10368@code{gnutarget} to an invalid value. In order to set the variable
10369@code{g}, use
10370
474c8240 10371@smallexample
c906108c 10372(@value{GDBP}) set var g=4
474c8240 10373@end smallexample
c906108c
SS
10374
10375@value{GDBN} allows more implicit conversions in assignments than C; you can
10376freely store an integer value into a pointer variable or vice versa,
10377and you can convert any structure to any other structure that is the
10378same length or shorter.
10379@comment FIXME: how do structs align/pad in these conversions?
10380@comment /doc@cygnus.com 18dec1990
10381
10382To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
10383construct to generate a value of specified type at a specified address
10384(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
10385to memory location @code{0x83040} as an integer (which implies a certain size
10386and representation in memory), and
10387
474c8240 10388@smallexample
c906108c 10389set @{int@}0x83040 = 4
474c8240 10390@end smallexample
c906108c
SS
10391
10392@noindent
10393stores the value 4 into that memory location.
10394
6d2ebf8b 10395@node Jumping
c906108c
SS
10396@section Continuing at a different address
10397
10398Ordinarily, when you continue your program, you do so at the place where
10399it stopped, with the @code{continue} command. You can instead continue at
10400an address of your own choosing, with the following commands:
10401
10402@table @code
10403@kindex jump
10404@item jump @var{linespec}
10405Resume execution at line @var{linespec}. Execution stops again
10406immediately if there is a breakpoint there. @xref{List, ,Printing
10407source lines}, for a description of the different forms of
10408@var{linespec}. It is common practice to use the @code{tbreak} command
10409in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
10410breakpoints}.
10411
10412The @code{jump} command does not change the current stack frame, or
10413the stack pointer, or the contents of any memory location or any
10414register other than the program counter. If line @var{linespec} is in
10415a different function from the one currently executing, the results may
10416be bizarre if the two functions expect different patterns of arguments or
10417of local variables. For this reason, the @code{jump} command requests
10418confirmation if the specified line is not in the function currently
10419executing. However, even bizarre results are predictable if you are
10420well acquainted with the machine-language code of your program.
10421
10422@item jump *@var{address}
10423Resume execution at the instruction at address @var{address}.
10424@end table
10425
c906108c 10426@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
10427On many systems, you can get much the same effect as the @code{jump}
10428command by storing a new value into the register @code{$pc}. The
10429difference is that this does not start your program running; it only
10430changes the address of where it @emph{will} run when you continue. For
10431example,
c906108c 10432
474c8240 10433@smallexample
c906108c 10434set $pc = 0x485
474c8240 10435@end smallexample
c906108c
SS
10436
10437@noindent
10438makes the next @code{continue} command or stepping command execute at
10439address @code{0x485}, rather than at the address where your program stopped.
10440@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
10441
10442The most common occasion to use the @code{jump} command is to back
10443up---perhaps with more breakpoints set---over a portion of a program
10444that has already executed, in order to examine its execution in more
10445detail.
10446
c906108c 10447@c @group
6d2ebf8b 10448@node Signaling
c906108c 10449@section Giving your program a signal
9c16f35a 10450@cindex deliver a signal to a program
c906108c
SS
10451
10452@table @code
10453@kindex signal
10454@item signal @var{signal}
10455Resume execution where your program stopped, but immediately give it the
10456signal @var{signal}. @var{signal} can be the name or the number of a
10457signal. For example, on many systems @code{signal 2} and @code{signal
10458SIGINT} are both ways of sending an interrupt signal.
10459
10460Alternatively, if @var{signal} is zero, continue execution without
10461giving a signal. This is useful when your program stopped on account of
10462a signal and would ordinary see the signal when resumed with the
10463@code{continue} command; @samp{signal 0} causes it to resume without a
10464signal.
10465
10466@code{signal} does not repeat when you press @key{RET} a second time
10467after executing the command.
10468@end table
10469@c @end group
10470
10471Invoking the @code{signal} command is not the same as invoking the
10472@code{kill} utility from the shell. Sending a signal with @code{kill}
10473causes @value{GDBN} to decide what to do with the signal depending on
10474the signal handling tables (@pxref{Signals}). The @code{signal} command
10475passes the signal directly to your program.
10476
c906108c 10477
6d2ebf8b 10478@node Returning
c906108c
SS
10479@section Returning from a function
10480
10481@table @code
10482@cindex returning from a function
10483@kindex return
10484@item return
10485@itemx return @var{expression}
10486You can cancel execution of a function call with the @code{return}
10487command. If you give an
10488@var{expression} argument, its value is used as the function's return
10489value.
10490@end table
10491
10492When you use @code{return}, @value{GDBN} discards the selected stack frame
10493(and all frames within it). You can think of this as making the
10494discarded frame return prematurely. If you wish to specify a value to
10495be returned, give that value as the argument to @code{return}.
10496
10497This pops the selected stack frame (@pxref{Selection, ,Selecting a
10498frame}), and any other frames inside of it, leaving its caller as the
10499innermost remaining frame. That frame becomes selected. The
10500specified value is stored in the registers used for returning values
10501of functions.
10502
10503The @code{return} command does not resume execution; it leaves the
10504program stopped in the state that would exist if the function had just
10505returned. In contrast, the @code{finish} command (@pxref{Continuing
10506and Stepping, ,Continuing and stepping}) resumes execution until the
10507selected stack frame returns naturally.
10508
6d2ebf8b 10509@node Calling
c906108c
SS
10510@section Calling program functions
10511
f8568604 10512@table @code
c906108c 10513@cindex calling functions
f8568604
EZ
10514@cindex inferior functions, calling
10515@item print @var{expr}
9c16f35a 10516Evaluate the expression @var{expr} and display the resuling value.
f8568604
EZ
10517@var{expr} may include calls to functions in the program being
10518debugged.
10519
c906108c 10520@kindex call
c906108c
SS
10521@item call @var{expr}
10522Evaluate the expression @var{expr} without displaying @code{void}
10523returned values.
c906108c
SS
10524
10525You can use this variant of the @code{print} command if you want to
f8568604
EZ
10526execute a function from your program that does not return anything
10527(a.k.a.@: @dfn{a void function}), but without cluttering the output
10528with @code{void} returned values that @value{GDBN} will otherwise
10529print. If the result is not void, it is printed and saved in the
10530value history.
10531@end table
10532
9c16f35a
EZ
10533It is possible for the function you call via the @code{print} or
10534@code{call} command to generate a signal (e.g., if there's a bug in
10535the function, or if you passed it incorrect arguments). What happens
10536in that case is controlled by the @code{set unwindonsignal} command.
10537
10538@table @code
10539@item set unwindonsignal
10540@kindex set unwindonsignal
10541@cindex unwind stack in called functions
10542@cindex call dummy stack unwinding
10543Set unwinding of the stack if a signal is received while in a function
10544that @value{GDBN} called in the program being debugged. If set to on,
10545@value{GDBN} unwinds the stack it created for the call and restores
10546the context to what it was before the call. If set to off (the
10547default), @value{GDBN} stops in the frame where the signal was
10548received.
10549
10550@item show unwindonsignal
10551@kindex show unwindonsignal
10552Show the current setting of stack unwinding in the functions called by
10553@value{GDBN}.
10554@end table
10555
f8568604
EZ
10556@cindex weak alias functions
10557Sometimes, a function you wish to call is actually a @dfn{weak alias}
10558for another function. In such case, @value{GDBN} might not pick up
10559the type information, including the types of the function arguments,
10560which causes @value{GDBN} to call the inferior function incorrectly.
10561As a result, the called function will function erroneously and may
10562even crash. A solution to that is to use the name of the aliased
10563function instead.
c906108c 10564
6d2ebf8b 10565@node Patching
c906108c 10566@section Patching programs
7a292a7a 10567
c906108c
SS
10568@cindex patching binaries
10569@cindex writing into executables
c906108c 10570@cindex writing into corefiles
c906108c 10571
7a292a7a
SS
10572By default, @value{GDBN} opens the file containing your program's
10573executable code (or the corefile) read-only. This prevents accidental
10574alterations to machine code; but it also prevents you from intentionally
10575patching your program's binary.
c906108c
SS
10576
10577If you'd like to be able to patch the binary, you can specify that
10578explicitly with the @code{set write} command. For example, you might
10579want to turn on internal debugging flags, or even to make emergency
10580repairs.
10581
10582@table @code
10583@kindex set write
10584@item set write on
10585@itemx set write off
7a292a7a
SS
10586If you specify @samp{set write on}, @value{GDBN} opens executable and
10587core files for both reading and writing; if you specify @samp{set write
c906108c
SS
10588off} (the default), @value{GDBN} opens them read-only.
10589
10590If you have already loaded a file, you must load it again (using the
7a292a7a
SS
10591@code{exec-file} or @code{core-file} command) after changing @code{set
10592write}, for your new setting to take effect.
c906108c
SS
10593
10594@item show write
10595@kindex show write
7a292a7a
SS
10596Display whether executable files and core files are opened for writing
10597as well as reading.
c906108c
SS
10598@end table
10599
6d2ebf8b 10600@node GDB Files
c906108c
SS
10601@chapter @value{GDBN} Files
10602
7a292a7a
SS
10603@value{GDBN} needs to know the file name of the program to be debugged,
10604both in order to read its symbol table and in order to start your
10605program. To debug a core dump of a previous run, you must also tell
10606@value{GDBN} the name of the core dump file.
c906108c
SS
10607
10608@menu
10609* Files:: Commands to specify files
5b5d99cf 10610* Separate Debug Files:: Debugging information in separate files
c906108c
SS
10611* Symbol Errors:: Errors reading symbol files
10612@end menu
10613
6d2ebf8b 10614@node Files
c906108c 10615@section Commands to specify files
c906108c 10616
7a292a7a 10617@cindex symbol table
c906108c 10618@cindex core dump file
7a292a7a
SS
10619
10620You may want to specify executable and core dump file names. The usual
10621way to do this is at start-up time, using the arguments to
10622@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
10623Out of @value{GDBN}}).
c906108c
SS
10624
10625Occasionally it is necessary to change to a different file during a
397ca115
EZ
10626@value{GDBN} session. Or you may run @value{GDBN} and forget to
10627specify a file you want to use. Or you are debugging a remote target
10628via @code{gdbserver} (@pxref{Server, file}). In these situations the
10629@value{GDBN} commands to specify new files are useful.
c906108c
SS
10630
10631@table @code
10632@cindex executable file
10633@kindex file
10634@item file @var{filename}
10635Use @var{filename} as the program to be debugged. It is read for its
10636symbols and for the contents of pure memory. It is also the program
10637executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
10638directory and the file is not found in the @value{GDBN} working directory,
10639@value{GDBN} uses the environment variable @code{PATH} as a list of
10640directories to search, just as the shell does when looking for a program
10641to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
10642and your program, using the @code{path} command.
10643
6d2ebf8b 10644On systems with memory-mapped files, an auxiliary file named
c906108c
SS
10645@file{@var{filename}.syms} may hold symbol table information for
10646@var{filename}. If so, @value{GDBN} maps in the symbol table from
10647@file{@var{filename}.syms}, starting up more quickly. See the
10648descriptions of the file options @samp{-mapped} and @samp{-readnow}
7b5ba0cc
EZ
10649(available on the command line, see @ref{File Options, , -readnow},
10650and with the commands @code{file}, @code{symbol-file}, or
10651@code{add-symbol-file}, described below), for more information.
c906108c
SS
10652
10653@item file
10654@code{file} with no argument makes @value{GDBN} discard any information it
10655has on both executable file and the symbol table.
10656
10657@kindex exec-file
10658@item exec-file @r{[} @var{filename} @r{]}
10659Specify that the program to be run (but not the symbol table) is found
10660in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
10661if necessary to locate your program. Omitting @var{filename} means to
10662discard information on the executable file.
10663
10664@kindex symbol-file
10665@item symbol-file @r{[} @var{filename} @r{]}
10666Read symbol table information from file @var{filename}. @code{PATH} is
10667searched when necessary. Use the @code{file} command to get both symbol
10668table and program to run from the same file.
10669
10670@code{symbol-file} with no argument clears out @value{GDBN} information on your
10671program's symbol table.
10672
5d161b24 10673The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
10674of its convenience variables, the value history, and all breakpoints and
10675auto-display expressions. This is because they may contain pointers to
10676the internal data recording symbols and data types, which are part of
10677the old symbol table data being discarded inside @value{GDBN}.
10678
10679@code{symbol-file} does not repeat if you press @key{RET} again after
10680executing it once.
10681
10682When @value{GDBN} is configured for a particular environment, it
10683understands debugging information in whatever format is the standard
10684generated for that environment; you may use either a @sc{gnu} compiler, or
10685other compilers that adhere to the local conventions.
c906108c
SS
10686Best results are usually obtained from @sc{gnu} compilers; for example,
10687using @code{@value{GCC}} you can generate debugging information for
10688optimized code.
c906108c
SS
10689
10690For most kinds of object files, with the exception of old SVR3 systems
10691using COFF, the @code{symbol-file} command does not normally read the
10692symbol table in full right away. Instead, it scans the symbol table
10693quickly to find which source files and which symbols are present. The
10694details are read later, one source file at a time, as they are needed.
10695
10696The purpose of this two-stage reading strategy is to make @value{GDBN}
10697start up faster. For the most part, it is invisible except for
10698occasional pauses while the symbol table details for a particular source
10699file are being read. (The @code{set verbose} command can turn these
10700pauses into messages if desired. @xref{Messages/Warnings, ,Optional
10701warnings and messages}.)
10702
c906108c
SS
10703We have not implemented the two-stage strategy for COFF yet. When the
10704symbol table is stored in COFF format, @code{symbol-file} reads the
10705symbol table data in full right away. Note that ``stabs-in-COFF''
10706still does the two-stage strategy, since the debug info is actually
10707in stabs format.
10708
10709@kindex readnow
10710@cindex reading symbols immediately
10711@cindex symbols, reading immediately
10712@kindex mapped
10713@cindex memory-mapped symbol file
10714@cindex saving symbol table
10715@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10716@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10717You can override the @value{GDBN} two-stage strategy for reading symbol
10718tables by using the @samp{-readnow} option with any of the commands that
10719load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 10720entire symbol table available.
c906108c 10721
c906108c
SS
10722If memory-mapped files are available on your system through the
10723@code{mmap} system call, you can use another option, @samp{-mapped}, to
10724cause @value{GDBN} to write the symbols for your program into a reusable
10725file. Future @value{GDBN} debugging sessions map in symbol information
10726from this auxiliary symbol file (if the program has not changed), rather
10727than spending time reading the symbol table from the executable
10728program. Using the @samp{-mapped} option has the same effect as
10729starting @value{GDBN} with the @samp{-mapped} command-line option.
10730
10731You can use both options together, to make sure the auxiliary symbol
10732file has all the symbol information for your program.
10733
10734The auxiliary symbol file for a program called @var{myprog} is called
10735@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
10736than the corresponding executable), @value{GDBN} always attempts to use
10737it when you debug @var{myprog}; no special options or commands are
10738needed.
10739
10740The @file{.syms} file is specific to the host machine where you run
10741@value{GDBN}. It holds an exact image of the internal @value{GDBN}
10742symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
10743
10744@c FIXME: for now no mention of directories, since this seems to be in
10745@c flux. 13mar1992 status is that in theory GDB would look either in
10746@c current dir or in same dir as myprog; but issues like competing
10747@c GDB's, or clutter in system dirs, mean that in practice right now
10748@c only current dir is used. FFish says maybe a special GDB hierarchy
10749@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
10750@c files.
10751
c906108c 10752@kindex core-file
09d4efe1 10753@item core-file @r{[}@var{filename}@r{]}
4644b6e3 10754@itemx core
c906108c
SS
10755Specify the whereabouts of a core dump file to be used as the ``contents
10756of memory''. Traditionally, core files contain only some parts of the
10757address space of the process that generated them; @value{GDBN} can access the
10758executable file itself for other parts.
10759
10760@code{core-file} with no argument specifies that no core file is
10761to be used.
10762
10763Note that the core file is ignored when your program is actually running
7a292a7a
SS
10764under @value{GDBN}. So, if you have been running your program and you
10765wish to debug a core file instead, you must kill the subprocess in which
10766the program is running. To do this, use the @code{kill} command
c906108c 10767(@pxref{Kill Process, ,Killing the child process}).
c906108c 10768
c906108c
SS
10769@kindex add-symbol-file
10770@cindex dynamic linking
10771@item add-symbol-file @var{filename} @var{address}
10772@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
17d9d558 10773@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
10774The @code{add-symbol-file} command reads additional symbol table
10775information from the file @var{filename}. You would use this command
10776when @var{filename} has been dynamically loaded (by some other means)
10777into the program that is running. @var{address} should be the memory
10778address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
10779this out for itself. You can additionally specify an arbitrary number
10780of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
10781section name and base address for that section. You can specify any
10782@var{address} as an expression.
c906108c
SS
10783
10784The symbol table of the file @var{filename} is added to the symbol table
10785originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
10786@code{add-symbol-file} command any number of times; the new symbol data
10787thus read keeps adding to the old. To discard all old symbol data
10788instead, use the @code{symbol-file} command without any arguments.
c906108c 10789
17d9d558
JB
10790@cindex relocatable object files, reading symbols from
10791@cindex object files, relocatable, reading symbols from
10792@cindex reading symbols from relocatable object files
10793@cindex symbols, reading from relocatable object files
10794@cindex @file{.o} files, reading symbols from
10795Although @var{filename} is typically a shared library file, an
10796executable file, or some other object file which has been fully
10797relocated for loading into a process, you can also load symbolic
10798information from relocatable @file{.o} files, as long as:
10799
10800@itemize @bullet
10801@item
10802the file's symbolic information refers only to linker symbols defined in
10803that file, not to symbols defined by other object files,
10804@item
10805every section the file's symbolic information refers to has actually
10806been loaded into the inferior, as it appears in the file, and
10807@item
10808you can determine the address at which every section was loaded, and
10809provide these to the @code{add-symbol-file} command.
10810@end itemize
10811
10812@noindent
10813Some embedded operating systems, like Sun Chorus and VxWorks, can load
10814relocatable files into an already running program; such systems
10815typically make the requirements above easy to meet. However, it's
10816important to recognize that many native systems use complex link
49efadf5 10817procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
10818assembly, for example) that make the requirements difficult to meet. In
10819general, one cannot assume that using @code{add-symbol-file} to read a
10820relocatable object file's symbolic information will have the same effect
10821as linking the relocatable object file into the program in the normal
10822way.
10823
c906108c
SS
10824@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
10825
10826You can use the @samp{-mapped} and @samp{-readnow} options just as with
10827the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
10828table information for @var{filename}.
10829
c45da7e6
EZ
10830@kindex add-symbol-file-from-memory
10831@cindex @code{syscall DSO}
10832@cindex load symbols from memory
10833@item add-symbol-file-from-memory @var{address}
10834Load symbols from the given @var{address} in a dynamically loaded
10835object file whose image is mapped directly into the inferior's memory.
10836For example, the Linux kernel maps a @code{syscall DSO} into each
10837process's address space; this DSO provides kernel-specific code for
10838some system calls. The argument can be any expression whose
10839evaluation yields the address of the file's shared object file header.
10840For this command to work, you must have used @code{symbol-file} or
10841@code{exec-file} commands in advance.
10842
09d4efe1
EZ
10843@kindex add-shared-symbol-files
10844@kindex assf
10845@item add-shared-symbol-files @var{library-file}
10846@itemx assf @var{library-file}
10847The @code{add-shared-symbol-files} command can currently be used only
10848in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
10849alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
10850@value{GDBN} automatically looks for shared libraries, however if
10851@value{GDBN} does not find yours, you can invoke
10852@code{add-shared-symbol-files}. It takes one argument: the shared
10853library's file name. @code{assf} is a shorthand alias for
10854@code{add-shared-symbol-files}.
c906108c 10855
c906108c 10856@kindex section
09d4efe1
EZ
10857@item section @var{section} @var{addr}
10858The @code{section} command changes the base address of the named
10859@var{section} of the exec file to @var{addr}. This can be used if the
10860exec file does not contain section addresses, (such as in the
10861@code{a.out} format), or when the addresses specified in the file
10862itself are wrong. Each section must be changed separately. The
10863@code{info files} command, described below, lists all the sections and
10864their addresses.
c906108c
SS
10865
10866@kindex info files
10867@kindex info target
10868@item info files
10869@itemx info target
7a292a7a
SS
10870@code{info files} and @code{info target} are synonymous; both print the
10871current target (@pxref{Targets, ,Specifying a Debugging Target}),
10872including the names of the executable and core dump files currently in
10873use by @value{GDBN}, and the files from which symbols were loaded. The
10874command @code{help target} lists all possible targets rather than
10875current ones.
10876
fe95c787
MS
10877@kindex maint info sections
10878@item maint info sections
10879Another command that can give you extra information about program sections
10880is @code{maint info sections}. In addition to the section information
10881displayed by @code{info files}, this command displays the flags and file
10882offset of each section in the executable and core dump files. In addition,
10883@code{maint info sections} provides the following command options (which
10884may be arbitrarily combined):
10885
10886@table @code
10887@item ALLOBJ
10888Display sections for all loaded object files, including shared libraries.
10889@item @var{sections}
6600abed 10890Display info only for named @var{sections}.
fe95c787
MS
10891@item @var{section-flags}
10892Display info only for sections for which @var{section-flags} are true.
10893The section flags that @value{GDBN} currently knows about are:
10894@table @code
10895@item ALLOC
10896Section will have space allocated in the process when loaded.
10897Set for all sections except those containing debug information.
10898@item LOAD
10899Section will be loaded from the file into the child process memory.
10900Set for pre-initialized code and data, clear for @code{.bss} sections.
10901@item RELOC
10902Section needs to be relocated before loading.
10903@item READONLY
10904Section cannot be modified by the child process.
10905@item CODE
10906Section contains executable code only.
6600abed 10907@item DATA
fe95c787
MS
10908Section contains data only (no executable code).
10909@item ROM
10910Section will reside in ROM.
10911@item CONSTRUCTOR
10912Section contains data for constructor/destructor lists.
10913@item HAS_CONTENTS
10914Section is not empty.
10915@item NEVER_LOAD
10916An instruction to the linker to not output the section.
10917@item COFF_SHARED_LIBRARY
10918A notification to the linker that the section contains
10919COFF shared library information.
10920@item IS_COMMON
10921Section contains common symbols.
10922@end table
10923@end table
6763aef9 10924@kindex set trust-readonly-sections
9c16f35a 10925@cindex read-only sections
6763aef9
MS
10926@item set trust-readonly-sections on
10927Tell @value{GDBN} that readonly sections in your object file
6ca652b0 10928really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
10929In that case, @value{GDBN} can fetch values from these sections
10930out of the object file, rather than from the target program.
10931For some targets (notably embedded ones), this can be a significant
10932enhancement to debugging performance.
10933
10934The default is off.
10935
10936@item set trust-readonly-sections off
15110bc3 10937Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
10938the contents of the section might change while the program is running,
10939and must therefore be fetched from the target when needed.
9c16f35a
EZ
10940
10941@item show trust-readonly-sections
10942Show the current setting of trusting readonly sections.
c906108c
SS
10943@end table
10944
10945All file-specifying commands allow both absolute and relative file names
10946as arguments. @value{GDBN} always converts the file name to an absolute file
10947name and remembers it that way.
10948
c906108c 10949@cindex shared libraries
9c16f35a
EZ
10950@value{GDBN} supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
10951and IBM RS/6000 AIX shared libraries.
53a5351d 10952
c906108c
SS
10953@value{GDBN} automatically loads symbol definitions from shared libraries
10954when you use the @code{run} command, or when you examine a core file.
10955(Before you issue the @code{run} command, @value{GDBN} does not understand
10956references to a function in a shared library, however---unless you are
10957debugging a core file).
53a5351d
JM
10958
10959On HP-UX, if the program loads a library explicitly, @value{GDBN}
10960automatically loads the symbols at the time of the @code{shl_load} call.
10961
c906108c
SS
10962@c FIXME: some @value{GDBN} release may permit some refs to undef
10963@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
10964@c FIXME...lib; check this from time to time when updating manual
10965
b7209cb4
FF
10966There are times, however, when you may wish to not automatically load
10967symbol definitions from shared libraries, such as when they are
10968particularly large or there are many of them.
10969
10970To control the automatic loading of shared library symbols, use the
10971commands:
10972
10973@table @code
10974@kindex set auto-solib-add
10975@item set auto-solib-add @var{mode}
10976If @var{mode} is @code{on}, symbols from all shared object libraries
10977will be loaded automatically when the inferior begins execution, you
10978attach to an independently started inferior, or when the dynamic linker
10979informs @value{GDBN} that a new library has been loaded. If @var{mode}
10980is @code{off}, symbols must be loaded manually, using the
10981@code{sharedlibrary} command. The default value is @code{on}.
10982
dcaf7c2c
EZ
10983@cindex memory used for symbol tables
10984If your program uses lots of shared libraries with debug info that
10985takes large amounts of memory, you can decrease the @value{GDBN}
10986memory footprint by preventing it from automatically loading the
10987symbols from shared libraries. To that end, type @kbd{set
10988auto-solib-add off} before running the inferior, then load each
10989library whose debug symbols you do need with @kbd{sharedlibrary
10990@var{regexp}}, where @var{regexp} is a regular expresion that matches
10991the libraries whose symbols you want to be loaded.
10992
b7209cb4
FF
10993@kindex show auto-solib-add
10994@item show auto-solib-add
10995Display the current autoloading mode.
10996@end table
10997
c45da7e6 10998@cindex load shared library
b7209cb4
FF
10999To explicitly load shared library symbols, use the @code{sharedlibrary}
11000command:
11001
c906108c
SS
11002@table @code
11003@kindex info sharedlibrary
11004@kindex info share
11005@item info share
11006@itemx info sharedlibrary
11007Print the names of the shared libraries which are currently loaded.
11008
11009@kindex sharedlibrary
11010@kindex share
11011@item sharedlibrary @var{regex}
11012@itemx share @var{regex}
c906108c
SS
11013Load shared object library symbols for files matching a
11014Unix regular expression.
11015As with files loaded automatically, it only loads shared libraries
11016required by your program for a core file or after typing @code{run}. If
11017@var{regex} is omitted all shared libraries required by your program are
11018loaded.
c45da7e6
EZ
11019
11020@item nosharedlibrary
11021@kindex nosharedlibrary
11022@cindex unload symbols from shared libraries
11023Unload all shared object library symbols. This discards all symbols
11024that have been loaded from all shared libraries. Symbols from shared
11025libraries that were loaded by explicit user requests are not
11026discarded.
c906108c
SS
11027@end table
11028
721c2651
EZ
11029Sometimes you may wish that @value{GDBN} stops and gives you control
11030when any of shared library events happen. Use the @code{set
11031stop-on-solib-events} command for this:
11032
11033@table @code
11034@item set stop-on-solib-events
11035@kindex set stop-on-solib-events
11036This command controls whether @value{GDBN} should give you control
11037when the dynamic linker notifies it about some shared library event.
11038The most common event of interest is loading or unloading of a new
11039shared library.
11040
11041@item show stop-on-solib-events
11042@kindex show stop-on-solib-events
11043Show whether @value{GDBN} stops and gives you control when shared
11044library events happen.
11045@end table
11046
f5ebfba0
DJ
11047Shared libraries are also supported in many cross or remote debugging
11048configurations. A copy of the target's libraries need to be present on the
11049host system; they need to be the same as the target libraries, although the
11050copies on the target can be stripped as long as the copies on the host are
11051not.
11052
11053You need to tell @value{GDBN} where the target libraries are, so that it can
11054load the correct copies---otherwise, it may try to load the host's libraries.
11055@value{GDBN} has two variables to specify the search directories for target
11056libraries.
11057
11058@table @code
11059@kindex set solib-absolute-prefix
11060@item set solib-absolute-prefix @var{path}
11061If this variable is set, @var{path} will be used as a prefix for any
11062absolute shared library paths; many runtime loaders store the absolute
11063paths to the shared library in the target program's memory. If you use
11064@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
11065out in the same way that they are on the target, with e.g.@: a
11066@file{/usr/lib} hierarchy under @var{path}.
11067
11068You can set the default value of @samp{solib-absolute-prefix} by using the
11069configure-time @samp{--with-sysroot} option.
11070
11071@kindex show solib-absolute-prefix
11072@item show solib-absolute-prefix
11073Display the current shared library prefix.
11074
11075@kindex set solib-search-path
11076@item set solib-search-path @var{path}
11077If this variable is set, @var{path} is a colon-separated list of directories
11078to search for shared libraries. @samp{solib-search-path} is used after
11079@samp{solib-absolute-prefix} fails to locate the library, or if the path to
11080the library is relative instead of absolute. If you want to use
11081@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
11082set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
11083@value{GDBN} from finding your host's libraries.
11084
11085@kindex show solib-search-path
11086@item show solib-search-path
11087Display the current shared library search path.
11088@end table
11089
5b5d99cf
JB
11090
11091@node Separate Debug Files
11092@section Debugging Information in Separate Files
11093@cindex separate debugging information files
11094@cindex debugging information in separate files
11095@cindex @file{.debug} subdirectories
11096@cindex debugging information directory, global
11097@cindex global debugging information directory
11098
11099@value{GDBN} allows you to put a program's debugging information in a
11100file separate from the executable itself, in a way that allows
11101@value{GDBN} to find and load the debugging information automatically.
11102Since debugging information can be very large --- sometimes larger
11103than the executable code itself --- some systems distribute debugging
11104information for their executables in separate files, which users can
11105install only when they need to debug a problem.
11106
11107If an executable's debugging information has been extracted to a
11108separate file, the executable should contain a @dfn{debug link} giving
11109the name of the debugging information file (with no directory
11110components), and a checksum of its contents. (The exact form of a
11111debug link is described below.) If the full name of the directory
11112containing the executable is @var{execdir}, and the executable has a
11113debug link that specifies the name @var{debugfile}, then @value{GDBN}
11114will automatically search for the debugging information file in three
11115places:
11116
11117@itemize @bullet
11118@item
11119the directory containing the executable file (that is, it will look
11120for a file named @file{@var{execdir}/@var{debugfile}},
11121@item
11122a subdirectory of that directory named @file{.debug} (that is, the
11123file @file{@var{execdir}/.debug/@var{debugfile}}, and
11124@item
11125a subdirectory of the global debug file directory that includes the
11126executable's full path, and the name from the link (that is, the file
11127@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
11128@var{globaldebugdir} is the global debug file directory, and
11129@var{execdir} has been turned into a relative path).
11130@end itemize
11131@noindent
11132@value{GDBN} checks under each of these names for a debugging
11133information file whose checksum matches that given in the link, and
11134reads the debugging information from the first one it finds.
11135
11136So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
11137which has a link containing the name @file{ls.debug}, and the global
11138debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
11139for debug information in @file{/usr/bin/ls.debug},
11140@file{/usr/bin/.debug/ls.debug}, and
11141@file{/usr/lib/debug/usr/bin/ls.debug}.
11142
11143You can set the global debugging info directory's name, and view the
11144name @value{GDBN} is currently using.
11145
11146@table @code
11147
11148@kindex set debug-file-directory
11149@item set debug-file-directory @var{directory}
11150Set the directory which @value{GDBN} searches for separate debugging
11151information files to @var{directory}.
11152
11153@kindex show debug-file-directory
11154@item show debug-file-directory
11155Show the directory @value{GDBN} searches for separate debugging
11156information files.
11157
11158@end table
11159
11160@cindex @code{.gnu_debuglink} sections
11161@cindex debug links
11162A debug link is a special section of the executable file named
11163@code{.gnu_debuglink}. The section must contain:
11164
11165@itemize
11166@item
11167A filename, with any leading directory components removed, followed by
11168a zero byte,
11169@item
11170zero to three bytes of padding, as needed to reach the next four-byte
11171boundary within the section, and
11172@item
11173a four-byte CRC checksum, stored in the same endianness used for the
11174executable file itself. The checksum is computed on the debugging
11175information file's full contents by the function given below, passing
11176zero as the @var{crc} argument.
11177@end itemize
11178
11179Any executable file format can carry a debug link, as long as it can
11180contain a section named @code{.gnu_debuglink} with the contents
11181described above.
11182
11183The debugging information file itself should be an ordinary
11184executable, containing a full set of linker symbols, sections, and
11185debugging information. The sections of the debugging information file
11186should have the same names, addresses and sizes as the original file,
11187but they need not contain any data --- much like a @code{.bss} section
11188in an ordinary executable.
11189
11190As of December 2002, there is no standard GNU utility to produce
11191separated executable / debugging information file pairs. Ulrich
11192Drepper's @file{elfutils} package, starting with version 0.53,
11193contains a version of the @code{strip} command such that the command
11194@kbd{strip foo -f foo.debug} removes the debugging information from
11195the executable file @file{foo}, places it in the file
11196@file{foo.debug}, and leaves behind a debug link in @file{foo}.
11197
11198Since there are many different ways to compute CRC's (different
11199polynomials, reversals, byte ordering, etc.), the simplest way to
11200describe the CRC used in @code{.gnu_debuglink} sections is to give the
11201complete code for a function that computes it:
11202
4644b6e3 11203@kindex gnu_debuglink_crc32
5b5d99cf
JB
11204@smallexample
11205unsigned long
11206gnu_debuglink_crc32 (unsigned long crc,
11207 unsigned char *buf, size_t len)
11208@{
11209 static const unsigned long crc32_table[256] =
11210 @{
11211 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11212 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11213 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11214 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11215 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11216 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11217 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11218 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11219 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11220 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11221 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11222 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11223 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11224 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11225 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11226 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11227 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11228 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11229 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11230 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11231 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11232 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11233 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11234 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11235 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11236 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11237 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11238 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11239 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11240 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11241 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11242 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11243 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11244 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11245 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11246 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11247 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11248 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11249 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11250 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11251 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11252 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11253 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11254 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11255 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11256 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11257 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11258 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11259 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11260 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11261 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11262 0x2d02ef8d
11263 @};
11264 unsigned char *end;
11265
11266 crc = ~crc & 0xffffffff;
11267 for (end = buf + len; buf < end; ++buf)
11268 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 11269 return ~crc & 0xffffffff;
5b5d99cf
JB
11270@}
11271@end smallexample
11272
11273
6d2ebf8b 11274@node Symbol Errors
c906108c
SS
11275@section Errors reading symbol files
11276
11277While reading a symbol file, @value{GDBN} occasionally encounters problems,
11278such as symbol types it does not recognize, or known bugs in compiler
11279output. By default, @value{GDBN} does not notify you of such problems, since
11280they are relatively common and primarily of interest to people
11281debugging compilers. If you are interested in seeing information
11282about ill-constructed symbol tables, you can either ask @value{GDBN} to print
11283only one message about each such type of problem, no matter how many
11284times the problem occurs; or you can ask @value{GDBN} to print more messages,
11285to see how many times the problems occur, with the @code{set
11286complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
11287messages}).
11288
11289The messages currently printed, and their meanings, include:
11290
11291@table @code
11292@item inner block not inside outer block in @var{symbol}
11293
11294The symbol information shows where symbol scopes begin and end
11295(such as at the start of a function or a block of statements). This
11296error indicates that an inner scope block is not fully contained
11297in its outer scope blocks.
11298
11299@value{GDBN} circumvents the problem by treating the inner block as if it had
11300the same scope as the outer block. In the error message, @var{symbol}
11301may be shown as ``@code{(don't know)}'' if the outer block is not a
11302function.
11303
11304@item block at @var{address} out of order
11305
11306The symbol information for symbol scope blocks should occur in
11307order of increasing addresses. This error indicates that it does not
11308do so.
11309
11310@value{GDBN} does not circumvent this problem, and has trouble
11311locating symbols in the source file whose symbols it is reading. (You
11312can often determine what source file is affected by specifying
11313@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
11314messages}.)
11315
11316@item bad block start address patched
11317
11318The symbol information for a symbol scope block has a start address
11319smaller than the address of the preceding source line. This is known
11320to occur in the SunOS 4.1.1 (and earlier) C compiler.
11321
11322@value{GDBN} circumvents the problem by treating the symbol scope block as
11323starting on the previous source line.
11324
11325@item bad string table offset in symbol @var{n}
11326
11327@cindex foo
11328Symbol number @var{n} contains a pointer into the string table which is
11329larger than the size of the string table.
11330
11331@value{GDBN} circumvents the problem by considering the symbol to have the
11332name @code{foo}, which may cause other problems if many symbols end up
11333with this name.
11334
11335@item unknown symbol type @code{0x@var{nn}}
11336
7a292a7a
SS
11337The symbol information contains new data types that @value{GDBN} does
11338not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 11339uncomprehended information, in hexadecimal.
c906108c 11340
7a292a7a
SS
11341@value{GDBN} circumvents the error by ignoring this symbol information.
11342This usually allows you to debug your program, though certain symbols
c906108c 11343are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
11344debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
11345on @code{complain}, then go up to the function @code{read_dbx_symtab}
11346and examine @code{*bufp} to see the symbol.
c906108c
SS
11347
11348@item stub type has NULL name
c906108c 11349
7a292a7a 11350@value{GDBN} could not find the full definition for a struct or class.
c906108c 11351
7a292a7a 11352@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 11353The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
11354information that recent versions of the compiler should have output for
11355it.
c906108c
SS
11356
11357@item info mismatch between compiler and debugger
11358
11359@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 11360
c906108c
SS
11361@end table
11362
6d2ebf8b 11363@node Targets
c906108c 11364@chapter Specifying a Debugging Target
7a292a7a 11365
c906108c 11366@cindex debugging target
c906108c 11367A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
11368
11369Often, @value{GDBN} runs in the same host environment as your program;
11370in that case, the debugging target is specified as a side effect when
11371you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
11372flexibility---for example, running @value{GDBN} on a physically separate
11373host, or controlling a standalone system over a serial port or a
53a5351d
JM
11374realtime system over a TCP/IP connection---you can use the @code{target}
11375command to specify one of the target types configured for @value{GDBN}
11376(@pxref{Target Commands, ,Commands for managing targets}).
c906108c 11377
a8f24a35
EZ
11378@cindex target architecture
11379It is possible to build @value{GDBN} for several different @dfn{target
11380architectures}. When @value{GDBN} is built like that, you can choose
11381one of the available architectures with the @kbd{set architecture}
11382command.
11383
11384@table @code
11385@kindex set architecture
11386@kindex show architecture
11387@item set architecture @var{arch}
11388This command sets the current target architecture to @var{arch}. The
11389value of @var{arch} can be @code{"auto"}, in addition to one of the
11390supported architectures.
11391
11392@item show architecture
11393Show the current target architecture.
9c16f35a
EZ
11394
11395@item set processor
11396@itemx processor
11397@kindex set processor
11398@kindex show processor
11399These are alias commands for, respectively, @code{set architecture}
11400and @code{show architecture}.
a8f24a35
EZ
11401@end table
11402
c906108c
SS
11403@menu
11404* Active Targets:: Active targets
11405* Target Commands:: Commands for managing targets
c906108c
SS
11406* Byte Order:: Choosing target byte order
11407* Remote:: Remote debugging
96baa820 11408* KOD:: Kernel Object Display
c906108c
SS
11409
11410@end menu
11411
6d2ebf8b 11412@node Active Targets
c906108c 11413@section Active targets
7a292a7a 11414
c906108c
SS
11415@cindex stacking targets
11416@cindex active targets
11417@cindex multiple targets
11418
c906108c 11419There are three classes of targets: processes, core files, and
7a292a7a
SS
11420executable files. @value{GDBN} can work concurrently on up to three
11421active targets, one in each class. This allows you to (for example)
11422start a process and inspect its activity without abandoning your work on
11423a core file.
c906108c
SS
11424
11425For example, if you execute @samp{gdb a.out}, then the executable file
11426@code{a.out} is the only active target. If you designate a core file as
11427well---presumably from a prior run that crashed and coredumped---then
11428@value{GDBN} has two active targets and uses them in tandem, looking
11429first in the corefile target, then in the executable file, to satisfy
11430requests for memory addresses. (Typically, these two classes of target
11431are complementary, since core files contain only a program's
11432read-write memory---variables and so on---plus machine status, while
11433executable files contain only the program text and initialized data.)
c906108c
SS
11434
11435When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
11436target as well. When a process target is active, all @value{GDBN}
11437commands requesting memory addresses refer to that target; addresses in
11438an active core file or executable file target are obscured while the
11439process target is active.
c906108c 11440
7a292a7a
SS
11441Use the @code{core-file} and @code{exec-file} commands to select a new
11442core file or executable target (@pxref{Files, ,Commands to specify
c906108c 11443files}). To specify as a target a process that is already running, use
7a292a7a
SS
11444the @code{attach} command (@pxref{Attach, ,Debugging an already-running
11445process}).
c906108c 11446
6d2ebf8b 11447@node Target Commands
c906108c
SS
11448@section Commands for managing targets
11449
11450@table @code
11451@item target @var{type} @var{parameters}
7a292a7a
SS
11452Connects the @value{GDBN} host environment to a target machine or
11453process. A target is typically a protocol for talking to debugging
11454facilities. You use the argument @var{type} to specify the type or
11455protocol of the target machine.
c906108c
SS
11456
11457Further @var{parameters} are interpreted by the target protocol, but
11458typically include things like device names or host names to connect
11459with, process numbers, and baud rates.
c906108c
SS
11460
11461The @code{target} command does not repeat if you press @key{RET} again
11462after executing the command.
11463
11464@kindex help target
11465@item help target
11466Displays the names of all targets available. To display targets
11467currently selected, use either @code{info target} or @code{info files}
11468(@pxref{Files, ,Commands to specify files}).
11469
11470@item help target @var{name}
11471Describe a particular target, including any parameters necessary to
11472select it.
11473
11474@kindex set gnutarget
11475@item set gnutarget @var{args}
5d161b24 11476@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 11477knows whether it is reading an @dfn{executable},
5d161b24
DB
11478a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
11479with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
11480with @code{gnutarget} the @code{target} refers to a program, not a machine.
11481
d4f3574e 11482@quotation
c906108c
SS
11483@emph{Warning:} To specify a file format with @code{set gnutarget},
11484you must know the actual BFD name.
d4f3574e 11485@end quotation
c906108c 11486
d4f3574e
SS
11487@noindent
11488@xref{Files, , Commands to specify files}.
c906108c 11489
5d161b24 11490@kindex show gnutarget
c906108c
SS
11491@item show gnutarget
11492Use the @code{show gnutarget} command to display what file format
11493@code{gnutarget} is set to read. If you have not set @code{gnutarget},
11494@value{GDBN} will determine the file format for each file automatically,
11495and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11496@end table
11497
4644b6e3 11498@cindex common targets
c906108c
SS
11499Here are some common targets (available, or not, depending on the GDB
11500configuration):
c906108c
SS
11501
11502@table @code
4644b6e3 11503@kindex target
c906108c 11504@item target exec @var{program}
4644b6e3 11505@cindex executable file target
c906108c
SS
11506An executable file. @samp{target exec @var{program}} is the same as
11507@samp{exec-file @var{program}}.
11508
c906108c 11509@item target core @var{filename}
4644b6e3 11510@cindex core dump file target
c906108c
SS
11511A core dump file. @samp{target core @var{filename}} is the same as
11512@samp{core-file @var{filename}}.
c906108c 11513
c906108c 11514@item target remote @var{dev}
4644b6e3 11515@cindex remote target
c906108c
SS
11516Remote serial target in GDB-specific protocol. The argument @var{dev}
11517specifies what serial device to use for the connection (e.g.
11518@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 11519supports the @code{load} command. This is only useful if you have
c906108c
SS
11520some other way of getting the stub to the target system, and you can put
11521it somewhere in memory where it won't get clobbered by the download.
11522
c906108c 11523@item target sim
4644b6e3 11524@cindex built-in simulator target
2df3850c 11525Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 11526In general,
474c8240 11527@smallexample
104c1213
JM
11528 target sim
11529 load
11530 run
474c8240 11531@end smallexample
d4f3574e 11532@noindent
104c1213 11533works; however, you cannot assume that a specific memory map, device
d4f3574e 11534drivers, or even basic I/O is available, although some simulators do
104c1213
JM
11535provide these. For info about any processor-specific simulator details,
11536see the appropriate section in @ref{Embedded Processors, ,Embedded
11537Processors}.
11538
c906108c
SS
11539@end table
11540
104c1213 11541Some configurations may include these targets as well:
c906108c
SS
11542
11543@table @code
11544
c906108c 11545@item target nrom @var{dev}
4644b6e3 11546@cindex NetROM ROM emulator target
c906108c
SS
11547NetROM ROM emulator. This target only supports downloading.
11548
c906108c
SS
11549@end table
11550
5d161b24 11551Different targets are available on different configurations of @value{GDBN};
c906108c 11552your configuration may have more or fewer targets.
c906108c 11553
721c2651
EZ
11554Many remote targets require you to download the executable's code once
11555you've successfully established a connection. You may wish to control
11556various aspects of this process, such as the size of the data chunks
11557used by @value{GDBN} to download program parts to the remote target.
a8f24a35
EZ
11558
11559@table @code
11560@kindex set download-write-size
11561@item set download-write-size @var{size}
11562Set the write size used when downloading a program. Only used when
11563downloading a program onto a remote target. Specify zero or a
11564negative value to disable blocked writes. The actual size of each
11565transfer is also limited by the size of the target packet and the
11566memory cache.
11567
11568@kindex show download-write-size
11569@item show download-write-size
721c2651 11570@kindex show download-write-size
a8f24a35 11571Show the current value of the write size.
721c2651
EZ
11572
11573@item set hash
11574@kindex set hash@r{, for remote monitors}
11575@cindex hash mark while downloading
11576This command controls whether a hash mark @samp{#} is displayed while
11577downloading a file to the remote monitor. If on, a hash mark is
11578displayed after each S-record is successfully downloaded to the
11579monitor.
11580
11581@item show hash
11582@kindex show hash@r{, for remote monitors}
11583Show the current status of displaying the hash mark.
11584
11585@item set debug monitor
11586@kindex set debug monitor
11587@cindex display remote monitor communications
11588Enable or disable display of communications messages between
11589@value{GDBN} and the remote monitor.
11590
11591@item show debug monitor
11592@kindex show debug monitor
11593Show the current status of displaying communications between
11594@value{GDBN} and the remote monitor.
a8f24a35 11595@end table
c906108c
SS
11596
11597@table @code
11598
11599@kindex load @var{filename}
11600@item load @var{filename}
c906108c
SS
11601Depending on what remote debugging facilities are configured into
11602@value{GDBN}, the @code{load} command may be available. Where it exists, it
11603is meant to make @var{filename} (an executable) available for debugging
11604on the remote system---by downloading, or dynamic linking, for example.
11605@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
11606the @code{add-symbol-file} command.
11607
11608If your @value{GDBN} does not have a @code{load} command, attempting to
11609execute it gets the error message ``@code{You can't do that when your
11610target is @dots{}}''
c906108c
SS
11611
11612The file is loaded at whatever address is specified in the executable.
11613For some object file formats, you can specify the load address when you
11614link the program; for other formats, like a.out, the object file format
11615specifies a fixed address.
11616@c FIXME! This would be a good place for an xref to the GNU linker doc.
11617
c906108c
SS
11618@code{load} does not repeat if you press @key{RET} again after using it.
11619@end table
11620
6d2ebf8b 11621@node Byte Order
c906108c 11622@section Choosing target byte order
7a292a7a 11623
c906108c
SS
11624@cindex choosing target byte order
11625@cindex target byte order
c906108c 11626
172c2a43 11627Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
11628offer the ability to run either big-endian or little-endian byte
11629orders. Usually the executable or symbol will include a bit to
11630designate the endian-ness, and you will not need to worry about
11631which to use. However, you may still find it useful to adjust
d4f3574e 11632@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
11633
11634@table @code
4644b6e3 11635@kindex set endian
c906108c
SS
11636@item set endian big
11637Instruct @value{GDBN} to assume the target is big-endian.
11638
c906108c
SS
11639@item set endian little
11640Instruct @value{GDBN} to assume the target is little-endian.
11641
c906108c
SS
11642@item set endian auto
11643Instruct @value{GDBN} to use the byte order associated with the
11644executable.
11645
11646@item show endian
11647Display @value{GDBN}'s current idea of the target byte order.
11648
11649@end table
11650
11651Note that these commands merely adjust interpretation of symbolic
11652data on the host, and that they have absolutely no effect on the
11653target system.
11654
6d2ebf8b 11655@node Remote
c906108c
SS
11656@section Remote debugging
11657@cindex remote debugging
11658
11659If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
11660@value{GDBN} in the usual way, it is often useful to use remote debugging.
11661For example, you might use remote debugging on an operating system kernel,
c906108c
SS
11662or on a small system which does not have a general purpose operating system
11663powerful enough to run a full-featured debugger.
11664
11665Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
11666to make this work with particular debugging targets. In addition,
5d161b24 11667@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
11668but not specific to any particular target system) which you can use if you
11669write the remote stubs---the code that runs on the remote system to
11670communicate with @value{GDBN}.
11671
11672Other remote targets may be available in your
11673configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 11674
c45da7e6
EZ
11675Once you've connected to the remote target, @value{GDBN} allows you to
11676send arbitrary commands to the remote monitor:
11677
11678@table @code
11679@item remote @var{command}
11680@kindex remote@r{, a command}
11681@cindex send command to remote monitor
11682Send an arbitrary @var{command} string to the remote monitor.
11683@end table
11684
11685
6f05cf9f
AC
11686@node KOD
11687@section Kernel Object Display
6f05cf9f 11688@cindex kernel object display
6f05cf9f
AC
11689@cindex KOD
11690
11691Some targets support kernel object display. Using this facility,
11692@value{GDBN} communicates specially with the underlying operating system
11693and can display information about operating system-level objects such as
11694mutexes and other synchronization objects. Exactly which objects can be
11695displayed is determined on a per-OS basis.
11696
3bbe9696 11697@kindex set os
6f05cf9f
AC
11698Use the @code{set os} command to set the operating system. This tells
11699@value{GDBN} which kernel object display module to initialize:
11700
474c8240 11701@smallexample
6f05cf9f 11702(@value{GDBP}) set os cisco
474c8240 11703@end smallexample
6f05cf9f 11704
3bbe9696
EZ
11705@kindex show os
11706The associated command @code{show os} displays the operating system
11707set with the @code{set os} command; if no operating system has been
11708set, @code{show os} will display an empty string @samp{""}.
11709
6f05cf9f
AC
11710If @code{set os} succeeds, @value{GDBN} will display some information
11711about the operating system, and will create a new @code{info} command
11712which can be used to query the target. The @code{info} command is named
11713after the operating system:
c906108c 11714
3bbe9696 11715@kindex info cisco
474c8240 11716@smallexample
6f05cf9f
AC
11717(@value{GDBP}) info cisco
11718List of Cisco Kernel Objects
11719Object Description
11720any Any and all objects
474c8240 11721@end smallexample
6f05cf9f
AC
11722
11723Further subcommands can be used to query about particular objects known
11724by the kernel.
11725
3bbe9696
EZ
11726There is currently no way to determine whether a given operating
11727system is supported other than to try setting it with @kbd{set os
11728@var{name}}, where @var{name} is the name of the operating system you
11729want to try.
6f05cf9f
AC
11730
11731
11732@node Remote Debugging
11733@chapter Debugging remote programs
11734
6b2f586d 11735@menu
07f31aa6 11736* Connecting:: Connecting to a remote target
6b2f586d
AC
11737* Server:: Using the gdbserver program
11738* NetWare:: Using the gdbserve.nlm program
501eef12 11739* Remote configuration:: Remote configuration
6b2f586d 11740* remote stub:: Implementing a remote stub
6b2f586d
AC
11741@end menu
11742
07f31aa6
DJ
11743@node Connecting
11744@section Connecting to a remote target
11745
11746On the @value{GDBN} host machine, you will need an unstripped copy of
11747your program, since @value{GDBN} needs symobl and debugging information.
11748Start up @value{GDBN} as usual, using the name of the local copy of your
11749program as the first argument.
11750
11751@cindex serial line, @code{target remote}
11752If you're using a serial line, you may want to give @value{GDBN} the
11753@w{@samp{--baud}} option, or use the @code{set remotebaud} command
9c16f35a
EZ
11754(@pxref{Remote configuration, set remotebaud}) before the
11755@code{target} command.
07f31aa6
DJ
11756
11757After that, use @code{target remote} to establish communications with
11758the target machine. Its argument specifies how to communicate---either
11759via a devicename attached to a direct serial line, or a TCP or UDP port
11760(possibly to a terminal server which in turn has a serial line to the
11761target). For example, to use a serial line connected to the device
11762named @file{/dev/ttyb}:
11763
11764@smallexample
11765target remote /dev/ttyb
11766@end smallexample
11767
11768@cindex TCP port, @code{target remote}
11769To use a TCP connection, use an argument of the form
11770@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
11771For example, to connect to port 2828 on a
11772terminal server named @code{manyfarms}:
11773
11774@smallexample
11775target remote manyfarms:2828
11776@end smallexample
11777
11778If your remote target is actually running on the same machine as
11779your debugger session (e.g.@: a simulator of your target running on
11780the same host), you can omit the hostname. For example, to connect
11781to port 1234 on your local machine:
11782
11783@smallexample
11784target remote :1234
11785@end smallexample
11786@noindent
11787
11788Note that the colon is still required here.
11789
11790@cindex UDP port, @code{target remote}
11791To use a UDP connection, use an argument of the form
11792@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
11793on a terminal server named @code{manyfarms}:
11794
11795@smallexample
11796target remote udp:manyfarms:2828
11797@end smallexample
11798
11799When using a UDP connection for remote debugging, you should keep in mind
11800that the `U' stands for ``Unreliable''. UDP can silently drop packets on
11801busy or unreliable networks, which will cause havoc with your debugging
11802session.
11803
11804Now you can use all the usual commands to examine and change data and to
11805step and continue the remote program.
11806
11807@cindex interrupting remote programs
11808@cindex remote programs, interrupting
11809Whenever @value{GDBN} is waiting for the remote program, if you type the
11810interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
11811program. This may or may not succeed, depending in part on the hardware
11812and the serial drivers the remote system uses. If you type the
11813interrupt character once again, @value{GDBN} displays this prompt:
11814
11815@smallexample
11816Interrupted while waiting for the program.
11817Give up (and stop debugging it)? (y or n)
11818@end smallexample
11819
11820If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
11821(If you decide you want to try again later, you can use @samp{target
11822remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
11823goes back to waiting.
11824
11825@table @code
11826@kindex detach (remote)
11827@item detach
11828When you have finished debugging the remote program, you can use the
11829@code{detach} command to release it from @value{GDBN} control.
11830Detaching from the target normally resumes its execution, but the results
11831will depend on your particular remote stub. After the @code{detach}
11832command, @value{GDBN} is free to connect to another target.
11833
11834@kindex disconnect
11835@item disconnect
11836The @code{disconnect} command behaves like @code{detach}, except that
11837the target is generally not resumed. It will wait for @value{GDBN}
11838(this instance or another one) to connect and continue debugging. After
11839the @code{disconnect} command, @value{GDBN} is again free to connect to
11840another target.
09d4efe1
EZ
11841
11842@cindex send command to remote monitor
11843@kindex monitor
11844@item monitor @var{cmd}
11845This command allows you to send commands directly to the remote
11846monitor.
07f31aa6
DJ
11847@end table
11848
6f05cf9f
AC
11849@node Server
11850@section Using the @code{gdbserver} program
11851
11852@kindex gdbserver
11853@cindex remote connection without stubs
11854@code{gdbserver} is a control program for Unix-like systems, which
11855allows you to connect your program with a remote @value{GDBN} via
11856@code{target remote}---but without linking in the usual debugging stub.
11857
11858@code{gdbserver} is not a complete replacement for the debugging stubs,
11859because it requires essentially the same operating-system facilities
11860that @value{GDBN} itself does. In fact, a system that can run
11861@code{gdbserver} to connect to a remote @value{GDBN} could also run
11862@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
11863because it is a much smaller program than @value{GDBN} itself. It is
11864also easier to port than all of @value{GDBN}, so you may be able to get
11865started more quickly on a new system by using @code{gdbserver}.
11866Finally, if you develop code for real-time systems, you may find that
11867the tradeoffs involved in real-time operation make it more convenient to
11868do as much development work as possible on another system, for example
11869by cross-compiling. You can use @code{gdbserver} to make a similar
11870choice for debugging.
11871
11872@value{GDBN} and @code{gdbserver} communicate via either a serial line
11873or a TCP connection, using the standard @value{GDBN} remote serial
11874protocol.
11875
11876@table @emph
11877@item On the target machine,
11878you need to have a copy of the program you want to debug.
11879@code{gdbserver} does not need your program's symbol table, so you can
11880strip the program if necessary to save space. @value{GDBN} on the host
11881system does all the symbol handling.
11882
11883To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 11884the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
11885syntax is:
11886
11887@smallexample
11888target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
11889@end smallexample
11890
11891@var{comm} is either a device name (to use a serial line) or a TCP
11892hostname and portnumber. For example, to debug Emacs with the argument
11893@samp{foo.txt} and communicate with @value{GDBN} over the serial port
11894@file{/dev/com1}:
11895
11896@smallexample
11897target> gdbserver /dev/com1 emacs foo.txt
11898@end smallexample
11899
11900@code{gdbserver} waits passively for the host @value{GDBN} to communicate
11901with it.
11902
11903To use a TCP connection instead of a serial line:
11904
11905@smallexample
11906target> gdbserver host:2345 emacs foo.txt
11907@end smallexample
11908
11909The only difference from the previous example is the first argument,
11910specifying that you are communicating with the host @value{GDBN} via
11911TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
11912expect a TCP connection from machine @samp{host} to local TCP port 2345.
11913(Currently, the @samp{host} part is ignored.) You can choose any number
11914you want for the port number as long as it does not conflict with any
11915TCP ports already in use on the target system (for example, @code{23} is
11916reserved for @code{telnet}).@footnote{If you choose a port number that
11917conflicts with another service, @code{gdbserver} prints an error message
11918and exits.} You must use the same port number with the host @value{GDBN}
11919@code{target remote} command.
11920
56460a61
DJ
11921On some targets, @code{gdbserver} can also attach to running programs.
11922This is accomplished via the @code{--attach} argument. The syntax is:
11923
11924@smallexample
11925target> gdbserver @var{comm} --attach @var{pid}
11926@end smallexample
11927
11928@var{pid} is the process ID of a currently running process. It isn't necessary
11929to point @code{gdbserver} at a binary for the running process.
11930
b1fe9455
DJ
11931@pindex pidof
11932@cindex attach to a program by name
11933You can debug processes by name instead of process ID if your target has the
11934@code{pidof} utility:
11935
11936@smallexample
11937target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
11938@end smallexample
11939
11940In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
11941has multiple threads, most versions of @code{pidof} support the
11942@code{-s} option to only return the first process ID.
11943
07f31aa6
DJ
11944@item On the host machine,
11945connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
11946For TCP connections, you must start up @code{gdbserver} prior to using
11947the @code{target remote} command. Otherwise you may get an error whose
11948text depends on the host system, but which usually looks something like
07f31aa6 11949@samp{Connection refused}. You don't need to use the @code{load}
397ca115
EZ
11950command in @value{GDBN} when using @code{gdbserver}, since the program is
11951already on the target. However, if you want to load the symbols (as
11952you normally would), do that with the @code{file} command, and issue
11953it @emph{before} connecting to the server; otherwise, you will get an
11954error message saying @code{"Program is already running"}, since the
11955program is considered running after the connection.
07f31aa6 11956
6f05cf9f
AC
11957@end table
11958
11959@node NetWare
11960@section Using the @code{gdbserve.nlm} program
11961
11962@kindex gdbserve.nlm
11963@code{gdbserve.nlm} is a control program for NetWare systems, which
11964allows you to connect your program with a remote @value{GDBN} via
11965@code{target remote}.
11966
11967@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
11968using the standard @value{GDBN} remote serial protocol.
11969
11970@table @emph
11971@item On the target machine,
11972you need to have a copy of the program you want to debug.
11973@code{gdbserve.nlm} does not need your program's symbol table, so you
11974can strip the program if necessary to save space. @value{GDBN} on the
11975host system does all the symbol handling.
11976
11977To use the server, you must tell it how to communicate with
11978@value{GDBN}; the name of your program; and the arguments for your
11979program. The syntax is:
11980
11981@smallexample
11982load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
11983 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
11984@end smallexample
11985
11986@var{board} and @var{port} specify the serial line; @var{baud} specifies
11987the baud rate used by the connection. @var{port} and @var{node} default
11988to 0, @var{baud} defaults to 9600@dmn{bps}.
11989
11990For example, to debug Emacs with the argument @samp{foo.txt}and
11991communicate with @value{GDBN} over serial port number 2 or board 1
11992using a 19200@dmn{bps} connection:
11993
11994@smallexample
11995load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
11996@end smallexample
11997
07f31aa6
DJ
11998@item
11999On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
12000Connecting to a remote target}).
6f05cf9f 12001
6f05cf9f
AC
12002@end table
12003
501eef12
AC
12004@node Remote configuration
12005@section Remote configuration
12006
9c16f35a
EZ
12007@kindex set remote
12008@kindex show remote
12009This section documents the configuration options available when
12010debugging remote programs. For the options related to the File I/O
12011extensions of the remote protocol, see @ref{The system call,
12012system-call-allowed}.
501eef12
AC
12013
12014@table @code
9c16f35a
EZ
12015@item set remoteaddresssize @var{bits}
12016@cindex adress size for remote targets
12017@cindex bits in remote address
12018Set the maximum size of address in a memory packet to the specified
12019number of bits. @value{GDBN} will mask off the address bits above
12020that number, when it passes addresses to the remote target. The
12021default value is the number of bits in the target's address.
12022
12023@item show remoteaddresssize
12024Show the current value of remote address size in bits.
12025
12026@item set remotebaud @var{n}
12027@cindex baud rate for remote targets
12028Set the baud rate for the remote serial I/O to @var{n} baud. The
12029value is used to set the speed of the serial port used for debugging
12030remote targets.
12031
12032@item show remotebaud
12033Show the current speed of the remote connection.
12034
12035@item set remotebreak
12036@cindex interrupt remote programs
12037@cindex BREAK signal instead of Ctrl-C
12038If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
12039when you press the @key{Ctrl-C} key to interrupt the program running
12040on the remote. If set to off, @value{GDBN} sends the @samp{Strl-C}
12041character instead. The default is off, since most remote systems
12042expect to see @samp{Ctrl-C} as the interrupt signal.
12043
12044@item show remotebreak
12045Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
12046interrupt the remote program.
12047
12048@item set remotedebug
12049@cindex debug remote protocol
12050@cindex remote protocol debugging
12051@cindex display remote packets
12052Control the debugging of the remote protocol. When enabled, each
12053packet sent to or received from the remote target is displayed. The
12054defaults is off.
12055
12056@item show remotedebug
12057Show the current setting of the remote protocol debugging.
12058
12059@item set remotedevice @var{device}
12060@cindex serial port name
12061Set the name of the serial port through which to communicate to the
12062remote target to @var{device}. This is the device used by
12063@value{GDBN} to open the serial communications line to the remote
12064target. There's no default, so you must set a valid port name for the
12065remote serial communications to work. (Some varieties of the
12066@code{target} command accept the port name as part of their
12067arguments.)
12068
12069@item show remotedevice
12070Show the current name of the serial port.
12071
12072@item set remotelogbase @var{base}
12073Set the base (a.k.a.@: radix) of logging serial protocol
12074communications to @var{base}. Supported values of @var{base} are:
12075@code{ascii}, @code{octal}, and @code{hex}. The default is
12076@code{ascii}.
12077
12078@item show remotelogbase
12079Show the current setting of the radix for logging remote serial
12080protocol.
12081
12082@item set remotelogfile @var{file}
12083@cindex record serial communications on file
12084Record remote serial communications on the named @var{file}. The
12085default is not to record at all.
12086
12087@item show remotelogfile.
12088Show the current setting of the file name on which to record the
12089serial communications.
12090
12091@item set remotetimeout @var{num}
12092@cindex timeout for serial communications
12093@cindex remote timeout
12094Set the timeout limit to wait for the remote target to respond to
12095@var{num} seconds. The default is 2 seconds.
12096
12097@item show remotetimeout
12098Show the current number of seconds to wait for the remote target
12099responses.
12100
12101@cindex limit hardware breakpoints and watchpoints
12102@cindex remote target, limit break- and watchpoints
501eef12
AC
12103@anchor{set remote hardware-watchpoint-limit}
12104@anchor{set remote hardware-breakpoint-limit}
12105@item set remote hardware-watchpoint-limit @var{limit}
12106@itemx set remote hardware-breakpoint-limit @var{limit}
12107Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
12108watchpoints. A limit of -1, the default, is treated as unlimited.
9c16f35a
EZ
12109
12110@item set remote fetch-register-packet
12111@itemx set remote set-register-packet
12112@itemx set remote P-packet
12113@itemx set remote p-packet
12114@cindex P-packet
12115@cindex fetch registers from remote targets
12116@cindex set registers in remote targets
12117Determine whether @value{GDBN} can set and fetch registers from the
12118remote target using the @samp{P} packets. The default depends on the
12119remote stub's support of the @samp{P} packets (@value{GDBN} queries
12120the stub when this packet is first required).
12121
12122@item show remote fetch-register-packet
12123@itemx show remote set-register-packet
12124@itemx show remote P-packet
12125@itemx show remote p-packet
12126Show the current setting of using the @samp{P} packets for setting and
12127fetching registers from the remote target.
12128
12129@cindex binary downloads
12130@cindex X-packet
12131@item set remote binary-download-packet
12132@itemx set remote X-packet
12133Determine whether @value{GDBN} sends downloads in binary mode using
12134the @samp{X} packets. The default is on.
12135
12136@item show remote binary-download-packet
12137@itemx show remote X-packet
12138Show the current setting of using the @samp{X} packets for binary
12139downloads.
12140
12141@item set remote read-aux-vector-packet
12142@cindex auxiliary vector of remote target
12143@cindex @code{auxv}, and remote targets
12144Set the use of the remote protocol's @samp{qPart:auxv:read} (target
12145auxiliary vector read) request. This request is used to fetch the
721c2651
EZ
12146remote target's @dfn{auxiliary vector}, see @ref{OS Information,
12147Auxiliary Vector}. The default setting depends on the remote stub's
12148support of this request (@value{GDBN} queries the stub when this
12149request is first required). @xref{General Query Packets, qPart}, for
12150more information about this request.
9c16f35a
EZ
12151
12152@item show remote read-aux-vector-packet
12153Show the current setting of use of the @samp{qPart:auxv:read} request.
12154
12155@item set remote symbol-lookup-packet
12156@cindex remote symbol lookup request
12157Set the use of the remote protocol's @samp{qSymbol} (target symbol
12158lookup) request. This request is used to communicate symbol
12159information to the remote target, e.g., whenever a new shared library
12160is loaded by the remote (@pxref{Files, shared libraries}). The
12161default setting depends on the remote stub's support of this request
12162(@value{GDBN} queries the stub when this request is first required).
12163@xref{General Query Packets, qSymbol}, for more information about this
12164request.
12165
12166@item show remote symbol-lookup-packet
12167Show the current setting of use of the @samp{qSymbol} request.
12168
12169@item set remote verbose-resume-packet
12170@cindex resume remote target
12171@cindex signal thread, and remote targets
12172@cindex single-step thread, and remote targets
12173@cindex thread-specific operations on remote targets
12174Set the use of the remote protocol's @samp{vCont} (descriptive resume)
12175request. This request is used to resume specific threads in the
12176remote target, and to single-step or signal them. The default setting
12177depends on the remote stub's support of this request (@value{GDBN}
12178queries the stub when this request is first required). This setting
12179affects debugging of multithreaded programs: if @samp{vCont} cannot be
12180used, @value{GDBN} might be unable to single-step a specific thread,
12181especially under @code{set scheduler-locking off}; it is also
12182impossible to pause a specific thread. @xref{Packets, vCont}, for
12183more details.
12184
12185@item show remote verbose-resume-packet
12186Show the current setting of use of the @samp{vCont} request
12187
12188@item set remote software-breakpoint-packet
12189@itemx set remote hardware-breakpoint-packet
12190@itemx set remote write-watchpoint-packet
12191@itemx set remote read-watchpoint-packet
12192@itemx set remote access-watchpoint-packet
12193@itemx set remote Z-packet
12194@cindex Z-packet
12195@cindex remote hardware breakpoints and watchpoints
12196These commands enable or disable the use of @samp{Z} packets for
12197setting breakpoints and watchpoints in the remote target. The default
12198depends on the remote stub's support of the @samp{Z} packets
12199(@value{GDBN} queries the stub when each packet is first required).
12200The command @code{set remote Z-packet}, kept for back-compatibility,
12201turns on or off all the features that require the use of @samp{Z}
12202packets.
12203
12204@item show remote software-breakpoint-packet
12205@itemx show remote hardware-breakpoint-packet
12206@itemx show remote write-watchpoint-packet
12207@itemx show remote read-watchpoint-packet
12208@itemx show remote access-watchpoint-packet
12209@itemx show remote Z-packet
12210Show the current setting of @samp{Z} packets usage.
0abb7bc7
EZ
12211
12212@item set remote get-thread-local-storage-address
12213@kindex set remote get-thread-local-storage-address
12214@cindex thread local storage of remote targets
12215This command enables or disables the use of the @samp{qGetTLSAddr}
12216(Get Thread Local Storage Address) request packet. The default
12217depends on whether the remote stub supports this request.
12218@xref{General Query Packets, qGetTLSAddr}, for more details about this
12219packet.
12220
12221@item show remote get-thread-local-storage-address
12222@kindex show remote get-thread-local-storage-address
12223Show the current setting of @samp{qGetTLSAddr} packet usage.
501eef12
AC
12224@end table
12225
6f05cf9f
AC
12226@node remote stub
12227@section Implementing a remote stub
7a292a7a 12228
8e04817f
AC
12229@cindex debugging stub, example
12230@cindex remote stub, example
12231@cindex stub example, remote debugging
12232The stub files provided with @value{GDBN} implement the target side of the
12233communication protocol, and the @value{GDBN} side is implemented in the
12234@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
12235these subroutines to communicate, and ignore the details. (If you're
12236implementing your own stub file, you can still ignore the details: start
12237with one of the existing stub files. @file{sparc-stub.c} is the best
12238organized, and therefore the easiest to read.)
12239
104c1213
JM
12240@cindex remote serial debugging, overview
12241To debug a program running on another machine (the debugging
12242@dfn{target} machine), you must first arrange for all the usual
12243prerequisites for the program to run by itself. For example, for a C
12244program, you need:
c906108c 12245
104c1213
JM
12246@enumerate
12247@item
12248A startup routine to set up the C runtime environment; these usually
12249have a name like @file{crt0}. The startup routine may be supplied by
12250your hardware supplier, or you may have to write your own.
96baa820 12251
5d161b24 12252@item
d4f3574e 12253A C subroutine library to support your program's
104c1213 12254subroutine calls, notably managing input and output.
96baa820 12255
104c1213
JM
12256@item
12257A way of getting your program to the other machine---for example, a
12258download program. These are often supplied by the hardware
12259manufacturer, but you may have to write your own from hardware
12260documentation.
12261@end enumerate
96baa820 12262
104c1213
JM
12263The next step is to arrange for your program to use a serial port to
12264communicate with the machine where @value{GDBN} is running (the @dfn{host}
12265machine). In general terms, the scheme looks like this:
96baa820 12266
104c1213
JM
12267@table @emph
12268@item On the host,
12269@value{GDBN} already understands how to use this protocol; when everything
12270else is set up, you can simply use the @samp{target remote} command
12271(@pxref{Targets,,Specifying a Debugging Target}).
12272
12273@item On the target,
12274you must link with your program a few special-purpose subroutines that
12275implement the @value{GDBN} remote serial protocol. The file containing these
12276subroutines is called a @dfn{debugging stub}.
12277
12278On certain remote targets, you can use an auxiliary program
12279@code{gdbserver} instead of linking a stub into your program.
12280@xref{Server,,Using the @code{gdbserver} program}, for details.
12281@end table
96baa820 12282
104c1213
JM
12283The debugging stub is specific to the architecture of the remote
12284machine; for example, use @file{sparc-stub.c} to debug programs on
12285@sc{sparc} boards.
96baa820 12286
104c1213
JM
12287@cindex remote serial stub list
12288These working remote stubs are distributed with @value{GDBN}:
96baa820 12289
104c1213
JM
12290@table @code
12291
12292@item i386-stub.c
41afff9a 12293@cindex @file{i386-stub.c}
104c1213
JM
12294@cindex Intel
12295@cindex i386
12296For Intel 386 and compatible architectures.
12297
12298@item m68k-stub.c
41afff9a 12299@cindex @file{m68k-stub.c}
104c1213
JM
12300@cindex Motorola 680x0
12301@cindex m680x0
12302For Motorola 680x0 architectures.
12303
12304@item sh-stub.c
41afff9a 12305@cindex @file{sh-stub.c}
172c2a43 12306@cindex Renesas
104c1213 12307@cindex SH
172c2a43 12308For Renesas SH architectures.
104c1213
JM
12309
12310@item sparc-stub.c
41afff9a 12311@cindex @file{sparc-stub.c}
104c1213
JM
12312@cindex Sparc
12313For @sc{sparc} architectures.
12314
12315@item sparcl-stub.c
41afff9a 12316@cindex @file{sparcl-stub.c}
104c1213
JM
12317@cindex Fujitsu
12318@cindex SparcLite
12319For Fujitsu @sc{sparclite} architectures.
12320
12321@end table
12322
12323The @file{README} file in the @value{GDBN} distribution may list other
12324recently added stubs.
12325
12326@menu
12327* Stub Contents:: What the stub can do for you
12328* Bootstrapping:: What you must do for the stub
12329* Debug Session:: Putting it all together
104c1213
JM
12330@end menu
12331
6d2ebf8b 12332@node Stub Contents
6f05cf9f 12333@subsection What the stub can do for you
104c1213
JM
12334
12335@cindex remote serial stub
12336The debugging stub for your architecture supplies these three
12337subroutines:
12338
12339@table @code
12340@item set_debug_traps
4644b6e3 12341@findex set_debug_traps
104c1213
JM
12342@cindex remote serial stub, initialization
12343This routine arranges for @code{handle_exception} to run when your
12344program stops. You must call this subroutine explicitly near the
12345beginning of your program.
12346
12347@item handle_exception
4644b6e3 12348@findex handle_exception
104c1213
JM
12349@cindex remote serial stub, main routine
12350This is the central workhorse, but your program never calls it
12351explicitly---the setup code arranges for @code{handle_exception} to
12352run when a trap is triggered.
12353
12354@code{handle_exception} takes control when your program stops during
12355execution (for example, on a breakpoint), and mediates communications
12356with @value{GDBN} on the host machine. This is where the communications
12357protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 12358representative on the target machine. It begins by sending summary
104c1213
JM
12359information on the state of your program, then continues to execute,
12360retrieving and transmitting any information @value{GDBN} needs, until you
12361execute a @value{GDBN} command that makes your program resume; at that point,
12362@code{handle_exception} returns control to your own code on the target
5d161b24 12363machine.
104c1213
JM
12364
12365@item breakpoint
12366@cindex @code{breakpoint} subroutine, remote
12367Use this auxiliary subroutine to make your program contain a
12368breakpoint. Depending on the particular situation, this may be the only
12369way for @value{GDBN} to get control. For instance, if your target
12370machine has some sort of interrupt button, you won't need to call this;
12371pressing the interrupt button transfers control to
12372@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
12373simply receiving characters on the serial port may also trigger a trap;
12374again, in that situation, you don't need to call @code{breakpoint} from
12375your own program---simply running @samp{target remote} from the host
5d161b24 12376@value{GDBN} session gets control.
104c1213
JM
12377
12378Call @code{breakpoint} if none of these is true, or if you simply want
12379to make certain your program stops at a predetermined point for the
12380start of your debugging session.
12381@end table
12382
6d2ebf8b 12383@node Bootstrapping
6f05cf9f 12384@subsection What you must do for the stub
104c1213
JM
12385
12386@cindex remote stub, support routines
12387The debugging stubs that come with @value{GDBN} are set up for a particular
12388chip architecture, but they have no information about the rest of your
12389debugging target machine.
12390
12391First of all you need to tell the stub how to communicate with the
12392serial port.
12393
12394@table @code
12395@item int getDebugChar()
4644b6e3 12396@findex getDebugChar
104c1213
JM
12397Write this subroutine to read a single character from the serial port.
12398It may be identical to @code{getchar} for your target system; a
12399different name is used to allow you to distinguish the two if you wish.
12400
12401@item void putDebugChar(int)
4644b6e3 12402@findex putDebugChar
104c1213 12403Write this subroutine to write a single character to the serial port.
5d161b24 12404It may be identical to @code{putchar} for your target system; a
104c1213
JM
12405different name is used to allow you to distinguish the two if you wish.
12406@end table
12407
12408@cindex control C, and remote debugging
12409@cindex interrupting remote targets
12410If you want @value{GDBN} to be able to stop your program while it is
12411running, you need to use an interrupt-driven serial driver, and arrange
12412for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
12413character). That is the character which @value{GDBN} uses to tell the
12414remote system to stop.
12415
12416Getting the debugging target to return the proper status to @value{GDBN}
12417probably requires changes to the standard stub; one quick and dirty way
12418is to just execute a breakpoint instruction (the ``dirty'' part is that
12419@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
12420
12421Other routines you need to supply are:
12422
12423@table @code
12424@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 12425@findex exceptionHandler
104c1213
JM
12426Write this function to install @var{exception_address} in the exception
12427handling tables. You need to do this because the stub does not have any
12428way of knowing what the exception handling tables on your target system
12429are like (for example, the processor's table might be in @sc{rom},
12430containing entries which point to a table in @sc{ram}).
12431@var{exception_number} is the exception number which should be changed;
12432its meaning is architecture-dependent (for example, different numbers
12433might represent divide by zero, misaligned access, etc). When this
12434exception occurs, control should be transferred directly to
12435@var{exception_address}, and the processor state (stack, registers,
12436and so on) should be just as it is when a processor exception occurs. So if
12437you want to use a jump instruction to reach @var{exception_address}, it
12438should be a simple jump, not a jump to subroutine.
12439
12440For the 386, @var{exception_address} should be installed as an interrupt
12441gate so that interrupts are masked while the handler runs. The gate
12442should be at privilege level 0 (the most privileged level). The
12443@sc{sparc} and 68k stubs are able to mask interrupts themselves without
12444help from @code{exceptionHandler}.
12445
12446@item void flush_i_cache()
4644b6e3 12447@findex flush_i_cache
d4f3574e 12448On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
12449instruction cache, if any, on your target machine. If there is no
12450instruction cache, this subroutine may be a no-op.
12451
12452On target machines that have instruction caches, @value{GDBN} requires this
12453function to make certain that the state of your program is stable.
12454@end table
12455
12456@noindent
12457You must also make sure this library routine is available:
12458
12459@table @code
12460@item void *memset(void *, int, int)
4644b6e3 12461@findex memset
104c1213
JM
12462This is the standard library function @code{memset} that sets an area of
12463memory to a known value. If you have one of the free versions of
12464@code{libc.a}, @code{memset} can be found there; otherwise, you must
12465either obtain it from your hardware manufacturer, or write your own.
12466@end table
12467
12468If you do not use the GNU C compiler, you may need other standard
12469library subroutines as well; this varies from one stub to another,
12470but in general the stubs are likely to use any of the common library
d4f3574e 12471subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
12472
12473
6d2ebf8b 12474@node Debug Session
6f05cf9f 12475@subsection Putting it all together
104c1213
JM
12476
12477@cindex remote serial debugging summary
12478In summary, when your program is ready to debug, you must follow these
12479steps.
12480
12481@enumerate
12482@item
6d2ebf8b 12483Make sure you have defined the supporting low-level routines
104c1213
JM
12484(@pxref{Bootstrapping,,What you must do for the stub}):
12485@display
12486@code{getDebugChar}, @code{putDebugChar},
12487@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
12488@end display
12489
12490@item
12491Insert these lines near the top of your program:
12492
474c8240 12493@smallexample
104c1213
JM
12494set_debug_traps();
12495breakpoint();
474c8240 12496@end smallexample
104c1213
JM
12497
12498@item
12499For the 680x0 stub only, you need to provide a variable called
12500@code{exceptionHook}. Normally you just use:
12501
474c8240 12502@smallexample
104c1213 12503void (*exceptionHook)() = 0;
474c8240 12504@end smallexample
104c1213 12505
d4f3574e 12506@noindent
104c1213 12507but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 12508function in your program, that function is called when
104c1213
JM
12509@code{@value{GDBN}} continues after stopping on a trap (for example, bus
12510error). The function indicated by @code{exceptionHook} is called with
12511one parameter: an @code{int} which is the exception number.
12512
12513@item
12514Compile and link together: your program, the @value{GDBN} debugging stub for
12515your target architecture, and the supporting subroutines.
12516
12517@item
12518Make sure you have a serial connection between your target machine and
12519the @value{GDBN} host, and identify the serial port on the host.
12520
12521@item
12522@c The "remote" target now provides a `load' command, so we should
12523@c document that. FIXME.
12524Download your program to your target machine (or get it there by
12525whatever means the manufacturer provides), and start it.
12526
12527@item
07f31aa6
DJ
12528Start @value{GDBN} on the host, and connect to the target
12529(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 12530
104c1213
JM
12531@end enumerate
12532
8e04817f
AC
12533@node Configurations
12534@chapter Configuration-Specific Information
104c1213 12535
8e04817f
AC
12536While nearly all @value{GDBN} commands are available for all native and
12537cross versions of the debugger, there are some exceptions. This chapter
12538describes things that are only available in certain configurations.
104c1213 12539
8e04817f
AC
12540There are three major categories of configurations: native
12541configurations, where the host and target are the same, embedded
12542operating system configurations, which are usually the same for several
12543different processor architectures, and bare embedded processors, which
12544are quite different from each other.
104c1213 12545
8e04817f
AC
12546@menu
12547* Native::
12548* Embedded OS::
12549* Embedded Processors::
12550* Architectures::
12551@end menu
104c1213 12552
8e04817f
AC
12553@node Native
12554@section Native
104c1213 12555
8e04817f
AC
12556This section describes details specific to particular native
12557configurations.
6cf7e474 12558
8e04817f
AC
12559@menu
12560* HP-UX:: HP-UX
7561d450 12561* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
12562* SVR4 Process Information:: SVR4 process information
12563* DJGPP Native:: Features specific to the DJGPP port
78c47bea 12564* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 12565* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 12566* Neutrino:: Features specific to QNX Neutrino
8e04817f 12567@end menu
6cf7e474 12568
8e04817f
AC
12569@node HP-UX
12570@subsection HP-UX
104c1213 12571
8e04817f
AC
12572On HP-UX systems, if you refer to a function or variable name that
12573begins with a dollar sign, @value{GDBN} searches for a user or system
12574name first, before it searches for a convenience variable.
104c1213 12575
9c16f35a 12576
7561d450
MK
12577@node BSD libkvm Interface
12578@subsection BSD libkvm Interface
12579
12580@cindex libkvm
12581@cindex kernel memory image
12582@cindex kernel crash dump
12583
12584BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
12585interface that provides a uniform interface for accessing kernel virtual
12586memory images, including live systems and crash dumps. @value{GDBN}
12587uses this interface to allow you to debug live kernels and kernel crash
12588dumps on many native BSD configurations. This is implemented as a
12589special @code{kvm} debugging target. For debugging a live system, load
12590the currently running kernel into @value{GDBN} and connect to the
12591@code{kvm} target:
12592
12593@smallexample
12594(@value{GDBP}) @b{target kvm}
12595@end smallexample
12596
12597For debugging crash dumps, provide the file name of the crash dump as an
12598argument:
12599
12600@smallexample
12601(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
12602@end smallexample
12603
12604Once connected to the @code{kvm} target, the following commands are
12605available:
12606
12607@table @code
12608@kindex kvm
12609@item kvm pcb
721c2651 12610Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
12611
12612@item kvm proc
12613Set current context from proc address. This command isn't available on
12614modern FreeBSD systems.
12615@end table
12616
8e04817f
AC
12617@node SVR4 Process Information
12618@subsection SVR4 process information
60bf7e09
EZ
12619@cindex /proc
12620@cindex examine process image
12621@cindex process info via @file{/proc}
104c1213 12622
60bf7e09
EZ
12623Many versions of SVR4 and compatible systems provide a facility called
12624@samp{/proc} that can be used to examine the image of a running
12625process using file-system subroutines. If @value{GDBN} is configured
12626for an operating system with this facility, the command @code{info
12627proc} is available to report information about the process running
12628your program, or about any process running on your system. @code{info
12629proc} works only on SVR4 systems that include the @code{procfs} code.
12630This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
12631Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 12632
8e04817f
AC
12633@table @code
12634@kindex info proc
60bf7e09 12635@cindex process ID
8e04817f 12636@item info proc
60bf7e09
EZ
12637@itemx info proc @var{process-id}
12638Summarize available information about any running process. If a
12639process ID is specified by @var{process-id}, display information about
12640that process; otherwise display information about the program being
12641debugged. The summary includes the debugged process ID, the command
12642line used to invoke it, its current working directory, and its
12643executable file's absolute file name.
12644
12645On some systems, @var{process-id} can be of the form
12646@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
12647within a process. If the optional @var{pid} part is missing, it means
12648a thread from the process being debugged (the leading @samp{/} still
12649needs to be present, or else @value{GDBN} will interpret the number as
12650a process ID rather than a thread ID).
6cf7e474 12651
8e04817f 12652@item info proc mappings
60bf7e09
EZ
12653@cindex memory address space mappings
12654Report the memory address space ranges accessible in the program, with
12655information on whether the process has read, write, or execute access
12656rights to each range. On @sc{gnu}/Linux systems, each memory range
12657includes the object file which is mapped to that range, instead of the
12658memory access rights to that range.
12659
12660@item info proc stat
12661@itemx info proc status
12662@cindex process detailed status information
12663These subcommands are specific to @sc{gnu}/Linux systems. They show
12664the process-related information, including the user ID and group ID;
12665how many threads are there in the process; its virtual memory usage;
12666the signals that are pending, blocked, and ignored; its TTY; its
12667consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 12668value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
12669(type @kbd{man 5 proc} from your shell prompt).
12670
12671@item info proc all
12672Show all the information about the process described under all of the
12673above @code{info proc} subcommands.
12674
8e04817f
AC
12675@ignore
12676@comment These sub-options of 'info proc' were not included when
12677@comment procfs.c was re-written. Keep their descriptions around
12678@comment against the day when someone finds the time to put them back in.
12679@kindex info proc times
12680@item info proc times
12681Starting time, user CPU time, and system CPU time for your program and
12682its children.
6cf7e474 12683
8e04817f
AC
12684@kindex info proc id
12685@item info proc id
12686Report on the process IDs related to your program: its own process ID,
12687the ID of its parent, the process group ID, and the session ID.
8e04817f 12688@end ignore
721c2651
EZ
12689
12690@item set procfs-trace
12691@kindex set procfs-trace
12692@cindex @code{procfs} API calls
12693This command enables and disables tracing of @code{procfs} API calls.
12694
12695@item show procfs-trace
12696@kindex show procfs-trace
12697Show the current state of @code{procfs} API call tracing.
12698
12699@item set procfs-file @var{file}
12700@kindex set procfs-file
12701Tell @value{GDBN} to write @code{procfs} API trace to the named
12702@var{file}. @value{GDBN} appends the trace info to the previous
12703contents of the file. The default is to display the trace on the
12704standard output.
12705
12706@item show procfs-file
12707@kindex show procfs-file
12708Show the file to which @code{procfs} API trace is written.
12709
12710@item proc-trace-entry
12711@itemx proc-trace-exit
12712@itemx proc-untrace-entry
12713@itemx proc-untrace-exit
12714@kindex proc-trace-entry
12715@kindex proc-trace-exit
12716@kindex proc-untrace-entry
12717@kindex proc-untrace-exit
12718These commands enable and disable tracing of entries into and exits
12719from the @code{syscall} interface.
12720
12721@item info pidlist
12722@kindex info pidlist
12723@cindex process list, QNX Neutrino
12724For QNX Neutrino only, this command displays the list of all the
12725processes and all the threads within each process.
12726
12727@item info meminfo
12728@kindex info meminfo
12729@cindex mapinfo list, QNX Neutrino
12730For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 12731@end table
104c1213 12732
8e04817f
AC
12733@node DJGPP Native
12734@subsection Features for Debugging @sc{djgpp} Programs
12735@cindex @sc{djgpp} debugging
12736@cindex native @sc{djgpp} debugging
12737@cindex MS-DOS-specific commands
104c1213 12738
514c4d71
EZ
12739@cindex DPMI
12740@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
12741MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
12742that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
12743top of real-mode DOS systems and their emulations.
104c1213 12744
8e04817f
AC
12745@value{GDBN} supports native debugging of @sc{djgpp} programs, and
12746defines a few commands specific to the @sc{djgpp} port. This
12747subsection describes those commands.
104c1213 12748
8e04817f
AC
12749@table @code
12750@kindex info dos
12751@item info dos
12752This is a prefix of @sc{djgpp}-specific commands which print
12753information about the target system and important OS structures.
f1251bdd 12754
8e04817f
AC
12755@kindex sysinfo
12756@cindex MS-DOS system info
12757@cindex free memory information (MS-DOS)
12758@item info dos sysinfo
12759This command displays assorted information about the underlying
12760platform: the CPU type and features, the OS version and flavor, the
12761DPMI version, and the available conventional and DPMI memory.
104c1213 12762
8e04817f
AC
12763@cindex GDT
12764@cindex LDT
12765@cindex IDT
12766@cindex segment descriptor tables
12767@cindex descriptor tables display
12768@item info dos gdt
12769@itemx info dos ldt
12770@itemx info dos idt
12771These 3 commands display entries from, respectively, Global, Local,
12772and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
12773tables are data structures which store a descriptor for each segment
12774that is currently in use. The segment's selector is an index into a
12775descriptor table; the table entry for that index holds the
12776descriptor's base address and limit, and its attributes and access
12777rights.
104c1213 12778
8e04817f
AC
12779A typical @sc{djgpp} program uses 3 segments: a code segment, a data
12780segment (used for both data and the stack), and a DOS segment (which
12781allows access to DOS/BIOS data structures and absolute addresses in
12782conventional memory). However, the DPMI host will usually define
12783additional segments in order to support the DPMI environment.
d4f3574e 12784
8e04817f
AC
12785@cindex garbled pointers
12786These commands allow to display entries from the descriptor tables.
12787Without an argument, all entries from the specified table are
12788displayed. An argument, which should be an integer expression, means
12789display a single entry whose index is given by the argument. For
12790example, here's a convenient way to display information about the
12791debugged program's data segment:
104c1213 12792
8e04817f
AC
12793@smallexample
12794@exdent @code{(@value{GDBP}) info dos ldt $ds}
12795@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
12796@end smallexample
104c1213 12797
8e04817f
AC
12798@noindent
12799This comes in handy when you want to see whether a pointer is outside
12800the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 12801
8e04817f
AC
12802@cindex page tables display (MS-DOS)
12803@item info dos pde
12804@itemx info dos pte
12805These two commands display entries from, respectively, the Page
12806Directory and the Page Tables. Page Directories and Page Tables are
12807data structures which control how virtual memory addresses are mapped
12808into physical addresses. A Page Table includes an entry for every
12809page of memory that is mapped into the program's address space; there
12810may be several Page Tables, each one holding up to 4096 entries. A
12811Page Directory has up to 4096 entries, one each for every Page Table
12812that is currently in use.
104c1213 12813
8e04817f
AC
12814Without an argument, @kbd{info dos pde} displays the entire Page
12815Directory, and @kbd{info dos pte} displays all the entries in all of
12816the Page Tables. An argument, an integer expression, given to the
12817@kbd{info dos pde} command means display only that entry from the Page
12818Directory table. An argument given to the @kbd{info dos pte} command
12819means display entries from a single Page Table, the one pointed to by
12820the specified entry in the Page Directory.
104c1213 12821
8e04817f
AC
12822@cindex direct memory access (DMA) on MS-DOS
12823These commands are useful when your program uses @dfn{DMA} (Direct
12824Memory Access), which needs physical addresses to program the DMA
12825controller.
104c1213 12826
8e04817f 12827These commands are supported only with some DPMI servers.
104c1213 12828
8e04817f
AC
12829@cindex physical address from linear address
12830@item info dos address-pte @var{addr}
12831This command displays the Page Table entry for a specified linear
514c4d71
EZ
12832address. The argument @var{addr} is a linear address which should
12833already have the appropriate segment's base address added to it,
12834because this command accepts addresses which may belong to @emph{any}
12835segment. For example, here's how to display the Page Table entry for
12836the page where a variable @code{i} is stored:
104c1213 12837
b383017d 12838@smallexample
8e04817f
AC
12839@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
12840@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 12841@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 12842@end smallexample
104c1213 12843
8e04817f
AC
12844@noindent
12845This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 12846whose physical base address is @code{0x02698000}, and shows all the
8e04817f 12847attributes of that page.
104c1213 12848
8e04817f
AC
12849Note that you must cast the addresses of variables to a @code{char *},
12850since otherwise the value of @code{__djgpp_base_address}, the base
12851address of all variables and functions in a @sc{djgpp} program, will
12852be added using the rules of C pointer arithmetics: if @code{i} is
12853declared an @code{int}, @value{GDBN} will add 4 times the value of
12854@code{__djgpp_base_address} to the address of @code{i}.
104c1213 12855
8e04817f
AC
12856Here's another example, it displays the Page Table entry for the
12857transfer buffer:
104c1213 12858
8e04817f
AC
12859@smallexample
12860@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
12861@exdent @code{Page Table entry for address 0x29110:}
12862@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
12863@end smallexample
104c1213 12864
8e04817f
AC
12865@noindent
12866(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
128673rd member of the @code{_go32_info_block} structure.) The output
12868clearly shows that this DPMI server maps the addresses in conventional
12869memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
12870linear (@code{0x29110}) addresses are identical.
104c1213 12871
8e04817f
AC
12872This command is supported only with some DPMI servers.
12873@end table
104c1213 12874
c45da7e6 12875@cindex DOS serial data link, remote debugging
a8f24a35
EZ
12876In addition to native debugging, the DJGPP port supports remote
12877debugging via a serial data link. The following commands are specific
12878to remote serial debugging in the DJGPP port of @value{GDBN}.
12879
12880@table @code
12881@kindex set com1base
12882@kindex set com1irq
12883@kindex set com2base
12884@kindex set com2irq
12885@kindex set com3base
12886@kindex set com3irq
12887@kindex set com4base
12888@kindex set com4irq
12889@item set com1base @var{addr}
12890This command sets the base I/O port address of the @file{COM1} serial
12891port.
12892
12893@item set com1irq @var{irq}
12894This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
12895for the @file{COM1} serial port.
12896
12897There are similar commands @samp{set com2base}, @samp{set com3irq},
12898etc.@: for setting the port address and the @code{IRQ} lines for the
12899other 3 COM ports.
12900
12901@kindex show com1base
12902@kindex show com1irq
12903@kindex show com2base
12904@kindex show com2irq
12905@kindex show com3base
12906@kindex show com3irq
12907@kindex show com4base
12908@kindex show com4irq
12909The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
12910display the current settings of the base address and the @code{IRQ}
12911lines used by the COM ports.
c45da7e6
EZ
12912
12913@item info serial
12914@kindex info serial
12915@cindex DOS serial port status
12916This command prints the status of the 4 DOS serial ports. For each
12917port, it prints whether it's active or not, its I/O base address and
12918IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
12919counts of various errors encountered so far.
a8f24a35
EZ
12920@end table
12921
12922
78c47bea
PM
12923@node Cygwin Native
12924@subsection Features for Debugging MS Windows PE executables
12925@cindex MS Windows debugging
12926@cindex native Cygwin debugging
12927@cindex Cygwin-specific commands
12928
be448670
CF
12929@value{GDBN} supports native debugging of MS Windows programs, including
12930DLLs with and without symbolic debugging information. There are various
12931additional Cygwin-specific commands, described in this subsection. The
12932subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
12933that have no debugging symbols.
12934
78c47bea
PM
12935
12936@table @code
12937@kindex info w32
12938@item info w32
12939This is a prefix of MS Windows specific commands which print
12940information about the target system and important OS structures.
12941
12942@item info w32 selector
12943This command displays information returned by
12944the Win32 API @code{GetThreadSelectorEntry} function.
12945It takes an optional argument that is evaluated to
12946a long value to give the information about this given selector.
12947Without argument, this command displays information
12948about the the six segment registers.
12949
12950@kindex info dll
12951@item info dll
12952This is a Cygwin specific alias of info shared.
12953
12954@kindex dll-symbols
12955@item dll-symbols
12956This command loads symbols from a dll similarly to
12957add-sym command but without the need to specify a base address.
12958
b383017d 12959@kindex set new-console
78c47bea 12960@item set new-console @var{mode}
b383017d 12961If @var{mode} is @code{on} the debuggee will
78c47bea
PM
12962be started in a new console on next start.
12963If @var{mode} is @code{off}i, the debuggee will
12964be started in the same console as the debugger.
12965
12966@kindex show new-console
12967@item show new-console
12968Displays whether a new console is used
12969when the debuggee is started.
12970
12971@kindex set new-group
12972@item set new-group @var{mode}
12973This boolean value controls whether the debuggee should
12974start a new group or stay in the same group as the debugger.
12975This affects the way the Windows OS handles
12976Ctrl-C.
12977
12978@kindex show new-group
12979@item show new-group
12980Displays current value of new-group boolean.
12981
12982@kindex set debugevents
12983@item set debugevents
12984This boolean value adds debug output concerning events seen by the debugger.
12985
12986@kindex set debugexec
12987@item set debugexec
b383017d 12988This boolean value adds debug output concerning execute events
78c47bea
PM
12989seen by the debugger.
12990
12991@kindex set debugexceptions
12992@item set debugexceptions
b383017d 12993This boolean value adds debug ouptut concerning exception events
78c47bea
PM
12994seen by the debugger.
12995
12996@kindex set debugmemory
12997@item set debugmemory
b383017d 12998This boolean value adds debug ouptut concerning memory events
78c47bea
PM
12999seen by the debugger.
13000
13001@kindex set shell
13002@item set shell
13003This boolean values specifies whether the debuggee is called
13004via a shell or directly (default value is on).
13005
13006@kindex show shell
13007@item show shell
13008Displays if the debuggee will be started with a shell.
13009
13010@end table
13011
be448670
CF
13012@menu
13013* Non-debug DLL symbols:: Support for DLLs without debugging symbols
13014@end menu
13015
13016@node Non-debug DLL symbols
13017@subsubsection Support for DLLs without debugging symbols
13018@cindex DLLs with no debugging symbols
13019@cindex Minimal symbols and DLLs
13020
13021Very often on windows, some of the DLLs that your program relies on do
13022not include symbolic debugging information (for example,
13023@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
13024symbols in a DLL, it relies on the minimal amount of symbolic
13025information contained in the DLL's export table. This subsubsection
13026describes working with such symbols, known internally to @value{GDBN} as
13027``minimal symbols''.
13028
13029Note that before the debugged program has started execution, no DLLs
13030will have been loaded. The easiest way around this problem is simply to
13031start the program --- either by setting a breakpoint or letting the
13032program run once to completion. It is also possible to force
13033@value{GDBN} to load a particular DLL before starting the executable ---
13034see the shared library information in @pxref{Files} or the
13035@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
13036explicitly loading symbols from a DLL with no debugging information will
13037cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
13038which may adversely affect symbol lookup performance.
13039
13040@subsubsection DLL name prefixes
13041
13042In keeping with the naming conventions used by the Microsoft debugging
13043tools, DLL export symbols are made available with a prefix based on the
13044DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
13045also entered into the symbol table, so @code{CreateFileA} is often
13046sufficient. In some cases there will be name clashes within a program
13047(particularly if the executable itself includes full debugging symbols)
13048necessitating the use of the fully qualified name when referring to the
13049contents of the DLL. Use single-quotes around the name to avoid the
13050exclamation mark (``!'') being interpreted as a language operator.
13051
13052Note that the internal name of the DLL may be all upper-case, even
13053though the file name of the DLL is lower-case, or vice-versa. Since
13054symbols within @value{GDBN} are @emph{case-sensitive} this may cause
13055some confusion. If in doubt, try the @code{info functions} and
13056@code{info variables} commands or even @code{maint print msymbols} (see
13057@pxref{Symbols}). Here's an example:
13058
13059@smallexample
f7dc1244 13060(@value{GDBP}) info function CreateFileA
be448670
CF
13061All functions matching regular expression "CreateFileA":
13062
13063Non-debugging symbols:
130640x77e885f4 CreateFileA
130650x77e885f4 KERNEL32!CreateFileA
13066@end smallexample
13067
13068@smallexample
f7dc1244 13069(@value{GDBP}) info function !
be448670
CF
13070All functions matching regular expression "!":
13071
13072Non-debugging symbols:
130730x6100114c cygwin1!__assert
130740x61004034 cygwin1!_dll_crt0@@0
130750x61004240 cygwin1!dll_crt0(per_process *)
13076[etc...]
13077@end smallexample
13078
13079@subsubsection Working with minimal symbols
13080
13081Symbols extracted from a DLL's export table do not contain very much
13082type information. All that @value{GDBN} can do is guess whether a symbol
13083refers to a function or variable depending on the linker section that
13084contains the symbol. Also note that the actual contents of the memory
13085contained in a DLL are not available unless the program is running. This
13086means that you cannot examine the contents of a variable or disassemble
13087a function within a DLL without a running program.
13088
13089Variables are generally treated as pointers and dereferenced
13090automatically. For this reason, it is often necessary to prefix a
13091variable name with the address-of operator (``&'') and provide explicit
13092type information in the command. Here's an example of the type of
13093problem:
13094
13095@smallexample
f7dc1244 13096(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
13097$1 = 268572168
13098@end smallexample
13099
13100@smallexample
f7dc1244 13101(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
131020x10021610: "\230y\""
13103@end smallexample
13104
13105And two possible solutions:
13106
13107@smallexample
f7dc1244 13108(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
13109$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
13110@end smallexample
13111
13112@smallexample
f7dc1244 13113(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 131140x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 13115(@value{GDBP}) x/x 0x10021608
be448670 131160x10021608: 0x0022fd98
f7dc1244 13117(@value{GDBP}) x/s 0x0022fd98
be448670
CF
131180x22fd98: "/cygdrive/c/mydirectory/myprogram"
13119@end smallexample
13120
13121Setting a break point within a DLL is possible even before the program
13122starts execution. However, under these circumstances, @value{GDBN} can't
13123examine the initial instructions of the function in order to skip the
13124function's frame set-up code. You can work around this by using ``*&''
13125to set the breakpoint at a raw memory address:
13126
13127@smallexample
f7dc1244 13128(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
13129Breakpoint 1 at 0x1e04eff0
13130@end smallexample
13131
13132The author of these extensions is not entirely convinced that setting a
13133break point within a shared DLL like @file{kernel32.dll} is completely
13134safe.
13135
14d6dd68
EZ
13136@node Hurd Native
13137@subsection Commands specific to @sc{gnu} Hurd systems
13138@cindex @sc{gnu} Hurd debugging
13139
13140This subsection describes @value{GDBN} commands specific to the
13141@sc{gnu} Hurd native debugging.
13142
13143@table @code
13144@item set signals
13145@itemx set sigs
13146@kindex set signals@r{, Hurd command}
13147@kindex set sigs@r{, Hurd command}
13148This command toggles the state of inferior signal interception by
13149@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
13150affected by this command. @code{sigs} is a shorthand alias for
13151@code{signals}.
13152
13153@item show signals
13154@itemx show sigs
13155@kindex show signals@r{, Hurd command}
13156@kindex show sigs@r{, Hurd command}
13157Show the current state of intercepting inferior's signals.
13158
13159@item set signal-thread
13160@itemx set sigthread
13161@kindex set signal-thread
13162@kindex set sigthread
13163This command tells @value{GDBN} which thread is the @code{libc} signal
13164thread. That thread is run when a signal is delivered to a running
13165process. @code{set sigthread} is the shorthand alias of @code{set
13166signal-thread}.
13167
13168@item show signal-thread
13169@itemx show sigthread
13170@kindex show signal-thread
13171@kindex show sigthread
13172These two commands show which thread will run when the inferior is
13173delivered a signal.
13174
13175@item set stopped
13176@kindex set stopped@r{, Hurd command}
13177This commands tells @value{GDBN} that the inferior process is stopped,
13178as with the @code{SIGSTOP} signal. The stopped process can be
13179continued by delivering a signal to it.
13180
13181@item show stopped
13182@kindex show stopped@r{, Hurd command}
13183This command shows whether @value{GDBN} thinks the debuggee is
13184stopped.
13185
13186@item set exceptions
13187@kindex set exceptions@r{, Hurd command}
13188Use this command to turn off trapping of exceptions in the inferior.
13189When exception trapping is off, neither breakpoints nor
13190single-stepping will work. To restore the default, set exception
13191trapping on.
13192
13193@item show exceptions
13194@kindex show exceptions@r{, Hurd command}
13195Show the current state of trapping exceptions in the inferior.
13196
13197@item set task pause
13198@kindex set task@r{, Hurd commands}
13199@cindex task attributes (@sc{gnu} Hurd)
13200@cindex pause current task (@sc{gnu} Hurd)
13201This command toggles task suspension when @value{GDBN} has control.
13202Setting it to on takes effect immediately, and the task is suspended
13203whenever @value{GDBN} gets control. Setting it to off will take
13204effect the next time the inferior is continued. If this option is set
13205to off, you can use @code{set thread default pause on} or @code{set
13206thread pause on} (see below) to pause individual threads.
13207
13208@item show task pause
13209@kindex show task@r{, Hurd commands}
13210Show the current state of task suspension.
13211
13212@item set task detach-suspend-count
13213@cindex task suspend count
13214@cindex detach from task, @sc{gnu} Hurd
13215This command sets the suspend count the task will be left with when
13216@value{GDBN} detaches from it.
13217
13218@item show task detach-suspend-count
13219Show the suspend count the task will be left with when detaching.
13220
13221@item set task exception-port
13222@itemx set task excp
13223@cindex task exception port, @sc{gnu} Hurd
13224This command sets the task exception port to which @value{GDBN} will
13225forward exceptions. The argument should be the value of the @dfn{send
13226rights} of the task. @code{set task excp} is a shorthand alias.
13227
13228@item set noninvasive
13229@cindex noninvasive task options
13230This command switches @value{GDBN} to a mode that is the least
13231invasive as far as interfering with the inferior is concerned. This
13232is the same as using @code{set task pause}, @code{set exceptions}, and
13233@code{set signals} to values opposite to the defaults.
13234
13235@item info send-rights
13236@itemx info receive-rights
13237@itemx info port-rights
13238@itemx info port-sets
13239@itemx info dead-names
13240@itemx info ports
13241@itemx info psets
13242@cindex send rights, @sc{gnu} Hurd
13243@cindex receive rights, @sc{gnu} Hurd
13244@cindex port rights, @sc{gnu} Hurd
13245@cindex port sets, @sc{gnu} Hurd
13246@cindex dead names, @sc{gnu} Hurd
13247These commands display information about, respectively, send rights,
13248receive rights, port rights, port sets, and dead names of a task.
13249There are also shorthand aliases: @code{info ports} for @code{info
13250port-rights} and @code{info psets} for @code{info port-sets}.
13251
13252@item set thread pause
13253@kindex set thread@r{, Hurd command}
13254@cindex thread properties, @sc{gnu} Hurd
13255@cindex pause current thread (@sc{gnu} Hurd)
13256This command toggles current thread suspension when @value{GDBN} has
13257control. Setting it to on takes effect immediately, and the current
13258thread is suspended whenever @value{GDBN} gets control. Setting it to
13259off will take effect the next time the inferior is continued.
13260Normally, this command has no effect, since when @value{GDBN} has
13261control, the whole task is suspended. However, if you used @code{set
13262task pause off} (see above), this command comes in handy to suspend
13263only the current thread.
13264
13265@item show thread pause
13266@kindex show thread@r{, Hurd command}
13267This command shows the state of current thread suspension.
13268
13269@item set thread run
13270This comamnd sets whether the current thread is allowed to run.
13271
13272@item show thread run
13273Show whether the current thread is allowed to run.
13274
13275@item set thread detach-suspend-count
13276@cindex thread suspend count, @sc{gnu} Hurd
13277@cindex detach from thread, @sc{gnu} Hurd
13278This command sets the suspend count @value{GDBN} will leave on a
13279thread when detaching. This number is relative to the suspend count
13280found by @value{GDBN} when it notices the thread; use @code{set thread
13281takeover-suspend-count} to force it to an absolute value.
13282
13283@item show thread detach-suspend-count
13284Show the suspend count @value{GDBN} will leave on the thread when
13285detaching.
13286
13287@item set thread exception-port
13288@itemx set thread excp
13289Set the thread exception port to which to forward exceptions. This
13290overrides the port set by @code{set task exception-port} (see above).
13291@code{set thread excp} is the shorthand alias.
13292
13293@item set thread takeover-suspend-count
13294Normally, @value{GDBN}'s thread suspend counts are relative to the
13295value @value{GDBN} finds when it notices each thread. This command
13296changes the suspend counts to be absolute instead.
13297
13298@item set thread default
13299@itemx show thread default
13300@cindex thread default settings, @sc{gnu} Hurd
13301Each of the above @code{set thread} commands has a @code{set thread
13302default} counterpart (e.g., @code{set thread default pause}, @code{set
13303thread default exception-port}, etc.). The @code{thread default}
13304variety of commands sets the default thread properties for all
13305threads; you can then change the properties of individual threads with
13306the non-default commands.
13307@end table
13308
13309
a64548ea
EZ
13310@node Neutrino
13311@subsection QNX Neutrino
13312@cindex QNX Neutrino
13313
13314@value{GDBN} provides the following commands specific to the QNX
13315Neutrino target:
13316
13317@table @code
13318@item set debug nto-debug
13319@kindex set debug nto-debug
13320When set to on, enables debugging messages specific to the QNX
13321Neutrino support.
13322
13323@item show debug nto-debug
13324@kindex show debug nto-debug
13325Show the current state of QNX Neutrino messages.
13326@end table
13327
13328
8e04817f
AC
13329@node Embedded OS
13330@section Embedded Operating Systems
104c1213 13331
8e04817f
AC
13332This section describes configurations involving the debugging of
13333embedded operating systems that are available for several different
13334architectures.
d4f3574e 13335
8e04817f
AC
13336@menu
13337* VxWorks:: Using @value{GDBN} with VxWorks
13338@end menu
104c1213 13339
8e04817f
AC
13340@value{GDBN} includes the ability to debug programs running on
13341various real-time operating systems.
104c1213 13342
8e04817f
AC
13343@node VxWorks
13344@subsection Using @value{GDBN} with VxWorks
104c1213 13345
8e04817f 13346@cindex VxWorks
104c1213 13347
8e04817f 13348@table @code
104c1213 13349
8e04817f
AC
13350@kindex target vxworks
13351@item target vxworks @var{machinename}
13352A VxWorks system, attached via TCP/IP. The argument @var{machinename}
13353is the target system's machine name or IP address.
104c1213 13354
8e04817f 13355@end table
104c1213 13356
8e04817f
AC
13357On VxWorks, @code{load} links @var{filename} dynamically on the
13358current target system as well as adding its symbols in @value{GDBN}.
104c1213 13359
8e04817f
AC
13360@value{GDBN} enables developers to spawn and debug tasks running on networked
13361VxWorks targets from a Unix host. Already-running tasks spawned from
13362the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
13363both the Unix host and on the VxWorks target. The program
13364@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
13365installed with the name @code{vxgdb}, to distinguish it from a
13366@value{GDBN} for debugging programs on the host itself.)
104c1213 13367
8e04817f
AC
13368@table @code
13369@item VxWorks-timeout @var{args}
13370@kindex vxworks-timeout
13371All VxWorks-based targets now support the option @code{vxworks-timeout}.
13372This option is set by the user, and @var{args} represents the number of
13373seconds @value{GDBN} waits for responses to rpc's. You might use this if
13374your VxWorks target is a slow software simulator or is on the far side
13375of a thin network line.
13376@end table
104c1213 13377
8e04817f
AC
13378The following information on connecting to VxWorks was current when
13379this manual was produced; newer releases of VxWorks may use revised
13380procedures.
104c1213 13381
4644b6e3 13382@findex INCLUDE_RDB
8e04817f
AC
13383To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
13384to include the remote debugging interface routines in the VxWorks
13385library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
13386VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
13387kernel. The resulting kernel contains @file{rdb.a}, and spawns the
13388source debugging task @code{tRdbTask} when VxWorks is booted. For more
13389information on configuring and remaking VxWorks, see the manufacturer's
13390manual.
13391@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 13392
8e04817f
AC
13393Once you have included @file{rdb.a} in your VxWorks system image and set
13394your Unix execution search path to find @value{GDBN}, you are ready to
13395run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
13396@code{vxgdb}, depending on your installation).
104c1213 13397
8e04817f 13398@value{GDBN} comes up showing the prompt:
104c1213 13399
474c8240 13400@smallexample
8e04817f 13401(vxgdb)
474c8240 13402@end smallexample
104c1213 13403
8e04817f
AC
13404@menu
13405* VxWorks Connection:: Connecting to VxWorks
13406* VxWorks Download:: VxWorks download
13407* VxWorks Attach:: Running tasks
13408@end menu
104c1213 13409
8e04817f
AC
13410@node VxWorks Connection
13411@subsubsection Connecting to VxWorks
104c1213 13412
8e04817f
AC
13413The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
13414network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 13415
474c8240 13416@smallexample
8e04817f 13417(vxgdb) target vxworks tt
474c8240 13418@end smallexample
104c1213 13419
8e04817f
AC
13420@need 750
13421@value{GDBN} displays messages like these:
104c1213 13422
8e04817f
AC
13423@smallexample
13424Attaching remote machine across net...
13425Connected to tt.
13426@end smallexample
104c1213 13427
8e04817f
AC
13428@need 1000
13429@value{GDBN} then attempts to read the symbol tables of any object modules
13430loaded into the VxWorks target since it was last booted. @value{GDBN} locates
13431these files by searching the directories listed in the command search
13432path (@pxref{Environment, ,Your program's environment}); if it fails
13433to find an object file, it displays a message such as:
5d161b24 13434
474c8240 13435@smallexample
8e04817f 13436prog.o: No such file or directory.
474c8240 13437@end smallexample
104c1213 13438
8e04817f
AC
13439When this happens, add the appropriate directory to the search path with
13440the @value{GDBN} command @code{path}, and execute the @code{target}
13441command again.
104c1213 13442
8e04817f
AC
13443@node VxWorks Download
13444@subsubsection VxWorks download
104c1213 13445
8e04817f
AC
13446@cindex download to VxWorks
13447If you have connected to the VxWorks target and you want to debug an
13448object that has not yet been loaded, you can use the @value{GDBN}
13449@code{load} command to download a file from Unix to VxWorks
13450incrementally. The object file given as an argument to the @code{load}
13451command is actually opened twice: first by the VxWorks target in order
13452to download the code, then by @value{GDBN} in order to read the symbol
13453table. This can lead to problems if the current working directories on
13454the two systems differ. If both systems have NFS mounted the same
13455filesystems, you can avoid these problems by using absolute paths.
13456Otherwise, it is simplest to set the working directory on both systems
13457to the directory in which the object file resides, and then to reference
13458the file by its name, without any path. For instance, a program
13459@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
13460and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
13461program, type this on VxWorks:
104c1213 13462
474c8240 13463@smallexample
8e04817f 13464-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 13465@end smallexample
104c1213 13466
8e04817f
AC
13467@noindent
13468Then, in @value{GDBN}, type:
104c1213 13469
474c8240 13470@smallexample
8e04817f
AC
13471(vxgdb) cd @var{hostpath}/vw/demo/rdb
13472(vxgdb) load prog.o
474c8240 13473@end smallexample
104c1213 13474
8e04817f 13475@value{GDBN} displays a response similar to this:
104c1213 13476
8e04817f
AC
13477@smallexample
13478Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
13479@end smallexample
104c1213 13480
8e04817f
AC
13481You can also use the @code{load} command to reload an object module
13482after editing and recompiling the corresponding source file. Note that
13483this makes @value{GDBN} delete all currently-defined breakpoints,
13484auto-displays, and convenience variables, and to clear the value
13485history. (This is necessary in order to preserve the integrity of
13486debugger's data structures that reference the target system's symbol
13487table.)
104c1213 13488
8e04817f
AC
13489@node VxWorks Attach
13490@subsubsection Running tasks
104c1213
JM
13491
13492@cindex running VxWorks tasks
13493You can also attach to an existing task using the @code{attach} command as
13494follows:
13495
474c8240 13496@smallexample
104c1213 13497(vxgdb) attach @var{task}
474c8240 13498@end smallexample
104c1213
JM
13499
13500@noindent
13501where @var{task} is the VxWorks hexadecimal task ID. The task can be running
13502or suspended when you attach to it. Running tasks are suspended at
13503the time of attachment.
13504
6d2ebf8b 13505@node Embedded Processors
104c1213
JM
13506@section Embedded Processors
13507
13508This section goes into details specific to particular embedded
13509configurations.
13510
c45da7e6
EZ
13511@cindex send command to simulator
13512Whenever a specific embedded processor has a simulator, @value{GDBN}
13513allows to send an arbitrary command to the simulator.
13514
13515@table @code
13516@item sim @var{command}
13517@kindex sim@r{, a command}
13518Send an arbitrary @var{command} string to the simulator. Consult the
13519documentation for the specific simulator in use for information about
13520acceptable commands.
13521@end table
13522
7d86b5d5 13523
104c1213 13524@menu
c45da7e6 13525* ARM:: ARM RDI
172c2a43
KI
13526* H8/300:: Renesas H8/300
13527* H8/500:: Renesas H8/500
13528* M32R/D:: Renesas M32R/D
104c1213 13529* M68K:: Motorola M68K
104c1213 13530* MIPS Embedded:: MIPS Embedded
a37295f9 13531* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
13532* PA:: HP PA Embedded
13533* PowerPC: PowerPC
172c2a43 13534* SH:: Renesas SH
104c1213
JM
13535* Sparclet:: Tsqware Sparclet
13536* Sparclite:: Fujitsu Sparclite
13537* ST2000:: Tandem ST2000
13538* Z8000:: Zilog Z8000
a64548ea
EZ
13539* AVR:: Atmel AVR
13540* CRIS:: CRIS
13541* Super-H:: Renesas Super-H
c45da7e6 13542* WinCE:: Windows CE child processes
104c1213
JM
13543@end menu
13544
6d2ebf8b 13545@node ARM
104c1213 13546@subsection ARM
c45da7e6 13547@cindex ARM RDI
104c1213
JM
13548
13549@table @code
8e04817f
AC
13550@kindex target rdi
13551@item target rdi @var{dev}
13552ARM Angel monitor, via RDI library interface to ADP protocol. You may
13553use this target to communicate with both boards running the Angel
13554monitor, or with the EmbeddedICE JTAG debug device.
13555
13556@kindex target rdp
13557@item target rdp @var{dev}
13558ARM Demon monitor.
13559
13560@end table
13561
e2f4edfd
EZ
13562@value{GDBN} provides the following ARM-specific commands:
13563
13564@table @code
13565@item set arm disassembler
13566@kindex set arm
13567This commands selects from a list of disassembly styles. The
13568@code{"std"} style is the standard style.
13569
13570@item show arm disassembler
13571@kindex show arm
13572Show the current disassembly style.
13573
13574@item set arm apcs32
13575@cindex ARM 32-bit mode
13576This command toggles ARM operation mode between 32-bit and 26-bit.
13577
13578@item show arm apcs32
13579Display the current usage of the ARM 32-bit mode.
13580
13581@item set arm fpu @var{fputype}
13582This command sets the ARM floating-point unit (FPU) type. The
13583argument @var{fputype} can be one of these:
13584
13585@table @code
13586@item auto
13587Determine the FPU type by querying the OS ABI.
13588@item softfpa
13589Software FPU, with mixed-endian doubles on little-endian ARM
13590processors.
13591@item fpa
13592GCC-compiled FPA co-processor.
13593@item softvfp
13594Software FPU with pure-endian doubles.
13595@item vfp
13596VFP co-processor.
13597@end table
13598
13599@item show arm fpu
13600Show the current type of the FPU.
13601
13602@item set arm abi
13603This command forces @value{GDBN} to use the specified ABI.
13604
13605@item show arm abi
13606Show the currently used ABI.
13607
13608@item set debug arm
13609Toggle whether to display ARM-specific debugging messages from the ARM
13610target support subsystem.
13611
13612@item show debug arm
13613Show whether ARM-specific debugging messages are enabled.
13614@end table
13615
c45da7e6
EZ
13616The following commands are available when an ARM target is debugged
13617using the RDI interface:
13618
13619@table @code
13620@item rdilogfile @r{[}@var{file}@r{]}
13621@kindex rdilogfile
13622@cindex ADP (Angel Debugger Protocol) logging
13623Set the filename for the ADP (Angel Debugger Protocol) packet log.
13624With an argument, sets the log file to the specified @var{file}. With
13625no argument, show the current log file name. The default log file is
13626@file{rdi.log}.
13627
13628@item rdilogenable @r{[}@var{arg}@r{]}
13629@kindex rdilogenable
13630Control logging of ADP packets. With an argument of 1 or @code{"yes"}
13631enables logging, with an argument 0 or @code{"no"} disables it. With
13632no arguments displays the current setting. When logging is enabled,
13633ADP packets exchanged between @value{GDBN} and the RDI target device
13634are logged to a file.
13635
13636@item set rdiromatzero
13637@kindex set rdiromatzero
13638@cindex ROM at zero address, RDI
13639Tell @value{GDBN} whether the target has ROM at address 0. If on,
13640vector catching is disabled, so that zero address can be used. If off
13641(the default), vector catching is enabled. For this command to take
13642effect, it needs to be invoked prior to the @code{target rdi} command.
13643
13644@item show rdiromatzero
13645@kindex show rdiromatzero
13646Show the current setting of ROM at zero address.
13647
13648@item set rdiheartbeat
13649@kindex set rdiheartbeat
13650@cindex RDI heartbeat
13651Enable or disable RDI heartbeat packets. It is not recommended to
13652turn on this option, since it confuses ARM and EPI JTAG interface, as
13653well as the Angel monitor.
13654
13655@item show rdiheartbeat
13656@kindex show rdiheartbeat
13657Show the setting of RDI heartbeat packets.
13658@end table
13659
e2f4edfd 13660
8e04817f 13661@node H8/300
172c2a43 13662@subsection Renesas H8/300
8e04817f
AC
13663
13664@table @code
13665
13666@kindex target hms@r{, with H8/300}
13667@item target hms @var{dev}
172c2a43 13668A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
13669Use special commands @code{device} and @code{speed} to control the serial
13670line and the communications speed used.
13671
13672@kindex target e7000@r{, with H8/300}
13673@item target e7000 @var{dev}
172c2a43 13674E7000 emulator for Renesas H8 and SH.
8e04817f
AC
13675
13676@kindex target sh3@r{, with H8/300}
13677@kindex target sh3e@r{, with H8/300}
13678@item target sh3 @var{dev}
13679@itemx target sh3e @var{dev}
172c2a43 13680Renesas SH-3 and SH-3E target systems.
8e04817f
AC
13681
13682@end table
13683
13684@cindex download to H8/300 or H8/500
13685@cindex H8/300 or H8/500 download
172c2a43
KI
13686@cindex download to Renesas SH
13687@cindex Renesas SH download
13688When you select remote debugging to a Renesas SH, H8/300, or H8/500
13689board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
13690board and also opens it as the current executable target for
13691@value{GDBN} on your host (like the @code{file} command).
13692
13693@value{GDBN} needs to know these things to talk to your
172c2a43 13694Renesas SH, H8/300, or H8/500:
8e04817f
AC
13695
13696@enumerate
13697@item
13698that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
13699for Renesas microprocessors, or @samp{target e7000}, the in-circuit
13700emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
13701the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
13702H8/300, or H8/500.)
13703
13704@item
172c2a43 13705what serial device connects your host to your Renesas board (the first
8e04817f
AC
13706serial device available on your host is the default).
13707
13708@item
13709what speed to use over the serial device.
13710@end enumerate
13711
13712@menu
172c2a43
KI
13713* Renesas Boards:: Connecting to Renesas boards.
13714* Renesas ICE:: Using the E7000 In-Circuit Emulator.
13715* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
13716@end menu
13717
172c2a43
KI
13718@node Renesas Boards
13719@subsubsection Connecting to Renesas boards
8e04817f
AC
13720
13721@c only for Unix hosts
13722@kindex device
172c2a43 13723@cindex serial device, Renesas micros
8e04817f
AC
13724Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
13725need to explicitly set the serial device. The default @var{port} is the
13726first available port on your host. This is only necessary on Unix
13727hosts, where it is typically something like @file{/dev/ttya}.
13728
13729@kindex speed
172c2a43 13730@cindex serial line speed, Renesas micros
8e04817f
AC
13731@code{@value{GDBN}} has another special command to set the communications
13732speed: @samp{speed @var{bps}}. This command also is only used from Unix
13733hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
13734the DOS @code{mode} command (for instance,
13735@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
13736
13737The @samp{device} and @samp{speed} commands are available only when you
172c2a43 13738use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
13739use a DOS host,
13740@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
13741called @code{asynctsr} to communicate with the development board
13742through a PC serial port. You must also use the DOS @code{mode} command
13743to set up the serial port on the DOS side.
13744
13745The following sample session illustrates the steps needed to start a
13746program under @value{GDBN} control on an H8/300. The example uses a
13747sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 13748the Renesas SH and the H8/500.
8e04817f
AC
13749
13750First hook up your development board. In this example, we use a
13751board attached to serial port @code{COM2}; if you use a different serial
13752port, substitute its name in the argument of the @code{mode} command.
13753When you call @code{asynctsr}, the auxiliary comms program used by the
13754debugger, you give it just the numeric part of the serial port's name;
13755for example, @samp{asyncstr 2} below runs @code{asyncstr} on
13756@code{COM2}.
13757
474c8240 13758@smallexample
8e04817f
AC
13759C:\H8300\TEST> asynctsr 2
13760C:\H8300\TEST> mode com2:9600,n,8,1,p
13761
13762Resident portion of MODE loaded
13763
13764COM2: 9600, n, 8, 1, p
13765
474c8240 13766@end smallexample
8e04817f
AC
13767
13768@quotation
13769@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
13770@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
13771disable it, or even boot without it, to use @code{asynctsr} to control
13772your development board.
13773@end quotation
13774
13775@kindex target hms@r{, and serial protocol}
13776Now that serial communications are set up, and the development board is
9c16f35a 13777connected, you can start up @value{GDBN}. Call @code{@value{GDBN}} with
8e04817f
AC
13778the name of your program as the argument. @code{@value{GDBN}} prompts
13779you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
13780commands to begin your debugging session: @samp{target hms} to specify
172c2a43 13781cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
13782download your program to the board. @code{load} displays the names of
13783the program's sections, and a @samp{*} for each 2K of data downloaded.
13784(If you want to refresh @value{GDBN} data on symbols or on the
13785executable file without downloading, use the @value{GDBN} commands
13786@code{file} or @code{symbol-file}. These commands, and @code{load}
13787itself, are described in @ref{Files,,Commands to specify files}.)
13788
13789@smallexample
13790(eg-C:\H8300\TEST) @value{GDBP} t.x
13791@value{GDBN} is free software and you are welcome to distribute copies
13792 of it under certain conditions; type "show copying" to see
13793 the conditions.
13794There is absolutely no warranty for @value{GDBN}; type "show warranty"
13795for details.
13796@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
13797(@value{GDBP}) target hms
13798Connected to remote H8/300 HMS system.
13799(@value{GDBP}) load t.x
13800.text : 0x8000 .. 0xabde ***********
13801.data : 0xabde .. 0xad30 *
13802.stack : 0xf000 .. 0xf014 *
13803@end smallexample
13804
13805At this point, you're ready to run or debug your program. From here on,
13806you can use all the usual @value{GDBN} commands. The @code{break} command
13807sets breakpoints; the @code{run} command starts your program;
13808@code{print} or @code{x} display data; the @code{continue} command
13809resumes execution after stopping at a breakpoint. You can use the
13810@code{help} command at any time to find out more about @value{GDBN} commands.
13811
13812Remember, however, that @emph{operating system} facilities aren't
13813available on your development board; for example, if your program hangs,
13814you can't send an interrupt---but you can press the @sc{reset} switch!
13815
13816Use the @sc{reset} button on the development board
13817@itemize @bullet
13818@item
13819to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
13820no way to pass an interrupt signal to the development board); and
13821
13822@item
13823to return to the @value{GDBN} command prompt after your program finishes
13824normally. The communications protocol provides no other way for @value{GDBN}
13825to detect program completion.
13826@end itemize
13827
13828In either case, @value{GDBN} sees the effect of a @sc{reset} on the
13829development board as a ``normal exit'' of your program.
13830
172c2a43 13831@node Renesas ICE
8e04817f
AC
13832@subsubsection Using the E7000 in-circuit emulator
13833
172c2a43 13834@kindex target e7000@r{, with Renesas ICE}
8e04817f 13835You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 13836Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
13837e7000} command to connect @value{GDBN} to your E7000:
13838
13839@table @code
13840@item target e7000 @var{port} @var{speed}
13841Use this form if your E7000 is connected to a serial port. The
13842@var{port} argument identifies what serial port to use (for example,
13843@samp{com2}). The third argument is the line speed in bits per second
13844(for example, @samp{9600}).
13845
13846@item target e7000 @var{hostname}
13847If your E7000 is installed as a host on a TCP/IP network, you can just
13848specify its hostname; @value{GDBN} uses @code{telnet} to connect.
13849@end table
13850
ba04e063
EZ
13851The following special commands are available when debugging with the
13852Renesas E7000 ICE:
13853
13854@table @code
13855@item e7000 @var{command}
13856@kindex e7000
13857@cindex send command to E7000 monitor
13858This sends the specified @var{command} to the E7000 monitor.
13859
13860@item ftplogin @var{machine} @var{username} @var{password} @var{dir}
13861@kindex ftplogin@r{, E7000}
13862This command records information for subsequent interface with the
13863E7000 monitor via the FTP protocol: @value{GDBN} will log into the
13864named @var{machine} using specified @var{username} and @var{password},
13865and then chdir to the named directory @var{dir}.
13866
13867@item ftpload @var{file}
13868@kindex ftpload@r{, E7000}
13869This command uses credentials recorded by @code{ftplogin} to fetch and
13870load the named @var{file} from the E7000 monitor.
13871
13872@item drain
13873@kindex drain@r{, E7000}
13874This command drains any pending text buffers stored on the E7000.
13875
13876@item set usehardbreakpoints
13877@itemx show usehardbreakpoints
13878@kindex set usehardbreakpoints@r{, E7000}
13879@kindex show usehardbreakpoints@r{, E7000}
13880@cindex hardware breakpoints, and E7000
13881These commands set and show the use of hardware breakpoints for all
13882breakpoints. @xref{Set Breaks, hardware-assisted breakpoint}, for
13883more information about using hardware breakpoints selectively.
13884@end table
13885
172c2a43
KI
13886@node Renesas Special
13887@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
13888
13889Some @value{GDBN} commands are available only for the H8/300:
13890
13891@table @code
13892
13893@kindex set machine
13894@kindex show machine
13895@item set machine h8300
13896@itemx set machine h8300h
13897Condition @value{GDBN} for one of the two variants of the H8/300
13898architecture with @samp{set machine}. You can use @samp{show machine}
13899to check which variant is currently in effect.
104c1213
JM
13900
13901@end table
13902
8e04817f
AC
13903@node H8/500
13904@subsection H8/500
104c1213
JM
13905
13906@table @code
13907
8e04817f
AC
13908@kindex set memory @var{mod}
13909@cindex memory models, H8/500
13910@item set memory @var{mod}
13911@itemx show memory
13912Specify which H8/500 memory model (@var{mod}) you are using with
13913@samp{set memory}; check which memory model is in effect with @samp{show
13914memory}. The accepted values for @var{mod} are @code{small},
13915@code{big}, @code{medium}, and @code{compact}.
104c1213 13916
8e04817f 13917@end table
104c1213 13918
8e04817f 13919@node M32R/D
ba04e063 13920@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
13921
13922@table @code
8e04817f
AC
13923@kindex target m32r
13924@item target m32r @var{dev}
172c2a43 13925Renesas M32R/D ROM monitor.
8e04817f 13926
fb3e19c0
KI
13927@kindex target m32rsdi
13928@item target m32rsdi @var{dev}
13929Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
13930@end table
13931
13932The following @value{GDBN} commands are specific to the M32R monitor:
13933
13934@table @code
13935@item set download-path @var{path}
13936@kindex set download-path
13937@cindex find downloadable @sc{srec} files (M32R)
13938Set the default path for finding donwloadable @sc{srec} files.
13939
13940@item show download-path
13941@kindex show download-path
13942Show the default path for downloadable @sc{srec} files.
fb3e19c0 13943
721c2651
EZ
13944@item set board-address @var{addr}
13945@kindex set board-address
13946@cindex M32-EVA target board address
13947Set the IP address for the M32R-EVA target board.
13948
13949@item show board-address
13950@kindex show board-address
13951Show the current IP address of the target board.
13952
13953@item set server-address @var{addr}
13954@kindex set server-address
13955@cindex download server address (M32R)
13956Set the IP address for the download server, which is the @value{GDBN}'s
13957host machine.
13958
13959@item show server-address
13960@kindex show server-address
13961Display the IP address of the download server.
13962
13963@item upload @r{[}@var{file}@r{]}
13964@kindex upload@r{, M32R}
13965Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
13966upload capability. If no @var{file} argument is given, the current
13967executable file is uploaded.
13968
13969@item tload @r{[}@var{file}@r{]}
13970@kindex tload@r{, M32R}
13971Test the @code{upload} command.
8e04817f
AC
13972@end table
13973
ba04e063
EZ
13974The following commands are available for M32R/SDI:
13975
13976@table @code
13977@item sdireset
13978@kindex sdireset
13979@cindex reset SDI connection, M32R
13980This command resets the SDI connection.
13981
13982@item sdistatus
13983@kindex sdistatus
13984This command shows the SDI connection status.
13985
13986@item debug_chaos
13987@kindex debug_chaos
13988@cindex M32R/Chaos debugging
13989Instructs the remote that M32R/Chaos debugging is to be used.
13990
13991@item use_debug_dma
13992@kindex use_debug_dma
13993Instructs the remote to use the DEBUG_DMA method of accessing memory.
13994
13995@item use_mon_code
13996@kindex use_mon_code
13997Instructs the remote to use the MON_CODE method of accessing memory.
13998
13999@item use_ib_break
14000@kindex use_ib_break
14001Instructs the remote to set breakpoints by IB break.
14002
14003@item use_dbt_break
14004@kindex use_dbt_break
14005Instructs the remote to set breakpoints by DBT.
14006@end table
14007
8e04817f
AC
14008@node M68K
14009@subsection M68k
14010
14011The Motorola m68k configuration includes ColdFire support, and
14012target command for the following ROM monitors.
14013
14014@table @code
14015
14016@kindex target abug
14017@item target abug @var{dev}
14018ABug ROM monitor for M68K.
14019
14020@kindex target cpu32bug
14021@item target cpu32bug @var{dev}
14022CPU32BUG monitor, running on a CPU32 (M68K) board.
14023
14024@kindex target dbug
14025@item target dbug @var{dev}
14026dBUG ROM monitor for Motorola ColdFire.
14027
14028@kindex target est
14029@item target est @var{dev}
14030EST-300 ICE monitor, running on a CPU32 (M68K) board.
14031
14032@kindex target rom68k
14033@item target rom68k @var{dev}
14034ROM 68K monitor, running on an M68K IDP board.
14035
14036@end table
14037
8e04817f
AC
14038@table @code
14039
14040@kindex target rombug
14041@item target rombug @var{dev}
14042ROMBUG ROM monitor for OS/9000.
14043
14044@end table
14045
8e04817f
AC
14046@node MIPS Embedded
14047@subsection MIPS Embedded
14048
14049@cindex MIPS boards
14050@value{GDBN} can use the MIPS remote debugging protocol to talk to a
14051MIPS board attached to a serial line. This is available when
14052you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 14053
8e04817f
AC
14054@need 1000
14055Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 14056
8e04817f
AC
14057@table @code
14058@item target mips @var{port}
14059@kindex target mips @var{port}
14060To run a program on the board, start up @code{@value{GDBP}} with the
14061name of your program as the argument. To connect to the board, use the
14062command @samp{target mips @var{port}}, where @var{port} is the name of
14063the serial port connected to the board. If the program has not already
14064been downloaded to the board, you may use the @code{load} command to
14065download it. You can then use all the usual @value{GDBN} commands.
104c1213 14066
8e04817f
AC
14067For example, this sequence connects to the target board through a serial
14068port, and loads and runs a program called @var{prog} through the
14069debugger:
104c1213 14070
474c8240 14071@smallexample
8e04817f
AC
14072host$ @value{GDBP} @var{prog}
14073@value{GDBN} is free software and @dots{}
14074(@value{GDBP}) target mips /dev/ttyb
14075(@value{GDBP}) load @var{prog}
14076(@value{GDBP}) run
474c8240 14077@end smallexample
104c1213 14078
8e04817f
AC
14079@item target mips @var{hostname}:@var{portnumber}
14080On some @value{GDBN} host configurations, you can specify a TCP
14081connection (for instance, to a serial line managed by a terminal
14082concentrator) instead of a serial port, using the syntax
14083@samp{@var{hostname}:@var{portnumber}}.
104c1213 14084
8e04817f
AC
14085@item target pmon @var{port}
14086@kindex target pmon @var{port}
14087PMON ROM monitor.
104c1213 14088
8e04817f
AC
14089@item target ddb @var{port}
14090@kindex target ddb @var{port}
14091NEC's DDB variant of PMON for Vr4300.
104c1213 14092
8e04817f
AC
14093@item target lsi @var{port}
14094@kindex target lsi @var{port}
14095LSI variant of PMON.
104c1213 14096
8e04817f
AC
14097@kindex target r3900
14098@item target r3900 @var{dev}
14099Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 14100
8e04817f
AC
14101@kindex target array
14102@item target array @var{dev}
14103Array Tech LSI33K RAID controller board.
104c1213 14104
8e04817f 14105@end table
104c1213 14106
104c1213 14107
8e04817f
AC
14108@noindent
14109@value{GDBN} also supports these special commands for MIPS targets:
104c1213 14110
8e04817f 14111@table @code
8e04817f
AC
14112@item set mipsfpu double
14113@itemx set mipsfpu single
14114@itemx set mipsfpu none
a64548ea 14115@itemx set mipsfpu auto
8e04817f
AC
14116@itemx show mipsfpu
14117@kindex set mipsfpu
14118@kindex show mipsfpu
14119@cindex MIPS remote floating point
14120@cindex floating point, MIPS remote
14121If your target board does not support the MIPS floating point
14122coprocessor, you should use the command @samp{set mipsfpu none} (if you
14123need this, you may wish to put the command in your @value{GDBN} init
14124file). This tells @value{GDBN} how to find the return value of
14125functions which return floating point values. It also allows
14126@value{GDBN} to avoid saving the floating point registers when calling
14127functions on the board. If you are using a floating point coprocessor
14128with only single precision floating point support, as on the @sc{r4650}
14129processor, use the command @samp{set mipsfpu single}. The default
14130double precision floating point coprocessor may be selected using
14131@samp{set mipsfpu double}.
104c1213 14132
8e04817f
AC
14133In previous versions the only choices were double precision or no
14134floating point, so @samp{set mipsfpu on} will select double precision
14135and @samp{set mipsfpu off} will select no floating point.
104c1213 14136
8e04817f
AC
14137As usual, you can inquire about the @code{mipsfpu} variable with
14138@samp{show mipsfpu}.
104c1213 14139
8e04817f
AC
14140@item set timeout @var{seconds}
14141@itemx set retransmit-timeout @var{seconds}
14142@itemx show timeout
14143@itemx show retransmit-timeout
14144@cindex @code{timeout}, MIPS protocol
14145@cindex @code{retransmit-timeout}, MIPS protocol
14146@kindex set timeout
14147@kindex show timeout
14148@kindex set retransmit-timeout
14149@kindex show retransmit-timeout
14150You can control the timeout used while waiting for a packet, in the MIPS
14151remote protocol, with the @code{set timeout @var{seconds}} command. The
14152default is 5 seconds. Similarly, you can control the timeout used while
14153waiting for an acknowledgement of a packet with the @code{set
14154retransmit-timeout @var{seconds}} command. The default is 3 seconds.
14155You can inspect both values with @code{show timeout} and @code{show
14156retransmit-timeout}. (These commands are @emph{only} available when
14157@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 14158
8e04817f
AC
14159The timeout set by @code{set timeout} does not apply when @value{GDBN}
14160is waiting for your program to stop. In that case, @value{GDBN} waits
14161forever because it has no way of knowing how long the program is going
14162to run before stopping.
ba04e063
EZ
14163
14164@item set syn-garbage-limit @var{num}
14165@kindex set syn-garbage-limit@r{, MIPS remote}
14166@cindex synchronize with remote MIPS target
14167Limit the maximum number of characters @value{GDBN} should ignore when
14168it tries to synchronize with the remote target. The default is 10
14169characters. Setting the limit to -1 means there's no limit.
14170
14171@item show syn-garbage-limit
14172@kindex show syn-garbage-limit@r{, MIPS remote}
14173Show the current limit on the number of characters to ignore when
14174trying to synchronize with the remote system.
14175
14176@item set monitor-prompt @var{prompt}
14177@kindex set monitor-prompt@r{, MIPS remote}
14178@cindex remote monitor prompt
14179Tell @value{GDBN} to expect the specified @var{prompt} string from the
14180remote monitor. The default depends on the target:
14181@table @asis
14182@item pmon target
14183@samp{PMON}
14184@item ddb target
14185@samp{NEC010}
14186@item lsi target
14187@samp{PMON>}
14188@end table
14189
14190@item show monitor-prompt
14191@kindex show monitor-prompt@r{, MIPS remote}
14192Show the current strings @value{GDBN} expects as the prompt from the
14193remote monitor.
14194
14195@item set monitor-warnings
14196@kindex set monitor-warnings@r{, MIPS remote}
14197Enable or disable monitor warnings about hardware breakpoints. This
14198has effect only for the @code{lsi} target. When on, @value{GDBN} will
14199display warning messages whose codes are returned by the @code{lsi}
14200PMON monitor for breakpoint commands.
14201
14202@item show monitor-warnings
14203@kindex show monitor-warnings@r{, MIPS remote}
14204Show the current setting of printing monitor warnings.
14205
14206@item pmon @var{command}
14207@kindex pmon@r{, MIPS remote}
14208@cindex send PMON command
14209This command allows sending an arbitrary @var{command} string to the
14210monitor. The monitor must be in debug mode for this to work.
8e04817f 14211@end table
104c1213 14212
a37295f9
MM
14213@node OpenRISC 1000
14214@subsection OpenRISC 1000
14215@cindex OpenRISC 1000
14216
14217@cindex or1k boards
14218See OR1k Architecture document (@uref{www.opencores.org}) for more information
14219about platform and commands.
14220
14221@table @code
14222
14223@kindex target jtag
14224@item target jtag jtag://@var{host}:@var{port}
14225
14226Connects to remote JTAG server.
14227JTAG remote server can be either an or1ksim or JTAG server,
14228connected via parallel port to the board.
14229
14230Example: @code{target jtag jtag://localhost:9999}
14231
14232@kindex or1ksim
14233@item or1ksim @var{command}
14234If connected to @code{or1ksim} OpenRISC 1000 Architectural
14235Simulator, proprietary commands can be executed.
14236
14237@kindex info or1k spr
14238@item info or1k spr
14239Displays spr groups.
14240
14241@item info or1k spr @var{group}
14242@itemx info or1k spr @var{groupno}
14243Displays register names in selected group.
14244
14245@item info or1k spr @var{group} @var{register}
14246@itemx info or1k spr @var{register}
14247@itemx info or1k spr @var{groupno} @var{registerno}
14248@itemx info or1k spr @var{registerno}
14249Shows information about specified spr register.
14250
14251@kindex spr
14252@item spr @var{group} @var{register} @var{value}
14253@itemx spr @var{register @var{value}}
14254@itemx spr @var{groupno} @var{registerno @var{value}}
14255@itemx spr @var{registerno @var{value}}
14256Writes @var{value} to specified spr register.
14257@end table
14258
14259Some implementations of OpenRISC 1000 Architecture also have hardware trace.
14260It is very similar to @value{GDBN} trace, except it does not interfere with normal
14261program execution and is thus much faster. Hardware breakpoints/watchpoint
14262triggers can be set using:
14263@table @code
14264@item $LEA/$LDATA
14265Load effective address/data
14266@item $SEA/$SDATA
14267Store effective address/data
14268@item $AEA/$ADATA
14269Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
14270@item $FETCH
14271Fetch data
14272@end table
14273
14274When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
14275@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
14276
14277@code{htrace} commands:
14278@cindex OpenRISC 1000 htrace
14279@table @code
14280@kindex hwatch
14281@item hwatch @var{conditional}
14282Set hardware watchpoint on combination of Load/Store Effecive Address(es)
14283or Data. For example:
14284
14285@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14286
14287@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14288
4644b6e3 14289@kindex htrace
a37295f9
MM
14290@item htrace info
14291Display information about current HW trace configuration.
14292
a37295f9
MM
14293@item htrace trigger @var{conditional}
14294Set starting criteria for HW trace.
14295
a37295f9
MM
14296@item htrace qualifier @var{conditional}
14297Set acquisition qualifier for HW trace.
14298
a37295f9
MM
14299@item htrace stop @var{conditional}
14300Set HW trace stopping criteria.
14301
f153cc92 14302@item htrace record [@var{data}]*
a37295f9
MM
14303Selects the data to be recorded, when qualifier is met and HW trace was
14304triggered.
14305
a37295f9 14306@item htrace enable
a37295f9
MM
14307@itemx htrace disable
14308Enables/disables the HW trace.
14309
f153cc92 14310@item htrace rewind [@var{filename}]
a37295f9
MM
14311Clears currently recorded trace data.
14312
14313If filename is specified, new trace file is made and any newly collected data
14314will be written there.
14315
f153cc92 14316@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
14317Prints trace buffer, using current record configuration.
14318
a37295f9
MM
14319@item htrace mode continuous
14320Set continuous trace mode.
14321
a37295f9
MM
14322@item htrace mode suspend
14323Set suspend trace mode.
14324
14325@end table
14326
8e04817f
AC
14327@node PowerPC
14328@subsection PowerPC
104c1213
JM
14329
14330@table @code
8e04817f
AC
14331@kindex target dink32
14332@item target dink32 @var{dev}
14333DINK32 ROM monitor.
104c1213 14334
8e04817f
AC
14335@kindex target ppcbug
14336@item target ppcbug @var{dev}
14337@kindex target ppcbug1
14338@item target ppcbug1 @var{dev}
14339PPCBUG ROM monitor for PowerPC.
104c1213 14340
8e04817f
AC
14341@kindex target sds
14342@item target sds @var{dev}
14343SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 14344@end table
8e04817f 14345
c45da7e6
EZ
14346@cindex SDS protocol
14347The following commands specifi to the SDS protocol are supported
14348by@value{GDBN}:
14349
14350@table @code
14351@item set sdstimeout @var{nsec}
14352@kindex set sdstimeout
14353Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
14354default is 2 seconds.
14355
14356@item show sdstimeout
14357@kindex show sdstimeout
14358Show the current value of the SDS timeout.
14359
14360@item sds @var{command}
14361@kindex sds@r{, a command}
14362Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
14363@end table
14364
c45da7e6 14365
8e04817f
AC
14366@node PA
14367@subsection HP PA Embedded
104c1213
JM
14368
14369@table @code
14370
8e04817f
AC
14371@kindex target op50n
14372@item target op50n @var{dev}
14373OP50N monitor, running on an OKI HPPA board.
14374
14375@kindex target w89k
14376@item target w89k @var{dev}
14377W89K monitor, running on a Winbond HPPA board.
104c1213
JM
14378
14379@end table
14380
8e04817f 14381@node SH
172c2a43 14382@subsection Renesas SH
104c1213
JM
14383
14384@table @code
14385
172c2a43 14386@kindex target hms@r{, with Renesas SH}
8e04817f 14387@item target hms @var{dev}
172c2a43 14388A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
14389commands @code{device} and @code{speed} to control the serial line and
14390the communications speed used.
104c1213 14391
172c2a43 14392@kindex target e7000@r{, with Renesas SH}
8e04817f 14393@item target e7000 @var{dev}
172c2a43 14394E7000 emulator for Renesas SH.
104c1213 14395
8e04817f
AC
14396@kindex target sh3@r{, with SH}
14397@kindex target sh3e@r{, with SH}
14398@item target sh3 @var{dev}
14399@item target sh3e @var{dev}
172c2a43 14400Renesas SH-3 and SH-3E target systems.
104c1213 14401
8e04817f 14402@end table
104c1213 14403
8e04817f
AC
14404@node Sparclet
14405@subsection Tsqware Sparclet
104c1213 14406
8e04817f
AC
14407@cindex Sparclet
14408
14409@value{GDBN} enables developers to debug tasks running on
14410Sparclet targets from a Unix host.
14411@value{GDBN} uses code that runs on
14412both the Unix host and on the Sparclet target. The program
14413@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 14414
8e04817f
AC
14415@table @code
14416@item remotetimeout @var{args}
14417@kindex remotetimeout
14418@value{GDBN} supports the option @code{remotetimeout}.
14419This option is set by the user, and @var{args} represents the number of
14420seconds @value{GDBN} waits for responses.
104c1213
JM
14421@end table
14422
8e04817f
AC
14423@cindex compiling, on Sparclet
14424When compiling for debugging, include the options @samp{-g} to get debug
14425information and @samp{-Ttext} to relocate the program to where you wish to
14426load it on the target. You may also want to add the options @samp{-n} or
14427@samp{-N} in order to reduce the size of the sections. Example:
104c1213 14428
474c8240 14429@smallexample
8e04817f 14430sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 14431@end smallexample
104c1213 14432
8e04817f 14433You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 14434
474c8240 14435@smallexample
8e04817f 14436sparclet-aout-objdump --headers --syms prog
474c8240 14437@end smallexample
104c1213 14438
8e04817f
AC
14439@cindex running, on Sparclet
14440Once you have set
14441your Unix execution search path to find @value{GDBN}, you are ready to
14442run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
14443(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 14444
8e04817f
AC
14445@value{GDBN} comes up showing the prompt:
14446
474c8240 14447@smallexample
8e04817f 14448(gdbslet)
474c8240 14449@end smallexample
104c1213
JM
14450
14451@menu
8e04817f
AC
14452* Sparclet File:: Setting the file to debug
14453* Sparclet Connection:: Connecting to Sparclet
14454* Sparclet Download:: Sparclet download
14455* Sparclet Execution:: Running and debugging
104c1213
JM
14456@end menu
14457
8e04817f
AC
14458@node Sparclet File
14459@subsubsection Setting file to debug
104c1213 14460
8e04817f 14461The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 14462
474c8240 14463@smallexample
8e04817f 14464(gdbslet) file prog
474c8240 14465@end smallexample
104c1213 14466
8e04817f
AC
14467@need 1000
14468@value{GDBN} then attempts to read the symbol table of @file{prog}.
14469@value{GDBN} locates
14470the file by searching the directories listed in the command search
14471path.
14472If the file was compiled with debug information (option "-g"), source
14473files will be searched as well.
14474@value{GDBN} locates
14475the source files by searching the directories listed in the directory search
14476path (@pxref{Environment, ,Your program's environment}).
14477If it fails
14478to find a file, it displays a message such as:
104c1213 14479
474c8240 14480@smallexample
8e04817f 14481prog: No such file or directory.
474c8240 14482@end smallexample
104c1213 14483
8e04817f
AC
14484When this happens, add the appropriate directories to the search paths with
14485the @value{GDBN} commands @code{path} and @code{dir}, and execute the
14486@code{target} command again.
104c1213 14487
8e04817f
AC
14488@node Sparclet Connection
14489@subsubsection Connecting to Sparclet
104c1213 14490
8e04817f
AC
14491The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
14492To connect to a target on serial port ``@code{ttya}'', type:
104c1213 14493
474c8240 14494@smallexample
8e04817f
AC
14495(gdbslet) target sparclet /dev/ttya
14496Remote target sparclet connected to /dev/ttya
14497main () at ../prog.c:3
474c8240 14498@end smallexample
104c1213 14499
8e04817f
AC
14500@need 750
14501@value{GDBN} displays messages like these:
104c1213 14502
474c8240 14503@smallexample
8e04817f 14504Connected to ttya.
474c8240 14505@end smallexample
104c1213 14506
8e04817f
AC
14507@node Sparclet Download
14508@subsubsection Sparclet download
104c1213 14509
8e04817f
AC
14510@cindex download to Sparclet
14511Once connected to the Sparclet target,
14512you can use the @value{GDBN}
14513@code{load} command to download the file from the host to the target.
14514The file name and load offset should be given as arguments to the @code{load}
14515command.
14516Since the file format is aout, the program must be loaded to the starting
14517address. You can use @code{objdump} to find out what this value is. The load
14518offset is an offset which is added to the VMA (virtual memory address)
14519of each of the file's sections.
14520For instance, if the program
14521@file{prog} was linked to text address 0x1201000, with data at 0x12010160
14522and bss at 0x12010170, in @value{GDBN}, type:
104c1213 14523
474c8240 14524@smallexample
8e04817f
AC
14525(gdbslet) load prog 0x12010000
14526Loading section .text, size 0xdb0 vma 0x12010000
474c8240 14527@end smallexample
104c1213 14528
8e04817f
AC
14529If the code is loaded at a different address then what the program was linked
14530to, you may need to use the @code{section} and @code{add-symbol-file} commands
14531to tell @value{GDBN} where to map the symbol table.
14532
14533@node Sparclet Execution
14534@subsubsection Running and debugging
14535
14536@cindex running and debugging Sparclet programs
14537You can now begin debugging the task using @value{GDBN}'s execution control
14538commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
14539manual for the list of commands.
14540
474c8240 14541@smallexample
8e04817f
AC
14542(gdbslet) b main
14543Breakpoint 1 at 0x12010000: file prog.c, line 3.
14544(gdbslet) run
14545Starting program: prog
14546Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
145473 char *symarg = 0;
14548(gdbslet) step
145494 char *execarg = "hello!";
14550(gdbslet)
474c8240 14551@end smallexample
8e04817f
AC
14552
14553@node Sparclite
14554@subsection Fujitsu Sparclite
104c1213
JM
14555
14556@table @code
14557
8e04817f
AC
14558@kindex target sparclite
14559@item target sparclite @var{dev}
14560Fujitsu sparclite boards, used only for the purpose of loading.
14561You must use an additional command to debug the program.
14562For example: target remote @var{dev} using @value{GDBN} standard
14563remote protocol.
104c1213
JM
14564
14565@end table
14566
8e04817f
AC
14567@node ST2000
14568@subsection Tandem ST2000
104c1213 14569
8e04817f
AC
14570@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
14571STDBUG protocol.
104c1213 14572
8e04817f
AC
14573To connect your ST2000 to the host system, see the manufacturer's
14574manual. Once the ST2000 is physically attached, you can run:
104c1213 14575
474c8240 14576@smallexample
8e04817f 14577target st2000 @var{dev} @var{speed}
474c8240 14578@end smallexample
104c1213 14579
8e04817f
AC
14580@noindent
14581to establish it as your debugging environment. @var{dev} is normally
14582the name of a serial device, such as @file{/dev/ttya}, connected to the
14583ST2000 via a serial line. You can instead specify @var{dev} as a TCP
14584connection (for example, to a serial line attached via a terminal
14585concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 14586
8e04817f
AC
14587The @code{load} and @code{attach} commands are @emph{not} defined for
14588this target; you must load your program into the ST2000 as you normally
14589would for standalone operation. @value{GDBN} reads debugging information
14590(such as symbols) from a separate, debugging version of the program
14591available on your host computer.
14592@c FIXME!! This is terribly vague; what little content is here is
14593@c basically hearsay.
104c1213 14594
8e04817f
AC
14595@cindex ST2000 auxiliary commands
14596These auxiliary @value{GDBN} commands are available to help you with the ST2000
14597environment:
104c1213 14598
8e04817f
AC
14599@table @code
14600@item st2000 @var{command}
14601@kindex st2000 @var{cmd}
14602@cindex STDBUG commands (ST2000)
14603@cindex commands to STDBUG (ST2000)
14604Send a @var{command} to the STDBUG monitor. See the manufacturer's
14605manual for available commands.
104c1213 14606
8e04817f
AC
14607@item connect
14608@cindex connect (to STDBUG)
14609Connect the controlling terminal to the STDBUG command monitor. When
14610you are done interacting with STDBUG, typing either of two character
14611sequences gets you back to the @value{GDBN} command prompt:
14612@kbd{@key{RET}~.} (Return, followed by tilde and period) or
14613@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
14614@end table
14615
8e04817f
AC
14616@node Z8000
14617@subsection Zilog Z8000
104c1213 14618
8e04817f
AC
14619@cindex Z8000
14620@cindex simulator, Z8000
14621@cindex Zilog Z8000 simulator
104c1213 14622
8e04817f
AC
14623When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
14624a Z8000 simulator.
14625
14626For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
14627unsegmented variant of the Z8000 architecture) or the Z8001 (the
14628segmented variant). The simulator recognizes which architecture is
14629appropriate by inspecting the object code.
104c1213 14630
8e04817f
AC
14631@table @code
14632@item target sim @var{args}
14633@kindex sim
14634@kindex target sim@r{, with Z8000}
14635Debug programs on a simulated CPU. If the simulator supports setup
14636options, specify them via @var{args}.
104c1213
JM
14637@end table
14638
8e04817f
AC
14639@noindent
14640After specifying this target, you can debug programs for the simulated
14641CPU in the same style as programs for your host computer; use the
14642@code{file} command to load a new program image, the @code{run} command
14643to run your program, and so on.
14644
14645As well as making available all the usual machine registers
14646(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
14647additional items of information as specially named registers:
104c1213
JM
14648
14649@table @code
14650
8e04817f
AC
14651@item cycles
14652Counts clock-ticks in the simulator.
104c1213 14653
8e04817f
AC
14654@item insts
14655Counts instructions run in the simulator.
104c1213 14656
8e04817f
AC
14657@item time
14658Execution time in 60ths of a second.
104c1213 14659
8e04817f 14660@end table
104c1213 14661
8e04817f
AC
14662You can refer to these values in @value{GDBN} expressions with the usual
14663conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
14664conditional breakpoint that suspends only after at least 5000
14665simulated clock ticks.
104c1213 14666
a64548ea
EZ
14667@node AVR
14668@subsection Atmel AVR
14669@cindex AVR
14670
14671When configured for debugging the Atmel AVR, @value{GDBN} supports the
14672following AVR-specific commands:
14673
14674@table @code
14675@item info io_registers
14676@kindex info io_registers@r{, AVR}
14677@cindex I/O registers (Atmel AVR)
14678This command displays information about the AVR I/O registers. For
14679each register, @value{GDBN} prints its number and value.
14680@end table
14681
14682@node CRIS
14683@subsection CRIS
14684@cindex CRIS
14685
14686When configured for debugging CRIS, @value{GDBN} provides the
14687following CRIS-specific commands:
14688
14689@table @code
14690@item set cris-version @var{ver}
14691@cindex CRIS version
e22e55c9
OF
14692Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
14693The CRIS version affects register names and sizes. This command is useful in
14694case autodetection of the CRIS version fails.
a64548ea
EZ
14695
14696@item show cris-version
14697Show the current CRIS version.
14698
14699@item set cris-dwarf2-cfi
14700@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
14701Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
14702Change to @samp{off} when using @code{gcc-cris} whose version is below
14703@code{R59}.
a64548ea
EZ
14704
14705@item show cris-dwarf2-cfi
14706Show the current state of using DWARF-2 CFI.
e22e55c9
OF
14707
14708@item set cris-mode @var{mode}
14709@cindex CRIS mode
14710Set the current CRIS mode to @var{mode}. It should only be changed when
14711debugging in guru mode, in which case it should be set to
14712@samp{guru} (the default is @samp{normal}).
14713
14714@item show cris-mode
14715Show the current CRIS mode.
a64548ea
EZ
14716@end table
14717
14718@node Super-H
14719@subsection Renesas Super-H
14720@cindex Super-H
14721
14722For the Renesas Super-H processor, @value{GDBN} provides these
14723commands:
14724
14725@table @code
14726@item regs
14727@kindex regs@r{, Super-H}
14728Show the values of all Super-H registers.
14729@end table
14730
c45da7e6
EZ
14731@node WinCE
14732@subsection Windows CE
14733@cindex Windows CE
14734
14735The following commands are available for Windows CE:
14736
14737@table @code
14738@item set remotedirectory @var{dir}
14739@kindex set remotedirectory
14740Tell @value{GDBN} to upload files from the named directory @var{dir}.
14741The default is @file{/gdb}, i.e.@: the root directory on the current
14742drive.
14743
14744@item show remotedirectory
14745@kindex show remotedirectory
14746Show the current value of the upload directory.
14747
14748@item set remoteupload @var{method}
14749@kindex set remoteupload
14750Set the method used to upload files to remote device. Valid values
14751for @var{method} are @samp{always}, @samp{newer}, and @samp{never}.
14752The default is @samp{newer}.
14753
14754@item show remoteupload
14755@kindex show remoteupload
14756Show the current setting of the upload method.
14757
14758@item set remoteaddhost
14759@kindex set remoteaddhost
14760Tell @value{GDBN} whether to add this host to the remote stub's
14761arguments when you debug over a network.
14762
14763@item show remoteaddhost
14764@kindex show remoteaddhost
14765Show whether to add this host to remote stub's arguments when
14766debugging over a network.
14767@end table
14768
a64548ea 14769
8e04817f
AC
14770@node Architectures
14771@section Architectures
104c1213 14772
8e04817f
AC
14773This section describes characteristics of architectures that affect
14774all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 14775
8e04817f 14776@menu
9c16f35a 14777* i386::
8e04817f
AC
14778* A29K::
14779* Alpha::
14780* MIPS::
a64548ea 14781* HPPA:: HP PA architecture
8e04817f 14782@end menu
104c1213 14783
9c16f35a
EZ
14784@node i386
14785@subsection x86 Architecture-specific issues.
14786
14787@table @code
14788@item set struct-convention @var{mode}
14789@kindex set struct-convention
14790@cindex struct return convention
14791@cindex struct/union returned in registers
14792Set the convention used by the inferior to return @code{struct}s and
14793@code{union}s from functions to @var{mode}. Possible values of
14794@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
14795default). @code{"default"} or @code{"pcc"} means that @code{struct}s
14796are returned on the stack, while @code{"reg"} means that a
14797@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
14798be returned in a register.
14799
14800@item show struct-convention
14801@kindex show struct-convention
14802Show the current setting of the convention to return @code{struct}s
14803from functions.
14804@end table
14805
8e04817f
AC
14806@node A29K
14807@subsection A29K
104c1213
JM
14808
14809@table @code
104c1213 14810
8e04817f
AC
14811@kindex set rstack_high_address
14812@cindex AMD 29K register stack
14813@cindex register stack, AMD29K
14814@item set rstack_high_address @var{address}
14815On AMD 29000 family processors, registers are saved in a separate
14816@dfn{register stack}. There is no way for @value{GDBN} to determine the
14817extent of this stack. Normally, @value{GDBN} just assumes that the
14818stack is ``large enough''. This may result in @value{GDBN} referencing
14819memory locations that do not exist. If necessary, you can get around
14820this problem by specifying the ending address of the register stack with
14821the @code{set rstack_high_address} command. The argument should be an
14822address, which you probably want to precede with @samp{0x} to specify in
14823hexadecimal.
104c1213 14824
8e04817f
AC
14825@kindex show rstack_high_address
14826@item show rstack_high_address
14827Display the current limit of the register stack, on AMD 29000 family
14828processors.
104c1213 14829
8e04817f 14830@end table
104c1213 14831
8e04817f
AC
14832@node Alpha
14833@subsection Alpha
104c1213 14834
8e04817f 14835See the following section.
104c1213 14836
8e04817f
AC
14837@node MIPS
14838@subsection MIPS
104c1213 14839
8e04817f
AC
14840@cindex stack on Alpha
14841@cindex stack on MIPS
14842@cindex Alpha stack
14843@cindex MIPS stack
14844Alpha- and MIPS-based computers use an unusual stack frame, which
14845sometimes requires @value{GDBN} to search backward in the object code to
14846find the beginning of a function.
104c1213 14847
8e04817f
AC
14848@cindex response time, MIPS debugging
14849To improve response time (especially for embedded applications, where
14850@value{GDBN} may be restricted to a slow serial line for this search)
14851you may want to limit the size of this search, using one of these
14852commands:
104c1213 14853
8e04817f
AC
14854@table @code
14855@cindex @code{heuristic-fence-post} (Alpha, MIPS)
14856@item set heuristic-fence-post @var{limit}
14857Restrict @value{GDBN} to examining at most @var{limit} bytes in its
14858search for the beginning of a function. A value of @var{0} (the
14859default) means there is no limit. However, except for @var{0}, the
14860larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
14861and therefore the longer it takes to run. You should only need to use
14862this command when debugging a stripped executable.
104c1213 14863
8e04817f
AC
14864@item show heuristic-fence-post
14865Display the current limit.
14866@end table
104c1213
JM
14867
14868@noindent
8e04817f
AC
14869These commands are available @emph{only} when @value{GDBN} is configured
14870for debugging programs on Alpha or MIPS processors.
104c1213 14871
a64548ea
EZ
14872Several MIPS-specific commands are available when debugging MIPS
14873programs:
14874
14875@table @code
14876@item set mips saved-gpreg-size @var{size}
14877@kindex set mips saved-gpreg-size
14878@cindex MIPS GP register size on stack
14879Set the size of MIPS general-purpose registers saved on the stack.
14880The argument @var{size} can be one of the following:
14881
14882@table @samp
14883@item 32
1488432-bit GP registers
14885@item 64
1488664-bit GP registers
14887@item auto
14888Use the target's default setting or autodetect the saved size from the
14889information contained in the executable. This is the default
14890@end table
14891
14892@item show mips saved-gpreg-size
14893@kindex show mips saved-gpreg-size
14894Show the current size of MIPS GP registers on the stack.
14895
14896@item set mips stack-arg-size @var{size}
14897@kindex set mips stack-arg-size
14898@cindex MIPS stack space for arguments
14899Set the amount of stack space reserved for arguments to functions.
14900The argument can be one of @code{"32"}, @code{"64"} or @code{"auto"}
14901(the default).
14902
14903@item set mips abi @var{arg}
14904@kindex set mips abi
14905@cindex set ABI for MIPS
14906Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
14907values of @var{arg} are:
14908
14909@table @samp
14910@item auto
14911The default ABI associated with the current binary (this is the
14912default).
14913@item o32
14914@item o64
14915@item n32
14916@item n64
14917@item eabi32
14918@item eabi64
14919@item auto
14920@end table
14921
14922@item show mips abi
14923@kindex show mips abi
14924Show the MIPS ABI used by @value{GDBN} to debug the inferior.
14925
14926@item set mipsfpu
14927@itemx show mipsfpu
14928@xref{MIPS Embedded, set mipsfpu}.
14929
14930@item set mips mask-address @var{arg}
14931@kindex set mips mask-address
14932@cindex MIPS addresses, masking
14933This command determines whether the most-significant 32 bits of 64-bit
14934MIPS addresses are masked off. The argument @var{arg} can be
14935@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
14936setting, which lets @value{GDBN} determine the correct value.
14937
14938@item show mips mask-address
14939@kindex show mips mask-address
14940Show whether the upper 32 bits of MIPS addresses are masked off or
14941not.
14942
14943@item set remote-mips64-transfers-32bit-regs
14944@kindex set remote-mips64-transfers-32bit-regs
14945This command controls compatibility with 64-bit MIPS targets that
14946transfer data in 32-bit quantities. If you have an old MIPS 64 target
14947that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
14948and 64 bits for other registers, set this option to @samp{on}.
14949
14950@item show remote-mips64-transfers-32bit-regs
14951@kindex show remote-mips64-transfers-32bit-regs
14952Show the current setting of compatibility with older MIPS 64 targets.
14953
14954@item set debug mips
14955@kindex set debug mips
14956This command turns on and off debugging messages for the MIPS-specific
14957target code in @value{GDBN}.
14958
14959@item show debug mips
14960@kindex show debug mips
14961Show the current setting of MIPS debugging messages.
14962@end table
14963
14964
14965@node HPPA
14966@subsection HPPA
14967@cindex HPPA support
14968
14969When @value{GDBN} is debugging te HP PA architecture, it provides the
14970following special commands:
14971
14972@table @code
14973@item set debug hppa
14974@kindex set debug hppa
14975THis command determines whether HPPA architecture specific debugging
14976messages are to be displayed.
14977
14978@item show debug hppa
14979Show whether HPPA debugging messages are displayed.
14980
14981@item maint print unwind @var{address}
14982@kindex maint print unwind@r{, HPPA}
14983This command displays the contents of the unwind table entry at the
14984given @var{address}.
14985
14986@end table
14987
104c1213 14988
8e04817f
AC
14989@node Controlling GDB
14990@chapter Controlling @value{GDBN}
14991
14992You can alter the way @value{GDBN} interacts with you by using the
14993@code{set} command. For commands controlling how @value{GDBN} displays
14994data, see @ref{Print Settings, ,Print settings}. Other settings are
14995described here.
14996
14997@menu
14998* Prompt:: Prompt
14999* Editing:: Command editing
15000* History:: Command history
15001* Screen Size:: Screen size
15002* Numbers:: Numbers
1e698235 15003* ABI:: Configuring the current ABI
8e04817f
AC
15004* Messages/Warnings:: Optional warnings and messages
15005* Debugging Output:: Optional messages about internal happenings
15006@end menu
15007
15008@node Prompt
15009@section Prompt
104c1213 15010
8e04817f 15011@cindex prompt
104c1213 15012
8e04817f
AC
15013@value{GDBN} indicates its readiness to read a command by printing a string
15014called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
15015can change the prompt string with the @code{set prompt} command. For
15016instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
15017the prompt in one of the @value{GDBN} sessions so that you can always tell
15018which one you are talking to.
104c1213 15019
8e04817f
AC
15020@emph{Note:} @code{set prompt} does not add a space for you after the
15021prompt you set. This allows you to set a prompt which ends in a space
15022or a prompt that does not.
104c1213 15023
8e04817f
AC
15024@table @code
15025@kindex set prompt
15026@item set prompt @var{newprompt}
15027Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 15028
8e04817f
AC
15029@kindex show prompt
15030@item show prompt
15031Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
15032@end table
15033
8e04817f
AC
15034@node Editing
15035@section Command editing
15036@cindex readline
15037@cindex command line editing
104c1213 15038
703663ab 15039@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
15040@sc{gnu} library provides consistent behavior for programs which provide a
15041command line interface to the user. Advantages are @sc{gnu} Emacs-style
15042or @dfn{vi}-style inline editing of commands, @code{csh}-like history
15043substitution, and a storage and recall of command history across
15044debugging sessions.
104c1213 15045
8e04817f
AC
15046You may control the behavior of command line editing in @value{GDBN} with the
15047command @code{set}.
104c1213 15048
8e04817f
AC
15049@table @code
15050@kindex set editing
15051@cindex editing
15052@item set editing
15053@itemx set editing on
15054Enable command line editing (enabled by default).
104c1213 15055
8e04817f
AC
15056@item set editing off
15057Disable command line editing.
104c1213 15058
8e04817f
AC
15059@kindex show editing
15060@item show editing
15061Show whether command line editing is enabled.
104c1213
JM
15062@end table
15063
703663ab
EZ
15064@xref{Command Line Editing}, for more details about the Readline
15065interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
15066encouraged to read that chapter.
15067
8e04817f
AC
15068@node History
15069@section Command history
703663ab 15070@cindex command history
8e04817f
AC
15071
15072@value{GDBN} can keep track of the commands you type during your
15073debugging sessions, so that you can be certain of precisely what
15074happened. Use these commands to manage the @value{GDBN} command
15075history facility.
104c1213 15076
703663ab
EZ
15077@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
15078package, to provide the history facility. @xref{Using History
15079Interactively}, for the detailed description of the History library.
15080
15081Here is the description of @value{GDBN} commands related to command
15082history.
15083
104c1213 15084@table @code
8e04817f
AC
15085@cindex history substitution
15086@cindex history file
15087@kindex set history filename
4644b6e3 15088@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
15089@item set history filename @var{fname}
15090Set the name of the @value{GDBN} command history file to @var{fname}.
15091This is the file where @value{GDBN} reads an initial command history
15092list, and where it writes the command history from this session when it
15093exits. You can access this list through history expansion or through
15094the history command editing characters listed below. This file defaults
15095to the value of the environment variable @code{GDBHISTFILE}, or to
15096@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
15097is not set.
104c1213 15098
9c16f35a
EZ
15099@cindex save command history
15100@kindex set history save
8e04817f
AC
15101@item set history save
15102@itemx set history save on
15103Record command history in a file, whose name may be specified with the
15104@code{set history filename} command. By default, this option is disabled.
104c1213 15105
8e04817f
AC
15106@item set history save off
15107Stop recording command history in a file.
104c1213 15108
8e04817f 15109@cindex history size
9c16f35a 15110@kindex set history size
6fc08d32 15111@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
15112@item set history size @var{size}
15113Set the number of commands which @value{GDBN} keeps in its history list.
15114This defaults to the value of the environment variable
15115@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
15116@end table
15117
8e04817f 15118History expansion assigns special meaning to the character @kbd{!}.
703663ab 15119@xref{Event Designators}, for more details.
8e04817f 15120
703663ab 15121@cindex history expansion, turn on/off
8e04817f
AC
15122Since @kbd{!} is also the logical not operator in C, history expansion
15123is off by default. If you decide to enable history expansion with the
15124@code{set history expansion on} command, you may sometimes need to
15125follow @kbd{!} (when it is used as logical not, in an expression) with
15126a space or a tab to prevent it from being expanded. The readline
15127history facilities do not attempt substitution on the strings
15128@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
15129
15130The commands to control history expansion are:
104c1213
JM
15131
15132@table @code
8e04817f
AC
15133@item set history expansion on
15134@itemx set history expansion
703663ab 15135@kindex set history expansion
8e04817f 15136Enable history expansion. History expansion is off by default.
104c1213 15137
8e04817f
AC
15138@item set history expansion off
15139Disable history expansion.
104c1213 15140
8e04817f
AC
15141@c @group
15142@kindex show history
15143@item show history
15144@itemx show history filename
15145@itemx show history save
15146@itemx show history size
15147@itemx show history expansion
15148These commands display the state of the @value{GDBN} history parameters.
15149@code{show history} by itself displays all four states.
15150@c @end group
15151@end table
15152
15153@table @code
9c16f35a
EZ
15154@kindex show commands
15155@cindex show last commands
15156@cindex display command history
8e04817f
AC
15157@item show commands
15158Display the last ten commands in the command history.
104c1213 15159
8e04817f
AC
15160@item show commands @var{n}
15161Print ten commands centered on command number @var{n}.
15162
15163@item show commands +
15164Print ten commands just after the commands last printed.
104c1213
JM
15165@end table
15166
8e04817f
AC
15167@node Screen Size
15168@section Screen size
15169@cindex size of screen
15170@cindex pauses in output
104c1213 15171
8e04817f
AC
15172Certain commands to @value{GDBN} may produce large amounts of
15173information output to the screen. To help you read all of it,
15174@value{GDBN} pauses and asks you for input at the end of each page of
15175output. Type @key{RET} when you want to continue the output, or @kbd{q}
15176to discard the remaining output. Also, the screen width setting
15177determines when to wrap lines of output. Depending on what is being
15178printed, @value{GDBN} tries to break the line at a readable place,
15179rather than simply letting it overflow onto the following line.
15180
15181Normally @value{GDBN} knows the size of the screen from the terminal
15182driver software. For example, on Unix @value{GDBN} uses the termcap data base
15183together with the value of the @code{TERM} environment variable and the
15184@code{stty rows} and @code{stty cols} settings. If this is not correct,
15185you can override it with the @code{set height} and @code{set
15186width} commands:
15187
15188@table @code
15189@kindex set height
15190@kindex set width
15191@kindex show width
15192@kindex show height
15193@item set height @var{lpp}
15194@itemx show height
15195@itemx set width @var{cpl}
15196@itemx show width
15197These @code{set} commands specify a screen height of @var{lpp} lines and
15198a screen width of @var{cpl} characters. The associated @code{show}
15199commands display the current settings.
104c1213 15200
8e04817f
AC
15201If you specify a height of zero lines, @value{GDBN} does not pause during
15202output no matter how long the output is. This is useful if output is to a
15203file or to an editor buffer.
104c1213 15204
8e04817f
AC
15205Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
15206from wrapping its output.
9c16f35a
EZ
15207
15208@item set pagination on
15209@itemx set pagination off
15210@kindex set pagination
15211Turn the output pagination on or off; the default is on. Turning
15212pagination off is the alternative to @code{set height 0}.
15213
15214@item show pagination
15215@kindex show pagination
15216Show the current pagination mode.
104c1213
JM
15217@end table
15218
8e04817f
AC
15219@node Numbers
15220@section Numbers
15221@cindex number representation
15222@cindex entering numbers
104c1213 15223
8e04817f
AC
15224You can always enter numbers in octal, decimal, or hexadecimal in
15225@value{GDBN} by the usual conventions: octal numbers begin with
15226@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
15227begin with @samp{0x}. Numbers that neither begin with @samp{0} or
15228@samp{0x}, nor end with a @samp{.} are, by default, entered in base
1522910; likewise, the default display for numbers---when no particular
15230format is specified---is base 10. You can change the default base for
15231both input and output with the commands described below.
104c1213 15232
8e04817f
AC
15233@table @code
15234@kindex set input-radix
15235@item set input-radix @var{base}
15236Set the default base for numeric input. Supported choices
15237for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15238specified either unambiguously or using the current input radix; for
8e04817f 15239example, any of
104c1213 15240
8e04817f 15241@smallexample
9c16f35a
EZ
15242set input-radix 012
15243set input-radix 10.
15244set input-radix 0xa
8e04817f 15245@end smallexample
104c1213 15246
8e04817f 15247@noindent
9c16f35a 15248sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
15249leaves the input radix unchanged, no matter what it was, since
15250@samp{10}, being without any leading or trailing signs of its base, is
15251interpreted in the current radix. Thus, if the current radix is 16,
15252@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
15253change the radix.
104c1213 15254
8e04817f
AC
15255@kindex set output-radix
15256@item set output-radix @var{base}
15257Set the default base for numeric display. Supported choices
15258for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15259specified either unambiguously or using the current input radix.
104c1213 15260
8e04817f
AC
15261@kindex show input-radix
15262@item show input-radix
15263Display the current default base for numeric input.
104c1213 15264
8e04817f
AC
15265@kindex show output-radix
15266@item show output-radix
15267Display the current default base for numeric display.
9c16f35a
EZ
15268
15269@item set radix @r{[}@var{base}@r{]}
15270@itemx show radix
15271@kindex set radix
15272@kindex show radix
15273These commands set and show the default base for both input and output
15274of numbers. @code{set radix} sets the radix of input and output to
15275the same base; without an argument, it resets the radix back to its
15276default value of 10.
15277
8e04817f 15278@end table
104c1213 15279
1e698235
DJ
15280@node ABI
15281@section Configuring the current ABI
15282
15283@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
15284application automatically. However, sometimes you need to override its
15285conclusions. Use these commands to manage @value{GDBN}'s view of the
15286current ABI.
15287
98b45e30
DJ
15288@cindex OS ABI
15289@kindex set osabi
b4e9345d 15290@kindex show osabi
98b45e30
DJ
15291
15292One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 15293system targets, either via remote debugging or native emulation.
98b45e30
DJ
15294@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
15295but you can override its conclusion using the @code{set osabi} command.
15296One example where this is useful is in debugging of binaries which use
15297an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
15298not have the same identifying marks that the standard C library for your
15299platform provides.
15300
15301@table @code
15302@item show osabi
15303Show the OS ABI currently in use.
15304
15305@item set osabi
15306With no argument, show the list of registered available OS ABI's.
15307
15308@item set osabi @var{abi}
15309Set the current OS ABI to @var{abi}.
15310@end table
15311
1e698235 15312@cindex float promotion
1e698235
DJ
15313
15314Generally, the way that an argument of type @code{float} is passed to a
15315function depends on whether the function is prototyped. For a prototyped
15316(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
15317according to the architecture's convention for @code{float}. For unprototyped
15318(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
15319@code{double} and then passed.
15320
15321Unfortunately, some forms of debug information do not reliably indicate whether
15322a function is prototyped. If @value{GDBN} calls a function that is not marked
15323as prototyped, it consults @kbd{set coerce-float-to-double}.
15324
15325@table @code
a8f24a35 15326@kindex set coerce-float-to-double
1e698235
DJ
15327@item set coerce-float-to-double
15328@itemx set coerce-float-to-double on
15329Arguments of type @code{float} will be promoted to @code{double} when passed
15330to an unprototyped function. This is the default setting.
15331
15332@item set coerce-float-to-double off
15333Arguments of type @code{float} will be passed directly to unprototyped
15334functions.
9c16f35a
EZ
15335
15336@kindex show coerce-float-to-double
15337@item show coerce-float-to-double
15338Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
15339@end table
15340
f1212245
DJ
15341@kindex set cp-abi
15342@kindex show cp-abi
15343@value{GDBN} needs to know the ABI used for your program's C@t{++}
15344objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
15345used to build your application. @value{GDBN} only fully supports
15346programs with a single C@t{++} ABI; if your program contains code using
15347multiple C@t{++} ABI's or if @value{GDBN} can not identify your
15348program's ABI correctly, you can tell @value{GDBN} which ABI to use.
15349Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
15350before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
15351``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
15352use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
15353``auto''.
15354
15355@table @code
15356@item show cp-abi
15357Show the C@t{++} ABI currently in use.
15358
15359@item set cp-abi
15360With no argument, show the list of supported C@t{++} ABI's.
15361
15362@item set cp-abi @var{abi}
15363@itemx set cp-abi auto
15364Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
15365@end table
15366
8e04817f
AC
15367@node Messages/Warnings
15368@section Optional warnings and messages
104c1213 15369
9c16f35a
EZ
15370@cindex verbose operation
15371@cindex optional warnings
8e04817f
AC
15372By default, @value{GDBN} is silent about its inner workings. If you are
15373running on a slow machine, you may want to use the @code{set verbose}
15374command. This makes @value{GDBN} tell you when it does a lengthy
15375internal operation, so you will not think it has crashed.
104c1213 15376
8e04817f
AC
15377Currently, the messages controlled by @code{set verbose} are those
15378which announce that the symbol table for a source file is being read;
15379see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 15380
8e04817f
AC
15381@table @code
15382@kindex set verbose
15383@item set verbose on
15384Enables @value{GDBN} output of certain informational messages.
104c1213 15385
8e04817f
AC
15386@item set verbose off
15387Disables @value{GDBN} output of certain informational messages.
104c1213 15388
8e04817f
AC
15389@kindex show verbose
15390@item show verbose
15391Displays whether @code{set verbose} is on or off.
15392@end table
104c1213 15393
8e04817f
AC
15394By default, if @value{GDBN} encounters bugs in the symbol table of an
15395object file, it is silent; but if you are debugging a compiler, you may
15396find this information useful (@pxref{Symbol Errors, ,Errors reading
15397symbol files}).
104c1213 15398
8e04817f 15399@table @code
104c1213 15400
8e04817f
AC
15401@kindex set complaints
15402@item set complaints @var{limit}
15403Permits @value{GDBN} to output @var{limit} complaints about each type of
15404unusual symbols before becoming silent about the problem. Set
15405@var{limit} to zero to suppress all complaints; set it to a large number
15406to prevent complaints from being suppressed.
104c1213 15407
8e04817f
AC
15408@kindex show complaints
15409@item show complaints
15410Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 15411
8e04817f 15412@end table
104c1213 15413
8e04817f
AC
15414By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
15415lot of stupid questions to confirm certain commands. For example, if
15416you try to run a program which is already running:
104c1213 15417
474c8240 15418@smallexample
8e04817f
AC
15419(@value{GDBP}) run
15420The program being debugged has been started already.
15421Start it from the beginning? (y or n)
474c8240 15422@end smallexample
104c1213 15423
8e04817f
AC
15424If you are willing to unflinchingly face the consequences of your own
15425commands, you can disable this ``feature'':
104c1213 15426
8e04817f 15427@table @code
104c1213 15428
8e04817f
AC
15429@kindex set confirm
15430@cindex flinching
15431@cindex confirmation
15432@cindex stupid questions
15433@item set confirm off
15434Disables confirmation requests.
104c1213 15435
8e04817f
AC
15436@item set confirm on
15437Enables confirmation requests (the default).
104c1213 15438
8e04817f
AC
15439@kindex show confirm
15440@item show confirm
15441Displays state of confirmation requests.
15442
15443@end table
104c1213 15444
8e04817f
AC
15445@node Debugging Output
15446@section Optional messages about internal happenings
4644b6e3
EZ
15447@cindex optional debugging messages
15448
da316a69
EZ
15449@value{GDBN} has commands that enable optional debugging messages from
15450various @value{GDBN} subsystems; normally these commands are of
15451interest to @value{GDBN} maintainers, or when reporting a bug. This
15452section documents those commands.
15453
104c1213 15454@table @code
a8f24a35
EZ
15455@kindex set exec-done-display
15456@item set exec-done-display
15457Turns on or off the notification of asynchronous commands'
15458completion. When on, @value{GDBN} will print a message when an
15459asynchronous command finishes its execution. The default is off.
15460@kindex show exec-done-display
15461@item show exec-done-display
15462Displays the current setting of asynchronous command completion
15463notification.
4644b6e3
EZ
15464@kindex set debug
15465@cindex gdbarch debugging info
a8f24a35 15466@cindex architecture debugging info
8e04817f 15467@item set debug arch
a8f24a35 15468Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 15469@kindex show debug
8e04817f
AC
15470@item show debug arch
15471Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
15472@item set debug aix-thread
15473@cindex AIX threads
15474Display debugging messages about inner workings of the AIX thread
15475module.
15476@item show debug aix-thread
15477Show the current state of AIX thread debugging info display.
8e04817f 15478@item set debug event
4644b6e3 15479@cindex event debugging info
a8f24a35 15480Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 15481default is off.
8e04817f
AC
15482@item show debug event
15483Displays the current state of displaying @value{GDBN} event debugging
15484info.
8e04817f 15485@item set debug expression
4644b6e3 15486@cindex expression debugging info
721c2651
EZ
15487Turns on or off display of debugging info about @value{GDBN}
15488expression parsing. The default is off.
8e04817f 15489@item show debug expression
721c2651
EZ
15490Displays the current state of displaying debugging info about
15491@value{GDBN} expression parsing.
7453dc06 15492@item set debug frame
4644b6e3 15493@cindex frame debugging info
7453dc06
AC
15494Turns on or off display of @value{GDBN} frame debugging info. The
15495default is off.
7453dc06
AC
15496@item show debug frame
15497Displays the current state of displaying @value{GDBN} frame debugging
15498info.
30e91e0b
RC
15499@item set debug infrun
15500@cindex inferior debugging info
15501Turns on or off display of @value{GDBN} debugging info for running the inferior.
15502The default is off. @file{infrun.c} contains GDB's runtime state machine used
15503for implementing operations such as single-stepping the inferior.
15504@item show debug infrun
15505Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
15506@item set debug lin-lwp
15507@cindex @sc{gnu}/Linux LWP debug messages
15508@cindex Linux lightweight processes
721c2651 15509Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
15510@item show debug lin-lwp
15511Show the current state of Linux LWP debugging messages.
2b4855ab 15512@item set debug observer
4644b6e3 15513@cindex observer debugging info
2b4855ab
AC
15514Turns on or off display of @value{GDBN} observer debugging. This
15515includes info such as the notification of observable events.
2b4855ab
AC
15516@item show debug observer
15517Displays the current state of observer debugging.
8e04817f 15518@item set debug overload
4644b6e3 15519@cindex C@t{++} overload debugging info
8e04817f
AC
15520Turns on or off display of @value{GDBN} C@t{++} overload debugging
15521info. This includes info such as ranking of functions, etc. The default
15522is off.
8e04817f
AC
15523@item show debug overload
15524Displays the current state of displaying @value{GDBN} C@t{++} overload
15525debugging info.
8e04817f
AC
15526@cindex packets, reporting on stdout
15527@cindex serial connections, debugging
15528@item set debug remote
15529Turns on or off display of reports on all packets sent back and forth across
15530the serial line to the remote machine. The info is printed on the
15531@value{GDBN} standard output stream. The default is off.
8e04817f
AC
15532@item show debug remote
15533Displays the state of display of remote packets.
8e04817f
AC
15534@item set debug serial
15535Turns on or off display of @value{GDBN} serial debugging info. The
15536default is off.
8e04817f
AC
15537@item show debug serial
15538Displays the current state of displaying @value{GDBN} serial debugging
15539info.
c45da7e6
EZ
15540@item set debug solib-frv
15541@cindex FR-V shared-library debugging
15542Turns on or off debugging messages for FR-V shared-library code.
15543@item show debug solib-frv
15544Display the current state of FR-V shared-library code debugging
15545messages.
8e04817f 15546@item set debug target
4644b6e3 15547@cindex target debugging info
8e04817f
AC
15548Turns on or off display of @value{GDBN} target debugging info. This info
15549includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
15550default is 0. Set it to 1 to track events, and to 2 to also track the
15551value of large memory transfers. Changes to this flag do not take effect
15552until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
15553@item show debug target
15554Displays the current state of displaying @value{GDBN} target debugging
15555info.
c45da7e6 15556@item set debugvarobj
4644b6e3 15557@cindex variable object debugging info
8e04817f
AC
15558Turns on or off display of @value{GDBN} variable object debugging
15559info. The default is off.
c45da7e6 15560@item show debugvarobj
8e04817f
AC
15561Displays the current state of displaying @value{GDBN} variable object
15562debugging info.
15563@end table
104c1213 15564
8e04817f
AC
15565@node Sequences
15566@chapter Canned Sequences of Commands
104c1213 15567
8e04817f
AC
15568Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
15569command lists}), @value{GDBN} provides two ways to store sequences of
15570commands for execution as a unit: user-defined commands and command
15571files.
104c1213 15572
8e04817f
AC
15573@menu
15574* Define:: User-defined commands
15575* Hooks:: User-defined command hooks
15576* Command Files:: Command files
15577* Output:: Commands for controlled output
15578@end menu
104c1213 15579
8e04817f
AC
15580@node Define
15581@section User-defined commands
104c1213 15582
8e04817f
AC
15583@cindex user-defined command
15584A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
15585which you assign a new name as a command. This is done with the
15586@code{define} command. User commands may accept up to 10 arguments
15587separated by whitespace. Arguments are accessed within the user command
15588via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 15589
8e04817f
AC
15590@smallexample
15591define adder
15592 print $arg0 + $arg1 + $arg2
15593@end smallexample
104c1213
JM
15594
15595@noindent
8e04817f 15596To execute the command use:
104c1213 15597
8e04817f
AC
15598@smallexample
15599adder 1 2 3
15600@end smallexample
104c1213 15601
8e04817f
AC
15602@noindent
15603This defines the command @code{adder}, which prints the sum of
15604its three arguments. Note the arguments are text substitutions, so they may
15605reference variables, use complex expressions, or even perform inferior
15606functions calls.
104c1213
JM
15607
15608@table @code
104c1213 15609
8e04817f
AC
15610@kindex define
15611@item define @var{commandname}
15612Define a command named @var{commandname}. If there is already a command
15613by that name, you are asked to confirm that you want to redefine it.
104c1213 15614
8e04817f
AC
15615The definition of the command is made up of other @value{GDBN} command lines,
15616which are given following the @code{define} command. The end of these
15617commands is marked by a line containing @code{end}.
104c1213 15618
8e04817f
AC
15619@kindex if
15620@kindex else
15621@item if
09d4efe1 15622@itemx else
8e04817f
AC
15623Takes a single argument, which is an expression to evaluate.
15624It is followed by a series of commands that are executed
15625only if the expression is true (nonzero).
15626There can then optionally be a line @code{else}, followed
15627by a series of commands that are only executed if the expression
15628was false. The end of the list is marked by a line containing @code{end}.
104c1213 15629
8e04817f
AC
15630@kindex while
15631@item while
15632The syntax is similar to @code{if}: the command takes a single argument,
15633which is an expression to evaluate, and must be followed by the commands to
15634execute, one per line, terminated by an @code{end}.
15635The commands are executed repeatedly as long as the expression
15636evaluates to true.
104c1213 15637
8e04817f
AC
15638@kindex document
15639@item document @var{commandname}
15640Document the user-defined command @var{commandname}, so that it can be
15641accessed by @code{help}. The command @var{commandname} must already be
15642defined. This command reads lines of documentation just as @code{define}
15643reads the lines of the command definition, ending with @code{end}.
15644After the @code{document} command is finished, @code{help} on command
15645@var{commandname} displays the documentation you have written.
104c1213 15646
8e04817f
AC
15647You may use the @code{document} command again to change the
15648documentation of a command. Redefining the command with @code{define}
15649does not change the documentation.
104c1213 15650
c45da7e6
EZ
15651@kindex dont-repeat
15652@cindex don't repeat command
15653@item dont-repeat
15654Used inside a user-defined command, this tells @value{GDBN} that this
15655command should not be repeated when the user hits @key{RET}
15656(@pxref{Command Syntax, repeat last command}).
15657
8e04817f
AC
15658@kindex help user-defined
15659@item help user-defined
15660List all user-defined commands, with the first line of the documentation
15661(if any) for each.
104c1213 15662
8e04817f
AC
15663@kindex show user
15664@item show user
15665@itemx show user @var{commandname}
15666Display the @value{GDBN} commands used to define @var{commandname} (but
15667not its documentation). If no @var{commandname} is given, display the
15668definitions for all user-defined commands.
104c1213 15669
9c16f35a 15670@cindex infinite recusrion in user-defined commands
20f01a46
DH
15671@kindex show max-user-call-depth
15672@kindex set max-user-call-depth
15673@item show max-user-call-depth
5ca0cb28
DH
15674@itemx set max-user-call-depth
15675The value of @code{max-user-call-depth} controls how many recursion
15676levels are allowed in user-defined commands before GDB suspects an
15677infinite recursion and aborts the command.
20f01a46 15678
104c1213
JM
15679@end table
15680
8e04817f
AC
15681When user-defined commands are executed, the
15682commands of the definition are not printed. An error in any command
15683stops execution of the user-defined command.
104c1213 15684
8e04817f
AC
15685If used interactively, commands that would ask for confirmation proceed
15686without asking when used inside a user-defined command. Many @value{GDBN}
15687commands that normally print messages to say what they are doing omit the
15688messages when used in a user-defined command.
104c1213 15689
8e04817f
AC
15690@node Hooks
15691@section User-defined command hooks
15692@cindex command hooks
15693@cindex hooks, for commands
15694@cindex hooks, pre-command
104c1213 15695
8e04817f 15696@kindex hook
8e04817f
AC
15697You may define @dfn{hooks}, which are a special kind of user-defined
15698command. Whenever you run the command @samp{foo}, if the user-defined
15699command @samp{hook-foo} exists, it is executed (with no arguments)
15700before that command.
104c1213 15701
8e04817f
AC
15702@cindex hooks, post-command
15703@kindex hookpost
8e04817f
AC
15704A hook may also be defined which is run after the command you executed.
15705Whenever you run the command @samp{foo}, if the user-defined command
15706@samp{hookpost-foo} exists, it is executed (with no arguments) after
15707that command. Post-execution hooks may exist simultaneously with
15708pre-execution hooks, for the same command.
104c1213 15709
8e04817f 15710It is valid for a hook to call the command which it hooks. If this
9f1c6395 15711occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 15712
8e04817f
AC
15713@c It would be nice if hookpost could be passed a parameter indicating
15714@c if the command it hooks executed properly or not. FIXME!
104c1213 15715
8e04817f
AC
15716@kindex stop@r{, a pseudo-command}
15717In addition, a pseudo-command, @samp{stop} exists. Defining
15718(@samp{hook-stop}) makes the associated commands execute every time
15719execution stops in your program: before breakpoint commands are run,
15720displays are printed, or the stack frame is printed.
104c1213 15721
8e04817f
AC
15722For example, to ignore @code{SIGALRM} signals while
15723single-stepping, but treat them normally during normal execution,
15724you could define:
104c1213 15725
474c8240 15726@smallexample
8e04817f
AC
15727define hook-stop
15728handle SIGALRM nopass
15729end
104c1213 15730
8e04817f
AC
15731define hook-run
15732handle SIGALRM pass
15733end
104c1213 15734
8e04817f
AC
15735define hook-continue
15736handle SIGLARM pass
15737end
474c8240 15738@end smallexample
104c1213 15739
8e04817f 15740As a further example, to hook at the begining and end of the @code{echo}
b383017d 15741command, and to add extra text to the beginning and end of the message,
8e04817f 15742you could define:
104c1213 15743
474c8240 15744@smallexample
8e04817f
AC
15745define hook-echo
15746echo <<<---
15747end
104c1213 15748
8e04817f
AC
15749define hookpost-echo
15750echo --->>>\n
15751end
104c1213 15752
8e04817f
AC
15753(@value{GDBP}) echo Hello World
15754<<<---Hello World--->>>
15755(@value{GDBP})
104c1213 15756
474c8240 15757@end smallexample
104c1213 15758
8e04817f
AC
15759You can define a hook for any single-word command in @value{GDBN}, but
15760not for command aliases; you should define a hook for the basic command
15761name, e.g. @code{backtrace} rather than @code{bt}.
15762@c FIXME! So how does Joe User discover whether a command is an alias
15763@c or not?
15764If an error occurs during the execution of your hook, execution of
15765@value{GDBN} commands stops and @value{GDBN} issues a prompt
15766(before the command that you actually typed had a chance to run).
104c1213 15767
8e04817f
AC
15768If you try to define a hook which does not match any known command, you
15769get a warning from the @code{define} command.
c906108c 15770
8e04817f
AC
15771@node Command Files
15772@section Command files
c906108c 15773
8e04817f 15774@cindex command files
6fc08d32
EZ
15775A command file for @value{GDBN} is a text file made of lines that are
15776@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
15777also be included. An empty line in a command file does nothing; it
15778does not mean to repeat the last command, as it would from the
15779terminal.
c906108c 15780
6fc08d32
EZ
15781You can request the execution of a command file with the @code{source}
15782command:
c906108c 15783
8e04817f
AC
15784@table @code
15785@kindex source
15786@item source @var{filename}
15787Execute the command file @var{filename}.
c906108c
SS
15788@end table
15789
8e04817f 15790The lines in a command file are executed sequentially. They are not
a71ec265
DH
15791printed as they are executed. An error in any command terminates
15792execution of the command file and control is returned to the console.
c906108c 15793
8e04817f
AC
15794Commands that would ask for confirmation if used interactively proceed
15795without asking when used in a command file. Many @value{GDBN} commands that
15796normally print messages to say what they are doing omit the messages
15797when called from command files.
c906108c 15798
8e04817f
AC
15799@value{GDBN} also accepts command input from standard input. In this
15800mode, normal output goes to standard output and error output goes to
15801standard error. Errors in a command file supplied on standard input do
6fc08d32 15802not terminate execution of the command file---execution continues with
8e04817f 15803the next command.
c906108c 15804
474c8240 15805@smallexample
8e04817f 15806gdb < cmds > log 2>&1
474c8240 15807@end smallexample
c906108c 15808
8e04817f
AC
15809(The syntax above will vary depending on the shell used.) This example
15810will execute commands from the file @file{cmds}. All output and errors
15811would be directed to @file{log}.
c906108c 15812
8e04817f
AC
15813@node Output
15814@section Commands for controlled output
c906108c 15815
8e04817f
AC
15816During the execution of a command file or a user-defined command, normal
15817@value{GDBN} output is suppressed; the only output that appears is what is
15818explicitly printed by the commands in the definition. This section
15819describes three commands useful for generating exactly the output you
15820want.
c906108c
SS
15821
15822@table @code
8e04817f
AC
15823@kindex echo
15824@item echo @var{text}
15825@c I do not consider backslash-space a standard C escape sequence
15826@c because it is not in ANSI.
15827Print @var{text}. Nonprinting characters can be included in
15828@var{text} using C escape sequences, such as @samp{\n} to print a
15829newline. @strong{No newline is printed unless you specify one.}
15830In addition to the standard C escape sequences, a backslash followed
15831by a space stands for a space. This is useful for displaying a
15832string with spaces at the beginning or the end, since leading and
15833trailing spaces are otherwise trimmed from all arguments.
15834To print @samp{@w{ }and foo =@w{ }}, use the command
15835@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 15836
8e04817f
AC
15837A backslash at the end of @var{text} can be used, as in C, to continue
15838the command onto subsequent lines. For example,
c906108c 15839
474c8240 15840@smallexample
8e04817f
AC
15841echo This is some text\n\
15842which is continued\n\
15843onto several lines.\n
474c8240 15844@end smallexample
c906108c 15845
8e04817f 15846produces the same output as
c906108c 15847
474c8240 15848@smallexample
8e04817f
AC
15849echo This is some text\n
15850echo which is continued\n
15851echo onto several lines.\n
474c8240 15852@end smallexample
c906108c 15853
8e04817f
AC
15854@kindex output
15855@item output @var{expression}
15856Print the value of @var{expression} and nothing but that value: no
15857newlines, no @samp{$@var{nn} = }. The value is not entered in the
15858value history either. @xref{Expressions, ,Expressions}, for more information
15859on expressions.
c906108c 15860
8e04817f
AC
15861@item output/@var{fmt} @var{expression}
15862Print the value of @var{expression} in format @var{fmt}. You can use
15863the same formats as for @code{print}. @xref{Output Formats,,Output
15864formats}, for more information.
c906108c 15865
8e04817f
AC
15866@kindex printf
15867@item printf @var{string}, @var{expressions}@dots{}
15868Print the values of the @var{expressions} under the control of
15869@var{string}. The @var{expressions} are separated by commas and may be
15870either numbers or pointers. Their values are printed as specified by
15871@var{string}, exactly as if your program were to execute the C
15872subroutine
15873@c FIXME: the above implies that at least all ANSI C formats are
15874@c supported, but it isn't true: %E and %G don't work (or so it seems).
15875@c Either this is a bug, or the manual should document what formats are
15876@c supported.
c906108c 15877
474c8240 15878@smallexample
8e04817f 15879printf (@var{string}, @var{expressions}@dots{});
474c8240 15880@end smallexample
c906108c 15881
8e04817f 15882For example, you can print two values in hex like this:
c906108c 15883
8e04817f
AC
15884@smallexample
15885printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
15886@end smallexample
c906108c 15887
8e04817f
AC
15888The only backslash-escape sequences that you can use in the format
15889string are the simple ones that consist of backslash followed by a
15890letter.
c906108c
SS
15891@end table
15892
21c294e6
AC
15893@node Interpreters
15894@chapter Command Interpreters
15895@cindex command interpreters
15896
15897@value{GDBN} supports multiple command interpreters, and some command
15898infrastructure to allow users or user interface writers to switch
15899between interpreters or run commands in other interpreters.
15900
15901@value{GDBN} currently supports two command interpreters, the console
15902interpreter (sometimes called the command-line interpreter or @sc{cli})
15903and the machine interface interpreter (or @sc{gdb/mi}). This manual
15904describes both of these interfaces in great detail.
15905
15906By default, @value{GDBN} will start with the console interpreter.
15907However, the user may choose to start @value{GDBN} with another
15908interpreter by specifying the @option{-i} or @option{--interpreter}
15909startup options. Defined interpreters include:
15910
15911@table @code
15912@item console
15913@cindex console interpreter
15914The traditional console or command-line interpreter. This is the most often
15915used interpreter with @value{GDBN}. With no interpreter specified at runtime,
15916@value{GDBN} will use this interpreter.
15917
15918@item mi
15919@cindex mi interpreter
15920The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
15921by programs wishing to use @value{GDBN} as a backend for a debugger GUI
15922or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
15923Interface}.
15924
15925@item mi2
15926@cindex mi2 interpreter
15927The current @sc{gdb/mi} interface.
15928
15929@item mi1
15930@cindex mi1 interpreter
15931The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
15932
15933@end table
15934
15935@cindex invoke another interpreter
15936The interpreter being used by @value{GDBN} may not be dynamically
15937switched at runtime. Although possible, this could lead to a very
15938precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
15939enters the command "interpreter-set console" in a console view,
15940@value{GDBN} would switch to using the console interpreter, rendering
15941the IDE inoperable!
15942
15943@kindex interpreter-exec
15944Although you may only choose a single interpreter at startup, you may execute
15945commands in any interpreter from the current interpreter using the appropriate
15946command. If you are running the console interpreter, simply use the
15947@code{interpreter-exec} command:
15948
15949@smallexample
15950interpreter-exec mi "-data-list-register-names"
15951@end smallexample
15952
15953@sc{gdb/mi} has a similar command, although it is only available in versions of
15954@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
15955
8e04817f
AC
15956@node TUI
15957@chapter @value{GDBN} Text User Interface
15958@cindex TUI
d0d5df6f 15959@cindex Text User Interface
c906108c 15960
8e04817f
AC
15961@menu
15962* TUI Overview:: TUI overview
15963* TUI Keys:: TUI key bindings
7cf36c78 15964* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
15965* TUI Commands:: TUI specific commands
15966* TUI Configuration:: TUI configuration variables
15967@end menu
c906108c 15968
d0d5df6f
AC
15969The @value{GDBN} Text User Interface, TUI in short, is a terminal
15970interface which uses the @code{curses} library to show the source
15971file, the assembly output, the program registers and @value{GDBN}
15972commands in separate text windows.
15973
15974The TUI is enabled by invoking @value{GDBN} using either
15975@pindex gdbtui
15976@samp{gdbtui} or @samp{gdb -tui}.
c906108c 15977
8e04817f
AC
15978@node TUI Overview
15979@section TUI overview
c906108c 15980
8e04817f
AC
15981The TUI has two display modes that can be switched while
15982@value{GDBN} runs:
c906108c 15983
8e04817f
AC
15984@itemize @bullet
15985@item
15986A curses (or TUI) mode in which it displays several text
15987windows on the terminal.
c906108c 15988
8e04817f
AC
15989@item
15990A standard mode which corresponds to the @value{GDBN} configured without
15991the TUI.
15992@end itemize
c906108c 15993
8e04817f
AC
15994In the TUI mode, @value{GDBN} can display several text window
15995on the terminal:
c906108c 15996
8e04817f
AC
15997@table @emph
15998@item command
15999This window is the @value{GDBN} command window with the @value{GDBN}
16000prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
16001managed using readline but through the TUI. The @emph{command}
16002window is always visible.
c906108c 16003
8e04817f
AC
16004@item source
16005The source window shows the source file of the program. The current
16006line as well as active breakpoints are displayed in this window.
c906108c 16007
8e04817f
AC
16008@item assembly
16009The assembly window shows the disassembly output of the program.
c906108c 16010
8e04817f
AC
16011@item register
16012This window shows the processor registers. It detects when
16013a register is changed and when this is the case, registers that have
6a1b180d 16014changed are highlighted.
c906108c 16015
c906108c
SS
16016@end table
16017
269c21fe
SC
16018The source and assembly windows show the current program position
16019by highlighting the current line and marking them with the @samp{>} marker.
16020Breakpoints are also indicated with two markers. A first one
16021indicates the breakpoint type:
16022
16023@table @code
16024@item B
16025Breakpoint which was hit at least once.
16026
16027@item b
16028Breakpoint which was never hit.
16029
16030@item H
16031Hardware breakpoint which was hit at least once.
16032
16033@item h
16034Hardware breakpoint which was never hit.
16035
16036@end table
16037
16038The second marker indicates whether the breakpoint is enabled or not:
16039
16040@table @code
16041@item +
16042Breakpoint is enabled.
16043
16044@item -
16045Breakpoint is disabled.
16046
16047@end table
16048
8e04817f
AC
16049The source, assembly and register windows are attached to the thread
16050and the frame position. They are updated when the current thread
16051changes, when the frame changes or when the program counter changes.
16052These three windows are arranged by the TUI according to several
16053layouts. The layout defines which of these three windows are visible.
16054The following layouts are available:
c906108c 16055
8e04817f
AC
16056@itemize @bullet
16057@item
16058source
2df3850c 16059
8e04817f
AC
16060@item
16061assembly
16062
16063@item
16064source and assembly
16065
16066@item
16067source and registers
c906108c 16068
8e04817f
AC
16069@item
16070assembly and registers
2df3850c 16071
8e04817f 16072@end itemize
c906108c 16073
b7bb15bc
SC
16074On top of the command window a status line gives various information
16075concerning the current process begin debugged. The status line is
16076updated when the information it shows changes. The following fields
16077are displayed:
16078
16079@table @emph
16080@item target
16081Indicates the current gdb target
16082(@pxref{Targets, ,Specifying a Debugging Target}).
16083
16084@item process
16085Gives information about the current process or thread number.
16086When no process is being debugged, this field is set to @code{No process}.
16087
16088@item function
16089Gives the current function name for the selected frame.
16090The name is demangled if demangling is turned on (@pxref{Print Settings}).
16091When there is no symbol corresponding to the current program counter
16092the string @code{??} is displayed.
16093
16094@item line
16095Indicates the current line number for the selected frame.
16096When the current line number is not known the string @code{??} is displayed.
16097
16098@item pc
16099Indicates the current program counter address.
16100
16101@end table
16102
8e04817f
AC
16103@node TUI Keys
16104@section TUI Key Bindings
16105@cindex TUI key bindings
c906108c 16106
8e04817f
AC
16107The TUI installs several key bindings in the readline keymaps
16108(@pxref{Command Line Editing}).
16109They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
16110directly on the TUI layout and windows. The TUI also provides
16111a @emph{SingleKey} keymap which binds several keys directly to
16112@value{GDBN} commands. The following key bindings
8e04817f 16113are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 16114
8e04817f
AC
16115@table @kbd
16116@kindex C-x C-a
16117@item C-x C-a
16118@kindex C-x a
16119@itemx C-x a
16120@kindex C-x A
16121@itemx C-x A
16122Enter or leave the TUI mode. When the TUI mode is left,
16123the curses window management is left and @value{GDBN} operates using
16124its standard mode writing on the terminal directly. When the TUI
16125mode is entered, the control is given back to the curses windows.
16126The screen is then refreshed.
c906108c 16127
8e04817f
AC
16128@kindex C-x 1
16129@item C-x 1
16130Use a TUI layout with only one window. The layout will
16131either be @samp{source} or @samp{assembly}. When the TUI mode
16132is not active, it will switch to the TUI mode.
2df3850c 16133
8e04817f 16134Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 16135
8e04817f
AC
16136@kindex C-x 2
16137@item C-x 2
16138Use a TUI layout with at least two windows. When the current
16139layout shows already two windows, a next layout with two windows is used.
16140When a new layout is chosen, one window will always be common to the
16141previous layout and the new one.
c906108c 16142
8e04817f 16143Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 16144
72ffddc9
SC
16145@kindex C-x o
16146@item C-x o
16147Change the active window. The TUI associates several key bindings
16148(like scrolling and arrow keys) to the active window. This command
16149gives the focus to the next TUI window.
16150
16151Think of it as the Emacs @kbd{C-x o} binding.
16152
7cf36c78
SC
16153@kindex C-x s
16154@item C-x s
16155Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
16156(@pxref{TUI Single Key Mode}).
16157
c906108c
SS
16158@end table
16159
8e04817f 16160The following key bindings are handled only by the TUI mode:
5d161b24 16161
8e04817f
AC
16162@table @key
16163@kindex PgUp
16164@item PgUp
16165Scroll the active window one page up.
c906108c 16166
8e04817f
AC
16167@kindex PgDn
16168@item PgDn
16169Scroll the active window one page down.
c906108c 16170
8e04817f
AC
16171@kindex Up
16172@item Up
16173Scroll the active window one line up.
c906108c 16174
8e04817f
AC
16175@kindex Down
16176@item Down
16177Scroll the active window one line down.
c906108c 16178
8e04817f
AC
16179@kindex Left
16180@item Left
16181Scroll the active window one column left.
c906108c 16182
8e04817f
AC
16183@kindex Right
16184@item Right
16185Scroll the active window one column right.
c906108c 16186
8e04817f
AC
16187@kindex C-L
16188@item C-L
16189Refresh the screen.
c906108c 16190
8e04817f 16191@end table
c906108c 16192
8e04817f 16193In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
16194for scrolling. This means they are available for readline when the
16195active window is the command window. When the command window
16196does not have the focus, it is necessary to use other readline
16197key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 16198
7cf36c78
SC
16199@node TUI Single Key Mode
16200@section TUI Single Key Mode
16201@cindex TUI single key mode
16202
16203The TUI provides a @emph{SingleKey} mode in which it installs a particular
16204key binding in the readline keymaps to connect single keys to
b383017d 16205some gdb commands.
7cf36c78
SC
16206
16207@table @kbd
16208@kindex c @r{(SingleKey TUI key)}
16209@item c
16210continue
16211
16212@kindex d @r{(SingleKey TUI key)}
16213@item d
16214down
16215
16216@kindex f @r{(SingleKey TUI key)}
16217@item f
16218finish
16219
16220@kindex n @r{(SingleKey TUI key)}
16221@item n
16222next
16223
16224@kindex q @r{(SingleKey TUI key)}
16225@item q
16226exit the @emph{SingleKey} mode.
16227
16228@kindex r @r{(SingleKey TUI key)}
16229@item r
16230run
16231
16232@kindex s @r{(SingleKey TUI key)}
16233@item s
16234step
16235
16236@kindex u @r{(SingleKey TUI key)}
16237@item u
16238up
16239
16240@kindex v @r{(SingleKey TUI key)}
16241@item v
16242info locals
16243
16244@kindex w @r{(SingleKey TUI key)}
16245@item w
16246where
16247
16248@end table
16249
16250Other keys temporarily switch to the @value{GDBN} command prompt.
16251The key that was pressed is inserted in the editing buffer so that
16252it is possible to type most @value{GDBN} commands without interaction
16253with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
16254@emph{SingleKey} mode is restored. The only way to permanently leave
16255this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
16256
16257
8e04817f
AC
16258@node TUI Commands
16259@section TUI specific commands
16260@cindex TUI commands
16261
16262The TUI has specific commands to control the text windows.
16263These commands are always available, that is they do not depend on
16264the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
16265is in the standard mode, using these commands will automatically switch
16266in the TUI mode.
c906108c
SS
16267
16268@table @code
3d757584
SC
16269@item info win
16270@kindex info win
16271List and give the size of all displayed windows.
16272
8e04817f 16273@item layout next
4644b6e3 16274@kindex layout
8e04817f 16275Display the next layout.
2df3850c 16276
8e04817f 16277@item layout prev
8e04817f 16278Display the previous layout.
c906108c 16279
8e04817f 16280@item layout src
8e04817f 16281Display the source window only.
c906108c 16282
8e04817f 16283@item layout asm
8e04817f 16284Display the assembly window only.
c906108c 16285
8e04817f 16286@item layout split
8e04817f 16287Display the source and assembly window.
c906108c 16288
8e04817f 16289@item layout regs
8e04817f
AC
16290Display the register window together with the source or assembly window.
16291
16292@item focus next | prev | src | asm | regs | split
16293@kindex focus
16294Set the focus to the named window.
16295This command allows to change the active window so that scrolling keys
16296can be affected to another window.
c906108c 16297
8e04817f
AC
16298@item refresh
16299@kindex refresh
16300Refresh the screen. This is similar to using @key{C-L} key.
c906108c 16301
6a1b180d
SC
16302@item tui reg float
16303@kindex tui reg
16304Show the floating point registers in the register window.
16305
16306@item tui reg general
16307Show the general registers in the register window.
16308
16309@item tui reg next
16310Show the next register group. The list of register groups as well as
16311their order is target specific. The predefined register groups are the
16312following: @code{general}, @code{float}, @code{system}, @code{vector},
16313@code{all}, @code{save}, @code{restore}.
16314
16315@item tui reg system
16316Show the system registers in the register window.
16317
8e04817f
AC
16318@item update
16319@kindex update
16320Update the source window and the current execution point.
c906108c 16321
8e04817f
AC
16322@item winheight @var{name} +@var{count}
16323@itemx winheight @var{name} -@var{count}
16324@kindex winheight
16325Change the height of the window @var{name} by @var{count}
16326lines. Positive counts increase the height, while negative counts
16327decrease it.
2df3850c 16328
c45da7e6
EZ
16329@item tabset
16330@kindex tabset @var{nchars}
16331Set the width of tab stops to be @var{nchars} characters.
16332
c906108c
SS
16333@end table
16334
8e04817f
AC
16335@node TUI Configuration
16336@section TUI configuration variables
16337@cindex TUI configuration variables
c906108c 16338
8e04817f
AC
16339The TUI has several configuration variables that control the
16340appearance of windows on the terminal.
c906108c 16341
8e04817f
AC
16342@table @code
16343@item set tui border-kind @var{kind}
16344@kindex set tui border-kind
16345Select the border appearance for the source, assembly and register windows.
16346The possible values are the following:
16347@table @code
16348@item space
16349Use a space character to draw the border.
c906108c 16350
8e04817f
AC
16351@item ascii
16352Use ascii characters + - and | to draw the border.
c906108c 16353
8e04817f
AC
16354@item acs
16355Use the Alternate Character Set to draw the border. The border is
16356drawn using character line graphics if the terminal supports them.
c78b4128 16357
8e04817f 16358@end table
c78b4128 16359
8e04817f
AC
16360@item set tui active-border-mode @var{mode}
16361@kindex set tui active-border-mode
16362Select the attributes to display the border of the active window.
16363The possible values are @code{normal}, @code{standout}, @code{reverse},
16364@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 16365
8e04817f
AC
16366@item set tui border-mode @var{mode}
16367@kindex set tui border-mode
16368Select the attributes to display the border of other windows.
16369The @var{mode} can be one of the following:
16370@table @code
16371@item normal
16372Use normal attributes to display the border.
c906108c 16373
8e04817f
AC
16374@item standout
16375Use standout mode.
c906108c 16376
8e04817f
AC
16377@item reverse
16378Use reverse video mode.
c906108c 16379
8e04817f
AC
16380@item half
16381Use half bright mode.
c906108c 16382
8e04817f
AC
16383@item half-standout
16384Use half bright and standout mode.
c906108c 16385
8e04817f
AC
16386@item bold
16387Use extra bright or bold mode.
c78b4128 16388
8e04817f
AC
16389@item bold-standout
16390Use extra bright or bold and standout mode.
c78b4128 16391
8e04817f 16392@end table
c78b4128 16393
8e04817f 16394@end table
c78b4128 16395
8e04817f
AC
16396@node Emacs
16397@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 16398
8e04817f
AC
16399@cindex Emacs
16400@cindex @sc{gnu} Emacs
16401A special interface allows you to use @sc{gnu} Emacs to view (and
16402edit) the source files for the program you are debugging with
16403@value{GDBN}.
c906108c 16404
8e04817f
AC
16405To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
16406executable file you want to debug as an argument. This command starts
16407@value{GDBN} as a subprocess of Emacs, with input and output through a newly
16408created Emacs buffer.
16409@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 16410
8e04817f
AC
16411Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
16412things:
c906108c 16413
8e04817f
AC
16414@itemize @bullet
16415@item
16416All ``terminal'' input and output goes through the Emacs buffer.
16417@end itemize
c906108c 16418
8e04817f
AC
16419This applies both to @value{GDBN} commands and their output, and to the input
16420and output done by the program you are debugging.
bf0184be 16421
8e04817f
AC
16422This is useful because it means that you can copy the text of previous
16423commands and input them again; you can even use parts of the output
16424in this way.
bf0184be 16425
8e04817f
AC
16426All the facilities of Emacs' Shell mode are available for interacting
16427with your program. In particular, you can send signals the usual
16428way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
16429stop.
bf0184be 16430
8e04817f 16431@itemize @bullet
bf0184be 16432@item
8e04817f
AC
16433@value{GDBN} displays source code through Emacs.
16434@end itemize
bf0184be 16435
8e04817f
AC
16436Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
16437source file for that frame and puts an arrow (@samp{=>}) at the
16438left margin of the current line. Emacs uses a separate buffer for
16439source display, and splits the screen to show both your @value{GDBN} session
16440and the source.
bf0184be 16441
8e04817f
AC
16442Explicit @value{GDBN} @code{list} or search commands still produce output as
16443usual, but you probably have no reason to use them from Emacs.
c906108c 16444
64fabec2
AC
16445If you specify an absolute file name when prompted for the @kbd{M-x
16446gdb} argument, then Emacs sets your current working directory to where
16447your program resides. If you only specify the file name, then Emacs
16448sets your current working directory to to the directory associated
16449with the previous buffer. In this case, @value{GDBN} may find your
16450program by searching your environment's @code{PATH} variable, but on
16451some operating systems it might not find the source. So, although the
16452@value{GDBN} input and output session proceeds normally, the auxiliary
16453buffer does not display the current source and line of execution.
16454
16455The initial working directory of @value{GDBN} is printed on the top
16456line of the @value{GDBN} I/O buffer and this serves as a default for
16457the commands that specify files for @value{GDBN} to operate
16458on. @xref{Files, ,Commands to specify files}.
16459
16460By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
16461need to call @value{GDBN} by a different name (for example, if you
16462keep several configurations around, with different names) you can
16463customize the Emacs variable @code{gud-gdb-command-name} to run the
16464one you want.
8e04817f
AC
16465
16466In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
16467addition to the standard Shell mode commands:
c906108c 16468
8e04817f
AC
16469@table @kbd
16470@item C-h m
16471Describe the features of Emacs' @value{GDBN} Mode.
c906108c 16472
64fabec2 16473@item C-c C-s
8e04817f
AC
16474Execute to another source line, like the @value{GDBN} @code{step} command; also
16475update the display window to show the current file and location.
c906108c 16476
64fabec2 16477@item C-c C-n
8e04817f
AC
16478Execute to next source line in this function, skipping all function
16479calls, like the @value{GDBN} @code{next} command. Then update the display window
16480to show the current file and location.
c906108c 16481
64fabec2 16482@item C-c C-i
8e04817f
AC
16483Execute one instruction, like the @value{GDBN} @code{stepi} command; update
16484display window accordingly.
c906108c 16485
8e04817f
AC
16486@item C-c C-f
16487Execute until exit from the selected stack frame, like the @value{GDBN}
16488@code{finish} command.
c906108c 16489
64fabec2 16490@item C-c C-r
8e04817f
AC
16491Continue execution of your program, like the @value{GDBN} @code{continue}
16492command.
b433d00b 16493
64fabec2 16494@item C-c <
8e04817f
AC
16495Go up the number of frames indicated by the numeric argument
16496(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
16497like the @value{GDBN} @code{up} command.
b433d00b 16498
64fabec2 16499@item C-c >
8e04817f
AC
16500Go down the number of frames indicated by the numeric argument, like the
16501@value{GDBN} @code{down} command.
8e04817f 16502@end table
c906108c 16503
64fabec2 16504In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 16505tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 16506
64fabec2
AC
16507If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
16508shows a backtrace when the @value{GDBN} I/O buffer is current. Move
16509point to any frame in the stack and type @key{RET} to make it become the
16510current frame and display the associated source in the source buffer.
16511Alternatively, click @kbd{Mouse-2} to make the selected frame become the
16512current one.
16513
8e04817f
AC
16514If you accidentally delete the source-display buffer, an easy way to get
16515it back is to type the command @code{f} in the @value{GDBN} buffer, to
16516request a frame display; when you run under Emacs, this recreates
16517the source buffer if necessary to show you the context of the current
16518frame.
c906108c 16519
8e04817f
AC
16520The source files displayed in Emacs are in ordinary Emacs buffers
16521which are visiting the source files in the usual way. You can edit
16522the files with these buffers if you wish; but keep in mind that @value{GDBN}
16523communicates with Emacs in terms of line numbers. If you add or
16524delete lines from the text, the line numbers that @value{GDBN} knows cease
16525to correspond properly with the code.
b383017d 16526
64fabec2
AC
16527The description given here is for GNU Emacs version 21.3 and a more
16528detailed description of its interaction with @value{GDBN} is given in
16529the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 16530
8e04817f
AC
16531@c The following dropped because Epoch is nonstandard. Reactivate
16532@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
16533@ignore
16534@kindex Emacs Epoch environment
16535@kindex Epoch
16536@kindex inspect
c906108c 16537
8e04817f
AC
16538Version 18 of @sc{gnu} Emacs has a built-in window system
16539called the @code{epoch}
16540environment. Users of this environment can use a new command,
16541@code{inspect} which performs identically to @code{print} except that
16542each value is printed in its own window.
16543@end ignore
c906108c 16544
922fbb7b
AC
16545
16546@node GDB/MI
16547@chapter The @sc{gdb/mi} Interface
16548
16549@unnumberedsec Function and Purpose
16550
16551@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
16552@sc{gdb/mi} is a line based machine oriented text interface to
16553@value{GDBN} and is activated by specifying using the
16554@option{--interpreter} command line option (@pxref{Mode Options}). It
16555is specifically intended to support the development of systems which
16556use the debugger as just one small component of a larger system.
922fbb7b
AC
16557
16558This chapter is a specification of the @sc{gdb/mi} interface. It is written
16559in the form of a reference manual.
16560
16561Note that @sc{gdb/mi} is still under construction, so some of the
16562features described below are incomplete and subject to change.
16563
16564@unnumberedsec Notation and Terminology
16565
16566@cindex notational conventions, for @sc{gdb/mi}
16567This chapter uses the following notation:
16568
16569@itemize @bullet
16570@item
16571@code{|} separates two alternatives.
16572
16573@item
16574@code{[ @var{something} ]} indicates that @var{something} is optional:
16575it may or may not be given.
16576
16577@item
16578@code{( @var{group} )*} means that @var{group} inside the parentheses
16579may repeat zero or more times.
16580
16581@item
16582@code{( @var{group} )+} means that @var{group} inside the parentheses
16583may repeat one or more times.
16584
16585@item
16586@code{"@var{string}"} means a literal @var{string}.
16587@end itemize
16588
16589@ignore
16590@heading Dependencies
16591@end ignore
16592
16593@heading Acknowledgments
16594
16595In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
16596Elena Zannoni.
16597
16598@menu
16599* GDB/MI Command Syntax::
16600* GDB/MI Compatibility with CLI::
16601* GDB/MI Output Records::
16602* GDB/MI Command Description Format::
16603* GDB/MI Breakpoint Table Commands::
16604* GDB/MI Data Manipulation::
16605* GDB/MI Program Control::
16606* GDB/MI Miscellaneous Commands::
16607@ignore
16608* GDB/MI Kod Commands::
16609* GDB/MI Memory Overlay Commands::
16610* GDB/MI Signal Handling Commands::
16611@end ignore
16612* GDB/MI Stack Manipulation::
16613* GDB/MI Symbol Query::
16614* GDB/MI Target Manipulation::
16615* GDB/MI Thread Commands::
16616* GDB/MI Tracepoint Commands::
16617* GDB/MI Variable Objects::
16618@end menu
16619
16620@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16621@node GDB/MI Command Syntax
16622@section @sc{gdb/mi} Command Syntax
16623
16624@menu
16625* GDB/MI Input Syntax::
16626* GDB/MI Output Syntax::
16627* GDB/MI Simple Examples::
16628@end menu
16629
16630@node GDB/MI Input Syntax
16631@subsection @sc{gdb/mi} Input Syntax
16632
16633@cindex input syntax for @sc{gdb/mi}
16634@cindex @sc{gdb/mi}, input syntax
16635@table @code
16636@item @var{command} @expansion{}
16637@code{@var{cli-command} | @var{mi-command}}
16638
16639@item @var{cli-command} @expansion{}
16640@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
16641@var{cli-command} is any existing @value{GDBN} CLI command.
16642
16643@item @var{mi-command} @expansion{}
16644@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
16645@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
16646
16647@item @var{token} @expansion{}
16648"any sequence of digits"
16649
16650@item @var{option} @expansion{}
16651@code{"-" @var{parameter} [ " " @var{parameter} ]}
16652
16653@item @var{parameter} @expansion{}
16654@code{@var{non-blank-sequence} | @var{c-string}}
16655
16656@item @var{operation} @expansion{}
16657@emph{any of the operations described in this chapter}
16658
16659@item @var{non-blank-sequence} @expansion{}
16660@emph{anything, provided it doesn't contain special characters such as
16661"-", @var{nl}, """ and of course " "}
16662
16663@item @var{c-string} @expansion{}
16664@code{""" @var{seven-bit-iso-c-string-content} """}
16665
16666@item @var{nl} @expansion{}
16667@code{CR | CR-LF}
16668@end table
16669
16670@noindent
16671Notes:
16672
16673@itemize @bullet
16674@item
16675The CLI commands are still handled by the @sc{mi} interpreter; their
16676output is described below.
16677
16678@item
16679The @code{@var{token}}, when present, is passed back when the command
16680finishes.
16681
16682@item
16683Some @sc{mi} commands accept optional arguments as part of the parameter
16684list. Each option is identified by a leading @samp{-} (dash) and may be
16685followed by an optional argument parameter. Options occur first in the
16686parameter list and can be delimited from normal parameters using
16687@samp{--} (this is useful when some parameters begin with a dash).
16688@end itemize
16689
16690Pragmatics:
16691
16692@itemize @bullet
16693@item
16694We want easy access to the existing CLI syntax (for debugging).
16695
16696@item
16697We want it to be easy to spot a @sc{mi} operation.
16698@end itemize
16699
16700@node GDB/MI Output Syntax
16701@subsection @sc{gdb/mi} Output Syntax
16702
16703@cindex output syntax of @sc{gdb/mi}
16704@cindex @sc{gdb/mi}, output syntax
16705The output from @sc{gdb/mi} consists of zero or more out-of-band records
16706followed, optionally, by a single result record. This result record
16707is for the most recent command. The sequence of output records is
16708terminated by @samp{(@value{GDBP})}.
16709
16710If an input command was prefixed with a @code{@var{token}} then the
16711corresponding output for that command will also be prefixed by that same
16712@var{token}.
16713
16714@table @code
16715@item @var{output} @expansion{}
f7dc1244 16716@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
922fbb7b
AC
16717
16718@item @var{result-record} @expansion{}
16719@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
16720
16721@item @var{out-of-band-record} @expansion{}
16722@code{@var{async-record} | @var{stream-record}}
16723
16724@item @var{async-record} @expansion{}
16725@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
16726
16727@item @var{exec-async-output} @expansion{}
16728@code{[ @var{token} ] "*" @var{async-output}}
16729
16730@item @var{status-async-output} @expansion{}
16731@code{[ @var{token} ] "+" @var{async-output}}
16732
16733@item @var{notify-async-output} @expansion{}
16734@code{[ @var{token} ] "=" @var{async-output}}
16735
16736@item @var{async-output} @expansion{}
16737@code{@var{async-class} ( "," @var{result} )* @var{nl}}
16738
16739@item @var{result-class} @expansion{}
16740@code{"done" | "running" | "connected" | "error" | "exit"}
16741
16742@item @var{async-class} @expansion{}
16743@code{"stopped" | @var{others}} (where @var{others} will be added
16744depending on the needs---this is still in development).
16745
16746@item @var{result} @expansion{}
16747@code{ @var{variable} "=" @var{value}}
16748
16749@item @var{variable} @expansion{}
16750@code{ @var{string} }
16751
16752@item @var{value} @expansion{}
16753@code{ @var{const} | @var{tuple} | @var{list} }
16754
16755@item @var{const} @expansion{}
16756@code{@var{c-string}}
16757
16758@item @var{tuple} @expansion{}
16759@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
16760
16761@item @var{list} @expansion{}
16762@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
16763@var{result} ( "," @var{result} )* "]" }
16764
16765@item @var{stream-record} @expansion{}
16766@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
16767
16768@item @var{console-stream-output} @expansion{}
16769@code{"~" @var{c-string}}
16770
16771@item @var{target-stream-output} @expansion{}
16772@code{"@@" @var{c-string}}
16773
16774@item @var{log-stream-output} @expansion{}
16775@code{"&" @var{c-string}}
16776
16777@item @var{nl} @expansion{}
16778@code{CR | CR-LF}
16779
16780@item @var{token} @expansion{}
16781@emph{any sequence of digits}.
16782@end table
16783
16784@noindent
16785Notes:
16786
16787@itemize @bullet
16788@item
16789All output sequences end in a single line containing a period.
16790
16791@item
16792The @code{@var{token}} is from the corresponding request. If an execution
16793command is interrupted by the @samp{-exec-interrupt} command, the
16794@var{token} associated with the @samp{*stopped} message is the one of the
16795original execution command, not the one of the interrupt command.
16796
16797@item
16798@cindex status output in @sc{gdb/mi}
16799@var{status-async-output} contains on-going status information about the
16800progress of a slow operation. It can be discarded. All status output is
16801prefixed by @samp{+}.
16802
16803@item
16804@cindex async output in @sc{gdb/mi}
16805@var{exec-async-output} contains asynchronous state change on the target
16806(stopped, started, disappeared). All async output is prefixed by
16807@samp{*}.
16808
16809@item
16810@cindex notify output in @sc{gdb/mi}
16811@var{notify-async-output} contains supplementary information that the
16812client should handle (e.g., a new breakpoint information). All notify
16813output is prefixed by @samp{=}.
16814
16815@item
16816@cindex console output in @sc{gdb/mi}
16817@var{console-stream-output} is output that should be displayed as is in the
16818console. It is the textual response to a CLI command. All the console
16819output is prefixed by @samp{~}.
16820
16821@item
16822@cindex target output in @sc{gdb/mi}
16823@var{target-stream-output} is the output produced by the target program.
16824All the target output is prefixed by @samp{@@}.
16825
16826@item
16827@cindex log output in @sc{gdb/mi}
16828@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
16829instance messages that should be displayed as part of an error log. All
16830the log output is prefixed by @samp{&}.
16831
16832@item
16833@cindex list output in @sc{gdb/mi}
16834New @sc{gdb/mi} commands should only output @var{lists} containing
16835@var{values}.
16836
16837
16838@end itemize
16839
16840@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
16841details about the various output records.
16842
16843@node GDB/MI Simple Examples
16844@subsection Simple Examples of @sc{gdb/mi} Interaction
16845@cindex @sc{gdb/mi}, simple examples
16846
16847This subsection presents several simple examples of interaction using
16848the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
16849following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
16850the output received from @sc{gdb/mi}.
16851
16852@subsubheading Target Stop
16853@c Ummm... There is no "-stop" command. This assumes async, no?
16854Here's an example of stopping the inferior process:
16855
16856@smallexample
16857-> -stop
16858<- (@value{GDBP})
16859@end smallexample
16860
16861@noindent
16862and later:
16863
16864@smallexample
16865<- *stop,reason="stop",address="0x123",source="a.c:123"
16866<- (@value{GDBP})
16867@end smallexample
16868
16869@subsubheading Simple CLI Command
16870
16871Here's an example of a simple CLI command being passed through
16872@sc{gdb/mi} and on to the CLI.
16873
16874@smallexample
16875-> print 1+2
16876<- &"print 1+2\n"
16877<- ~"$1 = 3\n"
16878<- ^done
16879<- (@value{GDBP})
16880@end smallexample
16881
16882@subsubheading Command With Side Effects
16883
16884@smallexample
16885-> -symbol-file xyz.exe
16886<- *breakpoint,nr="3",address="0x123",source="a.c:123"
16887<- (@value{GDBP})
16888@end smallexample
16889
16890@subsubheading A Bad Command
16891
16892Here's what happens if you pass a non-existent command:
16893
16894@smallexample
16895-> -rubbish
16896<- ^error,msg="Undefined MI command: rubbish"
16897<- (@value{GDBP})
16898@end smallexample
16899
16900@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16901@node GDB/MI Compatibility with CLI
16902@section @sc{gdb/mi} Compatibility with CLI
16903
16904@cindex compatibility, @sc{gdb/mi} and CLI
16905@cindex @sc{gdb/mi}, compatibility with CLI
16906To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
16907accepts existing CLI commands. As specified by the syntax, such
16908commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
16909respond.
16910
16911This mechanism is provided as an aid to developers of @sc{gdb/mi}
16912clients and not as a reliable interface into the CLI. Since the command
16913is being interpreteted in an environment that assumes @sc{gdb/mi}
16914behaviour, the exact output of such commands is likely to end up being
16915an un-supported hybrid of @sc{gdb/mi} and CLI output.
16916
16917@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16918@node GDB/MI Output Records
16919@section @sc{gdb/mi} Output Records
16920
16921@menu
16922* GDB/MI Result Records::
16923* GDB/MI Stream Records::
16924* GDB/MI Out-of-band Records::
16925@end menu
16926
16927@node GDB/MI Result Records
16928@subsection @sc{gdb/mi} Result Records
16929
16930@cindex result records in @sc{gdb/mi}
16931@cindex @sc{gdb/mi}, result records
16932In addition to a number of out-of-band notifications, the response to a
16933@sc{gdb/mi} command includes one of the following result indications:
16934
16935@table @code
16936@findex ^done
16937@item "^done" [ "," @var{results} ]
16938The synchronous operation was successful, @code{@var{results}} are the return
16939values.
16940
16941@item "^running"
16942@findex ^running
16943@c Is this one correct? Should it be an out-of-band notification?
16944The asynchronous operation was successfully started. The target is
16945running.
16946
16947@item "^error" "," @var{c-string}
16948@findex ^error
16949The operation failed. The @code{@var{c-string}} contains the corresponding
16950error message.
16951@end table
16952
16953@node GDB/MI Stream Records
16954@subsection @sc{gdb/mi} Stream Records
16955
16956@cindex @sc{gdb/mi}, stream records
16957@cindex stream records in @sc{gdb/mi}
16958@value{GDBN} internally maintains a number of output streams: the console, the
16959target, and the log. The output intended for each of these streams is
16960funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
16961
16962Each stream record begins with a unique @dfn{prefix character} which
16963identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
16964Syntax}). In addition to the prefix, each stream record contains a
16965@code{@var{string-output}}. This is either raw text (with an implicit new
16966line) or a quoted C string (which does not contain an implicit newline).
16967
16968@table @code
16969@item "~" @var{string-output}
16970The console output stream contains text that should be displayed in the
16971CLI console window. It contains the textual responses to CLI commands.
16972
16973@item "@@" @var{string-output}
16974The target output stream contains any textual output from the running
16975target.
16976
16977@item "&" @var{string-output}
16978The log stream contains debugging messages being produced by @value{GDBN}'s
16979internals.
16980@end table
16981
16982@node GDB/MI Out-of-band Records
16983@subsection @sc{gdb/mi} Out-of-band Records
16984
16985@cindex out-of-band records in @sc{gdb/mi}
16986@cindex @sc{gdb/mi}, out-of-band records
16987@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
16988additional changes that have occurred. Those changes can either be a
16989consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
16990target activity (e.g., target stopped).
16991
16992The following is a preliminary list of possible out-of-band records.
034dad6f 16993In particular, the @var{exec-async-output} records.
922fbb7b
AC
16994
16995@table @code
034dad6f
BR
16996@item *stopped,reason="@var{reason}"
16997@end table
16998
16999@var{reason} can be one of the following:
17000
17001@table @code
17002@item breakpoint-hit
17003A breakpoint was reached.
17004@item watchpoint-trigger
17005A watchpoint was triggered.
17006@item read-watchpoint-trigger
17007A read watchpoint was triggered.
17008@item access-watchpoint-trigger
17009An access watchpoint was triggered.
17010@item function-finished
17011An -exec-finish or similar CLI command was accomplished.
17012@item location-reached
17013An -exec-until or similar CLI command was accomplished.
17014@item watchpoint-scope
17015A watchpoint has gone out of scope.
17016@item end-stepping-range
17017An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
17018similar CLI command was accomplished.
17019@item exited-signalled
17020The inferior exited because of a signal.
17021@item exited
17022The inferior exited.
17023@item exited-normally
17024The inferior exited normally.
17025@item signal-received
17026A signal was received by the inferior.
922fbb7b
AC
17027@end table
17028
17029
17030@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17031@node GDB/MI Command Description Format
17032@section @sc{gdb/mi} Command Description Format
17033
17034The remaining sections describe blocks of commands. Each block of
17035commands is laid out in a fashion similar to this section.
17036
17037Note the the line breaks shown in the examples are here only for
17038readability. They don't appear in the real output.
17039Also note that the commands with a non-available example (N.A.@:) are
17040not yet implemented.
17041
17042@subheading Motivation
17043
17044The motivation for this collection of commands.
17045
17046@subheading Introduction
17047
17048A brief introduction to this collection of commands as a whole.
17049
17050@subheading Commands
17051
17052For each command in the block, the following is described:
17053
17054@subsubheading Synopsis
17055
17056@smallexample
17057 -command @var{args}@dots{}
17058@end smallexample
17059
17060@subsubheading @value{GDBN} Command
17061
17062The corresponding @value{GDBN} CLI command.
17063
17064@subsubheading Result
17065
17066@subsubheading Out-of-band
17067
17068@subsubheading Notes
17069
17070@subsubheading Example
17071
17072
17073@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17074@node GDB/MI Breakpoint Table Commands
17075@section @sc{gdb/mi} Breakpoint table commands
17076
17077@cindex breakpoint commands for @sc{gdb/mi}
17078@cindex @sc{gdb/mi}, breakpoint commands
17079This section documents @sc{gdb/mi} commands for manipulating
17080breakpoints.
17081
17082@subheading The @code{-break-after} Command
17083@findex -break-after
17084
17085@subsubheading Synopsis
17086
17087@smallexample
17088 -break-after @var{number} @var{count}
17089@end smallexample
17090
17091The breakpoint number @var{number} is not in effect until it has been
17092hit @var{count} times. To see how this is reflected in the output of
17093the @samp{-break-list} command, see the description of the
17094@samp{-break-list} command below.
17095
17096@subsubheading @value{GDBN} Command
17097
17098The corresponding @value{GDBN} command is @samp{ignore}.
17099
17100@subsubheading Example
17101
17102@smallexample
17103(@value{GDBP})
17104-break-insert main
17105^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
17106(@value{GDBP})
17107-break-after 1 3
17108~
17109^done
17110(@value{GDBP})
17111-break-list
17112^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17113hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17114@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17115@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17116@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17117@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17118@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17119body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17120addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
17121ignore="3"@}]@}
17122(@value{GDBP})
17123@end smallexample
17124
17125@ignore
17126@subheading The @code{-break-catch} Command
17127@findex -break-catch
17128
17129@subheading The @code{-break-commands} Command
17130@findex -break-commands
17131@end ignore
17132
17133
17134@subheading The @code{-break-condition} Command
17135@findex -break-condition
17136
17137@subsubheading Synopsis
17138
17139@smallexample
17140 -break-condition @var{number} @var{expr}
17141@end smallexample
17142
17143Breakpoint @var{number} will stop the program only if the condition in
17144@var{expr} is true. The condition becomes part of the
17145@samp{-break-list} output (see the description of the @samp{-break-list}
17146command below).
17147
17148@subsubheading @value{GDBN} Command
17149
17150The corresponding @value{GDBN} command is @samp{condition}.
17151
17152@subsubheading Example
17153
17154@smallexample
17155(@value{GDBP})
17156-break-condition 1 1
17157^done
17158(@value{GDBP})
17159-break-list
17160^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17161hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17162@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17163@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17164@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17165@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17166@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17167body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17168addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
17169times="0",ignore="3"@}]@}
17170(@value{GDBP})
17171@end smallexample
17172
17173@subheading The @code{-break-delete} Command
17174@findex -break-delete
17175
17176@subsubheading Synopsis
17177
17178@smallexample
17179 -break-delete ( @var{breakpoint} )+
17180@end smallexample
17181
17182Delete the breakpoint(s) whose number(s) are specified in the argument
17183list. This is obviously reflected in the breakpoint list.
17184
17185@subsubheading @value{GDBN} command
17186
17187The corresponding @value{GDBN} command is @samp{delete}.
17188
17189@subsubheading Example
17190
17191@smallexample
17192(@value{GDBP})
17193-break-delete 1
17194^done
17195(@value{GDBP})
17196-break-list
17197^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17198hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17199@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17200@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17201@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17202@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17203@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17204body=[]@}
17205(@value{GDBP})
17206@end smallexample
17207
17208@subheading The @code{-break-disable} Command
17209@findex -break-disable
17210
17211@subsubheading Synopsis
17212
17213@smallexample
17214 -break-disable ( @var{breakpoint} )+
17215@end smallexample
17216
17217Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
17218break list is now set to @samp{n} for the named @var{breakpoint}(s).
17219
17220@subsubheading @value{GDBN} Command
17221
17222The corresponding @value{GDBN} command is @samp{disable}.
17223
17224@subsubheading Example
17225
17226@smallexample
17227(@value{GDBP})
17228-break-disable 2
17229^done
17230(@value{GDBP})
17231-break-list
17232^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17233hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17234@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17235@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17236@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17237@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17238@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17239body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
17240addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17241(@value{GDBP})
17242@end smallexample
17243
17244@subheading The @code{-break-enable} Command
17245@findex -break-enable
17246
17247@subsubheading Synopsis
17248
17249@smallexample
17250 -break-enable ( @var{breakpoint} )+
17251@end smallexample
17252
17253Enable (previously disabled) @var{breakpoint}(s).
17254
17255@subsubheading @value{GDBN} Command
17256
17257The corresponding @value{GDBN} command is @samp{enable}.
17258
17259@subsubheading Example
17260
17261@smallexample
17262(@value{GDBP})
17263-break-enable 2
17264^done
17265(@value{GDBP})
17266-break-list
17267^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17268hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17269@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17270@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17271@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17272@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17273@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17274body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17275addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17276(@value{GDBP})
17277@end smallexample
17278
17279@subheading The @code{-break-info} Command
17280@findex -break-info
17281
17282@subsubheading Synopsis
17283
17284@smallexample
17285 -break-info @var{breakpoint}
17286@end smallexample
17287
17288@c REDUNDANT???
17289Get information about a single breakpoint.
17290
17291@subsubheading @value{GDBN} command
17292
17293The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
17294
17295@subsubheading Example
17296N.A.
17297
17298@subheading The @code{-break-insert} Command
17299@findex -break-insert
17300
17301@subsubheading Synopsis
17302
17303@smallexample
17304 -break-insert [ -t ] [ -h ] [ -r ]
17305 [ -c @var{condition} ] [ -i @var{ignore-count} ]
17306 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
17307@end smallexample
17308
17309@noindent
17310If specified, @var{line}, can be one of:
17311
17312@itemize @bullet
17313@item function
17314@c @item +offset
17315@c @item -offset
17316@c @item linenum
17317@item filename:linenum
17318@item filename:function
17319@item *address
17320@end itemize
17321
17322The possible optional parameters of this command are:
17323
17324@table @samp
17325@item -t
17326Insert a tempoary breakpoint.
17327@item -h
17328Insert a hardware breakpoint.
17329@item -c @var{condition}
17330Make the breakpoint conditional on @var{condition}.
17331@item -i @var{ignore-count}
17332Initialize the @var{ignore-count}.
17333@item -r
17334Insert a regular breakpoint in all the functions whose names match the
17335given regular expression. Other flags are not applicable to regular
17336expresson.
17337@end table
17338
17339@subsubheading Result
17340
17341The result is in the form:
17342
17343@smallexample
17344 ^done,bkptno="@var{number}",func="@var{funcname}",
17345 file="@var{filename}",line="@var{lineno}"
17346@end smallexample
17347
17348@noindent
17349where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
17350is the name of the function where the breakpoint was inserted,
17351@var{filename} is the name of the source file which contains this
17352function, and @var{lineno} is the source line number within that file.
17353
17354Note: this format is open to change.
17355@c An out-of-band breakpoint instead of part of the result?
17356
17357@subsubheading @value{GDBN} Command
17358
17359The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
17360@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
17361
17362@subsubheading Example
17363
17364@smallexample
17365(@value{GDBP})
17366-break-insert main
17367^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17368(@value{GDBP})
17369-break-insert -t foo
17370^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
17371(@value{GDBP})
17372-break-list
17373^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17374hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17375@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17376@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17377@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17378@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17379@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17380body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17381addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
17382bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
17383addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
17384(@value{GDBP})
17385-break-insert -r foo.*
17386~int foo(int, int);
17387^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
17388(@value{GDBP})
17389@end smallexample
17390
17391@subheading The @code{-break-list} Command
17392@findex -break-list
17393
17394@subsubheading Synopsis
17395
17396@smallexample
17397 -break-list
17398@end smallexample
17399
17400Displays the list of inserted breakpoints, showing the following fields:
17401
17402@table @samp
17403@item Number
17404number of the breakpoint
17405@item Type
17406type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
17407@item Disposition
17408should the breakpoint be deleted or disabled when it is hit: @samp{keep}
17409or @samp{nokeep}
17410@item Enabled
17411is the breakpoint enabled or no: @samp{y} or @samp{n}
17412@item Address
17413memory location at which the breakpoint is set
17414@item What
17415logical location of the breakpoint, expressed by function name, file
17416name, line number
17417@item Times
17418number of times the breakpoint has been hit
17419@end table
17420
17421If there are no breakpoints or watchpoints, the @code{BreakpointTable}
17422@code{body} field is an empty list.
17423
17424@subsubheading @value{GDBN} Command
17425
17426The corresponding @value{GDBN} command is @samp{info break}.
17427
17428@subsubheading Example
17429
17430@smallexample
17431(@value{GDBP})
17432-break-list
17433^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17434hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17435@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17436@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17437@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17438@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17439@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17440body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17441addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
17442bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17443addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
17444(@value{GDBP})
17445@end smallexample
17446
17447Here's an example of the result when there are no breakpoints:
17448
17449@smallexample
17450(@value{GDBP})
17451-break-list
17452^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17453hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17454@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17455@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17456@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17457@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17458@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17459body=[]@}
17460(@value{GDBP})
17461@end smallexample
17462
17463@subheading The @code{-break-watch} Command
17464@findex -break-watch
17465
17466@subsubheading Synopsis
17467
17468@smallexample
17469 -break-watch [ -a | -r ]
17470@end smallexample
17471
17472Create a watchpoint. With the @samp{-a} option it will create an
17473@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
17474read from or on a write to the memory location. With the @samp{-r}
17475option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
17476trigger only when the memory location is accessed for reading. Without
17477either of the options, the watchpoint created is a regular watchpoint,
17478i.e. it will trigger when the memory location is accessed for writing.
17479@xref{Set Watchpoints, , Setting watchpoints}.
17480
17481Note that @samp{-break-list} will report a single list of watchpoints and
17482breakpoints inserted.
17483
17484@subsubheading @value{GDBN} Command
17485
17486The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
17487@samp{rwatch}.
17488
17489@subsubheading Example
17490
17491Setting a watchpoint on a variable in the @code{main} function:
17492
17493@smallexample
17494(@value{GDBP})
17495-break-watch x
17496^done,wpt=@{number="2",exp="x"@}
17497(@value{GDBP})
17498-exec-continue
17499^running
17500^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
17501value=@{old="-268439212",new="55"@},
76ff342d
DJ
17502frame=@{func="main",args=[],file="recursive2.c",
17503fullname="/home/foo/bar/devo/myproject/recursive2.c",line="5"@}
922fbb7b
AC
17504(@value{GDBP})
17505@end smallexample
17506
17507Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
17508the program execution twice: first for the variable changing value, then
17509for the watchpoint going out of scope.
17510
17511@smallexample
17512(@value{GDBP})
17513-break-watch C
17514^done,wpt=@{number="5",exp="C"@}
17515(@value{GDBP})
17516-exec-continue
17517^running
17518^done,reason="watchpoint-trigger",
17519wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
17520frame=@{func="callee4",args=[],
76ff342d
DJ
17521file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17522fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17523(@value{GDBP})
17524-exec-continue
17525^running
17526^done,reason="watchpoint-scope",wpnum="5",
17527frame=@{func="callee3",args=[@{name="strarg",
17528value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17529file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17530fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17531(@value{GDBP})
17532@end smallexample
17533
17534Listing breakpoints and watchpoints, at different points in the program
17535execution. Note that once the watchpoint goes out of scope, it is
17536deleted.
17537
17538@smallexample
17539(@value{GDBP})
17540-break-watch C
17541^done,wpt=@{number="2",exp="C"@}
17542(@value{GDBP})
17543-break-list
17544^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17545hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17546@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17547@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17548@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17549@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17550@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17551body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17552addr="0x00010734",func="callee4",
17553file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17554bkpt=@{number="2",type="watchpoint",disp="keep",
17555enabled="y",addr="",what="C",times="0"@}]@}
17556(@value{GDBP})
17557-exec-continue
17558^running
17559^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
17560value=@{old="-276895068",new="3"@},
17561frame=@{func="callee4",args=[],
76ff342d
DJ
17562file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17563fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17564(@value{GDBP})
17565-break-list
17566^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17567hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17568@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17569@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17570@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17571@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17572@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17573body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17574addr="0x00010734",func="callee4",
17575file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17576bkpt=@{number="2",type="watchpoint",disp="keep",
17577enabled="y",addr="",what="C",times="-5"@}]@}
17578(@value{GDBP})
17579-exec-continue
17580^running
17581^done,reason="watchpoint-scope",wpnum="2",
17582frame=@{func="callee3",args=[@{name="strarg",
17583value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17584file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17585fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17586(@value{GDBP})
17587-break-list
17588^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17589hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17590@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17591@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17592@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17593@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17594@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17595body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17596addr="0x00010734",func="callee4",
17597file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
17598(@value{GDBP})
17599@end smallexample
17600
17601@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17602@node GDB/MI Data Manipulation
17603@section @sc{gdb/mi} Data Manipulation
17604
17605@cindex data manipulation, in @sc{gdb/mi}
17606@cindex @sc{gdb/mi}, data manipulation
17607This section describes the @sc{gdb/mi} commands that manipulate data:
17608examine memory and registers, evaluate expressions, etc.
17609
17610@c REMOVED FROM THE INTERFACE.
17611@c @subheading -data-assign
17612@c Change the value of a program variable. Plenty of side effects.
17613@c @subsubheading GDB command
17614@c set variable
17615@c @subsubheading Example
17616@c N.A.
17617
17618@subheading The @code{-data-disassemble} Command
17619@findex -data-disassemble
17620
17621@subsubheading Synopsis
17622
17623@smallexample
17624 -data-disassemble
17625 [ -s @var{start-addr} -e @var{end-addr} ]
17626 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
17627 -- @var{mode}
17628@end smallexample
17629
17630@noindent
17631Where:
17632
17633@table @samp
17634@item @var{start-addr}
17635is the beginning address (or @code{$pc})
17636@item @var{end-addr}
17637is the end address
17638@item @var{filename}
17639is the name of the file to disassemble
17640@item @var{linenum}
17641is the line number to disassemble around
17642@item @var{lines}
17643is the the number of disassembly lines to be produced. If it is -1,
17644the whole function will be disassembled, in case no @var{end-addr} is
17645specified. If @var{end-addr} is specified as a non-zero value, and
17646@var{lines} is lower than the number of disassembly lines between
17647@var{start-addr} and @var{end-addr}, only @var{lines} lines are
17648displayed; if @var{lines} is higher than the number of lines between
17649@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
17650are displayed.
17651@item @var{mode}
17652is either 0 (meaning only disassembly) or 1 (meaning mixed source and
17653disassembly).
17654@end table
17655
17656@subsubheading Result
17657
17658The output for each instruction is composed of four fields:
17659
17660@itemize @bullet
17661@item Address
17662@item Func-name
17663@item Offset
17664@item Instruction
17665@end itemize
17666
17667Note that whatever included in the instruction field, is not manipulated
17668directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
17669
17670@subsubheading @value{GDBN} Command
17671
17672There's no direct mapping from this command to the CLI.
17673
17674@subsubheading Example
17675
17676Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
17677
17678@smallexample
17679(@value{GDBP})
17680-data-disassemble -s $pc -e "$pc + 20" -- 0
17681^done,
17682asm_insns=[
17683@{address="0x000107c0",func-name="main",offset="4",
17684inst="mov 2, %o0"@},
17685@{address="0x000107c4",func-name="main",offset="8",
17686inst="sethi %hi(0x11800), %o2"@},
17687@{address="0x000107c8",func-name="main",offset="12",
17688inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
17689@{address="0x000107cc",func-name="main",offset="16",
17690inst="sethi %hi(0x11800), %o2"@},
17691@{address="0x000107d0",func-name="main",offset="20",
17692inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
17693(@value{GDBP})
17694@end smallexample
17695
17696Disassemble the whole @code{main} function. Line 32 is part of
17697@code{main}.
17698
17699@smallexample
17700-data-disassemble -f basics.c -l 32 -- 0
17701^done,asm_insns=[
17702@{address="0x000107bc",func-name="main",offset="0",
17703inst="save %sp, -112, %sp"@},
17704@{address="0x000107c0",func-name="main",offset="4",
17705inst="mov 2, %o0"@},
17706@{address="0x000107c4",func-name="main",offset="8",
17707inst="sethi %hi(0x11800), %o2"@},
17708[@dots{}]
17709@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
17710@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
17711(@value{GDBP})
17712@end smallexample
17713
17714Disassemble 3 instructions from the start of @code{main}:
17715
17716@smallexample
17717(@value{GDBP})
17718-data-disassemble -f basics.c -l 32 -n 3 -- 0
17719^done,asm_insns=[
17720@{address="0x000107bc",func-name="main",offset="0",
17721inst="save %sp, -112, %sp"@},
17722@{address="0x000107c0",func-name="main",offset="4",
17723inst="mov 2, %o0"@},
17724@{address="0x000107c4",func-name="main",offset="8",
17725inst="sethi %hi(0x11800), %o2"@}]
17726(@value{GDBP})
17727@end smallexample
17728
17729Disassemble 3 instructions from the start of @code{main} in mixed mode:
17730
17731@smallexample
17732(@value{GDBP})
17733-data-disassemble -f basics.c -l 32 -n 3 -- 1
17734^done,asm_insns=[
17735src_and_asm_line=@{line="31",
17736file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17737 testsuite/gdb.mi/basics.c",line_asm_insn=[
17738@{address="0x000107bc",func-name="main",offset="0",
17739inst="save %sp, -112, %sp"@}]@},
17740src_and_asm_line=@{line="32",
17741file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17742 testsuite/gdb.mi/basics.c",line_asm_insn=[
17743@{address="0x000107c0",func-name="main",offset="4",
17744inst="mov 2, %o0"@},
17745@{address="0x000107c4",func-name="main",offset="8",
17746inst="sethi %hi(0x11800), %o2"@}]@}]
17747(@value{GDBP})
17748@end smallexample
17749
17750
17751@subheading The @code{-data-evaluate-expression} Command
17752@findex -data-evaluate-expression
17753
17754@subsubheading Synopsis
17755
17756@smallexample
17757 -data-evaluate-expression @var{expr}
17758@end smallexample
17759
17760Evaluate @var{expr} as an expression. The expression could contain an
17761inferior function call. The function call will execute synchronously.
17762If the expression contains spaces, it must be enclosed in double quotes.
17763
17764@subsubheading @value{GDBN} Command
17765
17766The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
17767@samp{call}. In @code{gdbtk} only, there's a corresponding
17768@samp{gdb_eval} command.
17769
17770@subsubheading Example
17771
17772In the following example, the numbers that precede the commands are the
17773@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
17774Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
17775output.
17776
17777@smallexample
17778211-data-evaluate-expression A
17779211^done,value="1"
17780(@value{GDBP})
17781311-data-evaluate-expression &A
17782311^done,value="0xefffeb7c"
17783(@value{GDBP})
17784411-data-evaluate-expression A+3
17785411^done,value="4"
17786(@value{GDBP})
17787511-data-evaluate-expression "A + 3"
17788511^done,value="4"
17789(@value{GDBP})
17790@end smallexample
17791
17792
17793@subheading The @code{-data-list-changed-registers} Command
17794@findex -data-list-changed-registers
17795
17796@subsubheading Synopsis
17797
17798@smallexample
17799 -data-list-changed-registers
17800@end smallexample
17801
17802Display a list of the registers that have changed.
17803
17804@subsubheading @value{GDBN} Command
17805
17806@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
17807has the corresponding command @samp{gdb_changed_register_list}.
17808
17809@subsubheading Example
17810
17811On a PPC MBX board:
17812
17813@smallexample
17814(@value{GDBP})
17815-exec-continue
17816^running
17817
17818(@value{GDBP})
17819*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
76ff342d 17820args=[],file="try.c",fullname="/home/foo/bar/devo/myproject/try.c",line="5"@}
922fbb7b
AC
17821(@value{GDBP})
17822-data-list-changed-registers
17823^done,changed-registers=["0","1","2","4","5","6","7","8","9",
17824"10","11","13","14","15","16","17","18","19","20","21","22","23",
17825"24","25","26","27","28","30","31","64","65","66","67","69"]
17826(@value{GDBP})
17827@end smallexample
17828
17829
17830@subheading The @code{-data-list-register-names} Command
17831@findex -data-list-register-names
17832
17833@subsubheading Synopsis
17834
17835@smallexample
17836 -data-list-register-names [ ( @var{regno} )+ ]
17837@end smallexample
17838
17839Show a list of register names for the current target. If no arguments
17840are given, it shows a list of the names of all the registers. If
17841integer numbers are given as arguments, it will print a list of the
17842names of the registers corresponding to the arguments. To ensure
17843consistency between a register name and its number, the output list may
17844include empty register names.
17845
17846@subsubheading @value{GDBN} Command
17847
17848@value{GDBN} does not have a command which corresponds to
17849@samp{-data-list-register-names}. In @code{gdbtk} there is a
17850corresponding command @samp{gdb_regnames}.
17851
17852@subsubheading Example
17853
17854For the PPC MBX board:
17855@smallexample
17856(@value{GDBP})
17857-data-list-register-names
17858^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
17859"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
17860"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
17861"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
17862"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
17863"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
17864"", "pc","ps","cr","lr","ctr","xer"]
17865(@value{GDBP})
17866-data-list-register-names 1 2 3
17867^done,register-names=["r1","r2","r3"]
17868(@value{GDBP})
17869@end smallexample
17870
17871@subheading The @code{-data-list-register-values} Command
17872@findex -data-list-register-values
17873
17874@subsubheading Synopsis
17875
17876@smallexample
17877 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
17878@end smallexample
17879
17880Display the registers' contents. @var{fmt} is the format according to
17881which the registers' contents are to be returned, followed by an optional
17882list of numbers specifying the registers to display. A missing list of
17883numbers indicates that the contents of all the registers must be returned.
17884
17885Allowed formats for @var{fmt} are:
17886
17887@table @code
17888@item x
17889Hexadecimal
17890@item o
17891Octal
17892@item t
17893Binary
17894@item d
17895Decimal
17896@item r
17897Raw
17898@item N
17899Natural
17900@end table
17901
17902@subsubheading @value{GDBN} Command
17903
17904The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
17905all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
17906
17907@subsubheading Example
17908
17909For a PPC MBX board (note: line breaks are for readability only, they
17910don't appear in the actual output):
17911
17912@smallexample
17913(@value{GDBP})
17914-data-list-register-values r 64 65
17915^done,register-values=[@{number="64",value="0xfe00a300"@},
17916@{number="65",value="0x00029002"@}]
17917(@value{GDBP})
17918-data-list-register-values x
17919^done,register-values=[@{number="0",value="0xfe0043c8"@},
17920@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
17921@{number="3",value="0x0"@},@{number="4",value="0xa"@},
17922@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
17923@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
17924@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
17925@{number="11",value="0x1"@},@{number="12",value="0x0"@},
17926@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
17927@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
17928@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
17929@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
17930@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
17931@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
17932@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
17933@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
17934@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
17935@{number="31",value="0x0"@},@{number="32",value="0x0"@},
17936@{number="33",value="0x0"@},@{number="34",value="0x0"@},
17937@{number="35",value="0x0"@},@{number="36",value="0x0"@},
17938@{number="37",value="0x0"@},@{number="38",value="0x0"@},
17939@{number="39",value="0x0"@},@{number="40",value="0x0"@},
17940@{number="41",value="0x0"@},@{number="42",value="0x0"@},
17941@{number="43",value="0x0"@},@{number="44",value="0x0"@},
17942@{number="45",value="0x0"@},@{number="46",value="0x0"@},
17943@{number="47",value="0x0"@},@{number="48",value="0x0"@},
17944@{number="49",value="0x0"@},@{number="50",value="0x0"@},
17945@{number="51",value="0x0"@},@{number="52",value="0x0"@},
17946@{number="53",value="0x0"@},@{number="54",value="0x0"@},
17947@{number="55",value="0x0"@},@{number="56",value="0x0"@},
17948@{number="57",value="0x0"@},@{number="58",value="0x0"@},
17949@{number="59",value="0x0"@},@{number="60",value="0x0"@},
17950@{number="61",value="0x0"@},@{number="62",value="0x0"@},
17951@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
17952@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
17953@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
17954@{number="69",value="0x20002b03"@}]
17955(@value{GDBP})
17956@end smallexample
17957
17958
17959@subheading The @code{-data-read-memory} Command
17960@findex -data-read-memory
17961
17962@subsubheading Synopsis
17963
17964@smallexample
17965 -data-read-memory [ -o @var{byte-offset} ]
17966 @var{address} @var{word-format} @var{word-size}
17967 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
17968@end smallexample
17969
17970@noindent
17971where:
17972
17973@table @samp
17974@item @var{address}
17975An expression specifying the address of the first memory word to be
17976read. Complex expressions containing embedded white space should be
17977quoted using the C convention.
17978
17979@item @var{word-format}
17980The format to be used to print the memory words. The notation is the
17981same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
17982,Output formats}).
17983
17984@item @var{word-size}
17985The size of each memory word in bytes.
17986
17987@item @var{nr-rows}
17988The number of rows in the output table.
17989
17990@item @var{nr-cols}
17991The number of columns in the output table.
17992
17993@item @var{aschar}
17994If present, indicates that each row should include an @sc{ascii} dump. The
17995value of @var{aschar} is used as a padding character when a byte is not a
17996member of the printable @sc{ascii} character set (printable @sc{ascii}
17997characters are those whose code is between 32 and 126, inclusively).
17998
17999@item @var{byte-offset}
18000An offset to add to the @var{address} before fetching memory.
18001@end table
18002
18003This command displays memory contents as a table of @var{nr-rows} by
18004@var{nr-cols} words, each word being @var{word-size} bytes. In total,
18005@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
18006(returned as @samp{total-bytes}). Should less than the requested number
18007of bytes be returned by the target, the missing words are identified
18008using @samp{N/A}. The number of bytes read from the target is returned
18009in @samp{nr-bytes} and the starting address used to read memory in
18010@samp{addr}.
18011
18012The address of the next/previous row or page is available in
18013@samp{next-row} and @samp{prev-row}, @samp{next-page} and
18014@samp{prev-page}.
18015
18016@subsubheading @value{GDBN} Command
18017
18018The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
18019@samp{gdb_get_mem} memory read command.
18020
18021@subsubheading Example
18022
18023Read six bytes of memory starting at @code{bytes+6} but then offset by
18024@code{-6} bytes. Format as three rows of two columns. One byte per
18025word. Display each word in hex.
18026
18027@smallexample
18028(@value{GDBP})
180299-data-read-memory -o -6 -- bytes+6 x 1 3 2
180309^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
18031next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
18032prev-page="0x0000138a",memory=[
18033@{addr="0x00001390",data=["0x00","0x01"]@},
18034@{addr="0x00001392",data=["0x02","0x03"]@},
18035@{addr="0x00001394",data=["0x04","0x05"]@}]
18036(@value{GDBP})
18037@end smallexample
18038
18039Read two bytes of memory starting at address @code{shorts + 64} and
18040display as a single word formatted in decimal.
18041
18042@smallexample
18043(@value{GDBP})
180445-data-read-memory shorts+64 d 2 1 1
180455^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
18046next-row="0x00001512",prev-row="0x0000150e",
18047next-page="0x00001512",prev-page="0x0000150e",memory=[
18048@{addr="0x00001510",data=["128"]@}]
18049(@value{GDBP})
18050@end smallexample
18051
18052Read thirty two bytes of memory starting at @code{bytes+16} and format
18053as eight rows of four columns. Include a string encoding with @samp{x}
18054used as the non-printable character.
18055
18056@smallexample
18057(@value{GDBP})
180584-data-read-memory bytes+16 x 1 8 4 x
180594^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
18060next-row="0x000013c0",prev-row="0x0000139c",
18061next-page="0x000013c0",prev-page="0x00001380",memory=[
18062@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
18063@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
18064@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
18065@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
18066@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
18067@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
18068@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
18069@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
18070(@value{GDBP})
18071@end smallexample
18072
18073@subheading The @code{-display-delete} Command
18074@findex -display-delete
18075
18076@subsubheading Synopsis
18077
18078@smallexample
18079 -display-delete @var{number}
18080@end smallexample
18081
18082Delete the display @var{number}.
18083
18084@subsubheading @value{GDBN} Command
18085
18086The corresponding @value{GDBN} command is @samp{delete display}.
18087
18088@subsubheading Example
18089N.A.
18090
18091
18092@subheading The @code{-display-disable} Command
18093@findex -display-disable
18094
18095@subsubheading Synopsis
18096
18097@smallexample
18098 -display-disable @var{number}
18099@end smallexample
18100
18101Disable display @var{number}.
18102
18103@subsubheading @value{GDBN} Command
18104
18105The corresponding @value{GDBN} command is @samp{disable display}.
18106
18107@subsubheading Example
18108N.A.
18109
18110
18111@subheading The @code{-display-enable} Command
18112@findex -display-enable
18113
18114@subsubheading Synopsis
18115
18116@smallexample
18117 -display-enable @var{number}
18118@end smallexample
18119
18120Enable display @var{number}.
18121
18122@subsubheading @value{GDBN} Command
18123
18124The corresponding @value{GDBN} command is @samp{enable display}.
18125
18126@subsubheading Example
18127N.A.
18128
18129
18130@subheading The @code{-display-insert} Command
18131@findex -display-insert
18132
18133@subsubheading Synopsis
18134
18135@smallexample
18136 -display-insert @var{expression}
18137@end smallexample
18138
18139Display @var{expression} every time the program stops.
18140
18141@subsubheading @value{GDBN} Command
18142
18143The corresponding @value{GDBN} command is @samp{display}.
18144
18145@subsubheading Example
18146N.A.
18147
18148
18149@subheading The @code{-display-list} Command
18150@findex -display-list
18151
18152@subsubheading Synopsis
18153
18154@smallexample
18155 -display-list
18156@end smallexample
18157
18158List the displays. Do not show the current values.
18159
18160@subsubheading @value{GDBN} Command
18161
18162The corresponding @value{GDBN} command is @samp{info display}.
18163
18164@subsubheading Example
18165N.A.
18166
18167
18168@subheading The @code{-environment-cd} Command
18169@findex -environment-cd
18170
18171@subsubheading Synopsis
18172
18173@smallexample
18174 -environment-cd @var{pathdir}
18175@end smallexample
18176
18177Set @value{GDBN}'s working directory.
18178
18179@subsubheading @value{GDBN} Command
18180
18181The corresponding @value{GDBN} command is @samp{cd}.
18182
18183@subsubheading Example
18184
18185@smallexample
18186(@value{GDBP})
18187-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18188^done
18189(@value{GDBP})
18190@end smallexample
18191
18192
18193@subheading The @code{-environment-directory} Command
18194@findex -environment-directory
18195
18196@subsubheading Synopsis
18197
18198@smallexample
18199 -environment-directory [ -r ] [ @var{pathdir} ]+
18200@end smallexample
18201
18202Add directories @var{pathdir} to beginning of search path for source files.
18203If the @samp{-r} option is used, the search path is reset to the default
b383017d 18204search path. If directories @var{pathdir} are supplied in addition to the
922fbb7b
AC
18205@samp{-r} option, the search path is first reset and then addition
18206occurs as normal.
b383017d 18207Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18208multiple directories in a single command
18209results in the directories added to the beginning of the
18210search path in the same order they were presented in the command.
18211If blanks are needed as
18212part of a directory name, double-quotes should be used around
18213the name. In the command output, the path will show up separated
b383017d 18214by the system directory-separator character. The directory-seperator
922fbb7b
AC
18215character must not be used
18216in any directory name.
18217If no directories are specified, the current search path is displayed.
18218
18219@subsubheading @value{GDBN} Command
18220
18221The corresponding @value{GDBN} command is @samp{dir}.
18222
18223@subsubheading Example
18224
18225@smallexample
18226(@value{GDBP})
18227-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18228^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18229(@value{GDBP})
18230-environment-directory ""
18231^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18232(@value{GDBP})
18233-environment-directory -r /home/jjohnstn/src/gdb /usr/src
18234^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
18235(@value{GDBP})
18236-environment-directory -r
18237^done,source-path="$cdir:$cwd"
18238(@value{GDBP})
18239@end smallexample
18240
18241
18242@subheading The @code{-environment-path} Command
18243@findex -environment-path
18244
18245@subsubheading Synopsis
18246
18247@smallexample
18248 -environment-path [ -r ] [ @var{pathdir} ]+
18249@end smallexample
18250
18251Add directories @var{pathdir} to beginning of search path for object files.
18252If the @samp{-r} option is used, the search path is reset to the original
b383017d
RM
18253search path that existed at gdb start-up. If directories @var{pathdir} are
18254supplied in addition to the
922fbb7b
AC
18255@samp{-r} option, the search path is first reset and then addition
18256occurs as normal.
b383017d 18257Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18258multiple directories in a single command
18259results in the directories added to the beginning of the
18260search path in the same order they were presented in the command.
18261If blanks are needed as
18262part of a directory name, double-quotes should be used around
18263the name. In the command output, the path will show up separated
b383017d 18264by the system directory-separator character. The directory-seperator
922fbb7b
AC
18265character must not be used
18266in any directory name.
18267If no directories are specified, the current path is displayed.
18268
18269
18270@subsubheading @value{GDBN} Command
18271
18272The corresponding @value{GDBN} command is @samp{path}.
18273
18274@subsubheading Example
18275
18276@smallexample
18277(@value{GDBP})
b383017d 18278-environment-path
922fbb7b
AC
18279^done,path="/usr/bin"
18280(@value{GDBP})
18281-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
18282^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
18283(@value{GDBP})
18284-environment-path -r /usr/local/bin
18285^done,path="/usr/local/bin:/usr/bin"
18286(@value{GDBP})
18287@end smallexample
18288
18289
18290@subheading The @code{-environment-pwd} Command
18291@findex -environment-pwd
18292
18293@subsubheading Synopsis
18294
18295@smallexample
18296 -environment-pwd
18297@end smallexample
18298
18299Show the current working directory.
18300
18301@subsubheading @value{GDBN} command
18302
18303The corresponding @value{GDBN} command is @samp{pwd}.
18304
18305@subsubheading Example
18306
18307@smallexample
18308(@value{GDBP})
18309-environment-pwd
18310^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
18311(@value{GDBP})
18312@end smallexample
18313
18314@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18315@node GDB/MI Program Control
18316@section @sc{gdb/mi} Program control
18317
18318@subsubheading Program termination
18319
18320As a result of execution, the inferior program can run to completion, if
18321it doesn't encounter any breakpoints. In this case the output will
18322include an exit code, if the program has exited exceptionally.
18323
18324@subsubheading Examples
18325
18326@noindent
18327Program exited normally:
18328
18329@smallexample
18330(@value{GDBP})
18331-exec-run
18332^running
18333(@value{GDBP})
18334x = 55
18335*stopped,reason="exited-normally"
18336(@value{GDBP})
18337@end smallexample
18338
18339@noindent
18340Program exited exceptionally:
18341
18342@smallexample
18343(@value{GDBP})
18344-exec-run
18345^running
18346(@value{GDBP})
18347x = 55
18348*stopped,reason="exited",exit-code="01"
18349(@value{GDBP})
18350@end smallexample
18351
18352Another way the program can terminate is if it receives a signal such as
18353@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
18354
18355@smallexample
18356(@value{GDBP})
18357*stopped,reason="exited-signalled",signal-name="SIGINT",
18358signal-meaning="Interrupt"
18359@end smallexample
18360
18361
18362@subheading The @code{-exec-abort} Command
18363@findex -exec-abort
18364
18365@subsubheading Synopsis
18366
18367@smallexample
18368 -exec-abort
18369@end smallexample
18370
18371Kill the inferior running program.
18372
18373@subsubheading @value{GDBN} Command
18374
18375The corresponding @value{GDBN} command is @samp{kill}.
18376
18377@subsubheading Example
18378N.A.
18379
18380
18381@subheading The @code{-exec-arguments} Command
18382@findex -exec-arguments
18383
18384@subsubheading Synopsis
18385
18386@smallexample
18387 -exec-arguments @var{args}
18388@end smallexample
18389
18390Set the inferior program arguments, to be used in the next
18391@samp{-exec-run}.
18392
18393@subsubheading @value{GDBN} Command
18394
18395The corresponding @value{GDBN} command is @samp{set args}.
18396
18397@subsubheading Example
18398
18399@c FIXME!
18400Don't have one around.
18401
18402
18403@subheading The @code{-exec-continue} Command
18404@findex -exec-continue
18405
18406@subsubheading Synopsis
18407
18408@smallexample
18409 -exec-continue
18410@end smallexample
18411
18412Asynchronous command. Resumes the execution of the inferior program
18413until a breakpoint is encountered, or until the inferior exits.
18414
18415@subsubheading @value{GDBN} Command
18416
18417The corresponding @value{GDBN} corresponding is @samp{continue}.
18418
18419@subsubheading Example
18420
18421@smallexample
18422-exec-continue
18423^running
18424(@value{GDBP})
18425@@Hello world
18426*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
76ff342d 18427file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="13"@}
922fbb7b
AC
18428(@value{GDBP})
18429@end smallexample
18430
18431
18432@subheading The @code{-exec-finish} Command
18433@findex -exec-finish
18434
18435@subsubheading Synopsis
18436
18437@smallexample
18438 -exec-finish
18439@end smallexample
18440
18441Asynchronous command. Resumes the execution of the inferior program
18442until the current function is exited. Displays the results returned by
18443the function.
18444
18445@subsubheading @value{GDBN} Command
18446
18447The corresponding @value{GDBN} command is @samp{finish}.
18448
18449@subsubheading Example
18450
18451Function returning @code{void}.
18452
18453@smallexample
18454-exec-finish
18455^running
18456(@value{GDBP})
18457@@hello from foo
18458*stopped,reason="function-finished",frame=@{func="main",args=[],
76ff342d 18459file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="7"@}
922fbb7b
AC
18460(@value{GDBP})
18461@end smallexample
18462
18463Function returning other than @code{void}. The name of the internal
18464@value{GDBN} variable storing the result is printed, together with the
18465value itself.
18466
18467@smallexample
18468-exec-finish
18469^running
18470(@value{GDBP})
18471*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
18472args=[@{name="a",value="1"],@{name="b",value="9"@}@},
76ff342d 18473file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b
AC
18474gdb-result-var="$1",return-value="0"
18475(@value{GDBP})
18476@end smallexample
18477
18478
18479@subheading The @code{-exec-interrupt} Command
18480@findex -exec-interrupt
18481
18482@subsubheading Synopsis
18483
18484@smallexample
18485 -exec-interrupt
18486@end smallexample
18487
18488Asynchronous command. Interrupts the background execution of the target.
18489Note how the token associated with the stop message is the one for the
18490execution command that has been interrupted. The token for the interrupt
18491itself only appears in the @samp{^done} output. If the user is trying to
18492interrupt a non-running program, an error message will be printed.
18493
18494@subsubheading @value{GDBN} Command
18495
18496The corresponding @value{GDBN} command is @samp{interrupt}.
18497
18498@subsubheading Example
18499
18500@smallexample
18501(@value{GDBP})
18502111-exec-continue
18503111^running
18504
18505(@value{GDBP})
18506222-exec-interrupt
18507222^done
18508(@value{GDBP})
18509111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d
DJ
18510frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
18511fullname="/home/foo/bar/devo/myproject/try.c",line="13"@}
922fbb7b
AC
18512(@value{GDBP})
18513
18514(@value{GDBP})
18515-exec-interrupt
18516^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
18517(@value{GDBP})
18518@end smallexample
18519
18520
18521@subheading The @code{-exec-next} Command
18522@findex -exec-next
18523
18524@subsubheading Synopsis
18525
18526@smallexample
18527 -exec-next
18528@end smallexample
18529
18530Asynchronous command. Resumes execution of the inferior program, stopping
18531when the beginning of the next source line is reached.
18532
18533@subsubheading @value{GDBN} Command
18534
18535The corresponding @value{GDBN} command is @samp{next}.
18536
18537@subsubheading Example
18538
18539@smallexample
18540-exec-next
18541^running
18542(@value{GDBP})
18543*stopped,reason="end-stepping-range",line="8",file="hello.c"
18544(@value{GDBP})
18545@end smallexample
18546
18547
18548@subheading The @code{-exec-next-instruction} Command
18549@findex -exec-next-instruction
18550
18551@subsubheading Synopsis
18552
18553@smallexample
18554 -exec-next-instruction
18555@end smallexample
18556
18557Asynchronous command. Executes one machine instruction. If the
18558instruction is a function call continues until the function returns. If
18559the program stops at an instruction in the middle of a source line, the
18560address will be printed as well.
18561
18562@subsubheading @value{GDBN} Command
18563
18564The corresponding @value{GDBN} command is @samp{nexti}.
18565
18566@subsubheading Example
18567
18568@smallexample
18569(@value{GDBP})
18570-exec-next-instruction
18571^running
18572
18573(@value{GDBP})
18574*stopped,reason="end-stepping-range",
18575addr="0x000100d4",line="5",file="hello.c"
18576(@value{GDBP})
18577@end smallexample
18578
18579
18580@subheading The @code{-exec-return} Command
18581@findex -exec-return
18582
18583@subsubheading Synopsis
18584
18585@smallexample
18586 -exec-return
18587@end smallexample
18588
18589Makes current function return immediately. Doesn't execute the inferior.
18590Displays the new current frame.
18591
18592@subsubheading @value{GDBN} Command
18593
18594The corresponding @value{GDBN} command is @samp{return}.
18595
18596@subsubheading Example
18597
18598@smallexample
18599(@value{GDBP})
18600200-break-insert callee4
18601200^done,bkpt=@{number="1",addr="0x00010734",
18602file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
18603(@value{GDBP})
18604000-exec-run
18605000^running
18606(@value{GDBP})
18607000*stopped,reason="breakpoint-hit",bkptno="1",
18608frame=@{func="callee4",args=[],
76ff342d
DJ
18609file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18610fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
922fbb7b
AC
18611(@value{GDBP})
18612205-break-delete
18613205^done
18614(@value{GDBP})
18615111-exec-return
18616111^done,frame=@{level="0",func="callee3",
18617args=[@{name="strarg",
18618value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
18619file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18620fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
18621(@value{GDBP})
18622@end smallexample
18623
18624
18625@subheading The @code{-exec-run} Command
18626@findex -exec-run
18627
18628@subsubheading Synopsis
18629
18630@smallexample
18631 -exec-run
18632@end smallexample
18633
18634Asynchronous command. Starts execution of the inferior from the
18635beginning. The inferior executes until either a breakpoint is
18636encountered or the program exits.
18637
18638@subsubheading @value{GDBN} Command
18639
18640The corresponding @value{GDBN} command is @samp{run}.
18641
18642@subsubheading Example
18643
18644@smallexample
18645(@value{GDBP})
18646-break-insert main
18647^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
18648(@value{GDBP})
18649-exec-run
18650^running
18651(@value{GDBP})
18652*stopped,reason="breakpoint-hit",bkptno="1",
76ff342d
DJ
18653frame=@{func="main",args=[],file="recursive2.c",
18654fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}
922fbb7b
AC
18655(@value{GDBP})
18656@end smallexample
18657
18658
18659@subheading The @code{-exec-show-arguments} Command
18660@findex -exec-show-arguments
18661
18662@subsubheading Synopsis
18663
18664@smallexample
18665 -exec-show-arguments
18666@end smallexample
18667
18668Print the arguments of the program.
18669
18670@subsubheading @value{GDBN} Command
18671
18672The corresponding @value{GDBN} command is @samp{show args}.
18673
18674@subsubheading Example
18675N.A.
18676
18677@c @subheading -exec-signal
18678
18679@subheading The @code{-exec-step} Command
18680@findex -exec-step
18681
18682@subsubheading Synopsis
18683
18684@smallexample
18685 -exec-step
18686@end smallexample
18687
18688Asynchronous command. Resumes execution of the inferior program, stopping
18689when the beginning of the next source line is reached, if the next
18690source line is not a function call. If it is, stop at the first
18691instruction of the called function.
18692
18693@subsubheading @value{GDBN} Command
18694
18695The corresponding @value{GDBN} command is @samp{step}.
18696
18697@subsubheading Example
18698
18699Stepping into a function:
18700
18701@smallexample
18702-exec-step
18703^running
18704(@value{GDBP})
18705*stopped,reason="end-stepping-range",
18706frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d
DJ
18707@{name="b",value="0"@}],file="recursive2.c",
18708fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@}
922fbb7b
AC
18709(@value{GDBP})
18710@end smallexample
18711
18712Regular stepping:
18713
18714@smallexample
18715-exec-step
18716^running
18717(@value{GDBP})
18718*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
18719(@value{GDBP})
18720@end smallexample
18721
18722
18723@subheading The @code{-exec-step-instruction} Command
18724@findex -exec-step-instruction
18725
18726@subsubheading Synopsis
18727
18728@smallexample
18729 -exec-step-instruction
18730@end smallexample
18731
18732Asynchronous command. Resumes the inferior which executes one machine
18733instruction. The output, once @value{GDBN} has stopped, will vary depending on
18734whether we have stopped in the middle of a source line or not. In the
18735former case, the address at which the program stopped will be printed as
18736well.
18737
18738@subsubheading @value{GDBN} Command
18739
18740The corresponding @value{GDBN} command is @samp{stepi}.
18741
18742@subsubheading Example
18743
18744@smallexample
18745(@value{GDBP})
18746-exec-step-instruction
18747^running
18748
18749(@value{GDBP})
18750*stopped,reason="end-stepping-range",
76ff342d
DJ
18751frame=@{func="foo",args=[],file="try.c",
18752fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18753(@value{GDBP})
18754-exec-step-instruction
18755^running
18756
18757(@value{GDBP})
18758*stopped,reason="end-stepping-range",
76ff342d
DJ
18759frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
18760fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18761(@value{GDBP})
18762@end smallexample
18763
18764
18765@subheading The @code{-exec-until} Command
18766@findex -exec-until
18767
18768@subsubheading Synopsis
18769
18770@smallexample
18771 -exec-until [ @var{location} ]
18772@end smallexample
18773
18774Asynchronous command. Executes the inferior until the @var{location}
18775specified in the argument is reached. If there is no argument, the inferior
18776executes until a source line greater than the current one is reached.
18777The reason for stopping in this case will be @samp{location-reached}.
18778
18779@subsubheading @value{GDBN} Command
18780
18781The corresponding @value{GDBN} command is @samp{until}.
18782
18783@subsubheading Example
18784
18785@smallexample
18786(@value{GDBP})
18787-exec-until recursive2.c:6
18788^running
18789(@value{GDBP})
18790x = 55
18791*stopped,reason="location-reached",frame=@{func="main",args=[],
76ff342d 18792file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="6"@}
922fbb7b
AC
18793(@value{GDBP})
18794@end smallexample
18795
18796@ignore
18797@subheading -file-clear
18798Is this going away????
18799@end ignore
18800
18801
18802@subheading The @code{-file-exec-and-symbols} Command
18803@findex -file-exec-and-symbols
18804
18805@subsubheading Synopsis
18806
18807@smallexample
18808 -file-exec-and-symbols @var{file}
18809@end smallexample
18810
18811Specify the executable file to be debugged. This file is the one from
18812which the symbol table is also read. If no file is specified, the
18813command clears the executable and symbol information. If breakpoints
18814are set when using this command with no arguments, @value{GDBN} will produce
18815error messages. Otherwise, no output is produced, except a completion
18816notification.
18817
18818@subsubheading @value{GDBN} Command
18819
18820The corresponding @value{GDBN} command is @samp{file}.
18821
18822@subsubheading Example
18823
18824@smallexample
18825(@value{GDBP})
18826-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18827^done
18828(@value{GDBP})
18829@end smallexample
18830
18831
18832@subheading The @code{-file-exec-file} Command
18833@findex -file-exec-file
18834
18835@subsubheading Synopsis
18836
18837@smallexample
18838 -file-exec-file @var{file}
18839@end smallexample
18840
18841Specify the executable file to be debugged. Unlike
18842@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
18843from this file. If used without argument, @value{GDBN} clears the information
18844about the executable file. No output is produced, except a completion
18845notification.
18846
18847@subsubheading @value{GDBN} Command
18848
18849The corresponding @value{GDBN} command is @samp{exec-file}.
18850
18851@subsubheading Example
18852
18853@smallexample
18854(@value{GDBP})
18855-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18856^done
18857(@value{GDBP})
18858@end smallexample
18859
18860
18861@subheading The @code{-file-list-exec-sections} Command
18862@findex -file-list-exec-sections
18863
18864@subsubheading Synopsis
18865
18866@smallexample
18867 -file-list-exec-sections
18868@end smallexample
18869
18870List the sections of the current executable file.
18871
18872@subsubheading @value{GDBN} Command
18873
18874The @value{GDBN} command @samp{info file} shows, among the rest, the same
18875information as this command. @code{gdbtk} has a corresponding command
18876@samp{gdb_load_info}.
18877
18878@subsubheading Example
18879N.A.
18880
18881
1abaf70c
BR
18882@subheading The @code{-file-list-exec-source-file} Command
18883@findex -file-list-exec-source-file
18884
18885@subsubheading Synopsis
18886
18887@smallexample
18888 -file-list-exec-source-file
18889@end smallexample
18890
b383017d 18891List the line number, the current source file, and the absolute path
1abaf70c
BR
18892to the current source file for the current executable.
18893
18894@subsubheading @value{GDBN} Command
18895
18896There's no @value{GDBN} command which directly corresponds to this one.
18897
18898@subsubheading Example
18899
18900@smallexample
18901(@value{GDBP})
18902123-file-list-exec-source-file
18903123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
18904(@value{GDBP})
18905@end smallexample
18906
18907
922fbb7b
AC
18908@subheading The @code{-file-list-exec-source-files} Command
18909@findex -file-list-exec-source-files
18910
18911@subsubheading Synopsis
18912
18913@smallexample
18914 -file-list-exec-source-files
18915@end smallexample
18916
18917List the source files for the current executable.
18918
57c22c6c
BR
18919It will always output the filename, but only when GDB can find the absolute
18920file name of a source file, will it output the fullname.
18921
922fbb7b
AC
18922@subsubheading @value{GDBN} Command
18923
18924There's no @value{GDBN} command which directly corresponds to this one.
18925@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
18926
18927@subsubheading Example
57c22c6c
BR
18928@smallexample
18929(@value{GDBP})
18930-file-list-exec-source-files
18931^done,files=[
18932@{file=foo.c,fullname=/home/foo.c@},
18933@{file=/home/bar.c,fullname=/home/bar.c@},
18934@{file=gdb_could_not_find_fullpath.c@}]
18935(@value{GDBP})
18936@end smallexample
922fbb7b
AC
18937
18938@subheading The @code{-file-list-shared-libraries} Command
18939@findex -file-list-shared-libraries
18940
18941@subsubheading Synopsis
18942
18943@smallexample
18944 -file-list-shared-libraries
18945@end smallexample
18946
18947List the shared libraries in the program.
18948
18949@subsubheading @value{GDBN} Command
18950
18951The corresponding @value{GDBN} command is @samp{info shared}.
18952
18953@subsubheading Example
18954N.A.
18955
18956
18957@subheading The @code{-file-list-symbol-files} Command
18958@findex -file-list-symbol-files
18959
18960@subsubheading Synopsis
18961
18962@smallexample
18963 -file-list-symbol-files
18964@end smallexample
18965
18966List symbol files.
18967
18968@subsubheading @value{GDBN} Command
18969
18970The corresponding @value{GDBN} command is @samp{info file} (part of it).
18971
18972@subsubheading Example
18973N.A.
18974
18975
18976@subheading The @code{-file-symbol-file} Command
18977@findex -file-symbol-file
18978
18979@subsubheading Synopsis
18980
18981@smallexample
18982 -file-symbol-file @var{file}
18983@end smallexample
18984
18985Read symbol table info from the specified @var{file} argument. When
18986used without arguments, clears @value{GDBN}'s symbol table info. No output is
18987produced, except for a completion notification.
18988
18989@subsubheading @value{GDBN} Command
18990
18991The corresponding @value{GDBN} command is @samp{symbol-file}.
18992
18993@subsubheading Example
18994
18995@smallexample
18996(@value{GDBP})
18997-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18998^done
18999(@value{GDBP})
19000@end smallexample
19001
19002@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19003@node GDB/MI Miscellaneous Commands
19004@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
19005
19006@c @subheading -gdb-complete
19007
19008@subheading The @code{-gdb-exit} Command
19009@findex -gdb-exit
19010
19011@subsubheading Synopsis
19012
19013@smallexample
19014 -gdb-exit
19015@end smallexample
19016
19017Exit @value{GDBN} immediately.
19018
19019@subsubheading @value{GDBN} Command
19020
19021Approximately corresponds to @samp{quit}.
19022
19023@subsubheading Example
19024
19025@smallexample
19026(@value{GDBP})
19027-gdb-exit
19028@end smallexample
19029
19030@subheading The @code{-gdb-set} Command
19031@findex -gdb-set
19032
19033@subsubheading Synopsis
19034
19035@smallexample
19036 -gdb-set
19037@end smallexample
19038
19039Set an internal @value{GDBN} variable.
19040@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
19041
19042@subsubheading @value{GDBN} Command
19043
19044The corresponding @value{GDBN} command is @samp{set}.
19045
19046@subsubheading Example
19047
19048@smallexample
19049(@value{GDBP})
19050-gdb-set $foo=3
19051^done
19052(@value{GDBP})
19053@end smallexample
19054
19055
19056@subheading The @code{-gdb-show} Command
19057@findex -gdb-show
19058
19059@subsubheading Synopsis
19060
19061@smallexample
19062 -gdb-show
19063@end smallexample
19064
19065Show the current value of a @value{GDBN} variable.
19066
19067@subsubheading @value{GDBN} command
19068
19069The corresponding @value{GDBN} command is @samp{show}.
19070
19071@subsubheading Example
19072
19073@smallexample
19074(@value{GDBP})
19075-gdb-show annotate
19076^done,value="0"
19077(@value{GDBP})
19078@end smallexample
19079
19080@c @subheading -gdb-source
19081
19082
19083@subheading The @code{-gdb-version} Command
19084@findex -gdb-version
19085
19086@subsubheading Synopsis
19087
19088@smallexample
19089 -gdb-version
19090@end smallexample
19091
19092Show version information for @value{GDBN}. Used mostly in testing.
19093
19094@subsubheading @value{GDBN} Command
19095
19096There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
19097information when you start an interactive session.
19098
19099@subsubheading Example
19100
19101@c This example modifies the actual output from GDB to avoid overfull
19102@c box in TeX.
19103@smallexample
19104(@value{GDBP})
19105-gdb-version
19106~GNU gdb 5.2.1
19107~Copyright 2000 Free Software Foundation, Inc.
19108~GDB is free software, covered by the GNU General Public License, and
19109~you are welcome to change it and/or distribute copies of it under
19110~ certain conditions.
19111~Type "show copying" to see the conditions.
19112~There is absolutely no warranty for GDB. Type "show warranty" for
19113~ details.
b383017d 19114~This GDB was configured as
922fbb7b
AC
19115 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
19116^done
19117(@value{GDBP})
19118@end smallexample
19119
19120@subheading The @code{-interpreter-exec} Command
19121@findex -interpreter-exec
19122
19123@subheading Synopsis
19124
19125@smallexample
19126-interpreter-exec @var{interpreter} @var{command}
19127@end smallexample
19128
19129Execute the specified @var{command} in the given @var{interpreter}.
19130
19131@subheading @value{GDBN} Command
19132
19133The corresponding @value{GDBN} command is @samp{interpreter-exec}.
19134
19135@subheading Example
19136
19137@smallexample
19138(@value{GDBP})
19139-interpreter-exec console "break main"
19140&"During symbol reading, couldn't parse type; debugger out of date?.\n"
19141&"During symbol reading, bad structure-type format.\n"
19142~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
19143^done
19144(@value{GDBP})
19145@end smallexample
19146
19147@ignore
19148@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19149@node GDB/MI Kod Commands
19150@section @sc{gdb/mi} Kod Commands
19151
19152The Kod commands are not implemented.
19153
19154@c @subheading -kod-info
19155
19156@c @subheading -kod-list
19157
19158@c @subheading -kod-list-object-types
19159
19160@c @subheading -kod-show
19161
19162@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19163@node GDB/MI Memory Overlay Commands
19164@section @sc{gdb/mi} Memory Overlay Commands
19165
19166The memory overlay commands are not implemented.
19167
19168@c @subheading -overlay-auto
19169
19170@c @subheading -overlay-list-mapping-state
19171
19172@c @subheading -overlay-list-overlays
19173
19174@c @subheading -overlay-map
19175
19176@c @subheading -overlay-off
19177
19178@c @subheading -overlay-on
19179
19180@c @subheading -overlay-unmap
19181
19182@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19183@node GDB/MI Signal Handling Commands
19184@section @sc{gdb/mi} Signal Handling Commands
19185
19186Signal handling commands are not implemented.
19187
19188@c @subheading -signal-handle
19189
19190@c @subheading -signal-list-handle-actions
19191
19192@c @subheading -signal-list-signal-types
19193@end ignore
19194
19195
19196@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19197@node GDB/MI Stack Manipulation
19198@section @sc{gdb/mi} Stack Manipulation Commands
19199
922fbb7b
AC
19200@subheading The @code{-stack-info-depth} Command
19201@findex -stack-info-depth
19202
19203@subsubheading Synopsis
19204
19205@smallexample
19206 -stack-info-depth [ @var{max-depth} ]
19207@end smallexample
19208
19209Return the depth of the stack. If the integer argument @var{max-depth}
19210is specified, do not count beyond @var{max-depth} frames.
19211
19212@subsubheading @value{GDBN} Command
19213
19214There's no equivalent @value{GDBN} command.
19215
19216@subsubheading Example
19217
19218For a stack with frame levels 0 through 11:
19219
19220@smallexample
19221(@value{GDBP})
19222-stack-info-depth
19223^done,depth="12"
19224(@value{GDBP})
19225-stack-info-depth 4
19226^done,depth="4"
19227(@value{GDBP})
19228-stack-info-depth 12
19229^done,depth="12"
19230(@value{GDBP})
19231-stack-info-depth 11
19232^done,depth="11"
19233(@value{GDBP})
19234-stack-info-depth 13
19235^done,depth="12"
19236(@value{GDBP})
19237@end smallexample
19238
19239@subheading The @code{-stack-list-arguments} Command
19240@findex -stack-list-arguments
19241
19242@subsubheading Synopsis
19243
19244@smallexample
19245 -stack-list-arguments @var{show-values}
19246 [ @var{low-frame} @var{high-frame} ]
19247@end smallexample
19248
19249Display a list of the arguments for the frames between @var{low-frame}
19250and @var{high-frame} (inclusive). If @var{low-frame} and
19251@var{high-frame} are not provided, list the arguments for the whole call
19252stack.
19253
19254The @var{show-values} argument must have a value of 0 or 1. A value of
192550 means that only the names of the arguments are listed, a value of 1
19256means that both names and values of the arguments are printed.
19257
19258@subsubheading @value{GDBN} Command
19259
19260@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
19261@samp{gdb_get_args} command which partially overlaps with the
19262functionality of @samp{-stack-list-arguments}.
19263
19264@subsubheading Example
19265
19266@smallexample
19267(@value{GDBP})
19268-stack-list-frames
19269^done,
19270stack=[
19271frame=@{level="0",addr="0x00010734",func="callee4",
76ff342d
DJ
19272file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19273fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
922fbb7b 19274frame=@{level="1",addr="0x0001076c",func="callee3",
76ff342d
DJ
19275file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19276fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
922fbb7b 19277frame=@{level="2",addr="0x0001078c",func="callee2",
76ff342d
DJ
19278file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19279fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
922fbb7b 19280frame=@{level="3",addr="0x000107b4",func="callee1",
76ff342d
DJ
19281file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19282fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
922fbb7b 19283frame=@{level="4",addr="0x000107e0",func="main",
76ff342d
DJ
19284file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19285fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
922fbb7b
AC
19286(@value{GDBP})
19287-stack-list-arguments 0
19288^done,
19289stack-args=[
19290frame=@{level="0",args=[]@},
19291frame=@{level="1",args=[name="strarg"]@},
19292frame=@{level="2",args=[name="intarg",name="strarg"]@},
19293frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
19294frame=@{level="4",args=[]@}]
19295(@value{GDBP})
19296-stack-list-arguments 1
19297^done,
19298stack-args=[
19299frame=@{level="0",args=[]@},
19300frame=@{level="1",
19301 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19302frame=@{level="2",args=[
19303@{name="intarg",value="2"@},
19304@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19305@{frame=@{level="3",args=[
19306@{name="intarg",value="2"@},
19307@{name="strarg",value="0x11940 \"A string argument.\""@},
19308@{name="fltarg",value="3.5"@}]@},
19309frame=@{level="4",args=[]@}]
19310(@value{GDBP})
19311-stack-list-arguments 0 2 2
19312^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
19313(@value{GDBP})
19314-stack-list-arguments 1 2 2
19315^done,stack-args=[frame=@{level="2",
19316args=[@{name="intarg",value="2"@},
19317@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
19318(@value{GDBP})
19319@end smallexample
19320
19321@c @subheading -stack-list-exception-handlers
19322
19323
19324@subheading The @code{-stack-list-frames} Command
19325@findex -stack-list-frames
19326
19327@subsubheading Synopsis
19328
19329@smallexample
19330 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
19331@end smallexample
19332
19333List the frames currently on the stack. For each frame it displays the
19334following info:
19335
19336@table @samp
19337@item @var{level}
19338The frame number, 0 being the topmost frame, i.e. the innermost function.
19339@item @var{addr}
19340The @code{$pc} value for that frame.
19341@item @var{func}
19342Function name.
19343@item @var{file}
19344File name of the source file where the function lives.
19345@item @var{line}
19346Line number corresponding to the @code{$pc}.
19347@end table
19348
19349If invoked without arguments, this command prints a backtrace for the
19350whole stack. If given two integer arguments, it shows the frames whose
19351levels are between the two arguments (inclusive). If the two arguments
19352are equal, it shows the single frame at the corresponding level.
19353
19354@subsubheading @value{GDBN} Command
19355
19356The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
19357
19358@subsubheading Example
19359
19360Full stack backtrace:
19361
19362@smallexample
19363(@value{GDBP})
19364-stack-list-frames
19365^done,stack=
19366[frame=@{level="0",addr="0x0001076c",func="foo",
76ff342d 19367 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@},
922fbb7b 19368frame=@{level="1",addr="0x000107a4",func="foo",
76ff342d 19369 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19370frame=@{level="2",addr="0x000107a4",func="foo",
76ff342d 19371 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19372frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19373 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19374frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19375 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19376frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19377 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19378frame=@{level="6",addr="0x000107a4",func="foo",
76ff342d 19379 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19380frame=@{level="7",addr="0x000107a4",func="foo",
76ff342d 19381 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19382frame=@{level="8",addr="0x000107a4",func="foo",
76ff342d 19383 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19384frame=@{level="9",addr="0x000107a4",func="foo",
76ff342d 19385 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19386frame=@{level="10",addr="0x000107a4",func="foo",
76ff342d 19387 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19388frame=@{level="11",addr="0x00010738",func="main",
76ff342d 19389 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}]
922fbb7b
AC
19390(@value{GDBP})
19391@end smallexample
19392
19393Show frames between @var{low_frame} and @var{high_frame}:
19394
19395@smallexample
19396(@value{GDBP})
19397-stack-list-frames 3 5
19398^done,stack=
19399[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19400 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19401frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19402 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19403frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19404 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19405(@value{GDBP})
19406@end smallexample
19407
19408Show a single frame:
19409
19410@smallexample
19411(@value{GDBP})
19412-stack-list-frames 3 3
19413^done,stack=
19414[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19415 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19416(@value{GDBP})
19417@end smallexample
19418
19419
19420@subheading The @code{-stack-list-locals} Command
19421@findex -stack-list-locals
19422
19423@subsubheading Synopsis
19424
19425@smallexample
19426 -stack-list-locals @var{print-values}
19427@end smallexample
19428
19429Display the local variable names for the current frame. With an
bc8ced35
NR
19430argument of 0 or @code{--no-values}, prints only the names of the variables.
19431With argument of 1 or @code{--all-values}, prints also their values. With
19432argument of 2 or @code{--simple-values}, prints the name, type and value for
19433simple data types and the name and type for arrays, structures and
19434unions. In this last case, the idea is that the user can see the
19435value of simple data types immediately and he can create variable
19436objects for other data types if he wishes to explore their values in
19437more detail.
922fbb7b
AC
19438
19439@subsubheading @value{GDBN} Command
19440
19441@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
19442
19443@subsubheading Example
19444
19445@smallexample
19446(@value{GDBP})
19447-stack-list-locals 0
19448^done,locals=[name="A",name="B",name="C"]
19449(@value{GDBP})
bc8ced35 19450-stack-list-locals --all-values
922fbb7b 19451^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
bc8ced35
NR
19452 @{name="C",value="@{1, 2, 3@}"@}]
19453-stack-list-locals --simple-values
19454^done,locals=[@{name="A",type="int",value="1"@},
19455 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
922fbb7b
AC
19456(@value{GDBP})
19457@end smallexample
19458
19459
19460@subheading The @code{-stack-select-frame} Command
19461@findex -stack-select-frame
19462
19463@subsubheading Synopsis
19464
19465@smallexample
19466 -stack-select-frame @var{framenum}
19467@end smallexample
19468
19469Change the current frame. Select a different frame @var{framenum} on
19470the stack.
19471
19472@subsubheading @value{GDBN} Command
19473
19474The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
19475@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
19476
19477@subsubheading Example
19478
19479@smallexample
19480(@value{GDBP})
19481-stack-select-frame 2
19482^done
19483(@value{GDBP})
19484@end smallexample
19485
19486@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19487@node GDB/MI Symbol Query
19488@section @sc{gdb/mi} Symbol Query Commands
19489
19490
19491@subheading The @code{-symbol-info-address} Command
19492@findex -symbol-info-address
19493
19494@subsubheading Synopsis
19495
19496@smallexample
19497 -symbol-info-address @var{symbol}
19498@end smallexample
19499
19500Describe where @var{symbol} is stored.
19501
19502@subsubheading @value{GDBN} Command
19503
19504The corresponding @value{GDBN} command is @samp{info address}.
19505
19506@subsubheading Example
19507N.A.
19508
19509
19510@subheading The @code{-symbol-info-file} Command
19511@findex -symbol-info-file
19512
19513@subsubheading Synopsis
19514
19515@smallexample
19516 -symbol-info-file
19517@end smallexample
19518
19519Show the file for the symbol.
19520
19521@subsubheading @value{GDBN} Command
19522
19523There's no equivalent @value{GDBN} command. @code{gdbtk} has
19524@samp{gdb_find_file}.
19525
19526@subsubheading Example
19527N.A.
19528
19529
19530@subheading The @code{-symbol-info-function} Command
19531@findex -symbol-info-function
19532
19533@subsubheading Synopsis
19534
19535@smallexample
19536 -symbol-info-function
19537@end smallexample
19538
19539Show which function the symbol lives in.
19540
19541@subsubheading @value{GDBN} Command
19542
19543@samp{gdb_get_function} in @code{gdbtk}.
19544
19545@subsubheading Example
19546N.A.
19547
19548
19549@subheading The @code{-symbol-info-line} Command
19550@findex -symbol-info-line
19551
19552@subsubheading Synopsis
19553
19554@smallexample
19555 -symbol-info-line
19556@end smallexample
19557
19558Show the core addresses of the code for a source line.
19559
19560@subsubheading @value{GDBN} Command
19561
71952f4c 19562The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
19563@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
19564
19565@subsubheading Example
19566N.A.
19567
19568
19569@subheading The @code{-symbol-info-symbol} Command
19570@findex -symbol-info-symbol
19571
19572@subsubheading Synopsis
19573
19574@smallexample
19575 -symbol-info-symbol @var{addr}
19576@end smallexample
19577
19578Describe what symbol is at location @var{addr}.
19579
19580@subsubheading @value{GDBN} Command
19581
19582The corresponding @value{GDBN} command is @samp{info symbol}.
19583
19584@subsubheading Example
19585N.A.
19586
19587
19588@subheading The @code{-symbol-list-functions} Command
19589@findex -symbol-list-functions
19590
19591@subsubheading Synopsis
19592
19593@smallexample
19594 -symbol-list-functions
19595@end smallexample
19596
19597List the functions in the executable.
19598
19599@subsubheading @value{GDBN} Command
19600
19601@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
19602@samp{gdb_search} in @code{gdbtk}.
19603
19604@subsubheading Example
19605N.A.
19606
19607
32e7087d
JB
19608@subheading The @code{-symbol-list-lines} Command
19609@findex -symbol-list-lines
19610
19611@subsubheading Synopsis
19612
19613@smallexample
19614 -symbol-list-lines @var{filename}
19615@end smallexample
19616
19617Print the list of lines that contain code and their associated program
19618addresses for the given source filename. The entries are sorted in
19619ascending PC order.
19620
19621@subsubheading @value{GDBN} Command
19622
19623There is no corresponding @value{GDBN} command.
19624
19625@subsubheading Example
19626@smallexample
19627(@value{GDBP})
19628-symbol-list-lines basics.c
54ff5908 19629^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
19630(@value{GDBP})
19631@end smallexample
19632
19633
922fbb7b
AC
19634@subheading The @code{-symbol-list-types} Command
19635@findex -symbol-list-types
19636
19637@subsubheading Synopsis
19638
19639@smallexample
19640 -symbol-list-types
19641@end smallexample
19642
19643List all the type names.
19644
19645@subsubheading @value{GDBN} Command
19646
19647The corresponding commands are @samp{info types} in @value{GDBN},
19648@samp{gdb_search} in @code{gdbtk}.
19649
19650@subsubheading Example
19651N.A.
19652
19653
19654@subheading The @code{-symbol-list-variables} Command
19655@findex -symbol-list-variables
19656
19657@subsubheading Synopsis
19658
19659@smallexample
19660 -symbol-list-variables
19661@end smallexample
19662
19663List all the global and static variable names.
19664
19665@subsubheading @value{GDBN} Command
19666
19667@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
19668
19669@subsubheading Example
19670N.A.
19671
19672
19673@subheading The @code{-symbol-locate} Command
19674@findex -symbol-locate
19675
19676@subsubheading Synopsis
19677
19678@smallexample
19679 -symbol-locate
19680@end smallexample
19681
19682@subsubheading @value{GDBN} Command
19683
19684@samp{gdb_loc} in @code{gdbtk}.
19685
19686@subsubheading Example
19687N.A.
19688
19689
19690@subheading The @code{-symbol-type} Command
19691@findex -symbol-type
19692
19693@subsubheading Synopsis
19694
19695@smallexample
19696 -symbol-type @var{variable}
19697@end smallexample
19698
19699Show type of @var{variable}.
19700
19701@subsubheading @value{GDBN} Command
19702
19703The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
19704@samp{gdb_obj_variable}.
19705
19706@subsubheading Example
19707N.A.
19708
19709
19710@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19711@node GDB/MI Target Manipulation
19712@section @sc{gdb/mi} Target Manipulation Commands
19713
19714
19715@subheading The @code{-target-attach} Command
19716@findex -target-attach
19717
19718@subsubheading Synopsis
19719
19720@smallexample
19721 -target-attach @var{pid} | @var{file}
19722@end smallexample
19723
19724Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
19725
19726@subsubheading @value{GDBN} command
19727
19728The corresponding @value{GDBN} command is @samp{attach}.
19729
19730@subsubheading Example
19731N.A.
19732
19733
19734@subheading The @code{-target-compare-sections} Command
19735@findex -target-compare-sections
19736
19737@subsubheading Synopsis
19738
19739@smallexample
19740 -target-compare-sections [ @var{section} ]
19741@end smallexample
19742
19743Compare data of section @var{section} on target to the exec file.
19744Without the argument, all sections are compared.
19745
19746@subsubheading @value{GDBN} Command
19747
19748The @value{GDBN} equivalent is @samp{compare-sections}.
19749
19750@subsubheading Example
19751N.A.
19752
19753
19754@subheading The @code{-target-detach} Command
19755@findex -target-detach
19756
19757@subsubheading Synopsis
19758
19759@smallexample
19760 -target-detach
19761@end smallexample
19762
19763Disconnect from the remote target. There's no output.
19764
19765@subsubheading @value{GDBN} command
19766
19767The corresponding @value{GDBN} command is @samp{detach}.
19768
19769@subsubheading Example
19770
19771@smallexample
19772(@value{GDBP})
19773-target-detach
19774^done
19775(@value{GDBP})
19776@end smallexample
19777
19778
07f31aa6
DJ
19779@subheading The @code{-target-disconnect} Command
19780@findex -target-disconnect
19781
19782@subsubheading Synopsis
19783
19784@example
19785 -target-disconnect
19786@end example
19787
19788Disconnect from the remote target. There's no output.
19789
19790@subsubheading @value{GDBN} command
19791
19792The corresponding @value{GDBN} command is @samp{disconnect}.
19793
19794@subsubheading Example
19795
19796@smallexample
19797(@value{GDBP})
19798-target-disconnect
19799^done
19800(@value{GDBP})
19801@end smallexample
19802
19803
922fbb7b
AC
19804@subheading The @code{-target-download} Command
19805@findex -target-download
19806
19807@subsubheading Synopsis
19808
19809@smallexample
19810 -target-download
19811@end smallexample
19812
19813Loads the executable onto the remote target.
19814It prints out an update message every half second, which includes the fields:
19815
19816@table @samp
19817@item section
19818The name of the section.
19819@item section-sent
19820The size of what has been sent so far for that section.
19821@item section-size
19822The size of the section.
19823@item total-sent
19824The total size of what was sent so far (the current and the previous sections).
19825@item total-size
19826The size of the overall executable to download.
19827@end table
19828
19829@noindent
19830Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
19831@sc{gdb/mi} Output Syntax}).
19832
19833In addition, it prints the name and size of the sections, as they are
19834downloaded. These messages include the following fields:
19835
19836@table @samp
19837@item section
19838The name of the section.
19839@item section-size
19840The size of the section.
19841@item total-size
19842The size of the overall executable to download.
19843@end table
19844
19845@noindent
19846At the end, a summary is printed.
19847
19848@subsubheading @value{GDBN} Command
19849
19850The corresponding @value{GDBN} command is @samp{load}.
19851
19852@subsubheading Example
19853
19854Note: each status message appears on a single line. Here the messages
19855have been broken down so that they can fit onto a page.
19856
19857@smallexample
19858(@value{GDBP})
19859-target-download
19860+download,@{section=".text",section-size="6668",total-size="9880"@}
19861+download,@{section=".text",section-sent="512",section-size="6668",
19862total-sent="512",total-size="9880"@}
19863+download,@{section=".text",section-sent="1024",section-size="6668",
19864total-sent="1024",total-size="9880"@}
19865+download,@{section=".text",section-sent="1536",section-size="6668",
19866total-sent="1536",total-size="9880"@}
19867+download,@{section=".text",section-sent="2048",section-size="6668",
19868total-sent="2048",total-size="9880"@}
19869+download,@{section=".text",section-sent="2560",section-size="6668",
19870total-sent="2560",total-size="9880"@}
19871+download,@{section=".text",section-sent="3072",section-size="6668",
19872total-sent="3072",total-size="9880"@}
19873+download,@{section=".text",section-sent="3584",section-size="6668",
19874total-sent="3584",total-size="9880"@}
19875+download,@{section=".text",section-sent="4096",section-size="6668",
19876total-sent="4096",total-size="9880"@}
19877+download,@{section=".text",section-sent="4608",section-size="6668",
19878total-sent="4608",total-size="9880"@}
19879+download,@{section=".text",section-sent="5120",section-size="6668",
19880total-sent="5120",total-size="9880"@}
19881+download,@{section=".text",section-sent="5632",section-size="6668",
19882total-sent="5632",total-size="9880"@}
19883+download,@{section=".text",section-sent="6144",section-size="6668",
19884total-sent="6144",total-size="9880"@}
19885+download,@{section=".text",section-sent="6656",section-size="6668",
19886total-sent="6656",total-size="9880"@}
19887+download,@{section=".init",section-size="28",total-size="9880"@}
19888+download,@{section=".fini",section-size="28",total-size="9880"@}
19889+download,@{section=".data",section-size="3156",total-size="9880"@}
19890+download,@{section=".data",section-sent="512",section-size="3156",
19891total-sent="7236",total-size="9880"@}
19892+download,@{section=".data",section-sent="1024",section-size="3156",
19893total-sent="7748",total-size="9880"@}
19894+download,@{section=".data",section-sent="1536",section-size="3156",
19895total-sent="8260",total-size="9880"@}
19896+download,@{section=".data",section-sent="2048",section-size="3156",
19897total-sent="8772",total-size="9880"@}
19898+download,@{section=".data",section-sent="2560",section-size="3156",
19899total-sent="9284",total-size="9880"@}
19900+download,@{section=".data",section-sent="3072",section-size="3156",
19901total-sent="9796",total-size="9880"@}
19902^done,address="0x10004",load-size="9880",transfer-rate="6586",
19903write-rate="429"
19904(@value{GDBP})
19905@end smallexample
19906
19907
19908@subheading The @code{-target-exec-status} Command
19909@findex -target-exec-status
19910
19911@subsubheading Synopsis
19912
19913@smallexample
19914 -target-exec-status
19915@end smallexample
19916
19917Provide information on the state of the target (whether it is running or
19918not, for instance).
19919
19920@subsubheading @value{GDBN} Command
19921
19922There's no equivalent @value{GDBN} command.
19923
19924@subsubheading Example
19925N.A.
19926
19927
19928@subheading The @code{-target-list-available-targets} Command
19929@findex -target-list-available-targets
19930
19931@subsubheading Synopsis
19932
19933@smallexample
19934 -target-list-available-targets
19935@end smallexample
19936
19937List the possible targets to connect to.
19938
19939@subsubheading @value{GDBN} Command
19940
19941The corresponding @value{GDBN} command is @samp{help target}.
19942
19943@subsubheading Example
19944N.A.
19945
19946
19947@subheading The @code{-target-list-current-targets} Command
19948@findex -target-list-current-targets
19949
19950@subsubheading Synopsis
19951
19952@smallexample
19953 -target-list-current-targets
19954@end smallexample
19955
19956Describe the current target.
19957
19958@subsubheading @value{GDBN} Command
19959
19960The corresponding information is printed by @samp{info file} (among
19961other things).
19962
19963@subsubheading Example
19964N.A.
19965
19966
19967@subheading The @code{-target-list-parameters} Command
19968@findex -target-list-parameters
19969
19970@subsubheading Synopsis
19971
19972@smallexample
19973 -target-list-parameters
19974@end smallexample
19975
19976@c ????
19977
19978@subsubheading @value{GDBN} Command
19979
19980No equivalent.
19981
19982@subsubheading Example
19983N.A.
19984
19985
19986@subheading The @code{-target-select} Command
19987@findex -target-select
19988
19989@subsubheading Synopsis
19990
19991@smallexample
19992 -target-select @var{type} @var{parameters @dots{}}
19993@end smallexample
19994
19995Connect @value{GDBN} to the remote target. This command takes two args:
19996
19997@table @samp
19998@item @var{type}
19999The type of target, for instance @samp{async}, @samp{remote}, etc.
20000@item @var{parameters}
20001Device names, host names and the like. @xref{Target Commands, ,
20002Commands for managing targets}, for more details.
20003@end table
20004
20005The output is a connection notification, followed by the address at
20006which the target program is, in the following form:
20007
20008@smallexample
20009^connected,addr="@var{address}",func="@var{function name}",
20010 args=[@var{arg list}]
20011@end smallexample
20012
20013@subsubheading @value{GDBN} Command
20014
20015The corresponding @value{GDBN} command is @samp{target}.
20016
20017@subsubheading Example
20018
20019@smallexample
20020(@value{GDBP})
20021-target-select async /dev/ttya
20022^connected,addr="0xfe00a300",func="??",args=[]
20023(@value{GDBP})
20024@end smallexample
20025
20026@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20027@node GDB/MI Thread Commands
20028@section @sc{gdb/mi} Thread Commands
20029
20030
20031@subheading The @code{-thread-info} Command
20032@findex -thread-info
20033
20034@subsubheading Synopsis
20035
20036@smallexample
20037 -thread-info
20038@end smallexample
20039
20040@subsubheading @value{GDBN} command
20041
20042No equivalent.
20043
20044@subsubheading Example
20045N.A.
20046
20047
20048@subheading The @code{-thread-list-all-threads} Command
20049@findex -thread-list-all-threads
20050
20051@subsubheading Synopsis
20052
20053@smallexample
20054 -thread-list-all-threads
20055@end smallexample
20056
20057@subsubheading @value{GDBN} Command
20058
20059The equivalent @value{GDBN} command is @samp{info threads}.
20060
20061@subsubheading Example
20062N.A.
20063
20064
20065@subheading The @code{-thread-list-ids} Command
20066@findex -thread-list-ids
20067
20068@subsubheading Synopsis
20069
20070@smallexample
20071 -thread-list-ids
20072@end smallexample
20073
20074Produces a list of the currently known @value{GDBN} thread ids. At the
20075end of the list it also prints the total number of such threads.
20076
20077@subsubheading @value{GDBN} Command
20078
20079Part of @samp{info threads} supplies the same information.
20080
20081@subsubheading Example
20082
20083No threads present, besides the main process:
20084
20085@smallexample
20086(@value{GDBP})
20087-thread-list-ids
20088^done,thread-ids=@{@},number-of-threads="0"
20089(@value{GDBP})
20090@end smallexample
20091
20092
20093Several threads:
20094
20095@smallexample
20096(@value{GDBP})
20097-thread-list-ids
20098^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20099number-of-threads="3"
20100(@value{GDBP})
20101@end smallexample
20102
20103
20104@subheading The @code{-thread-select} Command
20105@findex -thread-select
20106
20107@subsubheading Synopsis
20108
20109@smallexample
20110 -thread-select @var{threadnum}
20111@end smallexample
20112
20113Make @var{threadnum} the current thread. It prints the number of the new
20114current thread, and the topmost frame for that thread.
20115
20116@subsubheading @value{GDBN} Command
20117
20118The corresponding @value{GDBN} command is @samp{thread}.
20119
20120@subsubheading Example
20121
20122@smallexample
20123(@value{GDBP})
20124-exec-next
20125^running
20126(@value{GDBP})
20127*stopped,reason="end-stepping-range",thread-id="2",line="187",
20128file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
20129(@value{GDBP})
20130-thread-list-ids
20131^done,
20132thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20133number-of-threads="3"
20134(@value{GDBP})
20135-thread-select 3
20136^done,new-thread-id="3",
20137frame=@{level="0",func="vprintf",
20138args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
20139@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
20140(@value{GDBP})
20141@end smallexample
20142
20143@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20144@node GDB/MI Tracepoint Commands
20145@section @sc{gdb/mi} Tracepoint Commands
20146
20147The tracepoint commands are not yet implemented.
20148
20149@c @subheading -trace-actions
20150
20151@c @subheading -trace-delete
20152
20153@c @subheading -trace-disable
20154
20155@c @subheading -trace-dump
20156
20157@c @subheading -trace-enable
20158
20159@c @subheading -trace-exists
20160
20161@c @subheading -trace-find
20162
20163@c @subheading -trace-frame-number
20164
20165@c @subheading -trace-info
20166
20167@c @subheading -trace-insert
20168
20169@c @subheading -trace-list
20170
20171@c @subheading -trace-pass-count
20172
20173@c @subheading -trace-save
20174
20175@c @subheading -trace-start
20176
20177@c @subheading -trace-stop
20178
20179
20180@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20181@node GDB/MI Variable Objects
20182@section @sc{gdb/mi} Variable Objects
20183
20184
20185@subheading Motivation for Variable Objects in @sc{gdb/mi}
20186
20187For the implementation of a variable debugger window (locals, watched
20188expressions, etc.), we are proposing the adaptation of the existing code
20189used by @code{Insight}.
20190
20191The two main reasons for that are:
20192
20193@enumerate 1
20194@item
20195It has been proven in practice (it is already on its second generation).
20196
20197@item
20198It will shorten development time (needless to say how important it is
20199now).
20200@end enumerate
20201
20202The original interface was designed to be used by Tcl code, so it was
20203slightly changed so it could be used through @sc{gdb/mi}. This section
20204describes the @sc{gdb/mi} operations that will be available and gives some
20205hints about their use.
20206
20207@emph{Note}: In addition to the set of operations described here, we
20208expect the @sc{gui} implementation of a variable window to require, at
20209least, the following operations:
20210
20211@itemize @bullet
20212@item @code{-gdb-show} @code{output-radix}
20213@item @code{-stack-list-arguments}
20214@item @code{-stack-list-locals}
20215@item @code{-stack-select-frame}
20216@end itemize
20217
20218@subheading Introduction to Variable Objects in @sc{gdb/mi}
20219
20220@cindex variable objects in @sc{gdb/mi}
20221The basic idea behind variable objects is the creation of a named object
20222to represent a variable, an expression, a memory location or even a CPU
20223register. For each object created, a set of operations is available for
20224examining or changing its properties.
20225
20226Furthermore, complex data types, such as C structures, are represented
20227in a tree format. For instance, the @code{struct} type variable is the
20228root and the children will represent the struct members. If a child
20229is itself of a complex type, it will also have children of its own.
20230Appropriate language differences are handled for C, C@t{++} and Java.
20231
20232When returning the actual values of the objects, this facility allows
20233for the individual selection of the display format used in the result
20234creation. It can be chosen among: binary, decimal, hexadecimal, octal
20235and natural. Natural refers to a default format automatically
20236chosen based on the variable type (like decimal for an @code{int}, hex
20237for pointers, etc.).
20238
20239The following is the complete set of @sc{gdb/mi} operations defined to
20240access this functionality:
20241
20242@multitable @columnfractions .4 .6
20243@item @strong{Operation}
20244@tab @strong{Description}
20245
20246@item @code{-var-create}
20247@tab create a variable object
20248@item @code{-var-delete}
20249@tab delete the variable object and its children
20250@item @code{-var-set-format}
20251@tab set the display format of this variable
20252@item @code{-var-show-format}
20253@tab show the display format of this variable
20254@item @code{-var-info-num-children}
20255@tab tells how many children this object has
20256@item @code{-var-list-children}
20257@tab return a list of the object's children
20258@item @code{-var-info-type}
20259@tab show the type of this variable object
20260@item @code{-var-info-expression}
20261@tab print what this variable object represents
20262@item @code{-var-show-attributes}
20263@tab is this variable editable? does it exist here?
20264@item @code{-var-evaluate-expression}
20265@tab get the value of this variable
20266@item @code{-var-assign}
20267@tab set the value of this variable
20268@item @code{-var-update}
20269@tab update the variable and its children
20270@end multitable
20271
20272In the next subsection we describe each operation in detail and suggest
20273how it can be used.
20274
20275@subheading Description And Use of Operations on Variable Objects
20276
20277@subheading The @code{-var-create} Command
20278@findex -var-create
20279
20280@subsubheading Synopsis
20281
20282@smallexample
20283 -var-create @{@var{name} | "-"@}
20284 @{@var{frame-addr} | "*"@} @var{expression}
20285@end smallexample
20286
20287This operation creates a variable object, which allows the monitoring of
20288a variable, the result of an expression, a memory cell or a CPU
20289register.
20290
20291The @var{name} parameter is the string by which the object can be
20292referenced. It must be unique. If @samp{-} is specified, the varobj
20293system will generate a string ``varNNNNNN'' automatically. It will be
20294unique provided that one does not specify @var{name} on that format.
20295The command fails if a duplicate name is found.
20296
20297The frame under which the expression should be evaluated can be
20298specified by @var{frame-addr}. A @samp{*} indicates that the current
20299frame should be used.
20300
20301@var{expression} is any expression valid on the current language set (must not
20302begin with a @samp{*}), or one of the following:
20303
20304@itemize @bullet
20305@item
20306@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
20307
20308@item
20309@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
20310
20311@item
20312@samp{$@var{regname}} --- a CPU register name
20313@end itemize
20314
20315@subsubheading Result
20316
20317This operation returns the name, number of children and the type of the
20318object created. Type is returned as a string as the ones generated by
20319the @value{GDBN} CLI:
20320
20321@smallexample
20322 name="@var{name}",numchild="N",type="@var{type}"
20323@end smallexample
20324
20325
20326@subheading The @code{-var-delete} Command
20327@findex -var-delete
20328
20329@subsubheading Synopsis
20330
20331@smallexample
20332 -var-delete @var{name}
20333@end smallexample
20334
20335Deletes a previously created variable object and all of its children.
20336
20337Returns an error if the object @var{name} is not found.
20338
20339
20340@subheading The @code{-var-set-format} Command
20341@findex -var-set-format
20342
20343@subsubheading Synopsis
20344
20345@smallexample
20346 -var-set-format @var{name} @var{format-spec}
20347@end smallexample
20348
20349Sets the output format for the value of the object @var{name} to be
20350@var{format-spec}.
20351
20352The syntax for the @var{format-spec} is as follows:
20353
20354@smallexample
20355 @var{format-spec} @expansion{}
20356 @{binary | decimal | hexadecimal | octal | natural@}
20357@end smallexample
20358
20359
20360@subheading The @code{-var-show-format} Command
20361@findex -var-show-format
20362
20363@subsubheading Synopsis
20364
20365@smallexample
20366 -var-show-format @var{name}
20367@end smallexample
20368
20369Returns the format used to display the value of the object @var{name}.
20370
20371@smallexample
20372 @var{format} @expansion{}
20373 @var{format-spec}
20374@end smallexample
20375
20376
20377@subheading The @code{-var-info-num-children} Command
20378@findex -var-info-num-children
20379
20380@subsubheading Synopsis
20381
20382@smallexample
20383 -var-info-num-children @var{name}
20384@end smallexample
20385
20386Returns the number of children of a variable object @var{name}:
20387
20388@smallexample
20389 numchild=@var{n}
20390@end smallexample
20391
20392
20393@subheading The @code{-var-list-children} Command
20394@findex -var-list-children
20395
20396@subsubheading Synopsis
20397
20398@smallexample
bc8ced35 20399 -var-list-children [@var{print-values}] @var{name}
922fbb7b
AC
20400@end smallexample
20401
bc8ced35
NR
20402Returns a list of the children of the specified variable object. With
20403just the variable object name as an argument or with an optional
20404preceding argument of 0 or @code{--no-values}, prints only the names of the
20405variables. With an optional preceding argument of 1 or @code{--all-values},
20406also prints their values.
20407
20408@subsubheading Example
922fbb7b
AC
20409
20410@smallexample
bc8ced35
NR
20411(@value{GDBP})
20412 -var-list-children n
922fbb7b
AC
20413 numchild=@var{n},children=[@{name=@var{name},
20414 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
bc8ced35
NR
20415(@value{GDBP})
20416 -var-list-children --all-values n
20417 numchild=@var{n},children=[@{name=@var{name},
20418 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
20419@end smallexample
20420
20421
20422@subheading The @code{-var-info-type} Command
20423@findex -var-info-type
20424
20425@subsubheading Synopsis
20426
20427@smallexample
20428 -var-info-type @var{name}
20429@end smallexample
20430
20431Returns the type of the specified variable @var{name}. The type is
20432returned as a string in the same format as it is output by the
20433@value{GDBN} CLI:
20434
20435@smallexample
20436 type=@var{typename}
20437@end smallexample
20438
20439
20440@subheading The @code{-var-info-expression} Command
20441@findex -var-info-expression
20442
20443@subsubheading Synopsis
20444
20445@smallexample
20446 -var-info-expression @var{name}
20447@end smallexample
20448
20449Returns what is represented by the variable object @var{name}:
20450
20451@smallexample
20452 lang=@var{lang-spec},exp=@var{expression}
20453@end smallexample
20454
20455@noindent
20456where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
20457
20458@subheading The @code{-var-show-attributes} Command
20459@findex -var-show-attributes
20460
20461@subsubheading Synopsis
20462
20463@smallexample
20464 -var-show-attributes @var{name}
20465@end smallexample
20466
20467List attributes of the specified variable object @var{name}:
20468
20469@smallexample
20470 status=@var{attr} [ ( ,@var{attr} )* ]
20471@end smallexample
20472
20473@noindent
20474where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
20475
20476@subheading The @code{-var-evaluate-expression} Command
20477@findex -var-evaluate-expression
20478
20479@subsubheading Synopsis
20480
20481@smallexample
20482 -var-evaluate-expression @var{name}
20483@end smallexample
20484
20485Evaluates the expression that is represented by the specified variable
20486object and returns its value as a string in the current format specified
20487for the object:
20488
20489@smallexample
20490 value=@var{value}
20491@end smallexample
20492
20493Note that one must invoke @code{-var-list-children} for a variable
20494before the value of a child variable can be evaluated.
20495
20496@subheading The @code{-var-assign} Command
20497@findex -var-assign
20498
20499@subsubheading Synopsis
20500
20501@smallexample
20502 -var-assign @var{name} @var{expression}
20503@end smallexample
20504
20505Assigns the value of @var{expression} to the variable object specified
20506by @var{name}. The object must be @samp{editable}. If the variable's
b383017d 20507value is altered by the assign, the variable will show up in any
922fbb7b
AC
20508subsequent @code{-var-update} list.
20509
20510@subsubheading Example
20511
20512@smallexample
20513(@value{GDBP})
20514-var-assign var1 3
20515^done,value="3"
20516(@value{GDBP})
20517-var-update *
20518^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
20519(@value{GDBP})
20520@end smallexample
20521
20522@subheading The @code{-var-update} Command
20523@findex -var-update
20524
20525@subsubheading Synopsis
20526
20527@smallexample
20528 -var-update @{@var{name} | "*"@}
20529@end smallexample
20530
20531Update the value of the variable object @var{name} by evaluating its
20532expression after fetching all the new values from memory or registers.
20533A @samp{*} causes all existing variable objects to be updated.
20534
20535
20536@node Annotations
20537@chapter @value{GDBN} Annotations
20538
086432e2
AC
20539This chapter describes annotations in @value{GDBN}. Annotations were
20540designed to interface @value{GDBN} to graphical user interfaces or other
20541similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
20542relatively high level.
20543
086432e2
AC
20544The annotation mechanism has largely been superseeded by @sc{gdb/mi}
20545(@pxref{GDB/MI}).
20546
922fbb7b
AC
20547@ignore
20548This is Edition @value{EDITION}, @value{DATE}.
20549@end ignore
20550
20551@menu
20552* Annotations Overview:: What annotations are; the general syntax.
20553* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
20554* Prompting:: Annotations marking @value{GDBN}'s need for input.
20555* Errors:: Annotations for error messages.
922fbb7b
AC
20556* Invalidation:: Some annotations describe things now invalid.
20557* Annotations for Running::
20558 Whether the program is running, how it stopped, etc.
20559* Source Annotations:: Annotations describing source code.
922fbb7b
AC
20560@end menu
20561
20562@node Annotations Overview
20563@section What is an Annotation?
20564@cindex annotations
20565
922fbb7b
AC
20566Annotations start with a newline character, two @samp{control-z}
20567characters, and the name of the annotation. If there is no additional
20568information associated with this annotation, the name of the annotation
20569is followed immediately by a newline. If there is additional
20570information, the name of the annotation is followed by a space, the
20571additional information, and a newline. The additional information
20572cannot contain newline characters.
20573
20574Any output not beginning with a newline and two @samp{control-z}
20575characters denotes literal output from @value{GDBN}. Currently there is
20576no need for @value{GDBN} to output a newline followed by two
20577@samp{control-z} characters, but if there was such a need, the
20578annotations could be extended with an @samp{escape} annotation which
20579means those three characters as output.
20580
086432e2
AC
20581The annotation @var{level}, which is specified using the
20582@option{--annotate} command line option (@pxref{Mode Options}), controls
20583how much information @value{GDBN} prints together with its prompt,
20584values of expressions, source lines, and other types of output. Level 0
20585is for no anntations, level 1 is for use when @value{GDBN} is run as a
20586subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
20587for programs that control @value{GDBN}, and level 2 annotations have
20588been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
20589Interface, annotate, GDB's Obsolete Annotations}).
20590
20591@table @code
20592@kindex set annotate
20593@item set annotate @var{level}
e09f16f9 20594The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 20595annotations to the specified @var{level}.
9c16f35a
EZ
20596
20597@item show annotate
20598@kindex show annotate
20599Show the current annotation level.
09d4efe1
EZ
20600@end table
20601
20602This chapter describes level 3 annotations.
086432e2 20603
922fbb7b
AC
20604A simple example of starting up @value{GDBN} with annotations is:
20605
20606@smallexample
086432e2
AC
20607$ @kbd{gdb --annotate=3}
20608GNU gdb 6.0
20609Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
20610GDB is free software, covered by the GNU General Public License,
20611and you are welcome to change it and/or distribute copies of it
20612under certain conditions.
20613Type "show copying" to see the conditions.
20614There is absolutely no warranty for GDB. Type "show warranty"
20615for details.
086432e2 20616This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
20617
20618^Z^Zpre-prompt
f7dc1244 20619(@value{GDBP})
922fbb7b 20620^Z^Zprompt
086432e2 20621@kbd{quit}
922fbb7b
AC
20622
20623^Z^Zpost-prompt
b383017d 20624$
922fbb7b
AC
20625@end smallexample
20626
20627Here @samp{quit} is input to @value{GDBN}; the rest is output from
20628@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
20629denotes a @samp{control-z} character) are annotations; the rest is
20630output from @value{GDBN}.
20631
20632@node Server Prefix
20633@section The Server Prefix
20634@cindex server prefix for annotations
20635
20636To issue a command to @value{GDBN} without affecting certain aspects of
20637the state which is seen by users, prefix it with @samp{server }. This
20638means that this command will not affect the command history, nor will it
20639affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
20640pressed on a line by itself.
20641
20642The server prefix does not affect the recording of values into the value
20643history; to print a value without recording it into the value history,
20644use the @code{output} command instead of the @code{print} command.
20645
922fbb7b
AC
20646@node Prompting
20647@section Annotation for @value{GDBN} Input
20648
20649@cindex annotations for prompts
20650When @value{GDBN} prompts for input, it annotates this fact so it is possible
20651to know when to send output, when the output from a given command is
20652over, etc.
20653
20654Different kinds of input each have a different @dfn{input type}. Each
20655input type has three annotations: a @code{pre-} annotation, which
20656denotes the beginning of any prompt which is being output, a plain
20657annotation, which denotes the end of the prompt, and then a @code{post-}
20658annotation which denotes the end of any echo which may (or may not) be
20659associated with the input. For example, the @code{prompt} input type
20660features the following annotations:
20661
20662@smallexample
20663^Z^Zpre-prompt
20664^Z^Zprompt
20665^Z^Zpost-prompt
20666@end smallexample
20667
20668The input types are
20669
20670@table @code
20671@findex pre-prompt
20672@findex prompt
20673@findex post-prompt
20674@item prompt
20675When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
20676
20677@findex pre-commands
20678@findex commands
20679@findex post-commands
20680@item commands
20681When @value{GDBN} prompts for a set of commands, like in the @code{commands}
20682command. The annotations are repeated for each command which is input.
20683
20684@findex pre-overload-choice
20685@findex overload-choice
20686@findex post-overload-choice
20687@item overload-choice
20688When @value{GDBN} wants the user to select between various overloaded functions.
20689
20690@findex pre-query
20691@findex query
20692@findex post-query
20693@item query
20694When @value{GDBN} wants the user to confirm a potentially dangerous operation.
20695
20696@findex pre-prompt-for-continue
20697@findex prompt-for-continue
20698@findex post-prompt-for-continue
20699@item prompt-for-continue
20700When @value{GDBN} is asking the user to press return to continue. Note: Don't
20701expect this to work well; instead use @code{set height 0} to disable
20702prompting. This is because the counting of lines is buggy in the
20703presence of annotations.
20704@end table
20705
20706@node Errors
20707@section Errors
20708@cindex annotations for errors, warnings and interrupts
20709
20710@findex quit
20711@smallexample
20712^Z^Zquit
20713@end smallexample
20714
20715This annotation occurs right before @value{GDBN} responds to an interrupt.
20716
20717@findex error
20718@smallexample
20719^Z^Zerror
20720@end smallexample
20721
20722This annotation occurs right before @value{GDBN} responds to an error.
20723
20724Quit and error annotations indicate that any annotations which @value{GDBN} was
20725in the middle of may end abruptly. For example, if a
20726@code{value-history-begin} annotation is followed by a @code{error}, one
20727cannot expect to receive the matching @code{value-history-end}. One
20728cannot expect not to receive it either, however; an error annotation
20729does not necessarily mean that @value{GDBN} is immediately returning all the way
20730to the top level.
20731
20732@findex error-begin
20733A quit or error annotation may be preceded by
20734
20735@smallexample
20736^Z^Zerror-begin
20737@end smallexample
20738
20739Any output between that and the quit or error annotation is the error
20740message.
20741
20742Warning messages are not yet annotated.
20743@c If we want to change that, need to fix warning(), type_error(),
20744@c range_error(), and possibly other places.
20745
922fbb7b
AC
20746@node Invalidation
20747@section Invalidation Notices
20748
20749@cindex annotations for invalidation messages
20750The following annotations say that certain pieces of state may have
20751changed.
20752
20753@table @code
20754@findex frames-invalid
20755@item ^Z^Zframes-invalid
20756
20757The frames (for example, output from the @code{backtrace} command) may
20758have changed.
20759
20760@findex breakpoints-invalid
20761@item ^Z^Zbreakpoints-invalid
20762
20763The breakpoints may have changed. For example, the user just added or
20764deleted a breakpoint.
20765@end table
20766
20767@node Annotations for Running
20768@section Running the Program
20769@cindex annotations for running programs
20770
20771@findex starting
20772@findex stopping
20773When the program starts executing due to a @value{GDBN} command such as
b383017d 20774@code{step} or @code{continue},
922fbb7b
AC
20775
20776@smallexample
20777^Z^Zstarting
20778@end smallexample
20779
b383017d 20780is output. When the program stops,
922fbb7b
AC
20781
20782@smallexample
20783^Z^Zstopped
20784@end smallexample
20785
20786is output. Before the @code{stopped} annotation, a variety of
20787annotations describe how the program stopped.
20788
20789@table @code
20790@findex exited
20791@item ^Z^Zexited @var{exit-status}
20792The program exited, and @var{exit-status} is the exit status (zero for
20793successful exit, otherwise nonzero).
20794
20795@findex signalled
20796@findex signal-name
20797@findex signal-name-end
20798@findex signal-string
20799@findex signal-string-end
20800@item ^Z^Zsignalled
20801The program exited with a signal. After the @code{^Z^Zsignalled}, the
20802annotation continues:
20803
20804@smallexample
20805@var{intro-text}
20806^Z^Zsignal-name
20807@var{name}
20808^Z^Zsignal-name-end
20809@var{middle-text}
20810^Z^Zsignal-string
20811@var{string}
20812^Z^Zsignal-string-end
20813@var{end-text}
20814@end smallexample
20815
20816@noindent
20817where @var{name} is the name of the signal, such as @code{SIGILL} or
20818@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
20819as @code{Illegal Instruction} or @code{Segmentation fault}.
20820@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
20821user's benefit and have no particular format.
20822
20823@findex signal
20824@item ^Z^Zsignal
20825The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
20826just saying that the program received the signal, not that it was
20827terminated with it.
20828
20829@findex breakpoint
20830@item ^Z^Zbreakpoint @var{number}
20831The program hit breakpoint number @var{number}.
20832
20833@findex watchpoint
20834@item ^Z^Zwatchpoint @var{number}
20835The program hit watchpoint number @var{number}.
20836@end table
20837
20838@node Source Annotations
20839@section Displaying Source
20840@cindex annotations for source display
20841
20842@findex source
20843The following annotation is used instead of displaying source code:
20844
20845@smallexample
20846^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
20847@end smallexample
20848
20849where @var{filename} is an absolute file name indicating which source
20850file, @var{line} is the line number within that file (where 1 is the
20851first line in the file), @var{character} is the character position
20852within the file (where 0 is the first character in the file) (for most
20853debug formats this will necessarily point to the beginning of a line),
20854@var{middle} is @samp{middle} if @var{addr} is in the middle of the
20855line, or @samp{beg} if @var{addr} is at the beginning of the line, and
20856@var{addr} is the address in the target program associated with the
20857source which is being displayed. @var{addr} is in the form @samp{0x}
20858followed by one or more lowercase hex digits (note that this does not
20859depend on the language).
20860
8e04817f
AC
20861@node GDB Bugs
20862@chapter Reporting Bugs in @value{GDBN}
20863@cindex bugs in @value{GDBN}
20864@cindex reporting bugs in @value{GDBN}
c906108c 20865
8e04817f 20866Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 20867
8e04817f
AC
20868Reporting a bug may help you by bringing a solution to your problem, or it
20869may not. But in any case the principal function of a bug report is to help
20870the entire community by making the next version of @value{GDBN} work better. Bug
20871reports are your contribution to the maintenance of @value{GDBN}.
c906108c 20872
8e04817f
AC
20873In order for a bug report to serve its purpose, you must include the
20874information that enables us to fix the bug.
c4555f82
SC
20875
20876@menu
8e04817f
AC
20877* Bug Criteria:: Have you found a bug?
20878* Bug Reporting:: How to report bugs
c4555f82
SC
20879@end menu
20880
8e04817f
AC
20881@node Bug Criteria
20882@section Have you found a bug?
20883@cindex bug criteria
c4555f82 20884
8e04817f 20885If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
20886
20887@itemize @bullet
8e04817f
AC
20888@cindex fatal signal
20889@cindex debugger crash
20890@cindex crash of debugger
c4555f82 20891@item
8e04817f
AC
20892If the debugger gets a fatal signal, for any input whatever, that is a
20893@value{GDBN} bug. Reliable debuggers never crash.
20894
20895@cindex error on valid input
20896@item
20897If @value{GDBN} produces an error message for valid input, that is a
20898bug. (Note that if you're cross debugging, the problem may also be
20899somewhere in the connection to the target.)
c4555f82 20900
8e04817f 20901@cindex invalid input
c4555f82 20902@item
8e04817f
AC
20903If @value{GDBN} does not produce an error message for invalid input,
20904that is a bug. However, you should note that your idea of
20905``invalid input'' might be our idea of ``an extension'' or ``support
20906for traditional practice''.
20907
20908@item
20909If you are an experienced user of debugging tools, your suggestions
20910for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
20911@end itemize
20912
8e04817f
AC
20913@node Bug Reporting
20914@section How to report bugs
20915@cindex bug reports
20916@cindex @value{GDBN} bugs, reporting
20917
20918A number of companies and individuals offer support for @sc{gnu} products.
20919If you obtained @value{GDBN} from a support organization, we recommend you
20920contact that organization first.
20921
20922You can find contact information for many support companies and
20923individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
20924distribution.
20925@c should add a web page ref...
20926
129188f6
AC
20927In any event, we also recommend that you submit bug reports for
20928@value{GDBN}. The prefered method is to submit them directly using
20929@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
20930page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
20931be used.
8e04817f
AC
20932
20933@strong{Do not send bug reports to @samp{info-gdb}, or to
20934@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
20935not want to receive bug reports. Those that do have arranged to receive
20936@samp{bug-gdb}.
20937
20938The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
20939serves as a repeater. The mailing list and the newsgroup carry exactly
20940the same messages. Often people think of posting bug reports to the
20941newsgroup instead of mailing them. This appears to work, but it has one
20942problem which can be crucial: a newsgroup posting often lacks a mail
20943path back to the sender. Thus, if we need to ask for more information,
20944we may be unable to reach you. For this reason, it is better to send
20945bug reports to the mailing list.
c4555f82 20946
8e04817f
AC
20947The fundamental principle of reporting bugs usefully is this:
20948@strong{report all the facts}. If you are not sure whether to state a
20949fact or leave it out, state it!
c4555f82 20950
8e04817f
AC
20951Often people omit facts because they think they know what causes the
20952problem and assume that some details do not matter. Thus, you might
20953assume that the name of the variable you use in an example does not matter.
20954Well, probably it does not, but one cannot be sure. Perhaps the bug is a
20955stray memory reference which happens to fetch from the location where that
20956name is stored in memory; perhaps, if the name were different, the contents
20957of that location would fool the debugger into doing the right thing despite
20958the bug. Play it safe and give a specific, complete example. That is the
20959easiest thing for you to do, and the most helpful.
c4555f82 20960
8e04817f
AC
20961Keep in mind that the purpose of a bug report is to enable us to fix the
20962bug. It may be that the bug has been reported previously, but neither
20963you nor we can know that unless your bug report is complete and
20964self-contained.
c4555f82 20965
8e04817f
AC
20966Sometimes people give a few sketchy facts and ask, ``Does this ring a
20967bell?'' Those bug reports are useless, and we urge everyone to
20968@emph{refuse to respond to them} except to chide the sender to report
20969bugs properly.
20970
20971To enable us to fix the bug, you should include all these things:
c4555f82
SC
20972
20973@itemize @bullet
20974@item
8e04817f
AC
20975The version of @value{GDBN}. @value{GDBN} announces it if you start
20976with no arguments; you can also print it at any time using @code{show
20977version}.
c4555f82 20978
8e04817f
AC
20979Without this, we will not know whether there is any point in looking for
20980the bug in the current version of @value{GDBN}.
c4555f82
SC
20981
20982@item
8e04817f
AC
20983The type of machine you are using, and the operating system name and
20984version number.
c4555f82
SC
20985
20986@item
8e04817f
AC
20987What compiler (and its version) was used to compile @value{GDBN}---e.g.
20988``@value{GCC}--2.8.1''.
c4555f82
SC
20989
20990@item
8e04817f
AC
20991What compiler (and its version) was used to compile the program you are
20992debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
20993C Compiler''. For GCC, you can say @code{gcc --version} to get this
20994information; for other compilers, see the documentation for those
20995compilers.
c4555f82 20996
8e04817f
AC
20997@item
20998The command arguments you gave the compiler to compile your example and
20999observe the bug. For example, did you use @samp{-O}? To guarantee
21000you will not omit something important, list them all. A copy of the
21001Makefile (or the output from make) is sufficient.
c4555f82 21002
8e04817f
AC
21003If we were to try to guess the arguments, we would probably guess wrong
21004and then we might not encounter the bug.
c4555f82 21005
8e04817f
AC
21006@item
21007A complete input script, and all necessary source files, that will
21008reproduce the bug.
c4555f82 21009
8e04817f
AC
21010@item
21011A description of what behavior you observe that you believe is
21012incorrect. For example, ``It gets a fatal signal.''
c4555f82 21013
8e04817f
AC
21014Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
21015will certainly notice it. But if the bug is incorrect output, we might
21016not notice unless it is glaringly wrong. You might as well not give us
21017a chance to make a mistake.
c4555f82 21018
8e04817f
AC
21019Even if the problem you experience is a fatal signal, you should still
21020say so explicitly. Suppose something strange is going on, such as, your
21021copy of @value{GDBN} is out of synch, or you have encountered a bug in
21022the C library on your system. (This has happened!) Your copy might
21023crash and ours would not. If you told us to expect a crash, then when
21024ours fails to crash, we would know that the bug was not happening for
21025us. If you had not told us to expect a crash, then we would not be able
21026to draw any conclusion from our observations.
c4555f82 21027
e0c07bf0
MC
21028@pindex script
21029@cindex recording a session script
21030To collect all this information, you can use a session recording program
21031such as @command{script}, which is available on many Unix systems.
21032Just run your @value{GDBN} session inside @command{script} and then
21033include the @file{typescript} file with your bug report.
21034
21035Another way to record a @value{GDBN} session is to run @value{GDBN}
21036inside Emacs and then save the entire buffer to a file.
21037
8e04817f
AC
21038@item
21039If you wish to suggest changes to the @value{GDBN} source, send us context
21040diffs. If you even discuss something in the @value{GDBN} source, refer to
21041it by context, not by line number.
c4555f82 21042
8e04817f
AC
21043The line numbers in our development sources will not match those in your
21044sources. Your line numbers would convey no useful information to us.
c4555f82 21045
8e04817f 21046@end itemize
c4555f82 21047
8e04817f 21048Here are some things that are not necessary:
c4555f82 21049
8e04817f
AC
21050@itemize @bullet
21051@item
21052A description of the envelope of the bug.
c4555f82 21053
8e04817f
AC
21054Often people who encounter a bug spend a lot of time investigating
21055which changes to the input file will make the bug go away and which
21056changes will not affect it.
c4555f82 21057
8e04817f
AC
21058This is often time consuming and not very useful, because the way we
21059will find the bug is by running a single example under the debugger
21060with breakpoints, not by pure deduction from a series of examples.
21061We recommend that you save your time for something else.
c4555f82 21062
8e04817f
AC
21063Of course, if you can find a simpler example to report @emph{instead}
21064of the original one, that is a convenience for us. Errors in the
21065output will be easier to spot, running under the debugger will take
21066less time, and so on.
c4555f82 21067
8e04817f
AC
21068However, simplification is not vital; if you do not want to do this,
21069report the bug anyway and send us the entire test case you used.
c4555f82 21070
8e04817f
AC
21071@item
21072A patch for the bug.
c4555f82 21073
8e04817f
AC
21074A patch for the bug does help us if it is a good one. But do not omit
21075the necessary information, such as the test case, on the assumption that
21076a patch is all we need. We might see problems with your patch and decide
21077to fix the problem another way, or we might not understand it at all.
c4555f82 21078
8e04817f
AC
21079Sometimes with a program as complicated as @value{GDBN} it is very hard to
21080construct an example that will make the program follow a certain path
21081through the code. If you do not send us the example, we will not be able
21082to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 21083
8e04817f
AC
21084And if we cannot understand what bug you are trying to fix, or why your
21085patch should be an improvement, we will not install it. A test case will
21086help us to understand.
c4555f82 21087
8e04817f
AC
21088@item
21089A guess about what the bug is or what it depends on.
c4555f82 21090
8e04817f
AC
21091Such guesses are usually wrong. Even we cannot guess right about such
21092things without first using the debugger to find the facts.
21093@end itemize
c4555f82 21094
8e04817f
AC
21095@c The readline documentation is distributed with the readline code
21096@c and consists of the two following files:
21097@c rluser.texinfo
21098@c inc-hist.texinfo
21099@c Use -I with makeinfo to point to the appropriate directory,
21100@c environment var TEXINPUTS with TeX.
21101@include rluser.texinfo
21102@include inc-hist.texinfo
c4555f82 21103
c4555f82 21104
8e04817f
AC
21105@node Formatting Documentation
21106@appendix Formatting Documentation
c4555f82 21107
8e04817f
AC
21108@cindex @value{GDBN} reference card
21109@cindex reference card
21110The @value{GDBN} 4 release includes an already-formatted reference card, ready
21111for printing with PostScript or Ghostscript, in the @file{gdb}
21112subdirectory of the main source directory@footnote{In
21113@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
21114release.}. If you can use PostScript or Ghostscript with your printer,
21115you can print the reference card immediately with @file{refcard.ps}.
c4555f82 21116
8e04817f
AC
21117The release also includes the source for the reference card. You
21118can format it, using @TeX{}, by typing:
c4555f82 21119
474c8240 21120@smallexample
8e04817f 21121make refcard.dvi
474c8240 21122@end smallexample
c4555f82 21123
8e04817f
AC
21124The @value{GDBN} reference card is designed to print in @dfn{landscape}
21125mode on US ``letter'' size paper;
21126that is, on a sheet 11 inches wide by 8.5 inches
21127high. You will need to specify this form of printing as an option to
21128your @sc{dvi} output program.
c4555f82 21129
8e04817f 21130@cindex documentation
c4555f82 21131
8e04817f
AC
21132All the documentation for @value{GDBN} comes as part of the machine-readable
21133distribution. The documentation is written in Texinfo format, which is
21134a documentation system that uses a single source file to produce both
21135on-line information and a printed manual. You can use one of the Info
21136formatting commands to create the on-line version of the documentation
21137and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 21138
8e04817f
AC
21139@value{GDBN} includes an already formatted copy of the on-line Info
21140version of this manual in the @file{gdb} subdirectory. The main Info
21141file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
21142subordinate files matching @samp{gdb.info*} in the same directory. If
21143necessary, you can print out these files, or read them with any editor;
21144but they are easier to read using the @code{info} subsystem in @sc{gnu}
21145Emacs or the standalone @code{info} program, available as part of the
21146@sc{gnu} Texinfo distribution.
c4555f82 21147
8e04817f
AC
21148If you want to format these Info files yourself, you need one of the
21149Info formatting programs, such as @code{texinfo-format-buffer} or
21150@code{makeinfo}.
c4555f82 21151
8e04817f
AC
21152If you have @code{makeinfo} installed, and are in the top level
21153@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
21154version @value{GDBVN}), you can make the Info file by typing:
c4555f82 21155
474c8240 21156@smallexample
8e04817f
AC
21157cd gdb
21158make gdb.info
474c8240 21159@end smallexample
c4555f82 21160
8e04817f
AC
21161If you want to typeset and print copies of this manual, you need @TeX{},
21162a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
21163Texinfo definitions file.
c4555f82 21164
8e04817f
AC
21165@TeX{} is a typesetting program; it does not print files directly, but
21166produces output files called @sc{dvi} files. To print a typeset
21167document, you need a program to print @sc{dvi} files. If your system
21168has @TeX{} installed, chances are it has such a program. The precise
21169command to use depends on your system; @kbd{lpr -d} is common; another
21170(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
21171require a file name without any extension or a @samp{.dvi} extension.
c4555f82 21172
8e04817f
AC
21173@TeX{} also requires a macro definitions file called
21174@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
21175written in Texinfo format. On its own, @TeX{} cannot either read or
21176typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
21177and is located in the @file{gdb-@var{version-number}/texinfo}
21178directory.
c4555f82 21179
8e04817f
AC
21180If you have @TeX{} and a @sc{dvi} printer program installed, you can
21181typeset and print this manual. First switch to the the @file{gdb}
21182subdirectory of the main source directory (for example, to
21183@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 21184
474c8240 21185@smallexample
8e04817f 21186make gdb.dvi
474c8240 21187@end smallexample
c4555f82 21188
8e04817f 21189Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 21190
8e04817f
AC
21191@node Installing GDB
21192@appendix Installing @value{GDBN}
21193@cindex configuring @value{GDBN}
21194@cindex installation
94e91d6d 21195@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 21196
8e04817f
AC
21197@value{GDBN} comes with a @code{configure} script that automates the process
21198of preparing @value{GDBN} for installation; you can then use @code{make} to
21199build the @code{gdb} program.
21200@iftex
21201@c irrelevant in info file; it's as current as the code it lives with.
21202@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
21203look at the @file{README} file in the sources; we may have improved the
21204installation procedures since publishing this manual.}
21205@end iftex
c4555f82 21206
8e04817f
AC
21207The @value{GDBN} distribution includes all the source code you need for
21208@value{GDBN} in a single directory, whose name is usually composed by
21209appending the version number to @samp{gdb}.
c4555f82 21210
8e04817f
AC
21211For example, the @value{GDBN} version @value{GDBVN} distribution is in the
21212@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 21213
8e04817f
AC
21214@table @code
21215@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
21216script for configuring @value{GDBN} and all its supporting libraries
c4555f82 21217
8e04817f
AC
21218@item gdb-@value{GDBVN}/gdb
21219the source specific to @value{GDBN} itself
c4555f82 21220
8e04817f
AC
21221@item gdb-@value{GDBVN}/bfd
21222source for the Binary File Descriptor library
c906108c 21223
8e04817f
AC
21224@item gdb-@value{GDBVN}/include
21225@sc{gnu} include files
c906108c 21226
8e04817f
AC
21227@item gdb-@value{GDBVN}/libiberty
21228source for the @samp{-liberty} free software library
c906108c 21229
8e04817f
AC
21230@item gdb-@value{GDBVN}/opcodes
21231source for the library of opcode tables and disassemblers
c906108c 21232
8e04817f
AC
21233@item gdb-@value{GDBVN}/readline
21234source for the @sc{gnu} command-line interface
c906108c 21235
8e04817f
AC
21236@item gdb-@value{GDBVN}/glob
21237source for the @sc{gnu} filename pattern-matching subroutine
c906108c 21238
8e04817f
AC
21239@item gdb-@value{GDBVN}/mmalloc
21240source for the @sc{gnu} memory-mapped malloc package
21241@end table
c906108c 21242
8e04817f
AC
21243The simplest way to configure and build @value{GDBN} is to run @code{configure}
21244from the @file{gdb-@var{version-number}} source directory, which in
21245this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 21246
8e04817f
AC
21247First switch to the @file{gdb-@var{version-number}} source directory
21248if you are not already in it; then run @code{configure}. Pass the
21249identifier for the platform on which @value{GDBN} will run as an
21250argument.
c906108c 21251
8e04817f 21252For example:
c906108c 21253
474c8240 21254@smallexample
8e04817f
AC
21255cd gdb-@value{GDBVN}
21256./configure @var{host}
21257make
474c8240 21258@end smallexample
c906108c 21259
8e04817f
AC
21260@noindent
21261where @var{host} is an identifier such as @samp{sun4} or
21262@samp{decstation}, that identifies the platform where @value{GDBN} will run.
21263(You can often leave off @var{host}; @code{configure} tries to guess the
21264correct value by examining your system.)
c906108c 21265
8e04817f
AC
21266Running @samp{configure @var{host}} and then running @code{make} builds the
21267@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
21268libraries, then @code{gdb} itself. The configured source files, and the
21269binaries, are left in the corresponding source directories.
c906108c 21270
8e04817f
AC
21271@need 750
21272@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
21273system does not recognize this automatically when you run a different
21274shell, you may need to run @code{sh} on it explicitly:
c906108c 21275
474c8240 21276@smallexample
8e04817f 21277sh configure @var{host}
474c8240 21278@end smallexample
c906108c 21279
8e04817f
AC
21280If you run @code{configure} from a directory that contains source
21281directories for multiple libraries or programs, such as the
21282@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
21283creates configuration files for every directory level underneath (unless
21284you tell it not to, with the @samp{--norecursion} option).
21285
94e91d6d
MC
21286You should run the @code{configure} script from the top directory in the
21287source tree, the @file{gdb-@var{version-number}} directory. If you run
21288@code{configure} from one of the subdirectories, you will configure only
21289that subdirectory. That is usually not what you want. In particular,
21290if you run the first @code{configure} from the @file{gdb} subdirectory
21291of the @file{gdb-@var{version-number}} directory, you will omit the
21292configuration of @file{bfd}, @file{readline}, and other sibling
21293directories of the @file{gdb} subdirectory. This leads to build errors
21294about missing include files such as @file{bfd/bfd.h}.
c906108c 21295
8e04817f
AC
21296You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
21297However, you should make sure that the shell on your path (named by
21298the @samp{SHELL} environment variable) is publicly readable. Remember
21299that @value{GDBN} uses the shell to start your program---some systems refuse to
21300let @value{GDBN} debug child processes whose programs are not readable.
c906108c 21301
8e04817f
AC
21302@menu
21303* Separate Objdir:: Compiling @value{GDBN} in another directory
21304* Config Names:: Specifying names for hosts and targets
21305* Configure Options:: Summary of options for configure
21306@end menu
c906108c 21307
8e04817f
AC
21308@node Separate Objdir
21309@section Compiling @value{GDBN} in another directory
c906108c 21310
8e04817f
AC
21311If you want to run @value{GDBN} versions for several host or target machines,
21312you need a different @code{gdb} compiled for each combination of
21313host and target. @code{configure} is designed to make this easy by
21314allowing you to generate each configuration in a separate subdirectory,
21315rather than in the source directory. If your @code{make} program
21316handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
21317@code{make} in each of these directories builds the @code{gdb}
21318program specified there.
c906108c 21319
8e04817f
AC
21320To build @code{gdb} in a separate directory, run @code{configure}
21321with the @samp{--srcdir} option to specify where to find the source.
21322(You also need to specify a path to find @code{configure}
21323itself from your working directory. If the path to @code{configure}
21324would be the same as the argument to @samp{--srcdir}, you can leave out
21325the @samp{--srcdir} option; it is assumed.)
c906108c 21326
8e04817f
AC
21327For example, with version @value{GDBVN}, you can build @value{GDBN} in a
21328separate directory for a Sun 4 like this:
c906108c 21329
474c8240 21330@smallexample
8e04817f
AC
21331@group
21332cd gdb-@value{GDBVN}
21333mkdir ../gdb-sun4
21334cd ../gdb-sun4
21335../gdb-@value{GDBVN}/configure sun4
21336make
21337@end group
474c8240 21338@end smallexample
c906108c 21339
8e04817f
AC
21340When @code{configure} builds a configuration using a remote source
21341directory, it creates a tree for the binaries with the same structure
21342(and using the same names) as the tree under the source directory. In
21343the example, you'd find the Sun 4 library @file{libiberty.a} in the
21344directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
21345@file{gdb-sun4/gdb}.
c906108c 21346
94e91d6d
MC
21347Make sure that your path to the @file{configure} script has just one
21348instance of @file{gdb} in it. If your path to @file{configure} looks
21349like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
21350one subdirectory of @value{GDBN}, not the whole package. This leads to
21351build errors about missing include files such as @file{bfd/bfd.h}.
21352
8e04817f
AC
21353One popular reason to build several @value{GDBN} configurations in separate
21354directories is to configure @value{GDBN} for cross-compiling (where
21355@value{GDBN} runs on one machine---the @dfn{host}---while debugging
21356programs that run on another machine---the @dfn{target}).
21357You specify a cross-debugging target by
21358giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 21359
8e04817f
AC
21360When you run @code{make} to build a program or library, you must run
21361it in a configured directory---whatever directory you were in when you
21362called @code{configure} (or one of its subdirectories).
c906108c 21363
8e04817f
AC
21364The @code{Makefile} that @code{configure} generates in each source
21365directory also runs recursively. If you type @code{make} in a source
21366directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
21367directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
21368will build all the required libraries, and then build GDB.
c906108c 21369
8e04817f
AC
21370When you have multiple hosts or targets configured in separate
21371directories, you can run @code{make} on them in parallel (for example,
21372if they are NFS-mounted on each of the hosts); they will not interfere
21373with each other.
c906108c 21374
8e04817f
AC
21375@node Config Names
21376@section Specifying names for hosts and targets
c906108c 21377
8e04817f
AC
21378The specifications used for hosts and targets in the @code{configure}
21379script are based on a three-part naming scheme, but some short predefined
21380aliases are also supported. The full naming scheme encodes three pieces
21381of information in the following pattern:
c906108c 21382
474c8240 21383@smallexample
8e04817f 21384@var{architecture}-@var{vendor}-@var{os}
474c8240 21385@end smallexample
c906108c 21386
8e04817f
AC
21387For example, you can use the alias @code{sun4} as a @var{host} argument,
21388or as the value for @var{target} in a @code{--target=@var{target}}
21389option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 21390
8e04817f
AC
21391The @code{configure} script accompanying @value{GDBN} does not provide
21392any query facility to list all supported host and target names or
21393aliases. @code{configure} calls the Bourne shell script
21394@code{config.sub} to map abbreviations to full names; you can read the
21395script, if you wish, or you can use it to test your guesses on
21396abbreviations---for example:
c906108c 21397
8e04817f
AC
21398@smallexample
21399% sh config.sub i386-linux
21400i386-pc-linux-gnu
21401% sh config.sub alpha-linux
21402alpha-unknown-linux-gnu
21403% sh config.sub hp9k700
21404hppa1.1-hp-hpux
21405% sh config.sub sun4
21406sparc-sun-sunos4.1.1
21407% sh config.sub sun3
21408m68k-sun-sunos4.1.1
21409% sh config.sub i986v
21410Invalid configuration `i986v': machine `i986v' not recognized
21411@end smallexample
c906108c 21412
8e04817f
AC
21413@noindent
21414@code{config.sub} is also distributed in the @value{GDBN} source
21415directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 21416
8e04817f
AC
21417@node Configure Options
21418@section @code{configure} options
c906108c 21419
8e04817f
AC
21420Here is a summary of the @code{configure} options and arguments that
21421are most often useful for building @value{GDBN}. @code{configure} also has
21422several other options not listed here. @inforef{What Configure
21423Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 21424
474c8240 21425@smallexample
8e04817f
AC
21426configure @r{[}--help@r{]}
21427 @r{[}--prefix=@var{dir}@r{]}
21428 @r{[}--exec-prefix=@var{dir}@r{]}
21429 @r{[}--srcdir=@var{dirname}@r{]}
21430 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
21431 @r{[}--target=@var{target}@r{]}
21432 @var{host}
474c8240 21433@end smallexample
c906108c 21434
8e04817f
AC
21435@noindent
21436You may introduce options with a single @samp{-} rather than
21437@samp{--} if you prefer; but you may abbreviate option names if you use
21438@samp{--}.
c906108c 21439
8e04817f
AC
21440@table @code
21441@item --help
21442Display a quick summary of how to invoke @code{configure}.
c906108c 21443
8e04817f
AC
21444@item --prefix=@var{dir}
21445Configure the source to install programs and files under directory
21446@file{@var{dir}}.
c906108c 21447
8e04817f
AC
21448@item --exec-prefix=@var{dir}
21449Configure the source to install programs under directory
21450@file{@var{dir}}.
c906108c 21451
8e04817f
AC
21452@c avoid splitting the warning from the explanation:
21453@need 2000
21454@item --srcdir=@var{dirname}
21455@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
21456@code{make} that implements the @code{VPATH} feature.}@*
21457Use this option to make configurations in directories separate from the
21458@value{GDBN} source directories. Among other things, you can use this to
21459build (or maintain) several configurations simultaneously, in separate
21460directories. @code{configure} writes configuration specific files in
21461the current directory, but arranges for them to use the source in the
21462directory @var{dirname}. @code{configure} creates directories under
21463the working directory in parallel to the source directories below
21464@var{dirname}.
c906108c 21465
8e04817f
AC
21466@item --norecursion
21467Configure only the directory level where @code{configure} is executed; do not
21468propagate configuration to subdirectories.
c906108c 21469
8e04817f
AC
21470@item --target=@var{target}
21471Configure @value{GDBN} for cross-debugging programs running on the specified
21472@var{target}. Without this option, @value{GDBN} is configured to debug
21473programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 21474
8e04817f 21475There is no convenient way to generate a list of all available targets.
c906108c 21476
8e04817f
AC
21477@item @var{host} @dots{}
21478Configure @value{GDBN} to run on the specified @var{host}.
c906108c 21479
8e04817f
AC
21480There is no convenient way to generate a list of all available hosts.
21481@end table
c906108c 21482
8e04817f
AC
21483There are many other options available as well, but they are generally
21484needed for special purposes only.
c906108c 21485
8e04817f
AC
21486@node Maintenance Commands
21487@appendix Maintenance Commands
21488@cindex maintenance commands
21489@cindex internal commands
c906108c 21490
8e04817f 21491In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
21492includes a number of commands intended for @value{GDBN} developers,
21493that are not documented elsewhere in this manual. These commands are
da316a69
EZ
21494provided here for reference. (For commands that turn on debugging
21495messages, see @ref{Debugging Output}.)
c906108c 21496
8e04817f 21497@table @code
09d4efe1
EZ
21498@kindex maint agent
21499@item maint agent @var{expression}
21500Translate the given @var{expression} into remote agent bytecodes.
21501This command is useful for debugging the Agent Expression mechanism
21502(@pxref{Agent Expressions}).
21503
8e04817f
AC
21504@kindex maint info breakpoints
21505@item @anchor{maint info breakpoints}maint info breakpoints
21506Using the same format as @samp{info breakpoints}, display both the
21507breakpoints you've set explicitly, and those @value{GDBN} is using for
21508internal purposes. Internal breakpoints are shown with negative
21509breakpoint numbers. The type column identifies what kind of breakpoint
21510is shown:
c906108c 21511
8e04817f
AC
21512@table @code
21513@item breakpoint
21514Normal, explicitly set breakpoint.
c906108c 21515
8e04817f
AC
21516@item watchpoint
21517Normal, explicitly set watchpoint.
c906108c 21518
8e04817f
AC
21519@item longjmp
21520Internal breakpoint, used to handle correctly stepping through
21521@code{longjmp} calls.
c906108c 21522
8e04817f
AC
21523@item longjmp resume
21524Internal breakpoint at the target of a @code{longjmp}.
c906108c 21525
8e04817f
AC
21526@item until
21527Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 21528
8e04817f
AC
21529@item finish
21530Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 21531
8e04817f
AC
21532@item shlib events
21533Shared library events.
c906108c 21534
8e04817f 21535@end table
c906108c 21536
09d4efe1
EZ
21537@kindex maint check-symtabs
21538@item maint check-symtabs
21539Check the consistency of psymtabs and symtabs.
21540
21541@kindex maint cplus first_component
21542@item maint cplus first_component @var{name}
21543Print the first C@t{++} class/namespace component of @var{name}.
21544
21545@kindex maint cplus namespace
21546@item maint cplus namespace
21547Print the list of possible C@t{++} namespaces.
21548
21549@kindex maint demangle
21550@item maint demangle @var{name}
21551Demangle a C@t{++} or Objective-C manled @var{name}.
21552
21553@kindex maint deprecate
21554@kindex maint undeprecate
21555@cindex deprecated commands
21556@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
21557@itemx maint undeprecate @var{command}
21558Deprecate or undeprecate the named @var{command}. Deprecated commands
21559cause @value{GDBN} to issue a warning when you use them. The optional
21560argument @var{replacement} says which newer command should be used in
21561favor of the deprecated one; if it is given, @value{GDBN} will mention
21562the replacement as part of the warning.
21563
21564@kindex maint dump-me
21565@item maint dump-me
721c2651 21566@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 21567Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
21568This is supported only on systems which support aborting a program
21569with the @code{SIGQUIT} signal.
09d4efe1 21570
8d30a00d
AC
21571@kindex maint internal-error
21572@kindex maint internal-warning
09d4efe1
EZ
21573@item maint internal-error @r{[}@var{message-text}@r{]}
21574@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
21575Cause @value{GDBN} to call the internal function @code{internal_error}
21576or @code{internal_warning} and hence behave as though an internal error
21577or internal warning has been detected. In addition to reporting the
21578internal problem, these functions give the user the opportunity to
21579either quit @value{GDBN} or create a core file of the current
21580@value{GDBN} session.
21581
09d4efe1
EZ
21582These commands take an optional parameter @var{message-text} that is
21583used as the text of the error or warning message.
21584
21585Here's an example of using @code{indernal-error}:
21586
8d30a00d 21587@smallexample
f7dc1244 21588(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
21589@dots{}/maint.c:121: internal-error: testing, 1, 2
21590A problem internal to GDB has been detected. Further
21591debugging may prove unreliable.
21592Quit this debugging session? (y or n) @kbd{n}
21593Create a core file? (y or n) @kbd{n}
f7dc1244 21594(@value{GDBP})
8d30a00d
AC
21595@end smallexample
21596
09d4efe1
EZ
21597@kindex maint packet
21598@item maint packet @var{text}
21599If @value{GDBN} is talking to an inferior via the serial protocol,
21600then this command sends the string @var{text} to the inferior, and
21601displays the response packet. @value{GDBN} supplies the initial
21602@samp{$} character, the terminating @samp{#} character, and the
21603checksum.
21604
21605@kindex maint print architecture
21606@item maint print architecture @r{[}@var{file}@r{]}
21607Print the entire architecture configuration. The optional argument
21608@var{file} names the file where the output goes.
8d30a00d 21609
00905d52
AC
21610@kindex maint print dummy-frames
21611@item maint print dummy-frames
00905d52
AC
21612Prints the contents of @value{GDBN}'s internal dummy-frame stack.
21613
21614@smallexample
f7dc1244 21615(@value{GDBP}) @kbd{b add}
00905d52 21616@dots{}
f7dc1244 21617(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
21618Breakpoint 2, add (a=2, b=3) at @dots{}
2161958 return (a + b);
21620The program being debugged stopped while in a function called from GDB.
21621@dots{}
f7dc1244 21622(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
216230x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
21624 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
21625 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 21626(@value{GDBP})
00905d52
AC
21627@end smallexample
21628
21629Takes an optional file parameter.
21630
0680b120
AC
21631@kindex maint print registers
21632@kindex maint print raw-registers
21633@kindex maint print cooked-registers
617073a9 21634@kindex maint print register-groups
09d4efe1
EZ
21635@item maint print registers @r{[}@var{file}@r{]}
21636@itemx maint print raw-registers @r{[}@var{file}@r{]}
21637@itemx maint print cooked-registers @r{[}@var{file}@r{]}
21638@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
21639Print @value{GDBN}'s internal register data structures.
21640
617073a9
AC
21641The command @code{maint print raw-registers} includes the contents of
21642the raw register cache; the command @code{maint print cooked-registers}
21643includes the (cooked) value of all registers; and the command
21644@code{maint print register-groups} includes the groups that each
21645register is a member of. @xref{Registers,, Registers, gdbint,
21646@value{GDBN} Internals}.
0680b120 21647
09d4efe1
EZ
21648These commands take an optional parameter, a file name to which to
21649write the information.
0680b120 21650
617073a9 21651@kindex maint print reggroups
09d4efe1
EZ
21652@item maint print reggroups @r{[}@var{file}@r{]}
21653Print @value{GDBN}'s internal register group data structures. The
21654optional argument @var{file} tells to what file to write the
21655information.
617073a9 21656
09d4efe1 21657The register groups info looks like this:
617073a9
AC
21658
21659@smallexample
f7dc1244 21660(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
21661 Group Type
21662 general user
21663 float user
21664 all user
21665 vector user
21666 system user
21667 save internal
21668 restore internal
617073a9
AC
21669@end smallexample
21670
09d4efe1
EZ
21671@kindex flushregs
21672@item flushregs
21673This command forces @value{GDBN} to flush its internal register cache.
21674
21675@kindex maint print objfiles
21676@cindex info for known object files
21677@item maint print objfiles
21678Print a dump of all known object files. For each object file, this
21679command prints its name, address in memory, and all of its psymtabs
21680and symtabs.
21681
21682@kindex maint print statistics
21683@cindex bcache statistics
21684@item maint print statistics
21685This command prints, for each object file in the program, various data
21686about that object file followed by the byte cache (@dfn{bcache})
21687statistics for the object file. The objfile data includes the number
21688of minimal, partical, full, and stabs symbols, the number of types
21689defined by the objfile, the number of as yet unexpanded psym tables,
21690the number of line tables and string tables, and the amount of memory
21691used by the various tables. The bcache statistics include the counts,
21692sizes, and counts of duplicates of all and unique objects, max,
21693average, and median entry size, total memory used and its overhead and
21694savings, and various measures of the hash table size and chain
21695lengths.
21696
21697@kindex maint print type
21698@cindex type chain of a data type
21699@item maint print type @var{expr}
21700Print the type chain for a type specified by @var{expr}. The argument
21701can be either a type name or a symbol. If it is a symbol, the type of
21702that symbol is described. The type chain produced by this command is
21703a recursive definition of the data type as stored in @value{GDBN}'s
21704data structures, including its flags and contained types.
21705
21706@kindex maint set dwarf2 max-cache-age
21707@kindex maint show dwarf2 max-cache-age
21708@item maint set dwarf2 max-cache-age
21709@itemx maint show dwarf2 max-cache-age
21710Control the DWARF 2 compilation unit cache.
21711
21712@cindex DWARF 2 compilation units cache
21713In object files with inter-compilation-unit references, such as those
21714produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
21715reader needs to frequently refer to previously read compilation units.
21716This setting controls how long a compilation unit will remain in the
21717cache if it is not referenced. A higher limit means that cached
21718compilation units will be stored in memory longer, and more total
21719memory will be used. Setting it to zero disables caching, which will
21720slow down @value{GDBN} startup, but reduce memory consumption.
21721
e7ba9c65
DJ
21722@kindex maint set profile
21723@kindex maint show profile
21724@cindex profiling GDB
21725@item maint set profile
21726@itemx maint show profile
21727Control profiling of @value{GDBN}.
21728
21729Profiling will be disabled until you use the @samp{maint set profile}
21730command to enable it. When you enable profiling, the system will begin
21731collecting timing and execution count data; when you disable profiling or
21732exit @value{GDBN}, the results will be written to a log file. Remember that
21733if you use profiling, @value{GDBN} will overwrite the profiling log file
21734(often called @file{gmon.out}). If you have a record of important profiling
21735data in a @file{gmon.out} file, be sure to move it to a safe location.
21736
21737Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 21738compiled with the @samp{-pg} compiler option.
e7ba9c65 21739
09d4efe1
EZ
21740@kindex maint show-debug-regs
21741@cindex x86 hardware debug registers
21742@item maint show-debug-regs
21743Control whether to show variables that mirror the x86 hardware debug
21744registers. Use @code{ON} to enable, @code{OFF} to disable. If
21745enabled, the debug registers values are shown when GDB inserts or
21746removes a hardware breakpoint or watchpoint, and when the inferior
21747triggers a hardware-assisted breakpoint or watchpoint.
21748
21749@kindex maint space
21750@cindex memory used by commands
21751@item maint space
21752Control whether to display memory usage for each command. If set to a
21753nonzero value, @value{GDBN} will display how much memory each command
21754took, following the command's own output. This can also be requested
21755by invoking @value{GDBN} with the @option{--statistics} command-line
21756switch (@pxref{Mode Options}).
21757
21758@kindex maint time
21759@cindex time of command execution
21760@item maint time
21761Control whether to display the execution time for each command. If
21762set to a nonzero value, @value{GDBN} will display how much time it
21763took to execute each command, following the command's own output.
21764This can also be requested by invoking @value{GDBN} with the
21765@option{--statistics} command-line switch (@pxref{Mode Options}).
21766
21767@kindex maint translate-address
21768@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
21769Find the symbol stored at the location specified by the address
21770@var{addr} and an optional section name @var{section}. If found,
21771@value{GDBN} prints the name of the closest symbol and an offset from
21772the symbol's location to the specified address. This is similar to
21773the @code{info address} command (@pxref{Symbols}), except that this
21774command also allows to find symbols in other sections.
ae038cb0 21775
8e04817f 21776@end table
c906108c 21777
9c16f35a
EZ
21778The following command is useful for non-interactive invocations of
21779@value{GDBN}, such as in the test suite.
21780
21781@table @code
21782@item set watchdog @var{nsec}
21783@kindex set watchdog
21784@cindex watchdog timer
21785@cindex timeout for commands
21786Set the maximum number of seconds @value{GDBN} will wait for the
21787target operation to finish. If this time expires, @value{GDBN}
21788reports and error and the command is aborted.
21789
21790@item show watchdog
21791Show the current setting of the target wait timeout.
21792@end table
c906108c 21793
e0ce93ac 21794@node Remote Protocol
8e04817f 21795@appendix @value{GDBN} Remote Serial Protocol
c906108c 21796
ee2d5c50
AC
21797@menu
21798* Overview::
21799* Packets::
21800* Stop Reply Packets::
21801* General Query Packets::
21802* Register Packet Format::
21803* Examples::
0ce1b118 21804* File-I/O remote protocol extension::
ee2d5c50
AC
21805@end menu
21806
21807@node Overview
21808@section Overview
21809
8e04817f
AC
21810There may be occasions when you need to know something about the
21811protocol---for example, if there is only one serial port to your target
21812machine, you might want your program to do something special if it
21813recognizes a packet meant for @value{GDBN}.
c906108c 21814
d2c6833e 21815In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 21816transmitted and received data respectfully.
c906108c 21817
8e04817f
AC
21818@cindex protocol, @value{GDBN} remote serial
21819@cindex serial protocol, @value{GDBN} remote
21820@cindex remote serial protocol
21821All @value{GDBN} commands and responses (other than acknowledgments) are
21822sent as a @var{packet}. A @var{packet} is introduced with the character
21823@samp{$}, the actual @var{packet-data}, and the terminating character
21824@samp{#} followed by a two-digit @var{checksum}:
c906108c 21825
474c8240 21826@smallexample
8e04817f 21827@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 21828@end smallexample
8e04817f 21829@noindent
c906108c 21830
8e04817f
AC
21831@cindex checksum, for @value{GDBN} remote
21832@noindent
21833The two-digit @var{checksum} is computed as the modulo 256 sum of all
21834characters between the leading @samp{$} and the trailing @samp{#} (an
21835eight bit unsigned checksum).
c906108c 21836
8e04817f
AC
21837Implementors should note that prior to @value{GDBN} 5.0 the protocol
21838specification also included an optional two-digit @var{sequence-id}:
c906108c 21839
474c8240 21840@smallexample
8e04817f 21841@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 21842@end smallexample
c906108c 21843
8e04817f
AC
21844@cindex sequence-id, for @value{GDBN} remote
21845@noindent
21846That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
21847has never output @var{sequence-id}s. Stubs that handle packets added
21848since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 21849
8e04817f
AC
21850@cindex acknowledgment, for @value{GDBN} remote
21851When either the host or the target machine receives a packet, the first
21852response expected is an acknowledgment: either @samp{+} (to indicate
21853the package was received correctly) or @samp{-} (to request
21854retransmission):
c906108c 21855
474c8240 21856@smallexample
d2c6833e
AC
21857-> @code{$}@var{packet-data}@code{#}@var{checksum}
21858<- @code{+}
474c8240 21859@end smallexample
8e04817f 21860@noindent
53a5351d 21861
8e04817f
AC
21862The host (@value{GDBN}) sends @var{command}s, and the target (the
21863debugging stub incorporated in your program) sends a @var{response}. In
21864the case of step and continue @var{command}s, the response is only sent
21865when the operation has completed (the target has again stopped).
c906108c 21866
8e04817f
AC
21867@var{packet-data} consists of a sequence of characters with the
21868exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
21869exceptions).
c906108c 21870
8e04817f 21871Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 21872@cindex remote protocol, field separator
8e04817f 21873@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 21874@sc{hex} with leading zeros suppressed.
c906108c 21875
8e04817f
AC
21876Implementors should note that prior to @value{GDBN} 5.0, the character
21877@samp{:} could not appear as the third character in a packet (as it
21878would potentially conflict with the @var{sequence-id}).
c906108c 21879
8e04817f
AC
21880Response @var{data} can be run-length encoded to save space. A @samp{*}
21881means that the next character is an @sc{ascii} encoding giving a repeat count
21882which stands for that many repetitions of the character preceding the
21883@samp{*}. The encoding is @code{n+29}, yielding a printable character
21884where @code{n >=3} (which is where rle starts to win). The printable
21885characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
21886value greater than 126 should not be used.
c906108c 21887
8e04817f 21888So:
474c8240 21889@smallexample
8e04817f 21890"@code{0* }"
474c8240 21891@end smallexample
8e04817f
AC
21892@noindent
21893means the same as "0000".
c906108c 21894
8e04817f
AC
21895The error response returned for some packets includes a two character
21896error number. That number is not well defined.
c906108c 21897
8e04817f
AC
21898For any @var{command} not supported by the stub, an empty response
21899(@samp{$#00}) should be returned. That way it is possible to extend the
21900protocol. A newer @value{GDBN} can tell if a packet is supported based
21901on that response.
c906108c 21902
b383017d
RM
21903A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
21904@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 21905optional.
c906108c 21906
ee2d5c50
AC
21907@node Packets
21908@section Packets
21909
21910The following table provides a complete list of all currently defined
21911@var{command}s and their corresponding response @var{data}.
9c16f35a
EZ
21912@xref{File-I/O remote protocol extension}, for details about the File
21913I/O extension of the remote protocol.
ee2d5c50
AC
21914
21915@table @r
21916
21917@item @code{!} --- extended mode
21918@cindex @code{!} packet
21919
8e04817f
AC
21920Enable extended mode. In extended mode, the remote server is made
21921persistent. The @samp{R} packet is used to restart the program being
21922debugged.
ee2d5c50
AC
21923
21924Reply:
21925@table @samp
21926@item OK
8e04817f 21927The remote target both supports and has enabled extended mode.
ee2d5c50 21928@end table
c906108c 21929
ee2d5c50
AC
21930@item @code{?} --- last signal
21931@cindex @code{?} packet
c906108c 21932
ee2d5c50
AC
21933Indicate the reason the target halted. The reply is the same as for
21934step and continue.
c906108c 21935
ee2d5c50
AC
21936Reply:
21937@xref{Stop Reply Packets}, for the reply specifications.
21938
21939@item @code{a} --- reserved
21940
21941Reserved for future use.
21942
21943@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
21944@cindex @code{A} packet
c906108c 21945
8e04817f
AC
21946Initialized @samp{argv[]} array passed into program. @var{arglen}
21947specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
21948See @code{gdbserver} for more details.
21949
21950Reply:
21951@table @samp
21952@item OK
21953@item E@var{NN}
21954@end table
21955
21956@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
21957@cindex @code{b} packet
21958
21959Change the serial line speed to @var{baud}.
21960
21961JTC: @emph{When does the transport layer state change? When it's
21962received, or after the ACK is transmitted. In either case, there are
21963problems if the command or the acknowledgment packet is dropped.}
21964
21965Stan: @emph{If people really wanted to add something like this, and get
21966it working for the first time, they ought to modify ser-unix.c to send
21967some kind of out-of-band message to a specially-setup stub and have the
21968switch happen "in between" packets, so that from remote protocol's point
21969of view, nothing actually happened.}
21970
21971@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
21972@cindex @code{B} packet
21973
8e04817f 21974Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
21975breakpoint at @var{addr}.
21976
21977This packet has been replaced by the @samp{Z} and @samp{z} packets
21978(@pxref{insert breakpoint or watchpoint packet}).
c906108c 21979
ee2d5c50
AC
21980@item @code{c}@var{addr} --- continue
21981@cindex @code{c} packet
21982
21983@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 21984current address.
c906108c 21985
ee2d5c50
AC
21986Reply:
21987@xref{Stop Reply Packets}, for the reply specifications.
21988
21989@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
21990@cindex @code{C} packet
21991
8e04817f
AC
21992Continue with signal @var{sig} (hex signal number). If
21993@code{;}@var{addr} is omitted, resume at same address.
c906108c 21994
ee2d5c50
AC
21995Reply:
21996@xref{Stop Reply Packets}, for the reply specifications.
c906108c 21997
ee2d5c50
AC
21998@item @code{d} --- toggle debug @strong{(deprecated)}
21999@cindex @code{d} packet
22000
22001Toggle debug flag.
22002
22003@item @code{D} --- detach
22004@cindex @code{D} packet
22005
22006Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 22007before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
22008
22009Reply:
22010@table @samp
22011@item @emph{no response}
8e04817f 22012@value{GDBN} does not check for any response after sending this packet.
ee2d5c50 22013@end table
c906108c 22014
ee2d5c50 22015@item @code{e} --- reserved
c906108c 22016
ee2d5c50 22017Reserved for future use.
c906108c 22018
ee2d5c50 22019@item @code{E} --- reserved
c906108c 22020
ee2d5c50 22021Reserved for future use.
c906108c 22022
ee2d5c50
AC
22023@item @code{f} --- reserved
22024
22025Reserved for future use.
22026
0ce1b118
CV
22027@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
22028@cindex @code{F} packet
ee2d5c50 22029
0ce1b118
CV
22030This packet is send by @value{GDBN} as reply to a @code{F} request packet
22031sent by the target. This is part of the File-I/O protocol extension.
22032@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
22033
22034@item @code{g} --- read registers
22035@anchor{read registers packet}
22036@cindex @code{g} packet
22037
22038Read general registers.
22039
22040Reply:
22041@table @samp
22042@item @var{XX@dots{}}
8e04817f
AC
22043Each byte of register data is described by two hex digits. The bytes
22044with the register are transmitted in target byte order. The size of
22045each register and their position within the @samp{g} @var{packet} are
12c266ea
AC
22046determined by the @value{GDBN} internal macros
22047@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
22048specification of several standard @code{g} packets is specified below.
ee2d5c50
AC
22049@item E@var{NN}
22050for an error.
22051@end table
c906108c 22052
ee2d5c50
AC
22053@item @code{G}@var{XX@dots{}} --- write regs
22054@cindex @code{G} packet
c906108c 22055
ee2d5c50
AC
22056@xref{read registers packet}, for a description of the @var{XX@dots{}}
22057data.
22058
22059Reply:
22060@table @samp
22061@item OK
22062for success
22063@item E@var{NN}
22064for an error
22065@end table
22066
22067@item @code{h} --- reserved
22068
22069Reserved for future use.
22070
b383017d 22071@item @code{H}@var{c}@var{t@dots{}} --- set thread
ee2d5c50 22072@cindex @code{H} packet
c906108c 22073
8e04817f 22074Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
22075@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
22076should be @samp{c} for step and continue operations, @samp{g} for other
22077operations. The thread designator @var{t@dots{}} may be -1, meaning all
22078the threads, a thread number, or zero which means pick any thread.
22079
22080Reply:
22081@table @samp
22082@item OK
22083for success
22084@item E@var{NN}
22085for an error
22086@end table
c906108c 22087
8e04817f
AC
22088@c FIXME: JTC:
22089@c 'H': How restrictive (or permissive) is the thread model. If a
22090@c thread is selected and stopped, are other threads allowed
22091@c to continue to execute? As I mentioned above, I think the
22092@c semantics of each command when a thread is selected must be
22093@c described. For example:
22094@c
22095@c 'g': If the stub supports threads and a specific thread is
22096@c selected, returns the register block from that thread;
22097@c otherwise returns current registers.
22098@c
22099@c 'G' If the stub supports threads and a specific thread is
22100@c selected, sets the registers of the register block of
22101@c that thread; otherwise sets current registers.
c906108c 22102
ee2d5c50
AC
22103@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
22104@anchor{cycle step packet}
22105@cindex @code{i} packet
22106
8e04817f
AC
22107Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
22108present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
22109step starting at that address.
c906108c 22110
ee2d5c50
AC
22111@item @code{I} --- signal then cycle step @strong{(reserved)}
22112@cindex @code{I} packet
22113
22114@xref{step with signal packet}. @xref{cycle step packet}.
22115
22116@item @code{j} --- reserved
22117
22118Reserved for future use.
22119
22120@item @code{J} --- reserved
c906108c 22121
ee2d5c50 22122Reserved for future use.
c906108c 22123
ee2d5c50
AC
22124@item @code{k} --- kill request
22125@cindex @code{k} packet
c906108c 22126
ac282366 22127FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
22128thread context has been selected (i.e.@: does 'k' kill only that
22129thread?)}.
c906108c 22130
ee2d5c50 22131@item @code{K} --- reserved
c906108c 22132
ee2d5c50
AC
22133Reserved for future use.
22134
22135@item @code{l} --- reserved
22136
22137Reserved for future use.
22138
22139@item @code{L} --- reserved
22140
22141Reserved for future use.
22142
22143@item @code{m}@var{addr}@code{,}@var{length} --- read memory
22144@cindex @code{m} packet
c906108c 22145
8e04817f 22146Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 22147Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 22148assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 22149transfer mechanism is needed.}
c906108c 22150
ee2d5c50
AC
22151Reply:
22152@table @samp
22153@item @var{XX@dots{}}
22154@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
22155to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 22156that sized memory transfers are assumed using word aligned
ee2d5c50
AC
22157accesses. FIXME: @emph{A word aligned memory transfer mechanism is
22158needed.}
22159@item E@var{NN}
22160@var{NN} is errno
22161@end table
22162
22163@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
22164@cindex @code{M} packet
22165
8e04817f 22166Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
22167@var{XX@dots{}} is the data.
22168
22169Reply:
22170@table @samp
22171@item OK
22172for success
22173@item E@var{NN}
8e04817f
AC
22174for an error (this includes the case where only part of the data was
22175written).
ee2d5c50 22176@end table
c906108c 22177
ee2d5c50 22178@item @code{n} --- reserved
c906108c 22179
ee2d5c50 22180Reserved for future use.
c906108c 22181
ee2d5c50 22182@item @code{N} --- reserved
c906108c 22183
ee2d5c50 22184Reserved for future use.
c906108c 22185
ee2d5c50
AC
22186@item @code{o} --- reserved
22187
22188Reserved for future use.
22189
22190@item @code{O} --- reserved
22191
2e868123 22192@item @code{p}@var{hex number of register} --- read register packet
ee2d5c50
AC
22193@cindex @code{p} packet
22194
2e868123
AC
22195@xref{read registers packet}, for a description of how the returned
22196register value is encoded.
ee2d5c50
AC
22197
22198Reply:
22199@table @samp
2e868123
AC
22200@item @var{XX@dots{}}
22201the register's value
22202@item E@var{NN}
22203for an error
22204@item
22205Indicating an unrecognized @var{query}.
ee2d5c50
AC
22206@end table
22207
22208@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
22209@anchor{write register packet}
22210@cindex @code{P} packet
22211
22212Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 22213digits for each byte in the register (target byte order).
c906108c 22214
ee2d5c50
AC
22215Reply:
22216@table @samp
22217@item OK
22218for success
22219@item E@var{NN}
22220for an error
22221@end table
22222
22223@item @code{q}@var{query} --- general query
22224@anchor{general query packet}
22225@cindex @code{q} packet
22226
22227Request info about @var{query}. In general @value{GDBN} queries have a
22228leading upper case letter. Custom vendor queries should use a company
22229prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
22230be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
22231that they match the full @var{query} name.
22232
22233Reply:
22234@table @samp
22235@item @var{XX@dots{}}
22236Hex encoded data from query. The reply can not be empty.
22237@item E@var{NN}
22238error reply
8e04817f 22239@item
ee2d5c50
AC
22240Indicating an unrecognized @var{query}.
22241@end table
22242
22243@item @code{Q}@var{var}@code{=}@var{val} --- general set
22244@cindex @code{Q} packet
22245
22246Set value of @var{var} to @var{val}.
22247
22248@xref{general query packet}, for a discussion of naming conventions.
c906108c 22249
ee2d5c50
AC
22250@item @code{r} --- reset @strong{(deprecated)}
22251@cindex @code{r} packet
c906108c 22252
8e04817f 22253Reset the entire system.
c906108c 22254
ee2d5c50
AC
22255@item @code{R}@var{XX} --- remote restart
22256@cindex @code{R} packet
22257
8e04817f
AC
22258Restart the program being debugged. @var{XX}, while needed, is ignored.
22259This packet is only available in extended mode.
ee2d5c50
AC
22260
22261Reply:
22262@table @samp
22263@item @emph{no reply}
8e04817f 22264The @samp{R} packet has no reply.
ee2d5c50
AC
22265@end table
22266
22267@item @code{s}@var{addr} --- step
22268@cindex @code{s} packet
c906108c 22269
8e04817f
AC
22270@var{addr} is address to resume. If @var{addr} is omitted, resume at
22271same address.
c906108c 22272
ee2d5c50
AC
22273Reply:
22274@xref{Stop Reply Packets}, for the reply specifications.
22275
22276@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
22277@anchor{step with signal packet}
22278@cindex @code{S} packet
22279
8e04817f 22280Like @samp{C} but step not continue.
c906108c 22281
ee2d5c50
AC
22282Reply:
22283@xref{Stop Reply Packets}, for the reply specifications.
22284
b383017d 22285@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
ee2d5c50
AC
22286@cindex @code{t} packet
22287
8e04817f 22288Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
22289@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
22290@var{addr} must be at least 3 digits.
c906108c 22291
ee2d5c50
AC
22292@item @code{T}@var{XX} --- thread alive
22293@cindex @code{T} packet
c906108c 22294
ee2d5c50 22295Find out if the thread XX is alive.
c906108c 22296
ee2d5c50
AC
22297Reply:
22298@table @samp
22299@item OK
22300thread is still alive
22301@item E@var{NN}
22302thread is dead
22303@end table
22304
22305@item @code{u} --- reserved
22306
22307Reserved for future use.
22308
22309@item @code{U} --- reserved
22310
22311Reserved for future use.
22312
86d30acc 22313@item @code{v} --- verbose packet prefix
ee2d5c50 22314
86d30acc
DJ
22315Packets starting with @code{v} are identified by a multi-letter name,
22316up to the first @code{;} or @code{?} (or the end of the packet).
22317
22318@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
22319@cindex @code{vCont} packet
22320
22321Resume the inferior. Different actions may be specified for each thread.
22322If an action is specified with no @var{tid}, then it is applied to any
22323threads that don't have a specific action specified; if no default action is
22324specified then other threads should remain stopped. Specifying multiple
22325default actions is an error; specifying no actions is also an error.
22326Thread IDs are specified in hexadecimal. Currently supported actions are:
22327
22328@table @code
22329@item c
22330Continue.
22331@item C@var{sig}
22332Continue with signal @var{sig}. @var{sig} should be two hex digits.
22333@item s
22334Step.
22335@item S@var{sig}
22336Step with signal @var{sig}. @var{sig} should be two hex digits.
22337@end table
22338
22339The optional @var{addr} argument normally associated with these packets is
22340not supported in @code{vCont}.
22341
22342Reply:
22343@xref{Stop Reply Packets}, for the reply specifications.
22344
22345@item @code{vCont?} --- extended resume query
22346@cindex @code{vCont?} packet
22347
22348Query support for the @code{vCont} packet.
22349
22350Reply:
22351@table @samp
22352@item @code{vCont}[;@var{action}]...
22353The @code{vCont} packet is supported. Each @var{action} is a supported
22354command in the @code{vCont} packet.
22355@item
22356The @code{vCont} packet is not supported.
22357@end table
ee2d5c50
AC
22358
22359@item @code{V} --- reserved
c906108c 22360
ee2d5c50 22361Reserved for future use.
c906108c 22362
ee2d5c50 22363@item @code{w} --- reserved
c906108c 22364
ee2d5c50 22365Reserved for future use.
c906108c 22366
ee2d5c50 22367@item @code{W} --- reserved
c906108c 22368
ee2d5c50 22369Reserved for future use.
c906108c 22370
ee2d5c50
AC
22371@item @code{x} --- reserved
22372
22373Reserved for future use.
22374
22375@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
22376@cindex @code{X} packet
22377
22378@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
22379is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
69065f5d
AC
22380escaped using @code{0x7d}, and then XORed with @code{0x20}.
22381For example, @code{0x7d} would be transmitted as @code{0x7d 0x5d}.
c906108c 22382
ee2d5c50
AC
22383Reply:
22384@table @samp
22385@item OK
22386for success
22387@item E@var{NN}
22388for an error
22389@end table
22390
22391@item @code{y} --- reserved
c906108c 22392
ee2d5c50 22393Reserved for future use.
c906108c 22394
ee2d5c50
AC
22395@item @code{Y} reserved
22396
22397Reserved for future use.
22398
2f870471
AC
22399@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
22400@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
22401@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 22402@cindex @code{z} packet
2f870471 22403@cindex @code{Z} packets
ee2d5c50 22404
2f870471
AC
22405Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
22406watchpoint starting at address @var{address} and covering the next
22407@var{length} bytes.
ee2d5c50 22408
2f870471
AC
22409Each breakpoint and watchpoint packet @var{type} is documented
22410separately.
22411
512217c7
AC
22412@emph{Implementation notes: A remote target shall return an empty string
22413for an unrecognized breakpoint or watchpoint packet @var{type}. A
22414remote target shall support either both or neither of a given
2f870471
AC
22415@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
22416avoid potential problems with duplicate packets, the operations should
22417be implemented in an idempotent way.}
22418
22419@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
22420@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
22421@cindex @code{z0} packet
22422@cindex @code{Z0} packet
22423
22424Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
22425@code{addr} of size @code{length}.
22426
22427A memory breakpoint is implemented by replacing the instruction at
22428@var{addr} with a software breakpoint or trap instruction. The
22429@code{length} is used by targets that indicates the size of the
22430breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
22431@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 22432
2f870471
AC
22433@emph{Implementation note: It is possible for a target to copy or move
22434code that contains memory breakpoints (e.g., when implementing
22435overlays). The behavior of this packet, in the presence of such a
22436target, is not defined.}
c906108c 22437
ee2d5c50
AC
22438Reply:
22439@table @samp
2f870471
AC
22440@item OK
22441success
22442@item
22443not supported
ee2d5c50
AC
22444@item E@var{NN}
22445for an error
2f870471
AC
22446@end table
22447
22448@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
22449@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
22450@cindex @code{z1} packet
22451@cindex @code{Z1} packet
22452
22453Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
22454address @code{addr} of size @code{length}.
22455
22456A hardware breakpoint is implemented using a mechanism that is not
22457dependant on being able to modify the target's memory.
22458
22459@emph{Implementation note: A hardware breakpoint is not affected by code
22460movement.}
22461
22462Reply:
22463@table @samp
ee2d5c50 22464@item OK
2f870471
AC
22465success
22466@item
22467not supported
22468@item E@var{NN}
22469for an error
22470@end table
22471
22472@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
22473@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
22474@cindex @code{z2} packet
22475@cindex @code{Z2} packet
22476
22477Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
22478
22479Reply:
22480@table @samp
22481@item OK
22482success
22483@item
22484not supported
22485@item E@var{NN}
22486for an error
22487@end table
22488
22489@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
22490@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
22491@cindex @code{z3} packet
22492@cindex @code{Z3} packet
22493
2e834e49 22494Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
22495
22496Reply:
22497@table @samp
22498@item OK
22499success
22500@item
22501not supported
22502@item E@var{NN}
22503for an error
22504@end table
22505
2e834e49
HPN
22506@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
22507@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
22508@cindex @code{z4} packet
22509@cindex @code{Z4} packet
22510
22511Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
22512
22513Reply:
22514@table @samp
22515@item OK
22516success
22517@item
22518not supported
22519@item E@var{NN}
22520for an error
ee2d5c50
AC
22521@end table
22522
22523@end table
c906108c 22524
ee2d5c50
AC
22525@node Stop Reply Packets
22526@section Stop Reply Packets
22527@cindex stop reply packets
c906108c 22528
8e04817f
AC
22529The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
22530receive any of the below as a reply. In the case of the @samp{C},
22531@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
22532when the target halts. In the below the exact meaning of @samp{signal
22533number} is poorly defined. In general one of the UNIX signal numbering
22534conventions is used.
c906108c 22535
ee2d5c50 22536@table @samp
c906108c 22537
ee2d5c50
AC
22538@item S@var{AA}
22539@var{AA} is the signal number
c906108c 22540
8e04817f 22541@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
22542@cindex @code{T} packet reply
22543
8e04817f
AC
22544@var{AA} = two hex digit signal number; @var{n...} = register number
22545(hex), @var{r...} = target byte ordered register contents, size defined
12c266ea
AC
22546by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
22547@var{r...} = thread process ID, this is a hex integer; @var{n...} =
22548(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
22549address, this is a hex integer; @var{n...} = other string not starting
22550with valid hex digit. @value{GDBN} should ignore this @var{n...},
22551@var{r...} pair and go on to the next. This way we can extend the
22552protocol.
c906108c 22553
ee2d5c50
AC
22554@item W@var{AA}
22555
8e04817f 22556The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
22557applicable to certain targets.
22558
22559@item X@var{AA}
c906108c 22560
8e04817f 22561The process terminated with signal @var{AA}.
c906108c 22562
ee2d5c50 22563@item O@var{XX@dots{}}
c906108c 22564
ee2d5c50
AC
22565@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
22566any time while the program is running and the debugger should continue
22567to wait for @samp{W}, @samp{T}, etc.
22568
0ce1b118
CV
22569@item F@var{call-id}@code{,}@var{parameter@dots{}}
22570
22571@var{call-id} is the identifier which says which host system call should
22572be called. This is just the name of the function. Translation into the
22573correct system call is only applicable as it's defined in @value{GDBN}.
22574@xref{File-I/O remote protocol extension}, for a list of implemented
22575system calls.
22576
22577@var{parameter@dots{}} is a list of parameters as defined for this very
22578system call.
22579
22580The target replies with this packet when it expects @value{GDBN} to call
22581a host system call on behalf of the target. @value{GDBN} replies with
22582an appropriate @code{F} packet and keeps up waiting for the next reply
22583packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
22584@samp{s} action is expected to be continued.
22585@xref{File-I/O remote protocol extension}, for more details.
22586
ee2d5c50
AC
22587@end table
22588
22589@node General Query Packets
22590@section General Query Packets
9c16f35a 22591@cindex remote query requests
c906108c 22592
8e04817f 22593The following set and query packets have already been defined.
c906108c 22594
ee2d5c50 22595@table @r
c906108c 22596
ee2d5c50 22597@item @code{q}@code{C} --- current thread
9c16f35a
EZ
22598@cindex current thread, remote request
22599@cindex @code{qC} packet
ee2d5c50
AC
22600Return the current thread id.
22601
22602Reply:
22603@table @samp
22604@item @code{QC}@var{pid}
e1aac25b 22605Where @var{pid} is an unsigned hexidecimal process id.
ee2d5c50
AC
22606@item *
22607Any other reply implies the old pid.
22608@end table
22609
22610@item @code{q}@code{fThreadInfo} -- all thread ids
9c16f35a
EZ
22611@cindex list active threads, remote request
22612@cindex @code{qfThreadInfo} packet
ee2d5c50 22613@code{q}@code{sThreadInfo}
c906108c 22614
8e04817f
AC
22615Obtain a list of active thread ids from the target (OS). Since there
22616may be too many active threads to fit into one reply packet, this query
22617works iteratively: it may require more than one query/reply sequence to
22618obtain the entire list of threads. The first query of the sequence will
22619be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
22620sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
22621
22622NOTE: replaces the @code{qL} query (see below).
22623
22624Reply:
22625@table @samp
22626@item @code{m}@var{id}
22627A single thread id
22628@item @code{m}@var{id},@var{id}@dots{}
22629a comma-separated list of thread ids
22630@item @code{l}
22631(lower case 'el') denotes end of list.
22632@end table
22633
22634In response to each query, the target will reply with a list of one or
e1aac25b
JB
22635more thread ids, in big-endian unsigned hex, separated by commas.
22636@value{GDBN} will respond to each reply with a request for more thread
22637ids (using the @code{qs} form of the query), until the target responds
22638with @code{l} (lower-case el, for @code{'last'}).
c906108c 22639
ee2d5c50 22640@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
9c16f35a
EZ
22641@cindex thread attributes info, remote request
22642@cindex @code{qThreadExtraInfo} packet
ee2d5c50
AC
22643Where @var{id} is a thread-id in big-endian hex. Obtain a printable
22644string description of a thread's attributes from the target OS. This
22645string may contain anything that the target OS thinks is interesting for
22646@value{GDBN} to tell the user about the thread. The string is displayed
22647in @value{GDBN}'s @samp{info threads} display. Some examples of
22648possible thread extra info strings are ``Runnable'', or ``Blocked on
22649Mutex''.
22650
22651Reply:
22652@table @samp
22653@item @var{XX@dots{}}
22654Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
22655the printable string containing the extra information about the thread's
8e04817f 22656attributes.
ee2d5c50
AC
22657@end table
22658
22659@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 22660
8e04817f
AC
22661Obtain thread information from RTOS. Where: @var{startflag} (one hex
22662digit) is one to indicate the first query and zero to indicate a
22663subsequent query; @var{threadcount} (two hex digits) is the maximum
22664number of threads the response packet can contain; and @var{nextthread}
22665(eight hex digits), for subsequent queries (@var{startflag} is zero), is
22666returned in the response as @var{argthread}.
ee2d5c50
AC
22667
22668NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
22669(see above).
22670
22671Reply:
22672@table @samp
22673@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
22674Where: @var{count} (two hex digits) is the number of threads being
22675returned; @var{done} (one hex digit) is zero to indicate more threads
22676and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
22677digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
22678is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 22679digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 22680@end table
c906108c 22681
ee2d5c50 22682@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
9c16f35a
EZ
22683@cindex CRC of memory block, remote request
22684@cindex @code{qCRC} packet
ee2d5c50
AC
22685Reply:
22686@table @samp
22687@item @code{E}@var{NN}
22688An error (such as memory fault)
22689@item @code{C}@var{CRC32}
22690A 32 bit cyclic redundancy check of the specified memory region.
22691@end table
22692
22693@item @code{q}@code{Offsets} --- query sect offs
9c16f35a
EZ
22694@cindex section offsets, remote request
22695@cindex @code{qOffsets} packet
8e04817f
AC
22696Get section offsets that the target used when re-locating the downloaded
22697image. @emph{Note: while a @code{Bss} offset is included in the
22698response, @value{GDBN} ignores this and instead applies the @code{Data}
22699offset to the @code{Bss} section.}
c906108c 22700
ee2d5c50
AC
22701Reply:
22702@table @samp
22703@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
22704@end table
22705
22706@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
9c16f35a
EZ
22707@cindex thread information, remote request
22708@cindex @code{qP} packet
8e04817f
AC
22709Returns information on @var{threadid}. Where: @var{mode} is a hex
22710encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
22711
22712Reply:
22713@table @samp
22714@item *
22715@end table
22716
8e04817f 22717See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 22718
ee2d5c50 22719@item @code{q}@code{Rcmd,}@var{command} --- remote command
9c16f35a
EZ
22720@cindex execute remote command, remote request
22721@cindex @code{qRcmd} packet
ee2d5c50 22722@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
22723execution. Invalid commands should be reported using the output string.
22724Before the final result packet, the target may also respond with a
ee2d5c50
AC
22725number of intermediate @code{O}@var{output} console output packets.
22726@emph{Implementors should note that providing access to a stubs's
22727interpreter may have security implications}.
22728
22729Reply:
22730@table @samp
22731@item OK
8e04817f 22732A command response with no output.
ee2d5c50 22733@item @var{OUTPUT}
8e04817f 22734A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 22735@item @code{E}@var{NN}
8e04817f 22736Indicate a badly formed request.
ee2d5c50 22737@item @samp{}
8e04817f 22738When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50 22739@end table
9c16f35a 22740z
ee2d5c50 22741@item @code{qSymbol::} --- symbol lookup
9c16f35a
EZ
22742@cindex symbol lookup, remote request
22743@cindex @code{qSymbol} packet
8e04817f
AC
22744Notify the target that @value{GDBN} is prepared to serve symbol lookup
22745requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
22746
22747Reply:
22748@table @samp
22749@item @code{OK}
8e04817f 22750The target does not need to look up any (more) symbols.
ee2d5c50
AC
22751@item @code{qSymbol:}@var{sym_name}
22752The target requests the value of symbol @var{sym_name} (hex encoded).
22753@value{GDBN} may provide the value by using the
22754@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
22755@end table
22756
22757@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
22758
22759Set the value of @var{sym_name} to @var{sym_value}.
22760
22761@var{sym_name} (hex encoded) is the name of a symbol whose value the
22762target has previously requested.
22763
22764@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
22765@value{GDBN} cannot supply a value for @var{sym_name}, then this field
22766will be empty.
22767
22768Reply:
22769@table @samp
22770@item @code{OK}
8e04817f 22771The target does not need to look up any (more) symbols.
ee2d5c50
AC
22772@item @code{qSymbol:}@var{sym_name}
22773The target requests the value of a new symbol @var{sym_name} (hex
22774encoded). @value{GDBN} will continue to supply the values of symbols
22775(if available), until the target ceases to request them.
22776@end table
eb12ee30 22777
649e03f6 22778@item @code{qPart}:@var{object}:@code{read}:@var{annex}:@var{offset},@var{length} --- read special data
9c16f35a
EZ
22779@cindex read special object, remote request
22780@cindex @code{qPart} packet
649e03f6
RM
22781Read uninterpreted bytes from the target's special data area
22782identified by the keyword @code{object}.
22783Request @var{length} bytes starting at @var{offset} bytes into the data.
22784The content and encoding of @var{annex} is specific to the object;
22785it can supply additional details about what data to access.
22786
22787Here are the specific requests of this form defined so far.
22788All @samp{@code{qPart}:@var{object}:@code{read}:@dots{}}
22789requests use the same reply formats, listed below.
22790
22791@table @asis
22792@item @code{qPart}:@code{auxv}:@code{read}::@var{offset},@var{length}
721c2651
EZ
22793Access the target's @dfn{auxiliary vector}. @xref{OS Information,
22794auxiliary vector}, and see @ref{Remote configuration,
22795read-aux-vector-packet}. Note @var{annex} must be empty.
649e03f6
RM
22796@end table
22797
22798Reply:
22799@table @asis
22800@item @code{OK}
22801The @var{offset} in the request is at the end of the data.
22802There is no more data to be read.
22803
22804@item @var{XX@dots{}}
22805Hex encoded data bytes read.
22806This may be fewer bytes than the @var{length} in the request.
22807
22808@item @code{E00}
22809The request was malformed, or @var{annex} was invalid.
22810
22811@item @code{E}@var{nn}
22812The offset was invalid, or there was an error encountered reading the data.
22813@var{nn} is a hex-encoded @code{errno} value.
22814
22815@item @code{""} (empty)
22816An empty reply indicates the @var{object} or @var{annex} string was not
22817recognized by the stub.
22818@end table
22819
22820@item @code{qPart}:@var{object}:@code{write}:@var{annex}:@var{offset}:@var{data@dots{}}
9c16f35a 22821@cindex write data into object, remote request
649e03f6
RM
22822Write uninterpreted bytes into the target's special data area
22823identified by the keyword @code{object},
22824starting at @var{offset} bytes into the data.
22825@var{data@dots{}} is the hex-encoded data to be written.
22826The content and encoding of @var{annex} is specific to the object;
22827it can supply additional details about what data to access.
22828
22829No requests of this form are presently in use. This specification
22830serves as a placeholder to document the common format that new
22831specific request specifications ought to use.
22832
22833Reply:
22834@table @asis
22835@item @var{nn}
22836@var{nn} (hex encoded) is the number of bytes written.
22837This may be fewer bytes than supplied in the request.
22838
22839@item @code{E00}
22840The request was malformed, or @var{annex} was invalid.
22841
22842@item @code{E}@var{nn}
22843The offset was invalid, or there was an error encountered writing the data.
22844@var{nn} is a hex-encoded @code{errno} value.
22845
22846@item @code{""} (empty)
22847An empty reply indicates the @var{object} or @var{annex} string was not
22848recognized by the stub, or that the object does not support writing.
22849@end table
22850
22851@item @code{qPart}:@var{object}:@var{operation}:@dots{}
22852Requests of this form may be added in the future. When a stub does
22853not recognize the @var{object} keyword, or its support for
22854@var{object} does not recognize the @var{operation} keyword,
22855the stub must respond with an empty packet.
83761cbd
KB
22856
22857@item @code{qGetTLSAddr}:@var{thread-id},@var{offset},@var{lm} --- get thread local storage address
9c16f35a
EZ
22858@cindex get thread-local storage address, remote request
22859@cindex @code{qGetTLSAddr} packet
83761cbd
KB
22860Fetch the address associated with thread local storage specified
22861by @var{thread-id}, @var{offset}, and @var{lm}.
22862
22863@var{thread-id} is the (big endian, hex encoded) thread id associated with the
22864thread for which to fetch the TLS address.
22865
22866@var{offset} is the (big endian, hex encoded) offset associated with the
22867thread local variable. (This offset is obtained from the debug
22868information associated with the variable.)
22869
22870@var{lm} is the (big endian, hex encoded) OS/ABI specific encoding of the
22871the load module associated with the thread local storage. For example,
22872a @sc{gnu}/Linux system will pass the link map address of the shared
22873object associated with the thread local storage under consideration.
22874Other operating environments may choose to represent the load module
22875differently, so the precise meaning of this parameter will vary.
22876
22877Reply:
22878@table @asis
68c71a2e 22879@item @var{XX@dots{}}
83761cbd
KB
22880Hex encoded (big endian) bytes representing the address of the thread
22881local storage requested.
22882
22883@item @code{E}@var{nn} (where @var{nn} are hex digits)
22884An error occurred.
22885
22886@item @code{""} (empty)
22887An empty reply indicates that @code{qGetTLSAddr} is not supported by the stub.
22888@end table
22889
0abb7bc7
EZ
22890Use of this request packet is controlled by the @code{set remote
22891get-thread-local-storage-address} command (@pxref{Remote
22892configuration, set remote get-thread-local-storage-address}).
22893
ee2d5c50
AC
22894@end table
22895
22896@node Register Packet Format
22897@section Register Packet Format
eb12ee30 22898
8e04817f 22899The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
22900In the below, some thirty-two bit registers are transferred as
22901sixty-four bits. Those registers should be zero/sign extended (which?)
22902to fill the space allocated. Register bytes are transfered in target
22903byte order. The two nibbles within a register byte are transfered
22904most-significant - least-significant.
eb12ee30 22905
ee2d5c50 22906@table @r
eb12ee30 22907
8e04817f 22908@item MIPS32
ee2d5c50 22909
8e04817f
AC
22910All registers are transfered as thirty-two bit quantities in the order:
2291132 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
22912registers; fsr; fir; fp.
eb12ee30 22913
8e04817f 22914@item MIPS64
ee2d5c50 22915
8e04817f
AC
22916All registers are transfered as sixty-four bit quantities (including
22917thirty-two bit registers such as @code{sr}). The ordering is the same
22918as @code{MIPS32}.
eb12ee30 22919
ee2d5c50
AC
22920@end table
22921
22922@node Examples
22923@section Examples
eb12ee30 22924
8e04817f
AC
22925Example sequence of a target being re-started. Notice how the restart
22926does not get any direct output:
eb12ee30 22927
474c8240 22928@smallexample
d2c6833e
AC
22929-> @code{R00}
22930<- @code{+}
8e04817f 22931@emph{target restarts}
d2c6833e 22932-> @code{?}
8e04817f 22933<- @code{+}
d2c6833e
AC
22934<- @code{T001:1234123412341234}
22935-> @code{+}
474c8240 22936@end smallexample
eb12ee30 22937
8e04817f 22938Example sequence of a target being stepped by a single instruction:
eb12ee30 22939
474c8240 22940@smallexample
d2c6833e 22941-> @code{G1445@dots{}}
8e04817f 22942<- @code{+}
d2c6833e
AC
22943-> @code{s}
22944<- @code{+}
22945@emph{time passes}
22946<- @code{T001:1234123412341234}
8e04817f 22947-> @code{+}
d2c6833e 22948-> @code{g}
8e04817f 22949<- @code{+}
d2c6833e
AC
22950<- @code{1455@dots{}}
22951-> @code{+}
474c8240 22952@end smallexample
eb12ee30 22953
0ce1b118
CV
22954@node File-I/O remote protocol extension
22955@section File-I/O remote protocol extension
22956@cindex File-I/O remote protocol extension
22957
22958@menu
22959* File-I/O Overview::
22960* Protocol basics::
1d8b2f28
JB
22961* The F request packet::
22962* The F reply packet::
0ce1b118
CV
22963* Memory transfer::
22964* The Ctrl-C message::
22965* Console I/O::
22966* The isatty call::
22967* The system call::
22968* List of supported calls::
22969* Protocol specific representation of datatypes::
22970* Constants::
22971* File-I/O Examples::
22972@end menu
22973
22974@node File-I/O Overview
22975@subsection File-I/O Overview
22976@cindex file-i/o overview
22977
9c16f35a
EZ
22978The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
22979target to use the host's file system and console I/O when calling various
0ce1b118
CV
22980system calls. System calls on the target system are translated into a
22981remote protocol packet to the host system which then performs the needed
22982actions and returns with an adequate response packet to the target system.
22983This simulates file system operations even on targets that lack file systems.
22984
22985The protocol is defined host- and target-system independent. It uses
9c16f35a 22986its own independent representation of datatypes and values. Both,
0ce1b118
CV
22987@value{GDBN} and the target's @value{GDBN} stub are responsible for
22988translating the system dependent values into the unified protocol values
22989when data is transmitted.
22990
22991The communication is synchronous. A system call is possible only
22992when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
22993packets. While @value{GDBN} handles the request for a system call,
22994the target is stopped to allow deterministic access to the target's
22995memory. Therefore File-I/O is not interuptible by target signals. It
22996is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
22997
22998The target's request to perform a host system call does not finish
22999the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
23000after finishing the system call, the target returns to continuing the
23001previous activity (continue, step). No additional continue or step
23002request from @value{GDBN} is required.
23003
23004@smallexample
f7dc1244 23005(@value{GDBP}) continue
0ce1b118
CV
23006 <- target requests 'system call X'
23007 target is stopped, @value{GDBN} executes system call
23008 -> GDB returns result
23009 ... target continues, GDB returns to wait for the target
23010 <- target hits breakpoint and sends a Txx packet
23011@end smallexample
23012
23013The protocol is only used for files on the host file system and
23014for I/O on the console. Character or block special devices, pipes,
23015named pipes or sockets or any other communication method on the host
23016system are not supported by this protocol.
23017
23018@node Protocol basics
23019@subsection Protocol basics
23020@cindex protocol basics, file-i/o
23021
23022The File-I/O protocol uses the @code{F} packet, as request as well
23023as as reply packet. Since a File-I/O system call can only occur when
b383017d 23024@value{GDBN} is waiting for the continuing or stepping target, the
0ce1b118
CV
23025File-I/O request is a reply that @value{GDBN} has to expect as a result
23026of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
23027This @code{F} packet contains all information needed to allow @value{GDBN}
23028to call the appropriate host system call:
23029
23030@itemize @bullet
b383017d 23031@item
0ce1b118
CV
23032A unique identifier for the requested system call.
23033
23034@item
23035All parameters to the system call. Pointers are given as addresses
23036in the target memory address space. Pointers to strings are given as
b383017d 23037pointer/length pair. Numerical values are given as they are.
0ce1b118
CV
23038Numerical control values are given in a protocol specific representation.
23039
23040@end itemize
23041
23042At that point @value{GDBN} has to perform the following actions.
23043
23044@itemize @bullet
b383017d 23045@item
0ce1b118
CV
23046If parameter pointer values are given, which point to data needed as input
23047to a system call, @value{GDBN} requests this data from the target with a
23048standard @code{m} packet request. This additional communication has to be
23049expected by the target implementation and is handled as any other @code{m}
23050packet.
23051
23052@item
23053@value{GDBN} translates all value from protocol representation to host
23054representation as needed. Datatypes are coerced into the host types.
23055
23056@item
23057@value{GDBN} calls the system call
23058
23059@item
23060It then coerces datatypes back to protocol representation.
23061
23062@item
23063If pointer parameters in the request packet point to buffer space in which
23064a system call is expected to copy data to, the data is transmitted to the
23065target using a @code{M} or @code{X} packet. This packet has to be expected
23066by the target implementation and is handled as any other @code{M} or @code{X}
23067packet.
23068
23069@end itemize
23070
23071Eventually @value{GDBN} replies with another @code{F} packet which contains all
23072necessary information for the target to continue. This at least contains
23073
23074@itemize @bullet
23075@item
23076Return value.
23077
23078@item
23079@code{errno}, if has been changed by the system call.
23080
23081@item
23082``Ctrl-C'' flag.
23083
23084@end itemize
23085
23086After having done the needed type and value coercion, the target continues
23087the latest continue or step action.
23088
1d8b2f28 23089@node The F request packet
0ce1b118
CV
23090@subsection The @code{F} request packet
23091@cindex file-i/o request packet
23092@cindex @code{F} request packet
23093
23094The @code{F} request packet has the following format:
23095
23096@table @samp
23097
23098@smallexample
23099@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
23100@end smallexample
23101
23102@var{call-id} is the identifier to indicate the host system call to be called.
23103This is just the name of the function.
23104
23105@var{parameter@dots{}} are the parameters to the system call.
23106
b383017d 23107@end table
0ce1b118
CV
23108
23109Parameters are hexadecimal integer values, either the real values in case
23110of scalar datatypes, as pointers to target buffer space in case of compound
23111datatypes and unspecified memory areas or as pointer/length pairs in case
23112of string parameters. These are appended to the call-id, each separated
23113from its predecessor by a comma. All values are transmitted in ASCII
23114string representation, pointer/length pairs separated by a slash.
23115
1d8b2f28 23116@node The F reply packet
0ce1b118
CV
23117@subsection The @code{F} reply packet
23118@cindex file-i/o reply packet
23119@cindex @code{F} reply packet
23120
23121The @code{F} reply packet has the following format:
23122
23123@table @samp
23124
23125@smallexample
23126@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
23127@end smallexample
23128
23129@var{retcode} is the return code of the system call as hexadecimal value.
23130
23131@var{errno} is the errno set by the call, in protocol specific representation.
23132This parameter can be omitted if the call was successful.
23133
23134@var{Ctrl-C flag} is only send if the user requested a break. In this
23135case, @var{errno} must be send as well, even if the call was successful.
23136The @var{Ctrl-C flag} itself consists of the character 'C':
23137
23138@smallexample
23139F0,0,C
23140@end smallexample
23141
23142@noindent
23143or, if the call was interupted before the host call has been performed:
23144
23145@smallexample
23146F-1,4,C
23147@end smallexample
23148
23149@noindent
23150assuming 4 is the protocol specific representation of @code{EINTR}.
23151
23152@end table
23153
23154@node Memory transfer
23155@subsection Memory transfer
23156@cindex memory transfer, in file-i/o protocol
23157
23158Structured data which is transferred using a memory read or write as e.g.@:
23159a @code{struct stat} is expected to be in a protocol specific format with
23160all scalar multibyte datatypes being big endian. This should be done by
23161the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
23162it transfers memory to the target. Transferred pointers to structured
23163data should point to the already coerced data at any time.
23164
23165@node The Ctrl-C message
23166@subsection The Ctrl-C message
23167@cindex ctrl-c message, in file-i/o protocol
23168
23169A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
23170reply packet. In this case the target should behave, as if it had
23171gotten a break message. The meaning for the target is ``system call
23172interupted by @code{SIGINT}''. Consequentially, the target should actually stop
23173(as with a break message) and return to @value{GDBN} with a @code{T02}
b383017d 23174packet. In this case, it's important for the target to know, in which
0ce1b118
CV
23175state the system call was interrupted. Since this action is by design
23176not an atomic operation, we have to differ between two cases:
23177
23178@itemize @bullet
23179@item
23180The system call hasn't been performed on the host yet.
23181
23182@item
23183The system call on the host has been finished.
23184
23185@end itemize
23186
23187These two states can be distinguished by the target by the value of the
23188returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
23189call hasn't been performed. This is equivalent to the @code{EINTR} handling
23190on POSIX systems. In any other case, the target may presume that the
23191system call has been finished --- successful or not --- and should behave
23192as if the break message arrived right after the system call.
23193
23194@value{GDBN} must behave reliable. If the system call has not been called
23195yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
23196@code{errno} in the packet. If the system call on the host has been finished
23197before the user requests a break, the full action must be finshed by
23198@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
23199The @code{F} packet may only be send when either nothing has happened
23200or the full action has been completed.
23201
23202@node Console I/O
23203@subsection Console I/O
23204@cindex console i/o as part of file-i/o
23205
23206By default and if not explicitely closed by the target system, the file
23207descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
23208on the @value{GDBN} console is handled as any other file output operation
23209(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
23210by @value{GDBN} so that after the target read request from file descriptor
232110 all following typing is buffered until either one of the following
23212conditions is met:
23213
23214@itemize @bullet
23215@item
23216The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
23217@code{read}
23218system call is treated as finished.
23219
23220@item
23221The user presses @kbd{Enter}. This is treated as end of input with a trailing
23222line feed.
23223
23224@item
23225The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
23226character, especially no Ctrl-D is appended to the input.
23227
23228@end itemize
23229
23230If the user has typed more characters as fit in the buffer given to
23231the read call, the trailing characters are buffered in @value{GDBN} until
23232either another @code{read(0, @dots{})} is requested by the target or debugging
23233is stopped on users request.
23234
23235@node The isatty call
2eecc4ab 23236@subsection The @samp{isatty} function call
0ce1b118
CV
23237@cindex isatty call, file-i/o protocol
23238
23239A special case in this protocol is the library call @code{isatty} which
9c16f35a 23240is implemented as its own call inside of this protocol. It returns
0ce1b118
CV
232411 to the target if the file descriptor given as parameter is attached
23242to the @value{GDBN} console, 0 otherwise. Implementing through system calls
23243would require implementing @code{ioctl} and would be more complex than
23244needed.
23245
23246@node The system call
2eecc4ab 23247@subsection The @samp{system} function call
0ce1b118
CV
23248@cindex system call, file-i/o protocol
23249
23250The other special case in this protocol is the @code{system} call which
9c16f35a 23251is implemented as its own call, too. @value{GDBN} is taking over the full
0ce1b118
CV
23252task of calling the necessary host calls to perform the @code{system}
23253call. The return value of @code{system} is simplified before it's returned
23254to the target. Basically, the only signal transmitted back is @code{EINTR}
23255in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
23256entirely of the exit status of the called command.
23257
9c16f35a
EZ
23258Due to security concerns, the @code{system} call is by default refused
23259by @value{GDBN}. The user has to allow this call explicitly with the
23260@kbd{set remote system-call-allowed 1} command.
0ce1b118 23261
9c16f35a
EZ
23262@table @code
23263@item set remote system-call-allowed
23264@kindex set remote system-call-allowed
23265Control whether to allow the @code{system} calls in the File I/O
23266protocol for the remote target. The default is zero (disabled).
0ce1b118 23267
9c16f35a 23268@item show remote system-call-allowed
0ce1b118 23269@kindex show remote system-call-allowed
9c16f35a
EZ
23270Show the current setting of system calls for the remote File I/O
23271protocol.
0ce1b118
CV
23272@end table
23273
23274@node List of supported calls
23275@subsection List of supported calls
23276@cindex list of supported file-i/o calls
23277
23278@menu
23279* open::
23280* close::
23281* read::
23282* write::
23283* lseek::
23284* rename::
23285* unlink::
23286* stat/fstat::
23287* gettimeofday::
23288* isatty::
23289* system::
23290@end menu
23291
23292@node open
23293@unnumberedsubsubsec open
23294@cindex open, file-i/o system call
23295
23296@smallexample
23297@exdent Synopsis:
23298int open(const char *pathname, int flags);
23299int open(const char *pathname, int flags, mode_t mode);
23300
b383017d 23301@exdent Request:
0ce1b118
CV
23302Fopen,pathptr/len,flags,mode
23303@end smallexample
23304
23305@noindent
23306@code{flags} is the bitwise or of the following values:
23307
23308@table @code
b383017d 23309@item O_CREAT
0ce1b118
CV
23310If the file does not exist it will be created. The host
23311rules apply as far as file ownership and time stamps
23312are concerned.
23313
b383017d 23314@item O_EXCL
0ce1b118
CV
23315When used with O_CREAT, if the file already exists it is
23316an error and open() fails.
23317
b383017d 23318@item O_TRUNC
0ce1b118
CV
23319If the file already exists and the open mode allows
23320writing (O_RDWR or O_WRONLY is given) it will be
23321truncated to length 0.
23322
b383017d 23323@item O_APPEND
0ce1b118
CV
23324The file is opened in append mode.
23325
b383017d 23326@item O_RDONLY
0ce1b118
CV
23327The file is opened for reading only.
23328
b383017d 23329@item O_WRONLY
0ce1b118
CV
23330The file is opened for writing only.
23331
b383017d 23332@item O_RDWR
0ce1b118
CV
23333The file is opened for reading and writing.
23334
23335@noindent
23336Each other bit is silently ignored.
23337
23338@end table
23339
23340@noindent
23341@code{mode} is the bitwise or of the following values:
23342
23343@table @code
b383017d 23344@item S_IRUSR
0ce1b118
CV
23345User has read permission.
23346
b383017d 23347@item S_IWUSR
0ce1b118
CV
23348User has write permission.
23349
b383017d 23350@item S_IRGRP
0ce1b118
CV
23351Group has read permission.
23352
b383017d 23353@item S_IWGRP
0ce1b118
CV
23354Group has write permission.
23355
b383017d 23356@item S_IROTH
0ce1b118
CV
23357Others have read permission.
23358
b383017d 23359@item S_IWOTH
0ce1b118
CV
23360Others have write permission.
23361
23362@noindent
23363Each other bit is silently ignored.
23364
23365@end table
23366
23367@smallexample
23368@exdent Return value:
23369open returns the new file descriptor or -1 if an error
23370occured.
23371
23372@exdent Errors:
23373@end smallexample
23374
23375@table @code
b383017d 23376@item EEXIST
0ce1b118
CV
23377pathname already exists and O_CREAT and O_EXCL were used.
23378
b383017d 23379@item EISDIR
0ce1b118
CV
23380pathname refers to a directory.
23381
b383017d 23382@item EACCES
0ce1b118
CV
23383The requested access is not allowed.
23384
23385@item ENAMETOOLONG
23386pathname was too long.
23387
b383017d 23388@item ENOENT
0ce1b118
CV
23389A directory component in pathname does not exist.
23390
b383017d 23391@item ENODEV
0ce1b118
CV
23392pathname refers to a device, pipe, named pipe or socket.
23393
b383017d 23394@item EROFS
0ce1b118
CV
23395pathname refers to a file on a read-only filesystem and
23396write access was requested.
23397
b383017d 23398@item EFAULT
0ce1b118
CV
23399pathname is an invalid pointer value.
23400
b383017d 23401@item ENOSPC
0ce1b118
CV
23402No space on device to create the file.
23403
b383017d 23404@item EMFILE
0ce1b118
CV
23405The process already has the maximum number of files open.
23406
b383017d 23407@item ENFILE
0ce1b118
CV
23408The limit on the total number of files open on the system
23409has been reached.
23410
b383017d 23411@item EINTR
0ce1b118
CV
23412The call was interrupted by the user.
23413@end table
23414
23415@node close
23416@unnumberedsubsubsec close
23417@cindex close, file-i/o system call
23418
23419@smallexample
b383017d 23420@exdent Synopsis:
0ce1b118
CV
23421int close(int fd);
23422
b383017d 23423@exdent Request:
0ce1b118
CV
23424Fclose,fd
23425
23426@exdent Return value:
23427close returns zero on success, or -1 if an error occurred.
23428
23429@exdent Errors:
23430@end smallexample
23431
23432@table @code
b383017d 23433@item EBADF
0ce1b118
CV
23434fd isn't a valid open file descriptor.
23435
b383017d 23436@item EINTR
0ce1b118
CV
23437The call was interrupted by the user.
23438@end table
23439
23440@node read
23441@unnumberedsubsubsec read
23442@cindex read, file-i/o system call
23443
23444@smallexample
b383017d 23445@exdent Synopsis:
0ce1b118
CV
23446int read(int fd, void *buf, unsigned int count);
23447
b383017d 23448@exdent Request:
0ce1b118
CV
23449Fread,fd,bufptr,count
23450
23451@exdent Return value:
23452On success, the number of bytes read is returned.
23453Zero indicates end of file. If count is zero, read
b383017d 23454returns zero as well. On error, -1 is returned.
0ce1b118
CV
23455
23456@exdent Errors:
23457@end smallexample
23458
23459@table @code
b383017d 23460@item EBADF
0ce1b118
CV
23461fd is not a valid file descriptor or is not open for
23462reading.
23463
b383017d 23464@item EFAULT
0ce1b118
CV
23465buf is an invalid pointer value.
23466
b383017d 23467@item EINTR
0ce1b118
CV
23468The call was interrupted by the user.
23469@end table
23470
23471@node write
23472@unnumberedsubsubsec write
23473@cindex write, file-i/o system call
23474
23475@smallexample
b383017d 23476@exdent Synopsis:
0ce1b118
CV
23477int write(int fd, const void *buf, unsigned int count);
23478
b383017d 23479@exdent Request:
0ce1b118
CV
23480Fwrite,fd,bufptr,count
23481
23482@exdent Return value:
23483On success, the number of bytes written are returned.
23484Zero indicates nothing was written. On error, -1
23485is returned.
23486
23487@exdent Errors:
23488@end smallexample
23489
23490@table @code
b383017d 23491@item EBADF
0ce1b118
CV
23492fd is not a valid file descriptor or is not open for
23493writing.
23494
b383017d 23495@item EFAULT
0ce1b118
CV
23496buf is an invalid pointer value.
23497
b383017d 23498@item EFBIG
0ce1b118
CV
23499An attempt was made to write a file that exceeds the
23500host specific maximum file size allowed.
23501
b383017d 23502@item ENOSPC
0ce1b118
CV
23503No space on device to write the data.
23504
b383017d 23505@item EINTR
0ce1b118
CV
23506The call was interrupted by the user.
23507@end table
23508
23509@node lseek
23510@unnumberedsubsubsec lseek
23511@cindex lseek, file-i/o system call
23512
23513@smallexample
b383017d 23514@exdent Synopsis:
0ce1b118
CV
23515long lseek (int fd, long offset, int flag);
23516
b383017d 23517@exdent Request:
0ce1b118
CV
23518Flseek,fd,offset,flag
23519@end smallexample
23520
23521@code{flag} is one of:
23522
23523@table @code
b383017d 23524@item SEEK_SET
0ce1b118
CV
23525The offset is set to offset bytes.
23526
b383017d 23527@item SEEK_CUR
0ce1b118
CV
23528The offset is set to its current location plus offset
23529bytes.
23530
b383017d 23531@item SEEK_END
0ce1b118
CV
23532The offset is set to the size of the file plus offset
23533bytes.
23534@end table
23535
23536@smallexample
23537@exdent Return value:
23538On success, the resulting unsigned offset in bytes from
23539the beginning of the file is returned. Otherwise, a
23540value of -1 is returned.
23541
23542@exdent Errors:
23543@end smallexample
23544
23545@table @code
b383017d 23546@item EBADF
0ce1b118
CV
23547fd is not a valid open file descriptor.
23548
b383017d 23549@item ESPIPE
0ce1b118
CV
23550fd is associated with the @value{GDBN} console.
23551
b383017d 23552@item EINVAL
0ce1b118
CV
23553flag is not a proper value.
23554
b383017d 23555@item EINTR
0ce1b118
CV
23556The call was interrupted by the user.
23557@end table
23558
23559@node rename
23560@unnumberedsubsubsec rename
23561@cindex rename, file-i/o system call
23562
23563@smallexample
b383017d 23564@exdent Synopsis:
0ce1b118
CV
23565int rename(const char *oldpath, const char *newpath);
23566
b383017d 23567@exdent Request:
0ce1b118
CV
23568Frename,oldpathptr/len,newpathptr/len
23569
23570@exdent Return value:
23571On success, zero is returned. On error, -1 is returned.
23572
23573@exdent Errors:
23574@end smallexample
23575
23576@table @code
b383017d 23577@item EISDIR
0ce1b118
CV
23578newpath is an existing directory, but oldpath is not a
23579directory.
23580
b383017d 23581@item EEXIST
0ce1b118
CV
23582newpath is a non-empty directory.
23583
b383017d 23584@item EBUSY
0ce1b118
CV
23585oldpath or newpath is a directory that is in use by some
23586process.
23587
b383017d 23588@item EINVAL
0ce1b118
CV
23589An attempt was made to make a directory a subdirectory
23590of itself.
23591
b383017d 23592@item ENOTDIR
0ce1b118
CV
23593A component used as a directory in oldpath or new
23594path is not a directory. Or oldpath is a directory
23595and newpath exists but is not a directory.
23596
b383017d 23597@item EFAULT
0ce1b118
CV
23598oldpathptr or newpathptr are invalid pointer values.
23599
b383017d 23600@item EACCES
0ce1b118
CV
23601No access to the file or the path of the file.
23602
23603@item ENAMETOOLONG
b383017d 23604
0ce1b118
CV
23605oldpath or newpath was too long.
23606
b383017d 23607@item ENOENT
0ce1b118
CV
23608A directory component in oldpath or newpath does not exist.
23609
b383017d 23610@item EROFS
0ce1b118
CV
23611The file is on a read-only filesystem.
23612
b383017d 23613@item ENOSPC
0ce1b118
CV
23614The device containing the file has no room for the new
23615directory entry.
23616
b383017d 23617@item EINTR
0ce1b118
CV
23618The call was interrupted by the user.
23619@end table
23620
23621@node unlink
23622@unnumberedsubsubsec unlink
23623@cindex unlink, file-i/o system call
23624
23625@smallexample
b383017d 23626@exdent Synopsis:
0ce1b118
CV
23627int unlink(const char *pathname);
23628
b383017d 23629@exdent Request:
0ce1b118
CV
23630Funlink,pathnameptr/len
23631
23632@exdent Return value:
23633On success, zero is returned. On error, -1 is returned.
23634
23635@exdent Errors:
23636@end smallexample
23637
23638@table @code
b383017d 23639@item EACCES
0ce1b118
CV
23640No access to the file or the path of the file.
23641
b383017d 23642@item EPERM
0ce1b118
CV
23643The system does not allow unlinking of directories.
23644
b383017d 23645@item EBUSY
0ce1b118
CV
23646The file pathname cannot be unlinked because it's
23647being used by another process.
23648
b383017d 23649@item EFAULT
0ce1b118
CV
23650pathnameptr is an invalid pointer value.
23651
23652@item ENAMETOOLONG
23653pathname was too long.
23654
b383017d 23655@item ENOENT
0ce1b118
CV
23656A directory component in pathname does not exist.
23657
b383017d 23658@item ENOTDIR
0ce1b118
CV
23659A component of the path is not a directory.
23660
b383017d 23661@item EROFS
0ce1b118
CV
23662The file is on a read-only filesystem.
23663
b383017d 23664@item EINTR
0ce1b118
CV
23665The call was interrupted by the user.
23666@end table
23667
23668@node stat/fstat
23669@unnumberedsubsubsec stat/fstat
23670@cindex fstat, file-i/o system call
23671@cindex stat, file-i/o system call
23672
23673@smallexample
b383017d 23674@exdent Synopsis:
0ce1b118
CV
23675int stat(const char *pathname, struct stat *buf);
23676int fstat(int fd, struct stat *buf);
23677
b383017d 23678@exdent Request:
0ce1b118
CV
23679Fstat,pathnameptr/len,bufptr
23680Ffstat,fd,bufptr
23681
23682@exdent Return value:
23683On success, zero is returned. On error, -1 is returned.
23684
23685@exdent Errors:
23686@end smallexample
23687
23688@table @code
b383017d 23689@item EBADF
0ce1b118
CV
23690fd is not a valid open file.
23691
b383017d 23692@item ENOENT
0ce1b118
CV
23693A directory component in pathname does not exist or the
23694path is an empty string.
23695
b383017d 23696@item ENOTDIR
0ce1b118
CV
23697A component of the path is not a directory.
23698
b383017d 23699@item EFAULT
0ce1b118
CV
23700pathnameptr is an invalid pointer value.
23701
b383017d 23702@item EACCES
0ce1b118
CV
23703No access to the file or the path of the file.
23704
23705@item ENAMETOOLONG
23706pathname was too long.
23707
b383017d 23708@item EINTR
0ce1b118
CV
23709The call was interrupted by the user.
23710@end table
23711
23712@node gettimeofday
23713@unnumberedsubsubsec gettimeofday
23714@cindex gettimeofday, file-i/o system call
23715
23716@smallexample
b383017d 23717@exdent Synopsis:
0ce1b118
CV
23718int gettimeofday(struct timeval *tv, void *tz);
23719
b383017d 23720@exdent Request:
0ce1b118
CV
23721Fgettimeofday,tvptr,tzptr
23722
23723@exdent Return value:
23724On success, 0 is returned, -1 otherwise.
23725
23726@exdent Errors:
23727@end smallexample
23728
23729@table @code
b383017d 23730@item EINVAL
0ce1b118
CV
23731tz is a non-NULL pointer.
23732
b383017d 23733@item EFAULT
0ce1b118
CV
23734tvptr and/or tzptr is an invalid pointer value.
23735@end table
23736
23737@node isatty
23738@unnumberedsubsubsec isatty
23739@cindex isatty, file-i/o system call
23740
23741@smallexample
b383017d 23742@exdent Synopsis:
0ce1b118
CV
23743int isatty(int fd);
23744
b383017d 23745@exdent Request:
0ce1b118
CV
23746Fisatty,fd
23747
23748@exdent Return value:
23749Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
23750
23751@exdent Errors:
23752@end smallexample
23753
23754@table @code
b383017d 23755@item EINTR
0ce1b118
CV
23756The call was interrupted by the user.
23757@end table
23758
23759@node system
23760@unnumberedsubsubsec system
23761@cindex system, file-i/o system call
23762
23763@smallexample
b383017d 23764@exdent Synopsis:
0ce1b118
CV
23765int system(const char *command);
23766
b383017d 23767@exdent Request:
0ce1b118
CV
23768Fsystem,commandptr/len
23769
23770@exdent Return value:
23771The value returned is -1 on error and the return status
23772of the command otherwise. Only the exit status of the
23773command is returned, which is extracted from the hosts
23774system return value by calling WEXITSTATUS(retval).
23775In case /bin/sh could not be executed, 127 is returned.
23776
23777@exdent Errors:
23778@end smallexample
23779
23780@table @code
b383017d 23781@item EINTR
0ce1b118
CV
23782The call was interrupted by the user.
23783@end table
23784
23785@node Protocol specific representation of datatypes
23786@subsection Protocol specific representation of datatypes
23787@cindex protocol specific representation of datatypes, in file-i/o protocol
23788
23789@menu
23790* Integral datatypes::
23791* Pointer values::
23792* struct stat::
23793* struct timeval::
23794@end menu
23795
23796@node Integral datatypes
23797@unnumberedsubsubsec Integral datatypes
23798@cindex integral datatypes, in file-i/o protocol
23799
23800The integral datatypes used in the system calls are
23801
23802@smallexample
23803int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
23804@end smallexample
23805
23806@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
23807implemented as 32 bit values in this protocol.
23808
b383017d
RM
23809@code{Long} and @code{unsigned long} are implemented as 64 bit types.
23810
0ce1b118
CV
23811@xref{Limits}, for corresponding MIN and MAX values (similar to those
23812in @file{limits.h}) to allow range checking on host and target.
23813
23814@code{time_t} datatypes are defined as seconds since the Epoch.
23815
23816All integral datatypes transferred as part of a memory read or write of a
23817structured datatype e.g.@: a @code{struct stat} have to be given in big endian
23818byte order.
23819
23820@node Pointer values
23821@unnumberedsubsubsec Pointer values
23822@cindex pointer values, in file-i/o protocol
23823
23824Pointers to target data are transmitted as they are. An exception
23825is made for pointers to buffers for which the length isn't
23826transmitted as part of the function call, namely strings. Strings
23827are transmitted as a pointer/length pair, both as hex values, e.g.@:
23828
23829@smallexample
23830@code{1aaf/12}
23831@end smallexample
23832
23833@noindent
23834which is a pointer to data of length 18 bytes at position 0x1aaf.
23835The length is defined as the full string length in bytes, including
23836the trailing null byte. Example:
23837
23838@smallexample
23839``hello, world'' at address 0x123456
23840@end smallexample
23841
23842@noindent
23843is transmitted as
23844
23845@smallexample
23846@code{123456/d}
23847@end smallexample
23848
23849@node struct stat
23850@unnumberedsubsubsec struct stat
23851@cindex struct stat, in file-i/o protocol
23852
23853The buffer of type struct stat used by the target and @value{GDBN} is defined
23854as follows:
23855
23856@smallexample
23857struct stat @{
23858 unsigned int st_dev; /* device */
23859 unsigned int st_ino; /* inode */
23860 mode_t st_mode; /* protection */
23861 unsigned int st_nlink; /* number of hard links */
23862 unsigned int st_uid; /* user ID of owner */
23863 unsigned int st_gid; /* group ID of owner */
23864 unsigned int st_rdev; /* device type (if inode device) */
23865 unsigned long st_size; /* total size, in bytes */
23866 unsigned long st_blksize; /* blocksize for filesystem I/O */
23867 unsigned long st_blocks; /* number of blocks allocated */
23868 time_t st_atime; /* time of last access */
23869 time_t st_mtime; /* time of last modification */
23870 time_t st_ctime; /* time of last change */
23871@};
23872@end smallexample
23873
23874The integral datatypes are conforming to the definitions given in the
23875approriate section (see @ref{Integral datatypes}, for details) so this
23876structure is of size 64 bytes.
23877
23878The values of several fields have a restricted meaning and/or
23879range of values.
23880
23881@smallexample
23882st_dev: 0 file
23883 1 console
23884
23885st_ino: No valid meaning for the target. Transmitted unchanged.
23886
23887st_mode: Valid mode bits are described in Appendix C. Any other
23888 bits have currently no meaning for the target.
23889
23890st_uid: No valid meaning for the target. Transmitted unchanged.
23891
23892st_gid: No valid meaning for the target. Transmitted unchanged.
23893
23894st_rdev: No valid meaning for the target. Transmitted unchanged.
23895
23896st_atime, st_mtime, st_ctime:
23897 These values have a host and file system dependent
23898 accuracy. Especially on Windows hosts the file systems
23899 don't support exact timing values.
23900@end smallexample
23901
23902The target gets a struct stat of the above representation and is
23903responsible to coerce it to the target representation before
23904continuing.
23905
23906Note that due to size differences between the host and target
23907representation of stat members, these members could eventually
23908get truncated on the target.
23909
23910@node struct timeval
23911@unnumberedsubsubsec struct timeval
23912@cindex struct timeval, in file-i/o protocol
23913
23914The buffer of type struct timeval used by the target and @value{GDBN}
23915is defined as follows:
23916
23917@smallexample
b383017d 23918struct timeval @{
0ce1b118
CV
23919 time_t tv_sec; /* second */
23920 long tv_usec; /* microsecond */
23921@};
23922@end smallexample
23923
23924The integral datatypes are conforming to the definitions given in the
23925approriate section (see @ref{Integral datatypes}, for details) so this
23926structure is of size 8 bytes.
23927
23928@node Constants
23929@subsection Constants
23930@cindex constants, in file-i/o protocol
23931
23932The following values are used for the constants inside of the
23933protocol. @value{GDBN} and target are resposible to translate these
23934values before and after the call as needed.
23935
23936@menu
23937* Open flags::
23938* mode_t values::
23939* Errno values::
23940* Lseek flags::
23941* Limits::
23942@end menu
23943
23944@node Open flags
23945@unnumberedsubsubsec Open flags
23946@cindex open flags, in file-i/o protocol
23947
23948All values are given in hexadecimal representation.
23949
23950@smallexample
23951 O_RDONLY 0x0
23952 O_WRONLY 0x1
23953 O_RDWR 0x2
23954 O_APPEND 0x8
23955 O_CREAT 0x200
23956 O_TRUNC 0x400
23957 O_EXCL 0x800
23958@end smallexample
23959
23960@node mode_t values
23961@unnumberedsubsubsec mode_t values
23962@cindex mode_t values, in file-i/o protocol
23963
23964All values are given in octal representation.
23965
23966@smallexample
23967 S_IFREG 0100000
23968 S_IFDIR 040000
23969 S_IRUSR 0400
23970 S_IWUSR 0200
23971 S_IXUSR 0100
23972 S_IRGRP 040
23973 S_IWGRP 020
23974 S_IXGRP 010
23975 S_IROTH 04
23976 S_IWOTH 02
23977 S_IXOTH 01
23978@end smallexample
23979
23980@node Errno values
23981@unnumberedsubsubsec Errno values
23982@cindex errno values, in file-i/o protocol
23983
23984All values are given in decimal representation.
23985
23986@smallexample
23987 EPERM 1
23988 ENOENT 2
23989 EINTR 4
23990 EBADF 9
23991 EACCES 13
23992 EFAULT 14
23993 EBUSY 16
23994 EEXIST 17
23995 ENODEV 19
23996 ENOTDIR 20
23997 EISDIR 21
23998 EINVAL 22
23999 ENFILE 23
24000 EMFILE 24
24001 EFBIG 27
24002 ENOSPC 28
24003 ESPIPE 29
24004 EROFS 30
24005 ENAMETOOLONG 91
24006 EUNKNOWN 9999
24007@end smallexample
24008
24009 EUNKNOWN is used as a fallback error value if a host system returns
24010 any error value not in the list of supported error numbers.
24011
24012@node Lseek flags
24013@unnumberedsubsubsec Lseek flags
24014@cindex lseek flags, in file-i/o protocol
24015
24016@smallexample
24017 SEEK_SET 0
24018 SEEK_CUR 1
24019 SEEK_END 2
24020@end smallexample
24021
24022@node Limits
24023@unnumberedsubsubsec Limits
24024@cindex limits, in file-i/o protocol
24025
24026All values are given in decimal representation.
24027
24028@smallexample
24029 INT_MIN -2147483648
24030 INT_MAX 2147483647
24031 UINT_MAX 4294967295
24032 LONG_MIN -9223372036854775808
24033 LONG_MAX 9223372036854775807
24034 ULONG_MAX 18446744073709551615
24035@end smallexample
24036
24037@node File-I/O Examples
24038@subsection File-I/O Examples
24039@cindex file-i/o examples
24040
24041Example sequence of a write call, file descriptor 3, buffer is at target
24042address 0x1234, 6 bytes should be written:
24043
24044@smallexample
24045<- @code{Fwrite,3,1234,6}
24046@emph{request memory read from target}
24047-> @code{m1234,6}
24048<- XXXXXX
24049@emph{return "6 bytes written"}
24050-> @code{F6}
24051@end smallexample
24052
24053Example sequence of a read call, file descriptor 3, buffer is at target
24054address 0x1234, 6 bytes should be read:
24055
24056@smallexample
24057<- @code{Fread,3,1234,6}
24058@emph{request memory write to target}
24059-> @code{X1234,6:XXXXXX}
24060@emph{return "6 bytes read"}
24061-> @code{F6}
24062@end smallexample
24063
24064Example sequence of a read call, call fails on the host due to invalid
24065file descriptor (EBADF):
24066
24067@smallexample
24068<- @code{Fread,3,1234,6}
24069-> @code{F-1,9}
24070@end smallexample
24071
24072Example sequence of a read call, user presses Ctrl-C before syscall on
24073host is called:
24074
24075@smallexample
24076<- @code{Fread,3,1234,6}
24077-> @code{F-1,4,C}
24078<- @code{T02}
24079@end smallexample
24080
24081Example sequence of a read call, user presses Ctrl-C after syscall on
24082host is called:
24083
24084@smallexample
24085<- @code{Fread,3,1234,6}
24086-> @code{X1234,6:XXXXXX}
24087<- @code{T02}
24088@end smallexample
24089
f418dd93
DJ
24090@include agentexpr.texi
24091
aab4e0ec 24092@include gpl.texi
eb12ee30 24093
2154891a 24094@raisesections
6826cf00 24095@include fdl.texi
2154891a 24096@lowersections
6826cf00 24097
6d2ebf8b 24098@node Index
c906108c
SS
24099@unnumbered Index
24100
24101@printindex cp
24102
24103@tex
24104% I think something like @colophon should be in texinfo. In the
24105% meantime:
24106\long\def\colophon{\hbox to0pt{}\vfill
24107\centerline{The body of this manual is set in}
24108\centerline{\fontname\tenrm,}
24109\centerline{with headings in {\bf\fontname\tenbf}}
24110\centerline{and examples in {\tt\fontname\tentt}.}
24111\centerline{{\it\fontname\tenit\/},}
24112\centerline{{\bf\fontname\tenbf}, and}
24113\centerline{{\sl\fontname\tensl\/}}
24114\centerline{are used for emphasis.}\vfill}
24115\page\colophon
24116% Blame: doc@cygnus.com, 1991.
24117@end tex
24118
c906108c 24119@bye
This page took 1.785249 seconds and 4 git commands to generate.