*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
b6ba6518 2@c Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
7d51c7de 3@c 1999, 2000, 2001, 2002, 2003, 2004, 2005
c906108c
SS
4@c Free Software Foundation, Inc.
5@c
5d161b24 6@c %**start of header
c906108c
SS
7@c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
8@c of @set vars. However, you can override filename with makeinfo -o.
9@setfilename gdb.info
10@c
11@include gdb-cfg.texi
12@c
c906108c 13@settitle Debugging with @value{GDBN}
c906108c
SS
14@setchapternewpage odd
15@c %**end of header
16
17@iftex
18@c @smallbook
19@c @cropmarks
20@end iftex
21
22@finalout
23@syncodeindex ky cp
24
41afff9a 25@c readline appendices use @vindex, @findex and @ftable,
48e934c6 26@c annotate.texi and gdbmi use @findex.
c906108c 27@syncodeindex vr cp
41afff9a 28@syncodeindex fn cp
c906108c
SS
29
30@c !!set GDB manual's edition---not the same as GDB version!
9fe8321b 31@c This is updated by GNU Press.
e9c75b65 32@set EDITION Ninth
c906108c 33
87885426
FN
34@c !!set GDB edit command default editor
35@set EDITOR /bin/ex
c906108c 36
6c0e9fb3 37@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
c906108c 38
c906108c 39@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 40@c manuals to an info tree.
03727ca6 41@dircategory Software development
96a2c332 42@direntry
03727ca6 43* Gdb: (gdb). The GNU debugger.
96a2c332
SS
44@end direntry
45
c906108c
SS
46@ifinfo
47This file documents the @sc{gnu} debugger @value{GDBN}.
48
49
9fe8321b
AC
50This is the @value{EDITION} Edition, of @cite{Debugging with
51@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
52Version @value{GDBVN}.
c906108c 53
8a037dd7 54Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,@*
7d51c7de
BR
55 1999, 2000, 2001, 2002, 2003, 2004, 2005@*
56 Free Software Foundation, Inc.
c906108c 57
e9c75b65
EZ
58Permission is granted to copy, distribute and/or modify this document
59under the terms of the GNU Free Documentation License, Version 1.1 or
60any later version published by the Free Software Foundation; with the
959acfd1
EZ
61Invariant Sections being ``Free Software'' and ``Free Software Needs
62Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
63and with the Back-Cover Texts as in (a) below.
c906108c 64
6826cf00
EZ
65(a) The Free Software Foundation's Back-Cover Text is: ``You have
66freedom to copy and modify this GNU Manual, like GNU software. Copies
67published by the Free Software Foundation raise funds for GNU
68development.''
c906108c
SS
69@end ifinfo
70
71@titlepage
72@title Debugging with @value{GDBN}
73@subtitle The @sc{gnu} Source-Level Debugger
c906108c 74@sp 1
c906108c 75@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
9e9c5ae7 76@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 77@page
c906108c
SS
78@tex
79{\parskip=0pt
53a5351d 80\hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
c906108c
SS
81\hfill {\it Debugging with @value{GDBN}}\par
82\hfill \TeX{}info \texinfoversion\par
83}
84@end tex
53a5351d 85
c906108c 86@vskip 0pt plus 1filll
8a037dd7 87Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
7d51c7de
BR
881996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
89Free Software Foundation, Inc.
c906108c 90@sp 2
c906108c
SS
91Published by the Free Software Foundation @*
9259 Temple Place - Suite 330, @*
93Boston, MA 02111-1307 USA @*
6d2ebf8b 94ISBN 1-882114-77-9 @*
e9c75b65
EZ
95
96Permission is granted to copy, distribute and/or modify this document
97under the terms of the GNU Free Documentation License, Version 1.1 or
98any later version published by the Free Software Foundation; with the
959acfd1
EZ
99Invariant Sections being ``Free Software'' and ``Free Software Needs
100Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
101and with the Back-Cover Texts as in (a) below.
e9c75b65 102
6826cf00
EZ
103(a) The Free Software Foundation's Back-Cover Text is: ``You have
104freedom to copy and modify this GNU Manual, like GNU software. Copies
105published by the Free Software Foundation raise funds for GNU
106development.''
c906108c
SS
107@end titlepage
108@page
109
6c0e9fb3 110@ifnottex
6d2ebf8b
SS
111@node Top, Summary, (dir), (dir)
112
c906108c
SS
113@top Debugging with @value{GDBN}
114
115This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
9fe8321b 117This is the @value{EDITION} Edition, for @value{GDBN} Version
c906108c
SS
118@value{GDBVN}.
119
7d51c7de 120Copyright (C) 1988-2005 Free Software Foundation, Inc.
6d2ebf8b
SS
121
122@menu
123* Summary:: Summary of @value{GDBN}
124* Sample Session:: A sample @value{GDBN} session
125
126* Invocation:: Getting in and out of @value{GDBN}
127* Commands:: @value{GDBN} commands
128* Running:: Running programs under @value{GDBN}
129* Stopping:: Stopping and continuing
130* Stack:: Examining the stack
131* Source:: Examining source files
132* Data:: Examining data
e2e0bcd1 133* Macros:: Preprocessor Macros
b37052ae 134* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 135* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
136
137* Languages:: Using @value{GDBN} with different languages
138
139* Symbols:: Examining the symbol table
140* Altering:: Altering execution
141* GDB Files:: @value{GDBN} files
142* Targets:: Specifying a debugging target
6b2f586d 143* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
144* Configurations:: Configuration-specific information
145* Controlling GDB:: Controlling @value{GDBN}
146* Sequences:: Canned sequences of commands
c4555f82 147* TUI:: @value{GDBN} Text User Interface
21c294e6 148* Interpreters:: Command Interpreters
6d2ebf8b
SS
149* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
150* Annotations:: @value{GDBN}'s annotation interface.
7162c0ca 151* GDB/MI:: @value{GDBN}'s Machine Interface.
6d2ebf8b
SS
152
153* GDB Bugs:: Reporting bugs in @value{GDBN}
154* Formatting Documentation:: How to format and print @value{GDBN} documentation
155
156* Command Line Editing:: Command Line Editing
157* Using History Interactively:: Using History Interactively
158* Installing GDB:: Installing GDB
eb12ee30 159* Maintenance Commands:: Maintenance Commands
e0ce93ac 160* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 161* Agent Expressions:: The GDB Agent Expression Mechanism
aab4e0ec
AC
162* Copying:: GNU General Public License says
163 how you can copy and share GDB
6826cf00 164* GNU Free Documentation License:: The license for this documentation
6d2ebf8b
SS
165* Index:: Index
166@end menu
167
6c0e9fb3 168@end ifnottex
c906108c 169
449f3b6c 170@contents
449f3b6c 171
6d2ebf8b 172@node Summary
c906108c
SS
173@unnumbered Summary of @value{GDBN}
174
175The purpose of a debugger such as @value{GDBN} is to allow you to see what is
176going on ``inside'' another program while it executes---or what another
177program was doing at the moment it crashed.
178
179@value{GDBN} can do four main kinds of things (plus other things in support of
180these) to help you catch bugs in the act:
181
182@itemize @bullet
183@item
184Start your program, specifying anything that might affect its behavior.
185
186@item
187Make your program stop on specified conditions.
188
189@item
190Examine what has happened, when your program has stopped.
191
192@item
193Change things in your program, so you can experiment with correcting the
194effects of one bug and go on to learn about another.
195@end itemize
196
49efadf5 197You can use @value{GDBN} to debug programs written in C and C@t{++}.
9c16f35a 198For more information, see @ref{Supported languages,,Supported languages}.
c906108c
SS
199For more information, see @ref{C,,C and C++}.
200
cce74817 201@cindex Modula-2
e632838e
AC
202Support for Modula-2 is partial. For information on Modula-2, see
203@ref{Modula-2,,Modula-2}.
c906108c 204
cce74817
JM
205@cindex Pascal
206Debugging Pascal programs which use sets, subranges, file variables, or
207nested functions does not currently work. @value{GDBN} does not support
208entering expressions, printing values, or similar features using Pascal
209syntax.
c906108c 210
c906108c
SS
211@cindex Fortran
212@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 213it may be necessary to refer to some variables with a trailing
cce74817 214underscore.
c906108c 215
b37303ee
AF
216@value{GDBN} can be used to debug programs written in Objective-C,
217using either the Apple/NeXT or the GNU Objective-C runtime.
218
c906108c
SS
219@menu
220* Free Software:: Freely redistributable software
221* Contributors:: Contributors to GDB
222@end menu
223
6d2ebf8b 224@node Free Software
c906108c
SS
225@unnumberedsec Free software
226
5d161b24 227@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
228General Public License
229(GPL). The GPL gives you the freedom to copy or adapt a licensed
230program---but every person getting a copy also gets with it the
231freedom to modify that copy (which means that they must get access to
232the source code), and the freedom to distribute further copies.
233Typical software companies use copyrights to limit your freedoms; the
234Free Software Foundation uses the GPL to preserve these freedoms.
235
236Fundamentally, the General Public License is a license which says that
237you have these freedoms and that you cannot take these freedoms away
238from anyone else.
239
2666264b 240@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
241
242The biggest deficiency in the free software community today is not in
243the software---it is the lack of good free documentation that we can
244include with the free software. Many of our most important
245programs do not come with free reference manuals and free introductory
246texts. Documentation is an essential part of any software package;
247when an important free software package does not come with a free
248manual and a free tutorial, that is a major gap. We have many such
249gaps today.
250
251Consider Perl, for instance. The tutorial manuals that people
252normally use are non-free. How did this come about? Because the
253authors of those manuals published them with restrictive terms---no
254copying, no modification, source files not available---which exclude
255them from the free software world.
256
257That wasn't the first time this sort of thing happened, and it was far
258from the last. Many times we have heard a GNU user eagerly describe a
259manual that he is writing, his intended contribution to the community,
260only to learn that he had ruined everything by signing a publication
261contract to make it non-free.
262
263Free documentation, like free software, is a matter of freedom, not
264price. The problem with the non-free manual is not that publishers
265charge a price for printed copies---that in itself is fine. (The Free
266Software Foundation sells printed copies of manuals, too.) The
267problem is the restrictions on the use of the manual. Free manuals
268are available in source code form, and give you permission to copy and
269modify. Non-free manuals do not allow this.
270
271The criteria of freedom for a free manual are roughly the same as for
272free software. Redistribution (including the normal kinds of
273commercial redistribution) must be permitted, so that the manual can
274accompany every copy of the program, both on-line and on paper.
275
276Permission for modification of the technical content is crucial too.
277When people modify the software, adding or changing features, if they
278are conscientious they will change the manual too---so they can
279provide accurate and clear documentation for the modified program. A
280manual that leaves you no choice but to write a new manual to document
281a changed version of the program is not really available to our
282community.
283
284Some kinds of limits on the way modification is handled are
285acceptable. For example, requirements to preserve the original
286author's copyright notice, the distribution terms, or the list of
287authors, are ok. It is also no problem to require modified versions
288to include notice that they were modified. Even entire sections that
289may not be deleted or changed are acceptable, as long as they deal
290with nontechnical topics (like this one). These kinds of restrictions
291are acceptable because they don't obstruct the community's normal use
292of the manual.
293
294However, it must be possible to modify all the @emph{technical}
295content of the manual, and then distribute the result in all the usual
296media, through all the usual channels. Otherwise, the restrictions
297obstruct the use of the manual, it is not free, and we need another
298manual to replace it.
299
300Please spread the word about this issue. Our community continues to
301lose manuals to proprietary publishing. If we spread the word that
302free software needs free reference manuals and free tutorials, perhaps
303the next person who wants to contribute by writing documentation will
304realize, before it is too late, that only free manuals contribute to
305the free software community.
306
307If you are writing documentation, please insist on publishing it under
308the GNU Free Documentation License or another free documentation
309license. Remember that this decision requires your approval---you
310don't have to let the publisher decide. Some commercial publishers
311will use a free license if you insist, but they will not propose the
312option; it is up to you to raise the issue and say firmly that this is
313what you want. If the publisher you are dealing with refuses, please
314try other publishers. If you're not sure whether a proposed license
42584a72 315is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
316
317You can encourage commercial publishers to sell more free, copylefted
318manuals and tutorials by buying them, and particularly by buying
319copies from the publishers that paid for their writing or for major
320improvements. Meanwhile, try to avoid buying non-free documentation
321at all. Check the distribution terms of a manual before you buy it,
322and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
323Check the history of the book, and try to reward the publishers that
324have paid or pay the authors to work on it.
959acfd1
EZ
325
326The Free Software Foundation maintains a list of free documentation
327published by other publishers, at
328@url{http://www.fsf.org/doc/other-free-books.html}.
329
6d2ebf8b 330@node Contributors
96a2c332
SS
331@unnumberedsec Contributors to @value{GDBN}
332
333Richard Stallman was the original author of @value{GDBN}, and of many
334other @sc{gnu} programs. Many others have contributed to its
335development. This section attempts to credit major contributors. One
336of the virtues of free software is that everyone is free to contribute
337to it; with regret, we cannot actually acknowledge everyone here. The
338file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
339blow-by-blow account.
340
341Changes much prior to version 2.0 are lost in the mists of time.
342
343@quotation
344@emph{Plea:} Additions to this section are particularly welcome. If you
345or your friends (or enemies, to be evenhanded) have been unfairly
346omitted from this list, we would like to add your names!
347@end quotation
348
349So that they may not regard their many labors as thankless, we
350particularly thank those who shepherded @value{GDBN} through major
351releases:
faae5abe 352Andrew Cagney (releases 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
353Jim Blandy (release 4.18);
354Jason Molenda (release 4.17);
355Stan Shebs (release 4.14);
356Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
357Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
358John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
359Jim Kingdon (releases 3.5, 3.4, and 3.3);
360and Randy Smith (releases 3.2, 3.1, and 3.0).
361
362Richard Stallman, assisted at various times by Peter TerMaat, Chris
363Hanson, and Richard Mlynarik, handled releases through 2.8.
364
b37052ae
EZ
365Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
366in @value{GDBN}, with significant additional contributions from Per
367Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
368demangler. Early work on C@t{++} was by Peter TerMaat (who also did
369much general update work leading to release 3.0).
c906108c 370
b37052ae 371@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
372object-file formats; BFD was a joint project of David V.
373Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
374
375David Johnson wrote the original COFF support; Pace Willison did
376the original support for encapsulated COFF.
377
0179ffac 378Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
379
380Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
381Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
382support.
383Jean-Daniel Fekete contributed Sun 386i support.
384Chris Hanson improved the HP9000 support.
385Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
386David Johnson contributed Encore Umax support.
387Jyrki Kuoppala contributed Altos 3068 support.
388Jeff Law contributed HP PA and SOM support.
389Keith Packard contributed NS32K support.
390Doug Rabson contributed Acorn Risc Machine support.
391Bob Rusk contributed Harris Nighthawk CX-UX support.
392Chris Smith contributed Convex support (and Fortran debugging).
393Jonathan Stone contributed Pyramid support.
394Michael Tiemann contributed SPARC support.
395Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
396Pace Willison contributed Intel 386 support.
397Jay Vosburgh contributed Symmetry support.
a37295f9 398Marko Mlinar contributed OpenRISC 1000 support.
c906108c 399
1104b9e7 400Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
401
402Rich Schaefer and Peter Schauer helped with support of SunOS shared
403libraries.
404
405Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
406about several machine instruction sets.
407
408Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
409remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
410contributed remote debugging modules for the i960, VxWorks, A29K UDI,
411and RDI targets, respectively.
412
413Brian Fox is the author of the readline libraries providing
414command-line editing and command history.
415
7a292a7a
SS
416Andrew Beers of SUNY Buffalo wrote the language-switching code, the
417Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 418
5d161b24 419Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 420He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 421symbols.
c906108c 422
f24c5e49
KI
423Hitachi America (now Renesas America), Ltd. sponsored the support for
424H8/300, H8/500, and Super-H processors.
c906108c
SS
425
426NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
427
f24c5e49
KI
428Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
429processors.
c906108c
SS
430
431Toshiba sponsored the support for the TX39 Mips processor.
432
433Matsushita sponsored the support for the MN10200 and MN10300 processors.
434
96a2c332 435Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
436
437Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
438watchpoints.
439
440Michael Snyder added support for tracepoints.
441
442Stu Grossman wrote gdbserver.
443
444Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 445nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
446
447The following people at the Hewlett-Packard Company contributed
448support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 449(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
d0d5df6f
AC
450compiler, and the Text User Interface (nee Terminal User Interface):
451Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
452Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
453provided HP-specific information in this manual.
c906108c 454
b37052ae
EZ
455DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
456Robert Hoehne made significant contributions to the DJGPP port.
457
96a2c332
SS
458Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
459development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
460fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
461Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
462Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
463Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
464Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
465addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
466JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
467Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
468Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
469Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
470Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
471Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
472Zuhn have made contributions both large and small.
c906108c 473
ffed4509
AC
474Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
475Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
476
e2e0bcd1
JB
477Jim Blandy added support for preprocessor macros, while working for Red
478Hat.
c906108c 479
a9967aef
AC
480Andrew Cagney designed @value{GDBN}'s architecture vector. Many
481people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
482Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
483Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
484Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
485with the migration of old architectures to this new framework.
486
6d2ebf8b 487@node Sample Session
c906108c
SS
488@chapter A Sample @value{GDBN} Session
489
490You can use this manual at your leisure to read all about @value{GDBN}.
491However, a handful of commands are enough to get started using the
492debugger. This chapter illustrates those commands.
493
494@iftex
495In this sample session, we emphasize user input like this: @b{input},
496to make it easier to pick out from the surrounding output.
497@end iftex
498
499@c FIXME: this example may not be appropriate for some configs, where
500@c FIXME...primary interest is in remote use.
501
502One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
503processor) exhibits the following bug: sometimes, when we change its
504quote strings from the default, the commands used to capture one macro
505definition within another stop working. In the following short @code{m4}
506session, we define a macro @code{foo} which expands to @code{0000}; we
507then use the @code{m4} built-in @code{defn} to define @code{bar} as the
508same thing. However, when we change the open quote string to
509@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
510procedure fails to define a new synonym @code{baz}:
511
512@smallexample
513$ @b{cd gnu/m4}
514$ @b{./m4}
515@b{define(foo,0000)}
516
517@b{foo}
5180000
519@b{define(bar,defn(`foo'))}
520
521@b{bar}
5220000
523@b{changequote(<QUOTE>,<UNQUOTE>)}
524
525@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
526@b{baz}
527@b{C-d}
528m4: End of input: 0: fatal error: EOF in string
529@end smallexample
530
531@noindent
532Let us use @value{GDBN} to try to see what is going on.
533
c906108c
SS
534@smallexample
535$ @b{@value{GDBP} m4}
536@c FIXME: this falsifies the exact text played out, to permit smallbook
537@c FIXME... format to come out better.
538@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 539 of it under certain conditions; type "show copying" to see
c906108c 540 the conditions.
5d161b24 541There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
542 for details.
543
544@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
545(@value{GDBP})
546@end smallexample
c906108c
SS
547
548@noindent
549@value{GDBN} reads only enough symbol data to know where to find the
550rest when needed; as a result, the first prompt comes up very quickly.
551We now tell @value{GDBN} to use a narrower display width than usual, so
552that examples fit in this manual.
553
554@smallexample
555(@value{GDBP}) @b{set width 70}
556@end smallexample
557
558@noindent
559We need to see how the @code{m4} built-in @code{changequote} works.
560Having looked at the source, we know the relevant subroutine is
561@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
562@code{break} command.
563
564@smallexample
565(@value{GDBP}) @b{break m4_changequote}
566Breakpoint 1 at 0x62f4: file builtin.c, line 879.
567@end smallexample
568
569@noindent
570Using the @code{run} command, we start @code{m4} running under @value{GDBN}
571control; as long as control does not reach the @code{m4_changequote}
572subroutine, the program runs as usual:
573
574@smallexample
575(@value{GDBP}) @b{run}
576Starting program: /work/Editorial/gdb/gnu/m4/m4
577@b{define(foo,0000)}
578
579@b{foo}
5800000
581@end smallexample
582
583@noindent
584To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
585suspends execution of @code{m4}, displaying information about the
586context where it stops.
587
588@smallexample
589@b{changequote(<QUOTE>,<UNQUOTE>)}
590
5d161b24 591Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
592 at builtin.c:879
593879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
594@end smallexample
595
596@noindent
597Now we use the command @code{n} (@code{next}) to advance execution to
598the next line of the current function.
599
600@smallexample
601(@value{GDBP}) @b{n}
602882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
603 : nil,
604@end smallexample
605
606@noindent
607@code{set_quotes} looks like a promising subroutine. We can go into it
608by using the command @code{s} (@code{step}) instead of @code{next}.
609@code{step} goes to the next line to be executed in @emph{any}
610subroutine, so it steps into @code{set_quotes}.
611
612@smallexample
613(@value{GDBP}) @b{s}
614set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
615 at input.c:530
616530 if (lquote != def_lquote)
617@end smallexample
618
619@noindent
620The display that shows the subroutine where @code{m4} is now
621suspended (and its arguments) is called a stack frame display. It
622shows a summary of the stack. We can use the @code{backtrace}
623command (which can also be spelled @code{bt}), to see where we are
624in the stack as a whole: the @code{backtrace} command displays a
625stack frame for each active subroutine.
626
627@smallexample
628(@value{GDBP}) @b{bt}
629#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
630 at input.c:530
5d161b24 631#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
632 at builtin.c:882
633#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
634#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
635 at macro.c:71
636#4 0x79dc in expand_input () at macro.c:40
637#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
638@end smallexample
639
640@noindent
641We step through a few more lines to see what happens. The first two
642times, we can use @samp{s}; the next two times we use @code{n} to avoid
643falling into the @code{xstrdup} subroutine.
644
645@smallexample
646(@value{GDBP}) @b{s}
6470x3b5c 532 if (rquote != def_rquote)
648(@value{GDBP}) @b{s}
6490x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
650def_lquote : xstrdup(lq);
651(@value{GDBP}) @b{n}
652536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
653 : xstrdup(rq);
654(@value{GDBP}) @b{n}
655538 len_lquote = strlen(rquote);
656@end smallexample
657
658@noindent
659The last line displayed looks a little odd; we can examine the variables
660@code{lquote} and @code{rquote} to see if they are in fact the new left
661and right quotes we specified. We use the command @code{p}
662(@code{print}) to see their values.
663
664@smallexample
665(@value{GDBP}) @b{p lquote}
666$1 = 0x35d40 "<QUOTE>"
667(@value{GDBP}) @b{p rquote}
668$2 = 0x35d50 "<UNQUOTE>"
669@end smallexample
670
671@noindent
672@code{lquote} and @code{rquote} are indeed the new left and right quotes.
673To look at some context, we can display ten lines of source
674surrounding the current line with the @code{l} (@code{list}) command.
675
676@smallexample
677(@value{GDBP}) @b{l}
678533 xfree(rquote);
679534
680535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
681 : xstrdup (lq);
682536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
683 : xstrdup (rq);
684537
685538 len_lquote = strlen(rquote);
686539 len_rquote = strlen(lquote);
687540 @}
688541
689542 void
690@end smallexample
691
692@noindent
693Let us step past the two lines that set @code{len_lquote} and
694@code{len_rquote}, and then examine the values of those variables.
695
696@smallexample
697(@value{GDBP}) @b{n}
698539 len_rquote = strlen(lquote);
699(@value{GDBP}) @b{n}
700540 @}
701(@value{GDBP}) @b{p len_lquote}
702$3 = 9
703(@value{GDBP}) @b{p len_rquote}
704$4 = 7
705@end smallexample
706
707@noindent
708That certainly looks wrong, assuming @code{len_lquote} and
709@code{len_rquote} are meant to be the lengths of @code{lquote} and
710@code{rquote} respectively. We can set them to better values using
711the @code{p} command, since it can print the value of
712any expression---and that expression can include subroutine calls and
713assignments.
714
715@smallexample
716(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
717$5 = 7
718(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
719$6 = 9
720@end smallexample
721
722@noindent
723Is that enough to fix the problem of using the new quotes with the
724@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
725executing with the @code{c} (@code{continue}) command, and then try the
726example that caused trouble initially:
727
728@smallexample
729(@value{GDBP}) @b{c}
730Continuing.
731
732@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
733
734baz
7350000
736@end smallexample
737
738@noindent
739Success! The new quotes now work just as well as the default ones. The
740problem seems to have been just the two typos defining the wrong
741lengths. We allow @code{m4} exit by giving it an EOF as input:
742
743@smallexample
744@b{C-d}
745Program exited normally.
746@end smallexample
747
748@noindent
749The message @samp{Program exited normally.} is from @value{GDBN}; it
750indicates @code{m4} has finished executing. We can end our @value{GDBN}
751session with the @value{GDBN} @code{quit} command.
752
753@smallexample
754(@value{GDBP}) @b{quit}
755@end smallexample
c906108c 756
6d2ebf8b 757@node Invocation
c906108c
SS
758@chapter Getting In and Out of @value{GDBN}
759
760This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 761The essentials are:
c906108c 762@itemize @bullet
5d161b24 763@item
53a5351d 764type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 765@item
c906108c
SS
766type @kbd{quit} or @kbd{C-d} to exit.
767@end itemize
768
769@menu
770* Invoking GDB:: How to start @value{GDBN}
771* Quitting GDB:: How to quit @value{GDBN}
772* Shell Commands:: How to use shell commands inside @value{GDBN}
0fac0b41 773* Logging output:: How to log @value{GDBN}'s output to a file
c906108c
SS
774@end menu
775
6d2ebf8b 776@node Invoking GDB
c906108c
SS
777@section Invoking @value{GDBN}
778
c906108c
SS
779Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
780@value{GDBN} reads commands from the terminal until you tell it to exit.
781
782You can also run @code{@value{GDBP}} with a variety of arguments and options,
783to specify more of your debugging environment at the outset.
784
c906108c
SS
785The command-line options described here are designed
786to cover a variety of situations; in some environments, some of these
5d161b24 787options may effectively be unavailable.
c906108c
SS
788
789The most usual way to start @value{GDBN} is with one argument,
790specifying an executable program:
791
474c8240 792@smallexample
c906108c 793@value{GDBP} @var{program}
474c8240 794@end smallexample
c906108c 795
c906108c
SS
796@noindent
797You can also start with both an executable program and a core file
798specified:
799
474c8240 800@smallexample
c906108c 801@value{GDBP} @var{program} @var{core}
474c8240 802@end smallexample
c906108c
SS
803
804You can, instead, specify a process ID as a second argument, if you want
805to debug a running process:
806
474c8240 807@smallexample
c906108c 808@value{GDBP} @var{program} 1234
474c8240 809@end smallexample
c906108c
SS
810
811@noindent
812would attach @value{GDBN} to process @code{1234} (unless you also have a file
813named @file{1234}; @value{GDBN} does check for a core file first).
814
c906108c 815Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
816complete operating system; when you use @value{GDBN} as a remote
817debugger attached to a bare board, there may not be any notion of
818``process'', and there is often no way to get a core dump. @value{GDBN}
819will warn you if it is unable to attach or to read core dumps.
c906108c 820
aa26fa3a
TT
821You can optionally have @code{@value{GDBP}} pass any arguments after the
822executable file to the inferior using @code{--args}. This option stops
823option processing.
474c8240 824@smallexample
aa26fa3a 825gdb --args gcc -O2 -c foo.c
474c8240 826@end smallexample
aa26fa3a
TT
827This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
828@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
829
96a2c332 830You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
831@value{GDBN}'s non-warranty, by specifying @code{-silent}:
832
833@smallexample
834@value{GDBP} -silent
835@end smallexample
836
837@noindent
838You can further control how @value{GDBN} starts up by using command-line
839options. @value{GDBN} itself can remind you of the options available.
840
841@noindent
842Type
843
474c8240 844@smallexample
c906108c 845@value{GDBP} -help
474c8240 846@end smallexample
c906108c
SS
847
848@noindent
849to display all available options and briefly describe their use
850(@samp{@value{GDBP} -h} is a shorter equivalent).
851
852All options and command line arguments you give are processed
853in sequential order. The order makes a difference when the
854@samp{-x} option is used.
855
856
857@menu
c906108c
SS
858* File Options:: Choosing files
859* Mode Options:: Choosing modes
6fc08d32 860* Startup:: What @value{GDBN} does during startup
c906108c
SS
861@end menu
862
6d2ebf8b 863@node File Options
c906108c
SS
864@subsection Choosing files
865
2df3850c 866When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
867specifying an executable file and core file (or process ID). This is
868the same as if the arguments were specified by the @samp{-se} and
19837790
MS
869@samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
870first argument that does not have an associated option flag as
871equivalent to the @samp{-se} option followed by that argument; and the
872second argument that does not have an associated option flag, if any, as
873equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
874If the second argument begins with a decimal digit, @value{GDBN} will
875first attempt to attach to it as a process, and if that fails, attempt
876to open it as a corefile. If you have a corefile whose name begins with
b383017d 877a digit, you can prevent @value{GDBN} from treating it as a pid by
79f12247 878prefixing it with @file{./}, eg. @file{./12345}.
7a292a7a
SS
879
880If @value{GDBN} has not been configured to included core file support,
881such as for most embedded targets, then it will complain about a second
882argument and ignore it.
c906108c
SS
883
884Many options have both long and short forms; both are shown in the
885following list. @value{GDBN} also recognizes the long forms if you truncate
886them, so long as enough of the option is present to be unambiguous.
887(If you prefer, you can flag option arguments with @samp{--} rather
888than @samp{-}, though we illustrate the more usual convention.)
889
d700128c
EZ
890@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
891@c way, both those who look for -foo and --foo in the index, will find
892@c it.
893
c906108c
SS
894@table @code
895@item -symbols @var{file}
896@itemx -s @var{file}
d700128c
EZ
897@cindex @code{--symbols}
898@cindex @code{-s}
c906108c
SS
899Read symbol table from file @var{file}.
900
901@item -exec @var{file}
902@itemx -e @var{file}
d700128c
EZ
903@cindex @code{--exec}
904@cindex @code{-e}
7a292a7a
SS
905Use file @var{file} as the executable file to execute when appropriate,
906and for examining pure data in conjunction with a core dump.
c906108c
SS
907
908@item -se @var{file}
d700128c 909@cindex @code{--se}
c906108c
SS
910Read symbol table from file @var{file} and use it as the executable
911file.
912
c906108c
SS
913@item -core @var{file}
914@itemx -c @var{file}
d700128c
EZ
915@cindex @code{--core}
916@cindex @code{-c}
b383017d 917Use file @var{file} as a core dump to examine.
c906108c
SS
918
919@item -c @var{number}
19837790
MS
920@item -pid @var{number}
921@itemx -p @var{number}
922@cindex @code{--pid}
923@cindex @code{-p}
924Connect to process ID @var{number}, as with the @code{attach} command.
925If there is no such process, @value{GDBN} will attempt to open a core
926file named @var{number}.
c906108c
SS
927
928@item -command @var{file}
929@itemx -x @var{file}
d700128c
EZ
930@cindex @code{--command}
931@cindex @code{-x}
c906108c
SS
932Execute @value{GDBN} commands from file @var{file}. @xref{Command
933Files,, Command files}.
934
935@item -directory @var{directory}
936@itemx -d @var{directory}
d700128c
EZ
937@cindex @code{--directory}
938@cindex @code{-d}
c906108c
SS
939Add @var{directory} to the path to search for source files.
940
c906108c
SS
941@item -r
942@itemx -readnow
d700128c
EZ
943@cindex @code{--readnow}
944@cindex @code{-r}
c906108c
SS
945Read each symbol file's entire symbol table immediately, rather than
946the default, which is to read it incrementally as it is needed.
947This makes startup slower, but makes future operations faster.
53a5351d 948
c906108c
SS
949@end table
950
6d2ebf8b 951@node Mode Options
c906108c
SS
952@subsection Choosing modes
953
954You can run @value{GDBN} in various alternative modes---for example, in
955batch mode or quiet mode.
956
957@table @code
958@item -nx
959@itemx -n
d700128c
EZ
960@cindex @code{--nx}
961@cindex @code{-n}
96565e91 962Do not execute commands found in any initialization files. Normally,
2df3850c
JM
963@value{GDBN} executes the commands in these files after all the command
964options and arguments have been processed. @xref{Command Files,,Command
965files}.
c906108c
SS
966
967@item -quiet
d700128c 968@itemx -silent
c906108c 969@itemx -q
d700128c
EZ
970@cindex @code{--quiet}
971@cindex @code{--silent}
972@cindex @code{-q}
c906108c
SS
973``Quiet''. Do not print the introductory and copyright messages. These
974messages are also suppressed in batch mode.
975
976@item -batch
d700128c 977@cindex @code{--batch}
c906108c
SS
978Run in batch mode. Exit with status @code{0} after processing all the
979command files specified with @samp{-x} (and all commands from
980initialization files, if not inhibited with @samp{-n}). Exit with
981nonzero status if an error occurs in executing the @value{GDBN} commands
982in the command files.
983
2df3850c
JM
984Batch mode may be useful for running @value{GDBN} as a filter, for
985example to download and run a program on another computer; in order to
986make this more useful, the message
c906108c 987
474c8240 988@smallexample
c906108c 989Program exited normally.
474c8240 990@end smallexample
c906108c
SS
991
992@noindent
2df3850c
JM
993(which is ordinarily issued whenever a program running under
994@value{GDBN} control terminates) is not issued when running in batch
995mode.
996
997@item -nowindows
998@itemx -nw
d700128c
EZ
999@cindex @code{--nowindows}
1000@cindex @code{-nw}
2df3850c 1001``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1002(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1003interface. If no GUI is available, this option has no effect.
1004
1005@item -windows
1006@itemx -w
d700128c
EZ
1007@cindex @code{--windows}
1008@cindex @code{-w}
2df3850c
JM
1009If @value{GDBN} includes a GUI, then this option requires it to be
1010used if possible.
c906108c
SS
1011
1012@item -cd @var{directory}
d700128c 1013@cindex @code{--cd}
c906108c
SS
1014Run @value{GDBN} using @var{directory} as its working directory,
1015instead of the current directory.
1016
c906108c
SS
1017@item -fullname
1018@itemx -f
d700128c
EZ
1019@cindex @code{--fullname}
1020@cindex @code{-f}
7a292a7a
SS
1021@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1022subprocess. It tells @value{GDBN} to output the full file name and line
1023number in a standard, recognizable fashion each time a stack frame is
1024displayed (which includes each time your program stops). This
1025recognizable format looks like two @samp{\032} characters, followed by
1026the file name, line number and character position separated by colons,
1027and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1028@samp{\032} characters as a signal to display the source code for the
1029frame.
c906108c 1030
d700128c
EZ
1031@item -epoch
1032@cindex @code{--epoch}
1033The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1034@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1035routines so as to allow Epoch to display values of expressions in a
1036separate window.
1037
1038@item -annotate @var{level}
1039@cindex @code{--annotate}
1040This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1041effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1042(@pxref{Annotations}). The annotation @var{level} controls how much
1043information @value{GDBN} prints together with its prompt, values of
1044expressions, source lines, and other types of output. Level 0 is the
1045normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1046@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1047that control @value{GDBN}, and level 2 has been deprecated.
1048
265eeb58 1049The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1050(@pxref{GDB/MI}).
d700128c 1051
aa26fa3a
TT
1052@item --args
1053@cindex @code{--args}
1054Change interpretation of command line so that arguments following the
1055executable file are passed as command line arguments to the inferior.
1056This option stops option processing.
1057
2df3850c
JM
1058@item -baud @var{bps}
1059@itemx -b @var{bps}
d700128c
EZ
1060@cindex @code{--baud}
1061@cindex @code{-b}
c906108c
SS
1062Set the line speed (baud rate or bits per second) of any serial
1063interface used by @value{GDBN} for remote debugging.
c906108c 1064
f47b1503
AS
1065@item -l @var{timeout}
1066@cindex @code{-l}
1067Set the timeout (in seconds) of any communication used by @value{GDBN}
1068for remote debugging.
1069
c906108c 1070@item -tty @var{device}
d700128c
EZ
1071@itemx -t @var{device}
1072@cindex @code{--tty}
1073@cindex @code{-t}
c906108c
SS
1074Run using @var{device} for your program's standard input and output.
1075@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1076
53a5351d 1077@c resolve the situation of these eventually
c4555f82
SC
1078@item -tui
1079@cindex @code{--tui}
d0d5df6f
AC
1080Activate the @dfn{Text User Interface} when starting. The Text User
1081Interface manages several text windows on the terminal, showing
1082source, assembly, registers and @value{GDBN} command outputs
1083(@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1084Text User Interface can be enabled by invoking the program
1085@samp{gdbtui}. Do not use this option if you run @value{GDBN} from
1086Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1087
1088@c @item -xdb
d700128c 1089@c @cindex @code{--xdb}
53a5351d
JM
1090@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1091@c For information, see the file @file{xdb_trans.html}, which is usually
1092@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1093@c systems.
1094
d700128c
EZ
1095@item -interpreter @var{interp}
1096@cindex @code{--interpreter}
1097Use the interpreter @var{interp} for interface with the controlling
1098program or device. This option is meant to be set by programs which
94bbb2c0 1099communicate with @value{GDBN} using it as a back end.
21c294e6 1100@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1101
da0f9dcd 1102@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1103@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1104The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1105previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1106selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1107@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1108
1109@item -write
1110@cindex @code{--write}
1111Open the executable and core files for both reading and writing. This
1112is equivalent to the @samp{set write on} command inside @value{GDBN}
1113(@pxref{Patching}).
1114
1115@item -statistics
1116@cindex @code{--statistics}
1117This option causes @value{GDBN} to print statistics about time and
1118memory usage after it completes each command and returns to the prompt.
1119
1120@item -version
1121@cindex @code{--version}
1122This option causes @value{GDBN} to print its version number and
1123no-warranty blurb, and exit.
1124
c906108c
SS
1125@end table
1126
6fc08d32
EZ
1127@node Startup
1128@subsection What @value{GDBN} does during startup
1129@cindex @value{GDBN} startup
1130
1131Here's the description of what @value{GDBN} does during session startup:
1132
1133@enumerate
1134@item
1135Sets up the command interpreter as specified by the command line
1136(@pxref{Mode Options, interpreter}).
1137
1138@item
1139@cindex init file
1140Reads the @dfn{init file} (if any) in your home directory@footnote{On
1141DOS/Windows systems, the home directory is the one pointed to by the
1142@code{HOME} environment variable.} and executes all the commands in
1143that file.
1144
1145@item
1146Processes command line options and operands.
1147
1148@item
1149Reads and executes the commands from init file (if any) in the current
119b882a
EZ
1150working directory. This is only done if the current directory is
1151different from your home directory. Thus, you can have more than one
1152init file, one generic in your home directory, and another, specific
1153to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1154@value{GDBN}.
1155
1156@item
1157Reads command files specified by the @samp{-x} option. @xref{Command
1158Files}, for more details about @value{GDBN} command files.
1159
1160@item
1161Reads the command history recorded in the @dfn{history file}.
d620b259 1162@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1163files where @value{GDBN} records it.
1164@end enumerate
1165
1166Init files use the same syntax as @dfn{command files} (@pxref{Command
1167Files}) and are processed by @value{GDBN} in the same way. The init
1168file in your home directory can set options (such as @samp{set
1169complaints}) that affect subsequent processing of command line options
1170and operands. Init files are not executed if you use the @samp{-nx}
1171option (@pxref{Mode Options, ,Choosing modes}).
1172
1173@cindex init file name
1174@cindex @file{.gdbinit}
119b882a 1175The @value{GDBN} init files are normally called @file{.gdbinit}.
6fc08d32
EZ
1176On some configurations of @value{GDBN}, the init file is known by a
1177different name (these are typically environments where a specialized
1178form of @value{GDBN} may need to coexist with other forms, hence a
1179different name for the specialized version's init file). These are the
1180environments with special init file names:
1181
6fc08d32 1182@itemize @bullet
119b882a
EZ
1183@cindex @file{gdb.ini}
1184@item
1185The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1186the limitations of file names imposed by DOS filesystems. The Windows
1187ports of @value{GDBN} use the standard name, but if they find a
1188@file{gdb.ini} file, they warn you about that and suggest to rename
1189the file to the standard name.
1190
1191@cindex @file{.vxgdbinit}
6fc08d32
EZ
1192@item
1193VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
1194
1195@cindex @file{.os68gdbinit}
1196@item
1197OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
1198
1199@cindex @file{.esgdbinit}
1200@item
1201ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
1202
1203@item
1204CISCO 68k: @file{.cisco-gdbinit}
1205@end itemize
1206
1207
6d2ebf8b 1208@node Quitting GDB
c906108c
SS
1209@section Quitting @value{GDBN}
1210@cindex exiting @value{GDBN}
1211@cindex leaving @value{GDBN}
1212
1213@table @code
1214@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1215@kindex q @r{(@code{quit})}
96a2c332
SS
1216@item quit @r{[}@var{expression}@r{]}
1217@itemx q
1218To exit @value{GDBN}, use the @code{quit} command (abbreviated
1219@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1220do not supply @var{expression}, @value{GDBN} will terminate normally;
1221otherwise it will terminate using the result of @var{expression} as the
1222error code.
c906108c
SS
1223@end table
1224
1225@cindex interrupt
1226An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1227terminates the action of any @value{GDBN} command that is in progress and
1228returns to @value{GDBN} command level. It is safe to type the interrupt
1229character at any time because @value{GDBN} does not allow it to take effect
1230until a time when it is safe.
1231
c906108c
SS
1232If you have been using @value{GDBN} to control an attached process or
1233device, you can release it with the @code{detach} command
1234(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1235
6d2ebf8b 1236@node Shell Commands
c906108c
SS
1237@section Shell commands
1238
1239If you need to execute occasional shell commands during your
1240debugging session, there is no need to leave or suspend @value{GDBN}; you can
1241just use the @code{shell} command.
1242
1243@table @code
1244@kindex shell
1245@cindex shell escape
1246@item shell @var{command string}
1247Invoke a standard shell to execute @var{command string}.
c906108c 1248If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1249shell to run. Otherwise @value{GDBN} uses the default shell
1250(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1251@end table
1252
1253The utility @code{make} is often needed in development environments.
1254You do not have to use the @code{shell} command for this purpose in
1255@value{GDBN}:
1256
1257@table @code
1258@kindex make
1259@cindex calling make
1260@item make @var{make-args}
1261Execute the @code{make} program with the specified
1262arguments. This is equivalent to @samp{shell make @var{make-args}}.
1263@end table
1264
0fac0b41
DJ
1265@node Logging output
1266@section Logging output
1267@cindex logging @value{GDBN} output
9c16f35a 1268@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1269
1270You may want to save the output of @value{GDBN} commands to a file.
1271There are several commands to control @value{GDBN}'s logging.
1272
1273@table @code
1274@kindex set logging
1275@item set logging on
1276Enable logging.
1277@item set logging off
1278Disable logging.
9c16f35a 1279@cindex logging file name
0fac0b41
DJ
1280@item set logging file @var{file}
1281Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1282@item set logging overwrite [on|off]
1283By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1284you want @code{set logging on} to overwrite the logfile instead.
1285@item set logging redirect [on|off]
1286By default, @value{GDBN} output will go to both the terminal and the logfile.
1287Set @code{redirect} if you want output to go only to the log file.
1288@kindex show logging
1289@item show logging
1290Show the current values of the logging settings.
1291@end table
1292
6d2ebf8b 1293@node Commands
c906108c
SS
1294@chapter @value{GDBN} Commands
1295
1296You can abbreviate a @value{GDBN} command to the first few letters of the command
1297name, if that abbreviation is unambiguous; and you can repeat certain
1298@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1299key to get @value{GDBN} to fill out the rest of a word in a command (or to
1300show you the alternatives available, if there is more than one possibility).
1301
1302@menu
1303* Command Syntax:: How to give commands to @value{GDBN}
1304* Completion:: Command completion
1305* Help:: How to ask @value{GDBN} for help
1306@end menu
1307
6d2ebf8b 1308@node Command Syntax
c906108c
SS
1309@section Command syntax
1310
1311A @value{GDBN} command is a single line of input. There is no limit on
1312how long it can be. It starts with a command name, which is followed by
1313arguments whose meaning depends on the command name. For example, the
1314command @code{step} accepts an argument which is the number of times to
1315step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1316with no arguments. Some commands do not allow any arguments.
c906108c
SS
1317
1318@cindex abbreviation
1319@value{GDBN} command names may always be truncated if that abbreviation is
1320unambiguous. Other possible command abbreviations are listed in the
1321documentation for individual commands. In some cases, even ambiguous
1322abbreviations are allowed; for example, @code{s} is specially defined as
1323equivalent to @code{step} even though there are other commands whose
1324names start with @code{s}. You can test abbreviations by using them as
1325arguments to the @code{help} command.
1326
1327@cindex repeating commands
41afff9a 1328@kindex RET @r{(repeat last command)}
c906108c 1329A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1330repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1331will not repeat this way; these are commands whose unintentional
1332repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1333repeat. User-defined commands can disable this feature; see
1334@ref{Define, dont-repeat}.
c906108c
SS
1335
1336The @code{list} and @code{x} commands, when you repeat them with
1337@key{RET}, construct new arguments rather than repeating
1338exactly as typed. This permits easy scanning of source or memory.
1339
1340@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1341output, in a way similar to the common utility @code{more}
1342(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1343@key{RET} too many in this situation, @value{GDBN} disables command
1344repetition after any command that generates this sort of display.
1345
41afff9a 1346@kindex # @r{(a comment)}
c906108c
SS
1347@cindex comment
1348Any text from a @kbd{#} to the end of the line is a comment; it does
1349nothing. This is useful mainly in command files (@pxref{Command
1350Files,,Command files}).
1351
88118b3a
TT
1352@cindex repeating command sequences
1353@kindex C-o @r{(operate-and-get-next)}
1354The @kbd{C-o} binding is useful for repeating a complex sequence of
1355commands. This command accepts the current line, like @kbd{RET}, and
1356then fetches the next line relative to the current line from the history
1357for editing.
1358
6d2ebf8b 1359@node Completion
c906108c
SS
1360@section Command completion
1361
1362@cindex completion
1363@cindex word completion
1364@value{GDBN} can fill in the rest of a word in a command for you, if there is
1365only one possibility; it can also show you what the valid possibilities
1366are for the next word in a command, at any time. This works for @value{GDBN}
1367commands, @value{GDBN} subcommands, and the names of symbols in your program.
1368
1369Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1370of a word. If there is only one possibility, @value{GDBN} fills in the
1371word, and waits for you to finish the command (or press @key{RET} to
1372enter it). For example, if you type
1373
1374@c FIXME "@key" does not distinguish its argument sufficiently to permit
1375@c complete accuracy in these examples; space introduced for clarity.
1376@c If texinfo enhancements make it unnecessary, it would be nice to
1377@c replace " @key" by "@key" in the following...
474c8240 1378@smallexample
c906108c 1379(@value{GDBP}) info bre @key{TAB}
474c8240 1380@end smallexample
c906108c
SS
1381
1382@noindent
1383@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1384the only @code{info} subcommand beginning with @samp{bre}:
1385
474c8240 1386@smallexample
c906108c 1387(@value{GDBP}) info breakpoints
474c8240 1388@end smallexample
c906108c
SS
1389
1390@noindent
1391You can either press @key{RET} at this point, to run the @code{info
1392breakpoints} command, or backspace and enter something else, if
1393@samp{breakpoints} does not look like the command you expected. (If you
1394were sure you wanted @code{info breakpoints} in the first place, you
1395might as well just type @key{RET} immediately after @samp{info bre},
1396to exploit command abbreviations rather than command completion).
1397
1398If there is more than one possibility for the next word when you press
1399@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1400characters and try again, or just press @key{TAB} a second time;
1401@value{GDBN} displays all the possible completions for that word. For
1402example, you might want to set a breakpoint on a subroutine whose name
1403begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1404just sounds the bell. Typing @key{TAB} again displays all the
1405function names in your program that begin with those characters, for
1406example:
1407
474c8240 1408@smallexample
c906108c
SS
1409(@value{GDBP}) b make_ @key{TAB}
1410@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1411make_a_section_from_file make_environ
1412make_abs_section make_function_type
1413make_blockvector make_pointer_type
1414make_cleanup make_reference_type
c906108c
SS
1415make_command make_symbol_completion_list
1416(@value{GDBP}) b make_
474c8240 1417@end smallexample
c906108c
SS
1418
1419@noindent
1420After displaying the available possibilities, @value{GDBN} copies your
1421partial input (@samp{b make_} in the example) so you can finish the
1422command.
1423
1424If you just want to see the list of alternatives in the first place, you
b37052ae 1425can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1426means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1427key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1428one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1429
1430@cindex quotes in commands
1431@cindex completion of quoted strings
1432Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1433parentheses or other characters that @value{GDBN} normally excludes from
1434its notion of a word. To permit word completion to work in this
1435situation, you may enclose words in @code{'} (single quote marks) in
1436@value{GDBN} commands.
c906108c 1437
c906108c 1438The most likely situation where you might need this is in typing the
b37052ae
EZ
1439name of a C@t{++} function. This is because C@t{++} allows function
1440overloading (multiple definitions of the same function, distinguished
1441by argument type). For example, when you want to set a breakpoint you
1442may need to distinguish whether you mean the version of @code{name}
1443that takes an @code{int} parameter, @code{name(int)}, or the version
1444that takes a @code{float} parameter, @code{name(float)}. To use the
1445word-completion facilities in this situation, type a single quote
1446@code{'} at the beginning of the function name. This alerts
1447@value{GDBN} that it may need to consider more information than usual
1448when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1449
474c8240 1450@smallexample
96a2c332 1451(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1452bubble(double,double) bubble(int,int)
1453(@value{GDBP}) b 'bubble(
474c8240 1454@end smallexample
c906108c
SS
1455
1456In some cases, @value{GDBN} can tell that completing a name requires using
1457quotes. When this happens, @value{GDBN} inserts the quote for you (while
1458completing as much as it can) if you do not type the quote in the first
1459place:
1460
474c8240 1461@smallexample
c906108c
SS
1462(@value{GDBP}) b bub @key{TAB}
1463@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1464(@value{GDBP}) b 'bubble(
474c8240 1465@end smallexample
c906108c
SS
1466
1467@noindent
1468In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1469you have not yet started typing the argument list when you ask for
1470completion on an overloaded symbol.
1471
d4f3574e 1472For more information about overloaded functions, see @ref{C plus plus
b37052ae 1473expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1474overload-resolution off} to disable overload resolution;
b37052ae 1475see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1476
1477
6d2ebf8b 1478@node Help
c906108c
SS
1479@section Getting help
1480@cindex online documentation
1481@kindex help
1482
5d161b24 1483You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1484using the command @code{help}.
1485
1486@table @code
41afff9a 1487@kindex h @r{(@code{help})}
c906108c
SS
1488@item help
1489@itemx h
1490You can use @code{help} (abbreviated @code{h}) with no arguments to
1491display a short list of named classes of commands:
1492
1493@smallexample
1494(@value{GDBP}) help
1495List of classes of commands:
1496
2df3850c 1497aliases -- Aliases of other commands
c906108c 1498breakpoints -- Making program stop at certain points
2df3850c 1499data -- Examining data
c906108c 1500files -- Specifying and examining files
2df3850c
JM
1501internals -- Maintenance commands
1502obscure -- Obscure features
1503running -- Running the program
1504stack -- Examining the stack
c906108c
SS
1505status -- Status inquiries
1506support -- Support facilities
96a2c332
SS
1507tracepoints -- Tracing of program execution without@*
1508 stopping the program
c906108c 1509user-defined -- User-defined commands
c906108c 1510
5d161b24 1511Type "help" followed by a class name for a list of
c906108c 1512commands in that class.
5d161b24 1513Type "help" followed by command name for full
c906108c
SS
1514documentation.
1515Command name abbreviations are allowed if unambiguous.
1516(@value{GDBP})
1517@end smallexample
96a2c332 1518@c the above line break eliminates huge line overfull...
c906108c
SS
1519
1520@item help @var{class}
1521Using one of the general help classes as an argument, you can get a
1522list of the individual commands in that class. For example, here is the
1523help display for the class @code{status}:
1524
1525@smallexample
1526(@value{GDBP}) help status
1527Status inquiries.
1528
1529List of commands:
1530
1531@c Line break in "show" line falsifies real output, but needed
1532@c to fit in smallbook page size.
2df3850c
JM
1533info -- Generic command for showing things
1534 about the program being debugged
1535show -- Generic command for showing things
1536 about the debugger
c906108c 1537
5d161b24 1538Type "help" followed by command name for full
c906108c
SS
1539documentation.
1540Command name abbreviations are allowed if unambiguous.
1541(@value{GDBP})
1542@end smallexample
1543
1544@item help @var{command}
1545With a command name as @code{help} argument, @value{GDBN} displays a
1546short paragraph on how to use that command.
1547
6837a0a2
DB
1548@kindex apropos
1549@item apropos @var{args}
09d4efe1 1550The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2
DB
1551commands, and their documentation, for the regular expression specified in
1552@var{args}. It prints out all matches found. For example:
1553
1554@smallexample
1555apropos reload
1556@end smallexample
1557
b37052ae
EZ
1558@noindent
1559results in:
6837a0a2
DB
1560
1561@smallexample
6d2ebf8b
SS
1562@c @group
1563set symbol-reloading -- Set dynamic symbol table reloading
1564 multiple times in one run
1565show symbol-reloading -- Show dynamic symbol table reloading
1566 multiple times in one run
1567@c @end group
6837a0a2
DB
1568@end smallexample
1569
c906108c
SS
1570@kindex complete
1571@item complete @var{args}
1572The @code{complete @var{args}} command lists all the possible completions
1573for the beginning of a command. Use @var{args} to specify the beginning of the
1574command you want completed. For example:
1575
1576@smallexample
1577complete i
1578@end smallexample
1579
1580@noindent results in:
1581
1582@smallexample
1583@group
2df3850c
JM
1584if
1585ignore
c906108c
SS
1586info
1587inspect
c906108c
SS
1588@end group
1589@end smallexample
1590
1591@noindent This is intended for use by @sc{gnu} Emacs.
1592@end table
1593
1594In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1595and @code{show} to inquire about the state of your program, or the state
1596of @value{GDBN} itself. Each command supports many topics of inquiry; this
1597manual introduces each of them in the appropriate context. The listings
1598under @code{info} and under @code{show} in the Index point to
1599all the sub-commands. @xref{Index}.
1600
1601@c @group
1602@table @code
1603@kindex info
41afff9a 1604@kindex i @r{(@code{info})}
c906108c
SS
1605@item info
1606This command (abbreviated @code{i}) is for describing the state of your
1607program. For example, you can list the arguments given to your program
1608with @code{info args}, list the registers currently in use with @code{info
1609registers}, or list the breakpoints you have set with @code{info breakpoints}.
1610You can get a complete list of the @code{info} sub-commands with
1611@w{@code{help info}}.
1612
1613@kindex set
1614@item set
5d161b24 1615You can assign the result of an expression to an environment variable with
c906108c
SS
1616@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1617@code{set prompt $}.
1618
1619@kindex show
1620@item show
5d161b24 1621In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1622@value{GDBN} itself.
1623You can change most of the things you can @code{show}, by using the
1624related command @code{set}; for example, you can control what number
1625system is used for displays with @code{set radix}, or simply inquire
1626which is currently in use with @code{show radix}.
1627
1628@kindex info set
1629To display all the settable parameters and their current
1630values, you can use @code{show} with no arguments; you may also use
1631@code{info set}. Both commands produce the same display.
1632@c FIXME: "info set" violates the rule that "info" is for state of
1633@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1634@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1635@end table
1636@c @end group
1637
1638Here are three miscellaneous @code{show} subcommands, all of which are
1639exceptional in lacking corresponding @code{set} commands:
1640
1641@table @code
1642@kindex show version
9c16f35a 1643@cindex @value{GDBN} version number
c906108c
SS
1644@item show version
1645Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1646information in @value{GDBN} bug-reports. If multiple versions of
1647@value{GDBN} are in use at your site, you may need to determine which
1648version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1649commands are introduced, and old ones may wither away. Also, many
1650system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1651variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1652The version number is the same as the one announced when you start
1653@value{GDBN}.
c906108c
SS
1654
1655@kindex show copying
09d4efe1 1656@kindex info copying
9c16f35a 1657@cindex display @value{GDBN} copyright
c906108c 1658@item show copying
09d4efe1 1659@itemx info copying
c906108c
SS
1660Display information about permission for copying @value{GDBN}.
1661
1662@kindex show warranty
09d4efe1 1663@kindex info warranty
c906108c 1664@item show warranty
09d4efe1 1665@itemx info warranty
2df3850c 1666Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1667if your version of @value{GDBN} comes with one.
2df3850c 1668
c906108c
SS
1669@end table
1670
6d2ebf8b 1671@node Running
c906108c
SS
1672@chapter Running Programs Under @value{GDBN}
1673
1674When you run a program under @value{GDBN}, you must first generate
1675debugging information when you compile it.
7a292a7a
SS
1676
1677You may start @value{GDBN} with its arguments, if any, in an environment
1678of your choice. If you are doing native debugging, you may redirect
1679your program's input and output, debug an already running process, or
1680kill a child process.
c906108c
SS
1681
1682@menu
1683* Compilation:: Compiling for debugging
1684* Starting:: Starting your program
c906108c
SS
1685* Arguments:: Your program's arguments
1686* Environment:: Your program's environment
c906108c
SS
1687
1688* Working Directory:: Your program's working directory
1689* Input/Output:: Your program's input and output
1690* Attach:: Debugging an already-running process
1691* Kill Process:: Killing the child process
c906108c
SS
1692
1693* Threads:: Debugging programs with multiple threads
1694* Processes:: Debugging programs with multiple processes
1695@end menu
1696
6d2ebf8b 1697@node Compilation
c906108c
SS
1698@section Compiling for debugging
1699
1700In order to debug a program effectively, you need to generate
1701debugging information when you compile it. This debugging information
1702is stored in the object file; it describes the data type of each
1703variable or function and the correspondence between source line numbers
1704and addresses in the executable code.
1705
1706To request debugging information, specify the @samp{-g} option when you run
1707the compiler.
1708
514c4d71
EZ
1709Programs that are to be shipped to your customers are compiled with
1710optimizations, using the @samp{-O} compiler option. However, many
1711compilers are unable to handle the @samp{-g} and @samp{-O} options
1712together. Using those compilers, you cannot generate optimized
c906108c
SS
1713executables containing debugging information.
1714
514c4d71 1715@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1716without @samp{-O}, making it possible to debug optimized code. We
1717recommend that you @emph{always} use @samp{-g} whenever you compile a
1718program. You may think your program is correct, but there is no sense
1719in pushing your luck.
c906108c
SS
1720
1721@cindex optimized code, debugging
1722@cindex debugging optimized code
1723When you debug a program compiled with @samp{-g -O}, remember that the
1724optimizer is rearranging your code; the debugger shows you what is
1725really there. Do not be too surprised when the execution path does not
1726exactly match your source file! An extreme example: if you define a
1727variable, but never use it, @value{GDBN} never sees that
1728variable---because the compiler optimizes it out of existence.
1729
1730Some things do not work as well with @samp{-g -O} as with just
1731@samp{-g}, particularly on machines with instruction scheduling. If in
1732doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1733please report it to us as a bug (including a test case!).
15387254 1734@xref{Variables}, for more information about debugging optimized code.
c906108c
SS
1735
1736Older versions of the @sc{gnu} C compiler permitted a variant option
1737@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1738format; if your @sc{gnu} C compiler has this option, do not use it.
1739
514c4d71
EZ
1740@value{GDBN} knows about preprocessor macros and can show you their
1741expansion (@pxref{Macros}). Most compilers do not include information
1742about preprocessor macros in the debugging information if you specify
1743the @option{-g} flag alone, because this information is rather large.
1744Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1745provides macro information if you specify the options
1746@option{-gdwarf-2} and @option{-g3}; the former option requests
1747debugging information in the Dwarf 2 format, and the latter requests
1748``extra information''. In the future, we hope to find more compact
1749ways to represent macro information, so that it can be included with
1750@option{-g} alone.
1751
c906108c 1752@need 2000
6d2ebf8b 1753@node Starting
c906108c
SS
1754@section Starting your program
1755@cindex starting
1756@cindex running
1757
1758@table @code
1759@kindex run
41afff9a 1760@kindex r @r{(@code{run})}
c906108c
SS
1761@item run
1762@itemx r
7a292a7a
SS
1763Use the @code{run} command to start your program under @value{GDBN}.
1764You must first specify the program name (except on VxWorks) with an
1765argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1766@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1767(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1768
1769@end table
1770
c906108c
SS
1771If you are running your program in an execution environment that
1772supports processes, @code{run} creates an inferior process and makes
1773that process run your program. (In environments without processes,
1774@code{run} jumps to the start of your program.)
1775
1776The execution of a program is affected by certain information it
1777receives from its superior. @value{GDBN} provides ways to specify this
1778information, which you must do @emph{before} starting your program. (You
1779can change it after starting your program, but such changes only affect
1780your program the next time you start it.) This information may be
1781divided into four categories:
1782
1783@table @asis
1784@item The @emph{arguments.}
1785Specify the arguments to give your program as the arguments of the
1786@code{run} command. If a shell is available on your target, the shell
1787is used to pass the arguments, so that you may use normal conventions
1788(such as wildcard expansion or variable substitution) in describing
1789the arguments.
1790In Unix systems, you can control which shell is used with the
1791@code{SHELL} environment variable.
1792@xref{Arguments, ,Your program's arguments}.
1793
1794@item The @emph{environment.}
1795Your program normally inherits its environment from @value{GDBN}, but you can
1796use the @value{GDBN} commands @code{set environment} and @code{unset
1797environment} to change parts of the environment that affect
1798your program. @xref{Environment, ,Your program's environment}.
1799
1800@item The @emph{working directory.}
1801Your program inherits its working directory from @value{GDBN}. You can set
1802the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1803@xref{Working Directory, ,Your program's working directory}.
1804
1805@item The @emph{standard input and output.}
1806Your program normally uses the same device for standard input and
1807standard output as @value{GDBN} is using. You can redirect input and output
1808in the @code{run} command line, or you can use the @code{tty} command to
1809set a different device for your program.
1810@xref{Input/Output, ,Your program's input and output}.
1811
1812@cindex pipes
1813@emph{Warning:} While input and output redirection work, you cannot use
1814pipes to pass the output of the program you are debugging to another
1815program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1816wrong program.
1817@end table
c906108c
SS
1818
1819When you issue the @code{run} command, your program begins to execute
1820immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1821of how to arrange for your program to stop. Once your program has
1822stopped, you may call functions in your program, using the @code{print}
1823or @code{call} commands. @xref{Data, ,Examining Data}.
1824
1825If the modification time of your symbol file has changed since the last
1826time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1827table, and reads it again. When it does this, @value{GDBN} tries to retain
1828your current breakpoints.
1829
4e8b0763
JB
1830@table @code
1831@kindex start
1832@item start
1833@cindex run to main procedure
1834The name of the main procedure can vary from language to language.
1835With C or C@t{++}, the main procedure name is always @code{main}, but
1836other languages such as Ada do not require a specific name for their
1837main procedure. The debugger provides a convenient way to start the
1838execution of the program and to stop at the beginning of the main
1839procedure, depending on the language used.
1840
1841The @samp{start} command does the equivalent of setting a temporary
1842breakpoint at the beginning of the main procedure and then invoking
1843the @samp{run} command.
1844
f018e82f
EZ
1845@cindex elaboration phase
1846Some programs contain an @dfn{elaboration} phase where some startup code is
1847executed before the main procedure is called. This depends on the
1848languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1849constructors for static and global objects are executed before
1850@code{main} is called. It is therefore possible that the debugger stops
1851before reaching the main procedure. However, the temporary breakpoint
1852will remain to halt execution.
1853
1854Specify the arguments to give to your program as arguments to the
1855@samp{start} command. These arguments will be given verbatim to the
1856underlying @samp{run} command. Note that the same arguments will be
1857reused if no argument is provided during subsequent calls to
1858@samp{start} or @samp{run}.
1859
1860It is sometimes necessary to debug the program during elaboration. In
1861these cases, using the @code{start} command would stop the execution of
1862your program too late, as the program would have already completed the
1863elaboration phase. Under these circumstances, insert breakpoints in your
1864elaboration code before running your program.
1865@end table
1866
6d2ebf8b 1867@node Arguments
c906108c
SS
1868@section Your program's arguments
1869
1870@cindex arguments (to your program)
1871The arguments to your program can be specified by the arguments of the
5d161b24 1872@code{run} command.
c906108c
SS
1873They are passed to a shell, which expands wildcard characters and
1874performs redirection of I/O, and thence to your program. Your
1875@code{SHELL} environment variable (if it exists) specifies what shell
1876@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1877the default shell (@file{/bin/sh} on Unix).
1878
1879On non-Unix systems, the program is usually invoked directly by
1880@value{GDBN}, which emulates I/O redirection via the appropriate system
1881calls, and the wildcard characters are expanded by the startup code of
1882the program, not by the shell.
c906108c
SS
1883
1884@code{run} with no arguments uses the same arguments used by the previous
1885@code{run}, or those set by the @code{set args} command.
1886
c906108c 1887@table @code
41afff9a 1888@kindex set args
c906108c
SS
1889@item set args
1890Specify the arguments to be used the next time your program is run. If
1891@code{set args} has no arguments, @code{run} executes your program
1892with no arguments. Once you have run your program with arguments,
1893using @code{set args} before the next @code{run} is the only way to run
1894it again without arguments.
1895
1896@kindex show args
1897@item show args
1898Show the arguments to give your program when it is started.
1899@end table
1900
6d2ebf8b 1901@node Environment
c906108c
SS
1902@section Your program's environment
1903
1904@cindex environment (of your program)
1905The @dfn{environment} consists of a set of environment variables and
1906their values. Environment variables conventionally record such things as
1907your user name, your home directory, your terminal type, and your search
1908path for programs to run. Usually you set up environment variables with
1909the shell and they are inherited by all the other programs you run. When
1910debugging, it can be useful to try running your program with a modified
1911environment without having to start @value{GDBN} over again.
1912
1913@table @code
1914@kindex path
1915@item path @var{directory}
1916Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1917(the search path for executables) that will be passed to your program.
1918The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1919You may specify several directory names, separated by whitespace or by a
1920system-dependent separator character (@samp{:} on Unix, @samp{;} on
1921MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1922is moved to the front, so it is searched sooner.
c906108c
SS
1923
1924You can use the string @samp{$cwd} to refer to whatever is the current
1925working directory at the time @value{GDBN} searches the path. If you
1926use @samp{.} instead, it refers to the directory where you executed the
1927@code{path} command. @value{GDBN} replaces @samp{.} in the
1928@var{directory} argument (with the current path) before adding
1929@var{directory} to the search path.
1930@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1931@c document that, since repeating it would be a no-op.
1932
1933@kindex show paths
1934@item show paths
1935Display the list of search paths for executables (the @code{PATH}
1936environment variable).
1937
1938@kindex show environment
1939@item show environment @r{[}@var{varname}@r{]}
1940Print the value of environment variable @var{varname} to be given to
1941your program when it starts. If you do not supply @var{varname},
1942print the names and values of all environment variables to be given to
1943your program. You can abbreviate @code{environment} as @code{env}.
1944
1945@kindex set environment
53a5351d 1946@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1947Set environment variable @var{varname} to @var{value}. The value
1948changes for your program only, not for @value{GDBN} itself. @var{value} may
1949be any string; the values of environment variables are just strings, and
1950any interpretation is supplied by your program itself. The @var{value}
1951parameter is optional; if it is eliminated, the variable is set to a
1952null value.
1953@c "any string" here does not include leading, trailing
1954@c blanks. Gnu asks: does anyone care?
1955
1956For example, this command:
1957
474c8240 1958@smallexample
c906108c 1959set env USER = foo
474c8240 1960@end smallexample
c906108c
SS
1961
1962@noindent
d4f3574e 1963tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1964@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1965are not actually required.)
1966
1967@kindex unset environment
1968@item unset environment @var{varname}
1969Remove variable @var{varname} from the environment to be passed to your
1970program. This is different from @samp{set env @var{varname} =};
1971@code{unset environment} removes the variable from the environment,
1972rather than assigning it an empty value.
1973@end table
1974
d4f3574e
SS
1975@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1976the shell indicated
c906108c
SS
1977by your @code{SHELL} environment variable if it exists (or
1978@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1979that runs an initialization file---such as @file{.cshrc} for C-shell, or
1980@file{.bashrc} for BASH---any variables you set in that file affect
1981your program. You may wish to move setting of environment variables to
1982files that are only run when you sign on, such as @file{.login} or
1983@file{.profile}.
1984
6d2ebf8b 1985@node Working Directory
c906108c
SS
1986@section Your program's working directory
1987
1988@cindex working directory (of your program)
1989Each time you start your program with @code{run}, it inherits its
1990working directory from the current working directory of @value{GDBN}.
1991The @value{GDBN} working directory is initially whatever it inherited
1992from its parent process (typically the shell), but you can specify a new
1993working directory in @value{GDBN} with the @code{cd} command.
1994
1995The @value{GDBN} working directory also serves as a default for the commands
1996that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1997specify files}.
1998
1999@table @code
2000@kindex cd
721c2651 2001@cindex change working directory
c906108c
SS
2002@item cd @var{directory}
2003Set the @value{GDBN} working directory to @var{directory}.
2004
2005@kindex pwd
2006@item pwd
2007Print the @value{GDBN} working directory.
2008@end table
2009
60bf7e09
EZ
2010It is generally impossible to find the current working directory of
2011the process being debugged (since a program can change its directory
2012during its run). If you work on a system where @value{GDBN} is
2013configured with the @file{/proc} support, you can use the @code{info
2014proc} command (@pxref{SVR4 Process Information}) to find out the
2015current working directory of the debuggee.
2016
6d2ebf8b 2017@node Input/Output
c906108c
SS
2018@section Your program's input and output
2019
2020@cindex redirection
2021@cindex i/o
2022@cindex terminal
2023By default, the program you run under @value{GDBN} does input and output to
5d161b24 2024the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2025to its own terminal modes to interact with you, but it records the terminal
2026modes your program was using and switches back to them when you continue
2027running your program.
2028
2029@table @code
2030@kindex info terminal
2031@item info terminal
2032Displays information recorded by @value{GDBN} about the terminal modes your
2033program is using.
2034@end table
2035
2036You can redirect your program's input and/or output using shell
2037redirection with the @code{run} command. For example,
2038
474c8240 2039@smallexample
c906108c 2040run > outfile
474c8240 2041@end smallexample
c906108c
SS
2042
2043@noindent
2044starts your program, diverting its output to the file @file{outfile}.
2045
2046@kindex tty
2047@cindex controlling terminal
2048Another way to specify where your program should do input and output is
2049with the @code{tty} command. This command accepts a file name as
2050argument, and causes this file to be the default for future @code{run}
2051commands. It also resets the controlling terminal for the child
2052process, for future @code{run} commands. For example,
2053
474c8240 2054@smallexample
c906108c 2055tty /dev/ttyb
474c8240 2056@end smallexample
c906108c
SS
2057
2058@noindent
2059directs that processes started with subsequent @code{run} commands
2060default to do input and output on the terminal @file{/dev/ttyb} and have
2061that as their controlling terminal.
2062
2063An explicit redirection in @code{run} overrides the @code{tty} command's
2064effect on the input/output device, but not its effect on the controlling
2065terminal.
2066
2067When you use the @code{tty} command or redirect input in the @code{run}
2068command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2069for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2070for @code{set inferior-tty}.
2071
2072@cindex inferior tty
2073@cindex set inferior controlling terminal
2074You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2075display the name of the terminal that will be used for future runs of your
2076program.
2077
2078@table @code
2079@item set inferior-tty /dev/ttyb
2080@kindex set inferior-tty
2081Set the tty for the program being debugged to /dev/ttyb.
2082
2083@item show inferior-tty
2084@kindex show inferior-tty
2085Show the current tty for the program being debugged.
2086@end table
c906108c 2087
6d2ebf8b 2088@node Attach
c906108c
SS
2089@section Debugging an already-running process
2090@kindex attach
2091@cindex attach
2092
2093@table @code
2094@item attach @var{process-id}
2095This command attaches to a running process---one that was started
2096outside @value{GDBN}. (@code{info files} shows your active
2097targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2098find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2099or with the @samp{jobs -l} shell command.
2100
2101@code{attach} does not repeat if you press @key{RET} a second time after
2102executing the command.
2103@end table
2104
2105To use @code{attach}, your program must be running in an environment
2106which supports processes; for example, @code{attach} does not work for
2107programs on bare-board targets that lack an operating system. You must
2108also have permission to send the process a signal.
2109
2110When you use @code{attach}, the debugger finds the program running in
2111the process first by looking in the current working directory, then (if
2112the program is not found) by using the source file search path
2113(@pxref{Source Path, ,Specifying source directories}). You can also use
2114the @code{file} command to load the program. @xref{Files, ,Commands to
2115Specify Files}.
2116
2117The first thing @value{GDBN} does after arranging to debug the specified
2118process is to stop it. You can examine and modify an attached process
53a5351d
JM
2119with all the @value{GDBN} commands that are ordinarily available when
2120you start processes with @code{run}. You can insert breakpoints; you
2121can step and continue; you can modify storage. If you would rather the
2122process continue running, you may use the @code{continue} command after
c906108c
SS
2123attaching @value{GDBN} to the process.
2124
2125@table @code
2126@kindex detach
2127@item detach
2128When you have finished debugging the attached process, you can use the
2129@code{detach} command to release it from @value{GDBN} control. Detaching
2130the process continues its execution. After the @code{detach} command,
2131that process and @value{GDBN} become completely independent once more, and you
2132are ready to @code{attach} another process or start one with @code{run}.
2133@code{detach} does not repeat if you press @key{RET} again after
2134executing the command.
2135@end table
2136
2137If you exit @value{GDBN} or use the @code{run} command while you have an
2138attached process, you kill that process. By default, @value{GDBN} asks
2139for confirmation if you try to do either of these things; you can
2140control whether or not you need to confirm by using the @code{set
2141confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2142messages}).
2143
6d2ebf8b 2144@node Kill Process
c906108c 2145@section Killing the child process
c906108c
SS
2146
2147@table @code
2148@kindex kill
2149@item kill
2150Kill the child process in which your program is running under @value{GDBN}.
2151@end table
2152
2153This command is useful if you wish to debug a core dump instead of a
2154running process. @value{GDBN} ignores any core dump file while your program
2155is running.
2156
2157On some operating systems, a program cannot be executed outside @value{GDBN}
2158while you have breakpoints set on it inside @value{GDBN}. You can use the
2159@code{kill} command in this situation to permit running your program
2160outside the debugger.
2161
2162The @code{kill} command is also useful if you wish to recompile and
2163relink your program, since on many systems it is impossible to modify an
2164executable file while it is running in a process. In this case, when you
2165next type @code{run}, @value{GDBN} notices that the file has changed, and
2166reads the symbol table again (while trying to preserve your current
2167breakpoint settings).
2168
6d2ebf8b 2169@node Threads
c906108c 2170@section Debugging programs with multiple threads
c906108c
SS
2171
2172@cindex threads of execution
2173@cindex multiple threads
2174@cindex switching threads
2175In some operating systems, such as HP-UX and Solaris, a single program
2176may have more than one @dfn{thread} of execution. The precise semantics
2177of threads differ from one operating system to another, but in general
2178the threads of a single program are akin to multiple processes---except
2179that they share one address space (that is, they can all examine and
2180modify the same variables). On the other hand, each thread has its own
2181registers and execution stack, and perhaps private memory.
2182
2183@value{GDBN} provides these facilities for debugging multi-thread
2184programs:
2185
2186@itemize @bullet
2187@item automatic notification of new threads
2188@item @samp{thread @var{threadno}}, a command to switch among threads
2189@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2190@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2191a command to apply a command to a list of threads
2192@item thread-specific breakpoints
2193@end itemize
2194
c906108c
SS
2195@quotation
2196@emph{Warning:} These facilities are not yet available on every
2197@value{GDBN} configuration where the operating system supports threads.
2198If your @value{GDBN} does not support threads, these commands have no
2199effect. For example, a system without thread support shows no output
2200from @samp{info threads}, and always rejects the @code{thread} command,
2201like this:
2202
2203@smallexample
2204(@value{GDBP}) info threads
2205(@value{GDBP}) thread 1
2206Thread ID 1 not known. Use the "info threads" command to
2207see the IDs of currently known threads.
2208@end smallexample
2209@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2210@c doesn't support threads"?
2211@end quotation
c906108c
SS
2212
2213@cindex focus of debugging
2214@cindex current thread
2215The @value{GDBN} thread debugging facility allows you to observe all
2216threads while your program runs---but whenever @value{GDBN} takes
2217control, one thread in particular is always the focus of debugging.
2218This thread is called the @dfn{current thread}. Debugging commands show
2219program information from the perspective of the current thread.
2220
41afff9a 2221@cindex @code{New} @var{systag} message
c906108c
SS
2222@cindex thread identifier (system)
2223@c FIXME-implementors!! It would be more helpful if the [New...] message
2224@c included GDB's numeric thread handle, so you could just go to that
2225@c thread without first checking `info threads'.
2226Whenever @value{GDBN} detects a new thread in your program, it displays
2227the target system's identification for the thread with a message in the
2228form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2229whose form varies depending on the particular system. For example, on
2230LynxOS, you might see
2231
474c8240 2232@smallexample
c906108c 2233[New process 35 thread 27]
474c8240 2234@end smallexample
c906108c
SS
2235
2236@noindent
2237when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2238the @var{systag} is simply something like @samp{process 368}, with no
2239further qualifier.
2240
2241@c FIXME!! (1) Does the [New...] message appear even for the very first
2242@c thread of a program, or does it only appear for the
6ca652b0 2243@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2244@c program?
2245@c (2) *Is* there necessarily a first thread always? Or do some
2246@c multithread systems permit starting a program with multiple
5d161b24 2247@c threads ab initio?
c906108c
SS
2248
2249@cindex thread number
2250@cindex thread identifier (GDB)
2251For debugging purposes, @value{GDBN} associates its own thread
2252number---always a single integer---with each thread in your program.
2253
2254@table @code
2255@kindex info threads
2256@item info threads
2257Display a summary of all threads currently in your
2258program. @value{GDBN} displays for each thread (in this order):
2259
2260@enumerate
09d4efe1
EZ
2261@item
2262the thread number assigned by @value{GDBN}
c906108c 2263
09d4efe1
EZ
2264@item
2265the target system's thread identifier (@var{systag})
c906108c 2266
09d4efe1
EZ
2267@item
2268the current stack frame summary for that thread
c906108c
SS
2269@end enumerate
2270
2271@noindent
2272An asterisk @samp{*} to the left of the @value{GDBN} thread number
2273indicates the current thread.
2274
5d161b24 2275For example,
c906108c
SS
2276@end table
2277@c end table here to get a little more width for example
2278
2279@smallexample
2280(@value{GDBP}) info threads
2281 3 process 35 thread 27 0x34e5 in sigpause ()
2282 2 process 35 thread 23 0x34e5 in sigpause ()
2283* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2284 at threadtest.c:68
2285@end smallexample
53a5351d
JM
2286
2287On HP-UX systems:
c906108c 2288
4644b6e3
EZ
2289@cindex debugging multithreaded programs (on HP-UX)
2290@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2291For debugging purposes, @value{GDBN} associates its own thread
2292number---a small integer assigned in thread-creation order---with each
2293thread in your program.
2294
41afff9a
EZ
2295@cindex @code{New} @var{systag} message, on HP-UX
2296@cindex thread identifier (system), on HP-UX
c906108c
SS
2297@c FIXME-implementors!! It would be more helpful if the [New...] message
2298@c included GDB's numeric thread handle, so you could just go to that
2299@c thread without first checking `info threads'.
2300Whenever @value{GDBN} detects a new thread in your program, it displays
2301both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2302form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2303whose form varies depending on the particular system. For example, on
2304HP-UX, you see
2305
474c8240 2306@smallexample
c906108c 2307[New thread 2 (system thread 26594)]
474c8240 2308@end smallexample
c906108c
SS
2309
2310@noindent
5d161b24 2311when @value{GDBN} notices a new thread.
c906108c
SS
2312
2313@table @code
4644b6e3 2314@kindex info threads (HP-UX)
c906108c
SS
2315@item info threads
2316Display a summary of all threads currently in your
2317program. @value{GDBN} displays for each thread (in this order):
2318
2319@enumerate
2320@item the thread number assigned by @value{GDBN}
2321
2322@item the target system's thread identifier (@var{systag})
2323
2324@item the current stack frame summary for that thread
2325@end enumerate
2326
2327@noindent
2328An asterisk @samp{*} to the left of the @value{GDBN} thread number
2329indicates the current thread.
2330
5d161b24 2331For example,
c906108c
SS
2332@end table
2333@c end table here to get a little more width for example
2334
474c8240 2335@smallexample
c906108c 2336(@value{GDBP}) info threads
6d2ebf8b
SS
2337 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2338 at quicksort.c:137
2339 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2340 from /usr/lib/libc.2
2341 1 system thread 27905 0x7b003498 in _brk () \@*
2342 from /usr/lib/libc.2
474c8240 2343@end smallexample
c906108c 2344
c45da7e6
EZ
2345On Solaris, you can display more information about user threads with a
2346Solaris-specific command:
2347
2348@table @code
2349@item maint info sol-threads
2350@kindex maint info sol-threads
2351@cindex thread info (Solaris)
2352Display info on Solaris user threads.
2353@end table
2354
c906108c
SS
2355@table @code
2356@kindex thread @var{threadno}
2357@item thread @var{threadno}
2358Make thread number @var{threadno} the current thread. The command
2359argument @var{threadno} is the internal @value{GDBN} thread number, as
2360shown in the first field of the @samp{info threads} display.
2361@value{GDBN} responds by displaying the system identifier of the thread
2362you selected, and its current stack frame summary:
2363
2364@smallexample
2365@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2366(@value{GDBP}) thread 2
c906108c 2367[Switching to process 35 thread 23]
c906108c
SS
23680x34e5 in sigpause ()
2369@end smallexample
2370
2371@noindent
2372As with the @samp{[New @dots{}]} message, the form of the text after
2373@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2374threads.
c906108c 2375
9c16f35a 2376@kindex thread apply
638ac427 2377@cindex apply command to several threads
c906108c
SS
2378@item thread apply [@var{threadno}] [@var{all}] @var{args}
2379The @code{thread apply} command allows you to apply a command to one or
2380more threads. Specify the numbers of the threads that you want affected
2381with the command argument @var{threadno}. @var{threadno} is the internal
2382@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2383threads} display. To apply a command to all threads, use
2384@code{thread apply all} @var{args}.
c906108c
SS
2385@end table
2386
2387@cindex automatic thread selection
2388@cindex switching threads automatically
2389@cindex threads, automatic switching
2390Whenever @value{GDBN} stops your program, due to a breakpoint or a
2391signal, it automatically selects the thread where that breakpoint or
2392signal happened. @value{GDBN} alerts you to the context switch with a
2393message of the form @samp{[Switching to @var{systag}]} to identify the
2394thread.
2395
2396@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2397more information about how @value{GDBN} behaves when you stop and start
2398programs with multiple threads.
2399
2400@xref{Set Watchpoints,,Setting watchpoints}, for information about
2401watchpoints in programs with multiple threads.
c906108c 2402
6d2ebf8b 2403@node Processes
c906108c
SS
2404@section Debugging programs with multiple processes
2405
2406@cindex fork, debugging programs which call
2407@cindex multiple processes
2408@cindex processes, multiple
53a5351d
JM
2409On most systems, @value{GDBN} has no special support for debugging
2410programs which create additional processes using the @code{fork}
2411function. When a program forks, @value{GDBN} will continue to debug the
2412parent process and the child process will run unimpeded. If you have
2413set a breakpoint in any code which the child then executes, the child
2414will get a @code{SIGTRAP} signal which (unless it catches the signal)
2415will cause it to terminate.
c906108c
SS
2416
2417However, if you want to debug the child process there is a workaround
2418which isn't too painful. Put a call to @code{sleep} in the code which
2419the child process executes after the fork. It may be useful to sleep
2420only if a certain environment variable is set, or a certain file exists,
2421so that the delay need not occur when you don't want to run @value{GDBN}
2422on the child. While the child is sleeping, use the @code{ps} program to
2423get its process ID. Then tell @value{GDBN} (a new invocation of
2424@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2425the child process (@pxref{Attach}). From that point on you can debug
c906108c 2426the child process just like any other process which you attached to.
c906108c 2427
b51970ac
DJ
2428On some systems, @value{GDBN} provides support for debugging programs that
2429create additional processes using the @code{fork} or @code{vfork} functions.
2430Currently, the only platforms with this feature are HP-UX (11.x and later
2431only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2432
2433By default, when a program forks, @value{GDBN} will continue to debug
2434the parent process and the child process will run unimpeded.
2435
2436If you want to follow the child process instead of the parent process,
2437use the command @w{@code{set follow-fork-mode}}.
2438
2439@table @code
2440@kindex set follow-fork-mode
2441@item set follow-fork-mode @var{mode}
2442Set the debugger response to a program call of @code{fork} or
2443@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 2444process. The @var{mode} argument can be:
c906108c
SS
2445
2446@table @code
2447@item parent
2448The original process is debugged after a fork. The child process runs
2df3850c 2449unimpeded. This is the default.
c906108c
SS
2450
2451@item child
2452The new process is debugged after a fork. The parent process runs
2453unimpeded.
2454
c906108c
SS
2455@end table
2456
9c16f35a 2457@kindex show follow-fork-mode
c906108c 2458@item show follow-fork-mode
2df3850c 2459Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2460@end table
2461
2462If you ask to debug a child process and a @code{vfork} is followed by an
2463@code{exec}, @value{GDBN} executes the new target up to the first
2464breakpoint in the new target. If you have a breakpoint set on
2465@code{main} in your original program, the breakpoint will also be set on
2466the child process's @code{main}.
2467
2468When a child process is spawned by @code{vfork}, you cannot debug the
2469child or parent until an @code{exec} call completes.
2470
2471If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2472call executes, the new target restarts. To restart the parent process,
2473use the @code{file} command with the parent executable name as its
2474argument.
2475
2476You can use the @code{catch} command to make @value{GDBN} stop whenever
2477a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2478Catchpoints, ,Setting catchpoints}.
c906108c 2479
6d2ebf8b 2480@node Stopping
c906108c
SS
2481@chapter Stopping and Continuing
2482
2483The principal purposes of using a debugger are so that you can stop your
2484program before it terminates; or so that, if your program runs into
2485trouble, you can investigate and find out why.
2486
7a292a7a
SS
2487Inside @value{GDBN}, your program may stop for any of several reasons,
2488such as a signal, a breakpoint, or reaching a new line after a
2489@value{GDBN} command such as @code{step}. You may then examine and
2490change variables, set new breakpoints or remove old ones, and then
2491continue execution. Usually, the messages shown by @value{GDBN} provide
2492ample explanation of the status of your program---but you can also
2493explicitly request this information at any time.
c906108c
SS
2494
2495@table @code
2496@kindex info program
2497@item info program
2498Display information about the status of your program: whether it is
7a292a7a 2499running or not, what process it is, and why it stopped.
c906108c
SS
2500@end table
2501
2502@menu
2503* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2504* Continuing and Stepping:: Resuming execution
c906108c 2505* Signals:: Signals
c906108c 2506* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2507@end menu
2508
6d2ebf8b 2509@node Breakpoints
c906108c
SS
2510@section Breakpoints, watchpoints, and catchpoints
2511
2512@cindex breakpoints
2513A @dfn{breakpoint} makes your program stop whenever a certain point in
2514the program is reached. For each breakpoint, you can add conditions to
2515control in finer detail whether your program stops. You can set
2516breakpoints with the @code{break} command and its variants (@pxref{Set
2517Breaks, ,Setting breakpoints}), to specify the place where your program
2518should stop by line number, function name or exact address in the
2519program.
2520
09d4efe1
EZ
2521On some systems, you can set breakpoints in shared libraries before
2522the executable is run. There is a minor limitation on HP-UX systems:
2523you must wait until the executable is run in order to set breakpoints
2524in shared library routines that are not called directly by the program
2525(for example, routines that are arguments in a @code{pthread_create}
2526call).
c906108c
SS
2527
2528@cindex watchpoints
2529@cindex memory tracing
2530@cindex breakpoint on memory address
2531@cindex breakpoint on variable modification
2532A @dfn{watchpoint} is a special breakpoint that stops your program
2533when the value of an expression changes. You must use a different
2534command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2535watchpoints}), but aside from that, you can manage a watchpoint like
2536any other breakpoint: you enable, disable, and delete both breakpoints
2537and watchpoints using the same commands.
2538
2539You can arrange to have values from your program displayed automatically
2540whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2541Automatic display}.
2542
2543@cindex catchpoints
2544@cindex breakpoint on events
2545A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2546when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2547exception or the loading of a library. As with watchpoints, you use a
2548different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2549catchpoints}), but aside from that, you can manage a catchpoint like any
2550other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2551@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2552
2553@cindex breakpoint numbers
2554@cindex numbers for breakpoints
2555@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2556catchpoint when you create it; these numbers are successive integers
2557starting with one. In many of the commands for controlling various
2558features of breakpoints you use the breakpoint number to say which
2559breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2560@dfn{disabled}; if disabled, it has no effect on your program until you
2561enable it again.
2562
c5394b80
JM
2563@cindex breakpoint ranges
2564@cindex ranges of breakpoints
2565Some @value{GDBN} commands accept a range of breakpoints on which to
2566operate. A breakpoint range is either a single breakpoint number, like
2567@samp{5}, or two such numbers, in increasing order, separated by a
2568hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2569all breakpoint in that range are operated on.
2570
c906108c
SS
2571@menu
2572* Set Breaks:: Setting breakpoints
2573* Set Watchpoints:: Setting watchpoints
2574* Set Catchpoints:: Setting catchpoints
2575* Delete Breaks:: Deleting breakpoints
2576* Disabling:: Disabling breakpoints
2577* Conditions:: Break conditions
2578* Break Commands:: Breakpoint command lists
c906108c 2579* Breakpoint Menus:: Breakpoint menus
d4f3574e 2580* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2581* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2582@end menu
2583
6d2ebf8b 2584@node Set Breaks
c906108c
SS
2585@subsection Setting breakpoints
2586
5d161b24 2587@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2588@c consider in particular declaration with/without initialization.
2589@c
2590@c FIXME 2 is there stuff on this already? break at fun start, already init?
2591
2592@kindex break
41afff9a
EZ
2593@kindex b @r{(@code{break})}
2594@vindex $bpnum@r{, convenience variable}
c906108c
SS
2595@cindex latest breakpoint
2596Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2597@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2598number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2599Vars,, Convenience variables}, for a discussion of what you can do with
2600convenience variables.
2601
2602You have several ways to say where the breakpoint should go.
2603
2604@table @code
2605@item break @var{function}
5d161b24 2606Set a breakpoint at entry to function @var{function}.
c906108c 2607When using source languages that permit overloading of symbols, such as
b37052ae 2608C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2609@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2610
2611@item break +@var{offset}
2612@itemx break -@var{offset}
2613Set a breakpoint some number of lines forward or back from the position
d4f3574e 2614at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2615(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2616
2617@item break @var{linenum}
2618Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2619The current source file is the last file whose source text was printed.
2620The breakpoint will stop your program just before it executes any of the
c906108c
SS
2621code on that line.
2622
2623@item break @var{filename}:@var{linenum}
2624Set a breakpoint at line @var{linenum} in source file @var{filename}.
2625
2626@item break @var{filename}:@var{function}
2627Set a breakpoint at entry to function @var{function} found in file
2628@var{filename}. Specifying a file name as well as a function name is
2629superfluous except when multiple files contain similarly named
2630functions.
2631
2632@item break *@var{address}
2633Set a breakpoint at address @var{address}. You can use this to set
2634breakpoints in parts of your program which do not have debugging
2635information or source files.
2636
2637@item break
2638When called without any arguments, @code{break} sets a breakpoint at
2639the next instruction to be executed in the selected stack frame
2640(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2641innermost, this makes your program stop as soon as control
2642returns to that frame. This is similar to the effect of a
2643@code{finish} command in the frame inside the selected frame---except
2644that @code{finish} does not leave an active breakpoint. If you use
2645@code{break} without an argument in the innermost frame, @value{GDBN} stops
2646the next time it reaches the current location; this may be useful
2647inside loops.
2648
2649@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2650least one instruction has been executed. If it did not do this, you
2651would be unable to proceed past a breakpoint without first disabling the
2652breakpoint. This rule applies whether or not the breakpoint already
2653existed when your program stopped.
2654
2655@item break @dots{} if @var{cond}
2656Set a breakpoint with condition @var{cond}; evaluate the expression
2657@var{cond} each time the breakpoint is reached, and stop only if the
2658value is nonzero---that is, if @var{cond} evaluates as true.
2659@samp{@dots{}} stands for one of the possible arguments described
2660above (or no argument) specifying where to break. @xref{Conditions,
2661,Break conditions}, for more information on breakpoint conditions.
2662
2663@kindex tbreak
2664@item tbreak @var{args}
2665Set a breakpoint enabled only for one stop. @var{args} are the
2666same as for the @code{break} command, and the breakpoint is set in the same
2667way, but the breakpoint is automatically deleted after the first time your
2668program stops there. @xref{Disabling, ,Disabling breakpoints}.
2669
c906108c 2670@kindex hbreak
ba04e063 2671@cindex hardware breakpoints
c906108c 2672@item hbreak @var{args}
d4f3574e
SS
2673Set a hardware-assisted breakpoint. @var{args} are the same as for the
2674@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2675breakpoint requires hardware support and some target hardware may not
2676have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2677debugging, so you can set a breakpoint at an instruction without
2678changing the instruction. This can be used with the new trap-generation
09d4efe1 2679provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
2680will generate traps when a program accesses some data or instruction
2681address that is assigned to the debug registers. However the hardware
2682breakpoint registers can take a limited number of breakpoints. For
2683example, on the DSU, only two data breakpoints can be set at a time, and
2684@value{GDBN} will reject this command if more than two are used. Delete
2685or disable unused hardware breakpoints before setting new ones
2686(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
9c16f35a
EZ
2687For remote targets, you can restrict the number of hardware
2688breakpoints @value{GDBN} will use, see @ref{set remote
2689hardware-breakpoint-limit}.
501eef12 2690
c906108c
SS
2691
2692@kindex thbreak
2693@item thbreak @var{args}
2694Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2695are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2696the same way. However, like the @code{tbreak} command,
c906108c
SS
2697the breakpoint is automatically deleted after the
2698first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2699command, the breakpoint requires hardware support and some target hardware
2700may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2701See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2702
2703@kindex rbreak
2704@cindex regular expression
c45da7e6
EZ
2705@cindex breakpoints in functions matching a regexp
2706@cindex set breakpoints in many functions
c906108c 2707@item rbreak @var{regex}
c906108c 2708Set breakpoints on all functions matching the regular expression
11cf8741
JM
2709@var{regex}. This command sets an unconditional breakpoint on all
2710matches, printing a list of all breakpoints it set. Once these
2711breakpoints are set, they are treated just like the breakpoints set with
2712the @code{break} command. You can delete them, disable them, or make
2713them conditional the same way as any other breakpoint.
2714
2715The syntax of the regular expression is the standard one used with tools
2716like @file{grep}. Note that this is different from the syntax used by
2717shells, so for instance @code{foo*} matches all functions that include
2718an @code{fo} followed by zero or more @code{o}s. There is an implicit
2719@code{.*} leading and trailing the regular expression you supply, so to
2720match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2721
f7dc1244 2722@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2723When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2724breakpoints on overloaded functions that are not members of any special
2725classes.
c906108c 2726
f7dc1244
EZ
2727@cindex set breakpoints on all functions
2728The @code{rbreak} command can be used to set breakpoints in
2729@strong{all} the functions in a program, like this:
2730
2731@smallexample
2732(@value{GDBP}) rbreak .
2733@end smallexample
2734
c906108c
SS
2735@kindex info breakpoints
2736@cindex @code{$_} and @code{info breakpoints}
2737@item info breakpoints @r{[}@var{n}@r{]}
2738@itemx info break @r{[}@var{n}@r{]}
2739@itemx info watchpoints @r{[}@var{n}@r{]}
2740Print a table of all breakpoints, watchpoints, and catchpoints set and
2741not deleted, with the following columns for each breakpoint:
2742
2743@table @emph
2744@item Breakpoint Numbers
2745@item Type
2746Breakpoint, watchpoint, or catchpoint.
2747@item Disposition
2748Whether the breakpoint is marked to be disabled or deleted when hit.
2749@item Enabled or Disabled
2750Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2751that are not enabled.
2752@item Address
2650777c
JJ
2753Where the breakpoint is in your program, as a memory address. If the
2754breakpoint is pending (see below for details) on a future load of a shared library, the address
2755will be listed as @samp{<PENDING>}.
c906108c
SS
2756@item What
2757Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
2758line number. For a pending breakpoint, the original string passed to
2759the breakpoint command will be listed as it cannot be resolved until
2760the appropriate shared library is loaded in the future.
c906108c
SS
2761@end table
2762
2763@noindent
2764If a breakpoint is conditional, @code{info break} shows the condition on
2765the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
2766are listed after that. A pending breakpoint is allowed to have a condition
2767specified for it. The condition is not parsed for validity until a shared
2768library is loaded that allows the pending breakpoint to resolve to a
2769valid location.
c906108c
SS
2770
2771@noindent
2772@code{info break} with a breakpoint
2773number @var{n} as argument lists only that breakpoint. The
2774convenience variable @code{$_} and the default examining-address for
2775the @code{x} command are set to the address of the last breakpoint
5d161b24 2776listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2777
2778@noindent
2779@code{info break} displays a count of the number of times the breakpoint
2780has been hit. This is especially useful in conjunction with the
2781@code{ignore} command. You can ignore a large number of breakpoint
2782hits, look at the breakpoint info to see how many times the breakpoint
2783was hit, and then run again, ignoring one less than that number. This
2784will get you quickly to the last hit of that breakpoint.
2785@end table
2786
2787@value{GDBN} allows you to set any number of breakpoints at the same place in
2788your program. There is nothing silly or meaningless about this. When
2789the breakpoints are conditional, this is even useful
2790(@pxref{Conditions, ,Break conditions}).
2791
2650777c 2792@cindex pending breakpoints
dd79a6cf
JJ
2793If a specified breakpoint location cannot be found, it may be due to the fact
2794that the location is in a shared library that is yet to be loaded. In such
2795a case, you may want @value{GDBN} to create a special breakpoint (known as
2796a @dfn{pending breakpoint}) that
2797attempts to resolve itself in the future when an appropriate shared library
2798gets loaded.
2799
2800Pending breakpoints are useful to set at the start of your
2650777c
JJ
2801@value{GDBN} session for locations that you know will be dynamically loaded
2802later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
2803a check is made to see if the load resolves any pending breakpoint locations.
2804If a pending breakpoint location gets resolved,
2805a regular breakpoint is created and the original pending breakpoint is removed.
2806
2807@value{GDBN} provides some additional commands for controlling pending
2808breakpoint support:
2809
2810@kindex set breakpoint pending
2811@kindex show breakpoint pending
2812@table @code
2813@item set breakpoint pending auto
2814This is the default behavior. When @value{GDBN} cannot find the breakpoint
2815location, it queries you whether a pending breakpoint should be created.
2816
2817@item set breakpoint pending on
2818This indicates that an unrecognized breakpoint location should automatically
2819result in a pending breakpoint being created.
2820
2821@item set breakpoint pending off
2822This indicates that pending breakpoints are not to be created. Any
2823unrecognized breakpoint location results in an error. This setting does
2824not affect any pending breakpoints previously created.
2825
2826@item show breakpoint pending
2827Show the current behavior setting for creating pending breakpoints.
2828@end table
2650777c 2829
649e03f6
RM
2830@cindex operations allowed on pending breakpoints
2831Normal breakpoint operations apply to pending breakpoints as well. You may
2832specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
2833breakpoint is reached. You can also enable or disable
2834the pending breakpoint. When you specify a condition for a pending breakpoint,
2835the parsing of the condition will be deferred until the point where the
2836pending breakpoint location is resolved. Disabling a pending breakpoint
2837tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
2838shared library load. When a pending breakpoint is re-enabled,
649e03f6 2839@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
2840This is done because any number of shared library loads could have
2841occurred since the time the breakpoint was disabled and one or more
2842of these loads could resolve the location.
2843
c906108c
SS
2844@cindex negative breakpoint numbers
2845@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2846@value{GDBN} itself sometimes sets breakpoints in your program for
2847special purposes, such as proper handling of @code{longjmp} (in C
2848programs). These internal breakpoints are assigned negative numbers,
2849starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2850You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2851@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2852
2853
6d2ebf8b 2854@node Set Watchpoints
c906108c
SS
2855@subsection Setting watchpoints
2856
2857@cindex setting watchpoints
c906108c
SS
2858You can use a watchpoint to stop execution whenever the value of an
2859expression changes, without having to predict a particular place where
2860this may happen.
2861
82f2d802
EZ
2862@cindex software watchpoints
2863@cindex hardware watchpoints
c906108c 2864Depending on your system, watchpoints may be implemented in software or
2df3850c 2865hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2866program and testing the variable's value each time, which is hundreds of
2867times slower than normal execution. (But this may still be worth it, to
2868catch errors where you have no clue what part of your program is the
2869culprit.)
2870
82f2d802
EZ
2871On some systems, such as HP-UX, @sc{gnu}/Linux and most other
2872x86-based targets, @value{GDBN} includes support for hardware
2873watchpoints, which do not slow down the running of your program.
c906108c
SS
2874
2875@table @code
2876@kindex watch
2877@item watch @var{expr}
2878Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2879is written into by the program and its value changes.
2880
2881@kindex rwatch
2882@item rwatch @var{expr}
09d4efe1
EZ
2883Set a watchpoint that will break when the value of @var{expr} is read
2884by the program.
c906108c
SS
2885
2886@kindex awatch
2887@item awatch @var{expr}
09d4efe1
EZ
2888Set a watchpoint that will break when @var{expr} is either read from
2889or written into by the program.
c906108c
SS
2890
2891@kindex info watchpoints
2892@item info watchpoints
2893This command prints a list of watchpoints, breakpoints, and catchpoints;
09d4efe1 2894it is the same as @code{info break} (@pxref{Set Breaks}).
c906108c
SS
2895@end table
2896
2897@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2898watchpoints execute very quickly, and the debugger reports a change in
2899value at the exact instruction where the change occurs. If @value{GDBN}
2900cannot set a hardware watchpoint, it sets a software watchpoint, which
2901executes more slowly and reports the change in value at the next
82f2d802
EZ
2902@emph{statement}, not the instruction, after the change occurs.
2903
82f2d802
EZ
2904@cindex use only software watchpoints
2905You can force @value{GDBN} to use only software watchpoints with the
2906@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
2907zero, @value{GDBN} will never try to use hardware watchpoints, even if
2908the underlying system supports them. (Note that hardware-assisted
2909watchpoints that were set @emph{before} setting
2910@code{can-use-hw-watchpoints} to zero will still use the hardware
2911mechanism of watching expressiion values.)
c906108c 2912
9c16f35a
EZ
2913@table @code
2914@item set can-use-hw-watchpoints
2915@kindex set can-use-hw-watchpoints
2916Set whether or not to use hardware watchpoints.
2917
2918@item show can-use-hw-watchpoints
2919@kindex show can-use-hw-watchpoints
2920Show the current mode of using hardware watchpoints.
2921@end table
2922
2923For remote targets, you can restrict the number of hardware
2924watchpoints @value{GDBN} will use, see @ref{set remote
2925hardware-breakpoint-limit}.
2926
c906108c
SS
2927When you issue the @code{watch} command, @value{GDBN} reports
2928
474c8240 2929@smallexample
c906108c 2930Hardware watchpoint @var{num}: @var{expr}
474c8240 2931@end smallexample
c906108c
SS
2932
2933@noindent
2934if it was able to set a hardware watchpoint.
2935
7be570e7
JM
2936Currently, the @code{awatch} and @code{rwatch} commands can only set
2937hardware watchpoints, because accesses to data that don't change the
2938value of the watched expression cannot be detected without examining
2939every instruction as it is being executed, and @value{GDBN} does not do
2940that currently. If @value{GDBN} finds that it is unable to set a
2941hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2942will print a message like this:
2943
2944@smallexample
2945Expression cannot be implemented with read/access watchpoint.
2946@end smallexample
2947
2948Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2949data type of the watched expression is wider than what a hardware
2950watchpoint on the target machine can handle. For example, some systems
2951can only watch regions that are up to 4 bytes wide; on such systems you
2952cannot set hardware watchpoints for an expression that yields a
2953double-precision floating-point number (which is typically 8 bytes
2954wide). As a work-around, it might be possible to break the large region
2955into a series of smaller ones and watch them with separate watchpoints.
2956
2957If you set too many hardware watchpoints, @value{GDBN} might be unable
2958to insert all of them when you resume the execution of your program.
2959Since the precise number of active watchpoints is unknown until such
2960time as the program is about to be resumed, @value{GDBN} might not be
2961able to warn you about this when you set the watchpoints, and the
2962warning will be printed only when the program is resumed:
2963
2964@smallexample
2965Hardware watchpoint @var{num}: Could not insert watchpoint
2966@end smallexample
2967
2968@noindent
2969If this happens, delete or disable some of the watchpoints.
2970
2971The SPARClite DSU will generate traps when a program accesses some data
2972or instruction address that is assigned to the debug registers. For the
2973data addresses, DSU facilitates the @code{watch} command. However the
2974hardware breakpoint registers can only take two data watchpoints, and
2975both watchpoints must be the same kind. For example, you can set two
2976watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2977@strong{or} two with @code{awatch} commands, but you cannot set one
2978watchpoint with one command and the other with a different command.
c906108c
SS
2979@value{GDBN} will reject the command if you try to mix watchpoints.
2980Delete or disable unused watchpoint commands before setting new ones.
2981
2982If you call a function interactively using @code{print} or @code{call},
2df3850c 2983any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2984kind of breakpoint or the call completes.
2985
7be570e7
JM
2986@value{GDBN} automatically deletes watchpoints that watch local
2987(automatic) variables, or expressions that involve such variables, when
2988they go out of scope, that is, when the execution leaves the block in
2989which these variables were defined. In particular, when the program
2990being debugged terminates, @emph{all} local variables go out of scope,
2991and so only watchpoints that watch global variables remain set. If you
2992rerun the program, you will need to set all such watchpoints again. One
2993way of doing that would be to set a code breakpoint at the entry to the
2994@code{main} function and when it breaks, set all the watchpoints.
2995
c906108c
SS
2996@quotation
2997@cindex watchpoints and threads
2998@cindex threads and watchpoints
c906108c
SS
2999@emph{Warning:} In multi-thread programs, watchpoints have only limited
3000usefulness. With the current watchpoint implementation, @value{GDBN}
3001can only watch the value of an expression @emph{in a single thread}. If
3002you are confident that the expression can only change due to the current
3003thread's activity (and if you are also confident that no other thread
3004can become current), then you can use watchpoints as usual. However,
3005@value{GDBN} may not notice when a non-current thread's activity changes
3006the expression.
53a5351d 3007
d4f3574e 3008@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
3009@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
3010have only limited usefulness. If @value{GDBN} creates a software
3011watchpoint, it can only watch the value of an expression @emph{in a
3012single thread}. If you are confident that the expression can only
3013change due to the current thread's activity (and if you are also
3014confident that no other thread can become current), then you can use
3015software watchpoints as usual. However, @value{GDBN} may not notice
3016when a non-current thread's activity changes the expression. (Hardware
3017watchpoints, in contrast, watch an expression in all threads.)
c906108c 3018@end quotation
c906108c 3019
501eef12
AC
3020@xref{set remote hardware-watchpoint-limit}.
3021
6d2ebf8b 3022@node Set Catchpoints
c906108c 3023@subsection Setting catchpoints
d4f3574e 3024@cindex catchpoints, setting
c906108c
SS
3025@cindex exception handlers
3026@cindex event handling
3027
3028You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 3029kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
3030shared library. Use the @code{catch} command to set a catchpoint.
3031
3032@table @code
3033@kindex catch
3034@item catch @var{event}
3035Stop when @var{event} occurs. @var{event} can be any of the following:
3036@table @code
3037@item throw
4644b6e3 3038@cindex stop on C@t{++} exceptions
b37052ae 3039The throwing of a C@t{++} exception.
c906108c
SS
3040
3041@item catch
b37052ae 3042The catching of a C@t{++} exception.
c906108c
SS
3043
3044@item exec
4644b6e3 3045@cindex break on fork/exec
c906108c
SS
3046A call to @code{exec}. This is currently only available for HP-UX.
3047
3048@item fork
c906108c
SS
3049A call to @code{fork}. This is currently only available for HP-UX.
3050
3051@item vfork
c906108c
SS
3052A call to @code{vfork}. This is currently only available for HP-UX.
3053
3054@item load
3055@itemx load @var{libname}
4644b6e3 3056@cindex break on load/unload of shared library
c906108c
SS
3057The dynamic loading of any shared library, or the loading of the library
3058@var{libname}. This is currently only available for HP-UX.
3059
3060@item unload
3061@itemx unload @var{libname}
c906108c
SS
3062The unloading of any dynamically loaded shared library, or the unloading
3063of the library @var{libname}. This is currently only available for HP-UX.
3064@end table
3065
3066@item tcatch @var{event}
3067Set a catchpoint that is enabled only for one stop. The catchpoint is
3068automatically deleted after the first time the event is caught.
3069
3070@end table
3071
3072Use the @code{info break} command to list the current catchpoints.
3073
b37052ae 3074There are currently some limitations to C@t{++} exception handling
c906108c
SS
3075(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3076
3077@itemize @bullet
3078@item
3079If you call a function interactively, @value{GDBN} normally returns
3080control to you when the function has finished executing. If the call
3081raises an exception, however, the call may bypass the mechanism that
3082returns control to you and cause your program either to abort or to
3083simply continue running until it hits a breakpoint, catches a signal
3084that @value{GDBN} is listening for, or exits. This is the case even if
3085you set a catchpoint for the exception; catchpoints on exceptions are
3086disabled within interactive calls.
3087
3088@item
3089You cannot raise an exception interactively.
3090
3091@item
3092You cannot install an exception handler interactively.
3093@end itemize
3094
3095@cindex raise exceptions
3096Sometimes @code{catch} is not the best way to debug exception handling:
3097if you need to know exactly where an exception is raised, it is better to
3098stop @emph{before} the exception handler is called, since that way you
3099can see the stack before any unwinding takes place. If you set a
3100breakpoint in an exception handler instead, it may not be easy to find
3101out where the exception was raised.
3102
3103To stop just before an exception handler is called, you need some
b37052ae 3104knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
3105raised by calling a library function named @code{__raise_exception}
3106which has the following ANSI C interface:
3107
474c8240 3108@smallexample
c906108c 3109 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
3110 @var{id} is the exception identifier. */
3111 void __raise_exception (void **addr, void *id);
474c8240 3112@end smallexample
c906108c
SS
3113
3114@noindent
3115To make the debugger catch all exceptions before any stack
3116unwinding takes place, set a breakpoint on @code{__raise_exception}
3117(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
3118
3119With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
3120that depends on the value of @var{id}, you can stop your program when
3121a specific exception is raised. You can use multiple conditional
3122breakpoints to stop your program when any of a number of exceptions are
3123raised.
3124
3125
6d2ebf8b 3126@node Delete Breaks
c906108c
SS
3127@subsection Deleting breakpoints
3128
3129@cindex clearing breakpoints, watchpoints, catchpoints
3130@cindex deleting breakpoints, watchpoints, catchpoints
3131It is often necessary to eliminate a breakpoint, watchpoint, or
3132catchpoint once it has done its job and you no longer want your program
3133to stop there. This is called @dfn{deleting} the breakpoint. A
3134breakpoint that has been deleted no longer exists; it is forgotten.
3135
3136With the @code{clear} command you can delete breakpoints according to
3137where they are in your program. With the @code{delete} command you can
3138delete individual breakpoints, watchpoints, or catchpoints by specifying
3139their breakpoint numbers.
3140
3141It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3142automatically ignores breakpoints on the first instruction to be executed
3143when you continue execution without changing the execution address.
3144
3145@table @code
3146@kindex clear
3147@item clear
3148Delete any breakpoints at the next instruction to be executed in the
3149selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3150the innermost frame is selected, this is a good way to delete a
3151breakpoint where your program just stopped.
3152
3153@item clear @var{function}
3154@itemx clear @var{filename}:@var{function}
09d4efe1 3155Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
3156
3157@item clear @var{linenum}
3158@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
3159Delete any breakpoints set at or within the code of the specified
3160@var{linenum} of the specified @var{filename}.
c906108c
SS
3161
3162@cindex delete breakpoints
3163@kindex delete
41afff9a 3164@kindex d @r{(@code{delete})}
c5394b80
JM
3165@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3166Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3167ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3168breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3169confirm off}). You can abbreviate this command as @code{d}.
3170@end table
3171
6d2ebf8b 3172@node Disabling
c906108c
SS
3173@subsection Disabling breakpoints
3174
4644b6e3 3175@cindex enable/disable a breakpoint
c906108c
SS
3176Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3177prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3178it had been deleted, but remembers the information on the breakpoint so
3179that you can @dfn{enable} it again later.
3180
3181You disable and enable breakpoints, watchpoints, and catchpoints with
3182the @code{enable} and @code{disable} commands, optionally specifying one
3183or more breakpoint numbers as arguments. Use @code{info break} or
3184@code{info watch} to print a list of breakpoints, watchpoints, and
3185catchpoints if you do not know which numbers to use.
3186
3187A breakpoint, watchpoint, or catchpoint can have any of four different
3188states of enablement:
3189
3190@itemize @bullet
3191@item
3192Enabled. The breakpoint stops your program. A breakpoint set
3193with the @code{break} command starts out in this state.
3194@item
3195Disabled. The breakpoint has no effect on your program.
3196@item
3197Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3198disabled.
c906108c
SS
3199@item
3200Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3201immediately after it does so it is deleted permanently. A breakpoint
3202set with the @code{tbreak} command starts out in this state.
c906108c
SS
3203@end itemize
3204
3205You can use the following commands to enable or disable breakpoints,
3206watchpoints, and catchpoints:
3207
3208@table @code
c906108c 3209@kindex disable
41afff9a 3210@kindex dis @r{(@code{disable})}
c5394b80 3211@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3212Disable the specified breakpoints---or all breakpoints, if none are
3213listed. A disabled breakpoint has no effect but is not forgotten. All
3214options such as ignore-counts, conditions and commands are remembered in
3215case the breakpoint is enabled again later. You may abbreviate
3216@code{disable} as @code{dis}.
3217
c906108c 3218@kindex enable
c5394b80 3219@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3220Enable the specified breakpoints (or all defined breakpoints). They
3221become effective once again in stopping your program.
3222
c5394b80 3223@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3224Enable the specified breakpoints temporarily. @value{GDBN} disables any
3225of these breakpoints immediately after stopping your program.
3226
c5394b80 3227@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3228Enable the specified breakpoints to work once, then die. @value{GDBN}
3229deletes any of these breakpoints as soon as your program stops there.
09d4efe1 3230Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
3231@end table
3232
d4f3574e
SS
3233@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3234@c confusing: tbreak is also initially enabled.
c906108c
SS
3235Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3236,Setting breakpoints}), breakpoints that you set are initially enabled;
3237subsequently, they become disabled or enabled only when you use one of
3238the commands above. (The command @code{until} can set and delete a
3239breakpoint of its own, but it does not change the state of your other
3240breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3241stepping}.)
3242
6d2ebf8b 3243@node Conditions
c906108c
SS
3244@subsection Break conditions
3245@cindex conditional breakpoints
3246@cindex breakpoint conditions
3247
3248@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3249@c in particular for a watchpoint?
c906108c
SS
3250The simplest sort of breakpoint breaks every time your program reaches a
3251specified place. You can also specify a @dfn{condition} for a
3252breakpoint. A condition is just a Boolean expression in your
3253programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3254a condition evaluates the expression each time your program reaches it,
3255and your program stops only if the condition is @emph{true}.
3256
3257This is the converse of using assertions for program validation; in that
3258situation, you want to stop when the assertion is violated---that is,
3259when the condition is false. In C, if you want to test an assertion expressed
3260by the condition @var{assert}, you should set the condition
3261@samp{! @var{assert}} on the appropriate breakpoint.
3262
3263Conditions are also accepted for watchpoints; you may not need them,
3264since a watchpoint is inspecting the value of an expression anyhow---but
3265it might be simpler, say, to just set a watchpoint on a variable name,
3266and specify a condition that tests whether the new value is an interesting
3267one.
3268
3269Break conditions can have side effects, and may even call functions in
3270your program. This can be useful, for example, to activate functions
3271that log program progress, or to use your own print functions to
3272format special data structures. The effects are completely predictable
3273unless there is another enabled breakpoint at the same address. (In
3274that case, @value{GDBN} might see the other breakpoint first and stop your
3275program without checking the condition of this one.) Note that
d4f3574e
SS
3276breakpoint commands are usually more convenient and flexible than break
3277conditions for the
c906108c
SS
3278purpose of performing side effects when a breakpoint is reached
3279(@pxref{Break Commands, ,Breakpoint command lists}).
3280
3281Break conditions can be specified when a breakpoint is set, by using
3282@samp{if} in the arguments to the @code{break} command. @xref{Set
3283Breaks, ,Setting breakpoints}. They can also be changed at any time
3284with the @code{condition} command.
53a5351d 3285
c906108c
SS
3286You can also use the @code{if} keyword with the @code{watch} command.
3287The @code{catch} command does not recognize the @code{if} keyword;
3288@code{condition} is the only way to impose a further condition on a
3289catchpoint.
c906108c
SS
3290
3291@table @code
3292@kindex condition
3293@item condition @var{bnum} @var{expression}
3294Specify @var{expression} as the break condition for breakpoint,
3295watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3296breakpoint @var{bnum} stops your program only if the value of
3297@var{expression} is true (nonzero, in C). When you use
3298@code{condition}, @value{GDBN} checks @var{expression} immediately for
3299syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3300referents in the context of your breakpoint. If @var{expression} uses
3301symbols not referenced in the context of the breakpoint, @value{GDBN}
3302prints an error message:
3303
474c8240 3304@smallexample
d4f3574e 3305No symbol "foo" in current context.
474c8240 3306@end smallexample
d4f3574e
SS
3307
3308@noindent
c906108c
SS
3309@value{GDBN} does
3310not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3311command (or a command that sets a breakpoint with a condition, like
3312@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3313
3314@item condition @var{bnum}
3315Remove the condition from breakpoint number @var{bnum}. It becomes
3316an ordinary unconditional breakpoint.
3317@end table
3318
3319@cindex ignore count (of breakpoint)
3320A special case of a breakpoint condition is to stop only when the
3321breakpoint has been reached a certain number of times. This is so
3322useful that there is a special way to do it, using the @dfn{ignore
3323count} of the breakpoint. Every breakpoint has an ignore count, which
3324is an integer. Most of the time, the ignore count is zero, and
3325therefore has no effect. But if your program reaches a breakpoint whose
3326ignore count is positive, then instead of stopping, it just decrements
3327the ignore count by one and continues. As a result, if the ignore count
3328value is @var{n}, the breakpoint does not stop the next @var{n} times
3329your program reaches it.
3330
3331@table @code
3332@kindex ignore
3333@item ignore @var{bnum} @var{count}
3334Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3335The next @var{count} times the breakpoint is reached, your program's
3336execution does not stop; other than to decrement the ignore count, @value{GDBN}
3337takes no action.
3338
3339To make the breakpoint stop the next time it is reached, specify
3340a count of zero.
3341
3342When you use @code{continue} to resume execution of your program from a
3343breakpoint, you can specify an ignore count directly as an argument to
3344@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3345Stepping,,Continuing and stepping}.
3346
3347If a breakpoint has a positive ignore count and a condition, the
3348condition is not checked. Once the ignore count reaches zero,
3349@value{GDBN} resumes checking the condition.
3350
3351You could achieve the effect of the ignore count with a condition such
3352as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3353is decremented each time. @xref{Convenience Vars, ,Convenience
3354variables}.
3355@end table
3356
3357Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3358
3359
6d2ebf8b 3360@node Break Commands
c906108c
SS
3361@subsection Breakpoint command lists
3362
3363@cindex breakpoint commands
3364You can give any breakpoint (or watchpoint or catchpoint) a series of
3365commands to execute when your program stops due to that breakpoint. For
3366example, you might want to print the values of certain expressions, or
3367enable other breakpoints.
3368
3369@table @code
3370@kindex commands
3371@kindex end
3372@item commands @r{[}@var{bnum}@r{]}
3373@itemx @dots{} @var{command-list} @dots{}
3374@itemx end
3375Specify a list of commands for breakpoint number @var{bnum}. The commands
3376themselves appear on the following lines. Type a line containing just
3377@code{end} to terminate the commands.
3378
3379To remove all commands from a breakpoint, type @code{commands} and
3380follow it immediately with @code{end}; that is, give no commands.
3381
3382With no @var{bnum} argument, @code{commands} refers to the last
3383breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3384recently encountered).
3385@end table
3386
3387Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3388disabled within a @var{command-list}.
3389
3390You can use breakpoint commands to start your program up again. Simply
3391use the @code{continue} command, or @code{step}, or any other command
3392that resumes execution.
3393
3394Any other commands in the command list, after a command that resumes
3395execution, are ignored. This is because any time you resume execution
3396(even with a simple @code{next} or @code{step}), you may encounter
3397another breakpoint---which could have its own command list, leading to
3398ambiguities about which list to execute.
3399
3400@kindex silent
3401If the first command you specify in a command list is @code{silent}, the
3402usual message about stopping at a breakpoint is not printed. This may
3403be desirable for breakpoints that are to print a specific message and
3404then continue. If none of the remaining commands print anything, you
3405see no sign that the breakpoint was reached. @code{silent} is
3406meaningful only at the beginning of a breakpoint command list.
3407
3408The commands @code{echo}, @code{output}, and @code{printf} allow you to
3409print precisely controlled output, and are often useful in silent
3410breakpoints. @xref{Output, ,Commands for controlled output}.
3411
3412For example, here is how you could use breakpoint commands to print the
3413value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3414
474c8240 3415@smallexample
c906108c
SS
3416break foo if x>0
3417commands
3418silent
3419printf "x is %d\n",x
3420cont
3421end
474c8240 3422@end smallexample
c906108c
SS
3423
3424One application for breakpoint commands is to compensate for one bug so
3425you can test for another. Put a breakpoint just after the erroneous line
3426of code, give it a condition to detect the case in which something
3427erroneous has been done, and give it commands to assign correct values
3428to any variables that need them. End with the @code{continue} command
3429so that your program does not stop, and start with the @code{silent}
3430command so that no output is produced. Here is an example:
3431
474c8240 3432@smallexample
c906108c
SS
3433break 403
3434commands
3435silent
3436set x = y + 4
3437cont
3438end
474c8240 3439@end smallexample
c906108c 3440
6d2ebf8b 3441@node Breakpoint Menus
c906108c
SS
3442@subsection Breakpoint menus
3443@cindex overloading
3444@cindex symbol overloading
3445
b383017d 3446Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3447single function name
c906108c
SS
3448to be defined several times, for application in different contexts.
3449This is called @dfn{overloading}. When a function name is overloaded,
3450@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3451a breakpoint. If you realize this is a problem, you can use
3452something like @samp{break @var{function}(@var{types})} to specify which
3453particular version of the function you want. Otherwise, @value{GDBN} offers
3454you a menu of numbered choices for different possible breakpoints, and
3455waits for your selection with the prompt @samp{>}. The first two
3456options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3457sets a breakpoint at each definition of @var{function}, and typing
3458@kbd{0} aborts the @code{break} command without setting any new
3459breakpoints.
3460
3461For example, the following session excerpt shows an attempt to set a
3462breakpoint at the overloaded symbol @code{String::after}.
3463We choose three particular definitions of that function name:
3464
3465@c FIXME! This is likely to change to show arg type lists, at least
3466@smallexample
3467@group
3468(@value{GDBP}) b String::after
3469[0] cancel
3470[1] all
3471[2] file:String.cc; line number:867
3472[3] file:String.cc; line number:860
3473[4] file:String.cc; line number:875
3474[5] file:String.cc; line number:853
3475[6] file:String.cc; line number:846
3476[7] file:String.cc; line number:735
3477> 2 4 6
3478Breakpoint 1 at 0xb26c: file String.cc, line 867.
3479Breakpoint 2 at 0xb344: file String.cc, line 875.
3480Breakpoint 3 at 0xafcc: file String.cc, line 846.
3481Multiple breakpoints were set.
3482Use the "delete" command to delete unwanted
3483 breakpoints.
3484(@value{GDBP})
3485@end group
3486@end smallexample
c906108c
SS
3487
3488@c @ifclear BARETARGET
6d2ebf8b 3489@node Error in Breakpoints
d4f3574e 3490@subsection ``Cannot insert breakpoints''
c906108c
SS
3491@c
3492@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3493@c
d4f3574e
SS
3494Under some operating systems, breakpoints cannot be used in a program if
3495any other process is running that program. In this situation,
5d161b24 3496attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3497@value{GDBN} to print an error message:
3498
474c8240 3499@smallexample
d4f3574e
SS
3500Cannot insert breakpoints.
3501The same program may be running in another process.
474c8240 3502@end smallexample
d4f3574e
SS
3503
3504When this happens, you have three ways to proceed:
3505
3506@enumerate
3507@item
3508Remove or disable the breakpoints, then continue.
3509
3510@item
5d161b24 3511Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3512name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3513that @value{GDBN} should run your program under that name.
d4f3574e
SS
3514Then start your program again.
3515
3516@item
3517Relink your program so that the text segment is nonsharable, using the
3518linker option @samp{-N}. The operating system limitation may not apply
3519to nonsharable executables.
3520@end enumerate
c906108c
SS
3521@c @end ifclear
3522
d4f3574e
SS
3523A similar message can be printed if you request too many active
3524hardware-assisted breakpoints and watchpoints:
3525
3526@c FIXME: the precise wording of this message may change; the relevant
3527@c source change is not committed yet (Sep 3, 1999).
3528@smallexample
3529Stopped; cannot insert breakpoints.
3530You may have requested too many hardware breakpoints and watchpoints.
3531@end smallexample
3532
3533@noindent
3534This message is printed when you attempt to resume the program, since
3535only then @value{GDBN} knows exactly how many hardware breakpoints and
3536watchpoints it needs to insert.
3537
3538When this message is printed, you need to disable or remove some of the
3539hardware-assisted breakpoints and watchpoints, and then continue.
3540
1485d690
KB
3541@node Breakpoint related warnings
3542@subsection ``Breakpoint address adjusted...''
3543@cindex breakpoint address adjusted
3544
3545Some processor architectures place constraints on the addresses at
3546which breakpoints may be placed. For architectures thus constrained,
3547@value{GDBN} will attempt to adjust the breakpoint's address to comply
3548with the constraints dictated by the architecture.
3549
3550One example of such an architecture is the Fujitsu FR-V. The FR-V is
3551a VLIW architecture in which a number of RISC-like instructions may be
3552bundled together for parallel execution. The FR-V architecture
3553constrains the location of a breakpoint instruction within such a
3554bundle to the instruction with the lowest address. @value{GDBN}
3555honors this constraint by adjusting a breakpoint's address to the
3556first in the bundle.
3557
3558It is not uncommon for optimized code to have bundles which contain
3559instructions from different source statements, thus it may happen that
3560a breakpoint's address will be adjusted from one source statement to
3561another. Since this adjustment may significantly alter @value{GDBN}'s
3562breakpoint related behavior from what the user expects, a warning is
3563printed when the breakpoint is first set and also when the breakpoint
3564is hit.
3565
3566A warning like the one below is printed when setting a breakpoint
3567that's been subject to address adjustment:
3568
3569@smallexample
3570warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3571@end smallexample
3572
3573Such warnings are printed both for user settable and @value{GDBN}'s
3574internal breakpoints. If you see one of these warnings, you should
3575verify that a breakpoint set at the adjusted address will have the
3576desired affect. If not, the breakpoint in question may be removed and
b383017d 3577other breakpoints may be set which will have the desired behavior.
1485d690
KB
3578E.g., it may be sufficient to place the breakpoint at a later
3579instruction. A conditional breakpoint may also be useful in some
3580cases to prevent the breakpoint from triggering too often.
3581
3582@value{GDBN} will also issue a warning when stopping at one of these
3583adjusted breakpoints:
3584
3585@smallexample
3586warning: Breakpoint 1 address previously adjusted from 0x00010414
3587to 0x00010410.
3588@end smallexample
3589
3590When this warning is encountered, it may be too late to take remedial
3591action except in cases where the breakpoint is hit earlier or more
3592frequently than expected.
d4f3574e 3593
6d2ebf8b 3594@node Continuing and Stepping
c906108c
SS
3595@section Continuing and stepping
3596
3597@cindex stepping
3598@cindex continuing
3599@cindex resuming execution
3600@dfn{Continuing} means resuming program execution until your program
3601completes normally. In contrast, @dfn{stepping} means executing just
3602one more ``step'' of your program, where ``step'' may mean either one
3603line of source code, or one machine instruction (depending on what
7a292a7a
SS
3604particular command you use). Either when continuing or when stepping,
3605your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3606it stops due to a signal, you may want to use @code{handle}, or use
3607@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3608
3609@table @code
3610@kindex continue
41afff9a
EZ
3611@kindex c @r{(@code{continue})}
3612@kindex fg @r{(resume foreground execution)}
c906108c
SS
3613@item continue @r{[}@var{ignore-count}@r{]}
3614@itemx c @r{[}@var{ignore-count}@r{]}
3615@itemx fg @r{[}@var{ignore-count}@r{]}
3616Resume program execution, at the address where your program last stopped;
3617any breakpoints set at that address are bypassed. The optional argument
3618@var{ignore-count} allows you to specify a further number of times to
3619ignore a breakpoint at this location; its effect is like that of
3620@code{ignore} (@pxref{Conditions, ,Break conditions}).
3621
3622The argument @var{ignore-count} is meaningful only when your program
3623stopped due to a breakpoint. At other times, the argument to
3624@code{continue} is ignored.
3625
d4f3574e
SS
3626The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3627debugged program is deemed to be the foreground program) are provided
3628purely for convenience, and have exactly the same behavior as
3629@code{continue}.
c906108c
SS
3630@end table
3631
3632To resume execution at a different place, you can use @code{return}
3633(@pxref{Returning, ,Returning from a function}) to go back to the
3634calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3635different address}) to go to an arbitrary location in your program.
3636
3637A typical technique for using stepping is to set a breakpoint
3638(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3639beginning of the function or the section of your program where a problem
3640is believed to lie, run your program until it stops at that breakpoint,
3641and then step through the suspect area, examining the variables that are
3642interesting, until you see the problem happen.
3643
3644@table @code
3645@kindex step
41afff9a 3646@kindex s @r{(@code{step})}
c906108c
SS
3647@item step
3648Continue running your program until control reaches a different source
3649line, then stop it and return control to @value{GDBN}. This command is
3650abbreviated @code{s}.
3651
3652@quotation
3653@c "without debugging information" is imprecise; actually "without line
3654@c numbers in the debugging information". (gcc -g1 has debugging info but
3655@c not line numbers). But it seems complex to try to make that
3656@c distinction here.
3657@emph{Warning:} If you use the @code{step} command while control is
3658within a function that was compiled without debugging information,
3659execution proceeds until control reaches a function that does have
3660debugging information. Likewise, it will not step into a function which
3661is compiled without debugging information. To step through functions
3662without debugging information, use the @code{stepi} command, described
3663below.
3664@end quotation
3665
4a92d011
EZ
3666The @code{step} command only stops at the first instruction of a source
3667line. This prevents the multiple stops that could otherwise occur in
3668@code{switch} statements, @code{for} loops, etc. @code{step} continues
3669to stop if a function that has debugging information is called within
3670the line. In other words, @code{step} @emph{steps inside} any functions
3671called within the line.
c906108c 3672
d4f3574e
SS
3673Also, the @code{step} command only enters a function if there is line
3674number information for the function. Otherwise it acts like the
5d161b24 3675@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3676on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3677was any debugging information about the routine.
c906108c
SS
3678
3679@item step @var{count}
3680Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3681breakpoint is reached, or a signal not related to stepping occurs before
3682@var{count} steps, stepping stops right away.
c906108c
SS
3683
3684@kindex next
41afff9a 3685@kindex n @r{(@code{next})}
c906108c
SS
3686@item next @r{[}@var{count}@r{]}
3687Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3688This is similar to @code{step}, but function calls that appear within
3689the line of code are executed without stopping. Execution stops when
3690control reaches a different line of code at the original stack level
3691that was executing when you gave the @code{next} command. This command
3692is abbreviated @code{n}.
c906108c
SS
3693
3694An argument @var{count} is a repeat count, as for @code{step}.
3695
3696
3697@c FIX ME!! Do we delete this, or is there a way it fits in with
3698@c the following paragraph? --- Vctoria
3699@c
3700@c @code{next} within a function that lacks debugging information acts like
3701@c @code{step}, but any function calls appearing within the code of the
3702@c function are executed without stopping.
3703
d4f3574e
SS
3704The @code{next} command only stops at the first instruction of a
3705source line. This prevents multiple stops that could otherwise occur in
4a92d011 3706@code{switch} statements, @code{for} loops, etc.
c906108c 3707
b90a5f51
CF
3708@kindex set step-mode
3709@item set step-mode
3710@cindex functions without line info, and stepping
3711@cindex stepping into functions with no line info
3712@itemx set step-mode on
4a92d011 3713The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3714stop at the first instruction of a function which contains no debug line
3715information rather than stepping over it.
3716
4a92d011
EZ
3717This is useful in cases where you may be interested in inspecting the
3718machine instructions of a function which has no symbolic info and do not
3719want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3720
3721@item set step-mode off
4a92d011 3722Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3723debug information. This is the default.
3724
9c16f35a
EZ
3725@item show step-mode
3726Show whether @value{GDBN} will stop in or step over functions without
3727source line debug information.
3728
c906108c
SS
3729@kindex finish
3730@item finish
3731Continue running until just after function in the selected stack frame
3732returns. Print the returned value (if any).
3733
3734Contrast this with the @code{return} command (@pxref{Returning,
3735,Returning from a function}).
3736
3737@kindex until
41afff9a 3738@kindex u @r{(@code{until})}
09d4efe1 3739@cindex run until specified location
c906108c
SS
3740@item until
3741@itemx u
3742Continue running until a source line past the current line, in the
3743current stack frame, is reached. This command is used to avoid single
3744stepping through a loop more than once. It is like the @code{next}
3745command, except that when @code{until} encounters a jump, it
3746automatically continues execution until the program counter is greater
3747than the address of the jump.
3748
3749This means that when you reach the end of a loop after single stepping
3750though it, @code{until} makes your program continue execution until it
3751exits the loop. In contrast, a @code{next} command at the end of a loop
3752simply steps back to the beginning of the loop, which forces you to step
3753through the next iteration.
3754
3755@code{until} always stops your program if it attempts to exit the current
3756stack frame.
3757
3758@code{until} may produce somewhat counterintuitive results if the order
3759of machine code does not match the order of the source lines. For
3760example, in the following excerpt from a debugging session, the @code{f}
3761(@code{frame}) command shows that execution is stopped at line
3762@code{206}; yet when we use @code{until}, we get to line @code{195}:
3763
474c8240 3764@smallexample
c906108c
SS
3765(@value{GDBP}) f
3766#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3767206 expand_input();
3768(@value{GDBP}) until
3769195 for ( ; argc > 0; NEXTARG) @{
474c8240 3770@end smallexample
c906108c
SS
3771
3772This happened because, for execution efficiency, the compiler had
3773generated code for the loop closure test at the end, rather than the
3774start, of the loop---even though the test in a C @code{for}-loop is
3775written before the body of the loop. The @code{until} command appeared
3776to step back to the beginning of the loop when it advanced to this
3777expression; however, it has not really gone to an earlier
3778statement---not in terms of the actual machine code.
3779
3780@code{until} with no argument works by means of single
3781instruction stepping, and hence is slower than @code{until} with an
3782argument.
3783
3784@item until @var{location}
3785@itemx u @var{location}
3786Continue running your program until either the specified location is
3787reached, or the current stack frame returns. @var{location} is any of
3788the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
3789,Setting breakpoints}). This form of the command uses breakpoints, and
3790hence is quicker than @code{until} without an argument. The specified
3791location is actually reached only if it is in the current frame. This
3792implies that @code{until} can be used to skip over recursive function
3793invocations. For instance in the code below, if the current location is
3794line @code{96}, issuing @code{until 99} will execute the program up to
3795line @code{99} in the same invocation of factorial, i.e. after the inner
3796invocations have returned.
3797
3798@smallexample
379994 int factorial (int value)
380095 @{
380196 if (value > 1) @{
380297 value *= factorial (value - 1);
380398 @}
380499 return (value);
3805100 @}
3806@end smallexample
3807
3808
3809@kindex advance @var{location}
3810@itemx advance @var{location}
09d4efe1
EZ
3811Continue running the program up to the given @var{location}. An argument is
3812required, which should be of the same form as arguments for the @code{break}
c60eb6f1
EZ
3813command. Execution will also stop upon exit from the current stack
3814frame. This command is similar to @code{until}, but @code{advance} will
3815not skip over recursive function calls, and the target location doesn't
3816have to be in the same frame as the current one.
3817
c906108c
SS
3818
3819@kindex stepi
41afff9a 3820@kindex si @r{(@code{stepi})}
c906108c 3821@item stepi
96a2c332 3822@itemx stepi @var{arg}
c906108c
SS
3823@itemx si
3824Execute one machine instruction, then stop and return to the debugger.
3825
3826It is often useful to do @samp{display/i $pc} when stepping by machine
3827instructions. This makes @value{GDBN} automatically display the next
3828instruction to be executed, each time your program stops. @xref{Auto
3829Display,, Automatic display}.
3830
3831An argument is a repeat count, as in @code{step}.
3832
3833@need 750
3834@kindex nexti
41afff9a 3835@kindex ni @r{(@code{nexti})}
c906108c 3836@item nexti
96a2c332 3837@itemx nexti @var{arg}
c906108c
SS
3838@itemx ni
3839Execute one machine instruction, but if it is a function call,
3840proceed until the function returns.
3841
3842An argument is a repeat count, as in @code{next}.
3843@end table
3844
6d2ebf8b 3845@node Signals
c906108c
SS
3846@section Signals
3847@cindex signals
3848
3849A signal is an asynchronous event that can happen in a program. The
3850operating system defines the possible kinds of signals, and gives each
3851kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3852signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3853@code{SIGSEGV} is the signal a program gets from referencing a place in
3854memory far away from all the areas in use; @code{SIGALRM} occurs when
3855the alarm clock timer goes off (which happens only if your program has
3856requested an alarm).
3857
3858@cindex fatal signals
3859Some signals, including @code{SIGALRM}, are a normal part of the
3860functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3861errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3862program has not specified in advance some other way to handle the signal.
3863@code{SIGINT} does not indicate an error in your program, but it is normally
3864fatal so it can carry out the purpose of the interrupt: to kill the program.
3865
3866@value{GDBN} has the ability to detect any occurrence of a signal in your
3867program. You can tell @value{GDBN} in advance what to do for each kind of
3868signal.
3869
3870@cindex handling signals
24f93129
EZ
3871Normally, @value{GDBN} is set up to let the non-erroneous signals like
3872@code{SIGALRM} be silently passed to your program
3873(so as not to interfere with their role in the program's functioning)
c906108c
SS
3874but to stop your program immediately whenever an error signal happens.
3875You can change these settings with the @code{handle} command.
3876
3877@table @code
3878@kindex info signals
09d4efe1 3879@kindex info handle
c906108c 3880@item info signals
96a2c332 3881@itemx info handle
c906108c
SS
3882Print a table of all the kinds of signals and how @value{GDBN} has been told to
3883handle each one. You can use this to see the signal numbers of all
3884the defined types of signals.
3885
d4f3574e 3886@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3887
3888@kindex handle
3889@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3890Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3891can be the number of a signal or its name (with or without the
24f93129 3892@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3893@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3894known signals. The @var{keywords} say what change to make.
c906108c
SS
3895@end table
3896
3897@c @group
3898The keywords allowed by the @code{handle} command can be abbreviated.
3899Their full names are:
3900
3901@table @code
3902@item nostop
3903@value{GDBN} should not stop your program when this signal happens. It may
3904still print a message telling you that the signal has come in.
3905
3906@item stop
3907@value{GDBN} should stop your program when this signal happens. This implies
3908the @code{print} keyword as well.
3909
3910@item print
3911@value{GDBN} should print a message when this signal happens.
3912
3913@item noprint
3914@value{GDBN} should not mention the occurrence of the signal at all. This
3915implies the @code{nostop} keyword as well.
3916
3917@item pass
5ece1a18 3918@itemx noignore
c906108c
SS
3919@value{GDBN} should allow your program to see this signal; your program
3920can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3921and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3922
3923@item nopass
5ece1a18 3924@itemx ignore
c906108c 3925@value{GDBN} should not allow your program to see this signal.
5ece1a18 3926@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3927@end table
3928@c @end group
3929
d4f3574e
SS
3930When a signal stops your program, the signal is not visible to the
3931program until you
c906108c
SS
3932continue. Your program sees the signal then, if @code{pass} is in
3933effect for the signal in question @emph{at that time}. In other words,
3934after @value{GDBN} reports a signal, you can use the @code{handle}
3935command with @code{pass} or @code{nopass} to control whether your
3936program sees that signal when you continue.
3937
24f93129
EZ
3938The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3939non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3940@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3941erroneous signals.
3942
c906108c
SS
3943You can also use the @code{signal} command to prevent your program from
3944seeing a signal, or cause it to see a signal it normally would not see,
3945or to give it any signal at any time. For example, if your program stopped
3946due to some sort of memory reference error, you might store correct
3947values into the erroneous variables and continue, hoping to see more
3948execution; but your program would probably terminate immediately as
3949a result of the fatal signal once it saw the signal. To prevent this,
3950you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3951program a signal}.
c906108c 3952
6d2ebf8b 3953@node Thread Stops
c906108c
SS
3954@section Stopping and starting multi-thread programs
3955
3956When your program has multiple threads (@pxref{Threads,, Debugging
3957programs with multiple threads}), you can choose whether to set
3958breakpoints on all threads, or on a particular thread.
3959
3960@table @code
3961@cindex breakpoints and threads
3962@cindex thread breakpoints
3963@kindex break @dots{} thread @var{threadno}
3964@item break @var{linespec} thread @var{threadno}
3965@itemx break @var{linespec} thread @var{threadno} if @dots{}
3966@var{linespec} specifies source lines; there are several ways of
3967writing them, but the effect is always to specify some source line.
3968
3969Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3970to specify that you only want @value{GDBN} to stop the program when a
3971particular thread reaches this breakpoint. @var{threadno} is one of the
3972numeric thread identifiers assigned by @value{GDBN}, shown in the first
3973column of the @samp{info threads} display.
3974
3975If you do not specify @samp{thread @var{threadno}} when you set a
3976breakpoint, the breakpoint applies to @emph{all} threads of your
3977program.
3978
3979You can use the @code{thread} qualifier on conditional breakpoints as
3980well; in this case, place @samp{thread @var{threadno}} before the
3981breakpoint condition, like this:
3982
3983@smallexample
2df3850c 3984(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3985@end smallexample
3986
3987@end table
3988
3989@cindex stopped threads
3990@cindex threads, stopped
3991Whenever your program stops under @value{GDBN} for any reason,
3992@emph{all} threads of execution stop, not just the current thread. This
3993allows you to examine the overall state of the program, including
3994switching between threads, without worrying that things may change
3995underfoot.
3996
36d86913
MC
3997@cindex thread breakpoints and system calls
3998@cindex system calls and thread breakpoints
3999@cindex premature return from system calls
4000There is an unfortunate side effect. If one thread stops for a
4001breakpoint, or for some other reason, and another thread is blocked in a
4002system call, then the system call may return prematurely. This is a
4003consequence of the interaction between multiple threads and the signals
4004that @value{GDBN} uses to implement breakpoints and other events that
4005stop execution.
4006
4007To handle this problem, your program should check the return value of
4008each system call and react appropriately. This is good programming
4009style anyways.
4010
4011For example, do not write code like this:
4012
4013@smallexample
4014 sleep (10);
4015@end smallexample
4016
4017The call to @code{sleep} will return early if a different thread stops
4018at a breakpoint or for some other reason.
4019
4020Instead, write this:
4021
4022@smallexample
4023 int unslept = 10;
4024 while (unslept > 0)
4025 unslept = sleep (unslept);
4026@end smallexample
4027
4028A system call is allowed to return early, so the system is still
4029conforming to its specification. But @value{GDBN} does cause your
4030multi-threaded program to behave differently than it would without
4031@value{GDBN}.
4032
4033Also, @value{GDBN} uses internal breakpoints in the thread library to
4034monitor certain events such as thread creation and thread destruction.
4035When such an event happens, a system call in another thread may return
4036prematurely, even though your program does not appear to stop.
4037
c906108c
SS
4038@cindex continuing threads
4039@cindex threads, continuing
4040Conversely, whenever you restart the program, @emph{all} threads start
4041executing. @emph{This is true even when single-stepping} with commands
5d161b24 4042like @code{step} or @code{next}.
c906108c
SS
4043
4044In particular, @value{GDBN} cannot single-step all threads in lockstep.
4045Since thread scheduling is up to your debugging target's operating
4046system (not controlled by @value{GDBN}), other threads may
4047execute more than one statement while the current thread completes a
4048single step. Moreover, in general other threads stop in the middle of a
4049statement, rather than at a clean statement boundary, when the program
4050stops.
4051
4052You might even find your program stopped in another thread after
4053continuing or even single-stepping. This happens whenever some other
4054thread runs into a breakpoint, a signal, or an exception before the
4055first thread completes whatever you requested.
4056
4057On some OSes, you can lock the OS scheduler and thus allow only a single
4058thread to run.
4059
4060@table @code
4061@item set scheduler-locking @var{mode}
9c16f35a
EZ
4062@cindex scheduler locking mode
4063@cindex lock scheduler
c906108c
SS
4064Set the scheduler locking mode. If it is @code{off}, then there is no
4065locking and any thread may run at any time. If @code{on}, then only the
4066current thread may run when the inferior is resumed. The @code{step}
4067mode optimizes for single-stepping. It stops other threads from
4068``seizing the prompt'' by preempting the current thread while you are
4069stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 4070when you step. They are more likely to run when you @samp{next} over a
c906108c 4071function call, and they are completely free to run when you use commands
d4f3574e 4072like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 4073thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 4074@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
4075
4076@item show scheduler-locking
4077Display the current scheduler locking mode.
4078@end table
4079
c906108c 4080
6d2ebf8b 4081@node Stack
c906108c
SS
4082@chapter Examining the Stack
4083
4084When your program has stopped, the first thing you need to know is where it
4085stopped and how it got there.
4086
4087@cindex call stack
5d161b24
DB
4088Each time your program performs a function call, information about the call
4089is generated.
4090That information includes the location of the call in your program,
4091the arguments of the call,
c906108c 4092and the local variables of the function being called.
5d161b24 4093The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
4094The stack frames are allocated in a region of memory called the @dfn{call
4095stack}.
4096
4097When your program stops, the @value{GDBN} commands for examining the
4098stack allow you to see all of this information.
4099
4100@cindex selected frame
4101One of the stack frames is @dfn{selected} by @value{GDBN} and many
4102@value{GDBN} commands refer implicitly to the selected frame. In
4103particular, whenever you ask @value{GDBN} for the value of a variable in
4104your program, the value is found in the selected frame. There are
4105special @value{GDBN} commands to select whichever frame you are
4106interested in. @xref{Selection, ,Selecting a frame}.
4107
4108When your program stops, @value{GDBN} automatically selects the
5d161b24 4109currently executing frame and describes it briefly, similar to the
c906108c
SS
4110@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
4111
4112@menu
4113* Frames:: Stack frames
4114* Backtrace:: Backtraces
4115* Selection:: Selecting a frame
4116* Frame Info:: Information on a frame
c906108c
SS
4117
4118@end menu
4119
6d2ebf8b 4120@node Frames
c906108c
SS
4121@section Stack frames
4122
d4f3574e 4123@cindex frame, definition
c906108c
SS
4124@cindex stack frame
4125The call stack is divided up into contiguous pieces called @dfn{stack
4126frames}, or @dfn{frames} for short; each frame is the data associated
4127with one call to one function. The frame contains the arguments given
4128to the function, the function's local variables, and the address at
4129which the function is executing.
4130
4131@cindex initial frame
4132@cindex outermost frame
4133@cindex innermost frame
4134When your program is started, the stack has only one frame, that of the
4135function @code{main}. This is called the @dfn{initial} frame or the
4136@dfn{outermost} frame. Each time a function is called, a new frame is
4137made. Each time a function returns, the frame for that function invocation
4138is eliminated. If a function is recursive, there can be many frames for
4139the same function. The frame for the function in which execution is
4140actually occurring is called the @dfn{innermost} frame. This is the most
4141recently created of all the stack frames that still exist.
4142
4143@cindex frame pointer
4144Inside your program, stack frames are identified by their addresses. A
4145stack frame consists of many bytes, each of which has its own address; each
4146kind of computer has a convention for choosing one byte whose
4147address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
4148in a register called the @dfn{frame pointer register}
4149(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
4150
4151@cindex frame number
4152@value{GDBN} assigns numbers to all existing stack frames, starting with
4153zero for the innermost frame, one for the frame that called it,
4154and so on upward. These numbers do not really exist in your program;
4155they are assigned by @value{GDBN} to give you a way of designating stack
4156frames in @value{GDBN} commands.
4157
6d2ebf8b
SS
4158@c The -fomit-frame-pointer below perennially causes hbox overflow
4159@c underflow problems.
c906108c
SS
4160@cindex frameless execution
4161Some compilers provide a way to compile functions so that they operate
6d2ebf8b 4162without stack frames. (For example, the @value{GCC} option
474c8240 4163@smallexample
6d2ebf8b 4164@samp{-fomit-frame-pointer}
474c8240 4165@end smallexample
6d2ebf8b 4166generates functions without a frame.)
c906108c
SS
4167This is occasionally done with heavily used library functions to save
4168the frame setup time. @value{GDBN} has limited facilities for dealing
4169with these function invocations. If the innermost function invocation
4170has no stack frame, @value{GDBN} nevertheless regards it as though
4171it had a separate frame, which is numbered zero as usual, allowing
4172correct tracing of the function call chain. However, @value{GDBN} has
4173no provision for frameless functions elsewhere in the stack.
4174
4175@table @code
d4f3574e 4176@kindex frame@r{, command}
41afff9a 4177@cindex current stack frame
c906108c 4178@item frame @var{args}
5d161b24 4179The @code{frame} command allows you to move from one stack frame to another,
c906108c 4180and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4181address of the frame or the stack frame number. Without an argument,
4182@code{frame} prints the current stack frame.
c906108c
SS
4183
4184@kindex select-frame
41afff9a 4185@cindex selecting frame silently
c906108c
SS
4186@item select-frame
4187The @code{select-frame} command allows you to move from one stack frame
4188to another without printing the frame. This is the silent version of
4189@code{frame}.
4190@end table
4191
6d2ebf8b 4192@node Backtrace
c906108c
SS
4193@section Backtraces
4194
09d4efe1
EZ
4195@cindex traceback
4196@cindex call stack traces
c906108c
SS
4197A backtrace is a summary of how your program got where it is. It shows one
4198line per frame, for many frames, starting with the currently executing
4199frame (frame zero), followed by its caller (frame one), and on up the
4200stack.
4201
4202@table @code
4203@kindex backtrace
41afff9a 4204@kindex bt @r{(@code{backtrace})}
c906108c
SS
4205@item backtrace
4206@itemx bt
4207Print a backtrace of the entire stack: one line per frame for all
4208frames in the stack.
4209
4210You can stop the backtrace at any time by typing the system interrupt
4211character, normally @kbd{C-c}.
4212
4213@item backtrace @var{n}
4214@itemx bt @var{n}
4215Similar, but print only the innermost @var{n} frames.
4216
4217@item backtrace -@var{n}
4218@itemx bt -@var{n}
4219Similar, but print only the outermost @var{n} frames.
0f061b69
NR
4220
4221@item backtrace full
4222Print the values of the local variables also.
4223@itemx bt full
c906108c
SS
4224@end table
4225
4226@kindex where
4227@kindex info stack
c906108c
SS
4228The names @code{where} and @code{info stack} (abbreviated @code{info s})
4229are additional aliases for @code{backtrace}.
4230
4231Each line in the backtrace shows the frame number and the function name.
4232The program counter value is also shown---unless you use @code{set
4233print address off}. The backtrace also shows the source file name and
4234line number, as well as the arguments to the function. The program
4235counter value is omitted if it is at the beginning of the code for that
4236line number.
4237
4238Here is an example of a backtrace. It was made with the command
4239@samp{bt 3}, so it shows the innermost three frames.
4240
4241@smallexample
4242@group
5d161b24 4243#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4244 at builtin.c:993
4245#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4246#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4247 at macro.c:71
4248(More stack frames follow...)
4249@end group
4250@end smallexample
4251
4252@noindent
4253The display for frame zero does not begin with a program counter
4254value, indicating that your program has stopped at the beginning of the
4255code for line @code{993} of @code{builtin.c}.
4256
18999be5
EZ
4257@cindex value optimized out, in backtrace
4258@cindex function call arguments, optimized out
4259If your program was compiled with optimizations, some compilers will
4260optimize away arguments passed to functions if those arguments are
4261never used after the call. Such optimizations generate code that
4262passes arguments through registers, but doesn't store those arguments
4263in the stack frame. @value{GDBN} has no way of displaying such
4264arguments in stack frames other than the innermost one. Here's what
4265such a backtrace might look like:
4266
4267@smallexample
4268@group
4269#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4270 at builtin.c:993
4271#1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
4272#2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
4273 at macro.c:71
4274(More stack frames follow...)
4275@end group
4276@end smallexample
4277
4278@noindent
4279The values of arguments that were not saved in their stack frames are
4280shown as @samp{<value optimized out>}.
4281
4282If you need to display the values of such optimized-out arguments,
4283either deduce that from other variables whose values depend on the one
4284you are interested in, or recompile without optimizations.
4285
a8f24a35
EZ
4286@cindex backtrace beyond @code{main} function
4287@cindex program entry point
4288@cindex startup code, and backtrace
25d29d70
AC
4289Most programs have a standard user entry point---a place where system
4290libraries and startup code transition into user code. For C this is
d416eeec
EZ
4291@code{main}@footnote{
4292Note that embedded programs (the so-called ``free-standing''
4293environment) are not required to have a @code{main} function as the
4294entry point. They could even have multiple entry points.}.
4295When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
4296it will terminate the backtrace, to avoid tracing into highly
4297system-specific (and generally uninteresting) code.
4298
4299If you need to examine the startup code, or limit the number of levels
4300in a backtrace, you can change this behavior:
95f90d25
DJ
4301
4302@table @code
25d29d70
AC
4303@item set backtrace past-main
4304@itemx set backtrace past-main on
4644b6e3 4305@kindex set backtrace
25d29d70
AC
4306Backtraces will continue past the user entry point.
4307
4308@item set backtrace past-main off
95f90d25
DJ
4309Backtraces will stop when they encounter the user entry point. This is the
4310default.
4311
25d29d70 4312@item show backtrace past-main
4644b6e3 4313@kindex show backtrace
25d29d70
AC
4314Display the current user entry point backtrace policy.
4315
2315ffec
RC
4316@item set backtrace past-entry
4317@itemx set backtrace past-entry on
a8f24a35 4318Backtraces will continue past the internal entry point of an application.
2315ffec
RC
4319This entry point is encoded by the linker when the application is built,
4320and is likely before the user entry point @code{main} (or equivalent) is called.
4321
4322@item set backtrace past-entry off
4323Backtraces will stop when they encouter the internal entry point of an
4324application. This is the default.
4325
4326@item show backtrace past-entry
4327Display the current internal entry point backtrace policy.
4328
25d29d70
AC
4329@item set backtrace limit @var{n}
4330@itemx set backtrace limit 0
4331@cindex backtrace limit
4332Limit the backtrace to @var{n} levels. A value of zero means
4333unlimited.
95f90d25 4334
25d29d70
AC
4335@item show backtrace limit
4336Display the current limit on backtrace levels.
95f90d25
DJ
4337@end table
4338
6d2ebf8b 4339@node Selection
c906108c
SS
4340@section Selecting a frame
4341
4342Most commands for examining the stack and other data in your program work on
4343whichever stack frame is selected at the moment. Here are the commands for
4344selecting a stack frame; all of them finish by printing a brief description
4345of the stack frame just selected.
4346
4347@table @code
d4f3574e 4348@kindex frame@r{, selecting}
41afff9a 4349@kindex f @r{(@code{frame})}
c906108c
SS
4350@item frame @var{n}
4351@itemx f @var{n}
4352Select frame number @var{n}. Recall that frame zero is the innermost
4353(currently executing) frame, frame one is the frame that called the
4354innermost one, and so on. The highest-numbered frame is the one for
4355@code{main}.
4356
4357@item frame @var{addr}
4358@itemx f @var{addr}
4359Select the frame at address @var{addr}. This is useful mainly if the
4360chaining of stack frames has been damaged by a bug, making it
4361impossible for @value{GDBN} to assign numbers properly to all frames. In
4362addition, this can be useful when your program has multiple stacks and
4363switches between them.
4364
c906108c
SS
4365On the SPARC architecture, @code{frame} needs two addresses to
4366select an arbitrary frame: a frame pointer and a stack pointer.
4367
4368On the MIPS and Alpha architecture, it needs two addresses: a stack
4369pointer and a program counter.
4370
4371On the 29k architecture, it needs three addresses: a register stack
4372pointer, a program counter, and a memory stack pointer.
c906108c
SS
4373
4374@kindex up
4375@item up @var{n}
4376Move @var{n} frames up the stack. For positive numbers @var{n}, this
4377advances toward the outermost frame, to higher frame numbers, to frames
4378that have existed longer. @var{n} defaults to one.
4379
4380@kindex down
41afff9a 4381@kindex do @r{(@code{down})}
c906108c
SS
4382@item down @var{n}
4383Move @var{n} frames down the stack. For positive numbers @var{n}, this
4384advances toward the innermost frame, to lower frame numbers, to frames
4385that were created more recently. @var{n} defaults to one. You may
4386abbreviate @code{down} as @code{do}.
4387@end table
4388
4389All of these commands end by printing two lines of output describing the
4390frame. The first line shows the frame number, the function name, the
4391arguments, and the source file and line number of execution in that
5d161b24 4392frame. The second line shows the text of that source line.
c906108c
SS
4393
4394@need 1000
4395For example:
4396
4397@smallexample
4398@group
4399(@value{GDBP}) up
4400#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4401 at env.c:10
440210 read_input_file (argv[i]);
4403@end group
4404@end smallexample
4405
4406After such a printout, the @code{list} command with no arguments
4407prints ten lines centered on the point of execution in the frame.
87885426
FN
4408You can also edit the program at the point of execution with your favorite
4409editing program by typing @code{edit}.
4410@xref{List, ,Printing source lines},
4411for details.
c906108c
SS
4412
4413@table @code
4414@kindex down-silently
4415@kindex up-silently
4416@item up-silently @var{n}
4417@itemx down-silently @var{n}
4418These two commands are variants of @code{up} and @code{down},
4419respectively; they differ in that they do their work silently, without
4420causing display of the new frame. They are intended primarily for use
4421in @value{GDBN} command scripts, where the output might be unnecessary and
4422distracting.
4423@end table
4424
6d2ebf8b 4425@node Frame Info
c906108c
SS
4426@section Information about a frame
4427
4428There are several other commands to print information about the selected
4429stack frame.
4430
4431@table @code
4432@item frame
4433@itemx f
4434When used without any argument, this command does not change which
4435frame is selected, but prints a brief description of the currently
4436selected stack frame. It can be abbreviated @code{f}. With an
4437argument, this command is used to select a stack frame.
4438@xref{Selection, ,Selecting a frame}.
4439
4440@kindex info frame
41afff9a 4441@kindex info f @r{(@code{info frame})}
c906108c
SS
4442@item info frame
4443@itemx info f
4444This command prints a verbose description of the selected stack frame,
4445including:
4446
4447@itemize @bullet
5d161b24
DB
4448@item
4449the address of the frame
c906108c
SS
4450@item
4451the address of the next frame down (called by this frame)
4452@item
4453the address of the next frame up (caller of this frame)
4454@item
4455the language in which the source code corresponding to this frame is written
4456@item
4457the address of the frame's arguments
4458@item
d4f3574e
SS
4459the address of the frame's local variables
4460@item
c906108c
SS
4461the program counter saved in it (the address of execution in the caller frame)
4462@item
4463which registers were saved in the frame
4464@end itemize
4465
4466@noindent The verbose description is useful when
4467something has gone wrong that has made the stack format fail to fit
4468the usual conventions.
4469
4470@item info frame @var{addr}
4471@itemx info f @var{addr}
4472Print a verbose description of the frame at address @var{addr}, without
4473selecting that frame. The selected frame remains unchanged by this
4474command. This requires the same kind of address (more than one for some
4475architectures) that you specify in the @code{frame} command.
4476@xref{Selection, ,Selecting a frame}.
4477
4478@kindex info args
4479@item info args
4480Print the arguments of the selected frame, each on a separate line.
4481
4482@item info locals
4483@kindex info locals
4484Print the local variables of the selected frame, each on a separate
4485line. These are all variables (declared either static or automatic)
4486accessible at the point of execution of the selected frame.
4487
c906108c 4488@kindex info catch
d4f3574e
SS
4489@cindex catch exceptions, list active handlers
4490@cindex exception handlers, how to list
c906108c
SS
4491@item info catch
4492Print a list of all the exception handlers that are active in the
4493current stack frame at the current point of execution. To see other
4494exception handlers, visit the associated frame (using the @code{up},
4495@code{down}, or @code{frame} commands); then type @code{info catch}.
4496@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4497
c906108c
SS
4498@end table
4499
c906108c 4500
6d2ebf8b 4501@node Source
c906108c
SS
4502@chapter Examining Source Files
4503
4504@value{GDBN} can print parts of your program's source, since the debugging
4505information recorded in the program tells @value{GDBN} what source files were
4506used to build it. When your program stops, @value{GDBN} spontaneously prints
4507the line where it stopped. Likewise, when you select a stack frame
4508(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4509execution in that frame has stopped. You can print other portions of
4510source files by explicit command.
4511
7a292a7a 4512If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4513prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4514@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4515
4516@menu
4517* List:: Printing source lines
87885426 4518* Edit:: Editing source files
c906108c 4519* Search:: Searching source files
c906108c
SS
4520* Source Path:: Specifying source directories
4521* Machine Code:: Source and machine code
4522@end menu
4523
6d2ebf8b 4524@node List
c906108c
SS
4525@section Printing source lines
4526
4527@kindex list
41afff9a 4528@kindex l @r{(@code{list})}
c906108c 4529To print lines from a source file, use the @code{list} command
5d161b24 4530(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4531There are several ways to specify what part of the file you want to print.
4532
4533Here are the forms of the @code{list} command most commonly used:
4534
4535@table @code
4536@item list @var{linenum}
4537Print lines centered around line number @var{linenum} in the
4538current source file.
4539
4540@item list @var{function}
4541Print lines centered around the beginning of function
4542@var{function}.
4543
4544@item list
4545Print more lines. If the last lines printed were printed with a
4546@code{list} command, this prints lines following the last lines
4547printed; however, if the last line printed was a solitary line printed
4548as part of displaying a stack frame (@pxref{Stack, ,Examining the
4549Stack}), this prints lines centered around that line.
4550
4551@item list -
4552Print lines just before the lines last printed.
4553@end table
4554
9c16f35a 4555@cindex @code{list}, how many lines to display
c906108c
SS
4556By default, @value{GDBN} prints ten source lines with any of these forms of
4557the @code{list} command. You can change this using @code{set listsize}:
4558
4559@table @code
4560@kindex set listsize
4561@item set listsize @var{count}
4562Make the @code{list} command display @var{count} source lines (unless
4563the @code{list} argument explicitly specifies some other number).
4564
4565@kindex show listsize
4566@item show listsize
4567Display the number of lines that @code{list} prints.
4568@end table
4569
4570Repeating a @code{list} command with @key{RET} discards the argument,
4571so it is equivalent to typing just @code{list}. This is more useful
4572than listing the same lines again. An exception is made for an
4573argument of @samp{-}; that argument is preserved in repetition so that
4574each repetition moves up in the source file.
4575
4576@cindex linespec
4577In general, the @code{list} command expects you to supply zero, one or two
4578@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4579of writing them, but the effect is always to specify some source line.
c906108c
SS
4580Here is a complete description of the possible arguments for @code{list}:
4581
4582@table @code
4583@item list @var{linespec}
4584Print lines centered around the line specified by @var{linespec}.
4585
4586@item list @var{first},@var{last}
4587Print lines from @var{first} to @var{last}. Both arguments are
4588linespecs.
4589
4590@item list ,@var{last}
4591Print lines ending with @var{last}.
4592
4593@item list @var{first},
4594Print lines starting with @var{first}.
4595
4596@item list +
4597Print lines just after the lines last printed.
4598
4599@item list -
4600Print lines just before the lines last printed.
4601
4602@item list
4603As described in the preceding table.
4604@end table
4605
4606Here are the ways of specifying a single source line---all the
4607kinds of linespec.
4608
4609@table @code
4610@item @var{number}
4611Specifies line @var{number} of the current source file.
4612When a @code{list} command has two linespecs, this refers to
4613the same source file as the first linespec.
4614
4615@item +@var{offset}
4616Specifies the line @var{offset} lines after the last line printed.
4617When used as the second linespec in a @code{list} command that has
4618two, this specifies the line @var{offset} lines down from the
4619first linespec.
4620
4621@item -@var{offset}
4622Specifies the line @var{offset} lines before the last line printed.
4623
4624@item @var{filename}:@var{number}
4625Specifies line @var{number} in the source file @var{filename}.
4626
4627@item @var{function}
4628Specifies the line that begins the body of the function @var{function}.
4629For example: in C, this is the line with the open brace.
4630
4631@item @var{filename}:@var{function}
4632Specifies the line of the open-brace that begins the body of the
4633function @var{function} in the file @var{filename}. You only need the
4634file name with a function name to avoid ambiguity when there are
4635identically named functions in different source files.
4636
4637@item *@var{address}
4638Specifies the line containing the program address @var{address}.
4639@var{address} may be any expression.
4640@end table
4641
87885426
FN
4642@node Edit
4643@section Editing source files
4644@cindex editing source files
4645
4646@kindex edit
4647@kindex e @r{(@code{edit})}
4648To edit the lines in a source file, use the @code{edit} command.
4649The editing program of your choice
4650is invoked with the current line set to
4651the active line in the program.
4652Alternatively, there are several ways to specify what part of the file you
4653want to print if you want to see other parts of the program.
4654
4655Here are the forms of the @code{edit} command most commonly used:
4656
4657@table @code
4658@item edit
4659Edit the current source file at the active line number in the program.
4660
4661@item edit @var{number}
4662Edit the current source file with @var{number} as the active line number.
4663
4664@item edit @var{function}
4665Edit the file containing @var{function} at the beginning of its definition.
4666
4667@item edit @var{filename}:@var{number}
4668Specifies line @var{number} in the source file @var{filename}.
4669
4670@item edit @var{filename}:@var{function}
4671Specifies the line that begins the body of the
4672function @var{function} in the file @var{filename}. You only need the
4673file name with a function name to avoid ambiguity when there are
4674identically named functions in different source files.
4675
4676@item edit *@var{address}
4677Specifies the line containing the program address @var{address}.
4678@var{address} may be any expression.
4679@end table
4680
4681@subsection Choosing your editor
4682You can customize @value{GDBN} to use any editor you want
4683@footnote{
4684The only restriction is that your editor (say @code{ex}), recognizes the
4685following command-line syntax:
10998722 4686@smallexample
87885426 4687ex +@var{number} file
10998722 4688@end smallexample
15387254
EZ
4689The optional numeric value +@var{number} specifies the number of the line in
4690the file where to start editing.}.
4691By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4692by setting the environment variable @code{EDITOR} before using
4693@value{GDBN}. For example, to configure @value{GDBN} to use the
4694@code{vi} editor, you could use these commands with the @code{sh} shell:
4695@smallexample
87885426
FN
4696EDITOR=/usr/bin/vi
4697export EDITOR
15387254 4698gdb @dots{}
10998722 4699@end smallexample
87885426 4700or in the @code{csh} shell,
10998722 4701@smallexample
87885426 4702setenv EDITOR /usr/bin/vi
15387254 4703gdb @dots{}
10998722 4704@end smallexample
87885426 4705
6d2ebf8b 4706@node Search
c906108c 4707@section Searching source files
15387254 4708@cindex searching source files
c906108c
SS
4709
4710There are two commands for searching through the current source file for a
4711regular expression.
4712
4713@table @code
4714@kindex search
4715@kindex forward-search
4716@item forward-search @var{regexp}
4717@itemx search @var{regexp}
4718The command @samp{forward-search @var{regexp}} checks each line,
4719starting with the one following the last line listed, for a match for
5d161b24 4720@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4721synonym @samp{search @var{regexp}} or abbreviate the command name as
4722@code{fo}.
4723
09d4efe1 4724@kindex reverse-search
c906108c
SS
4725@item reverse-search @var{regexp}
4726The command @samp{reverse-search @var{regexp}} checks each line, starting
4727with the one before the last line listed and going backward, for a match
4728for @var{regexp}. It lists the line that is found. You can abbreviate
4729this command as @code{rev}.
4730@end table
c906108c 4731
6d2ebf8b 4732@node Source Path
c906108c
SS
4733@section Specifying source directories
4734
4735@cindex source path
4736@cindex directories for source files
4737Executable programs sometimes do not record the directories of the source
4738files from which they were compiled, just the names. Even when they do,
4739the directories could be moved between the compilation and your debugging
4740session. @value{GDBN} has a list of directories to search for source files;
4741this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4742it tries all the directories in the list, in the order they are present
0b66e38c
EZ
4743in the list, until it finds a file with the desired name.
4744
4745For example, suppose an executable references the file
4746@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4747@file{/mnt/cross}. The file is first looked up literally; if this
4748fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4749fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4750message is printed. @value{GDBN} does not look up the parts of the
4751source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4752Likewise, the subdirectories of the source path are not searched: if
4753the source path is @file{/mnt/cross}, and the binary refers to
4754@file{foo.c}, @value{GDBN} would not find it under
4755@file{/mnt/cross/usr/src/foo-1.0/lib}.
4756
4757Plain file names, relative file names with leading directories, file
4758names containing dots, etc.@: are all treated as described above; for
4759instance, if the source path is @file{/mnt/cross}, and the source file
4760is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4761@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4762that---@file{/mnt/cross/foo.c}.
4763
4764Note that the executable search path is @emph{not} used to locate the
4765source files. Neither is the current working directory, unless it
4766happens to be in the source path.
c906108c
SS
4767
4768Whenever you reset or rearrange the source path, @value{GDBN} clears out
4769any information it has cached about where source files are found and where
4770each line is in the file.
4771
4772@kindex directory
4773@kindex dir
d4f3574e
SS
4774When you start @value{GDBN}, its source path includes only @samp{cdir}
4775and @samp{cwd}, in that order.
c906108c
SS
4776To add other directories, use the @code{directory} command.
4777
4778@table @code
4779@item directory @var{dirname} @dots{}
4780@item dir @var{dirname} @dots{}
4781Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4782directory names may be given to this command, separated by @samp{:}
4783(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4784part of absolute file names) or
c906108c
SS
4785whitespace. You may specify a directory that is already in the source
4786path; this moves it forward, so @value{GDBN} searches it sooner.
4787
4788@kindex cdir
4789@kindex cwd
41afff9a
EZ
4790@vindex $cdir@r{, convenience variable}
4791@vindex $cwdr@r{, convenience variable}
c906108c
SS
4792@cindex compilation directory
4793@cindex current directory
4794@cindex working directory
4795@cindex directory, current
4796@cindex directory, compilation
4797You can use the string @samp{$cdir} to refer to the compilation
4798directory (if one is recorded), and @samp{$cwd} to refer to the current
4799working directory. @samp{$cwd} is not the same as @samp{.}---the former
4800tracks the current working directory as it changes during your @value{GDBN}
4801session, while the latter is immediately expanded to the current
4802directory at the time you add an entry to the source path.
4803
4804@item directory
4805Reset the source path to empty again. This requires confirmation.
4806
4807@c RET-repeat for @code{directory} is explicitly disabled, but since
4808@c repeating it would be a no-op we do not say that. (thanks to RMS)
4809
4810@item show directories
4811@kindex show directories
4812Print the source path: show which directories it contains.
4813@end table
4814
4815If your source path is cluttered with directories that are no longer of
4816interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4817versions of source. You can correct the situation as follows:
4818
4819@enumerate
4820@item
4821Use @code{directory} with no argument to reset the source path to empty.
4822
4823@item
4824Use @code{directory} with suitable arguments to reinstall the
4825directories you want in the source path. You can add all the
4826directories in one command.
4827@end enumerate
4828
6d2ebf8b 4829@node Machine Code
c906108c 4830@section Source and machine code
15387254 4831@cindex source line and its code address
c906108c
SS
4832
4833You can use the command @code{info line} to map source lines to program
4834addresses (and vice versa), and the command @code{disassemble} to display
4835a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4836mode, the @code{info line} command causes the arrow to point to the
5d161b24 4837line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4838well as hex.
4839
4840@table @code
4841@kindex info line
4842@item info line @var{linespec}
4843Print the starting and ending addresses of the compiled code for
4844source line @var{linespec}. You can specify source lines in any of
4845the ways understood by the @code{list} command (@pxref{List, ,Printing
4846source lines}).
4847@end table
4848
4849For example, we can use @code{info line} to discover the location of
4850the object code for the first line of function
4851@code{m4_changequote}:
4852
d4f3574e
SS
4853@c FIXME: I think this example should also show the addresses in
4854@c symbolic form, as they usually would be displayed.
c906108c 4855@smallexample
96a2c332 4856(@value{GDBP}) info line m4_changequote
c906108c
SS
4857Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4858@end smallexample
4859
4860@noindent
15387254 4861@cindex code address and its source line
c906108c
SS
4862We can also inquire (using @code{*@var{addr}} as the form for
4863@var{linespec}) what source line covers a particular address:
4864@smallexample
4865(@value{GDBP}) info line *0x63ff
4866Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4867@end smallexample
4868
4869@cindex @code{$_} and @code{info line}
15387254 4870@cindex @code{x} command, default address
41afff9a 4871@kindex x@r{(examine), and} info line
c906108c
SS
4872After @code{info line}, the default address for the @code{x} command
4873is changed to the starting address of the line, so that @samp{x/i} is
4874sufficient to begin examining the machine code (@pxref{Memory,
4875,Examining memory}). Also, this address is saved as the value of the
4876convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4877variables}).
4878
4879@table @code
4880@kindex disassemble
4881@cindex assembly instructions
4882@cindex instructions, assembly
4883@cindex machine instructions
4884@cindex listing machine instructions
4885@item disassemble
4886This specialized command dumps a range of memory as machine
4887instructions. The default memory range is the function surrounding the
4888program counter of the selected frame. A single argument to this
4889command is a program counter value; @value{GDBN} dumps the function
4890surrounding this value. Two arguments specify a range of addresses
4891(first inclusive, second exclusive) to dump.
4892@end table
4893
c906108c
SS
4894The following example shows the disassembly of a range of addresses of
4895HP PA-RISC 2.0 code:
4896
4897@smallexample
4898(@value{GDBP}) disas 0x32c4 0x32e4
4899Dump of assembler code from 0x32c4 to 0x32e4:
49000x32c4 <main+204>: addil 0,dp
49010x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
49020x32cc <main+212>: ldil 0x3000,r31
49030x32d0 <main+216>: ble 0x3f8(sr4,r31)
49040x32d4 <main+220>: ldo 0(r31),rp
49050x32d8 <main+224>: addil -0x800,dp
49060x32dc <main+228>: ldo 0x588(r1),r26
49070x32e0 <main+232>: ldil 0x3000,r31
4908End of assembler dump.
4909@end smallexample
c906108c
SS
4910
4911Some architectures have more than one commonly-used set of instruction
4912mnemonics or other syntax.
4913
76d17f34
EZ
4914For programs that were dynamically linked and use shared libraries,
4915instructions that call functions or branch to locations in the shared
4916libraries might show a seemingly bogus location---it's actually a
4917location of the relocation table. On some architectures, @value{GDBN}
4918might be able to resolve these to actual function names.
4919
c906108c 4920@table @code
d4f3574e 4921@kindex set disassembly-flavor
d4f3574e
SS
4922@cindex Intel disassembly flavor
4923@cindex AT&T disassembly flavor
4924@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4925Select the instruction set to use when disassembling the
4926program via the @code{disassemble} or @code{x/i} commands.
4927
4928Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4929can set @var{instruction-set} to either @code{intel} or @code{att}.
4930The default is @code{att}, the AT&T flavor used by default by Unix
4931assemblers for x86-based targets.
9c16f35a
EZ
4932
4933@kindex show disassembly-flavor
4934@item show disassembly-flavor
4935Show the current setting of the disassembly flavor.
c906108c
SS
4936@end table
4937
4938
6d2ebf8b 4939@node Data
c906108c
SS
4940@chapter Examining Data
4941
4942@cindex printing data
4943@cindex examining data
4944@kindex print
4945@kindex inspect
4946@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4947@c document because it is nonstandard... Under Epoch it displays in a
4948@c different window or something like that.
4949The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4950command (abbreviated @code{p}), or its synonym @code{inspect}. It
4951evaluates and prints the value of an expression of the language your
4952program is written in (@pxref{Languages, ,Using @value{GDBN} with
4953Different Languages}).
c906108c
SS
4954
4955@table @code
d4f3574e
SS
4956@item print @var{expr}
4957@itemx print /@var{f} @var{expr}
4958@var{expr} is an expression (in the source language). By default the
4959value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4960you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4961@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4962formats}.
4963
4964@item print
4965@itemx print /@var{f}
15387254 4966@cindex reprint the last value
d4f3574e 4967If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4968@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4969conveniently inspect the same value in an alternative format.
4970@end table
4971
4972A more low-level way of examining data is with the @code{x} command.
4973It examines data in memory at a specified address and prints it in a
4974specified format. @xref{Memory, ,Examining memory}.
4975
7a292a7a 4976If you are interested in information about types, or about how the
d4f3574e
SS
4977fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4978command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4979Table}.
c906108c
SS
4980
4981@menu
4982* Expressions:: Expressions
4983* Variables:: Program variables
4984* Arrays:: Artificial arrays
4985* Output Formats:: Output formats
4986* Memory:: Examining memory
4987* Auto Display:: Automatic display
4988* Print Settings:: Print settings
4989* Value History:: Value history
4990* Convenience Vars:: Convenience variables
4991* Registers:: Registers
c906108c 4992* Floating Point Hardware:: Floating point hardware
53c69bd7 4993* Vector Unit:: Vector Unit
721c2651 4994* OS Information:: Auxiliary data provided by operating system
29e57380 4995* Memory Region Attributes:: Memory region attributes
16d9dec6 4996* Dump/Restore Files:: Copy between memory and a file
384ee23f 4997* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
4998* Character Sets:: Debugging programs that use a different
4999 character set than GDB does
09d4efe1 5000* Caching Remote Data:: Data caching for remote targets
c906108c
SS
5001@end menu
5002
6d2ebf8b 5003@node Expressions
c906108c
SS
5004@section Expressions
5005
5006@cindex expressions
5007@code{print} and many other @value{GDBN} commands accept an expression and
5008compute its value. Any kind of constant, variable or operator defined
5009by the programming language you are using is valid in an expression in
e2e0bcd1
JB
5010@value{GDBN}. This includes conditional expressions, function calls,
5011casts, and string constants. It also includes preprocessor macros, if
5012you compiled your program to include this information; see
5013@ref{Compilation}.
c906108c 5014
15387254 5015@cindex arrays in expressions
d4f3574e
SS
5016@value{GDBN} supports array constants in expressions input by
5017the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 5018you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 5019memory that is @code{malloc}ed in the target program.
c906108c 5020
c906108c
SS
5021Because C is so widespread, most of the expressions shown in examples in
5022this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
5023Languages}, for information on how to use expressions in other
5024languages.
5025
5026In this section, we discuss operators that you can use in @value{GDBN}
5027expressions regardless of your programming language.
5028
15387254 5029@cindex casts, in expressions
c906108c
SS
5030Casts are supported in all languages, not just in C, because it is so
5031useful to cast a number into a pointer in order to examine a structure
5032at that address in memory.
5033@c FIXME: casts supported---Mod2 true?
c906108c
SS
5034
5035@value{GDBN} supports these operators, in addition to those common
5036to programming languages:
5037
5038@table @code
5039@item @@
5040@samp{@@} is a binary operator for treating parts of memory as arrays.
5041@xref{Arrays, ,Artificial arrays}, for more information.
5042
5043@item ::
5044@samp{::} allows you to specify a variable in terms of the file or
5045function where it is defined. @xref{Variables, ,Program variables}.
5046
5047@cindex @{@var{type}@}
5048@cindex type casting memory
5049@cindex memory, viewing as typed object
5050@cindex casts, to view memory
5051@item @{@var{type}@} @var{addr}
5052Refers to an object of type @var{type} stored at address @var{addr} in
5053memory. @var{addr} may be any expression whose value is an integer or
5054pointer (but parentheses are required around binary operators, just as in
5055a cast). This construct is allowed regardless of what kind of data is
5056normally supposed to reside at @var{addr}.
5057@end table
5058
6d2ebf8b 5059@node Variables
c906108c
SS
5060@section Program variables
5061
5062The most common kind of expression to use is the name of a variable
5063in your program.
5064
5065Variables in expressions are understood in the selected stack frame
5066(@pxref{Selection, ,Selecting a frame}); they must be either:
5067
5068@itemize @bullet
5069@item
5070global (or file-static)
5071@end itemize
5072
5d161b24 5073@noindent or
c906108c
SS
5074
5075@itemize @bullet
5076@item
5077visible according to the scope rules of the
5078programming language from the point of execution in that frame
5d161b24 5079@end itemize
c906108c
SS
5080
5081@noindent This means that in the function
5082
474c8240 5083@smallexample
c906108c
SS
5084foo (a)
5085 int a;
5086@{
5087 bar (a);
5088 @{
5089 int b = test ();
5090 bar (b);
5091 @}
5092@}
474c8240 5093@end smallexample
c906108c
SS
5094
5095@noindent
5096you can examine and use the variable @code{a} whenever your program is
5097executing within the function @code{foo}, but you can only use or
5098examine the variable @code{b} while your program is executing inside
5099the block where @code{b} is declared.
5100
5101@cindex variable name conflict
5102There is an exception: you can refer to a variable or function whose
5103scope is a single source file even if the current execution point is not
5104in this file. But it is possible to have more than one such variable or
5105function with the same name (in different source files). If that
5106happens, referring to that name has unpredictable effects. If you wish,
5107you can specify a static variable in a particular function or file,
15387254 5108using the colon-colon (@code{::}) notation:
c906108c 5109
d4f3574e 5110@cindex colon-colon, context for variables/functions
c906108c
SS
5111@iftex
5112@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 5113@cindex @code{::}, context for variables/functions
c906108c 5114@end iftex
474c8240 5115@smallexample
c906108c
SS
5116@var{file}::@var{variable}
5117@var{function}::@var{variable}
474c8240 5118@end smallexample
c906108c
SS
5119
5120@noindent
5121Here @var{file} or @var{function} is the name of the context for the
5122static @var{variable}. In the case of file names, you can use quotes to
5123make sure @value{GDBN} parses the file name as a single word---for example,
5124to print a global value of @code{x} defined in @file{f2.c}:
5125
474c8240 5126@smallexample
c906108c 5127(@value{GDBP}) p 'f2.c'::x
474c8240 5128@end smallexample
c906108c 5129
b37052ae 5130@cindex C@t{++} scope resolution
c906108c 5131This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 5132use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
5133scope resolution operator in @value{GDBN} expressions.
5134@c FIXME: Um, so what happens in one of those rare cases where it's in
5135@c conflict?? --mew
c906108c
SS
5136
5137@cindex wrong values
5138@cindex variable values, wrong
15387254
EZ
5139@cindex function entry/exit, wrong values of variables
5140@cindex optimized code, wrong values of variables
c906108c
SS
5141@quotation
5142@emph{Warning:} Occasionally, a local variable may appear to have the
5143wrong value at certain points in a function---just after entry to a new
5144scope, and just before exit.
5145@end quotation
5146You may see this problem when you are stepping by machine instructions.
5147This is because, on most machines, it takes more than one instruction to
5148set up a stack frame (including local variable definitions); if you are
5149stepping by machine instructions, variables may appear to have the wrong
5150values until the stack frame is completely built. On exit, it usually
5151also takes more than one machine instruction to destroy a stack frame;
5152after you begin stepping through that group of instructions, local
5153variable definitions may be gone.
5154
5155This may also happen when the compiler does significant optimizations.
5156To be sure of always seeing accurate values, turn off all optimization
5157when compiling.
5158
d4f3574e
SS
5159@cindex ``No symbol "foo" in current context''
5160Another possible effect of compiler optimizations is to optimize
5161unused variables out of existence, or assign variables to registers (as
5162opposed to memory addresses). Depending on the support for such cases
5163offered by the debug info format used by the compiler, @value{GDBN}
5164might not be able to display values for such local variables. If that
5165happens, @value{GDBN} will print a message like this:
5166
474c8240 5167@smallexample
d4f3574e 5168No symbol "foo" in current context.
474c8240 5169@end smallexample
d4f3574e
SS
5170
5171To solve such problems, either recompile without optimizations, or use a
5172different debug info format, if the compiler supports several such
15387254 5173formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
5174usually supports the @option{-gstabs+} option. @option{-gstabs+}
5175produces debug info in a format that is superior to formats such as
5176COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5177an effective form for debug info. @xref{Debugging Options,,Options
5178for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
5179@xref{C, , Debugging C++}, for more info about debug info formats
5180that are best suited to C@t{++} programs.
d4f3574e 5181
ab1adacd
EZ
5182If you ask to print an object whose contents are unknown to
5183@value{GDBN}, e.g., because its data type is not completely specified
5184by the debug information, @value{GDBN} will say @samp{<incomplete
5185type>}. @xref{Symbols, incomplete type}, for more about this.
5186
6d2ebf8b 5187@node Arrays
c906108c
SS
5188@section Artificial arrays
5189
5190@cindex artificial array
15387254 5191@cindex arrays
41afff9a 5192@kindex @@@r{, referencing memory as an array}
c906108c
SS
5193It is often useful to print out several successive objects of the
5194same type in memory; a section of an array, or an array of
5195dynamically determined size for which only a pointer exists in the
5196program.
5197
5198You can do this by referring to a contiguous span of memory as an
5199@dfn{artificial array}, using the binary operator @samp{@@}. The left
5200operand of @samp{@@} should be the first element of the desired array
5201and be an individual object. The right operand should be the desired length
5202of the array. The result is an array value whose elements are all of
5203the type of the left argument. The first element is actually the left
5204argument; the second element comes from bytes of memory immediately
5205following those that hold the first element, and so on. Here is an
5206example. If a program says
5207
474c8240 5208@smallexample
c906108c 5209int *array = (int *) malloc (len * sizeof (int));
474c8240 5210@end smallexample
c906108c
SS
5211
5212@noindent
5213you can print the contents of @code{array} with
5214
474c8240 5215@smallexample
c906108c 5216p *array@@len
474c8240 5217@end smallexample
c906108c
SS
5218
5219The left operand of @samp{@@} must reside in memory. Array values made
5220with @samp{@@} in this way behave just like other arrays in terms of
5221subscripting, and are coerced to pointers when used in expressions.
5222Artificial arrays most often appear in expressions via the value history
5223(@pxref{Value History, ,Value history}), after printing one out.
5224
5225Another way to create an artificial array is to use a cast.
5226This re-interprets a value as if it were an array.
5227The value need not be in memory:
474c8240 5228@smallexample
c906108c
SS
5229(@value{GDBP}) p/x (short[2])0x12345678
5230$1 = @{0x1234, 0x5678@}
474c8240 5231@end smallexample
c906108c
SS
5232
5233As a convenience, if you leave the array length out (as in
c3f6f71d 5234@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5235the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5236@smallexample
c906108c
SS
5237(@value{GDBP}) p/x (short[])0x12345678
5238$2 = @{0x1234, 0x5678@}
474c8240 5239@end smallexample
c906108c
SS
5240
5241Sometimes the artificial array mechanism is not quite enough; in
5242moderately complex data structures, the elements of interest may not
5243actually be adjacent---for example, if you are interested in the values
5244of pointers in an array. One useful work-around in this situation is
5245to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5246variables}) as a counter in an expression that prints the first
5247interesting value, and then repeat that expression via @key{RET}. For
5248instance, suppose you have an array @code{dtab} of pointers to
5249structures, and you are interested in the values of a field @code{fv}
5250in each structure. Here is an example of what you might type:
5251
474c8240 5252@smallexample
c906108c
SS
5253set $i = 0
5254p dtab[$i++]->fv
5255@key{RET}
5256@key{RET}
5257@dots{}
474c8240 5258@end smallexample
c906108c 5259
6d2ebf8b 5260@node Output Formats
c906108c
SS
5261@section Output formats
5262
5263@cindex formatted output
5264@cindex output formats
5265By default, @value{GDBN} prints a value according to its data type. Sometimes
5266this is not what you want. For example, you might want to print a number
5267in hex, or a pointer in decimal. Or you might want to view data in memory
5268at a certain address as a character string or as an instruction. To do
5269these things, specify an @dfn{output format} when you print a value.
5270
5271The simplest use of output formats is to say how to print a value
5272already computed. This is done by starting the arguments of the
5273@code{print} command with a slash and a format letter. The format
5274letters supported are:
5275
5276@table @code
5277@item x
5278Regard the bits of the value as an integer, and print the integer in
5279hexadecimal.
5280
5281@item d
5282Print as integer in signed decimal.
5283
5284@item u
5285Print as integer in unsigned decimal.
5286
5287@item o
5288Print as integer in octal.
5289
5290@item t
5291Print as integer in binary. The letter @samp{t} stands for ``two''.
5292@footnote{@samp{b} cannot be used because these format letters are also
5293used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5294see @ref{Memory,,Examining memory}.}
c906108c
SS
5295
5296@item a
5297@cindex unknown address, locating
3d67e040 5298@cindex locate address
c906108c
SS
5299Print as an address, both absolute in hexadecimal and as an offset from
5300the nearest preceding symbol. You can use this format used to discover
5301where (in what function) an unknown address is located:
5302
474c8240 5303@smallexample
c906108c
SS
5304(@value{GDBP}) p/a 0x54320
5305$3 = 0x54320 <_initialize_vx+396>
474c8240 5306@end smallexample
c906108c 5307
3d67e040
EZ
5308@noindent
5309The command @code{info symbol 0x54320} yields similar results.
5310@xref{Symbols, info symbol}.
5311
c906108c 5312@item c
51274035
EZ
5313Regard as an integer and print it as a character constant. This
5314prints both the numerical value and its character representation. The
5315character representation is replaced with the octal escape @samp{\nnn}
5316for characters outside the 7-bit @sc{ascii} range.
c906108c
SS
5317
5318@item f
5319Regard the bits of the value as a floating point number and print
5320using typical floating point syntax.
5321@end table
5322
5323For example, to print the program counter in hex (@pxref{Registers}), type
5324
474c8240 5325@smallexample
c906108c 5326p/x $pc
474c8240 5327@end smallexample
c906108c
SS
5328
5329@noindent
5330Note that no space is required before the slash; this is because command
5331names in @value{GDBN} cannot contain a slash.
5332
5333To reprint the last value in the value history with a different format,
5334you can use the @code{print} command with just a format and no
5335expression. For example, @samp{p/x} reprints the last value in hex.
5336
6d2ebf8b 5337@node Memory
c906108c
SS
5338@section Examining memory
5339
5340You can use the command @code{x} (for ``examine'') to examine memory in
5341any of several formats, independently of your program's data types.
5342
5343@cindex examining memory
5344@table @code
41afff9a 5345@kindex x @r{(examine memory)}
c906108c
SS
5346@item x/@var{nfu} @var{addr}
5347@itemx x @var{addr}
5348@itemx x
5349Use the @code{x} command to examine memory.
5350@end table
5351
5352@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5353much memory to display and how to format it; @var{addr} is an
5354expression giving the address where you want to start displaying memory.
5355If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5356Several commands set convenient defaults for @var{addr}.
5357
5358@table @r
5359@item @var{n}, the repeat count
5360The repeat count is a decimal integer; the default is 1. It specifies
5361how much memory (counting by units @var{u}) to display.
5362@c This really is **decimal**; unaffected by 'set radix' as of GDB
5363@c 4.1.2.
5364
5365@item @var{f}, the display format
51274035
EZ
5366The display format is one of the formats used by @code{print}
5367(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
5368@samp{f}), and in addition @samp{s} (for null-terminated strings) and
5369@samp{i} (for machine instructions). The default is @samp{x}
5370(hexadecimal) initially. The default changes each time you use either
5371@code{x} or @code{print}.
c906108c
SS
5372
5373@item @var{u}, the unit size
5374The unit size is any of
5375
5376@table @code
5377@item b
5378Bytes.
5379@item h
5380Halfwords (two bytes).
5381@item w
5382Words (four bytes). This is the initial default.
5383@item g
5384Giant words (eight bytes).
5385@end table
5386
5387Each time you specify a unit size with @code{x}, that size becomes the
5388default unit the next time you use @code{x}. (For the @samp{s} and
5389@samp{i} formats, the unit size is ignored and is normally not written.)
5390
5391@item @var{addr}, starting display address
5392@var{addr} is the address where you want @value{GDBN} to begin displaying
5393memory. The expression need not have a pointer value (though it may);
5394it is always interpreted as an integer address of a byte of memory.
5395@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5396@var{addr} is usually just after the last address examined---but several
5397other commands also set the default address: @code{info breakpoints} (to
5398the address of the last breakpoint listed), @code{info line} (to the
5399starting address of a line), and @code{print} (if you use it to display
5400a value from memory).
5401@end table
5402
5403For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5404(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5405starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5406words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5407@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5408
5409Since the letters indicating unit sizes are all distinct from the
5410letters specifying output formats, you do not have to remember whether
5411unit size or format comes first; either order works. The output
5412specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5413(However, the count @var{n} must come first; @samp{wx4} does not work.)
5414
5415Even though the unit size @var{u} is ignored for the formats @samp{s}
5416and @samp{i}, you might still want to use a count @var{n}; for example,
5417@samp{3i} specifies that you want to see three machine instructions,
5418including any operands. The command @code{disassemble} gives an
d4f3574e 5419alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5420Code,,Source and machine code}.
5421
5422All the defaults for the arguments to @code{x} are designed to make it
5423easy to continue scanning memory with minimal specifications each time
5424you use @code{x}. For example, after you have inspected three machine
5425instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5426with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5427the repeat count @var{n} is used again; the other arguments default as
5428for successive uses of @code{x}.
5429
5430@cindex @code{$_}, @code{$__}, and value history
5431The addresses and contents printed by the @code{x} command are not saved
5432in the value history because there is often too much of them and they
5433would get in the way. Instead, @value{GDBN} makes these values available for
5434subsequent use in expressions as values of the convenience variables
5435@code{$_} and @code{$__}. After an @code{x} command, the last address
5436examined is available for use in expressions in the convenience variable
5437@code{$_}. The contents of that address, as examined, are available in
5438the convenience variable @code{$__}.
5439
5440If the @code{x} command has a repeat count, the address and contents saved
5441are from the last memory unit printed; this is not the same as the last
5442address printed if several units were printed on the last line of output.
5443
09d4efe1
EZ
5444@cindex remote memory comparison
5445@cindex verify remote memory image
5446When you are debugging a program running on a remote target machine
5447(@pxref{Remote}), you may wish to verify the program's image in the
5448remote machine's memory against the executable file you downloaded to
5449the target. The @code{compare-sections} command is provided for such
5450situations.
5451
5452@table @code
5453@kindex compare-sections
5454@item compare-sections @r{[}@var{section-name}@r{]}
5455Compare the data of a loadable section @var{section-name} in the
5456executable file of the program being debugged with the same section in
5457the remote machine's memory, and report any mismatches. With no
5458arguments, compares all loadable sections. This command's
5459availability depends on the target's support for the @code{"qCRC"}
5460remote request.
5461@end table
5462
6d2ebf8b 5463@node Auto Display
c906108c
SS
5464@section Automatic display
5465@cindex automatic display
5466@cindex display of expressions
5467
5468If you find that you want to print the value of an expression frequently
5469(to see how it changes), you might want to add it to the @dfn{automatic
5470display list} so that @value{GDBN} prints its value each time your program stops.
5471Each expression added to the list is given a number to identify it;
5472to remove an expression from the list, you specify that number.
5473The automatic display looks like this:
5474
474c8240 5475@smallexample
c906108c
SS
54762: foo = 38
54773: bar[5] = (struct hack *) 0x3804
474c8240 5478@end smallexample
c906108c
SS
5479
5480@noindent
5481This display shows item numbers, expressions and their current values. As with
5482displays you request manually using @code{x} or @code{print}, you can
5483specify the output format you prefer; in fact, @code{display} decides
5484whether to use @code{print} or @code{x} depending on how elaborate your
5485format specification is---it uses @code{x} if you specify a unit size,
5486or one of the two formats (@samp{i} and @samp{s}) that are only
5487supported by @code{x}; otherwise it uses @code{print}.
5488
5489@table @code
5490@kindex display
d4f3574e
SS
5491@item display @var{expr}
5492Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5493each time your program stops. @xref{Expressions, ,Expressions}.
5494
5495@code{display} does not repeat if you press @key{RET} again after using it.
5496
d4f3574e 5497@item display/@var{fmt} @var{expr}
c906108c 5498For @var{fmt} specifying only a display format and not a size or
d4f3574e 5499count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5500arrange to display it each time in the specified format @var{fmt}.
5501@xref{Output Formats,,Output formats}.
5502
5503@item display/@var{fmt} @var{addr}
5504For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5505number of units, add the expression @var{addr} as a memory address to
5506be examined each time your program stops. Examining means in effect
5507doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5508@end table
5509
5510For example, @samp{display/i $pc} can be helpful, to see the machine
5511instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5512is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5513
5514@table @code
5515@kindex delete display
5516@kindex undisplay
5517@item undisplay @var{dnums}@dots{}
5518@itemx delete display @var{dnums}@dots{}
5519Remove item numbers @var{dnums} from the list of expressions to display.
5520
5521@code{undisplay} does not repeat if you press @key{RET} after using it.
5522(Otherwise you would just get the error @samp{No display number @dots{}}.)
5523
5524@kindex disable display
5525@item disable display @var{dnums}@dots{}
5526Disable the display of item numbers @var{dnums}. A disabled display
5527item is not printed automatically, but is not forgotten. It may be
5528enabled again later.
5529
5530@kindex enable display
5531@item enable display @var{dnums}@dots{}
5532Enable display of item numbers @var{dnums}. It becomes effective once
5533again in auto display of its expression, until you specify otherwise.
5534
5535@item display
5536Display the current values of the expressions on the list, just as is
5537done when your program stops.
5538
5539@kindex info display
5540@item info display
5541Print the list of expressions previously set up to display
5542automatically, each one with its item number, but without showing the
5543values. This includes disabled expressions, which are marked as such.
5544It also includes expressions which would not be displayed right now
5545because they refer to automatic variables not currently available.
5546@end table
5547
15387254 5548@cindex display disabled out of scope
c906108c
SS
5549If a display expression refers to local variables, then it does not make
5550sense outside the lexical context for which it was set up. Such an
5551expression is disabled when execution enters a context where one of its
5552variables is not defined. For example, if you give the command
5553@code{display last_char} while inside a function with an argument
5554@code{last_char}, @value{GDBN} displays this argument while your program
5555continues to stop inside that function. When it stops elsewhere---where
5556there is no variable @code{last_char}---the display is disabled
5557automatically. The next time your program stops where @code{last_char}
5558is meaningful, you can enable the display expression once again.
5559
6d2ebf8b 5560@node Print Settings
c906108c
SS
5561@section Print settings
5562
5563@cindex format options
5564@cindex print settings
5565@value{GDBN} provides the following ways to control how arrays, structures,
5566and symbols are printed.
5567
5568@noindent
5569These settings are useful for debugging programs in any language:
5570
5571@table @code
4644b6e3 5572@kindex set print
c906108c
SS
5573@item set print address
5574@itemx set print address on
4644b6e3 5575@cindex print/don't print memory addresses
c906108c
SS
5576@value{GDBN} prints memory addresses showing the location of stack
5577traces, structure values, pointer values, breakpoints, and so forth,
5578even when it also displays the contents of those addresses. The default
5579is @code{on}. For example, this is what a stack frame display looks like with
5580@code{set print address on}:
5581
5582@smallexample
5583@group
5584(@value{GDBP}) f
5585#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5586 at input.c:530
5587530 if (lquote != def_lquote)
5588@end group
5589@end smallexample
5590
5591@item set print address off
5592Do not print addresses when displaying their contents. For example,
5593this is the same stack frame displayed with @code{set print address off}:
5594
5595@smallexample
5596@group
5597(@value{GDBP}) set print addr off
5598(@value{GDBP}) f
5599#0 set_quotes (lq="<<", rq=">>") at input.c:530
5600530 if (lquote != def_lquote)
5601@end group
5602@end smallexample
5603
5604You can use @samp{set print address off} to eliminate all machine
5605dependent displays from the @value{GDBN} interface. For example, with
5606@code{print address off}, you should get the same text for backtraces on
5607all machines---whether or not they involve pointer arguments.
5608
4644b6e3 5609@kindex show print
c906108c
SS
5610@item show print address
5611Show whether or not addresses are to be printed.
5612@end table
5613
5614When @value{GDBN} prints a symbolic address, it normally prints the
5615closest earlier symbol plus an offset. If that symbol does not uniquely
5616identify the address (for example, it is a name whose scope is a single
5617source file), you may need to clarify. One way to do this is with
5618@code{info line}, for example @samp{info line *0x4537}. Alternately,
5619you can set @value{GDBN} to print the source file and line number when
5620it prints a symbolic address:
5621
5622@table @code
c906108c 5623@item set print symbol-filename on
9c16f35a
EZ
5624@cindex source file and line of a symbol
5625@cindex symbol, source file and line
c906108c
SS
5626Tell @value{GDBN} to print the source file name and line number of a
5627symbol in the symbolic form of an address.
5628
5629@item set print symbol-filename off
5630Do not print source file name and line number of a symbol. This is the
5631default.
5632
c906108c
SS
5633@item show print symbol-filename
5634Show whether or not @value{GDBN} will print the source file name and
5635line number of a symbol in the symbolic form of an address.
5636@end table
5637
5638Another situation where it is helpful to show symbol filenames and line
5639numbers is when disassembling code; @value{GDBN} shows you the line
5640number and source file that corresponds to each instruction.
5641
5642Also, you may wish to see the symbolic form only if the address being
5643printed is reasonably close to the closest earlier symbol:
5644
5645@table @code
c906108c 5646@item set print max-symbolic-offset @var{max-offset}
4644b6e3 5647@cindex maximum value for offset of closest symbol
c906108c
SS
5648Tell @value{GDBN} to only display the symbolic form of an address if the
5649offset between the closest earlier symbol and the address is less than
5d161b24 5650@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5651to always print the symbolic form of an address if any symbol precedes it.
5652
c906108c
SS
5653@item show print max-symbolic-offset
5654Ask how large the maximum offset is that @value{GDBN} prints in a
5655symbolic address.
5656@end table
5657
5658@cindex wild pointer, interpreting
5659@cindex pointer, finding referent
5660If you have a pointer and you are not sure where it points, try
5661@samp{set print symbol-filename on}. Then you can determine the name
5662and source file location of the variable where it points, using
5663@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5664For example, here @value{GDBN} shows that a variable @code{ptt} points
5665at another variable @code{t}, defined in @file{hi2.c}:
5666
474c8240 5667@smallexample
c906108c
SS
5668(@value{GDBP}) set print symbol-filename on
5669(@value{GDBP}) p/a ptt
5670$4 = 0xe008 <t in hi2.c>
474c8240 5671@end smallexample
c906108c
SS
5672
5673@quotation
5674@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5675does not show the symbol name and filename of the referent, even with
5676the appropriate @code{set print} options turned on.
5677@end quotation
5678
5679Other settings control how different kinds of objects are printed:
5680
5681@table @code
c906108c
SS
5682@item set print array
5683@itemx set print array on
4644b6e3 5684@cindex pretty print arrays
c906108c
SS
5685Pretty print arrays. This format is more convenient to read,
5686but uses more space. The default is off.
5687
5688@item set print array off
5689Return to compressed format for arrays.
5690
c906108c
SS
5691@item show print array
5692Show whether compressed or pretty format is selected for displaying
5693arrays.
5694
c906108c 5695@item set print elements @var{number-of-elements}
4644b6e3 5696@cindex number of array elements to print
9c16f35a 5697@cindex limit on number of printed array elements
c906108c
SS
5698Set a limit on how many elements of an array @value{GDBN} will print.
5699If @value{GDBN} is printing a large array, it stops printing after it has
5700printed the number of elements set by the @code{set print elements} command.
5701This limit also applies to the display of strings.
d4f3574e 5702When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5703Setting @var{number-of-elements} to zero means that the printing is unlimited.
5704
c906108c
SS
5705@item show print elements
5706Display the number of elements of a large array that @value{GDBN} will print.
5707If the number is 0, then the printing is unlimited.
5708
9c16f35a
EZ
5709@item set print repeats
5710@cindex repeated array elements
5711Set the threshold for suppressing display of repeated array
5712elelments. When the number of consecutive identical elements of an
5713array exceeds the threshold, @value{GDBN} prints the string
5714@code{"<repeats @var{n} times>"}, where @var{n} is the number of
5715identical repetitions, instead of displaying the identical elements
5716themselves. Setting the threshold to zero will cause all elements to
5717be individually printed. The default threshold is 10.
5718
5719@item show print repeats
5720Display the current threshold for printing repeated identical
5721elements.
5722
c906108c 5723@item set print null-stop
4644b6e3 5724@cindex @sc{null} elements in arrays
c906108c 5725Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5726@sc{null} is encountered. This is useful when large arrays actually
c906108c 5727contain only short strings.
d4f3574e 5728The default is off.
c906108c 5729
9c16f35a
EZ
5730@item show print null-stop
5731Show whether @value{GDBN} stops printing an array on the first
5732@sc{null} character.
5733
c906108c 5734@item set print pretty on
9c16f35a
EZ
5735@cindex print structures in indented form
5736@cindex indentation in structure display
5d161b24 5737Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5738per line, like this:
5739
5740@smallexample
5741@group
5742$1 = @{
5743 next = 0x0,
5744 flags = @{
5745 sweet = 1,
5746 sour = 1
5747 @},
5748 meat = 0x54 "Pork"
5749@}
5750@end group
5751@end smallexample
5752
5753@item set print pretty off
5754Cause @value{GDBN} to print structures in a compact format, like this:
5755
5756@smallexample
5757@group
5758$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5759meat = 0x54 "Pork"@}
5760@end group
5761@end smallexample
5762
5763@noindent
5764This is the default format.
5765
c906108c
SS
5766@item show print pretty
5767Show which format @value{GDBN} is using to print structures.
5768
c906108c 5769@item set print sevenbit-strings on
4644b6e3
EZ
5770@cindex eight-bit characters in strings
5771@cindex octal escapes in strings
c906108c
SS
5772Print using only seven-bit characters; if this option is set,
5773@value{GDBN} displays any eight-bit characters (in strings or
5774character values) using the notation @code{\}@var{nnn}. This setting is
5775best if you are working in English (@sc{ascii}) and you use the
5776high-order bit of characters as a marker or ``meta'' bit.
5777
5778@item set print sevenbit-strings off
5779Print full eight-bit characters. This allows the use of more
5780international character sets, and is the default.
5781
c906108c
SS
5782@item show print sevenbit-strings
5783Show whether or not @value{GDBN} is printing only seven-bit characters.
5784
c906108c 5785@item set print union on
4644b6e3 5786@cindex unions in structures, printing
9c16f35a
EZ
5787Tell @value{GDBN} to print unions which are contained in structures
5788and other unions. This is the default setting.
c906108c
SS
5789
5790@item set print union off
9c16f35a
EZ
5791Tell @value{GDBN} not to print unions which are contained in
5792structures and other unions. @value{GDBN} will print @code{"@{...@}"}
5793instead.
c906108c 5794
c906108c
SS
5795@item show print union
5796Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 5797structures and other unions.
c906108c
SS
5798
5799For example, given the declarations
5800
5801@smallexample
5802typedef enum @{Tree, Bug@} Species;
5803typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5804typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5805 Bug_forms;
5806
5807struct thing @{
5808 Species it;
5809 union @{
5810 Tree_forms tree;
5811 Bug_forms bug;
5812 @} form;
5813@};
5814
5815struct thing foo = @{Tree, @{Acorn@}@};
5816@end smallexample
5817
5818@noindent
5819with @code{set print union on} in effect @samp{p foo} would print
5820
5821@smallexample
5822$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5823@end smallexample
5824
5825@noindent
5826and with @code{set print union off} in effect it would print
5827
5828@smallexample
5829$1 = @{it = Tree, form = @{...@}@}
5830@end smallexample
9c16f35a
EZ
5831
5832@noindent
5833@code{set print union} affects programs written in C-like languages
5834and in Pascal.
c906108c
SS
5835@end table
5836
c906108c
SS
5837@need 1000
5838@noindent
b37052ae 5839These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5840
5841@table @code
4644b6e3 5842@cindex demangling C@t{++} names
c906108c
SS
5843@item set print demangle
5844@itemx set print demangle on
b37052ae 5845Print C@t{++} names in their source form rather than in the encoded
c906108c 5846(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5847linkage. The default is on.
c906108c 5848
c906108c 5849@item show print demangle
b37052ae 5850Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 5851
c906108c
SS
5852@item set print asm-demangle
5853@itemx set print asm-demangle on
b37052ae 5854Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5855in assembler code printouts such as instruction disassemblies.
5856The default is off.
5857
c906108c 5858@item show print asm-demangle
b37052ae 5859Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5860or demangled form.
5861
b37052ae
EZ
5862@cindex C@t{++} symbol decoding style
5863@cindex symbol decoding style, C@t{++}
a8f24a35 5864@kindex set demangle-style
c906108c
SS
5865@item set demangle-style @var{style}
5866Choose among several encoding schemes used by different compilers to
b37052ae 5867represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5868
5869@table @code
5870@item auto
5871Allow @value{GDBN} to choose a decoding style by inspecting your program.
5872
5873@item gnu
b37052ae 5874Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5875This is the default.
c906108c
SS
5876
5877@item hp
b37052ae 5878Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5879
5880@item lucid
b37052ae 5881Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5882
5883@item arm
b37052ae 5884Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5885@strong{Warning:} this setting alone is not sufficient to allow
5886debugging @code{cfront}-generated executables. @value{GDBN} would
5887require further enhancement to permit that.
5888
5889@end table
5890If you omit @var{style}, you will see a list of possible formats.
5891
c906108c 5892@item show demangle-style
b37052ae 5893Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 5894
c906108c
SS
5895@item set print object
5896@itemx set print object on
4644b6e3 5897@cindex derived type of an object, printing
9c16f35a 5898@cindex display derived types
c906108c
SS
5899When displaying a pointer to an object, identify the @emph{actual}
5900(derived) type of the object rather than the @emph{declared} type, using
5901the virtual function table.
5902
5903@item set print object off
5904Display only the declared type of objects, without reference to the
5905virtual function table. This is the default setting.
5906
c906108c
SS
5907@item show print object
5908Show whether actual, or declared, object types are displayed.
5909
c906108c
SS
5910@item set print static-members
5911@itemx set print static-members on
4644b6e3 5912@cindex static members of C@t{++} objects
b37052ae 5913Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5914
5915@item set print static-members off
b37052ae 5916Do not print static members when displaying a C@t{++} object.
c906108c 5917
c906108c 5918@item show print static-members
9c16f35a
EZ
5919Show whether C@t{++} static members are printed or not.
5920
5921@item set print pascal_static-members
5922@itemx set print pascal_static-members on
5923@cindex static members of Pacal objects
5924@cindex Pacal objects, static members display
5925Print static members when displaying a Pascal object. The default is on.
5926
5927@item set print pascal_static-members off
5928Do not print static members when displaying a Pascal object.
5929
5930@item show print pascal_static-members
5931Show whether Pascal static members are printed or not.
c906108c
SS
5932
5933@c These don't work with HP ANSI C++ yet.
c906108c
SS
5934@item set print vtbl
5935@itemx set print vtbl on
4644b6e3 5936@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
5937@cindex virtual functions (C@t{++}) display
5938@cindex VTBL display
b37052ae 5939Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5940(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5941ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5942
5943@item set print vtbl off
b37052ae 5944Do not pretty print C@t{++} virtual function tables.
c906108c 5945
c906108c 5946@item show print vtbl
b37052ae 5947Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5948@end table
c906108c 5949
6d2ebf8b 5950@node Value History
c906108c
SS
5951@section Value history
5952
5953@cindex value history
9c16f35a 5954@cindex history of values printed by @value{GDBN}
5d161b24
DB
5955Values printed by the @code{print} command are saved in the @value{GDBN}
5956@dfn{value history}. This allows you to refer to them in other expressions.
5957Values are kept until the symbol table is re-read or discarded
5958(for example with the @code{file} or @code{symbol-file} commands).
5959When the symbol table changes, the value history is discarded,
5960since the values may contain pointers back to the types defined in the
c906108c
SS
5961symbol table.
5962
5963@cindex @code{$}
5964@cindex @code{$$}
5965@cindex history number
5966The values printed are given @dfn{history numbers} by which you can
5967refer to them. These are successive integers starting with one.
5968@code{print} shows you the history number assigned to a value by
5969printing @samp{$@var{num} = } before the value; here @var{num} is the
5970history number.
5971
5972To refer to any previous value, use @samp{$} followed by the value's
5973history number. The way @code{print} labels its output is designed to
5974remind you of this. Just @code{$} refers to the most recent value in
5975the history, and @code{$$} refers to the value before that.
5976@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5977is the value just prior to @code{$$}, @code{$$1} is equivalent to
5978@code{$$}, and @code{$$0} is equivalent to @code{$}.
5979
5980For example, suppose you have just printed a pointer to a structure and
5981want to see the contents of the structure. It suffices to type
5982
474c8240 5983@smallexample
c906108c 5984p *$
474c8240 5985@end smallexample
c906108c
SS
5986
5987If you have a chain of structures where the component @code{next} points
5988to the next one, you can print the contents of the next one with this:
5989
474c8240 5990@smallexample
c906108c 5991p *$.next
474c8240 5992@end smallexample
c906108c
SS
5993
5994@noindent
5995You can print successive links in the chain by repeating this
5996command---which you can do by just typing @key{RET}.
5997
5998Note that the history records values, not expressions. If the value of
5999@code{x} is 4 and you type these commands:
6000
474c8240 6001@smallexample
c906108c
SS
6002print x
6003set x=5
474c8240 6004@end smallexample
c906108c
SS
6005
6006@noindent
6007then the value recorded in the value history by the @code{print} command
6008remains 4 even though the value of @code{x} has changed.
6009
6010@table @code
6011@kindex show values
6012@item show values
6013Print the last ten values in the value history, with their item numbers.
6014This is like @samp{p@ $$9} repeated ten times, except that @code{show
6015values} does not change the history.
6016
6017@item show values @var{n}
6018Print ten history values centered on history item number @var{n}.
6019
6020@item show values +
6021Print ten history values just after the values last printed. If no more
6022values are available, @code{show values +} produces no display.
6023@end table
6024
6025Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
6026same effect as @samp{show values +}.
6027
6d2ebf8b 6028@node Convenience Vars
c906108c
SS
6029@section Convenience variables
6030
6031@cindex convenience variables
9c16f35a 6032@cindex user-defined variables
c906108c
SS
6033@value{GDBN} provides @dfn{convenience variables} that you can use within
6034@value{GDBN} to hold on to a value and refer to it later. These variables
6035exist entirely within @value{GDBN}; they are not part of your program, and
6036setting a convenience variable has no direct effect on further execution
6037of your program. That is why you can use them freely.
6038
6039Convenience variables are prefixed with @samp{$}. Any name preceded by
6040@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 6041the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
6042(Value history references, in contrast, are @emph{numbers} preceded
6043by @samp{$}. @xref{Value History, ,Value history}.)
6044
6045You can save a value in a convenience variable with an assignment
6046expression, just as you would set a variable in your program.
6047For example:
6048
474c8240 6049@smallexample
c906108c 6050set $foo = *object_ptr
474c8240 6051@end smallexample
c906108c
SS
6052
6053@noindent
6054would save in @code{$foo} the value contained in the object pointed to by
6055@code{object_ptr}.
6056
6057Using a convenience variable for the first time creates it, but its
6058value is @code{void} until you assign a new value. You can alter the
6059value with another assignment at any time.
6060
6061Convenience variables have no fixed types. You can assign a convenience
6062variable any type of value, including structures and arrays, even if
6063that variable already has a value of a different type. The convenience
6064variable, when used as an expression, has the type of its current value.
6065
6066@table @code
6067@kindex show convenience
9c16f35a 6068@cindex show all user variables
c906108c
SS
6069@item show convenience
6070Print a list of convenience variables used so far, and their values.
d4f3574e 6071Abbreviated @code{show conv}.
c906108c
SS
6072@end table
6073
6074One of the ways to use a convenience variable is as a counter to be
6075incremented or a pointer to be advanced. For example, to print
6076a field from successive elements of an array of structures:
6077
474c8240 6078@smallexample
c906108c
SS
6079set $i = 0
6080print bar[$i++]->contents
474c8240 6081@end smallexample
c906108c 6082
d4f3574e
SS
6083@noindent
6084Repeat that command by typing @key{RET}.
c906108c
SS
6085
6086Some convenience variables are created automatically by @value{GDBN} and given
6087values likely to be useful.
6088
6089@table @code
41afff9a 6090@vindex $_@r{, convenience variable}
c906108c
SS
6091@item $_
6092The variable @code{$_} is automatically set by the @code{x} command to
6093the last address examined (@pxref{Memory, ,Examining memory}). Other
6094commands which provide a default address for @code{x} to examine also
6095set @code{$_} to that address; these commands include @code{info line}
6096and @code{info breakpoint}. The type of @code{$_} is @code{void *}
6097except when set by the @code{x} command, in which case it is a pointer
6098to the type of @code{$__}.
6099
41afff9a 6100@vindex $__@r{, convenience variable}
c906108c
SS
6101@item $__
6102The variable @code{$__} is automatically set by the @code{x} command
6103to the value found in the last address examined. Its type is chosen
6104to match the format in which the data was printed.
6105
6106@item $_exitcode
41afff9a 6107@vindex $_exitcode@r{, convenience variable}
c906108c
SS
6108The variable @code{$_exitcode} is automatically set to the exit code when
6109the program being debugged terminates.
6110@end table
6111
53a5351d
JM
6112On HP-UX systems, if you refer to a function or variable name that
6113begins with a dollar sign, @value{GDBN} searches for a user or system
6114name first, before it searches for a convenience variable.
c906108c 6115
6d2ebf8b 6116@node Registers
c906108c
SS
6117@section Registers
6118
6119@cindex registers
6120You can refer to machine register contents, in expressions, as variables
6121with names starting with @samp{$}. The names of registers are different
6122for each machine; use @code{info registers} to see the names used on
6123your machine.
6124
6125@table @code
6126@kindex info registers
6127@item info registers
6128Print the names and values of all registers except floating-point
c85508ee 6129and vector registers (in the selected stack frame).
c906108c
SS
6130
6131@kindex info all-registers
6132@cindex floating point registers
6133@item info all-registers
6134Print the names and values of all registers, including floating-point
c85508ee 6135and vector registers (in the selected stack frame).
c906108c
SS
6136
6137@item info registers @var{regname} @dots{}
6138Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
6139As discussed in detail below, register values are normally relative to
6140the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
6141the machine you are using, with or without the initial @samp{$}.
6142@end table
6143
e09f16f9
EZ
6144@cindex stack pointer register
6145@cindex program counter register
6146@cindex process status register
6147@cindex frame pointer register
6148@cindex standard registers
c906108c
SS
6149@value{GDBN} has four ``standard'' register names that are available (in
6150expressions) on most machines---whenever they do not conflict with an
6151architecture's canonical mnemonics for registers. The register names
6152@code{$pc} and @code{$sp} are used for the program counter register and
6153the stack pointer. @code{$fp} is used for a register that contains a
6154pointer to the current stack frame, and @code{$ps} is used for a
6155register that contains the processor status. For example,
6156you could print the program counter in hex with
6157
474c8240 6158@smallexample
c906108c 6159p/x $pc
474c8240 6160@end smallexample
c906108c
SS
6161
6162@noindent
6163or print the instruction to be executed next with
6164
474c8240 6165@smallexample
c906108c 6166x/i $pc
474c8240 6167@end smallexample
c906108c
SS
6168
6169@noindent
6170or add four to the stack pointer@footnote{This is a way of removing
6171one word from the stack, on machines where stacks grow downward in
6172memory (most machines, nowadays). This assumes that the innermost
6173stack frame is selected; setting @code{$sp} is not allowed when other
6174stack frames are selected. To pop entire frames off the stack,
6175regardless of machine architecture, use @code{return};
d4f3574e 6176see @ref{Returning, ,Returning from a function}.} with
c906108c 6177
474c8240 6178@smallexample
c906108c 6179set $sp += 4
474c8240 6180@end smallexample
c906108c
SS
6181
6182Whenever possible, these four standard register names are available on
6183your machine even though the machine has different canonical mnemonics,
6184so long as there is no conflict. The @code{info registers} command
6185shows the canonical names. For example, on the SPARC, @code{info
6186registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
6187can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6188is an alias for the @sc{eflags} register.
c906108c
SS
6189
6190@value{GDBN} always considers the contents of an ordinary register as an
6191integer when the register is examined in this way. Some machines have
6192special registers which can hold nothing but floating point; these
6193registers are considered to have floating point values. There is no way
6194to refer to the contents of an ordinary register as floating point value
6195(although you can @emph{print} it as a floating point value with
6196@samp{print/f $@var{regname}}).
6197
6198Some registers have distinct ``raw'' and ``virtual'' data formats. This
6199means that the data format in which the register contents are saved by
6200the operating system is not the same one that your program normally
6201sees. For example, the registers of the 68881 floating point
6202coprocessor are always saved in ``extended'' (raw) format, but all C
6203programs expect to work with ``double'' (virtual) format. In such
5d161b24 6204cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
6205that makes sense for your program), but the @code{info registers} command
6206prints the data in both formats.
6207
6208Normally, register values are relative to the selected stack frame
6209(@pxref{Selection, ,Selecting a frame}). This means that you get the
6210value that the register would contain if all stack frames farther in
6211were exited and their saved registers restored. In order to see the
6212true contents of hardware registers, you must select the innermost
6213frame (with @samp{frame 0}).
6214
6215However, @value{GDBN} must deduce where registers are saved, from the machine
6216code generated by your compiler. If some registers are not saved, or if
6217@value{GDBN} is unable to locate the saved registers, the selected stack
6218frame makes no difference.
6219
6d2ebf8b 6220@node Floating Point Hardware
c906108c
SS
6221@section Floating point hardware
6222@cindex floating point
6223
6224Depending on the configuration, @value{GDBN} may be able to give
6225you more information about the status of the floating point hardware.
6226
6227@table @code
6228@kindex info float
6229@item info float
6230Display hardware-dependent information about the floating
6231point unit. The exact contents and layout vary depending on the
6232floating point chip. Currently, @samp{info float} is supported on
6233the ARM and x86 machines.
6234@end table
c906108c 6235
e76f1f2e
AC
6236@node Vector Unit
6237@section Vector Unit
6238@cindex vector unit
6239
6240Depending on the configuration, @value{GDBN} may be able to give you
6241more information about the status of the vector unit.
6242
6243@table @code
6244@kindex info vector
6245@item info vector
6246Display information about the vector unit. The exact contents and
6247layout vary depending on the hardware.
6248@end table
6249
721c2651
EZ
6250@node OS Information
6251@section Operating system auxiliary information
6252@cindex OS information
6253
6254@value{GDBN} provides interfaces to useful OS facilities that can help
6255you debug your program.
6256
6257@cindex @code{ptrace} system call
6258@cindex @code{struct user} contents
6259When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6260machines), it interfaces with the inferior via the @code{ptrace}
6261system call. The operating system creates a special sata structure,
6262called @code{struct user}, for this interface. You can use the
6263command @code{info udot} to display the contents of this data
6264structure.
6265
6266@table @code
6267@item info udot
6268@kindex info udot
6269Display the contents of the @code{struct user} maintained by the OS
6270kernel for the program being debugged. @value{GDBN} displays the
6271contents of @code{struct user} as a list of hex numbers, similar to
6272the @code{examine} command.
6273@end table
6274
b383017d
RM
6275@cindex auxiliary vector
6276@cindex vector, auxiliary
b383017d
RM
6277Some operating systems supply an @dfn{auxiliary vector} to programs at
6278startup. This is akin to the arguments and environment that you
6279specify for a program, but contains a system-dependent variety of
6280binary values that tell system libraries important details about the
6281hardware, operating system, and process. Each value's purpose is
6282identified by an integer tag; the meanings are well-known but system-specific.
6283Depending on the configuration and operating system facilities,
9c16f35a
EZ
6284@value{GDBN} may be able to show you this information. For remote
6285targets, this functionality may further depend on the remote stub's
6286support of the @samp{qPart:auxv:read} packet, see @ref{Remote
6287configuration, auxiliary vector}.
b383017d
RM
6288
6289@table @code
6290@kindex info auxv
6291@item info auxv
6292Display the auxiliary vector of the inferior, which can be either a
e4937fc1 6293live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
6294numerically, and also shows names and text descriptions for recognized
6295tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 6296pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
6297most appropriate form for a recognized tag, and in hexadecimal for
6298an unrecognized tag.
6299@end table
6300
721c2651 6301
29e57380 6302@node Memory Region Attributes
b383017d 6303@section Memory region attributes
29e57380
C
6304@cindex memory region attributes
6305
b383017d
RM
6306@dfn{Memory region attributes} allow you to describe special handling
6307required by regions of your target's memory. @value{GDBN} uses attributes
29e57380
C
6308to determine whether to allow certain types of memory accesses; whether to
6309use specific width accesses; and whether to cache target memory.
6310
6311Defined memory regions can be individually enabled and disabled. When a
6312memory region is disabled, @value{GDBN} uses the default attributes when
6313accessing memory in that region. Similarly, if no memory regions have
6314been defined, @value{GDBN} uses the default attributes when accessing
6315all memory.
6316
b383017d 6317When a memory region is defined, it is given a number to identify it;
29e57380
C
6318to enable, disable, or remove a memory region, you specify that number.
6319
6320@table @code
6321@kindex mem
bfac230e 6322@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
6323Define a memory region bounded by @var{lower} and @var{upper} with
6324attributes @var{attributes}@dots{}, and add it to the list of regions
6325monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
6326case: it is treated as the the target's maximum memory address.
bfac230e 6327(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
6328
6329@kindex delete mem
6330@item delete mem @var{nums}@dots{}
09d4efe1
EZ
6331Remove memory regions @var{nums}@dots{} from the list of regions
6332monitored by @value{GDBN}.
29e57380
C
6333
6334@kindex disable mem
6335@item disable mem @var{nums}@dots{}
09d4efe1 6336Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 6337A disabled memory region is not forgotten.
29e57380
C
6338It may be enabled again later.
6339
6340@kindex enable mem
6341@item enable mem @var{nums}@dots{}
09d4efe1 6342Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
6343
6344@kindex info mem
6345@item info mem
6346Print a table of all defined memory regions, with the following columns
09d4efe1 6347for each region:
29e57380
C
6348
6349@table @emph
6350@item Memory Region Number
6351@item Enabled or Disabled.
b383017d 6352Enabled memory regions are marked with @samp{y}.
29e57380
C
6353Disabled memory regions are marked with @samp{n}.
6354
6355@item Lo Address
6356The address defining the inclusive lower bound of the memory region.
6357
6358@item Hi Address
6359The address defining the exclusive upper bound of the memory region.
6360
6361@item Attributes
6362The list of attributes set for this memory region.
6363@end table
6364@end table
6365
6366
6367@subsection Attributes
6368
b383017d 6369@subsubsection Memory Access Mode
29e57380
C
6370The access mode attributes set whether @value{GDBN} may make read or
6371write accesses to a memory region.
6372
6373While these attributes prevent @value{GDBN} from performing invalid
6374memory accesses, they do nothing to prevent the target system, I/O DMA,
6375etc. from accessing memory.
6376
6377@table @code
6378@item ro
6379Memory is read only.
6380@item wo
6381Memory is write only.
6382@item rw
6ca652b0 6383Memory is read/write. This is the default.
29e57380
C
6384@end table
6385
6386@subsubsection Memory Access Size
6387The acccess size attributes tells @value{GDBN} to use specific sized
6388accesses in the memory region. Often memory mapped device registers
6389require specific sized accesses. If no access size attribute is
6390specified, @value{GDBN} may use accesses of any size.
6391
6392@table @code
6393@item 8
6394Use 8 bit memory accesses.
6395@item 16
6396Use 16 bit memory accesses.
6397@item 32
6398Use 32 bit memory accesses.
6399@item 64
6400Use 64 bit memory accesses.
6401@end table
6402
6403@c @subsubsection Hardware/Software Breakpoints
6404@c The hardware/software breakpoint attributes set whether @value{GDBN}
6405@c will use hardware or software breakpoints for the internal breakpoints
6406@c used by the step, next, finish, until, etc. commands.
6407@c
6408@c @table @code
6409@c @item hwbreak
b383017d 6410@c Always use hardware breakpoints
29e57380
C
6411@c @item swbreak (default)
6412@c @end table
6413
6414@subsubsection Data Cache
6415The data cache attributes set whether @value{GDBN} will cache target
6416memory. While this generally improves performance by reducing debug
6417protocol overhead, it can lead to incorrect results because @value{GDBN}
6418does not know about volatile variables or memory mapped device
6419registers.
6420
6421@table @code
6422@item cache
b383017d 6423Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6424@item nocache
6425Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6426@end table
6427
6428@c @subsubsection Memory Write Verification
b383017d 6429@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6430@c will re-reads data after each write to verify the write was successful.
6431@c
6432@c @table @code
6433@c @item verify
6434@c @item noverify (default)
6435@c @end table
6436
16d9dec6
MS
6437@node Dump/Restore Files
6438@section Copy between memory and a file
6439@cindex dump/restore files
6440@cindex append data to a file
6441@cindex dump data to a file
6442@cindex restore data from a file
16d9dec6 6443
df5215a6
JB
6444You can use the commands @code{dump}, @code{append}, and
6445@code{restore} to copy data between target memory and a file. The
6446@code{dump} and @code{append} commands write data to a file, and the
6447@code{restore} command reads data from a file back into the inferior's
6448memory. Files may be in binary, Motorola S-record, Intel hex, or
6449Tektronix Hex format; however, @value{GDBN} can only append to binary
6450files.
6451
6452@table @code
6453
6454@kindex dump
6455@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6456@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6457Dump the contents of memory from @var{start_addr} to @var{end_addr},
6458or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6459
df5215a6 6460The @var{format} parameter may be any one of:
16d9dec6 6461@table @code
df5215a6
JB
6462@item binary
6463Raw binary form.
6464@item ihex
6465Intel hex format.
6466@item srec
6467Motorola S-record format.
6468@item tekhex
6469Tektronix Hex format.
6470@end table
6471
6472@value{GDBN} uses the same definitions of these formats as the
6473@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6474@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6475form.
6476
6477@kindex append
6478@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6479@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6480Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 6481or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
6482(@value{GDBN} can only append data to files in raw binary form.)
6483
6484@kindex restore
6485@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6486Restore the contents of file @var{filename} into memory. The
6487@code{restore} command can automatically recognize any known @sc{bfd}
6488file format, except for raw binary. To restore a raw binary file you
6489must specify the optional keyword @code{binary} after the filename.
16d9dec6 6490
b383017d 6491If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6492contained in the file. Binary files always start at address zero, so
6493they will be restored at address @var{bias}. Other bfd files have
6494a built-in location; they will be restored at offset @var{bias}
6495from that location.
6496
6497If @var{start} and/or @var{end} are non-zero, then only data between
6498file offset @var{start} and file offset @var{end} will be restored.
b383017d 6499These offsets are relative to the addresses in the file, before
16d9dec6
MS
6500the @var{bias} argument is applied.
6501
6502@end table
6503
384ee23f
EZ
6504@node Core File Generation
6505@section How to Produce a Core File from Your Program
6506@cindex dump core from inferior
6507
6508A @dfn{core file} or @dfn{core dump} is a file that records the memory
6509image of a running process and its process status (register values
6510etc.). Its primary use is post-mortem debugging of a program that
6511crashed while it ran outside a debugger. A program that crashes
6512automatically produces a core file, unless this feature is disabled by
6513the user. @xref{Files}, for information on invoking @value{GDBN} in
6514the post-mortem debugging mode.
6515
6516Occasionally, you may wish to produce a core file of the program you
6517are debugging in order to preserve a snapshot of its state.
6518@value{GDBN} has a special command for that.
6519
6520@table @code
6521@kindex gcore
6522@kindex generate-core-file
6523@item generate-core-file [@var{file}]
6524@itemx gcore [@var{file}]
6525Produce a core dump of the inferior process. The optional argument
6526@var{file} specifies the file name where to put the core dump. If not
6527specified, the file name defaults to @file{core.@var{pid}}, where
6528@var{pid} is the inferior process ID.
6529
6530Note that this command is implemented only for some systems (as of
6531this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6532@end table
6533
a0eb71c5
KB
6534@node Character Sets
6535@section Character Sets
6536@cindex character sets
6537@cindex charset
6538@cindex translating between character sets
6539@cindex host character set
6540@cindex target character set
6541
6542If the program you are debugging uses a different character set to
6543represent characters and strings than the one @value{GDBN} uses itself,
6544@value{GDBN} can automatically translate between the character sets for
6545you. The character set @value{GDBN} uses we call the @dfn{host
6546character set}; the one the inferior program uses we call the
6547@dfn{target character set}.
6548
6549For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6550uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6551remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6552running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6553then the host character set is Latin-1, and the target character set is
6554@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6555target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6556@sc{ebcdic} and Latin 1 as you print character or string values, or use
6557character and string literals in expressions.
6558
6559@value{GDBN} has no way to automatically recognize which character set
6560the inferior program uses; you must tell it, using the @code{set
6561target-charset} command, described below.
6562
6563Here are the commands for controlling @value{GDBN}'s character set
6564support:
6565
6566@table @code
6567@item set target-charset @var{charset}
6568@kindex set target-charset
6569Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6570character set names @value{GDBN} recognizes below, but if you type
6571@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6572list the target character sets it supports.
a0eb71c5
KB
6573@end table
6574
6575@table @code
6576@item set host-charset @var{charset}
6577@kindex set host-charset
6578Set the current host character set to @var{charset}.
6579
6580By default, @value{GDBN} uses a host character set appropriate to the
6581system it is running on; you can override that default using the
6582@code{set host-charset} command.
6583
6584@value{GDBN} can only use certain character sets as its host character
6585set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6586indicate which can be host character sets, but if you type
6587@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6588list the host character sets it supports.
a0eb71c5
KB
6589
6590@item set charset @var{charset}
6591@kindex set charset
e33d66ec
EZ
6592Set the current host and target character sets to @var{charset}. As
6593above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6594@value{GDBN} will list the name of the character sets that can be used
6595for both host and target.
6596
a0eb71c5
KB
6597
6598@item show charset
a0eb71c5 6599@kindex show charset
b383017d 6600Show the names of the current host and target charsets.
e33d66ec
EZ
6601
6602@itemx show host-charset
a0eb71c5 6603@kindex show host-charset
b383017d 6604Show the name of the current host charset.
e33d66ec
EZ
6605
6606@itemx show target-charset
a0eb71c5 6607@kindex show target-charset
b383017d 6608Show the name of the current target charset.
a0eb71c5
KB
6609
6610@end table
6611
6612@value{GDBN} currently includes support for the following character
6613sets:
6614
6615@table @code
6616
6617@item ASCII
6618@cindex ASCII character set
6619Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6620character set.
6621
6622@item ISO-8859-1
6623@cindex ISO 8859-1 character set
6624@cindex ISO Latin 1 character set
e33d66ec 6625The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6626characters needed for French, German, and Spanish. @value{GDBN} can use
6627this as its host character set.
6628
6629@item EBCDIC-US
6630@itemx IBM1047
6631@cindex EBCDIC character set
6632@cindex IBM1047 character set
6633Variants of the @sc{ebcdic} character set, used on some of IBM's
6634mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6635@value{GDBN} cannot use these as its host character set.
6636
6637@end table
6638
6639Note that these are all single-byte character sets. More work inside
6640GDB is needed to support multi-byte or variable-width character
6641encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6642
6643Here is an example of @value{GDBN}'s character set support in action.
6644Assume that the following source code has been placed in the file
6645@file{charset-test.c}:
6646
6647@smallexample
6648#include <stdio.h>
6649
6650char ascii_hello[]
6651 = @{72, 101, 108, 108, 111, 44, 32, 119,
6652 111, 114, 108, 100, 33, 10, 0@};
6653char ibm1047_hello[]
6654 = @{200, 133, 147, 147, 150, 107, 64, 166,
6655 150, 153, 147, 132, 90, 37, 0@};
6656
6657main ()
6658@{
6659 printf ("Hello, world!\n");
6660@}
10998722 6661@end smallexample
a0eb71c5
KB
6662
6663In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6664containing the string @samp{Hello, world!} followed by a newline,
6665encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6666
6667We compile the program, and invoke the debugger on it:
6668
6669@smallexample
6670$ gcc -g charset-test.c -o charset-test
6671$ gdb -nw charset-test
6672GNU gdb 2001-12-19-cvs
6673Copyright 2001 Free Software Foundation, Inc.
6674@dots{}
f7dc1244 6675(@value{GDBP})
10998722 6676@end smallexample
a0eb71c5
KB
6677
6678We can use the @code{show charset} command to see what character sets
6679@value{GDBN} is currently using to interpret and display characters and
6680strings:
6681
6682@smallexample
f7dc1244 6683(@value{GDBP}) show charset
e33d66ec 6684The current host and target character set is `ISO-8859-1'.
f7dc1244 6685(@value{GDBP})
10998722 6686@end smallexample
a0eb71c5
KB
6687
6688For the sake of printing this manual, let's use @sc{ascii} as our
6689initial character set:
6690@smallexample
f7dc1244
EZ
6691(@value{GDBP}) set charset ASCII
6692(@value{GDBP}) show charset
e33d66ec 6693The current host and target character set is `ASCII'.
f7dc1244 6694(@value{GDBP})
10998722 6695@end smallexample
a0eb71c5
KB
6696
6697Let's assume that @sc{ascii} is indeed the correct character set for our
6698host system --- in other words, let's assume that if @value{GDBN} prints
6699characters using the @sc{ascii} character set, our terminal will display
6700them properly. Since our current target character set is also
6701@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6702
6703@smallexample
f7dc1244 6704(@value{GDBP}) print ascii_hello
a0eb71c5 6705$1 = 0x401698 "Hello, world!\n"
f7dc1244 6706(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6707$2 = 72 'H'
f7dc1244 6708(@value{GDBP})
10998722 6709@end smallexample
a0eb71c5
KB
6710
6711@value{GDBN} uses the target character set for character and string
6712literals you use in expressions:
6713
6714@smallexample
f7dc1244 6715(@value{GDBP}) print '+'
a0eb71c5 6716$3 = 43 '+'
f7dc1244 6717(@value{GDBP})
10998722 6718@end smallexample
a0eb71c5
KB
6719
6720The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6721character.
6722
6723@value{GDBN} relies on the user to tell it which character set the
6724target program uses. If we print @code{ibm1047_hello} while our target
6725character set is still @sc{ascii}, we get jibberish:
6726
6727@smallexample
f7dc1244 6728(@value{GDBP}) print ibm1047_hello
a0eb71c5 6729$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 6730(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6731$5 = 200 '\310'
f7dc1244 6732(@value{GDBP})
10998722 6733@end smallexample
a0eb71c5 6734
e33d66ec 6735If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6736@value{GDBN} tells us the character sets it supports:
6737
6738@smallexample
f7dc1244 6739(@value{GDBP}) set target-charset
b383017d 6740ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 6741(@value{GDBP}) set target-charset
10998722 6742@end smallexample
a0eb71c5
KB
6743
6744We can select @sc{ibm1047} as our target character set, and examine the
6745program's strings again. Now the @sc{ascii} string is wrong, but
6746@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6747target character set, @sc{ibm1047}, to the host character set,
6748@sc{ascii}, and they display correctly:
6749
6750@smallexample
f7dc1244
EZ
6751(@value{GDBP}) set target-charset IBM1047
6752(@value{GDBP}) show charset
e33d66ec
EZ
6753The current host character set is `ASCII'.
6754The current target character set is `IBM1047'.
f7dc1244 6755(@value{GDBP}) print ascii_hello
a0eb71c5 6756$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 6757(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6758$7 = 72 '\110'
f7dc1244 6759(@value{GDBP}) print ibm1047_hello
a0eb71c5 6760$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 6761(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6762$9 = 200 'H'
f7dc1244 6763(@value{GDBP})
10998722 6764@end smallexample
a0eb71c5
KB
6765
6766As above, @value{GDBN} uses the target character set for character and
6767string literals you use in expressions:
6768
6769@smallexample
f7dc1244 6770(@value{GDBP}) print '+'
a0eb71c5 6771$10 = 78 '+'
f7dc1244 6772(@value{GDBP})
10998722 6773@end smallexample
a0eb71c5 6774
e33d66ec 6775The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6776character.
6777
09d4efe1
EZ
6778@node Caching Remote Data
6779@section Caching Data of Remote Targets
6780@cindex caching data of remote targets
6781
6782@value{GDBN} can cache data exchanged between the debugger and a
6783remote target (@pxref{Remote}). Such caching generally improves
6784performance, because it reduces the overhead of the remote protocol by
6785bundling memory reads and writes into large chunks. Unfortunately,
6786@value{GDBN} does not currently know anything about volatile
6787registers, and thus data caching will produce incorrect results when
6788volatile registers are in use.
6789
6790@table @code
6791@kindex set remotecache
6792@item set remotecache on
6793@itemx set remotecache off
6794Set caching state for remote targets. When @code{ON}, use data
6795caching. By default, this option is @code{OFF}.
6796
6797@kindex show remotecache
6798@item show remotecache
6799Show the current state of data caching for remote targets.
6800
6801@kindex info dcache
6802@item info dcache
6803Print the information about the data cache performance. The
6804information displayed includes: the dcache width and depth; and for
6805each cache line, how many times it was referenced, and its data and
6806state (dirty, bad, ok, etc.). This command is useful for debugging
6807the data cache operation.
6808@end table
6809
a0eb71c5 6810
e2e0bcd1
JB
6811@node Macros
6812@chapter C Preprocessor Macros
6813
49efadf5 6814Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
6815``preprocessor macros'' which expand into strings of tokens.
6816@value{GDBN} can evaluate expressions containing macro invocations, show
6817the result of macro expansion, and show a macro's definition, including
6818where it was defined.
6819
6820You may need to compile your program specially to provide @value{GDBN}
6821with information about preprocessor macros. Most compilers do not
6822include macros in their debugging information, even when you compile
6823with the @option{-g} flag. @xref{Compilation}.
6824
6825A program may define a macro at one point, remove that definition later,
6826and then provide a different definition after that. Thus, at different
6827points in the program, a macro may have different definitions, or have
6828no definition at all. If there is a current stack frame, @value{GDBN}
6829uses the macros in scope at that frame's source code line. Otherwise,
6830@value{GDBN} uses the macros in scope at the current listing location;
6831see @ref{List}.
6832
6833At the moment, @value{GDBN} does not support the @code{##}
6834token-splicing operator, the @code{#} stringification operator, or
6835variable-arity macros.
6836
6837Whenever @value{GDBN} evaluates an expression, it always expands any
6838macro invocations present in the expression. @value{GDBN} also provides
6839the following commands for working with macros explicitly.
6840
6841@table @code
6842
6843@kindex macro expand
6844@cindex macro expansion, showing the results of preprocessor
6845@cindex preprocessor macro expansion, showing the results of
6846@cindex expanding preprocessor macros
6847@item macro expand @var{expression}
6848@itemx macro exp @var{expression}
6849Show the results of expanding all preprocessor macro invocations in
6850@var{expression}. Since @value{GDBN} simply expands macros, but does
6851not parse the result, @var{expression} need not be a valid expression;
6852it can be any string of tokens.
6853
09d4efe1 6854@kindex macro exp1
e2e0bcd1
JB
6855@item macro expand-once @var{expression}
6856@itemx macro exp1 @var{expression}
4644b6e3 6857@cindex expand macro once
e2e0bcd1
JB
6858@i{(This command is not yet implemented.)} Show the results of
6859expanding those preprocessor macro invocations that appear explicitly in
6860@var{expression}. Macro invocations appearing in that expansion are
6861left unchanged. This command allows you to see the effect of a
6862particular macro more clearly, without being confused by further
6863expansions. Since @value{GDBN} simply expands macros, but does not
6864parse the result, @var{expression} need not be a valid expression; it
6865can be any string of tokens.
6866
475b0867 6867@kindex info macro
e2e0bcd1
JB
6868@cindex macro definition, showing
6869@cindex definition, showing a macro's
475b0867 6870@item info macro @var{macro}
e2e0bcd1
JB
6871Show the definition of the macro named @var{macro}, and describe the
6872source location where that definition was established.
6873
6874@kindex macro define
6875@cindex user-defined macros
6876@cindex defining macros interactively
6877@cindex macros, user-defined
6878@item macro define @var{macro} @var{replacement-list}
6879@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6880@i{(This command is not yet implemented.)} Introduce a definition for a
6881preprocessor macro named @var{macro}, invocations of which are replaced
6882by the tokens given in @var{replacement-list}. The first form of this
6883command defines an ``object-like'' macro, which takes no arguments; the
6884second form defines a ``function-like'' macro, which takes the arguments
6885given in @var{arglist}.
6886
6887A definition introduced by this command is in scope in every expression
6888evaluated in @value{GDBN}, until it is removed with the @command{macro
6889undef} command, described below. The definition overrides all
6890definitions for @var{macro} present in the program being debugged, as
6891well as any previous user-supplied definition.
6892
6893@kindex macro undef
6894@item macro undef @var{macro}
6895@i{(This command is not yet implemented.)} Remove any user-supplied
6896definition for the macro named @var{macro}. This command only affects
6897definitions provided with the @command{macro define} command, described
6898above; it cannot remove definitions present in the program being
6899debugged.
6900
09d4efe1
EZ
6901@kindex macro list
6902@item macro list
6903@i{(This command is not yet implemented.)} List all the macros
6904defined using the @code{macro define} command.
e2e0bcd1
JB
6905@end table
6906
6907@cindex macros, example of debugging with
6908Here is a transcript showing the above commands in action. First, we
6909show our source files:
6910
6911@smallexample
6912$ cat sample.c
6913#include <stdio.h>
6914#include "sample.h"
6915
6916#define M 42
6917#define ADD(x) (M + x)
6918
6919main ()
6920@{
6921#define N 28
6922 printf ("Hello, world!\n");
6923#undef N
6924 printf ("We're so creative.\n");
6925#define N 1729
6926 printf ("Goodbye, world!\n");
6927@}
6928$ cat sample.h
6929#define Q <
6930$
6931@end smallexample
6932
6933Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6934We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6935compiler includes information about preprocessor macros in the debugging
6936information.
6937
6938@smallexample
6939$ gcc -gdwarf-2 -g3 sample.c -o sample
6940$
6941@end smallexample
6942
6943Now, we start @value{GDBN} on our sample program:
6944
6945@smallexample
6946$ gdb -nw sample
6947GNU gdb 2002-05-06-cvs
6948Copyright 2002 Free Software Foundation, Inc.
6949GDB is free software, @dots{}
f7dc1244 6950(@value{GDBP})
e2e0bcd1
JB
6951@end smallexample
6952
6953We can expand macros and examine their definitions, even when the
6954program is not running. @value{GDBN} uses the current listing position
6955to decide which macro definitions are in scope:
6956
6957@smallexample
f7dc1244 6958(@value{GDBP}) list main
e2e0bcd1
JB
69593
69604 #define M 42
69615 #define ADD(x) (M + x)
69626
69637 main ()
69648 @{
69659 #define N 28
696610 printf ("Hello, world!\n");
696711 #undef N
696812 printf ("We're so creative.\n");
f7dc1244 6969(@value{GDBP}) info macro ADD
e2e0bcd1
JB
6970Defined at /home/jimb/gdb/macros/play/sample.c:5
6971#define ADD(x) (M + x)
f7dc1244 6972(@value{GDBP}) info macro Q
e2e0bcd1
JB
6973Defined at /home/jimb/gdb/macros/play/sample.h:1
6974 included at /home/jimb/gdb/macros/play/sample.c:2
6975#define Q <
f7dc1244 6976(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 6977expands to: (42 + 1)
f7dc1244 6978(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 6979expands to: once (M + 1)
f7dc1244 6980(@value{GDBP})
e2e0bcd1
JB
6981@end smallexample
6982
6983In the example above, note that @command{macro expand-once} expands only
6984the macro invocation explicit in the original text --- the invocation of
6985@code{ADD} --- but does not expand the invocation of the macro @code{M},
6986which was introduced by @code{ADD}.
6987
6988Once the program is running, GDB uses the macro definitions in force at
6989the source line of the current stack frame:
6990
6991@smallexample
f7dc1244 6992(@value{GDBP}) break main
e2e0bcd1 6993Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 6994(@value{GDBP}) run
b383017d 6995Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
6996
6997Breakpoint 1, main () at sample.c:10
699810 printf ("Hello, world!\n");
f7dc1244 6999(@value{GDBP})
e2e0bcd1
JB
7000@end smallexample
7001
7002At line 10, the definition of the macro @code{N} at line 9 is in force:
7003
7004@smallexample
f7dc1244 7005(@value{GDBP}) info macro N
e2e0bcd1
JB
7006Defined at /home/jimb/gdb/macros/play/sample.c:9
7007#define N 28
f7dc1244 7008(@value{GDBP}) macro expand N Q M
e2e0bcd1 7009expands to: 28 < 42
f7dc1244 7010(@value{GDBP}) print N Q M
e2e0bcd1 7011$1 = 1
f7dc1244 7012(@value{GDBP})
e2e0bcd1
JB
7013@end smallexample
7014
7015As we step over directives that remove @code{N}'s definition, and then
7016give it a new definition, @value{GDBN} finds the definition (or lack
7017thereof) in force at each point:
7018
7019@smallexample
f7dc1244 7020(@value{GDBP}) next
e2e0bcd1
JB
7021Hello, world!
702212 printf ("We're so creative.\n");
f7dc1244 7023(@value{GDBP}) info macro N
e2e0bcd1
JB
7024The symbol `N' has no definition as a C/C++ preprocessor macro
7025at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 7026(@value{GDBP}) next
e2e0bcd1
JB
7027We're so creative.
702814 printf ("Goodbye, world!\n");
f7dc1244 7029(@value{GDBP}) info macro N
e2e0bcd1
JB
7030Defined at /home/jimb/gdb/macros/play/sample.c:13
7031#define N 1729
f7dc1244 7032(@value{GDBP}) macro expand N Q M
e2e0bcd1 7033expands to: 1729 < 42
f7dc1244 7034(@value{GDBP}) print N Q M
e2e0bcd1 7035$2 = 0
f7dc1244 7036(@value{GDBP})
e2e0bcd1
JB
7037@end smallexample
7038
7039
b37052ae
EZ
7040@node Tracepoints
7041@chapter Tracepoints
7042@c This chapter is based on the documentation written by Michael
7043@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
7044
7045@cindex tracepoints
7046In some applications, it is not feasible for the debugger to interrupt
7047the program's execution long enough for the developer to learn
7048anything helpful about its behavior. If the program's correctness
7049depends on its real-time behavior, delays introduced by a debugger
7050might cause the program to change its behavior drastically, or perhaps
7051fail, even when the code itself is correct. It is useful to be able
7052to observe the program's behavior without interrupting it.
7053
7054Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
7055specify locations in the program, called @dfn{tracepoints}, and
7056arbitrary expressions to evaluate when those tracepoints are reached.
7057Later, using the @code{tfind} command, you can examine the values
7058those expressions had when the program hit the tracepoints. The
7059expressions may also denote objects in memory---structures or arrays,
7060for example---whose values @value{GDBN} should record; while visiting
7061a particular tracepoint, you may inspect those objects as if they were
7062in memory at that moment. However, because @value{GDBN} records these
7063values without interacting with you, it can do so quickly and
7064unobtrusively, hopefully not disturbing the program's behavior.
7065
7066The tracepoint facility is currently available only for remote
2c0069bb
EZ
7067targets. @xref{Targets}. In addition, your remote target must know how
7068to collect trace data. This functionality is implemented in the remote
7069stub; however, none of the stubs distributed with @value{GDBN} support
7070tracepoints as of this writing.
b37052ae
EZ
7071
7072This chapter describes the tracepoint commands and features.
7073
7074@menu
b383017d
RM
7075* Set Tracepoints::
7076* Analyze Collected Data::
7077* Tracepoint Variables::
b37052ae
EZ
7078@end menu
7079
7080@node Set Tracepoints
7081@section Commands to Set Tracepoints
7082
7083Before running such a @dfn{trace experiment}, an arbitrary number of
7084tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
7085tracepoint has a number assigned to it by @value{GDBN}. Like with
7086breakpoints, tracepoint numbers are successive integers starting from
7087one. Many of the commands associated with tracepoints take the
7088tracepoint number as their argument, to identify which tracepoint to
7089work on.
7090
7091For each tracepoint, you can specify, in advance, some arbitrary set
7092of data that you want the target to collect in the trace buffer when
7093it hits that tracepoint. The collected data can include registers,
7094local variables, or global data. Later, you can use @value{GDBN}
7095commands to examine the values these data had at the time the
7096tracepoint was hit.
7097
7098This section describes commands to set tracepoints and associated
7099conditions and actions.
7100
7101@menu
b383017d
RM
7102* Create and Delete Tracepoints::
7103* Enable and Disable Tracepoints::
7104* Tracepoint Passcounts::
7105* Tracepoint Actions::
7106* Listing Tracepoints::
7107* Starting and Stopping Trace Experiment::
b37052ae
EZ
7108@end menu
7109
7110@node Create and Delete Tracepoints
7111@subsection Create and Delete Tracepoints
7112
7113@table @code
7114@cindex set tracepoint
7115@kindex trace
7116@item trace
7117The @code{trace} command is very similar to the @code{break} command.
7118Its argument can be a source line, a function name, or an address in
7119the target program. @xref{Set Breaks}. The @code{trace} command
7120defines a tracepoint, which is a point in the target program where the
7121debugger will briefly stop, collect some data, and then allow the
7122program to continue. Setting a tracepoint or changing its commands
7123doesn't take effect until the next @code{tstart} command; thus, you
7124cannot change the tracepoint attributes once a trace experiment is
7125running.
7126
7127Here are some examples of using the @code{trace} command:
7128
7129@smallexample
7130(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
7131
7132(@value{GDBP}) @b{trace +2} // 2 lines forward
7133
7134(@value{GDBP}) @b{trace my_function} // first source line of function
7135
7136(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
7137
7138(@value{GDBP}) @b{trace *0x2117c4} // an address
7139@end smallexample
7140
7141@noindent
7142You can abbreviate @code{trace} as @code{tr}.
7143
7144@vindex $tpnum
7145@cindex last tracepoint number
7146@cindex recent tracepoint number
7147@cindex tracepoint number
7148The convenience variable @code{$tpnum} records the tracepoint number
7149of the most recently set tracepoint.
7150
7151@kindex delete tracepoint
7152@cindex tracepoint deletion
7153@item delete tracepoint @r{[}@var{num}@r{]}
7154Permanently delete one or more tracepoints. With no argument, the
7155default is to delete all tracepoints.
7156
7157Examples:
7158
7159@smallexample
7160(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7161
7162(@value{GDBP}) @b{delete trace} // remove all tracepoints
7163@end smallexample
7164
7165@noindent
7166You can abbreviate this command as @code{del tr}.
7167@end table
7168
7169@node Enable and Disable Tracepoints
7170@subsection Enable and Disable Tracepoints
7171
7172@table @code
7173@kindex disable tracepoint
7174@item disable tracepoint @r{[}@var{num}@r{]}
7175Disable tracepoint @var{num}, or all tracepoints if no argument
7176@var{num} is given. A disabled tracepoint will have no effect during
7177the next trace experiment, but it is not forgotten. You can re-enable
7178a disabled tracepoint using the @code{enable tracepoint} command.
7179
7180@kindex enable tracepoint
7181@item enable tracepoint @r{[}@var{num}@r{]}
7182Enable tracepoint @var{num}, or all tracepoints. The enabled
7183tracepoints will become effective the next time a trace experiment is
7184run.
7185@end table
7186
7187@node Tracepoint Passcounts
7188@subsection Tracepoint Passcounts
7189
7190@table @code
7191@kindex passcount
7192@cindex tracepoint pass count
7193@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7194Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7195automatically stop a trace experiment. If a tracepoint's passcount is
7196@var{n}, then the trace experiment will be automatically stopped on
7197the @var{n}'th time that tracepoint is hit. If the tracepoint number
7198@var{num} is not specified, the @code{passcount} command sets the
7199passcount of the most recently defined tracepoint. If no passcount is
7200given, the trace experiment will run until stopped explicitly by the
7201user.
7202
7203Examples:
7204
7205@smallexample
b383017d 7206(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 7207@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
7208
7209(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 7210@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
7211(@value{GDBP}) @b{trace foo}
7212(@value{GDBP}) @b{pass 3}
7213(@value{GDBP}) @b{trace bar}
7214(@value{GDBP}) @b{pass 2}
7215(@value{GDBP}) @b{trace baz}
7216(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
7217@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7218@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7219@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
7220@end smallexample
7221@end table
7222
7223@node Tracepoint Actions
7224@subsection Tracepoint Action Lists
7225
7226@table @code
7227@kindex actions
7228@cindex tracepoint actions
7229@item actions @r{[}@var{num}@r{]}
7230This command will prompt for a list of actions to be taken when the
7231tracepoint is hit. If the tracepoint number @var{num} is not
7232specified, this command sets the actions for the one that was most
7233recently defined (so that you can define a tracepoint and then say
7234@code{actions} without bothering about its number). You specify the
7235actions themselves on the following lines, one action at a time, and
7236terminate the actions list with a line containing just @code{end}. So
7237far, the only defined actions are @code{collect} and
7238@code{while-stepping}.
7239
7240@cindex remove actions from a tracepoint
7241To remove all actions from a tracepoint, type @samp{actions @var{num}}
7242and follow it immediately with @samp{end}.
7243
7244@smallexample
7245(@value{GDBP}) @b{collect @var{data}} // collect some data
7246
6826cf00 7247(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 7248
6826cf00 7249(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
7250@end smallexample
7251
7252In the following example, the action list begins with @code{collect}
7253commands indicating the things to be collected when the tracepoint is
7254hit. Then, in order to single-step and collect additional data
7255following the tracepoint, a @code{while-stepping} command is used,
7256followed by the list of things to be collected while stepping. The
7257@code{while-stepping} command is terminated by its own separate
7258@code{end} command. Lastly, the action list is terminated by an
7259@code{end} command.
7260
7261@smallexample
7262(@value{GDBP}) @b{trace foo}
7263(@value{GDBP}) @b{actions}
7264Enter actions for tracepoint 1, one per line:
7265> collect bar,baz
7266> collect $regs
7267> while-stepping 12
7268 > collect $fp, $sp
7269 > end
7270end
7271@end smallexample
7272
7273@kindex collect @r{(tracepoints)}
7274@item collect @var{expr1}, @var{expr2}, @dots{}
7275Collect values of the given expressions when the tracepoint is hit.
7276This command accepts a comma-separated list of any valid expressions.
7277In addition to global, static, or local variables, the following
7278special arguments are supported:
7279
7280@table @code
7281@item $regs
7282collect all registers
7283
7284@item $args
7285collect all function arguments
7286
7287@item $locals
7288collect all local variables.
7289@end table
7290
7291You can give several consecutive @code{collect} commands, each one
7292with a single argument, or one @code{collect} command with several
7293arguments separated by commas: the effect is the same.
7294
f5c37c66
EZ
7295The command @code{info scope} (@pxref{Symbols, info scope}) is
7296particularly useful for figuring out what data to collect.
7297
b37052ae
EZ
7298@kindex while-stepping @r{(tracepoints)}
7299@item while-stepping @var{n}
7300Perform @var{n} single-step traces after the tracepoint, collecting
7301new data at each step. The @code{while-stepping} command is
7302followed by the list of what to collect while stepping (followed by
7303its own @code{end} command):
7304
7305@smallexample
7306> while-stepping 12
7307 > collect $regs, myglobal
7308 > end
7309>
7310@end smallexample
7311
7312@noindent
7313You may abbreviate @code{while-stepping} as @code{ws} or
7314@code{stepping}.
7315@end table
7316
7317@node Listing Tracepoints
7318@subsection Listing Tracepoints
7319
7320@table @code
7321@kindex info tracepoints
09d4efe1 7322@kindex info tp
b37052ae
EZ
7323@cindex information about tracepoints
7324@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 7325Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 7326a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
7327defined so far. For each tracepoint, the following information is
7328shown:
7329
7330@itemize @bullet
7331@item
7332its number
7333@item
7334whether it is enabled or disabled
7335@item
7336its address
7337@item
7338its passcount as given by the @code{passcount @var{n}} command
7339@item
7340its step count as given by the @code{while-stepping @var{n}} command
7341@item
7342where in the source files is the tracepoint set
7343@item
7344its action list as given by the @code{actions} command
7345@end itemize
7346
7347@smallexample
7348(@value{GDBP}) @b{info trace}
7349Num Enb Address PassC StepC What
73501 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
73512 y 0x0020dc64 0 0 in g_test at g_test.c:1375
73523 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
7353(@value{GDBP})
7354@end smallexample
7355
7356@noindent
7357This command can be abbreviated @code{info tp}.
7358@end table
7359
7360@node Starting and Stopping Trace Experiment
7361@subsection Starting and Stopping Trace Experiment
7362
7363@table @code
7364@kindex tstart
7365@cindex start a new trace experiment
7366@cindex collected data discarded
7367@item tstart
7368This command takes no arguments. It starts the trace experiment, and
7369begins collecting data. This has the side effect of discarding all
7370the data collected in the trace buffer during the previous trace
7371experiment.
7372
7373@kindex tstop
7374@cindex stop a running trace experiment
7375@item tstop
7376This command takes no arguments. It ends the trace experiment, and
7377stops collecting data.
7378
68c71a2e 7379@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
7380automatically if any tracepoint's passcount is reached
7381(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7382
7383@kindex tstatus
7384@cindex status of trace data collection
7385@cindex trace experiment, status of
7386@item tstatus
7387This command displays the status of the current trace data
7388collection.
7389@end table
7390
7391Here is an example of the commands we described so far:
7392
7393@smallexample
7394(@value{GDBP}) @b{trace gdb_c_test}
7395(@value{GDBP}) @b{actions}
7396Enter actions for tracepoint #1, one per line.
7397> collect $regs,$locals,$args
7398> while-stepping 11
7399 > collect $regs
7400 > end
7401> end
7402(@value{GDBP}) @b{tstart}
7403 [time passes @dots{}]
7404(@value{GDBP}) @b{tstop}
7405@end smallexample
7406
7407
7408@node Analyze Collected Data
7409@section Using the collected data
7410
7411After the tracepoint experiment ends, you use @value{GDBN} commands
7412for examining the trace data. The basic idea is that each tracepoint
7413collects a trace @dfn{snapshot} every time it is hit and another
7414snapshot every time it single-steps. All these snapshots are
7415consecutively numbered from zero and go into a buffer, and you can
7416examine them later. The way you examine them is to @dfn{focus} on a
7417specific trace snapshot. When the remote stub is focused on a trace
7418snapshot, it will respond to all @value{GDBN} requests for memory and
7419registers by reading from the buffer which belongs to that snapshot,
7420rather than from @emph{real} memory or registers of the program being
7421debugged. This means that @strong{all} @value{GDBN} commands
7422(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7423behave as if we were currently debugging the program state as it was
7424when the tracepoint occurred. Any requests for data that are not in
7425the buffer will fail.
7426
7427@menu
7428* tfind:: How to select a trace snapshot
7429* tdump:: How to display all data for a snapshot
7430* save-tracepoints:: How to save tracepoints for a future run
7431@end menu
7432
7433@node tfind
7434@subsection @code{tfind @var{n}}
7435
7436@kindex tfind
7437@cindex select trace snapshot
7438@cindex find trace snapshot
7439The basic command for selecting a trace snapshot from the buffer is
7440@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7441counting from zero. If no argument @var{n} is given, the next
7442snapshot is selected.
7443
7444Here are the various forms of using the @code{tfind} command.
7445
7446@table @code
7447@item tfind start
7448Find the first snapshot in the buffer. This is a synonym for
7449@code{tfind 0} (since 0 is the number of the first snapshot).
7450
7451@item tfind none
7452Stop debugging trace snapshots, resume @emph{live} debugging.
7453
7454@item tfind end
7455Same as @samp{tfind none}.
7456
7457@item tfind
7458No argument means find the next trace snapshot.
7459
7460@item tfind -
7461Find the previous trace snapshot before the current one. This permits
7462retracing earlier steps.
7463
7464@item tfind tracepoint @var{num}
7465Find the next snapshot associated with tracepoint @var{num}. Search
7466proceeds forward from the last examined trace snapshot. If no
7467argument @var{num} is given, it means find the next snapshot collected
7468for the same tracepoint as the current snapshot.
7469
7470@item tfind pc @var{addr}
7471Find the next snapshot associated with the value @var{addr} of the
7472program counter. Search proceeds forward from the last examined trace
7473snapshot. If no argument @var{addr} is given, it means find the next
7474snapshot with the same value of PC as the current snapshot.
7475
7476@item tfind outside @var{addr1}, @var{addr2}
7477Find the next snapshot whose PC is outside the given range of
7478addresses.
7479
7480@item tfind range @var{addr1}, @var{addr2}
7481Find the next snapshot whose PC is between @var{addr1} and
7482@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7483
7484@item tfind line @r{[}@var{file}:@r{]}@var{n}
7485Find the next snapshot associated with the source line @var{n}. If
7486the optional argument @var{file} is given, refer to line @var{n} in
7487that source file. Search proceeds forward from the last examined
7488trace snapshot. If no argument @var{n} is given, it means find the
7489next line other than the one currently being examined; thus saying
7490@code{tfind line} repeatedly can appear to have the same effect as
7491stepping from line to line in a @emph{live} debugging session.
7492@end table
7493
7494The default arguments for the @code{tfind} commands are specifically
7495designed to make it easy to scan through the trace buffer. For
7496instance, @code{tfind} with no argument selects the next trace
7497snapshot, and @code{tfind -} with no argument selects the previous
7498trace snapshot. So, by giving one @code{tfind} command, and then
7499simply hitting @key{RET} repeatedly you can examine all the trace
7500snapshots in order. Or, by saying @code{tfind -} and then hitting
7501@key{RET} repeatedly you can examine the snapshots in reverse order.
7502The @code{tfind line} command with no argument selects the snapshot
7503for the next source line executed. The @code{tfind pc} command with
7504no argument selects the next snapshot with the same program counter
7505(PC) as the current frame. The @code{tfind tracepoint} command with
7506no argument selects the next trace snapshot collected by the same
7507tracepoint as the current one.
7508
7509In addition to letting you scan through the trace buffer manually,
7510these commands make it easy to construct @value{GDBN} scripts that
7511scan through the trace buffer and print out whatever collected data
7512you are interested in. Thus, if we want to examine the PC, FP, and SP
7513registers from each trace frame in the buffer, we can say this:
7514
7515@smallexample
7516(@value{GDBP}) @b{tfind start}
7517(@value{GDBP}) @b{while ($trace_frame != -1)}
7518> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7519 $trace_frame, $pc, $sp, $fp
7520> tfind
7521> end
7522
7523Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7524Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7525Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7526Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7527Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7528Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7529Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7530Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7531Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7532Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7533Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7534@end smallexample
7535
7536Or, if we want to examine the variable @code{X} at each source line in
7537the buffer:
7538
7539@smallexample
7540(@value{GDBP}) @b{tfind start}
7541(@value{GDBP}) @b{while ($trace_frame != -1)}
7542> printf "Frame %d, X == %d\n", $trace_frame, X
7543> tfind line
7544> end
7545
7546Frame 0, X = 1
7547Frame 7, X = 2
7548Frame 13, X = 255
7549@end smallexample
7550
7551@node tdump
7552@subsection @code{tdump}
7553@kindex tdump
7554@cindex dump all data collected at tracepoint
7555@cindex tracepoint data, display
7556
7557This command takes no arguments. It prints all the data collected at
7558the current trace snapshot.
7559
7560@smallexample
7561(@value{GDBP}) @b{trace 444}
7562(@value{GDBP}) @b{actions}
7563Enter actions for tracepoint #2, one per line:
7564> collect $regs, $locals, $args, gdb_long_test
7565> end
7566
7567(@value{GDBP}) @b{tstart}
7568
7569(@value{GDBP}) @b{tfind line 444}
7570#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7571at gdb_test.c:444
7572444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7573
7574(@value{GDBP}) @b{tdump}
7575Data collected at tracepoint 2, trace frame 1:
7576d0 0xc4aa0085 -995491707
7577d1 0x18 24
7578d2 0x80 128
7579d3 0x33 51
7580d4 0x71aea3d 119204413
7581d5 0x22 34
7582d6 0xe0 224
7583d7 0x380035 3670069
7584a0 0x19e24a 1696330
7585a1 0x3000668 50333288
7586a2 0x100 256
7587a3 0x322000 3284992
7588a4 0x3000698 50333336
7589a5 0x1ad3cc 1758156
7590fp 0x30bf3c 0x30bf3c
7591sp 0x30bf34 0x30bf34
7592ps 0x0 0
7593pc 0x20b2c8 0x20b2c8
7594fpcontrol 0x0 0
7595fpstatus 0x0 0
7596fpiaddr 0x0 0
7597p = 0x20e5b4 "gdb-test"
7598p1 = (void *) 0x11
7599p2 = (void *) 0x22
7600p3 = (void *) 0x33
7601p4 = (void *) 0x44
7602p5 = (void *) 0x55
7603p6 = (void *) 0x66
7604gdb_long_test = 17 '\021'
7605
7606(@value{GDBP})
7607@end smallexample
7608
7609@node save-tracepoints
7610@subsection @code{save-tracepoints @var{filename}}
7611@kindex save-tracepoints
7612@cindex save tracepoints for future sessions
7613
7614This command saves all current tracepoint definitions together with
7615their actions and passcounts, into a file @file{@var{filename}}
7616suitable for use in a later debugging session. To read the saved
7617tracepoint definitions, use the @code{source} command (@pxref{Command
7618Files}).
7619
7620@node Tracepoint Variables
7621@section Convenience Variables for Tracepoints
7622@cindex tracepoint variables
7623@cindex convenience variables for tracepoints
7624
7625@table @code
7626@vindex $trace_frame
7627@item (int) $trace_frame
7628The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7629snapshot is selected.
7630
7631@vindex $tracepoint
7632@item (int) $tracepoint
7633The tracepoint for the current trace snapshot.
7634
7635@vindex $trace_line
7636@item (int) $trace_line
7637The line number for the current trace snapshot.
7638
7639@vindex $trace_file
7640@item (char []) $trace_file
7641The source file for the current trace snapshot.
7642
7643@vindex $trace_func
7644@item (char []) $trace_func
7645The name of the function containing @code{$tracepoint}.
7646@end table
7647
7648Note: @code{$trace_file} is not suitable for use in @code{printf},
7649use @code{output} instead.
7650
7651Here's a simple example of using these convenience variables for
7652stepping through all the trace snapshots and printing some of their
7653data.
7654
7655@smallexample
7656(@value{GDBP}) @b{tfind start}
7657
7658(@value{GDBP}) @b{while $trace_frame != -1}
7659> output $trace_file
7660> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7661> tfind
7662> end
7663@end smallexample
7664
df0cd8c5
JB
7665@node Overlays
7666@chapter Debugging Programs That Use Overlays
7667@cindex overlays
7668
7669If your program is too large to fit completely in your target system's
7670memory, you can sometimes use @dfn{overlays} to work around this
7671problem. @value{GDBN} provides some support for debugging programs that
7672use overlays.
7673
7674@menu
7675* How Overlays Work:: A general explanation of overlays.
7676* Overlay Commands:: Managing overlays in @value{GDBN}.
7677* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7678 mapped by asking the inferior.
7679* Overlay Sample Program:: A sample program using overlays.
7680@end menu
7681
7682@node How Overlays Work
7683@section How Overlays Work
7684@cindex mapped overlays
7685@cindex unmapped overlays
7686@cindex load address, overlay's
7687@cindex mapped address
7688@cindex overlay area
7689
7690Suppose you have a computer whose instruction address space is only 64
7691kilobytes long, but which has much more memory which can be accessed by
7692other means: special instructions, segment registers, or memory
7693management hardware, for example. Suppose further that you want to
7694adapt a program which is larger than 64 kilobytes to run on this system.
7695
7696One solution is to identify modules of your program which are relatively
7697independent, and need not call each other directly; call these modules
7698@dfn{overlays}. Separate the overlays from the main program, and place
7699their machine code in the larger memory. Place your main program in
7700instruction memory, but leave at least enough space there to hold the
7701largest overlay as well.
7702
7703Now, to call a function located in an overlay, you must first copy that
7704overlay's machine code from the large memory into the space set aside
7705for it in the instruction memory, and then jump to its entry point
7706there.
7707
c928edc0
AC
7708@c NB: In the below the mapped area's size is greater or equal to the
7709@c size of all overlays. This is intentional to remind the developer
7710@c that overlays don't necessarily need to be the same size.
7711
474c8240 7712@smallexample
df0cd8c5 7713@group
c928edc0
AC
7714 Data Instruction Larger
7715Address Space Address Space Address Space
7716+-----------+ +-----------+ +-----------+
7717| | | | | |
7718+-----------+ +-----------+ +-----------+<-- overlay 1
7719| program | | main | .----| overlay 1 | load address
7720| variables | | program | | +-----------+
7721| and heap | | | | | |
7722+-----------+ | | | +-----------+<-- overlay 2
7723| | +-----------+ | | | load address
7724+-----------+ | | | .-| overlay 2 |
7725 | | | | | |
7726 mapped --->+-----------+ | | +-----------+
7727 address | | | | | |
7728 | overlay | <-' | | |
7729 | area | <---' +-----------+<-- overlay 3
7730 | | <---. | | load address
7731 +-----------+ `--| overlay 3 |
7732 | | | |
7733 +-----------+ | |
7734 +-----------+
7735 | |
7736 +-----------+
7737
7738 @anchor{A code overlay}A code overlay
df0cd8c5 7739@end group
474c8240 7740@end smallexample
df0cd8c5 7741
c928edc0
AC
7742The diagram (@pxref{A code overlay}) shows a system with separate data
7743and instruction address spaces. To map an overlay, the program copies
7744its code from the larger address space to the instruction address space.
7745Since the overlays shown here all use the same mapped address, only one
7746may be mapped at a time. For a system with a single address space for
7747data and instructions, the diagram would be similar, except that the
7748program variables and heap would share an address space with the main
7749program and the overlay area.
df0cd8c5
JB
7750
7751An overlay loaded into instruction memory and ready for use is called a
7752@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7753instruction memory. An overlay not present (or only partially present)
7754in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7755is its address in the larger memory. The mapped address is also called
7756the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7757called the @dfn{load memory address}, or @dfn{LMA}.
7758
7759Unfortunately, overlays are not a completely transparent way to adapt a
7760program to limited instruction memory. They introduce a new set of
7761global constraints you must keep in mind as you design your program:
7762
7763@itemize @bullet
7764
7765@item
7766Before calling or returning to a function in an overlay, your program
7767must make sure that overlay is actually mapped. Otherwise, the call or
7768return will transfer control to the right address, but in the wrong
7769overlay, and your program will probably crash.
7770
7771@item
7772If the process of mapping an overlay is expensive on your system, you
7773will need to choose your overlays carefully to minimize their effect on
7774your program's performance.
7775
7776@item
7777The executable file you load onto your system must contain each
7778overlay's instructions, appearing at the overlay's load address, not its
7779mapped address. However, each overlay's instructions must be relocated
7780and its symbols defined as if the overlay were at its mapped address.
7781You can use GNU linker scripts to specify different load and relocation
7782addresses for pieces of your program; see @ref{Overlay Description,,,
7783ld.info, Using ld: the GNU linker}.
7784
7785@item
7786The procedure for loading executable files onto your system must be able
7787to load their contents into the larger address space as well as the
7788instruction and data spaces.
7789
7790@end itemize
7791
7792The overlay system described above is rather simple, and could be
7793improved in many ways:
7794
7795@itemize @bullet
7796
7797@item
7798If your system has suitable bank switch registers or memory management
7799hardware, you could use those facilities to make an overlay's load area
7800contents simply appear at their mapped address in instruction space.
7801This would probably be faster than copying the overlay to its mapped
7802area in the usual way.
7803
7804@item
7805If your overlays are small enough, you could set aside more than one
7806overlay area, and have more than one overlay mapped at a time.
7807
7808@item
7809You can use overlays to manage data, as well as instructions. In
7810general, data overlays are even less transparent to your design than
7811code overlays: whereas code overlays only require care when you call or
7812return to functions, data overlays require care every time you access
7813the data. Also, if you change the contents of a data overlay, you
7814must copy its contents back out to its load address before you can copy a
7815different data overlay into the same mapped area.
7816
7817@end itemize
7818
7819
7820@node Overlay Commands
7821@section Overlay Commands
7822
7823To use @value{GDBN}'s overlay support, each overlay in your program must
7824correspond to a separate section of the executable file. The section's
7825virtual memory address and load memory address must be the overlay's
7826mapped and load addresses. Identifying overlays with sections allows
7827@value{GDBN} to determine the appropriate address of a function or
7828variable, depending on whether the overlay is mapped or not.
7829
7830@value{GDBN}'s overlay commands all start with the word @code{overlay};
7831you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7832
7833@table @code
7834@item overlay off
4644b6e3 7835@kindex overlay
df0cd8c5
JB
7836Disable @value{GDBN}'s overlay support. When overlay support is
7837disabled, @value{GDBN} assumes that all functions and variables are
7838always present at their mapped addresses. By default, @value{GDBN}'s
7839overlay support is disabled.
7840
7841@item overlay manual
df0cd8c5
JB
7842@cindex manual overlay debugging
7843Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7844relies on you to tell it which overlays are mapped, and which are not,
7845using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7846commands described below.
7847
7848@item overlay map-overlay @var{overlay}
7849@itemx overlay map @var{overlay}
df0cd8c5
JB
7850@cindex map an overlay
7851Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7852be the name of the object file section containing the overlay. When an
7853overlay is mapped, @value{GDBN} assumes it can find the overlay's
7854functions and variables at their mapped addresses. @value{GDBN} assumes
7855that any other overlays whose mapped ranges overlap that of
7856@var{overlay} are now unmapped.
7857
7858@item overlay unmap-overlay @var{overlay}
7859@itemx overlay unmap @var{overlay}
df0cd8c5
JB
7860@cindex unmap an overlay
7861Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7862must be the name of the object file section containing the overlay.
7863When an overlay is unmapped, @value{GDBN} assumes it can find the
7864overlay's functions and variables at their load addresses.
7865
7866@item overlay auto
df0cd8c5
JB
7867Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7868consults a data structure the overlay manager maintains in the inferior
7869to see which overlays are mapped. For details, see @ref{Automatic
7870Overlay Debugging}.
7871
7872@item overlay load-target
7873@itemx overlay load
df0cd8c5
JB
7874@cindex reloading the overlay table
7875Re-read the overlay table from the inferior. Normally, @value{GDBN}
7876re-reads the table @value{GDBN} automatically each time the inferior
7877stops, so this command should only be necessary if you have changed the
7878overlay mapping yourself using @value{GDBN}. This command is only
7879useful when using automatic overlay debugging.
7880
7881@item overlay list-overlays
7882@itemx overlay list
7883@cindex listing mapped overlays
7884Display a list of the overlays currently mapped, along with their mapped
7885addresses, load addresses, and sizes.
7886
7887@end table
7888
7889Normally, when @value{GDBN} prints a code address, it includes the name
7890of the function the address falls in:
7891
474c8240 7892@smallexample
f7dc1244 7893(@value{GDBP}) print main
df0cd8c5 7894$3 = @{int ()@} 0x11a0 <main>
474c8240 7895@end smallexample
df0cd8c5
JB
7896@noindent
7897When overlay debugging is enabled, @value{GDBN} recognizes code in
7898unmapped overlays, and prints the names of unmapped functions with
7899asterisks around them. For example, if @code{foo} is a function in an
7900unmapped overlay, @value{GDBN} prints it this way:
7901
474c8240 7902@smallexample
f7dc1244 7903(@value{GDBP}) overlay list
df0cd8c5 7904No sections are mapped.
f7dc1244 7905(@value{GDBP}) print foo
df0cd8c5 7906$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7907@end smallexample
df0cd8c5
JB
7908@noindent
7909When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7910name normally:
7911
474c8240 7912@smallexample
f7dc1244 7913(@value{GDBP}) overlay list
b383017d 7914Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 7915 mapped at 0x1016 - 0x104a
f7dc1244 7916(@value{GDBP}) print foo
df0cd8c5 7917$6 = @{int (int)@} 0x1016 <foo>
474c8240 7918@end smallexample
df0cd8c5
JB
7919
7920When overlay debugging is enabled, @value{GDBN} can find the correct
7921address for functions and variables in an overlay, whether or not the
7922overlay is mapped. This allows most @value{GDBN} commands, like
7923@code{break} and @code{disassemble}, to work normally, even on unmapped
7924code. However, @value{GDBN}'s breakpoint support has some limitations:
7925
7926@itemize @bullet
7927@item
7928@cindex breakpoints in overlays
7929@cindex overlays, setting breakpoints in
7930You can set breakpoints in functions in unmapped overlays, as long as
7931@value{GDBN} can write to the overlay at its load address.
7932@item
7933@value{GDBN} can not set hardware or simulator-based breakpoints in
7934unmapped overlays. However, if you set a breakpoint at the end of your
7935overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7936you are using manual overlay management), @value{GDBN} will re-set its
7937breakpoints properly.
7938@end itemize
7939
7940
7941@node Automatic Overlay Debugging
7942@section Automatic Overlay Debugging
7943@cindex automatic overlay debugging
7944
7945@value{GDBN} can automatically track which overlays are mapped and which
7946are not, given some simple co-operation from the overlay manager in the
7947inferior. If you enable automatic overlay debugging with the
7948@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7949looks in the inferior's memory for certain variables describing the
7950current state of the overlays.
7951
7952Here are the variables your overlay manager must define to support
7953@value{GDBN}'s automatic overlay debugging:
7954
7955@table @asis
7956
7957@item @code{_ovly_table}:
7958This variable must be an array of the following structures:
7959
474c8240 7960@smallexample
df0cd8c5
JB
7961struct
7962@{
7963 /* The overlay's mapped address. */
7964 unsigned long vma;
7965
7966 /* The size of the overlay, in bytes. */
7967 unsigned long size;
7968
7969 /* The overlay's load address. */
7970 unsigned long lma;
7971
7972 /* Non-zero if the overlay is currently mapped;
7973 zero otherwise. */
7974 unsigned long mapped;
7975@}
474c8240 7976@end smallexample
df0cd8c5
JB
7977
7978@item @code{_novlys}:
7979This variable must be a four-byte signed integer, holding the total
7980number of elements in @code{_ovly_table}.
7981
7982@end table
7983
7984To decide whether a particular overlay is mapped or not, @value{GDBN}
7985looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
7986@code{lma} members equal the VMA and LMA of the overlay's section in the
7987executable file. When @value{GDBN} finds a matching entry, it consults
7988the entry's @code{mapped} member to determine whether the overlay is
7989currently mapped.
7990
81d46470 7991In addition, your overlay manager may define a function called
def71bfa 7992@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
7993will silently set a breakpoint there. If the overlay manager then
7994calls this function whenever it has changed the overlay table, this
7995will enable @value{GDBN} to accurately keep track of which overlays
7996are in program memory, and update any breakpoints that may be set
b383017d 7997in overlays. This will allow breakpoints to work even if the
81d46470
MS
7998overlays are kept in ROM or other non-writable memory while they
7999are not being executed.
df0cd8c5
JB
8000
8001@node Overlay Sample Program
8002@section Overlay Sample Program
8003@cindex overlay example program
8004
8005When linking a program which uses overlays, you must place the overlays
8006at their load addresses, while relocating them to run at their mapped
8007addresses. To do this, you must write a linker script (@pxref{Overlay
8008Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
8009since linker scripts are specific to a particular host system, target
8010architecture, and target memory layout, this manual cannot provide
8011portable sample code demonstrating @value{GDBN}'s overlay support.
8012
8013However, the @value{GDBN} source distribution does contain an overlaid
8014program, with linker scripts for a few systems, as part of its test
8015suite. The program consists of the following files from
8016@file{gdb/testsuite/gdb.base}:
8017
8018@table @file
8019@item overlays.c
8020The main program file.
8021@item ovlymgr.c
8022A simple overlay manager, used by @file{overlays.c}.
8023@item foo.c
8024@itemx bar.c
8025@itemx baz.c
8026@itemx grbx.c
8027Overlay modules, loaded and used by @file{overlays.c}.
8028@item d10v.ld
8029@itemx m32r.ld
8030Linker scripts for linking the test program on the @code{d10v-elf}
8031and @code{m32r-elf} targets.
8032@end table
8033
8034You can build the test program using the @code{d10v-elf} GCC
8035cross-compiler like this:
8036
474c8240 8037@smallexample
df0cd8c5
JB
8038$ d10v-elf-gcc -g -c overlays.c
8039$ d10v-elf-gcc -g -c ovlymgr.c
8040$ d10v-elf-gcc -g -c foo.c
8041$ d10v-elf-gcc -g -c bar.c
8042$ d10v-elf-gcc -g -c baz.c
8043$ d10v-elf-gcc -g -c grbx.c
8044$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
8045 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 8046@end smallexample
df0cd8c5
JB
8047
8048The build process is identical for any other architecture, except that
8049you must substitute the appropriate compiler and linker script for the
8050target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
8051
8052
6d2ebf8b 8053@node Languages
c906108c
SS
8054@chapter Using @value{GDBN} with Different Languages
8055@cindex languages
8056
c906108c
SS
8057Although programming languages generally have common aspects, they are
8058rarely expressed in the same manner. For instance, in ANSI C,
8059dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
8060Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 8061represented (and displayed) differently. Hex numbers in C appear as
c906108c 8062@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
8063
8064@cindex working language
8065Language-specific information is built into @value{GDBN} for some languages,
8066allowing you to express operations like the above in your program's
8067native language, and allowing @value{GDBN} to output values in a manner
8068consistent with the syntax of your program's native language. The
8069language you use to build expressions is called the @dfn{working
8070language}.
8071
8072@menu
8073* Setting:: Switching between source languages
8074* Show:: Displaying the language
c906108c 8075* Checks:: Type and range checks
9c16f35a 8076* Supported languages:: Supported languages
4e562065 8077* Unsupported languages:: Unsupported languages
c906108c
SS
8078@end menu
8079
6d2ebf8b 8080@node Setting
c906108c
SS
8081@section Switching between source languages
8082
8083There are two ways to control the working language---either have @value{GDBN}
8084set it automatically, or select it manually yourself. You can use the
8085@code{set language} command for either purpose. On startup, @value{GDBN}
8086defaults to setting the language automatically. The working language is
8087used to determine how expressions you type are interpreted, how values
8088are printed, etc.
8089
8090In addition to the working language, every source file that
8091@value{GDBN} knows about has its own working language. For some object
8092file formats, the compiler might indicate which language a particular
8093source file is in. However, most of the time @value{GDBN} infers the
8094language from the name of the file. The language of a source file
b37052ae 8095controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 8096show each frame appropriately for its own language. There is no way to
d4f3574e
SS
8097set the language of a source file from within @value{GDBN}, but you can
8098set the language associated with a filename extension. @xref{Show, ,
8099Displaying the language}.
c906108c
SS
8100
8101This is most commonly a problem when you use a program, such
5d161b24 8102as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
8103another language. In that case, make the
8104program use @code{#line} directives in its C output; that way
8105@value{GDBN} will know the correct language of the source code of the original
8106program, and will display that source code, not the generated C code.
8107
8108@menu
8109* Filenames:: Filename extensions and languages.
8110* Manually:: Setting the working language manually
8111* Automatically:: Having @value{GDBN} infer the source language
8112@end menu
8113
6d2ebf8b 8114@node Filenames
c906108c
SS
8115@subsection List of filename extensions and languages
8116
8117If a source file name ends in one of the following extensions, then
8118@value{GDBN} infers that its language is the one indicated.
8119
8120@table @file
e07c999f
PH
8121@item .ada
8122@itemx .ads
8123@itemx .adb
8124@itemx .a
8125Ada source file.
c906108c
SS
8126
8127@item .c
8128C source file
8129
8130@item .C
8131@itemx .cc
8132@itemx .cp
8133@itemx .cpp
8134@itemx .cxx
8135@itemx .c++
b37052ae 8136C@t{++} source file
c906108c 8137
b37303ee
AF
8138@item .m
8139Objective-C source file
8140
c906108c
SS
8141@item .f
8142@itemx .F
8143Fortran source file
8144
c906108c
SS
8145@item .mod
8146Modula-2 source file
c906108c
SS
8147
8148@item .s
8149@itemx .S
8150Assembler source file. This actually behaves almost like C, but
8151@value{GDBN} does not skip over function prologues when stepping.
8152@end table
8153
8154In addition, you may set the language associated with a filename
8155extension. @xref{Show, , Displaying the language}.
8156
6d2ebf8b 8157@node Manually
c906108c
SS
8158@subsection Setting the working language
8159
8160If you allow @value{GDBN} to set the language automatically,
8161expressions are interpreted the same way in your debugging session and
8162your program.
8163
8164@kindex set language
8165If you wish, you may set the language manually. To do this, issue the
8166command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 8167a language, such as
c906108c 8168@code{c} or @code{modula-2}.
c906108c
SS
8169For a list of the supported languages, type @samp{set language}.
8170
c906108c
SS
8171Setting the language manually prevents @value{GDBN} from updating the working
8172language automatically. This can lead to confusion if you try
8173to debug a program when the working language is not the same as the
8174source language, when an expression is acceptable to both
8175languages---but means different things. For instance, if the current
8176source file were written in C, and @value{GDBN} was parsing Modula-2, a
8177command such as:
8178
474c8240 8179@smallexample
c906108c 8180print a = b + c
474c8240 8181@end smallexample
c906108c
SS
8182
8183@noindent
8184might not have the effect you intended. In C, this means to add
8185@code{b} and @code{c} and place the result in @code{a}. The result
8186printed would be the value of @code{a}. In Modula-2, this means to compare
8187@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 8188
6d2ebf8b 8189@node Automatically
c906108c
SS
8190@subsection Having @value{GDBN} infer the source language
8191
8192To have @value{GDBN} set the working language automatically, use
8193@samp{set language local} or @samp{set language auto}. @value{GDBN}
8194then infers the working language. That is, when your program stops in a
8195frame (usually by encountering a breakpoint), @value{GDBN} sets the
8196working language to the language recorded for the function in that
8197frame. If the language for a frame is unknown (that is, if the function
8198or block corresponding to the frame was defined in a source file that
8199does not have a recognized extension), the current working language is
8200not changed, and @value{GDBN} issues a warning.
8201
8202This may not seem necessary for most programs, which are written
8203entirely in one source language. However, program modules and libraries
8204written in one source language can be used by a main program written in
8205a different source language. Using @samp{set language auto} in this
8206case frees you from having to set the working language manually.
8207
6d2ebf8b 8208@node Show
c906108c 8209@section Displaying the language
c906108c
SS
8210
8211The following commands help you find out which language is the
8212working language, and also what language source files were written in.
8213
c906108c
SS
8214@table @code
8215@item show language
9c16f35a 8216@kindex show language
c906108c
SS
8217Display the current working language. This is the
8218language you can use with commands such as @code{print} to
8219build and compute expressions that may involve variables in your program.
8220
8221@item info frame
4644b6e3 8222@kindex info frame@r{, show the source language}
5d161b24 8223Display the source language for this frame. This language becomes the
c906108c 8224working language if you use an identifier from this frame.
5d161b24 8225@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
8226information listed here.
8227
8228@item info source
4644b6e3 8229@kindex info source@r{, show the source language}
c906108c 8230Display the source language of this source file.
5d161b24 8231@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
8232information listed here.
8233@end table
8234
8235In unusual circumstances, you may have source files with extensions
8236not in the standard list. You can then set the extension associated
8237with a language explicitly:
8238
c906108c 8239@table @code
09d4efe1 8240@item set extension-language @var{ext} @var{language}
9c16f35a 8241@kindex set extension-language
09d4efe1
EZ
8242Tell @value{GDBN} that source files with extension @var{ext} are to be
8243assumed as written in the source language @var{language}.
c906108c
SS
8244
8245@item info extensions
9c16f35a 8246@kindex info extensions
c906108c
SS
8247List all the filename extensions and the associated languages.
8248@end table
8249
6d2ebf8b 8250@node Checks
c906108c
SS
8251@section Type and range checking
8252
8253@quotation
8254@emph{Warning:} In this release, the @value{GDBN} commands for type and range
8255checking are included, but they do not yet have any effect. This
8256section documents the intended facilities.
8257@end quotation
8258@c FIXME remove warning when type/range code added
8259
8260Some languages are designed to guard you against making seemingly common
8261errors through a series of compile- and run-time checks. These include
8262checking the type of arguments to functions and operators, and making
8263sure mathematical overflows are caught at run time. Checks such as
8264these help to ensure a program's correctness once it has been compiled
8265by eliminating type mismatches, and providing active checks for range
8266errors when your program is running.
8267
8268@value{GDBN} can check for conditions like the above if you wish.
9c16f35a
EZ
8269Although @value{GDBN} does not check the statements in your program,
8270it can check expressions entered directly into @value{GDBN} for
8271evaluation via the @code{print} command, for example. As with the
8272working language, @value{GDBN} can also decide whether or not to check
8273automatically based on your program's source language.
8274@xref{Supported languages, ,Supported languages}, for the default
8275settings of supported languages.
c906108c
SS
8276
8277@menu
8278* Type Checking:: An overview of type checking
8279* Range Checking:: An overview of range checking
8280@end menu
8281
8282@cindex type checking
8283@cindex checks, type
6d2ebf8b 8284@node Type Checking
c906108c
SS
8285@subsection An overview of type checking
8286
8287Some languages, such as Modula-2, are strongly typed, meaning that the
8288arguments to operators and functions have to be of the correct type,
8289otherwise an error occurs. These checks prevent type mismatch
8290errors from ever causing any run-time problems. For example,
8291
8292@smallexample
82931 + 2 @result{} 3
8294@exdent but
8295@error{} 1 + 2.3
8296@end smallexample
8297
8298The second example fails because the @code{CARDINAL} 1 is not
8299type-compatible with the @code{REAL} 2.3.
8300
5d161b24
DB
8301For the expressions you use in @value{GDBN} commands, you can tell the
8302@value{GDBN} type checker to skip checking;
8303to treat any mismatches as errors and abandon the expression;
8304or to only issue warnings when type mismatches occur,
c906108c
SS
8305but evaluate the expression anyway. When you choose the last of
8306these, @value{GDBN} evaluates expressions like the second example above, but
8307also issues a warning.
8308
5d161b24
DB
8309Even if you turn type checking off, there may be other reasons
8310related to type that prevent @value{GDBN} from evaluating an expression.
8311For instance, @value{GDBN} does not know how to add an @code{int} and
8312a @code{struct foo}. These particular type errors have nothing to do
8313with the language in use, and usually arise from expressions, such as
c906108c
SS
8314the one described above, which make little sense to evaluate anyway.
8315
8316Each language defines to what degree it is strict about type. For
8317instance, both Modula-2 and C require the arguments to arithmetical
8318operators to be numbers. In C, enumerated types and pointers can be
8319represented as numbers, so that they are valid arguments to mathematical
9c16f35a 8320operators. @xref{Supported languages, ,Supported languages}, for further
c906108c
SS
8321details on specific languages.
8322
8323@value{GDBN} provides some additional commands for controlling the type checker:
8324
c906108c
SS
8325@kindex set check type
8326@kindex show check type
8327@table @code
8328@item set check type auto
8329Set type checking on or off based on the current working language.
9c16f35a 8330@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8331each language.
8332
8333@item set check type on
8334@itemx set check type off
8335Set type checking on or off, overriding the default setting for the
8336current working language. Issue a warning if the setting does not
8337match the language default. If any type mismatches occur in
d4f3574e 8338evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
8339message and aborts evaluation of the expression.
8340
8341@item set check type warn
8342Cause the type checker to issue warnings, but to always attempt to
8343evaluate the expression. Evaluating the expression may still
8344be impossible for other reasons. For example, @value{GDBN} cannot add
8345numbers and structures.
8346
8347@item show type
5d161b24 8348Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
8349is setting it automatically.
8350@end table
8351
8352@cindex range checking
8353@cindex checks, range
6d2ebf8b 8354@node Range Checking
c906108c
SS
8355@subsection An overview of range checking
8356
8357In some languages (such as Modula-2), it is an error to exceed the
8358bounds of a type; this is enforced with run-time checks. Such range
8359checking is meant to ensure program correctness by making sure
8360computations do not overflow, or indices on an array element access do
8361not exceed the bounds of the array.
8362
8363For expressions you use in @value{GDBN} commands, you can tell
8364@value{GDBN} to treat range errors in one of three ways: ignore them,
8365always treat them as errors and abandon the expression, or issue
8366warnings but evaluate the expression anyway.
8367
8368A range error can result from numerical overflow, from exceeding an
8369array index bound, or when you type a constant that is not a member
8370of any type. Some languages, however, do not treat overflows as an
8371error. In many implementations of C, mathematical overflow causes the
8372result to ``wrap around'' to lower values---for example, if @var{m} is
8373the largest integer value, and @var{s} is the smallest, then
8374
474c8240 8375@smallexample
c906108c 8376@var{m} + 1 @result{} @var{s}
474c8240 8377@end smallexample
c906108c
SS
8378
8379This, too, is specific to individual languages, and in some cases
9c16f35a 8380specific to individual compilers or machines. @xref{Supported languages, ,
c906108c
SS
8381Supported languages}, for further details on specific languages.
8382
8383@value{GDBN} provides some additional commands for controlling the range checker:
8384
c906108c
SS
8385@kindex set check range
8386@kindex show check range
8387@table @code
8388@item set check range auto
8389Set range checking on or off based on the current working language.
9c16f35a 8390@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8391each language.
8392
8393@item set check range on
8394@itemx set check range off
8395Set range checking on or off, overriding the default setting for the
8396current working language. A warning is issued if the setting does not
c3f6f71d
JM
8397match the language default. If a range error occurs and range checking is on,
8398then a message is printed and evaluation of the expression is aborted.
c906108c
SS
8399
8400@item set check range warn
8401Output messages when the @value{GDBN} range checker detects a range error,
8402but attempt to evaluate the expression anyway. Evaluating the
8403expression may still be impossible for other reasons, such as accessing
8404memory that the process does not own (a typical example from many Unix
8405systems).
8406
8407@item show range
8408Show the current setting of the range checker, and whether or not it is
8409being set automatically by @value{GDBN}.
8410@end table
c906108c 8411
9c16f35a 8412@node Supported languages
c906108c 8413@section Supported languages
c906108c 8414
9c16f35a
EZ
8415@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
8416assembly, Modula-2, and Ada.
cce74817 8417@c This is false ...
c906108c
SS
8418Some @value{GDBN} features may be used in expressions regardless of the
8419language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8420and the @samp{@{type@}addr} construct (@pxref{Expressions,
8421,Expressions}) can be used with the constructs of any supported
8422language.
8423
8424The following sections detail to what degree each source language is
8425supported by @value{GDBN}. These sections are not meant to be language
8426tutorials or references, but serve only as a reference guide to what the
8427@value{GDBN} expression parser accepts, and what input and output
8428formats should look like for different languages. There are many good
8429books written on each of these languages; please look to these for a
8430language reference or tutorial.
8431
c906108c 8432@menu
b37303ee 8433* C:: C and C@t{++}
b383017d 8434* Objective-C:: Objective-C
09d4efe1 8435* Fortran:: Fortran
9c16f35a 8436* Pascal:: Pascal
b37303ee 8437* Modula-2:: Modula-2
e07c999f 8438* Ada:: Ada
c906108c
SS
8439@end menu
8440
6d2ebf8b 8441@node C
b37052ae 8442@subsection C and C@t{++}
7a292a7a 8443
b37052ae
EZ
8444@cindex C and C@t{++}
8445@cindex expressions in C or C@t{++}
c906108c 8446
b37052ae 8447Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8448to both languages. Whenever this is the case, we discuss those languages
8449together.
8450
41afff9a
EZ
8451@cindex C@t{++}
8452@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8453@cindex @sc{gnu} C@t{++}
8454The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8455compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8456effectively, you must compile your C@t{++} programs with a supported
8457C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8458compiler (@code{aCC}).
8459
0179ffac
DC
8460For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8461format; if it doesn't work on your system, try the stabs+ debugging
8462format. You can select those formats explicitly with the @code{g++}
8463command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8464@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8465CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8466
c906108c 8467@menu
b37052ae
EZ
8468* C Operators:: C and C@t{++} operators
8469* C Constants:: C and C@t{++} constants
8470* C plus plus expressions:: C@t{++} expressions
8471* C Defaults:: Default settings for C and C@t{++}
8472* C Checks:: C and C@t{++} type and range checks
c906108c 8473* Debugging C:: @value{GDBN} and C
b37052ae 8474* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8475@end menu
c906108c 8476
6d2ebf8b 8477@node C Operators
b37052ae 8478@subsubsection C and C@t{++} operators
7a292a7a 8479
b37052ae 8480@cindex C and C@t{++} operators
c906108c
SS
8481
8482Operators must be defined on values of specific types. For instance,
8483@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8484often defined on groups of types.
c906108c 8485
b37052ae 8486For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8487
8488@itemize @bullet
53a5351d 8489
c906108c 8490@item
c906108c 8491@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8492specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8493
8494@item
d4f3574e
SS
8495@emph{Floating-point types} include @code{float}, @code{double}, and
8496@code{long double} (if supported by the target platform).
c906108c
SS
8497
8498@item
53a5351d 8499@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8500
8501@item
8502@emph{Scalar types} include all of the above.
53a5351d 8503
c906108c
SS
8504@end itemize
8505
8506@noindent
8507The following operators are supported. They are listed here
8508in order of increasing precedence:
8509
8510@table @code
8511@item ,
8512The comma or sequencing operator. Expressions in a comma-separated list
8513are evaluated from left to right, with the result of the entire
8514expression being the last expression evaluated.
8515
8516@item =
8517Assignment. The value of an assignment expression is the value
8518assigned. Defined on scalar types.
8519
8520@item @var{op}=
8521Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8522and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8523@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8524@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8525@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8526
8527@item ?:
8528The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8529of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8530integral type.
8531
8532@item ||
8533Logical @sc{or}. Defined on integral types.
8534
8535@item &&
8536Logical @sc{and}. Defined on integral types.
8537
8538@item |
8539Bitwise @sc{or}. Defined on integral types.
8540
8541@item ^
8542Bitwise exclusive-@sc{or}. Defined on integral types.
8543
8544@item &
8545Bitwise @sc{and}. Defined on integral types.
8546
8547@item ==@r{, }!=
8548Equality and inequality. Defined on scalar types. The value of these
8549expressions is 0 for false and non-zero for true.
8550
8551@item <@r{, }>@r{, }<=@r{, }>=
8552Less than, greater than, less than or equal, greater than or equal.
8553Defined on scalar types. The value of these expressions is 0 for false
8554and non-zero for true.
8555
8556@item <<@r{, }>>
8557left shift, and right shift. Defined on integral types.
8558
8559@item @@
8560The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8561
8562@item +@r{, }-
8563Addition and subtraction. Defined on integral types, floating-point types and
8564pointer types.
8565
8566@item *@r{, }/@r{, }%
8567Multiplication, division, and modulus. Multiplication and division are
8568defined on integral and floating-point types. Modulus is defined on
8569integral types.
8570
8571@item ++@r{, }--
8572Increment and decrement. When appearing before a variable, the
8573operation is performed before the variable is used in an expression;
8574when appearing after it, the variable's value is used before the
8575operation takes place.
8576
8577@item *
8578Pointer dereferencing. Defined on pointer types. Same precedence as
8579@code{++}.
8580
8581@item &
8582Address operator. Defined on variables. Same precedence as @code{++}.
8583
b37052ae
EZ
8584For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8585allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8586(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8587where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8588stored.
c906108c
SS
8589
8590@item -
8591Negative. Defined on integral and floating-point types. Same
8592precedence as @code{++}.
8593
8594@item !
8595Logical negation. Defined on integral types. Same precedence as
8596@code{++}.
8597
8598@item ~
8599Bitwise complement operator. Defined on integral types. Same precedence as
8600@code{++}.
8601
8602
8603@item .@r{, }->
8604Structure member, and pointer-to-structure member. For convenience,
8605@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8606pointer based on the stored type information.
8607Defined on @code{struct} and @code{union} data.
8608
c906108c
SS
8609@item .*@r{, }->*
8610Dereferences of pointers to members.
c906108c
SS
8611
8612@item []
8613Array indexing. @code{@var{a}[@var{i}]} is defined as
8614@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8615
8616@item ()
8617Function parameter list. Same precedence as @code{->}.
8618
c906108c 8619@item ::
b37052ae 8620C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8621and @code{class} types.
c906108c
SS
8622
8623@item ::
7a292a7a
SS
8624Doubled colons also represent the @value{GDBN} scope operator
8625(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8626above.
c906108c
SS
8627@end table
8628
c906108c
SS
8629If an operator is redefined in the user code, @value{GDBN} usually
8630attempts to invoke the redefined version instead of using the operator's
8631predefined meaning.
c906108c 8632
c906108c 8633@menu
5d161b24 8634* C Constants::
c906108c
SS
8635@end menu
8636
6d2ebf8b 8637@node C Constants
b37052ae 8638@subsubsection C and C@t{++} constants
c906108c 8639
b37052ae 8640@cindex C and C@t{++} constants
c906108c 8641
b37052ae 8642@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8643following ways:
c906108c
SS
8644
8645@itemize @bullet
8646@item
8647Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8648specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8649by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8650@samp{l}, specifying that the constant should be treated as a
8651@code{long} value.
8652
8653@item
8654Floating point constants are a sequence of digits, followed by a decimal
8655point, followed by a sequence of digits, and optionally followed by an
8656exponent. An exponent is of the form:
8657@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8658sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8659A floating-point constant may also end with a letter @samp{f} or
8660@samp{F}, specifying that the constant should be treated as being of
8661the @code{float} (as opposed to the default @code{double}) type; or with
8662a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8663constant.
c906108c
SS
8664
8665@item
8666Enumerated constants consist of enumerated identifiers, or their
8667integral equivalents.
8668
8669@item
8670Character constants are a single character surrounded by single quotes
8671(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8672(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8673be represented by a letter or by @dfn{escape sequences}, which are of
8674the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8675of the character's ordinal value; or of the form @samp{\@var{x}}, where
8676@samp{@var{x}} is a predefined special character---for example,
8677@samp{\n} for newline.
8678
8679@item
96a2c332
SS
8680String constants are a sequence of character constants surrounded by
8681double quotes (@code{"}). Any valid character constant (as described
8682above) may appear. Double quotes within the string must be preceded by
8683a backslash, so for instance @samp{"a\"b'c"} is a string of five
8684characters.
c906108c
SS
8685
8686@item
8687Pointer constants are an integral value. You can also write pointers
8688to constants using the C operator @samp{&}.
8689
8690@item
8691Array constants are comma-separated lists surrounded by braces @samp{@{}
8692and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8693integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8694and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8695@end itemize
8696
c906108c 8697@menu
5d161b24
DB
8698* C plus plus expressions::
8699* C Defaults::
8700* C Checks::
c906108c 8701
5d161b24 8702* Debugging C::
c906108c
SS
8703@end menu
8704
6d2ebf8b 8705@node C plus plus expressions
b37052ae
EZ
8706@subsubsection C@t{++} expressions
8707
8708@cindex expressions in C@t{++}
8709@value{GDBN} expression handling can interpret most C@t{++} expressions.
8710
0179ffac
DC
8711@cindex debugging C@t{++} programs
8712@cindex C@t{++} compilers
8713@cindex debug formats and C@t{++}
8714@cindex @value{NGCC} and C@t{++}
c906108c 8715@quotation
b37052ae 8716@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8717proper compiler and the proper debug format. Currently, @value{GDBN}
8718works best when debugging C@t{++} code that is compiled with
8719@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8720@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8721stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8722stabs+ as their default debug format, so you usually don't need to
8723specify a debug format explicitly. Other compilers and/or debug formats
8724are likely to work badly or not at all when using @value{GDBN} to debug
8725C@t{++} code.
c906108c 8726@end quotation
c906108c
SS
8727
8728@enumerate
8729
8730@cindex member functions
8731@item
8732Member function calls are allowed; you can use expressions like
8733
474c8240 8734@smallexample
c906108c 8735count = aml->GetOriginal(x, y)
474c8240 8736@end smallexample
c906108c 8737
41afff9a 8738@vindex this@r{, inside C@t{++} member functions}
b37052ae 8739@cindex namespace in C@t{++}
c906108c
SS
8740@item
8741While a member function is active (in the selected stack frame), your
8742expressions have the same namespace available as the member function;
8743that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8744pointer @code{this} following the same rules as C@t{++}.
c906108c 8745
c906108c 8746@cindex call overloaded functions
d4f3574e 8747@cindex overloaded functions, calling
b37052ae 8748@cindex type conversions in C@t{++}
c906108c
SS
8749@item
8750You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8751call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8752perform overload resolution involving user-defined type conversions,
8753calls to constructors, or instantiations of templates that do not exist
8754in the program. It also cannot handle ellipsis argument lists or
8755default arguments.
8756
8757It does perform integral conversions and promotions, floating-point
8758promotions, arithmetic conversions, pointer conversions, conversions of
8759class objects to base classes, and standard conversions such as those of
8760functions or arrays to pointers; it requires an exact match on the
8761number of function arguments.
8762
8763Overload resolution is always performed, unless you have specified
8764@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8765,@value{GDBN} features for C@t{++}}.
c906108c 8766
d4f3574e 8767You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8768explicit function signature to call an overloaded function, as in
8769@smallexample
8770p 'foo(char,int)'('x', 13)
8771@end smallexample
d4f3574e 8772
c906108c 8773The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8774see @ref{Completion, ,Command completion}.
c906108c 8775
c906108c
SS
8776@cindex reference declarations
8777@item
b37052ae
EZ
8778@value{GDBN} understands variables declared as C@t{++} references; you can use
8779them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8780dereferenced.
8781
8782In the parameter list shown when @value{GDBN} displays a frame, the values of
8783reference variables are not displayed (unlike other variables); this
8784avoids clutter, since references are often used for large structures.
8785The @emph{address} of a reference variable is always shown, unless
8786you have specified @samp{set print address off}.
8787
8788@item
b37052ae 8789@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8790expressions can use it just as expressions in your program do. Since
8791one scope may be defined in another, you can use @code{::} repeatedly if
8792necessary, for example in an expression like
8793@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8794resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8795debugging (@pxref{Variables, ,Program variables}).
8796@end enumerate
8797
b37052ae 8798In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8799calling virtual functions correctly, printing out virtual bases of
8800objects, calling functions in a base subobject, casting objects, and
8801invoking user-defined operators.
c906108c 8802
6d2ebf8b 8803@node C Defaults
b37052ae 8804@subsubsection C and C@t{++} defaults
7a292a7a 8805
b37052ae 8806@cindex C and C@t{++} defaults
c906108c 8807
c906108c
SS
8808If you allow @value{GDBN} to set type and range checking automatically, they
8809both default to @code{off} whenever the working language changes to
b37052ae 8810C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8811selects the working language.
c906108c
SS
8812
8813If you allow @value{GDBN} to set the language automatically, it
8814recognizes source files whose names end with @file{.c}, @file{.C}, or
8815@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8816these files, it sets the working language to C or C@t{++}.
c906108c
SS
8817@xref{Automatically, ,Having @value{GDBN} infer the source language},
8818for further details.
8819
c906108c
SS
8820@c Type checking is (a) primarily motivated by Modula-2, and (b)
8821@c unimplemented. If (b) changes, it might make sense to let this node
8822@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8823
6d2ebf8b 8824@node C Checks
b37052ae 8825@subsubsection C and C@t{++} type and range checks
7a292a7a 8826
b37052ae 8827@cindex C and C@t{++} checks
c906108c 8828
b37052ae 8829By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8830is not used. However, if you turn type checking on, @value{GDBN}
8831considers two variables type equivalent if:
8832
8833@itemize @bullet
8834@item
8835The two variables are structured and have the same structure, union, or
8836enumerated tag.
8837
8838@item
8839The two variables have the same type name, or types that have been
8840declared equivalent through @code{typedef}.
8841
8842@ignore
8843@c leaving this out because neither J Gilmore nor R Pesch understand it.
8844@c FIXME--beers?
8845@item
8846The two @code{struct}, @code{union}, or @code{enum} variables are
8847declared in the same declaration. (Note: this may not be true for all C
8848compilers.)
8849@end ignore
8850@end itemize
8851
8852Range checking, if turned on, is done on mathematical operations. Array
8853indices are not checked, since they are often used to index a pointer
8854that is not itself an array.
c906108c 8855
6d2ebf8b 8856@node Debugging C
c906108c 8857@subsubsection @value{GDBN} and C
c906108c
SS
8858
8859The @code{set print union} and @code{show print union} commands apply to
8860the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8861inside a @code{struct} or @code{class} is also printed. Otherwise, it
8862appears as @samp{@{...@}}.
c906108c
SS
8863
8864The @code{@@} operator aids in the debugging of dynamic arrays, formed
8865with pointers and a memory allocation function. @xref{Expressions,
8866,Expressions}.
8867
c906108c 8868@menu
5d161b24 8869* Debugging C plus plus::
c906108c
SS
8870@end menu
8871
6d2ebf8b 8872@node Debugging C plus plus
b37052ae 8873@subsubsection @value{GDBN} features for C@t{++}
c906108c 8874
b37052ae 8875@cindex commands for C@t{++}
7a292a7a 8876
b37052ae
EZ
8877Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8878designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8879
8880@table @code
8881@cindex break in overloaded functions
8882@item @r{breakpoint menus}
8883When you want a breakpoint in a function whose name is overloaded,
8884@value{GDBN} breakpoint menus help you specify which function definition
8885you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8886
b37052ae 8887@cindex overloading in C@t{++}
c906108c
SS
8888@item rbreak @var{regex}
8889Setting breakpoints using regular expressions is helpful for setting
8890breakpoints on overloaded functions that are not members of any special
8891classes.
8892@xref{Set Breaks, ,Setting breakpoints}.
8893
b37052ae 8894@cindex C@t{++} exception handling
c906108c
SS
8895@item catch throw
8896@itemx catch catch
b37052ae 8897Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8898Catchpoints, , Setting catchpoints}.
8899
8900@cindex inheritance
8901@item ptype @var{typename}
8902Print inheritance relationships as well as other information for type
8903@var{typename}.
8904@xref{Symbols, ,Examining the Symbol Table}.
8905
b37052ae 8906@cindex C@t{++} symbol display
c906108c
SS
8907@item set print demangle
8908@itemx show print demangle
8909@itemx set print asm-demangle
8910@itemx show print asm-demangle
b37052ae
EZ
8911Control whether C@t{++} symbols display in their source form, both when
8912displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8913@xref{Print Settings, ,Print settings}.
8914
8915@item set print object
8916@itemx show print object
8917Choose whether to print derived (actual) or declared types of objects.
8918@xref{Print Settings, ,Print settings}.
8919
8920@item set print vtbl
8921@itemx show print vtbl
8922Control the format for printing virtual function tables.
8923@xref{Print Settings, ,Print settings}.
c906108c 8924(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8925ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8926
8927@kindex set overload-resolution
d4f3574e 8928@cindex overloaded functions, overload resolution
c906108c 8929@item set overload-resolution on
b37052ae 8930Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8931is on. For overloaded functions, @value{GDBN} evaluates the arguments
8932and searches for a function whose signature matches the argument types,
b37052ae 8933using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8934expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8935message.
8936
8937@item set overload-resolution off
b37052ae 8938Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8939overloaded functions that are not class member functions, @value{GDBN}
8940chooses the first function of the specified name that it finds in the
8941symbol table, whether or not its arguments are of the correct type. For
8942overloaded functions that are class member functions, @value{GDBN}
8943searches for a function whose signature @emph{exactly} matches the
8944argument types.
c906108c 8945
9c16f35a
EZ
8946@kindex show overload-resolution
8947@item show overload-resolution
8948Show the current setting of overload resolution.
8949
c906108c
SS
8950@item @r{Overloaded symbol names}
8951You can specify a particular definition of an overloaded symbol, using
b37052ae 8952the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
8953@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8954also use the @value{GDBN} command-line word completion facilities to list the
8955available choices, or to finish the type list for you.
8956@xref{Completion,, Command completion}, for details on how to do this.
8957@end table
c906108c 8958
b37303ee
AF
8959@node Objective-C
8960@subsection Objective-C
8961
8962@cindex Objective-C
8963This section provides information about some commands and command
721c2651
EZ
8964options that are useful for debugging Objective-C code. See also
8965@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
8966few more commands specific to Objective-C support.
b37303ee
AF
8967
8968@menu
b383017d
RM
8969* Method Names in Commands::
8970* The Print Command with Objective-C::
b37303ee
AF
8971@end menu
8972
8973@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
8974@subsubsection Method Names in Commands
8975
8976The following commands have been extended to accept Objective-C method
8977names as line specifications:
8978
8979@kindex clear@r{, and Objective-C}
8980@kindex break@r{, and Objective-C}
8981@kindex info line@r{, and Objective-C}
8982@kindex jump@r{, and Objective-C}
8983@kindex list@r{, and Objective-C}
8984@itemize
8985@item @code{clear}
8986@item @code{break}
8987@item @code{info line}
8988@item @code{jump}
8989@item @code{list}
8990@end itemize
8991
8992A fully qualified Objective-C method name is specified as
8993
8994@smallexample
8995-[@var{Class} @var{methodName}]
8996@end smallexample
8997
c552b3bb
JM
8998where the minus sign is used to indicate an instance method and a
8999plus sign (not shown) is used to indicate a class method. The class
9000name @var{Class} and method name @var{methodName} are enclosed in
9001brackets, similar to the way messages are specified in Objective-C
9002source code. For example, to set a breakpoint at the @code{create}
9003instance method of class @code{Fruit} in the program currently being
9004debugged, enter:
b37303ee
AF
9005
9006@smallexample
9007break -[Fruit create]
9008@end smallexample
9009
9010To list ten program lines around the @code{initialize} class method,
9011enter:
9012
9013@smallexample
9014list +[NSText initialize]
9015@end smallexample
9016
c552b3bb
JM
9017In the current version of @value{GDBN}, the plus or minus sign is
9018required. In future versions of @value{GDBN}, the plus or minus
9019sign will be optional, but you can use it to narrow the search. It
9020is also possible to specify just a method name:
b37303ee
AF
9021
9022@smallexample
9023break create
9024@end smallexample
9025
9026You must specify the complete method name, including any colons. If
9027your program's source files contain more than one @code{create} method,
9028you'll be presented with a numbered list of classes that implement that
9029method. Indicate your choice by number, or type @samp{0} to exit if
9030none apply.
9031
9032As another example, to clear a breakpoint established at the
9033@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
9034
9035@smallexample
9036clear -[NSWindow makeKeyAndOrderFront:]
9037@end smallexample
9038
9039@node The Print Command with Objective-C
9040@subsubsection The Print Command With Objective-C
721c2651 9041@cindex Objective-C, print objects
c552b3bb
JM
9042@kindex print-object
9043@kindex po @r{(@code{print-object})}
b37303ee 9044
c552b3bb 9045The print command has also been extended to accept methods. For example:
b37303ee
AF
9046
9047@smallexample
c552b3bb 9048print -[@var{object} hash]
b37303ee
AF
9049@end smallexample
9050
9051@cindex print an Objective-C object description
c552b3bb
JM
9052@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
9053@noindent
9054will tell @value{GDBN} to send the @code{hash} message to @var{object}
9055and print the result. Also, an additional command has been added,
9056@code{print-object} or @code{po} for short, which is meant to print
9057the description of an object. However, this command may only work
9058with certain Objective-C libraries that have a particular hook
9059function, @code{_NSPrintForDebugger}, defined.
b37303ee 9060
09d4efe1
EZ
9061@node Fortran
9062@subsection Fortran
9063@cindex Fortran-specific support in @value{GDBN}
9064
9065@table @code
9066@cindex @code{COMMON} blocks, Fortran
9067@kindex info common
9068@item info common @r{[}@var{common-name}@r{]}
9069This command prints the values contained in the Fortran @code{COMMON}
9070block whose name is @var{common-name}. With no argument, the names of
9071all @code{COMMON} blocks visible at current program location are
9072printed.
9073@end table
9074
a8f24a35
EZ
9075Fortran symbols are usually case-insensitive, so @value{GDBN} by
9076default uses case-insensitive matches for Fortran symbols. You can
9077change that with the @samp{set case-insensitive} command, see
9078@ref{Symbols}, for the details.
9079
9c16f35a
EZ
9080@node Pascal
9081@subsection Pascal
9082
9083@cindex Pascal support in @value{GDBN}, limitations
9084Debugging Pascal programs which use sets, subranges, file variables, or
9085nested functions does not currently work. @value{GDBN} does not support
9086entering expressions, printing values, or similar features using Pascal
9087syntax.
9088
9089The Pascal-specific command @code{set print pascal_static-members}
9090controls whether static members of Pascal objects are displayed.
9091@xref{Print Settings, pascal_static-members}.
9092
09d4efe1 9093@node Modula-2
c906108c 9094@subsection Modula-2
7a292a7a 9095
d4f3574e 9096@cindex Modula-2, @value{GDBN} support
c906108c
SS
9097
9098The extensions made to @value{GDBN} to support Modula-2 only support
9099output from the @sc{gnu} Modula-2 compiler (which is currently being
9100developed). Other Modula-2 compilers are not currently supported, and
9101attempting to debug executables produced by them is most likely
9102to give an error as @value{GDBN} reads in the executable's symbol
9103table.
9104
9105@cindex expressions in Modula-2
9106@menu
9107* M2 Operators:: Built-in operators
9108* Built-In Func/Proc:: Built-in functions and procedures
9109* M2 Constants:: Modula-2 constants
9110* M2 Defaults:: Default settings for Modula-2
9111* Deviations:: Deviations from standard Modula-2
9112* M2 Checks:: Modula-2 type and range checks
9113* M2 Scope:: The scope operators @code{::} and @code{.}
9114* GDB/M2:: @value{GDBN} and Modula-2
9115@end menu
9116
6d2ebf8b 9117@node M2 Operators
c906108c
SS
9118@subsubsection Operators
9119@cindex Modula-2 operators
9120
9121Operators must be defined on values of specific types. For instance,
9122@code{+} is defined on numbers, but not on structures. Operators are
9123often defined on groups of types. For the purposes of Modula-2, the
9124following definitions hold:
9125
9126@itemize @bullet
9127
9128@item
9129@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
9130their subranges.
9131
9132@item
9133@emph{Character types} consist of @code{CHAR} and its subranges.
9134
9135@item
9136@emph{Floating-point types} consist of @code{REAL}.
9137
9138@item
9139@emph{Pointer types} consist of anything declared as @code{POINTER TO
9140@var{type}}.
9141
9142@item
9143@emph{Scalar types} consist of all of the above.
9144
9145@item
9146@emph{Set types} consist of @code{SET} and @code{BITSET} types.
9147
9148@item
9149@emph{Boolean types} consist of @code{BOOLEAN}.
9150@end itemize
9151
9152@noindent
9153The following operators are supported, and appear in order of
9154increasing precedence:
9155
9156@table @code
9157@item ,
9158Function argument or array index separator.
9159
9160@item :=
9161Assignment. The value of @var{var} @code{:=} @var{value} is
9162@var{value}.
9163
9164@item <@r{, }>
9165Less than, greater than on integral, floating-point, or enumerated
9166types.
9167
9168@item <=@r{, }>=
96a2c332 9169Less than or equal to, greater than or equal to
c906108c
SS
9170on integral, floating-point and enumerated types, or set inclusion on
9171set types. Same precedence as @code{<}.
9172
9173@item =@r{, }<>@r{, }#
9174Equality and two ways of expressing inequality, valid on scalar types.
9175Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9176available for inequality, since @code{#} conflicts with the script
9177comment character.
9178
9179@item IN
9180Set membership. Defined on set types and the types of their members.
9181Same precedence as @code{<}.
9182
9183@item OR
9184Boolean disjunction. Defined on boolean types.
9185
9186@item AND@r{, }&
d4f3574e 9187Boolean conjunction. Defined on boolean types.
c906108c
SS
9188
9189@item @@
9190The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9191
9192@item +@r{, }-
9193Addition and subtraction on integral and floating-point types, or union
9194and difference on set types.
9195
9196@item *
9197Multiplication on integral and floating-point types, or set intersection
9198on set types.
9199
9200@item /
9201Division on floating-point types, or symmetric set difference on set
9202types. Same precedence as @code{*}.
9203
9204@item DIV@r{, }MOD
9205Integer division and remainder. Defined on integral types. Same
9206precedence as @code{*}.
9207
9208@item -
9209Negative. Defined on @code{INTEGER} and @code{REAL} data.
9210
9211@item ^
9212Pointer dereferencing. Defined on pointer types.
9213
9214@item NOT
9215Boolean negation. Defined on boolean types. Same precedence as
9216@code{^}.
9217
9218@item .
9219@code{RECORD} field selector. Defined on @code{RECORD} data. Same
9220precedence as @code{^}.
9221
9222@item []
9223Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
9224
9225@item ()
9226Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
9227as @code{^}.
9228
9229@item ::@r{, }.
9230@value{GDBN} and Modula-2 scope operators.
9231@end table
9232
9233@quotation
9234@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
9235treats the use of the operator @code{IN}, or the use of operators
9236@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
9237@code{<=}, and @code{>=} on sets as an error.
9238@end quotation
9239
cb51c4e0 9240
6d2ebf8b 9241@node Built-In Func/Proc
c906108c 9242@subsubsection Built-in functions and procedures
cb51c4e0 9243@cindex Modula-2 built-ins
c906108c
SS
9244
9245Modula-2 also makes available several built-in procedures and functions.
9246In describing these, the following metavariables are used:
9247
9248@table @var
9249
9250@item a
9251represents an @code{ARRAY} variable.
9252
9253@item c
9254represents a @code{CHAR} constant or variable.
9255
9256@item i
9257represents a variable or constant of integral type.
9258
9259@item m
9260represents an identifier that belongs to a set. Generally used in the
9261same function with the metavariable @var{s}. The type of @var{s} should
9262be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
9263
9264@item n
9265represents a variable or constant of integral or floating-point type.
9266
9267@item r
9268represents a variable or constant of floating-point type.
9269
9270@item t
9271represents a type.
9272
9273@item v
9274represents a variable.
9275
9276@item x
9277represents a variable or constant of one of many types. See the
9278explanation of the function for details.
9279@end table
9280
9281All Modula-2 built-in procedures also return a result, described below.
9282
9283@table @code
9284@item ABS(@var{n})
9285Returns the absolute value of @var{n}.
9286
9287@item CAP(@var{c})
9288If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 9289equivalent, otherwise it returns its argument.
c906108c
SS
9290
9291@item CHR(@var{i})
9292Returns the character whose ordinal value is @var{i}.
9293
9294@item DEC(@var{v})
c3f6f71d 9295Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9296
9297@item DEC(@var{v},@var{i})
9298Decrements the value in the variable @var{v} by @var{i}. Returns the
9299new value.
9300
9301@item EXCL(@var{m},@var{s})
9302Removes the element @var{m} from the set @var{s}. Returns the new
9303set.
9304
9305@item FLOAT(@var{i})
9306Returns the floating point equivalent of the integer @var{i}.
9307
9308@item HIGH(@var{a})
9309Returns the index of the last member of @var{a}.
9310
9311@item INC(@var{v})
c3f6f71d 9312Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9313
9314@item INC(@var{v},@var{i})
9315Increments the value in the variable @var{v} by @var{i}. Returns the
9316new value.
9317
9318@item INCL(@var{m},@var{s})
9319Adds the element @var{m} to the set @var{s} if it is not already
9320there. Returns the new set.
9321
9322@item MAX(@var{t})
9323Returns the maximum value of the type @var{t}.
9324
9325@item MIN(@var{t})
9326Returns the minimum value of the type @var{t}.
9327
9328@item ODD(@var{i})
9329Returns boolean TRUE if @var{i} is an odd number.
9330
9331@item ORD(@var{x})
9332Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
9333value of a character is its @sc{ascii} value (on machines supporting the
9334@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
9335integral, character and enumerated types.
9336
9337@item SIZE(@var{x})
9338Returns the size of its argument. @var{x} can be a variable or a type.
9339
9340@item TRUNC(@var{r})
9341Returns the integral part of @var{r}.
9342
9343@item VAL(@var{t},@var{i})
9344Returns the member of the type @var{t} whose ordinal value is @var{i}.
9345@end table
9346
9347@quotation
9348@emph{Warning:} Sets and their operations are not yet supported, so
9349@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
9350an error.
9351@end quotation
9352
9353@cindex Modula-2 constants
6d2ebf8b 9354@node M2 Constants
c906108c
SS
9355@subsubsection Constants
9356
9357@value{GDBN} allows you to express the constants of Modula-2 in the following
9358ways:
9359
9360@itemize @bullet
9361
9362@item
9363Integer constants are simply a sequence of digits. When used in an
9364expression, a constant is interpreted to be type-compatible with the
9365rest of the expression. Hexadecimal integers are specified by a
9366trailing @samp{H}, and octal integers by a trailing @samp{B}.
9367
9368@item
9369Floating point constants appear as a sequence of digits, followed by a
9370decimal point and another sequence of digits. An optional exponent can
9371then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
9372@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
9373digits of the floating point constant must be valid decimal (base 10)
9374digits.
9375
9376@item
9377Character constants consist of a single character enclosed by a pair of
9378like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 9379also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
9380followed by a @samp{C}.
9381
9382@item
9383String constants consist of a sequence of characters enclosed by a
9384pair of like quotes, either single (@code{'}) or double (@code{"}).
9385Escape sequences in the style of C are also allowed. @xref{C
b37052ae 9386Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
9387sequences.
9388
9389@item
9390Enumerated constants consist of an enumerated identifier.
9391
9392@item
9393Boolean constants consist of the identifiers @code{TRUE} and
9394@code{FALSE}.
9395
9396@item
9397Pointer constants consist of integral values only.
9398
9399@item
9400Set constants are not yet supported.
9401@end itemize
9402
6d2ebf8b 9403@node M2 Defaults
c906108c
SS
9404@subsubsection Modula-2 defaults
9405@cindex Modula-2 defaults
9406
9407If type and range checking are set automatically by @value{GDBN}, they
9408both default to @code{on} whenever the working language changes to
d4f3574e 9409Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
9410selected the working language.
9411
9412If you allow @value{GDBN} to set the language automatically, then entering
9413code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 9414working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
9415the language automatically}, for further details.
9416
6d2ebf8b 9417@node Deviations
c906108c
SS
9418@subsubsection Deviations from standard Modula-2
9419@cindex Modula-2, deviations from
9420
9421A few changes have been made to make Modula-2 programs easier to debug.
9422This is done primarily via loosening its type strictness:
9423
9424@itemize @bullet
9425@item
9426Unlike in standard Modula-2, pointer constants can be formed by
9427integers. This allows you to modify pointer variables during
9428debugging. (In standard Modula-2, the actual address contained in a
9429pointer variable is hidden from you; it can only be modified
9430through direct assignment to another pointer variable or expression that
9431returned a pointer.)
9432
9433@item
9434C escape sequences can be used in strings and characters to represent
9435non-printable characters. @value{GDBN} prints out strings with these
9436escape sequences embedded. Single non-printable characters are
9437printed using the @samp{CHR(@var{nnn})} format.
9438
9439@item
9440The assignment operator (@code{:=}) returns the value of its right-hand
9441argument.
9442
9443@item
9444All built-in procedures both modify @emph{and} return their argument.
9445@end itemize
9446
6d2ebf8b 9447@node M2 Checks
c906108c
SS
9448@subsubsection Modula-2 type and range checks
9449@cindex Modula-2 checks
9450
9451@quotation
9452@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9453range checking.
9454@end quotation
9455@c FIXME remove warning when type/range checks added
9456
9457@value{GDBN} considers two Modula-2 variables type equivalent if:
9458
9459@itemize @bullet
9460@item
9461They are of types that have been declared equivalent via a @code{TYPE
9462@var{t1} = @var{t2}} statement
9463
9464@item
9465They have been declared on the same line. (Note: This is true of the
9466@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9467@end itemize
9468
9469As long as type checking is enabled, any attempt to combine variables
9470whose types are not equivalent is an error.
9471
9472Range checking is done on all mathematical operations, assignment, array
9473index bounds, and all built-in functions and procedures.
9474
6d2ebf8b 9475@node M2 Scope
c906108c
SS
9476@subsubsection The scope operators @code{::} and @code{.}
9477@cindex scope
41afff9a 9478@cindex @code{.}, Modula-2 scope operator
c906108c
SS
9479@cindex colon, doubled as scope operator
9480@ifinfo
41afff9a 9481@vindex colon-colon@r{, in Modula-2}
c906108c
SS
9482@c Info cannot handle :: but TeX can.
9483@end ifinfo
9484@iftex
41afff9a 9485@vindex ::@r{, in Modula-2}
c906108c
SS
9486@end iftex
9487
9488There are a few subtle differences between the Modula-2 scope operator
9489(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9490similar syntax:
9491
474c8240 9492@smallexample
c906108c
SS
9493
9494@var{module} . @var{id}
9495@var{scope} :: @var{id}
474c8240 9496@end smallexample
c906108c
SS
9497
9498@noindent
9499where @var{scope} is the name of a module or a procedure,
9500@var{module} the name of a module, and @var{id} is any declared
9501identifier within your program, except another module.
9502
9503Using the @code{::} operator makes @value{GDBN} search the scope
9504specified by @var{scope} for the identifier @var{id}. If it is not
9505found in the specified scope, then @value{GDBN} searches all scopes
9506enclosing the one specified by @var{scope}.
9507
9508Using the @code{.} operator makes @value{GDBN} search the current scope for
9509the identifier specified by @var{id} that was imported from the
9510definition module specified by @var{module}. With this operator, it is
9511an error if the identifier @var{id} was not imported from definition
9512module @var{module}, or if @var{id} is not an identifier in
9513@var{module}.
9514
6d2ebf8b 9515@node GDB/M2
c906108c
SS
9516@subsubsection @value{GDBN} and Modula-2
9517
9518Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9519Five subcommands of @code{set print} and @code{show print} apply
b37052ae 9520specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 9521@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 9522apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
9523analogue in Modula-2.
9524
9525The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 9526with any language, is not useful with Modula-2. Its
c906108c 9527intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 9528created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 9529address can be specified by an integral constant, the construct
d4f3574e 9530@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
9531
9532@cindex @code{#} in Modula-2
9533In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9534interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 9535
e07c999f
PH
9536@node Ada
9537@subsection Ada
9538@cindex Ada
9539
9540The extensions made to @value{GDBN} for Ada only support
9541output from the @sc{gnu} Ada (GNAT) compiler.
9542Other Ada compilers are not currently supported, and
9543attempting to debug executables produced by them is most likely
9544to be difficult.
9545
9546
9547@cindex expressions in Ada
9548@menu
9549* Ada Mode Intro:: General remarks on the Ada syntax
9550 and semantics supported by Ada mode
9551 in @value{GDBN}.
9552* Omissions from Ada:: Restrictions on the Ada expression syntax.
9553* Additions to Ada:: Extensions of the Ada expression syntax.
9554* Stopping Before Main Program:: Debugging the program during elaboration.
9555* Ada Glitches:: Known peculiarities of Ada mode.
9556@end menu
9557
9558@node Ada Mode Intro
9559@subsubsection Introduction
9560@cindex Ada mode, general
9561
9562The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9563syntax, with some extensions.
9564The philosophy behind the design of this subset is
9565
9566@itemize @bullet
9567@item
9568That @value{GDBN} should provide basic literals and access to operations for
9569arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9570leaving more sophisticated computations to subprograms written into the
9571program (which therefore may be called from @value{GDBN}).
9572
9573@item
9574That type safety and strict adherence to Ada language restrictions
9575are not particularly important to the @value{GDBN} user.
9576
9577@item
9578That brevity is important to the @value{GDBN} user.
9579@end itemize
9580
9581Thus, for brevity, the debugger acts as if there were
9582implicit @code{with} and @code{use} clauses in effect for all user-written
9583packages, making it unnecessary to fully qualify most names with
9584their packages, regardless of context. Where this causes ambiguity,
9585@value{GDBN} asks the user's intent.
9586
9587The debugger will start in Ada mode if it detects an Ada main program.
9588As for other languages, it will enter Ada mode when stopped in a program that
9589was translated from an Ada source file.
9590
9591While in Ada mode, you may use `@t{--}' for comments. This is useful
9592mostly for documenting command files. The standard @value{GDBN} comment
9593(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9594middle (to allow based literals).
9595
9596The debugger supports limited overloading. Given a subprogram call in which
9597the function symbol has multiple definitions, it will use the number of
9598actual parameters and some information about their types to attempt to narrow
9599the set of definitions. It also makes very limited use of context, preferring
9600procedures to functions in the context of the @code{call} command, and
9601functions to procedures elsewhere.
9602
9603@node Omissions from Ada
9604@subsubsection Omissions from Ada
9605@cindex Ada, omissions from
9606
9607Here are the notable omissions from the subset:
9608
9609@itemize @bullet
9610@item
9611Only a subset of the attributes are supported:
9612
9613@itemize @minus
9614@item
9615@t{'First}, @t{'Last}, and @t{'Length}
9616 on array objects (not on types and subtypes).
9617
9618@item
9619@t{'Min} and @t{'Max}.
9620
9621@item
9622@t{'Pos} and @t{'Val}.
9623
9624@item
9625@t{'Tag}.
9626
9627@item
9628@t{'Range} on array objects (not subtypes), but only as the right
9629operand of the membership (@code{in}) operator.
9630
9631@item
9632@t{'Access}, @t{'Unchecked_Access}, and
9633@t{'Unrestricted_Access} (a GNAT extension).
9634
9635@item
9636@t{'Address}.
9637@end itemize
9638
9639@item
9640The names in
9641@code{Characters.Latin_1} are not available and
9642concatenation is not implemented. Thus, escape characters in strings are
9643not currently available.
9644
9645@item
9646Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9647equality of representations. They will generally work correctly
9648for strings and arrays whose elements have integer or enumeration types.
9649They may not work correctly for arrays whose element
9650types have user-defined equality, for arrays of real values
9651(in particular, IEEE-conformant floating point, because of negative
9652zeroes and NaNs), and for arrays whose elements contain unused bits with
9653indeterminate values.
9654
9655@item
9656The other component-by-component array operations (@code{and}, @code{or},
9657@code{xor}, @code{not}, and relational tests other than equality)
9658are not implemented.
9659
9660@item
9661There are no record or array aggregates.
9662
9663@item
9664Calls to dispatching subprograms are not implemented.
9665
9666@item
9667The overloading algorithm is much more limited (i.e., less selective)
9668than that of real Ada. It makes only limited use of the context in which a subexpression
9669appears to resolve its meaning, and it is much looser in its rules for allowing
9670type matches. As a result, some function calls will be ambiguous, and the user
9671will be asked to choose the proper resolution.
9672
9673@item
9674The @code{new} operator is not implemented.
9675
9676@item
9677Entry calls are not implemented.
9678
9679@item
9680Aside from printing, arithmetic operations on the native VAX floating-point
9681formats are not supported.
9682
9683@item
9684It is not possible to slice a packed array.
9685@end itemize
9686
9687@node Additions to Ada
9688@subsubsection Additions to Ada
9689@cindex Ada, deviations from
9690
9691As it does for other languages, @value{GDBN} makes certain generic
9692extensions to Ada (@pxref{Expressions}):
9693
9694@itemize @bullet
9695@item
9696If the expression @var{E} is a variable residing in memory
9697(typically a local variable or array element) and @var{N} is
9698a positive integer, then @code{@var{E}@@@var{N}} displays the values of
9699@var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
9700In Ada, this operator is generally not necessary, since its prime use
9701is in displaying parts of an array, and slicing will usually do this in Ada.
9702However, there are occasional uses when debugging programs
9703in which certain debugging information has been optimized away.
9704
9705@item
9706@code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
9707in function or file @var{B}.'' When @var{B} is a file name, you must typically
9708surround it in single quotes.
9709
9710@item
9711The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
9712@var{type} that appears at address @var{addr}.''
9713
9714@item
9715A name starting with @samp{$} is a convenience variable
9716(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
9717@end itemize
9718
9719In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
9720to Ada:
9721
9722@itemize @bullet
9723@item
9724The assignment statement is allowed as an expression, returning
9725its right-hand operand as its value. Thus, you may enter
9726
9727@smallexample
9728set x := y + 3
9729print A(tmp := y + 1)
9730@end smallexample
9731
9732@item
9733The semicolon is allowed as an ``operator,'' returning as its value
9734the value of its right-hand operand.
9735This allows, for example,
9736complex conditional breaks:
9737
9738@smallexample
9739break f
9740condition 1 (report(i); k += 1; A(k) > 100)
9741@end smallexample
9742
9743@item
9744Rather than use catenation and symbolic character names to introduce special
9745characters into strings, one may instead use a special bracket notation,
9746which is also used to print strings. A sequence of characters of the form
9747@samp{["@var{XX}"]} within a string or character literal denotes the
9748(single) character whose numeric encoding is @var{XX} in hexadecimal. The
9749sequence of characters @samp{["""]} also denotes a single quotation mark
9750in strings. For example,
9751@smallexample
9752 "One line.["0a"]Next line.["0a"]"
9753@end smallexample
9754@noindent
9755contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
9756period.
9757
9758@item
9759The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
9760@t{'Max} is optional (and is ignored in any case). For example, it is valid
9761to write
9762
9763@smallexample
9764print 'max(x, y)
9765@end smallexample
9766
9767@item
9768When printing arrays, @value{GDBN} uses positional notation when the
9769array has a lower bound of 1, and uses a modified named notation otherwise.
9770For example, a one-dimensional array of three integers with a lower bound of 3 might print as
9771
9772@smallexample
9773(3 => 10, 17, 1)
9774@end smallexample
9775
9776@noindent
9777That is, in contrast to valid Ada, only the first component has a @code{=>}
9778clause.
9779
9780@item
9781You may abbreviate attributes in expressions with any unique,
9782multi-character subsequence of
9783their names (an exact match gets preference).
9784For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
9785in place of @t{a'length}.
9786
9787@item
9788@cindex quoting Ada internal identifiers
9789Since Ada is case-insensitive, the debugger normally maps identifiers you type
9790to lower case. The GNAT compiler uses upper-case characters for
9791some of its internal identifiers, which are normally of no interest to users.
9792For the rare occasions when you actually have to look at them,
9793enclose them in angle brackets to avoid the lower-case mapping.
9794For example,
9795@smallexample
9796@value{GDBP} print <JMPBUF_SAVE>[0]
9797@end smallexample
9798
9799@item
9800Printing an object of class-wide type or dereferencing an
9801access-to-class-wide value will display all the components of the object's
9802specific type (as indicated by its run-time tag). Likewise, component
9803selection on such a value will operate on the specific type of the
9804object.
9805
9806@end itemize
9807
9808@node Stopping Before Main Program
9809@subsubsection Stopping at the Very Beginning
9810
9811@cindex breakpointing Ada elaboration code
9812It is sometimes necessary to debug the program during elaboration, and
9813before reaching the main procedure.
9814As defined in the Ada Reference
9815Manual, the elaboration code is invoked from a procedure called
9816@code{adainit}. To run your program up to the beginning of
9817elaboration, simply use the following two commands:
9818@code{tbreak adainit} and @code{run}.
9819
9820@node Ada Glitches
9821@subsubsection Known Peculiarities of Ada Mode
9822@cindex Ada, problems
9823
9824Besides the omissions listed previously (@pxref{Omissions from Ada}),
9825we know of several problems with and limitations of Ada mode in
9826@value{GDBN},
9827some of which will be fixed with planned future releases of the debugger
9828and the GNU Ada compiler.
9829
9830@itemize @bullet
9831@item
9832Currently, the debugger
9833has insufficient information to determine whether certain pointers represent
9834pointers to objects or the objects themselves.
9835Thus, the user may have to tack an extra @code{.all} after an expression
9836to get it printed properly.
9837
9838@item
9839Static constants that the compiler chooses not to materialize as objects in
9840storage are invisible to the debugger.
9841
9842@item
9843Named parameter associations in function argument lists are ignored (the
9844argument lists are treated as positional).
9845
9846@item
9847Many useful library packages are currently invisible to the debugger.
9848
9849@item
9850Fixed-point arithmetic, conversions, input, and output is carried out using
9851floating-point arithmetic, and may give results that only approximate those on
9852the host machine.
9853
9854@item
9855The type of the @t{'Address} attribute may not be @code{System.Address}.
9856
9857@item
9858The GNAT compiler never generates the prefix @code{Standard} for any of
9859the standard symbols defined by the Ada language. @value{GDBN} knows about
9860this: it will strip the prefix from names when you use it, and will never
9861look for a name you have so qualified among local symbols, nor match against
9862symbols in other packages or subprograms. If you have
9863defined entities anywhere in your program other than parameters and
9864local variables whose simple names match names in @code{Standard},
9865GNAT's lack of qualification here can cause confusion. When this happens,
9866you can usually resolve the confusion
9867by qualifying the problematic names with package
9868@code{Standard} explicitly.
9869@end itemize
9870
4e562065
JB
9871@node Unsupported languages
9872@section Unsupported languages
9873
9874@cindex unsupported languages
9875@cindex minimal language
9876In addition to the other fully-supported programming languages,
9877@value{GDBN} also provides a pseudo-language, called @code{minimal}.
9878It does not represent a real programming language, but provides a set
9879of capabilities close to what the C or assembly languages provide.
9880This should allow most simple operations to be performed while debugging
9881an application that uses a language currently not supported by @value{GDBN}.
9882
9883If the language is set to @code{auto}, @value{GDBN} will automatically
9884select this language if the current frame corresponds to an unsupported
9885language.
9886
6d2ebf8b 9887@node Symbols
c906108c
SS
9888@chapter Examining the Symbol Table
9889
d4f3574e 9890The commands described in this chapter allow you to inquire about the
c906108c
SS
9891symbols (names of variables, functions and types) defined in your
9892program. This information is inherent in the text of your program and
9893does not change as your program executes. @value{GDBN} finds it in your
9894program's symbol table, in the file indicated when you started @value{GDBN}
9895(@pxref{File Options, ,Choosing files}), or by one of the
9896file-management commands (@pxref{Files, ,Commands to specify files}).
9897
9898@cindex symbol names
9899@cindex names of symbols
9900@cindex quoting names
9901Occasionally, you may need to refer to symbols that contain unusual
9902characters, which @value{GDBN} ordinarily treats as word delimiters. The
9903most frequent case is in referring to static variables in other
9904source files (@pxref{Variables,,Program variables}). File names
9905are recorded in object files as debugging symbols, but @value{GDBN} would
9906ordinarily parse a typical file name, like @file{foo.c}, as the three words
9907@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
9908@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
9909
474c8240 9910@smallexample
c906108c 9911p 'foo.c'::x
474c8240 9912@end smallexample
c906108c
SS
9913
9914@noindent
9915looks up the value of @code{x} in the scope of the file @file{foo.c}.
9916
9917@table @code
a8f24a35
EZ
9918@cindex case-insensitive symbol names
9919@cindex case sensitivity in symbol names
9920@kindex set case-sensitive
9921@item set case-sensitive on
9922@itemx set case-sensitive off
9923@itemx set case-sensitive auto
9924Normally, when @value{GDBN} looks up symbols, it matches their names
9925with case sensitivity determined by the current source language.
9926Occasionally, you may wish to control that. The command @code{set
9927case-sensitive} lets you do that by specifying @code{on} for
9928case-sensitive matches or @code{off} for case-insensitive ones. If
9929you specify @code{auto}, case sensitivity is reset to the default
9930suitable for the source language. The default is case-sensitive
9931matches for all languages except for Fortran, for which the default is
9932case-insensitive matches.
9933
9c16f35a
EZ
9934@kindex show case-sensitive
9935@item show case-sensitive
a8f24a35
EZ
9936This command shows the current setting of case sensitivity for symbols
9937lookups.
9938
c906108c 9939@kindex info address
b37052ae 9940@cindex address of a symbol
c906108c
SS
9941@item info address @var{symbol}
9942Describe where the data for @var{symbol} is stored. For a register
9943variable, this says which register it is kept in. For a non-register
9944local variable, this prints the stack-frame offset at which the variable
9945is always stored.
9946
9947Note the contrast with @samp{print &@var{symbol}}, which does not work
9948at all for a register variable, and for a stack local variable prints
9949the exact address of the current instantiation of the variable.
9950
3d67e040 9951@kindex info symbol
b37052ae 9952@cindex symbol from address
9c16f35a 9953@cindex closest symbol and offset for an address
3d67e040
EZ
9954@item info symbol @var{addr}
9955Print the name of a symbol which is stored at the address @var{addr}.
9956If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
9957nearest symbol and an offset from it:
9958
474c8240 9959@smallexample
3d67e040
EZ
9960(@value{GDBP}) info symbol 0x54320
9961_initialize_vx + 396 in section .text
474c8240 9962@end smallexample
3d67e040
EZ
9963
9964@noindent
9965This is the opposite of the @code{info address} command. You can use
9966it to find out the name of a variable or a function given its address.
9967
c906108c 9968@kindex whatis
d4f3574e
SS
9969@item whatis @var{expr}
9970Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
9971actually evaluated, and any side-effecting operations (such as
9972assignments or function calls) inside it do not take place.
9973@xref{Expressions, ,Expressions}.
9974
9975@item whatis
9976Print the data type of @code{$}, the last value in the value history.
9977
9978@kindex ptype
9979@item ptype @var{typename}
9980Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
9981the name of a type, or for C code it may have the form @samp{class
9982@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
9983@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 9984
d4f3574e 9985@item ptype @var{expr}
c906108c 9986@itemx ptype
d4f3574e 9987Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
9988differs from @code{whatis} by printing a detailed description, instead
9989of just the name of the type.
9990
9991For example, for this variable declaration:
9992
474c8240 9993@smallexample
c906108c 9994struct complex @{double real; double imag;@} v;
474c8240 9995@end smallexample
c906108c
SS
9996
9997@noindent
9998the two commands give this output:
9999
474c8240 10000@smallexample
c906108c
SS
10001@group
10002(@value{GDBP}) whatis v
10003type = struct complex
10004(@value{GDBP}) ptype v
10005type = struct complex @{
10006 double real;
10007 double imag;
10008@}
10009@end group
474c8240 10010@end smallexample
c906108c
SS
10011
10012@noindent
10013As with @code{whatis}, using @code{ptype} without an argument refers to
10014the type of @code{$}, the last value in the value history.
10015
ab1adacd
EZ
10016@cindex incomplete type
10017Sometimes, programs use opaque data types or incomplete specifications
10018of complex data structure. If the debug information included in the
10019program does not allow @value{GDBN} to display a full declaration of
10020the data type, it will say @samp{<incomplete type>}. For example,
10021given these declarations:
10022
10023@smallexample
10024 struct foo;
10025 struct foo *fooptr;
10026@end smallexample
10027
10028@noindent
10029but no definition for @code{struct foo} itself, @value{GDBN} will say:
10030
10031@smallexample
10032 (gdb) ptype foo
10033 $1 = <incomplete type>
10034@end smallexample
10035
10036@noindent
10037``Incomplete type'' is C terminology for data types that are not
10038completely specified.
10039
c906108c
SS
10040@kindex info types
10041@item info types @var{regexp}
10042@itemx info types
09d4efe1
EZ
10043Print a brief description of all types whose names match the regular
10044expression @var{regexp} (or all types in your program, if you supply
10045no argument). Each complete typename is matched as though it were a
10046complete line; thus, @samp{i type value} gives information on all
10047types in your program whose names include the string @code{value}, but
10048@samp{i type ^value$} gives information only on types whose complete
10049name is @code{value}.
c906108c
SS
10050
10051This command differs from @code{ptype} in two ways: first, like
10052@code{whatis}, it does not print a detailed description; second, it
10053lists all source files where a type is defined.
10054
b37052ae
EZ
10055@kindex info scope
10056@cindex local variables
09d4efe1 10057@item info scope @var{location}
b37052ae 10058List all the variables local to a particular scope. This command
09d4efe1
EZ
10059accepts a @var{location} argument---a function name, a source line, or
10060an address preceded by a @samp{*}, and prints all the variables local
10061to the scope defined by that location. For example:
b37052ae
EZ
10062
10063@smallexample
10064(@value{GDBP}) @b{info scope command_line_handler}
10065Scope for command_line_handler:
10066Symbol rl is an argument at stack/frame offset 8, length 4.
10067Symbol linebuffer is in static storage at address 0x150a18, length 4.
10068Symbol linelength is in static storage at address 0x150a1c, length 4.
10069Symbol p is a local variable in register $esi, length 4.
10070Symbol p1 is a local variable in register $ebx, length 4.
10071Symbol nline is a local variable in register $edx, length 4.
10072Symbol repeat is a local variable at frame offset -8, length 4.
10073@end smallexample
10074
f5c37c66
EZ
10075@noindent
10076This command is especially useful for determining what data to collect
10077during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
10078collect}.
10079
c906108c
SS
10080@kindex info source
10081@item info source
919d772c
JB
10082Show information about the current source file---that is, the source file for
10083the function containing the current point of execution:
10084@itemize @bullet
10085@item
10086the name of the source file, and the directory containing it,
10087@item
10088the directory it was compiled in,
10089@item
10090its length, in lines,
10091@item
10092which programming language it is written in,
10093@item
10094whether the executable includes debugging information for that file, and
10095if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
10096@item
10097whether the debugging information includes information about
10098preprocessor macros.
10099@end itemize
10100
c906108c
SS
10101
10102@kindex info sources
10103@item info sources
10104Print the names of all source files in your program for which there is
10105debugging information, organized into two lists: files whose symbols
10106have already been read, and files whose symbols will be read when needed.
10107
10108@kindex info functions
10109@item info functions
10110Print the names and data types of all defined functions.
10111
10112@item info functions @var{regexp}
10113Print the names and data types of all defined functions
10114whose names contain a match for regular expression @var{regexp}.
10115Thus, @samp{info fun step} finds all functions whose names
10116include @code{step}; @samp{info fun ^step} finds those whose names
b383017d
RM
10117start with @code{step}. If a function name contains characters
10118that conflict with the regular expression language (eg.
1c5dfdad 10119@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
10120
10121@kindex info variables
10122@item info variables
10123Print the names and data types of all variables that are declared
6ca652b0 10124outside of functions (i.e.@: excluding local variables).
c906108c
SS
10125
10126@item info variables @var{regexp}
10127Print the names and data types of all variables (except for local
10128variables) whose names contain a match for regular expression
10129@var{regexp}.
10130
b37303ee 10131@kindex info classes
721c2651 10132@cindex Objective-C, classes and selectors
b37303ee
AF
10133@item info classes
10134@itemx info classes @var{regexp}
10135Display all Objective-C classes in your program, or
10136(with the @var{regexp} argument) all those matching a particular regular
10137expression.
10138
10139@kindex info selectors
10140@item info selectors
10141@itemx info selectors @var{regexp}
10142Display all Objective-C selectors in your program, or
10143(with the @var{regexp} argument) all those matching a particular regular
10144expression.
10145
c906108c
SS
10146@ignore
10147This was never implemented.
10148@kindex info methods
10149@item info methods
10150@itemx info methods @var{regexp}
10151The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
10152methods within C@t{++} program, or (with the @var{regexp} argument) a
10153specific set of methods found in the various C@t{++} classes. Many
10154C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
10155from the @code{ptype} command can be overwhelming and hard to use. The
10156@code{info-methods} command filters the methods, printing only those
10157which match the regular-expression @var{regexp}.
10158@end ignore
10159
c906108c
SS
10160@cindex reloading symbols
10161Some systems allow individual object files that make up your program to
7a292a7a
SS
10162be replaced without stopping and restarting your program. For example,
10163in VxWorks you can simply recompile a defective object file and keep on
10164running. If you are running on one of these systems, you can allow
10165@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
10166
10167@table @code
10168@kindex set symbol-reloading
10169@item set symbol-reloading on
10170Replace symbol definitions for the corresponding source file when an
10171object file with a particular name is seen again.
10172
10173@item set symbol-reloading off
6d2ebf8b
SS
10174Do not replace symbol definitions when encountering object files of the
10175same name more than once. This is the default state; if you are not
10176running on a system that permits automatic relinking of modules, you
10177should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
10178may discard symbols when linking large programs, that may contain
10179several modules (from different directories or libraries) with the same
10180name.
c906108c
SS
10181
10182@kindex show symbol-reloading
10183@item show symbol-reloading
10184Show the current @code{on} or @code{off} setting.
10185@end table
c906108c 10186
9c16f35a 10187@cindex opaque data types
c906108c
SS
10188@kindex set opaque-type-resolution
10189@item set opaque-type-resolution on
10190Tell @value{GDBN} to resolve opaque types. An opaque type is a type
10191declared as a pointer to a @code{struct}, @code{class}, or
10192@code{union}---for example, @code{struct MyType *}---that is used in one
10193source file although the full declaration of @code{struct MyType} is in
10194another source file. The default is on.
10195
10196A change in the setting of this subcommand will not take effect until
10197the next time symbols for a file are loaded.
10198
10199@item set opaque-type-resolution off
10200Tell @value{GDBN} not to resolve opaque types. In this case, the type
10201is printed as follows:
10202@smallexample
10203@{<no data fields>@}
10204@end smallexample
10205
10206@kindex show opaque-type-resolution
10207@item show opaque-type-resolution
10208Show whether opaque types are resolved or not.
c906108c
SS
10209
10210@kindex maint print symbols
10211@cindex symbol dump
10212@kindex maint print psymbols
10213@cindex partial symbol dump
10214@item maint print symbols @var{filename}
10215@itemx maint print psymbols @var{filename}
10216@itemx maint print msymbols @var{filename}
10217Write a dump of debugging symbol data into the file @var{filename}.
10218These commands are used to debug the @value{GDBN} symbol-reading code. Only
10219symbols with debugging data are included. If you use @samp{maint print
10220symbols}, @value{GDBN} includes all the symbols for which it has already
10221collected full details: that is, @var{filename} reflects symbols for
10222only those files whose symbols @value{GDBN} has read. You can use the
10223command @code{info sources} to find out which files these are. If you
10224use @samp{maint print psymbols} instead, the dump shows information about
10225symbols that @value{GDBN} only knows partially---that is, symbols defined in
10226files that @value{GDBN} has skimmed, but not yet read completely. Finally,
10227@samp{maint print msymbols} dumps just the minimal symbol information
10228required for each object file from which @value{GDBN} has read some symbols.
10229@xref{Files, ,Commands to specify files}, for a discussion of how
10230@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 10231
5e7b2f39
JB
10232@kindex maint info symtabs
10233@kindex maint info psymtabs
44ea7b70
JB
10234@cindex listing @value{GDBN}'s internal symbol tables
10235@cindex symbol tables, listing @value{GDBN}'s internal
10236@cindex full symbol tables, listing @value{GDBN}'s internal
10237@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
10238@item maint info symtabs @r{[} @var{regexp} @r{]}
10239@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
10240
10241List the @code{struct symtab} or @code{struct partial_symtab}
10242structures whose names match @var{regexp}. If @var{regexp} is not
10243given, list them all. The output includes expressions which you can
10244copy into a @value{GDBN} debugging this one to examine a particular
10245structure in more detail. For example:
10246
10247@smallexample
5e7b2f39 10248(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
10249@{ objfile /home/gnu/build/gdb/gdb
10250 ((struct objfile *) 0x82e69d0)
b383017d 10251 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10252 ((struct partial_symtab *) 0x8474b10)
10253 readin no
10254 fullname (null)
10255 text addresses 0x814d3c8 -- 0x8158074
10256 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
10257 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
10258 dependencies (none)
10259 @}
10260@}
5e7b2f39 10261(@value{GDBP}) maint info symtabs
44ea7b70
JB
10262(@value{GDBP})
10263@end smallexample
10264@noindent
10265We see that there is one partial symbol table whose filename contains
10266the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
10267and we see that @value{GDBN} has not read in any symtabs yet at all.
10268If we set a breakpoint on a function, that will cause @value{GDBN} to
10269read the symtab for the compilation unit containing that function:
10270
10271@smallexample
10272(@value{GDBP}) break dwarf2_psymtab_to_symtab
10273Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
10274line 1574.
5e7b2f39 10275(@value{GDBP}) maint info symtabs
b383017d 10276@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 10277 ((struct objfile *) 0x82e69d0)
b383017d 10278 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10279 ((struct symtab *) 0x86c1f38)
10280 dirname (null)
10281 fullname (null)
10282 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
10283 debugformat DWARF 2
10284 @}
10285@}
b383017d 10286(@value{GDBP})
44ea7b70 10287@end smallexample
c906108c
SS
10288@end table
10289
44ea7b70 10290
6d2ebf8b 10291@node Altering
c906108c
SS
10292@chapter Altering Execution
10293
10294Once you think you have found an error in your program, you might want to
10295find out for certain whether correcting the apparent error would lead to
10296correct results in the rest of the run. You can find the answer by
10297experiment, using the @value{GDBN} features for altering execution of the
10298program.
10299
10300For example, you can store new values into variables or memory
7a292a7a
SS
10301locations, give your program a signal, restart it at a different
10302address, or even return prematurely from a function.
c906108c
SS
10303
10304@menu
10305* Assignment:: Assignment to variables
10306* Jumping:: Continuing at a different address
c906108c 10307* Signaling:: Giving your program a signal
c906108c
SS
10308* Returning:: Returning from a function
10309* Calling:: Calling your program's functions
10310* Patching:: Patching your program
10311@end menu
10312
6d2ebf8b 10313@node Assignment
c906108c
SS
10314@section Assignment to variables
10315
10316@cindex assignment
10317@cindex setting variables
10318To alter the value of a variable, evaluate an assignment expression.
10319@xref{Expressions, ,Expressions}. For example,
10320
474c8240 10321@smallexample
c906108c 10322print x=4
474c8240 10323@end smallexample
c906108c
SS
10324
10325@noindent
10326stores the value 4 into the variable @code{x}, and then prints the
5d161b24 10327value of the assignment expression (which is 4).
c906108c
SS
10328@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
10329information on operators in supported languages.
c906108c
SS
10330
10331@kindex set variable
10332@cindex variables, setting
10333If you are not interested in seeing the value of the assignment, use the
10334@code{set} command instead of the @code{print} command. @code{set} is
10335really the same as @code{print} except that the expression's value is
10336not printed and is not put in the value history (@pxref{Value History,
10337,Value history}). The expression is evaluated only for its effects.
10338
c906108c
SS
10339If the beginning of the argument string of the @code{set} command
10340appears identical to a @code{set} subcommand, use the @code{set
10341variable} command instead of just @code{set}. This command is identical
10342to @code{set} except for its lack of subcommands. For example, if your
10343program has a variable @code{width}, you get an error if you try to set
10344a new value with just @samp{set width=13}, because @value{GDBN} has the
10345command @code{set width}:
10346
474c8240 10347@smallexample
c906108c
SS
10348(@value{GDBP}) whatis width
10349type = double
10350(@value{GDBP}) p width
10351$4 = 13
10352(@value{GDBP}) set width=47
10353Invalid syntax in expression.
474c8240 10354@end smallexample
c906108c
SS
10355
10356@noindent
10357The invalid expression, of course, is @samp{=47}. In
10358order to actually set the program's variable @code{width}, use
10359
474c8240 10360@smallexample
c906108c 10361(@value{GDBP}) set var width=47
474c8240 10362@end smallexample
53a5351d 10363
c906108c
SS
10364Because the @code{set} command has many subcommands that can conflict
10365with the names of program variables, it is a good idea to use the
10366@code{set variable} command instead of just @code{set}. For example, if
10367your program has a variable @code{g}, you run into problems if you try
10368to set a new value with just @samp{set g=4}, because @value{GDBN} has
10369the command @code{set gnutarget}, abbreviated @code{set g}:
10370
474c8240 10371@smallexample
c906108c
SS
10372@group
10373(@value{GDBP}) whatis g
10374type = double
10375(@value{GDBP}) p g
10376$1 = 1
10377(@value{GDBP}) set g=4
2df3850c 10378(@value{GDBP}) p g
c906108c
SS
10379$2 = 1
10380(@value{GDBP}) r
10381The program being debugged has been started already.
10382Start it from the beginning? (y or n) y
10383Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
10384"/home/smith/cc_progs/a.out": can't open to read symbols:
10385 Invalid bfd target.
c906108c
SS
10386(@value{GDBP}) show g
10387The current BFD target is "=4".
10388@end group
474c8240 10389@end smallexample
c906108c
SS
10390
10391@noindent
10392The program variable @code{g} did not change, and you silently set the
10393@code{gnutarget} to an invalid value. In order to set the variable
10394@code{g}, use
10395
474c8240 10396@smallexample
c906108c 10397(@value{GDBP}) set var g=4
474c8240 10398@end smallexample
c906108c
SS
10399
10400@value{GDBN} allows more implicit conversions in assignments than C; you can
10401freely store an integer value into a pointer variable or vice versa,
10402and you can convert any structure to any other structure that is the
10403same length or shorter.
10404@comment FIXME: how do structs align/pad in these conversions?
10405@comment /doc@cygnus.com 18dec1990
10406
10407To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
10408construct to generate a value of specified type at a specified address
10409(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
10410to memory location @code{0x83040} as an integer (which implies a certain size
10411and representation in memory), and
10412
474c8240 10413@smallexample
c906108c 10414set @{int@}0x83040 = 4
474c8240 10415@end smallexample
c906108c
SS
10416
10417@noindent
10418stores the value 4 into that memory location.
10419
6d2ebf8b 10420@node Jumping
c906108c
SS
10421@section Continuing at a different address
10422
10423Ordinarily, when you continue your program, you do so at the place where
10424it stopped, with the @code{continue} command. You can instead continue at
10425an address of your own choosing, with the following commands:
10426
10427@table @code
10428@kindex jump
10429@item jump @var{linespec}
10430Resume execution at line @var{linespec}. Execution stops again
10431immediately if there is a breakpoint there. @xref{List, ,Printing
10432source lines}, for a description of the different forms of
10433@var{linespec}. It is common practice to use the @code{tbreak} command
10434in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
10435breakpoints}.
10436
10437The @code{jump} command does not change the current stack frame, or
10438the stack pointer, or the contents of any memory location or any
10439register other than the program counter. If line @var{linespec} is in
10440a different function from the one currently executing, the results may
10441be bizarre if the two functions expect different patterns of arguments or
10442of local variables. For this reason, the @code{jump} command requests
10443confirmation if the specified line is not in the function currently
10444executing. However, even bizarre results are predictable if you are
10445well acquainted with the machine-language code of your program.
10446
10447@item jump *@var{address}
10448Resume execution at the instruction at address @var{address}.
10449@end table
10450
c906108c 10451@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
10452On many systems, you can get much the same effect as the @code{jump}
10453command by storing a new value into the register @code{$pc}. The
10454difference is that this does not start your program running; it only
10455changes the address of where it @emph{will} run when you continue. For
10456example,
c906108c 10457
474c8240 10458@smallexample
c906108c 10459set $pc = 0x485
474c8240 10460@end smallexample
c906108c
SS
10461
10462@noindent
10463makes the next @code{continue} command or stepping command execute at
10464address @code{0x485}, rather than at the address where your program stopped.
10465@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
10466
10467The most common occasion to use the @code{jump} command is to back
10468up---perhaps with more breakpoints set---over a portion of a program
10469that has already executed, in order to examine its execution in more
10470detail.
10471
c906108c 10472@c @group
6d2ebf8b 10473@node Signaling
c906108c 10474@section Giving your program a signal
9c16f35a 10475@cindex deliver a signal to a program
c906108c
SS
10476
10477@table @code
10478@kindex signal
10479@item signal @var{signal}
10480Resume execution where your program stopped, but immediately give it the
10481signal @var{signal}. @var{signal} can be the name or the number of a
10482signal. For example, on many systems @code{signal 2} and @code{signal
10483SIGINT} are both ways of sending an interrupt signal.
10484
10485Alternatively, if @var{signal} is zero, continue execution without
10486giving a signal. This is useful when your program stopped on account of
10487a signal and would ordinary see the signal when resumed with the
10488@code{continue} command; @samp{signal 0} causes it to resume without a
10489signal.
10490
10491@code{signal} does not repeat when you press @key{RET} a second time
10492after executing the command.
10493@end table
10494@c @end group
10495
10496Invoking the @code{signal} command is not the same as invoking the
10497@code{kill} utility from the shell. Sending a signal with @code{kill}
10498causes @value{GDBN} to decide what to do with the signal depending on
10499the signal handling tables (@pxref{Signals}). The @code{signal} command
10500passes the signal directly to your program.
10501
c906108c 10502
6d2ebf8b 10503@node Returning
c906108c
SS
10504@section Returning from a function
10505
10506@table @code
10507@cindex returning from a function
10508@kindex return
10509@item return
10510@itemx return @var{expression}
10511You can cancel execution of a function call with the @code{return}
10512command. If you give an
10513@var{expression} argument, its value is used as the function's return
10514value.
10515@end table
10516
10517When you use @code{return}, @value{GDBN} discards the selected stack frame
10518(and all frames within it). You can think of this as making the
10519discarded frame return prematurely. If you wish to specify a value to
10520be returned, give that value as the argument to @code{return}.
10521
10522This pops the selected stack frame (@pxref{Selection, ,Selecting a
10523frame}), and any other frames inside of it, leaving its caller as the
10524innermost remaining frame. That frame becomes selected. The
10525specified value is stored in the registers used for returning values
10526of functions.
10527
10528The @code{return} command does not resume execution; it leaves the
10529program stopped in the state that would exist if the function had just
10530returned. In contrast, the @code{finish} command (@pxref{Continuing
10531and Stepping, ,Continuing and stepping}) resumes execution until the
10532selected stack frame returns naturally.
10533
6d2ebf8b 10534@node Calling
c906108c
SS
10535@section Calling program functions
10536
f8568604 10537@table @code
c906108c 10538@cindex calling functions
f8568604
EZ
10539@cindex inferior functions, calling
10540@item print @var{expr}
9c16f35a 10541Evaluate the expression @var{expr} and display the resuling value.
f8568604
EZ
10542@var{expr} may include calls to functions in the program being
10543debugged.
10544
c906108c 10545@kindex call
c906108c
SS
10546@item call @var{expr}
10547Evaluate the expression @var{expr} without displaying @code{void}
10548returned values.
c906108c
SS
10549
10550You can use this variant of the @code{print} command if you want to
f8568604
EZ
10551execute a function from your program that does not return anything
10552(a.k.a.@: @dfn{a void function}), but without cluttering the output
10553with @code{void} returned values that @value{GDBN} will otherwise
10554print. If the result is not void, it is printed and saved in the
10555value history.
10556@end table
10557
9c16f35a
EZ
10558It is possible for the function you call via the @code{print} or
10559@code{call} command to generate a signal (e.g., if there's a bug in
10560the function, or if you passed it incorrect arguments). What happens
10561in that case is controlled by the @code{set unwindonsignal} command.
10562
10563@table @code
10564@item set unwindonsignal
10565@kindex set unwindonsignal
10566@cindex unwind stack in called functions
10567@cindex call dummy stack unwinding
10568Set unwinding of the stack if a signal is received while in a function
10569that @value{GDBN} called in the program being debugged. If set to on,
10570@value{GDBN} unwinds the stack it created for the call and restores
10571the context to what it was before the call. If set to off (the
10572default), @value{GDBN} stops in the frame where the signal was
10573received.
10574
10575@item show unwindonsignal
10576@kindex show unwindonsignal
10577Show the current setting of stack unwinding in the functions called by
10578@value{GDBN}.
10579@end table
10580
f8568604
EZ
10581@cindex weak alias functions
10582Sometimes, a function you wish to call is actually a @dfn{weak alias}
10583for another function. In such case, @value{GDBN} might not pick up
10584the type information, including the types of the function arguments,
10585which causes @value{GDBN} to call the inferior function incorrectly.
10586As a result, the called function will function erroneously and may
10587even crash. A solution to that is to use the name of the aliased
10588function instead.
c906108c 10589
6d2ebf8b 10590@node Patching
c906108c 10591@section Patching programs
7a292a7a 10592
c906108c
SS
10593@cindex patching binaries
10594@cindex writing into executables
c906108c 10595@cindex writing into corefiles
c906108c 10596
7a292a7a
SS
10597By default, @value{GDBN} opens the file containing your program's
10598executable code (or the corefile) read-only. This prevents accidental
10599alterations to machine code; but it also prevents you from intentionally
10600patching your program's binary.
c906108c
SS
10601
10602If you'd like to be able to patch the binary, you can specify that
10603explicitly with the @code{set write} command. For example, you might
10604want to turn on internal debugging flags, or even to make emergency
10605repairs.
10606
10607@table @code
10608@kindex set write
10609@item set write on
10610@itemx set write off
7a292a7a
SS
10611If you specify @samp{set write on}, @value{GDBN} opens executable and
10612core files for both reading and writing; if you specify @samp{set write
c906108c
SS
10613off} (the default), @value{GDBN} opens them read-only.
10614
10615If you have already loaded a file, you must load it again (using the
7a292a7a
SS
10616@code{exec-file} or @code{core-file} command) after changing @code{set
10617write}, for your new setting to take effect.
c906108c
SS
10618
10619@item show write
10620@kindex show write
7a292a7a
SS
10621Display whether executable files and core files are opened for writing
10622as well as reading.
c906108c
SS
10623@end table
10624
6d2ebf8b 10625@node GDB Files
c906108c
SS
10626@chapter @value{GDBN} Files
10627
7a292a7a
SS
10628@value{GDBN} needs to know the file name of the program to be debugged,
10629both in order to read its symbol table and in order to start your
10630program. To debug a core dump of a previous run, you must also tell
10631@value{GDBN} the name of the core dump file.
c906108c
SS
10632
10633@menu
10634* Files:: Commands to specify files
5b5d99cf 10635* Separate Debug Files:: Debugging information in separate files
c906108c
SS
10636* Symbol Errors:: Errors reading symbol files
10637@end menu
10638
6d2ebf8b 10639@node Files
c906108c 10640@section Commands to specify files
c906108c 10641
7a292a7a 10642@cindex symbol table
c906108c 10643@cindex core dump file
7a292a7a
SS
10644
10645You may want to specify executable and core dump file names. The usual
10646way to do this is at start-up time, using the arguments to
10647@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
10648Out of @value{GDBN}}).
c906108c
SS
10649
10650Occasionally it is necessary to change to a different file during a
397ca115
EZ
10651@value{GDBN} session. Or you may run @value{GDBN} and forget to
10652specify a file you want to use. Or you are debugging a remote target
10653via @code{gdbserver} (@pxref{Server, file}). In these situations the
10654@value{GDBN} commands to specify new files are useful.
c906108c
SS
10655
10656@table @code
10657@cindex executable file
10658@kindex file
10659@item file @var{filename}
10660Use @var{filename} as the program to be debugged. It is read for its
10661symbols and for the contents of pure memory. It is also the program
10662executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
10663directory and the file is not found in the @value{GDBN} working directory,
10664@value{GDBN} uses the environment variable @code{PATH} as a list of
10665directories to search, just as the shell does when looking for a program
10666to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
10667and your program, using the @code{path} command.
10668
fc8be69e
EZ
10669@cindex unlinked object files
10670@cindex patching object files
10671You can load unlinked object @file{.o} files into @value{GDBN} using
10672the @code{file} command. You will not be able to ``run'' an object
10673file, but you can disassemble functions and inspect variables. Also,
10674if the underlying BFD functionality supports it, you could use
10675@kbd{gdb -write} to patch object files using this technique. Note
10676that @value{GDBN} can neither interpret nor modify relocations in this
10677case, so branches and some initialized variables will appear to go to
10678the wrong place. But this feature is still handy from time to time.
10679
c906108c
SS
10680@item file
10681@code{file} with no argument makes @value{GDBN} discard any information it
10682has on both executable file and the symbol table.
10683
10684@kindex exec-file
10685@item exec-file @r{[} @var{filename} @r{]}
10686Specify that the program to be run (but not the symbol table) is found
10687in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
10688if necessary to locate your program. Omitting @var{filename} means to
10689discard information on the executable file.
10690
10691@kindex symbol-file
10692@item symbol-file @r{[} @var{filename} @r{]}
10693Read symbol table information from file @var{filename}. @code{PATH} is
10694searched when necessary. Use the @code{file} command to get both symbol
10695table and program to run from the same file.
10696
10697@code{symbol-file} with no argument clears out @value{GDBN} information on your
10698program's symbol table.
10699
5d161b24 10700The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
10701of its convenience variables, the value history, and all breakpoints and
10702auto-display expressions. This is because they may contain pointers to
10703the internal data recording symbols and data types, which are part of
10704the old symbol table data being discarded inside @value{GDBN}.
10705
10706@code{symbol-file} does not repeat if you press @key{RET} again after
10707executing it once.
10708
10709When @value{GDBN} is configured for a particular environment, it
10710understands debugging information in whatever format is the standard
10711generated for that environment; you may use either a @sc{gnu} compiler, or
10712other compilers that adhere to the local conventions.
c906108c
SS
10713Best results are usually obtained from @sc{gnu} compilers; for example,
10714using @code{@value{GCC}} you can generate debugging information for
10715optimized code.
c906108c
SS
10716
10717For most kinds of object files, with the exception of old SVR3 systems
10718using COFF, the @code{symbol-file} command does not normally read the
10719symbol table in full right away. Instead, it scans the symbol table
10720quickly to find which source files and which symbols are present. The
10721details are read later, one source file at a time, as they are needed.
10722
10723The purpose of this two-stage reading strategy is to make @value{GDBN}
10724start up faster. For the most part, it is invisible except for
10725occasional pauses while the symbol table details for a particular source
10726file are being read. (The @code{set verbose} command can turn these
10727pauses into messages if desired. @xref{Messages/Warnings, ,Optional
10728warnings and messages}.)
10729
c906108c
SS
10730We have not implemented the two-stage strategy for COFF yet. When the
10731symbol table is stored in COFF format, @code{symbol-file} reads the
10732symbol table data in full right away. Note that ``stabs-in-COFF''
10733still does the two-stage strategy, since the debug info is actually
10734in stabs format.
10735
10736@kindex readnow
10737@cindex reading symbols immediately
10738@cindex symbols, reading immediately
a94ab193
EZ
10739@item symbol-file @var{filename} @r{[} -readnow @r{]}
10740@itemx file @var{filename} @r{[} -readnow @r{]}
c906108c
SS
10741You can override the @value{GDBN} two-stage strategy for reading symbol
10742tables by using the @samp{-readnow} option with any of the commands that
10743load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 10744entire symbol table available.
c906108c 10745
c906108c
SS
10746@c FIXME: for now no mention of directories, since this seems to be in
10747@c flux. 13mar1992 status is that in theory GDB would look either in
10748@c current dir or in same dir as myprog; but issues like competing
10749@c GDB's, or clutter in system dirs, mean that in practice right now
10750@c only current dir is used. FFish says maybe a special GDB hierarchy
10751@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
10752@c files.
10753
c906108c 10754@kindex core-file
09d4efe1 10755@item core-file @r{[}@var{filename}@r{]}
4644b6e3 10756@itemx core
c906108c
SS
10757Specify the whereabouts of a core dump file to be used as the ``contents
10758of memory''. Traditionally, core files contain only some parts of the
10759address space of the process that generated them; @value{GDBN} can access the
10760executable file itself for other parts.
10761
10762@code{core-file} with no argument specifies that no core file is
10763to be used.
10764
10765Note that the core file is ignored when your program is actually running
7a292a7a
SS
10766under @value{GDBN}. So, if you have been running your program and you
10767wish to debug a core file instead, you must kill the subprocess in which
10768the program is running. To do this, use the @code{kill} command
c906108c 10769(@pxref{Kill Process, ,Killing the child process}).
c906108c 10770
c906108c
SS
10771@kindex add-symbol-file
10772@cindex dynamic linking
10773@item add-symbol-file @var{filename} @var{address}
a94ab193 10774@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
17d9d558 10775@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
10776The @code{add-symbol-file} command reads additional symbol table
10777information from the file @var{filename}. You would use this command
10778when @var{filename} has been dynamically loaded (by some other means)
10779into the program that is running. @var{address} should be the memory
10780address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
10781this out for itself. You can additionally specify an arbitrary number
10782of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
10783section name and base address for that section. You can specify any
10784@var{address} as an expression.
c906108c
SS
10785
10786The symbol table of the file @var{filename} is added to the symbol table
10787originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
10788@code{add-symbol-file} command any number of times; the new symbol data
10789thus read keeps adding to the old. To discard all old symbol data
10790instead, use the @code{symbol-file} command without any arguments.
c906108c 10791
17d9d558
JB
10792@cindex relocatable object files, reading symbols from
10793@cindex object files, relocatable, reading symbols from
10794@cindex reading symbols from relocatable object files
10795@cindex symbols, reading from relocatable object files
10796@cindex @file{.o} files, reading symbols from
10797Although @var{filename} is typically a shared library file, an
10798executable file, or some other object file which has been fully
10799relocated for loading into a process, you can also load symbolic
10800information from relocatable @file{.o} files, as long as:
10801
10802@itemize @bullet
10803@item
10804the file's symbolic information refers only to linker symbols defined in
10805that file, not to symbols defined by other object files,
10806@item
10807every section the file's symbolic information refers to has actually
10808been loaded into the inferior, as it appears in the file, and
10809@item
10810you can determine the address at which every section was loaded, and
10811provide these to the @code{add-symbol-file} command.
10812@end itemize
10813
10814@noindent
10815Some embedded operating systems, like Sun Chorus and VxWorks, can load
10816relocatable files into an already running program; such systems
10817typically make the requirements above easy to meet. However, it's
10818important to recognize that many native systems use complex link
49efadf5 10819procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
10820assembly, for example) that make the requirements difficult to meet. In
10821general, one cannot assume that using @code{add-symbol-file} to read a
10822relocatable object file's symbolic information will have the same effect
10823as linking the relocatable object file into the program in the normal
10824way.
10825
c906108c
SS
10826@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
10827
c45da7e6
EZ
10828@kindex add-symbol-file-from-memory
10829@cindex @code{syscall DSO}
10830@cindex load symbols from memory
10831@item add-symbol-file-from-memory @var{address}
10832Load symbols from the given @var{address} in a dynamically loaded
10833object file whose image is mapped directly into the inferior's memory.
10834For example, the Linux kernel maps a @code{syscall DSO} into each
10835process's address space; this DSO provides kernel-specific code for
10836some system calls. The argument can be any expression whose
10837evaluation yields the address of the file's shared object file header.
10838For this command to work, you must have used @code{symbol-file} or
10839@code{exec-file} commands in advance.
10840
09d4efe1
EZ
10841@kindex add-shared-symbol-files
10842@kindex assf
10843@item add-shared-symbol-files @var{library-file}
10844@itemx assf @var{library-file}
10845The @code{add-shared-symbol-files} command can currently be used only
10846in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
10847alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
10848@value{GDBN} automatically looks for shared libraries, however if
10849@value{GDBN} does not find yours, you can invoke
10850@code{add-shared-symbol-files}. It takes one argument: the shared
10851library's file name. @code{assf} is a shorthand alias for
10852@code{add-shared-symbol-files}.
c906108c 10853
c906108c 10854@kindex section
09d4efe1
EZ
10855@item section @var{section} @var{addr}
10856The @code{section} command changes the base address of the named
10857@var{section} of the exec file to @var{addr}. This can be used if the
10858exec file does not contain section addresses, (such as in the
10859@code{a.out} format), or when the addresses specified in the file
10860itself are wrong. Each section must be changed separately. The
10861@code{info files} command, described below, lists all the sections and
10862their addresses.
c906108c
SS
10863
10864@kindex info files
10865@kindex info target
10866@item info files
10867@itemx info target
7a292a7a
SS
10868@code{info files} and @code{info target} are synonymous; both print the
10869current target (@pxref{Targets, ,Specifying a Debugging Target}),
10870including the names of the executable and core dump files currently in
10871use by @value{GDBN}, and the files from which symbols were loaded. The
10872command @code{help target} lists all possible targets rather than
10873current ones.
10874
fe95c787
MS
10875@kindex maint info sections
10876@item maint info sections
10877Another command that can give you extra information about program sections
10878is @code{maint info sections}. In addition to the section information
10879displayed by @code{info files}, this command displays the flags and file
10880offset of each section in the executable and core dump files. In addition,
10881@code{maint info sections} provides the following command options (which
10882may be arbitrarily combined):
10883
10884@table @code
10885@item ALLOBJ
10886Display sections for all loaded object files, including shared libraries.
10887@item @var{sections}
6600abed 10888Display info only for named @var{sections}.
fe95c787
MS
10889@item @var{section-flags}
10890Display info only for sections for which @var{section-flags} are true.
10891The section flags that @value{GDBN} currently knows about are:
10892@table @code
10893@item ALLOC
10894Section will have space allocated in the process when loaded.
10895Set for all sections except those containing debug information.
10896@item LOAD
10897Section will be loaded from the file into the child process memory.
10898Set for pre-initialized code and data, clear for @code{.bss} sections.
10899@item RELOC
10900Section needs to be relocated before loading.
10901@item READONLY
10902Section cannot be modified by the child process.
10903@item CODE
10904Section contains executable code only.
6600abed 10905@item DATA
fe95c787
MS
10906Section contains data only (no executable code).
10907@item ROM
10908Section will reside in ROM.
10909@item CONSTRUCTOR
10910Section contains data for constructor/destructor lists.
10911@item HAS_CONTENTS
10912Section is not empty.
10913@item NEVER_LOAD
10914An instruction to the linker to not output the section.
10915@item COFF_SHARED_LIBRARY
10916A notification to the linker that the section contains
10917COFF shared library information.
10918@item IS_COMMON
10919Section contains common symbols.
10920@end table
10921@end table
6763aef9 10922@kindex set trust-readonly-sections
9c16f35a 10923@cindex read-only sections
6763aef9
MS
10924@item set trust-readonly-sections on
10925Tell @value{GDBN} that readonly sections in your object file
6ca652b0 10926really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
10927In that case, @value{GDBN} can fetch values from these sections
10928out of the object file, rather than from the target program.
10929For some targets (notably embedded ones), this can be a significant
10930enhancement to debugging performance.
10931
10932The default is off.
10933
10934@item set trust-readonly-sections off
15110bc3 10935Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
10936the contents of the section might change while the program is running,
10937and must therefore be fetched from the target when needed.
9c16f35a
EZ
10938
10939@item show trust-readonly-sections
10940Show the current setting of trusting readonly sections.
c906108c
SS
10941@end table
10942
10943All file-specifying commands allow both absolute and relative file names
10944as arguments. @value{GDBN} always converts the file name to an absolute file
10945name and remembers it that way.
10946
c906108c 10947@cindex shared libraries
9c16f35a
EZ
10948@value{GDBN} supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
10949and IBM RS/6000 AIX shared libraries.
53a5351d 10950
c906108c
SS
10951@value{GDBN} automatically loads symbol definitions from shared libraries
10952when you use the @code{run} command, or when you examine a core file.
10953(Before you issue the @code{run} command, @value{GDBN} does not understand
10954references to a function in a shared library, however---unless you are
10955debugging a core file).
53a5351d
JM
10956
10957On HP-UX, if the program loads a library explicitly, @value{GDBN}
10958automatically loads the symbols at the time of the @code{shl_load} call.
10959
c906108c
SS
10960@c FIXME: some @value{GDBN} release may permit some refs to undef
10961@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
10962@c FIXME...lib; check this from time to time when updating manual
10963
b7209cb4
FF
10964There are times, however, when you may wish to not automatically load
10965symbol definitions from shared libraries, such as when they are
10966particularly large or there are many of them.
10967
10968To control the automatic loading of shared library symbols, use the
10969commands:
10970
10971@table @code
10972@kindex set auto-solib-add
10973@item set auto-solib-add @var{mode}
10974If @var{mode} is @code{on}, symbols from all shared object libraries
10975will be loaded automatically when the inferior begins execution, you
10976attach to an independently started inferior, or when the dynamic linker
10977informs @value{GDBN} that a new library has been loaded. If @var{mode}
10978is @code{off}, symbols must be loaded manually, using the
10979@code{sharedlibrary} command. The default value is @code{on}.
10980
dcaf7c2c
EZ
10981@cindex memory used for symbol tables
10982If your program uses lots of shared libraries with debug info that
10983takes large amounts of memory, you can decrease the @value{GDBN}
10984memory footprint by preventing it from automatically loading the
10985symbols from shared libraries. To that end, type @kbd{set
10986auto-solib-add off} before running the inferior, then load each
10987library whose debug symbols you do need with @kbd{sharedlibrary
10988@var{regexp}}, where @var{regexp} is a regular expresion that matches
10989the libraries whose symbols you want to be loaded.
10990
b7209cb4
FF
10991@kindex show auto-solib-add
10992@item show auto-solib-add
10993Display the current autoloading mode.
10994@end table
10995
c45da7e6 10996@cindex load shared library
b7209cb4
FF
10997To explicitly load shared library symbols, use the @code{sharedlibrary}
10998command:
10999
c906108c
SS
11000@table @code
11001@kindex info sharedlibrary
11002@kindex info share
11003@item info share
11004@itemx info sharedlibrary
11005Print the names of the shared libraries which are currently loaded.
11006
11007@kindex sharedlibrary
11008@kindex share
11009@item sharedlibrary @var{regex}
11010@itemx share @var{regex}
c906108c
SS
11011Load shared object library symbols for files matching a
11012Unix regular expression.
11013As with files loaded automatically, it only loads shared libraries
11014required by your program for a core file or after typing @code{run}. If
11015@var{regex} is omitted all shared libraries required by your program are
11016loaded.
c45da7e6
EZ
11017
11018@item nosharedlibrary
11019@kindex nosharedlibrary
11020@cindex unload symbols from shared libraries
11021Unload all shared object library symbols. This discards all symbols
11022that have been loaded from all shared libraries. Symbols from shared
11023libraries that were loaded by explicit user requests are not
11024discarded.
c906108c
SS
11025@end table
11026
721c2651
EZ
11027Sometimes you may wish that @value{GDBN} stops and gives you control
11028when any of shared library events happen. Use the @code{set
11029stop-on-solib-events} command for this:
11030
11031@table @code
11032@item set stop-on-solib-events
11033@kindex set stop-on-solib-events
11034This command controls whether @value{GDBN} should give you control
11035when the dynamic linker notifies it about some shared library event.
11036The most common event of interest is loading or unloading of a new
11037shared library.
11038
11039@item show stop-on-solib-events
11040@kindex show stop-on-solib-events
11041Show whether @value{GDBN} stops and gives you control when shared
11042library events happen.
11043@end table
11044
f5ebfba0
DJ
11045Shared libraries are also supported in many cross or remote debugging
11046configurations. A copy of the target's libraries need to be present on the
11047host system; they need to be the same as the target libraries, although the
11048copies on the target can be stripped as long as the copies on the host are
11049not.
11050
59b7b46f
EZ
11051@cindex where to look for shared libraries
11052For remote debugging, you need to tell @value{GDBN} where the target
11053libraries are, so that it can load the correct copies---otherwise, it
11054may try to load the host's libraries. @value{GDBN} has two variables
11055to specify the search directories for target libraries.
f5ebfba0
DJ
11056
11057@table @code
59b7b46f 11058@cindex prefix for shared library file names
f5ebfba0
DJ
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
59b7b46f
EZ
11068@cindex default value of @samp{solib-absolute-prefix}
11069@cindex @samp{--with-sysroot}
f5ebfba0
DJ
11070You can set the default value of @samp{solib-absolute-prefix} by using the
11071configure-time @samp{--with-sysroot} option.
11072
11073@kindex show solib-absolute-prefix
11074@item show solib-absolute-prefix
11075Display the current shared library prefix.
11076
11077@kindex set solib-search-path
11078@item set solib-search-path @var{path}
11079If this variable is set, @var{path} is a colon-separated list of directories
11080to search for shared libraries. @samp{solib-search-path} is used after
11081@samp{solib-absolute-prefix} fails to locate the library, or if the path to
11082the library is relative instead of absolute. If you want to use
11083@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
11084set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
11085@value{GDBN} from finding your host's libraries.
11086
11087@kindex show solib-search-path
11088@item show solib-search-path
11089Display the current shared library search path.
11090@end table
11091
5b5d99cf
JB
11092
11093@node Separate Debug Files
11094@section Debugging Information in Separate Files
11095@cindex separate debugging information files
11096@cindex debugging information in separate files
11097@cindex @file{.debug} subdirectories
11098@cindex debugging information directory, global
11099@cindex global debugging information directory
11100
11101@value{GDBN} allows you to put a program's debugging information in a
11102file separate from the executable itself, in a way that allows
11103@value{GDBN} to find and load the debugging information automatically.
11104Since debugging information can be very large --- sometimes larger
11105than the executable code itself --- some systems distribute debugging
11106information for their executables in separate files, which users can
11107install only when they need to debug a problem.
11108
11109If an executable's debugging information has been extracted to a
11110separate file, the executable should contain a @dfn{debug link} giving
11111the name of the debugging information file (with no directory
11112components), and a checksum of its contents. (The exact form of a
11113debug link is described below.) If the full name of the directory
11114containing the executable is @var{execdir}, and the executable has a
11115debug link that specifies the name @var{debugfile}, then @value{GDBN}
11116will automatically search for the debugging information file in three
11117places:
11118
11119@itemize @bullet
11120@item
11121the directory containing the executable file (that is, it will look
11122for a file named @file{@var{execdir}/@var{debugfile}},
11123@item
11124a subdirectory of that directory named @file{.debug} (that is, the
11125file @file{@var{execdir}/.debug/@var{debugfile}}, and
11126@item
11127a subdirectory of the global debug file directory that includes the
11128executable's full path, and the name from the link (that is, the file
11129@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
11130@var{globaldebugdir} is the global debug file directory, and
11131@var{execdir} has been turned into a relative path).
11132@end itemize
11133@noindent
11134@value{GDBN} checks under each of these names for a debugging
11135information file whose checksum matches that given in the link, and
11136reads the debugging information from the first one it finds.
11137
11138So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
11139which has a link containing the name @file{ls.debug}, and the global
11140debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
11141for debug information in @file{/usr/bin/ls.debug},
11142@file{/usr/bin/.debug/ls.debug}, and
11143@file{/usr/lib/debug/usr/bin/ls.debug}.
11144
11145You can set the global debugging info directory's name, and view the
11146name @value{GDBN} is currently using.
11147
11148@table @code
11149
11150@kindex set debug-file-directory
11151@item set debug-file-directory @var{directory}
11152Set the directory which @value{GDBN} searches for separate debugging
11153information files to @var{directory}.
11154
11155@kindex show debug-file-directory
11156@item show debug-file-directory
11157Show the directory @value{GDBN} searches for separate debugging
11158information files.
11159
11160@end table
11161
11162@cindex @code{.gnu_debuglink} sections
11163@cindex debug links
11164A debug link is a special section of the executable file named
11165@code{.gnu_debuglink}. The section must contain:
11166
11167@itemize
11168@item
11169A filename, with any leading directory components removed, followed by
11170a zero byte,
11171@item
11172zero to three bytes of padding, as needed to reach the next four-byte
11173boundary within the section, and
11174@item
11175a four-byte CRC checksum, stored in the same endianness used for the
11176executable file itself. The checksum is computed on the debugging
11177information file's full contents by the function given below, passing
11178zero as the @var{crc} argument.
11179@end itemize
11180
11181Any executable file format can carry a debug link, as long as it can
11182contain a section named @code{.gnu_debuglink} with the contents
11183described above.
11184
11185The debugging information file itself should be an ordinary
11186executable, containing a full set of linker symbols, sections, and
11187debugging information. The sections of the debugging information file
11188should have the same names, addresses and sizes as the original file,
11189but they need not contain any data --- much like a @code{.bss} section
11190in an ordinary executable.
11191
11192As of December 2002, there is no standard GNU utility to produce
11193separated executable / debugging information file pairs. Ulrich
11194Drepper's @file{elfutils} package, starting with version 0.53,
11195contains a version of the @code{strip} command such that the command
11196@kbd{strip foo -f foo.debug} removes the debugging information from
11197the executable file @file{foo}, places it in the file
11198@file{foo.debug}, and leaves behind a debug link in @file{foo}.
11199
11200Since there are many different ways to compute CRC's (different
11201polynomials, reversals, byte ordering, etc.), the simplest way to
11202describe the CRC used in @code{.gnu_debuglink} sections is to give the
11203complete code for a function that computes it:
11204
4644b6e3 11205@kindex gnu_debuglink_crc32
5b5d99cf
JB
11206@smallexample
11207unsigned long
11208gnu_debuglink_crc32 (unsigned long crc,
11209 unsigned char *buf, size_t len)
11210@{
11211 static const unsigned long crc32_table[256] =
11212 @{
11213 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11214 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11215 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11216 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11217 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11218 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11219 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11220 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11221 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11222 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11223 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11224 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11225 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11226 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11227 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11228 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11229 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11230 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11231 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11232 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11233 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11234 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11235 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11236 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11237 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11238 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11239 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11240 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11241 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11242 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11243 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11244 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11245 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11246 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11247 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11248 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11249 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11250 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11251 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11252 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11253 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11254 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11255 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11256 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11257 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11258 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11259 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11260 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11261 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11262 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11263 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11264 0x2d02ef8d
11265 @};
11266 unsigned char *end;
11267
11268 crc = ~crc & 0xffffffff;
11269 for (end = buf + len; buf < end; ++buf)
11270 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 11271 return ~crc & 0xffffffff;
5b5d99cf
JB
11272@}
11273@end smallexample
11274
11275
6d2ebf8b 11276@node Symbol Errors
c906108c
SS
11277@section Errors reading symbol files
11278
11279While reading a symbol file, @value{GDBN} occasionally encounters problems,
11280such as symbol types it does not recognize, or known bugs in compiler
11281output. By default, @value{GDBN} does not notify you of such problems, since
11282they are relatively common and primarily of interest to people
11283debugging compilers. If you are interested in seeing information
11284about ill-constructed symbol tables, you can either ask @value{GDBN} to print
11285only one message about each such type of problem, no matter how many
11286times the problem occurs; or you can ask @value{GDBN} to print more messages,
11287to see how many times the problems occur, with the @code{set
11288complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
11289messages}).
11290
11291The messages currently printed, and their meanings, include:
11292
11293@table @code
11294@item inner block not inside outer block in @var{symbol}
11295
11296The symbol information shows where symbol scopes begin and end
11297(such as at the start of a function or a block of statements). This
11298error indicates that an inner scope block is not fully contained
11299in its outer scope blocks.
11300
11301@value{GDBN} circumvents the problem by treating the inner block as if it had
11302the same scope as the outer block. In the error message, @var{symbol}
11303may be shown as ``@code{(don't know)}'' if the outer block is not a
11304function.
11305
11306@item block at @var{address} out of order
11307
11308The symbol information for symbol scope blocks should occur in
11309order of increasing addresses. This error indicates that it does not
11310do so.
11311
11312@value{GDBN} does not circumvent this problem, and has trouble
11313locating symbols in the source file whose symbols it is reading. (You
11314can often determine what source file is affected by specifying
11315@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
11316messages}.)
11317
11318@item bad block start address patched
11319
11320The symbol information for a symbol scope block has a start address
11321smaller than the address of the preceding source line. This is known
11322to occur in the SunOS 4.1.1 (and earlier) C compiler.
11323
11324@value{GDBN} circumvents the problem by treating the symbol scope block as
11325starting on the previous source line.
11326
11327@item bad string table offset in symbol @var{n}
11328
11329@cindex foo
11330Symbol number @var{n} contains a pointer into the string table which is
11331larger than the size of the string table.
11332
11333@value{GDBN} circumvents the problem by considering the symbol to have the
11334name @code{foo}, which may cause other problems if many symbols end up
11335with this name.
11336
11337@item unknown symbol type @code{0x@var{nn}}
11338
7a292a7a
SS
11339The symbol information contains new data types that @value{GDBN} does
11340not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 11341uncomprehended information, in hexadecimal.
c906108c 11342
7a292a7a
SS
11343@value{GDBN} circumvents the error by ignoring this symbol information.
11344This usually allows you to debug your program, though certain symbols
c906108c 11345are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
11346debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
11347on @code{complain}, then go up to the function @code{read_dbx_symtab}
11348and examine @code{*bufp} to see the symbol.
c906108c
SS
11349
11350@item stub type has NULL name
c906108c 11351
7a292a7a 11352@value{GDBN} could not find the full definition for a struct or class.
c906108c 11353
7a292a7a 11354@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 11355The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
11356information that recent versions of the compiler should have output for
11357it.
c906108c
SS
11358
11359@item info mismatch between compiler and debugger
11360
11361@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 11362
c906108c
SS
11363@end table
11364
6d2ebf8b 11365@node Targets
c906108c 11366@chapter Specifying a Debugging Target
7a292a7a 11367
c906108c 11368@cindex debugging target
c906108c 11369A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
11370
11371Often, @value{GDBN} runs in the same host environment as your program;
11372in that case, the debugging target is specified as a side effect when
11373you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
11374flexibility---for example, running @value{GDBN} on a physically separate
11375host, or controlling a standalone system over a serial port or a
53a5351d
JM
11376realtime system over a TCP/IP connection---you can use the @code{target}
11377command to specify one of the target types configured for @value{GDBN}
11378(@pxref{Target Commands, ,Commands for managing targets}).
c906108c 11379
a8f24a35
EZ
11380@cindex target architecture
11381It is possible to build @value{GDBN} for several different @dfn{target
11382architectures}. When @value{GDBN} is built like that, you can choose
11383one of the available architectures with the @kbd{set architecture}
11384command.
11385
11386@table @code
11387@kindex set architecture
11388@kindex show architecture
11389@item set architecture @var{arch}
11390This command sets the current target architecture to @var{arch}. The
11391value of @var{arch} can be @code{"auto"}, in addition to one of the
11392supported architectures.
11393
11394@item show architecture
11395Show the current target architecture.
9c16f35a
EZ
11396
11397@item set processor
11398@itemx processor
11399@kindex set processor
11400@kindex show processor
11401These are alias commands for, respectively, @code{set architecture}
11402and @code{show architecture}.
a8f24a35
EZ
11403@end table
11404
c906108c
SS
11405@menu
11406* Active Targets:: Active targets
11407* Target Commands:: Commands for managing targets
c906108c
SS
11408* Byte Order:: Choosing target byte order
11409* Remote:: Remote debugging
96baa820 11410* KOD:: Kernel Object Display
c906108c
SS
11411
11412@end menu
11413
6d2ebf8b 11414@node Active Targets
c906108c 11415@section Active targets
7a292a7a 11416
c906108c
SS
11417@cindex stacking targets
11418@cindex active targets
11419@cindex multiple targets
11420
c906108c 11421There are three classes of targets: processes, core files, and
7a292a7a
SS
11422executable files. @value{GDBN} can work concurrently on up to three
11423active targets, one in each class. This allows you to (for example)
11424start a process and inspect its activity without abandoning your work on
11425a core file.
c906108c
SS
11426
11427For example, if you execute @samp{gdb a.out}, then the executable file
11428@code{a.out} is the only active target. If you designate a core file as
11429well---presumably from a prior run that crashed and coredumped---then
11430@value{GDBN} has two active targets and uses them in tandem, looking
11431first in the corefile target, then in the executable file, to satisfy
11432requests for memory addresses. (Typically, these two classes of target
11433are complementary, since core files contain only a program's
11434read-write memory---variables and so on---plus machine status, while
11435executable files contain only the program text and initialized data.)
c906108c
SS
11436
11437When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
11438target as well. When a process target is active, all @value{GDBN}
11439commands requesting memory addresses refer to that target; addresses in
11440an active core file or executable file target are obscured while the
11441process target is active.
c906108c 11442
7a292a7a
SS
11443Use the @code{core-file} and @code{exec-file} commands to select a new
11444core file or executable target (@pxref{Files, ,Commands to specify
c906108c 11445files}). To specify as a target a process that is already running, use
7a292a7a
SS
11446the @code{attach} command (@pxref{Attach, ,Debugging an already-running
11447process}).
c906108c 11448
6d2ebf8b 11449@node Target Commands
c906108c
SS
11450@section Commands for managing targets
11451
11452@table @code
11453@item target @var{type} @var{parameters}
7a292a7a
SS
11454Connects the @value{GDBN} host environment to a target machine or
11455process. A target is typically a protocol for talking to debugging
11456facilities. You use the argument @var{type} to specify the type or
11457protocol of the target machine.
c906108c
SS
11458
11459Further @var{parameters} are interpreted by the target protocol, but
11460typically include things like device names or host names to connect
11461with, process numbers, and baud rates.
c906108c
SS
11462
11463The @code{target} command does not repeat if you press @key{RET} again
11464after executing the command.
11465
11466@kindex help target
11467@item help target
11468Displays the names of all targets available. To display targets
11469currently selected, use either @code{info target} or @code{info files}
11470(@pxref{Files, ,Commands to specify files}).
11471
11472@item help target @var{name}
11473Describe a particular target, including any parameters necessary to
11474select it.
11475
11476@kindex set gnutarget
11477@item set gnutarget @var{args}
5d161b24 11478@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 11479knows whether it is reading an @dfn{executable},
5d161b24
DB
11480a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
11481with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
11482with @code{gnutarget} the @code{target} refers to a program, not a machine.
11483
d4f3574e 11484@quotation
c906108c
SS
11485@emph{Warning:} To specify a file format with @code{set gnutarget},
11486you must know the actual BFD name.
d4f3574e 11487@end quotation
c906108c 11488
d4f3574e
SS
11489@noindent
11490@xref{Files, , Commands to specify files}.
c906108c 11491
5d161b24 11492@kindex show gnutarget
c906108c
SS
11493@item show gnutarget
11494Use the @code{show gnutarget} command to display what file format
11495@code{gnutarget} is set to read. If you have not set @code{gnutarget},
11496@value{GDBN} will determine the file format for each file automatically,
11497and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11498@end table
11499
4644b6e3 11500@cindex common targets
c906108c
SS
11501Here are some common targets (available, or not, depending on the GDB
11502configuration):
c906108c
SS
11503
11504@table @code
4644b6e3 11505@kindex target
c906108c 11506@item target exec @var{program}
4644b6e3 11507@cindex executable file target
c906108c
SS
11508An executable file. @samp{target exec @var{program}} is the same as
11509@samp{exec-file @var{program}}.
11510
c906108c 11511@item target core @var{filename}
4644b6e3 11512@cindex core dump file target
c906108c
SS
11513A core dump file. @samp{target core @var{filename}} is the same as
11514@samp{core-file @var{filename}}.
c906108c 11515
c906108c 11516@item target remote @var{dev}
4644b6e3 11517@cindex remote target
c906108c
SS
11518Remote serial target in GDB-specific protocol. The argument @var{dev}
11519specifies what serial device to use for the connection (e.g.
11520@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 11521supports the @code{load} command. This is only useful if you have
c906108c
SS
11522some other way of getting the stub to the target system, and you can put
11523it somewhere in memory where it won't get clobbered by the download.
11524
c906108c 11525@item target sim
4644b6e3 11526@cindex built-in simulator target
2df3850c 11527Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 11528In general,
474c8240 11529@smallexample
104c1213
JM
11530 target sim
11531 load
11532 run
474c8240 11533@end smallexample
d4f3574e 11534@noindent
104c1213 11535works; however, you cannot assume that a specific memory map, device
d4f3574e 11536drivers, or even basic I/O is available, although some simulators do
104c1213
JM
11537provide these. For info about any processor-specific simulator details,
11538see the appropriate section in @ref{Embedded Processors, ,Embedded
11539Processors}.
11540
c906108c
SS
11541@end table
11542
104c1213 11543Some configurations may include these targets as well:
c906108c
SS
11544
11545@table @code
11546
c906108c 11547@item target nrom @var{dev}
4644b6e3 11548@cindex NetROM ROM emulator target
c906108c
SS
11549NetROM ROM emulator. This target only supports downloading.
11550
c906108c
SS
11551@end table
11552
5d161b24 11553Different targets are available on different configurations of @value{GDBN};
c906108c 11554your configuration may have more or fewer targets.
c906108c 11555
721c2651
EZ
11556Many remote targets require you to download the executable's code once
11557you've successfully established a connection. You may wish to control
11558various aspects of this process, such as the size of the data chunks
11559used by @value{GDBN} to download program parts to the remote target.
a8f24a35
EZ
11560
11561@table @code
11562@kindex set download-write-size
11563@item set download-write-size @var{size}
11564Set the write size used when downloading a program. Only used when
11565downloading a program onto a remote target. Specify zero or a
11566negative value to disable blocked writes. The actual size of each
11567transfer is also limited by the size of the target packet and the
11568memory cache.
11569
11570@kindex show download-write-size
11571@item show download-write-size
721c2651 11572@kindex show download-write-size
a8f24a35 11573Show the current value of the write size.
721c2651
EZ
11574
11575@item set hash
11576@kindex set hash@r{, for remote monitors}
11577@cindex hash mark while downloading
11578This command controls whether a hash mark @samp{#} is displayed while
11579downloading a file to the remote monitor. If on, a hash mark is
11580displayed after each S-record is successfully downloaded to the
11581monitor.
11582
11583@item show hash
11584@kindex show hash@r{, for remote monitors}
11585Show the current status of displaying the hash mark.
11586
11587@item set debug monitor
11588@kindex set debug monitor
11589@cindex display remote monitor communications
11590Enable or disable display of communications messages between
11591@value{GDBN} and the remote monitor.
11592
11593@item show debug monitor
11594@kindex show debug monitor
11595Show the current status of displaying communications between
11596@value{GDBN} and the remote monitor.
a8f24a35 11597@end table
c906108c
SS
11598
11599@table @code
11600
11601@kindex load @var{filename}
11602@item load @var{filename}
c906108c
SS
11603Depending on what remote debugging facilities are configured into
11604@value{GDBN}, the @code{load} command may be available. Where it exists, it
11605is meant to make @var{filename} (an executable) available for debugging
11606on the remote system---by downloading, or dynamic linking, for example.
11607@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
11608the @code{add-symbol-file} command.
11609
11610If your @value{GDBN} does not have a @code{load} command, attempting to
11611execute it gets the error message ``@code{You can't do that when your
11612target is @dots{}}''
c906108c
SS
11613
11614The file is loaded at whatever address is specified in the executable.
11615For some object file formats, you can specify the load address when you
11616link the program; for other formats, like a.out, the object file format
11617specifies a fixed address.
11618@c FIXME! This would be a good place for an xref to the GNU linker doc.
11619
c906108c
SS
11620@code{load} does not repeat if you press @key{RET} again after using it.
11621@end table
11622
6d2ebf8b 11623@node Byte Order
c906108c 11624@section Choosing target byte order
7a292a7a 11625
c906108c
SS
11626@cindex choosing target byte order
11627@cindex target byte order
c906108c 11628
172c2a43 11629Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
11630offer the ability to run either big-endian or little-endian byte
11631orders. Usually the executable or symbol will include a bit to
11632designate the endian-ness, and you will not need to worry about
11633which to use. However, you may still find it useful to adjust
d4f3574e 11634@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
11635
11636@table @code
4644b6e3 11637@kindex set endian
c906108c
SS
11638@item set endian big
11639Instruct @value{GDBN} to assume the target is big-endian.
11640
c906108c
SS
11641@item set endian little
11642Instruct @value{GDBN} to assume the target is little-endian.
11643
c906108c
SS
11644@item set endian auto
11645Instruct @value{GDBN} to use the byte order associated with the
11646executable.
11647
11648@item show endian
11649Display @value{GDBN}'s current idea of the target byte order.
11650
11651@end table
11652
11653Note that these commands merely adjust interpretation of symbolic
11654data on the host, and that they have absolutely no effect on the
11655target system.
11656
6d2ebf8b 11657@node Remote
c906108c
SS
11658@section Remote debugging
11659@cindex remote debugging
11660
11661If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
11662@value{GDBN} in the usual way, it is often useful to use remote debugging.
11663For example, you might use remote debugging on an operating system kernel,
c906108c
SS
11664or on a small system which does not have a general purpose operating system
11665powerful enough to run a full-featured debugger.
11666
11667Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
11668to make this work with particular debugging targets. In addition,
5d161b24 11669@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
11670but not specific to any particular target system) which you can use if you
11671write the remote stubs---the code that runs on the remote system to
11672communicate with @value{GDBN}.
11673
11674Other remote targets may be available in your
11675configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 11676
c45da7e6
EZ
11677Once you've connected to the remote target, @value{GDBN} allows you to
11678send arbitrary commands to the remote monitor:
11679
11680@table @code
11681@item remote @var{command}
11682@kindex remote@r{, a command}
11683@cindex send command to remote monitor
11684Send an arbitrary @var{command} string to the remote monitor.
11685@end table
11686
11687
6f05cf9f
AC
11688@node KOD
11689@section Kernel Object Display
6f05cf9f 11690@cindex kernel object display
6f05cf9f
AC
11691@cindex KOD
11692
11693Some targets support kernel object display. Using this facility,
11694@value{GDBN} communicates specially with the underlying operating system
11695and can display information about operating system-level objects such as
11696mutexes and other synchronization objects. Exactly which objects can be
11697displayed is determined on a per-OS basis.
11698
3bbe9696 11699@kindex set os
6f05cf9f
AC
11700Use the @code{set os} command to set the operating system. This tells
11701@value{GDBN} which kernel object display module to initialize:
11702
474c8240 11703@smallexample
6f05cf9f 11704(@value{GDBP}) set os cisco
474c8240 11705@end smallexample
6f05cf9f 11706
3bbe9696
EZ
11707@kindex show os
11708The associated command @code{show os} displays the operating system
11709set with the @code{set os} command; if no operating system has been
11710set, @code{show os} will display an empty string @samp{""}.
11711
6f05cf9f
AC
11712If @code{set os} succeeds, @value{GDBN} will display some information
11713about the operating system, and will create a new @code{info} command
11714which can be used to query the target. The @code{info} command is named
11715after the operating system:
c906108c 11716
3bbe9696 11717@kindex info cisco
474c8240 11718@smallexample
6f05cf9f
AC
11719(@value{GDBP}) info cisco
11720List of Cisco Kernel Objects
11721Object Description
11722any Any and all objects
474c8240 11723@end smallexample
6f05cf9f
AC
11724
11725Further subcommands can be used to query about particular objects known
11726by the kernel.
11727
3bbe9696
EZ
11728There is currently no way to determine whether a given operating
11729system is supported other than to try setting it with @kbd{set os
11730@var{name}}, where @var{name} is the name of the operating system you
11731want to try.
6f05cf9f
AC
11732
11733
11734@node Remote Debugging
11735@chapter Debugging remote programs
11736
6b2f586d 11737@menu
07f31aa6 11738* Connecting:: Connecting to a remote target
6b2f586d
AC
11739* Server:: Using the gdbserver program
11740* NetWare:: Using the gdbserve.nlm program
501eef12 11741* Remote configuration:: Remote configuration
6b2f586d 11742* remote stub:: Implementing a remote stub
6b2f586d
AC
11743@end menu
11744
07f31aa6
DJ
11745@node Connecting
11746@section Connecting to a remote target
11747
11748On the @value{GDBN} host machine, you will need an unstripped copy of
11749your program, since @value{GDBN} needs symobl and debugging information.
11750Start up @value{GDBN} as usual, using the name of the local copy of your
11751program as the first argument.
11752
11753@cindex serial line, @code{target remote}
11754If you're using a serial line, you may want to give @value{GDBN} the
11755@w{@samp{--baud}} option, or use the @code{set remotebaud} command
9c16f35a
EZ
11756(@pxref{Remote configuration, set remotebaud}) before the
11757@code{target} command.
07f31aa6
DJ
11758
11759After that, use @code{target remote} to establish communications with
11760the target machine. Its argument specifies how to communicate---either
11761via a devicename attached to a direct serial line, or a TCP or UDP port
11762(possibly to a terminal server which in turn has a serial line to the
11763target). For example, to use a serial line connected to the device
11764named @file{/dev/ttyb}:
11765
11766@smallexample
11767target remote /dev/ttyb
11768@end smallexample
11769
11770@cindex TCP port, @code{target remote}
11771To use a TCP connection, use an argument of the form
11772@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
11773For example, to connect to port 2828 on a
11774terminal server named @code{manyfarms}:
11775
11776@smallexample
11777target remote manyfarms:2828
11778@end smallexample
11779
11780If your remote target is actually running on the same machine as
11781your debugger session (e.g.@: a simulator of your target running on
11782the same host), you can omit the hostname. For example, to connect
11783to port 1234 on your local machine:
11784
11785@smallexample
11786target remote :1234
11787@end smallexample
11788@noindent
11789
11790Note that the colon is still required here.
11791
11792@cindex UDP port, @code{target remote}
11793To use a UDP connection, use an argument of the form
11794@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
11795on a terminal server named @code{manyfarms}:
11796
11797@smallexample
11798target remote udp:manyfarms:2828
11799@end smallexample
11800
11801When using a UDP connection for remote debugging, you should keep in mind
11802that the `U' stands for ``Unreliable''. UDP can silently drop packets on
11803busy or unreliable networks, which will cause havoc with your debugging
11804session.
11805
11806Now you can use all the usual commands to examine and change data and to
11807step and continue the remote program.
11808
11809@cindex interrupting remote programs
11810@cindex remote programs, interrupting
11811Whenever @value{GDBN} is waiting for the remote program, if you type the
11812interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
11813program. This may or may not succeed, depending in part on the hardware
11814and the serial drivers the remote system uses. If you type the
11815interrupt character once again, @value{GDBN} displays this prompt:
11816
11817@smallexample
11818Interrupted while waiting for the program.
11819Give up (and stop debugging it)? (y or n)
11820@end smallexample
11821
11822If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
11823(If you decide you want to try again later, you can use @samp{target
11824remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
11825goes back to waiting.
11826
11827@table @code
11828@kindex detach (remote)
11829@item detach
11830When you have finished debugging the remote program, you can use the
11831@code{detach} command to release it from @value{GDBN} control.
11832Detaching from the target normally resumes its execution, but the results
11833will depend on your particular remote stub. After the @code{detach}
11834command, @value{GDBN} is free to connect to another target.
11835
11836@kindex disconnect
11837@item disconnect
11838The @code{disconnect} command behaves like @code{detach}, except that
11839the target is generally not resumed. It will wait for @value{GDBN}
11840(this instance or another one) to connect and continue debugging. After
11841the @code{disconnect} command, @value{GDBN} is again free to connect to
11842another target.
09d4efe1
EZ
11843
11844@cindex send command to remote monitor
11845@kindex monitor
11846@item monitor @var{cmd}
11847This command allows you to send commands directly to the remote
11848monitor.
07f31aa6
DJ
11849@end table
11850
6f05cf9f
AC
11851@node Server
11852@section Using the @code{gdbserver} program
11853
11854@kindex gdbserver
11855@cindex remote connection without stubs
11856@code{gdbserver} is a control program for Unix-like systems, which
11857allows you to connect your program with a remote @value{GDBN} via
11858@code{target remote}---but without linking in the usual debugging stub.
11859
11860@code{gdbserver} is not a complete replacement for the debugging stubs,
11861because it requires essentially the same operating-system facilities
11862that @value{GDBN} itself does. In fact, a system that can run
11863@code{gdbserver} to connect to a remote @value{GDBN} could also run
11864@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
11865because it is a much smaller program than @value{GDBN} itself. It is
11866also easier to port than all of @value{GDBN}, so you may be able to get
11867started more quickly on a new system by using @code{gdbserver}.
11868Finally, if you develop code for real-time systems, you may find that
11869the tradeoffs involved in real-time operation make it more convenient to
11870do as much development work as possible on another system, for example
11871by cross-compiling. You can use @code{gdbserver} to make a similar
11872choice for debugging.
11873
11874@value{GDBN} and @code{gdbserver} communicate via either a serial line
11875or a TCP connection, using the standard @value{GDBN} remote serial
11876protocol.
11877
11878@table @emph
11879@item On the target machine,
11880you need to have a copy of the program you want to debug.
11881@code{gdbserver} does not need your program's symbol table, so you can
11882strip the program if necessary to save space. @value{GDBN} on the host
11883system does all the symbol handling.
11884
11885To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 11886the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
11887syntax is:
11888
11889@smallexample
11890target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
11891@end smallexample
11892
11893@var{comm} is either a device name (to use a serial line) or a TCP
11894hostname and portnumber. For example, to debug Emacs with the argument
11895@samp{foo.txt} and communicate with @value{GDBN} over the serial port
11896@file{/dev/com1}:
11897
11898@smallexample
11899target> gdbserver /dev/com1 emacs foo.txt
11900@end smallexample
11901
11902@code{gdbserver} waits passively for the host @value{GDBN} to communicate
11903with it.
11904
11905To use a TCP connection instead of a serial line:
11906
11907@smallexample
11908target> gdbserver host:2345 emacs foo.txt
11909@end smallexample
11910
11911The only difference from the previous example is the first argument,
11912specifying that you are communicating with the host @value{GDBN} via
11913TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
11914expect a TCP connection from machine @samp{host} to local TCP port 2345.
11915(Currently, the @samp{host} part is ignored.) You can choose any number
11916you want for the port number as long as it does not conflict with any
11917TCP ports already in use on the target system (for example, @code{23} is
11918reserved for @code{telnet}).@footnote{If you choose a port number that
11919conflicts with another service, @code{gdbserver} prints an error message
11920and exits.} You must use the same port number with the host @value{GDBN}
11921@code{target remote} command.
11922
56460a61
DJ
11923On some targets, @code{gdbserver} can also attach to running programs.
11924This is accomplished via the @code{--attach} argument. The syntax is:
11925
11926@smallexample
11927target> gdbserver @var{comm} --attach @var{pid}
11928@end smallexample
11929
11930@var{pid} is the process ID of a currently running process. It isn't necessary
11931to point @code{gdbserver} at a binary for the running process.
11932
b1fe9455
DJ
11933@pindex pidof
11934@cindex attach to a program by name
11935You can debug processes by name instead of process ID if your target has the
11936@code{pidof} utility:
11937
11938@smallexample
11939target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
11940@end smallexample
11941
11942In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
11943has multiple threads, most versions of @code{pidof} support the
11944@code{-s} option to only return the first process ID.
11945
07f31aa6
DJ
11946@item On the host machine,
11947connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
11948For TCP connections, you must start up @code{gdbserver} prior to using
11949the @code{target remote} command. Otherwise you may get an error whose
11950text depends on the host system, but which usually looks something like
07f31aa6 11951@samp{Connection refused}. You don't need to use the @code{load}
397ca115
EZ
11952command in @value{GDBN} when using @code{gdbserver}, since the program is
11953already on the target. However, if you want to load the symbols (as
11954you normally would), do that with the @code{file} command, and issue
11955it @emph{before} connecting to the server; otherwise, you will get an
11956error message saying @code{"Program is already running"}, since the
11957program is considered running after the connection.
07f31aa6 11958
6f05cf9f
AC
11959@end table
11960
11961@node NetWare
11962@section Using the @code{gdbserve.nlm} program
11963
11964@kindex gdbserve.nlm
11965@code{gdbserve.nlm} is a control program for NetWare systems, which
11966allows you to connect your program with a remote @value{GDBN} via
11967@code{target remote}.
11968
11969@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
11970using the standard @value{GDBN} remote serial protocol.
11971
11972@table @emph
11973@item On the target machine,
11974you need to have a copy of the program you want to debug.
11975@code{gdbserve.nlm} does not need your program's symbol table, so you
11976can strip the program if necessary to save space. @value{GDBN} on the
11977host system does all the symbol handling.
11978
11979To use the server, you must tell it how to communicate with
11980@value{GDBN}; the name of your program; and the arguments for your
11981program. The syntax is:
11982
11983@smallexample
11984load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
11985 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
11986@end smallexample
11987
11988@var{board} and @var{port} specify the serial line; @var{baud} specifies
11989the baud rate used by the connection. @var{port} and @var{node} default
11990to 0, @var{baud} defaults to 9600@dmn{bps}.
11991
11992For example, to debug Emacs with the argument @samp{foo.txt}and
11993communicate with @value{GDBN} over serial port number 2 or board 1
11994using a 19200@dmn{bps} connection:
11995
11996@smallexample
11997load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
11998@end smallexample
11999
07f31aa6
DJ
12000@item
12001On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
12002Connecting to a remote target}).
6f05cf9f 12003
6f05cf9f
AC
12004@end table
12005
501eef12
AC
12006@node Remote configuration
12007@section Remote configuration
12008
9c16f35a
EZ
12009@kindex set remote
12010@kindex show remote
12011This section documents the configuration options available when
12012debugging remote programs. For the options related to the File I/O
12013extensions of the remote protocol, see @ref{The system call,
12014system-call-allowed}.
501eef12
AC
12015
12016@table @code
9c16f35a
EZ
12017@item set remoteaddresssize @var{bits}
12018@cindex adress size for remote targets
12019@cindex bits in remote address
12020Set the maximum size of address in a memory packet to the specified
12021number of bits. @value{GDBN} will mask off the address bits above
12022that number, when it passes addresses to the remote target. The
12023default value is the number of bits in the target's address.
12024
12025@item show remoteaddresssize
12026Show the current value of remote address size in bits.
12027
12028@item set remotebaud @var{n}
12029@cindex baud rate for remote targets
12030Set the baud rate for the remote serial I/O to @var{n} baud. The
12031value is used to set the speed of the serial port used for debugging
12032remote targets.
12033
12034@item show remotebaud
12035Show the current speed of the remote connection.
12036
12037@item set remotebreak
12038@cindex interrupt remote programs
12039@cindex BREAK signal instead of Ctrl-C
12040If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
12041when you press the @key{Ctrl-C} key to interrupt the program running
12042on the remote. If set to off, @value{GDBN} sends the @samp{Strl-C}
12043character instead. The default is off, since most remote systems
12044expect to see @samp{Ctrl-C} as the interrupt signal.
12045
12046@item show remotebreak
12047Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
12048interrupt the remote program.
12049
12050@item set remotedebug
12051@cindex debug remote protocol
12052@cindex remote protocol debugging
12053@cindex display remote packets
12054Control the debugging of the remote protocol. When enabled, each
12055packet sent to or received from the remote target is displayed. The
12056defaults is off.
12057
12058@item show remotedebug
12059Show the current setting of the remote protocol debugging.
12060
12061@item set remotedevice @var{device}
12062@cindex serial port name
12063Set the name of the serial port through which to communicate to the
12064remote target to @var{device}. This is the device used by
12065@value{GDBN} to open the serial communications line to the remote
12066target. There's no default, so you must set a valid port name for the
12067remote serial communications to work. (Some varieties of the
12068@code{target} command accept the port name as part of their
12069arguments.)
12070
12071@item show remotedevice
12072Show the current name of the serial port.
12073
12074@item set remotelogbase @var{base}
12075Set the base (a.k.a.@: radix) of logging serial protocol
12076communications to @var{base}. Supported values of @var{base} are:
12077@code{ascii}, @code{octal}, and @code{hex}. The default is
12078@code{ascii}.
12079
12080@item show remotelogbase
12081Show the current setting of the radix for logging remote serial
12082protocol.
12083
12084@item set remotelogfile @var{file}
12085@cindex record serial communications on file
12086Record remote serial communications on the named @var{file}. The
12087default is not to record at all.
12088
12089@item show remotelogfile.
12090Show the current setting of the file name on which to record the
12091serial communications.
12092
12093@item set remotetimeout @var{num}
12094@cindex timeout for serial communications
12095@cindex remote timeout
12096Set the timeout limit to wait for the remote target to respond to
12097@var{num} seconds. The default is 2 seconds.
12098
12099@item show remotetimeout
12100Show the current number of seconds to wait for the remote target
12101responses.
12102
12103@cindex limit hardware breakpoints and watchpoints
12104@cindex remote target, limit break- and watchpoints
501eef12
AC
12105@anchor{set remote hardware-watchpoint-limit}
12106@anchor{set remote hardware-breakpoint-limit}
12107@item set remote hardware-watchpoint-limit @var{limit}
12108@itemx set remote hardware-breakpoint-limit @var{limit}
12109Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
12110watchpoints. A limit of -1, the default, is treated as unlimited.
9c16f35a
EZ
12111
12112@item set remote fetch-register-packet
12113@itemx set remote set-register-packet
12114@itemx set remote P-packet
12115@itemx set remote p-packet
12116@cindex P-packet
12117@cindex fetch registers from remote targets
12118@cindex set registers in remote targets
12119Determine whether @value{GDBN} can set and fetch registers from the
12120remote target using the @samp{P} packets. The default depends on the
12121remote stub's support of the @samp{P} packets (@value{GDBN} queries
12122the stub when this packet is first required).
12123
12124@item show remote fetch-register-packet
12125@itemx show remote set-register-packet
12126@itemx show remote P-packet
12127@itemx show remote p-packet
12128Show the current setting of using the @samp{P} packets for setting and
12129fetching registers from the remote target.
12130
12131@cindex binary downloads
12132@cindex X-packet
12133@item set remote binary-download-packet
12134@itemx set remote X-packet
12135Determine whether @value{GDBN} sends downloads in binary mode using
12136the @samp{X} packets. The default is on.
12137
12138@item show remote binary-download-packet
12139@itemx show remote X-packet
12140Show the current setting of using the @samp{X} packets for binary
12141downloads.
12142
12143@item set remote read-aux-vector-packet
12144@cindex auxiliary vector of remote target
12145@cindex @code{auxv}, and remote targets
12146Set the use of the remote protocol's @samp{qPart:auxv:read} (target
12147auxiliary vector read) request. This request is used to fetch the
721c2651
EZ
12148remote target's @dfn{auxiliary vector}, see @ref{OS Information,
12149Auxiliary Vector}. The default setting depends on the remote stub's
12150support of this request (@value{GDBN} queries the stub when this
12151request is first required). @xref{General Query Packets, qPart}, for
12152more information about this request.
9c16f35a
EZ
12153
12154@item show remote read-aux-vector-packet
12155Show the current setting of use of the @samp{qPart:auxv:read} request.
12156
12157@item set remote symbol-lookup-packet
12158@cindex remote symbol lookup request
12159Set the use of the remote protocol's @samp{qSymbol} (target symbol
12160lookup) request. This request is used to communicate symbol
12161information to the remote target, e.g., whenever a new shared library
12162is loaded by the remote (@pxref{Files, shared libraries}). The
12163default setting depends on the remote stub's support of this request
12164(@value{GDBN} queries the stub when this request is first required).
12165@xref{General Query Packets, qSymbol}, for more information about this
12166request.
12167
12168@item show remote symbol-lookup-packet
12169Show the current setting of use of the @samp{qSymbol} request.
12170
12171@item set remote verbose-resume-packet
12172@cindex resume remote target
12173@cindex signal thread, and remote targets
12174@cindex single-step thread, and remote targets
12175@cindex thread-specific operations on remote targets
12176Set the use of the remote protocol's @samp{vCont} (descriptive resume)
12177request. This request is used to resume specific threads in the
12178remote target, and to single-step or signal them. The default setting
12179depends on the remote stub's support of this request (@value{GDBN}
12180queries the stub when this request is first required). This setting
12181affects debugging of multithreaded programs: if @samp{vCont} cannot be
12182used, @value{GDBN} might be unable to single-step a specific thread,
12183especially under @code{set scheduler-locking off}; it is also
12184impossible to pause a specific thread. @xref{Packets, vCont}, for
12185more details.
12186
12187@item show remote verbose-resume-packet
12188Show the current setting of use of the @samp{vCont} request
12189
12190@item set remote software-breakpoint-packet
12191@itemx set remote hardware-breakpoint-packet
12192@itemx set remote write-watchpoint-packet
12193@itemx set remote read-watchpoint-packet
12194@itemx set remote access-watchpoint-packet
12195@itemx set remote Z-packet
12196@cindex Z-packet
12197@cindex remote hardware breakpoints and watchpoints
12198These commands enable or disable the use of @samp{Z} packets for
12199setting breakpoints and watchpoints in the remote target. The default
12200depends on the remote stub's support of the @samp{Z} packets
12201(@value{GDBN} queries the stub when each packet is first required).
12202The command @code{set remote Z-packet}, kept for back-compatibility,
12203turns on or off all the features that require the use of @samp{Z}
12204packets.
12205
12206@item show remote software-breakpoint-packet
12207@itemx show remote hardware-breakpoint-packet
12208@itemx show remote write-watchpoint-packet
12209@itemx show remote read-watchpoint-packet
12210@itemx show remote access-watchpoint-packet
12211@itemx show remote Z-packet
12212Show the current setting of @samp{Z} packets usage.
0abb7bc7
EZ
12213
12214@item set remote get-thread-local-storage-address
12215@kindex set remote get-thread-local-storage-address
12216@cindex thread local storage of remote targets
12217This command enables or disables the use of the @samp{qGetTLSAddr}
12218(Get Thread Local Storage Address) request packet. The default
12219depends on whether the remote stub supports this request.
12220@xref{General Query Packets, qGetTLSAddr}, for more details about this
12221packet.
12222
12223@item show remote get-thread-local-storage-address
12224@kindex show remote get-thread-local-storage-address
12225Show the current setting of @samp{qGetTLSAddr} packet usage.
501eef12
AC
12226@end table
12227
6f05cf9f
AC
12228@node remote stub
12229@section Implementing a remote stub
7a292a7a 12230
8e04817f
AC
12231@cindex debugging stub, example
12232@cindex remote stub, example
12233@cindex stub example, remote debugging
12234The stub files provided with @value{GDBN} implement the target side of the
12235communication protocol, and the @value{GDBN} side is implemented in the
12236@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
12237these subroutines to communicate, and ignore the details. (If you're
12238implementing your own stub file, you can still ignore the details: start
12239with one of the existing stub files. @file{sparc-stub.c} is the best
12240organized, and therefore the easiest to read.)
12241
104c1213
JM
12242@cindex remote serial debugging, overview
12243To debug a program running on another machine (the debugging
12244@dfn{target} machine), you must first arrange for all the usual
12245prerequisites for the program to run by itself. For example, for a C
12246program, you need:
c906108c 12247
104c1213
JM
12248@enumerate
12249@item
12250A startup routine to set up the C runtime environment; these usually
12251have a name like @file{crt0}. The startup routine may be supplied by
12252your hardware supplier, or you may have to write your own.
96baa820 12253
5d161b24 12254@item
d4f3574e 12255A C subroutine library to support your program's
104c1213 12256subroutine calls, notably managing input and output.
96baa820 12257
104c1213
JM
12258@item
12259A way of getting your program to the other machine---for example, a
12260download program. These are often supplied by the hardware
12261manufacturer, but you may have to write your own from hardware
12262documentation.
12263@end enumerate
96baa820 12264
104c1213
JM
12265The next step is to arrange for your program to use a serial port to
12266communicate with the machine where @value{GDBN} is running (the @dfn{host}
12267machine). In general terms, the scheme looks like this:
96baa820 12268
104c1213
JM
12269@table @emph
12270@item On the host,
12271@value{GDBN} already understands how to use this protocol; when everything
12272else is set up, you can simply use the @samp{target remote} command
12273(@pxref{Targets,,Specifying a Debugging Target}).
12274
12275@item On the target,
12276you must link with your program a few special-purpose subroutines that
12277implement the @value{GDBN} remote serial protocol. The file containing these
12278subroutines is called a @dfn{debugging stub}.
12279
12280On certain remote targets, you can use an auxiliary program
12281@code{gdbserver} instead of linking a stub into your program.
12282@xref{Server,,Using the @code{gdbserver} program}, for details.
12283@end table
96baa820 12284
104c1213
JM
12285The debugging stub is specific to the architecture of the remote
12286machine; for example, use @file{sparc-stub.c} to debug programs on
12287@sc{sparc} boards.
96baa820 12288
104c1213
JM
12289@cindex remote serial stub list
12290These working remote stubs are distributed with @value{GDBN}:
96baa820 12291
104c1213
JM
12292@table @code
12293
12294@item i386-stub.c
41afff9a 12295@cindex @file{i386-stub.c}
104c1213
JM
12296@cindex Intel
12297@cindex i386
12298For Intel 386 and compatible architectures.
12299
12300@item m68k-stub.c
41afff9a 12301@cindex @file{m68k-stub.c}
104c1213
JM
12302@cindex Motorola 680x0
12303@cindex m680x0
12304For Motorola 680x0 architectures.
12305
12306@item sh-stub.c
41afff9a 12307@cindex @file{sh-stub.c}
172c2a43 12308@cindex Renesas
104c1213 12309@cindex SH
172c2a43 12310For Renesas SH architectures.
104c1213
JM
12311
12312@item sparc-stub.c
41afff9a 12313@cindex @file{sparc-stub.c}
104c1213
JM
12314@cindex Sparc
12315For @sc{sparc} architectures.
12316
12317@item sparcl-stub.c
41afff9a 12318@cindex @file{sparcl-stub.c}
104c1213
JM
12319@cindex Fujitsu
12320@cindex SparcLite
12321For Fujitsu @sc{sparclite} architectures.
12322
12323@end table
12324
12325The @file{README} file in the @value{GDBN} distribution may list other
12326recently added stubs.
12327
12328@menu
12329* Stub Contents:: What the stub can do for you
12330* Bootstrapping:: What you must do for the stub
12331* Debug Session:: Putting it all together
104c1213
JM
12332@end menu
12333
6d2ebf8b 12334@node Stub Contents
6f05cf9f 12335@subsection What the stub can do for you
104c1213
JM
12336
12337@cindex remote serial stub
12338The debugging stub for your architecture supplies these three
12339subroutines:
12340
12341@table @code
12342@item set_debug_traps
4644b6e3 12343@findex set_debug_traps
104c1213
JM
12344@cindex remote serial stub, initialization
12345This routine arranges for @code{handle_exception} to run when your
12346program stops. You must call this subroutine explicitly near the
12347beginning of your program.
12348
12349@item handle_exception
4644b6e3 12350@findex handle_exception
104c1213
JM
12351@cindex remote serial stub, main routine
12352This is the central workhorse, but your program never calls it
12353explicitly---the setup code arranges for @code{handle_exception} to
12354run when a trap is triggered.
12355
12356@code{handle_exception} takes control when your program stops during
12357execution (for example, on a breakpoint), and mediates communications
12358with @value{GDBN} on the host machine. This is where the communications
12359protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 12360representative on the target machine. It begins by sending summary
104c1213
JM
12361information on the state of your program, then continues to execute,
12362retrieving and transmitting any information @value{GDBN} needs, until you
12363execute a @value{GDBN} command that makes your program resume; at that point,
12364@code{handle_exception} returns control to your own code on the target
5d161b24 12365machine.
104c1213
JM
12366
12367@item breakpoint
12368@cindex @code{breakpoint} subroutine, remote
12369Use this auxiliary subroutine to make your program contain a
12370breakpoint. Depending on the particular situation, this may be the only
12371way for @value{GDBN} to get control. For instance, if your target
12372machine has some sort of interrupt button, you won't need to call this;
12373pressing the interrupt button transfers control to
12374@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
12375simply receiving characters on the serial port may also trigger a trap;
12376again, in that situation, you don't need to call @code{breakpoint} from
12377your own program---simply running @samp{target remote} from the host
5d161b24 12378@value{GDBN} session gets control.
104c1213
JM
12379
12380Call @code{breakpoint} if none of these is true, or if you simply want
12381to make certain your program stops at a predetermined point for the
12382start of your debugging session.
12383@end table
12384
6d2ebf8b 12385@node Bootstrapping
6f05cf9f 12386@subsection What you must do for the stub
104c1213
JM
12387
12388@cindex remote stub, support routines
12389The debugging stubs that come with @value{GDBN} are set up for a particular
12390chip architecture, but they have no information about the rest of your
12391debugging target machine.
12392
12393First of all you need to tell the stub how to communicate with the
12394serial port.
12395
12396@table @code
12397@item int getDebugChar()
4644b6e3 12398@findex getDebugChar
104c1213
JM
12399Write this subroutine to read a single character from the serial port.
12400It may be identical to @code{getchar} for your target system; a
12401different name is used to allow you to distinguish the two if you wish.
12402
12403@item void putDebugChar(int)
4644b6e3 12404@findex putDebugChar
104c1213 12405Write this subroutine to write a single character to the serial port.
5d161b24 12406It may be identical to @code{putchar} for your target system; a
104c1213
JM
12407different name is used to allow you to distinguish the two if you wish.
12408@end table
12409
12410@cindex control C, and remote debugging
12411@cindex interrupting remote targets
12412If you want @value{GDBN} to be able to stop your program while it is
12413running, you need to use an interrupt-driven serial driver, and arrange
12414for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
12415character). That is the character which @value{GDBN} uses to tell the
12416remote system to stop.
12417
12418Getting the debugging target to return the proper status to @value{GDBN}
12419probably requires changes to the standard stub; one quick and dirty way
12420is to just execute a breakpoint instruction (the ``dirty'' part is that
12421@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
12422
12423Other routines you need to supply are:
12424
12425@table @code
12426@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 12427@findex exceptionHandler
104c1213
JM
12428Write this function to install @var{exception_address} in the exception
12429handling tables. You need to do this because the stub does not have any
12430way of knowing what the exception handling tables on your target system
12431are like (for example, the processor's table might be in @sc{rom},
12432containing entries which point to a table in @sc{ram}).
12433@var{exception_number} is the exception number which should be changed;
12434its meaning is architecture-dependent (for example, different numbers
12435might represent divide by zero, misaligned access, etc). When this
12436exception occurs, control should be transferred directly to
12437@var{exception_address}, and the processor state (stack, registers,
12438and so on) should be just as it is when a processor exception occurs. So if
12439you want to use a jump instruction to reach @var{exception_address}, it
12440should be a simple jump, not a jump to subroutine.
12441
12442For the 386, @var{exception_address} should be installed as an interrupt
12443gate so that interrupts are masked while the handler runs. The gate
12444should be at privilege level 0 (the most privileged level). The
12445@sc{sparc} and 68k stubs are able to mask interrupts themselves without
12446help from @code{exceptionHandler}.
12447
12448@item void flush_i_cache()
4644b6e3 12449@findex flush_i_cache
d4f3574e 12450On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
12451instruction cache, if any, on your target machine. If there is no
12452instruction cache, this subroutine may be a no-op.
12453
12454On target machines that have instruction caches, @value{GDBN} requires this
12455function to make certain that the state of your program is stable.
12456@end table
12457
12458@noindent
12459You must also make sure this library routine is available:
12460
12461@table @code
12462@item void *memset(void *, int, int)
4644b6e3 12463@findex memset
104c1213
JM
12464This is the standard library function @code{memset} that sets an area of
12465memory to a known value. If you have one of the free versions of
12466@code{libc.a}, @code{memset} can be found there; otherwise, you must
12467either obtain it from your hardware manufacturer, or write your own.
12468@end table
12469
12470If you do not use the GNU C compiler, you may need other standard
12471library subroutines as well; this varies from one stub to another,
12472but in general the stubs are likely to use any of the common library
d4f3574e 12473subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
12474
12475
6d2ebf8b 12476@node Debug Session
6f05cf9f 12477@subsection Putting it all together
104c1213
JM
12478
12479@cindex remote serial debugging summary
12480In summary, when your program is ready to debug, you must follow these
12481steps.
12482
12483@enumerate
12484@item
6d2ebf8b 12485Make sure you have defined the supporting low-level routines
104c1213
JM
12486(@pxref{Bootstrapping,,What you must do for the stub}):
12487@display
12488@code{getDebugChar}, @code{putDebugChar},
12489@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
12490@end display
12491
12492@item
12493Insert these lines near the top of your program:
12494
474c8240 12495@smallexample
104c1213
JM
12496set_debug_traps();
12497breakpoint();
474c8240 12498@end smallexample
104c1213
JM
12499
12500@item
12501For the 680x0 stub only, you need to provide a variable called
12502@code{exceptionHook}. Normally you just use:
12503
474c8240 12504@smallexample
104c1213 12505void (*exceptionHook)() = 0;
474c8240 12506@end smallexample
104c1213 12507
d4f3574e 12508@noindent
104c1213 12509but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 12510function in your program, that function is called when
104c1213
JM
12511@code{@value{GDBN}} continues after stopping on a trap (for example, bus
12512error). The function indicated by @code{exceptionHook} is called with
12513one parameter: an @code{int} which is the exception number.
12514
12515@item
12516Compile and link together: your program, the @value{GDBN} debugging stub for
12517your target architecture, and the supporting subroutines.
12518
12519@item
12520Make sure you have a serial connection between your target machine and
12521the @value{GDBN} host, and identify the serial port on the host.
12522
12523@item
12524@c The "remote" target now provides a `load' command, so we should
12525@c document that. FIXME.
12526Download your program to your target machine (or get it there by
12527whatever means the manufacturer provides), and start it.
12528
12529@item
07f31aa6
DJ
12530Start @value{GDBN} on the host, and connect to the target
12531(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 12532
104c1213
JM
12533@end enumerate
12534
8e04817f
AC
12535@node Configurations
12536@chapter Configuration-Specific Information
104c1213 12537
8e04817f
AC
12538While nearly all @value{GDBN} commands are available for all native and
12539cross versions of the debugger, there are some exceptions. This chapter
12540describes things that are only available in certain configurations.
104c1213 12541
8e04817f
AC
12542There are three major categories of configurations: native
12543configurations, where the host and target are the same, embedded
12544operating system configurations, which are usually the same for several
12545different processor architectures, and bare embedded processors, which
12546are quite different from each other.
104c1213 12547
8e04817f
AC
12548@menu
12549* Native::
12550* Embedded OS::
12551* Embedded Processors::
12552* Architectures::
12553@end menu
104c1213 12554
8e04817f
AC
12555@node Native
12556@section Native
104c1213 12557
8e04817f
AC
12558This section describes details specific to particular native
12559configurations.
6cf7e474 12560
8e04817f
AC
12561@menu
12562* HP-UX:: HP-UX
7561d450 12563* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
12564* SVR4 Process Information:: SVR4 process information
12565* DJGPP Native:: Features specific to the DJGPP port
78c47bea 12566* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 12567* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 12568* Neutrino:: Features specific to QNX Neutrino
8e04817f 12569@end menu
6cf7e474 12570
8e04817f
AC
12571@node HP-UX
12572@subsection HP-UX
104c1213 12573
8e04817f
AC
12574On HP-UX systems, if you refer to a function or variable name that
12575begins with a dollar sign, @value{GDBN} searches for a user or system
12576name first, before it searches for a convenience variable.
104c1213 12577
9c16f35a 12578
7561d450
MK
12579@node BSD libkvm Interface
12580@subsection BSD libkvm Interface
12581
12582@cindex libkvm
12583@cindex kernel memory image
12584@cindex kernel crash dump
12585
12586BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
12587interface that provides a uniform interface for accessing kernel virtual
12588memory images, including live systems and crash dumps. @value{GDBN}
12589uses this interface to allow you to debug live kernels and kernel crash
12590dumps on many native BSD configurations. This is implemented as a
12591special @code{kvm} debugging target. For debugging a live system, load
12592the currently running kernel into @value{GDBN} and connect to the
12593@code{kvm} target:
12594
12595@smallexample
12596(@value{GDBP}) @b{target kvm}
12597@end smallexample
12598
12599For debugging crash dumps, provide the file name of the crash dump as an
12600argument:
12601
12602@smallexample
12603(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
12604@end smallexample
12605
12606Once connected to the @code{kvm} target, the following commands are
12607available:
12608
12609@table @code
12610@kindex kvm
12611@item kvm pcb
721c2651 12612Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
12613
12614@item kvm proc
12615Set current context from proc address. This command isn't available on
12616modern FreeBSD systems.
12617@end table
12618
8e04817f
AC
12619@node SVR4 Process Information
12620@subsection SVR4 process information
60bf7e09
EZ
12621@cindex /proc
12622@cindex examine process image
12623@cindex process info via @file{/proc}
104c1213 12624
60bf7e09
EZ
12625Many versions of SVR4 and compatible systems provide a facility called
12626@samp{/proc} that can be used to examine the image of a running
12627process using file-system subroutines. If @value{GDBN} is configured
12628for an operating system with this facility, the command @code{info
12629proc} is available to report information about the process running
12630your program, or about any process running on your system. @code{info
12631proc} works only on SVR4 systems that include the @code{procfs} code.
12632This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
12633Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 12634
8e04817f
AC
12635@table @code
12636@kindex info proc
60bf7e09 12637@cindex process ID
8e04817f 12638@item info proc
60bf7e09
EZ
12639@itemx info proc @var{process-id}
12640Summarize available information about any running process. If a
12641process ID is specified by @var{process-id}, display information about
12642that process; otherwise display information about the program being
12643debugged. The summary includes the debugged process ID, the command
12644line used to invoke it, its current working directory, and its
12645executable file's absolute file name.
12646
12647On some systems, @var{process-id} can be of the form
12648@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
12649within a process. If the optional @var{pid} part is missing, it means
12650a thread from the process being debugged (the leading @samp{/} still
12651needs to be present, or else @value{GDBN} will interpret the number as
12652a process ID rather than a thread ID).
6cf7e474 12653
8e04817f 12654@item info proc mappings
60bf7e09
EZ
12655@cindex memory address space mappings
12656Report the memory address space ranges accessible in the program, with
12657information on whether the process has read, write, or execute access
12658rights to each range. On @sc{gnu}/Linux systems, each memory range
12659includes the object file which is mapped to that range, instead of the
12660memory access rights to that range.
12661
12662@item info proc stat
12663@itemx info proc status
12664@cindex process detailed status information
12665These subcommands are specific to @sc{gnu}/Linux systems. They show
12666the process-related information, including the user ID and group ID;
12667how many threads are there in the process; its virtual memory usage;
12668the signals that are pending, blocked, and ignored; its TTY; its
12669consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 12670value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
12671(type @kbd{man 5 proc} from your shell prompt).
12672
12673@item info proc all
12674Show all the information about the process described under all of the
12675above @code{info proc} subcommands.
12676
8e04817f
AC
12677@ignore
12678@comment These sub-options of 'info proc' were not included when
12679@comment procfs.c was re-written. Keep their descriptions around
12680@comment against the day when someone finds the time to put them back in.
12681@kindex info proc times
12682@item info proc times
12683Starting time, user CPU time, and system CPU time for your program and
12684its children.
6cf7e474 12685
8e04817f
AC
12686@kindex info proc id
12687@item info proc id
12688Report on the process IDs related to your program: its own process ID,
12689the ID of its parent, the process group ID, and the session ID.
8e04817f 12690@end ignore
721c2651
EZ
12691
12692@item set procfs-trace
12693@kindex set procfs-trace
12694@cindex @code{procfs} API calls
12695This command enables and disables tracing of @code{procfs} API calls.
12696
12697@item show procfs-trace
12698@kindex show procfs-trace
12699Show the current state of @code{procfs} API call tracing.
12700
12701@item set procfs-file @var{file}
12702@kindex set procfs-file
12703Tell @value{GDBN} to write @code{procfs} API trace to the named
12704@var{file}. @value{GDBN} appends the trace info to the previous
12705contents of the file. The default is to display the trace on the
12706standard output.
12707
12708@item show procfs-file
12709@kindex show procfs-file
12710Show the file to which @code{procfs} API trace is written.
12711
12712@item proc-trace-entry
12713@itemx proc-trace-exit
12714@itemx proc-untrace-entry
12715@itemx proc-untrace-exit
12716@kindex proc-trace-entry
12717@kindex proc-trace-exit
12718@kindex proc-untrace-entry
12719@kindex proc-untrace-exit
12720These commands enable and disable tracing of entries into and exits
12721from the @code{syscall} interface.
12722
12723@item info pidlist
12724@kindex info pidlist
12725@cindex process list, QNX Neutrino
12726For QNX Neutrino only, this command displays the list of all the
12727processes and all the threads within each process.
12728
12729@item info meminfo
12730@kindex info meminfo
12731@cindex mapinfo list, QNX Neutrino
12732For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 12733@end table
104c1213 12734
8e04817f
AC
12735@node DJGPP Native
12736@subsection Features for Debugging @sc{djgpp} Programs
12737@cindex @sc{djgpp} debugging
12738@cindex native @sc{djgpp} debugging
12739@cindex MS-DOS-specific commands
104c1213 12740
514c4d71
EZ
12741@cindex DPMI
12742@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
12743MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
12744that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
12745top of real-mode DOS systems and their emulations.
104c1213 12746
8e04817f
AC
12747@value{GDBN} supports native debugging of @sc{djgpp} programs, and
12748defines a few commands specific to the @sc{djgpp} port. This
12749subsection describes those commands.
104c1213 12750
8e04817f
AC
12751@table @code
12752@kindex info dos
12753@item info dos
12754This is a prefix of @sc{djgpp}-specific commands which print
12755information about the target system and important OS structures.
f1251bdd 12756
8e04817f
AC
12757@kindex sysinfo
12758@cindex MS-DOS system info
12759@cindex free memory information (MS-DOS)
12760@item info dos sysinfo
12761This command displays assorted information about the underlying
12762platform: the CPU type and features, the OS version and flavor, the
12763DPMI version, and the available conventional and DPMI memory.
104c1213 12764
8e04817f
AC
12765@cindex GDT
12766@cindex LDT
12767@cindex IDT
12768@cindex segment descriptor tables
12769@cindex descriptor tables display
12770@item info dos gdt
12771@itemx info dos ldt
12772@itemx info dos idt
12773These 3 commands display entries from, respectively, Global, Local,
12774and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
12775tables are data structures which store a descriptor for each segment
12776that is currently in use. The segment's selector is an index into a
12777descriptor table; the table entry for that index holds the
12778descriptor's base address and limit, and its attributes and access
12779rights.
104c1213 12780
8e04817f
AC
12781A typical @sc{djgpp} program uses 3 segments: a code segment, a data
12782segment (used for both data and the stack), and a DOS segment (which
12783allows access to DOS/BIOS data structures and absolute addresses in
12784conventional memory). However, the DPMI host will usually define
12785additional segments in order to support the DPMI environment.
d4f3574e 12786
8e04817f
AC
12787@cindex garbled pointers
12788These commands allow to display entries from the descriptor tables.
12789Without an argument, all entries from the specified table are
12790displayed. An argument, which should be an integer expression, means
12791display a single entry whose index is given by the argument. For
12792example, here's a convenient way to display information about the
12793debugged program's data segment:
104c1213 12794
8e04817f
AC
12795@smallexample
12796@exdent @code{(@value{GDBP}) info dos ldt $ds}
12797@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
12798@end smallexample
104c1213 12799
8e04817f
AC
12800@noindent
12801This comes in handy when you want to see whether a pointer is outside
12802the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 12803
8e04817f
AC
12804@cindex page tables display (MS-DOS)
12805@item info dos pde
12806@itemx info dos pte
12807These two commands display entries from, respectively, the Page
12808Directory and the Page Tables. Page Directories and Page Tables are
12809data structures which control how virtual memory addresses are mapped
12810into physical addresses. A Page Table includes an entry for every
12811page of memory that is mapped into the program's address space; there
12812may be several Page Tables, each one holding up to 4096 entries. A
12813Page Directory has up to 4096 entries, one each for every Page Table
12814that is currently in use.
104c1213 12815
8e04817f
AC
12816Without an argument, @kbd{info dos pde} displays the entire Page
12817Directory, and @kbd{info dos pte} displays all the entries in all of
12818the Page Tables. An argument, an integer expression, given to the
12819@kbd{info dos pde} command means display only that entry from the Page
12820Directory table. An argument given to the @kbd{info dos pte} command
12821means display entries from a single Page Table, the one pointed to by
12822the specified entry in the Page Directory.
104c1213 12823
8e04817f
AC
12824@cindex direct memory access (DMA) on MS-DOS
12825These commands are useful when your program uses @dfn{DMA} (Direct
12826Memory Access), which needs physical addresses to program the DMA
12827controller.
104c1213 12828
8e04817f 12829These commands are supported only with some DPMI servers.
104c1213 12830
8e04817f
AC
12831@cindex physical address from linear address
12832@item info dos address-pte @var{addr}
12833This command displays the Page Table entry for a specified linear
514c4d71
EZ
12834address. The argument @var{addr} is a linear address which should
12835already have the appropriate segment's base address added to it,
12836because this command accepts addresses which may belong to @emph{any}
12837segment. For example, here's how to display the Page Table entry for
12838the page where a variable @code{i} is stored:
104c1213 12839
b383017d 12840@smallexample
8e04817f
AC
12841@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
12842@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 12843@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 12844@end smallexample
104c1213 12845
8e04817f
AC
12846@noindent
12847This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 12848whose physical base address is @code{0x02698000}, and shows all the
8e04817f 12849attributes of that page.
104c1213 12850
8e04817f
AC
12851Note that you must cast the addresses of variables to a @code{char *},
12852since otherwise the value of @code{__djgpp_base_address}, the base
12853address of all variables and functions in a @sc{djgpp} program, will
12854be added using the rules of C pointer arithmetics: if @code{i} is
12855declared an @code{int}, @value{GDBN} will add 4 times the value of
12856@code{__djgpp_base_address} to the address of @code{i}.
104c1213 12857
8e04817f
AC
12858Here's another example, it displays the Page Table entry for the
12859transfer buffer:
104c1213 12860
8e04817f
AC
12861@smallexample
12862@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
12863@exdent @code{Page Table entry for address 0x29110:}
12864@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
12865@end smallexample
104c1213 12866
8e04817f
AC
12867@noindent
12868(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
128693rd member of the @code{_go32_info_block} structure.) The output
12870clearly shows that this DPMI server maps the addresses in conventional
12871memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
12872linear (@code{0x29110}) addresses are identical.
104c1213 12873
8e04817f
AC
12874This command is supported only with some DPMI servers.
12875@end table
104c1213 12876
c45da7e6 12877@cindex DOS serial data link, remote debugging
a8f24a35
EZ
12878In addition to native debugging, the DJGPP port supports remote
12879debugging via a serial data link. The following commands are specific
12880to remote serial debugging in the DJGPP port of @value{GDBN}.
12881
12882@table @code
12883@kindex set com1base
12884@kindex set com1irq
12885@kindex set com2base
12886@kindex set com2irq
12887@kindex set com3base
12888@kindex set com3irq
12889@kindex set com4base
12890@kindex set com4irq
12891@item set com1base @var{addr}
12892This command sets the base I/O port address of the @file{COM1} serial
12893port.
12894
12895@item set com1irq @var{irq}
12896This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
12897for the @file{COM1} serial port.
12898
12899There are similar commands @samp{set com2base}, @samp{set com3irq},
12900etc.@: for setting the port address and the @code{IRQ} lines for the
12901other 3 COM ports.
12902
12903@kindex show com1base
12904@kindex show com1irq
12905@kindex show com2base
12906@kindex show com2irq
12907@kindex show com3base
12908@kindex show com3irq
12909@kindex show com4base
12910@kindex show com4irq
12911The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
12912display the current settings of the base address and the @code{IRQ}
12913lines used by the COM ports.
c45da7e6
EZ
12914
12915@item info serial
12916@kindex info serial
12917@cindex DOS serial port status
12918This command prints the status of the 4 DOS serial ports. For each
12919port, it prints whether it's active or not, its I/O base address and
12920IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
12921counts of various errors encountered so far.
a8f24a35
EZ
12922@end table
12923
12924
78c47bea
PM
12925@node Cygwin Native
12926@subsection Features for Debugging MS Windows PE executables
12927@cindex MS Windows debugging
12928@cindex native Cygwin debugging
12929@cindex Cygwin-specific commands
12930
be448670
CF
12931@value{GDBN} supports native debugging of MS Windows programs, including
12932DLLs with and without symbolic debugging information. There are various
12933additional Cygwin-specific commands, described in this subsection. The
12934subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
12935that have no debugging symbols.
12936
78c47bea
PM
12937
12938@table @code
12939@kindex info w32
12940@item info w32
12941This is a prefix of MS Windows specific commands which print
12942information about the target system and important OS structures.
12943
12944@item info w32 selector
12945This command displays information returned by
12946the Win32 API @code{GetThreadSelectorEntry} function.
12947It takes an optional argument that is evaluated to
12948a long value to give the information about this given selector.
12949Without argument, this command displays information
12950about the the six segment registers.
12951
12952@kindex info dll
12953@item info dll
12954This is a Cygwin specific alias of info shared.
12955
12956@kindex dll-symbols
12957@item dll-symbols
12958This command loads symbols from a dll similarly to
12959add-sym command but without the need to specify a base address.
12960
b383017d 12961@kindex set new-console
78c47bea 12962@item set new-console @var{mode}
b383017d 12963If @var{mode} is @code{on} the debuggee will
78c47bea
PM
12964be started in a new console on next start.
12965If @var{mode} is @code{off}i, the debuggee will
12966be started in the same console as the debugger.
12967
12968@kindex show new-console
12969@item show new-console
12970Displays whether a new console is used
12971when the debuggee is started.
12972
12973@kindex set new-group
12974@item set new-group @var{mode}
12975This boolean value controls whether the debuggee should
12976start a new group or stay in the same group as the debugger.
12977This affects the way the Windows OS handles
12978Ctrl-C.
12979
12980@kindex show new-group
12981@item show new-group
12982Displays current value of new-group boolean.
12983
12984@kindex set debugevents
12985@item set debugevents
12986This boolean value adds debug output concerning events seen by the debugger.
12987
12988@kindex set debugexec
12989@item set debugexec
b383017d 12990This boolean value adds debug output concerning execute events
78c47bea
PM
12991seen by the debugger.
12992
12993@kindex set debugexceptions
12994@item set debugexceptions
b383017d 12995This boolean value adds debug ouptut concerning exception events
78c47bea
PM
12996seen by the debugger.
12997
12998@kindex set debugmemory
12999@item set debugmemory
b383017d 13000This boolean value adds debug ouptut concerning memory events
78c47bea
PM
13001seen by the debugger.
13002
13003@kindex set shell
13004@item set shell
13005This boolean values specifies whether the debuggee is called
13006via a shell or directly (default value is on).
13007
13008@kindex show shell
13009@item show shell
13010Displays if the debuggee will be started with a shell.
13011
13012@end table
13013
be448670
CF
13014@menu
13015* Non-debug DLL symbols:: Support for DLLs without debugging symbols
13016@end menu
13017
13018@node Non-debug DLL symbols
13019@subsubsection Support for DLLs without debugging symbols
13020@cindex DLLs with no debugging symbols
13021@cindex Minimal symbols and DLLs
13022
13023Very often on windows, some of the DLLs that your program relies on do
13024not include symbolic debugging information (for example,
13025@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
13026symbols in a DLL, it relies on the minimal amount of symbolic
13027information contained in the DLL's export table. This subsubsection
13028describes working with such symbols, known internally to @value{GDBN} as
13029``minimal symbols''.
13030
13031Note that before the debugged program has started execution, no DLLs
13032will have been loaded. The easiest way around this problem is simply to
13033start the program --- either by setting a breakpoint or letting the
13034program run once to completion. It is also possible to force
13035@value{GDBN} to load a particular DLL before starting the executable ---
13036see the shared library information in @pxref{Files} or the
13037@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
13038explicitly loading symbols from a DLL with no debugging information will
13039cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
13040which may adversely affect symbol lookup performance.
13041
13042@subsubsection DLL name prefixes
13043
13044In keeping with the naming conventions used by the Microsoft debugging
13045tools, DLL export symbols are made available with a prefix based on the
13046DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
13047also entered into the symbol table, so @code{CreateFileA} is often
13048sufficient. In some cases there will be name clashes within a program
13049(particularly if the executable itself includes full debugging symbols)
13050necessitating the use of the fully qualified name when referring to the
13051contents of the DLL. Use single-quotes around the name to avoid the
13052exclamation mark (``!'') being interpreted as a language operator.
13053
13054Note that the internal name of the DLL may be all upper-case, even
13055though the file name of the DLL is lower-case, or vice-versa. Since
13056symbols within @value{GDBN} are @emph{case-sensitive} this may cause
13057some confusion. If in doubt, try the @code{info functions} and
13058@code{info variables} commands or even @code{maint print msymbols} (see
13059@pxref{Symbols}). Here's an example:
13060
13061@smallexample
f7dc1244 13062(@value{GDBP}) info function CreateFileA
be448670
CF
13063All functions matching regular expression "CreateFileA":
13064
13065Non-debugging symbols:
130660x77e885f4 CreateFileA
130670x77e885f4 KERNEL32!CreateFileA
13068@end smallexample
13069
13070@smallexample
f7dc1244 13071(@value{GDBP}) info function !
be448670
CF
13072All functions matching regular expression "!":
13073
13074Non-debugging symbols:
130750x6100114c cygwin1!__assert
130760x61004034 cygwin1!_dll_crt0@@0
130770x61004240 cygwin1!dll_crt0(per_process *)
13078[etc...]
13079@end smallexample
13080
13081@subsubsection Working with minimal symbols
13082
13083Symbols extracted from a DLL's export table do not contain very much
13084type information. All that @value{GDBN} can do is guess whether a symbol
13085refers to a function or variable depending on the linker section that
13086contains the symbol. Also note that the actual contents of the memory
13087contained in a DLL are not available unless the program is running. This
13088means that you cannot examine the contents of a variable or disassemble
13089a function within a DLL without a running program.
13090
13091Variables are generally treated as pointers and dereferenced
13092automatically. For this reason, it is often necessary to prefix a
13093variable name with the address-of operator (``&'') and provide explicit
13094type information in the command. Here's an example of the type of
13095problem:
13096
13097@smallexample
f7dc1244 13098(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
13099$1 = 268572168
13100@end smallexample
13101
13102@smallexample
f7dc1244 13103(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
131040x10021610: "\230y\""
13105@end smallexample
13106
13107And two possible solutions:
13108
13109@smallexample
f7dc1244 13110(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
13111$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
13112@end smallexample
13113
13114@smallexample
f7dc1244 13115(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 131160x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 13117(@value{GDBP}) x/x 0x10021608
be448670 131180x10021608: 0x0022fd98
f7dc1244 13119(@value{GDBP}) x/s 0x0022fd98
be448670
CF
131200x22fd98: "/cygdrive/c/mydirectory/myprogram"
13121@end smallexample
13122
13123Setting a break point within a DLL is possible even before the program
13124starts execution. However, under these circumstances, @value{GDBN} can't
13125examine the initial instructions of the function in order to skip the
13126function's frame set-up code. You can work around this by using ``*&''
13127to set the breakpoint at a raw memory address:
13128
13129@smallexample
f7dc1244 13130(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
13131Breakpoint 1 at 0x1e04eff0
13132@end smallexample
13133
13134The author of these extensions is not entirely convinced that setting a
13135break point within a shared DLL like @file{kernel32.dll} is completely
13136safe.
13137
14d6dd68
EZ
13138@node Hurd Native
13139@subsection Commands specific to @sc{gnu} Hurd systems
13140@cindex @sc{gnu} Hurd debugging
13141
13142This subsection describes @value{GDBN} commands specific to the
13143@sc{gnu} Hurd native debugging.
13144
13145@table @code
13146@item set signals
13147@itemx set sigs
13148@kindex set signals@r{, Hurd command}
13149@kindex set sigs@r{, Hurd command}
13150This command toggles the state of inferior signal interception by
13151@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
13152affected by this command. @code{sigs} is a shorthand alias for
13153@code{signals}.
13154
13155@item show signals
13156@itemx show sigs
13157@kindex show signals@r{, Hurd command}
13158@kindex show sigs@r{, Hurd command}
13159Show the current state of intercepting inferior's signals.
13160
13161@item set signal-thread
13162@itemx set sigthread
13163@kindex set signal-thread
13164@kindex set sigthread
13165This command tells @value{GDBN} which thread is the @code{libc} signal
13166thread. That thread is run when a signal is delivered to a running
13167process. @code{set sigthread} is the shorthand alias of @code{set
13168signal-thread}.
13169
13170@item show signal-thread
13171@itemx show sigthread
13172@kindex show signal-thread
13173@kindex show sigthread
13174These two commands show which thread will run when the inferior is
13175delivered a signal.
13176
13177@item set stopped
13178@kindex set stopped@r{, Hurd command}
13179This commands tells @value{GDBN} that the inferior process is stopped,
13180as with the @code{SIGSTOP} signal. The stopped process can be
13181continued by delivering a signal to it.
13182
13183@item show stopped
13184@kindex show stopped@r{, Hurd command}
13185This command shows whether @value{GDBN} thinks the debuggee is
13186stopped.
13187
13188@item set exceptions
13189@kindex set exceptions@r{, Hurd command}
13190Use this command to turn off trapping of exceptions in the inferior.
13191When exception trapping is off, neither breakpoints nor
13192single-stepping will work. To restore the default, set exception
13193trapping on.
13194
13195@item show exceptions
13196@kindex show exceptions@r{, Hurd command}
13197Show the current state of trapping exceptions in the inferior.
13198
13199@item set task pause
13200@kindex set task@r{, Hurd commands}
13201@cindex task attributes (@sc{gnu} Hurd)
13202@cindex pause current task (@sc{gnu} Hurd)
13203This command toggles task suspension when @value{GDBN} has control.
13204Setting it to on takes effect immediately, and the task is suspended
13205whenever @value{GDBN} gets control. Setting it to off will take
13206effect the next time the inferior is continued. If this option is set
13207to off, you can use @code{set thread default pause on} or @code{set
13208thread pause on} (see below) to pause individual threads.
13209
13210@item show task pause
13211@kindex show task@r{, Hurd commands}
13212Show the current state of task suspension.
13213
13214@item set task detach-suspend-count
13215@cindex task suspend count
13216@cindex detach from task, @sc{gnu} Hurd
13217This command sets the suspend count the task will be left with when
13218@value{GDBN} detaches from it.
13219
13220@item show task detach-suspend-count
13221Show the suspend count the task will be left with when detaching.
13222
13223@item set task exception-port
13224@itemx set task excp
13225@cindex task exception port, @sc{gnu} Hurd
13226This command sets the task exception port to which @value{GDBN} will
13227forward exceptions. The argument should be the value of the @dfn{send
13228rights} of the task. @code{set task excp} is a shorthand alias.
13229
13230@item set noninvasive
13231@cindex noninvasive task options
13232This command switches @value{GDBN} to a mode that is the least
13233invasive as far as interfering with the inferior is concerned. This
13234is the same as using @code{set task pause}, @code{set exceptions}, and
13235@code{set signals} to values opposite to the defaults.
13236
13237@item info send-rights
13238@itemx info receive-rights
13239@itemx info port-rights
13240@itemx info port-sets
13241@itemx info dead-names
13242@itemx info ports
13243@itemx info psets
13244@cindex send rights, @sc{gnu} Hurd
13245@cindex receive rights, @sc{gnu} Hurd
13246@cindex port rights, @sc{gnu} Hurd
13247@cindex port sets, @sc{gnu} Hurd
13248@cindex dead names, @sc{gnu} Hurd
13249These commands display information about, respectively, send rights,
13250receive rights, port rights, port sets, and dead names of a task.
13251There are also shorthand aliases: @code{info ports} for @code{info
13252port-rights} and @code{info psets} for @code{info port-sets}.
13253
13254@item set thread pause
13255@kindex set thread@r{, Hurd command}
13256@cindex thread properties, @sc{gnu} Hurd
13257@cindex pause current thread (@sc{gnu} Hurd)
13258This command toggles current thread suspension when @value{GDBN} has
13259control. Setting it to on takes effect immediately, and the current
13260thread is suspended whenever @value{GDBN} gets control. Setting it to
13261off will take effect the next time the inferior is continued.
13262Normally, this command has no effect, since when @value{GDBN} has
13263control, the whole task is suspended. However, if you used @code{set
13264task pause off} (see above), this command comes in handy to suspend
13265only the current thread.
13266
13267@item show thread pause
13268@kindex show thread@r{, Hurd command}
13269This command shows the state of current thread suspension.
13270
13271@item set thread run
13272This comamnd sets whether the current thread is allowed to run.
13273
13274@item show thread run
13275Show whether the current thread is allowed to run.
13276
13277@item set thread detach-suspend-count
13278@cindex thread suspend count, @sc{gnu} Hurd
13279@cindex detach from thread, @sc{gnu} Hurd
13280This command sets the suspend count @value{GDBN} will leave on a
13281thread when detaching. This number is relative to the suspend count
13282found by @value{GDBN} when it notices the thread; use @code{set thread
13283takeover-suspend-count} to force it to an absolute value.
13284
13285@item show thread detach-suspend-count
13286Show the suspend count @value{GDBN} will leave on the thread when
13287detaching.
13288
13289@item set thread exception-port
13290@itemx set thread excp
13291Set the thread exception port to which to forward exceptions. This
13292overrides the port set by @code{set task exception-port} (see above).
13293@code{set thread excp} is the shorthand alias.
13294
13295@item set thread takeover-suspend-count
13296Normally, @value{GDBN}'s thread suspend counts are relative to the
13297value @value{GDBN} finds when it notices each thread. This command
13298changes the suspend counts to be absolute instead.
13299
13300@item set thread default
13301@itemx show thread default
13302@cindex thread default settings, @sc{gnu} Hurd
13303Each of the above @code{set thread} commands has a @code{set thread
13304default} counterpart (e.g., @code{set thread default pause}, @code{set
13305thread default exception-port}, etc.). The @code{thread default}
13306variety of commands sets the default thread properties for all
13307threads; you can then change the properties of individual threads with
13308the non-default commands.
13309@end table
13310
13311
a64548ea
EZ
13312@node Neutrino
13313@subsection QNX Neutrino
13314@cindex QNX Neutrino
13315
13316@value{GDBN} provides the following commands specific to the QNX
13317Neutrino target:
13318
13319@table @code
13320@item set debug nto-debug
13321@kindex set debug nto-debug
13322When set to on, enables debugging messages specific to the QNX
13323Neutrino support.
13324
13325@item show debug nto-debug
13326@kindex show debug nto-debug
13327Show the current state of QNX Neutrino messages.
13328@end table
13329
13330
8e04817f
AC
13331@node Embedded OS
13332@section Embedded Operating Systems
104c1213 13333
8e04817f
AC
13334This section describes configurations involving the debugging of
13335embedded operating systems that are available for several different
13336architectures.
d4f3574e 13337
8e04817f
AC
13338@menu
13339* VxWorks:: Using @value{GDBN} with VxWorks
13340@end menu
104c1213 13341
8e04817f
AC
13342@value{GDBN} includes the ability to debug programs running on
13343various real-time operating systems.
104c1213 13344
8e04817f
AC
13345@node VxWorks
13346@subsection Using @value{GDBN} with VxWorks
104c1213 13347
8e04817f 13348@cindex VxWorks
104c1213 13349
8e04817f 13350@table @code
104c1213 13351
8e04817f
AC
13352@kindex target vxworks
13353@item target vxworks @var{machinename}
13354A VxWorks system, attached via TCP/IP. The argument @var{machinename}
13355is the target system's machine name or IP address.
104c1213 13356
8e04817f 13357@end table
104c1213 13358
8e04817f
AC
13359On VxWorks, @code{load} links @var{filename} dynamically on the
13360current target system as well as adding its symbols in @value{GDBN}.
104c1213 13361
8e04817f
AC
13362@value{GDBN} enables developers to spawn and debug tasks running on networked
13363VxWorks targets from a Unix host. Already-running tasks spawned from
13364the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
13365both the Unix host and on the VxWorks target. The program
13366@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
13367installed with the name @code{vxgdb}, to distinguish it from a
13368@value{GDBN} for debugging programs on the host itself.)
104c1213 13369
8e04817f
AC
13370@table @code
13371@item VxWorks-timeout @var{args}
13372@kindex vxworks-timeout
13373All VxWorks-based targets now support the option @code{vxworks-timeout}.
13374This option is set by the user, and @var{args} represents the number of
13375seconds @value{GDBN} waits for responses to rpc's. You might use this if
13376your VxWorks target is a slow software simulator or is on the far side
13377of a thin network line.
13378@end table
104c1213 13379
8e04817f
AC
13380The following information on connecting to VxWorks was current when
13381this manual was produced; newer releases of VxWorks may use revised
13382procedures.
104c1213 13383
4644b6e3 13384@findex INCLUDE_RDB
8e04817f
AC
13385To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
13386to include the remote debugging interface routines in the VxWorks
13387library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
13388VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
13389kernel. The resulting kernel contains @file{rdb.a}, and spawns the
13390source debugging task @code{tRdbTask} when VxWorks is booted. For more
13391information on configuring and remaking VxWorks, see the manufacturer's
13392manual.
13393@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 13394
8e04817f
AC
13395Once you have included @file{rdb.a} in your VxWorks system image and set
13396your Unix execution search path to find @value{GDBN}, you are ready to
13397run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
13398@code{vxgdb}, depending on your installation).
104c1213 13399
8e04817f 13400@value{GDBN} comes up showing the prompt:
104c1213 13401
474c8240 13402@smallexample
8e04817f 13403(vxgdb)
474c8240 13404@end smallexample
104c1213 13405
8e04817f
AC
13406@menu
13407* VxWorks Connection:: Connecting to VxWorks
13408* VxWorks Download:: VxWorks download
13409* VxWorks Attach:: Running tasks
13410@end menu
104c1213 13411
8e04817f
AC
13412@node VxWorks Connection
13413@subsubsection Connecting to VxWorks
104c1213 13414
8e04817f
AC
13415The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
13416network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 13417
474c8240 13418@smallexample
8e04817f 13419(vxgdb) target vxworks tt
474c8240 13420@end smallexample
104c1213 13421
8e04817f
AC
13422@need 750
13423@value{GDBN} displays messages like these:
104c1213 13424
8e04817f
AC
13425@smallexample
13426Attaching remote machine across net...
13427Connected to tt.
13428@end smallexample
104c1213 13429
8e04817f
AC
13430@need 1000
13431@value{GDBN} then attempts to read the symbol tables of any object modules
13432loaded into the VxWorks target since it was last booted. @value{GDBN} locates
13433these files by searching the directories listed in the command search
13434path (@pxref{Environment, ,Your program's environment}); if it fails
13435to find an object file, it displays a message such as:
5d161b24 13436
474c8240 13437@smallexample
8e04817f 13438prog.o: No such file or directory.
474c8240 13439@end smallexample
104c1213 13440
8e04817f
AC
13441When this happens, add the appropriate directory to the search path with
13442the @value{GDBN} command @code{path}, and execute the @code{target}
13443command again.
104c1213 13444
8e04817f
AC
13445@node VxWorks Download
13446@subsubsection VxWorks download
104c1213 13447
8e04817f
AC
13448@cindex download to VxWorks
13449If you have connected to the VxWorks target and you want to debug an
13450object that has not yet been loaded, you can use the @value{GDBN}
13451@code{load} command to download a file from Unix to VxWorks
13452incrementally. The object file given as an argument to the @code{load}
13453command is actually opened twice: first by the VxWorks target in order
13454to download the code, then by @value{GDBN} in order to read the symbol
13455table. This can lead to problems if the current working directories on
13456the two systems differ. If both systems have NFS mounted the same
13457filesystems, you can avoid these problems by using absolute paths.
13458Otherwise, it is simplest to set the working directory on both systems
13459to the directory in which the object file resides, and then to reference
13460the file by its name, without any path. For instance, a program
13461@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
13462and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
13463program, type this on VxWorks:
104c1213 13464
474c8240 13465@smallexample
8e04817f 13466-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 13467@end smallexample
104c1213 13468
8e04817f
AC
13469@noindent
13470Then, in @value{GDBN}, type:
104c1213 13471
474c8240 13472@smallexample
8e04817f
AC
13473(vxgdb) cd @var{hostpath}/vw/demo/rdb
13474(vxgdb) load prog.o
474c8240 13475@end smallexample
104c1213 13476
8e04817f 13477@value{GDBN} displays a response similar to this:
104c1213 13478
8e04817f
AC
13479@smallexample
13480Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
13481@end smallexample
104c1213 13482
8e04817f
AC
13483You can also use the @code{load} command to reload an object module
13484after editing and recompiling the corresponding source file. Note that
13485this makes @value{GDBN} delete all currently-defined breakpoints,
13486auto-displays, and convenience variables, and to clear the value
13487history. (This is necessary in order to preserve the integrity of
13488debugger's data structures that reference the target system's symbol
13489table.)
104c1213 13490
8e04817f
AC
13491@node VxWorks Attach
13492@subsubsection Running tasks
104c1213
JM
13493
13494@cindex running VxWorks tasks
13495You can also attach to an existing task using the @code{attach} command as
13496follows:
13497
474c8240 13498@smallexample
104c1213 13499(vxgdb) attach @var{task}
474c8240 13500@end smallexample
104c1213
JM
13501
13502@noindent
13503where @var{task} is the VxWorks hexadecimal task ID. The task can be running
13504or suspended when you attach to it. Running tasks are suspended at
13505the time of attachment.
13506
6d2ebf8b 13507@node Embedded Processors
104c1213
JM
13508@section Embedded Processors
13509
13510This section goes into details specific to particular embedded
13511configurations.
13512
c45da7e6
EZ
13513@cindex send command to simulator
13514Whenever a specific embedded processor has a simulator, @value{GDBN}
13515allows to send an arbitrary command to the simulator.
13516
13517@table @code
13518@item sim @var{command}
13519@kindex sim@r{, a command}
13520Send an arbitrary @var{command} string to the simulator. Consult the
13521documentation for the specific simulator in use for information about
13522acceptable commands.
13523@end table
13524
7d86b5d5 13525
104c1213 13526@menu
c45da7e6 13527* ARM:: ARM RDI
172c2a43
KI
13528* H8/300:: Renesas H8/300
13529* H8/500:: Renesas H8/500
13530* M32R/D:: Renesas M32R/D
104c1213 13531* M68K:: Motorola M68K
104c1213 13532* MIPS Embedded:: MIPS Embedded
a37295f9 13533* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
13534* PA:: HP PA Embedded
13535* PowerPC: PowerPC
172c2a43 13536* SH:: Renesas SH
104c1213
JM
13537* Sparclet:: Tsqware Sparclet
13538* Sparclite:: Fujitsu Sparclite
13539* ST2000:: Tandem ST2000
13540* Z8000:: Zilog Z8000
a64548ea
EZ
13541* AVR:: Atmel AVR
13542* CRIS:: CRIS
13543* Super-H:: Renesas Super-H
c45da7e6 13544* WinCE:: Windows CE child processes
104c1213
JM
13545@end menu
13546
6d2ebf8b 13547@node ARM
104c1213 13548@subsection ARM
c45da7e6 13549@cindex ARM RDI
104c1213
JM
13550
13551@table @code
8e04817f
AC
13552@kindex target rdi
13553@item target rdi @var{dev}
13554ARM Angel monitor, via RDI library interface to ADP protocol. You may
13555use this target to communicate with both boards running the Angel
13556monitor, or with the EmbeddedICE JTAG debug device.
13557
13558@kindex target rdp
13559@item target rdp @var{dev}
13560ARM Demon monitor.
13561
13562@end table
13563
e2f4edfd
EZ
13564@value{GDBN} provides the following ARM-specific commands:
13565
13566@table @code
13567@item set arm disassembler
13568@kindex set arm
13569This commands selects from a list of disassembly styles. The
13570@code{"std"} style is the standard style.
13571
13572@item show arm disassembler
13573@kindex show arm
13574Show the current disassembly style.
13575
13576@item set arm apcs32
13577@cindex ARM 32-bit mode
13578This command toggles ARM operation mode between 32-bit and 26-bit.
13579
13580@item show arm apcs32
13581Display the current usage of the ARM 32-bit mode.
13582
13583@item set arm fpu @var{fputype}
13584This command sets the ARM floating-point unit (FPU) type. The
13585argument @var{fputype} can be one of these:
13586
13587@table @code
13588@item auto
13589Determine the FPU type by querying the OS ABI.
13590@item softfpa
13591Software FPU, with mixed-endian doubles on little-endian ARM
13592processors.
13593@item fpa
13594GCC-compiled FPA co-processor.
13595@item softvfp
13596Software FPU with pure-endian doubles.
13597@item vfp
13598VFP co-processor.
13599@end table
13600
13601@item show arm fpu
13602Show the current type of the FPU.
13603
13604@item set arm abi
13605This command forces @value{GDBN} to use the specified ABI.
13606
13607@item show arm abi
13608Show the currently used ABI.
13609
13610@item set debug arm
13611Toggle whether to display ARM-specific debugging messages from the ARM
13612target support subsystem.
13613
13614@item show debug arm
13615Show whether ARM-specific debugging messages are enabled.
13616@end table
13617
c45da7e6
EZ
13618The following commands are available when an ARM target is debugged
13619using the RDI interface:
13620
13621@table @code
13622@item rdilogfile @r{[}@var{file}@r{]}
13623@kindex rdilogfile
13624@cindex ADP (Angel Debugger Protocol) logging
13625Set the filename for the ADP (Angel Debugger Protocol) packet log.
13626With an argument, sets the log file to the specified @var{file}. With
13627no argument, show the current log file name. The default log file is
13628@file{rdi.log}.
13629
13630@item rdilogenable @r{[}@var{arg}@r{]}
13631@kindex rdilogenable
13632Control logging of ADP packets. With an argument of 1 or @code{"yes"}
13633enables logging, with an argument 0 or @code{"no"} disables it. With
13634no arguments displays the current setting. When logging is enabled,
13635ADP packets exchanged between @value{GDBN} and the RDI target device
13636are logged to a file.
13637
13638@item set rdiromatzero
13639@kindex set rdiromatzero
13640@cindex ROM at zero address, RDI
13641Tell @value{GDBN} whether the target has ROM at address 0. If on,
13642vector catching is disabled, so that zero address can be used. If off
13643(the default), vector catching is enabled. For this command to take
13644effect, it needs to be invoked prior to the @code{target rdi} command.
13645
13646@item show rdiromatzero
13647@kindex show rdiromatzero
13648Show the current setting of ROM at zero address.
13649
13650@item set rdiheartbeat
13651@kindex set rdiheartbeat
13652@cindex RDI heartbeat
13653Enable or disable RDI heartbeat packets. It is not recommended to
13654turn on this option, since it confuses ARM and EPI JTAG interface, as
13655well as the Angel monitor.
13656
13657@item show rdiheartbeat
13658@kindex show rdiheartbeat
13659Show the setting of RDI heartbeat packets.
13660@end table
13661
e2f4edfd 13662
8e04817f 13663@node H8/300
172c2a43 13664@subsection Renesas H8/300
8e04817f
AC
13665
13666@table @code
13667
13668@kindex target hms@r{, with H8/300}
13669@item target hms @var{dev}
172c2a43 13670A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
13671Use special commands @code{device} and @code{speed} to control the serial
13672line and the communications speed used.
13673
13674@kindex target e7000@r{, with H8/300}
13675@item target e7000 @var{dev}
172c2a43 13676E7000 emulator for Renesas H8 and SH.
8e04817f
AC
13677
13678@kindex target sh3@r{, with H8/300}
13679@kindex target sh3e@r{, with H8/300}
13680@item target sh3 @var{dev}
13681@itemx target sh3e @var{dev}
172c2a43 13682Renesas SH-3 and SH-3E target systems.
8e04817f
AC
13683
13684@end table
13685
13686@cindex download to H8/300 or H8/500
13687@cindex H8/300 or H8/500 download
172c2a43
KI
13688@cindex download to Renesas SH
13689@cindex Renesas SH download
13690When you select remote debugging to a Renesas SH, H8/300, or H8/500
13691board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
13692board and also opens it as the current executable target for
13693@value{GDBN} on your host (like the @code{file} command).
13694
13695@value{GDBN} needs to know these things to talk to your
172c2a43 13696Renesas SH, H8/300, or H8/500:
8e04817f
AC
13697
13698@enumerate
13699@item
13700that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
13701for Renesas microprocessors, or @samp{target e7000}, the in-circuit
13702emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
13703the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
13704H8/300, or H8/500.)
13705
13706@item
172c2a43 13707what serial device connects your host to your Renesas board (the first
8e04817f
AC
13708serial device available on your host is the default).
13709
13710@item
13711what speed to use over the serial device.
13712@end enumerate
13713
13714@menu
172c2a43
KI
13715* Renesas Boards:: Connecting to Renesas boards.
13716* Renesas ICE:: Using the E7000 In-Circuit Emulator.
13717* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
13718@end menu
13719
172c2a43
KI
13720@node Renesas Boards
13721@subsubsection Connecting to Renesas boards
8e04817f
AC
13722
13723@c only for Unix hosts
13724@kindex device
172c2a43 13725@cindex serial device, Renesas micros
8e04817f
AC
13726Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
13727need to explicitly set the serial device. The default @var{port} is the
13728first available port on your host. This is only necessary on Unix
13729hosts, where it is typically something like @file{/dev/ttya}.
13730
13731@kindex speed
172c2a43 13732@cindex serial line speed, Renesas micros
8e04817f
AC
13733@code{@value{GDBN}} has another special command to set the communications
13734speed: @samp{speed @var{bps}}. This command also is only used from Unix
13735hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
13736the DOS @code{mode} command (for instance,
13737@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
13738
13739The @samp{device} and @samp{speed} commands are available only when you
172c2a43 13740use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
13741use a DOS host,
13742@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
13743called @code{asynctsr} to communicate with the development board
13744through a PC serial port. You must also use the DOS @code{mode} command
13745to set up the serial port on the DOS side.
13746
13747The following sample session illustrates the steps needed to start a
13748program under @value{GDBN} control on an H8/300. The example uses a
13749sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 13750the Renesas SH and the H8/500.
8e04817f
AC
13751
13752First hook up your development board. In this example, we use a
13753board attached to serial port @code{COM2}; if you use a different serial
13754port, substitute its name in the argument of the @code{mode} command.
13755When you call @code{asynctsr}, the auxiliary comms program used by the
13756debugger, you give it just the numeric part of the serial port's name;
13757for example, @samp{asyncstr 2} below runs @code{asyncstr} on
13758@code{COM2}.
13759
474c8240 13760@smallexample
8e04817f
AC
13761C:\H8300\TEST> asynctsr 2
13762C:\H8300\TEST> mode com2:9600,n,8,1,p
13763
13764Resident portion of MODE loaded
13765
13766COM2: 9600, n, 8, 1, p
13767
474c8240 13768@end smallexample
8e04817f
AC
13769
13770@quotation
13771@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
13772@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
13773disable it, or even boot without it, to use @code{asynctsr} to control
13774your development board.
13775@end quotation
13776
13777@kindex target hms@r{, and serial protocol}
13778Now that serial communications are set up, and the development board is
9c16f35a 13779connected, you can start up @value{GDBN}. Call @code{@value{GDBN}} with
8e04817f
AC
13780the name of your program as the argument. @code{@value{GDBN}} prompts
13781you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
13782commands to begin your debugging session: @samp{target hms} to specify
172c2a43 13783cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
13784download your program to the board. @code{load} displays the names of
13785the program's sections, and a @samp{*} for each 2K of data downloaded.
13786(If you want to refresh @value{GDBN} data on symbols or on the
13787executable file without downloading, use the @value{GDBN} commands
13788@code{file} or @code{symbol-file}. These commands, and @code{load}
13789itself, are described in @ref{Files,,Commands to specify files}.)
13790
13791@smallexample
13792(eg-C:\H8300\TEST) @value{GDBP} t.x
13793@value{GDBN} is free software and you are welcome to distribute copies
13794 of it under certain conditions; type "show copying" to see
13795 the conditions.
13796There is absolutely no warranty for @value{GDBN}; type "show warranty"
13797for details.
13798@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
13799(@value{GDBP}) target hms
13800Connected to remote H8/300 HMS system.
13801(@value{GDBP}) load t.x
13802.text : 0x8000 .. 0xabde ***********
13803.data : 0xabde .. 0xad30 *
13804.stack : 0xf000 .. 0xf014 *
13805@end smallexample
13806
13807At this point, you're ready to run or debug your program. From here on,
13808you can use all the usual @value{GDBN} commands. The @code{break} command
13809sets breakpoints; the @code{run} command starts your program;
13810@code{print} or @code{x} display data; the @code{continue} command
13811resumes execution after stopping at a breakpoint. You can use the
13812@code{help} command at any time to find out more about @value{GDBN} commands.
13813
13814Remember, however, that @emph{operating system} facilities aren't
13815available on your development board; for example, if your program hangs,
13816you can't send an interrupt---but you can press the @sc{reset} switch!
13817
13818Use the @sc{reset} button on the development board
13819@itemize @bullet
13820@item
13821to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
13822no way to pass an interrupt signal to the development board); and
13823
13824@item
13825to return to the @value{GDBN} command prompt after your program finishes
13826normally. The communications protocol provides no other way for @value{GDBN}
13827to detect program completion.
13828@end itemize
13829
13830In either case, @value{GDBN} sees the effect of a @sc{reset} on the
13831development board as a ``normal exit'' of your program.
13832
172c2a43 13833@node Renesas ICE
8e04817f
AC
13834@subsubsection Using the E7000 in-circuit emulator
13835
172c2a43 13836@kindex target e7000@r{, with Renesas ICE}
8e04817f 13837You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 13838Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
13839e7000} command to connect @value{GDBN} to your E7000:
13840
13841@table @code
13842@item target e7000 @var{port} @var{speed}
13843Use this form if your E7000 is connected to a serial port. The
13844@var{port} argument identifies what serial port to use (for example,
13845@samp{com2}). The third argument is the line speed in bits per second
13846(for example, @samp{9600}).
13847
13848@item target e7000 @var{hostname}
13849If your E7000 is installed as a host on a TCP/IP network, you can just
13850specify its hostname; @value{GDBN} uses @code{telnet} to connect.
13851@end table
13852
ba04e063
EZ
13853The following special commands are available when debugging with the
13854Renesas E7000 ICE:
13855
13856@table @code
13857@item e7000 @var{command}
13858@kindex e7000
13859@cindex send command to E7000 monitor
13860This sends the specified @var{command} to the E7000 monitor.
13861
13862@item ftplogin @var{machine} @var{username} @var{password} @var{dir}
13863@kindex ftplogin@r{, E7000}
13864This command records information for subsequent interface with the
13865E7000 monitor via the FTP protocol: @value{GDBN} will log into the
13866named @var{machine} using specified @var{username} and @var{password},
13867and then chdir to the named directory @var{dir}.
13868
13869@item ftpload @var{file}
13870@kindex ftpload@r{, E7000}
13871This command uses credentials recorded by @code{ftplogin} to fetch and
13872load the named @var{file} from the E7000 monitor.
13873
13874@item drain
13875@kindex drain@r{, E7000}
13876This command drains any pending text buffers stored on the E7000.
13877
13878@item set usehardbreakpoints
13879@itemx show usehardbreakpoints
13880@kindex set usehardbreakpoints@r{, E7000}
13881@kindex show usehardbreakpoints@r{, E7000}
13882@cindex hardware breakpoints, and E7000
13883These commands set and show the use of hardware breakpoints for all
13884breakpoints. @xref{Set Breaks, hardware-assisted breakpoint}, for
13885more information about using hardware breakpoints selectively.
13886@end table
13887
172c2a43
KI
13888@node Renesas Special
13889@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
13890
13891Some @value{GDBN} commands are available only for the H8/300:
13892
13893@table @code
13894
13895@kindex set machine
13896@kindex show machine
13897@item set machine h8300
13898@itemx set machine h8300h
13899Condition @value{GDBN} for one of the two variants of the H8/300
13900architecture with @samp{set machine}. You can use @samp{show machine}
13901to check which variant is currently in effect.
104c1213
JM
13902
13903@end table
13904
8e04817f
AC
13905@node H8/500
13906@subsection H8/500
104c1213
JM
13907
13908@table @code
13909
8e04817f
AC
13910@kindex set memory @var{mod}
13911@cindex memory models, H8/500
13912@item set memory @var{mod}
13913@itemx show memory
13914Specify which H8/500 memory model (@var{mod}) you are using with
13915@samp{set memory}; check which memory model is in effect with @samp{show
13916memory}. The accepted values for @var{mod} are @code{small},
13917@code{big}, @code{medium}, and @code{compact}.
104c1213 13918
8e04817f 13919@end table
104c1213 13920
8e04817f 13921@node M32R/D
ba04e063 13922@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
13923
13924@table @code
8e04817f
AC
13925@kindex target m32r
13926@item target m32r @var{dev}
172c2a43 13927Renesas M32R/D ROM monitor.
8e04817f 13928
fb3e19c0
KI
13929@kindex target m32rsdi
13930@item target m32rsdi @var{dev}
13931Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
13932@end table
13933
13934The following @value{GDBN} commands are specific to the M32R monitor:
13935
13936@table @code
13937@item set download-path @var{path}
13938@kindex set download-path
13939@cindex find downloadable @sc{srec} files (M32R)
13940Set the default path for finding donwloadable @sc{srec} files.
13941
13942@item show download-path
13943@kindex show download-path
13944Show the default path for downloadable @sc{srec} files.
fb3e19c0 13945
721c2651
EZ
13946@item set board-address @var{addr}
13947@kindex set board-address
13948@cindex M32-EVA target board address
13949Set the IP address for the M32R-EVA target board.
13950
13951@item show board-address
13952@kindex show board-address
13953Show the current IP address of the target board.
13954
13955@item set server-address @var{addr}
13956@kindex set server-address
13957@cindex download server address (M32R)
13958Set the IP address for the download server, which is the @value{GDBN}'s
13959host machine.
13960
13961@item show server-address
13962@kindex show server-address
13963Display the IP address of the download server.
13964
13965@item upload @r{[}@var{file}@r{]}
13966@kindex upload@r{, M32R}
13967Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
13968upload capability. If no @var{file} argument is given, the current
13969executable file is uploaded.
13970
13971@item tload @r{[}@var{file}@r{]}
13972@kindex tload@r{, M32R}
13973Test the @code{upload} command.
8e04817f
AC
13974@end table
13975
ba04e063
EZ
13976The following commands are available for M32R/SDI:
13977
13978@table @code
13979@item sdireset
13980@kindex sdireset
13981@cindex reset SDI connection, M32R
13982This command resets the SDI connection.
13983
13984@item sdistatus
13985@kindex sdistatus
13986This command shows the SDI connection status.
13987
13988@item debug_chaos
13989@kindex debug_chaos
13990@cindex M32R/Chaos debugging
13991Instructs the remote that M32R/Chaos debugging is to be used.
13992
13993@item use_debug_dma
13994@kindex use_debug_dma
13995Instructs the remote to use the DEBUG_DMA method of accessing memory.
13996
13997@item use_mon_code
13998@kindex use_mon_code
13999Instructs the remote to use the MON_CODE method of accessing memory.
14000
14001@item use_ib_break
14002@kindex use_ib_break
14003Instructs the remote to set breakpoints by IB break.
14004
14005@item use_dbt_break
14006@kindex use_dbt_break
14007Instructs the remote to set breakpoints by DBT.
14008@end table
14009
8e04817f
AC
14010@node M68K
14011@subsection M68k
14012
14013The Motorola m68k configuration includes ColdFire support, and
14014target command for the following ROM monitors.
14015
14016@table @code
14017
14018@kindex target abug
14019@item target abug @var{dev}
14020ABug ROM monitor for M68K.
14021
14022@kindex target cpu32bug
14023@item target cpu32bug @var{dev}
14024CPU32BUG monitor, running on a CPU32 (M68K) board.
14025
14026@kindex target dbug
14027@item target dbug @var{dev}
14028dBUG ROM monitor for Motorola ColdFire.
14029
14030@kindex target est
14031@item target est @var{dev}
14032EST-300 ICE monitor, running on a CPU32 (M68K) board.
14033
14034@kindex target rom68k
14035@item target rom68k @var{dev}
14036ROM 68K monitor, running on an M68K IDP board.
14037
14038@end table
14039
8e04817f
AC
14040@table @code
14041
14042@kindex target rombug
14043@item target rombug @var{dev}
14044ROMBUG ROM monitor for OS/9000.
14045
14046@end table
14047
8e04817f
AC
14048@node MIPS Embedded
14049@subsection MIPS Embedded
14050
14051@cindex MIPS boards
14052@value{GDBN} can use the MIPS remote debugging protocol to talk to a
14053MIPS board attached to a serial line. This is available when
14054you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 14055
8e04817f
AC
14056@need 1000
14057Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 14058
8e04817f
AC
14059@table @code
14060@item target mips @var{port}
14061@kindex target mips @var{port}
14062To run a program on the board, start up @code{@value{GDBP}} with the
14063name of your program as the argument. To connect to the board, use the
14064command @samp{target mips @var{port}}, where @var{port} is the name of
14065the serial port connected to the board. If the program has not already
14066been downloaded to the board, you may use the @code{load} command to
14067download it. You can then use all the usual @value{GDBN} commands.
104c1213 14068
8e04817f
AC
14069For example, this sequence connects to the target board through a serial
14070port, and loads and runs a program called @var{prog} through the
14071debugger:
104c1213 14072
474c8240 14073@smallexample
8e04817f
AC
14074host$ @value{GDBP} @var{prog}
14075@value{GDBN} is free software and @dots{}
14076(@value{GDBP}) target mips /dev/ttyb
14077(@value{GDBP}) load @var{prog}
14078(@value{GDBP}) run
474c8240 14079@end smallexample
104c1213 14080
8e04817f
AC
14081@item target mips @var{hostname}:@var{portnumber}
14082On some @value{GDBN} host configurations, you can specify a TCP
14083connection (for instance, to a serial line managed by a terminal
14084concentrator) instead of a serial port, using the syntax
14085@samp{@var{hostname}:@var{portnumber}}.
104c1213 14086
8e04817f
AC
14087@item target pmon @var{port}
14088@kindex target pmon @var{port}
14089PMON ROM monitor.
104c1213 14090
8e04817f
AC
14091@item target ddb @var{port}
14092@kindex target ddb @var{port}
14093NEC's DDB variant of PMON for Vr4300.
104c1213 14094
8e04817f
AC
14095@item target lsi @var{port}
14096@kindex target lsi @var{port}
14097LSI variant of PMON.
104c1213 14098
8e04817f
AC
14099@kindex target r3900
14100@item target r3900 @var{dev}
14101Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 14102
8e04817f
AC
14103@kindex target array
14104@item target array @var{dev}
14105Array Tech LSI33K RAID controller board.
104c1213 14106
8e04817f 14107@end table
104c1213 14108
104c1213 14109
8e04817f
AC
14110@noindent
14111@value{GDBN} also supports these special commands for MIPS targets:
104c1213 14112
8e04817f 14113@table @code
8e04817f
AC
14114@item set mipsfpu double
14115@itemx set mipsfpu single
14116@itemx set mipsfpu none
a64548ea 14117@itemx set mipsfpu auto
8e04817f
AC
14118@itemx show mipsfpu
14119@kindex set mipsfpu
14120@kindex show mipsfpu
14121@cindex MIPS remote floating point
14122@cindex floating point, MIPS remote
14123If your target board does not support the MIPS floating point
14124coprocessor, you should use the command @samp{set mipsfpu none} (if you
14125need this, you may wish to put the command in your @value{GDBN} init
14126file). This tells @value{GDBN} how to find the return value of
14127functions which return floating point values. It also allows
14128@value{GDBN} to avoid saving the floating point registers when calling
14129functions on the board. If you are using a floating point coprocessor
14130with only single precision floating point support, as on the @sc{r4650}
14131processor, use the command @samp{set mipsfpu single}. The default
14132double precision floating point coprocessor may be selected using
14133@samp{set mipsfpu double}.
104c1213 14134
8e04817f
AC
14135In previous versions the only choices were double precision or no
14136floating point, so @samp{set mipsfpu on} will select double precision
14137and @samp{set mipsfpu off} will select no floating point.
104c1213 14138
8e04817f
AC
14139As usual, you can inquire about the @code{mipsfpu} variable with
14140@samp{show mipsfpu}.
104c1213 14141
8e04817f
AC
14142@item set timeout @var{seconds}
14143@itemx set retransmit-timeout @var{seconds}
14144@itemx show timeout
14145@itemx show retransmit-timeout
14146@cindex @code{timeout}, MIPS protocol
14147@cindex @code{retransmit-timeout}, MIPS protocol
14148@kindex set timeout
14149@kindex show timeout
14150@kindex set retransmit-timeout
14151@kindex show retransmit-timeout
14152You can control the timeout used while waiting for a packet, in the MIPS
14153remote protocol, with the @code{set timeout @var{seconds}} command. The
14154default is 5 seconds. Similarly, you can control the timeout used while
14155waiting for an acknowledgement of a packet with the @code{set
14156retransmit-timeout @var{seconds}} command. The default is 3 seconds.
14157You can inspect both values with @code{show timeout} and @code{show
14158retransmit-timeout}. (These commands are @emph{only} available when
14159@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 14160
8e04817f
AC
14161The timeout set by @code{set timeout} does not apply when @value{GDBN}
14162is waiting for your program to stop. In that case, @value{GDBN} waits
14163forever because it has no way of knowing how long the program is going
14164to run before stopping.
ba04e063
EZ
14165
14166@item set syn-garbage-limit @var{num}
14167@kindex set syn-garbage-limit@r{, MIPS remote}
14168@cindex synchronize with remote MIPS target
14169Limit the maximum number of characters @value{GDBN} should ignore when
14170it tries to synchronize with the remote target. The default is 10
14171characters. Setting the limit to -1 means there's no limit.
14172
14173@item show syn-garbage-limit
14174@kindex show syn-garbage-limit@r{, MIPS remote}
14175Show the current limit on the number of characters to ignore when
14176trying to synchronize with the remote system.
14177
14178@item set monitor-prompt @var{prompt}
14179@kindex set monitor-prompt@r{, MIPS remote}
14180@cindex remote monitor prompt
14181Tell @value{GDBN} to expect the specified @var{prompt} string from the
14182remote monitor. The default depends on the target:
14183@table @asis
14184@item pmon target
14185@samp{PMON}
14186@item ddb target
14187@samp{NEC010}
14188@item lsi target
14189@samp{PMON>}
14190@end table
14191
14192@item show monitor-prompt
14193@kindex show monitor-prompt@r{, MIPS remote}
14194Show the current strings @value{GDBN} expects as the prompt from the
14195remote monitor.
14196
14197@item set monitor-warnings
14198@kindex set monitor-warnings@r{, MIPS remote}
14199Enable or disable monitor warnings about hardware breakpoints. This
14200has effect only for the @code{lsi} target. When on, @value{GDBN} will
14201display warning messages whose codes are returned by the @code{lsi}
14202PMON monitor for breakpoint commands.
14203
14204@item show monitor-warnings
14205@kindex show monitor-warnings@r{, MIPS remote}
14206Show the current setting of printing monitor warnings.
14207
14208@item pmon @var{command}
14209@kindex pmon@r{, MIPS remote}
14210@cindex send PMON command
14211This command allows sending an arbitrary @var{command} string to the
14212monitor. The monitor must be in debug mode for this to work.
8e04817f 14213@end table
104c1213 14214
a37295f9
MM
14215@node OpenRISC 1000
14216@subsection OpenRISC 1000
14217@cindex OpenRISC 1000
14218
14219@cindex or1k boards
14220See OR1k Architecture document (@uref{www.opencores.org}) for more information
14221about platform and commands.
14222
14223@table @code
14224
14225@kindex target jtag
14226@item target jtag jtag://@var{host}:@var{port}
14227
14228Connects to remote JTAG server.
14229JTAG remote server can be either an or1ksim or JTAG server,
14230connected via parallel port to the board.
14231
14232Example: @code{target jtag jtag://localhost:9999}
14233
14234@kindex or1ksim
14235@item or1ksim @var{command}
14236If connected to @code{or1ksim} OpenRISC 1000 Architectural
14237Simulator, proprietary commands can be executed.
14238
14239@kindex info or1k spr
14240@item info or1k spr
14241Displays spr groups.
14242
14243@item info or1k spr @var{group}
14244@itemx info or1k spr @var{groupno}
14245Displays register names in selected group.
14246
14247@item info or1k spr @var{group} @var{register}
14248@itemx info or1k spr @var{register}
14249@itemx info or1k spr @var{groupno} @var{registerno}
14250@itemx info or1k spr @var{registerno}
14251Shows information about specified spr register.
14252
14253@kindex spr
14254@item spr @var{group} @var{register} @var{value}
14255@itemx spr @var{register @var{value}}
14256@itemx spr @var{groupno} @var{registerno @var{value}}
14257@itemx spr @var{registerno @var{value}}
14258Writes @var{value} to specified spr register.
14259@end table
14260
14261Some implementations of OpenRISC 1000 Architecture also have hardware trace.
14262It is very similar to @value{GDBN} trace, except it does not interfere with normal
14263program execution and is thus much faster. Hardware breakpoints/watchpoint
14264triggers can be set using:
14265@table @code
14266@item $LEA/$LDATA
14267Load effective address/data
14268@item $SEA/$SDATA
14269Store effective address/data
14270@item $AEA/$ADATA
14271Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
14272@item $FETCH
14273Fetch data
14274@end table
14275
14276When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
14277@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
14278
14279@code{htrace} commands:
14280@cindex OpenRISC 1000 htrace
14281@table @code
14282@kindex hwatch
14283@item hwatch @var{conditional}
14284Set hardware watchpoint on combination of Load/Store Effecive Address(es)
14285or Data. For example:
14286
14287@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14288
14289@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14290
4644b6e3 14291@kindex htrace
a37295f9
MM
14292@item htrace info
14293Display information about current HW trace configuration.
14294
a37295f9
MM
14295@item htrace trigger @var{conditional}
14296Set starting criteria for HW trace.
14297
a37295f9
MM
14298@item htrace qualifier @var{conditional}
14299Set acquisition qualifier for HW trace.
14300
a37295f9
MM
14301@item htrace stop @var{conditional}
14302Set HW trace stopping criteria.
14303
f153cc92 14304@item htrace record [@var{data}]*
a37295f9
MM
14305Selects the data to be recorded, when qualifier is met and HW trace was
14306triggered.
14307
a37295f9 14308@item htrace enable
a37295f9
MM
14309@itemx htrace disable
14310Enables/disables the HW trace.
14311
f153cc92 14312@item htrace rewind [@var{filename}]
a37295f9
MM
14313Clears currently recorded trace data.
14314
14315If filename is specified, new trace file is made and any newly collected data
14316will be written there.
14317
f153cc92 14318@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
14319Prints trace buffer, using current record configuration.
14320
a37295f9
MM
14321@item htrace mode continuous
14322Set continuous trace mode.
14323
a37295f9
MM
14324@item htrace mode suspend
14325Set suspend trace mode.
14326
14327@end table
14328
8e04817f
AC
14329@node PowerPC
14330@subsection PowerPC
104c1213
JM
14331
14332@table @code
8e04817f
AC
14333@kindex target dink32
14334@item target dink32 @var{dev}
14335DINK32 ROM monitor.
104c1213 14336
8e04817f
AC
14337@kindex target ppcbug
14338@item target ppcbug @var{dev}
14339@kindex target ppcbug1
14340@item target ppcbug1 @var{dev}
14341PPCBUG ROM monitor for PowerPC.
104c1213 14342
8e04817f
AC
14343@kindex target sds
14344@item target sds @var{dev}
14345SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 14346@end table
8e04817f 14347
c45da7e6
EZ
14348@cindex SDS protocol
14349The following commands specifi to the SDS protocol are supported
14350by@value{GDBN}:
14351
14352@table @code
14353@item set sdstimeout @var{nsec}
14354@kindex set sdstimeout
14355Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
14356default is 2 seconds.
14357
14358@item show sdstimeout
14359@kindex show sdstimeout
14360Show the current value of the SDS timeout.
14361
14362@item sds @var{command}
14363@kindex sds@r{, a command}
14364Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
14365@end table
14366
c45da7e6 14367
8e04817f
AC
14368@node PA
14369@subsection HP PA Embedded
104c1213
JM
14370
14371@table @code
14372
8e04817f
AC
14373@kindex target op50n
14374@item target op50n @var{dev}
14375OP50N monitor, running on an OKI HPPA board.
14376
14377@kindex target w89k
14378@item target w89k @var{dev}
14379W89K monitor, running on a Winbond HPPA board.
104c1213
JM
14380
14381@end table
14382
8e04817f 14383@node SH
172c2a43 14384@subsection Renesas SH
104c1213
JM
14385
14386@table @code
14387
172c2a43 14388@kindex target hms@r{, with Renesas SH}
8e04817f 14389@item target hms @var{dev}
172c2a43 14390A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
14391commands @code{device} and @code{speed} to control the serial line and
14392the communications speed used.
104c1213 14393
172c2a43 14394@kindex target e7000@r{, with Renesas SH}
8e04817f 14395@item target e7000 @var{dev}
172c2a43 14396E7000 emulator for Renesas SH.
104c1213 14397
8e04817f
AC
14398@kindex target sh3@r{, with SH}
14399@kindex target sh3e@r{, with SH}
14400@item target sh3 @var{dev}
14401@item target sh3e @var{dev}
172c2a43 14402Renesas SH-3 and SH-3E target systems.
104c1213 14403
8e04817f 14404@end table
104c1213 14405
8e04817f
AC
14406@node Sparclet
14407@subsection Tsqware Sparclet
104c1213 14408
8e04817f
AC
14409@cindex Sparclet
14410
14411@value{GDBN} enables developers to debug tasks running on
14412Sparclet targets from a Unix host.
14413@value{GDBN} uses code that runs on
14414both the Unix host and on the Sparclet target. The program
14415@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 14416
8e04817f
AC
14417@table @code
14418@item remotetimeout @var{args}
14419@kindex remotetimeout
14420@value{GDBN} supports the option @code{remotetimeout}.
14421This option is set by the user, and @var{args} represents the number of
14422seconds @value{GDBN} waits for responses.
104c1213
JM
14423@end table
14424
8e04817f
AC
14425@cindex compiling, on Sparclet
14426When compiling for debugging, include the options @samp{-g} to get debug
14427information and @samp{-Ttext} to relocate the program to where you wish to
14428load it on the target. You may also want to add the options @samp{-n} or
14429@samp{-N} in order to reduce the size of the sections. Example:
104c1213 14430
474c8240 14431@smallexample
8e04817f 14432sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 14433@end smallexample
104c1213 14434
8e04817f 14435You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 14436
474c8240 14437@smallexample
8e04817f 14438sparclet-aout-objdump --headers --syms prog
474c8240 14439@end smallexample
104c1213 14440
8e04817f
AC
14441@cindex running, on Sparclet
14442Once you have set
14443your Unix execution search path to find @value{GDBN}, you are ready to
14444run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
14445(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 14446
8e04817f
AC
14447@value{GDBN} comes up showing the prompt:
14448
474c8240 14449@smallexample
8e04817f 14450(gdbslet)
474c8240 14451@end smallexample
104c1213
JM
14452
14453@menu
8e04817f
AC
14454* Sparclet File:: Setting the file to debug
14455* Sparclet Connection:: Connecting to Sparclet
14456* Sparclet Download:: Sparclet download
14457* Sparclet Execution:: Running and debugging
104c1213
JM
14458@end menu
14459
8e04817f
AC
14460@node Sparclet File
14461@subsubsection Setting file to debug
104c1213 14462
8e04817f 14463The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 14464
474c8240 14465@smallexample
8e04817f 14466(gdbslet) file prog
474c8240 14467@end smallexample
104c1213 14468
8e04817f
AC
14469@need 1000
14470@value{GDBN} then attempts to read the symbol table of @file{prog}.
14471@value{GDBN} locates
14472the file by searching the directories listed in the command search
14473path.
14474If the file was compiled with debug information (option "-g"), source
14475files will be searched as well.
14476@value{GDBN} locates
14477the source files by searching the directories listed in the directory search
14478path (@pxref{Environment, ,Your program's environment}).
14479If it fails
14480to find a file, it displays a message such as:
104c1213 14481
474c8240 14482@smallexample
8e04817f 14483prog: No such file or directory.
474c8240 14484@end smallexample
104c1213 14485
8e04817f
AC
14486When this happens, add the appropriate directories to the search paths with
14487the @value{GDBN} commands @code{path} and @code{dir}, and execute the
14488@code{target} command again.
104c1213 14489
8e04817f
AC
14490@node Sparclet Connection
14491@subsubsection Connecting to Sparclet
104c1213 14492
8e04817f
AC
14493The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
14494To connect to a target on serial port ``@code{ttya}'', type:
104c1213 14495
474c8240 14496@smallexample
8e04817f
AC
14497(gdbslet) target sparclet /dev/ttya
14498Remote target sparclet connected to /dev/ttya
14499main () at ../prog.c:3
474c8240 14500@end smallexample
104c1213 14501
8e04817f
AC
14502@need 750
14503@value{GDBN} displays messages like these:
104c1213 14504
474c8240 14505@smallexample
8e04817f 14506Connected to ttya.
474c8240 14507@end smallexample
104c1213 14508
8e04817f
AC
14509@node Sparclet Download
14510@subsubsection Sparclet download
104c1213 14511
8e04817f
AC
14512@cindex download to Sparclet
14513Once connected to the Sparclet target,
14514you can use the @value{GDBN}
14515@code{load} command to download the file from the host to the target.
14516The file name and load offset should be given as arguments to the @code{load}
14517command.
14518Since the file format is aout, the program must be loaded to the starting
14519address. You can use @code{objdump} to find out what this value is. The load
14520offset is an offset which is added to the VMA (virtual memory address)
14521of each of the file's sections.
14522For instance, if the program
14523@file{prog} was linked to text address 0x1201000, with data at 0x12010160
14524and bss at 0x12010170, in @value{GDBN}, type:
104c1213 14525
474c8240 14526@smallexample
8e04817f
AC
14527(gdbslet) load prog 0x12010000
14528Loading section .text, size 0xdb0 vma 0x12010000
474c8240 14529@end smallexample
104c1213 14530
8e04817f
AC
14531If the code is loaded at a different address then what the program was linked
14532to, you may need to use the @code{section} and @code{add-symbol-file} commands
14533to tell @value{GDBN} where to map the symbol table.
14534
14535@node Sparclet Execution
14536@subsubsection Running and debugging
14537
14538@cindex running and debugging Sparclet programs
14539You can now begin debugging the task using @value{GDBN}'s execution control
14540commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
14541manual for the list of commands.
14542
474c8240 14543@smallexample
8e04817f
AC
14544(gdbslet) b main
14545Breakpoint 1 at 0x12010000: file prog.c, line 3.
14546(gdbslet) run
14547Starting program: prog
14548Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
145493 char *symarg = 0;
14550(gdbslet) step
145514 char *execarg = "hello!";
14552(gdbslet)
474c8240 14553@end smallexample
8e04817f
AC
14554
14555@node Sparclite
14556@subsection Fujitsu Sparclite
104c1213
JM
14557
14558@table @code
14559
8e04817f
AC
14560@kindex target sparclite
14561@item target sparclite @var{dev}
14562Fujitsu sparclite boards, used only for the purpose of loading.
14563You must use an additional command to debug the program.
14564For example: target remote @var{dev} using @value{GDBN} standard
14565remote protocol.
104c1213
JM
14566
14567@end table
14568
8e04817f
AC
14569@node ST2000
14570@subsection Tandem ST2000
104c1213 14571
8e04817f
AC
14572@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
14573STDBUG protocol.
104c1213 14574
8e04817f
AC
14575To connect your ST2000 to the host system, see the manufacturer's
14576manual. Once the ST2000 is physically attached, you can run:
104c1213 14577
474c8240 14578@smallexample
8e04817f 14579target st2000 @var{dev} @var{speed}
474c8240 14580@end smallexample
104c1213 14581
8e04817f
AC
14582@noindent
14583to establish it as your debugging environment. @var{dev} is normally
14584the name of a serial device, such as @file{/dev/ttya}, connected to the
14585ST2000 via a serial line. You can instead specify @var{dev} as a TCP
14586connection (for example, to a serial line attached via a terminal
14587concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 14588
8e04817f
AC
14589The @code{load} and @code{attach} commands are @emph{not} defined for
14590this target; you must load your program into the ST2000 as you normally
14591would for standalone operation. @value{GDBN} reads debugging information
14592(such as symbols) from a separate, debugging version of the program
14593available on your host computer.
14594@c FIXME!! This is terribly vague; what little content is here is
14595@c basically hearsay.
104c1213 14596
8e04817f
AC
14597@cindex ST2000 auxiliary commands
14598These auxiliary @value{GDBN} commands are available to help you with the ST2000
14599environment:
104c1213 14600
8e04817f
AC
14601@table @code
14602@item st2000 @var{command}
14603@kindex st2000 @var{cmd}
14604@cindex STDBUG commands (ST2000)
14605@cindex commands to STDBUG (ST2000)
14606Send a @var{command} to the STDBUG monitor. See the manufacturer's
14607manual for available commands.
104c1213 14608
8e04817f
AC
14609@item connect
14610@cindex connect (to STDBUG)
14611Connect the controlling terminal to the STDBUG command monitor. When
14612you are done interacting with STDBUG, typing either of two character
14613sequences gets you back to the @value{GDBN} command prompt:
14614@kbd{@key{RET}~.} (Return, followed by tilde and period) or
14615@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
14616@end table
14617
8e04817f
AC
14618@node Z8000
14619@subsection Zilog Z8000
104c1213 14620
8e04817f
AC
14621@cindex Z8000
14622@cindex simulator, Z8000
14623@cindex Zilog Z8000 simulator
104c1213 14624
8e04817f
AC
14625When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
14626a Z8000 simulator.
14627
14628For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
14629unsegmented variant of the Z8000 architecture) or the Z8001 (the
14630segmented variant). The simulator recognizes which architecture is
14631appropriate by inspecting the object code.
104c1213 14632
8e04817f
AC
14633@table @code
14634@item target sim @var{args}
14635@kindex sim
14636@kindex target sim@r{, with Z8000}
14637Debug programs on a simulated CPU. If the simulator supports setup
14638options, specify them via @var{args}.
104c1213
JM
14639@end table
14640
8e04817f
AC
14641@noindent
14642After specifying this target, you can debug programs for the simulated
14643CPU in the same style as programs for your host computer; use the
14644@code{file} command to load a new program image, the @code{run} command
14645to run your program, and so on.
14646
14647As well as making available all the usual machine registers
14648(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
14649additional items of information as specially named registers:
104c1213
JM
14650
14651@table @code
14652
8e04817f
AC
14653@item cycles
14654Counts clock-ticks in the simulator.
104c1213 14655
8e04817f
AC
14656@item insts
14657Counts instructions run in the simulator.
104c1213 14658
8e04817f
AC
14659@item time
14660Execution time in 60ths of a second.
104c1213 14661
8e04817f 14662@end table
104c1213 14663
8e04817f
AC
14664You can refer to these values in @value{GDBN} expressions with the usual
14665conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
14666conditional breakpoint that suspends only after at least 5000
14667simulated clock ticks.
104c1213 14668
a64548ea
EZ
14669@node AVR
14670@subsection Atmel AVR
14671@cindex AVR
14672
14673When configured for debugging the Atmel AVR, @value{GDBN} supports the
14674following AVR-specific commands:
14675
14676@table @code
14677@item info io_registers
14678@kindex info io_registers@r{, AVR}
14679@cindex I/O registers (Atmel AVR)
14680This command displays information about the AVR I/O registers. For
14681each register, @value{GDBN} prints its number and value.
14682@end table
14683
14684@node CRIS
14685@subsection CRIS
14686@cindex CRIS
14687
14688When configured for debugging CRIS, @value{GDBN} provides the
14689following CRIS-specific commands:
14690
14691@table @code
14692@item set cris-version @var{ver}
14693@cindex CRIS version
e22e55c9
OF
14694Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
14695The CRIS version affects register names and sizes. This command is useful in
14696case autodetection of the CRIS version fails.
a64548ea
EZ
14697
14698@item show cris-version
14699Show the current CRIS version.
14700
14701@item set cris-dwarf2-cfi
14702@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
14703Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
14704Change to @samp{off} when using @code{gcc-cris} whose version is below
14705@code{R59}.
a64548ea
EZ
14706
14707@item show cris-dwarf2-cfi
14708Show the current state of using DWARF-2 CFI.
e22e55c9
OF
14709
14710@item set cris-mode @var{mode}
14711@cindex CRIS mode
14712Set the current CRIS mode to @var{mode}. It should only be changed when
14713debugging in guru mode, in which case it should be set to
14714@samp{guru} (the default is @samp{normal}).
14715
14716@item show cris-mode
14717Show the current CRIS mode.
a64548ea
EZ
14718@end table
14719
14720@node Super-H
14721@subsection Renesas Super-H
14722@cindex Super-H
14723
14724For the Renesas Super-H processor, @value{GDBN} provides these
14725commands:
14726
14727@table @code
14728@item regs
14729@kindex regs@r{, Super-H}
14730Show the values of all Super-H registers.
14731@end table
14732
c45da7e6
EZ
14733@node WinCE
14734@subsection Windows CE
14735@cindex Windows CE
14736
14737The following commands are available for Windows CE:
14738
14739@table @code
14740@item set remotedirectory @var{dir}
14741@kindex set remotedirectory
14742Tell @value{GDBN} to upload files from the named directory @var{dir}.
14743The default is @file{/gdb}, i.e.@: the root directory on the current
14744drive.
14745
14746@item show remotedirectory
14747@kindex show remotedirectory
14748Show the current value of the upload directory.
14749
14750@item set remoteupload @var{method}
14751@kindex set remoteupload
14752Set the method used to upload files to remote device. Valid values
14753for @var{method} are @samp{always}, @samp{newer}, and @samp{never}.
14754The default is @samp{newer}.
14755
14756@item show remoteupload
14757@kindex show remoteupload
14758Show the current setting of the upload method.
14759
14760@item set remoteaddhost
14761@kindex set remoteaddhost
14762Tell @value{GDBN} whether to add this host to the remote stub's
14763arguments when you debug over a network.
14764
14765@item show remoteaddhost
14766@kindex show remoteaddhost
14767Show whether to add this host to remote stub's arguments when
14768debugging over a network.
14769@end table
14770
a64548ea 14771
8e04817f
AC
14772@node Architectures
14773@section Architectures
104c1213 14774
8e04817f
AC
14775This section describes characteristics of architectures that affect
14776all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 14777
8e04817f 14778@menu
9c16f35a 14779* i386::
8e04817f
AC
14780* A29K::
14781* Alpha::
14782* MIPS::
a64548ea 14783* HPPA:: HP PA architecture
8e04817f 14784@end menu
104c1213 14785
9c16f35a
EZ
14786@node i386
14787@subsection x86 Architecture-specific issues.
14788
14789@table @code
14790@item set struct-convention @var{mode}
14791@kindex set struct-convention
14792@cindex struct return convention
14793@cindex struct/union returned in registers
14794Set the convention used by the inferior to return @code{struct}s and
14795@code{union}s from functions to @var{mode}. Possible values of
14796@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
14797default). @code{"default"} or @code{"pcc"} means that @code{struct}s
14798are returned on the stack, while @code{"reg"} means that a
14799@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
14800be returned in a register.
14801
14802@item show struct-convention
14803@kindex show struct-convention
14804Show the current setting of the convention to return @code{struct}s
14805from functions.
14806@end table
14807
8e04817f
AC
14808@node A29K
14809@subsection A29K
104c1213
JM
14810
14811@table @code
104c1213 14812
8e04817f
AC
14813@kindex set rstack_high_address
14814@cindex AMD 29K register stack
14815@cindex register stack, AMD29K
14816@item set rstack_high_address @var{address}
14817On AMD 29000 family processors, registers are saved in a separate
14818@dfn{register stack}. There is no way for @value{GDBN} to determine the
14819extent of this stack. Normally, @value{GDBN} just assumes that the
14820stack is ``large enough''. This may result in @value{GDBN} referencing
14821memory locations that do not exist. If necessary, you can get around
14822this problem by specifying the ending address of the register stack with
14823the @code{set rstack_high_address} command. The argument should be an
14824address, which you probably want to precede with @samp{0x} to specify in
14825hexadecimal.
104c1213 14826
8e04817f
AC
14827@kindex show rstack_high_address
14828@item show rstack_high_address
14829Display the current limit of the register stack, on AMD 29000 family
14830processors.
104c1213 14831
8e04817f 14832@end table
104c1213 14833
8e04817f
AC
14834@node Alpha
14835@subsection Alpha
104c1213 14836
8e04817f 14837See the following section.
104c1213 14838
8e04817f
AC
14839@node MIPS
14840@subsection MIPS
104c1213 14841
8e04817f
AC
14842@cindex stack on Alpha
14843@cindex stack on MIPS
14844@cindex Alpha stack
14845@cindex MIPS stack
14846Alpha- and MIPS-based computers use an unusual stack frame, which
14847sometimes requires @value{GDBN} to search backward in the object code to
14848find the beginning of a function.
104c1213 14849
8e04817f
AC
14850@cindex response time, MIPS debugging
14851To improve response time (especially for embedded applications, where
14852@value{GDBN} may be restricted to a slow serial line for this search)
14853you may want to limit the size of this search, using one of these
14854commands:
104c1213 14855
8e04817f
AC
14856@table @code
14857@cindex @code{heuristic-fence-post} (Alpha, MIPS)
14858@item set heuristic-fence-post @var{limit}
14859Restrict @value{GDBN} to examining at most @var{limit} bytes in its
14860search for the beginning of a function. A value of @var{0} (the
14861default) means there is no limit. However, except for @var{0}, the
14862larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
14863and therefore the longer it takes to run. You should only need to use
14864this command when debugging a stripped executable.
104c1213 14865
8e04817f
AC
14866@item show heuristic-fence-post
14867Display the current limit.
14868@end table
104c1213
JM
14869
14870@noindent
8e04817f
AC
14871These commands are available @emph{only} when @value{GDBN} is configured
14872for debugging programs on Alpha or MIPS processors.
104c1213 14873
a64548ea
EZ
14874Several MIPS-specific commands are available when debugging MIPS
14875programs:
14876
14877@table @code
14878@item set mips saved-gpreg-size @var{size}
14879@kindex set mips saved-gpreg-size
14880@cindex MIPS GP register size on stack
14881Set the size of MIPS general-purpose registers saved on the stack.
14882The argument @var{size} can be one of the following:
14883
14884@table @samp
14885@item 32
1488632-bit GP registers
14887@item 64
1488864-bit GP registers
14889@item auto
14890Use the target's default setting or autodetect the saved size from the
14891information contained in the executable. This is the default
14892@end table
14893
14894@item show mips saved-gpreg-size
14895@kindex show mips saved-gpreg-size
14896Show the current size of MIPS GP registers on the stack.
14897
14898@item set mips stack-arg-size @var{size}
14899@kindex set mips stack-arg-size
14900@cindex MIPS stack space for arguments
14901Set the amount of stack space reserved for arguments to functions.
14902The argument can be one of @code{"32"}, @code{"64"} or @code{"auto"}
14903(the default).
14904
14905@item set mips abi @var{arg}
14906@kindex set mips abi
14907@cindex set ABI for MIPS
14908Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
14909values of @var{arg} are:
14910
14911@table @samp
14912@item auto
14913The default ABI associated with the current binary (this is the
14914default).
14915@item o32
14916@item o64
14917@item n32
14918@item n64
14919@item eabi32
14920@item eabi64
14921@item auto
14922@end table
14923
14924@item show mips abi
14925@kindex show mips abi
14926Show the MIPS ABI used by @value{GDBN} to debug the inferior.
14927
14928@item set mipsfpu
14929@itemx show mipsfpu
14930@xref{MIPS Embedded, set mipsfpu}.
14931
14932@item set mips mask-address @var{arg}
14933@kindex set mips mask-address
14934@cindex MIPS addresses, masking
14935This command determines whether the most-significant 32 bits of 64-bit
14936MIPS addresses are masked off. The argument @var{arg} can be
14937@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
14938setting, which lets @value{GDBN} determine the correct value.
14939
14940@item show mips mask-address
14941@kindex show mips mask-address
14942Show whether the upper 32 bits of MIPS addresses are masked off or
14943not.
14944
14945@item set remote-mips64-transfers-32bit-regs
14946@kindex set remote-mips64-transfers-32bit-regs
14947This command controls compatibility with 64-bit MIPS targets that
14948transfer data in 32-bit quantities. If you have an old MIPS 64 target
14949that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
14950and 64 bits for other registers, set this option to @samp{on}.
14951
14952@item show remote-mips64-transfers-32bit-regs
14953@kindex show remote-mips64-transfers-32bit-regs
14954Show the current setting of compatibility with older MIPS 64 targets.
14955
14956@item set debug mips
14957@kindex set debug mips
14958This command turns on and off debugging messages for the MIPS-specific
14959target code in @value{GDBN}.
14960
14961@item show debug mips
14962@kindex show debug mips
14963Show the current setting of MIPS debugging messages.
14964@end table
14965
14966
14967@node HPPA
14968@subsection HPPA
14969@cindex HPPA support
14970
14971When @value{GDBN} is debugging te HP PA architecture, it provides the
14972following special commands:
14973
14974@table @code
14975@item set debug hppa
14976@kindex set debug hppa
14977THis command determines whether HPPA architecture specific debugging
14978messages are to be displayed.
14979
14980@item show debug hppa
14981Show whether HPPA debugging messages are displayed.
14982
14983@item maint print unwind @var{address}
14984@kindex maint print unwind@r{, HPPA}
14985This command displays the contents of the unwind table entry at the
14986given @var{address}.
14987
14988@end table
14989
104c1213 14990
8e04817f
AC
14991@node Controlling GDB
14992@chapter Controlling @value{GDBN}
14993
14994You can alter the way @value{GDBN} interacts with you by using the
14995@code{set} command. For commands controlling how @value{GDBN} displays
14996data, see @ref{Print Settings, ,Print settings}. Other settings are
14997described here.
14998
14999@menu
15000* Prompt:: Prompt
15001* Editing:: Command editing
d620b259 15002* Command History:: Command history
8e04817f
AC
15003* Screen Size:: Screen size
15004* Numbers:: Numbers
1e698235 15005* ABI:: Configuring the current ABI
8e04817f
AC
15006* Messages/Warnings:: Optional warnings and messages
15007* Debugging Output:: Optional messages about internal happenings
15008@end menu
15009
15010@node Prompt
15011@section Prompt
104c1213 15012
8e04817f 15013@cindex prompt
104c1213 15014
8e04817f
AC
15015@value{GDBN} indicates its readiness to read a command by printing a string
15016called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
15017can change the prompt string with the @code{set prompt} command. For
15018instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
15019the prompt in one of the @value{GDBN} sessions so that you can always tell
15020which one you are talking to.
104c1213 15021
8e04817f
AC
15022@emph{Note:} @code{set prompt} does not add a space for you after the
15023prompt you set. This allows you to set a prompt which ends in a space
15024or a prompt that does not.
104c1213 15025
8e04817f
AC
15026@table @code
15027@kindex set prompt
15028@item set prompt @var{newprompt}
15029Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 15030
8e04817f
AC
15031@kindex show prompt
15032@item show prompt
15033Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
15034@end table
15035
8e04817f
AC
15036@node Editing
15037@section Command editing
15038@cindex readline
15039@cindex command line editing
104c1213 15040
703663ab 15041@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
15042@sc{gnu} library provides consistent behavior for programs which provide a
15043command line interface to the user. Advantages are @sc{gnu} Emacs-style
15044or @dfn{vi}-style inline editing of commands, @code{csh}-like history
15045substitution, and a storage and recall of command history across
15046debugging sessions.
104c1213 15047
8e04817f
AC
15048You may control the behavior of command line editing in @value{GDBN} with the
15049command @code{set}.
104c1213 15050
8e04817f
AC
15051@table @code
15052@kindex set editing
15053@cindex editing
15054@item set editing
15055@itemx set editing on
15056Enable command line editing (enabled by default).
104c1213 15057
8e04817f
AC
15058@item set editing off
15059Disable command line editing.
104c1213 15060
8e04817f
AC
15061@kindex show editing
15062@item show editing
15063Show whether command line editing is enabled.
104c1213
JM
15064@end table
15065
703663ab
EZ
15066@xref{Command Line Editing}, for more details about the Readline
15067interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
15068encouraged to read that chapter.
15069
d620b259 15070@node Command History
8e04817f 15071@section Command history
703663ab 15072@cindex command history
8e04817f
AC
15073
15074@value{GDBN} can keep track of the commands you type during your
15075debugging sessions, so that you can be certain of precisely what
15076happened. Use these commands to manage the @value{GDBN} command
15077history facility.
104c1213 15078
703663ab
EZ
15079@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
15080package, to provide the history facility. @xref{Using History
15081Interactively}, for the detailed description of the History library.
15082
d620b259
NR
15083To issue a command to @value{GDBN} without affecting certain aspects of
15084the state which is seen by users, prefix it with @samp{server }. This
15085means that this command will not affect the command history, nor will it
15086affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
15087pressed on a line by itself.
15088
15089@cindex @code{server}, command prefix
15090The server prefix does not affect the recording of values into the value
15091history; to print a value without recording it into the value history,
15092use the @code{output} command instead of the @code{print} command.
15093
703663ab
EZ
15094Here is the description of @value{GDBN} commands related to command
15095history.
15096
104c1213 15097@table @code
8e04817f
AC
15098@cindex history substitution
15099@cindex history file
15100@kindex set history filename
4644b6e3 15101@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
15102@item set history filename @var{fname}
15103Set the name of the @value{GDBN} command history file to @var{fname}.
15104This is the file where @value{GDBN} reads an initial command history
15105list, and where it writes the command history from this session when it
15106exits. You can access this list through history expansion or through
15107the history command editing characters listed below. This file defaults
15108to the value of the environment variable @code{GDBHISTFILE}, or to
15109@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
15110is not set.
104c1213 15111
9c16f35a
EZ
15112@cindex save command history
15113@kindex set history save
8e04817f
AC
15114@item set history save
15115@itemx set history save on
15116Record command history in a file, whose name may be specified with the
15117@code{set history filename} command. By default, this option is disabled.
104c1213 15118
8e04817f
AC
15119@item set history save off
15120Stop recording command history in a file.
104c1213 15121
8e04817f 15122@cindex history size
9c16f35a 15123@kindex set history size
6fc08d32 15124@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
15125@item set history size @var{size}
15126Set the number of commands which @value{GDBN} keeps in its history list.
15127This defaults to the value of the environment variable
15128@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
15129@end table
15130
8e04817f 15131History expansion assigns special meaning to the character @kbd{!}.
703663ab 15132@xref{Event Designators}, for more details.
8e04817f 15133
703663ab 15134@cindex history expansion, turn on/off
8e04817f
AC
15135Since @kbd{!} is also the logical not operator in C, history expansion
15136is off by default. If you decide to enable history expansion with the
15137@code{set history expansion on} command, you may sometimes need to
15138follow @kbd{!} (when it is used as logical not, in an expression) with
15139a space or a tab to prevent it from being expanded. The readline
15140history facilities do not attempt substitution on the strings
15141@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
15142
15143The commands to control history expansion are:
104c1213
JM
15144
15145@table @code
8e04817f
AC
15146@item set history expansion on
15147@itemx set history expansion
703663ab 15148@kindex set history expansion
8e04817f 15149Enable history expansion. History expansion is off by default.
104c1213 15150
8e04817f
AC
15151@item set history expansion off
15152Disable history expansion.
104c1213 15153
8e04817f
AC
15154@c @group
15155@kindex show history
15156@item show history
15157@itemx show history filename
15158@itemx show history save
15159@itemx show history size
15160@itemx show history expansion
15161These commands display the state of the @value{GDBN} history parameters.
15162@code{show history} by itself displays all four states.
15163@c @end group
15164@end table
15165
15166@table @code
9c16f35a
EZ
15167@kindex show commands
15168@cindex show last commands
15169@cindex display command history
8e04817f
AC
15170@item show commands
15171Display the last ten commands in the command history.
104c1213 15172
8e04817f
AC
15173@item show commands @var{n}
15174Print ten commands centered on command number @var{n}.
15175
15176@item show commands +
15177Print ten commands just after the commands last printed.
104c1213
JM
15178@end table
15179
8e04817f
AC
15180@node Screen Size
15181@section Screen size
15182@cindex size of screen
15183@cindex pauses in output
104c1213 15184
8e04817f
AC
15185Certain commands to @value{GDBN} may produce large amounts of
15186information output to the screen. To help you read all of it,
15187@value{GDBN} pauses and asks you for input at the end of each page of
15188output. Type @key{RET} when you want to continue the output, or @kbd{q}
15189to discard the remaining output. Also, the screen width setting
15190determines when to wrap lines of output. Depending on what is being
15191printed, @value{GDBN} tries to break the line at a readable place,
15192rather than simply letting it overflow onto the following line.
15193
15194Normally @value{GDBN} knows the size of the screen from the terminal
15195driver software. For example, on Unix @value{GDBN} uses the termcap data base
15196together with the value of the @code{TERM} environment variable and the
15197@code{stty rows} and @code{stty cols} settings. If this is not correct,
15198you can override it with the @code{set height} and @code{set
15199width} commands:
15200
15201@table @code
15202@kindex set height
15203@kindex set width
15204@kindex show width
15205@kindex show height
15206@item set height @var{lpp}
15207@itemx show height
15208@itemx set width @var{cpl}
15209@itemx show width
15210These @code{set} commands specify a screen height of @var{lpp} lines and
15211a screen width of @var{cpl} characters. The associated @code{show}
15212commands display the current settings.
104c1213 15213
8e04817f
AC
15214If you specify a height of zero lines, @value{GDBN} does not pause during
15215output no matter how long the output is. This is useful if output is to a
15216file or to an editor buffer.
104c1213 15217
8e04817f
AC
15218Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
15219from wrapping its output.
9c16f35a
EZ
15220
15221@item set pagination on
15222@itemx set pagination off
15223@kindex set pagination
15224Turn the output pagination on or off; the default is on. Turning
15225pagination off is the alternative to @code{set height 0}.
15226
15227@item show pagination
15228@kindex show pagination
15229Show the current pagination mode.
104c1213
JM
15230@end table
15231
8e04817f
AC
15232@node Numbers
15233@section Numbers
15234@cindex number representation
15235@cindex entering numbers
104c1213 15236
8e04817f
AC
15237You can always enter numbers in octal, decimal, or hexadecimal in
15238@value{GDBN} by the usual conventions: octal numbers begin with
15239@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
15240begin with @samp{0x}. Numbers that neither begin with @samp{0} or
15241@samp{0x}, nor end with a @samp{.} are, by default, entered in base
1524210; likewise, the default display for numbers---when no particular
15243format is specified---is base 10. You can change the default base for
15244both input and output with the commands described below.
104c1213 15245
8e04817f
AC
15246@table @code
15247@kindex set input-radix
15248@item set input-radix @var{base}
15249Set the default base for numeric input. Supported choices
15250for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15251specified either unambiguously or using the current input radix; for
8e04817f 15252example, any of
104c1213 15253
8e04817f 15254@smallexample
9c16f35a
EZ
15255set input-radix 012
15256set input-radix 10.
15257set input-radix 0xa
8e04817f 15258@end smallexample
104c1213 15259
8e04817f 15260@noindent
9c16f35a 15261sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
15262leaves the input radix unchanged, no matter what it was, since
15263@samp{10}, being without any leading or trailing signs of its base, is
15264interpreted in the current radix. Thus, if the current radix is 16,
15265@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
15266change the radix.
104c1213 15267
8e04817f
AC
15268@kindex set output-radix
15269@item set output-radix @var{base}
15270Set the default base for numeric display. Supported choices
15271for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15272specified either unambiguously or using the current input radix.
104c1213 15273
8e04817f
AC
15274@kindex show input-radix
15275@item show input-radix
15276Display the current default base for numeric input.
104c1213 15277
8e04817f
AC
15278@kindex show output-radix
15279@item show output-radix
15280Display the current default base for numeric display.
9c16f35a
EZ
15281
15282@item set radix @r{[}@var{base}@r{]}
15283@itemx show radix
15284@kindex set radix
15285@kindex show radix
15286These commands set and show the default base for both input and output
15287of numbers. @code{set radix} sets the radix of input and output to
15288the same base; without an argument, it resets the radix back to its
15289default value of 10.
15290
8e04817f 15291@end table
104c1213 15292
1e698235
DJ
15293@node ABI
15294@section Configuring the current ABI
15295
15296@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
15297application automatically. However, sometimes you need to override its
15298conclusions. Use these commands to manage @value{GDBN}'s view of the
15299current ABI.
15300
98b45e30
DJ
15301@cindex OS ABI
15302@kindex set osabi
b4e9345d 15303@kindex show osabi
98b45e30
DJ
15304
15305One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 15306system targets, either via remote debugging or native emulation.
98b45e30
DJ
15307@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
15308but you can override its conclusion using the @code{set osabi} command.
15309One example where this is useful is in debugging of binaries which use
15310an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
15311not have the same identifying marks that the standard C library for your
15312platform provides.
15313
15314@table @code
15315@item show osabi
15316Show the OS ABI currently in use.
15317
15318@item set osabi
15319With no argument, show the list of registered available OS ABI's.
15320
15321@item set osabi @var{abi}
15322Set the current OS ABI to @var{abi}.
15323@end table
15324
1e698235 15325@cindex float promotion
1e698235
DJ
15326
15327Generally, the way that an argument of type @code{float} is passed to a
15328function depends on whether the function is prototyped. For a prototyped
15329(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
15330according to the architecture's convention for @code{float}. For unprototyped
15331(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
15332@code{double} and then passed.
15333
15334Unfortunately, some forms of debug information do not reliably indicate whether
15335a function is prototyped. If @value{GDBN} calls a function that is not marked
15336as prototyped, it consults @kbd{set coerce-float-to-double}.
15337
15338@table @code
a8f24a35 15339@kindex set coerce-float-to-double
1e698235
DJ
15340@item set coerce-float-to-double
15341@itemx set coerce-float-to-double on
15342Arguments of type @code{float} will be promoted to @code{double} when passed
15343to an unprototyped function. This is the default setting.
15344
15345@item set coerce-float-to-double off
15346Arguments of type @code{float} will be passed directly to unprototyped
15347functions.
9c16f35a
EZ
15348
15349@kindex show coerce-float-to-double
15350@item show coerce-float-to-double
15351Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
15352@end table
15353
f1212245
DJ
15354@kindex set cp-abi
15355@kindex show cp-abi
15356@value{GDBN} needs to know the ABI used for your program's C@t{++}
15357objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
15358used to build your application. @value{GDBN} only fully supports
15359programs with a single C@t{++} ABI; if your program contains code using
15360multiple C@t{++} ABI's or if @value{GDBN} can not identify your
15361program's ABI correctly, you can tell @value{GDBN} which ABI to use.
15362Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
15363before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
15364``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
15365use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
15366``auto''.
15367
15368@table @code
15369@item show cp-abi
15370Show the C@t{++} ABI currently in use.
15371
15372@item set cp-abi
15373With no argument, show the list of supported C@t{++} ABI's.
15374
15375@item set cp-abi @var{abi}
15376@itemx set cp-abi auto
15377Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
15378@end table
15379
8e04817f
AC
15380@node Messages/Warnings
15381@section Optional warnings and messages
104c1213 15382
9c16f35a
EZ
15383@cindex verbose operation
15384@cindex optional warnings
8e04817f
AC
15385By default, @value{GDBN} is silent about its inner workings. If you are
15386running on a slow machine, you may want to use the @code{set verbose}
15387command. This makes @value{GDBN} tell you when it does a lengthy
15388internal operation, so you will not think it has crashed.
104c1213 15389
8e04817f
AC
15390Currently, the messages controlled by @code{set verbose} are those
15391which announce that the symbol table for a source file is being read;
15392see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 15393
8e04817f
AC
15394@table @code
15395@kindex set verbose
15396@item set verbose on
15397Enables @value{GDBN} output of certain informational messages.
104c1213 15398
8e04817f
AC
15399@item set verbose off
15400Disables @value{GDBN} output of certain informational messages.
104c1213 15401
8e04817f
AC
15402@kindex show verbose
15403@item show verbose
15404Displays whether @code{set verbose} is on or off.
15405@end table
104c1213 15406
8e04817f
AC
15407By default, if @value{GDBN} encounters bugs in the symbol table of an
15408object file, it is silent; but if you are debugging a compiler, you may
15409find this information useful (@pxref{Symbol Errors, ,Errors reading
15410symbol files}).
104c1213 15411
8e04817f 15412@table @code
104c1213 15413
8e04817f
AC
15414@kindex set complaints
15415@item set complaints @var{limit}
15416Permits @value{GDBN} to output @var{limit} complaints about each type of
15417unusual symbols before becoming silent about the problem. Set
15418@var{limit} to zero to suppress all complaints; set it to a large number
15419to prevent complaints from being suppressed.
104c1213 15420
8e04817f
AC
15421@kindex show complaints
15422@item show complaints
15423Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 15424
8e04817f 15425@end table
104c1213 15426
8e04817f
AC
15427By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
15428lot of stupid questions to confirm certain commands. For example, if
15429you try to run a program which is already running:
104c1213 15430
474c8240 15431@smallexample
8e04817f
AC
15432(@value{GDBP}) run
15433The program being debugged has been started already.
15434Start it from the beginning? (y or n)
474c8240 15435@end smallexample
104c1213 15436
8e04817f
AC
15437If you are willing to unflinchingly face the consequences of your own
15438commands, you can disable this ``feature'':
104c1213 15439
8e04817f 15440@table @code
104c1213 15441
8e04817f
AC
15442@kindex set confirm
15443@cindex flinching
15444@cindex confirmation
15445@cindex stupid questions
15446@item set confirm off
15447Disables confirmation requests.
104c1213 15448
8e04817f
AC
15449@item set confirm on
15450Enables confirmation requests (the default).
104c1213 15451
8e04817f
AC
15452@kindex show confirm
15453@item show confirm
15454Displays state of confirmation requests.
15455
15456@end table
104c1213 15457
8e04817f
AC
15458@node Debugging Output
15459@section Optional messages about internal happenings
4644b6e3
EZ
15460@cindex optional debugging messages
15461
da316a69
EZ
15462@value{GDBN} has commands that enable optional debugging messages from
15463various @value{GDBN} subsystems; normally these commands are of
15464interest to @value{GDBN} maintainers, or when reporting a bug. This
15465section documents those commands.
15466
104c1213 15467@table @code
a8f24a35
EZ
15468@kindex set exec-done-display
15469@item set exec-done-display
15470Turns on or off the notification of asynchronous commands'
15471completion. When on, @value{GDBN} will print a message when an
15472asynchronous command finishes its execution. The default is off.
15473@kindex show exec-done-display
15474@item show exec-done-display
15475Displays the current setting of asynchronous command completion
15476notification.
4644b6e3
EZ
15477@kindex set debug
15478@cindex gdbarch debugging info
a8f24a35 15479@cindex architecture debugging info
8e04817f 15480@item set debug arch
a8f24a35 15481Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 15482@kindex show debug
8e04817f
AC
15483@item show debug arch
15484Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
15485@item set debug aix-thread
15486@cindex AIX threads
15487Display debugging messages about inner workings of the AIX thread
15488module.
15489@item show debug aix-thread
15490Show the current state of AIX thread debugging info display.
8e04817f 15491@item set debug event
4644b6e3 15492@cindex event debugging info
a8f24a35 15493Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 15494default is off.
8e04817f
AC
15495@item show debug event
15496Displays the current state of displaying @value{GDBN} event debugging
15497info.
8e04817f 15498@item set debug expression
4644b6e3 15499@cindex expression debugging info
721c2651
EZ
15500Turns on or off display of debugging info about @value{GDBN}
15501expression parsing. The default is off.
8e04817f 15502@item show debug expression
721c2651
EZ
15503Displays the current state of displaying debugging info about
15504@value{GDBN} expression parsing.
7453dc06 15505@item set debug frame
4644b6e3 15506@cindex frame debugging info
7453dc06
AC
15507Turns on or off display of @value{GDBN} frame debugging info. The
15508default is off.
7453dc06
AC
15509@item show debug frame
15510Displays the current state of displaying @value{GDBN} frame debugging
15511info.
30e91e0b
RC
15512@item set debug infrun
15513@cindex inferior debugging info
15514Turns on or off display of @value{GDBN} debugging info for running the inferior.
15515The default is off. @file{infrun.c} contains GDB's runtime state machine used
15516for implementing operations such as single-stepping the inferior.
15517@item show debug infrun
15518Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
15519@item set debug lin-lwp
15520@cindex @sc{gnu}/Linux LWP debug messages
15521@cindex Linux lightweight processes
721c2651 15522Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
15523@item show debug lin-lwp
15524Show the current state of Linux LWP debugging messages.
2b4855ab 15525@item set debug observer
4644b6e3 15526@cindex observer debugging info
2b4855ab
AC
15527Turns on or off display of @value{GDBN} observer debugging. This
15528includes info such as the notification of observable events.
2b4855ab
AC
15529@item show debug observer
15530Displays the current state of observer debugging.
8e04817f 15531@item set debug overload
4644b6e3 15532@cindex C@t{++} overload debugging info
8e04817f
AC
15533Turns on or off display of @value{GDBN} C@t{++} overload debugging
15534info. This includes info such as ranking of functions, etc. The default
15535is off.
8e04817f
AC
15536@item show debug overload
15537Displays the current state of displaying @value{GDBN} C@t{++} overload
15538debugging info.
8e04817f
AC
15539@cindex packets, reporting on stdout
15540@cindex serial connections, debugging
15541@item set debug remote
15542Turns on or off display of reports on all packets sent back and forth across
15543the serial line to the remote machine. The info is printed on the
15544@value{GDBN} standard output stream. The default is off.
8e04817f
AC
15545@item show debug remote
15546Displays the state of display of remote packets.
8e04817f
AC
15547@item set debug serial
15548Turns on or off display of @value{GDBN} serial debugging info. The
15549default is off.
8e04817f
AC
15550@item show debug serial
15551Displays the current state of displaying @value{GDBN} serial debugging
15552info.
c45da7e6
EZ
15553@item set debug solib-frv
15554@cindex FR-V shared-library debugging
15555Turns on or off debugging messages for FR-V shared-library code.
15556@item show debug solib-frv
15557Display the current state of FR-V shared-library code debugging
15558messages.
8e04817f 15559@item set debug target
4644b6e3 15560@cindex target debugging info
8e04817f
AC
15561Turns on or off display of @value{GDBN} target debugging info. This info
15562includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
15563default is 0. Set it to 1 to track events, and to 2 to also track the
15564value of large memory transfers. Changes to this flag do not take effect
15565until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
15566@item show debug target
15567Displays the current state of displaying @value{GDBN} target debugging
15568info.
c45da7e6 15569@item set debugvarobj
4644b6e3 15570@cindex variable object debugging info
8e04817f
AC
15571Turns on or off display of @value{GDBN} variable object debugging
15572info. The default is off.
c45da7e6 15573@item show debugvarobj
8e04817f
AC
15574Displays the current state of displaying @value{GDBN} variable object
15575debugging info.
15576@end table
104c1213 15577
8e04817f
AC
15578@node Sequences
15579@chapter Canned Sequences of Commands
104c1213 15580
8e04817f
AC
15581Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
15582command lists}), @value{GDBN} provides two ways to store sequences of
15583commands for execution as a unit: user-defined commands and command
15584files.
104c1213 15585
8e04817f
AC
15586@menu
15587* Define:: User-defined commands
15588* Hooks:: User-defined command hooks
15589* Command Files:: Command files
15590* Output:: Commands for controlled output
15591@end menu
104c1213 15592
8e04817f
AC
15593@node Define
15594@section User-defined commands
104c1213 15595
8e04817f
AC
15596@cindex user-defined command
15597A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
15598which you assign a new name as a command. This is done with the
15599@code{define} command. User commands may accept up to 10 arguments
15600separated by whitespace. Arguments are accessed within the user command
15601via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 15602
8e04817f
AC
15603@smallexample
15604define adder
15605 print $arg0 + $arg1 + $arg2
15606@end smallexample
104c1213
JM
15607
15608@noindent
8e04817f 15609To execute the command use:
104c1213 15610
8e04817f
AC
15611@smallexample
15612adder 1 2 3
15613@end smallexample
104c1213 15614
8e04817f
AC
15615@noindent
15616This defines the command @code{adder}, which prints the sum of
15617its three arguments. Note the arguments are text substitutions, so they may
15618reference variables, use complex expressions, or even perform inferior
15619functions calls.
104c1213
JM
15620
15621@table @code
104c1213 15622
8e04817f
AC
15623@kindex define
15624@item define @var{commandname}
15625Define a command named @var{commandname}. If there is already a command
15626by that name, you are asked to confirm that you want to redefine it.
104c1213 15627
8e04817f
AC
15628The definition of the command is made up of other @value{GDBN} command lines,
15629which are given following the @code{define} command. The end of these
15630commands is marked by a line containing @code{end}.
104c1213 15631
8e04817f
AC
15632@kindex if
15633@kindex else
15634@item if
09d4efe1 15635@itemx else
8e04817f
AC
15636Takes a single argument, which is an expression to evaluate.
15637It is followed by a series of commands that are executed
15638only if the expression is true (nonzero).
15639There can then optionally be a line @code{else}, followed
15640by a series of commands that are only executed if the expression
15641was false. The end of the list is marked by a line containing @code{end}.
104c1213 15642
8e04817f
AC
15643@kindex while
15644@item while
15645The syntax is similar to @code{if}: the command takes a single argument,
15646which is an expression to evaluate, and must be followed by the commands to
15647execute, one per line, terminated by an @code{end}.
15648The commands are executed repeatedly as long as the expression
15649evaluates to true.
104c1213 15650
8e04817f
AC
15651@kindex document
15652@item document @var{commandname}
15653Document the user-defined command @var{commandname}, so that it can be
15654accessed by @code{help}. The command @var{commandname} must already be
15655defined. This command reads lines of documentation just as @code{define}
15656reads the lines of the command definition, ending with @code{end}.
15657After the @code{document} command is finished, @code{help} on command
15658@var{commandname} displays the documentation you have written.
104c1213 15659
8e04817f
AC
15660You may use the @code{document} command again to change the
15661documentation of a command. Redefining the command with @code{define}
15662does not change the documentation.
104c1213 15663
c45da7e6
EZ
15664@kindex dont-repeat
15665@cindex don't repeat command
15666@item dont-repeat
15667Used inside a user-defined command, this tells @value{GDBN} that this
15668command should not be repeated when the user hits @key{RET}
15669(@pxref{Command Syntax, repeat last command}).
15670
8e04817f
AC
15671@kindex help user-defined
15672@item help user-defined
15673List all user-defined commands, with the first line of the documentation
15674(if any) for each.
104c1213 15675
8e04817f
AC
15676@kindex show user
15677@item show user
15678@itemx show user @var{commandname}
15679Display the @value{GDBN} commands used to define @var{commandname} (but
15680not its documentation). If no @var{commandname} is given, display the
15681definitions for all user-defined commands.
104c1213 15682
9c16f35a 15683@cindex infinite recusrion in user-defined commands
20f01a46
DH
15684@kindex show max-user-call-depth
15685@kindex set max-user-call-depth
15686@item show max-user-call-depth
5ca0cb28
DH
15687@itemx set max-user-call-depth
15688The value of @code{max-user-call-depth} controls how many recursion
15689levels are allowed in user-defined commands before GDB suspects an
15690infinite recursion and aborts the command.
20f01a46 15691
104c1213
JM
15692@end table
15693
8e04817f
AC
15694When user-defined commands are executed, the
15695commands of the definition are not printed. An error in any command
15696stops execution of the user-defined command.
104c1213 15697
8e04817f
AC
15698If used interactively, commands that would ask for confirmation proceed
15699without asking when used inside a user-defined command. Many @value{GDBN}
15700commands that normally print messages to say what they are doing omit the
15701messages when used in a user-defined command.
104c1213 15702
8e04817f
AC
15703@node Hooks
15704@section User-defined command hooks
15705@cindex command hooks
15706@cindex hooks, for commands
15707@cindex hooks, pre-command
104c1213 15708
8e04817f 15709@kindex hook
8e04817f
AC
15710You may define @dfn{hooks}, which are a special kind of user-defined
15711command. Whenever you run the command @samp{foo}, if the user-defined
15712command @samp{hook-foo} exists, it is executed (with no arguments)
15713before that command.
104c1213 15714
8e04817f
AC
15715@cindex hooks, post-command
15716@kindex hookpost
8e04817f
AC
15717A hook may also be defined which is run after the command you executed.
15718Whenever you run the command @samp{foo}, if the user-defined command
15719@samp{hookpost-foo} exists, it is executed (with no arguments) after
15720that command. Post-execution hooks may exist simultaneously with
15721pre-execution hooks, for the same command.
104c1213 15722
8e04817f 15723It is valid for a hook to call the command which it hooks. If this
9f1c6395 15724occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 15725
8e04817f
AC
15726@c It would be nice if hookpost could be passed a parameter indicating
15727@c if the command it hooks executed properly or not. FIXME!
104c1213 15728
8e04817f
AC
15729@kindex stop@r{, a pseudo-command}
15730In addition, a pseudo-command, @samp{stop} exists. Defining
15731(@samp{hook-stop}) makes the associated commands execute every time
15732execution stops in your program: before breakpoint commands are run,
15733displays are printed, or the stack frame is printed.
104c1213 15734
8e04817f
AC
15735For example, to ignore @code{SIGALRM} signals while
15736single-stepping, but treat them normally during normal execution,
15737you could define:
104c1213 15738
474c8240 15739@smallexample
8e04817f
AC
15740define hook-stop
15741handle SIGALRM nopass
15742end
104c1213 15743
8e04817f
AC
15744define hook-run
15745handle SIGALRM pass
15746end
104c1213 15747
8e04817f
AC
15748define hook-continue
15749handle SIGLARM pass
15750end
474c8240 15751@end smallexample
104c1213 15752
8e04817f 15753As a further example, to hook at the begining and end of the @code{echo}
b383017d 15754command, and to add extra text to the beginning and end of the message,
8e04817f 15755you could define:
104c1213 15756
474c8240 15757@smallexample
8e04817f
AC
15758define hook-echo
15759echo <<<---
15760end
104c1213 15761
8e04817f
AC
15762define hookpost-echo
15763echo --->>>\n
15764end
104c1213 15765
8e04817f
AC
15766(@value{GDBP}) echo Hello World
15767<<<---Hello World--->>>
15768(@value{GDBP})
104c1213 15769
474c8240 15770@end smallexample
104c1213 15771
8e04817f
AC
15772You can define a hook for any single-word command in @value{GDBN}, but
15773not for command aliases; you should define a hook for the basic command
15774name, e.g. @code{backtrace} rather than @code{bt}.
15775@c FIXME! So how does Joe User discover whether a command is an alias
15776@c or not?
15777If an error occurs during the execution of your hook, execution of
15778@value{GDBN} commands stops and @value{GDBN} issues a prompt
15779(before the command that you actually typed had a chance to run).
104c1213 15780
8e04817f
AC
15781If you try to define a hook which does not match any known command, you
15782get a warning from the @code{define} command.
c906108c 15783
8e04817f
AC
15784@node Command Files
15785@section Command files
c906108c 15786
8e04817f 15787@cindex command files
6fc08d32
EZ
15788A command file for @value{GDBN} is a text file made of lines that are
15789@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
15790also be included. An empty line in a command file does nothing; it
15791does not mean to repeat the last command, as it would from the
15792terminal.
c906108c 15793
6fc08d32
EZ
15794You can request the execution of a command file with the @code{source}
15795command:
c906108c 15796
8e04817f
AC
15797@table @code
15798@kindex source
15799@item source @var{filename}
15800Execute the command file @var{filename}.
c906108c
SS
15801@end table
15802
8e04817f 15803The lines in a command file are executed sequentially. They are not
a71ec265
DH
15804printed as they are executed. An error in any command terminates
15805execution of the command file and control is returned to the console.
c906108c 15806
8e04817f
AC
15807Commands that would ask for confirmation if used interactively proceed
15808without asking when used in a command file. Many @value{GDBN} commands that
15809normally print messages to say what they are doing omit the messages
15810when called from command files.
c906108c 15811
8e04817f
AC
15812@value{GDBN} also accepts command input from standard input. In this
15813mode, normal output goes to standard output and error output goes to
15814standard error. Errors in a command file supplied on standard input do
6fc08d32 15815not terminate execution of the command file---execution continues with
8e04817f 15816the next command.
c906108c 15817
474c8240 15818@smallexample
8e04817f 15819gdb < cmds > log 2>&1
474c8240 15820@end smallexample
c906108c 15821
8e04817f
AC
15822(The syntax above will vary depending on the shell used.) This example
15823will execute commands from the file @file{cmds}. All output and errors
15824would be directed to @file{log}.
c906108c 15825
8e04817f
AC
15826@node Output
15827@section Commands for controlled output
c906108c 15828
8e04817f
AC
15829During the execution of a command file or a user-defined command, normal
15830@value{GDBN} output is suppressed; the only output that appears is what is
15831explicitly printed by the commands in the definition. This section
15832describes three commands useful for generating exactly the output you
15833want.
c906108c
SS
15834
15835@table @code
8e04817f
AC
15836@kindex echo
15837@item echo @var{text}
15838@c I do not consider backslash-space a standard C escape sequence
15839@c because it is not in ANSI.
15840Print @var{text}. Nonprinting characters can be included in
15841@var{text} using C escape sequences, such as @samp{\n} to print a
15842newline. @strong{No newline is printed unless you specify one.}
15843In addition to the standard C escape sequences, a backslash followed
15844by a space stands for a space. This is useful for displaying a
15845string with spaces at the beginning or the end, since leading and
15846trailing spaces are otherwise trimmed from all arguments.
15847To print @samp{@w{ }and foo =@w{ }}, use the command
15848@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 15849
8e04817f
AC
15850A backslash at the end of @var{text} can be used, as in C, to continue
15851the command onto subsequent lines. For example,
c906108c 15852
474c8240 15853@smallexample
8e04817f
AC
15854echo This is some text\n\
15855which is continued\n\
15856onto several lines.\n
474c8240 15857@end smallexample
c906108c 15858
8e04817f 15859produces the same output as
c906108c 15860
474c8240 15861@smallexample
8e04817f
AC
15862echo This is some text\n
15863echo which is continued\n
15864echo onto several lines.\n
474c8240 15865@end smallexample
c906108c 15866
8e04817f
AC
15867@kindex output
15868@item output @var{expression}
15869Print the value of @var{expression} and nothing but that value: no
15870newlines, no @samp{$@var{nn} = }. The value is not entered in the
15871value history either. @xref{Expressions, ,Expressions}, for more information
15872on expressions.
c906108c 15873
8e04817f
AC
15874@item output/@var{fmt} @var{expression}
15875Print the value of @var{expression} in format @var{fmt}. You can use
15876the same formats as for @code{print}. @xref{Output Formats,,Output
15877formats}, for more information.
c906108c 15878
8e04817f
AC
15879@kindex printf
15880@item printf @var{string}, @var{expressions}@dots{}
15881Print the values of the @var{expressions} under the control of
15882@var{string}. The @var{expressions} are separated by commas and may be
15883either numbers or pointers. Their values are printed as specified by
15884@var{string}, exactly as if your program were to execute the C
15885subroutine
15886@c FIXME: the above implies that at least all ANSI C formats are
15887@c supported, but it isn't true: %E and %G don't work (or so it seems).
15888@c Either this is a bug, or the manual should document what formats are
15889@c supported.
c906108c 15890
474c8240 15891@smallexample
8e04817f 15892printf (@var{string}, @var{expressions}@dots{});
474c8240 15893@end smallexample
c906108c 15894
8e04817f 15895For example, you can print two values in hex like this:
c906108c 15896
8e04817f
AC
15897@smallexample
15898printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
15899@end smallexample
c906108c 15900
8e04817f
AC
15901The only backslash-escape sequences that you can use in the format
15902string are the simple ones that consist of backslash followed by a
15903letter.
c906108c
SS
15904@end table
15905
21c294e6
AC
15906@node Interpreters
15907@chapter Command Interpreters
15908@cindex command interpreters
15909
15910@value{GDBN} supports multiple command interpreters, and some command
15911infrastructure to allow users or user interface writers to switch
15912between interpreters or run commands in other interpreters.
15913
15914@value{GDBN} currently supports two command interpreters, the console
15915interpreter (sometimes called the command-line interpreter or @sc{cli})
15916and the machine interface interpreter (or @sc{gdb/mi}). This manual
15917describes both of these interfaces in great detail.
15918
15919By default, @value{GDBN} will start with the console interpreter.
15920However, the user may choose to start @value{GDBN} with another
15921interpreter by specifying the @option{-i} or @option{--interpreter}
15922startup options. Defined interpreters include:
15923
15924@table @code
15925@item console
15926@cindex console interpreter
15927The traditional console or command-line interpreter. This is the most often
15928used interpreter with @value{GDBN}. With no interpreter specified at runtime,
15929@value{GDBN} will use this interpreter.
15930
15931@item mi
15932@cindex mi interpreter
15933The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
15934by programs wishing to use @value{GDBN} as a backend for a debugger GUI
15935or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
15936Interface}.
15937
15938@item mi2
15939@cindex mi2 interpreter
15940The current @sc{gdb/mi} interface.
15941
15942@item mi1
15943@cindex mi1 interpreter
15944The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
15945
15946@end table
15947
15948@cindex invoke another interpreter
15949The interpreter being used by @value{GDBN} may not be dynamically
15950switched at runtime. Although possible, this could lead to a very
15951precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
15952enters the command "interpreter-set console" in a console view,
15953@value{GDBN} would switch to using the console interpreter, rendering
15954the IDE inoperable!
15955
15956@kindex interpreter-exec
15957Although you may only choose a single interpreter at startup, you may execute
15958commands in any interpreter from the current interpreter using the appropriate
15959command. If you are running the console interpreter, simply use the
15960@code{interpreter-exec} command:
15961
15962@smallexample
15963interpreter-exec mi "-data-list-register-names"
15964@end smallexample
15965
15966@sc{gdb/mi} has a similar command, although it is only available in versions of
15967@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
15968
8e04817f
AC
15969@node TUI
15970@chapter @value{GDBN} Text User Interface
15971@cindex TUI
d0d5df6f 15972@cindex Text User Interface
c906108c 15973
8e04817f
AC
15974@menu
15975* TUI Overview:: TUI overview
15976* TUI Keys:: TUI key bindings
7cf36c78 15977* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
15978* TUI Commands:: TUI specific commands
15979* TUI Configuration:: TUI configuration variables
15980@end menu
c906108c 15981
d0d5df6f
AC
15982The @value{GDBN} Text User Interface, TUI in short, is a terminal
15983interface which uses the @code{curses} library to show the source
15984file, the assembly output, the program registers and @value{GDBN}
15985commands in separate text windows.
15986
15987The TUI is enabled by invoking @value{GDBN} using either
15988@pindex gdbtui
15989@samp{gdbtui} or @samp{gdb -tui}.
c906108c 15990
8e04817f
AC
15991@node TUI Overview
15992@section TUI overview
c906108c 15993
8e04817f
AC
15994The TUI has two display modes that can be switched while
15995@value{GDBN} runs:
c906108c 15996
8e04817f
AC
15997@itemize @bullet
15998@item
15999A curses (or TUI) mode in which it displays several text
16000windows on the terminal.
c906108c 16001
8e04817f
AC
16002@item
16003A standard mode which corresponds to the @value{GDBN} configured without
16004the TUI.
16005@end itemize
c906108c 16006
8e04817f
AC
16007In the TUI mode, @value{GDBN} can display several text window
16008on the terminal:
c906108c 16009
8e04817f
AC
16010@table @emph
16011@item command
16012This window is the @value{GDBN} command window with the @value{GDBN}
16013prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
16014managed using readline but through the TUI. The @emph{command}
16015window is always visible.
c906108c 16016
8e04817f
AC
16017@item source
16018The source window shows the source file of the program. The current
16019line as well as active breakpoints are displayed in this window.
c906108c 16020
8e04817f
AC
16021@item assembly
16022The assembly window shows the disassembly output of the program.
c906108c 16023
8e04817f
AC
16024@item register
16025This window shows the processor registers. It detects when
16026a register is changed and when this is the case, registers that have
6a1b180d 16027changed are highlighted.
c906108c 16028
c906108c
SS
16029@end table
16030
269c21fe
SC
16031The source and assembly windows show the current program position
16032by highlighting the current line and marking them with the @samp{>} marker.
16033Breakpoints are also indicated with two markers. A first one
16034indicates the breakpoint type:
16035
16036@table @code
16037@item B
16038Breakpoint which was hit at least once.
16039
16040@item b
16041Breakpoint which was never hit.
16042
16043@item H
16044Hardware breakpoint which was hit at least once.
16045
16046@item h
16047Hardware breakpoint which was never hit.
16048
16049@end table
16050
16051The second marker indicates whether the breakpoint is enabled or not:
16052
16053@table @code
16054@item +
16055Breakpoint is enabled.
16056
16057@item -
16058Breakpoint is disabled.
16059
16060@end table
16061
8e04817f
AC
16062The source, assembly and register windows are attached to the thread
16063and the frame position. They are updated when the current thread
16064changes, when the frame changes or when the program counter changes.
16065These three windows are arranged by the TUI according to several
16066layouts. The layout defines which of these three windows are visible.
16067The following layouts are available:
c906108c 16068
8e04817f
AC
16069@itemize @bullet
16070@item
16071source
2df3850c 16072
8e04817f
AC
16073@item
16074assembly
16075
16076@item
16077source and assembly
16078
16079@item
16080source and registers
c906108c 16081
8e04817f
AC
16082@item
16083assembly and registers
2df3850c 16084
8e04817f 16085@end itemize
c906108c 16086
b7bb15bc
SC
16087On top of the command window a status line gives various information
16088concerning the current process begin debugged. The status line is
16089updated when the information it shows changes. The following fields
16090are displayed:
16091
16092@table @emph
16093@item target
16094Indicates the current gdb target
16095(@pxref{Targets, ,Specifying a Debugging Target}).
16096
16097@item process
16098Gives information about the current process or thread number.
16099When no process is being debugged, this field is set to @code{No process}.
16100
16101@item function
16102Gives the current function name for the selected frame.
16103The name is demangled if demangling is turned on (@pxref{Print Settings}).
16104When there is no symbol corresponding to the current program counter
16105the string @code{??} is displayed.
16106
16107@item line
16108Indicates the current line number for the selected frame.
16109When the current line number is not known the string @code{??} is displayed.
16110
16111@item pc
16112Indicates the current program counter address.
16113
16114@end table
16115
8e04817f
AC
16116@node TUI Keys
16117@section TUI Key Bindings
16118@cindex TUI key bindings
c906108c 16119
8e04817f
AC
16120The TUI installs several key bindings in the readline keymaps
16121(@pxref{Command Line Editing}).
16122They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
16123directly on the TUI layout and windows. The TUI also provides
16124a @emph{SingleKey} keymap which binds several keys directly to
16125@value{GDBN} commands. The following key bindings
8e04817f 16126are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 16127
8e04817f
AC
16128@table @kbd
16129@kindex C-x C-a
16130@item C-x C-a
16131@kindex C-x a
16132@itemx C-x a
16133@kindex C-x A
16134@itemx C-x A
16135Enter or leave the TUI mode. When the TUI mode is left,
16136the curses window management is left and @value{GDBN} operates using
16137its standard mode writing on the terminal directly. When the TUI
16138mode is entered, the control is given back to the curses windows.
16139The screen is then refreshed.
c906108c 16140
8e04817f
AC
16141@kindex C-x 1
16142@item C-x 1
16143Use a TUI layout with only one window. The layout will
16144either be @samp{source} or @samp{assembly}. When the TUI mode
16145is not active, it will switch to the TUI mode.
2df3850c 16146
8e04817f 16147Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 16148
8e04817f
AC
16149@kindex C-x 2
16150@item C-x 2
16151Use a TUI layout with at least two windows. When the current
16152layout shows already two windows, a next layout with two windows is used.
16153When a new layout is chosen, one window will always be common to the
16154previous layout and the new one.
c906108c 16155
8e04817f 16156Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 16157
72ffddc9
SC
16158@kindex C-x o
16159@item C-x o
16160Change the active window. The TUI associates several key bindings
16161(like scrolling and arrow keys) to the active window. This command
16162gives the focus to the next TUI window.
16163
16164Think of it as the Emacs @kbd{C-x o} binding.
16165
7cf36c78
SC
16166@kindex C-x s
16167@item C-x s
16168Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
16169(@pxref{TUI Single Key Mode}).
16170
c906108c
SS
16171@end table
16172
8e04817f 16173The following key bindings are handled only by the TUI mode:
5d161b24 16174
8e04817f
AC
16175@table @key
16176@kindex PgUp
16177@item PgUp
16178Scroll the active window one page up.
c906108c 16179
8e04817f
AC
16180@kindex PgDn
16181@item PgDn
16182Scroll the active window one page down.
c906108c 16183
8e04817f
AC
16184@kindex Up
16185@item Up
16186Scroll the active window one line up.
c906108c 16187
8e04817f
AC
16188@kindex Down
16189@item Down
16190Scroll the active window one line down.
c906108c 16191
8e04817f
AC
16192@kindex Left
16193@item Left
16194Scroll the active window one column left.
c906108c 16195
8e04817f
AC
16196@kindex Right
16197@item Right
16198Scroll the active window one column right.
c906108c 16199
8e04817f
AC
16200@kindex C-L
16201@item C-L
16202Refresh the screen.
c906108c 16203
8e04817f 16204@end table
c906108c 16205
8e04817f 16206In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
16207for scrolling. This means they are available for readline when the
16208active window is the command window. When the command window
16209does not have the focus, it is necessary to use other readline
16210key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 16211
7cf36c78
SC
16212@node TUI Single Key Mode
16213@section TUI Single Key Mode
16214@cindex TUI single key mode
16215
16216The TUI provides a @emph{SingleKey} mode in which it installs a particular
16217key binding in the readline keymaps to connect single keys to
b383017d 16218some gdb commands.
7cf36c78
SC
16219
16220@table @kbd
16221@kindex c @r{(SingleKey TUI key)}
16222@item c
16223continue
16224
16225@kindex d @r{(SingleKey TUI key)}
16226@item d
16227down
16228
16229@kindex f @r{(SingleKey TUI key)}
16230@item f
16231finish
16232
16233@kindex n @r{(SingleKey TUI key)}
16234@item n
16235next
16236
16237@kindex q @r{(SingleKey TUI key)}
16238@item q
16239exit the @emph{SingleKey} mode.
16240
16241@kindex r @r{(SingleKey TUI key)}
16242@item r
16243run
16244
16245@kindex s @r{(SingleKey TUI key)}
16246@item s
16247step
16248
16249@kindex u @r{(SingleKey TUI key)}
16250@item u
16251up
16252
16253@kindex v @r{(SingleKey TUI key)}
16254@item v
16255info locals
16256
16257@kindex w @r{(SingleKey TUI key)}
16258@item w
16259where
16260
16261@end table
16262
16263Other keys temporarily switch to the @value{GDBN} command prompt.
16264The key that was pressed is inserted in the editing buffer so that
16265it is possible to type most @value{GDBN} commands without interaction
16266with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
16267@emph{SingleKey} mode is restored. The only way to permanently leave
16268this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
16269
16270
8e04817f
AC
16271@node TUI Commands
16272@section TUI specific commands
16273@cindex TUI commands
16274
16275The TUI has specific commands to control the text windows.
16276These commands are always available, that is they do not depend on
16277the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
16278is in the standard mode, using these commands will automatically switch
16279in the TUI mode.
c906108c
SS
16280
16281@table @code
3d757584
SC
16282@item info win
16283@kindex info win
16284List and give the size of all displayed windows.
16285
8e04817f 16286@item layout next
4644b6e3 16287@kindex layout
8e04817f 16288Display the next layout.
2df3850c 16289
8e04817f 16290@item layout prev
8e04817f 16291Display the previous layout.
c906108c 16292
8e04817f 16293@item layout src
8e04817f 16294Display the source window only.
c906108c 16295
8e04817f 16296@item layout asm
8e04817f 16297Display the assembly window only.
c906108c 16298
8e04817f 16299@item layout split
8e04817f 16300Display the source and assembly window.
c906108c 16301
8e04817f 16302@item layout regs
8e04817f
AC
16303Display the register window together with the source or assembly window.
16304
16305@item focus next | prev | src | asm | regs | split
16306@kindex focus
16307Set the focus to the named window.
16308This command allows to change the active window so that scrolling keys
16309can be affected to another window.
c906108c 16310
8e04817f
AC
16311@item refresh
16312@kindex refresh
16313Refresh the screen. This is similar to using @key{C-L} key.
c906108c 16314
6a1b180d
SC
16315@item tui reg float
16316@kindex tui reg
16317Show the floating point registers in the register window.
16318
16319@item tui reg general
16320Show the general registers in the register window.
16321
16322@item tui reg next
16323Show the next register group. The list of register groups as well as
16324their order is target specific. The predefined register groups are the
16325following: @code{general}, @code{float}, @code{system}, @code{vector},
16326@code{all}, @code{save}, @code{restore}.
16327
16328@item tui reg system
16329Show the system registers in the register window.
16330
8e04817f
AC
16331@item update
16332@kindex update
16333Update the source window and the current execution point.
c906108c 16334
8e04817f
AC
16335@item winheight @var{name} +@var{count}
16336@itemx winheight @var{name} -@var{count}
16337@kindex winheight
16338Change the height of the window @var{name} by @var{count}
16339lines. Positive counts increase the height, while negative counts
16340decrease it.
2df3850c 16341
c45da7e6
EZ
16342@item tabset
16343@kindex tabset @var{nchars}
16344Set the width of tab stops to be @var{nchars} characters.
16345
c906108c
SS
16346@end table
16347
8e04817f
AC
16348@node TUI Configuration
16349@section TUI configuration variables
16350@cindex TUI configuration variables
c906108c 16351
8e04817f
AC
16352The TUI has several configuration variables that control the
16353appearance of windows on the terminal.
c906108c 16354
8e04817f
AC
16355@table @code
16356@item set tui border-kind @var{kind}
16357@kindex set tui border-kind
16358Select the border appearance for the source, assembly and register windows.
16359The possible values are the following:
16360@table @code
16361@item space
16362Use a space character to draw the border.
c906108c 16363
8e04817f
AC
16364@item ascii
16365Use ascii characters + - and | to draw the border.
c906108c 16366
8e04817f
AC
16367@item acs
16368Use the Alternate Character Set to draw the border. The border is
16369drawn using character line graphics if the terminal supports them.
c78b4128 16370
8e04817f 16371@end table
c78b4128 16372
8e04817f
AC
16373@item set tui active-border-mode @var{mode}
16374@kindex set tui active-border-mode
16375Select the attributes to display the border of the active window.
16376The possible values are @code{normal}, @code{standout}, @code{reverse},
16377@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 16378
8e04817f
AC
16379@item set tui border-mode @var{mode}
16380@kindex set tui border-mode
16381Select the attributes to display the border of other windows.
16382The @var{mode} can be one of the following:
16383@table @code
16384@item normal
16385Use normal attributes to display the border.
c906108c 16386
8e04817f
AC
16387@item standout
16388Use standout mode.
c906108c 16389
8e04817f
AC
16390@item reverse
16391Use reverse video mode.
c906108c 16392
8e04817f
AC
16393@item half
16394Use half bright mode.
c906108c 16395
8e04817f
AC
16396@item half-standout
16397Use half bright and standout mode.
c906108c 16398
8e04817f
AC
16399@item bold
16400Use extra bright or bold mode.
c78b4128 16401
8e04817f
AC
16402@item bold-standout
16403Use extra bright or bold and standout mode.
c78b4128 16404
8e04817f 16405@end table
c78b4128 16406
8e04817f 16407@end table
c78b4128 16408
8e04817f
AC
16409@node Emacs
16410@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 16411
8e04817f
AC
16412@cindex Emacs
16413@cindex @sc{gnu} Emacs
16414A special interface allows you to use @sc{gnu} Emacs to view (and
16415edit) the source files for the program you are debugging with
16416@value{GDBN}.
c906108c 16417
8e04817f
AC
16418To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
16419executable file you want to debug as an argument. This command starts
16420@value{GDBN} as a subprocess of Emacs, with input and output through a newly
16421created Emacs buffer.
16422@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 16423
8e04817f
AC
16424Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
16425things:
c906108c 16426
8e04817f
AC
16427@itemize @bullet
16428@item
16429All ``terminal'' input and output goes through the Emacs buffer.
16430@end itemize
c906108c 16431
8e04817f
AC
16432This applies both to @value{GDBN} commands and their output, and to the input
16433and output done by the program you are debugging.
bf0184be 16434
8e04817f
AC
16435This is useful because it means that you can copy the text of previous
16436commands and input them again; you can even use parts of the output
16437in this way.
bf0184be 16438
8e04817f
AC
16439All the facilities of Emacs' Shell mode are available for interacting
16440with your program. In particular, you can send signals the usual
16441way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
16442stop.
bf0184be 16443
8e04817f 16444@itemize @bullet
bf0184be 16445@item
8e04817f
AC
16446@value{GDBN} displays source code through Emacs.
16447@end itemize
bf0184be 16448
8e04817f
AC
16449Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
16450source file for that frame and puts an arrow (@samp{=>}) at the
16451left margin of the current line. Emacs uses a separate buffer for
16452source display, and splits the screen to show both your @value{GDBN} session
16453and the source.
bf0184be 16454
8e04817f
AC
16455Explicit @value{GDBN} @code{list} or search commands still produce output as
16456usual, but you probably have no reason to use them from Emacs.
c906108c 16457
64fabec2
AC
16458If you specify an absolute file name when prompted for the @kbd{M-x
16459gdb} argument, then Emacs sets your current working directory to where
16460your program resides. If you only specify the file name, then Emacs
16461sets your current working directory to to the directory associated
16462with the previous buffer. In this case, @value{GDBN} may find your
16463program by searching your environment's @code{PATH} variable, but on
16464some operating systems it might not find the source. So, although the
16465@value{GDBN} input and output session proceeds normally, the auxiliary
16466buffer does not display the current source and line of execution.
16467
16468The initial working directory of @value{GDBN} is printed on the top
16469line of the @value{GDBN} I/O buffer and this serves as a default for
16470the commands that specify files for @value{GDBN} to operate
16471on. @xref{Files, ,Commands to specify files}.
16472
16473By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
16474need to call @value{GDBN} by a different name (for example, if you
16475keep several configurations around, with different names) you can
16476customize the Emacs variable @code{gud-gdb-command-name} to run the
16477one you want.
8e04817f
AC
16478
16479In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
16480addition to the standard Shell mode commands:
c906108c 16481
8e04817f
AC
16482@table @kbd
16483@item C-h m
16484Describe the features of Emacs' @value{GDBN} Mode.
c906108c 16485
64fabec2 16486@item C-c C-s
8e04817f
AC
16487Execute to another source line, like the @value{GDBN} @code{step} command; also
16488update the display window to show the current file and location.
c906108c 16489
64fabec2 16490@item C-c C-n
8e04817f
AC
16491Execute to next source line in this function, skipping all function
16492calls, like the @value{GDBN} @code{next} command. Then update the display window
16493to show the current file and location.
c906108c 16494
64fabec2 16495@item C-c C-i
8e04817f
AC
16496Execute one instruction, like the @value{GDBN} @code{stepi} command; update
16497display window accordingly.
c906108c 16498
8e04817f
AC
16499@item C-c C-f
16500Execute until exit from the selected stack frame, like the @value{GDBN}
16501@code{finish} command.
c906108c 16502
64fabec2 16503@item C-c C-r
8e04817f
AC
16504Continue execution of your program, like the @value{GDBN} @code{continue}
16505command.
b433d00b 16506
64fabec2 16507@item C-c <
8e04817f
AC
16508Go up the number of frames indicated by the numeric argument
16509(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
16510like the @value{GDBN} @code{up} command.
b433d00b 16511
64fabec2 16512@item C-c >
8e04817f
AC
16513Go down the number of frames indicated by the numeric argument, like the
16514@value{GDBN} @code{down} command.
8e04817f 16515@end table
c906108c 16516
64fabec2 16517In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 16518tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 16519
64fabec2
AC
16520If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
16521shows a backtrace when the @value{GDBN} I/O buffer is current. Move
16522point to any frame in the stack and type @key{RET} to make it become the
16523current frame and display the associated source in the source buffer.
16524Alternatively, click @kbd{Mouse-2} to make the selected frame become the
16525current one.
16526
8e04817f
AC
16527If you accidentally delete the source-display buffer, an easy way to get
16528it back is to type the command @code{f} in the @value{GDBN} buffer, to
16529request a frame display; when you run under Emacs, this recreates
16530the source buffer if necessary to show you the context of the current
16531frame.
c906108c 16532
8e04817f
AC
16533The source files displayed in Emacs are in ordinary Emacs buffers
16534which are visiting the source files in the usual way. You can edit
16535the files with these buffers if you wish; but keep in mind that @value{GDBN}
16536communicates with Emacs in terms of line numbers. If you add or
16537delete lines from the text, the line numbers that @value{GDBN} knows cease
16538to correspond properly with the code.
b383017d 16539
64fabec2
AC
16540The description given here is for GNU Emacs version 21.3 and a more
16541detailed description of its interaction with @value{GDBN} is given in
16542the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 16543
8e04817f
AC
16544@c The following dropped because Epoch is nonstandard. Reactivate
16545@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
16546@ignore
16547@kindex Emacs Epoch environment
16548@kindex Epoch
16549@kindex inspect
c906108c 16550
8e04817f
AC
16551Version 18 of @sc{gnu} Emacs has a built-in window system
16552called the @code{epoch}
16553environment. Users of this environment can use a new command,
16554@code{inspect} which performs identically to @code{print} except that
16555each value is printed in its own window.
16556@end ignore
c906108c 16557
922fbb7b
AC
16558
16559@node GDB/MI
16560@chapter The @sc{gdb/mi} Interface
16561
16562@unnumberedsec Function and Purpose
16563
16564@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
16565@sc{gdb/mi} is a line based machine oriented text interface to
16566@value{GDBN} and is activated by specifying using the
16567@option{--interpreter} command line option (@pxref{Mode Options}). It
16568is specifically intended to support the development of systems which
16569use the debugger as just one small component of a larger system.
922fbb7b
AC
16570
16571This chapter is a specification of the @sc{gdb/mi} interface. It is written
16572in the form of a reference manual.
16573
16574Note that @sc{gdb/mi} is still under construction, so some of the
16575features described below are incomplete and subject to change.
16576
16577@unnumberedsec Notation and Terminology
16578
16579@cindex notational conventions, for @sc{gdb/mi}
16580This chapter uses the following notation:
16581
16582@itemize @bullet
16583@item
16584@code{|} separates two alternatives.
16585
16586@item
16587@code{[ @var{something} ]} indicates that @var{something} is optional:
16588it may or may not be given.
16589
16590@item
16591@code{( @var{group} )*} means that @var{group} inside the parentheses
16592may repeat zero or more times.
16593
16594@item
16595@code{( @var{group} )+} means that @var{group} inside the parentheses
16596may repeat one or more times.
16597
16598@item
16599@code{"@var{string}"} means a literal @var{string}.
16600@end itemize
16601
16602@ignore
16603@heading Dependencies
16604@end ignore
16605
16606@heading Acknowledgments
16607
16608In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
16609Elena Zannoni.
16610
16611@menu
16612* GDB/MI Command Syntax::
16613* GDB/MI Compatibility with CLI::
16614* GDB/MI Output Records::
16615* GDB/MI Command Description Format::
16616* GDB/MI Breakpoint Table Commands::
16617* GDB/MI Data Manipulation::
16618* GDB/MI Program Control::
16619* GDB/MI Miscellaneous Commands::
16620@ignore
16621* GDB/MI Kod Commands::
16622* GDB/MI Memory Overlay Commands::
16623* GDB/MI Signal Handling Commands::
16624@end ignore
16625* GDB/MI Stack Manipulation::
16626* GDB/MI Symbol Query::
16627* GDB/MI Target Manipulation::
16628* GDB/MI Thread Commands::
16629* GDB/MI Tracepoint Commands::
16630* GDB/MI Variable Objects::
16631@end menu
16632
16633@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16634@node GDB/MI Command Syntax
16635@section @sc{gdb/mi} Command Syntax
16636
16637@menu
16638* GDB/MI Input Syntax::
16639* GDB/MI Output Syntax::
16640* GDB/MI Simple Examples::
16641@end menu
16642
16643@node GDB/MI Input Syntax
16644@subsection @sc{gdb/mi} Input Syntax
16645
16646@cindex input syntax for @sc{gdb/mi}
16647@cindex @sc{gdb/mi}, input syntax
16648@table @code
16649@item @var{command} @expansion{}
16650@code{@var{cli-command} | @var{mi-command}}
16651
16652@item @var{cli-command} @expansion{}
16653@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
16654@var{cli-command} is any existing @value{GDBN} CLI command.
16655
16656@item @var{mi-command} @expansion{}
16657@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
16658@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
16659
16660@item @var{token} @expansion{}
16661"any sequence of digits"
16662
16663@item @var{option} @expansion{}
16664@code{"-" @var{parameter} [ " " @var{parameter} ]}
16665
16666@item @var{parameter} @expansion{}
16667@code{@var{non-blank-sequence} | @var{c-string}}
16668
16669@item @var{operation} @expansion{}
16670@emph{any of the operations described in this chapter}
16671
16672@item @var{non-blank-sequence} @expansion{}
16673@emph{anything, provided it doesn't contain special characters such as
16674"-", @var{nl}, """ and of course " "}
16675
16676@item @var{c-string} @expansion{}
16677@code{""" @var{seven-bit-iso-c-string-content} """}
16678
16679@item @var{nl} @expansion{}
16680@code{CR | CR-LF}
16681@end table
16682
16683@noindent
16684Notes:
16685
16686@itemize @bullet
16687@item
16688The CLI commands are still handled by the @sc{mi} interpreter; their
16689output is described below.
16690
16691@item
16692The @code{@var{token}}, when present, is passed back when the command
16693finishes.
16694
16695@item
16696Some @sc{mi} commands accept optional arguments as part of the parameter
16697list. Each option is identified by a leading @samp{-} (dash) and may be
16698followed by an optional argument parameter. Options occur first in the
16699parameter list and can be delimited from normal parameters using
16700@samp{--} (this is useful when some parameters begin with a dash).
16701@end itemize
16702
16703Pragmatics:
16704
16705@itemize @bullet
16706@item
16707We want easy access to the existing CLI syntax (for debugging).
16708
16709@item
16710We want it to be easy to spot a @sc{mi} operation.
16711@end itemize
16712
16713@node GDB/MI Output Syntax
16714@subsection @sc{gdb/mi} Output Syntax
16715
16716@cindex output syntax of @sc{gdb/mi}
16717@cindex @sc{gdb/mi}, output syntax
16718The output from @sc{gdb/mi} consists of zero or more out-of-band records
16719followed, optionally, by a single result record. This result record
16720is for the most recent command. The sequence of output records is
16721terminated by @samp{(@value{GDBP})}.
16722
16723If an input command was prefixed with a @code{@var{token}} then the
16724corresponding output for that command will also be prefixed by that same
16725@var{token}.
16726
16727@table @code
16728@item @var{output} @expansion{}
f7dc1244 16729@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
922fbb7b
AC
16730
16731@item @var{result-record} @expansion{}
16732@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
16733
16734@item @var{out-of-band-record} @expansion{}
16735@code{@var{async-record} | @var{stream-record}}
16736
16737@item @var{async-record} @expansion{}
16738@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
16739
16740@item @var{exec-async-output} @expansion{}
16741@code{[ @var{token} ] "*" @var{async-output}}
16742
16743@item @var{status-async-output} @expansion{}
16744@code{[ @var{token} ] "+" @var{async-output}}
16745
16746@item @var{notify-async-output} @expansion{}
16747@code{[ @var{token} ] "=" @var{async-output}}
16748
16749@item @var{async-output} @expansion{}
16750@code{@var{async-class} ( "," @var{result} )* @var{nl}}
16751
16752@item @var{result-class} @expansion{}
16753@code{"done" | "running" | "connected" | "error" | "exit"}
16754
16755@item @var{async-class} @expansion{}
16756@code{"stopped" | @var{others}} (where @var{others} will be added
16757depending on the needs---this is still in development).
16758
16759@item @var{result} @expansion{}
16760@code{ @var{variable} "=" @var{value}}
16761
16762@item @var{variable} @expansion{}
16763@code{ @var{string} }
16764
16765@item @var{value} @expansion{}
16766@code{ @var{const} | @var{tuple} | @var{list} }
16767
16768@item @var{const} @expansion{}
16769@code{@var{c-string}}
16770
16771@item @var{tuple} @expansion{}
16772@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
16773
16774@item @var{list} @expansion{}
16775@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
16776@var{result} ( "," @var{result} )* "]" }
16777
16778@item @var{stream-record} @expansion{}
16779@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
16780
16781@item @var{console-stream-output} @expansion{}
16782@code{"~" @var{c-string}}
16783
16784@item @var{target-stream-output} @expansion{}
16785@code{"@@" @var{c-string}}
16786
16787@item @var{log-stream-output} @expansion{}
16788@code{"&" @var{c-string}}
16789
16790@item @var{nl} @expansion{}
16791@code{CR | CR-LF}
16792
16793@item @var{token} @expansion{}
16794@emph{any sequence of digits}.
16795@end table
16796
16797@noindent
16798Notes:
16799
16800@itemize @bullet
16801@item
16802All output sequences end in a single line containing a period.
16803
16804@item
16805The @code{@var{token}} is from the corresponding request. If an execution
16806command is interrupted by the @samp{-exec-interrupt} command, the
16807@var{token} associated with the @samp{*stopped} message is the one of the
16808original execution command, not the one of the interrupt command.
16809
16810@item
16811@cindex status output in @sc{gdb/mi}
16812@var{status-async-output} contains on-going status information about the
16813progress of a slow operation. It can be discarded. All status output is
16814prefixed by @samp{+}.
16815
16816@item
16817@cindex async output in @sc{gdb/mi}
16818@var{exec-async-output} contains asynchronous state change on the target
16819(stopped, started, disappeared). All async output is prefixed by
16820@samp{*}.
16821
16822@item
16823@cindex notify output in @sc{gdb/mi}
16824@var{notify-async-output} contains supplementary information that the
16825client should handle (e.g., a new breakpoint information). All notify
16826output is prefixed by @samp{=}.
16827
16828@item
16829@cindex console output in @sc{gdb/mi}
16830@var{console-stream-output} is output that should be displayed as is in the
16831console. It is the textual response to a CLI command. All the console
16832output is prefixed by @samp{~}.
16833
16834@item
16835@cindex target output in @sc{gdb/mi}
16836@var{target-stream-output} is the output produced by the target program.
16837All the target output is prefixed by @samp{@@}.
16838
16839@item
16840@cindex log output in @sc{gdb/mi}
16841@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
16842instance messages that should be displayed as part of an error log. All
16843the log output is prefixed by @samp{&}.
16844
16845@item
16846@cindex list output in @sc{gdb/mi}
16847New @sc{gdb/mi} commands should only output @var{lists} containing
16848@var{values}.
16849
16850
16851@end itemize
16852
16853@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
16854details about the various output records.
16855
16856@node GDB/MI Simple Examples
16857@subsection Simple Examples of @sc{gdb/mi} Interaction
16858@cindex @sc{gdb/mi}, simple examples
16859
16860This subsection presents several simple examples of interaction using
16861the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
16862following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
16863the output received from @sc{gdb/mi}.
16864
16865@subsubheading Target Stop
16866@c Ummm... There is no "-stop" command. This assumes async, no?
16867Here's an example of stopping the inferior process:
16868
16869@smallexample
16870-> -stop
16871<- (@value{GDBP})
16872@end smallexample
16873
16874@noindent
16875and later:
16876
16877@smallexample
16878<- *stop,reason="stop",address="0x123",source="a.c:123"
16879<- (@value{GDBP})
16880@end smallexample
16881
16882@subsubheading Simple CLI Command
16883
16884Here's an example of a simple CLI command being passed through
16885@sc{gdb/mi} and on to the CLI.
16886
16887@smallexample
16888-> print 1+2
16889<- &"print 1+2\n"
16890<- ~"$1 = 3\n"
16891<- ^done
16892<- (@value{GDBP})
16893@end smallexample
16894
16895@subsubheading Command With Side Effects
16896
16897@smallexample
16898-> -symbol-file xyz.exe
16899<- *breakpoint,nr="3",address="0x123",source="a.c:123"
16900<- (@value{GDBP})
16901@end smallexample
16902
16903@subsubheading A Bad Command
16904
16905Here's what happens if you pass a non-existent command:
16906
16907@smallexample
16908-> -rubbish
16909<- ^error,msg="Undefined MI command: rubbish"
16910<- (@value{GDBP})
16911@end smallexample
16912
16913@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16914@node GDB/MI Compatibility with CLI
16915@section @sc{gdb/mi} Compatibility with CLI
16916
16917@cindex compatibility, @sc{gdb/mi} and CLI
16918@cindex @sc{gdb/mi}, compatibility with CLI
16919To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
16920accepts existing CLI commands. As specified by the syntax, such
16921commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
16922respond.
16923
16924This mechanism is provided as an aid to developers of @sc{gdb/mi}
16925clients and not as a reliable interface into the CLI. Since the command
16926is being interpreteted in an environment that assumes @sc{gdb/mi}
16927behaviour, the exact output of such commands is likely to end up being
16928an un-supported hybrid of @sc{gdb/mi} and CLI output.
16929
16930@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16931@node GDB/MI Output Records
16932@section @sc{gdb/mi} Output Records
16933
16934@menu
16935* GDB/MI Result Records::
16936* GDB/MI Stream Records::
16937* GDB/MI Out-of-band Records::
16938@end menu
16939
16940@node GDB/MI Result Records
16941@subsection @sc{gdb/mi} Result Records
16942
16943@cindex result records in @sc{gdb/mi}
16944@cindex @sc{gdb/mi}, result records
16945In addition to a number of out-of-band notifications, the response to a
16946@sc{gdb/mi} command includes one of the following result indications:
16947
16948@table @code
16949@findex ^done
16950@item "^done" [ "," @var{results} ]
16951The synchronous operation was successful, @code{@var{results}} are the return
16952values.
16953
16954@item "^running"
16955@findex ^running
16956@c Is this one correct? Should it be an out-of-band notification?
16957The asynchronous operation was successfully started. The target is
16958running.
16959
16960@item "^error" "," @var{c-string}
16961@findex ^error
16962The operation failed. The @code{@var{c-string}} contains the corresponding
16963error message.
16964@end table
16965
16966@node GDB/MI Stream Records
16967@subsection @sc{gdb/mi} Stream Records
16968
16969@cindex @sc{gdb/mi}, stream records
16970@cindex stream records in @sc{gdb/mi}
16971@value{GDBN} internally maintains a number of output streams: the console, the
16972target, and the log. The output intended for each of these streams is
16973funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
16974
16975Each stream record begins with a unique @dfn{prefix character} which
16976identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
16977Syntax}). In addition to the prefix, each stream record contains a
16978@code{@var{string-output}}. This is either raw text (with an implicit new
16979line) or a quoted C string (which does not contain an implicit newline).
16980
16981@table @code
16982@item "~" @var{string-output}
16983The console output stream contains text that should be displayed in the
16984CLI console window. It contains the textual responses to CLI commands.
16985
16986@item "@@" @var{string-output}
16987The target output stream contains any textual output from the running
16988target.
16989
16990@item "&" @var{string-output}
16991The log stream contains debugging messages being produced by @value{GDBN}'s
16992internals.
16993@end table
16994
16995@node GDB/MI Out-of-band Records
16996@subsection @sc{gdb/mi} Out-of-band Records
16997
16998@cindex out-of-band records in @sc{gdb/mi}
16999@cindex @sc{gdb/mi}, out-of-band records
17000@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
17001additional changes that have occurred. Those changes can either be a
17002consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
17003target activity (e.g., target stopped).
17004
17005The following is a preliminary list of possible out-of-band records.
034dad6f 17006In particular, the @var{exec-async-output} records.
922fbb7b
AC
17007
17008@table @code
034dad6f
BR
17009@item *stopped,reason="@var{reason}"
17010@end table
17011
17012@var{reason} can be one of the following:
17013
17014@table @code
17015@item breakpoint-hit
17016A breakpoint was reached.
17017@item watchpoint-trigger
17018A watchpoint was triggered.
17019@item read-watchpoint-trigger
17020A read watchpoint was triggered.
17021@item access-watchpoint-trigger
17022An access watchpoint was triggered.
17023@item function-finished
17024An -exec-finish or similar CLI command was accomplished.
17025@item location-reached
17026An -exec-until or similar CLI command was accomplished.
17027@item watchpoint-scope
17028A watchpoint has gone out of scope.
17029@item end-stepping-range
17030An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
17031similar CLI command was accomplished.
17032@item exited-signalled
17033The inferior exited because of a signal.
17034@item exited
17035The inferior exited.
17036@item exited-normally
17037The inferior exited normally.
17038@item signal-received
17039A signal was received by the inferior.
922fbb7b
AC
17040@end table
17041
17042
17043@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17044@node GDB/MI Command Description Format
17045@section @sc{gdb/mi} Command Description Format
17046
17047The remaining sections describe blocks of commands. Each block of
17048commands is laid out in a fashion similar to this section.
17049
17050Note the the line breaks shown in the examples are here only for
17051readability. They don't appear in the real output.
17052Also note that the commands with a non-available example (N.A.@:) are
17053not yet implemented.
17054
17055@subheading Motivation
17056
17057The motivation for this collection of commands.
17058
17059@subheading Introduction
17060
17061A brief introduction to this collection of commands as a whole.
17062
17063@subheading Commands
17064
17065For each command in the block, the following is described:
17066
17067@subsubheading Synopsis
17068
17069@smallexample
17070 -command @var{args}@dots{}
17071@end smallexample
17072
922fbb7b
AC
17073@subsubheading Result
17074
265eeb58 17075@subsubheading @value{GDBN} Command
922fbb7b 17076
265eeb58 17077The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
17078
17079@subsubheading Example
17080
922fbb7b
AC
17081@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17082@node GDB/MI Breakpoint Table Commands
17083@section @sc{gdb/mi} Breakpoint table commands
17084
17085@cindex breakpoint commands for @sc{gdb/mi}
17086@cindex @sc{gdb/mi}, breakpoint commands
17087This section documents @sc{gdb/mi} commands for manipulating
17088breakpoints.
17089
17090@subheading The @code{-break-after} Command
17091@findex -break-after
17092
17093@subsubheading Synopsis
17094
17095@smallexample
17096 -break-after @var{number} @var{count}
17097@end smallexample
17098
17099The breakpoint number @var{number} is not in effect until it has been
17100hit @var{count} times. To see how this is reflected in the output of
17101the @samp{-break-list} command, see the description of the
17102@samp{-break-list} command below.
17103
17104@subsubheading @value{GDBN} Command
17105
17106The corresponding @value{GDBN} command is @samp{ignore}.
17107
17108@subsubheading Example
17109
17110@smallexample
17111(@value{GDBP})
17112-break-insert main
17113^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
17114(@value{GDBP})
17115-break-after 1 3
17116~
17117^done
17118(@value{GDBP})
17119-break-list
17120^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17121hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17122@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17123@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17124@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17125@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17126@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17127body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17128addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
17129ignore="3"@}]@}
17130(@value{GDBP})
17131@end smallexample
17132
17133@ignore
17134@subheading The @code{-break-catch} Command
17135@findex -break-catch
17136
17137@subheading The @code{-break-commands} Command
17138@findex -break-commands
17139@end ignore
17140
17141
17142@subheading The @code{-break-condition} Command
17143@findex -break-condition
17144
17145@subsubheading Synopsis
17146
17147@smallexample
17148 -break-condition @var{number} @var{expr}
17149@end smallexample
17150
17151Breakpoint @var{number} will stop the program only if the condition in
17152@var{expr} is true. The condition becomes part of the
17153@samp{-break-list} output (see the description of the @samp{-break-list}
17154command below).
17155
17156@subsubheading @value{GDBN} Command
17157
17158The corresponding @value{GDBN} command is @samp{condition}.
17159
17160@subsubheading Example
17161
17162@smallexample
17163(@value{GDBP})
17164-break-condition 1 1
17165^done
17166(@value{GDBP})
17167-break-list
17168^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17169hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17170@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17171@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17172@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17173@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17174@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17175body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17176addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
17177times="0",ignore="3"@}]@}
17178(@value{GDBP})
17179@end smallexample
17180
17181@subheading The @code{-break-delete} Command
17182@findex -break-delete
17183
17184@subsubheading Synopsis
17185
17186@smallexample
17187 -break-delete ( @var{breakpoint} )+
17188@end smallexample
17189
17190Delete the breakpoint(s) whose number(s) are specified in the argument
17191list. This is obviously reflected in the breakpoint list.
17192
17193@subsubheading @value{GDBN} command
17194
17195The corresponding @value{GDBN} command is @samp{delete}.
17196
17197@subsubheading Example
17198
17199@smallexample
17200(@value{GDBP})
17201-break-delete 1
17202^done
17203(@value{GDBP})
17204-break-list
17205^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17206hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17207@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17208@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17209@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17210@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17211@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17212body=[]@}
17213(@value{GDBP})
17214@end smallexample
17215
17216@subheading The @code{-break-disable} Command
17217@findex -break-disable
17218
17219@subsubheading Synopsis
17220
17221@smallexample
17222 -break-disable ( @var{breakpoint} )+
17223@end smallexample
17224
17225Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
17226break list is now set to @samp{n} for the named @var{breakpoint}(s).
17227
17228@subsubheading @value{GDBN} Command
17229
17230The corresponding @value{GDBN} command is @samp{disable}.
17231
17232@subsubheading Example
17233
17234@smallexample
17235(@value{GDBP})
17236-break-disable 2
17237^done
17238(@value{GDBP})
17239-break-list
17240^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17241hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17242@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17243@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17244@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17245@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17246@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17247body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
17248addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17249(@value{GDBP})
17250@end smallexample
17251
17252@subheading The @code{-break-enable} Command
17253@findex -break-enable
17254
17255@subsubheading Synopsis
17256
17257@smallexample
17258 -break-enable ( @var{breakpoint} )+
17259@end smallexample
17260
17261Enable (previously disabled) @var{breakpoint}(s).
17262
17263@subsubheading @value{GDBN} Command
17264
17265The corresponding @value{GDBN} command is @samp{enable}.
17266
17267@subsubheading Example
17268
17269@smallexample
17270(@value{GDBP})
17271-break-enable 2
17272^done
17273(@value{GDBP})
17274-break-list
17275^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17276hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17277@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17278@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17279@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17280@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17281@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17282body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17283addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17284(@value{GDBP})
17285@end smallexample
17286
17287@subheading The @code{-break-info} Command
17288@findex -break-info
17289
17290@subsubheading Synopsis
17291
17292@smallexample
17293 -break-info @var{breakpoint}
17294@end smallexample
17295
17296@c REDUNDANT???
17297Get information about a single breakpoint.
17298
17299@subsubheading @value{GDBN} command
17300
17301The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
17302
17303@subsubheading Example
17304N.A.
17305
17306@subheading The @code{-break-insert} Command
17307@findex -break-insert
17308
17309@subsubheading Synopsis
17310
17311@smallexample
17312 -break-insert [ -t ] [ -h ] [ -r ]
17313 [ -c @var{condition} ] [ -i @var{ignore-count} ]
17314 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
17315@end smallexample
17316
17317@noindent
17318If specified, @var{line}, can be one of:
17319
17320@itemize @bullet
17321@item function
17322@c @item +offset
17323@c @item -offset
17324@c @item linenum
17325@item filename:linenum
17326@item filename:function
17327@item *address
17328@end itemize
17329
17330The possible optional parameters of this command are:
17331
17332@table @samp
17333@item -t
17334Insert a tempoary breakpoint.
17335@item -h
17336Insert a hardware breakpoint.
17337@item -c @var{condition}
17338Make the breakpoint conditional on @var{condition}.
17339@item -i @var{ignore-count}
17340Initialize the @var{ignore-count}.
17341@item -r
17342Insert a regular breakpoint in all the functions whose names match the
17343given regular expression. Other flags are not applicable to regular
17344expresson.
17345@end table
17346
17347@subsubheading Result
17348
17349The result is in the form:
17350
17351@smallexample
17352 ^done,bkptno="@var{number}",func="@var{funcname}",
17353 file="@var{filename}",line="@var{lineno}"
17354@end smallexample
17355
17356@noindent
17357where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
17358is the name of the function where the breakpoint was inserted,
17359@var{filename} is the name of the source file which contains this
17360function, and @var{lineno} is the source line number within that file.
17361
17362Note: this format is open to change.
17363@c An out-of-band breakpoint instead of part of the result?
17364
17365@subsubheading @value{GDBN} Command
17366
17367The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
17368@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
17369
17370@subsubheading Example
17371
17372@smallexample
17373(@value{GDBP})
17374-break-insert main
17375^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17376(@value{GDBP})
17377-break-insert -t foo
17378^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
17379(@value{GDBP})
17380-break-list
17381^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17382hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17383@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17384@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17385@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17386@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17387@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17388body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17389addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
17390bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
17391addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
17392(@value{GDBP})
17393-break-insert -r foo.*
17394~int foo(int, int);
17395^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
17396(@value{GDBP})
17397@end smallexample
17398
17399@subheading The @code{-break-list} Command
17400@findex -break-list
17401
17402@subsubheading Synopsis
17403
17404@smallexample
17405 -break-list
17406@end smallexample
17407
17408Displays the list of inserted breakpoints, showing the following fields:
17409
17410@table @samp
17411@item Number
17412number of the breakpoint
17413@item Type
17414type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
17415@item Disposition
17416should the breakpoint be deleted or disabled when it is hit: @samp{keep}
17417or @samp{nokeep}
17418@item Enabled
17419is the breakpoint enabled or no: @samp{y} or @samp{n}
17420@item Address
17421memory location at which the breakpoint is set
17422@item What
17423logical location of the breakpoint, expressed by function name, file
17424name, line number
17425@item Times
17426number of times the breakpoint has been hit
17427@end table
17428
17429If there are no breakpoints or watchpoints, the @code{BreakpointTable}
17430@code{body} field is an empty list.
17431
17432@subsubheading @value{GDBN} Command
17433
17434The corresponding @value{GDBN} command is @samp{info break}.
17435
17436@subsubheading Example
17437
17438@smallexample
17439(@value{GDBP})
17440-break-list
17441^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17442hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17443@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17444@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17445@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17446@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17447@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17448body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17449addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
17450bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17451addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
17452(@value{GDBP})
17453@end smallexample
17454
17455Here's an example of the result when there are no breakpoints:
17456
17457@smallexample
17458(@value{GDBP})
17459-break-list
17460^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17461hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17462@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17463@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17464@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17465@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17466@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17467body=[]@}
17468(@value{GDBP})
17469@end smallexample
17470
17471@subheading The @code{-break-watch} Command
17472@findex -break-watch
17473
17474@subsubheading Synopsis
17475
17476@smallexample
17477 -break-watch [ -a | -r ]
17478@end smallexample
17479
17480Create a watchpoint. With the @samp{-a} option it will create an
17481@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
17482read from or on a write to the memory location. With the @samp{-r}
17483option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
17484trigger only when the memory location is accessed for reading. Without
17485either of the options, the watchpoint created is a regular watchpoint,
17486i.e. it will trigger when the memory location is accessed for writing.
17487@xref{Set Watchpoints, , Setting watchpoints}.
17488
17489Note that @samp{-break-list} will report a single list of watchpoints and
17490breakpoints inserted.
17491
17492@subsubheading @value{GDBN} Command
17493
17494The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
17495@samp{rwatch}.
17496
17497@subsubheading Example
17498
17499Setting a watchpoint on a variable in the @code{main} function:
17500
17501@smallexample
17502(@value{GDBP})
17503-break-watch x
17504^done,wpt=@{number="2",exp="x"@}
17505(@value{GDBP})
17506-exec-continue
17507^running
17508^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
17509value=@{old="-268439212",new="55"@},
76ff342d
DJ
17510frame=@{func="main",args=[],file="recursive2.c",
17511fullname="/home/foo/bar/devo/myproject/recursive2.c",line="5"@}
922fbb7b
AC
17512(@value{GDBP})
17513@end smallexample
17514
17515Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
17516the program execution twice: first for the variable changing value, then
17517for the watchpoint going out of scope.
17518
17519@smallexample
17520(@value{GDBP})
17521-break-watch C
17522^done,wpt=@{number="5",exp="C"@}
17523(@value{GDBP})
17524-exec-continue
17525^running
17526^done,reason="watchpoint-trigger",
17527wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
17528frame=@{func="callee4",args=[],
76ff342d
DJ
17529file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17530fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17531(@value{GDBP})
17532-exec-continue
17533^running
17534^done,reason="watchpoint-scope",wpnum="5",
17535frame=@{func="callee3",args=[@{name="strarg",
17536value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17537file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17538fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17539(@value{GDBP})
17540@end smallexample
17541
17542Listing breakpoints and watchpoints, at different points in the program
17543execution. Note that once the watchpoint goes out of scope, it is
17544deleted.
17545
17546@smallexample
17547(@value{GDBP})
17548-break-watch C
17549^done,wpt=@{number="2",exp="C"@}
17550(@value{GDBP})
17551-break-list
17552^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17553hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17554@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17555@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17556@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17557@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17558@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17559body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17560addr="0x00010734",func="callee4",
17561file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17562bkpt=@{number="2",type="watchpoint",disp="keep",
17563enabled="y",addr="",what="C",times="0"@}]@}
17564(@value{GDBP})
17565-exec-continue
17566^running
17567^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
17568value=@{old="-276895068",new="3"@},
17569frame=@{func="callee4",args=[],
76ff342d
DJ
17570file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17571fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17572(@value{GDBP})
17573-break-list
17574^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17575hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17576@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17577@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17578@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17579@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17580@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17581body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17582addr="0x00010734",func="callee4",
17583file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17584bkpt=@{number="2",type="watchpoint",disp="keep",
17585enabled="y",addr="",what="C",times="-5"@}]@}
17586(@value{GDBP})
17587-exec-continue
17588^running
17589^done,reason="watchpoint-scope",wpnum="2",
17590frame=@{func="callee3",args=[@{name="strarg",
17591value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17592file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17593fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17594(@value{GDBP})
17595-break-list
17596^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17597hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17598@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17599@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17600@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17601@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17602@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17603body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17604addr="0x00010734",func="callee4",
17605file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
17606(@value{GDBP})
17607@end smallexample
17608
17609@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17610@node GDB/MI Data Manipulation
17611@section @sc{gdb/mi} Data Manipulation
17612
17613@cindex data manipulation, in @sc{gdb/mi}
17614@cindex @sc{gdb/mi}, data manipulation
17615This section describes the @sc{gdb/mi} commands that manipulate data:
17616examine memory and registers, evaluate expressions, etc.
17617
17618@c REMOVED FROM THE INTERFACE.
17619@c @subheading -data-assign
17620@c Change the value of a program variable. Plenty of side effects.
17621@c @subsubheading GDB command
17622@c set variable
17623@c @subsubheading Example
17624@c N.A.
17625
17626@subheading The @code{-data-disassemble} Command
17627@findex -data-disassemble
17628
17629@subsubheading Synopsis
17630
17631@smallexample
17632 -data-disassemble
17633 [ -s @var{start-addr} -e @var{end-addr} ]
17634 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
17635 -- @var{mode}
17636@end smallexample
17637
17638@noindent
17639Where:
17640
17641@table @samp
17642@item @var{start-addr}
17643is the beginning address (or @code{$pc})
17644@item @var{end-addr}
17645is the end address
17646@item @var{filename}
17647is the name of the file to disassemble
17648@item @var{linenum}
17649is the line number to disassemble around
17650@item @var{lines}
17651is the the number of disassembly lines to be produced. If it is -1,
17652the whole function will be disassembled, in case no @var{end-addr} is
17653specified. If @var{end-addr} is specified as a non-zero value, and
17654@var{lines} is lower than the number of disassembly lines between
17655@var{start-addr} and @var{end-addr}, only @var{lines} lines are
17656displayed; if @var{lines} is higher than the number of lines between
17657@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
17658are displayed.
17659@item @var{mode}
17660is either 0 (meaning only disassembly) or 1 (meaning mixed source and
17661disassembly).
17662@end table
17663
17664@subsubheading Result
17665
17666The output for each instruction is composed of four fields:
17667
17668@itemize @bullet
17669@item Address
17670@item Func-name
17671@item Offset
17672@item Instruction
17673@end itemize
17674
17675Note that whatever included in the instruction field, is not manipulated
17676directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
17677
17678@subsubheading @value{GDBN} Command
17679
17680There's no direct mapping from this command to the CLI.
17681
17682@subsubheading Example
17683
17684Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
17685
17686@smallexample
17687(@value{GDBP})
17688-data-disassemble -s $pc -e "$pc + 20" -- 0
17689^done,
17690asm_insns=[
17691@{address="0x000107c0",func-name="main",offset="4",
17692inst="mov 2, %o0"@},
17693@{address="0x000107c4",func-name="main",offset="8",
17694inst="sethi %hi(0x11800), %o2"@},
17695@{address="0x000107c8",func-name="main",offset="12",
17696inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
17697@{address="0x000107cc",func-name="main",offset="16",
17698inst="sethi %hi(0x11800), %o2"@},
17699@{address="0x000107d0",func-name="main",offset="20",
17700inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
17701(@value{GDBP})
17702@end smallexample
17703
17704Disassemble the whole @code{main} function. Line 32 is part of
17705@code{main}.
17706
17707@smallexample
17708-data-disassemble -f basics.c -l 32 -- 0
17709^done,asm_insns=[
17710@{address="0x000107bc",func-name="main",offset="0",
17711inst="save %sp, -112, %sp"@},
17712@{address="0x000107c0",func-name="main",offset="4",
17713inst="mov 2, %o0"@},
17714@{address="0x000107c4",func-name="main",offset="8",
17715inst="sethi %hi(0x11800), %o2"@},
17716[@dots{}]
17717@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
17718@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
17719(@value{GDBP})
17720@end smallexample
17721
17722Disassemble 3 instructions from the start of @code{main}:
17723
17724@smallexample
17725(@value{GDBP})
17726-data-disassemble -f basics.c -l 32 -n 3 -- 0
17727^done,asm_insns=[
17728@{address="0x000107bc",func-name="main",offset="0",
17729inst="save %sp, -112, %sp"@},
17730@{address="0x000107c0",func-name="main",offset="4",
17731inst="mov 2, %o0"@},
17732@{address="0x000107c4",func-name="main",offset="8",
17733inst="sethi %hi(0x11800), %o2"@}]
17734(@value{GDBP})
17735@end smallexample
17736
17737Disassemble 3 instructions from the start of @code{main} in mixed mode:
17738
17739@smallexample
17740(@value{GDBP})
17741-data-disassemble -f basics.c -l 32 -n 3 -- 1
17742^done,asm_insns=[
17743src_and_asm_line=@{line="31",
17744file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17745 testsuite/gdb.mi/basics.c",line_asm_insn=[
17746@{address="0x000107bc",func-name="main",offset="0",
17747inst="save %sp, -112, %sp"@}]@},
17748src_and_asm_line=@{line="32",
17749file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17750 testsuite/gdb.mi/basics.c",line_asm_insn=[
17751@{address="0x000107c0",func-name="main",offset="4",
17752inst="mov 2, %o0"@},
17753@{address="0x000107c4",func-name="main",offset="8",
17754inst="sethi %hi(0x11800), %o2"@}]@}]
17755(@value{GDBP})
17756@end smallexample
17757
17758
17759@subheading The @code{-data-evaluate-expression} Command
17760@findex -data-evaluate-expression
17761
17762@subsubheading Synopsis
17763
17764@smallexample
17765 -data-evaluate-expression @var{expr}
17766@end smallexample
17767
17768Evaluate @var{expr} as an expression. The expression could contain an
17769inferior function call. The function call will execute synchronously.
17770If the expression contains spaces, it must be enclosed in double quotes.
17771
17772@subsubheading @value{GDBN} Command
17773
17774The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
17775@samp{call}. In @code{gdbtk} only, there's a corresponding
17776@samp{gdb_eval} command.
17777
17778@subsubheading Example
17779
17780In the following example, the numbers that precede the commands are the
17781@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
17782Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
17783output.
17784
17785@smallexample
17786211-data-evaluate-expression A
17787211^done,value="1"
17788(@value{GDBP})
17789311-data-evaluate-expression &A
17790311^done,value="0xefffeb7c"
17791(@value{GDBP})
17792411-data-evaluate-expression A+3
17793411^done,value="4"
17794(@value{GDBP})
17795511-data-evaluate-expression "A + 3"
17796511^done,value="4"
17797(@value{GDBP})
17798@end smallexample
17799
17800
17801@subheading The @code{-data-list-changed-registers} Command
17802@findex -data-list-changed-registers
17803
17804@subsubheading Synopsis
17805
17806@smallexample
17807 -data-list-changed-registers
17808@end smallexample
17809
17810Display a list of the registers that have changed.
17811
17812@subsubheading @value{GDBN} Command
17813
17814@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
17815has the corresponding command @samp{gdb_changed_register_list}.
17816
17817@subsubheading Example
17818
17819On a PPC MBX board:
17820
17821@smallexample
17822(@value{GDBP})
17823-exec-continue
17824^running
17825
17826(@value{GDBP})
17827*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
76ff342d 17828args=[],file="try.c",fullname="/home/foo/bar/devo/myproject/try.c",line="5"@}
922fbb7b
AC
17829(@value{GDBP})
17830-data-list-changed-registers
17831^done,changed-registers=["0","1","2","4","5","6","7","8","9",
17832"10","11","13","14","15","16","17","18","19","20","21","22","23",
17833"24","25","26","27","28","30","31","64","65","66","67","69"]
17834(@value{GDBP})
17835@end smallexample
17836
17837
17838@subheading The @code{-data-list-register-names} Command
17839@findex -data-list-register-names
17840
17841@subsubheading Synopsis
17842
17843@smallexample
17844 -data-list-register-names [ ( @var{regno} )+ ]
17845@end smallexample
17846
17847Show a list of register names for the current target. If no arguments
17848are given, it shows a list of the names of all the registers. If
17849integer numbers are given as arguments, it will print a list of the
17850names of the registers corresponding to the arguments. To ensure
17851consistency between a register name and its number, the output list may
17852include empty register names.
17853
17854@subsubheading @value{GDBN} Command
17855
17856@value{GDBN} does not have a command which corresponds to
17857@samp{-data-list-register-names}. In @code{gdbtk} there is a
17858corresponding command @samp{gdb_regnames}.
17859
17860@subsubheading Example
17861
17862For the PPC MBX board:
17863@smallexample
17864(@value{GDBP})
17865-data-list-register-names
17866^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
17867"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
17868"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
17869"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
17870"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
17871"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
17872"", "pc","ps","cr","lr","ctr","xer"]
17873(@value{GDBP})
17874-data-list-register-names 1 2 3
17875^done,register-names=["r1","r2","r3"]
17876(@value{GDBP})
17877@end smallexample
17878
17879@subheading The @code{-data-list-register-values} Command
17880@findex -data-list-register-values
17881
17882@subsubheading Synopsis
17883
17884@smallexample
17885 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
17886@end smallexample
17887
17888Display the registers' contents. @var{fmt} is the format according to
17889which the registers' contents are to be returned, followed by an optional
17890list of numbers specifying the registers to display. A missing list of
17891numbers indicates that the contents of all the registers must be returned.
17892
17893Allowed formats for @var{fmt} are:
17894
17895@table @code
17896@item x
17897Hexadecimal
17898@item o
17899Octal
17900@item t
17901Binary
17902@item d
17903Decimal
17904@item r
17905Raw
17906@item N
17907Natural
17908@end table
17909
17910@subsubheading @value{GDBN} Command
17911
17912The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
17913all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
17914
17915@subsubheading Example
17916
17917For a PPC MBX board (note: line breaks are for readability only, they
17918don't appear in the actual output):
17919
17920@smallexample
17921(@value{GDBP})
17922-data-list-register-values r 64 65
17923^done,register-values=[@{number="64",value="0xfe00a300"@},
17924@{number="65",value="0x00029002"@}]
17925(@value{GDBP})
17926-data-list-register-values x
17927^done,register-values=[@{number="0",value="0xfe0043c8"@},
17928@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
17929@{number="3",value="0x0"@},@{number="4",value="0xa"@},
17930@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
17931@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
17932@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
17933@{number="11",value="0x1"@},@{number="12",value="0x0"@},
17934@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
17935@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
17936@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
17937@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
17938@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
17939@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
17940@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
17941@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
17942@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
17943@{number="31",value="0x0"@},@{number="32",value="0x0"@},
17944@{number="33",value="0x0"@},@{number="34",value="0x0"@},
17945@{number="35",value="0x0"@},@{number="36",value="0x0"@},
17946@{number="37",value="0x0"@},@{number="38",value="0x0"@},
17947@{number="39",value="0x0"@},@{number="40",value="0x0"@},
17948@{number="41",value="0x0"@},@{number="42",value="0x0"@},
17949@{number="43",value="0x0"@},@{number="44",value="0x0"@},
17950@{number="45",value="0x0"@},@{number="46",value="0x0"@},
17951@{number="47",value="0x0"@},@{number="48",value="0x0"@},
17952@{number="49",value="0x0"@},@{number="50",value="0x0"@},
17953@{number="51",value="0x0"@},@{number="52",value="0x0"@},
17954@{number="53",value="0x0"@},@{number="54",value="0x0"@},
17955@{number="55",value="0x0"@},@{number="56",value="0x0"@},
17956@{number="57",value="0x0"@},@{number="58",value="0x0"@},
17957@{number="59",value="0x0"@},@{number="60",value="0x0"@},
17958@{number="61",value="0x0"@},@{number="62",value="0x0"@},
17959@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
17960@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
17961@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
17962@{number="69",value="0x20002b03"@}]
17963(@value{GDBP})
17964@end smallexample
17965
17966
17967@subheading The @code{-data-read-memory} Command
17968@findex -data-read-memory
17969
17970@subsubheading Synopsis
17971
17972@smallexample
17973 -data-read-memory [ -o @var{byte-offset} ]
17974 @var{address} @var{word-format} @var{word-size}
17975 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
17976@end smallexample
17977
17978@noindent
17979where:
17980
17981@table @samp
17982@item @var{address}
17983An expression specifying the address of the first memory word to be
17984read. Complex expressions containing embedded white space should be
17985quoted using the C convention.
17986
17987@item @var{word-format}
17988The format to be used to print the memory words. The notation is the
17989same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
17990,Output formats}).
17991
17992@item @var{word-size}
17993The size of each memory word in bytes.
17994
17995@item @var{nr-rows}
17996The number of rows in the output table.
17997
17998@item @var{nr-cols}
17999The number of columns in the output table.
18000
18001@item @var{aschar}
18002If present, indicates that each row should include an @sc{ascii} dump. The
18003value of @var{aschar} is used as a padding character when a byte is not a
18004member of the printable @sc{ascii} character set (printable @sc{ascii}
18005characters are those whose code is between 32 and 126, inclusively).
18006
18007@item @var{byte-offset}
18008An offset to add to the @var{address} before fetching memory.
18009@end table
18010
18011This command displays memory contents as a table of @var{nr-rows} by
18012@var{nr-cols} words, each word being @var{word-size} bytes. In total,
18013@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
18014(returned as @samp{total-bytes}). Should less than the requested number
18015of bytes be returned by the target, the missing words are identified
18016using @samp{N/A}. The number of bytes read from the target is returned
18017in @samp{nr-bytes} and the starting address used to read memory in
18018@samp{addr}.
18019
18020The address of the next/previous row or page is available in
18021@samp{next-row} and @samp{prev-row}, @samp{next-page} and
18022@samp{prev-page}.
18023
18024@subsubheading @value{GDBN} Command
18025
18026The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
18027@samp{gdb_get_mem} memory read command.
18028
18029@subsubheading Example
18030
18031Read six bytes of memory starting at @code{bytes+6} but then offset by
18032@code{-6} bytes. Format as three rows of two columns. One byte per
18033word. Display each word in hex.
18034
18035@smallexample
18036(@value{GDBP})
180379-data-read-memory -o -6 -- bytes+6 x 1 3 2
180389^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
18039next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
18040prev-page="0x0000138a",memory=[
18041@{addr="0x00001390",data=["0x00","0x01"]@},
18042@{addr="0x00001392",data=["0x02","0x03"]@},
18043@{addr="0x00001394",data=["0x04","0x05"]@}]
18044(@value{GDBP})
18045@end smallexample
18046
18047Read two bytes of memory starting at address @code{shorts + 64} and
18048display as a single word formatted in decimal.
18049
18050@smallexample
18051(@value{GDBP})
180525-data-read-memory shorts+64 d 2 1 1
180535^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
18054next-row="0x00001512",prev-row="0x0000150e",
18055next-page="0x00001512",prev-page="0x0000150e",memory=[
18056@{addr="0x00001510",data=["128"]@}]
18057(@value{GDBP})
18058@end smallexample
18059
18060Read thirty two bytes of memory starting at @code{bytes+16} and format
18061as eight rows of four columns. Include a string encoding with @samp{x}
18062used as the non-printable character.
18063
18064@smallexample
18065(@value{GDBP})
180664-data-read-memory bytes+16 x 1 8 4 x
180674^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
18068next-row="0x000013c0",prev-row="0x0000139c",
18069next-page="0x000013c0",prev-page="0x00001380",memory=[
18070@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
18071@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
18072@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
18073@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
18074@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
18075@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
18076@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
18077@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
18078(@value{GDBP})
18079@end smallexample
18080
18081@subheading The @code{-display-delete} Command
18082@findex -display-delete
18083
18084@subsubheading Synopsis
18085
18086@smallexample
18087 -display-delete @var{number}
18088@end smallexample
18089
18090Delete the display @var{number}.
18091
18092@subsubheading @value{GDBN} Command
18093
18094The corresponding @value{GDBN} command is @samp{delete display}.
18095
18096@subsubheading Example
18097N.A.
18098
18099
18100@subheading The @code{-display-disable} Command
18101@findex -display-disable
18102
18103@subsubheading Synopsis
18104
18105@smallexample
18106 -display-disable @var{number}
18107@end smallexample
18108
18109Disable display @var{number}.
18110
18111@subsubheading @value{GDBN} Command
18112
18113The corresponding @value{GDBN} command is @samp{disable display}.
18114
18115@subsubheading Example
18116N.A.
18117
18118
18119@subheading The @code{-display-enable} Command
18120@findex -display-enable
18121
18122@subsubheading Synopsis
18123
18124@smallexample
18125 -display-enable @var{number}
18126@end smallexample
18127
18128Enable display @var{number}.
18129
18130@subsubheading @value{GDBN} Command
18131
18132The corresponding @value{GDBN} command is @samp{enable display}.
18133
18134@subsubheading Example
18135N.A.
18136
18137
18138@subheading The @code{-display-insert} Command
18139@findex -display-insert
18140
18141@subsubheading Synopsis
18142
18143@smallexample
18144 -display-insert @var{expression}
18145@end smallexample
18146
18147Display @var{expression} every time the program stops.
18148
18149@subsubheading @value{GDBN} Command
18150
18151The corresponding @value{GDBN} command is @samp{display}.
18152
18153@subsubheading Example
18154N.A.
18155
18156
18157@subheading The @code{-display-list} Command
18158@findex -display-list
18159
18160@subsubheading Synopsis
18161
18162@smallexample
18163 -display-list
18164@end smallexample
18165
18166List the displays. Do not show the current values.
18167
18168@subsubheading @value{GDBN} Command
18169
18170The corresponding @value{GDBN} command is @samp{info display}.
18171
18172@subsubheading Example
18173N.A.
18174
18175
18176@subheading The @code{-environment-cd} Command
18177@findex -environment-cd
18178
18179@subsubheading Synopsis
18180
18181@smallexample
18182 -environment-cd @var{pathdir}
18183@end smallexample
18184
18185Set @value{GDBN}'s working directory.
18186
18187@subsubheading @value{GDBN} Command
18188
18189The corresponding @value{GDBN} command is @samp{cd}.
18190
18191@subsubheading Example
18192
18193@smallexample
18194(@value{GDBP})
18195-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18196^done
18197(@value{GDBP})
18198@end smallexample
18199
18200
18201@subheading The @code{-environment-directory} Command
18202@findex -environment-directory
18203
18204@subsubheading Synopsis
18205
18206@smallexample
18207 -environment-directory [ -r ] [ @var{pathdir} ]+
18208@end smallexample
18209
18210Add directories @var{pathdir} to beginning of search path for source files.
18211If the @samp{-r} option is used, the search path is reset to the default
b383017d 18212search path. If directories @var{pathdir} are supplied in addition to the
922fbb7b
AC
18213@samp{-r} option, the search path is first reset and then addition
18214occurs as normal.
b383017d 18215Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18216multiple directories in a single command
18217results in the directories added to the beginning of the
18218search path in the same order they were presented in the command.
18219If blanks are needed as
18220part of a directory name, double-quotes should be used around
18221the name. In the command output, the path will show up separated
b383017d 18222by the system directory-separator character. The directory-seperator
922fbb7b
AC
18223character must not be used
18224in any directory name.
18225If no directories are specified, the current search path is displayed.
18226
18227@subsubheading @value{GDBN} Command
18228
18229The corresponding @value{GDBN} command is @samp{dir}.
18230
18231@subsubheading Example
18232
18233@smallexample
18234(@value{GDBP})
18235-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18236^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18237(@value{GDBP})
18238-environment-directory ""
18239^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18240(@value{GDBP})
18241-environment-directory -r /home/jjohnstn/src/gdb /usr/src
18242^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
18243(@value{GDBP})
18244-environment-directory -r
18245^done,source-path="$cdir:$cwd"
18246(@value{GDBP})
18247@end smallexample
18248
18249
18250@subheading The @code{-environment-path} Command
18251@findex -environment-path
18252
18253@subsubheading Synopsis
18254
18255@smallexample
18256 -environment-path [ -r ] [ @var{pathdir} ]+
18257@end smallexample
18258
18259Add directories @var{pathdir} to beginning of search path for object files.
18260If the @samp{-r} option is used, the search path is reset to the original
b383017d
RM
18261search path that existed at gdb start-up. If directories @var{pathdir} are
18262supplied in addition to the
922fbb7b
AC
18263@samp{-r} option, the search path is first reset and then addition
18264occurs as normal.
b383017d 18265Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18266multiple directories in a single command
18267results in the directories added to the beginning of the
18268search path in the same order they were presented in the command.
18269If blanks are needed as
18270part of a directory name, double-quotes should be used around
18271the name. In the command output, the path will show up separated
b383017d 18272by the system directory-separator character. The directory-seperator
922fbb7b
AC
18273character must not be used
18274in any directory name.
18275If no directories are specified, the current path is displayed.
18276
18277
18278@subsubheading @value{GDBN} Command
18279
18280The corresponding @value{GDBN} command is @samp{path}.
18281
18282@subsubheading Example
18283
18284@smallexample
18285(@value{GDBP})
b383017d 18286-environment-path
922fbb7b
AC
18287^done,path="/usr/bin"
18288(@value{GDBP})
18289-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
18290^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
18291(@value{GDBP})
18292-environment-path -r /usr/local/bin
18293^done,path="/usr/local/bin:/usr/bin"
18294(@value{GDBP})
18295@end smallexample
18296
18297
18298@subheading The @code{-environment-pwd} Command
18299@findex -environment-pwd
18300
18301@subsubheading Synopsis
18302
18303@smallexample
18304 -environment-pwd
18305@end smallexample
18306
18307Show the current working directory.
18308
18309@subsubheading @value{GDBN} command
18310
18311The corresponding @value{GDBN} command is @samp{pwd}.
18312
18313@subsubheading Example
18314
18315@smallexample
18316(@value{GDBP})
18317-environment-pwd
18318^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
18319(@value{GDBP})
18320@end smallexample
18321
18322@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18323@node GDB/MI Program Control
18324@section @sc{gdb/mi} Program control
18325
18326@subsubheading Program termination
18327
18328As a result of execution, the inferior program can run to completion, if
18329it doesn't encounter any breakpoints. In this case the output will
18330include an exit code, if the program has exited exceptionally.
18331
18332@subsubheading Examples
18333
18334@noindent
18335Program exited normally:
18336
18337@smallexample
18338(@value{GDBP})
18339-exec-run
18340^running
18341(@value{GDBP})
18342x = 55
18343*stopped,reason="exited-normally"
18344(@value{GDBP})
18345@end smallexample
18346
18347@noindent
18348Program exited exceptionally:
18349
18350@smallexample
18351(@value{GDBP})
18352-exec-run
18353^running
18354(@value{GDBP})
18355x = 55
18356*stopped,reason="exited",exit-code="01"
18357(@value{GDBP})
18358@end smallexample
18359
18360Another way the program can terminate is if it receives a signal such as
18361@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
18362
18363@smallexample
18364(@value{GDBP})
18365*stopped,reason="exited-signalled",signal-name="SIGINT",
18366signal-meaning="Interrupt"
18367@end smallexample
18368
18369
18370@subheading The @code{-exec-abort} Command
18371@findex -exec-abort
18372
18373@subsubheading Synopsis
18374
18375@smallexample
18376 -exec-abort
18377@end smallexample
18378
18379Kill the inferior running program.
18380
18381@subsubheading @value{GDBN} Command
18382
18383The corresponding @value{GDBN} command is @samp{kill}.
18384
18385@subsubheading Example
18386N.A.
18387
18388
18389@subheading The @code{-exec-arguments} Command
18390@findex -exec-arguments
18391
18392@subsubheading Synopsis
18393
18394@smallexample
18395 -exec-arguments @var{args}
18396@end smallexample
18397
18398Set the inferior program arguments, to be used in the next
18399@samp{-exec-run}.
18400
18401@subsubheading @value{GDBN} Command
18402
18403The corresponding @value{GDBN} command is @samp{set args}.
18404
18405@subsubheading Example
18406
18407@c FIXME!
18408Don't have one around.
18409
18410
18411@subheading The @code{-exec-continue} Command
18412@findex -exec-continue
18413
18414@subsubheading Synopsis
18415
18416@smallexample
18417 -exec-continue
18418@end smallexample
18419
18420Asynchronous command. Resumes the execution of the inferior program
18421until a breakpoint is encountered, or until the inferior exits.
18422
18423@subsubheading @value{GDBN} Command
18424
18425The corresponding @value{GDBN} corresponding is @samp{continue}.
18426
18427@subsubheading Example
18428
18429@smallexample
18430-exec-continue
18431^running
18432(@value{GDBP})
18433@@Hello world
18434*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
76ff342d 18435file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="13"@}
922fbb7b
AC
18436(@value{GDBP})
18437@end smallexample
18438
18439
18440@subheading The @code{-exec-finish} Command
18441@findex -exec-finish
18442
18443@subsubheading Synopsis
18444
18445@smallexample
18446 -exec-finish
18447@end smallexample
18448
18449Asynchronous command. Resumes the execution of the inferior program
18450until the current function is exited. Displays the results returned by
18451the function.
18452
18453@subsubheading @value{GDBN} Command
18454
18455The corresponding @value{GDBN} command is @samp{finish}.
18456
18457@subsubheading Example
18458
18459Function returning @code{void}.
18460
18461@smallexample
18462-exec-finish
18463^running
18464(@value{GDBP})
18465@@hello from foo
18466*stopped,reason="function-finished",frame=@{func="main",args=[],
76ff342d 18467file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="7"@}
922fbb7b
AC
18468(@value{GDBP})
18469@end smallexample
18470
18471Function returning other than @code{void}. The name of the internal
18472@value{GDBN} variable storing the result is printed, together with the
18473value itself.
18474
18475@smallexample
18476-exec-finish
18477^running
18478(@value{GDBP})
18479*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
18480args=[@{name="a",value="1"],@{name="b",value="9"@}@},
76ff342d 18481file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b
AC
18482gdb-result-var="$1",return-value="0"
18483(@value{GDBP})
18484@end smallexample
18485
18486
18487@subheading The @code{-exec-interrupt} Command
18488@findex -exec-interrupt
18489
18490@subsubheading Synopsis
18491
18492@smallexample
18493 -exec-interrupt
18494@end smallexample
18495
18496Asynchronous command. Interrupts the background execution of the target.
18497Note how the token associated with the stop message is the one for the
18498execution command that has been interrupted. The token for the interrupt
18499itself only appears in the @samp{^done} output. If the user is trying to
18500interrupt a non-running program, an error message will be printed.
18501
18502@subsubheading @value{GDBN} Command
18503
18504The corresponding @value{GDBN} command is @samp{interrupt}.
18505
18506@subsubheading Example
18507
18508@smallexample
18509(@value{GDBP})
18510111-exec-continue
18511111^running
18512
18513(@value{GDBP})
18514222-exec-interrupt
18515222^done
18516(@value{GDBP})
18517111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d
DJ
18518frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
18519fullname="/home/foo/bar/devo/myproject/try.c",line="13"@}
922fbb7b
AC
18520(@value{GDBP})
18521
18522(@value{GDBP})
18523-exec-interrupt
18524^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
18525(@value{GDBP})
18526@end smallexample
18527
18528
18529@subheading The @code{-exec-next} Command
18530@findex -exec-next
18531
18532@subsubheading Synopsis
18533
18534@smallexample
18535 -exec-next
18536@end smallexample
18537
18538Asynchronous command. Resumes execution of the inferior program, stopping
18539when the beginning of the next source line is reached.
18540
18541@subsubheading @value{GDBN} Command
18542
18543The corresponding @value{GDBN} command is @samp{next}.
18544
18545@subsubheading Example
18546
18547@smallexample
18548-exec-next
18549^running
18550(@value{GDBP})
18551*stopped,reason="end-stepping-range",line="8",file="hello.c"
18552(@value{GDBP})
18553@end smallexample
18554
18555
18556@subheading The @code{-exec-next-instruction} Command
18557@findex -exec-next-instruction
18558
18559@subsubheading Synopsis
18560
18561@smallexample
18562 -exec-next-instruction
18563@end smallexample
18564
18565Asynchronous command. Executes one machine instruction. If the
18566instruction is a function call continues until the function returns. If
18567the program stops at an instruction in the middle of a source line, the
18568address will be printed as well.
18569
18570@subsubheading @value{GDBN} Command
18571
18572The corresponding @value{GDBN} command is @samp{nexti}.
18573
18574@subsubheading Example
18575
18576@smallexample
18577(@value{GDBP})
18578-exec-next-instruction
18579^running
18580
18581(@value{GDBP})
18582*stopped,reason="end-stepping-range",
18583addr="0x000100d4",line="5",file="hello.c"
18584(@value{GDBP})
18585@end smallexample
18586
18587
18588@subheading The @code{-exec-return} Command
18589@findex -exec-return
18590
18591@subsubheading Synopsis
18592
18593@smallexample
18594 -exec-return
18595@end smallexample
18596
18597Makes current function return immediately. Doesn't execute the inferior.
18598Displays the new current frame.
18599
18600@subsubheading @value{GDBN} Command
18601
18602The corresponding @value{GDBN} command is @samp{return}.
18603
18604@subsubheading Example
18605
18606@smallexample
18607(@value{GDBP})
18608200-break-insert callee4
18609200^done,bkpt=@{number="1",addr="0x00010734",
18610file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
18611(@value{GDBP})
18612000-exec-run
18613000^running
18614(@value{GDBP})
18615000*stopped,reason="breakpoint-hit",bkptno="1",
18616frame=@{func="callee4",args=[],
76ff342d
DJ
18617file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18618fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
922fbb7b
AC
18619(@value{GDBP})
18620205-break-delete
18621205^done
18622(@value{GDBP})
18623111-exec-return
18624111^done,frame=@{level="0",func="callee3",
18625args=[@{name="strarg",
18626value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
18627file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18628fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
18629(@value{GDBP})
18630@end smallexample
18631
18632
18633@subheading The @code{-exec-run} Command
18634@findex -exec-run
18635
18636@subsubheading Synopsis
18637
18638@smallexample
18639 -exec-run
18640@end smallexample
18641
18642Asynchronous command. Starts execution of the inferior from the
18643beginning. The inferior executes until either a breakpoint is
18644encountered or the program exits.
18645
18646@subsubheading @value{GDBN} Command
18647
18648The corresponding @value{GDBN} command is @samp{run}.
18649
18650@subsubheading Example
18651
18652@smallexample
18653(@value{GDBP})
18654-break-insert main
18655^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
18656(@value{GDBP})
18657-exec-run
18658^running
18659(@value{GDBP})
18660*stopped,reason="breakpoint-hit",bkptno="1",
76ff342d
DJ
18661frame=@{func="main",args=[],file="recursive2.c",
18662fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}
922fbb7b
AC
18663(@value{GDBP})
18664@end smallexample
18665
18666
18667@subheading The @code{-exec-show-arguments} Command
18668@findex -exec-show-arguments
18669
18670@subsubheading Synopsis
18671
18672@smallexample
18673 -exec-show-arguments
18674@end smallexample
18675
18676Print the arguments of the program.
18677
18678@subsubheading @value{GDBN} Command
18679
18680The corresponding @value{GDBN} command is @samp{show args}.
18681
18682@subsubheading Example
18683N.A.
18684
18685@c @subheading -exec-signal
18686
18687@subheading The @code{-exec-step} Command
18688@findex -exec-step
18689
18690@subsubheading Synopsis
18691
18692@smallexample
18693 -exec-step
18694@end smallexample
18695
18696Asynchronous command. Resumes execution of the inferior program, stopping
18697when the beginning of the next source line is reached, if the next
18698source line is not a function call. If it is, stop at the first
18699instruction of the called function.
18700
18701@subsubheading @value{GDBN} Command
18702
18703The corresponding @value{GDBN} command is @samp{step}.
18704
18705@subsubheading Example
18706
18707Stepping into a function:
18708
18709@smallexample
18710-exec-step
18711^running
18712(@value{GDBP})
18713*stopped,reason="end-stepping-range",
18714frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d
DJ
18715@{name="b",value="0"@}],file="recursive2.c",
18716fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@}
922fbb7b
AC
18717(@value{GDBP})
18718@end smallexample
18719
18720Regular stepping:
18721
18722@smallexample
18723-exec-step
18724^running
18725(@value{GDBP})
18726*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
18727(@value{GDBP})
18728@end smallexample
18729
18730
18731@subheading The @code{-exec-step-instruction} Command
18732@findex -exec-step-instruction
18733
18734@subsubheading Synopsis
18735
18736@smallexample
18737 -exec-step-instruction
18738@end smallexample
18739
18740Asynchronous command. Resumes the inferior which executes one machine
18741instruction. The output, once @value{GDBN} has stopped, will vary depending on
18742whether we have stopped in the middle of a source line or not. In the
18743former case, the address at which the program stopped will be printed as
18744well.
18745
18746@subsubheading @value{GDBN} Command
18747
18748The corresponding @value{GDBN} command is @samp{stepi}.
18749
18750@subsubheading Example
18751
18752@smallexample
18753(@value{GDBP})
18754-exec-step-instruction
18755^running
18756
18757(@value{GDBP})
18758*stopped,reason="end-stepping-range",
76ff342d
DJ
18759frame=@{func="foo",args=[],file="try.c",
18760fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18761(@value{GDBP})
18762-exec-step-instruction
18763^running
18764
18765(@value{GDBP})
18766*stopped,reason="end-stepping-range",
76ff342d
DJ
18767frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
18768fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18769(@value{GDBP})
18770@end smallexample
18771
18772
18773@subheading The @code{-exec-until} Command
18774@findex -exec-until
18775
18776@subsubheading Synopsis
18777
18778@smallexample
18779 -exec-until [ @var{location} ]
18780@end smallexample
18781
18782Asynchronous command. Executes the inferior until the @var{location}
18783specified in the argument is reached. If there is no argument, the inferior
18784executes until a source line greater than the current one is reached.
18785The reason for stopping in this case will be @samp{location-reached}.
18786
18787@subsubheading @value{GDBN} Command
18788
18789The corresponding @value{GDBN} command is @samp{until}.
18790
18791@subsubheading Example
18792
18793@smallexample
18794(@value{GDBP})
18795-exec-until recursive2.c:6
18796^running
18797(@value{GDBP})
18798x = 55
18799*stopped,reason="location-reached",frame=@{func="main",args=[],
76ff342d 18800file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="6"@}
922fbb7b
AC
18801(@value{GDBP})
18802@end smallexample
18803
18804@ignore
18805@subheading -file-clear
18806Is this going away????
18807@end ignore
18808
18809
18810@subheading The @code{-file-exec-and-symbols} Command
18811@findex -file-exec-and-symbols
18812
18813@subsubheading Synopsis
18814
18815@smallexample
18816 -file-exec-and-symbols @var{file}
18817@end smallexample
18818
18819Specify the executable file to be debugged. This file is the one from
18820which the symbol table is also read. If no file is specified, the
18821command clears the executable and symbol information. If breakpoints
18822are set when using this command with no arguments, @value{GDBN} will produce
18823error messages. Otherwise, no output is produced, except a completion
18824notification.
18825
18826@subsubheading @value{GDBN} Command
18827
18828The corresponding @value{GDBN} command is @samp{file}.
18829
18830@subsubheading Example
18831
18832@smallexample
18833(@value{GDBP})
18834-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18835^done
18836(@value{GDBP})
18837@end smallexample
18838
18839
18840@subheading The @code{-file-exec-file} Command
18841@findex -file-exec-file
18842
18843@subsubheading Synopsis
18844
18845@smallexample
18846 -file-exec-file @var{file}
18847@end smallexample
18848
18849Specify the executable file to be debugged. Unlike
18850@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
18851from this file. If used without argument, @value{GDBN} clears the information
18852about the executable file. No output is produced, except a completion
18853notification.
18854
18855@subsubheading @value{GDBN} Command
18856
18857The corresponding @value{GDBN} command is @samp{exec-file}.
18858
18859@subsubheading Example
18860
18861@smallexample
18862(@value{GDBP})
18863-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18864^done
18865(@value{GDBP})
18866@end smallexample
18867
18868
18869@subheading The @code{-file-list-exec-sections} Command
18870@findex -file-list-exec-sections
18871
18872@subsubheading Synopsis
18873
18874@smallexample
18875 -file-list-exec-sections
18876@end smallexample
18877
18878List the sections of the current executable file.
18879
18880@subsubheading @value{GDBN} Command
18881
18882The @value{GDBN} command @samp{info file} shows, among the rest, the same
18883information as this command. @code{gdbtk} has a corresponding command
18884@samp{gdb_load_info}.
18885
18886@subsubheading Example
18887N.A.
18888
18889
1abaf70c
BR
18890@subheading The @code{-file-list-exec-source-file} Command
18891@findex -file-list-exec-source-file
18892
18893@subsubheading Synopsis
18894
18895@smallexample
18896 -file-list-exec-source-file
18897@end smallexample
18898
b383017d 18899List the line number, the current source file, and the absolute path
1abaf70c
BR
18900to the current source file for the current executable.
18901
18902@subsubheading @value{GDBN} Command
18903
18904There's no @value{GDBN} command which directly corresponds to this one.
18905
18906@subsubheading Example
18907
18908@smallexample
18909(@value{GDBP})
18910123-file-list-exec-source-file
18911123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
18912(@value{GDBP})
18913@end smallexample
18914
18915
922fbb7b
AC
18916@subheading The @code{-file-list-exec-source-files} Command
18917@findex -file-list-exec-source-files
18918
18919@subsubheading Synopsis
18920
18921@smallexample
18922 -file-list-exec-source-files
18923@end smallexample
18924
18925List the source files for the current executable.
18926
57c22c6c
BR
18927It will always output the filename, but only when GDB can find the absolute
18928file name of a source file, will it output the fullname.
18929
922fbb7b
AC
18930@subsubheading @value{GDBN} Command
18931
18932There's no @value{GDBN} command which directly corresponds to this one.
18933@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
18934
18935@subsubheading Example
57c22c6c
BR
18936@smallexample
18937(@value{GDBP})
18938-file-list-exec-source-files
18939^done,files=[
18940@{file=foo.c,fullname=/home/foo.c@},
18941@{file=/home/bar.c,fullname=/home/bar.c@},
18942@{file=gdb_could_not_find_fullpath.c@}]
18943(@value{GDBP})
18944@end smallexample
922fbb7b
AC
18945
18946@subheading The @code{-file-list-shared-libraries} Command
18947@findex -file-list-shared-libraries
18948
18949@subsubheading Synopsis
18950
18951@smallexample
18952 -file-list-shared-libraries
18953@end smallexample
18954
18955List the shared libraries in the program.
18956
18957@subsubheading @value{GDBN} Command
18958
18959The corresponding @value{GDBN} command is @samp{info shared}.
18960
18961@subsubheading Example
18962N.A.
18963
18964
18965@subheading The @code{-file-list-symbol-files} Command
18966@findex -file-list-symbol-files
18967
18968@subsubheading Synopsis
18969
18970@smallexample
18971 -file-list-symbol-files
18972@end smallexample
18973
18974List symbol files.
18975
18976@subsubheading @value{GDBN} Command
18977
18978The corresponding @value{GDBN} command is @samp{info file} (part of it).
18979
18980@subsubheading Example
18981N.A.
18982
18983
18984@subheading The @code{-file-symbol-file} Command
18985@findex -file-symbol-file
18986
18987@subsubheading Synopsis
18988
18989@smallexample
18990 -file-symbol-file @var{file}
18991@end smallexample
18992
18993Read symbol table info from the specified @var{file} argument. When
18994used without arguments, clears @value{GDBN}'s symbol table info. No output is
18995produced, except for a completion notification.
18996
18997@subsubheading @value{GDBN} Command
18998
18999The corresponding @value{GDBN} command is @samp{symbol-file}.
19000
19001@subsubheading Example
19002
19003@smallexample
19004(@value{GDBP})
19005-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
19006^done
19007(@value{GDBP})
19008@end smallexample
19009
19010@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19011@node GDB/MI Miscellaneous Commands
19012@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
19013
19014@c @subheading -gdb-complete
19015
19016@subheading The @code{-gdb-exit} Command
19017@findex -gdb-exit
19018
19019@subsubheading Synopsis
19020
19021@smallexample
19022 -gdb-exit
19023@end smallexample
19024
19025Exit @value{GDBN} immediately.
19026
19027@subsubheading @value{GDBN} Command
19028
19029Approximately corresponds to @samp{quit}.
19030
19031@subsubheading Example
19032
19033@smallexample
19034(@value{GDBP})
19035-gdb-exit
19036@end smallexample
19037
19038@subheading The @code{-gdb-set} Command
19039@findex -gdb-set
19040
19041@subsubheading Synopsis
19042
19043@smallexample
19044 -gdb-set
19045@end smallexample
19046
19047Set an internal @value{GDBN} variable.
19048@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
19049
19050@subsubheading @value{GDBN} Command
19051
19052The corresponding @value{GDBN} command is @samp{set}.
19053
19054@subsubheading Example
19055
19056@smallexample
19057(@value{GDBP})
19058-gdb-set $foo=3
19059^done
19060(@value{GDBP})
19061@end smallexample
19062
19063
19064@subheading The @code{-gdb-show} Command
19065@findex -gdb-show
19066
19067@subsubheading Synopsis
19068
19069@smallexample
19070 -gdb-show
19071@end smallexample
19072
19073Show the current value of a @value{GDBN} variable.
19074
19075@subsubheading @value{GDBN} command
19076
19077The corresponding @value{GDBN} command is @samp{show}.
19078
19079@subsubheading Example
19080
19081@smallexample
19082(@value{GDBP})
19083-gdb-show annotate
19084^done,value="0"
19085(@value{GDBP})
19086@end smallexample
19087
19088@c @subheading -gdb-source
19089
19090
19091@subheading The @code{-gdb-version} Command
19092@findex -gdb-version
19093
19094@subsubheading Synopsis
19095
19096@smallexample
19097 -gdb-version
19098@end smallexample
19099
19100Show version information for @value{GDBN}. Used mostly in testing.
19101
19102@subsubheading @value{GDBN} Command
19103
19104There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
19105information when you start an interactive session.
19106
19107@subsubheading Example
19108
19109@c This example modifies the actual output from GDB to avoid overfull
19110@c box in TeX.
19111@smallexample
19112(@value{GDBP})
19113-gdb-version
19114~GNU gdb 5.2.1
19115~Copyright 2000 Free Software Foundation, Inc.
19116~GDB is free software, covered by the GNU General Public License, and
19117~you are welcome to change it and/or distribute copies of it under
19118~ certain conditions.
19119~Type "show copying" to see the conditions.
19120~There is absolutely no warranty for GDB. Type "show warranty" for
19121~ details.
b383017d 19122~This GDB was configured as
922fbb7b
AC
19123 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
19124^done
19125(@value{GDBP})
19126@end smallexample
19127
19128@subheading The @code{-interpreter-exec} Command
19129@findex -interpreter-exec
19130
19131@subheading Synopsis
19132
19133@smallexample
19134-interpreter-exec @var{interpreter} @var{command}
19135@end smallexample
19136
19137Execute the specified @var{command} in the given @var{interpreter}.
19138
19139@subheading @value{GDBN} Command
19140
19141The corresponding @value{GDBN} command is @samp{interpreter-exec}.
19142
19143@subheading Example
19144
19145@smallexample
19146(@value{GDBP})
19147-interpreter-exec console "break main"
19148&"During symbol reading, couldn't parse type; debugger out of date?.\n"
19149&"During symbol reading, bad structure-type format.\n"
19150~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
19151^done
19152(@value{GDBP})
19153@end smallexample
19154
3cb3b8df
BR
19155@subheading The @code{-inferior-tty-set} Command
19156@findex -inferior-tty-set
19157
19158@subheading Synopsis
19159
19160@smallexample
19161-inferior-tty-set /dev/pts/1
19162@end smallexample
19163
19164Set terminal for future runs of the program being debugged.
19165
19166@subheading @value{GDBN} Command
19167
19168The corresponding @value{GDBN} command is @samp{set inferior-tty /dev/pts/1}.
19169
19170@subheading Example
19171
19172@smallexample
19173(@value{GDBP})
19174-inferior-tty-set /dev/pts/1
19175^done
19176(@value{GDBP})
19177@end smallexample
19178
19179@subheading The @code{-inferior-tty-show} Command
19180@findex -inferior-tty-show
19181
19182@subheading Synopsis
19183
19184@smallexample
19185-inferior-tty-show
19186@end smallexample
19187
19188Show terminal for future runs of program being debugged.
19189
19190@subheading @value{GDBN} Command
19191
38f1196a 19192The corresponding @value{GDBN} command is @samp{show inferior-tty}.
3cb3b8df
BR
19193
19194@subheading Example
19195
19196@smallexample
19197(@value{GDBP})
19198-inferior-tty-set /dev/pts/1
19199^done
19200(@value{GDBP})
19201-inferior-tty-show
19202^done,inferior_tty_terminal="/dev/pts/1"
19203(@value{GDBP})
19204@end smallexample
19205
922fbb7b
AC
19206@ignore
19207@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19208@node GDB/MI Kod Commands
19209@section @sc{gdb/mi} Kod Commands
19210
19211The Kod commands are not implemented.
19212
19213@c @subheading -kod-info
19214
19215@c @subheading -kod-list
19216
19217@c @subheading -kod-list-object-types
19218
19219@c @subheading -kod-show
19220
19221@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19222@node GDB/MI Memory Overlay Commands
19223@section @sc{gdb/mi} Memory Overlay Commands
19224
19225The memory overlay commands are not implemented.
19226
19227@c @subheading -overlay-auto
19228
19229@c @subheading -overlay-list-mapping-state
19230
19231@c @subheading -overlay-list-overlays
19232
19233@c @subheading -overlay-map
19234
19235@c @subheading -overlay-off
19236
19237@c @subheading -overlay-on
19238
19239@c @subheading -overlay-unmap
19240
19241@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19242@node GDB/MI Signal Handling Commands
19243@section @sc{gdb/mi} Signal Handling Commands
19244
19245Signal handling commands are not implemented.
19246
19247@c @subheading -signal-handle
19248
19249@c @subheading -signal-list-handle-actions
19250
19251@c @subheading -signal-list-signal-types
19252@end ignore
19253
19254
19255@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19256@node GDB/MI Stack Manipulation
19257@section @sc{gdb/mi} Stack Manipulation Commands
19258
dcaaae04
NR
19259
19260@subheading The @code{-stack-info-frame} Command
19261@findex -stack-info-frame
19262
19263@subsubheading Synopsis
19264
19265@smallexample
19266 -stack-info-frame
19267@end smallexample
19268
19269Get info on the selected frame.
19270
19271@subsubheading @value{GDBN} Command
19272
19273The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
19274(without arguments).
19275
19276@subsubheading Example
19277
19278@smallexample
19279(@value{GDBP})
19280-stack-info-frame
19281^done,frame=@{level="1",addr="0x0001076c",func="callee3",
19282file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19283fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
19284(@value{GDBP})
19285@end smallexample
19286
922fbb7b
AC
19287@subheading The @code{-stack-info-depth} Command
19288@findex -stack-info-depth
19289
19290@subsubheading Synopsis
19291
19292@smallexample
19293 -stack-info-depth [ @var{max-depth} ]
19294@end smallexample
19295
19296Return the depth of the stack. If the integer argument @var{max-depth}
19297is specified, do not count beyond @var{max-depth} frames.
19298
19299@subsubheading @value{GDBN} Command
19300
19301There's no equivalent @value{GDBN} command.
19302
19303@subsubheading Example
19304
19305For a stack with frame levels 0 through 11:
19306
19307@smallexample
19308(@value{GDBP})
19309-stack-info-depth
19310^done,depth="12"
19311(@value{GDBP})
19312-stack-info-depth 4
19313^done,depth="4"
19314(@value{GDBP})
19315-stack-info-depth 12
19316^done,depth="12"
19317(@value{GDBP})
19318-stack-info-depth 11
19319^done,depth="11"
19320(@value{GDBP})
19321-stack-info-depth 13
19322^done,depth="12"
19323(@value{GDBP})
19324@end smallexample
19325
19326@subheading The @code{-stack-list-arguments} Command
19327@findex -stack-list-arguments
19328
19329@subsubheading Synopsis
19330
19331@smallexample
19332 -stack-list-arguments @var{show-values}
19333 [ @var{low-frame} @var{high-frame} ]
19334@end smallexample
19335
19336Display a list of the arguments for the frames between @var{low-frame}
19337and @var{high-frame} (inclusive). If @var{low-frame} and
19338@var{high-frame} are not provided, list the arguments for the whole call
19339stack.
19340
19341The @var{show-values} argument must have a value of 0 or 1. A value of
193420 means that only the names of the arguments are listed, a value of 1
19343means that both names and values of the arguments are printed.
19344
19345@subsubheading @value{GDBN} Command
19346
19347@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
19348@samp{gdb_get_args} command which partially overlaps with the
19349functionality of @samp{-stack-list-arguments}.
19350
19351@subsubheading Example
19352
19353@smallexample
19354(@value{GDBP})
19355-stack-list-frames
19356^done,
19357stack=[
19358frame=@{level="0",addr="0x00010734",func="callee4",
76ff342d
DJ
19359file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19360fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
922fbb7b 19361frame=@{level="1",addr="0x0001076c",func="callee3",
76ff342d
DJ
19362file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19363fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
922fbb7b 19364frame=@{level="2",addr="0x0001078c",func="callee2",
76ff342d
DJ
19365file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19366fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
922fbb7b 19367frame=@{level="3",addr="0x000107b4",func="callee1",
76ff342d
DJ
19368file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19369fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
922fbb7b 19370frame=@{level="4",addr="0x000107e0",func="main",
76ff342d
DJ
19371file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19372fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
922fbb7b
AC
19373(@value{GDBP})
19374-stack-list-arguments 0
19375^done,
19376stack-args=[
19377frame=@{level="0",args=[]@},
19378frame=@{level="1",args=[name="strarg"]@},
19379frame=@{level="2",args=[name="intarg",name="strarg"]@},
19380frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
19381frame=@{level="4",args=[]@}]
19382(@value{GDBP})
19383-stack-list-arguments 1
19384^done,
19385stack-args=[
19386frame=@{level="0",args=[]@},
19387frame=@{level="1",
19388 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19389frame=@{level="2",args=[
19390@{name="intarg",value="2"@},
19391@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19392@{frame=@{level="3",args=[
19393@{name="intarg",value="2"@},
19394@{name="strarg",value="0x11940 \"A string argument.\""@},
19395@{name="fltarg",value="3.5"@}]@},
19396frame=@{level="4",args=[]@}]
19397(@value{GDBP})
19398-stack-list-arguments 0 2 2
19399^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
19400(@value{GDBP})
19401-stack-list-arguments 1 2 2
19402^done,stack-args=[frame=@{level="2",
19403args=[@{name="intarg",value="2"@},
19404@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
19405(@value{GDBP})
19406@end smallexample
19407
19408@c @subheading -stack-list-exception-handlers
19409
19410
19411@subheading The @code{-stack-list-frames} Command
19412@findex -stack-list-frames
19413
19414@subsubheading Synopsis
19415
19416@smallexample
19417 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
19418@end smallexample
19419
19420List the frames currently on the stack. For each frame it displays the
19421following info:
19422
19423@table @samp
19424@item @var{level}
19425The frame number, 0 being the topmost frame, i.e. the innermost function.
19426@item @var{addr}
19427The @code{$pc} value for that frame.
19428@item @var{func}
19429Function name.
19430@item @var{file}
19431File name of the source file where the function lives.
19432@item @var{line}
19433Line number corresponding to the @code{$pc}.
19434@end table
19435
19436If invoked without arguments, this command prints a backtrace for the
19437whole stack. If given two integer arguments, it shows the frames whose
19438levels are between the two arguments (inclusive). If the two arguments
19439are equal, it shows the single frame at the corresponding level.
19440
19441@subsubheading @value{GDBN} Command
19442
19443The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
19444
19445@subsubheading Example
19446
19447Full stack backtrace:
19448
19449@smallexample
19450(@value{GDBP})
19451-stack-list-frames
19452^done,stack=
19453[frame=@{level="0",addr="0x0001076c",func="foo",
76ff342d 19454 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@},
922fbb7b 19455frame=@{level="1",addr="0x000107a4",func="foo",
76ff342d 19456 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19457frame=@{level="2",addr="0x000107a4",func="foo",
76ff342d 19458 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19459frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19460 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19461frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19462 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19463frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19464 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19465frame=@{level="6",addr="0x000107a4",func="foo",
76ff342d 19466 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19467frame=@{level="7",addr="0x000107a4",func="foo",
76ff342d 19468 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19469frame=@{level="8",addr="0x000107a4",func="foo",
76ff342d 19470 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19471frame=@{level="9",addr="0x000107a4",func="foo",
76ff342d 19472 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19473frame=@{level="10",addr="0x000107a4",func="foo",
76ff342d 19474 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19475frame=@{level="11",addr="0x00010738",func="main",
76ff342d 19476 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}]
922fbb7b
AC
19477(@value{GDBP})
19478@end smallexample
19479
19480Show frames between @var{low_frame} and @var{high_frame}:
19481
19482@smallexample
19483(@value{GDBP})
19484-stack-list-frames 3 5
19485^done,stack=
19486[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19487 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19488frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19489 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19490frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19491 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19492(@value{GDBP})
19493@end smallexample
19494
19495Show a single frame:
19496
19497@smallexample
19498(@value{GDBP})
19499-stack-list-frames 3 3
19500^done,stack=
19501[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19502 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19503(@value{GDBP})
19504@end smallexample
19505
19506
19507@subheading The @code{-stack-list-locals} Command
19508@findex -stack-list-locals
19509
19510@subsubheading Synopsis
19511
19512@smallexample
19513 -stack-list-locals @var{print-values}
19514@end smallexample
19515
265eeb58
NR
19516Display the local variable names for the selected frame. If
19517@var{print-values} is 0 or @code{--no-values}, print only the names of
19518the variables; if it is 1 or @code{--all-values}, print also their
19519values; and if it is 2 or @code{--simple-values}, print the name,
19520type and value for simple data types and the name and type for arrays,
19521structures and unions. In this last case, a frontend can immediately
19522display the value of simple data types and create variable objects for
19523other data types when the the user wishes to explore their values in
bc8ced35 19524more detail.
922fbb7b
AC
19525
19526@subsubheading @value{GDBN} Command
19527
19528@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
19529
19530@subsubheading Example
19531
19532@smallexample
19533(@value{GDBP})
19534-stack-list-locals 0
19535^done,locals=[name="A",name="B",name="C"]
19536(@value{GDBP})
bc8ced35 19537-stack-list-locals --all-values
922fbb7b 19538^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
bc8ced35
NR
19539 @{name="C",value="@{1, 2, 3@}"@}]
19540-stack-list-locals --simple-values
19541^done,locals=[@{name="A",type="int",value="1"@},
19542 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
922fbb7b
AC
19543(@value{GDBP})
19544@end smallexample
19545
19546
19547@subheading The @code{-stack-select-frame} Command
19548@findex -stack-select-frame
19549
19550@subsubheading Synopsis
19551
19552@smallexample
19553 -stack-select-frame @var{framenum}
19554@end smallexample
19555
265eeb58 19556Change the selected frame. Select a different frame @var{framenum} on
922fbb7b
AC
19557the stack.
19558
19559@subsubheading @value{GDBN} Command
19560
19561The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
19562@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
19563
19564@subsubheading Example
19565
19566@smallexample
19567(@value{GDBP})
19568-stack-select-frame 2
19569^done
19570(@value{GDBP})
19571@end smallexample
19572
19573@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19574@node GDB/MI Symbol Query
19575@section @sc{gdb/mi} Symbol Query Commands
19576
19577
19578@subheading The @code{-symbol-info-address} Command
19579@findex -symbol-info-address
19580
19581@subsubheading Synopsis
19582
19583@smallexample
19584 -symbol-info-address @var{symbol}
19585@end smallexample
19586
19587Describe where @var{symbol} is stored.
19588
19589@subsubheading @value{GDBN} Command
19590
19591The corresponding @value{GDBN} command is @samp{info address}.
19592
19593@subsubheading Example
19594N.A.
19595
19596
19597@subheading The @code{-symbol-info-file} Command
19598@findex -symbol-info-file
19599
19600@subsubheading Synopsis
19601
19602@smallexample
19603 -symbol-info-file
19604@end smallexample
19605
19606Show the file for the symbol.
19607
19608@subsubheading @value{GDBN} Command
19609
19610There's no equivalent @value{GDBN} command. @code{gdbtk} has
19611@samp{gdb_find_file}.
19612
19613@subsubheading Example
19614N.A.
19615
19616
19617@subheading The @code{-symbol-info-function} Command
19618@findex -symbol-info-function
19619
19620@subsubheading Synopsis
19621
19622@smallexample
19623 -symbol-info-function
19624@end smallexample
19625
19626Show which function the symbol lives in.
19627
19628@subsubheading @value{GDBN} Command
19629
19630@samp{gdb_get_function} in @code{gdbtk}.
19631
19632@subsubheading Example
19633N.A.
19634
19635
19636@subheading The @code{-symbol-info-line} Command
19637@findex -symbol-info-line
19638
19639@subsubheading Synopsis
19640
19641@smallexample
19642 -symbol-info-line
19643@end smallexample
19644
19645Show the core addresses of the code for a source line.
19646
19647@subsubheading @value{GDBN} Command
19648
71952f4c 19649The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
19650@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
19651
19652@subsubheading Example
19653N.A.
19654
19655
19656@subheading The @code{-symbol-info-symbol} Command
19657@findex -symbol-info-symbol
19658
19659@subsubheading Synopsis
19660
19661@smallexample
19662 -symbol-info-symbol @var{addr}
19663@end smallexample
19664
19665Describe what symbol is at location @var{addr}.
19666
19667@subsubheading @value{GDBN} Command
19668
19669The corresponding @value{GDBN} command is @samp{info symbol}.
19670
19671@subsubheading Example
19672N.A.
19673
19674
19675@subheading The @code{-symbol-list-functions} Command
19676@findex -symbol-list-functions
19677
19678@subsubheading Synopsis
19679
19680@smallexample
19681 -symbol-list-functions
19682@end smallexample
19683
19684List the functions in the executable.
19685
19686@subsubheading @value{GDBN} Command
19687
19688@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
19689@samp{gdb_search} in @code{gdbtk}.
19690
19691@subsubheading Example
19692N.A.
19693
19694
32e7087d
JB
19695@subheading The @code{-symbol-list-lines} Command
19696@findex -symbol-list-lines
19697
19698@subsubheading Synopsis
19699
19700@smallexample
19701 -symbol-list-lines @var{filename}
19702@end smallexample
19703
19704Print the list of lines that contain code and their associated program
19705addresses for the given source filename. The entries are sorted in
19706ascending PC order.
19707
19708@subsubheading @value{GDBN} Command
19709
19710There is no corresponding @value{GDBN} command.
19711
19712@subsubheading Example
19713@smallexample
19714(@value{GDBP})
19715-symbol-list-lines basics.c
54ff5908 19716^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
19717(@value{GDBP})
19718@end smallexample
19719
19720
922fbb7b
AC
19721@subheading The @code{-symbol-list-types} Command
19722@findex -symbol-list-types
19723
19724@subsubheading Synopsis
19725
19726@smallexample
19727 -symbol-list-types
19728@end smallexample
19729
19730List all the type names.
19731
19732@subsubheading @value{GDBN} Command
19733
19734The corresponding commands are @samp{info types} in @value{GDBN},
19735@samp{gdb_search} in @code{gdbtk}.
19736
19737@subsubheading Example
19738N.A.
19739
19740
19741@subheading The @code{-symbol-list-variables} Command
19742@findex -symbol-list-variables
19743
19744@subsubheading Synopsis
19745
19746@smallexample
19747 -symbol-list-variables
19748@end smallexample
19749
19750List all the global and static variable names.
19751
19752@subsubheading @value{GDBN} Command
19753
19754@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
19755
19756@subsubheading Example
19757N.A.
19758
19759
19760@subheading The @code{-symbol-locate} Command
19761@findex -symbol-locate
19762
19763@subsubheading Synopsis
19764
19765@smallexample
19766 -symbol-locate
19767@end smallexample
19768
19769@subsubheading @value{GDBN} Command
19770
19771@samp{gdb_loc} in @code{gdbtk}.
19772
19773@subsubheading Example
19774N.A.
19775
19776
19777@subheading The @code{-symbol-type} Command
19778@findex -symbol-type
19779
19780@subsubheading Synopsis
19781
19782@smallexample
19783 -symbol-type @var{variable}
19784@end smallexample
19785
19786Show type of @var{variable}.
19787
19788@subsubheading @value{GDBN} Command
19789
19790The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
19791@samp{gdb_obj_variable}.
19792
19793@subsubheading Example
19794N.A.
19795
19796
19797@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19798@node GDB/MI Target Manipulation
19799@section @sc{gdb/mi} Target Manipulation Commands
19800
19801
19802@subheading The @code{-target-attach} Command
19803@findex -target-attach
19804
19805@subsubheading Synopsis
19806
19807@smallexample
19808 -target-attach @var{pid} | @var{file}
19809@end smallexample
19810
19811Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
19812
19813@subsubheading @value{GDBN} command
19814
19815The corresponding @value{GDBN} command is @samp{attach}.
19816
19817@subsubheading Example
19818N.A.
19819
19820
19821@subheading The @code{-target-compare-sections} Command
19822@findex -target-compare-sections
19823
19824@subsubheading Synopsis
19825
19826@smallexample
19827 -target-compare-sections [ @var{section} ]
19828@end smallexample
19829
19830Compare data of section @var{section} on target to the exec file.
19831Without the argument, all sections are compared.
19832
19833@subsubheading @value{GDBN} Command
19834
19835The @value{GDBN} equivalent is @samp{compare-sections}.
19836
19837@subsubheading Example
19838N.A.
19839
19840
19841@subheading The @code{-target-detach} Command
19842@findex -target-detach
19843
19844@subsubheading Synopsis
19845
19846@smallexample
19847 -target-detach
19848@end smallexample
19849
19850Disconnect from the remote target. There's no output.
19851
19852@subsubheading @value{GDBN} command
19853
19854The corresponding @value{GDBN} command is @samp{detach}.
19855
19856@subsubheading Example
19857
19858@smallexample
19859(@value{GDBP})
19860-target-detach
19861^done
19862(@value{GDBP})
19863@end smallexample
19864
19865
07f31aa6
DJ
19866@subheading The @code{-target-disconnect} Command
19867@findex -target-disconnect
19868
19869@subsubheading Synopsis
19870
19871@example
19872 -target-disconnect
19873@end example
19874
19875Disconnect from the remote target. There's no output.
19876
19877@subsubheading @value{GDBN} command
19878
19879The corresponding @value{GDBN} command is @samp{disconnect}.
19880
19881@subsubheading Example
19882
19883@smallexample
19884(@value{GDBP})
19885-target-disconnect
19886^done
19887(@value{GDBP})
19888@end smallexample
19889
19890
922fbb7b
AC
19891@subheading The @code{-target-download} Command
19892@findex -target-download
19893
19894@subsubheading Synopsis
19895
19896@smallexample
19897 -target-download
19898@end smallexample
19899
19900Loads the executable onto the remote target.
19901It prints out an update message every half second, which includes the fields:
19902
19903@table @samp
19904@item section
19905The name of the section.
19906@item section-sent
19907The size of what has been sent so far for that section.
19908@item section-size
19909The size of the section.
19910@item total-sent
19911The total size of what was sent so far (the current and the previous sections).
19912@item total-size
19913The size of the overall executable to download.
19914@end table
19915
19916@noindent
19917Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
19918@sc{gdb/mi} Output Syntax}).
19919
19920In addition, it prints the name and size of the sections, as they are
19921downloaded. These messages include the following fields:
19922
19923@table @samp
19924@item section
19925The name of the section.
19926@item section-size
19927The size of the section.
19928@item total-size
19929The size of the overall executable to download.
19930@end table
19931
19932@noindent
19933At the end, a summary is printed.
19934
19935@subsubheading @value{GDBN} Command
19936
19937The corresponding @value{GDBN} command is @samp{load}.
19938
19939@subsubheading Example
19940
19941Note: each status message appears on a single line. Here the messages
19942have been broken down so that they can fit onto a page.
19943
19944@smallexample
19945(@value{GDBP})
19946-target-download
19947+download,@{section=".text",section-size="6668",total-size="9880"@}
19948+download,@{section=".text",section-sent="512",section-size="6668",
19949total-sent="512",total-size="9880"@}
19950+download,@{section=".text",section-sent="1024",section-size="6668",
19951total-sent="1024",total-size="9880"@}
19952+download,@{section=".text",section-sent="1536",section-size="6668",
19953total-sent="1536",total-size="9880"@}
19954+download,@{section=".text",section-sent="2048",section-size="6668",
19955total-sent="2048",total-size="9880"@}
19956+download,@{section=".text",section-sent="2560",section-size="6668",
19957total-sent="2560",total-size="9880"@}
19958+download,@{section=".text",section-sent="3072",section-size="6668",
19959total-sent="3072",total-size="9880"@}
19960+download,@{section=".text",section-sent="3584",section-size="6668",
19961total-sent="3584",total-size="9880"@}
19962+download,@{section=".text",section-sent="4096",section-size="6668",
19963total-sent="4096",total-size="9880"@}
19964+download,@{section=".text",section-sent="4608",section-size="6668",
19965total-sent="4608",total-size="9880"@}
19966+download,@{section=".text",section-sent="5120",section-size="6668",
19967total-sent="5120",total-size="9880"@}
19968+download,@{section=".text",section-sent="5632",section-size="6668",
19969total-sent="5632",total-size="9880"@}
19970+download,@{section=".text",section-sent="6144",section-size="6668",
19971total-sent="6144",total-size="9880"@}
19972+download,@{section=".text",section-sent="6656",section-size="6668",
19973total-sent="6656",total-size="9880"@}
19974+download,@{section=".init",section-size="28",total-size="9880"@}
19975+download,@{section=".fini",section-size="28",total-size="9880"@}
19976+download,@{section=".data",section-size="3156",total-size="9880"@}
19977+download,@{section=".data",section-sent="512",section-size="3156",
19978total-sent="7236",total-size="9880"@}
19979+download,@{section=".data",section-sent="1024",section-size="3156",
19980total-sent="7748",total-size="9880"@}
19981+download,@{section=".data",section-sent="1536",section-size="3156",
19982total-sent="8260",total-size="9880"@}
19983+download,@{section=".data",section-sent="2048",section-size="3156",
19984total-sent="8772",total-size="9880"@}
19985+download,@{section=".data",section-sent="2560",section-size="3156",
19986total-sent="9284",total-size="9880"@}
19987+download,@{section=".data",section-sent="3072",section-size="3156",
19988total-sent="9796",total-size="9880"@}
19989^done,address="0x10004",load-size="9880",transfer-rate="6586",
19990write-rate="429"
19991(@value{GDBP})
19992@end smallexample
19993
19994
19995@subheading The @code{-target-exec-status} Command
19996@findex -target-exec-status
19997
19998@subsubheading Synopsis
19999
20000@smallexample
20001 -target-exec-status
20002@end smallexample
20003
20004Provide information on the state of the target (whether it is running or
20005not, for instance).
20006
20007@subsubheading @value{GDBN} Command
20008
20009There's no equivalent @value{GDBN} command.
20010
20011@subsubheading Example
20012N.A.
20013
20014
20015@subheading The @code{-target-list-available-targets} Command
20016@findex -target-list-available-targets
20017
20018@subsubheading Synopsis
20019
20020@smallexample
20021 -target-list-available-targets
20022@end smallexample
20023
20024List the possible targets to connect to.
20025
20026@subsubheading @value{GDBN} Command
20027
20028The corresponding @value{GDBN} command is @samp{help target}.
20029
20030@subsubheading Example
20031N.A.
20032
20033
20034@subheading The @code{-target-list-current-targets} Command
20035@findex -target-list-current-targets
20036
20037@subsubheading Synopsis
20038
20039@smallexample
20040 -target-list-current-targets
20041@end smallexample
20042
20043Describe the current target.
20044
20045@subsubheading @value{GDBN} Command
20046
20047The corresponding information is printed by @samp{info file} (among
20048other things).
20049
20050@subsubheading Example
20051N.A.
20052
20053
20054@subheading The @code{-target-list-parameters} Command
20055@findex -target-list-parameters
20056
20057@subsubheading Synopsis
20058
20059@smallexample
20060 -target-list-parameters
20061@end smallexample
20062
20063@c ????
20064
20065@subsubheading @value{GDBN} Command
20066
20067No equivalent.
20068
20069@subsubheading Example
20070N.A.
20071
20072
20073@subheading The @code{-target-select} Command
20074@findex -target-select
20075
20076@subsubheading Synopsis
20077
20078@smallexample
20079 -target-select @var{type} @var{parameters @dots{}}
20080@end smallexample
20081
20082Connect @value{GDBN} to the remote target. This command takes two args:
20083
20084@table @samp
20085@item @var{type}
20086The type of target, for instance @samp{async}, @samp{remote}, etc.
20087@item @var{parameters}
20088Device names, host names and the like. @xref{Target Commands, ,
20089Commands for managing targets}, for more details.
20090@end table
20091
20092The output is a connection notification, followed by the address at
20093which the target program is, in the following form:
20094
20095@smallexample
20096^connected,addr="@var{address}",func="@var{function name}",
20097 args=[@var{arg list}]
20098@end smallexample
20099
20100@subsubheading @value{GDBN} Command
20101
20102The corresponding @value{GDBN} command is @samp{target}.
20103
20104@subsubheading Example
20105
20106@smallexample
20107(@value{GDBP})
20108-target-select async /dev/ttya
20109^connected,addr="0xfe00a300",func="??",args=[]
20110(@value{GDBP})
20111@end smallexample
20112
20113@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20114@node GDB/MI Thread Commands
20115@section @sc{gdb/mi} Thread Commands
20116
20117
20118@subheading The @code{-thread-info} Command
20119@findex -thread-info
20120
20121@subsubheading Synopsis
20122
20123@smallexample
20124 -thread-info
20125@end smallexample
20126
20127@subsubheading @value{GDBN} command
20128
20129No equivalent.
20130
20131@subsubheading Example
20132N.A.
20133
20134
20135@subheading The @code{-thread-list-all-threads} Command
20136@findex -thread-list-all-threads
20137
20138@subsubheading Synopsis
20139
20140@smallexample
20141 -thread-list-all-threads
20142@end smallexample
20143
20144@subsubheading @value{GDBN} Command
20145
20146The equivalent @value{GDBN} command is @samp{info threads}.
20147
20148@subsubheading Example
20149N.A.
20150
20151
20152@subheading The @code{-thread-list-ids} Command
20153@findex -thread-list-ids
20154
20155@subsubheading Synopsis
20156
20157@smallexample
20158 -thread-list-ids
20159@end smallexample
20160
20161Produces a list of the currently known @value{GDBN} thread ids. At the
20162end of the list it also prints the total number of such threads.
20163
20164@subsubheading @value{GDBN} Command
20165
20166Part of @samp{info threads} supplies the same information.
20167
20168@subsubheading Example
20169
20170No threads present, besides the main process:
20171
20172@smallexample
20173(@value{GDBP})
20174-thread-list-ids
20175^done,thread-ids=@{@},number-of-threads="0"
20176(@value{GDBP})
20177@end smallexample
20178
20179
20180Several threads:
20181
20182@smallexample
20183(@value{GDBP})
20184-thread-list-ids
20185^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20186number-of-threads="3"
20187(@value{GDBP})
20188@end smallexample
20189
20190
20191@subheading The @code{-thread-select} Command
20192@findex -thread-select
20193
20194@subsubheading Synopsis
20195
20196@smallexample
20197 -thread-select @var{threadnum}
20198@end smallexample
20199
20200Make @var{threadnum} the current thread. It prints the number of the new
20201current thread, and the topmost frame for that thread.
20202
20203@subsubheading @value{GDBN} Command
20204
20205The corresponding @value{GDBN} command is @samp{thread}.
20206
20207@subsubheading Example
20208
20209@smallexample
20210(@value{GDBP})
20211-exec-next
20212^running
20213(@value{GDBP})
20214*stopped,reason="end-stepping-range",thread-id="2",line="187",
20215file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
20216(@value{GDBP})
20217-thread-list-ids
20218^done,
20219thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20220number-of-threads="3"
20221(@value{GDBP})
20222-thread-select 3
20223^done,new-thread-id="3",
20224frame=@{level="0",func="vprintf",
20225args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
20226@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
20227(@value{GDBP})
20228@end smallexample
20229
20230@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20231@node GDB/MI Tracepoint Commands
20232@section @sc{gdb/mi} Tracepoint Commands
20233
20234The tracepoint commands are not yet implemented.
20235
20236@c @subheading -trace-actions
20237
20238@c @subheading -trace-delete
20239
20240@c @subheading -trace-disable
20241
20242@c @subheading -trace-dump
20243
20244@c @subheading -trace-enable
20245
20246@c @subheading -trace-exists
20247
20248@c @subheading -trace-find
20249
20250@c @subheading -trace-frame-number
20251
20252@c @subheading -trace-info
20253
20254@c @subheading -trace-insert
20255
20256@c @subheading -trace-list
20257
20258@c @subheading -trace-pass-count
20259
20260@c @subheading -trace-save
20261
20262@c @subheading -trace-start
20263
20264@c @subheading -trace-stop
20265
20266
20267@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20268@node GDB/MI Variable Objects
20269@section @sc{gdb/mi} Variable Objects
20270
20271
20272@subheading Motivation for Variable Objects in @sc{gdb/mi}
20273
20274For the implementation of a variable debugger window (locals, watched
20275expressions, etc.), we are proposing the adaptation of the existing code
20276used by @code{Insight}.
20277
20278The two main reasons for that are:
20279
20280@enumerate 1
20281@item
20282It has been proven in practice (it is already on its second generation).
20283
20284@item
20285It will shorten development time (needless to say how important it is
20286now).
20287@end enumerate
20288
20289The original interface was designed to be used by Tcl code, so it was
20290slightly changed so it could be used through @sc{gdb/mi}. This section
20291describes the @sc{gdb/mi} operations that will be available and gives some
20292hints about their use.
20293
20294@emph{Note}: In addition to the set of operations described here, we
20295expect the @sc{gui} implementation of a variable window to require, at
20296least, the following operations:
20297
20298@itemize @bullet
20299@item @code{-gdb-show} @code{output-radix}
20300@item @code{-stack-list-arguments}
20301@item @code{-stack-list-locals}
20302@item @code{-stack-select-frame}
20303@end itemize
20304
20305@subheading Introduction to Variable Objects in @sc{gdb/mi}
20306
20307@cindex variable objects in @sc{gdb/mi}
20308The basic idea behind variable objects is the creation of a named object
20309to represent a variable, an expression, a memory location or even a CPU
20310register. For each object created, a set of operations is available for
20311examining or changing its properties.
20312
20313Furthermore, complex data types, such as C structures, are represented
20314in a tree format. For instance, the @code{struct} type variable is the
20315root and the children will represent the struct members. If a child
20316is itself of a complex type, it will also have children of its own.
20317Appropriate language differences are handled for C, C@t{++} and Java.
20318
20319When returning the actual values of the objects, this facility allows
20320for the individual selection of the display format used in the result
20321creation. It can be chosen among: binary, decimal, hexadecimal, octal
20322and natural. Natural refers to a default format automatically
20323chosen based on the variable type (like decimal for an @code{int}, hex
20324for pointers, etc.).
20325
20326The following is the complete set of @sc{gdb/mi} operations defined to
20327access this functionality:
20328
20329@multitable @columnfractions .4 .6
20330@item @strong{Operation}
20331@tab @strong{Description}
20332
20333@item @code{-var-create}
20334@tab create a variable object
20335@item @code{-var-delete}
20336@tab delete the variable object and its children
20337@item @code{-var-set-format}
20338@tab set the display format of this variable
20339@item @code{-var-show-format}
20340@tab show the display format of this variable
20341@item @code{-var-info-num-children}
20342@tab tells how many children this object has
20343@item @code{-var-list-children}
20344@tab return a list of the object's children
20345@item @code{-var-info-type}
20346@tab show the type of this variable object
20347@item @code{-var-info-expression}
20348@tab print what this variable object represents
20349@item @code{-var-show-attributes}
20350@tab is this variable editable? does it exist here?
20351@item @code{-var-evaluate-expression}
20352@tab get the value of this variable
20353@item @code{-var-assign}
20354@tab set the value of this variable
20355@item @code{-var-update}
20356@tab update the variable and its children
20357@end multitable
20358
20359In the next subsection we describe each operation in detail and suggest
20360how it can be used.
20361
20362@subheading Description And Use of Operations on Variable Objects
20363
20364@subheading The @code{-var-create} Command
20365@findex -var-create
20366
20367@subsubheading Synopsis
20368
20369@smallexample
20370 -var-create @{@var{name} | "-"@}
20371 @{@var{frame-addr} | "*"@} @var{expression}
20372@end smallexample
20373
20374This operation creates a variable object, which allows the monitoring of
20375a variable, the result of an expression, a memory cell or a CPU
20376register.
20377
20378The @var{name} parameter is the string by which the object can be
20379referenced. It must be unique. If @samp{-} is specified, the varobj
20380system will generate a string ``varNNNNNN'' automatically. It will be
20381unique provided that one does not specify @var{name} on that format.
20382The command fails if a duplicate name is found.
20383
20384The frame under which the expression should be evaluated can be
20385specified by @var{frame-addr}. A @samp{*} indicates that the current
20386frame should be used.
20387
20388@var{expression} is any expression valid on the current language set (must not
20389begin with a @samp{*}), or one of the following:
20390
20391@itemize @bullet
20392@item
20393@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
20394
20395@item
20396@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
20397
20398@item
20399@samp{$@var{regname}} --- a CPU register name
20400@end itemize
20401
20402@subsubheading Result
20403
20404This operation returns the name, number of children and the type of the
20405object created. Type is returned as a string as the ones generated by
20406the @value{GDBN} CLI:
20407
20408@smallexample
20409 name="@var{name}",numchild="N",type="@var{type}"
20410@end smallexample
20411
20412
20413@subheading The @code{-var-delete} Command
20414@findex -var-delete
20415
20416@subsubheading Synopsis
20417
20418@smallexample
20419 -var-delete @var{name}
20420@end smallexample
20421
20422Deletes a previously created variable object and all of its children.
20423
20424Returns an error if the object @var{name} is not found.
20425
20426
20427@subheading The @code{-var-set-format} Command
20428@findex -var-set-format
20429
20430@subsubheading Synopsis
20431
20432@smallexample
20433 -var-set-format @var{name} @var{format-spec}
20434@end smallexample
20435
20436Sets the output format for the value of the object @var{name} to be
20437@var{format-spec}.
20438
20439The syntax for the @var{format-spec} is as follows:
20440
20441@smallexample
20442 @var{format-spec} @expansion{}
20443 @{binary | decimal | hexadecimal | octal | natural@}
20444@end smallexample
20445
20446
20447@subheading The @code{-var-show-format} Command
20448@findex -var-show-format
20449
20450@subsubheading Synopsis
20451
20452@smallexample
20453 -var-show-format @var{name}
20454@end smallexample
20455
20456Returns the format used to display the value of the object @var{name}.
20457
20458@smallexample
20459 @var{format} @expansion{}
20460 @var{format-spec}
20461@end smallexample
20462
20463
20464@subheading The @code{-var-info-num-children} Command
20465@findex -var-info-num-children
20466
20467@subsubheading Synopsis
20468
20469@smallexample
20470 -var-info-num-children @var{name}
20471@end smallexample
20472
20473Returns the number of children of a variable object @var{name}:
20474
20475@smallexample
20476 numchild=@var{n}
20477@end smallexample
20478
20479
20480@subheading The @code{-var-list-children} Command
20481@findex -var-list-children
20482
20483@subsubheading Synopsis
20484
20485@smallexample
bc8ced35 20486 -var-list-children [@var{print-values}] @var{name}
922fbb7b 20487@end smallexample
265eeb58 20488@anchor{-var-list-children}
922fbb7b 20489
265eeb58
NR
20490Return a list of the children of the specified variable object and
20491create variable objects for them, if they do not already exist. With
20492a single argument or if @var{print-values} has a value for of 0 or
20493@code{--no-values}, print only the names of the variables; if
20494@var{print-values} is 1 or @code{--all-values}, also print their
20495values; and if it is 2 or @code{--simple-values} print the name and
20496value for simple data types and just the name for arrays, structures
20497and unions.
bc8ced35
NR
20498
20499@subsubheading Example
922fbb7b
AC
20500
20501@smallexample
bc8ced35
NR
20502(@value{GDBP})
20503 -var-list-children n
265eeb58 20504 ^done,numchild=@var{n},children=[@{name=@var{name},
922fbb7b 20505 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
bc8ced35
NR
20506(@value{GDBP})
20507 -var-list-children --all-values n
265eeb58 20508 ^done,numchild=@var{n},children=[@{name=@var{name},
bc8ced35 20509 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
20510@end smallexample
20511
20512
20513@subheading The @code{-var-info-type} Command
20514@findex -var-info-type
20515
20516@subsubheading Synopsis
20517
20518@smallexample
20519 -var-info-type @var{name}
20520@end smallexample
20521
20522Returns the type of the specified variable @var{name}. The type is
20523returned as a string in the same format as it is output by the
20524@value{GDBN} CLI:
20525
20526@smallexample
20527 type=@var{typename}
20528@end smallexample
20529
20530
20531@subheading The @code{-var-info-expression} Command
20532@findex -var-info-expression
20533
20534@subsubheading Synopsis
20535
20536@smallexample
20537 -var-info-expression @var{name}
20538@end smallexample
20539
20540Returns what is represented by the variable object @var{name}:
20541
20542@smallexample
20543 lang=@var{lang-spec},exp=@var{expression}
20544@end smallexample
20545
20546@noindent
20547where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
20548
20549@subheading The @code{-var-show-attributes} Command
20550@findex -var-show-attributes
20551
20552@subsubheading Synopsis
20553
20554@smallexample
20555 -var-show-attributes @var{name}
20556@end smallexample
20557
20558List attributes of the specified variable object @var{name}:
20559
20560@smallexample
20561 status=@var{attr} [ ( ,@var{attr} )* ]
20562@end smallexample
20563
20564@noindent
20565where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
20566
20567@subheading The @code{-var-evaluate-expression} Command
20568@findex -var-evaluate-expression
20569
20570@subsubheading Synopsis
20571
20572@smallexample
20573 -var-evaluate-expression @var{name}
20574@end smallexample
20575
20576Evaluates the expression that is represented by the specified variable
20577object and returns its value as a string in the current format specified
20578for the object:
20579
20580@smallexample
20581 value=@var{value}
20582@end smallexample
20583
20584Note that one must invoke @code{-var-list-children} for a variable
20585before the value of a child variable can be evaluated.
20586
20587@subheading The @code{-var-assign} Command
20588@findex -var-assign
20589
20590@subsubheading Synopsis
20591
20592@smallexample
20593 -var-assign @var{name} @var{expression}
20594@end smallexample
20595
20596Assigns the value of @var{expression} to the variable object specified
20597by @var{name}. The object must be @samp{editable}. If the variable's
b383017d 20598value is altered by the assign, the variable will show up in any
922fbb7b
AC
20599subsequent @code{-var-update} list.
20600
20601@subsubheading Example
20602
20603@smallexample
20604(@value{GDBP})
20605-var-assign var1 3
20606^done,value="3"
20607(@value{GDBP})
20608-var-update *
20609^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
20610(@value{GDBP})
20611@end smallexample
20612
20613@subheading The @code{-var-update} Command
20614@findex -var-update
20615
20616@subsubheading Synopsis
20617
20618@smallexample
265eeb58 20619 -var-update [@var{print-values}] @{@var{name} | "*"@}
922fbb7b
AC
20620@end smallexample
20621
20622Update the value of the variable object @var{name} by evaluating its
20623expression after fetching all the new values from memory or registers.
265eeb58
NR
20624A @samp{*} causes all existing variable objects to be updated. The
20625option @var{print-values} determines whether names and values, or just
20626names are printed in the manner described for
20627@code{@pxref{-var-list-children}}.
20628
20629@subsubheading Example
922fbb7b 20630
265eeb58
NR
20631@smallexample
20632(@value{GDBP})
20633-var-assign var1 3
20634^done,value="3"
20635(@value{GDBP})
20636-var-update --all-values var1
20637^done,changelist=[@{name="var1",value="3",in_scope="true",
20638type_changed="false"@}]
20639(@value{GDBP})
20640@end smallexample
922fbb7b
AC
20641
20642@node Annotations
20643@chapter @value{GDBN} Annotations
20644
086432e2
AC
20645This chapter describes annotations in @value{GDBN}. Annotations were
20646designed to interface @value{GDBN} to graphical user interfaces or other
20647similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
20648relatively high level.
20649
086432e2
AC
20650The annotation mechanism has largely been superseeded by @sc{gdb/mi}
20651(@pxref{GDB/MI}).
20652
922fbb7b
AC
20653@ignore
20654This is Edition @value{EDITION}, @value{DATE}.
20655@end ignore
20656
20657@menu
20658* Annotations Overview:: What annotations are; the general syntax.
922fbb7b
AC
20659* Prompting:: Annotations marking @value{GDBN}'s need for input.
20660* Errors:: Annotations for error messages.
922fbb7b
AC
20661* Invalidation:: Some annotations describe things now invalid.
20662* Annotations for Running::
20663 Whether the program is running, how it stopped, etc.
20664* Source Annotations:: Annotations describing source code.
922fbb7b
AC
20665@end menu
20666
20667@node Annotations Overview
20668@section What is an Annotation?
20669@cindex annotations
20670
922fbb7b
AC
20671Annotations start with a newline character, two @samp{control-z}
20672characters, and the name of the annotation. If there is no additional
20673information associated with this annotation, the name of the annotation
20674is followed immediately by a newline. If there is additional
20675information, the name of the annotation is followed by a space, the
20676additional information, and a newline. The additional information
20677cannot contain newline characters.
20678
20679Any output not beginning with a newline and two @samp{control-z}
20680characters denotes literal output from @value{GDBN}. Currently there is
20681no need for @value{GDBN} to output a newline followed by two
20682@samp{control-z} characters, but if there was such a need, the
20683annotations could be extended with an @samp{escape} annotation which
20684means those three characters as output.
20685
086432e2
AC
20686The annotation @var{level}, which is specified using the
20687@option{--annotate} command line option (@pxref{Mode Options}), controls
20688how much information @value{GDBN} prints together with its prompt,
20689values of expressions, source lines, and other types of output. Level 0
20690is for no anntations, level 1 is for use when @value{GDBN} is run as a
20691subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
20692for programs that control @value{GDBN}, and level 2 annotations have
20693been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
20694Interface, annotate, GDB's Obsolete Annotations}).
20695
20696@table @code
20697@kindex set annotate
20698@item set annotate @var{level}
e09f16f9 20699The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 20700annotations to the specified @var{level}.
9c16f35a
EZ
20701
20702@item show annotate
20703@kindex show annotate
20704Show the current annotation level.
09d4efe1
EZ
20705@end table
20706
20707This chapter describes level 3 annotations.
086432e2 20708
922fbb7b
AC
20709A simple example of starting up @value{GDBN} with annotations is:
20710
20711@smallexample
086432e2
AC
20712$ @kbd{gdb --annotate=3}
20713GNU gdb 6.0
20714Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
20715GDB is free software, covered by the GNU General Public License,
20716and you are welcome to change it and/or distribute copies of it
20717under certain conditions.
20718Type "show copying" to see the conditions.
20719There is absolutely no warranty for GDB. Type "show warranty"
20720for details.
086432e2 20721This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
20722
20723^Z^Zpre-prompt
f7dc1244 20724(@value{GDBP})
922fbb7b 20725^Z^Zprompt
086432e2 20726@kbd{quit}
922fbb7b
AC
20727
20728^Z^Zpost-prompt
b383017d 20729$
922fbb7b
AC
20730@end smallexample
20731
20732Here @samp{quit} is input to @value{GDBN}; the rest is output from
20733@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
20734denotes a @samp{control-z} character) are annotations; the rest is
20735output from @value{GDBN}.
20736
922fbb7b
AC
20737@node Prompting
20738@section Annotation for @value{GDBN} Input
20739
20740@cindex annotations for prompts
20741When @value{GDBN} prompts for input, it annotates this fact so it is possible
20742to know when to send output, when the output from a given command is
20743over, etc.
20744
20745Different kinds of input each have a different @dfn{input type}. Each
20746input type has three annotations: a @code{pre-} annotation, which
20747denotes the beginning of any prompt which is being output, a plain
20748annotation, which denotes the end of the prompt, and then a @code{post-}
20749annotation which denotes the end of any echo which may (or may not) be
20750associated with the input. For example, the @code{prompt} input type
20751features the following annotations:
20752
20753@smallexample
20754^Z^Zpre-prompt
20755^Z^Zprompt
20756^Z^Zpost-prompt
20757@end smallexample
20758
20759The input types are
20760
20761@table @code
20762@findex pre-prompt
20763@findex prompt
20764@findex post-prompt
20765@item prompt
20766When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
20767
20768@findex pre-commands
20769@findex commands
20770@findex post-commands
20771@item commands
20772When @value{GDBN} prompts for a set of commands, like in the @code{commands}
20773command. The annotations are repeated for each command which is input.
20774
20775@findex pre-overload-choice
20776@findex overload-choice
20777@findex post-overload-choice
20778@item overload-choice
20779When @value{GDBN} wants the user to select between various overloaded functions.
20780
20781@findex pre-query
20782@findex query
20783@findex post-query
20784@item query
20785When @value{GDBN} wants the user to confirm a potentially dangerous operation.
20786
20787@findex pre-prompt-for-continue
20788@findex prompt-for-continue
20789@findex post-prompt-for-continue
20790@item prompt-for-continue
20791When @value{GDBN} is asking the user to press return to continue. Note: Don't
20792expect this to work well; instead use @code{set height 0} to disable
20793prompting. This is because the counting of lines is buggy in the
20794presence of annotations.
20795@end table
20796
20797@node Errors
20798@section Errors
20799@cindex annotations for errors, warnings and interrupts
20800
20801@findex quit
20802@smallexample
20803^Z^Zquit
20804@end smallexample
20805
20806This annotation occurs right before @value{GDBN} responds to an interrupt.
20807
20808@findex error
20809@smallexample
20810^Z^Zerror
20811@end smallexample
20812
20813This annotation occurs right before @value{GDBN} responds to an error.
20814
20815Quit and error annotations indicate that any annotations which @value{GDBN} was
20816in the middle of may end abruptly. For example, if a
20817@code{value-history-begin} annotation is followed by a @code{error}, one
20818cannot expect to receive the matching @code{value-history-end}. One
20819cannot expect not to receive it either, however; an error annotation
20820does not necessarily mean that @value{GDBN} is immediately returning all the way
20821to the top level.
20822
20823@findex error-begin
20824A quit or error annotation may be preceded by
20825
20826@smallexample
20827^Z^Zerror-begin
20828@end smallexample
20829
20830Any output between that and the quit or error annotation is the error
20831message.
20832
20833Warning messages are not yet annotated.
20834@c If we want to change that, need to fix warning(), type_error(),
20835@c range_error(), and possibly other places.
20836
922fbb7b
AC
20837@node Invalidation
20838@section Invalidation Notices
20839
20840@cindex annotations for invalidation messages
20841The following annotations say that certain pieces of state may have
20842changed.
20843
20844@table @code
20845@findex frames-invalid
20846@item ^Z^Zframes-invalid
20847
20848The frames (for example, output from the @code{backtrace} command) may
20849have changed.
20850
20851@findex breakpoints-invalid
20852@item ^Z^Zbreakpoints-invalid
20853
20854The breakpoints may have changed. For example, the user just added or
20855deleted a breakpoint.
20856@end table
20857
20858@node Annotations for Running
20859@section Running the Program
20860@cindex annotations for running programs
20861
20862@findex starting
20863@findex stopping
20864When the program starts executing due to a @value{GDBN} command such as
b383017d 20865@code{step} or @code{continue},
922fbb7b
AC
20866
20867@smallexample
20868^Z^Zstarting
20869@end smallexample
20870
b383017d 20871is output. When the program stops,
922fbb7b
AC
20872
20873@smallexample
20874^Z^Zstopped
20875@end smallexample
20876
20877is output. Before the @code{stopped} annotation, a variety of
20878annotations describe how the program stopped.
20879
20880@table @code
20881@findex exited
20882@item ^Z^Zexited @var{exit-status}
20883The program exited, and @var{exit-status} is the exit status (zero for
20884successful exit, otherwise nonzero).
20885
20886@findex signalled
20887@findex signal-name
20888@findex signal-name-end
20889@findex signal-string
20890@findex signal-string-end
20891@item ^Z^Zsignalled
20892The program exited with a signal. After the @code{^Z^Zsignalled}, the
20893annotation continues:
20894
20895@smallexample
20896@var{intro-text}
20897^Z^Zsignal-name
20898@var{name}
20899^Z^Zsignal-name-end
20900@var{middle-text}
20901^Z^Zsignal-string
20902@var{string}
20903^Z^Zsignal-string-end
20904@var{end-text}
20905@end smallexample
20906
20907@noindent
20908where @var{name} is the name of the signal, such as @code{SIGILL} or
20909@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
20910as @code{Illegal Instruction} or @code{Segmentation fault}.
20911@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
20912user's benefit and have no particular format.
20913
20914@findex signal
20915@item ^Z^Zsignal
20916The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
20917just saying that the program received the signal, not that it was
20918terminated with it.
20919
20920@findex breakpoint
20921@item ^Z^Zbreakpoint @var{number}
20922The program hit breakpoint number @var{number}.
20923
20924@findex watchpoint
20925@item ^Z^Zwatchpoint @var{number}
20926The program hit watchpoint number @var{number}.
20927@end table
20928
20929@node Source Annotations
20930@section Displaying Source
20931@cindex annotations for source display
20932
20933@findex source
20934The following annotation is used instead of displaying source code:
20935
20936@smallexample
20937^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
20938@end smallexample
20939
20940where @var{filename} is an absolute file name indicating which source
20941file, @var{line} is the line number within that file (where 1 is the
20942first line in the file), @var{character} is the character position
20943within the file (where 0 is the first character in the file) (for most
20944debug formats this will necessarily point to the beginning of a line),
20945@var{middle} is @samp{middle} if @var{addr} is in the middle of the
20946line, or @samp{beg} if @var{addr} is at the beginning of the line, and
20947@var{addr} is the address in the target program associated with the
20948source which is being displayed. @var{addr} is in the form @samp{0x}
20949followed by one or more lowercase hex digits (note that this does not
20950depend on the language).
20951
8e04817f
AC
20952@node GDB Bugs
20953@chapter Reporting Bugs in @value{GDBN}
20954@cindex bugs in @value{GDBN}
20955@cindex reporting bugs in @value{GDBN}
c906108c 20956
8e04817f 20957Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 20958
8e04817f
AC
20959Reporting a bug may help you by bringing a solution to your problem, or it
20960may not. But in any case the principal function of a bug report is to help
20961the entire community by making the next version of @value{GDBN} work better. Bug
20962reports are your contribution to the maintenance of @value{GDBN}.
c906108c 20963
8e04817f
AC
20964In order for a bug report to serve its purpose, you must include the
20965information that enables us to fix the bug.
c4555f82
SC
20966
20967@menu
8e04817f
AC
20968* Bug Criteria:: Have you found a bug?
20969* Bug Reporting:: How to report bugs
c4555f82
SC
20970@end menu
20971
8e04817f
AC
20972@node Bug Criteria
20973@section Have you found a bug?
20974@cindex bug criteria
c4555f82 20975
8e04817f 20976If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
20977
20978@itemize @bullet
8e04817f
AC
20979@cindex fatal signal
20980@cindex debugger crash
20981@cindex crash of debugger
c4555f82 20982@item
8e04817f
AC
20983If the debugger gets a fatal signal, for any input whatever, that is a
20984@value{GDBN} bug. Reliable debuggers never crash.
20985
20986@cindex error on valid input
20987@item
20988If @value{GDBN} produces an error message for valid input, that is a
20989bug. (Note that if you're cross debugging, the problem may also be
20990somewhere in the connection to the target.)
c4555f82 20991
8e04817f 20992@cindex invalid input
c4555f82 20993@item
8e04817f
AC
20994If @value{GDBN} does not produce an error message for invalid input,
20995that is a bug. However, you should note that your idea of
20996``invalid input'' might be our idea of ``an extension'' or ``support
20997for traditional practice''.
20998
20999@item
21000If you are an experienced user of debugging tools, your suggestions
21001for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
21002@end itemize
21003
8e04817f
AC
21004@node Bug Reporting
21005@section How to report bugs
21006@cindex bug reports
21007@cindex @value{GDBN} bugs, reporting
21008
21009A number of companies and individuals offer support for @sc{gnu} products.
21010If you obtained @value{GDBN} from a support organization, we recommend you
21011contact that organization first.
21012
21013You can find contact information for many support companies and
21014individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
21015distribution.
21016@c should add a web page ref...
21017
129188f6
AC
21018In any event, we also recommend that you submit bug reports for
21019@value{GDBN}. The prefered method is to submit them directly using
21020@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
21021page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
21022be used.
8e04817f
AC
21023
21024@strong{Do not send bug reports to @samp{info-gdb}, or to
21025@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
21026not want to receive bug reports. Those that do have arranged to receive
21027@samp{bug-gdb}.
21028
21029The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
21030serves as a repeater. The mailing list and the newsgroup carry exactly
21031the same messages. Often people think of posting bug reports to the
21032newsgroup instead of mailing them. This appears to work, but it has one
21033problem which can be crucial: a newsgroup posting often lacks a mail
21034path back to the sender. Thus, if we need to ask for more information,
21035we may be unable to reach you. For this reason, it is better to send
21036bug reports to the mailing list.
c4555f82 21037
8e04817f
AC
21038The fundamental principle of reporting bugs usefully is this:
21039@strong{report all the facts}. If you are not sure whether to state a
21040fact or leave it out, state it!
c4555f82 21041
8e04817f
AC
21042Often people omit facts because they think they know what causes the
21043problem and assume that some details do not matter. Thus, you might
21044assume that the name of the variable you use in an example does not matter.
21045Well, probably it does not, but one cannot be sure. Perhaps the bug is a
21046stray memory reference which happens to fetch from the location where that
21047name is stored in memory; perhaps, if the name were different, the contents
21048of that location would fool the debugger into doing the right thing despite
21049the bug. Play it safe and give a specific, complete example. That is the
21050easiest thing for you to do, and the most helpful.
c4555f82 21051
8e04817f
AC
21052Keep in mind that the purpose of a bug report is to enable us to fix the
21053bug. It may be that the bug has been reported previously, but neither
21054you nor we can know that unless your bug report is complete and
21055self-contained.
c4555f82 21056
8e04817f
AC
21057Sometimes people give a few sketchy facts and ask, ``Does this ring a
21058bell?'' Those bug reports are useless, and we urge everyone to
21059@emph{refuse to respond to them} except to chide the sender to report
21060bugs properly.
21061
21062To enable us to fix the bug, you should include all these things:
c4555f82
SC
21063
21064@itemize @bullet
21065@item
8e04817f
AC
21066The version of @value{GDBN}. @value{GDBN} announces it if you start
21067with no arguments; you can also print it at any time using @code{show
21068version}.
c4555f82 21069
8e04817f
AC
21070Without this, we will not know whether there is any point in looking for
21071the bug in the current version of @value{GDBN}.
c4555f82
SC
21072
21073@item
8e04817f
AC
21074The type of machine you are using, and the operating system name and
21075version number.
c4555f82
SC
21076
21077@item
8e04817f
AC
21078What compiler (and its version) was used to compile @value{GDBN}---e.g.
21079``@value{GCC}--2.8.1''.
c4555f82
SC
21080
21081@item
8e04817f
AC
21082What compiler (and its version) was used to compile the program you are
21083debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
21084C Compiler''. For GCC, you can say @code{gcc --version} to get this
21085information; for other compilers, see the documentation for those
21086compilers.
c4555f82 21087
8e04817f
AC
21088@item
21089The command arguments you gave the compiler to compile your example and
21090observe the bug. For example, did you use @samp{-O}? To guarantee
21091you will not omit something important, list them all. A copy of the
21092Makefile (or the output from make) is sufficient.
c4555f82 21093
8e04817f
AC
21094If we were to try to guess the arguments, we would probably guess wrong
21095and then we might not encounter the bug.
c4555f82 21096
8e04817f
AC
21097@item
21098A complete input script, and all necessary source files, that will
21099reproduce the bug.
c4555f82 21100
8e04817f
AC
21101@item
21102A description of what behavior you observe that you believe is
21103incorrect. For example, ``It gets a fatal signal.''
c4555f82 21104
8e04817f
AC
21105Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
21106will certainly notice it. But if the bug is incorrect output, we might
21107not notice unless it is glaringly wrong. You might as well not give us
21108a chance to make a mistake.
c4555f82 21109
8e04817f
AC
21110Even if the problem you experience is a fatal signal, you should still
21111say so explicitly. Suppose something strange is going on, such as, your
21112copy of @value{GDBN} is out of synch, or you have encountered a bug in
21113the C library on your system. (This has happened!) Your copy might
21114crash and ours would not. If you told us to expect a crash, then when
21115ours fails to crash, we would know that the bug was not happening for
21116us. If you had not told us to expect a crash, then we would not be able
21117to draw any conclusion from our observations.
c4555f82 21118
e0c07bf0
MC
21119@pindex script
21120@cindex recording a session script
21121To collect all this information, you can use a session recording program
21122such as @command{script}, which is available on many Unix systems.
21123Just run your @value{GDBN} session inside @command{script} and then
21124include the @file{typescript} file with your bug report.
21125
21126Another way to record a @value{GDBN} session is to run @value{GDBN}
21127inside Emacs and then save the entire buffer to a file.
21128
8e04817f
AC
21129@item
21130If you wish to suggest changes to the @value{GDBN} source, send us context
21131diffs. If you even discuss something in the @value{GDBN} source, refer to
21132it by context, not by line number.
c4555f82 21133
8e04817f
AC
21134The line numbers in our development sources will not match those in your
21135sources. Your line numbers would convey no useful information to us.
c4555f82 21136
8e04817f 21137@end itemize
c4555f82 21138
8e04817f 21139Here are some things that are not necessary:
c4555f82 21140
8e04817f
AC
21141@itemize @bullet
21142@item
21143A description of the envelope of the bug.
c4555f82 21144
8e04817f
AC
21145Often people who encounter a bug spend a lot of time investigating
21146which changes to the input file will make the bug go away and which
21147changes will not affect it.
c4555f82 21148
8e04817f
AC
21149This is often time consuming and not very useful, because the way we
21150will find the bug is by running a single example under the debugger
21151with breakpoints, not by pure deduction from a series of examples.
21152We recommend that you save your time for something else.
c4555f82 21153
8e04817f
AC
21154Of course, if you can find a simpler example to report @emph{instead}
21155of the original one, that is a convenience for us. Errors in the
21156output will be easier to spot, running under the debugger will take
21157less time, and so on.
c4555f82 21158
8e04817f
AC
21159However, simplification is not vital; if you do not want to do this,
21160report the bug anyway and send us the entire test case you used.
c4555f82 21161
8e04817f
AC
21162@item
21163A patch for the bug.
c4555f82 21164
8e04817f
AC
21165A patch for the bug does help us if it is a good one. But do not omit
21166the necessary information, such as the test case, on the assumption that
21167a patch is all we need. We might see problems with your patch and decide
21168to fix the problem another way, or we might not understand it at all.
c4555f82 21169
8e04817f
AC
21170Sometimes with a program as complicated as @value{GDBN} it is very hard to
21171construct an example that will make the program follow a certain path
21172through the code. If you do not send us the example, we will not be able
21173to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 21174
8e04817f
AC
21175And if we cannot understand what bug you are trying to fix, or why your
21176patch should be an improvement, we will not install it. A test case will
21177help us to understand.
c4555f82 21178
8e04817f
AC
21179@item
21180A guess about what the bug is or what it depends on.
c4555f82 21181
8e04817f
AC
21182Such guesses are usually wrong. Even we cannot guess right about such
21183things without first using the debugger to find the facts.
21184@end itemize
c4555f82 21185
8e04817f
AC
21186@c The readline documentation is distributed with the readline code
21187@c and consists of the two following files:
21188@c rluser.texinfo
21189@c inc-hist.texinfo
21190@c Use -I with makeinfo to point to the appropriate directory,
21191@c environment var TEXINPUTS with TeX.
21192@include rluser.texinfo
21193@include inc-hist.texinfo
c4555f82 21194
c4555f82 21195
8e04817f
AC
21196@node Formatting Documentation
21197@appendix Formatting Documentation
c4555f82 21198
8e04817f
AC
21199@cindex @value{GDBN} reference card
21200@cindex reference card
21201The @value{GDBN} 4 release includes an already-formatted reference card, ready
21202for printing with PostScript or Ghostscript, in the @file{gdb}
21203subdirectory of the main source directory@footnote{In
21204@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
21205release.}. If you can use PostScript or Ghostscript with your printer,
21206you can print the reference card immediately with @file{refcard.ps}.
c4555f82 21207
8e04817f
AC
21208The release also includes the source for the reference card. You
21209can format it, using @TeX{}, by typing:
c4555f82 21210
474c8240 21211@smallexample
8e04817f 21212make refcard.dvi
474c8240 21213@end smallexample
c4555f82 21214
8e04817f
AC
21215The @value{GDBN} reference card is designed to print in @dfn{landscape}
21216mode on US ``letter'' size paper;
21217that is, on a sheet 11 inches wide by 8.5 inches
21218high. You will need to specify this form of printing as an option to
21219your @sc{dvi} output program.
c4555f82 21220
8e04817f 21221@cindex documentation
c4555f82 21222
8e04817f
AC
21223All the documentation for @value{GDBN} comes as part of the machine-readable
21224distribution. The documentation is written in Texinfo format, which is
21225a documentation system that uses a single source file to produce both
21226on-line information and a printed manual. You can use one of the Info
21227formatting commands to create the on-line version of the documentation
21228and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 21229
8e04817f
AC
21230@value{GDBN} includes an already formatted copy of the on-line Info
21231version of this manual in the @file{gdb} subdirectory. The main Info
21232file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
21233subordinate files matching @samp{gdb.info*} in the same directory. If
21234necessary, you can print out these files, or read them with any editor;
21235but they are easier to read using the @code{info} subsystem in @sc{gnu}
21236Emacs or the standalone @code{info} program, available as part of the
21237@sc{gnu} Texinfo distribution.
c4555f82 21238
8e04817f
AC
21239If you want to format these Info files yourself, you need one of the
21240Info formatting programs, such as @code{texinfo-format-buffer} or
21241@code{makeinfo}.
c4555f82 21242
8e04817f
AC
21243If you have @code{makeinfo} installed, and are in the top level
21244@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
21245version @value{GDBVN}), you can make the Info file by typing:
c4555f82 21246
474c8240 21247@smallexample
8e04817f
AC
21248cd gdb
21249make gdb.info
474c8240 21250@end smallexample
c4555f82 21251
8e04817f
AC
21252If you want to typeset and print copies of this manual, you need @TeX{},
21253a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
21254Texinfo definitions file.
c4555f82 21255
8e04817f
AC
21256@TeX{} is a typesetting program; it does not print files directly, but
21257produces output files called @sc{dvi} files. To print a typeset
21258document, you need a program to print @sc{dvi} files. If your system
21259has @TeX{} installed, chances are it has such a program. The precise
21260command to use depends on your system; @kbd{lpr -d} is common; another
21261(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
21262require a file name without any extension or a @samp{.dvi} extension.
c4555f82 21263
8e04817f
AC
21264@TeX{} also requires a macro definitions file called
21265@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
21266written in Texinfo format. On its own, @TeX{} cannot either read or
21267typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
21268and is located in the @file{gdb-@var{version-number}/texinfo}
21269directory.
c4555f82 21270
8e04817f
AC
21271If you have @TeX{} and a @sc{dvi} printer program installed, you can
21272typeset and print this manual. First switch to the the @file{gdb}
21273subdirectory of the main source directory (for example, to
21274@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 21275
474c8240 21276@smallexample
8e04817f 21277make gdb.dvi
474c8240 21278@end smallexample
c4555f82 21279
8e04817f 21280Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 21281
8e04817f
AC
21282@node Installing GDB
21283@appendix Installing @value{GDBN}
21284@cindex configuring @value{GDBN}
21285@cindex installation
94e91d6d 21286@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 21287
8e04817f
AC
21288@value{GDBN} comes with a @code{configure} script that automates the process
21289of preparing @value{GDBN} for installation; you can then use @code{make} to
21290build the @code{gdb} program.
21291@iftex
21292@c irrelevant in info file; it's as current as the code it lives with.
21293@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
21294look at the @file{README} file in the sources; we may have improved the
21295installation procedures since publishing this manual.}
21296@end iftex
c4555f82 21297
8e04817f
AC
21298The @value{GDBN} distribution includes all the source code you need for
21299@value{GDBN} in a single directory, whose name is usually composed by
21300appending the version number to @samp{gdb}.
c4555f82 21301
8e04817f
AC
21302For example, the @value{GDBN} version @value{GDBVN} distribution is in the
21303@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 21304
8e04817f
AC
21305@table @code
21306@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
21307script for configuring @value{GDBN} and all its supporting libraries
c4555f82 21308
8e04817f
AC
21309@item gdb-@value{GDBVN}/gdb
21310the source specific to @value{GDBN} itself
c4555f82 21311
8e04817f
AC
21312@item gdb-@value{GDBVN}/bfd
21313source for the Binary File Descriptor library
c906108c 21314
8e04817f
AC
21315@item gdb-@value{GDBVN}/include
21316@sc{gnu} include files
c906108c 21317
8e04817f
AC
21318@item gdb-@value{GDBVN}/libiberty
21319source for the @samp{-liberty} free software library
c906108c 21320
8e04817f
AC
21321@item gdb-@value{GDBVN}/opcodes
21322source for the library of opcode tables and disassemblers
c906108c 21323
8e04817f
AC
21324@item gdb-@value{GDBVN}/readline
21325source for the @sc{gnu} command-line interface
c906108c 21326
8e04817f
AC
21327@item gdb-@value{GDBVN}/glob
21328source for the @sc{gnu} filename pattern-matching subroutine
c906108c 21329
8e04817f
AC
21330@item gdb-@value{GDBVN}/mmalloc
21331source for the @sc{gnu} memory-mapped malloc package
21332@end table
c906108c 21333
8e04817f
AC
21334The simplest way to configure and build @value{GDBN} is to run @code{configure}
21335from the @file{gdb-@var{version-number}} source directory, which in
21336this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 21337
8e04817f
AC
21338First switch to the @file{gdb-@var{version-number}} source directory
21339if you are not already in it; then run @code{configure}. Pass the
21340identifier for the platform on which @value{GDBN} will run as an
21341argument.
c906108c 21342
8e04817f 21343For example:
c906108c 21344
474c8240 21345@smallexample
8e04817f
AC
21346cd gdb-@value{GDBVN}
21347./configure @var{host}
21348make
474c8240 21349@end smallexample
c906108c 21350
8e04817f
AC
21351@noindent
21352where @var{host} is an identifier such as @samp{sun4} or
21353@samp{decstation}, that identifies the platform where @value{GDBN} will run.
21354(You can often leave off @var{host}; @code{configure} tries to guess the
21355correct value by examining your system.)
c906108c 21356
8e04817f
AC
21357Running @samp{configure @var{host}} and then running @code{make} builds the
21358@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
21359libraries, then @code{gdb} itself. The configured source files, and the
21360binaries, are left in the corresponding source directories.
c906108c 21361
8e04817f
AC
21362@need 750
21363@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
21364system does not recognize this automatically when you run a different
21365shell, you may need to run @code{sh} on it explicitly:
c906108c 21366
474c8240 21367@smallexample
8e04817f 21368sh configure @var{host}
474c8240 21369@end smallexample
c906108c 21370
8e04817f
AC
21371If you run @code{configure} from a directory that contains source
21372directories for multiple libraries or programs, such as the
21373@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
21374creates configuration files for every directory level underneath (unless
21375you tell it not to, with the @samp{--norecursion} option).
21376
94e91d6d
MC
21377You should run the @code{configure} script from the top directory in the
21378source tree, the @file{gdb-@var{version-number}} directory. If you run
21379@code{configure} from one of the subdirectories, you will configure only
21380that subdirectory. That is usually not what you want. In particular,
21381if you run the first @code{configure} from the @file{gdb} subdirectory
21382of the @file{gdb-@var{version-number}} directory, you will omit the
21383configuration of @file{bfd}, @file{readline}, and other sibling
21384directories of the @file{gdb} subdirectory. This leads to build errors
21385about missing include files such as @file{bfd/bfd.h}.
c906108c 21386
8e04817f
AC
21387You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
21388However, you should make sure that the shell on your path (named by
21389the @samp{SHELL} environment variable) is publicly readable. Remember
21390that @value{GDBN} uses the shell to start your program---some systems refuse to
21391let @value{GDBN} debug child processes whose programs are not readable.
c906108c 21392
8e04817f
AC
21393@menu
21394* Separate Objdir:: Compiling @value{GDBN} in another directory
21395* Config Names:: Specifying names for hosts and targets
21396* Configure Options:: Summary of options for configure
21397@end menu
c906108c 21398
8e04817f
AC
21399@node Separate Objdir
21400@section Compiling @value{GDBN} in another directory
c906108c 21401
8e04817f
AC
21402If you want to run @value{GDBN} versions for several host or target machines,
21403you need a different @code{gdb} compiled for each combination of
21404host and target. @code{configure} is designed to make this easy by
21405allowing you to generate each configuration in a separate subdirectory,
21406rather than in the source directory. If your @code{make} program
21407handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
21408@code{make} in each of these directories builds the @code{gdb}
21409program specified there.
c906108c 21410
8e04817f
AC
21411To build @code{gdb} in a separate directory, run @code{configure}
21412with the @samp{--srcdir} option to specify where to find the source.
21413(You also need to specify a path to find @code{configure}
21414itself from your working directory. If the path to @code{configure}
21415would be the same as the argument to @samp{--srcdir}, you can leave out
21416the @samp{--srcdir} option; it is assumed.)
c906108c 21417
8e04817f
AC
21418For example, with version @value{GDBVN}, you can build @value{GDBN} in a
21419separate directory for a Sun 4 like this:
c906108c 21420
474c8240 21421@smallexample
8e04817f
AC
21422@group
21423cd gdb-@value{GDBVN}
21424mkdir ../gdb-sun4
21425cd ../gdb-sun4
21426../gdb-@value{GDBVN}/configure sun4
21427make
21428@end group
474c8240 21429@end smallexample
c906108c 21430
8e04817f
AC
21431When @code{configure} builds a configuration using a remote source
21432directory, it creates a tree for the binaries with the same structure
21433(and using the same names) as the tree under the source directory. In
21434the example, you'd find the Sun 4 library @file{libiberty.a} in the
21435directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
21436@file{gdb-sun4/gdb}.
c906108c 21437
94e91d6d
MC
21438Make sure that your path to the @file{configure} script has just one
21439instance of @file{gdb} in it. If your path to @file{configure} looks
21440like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
21441one subdirectory of @value{GDBN}, not the whole package. This leads to
21442build errors about missing include files such as @file{bfd/bfd.h}.
21443
8e04817f
AC
21444One popular reason to build several @value{GDBN} configurations in separate
21445directories is to configure @value{GDBN} for cross-compiling (where
21446@value{GDBN} runs on one machine---the @dfn{host}---while debugging
21447programs that run on another machine---the @dfn{target}).
21448You specify a cross-debugging target by
21449giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 21450
8e04817f
AC
21451When you run @code{make} to build a program or library, you must run
21452it in a configured directory---whatever directory you were in when you
21453called @code{configure} (or one of its subdirectories).
c906108c 21454
8e04817f
AC
21455The @code{Makefile} that @code{configure} generates in each source
21456directory also runs recursively. If you type @code{make} in a source
21457directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
21458directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
21459will build all the required libraries, and then build GDB.
c906108c 21460
8e04817f
AC
21461When you have multiple hosts or targets configured in separate
21462directories, you can run @code{make} on them in parallel (for example,
21463if they are NFS-mounted on each of the hosts); they will not interfere
21464with each other.
c906108c 21465
8e04817f
AC
21466@node Config Names
21467@section Specifying names for hosts and targets
c906108c 21468
8e04817f
AC
21469The specifications used for hosts and targets in the @code{configure}
21470script are based on a three-part naming scheme, but some short predefined
21471aliases are also supported. The full naming scheme encodes three pieces
21472of information in the following pattern:
c906108c 21473
474c8240 21474@smallexample
8e04817f 21475@var{architecture}-@var{vendor}-@var{os}
474c8240 21476@end smallexample
c906108c 21477
8e04817f
AC
21478For example, you can use the alias @code{sun4} as a @var{host} argument,
21479or as the value for @var{target} in a @code{--target=@var{target}}
21480option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 21481
8e04817f
AC
21482The @code{configure} script accompanying @value{GDBN} does not provide
21483any query facility to list all supported host and target names or
21484aliases. @code{configure} calls the Bourne shell script
21485@code{config.sub} to map abbreviations to full names; you can read the
21486script, if you wish, or you can use it to test your guesses on
21487abbreviations---for example:
c906108c 21488
8e04817f
AC
21489@smallexample
21490% sh config.sub i386-linux
21491i386-pc-linux-gnu
21492% sh config.sub alpha-linux
21493alpha-unknown-linux-gnu
21494% sh config.sub hp9k700
21495hppa1.1-hp-hpux
21496% sh config.sub sun4
21497sparc-sun-sunos4.1.1
21498% sh config.sub sun3
21499m68k-sun-sunos4.1.1
21500% sh config.sub i986v
21501Invalid configuration `i986v': machine `i986v' not recognized
21502@end smallexample
c906108c 21503
8e04817f
AC
21504@noindent
21505@code{config.sub} is also distributed in the @value{GDBN} source
21506directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 21507
8e04817f
AC
21508@node Configure Options
21509@section @code{configure} options
c906108c 21510
8e04817f
AC
21511Here is a summary of the @code{configure} options and arguments that
21512are most often useful for building @value{GDBN}. @code{configure} also has
21513several other options not listed here. @inforef{What Configure
21514Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 21515
474c8240 21516@smallexample
8e04817f
AC
21517configure @r{[}--help@r{]}
21518 @r{[}--prefix=@var{dir}@r{]}
21519 @r{[}--exec-prefix=@var{dir}@r{]}
21520 @r{[}--srcdir=@var{dirname}@r{]}
21521 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
21522 @r{[}--target=@var{target}@r{]}
21523 @var{host}
474c8240 21524@end smallexample
c906108c 21525
8e04817f
AC
21526@noindent
21527You may introduce options with a single @samp{-} rather than
21528@samp{--} if you prefer; but you may abbreviate option names if you use
21529@samp{--}.
c906108c 21530
8e04817f
AC
21531@table @code
21532@item --help
21533Display a quick summary of how to invoke @code{configure}.
c906108c 21534
8e04817f
AC
21535@item --prefix=@var{dir}
21536Configure the source to install programs and files under directory
21537@file{@var{dir}}.
c906108c 21538
8e04817f
AC
21539@item --exec-prefix=@var{dir}
21540Configure the source to install programs under directory
21541@file{@var{dir}}.
c906108c 21542
8e04817f
AC
21543@c avoid splitting the warning from the explanation:
21544@need 2000
21545@item --srcdir=@var{dirname}
21546@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
21547@code{make} that implements the @code{VPATH} feature.}@*
21548Use this option to make configurations in directories separate from the
21549@value{GDBN} source directories. Among other things, you can use this to
21550build (or maintain) several configurations simultaneously, in separate
21551directories. @code{configure} writes configuration specific files in
21552the current directory, but arranges for them to use the source in the
21553directory @var{dirname}. @code{configure} creates directories under
21554the working directory in parallel to the source directories below
21555@var{dirname}.
c906108c 21556
8e04817f
AC
21557@item --norecursion
21558Configure only the directory level where @code{configure} is executed; do not
21559propagate configuration to subdirectories.
c906108c 21560
8e04817f
AC
21561@item --target=@var{target}
21562Configure @value{GDBN} for cross-debugging programs running on the specified
21563@var{target}. Without this option, @value{GDBN} is configured to debug
21564programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 21565
8e04817f 21566There is no convenient way to generate a list of all available targets.
c906108c 21567
8e04817f
AC
21568@item @var{host} @dots{}
21569Configure @value{GDBN} to run on the specified @var{host}.
c906108c 21570
8e04817f
AC
21571There is no convenient way to generate a list of all available hosts.
21572@end table
c906108c 21573
8e04817f
AC
21574There are many other options available as well, but they are generally
21575needed for special purposes only.
c906108c 21576
8e04817f
AC
21577@node Maintenance Commands
21578@appendix Maintenance Commands
21579@cindex maintenance commands
21580@cindex internal commands
c906108c 21581
8e04817f 21582In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
21583includes a number of commands intended for @value{GDBN} developers,
21584that are not documented elsewhere in this manual. These commands are
da316a69
EZ
21585provided here for reference. (For commands that turn on debugging
21586messages, see @ref{Debugging Output}.)
c906108c 21587
8e04817f 21588@table @code
09d4efe1
EZ
21589@kindex maint agent
21590@item maint agent @var{expression}
21591Translate the given @var{expression} into remote agent bytecodes.
21592This command is useful for debugging the Agent Expression mechanism
21593(@pxref{Agent Expressions}).
21594
8e04817f
AC
21595@kindex maint info breakpoints
21596@item @anchor{maint info breakpoints}maint info breakpoints
21597Using the same format as @samp{info breakpoints}, display both the
21598breakpoints you've set explicitly, and those @value{GDBN} is using for
21599internal purposes. Internal breakpoints are shown with negative
21600breakpoint numbers. The type column identifies what kind of breakpoint
21601is shown:
c906108c 21602
8e04817f
AC
21603@table @code
21604@item breakpoint
21605Normal, explicitly set breakpoint.
c906108c 21606
8e04817f
AC
21607@item watchpoint
21608Normal, explicitly set watchpoint.
c906108c 21609
8e04817f
AC
21610@item longjmp
21611Internal breakpoint, used to handle correctly stepping through
21612@code{longjmp} calls.
c906108c 21613
8e04817f
AC
21614@item longjmp resume
21615Internal breakpoint at the target of a @code{longjmp}.
c906108c 21616
8e04817f
AC
21617@item until
21618Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 21619
8e04817f
AC
21620@item finish
21621Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 21622
8e04817f
AC
21623@item shlib events
21624Shared library events.
c906108c 21625
8e04817f 21626@end table
c906108c 21627
09d4efe1
EZ
21628@kindex maint check-symtabs
21629@item maint check-symtabs
21630Check the consistency of psymtabs and symtabs.
21631
21632@kindex maint cplus first_component
21633@item maint cplus first_component @var{name}
21634Print the first C@t{++} class/namespace component of @var{name}.
21635
21636@kindex maint cplus namespace
21637@item maint cplus namespace
21638Print the list of possible C@t{++} namespaces.
21639
21640@kindex maint demangle
21641@item maint demangle @var{name}
21642Demangle a C@t{++} or Objective-C manled @var{name}.
21643
21644@kindex maint deprecate
21645@kindex maint undeprecate
21646@cindex deprecated commands
21647@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
21648@itemx maint undeprecate @var{command}
21649Deprecate or undeprecate the named @var{command}. Deprecated commands
21650cause @value{GDBN} to issue a warning when you use them. The optional
21651argument @var{replacement} says which newer command should be used in
21652favor of the deprecated one; if it is given, @value{GDBN} will mention
21653the replacement as part of the warning.
21654
21655@kindex maint dump-me
21656@item maint dump-me
721c2651 21657@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 21658Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
21659This is supported only on systems which support aborting a program
21660with the @code{SIGQUIT} signal.
09d4efe1 21661
8d30a00d
AC
21662@kindex maint internal-error
21663@kindex maint internal-warning
09d4efe1
EZ
21664@item maint internal-error @r{[}@var{message-text}@r{]}
21665@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
21666Cause @value{GDBN} to call the internal function @code{internal_error}
21667or @code{internal_warning} and hence behave as though an internal error
21668or internal warning has been detected. In addition to reporting the
21669internal problem, these functions give the user the opportunity to
21670either quit @value{GDBN} or create a core file of the current
21671@value{GDBN} session.
21672
09d4efe1
EZ
21673These commands take an optional parameter @var{message-text} that is
21674used as the text of the error or warning message.
21675
21676Here's an example of using @code{indernal-error}:
21677
8d30a00d 21678@smallexample
f7dc1244 21679(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
21680@dots{}/maint.c:121: internal-error: testing, 1, 2
21681A problem internal to GDB has been detected. Further
21682debugging may prove unreliable.
21683Quit this debugging session? (y or n) @kbd{n}
21684Create a core file? (y or n) @kbd{n}
f7dc1244 21685(@value{GDBP})
8d30a00d
AC
21686@end smallexample
21687
09d4efe1
EZ
21688@kindex maint packet
21689@item maint packet @var{text}
21690If @value{GDBN} is talking to an inferior via the serial protocol,
21691then this command sends the string @var{text} to the inferior, and
21692displays the response packet. @value{GDBN} supplies the initial
21693@samp{$} character, the terminating @samp{#} character, and the
21694checksum.
21695
21696@kindex maint print architecture
21697@item maint print architecture @r{[}@var{file}@r{]}
21698Print the entire architecture configuration. The optional argument
21699@var{file} names the file where the output goes.
8d30a00d 21700
00905d52
AC
21701@kindex maint print dummy-frames
21702@item maint print dummy-frames
00905d52
AC
21703Prints the contents of @value{GDBN}'s internal dummy-frame stack.
21704
21705@smallexample
f7dc1244 21706(@value{GDBP}) @kbd{b add}
00905d52 21707@dots{}
f7dc1244 21708(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
21709Breakpoint 2, add (a=2, b=3) at @dots{}
2171058 return (a + b);
21711The program being debugged stopped while in a function called from GDB.
21712@dots{}
f7dc1244 21713(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
217140x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
21715 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
21716 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 21717(@value{GDBP})
00905d52
AC
21718@end smallexample
21719
21720Takes an optional file parameter.
21721
0680b120
AC
21722@kindex maint print registers
21723@kindex maint print raw-registers
21724@kindex maint print cooked-registers
617073a9 21725@kindex maint print register-groups
09d4efe1
EZ
21726@item maint print registers @r{[}@var{file}@r{]}
21727@itemx maint print raw-registers @r{[}@var{file}@r{]}
21728@itemx maint print cooked-registers @r{[}@var{file}@r{]}
21729@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
21730Print @value{GDBN}'s internal register data structures.
21731
617073a9
AC
21732The command @code{maint print raw-registers} includes the contents of
21733the raw register cache; the command @code{maint print cooked-registers}
21734includes the (cooked) value of all registers; and the command
21735@code{maint print register-groups} includes the groups that each
21736register is a member of. @xref{Registers,, Registers, gdbint,
21737@value{GDBN} Internals}.
0680b120 21738
09d4efe1
EZ
21739These commands take an optional parameter, a file name to which to
21740write the information.
0680b120 21741
617073a9 21742@kindex maint print reggroups
09d4efe1
EZ
21743@item maint print reggroups @r{[}@var{file}@r{]}
21744Print @value{GDBN}'s internal register group data structures. The
21745optional argument @var{file} tells to what file to write the
21746information.
617073a9 21747
09d4efe1 21748The register groups info looks like this:
617073a9
AC
21749
21750@smallexample
f7dc1244 21751(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
21752 Group Type
21753 general user
21754 float user
21755 all user
21756 vector user
21757 system user
21758 save internal
21759 restore internal
617073a9
AC
21760@end smallexample
21761
09d4efe1
EZ
21762@kindex flushregs
21763@item flushregs
21764This command forces @value{GDBN} to flush its internal register cache.
21765
21766@kindex maint print objfiles
21767@cindex info for known object files
21768@item maint print objfiles
21769Print a dump of all known object files. For each object file, this
21770command prints its name, address in memory, and all of its psymtabs
21771and symtabs.
21772
21773@kindex maint print statistics
21774@cindex bcache statistics
21775@item maint print statistics
21776This command prints, for each object file in the program, various data
21777about that object file followed by the byte cache (@dfn{bcache})
21778statistics for the object file. The objfile data includes the number
21779of minimal, partical, full, and stabs symbols, the number of types
21780defined by the objfile, the number of as yet unexpanded psym tables,
21781the number of line tables and string tables, and the amount of memory
21782used by the various tables. The bcache statistics include the counts,
21783sizes, and counts of duplicates of all and unique objects, max,
21784average, and median entry size, total memory used and its overhead and
21785savings, and various measures of the hash table size and chain
21786lengths.
21787
21788@kindex maint print type
21789@cindex type chain of a data type
21790@item maint print type @var{expr}
21791Print the type chain for a type specified by @var{expr}. The argument
21792can be either a type name or a symbol. If it is a symbol, the type of
21793that symbol is described. The type chain produced by this command is
21794a recursive definition of the data type as stored in @value{GDBN}'s
21795data structures, including its flags and contained types.
21796
21797@kindex maint set dwarf2 max-cache-age
21798@kindex maint show dwarf2 max-cache-age
21799@item maint set dwarf2 max-cache-age
21800@itemx maint show dwarf2 max-cache-age
21801Control the DWARF 2 compilation unit cache.
21802
21803@cindex DWARF 2 compilation units cache
21804In object files with inter-compilation-unit references, such as those
21805produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
21806reader needs to frequently refer to previously read compilation units.
21807This setting controls how long a compilation unit will remain in the
21808cache if it is not referenced. A higher limit means that cached
21809compilation units will be stored in memory longer, and more total
21810memory will be used. Setting it to zero disables caching, which will
21811slow down @value{GDBN} startup, but reduce memory consumption.
21812
e7ba9c65
DJ
21813@kindex maint set profile
21814@kindex maint show profile
21815@cindex profiling GDB
21816@item maint set profile
21817@itemx maint show profile
21818Control profiling of @value{GDBN}.
21819
21820Profiling will be disabled until you use the @samp{maint set profile}
21821command to enable it. When you enable profiling, the system will begin
21822collecting timing and execution count data; when you disable profiling or
21823exit @value{GDBN}, the results will be written to a log file. Remember that
21824if you use profiling, @value{GDBN} will overwrite the profiling log file
21825(often called @file{gmon.out}). If you have a record of important profiling
21826data in a @file{gmon.out} file, be sure to move it to a safe location.
21827
21828Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 21829compiled with the @samp{-pg} compiler option.
e7ba9c65 21830
09d4efe1
EZ
21831@kindex maint show-debug-regs
21832@cindex x86 hardware debug registers
21833@item maint show-debug-regs
21834Control whether to show variables that mirror the x86 hardware debug
21835registers. Use @code{ON} to enable, @code{OFF} to disable. If
21836enabled, the debug registers values are shown when GDB inserts or
21837removes a hardware breakpoint or watchpoint, and when the inferior
21838triggers a hardware-assisted breakpoint or watchpoint.
21839
21840@kindex maint space
21841@cindex memory used by commands
21842@item maint space
21843Control whether to display memory usage for each command. If set to a
21844nonzero value, @value{GDBN} will display how much memory each command
21845took, following the command's own output. This can also be requested
21846by invoking @value{GDBN} with the @option{--statistics} command-line
21847switch (@pxref{Mode Options}).
21848
21849@kindex maint time
21850@cindex time of command execution
21851@item maint time
21852Control whether to display the execution time for each command. If
21853set to a nonzero value, @value{GDBN} will display how much time it
21854took to execute each command, following the command's own output.
21855This can also be requested by invoking @value{GDBN} with the
21856@option{--statistics} command-line switch (@pxref{Mode Options}).
21857
21858@kindex maint translate-address
21859@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
21860Find the symbol stored at the location specified by the address
21861@var{addr} and an optional section name @var{section}. If found,
21862@value{GDBN} prints the name of the closest symbol and an offset from
21863the symbol's location to the specified address. This is similar to
21864the @code{info address} command (@pxref{Symbols}), except that this
21865command also allows to find symbols in other sections.
ae038cb0 21866
8e04817f 21867@end table
c906108c 21868
9c16f35a
EZ
21869The following command is useful for non-interactive invocations of
21870@value{GDBN}, such as in the test suite.
21871
21872@table @code
21873@item set watchdog @var{nsec}
21874@kindex set watchdog
21875@cindex watchdog timer
21876@cindex timeout for commands
21877Set the maximum number of seconds @value{GDBN} will wait for the
21878target operation to finish. If this time expires, @value{GDBN}
21879reports and error and the command is aborted.
21880
21881@item show watchdog
21882Show the current setting of the target wait timeout.
21883@end table
c906108c 21884
e0ce93ac 21885@node Remote Protocol
8e04817f 21886@appendix @value{GDBN} Remote Serial Protocol
c906108c 21887
ee2d5c50
AC
21888@menu
21889* Overview::
21890* Packets::
21891* Stop Reply Packets::
21892* General Query Packets::
21893* Register Packet Format::
21894* Examples::
0ce1b118 21895* File-I/O remote protocol extension::
ee2d5c50
AC
21896@end menu
21897
21898@node Overview
21899@section Overview
21900
8e04817f
AC
21901There may be occasions when you need to know something about the
21902protocol---for example, if there is only one serial port to your target
21903machine, you might want your program to do something special if it
21904recognizes a packet meant for @value{GDBN}.
c906108c 21905
d2c6833e 21906In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 21907transmitted and received data respectfully.
c906108c 21908
8e04817f
AC
21909@cindex protocol, @value{GDBN} remote serial
21910@cindex serial protocol, @value{GDBN} remote
21911@cindex remote serial protocol
21912All @value{GDBN} commands and responses (other than acknowledgments) are
21913sent as a @var{packet}. A @var{packet} is introduced with the character
21914@samp{$}, the actual @var{packet-data}, and the terminating character
21915@samp{#} followed by a two-digit @var{checksum}:
c906108c 21916
474c8240 21917@smallexample
8e04817f 21918@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 21919@end smallexample
8e04817f 21920@noindent
c906108c 21921
8e04817f
AC
21922@cindex checksum, for @value{GDBN} remote
21923@noindent
21924The two-digit @var{checksum} is computed as the modulo 256 sum of all
21925characters between the leading @samp{$} and the trailing @samp{#} (an
21926eight bit unsigned checksum).
c906108c 21927
8e04817f
AC
21928Implementors should note that prior to @value{GDBN} 5.0 the protocol
21929specification also included an optional two-digit @var{sequence-id}:
c906108c 21930
474c8240 21931@smallexample
8e04817f 21932@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 21933@end smallexample
c906108c 21934
8e04817f
AC
21935@cindex sequence-id, for @value{GDBN} remote
21936@noindent
21937That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
21938has never output @var{sequence-id}s. Stubs that handle packets added
21939since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 21940
8e04817f
AC
21941@cindex acknowledgment, for @value{GDBN} remote
21942When either the host or the target machine receives a packet, the first
21943response expected is an acknowledgment: either @samp{+} (to indicate
21944the package was received correctly) or @samp{-} (to request
21945retransmission):
c906108c 21946
474c8240 21947@smallexample
d2c6833e
AC
21948-> @code{$}@var{packet-data}@code{#}@var{checksum}
21949<- @code{+}
474c8240 21950@end smallexample
8e04817f 21951@noindent
53a5351d 21952
8e04817f
AC
21953The host (@value{GDBN}) sends @var{command}s, and the target (the
21954debugging stub incorporated in your program) sends a @var{response}. In
21955the case of step and continue @var{command}s, the response is only sent
21956when the operation has completed (the target has again stopped).
c906108c 21957
8e04817f
AC
21958@var{packet-data} consists of a sequence of characters with the
21959exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
21960exceptions).
c906108c 21961
8e04817f 21962Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 21963@cindex remote protocol, field separator
8e04817f 21964@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 21965@sc{hex} with leading zeros suppressed.
c906108c 21966
8e04817f
AC
21967Implementors should note that prior to @value{GDBN} 5.0, the character
21968@samp{:} could not appear as the third character in a packet (as it
21969would potentially conflict with the @var{sequence-id}).
c906108c 21970
8e04817f
AC
21971Response @var{data} can be run-length encoded to save space. A @samp{*}
21972means that the next character is an @sc{ascii} encoding giving a repeat count
21973which stands for that many repetitions of the character preceding the
21974@samp{*}. The encoding is @code{n+29}, yielding a printable character
21975where @code{n >=3} (which is where rle starts to win). The printable
21976characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
21977value greater than 126 should not be used.
c906108c 21978
8e04817f 21979So:
474c8240 21980@smallexample
8e04817f 21981"@code{0* }"
474c8240 21982@end smallexample
8e04817f
AC
21983@noindent
21984means the same as "0000".
c906108c 21985
8e04817f
AC
21986The error response returned for some packets includes a two character
21987error number. That number is not well defined.
c906108c 21988
8e04817f
AC
21989For any @var{command} not supported by the stub, an empty response
21990(@samp{$#00}) should be returned. That way it is possible to extend the
21991protocol. A newer @value{GDBN} can tell if a packet is supported based
21992on that response.
c906108c 21993
b383017d
RM
21994A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
21995@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 21996optional.
c906108c 21997
ee2d5c50
AC
21998@node Packets
21999@section Packets
22000
22001The following table provides a complete list of all currently defined
22002@var{command}s and their corresponding response @var{data}.
9c16f35a
EZ
22003@xref{File-I/O remote protocol extension}, for details about the File
22004I/O extension of the remote protocol.
ee2d5c50
AC
22005
22006@table @r
22007
22008@item @code{!} --- extended mode
22009@cindex @code{!} packet
22010
8e04817f
AC
22011Enable extended mode. In extended mode, the remote server is made
22012persistent. The @samp{R} packet is used to restart the program being
22013debugged.
ee2d5c50
AC
22014
22015Reply:
22016@table @samp
22017@item OK
8e04817f 22018The remote target both supports and has enabled extended mode.
ee2d5c50 22019@end table
c906108c 22020
ee2d5c50
AC
22021@item @code{?} --- last signal
22022@cindex @code{?} packet
c906108c 22023
ee2d5c50
AC
22024Indicate the reason the target halted. The reply is the same as for
22025step and continue.
c906108c 22026
ee2d5c50
AC
22027Reply:
22028@xref{Stop Reply Packets}, for the reply specifications.
22029
22030@item @code{a} --- reserved
22031
22032Reserved for future use.
22033
22034@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
22035@cindex @code{A} packet
c906108c 22036
8e04817f
AC
22037Initialized @samp{argv[]} array passed into program. @var{arglen}
22038specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
22039See @code{gdbserver} for more details.
22040
22041Reply:
22042@table @samp
22043@item OK
22044@item E@var{NN}
22045@end table
22046
22047@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
22048@cindex @code{b} packet
22049
22050Change the serial line speed to @var{baud}.
22051
22052JTC: @emph{When does the transport layer state change? When it's
22053received, or after the ACK is transmitted. In either case, there are
22054problems if the command or the acknowledgment packet is dropped.}
22055
22056Stan: @emph{If people really wanted to add something like this, and get
22057it working for the first time, they ought to modify ser-unix.c to send
22058some kind of out-of-band message to a specially-setup stub and have the
22059switch happen "in between" packets, so that from remote protocol's point
22060of view, nothing actually happened.}
22061
22062@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
22063@cindex @code{B} packet
22064
8e04817f 22065Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
22066breakpoint at @var{addr}.
22067
22068This packet has been replaced by the @samp{Z} and @samp{z} packets
22069(@pxref{insert breakpoint or watchpoint packet}).
c906108c 22070
ee2d5c50
AC
22071@item @code{c}@var{addr} --- continue
22072@cindex @code{c} packet
22073
22074@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 22075current address.
c906108c 22076
ee2d5c50
AC
22077Reply:
22078@xref{Stop Reply Packets}, for the reply specifications.
22079
22080@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
22081@cindex @code{C} packet
22082
8e04817f
AC
22083Continue with signal @var{sig} (hex signal number). If
22084@code{;}@var{addr} is omitted, resume at same address.
c906108c 22085
ee2d5c50
AC
22086Reply:
22087@xref{Stop Reply Packets}, for the reply specifications.
c906108c 22088
ee2d5c50
AC
22089@item @code{d} --- toggle debug @strong{(deprecated)}
22090@cindex @code{d} packet
22091
22092Toggle debug flag.
22093
22094@item @code{D} --- detach
22095@cindex @code{D} packet
22096
22097Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 22098before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
22099
22100Reply:
22101@table @samp
10fac096
NW
22102@item OK
22103for success
22104@item E@var{NN}
22105for an error
ee2d5c50 22106@end table
c906108c 22107
ee2d5c50 22108@item @code{e} --- reserved
c906108c 22109
ee2d5c50 22110Reserved for future use.
c906108c 22111
ee2d5c50 22112@item @code{E} --- reserved
c906108c 22113
ee2d5c50 22114Reserved for future use.
c906108c 22115
ee2d5c50
AC
22116@item @code{f} --- reserved
22117
22118Reserved for future use.
22119
0ce1b118
CV
22120@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
22121@cindex @code{F} packet
ee2d5c50 22122
0ce1b118
CV
22123This packet is send by @value{GDBN} as reply to a @code{F} request packet
22124sent by the target. This is part of the File-I/O protocol extension.
22125@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
22126
22127@item @code{g} --- read registers
22128@anchor{read registers packet}
22129@cindex @code{g} packet
22130
22131Read general registers.
22132
22133Reply:
22134@table @samp
22135@item @var{XX@dots{}}
8e04817f
AC
22136Each byte of register data is described by two hex digits. The bytes
22137with the register are transmitted in target byte order. The size of
22138each register and their position within the @samp{g} @var{packet} are
12c266ea
AC
22139determined by the @value{GDBN} internal macros
22140@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
22141specification of several standard @code{g} packets is specified below.
ee2d5c50
AC
22142@item E@var{NN}
22143for an error.
22144@end table
c906108c 22145
ee2d5c50
AC
22146@item @code{G}@var{XX@dots{}} --- write regs
22147@cindex @code{G} packet
c906108c 22148
ee2d5c50
AC
22149@xref{read registers packet}, for a description of the @var{XX@dots{}}
22150data.
22151
22152Reply:
22153@table @samp
22154@item OK
22155for success
22156@item E@var{NN}
22157for an error
22158@end table
22159
22160@item @code{h} --- reserved
22161
22162Reserved for future use.
22163
b383017d 22164@item @code{H}@var{c}@var{t@dots{}} --- set thread
ee2d5c50 22165@cindex @code{H} packet
c906108c 22166
8e04817f 22167Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
22168@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
22169should be @samp{c} for step and continue operations, @samp{g} for other
22170operations. The thread designator @var{t@dots{}} may be -1, meaning all
22171the threads, a thread number, or zero which means pick any thread.
22172
22173Reply:
22174@table @samp
22175@item OK
22176for success
22177@item E@var{NN}
22178for an error
22179@end table
c906108c 22180
8e04817f
AC
22181@c FIXME: JTC:
22182@c 'H': How restrictive (or permissive) is the thread model. If a
22183@c thread is selected and stopped, are other threads allowed
22184@c to continue to execute? As I mentioned above, I think the
22185@c semantics of each command when a thread is selected must be
22186@c described. For example:
22187@c
22188@c 'g': If the stub supports threads and a specific thread is
22189@c selected, returns the register block from that thread;
22190@c otherwise returns current registers.
22191@c
22192@c 'G' If the stub supports threads and a specific thread is
22193@c selected, sets the registers of the register block of
22194@c that thread; otherwise sets current registers.
c906108c 22195
ee2d5c50
AC
22196@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
22197@anchor{cycle step packet}
22198@cindex @code{i} packet
22199
8e04817f
AC
22200Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
22201present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
22202step starting at that address.
c906108c 22203
ee2d5c50
AC
22204@item @code{I} --- signal then cycle step @strong{(reserved)}
22205@cindex @code{I} packet
22206
22207@xref{step with signal packet}. @xref{cycle step packet}.
22208
22209@item @code{j} --- reserved
22210
22211Reserved for future use.
22212
22213@item @code{J} --- reserved
c906108c 22214
ee2d5c50 22215Reserved for future use.
c906108c 22216
ee2d5c50
AC
22217@item @code{k} --- kill request
22218@cindex @code{k} packet
c906108c 22219
ac282366 22220FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
22221thread context has been selected (i.e.@: does 'k' kill only that
22222thread?)}.
c906108c 22223
ee2d5c50 22224@item @code{K} --- reserved
c906108c 22225
ee2d5c50
AC
22226Reserved for future use.
22227
22228@item @code{l} --- reserved
22229
22230Reserved for future use.
22231
22232@item @code{L} --- reserved
22233
22234Reserved for future use.
22235
22236@item @code{m}@var{addr}@code{,}@var{length} --- read memory
22237@cindex @code{m} packet
c906108c 22238
8e04817f 22239Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 22240Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 22241assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 22242transfer mechanism is needed.}
c906108c 22243
ee2d5c50
AC
22244Reply:
22245@table @samp
22246@item @var{XX@dots{}}
22247@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
22248to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 22249that sized memory transfers are assumed using word aligned
ee2d5c50
AC
22250accesses. FIXME: @emph{A word aligned memory transfer mechanism is
22251needed.}
22252@item E@var{NN}
22253@var{NN} is errno
22254@end table
22255
22256@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
22257@cindex @code{M} packet
22258
8e04817f 22259Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
22260@var{XX@dots{}} is the data.
22261
22262Reply:
22263@table @samp
22264@item OK
22265for success
22266@item E@var{NN}
8e04817f
AC
22267for an error (this includes the case where only part of the data was
22268written).
ee2d5c50 22269@end table
c906108c 22270
ee2d5c50 22271@item @code{n} --- reserved
c906108c 22272
ee2d5c50 22273Reserved for future use.
c906108c 22274
ee2d5c50 22275@item @code{N} --- reserved
c906108c 22276
ee2d5c50 22277Reserved for future use.
c906108c 22278
ee2d5c50
AC
22279@item @code{o} --- reserved
22280
22281Reserved for future use.
22282
22283@item @code{O} --- reserved
22284
2e868123 22285@item @code{p}@var{hex number of register} --- read register packet
ee2d5c50
AC
22286@cindex @code{p} packet
22287
2e868123
AC
22288@xref{read registers packet}, for a description of how the returned
22289register value is encoded.
ee2d5c50
AC
22290
22291Reply:
22292@table @samp
2e868123
AC
22293@item @var{XX@dots{}}
22294the register's value
22295@item E@var{NN}
22296for an error
22297@item
22298Indicating an unrecognized @var{query}.
ee2d5c50
AC
22299@end table
22300
22301@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
22302@anchor{write register packet}
22303@cindex @code{P} packet
22304
22305Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 22306digits for each byte in the register (target byte order).
c906108c 22307
ee2d5c50
AC
22308Reply:
22309@table @samp
22310@item OK
22311for success
22312@item E@var{NN}
22313for an error
22314@end table
22315
22316@item @code{q}@var{query} --- general query
22317@anchor{general query packet}
22318@cindex @code{q} packet
22319
22320Request info about @var{query}. In general @value{GDBN} queries have a
22321leading upper case letter. Custom vendor queries should use a company
22322prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
22323be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
22324that they match the full @var{query} name.
22325
22326Reply:
22327@table @samp
22328@item @var{XX@dots{}}
22329Hex encoded data from query. The reply can not be empty.
22330@item E@var{NN}
22331error reply
8e04817f 22332@item
ee2d5c50
AC
22333Indicating an unrecognized @var{query}.
22334@end table
22335
22336@item @code{Q}@var{var}@code{=}@var{val} --- general set
22337@cindex @code{Q} packet
22338
22339Set value of @var{var} to @var{val}.
22340
22341@xref{general query packet}, for a discussion of naming conventions.
c906108c 22342
ee2d5c50
AC
22343@item @code{r} --- reset @strong{(deprecated)}
22344@cindex @code{r} packet
c906108c 22345
8e04817f 22346Reset the entire system.
c906108c 22347
ee2d5c50
AC
22348@item @code{R}@var{XX} --- remote restart
22349@cindex @code{R} packet
22350
8e04817f
AC
22351Restart the program being debugged. @var{XX}, while needed, is ignored.
22352This packet is only available in extended mode.
ee2d5c50
AC
22353
22354Reply:
22355@table @samp
22356@item @emph{no reply}
8e04817f 22357The @samp{R} packet has no reply.
ee2d5c50
AC
22358@end table
22359
22360@item @code{s}@var{addr} --- step
22361@cindex @code{s} packet
c906108c 22362
8e04817f
AC
22363@var{addr} is address to resume. If @var{addr} is omitted, resume at
22364same address.
c906108c 22365
ee2d5c50
AC
22366Reply:
22367@xref{Stop Reply Packets}, for the reply specifications.
22368
22369@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
22370@anchor{step with signal packet}
22371@cindex @code{S} packet
22372
8e04817f 22373Like @samp{C} but step not continue.
c906108c 22374
ee2d5c50
AC
22375Reply:
22376@xref{Stop Reply Packets}, for the reply specifications.
22377
b383017d 22378@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
ee2d5c50
AC
22379@cindex @code{t} packet
22380
8e04817f 22381Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
22382@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
22383@var{addr} must be at least 3 digits.
c906108c 22384
ee2d5c50
AC
22385@item @code{T}@var{XX} --- thread alive
22386@cindex @code{T} packet
c906108c 22387
ee2d5c50 22388Find out if the thread XX is alive.
c906108c 22389
ee2d5c50
AC
22390Reply:
22391@table @samp
22392@item OK
22393thread is still alive
22394@item E@var{NN}
22395thread is dead
22396@end table
22397
22398@item @code{u} --- reserved
22399
22400Reserved for future use.
22401
22402@item @code{U} --- reserved
22403
22404Reserved for future use.
22405
86d30acc 22406@item @code{v} --- verbose packet prefix
ee2d5c50 22407
86d30acc
DJ
22408Packets starting with @code{v} are identified by a multi-letter name,
22409up to the first @code{;} or @code{?} (or the end of the packet).
22410
22411@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
22412@cindex @code{vCont} packet
22413
22414Resume the inferior. Different actions may be specified for each thread.
22415If an action is specified with no @var{tid}, then it is applied to any
22416threads that don't have a specific action specified; if no default action is
22417specified then other threads should remain stopped. Specifying multiple
22418default actions is an error; specifying no actions is also an error.
22419Thread IDs are specified in hexadecimal. Currently supported actions are:
22420
22421@table @code
22422@item c
22423Continue.
22424@item C@var{sig}
22425Continue with signal @var{sig}. @var{sig} should be two hex digits.
22426@item s
22427Step.
22428@item S@var{sig}
22429Step with signal @var{sig}. @var{sig} should be two hex digits.
22430@end table
22431
22432The optional @var{addr} argument normally associated with these packets is
22433not supported in @code{vCont}.
22434
22435Reply:
22436@xref{Stop Reply Packets}, for the reply specifications.
22437
22438@item @code{vCont?} --- extended resume query
22439@cindex @code{vCont?} packet
22440
22441Query support for the @code{vCont} packet.
22442
22443Reply:
22444@table @samp
22445@item @code{vCont}[;@var{action}]...
22446The @code{vCont} packet is supported. Each @var{action} is a supported
22447command in the @code{vCont} packet.
22448@item
22449The @code{vCont} packet is not supported.
22450@end table
ee2d5c50
AC
22451
22452@item @code{V} --- reserved
c906108c 22453
ee2d5c50 22454Reserved for future use.
c906108c 22455
ee2d5c50 22456@item @code{w} --- reserved
c906108c 22457
ee2d5c50 22458Reserved for future use.
c906108c 22459
ee2d5c50 22460@item @code{W} --- reserved
c906108c 22461
ee2d5c50 22462Reserved for future use.
c906108c 22463
ee2d5c50
AC
22464@item @code{x} --- reserved
22465
22466Reserved for future use.
22467
22468@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
22469@cindex @code{X} packet
22470
22471@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
22472is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
69065f5d
AC
22473escaped using @code{0x7d}, and then XORed with @code{0x20}.
22474For example, @code{0x7d} would be transmitted as @code{0x7d 0x5d}.
c906108c 22475
ee2d5c50
AC
22476Reply:
22477@table @samp
22478@item OK
22479for success
22480@item E@var{NN}
22481for an error
22482@end table
22483
22484@item @code{y} --- reserved
c906108c 22485
ee2d5c50 22486Reserved for future use.
c906108c 22487
ee2d5c50
AC
22488@item @code{Y} reserved
22489
22490Reserved for future use.
22491
2f870471
AC
22492@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
22493@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
22494@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 22495@cindex @code{z} packet
2f870471 22496@cindex @code{Z} packets
ee2d5c50 22497
2f870471
AC
22498Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
22499watchpoint starting at address @var{address} and covering the next
22500@var{length} bytes.
ee2d5c50 22501
2f870471
AC
22502Each breakpoint and watchpoint packet @var{type} is documented
22503separately.
22504
512217c7
AC
22505@emph{Implementation notes: A remote target shall return an empty string
22506for an unrecognized breakpoint or watchpoint packet @var{type}. A
22507remote target shall support either both or neither of a given
2f870471
AC
22508@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
22509avoid potential problems with duplicate packets, the operations should
22510be implemented in an idempotent way.}
22511
22512@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
22513@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
22514@cindex @code{z0} packet
22515@cindex @code{Z0} packet
22516
22517Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
22518@code{addr} of size @code{length}.
22519
22520A memory breakpoint is implemented by replacing the instruction at
22521@var{addr} with a software breakpoint or trap instruction. The
22522@code{length} is used by targets that indicates the size of the
22523breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
22524@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 22525
2f870471
AC
22526@emph{Implementation note: It is possible for a target to copy or move
22527code that contains memory breakpoints (e.g., when implementing
22528overlays). The behavior of this packet, in the presence of such a
22529target, is not defined.}
c906108c 22530
ee2d5c50
AC
22531Reply:
22532@table @samp
2f870471
AC
22533@item OK
22534success
22535@item
22536not supported
ee2d5c50
AC
22537@item E@var{NN}
22538for an error
2f870471
AC
22539@end table
22540
22541@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
22542@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
22543@cindex @code{z1} packet
22544@cindex @code{Z1} packet
22545
22546Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
22547address @code{addr} of size @code{length}.
22548
22549A hardware breakpoint is implemented using a mechanism that is not
22550dependant on being able to modify the target's memory.
22551
22552@emph{Implementation note: A hardware breakpoint is not affected by code
22553movement.}
22554
22555Reply:
22556@table @samp
ee2d5c50 22557@item OK
2f870471
AC
22558success
22559@item
22560not supported
22561@item E@var{NN}
22562for an error
22563@end table
22564
22565@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
22566@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
22567@cindex @code{z2} packet
22568@cindex @code{Z2} packet
22569
22570Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
22571
22572Reply:
22573@table @samp
22574@item OK
22575success
22576@item
22577not supported
22578@item E@var{NN}
22579for an error
22580@end table
22581
22582@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
22583@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
22584@cindex @code{z3} packet
22585@cindex @code{Z3} packet
22586
2e834e49 22587Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
22588
22589Reply:
22590@table @samp
22591@item OK
22592success
22593@item
22594not supported
22595@item E@var{NN}
22596for an error
22597@end table
22598
2e834e49
HPN
22599@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
22600@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
22601@cindex @code{z4} packet
22602@cindex @code{Z4} packet
22603
22604Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
22605
22606Reply:
22607@table @samp
22608@item OK
22609success
22610@item
22611not supported
22612@item E@var{NN}
22613for an error
ee2d5c50
AC
22614@end table
22615
22616@end table
c906108c 22617
ee2d5c50
AC
22618@node Stop Reply Packets
22619@section Stop Reply Packets
22620@cindex stop reply packets
c906108c 22621
8e04817f
AC
22622The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
22623receive any of the below as a reply. In the case of the @samp{C},
22624@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
22625when the target halts. In the below the exact meaning of @samp{signal
22626number} is poorly defined. In general one of the UNIX signal numbering
22627conventions is used.
c906108c 22628
ee2d5c50 22629@table @samp
c906108c 22630
ee2d5c50
AC
22631@item S@var{AA}
22632@var{AA} is the signal number
c906108c 22633
8e04817f 22634@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
22635@cindex @code{T} packet reply
22636
8e04817f
AC
22637@var{AA} = two hex digit signal number; @var{n...} = register number
22638(hex), @var{r...} = target byte ordered register contents, size defined
12c266ea
AC
22639by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
22640@var{r...} = thread process ID, this is a hex integer; @var{n...} =
22641(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
22642address, this is a hex integer; @var{n...} = other string not starting
22643with valid hex digit. @value{GDBN} should ignore this @var{n...},
22644@var{r...} pair and go on to the next. This way we can extend the
22645protocol.
c906108c 22646
ee2d5c50
AC
22647@item W@var{AA}
22648
8e04817f 22649The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
22650applicable to certain targets.
22651
22652@item X@var{AA}
c906108c 22653
8e04817f 22654The process terminated with signal @var{AA}.
c906108c 22655
ee2d5c50 22656@item O@var{XX@dots{}}
c906108c 22657
ee2d5c50
AC
22658@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
22659any time while the program is running and the debugger should continue
22660to wait for @samp{W}, @samp{T}, etc.
22661
0ce1b118
CV
22662@item F@var{call-id}@code{,}@var{parameter@dots{}}
22663
22664@var{call-id} is the identifier which says which host system call should
22665be called. This is just the name of the function. Translation into the
22666correct system call is only applicable as it's defined in @value{GDBN}.
22667@xref{File-I/O remote protocol extension}, for a list of implemented
22668system calls.
22669
22670@var{parameter@dots{}} is a list of parameters as defined for this very
22671system call.
22672
22673The target replies with this packet when it expects @value{GDBN} to call
22674a host system call on behalf of the target. @value{GDBN} replies with
22675an appropriate @code{F} packet and keeps up waiting for the next reply
22676packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
22677@samp{s} action is expected to be continued.
22678@xref{File-I/O remote protocol extension}, for more details.
22679
ee2d5c50
AC
22680@end table
22681
22682@node General Query Packets
22683@section General Query Packets
9c16f35a 22684@cindex remote query requests
c906108c 22685
8e04817f 22686The following set and query packets have already been defined.
c906108c 22687
ee2d5c50 22688@table @r
c906108c 22689
ee2d5c50 22690@item @code{q}@code{C} --- current thread
9c16f35a
EZ
22691@cindex current thread, remote request
22692@cindex @code{qC} packet
ee2d5c50
AC
22693Return the current thread id.
22694
22695Reply:
22696@table @samp
22697@item @code{QC}@var{pid}
e1aac25b 22698Where @var{pid} is an unsigned hexidecimal process id.
ee2d5c50
AC
22699@item *
22700Any other reply implies the old pid.
22701@end table
22702
22703@item @code{q}@code{fThreadInfo} -- all thread ids
9c16f35a
EZ
22704@cindex list active threads, remote request
22705@cindex @code{qfThreadInfo} packet
ee2d5c50 22706@code{q}@code{sThreadInfo}
c906108c 22707
8e04817f
AC
22708Obtain a list of active thread ids from the target (OS). Since there
22709may be too many active threads to fit into one reply packet, this query
22710works iteratively: it may require more than one query/reply sequence to
22711obtain the entire list of threads. The first query of the sequence will
22712be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
22713sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
22714
22715NOTE: replaces the @code{qL} query (see below).
22716
22717Reply:
22718@table @samp
22719@item @code{m}@var{id}
22720A single thread id
22721@item @code{m}@var{id},@var{id}@dots{}
22722a comma-separated list of thread ids
22723@item @code{l}
22724(lower case 'el') denotes end of list.
22725@end table
22726
22727In response to each query, the target will reply with a list of one or
e1aac25b
JB
22728more thread ids, in big-endian unsigned hex, separated by commas.
22729@value{GDBN} will respond to each reply with a request for more thread
22730ids (using the @code{qs} form of the query), until the target responds
22731with @code{l} (lower-case el, for @code{'last'}).
c906108c 22732
ee2d5c50 22733@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
9c16f35a
EZ
22734@cindex thread attributes info, remote request
22735@cindex @code{qThreadExtraInfo} packet
ee2d5c50
AC
22736Where @var{id} is a thread-id in big-endian hex. Obtain a printable
22737string description of a thread's attributes from the target OS. This
22738string may contain anything that the target OS thinks is interesting for
22739@value{GDBN} to tell the user about the thread. The string is displayed
22740in @value{GDBN}'s @samp{info threads} display. Some examples of
22741possible thread extra info strings are ``Runnable'', or ``Blocked on
22742Mutex''.
22743
22744Reply:
22745@table @samp
22746@item @var{XX@dots{}}
22747Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
22748the printable string containing the extra information about the thread's
8e04817f 22749attributes.
ee2d5c50
AC
22750@end table
22751
22752@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 22753
8e04817f
AC
22754Obtain thread information from RTOS. Where: @var{startflag} (one hex
22755digit) is one to indicate the first query and zero to indicate a
22756subsequent query; @var{threadcount} (two hex digits) is the maximum
22757number of threads the response packet can contain; and @var{nextthread}
22758(eight hex digits), for subsequent queries (@var{startflag} is zero), is
22759returned in the response as @var{argthread}.
ee2d5c50
AC
22760
22761NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
22762(see above).
22763
22764Reply:
22765@table @samp
22766@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
22767Where: @var{count} (two hex digits) is the number of threads being
22768returned; @var{done} (one hex digit) is zero to indicate more threads
22769and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
22770digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
22771is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 22772digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 22773@end table
c906108c 22774
ee2d5c50 22775@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
9c16f35a
EZ
22776@cindex CRC of memory block, remote request
22777@cindex @code{qCRC} packet
ee2d5c50
AC
22778Reply:
22779@table @samp
22780@item @code{E}@var{NN}
22781An error (such as memory fault)
22782@item @code{C}@var{CRC32}
22783A 32 bit cyclic redundancy check of the specified memory region.
22784@end table
22785
22786@item @code{q}@code{Offsets} --- query sect offs
9c16f35a
EZ
22787@cindex section offsets, remote request
22788@cindex @code{qOffsets} packet
8e04817f
AC
22789Get section offsets that the target used when re-locating the downloaded
22790image. @emph{Note: while a @code{Bss} offset is included in the
22791response, @value{GDBN} ignores this and instead applies the @code{Data}
22792offset to the @code{Bss} section.}
c906108c 22793
ee2d5c50
AC
22794Reply:
22795@table @samp
22796@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
22797@end table
22798
22799@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
9c16f35a
EZ
22800@cindex thread information, remote request
22801@cindex @code{qP} packet
8e04817f
AC
22802Returns information on @var{threadid}. Where: @var{mode} is a hex
22803encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
22804
22805Reply:
22806@table @samp
22807@item *
22808@end table
22809
8e04817f 22810See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 22811
ee2d5c50 22812@item @code{q}@code{Rcmd,}@var{command} --- remote command
9c16f35a
EZ
22813@cindex execute remote command, remote request
22814@cindex @code{qRcmd} packet
ee2d5c50 22815@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
22816execution. Invalid commands should be reported using the output string.
22817Before the final result packet, the target may also respond with a
ee2d5c50
AC
22818number of intermediate @code{O}@var{output} console output packets.
22819@emph{Implementors should note that providing access to a stubs's
22820interpreter may have security implications}.
22821
22822Reply:
22823@table @samp
22824@item OK
8e04817f 22825A command response with no output.
ee2d5c50 22826@item @var{OUTPUT}
8e04817f 22827A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 22828@item @code{E}@var{NN}
8e04817f 22829Indicate a badly formed request.
ee2d5c50 22830@item @samp{}
8e04817f 22831When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50 22832@end table
9c16f35a 22833z
ee2d5c50 22834@item @code{qSymbol::} --- symbol lookup
9c16f35a
EZ
22835@cindex symbol lookup, remote request
22836@cindex @code{qSymbol} packet
8e04817f
AC
22837Notify the target that @value{GDBN} is prepared to serve symbol lookup
22838requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
22839
22840Reply:
22841@table @samp
22842@item @code{OK}
8e04817f 22843The target does not need to look up any (more) symbols.
ee2d5c50
AC
22844@item @code{qSymbol:}@var{sym_name}
22845The target requests the value of symbol @var{sym_name} (hex encoded).
22846@value{GDBN} may provide the value by using the
22847@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
22848@end table
22849
22850@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
22851
22852Set the value of @var{sym_name} to @var{sym_value}.
22853
22854@var{sym_name} (hex encoded) is the name of a symbol whose value the
22855target has previously requested.
22856
22857@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
22858@value{GDBN} cannot supply a value for @var{sym_name}, then this field
22859will be empty.
22860
22861Reply:
22862@table @samp
22863@item @code{OK}
8e04817f 22864The target does not need to look up any (more) symbols.
ee2d5c50
AC
22865@item @code{qSymbol:}@var{sym_name}
22866The target requests the value of a new symbol @var{sym_name} (hex
22867encoded). @value{GDBN} will continue to supply the values of symbols
22868(if available), until the target ceases to request them.
22869@end table
eb12ee30 22870
649e03f6 22871@item @code{qPart}:@var{object}:@code{read}:@var{annex}:@var{offset},@var{length} --- read special data
9c16f35a
EZ
22872@cindex read special object, remote request
22873@cindex @code{qPart} packet
649e03f6
RM
22874Read uninterpreted bytes from the target's special data area
22875identified by the keyword @code{object}.
22876Request @var{length} bytes starting at @var{offset} bytes into the data.
22877The content and encoding of @var{annex} is specific to the object;
22878it can supply additional details about what data to access.
22879
22880Here are the specific requests of this form defined so far.
22881All @samp{@code{qPart}:@var{object}:@code{read}:@dots{}}
22882requests use the same reply formats, listed below.
22883
22884@table @asis
22885@item @code{qPart}:@code{auxv}:@code{read}::@var{offset},@var{length}
721c2651
EZ
22886Access the target's @dfn{auxiliary vector}. @xref{OS Information,
22887auxiliary vector}, and see @ref{Remote configuration,
22888read-aux-vector-packet}. Note @var{annex} must be empty.
649e03f6
RM
22889@end table
22890
22891Reply:
22892@table @asis
22893@item @code{OK}
22894The @var{offset} in the request is at the end of the data.
22895There is no more data to be read.
22896
22897@item @var{XX@dots{}}
22898Hex encoded data bytes read.
22899This may be fewer bytes than the @var{length} in the request.
22900
22901@item @code{E00}
22902The request was malformed, or @var{annex} was invalid.
22903
22904@item @code{E}@var{nn}
22905The offset was invalid, or there was an error encountered reading the data.
22906@var{nn} is a hex-encoded @code{errno} value.
22907
22908@item @code{""} (empty)
22909An empty reply indicates the @var{object} or @var{annex} string was not
22910recognized by the stub.
22911@end table
22912
22913@item @code{qPart}:@var{object}:@code{write}:@var{annex}:@var{offset}:@var{data@dots{}}
9c16f35a 22914@cindex write data into object, remote request
649e03f6
RM
22915Write uninterpreted bytes into the target's special data area
22916identified by the keyword @code{object},
22917starting at @var{offset} bytes into the data.
22918@var{data@dots{}} is the hex-encoded data to be written.
22919The content and encoding of @var{annex} is specific to the object;
22920it can supply additional details about what data to access.
22921
22922No requests of this form are presently in use. This specification
22923serves as a placeholder to document the common format that new
22924specific request specifications ought to use.
22925
22926Reply:
22927@table @asis
22928@item @var{nn}
22929@var{nn} (hex encoded) is the number of bytes written.
22930This may be fewer bytes than supplied in the request.
22931
22932@item @code{E00}
22933The request was malformed, or @var{annex} was invalid.
22934
22935@item @code{E}@var{nn}
22936The offset was invalid, or there was an error encountered writing the data.
22937@var{nn} is a hex-encoded @code{errno} value.
22938
22939@item @code{""} (empty)
22940An empty reply indicates the @var{object} or @var{annex} string was not
22941recognized by the stub, or that the object does not support writing.
22942@end table
22943
22944@item @code{qPart}:@var{object}:@var{operation}:@dots{}
22945Requests of this form may be added in the future. When a stub does
22946not recognize the @var{object} keyword, or its support for
22947@var{object} does not recognize the @var{operation} keyword,
22948the stub must respond with an empty packet.
83761cbd
KB
22949
22950@item @code{qGetTLSAddr}:@var{thread-id},@var{offset},@var{lm} --- get thread local storage address
9c16f35a
EZ
22951@cindex get thread-local storage address, remote request
22952@cindex @code{qGetTLSAddr} packet
83761cbd
KB
22953Fetch the address associated with thread local storage specified
22954by @var{thread-id}, @var{offset}, and @var{lm}.
22955
22956@var{thread-id} is the (big endian, hex encoded) thread id associated with the
22957thread for which to fetch the TLS address.
22958
22959@var{offset} is the (big endian, hex encoded) offset associated with the
22960thread local variable. (This offset is obtained from the debug
22961information associated with the variable.)
22962
22963@var{lm} is the (big endian, hex encoded) OS/ABI specific encoding of the
22964the load module associated with the thread local storage. For example,
22965a @sc{gnu}/Linux system will pass the link map address of the shared
22966object associated with the thread local storage under consideration.
22967Other operating environments may choose to represent the load module
22968differently, so the precise meaning of this parameter will vary.
22969
22970Reply:
22971@table @asis
68c71a2e 22972@item @var{XX@dots{}}
83761cbd
KB
22973Hex encoded (big endian) bytes representing the address of the thread
22974local storage requested.
22975
22976@item @code{E}@var{nn} (where @var{nn} are hex digits)
22977An error occurred.
22978
22979@item @code{""} (empty)
22980An empty reply indicates that @code{qGetTLSAddr} is not supported by the stub.
22981@end table
22982
0abb7bc7
EZ
22983Use of this request packet is controlled by the @code{set remote
22984get-thread-local-storage-address} command (@pxref{Remote
22985configuration, set remote get-thread-local-storage-address}).
22986
ee2d5c50
AC
22987@end table
22988
22989@node Register Packet Format
22990@section Register Packet Format
eb12ee30 22991
8e04817f 22992The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
22993In the below, some thirty-two bit registers are transferred as
22994sixty-four bits. Those registers should be zero/sign extended (which?)
22995to fill the space allocated. Register bytes are transfered in target
22996byte order. The two nibbles within a register byte are transfered
22997most-significant - least-significant.
eb12ee30 22998
ee2d5c50 22999@table @r
eb12ee30 23000
8e04817f 23001@item MIPS32
ee2d5c50 23002
8e04817f
AC
23003All registers are transfered as thirty-two bit quantities in the order:
2300432 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
23005registers; fsr; fir; fp.
eb12ee30 23006
8e04817f 23007@item MIPS64
ee2d5c50 23008
8e04817f
AC
23009All registers are transfered as sixty-four bit quantities (including
23010thirty-two bit registers such as @code{sr}). The ordering is the same
23011as @code{MIPS32}.
eb12ee30 23012
ee2d5c50
AC
23013@end table
23014
23015@node Examples
23016@section Examples
eb12ee30 23017
8e04817f
AC
23018Example sequence of a target being re-started. Notice how the restart
23019does not get any direct output:
eb12ee30 23020
474c8240 23021@smallexample
d2c6833e
AC
23022-> @code{R00}
23023<- @code{+}
8e04817f 23024@emph{target restarts}
d2c6833e 23025-> @code{?}
8e04817f 23026<- @code{+}
d2c6833e
AC
23027<- @code{T001:1234123412341234}
23028-> @code{+}
474c8240 23029@end smallexample
eb12ee30 23030
8e04817f 23031Example sequence of a target being stepped by a single instruction:
eb12ee30 23032
474c8240 23033@smallexample
d2c6833e 23034-> @code{G1445@dots{}}
8e04817f 23035<- @code{+}
d2c6833e
AC
23036-> @code{s}
23037<- @code{+}
23038@emph{time passes}
23039<- @code{T001:1234123412341234}
8e04817f 23040-> @code{+}
d2c6833e 23041-> @code{g}
8e04817f 23042<- @code{+}
d2c6833e
AC
23043<- @code{1455@dots{}}
23044-> @code{+}
474c8240 23045@end smallexample
eb12ee30 23046
0ce1b118
CV
23047@node File-I/O remote protocol extension
23048@section File-I/O remote protocol extension
23049@cindex File-I/O remote protocol extension
23050
23051@menu
23052* File-I/O Overview::
23053* Protocol basics::
1d8b2f28
JB
23054* The F request packet::
23055* The F reply packet::
0ce1b118
CV
23056* Memory transfer::
23057* The Ctrl-C message::
23058* Console I/O::
23059* The isatty call::
23060* The system call::
23061* List of supported calls::
23062* Protocol specific representation of datatypes::
23063* Constants::
23064* File-I/O Examples::
23065@end menu
23066
23067@node File-I/O Overview
23068@subsection File-I/O Overview
23069@cindex file-i/o overview
23070
9c16f35a
EZ
23071The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
23072target to use the host's file system and console I/O when calling various
0ce1b118
CV
23073system calls. System calls on the target system are translated into a
23074remote protocol packet to the host system which then performs the needed
23075actions and returns with an adequate response packet to the target system.
23076This simulates file system operations even on targets that lack file systems.
23077
23078The protocol is defined host- and target-system independent. It uses
9c16f35a 23079its own independent representation of datatypes and values. Both,
0ce1b118
CV
23080@value{GDBN} and the target's @value{GDBN} stub are responsible for
23081translating the system dependent values into the unified protocol values
23082when data is transmitted.
23083
23084The communication is synchronous. A system call is possible only
23085when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
23086packets. While @value{GDBN} handles the request for a system call,
23087the target is stopped to allow deterministic access to the target's
23088memory. Therefore File-I/O is not interuptible by target signals. It
23089is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
23090
23091The target's request to perform a host system call does not finish
23092the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
23093after finishing the system call, the target returns to continuing the
23094previous activity (continue, step). No additional continue or step
23095request from @value{GDBN} is required.
23096
23097@smallexample
f7dc1244 23098(@value{GDBP}) continue
0ce1b118
CV
23099 <- target requests 'system call X'
23100 target is stopped, @value{GDBN} executes system call
23101 -> GDB returns result
23102 ... target continues, GDB returns to wait for the target
23103 <- target hits breakpoint and sends a Txx packet
23104@end smallexample
23105
23106The protocol is only used for files on the host file system and
23107for I/O on the console. Character or block special devices, pipes,
23108named pipes or sockets or any other communication method on the host
23109system are not supported by this protocol.
23110
23111@node Protocol basics
23112@subsection Protocol basics
23113@cindex protocol basics, file-i/o
23114
23115The File-I/O protocol uses the @code{F} packet, as request as well
23116as as reply packet. Since a File-I/O system call can only occur when
b383017d 23117@value{GDBN} is waiting for the continuing or stepping target, the
0ce1b118
CV
23118File-I/O request is a reply that @value{GDBN} has to expect as a result
23119of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
23120This @code{F} packet contains all information needed to allow @value{GDBN}
23121to call the appropriate host system call:
23122
23123@itemize @bullet
b383017d 23124@item
0ce1b118
CV
23125A unique identifier for the requested system call.
23126
23127@item
23128All parameters to the system call. Pointers are given as addresses
23129in the target memory address space. Pointers to strings are given as
b383017d 23130pointer/length pair. Numerical values are given as they are.
0ce1b118
CV
23131Numerical control values are given in a protocol specific representation.
23132
23133@end itemize
23134
23135At that point @value{GDBN} has to perform the following actions.
23136
23137@itemize @bullet
b383017d 23138@item
0ce1b118
CV
23139If parameter pointer values are given, which point to data needed as input
23140to a system call, @value{GDBN} requests this data from the target with a
23141standard @code{m} packet request. This additional communication has to be
23142expected by the target implementation and is handled as any other @code{m}
23143packet.
23144
23145@item
23146@value{GDBN} translates all value from protocol representation to host
23147representation as needed. Datatypes are coerced into the host types.
23148
23149@item
23150@value{GDBN} calls the system call
23151
23152@item
23153It then coerces datatypes back to protocol representation.
23154
23155@item
23156If pointer parameters in the request packet point to buffer space in which
23157a system call is expected to copy data to, the data is transmitted to the
23158target using a @code{M} or @code{X} packet. This packet has to be expected
23159by the target implementation and is handled as any other @code{M} or @code{X}
23160packet.
23161
23162@end itemize
23163
23164Eventually @value{GDBN} replies with another @code{F} packet which contains all
23165necessary information for the target to continue. This at least contains
23166
23167@itemize @bullet
23168@item
23169Return value.
23170
23171@item
23172@code{errno}, if has been changed by the system call.
23173
23174@item
23175``Ctrl-C'' flag.
23176
23177@end itemize
23178
23179After having done the needed type and value coercion, the target continues
23180the latest continue or step action.
23181
1d8b2f28 23182@node The F request packet
0ce1b118
CV
23183@subsection The @code{F} request packet
23184@cindex file-i/o request packet
23185@cindex @code{F} request packet
23186
23187The @code{F} request packet has the following format:
23188
23189@table @samp
23190
23191@smallexample
23192@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
23193@end smallexample
23194
23195@var{call-id} is the identifier to indicate the host system call to be called.
23196This is just the name of the function.
23197
23198@var{parameter@dots{}} are the parameters to the system call.
23199
b383017d 23200@end table
0ce1b118
CV
23201
23202Parameters are hexadecimal integer values, either the real values in case
23203of scalar datatypes, as pointers to target buffer space in case of compound
23204datatypes and unspecified memory areas or as pointer/length pairs in case
23205of string parameters. These are appended to the call-id, each separated
23206from its predecessor by a comma. All values are transmitted in ASCII
23207string representation, pointer/length pairs separated by a slash.
23208
1d8b2f28 23209@node The F reply packet
0ce1b118
CV
23210@subsection The @code{F} reply packet
23211@cindex file-i/o reply packet
23212@cindex @code{F} reply packet
23213
23214The @code{F} reply packet has the following format:
23215
23216@table @samp
23217
23218@smallexample
23219@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
23220@end smallexample
23221
23222@var{retcode} is the return code of the system call as hexadecimal value.
23223
23224@var{errno} is the errno set by the call, in protocol specific representation.
23225This parameter can be omitted if the call was successful.
23226
23227@var{Ctrl-C flag} is only send if the user requested a break. In this
23228case, @var{errno} must be send as well, even if the call was successful.
23229The @var{Ctrl-C flag} itself consists of the character 'C':
23230
23231@smallexample
23232F0,0,C
23233@end smallexample
23234
23235@noindent
23236or, if the call was interupted before the host call has been performed:
23237
23238@smallexample
23239F-1,4,C
23240@end smallexample
23241
23242@noindent
23243assuming 4 is the protocol specific representation of @code{EINTR}.
23244
23245@end table
23246
23247@node Memory transfer
23248@subsection Memory transfer
23249@cindex memory transfer, in file-i/o protocol
23250
23251Structured data which is transferred using a memory read or write as e.g.@:
23252a @code{struct stat} is expected to be in a protocol specific format with
23253all scalar multibyte datatypes being big endian. This should be done by
23254the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
23255it transfers memory to the target. Transferred pointers to structured
23256data should point to the already coerced data at any time.
23257
23258@node The Ctrl-C message
23259@subsection The Ctrl-C message
23260@cindex ctrl-c message, in file-i/o protocol
23261
23262A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
23263reply packet. In this case the target should behave, as if it had
23264gotten a break message. The meaning for the target is ``system call
23265interupted by @code{SIGINT}''. Consequentially, the target should actually stop
23266(as with a break message) and return to @value{GDBN} with a @code{T02}
b383017d 23267packet. In this case, it's important for the target to know, in which
0ce1b118
CV
23268state the system call was interrupted. Since this action is by design
23269not an atomic operation, we have to differ between two cases:
23270
23271@itemize @bullet
23272@item
23273The system call hasn't been performed on the host yet.
23274
23275@item
23276The system call on the host has been finished.
23277
23278@end itemize
23279
23280These two states can be distinguished by the target by the value of the
23281returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
23282call hasn't been performed. This is equivalent to the @code{EINTR} handling
23283on POSIX systems. In any other case, the target may presume that the
23284system call has been finished --- successful or not --- and should behave
23285as if the break message arrived right after the system call.
23286
23287@value{GDBN} must behave reliable. If the system call has not been called
23288yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
23289@code{errno} in the packet. If the system call on the host has been finished
23290before the user requests a break, the full action must be finshed by
23291@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
23292The @code{F} packet may only be send when either nothing has happened
23293or the full action has been completed.
23294
23295@node Console I/O
23296@subsection Console I/O
23297@cindex console i/o as part of file-i/o
23298
23299By default and if not explicitely closed by the target system, the file
23300descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
23301on the @value{GDBN} console is handled as any other file output operation
23302(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
23303by @value{GDBN} so that after the target read request from file descriptor
233040 all following typing is buffered until either one of the following
23305conditions is met:
23306
23307@itemize @bullet
23308@item
23309The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
23310@code{read}
23311system call is treated as finished.
23312
23313@item
23314The user presses @kbd{Enter}. This is treated as end of input with a trailing
23315line feed.
23316
23317@item
23318The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
23319character, especially no Ctrl-D is appended to the input.
23320
23321@end itemize
23322
23323If the user has typed more characters as fit in the buffer given to
23324the read call, the trailing characters are buffered in @value{GDBN} until
23325either another @code{read(0, @dots{})} is requested by the target or debugging
23326is stopped on users request.
23327
23328@node The isatty call
2eecc4ab 23329@subsection The @samp{isatty} function call
0ce1b118
CV
23330@cindex isatty call, file-i/o protocol
23331
23332A special case in this protocol is the library call @code{isatty} which
9c16f35a 23333is implemented as its own call inside of this protocol. It returns
0ce1b118
CV
233341 to the target if the file descriptor given as parameter is attached
23335to the @value{GDBN} console, 0 otherwise. Implementing through system calls
23336would require implementing @code{ioctl} and would be more complex than
23337needed.
23338
23339@node The system call
2eecc4ab 23340@subsection The @samp{system} function call
0ce1b118
CV
23341@cindex system call, file-i/o protocol
23342
23343The other special case in this protocol is the @code{system} call which
9c16f35a 23344is implemented as its own call, too. @value{GDBN} is taking over the full
0ce1b118
CV
23345task of calling the necessary host calls to perform the @code{system}
23346call. The return value of @code{system} is simplified before it's returned
23347to the target. Basically, the only signal transmitted back is @code{EINTR}
23348in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
23349entirely of the exit status of the called command.
23350
9c16f35a
EZ
23351Due to security concerns, the @code{system} call is by default refused
23352by @value{GDBN}. The user has to allow this call explicitly with the
23353@kbd{set remote system-call-allowed 1} command.
0ce1b118 23354
9c16f35a
EZ
23355@table @code
23356@item set remote system-call-allowed
23357@kindex set remote system-call-allowed
23358Control whether to allow the @code{system} calls in the File I/O
23359protocol for the remote target. The default is zero (disabled).
0ce1b118 23360
9c16f35a 23361@item show remote system-call-allowed
0ce1b118 23362@kindex show remote system-call-allowed
9c16f35a
EZ
23363Show the current setting of system calls for the remote File I/O
23364protocol.
0ce1b118
CV
23365@end table
23366
23367@node List of supported calls
23368@subsection List of supported calls
23369@cindex list of supported file-i/o calls
23370
23371@menu
23372* open::
23373* close::
23374* read::
23375* write::
23376* lseek::
23377* rename::
23378* unlink::
23379* stat/fstat::
23380* gettimeofday::
23381* isatty::
23382* system::
23383@end menu
23384
23385@node open
23386@unnumberedsubsubsec open
23387@cindex open, file-i/o system call
23388
23389@smallexample
23390@exdent Synopsis:
23391int open(const char *pathname, int flags);
23392int open(const char *pathname, int flags, mode_t mode);
23393
b383017d 23394@exdent Request:
0ce1b118
CV
23395Fopen,pathptr/len,flags,mode
23396@end smallexample
23397
23398@noindent
23399@code{flags} is the bitwise or of the following values:
23400
23401@table @code
b383017d 23402@item O_CREAT
0ce1b118
CV
23403If the file does not exist it will be created. The host
23404rules apply as far as file ownership and time stamps
23405are concerned.
23406
b383017d 23407@item O_EXCL
0ce1b118
CV
23408When used with O_CREAT, if the file already exists it is
23409an error and open() fails.
23410
b383017d 23411@item O_TRUNC
0ce1b118
CV
23412If the file already exists and the open mode allows
23413writing (O_RDWR or O_WRONLY is given) it will be
23414truncated to length 0.
23415
b383017d 23416@item O_APPEND
0ce1b118
CV
23417The file is opened in append mode.
23418
b383017d 23419@item O_RDONLY
0ce1b118
CV
23420The file is opened for reading only.
23421
b383017d 23422@item O_WRONLY
0ce1b118
CV
23423The file is opened for writing only.
23424
b383017d 23425@item O_RDWR
0ce1b118
CV
23426The file is opened for reading and writing.
23427
23428@noindent
23429Each other bit is silently ignored.
23430
23431@end table
23432
23433@noindent
23434@code{mode} is the bitwise or of the following values:
23435
23436@table @code
b383017d 23437@item S_IRUSR
0ce1b118
CV
23438User has read permission.
23439
b383017d 23440@item S_IWUSR
0ce1b118
CV
23441User has write permission.
23442
b383017d 23443@item S_IRGRP
0ce1b118
CV
23444Group has read permission.
23445
b383017d 23446@item S_IWGRP
0ce1b118
CV
23447Group has write permission.
23448
b383017d 23449@item S_IROTH
0ce1b118
CV
23450Others have read permission.
23451
b383017d 23452@item S_IWOTH
0ce1b118
CV
23453Others have write permission.
23454
23455@noindent
23456Each other bit is silently ignored.
23457
23458@end table
23459
23460@smallexample
23461@exdent Return value:
23462open returns the new file descriptor or -1 if an error
23463occured.
23464
23465@exdent Errors:
23466@end smallexample
23467
23468@table @code
b383017d 23469@item EEXIST
0ce1b118
CV
23470pathname already exists and O_CREAT and O_EXCL were used.
23471
b383017d 23472@item EISDIR
0ce1b118
CV
23473pathname refers to a directory.
23474
b383017d 23475@item EACCES
0ce1b118
CV
23476The requested access is not allowed.
23477
23478@item ENAMETOOLONG
23479pathname was too long.
23480
b383017d 23481@item ENOENT
0ce1b118
CV
23482A directory component in pathname does not exist.
23483
b383017d 23484@item ENODEV
0ce1b118
CV
23485pathname refers to a device, pipe, named pipe or socket.
23486
b383017d 23487@item EROFS
0ce1b118
CV
23488pathname refers to a file on a read-only filesystem and
23489write access was requested.
23490
b383017d 23491@item EFAULT
0ce1b118
CV
23492pathname is an invalid pointer value.
23493
b383017d 23494@item ENOSPC
0ce1b118
CV
23495No space on device to create the file.
23496
b383017d 23497@item EMFILE
0ce1b118
CV
23498The process already has the maximum number of files open.
23499
b383017d 23500@item ENFILE
0ce1b118
CV
23501The limit on the total number of files open on the system
23502has been reached.
23503
b383017d 23504@item EINTR
0ce1b118
CV
23505The call was interrupted by the user.
23506@end table
23507
23508@node close
23509@unnumberedsubsubsec close
23510@cindex close, file-i/o system call
23511
23512@smallexample
b383017d 23513@exdent Synopsis:
0ce1b118
CV
23514int close(int fd);
23515
b383017d 23516@exdent Request:
0ce1b118
CV
23517Fclose,fd
23518
23519@exdent Return value:
23520close returns zero on success, or -1 if an error occurred.
23521
23522@exdent Errors:
23523@end smallexample
23524
23525@table @code
b383017d 23526@item EBADF
0ce1b118
CV
23527fd isn't a valid open file descriptor.
23528
b383017d 23529@item EINTR
0ce1b118
CV
23530The call was interrupted by the user.
23531@end table
23532
23533@node read
23534@unnumberedsubsubsec read
23535@cindex read, file-i/o system call
23536
23537@smallexample
b383017d 23538@exdent Synopsis:
0ce1b118
CV
23539int read(int fd, void *buf, unsigned int count);
23540
b383017d 23541@exdent Request:
0ce1b118
CV
23542Fread,fd,bufptr,count
23543
23544@exdent Return value:
23545On success, the number of bytes read is returned.
23546Zero indicates end of file. If count is zero, read
b383017d 23547returns zero as well. On error, -1 is returned.
0ce1b118
CV
23548
23549@exdent Errors:
23550@end smallexample
23551
23552@table @code
b383017d 23553@item EBADF
0ce1b118
CV
23554fd is not a valid file descriptor or is not open for
23555reading.
23556
b383017d 23557@item EFAULT
0ce1b118
CV
23558buf is an invalid pointer value.
23559
b383017d 23560@item EINTR
0ce1b118
CV
23561The call was interrupted by the user.
23562@end table
23563
23564@node write
23565@unnumberedsubsubsec write
23566@cindex write, file-i/o system call
23567
23568@smallexample
b383017d 23569@exdent Synopsis:
0ce1b118
CV
23570int write(int fd, const void *buf, unsigned int count);
23571
b383017d 23572@exdent Request:
0ce1b118
CV
23573Fwrite,fd,bufptr,count
23574
23575@exdent Return value:
23576On success, the number of bytes written are returned.
23577Zero indicates nothing was written. On error, -1
23578is returned.
23579
23580@exdent Errors:
23581@end smallexample
23582
23583@table @code
b383017d 23584@item EBADF
0ce1b118
CV
23585fd is not a valid file descriptor or is not open for
23586writing.
23587
b383017d 23588@item EFAULT
0ce1b118
CV
23589buf is an invalid pointer value.
23590
b383017d 23591@item EFBIG
0ce1b118
CV
23592An attempt was made to write a file that exceeds the
23593host specific maximum file size allowed.
23594
b383017d 23595@item ENOSPC
0ce1b118
CV
23596No space on device to write the data.
23597
b383017d 23598@item EINTR
0ce1b118
CV
23599The call was interrupted by the user.
23600@end table
23601
23602@node lseek
23603@unnumberedsubsubsec lseek
23604@cindex lseek, file-i/o system call
23605
23606@smallexample
b383017d 23607@exdent Synopsis:
0ce1b118
CV
23608long lseek (int fd, long offset, int flag);
23609
b383017d 23610@exdent Request:
0ce1b118
CV
23611Flseek,fd,offset,flag
23612@end smallexample
23613
23614@code{flag} is one of:
23615
23616@table @code
b383017d 23617@item SEEK_SET
0ce1b118
CV
23618The offset is set to offset bytes.
23619
b383017d 23620@item SEEK_CUR
0ce1b118
CV
23621The offset is set to its current location plus offset
23622bytes.
23623
b383017d 23624@item SEEK_END
0ce1b118
CV
23625The offset is set to the size of the file plus offset
23626bytes.
23627@end table
23628
23629@smallexample
23630@exdent Return value:
23631On success, the resulting unsigned offset in bytes from
23632the beginning of the file is returned. Otherwise, a
23633value of -1 is returned.
23634
23635@exdent Errors:
23636@end smallexample
23637
23638@table @code
b383017d 23639@item EBADF
0ce1b118
CV
23640fd is not a valid open file descriptor.
23641
b383017d 23642@item ESPIPE
0ce1b118
CV
23643fd is associated with the @value{GDBN} console.
23644
b383017d 23645@item EINVAL
0ce1b118
CV
23646flag is not a proper value.
23647
b383017d 23648@item EINTR
0ce1b118
CV
23649The call was interrupted by the user.
23650@end table
23651
23652@node rename
23653@unnumberedsubsubsec rename
23654@cindex rename, file-i/o system call
23655
23656@smallexample
b383017d 23657@exdent Synopsis:
0ce1b118
CV
23658int rename(const char *oldpath, const char *newpath);
23659
b383017d 23660@exdent Request:
0ce1b118
CV
23661Frename,oldpathptr/len,newpathptr/len
23662
23663@exdent Return value:
23664On success, zero is returned. On error, -1 is returned.
23665
23666@exdent Errors:
23667@end smallexample
23668
23669@table @code
b383017d 23670@item EISDIR
0ce1b118
CV
23671newpath is an existing directory, but oldpath is not a
23672directory.
23673
b383017d 23674@item EEXIST
0ce1b118
CV
23675newpath is a non-empty directory.
23676
b383017d 23677@item EBUSY
0ce1b118
CV
23678oldpath or newpath is a directory that is in use by some
23679process.
23680
b383017d 23681@item EINVAL
0ce1b118
CV
23682An attempt was made to make a directory a subdirectory
23683of itself.
23684
b383017d 23685@item ENOTDIR
0ce1b118
CV
23686A component used as a directory in oldpath or new
23687path is not a directory. Or oldpath is a directory
23688and newpath exists but is not a directory.
23689
b383017d 23690@item EFAULT
0ce1b118
CV
23691oldpathptr or newpathptr are invalid pointer values.
23692
b383017d 23693@item EACCES
0ce1b118
CV
23694No access to the file or the path of the file.
23695
23696@item ENAMETOOLONG
b383017d 23697
0ce1b118
CV
23698oldpath or newpath was too long.
23699
b383017d 23700@item ENOENT
0ce1b118
CV
23701A directory component in oldpath or newpath does not exist.
23702
b383017d 23703@item EROFS
0ce1b118
CV
23704The file is on a read-only filesystem.
23705
b383017d 23706@item ENOSPC
0ce1b118
CV
23707The device containing the file has no room for the new
23708directory entry.
23709
b383017d 23710@item EINTR
0ce1b118
CV
23711The call was interrupted by the user.
23712@end table
23713
23714@node unlink
23715@unnumberedsubsubsec unlink
23716@cindex unlink, file-i/o system call
23717
23718@smallexample
b383017d 23719@exdent Synopsis:
0ce1b118
CV
23720int unlink(const char *pathname);
23721
b383017d 23722@exdent Request:
0ce1b118
CV
23723Funlink,pathnameptr/len
23724
23725@exdent Return value:
23726On success, zero is returned. On error, -1 is returned.
23727
23728@exdent Errors:
23729@end smallexample
23730
23731@table @code
b383017d 23732@item EACCES
0ce1b118
CV
23733No access to the file or the path of the file.
23734
b383017d 23735@item EPERM
0ce1b118
CV
23736The system does not allow unlinking of directories.
23737
b383017d 23738@item EBUSY
0ce1b118
CV
23739The file pathname cannot be unlinked because it's
23740being used by another process.
23741
b383017d 23742@item EFAULT
0ce1b118
CV
23743pathnameptr is an invalid pointer value.
23744
23745@item ENAMETOOLONG
23746pathname was too long.
23747
b383017d 23748@item ENOENT
0ce1b118
CV
23749A directory component in pathname does not exist.
23750
b383017d 23751@item ENOTDIR
0ce1b118
CV
23752A component of the path is not a directory.
23753
b383017d 23754@item EROFS
0ce1b118
CV
23755The file is on a read-only filesystem.
23756
b383017d 23757@item EINTR
0ce1b118
CV
23758The call was interrupted by the user.
23759@end table
23760
23761@node stat/fstat
23762@unnumberedsubsubsec stat/fstat
23763@cindex fstat, file-i/o system call
23764@cindex stat, file-i/o system call
23765
23766@smallexample
b383017d 23767@exdent Synopsis:
0ce1b118
CV
23768int stat(const char *pathname, struct stat *buf);
23769int fstat(int fd, struct stat *buf);
23770
b383017d 23771@exdent Request:
0ce1b118
CV
23772Fstat,pathnameptr/len,bufptr
23773Ffstat,fd,bufptr
23774
23775@exdent Return value:
23776On success, zero is returned. On error, -1 is returned.
23777
23778@exdent Errors:
23779@end smallexample
23780
23781@table @code
b383017d 23782@item EBADF
0ce1b118
CV
23783fd is not a valid open file.
23784
b383017d 23785@item ENOENT
0ce1b118
CV
23786A directory component in pathname does not exist or the
23787path is an empty string.
23788
b383017d 23789@item ENOTDIR
0ce1b118
CV
23790A component of the path is not a directory.
23791
b383017d 23792@item EFAULT
0ce1b118
CV
23793pathnameptr is an invalid pointer value.
23794
b383017d 23795@item EACCES
0ce1b118
CV
23796No access to the file or the path of the file.
23797
23798@item ENAMETOOLONG
23799pathname was too long.
23800
b383017d 23801@item EINTR
0ce1b118
CV
23802The call was interrupted by the user.
23803@end table
23804
23805@node gettimeofday
23806@unnumberedsubsubsec gettimeofday
23807@cindex gettimeofday, file-i/o system call
23808
23809@smallexample
b383017d 23810@exdent Synopsis:
0ce1b118
CV
23811int gettimeofday(struct timeval *tv, void *tz);
23812
b383017d 23813@exdent Request:
0ce1b118
CV
23814Fgettimeofday,tvptr,tzptr
23815
23816@exdent Return value:
23817On success, 0 is returned, -1 otherwise.
23818
23819@exdent Errors:
23820@end smallexample
23821
23822@table @code
b383017d 23823@item EINVAL
0ce1b118
CV
23824tz is a non-NULL pointer.
23825
b383017d 23826@item EFAULT
0ce1b118
CV
23827tvptr and/or tzptr is an invalid pointer value.
23828@end table
23829
23830@node isatty
23831@unnumberedsubsubsec isatty
23832@cindex isatty, file-i/o system call
23833
23834@smallexample
b383017d 23835@exdent Synopsis:
0ce1b118
CV
23836int isatty(int fd);
23837
b383017d 23838@exdent Request:
0ce1b118
CV
23839Fisatty,fd
23840
23841@exdent Return value:
23842Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
23843
23844@exdent Errors:
23845@end smallexample
23846
23847@table @code
b383017d 23848@item EINTR
0ce1b118
CV
23849The call was interrupted by the user.
23850@end table
23851
23852@node system
23853@unnumberedsubsubsec system
23854@cindex system, file-i/o system call
23855
23856@smallexample
b383017d 23857@exdent Synopsis:
0ce1b118
CV
23858int system(const char *command);
23859
b383017d 23860@exdent Request:
0ce1b118
CV
23861Fsystem,commandptr/len
23862
23863@exdent Return value:
23864The value returned is -1 on error and the return status
23865of the command otherwise. Only the exit status of the
23866command is returned, which is extracted from the hosts
23867system return value by calling WEXITSTATUS(retval).
23868In case /bin/sh could not be executed, 127 is returned.
23869
23870@exdent Errors:
23871@end smallexample
23872
23873@table @code
b383017d 23874@item EINTR
0ce1b118
CV
23875The call was interrupted by the user.
23876@end table
23877
23878@node Protocol specific representation of datatypes
23879@subsection Protocol specific representation of datatypes
23880@cindex protocol specific representation of datatypes, in file-i/o protocol
23881
23882@menu
23883* Integral datatypes::
23884* Pointer values::
23885* struct stat::
23886* struct timeval::
23887@end menu
23888
23889@node Integral datatypes
23890@unnumberedsubsubsec Integral datatypes
23891@cindex integral datatypes, in file-i/o protocol
23892
23893The integral datatypes used in the system calls are
23894
23895@smallexample
23896int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
23897@end smallexample
23898
23899@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
23900implemented as 32 bit values in this protocol.
23901
b383017d
RM
23902@code{Long} and @code{unsigned long} are implemented as 64 bit types.
23903
0ce1b118
CV
23904@xref{Limits}, for corresponding MIN and MAX values (similar to those
23905in @file{limits.h}) to allow range checking on host and target.
23906
23907@code{time_t} datatypes are defined as seconds since the Epoch.
23908
23909All integral datatypes transferred as part of a memory read or write of a
23910structured datatype e.g.@: a @code{struct stat} have to be given in big endian
23911byte order.
23912
23913@node Pointer values
23914@unnumberedsubsubsec Pointer values
23915@cindex pointer values, in file-i/o protocol
23916
23917Pointers to target data are transmitted as they are. An exception
23918is made for pointers to buffers for which the length isn't
23919transmitted as part of the function call, namely strings. Strings
23920are transmitted as a pointer/length pair, both as hex values, e.g.@:
23921
23922@smallexample
23923@code{1aaf/12}
23924@end smallexample
23925
23926@noindent
23927which is a pointer to data of length 18 bytes at position 0x1aaf.
23928The length is defined as the full string length in bytes, including
23929the trailing null byte. Example:
23930
23931@smallexample
23932``hello, world'' at address 0x123456
23933@end smallexample
23934
23935@noindent
23936is transmitted as
23937
23938@smallexample
23939@code{123456/d}
23940@end smallexample
23941
23942@node struct stat
23943@unnumberedsubsubsec struct stat
23944@cindex struct stat, in file-i/o protocol
23945
23946The buffer of type struct stat used by the target and @value{GDBN} is defined
23947as follows:
23948
23949@smallexample
23950struct stat @{
23951 unsigned int st_dev; /* device */
23952 unsigned int st_ino; /* inode */
23953 mode_t st_mode; /* protection */
23954 unsigned int st_nlink; /* number of hard links */
23955 unsigned int st_uid; /* user ID of owner */
23956 unsigned int st_gid; /* group ID of owner */
23957 unsigned int st_rdev; /* device type (if inode device) */
23958 unsigned long st_size; /* total size, in bytes */
23959 unsigned long st_blksize; /* blocksize for filesystem I/O */
23960 unsigned long st_blocks; /* number of blocks allocated */
23961 time_t st_atime; /* time of last access */
23962 time_t st_mtime; /* time of last modification */
23963 time_t st_ctime; /* time of last change */
23964@};
23965@end smallexample
23966
23967The integral datatypes are conforming to the definitions given in the
23968approriate section (see @ref{Integral datatypes}, for details) so this
23969structure is of size 64 bytes.
23970
23971The values of several fields have a restricted meaning and/or
23972range of values.
23973
23974@smallexample
23975st_dev: 0 file
23976 1 console
23977
23978st_ino: No valid meaning for the target. Transmitted unchanged.
23979
23980st_mode: Valid mode bits are described in Appendix C. Any other
23981 bits have currently no meaning for the target.
23982
23983st_uid: No valid meaning for the target. Transmitted unchanged.
23984
23985st_gid: No valid meaning for the target. Transmitted unchanged.
23986
23987st_rdev: No valid meaning for the target. Transmitted unchanged.
23988
23989st_atime, st_mtime, st_ctime:
23990 These values have a host and file system dependent
23991 accuracy. Especially on Windows hosts the file systems
23992 don't support exact timing values.
23993@end smallexample
23994
23995The target gets a struct stat of the above representation and is
23996responsible to coerce it to the target representation before
23997continuing.
23998
23999Note that due to size differences between the host and target
24000representation of stat members, these members could eventually
24001get truncated on the target.
24002
24003@node struct timeval
24004@unnumberedsubsubsec struct timeval
24005@cindex struct timeval, in file-i/o protocol
24006
24007The buffer of type struct timeval used by the target and @value{GDBN}
24008is defined as follows:
24009
24010@smallexample
b383017d 24011struct timeval @{
0ce1b118
CV
24012 time_t tv_sec; /* second */
24013 long tv_usec; /* microsecond */
24014@};
24015@end smallexample
24016
24017The integral datatypes are conforming to the definitions given in the
24018approriate section (see @ref{Integral datatypes}, for details) so this
24019structure is of size 8 bytes.
24020
24021@node Constants
24022@subsection Constants
24023@cindex constants, in file-i/o protocol
24024
24025The following values are used for the constants inside of the
24026protocol. @value{GDBN} and target are resposible to translate these
24027values before and after the call as needed.
24028
24029@menu
24030* Open flags::
24031* mode_t values::
24032* Errno values::
24033* Lseek flags::
24034* Limits::
24035@end menu
24036
24037@node Open flags
24038@unnumberedsubsubsec Open flags
24039@cindex open flags, in file-i/o protocol
24040
24041All values are given in hexadecimal representation.
24042
24043@smallexample
24044 O_RDONLY 0x0
24045 O_WRONLY 0x1
24046 O_RDWR 0x2
24047 O_APPEND 0x8
24048 O_CREAT 0x200
24049 O_TRUNC 0x400
24050 O_EXCL 0x800
24051@end smallexample
24052
24053@node mode_t values
24054@unnumberedsubsubsec mode_t values
24055@cindex mode_t values, in file-i/o protocol
24056
24057All values are given in octal representation.
24058
24059@smallexample
24060 S_IFREG 0100000
24061 S_IFDIR 040000
24062 S_IRUSR 0400
24063 S_IWUSR 0200
24064 S_IXUSR 0100
24065 S_IRGRP 040
24066 S_IWGRP 020
24067 S_IXGRP 010
24068 S_IROTH 04
24069 S_IWOTH 02
24070 S_IXOTH 01
24071@end smallexample
24072
24073@node Errno values
24074@unnumberedsubsubsec Errno values
24075@cindex errno values, in file-i/o protocol
24076
24077All values are given in decimal representation.
24078
24079@smallexample
24080 EPERM 1
24081 ENOENT 2
24082 EINTR 4
24083 EBADF 9
24084 EACCES 13
24085 EFAULT 14
24086 EBUSY 16
24087 EEXIST 17
24088 ENODEV 19
24089 ENOTDIR 20
24090 EISDIR 21
24091 EINVAL 22
24092 ENFILE 23
24093 EMFILE 24
24094 EFBIG 27
24095 ENOSPC 28
24096 ESPIPE 29
24097 EROFS 30
24098 ENAMETOOLONG 91
24099 EUNKNOWN 9999
24100@end smallexample
24101
24102 EUNKNOWN is used as a fallback error value if a host system returns
24103 any error value not in the list of supported error numbers.
24104
24105@node Lseek flags
24106@unnumberedsubsubsec Lseek flags
24107@cindex lseek flags, in file-i/o protocol
24108
24109@smallexample
24110 SEEK_SET 0
24111 SEEK_CUR 1
24112 SEEK_END 2
24113@end smallexample
24114
24115@node Limits
24116@unnumberedsubsubsec Limits
24117@cindex limits, in file-i/o protocol
24118
24119All values are given in decimal representation.
24120
24121@smallexample
24122 INT_MIN -2147483648
24123 INT_MAX 2147483647
24124 UINT_MAX 4294967295
24125 LONG_MIN -9223372036854775808
24126 LONG_MAX 9223372036854775807
24127 ULONG_MAX 18446744073709551615
24128@end smallexample
24129
24130@node File-I/O Examples
24131@subsection File-I/O Examples
24132@cindex file-i/o examples
24133
24134Example sequence of a write call, file descriptor 3, buffer is at target
24135address 0x1234, 6 bytes should be written:
24136
24137@smallexample
24138<- @code{Fwrite,3,1234,6}
24139@emph{request memory read from target}
24140-> @code{m1234,6}
24141<- XXXXXX
24142@emph{return "6 bytes written"}
24143-> @code{F6}
24144@end smallexample
24145
24146Example sequence of a read call, file descriptor 3, buffer is at target
24147address 0x1234, 6 bytes should be read:
24148
24149@smallexample
24150<- @code{Fread,3,1234,6}
24151@emph{request memory write to target}
24152-> @code{X1234,6:XXXXXX}
24153@emph{return "6 bytes read"}
24154-> @code{F6}
24155@end smallexample
24156
24157Example sequence of a read call, call fails on the host due to invalid
24158file descriptor (EBADF):
24159
24160@smallexample
24161<- @code{Fread,3,1234,6}
24162-> @code{F-1,9}
24163@end smallexample
24164
24165Example sequence of a read call, user presses Ctrl-C before syscall on
24166host is called:
24167
24168@smallexample
24169<- @code{Fread,3,1234,6}
24170-> @code{F-1,4,C}
24171<- @code{T02}
24172@end smallexample
24173
24174Example sequence of a read call, user presses Ctrl-C after syscall on
24175host is called:
24176
24177@smallexample
24178<- @code{Fread,3,1234,6}
24179-> @code{X1234,6:XXXXXX}
24180<- @code{T02}
24181@end smallexample
24182
f418dd93
DJ
24183@include agentexpr.texi
24184
aab4e0ec 24185@include gpl.texi
eb12ee30 24186
2154891a 24187@raisesections
6826cf00 24188@include fdl.texi
2154891a 24189@lowersections
6826cf00 24190
6d2ebf8b 24191@node Index
c906108c
SS
24192@unnumbered Index
24193
24194@printindex cp
24195
24196@tex
24197% I think something like @colophon should be in texinfo. In the
24198% meantime:
24199\long\def\colophon{\hbox to0pt{}\vfill
24200\centerline{The body of this manual is set in}
24201\centerline{\fontname\tenrm,}
24202\centerline{with headings in {\bf\fontname\tenbf}}
24203\centerline{and examples in {\tt\fontname\tentt}.}
24204\centerline{{\it\fontname\tenit\/},}
24205\centerline{{\bf\fontname\tenbf}, and}
24206\centerline{{\sl\fontname\tensl\/}}
24207\centerline{are used for emphasis.}\vfill}
24208\page\colophon
24209% Blame: doc@cygnus.com, 1991.
24210@end tex
24211
c906108c 24212@bye
This page took 2.882323 seconds and 4 git commands to generate.