Reviewed/approved by Daniel Jacobowitz <drow@false.org>
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
b6ba6518 2@c Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
7d51c7de 3@c 1999, 2000, 2001, 2002, 2003, 2004, 2005
c906108c
SS
4@c Free Software Foundation, Inc.
5@c
5d161b24 6@c %**start of header
c906108c
SS
7@c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
8@c of @set vars. However, you can override filename with makeinfo -o.
9@setfilename gdb.info
10@c
11@include gdb-cfg.texi
12@c
c906108c 13@settitle Debugging with @value{GDBN}
c906108c
SS
14@setchapternewpage odd
15@c %**end of header
16
17@iftex
18@c @smallbook
19@c @cropmarks
20@end iftex
21
22@finalout
23@syncodeindex ky cp
24
41afff9a 25@c readline appendices use @vindex, @findex and @ftable,
48e934c6 26@c annotate.texi and gdbmi use @findex.
c906108c 27@syncodeindex vr cp
41afff9a 28@syncodeindex fn cp
c906108c
SS
29
30@c !!set GDB manual's edition---not the same as GDB version!
9fe8321b 31@c This is updated by GNU Press.
e9c75b65 32@set EDITION Ninth
c906108c 33
87885426
FN
34@c !!set GDB edit command default editor
35@set EDITOR /bin/ex
c906108c 36
6c0e9fb3 37@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
c906108c 38
c906108c 39@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 40@c manuals to an info tree.
03727ca6 41@dircategory Software development
96a2c332 42@direntry
03727ca6 43* Gdb: (gdb). The GNU debugger.
96a2c332
SS
44@end direntry
45
c906108c
SS
46@ifinfo
47This file documents the @sc{gnu} debugger @value{GDBN}.
48
49
9fe8321b
AC
50This is the @value{EDITION} Edition, of @cite{Debugging with
51@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
52Version @value{GDBVN}.
c906108c 53
8a037dd7 54Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,@*
7d51c7de
BR
55 1999, 2000, 2001, 2002, 2003, 2004, 2005@*
56 Free Software Foundation, Inc.
c906108c 57
e9c75b65
EZ
58Permission is granted to copy, distribute and/or modify this document
59under the terms of the GNU Free Documentation License, Version 1.1 or
60any later version published by the Free Software Foundation; with the
959acfd1
EZ
61Invariant Sections being ``Free Software'' and ``Free Software Needs
62Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
63and with the Back-Cover Texts as in (a) below.
c906108c 64
6826cf00
EZ
65(a) The Free Software Foundation's Back-Cover Text is: ``You have
66freedom to copy and modify this GNU Manual, like GNU software. Copies
67published by the Free Software Foundation raise funds for GNU
68development.''
c906108c
SS
69@end ifinfo
70
71@titlepage
72@title Debugging with @value{GDBN}
73@subtitle The @sc{gnu} Source-Level Debugger
c906108c 74@sp 1
c906108c 75@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
9e9c5ae7 76@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 77@page
c906108c
SS
78@tex
79{\parskip=0pt
53a5351d 80\hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
c906108c
SS
81\hfill {\it Debugging with @value{GDBN}}\par
82\hfill \TeX{}info \texinfoversion\par
83}
84@end tex
53a5351d 85
c906108c 86@vskip 0pt plus 1filll
8a037dd7 87Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
7d51c7de
BR
881996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
89Free Software Foundation, Inc.
c906108c 90@sp 2
c906108c
SS
91Published by the Free Software Foundation @*
9259 Temple Place - Suite 330, @*
93Boston, MA 02111-1307 USA @*
6d2ebf8b 94ISBN 1-882114-77-9 @*
e9c75b65
EZ
95
96Permission is granted to copy, distribute and/or modify this document
97under the terms of the GNU Free Documentation License, Version 1.1 or
98any later version published by the Free Software Foundation; with the
959acfd1
EZ
99Invariant Sections being ``Free Software'' and ``Free Software Needs
100Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
101and with the Back-Cover Texts as in (a) below.
e9c75b65 102
6826cf00
EZ
103(a) The Free Software Foundation's Back-Cover Text is: ``You have
104freedom to copy and modify this GNU Manual, like GNU software. Copies
105published by the Free Software Foundation raise funds for GNU
106development.''
c906108c
SS
107@end titlepage
108@page
109
6c0e9fb3 110@ifnottex
6d2ebf8b
SS
111@node Top, Summary, (dir), (dir)
112
c906108c
SS
113@top Debugging with @value{GDBN}
114
115This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
9fe8321b 117This is the @value{EDITION} Edition, for @value{GDBN} Version
c906108c
SS
118@value{GDBVN}.
119
7d51c7de 120Copyright (C) 1988-2005 Free Software Foundation, Inc.
6d2ebf8b
SS
121
122@menu
123* Summary:: Summary of @value{GDBN}
124* Sample Session:: A sample @value{GDBN} session
125
126* Invocation:: Getting in and out of @value{GDBN}
127* Commands:: @value{GDBN} commands
128* Running:: Running programs under @value{GDBN}
129* Stopping:: Stopping and continuing
130* Stack:: Examining the stack
131* Source:: Examining source files
132* Data:: Examining data
e2e0bcd1 133* Macros:: Preprocessor Macros
b37052ae 134* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 135* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
136
137* Languages:: Using @value{GDBN} with different languages
138
139* Symbols:: Examining the symbol table
140* Altering:: Altering execution
141* GDB Files:: @value{GDBN} files
142* Targets:: Specifying a debugging target
6b2f586d 143* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
144* Configurations:: Configuration-specific information
145* Controlling GDB:: Controlling @value{GDBN}
146* Sequences:: Canned sequences of commands
c4555f82 147* TUI:: @value{GDBN} Text User Interface
21c294e6 148* Interpreters:: Command Interpreters
6d2ebf8b
SS
149* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
150* Annotations:: @value{GDBN}'s annotation interface.
7162c0ca 151* GDB/MI:: @value{GDBN}'s Machine Interface.
6d2ebf8b
SS
152
153* GDB Bugs:: Reporting bugs in @value{GDBN}
154* Formatting Documentation:: How to format and print @value{GDBN} documentation
155
156* Command Line Editing:: Command Line Editing
157* Using History Interactively:: Using History Interactively
158* Installing GDB:: Installing GDB
eb12ee30 159* Maintenance Commands:: Maintenance Commands
e0ce93ac 160* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 161* Agent Expressions:: The GDB Agent Expression Mechanism
aab4e0ec
AC
162* Copying:: GNU General Public License says
163 how you can copy and share GDB
6826cf00 164* GNU Free Documentation License:: The license for this documentation
6d2ebf8b
SS
165* Index:: Index
166@end menu
167
6c0e9fb3 168@end ifnottex
c906108c 169
449f3b6c 170@contents
449f3b6c 171
6d2ebf8b 172@node Summary
c906108c
SS
173@unnumbered Summary of @value{GDBN}
174
175The purpose of a debugger such as @value{GDBN} is to allow you to see what is
176going on ``inside'' another program while it executes---or what another
177program was doing at the moment it crashed.
178
179@value{GDBN} can do four main kinds of things (plus other things in support of
180these) to help you catch bugs in the act:
181
182@itemize @bullet
183@item
184Start your program, specifying anything that might affect its behavior.
185
186@item
187Make your program stop on specified conditions.
188
189@item
190Examine what has happened, when your program has stopped.
191
192@item
193Change things in your program, so you can experiment with correcting the
194effects of one bug and go on to learn about another.
195@end itemize
196
49efadf5 197You can use @value{GDBN} to debug programs written in C and C@t{++}.
9c16f35a 198For more information, see @ref{Supported languages,,Supported languages}.
c906108c
SS
199For more information, see @ref{C,,C and C++}.
200
cce74817 201@cindex Modula-2
e632838e
AC
202Support for Modula-2 is partial. For information on Modula-2, see
203@ref{Modula-2,,Modula-2}.
c906108c 204
cce74817
JM
205@cindex Pascal
206Debugging Pascal programs which use sets, subranges, file variables, or
207nested functions does not currently work. @value{GDBN} does not support
208entering expressions, printing values, or similar features using Pascal
209syntax.
c906108c 210
c906108c
SS
211@cindex Fortran
212@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 213it may be necessary to refer to some variables with a trailing
cce74817 214underscore.
c906108c 215
b37303ee
AF
216@value{GDBN} can be used to debug programs written in Objective-C,
217using either the Apple/NeXT or the GNU Objective-C runtime.
218
c906108c
SS
219@menu
220* Free Software:: Freely redistributable software
221* Contributors:: Contributors to GDB
222@end menu
223
6d2ebf8b 224@node Free Software
c906108c
SS
225@unnumberedsec Free software
226
5d161b24 227@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
228General Public License
229(GPL). The GPL gives you the freedom to copy or adapt a licensed
230program---but every person getting a copy also gets with it the
231freedom to modify that copy (which means that they must get access to
232the source code), and the freedom to distribute further copies.
233Typical software companies use copyrights to limit your freedoms; the
234Free Software Foundation uses the GPL to preserve these freedoms.
235
236Fundamentally, the General Public License is a license which says that
237you have these freedoms and that you cannot take these freedoms away
238from anyone else.
239
2666264b 240@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
241
242The biggest deficiency in the free software community today is not in
243the software---it is the lack of good free documentation that we can
244include with the free software. Many of our most important
245programs do not come with free reference manuals and free introductory
246texts. Documentation is an essential part of any software package;
247when an important free software package does not come with a free
248manual and a free tutorial, that is a major gap. We have many such
249gaps today.
250
251Consider Perl, for instance. The tutorial manuals that people
252normally use are non-free. How did this come about? Because the
253authors of those manuals published them with restrictive terms---no
254copying, no modification, source files not available---which exclude
255them from the free software world.
256
257That wasn't the first time this sort of thing happened, and it was far
258from the last. Many times we have heard a GNU user eagerly describe a
259manual that he is writing, his intended contribution to the community,
260only to learn that he had ruined everything by signing a publication
261contract to make it non-free.
262
263Free documentation, like free software, is a matter of freedom, not
264price. The problem with the non-free manual is not that publishers
265charge a price for printed copies---that in itself is fine. (The Free
266Software Foundation sells printed copies of manuals, too.) The
267problem is the restrictions on the use of the manual. Free manuals
268are available in source code form, and give you permission to copy and
269modify. Non-free manuals do not allow this.
270
271The criteria of freedom for a free manual are roughly the same as for
272free software. Redistribution (including the normal kinds of
273commercial redistribution) must be permitted, so that the manual can
274accompany every copy of the program, both on-line and on paper.
275
276Permission for modification of the technical content is crucial too.
277When people modify the software, adding or changing features, if they
278are conscientious they will change the manual too---so they can
279provide accurate and clear documentation for the modified program. A
280manual that leaves you no choice but to write a new manual to document
281a changed version of the program is not really available to our
282community.
283
284Some kinds of limits on the way modification is handled are
285acceptable. For example, requirements to preserve the original
286author's copyright notice, the distribution terms, or the list of
287authors, are ok. It is also no problem to require modified versions
288to include notice that they were modified. Even entire sections that
289may not be deleted or changed are acceptable, as long as they deal
290with nontechnical topics (like this one). These kinds of restrictions
291are acceptable because they don't obstruct the community's normal use
292of the manual.
293
294However, it must be possible to modify all the @emph{technical}
295content of the manual, and then distribute the result in all the usual
296media, through all the usual channels. Otherwise, the restrictions
297obstruct the use of the manual, it is not free, and we need another
298manual to replace it.
299
300Please spread the word about this issue. Our community continues to
301lose manuals to proprietary publishing. If we spread the word that
302free software needs free reference manuals and free tutorials, perhaps
303the next person who wants to contribute by writing documentation will
304realize, before it is too late, that only free manuals contribute to
305the free software community.
306
307If you are writing documentation, please insist on publishing it under
308the GNU Free Documentation License or another free documentation
309license. Remember that this decision requires your approval---you
310don't have to let the publisher decide. Some commercial publishers
311will use a free license if you insist, but they will not propose the
312option; it is up to you to raise the issue and say firmly that this is
313what you want. If the publisher you are dealing with refuses, please
314try other publishers. If you're not sure whether a proposed license
42584a72 315is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
316
317You can encourage commercial publishers to sell more free, copylefted
318manuals and tutorials by buying them, and particularly by buying
319copies from the publishers that paid for their writing or for major
320improvements. Meanwhile, try to avoid buying non-free documentation
321at all. Check the distribution terms of a manual before you buy it,
322and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
323Check the history of the book, and try to reward the publishers that
324have paid or pay the authors to work on it.
959acfd1
EZ
325
326The Free Software Foundation maintains a list of free documentation
327published by other publishers, at
328@url{http://www.fsf.org/doc/other-free-books.html}.
329
6d2ebf8b 330@node Contributors
96a2c332
SS
331@unnumberedsec Contributors to @value{GDBN}
332
333Richard Stallman was the original author of @value{GDBN}, and of many
334other @sc{gnu} programs. Many others have contributed to its
335development. This section attempts to credit major contributors. One
336of the virtues of free software is that everyone is free to contribute
337to it; with regret, we cannot actually acknowledge everyone here. The
338file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
339blow-by-blow account.
340
341Changes much prior to version 2.0 are lost in the mists of time.
342
343@quotation
344@emph{Plea:} Additions to this section are particularly welcome. If you
345or your friends (or enemies, to be evenhanded) have been unfairly
346omitted from this list, we would like to add your names!
347@end quotation
348
349So that they may not regard their many labors as thankless, we
350particularly thank those who shepherded @value{GDBN} through major
351releases:
faae5abe 352Andrew Cagney (releases 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
353Jim Blandy (release 4.18);
354Jason Molenda (release 4.17);
355Stan Shebs (release 4.14);
356Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
357Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
358John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
359Jim Kingdon (releases 3.5, 3.4, and 3.3);
360and Randy Smith (releases 3.2, 3.1, and 3.0).
361
362Richard Stallman, assisted at various times by Peter TerMaat, Chris
363Hanson, and Richard Mlynarik, handled releases through 2.8.
364
b37052ae
EZ
365Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
366in @value{GDBN}, with significant additional contributions from Per
367Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
368demangler. Early work on C@t{++} was by Peter TerMaat (who also did
369much general update work leading to release 3.0).
c906108c 370
b37052ae 371@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
372object-file formats; BFD was a joint project of David V.
373Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
374
375David Johnson wrote the original COFF support; Pace Willison did
376the original support for encapsulated COFF.
377
0179ffac 378Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
379
380Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
381Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
382support.
383Jean-Daniel Fekete contributed Sun 386i support.
384Chris Hanson improved the HP9000 support.
385Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
386David Johnson contributed Encore Umax support.
387Jyrki Kuoppala contributed Altos 3068 support.
388Jeff Law contributed HP PA and SOM support.
389Keith Packard contributed NS32K support.
390Doug Rabson contributed Acorn Risc Machine support.
391Bob Rusk contributed Harris Nighthawk CX-UX support.
392Chris Smith contributed Convex support (and Fortran debugging).
393Jonathan Stone contributed Pyramid support.
394Michael Tiemann contributed SPARC support.
395Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
396Pace Willison contributed Intel 386 support.
397Jay Vosburgh contributed Symmetry support.
a37295f9 398Marko Mlinar contributed OpenRISC 1000 support.
c906108c 399
1104b9e7 400Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
401
402Rich Schaefer and Peter Schauer helped with support of SunOS shared
403libraries.
404
405Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
406about several machine instruction sets.
407
408Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
409remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
410contributed remote debugging modules for the i960, VxWorks, A29K UDI,
411and RDI targets, respectively.
412
413Brian Fox is the author of the readline libraries providing
414command-line editing and command history.
415
7a292a7a
SS
416Andrew Beers of SUNY Buffalo wrote the language-switching code, the
417Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 418
5d161b24 419Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 420He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 421symbols.
c906108c 422
f24c5e49
KI
423Hitachi America (now Renesas America), Ltd. sponsored the support for
424H8/300, H8/500, and Super-H processors.
c906108c
SS
425
426NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
427
f24c5e49
KI
428Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
429processors.
c906108c
SS
430
431Toshiba sponsored the support for the TX39 Mips processor.
432
433Matsushita sponsored the support for the MN10200 and MN10300 processors.
434
96a2c332 435Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
436
437Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
438watchpoints.
439
440Michael Snyder added support for tracepoints.
441
442Stu Grossman wrote gdbserver.
443
444Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 445nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
446
447The following people at the Hewlett-Packard Company contributed
448support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 449(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
d0d5df6f
AC
450compiler, and the Text User Interface (nee Terminal User Interface):
451Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
452Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
453provided HP-specific information in this manual.
c906108c 454
b37052ae
EZ
455DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
456Robert Hoehne made significant contributions to the DJGPP port.
457
96a2c332
SS
458Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
459development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
460fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
461Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
462Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
463Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
464Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
465addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
466JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
467Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
468Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
469Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
470Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
471Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
472Zuhn have made contributions both large and small.
c906108c 473
ffed4509
AC
474Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
475Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
476
e2e0bcd1
JB
477Jim Blandy added support for preprocessor macros, while working for Red
478Hat.
c906108c 479
a9967aef
AC
480Andrew Cagney designed @value{GDBN}'s architecture vector. Many
481people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
482Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
483Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
484Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
485with the migration of old architectures to this new framework.
486
6d2ebf8b 487@node Sample Session
c906108c
SS
488@chapter A Sample @value{GDBN} Session
489
490You can use this manual at your leisure to read all about @value{GDBN}.
491However, a handful of commands are enough to get started using the
492debugger. This chapter illustrates those commands.
493
494@iftex
495In this sample session, we emphasize user input like this: @b{input},
496to make it easier to pick out from the surrounding output.
497@end iftex
498
499@c FIXME: this example may not be appropriate for some configs, where
500@c FIXME...primary interest is in remote use.
501
502One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
503processor) exhibits the following bug: sometimes, when we change its
504quote strings from the default, the commands used to capture one macro
505definition within another stop working. In the following short @code{m4}
506session, we define a macro @code{foo} which expands to @code{0000}; we
507then use the @code{m4} built-in @code{defn} to define @code{bar} as the
508same thing. However, when we change the open quote string to
509@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
510procedure fails to define a new synonym @code{baz}:
511
512@smallexample
513$ @b{cd gnu/m4}
514$ @b{./m4}
515@b{define(foo,0000)}
516
517@b{foo}
5180000
519@b{define(bar,defn(`foo'))}
520
521@b{bar}
5220000
523@b{changequote(<QUOTE>,<UNQUOTE>)}
524
525@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
526@b{baz}
527@b{C-d}
528m4: End of input: 0: fatal error: EOF in string
529@end smallexample
530
531@noindent
532Let us use @value{GDBN} to try to see what is going on.
533
c906108c
SS
534@smallexample
535$ @b{@value{GDBP} m4}
536@c FIXME: this falsifies the exact text played out, to permit smallbook
537@c FIXME... format to come out better.
538@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 539 of it under certain conditions; type "show copying" to see
c906108c 540 the conditions.
5d161b24 541There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
542 for details.
543
544@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
545(@value{GDBP})
546@end smallexample
c906108c
SS
547
548@noindent
549@value{GDBN} reads only enough symbol data to know where to find the
550rest when needed; as a result, the first prompt comes up very quickly.
551We now tell @value{GDBN} to use a narrower display width than usual, so
552that examples fit in this manual.
553
554@smallexample
555(@value{GDBP}) @b{set width 70}
556@end smallexample
557
558@noindent
559We need to see how the @code{m4} built-in @code{changequote} works.
560Having looked at the source, we know the relevant subroutine is
561@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
562@code{break} command.
563
564@smallexample
565(@value{GDBP}) @b{break m4_changequote}
566Breakpoint 1 at 0x62f4: file builtin.c, line 879.
567@end smallexample
568
569@noindent
570Using the @code{run} command, we start @code{m4} running under @value{GDBN}
571control; as long as control does not reach the @code{m4_changequote}
572subroutine, the program runs as usual:
573
574@smallexample
575(@value{GDBP}) @b{run}
576Starting program: /work/Editorial/gdb/gnu/m4/m4
577@b{define(foo,0000)}
578
579@b{foo}
5800000
581@end smallexample
582
583@noindent
584To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
585suspends execution of @code{m4}, displaying information about the
586context where it stops.
587
588@smallexample
589@b{changequote(<QUOTE>,<UNQUOTE>)}
590
5d161b24 591Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
592 at builtin.c:879
593879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
594@end smallexample
595
596@noindent
597Now we use the command @code{n} (@code{next}) to advance execution to
598the next line of the current function.
599
600@smallexample
601(@value{GDBP}) @b{n}
602882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
603 : nil,
604@end smallexample
605
606@noindent
607@code{set_quotes} looks like a promising subroutine. We can go into it
608by using the command @code{s} (@code{step}) instead of @code{next}.
609@code{step} goes to the next line to be executed in @emph{any}
610subroutine, so it steps into @code{set_quotes}.
611
612@smallexample
613(@value{GDBP}) @b{s}
614set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
615 at input.c:530
616530 if (lquote != def_lquote)
617@end smallexample
618
619@noindent
620The display that shows the subroutine where @code{m4} is now
621suspended (and its arguments) is called a stack frame display. It
622shows a summary of the stack. We can use the @code{backtrace}
623command (which can also be spelled @code{bt}), to see where we are
624in the stack as a whole: the @code{backtrace} command displays a
625stack frame for each active subroutine.
626
627@smallexample
628(@value{GDBP}) @b{bt}
629#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
630 at input.c:530
5d161b24 631#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
632 at builtin.c:882
633#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
634#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
635 at macro.c:71
636#4 0x79dc in expand_input () at macro.c:40
637#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
638@end smallexample
639
640@noindent
641We step through a few more lines to see what happens. The first two
642times, we can use @samp{s}; the next two times we use @code{n} to avoid
643falling into the @code{xstrdup} subroutine.
644
645@smallexample
646(@value{GDBP}) @b{s}
6470x3b5c 532 if (rquote != def_rquote)
648(@value{GDBP}) @b{s}
6490x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
650def_lquote : xstrdup(lq);
651(@value{GDBP}) @b{n}
652536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
653 : xstrdup(rq);
654(@value{GDBP}) @b{n}
655538 len_lquote = strlen(rquote);
656@end smallexample
657
658@noindent
659The last line displayed looks a little odd; we can examine the variables
660@code{lquote} and @code{rquote} to see if they are in fact the new left
661and right quotes we specified. We use the command @code{p}
662(@code{print}) to see their values.
663
664@smallexample
665(@value{GDBP}) @b{p lquote}
666$1 = 0x35d40 "<QUOTE>"
667(@value{GDBP}) @b{p rquote}
668$2 = 0x35d50 "<UNQUOTE>"
669@end smallexample
670
671@noindent
672@code{lquote} and @code{rquote} are indeed the new left and right quotes.
673To look at some context, we can display ten lines of source
674surrounding the current line with the @code{l} (@code{list}) command.
675
676@smallexample
677(@value{GDBP}) @b{l}
678533 xfree(rquote);
679534
680535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
681 : xstrdup (lq);
682536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
683 : xstrdup (rq);
684537
685538 len_lquote = strlen(rquote);
686539 len_rquote = strlen(lquote);
687540 @}
688541
689542 void
690@end smallexample
691
692@noindent
693Let us step past the two lines that set @code{len_lquote} and
694@code{len_rquote}, and then examine the values of those variables.
695
696@smallexample
697(@value{GDBP}) @b{n}
698539 len_rquote = strlen(lquote);
699(@value{GDBP}) @b{n}
700540 @}
701(@value{GDBP}) @b{p len_lquote}
702$3 = 9
703(@value{GDBP}) @b{p len_rquote}
704$4 = 7
705@end smallexample
706
707@noindent
708That certainly looks wrong, assuming @code{len_lquote} and
709@code{len_rquote} are meant to be the lengths of @code{lquote} and
710@code{rquote} respectively. We can set them to better values using
711the @code{p} command, since it can print the value of
712any expression---and that expression can include subroutine calls and
713assignments.
714
715@smallexample
716(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
717$5 = 7
718(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
719$6 = 9
720@end smallexample
721
722@noindent
723Is that enough to fix the problem of using the new quotes with the
724@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
725executing with the @code{c} (@code{continue}) command, and then try the
726example that caused trouble initially:
727
728@smallexample
729(@value{GDBP}) @b{c}
730Continuing.
731
732@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
733
734baz
7350000
736@end smallexample
737
738@noindent
739Success! The new quotes now work just as well as the default ones. The
740problem seems to have been just the two typos defining the wrong
741lengths. We allow @code{m4} exit by giving it an EOF as input:
742
743@smallexample
744@b{C-d}
745Program exited normally.
746@end smallexample
747
748@noindent
749The message @samp{Program exited normally.} is from @value{GDBN}; it
750indicates @code{m4} has finished executing. We can end our @value{GDBN}
751session with the @value{GDBN} @code{quit} command.
752
753@smallexample
754(@value{GDBP}) @b{quit}
755@end smallexample
c906108c 756
6d2ebf8b 757@node Invocation
c906108c
SS
758@chapter Getting In and Out of @value{GDBN}
759
760This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 761The essentials are:
c906108c 762@itemize @bullet
5d161b24 763@item
53a5351d 764type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 765@item
c906108c
SS
766type @kbd{quit} or @kbd{C-d} to exit.
767@end itemize
768
769@menu
770* Invoking GDB:: How to start @value{GDBN}
771* Quitting GDB:: How to quit @value{GDBN}
772* Shell Commands:: How to use shell commands inside @value{GDBN}
0fac0b41 773* Logging output:: How to log @value{GDBN}'s output to a file
c906108c
SS
774@end menu
775
6d2ebf8b 776@node Invoking GDB
c906108c
SS
777@section Invoking @value{GDBN}
778
c906108c
SS
779Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
780@value{GDBN} reads commands from the terminal until you tell it to exit.
781
782You can also run @code{@value{GDBP}} with a variety of arguments and options,
783to specify more of your debugging environment at the outset.
784
c906108c
SS
785The command-line options described here are designed
786to cover a variety of situations; in some environments, some of these
5d161b24 787options may effectively be unavailable.
c906108c
SS
788
789The most usual way to start @value{GDBN} is with one argument,
790specifying an executable program:
791
474c8240 792@smallexample
c906108c 793@value{GDBP} @var{program}
474c8240 794@end smallexample
c906108c 795
c906108c
SS
796@noindent
797You can also start with both an executable program and a core file
798specified:
799
474c8240 800@smallexample
c906108c 801@value{GDBP} @var{program} @var{core}
474c8240 802@end smallexample
c906108c
SS
803
804You can, instead, specify a process ID as a second argument, if you want
805to debug a running process:
806
474c8240 807@smallexample
c906108c 808@value{GDBP} @var{program} 1234
474c8240 809@end smallexample
c906108c
SS
810
811@noindent
812would attach @value{GDBN} to process @code{1234} (unless you also have a file
813named @file{1234}; @value{GDBN} does check for a core file first).
814
c906108c 815Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
816complete operating system; when you use @value{GDBN} as a remote
817debugger attached to a bare board, there may not be any notion of
818``process'', and there is often no way to get a core dump. @value{GDBN}
819will warn you if it is unable to attach or to read core dumps.
c906108c 820
aa26fa3a
TT
821You can optionally have @code{@value{GDBP}} pass any arguments after the
822executable file to the inferior using @code{--args}. This option stops
823option processing.
474c8240 824@smallexample
aa26fa3a 825gdb --args gcc -O2 -c foo.c
474c8240 826@end smallexample
aa26fa3a
TT
827This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
828@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
829
96a2c332 830You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
831@value{GDBN}'s non-warranty, by specifying @code{-silent}:
832
833@smallexample
834@value{GDBP} -silent
835@end smallexample
836
837@noindent
838You can further control how @value{GDBN} starts up by using command-line
839options. @value{GDBN} itself can remind you of the options available.
840
841@noindent
842Type
843
474c8240 844@smallexample
c906108c 845@value{GDBP} -help
474c8240 846@end smallexample
c906108c
SS
847
848@noindent
849to display all available options and briefly describe their use
850(@samp{@value{GDBP} -h} is a shorter equivalent).
851
852All options and command line arguments you give are processed
853in sequential order. The order makes a difference when the
854@samp{-x} option is used.
855
856
857@menu
c906108c
SS
858* File Options:: Choosing files
859* Mode Options:: Choosing modes
6fc08d32 860* Startup:: What @value{GDBN} does during startup
c906108c
SS
861@end menu
862
6d2ebf8b 863@node File Options
c906108c
SS
864@subsection Choosing files
865
2df3850c 866When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
867specifying an executable file and core file (or process ID). This is
868the same as if the arguments were specified by the @samp{-se} and
19837790
MS
869@samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
870first argument that does not have an associated option flag as
871equivalent to the @samp{-se} option followed by that argument; and the
872second argument that does not have an associated option flag, if any, as
873equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
874If the second argument begins with a decimal digit, @value{GDBN} will
875first attempt to attach to it as a process, and if that fails, attempt
876to open it as a corefile. If you have a corefile whose name begins with
b383017d 877a digit, you can prevent @value{GDBN} from treating it as a pid by
79f12247 878prefixing it with @file{./}, eg. @file{./12345}.
7a292a7a
SS
879
880If @value{GDBN} has not been configured to included core file support,
881such as for most embedded targets, then it will complain about a second
882argument and ignore it.
c906108c
SS
883
884Many options have both long and short forms; both are shown in the
885following list. @value{GDBN} also recognizes the long forms if you truncate
886them, so long as enough of the option is present to be unambiguous.
887(If you prefer, you can flag option arguments with @samp{--} rather
888than @samp{-}, though we illustrate the more usual convention.)
889
d700128c
EZ
890@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
891@c way, both those who look for -foo and --foo in the index, will find
892@c it.
893
c906108c
SS
894@table @code
895@item -symbols @var{file}
896@itemx -s @var{file}
d700128c
EZ
897@cindex @code{--symbols}
898@cindex @code{-s}
c906108c
SS
899Read symbol table from file @var{file}.
900
901@item -exec @var{file}
902@itemx -e @var{file}
d700128c
EZ
903@cindex @code{--exec}
904@cindex @code{-e}
7a292a7a
SS
905Use file @var{file} as the executable file to execute when appropriate,
906and for examining pure data in conjunction with a core dump.
c906108c
SS
907
908@item -se @var{file}
d700128c 909@cindex @code{--se}
c906108c
SS
910Read symbol table from file @var{file} and use it as the executable
911file.
912
c906108c
SS
913@item -core @var{file}
914@itemx -c @var{file}
d700128c
EZ
915@cindex @code{--core}
916@cindex @code{-c}
b383017d 917Use file @var{file} as a core dump to examine.
c906108c
SS
918
919@item -c @var{number}
19837790
MS
920@item -pid @var{number}
921@itemx -p @var{number}
922@cindex @code{--pid}
923@cindex @code{-p}
924Connect to process ID @var{number}, as with the @code{attach} command.
925If there is no such process, @value{GDBN} will attempt to open a core
926file named @var{number}.
c906108c
SS
927
928@item -command @var{file}
929@itemx -x @var{file}
d700128c
EZ
930@cindex @code{--command}
931@cindex @code{-x}
c906108c
SS
932Execute @value{GDBN} commands from file @var{file}. @xref{Command
933Files,, Command files}.
934
935@item -directory @var{directory}
936@itemx -d @var{directory}
d700128c
EZ
937@cindex @code{--directory}
938@cindex @code{-d}
c906108c
SS
939Add @var{directory} to the path to search for source files.
940
c906108c
SS
941@item -m
942@itemx -mapped
d700128c
EZ
943@cindex @code{--mapped}
944@cindex @code{-m}
c906108c
SS
945@emph{Warning: this option depends on operating system facilities that are not
946supported on all systems.}@*
947If memory-mapped files are available on your system through the @code{mmap}
5d161b24 948system call, you can use this option
c906108c
SS
949to have @value{GDBN} write the symbols from your
950program into a reusable file in the current directory. If the program you are debugging is
96a2c332 951called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
c906108c
SS
952Future @value{GDBN} debugging sessions notice the presence of this file,
953and can quickly map in symbol information from it, rather than reading
954the symbol table from the executable program.
955
956The @file{.syms} file is specific to the host machine where @value{GDBN}
957is run. It holds an exact image of the internal @value{GDBN} symbol
958table. It cannot be shared across multiple host platforms.
c906108c 959
c906108c
SS
960@item -r
961@itemx -readnow
d700128c
EZ
962@cindex @code{--readnow}
963@cindex @code{-r}
c906108c
SS
964Read each symbol file's entire symbol table immediately, rather than
965the default, which is to read it incrementally as it is needed.
966This makes startup slower, but makes future operations faster.
53a5351d 967
c906108c
SS
968@end table
969
2df3850c 970You typically combine the @code{-mapped} and @code{-readnow} options in
c906108c 971order to build a @file{.syms} file that contains complete symbol
2df3850c
JM
972information. (@xref{Files,,Commands to specify files}, for information
973on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
974but build a @file{.syms} file for future use is:
c906108c 975
474c8240 976@smallexample
2df3850c 977gdb -batch -nx -mapped -readnow programname
474c8240 978@end smallexample
c906108c 979
6d2ebf8b 980@node Mode Options
c906108c
SS
981@subsection Choosing modes
982
983You can run @value{GDBN} in various alternative modes---for example, in
984batch mode or quiet mode.
985
986@table @code
987@item -nx
988@itemx -n
d700128c
EZ
989@cindex @code{--nx}
990@cindex @code{-n}
96565e91 991Do not execute commands found in any initialization files. Normally,
2df3850c
JM
992@value{GDBN} executes the commands in these files after all the command
993options and arguments have been processed. @xref{Command Files,,Command
994files}.
c906108c
SS
995
996@item -quiet
d700128c 997@itemx -silent
c906108c 998@itemx -q
d700128c
EZ
999@cindex @code{--quiet}
1000@cindex @code{--silent}
1001@cindex @code{-q}
c906108c
SS
1002``Quiet''. Do not print the introductory and copyright messages. These
1003messages are also suppressed in batch mode.
1004
1005@item -batch
d700128c 1006@cindex @code{--batch}
c906108c
SS
1007Run in batch mode. Exit with status @code{0} after processing all the
1008command files specified with @samp{-x} (and all commands from
1009initialization files, if not inhibited with @samp{-n}). Exit with
1010nonzero status if an error occurs in executing the @value{GDBN} commands
1011in the command files.
1012
2df3850c
JM
1013Batch mode may be useful for running @value{GDBN} as a filter, for
1014example to download and run a program on another computer; in order to
1015make this more useful, the message
c906108c 1016
474c8240 1017@smallexample
c906108c 1018Program exited normally.
474c8240 1019@end smallexample
c906108c
SS
1020
1021@noindent
2df3850c
JM
1022(which is ordinarily issued whenever a program running under
1023@value{GDBN} control terminates) is not issued when running in batch
1024mode.
1025
1026@item -nowindows
1027@itemx -nw
d700128c
EZ
1028@cindex @code{--nowindows}
1029@cindex @code{-nw}
2df3850c 1030``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1031(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1032interface. If no GUI is available, this option has no effect.
1033
1034@item -windows
1035@itemx -w
d700128c
EZ
1036@cindex @code{--windows}
1037@cindex @code{-w}
2df3850c
JM
1038If @value{GDBN} includes a GUI, then this option requires it to be
1039used if possible.
c906108c
SS
1040
1041@item -cd @var{directory}
d700128c 1042@cindex @code{--cd}
c906108c
SS
1043Run @value{GDBN} using @var{directory} as its working directory,
1044instead of the current directory.
1045
c906108c
SS
1046@item -fullname
1047@itemx -f
d700128c
EZ
1048@cindex @code{--fullname}
1049@cindex @code{-f}
7a292a7a
SS
1050@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1051subprocess. It tells @value{GDBN} to output the full file name and line
1052number in a standard, recognizable fashion each time a stack frame is
1053displayed (which includes each time your program stops). This
1054recognizable format looks like two @samp{\032} characters, followed by
1055the file name, line number and character position separated by colons,
1056and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1057@samp{\032} characters as a signal to display the source code for the
1058frame.
c906108c 1059
d700128c
EZ
1060@item -epoch
1061@cindex @code{--epoch}
1062The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1063@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1064routines so as to allow Epoch to display values of expressions in a
1065separate window.
1066
1067@item -annotate @var{level}
1068@cindex @code{--annotate}
1069This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1070effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1071(@pxref{Annotations}). The annotation @var{level} controls how much
1072information @value{GDBN} prints together with its prompt, values of
1073expressions, source lines, and other types of output. Level 0 is the
1074normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1075@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1076that control @value{GDBN}, and level 2 has been deprecated.
1077
265eeb58 1078The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1079(@pxref{GDB/MI}).
d700128c 1080
aa26fa3a
TT
1081@item --args
1082@cindex @code{--args}
1083Change interpretation of command line so that arguments following the
1084executable file are passed as command line arguments to the inferior.
1085This option stops option processing.
1086
2df3850c
JM
1087@item -baud @var{bps}
1088@itemx -b @var{bps}
d700128c
EZ
1089@cindex @code{--baud}
1090@cindex @code{-b}
c906108c
SS
1091Set the line speed (baud rate or bits per second) of any serial
1092interface used by @value{GDBN} for remote debugging.
c906108c 1093
f47b1503
AS
1094@item -l @var{timeout}
1095@cindex @code{-l}
1096Set the timeout (in seconds) of any communication used by @value{GDBN}
1097for remote debugging.
1098
c906108c 1099@item -tty @var{device}
d700128c
EZ
1100@itemx -t @var{device}
1101@cindex @code{--tty}
1102@cindex @code{-t}
c906108c
SS
1103Run using @var{device} for your program's standard input and output.
1104@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1105
53a5351d 1106@c resolve the situation of these eventually
c4555f82
SC
1107@item -tui
1108@cindex @code{--tui}
d0d5df6f
AC
1109Activate the @dfn{Text User Interface} when starting. The Text User
1110Interface manages several text windows on the terminal, showing
1111source, assembly, registers and @value{GDBN} command outputs
1112(@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1113Text User Interface can be enabled by invoking the program
1114@samp{gdbtui}. Do not use this option if you run @value{GDBN} from
1115Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1116
1117@c @item -xdb
d700128c 1118@c @cindex @code{--xdb}
53a5351d
JM
1119@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1120@c For information, see the file @file{xdb_trans.html}, which is usually
1121@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1122@c systems.
1123
d700128c
EZ
1124@item -interpreter @var{interp}
1125@cindex @code{--interpreter}
1126Use the interpreter @var{interp} for interface with the controlling
1127program or device. This option is meant to be set by programs which
94bbb2c0 1128communicate with @value{GDBN} using it as a back end.
21c294e6 1129@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1130
da0f9dcd 1131@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1132@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1133The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1134previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1135selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1136@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1137
1138@item -write
1139@cindex @code{--write}
1140Open the executable and core files for both reading and writing. This
1141is equivalent to the @samp{set write on} command inside @value{GDBN}
1142(@pxref{Patching}).
1143
1144@item -statistics
1145@cindex @code{--statistics}
1146This option causes @value{GDBN} to print statistics about time and
1147memory usage after it completes each command and returns to the prompt.
1148
1149@item -version
1150@cindex @code{--version}
1151This option causes @value{GDBN} to print its version number and
1152no-warranty blurb, and exit.
1153
c906108c
SS
1154@end table
1155
6fc08d32
EZ
1156@node Startup
1157@subsection What @value{GDBN} does during startup
1158@cindex @value{GDBN} startup
1159
1160Here's the description of what @value{GDBN} does during session startup:
1161
1162@enumerate
1163@item
1164Sets up the command interpreter as specified by the command line
1165(@pxref{Mode Options, interpreter}).
1166
1167@item
1168@cindex init file
1169Reads the @dfn{init file} (if any) in your home directory@footnote{On
1170DOS/Windows systems, the home directory is the one pointed to by the
1171@code{HOME} environment variable.} and executes all the commands in
1172that file.
1173
1174@item
1175Processes command line options and operands.
1176
1177@item
1178Reads and executes the commands from init file (if any) in the current
119b882a
EZ
1179working directory. This is only done if the current directory is
1180different from your home directory. Thus, you can have more than one
1181init file, one generic in your home directory, and another, specific
1182to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1183@value{GDBN}.
1184
1185@item
1186Reads command files specified by the @samp{-x} option. @xref{Command
1187Files}, for more details about @value{GDBN} command files.
1188
1189@item
1190Reads the command history recorded in the @dfn{history file}.
d620b259 1191@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1192files where @value{GDBN} records it.
1193@end enumerate
1194
1195Init files use the same syntax as @dfn{command files} (@pxref{Command
1196Files}) and are processed by @value{GDBN} in the same way. The init
1197file in your home directory can set options (such as @samp{set
1198complaints}) that affect subsequent processing of command line options
1199and operands. Init files are not executed if you use the @samp{-nx}
1200option (@pxref{Mode Options, ,Choosing modes}).
1201
1202@cindex init file name
1203@cindex @file{.gdbinit}
119b882a 1204The @value{GDBN} init files are normally called @file{.gdbinit}.
6fc08d32
EZ
1205On some configurations of @value{GDBN}, the init file is known by a
1206different name (these are typically environments where a specialized
1207form of @value{GDBN} may need to coexist with other forms, hence a
1208different name for the specialized version's init file). These are the
1209environments with special init file names:
1210
6fc08d32 1211@itemize @bullet
119b882a
EZ
1212@cindex @file{gdb.ini}
1213@item
1214The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1215the limitations of file names imposed by DOS filesystems. The Windows
1216ports of @value{GDBN} use the standard name, but if they find a
1217@file{gdb.ini} file, they warn you about that and suggest to rename
1218the file to the standard name.
1219
1220@cindex @file{.vxgdbinit}
6fc08d32
EZ
1221@item
1222VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
1223
1224@cindex @file{.os68gdbinit}
1225@item
1226OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
1227
1228@cindex @file{.esgdbinit}
1229@item
1230ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
1231
1232@item
1233CISCO 68k: @file{.cisco-gdbinit}
1234@end itemize
1235
1236
6d2ebf8b 1237@node Quitting GDB
c906108c
SS
1238@section Quitting @value{GDBN}
1239@cindex exiting @value{GDBN}
1240@cindex leaving @value{GDBN}
1241
1242@table @code
1243@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1244@kindex q @r{(@code{quit})}
96a2c332
SS
1245@item quit @r{[}@var{expression}@r{]}
1246@itemx q
1247To exit @value{GDBN}, use the @code{quit} command (abbreviated
1248@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1249do not supply @var{expression}, @value{GDBN} will terminate normally;
1250otherwise it will terminate using the result of @var{expression} as the
1251error code.
c906108c
SS
1252@end table
1253
1254@cindex interrupt
1255An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1256terminates the action of any @value{GDBN} command that is in progress and
1257returns to @value{GDBN} command level. It is safe to type the interrupt
1258character at any time because @value{GDBN} does not allow it to take effect
1259until a time when it is safe.
1260
c906108c
SS
1261If you have been using @value{GDBN} to control an attached process or
1262device, you can release it with the @code{detach} command
1263(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1264
6d2ebf8b 1265@node Shell Commands
c906108c
SS
1266@section Shell commands
1267
1268If you need to execute occasional shell commands during your
1269debugging session, there is no need to leave or suspend @value{GDBN}; you can
1270just use the @code{shell} command.
1271
1272@table @code
1273@kindex shell
1274@cindex shell escape
1275@item shell @var{command string}
1276Invoke a standard shell to execute @var{command string}.
c906108c 1277If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1278shell to run. Otherwise @value{GDBN} uses the default shell
1279(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1280@end table
1281
1282The utility @code{make} is often needed in development environments.
1283You do not have to use the @code{shell} command for this purpose in
1284@value{GDBN}:
1285
1286@table @code
1287@kindex make
1288@cindex calling make
1289@item make @var{make-args}
1290Execute the @code{make} program with the specified
1291arguments. This is equivalent to @samp{shell make @var{make-args}}.
1292@end table
1293
0fac0b41
DJ
1294@node Logging output
1295@section Logging output
1296@cindex logging @value{GDBN} output
9c16f35a 1297@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1298
1299You may want to save the output of @value{GDBN} commands to a file.
1300There are several commands to control @value{GDBN}'s logging.
1301
1302@table @code
1303@kindex set logging
1304@item set logging on
1305Enable logging.
1306@item set logging off
1307Disable logging.
9c16f35a 1308@cindex logging file name
0fac0b41
DJ
1309@item set logging file @var{file}
1310Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1311@item set logging overwrite [on|off]
1312By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1313you want @code{set logging on} to overwrite the logfile instead.
1314@item set logging redirect [on|off]
1315By default, @value{GDBN} output will go to both the terminal and the logfile.
1316Set @code{redirect} if you want output to go only to the log file.
1317@kindex show logging
1318@item show logging
1319Show the current values of the logging settings.
1320@end table
1321
6d2ebf8b 1322@node Commands
c906108c
SS
1323@chapter @value{GDBN} Commands
1324
1325You can abbreviate a @value{GDBN} command to the first few letters of the command
1326name, if that abbreviation is unambiguous; and you can repeat certain
1327@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1328key to get @value{GDBN} to fill out the rest of a word in a command (or to
1329show you the alternatives available, if there is more than one possibility).
1330
1331@menu
1332* Command Syntax:: How to give commands to @value{GDBN}
1333* Completion:: Command completion
1334* Help:: How to ask @value{GDBN} for help
1335@end menu
1336
6d2ebf8b 1337@node Command Syntax
c906108c
SS
1338@section Command syntax
1339
1340A @value{GDBN} command is a single line of input. There is no limit on
1341how long it can be. It starts with a command name, which is followed by
1342arguments whose meaning depends on the command name. For example, the
1343command @code{step} accepts an argument which is the number of times to
1344step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1345with no arguments. Some commands do not allow any arguments.
c906108c
SS
1346
1347@cindex abbreviation
1348@value{GDBN} command names may always be truncated if that abbreviation is
1349unambiguous. Other possible command abbreviations are listed in the
1350documentation for individual commands. In some cases, even ambiguous
1351abbreviations are allowed; for example, @code{s} is specially defined as
1352equivalent to @code{step} even though there are other commands whose
1353names start with @code{s}. You can test abbreviations by using them as
1354arguments to the @code{help} command.
1355
1356@cindex repeating commands
41afff9a 1357@kindex RET @r{(repeat last command)}
c906108c 1358A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1359repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1360will not repeat this way; these are commands whose unintentional
1361repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1362repeat. User-defined commands can disable this feature; see
1363@ref{Define, dont-repeat}.
c906108c
SS
1364
1365The @code{list} and @code{x} commands, when you repeat them with
1366@key{RET}, construct new arguments rather than repeating
1367exactly as typed. This permits easy scanning of source or memory.
1368
1369@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1370output, in a way similar to the common utility @code{more}
1371(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1372@key{RET} too many in this situation, @value{GDBN} disables command
1373repetition after any command that generates this sort of display.
1374
41afff9a 1375@kindex # @r{(a comment)}
c906108c
SS
1376@cindex comment
1377Any text from a @kbd{#} to the end of the line is a comment; it does
1378nothing. This is useful mainly in command files (@pxref{Command
1379Files,,Command files}).
1380
88118b3a
TT
1381@cindex repeating command sequences
1382@kindex C-o @r{(operate-and-get-next)}
1383The @kbd{C-o} binding is useful for repeating a complex sequence of
1384commands. This command accepts the current line, like @kbd{RET}, and
1385then fetches the next line relative to the current line from the history
1386for editing.
1387
6d2ebf8b 1388@node Completion
c906108c
SS
1389@section Command completion
1390
1391@cindex completion
1392@cindex word completion
1393@value{GDBN} can fill in the rest of a word in a command for you, if there is
1394only one possibility; it can also show you what the valid possibilities
1395are for the next word in a command, at any time. This works for @value{GDBN}
1396commands, @value{GDBN} subcommands, and the names of symbols in your program.
1397
1398Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1399of a word. If there is only one possibility, @value{GDBN} fills in the
1400word, and waits for you to finish the command (or press @key{RET} to
1401enter it). For example, if you type
1402
1403@c FIXME "@key" does not distinguish its argument sufficiently to permit
1404@c complete accuracy in these examples; space introduced for clarity.
1405@c If texinfo enhancements make it unnecessary, it would be nice to
1406@c replace " @key" by "@key" in the following...
474c8240 1407@smallexample
c906108c 1408(@value{GDBP}) info bre @key{TAB}
474c8240 1409@end smallexample
c906108c
SS
1410
1411@noindent
1412@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1413the only @code{info} subcommand beginning with @samp{bre}:
1414
474c8240 1415@smallexample
c906108c 1416(@value{GDBP}) info breakpoints
474c8240 1417@end smallexample
c906108c
SS
1418
1419@noindent
1420You can either press @key{RET} at this point, to run the @code{info
1421breakpoints} command, or backspace and enter something else, if
1422@samp{breakpoints} does not look like the command you expected. (If you
1423were sure you wanted @code{info breakpoints} in the first place, you
1424might as well just type @key{RET} immediately after @samp{info bre},
1425to exploit command abbreviations rather than command completion).
1426
1427If there is more than one possibility for the next word when you press
1428@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1429characters and try again, or just press @key{TAB} a second time;
1430@value{GDBN} displays all the possible completions for that word. For
1431example, you might want to set a breakpoint on a subroutine whose name
1432begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1433just sounds the bell. Typing @key{TAB} again displays all the
1434function names in your program that begin with those characters, for
1435example:
1436
474c8240 1437@smallexample
c906108c
SS
1438(@value{GDBP}) b make_ @key{TAB}
1439@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1440make_a_section_from_file make_environ
1441make_abs_section make_function_type
1442make_blockvector make_pointer_type
1443make_cleanup make_reference_type
c906108c
SS
1444make_command make_symbol_completion_list
1445(@value{GDBP}) b make_
474c8240 1446@end smallexample
c906108c
SS
1447
1448@noindent
1449After displaying the available possibilities, @value{GDBN} copies your
1450partial input (@samp{b make_} in the example) so you can finish the
1451command.
1452
1453If you just want to see the list of alternatives in the first place, you
b37052ae 1454can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1455means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1456key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1457one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1458
1459@cindex quotes in commands
1460@cindex completion of quoted strings
1461Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1462parentheses or other characters that @value{GDBN} normally excludes from
1463its notion of a word. To permit word completion to work in this
1464situation, you may enclose words in @code{'} (single quote marks) in
1465@value{GDBN} commands.
c906108c 1466
c906108c 1467The most likely situation where you might need this is in typing the
b37052ae
EZ
1468name of a C@t{++} function. This is because C@t{++} allows function
1469overloading (multiple definitions of the same function, distinguished
1470by argument type). For example, when you want to set a breakpoint you
1471may need to distinguish whether you mean the version of @code{name}
1472that takes an @code{int} parameter, @code{name(int)}, or the version
1473that takes a @code{float} parameter, @code{name(float)}. To use the
1474word-completion facilities in this situation, type a single quote
1475@code{'} at the beginning of the function name. This alerts
1476@value{GDBN} that it may need to consider more information than usual
1477when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1478
474c8240 1479@smallexample
96a2c332 1480(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1481bubble(double,double) bubble(int,int)
1482(@value{GDBP}) b 'bubble(
474c8240 1483@end smallexample
c906108c
SS
1484
1485In some cases, @value{GDBN} can tell that completing a name requires using
1486quotes. When this happens, @value{GDBN} inserts the quote for you (while
1487completing as much as it can) if you do not type the quote in the first
1488place:
1489
474c8240 1490@smallexample
c906108c
SS
1491(@value{GDBP}) b bub @key{TAB}
1492@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1493(@value{GDBP}) b 'bubble(
474c8240 1494@end smallexample
c906108c
SS
1495
1496@noindent
1497In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1498you have not yet started typing the argument list when you ask for
1499completion on an overloaded symbol.
1500
d4f3574e 1501For more information about overloaded functions, see @ref{C plus plus
b37052ae 1502expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1503overload-resolution off} to disable overload resolution;
b37052ae 1504see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1505
1506
6d2ebf8b 1507@node Help
c906108c
SS
1508@section Getting help
1509@cindex online documentation
1510@kindex help
1511
5d161b24 1512You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1513using the command @code{help}.
1514
1515@table @code
41afff9a 1516@kindex h @r{(@code{help})}
c906108c
SS
1517@item help
1518@itemx h
1519You can use @code{help} (abbreviated @code{h}) with no arguments to
1520display a short list of named classes of commands:
1521
1522@smallexample
1523(@value{GDBP}) help
1524List of classes of commands:
1525
2df3850c 1526aliases -- Aliases of other commands
c906108c 1527breakpoints -- Making program stop at certain points
2df3850c 1528data -- Examining data
c906108c 1529files -- Specifying and examining files
2df3850c
JM
1530internals -- Maintenance commands
1531obscure -- Obscure features
1532running -- Running the program
1533stack -- Examining the stack
c906108c
SS
1534status -- Status inquiries
1535support -- Support facilities
96a2c332
SS
1536tracepoints -- Tracing of program execution without@*
1537 stopping the program
c906108c 1538user-defined -- User-defined commands
c906108c 1539
5d161b24 1540Type "help" followed by a class name for a list of
c906108c 1541commands in that class.
5d161b24 1542Type "help" followed by command name for full
c906108c
SS
1543documentation.
1544Command name abbreviations are allowed if unambiguous.
1545(@value{GDBP})
1546@end smallexample
96a2c332 1547@c the above line break eliminates huge line overfull...
c906108c
SS
1548
1549@item help @var{class}
1550Using one of the general help classes as an argument, you can get a
1551list of the individual commands in that class. For example, here is the
1552help display for the class @code{status}:
1553
1554@smallexample
1555(@value{GDBP}) help status
1556Status inquiries.
1557
1558List of commands:
1559
1560@c Line break in "show" line falsifies real output, but needed
1561@c to fit in smallbook page size.
2df3850c
JM
1562info -- Generic command for showing things
1563 about the program being debugged
1564show -- Generic command for showing things
1565 about the debugger
c906108c 1566
5d161b24 1567Type "help" followed by command name for full
c906108c
SS
1568documentation.
1569Command name abbreviations are allowed if unambiguous.
1570(@value{GDBP})
1571@end smallexample
1572
1573@item help @var{command}
1574With a command name as @code{help} argument, @value{GDBN} displays a
1575short paragraph on how to use that command.
1576
6837a0a2
DB
1577@kindex apropos
1578@item apropos @var{args}
09d4efe1 1579The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2
DB
1580commands, and their documentation, for the regular expression specified in
1581@var{args}. It prints out all matches found. For example:
1582
1583@smallexample
1584apropos reload
1585@end smallexample
1586
b37052ae
EZ
1587@noindent
1588results in:
6837a0a2
DB
1589
1590@smallexample
6d2ebf8b
SS
1591@c @group
1592set symbol-reloading -- Set dynamic symbol table reloading
1593 multiple times in one run
1594show symbol-reloading -- Show dynamic symbol table reloading
1595 multiple times in one run
1596@c @end group
6837a0a2
DB
1597@end smallexample
1598
c906108c
SS
1599@kindex complete
1600@item complete @var{args}
1601The @code{complete @var{args}} command lists all the possible completions
1602for the beginning of a command. Use @var{args} to specify the beginning of the
1603command you want completed. For example:
1604
1605@smallexample
1606complete i
1607@end smallexample
1608
1609@noindent results in:
1610
1611@smallexample
1612@group
2df3850c
JM
1613if
1614ignore
c906108c
SS
1615info
1616inspect
c906108c
SS
1617@end group
1618@end smallexample
1619
1620@noindent This is intended for use by @sc{gnu} Emacs.
1621@end table
1622
1623In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1624and @code{show} to inquire about the state of your program, or the state
1625of @value{GDBN} itself. Each command supports many topics of inquiry; this
1626manual introduces each of them in the appropriate context. The listings
1627under @code{info} and under @code{show} in the Index point to
1628all the sub-commands. @xref{Index}.
1629
1630@c @group
1631@table @code
1632@kindex info
41afff9a 1633@kindex i @r{(@code{info})}
c906108c
SS
1634@item info
1635This command (abbreviated @code{i}) is for describing the state of your
1636program. For example, you can list the arguments given to your program
1637with @code{info args}, list the registers currently in use with @code{info
1638registers}, or list the breakpoints you have set with @code{info breakpoints}.
1639You can get a complete list of the @code{info} sub-commands with
1640@w{@code{help info}}.
1641
1642@kindex set
1643@item set
5d161b24 1644You can assign the result of an expression to an environment variable with
c906108c
SS
1645@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1646@code{set prompt $}.
1647
1648@kindex show
1649@item show
5d161b24 1650In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1651@value{GDBN} itself.
1652You can change most of the things you can @code{show}, by using the
1653related command @code{set}; for example, you can control what number
1654system is used for displays with @code{set radix}, or simply inquire
1655which is currently in use with @code{show radix}.
1656
1657@kindex info set
1658To display all the settable parameters and their current
1659values, you can use @code{show} with no arguments; you may also use
1660@code{info set}. Both commands produce the same display.
1661@c FIXME: "info set" violates the rule that "info" is for state of
1662@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1663@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1664@end table
1665@c @end group
1666
1667Here are three miscellaneous @code{show} subcommands, all of which are
1668exceptional in lacking corresponding @code{set} commands:
1669
1670@table @code
1671@kindex show version
9c16f35a 1672@cindex @value{GDBN} version number
c906108c
SS
1673@item show version
1674Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1675information in @value{GDBN} bug-reports. If multiple versions of
1676@value{GDBN} are in use at your site, you may need to determine which
1677version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1678commands are introduced, and old ones may wither away. Also, many
1679system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1680variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1681The version number is the same as the one announced when you start
1682@value{GDBN}.
c906108c
SS
1683
1684@kindex show copying
09d4efe1 1685@kindex info copying
9c16f35a 1686@cindex display @value{GDBN} copyright
c906108c 1687@item show copying
09d4efe1 1688@itemx info copying
c906108c
SS
1689Display information about permission for copying @value{GDBN}.
1690
1691@kindex show warranty
09d4efe1 1692@kindex info warranty
c906108c 1693@item show warranty
09d4efe1 1694@itemx info warranty
2df3850c 1695Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1696if your version of @value{GDBN} comes with one.
2df3850c 1697
c906108c
SS
1698@end table
1699
6d2ebf8b 1700@node Running
c906108c
SS
1701@chapter Running Programs Under @value{GDBN}
1702
1703When you run a program under @value{GDBN}, you must first generate
1704debugging information when you compile it.
7a292a7a
SS
1705
1706You may start @value{GDBN} with its arguments, if any, in an environment
1707of your choice. If you are doing native debugging, you may redirect
1708your program's input and output, debug an already running process, or
1709kill a child process.
c906108c
SS
1710
1711@menu
1712* Compilation:: Compiling for debugging
1713* Starting:: Starting your program
c906108c
SS
1714* Arguments:: Your program's arguments
1715* Environment:: Your program's environment
c906108c
SS
1716
1717* Working Directory:: Your program's working directory
1718* Input/Output:: Your program's input and output
1719* Attach:: Debugging an already-running process
1720* Kill Process:: Killing the child process
c906108c
SS
1721
1722* Threads:: Debugging programs with multiple threads
1723* Processes:: Debugging programs with multiple processes
1724@end menu
1725
6d2ebf8b 1726@node Compilation
c906108c
SS
1727@section Compiling for debugging
1728
1729In order to debug a program effectively, you need to generate
1730debugging information when you compile it. This debugging information
1731is stored in the object file; it describes the data type of each
1732variable or function and the correspondence between source line numbers
1733and addresses in the executable code.
1734
1735To request debugging information, specify the @samp{-g} option when you run
1736the compiler.
1737
514c4d71
EZ
1738Programs that are to be shipped to your customers are compiled with
1739optimizations, using the @samp{-O} compiler option. However, many
1740compilers are unable to handle the @samp{-g} and @samp{-O} options
1741together. Using those compilers, you cannot generate optimized
c906108c
SS
1742executables containing debugging information.
1743
514c4d71 1744@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1745without @samp{-O}, making it possible to debug optimized code. We
1746recommend that you @emph{always} use @samp{-g} whenever you compile a
1747program. You may think your program is correct, but there is no sense
1748in pushing your luck.
c906108c
SS
1749
1750@cindex optimized code, debugging
1751@cindex debugging optimized code
1752When you debug a program compiled with @samp{-g -O}, remember that the
1753optimizer is rearranging your code; the debugger shows you what is
1754really there. Do not be too surprised when the execution path does not
1755exactly match your source file! An extreme example: if you define a
1756variable, but never use it, @value{GDBN} never sees that
1757variable---because the compiler optimizes it out of existence.
1758
1759Some things do not work as well with @samp{-g -O} as with just
1760@samp{-g}, particularly on machines with instruction scheduling. If in
1761doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1762please report it to us as a bug (including a test case!).
15387254 1763@xref{Variables}, for more information about debugging optimized code.
c906108c
SS
1764
1765Older versions of the @sc{gnu} C compiler permitted a variant option
1766@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1767format; if your @sc{gnu} C compiler has this option, do not use it.
1768
514c4d71
EZ
1769@value{GDBN} knows about preprocessor macros and can show you their
1770expansion (@pxref{Macros}). Most compilers do not include information
1771about preprocessor macros in the debugging information if you specify
1772the @option{-g} flag alone, because this information is rather large.
1773Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1774provides macro information if you specify the options
1775@option{-gdwarf-2} and @option{-g3}; the former option requests
1776debugging information in the Dwarf 2 format, and the latter requests
1777``extra information''. In the future, we hope to find more compact
1778ways to represent macro information, so that it can be included with
1779@option{-g} alone.
1780
c906108c 1781@need 2000
6d2ebf8b 1782@node Starting
c906108c
SS
1783@section Starting your program
1784@cindex starting
1785@cindex running
1786
1787@table @code
1788@kindex run
41afff9a 1789@kindex r @r{(@code{run})}
c906108c
SS
1790@item run
1791@itemx r
7a292a7a
SS
1792Use the @code{run} command to start your program under @value{GDBN}.
1793You must first specify the program name (except on VxWorks) with an
1794argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1795@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1796(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1797
1798@end table
1799
c906108c
SS
1800If you are running your program in an execution environment that
1801supports processes, @code{run} creates an inferior process and makes
1802that process run your program. (In environments without processes,
1803@code{run} jumps to the start of your program.)
1804
1805The execution of a program is affected by certain information it
1806receives from its superior. @value{GDBN} provides ways to specify this
1807information, which you must do @emph{before} starting your program. (You
1808can change it after starting your program, but such changes only affect
1809your program the next time you start it.) This information may be
1810divided into four categories:
1811
1812@table @asis
1813@item The @emph{arguments.}
1814Specify the arguments to give your program as the arguments of the
1815@code{run} command. If a shell is available on your target, the shell
1816is used to pass the arguments, so that you may use normal conventions
1817(such as wildcard expansion or variable substitution) in describing
1818the arguments.
1819In Unix systems, you can control which shell is used with the
1820@code{SHELL} environment variable.
1821@xref{Arguments, ,Your program's arguments}.
1822
1823@item The @emph{environment.}
1824Your program normally inherits its environment from @value{GDBN}, but you can
1825use the @value{GDBN} commands @code{set environment} and @code{unset
1826environment} to change parts of the environment that affect
1827your program. @xref{Environment, ,Your program's environment}.
1828
1829@item The @emph{working directory.}
1830Your program inherits its working directory from @value{GDBN}. You can set
1831the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1832@xref{Working Directory, ,Your program's working directory}.
1833
1834@item The @emph{standard input and output.}
1835Your program normally uses the same device for standard input and
1836standard output as @value{GDBN} is using. You can redirect input and output
1837in the @code{run} command line, or you can use the @code{tty} command to
1838set a different device for your program.
1839@xref{Input/Output, ,Your program's input and output}.
1840
1841@cindex pipes
1842@emph{Warning:} While input and output redirection work, you cannot use
1843pipes to pass the output of the program you are debugging to another
1844program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1845wrong program.
1846@end table
c906108c
SS
1847
1848When you issue the @code{run} command, your program begins to execute
1849immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1850of how to arrange for your program to stop. Once your program has
1851stopped, you may call functions in your program, using the @code{print}
1852or @code{call} commands. @xref{Data, ,Examining Data}.
1853
1854If the modification time of your symbol file has changed since the last
1855time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1856table, and reads it again. When it does this, @value{GDBN} tries to retain
1857your current breakpoints.
1858
4e8b0763
JB
1859@table @code
1860@kindex start
1861@item start
1862@cindex run to main procedure
1863The name of the main procedure can vary from language to language.
1864With C or C@t{++}, the main procedure name is always @code{main}, but
1865other languages such as Ada do not require a specific name for their
1866main procedure. The debugger provides a convenient way to start the
1867execution of the program and to stop at the beginning of the main
1868procedure, depending on the language used.
1869
1870The @samp{start} command does the equivalent of setting a temporary
1871breakpoint at the beginning of the main procedure and then invoking
1872the @samp{run} command.
1873
f018e82f
EZ
1874@cindex elaboration phase
1875Some programs contain an @dfn{elaboration} phase where some startup code is
1876executed before the main procedure is called. This depends on the
1877languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1878constructors for static and global objects are executed before
1879@code{main} is called. It is therefore possible that the debugger stops
1880before reaching the main procedure. However, the temporary breakpoint
1881will remain to halt execution.
1882
1883Specify the arguments to give to your program as arguments to the
1884@samp{start} command. These arguments will be given verbatim to the
1885underlying @samp{run} command. Note that the same arguments will be
1886reused if no argument is provided during subsequent calls to
1887@samp{start} or @samp{run}.
1888
1889It is sometimes necessary to debug the program during elaboration. In
1890these cases, using the @code{start} command would stop the execution of
1891your program too late, as the program would have already completed the
1892elaboration phase. Under these circumstances, insert breakpoints in your
1893elaboration code before running your program.
1894@end table
1895
6d2ebf8b 1896@node Arguments
c906108c
SS
1897@section Your program's arguments
1898
1899@cindex arguments (to your program)
1900The arguments to your program can be specified by the arguments of the
5d161b24 1901@code{run} command.
c906108c
SS
1902They are passed to a shell, which expands wildcard characters and
1903performs redirection of I/O, and thence to your program. Your
1904@code{SHELL} environment variable (if it exists) specifies what shell
1905@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1906the default shell (@file{/bin/sh} on Unix).
1907
1908On non-Unix systems, the program is usually invoked directly by
1909@value{GDBN}, which emulates I/O redirection via the appropriate system
1910calls, and the wildcard characters are expanded by the startup code of
1911the program, not by the shell.
c906108c
SS
1912
1913@code{run} with no arguments uses the same arguments used by the previous
1914@code{run}, or those set by the @code{set args} command.
1915
c906108c 1916@table @code
41afff9a 1917@kindex set args
c906108c
SS
1918@item set args
1919Specify the arguments to be used the next time your program is run. If
1920@code{set args} has no arguments, @code{run} executes your program
1921with no arguments. Once you have run your program with arguments,
1922using @code{set args} before the next @code{run} is the only way to run
1923it again without arguments.
1924
1925@kindex show args
1926@item show args
1927Show the arguments to give your program when it is started.
1928@end table
1929
6d2ebf8b 1930@node Environment
c906108c
SS
1931@section Your program's environment
1932
1933@cindex environment (of your program)
1934The @dfn{environment} consists of a set of environment variables and
1935their values. Environment variables conventionally record such things as
1936your user name, your home directory, your terminal type, and your search
1937path for programs to run. Usually you set up environment variables with
1938the shell and they are inherited by all the other programs you run. When
1939debugging, it can be useful to try running your program with a modified
1940environment without having to start @value{GDBN} over again.
1941
1942@table @code
1943@kindex path
1944@item path @var{directory}
1945Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1946(the search path for executables) that will be passed to your program.
1947The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1948You may specify several directory names, separated by whitespace or by a
1949system-dependent separator character (@samp{:} on Unix, @samp{;} on
1950MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1951is moved to the front, so it is searched sooner.
c906108c
SS
1952
1953You can use the string @samp{$cwd} to refer to whatever is the current
1954working directory at the time @value{GDBN} searches the path. If you
1955use @samp{.} instead, it refers to the directory where you executed the
1956@code{path} command. @value{GDBN} replaces @samp{.} in the
1957@var{directory} argument (with the current path) before adding
1958@var{directory} to the search path.
1959@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1960@c document that, since repeating it would be a no-op.
1961
1962@kindex show paths
1963@item show paths
1964Display the list of search paths for executables (the @code{PATH}
1965environment variable).
1966
1967@kindex show environment
1968@item show environment @r{[}@var{varname}@r{]}
1969Print the value of environment variable @var{varname} to be given to
1970your program when it starts. If you do not supply @var{varname},
1971print the names and values of all environment variables to be given to
1972your program. You can abbreviate @code{environment} as @code{env}.
1973
1974@kindex set environment
53a5351d 1975@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1976Set environment variable @var{varname} to @var{value}. The value
1977changes for your program only, not for @value{GDBN} itself. @var{value} may
1978be any string; the values of environment variables are just strings, and
1979any interpretation is supplied by your program itself. The @var{value}
1980parameter is optional; if it is eliminated, the variable is set to a
1981null value.
1982@c "any string" here does not include leading, trailing
1983@c blanks. Gnu asks: does anyone care?
1984
1985For example, this command:
1986
474c8240 1987@smallexample
c906108c 1988set env USER = foo
474c8240 1989@end smallexample
c906108c
SS
1990
1991@noindent
d4f3574e 1992tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1993@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1994are not actually required.)
1995
1996@kindex unset environment
1997@item unset environment @var{varname}
1998Remove variable @var{varname} from the environment to be passed to your
1999program. This is different from @samp{set env @var{varname} =};
2000@code{unset environment} removes the variable from the environment,
2001rather than assigning it an empty value.
2002@end table
2003
d4f3574e
SS
2004@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2005the shell indicated
c906108c
SS
2006by your @code{SHELL} environment variable if it exists (or
2007@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2008that runs an initialization file---such as @file{.cshrc} for C-shell, or
2009@file{.bashrc} for BASH---any variables you set in that file affect
2010your program. You may wish to move setting of environment variables to
2011files that are only run when you sign on, such as @file{.login} or
2012@file{.profile}.
2013
6d2ebf8b 2014@node Working Directory
c906108c
SS
2015@section Your program's working directory
2016
2017@cindex working directory (of your program)
2018Each time you start your program with @code{run}, it inherits its
2019working directory from the current working directory of @value{GDBN}.
2020The @value{GDBN} working directory is initially whatever it inherited
2021from its parent process (typically the shell), but you can specify a new
2022working directory in @value{GDBN} with the @code{cd} command.
2023
2024The @value{GDBN} working directory also serves as a default for the commands
2025that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
2026specify files}.
2027
2028@table @code
2029@kindex cd
721c2651 2030@cindex change working directory
c906108c
SS
2031@item cd @var{directory}
2032Set the @value{GDBN} working directory to @var{directory}.
2033
2034@kindex pwd
2035@item pwd
2036Print the @value{GDBN} working directory.
2037@end table
2038
60bf7e09
EZ
2039It is generally impossible to find the current working directory of
2040the process being debugged (since a program can change its directory
2041during its run). If you work on a system where @value{GDBN} is
2042configured with the @file{/proc} support, you can use the @code{info
2043proc} command (@pxref{SVR4 Process Information}) to find out the
2044current working directory of the debuggee.
2045
6d2ebf8b 2046@node Input/Output
c906108c
SS
2047@section Your program's input and output
2048
2049@cindex redirection
2050@cindex i/o
2051@cindex terminal
2052By default, the program you run under @value{GDBN} does input and output to
5d161b24 2053the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2054to its own terminal modes to interact with you, but it records the terminal
2055modes your program was using and switches back to them when you continue
2056running your program.
2057
2058@table @code
2059@kindex info terminal
2060@item info terminal
2061Displays information recorded by @value{GDBN} about the terminal modes your
2062program is using.
2063@end table
2064
2065You can redirect your program's input and/or output using shell
2066redirection with the @code{run} command. For example,
2067
474c8240 2068@smallexample
c906108c 2069run > outfile
474c8240 2070@end smallexample
c906108c
SS
2071
2072@noindent
2073starts your program, diverting its output to the file @file{outfile}.
2074
2075@kindex tty
2076@cindex controlling terminal
2077Another way to specify where your program should do input and output is
2078with the @code{tty} command. This command accepts a file name as
2079argument, and causes this file to be the default for future @code{run}
2080commands. It also resets the controlling terminal for the child
2081process, for future @code{run} commands. For example,
2082
474c8240 2083@smallexample
c906108c 2084tty /dev/ttyb
474c8240 2085@end smallexample
c906108c
SS
2086
2087@noindent
2088directs that processes started with subsequent @code{run} commands
2089default to do input and output on the terminal @file{/dev/ttyb} and have
2090that as their controlling terminal.
2091
2092An explicit redirection in @code{run} overrides the @code{tty} command's
2093effect on the input/output device, but not its effect on the controlling
2094terminal.
2095
2096When you use the @code{tty} command or redirect input in the @code{run}
2097command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2098for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2099for @code{set inferior-tty}.
2100
2101@cindex inferior tty
2102@cindex set inferior controlling terminal
2103You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2104display the name of the terminal that will be used for future runs of your
2105program.
2106
2107@table @code
2108@item set inferior-tty /dev/ttyb
2109@kindex set inferior-tty
2110Set the tty for the program being debugged to /dev/ttyb.
2111
2112@item show inferior-tty
2113@kindex show inferior-tty
2114Show the current tty for the program being debugged.
2115@end table
c906108c 2116
6d2ebf8b 2117@node Attach
c906108c
SS
2118@section Debugging an already-running process
2119@kindex attach
2120@cindex attach
2121
2122@table @code
2123@item attach @var{process-id}
2124This command attaches to a running process---one that was started
2125outside @value{GDBN}. (@code{info files} shows your active
2126targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2127find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2128or with the @samp{jobs -l} shell command.
2129
2130@code{attach} does not repeat if you press @key{RET} a second time after
2131executing the command.
2132@end table
2133
2134To use @code{attach}, your program must be running in an environment
2135which supports processes; for example, @code{attach} does not work for
2136programs on bare-board targets that lack an operating system. You must
2137also have permission to send the process a signal.
2138
2139When you use @code{attach}, the debugger finds the program running in
2140the process first by looking in the current working directory, then (if
2141the program is not found) by using the source file search path
2142(@pxref{Source Path, ,Specifying source directories}). You can also use
2143the @code{file} command to load the program. @xref{Files, ,Commands to
2144Specify Files}.
2145
2146The first thing @value{GDBN} does after arranging to debug the specified
2147process is to stop it. You can examine and modify an attached process
53a5351d
JM
2148with all the @value{GDBN} commands that are ordinarily available when
2149you start processes with @code{run}. You can insert breakpoints; you
2150can step and continue; you can modify storage. If you would rather the
2151process continue running, you may use the @code{continue} command after
c906108c
SS
2152attaching @value{GDBN} to the process.
2153
2154@table @code
2155@kindex detach
2156@item detach
2157When you have finished debugging the attached process, you can use the
2158@code{detach} command to release it from @value{GDBN} control. Detaching
2159the process continues its execution. After the @code{detach} command,
2160that process and @value{GDBN} become completely independent once more, and you
2161are ready to @code{attach} another process or start one with @code{run}.
2162@code{detach} does not repeat if you press @key{RET} again after
2163executing the command.
2164@end table
2165
2166If you exit @value{GDBN} or use the @code{run} command while you have an
2167attached process, you kill that process. By default, @value{GDBN} asks
2168for confirmation if you try to do either of these things; you can
2169control whether or not you need to confirm by using the @code{set
2170confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2171messages}).
2172
6d2ebf8b 2173@node Kill Process
c906108c 2174@section Killing the child process
c906108c
SS
2175
2176@table @code
2177@kindex kill
2178@item kill
2179Kill the child process in which your program is running under @value{GDBN}.
2180@end table
2181
2182This command is useful if you wish to debug a core dump instead of a
2183running process. @value{GDBN} ignores any core dump file while your program
2184is running.
2185
2186On some operating systems, a program cannot be executed outside @value{GDBN}
2187while you have breakpoints set on it inside @value{GDBN}. You can use the
2188@code{kill} command in this situation to permit running your program
2189outside the debugger.
2190
2191The @code{kill} command is also useful if you wish to recompile and
2192relink your program, since on many systems it is impossible to modify an
2193executable file while it is running in a process. In this case, when you
2194next type @code{run}, @value{GDBN} notices that the file has changed, and
2195reads the symbol table again (while trying to preserve your current
2196breakpoint settings).
2197
6d2ebf8b 2198@node Threads
c906108c 2199@section Debugging programs with multiple threads
c906108c
SS
2200
2201@cindex threads of execution
2202@cindex multiple threads
2203@cindex switching threads
2204In some operating systems, such as HP-UX and Solaris, a single program
2205may have more than one @dfn{thread} of execution. The precise semantics
2206of threads differ from one operating system to another, but in general
2207the threads of a single program are akin to multiple processes---except
2208that they share one address space (that is, they can all examine and
2209modify the same variables). On the other hand, each thread has its own
2210registers and execution stack, and perhaps private memory.
2211
2212@value{GDBN} provides these facilities for debugging multi-thread
2213programs:
2214
2215@itemize @bullet
2216@item automatic notification of new threads
2217@item @samp{thread @var{threadno}}, a command to switch among threads
2218@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2219@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2220a command to apply a command to a list of threads
2221@item thread-specific breakpoints
2222@end itemize
2223
c906108c
SS
2224@quotation
2225@emph{Warning:} These facilities are not yet available on every
2226@value{GDBN} configuration where the operating system supports threads.
2227If your @value{GDBN} does not support threads, these commands have no
2228effect. For example, a system without thread support shows no output
2229from @samp{info threads}, and always rejects the @code{thread} command,
2230like this:
2231
2232@smallexample
2233(@value{GDBP}) info threads
2234(@value{GDBP}) thread 1
2235Thread ID 1 not known. Use the "info threads" command to
2236see the IDs of currently known threads.
2237@end smallexample
2238@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2239@c doesn't support threads"?
2240@end quotation
c906108c
SS
2241
2242@cindex focus of debugging
2243@cindex current thread
2244The @value{GDBN} thread debugging facility allows you to observe all
2245threads while your program runs---but whenever @value{GDBN} takes
2246control, one thread in particular is always the focus of debugging.
2247This thread is called the @dfn{current thread}. Debugging commands show
2248program information from the perspective of the current thread.
2249
41afff9a 2250@cindex @code{New} @var{systag} message
c906108c
SS
2251@cindex thread identifier (system)
2252@c FIXME-implementors!! It would be more helpful if the [New...] message
2253@c included GDB's numeric thread handle, so you could just go to that
2254@c thread without first checking `info threads'.
2255Whenever @value{GDBN} detects a new thread in your program, it displays
2256the target system's identification for the thread with a message in the
2257form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2258whose form varies depending on the particular system. For example, on
2259LynxOS, you might see
2260
474c8240 2261@smallexample
c906108c 2262[New process 35 thread 27]
474c8240 2263@end smallexample
c906108c
SS
2264
2265@noindent
2266when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2267the @var{systag} is simply something like @samp{process 368}, with no
2268further qualifier.
2269
2270@c FIXME!! (1) Does the [New...] message appear even for the very first
2271@c thread of a program, or does it only appear for the
6ca652b0 2272@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2273@c program?
2274@c (2) *Is* there necessarily a first thread always? Or do some
2275@c multithread systems permit starting a program with multiple
5d161b24 2276@c threads ab initio?
c906108c
SS
2277
2278@cindex thread number
2279@cindex thread identifier (GDB)
2280For debugging purposes, @value{GDBN} associates its own thread
2281number---always a single integer---with each thread in your program.
2282
2283@table @code
2284@kindex info threads
2285@item info threads
2286Display a summary of all threads currently in your
2287program. @value{GDBN} displays for each thread (in this order):
2288
2289@enumerate
09d4efe1
EZ
2290@item
2291the thread number assigned by @value{GDBN}
c906108c 2292
09d4efe1
EZ
2293@item
2294the target system's thread identifier (@var{systag})
c906108c 2295
09d4efe1
EZ
2296@item
2297the current stack frame summary for that thread
c906108c
SS
2298@end enumerate
2299
2300@noindent
2301An asterisk @samp{*} to the left of the @value{GDBN} thread number
2302indicates the current thread.
2303
5d161b24 2304For example,
c906108c
SS
2305@end table
2306@c end table here to get a little more width for example
2307
2308@smallexample
2309(@value{GDBP}) info threads
2310 3 process 35 thread 27 0x34e5 in sigpause ()
2311 2 process 35 thread 23 0x34e5 in sigpause ()
2312* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2313 at threadtest.c:68
2314@end smallexample
53a5351d
JM
2315
2316On HP-UX systems:
c906108c 2317
4644b6e3
EZ
2318@cindex debugging multithreaded programs (on HP-UX)
2319@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2320For debugging purposes, @value{GDBN} associates its own thread
2321number---a small integer assigned in thread-creation order---with each
2322thread in your program.
2323
41afff9a
EZ
2324@cindex @code{New} @var{systag} message, on HP-UX
2325@cindex thread identifier (system), on HP-UX
c906108c
SS
2326@c FIXME-implementors!! It would be more helpful if the [New...] message
2327@c included GDB's numeric thread handle, so you could just go to that
2328@c thread without first checking `info threads'.
2329Whenever @value{GDBN} detects a new thread in your program, it displays
2330both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2331form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2332whose form varies depending on the particular system. For example, on
2333HP-UX, you see
2334
474c8240 2335@smallexample
c906108c 2336[New thread 2 (system thread 26594)]
474c8240 2337@end smallexample
c906108c
SS
2338
2339@noindent
5d161b24 2340when @value{GDBN} notices a new thread.
c906108c
SS
2341
2342@table @code
4644b6e3 2343@kindex info threads (HP-UX)
c906108c
SS
2344@item info threads
2345Display a summary of all threads currently in your
2346program. @value{GDBN} displays for each thread (in this order):
2347
2348@enumerate
2349@item the thread number assigned by @value{GDBN}
2350
2351@item the target system's thread identifier (@var{systag})
2352
2353@item the current stack frame summary for that thread
2354@end enumerate
2355
2356@noindent
2357An asterisk @samp{*} to the left of the @value{GDBN} thread number
2358indicates the current thread.
2359
5d161b24 2360For example,
c906108c
SS
2361@end table
2362@c end table here to get a little more width for example
2363
474c8240 2364@smallexample
c906108c 2365(@value{GDBP}) info threads
6d2ebf8b
SS
2366 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2367 at quicksort.c:137
2368 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2369 from /usr/lib/libc.2
2370 1 system thread 27905 0x7b003498 in _brk () \@*
2371 from /usr/lib/libc.2
474c8240 2372@end smallexample
c906108c 2373
c45da7e6
EZ
2374On Solaris, you can display more information about user threads with a
2375Solaris-specific command:
2376
2377@table @code
2378@item maint info sol-threads
2379@kindex maint info sol-threads
2380@cindex thread info (Solaris)
2381Display info on Solaris user threads.
2382@end table
2383
c906108c
SS
2384@table @code
2385@kindex thread @var{threadno}
2386@item thread @var{threadno}
2387Make thread number @var{threadno} the current thread. The command
2388argument @var{threadno} is the internal @value{GDBN} thread number, as
2389shown in the first field of the @samp{info threads} display.
2390@value{GDBN} responds by displaying the system identifier of the thread
2391you selected, and its current stack frame summary:
2392
2393@smallexample
2394@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2395(@value{GDBP}) thread 2
c906108c 2396[Switching to process 35 thread 23]
c906108c
SS
23970x34e5 in sigpause ()
2398@end smallexample
2399
2400@noindent
2401As with the @samp{[New @dots{}]} message, the form of the text after
2402@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2403threads.
c906108c 2404
9c16f35a 2405@kindex thread apply
638ac427 2406@cindex apply command to several threads
c906108c
SS
2407@item thread apply [@var{threadno}] [@var{all}] @var{args}
2408The @code{thread apply} command allows you to apply a command to one or
2409more threads. Specify the numbers of the threads that you want affected
2410with the command argument @var{threadno}. @var{threadno} is the internal
2411@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2412threads} display. To apply a command to all threads, use
2413@code{thread apply all} @var{args}.
c906108c
SS
2414@end table
2415
2416@cindex automatic thread selection
2417@cindex switching threads automatically
2418@cindex threads, automatic switching
2419Whenever @value{GDBN} stops your program, due to a breakpoint or a
2420signal, it automatically selects the thread where that breakpoint or
2421signal happened. @value{GDBN} alerts you to the context switch with a
2422message of the form @samp{[Switching to @var{systag}]} to identify the
2423thread.
2424
2425@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2426more information about how @value{GDBN} behaves when you stop and start
2427programs with multiple threads.
2428
2429@xref{Set Watchpoints,,Setting watchpoints}, for information about
2430watchpoints in programs with multiple threads.
c906108c 2431
6d2ebf8b 2432@node Processes
c906108c
SS
2433@section Debugging programs with multiple processes
2434
2435@cindex fork, debugging programs which call
2436@cindex multiple processes
2437@cindex processes, multiple
53a5351d
JM
2438On most systems, @value{GDBN} has no special support for debugging
2439programs which create additional processes using the @code{fork}
2440function. When a program forks, @value{GDBN} will continue to debug the
2441parent process and the child process will run unimpeded. If you have
2442set a breakpoint in any code which the child then executes, the child
2443will get a @code{SIGTRAP} signal which (unless it catches the signal)
2444will cause it to terminate.
c906108c
SS
2445
2446However, if you want to debug the child process there is a workaround
2447which isn't too painful. Put a call to @code{sleep} in the code which
2448the child process executes after the fork. It may be useful to sleep
2449only if a certain environment variable is set, or a certain file exists,
2450so that the delay need not occur when you don't want to run @value{GDBN}
2451on the child. While the child is sleeping, use the @code{ps} program to
2452get its process ID. Then tell @value{GDBN} (a new invocation of
2453@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2454the child process (@pxref{Attach}). From that point on you can debug
c906108c 2455the child process just like any other process which you attached to.
c906108c 2456
b51970ac
DJ
2457On some systems, @value{GDBN} provides support for debugging programs that
2458create additional processes using the @code{fork} or @code{vfork} functions.
2459Currently, the only platforms with this feature are HP-UX (11.x and later
2460only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2461
2462By default, when a program forks, @value{GDBN} will continue to debug
2463the parent process and the child process will run unimpeded.
2464
2465If you want to follow the child process instead of the parent process,
2466use the command @w{@code{set follow-fork-mode}}.
2467
2468@table @code
2469@kindex set follow-fork-mode
2470@item set follow-fork-mode @var{mode}
2471Set the debugger response to a program call of @code{fork} or
2472@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 2473process. The @var{mode} argument can be:
c906108c
SS
2474
2475@table @code
2476@item parent
2477The original process is debugged after a fork. The child process runs
2df3850c 2478unimpeded. This is the default.
c906108c
SS
2479
2480@item child
2481The new process is debugged after a fork. The parent process runs
2482unimpeded.
2483
c906108c
SS
2484@end table
2485
9c16f35a 2486@kindex show follow-fork-mode
c906108c 2487@item show follow-fork-mode
2df3850c 2488Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2489@end table
2490
2491If you ask to debug a child process and a @code{vfork} is followed by an
2492@code{exec}, @value{GDBN} executes the new target up to the first
2493breakpoint in the new target. If you have a breakpoint set on
2494@code{main} in your original program, the breakpoint will also be set on
2495the child process's @code{main}.
2496
2497When a child process is spawned by @code{vfork}, you cannot debug the
2498child or parent until an @code{exec} call completes.
2499
2500If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2501call executes, the new target restarts. To restart the parent process,
2502use the @code{file} command with the parent executable name as its
2503argument.
2504
2505You can use the @code{catch} command to make @value{GDBN} stop whenever
2506a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2507Catchpoints, ,Setting catchpoints}.
c906108c 2508
6d2ebf8b 2509@node Stopping
c906108c
SS
2510@chapter Stopping and Continuing
2511
2512The principal purposes of using a debugger are so that you can stop your
2513program before it terminates; or so that, if your program runs into
2514trouble, you can investigate and find out why.
2515
7a292a7a
SS
2516Inside @value{GDBN}, your program may stop for any of several reasons,
2517such as a signal, a breakpoint, or reaching a new line after a
2518@value{GDBN} command such as @code{step}. You may then examine and
2519change variables, set new breakpoints or remove old ones, and then
2520continue execution. Usually, the messages shown by @value{GDBN} provide
2521ample explanation of the status of your program---but you can also
2522explicitly request this information at any time.
c906108c
SS
2523
2524@table @code
2525@kindex info program
2526@item info program
2527Display information about the status of your program: whether it is
7a292a7a 2528running or not, what process it is, and why it stopped.
c906108c
SS
2529@end table
2530
2531@menu
2532* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2533* Continuing and Stepping:: Resuming execution
c906108c 2534* Signals:: Signals
c906108c 2535* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2536@end menu
2537
6d2ebf8b 2538@node Breakpoints
c906108c
SS
2539@section Breakpoints, watchpoints, and catchpoints
2540
2541@cindex breakpoints
2542A @dfn{breakpoint} makes your program stop whenever a certain point in
2543the program is reached. For each breakpoint, you can add conditions to
2544control in finer detail whether your program stops. You can set
2545breakpoints with the @code{break} command and its variants (@pxref{Set
2546Breaks, ,Setting breakpoints}), to specify the place where your program
2547should stop by line number, function name or exact address in the
2548program.
2549
09d4efe1
EZ
2550On some systems, you can set breakpoints in shared libraries before
2551the executable is run. There is a minor limitation on HP-UX systems:
2552you must wait until the executable is run in order to set breakpoints
2553in shared library routines that are not called directly by the program
2554(for example, routines that are arguments in a @code{pthread_create}
2555call).
c906108c
SS
2556
2557@cindex watchpoints
2558@cindex memory tracing
2559@cindex breakpoint on memory address
2560@cindex breakpoint on variable modification
2561A @dfn{watchpoint} is a special breakpoint that stops your program
2562when the value of an expression changes. You must use a different
2563command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2564watchpoints}), but aside from that, you can manage a watchpoint like
2565any other breakpoint: you enable, disable, and delete both breakpoints
2566and watchpoints using the same commands.
2567
2568You can arrange to have values from your program displayed automatically
2569whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2570Automatic display}.
2571
2572@cindex catchpoints
2573@cindex breakpoint on events
2574A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2575when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2576exception or the loading of a library. As with watchpoints, you use a
2577different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2578catchpoints}), but aside from that, you can manage a catchpoint like any
2579other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2580@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2581
2582@cindex breakpoint numbers
2583@cindex numbers for breakpoints
2584@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2585catchpoint when you create it; these numbers are successive integers
2586starting with one. In many of the commands for controlling various
2587features of breakpoints you use the breakpoint number to say which
2588breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2589@dfn{disabled}; if disabled, it has no effect on your program until you
2590enable it again.
2591
c5394b80
JM
2592@cindex breakpoint ranges
2593@cindex ranges of breakpoints
2594Some @value{GDBN} commands accept a range of breakpoints on which to
2595operate. A breakpoint range is either a single breakpoint number, like
2596@samp{5}, or two such numbers, in increasing order, separated by a
2597hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2598all breakpoint in that range are operated on.
2599
c906108c
SS
2600@menu
2601* Set Breaks:: Setting breakpoints
2602* Set Watchpoints:: Setting watchpoints
2603* Set Catchpoints:: Setting catchpoints
2604* Delete Breaks:: Deleting breakpoints
2605* Disabling:: Disabling breakpoints
2606* Conditions:: Break conditions
2607* Break Commands:: Breakpoint command lists
c906108c 2608* Breakpoint Menus:: Breakpoint menus
d4f3574e 2609* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2610* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2611@end menu
2612
6d2ebf8b 2613@node Set Breaks
c906108c
SS
2614@subsection Setting breakpoints
2615
5d161b24 2616@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2617@c consider in particular declaration with/without initialization.
2618@c
2619@c FIXME 2 is there stuff on this already? break at fun start, already init?
2620
2621@kindex break
41afff9a
EZ
2622@kindex b @r{(@code{break})}
2623@vindex $bpnum@r{, convenience variable}
c906108c
SS
2624@cindex latest breakpoint
2625Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2626@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2627number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2628Vars,, Convenience variables}, for a discussion of what you can do with
2629convenience variables.
2630
2631You have several ways to say where the breakpoint should go.
2632
2633@table @code
2634@item break @var{function}
5d161b24 2635Set a breakpoint at entry to function @var{function}.
c906108c 2636When using source languages that permit overloading of symbols, such as
b37052ae 2637C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2638@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2639
2640@item break +@var{offset}
2641@itemx break -@var{offset}
2642Set a breakpoint some number of lines forward or back from the position
d4f3574e 2643at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2644(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2645
2646@item break @var{linenum}
2647Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2648The current source file is the last file whose source text was printed.
2649The breakpoint will stop your program just before it executes any of the
c906108c
SS
2650code on that line.
2651
2652@item break @var{filename}:@var{linenum}
2653Set a breakpoint at line @var{linenum} in source file @var{filename}.
2654
2655@item break @var{filename}:@var{function}
2656Set a breakpoint at entry to function @var{function} found in file
2657@var{filename}. Specifying a file name as well as a function name is
2658superfluous except when multiple files contain similarly named
2659functions.
2660
2661@item break *@var{address}
2662Set a breakpoint at address @var{address}. You can use this to set
2663breakpoints in parts of your program which do not have debugging
2664information or source files.
2665
2666@item break
2667When called without any arguments, @code{break} sets a breakpoint at
2668the next instruction to be executed in the selected stack frame
2669(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2670innermost, this makes your program stop as soon as control
2671returns to that frame. This is similar to the effect of a
2672@code{finish} command in the frame inside the selected frame---except
2673that @code{finish} does not leave an active breakpoint. If you use
2674@code{break} without an argument in the innermost frame, @value{GDBN} stops
2675the next time it reaches the current location; this may be useful
2676inside loops.
2677
2678@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2679least one instruction has been executed. If it did not do this, you
2680would be unable to proceed past a breakpoint without first disabling the
2681breakpoint. This rule applies whether or not the breakpoint already
2682existed when your program stopped.
2683
2684@item break @dots{} if @var{cond}
2685Set a breakpoint with condition @var{cond}; evaluate the expression
2686@var{cond} each time the breakpoint is reached, and stop only if the
2687value is nonzero---that is, if @var{cond} evaluates as true.
2688@samp{@dots{}} stands for one of the possible arguments described
2689above (or no argument) specifying where to break. @xref{Conditions,
2690,Break conditions}, for more information on breakpoint conditions.
2691
2692@kindex tbreak
2693@item tbreak @var{args}
2694Set a breakpoint enabled only for one stop. @var{args} are the
2695same as for the @code{break} command, and the breakpoint is set in the same
2696way, but the breakpoint is automatically deleted after the first time your
2697program stops there. @xref{Disabling, ,Disabling breakpoints}.
2698
c906108c 2699@kindex hbreak
ba04e063 2700@cindex hardware breakpoints
c906108c 2701@item hbreak @var{args}
d4f3574e
SS
2702Set a hardware-assisted breakpoint. @var{args} are the same as for the
2703@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2704breakpoint requires hardware support and some target hardware may not
2705have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2706debugging, so you can set a breakpoint at an instruction without
2707changing the instruction. This can be used with the new trap-generation
09d4efe1 2708provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
2709will generate traps when a program accesses some data or instruction
2710address that is assigned to the debug registers. However the hardware
2711breakpoint registers can take a limited number of breakpoints. For
2712example, on the DSU, only two data breakpoints can be set at a time, and
2713@value{GDBN} will reject this command if more than two are used. Delete
2714or disable unused hardware breakpoints before setting new ones
2715(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
9c16f35a
EZ
2716For remote targets, you can restrict the number of hardware
2717breakpoints @value{GDBN} will use, see @ref{set remote
2718hardware-breakpoint-limit}.
501eef12 2719
c906108c
SS
2720
2721@kindex thbreak
2722@item thbreak @var{args}
2723Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2724are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2725the same way. However, like the @code{tbreak} command,
c906108c
SS
2726the breakpoint is automatically deleted after the
2727first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2728command, the breakpoint requires hardware support and some target hardware
2729may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2730See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2731
2732@kindex rbreak
2733@cindex regular expression
c45da7e6
EZ
2734@cindex breakpoints in functions matching a regexp
2735@cindex set breakpoints in many functions
c906108c 2736@item rbreak @var{regex}
c906108c 2737Set breakpoints on all functions matching the regular expression
11cf8741
JM
2738@var{regex}. This command sets an unconditional breakpoint on all
2739matches, printing a list of all breakpoints it set. Once these
2740breakpoints are set, they are treated just like the breakpoints set with
2741the @code{break} command. You can delete them, disable them, or make
2742them conditional the same way as any other breakpoint.
2743
2744The syntax of the regular expression is the standard one used with tools
2745like @file{grep}. Note that this is different from the syntax used by
2746shells, so for instance @code{foo*} matches all functions that include
2747an @code{fo} followed by zero or more @code{o}s. There is an implicit
2748@code{.*} leading and trailing the regular expression you supply, so to
2749match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2750
f7dc1244 2751@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2752When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2753breakpoints on overloaded functions that are not members of any special
2754classes.
c906108c 2755
f7dc1244
EZ
2756@cindex set breakpoints on all functions
2757The @code{rbreak} command can be used to set breakpoints in
2758@strong{all} the functions in a program, like this:
2759
2760@smallexample
2761(@value{GDBP}) rbreak .
2762@end smallexample
2763
c906108c
SS
2764@kindex info breakpoints
2765@cindex @code{$_} and @code{info breakpoints}
2766@item info breakpoints @r{[}@var{n}@r{]}
2767@itemx info break @r{[}@var{n}@r{]}
2768@itemx info watchpoints @r{[}@var{n}@r{]}
2769Print a table of all breakpoints, watchpoints, and catchpoints set and
2770not deleted, with the following columns for each breakpoint:
2771
2772@table @emph
2773@item Breakpoint Numbers
2774@item Type
2775Breakpoint, watchpoint, or catchpoint.
2776@item Disposition
2777Whether the breakpoint is marked to be disabled or deleted when hit.
2778@item Enabled or Disabled
2779Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2780that are not enabled.
2781@item Address
2650777c
JJ
2782Where the breakpoint is in your program, as a memory address. If the
2783breakpoint is pending (see below for details) on a future load of a shared library, the address
2784will be listed as @samp{<PENDING>}.
c906108c
SS
2785@item What
2786Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
2787line number. For a pending breakpoint, the original string passed to
2788the breakpoint command will be listed as it cannot be resolved until
2789the appropriate shared library is loaded in the future.
c906108c
SS
2790@end table
2791
2792@noindent
2793If a breakpoint is conditional, @code{info break} shows the condition on
2794the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
2795are listed after that. A pending breakpoint is allowed to have a condition
2796specified for it. The condition is not parsed for validity until a shared
2797library is loaded that allows the pending breakpoint to resolve to a
2798valid location.
c906108c
SS
2799
2800@noindent
2801@code{info break} with a breakpoint
2802number @var{n} as argument lists only that breakpoint. The
2803convenience variable @code{$_} and the default examining-address for
2804the @code{x} command are set to the address of the last breakpoint
5d161b24 2805listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2806
2807@noindent
2808@code{info break} displays a count of the number of times the breakpoint
2809has been hit. This is especially useful in conjunction with the
2810@code{ignore} command. You can ignore a large number of breakpoint
2811hits, look at the breakpoint info to see how many times the breakpoint
2812was hit, and then run again, ignoring one less than that number. This
2813will get you quickly to the last hit of that breakpoint.
2814@end table
2815
2816@value{GDBN} allows you to set any number of breakpoints at the same place in
2817your program. There is nothing silly or meaningless about this. When
2818the breakpoints are conditional, this is even useful
2819(@pxref{Conditions, ,Break conditions}).
2820
2650777c 2821@cindex pending breakpoints
dd79a6cf
JJ
2822If a specified breakpoint location cannot be found, it may be due to the fact
2823that the location is in a shared library that is yet to be loaded. In such
2824a case, you may want @value{GDBN} to create a special breakpoint (known as
2825a @dfn{pending breakpoint}) that
2826attempts to resolve itself in the future when an appropriate shared library
2827gets loaded.
2828
2829Pending breakpoints are useful to set at the start of your
2650777c
JJ
2830@value{GDBN} session for locations that you know will be dynamically loaded
2831later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
2832a check is made to see if the load resolves any pending breakpoint locations.
2833If a pending breakpoint location gets resolved,
2834a regular breakpoint is created and the original pending breakpoint is removed.
2835
2836@value{GDBN} provides some additional commands for controlling pending
2837breakpoint support:
2838
2839@kindex set breakpoint pending
2840@kindex show breakpoint pending
2841@table @code
2842@item set breakpoint pending auto
2843This is the default behavior. When @value{GDBN} cannot find the breakpoint
2844location, it queries you whether a pending breakpoint should be created.
2845
2846@item set breakpoint pending on
2847This indicates that an unrecognized breakpoint location should automatically
2848result in a pending breakpoint being created.
2849
2850@item set breakpoint pending off
2851This indicates that pending breakpoints are not to be created. Any
2852unrecognized breakpoint location results in an error. This setting does
2853not affect any pending breakpoints previously created.
2854
2855@item show breakpoint pending
2856Show the current behavior setting for creating pending breakpoints.
2857@end table
2650777c 2858
649e03f6
RM
2859@cindex operations allowed on pending breakpoints
2860Normal breakpoint operations apply to pending breakpoints as well. You may
2861specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
2862breakpoint is reached. You can also enable or disable
2863the pending breakpoint. When you specify a condition for a pending breakpoint,
2864the parsing of the condition will be deferred until the point where the
2865pending breakpoint location is resolved. Disabling a pending breakpoint
2866tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
2867shared library load. When a pending breakpoint is re-enabled,
649e03f6 2868@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
2869This is done because any number of shared library loads could have
2870occurred since the time the breakpoint was disabled and one or more
2871of these loads could resolve the location.
2872
c906108c
SS
2873@cindex negative breakpoint numbers
2874@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2875@value{GDBN} itself sometimes sets breakpoints in your program for
2876special purposes, such as proper handling of @code{longjmp} (in C
2877programs). These internal breakpoints are assigned negative numbers,
2878starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2879You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2880@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2881
2882
6d2ebf8b 2883@node Set Watchpoints
c906108c
SS
2884@subsection Setting watchpoints
2885
2886@cindex setting watchpoints
c906108c
SS
2887You can use a watchpoint to stop execution whenever the value of an
2888expression changes, without having to predict a particular place where
2889this may happen.
2890
82f2d802
EZ
2891@cindex software watchpoints
2892@cindex hardware watchpoints
c906108c 2893Depending on your system, watchpoints may be implemented in software or
2df3850c 2894hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2895program and testing the variable's value each time, which is hundreds of
2896times slower than normal execution. (But this may still be worth it, to
2897catch errors where you have no clue what part of your program is the
2898culprit.)
2899
82f2d802
EZ
2900On some systems, such as HP-UX, @sc{gnu}/Linux and most other
2901x86-based targets, @value{GDBN} includes support for hardware
2902watchpoints, which do not slow down the running of your program.
c906108c
SS
2903
2904@table @code
2905@kindex watch
2906@item watch @var{expr}
2907Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2908is written into by the program and its value changes.
2909
2910@kindex rwatch
2911@item rwatch @var{expr}
09d4efe1
EZ
2912Set a watchpoint that will break when the value of @var{expr} is read
2913by the program.
c906108c
SS
2914
2915@kindex awatch
2916@item awatch @var{expr}
09d4efe1
EZ
2917Set a watchpoint that will break when @var{expr} is either read from
2918or written into by the program.
c906108c
SS
2919
2920@kindex info watchpoints
2921@item info watchpoints
2922This command prints a list of watchpoints, breakpoints, and catchpoints;
09d4efe1 2923it is the same as @code{info break} (@pxref{Set Breaks}).
c906108c
SS
2924@end table
2925
2926@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2927watchpoints execute very quickly, and the debugger reports a change in
2928value at the exact instruction where the change occurs. If @value{GDBN}
2929cannot set a hardware watchpoint, it sets a software watchpoint, which
2930executes more slowly and reports the change in value at the next
82f2d802
EZ
2931@emph{statement}, not the instruction, after the change occurs.
2932
82f2d802
EZ
2933@cindex use only software watchpoints
2934You can force @value{GDBN} to use only software watchpoints with the
2935@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
2936zero, @value{GDBN} will never try to use hardware watchpoints, even if
2937the underlying system supports them. (Note that hardware-assisted
2938watchpoints that were set @emph{before} setting
2939@code{can-use-hw-watchpoints} to zero will still use the hardware
2940mechanism of watching expressiion values.)
c906108c 2941
9c16f35a
EZ
2942@table @code
2943@item set can-use-hw-watchpoints
2944@kindex set can-use-hw-watchpoints
2945Set whether or not to use hardware watchpoints.
2946
2947@item show can-use-hw-watchpoints
2948@kindex show can-use-hw-watchpoints
2949Show the current mode of using hardware watchpoints.
2950@end table
2951
2952For remote targets, you can restrict the number of hardware
2953watchpoints @value{GDBN} will use, see @ref{set remote
2954hardware-breakpoint-limit}.
2955
c906108c
SS
2956When you issue the @code{watch} command, @value{GDBN} reports
2957
474c8240 2958@smallexample
c906108c 2959Hardware watchpoint @var{num}: @var{expr}
474c8240 2960@end smallexample
c906108c
SS
2961
2962@noindent
2963if it was able to set a hardware watchpoint.
2964
7be570e7
JM
2965Currently, the @code{awatch} and @code{rwatch} commands can only set
2966hardware watchpoints, because accesses to data that don't change the
2967value of the watched expression cannot be detected without examining
2968every instruction as it is being executed, and @value{GDBN} does not do
2969that currently. If @value{GDBN} finds that it is unable to set a
2970hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2971will print a message like this:
2972
2973@smallexample
2974Expression cannot be implemented with read/access watchpoint.
2975@end smallexample
2976
2977Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2978data type of the watched expression is wider than what a hardware
2979watchpoint on the target machine can handle. For example, some systems
2980can only watch regions that are up to 4 bytes wide; on such systems you
2981cannot set hardware watchpoints for an expression that yields a
2982double-precision floating-point number (which is typically 8 bytes
2983wide). As a work-around, it might be possible to break the large region
2984into a series of smaller ones and watch them with separate watchpoints.
2985
2986If you set too many hardware watchpoints, @value{GDBN} might be unable
2987to insert all of them when you resume the execution of your program.
2988Since the precise number of active watchpoints is unknown until such
2989time as the program is about to be resumed, @value{GDBN} might not be
2990able to warn you about this when you set the watchpoints, and the
2991warning will be printed only when the program is resumed:
2992
2993@smallexample
2994Hardware watchpoint @var{num}: Could not insert watchpoint
2995@end smallexample
2996
2997@noindent
2998If this happens, delete or disable some of the watchpoints.
2999
3000The SPARClite DSU will generate traps when a program accesses some data
3001or instruction address that is assigned to the debug registers. For the
3002data addresses, DSU facilitates the @code{watch} command. However the
3003hardware breakpoint registers can only take two data watchpoints, and
3004both watchpoints must be the same kind. For example, you can set two
3005watchpoints with @code{watch} commands, two with @code{rwatch} commands,
3006@strong{or} two with @code{awatch} commands, but you cannot set one
3007watchpoint with one command and the other with a different command.
c906108c
SS
3008@value{GDBN} will reject the command if you try to mix watchpoints.
3009Delete or disable unused watchpoint commands before setting new ones.
3010
3011If you call a function interactively using @code{print} or @code{call},
2df3850c 3012any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
3013kind of breakpoint or the call completes.
3014
7be570e7
JM
3015@value{GDBN} automatically deletes watchpoints that watch local
3016(automatic) variables, or expressions that involve such variables, when
3017they go out of scope, that is, when the execution leaves the block in
3018which these variables were defined. In particular, when the program
3019being debugged terminates, @emph{all} local variables go out of scope,
3020and so only watchpoints that watch global variables remain set. If you
3021rerun the program, you will need to set all such watchpoints again. One
3022way of doing that would be to set a code breakpoint at the entry to the
3023@code{main} function and when it breaks, set all the watchpoints.
3024
c906108c
SS
3025@quotation
3026@cindex watchpoints and threads
3027@cindex threads and watchpoints
c906108c
SS
3028@emph{Warning:} In multi-thread programs, watchpoints have only limited
3029usefulness. With the current watchpoint implementation, @value{GDBN}
3030can only watch the value of an expression @emph{in a single thread}. If
3031you are confident that the expression can only change due to the current
3032thread's activity (and if you are also confident that no other thread
3033can become current), then you can use watchpoints as usual. However,
3034@value{GDBN} may not notice when a non-current thread's activity changes
3035the expression.
53a5351d 3036
d4f3574e 3037@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
3038@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
3039have only limited usefulness. If @value{GDBN} creates a software
3040watchpoint, it can only watch the value of an expression @emph{in a
3041single thread}. If you are confident that the expression can only
3042change due to the current thread's activity (and if you are also
3043confident that no other thread can become current), then you can use
3044software watchpoints as usual. However, @value{GDBN} may not notice
3045when a non-current thread's activity changes the expression. (Hardware
3046watchpoints, in contrast, watch an expression in all threads.)
c906108c 3047@end quotation
c906108c 3048
501eef12
AC
3049@xref{set remote hardware-watchpoint-limit}.
3050
6d2ebf8b 3051@node Set Catchpoints
c906108c 3052@subsection Setting catchpoints
d4f3574e 3053@cindex catchpoints, setting
c906108c
SS
3054@cindex exception handlers
3055@cindex event handling
3056
3057You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 3058kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
3059shared library. Use the @code{catch} command to set a catchpoint.
3060
3061@table @code
3062@kindex catch
3063@item catch @var{event}
3064Stop when @var{event} occurs. @var{event} can be any of the following:
3065@table @code
3066@item throw
4644b6e3 3067@cindex stop on C@t{++} exceptions
b37052ae 3068The throwing of a C@t{++} exception.
c906108c
SS
3069
3070@item catch
b37052ae 3071The catching of a C@t{++} exception.
c906108c
SS
3072
3073@item exec
4644b6e3 3074@cindex break on fork/exec
c906108c
SS
3075A call to @code{exec}. This is currently only available for HP-UX.
3076
3077@item fork
c906108c
SS
3078A call to @code{fork}. This is currently only available for HP-UX.
3079
3080@item vfork
c906108c
SS
3081A call to @code{vfork}. This is currently only available for HP-UX.
3082
3083@item load
3084@itemx load @var{libname}
4644b6e3 3085@cindex break on load/unload of shared library
c906108c
SS
3086The dynamic loading of any shared library, or the loading of the library
3087@var{libname}. This is currently only available for HP-UX.
3088
3089@item unload
3090@itemx unload @var{libname}
c906108c
SS
3091The unloading of any dynamically loaded shared library, or the unloading
3092of the library @var{libname}. This is currently only available for HP-UX.
3093@end table
3094
3095@item tcatch @var{event}
3096Set a catchpoint that is enabled only for one stop. The catchpoint is
3097automatically deleted after the first time the event is caught.
3098
3099@end table
3100
3101Use the @code{info break} command to list the current catchpoints.
3102
b37052ae 3103There are currently some limitations to C@t{++} exception handling
c906108c
SS
3104(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3105
3106@itemize @bullet
3107@item
3108If you call a function interactively, @value{GDBN} normally returns
3109control to you when the function has finished executing. If the call
3110raises an exception, however, the call may bypass the mechanism that
3111returns control to you and cause your program either to abort or to
3112simply continue running until it hits a breakpoint, catches a signal
3113that @value{GDBN} is listening for, or exits. This is the case even if
3114you set a catchpoint for the exception; catchpoints on exceptions are
3115disabled within interactive calls.
3116
3117@item
3118You cannot raise an exception interactively.
3119
3120@item
3121You cannot install an exception handler interactively.
3122@end itemize
3123
3124@cindex raise exceptions
3125Sometimes @code{catch} is not the best way to debug exception handling:
3126if you need to know exactly where an exception is raised, it is better to
3127stop @emph{before} the exception handler is called, since that way you
3128can see the stack before any unwinding takes place. If you set a
3129breakpoint in an exception handler instead, it may not be easy to find
3130out where the exception was raised.
3131
3132To stop just before an exception handler is called, you need some
b37052ae 3133knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
3134raised by calling a library function named @code{__raise_exception}
3135which has the following ANSI C interface:
3136
474c8240 3137@smallexample
c906108c 3138 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
3139 @var{id} is the exception identifier. */
3140 void __raise_exception (void **addr, void *id);
474c8240 3141@end smallexample
c906108c
SS
3142
3143@noindent
3144To make the debugger catch all exceptions before any stack
3145unwinding takes place, set a breakpoint on @code{__raise_exception}
3146(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
3147
3148With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
3149that depends on the value of @var{id}, you can stop your program when
3150a specific exception is raised. You can use multiple conditional
3151breakpoints to stop your program when any of a number of exceptions are
3152raised.
3153
3154
6d2ebf8b 3155@node Delete Breaks
c906108c
SS
3156@subsection Deleting breakpoints
3157
3158@cindex clearing breakpoints, watchpoints, catchpoints
3159@cindex deleting breakpoints, watchpoints, catchpoints
3160It is often necessary to eliminate a breakpoint, watchpoint, or
3161catchpoint once it has done its job and you no longer want your program
3162to stop there. This is called @dfn{deleting} the breakpoint. A
3163breakpoint that has been deleted no longer exists; it is forgotten.
3164
3165With the @code{clear} command you can delete breakpoints according to
3166where they are in your program. With the @code{delete} command you can
3167delete individual breakpoints, watchpoints, or catchpoints by specifying
3168their breakpoint numbers.
3169
3170It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3171automatically ignores breakpoints on the first instruction to be executed
3172when you continue execution without changing the execution address.
3173
3174@table @code
3175@kindex clear
3176@item clear
3177Delete any breakpoints at the next instruction to be executed in the
3178selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3179the innermost frame is selected, this is a good way to delete a
3180breakpoint where your program just stopped.
3181
3182@item clear @var{function}
3183@itemx clear @var{filename}:@var{function}
09d4efe1 3184Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
3185
3186@item clear @var{linenum}
3187@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
3188Delete any breakpoints set at or within the code of the specified
3189@var{linenum} of the specified @var{filename}.
c906108c
SS
3190
3191@cindex delete breakpoints
3192@kindex delete
41afff9a 3193@kindex d @r{(@code{delete})}
c5394b80
JM
3194@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3195Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3196ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3197breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3198confirm off}). You can abbreviate this command as @code{d}.
3199@end table
3200
6d2ebf8b 3201@node Disabling
c906108c
SS
3202@subsection Disabling breakpoints
3203
4644b6e3 3204@cindex enable/disable a breakpoint
c906108c
SS
3205Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3206prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3207it had been deleted, but remembers the information on the breakpoint so
3208that you can @dfn{enable} it again later.
3209
3210You disable and enable breakpoints, watchpoints, and catchpoints with
3211the @code{enable} and @code{disable} commands, optionally specifying one
3212or more breakpoint numbers as arguments. Use @code{info break} or
3213@code{info watch} to print a list of breakpoints, watchpoints, and
3214catchpoints if you do not know which numbers to use.
3215
3216A breakpoint, watchpoint, or catchpoint can have any of four different
3217states of enablement:
3218
3219@itemize @bullet
3220@item
3221Enabled. The breakpoint stops your program. A breakpoint set
3222with the @code{break} command starts out in this state.
3223@item
3224Disabled. The breakpoint has no effect on your program.
3225@item
3226Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3227disabled.
c906108c
SS
3228@item
3229Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3230immediately after it does so it is deleted permanently. A breakpoint
3231set with the @code{tbreak} command starts out in this state.
c906108c
SS
3232@end itemize
3233
3234You can use the following commands to enable or disable breakpoints,
3235watchpoints, and catchpoints:
3236
3237@table @code
c906108c 3238@kindex disable
41afff9a 3239@kindex dis @r{(@code{disable})}
c5394b80 3240@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3241Disable the specified breakpoints---or all breakpoints, if none are
3242listed. A disabled breakpoint has no effect but is not forgotten. All
3243options such as ignore-counts, conditions and commands are remembered in
3244case the breakpoint is enabled again later. You may abbreviate
3245@code{disable} as @code{dis}.
3246
c906108c 3247@kindex enable
c5394b80 3248@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3249Enable the specified breakpoints (or all defined breakpoints). They
3250become effective once again in stopping your program.
3251
c5394b80 3252@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3253Enable the specified breakpoints temporarily. @value{GDBN} disables any
3254of these breakpoints immediately after stopping your program.
3255
c5394b80 3256@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3257Enable the specified breakpoints to work once, then die. @value{GDBN}
3258deletes any of these breakpoints as soon as your program stops there.
09d4efe1 3259Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
3260@end table
3261
d4f3574e
SS
3262@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3263@c confusing: tbreak is also initially enabled.
c906108c
SS
3264Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3265,Setting breakpoints}), breakpoints that you set are initially enabled;
3266subsequently, they become disabled or enabled only when you use one of
3267the commands above. (The command @code{until} can set and delete a
3268breakpoint of its own, but it does not change the state of your other
3269breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3270stepping}.)
3271
6d2ebf8b 3272@node Conditions
c906108c
SS
3273@subsection Break conditions
3274@cindex conditional breakpoints
3275@cindex breakpoint conditions
3276
3277@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3278@c in particular for a watchpoint?
c906108c
SS
3279The simplest sort of breakpoint breaks every time your program reaches a
3280specified place. You can also specify a @dfn{condition} for a
3281breakpoint. A condition is just a Boolean expression in your
3282programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3283a condition evaluates the expression each time your program reaches it,
3284and your program stops only if the condition is @emph{true}.
3285
3286This is the converse of using assertions for program validation; in that
3287situation, you want to stop when the assertion is violated---that is,
3288when the condition is false. In C, if you want to test an assertion expressed
3289by the condition @var{assert}, you should set the condition
3290@samp{! @var{assert}} on the appropriate breakpoint.
3291
3292Conditions are also accepted for watchpoints; you may not need them,
3293since a watchpoint is inspecting the value of an expression anyhow---but
3294it might be simpler, say, to just set a watchpoint on a variable name,
3295and specify a condition that tests whether the new value is an interesting
3296one.
3297
3298Break conditions can have side effects, and may even call functions in
3299your program. This can be useful, for example, to activate functions
3300that log program progress, or to use your own print functions to
3301format special data structures. The effects are completely predictable
3302unless there is another enabled breakpoint at the same address. (In
3303that case, @value{GDBN} might see the other breakpoint first and stop your
3304program without checking the condition of this one.) Note that
d4f3574e
SS
3305breakpoint commands are usually more convenient and flexible than break
3306conditions for the
c906108c
SS
3307purpose of performing side effects when a breakpoint is reached
3308(@pxref{Break Commands, ,Breakpoint command lists}).
3309
3310Break conditions can be specified when a breakpoint is set, by using
3311@samp{if} in the arguments to the @code{break} command. @xref{Set
3312Breaks, ,Setting breakpoints}. They can also be changed at any time
3313with the @code{condition} command.
53a5351d 3314
c906108c
SS
3315You can also use the @code{if} keyword with the @code{watch} command.
3316The @code{catch} command does not recognize the @code{if} keyword;
3317@code{condition} is the only way to impose a further condition on a
3318catchpoint.
c906108c
SS
3319
3320@table @code
3321@kindex condition
3322@item condition @var{bnum} @var{expression}
3323Specify @var{expression} as the break condition for breakpoint,
3324watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3325breakpoint @var{bnum} stops your program only if the value of
3326@var{expression} is true (nonzero, in C). When you use
3327@code{condition}, @value{GDBN} checks @var{expression} immediately for
3328syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3329referents in the context of your breakpoint. If @var{expression} uses
3330symbols not referenced in the context of the breakpoint, @value{GDBN}
3331prints an error message:
3332
474c8240 3333@smallexample
d4f3574e 3334No symbol "foo" in current context.
474c8240 3335@end smallexample
d4f3574e
SS
3336
3337@noindent
c906108c
SS
3338@value{GDBN} does
3339not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3340command (or a command that sets a breakpoint with a condition, like
3341@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3342
3343@item condition @var{bnum}
3344Remove the condition from breakpoint number @var{bnum}. It becomes
3345an ordinary unconditional breakpoint.
3346@end table
3347
3348@cindex ignore count (of breakpoint)
3349A special case of a breakpoint condition is to stop only when the
3350breakpoint has been reached a certain number of times. This is so
3351useful that there is a special way to do it, using the @dfn{ignore
3352count} of the breakpoint. Every breakpoint has an ignore count, which
3353is an integer. Most of the time, the ignore count is zero, and
3354therefore has no effect. But if your program reaches a breakpoint whose
3355ignore count is positive, then instead of stopping, it just decrements
3356the ignore count by one and continues. As a result, if the ignore count
3357value is @var{n}, the breakpoint does not stop the next @var{n} times
3358your program reaches it.
3359
3360@table @code
3361@kindex ignore
3362@item ignore @var{bnum} @var{count}
3363Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3364The next @var{count} times the breakpoint is reached, your program's
3365execution does not stop; other than to decrement the ignore count, @value{GDBN}
3366takes no action.
3367
3368To make the breakpoint stop the next time it is reached, specify
3369a count of zero.
3370
3371When you use @code{continue} to resume execution of your program from a
3372breakpoint, you can specify an ignore count directly as an argument to
3373@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3374Stepping,,Continuing and stepping}.
3375
3376If a breakpoint has a positive ignore count and a condition, the
3377condition is not checked. Once the ignore count reaches zero,
3378@value{GDBN} resumes checking the condition.
3379
3380You could achieve the effect of the ignore count with a condition such
3381as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3382is decremented each time. @xref{Convenience Vars, ,Convenience
3383variables}.
3384@end table
3385
3386Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3387
3388
6d2ebf8b 3389@node Break Commands
c906108c
SS
3390@subsection Breakpoint command lists
3391
3392@cindex breakpoint commands
3393You can give any breakpoint (or watchpoint or catchpoint) a series of
3394commands to execute when your program stops due to that breakpoint. For
3395example, you might want to print the values of certain expressions, or
3396enable other breakpoints.
3397
3398@table @code
3399@kindex commands
3400@kindex end
3401@item commands @r{[}@var{bnum}@r{]}
3402@itemx @dots{} @var{command-list} @dots{}
3403@itemx end
3404Specify a list of commands for breakpoint number @var{bnum}. The commands
3405themselves appear on the following lines. Type a line containing just
3406@code{end} to terminate the commands.
3407
3408To remove all commands from a breakpoint, type @code{commands} and
3409follow it immediately with @code{end}; that is, give no commands.
3410
3411With no @var{bnum} argument, @code{commands} refers to the last
3412breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3413recently encountered).
3414@end table
3415
3416Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3417disabled within a @var{command-list}.
3418
3419You can use breakpoint commands to start your program up again. Simply
3420use the @code{continue} command, or @code{step}, or any other command
3421that resumes execution.
3422
3423Any other commands in the command list, after a command that resumes
3424execution, are ignored. This is because any time you resume execution
3425(even with a simple @code{next} or @code{step}), you may encounter
3426another breakpoint---which could have its own command list, leading to
3427ambiguities about which list to execute.
3428
3429@kindex silent
3430If the first command you specify in a command list is @code{silent}, the
3431usual message about stopping at a breakpoint is not printed. This may
3432be desirable for breakpoints that are to print a specific message and
3433then continue. If none of the remaining commands print anything, you
3434see no sign that the breakpoint was reached. @code{silent} is
3435meaningful only at the beginning of a breakpoint command list.
3436
3437The commands @code{echo}, @code{output}, and @code{printf} allow you to
3438print precisely controlled output, and are often useful in silent
3439breakpoints. @xref{Output, ,Commands for controlled output}.
3440
3441For example, here is how you could use breakpoint commands to print the
3442value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3443
474c8240 3444@smallexample
c906108c
SS
3445break foo if x>0
3446commands
3447silent
3448printf "x is %d\n",x
3449cont
3450end
474c8240 3451@end smallexample
c906108c
SS
3452
3453One application for breakpoint commands is to compensate for one bug so
3454you can test for another. Put a breakpoint just after the erroneous line
3455of code, give it a condition to detect the case in which something
3456erroneous has been done, and give it commands to assign correct values
3457to any variables that need them. End with the @code{continue} command
3458so that your program does not stop, and start with the @code{silent}
3459command so that no output is produced. Here is an example:
3460
474c8240 3461@smallexample
c906108c
SS
3462break 403
3463commands
3464silent
3465set x = y + 4
3466cont
3467end
474c8240 3468@end smallexample
c906108c 3469
6d2ebf8b 3470@node Breakpoint Menus
c906108c
SS
3471@subsection Breakpoint menus
3472@cindex overloading
3473@cindex symbol overloading
3474
b383017d 3475Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3476single function name
c906108c
SS
3477to be defined several times, for application in different contexts.
3478This is called @dfn{overloading}. When a function name is overloaded,
3479@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3480a breakpoint. If you realize this is a problem, you can use
3481something like @samp{break @var{function}(@var{types})} to specify which
3482particular version of the function you want. Otherwise, @value{GDBN} offers
3483you a menu of numbered choices for different possible breakpoints, and
3484waits for your selection with the prompt @samp{>}. The first two
3485options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3486sets a breakpoint at each definition of @var{function}, and typing
3487@kbd{0} aborts the @code{break} command without setting any new
3488breakpoints.
3489
3490For example, the following session excerpt shows an attempt to set a
3491breakpoint at the overloaded symbol @code{String::after}.
3492We choose three particular definitions of that function name:
3493
3494@c FIXME! This is likely to change to show arg type lists, at least
3495@smallexample
3496@group
3497(@value{GDBP}) b String::after
3498[0] cancel
3499[1] all
3500[2] file:String.cc; line number:867
3501[3] file:String.cc; line number:860
3502[4] file:String.cc; line number:875
3503[5] file:String.cc; line number:853
3504[6] file:String.cc; line number:846
3505[7] file:String.cc; line number:735
3506> 2 4 6
3507Breakpoint 1 at 0xb26c: file String.cc, line 867.
3508Breakpoint 2 at 0xb344: file String.cc, line 875.
3509Breakpoint 3 at 0xafcc: file String.cc, line 846.
3510Multiple breakpoints were set.
3511Use the "delete" command to delete unwanted
3512 breakpoints.
3513(@value{GDBP})
3514@end group
3515@end smallexample
c906108c
SS
3516
3517@c @ifclear BARETARGET
6d2ebf8b 3518@node Error in Breakpoints
d4f3574e 3519@subsection ``Cannot insert breakpoints''
c906108c
SS
3520@c
3521@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3522@c
d4f3574e
SS
3523Under some operating systems, breakpoints cannot be used in a program if
3524any other process is running that program. In this situation,
5d161b24 3525attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3526@value{GDBN} to print an error message:
3527
474c8240 3528@smallexample
d4f3574e
SS
3529Cannot insert breakpoints.
3530The same program may be running in another process.
474c8240 3531@end smallexample
d4f3574e
SS
3532
3533When this happens, you have three ways to proceed:
3534
3535@enumerate
3536@item
3537Remove or disable the breakpoints, then continue.
3538
3539@item
5d161b24 3540Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3541name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3542that @value{GDBN} should run your program under that name.
d4f3574e
SS
3543Then start your program again.
3544
3545@item
3546Relink your program so that the text segment is nonsharable, using the
3547linker option @samp{-N}. The operating system limitation may not apply
3548to nonsharable executables.
3549@end enumerate
c906108c
SS
3550@c @end ifclear
3551
d4f3574e
SS
3552A similar message can be printed if you request too many active
3553hardware-assisted breakpoints and watchpoints:
3554
3555@c FIXME: the precise wording of this message may change; the relevant
3556@c source change is not committed yet (Sep 3, 1999).
3557@smallexample
3558Stopped; cannot insert breakpoints.
3559You may have requested too many hardware breakpoints and watchpoints.
3560@end smallexample
3561
3562@noindent
3563This message is printed when you attempt to resume the program, since
3564only then @value{GDBN} knows exactly how many hardware breakpoints and
3565watchpoints it needs to insert.
3566
3567When this message is printed, you need to disable or remove some of the
3568hardware-assisted breakpoints and watchpoints, and then continue.
3569
1485d690
KB
3570@node Breakpoint related warnings
3571@subsection ``Breakpoint address adjusted...''
3572@cindex breakpoint address adjusted
3573
3574Some processor architectures place constraints on the addresses at
3575which breakpoints may be placed. For architectures thus constrained,
3576@value{GDBN} will attempt to adjust the breakpoint's address to comply
3577with the constraints dictated by the architecture.
3578
3579One example of such an architecture is the Fujitsu FR-V. The FR-V is
3580a VLIW architecture in which a number of RISC-like instructions may be
3581bundled together for parallel execution. The FR-V architecture
3582constrains the location of a breakpoint instruction within such a
3583bundle to the instruction with the lowest address. @value{GDBN}
3584honors this constraint by adjusting a breakpoint's address to the
3585first in the bundle.
3586
3587It is not uncommon for optimized code to have bundles which contain
3588instructions from different source statements, thus it may happen that
3589a breakpoint's address will be adjusted from one source statement to
3590another. Since this adjustment may significantly alter @value{GDBN}'s
3591breakpoint related behavior from what the user expects, a warning is
3592printed when the breakpoint is first set and also when the breakpoint
3593is hit.
3594
3595A warning like the one below is printed when setting a breakpoint
3596that's been subject to address adjustment:
3597
3598@smallexample
3599warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3600@end smallexample
3601
3602Such warnings are printed both for user settable and @value{GDBN}'s
3603internal breakpoints. If you see one of these warnings, you should
3604verify that a breakpoint set at the adjusted address will have the
3605desired affect. If not, the breakpoint in question may be removed and
b383017d 3606other breakpoints may be set which will have the desired behavior.
1485d690
KB
3607E.g., it may be sufficient to place the breakpoint at a later
3608instruction. A conditional breakpoint may also be useful in some
3609cases to prevent the breakpoint from triggering too often.
3610
3611@value{GDBN} will also issue a warning when stopping at one of these
3612adjusted breakpoints:
3613
3614@smallexample
3615warning: Breakpoint 1 address previously adjusted from 0x00010414
3616to 0x00010410.
3617@end smallexample
3618
3619When this warning is encountered, it may be too late to take remedial
3620action except in cases where the breakpoint is hit earlier or more
3621frequently than expected.
d4f3574e 3622
6d2ebf8b 3623@node Continuing and Stepping
c906108c
SS
3624@section Continuing and stepping
3625
3626@cindex stepping
3627@cindex continuing
3628@cindex resuming execution
3629@dfn{Continuing} means resuming program execution until your program
3630completes normally. In contrast, @dfn{stepping} means executing just
3631one more ``step'' of your program, where ``step'' may mean either one
3632line of source code, or one machine instruction (depending on what
7a292a7a
SS
3633particular command you use). Either when continuing or when stepping,
3634your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3635it stops due to a signal, you may want to use @code{handle}, or use
3636@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3637
3638@table @code
3639@kindex continue
41afff9a
EZ
3640@kindex c @r{(@code{continue})}
3641@kindex fg @r{(resume foreground execution)}
c906108c
SS
3642@item continue @r{[}@var{ignore-count}@r{]}
3643@itemx c @r{[}@var{ignore-count}@r{]}
3644@itemx fg @r{[}@var{ignore-count}@r{]}
3645Resume program execution, at the address where your program last stopped;
3646any breakpoints set at that address are bypassed. The optional argument
3647@var{ignore-count} allows you to specify a further number of times to
3648ignore a breakpoint at this location; its effect is like that of
3649@code{ignore} (@pxref{Conditions, ,Break conditions}).
3650
3651The argument @var{ignore-count} is meaningful only when your program
3652stopped due to a breakpoint. At other times, the argument to
3653@code{continue} is ignored.
3654
d4f3574e
SS
3655The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3656debugged program is deemed to be the foreground program) are provided
3657purely for convenience, and have exactly the same behavior as
3658@code{continue}.
c906108c
SS
3659@end table
3660
3661To resume execution at a different place, you can use @code{return}
3662(@pxref{Returning, ,Returning from a function}) to go back to the
3663calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3664different address}) to go to an arbitrary location in your program.
3665
3666A typical technique for using stepping is to set a breakpoint
3667(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3668beginning of the function or the section of your program where a problem
3669is believed to lie, run your program until it stops at that breakpoint,
3670and then step through the suspect area, examining the variables that are
3671interesting, until you see the problem happen.
3672
3673@table @code
3674@kindex step
41afff9a 3675@kindex s @r{(@code{step})}
c906108c
SS
3676@item step
3677Continue running your program until control reaches a different source
3678line, then stop it and return control to @value{GDBN}. This command is
3679abbreviated @code{s}.
3680
3681@quotation
3682@c "without debugging information" is imprecise; actually "without line
3683@c numbers in the debugging information". (gcc -g1 has debugging info but
3684@c not line numbers). But it seems complex to try to make that
3685@c distinction here.
3686@emph{Warning:} If you use the @code{step} command while control is
3687within a function that was compiled without debugging information,
3688execution proceeds until control reaches a function that does have
3689debugging information. Likewise, it will not step into a function which
3690is compiled without debugging information. To step through functions
3691without debugging information, use the @code{stepi} command, described
3692below.
3693@end quotation
3694
4a92d011
EZ
3695The @code{step} command only stops at the first instruction of a source
3696line. This prevents the multiple stops that could otherwise occur in
3697@code{switch} statements, @code{for} loops, etc. @code{step} continues
3698to stop if a function that has debugging information is called within
3699the line. In other words, @code{step} @emph{steps inside} any functions
3700called within the line.
c906108c 3701
d4f3574e
SS
3702Also, the @code{step} command only enters a function if there is line
3703number information for the function. Otherwise it acts like the
5d161b24 3704@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3705on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3706was any debugging information about the routine.
c906108c
SS
3707
3708@item step @var{count}
3709Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3710breakpoint is reached, or a signal not related to stepping occurs before
3711@var{count} steps, stepping stops right away.
c906108c
SS
3712
3713@kindex next
41afff9a 3714@kindex n @r{(@code{next})}
c906108c
SS
3715@item next @r{[}@var{count}@r{]}
3716Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3717This is similar to @code{step}, but function calls that appear within
3718the line of code are executed without stopping. Execution stops when
3719control reaches a different line of code at the original stack level
3720that was executing when you gave the @code{next} command. This command
3721is abbreviated @code{n}.
c906108c
SS
3722
3723An argument @var{count} is a repeat count, as for @code{step}.
3724
3725
3726@c FIX ME!! Do we delete this, or is there a way it fits in with
3727@c the following paragraph? --- Vctoria
3728@c
3729@c @code{next} within a function that lacks debugging information acts like
3730@c @code{step}, but any function calls appearing within the code of the
3731@c function are executed without stopping.
3732
d4f3574e
SS
3733The @code{next} command only stops at the first instruction of a
3734source line. This prevents multiple stops that could otherwise occur in
4a92d011 3735@code{switch} statements, @code{for} loops, etc.
c906108c 3736
b90a5f51
CF
3737@kindex set step-mode
3738@item set step-mode
3739@cindex functions without line info, and stepping
3740@cindex stepping into functions with no line info
3741@itemx set step-mode on
4a92d011 3742The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3743stop at the first instruction of a function which contains no debug line
3744information rather than stepping over it.
3745
4a92d011
EZ
3746This is useful in cases where you may be interested in inspecting the
3747machine instructions of a function which has no symbolic info and do not
3748want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3749
3750@item set step-mode off
4a92d011 3751Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3752debug information. This is the default.
3753
9c16f35a
EZ
3754@item show step-mode
3755Show whether @value{GDBN} will stop in or step over functions without
3756source line debug information.
3757
c906108c
SS
3758@kindex finish
3759@item finish
3760Continue running until just after function in the selected stack frame
3761returns. Print the returned value (if any).
3762
3763Contrast this with the @code{return} command (@pxref{Returning,
3764,Returning from a function}).
3765
3766@kindex until
41afff9a 3767@kindex u @r{(@code{until})}
09d4efe1 3768@cindex run until specified location
c906108c
SS
3769@item until
3770@itemx u
3771Continue running until a source line past the current line, in the
3772current stack frame, is reached. This command is used to avoid single
3773stepping through a loop more than once. It is like the @code{next}
3774command, except that when @code{until} encounters a jump, it
3775automatically continues execution until the program counter is greater
3776than the address of the jump.
3777
3778This means that when you reach the end of a loop after single stepping
3779though it, @code{until} makes your program continue execution until it
3780exits the loop. In contrast, a @code{next} command at the end of a loop
3781simply steps back to the beginning of the loop, which forces you to step
3782through the next iteration.
3783
3784@code{until} always stops your program if it attempts to exit the current
3785stack frame.
3786
3787@code{until} may produce somewhat counterintuitive results if the order
3788of machine code does not match the order of the source lines. For
3789example, in the following excerpt from a debugging session, the @code{f}
3790(@code{frame}) command shows that execution is stopped at line
3791@code{206}; yet when we use @code{until}, we get to line @code{195}:
3792
474c8240 3793@smallexample
c906108c
SS
3794(@value{GDBP}) f
3795#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3796206 expand_input();
3797(@value{GDBP}) until
3798195 for ( ; argc > 0; NEXTARG) @{
474c8240 3799@end smallexample
c906108c
SS
3800
3801This happened because, for execution efficiency, the compiler had
3802generated code for the loop closure test at the end, rather than the
3803start, of the loop---even though the test in a C @code{for}-loop is
3804written before the body of the loop. The @code{until} command appeared
3805to step back to the beginning of the loop when it advanced to this
3806expression; however, it has not really gone to an earlier
3807statement---not in terms of the actual machine code.
3808
3809@code{until} with no argument works by means of single
3810instruction stepping, and hence is slower than @code{until} with an
3811argument.
3812
3813@item until @var{location}
3814@itemx u @var{location}
3815Continue running your program until either the specified location is
3816reached, or the current stack frame returns. @var{location} is any of
3817the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
3818,Setting breakpoints}). This form of the command uses breakpoints, and
3819hence is quicker than @code{until} without an argument. The specified
3820location is actually reached only if it is in the current frame. This
3821implies that @code{until} can be used to skip over recursive function
3822invocations. For instance in the code below, if the current location is
3823line @code{96}, issuing @code{until 99} will execute the program up to
3824line @code{99} in the same invocation of factorial, i.e. after the inner
3825invocations have returned.
3826
3827@smallexample
382894 int factorial (int value)
382995 @{
383096 if (value > 1) @{
383197 value *= factorial (value - 1);
383298 @}
383399 return (value);
3834100 @}
3835@end smallexample
3836
3837
3838@kindex advance @var{location}
3839@itemx advance @var{location}
09d4efe1
EZ
3840Continue running the program up to the given @var{location}. An argument is
3841required, which should be of the same form as arguments for the @code{break}
c60eb6f1
EZ
3842command. Execution will also stop upon exit from the current stack
3843frame. This command is similar to @code{until}, but @code{advance} will
3844not skip over recursive function calls, and the target location doesn't
3845have to be in the same frame as the current one.
3846
c906108c
SS
3847
3848@kindex stepi
41afff9a 3849@kindex si @r{(@code{stepi})}
c906108c 3850@item stepi
96a2c332 3851@itemx stepi @var{arg}
c906108c
SS
3852@itemx si
3853Execute one machine instruction, then stop and return to the debugger.
3854
3855It is often useful to do @samp{display/i $pc} when stepping by machine
3856instructions. This makes @value{GDBN} automatically display the next
3857instruction to be executed, each time your program stops. @xref{Auto
3858Display,, Automatic display}.
3859
3860An argument is a repeat count, as in @code{step}.
3861
3862@need 750
3863@kindex nexti
41afff9a 3864@kindex ni @r{(@code{nexti})}
c906108c 3865@item nexti
96a2c332 3866@itemx nexti @var{arg}
c906108c
SS
3867@itemx ni
3868Execute one machine instruction, but if it is a function call,
3869proceed until the function returns.
3870
3871An argument is a repeat count, as in @code{next}.
3872@end table
3873
6d2ebf8b 3874@node Signals
c906108c
SS
3875@section Signals
3876@cindex signals
3877
3878A signal is an asynchronous event that can happen in a program. The
3879operating system defines the possible kinds of signals, and gives each
3880kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3881signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3882@code{SIGSEGV} is the signal a program gets from referencing a place in
3883memory far away from all the areas in use; @code{SIGALRM} occurs when
3884the alarm clock timer goes off (which happens only if your program has
3885requested an alarm).
3886
3887@cindex fatal signals
3888Some signals, including @code{SIGALRM}, are a normal part of the
3889functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3890errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3891program has not specified in advance some other way to handle the signal.
3892@code{SIGINT} does not indicate an error in your program, but it is normally
3893fatal so it can carry out the purpose of the interrupt: to kill the program.
3894
3895@value{GDBN} has the ability to detect any occurrence of a signal in your
3896program. You can tell @value{GDBN} in advance what to do for each kind of
3897signal.
3898
3899@cindex handling signals
24f93129
EZ
3900Normally, @value{GDBN} is set up to let the non-erroneous signals like
3901@code{SIGALRM} be silently passed to your program
3902(so as not to interfere with their role in the program's functioning)
c906108c
SS
3903but to stop your program immediately whenever an error signal happens.
3904You can change these settings with the @code{handle} command.
3905
3906@table @code
3907@kindex info signals
09d4efe1 3908@kindex info handle
c906108c 3909@item info signals
96a2c332 3910@itemx info handle
c906108c
SS
3911Print a table of all the kinds of signals and how @value{GDBN} has been told to
3912handle each one. You can use this to see the signal numbers of all
3913the defined types of signals.
3914
d4f3574e 3915@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3916
3917@kindex handle
3918@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3919Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3920can be the number of a signal or its name (with or without the
24f93129 3921@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3922@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3923known signals. The @var{keywords} say what change to make.
c906108c
SS
3924@end table
3925
3926@c @group
3927The keywords allowed by the @code{handle} command can be abbreviated.
3928Their full names are:
3929
3930@table @code
3931@item nostop
3932@value{GDBN} should not stop your program when this signal happens. It may
3933still print a message telling you that the signal has come in.
3934
3935@item stop
3936@value{GDBN} should stop your program when this signal happens. This implies
3937the @code{print} keyword as well.
3938
3939@item print
3940@value{GDBN} should print a message when this signal happens.
3941
3942@item noprint
3943@value{GDBN} should not mention the occurrence of the signal at all. This
3944implies the @code{nostop} keyword as well.
3945
3946@item pass
5ece1a18 3947@itemx noignore
c906108c
SS
3948@value{GDBN} should allow your program to see this signal; your program
3949can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3950and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3951
3952@item nopass
5ece1a18 3953@itemx ignore
c906108c 3954@value{GDBN} should not allow your program to see this signal.
5ece1a18 3955@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3956@end table
3957@c @end group
3958
d4f3574e
SS
3959When a signal stops your program, the signal is not visible to the
3960program until you
c906108c
SS
3961continue. Your program sees the signal then, if @code{pass} is in
3962effect for the signal in question @emph{at that time}. In other words,
3963after @value{GDBN} reports a signal, you can use the @code{handle}
3964command with @code{pass} or @code{nopass} to control whether your
3965program sees that signal when you continue.
3966
24f93129
EZ
3967The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3968non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3969@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3970erroneous signals.
3971
c906108c
SS
3972You can also use the @code{signal} command to prevent your program from
3973seeing a signal, or cause it to see a signal it normally would not see,
3974or to give it any signal at any time. For example, if your program stopped
3975due to some sort of memory reference error, you might store correct
3976values into the erroneous variables and continue, hoping to see more
3977execution; but your program would probably terminate immediately as
3978a result of the fatal signal once it saw the signal. To prevent this,
3979you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3980program a signal}.
c906108c 3981
6d2ebf8b 3982@node Thread Stops
c906108c
SS
3983@section Stopping and starting multi-thread programs
3984
3985When your program has multiple threads (@pxref{Threads,, Debugging
3986programs with multiple threads}), you can choose whether to set
3987breakpoints on all threads, or on a particular thread.
3988
3989@table @code
3990@cindex breakpoints and threads
3991@cindex thread breakpoints
3992@kindex break @dots{} thread @var{threadno}
3993@item break @var{linespec} thread @var{threadno}
3994@itemx break @var{linespec} thread @var{threadno} if @dots{}
3995@var{linespec} specifies source lines; there are several ways of
3996writing them, but the effect is always to specify some source line.
3997
3998Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3999to specify that you only want @value{GDBN} to stop the program when a
4000particular thread reaches this breakpoint. @var{threadno} is one of the
4001numeric thread identifiers assigned by @value{GDBN}, shown in the first
4002column of the @samp{info threads} display.
4003
4004If you do not specify @samp{thread @var{threadno}} when you set a
4005breakpoint, the breakpoint applies to @emph{all} threads of your
4006program.
4007
4008You can use the @code{thread} qualifier on conditional breakpoints as
4009well; in this case, place @samp{thread @var{threadno}} before the
4010breakpoint condition, like this:
4011
4012@smallexample
2df3850c 4013(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
4014@end smallexample
4015
4016@end table
4017
4018@cindex stopped threads
4019@cindex threads, stopped
4020Whenever your program stops under @value{GDBN} for any reason,
4021@emph{all} threads of execution stop, not just the current thread. This
4022allows you to examine the overall state of the program, including
4023switching between threads, without worrying that things may change
4024underfoot.
4025
36d86913
MC
4026@cindex thread breakpoints and system calls
4027@cindex system calls and thread breakpoints
4028@cindex premature return from system calls
4029There is an unfortunate side effect. If one thread stops for a
4030breakpoint, or for some other reason, and another thread is blocked in a
4031system call, then the system call may return prematurely. This is a
4032consequence of the interaction between multiple threads and the signals
4033that @value{GDBN} uses to implement breakpoints and other events that
4034stop execution.
4035
4036To handle this problem, your program should check the return value of
4037each system call and react appropriately. This is good programming
4038style anyways.
4039
4040For example, do not write code like this:
4041
4042@smallexample
4043 sleep (10);
4044@end smallexample
4045
4046The call to @code{sleep} will return early if a different thread stops
4047at a breakpoint or for some other reason.
4048
4049Instead, write this:
4050
4051@smallexample
4052 int unslept = 10;
4053 while (unslept > 0)
4054 unslept = sleep (unslept);
4055@end smallexample
4056
4057A system call is allowed to return early, so the system is still
4058conforming to its specification. But @value{GDBN} does cause your
4059multi-threaded program to behave differently than it would without
4060@value{GDBN}.
4061
4062Also, @value{GDBN} uses internal breakpoints in the thread library to
4063monitor certain events such as thread creation and thread destruction.
4064When such an event happens, a system call in another thread may return
4065prematurely, even though your program does not appear to stop.
4066
c906108c
SS
4067@cindex continuing threads
4068@cindex threads, continuing
4069Conversely, whenever you restart the program, @emph{all} threads start
4070executing. @emph{This is true even when single-stepping} with commands
5d161b24 4071like @code{step} or @code{next}.
c906108c
SS
4072
4073In particular, @value{GDBN} cannot single-step all threads in lockstep.
4074Since thread scheduling is up to your debugging target's operating
4075system (not controlled by @value{GDBN}), other threads may
4076execute more than one statement while the current thread completes a
4077single step. Moreover, in general other threads stop in the middle of a
4078statement, rather than at a clean statement boundary, when the program
4079stops.
4080
4081You might even find your program stopped in another thread after
4082continuing or even single-stepping. This happens whenever some other
4083thread runs into a breakpoint, a signal, or an exception before the
4084first thread completes whatever you requested.
4085
4086On some OSes, you can lock the OS scheduler and thus allow only a single
4087thread to run.
4088
4089@table @code
4090@item set scheduler-locking @var{mode}
9c16f35a
EZ
4091@cindex scheduler locking mode
4092@cindex lock scheduler
c906108c
SS
4093Set the scheduler locking mode. If it is @code{off}, then there is no
4094locking and any thread may run at any time. If @code{on}, then only the
4095current thread may run when the inferior is resumed. The @code{step}
4096mode optimizes for single-stepping. It stops other threads from
4097``seizing the prompt'' by preempting the current thread while you are
4098stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 4099when you step. They are more likely to run when you @samp{next} over a
c906108c 4100function call, and they are completely free to run when you use commands
d4f3574e 4101like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 4102thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 4103@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
4104
4105@item show scheduler-locking
4106Display the current scheduler locking mode.
4107@end table
4108
c906108c 4109
6d2ebf8b 4110@node Stack
c906108c
SS
4111@chapter Examining the Stack
4112
4113When your program has stopped, the first thing you need to know is where it
4114stopped and how it got there.
4115
4116@cindex call stack
5d161b24
DB
4117Each time your program performs a function call, information about the call
4118is generated.
4119That information includes the location of the call in your program,
4120the arguments of the call,
c906108c 4121and the local variables of the function being called.
5d161b24 4122The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
4123The stack frames are allocated in a region of memory called the @dfn{call
4124stack}.
4125
4126When your program stops, the @value{GDBN} commands for examining the
4127stack allow you to see all of this information.
4128
4129@cindex selected frame
4130One of the stack frames is @dfn{selected} by @value{GDBN} and many
4131@value{GDBN} commands refer implicitly to the selected frame. In
4132particular, whenever you ask @value{GDBN} for the value of a variable in
4133your program, the value is found in the selected frame. There are
4134special @value{GDBN} commands to select whichever frame you are
4135interested in. @xref{Selection, ,Selecting a frame}.
4136
4137When your program stops, @value{GDBN} automatically selects the
5d161b24 4138currently executing frame and describes it briefly, similar to the
c906108c
SS
4139@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
4140
4141@menu
4142* Frames:: Stack frames
4143* Backtrace:: Backtraces
4144* Selection:: Selecting a frame
4145* Frame Info:: Information on a frame
c906108c
SS
4146
4147@end menu
4148
6d2ebf8b 4149@node Frames
c906108c
SS
4150@section Stack frames
4151
d4f3574e 4152@cindex frame, definition
c906108c
SS
4153@cindex stack frame
4154The call stack is divided up into contiguous pieces called @dfn{stack
4155frames}, or @dfn{frames} for short; each frame is the data associated
4156with one call to one function. The frame contains the arguments given
4157to the function, the function's local variables, and the address at
4158which the function is executing.
4159
4160@cindex initial frame
4161@cindex outermost frame
4162@cindex innermost frame
4163When your program is started, the stack has only one frame, that of the
4164function @code{main}. This is called the @dfn{initial} frame or the
4165@dfn{outermost} frame. Each time a function is called, a new frame is
4166made. Each time a function returns, the frame for that function invocation
4167is eliminated. If a function is recursive, there can be many frames for
4168the same function. The frame for the function in which execution is
4169actually occurring is called the @dfn{innermost} frame. This is the most
4170recently created of all the stack frames that still exist.
4171
4172@cindex frame pointer
4173Inside your program, stack frames are identified by their addresses. A
4174stack frame consists of many bytes, each of which has its own address; each
4175kind of computer has a convention for choosing one byte whose
4176address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
4177in a register called the @dfn{frame pointer register}
4178(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
4179
4180@cindex frame number
4181@value{GDBN} assigns numbers to all existing stack frames, starting with
4182zero for the innermost frame, one for the frame that called it,
4183and so on upward. These numbers do not really exist in your program;
4184they are assigned by @value{GDBN} to give you a way of designating stack
4185frames in @value{GDBN} commands.
4186
6d2ebf8b
SS
4187@c The -fomit-frame-pointer below perennially causes hbox overflow
4188@c underflow problems.
c906108c
SS
4189@cindex frameless execution
4190Some compilers provide a way to compile functions so that they operate
6d2ebf8b 4191without stack frames. (For example, the @value{GCC} option
474c8240 4192@smallexample
6d2ebf8b 4193@samp{-fomit-frame-pointer}
474c8240 4194@end smallexample
6d2ebf8b 4195generates functions without a frame.)
c906108c
SS
4196This is occasionally done with heavily used library functions to save
4197the frame setup time. @value{GDBN} has limited facilities for dealing
4198with these function invocations. If the innermost function invocation
4199has no stack frame, @value{GDBN} nevertheless regards it as though
4200it had a separate frame, which is numbered zero as usual, allowing
4201correct tracing of the function call chain. However, @value{GDBN} has
4202no provision for frameless functions elsewhere in the stack.
4203
4204@table @code
d4f3574e 4205@kindex frame@r{, command}
41afff9a 4206@cindex current stack frame
c906108c 4207@item frame @var{args}
5d161b24 4208The @code{frame} command allows you to move from one stack frame to another,
c906108c 4209and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4210address of the frame or the stack frame number. Without an argument,
4211@code{frame} prints the current stack frame.
c906108c
SS
4212
4213@kindex select-frame
41afff9a 4214@cindex selecting frame silently
c906108c
SS
4215@item select-frame
4216The @code{select-frame} command allows you to move from one stack frame
4217to another without printing the frame. This is the silent version of
4218@code{frame}.
4219@end table
4220
6d2ebf8b 4221@node Backtrace
c906108c
SS
4222@section Backtraces
4223
09d4efe1
EZ
4224@cindex traceback
4225@cindex call stack traces
c906108c
SS
4226A backtrace is a summary of how your program got where it is. It shows one
4227line per frame, for many frames, starting with the currently executing
4228frame (frame zero), followed by its caller (frame one), and on up the
4229stack.
4230
4231@table @code
4232@kindex backtrace
41afff9a 4233@kindex bt @r{(@code{backtrace})}
c906108c
SS
4234@item backtrace
4235@itemx bt
4236Print a backtrace of the entire stack: one line per frame for all
4237frames in the stack.
4238
4239You can stop the backtrace at any time by typing the system interrupt
4240character, normally @kbd{C-c}.
4241
4242@item backtrace @var{n}
4243@itemx bt @var{n}
4244Similar, but print only the innermost @var{n} frames.
4245
4246@item backtrace -@var{n}
4247@itemx bt -@var{n}
4248Similar, but print only the outermost @var{n} frames.
0f061b69
NR
4249
4250@item backtrace full
4251Print the values of the local variables also.
4252@itemx bt full
c906108c
SS
4253@end table
4254
4255@kindex where
4256@kindex info stack
c906108c
SS
4257The names @code{where} and @code{info stack} (abbreviated @code{info s})
4258are additional aliases for @code{backtrace}.
4259
4260Each line in the backtrace shows the frame number and the function name.
4261The program counter value is also shown---unless you use @code{set
4262print address off}. The backtrace also shows the source file name and
4263line number, as well as the arguments to the function. The program
4264counter value is omitted if it is at the beginning of the code for that
4265line number.
4266
4267Here is an example of a backtrace. It was made with the command
4268@samp{bt 3}, so it shows the innermost three frames.
4269
4270@smallexample
4271@group
5d161b24 4272#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4273 at builtin.c:993
4274#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4275#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4276 at macro.c:71
4277(More stack frames follow...)
4278@end group
4279@end smallexample
4280
4281@noindent
4282The display for frame zero does not begin with a program counter
4283value, indicating that your program has stopped at the beginning of the
4284code for line @code{993} of @code{builtin.c}.
4285
18999be5
EZ
4286@cindex value optimized out, in backtrace
4287@cindex function call arguments, optimized out
4288If your program was compiled with optimizations, some compilers will
4289optimize away arguments passed to functions if those arguments are
4290never used after the call. Such optimizations generate code that
4291passes arguments through registers, but doesn't store those arguments
4292in the stack frame. @value{GDBN} has no way of displaying such
4293arguments in stack frames other than the innermost one. Here's what
4294such a backtrace might look like:
4295
4296@smallexample
4297@group
4298#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4299 at builtin.c:993
4300#1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
4301#2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
4302 at macro.c:71
4303(More stack frames follow...)
4304@end group
4305@end smallexample
4306
4307@noindent
4308The values of arguments that were not saved in their stack frames are
4309shown as @samp{<value optimized out>}.
4310
4311If you need to display the values of such optimized-out arguments,
4312either deduce that from other variables whose values depend on the one
4313you are interested in, or recompile without optimizations.
4314
a8f24a35
EZ
4315@cindex backtrace beyond @code{main} function
4316@cindex program entry point
4317@cindex startup code, and backtrace
25d29d70
AC
4318Most programs have a standard user entry point---a place where system
4319libraries and startup code transition into user code. For C this is
d416eeec
EZ
4320@code{main}@footnote{
4321Note that embedded programs (the so-called ``free-standing''
4322environment) are not required to have a @code{main} function as the
4323entry point. They could even have multiple entry points.}.
4324When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
4325it will terminate the backtrace, to avoid tracing into highly
4326system-specific (and generally uninteresting) code.
4327
4328If you need to examine the startup code, or limit the number of levels
4329in a backtrace, you can change this behavior:
95f90d25
DJ
4330
4331@table @code
25d29d70
AC
4332@item set backtrace past-main
4333@itemx set backtrace past-main on
4644b6e3 4334@kindex set backtrace
25d29d70
AC
4335Backtraces will continue past the user entry point.
4336
4337@item set backtrace past-main off
95f90d25
DJ
4338Backtraces will stop when they encounter the user entry point. This is the
4339default.
4340
25d29d70 4341@item show backtrace past-main
4644b6e3 4342@kindex show backtrace
25d29d70
AC
4343Display the current user entry point backtrace policy.
4344
2315ffec
RC
4345@item set backtrace past-entry
4346@itemx set backtrace past-entry on
a8f24a35 4347Backtraces will continue past the internal entry point of an application.
2315ffec
RC
4348This entry point is encoded by the linker when the application is built,
4349and is likely before the user entry point @code{main} (or equivalent) is called.
4350
4351@item set backtrace past-entry off
4352Backtraces will stop when they encouter the internal entry point of an
4353application. This is the default.
4354
4355@item show backtrace past-entry
4356Display the current internal entry point backtrace policy.
4357
25d29d70
AC
4358@item set backtrace limit @var{n}
4359@itemx set backtrace limit 0
4360@cindex backtrace limit
4361Limit the backtrace to @var{n} levels. A value of zero means
4362unlimited.
95f90d25 4363
25d29d70
AC
4364@item show backtrace limit
4365Display the current limit on backtrace levels.
95f90d25
DJ
4366@end table
4367
6d2ebf8b 4368@node Selection
c906108c
SS
4369@section Selecting a frame
4370
4371Most commands for examining the stack and other data in your program work on
4372whichever stack frame is selected at the moment. Here are the commands for
4373selecting a stack frame; all of them finish by printing a brief description
4374of the stack frame just selected.
4375
4376@table @code
d4f3574e 4377@kindex frame@r{, selecting}
41afff9a 4378@kindex f @r{(@code{frame})}
c906108c
SS
4379@item frame @var{n}
4380@itemx f @var{n}
4381Select frame number @var{n}. Recall that frame zero is the innermost
4382(currently executing) frame, frame one is the frame that called the
4383innermost one, and so on. The highest-numbered frame is the one for
4384@code{main}.
4385
4386@item frame @var{addr}
4387@itemx f @var{addr}
4388Select the frame at address @var{addr}. This is useful mainly if the
4389chaining of stack frames has been damaged by a bug, making it
4390impossible for @value{GDBN} to assign numbers properly to all frames. In
4391addition, this can be useful when your program has multiple stacks and
4392switches between them.
4393
c906108c
SS
4394On the SPARC architecture, @code{frame} needs two addresses to
4395select an arbitrary frame: a frame pointer and a stack pointer.
4396
4397On the MIPS and Alpha architecture, it needs two addresses: a stack
4398pointer and a program counter.
4399
4400On the 29k architecture, it needs three addresses: a register stack
4401pointer, a program counter, and a memory stack pointer.
c906108c
SS
4402
4403@kindex up
4404@item up @var{n}
4405Move @var{n} frames up the stack. For positive numbers @var{n}, this
4406advances toward the outermost frame, to higher frame numbers, to frames
4407that have existed longer. @var{n} defaults to one.
4408
4409@kindex down
41afff9a 4410@kindex do @r{(@code{down})}
c906108c
SS
4411@item down @var{n}
4412Move @var{n} frames down the stack. For positive numbers @var{n}, this
4413advances toward the innermost frame, to lower frame numbers, to frames
4414that were created more recently. @var{n} defaults to one. You may
4415abbreviate @code{down} as @code{do}.
4416@end table
4417
4418All of these commands end by printing two lines of output describing the
4419frame. The first line shows the frame number, the function name, the
4420arguments, and the source file and line number of execution in that
5d161b24 4421frame. The second line shows the text of that source line.
c906108c
SS
4422
4423@need 1000
4424For example:
4425
4426@smallexample
4427@group
4428(@value{GDBP}) up
4429#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4430 at env.c:10
443110 read_input_file (argv[i]);
4432@end group
4433@end smallexample
4434
4435After such a printout, the @code{list} command with no arguments
4436prints ten lines centered on the point of execution in the frame.
87885426
FN
4437You can also edit the program at the point of execution with your favorite
4438editing program by typing @code{edit}.
4439@xref{List, ,Printing source lines},
4440for details.
c906108c
SS
4441
4442@table @code
4443@kindex down-silently
4444@kindex up-silently
4445@item up-silently @var{n}
4446@itemx down-silently @var{n}
4447These two commands are variants of @code{up} and @code{down},
4448respectively; they differ in that they do their work silently, without
4449causing display of the new frame. They are intended primarily for use
4450in @value{GDBN} command scripts, where the output might be unnecessary and
4451distracting.
4452@end table
4453
6d2ebf8b 4454@node Frame Info
c906108c
SS
4455@section Information about a frame
4456
4457There are several other commands to print information about the selected
4458stack frame.
4459
4460@table @code
4461@item frame
4462@itemx f
4463When used without any argument, this command does not change which
4464frame is selected, but prints a brief description of the currently
4465selected stack frame. It can be abbreviated @code{f}. With an
4466argument, this command is used to select a stack frame.
4467@xref{Selection, ,Selecting a frame}.
4468
4469@kindex info frame
41afff9a 4470@kindex info f @r{(@code{info frame})}
c906108c
SS
4471@item info frame
4472@itemx info f
4473This command prints a verbose description of the selected stack frame,
4474including:
4475
4476@itemize @bullet
5d161b24
DB
4477@item
4478the address of the frame
c906108c
SS
4479@item
4480the address of the next frame down (called by this frame)
4481@item
4482the address of the next frame up (caller of this frame)
4483@item
4484the language in which the source code corresponding to this frame is written
4485@item
4486the address of the frame's arguments
4487@item
d4f3574e
SS
4488the address of the frame's local variables
4489@item
c906108c
SS
4490the program counter saved in it (the address of execution in the caller frame)
4491@item
4492which registers were saved in the frame
4493@end itemize
4494
4495@noindent The verbose description is useful when
4496something has gone wrong that has made the stack format fail to fit
4497the usual conventions.
4498
4499@item info frame @var{addr}
4500@itemx info f @var{addr}
4501Print a verbose description of the frame at address @var{addr}, without
4502selecting that frame. The selected frame remains unchanged by this
4503command. This requires the same kind of address (more than one for some
4504architectures) that you specify in the @code{frame} command.
4505@xref{Selection, ,Selecting a frame}.
4506
4507@kindex info args
4508@item info args
4509Print the arguments of the selected frame, each on a separate line.
4510
4511@item info locals
4512@kindex info locals
4513Print the local variables of the selected frame, each on a separate
4514line. These are all variables (declared either static or automatic)
4515accessible at the point of execution of the selected frame.
4516
c906108c 4517@kindex info catch
d4f3574e
SS
4518@cindex catch exceptions, list active handlers
4519@cindex exception handlers, how to list
c906108c
SS
4520@item info catch
4521Print a list of all the exception handlers that are active in the
4522current stack frame at the current point of execution. To see other
4523exception handlers, visit the associated frame (using the @code{up},
4524@code{down}, or @code{frame} commands); then type @code{info catch}.
4525@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4526
c906108c
SS
4527@end table
4528
c906108c 4529
6d2ebf8b 4530@node Source
c906108c
SS
4531@chapter Examining Source Files
4532
4533@value{GDBN} can print parts of your program's source, since the debugging
4534information recorded in the program tells @value{GDBN} what source files were
4535used to build it. When your program stops, @value{GDBN} spontaneously prints
4536the line where it stopped. Likewise, when you select a stack frame
4537(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4538execution in that frame has stopped. You can print other portions of
4539source files by explicit command.
4540
7a292a7a 4541If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4542prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4543@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4544
4545@menu
4546* List:: Printing source lines
87885426 4547* Edit:: Editing source files
c906108c 4548* Search:: Searching source files
c906108c
SS
4549* Source Path:: Specifying source directories
4550* Machine Code:: Source and machine code
4551@end menu
4552
6d2ebf8b 4553@node List
c906108c
SS
4554@section Printing source lines
4555
4556@kindex list
41afff9a 4557@kindex l @r{(@code{list})}
c906108c 4558To print lines from a source file, use the @code{list} command
5d161b24 4559(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4560There are several ways to specify what part of the file you want to print.
4561
4562Here are the forms of the @code{list} command most commonly used:
4563
4564@table @code
4565@item list @var{linenum}
4566Print lines centered around line number @var{linenum} in the
4567current source file.
4568
4569@item list @var{function}
4570Print lines centered around the beginning of function
4571@var{function}.
4572
4573@item list
4574Print more lines. If the last lines printed were printed with a
4575@code{list} command, this prints lines following the last lines
4576printed; however, if the last line printed was a solitary line printed
4577as part of displaying a stack frame (@pxref{Stack, ,Examining the
4578Stack}), this prints lines centered around that line.
4579
4580@item list -
4581Print lines just before the lines last printed.
4582@end table
4583
9c16f35a 4584@cindex @code{list}, how many lines to display
c906108c
SS
4585By default, @value{GDBN} prints ten source lines with any of these forms of
4586the @code{list} command. You can change this using @code{set listsize}:
4587
4588@table @code
4589@kindex set listsize
4590@item set listsize @var{count}
4591Make the @code{list} command display @var{count} source lines (unless
4592the @code{list} argument explicitly specifies some other number).
4593
4594@kindex show listsize
4595@item show listsize
4596Display the number of lines that @code{list} prints.
4597@end table
4598
4599Repeating a @code{list} command with @key{RET} discards the argument,
4600so it is equivalent to typing just @code{list}. This is more useful
4601than listing the same lines again. An exception is made for an
4602argument of @samp{-}; that argument is preserved in repetition so that
4603each repetition moves up in the source file.
4604
4605@cindex linespec
4606In general, the @code{list} command expects you to supply zero, one or two
4607@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4608of writing them, but the effect is always to specify some source line.
c906108c
SS
4609Here is a complete description of the possible arguments for @code{list}:
4610
4611@table @code
4612@item list @var{linespec}
4613Print lines centered around the line specified by @var{linespec}.
4614
4615@item list @var{first},@var{last}
4616Print lines from @var{first} to @var{last}. Both arguments are
4617linespecs.
4618
4619@item list ,@var{last}
4620Print lines ending with @var{last}.
4621
4622@item list @var{first},
4623Print lines starting with @var{first}.
4624
4625@item list +
4626Print lines just after the lines last printed.
4627
4628@item list -
4629Print lines just before the lines last printed.
4630
4631@item list
4632As described in the preceding table.
4633@end table
4634
4635Here are the ways of specifying a single source line---all the
4636kinds of linespec.
4637
4638@table @code
4639@item @var{number}
4640Specifies line @var{number} of the current source file.
4641When a @code{list} command has two linespecs, this refers to
4642the same source file as the first linespec.
4643
4644@item +@var{offset}
4645Specifies the line @var{offset} lines after the last line printed.
4646When used as the second linespec in a @code{list} command that has
4647two, this specifies the line @var{offset} lines down from the
4648first linespec.
4649
4650@item -@var{offset}
4651Specifies the line @var{offset} lines before the last line printed.
4652
4653@item @var{filename}:@var{number}
4654Specifies line @var{number} in the source file @var{filename}.
4655
4656@item @var{function}
4657Specifies the line that begins the body of the function @var{function}.
4658For example: in C, this is the line with the open brace.
4659
4660@item @var{filename}:@var{function}
4661Specifies the line of the open-brace that begins the body of the
4662function @var{function} in the file @var{filename}. You only need the
4663file name with a function name to avoid ambiguity when there are
4664identically named functions in different source files.
4665
4666@item *@var{address}
4667Specifies the line containing the program address @var{address}.
4668@var{address} may be any expression.
4669@end table
4670
87885426
FN
4671@node Edit
4672@section Editing source files
4673@cindex editing source files
4674
4675@kindex edit
4676@kindex e @r{(@code{edit})}
4677To edit the lines in a source file, use the @code{edit} command.
4678The editing program of your choice
4679is invoked with the current line set to
4680the active line in the program.
4681Alternatively, there are several ways to specify what part of the file you
4682want to print if you want to see other parts of the program.
4683
4684Here are the forms of the @code{edit} command most commonly used:
4685
4686@table @code
4687@item edit
4688Edit the current source file at the active line number in the program.
4689
4690@item edit @var{number}
4691Edit the current source file with @var{number} as the active line number.
4692
4693@item edit @var{function}
4694Edit the file containing @var{function} at the beginning of its definition.
4695
4696@item edit @var{filename}:@var{number}
4697Specifies line @var{number} in the source file @var{filename}.
4698
4699@item edit @var{filename}:@var{function}
4700Specifies the line that begins the body of the
4701function @var{function} in the file @var{filename}. You only need the
4702file name with a function name to avoid ambiguity when there are
4703identically named functions in different source files.
4704
4705@item edit *@var{address}
4706Specifies the line containing the program address @var{address}.
4707@var{address} may be any expression.
4708@end table
4709
4710@subsection Choosing your editor
4711You can customize @value{GDBN} to use any editor you want
4712@footnote{
4713The only restriction is that your editor (say @code{ex}), recognizes the
4714following command-line syntax:
10998722 4715@smallexample
87885426 4716ex +@var{number} file
10998722 4717@end smallexample
15387254
EZ
4718The optional numeric value +@var{number} specifies the number of the line in
4719the file where to start editing.}.
4720By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4721by setting the environment variable @code{EDITOR} before using
4722@value{GDBN}. For example, to configure @value{GDBN} to use the
4723@code{vi} editor, you could use these commands with the @code{sh} shell:
4724@smallexample
87885426
FN
4725EDITOR=/usr/bin/vi
4726export EDITOR
15387254 4727gdb @dots{}
10998722 4728@end smallexample
87885426 4729or in the @code{csh} shell,
10998722 4730@smallexample
87885426 4731setenv EDITOR /usr/bin/vi
15387254 4732gdb @dots{}
10998722 4733@end smallexample
87885426 4734
6d2ebf8b 4735@node Search
c906108c 4736@section Searching source files
15387254 4737@cindex searching source files
c906108c
SS
4738
4739There are two commands for searching through the current source file for a
4740regular expression.
4741
4742@table @code
4743@kindex search
4744@kindex forward-search
4745@item forward-search @var{regexp}
4746@itemx search @var{regexp}
4747The command @samp{forward-search @var{regexp}} checks each line,
4748starting with the one following the last line listed, for a match for
5d161b24 4749@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4750synonym @samp{search @var{regexp}} or abbreviate the command name as
4751@code{fo}.
4752
09d4efe1 4753@kindex reverse-search
c906108c
SS
4754@item reverse-search @var{regexp}
4755The command @samp{reverse-search @var{regexp}} checks each line, starting
4756with the one before the last line listed and going backward, for a match
4757for @var{regexp}. It lists the line that is found. You can abbreviate
4758this command as @code{rev}.
4759@end table
c906108c 4760
6d2ebf8b 4761@node Source Path
c906108c
SS
4762@section Specifying source directories
4763
4764@cindex source path
4765@cindex directories for source files
4766Executable programs sometimes do not record the directories of the source
4767files from which they were compiled, just the names. Even when they do,
4768the directories could be moved between the compilation and your debugging
4769session. @value{GDBN} has a list of directories to search for source files;
4770this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4771it tries all the directories in the list, in the order they are present
0b66e38c
EZ
4772in the list, until it finds a file with the desired name.
4773
4774For example, suppose an executable references the file
4775@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4776@file{/mnt/cross}. The file is first looked up literally; if this
4777fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4778fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4779message is printed. @value{GDBN} does not look up the parts of the
4780source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4781Likewise, the subdirectories of the source path are not searched: if
4782the source path is @file{/mnt/cross}, and the binary refers to
4783@file{foo.c}, @value{GDBN} would not find it under
4784@file{/mnt/cross/usr/src/foo-1.0/lib}.
4785
4786Plain file names, relative file names with leading directories, file
4787names containing dots, etc.@: are all treated as described above; for
4788instance, if the source path is @file{/mnt/cross}, and the source file
4789is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4790@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4791that---@file{/mnt/cross/foo.c}.
4792
4793Note that the executable search path is @emph{not} used to locate the
4794source files. Neither is the current working directory, unless it
4795happens to be in the source path.
c906108c
SS
4796
4797Whenever you reset or rearrange the source path, @value{GDBN} clears out
4798any information it has cached about where source files are found and where
4799each line is in the file.
4800
4801@kindex directory
4802@kindex dir
d4f3574e
SS
4803When you start @value{GDBN}, its source path includes only @samp{cdir}
4804and @samp{cwd}, in that order.
c906108c
SS
4805To add other directories, use the @code{directory} command.
4806
4807@table @code
4808@item directory @var{dirname} @dots{}
4809@item dir @var{dirname} @dots{}
4810Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4811directory names may be given to this command, separated by @samp{:}
4812(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4813part of absolute file names) or
c906108c
SS
4814whitespace. You may specify a directory that is already in the source
4815path; this moves it forward, so @value{GDBN} searches it sooner.
4816
4817@kindex cdir
4818@kindex cwd
41afff9a
EZ
4819@vindex $cdir@r{, convenience variable}
4820@vindex $cwdr@r{, convenience variable}
c906108c
SS
4821@cindex compilation directory
4822@cindex current directory
4823@cindex working directory
4824@cindex directory, current
4825@cindex directory, compilation
4826You can use the string @samp{$cdir} to refer to the compilation
4827directory (if one is recorded), and @samp{$cwd} to refer to the current
4828working directory. @samp{$cwd} is not the same as @samp{.}---the former
4829tracks the current working directory as it changes during your @value{GDBN}
4830session, while the latter is immediately expanded to the current
4831directory at the time you add an entry to the source path.
4832
4833@item directory
4834Reset the source path to empty again. This requires confirmation.
4835
4836@c RET-repeat for @code{directory} is explicitly disabled, but since
4837@c repeating it would be a no-op we do not say that. (thanks to RMS)
4838
4839@item show directories
4840@kindex show directories
4841Print the source path: show which directories it contains.
4842@end table
4843
4844If your source path is cluttered with directories that are no longer of
4845interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4846versions of source. You can correct the situation as follows:
4847
4848@enumerate
4849@item
4850Use @code{directory} with no argument to reset the source path to empty.
4851
4852@item
4853Use @code{directory} with suitable arguments to reinstall the
4854directories you want in the source path. You can add all the
4855directories in one command.
4856@end enumerate
4857
6d2ebf8b 4858@node Machine Code
c906108c 4859@section Source and machine code
15387254 4860@cindex source line and its code address
c906108c
SS
4861
4862You can use the command @code{info line} to map source lines to program
4863addresses (and vice versa), and the command @code{disassemble} to display
4864a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4865mode, the @code{info line} command causes the arrow to point to the
5d161b24 4866line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4867well as hex.
4868
4869@table @code
4870@kindex info line
4871@item info line @var{linespec}
4872Print the starting and ending addresses of the compiled code for
4873source line @var{linespec}. You can specify source lines in any of
4874the ways understood by the @code{list} command (@pxref{List, ,Printing
4875source lines}).
4876@end table
4877
4878For example, we can use @code{info line} to discover the location of
4879the object code for the first line of function
4880@code{m4_changequote}:
4881
d4f3574e
SS
4882@c FIXME: I think this example should also show the addresses in
4883@c symbolic form, as they usually would be displayed.
c906108c 4884@smallexample
96a2c332 4885(@value{GDBP}) info line m4_changequote
c906108c
SS
4886Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4887@end smallexample
4888
4889@noindent
15387254 4890@cindex code address and its source line
c906108c
SS
4891We can also inquire (using @code{*@var{addr}} as the form for
4892@var{linespec}) what source line covers a particular address:
4893@smallexample
4894(@value{GDBP}) info line *0x63ff
4895Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4896@end smallexample
4897
4898@cindex @code{$_} and @code{info line}
15387254 4899@cindex @code{x} command, default address
41afff9a 4900@kindex x@r{(examine), and} info line
c906108c
SS
4901After @code{info line}, the default address for the @code{x} command
4902is changed to the starting address of the line, so that @samp{x/i} is
4903sufficient to begin examining the machine code (@pxref{Memory,
4904,Examining memory}). Also, this address is saved as the value of the
4905convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4906variables}).
4907
4908@table @code
4909@kindex disassemble
4910@cindex assembly instructions
4911@cindex instructions, assembly
4912@cindex machine instructions
4913@cindex listing machine instructions
4914@item disassemble
4915This specialized command dumps a range of memory as machine
4916instructions. The default memory range is the function surrounding the
4917program counter of the selected frame. A single argument to this
4918command is a program counter value; @value{GDBN} dumps the function
4919surrounding this value. Two arguments specify a range of addresses
4920(first inclusive, second exclusive) to dump.
4921@end table
4922
c906108c
SS
4923The following example shows the disassembly of a range of addresses of
4924HP PA-RISC 2.0 code:
4925
4926@smallexample
4927(@value{GDBP}) disas 0x32c4 0x32e4
4928Dump of assembler code from 0x32c4 to 0x32e4:
49290x32c4 <main+204>: addil 0,dp
49300x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
49310x32cc <main+212>: ldil 0x3000,r31
49320x32d0 <main+216>: ble 0x3f8(sr4,r31)
49330x32d4 <main+220>: ldo 0(r31),rp
49340x32d8 <main+224>: addil -0x800,dp
49350x32dc <main+228>: ldo 0x588(r1),r26
49360x32e0 <main+232>: ldil 0x3000,r31
4937End of assembler dump.
4938@end smallexample
c906108c
SS
4939
4940Some architectures have more than one commonly-used set of instruction
4941mnemonics or other syntax.
4942
76d17f34
EZ
4943For programs that were dynamically linked and use shared libraries,
4944instructions that call functions or branch to locations in the shared
4945libraries might show a seemingly bogus location---it's actually a
4946location of the relocation table. On some architectures, @value{GDBN}
4947might be able to resolve these to actual function names.
4948
c906108c 4949@table @code
d4f3574e 4950@kindex set disassembly-flavor
d4f3574e
SS
4951@cindex Intel disassembly flavor
4952@cindex AT&T disassembly flavor
4953@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4954Select the instruction set to use when disassembling the
4955program via the @code{disassemble} or @code{x/i} commands.
4956
4957Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4958can set @var{instruction-set} to either @code{intel} or @code{att}.
4959The default is @code{att}, the AT&T flavor used by default by Unix
4960assemblers for x86-based targets.
9c16f35a
EZ
4961
4962@kindex show disassembly-flavor
4963@item show disassembly-flavor
4964Show the current setting of the disassembly flavor.
c906108c
SS
4965@end table
4966
4967
6d2ebf8b 4968@node Data
c906108c
SS
4969@chapter Examining Data
4970
4971@cindex printing data
4972@cindex examining data
4973@kindex print
4974@kindex inspect
4975@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4976@c document because it is nonstandard... Under Epoch it displays in a
4977@c different window or something like that.
4978The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4979command (abbreviated @code{p}), or its synonym @code{inspect}. It
4980evaluates and prints the value of an expression of the language your
4981program is written in (@pxref{Languages, ,Using @value{GDBN} with
4982Different Languages}).
c906108c
SS
4983
4984@table @code
d4f3574e
SS
4985@item print @var{expr}
4986@itemx print /@var{f} @var{expr}
4987@var{expr} is an expression (in the source language). By default the
4988value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4989you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4990@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4991formats}.
4992
4993@item print
4994@itemx print /@var{f}
15387254 4995@cindex reprint the last value
d4f3574e 4996If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4997@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4998conveniently inspect the same value in an alternative format.
4999@end table
5000
5001A more low-level way of examining data is with the @code{x} command.
5002It examines data in memory at a specified address and prints it in a
5003specified format. @xref{Memory, ,Examining memory}.
5004
7a292a7a 5005If you are interested in information about types, or about how the
d4f3574e
SS
5006fields of a struct or a class are declared, use the @code{ptype @var{exp}}
5007command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 5008Table}.
c906108c
SS
5009
5010@menu
5011* Expressions:: Expressions
5012* Variables:: Program variables
5013* Arrays:: Artificial arrays
5014* Output Formats:: Output formats
5015* Memory:: Examining memory
5016* Auto Display:: Automatic display
5017* Print Settings:: Print settings
5018* Value History:: Value history
5019* Convenience Vars:: Convenience variables
5020* Registers:: Registers
c906108c 5021* Floating Point Hardware:: Floating point hardware
53c69bd7 5022* Vector Unit:: Vector Unit
721c2651 5023* OS Information:: Auxiliary data provided by operating system
29e57380 5024* Memory Region Attributes:: Memory region attributes
16d9dec6 5025* Dump/Restore Files:: Copy between memory and a file
384ee23f 5026* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
5027* Character Sets:: Debugging programs that use a different
5028 character set than GDB does
09d4efe1 5029* Caching Remote Data:: Data caching for remote targets
c906108c
SS
5030@end menu
5031
6d2ebf8b 5032@node Expressions
c906108c
SS
5033@section Expressions
5034
5035@cindex expressions
5036@code{print} and many other @value{GDBN} commands accept an expression and
5037compute its value. Any kind of constant, variable or operator defined
5038by the programming language you are using is valid in an expression in
e2e0bcd1
JB
5039@value{GDBN}. This includes conditional expressions, function calls,
5040casts, and string constants. It also includes preprocessor macros, if
5041you compiled your program to include this information; see
5042@ref{Compilation}.
c906108c 5043
15387254 5044@cindex arrays in expressions
d4f3574e
SS
5045@value{GDBN} supports array constants in expressions input by
5046the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 5047you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 5048memory that is @code{malloc}ed in the target program.
c906108c 5049
c906108c
SS
5050Because C is so widespread, most of the expressions shown in examples in
5051this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
5052Languages}, for information on how to use expressions in other
5053languages.
5054
5055In this section, we discuss operators that you can use in @value{GDBN}
5056expressions regardless of your programming language.
5057
15387254 5058@cindex casts, in expressions
c906108c
SS
5059Casts are supported in all languages, not just in C, because it is so
5060useful to cast a number into a pointer in order to examine a structure
5061at that address in memory.
5062@c FIXME: casts supported---Mod2 true?
c906108c
SS
5063
5064@value{GDBN} supports these operators, in addition to those common
5065to programming languages:
5066
5067@table @code
5068@item @@
5069@samp{@@} is a binary operator for treating parts of memory as arrays.
5070@xref{Arrays, ,Artificial arrays}, for more information.
5071
5072@item ::
5073@samp{::} allows you to specify a variable in terms of the file or
5074function where it is defined. @xref{Variables, ,Program variables}.
5075
5076@cindex @{@var{type}@}
5077@cindex type casting memory
5078@cindex memory, viewing as typed object
5079@cindex casts, to view memory
5080@item @{@var{type}@} @var{addr}
5081Refers to an object of type @var{type} stored at address @var{addr} in
5082memory. @var{addr} may be any expression whose value is an integer or
5083pointer (but parentheses are required around binary operators, just as in
5084a cast). This construct is allowed regardless of what kind of data is
5085normally supposed to reside at @var{addr}.
5086@end table
5087
6d2ebf8b 5088@node Variables
c906108c
SS
5089@section Program variables
5090
5091The most common kind of expression to use is the name of a variable
5092in your program.
5093
5094Variables in expressions are understood in the selected stack frame
5095(@pxref{Selection, ,Selecting a frame}); they must be either:
5096
5097@itemize @bullet
5098@item
5099global (or file-static)
5100@end itemize
5101
5d161b24 5102@noindent or
c906108c
SS
5103
5104@itemize @bullet
5105@item
5106visible according to the scope rules of the
5107programming language from the point of execution in that frame
5d161b24 5108@end itemize
c906108c
SS
5109
5110@noindent This means that in the function
5111
474c8240 5112@smallexample
c906108c
SS
5113foo (a)
5114 int a;
5115@{
5116 bar (a);
5117 @{
5118 int b = test ();
5119 bar (b);
5120 @}
5121@}
474c8240 5122@end smallexample
c906108c
SS
5123
5124@noindent
5125you can examine and use the variable @code{a} whenever your program is
5126executing within the function @code{foo}, but you can only use or
5127examine the variable @code{b} while your program is executing inside
5128the block where @code{b} is declared.
5129
5130@cindex variable name conflict
5131There is an exception: you can refer to a variable or function whose
5132scope is a single source file even if the current execution point is not
5133in this file. But it is possible to have more than one such variable or
5134function with the same name (in different source files). If that
5135happens, referring to that name has unpredictable effects. If you wish,
5136you can specify a static variable in a particular function or file,
15387254 5137using the colon-colon (@code{::}) notation:
c906108c 5138
d4f3574e 5139@cindex colon-colon, context for variables/functions
c906108c
SS
5140@iftex
5141@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 5142@cindex @code{::}, context for variables/functions
c906108c 5143@end iftex
474c8240 5144@smallexample
c906108c
SS
5145@var{file}::@var{variable}
5146@var{function}::@var{variable}
474c8240 5147@end smallexample
c906108c
SS
5148
5149@noindent
5150Here @var{file} or @var{function} is the name of the context for the
5151static @var{variable}. In the case of file names, you can use quotes to
5152make sure @value{GDBN} parses the file name as a single word---for example,
5153to print a global value of @code{x} defined in @file{f2.c}:
5154
474c8240 5155@smallexample
c906108c 5156(@value{GDBP}) p 'f2.c'::x
474c8240 5157@end smallexample
c906108c 5158
b37052ae 5159@cindex C@t{++} scope resolution
c906108c 5160This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 5161use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
5162scope resolution operator in @value{GDBN} expressions.
5163@c FIXME: Um, so what happens in one of those rare cases where it's in
5164@c conflict?? --mew
c906108c
SS
5165
5166@cindex wrong values
5167@cindex variable values, wrong
15387254
EZ
5168@cindex function entry/exit, wrong values of variables
5169@cindex optimized code, wrong values of variables
c906108c
SS
5170@quotation
5171@emph{Warning:} Occasionally, a local variable may appear to have the
5172wrong value at certain points in a function---just after entry to a new
5173scope, and just before exit.
5174@end quotation
5175You may see this problem when you are stepping by machine instructions.
5176This is because, on most machines, it takes more than one instruction to
5177set up a stack frame (including local variable definitions); if you are
5178stepping by machine instructions, variables may appear to have the wrong
5179values until the stack frame is completely built. On exit, it usually
5180also takes more than one machine instruction to destroy a stack frame;
5181after you begin stepping through that group of instructions, local
5182variable definitions may be gone.
5183
5184This may also happen when the compiler does significant optimizations.
5185To be sure of always seeing accurate values, turn off all optimization
5186when compiling.
5187
d4f3574e
SS
5188@cindex ``No symbol "foo" in current context''
5189Another possible effect of compiler optimizations is to optimize
5190unused variables out of existence, or assign variables to registers (as
5191opposed to memory addresses). Depending on the support for such cases
5192offered by the debug info format used by the compiler, @value{GDBN}
5193might not be able to display values for such local variables. If that
5194happens, @value{GDBN} will print a message like this:
5195
474c8240 5196@smallexample
d4f3574e 5197No symbol "foo" in current context.
474c8240 5198@end smallexample
d4f3574e
SS
5199
5200To solve such problems, either recompile without optimizations, or use a
5201different debug info format, if the compiler supports several such
15387254 5202formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
5203usually supports the @option{-gstabs+} option. @option{-gstabs+}
5204produces debug info in a format that is superior to formats such as
5205COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5206an effective form for debug info. @xref{Debugging Options,,Options
5207for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
5208@xref{C, , Debugging C++}, for more info about debug info formats
5209that are best suited to C@t{++} programs.
d4f3574e 5210
6d2ebf8b 5211@node Arrays
c906108c
SS
5212@section Artificial arrays
5213
5214@cindex artificial array
15387254 5215@cindex arrays
41afff9a 5216@kindex @@@r{, referencing memory as an array}
c906108c
SS
5217It is often useful to print out several successive objects of the
5218same type in memory; a section of an array, or an array of
5219dynamically determined size for which only a pointer exists in the
5220program.
5221
5222You can do this by referring to a contiguous span of memory as an
5223@dfn{artificial array}, using the binary operator @samp{@@}. The left
5224operand of @samp{@@} should be the first element of the desired array
5225and be an individual object. The right operand should be the desired length
5226of the array. The result is an array value whose elements are all of
5227the type of the left argument. The first element is actually the left
5228argument; the second element comes from bytes of memory immediately
5229following those that hold the first element, and so on. Here is an
5230example. If a program says
5231
474c8240 5232@smallexample
c906108c 5233int *array = (int *) malloc (len * sizeof (int));
474c8240 5234@end smallexample
c906108c
SS
5235
5236@noindent
5237you can print the contents of @code{array} with
5238
474c8240 5239@smallexample
c906108c 5240p *array@@len
474c8240 5241@end smallexample
c906108c
SS
5242
5243The left operand of @samp{@@} must reside in memory. Array values made
5244with @samp{@@} in this way behave just like other arrays in terms of
5245subscripting, and are coerced to pointers when used in expressions.
5246Artificial arrays most often appear in expressions via the value history
5247(@pxref{Value History, ,Value history}), after printing one out.
5248
5249Another way to create an artificial array is to use a cast.
5250This re-interprets a value as if it were an array.
5251The value need not be in memory:
474c8240 5252@smallexample
c906108c
SS
5253(@value{GDBP}) p/x (short[2])0x12345678
5254$1 = @{0x1234, 0x5678@}
474c8240 5255@end smallexample
c906108c
SS
5256
5257As a convenience, if you leave the array length out (as in
c3f6f71d 5258@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5259the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5260@smallexample
c906108c
SS
5261(@value{GDBP}) p/x (short[])0x12345678
5262$2 = @{0x1234, 0x5678@}
474c8240 5263@end smallexample
c906108c
SS
5264
5265Sometimes the artificial array mechanism is not quite enough; in
5266moderately complex data structures, the elements of interest may not
5267actually be adjacent---for example, if you are interested in the values
5268of pointers in an array. One useful work-around in this situation is
5269to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5270variables}) as a counter in an expression that prints the first
5271interesting value, and then repeat that expression via @key{RET}. For
5272instance, suppose you have an array @code{dtab} of pointers to
5273structures, and you are interested in the values of a field @code{fv}
5274in each structure. Here is an example of what you might type:
5275
474c8240 5276@smallexample
c906108c
SS
5277set $i = 0
5278p dtab[$i++]->fv
5279@key{RET}
5280@key{RET}
5281@dots{}
474c8240 5282@end smallexample
c906108c 5283
6d2ebf8b 5284@node Output Formats
c906108c
SS
5285@section Output formats
5286
5287@cindex formatted output
5288@cindex output formats
5289By default, @value{GDBN} prints a value according to its data type. Sometimes
5290this is not what you want. For example, you might want to print a number
5291in hex, or a pointer in decimal. Or you might want to view data in memory
5292at a certain address as a character string or as an instruction. To do
5293these things, specify an @dfn{output format} when you print a value.
5294
5295The simplest use of output formats is to say how to print a value
5296already computed. This is done by starting the arguments of the
5297@code{print} command with a slash and a format letter. The format
5298letters supported are:
5299
5300@table @code
5301@item x
5302Regard the bits of the value as an integer, and print the integer in
5303hexadecimal.
5304
5305@item d
5306Print as integer in signed decimal.
5307
5308@item u
5309Print as integer in unsigned decimal.
5310
5311@item o
5312Print as integer in octal.
5313
5314@item t
5315Print as integer in binary. The letter @samp{t} stands for ``two''.
5316@footnote{@samp{b} cannot be used because these format letters are also
5317used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5318see @ref{Memory,,Examining memory}.}
c906108c
SS
5319
5320@item a
5321@cindex unknown address, locating
3d67e040 5322@cindex locate address
c906108c
SS
5323Print as an address, both absolute in hexadecimal and as an offset from
5324the nearest preceding symbol. You can use this format used to discover
5325where (in what function) an unknown address is located:
5326
474c8240 5327@smallexample
c906108c
SS
5328(@value{GDBP}) p/a 0x54320
5329$3 = 0x54320 <_initialize_vx+396>
474c8240 5330@end smallexample
c906108c 5331
3d67e040
EZ
5332@noindent
5333The command @code{info symbol 0x54320} yields similar results.
5334@xref{Symbols, info symbol}.
5335
c906108c 5336@item c
51274035
EZ
5337Regard as an integer and print it as a character constant. This
5338prints both the numerical value and its character representation. The
5339character representation is replaced with the octal escape @samp{\nnn}
5340for characters outside the 7-bit @sc{ascii} range.
c906108c
SS
5341
5342@item f
5343Regard the bits of the value as a floating point number and print
5344using typical floating point syntax.
5345@end table
5346
5347For example, to print the program counter in hex (@pxref{Registers}), type
5348
474c8240 5349@smallexample
c906108c 5350p/x $pc
474c8240 5351@end smallexample
c906108c
SS
5352
5353@noindent
5354Note that no space is required before the slash; this is because command
5355names in @value{GDBN} cannot contain a slash.
5356
5357To reprint the last value in the value history with a different format,
5358you can use the @code{print} command with just a format and no
5359expression. For example, @samp{p/x} reprints the last value in hex.
5360
6d2ebf8b 5361@node Memory
c906108c
SS
5362@section Examining memory
5363
5364You can use the command @code{x} (for ``examine'') to examine memory in
5365any of several formats, independently of your program's data types.
5366
5367@cindex examining memory
5368@table @code
41afff9a 5369@kindex x @r{(examine memory)}
c906108c
SS
5370@item x/@var{nfu} @var{addr}
5371@itemx x @var{addr}
5372@itemx x
5373Use the @code{x} command to examine memory.
5374@end table
5375
5376@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5377much memory to display and how to format it; @var{addr} is an
5378expression giving the address where you want to start displaying memory.
5379If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5380Several commands set convenient defaults for @var{addr}.
5381
5382@table @r
5383@item @var{n}, the repeat count
5384The repeat count is a decimal integer; the default is 1. It specifies
5385how much memory (counting by units @var{u}) to display.
5386@c This really is **decimal**; unaffected by 'set radix' as of GDB
5387@c 4.1.2.
5388
5389@item @var{f}, the display format
51274035
EZ
5390The display format is one of the formats used by @code{print}
5391(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
5392@samp{f}), and in addition @samp{s} (for null-terminated strings) and
5393@samp{i} (for machine instructions). The default is @samp{x}
5394(hexadecimal) initially. The default changes each time you use either
5395@code{x} or @code{print}.
c906108c
SS
5396
5397@item @var{u}, the unit size
5398The unit size is any of
5399
5400@table @code
5401@item b
5402Bytes.
5403@item h
5404Halfwords (two bytes).
5405@item w
5406Words (four bytes). This is the initial default.
5407@item g
5408Giant words (eight bytes).
5409@end table
5410
5411Each time you specify a unit size with @code{x}, that size becomes the
5412default unit the next time you use @code{x}. (For the @samp{s} and
5413@samp{i} formats, the unit size is ignored and is normally not written.)
5414
5415@item @var{addr}, starting display address
5416@var{addr} is the address where you want @value{GDBN} to begin displaying
5417memory. The expression need not have a pointer value (though it may);
5418it is always interpreted as an integer address of a byte of memory.
5419@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5420@var{addr} is usually just after the last address examined---but several
5421other commands also set the default address: @code{info breakpoints} (to
5422the address of the last breakpoint listed), @code{info line} (to the
5423starting address of a line), and @code{print} (if you use it to display
5424a value from memory).
5425@end table
5426
5427For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5428(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5429starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5430words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5431@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5432
5433Since the letters indicating unit sizes are all distinct from the
5434letters specifying output formats, you do not have to remember whether
5435unit size or format comes first; either order works. The output
5436specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5437(However, the count @var{n} must come first; @samp{wx4} does not work.)
5438
5439Even though the unit size @var{u} is ignored for the formats @samp{s}
5440and @samp{i}, you might still want to use a count @var{n}; for example,
5441@samp{3i} specifies that you want to see three machine instructions,
5442including any operands. The command @code{disassemble} gives an
d4f3574e 5443alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5444Code,,Source and machine code}.
5445
5446All the defaults for the arguments to @code{x} are designed to make it
5447easy to continue scanning memory with minimal specifications each time
5448you use @code{x}. For example, after you have inspected three machine
5449instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5450with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5451the repeat count @var{n} is used again; the other arguments default as
5452for successive uses of @code{x}.
5453
5454@cindex @code{$_}, @code{$__}, and value history
5455The addresses and contents printed by the @code{x} command are not saved
5456in the value history because there is often too much of them and they
5457would get in the way. Instead, @value{GDBN} makes these values available for
5458subsequent use in expressions as values of the convenience variables
5459@code{$_} and @code{$__}. After an @code{x} command, the last address
5460examined is available for use in expressions in the convenience variable
5461@code{$_}. The contents of that address, as examined, are available in
5462the convenience variable @code{$__}.
5463
5464If the @code{x} command has a repeat count, the address and contents saved
5465are from the last memory unit printed; this is not the same as the last
5466address printed if several units were printed on the last line of output.
5467
09d4efe1
EZ
5468@cindex remote memory comparison
5469@cindex verify remote memory image
5470When you are debugging a program running on a remote target machine
5471(@pxref{Remote}), you may wish to verify the program's image in the
5472remote machine's memory against the executable file you downloaded to
5473the target. The @code{compare-sections} command is provided for such
5474situations.
5475
5476@table @code
5477@kindex compare-sections
5478@item compare-sections @r{[}@var{section-name}@r{]}
5479Compare the data of a loadable section @var{section-name} in the
5480executable file of the program being debugged with the same section in
5481the remote machine's memory, and report any mismatches. With no
5482arguments, compares all loadable sections. This command's
5483availability depends on the target's support for the @code{"qCRC"}
5484remote request.
5485@end table
5486
6d2ebf8b 5487@node Auto Display
c906108c
SS
5488@section Automatic display
5489@cindex automatic display
5490@cindex display of expressions
5491
5492If you find that you want to print the value of an expression frequently
5493(to see how it changes), you might want to add it to the @dfn{automatic
5494display list} so that @value{GDBN} prints its value each time your program stops.
5495Each expression added to the list is given a number to identify it;
5496to remove an expression from the list, you specify that number.
5497The automatic display looks like this:
5498
474c8240 5499@smallexample
c906108c
SS
55002: foo = 38
55013: bar[5] = (struct hack *) 0x3804
474c8240 5502@end smallexample
c906108c
SS
5503
5504@noindent
5505This display shows item numbers, expressions and their current values. As with
5506displays you request manually using @code{x} or @code{print}, you can
5507specify the output format you prefer; in fact, @code{display} decides
5508whether to use @code{print} or @code{x} depending on how elaborate your
5509format specification is---it uses @code{x} if you specify a unit size,
5510or one of the two formats (@samp{i} and @samp{s}) that are only
5511supported by @code{x}; otherwise it uses @code{print}.
5512
5513@table @code
5514@kindex display
d4f3574e
SS
5515@item display @var{expr}
5516Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5517each time your program stops. @xref{Expressions, ,Expressions}.
5518
5519@code{display} does not repeat if you press @key{RET} again after using it.
5520
d4f3574e 5521@item display/@var{fmt} @var{expr}
c906108c 5522For @var{fmt} specifying only a display format and not a size or
d4f3574e 5523count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5524arrange to display it each time in the specified format @var{fmt}.
5525@xref{Output Formats,,Output formats}.
5526
5527@item display/@var{fmt} @var{addr}
5528For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5529number of units, add the expression @var{addr} as a memory address to
5530be examined each time your program stops. Examining means in effect
5531doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5532@end table
5533
5534For example, @samp{display/i $pc} can be helpful, to see the machine
5535instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5536is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5537
5538@table @code
5539@kindex delete display
5540@kindex undisplay
5541@item undisplay @var{dnums}@dots{}
5542@itemx delete display @var{dnums}@dots{}
5543Remove item numbers @var{dnums} from the list of expressions to display.
5544
5545@code{undisplay} does not repeat if you press @key{RET} after using it.
5546(Otherwise you would just get the error @samp{No display number @dots{}}.)
5547
5548@kindex disable display
5549@item disable display @var{dnums}@dots{}
5550Disable the display of item numbers @var{dnums}. A disabled display
5551item is not printed automatically, but is not forgotten. It may be
5552enabled again later.
5553
5554@kindex enable display
5555@item enable display @var{dnums}@dots{}
5556Enable display of item numbers @var{dnums}. It becomes effective once
5557again in auto display of its expression, until you specify otherwise.
5558
5559@item display
5560Display the current values of the expressions on the list, just as is
5561done when your program stops.
5562
5563@kindex info display
5564@item info display
5565Print the list of expressions previously set up to display
5566automatically, each one with its item number, but without showing the
5567values. This includes disabled expressions, which are marked as such.
5568It also includes expressions which would not be displayed right now
5569because they refer to automatic variables not currently available.
5570@end table
5571
15387254 5572@cindex display disabled out of scope
c906108c
SS
5573If a display expression refers to local variables, then it does not make
5574sense outside the lexical context for which it was set up. Such an
5575expression is disabled when execution enters a context where one of its
5576variables is not defined. For example, if you give the command
5577@code{display last_char} while inside a function with an argument
5578@code{last_char}, @value{GDBN} displays this argument while your program
5579continues to stop inside that function. When it stops elsewhere---where
5580there is no variable @code{last_char}---the display is disabled
5581automatically. The next time your program stops where @code{last_char}
5582is meaningful, you can enable the display expression once again.
5583
6d2ebf8b 5584@node Print Settings
c906108c
SS
5585@section Print settings
5586
5587@cindex format options
5588@cindex print settings
5589@value{GDBN} provides the following ways to control how arrays, structures,
5590and symbols are printed.
5591
5592@noindent
5593These settings are useful for debugging programs in any language:
5594
5595@table @code
4644b6e3 5596@kindex set print
c906108c
SS
5597@item set print address
5598@itemx set print address on
4644b6e3 5599@cindex print/don't print memory addresses
c906108c
SS
5600@value{GDBN} prints memory addresses showing the location of stack
5601traces, structure values, pointer values, breakpoints, and so forth,
5602even when it also displays the contents of those addresses. The default
5603is @code{on}. For example, this is what a stack frame display looks like with
5604@code{set print address on}:
5605
5606@smallexample
5607@group
5608(@value{GDBP}) f
5609#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5610 at input.c:530
5611530 if (lquote != def_lquote)
5612@end group
5613@end smallexample
5614
5615@item set print address off
5616Do not print addresses when displaying their contents. For example,
5617this is the same stack frame displayed with @code{set print address off}:
5618
5619@smallexample
5620@group
5621(@value{GDBP}) set print addr off
5622(@value{GDBP}) f
5623#0 set_quotes (lq="<<", rq=">>") at input.c:530
5624530 if (lquote != def_lquote)
5625@end group
5626@end smallexample
5627
5628You can use @samp{set print address off} to eliminate all machine
5629dependent displays from the @value{GDBN} interface. For example, with
5630@code{print address off}, you should get the same text for backtraces on
5631all machines---whether or not they involve pointer arguments.
5632
4644b6e3 5633@kindex show print
c906108c
SS
5634@item show print address
5635Show whether or not addresses are to be printed.
5636@end table
5637
5638When @value{GDBN} prints a symbolic address, it normally prints the
5639closest earlier symbol plus an offset. If that symbol does not uniquely
5640identify the address (for example, it is a name whose scope is a single
5641source file), you may need to clarify. One way to do this is with
5642@code{info line}, for example @samp{info line *0x4537}. Alternately,
5643you can set @value{GDBN} to print the source file and line number when
5644it prints a symbolic address:
5645
5646@table @code
c906108c 5647@item set print symbol-filename on
9c16f35a
EZ
5648@cindex source file and line of a symbol
5649@cindex symbol, source file and line
c906108c
SS
5650Tell @value{GDBN} to print the source file name and line number of a
5651symbol in the symbolic form of an address.
5652
5653@item set print symbol-filename off
5654Do not print source file name and line number of a symbol. This is the
5655default.
5656
c906108c
SS
5657@item show print symbol-filename
5658Show whether or not @value{GDBN} will print the source file name and
5659line number of a symbol in the symbolic form of an address.
5660@end table
5661
5662Another situation where it is helpful to show symbol filenames and line
5663numbers is when disassembling code; @value{GDBN} shows you the line
5664number and source file that corresponds to each instruction.
5665
5666Also, you may wish to see the symbolic form only if the address being
5667printed is reasonably close to the closest earlier symbol:
5668
5669@table @code
c906108c 5670@item set print max-symbolic-offset @var{max-offset}
4644b6e3 5671@cindex maximum value for offset of closest symbol
c906108c
SS
5672Tell @value{GDBN} to only display the symbolic form of an address if the
5673offset between the closest earlier symbol and the address is less than
5d161b24 5674@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5675to always print the symbolic form of an address if any symbol precedes it.
5676
c906108c
SS
5677@item show print max-symbolic-offset
5678Ask how large the maximum offset is that @value{GDBN} prints in a
5679symbolic address.
5680@end table
5681
5682@cindex wild pointer, interpreting
5683@cindex pointer, finding referent
5684If you have a pointer and you are not sure where it points, try
5685@samp{set print symbol-filename on}. Then you can determine the name
5686and source file location of the variable where it points, using
5687@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5688For example, here @value{GDBN} shows that a variable @code{ptt} points
5689at another variable @code{t}, defined in @file{hi2.c}:
5690
474c8240 5691@smallexample
c906108c
SS
5692(@value{GDBP}) set print symbol-filename on
5693(@value{GDBP}) p/a ptt
5694$4 = 0xe008 <t in hi2.c>
474c8240 5695@end smallexample
c906108c
SS
5696
5697@quotation
5698@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5699does not show the symbol name and filename of the referent, even with
5700the appropriate @code{set print} options turned on.
5701@end quotation
5702
5703Other settings control how different kinds of objects are printed:
5704
5705@table @code
c906108c
SS
5706@item set print array
5707@itemx set print array on
4644b6e3 5708@cindex pretty print arrays
c906108c
SS
5709Pretty print arrays. This format is more convenient to read,
5710but uses more space. The default is off.
5711
5712@item set print array off
5713Return to compressed format for arrays.
5714
c906108c
SS
5715@item show print array
5716Show whether compressed or pretty format is selected for displaying
5717arrays.
5718
c906108c 5719@item set print elements @var{number-of-elements}
4644b6e3 5720@cindex number of array elements to print
9c16f35a 5721@cindex limit on number of printed array elements
c906108c
SS
5722Set a limit on how many elements of an array @value{GDBN} will print.
5723If @value{GDBN} is printing a large array, it stops printing after it has
5724printed the number of elements set by the @code{set print elements} command.
5725This limit also applies to the display of strings.
d4f3574e 5726When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5727Setting @var{number-of-elements} to zero means that the printing is unlimited.
5728
c906108c
SS
5729@item show print elements
5730Display the number of elements of a large array that @value{GDBN} will print.
5731If the number is 0, then the printing is unlimited.
5732
9c16f35a
EZ
5733@item set print repeats
5734@cindex repeated array elements
5735Set the threshold for suppressing display of repeated array
5736elelments. When the number of consecutive identical elements of an
5737array exceeds the threshold, @value{GDBN} prints the string
5738@code{"<repeats @var{n} times>"}, where @var{n} is the number of
5739identical repetitions, instead of displaying the identical elements
5740themselves. Setting the threshold to zero will cause all elements to
5741be individually printed. The default threshold is 10.
5742
5743@item show print repeats
5744Display the current threshold for printing repeated identical
5745elements.
5746
c906108c 5747@item set print null-stop
4644b6e3 5748@cindex @sc{null} elements in arrays
c906108c 5749Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5750@sc{null} is encountered. This is useful when large arrays actually
c906108c 5751contain only short strings.
d4f3574e 5752The default is off.
c906108c 5753
9c16f35a
EZ
5754@item show print null-stop
5755Show whether @value{GDBN} stops printing an array on the first
5756@sc{null} character.
5757
c906108c 5758@item set print pretty on
9c16f35a
EZ
5759@cindex print structures in indented form
5760@cindex indentation in structure display
5d161b24 5761Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5762per line, like this:
5763
5764@smallexample
5765@group
5766$1 = @{
5767 next = 0x0,
5768 flags = @{
5769 sweet = 1,
5770 sour = 1
5771 @},
5772 meat = 0x54 "Pork"
5773@}
5774@end group
5775@end smallexample
5776
5777@item set print pretty off
5778Cause @value{GDBN} to print structures in a compact format, like this:
5779
5780@smallexample
5781@group
5782$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5783meat = 0x54 "Pork"@}
5784@end group
5785@end smallexample
5786
5787@noindent
5788This is the default format.
5789
c906108c
SS
5790@item show print pretty
5791Show which format @value{GDBN} is using to print structures.
5792
c906108c 5793@item set print sevenbit-strings on
4644b6e3
EZ
5794@cindex eight-bit characters in strings
5795@cindex octal escapes in strings
c906108c
SS
5796Print using only seven-bit characters; if this option is set,
5797@value{GDBN} displays any eight-bit characters (in strings or
5798character values) using the notation @code{\}@var{nnn}. This setting is
5799best if you are working in English (@sc{ascii}) and you use the
5800high-order bit of characters as a marker or ``meta'' bit.
5801
5802@item set print sevenbit-strings off
5803Print full eight-bit characters. This allows the use of more
5804international character sets, and is the default.
5805
c906108c
SS
5806@item show print sevenbit-strings
5807Show whether or not @value{GDBN} is printing only seven-bit characters.
5808
c906108c 5809@item set print union on
4644b6e3 5810@cindex unions in structures, printing
9c16f35a
EZ
5811Tell @value{GDBN} to print unions which are contained in structures
5812and other unions. This is the default setting.
c906108c
SS
5813
5814@item set print union off
9c16f35a
EZ
5815Tell @value{GDBN} not to print unions which are contained in
5816structures and other unions. @value{GDBN} will print @code{"@{...@}"}
5817instead.
c906108c 5818
c906108c
SS
5819@item show print union
5820Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 5821structures and other unions.
c906108c
SS
5822
5823For example, given the declarations
5824
5825@smallexample
5826typedef enum @{Tree, Bug@} Species;
5827typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5828typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5829 Bug_forms;
5830
5831struct thing @{
5832 Species it;
5833 union @{
5834 Tree_forms tree;
5835 Bug_forms bug;
5836 @} form;
5837@};
5838
5839struct thing foo = @{Tree, @{Acorn@}@};
5840@end smallexample
5841
5842@noindent
5843with @code{set print union on} in effect @samp{p foo} would print
5844
5845@smallexample
5846$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5847@end smallexample
5848
5849@noindent
5850and with @code{set print union off} in effect it would print
5851
5852@smallexample
5853$1 = @{it = Tree, form = @{...@}@}
5854@end smallexample
9c16f35a
EZ
5855
5856@noindent
5857@code{set print union} affects programs written in C-like languages
5858and in Pascal.
c906108c
SS
5859@end table
5860
c906108c
SS
5861@need 1000
5862@noindent
b37052ae 5863These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5864
5865@table @code
4644b6e3 5866@cindex demangling C@t{++} names
c906108c
SS
5867@item set print demangle
5868@itemx set print demangle on
b37052ae 5869Print C@t{++} names in their source form rather than in the encoded
c906108c 5870(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5871linkage. The default is on.
c906108c 5872
c906108c 5873@item show print demangle
b37052ae 5874Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 5875
c906108c
SS
5876@item set print asm-demangle
5877@itemx set print asm-demangle on
b37052ae 5878Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5879in assembler code printouts such as instruction disassemblies.
5880The default is off.
5881
c906108c 5882@item show print asm-demangle
b37052ae 5883Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5884or demangled form.
5885
b37052ae
EZ
5886@cindex C@t{++} symbol decoding style
5887@cindex symbol decoding style, C@t{++}
a8f24a35 5888@kindex set demangle-style
c906108c
SS
5889@item set demangle-style @var{style}
5890Choose among several encoding schemes used by different compilers to
b37052ae 5891represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5892
5893@table @code
5894@item auto
5895Allow @value{GDBN} to choose a decoding style by inspecting your program.
5896
5897@item gnu
b37052ae 5898Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5899This is the default.
c906108c
SS
5900
5901@item hp
b37052ae 5902Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5903
5904@item lucid
b37052ae 5905Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5906
5907@item arm
b37052ae 5908Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5909@strong{Warning:} this setting alone is not sufficient to allow
5910debugging @code{cfront}-generated executables. @value{GDBN} would
5911require further enhancement to permit that.
5912
5913@end table
5914If you omit @var{style}, you will see a list of possible formats.
5915
c906108c 5916@item show demangle-style
b37052ae 5917Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 5918
c906108c
SS
5919@item set print object
5920@itemx set print object on
4644b6e3 5921@cindex derived type of an object, printing
9c16f35a 5922@cindex display derived types
c906108c
SS
5923When displaying a pointer to an object, identify the @emph{actual}
5924(derived) type of the object rather than the @emph{declared} type, using
5925the virtual function table.
5926
5927@item set print object off
5928Display only the declared type of objects, without reference to the
5929virtual function table. This is the default setting.
5930
c906108c
SS
5931@item show print object
5932Show whether actual, or declared, object types are displayed.
5933
c906108c
SS
5934@item set print static-members
5935@itemx set print static-members on
4644b6e3 5936@cindex static members of C@t{++} objects
b37052ae 5937Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5938
5939@item set print static-members off
b37052ae 5940Do not print static members when displaying a C@t{++} object.
c906108c 5941
c906108c 5942@item show print static-members
9c16f35a
EZ
5943Show whether C@t{++} static members are printed or not.
5944
5945@item set print pascal_static-members
5946@itemx set print pascal_static-members on
5947@cindex static members of Pacal objects
5948@cindex Pacal objects, static members display
5949Print static members when displaying a Pascal object. The default is on.
5950
5951@item set print pascal_static-members off
5952Do not print static members when displaying a Pascal object.
5953
5954@item show print pascal_static-members
5955Show whether Pascal static members are printed or not.
c906108c
SS
5956
5957@c These don't work with HP ANSI C++ yet.
c906108c
SS
5958@item set print vtbl
5959@itemx set print vtbl on
4644b6e3 5960@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
5961@cindex virtual functions (C@t{++}) display
5962@cindex VTBL display
b37052ae 5963Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5964(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5965ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5966
5967@item set print vtbl off
b37052ae 5968Do not pretty print C@t{++} virtual function tables.
c906108c 5969
c906108c 5970@item show print vtbl
b37052ae 5971Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5972@end table
c906108c 5973
6d2ebf8b 5974@node Value History
c906108c
SS
5975@section Value history
5976
5977@cindex value history
9c16f35a 5978@cindex history of values printed by @value{GDBN}
5d161b24
DB
5979Values printed by the @code{print} command are saved in the @value{GDBN}
5980@dfn{value history}. This allows you to refer to them in other expressions.
5981Values are kept until the symbol table is re-read or discarded
5982(for example with the @code{file} or @code{symbol-file} commands).
5983When the symbol table changes, the value history is discarded,
5984since the values may contain pointers back to the types defined in the
c906108c
SS
5985symbol table.
5986
5987@cindex @code{$}
5988@cindex @code{$$}
5989@cindex history number
5990The values printed are given @dfn{history numbers} by which you can
5991refer to them. These are successive integers starting with one.
5992@code{print} shows you the history number assigned to a value by
5993printing @samp{$@var{num} = } before the value; here @var{num} is the
5994history number.
5995
5996To refer to any previous value, use @samp{$} followed by the value's
5997history number. The way @code{print} labels its output is designed to
5998remind you of this. Just @code{$} refers to the most recent value in
5999the history, and @code{$$} refers to the value before that.
6000@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
6001is the value just prior to @code{$$}, @code{$$1} is equivalent to
6002@code{$$}, and @code{$$0} is equivalent to @code{$}.
6003
6004For example, suppose you have just printed a pointer to a structure and
6005want to see the contents of the structure. It suffices to type
6006
474c8240 6007@smallexample
c906108c 6008p *$
474c8240 6009@end smallexample
c906108c
SS
6010
6011If you have a chain of structures where the component @code{next} points
6012to the next one, you can print the contents of the next one with this:
6013
474c8240 6014@smallexample
c906108c 6015p *$.next
474c8240 6016@end smallexample
c906108c
SS
6017
6018@noindent
6019You can print successive links in the chain by repeating this
6020command---which you can do by just typing @key{RET}.
6021
6022Note that the history records values, not expressions. If the value of
6023@code{x} is 4 and you type these commands:
6024
474c8240 6025@smallexample
c906108c
SS
6026print x
6027set x=5
474c8240 6028@end smallexample
c906108c
SS
6029
6030@noindent
6031then the value recorded in the value history by the @code{print} command
6032remains 4 even though the value of @code{x} has changed.
6033
6034@table @code
6035@kindex show values
6036@item show values
6037Print the last ten values in the value history, with their item numbers.
6038This is like @samp{p@ $$9} repeated ten times, except that @code{show
6039values} does not change the history.
6040
6041@item show values @var{n}
6042Print ten history values centered on history item number @var{n}.
6043
6044@item show values +
6045Print ten history values just after the values last printed. If no more
6046values are available, @code{show values +} produces no display.
6047@end table
6048
6049Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
6050same effect as @samp{show values +}.
6051
6d2ebf8b 6052@node Convenience Vars
c906108c
SS
6053@section Convenience variables
6054
6055@cindex convenience variables
9c16f35a 6056@cindex user-defined variables
c906108c
SS
6057@value{GDBN} provides @dfn{convenience variables} that you can use within
6058@value{GDBN} to hold on to a value and refer to it later. These variables
6059exist entirely within @value{GDBN}; they are not part of your program, and
6060setting a convenience variable has no direct effect on further execution
6061of your program. That is why you can use them freely.
6062
6063Convenience variables are prefixed with @samp{$}. Any name preceded by
6064@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 6065the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
6066(Value history references, in contrast, are @emph{numbers} preceded
6067by @samp{$}. @xref{Value History, ,Value history}.)
6068
6069You can save a value in a convenience variable with an assignment
6070expression, just as you would set a variable in your program.
6071For example:
6072
474c8240 6073@smallexample
c906108c 6074set $foo = *object_ptr
474c8240 6075@end smallexample
c906108c
SS
6076
6077@noindent
6078would save in @code{$foo} the value contained in the object pointed to by
6079@code{object_ptr}.
6080
6081Using a convenience variable for the first time creates it, but its
6082value is @code{void} until you assign a new value. You can alter the
6083value with another assignment at any time.
6084
6085Convenience variables have no fixed types. You can assign a convenience
6086variable any type of value, including structures and arrays, even if
6087that variable already has a value of a different type. The convenience
6088variable, when used as an expression, has the type of its current value.
6089
6090@table @code
6091@kindex show convenience
9c16f35a 6092@cindex show all user variables
c906108c
SS
6093@item show convenience
6094Print a list of convenience variables used so far, and their values.
d4f3574e 6095Abbreviated @code{show conv}.
c906108c
SS
6096@end table
6097
6098One of the ways to use a convenience variable is as a counter to be
6099incremented or a pointer to be advanced. For example, to print
6100a field from successive elements of an array of structures:
6101
474c8240 6102@smallexample
c906108c
SS
6103set $i = 0
6104print bar[$i++]->contents
474c8240 6105@end smallexample
c906108c 6106
d4f3574e
SS
6107@noindent
6108Repeat that command by typing @key{RET}.
c906108c
SS
6109
6110Some convenience variables are created automatically by @value{GDBN} and given
6111values likely to be useful.
6112
6113@table @code
41afff9a 6114@vindex $_@r{, convenience variable}
c906108c
SS
6115@item $_
6116The variable @code{$_} is automatically set by the @code{x} command to
6117the last address examined (@pxref{Memory, ,Examining memory}). Other
6118commands which provide a default address for @code{x} to examine also
6119set @code{$_} to that address; these commands include @code{info line}
6120and @code{info breakpoint}. The type of @code{$_} is @code{void *}
6121except when set by the @code{x} command, in which case it is a pointer
6122to the type of @code{$__}.
6123
41afff9a 6124@vindex $__@r{, convenience variable}
c906108c
SS
6125@item $__
6126The variable @code{$__} is automatically set by the @code{x} command
6127to the value found in the last address examined. Its type is chosen
6128to match the format in which the data was printed.
6129
6130@item $_exitcode
41afff9a 6131@vindex $_exitcode@r{, convenience variable}
c906108c
SS
6132The variable @code{$_exitcode} is automatically set to the exit code when
6133the program being debugged terminates.
6134@end table
6135
53a5351d
JM
6136On HP-UX systems, if you refer to a function or variable name that
6137begins with a dollar sign, @value{GDBN} searches for a user or system
6138name first, before it searches for a convenience variable.
c906108c 6139
6d2ebf8b 6140@node Registers
c906108c
SS
6141@section Registers
6142
6143@cindex registers
6144You can refer to machine register contents, in expressions, as variables
6145with names starting with @samp{$}. The names of registers are different
6146for each machine; use @code{info registers} to see the names used on
6147your machine.
6148
6149@table @code
6150@kindex info registers
6151@item info registers
6152Print the names and values of all registers except floating-point
c85508ee 6153and vector registers (in the selected stack frame).
c906108c
SS
6154
6155@kindex info all-registers
6156@cindex floating point registers
6157@item info all-registers
6158Print the names and values of all registers, including floating-point
c85508ee 6159and vector registers (in the selected stack frame).
c906108c
SS
6160
6161@item info registers @var{regname} @dots{}
6162Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
6163As discussed in detail below, register values are normally relative to
6164the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
6165the machine you are using, with or without the initial @samp{$}.
6166@end table
6167
e09f16f9
EZ
6168@cindex stack pointer register
6169@cindex program counter register
6170@cindex process status register
6171@cindex frame pointer register
6172@cindex standard registers
c906108c
SS
6173@value{GDBN} has four ``standard'' register names that are available (in
6174expressions) on most machines---whenever they do not conflict with an
6175architecture's canonical mnemonics for registers. The register names
6176@code{$pc} and @code{$sp} are used for the program counter register and
6177the stack pointer. @code{$fp} is used for a register that contains a
6178pointer to the current stack frame, and @code{$ps} is used for a
6179register that contains the processor status. For example,
6180you could print the program counter in hex with
6181
474c8240 6182@smallexample
c906108c 6183p/x $pc
474c8240 6184@end smallexample
c906108c
SS
6185
6186@noindent
6187or print the instruction to be executed next with
6188
474c8240 6189@smallexample
c906108c 6190x/i $pc
474c8240 6191@end smallexample
c906108c
SS
6192
6193@noindent
6194or add four to the stack pointer@footnote{This is a way of removing
6195one word from the stack, on machines where stacks grow downward in
6196memory (most machines, nowadays). This assumes that the innermost
6197stack frame is selected; setting @code{$sp} is not allowed when other
6198stack frames are selected. To pop entire frames off the stack,
6199regardless of machine architecture, use @code{return};
d4f3574e 6200see @ref{Returning, ,Returning from a function}.} with
c906108c 6201
474c8240 6202@smallexample
c906108c 6203set $sp += 4
474c8240 6204@end smallexample
c906108c
SS
6205
6206Whenever possible, these four standard register names are available on
6207your machine even though the machine has different canonical mnemonics,
6208so long as there is no conflict. The @code{info registers} command
6209shows the canonical names. For example, on the SPARC, @code{info
6210registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
6211can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6212is an alias for the @sc{eflags} register.
c906108c
SS
6213
6214@value{GDBN} always considers the contents of an ordinary register as an
6215integer when the register is examined in this way. Some machines have
6216special registers which can hold nothing but floating point; these
6217registers are considered to have floating point values. There is no way
6218to refer to the contents of an ordinary register as floating point value
6219(although you can @emph{print} it as a floating point value with
6220@samp{print/f $@var{regname}}).
6221
6222Some registers have distinct ``raw'' and ``virtual'' data formats. This
6223means that the data format in which the register contents are saved by
6224the operating system is not the same one that your program normally
6225sees. For example, the registers of the 68881 floating point
6226coprocessor are always saved in ``extended'' (raw) format, but all C
6227programs expect to work with ``double'' (virtual) format. In such
5d161b24 6228cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
6229that makes sense for your program), but the @code{info registers} command
6230prints the data in both formats.
6231
6232Normally, register values are relative to the selected stack frame
6233(@pxref{Selection, ,Selecting a frame}). This means that you get the
6234value that the register would contain if all stack frames farther in
6235were exited and their saved registers restored. In order to see the
6236true contents of hardware registers, you must select the innermost
6237frame (with @samp{frame 0}).
6238
6239However, @value{GDBN} must deduce where registers are saved, from the machine
6240code generated by your compiler. If some registers are not saved, or if
6241@value{GDBN} is unable to locate the saved registers, the selected stack
6242frame makes no difference.
6243
6d2ebf8b 6244@node Floating Point Hardware
c906108c
SS
6245@section Floating point hardware
6246@cindex floating point
6247
6248Depending on the configuration, @value{GDBN} may be able to give
6249you more information about the status of the floating point hardware.
6250
6251@table @code
6252@kindex info float
6253@item info float
6254Display hardware-dependent information about the floating
6255point unit. The exact contents and layout vary depending on the
6256floating point chip. Currently, @samp{info float} is supported on
6257the ARM and x86 machines.
6258@end table
c906108c 6259
e76f1f2e
AC
6260@node Vector Unit
6261@section Vector Unit
6262@cindex vector unit
6263
6264Depending on the configuration, @value{GDBN} may be able to give you
6265more information about the status of the vector unit.
6266
6267@table @code
6268@kindex info vector
6269@item info vector
6270Display information about the vector unit. The exact contents and
6271layout vary depending on the hardware.
6272@end table
6273
721c2651
EZ
6274@node OS Information
6275@section Operating system auxiliary information
6276@cindex OS information
6277
6278@value{GDBN} provides interfaces to useful OS facilities that can help
6279you debug your program.
6280
6281@cindex @code{ptrace} system call
6282@cindex @code{struct user} contents
6283When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6284machines), it interfaces with the inferior via the @code{ptrace}
6285system call. The operating system creates a special sata structure,
6286called @code{struct user}, for this interface. You can use the
6287command @code{info udot} to display the contents of this data
6288structure.
6289
6290@table @code
6291@item info udot
6292@kindex info udot
6293Display the contents of the @code{struct user} maintained by the OS
6294kernel for the program being debugged. @value{GDBN} displays the
6295contents of @code{struct user} as a list of hex numbers, similar to
6296the @code{examine} command.
6297@end table
6298
b383017d
RM
6299@cindex auxiliary vector
6300@cindex vector, auxiliary
b383017d
RM
6301Some operating systems supply an @dfn{auxiliary vector} to programs at
6302startup. This is akin to the arguments and environment that you
6303specify for a program, but contains a system-dependent variety of
6304binary values that tell system libraries important details about the
6305hardware, operating system, and process. Each value's purpose is
6306identified by an integer tag; the meanings are well-known but system-specific.
6307Depending on the configuration and operating system facilities,
9c16f35a
EZ
6308@value{GDBN} may be able to show you this information. For remote
6309targets, this functionality may further depend on the remote stub's
6310support of the @samp{qPart:auxv:read} packet, see @ref{Remote
6311configuration, auxiliary vector}.
b383017d
RM
6312
6313@table @code
6314@kindex info auxv
6315@item info auxv
6316Display the auxiliary vector of the inferior, which can be either a
e4937fc1 6317live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
6318numerically, and also shows names and text descriptions for recognized
6319tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 6320pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
6321most appropriate form for a recognized tag, and in hexadecimal for
6322an unrecognized tag.
6323@end table
6324
721c2651 6325
29e57380 6326@node Memory Region Attributes
b383017d 6327@section Memory region attributes
29e57380
C
6328@cindex memory region attributes
6329
b383017d
RM
6330@dfn{Memory region attributes} allow you to describe special handling
6331required by regions of your target's memory. @value{GDBN} uses attributes
29e57380
C
6332to determine whether to allow certain types of memory accesses; whether to
6333use specific width accesses; and whether to cache target memory.
6334
6335Defined memory regions can be individually enabled and disabled. When a
6336memory region is disabled, @value{GDBN} uses the default attributes when
6337accessing memory in that region. Similarly, if no memory regions have
6338been defined, @value{GDBN} uses the default attributes when accessing
6339all memory.
6340
b383017d 6341When a memory region is defined, it is given a number to identify it;
29e57380
C
6342to enable, disable, or remove a memory region, you specify that number.
6343
6344@table @code
6345@kindex mem
bfac230e 6346@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
6347Define a memory region bounded by @var{lower} and @var{upper} with
6348attributes @var{attributes}@dots{}, and add it to the list of regions
6349monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
6350case: it is treated as the the target's maximum memory address.
bfac230e 6351(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
6352
6353@kindex delete mem
6354@item delete mem @var{nums}@dots{}
09d4efe1
EZ
6355Remove memory regions @var{nums}@dots{} from the list of regions
6356monitored by @value{GDBN}.
29e57380
C
6357
6358@kindex disable mem
6359@item disable mem @var{nums}@dots{}
09d4efe1 6360Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 6361A disabled memory region is not forgotten.
29e57380
C
6362It may be enabled again later.
6363
6364@kindex enable mem
6365@item enable mem @var{nums}@dots{}
09d4efe1 6366Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
6367
6368@kindex info mem
6369@item info mem
6370Print a table of all defined memory regions, with the following columns
09d4efe1 6371for each region:
29e57380
C
6372
6373@table @emph
6374@item Memory Region Number
6375@item Enabled or Disabled.
b383017d 6376Enabled memory regions are marked with @samp{y}.
29e57380
C
6377Disabled memory regions are marked with @samp{n}.
6378
6379@item Lo Address
6380The address defining the inclusive lower bound of the memory region.
6381
6382@item Hi Address
6383The address defining the exclusive upper bound of the memory region.
6384
6385@item Attributes
6386The list of attributes set for this memory region.
6387@end table
6388@end table
6389
6390
6391@subsection Attributes
6392
b383017d 6393@subsubsection Memory Access Mode
29e57380
C
6394The access mode attributes set whether @value{GDBN} may make read or
6395write accesses to a memory region.
6396
6397While these attributes prevent @value{GDBN} from performing invalid
6398memory accesses, they do nothing to prevent the target system, I/O DMA,
6399etc. from accessing memory.
6400
6401@table @code
6402@item ro
6403Memory is read only.
6404@item wo
6405Memory is write only.
6406@item rw
6ca652b0 6407Memory is read/write. This is the default.
29e57380
C
6408@end table
6409
6410@subsubsection Memory Access Size
6411The acccess size attributes tells @value{GDBN} to use specific sized
6412accesses in the memory region. Often memory mapped device registers
6413require specific sized accesses. If no access size attribute is
6414specified, @value{GDBN} may use accesses of any size.
6415
6416@table @code
6417@item 8
6418Use 8 bit memory accesses.
6419@item 16
6420Use 16 bit memory accesses.
6421@item 32
6422Use 32 bit memory accesses.
6423@item 64
6424Use 64 bit memory accesses.
6425@end table
6426
6427@c @subsubsection Hardware/Software Breakpoints
6428@c The hardware/software breakpoint attributes set whether @value{GDBN}
6429@c will use hardware or software breakpoints for the internal breakpoints
6430@c used by the step, next, finish, until, etc. commands.
6431@c
6432@c @table @code
6433@c @item hwbreak
b383017d 6434@c Always use hardware breakpoints
29e57380
C
6435@c @item swbreak (default)
6436@c @end table
6437
6438@subsubsection Data Cache
6439The data cache attributes set whether @value{GDBN} will cache target
6440memory. While this generally improves performance by reducing debug
6441protocol overhead, it can lead to incorrect results because @value{GDBN}
6442does not know about volatile variables or memory mapped device
6443registers.
6444
6445@table @code
6446@item cache
b383017d 6447Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6448@item nocache
6449Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6450@end table
6451
6452@c @subsubsection Memory Write Verification
b383017d 6453@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6454@c will re-reads data after each write to verify the write was successful.
6455@c
6456@c @table @code
6457@c @item verify
6458@c @item noverify (default)
6459@c @end table
6460
16d9dec6
MS
6461@node Dump/Restore Files
6462@section Copy between memory and a file
6463@cindex dump/restore files
6464@cindex append data to a file
6465@cindex dump data to a file
6466@cindex restore data from a file
16d9dec6 6467
df5215a6
JB
6468You can use the commands @code{dump}, @code{append}, and
6469@code{restore} to copy data between target memory and a file. The
6470@code{dump} and @code{append} commands write data to a file, and the
6471@code{restore} command reads data from a file back into the inferior's
6472memory. Files may be in binary, Motorola S-record, Intel hex, or
6473Tektronix Hex format; however, @value{GDBN} can only append to binary
6474files.
6475
6476@table @code
6477
6478@kindex dump
6479@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6480@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6481Dump the contents of memory from @var{start_addr} to @var{end_addr},
6482or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6483
df5215a6 6484The @var{format} parameter may be any one of:
16d9dec6 6485@table @code
df5215a6
JB
6486@item binary
6487Raw binary form.
6488@item ihex
6489Intel hex format.
6490@item srec
6491Motorola S-record format.
6492@item tekhex
6493Tektronix Hex format.
6494@end table
6495
6496@value{GDBN} uses the same definitions of these formats as the
6497@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6498@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6499form.
6500
6501@kindex append
6502@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6503@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6504Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 6505or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
6506(@value{GDBN} can only append data to files in raw binary form.)
6507
6508@kindex restore
6509@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6510Restore the contents of file @var{filename} into memory. The
6511@code{restore} command can automatically recognize any known @sc{bfd}
6512file format, except for raw binary. To restore a raw binary file you
6513must specify the optional keyword @code{binary} after the filename.
16d9dec6 6514
b383017d 6515If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6516contained in the file. Binary files always start at address zero, so
6517they will be restored at address @var{bias}. Other bfd files have
6518a built-in location; they will be restored at offset @var{bias}
6519from that location.
6520
6521If @var{start} and/or @var{end} are non-zero, then only data between
6522file offset @var{start} and file offset @var{end} will be restored.
b383017d 6523These offsets are relative to the addresses in the file, before
16d9dec6
MS
6524the @var{bias} argument is applied.
6525
6526@end table
6527
384ee23f
EZ
6528@node Core File Generation
6529@section How to Produce a Core File from Your Program
6530@cindex dump core from inferior
6531
6532A @dfn{core file} or @dfn{core dump} is a file that records the memory
6533image of a running process and its process status (register values
6534etc.). Its primary use is post-mortem debugging of a program that
6535crashed while it ran outside a debugger. A program that crashes
6536automatically produces a core file, unless this feature is disabled by
6537the user. @xref{Files}, for information on invoking @value{GDBN} in
6538the post-mortem debugging mode.
6539
6540Occasionally, you may wish to produce a core file of the program you
6541are debugging in order to preserve a snapshot of its state.
6542@value{GDBN} has a special command for that.
6543
6544@table @code
6545@kindex gcore
6546@kindex generate-core-file
6547@item generate-core-file [@var{file}]
6548@itemx gcore [@var{file}]
6549Produce a core dump of the inferior process. The optional argument
6550@var{file} specifies the file name where to put the core dump. If not
6551specified, the file name defaults to @file{core.@var{pid}}, where
6552@var{pid} is the inferior process ID.
6553
6554Note that this command is implemented only for some systems (as of
6555this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6556@end table
6557
a0eb71c5
KB
6558@node Character Sets
6559@section Character Sets
6560@cindex character sets
6561@cindex charset
6562@cindex translating between character sets
6563@cindex host character set
6564@cindex target character set
6565
6566If the program you are debugging uses a different character set to
6567represent characters and strings than the one @value{GDBN} uses itself,
6568@value{GDBN} can automatically translate between the character sets for
6569you. The character set @value{GDBN} uses we call the @dfn{host
6570character set}; the one the inferior program uses we call the
6571@dfn{target character set}.
6572
6573For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6574uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6575remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6576running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6577then the host character set is Latin-1, and the target character set is
6578@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6579target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6580@sc{ebcdic} and Latin 1 as you print character or string values, or use
6581character and string literals in expressions.
6582
6583@value{GDBN} has no way to automatically recognize which character set
6584the inferior program uses; you must tell it, using the @code{set
6585target-charset} command, described below.
6586
6587Here are the commands for controlling @value{GDBN}'s character set
6588support:
6589
6590@table @code
6591@item set target-charset @var{charset}
6592@kindex set target-charset
6593Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6594character set names @value{GDBN} recognizes below, but if you type
6595@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6596list the target character sets it supports.
a0eb71c5
KB
6597@end table
6598
6599@table @code
6600@item set host-charset @var{charset}
6601@kindex set host-charset
6602Set the current host character set to @var{charset}.
6603
6604By default, @value{GDBN} uses a host character set appropriate to the
6605system it is running on; you can override that default using the
6606@code{set host-charset} command.
6607
6608@value{GDBN} can only use certain character sets as its host character
6609set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6610indicate which can be host character sets, but if you type
6611@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6612list the host character sets it supports.
a0eb71c5
KB
6613
6614@item set charset @var{charset}
6615@kindex set charset
e33d66ec
EZ
6616Set the current host and target character sets to @var{charset}. As
6617above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6618@value{GDBN} will list the name of the character sets that can be used
6619for both host and target.
6620
a0eb71c5
KB
6621
6622@item show charset
a0eb71c5 6623@kindex show charset
b383017d 6624Show the names of the current host and target charsets.
e33d66ec
EZ
6625
6626@itemx show host-charset
a0eb71c5 6627@kindex show host-charset
b383017d 6628Show the name of the current host charset.
e33d66ec
EZ
6629
6630@itemx show target-charset
a0eb71c5 6631@kindex show target-charset
b383017d 6632Show the name of the current target charset.
a0eb71c5
KB
6633
6634@end table
6635
6636@value{GDBN} currently includes support for the following character
6637sets:
6638
6639@table @code
6640
6641@item ASCII
6642@cindex ASCII character set
6643Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6644character set.
6645
6646@item ISO-8859-1
6647@cindex ISO 8859-1 character set
6648@cindex ISO Latin 1 character set
e33d66ec 6649The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6650characters needed for French, German, and Spanish. @value{GDBN} can use
6651this as its host character set.
6652
6653@item EBCDIC-US
6654@itemx IBM1047
6655@cindex EBCDIC character set
6656@cindex IBM1047 character set
6657Variants of the @sc{ebcdic} character set, used on some of IBM's
6658mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6659@value{GDBN} cannot use these as its host character set.
6660
6661@end table
6662
6663Note that these are all single-byte character sets. More work inside
6664GDB is needed to support multi-byte or variable-width character
6665encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6666
6667Here is an example of @value{GDBN}'s character set support in action.
6668Assume that the following source code has been placed in the file
6669@file{charset-test.c}:
6670
6671@smallexample
6672#include <stdio.h>
6673
6674char ascii_hello[]
6675 = @{72, 101, 108, 108, 111, 44, 32, 119,
6676 111, 114, 108, 100, 33, 10, 0@};
6677char ibm1047_hello[]
6678 = @{200, 133, 147, 147, 150, 107, 64, 166,
6679 150, 153, 147, 132, 90, 37, 0@};
6680
6681main ()
6682@{
6683 printf ("Hello, world!\n");
6684@}
10998722 6685@end smallexample
a0eb71c5
KB
6686
6687In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6688containing the string @samp{Hello, world!} followed by a newline,
6689encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6690
6691We compile the program, and invoke the debugger on it:
6692
6693@smallexample
6694$ gcc -g charset-test.c -o charset-test
6695$ gdb -nw charset-test
6696GNU gdb 2001-12-19-cvs
6697Copyright 2001 Free Software Foundation, Inc.
6698@dots{}
f7dc1244 6699(@value{GDBP})
10998722 6700@end smallexample
a0eb71c5
KB
6701
6702We can use the @code{show charset} command to see what character sets
6703@value{GDBN} is currently using to interpret and display characters and
6704strings:
6705
6706@smallexample
f7dc1244 6707(@value{GDBP}) show charset
e33d66ec 6708The current host and target character set is `ISO-8859-1'.
f7dc1244 6709(@value{GDBP})
10998722 6710@end smallexample
a0eb71c5
KB
6711
6712For the sake of printing this manual, let's use @sc{ascii} as our
6713initial character set:
6714@smallexample
f7dc1244
EZ
6715(@value{GDBP}) set charset ASCII
6716(@value{GDBP}) show charset
e33d66ec 6717The current host and target character set is `ASCII'.
f7dc1244 6718(@value{GDBP})
10998722 6719@end smallexample
a0eb71c5
KB
6720
6721Let's assume that @sc{ascii} is indeed the correct character set for our
6722host system --- in other words, let's assume that if @value{GDBN} prints
6723characters using the @sc{ascii} character set, our terminal will display
6724them properly. Since our current target character set is also
6725@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6726
6727@smallexample
f7dc1244 6728(@value{GDBP}) print ascii_hello
a0eb71c5 6729$1 = 0x401698 "Hello, world!\n"
f7dc1244 6730(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6731$2 = 72 'H'
f7dc1244 6732(@value{GDBP})
10998722 6733@end smallexample
a0eb71c5
KB
6734
6735@value{GDBN} uses the target character set for character and string
6736literals you use in expressions:
6737
6738@smallexample
f7dc1244 6739(@value{GDBP}) print '+'
a0eb71c5 6740$3 = 43 '+'
f7dc1244 6741(@value{GDBP})
10998722 6742@end smallexample
a0eb71c5
KB
6743
6744The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6745character.
6746
6747@value{GDBN} relies on the user to tell it which character set the
6748target program uses. If we print @code{ibm1047_hello} while our target
6749character set is still @sc{ascii}, we get jibberish:
6750
6751@smallexample
f7dc1244 6752(@value{GDBP}) print ibm1047_hello
a0eb71c5 6753$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 6754(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6755$5 = 200 '\310'
f7dc1244 6756(@value{GDBP})
10998722 6757@end smallexample
a0eb71c5 6758
e33d66ec 6759If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6760@value{GDBN} tells us the character sets it supports:
6761
6762@smallexample
f7dc1244 6763(@value{GDBP}) set target-charset
b383017d 6764ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 6765(@value{GDBP}) set target-charset
10998722 6766@end smallexample
a0eb71c5
KB
6767
6768We can select @sc{ibm1047} as our target character set, and examine the
6769program's strings again. Now the @sc{ascii} string is wrong, but
6770@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6771target character set, @sc{ibm1047}, to the host character set,
6772@sc{ascii}, and they display correctly:
6773
6774@smallexample
f7dc1244
EZ
6775(@value{GDBP}) set target-charset IBM1047
6776(@value{GDBP}) show charset
e33d66ec
EZ
6777The current host character set is `ASCII'.
6778The current target character set is `IBM1047'.
f7dc1244 6779(@value{GDBP}) print ascii_hello
a0eb71c5 6780$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 6781(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6782$7 = 72 '\110'
f7dc1244 6783(@value{GDBP}) print ibm1047_hello
a0eb71c5 6784$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 6785(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6786$9 = 200 'H'
f7dc1244 6787(@value{GDBP})
10998722 6788@end smallexample
a0eb71c5
KB
6789
6790As above, @value{GDBN} uses the target character set for character and
6791string literals you use in expressions:
6792
6793@smallexample
f7dc1244 6794(@value{GDBP}) print '+'
a0eb71c5 6795$10 = 78 '+'
f7dc1244 6796(@value{GDBP})
10998722 6797@end smallexample
a0eb71c5 6798
e33d66ec 6799The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6800character.
6801
09d4efe1
EZ
6802@node Caching Remote Data
6803@section Caching Data of Remote Targets
6804@cindex caching data of remote targets
6805
6806@value{GDBN} can cache data exchanged between the debugger and a
6807remote target (@pxref{Remote}). Such caching generally improves
6808performance, because it reduces the overhead of the remote protocol by
6809bundling memory reads and writes into large chunks. Unfortunately,
6810@value{GDBN} does not currently know anything about volatile
6811registers, and thus data caching will produce incorrect results when
6812volatile registers are in use.
6813
6814@table @code
6815@kindex set remotecache
6816@item set remotecache on
6817@itemx set remotecache off
6818Set caching state for remote targets. When @code{ON}, use data
6819caching. By default, this option is @code{OFF}.
6820
6821@kindex show remotecache
6822@item show remotecache
6823Show the current state of data caching for remote targets.
6824
6825@kindex info dcache
6826@item info dcache
6827Print the information about the data cache performance. The
6828information displayed includes: the dcache width and depth; and for
6829each cache line, how many times it was referenced, and its data and
6830state (dirty, bad, ok, etc.). This command is useful for debugging
6831the data cache operation.
6832@end table
6833
a0eb71c5 6834
e2e0bcd1
JB
6835@node Macros
6836@chapter C Preprocessor Macros
6837
49efadf5 6838Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
6839``preprocessor macros'' which expand into strings of tokens.
6840@value{GDBN} can evaluate expressions containing macro invocations, show
6841the result of macro expansion, and show a macro's definition, including
6842where it was defined.
6843
6844You may need to compile your program specially to provide @value{GDBN}
6845with information about preprocessor macros. Most compilers do not
6846include macros in their debugging information, even when you compile
6847with the @option{-g} flag. @xref{Compilation}.
6848
6849A program may define a macro at one point, remove that definition later,
6850and then provide a different definition after that. Thus, at different
6851points in the program, a macro may have different definitions, or have
6852no definition at all. If there is a current stack frame, @value{GDBN}
6853uses the macros in scope at that frame's source code line. Otherwise,
6854@value{GDBN} uses the macros in scope at the current listing location;
6855see @ref{List}.
6856
6857At the moment, @value{GDBN} does not support the @code{##}
6858token-splicing operator, the @code{#} stringification operator, or
6859variable-arity macros.
6860
6861Whenever @value{GDBN} evaluates an expression, it always expands any
6862macro invocations present in the expression. @value{GDBN} also provides
6863the following commands for working with macros explicitly.
6864
6865@table @code
6866
6867@kindex macro expand
6868@cindex macro expansion, showing the results of preprocessor
6869@cindex preprocessor macro expansion, showing the results of
6870@cindex expanding preprocessor macros
6871@item macro expand @var{expression}
6872@itemx macro exp @var{expression}
6873Show the results of expanding all preprocessor macro invocations in
6874@var{expression}. Since @value{GDBN} simply expands macros, but does
6875not parse the result, @var{expression} need not be a valid expression;
6876it can be any string of tokens.
6877
09d4efe1 6878@kindex macro exp1
e2e0bcd1
JB
6879@item macro expand-once @var{expression}
6880@itemx macro exp1 @var{expression}
4644b6e3 6881@cindex expand macro once
e2e0bcd1
JB
6882@i{(This command is not yet implemented.)} Show the results of
6883expanding those preprocessor macro invocations that appear explicitly in
6884@var{expression}. Macro invocations appearing in that expansion are
6885left unchanged. This command allows you to see the effect of a
6886particular macro more clearly, without being confused by further
6887expansions. Since @value{GDBN} simply expands macros, but does not
6888parse the result, @var{expression} need not be a valid expression; it
6889can be any string of tokens.
6890
475b0867 6891@kindex info macro
e2e0bcd1
JB
6892@cindex macro definition, showing
6893@cindex definition, showing a macro's
475b0867 6894@item info macro @var{macro}
e2e0bcd1
JB
6895Show the definition of the macro named @var{macro}, and describe the
6896source location where that definition was established.
6897
6898@kindex macro define
6899@cindex user-defined macros
6900@cindex defining macros interactively
6901@cindex macros, user-defined
6902@item macro define @var{macro} @var{replacement-list}
6903@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6904@i{(This command is not yet implemented.)} Introduce a definition for a
6905preprocessor macro named @var{macro}, invocations of which are replaced
6906by the tokens given in @var{replacement-list}. The first form of this
6907command defines an ``object-like'' macro, which takes no arguments; the
6908second form defines a ``function-like'' macro, which takes the arguments
6909given in @var{arglist}.
6910
6911A definition introduced by this command is in scope in every expression
6912evaluated in @value{GDBN}, until it is removed with the @command{macro
6913undef} command, described below. The definition overrides all
6914definitions for @var{macro} present in the program being debugged, as
6915well as any previous user-supplied definition.
6916
6917@kindex macro undef
6918@item macro undef @var{macro}
6919@i{(This command is not yet implemented.)} Remove any user-supplied
6920definition for the macro named @var{macro}. This command only affects
6921definitions provided with the @command{macro define} command, described
6922above; it cannot remove definitions present in the program being
6923debugged.
6924
09d4efe1
EZ
6925@kindex macro list
6926@item macro list
6927@i{(This command is not yet implemented.)} List all the macros
6928defined using the @code{macro define} command.
e2e0bcd1
JB
6929@end table
6930
6931@cindex macros, example of debugging with
6932Here is a transcript showing the above commands in action. First, we
6933show our source files:
6934
6935@smallexample
6936$ cat sample.c
6937#include <stdio.h>
6938#include "sample.h"
6939
6940#define M 42
6941#define ADD(x) (M + x)
6942
6943main ()
6944@{
6945#define N 28
6946 printf ("Hello, world!\n");
6947#undef N
6948 printf ("We're so creative.\n");
6949#define N 1729
6950 printf ("Goodbye, world!\n");
6951@}
6952$ cat sample.h
6953#define Q <
6954$
6955@end smallexample
6956
6957Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6958We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6959compiler includes information about preprocessor macros in the debugging
6960information.
6961
6962@smallexample
6963$ gcc -gdwarf-2 -g3 sample.c -o sample
6964$
6965@end smallexample
6966
6967Now, we start @value{GDBN} on our sample program:
6968
6969@smallexample
6970$ gdb -nw sample
6971GNU gdb 2002-05-06-cvs
6972Copyright 2002 Free Software Foundation, Inc.
6973GDB is free software, @dots{}
f7dc1244 6974(@value{GDBP})
e2e0bcd1
JB
6975@end smallexample
6976
6977We can expand macros and examine their definitions, even when the
6978program is not running. @value{GDBN} uses the current listing position
6979to decide which macro definitions are in scope:
6980
6981@smallexample
f7dc1244 6982(@value{GDBP}) list main
e2e0bcd1
JB
69833
69844 #define M 42
69855 #define ADD(x) (M + x)
69866
69877 main ()
69888 @{
69899 #define N 28
699010 printf ("Hello, world!\n");
699111 #undef N
699212 printf ("We're so creative.\n");
f7dc1244 6993(@value{GDBP}) info macro ADD
e2e0bcd1
JB
6994Defined at /home/jimb/gdb/macros/play/sample.c:5
6995#define ADD(x) (M + x)
f7dc1244 6996(@value{GDBP}) info macro Q
e2e0bcd1
JB
6997Defined at /home/jimb/gdb/macros/play/sample.h:1
6998 included at /home/jimb/gdb/macros/play/sample.c:2
6999#define Q <
f7dc1244 7000(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 7001expands to: (42 + 1)
f7dc1244 7002(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 7003expands to: once (M + 1)
f7dc1244 7004(@value{GDBP})
e2e0bcd1
JB
7005@end smallexample
7006
7007In the example above, note that @command{macro expand-once} expands only
7008the macro invocation explicit in the original text --- the invocation of
7009@code{ADD} --- but does not expand the invocation of the macro @code{M},
7010which was introduced by @code{ADD}.
7011
7012Once the program is running, GDB uses the macro definitions in force at
7013the source line of the current stack frame:
7014
7015@smallexample
f7dc1244 7016(@value{GDBP}) break main
e2e0bcd1 7017Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 7018(@value{GDBP}) run
b383017d 7019Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
7020
7021Breakpoint 1, main () at sample.c:10
702210 printf ("Hello, world!\n");
f7dc1244 7023(@value{GDBP})
e2e0bcd1
JB
7024@end smallexample
7025
7026At line 10, the definition of the macro @code{N} at line 9 is in force:
7027
7028@smallexample
f7dc1244 7029(@value{GDBP}) info macro N
e2e0bcd1
JB
7030Defined at /home/jimb/gdb/macros/play/sample.c:9
7031#define N 28
f7dc1244 7032(@value{GDBP}) macro expand N Q M
e2e0bcd1 7033expands to: 28 < 42
f7dc1244 7034(@value{GDBP}) print N Q M
e2e0bcd1 7035$1 = 1
f7dc1244 7036(@value{GDBP})
e2e0bcd1
JB
7037@end smallexample
7038
7039As we step over directives that remove @code{N}'s definition, and then
7040give it a new definition, @value{GDBN} finds the definition (or lack
7041thereof) in force at each point:
7042
7043@smallexample
f7dc1244 7044(@value{GDBP}) next
e2e0bcd1
JB
7045Hello, world!
704612 printf ("We're so creative.\n");
f7dc1244 7047(@value{GDBP}) info macro N
e2e0bcd1
JB
7048The symbol `N' has no definition as a C/C++ preprocessor macro
7049at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 7050(@value{GDBP}) next
e2e0bcd1
JB
7051We're so creative.
705214 printf ("Goodbye, world!\n");
f7dc1244 7053(@value{GDBP}) info macro N
e2e0bcd1
JB
7054Defined at /home/jimb/gdb/macros/play/sample.c:13
7055#define N 1729
f7dc1244 7056(@value{GDBP}) macro expand N Q M
e2e0bcd1 7057expands to: 1729 < 42
f7dc1244 7058(@value{GDBP}) print N Q M
e2e0bcd1 7059$2 = 0
f7dc1244 7060(@value{GDBP})
e2e0bcd1
JB
7061@end smallexample
7062
7063
b37052ae
EZ
7064@node Tracepoints
7065@chapter Tracepoints
7066@c This chapter is based on the documentation written by Michael
7067@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
7068
7069@cindex tracepoints
7070In some applications, it is not feasible for the debugger to interrupt
7071the program's execution long enough for the developer to learn
7072anything helpful about its behavior. If the program's correctness
7073depends on its real-time behavior, delays introduced by a debugger
7074might cause the program to change its behavior drastically, or perhaps
7075fail, even when the code itself is correct. It is useful to be able
7076to observe the program's behavior without interrupting it.
7077
7078Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
7079specify locations in the program, called @dfn{tracepoints}, and
7080arbitrary expressions to evaluate when those tracepoints are reached.
7081Later, using the @code{tfind} command, you can examine the values
7082those expressions had when the program hit the tracepoints. The
7083expressions may also denote objects in memory---structures or arrays,
7084for example---whose values @value{GDBN} should record; while visiting
7085a particular tracepoint, you may inspect those objects as if they were
7086in memory at that moment. However, because @value{GDBN} records these
7087values without interacting with you, it can do so quickly and
7088unobtrusively, hopefully not disturbing the program's behavior.
7089
7090The tracepoint facility is currently available only for remote
2c0069bb
EZ
7091targets. @xref{Targets}. In addition, your remote target must know how
7092to collect trace data. This functionality is implemented in the remote
7093stub; however, none of the stubs distributed with @value{GDBN} support
7094tracepoints as of this writing.
b37052ae
EZ
7095
7096This chapter describes the tracepoint commands and features.
7097
7098@menu
b383017d
RM
7099* Set Tracepoints::
7100* Analyze Collected Data::
7101* Tracepoint Variables::
b37052ae
EZ
7102@end menu
7103
7104@node Set Tracepoints
7105@section Commands to Set Tracepoints
7106
7107Before running such a @dfn{trace experiment}, an arbitrary number of
7108tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
7109tracepoint has a number assigned to it by @value{GDBN}. Like with
7110breakpoints, tracepoint numbers are successive integers starting from
7111one. Many of the commands associated with tracepoints take the
7112tracepoint number as their argument, to identify which tracepoint to
7113work on.
7114
7115For each tracepoint, you can specify, in advance, some arbitrary set
7116of data that you want the target to collect in the trace buffer when
7117it hits that tracepoint. The collected data can include registers,
7118local variables, or global data. Later, you can use @value{GDBN}
7119commands to examine the values these data had at the time the
7120tracepoint was hit.
7121
7122This section describes commands to set tracepoints and associated
7123conditions and actions.
7124
7125@menu
b383017d
RM
7126* Create and Delete Tracepoints::
7127* Enable and Disable Tracepoints::
7128* Tracepoint Passcounts::
7129* Tracepoint Actions::
7130* Listing Tracepoints::
7131* Starting and Stopping Trace Experiment::
b37052ae
EZ
7132@end menu
7133
7134@node Create and Delete Tracepoints
7135@subsection Create and Delete Tracepoints
7136
7137@table @code
7138@cindex set tracepoint
7139@kindex trace
7140@item trace
7141The @code{trace} command is very similar to the @code{break} command.
7142Its argument can be a source line, a function name, or an address in
7143the target program. @xref{Set Breaks}. The @code{trace} command
7144defines a tracepoint, which is a point in the target program where the
7145debugger will briefly stop, collect some data, and then allow the
7146program to continue. Setting a tracepoint or changing its commands
7147doesn't take effect until the next @code{tstart} command; thus, you
7148cannot change the tracepoint attributes once a trace experiment is
7149running.
7150
7151Here are some examples of using the @code{trace} command:
7152
7153@smallexample
7154(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
7155
7156(@value{GDBP}) @b{trace +2} // 2 lines forward
7157
7158(@value{GDBP}) @b{trace my_function} // first source line of function
7159
7160(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
7161
7162(@value{GDBP}) @b{trace *0x2117c4} // an address
7163@end smallexample
7164
7165@noindent
7166You can abbreviate @code{trace} as @code{tr}.
7167
7168@vindex $tpnum
7169@cindex last tracepoint number
7170@cindex recent tracepoint number
7171@cindex tracepoint number
7172The convenience variable @code{$tpnum} records the tracepoint number
7173of the most recently set tracepoint.
7174
7175@kindex delete tracepoint
7176@cindex tracepoint deletion
7177@item delete tracepoint @r{[}@var{num}@r{]}
7178Permanently delete one or more tracepoints. With no argument, the
7179default is to delete all tracepoints.
7180
7181Examples:
7182
7183@smallexample
7184(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7185
7186(@value{GDBP}) @b{delete trace} // remove all tracepoints
7187@end smallexample
7188
7189@noindent
7190You can abbreviate this command as @code{del tr}.
7191@end table
7192
7193@node Enable and Disable Tracepoints
7194@subsection Enable and Disable Tracepoints
7195
7196@table @code
7197@kindex disable tracepoint
7198@item disable tracepoint @r{[}@var{num}@r{]}
7199Disable tracepoint @var{num}, or all tracepoints if no argument
7200@var{num} is given. A disabled tracepoint will have no effect during
7201the next trace experiment, but it is not forgotten. You can re-enable
7202a disabled tracepoint using the @code{enable tracepoint} command.
7203
7204@kindex enable tracepoint
7205@item enable tracepoint @r{[}@var{num}@r{]}
7206Enable tracepoint @var{num}, or all tracepoints. The enabled
7207tracepoints will become effective the next time a trace experiment is
7208run.
7209@end table
7210
7211@node Tracepoint Passcounts
7212@subsection Tracepoint Passcounts
7213
7214@table @code
7215@kindex passcount
7216@cindex tracepoint pass count
7217@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7218Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7219automatically stop a trace experiment. If a tracepoint's passcount is
7220@var{n}, then the trace experiment will be automatically stopped on
7221the @var{n}'th time that tracepoint is hit. If the tracepoint number
7222@var{num} is not specified, the @code{passcount} command sets the
7223passcount of the most recently defined tracepoint. If no passcount is
7224given, the trace experiment will run until stopped explicitly by the
7225user.
7226
7227Examples:
7228
7229@smallexample
b383017d 7230(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 7231@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
7232
7233(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 7234@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
7235(@value{GDBP}) @b{trace foo}
7236(@value{GDBP}) @b{pass 3}
7237(@value{GDBP}) @b{trace bar}
7238(@value{GDBP}) @b{pass 2}
7239(@value{GDBP}) @b{trace baz}
7240(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
7241@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7242@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7243@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
7244@end smallexample
7245@end table
7246
7247@node Tracepoint Actions
7248@subsection Tracepoint Action Lists
7249
7250@table @code
7251@kindex actions
7252@cindex tracepoint actions
7253@item actions @r{[}@var{num}@r{]}
7254This command will prompt for a list of actions to be taken when the
7255tracepoint is hit. If the tracepoint number @var{num} is not
7256specified, this command sets the actions for the one that was most
7257recently defined (so that you can define a tracepoint and then say
7258@code{actions} without bothering about its number). You specify the
7259actions themselves on the following lines, one action at a time, and
7260terminate the actions list with a line containing just @code{end}. So
7261far, the only defined actions are @code{collect} and
7262@code{while-stepping}.
7263
7264@cindex remove actions from a tracepoint
7265To remove all actions from a tracepoint, type @samp{actions @var{num}}
7266and follow it immediately with @samp{end}.
7267
7268@smallexample
7269(@value{GDBP}) @b{collect @var{data}} // collect some data
7270
6826cf00 7271(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 7272
6826cf00 7273(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
7274@end smallexample
7275
7276In the following example, the action list begins with @code{collect}
7277commands indicating the things to be collected when the tracepoint is
7278hit. Then, in order to single-step and collect additional data
7279following the tracepoint, a @code{while-stepping} command is used,
7280followed by the list of things to be collected while stepping. The
7281@code{while-stepping} command is terminated by its own separate
7282@code{end} command. Lastly, the action list is terminated by an
7283@code{end} command.
7284
7285@smallexample
7286(@value{GDBP}) @b{trace foo}
7287(@value{GDBP}) @b{actions}
7288Enter actions for tracepoint 1, one per line:
7289> collect bar,baz
7290> collect $regs
7291> while-stepping 12
7292 > collect $fp, $sp
7293 > end
7294end
7295@end smallexample
7296
7297@kindex collect @r{(tracepoints)}
7298@item collect @var{expr1}, @var{expr2}, @dots{}
7299Collect values of the given expressions when the tracepoint is hit.
7300This command accepts a comma-separated list of any valid expressions.
7301In addition to global, static, or local variables, the following
7302special arguments are supported:
7303
7304@table @code
7305@item $regs
7306collect all registers
7307
7308@item $args
7309collect all function arguments
7310
7311@item $locals
7312collect all local variables.
7313@end table
7314
7315You can give several consecutive @code{collect} commands, each one
7316with a single argument, or one @code{collect} command with several
7317arguments separated by commas: the effect is the same.
7318
f5c37c66
EZ
7319The command @code{info scope} (@pxref{Symbols, info scope}) is
7320particularly useful for figuring out what data to collect.
7321
b37052ae
EZ
7322@kindex while-stepping @r{(tracepoints)}
7323@item while-stepping @var{n}
7324Perform @var{n} single-step traces after the tracepoint, collecting
7325new data at each step. The @code{while-stepping} command is
7326followed by the list of what to collect while stepping (followed by
7327its own @code{end} command):
7328
7329@smallexample
7330> while-stepping 12
7331 > collect $regs, myglobal
7332 > end
7333>
7334@end smallexample
7335
7336@noindent
7337You may abbreviate @code{while-stepping} as @code{ws} or
7338@code{stepping}.
7339@end table
7340
7341@node Listing Tracepoints
7342@subsection Listing Tracepoints
7343
7344@table @code
7345@kindex info tracepoints
09d4efe1 7346@kindex info tp
b37052ae
EZ
7347@cindex information about tracepoints
7348@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 7349Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 7350a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
7351defined so far. For each tracepoint, the following information is
7352shown:
7353
7354@itemize @bullet
7355@item
7356its number
7357@item
7358whether it is enabled or disabled
7359@item
7360its address
7361@item
7362its passcount as given by the @code{passcount @var{n}} command
7363@item
7364its step count as given by the @code{while-stepping @var{n}} command
7365@item
7366where in the source files is the tracepoint set
7367@item
7368its action list as given by the @code{actions} command
7369@end itemize
7370
7371@smallexample
7372(@value{GDBP}) @b{info trace}
7373Num Enb Address PassC StepC What
73741 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
73752 y 0x0020dc64 0 0 in g_test at g_test.c:1375
73763 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
7377(@value{GDBP})
7378@end smallexample
7379
7380@noindent
7381This command can be abbreviated @code{info tp}.
7382@end table
7383
7384@node Starting and Stopping Trace Experiment
7385@subsection Starting and Stopping Trace Experiment
7386
7387@table @code
7388@kindex tstart
7389@cindex start a new trace experiment
7390@cindex collected data discarded
7391@item tstart
7392This command takes no arguments. It starts the trace experiment, and
7393begins collecting data. This has the side effect of discarding all
7394the data collected in the trace buffer during the previous trace
7395experiment.
7396
7397@kindex tstop
7398@cindex stop a running trace experiment
7399@item tstop
7400This command takes no arguments. It ends the trace experiment, and
7401stops collecting data.
7402
68c71a2e 7403@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
7404automatically if any tracepoint's passcount is reached
7405(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7406
7407@kindex tstatus
7408@cindex status of trace data collection
7409@cindex trace experiment, status of
7410@item tstatus
7411This command displays the status of the current trace data
7412collection.
7413@end table
7414
7415Here is an example of the commands we described so far:
7416
7417@smallexample
7418(@value{GDBP}) @b{trace gdb_c_test}
7419(@value{GDBP}) @b{actions}
7420Enter actions for tracepoint #1, one per line.
7421> collect $regs,$locals,$args
7422> while-stepping 11
7423 > collect $regs
7424 > end
7425> end
7426(@value{GDBP}) @b{tstart}
7427 [time passes @dots{}]
7428(@value{GDBP}) @b{tstop}
7429@end smallexample
7430
7431
7432@node Analyze Collected Data
7433@section Using the collected data
7434
7435After the tracepoint experiment ends, you use @value{GDBN} commands
7436for examining the trace data. The basic idea is that each tracepoint
7437collects a trace @dfn{snapshot} every time it is hit and another
7438snapshot every time it single-steps. All these snapshots are
7439consecutively numbered from zero and go into a buffer, and you can
7440examine them later. The way you examine them is to @dfn{focus} on a
7441specific trace snapshot. When the remote stub is focused on a trace
7442snapshot, it will respond to all @value{GDBN} requests for memory and
7443registers by reading from the buffer which belongs to that snapshot,
7444rather than from @emph{real} memory or registers of the program being
7445debugged. This means that @strong{all} @value{GDBN} commands
7446(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7447behave as if we were currently debugging the program state as it was
7448when the tracepoint occurred. Any requests for data that are not in
7449the buffer will fail.
7450
7451@menu
7452* tfind:: How to select a trace snapshot
7453* tdump:: How to display all data for a snapshot
7454* save-tracepoints:: How to save tracepoints for a future run
7455@end menu
7456
7457@node tfind
7458@subsection @code{tfind @var{n}}
7459
7460@kindex tfind
7461@cindex select trace snapshot
7462@cindex find trace snapshot
7463The basic command for selecting a trace snapshot from the buffer is
7464@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7465counting from zero. If no argument @var{n} is given, the next
7466snapshot is selected.
7467
7468Here are the various forms of using the @code{tfind} command.
7469
7470@table @code
7471@item tfind start
7472Find the first snapshot in the buffer. This is a synonym for
7473@code{tfind 0} (since 0 is the number of the first snapshot).
7474
7475@item tfind none
7476Stop debugging trace snapshots, resume @emph{live} debugging.
7477
7478@item tfind end
7479Same as @samp{tfind none}.
7480
7481@item tfind
7482No argument means find the next trace snapshot.
7483
7484@item tfind -
7485Find the previous trace snapshot before the current one. This permits
7486retracing earlier steps.
7487
7488@item tfind tracepoint @var{num}
7489Find the next snapshot associated with tracepoint @var{num}. Search
7490proceeds forward from the last examined trace snapshot. If no
7491argument @var{num} is given, it means find the next snapshot collected
7492for the same tracepoint as the current snapshot.
7493
7494@item tfind pc @var{addr}
7495Find the next snapshot associated with the value @var{addr} of the
7496program counter. Search proceeds forward from the last examined trace
7497snapshot. If no argument @var{addr} is given, it means find the next
7498snapshot with the same value of PC as the current snapshot.
7499
7500@item tfind outside @var{addr1}, @var{addr2}
7501Find the next snapshot whose PC is outside the given range of
7502addresses.
7503
7504@item tfind range @var{addr1}, @var{addr2}
7505Find the next snapshot whose PC is between @var{addr1} and
7506@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7507
7508@item tfind line @r{[}@var{file}:@r{]}@var{n}
7509Find the next snapshot associated with the source line @var{n}. If
7510the optional argument @var{file} is given, refer to line @var{n} in
7511that source file. Search proceeds forward from the last examined
7512trace snapshot. If no argument @var{n} is given, it means find the
7513next line other than the one currently being examined; thus saying
7514@code{tfind line} repeatedly can appear to have the same effect as
7515stepping from line to line in a @emph{live} debugging session.
7516@end table
7517
7518The default arguments for the @code{tfind} commands are specifically
7519designed to make it easy to scan through the trace buffer. For
7520instance, @code{tfind} with no argument selects the next trace
7521snapshot, and @code{tfind -} with no argument selects the previous
7522trace snapshot. So, by giving one @code{tfind} command, and then
7523simply hitting @key{RET} repeatedly you can examine all the trace
7524snapshots in order. Or, by saying @code{tfind -} and then hitting
7525@key{RET} repeatedly you can examine the snapshots in reverse order.
7526The @code{tfind line} command with no argument selects the snapshot
7527for the next source line executed. The @code{tfind pc} command with
7528no argument selects the next snapshot with the same program counter
7529(PC) as the current frame. The @code{tfind tracepoint} command with
7530no argument selects the next trace snapshot collected by the same
7531tracepoint as the current one.
7532
7533In addition to letting you scan through the trace buffer manually,
7534these commands make it easy to construct @value{GDBN} scripts that
7535scan through the trace buffer and print out whatever collected data
7536you are interested in. Thus, if we want to examine the PC, FP, and SP
7537registers from each trace frame in the buffer, we can say this:
7538
7539@smallexample
7540(@value{GDBP}) @b{tfind start}
7541(@value{GDBP}) @b{while ($trace_frame != -1)}
7542> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7543 $trace_frame, $pc, $sp, $fp
7544> tfind
7545> end
7546
7547Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7548Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7549Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7550Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7551Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7552Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7553Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7554Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7555Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7556Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7557Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7558@end smallexample
7559
7560Or, if we want to examine the variable @code{X} at each source line in
7561the buffer:
7562
7563@smallexample
7564(@value{GDBP}) @b{tfind start}
7565(@value{GDBP}) @b{while ($trace_frame != -1)}
7566> printf "Frame %d, X == %d\n", $trace_frame, X
7567> tfind line
7568> end
7569
7570Frame 0, X = 1
7571Frame 7, X = 2
7572Frame 13, X = 255
7573@end smallexample
7574
7575@node tdump
7576@subsection @code{tdump}
7577@kindex tdump
7578@cindex dump all data collected at tracepoint
7579@cindex tracepoint data, display
7580
7581This command takes no arguments. It prints all the data collected at
7582the current trace snapshot.
7583
7584@smallexample
7585(@value{GDBP}) @b{trace 444}
7586(@value{GDBP}) @b{actions}
7587Enter actions for tracepoint #2, one per line:
7588> collect $regs, $locals, $args, gdb_long_test
7589> end
7590
7591(@value{GDBP}) @b{tstart}
7592
7593(@value{GDBP}) @b{tfind line 444}
7594#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7595at gdb_test.c:444
7596444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7597
7598(@value{GDBP}) @b{tdump}
7599Data collected at tracepoint 2, trace frame 1:
7600d0 0xc4aa0085 -995491707
7601d1 0x18 24
7602d2 0x80 128
7603d3 0x33 51
7604d4 0x71aea3d 119204413
7605d5 0x22 34
7606d6 0xe0 224
7607d7 0x380035 3670069
7608a0 0x19e24a 1696330
7609a1 0x3000668 50333288
7610a2 0x100 256
7611a3 0x322000 3284992
7612a4 0x3000698 50333336
7613a5 0x1ad3cc 1758156
7614fp 0x30bf3c 0x30bf3c
7615sp 0x30bf34 0x30bf34
7616ps 0x0 0
7617pc 0x20b2c8 0x20b2c8
7618fpcontrol 0x0 0
7619fpstatus 0x0 0
7620fpiaddr 0x0 0
7621p = 0x20e5b4 "gdb-test"
7622p1 = (void *) 0x11
7623p2 = (void *) 0x22
7624p3 = (void *) 0x33
7625p4 = (void *) 0x44
7626p5 = (void *) 0x55
7627p6 = (void *) 0x66
7628gdb_long_test = 17 '\021'
7629
7630(@value{GDBP})
7631@end smallexample
7632
7633@node save-tracepoints
7634@subsection @code{save-tracepoints @var{filename}}
7635@kindex save-tracepoints
7636@cindex save tracepoints for future sessions
7637
7638This command saves all current tracepoint definitions together with
7639their actions and passcounts, into a file @file{@var{filename}}
7640suitable for use in a later debugging session. To read the saved
7641tracepoint definitions, use the @code{source} command (@pxref{Command
7642Files}).
7643
7644@node Tracepoint Variables
7645@section Convenience Variables for Tracepoints
7646@cindex tracepoint variables
7647@cindex convenience variables for tracepoints
7648
7649@table @code
7650@vindex $trace_frame
7651@item (int) $trace_frame
7652The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7653snapshot is selected.
7654
7655@vindex $tracepoint
7656@item (int) $tracepoint
7657The tracepoint for the current trace snapshot.
7658
7659@vindex $trace_line
7660@item (int) $trace_line
7661The line number for the current trace snapshot.
7662
7663@vindex $trace_file
7664@item (char []) $trace_file
7665The source file for the current trace snapshot.
7666
7667@vindex $trace_func
7668@item (char []) $trace_func
7669The name of the function containing @code{$tracepoint}.
7670@end table
7671
7672Note: @code{$trace_file} is not suitable for use in @code{printf},
7673use @code{output} instead.
7674
7675Here's a simple example of using these convenience variables for
7676stepping through all the trace snapshots and printing some of their
7677data.
7678
7679@smallexample
7680(@value{GDBP}) @b{tfind start}
7681
7682(@value{GDBP}) @b{while $trace_frame != -1}
7683> output $trace_file
7684> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7685> tfind
7686> end
7687@end smallexample
7688
df0cd8c5
JB
7689@node Overlays
7690@chapter Debugging Programs That Use Overlays
7691@cindex overlays
7692
7693If your program is too large to fit completely in your target system's
7694memory, you can sometimes use @dfn{overlays} to work around this
7695problem. @value{GDBN} provides some support for debugging programs that
7696use overlays.
7697
7698@menu
7699* How Overlays Work:: A general explanation of overlays.
7700* Overlay Commands:: Managing overlays in @value{GDBN}.
7701* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7702 mapped by asking the inferior.
7703* Overlay Sample Program:: A sample program using overlays.
7704@end menu
7705
7706@node How Overlays Work
7707@section How Overlays Work
7708@cindex mapped overlays
7709@cindex unmapped overlays
7710@cindex load address, overlay's
7711@cindex mapped address
7712@cindex overlay area
7713
7714Suppose you have a computer whose instruction address space is only 64
7715kilobytes long, but which has much more memory which can be accessed by
7716other means: special instructions, segment registers, or memory
7717management hardware, for example. Suppose further that you want to
7718adapt a program which is larger than 64 kilobytes to run on this system.
7719
7720One solution is to identify modules of your program which are relatively
7721independent, and need not call each other directly; call these modules
7722@dfn{overlays}. Separate the overlays from the main program, and place
7723their machine code in the larger memory. Place your main program in
7724instruction memory, but leave at least enough space there to hold the
7725largest overlay as well.
7726
7727Now, to call a function located in an overlay, you must first copy that
7728overlay's machine code from the large memory into the space set aside
7729for it in the instruction memory, and then jump to its entry point
7730there.
7731
c928edc0
AC
7732@c NB: In the below the mapped area's size is greater or equal to the
7733@c size of all overlays. This is intentional to remind the developer
7734@c that overlays don't necessarily need to be the same size.
7735
474c8240 7736@smallexample
df0cd8c5 7737@group
c928edc0
AC
7738 Data Instruction Larger
7739Address Space Address Space Address Space
7740+-----------+ +-----------+ +-----------+
7741| | | | | |
7742+-----------+ +-----------+ +-----------+<-- overlay 1
7743| program | | main | .----| overlay 1 | load address
7744| variables | | program | | +-----------+
7745| and heap | | | | | |
7746+-----------+ | | | +-----------+<-- overlay 2
7747| | +-----------+ | | | load address
7748+-----------+ | | | .-| overlay 2 |
7749 | | | | | |
7750 mapped --->+-----------+ | | +-----------+
7751 address | | | | | |
7752 | overlay | <-' | | |
7753 | area | <---' +-----------+<-- overlay 3
7754 | | <---. | | load address
7755 +-----------+ `--| overlay 3 |
7756 | | | |
7757 +-----------+ | |
7758 +-----------+
7759 | |
7760 +-----------+
7761
7762 @anchor{A code overlay}A code overlay
df0cd8c5 7763@end group
474c8240 7764@end smallexample
df0cd8c5 7765
c928edc0
AC
7766The diagram (@pxref{A code overlay}) shows a system with separate data
7767and instruction address spaces. To map an overlay, the program copies
7768its code from the larger address space to the instruction address space.
7769Since the overlays shown here all use the same mapped address, only one
7770may be mapped at a time. For a system with a single address space for
7771data and instructions, the diagram would be similar, except that the
7772program variables and heap would share an address space with the main
7773program and the overlay area.
df0cd8c5
JB
7774
7775An overlay loaded into instruction memory and ready for use is called a
7776@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7777instruction memory. An overlay not present (or only partially present)
7778in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7779is its address in the larger memory. The mapped address is also called
7780the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7781called the @dfn{load memory address}, or @dfn{LMA}.
7782
7783Unfortunately, overlays are not a completely transparent way to adapt a
7784program to limited instruction memory. They introduce a new set of
7785global constraints you must keep in mind as you design your program:
7786
7787@itemize @bullet
7788
7789@item
7790Before calling or returning to a function in an overlay, your program
7791must make sure that overlay is actually mapped. Otherwise, the call or
7792return will transfer control to the right address, but in the wrong
7793overlay, and your program will probably crash.
7794
7795@item
7796If the process of mapping an overlay is expensive on your system, you
7797will need to choose your overlays carefully to minimize their effect on
7798your program's performance.
7799
7800@item
7801The executable file you load onto your system must contain each
7802overlay's instructions, appearing at the overlay's load address, not its
7803mapped address. However, each overlay's instructions must be relocated
7804and its symbols defined as if the overlay were at its mapped address.
7805You can use GNU linker scripts to specify different load and relocation
7806addresses for pieces of your program; see @ref{Overlay Description,,,
7807ld.info, Using ld: the GNU linker}.
7808
7809@item
7810The procedure for loading executable files onto your system must be able
7811to load their contents into the larger address space as well as the
7812instruction and data spaces.
7813
7814@end itemize
7815
7816The overlay system described above is rather simple, and could be
7817improved in many ways:
7818
7819@itemize @bullet
7820
7821@item
7822If your system has suitable bank switch registers or memory management
7823hardware, you could use those facilities to make an overlay's load area
7824contents simply appear at their mapped address in instruction space.
7825This would probably be faster than copying the overlay to its mapped
7826area in the usual way.
7827
7828@item
7829If your overlays are small enough, you could set aside more than one
7830overlay area, and have more than one overlay mapped at a time.
7831
7832@item
7833You can use overlays to manage data, as well as instructions. In
7834general, data overlays are even less transparent to your design than
7835code overlays: whereas code overlays only require care when you call or
7836return to functions, data overlays require care every time you access
7837the data. Also, if you change the contents of a data overlay, you
7838must copy its contents back out to its load address before you can copy a
7839different data overlay into the same mapped area.
7840
7841@end itemize
7842
7843
7844@node Overlay Commands
7845@section Overlay Commands
7846
7847To use @value{GDBN}'s overlay support, each overlay in your program must
7848correspond to a separate section of the executable file. The section's
7849virtual memory address and load memory address must be the overlay's
7850mapped and load addresses. Identifying overlays with sections allows
7851@value{GDBN} to determine the appropriate address of a function or
7852variable, depending on whether the overlay is mapped or not.
7853
7854@value{GDBN}'s overlay commands all start with the word @code{overlay};
7855you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7856
7857@table @code
7858@item overlay off
4644b6e3 7859@kindex overlay
df0cd8c5
JB
7860Disable @value{GDBN}'s overlay support. When overlay support is
7861disabled, @value{GDBN} assumes that all functions and variables are
7862always present at their mapped addresses. By default, @value{GDBN}'s
7863overlay support is disabled.
7864
7865@item overlay manual
df0cd8c5
JB
7866@cindex manual overlay debugging
7867Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7868relies on you to tell it which overlays are mapped, and which are not,
7869using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7870commands described below.
7871
7872@item overlay map-overlay @var{overlay}
7873@itemx overlay map @var{overlay}
df0cd8c5
JB
7874@cindex map an overlay
7875Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7876be the name of the object file section containing the overlay. When an
7877overlay is mapped, @value{GDBN} assumes it can find the overlay's
7878functions and variables at their mapped addresses. @value{GDBN} assumes
7879that any other overlays whose mapped ranges overlap that of
7880@var{overlay} are now unmapped.
7881
7882@item overlay unmap-overlay @var{overlay}
7883@itemx overlay unmap @var{overlay}
df0cd8c5
JB
7884@cindex unmap an overlay
7885Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7886must be the name of the object file section containing the overlay.
7887When an overlay is unmapped, @value{GDBN} assumes it can find the
7888overlay's functions and variables at their load addresses.
7889
7890@item overlay auto
df0cd8c5
JB
7891Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7892consults a data structure the overlay manager maintains in the inferior
7893to see which overlays are mapped. For details, see @ref{Automatic
7894Overlay Debugging}.
7895
7896@item overlay load-target
7897@itemx overlay load
df0cd8c5
JB
7898@cindex reloading the overlay table
7899Re-read the overlay table from the inferior. Normally, @value{GDBN}
7900re-reads the table @value{GDBN} automatically each time the inferior
7901stops, so this command should only be necessary if you have changed the
7902overlay mapping yourself using @value{GDBN}. This command is only
7903useful when using automatic overlay debugging.
7904
7905@item overlay list-overlays
7906@itemx overlay list
7907@cindex listing mapped overlays
7908Display a list of the overlays currently mapped, along with their mapped
7909addresses, load addresses, and sizes.
7910
7911@end table
7912
7913Normally, when @value{GDBN} prints a code address, it includes the name
7914of the function the address falls in:
7915
474c8240 7916@smallexample
f7dc1244 7917(@value{GDBP}) print main
df0cd8c5 7918$3 = @{int ()@} 0x11a0 <main>
474c8240 7919@end smallexample
df0cd8c5
JB
7920@noindent
7921When overlay debugging is enabled, @value{GDBN} recognizes code in
7922unmapped overlays, and prints the names of unmapped functions with
7923asterisks around them. For example, if @code{foo} is a function in an
7924unmapped overlay, @value{GDBN} prints it this way:
7925
474c8240 7926@smallexample
f7dc1244 7927(@value{GDBP}) overlay list
df0cd8c5 7928No sections are mapped.
f7dc1244 7929(@value{GDBP}) print foo
df0cd8c5 7930$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7931@end smallexample
df0cd8c5
JB
7932@noindent
7933When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7934name normally:
7935
474c8240 7936@smallexample
f7dc1244 7937(@value{GDBP}) overlay list
b383017d 7938Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 7939 mapped at 0x1016 - 0x104a
f7dc1244 7940(@value{GDBP}) print foo
df0cd8c5 7941$6 = @{int (int)@} 0x1016 <foo>
474c8240 7942@end smallexample
df0cd8c5
JB
7943
7944When overlay debugging is enabled, @value{GDBN} can find the correct
7945address for functions and variables in an overlay, whether or not the
7946overlay is mapped. This allows most @value{GDBN} commands, like
7947@code{break} and @code{disassemble}, to work normally, even on unmapped
7948code. However, @value{GDBN}'s breakpoint support has some limitations:
7949
7950@itemize @bullet
7951@item
7952@cindex breakpoints in overlays
7953@cindex overlays, setting breakpoints in
7954You can set breakpoints in functions in unmapped overlays, as long as
7955@value{GDBN} can write to the overlay at its load address.
7956@item
7957@value{GDBN} can not set hardware or simulator-based breakpoints in
7958unmapped overlays. However, if you set a breakpoint at the end of your
7959overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7960you are using manual overlay management), @value{GDBN} will re-set its
7961breakpoints properly.
7962@end itemize
7963
7964
7965@node Automatic Overlay Debugging
7966@section Automatic Overlay Debugging
7967@cindex automatic overlay debugging
7968
7969@value{GDBN} can automatically track which overlays are mapped and which
7970are not, given some simple co-operation from the overlay manager in the
7971inferior. If you enable automatic overlay debugging with the
7972@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7973looks in the inferior's memory for certain variables describing the
7974current state of the overlays.
7975
7976Here are the variables your overlay manager must define to support
7977@value{GDBN}'s automatic overlay debugging:
7978
7979@table @asis
7980
7981@item @code{_ovly_table}:
7982This variable must be an array of the following structures:
7983
474c8240 7984@smallexample
df0cd8c5
JB
7985struct
7986@{
7987 /* The overlay's mapped address. */
7988 unsigned long vma;
7989
7990 /* The size of the overlay, in bytes. */
7991 unsigned long size;
7992
7993 /* The overlay's load address. */
7994 unsigned long lma;
7995
7996 /* Non-zero if the overlay is currently mapped;
7997 zero otherwise. */
7998 unsigned long mapped;
7999@}
474c8240 8000@end smallexample
df0cd8c5
JB
8001
8002@item @code{_novlys}:
8003This variable must be a four-byte signed integer, holding the total
8004number of elements in @code{_ovly_table}.
8005
8006@end table
8007
8008To decide whether a particular overlay is mapped or not, @value{GDBN}
8009looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
8010@code{lma} members equal the VMA and LMA of the overlay's section in the
8011executable file. When @value{GDBN} finds a matching entry, it consults
8012the entry's @code{mapped} member to determine whether the overlay is
8013currently mapped.
8014
81d46470 8015In addition, your overlay manager may define a function called
def71bfa 8016@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
8017will silently set a breakpoint there. If the overlay manager then
8018calls this function whenever it has changed the overlay table, this
8019will enable @value{GDBN} to accurately keep track of which overlays
8020are in program memory, and update any breakpoints that may be set
b383017d 8021in overlays. This will allow breakpoints to work even if the
81d46470
MS
8022overlays are kept in ROM or other non-writable memory while they
8023are not being executed.
df0cd8c5
JB
8024
8025@node Overlay Sample Program
8026@section Overlay Sample Program
8027@cindex overlay example program
8028
8029When linking a program which uses overlays, you must place the overlays
8030at their load addresses, while relocating them to run at their mapped
8031addresses. To do this, you must write a linker script (@pxref{Overlay
8032Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
8033since linker scripts are specific to a particular host system, target
8034architecture, and target memory layout, this manual cannot provide
8035portable sample code demonstrating @value{GDBN}'s overlay support.
8036
8037However, the @value{GDBN} source distribution does contain an overlaid
8038program, with linker scripts for a few systems, as part of its test
8039suite. The program consists of the following files from
8040@file{gdb/testsuite/gdb.base}:
8041
8042@table @file
8043@item overlays.c
8044The main program file.
8045@item ovlymgr.c
8046A simple overlay manager, used by @file{overlays.c}.
8047@item foo.c
8048@itemx bar.c
8049@itemx baz.c
8050@itemx grbx.c
8051Overlay modules, loaded and used by @file{overlays.c}.
8052@item d10v.ld
8053@itemx m32r.ld
8054Linker scripts for linking the test program on the @code{d10v-elf}
8055and @code{m32r-elf} targets.
8056@end table
8057
8058You can build the test program using the @code{d10v-elf} GCC
8059cross-compiler like this:
8060
474c8240 8061@smallexample
df0cd8c5
JB
8062$ d10v-elf-gcc -g -c overlays.c
8063$ d10v-elf-gcc -g -c ovlymgr.c
8064$ d10v-elf-gcc -g -c foo.c
8065$ d10v-elf-gcc -g -c bar.c
8066$ d10v-elf-gcc -g -c baz.c
8067$ d10v-elf-gcc -g -c grbx.c
8068$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
8069 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 8070@end smallexample
df0cd8c5
JB
8071
8072The build process is identical for any other architecture, except that
8073you must substitute the appropriate compiler and linker script for the
8074target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
8075
8076
6d2ebf8b 8077@node Languages
c906108c
SS
8078@chapter Using @value{GDBN} with Different Languages
8079@cindex languages
8080
c906108c
SS
8081Although programming languages generally have common aspects, they are
8082rarely expressed in the same manner. For instance, in ANSI C,
8083dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
8084Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 8085represented (and displayed) differently. Hex numbers in C appear as
c906108c 8086@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
8087
8088@cindex working language
8089Language-specific information is built into @value{GDBN} for some languages,
8090allowing you to express operations like the above in your program's
8091native language, and allowing @value{GDBN} to output values in a manner
8092consistent with the syntax of your program's native language. The
8093language you use to build expressions is called the @dfn{working
8094language}.
8095
8096@menu
8097* Setting:: Switching between source languages
8098* Show:: Displaying the language
c906108c 8099* Checks:: Type and range checks
9c16f35a 8100* Supported languages:: Supported languages
4e562065 8101* Unsupported languages:: Unsupported languages
c906108c
SS
8102@end menu
8103
6d2ebf8b 8104@node Setting
c906108c
SS
8105@section Switching between source languages
8106
8107There are two ways to control the working language---either have @value{GDBN}
8108set it automatically, or select it manually yourself. You can use the
8109@code{set language} command for either purpose. On startup, @value{GDBN}
8110defaults to setting the language automatically. The working language is
8111used to determine how expressions you type are interpreted, how values
8112are printed, etc.
8113
8114In addition to the working language, every source file that
8115@value{GDBN} knows about has its own working language. For some object
8116file formats, the compiler might indicate which language a particular
8117source file is in. However, most of the time @value{GDBN} infers the
8118language from the name of the file. The language of a source file
b37052ae 8119controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 8120show each frame appropriately for its own language. There is no way to
d4f3574e
SS
8121set the language of a source file from within @value{GDBN}, but you can
8122set the language associated with a filename extension. @xref{Show, ,
8123Displaying the language}.
c906108c
SS
8124
8125This is most commonly a problem when you use a program, such
5d161b24 8126as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
8127another language. In that case, make the
8128program use @code{#line} directives in its C output; that way
8129@value{GDBN} will know the correct language of the source code of the original
8130program, and will display that source code, not the generated C code.
8131
8132@menu
8133* Filenames:: Filename extensions and languages.
8134* Manually:: Setting the working language manually
8135* Automatically:: Having @value{GDBN} infer the source language
8136@end menu
8137
6d2ebf8b 8138@node Filenames
c906108c
SS
8139@subsection List of filename extensions and languages
8140
8141If a source file name ends in one of the following extensions, then
8142@value{GDBN} infers that its language is the one indicated.
8143
8144@table @file
e07c999f
PH
8145@item .ada
8146@itemx .ads
8147@itemx .adb
8148@itemx .a
8149Ada source file.
c906108c
SS
8150
8151@item .c
8152C source file
8153
8154@item .C
8155@itemx .cc
8156@itemx .cp
8157@itemx .cpp
8158@itemx .cxx
8159@itemx .c++
b37052ae 8160C@t{++} source file
c906108c 8161
b37303ee
AF
8162@item .m
8163Objective-C source file
8164
c906108c
SS
8165@item .f
8166@itemx .F
8167Fortran source file
8168
c906108c
SS
8169@item .mod
8170Modula-2 source file
c906108c
SS
8171
8172@item .s
8173@itemx .S
8174Assembler source file. This actually behaves almost like C, but
8175@value{GDBN} does not skip over function prologues when stepping.
8176@end table
8177
8178In addition, you may set the language associated with a filename
8179extension. @xref{Show, , Displaying the language}.
8180
6d2ebf8b 8181@node Manually
c906108c
SS
8182@subsection Setting the working language
8183
8184If you allow @value{GDBN} to set the language automatically,
8185expressions are interpreted the same way in your debugging session and
8186your program.
8187
8188@kindex set language
8189If you wish, you may set the language manually. To do this, issue the
8190command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 8191a language, such as
c906108c 8192@code{c} or @code{modula-2}.
c906108c
SS
8193For a list of the supported languages, type @samp{set language}.
8194
c906108c
SS
8195Setting the language manually prevents @value{GDBN} from updating the working
8196language automatically. This can lead to confusion if you try
8197to debug a program when the working language is not the same as the
8198source language, when an expression is acceptable to both
8199languages---but means different things. For instance, if the current
8200source file were written in C, and @value{GDBN} was parsing Modula-2, a
8201command such as:
8202
474c8240 8203@smallexample
c906108c 8204print a = b + c
474c8240 8205@end smallexample
c906108c
SS
8206
8207@noindent
8208might not have the effect you intended. In C, this means to add
8209@code{b} and @code{c} and place the result in @code{a}. The result
8210printed would be the value of @code{a}. In Modula-2, this means to compare
8211@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 8212
6d2ebf8b 8213@node Automatically
c906108c
SS
8214@subsection Having @value{GDBN} infer the source language
8215
8216To have @value{GDBN} set the working language automatically, use
8217@samp{set language local} or @samp{set language auto}. @value{GDBN}
8218then infers the working language. That is, when your program stops in a
8219frame (usually by encountering a breakpoint), @value{GDBN} sets the
8220working language to the language recorded for the function in that
8221frame. If the language for a frame is unknown (that is, if the function
8222or block corresponding to the frame was defined in a source file that
8223does not have a recognized extension), the current working language is
8224not changed, and @value{GDBN} issues a warning.
8225
8226This may not seem necessary for most programs, which are written
8227entirely in one source language. However, program modules and libraries
8228written in one source language can be used by a main program written in
8229a different source language. Using @samp{set language auto} in this
8230case frees you from having to set the working language manually.
8231
6d2ebf8b 8232@node Show
c906108c 8233@section Displaying the language
c906108c
SS
8234
8235The following commands help you find out which language is the
8236working language, and also what language source files were written in.
8237
c906108c
SS
8238@table @code
8239@item show language
9c16f35a 8240@kindex show language
c906108c
SS
8241Display the current working language. This is the
8242language you can use with commands such as @code{print} to
8243build and compute expressions that may involve variables in your program.
8244
8245@item info frame
4644b6e3 8246@kindex info frame@r{, show the source language}
5d161b24 8247Display the source language for this frame. This language becomes the
c906108c 8248working language if you use an identifier from this frame.
5d161b24 8249@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
8250information listed here.
8251
8252@item info source
4644b6e3 8253@kindex info source@r{, show the source language}
c906108c 8254Display the source language of this source file.
5d161b24 8255@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
8256information listed here.
8257@end table
8258
8259In unusual circumstances, you may have source files with extensions
8260not in the standard list. You can then set the extension associated
8261with a language explicitly:
8262
c906108c 8263@table @code
09d4efe1 8264@item set extension-language @var{ext} @var{language}
9c16f35a 8265@kindex set extension-language
09d4efe1
EZ
8266Tell @value{GDBN} that source files with extension @var{ext} are to be
8267assumed as written in the source language @var{language}.
c906108c
SS
8268
8269@item info extensions
9c16f35a 8270@kindex info extensions
c906108c
SS
8271List all the filename extensions and the associated languages.
8272@end table
8273
6d2ebf8b 8274@node Checks
c906108c
SS
8275@section Type and range checking
8276
8277@quotation
8278@emph{Warning:} In this release, the @value{GDBN} commands for type and range
8279checking are included, but they do not yet have any effect. This
8280section documents the intended facilities.
8281@end quotation
8282@c FIXME remove warning when type/range code added
8283
8284Some languages are designed to guard you against making seemingly common
8285errors through a series of compile- and run-time checks. These include
8286checking the type of arguments to functions and operators, and making
8287sure mathematical overflows are caught at run time. Checks such as
8288these help to ensure a program's correctness once it has been compiled
8289by eliminating type mismatches, and providing active checks for range
8290errors when your program is running.
8291
8292@value{GDBN} can check for conditions like the above if you wish.
9c16f35a
EZ
8293Although @value{GDBN} does not check the statements in your program,
8294it can check expressions entered directly into @value{GDBN} for
8295evaluation via the @code{print} command, for example. As with the
8296working language, @value{GDBN} can also decide whether or not to check
8297automatically based on your program's source language.
8298@xref{Supported languages, ,Supported languages}, for the default
8299settings of supported languages.
c906108c
SS
8300
8301@menu
8302* Type Checking:: An overview of type checking
8303* Range Checking:: An overview of range checking
8304@end menu
8305
8306@cindex type checking
8307@cindex checks, type
6d2ebf8b 8308@node Type Checking
c906108c
SS
8309@subsection An overview of type checking
8310
8311Some languages, such as Modula-2, are strongly typed, meaning that the
8312arguments to operators and functions have to be of the correct type,
8313otherwise an error occurs. These checks prevent type mismatch
8314errors from ever causing any run-time problems. For example,
8315
8316@smallexample
83171 + 2 @result{} 3
8318@exdent but
8319@error{} 1 + 2.3
8320@end smallexample
8321
8322The second example fails because the @code{CARDINAL} 1 is not
8323type-compatible with the @code{REAL} 2.3.
8324
5d161b24
DB
8325For the expressions you use in @value{GDBN} commands, you can tell the
8326@value{GDBN} type checker to skip checking;
8327to treat any mismatches as errors and abandon the expression;
8328or to only issue warnings when type mismatches occur,
c906108c
SS
8329but evaluate the expression anyway. When you choose the last of
8330these, @value{GDBN} evaluates expressions like the second example above, but
8331also issues a warning.
8332
5d161b24
DB
8333Even if you turn type checking off, there may be other reasons
8334related to type that prevent @value{GDBN} from evaluating an expression.
8335For instance, @value{GDBN} does not know how to add an @code{int} and
8336a @code{struct foo}. These particular type errors have nothing to do
8337with the language in use, and usually arise from expressions, such as
c906108c
SS
8338the one described above, which make little sense to evaluate anyway.
8339
8340Each language defines to what degree it is strict about type. For
8341instance, both Modula-2 and C require the arguments to arithmetical
8342operators to be numbers. In C, enumerated types and pointers can be
8343represented as numbers, so that they are valid arguments to mathematical
9c16f35a 8344operators. @xref{Supported languages, ,Supported languages}, for further
c906108c
SS
8345details on specific languages.
8346
8347@value{GDBN} provides some additional commands for controlling the type checker:
8348
c906108c
SS
8349@kindex set check type
8350@kindex show check type
8351@table @code
8352@item set check type auto
8353Set type checking on or off based on the current working language.
9c16f35a 8354@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8355each language.
8356
8357@item set check type on
8358@itemx set check type off
8359Set type checking on or off, overriding the default setting for the
8360current working language. Issue a warning if the setting does not
8361match the language default. If any type mismatches occur in
d4f3574e 8362evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
8363message and aborts evaluation of the expression.
8364
8365@item set check type warn
8366Cause the type checker to issue warnings, but to always attempt to
8367evaluate the expression. Evaluating the expression may still
8368be impossible for other reasons. For example, @value{GDBN} cannot add
8369numbers and structures.
8370
8371@item show type
5d161b24 8372Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
8373is setting it automatically.
8374@end table
8375
8376@cindex range checking
8377@cindex checks, range
6d2ebf8b 8378@node Range Checking
c906108c
SS
8379@subsection An overview of range checking
8380
8381In some languages (such as Modula-2), it is an error to exceed the
8382bounds of a type; this is enforced with run-time checks. Such range
8383checking is meant to ensure program correctness by making sure
8384computations do not overflow, or indices on an array element access do
8385not exceed the bounds of the array.
8386
8387For expressions you use in @value{GDBN} commands, you can tell
8388@value{GDBN} to treat range errors in one of three ways: ignore them,
8389always treat them as errors and abandon the expression, or issue
8390warnings but evaluate the expression anyway.
8391
8392A range error can result from numerical overflow, from exceeding an
8393array index bound, or when you type a constant that is not a member
8394of any type. Some languages, however, do not treat overflows as an
8395error. In many implementations of C, mathematical overflow causes the
8396result to ``wrap around'' to lower values---for example, if @var{m} is
8397the largest integer value, and @var{s} is the smallest, then
8398
474c8240 8399@smallexample
c906108c 8400@var{m} + 1 @result{} @var{s}
474c8240 8401@end smallexample
c906108c
SS
8402
8403This, too, is specific to individual languages, and in some cases
9c16f35a 8404specific to individual compilers or machines. @xref{Supported languages, ,
c906108c
SS
8405Supported languages}, for further details on specific languages.
8406
8407@value{GDBN} provides some additional commands for controlling the range checker:
8408
c906108c
SS
8409@kindex set check range
8410@kindex show check range
8411@table @code
8412@item set check range auto
8413Set range checking on or off based on the current working language.
9c16f35a 8414@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8415each language.
8416
8417@item set check range on
8418@itemx set check range off
8419Set range checking on or off, overriding the default setting for the
8420current working language. A warning is issued if the setting does not
c3f6f71d
JM
8421match the language default. If a range error occurs and range checking is on,
8422then a message is printed and evaluation of the expression is aborted.
c906108c
SS
8423
8424@item set check range warn
8425Output messages when the @value{GDBN} range checker detects a range error,
8426but attempt to evaluate the expression anyway. Evaluating the
8427expression may still be impossible for other reasons, such as accessing
8428memory that the process does not own (a typical example from many Unix
8429systems).
8430
8431@item show range
8432Show the current setting of the range checker, and whether or not it is
8433being set automatically by @value{GDBN}.
8434@end table
c906108c 8435
9c16f35a 8436@node Supported languages
c906108c 8437@section Supported languages
c906108c 8438
9c16f35a
EZ
8439@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
8440assembly, Modula-2, and Ada.
cce74817 8441@c This is false ...
c906108c
SS
8442Some @value{GDBN} features may be used in expressions regardless of the
8443language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8444and the @samp{@{type@}addr} construct (@pxref{Expressions,
8445,Expressions}) can be used with the constructs of any supported
8446language.
8447
8448The following sections detail to what degree each source language is
8449supported by @value{GDBN}. These sections are not meant to be language
8450tutorials or references, but serve only as a reference guide to what the
8451@value{GDBN} expression parser accepts, and what input and output
8452formats should look like for different languages. There are many good
8453books written on each of these languages; please look to these for a
8454language reference or tutorial.
8455
c906108c 8456@menu
b37303ee 8457* C:: C and C@t{++}
b383017d 8458* Objective-C:: Objective-C
09d4efe1 8459* Fortran:: Fortran
9c16f35a 8460* Pascal:: Pascal
b37303ee 8461* Modula-2:: Modula-2
e07c999f 8462* Ada:: Ada
c906108c
SS
8463@end menu
8464
6d2ebf8b 8465@node C
b37052ae 8466@subsection C and C@t{++}
7a292a7a 8467
b37052ae
EZ
8468@cindex C and C@t{++}
8469@cindex expressions in C or C@t{++}
c906108c 8470
b37052ae 8471Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8472to both languages. Whenever this is the case, we discuss those languages
8473together.
8474
41afff9a
EZ
8475@cindex C@t{++}
8476@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8477@cindex @sc{gnu} C@t{++}
8478The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8479compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8480effectively, you must compile your C@t{++} programs with a supported
8481C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8482compiler (@code{aCC}).
8483
0179ffac
DC
8484For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8485format; if it doesn't work on your system, try the stabs+ debugging
8486format. You can select those formats explicitly with the @code{g++}
8487command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8488@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8489CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8490
c906108c 8491@menu
b37052ae
EZ
8492* C Operators:: C and C@t{++} operators
8493* C Constants:: C and C@t{++} constants
8494* C plus plus expressions:: C@t{++} expressions
8495* C Defaults:: Default settings for C and C@t{++}
8496* C Checks:: C and C@t{++} type and range checks
c906108c 8497* Debugging C:: @value{GDBN} and C
b37052ae 8498* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8499@end menu
c906108c 8500
6d2ebf8b 8501@node C Operators
b37052ae 8502@subsubsection C and C@t{++} operators
7a292a7a 8503
b37052ae 8504@cindex C and C@t{++} operators
c906108c
SS
8505
8506Operators must be defined on values of specific types. For instance,
8507@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8508often defined on groups of types.
c906108c 8509
b37052ae 8510For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8511
8512@itemize @bullet
53a5351d 8513
c906108c 8514@item
c906108c 8515@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8516specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8517
8518@item
d4f3574e
SS
8519@emph{Floating-point types} include @code{float}, @code{double}, and
8520@code{long double} (if supported by the target platform).
c906108c
SS
8521
8522@item
53a5351d 8523@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8524
8525@item
8526@emph{Scalar types} include all of the above.
53a5351d 8527
c906108c
SS
8528@end itemize
8529
8530@noindent
8531The following operators are supported. They are listed here
8532in order of increasing precedence:
8533
8534@table @code
8535@item ,
8536The comma or sequencing operator. Expressions in a comma-separated list
8537are evaluated from left to right, with the result of the entire
8538expression being the last expression evaluated.
8539
8540@item =
8541Assignment. The value of an assignment expression is the value
8542assigned. Defined on scalar types.
8543
8544@item @var{op}=
8545Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8546and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8547@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8548@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8549@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8550
8551@item ?:
8552The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8553of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8554integral type.
8555
8556@item ||
8557Logical @sc{or}. Defined on integral types.
8558
8559@item &&
8560Logical @sc{and}. Defined on integral types.
8561
8562@item |
8563Bitwise @sc{or}. Defined on integral types.
8564
8565@item ^
8566Bitwise exclusive-@sc{or}. Defined on integral types.
8567
8568@item &
8569Bitwise @sc{and}. Defined on integral types.
8570
8571@item ==@r{, }!=
8572Equality and inequality. Defined on scalar types. The value of these
8573expressions is 0 for false and non-zero for true.
8574
8575@item <@r{, }>@r{, }<=@r{, }>=
8576Less than, greater than, less than or equal, greater than or equal.
8577Defined on scalar types. The value of these expressions is 0 for false
8578and non-zero for true.
8579
8580@item <<@r{, }>>
8581left shift, and right shift. Defined on integral types.
8582
8583@item @@
8584The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8585
8586@item +@r{, }-
8587Addition and subtraction. Defined on integral types, floating-point types and
8588pointer types.
8589
8590@item *@r{, }/@r{, }%
8591Multiplication, division, and modulus. Multiplication and division are
8592defined on integral and floating-point types. Modulus is defined on
8593integral types.
8594
8595@item ++@r{, }--
8596Increment and decrement. When appearing before a variable, the
8597operation is performed before the variable is used in an expression;
8598when appearing after it, the variable's value is used before the
8599operation takes place.
8600
8601@item *
8602Pointer dereferencing. Defined on pointer types. Same precedence as
8603@code{++}.
8604
8605@item &
8606Address operator. Defined on variables. Same precedence as @code{++}.
8607
b37052ae
EZ
8608For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8609allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8610(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8611where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8612stored.
c906108c
SS
8613
8614@item -
8615Negative. Defined on integral and floating-point types. Same
8616precedence as @code{++}.
8617
8618@item !
8619Logical negation. Defined on integral types. Same precedence as
8620@code{++}.
8621
8622@item ~
8623Bitwise complement operator. Defined on integral types. Same precedence as
8624@code{++}.
8625
8626
8627@item .@r{, }->
8628Structure member, and pointer-to-structure member. For convenience,
8629@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8630pointer based on the stored type information.
8631Defined on @code{struct} and @code{union} data.
8632
c906108c
SS
8633@item .*@r{, }->*
8634Dereferences of pointers to members.
c906108c
SS
8635
8636@item []
8637Array indexing. @code{@var{a}[@var{i}]} is defined as
8638@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8639
8640@item ()
8641Function parameter list. Same precedence as @code{->}.
8642
c906108c 8643@item ::
b37052ae 8644C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8645and @code{class} types.
c906108c
SS
8646
8647@item ::
7a292a7a
SS
8648Doubled colons also represent the @value{GDBN} scope operator
8649(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8650above.
c906108c
SS
8651@end table
8652
c906108c
SS
8653If an operator is redefined in the user code, @value{GDBN} usually
8654attempts to invoke the redefined version instead of using the operator's
8655predefined meaning.
c906108c 8656
c906108c 8657@menu
5d161b24 8658* C Constants::
c906108c
SS
8659@end menu
8660
6d2ebf8b 8661@node C Constants
b37052ae 8662@subsubsection C and C@t{++} constants
c906108c 8663
b37052ae 8664@cindex C and C@t{++} constants
c906108c 8665
b37052ae 8666@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8667following ways:
c906108c
SS
8668
8669@itemize @bullet
8670@item
8671Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8672specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8673by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8674@samp{l}, specifying that the constant should be treated as a
8675@code{long} value.
8676
8677@item
8678Floating point constants are a sequence of digits, followed by a decimal
8679point, followed by a sequence of digits, and optionally followed by an
8680exponent. An exponent is of the form:
8681@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8682sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8683A floating-point constant may also end with a letter @samp{f} or
8684@samp{F}, specifying that the constant should be treated as being of
8685the @code{float} (as opposed to the default @code{double}) type; or with
8686a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8687constant.
c906108c
SS
8688
8689@item
8690Enumerated constants consist of enumerated identifiers, or their
8691integral equivalents.
8692
8693@item
8694Character constants are a single character surrounded by single quotes
8695(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8696(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8697be represented by a letter or by @dfn{escape sequences}, which are of
8698the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8699of the character's ordinal value; or of the form @samp{\@var{x}}, where
8700@samp{@var{x}} is a predefined special character---for example,
8701@samp{\n} for newline.
8702
8703@item
96a2c332
SS
8704String constants are a sequence of character constants surrounded by
8705double quotes (@code{"}). Any valid character constant (as described
8706above) may appear. Double quotes within the string must be preceded by
8707a backslash, so for instance @samp{"a\"b'c"} is a string of five
8708characters.
c906108c
SS
8709
8710@item
8711Pointer constants are an integral value. You can also write pointers
8712to constants using the C operator @samp{&}.
8713
8714@item
8715Array constants are comma-separated lists surrounded by braces @samp{@{}
8716and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8717integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8718and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8719@end itemize
8720
c906108c 8721@menu
5d161b24
DB
8722* C plus plus expressions::
8723* C Defaults::
8724* C Checks::
c906108c 8725
5d161b24 8726* Debugging C::
c906108c
SS
8727@end menu
8728
6d2ebf8b 8729@node C plus plus expressions
b37052ae
EZ
8730@subsubsection C@t{++} expressions
8731
8732@cindex expressions in C@t{++}
8733@value{GDBN} expression handling can interpret most C@t{++} expressions.
8734
0179ffac
DC
8735@cindex debugging C@t{++} programs
8736@cindex C@t{++} compilers
8737@cindex debug formats and C@t{++}
8738@cindex @value{NGCC} and C@t{++}
c906108c 8739@quotation
b37052ae 8740@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8741proper compiler and the proper debug format. Currently, @value{GDBN}
8742works best when debugging C@t{++} code that is compiled with
8743@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8744@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8745stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8746stabs+ as their default debug format, so you usually don't need to
8747specify a debug format explicitly. Other compilers and/or debug formats
8748are likely to work badly or not at all when using @value{GDBN} to debug
8749C@t{++} code.
c906108c 8750@end quotation
c906108c
SS
8751
8752@enumerate
8753
8754@cindex member functions
8755@item
8756Member function calls are allowed; you can use expressions like
8757
474c8240 8758@smallexample
c906108c 8759count = aml->GetOriginal(x, y)
474c8240 8760@end smallexample
c906108c 8761
41afff9a 8762@vindex this@r{, inside C@t{++} member functions}
b37052ae 8763@cindex namespace in C@t{++}
c906108c
SS
8764@item
8765While a member function is active (in the selected stack frame), your
8766expressions have the same namespace available as the member function;
8767that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8768pointer @code{this} following the same rules as C@t{++}.
c906108c 8769
c906108c 8770@cindex call overloaded functions
d4f3574e 8771@cindex overloaded functions, calling
b37052ae 8772@cindex type conversions in C@t{++}
c906108c
SS
8773@item
8774You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8775call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8776perform overload resolution involving user-defined type conversions,
8777calls to constructors, or instantiations of templates that do not exist
8778in the program. It also cannot handle ellipsis argument lists or
8779default arguments.
8780
8781It does perform integral conversions and promotions, floating-point
8782promotions, arithmetic conversions, pointer conversions, conversions of
8783class objects to base classes, and standard conversions such as those of
8784functions or arrays to pointers; it requires an exact match on the
8785number of function arguments.
8786
8787Overload resolution is always performed, unless you have specified
8788@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8789,@value{GDBN} features for C@t{++}}.
c906108c 8790
d4f3574e 8791You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8792explicit function signature to call an overloaded function, as in
8793@smallexample
8794p 'foo(char,int)'('x', 13)
8795@end smallexample
d4f3574e 8796
c906108c 8797The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8798see @ref{Completion, ,Command completion}.
c906108c 8799
c906108c
SS
8800@cindex reference declarations
8801@item
b37052ae
EZ
8802@value{GDBN} understands variables declared as C@t{++} references; you can use
8803them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8804dereferenced.
8805
8806In the parameter list shown when @value{GDBN} displays a frame, the values of
8807reference variables are not displayed (unlike other variables); this
8808avoids clutter, since references are often used for large structures.
8809The @emph{address} of a reference variable is always shown, unless
8810you have specified @samp{set print address off}.
8811
8812@item
b37052ae 8813@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8814expressions can use it just as expressions in your program do. Since
8815one scope may be defined in another, you can use @code{::} repeatedly if
8816necessary, for example in an expression like
8817@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8818resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8819debugging (@pxref{Variables, ,Program variables}).
8820@end enumerate
8821
b37052ae 8822In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8823calling virtual functions correctly, printing out virtual bases of
8824objects, calling functions in a base subobject, casting objects, and
8825invoking user-defined operators.
c906108c 8826
6d2ebf8b 8827@node C Defaults
b37052ae 8828@subsubsection C and C@t{++} defaults
7a292a7a 8829
b37052ae 8830@cindex C and C@t{++} defaults
c906108c 8831
c906108c
SS
8832If you allow @value{GDBN} to set type and range checking automatically, they
8833both default to @code{off} whenever the working language changes to
b37052ae 8834C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8835selects the working language.
c906108c
SS
8836
8837If you allow @value{GDBN} to set the language automatically, it
8838recognizes source files whose names end with @file{.c}, @file{.C}, or
8839@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8840these files, it sets the working language to C or C@t{++}.
c906108c
SS
8841@xref{Automatically, ,Having @value{GDBN} infer the source language},
8842for further details.
8843
c906108c
SS
8844@c Type checking is (a) primarily motivated by Modula-2, and (b)
8845@c unimplemented. If (b) changes, it might make sense to let this node
8846@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8847
6d2ebf8b 8848@node C Checks
b37052ae 8849@subsubsection C and C@t{++} type and range checks
7a292a7a 8850
b37052ae 8851@cindex C and C@t{++} checks
c906108c 8852
b37052ae 8853By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8854is not used. However, if you turn type checking on, @value{GDBN}
8855considers two variables type equivalent if:
8856
8857@itemize @bullet
8858@item
8859The two variables are structured and have the same structure, union, or
8860enumerated tag.
8861
8862@item
8863The two variables have the same type name, or types that have been
8864declared equivalent through @code{typedef}.
8865
8866@ignore
8867@c leaving this out because neither J Gilmore nor R Pesch understand it.
8868@c FIXME--beers?
8869@item
8870The two @code{struct}, @code{union}, or @code{enum} variables are
8871declared in the same declaration. (Note: this may not be true for all C
8872compilers.)
8873@end ignore
8874@end itemize
8875
8876Range checking, if turned on, is done on mathematical operations. Array
8877indices are not checked, since they are often used to index a pointer
8878that is not itself an array.
c906108c 8879
6d2ebf8b 8880@node Debugging C
c906108c 8881@subsubsection @value{GDBN} and C
c906108c
SS
8882
8883The @code{set print union} and @code{show print union} commands apply to
8884the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8885inside a @code{struct} or @code{class} is also printed. Otherwise, it
8886appears as @samp{@{...@}}.
c906108c
SS
8887
8888The @code{@@} operator aids in the debugging of dynamic arrays, formed
8889with pointers and a memory allocation function. @xref{Expressions,
8890,Expressions}.
8891
c906108c 8892@menu
5d161b24 8893* Debugging C plus plus::
c906108c
SS
8894@end menu
8895
6d2ebf8b 8896@node Debugging C plus plus
b37052ae 8897@subsubsection @value{GDBN} features for C@t{++}
c906108c 8898
b37052ae 8899@cindex commands for C@t{++}
7a292a7a 8900
b37052ae
EZ
8901Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8902designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8903
8904@table @code
8905@cindex break in overloaded functions
8906@item @r{breakpoint menus}
8907When you want a breakpoint in a function whose name is overloaded,
8908@value{GDBN} breakpoint menus help you specify which function definition
8909you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8910
b37052ae 8911@cindex overloading in C@t{++}
c906108c
SS
8912@item rbreak @var{regex}
8913Setting breakpoints using regular expressions is helpful for setting
8914breakpoints on overloaded functions that are not members of any special
8915classes.
8916@xref{Set Breaks, ,Setting breakpoints}.
8917
b37052ae 8918@cindex C@t{++} exception handling
c906108c
SS
8919@item catch throw
8920@itemx catch catch
b37052ae 8921Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8922Catchpoints, , Setting catchpoints}.
8923
8924@cindex inheritance
8925@item ptype @var{typename}
8926Print inheritance relationships as well as other information for type
8927@var{typename}.
8928@xref{Symbols, ,Examining the Symbol Table}.
8929
b37052ae 8930@cindex C@t{++} symbol display
c906108c
SS
8931@item set print demangle
8932@itemx show print demangle
8933@itemx set print asm-demangle
8934@itemx show print asm-demangle
b37052ae
EZ
8935Control whether C@t{++} symbols display in their source form, both when
8936displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8937@xref{Print Settings, ,Print settings}.
8938
8939@item set print object
8940@itemx show print object
8941Choose whether to print derived (actual) or declared types of objects.
8942@xref{Print Settings, ,Print settings}.
8943
8944@item set print vtbl
8945@itemx show print vtbl
8946Control the format for printing virtual function tables.
8947@xref{Print Settings, ,Print settings}.
c906108c 8948(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8949ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8950
8951@kindex set overload-resolution
d4f3574e 8952@cindex overloaded functions, overload resolution
c906108c 8953@item set overload-resolution on
b37052ae 8954Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8955is on. For overloaded functions, @value{GDBN} evaluates the arguments
8956and searches for a function whose signature matches the argument types,
b37052ae 8957using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8958expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8959message.
8960
8961@item set overload-resolution off
b37052ae 8962Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8963overloaded functions that are not class member functions, @value{GDBN}
8964chooses the first function of the specified name that it finds in the
8965symbol table, whether or not its arguments are of the correct type. For
8966overloaded functions that are class member functions, @value{GDBN}
8967searches for a function whose signature @emph{exactly} matches the
8968argument types.
c906108c 8969
9c16f35a
EZ
8970@kindex show overload-resolution
8971@item show overload-resolution
8972Show the current setting of overload resolution.
8973
c906108c
SS
8974@item @r{Overloaded symbol names}
8975You can specify a particular definition of an overloaded symbol, using
b37052ae 8976the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
8977@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8978also use the @value{GDBN} command-line word completion facilities to list the
8979available choices, or to finish the type list for you.
8980@xref{Completion,, Command completion}, for details on how to do this.
8981@end table
c906108c 8982
b37303ee
AF
8983@node Objective-C
8984@subsection Objective-C
8985
8986@cindex Objective-C
8987This section provides information about some commands and command
721c2651
EZ
8988options that are useful for debugging Objective-C code. See also
8989@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
8990few more commands specific to Objective-C support.
b37303ee
AF
8991
8992@menu
b383017d
RM
8993* Method Names in Commands::
8994* The Print Command with Objective-C::
b37303ee
AF
8995@end menu
8996
8997@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
8998@subsubsection Method Names in Commands
8999
9000The following commands have been extended to accept Objective-C method
9001names as line specifications:
9002
9003@kindex clear@r{, and Objective-C}
9004@kindex break@r{, and Objective-C}
9005@kindex info line@r{, and Objective-C}
9006@kindex jump@r{, and Objective-C}
9007@kindex list@r{, and Objective-C}
9008@itemize
9009@item @code{clear}
9010@item @code{break}
9011@item @code{info line}
9012@item @code{jump}
9013@item @code{list}
9014@end itemize
9015
9016A fully qualified Objective-C method name is specified as
9017
9018@smallexample
9019-[@var{Class} @var{methodName}]
9020@end smallexample
9021
c552b3bb
JM
9022where the minus sign is used to indicate an instance method and a
9023plus sign (not shown) is used to indicate a class method. The class
9024name @var{Class} and method name @var{methodName} are enclosed in
9025brackets, similar to the way messages are specified in Objective-C
9026source code. For example, to set a breakpoint at the @code{create}
9027instance method of class @code{Fruit} in the program currently being
9028debugged, enter:
b37303ee
AF
9029
9030@smallexample
9031break -[Fruit create]
9032@end smallexample
9033
9034To list ten program lines around the @code{initialize} class method,
9035enter:
9036
9037@smallexample
9038list +[NSText initialize]
9039@end smallexample
9040
c552b3bb
JM
9041In the current version of @value{GDBN}, the plus or minus sign is
9042required. In future versions of @value{GDBN}, the plus or minus
9043sign will be optional, but you can use it to narrow the search. It
9044is also possible to specify just a method name:
b37303ee
AF
9045
9046@smallexample
9047break create
9048@end smallexample
9049
9050You must specify the complete method name, including any colons. If
9051your program's source files contain more than one @code{create} method,
9052you'll be presented with a numbered list of classes that implement that
9053method. Indicate your choice by number, or type @samp{0} to exit if
9054none apply.
9055
9056As another example, to clear a breakpoint established at the
9057@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
9058
9059@smallexample
9060clear -[NSWindow makeKeyAndOrderFront:]
9061@end smallexample
9062
9063@node The Print Command with Objective-C
9064@subsubsection The Print Command With Objective-C
721c2651 9065@cindex Objective-C, print objects
c552b3bb
JM
9066@kindex print-object
9067@kindex po @r{(@code{print-object})}
b37303ee 9068
c552b3bb 9069The print command has also been extended to accept methods. For example:
b37303ee
AF
9070
9071@smallexample
c552b3bb 9072print -[@var{object} hash]
b37303ee
AF
9073@end smallexample
9074
9075@cindex print an Objective-C object description
c552b3bb
JM
9076@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
9077@noindent
9078will tell @value{GDBN} to send the @code{hash} message to @var{object}
9079and print the result. Also, an additional command has been added,
9080@code{print-object} or @code{po} for short, which is meant to print
9081the description of an object. However, this command may only work
9082with certain Objective-C libraries that have a particular hook
9083function, @code{_NSPrintForDebugger}, defined.
b37303ee 9084
09d4efe1
EZ
9085@node Fortran
9086@subsection Fortran
9087@cindex Fortran-specific support in @value{GDBN}
9088
9089@table @code
9090@cindex @code{COMMON} blocks, Fortran
9091@kindex info common
9092@item info common @r{[}@var{common-name}@r{]}
9093This command prints the values contained in the Fortran @code{COMMON}
9094block whose name is @var{common-name}. With no argument, the names of
9095all @code{COMMON} blocks visible at current program location are
9096printed.
9097@end table
9098
a8f24a35
EZ
9099Fortran symbols are usually case-insensitive, so @value{GDBN} by
9100default uses case-insensitive matches for Fortran symbols. You can
9101change that with the @samp{set case-insensitive} command, see
9102@ref{Symbols}, for the details.
9103
9c16f35a
EZ
9104@node Pascal
9105@subsection Pascal
9106
9107@cindex Pascal support in @value{GDBN}, limitations
9108Debugging Pascal programs which use sets, subranges, file variables, or
9109nested functions does not currently work. @value{GDBN} does not support
9110entering expressions, printing values, or similar features using Pascal
9111syntax.
9112
9113The Pascal-specific command @code{set print pascal_static-members}
9114controls whether static members of Pascal objects are displayed.
9115@xref{Print Settings, pascal_static-members}.
9116
09d4efe1 9117@node Modula-2
c906108c 9118@subsection Modula-2
7a292a7a 9119
d4f3574e 9120@cindex Modula-2, @value{GDBN} support
c906108c
SS
9121
9122The extensions made to @value{GDBN} to support Modula-2 only support
9123output from the @sc{gnu} Modula-2 compiler (which is currently being
9124developed). Other Modula-2 compilers are not currently supported, and
9125attempting to debug executables produced by them is most likely
9126to give an error as @value{GDBN} reads in the executable's symbol
9127table.
9128
9129@cindex expressions in Modula-2
9130@menu
9131* M2 Operators:: Built-in operators
9132* Built-In Func/Proc:: Built-in functions and procedures
9133* M2 Constants:: Modula-2 constants
9134* M2 Defaults:: Default settings for Modula-2
9135* Deviations:: Deviations from standard Modula-2
9136* M2 Checks:: Modula-2 type and range checks
9137* M2 Scope:: The scope operators @code{::} and @code{.}
9138* GDB/M2:: @value{GDBN} and Modula-2
9139@end menu
9140
6d2ebf8b 9141@node M2 Operators
c906108c
SS
9142@subsubsection Operators
9143@cindex Modula-2 operators
9144
9145Operators must be defined on values of specific types. For instance,
9146@code{+} is defined on numbers, but not on structures. Operators are
9147often defined on groups of types. For the purposes of Modula-2, the
9148following definitions hold:
9149
9150@itemize @bullet
9151
9152@item
9153@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
9154their subranges.
9155
9156@item
9157@emph{Character types} consist of @code{CHAR} and its subranges.
9158
9159@item
9160@emph{Floating-point types} consist of @code{REAL}.
9161
9162@item
9163@emph{Pointer types} consist of anything declared as @code{POINTER TO
9164@var{type}}.
9165
9166@item
9167@emph{Scalar types} consist of all of the above.
9168
9169@item
9170@emph{Set types} consist of @code{SET} and @code{BITSET} types.
9171
9172@item
9173@emph{Boolean types} consist of @code{BOOLEAN}.
9174@end itemize
9175
9176@noindent
9177The following operators are supported, and appear in order of
9178increasing precedence:
9179
9180@table @code
9181@item ,
9182Function argument or array index separator.
9183
9184@item :=
9185Assignment. The value of @var{var} @code{:=} @var{value} is
9186@var{value}.
9187
9188@item <@r{, }>
9189Less than, greater than on integral, floating-point, or enumerated
9190types.
9191
9192@item <=@r{, }>=
96a2c332 9193Less than or equal to, greater than or equal to
c906108c
SS
9194on integral, floating-point and enumerated types, or set inclusion on
9195set types. Same precedence as @code{<}.
9196
9197@item =@r{, }<>@r{, }#
9198Equality and two ways of expressing inequality, valid on scalar types.
9199Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9200available for inequality, since @code{#} conflicts with the script
9201comment character.
9202
9203@item IN
9204Set membership. Defined on set types and the types of their members.
9205Same precedence as @code{<}.
9206
9207@item OR
9208Boolean disjunction. Defined on boolean types.
9209
9210@item AND@r{, }&
d4f3574e 9211Boolean conjunction. Defined on boolean types.
c906108c
SS
9212
9213@item @@
9214The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9215
9216@item +@r{, }-
9217Addition and subtraction on integral and floating-point types, or union
9218and difference on set types.
9219
9220@item *
9221Multiplication on integral and floating-point types, or set intersection
9222on set types.
9223
9224@item /
9225Division on floating-point types, or symmetric set difference on set
9226types. Same precedence as @code{*}.
9227
9228@item DIV@r{, }MOD
9229Integer division and remainder. Defined on integral types. Same
9230precedence as @code{*}.
9231
9232@item -
9233Negative. Defined on @code{INTEGER} and @code{REAL} data.
9234
9235@item ^
9236Pointer dereferencing. Defined on pointer types.
9237
9238@item NOT
9239Boolean negation. Defined on boolean types. Same precedence as
9240@code{^}.
9241
9242@item .
9243@code{RECORD} field selector. Defined on @code{RECORD} data. Same
9244precedence as @code{^}.
9245
9246@item []
9247Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
9248
9249@item ()
9250Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
9251as @code{^}.
9252
9253@item ::@r{, }.
9254@value{GDBN} and Modula-2 scope operators.
9255@end table
9256
9257@quotation
9258@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
9259treats the use of the operator @code{IN}, or the use of operators
9260@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
9261@code{<=}, and @code{>=} on sets as an error.
9262@end quotation
9263
cb51c4e0 9264
6d2ebf8b 9265@node Built-In Func/Proc
c906108c 9266@subsubsection Built-in functions and procedures
cb51c4e0 9267@cindex Modula-2 built-ins
c906108c
SS
9268
9269Modula-2 also makes available several built-in procedures and functions.
9270In describing these, the following metavariables are used:
9271
9272@table @var
9273
9274@item a
9275represents an @code{ARRAY} variable.
9276
9277@item c
9278represents a @code{CHAR} constant or variable.
9279
9280@item i
9281represents a variable or constant of integral type.
9282
9283@item m
9284represents an identifier that belongs to a set. Generally used in the
9285same function with the metavariable @var{s}. The type of @var{s} should
9286be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
9287
9288@item n
9289represents a variable or constant of integral or floating-point type.
9290
9291@item r
9292represents a variable or constant of floating-point type.
9293
9294@item t
9295represents a type.
9296
9297@item v
9298represents a variable.
9299
9300@item x
9301represents a variable or constant of one of many types. See the
9302explanation of the function for details.
9303@end table
9304
9305All Modula-2 built-in procedures also return a result, described below.
9306
9307@table @code
9308@item ABS(@var{n})
9309Returns the absolute value of @var{n}.
9310
9311@item CAP(@var{c})
9312If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 9313equivalent, otherwise it returns its argument.
c906108c
SS
9314
9315@item CHR(@var{i})
9316Returns the character whose ordinal value is @var{i}.
9317
9318@item DEC(@var{v})
c3f6f71d 9319Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9320
9321@item DEC(@var{v},@var{i})
9322Decrements the value in the variable @var{v} by @var{i}. Returns the
9323new value.
9324
9325@item EXCL(@var{m},@var{s})
9326Removes the element @var{m} from the set @var{s}. Returns the new
9327set.
9328
9329@item FLOAT(@var{i})
9330Returns the floating point equivalent of the integer @var{i}.
9331
9332@item HIGH(@var{a})
9333Returns the index of the last member of @var{a}.
9334
9335@item INC(@var{v})
c3f6f71d 9336Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9337
9338@item INC(@var{v},@var{i})
9339Increments the value in the variable @var{v} by @var{i}. Returns the
9340new value.
9341
9342@item INCL(@var{m},@var{s})
9343Adds the element @var{m} to the set @var{s} if it is not already
9344there. Returns the new set.
9345
9346@item MAX(@var{t})
9347Returns the maximum value of the type @var{t}.
9348
9349@item MIN(@var{t})
9350Returns the minimum value of the type @var{t}.
9351
9352@item ODD(@var{i})
9353Returns boolean TRUE if @var{i} is an odd number.
9354
9355@item ORD(@var{x})
9356Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
9357value of a character is its @sc{ascii} value (on machines supporting the
9358@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
9359integral, character and enumerated types.
9360
9361@item SIZE(@var{x})
9362Returns the size of its argument. @var{x} can be a variable or a type.
9363
9364@item TRUNC(@var{r})
9365Returns the integral part of @var{r}.
9366
9367@item VAL(@var{t},@var{i})
9368Returns the member of the type @var{t} whose ordinal value is @var{i}.
9369@end table
9370
9371@quotation
9372@emph{Warning:} Sets and their operations are not yet supported, so
9373@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
9374an error.
9375@end quotation
9376
9377@cindex Modula-2 constants
6d2ebf8b 9378@node M2 Constants
c906108c
SS
9379@subsubsection Constants
9380
9381@value{GDBN} allows you to express the constants of Modula-2 in the following
9382ways:
9383
9384@itemize @bullet
9385
9386@item
9387Integer constants are simply a sequence of digits. When used in an
9388expression, a constant is interpreted to be type-compatible with the
9389rest of the expression. Hexadecimal integers are specified by a
9390trailing @samp{H}, and octal integers by a trailing @samp{B}.
9391
9392@item
9393Floating point constants appear as a sequence of digits, followed by a
9394decimal point and another sequence of digits. An optional exponent can
9395then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
9396@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
9397digits of the floating point constant must be valid decimal (base 10)
9398digits.
9399
9400@item
9401Character constants consist of a single character enclosed by a pair of
9402like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 9403also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
9404followed by a @samp{C}.
9405
9406@item
9407String constants consist of a sequence of characters enclosed by a
9408pair of like quotes, either single (@code{'}) or double (@code{"}).
9409Escape sequences in the style of C are also allowed. @xref{C
b37052ae 9410Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
9411sequences.
9412
9413@item
9414Enumerated constants consist of an enumerated identifier.
9415
9416@item
9417Boolean constants consist of the identifiers @code{TRUE} and
9418@code{FALSE}.
9419
9420@item
9421Pointer constants consist of integral values only.
9422
9423@item
9424Set constants are not yet supported.
9425@end itemize
9426
6d2ebf8b 9427@node M2 Defaults
c906108c
SS
9428@subsubsection Modula-2 defaults
9429@cindex Modula-2 defaults
9430
9431If type and range checking are set automatically by @value{GDBN}, they
9432both default to @code{on} whenever the working language changes to
d4f3574e 9433Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
9434selected the working language.
9435
9436If you allow @value{GDBN} to set the language automatically, then entering
9437code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 9438working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
9439the language automatically}, for further details.
9440
6d2ebf8b 9441@node Deviations
c906108c
SS
9442@subsubsection Deviations from standard Modula-2
9443@cindex Modula-2, deviations from
9444
9445A few changes have been made to make Modula-2 programs easier to debug.
9446This is done primarily via loosening its type strictness:
9447
9448@itemize @bullet
9449@item
9450Unlike in standard Modula-2, pointer constants can be formed by
9451integers. This allows you to modify pointer variables during
9452debugging. (In standard Modula-2, the actual address contained in a
9453pointer variable is hidden from you; it can only be modified
9454through direct assignment to another pointer variable or expression that
9455returned a pointer.)
9456
9457@item
9458C escape sequences can be used in strings and characters to represent
9459non-printable characters. @value{GDBN} prints out strings with these
9460escape sequences embedded. Single non-printable characters are
9461printed using the @samp{CHR(@var{nnn})} format.
9462
9463@item
9464The assignment operator (@code{:=}) returns the value of its right-hand
9465argument.
9466
9467@item
9468All built-in procedures both modify @emph{and} return their argument.
9469@end itemize
9470
6d2ebf8b 9471@node M2 Checks
c906108c
SS
9472@subsubsection Modula-2 type and range checks
9473@cindex Modula-2 checks
9474
9475@quotation
9476@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9477range checking.
9478@end quotation
9479@c FIXME remove warning when type/range checks added
9480
9481@value{GDBN} considers two Modula-2 variables type equivalent if:
9482
9483@itemize @bullet
9484@item
9485They are of types that have been declared equivalent via a @code{TYPE
9486@var{t1} = @var{t2}} statement
9487
9488@item
9489They have been declared on the same line. (Note: This is true of the
9490@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9491@end itemize
9492
9493As long as type checking is enabled, any attempt to combine variables
9494whose types are not equivalent is an error.
9495
9496Range checking is done on all mathematical operations, assignment, array
9497index bounds, and all built-in functions and procedures.
9498
6d2ebf8b 9499@node M2 Scope
c906108c
SS
9500@subsubsection The scope operators @code{::} and @code{.}
9501@cindex scope
41afff9a 9502@cindex @code{.}, Modula-2 scope operator
c906108c
SS
9503@cindex colon, doubled as scope operator
9504@ifinfo
41afff9a 9505@vindex colon-colon@r{, in Modula-2}
c906108c
SS
9506@c Info cannot handle :: but TeX can.
9507@end ifinfo
9508@iftex
41afff9a 9509@vindex ::@r{, in Modula-2}
c906108c
SS
9510@end iftex
9511
9512There are a few subtle differences between the Modula-2 scope operator
9513(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9514similar syntax:
9515
474c8240 9516@smallexample
c906108c
SS
9517
9518@var{module} . @var{id}
9519@var{scope} :: @var{id}
474c8240 9520@end smallexample
c906108c
SS
9521
9522@noindent
9523where @var{scope} is the name of a module or a procedure,
9524@var{module} the name of a module, and @var{id} is any declared
9525identifier within your program, except another module.
9526
9527Using the @code{::} operator makes @value{GDBN} search the scope
9528specified by @var{scope} for the identifier @var{id}. If it is not
9529found in the specified scope, then @value{GDBN} searches all scopes
9530enclosing the one specified by @var{scope}.
9531
9532Using the @code{.} operator makes @value{GDBN} search the current scope for
9533the identifier specified by @var{id} that was imported from the
9534definition module specified by @var{module}. With this operator, it is
9535an error if the identifier @var{id} was not imported from definition
9536module @var{module}, or if @var{id} is not an identifier in
9537@var{module}.
9538
6d2ebf8b 9539@node GDB/M2
c906108c
SS
9540@subsubsection @value{GDBN} and Modula-2
9541
9542Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9543Five subcommands of @code{set print} and @code{show print} apply
b37052ae 9544specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 9545@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 9546apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
9547analogue in Modula-2.
9548
9549The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 9550with any language, is not useful with Modula-2. Its
c906108c 9551intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 9552created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 9553address can be specified by an integral constant, the construct
d4f3574e 9554@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
9555
9556@cindex @code{#} in Modula-2
9557In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9558interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 9559
e07c999f
PH
9560@node Ada
9561@subsection Ada
9562@cindex Ada
9563
9564The extensions made to @value{GDBN} for Ada only support
9565output from the @sc{gnu} Ada (GNAT) compiler.
9566Other Ada compilers are not currently supported, and
9567attempting to debug executables produced by them is most likely
9568to be difficult.
9569
9570
9571@cindex expressions in Ada
9572@menu
9573* Ada Mode Intro:: General remarks on the Ada syntax
9574 and semantics supported by Ada mode
9575 in @value{GDBN}.
9576* Omissions from Ada:: Restrictions on the Ada expression syntax.
9577* Additions to Ada:: Extensions of the Ada expression syntax.
9578* Stopping Before Main Program:: Debugging the program during elaboration.
9579* Ada Glitches:: Known peculiarities of Ada mode.
9580@end menu
9581
9582@node Ada Mode Intro
9583@subsubsection Introduction
9584@cindex Ada mode, general
9585
9586The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9587syntax, with some extensions.
9588The philosophy behind the design of this subset is
9589
9590@itemize @bullet
9591@item
9592That @value{GDBN} should provide basic literals and access to operations for
9593arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9594leaving more sophisticated computations to subprograms written into the
9595program (which therefore may be called from @value{GDBN}).
9596
9597@item
9598That type safety and strict adherence to Ada language restrictions
9599are not particularly important to the @value{GDBN} user.
9600
9601@item
9602That brevity is important to the @value{GDBN} user.
9603@end itemize
9604
9605Thus, for brevity, the debugger acts as if there were
9606implicit @code{with} and @code{use} clauses in effect for all user-written
9607packages, making it unnecessary to fully qualify most names with
9608their packages, regardless of context. Where this causes ambiguity,
9609@value{GDBN} asks the user's intent.
9610
9611The debugger will start in Ada mode if it detects an Ada main program.
9612As for other languages, it will enter Ada mode when stopped in a program that
9613was translated from an Ada source file.
9614
9615While in Ada mode, you may use `@t{--}' for comments. This is useful
9616mostly for documenting command files. The standard @value{GDBN} comment
9617(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9618middle (to allow based literals).
9619
9620The debugger supports limited overloading. Given a subprogram call in which
9621the function symbol has multiple definitions, it will use the number of
9622actual parameters and some information about their types to attempt to narrow
9623the set of definitions. It also makes very limited use of context, preferring
9624procedures to functions in the context of the @code{call} command, and
9625functions to procedures elsewhere.
9626
9627@node Omissions from Ada
9628@subsubsection Omissions from Ada
9629@cindex Ada, omissions from
9630
9631Here are the notable omissions from the subset:
9632
9633@itemize @bullet
9634@item
9635Only a subset of the attributes are supported:
9636
9637@itemize @minus
9638@item
9639@t{'First}, @t{'Last}, and @t{'Length}
9640 on array objects (not on types and subtypes).
9641
9642@item
9643@t{'Min} and @t{'Max}.
9644
9645@item
9646@t{'Pos} and @t{'Val}.
9647
9648@item
9649@t{'Tag}.
9650
9651@item
9652@t{'Range} on array objects (not subtypes), but only as the right
9653operand of the membership (@code{in}) operator.
9654
9655@item
9656@t{'Access}, @t{'Unchecked_Access}, and
9657@t{'Unrestricted_Access} (a GNAT extension).
9658
9659@item
9660@t{'Address}.
9661@end itemize
9662
9663@item
9664The names in
9665@code{Characters.Latin_1} are not available and
9666concatenation is not implemented. Thus, escape characters in strings are
9667not currently available.
9668
9669@item
9670Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9671equality of representations. They will generally work correctly
9672for strings and arrays whose elements have integer or enumeration types.
9673They may not work correctly for arrays whose element
9674types have user-defined equality, for arrays of real values
9675(in particular, IEEE-conformant floating point, because of negative
9676zeroes and NaNs), and for arrays whose elements contain unused bits with
9677indeterminate values.
9678
9679@item
9680The other component-by-component array operations (@code{and}, @code{or},
9681@code{xor}, @code{not}, and relational tests other than equality)
9682are not implemented.
9683
9684@item
9685There are no record or array aggregates.
9686
9687@item
9688Calls to dispatching subprograms are not implemented.
9689
9690@item
9691The overloading algorithm is much more limited (i.e., less selective)
9692than that of real Ada. It makes only limited use of the context in which a subexpression
9693appears to resolve its meaning, and it is much looser in its rules for allowing
9694type matches. As a result, some function calls will be ambiguous, and the user
9695will be asked to choose the proper resolution.
9696
9697@item
9698The @code{new} operator is not implemented.
9699
9700@item
9701Entry calls are not implemented.
9702
9703@item
9704Aside from printing, arithmetic operations on the native VAX floating-point
9705formats are not supported.
9706
9707@item
9708It is not possible to slice a packed array.
9709@end itemize
9710
9711@node Additions to Ada
9712@subsubsection Additions to Ada
9713@cindex Ada, deviations from
9714
9715As it does for other languages, @value{GDBN} makes certain generic
9716extensions to Ada (@pxref{Expressions}):
9717
9718@itemize @bullet
9719@item
9720If the expression @var{E} is a variable residing in memory
9721(typically a local variable or array element) and @var{N} is
9722a positive integer, then @code{@var{E}@@@var{N}} displays the values of
9723@var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
9724In Ada, this operator is generally not necessary, since its prime use
9725is in displaying parts of an array, and slicing will usually do this in Ada.
9726However, there are occasional uses when debugging programs
9727in which certain debugging information has been optimized away.
9728
9729@item
9730@code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
9731in function or file @var{B}.'' When @var{B} is a file name, you must typically
9732surround it in single quotes.
9733
9734@item
9735The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
9736@var{type} that appears at address @var{addr}.''
9737
9738@item
9739A name starting with @samp{$} is a convenience variable
9740(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
9741@end itemize
9742
9743In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
9744to Ada:
9745
9746@itemize @bullet
9747@item
9748The assignment statement is allowed as an expression, returning
9749its right-hand operand as its value. Thus, you may enter
9750
9751@smallexample
9752set x := y + 3
9753print A(tmp := y + 1)
9754@end smallexample
9755
9756@item
9757The semicolon is allowed as an ``operator,'' returning as its value
9758the value of its right-hand operand.
9759This allows, for example,
9760complex conditional breaks:
9761
9762@smallexample
9763break f
9764condition 1 (report(i); k += 1; A(k) > 100)
9765@end smallexample
9766
9767@item
9768Rather than use catenation and symbolic character names to introduce special
9769characters into strings, one may instead use a special bracket notation,
9770which is also used to print strings. A sequence of characters of the form
9771@samp{["@var{XX}"]} within a string or character literal denotes the
9772(single) character whose numeric encoding is @var{XX} in hexadecimal. The
9773sequence of characters @samp{["""]} also denotes a single quotation mark
9774in strings. For example,
9775@smallexample
9776 "One line.["0a"]Next line.["0a"]"
9777@end smallexample
9778@noindent
9779contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
9780period.
9781
9782@item
9783The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
9784@t{'Max} is optional (and is ignored in any case). For example, it is valid
9785to write
9786
9787@smallexample
9788print 'max(x, y)
9789@end smallexample
9790
9791@item
9792When printing arrays, @value{GDBN} uses positional notation when the
9793array has a lower bound of 1, and uses a modified named notation otherwise.
9794For example, a one-dimensional array of three integers with a lower bound of 3 might print as
9795
9796@smallexample
9797(3 => 10, 17, 1)
9798@end smallexample
9799
9800@noindent
9801That is, in contrast to valid Ada, only the first component has a @code{=>}
9802clause.
9803
9804@item
9805You may abbreviate attributes in expressions with any unique,
9806multi-character subsequence of
9807their names (an exact match gets preference).
9808For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
9809in place of @t{a'length}.
9810
9811@item
9812@cindex quoting Ada internal identifiers
9813Since Ada is case-insensitive, the debugger normally maps identifiers you type
9814to lower case. The GNAT compiler uses upper-case characters for
9815some of its internal identifiers, which are normally of no interest to users.
9816For the rare occasions when you actually have to look at them,
9817enclose them in angle brackets to avoid the lower-case mapping.
9818For example,
9819@smallexample
9820@value{GDBP} print <JMPBUF_SAVE>[0]
9821@end smallexample
9822
9823@item
9824Printing an object of class-wide type or dereferencing an
9825access-to-class-wide value will display all the components of the object's
9826specific type (as indicated by its run-time tag). Likewise, component
9827selection on such a value will operate on the specific type of the
9828object.
9829
9830@end itemize
9831
9832@node Stopping Before Main Program
9833@subsubsection Stopping at the Very Beginning
9834
9835@cindex breakpointing Ada elaboration code
9836It is sometimes necessary to debug the program during elaboration, and
9837before reaching the main procedure.
9838As defined in the Ada Reference
9839Manual, the elaboration code is invoked from a procedure called
9840@code{adainit}. To run your program up to the beginning of
9841elaboration, simply use the following two commands:
9842@code{tbreak adainit} and @code{run}.
9843
9844@node Ada Glitches
9845@subsubsection Known Peculiarities of Ada Mode
9846@cindex Ada, problems
9847
9848Besides the omissions listed previously (@pxref{Omissions from Ada}),
9849we know of several problems with and limitations of Ada mode in
9850@value{GDBN},
9851some of which will be fixed with planned future releases of the debugger
9852and the GNU Ada compiler.
9853
9854@itemize @bullet
9855@item
9856Currently, the debugger
9857has insufficient information to determine whether certain pointers represent
9858pointers to objects or the objects themselves.
9859Thus, the user may have to tack an extra @code{.all} after an expression
9860to get it printed properly.
9861
9862@item
9863Static constants that the compiler chooses not to materialize as objects in
9864storage are invisible to the debugger.
9865
9866@item
9867Named parameter associations in function argument lists are ignored (the
9868argument lists are treated as positional).
9869
9870@item
9871Many useful library packages are currently invisible to the debugger.
9872
9873@item
9874Fixed-point arithmetic, conversions, input, and output is carried out using
9875floating-point arithmetic, and may give results that only approximate those on
9876the host machine.
9877
9878@item
9879The type of the @t{'Address} attribute may not be @code{System.Address}.
9880
9881@item
9882The GNAT compiler never generates the prefix @code{Standard} for any of
9883the standard symbols defined by the Ada language. @value{GDBN} knows about
9884this: it will strip the prefix from names when you use it, and will never
9885look for a name you have so qualified among local symbols, nor match against
9886symbols in other packages or subprograms. If you have
9887defined entities anywhere in your program other than parameters and
9888local variables whose simple names match names in @code{Standard},
9889GNAT's lack of qualification here can cause confusion. When this happens,
9890you can usually resolve the confusion
9891by qualifying the problematic names with package
9892@code{Standard} explicitly.
9893@end itemize
9894
4e562065
JB
9895@node Unsupported languages
9896@section Unsupported languages
9897
9898@cindex unsupported languages
9899@cindex minimal language
9900In addition to the other fully-supported programming languages,
9901@value{GDBN} also provides a pseudo-language, called @code{minimal}.
9902It does not represent a real programming language, but provides a set
9903of capabilities close to what the C or assembly languages provide.
9904This should allow most simple operations to be performed while debugging
9905an application that uses a language currently not supported by @value{GDBN}.
9906
9907If the language is set to @code{auto}, @value{GDBN} will automatically
9908select this language if the current frame corresponds to an unsupported
9909language.
9910
6d2ebf8b 9911@node Symbols
c906108c
SS
9912@chapter Examining the Symbol Table
9913
d4f3574e 9914The commands described in this chapter allow you to inquire about the
c906108c
SS
9915symbols (names of variables, functions and types) defined in your
9916program. This information is inherent in the text of your program and
9917does not change as your program executes. @value{GDBN} finds it in your
9918program's symbol table, in the file indicated when you started @value{GDBN}
9919(@pxref{File Options, ,Choosing files}), or by one of the
9920file-management commands (@pxref{Files, ,Commands to specify files}).
9921
9922@cindex symbol names
9923@cindex names of symbols
9924@cindex quoting names
9925Occasionally, you may need to refer to symbols that contain unusual
9926characters, which @value{GDBN} ordinarily treats as word delimiters. The
9927most frequent case is in referring to static variables in other
9928source files (@pxref{Variables,,Program variables}). File names
9929are recorded in object files as debugging symbols, but @value{GDBN} would
9930ordinarily parse a typical file name, like @file{foo.c}, as the three words
9931@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
9932@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
9933
474c8240 9934@smallexample
c906108c 9935p 'foo.c'::x
474c8240 9936@end smallexample
c906108c
SS
9937
9938@noindent
9939looks up the value of @code{x} in the scope of the file @file{foo.c}.
9940
9941@table @code
a8f24a35
EZ
9942@cindex case-insensitive symbol names
9943@cindex case sensitivity in symbol names
9944@kindex set case-sensitive
9945@item set case-sensitive on
9946@itemx set case-sensitive off
9947@itemx set case-sensitive auto
9948Normally, when @value{GDBN} looks up symbols, it matches their names
9949with case sensitivity determined by the current source language.
9950Occasionally, you may wish to control that. The command @code{set
9951case-sensitive} lets you do that by specifying @code{on} for
9952case-sensitive matches or @code{off} for case-insensitive ones. If
9953you specify @code{auto}, case sensitivity is reset to the default
9954suitable for the source language. The default is case-sensitive
9955matches for all languages except for Fortran, for which the default is
9956case-insensitive matches.
9957
9c16f35a
EZ
9958@kindex show case-sensitive
9959@item show case-sensitive
a8f24a35
EZ
9960This command shows the current setting of case sensitivity for symbols
9961lookups.
9962
c906108c 9963@kindex info address
b37052ae 9964@cindex address of a symbol
c906108c
SS
9965@item info address @var{symbol}
9966Describe where the data for @var{symbol} is stored. For a register
9967variable, this says which register it is kept in. For a non-register
9968local variable, this prints the stack-frame offset at which the variable
9969is always stored.
9970
9971Note the contrast with @samp{print &@var{symbol}}, which does not work
9972at all for a register variable, and for a stack local variable prints
9973the exact address of the current instantiation of the variable.
9974
3d67e040 9975@kindex info symbol
b37052ae 9976@cindex symbol from address
9c16f35a 9977@cindex closest symbol and offset for an address
3d67e040
EZ
9978@item info symbol @var{addr}
9979Print the name of a symbol which is stored at the address @var{addr}.
9980If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
9981nearest symbol and an offset from it:
9982
474c8240 9983@smallexample
3d67e040
EZ
9984(@value{GDBP}) info symbol 0x54320
9985_initialize_vx + 396 in section .text
474c8240 9986@end smallexample
3d67e040
EZ
9987
9988@noindent
9989This is the opposite of the @code{info address} command. You can use
9990it to find out the name of a variable or a function given its address.
9991
c906108c 9992@kindex whatis
d4f3574e
SS
9993@item whatis @var{expr}
9994Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
9995actually evaluated, and any side-effecting operations (such as
9996assignments or function calls) inside it do not take place.
9997@xref{Expressions, ,Expressions}.
9998
9999@item whatis
10000Print the data type of @code{$}, the last value in the value history.
10001
10002@kindex ptype
10003@item ptype @var{typename}
10004Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
10005the name of a type, or for C code it may have the form @samp{class
10006@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
10007@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 10008
d4f3574e 10009@item ptype @var{expr}
c906108c 10010@itemx ptype
d4f3574e 10011Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
10012differs from @code{whatis} by printing a detailed description, instead
10013of just the name of the type.
10014
10015For example, for this variable declaration:
10016
474c8240 10017@smallexample
c906108c 10018struct complex @{double real; double imag;@} v;
474c8240 10019@end smallexample
c906108c
SS
10020
10021@noindent
10022the two commands give this output:
10023
474c8240 10024@smallexample
c906108c
SS
10025@group
10026(@value{GDBP}) whatis v
10027type = struct complex
10028(@value{GDBP}) ptype v
10029type = struct complex @{
10030 double real;
10031 double imag;
10032@}
10033@end group
474c8240 10034@end smallexample
c906108c
SS
10035
10036@noindent
10037As with @code{whatis}, using @code{ptype} without an argument refers to
10038the type of @code{$}, the last value in the value history.
10039
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
6d2ebf8b 10669On systems with memory-mapped files, an auxiliary file named
c906108c
SS
10670@file{@var{filename}.syms} may hold symbol table information for
10671@var{filename}. If so, @value{GDBN} maps in the symbol table from
10672@file{@var{filename}.syms}, starting up more quickly. See the
10673descriptions of the file options @samp{-mapped} and @samp{-readnow}
7b5ba0cc
EZ
10674(available on the command line, see @ref{File Options, , -readnow},
10675and with the commands @code{file}, @code{symbol-file}, or
10676@code{add-symbol-file}, described below), for more information.
c906108c 10677
fc8be69e
EZ
10678@cindex unlinked object files
10679@cindex patching object files
10680You can load unlinked object @file{.o} files into @value{GDBN} using
10681the @code{file} command. You will not be able to ``run'' an object
10682file, but you can disassemble functions and inspect variables. Also,
10683if the underlying BFD functionality supports it, you could use
10684@kbd{gdb -write} to patch object files using this technique. Note
10685that @value{GDBN} can neither interpret nor modify relocations in this
10686case, so branches and some initialized variables will appear to go to
10687the wrong place. But this feature is still handy from time to time.
10688
c906108c
SS
10689@item file
10690@code{file} with no argument makes @value{GDBN} discard any information it
10691has on both executable file and the symbol table.
10692
10693@kindex exec-file
10694@item exec-file @r{[} @var{filename} @r{]}
10695Specify that the program to be run (but not the symbol table) is found
10696in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
10697if necessary to locate your program. Omitting @var{filename} means to
10698discard information on the executable file.
10699
10700@kindex symbol-file
10701@item symbol-file @r{[} @var{filename} @r{]}
10702Read symbol table information from file @var{filename}. @code{PATH} is
10703searched when necessary. Use the @code{file} command to get both symbol
10704table and program to run from the same file.
10705
10706@code{symbol-file} with no argument clears out @value{GDBN} information on your
10707program's symbol table.
10708
5d161b24 10709The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
10710of its convenience variables, the value history, and all breakpoints and
10711auto-display expressions. This is because they may contain pointers to
10712the internal data recording symbols and data types, which are part of
10713the old symbol table data being discarded inside @value{GDBN}.
10714
10715@code{symbol-file} does not repeat if you press @key{RET} again after
10716executing it once.
10717
10718When @value{GDBN} is configured for a particular environment, it
10719understands debugging information in whatever format is the standard
10720generated for that environment; you may use either a @sc{gnu} compiler, or
10721other compilers that adhere to the local conventions.
c906108c
SS
10722Best results are usually obtained from @sc{gnu} compilers; for example,
10723using @code{@value{GCC}} you can generate debugging information for
10724optimized code.
c906108c
SS
10725
10726For most kinds of object files, with the exception of old SVR3 systems
10727using COFF, the @code{symbol-file} command does not normally read the
10728symbol table in full right away. Instead, it scans the symbol table
10729quickly to find which source files and which symbols are present. The
10730details are read later, one source file at a time, as they are needed.
10731
10732The purpose of this two-stage reading strategy is to make @value{GDBN}
10733start up faster. For the most part, it is invisible except for
10734occasional pauses while the symbol table details for a particular source
10735file are being read. (The @code{set verbose} command can turn these
10736pauses into messages if desired. @xref{Messages/Warnings, ,Optional
10737warnings and messages}.)
10738
c906108c
SS
10739We have not implemented the two-stage strategy for COFF yet. When the
10740symbol table is stored in COFF format, @code{symbol-file} reads the
10741symbol table data in full right away. Note that ``stabs-in-COFF''
10742still does the two-stage strategy, since the debug info is actually
10743in stabs format.
10744
10745@kindex readnow
10746@cindex reading symbols immediately
10747@cindex symbols, reading immediately
10748@kindex mapped
10749@cindex memory-mapped symbol file
10750@cindex saving symbol table
10751@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10752@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10753You can override the @value{GDBN} two-stage strategy for reading symbol
10754tables by using the @samp{-readnow} option with any of the commands that
10755load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 10756entire symbol table available.
c906108c 10757
c906108c
SS
10758If memory-mapped files are available on your system through the
10759@code{mmap} system call, you can use another option, @samp{-mapped}, to
10760cause @value{GDBN} to write the symbols for your program into a reusable
10761file. Future @value{GDBN} debugging sessions map in symbol information
10762from this auxiliary symbol file (if the program has not changed), rather
10763than spending time reading the symbol table from the executable
10764program. Using the @samp{-mapped} option has the same effect as
10765starting @value{GDBN} with the @samp{-mapped} command-line option.
10766
10767You can use both options together, to make sure the auxiliary symbol
10768file has all the symbol information for your program.
10769
10770The auxiliary symbol file for a program called @var{myprog} is called
10771@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
10772than the corresponding executable), @value{GDBN} always attempts to use
10773it when you debug @var{myprog}; no special options or commands are
10774needed.
10775
10776The @file{.syms} file is specific to the host machine where you run
10777@value{GDBN}. It holds an exact image of the internal @value{GDBN}
10778symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
10779
10780@c FIXME: for now no mention of directories, since this seems to be in
10781@c flux. 13mar1992 status is that in theory GDB would look either in
10782@c current dir or in same dir as myprog; but issues like competing
10783@c GDB's, or clutter in system dirs, mean that in practice right now
10784@c only current dir is used. FFish says maybe a special GDB hierarchy
10785@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
10786@c files.
10787
c906108c 10788@kindex core-file
09d4efe1 10789@item core-file @r{[}@var{filename}@r{]}
4644b6e3 10790@itemx core
c906108c
SS
10791Specify the whereabouts of a core dump file to be used as the ``contents
10792of memory''. Traditionally, core files contain only some parts of the
10793address space of the process that generated them; @value{GDBN} can access the
10794executable file itself for other parts.
10795
10796@code{core-file} with no argument specifies that no core file is
10797to be used.
10798
10799Note that the core file is ignored when your program is actually running
7a292a7a
SS
10800under @value{GDBN}. So, if you have been running your program and you
10801wish to debug a core file instead, you must kill the subprocess in which
10802the program is running. To do this, use the @code{kill} command
c906108c 10803(@pxref{Kill Process, ,Killing the child process}).
c906108c 10804
c906108c
SS
10805@kindex add-symbol-file
10806@cindex dynamic linking
10807@item add-symbol-file @var{filename} @var{address}
10808@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
17d9d558 10809@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
10810The @code{add-symbol-file} command reads additional symbol table
10811information from the file @var{filename}. You would use this command
10812when @var{filename} has been dynamically loaded (by some other means)
10813into the program that is running. @var{address} should be the memory
10814address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
10815this out for itself. You can additionally specify an arbitrary number
10816of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
10817section name and base address for that section. You can specify any
10818@var{address} as an expression.
c906108c
SS
10819
10820The symbol table of the file @var{filename} is added to the symbol table
10821originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
10822@code{add-symbol-file} command any number of times; the new symbol data
10823thus read keeps adding to the old. To discard all old symbol data
10824instead, use the @code{symbol-file} command without any arguments.
c906108c 10825
17d9d558
JB
10826@cindex relocatable object files, reading symbols from
10827@cindex object files, relocatable, reading symbols from
10828@cindex reading symbols from relocatable object files
10829@cindex symbols, reading from relocatable object files
10830@cindex @file{.o} files, reading symbols from
10831Although @var{filename} is typically a shared library file, an
10832executable file, or some other object file which has been fully
10833relocated for loading into a process, you can also load symbolic
10834information from relocatable @file{.o} files, as long as:
10835
10836@itemize @bullet
10837@item
10838the file's symbolic information refers only to linker symbols defined in
10839that file, not to symbols defined by other object files,
10840@item
10841every section the file's symbolic information refers to has actually
10842been loaded into the inferior, as it appears in the file, and
10843@item
10844you can determine the address at which every section was loaded, and
10845provide these to the @code{add-symbol-file} command.
10846@end itemize
10847
10848@noindent
10849Some embedded operating systems, like Sun Chorus and VxWorks, can load
10850relocatable files into an already running program; such systems
10851typically make the requirements above easy to meet. However, it's
10852important to recognize that many native systems use complex link
49efadf5 10853procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
10854assembly, for example) that make the requirements difficult to meet. In
10855general, one cannot assume that using @code{add-symbol-file} to read a
10856relocatable object file's symbolic information will have the same effect
10857as linking the relocatable object file into the program in the normal
10858way.
10859
c906108c
SS
10860@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
10861
10862You can use the @samp{-mapped} and @samp{-readnow} options just as with
10863the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
10864table information for @var{filename}.
10865
c45da7e6
EZ
10866@kindex add-symbol-file-from-memory
10867@cindex @code{syscall DSO}
10868@cindex load symbols from memory
10869@item add-symbol-file-from-memory @var{address}
10870Load symbols from the given @var{address} in a dynamically loaded
10871object file whose image is mapped directly into the inferior's memory.
10872For example, the Linux kernel maps a @code{syscall DSO} into each
10873process's address space; this DSO provides kernel-specific code for
10874some system calls. The argument can be any expression whose
10875evaluation yields the address of the file's shared object file header.
10876For this command to work, you must have used @code{symbol-file} or
10877@code{exec-file} commands in advance.
10878
09d4efe1
EZ
10879@kindex add-shared-symbol-files
10880@kindex assf
10881@item add-shared-symbol-files @var{library-file}
10882@itemx assf @var{library-file}
10883The @code{add-shared-symbol-files} command can currently be used only
10884in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
10885alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
10886@value{GDBN} automatically looks for shared libraries, however if
10887@value{GDBN} does not find yours, you can invoke
10888@code{add-shared-symbol-files}. It takes one argument: the shared
10889library's file name. @code{assf} is a shorthand alias for
10890@code{add-shared-symbol-files}.
c906108c 10891
c906108c 10892@kindex section
09d4efe1
EZ
10893@item section @var{section} @var{addr}
10894The @code{section} command changes the base address of the named
10895@var{section} of the exec file to @var{addr}. This can be used if the
10896exec file does not contain section addresses, (such as in the
10897@code{a.out} format), or when the addresses specified in the file
10898itself are wrong. Each section must be changed separately. The
10899@code{info files} command, described below, lists all the sections and
10900their addresses.
c906108c
SS
10901
10902@kindex info files
10903@kindex info target
10904@item info files
10905@itemx info target
7a292a7a
SS
10906@code{info files} and @code{info target} are synonymous; both print the
10907current target (@pxref{Targets, ,Specifying a Debugging Target}),
10908including the names of the executable and core dump files currently in
10909use by @value{GDBN}, and the files from which symbols were loaded. The
10910command @code{help target} lists all possible targets rather than
10911current ones.
10912
fe95c787
MS
10913@kindex maint info sections
10914@item maint info sections
10915Another command that can give you extra information about program sections
10916is @code{maint info sections}. In addition to the section information
10917displayed by @code{info files}, this command displays the flags and file
10918offset of each section in the executable and core dump files. In addition,
10919@code{maint info sections} provides the following command options (which
10920may be arbitrarily combined):
10921
10922@table @code
10923@item ALLOBJ
10924Display sections for all loaded object files, including shared libraries.
10925@item @var{sections}
6600abed 10926Display info only for named @var{sections}.
fe95c787
MS
10927@item @var{section-flags}
10928Display info only for sections for which @var{section-flags} are true.
10929The section flags that @value{GDBN} currently knows about are:
10930@table @code
10931@item ALLOC
10932Section will have space allocated in the process when loaded.
10933Set for all sections except those containing debug information.
10934@item LOAD
10935Section will be loaded from the file into the child process memory.
10936Set for pre-initialized code and data, clear for @code{.bss} sections.
10937@item RELOC
10938Section needs to be relocated before loading.
10939@item READONLY
10940Section cannot be modified by the child process.
10941@item CODE
10942Section contains executable code only.
6600abed 10943@item DATA
fe95c787
MS
10944Section contains data only (no executable code).
10945@item ROM
10946Section will reside in ROM.
10947@item CONSTRUCTOR
10948Section contains data for constructor/destructor lists.
10949@item HAS_CONTENTS
10950Section is not empty.
10951@item NEVER_LOAD
10952An instruction to the linker to not output the section.
10953@item COFF_SHARED_LIBRARY
10954A notification to the linker that the section contains
10955COFF shared library information.
10956@item IS_COMMON
10957Section contains common symbols.
10958@end table
10959@end table
6763aef9 10960@kindex set trust-readonly-sections
9c16f35a 10961@cindex read-only sections
6763aef9
MS
10962@item set trust-readonly-sections on
10963Tell @value{GDBN} that readonly sections in your object file
6ca652b0 10964really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
10965In that case, @value{GDBN} can fetch values from these sections
10966out of the object file, rather than from the target program.
10967For some targets (notably embedded ones), this can be a significant
10968enhancement to debugging performance.
10969
10970The default is off.
10971
10972@item set trust-readonly-sections off
15110bc3 10973Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
10974the contents of the section might change while the program is running,
10975and must therefore be fetched from the target when needed.
9c16f35a
EZ
10976
10977@item show trust-readonly-sections
10978Show the current setting of trusting readonly sections.
c906108c
SS
10979@end table
10980
10981All file-specifying commands allow both absolute and relative file names
10982as arguments. @value{GDBN} always converts the file name to an absolute file
10983name and remembers it that way.
10984
c906108c 10985@cindex shared libraries
9c16f35a
EZ
10986@value{GDBN} supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
10987and IBM RS/6000 AIX shared libraries.
53a5351d 10988
c906108c
SS
10989@value{GDBN} automatically loads symbol definitions from shared libraries
10990when you use the @code{run} command, or when you examine a core file.
10991(Before you issue the @code{run} command, @value{GDBN} does not understand
10992references to a function in a shared library, however---unless you are
10993debugging a core file).
53a5351d
JM
10994
10995On HP-UX, if the program loads a library explicitly, @value{GDBN}
10996automatically loads the symbols at the time of the @code{shl_load} call.
10997
c906108c
SS
10998@c FIXME: some @value{GDBN} release may permit some refs to undef
10999@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
11000@c FIXME...lib; check this from time to time when updating manual
11001
b7209cb4
FF
11002There are times, however, when you may wish to not automatically load
11003symbol definitions from shared libraries, such as when they are
11004particularly large or there are many of them.
11005
11006To control the automatic loading of shared library symbols, use the
11007commands:
11008
11009@table @code
11010@kindex set auto-solib-add
11011@item set auto-solib-add @var{mode}
11012If @var{mode} is @code{on}, symbols from all shared object libraries
11013will be loaded automatically when the inferior begins execution, you
11014attach to an independently started inferior, or when the dynamic linker
11015informs @value{GDBN} that a new library has been loaded. If @var{mode}
11016is @code{off}, symbols must be loaded manually, using the
11017@code{sharedlibrary} command. The default value is @code{on}.
11018
dcaf7c2c
EZ
11019@cindex memory used for symbol tables
11020If your program uses lots of shared libraries with debug info that
11021takes large amounts of memory, you can decrease the @value{GDBN}
11022memory footprint by preventing it from automatically loading the
11023symbols from shared libraries. To that end, type @kbd{set
11024auto-solib-add off} before running the inferior, then load each
11025library whose debug symbols you do need with @kbd{sharedlibrary
11026@var{regexp}}, where @var{regexp} is a regular expresion that matches
11027the libraries whose symbols you want to be loaded.
11028
b7209cb4
FF
11029@kindex show auto-solib-add
11030@item show auto-solib-add
11031Display the current autoloading mode.
11032@end table
11033
c45da7e6 11034@cindex load shared library
b7209cb4
FF
11035To explicitly load shared library symbols, use the @code{sharedlibrary}
11036command:
11037
c906108c
SS
11038@table @code
11039@kindex info sharedlibrary
11040@kindex info share
11041@item info share
11042@itemx info sharedlibrary
11043Print the names of the shared libraries which are currently loaded.
11044
11045@kindex sharedlibrary
11046@kindex share
11047@item sharedlibrary @var{regex}
11048@itemx share @var{regex}
c906108c
SS
11049Load shared object library symbols for files matching a
11050Unix regular expression.
11051As with files loaded automatically, it only loads shared libraries
11052required by your program for a core file or after typing @code{run}. If
11053@var{regex} is omitted all shared libraries required by your program are
11054loaded.
c45da7e6
EZ
11055
11056@item nosharedlibrary
11057@kindex nosharedlibrary
11058@cindex unload symbols from shared libraries
11059Unload all shared object library symbols. This discards all symbols
11060that have been loaded from all shared libraries. Symbols from shared
11061libraries that were loaded by explicit user requests are not
11062discarded.
c906108c
SS
11063@end table
11064
721c2651
EZ
11065Sometimes you may wish that @value{GDBN} stops and gives you control
11066when any of shared library events happen. Use the @code{set
11067stop-on-solib-events} command for this:
11068
11069@table @code
11070@item set stop-on-solib-events
11071@kindex set stop-on-solib-events
11072This command controls whether @value{GDBN} should give you control
11073when the dynamic linker notifies it about some shared library event.
11074The most common event of interest is loading or unloading of a new
11075shared library.
11076
11077@item show stop-on-solib-events
11078@kindex show stop-on-solib-events
11079Show whether @value{GDBN} stops and gives you control when shared
11080library events happen.
11081@end table
11082
f5ebfba0
DJ
11083Shared libraries are also supported in many cross or remote debugging
11084configurations. A copy of the target's libraries need to be present on the
11085host system; they need to be the same as the target libraries, although the
11086copies on the target can be stripped as long as the copies on the host are
11087not.
11088
59b7b46f
EZ
11089@cindex where to look for shared libraries
11090For remote debugging, you need to tell @value{GDBN} where the target
11091libraries are, so that it can load the correct copies---otherwise, it
11092may try to load the host's libraries. @value{GDBN} has two variables
11093to specify the search directories for target libraries.
f5ebfba0
DJ
11094
11095@table @code
59b7b46f 11096@cindex prefix for shared library file names
f5ebfba0
DJ
11097@kindex set solib-absolute-prefix
11098@item set solib-absolute-prefix @var{path}
11099If this variable is set, @var{path} will be used as a prefix for any
11100absolute shared library paths; many runtime loaders store the absolute
11101paths to the shared library in the target program's memory. If you use
11102@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
11103out in the same way that they are on the target, with e.g.@: a
11104@file{/usr/lib} hierarchy under @var{path}.
11105
59b7b46f
EZ
11106@cindex default value of @samp{solib-absolute-prefix}
11107@cindex @samp{--with-sysroot}
f5ebfba0
DJ
11108You can set the default value of @samp{solib-absolute-prefix} by using the
11109configure-time @samp{--with-sysroot} option.
11110
11111@kindex show solib-absolute-prefix
11112@item show solib-absolute-prefix
11113Display the current shared library prefix.
11114
11115@kindex set solib-search-path
11116@item set solib-search-path @var{path}
11117If this variable is set, @var{path} is a colon-separated list of directories
11118to search for shared libraries. @samp{solib-search-path} is used after
11119@samp{solib-absolute-prefix} fails to locate the library, or if the path to
11120the library is relative instead of absolute. If you want to use
11121@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
11122set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
11123@value{GDBN} from finding your host's libraries.
11124
11125@kindex show solib-search-path
11126@item show solib-search-path
11127Display the current shared library search path.
11128@end table
11129
5b5d99cf
JB
11130
11131@node Separate Debug Files
11132@section Debugging Information in Separate Files
11133@cindex separate debugging information files
11134@cindex debugging information in separate files
11135@cindex @file{.debug} subdirectories
11136@cindex debugging information directory, global
11137@cindex global debugging information directory
11138
11139@value{GDBN} allows you to put a program's debugging information in a
11140file separate from the executable itself, in a way that allows
11141@value{GDBN} to find and load the debugging information automatically.
11142Since debugging information can be very large --- sometimes larger
11143than the executable code itself --- some systems distribute debugging
11144information for their executables in separate files, which users can
11145install only when they need to debug a problem.
11146
11147If an executable's debugging information has been extracted to a
11148separate file, the executable should contain a @dfn{debug link} giving
11149the name of the debugging information file (with no directory
11150components), and a checksum of its contents. (The exact form of a
11151debug link is described below.) If the full name of the directory
11152containing the executable is @var{execdir}, and the executable has a
11153debug link that specifies the name @var{debugfile}, then @value{GDBN}
11154will automatically search for the debugging information file in three
11155places:
11156
11157@itemize @bullet
11158@item
11159the directory containing the executable file (that is, it will look
11160for a file named @file{@var{execdir}/@var{debugfile}},
11161@item
11162a subdirectory of that directory named @file{.debug} (that is, the
11163file @file{@var{execdir}/.debug/@var{debugfile}}, and
11164@item
11165a subdirectory of the global debug file directory that includes the
11166executable's full path, and the name from the link (that is, the file
11167@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
11168@var{globaldebugdir} is the global debug file directory, and
11169@var{execdir} has been turned into a relative path).
11170@end itemize
11171@noindent
11172@value{GDBN} checks under each of these names for a debugging
11173information file whose checksum matches that given in the link, and
11174reads the debugging information from the first one it finds.
11175
11176So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
11177which has a link containing the name @file{ls.debug}, and the global
11178debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
11179for debug information in @file{/usr/bin/ls.debug},
11180@file{/usr/bin/.debug/ls.debug}, and
11181@file{/usr/lib/debug/usr/bin/ls.debug}.
11182
11183You can set the global debugging info directory's name, and view the
11184name @value{GDBN} is currently using.
11185
11186@table @code
11187
11188@kindex set debug-file-directory
11189@item set debug-file-directory @var{directory}
11190Set the directory which @value{GDBN} searches for separate debugging
11191information files to @var{directory}.
11192
11193@kindex show debug-file-directory
11194@item show debug-file-directory
11195Show the directory @value{GDBN} searches for separate debugging
11196information files.
11197
11198@end table
11199
11200@cindex @code{.gnu_debuglink} sections
11201@cindex debug links
11202A debug link is a special section of the executable file named
11203@code{.gnu_debuglink}. The section must contain:
11204
11205@itemize
11206@item
11207A filename, with any leading directory components removed, followed by
11208a zero byte,
11209@item
11210zero to three bytes of padding, as needed to reach the next four-byte
11211boundary within the section, and
11212@item
11213a four-byte CRC checksum, stored in the same endianness used for the
11214executable file itself. The checksum is computed on the debugging
11215information file's full contents by the function given below, passing
11216zero as the @var{crc} argument.
11217@end itemize
11218
11219Any executable file format can carry a debug link, as long as it can
11220contain a section named @code{.gnu_debuglink} with the contents
11221described above.
11222
11223The debugging information file itself should be an ordinary
11224executable, containing a full set of linker symbols, sections, and
11225debugging information. The sections of the debugging information file
11226should have the same names, addresses and sizes as the original file,
11227but they need not contain any data --- much like a @code{.bss} section
11228in an ordinary executable.
11229
11230As of December 2002, there is no standard GNU utility to produce
11231separated executable / debugging information file pairs. Ulrich
11232Drepper's @file{elfutils} package, starting with version 0.53,
11233contains a version of the @code{strip} command such that the command
11234@kbd{strip foo -f foo.debug} removes the debugging information from
11235the executable file @file{foo}, places it in the file
11236@file{foo.debug}, and leaves behind a debug link in @file{foo}.
11237
11238Since there are many different ways to compute CRC's (different
11239polynomials, reversals, byte ordering, etc.), the simplest way to
11240describe the CRC used in @code{.gnu_debuglink} sections is to give the
11241complete code for a function that computes it:
11242
4644b6e3 11243@kindex gnu_debuglink_crc32
5b5d99cf
JB
11244@smallexample
11245unsigned long
11246gnu_debuglink_crc32 (unsigned long crc,
11247 unsigned char *buf, size_t len)
11248@{
11249 static const unsigned long crc32_table[256] =
11250 @{
11251 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11252 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11253 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11254 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11255 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11256 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11257 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11258 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11259 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11260 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11261 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11262 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11263 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11264 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11265 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11266 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11267 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11268 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11269 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11270 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11271 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11272 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11273 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11274 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11275 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11276 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11277 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11278 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11279 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11280 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11281 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11282 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11283 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11284 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11285 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11286 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11287 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11288 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11289 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11290 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11291 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11292 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11293 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11294 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11295 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11296 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11297 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11298 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11299 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11300 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11301 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11302 0x2d02ef8d
11303 @};
11304 unsigned char *end;
11305
11306 crc = ~crc & 0xffffffff;
11307 for (end = buf + len; buf < end; ++buf)
11308 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 11309 return ~crc & 0xffffffff;
5b5d99cf
JB
11310@}
11311@end smallexample
11312
11313
6d2ebf8b 11314@node Symbol Errors
c906108c
SS
11315@section Errors reading symbol files
11316
11317While reading a symbol file, @value{GDBN} occasionally encounters problems,
11318such as symbol types it does not recognize, or known bugs in compiler
11319output. By default, @value{GDBN} does not notify you of such problems, since
11320they are relatively common and primarily of interest to people
11321debugging compilers. If you are interested in seeing information
11322about ill-constructed symbol tables, you can either ask @value{GDBN} to print
11323only one message about each such type of problem, no matter how many
11324times the problem occurs; or you can ask @value{GDBN} to print more messages,
11325to see how many times the problems occur, with the @code{set
11326complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
11327messages}).
11328
11329The messages currently printed, and their meanings, include:
11330
11331@table @code
11332@item inner block not inside outer block in @var{symbol}
11333
11334The symbol information shows where symbol scopes begin and end
11335(such as at the start of a function or a block of statements). This
11336error indicates that an inner scope block is not fully contained
11337in its outer scope blocks.
11338
11339@value{GDBN} circumvents the problem by treating the inner block as if it had
11340the same scope as the outer block. In the error message, @var{symbol}
11341may be shown as ``@code{(don't know)}'' if the outer block is not a
11342function.
11343
11344@item block at @var{address} out of order
11345
11346The symbol information for symbol scope blocks should occur in
11347order of increasing addresses. This error indicates that it does not
11348do so.
11349
11350@value{GDBN} does not circumvent this problem, and has trouble
11351locating symbols in the source file whose symbols it is reading. (You
11352can often determine what source file is affected by specifying
11353@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
11354messages}.)
11355
11356@item bad block start address patched
11357
11358The symbol information for a symbol scope block has a start address
11359smaller than the address of the preceding source line. This is known
11360to occur in the SunOS 4.1.1 (and earlier) C compiler.
11361
11362@value{GDBN} circumvents the problem by treating the symbol scope block as
11363starting on the previous source line.
11364
11365@item bad string table offset in symbol @var{n}
11366
11367@cindex foo
11368Symbol number @var{n} contains a pointer into the string table which is
11369larger than the size of the string table.
11370
11371@value{GDBN} circumvents the problem by considering the symbol to have the
11372name @code{foo}, which may cause other problems if many symbols end up
11373with this name.
11374
11375@item unknown symbol type @code{0x@var{nn}}
11376
7a292a7a
SS
11377The symbol information contains new data types that @value{GDBN} does
11378not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 11379uncomprehended information, in hexadecimal.
c906108c 11380
7a292a7a
SS
11381@value{GDBN} circumvents the error by ignoring this symbol information.
11382This usually allows you to debug your program, though certain symbols
c906108c 11383are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
11384debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
11385on @code{complain}, then go up to the function @code{read_dbx_symtab}
11386and examine @code{*bufp} to see the symbol.
c906108c
SS
11387
11388@item stub type has NULL name
c906108c 11389
7a292a7a 11390@value{GDBN} could not find the full definition for a struct or class.
c906108c 11391
7a292a7a 11392@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 11393The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
11394information that recent versions of the compiler should have output for
11395it.
c906108c
SS
11396
11397@item info mismatch between compiler and debugger
11398
11399@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 11400
c906108c
SS
11401@end table
11402
6d2ebf8b 11403@node Targets
c906108c 11404@chapter Specifying a Debugging Target
7a292a7a 11405
c906108c 11406@cindex debugging target
c906108c 11407A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
11408
11409Often, @value{GDBN} runs in the same host environment as your program;
11410in that case, the debugging target is specified as a side effect when
11411you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
11412flexibility---for example, running @value{GDBN} on a physically separate
11413host, or controlling a standalone system over a serial port or a
53a5351d
JM
11414realtime system over a TCP/IP connection---you can use the @code{target}
11415command to specify one of the target types configured for @value{GDBN}
11416(@pxref{Target Commands, ,Commands for managing targets}).
c906108c 11417
a8f24a35
EZ
11418@cindex target architecture
11419It is possible to build @value{GDBN} for several different @dfn{target
11420architectures}. When @value{GDBN} is built like that, you can choose
11421one of the available architectures with the @kbd{set architecture}
11422command.
11423
11424@table @code
11425@kindex set architecture
11426@kindex show architecture
11427@item set architecture @var{arch}
11428This command sets the current target architecture to @var{arch}. The
11429value of @var{arch} can be @code{"auto"}, in addition to one of the
11430supported architectures.
11431
11432@item show architecture
11433Show the current target architecture.
9c16f35a
EZ
11434
11435@item set processor
11436@itemx processor
11437@kindex set processor
11438@kindex show processor
11439These are alias commands for, respectively, @code{set architecture}
11440and @code{show architecture}.
a8f24a35
EZ
11441@end table
11442
c906108c
SS
11443@menu
11444* Active Targets:: Active targets
11445* Target Commands:: Commands for managing targets
c906108c
SS
11446* Byte Order:: Choosing target byte order
11447* Remote:: Remote debugging
96baa820 11448* KOD:: Kernel Object Display
c906108c
SS
11449
11450@end menu
11451
6d2ebf8b 11452@node Active Targets
c906108c 11453@section Active targets
7a292a7a 11454
c906108c
SS
11455@cindex stacking targets
11456@cindex active targets
11457@cindex multiple targets
11458
c906108c 11459There are three classes of targets: processes, core files, and
7a292a7a
SS
11460executable files. @value{GDBN} can work concurrently on up to three
11461active targets, one in each class. This allows you to (for example)
11462start a process and inspect its activity without abandoning your work on
11463a core file.
c906108c
SS
11464
11465For example, if you execute @samp{gdb a.out}, then the executable file
11466@code{a.out} is the only active target. If you designate a core file as
11467well---presumably from a prior run that crashed and coredumped---then
11468@value{GDBN} has two active targets and uses them in tandem, looking
11469first in the corefile target, then in the executable file, to satisfy
11470requests for memory addresses. (Typically, these two classes of target
11471are complementary, since core files contain only a program's
11472read-write memory---variables and so on---plus machine status, while
11473executable files contain only the program text and initialized data.)
c906108c
SS
11474
11475When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
11476target as well. When a process target is active, all @value{GDBN}
11477commands requesting memory addresses refer to that target; addresses in
11478an active core file or executable file target are obscured while the
11479process target is active.
c906108c 11480
7a292a7a
SS
11481Use the @code{core-file} and @code{exec-file} commands to select a new
11482core file or executable target (@pxref{Files, ,Commands to specify
c906108c 11483files}). To specify as a target a process that is already running, use
7a292a7a
SS
11484the @code{attach} command (@pxref{Attach, ,Debugging an already-running
11485process}).
c906108c 11486
6d2ebf8b 11487@node Target Commands
c906108c
SS
11488@section Commands for managing targets
11489
11490@table @code
11491@item target @var{type} @var{parameters}
7a292a7a
SS
11492Connects the @value{GDBN} host environment to a target machine or
11493process. A target is typically a protocol for talking to debugging
11494facilities. You use the argument @var{type} to specify the type or
11495protocol of the target machine.
c906108c
SS
11496
11497Further @var{parameters} are interpreted by the target protocol, but
11498typically include things like device names or host names to connect
11499with, process numbers, and baud rates.
c906108c
SS
11500
11501The @code{target} command does not repeat if you press @key{RET} again
11502after executing the command.
11503
11504@kindex help target
11505@item help target
11506Displays the names of all targets available. To display targets
11507currently selected, use either @code{info target} or @code{info files}
11508(@pxref{Files, ,Commands to specify files}).
11509
11510@item help target @var{name}
11511Describe a particular target, including any parameters necessary to
11512select it.
11513
11514@kindex set gnutarget
11515@item set gnutarget @var{args}
5d161b24 11516@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 11517knows whether it is reading an @dfn{executable},
5d161b24
DB
11518a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
11519with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
11520with @code{gnutarget} the @code{target} refers to a program, not a machine.
11521
d4f3574e 11522@quotation
c906108c
SS
11523@emph{Warning:} To specify a file format with @code{set gnutarget},
11524you must know the actual BFD name.
d4f3574e 11525@end quotation
c906108c 11526
d4f3574e
SS
11527@noindent
11528@xref{Files, , Commands to specify files}.
c906108c 11529
5d161b24 11530@kindex show gnutarget
c906108c
SS
11531@item show gnutarget
11532Use the @code{show gnutarget} command to display what file format
11533@code{gnutarget} is set to read. If you have not set @code{gnutarget},
11534@value{GDBN} will determine the file format for each file automatically,
11535and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11536@end table
11537
4644b6e3 11538@cindex common targets
c906108c
SS
11539Here are some common targets (available, or not, depending on the GDB
11540configuration):
c906108c
SS
11541
11542@table @code
4644b6e3 11543@kindex target
c906108c 11544@item target exec @var{program}
4644b6e3 11545@cindex executable file target
c906108c
SS
11546An executable file. @samp{target exec @var{program}} is the same as
11547@samp{exec-file @var{program}}.
11548
c906108c 11549@item target core @var{filename}
4644b6e3 11550@cindex core dump file target
c906108c
SS
11551A core dump file. @samp{target core @var{filename}} is the same as
11552@samp{core-file @var{filename}}.
c906108c 11553
c906108c 11554@item target remote @var{dev}
4644b6e3 11555@cindex remote target
c906108c
SS
11556Remote serial target in GDB-specific protocol. The argument @var{dev}
11557specifies what serial device to use for the connection (e.g.
11558@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 11559supports the @code{load} command. This is only useful if you have
c906108c
SS
11560some other way of getting the stub to the target system, and you can put
11561it somewhere in memory where it won't get clobbered by the download.
11562
c906108c 11563@item target sim
4644b6e3 11564@cindex built-in simulator target
2df3850c 11565Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 11566In general,
474c8240 11567@smallexample
104c1213
JM
11568 target sim
11569 load
11570 run
474c8240 11571@end smallexample
d4f3574e 11572@noindent
104c1213 11573works; however, you cannot assume that a specific memory map, device
d4f3574e 11574drivers, or even basic I/O is available, although some simulators do
104c1213
JM
11575provide these. For info about any processor-specific simulator details,
11576see the appropriate section in @ref{Embedded Processors, ,Embedded
11577Processors}.
11578
c906108c
SS
11579@end table
11580
104c1213 11581Some configurations may include these targets as well:
c906108c
SS
11582
11583@table @code
11584
c906108c 11585@item target nrom @var{dev}
4644b6e3 11586@cindex NetROM ROM emulator target
c906108c
SS
11587NetROM ROM emulator. This target only supports downloading.
11588
c906108c
SS
11589@end table
11590
5d161b24 11591Different targets are available on different configurations of @value{GDBN};
c906108c 11592your configuration may have more or fewer targets.
c906108c 11593
721c2651
EZ
11594Many remote targets require you to download the executable's code once
11595you've successfully established a connection. You may wish to control
11596various aspects of this process, such as the size of the data chunks
11597used by @value{GDBN} to download program parts to the remote target.
a8f24a35
EZ
11598
11599@table @code
11600@kindex set download-write-size
11601@item set download-write-size @var{size}
11602Set the write size used when downloading a program. Only used when
11603downloading a program onto a remote target. Specify zero or a
11604negative value to disable blocked writes. The actual size of each
11605transfer is also limited by the size of the target packet and the
11606memory cache.
11607
11608@kindex show download-write-size
11609@item show download-write-size
721c2651 11610@kindex show download-write-size
a8f24a35 11611Show the current value of the write size.
721c2651
EZ
11612
11613@item set hash
11614@kindex set hash@r{, for remote monitors}
11615@cindex hash mark while downloading
11616This command controls whether a hash mark @samp{#} is displayed while
11617downloading a file to the remote monitor. If on, a hash mark is
11618displayed after each S-record is successfully downloaded to the
11619monitor.
11620
11621@item show hash
11622@kindex show hash@r{, for remote monitors}
11623Show the current status of displaying the hash mark.
11624
11625@item set debug monitor
11626@kindex set debug monitor
11627@cindex display remote monitor communications
11628Enable or disable display of communications messages between
11629@value{GDBN} and the remote monitor.
11630
11631@item show debug monitor
11632@kindex show debug monitor
11633Show the current status of displaying communications between
11634@value{GDBN} and the remote monitor.
a8f24a35 11635@end table
c906108c
SS
11636
11637@table @code
11638
11639@kindex load @var{filename}
11640@item load @var{filename}
c906108c
SS
11641Depending on what remote debugging facilities are configured into
11642@value{GDBN}, the @code{load} command may be available. Where it exists, it
11643is meant to make @var{filename} (an executable) available for debugging
11644on the remote system---by downloading, or dynamic linking, for example.
11645@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
11646the @code{add-symbol-file} command.
11647
11648If your @value{GDBN} does not have a @code{load} command, attempting to
11649execute it gets the error message ``@code{You can't do that when your
11650target is @dots{}}''
c906108c
SS
11651
11652The file is loaded at whatever address is specified in the executable.
11653For some object file formats, you can specify the load address when you
11654link the program; for other formats, like a.out, the object file format
11655specifies a fixed address.
11656@c FIXME! This would be a good place for an xref to the GNU linker doc.
11657
c906108c
SS
11658@code{load} does not repeat if you press @key{RET} again after using it.
11659@end table
11660
6d2ebf8b 11661@node Byte Order
c906108c 11662@section Choosing target byte order
7a292a7a 11663
c906108c
SS
11664@cindex choosing target byte order
11665@cindex target byte order
c906108c 11666
172c2a43 11667Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
11668offer the ability to run either big-endian or little-endian byte
11669orders. Usually the executable or symbol will include a bit to
11670designate the endian-ness, and you will not need to worry about
11671which to use. However, you may still find it useful to adjust
d4f3574e 11672@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
11673
11674@table @code
4644b6e3 11675@kindex set endian
c906108c
SS
11676@item set endian big
11677Instruct @value{GDBN} to assume the target is big-endian.
11678
c906108c
SS
11679@item set endian little
11680Instruct @value{GDBN} to assume the target is little-endian.
11681
c906108c
SS
11682@item set endian auto
11683Instruct @value{GDBN} to use the byte order associated with the
11684executable.
11685
11686@item show endian
11687Display @value{GDBN}'s current idea of the target byte order.
11688
11689@end table
11690
11691Note that these commands merely adjust interpretation of symbolic
11692data on the host, and that they have absolutely no effect on the
11693target system.
11694
6d2ebf8b 11695@node Remote
c906108c
SS
11696@section Remote debugging
11697@cindex remote debugging
11698
11699If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
11700@value{GDBN} in the usual way, it is often useful to use remote debugging.
11701For example, you might use remote debugging on an operating system kernel,
c906108c
SS
11702or on a small system which does not have a general purpose operating system
11703powerful enough to run a full-featured debugger.
11704
11705Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
11706to make this work with particular debugging targets. In addition,
5d161b24 11707@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
11708but not specific to any particular target system) which you can use if you
11709write the remote stubs---the code that runs on the remote system to
11710communicate with @value{GDBN}.
11711
11712Other remote targets may be available in your
11713configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 11714
c45da7e6
EZ
11715Once you've connected to the remote target, @value{GDBN} allows you to
11716send arbitrary commands to the remote monitor:
11717
11718@table @code
11719@item remote @var{command}
11720@kindex remote@r{, a command}
11721@cindex send command to remote monitor
11722Send an arbitrary @var{command} string to the remote monitor.
11723@end table
11724
11725
6f05cf9f
AC
11726@node KOD
11727@section Kernel Object Display
6f05cf9f 11728@cindex kernel object display
6f05cf9f
AC
11729@cindex KOD
11730
11731Some targets support kernel object display. Using this facility,
11732@value{GDBN} communicates specially with the underlying operating system
11733and can display information about operating system-level objects such as
11734mutexes and other synchronization objects. Exactly which objects can be
11735displayed is determined on a per-OS basis.
11736
3bbe9696 11737@kindex set os
6f05cf9f
AC
11738Use the @code{set os} command to set the operating system. This tells
11739@value{GDBN} which kernel object display module to initialize:
11740
474c8240 11741@smallexample
6f05cf9f 11742(@value{GDBP}) set os cisco
474c8240 11743@end smallexample
6f05cf9f 11744
3bbe9696
EZ
11745@kindex show os
11746The associated command @code{show os} displays the operating system
11747set with the @code{set os} command; if no operating system has been
11748set, @code{show os} will display an empty string @samp{""}.
11749
6f05cf9f
AC
11750If @code{set os} succeeds, @value{GDBN} will display some information
11751about the operating system, and will create a new @code{info} command
11752which can be used to query the target. The @code{info} command is named
11753after the operating system:
c906108c 11754
3bbe9696 11755@kindex info cisco
474c8240 11756@smallexample
6f05cf9f
AC
11757(@value{GDBP}) info cisco
11758List of Cisco Kernel Objects
11759Object Description
11760any Any and all objects
474c8240 11761@end smallexample
6f05cf9f
AC
11762
11763Further subcommands can be used to query about particular objects known
11764by the kernel.
11765
3bbe9696
EZ
11766There is currently no way to determine whether a given operating
11767system is supported other than to try setting it with @kbd{set os
11768@var{name}}, where @var{name} is the name of the operating system you
11769want to try.
6f05cf9f
AC
11770
11771
11772@node Remote Debugging
11773@chapter Debugging remote programs
11774
6b2f586d 11775@menu
07f31aa6 11776* Connecting:: Connecting to a remote target
6b2f586d
AC
11777* Server:: Using the gdbserver program
11778* NetWare:: Using the gdbserve.nlm program
501eef12 11779* Remote configuration:: Remote configuration
6b2f586d 11780* remote stub:: Implementing a remote stub
6b2f586d
AC
11781@end menu
11782
07f31aa6
DJ
11783@node Connecting
11784@section Connecting to a remote target
11785
11786On the @value{GDBN} host machine, you will need an unstripped copy of
11787your program, since @value{GDBN} needs symobl and debugging information.
11788Start up @value{GDBN} as usual, using the name of the local copy of your
11789program as the first argument.
11790
11791@cindex serial line, @code{target remote}
11792If you're using a serial line, you may want to give @value{GDBN} the
11793@w{@samp{--baud}} option, or use the @code{set remotebaud} command
9c16f35a
EZ
11794(@pxref{Remote configuration, set remotebaud}) before the
11795@code{target} command.
07f31aa6
DJ
11796
11797After that, use @code{target remote} to establish communications with
11798the target machine. Its argument specifies how to communicate---either
11799via a devicename attached to a direct serial line, or a TCP or UDP port
11800(possibly to a terminal server which in turn has a serial line to the
11801target). For example, to use a serial line connected to the device
11802named @file{/dev/ttyb}:
11803
11804@smallexample
11805target remote /dev/ttyb
11806@end smallexample
11807
11808@cindex TCP port, @code{target remote}
11809To use a TCP connection, use an argument of the form
11810@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
11811For example, to connect to port 2828 on a
11812terminal server named @code{manyfarms}:
11813
11814@smallexample
11815target remote manyfarms:2828
11816@end smallexample
11817
11818If your remote target is actually running on the same machine as
11819your debugger session (e.g.@: a simulator of your target running on
11820the same host), you can omit the hostname. For example, to connect
11821to port 1234 on your local machine:
11822
11823@smallexample
11824target remote :1234
11825@end smallexample
11826@noindent
11827
11828Note that the colon is still required here.
11829
11830@cindex UDP port, @code{target remote}
11831To use a UDP connection, use an argument of the form
11832@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
11833on a terminal server named @code{manyfarms}:
11834
11835@smallexample
11836target remote udp:manyfarms:2828
11837@end smallexample
11838
11839When using a UDP connection for remote debugging, you should keep in mind
11840that the `U' stands for ``Unreliable''. UDP can silently drop packets on
11841busy or unreliable networks, which will cause havoc with your debugging
11842session.
11843
11844Now you can use all the usual commands to examine and change data and to
11845step and continue the remote program.
11846
11847@cindex interrupting remote programs
11848@cindex remote programs, interrupting
11849Whenever @value{GDBN} is waiting for the remote program, if you type the
11850interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
11851program. This may or may not succeed, depending in part on the hardware
11852and the serial drivers the remote system uses. If you type the
11853interrupt character once again, @value{GDBN} displays this prompt:
11854
11855@smallexample
11856Interrupted while waiting for the program.
11857Give up (and stop debugging it)? (y or n)
11858@end smallexample
11859
11860If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
11861(If you decide you want to try again later, you can use @samp{target
11862remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
11863goes back to waiting.
11864
11865@table @code
11866@kindex detach (remote)
11867@item detach
11868When you have finished debugging the remote program, you can use the
11869@code{detach} command to release it from @value{GDBN} control.
11870Detaching from the target normally resumes its execution, but the results
11871will depend on your particular remote stub. After the @code{detach}
11872command, @value{GDBN} is free to connect to another target.
11873
11874@kindex disconnect
11875@item disconnect
11876The @code{disconnect} command behaves like @code{detach}, except that
11877the target is generally not resumed. It will wait for @value{GDBN}
11878(this instance or another one) to connect and continue debugging. After
11879the @code{disconnect} command, @value{GDBN} is again free to connect to
11880another target.
09d4efe1
EZ
11881
11882@cindex send command to remote monitor
11883@kindex monitor
11884@item monitor @var{cmd}
11885This command allows you to send commands directly to the remote
11886monitor.
07f31aa6
DJ
11887@end table
11888
6f05cf9f
AC
11889@node Server
11890@section Using the @code{gdbserver} program
11891
11892@kindex gdbserver
11893@cindex remote connection without stubs
11894@code{gdbserver} is a control program for Unix-like systems, which
11895allows you to connect your program with a remote @value{GDBN} via
11896@code{target remote}---but without linking in the usual debugging stub.
11897
11898@code{gdbserver} is not a complete replacement for the debugging stubs,
11899because it requires essentially the same operating-system facilities
11900that @value{GDBN} itself does. In fact, a system that can run
11901@code{gdbserver} to connect to a remote @value{GDBN} could also run
11902@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
11903because it is a much smaller program than @value{GDBN} itself. It is
11904also easier to port than all of @value{GDBN}, so you may be able to get
11905started more quickly on a new system by using @code{gdbserver}.
11906Finally, if you develop code for real-time systems, you may find that
11907the tradeoffs involved in real-time operation make it more convenient to
11908do as much development work as possible on another system, for example
11909by cross-compiling. You can use @code{gdbserver} to make a similar
11910choice for debugging.
11911
11912@value{GDBN} and @code{gdbserver} communicate via either a serial line
11913or a TCP connection, using the standard @value{GDBN} remote serial
11914protocol.
11915
11916@table @emph
11917@item On the target machine,
11918you need to have a copy of the program you want to debug.
11919@code{gdbserver} does not need your program's symbol table, so you can
11920strip the program if necessary to save space. @value{GDBN} on the host
11921system does all the symbol handling.
11922
11923To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 11924the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
11925syntax is:
11926
11927@smallexample
11928target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
11929@end smallexample
11930
11931@var{comm} is either a device name (to use a serial line) or a TCP
11932hostname and portnumber. For example, to debug Emacs with the argument
11933@samp{foo.txt} and communicate with @value{GDBN} over the serial port
11934@file{/dev/com1}:
11935
11936@smallexample
11937target> gdbserver /dev/com1 emacs foo.txt
11938@end smallexample
11939
11940@code{gdbserver} waits passively for the host @value{GDBN} to communicate
11941with it.
11942
11943To use a TCP connection instead of a serial line:
11944
11945@smallexample
11946target> gdbserver host:2345 emacs foo.txt
11947@end smallexample
11948
11949The only difference from the previous example is the first argument,
11950specifying that you are communicating with the host @value{GDBN} via
11951TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
11952expect a TCP connection from machine @samp{host} to local TCP port 2345.
11953(Currently, the @samp{host} part is ignored.) You can choose any number
11954you want for the port number as long as it does not conflict with any
11955TCP ports already in use on the target system (for example, @code{23} is
11956reserved for @code{telnet}).@footnote{If you choose a port number that
11957conflicts with another service, @code{gdbserver} prints an error message
11958and exits.} You must use the same port number with the host @value{GDBN}
11959@code{target remote} command.
11960
56460a61
DJ
11961On some targets, @code{gdbserver} can also attach to running programs.
11962This is accomplished via the @code{--attach} argument. The syntax is:
11963
11964@smallexample
11965target> gdbserver @var{comm} --attach @var{pid}
11966@end smallexample
11967
11968@var{pid} is the process ID of a currently running process. It isn't necessary
11969to point @code{gdbserver} at a binary for the running process.
11970
b1fe9455
DJ
11971@pindex pidof
11972@cindex attach to a program by name
11973You can debug processes by name instead of process ID if your target has the
11974@code{pidof} utility:
11975
11976@smallexample
11977target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
11978@end smallexample
11979
11980In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
11981has multiple threads, most versions of @code{pidof} support the
11982@code{-s} option to only return the first process ID.
11983
07f31aa6
DJ
11984@item On the host machine,
11985connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
11986For TCP connections, you must start up @code{gdbserver} prior to using
11987the @code{target remote} command. Otherwise you may get an error whose
11988text depends on the host system, but which usually looks something like
07f31aa6 11989@samp{Connection refused}. You don't need to use the @code{load}
397ca115
EZ
11990command in @value{GDBN} when using @code{gdbserver}, since the program is
11991already on the target. However, if you want to load the symbols (as
11992you normally would), do that with the @code{file} command, and issue
11993it @emph{before} connecting to the server; otherwise, you will get an
11994error message saying @code{"Program is already running"}, since the
11995program is considered running after the connection.
07f31aa6 11996
6f05cf9f
AC
11997@end table
11998
11999@node NetWare
12000@section Using the @code{gdbserve.nlm} program
12001
12002@kindex gdbserve.nlm
12003@code{gdbserve.nlm} is a control program for NetWare systems, which
12004allows you to connect your program with a remote @value{GDBN} via
12005@code{target remote}.
12006
12007@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
12008using the standard @value{GDBN} remote serial protocol.
12009
12010@table @emph
12011@item On the target machine,
12012you need to have a copy of the program you want to debug.
12013@code{gdbserve.nlm} does not need your program's symbol table, so you
12014can strip the program if necessary to save space. @value{GDBN} on the
12015host system does all the symbol handling.
12016
12017To use the server, you must tell it how to communicate with
12018@value{GDBN}; the name of your program; and the arguments for your
12019program. The syntax is:
12020
12021@smallexample
12022load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
12023 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
12024@end smallexample
12025
12026@var{board} and @var{port} specify the serial line; @var{baud} specifies
12027the baud rate used by the connection. @var{port} and @var{node} default
12028to 0, @var{baud} defaults to 9600@dmn{bps}.
12029
12030For example, to debug Emacs with the argument @samp{foo.txt}and
12031communicate with @value{GDBN} over serial port number 2 or board 1
12032using a 19200@dmn{bps} connection:
12033
12034@smallexample
12035load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
12036@end smallexample
12037
07f31aa6
DJ
12038@item
12039On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
12040Connecting to a remote target}).
6f05cf9f 12041
6f05cf9f
AC
12042@end table
12043
501eef12
AC
12044@node Remote configuration
12045@section Remote configuration
12046
9c16f35a
EZ
12047@kindex set remote
12048@kindex show remote
12049This section documents the configuration options available when
12050debugging remote programs. For the options related to the File I/O
12051extensions of the remote protocol, see @ref{The system call,
12052system-call-allowed}.
501eef12
AC
12053
12054@table @code
9c16f35a
EZ
12055@item set remoteaddresssize @var{bits}
12056@cindex adress size for remote targets
12057@cindex bits in remote address
12058Set the maximum size of address in a memory packet to the specified
12059number of bits. @value{GDBN} will mask off the address bits above
12060that number, when it passes addresses to the remote target. The
12061default value is the number of bits in the target's address.
12062
12063@item show remoteaddresssize
12064Show the current value of remote address size in bits.
12065
12066@item set remotebaud @var{n}
12067@cindex baud rate for remote targets
12068Set the baud rate for the remote serial I/O to @var{n} baud. The
12069value is used to set the speed of the serial port used for debugging
12070remote targets.
12071
12072@item show remotebaud
12073Show the current speed of the remote connection.
12074
12075@item set remotebreak
12076@cindex interrupt remote programs
12077@cindex BREAK signal instead of Ctrl-C
12078If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
12079when you press the @key{Ctrl-C} key to interrupt the program running
12080on the remote. If set to off, @value{GDBN} sends the @samp{Strl-C}
12081character instead. The default is off, since most remote systems
12082expect to see @samp{Ctrl-C} as the interrupt signal.
12083
12084@item show remotebreak
12085Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
12086interrupt the remote program.
12087
12088@item set remotedebug
12089@cindex debug remote protocol
12090@cindex remote protocol debugging
12091@cindex display remote packets
12092Control the debugging of the remote protocol. When enabled, each
12093packet sent to or received from the remote target is displayed. The
12094defaults is off.
12095
12096@item show remotedebug
12097Show the current setting of the remote protocol debugging.
12098
12099@item set remotedevice @var{device}
12100@cindex serial port name
12101Set the name of the serial port through which to communicate to the
12102remote target to @var{device}. This is the device used by
12103@value{GDBN} to open the serial communications line to the remote
12104target. There's no default, so you must set a valid port name for the
12105remote serial communications to work. (Some varieties of the
12106@code{target} command accept the port name as part of their
12107arguments.)
12108
12109@item show remotedevice
12110Show the current name of the serial port.
12111
12112@item set remotelogbase @var{base}
12113Set the base (a.k.a.@: radix) of logging serial protocol
12114communications to @var{base}. Supported values of @var{base} are:
12115@code{ascii}, @code{octal}, and @code{hex}. The default is
12116@code{ascii}.
12117
12118@item show remotelogbase
12119Show the current setting of the radix for logging remote serial
12120protocol.
12121
12122@item set remotelogfile @var{file}
12123@cindex record serial communications on file
12124Record remote serial communications on the named @var{file}. The
12125default is not to record at all.
12126
12127@item show remotelogfile.
12128Show the current setting of the file name on which to record the
12129serial communications.
12130
12131@item set remotetimeout @var{num}
12132@cindex timeout for serial communications
12133@cindex remote timeout
12134Set the timeout limit to wait for the remote target to respond to
12135@var{num} seconds. The default is 2 seconds.
12136
12137@item show remotetimeout
12138Show the current number of seconds to wait for the remote target
12139responses.
12140
12141@cindex limit hardware breakpoints and watchpoints
12142@cindex remote target, limit break- and watchpoints
501eef12
AC
12143@anchor{set remote hardware-watchpoint-limit}
12144@anchor{set remote hardware-breakpoint-limit}
12145@item set remote hardware-watchpoint-limit @var{limit}
12146@itemx set remote hardware-breakpoint-limit @var{limit}
12147Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
12148watchpoints. A limit of -1, the default, is treated as unlimited.
9c16f35a
EZ
12149
12150@item set remote fetch-register-packet
12151@itemx set remote set-register-packet
12152@itemx set remote P-packet
12153@itemx set remote p-packet
12154@cindex P-packet
12155@cindex fetch registers from remote targets
12156@cindex set registers in remote targets
12157Determine whether @value{GDBN} can set and fetch registers from the
12158remote target using the @samp{P} packets. The default depends on the
12159remote stub's support of the @samp{P} packets (@value{GDBN} queries
12160the stub when this packet is first required).
12161
12162@item show remote fetch-register-packet
12163@itemx show remote set-register-packet
12164@itemx show remote P-packet
12165@itemx show remote p-packet
12166Show the current setting of using the @samp{P} packets for setting and
12167fetching registers from the remote target.
12168
12169@cindex binary downloads
12170@cindex X-packet
12171@item set remote binary-download-packet
12172@itemx set remote X-packet
12173Determine whether @value{GDBN} sends downloads in binary mode using
12174the @samp{X} packets. The default is on.
12175
12176@item show remote binary-download-packet
12177@itemx show remote X-packet
12178Show the current setting of using the @samp{X} packets for binary
12179downloads.
12180
12181@item set remote read-aux-vector-packet
12182@cindex auxiliary vector of remote target
12183@cindex @code{auxv}, and remote targets
12184Set the use of the remote protocol's @samp{qPart:auxv:read} (target
12185auxiliary vector read) request. This request is used to fetch the
721c2651
EZ
12186remote target's @dfn{auxiliary vector}, see @ref{OS Information,
12187Auxiliary Vector}. The default setting depends on the remote stub's
12188support of this request (@value{GDBN} queries the stub when this
12189request is first required). @xref{General Query Packets, qPart}, for
12190more information about this request.
9c16f35a
EZ
12191
12192@item show remote read-aux-vector-packet
12193Show the current setting of use of the @samp{qPart:auxv:read} request.
12194
12195@item set remote symbol-lookup-packet
12196@cindex remote symbol lookup request
12197Set the use of the remote protocol's @samp{qSymbol} (target symbol
12198lookup) request. This request is used to communicate symbol
12199information to the remote target, e.g., whenever a new shared library
12200is loaded by the remote (@pxref{Files, shared libraries}). The
12201default setting depends on the remote stub's support of this request
12202(@value{GDBN} queries the stub when this request is first required).
12203@xref{General Query Packets, qSymbol}, for more information about this
12204request.
12205
12206@item show remote symbol-lookup-packet
12207Show the current setting of use of the @samp{qSymbol} request.
12208
12209@item set remote verbose-resume-packet
12210@cindex resume remote target
12211@cindex signal thread, and remote targets
12212@cindex single-step thread, and remote targets
12213@cindex thread-specific operations on remote targets
12214Set the use of the remote protocol's @samp{vCont} (descriptive resume)
12215request. This request is used to resume specific threads in the
12216remote target, and to single-step or signal them. The default setting
12217depends on the remote stub's support of this request (@value{GDBN}
12218queries the stub when this request is first required). This setting
12219affects debugging of multithreaded programs: if @samp{vCont} cannot be
12220used, @value{GDBN} might be unable to single-step a specific thread,
12221especially under @code{set scheduler-locking off}; it is also
12222impossible to pause a specific thread. @xref{Packets, vCont}, for
12223more details.
12224
12225@item show remote verbose-resume-packet
12226Show the current setting of use of the @samp{vCont} request
12227
12228@item set remote software-breakpoint-packet
12229@itemx set remote hardware-breakpoint-packet
12230@itemx set remote write-watchpoint-packet
12231@itemx set remote read-watchpoint-packet
12232@itemx set remote access-watchpoint-packet
12233@itemx set remote Z-packet
12234@cindex Z-packet
12235@cindex remote hardware breakpoints and watchpoints
12236These commands enable or disable the use of @samp{Z} packets for
12237setting breakpoints and watchpoints in the remote target. The default
12238depends on the remote stub's support of the @samp{Z} packets
12239(@value{GDBN} queries the stub when each packet is first required).
12240The command @code{set remote Z-packet}, kept for back-compatibility,
12241turns on or off all the features that require the use of @samp{Z}
12242packets.
12243
12244@item show remote software-breakpoint-packet
12245@itemx show remote hardware-breakpoint-packet
12246@itemx show remote write-watchpoint-packet
12247@itemx show remote read-watchpoint-packet
12248@itemx show remote access-watchpoint-packet
12249@itemx show remote Z-packet
12250Show the current setting of @samp{Z} packets usage.
0abb7bc7
EZ
12251
12252@item set remote get-thread-local-storage-address
12253@kindex set remote get-thread-local-storage-address
12254@cindex thread local storage of remote targets
12255This command enables or disables the use of the @samp{qGetTLSAddr}
12256(Get Thread Local Storage Address) request packet. The default
12257depends on whether the remote stub supports this request.
12258@xref{General Query Packets, qGetTLSAddr}, for more details about this
12259packet.
12260
12261@item show remote get-thread-local-storage-address
12262@kindex show remote get-thread-local-storage-address
12263Show the current setting of @samp{qGetTLSAddr} packet usage.
501eef12
AC
12264@end table
12265
6f05cf9f
AC
12266@node remote stub
12267@section Implementing a remote stub
7a292a7a 12268
8e04817f
AC
12269@cindex debugging stub, example
12270@cindex remote stub, example
12271@cindex stub example, remote debugging
12272The stub files provided with @value{GDBN} implement the target side of the
12273communication protocol, and the @value{GDBN} side is implemented in the
12274@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
12275these subroutines to communicate, and ignore the details. (If you're
12276implementing your own stub file, you can still ignore the details: start
12277with one of the existing stub files. @file{sparc-stub.c} is the best
12278organized, and therefore the easiest to read.)
12279
104c1213
JM
12280@cindex remote serial debugging, overview
12281To debug a program running on another machine (the debugging
12282@dfn{target} machine), you must first arrange for all the usual
12283prerequisites for the program to run by itself. For example, for a C
12284program, you need:
c906108c 12285
104c1213
JM
12286@enumerate
12287@item
12288A startup routine to set up the C runtime environment; these usually
12289have a name like @file{crt0}. The startup routine may be supplied by
12290your hardware supplier, or you may have to write your own.
96baa820 12291
5d161b24 12292@item
d4f3574e 12293A C subroutine library to support your program's
104c1213 12294subroutine calls, notably managing input and output.
96baa820 12295
104c1213
JM
12296@item
12297A way of getting your program to the other machine---for example, a
12298download program. These are often supplied by the hardware
12299manufacturer, but you may have to write your own from hardware
12300documentation.
12301@end enumerate
96baa820 12302
104c1213
JM
12303The next step is to arrange for your program to use a serial port to
12304communicate with the machine where @value{GDBN} is running (the @dfn{host}
12305machine). In general terms, the scheme looks like this:
96baa820 12306
104c1213
JM
12307@table @emph
12308@item On the host,
12309@value{GDBN} already understands how to use this protocol; when everything
12310else is set up, you can simply use the @samp{target remote} command
12311(@pxref{Targets,,Specifying a Debugging Target}).
12312
12313@item On the target,
12314you must link with your program a few special-purpose subroutines that
12315implement the @value{GDBN} remote serial protocol. The file containing these
12316subroutines is called a @dfn{debugging stub}.
12317
12318On certain remote targets, you can use an auxiliary program
12319@code{gdbserver} instead of linking a stub into your program.
12320@xref{Server,,Using the @code{gdbserver} program}, for details.
12321@end table
96baa820 12322
104c1213
JM
12323The debugging stub is specific to the architecture of the remote
12324machine; for example, use @file{sparc-stub.c} to debug programs on
12325@sc{sparc} boards.
96baa820 12326
104c1213
JM
12327@cindex remote serial stub list
12328These working remote stubs are distributed with @value{GDBN}:
96baa820 12329
104c1213
JM
12330@table @code
12331
12332@item i386-stub.c
41afff9a 12333@cindex @file{i386-stub.c}
104c1213
JM
12334@cindex Intel
12335@cindex i386
12336For Intel 386 and compatible architectures.
12337
12338@item m68k-stub.c
41afff9a 12339@cindex @file{m68k-stub.c}
104c1213
JM
12340@cindex Motorola 680x0
12341@cindex m680x0
12342For Motorola 680x0 architectures.
12343
12344@item sh-stub.c
41afff9a 12345@cindex @file{sh-stub.c}
172c2a43 12346@cindex Renesas
104c1213 12347@cindex SH
172c2a43 12348For Renesas SH architectures.
104c1213
JM
12349
12350@item sparc-stub.c
41afff9a 12351@cindex @file{sparc-stub.c}
104c1213
JM
12352@cindex Sparc
12353For @sc{sparc} architectures.
12354
12355@item sparcl-stub.c
41afff9a 12356@cindex @file{sparcl-stub.c}
104c1213
JM
12357@cindex Fujitsu
12358@cindex SparcLite
12359For Fujitsu @sc{sparclite} architectures.
12360
12361@end table
12362
12363The @file{README} file in the @value{GDBN} distribution may list other
12364recently added stubs.
12365
12366@menu
12367* Stub Contents:: What the stub can do for you
12368* Bootstrapping:: What you must do for the stub
12369* Debug Session:: Putting it all together
104c1213
JM
12370@end menu
12371
6d2ebf8b 12372@node Stub Contents
6f05cf9f 12373@subsection What the stub can do for you
104c1213
JM
12374
12375@cindex remote serial stub
12376The debugging stub for your architecture supplies these three
12377subroutines:
12378
12379@table @code
12380@item set_debug_traps
4644b6e3 12381@findex set_debug_traps
104c1213
JM
12382@cindex remote serial stub, initialization
12383This routine arranges for @code{handle_exception} to run when your
12384program stops. You must call this subroutine explicitly near the
12385beginning of your program.
12386
12387@item handle_exception
4644b6e3 12388@findex handle_exception
104c1213
JM
12389@cindex remote serial stub, main routine
12390This is the central workhorse, but your program never calls it
12391explicitly---the setup code arranges for @code{handle_exception} to
12392run when a trap is triggered.
12393
12394@code{handle_exception} takes control when your program stops during
12395execution (for example, on a breakpoint), and mediates communications
12396with @value{GDBN} on the host machine. This is where the communications
12397protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 12398representative on the target machine. It begins by sending summary
104c1213
JM
12399information on the state of your program, then continues to execute,
12400retrieving and transmitting any information @value{GDBN} needs, until you
12401execute a @value{GDBN} command that makes your program resume; at that point,
12402@code{handle_exception} returns control to your own code on the target
5d161b24 12403machine.
104c1213
JM
12404
12405@item breakpoint
12406@cindex @code{breakpoint} subroutine, remote
12407Use this auxiliary subroutine to make your program contain a
12408breakpoint. Depending on the particular situation, this may be the only
12409way for @value{GDBN} to get control. For instance, if your target
12410machine has some sort of interrupt button, you won't need to call this;
12411pressing the interrupt button transfers control to
12412@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
12413simply receiving characters on the serial port may also trigger a trap;
12414again, in that situation, you don't need to call @code{breakpoint} from
12415your own program---simply running @samp{target remote} from the host
5d161b24 12416@value{GDBN} session gets control.
104c1213
JM
12417
12418Call @code{breakpoint} if none of these is true, or if you simply want
12419to make certain your program stops at a predetermined point for the
12420start of your debugging session.
12421@end table
12422
6d2ebf8b 12423@node Bootstrapping
6f05cf9f 12424@subsection What you must do for the stub
104c1213
JM
12425
12426@cindex remote stub, support routines
12427The debugging stubs that come with @value{GDBN} are set up for a particular
12428chip architecture, but they have no information about the rest of your
12429debugging target machine.
12430
12431First of all you need to tell the stub how to communicate with the
12432serial port.
12433
12434@table @code
12435@item int getDebugChar()
4644b6e3 12436@findex getDebugChar
104c1213
JM
12437Write this subroutine to read a single character from the serial port.
12438It may be identical to @code{getchar} for your target system; a
12439different name is used to allow you to distinguish the two if you wish.
12440
12441@item void putDebugChar(int)
4644b6e3 12442@findex putDebugChar
104c1213 12443Write this subroutine to write a single character to the serial port.
5d161b24 12444It may be identical to @code{putchar} for your target system; a
104c1213
JM
12445different name is used to allow you to distinguish the two if you wish.
12446@end table
12447
12448@cindex control C, and remote debugging
12449@cindex interrupting remote targets
12450If you want @value{GDBN} to be able to stop your program while it is
12451running, you need to use an interrupt-driven serial driver, and arrange
12452for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
12453character). That is the character which @value{GDBN} uses to tell the
12454remote system to stop.
12455
12456Getting the debugging target to return the proper status to @value{GDBN}
12457probably requires changes to the standard stub; one quick and dirty way
12458is to just execute a breakpoint instruction (the ``dirty'' part is that
12459@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
12460
12461Other routines you need to supply are:
12462
12463@table @code
12464@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 12465@findex exceptionHandler
104c1213
JM
12466Write this function to install @var{exception_address} in the exception
12467handling tables. You need to do this because the stub does not have any
12468way of knowing what the exception handling tables on your target system
12469are like (for example, the processor's table might be in @sc{rom},
12470containing entries which point to a table in @sc{ram}).
12471@var{exception_number} is the exception number which should be changed;
12472its meaning is architecture-dependent (for example, different numbers
12473might represent divide by zero, misaligned access, etc). When this
12474exception occurs, control should be transferred directly to
12475@var{exception_address}, and the processor state (stack, registers,
12476and so on) should be just as it is when a processor exception occurs. So if
12477you want to use a jump instruction to reach @var{exception_address}, it
12478should be a simple jump, not a jump to subroutine.
12479
12480For the 386, @var{exception_address} should be installed as an interrupt
12481gate so that interrupts are masked while the handler runs. The gate
12482should be at privilege level 0 (the most privileged level). The
12483@sc{sparc} and 68k stubs are able to mask interrupts themselves without
12484help from @code{exceptionHandler}.
12485
12486@item void flush_i_cache()
4644b6e3 12487@findex flush_i_cache
d4f3574e 12488On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
12489instruction cache, if any, on your target machine. If there is no
12490instruction cache, this subroutine may be a no-op.
12491
12492On target machines that have instruction caches, @value{GDBN} requires this
12493function to make certain that the state of your program is stable.
12494@end table
12495
12496@noindent
12497You must also make sure this library routine is available:
12498
12499@table @code
12500@item void *memset(void *, int, int)
4644b6e3 12501@findex memset
104c1213
JM
12502This is the standard library function @code{memset} that sets an area of
12503memory to a known value. If you have one of the free versions of
12504@code{libc.a}, @code{memset} can be found there; otherwise, you must
12505either obtain it from your hardware manufacturer, or write your own.
12506@end table
12507
12508If you do not use the GNU C compiler, you may need other standard
12509library subroutines as well; this varies from one stub to another,
12510but in general the stubs are likely to use any of the common library
d4f3574e 12511subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
12512
12513
6d2ebf8b 12514@node Debug Session
6f05cf9f 12515@subsection Putting it all together
104c1213
JM
12516
12517@cindex remote serial debugging summary
12518In summary, when your program is ready to debug, you must follow these
12519steps.
12520
12521@enumerate
12522@item
6d2ebf8b 12523Make sure you have defined the supporting low-level routines
104c1213
JM
12524(@pxref{Bootstrapping,,What you must do for the stub}):
12525@display
12526@code{getDebugChar}, @code{putDebugChar},
12527@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
12528@end display
12529
12530@item
12531Insert these lines near the top of your program:
12532
474c8240 12533@smallexample
104c1213
JM
12534set_debug_traps();
12535breakpoint();
474c8240 12536@end smallexample
104c1213
JM
12537
12538@item
12539For the 680x0 stub only, you need to provide a variable called
12540@code{exceptionHook}. Normally you just use:
12541
474c8240 12542@smallexample
104c1213 12543void (*exceptionHook)() = 0;
474c8240 12544@end smallexample
104c1213 12545
d4f3574e 12546@noindent
104c1213 12547but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 12548function in your program, that function is called when
104c1213
JM
12549@code{@value{GDBN}} continues after stopping on a trap (for example, bus
12550error). The function indicated by @code{exceptionHook} is called with
12551one parameter: an @code{int} which is the exception number.
12552
12553@item
12554Compile and link together: your program, the @value{GDBN} debugging stub for
12555your target architecture, and the supporting subroutines.
12556
12557@item
12558Make sure you have a serial connection between your target machine and
12559the @value{GDBN} host, and identify the serial port on the host.
12560
12561@item
12562@c The "remote" target now provides a `load' command, so we should
12563@c document that. FIXME.
12564Download your program to your target machine (or get it there by
12565whatever means the manufacturer provides), and start it.
12566
12567@item
07f31aa6
DJ
12568Start @value{GDBN} on the host, and connect to the target
12569(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 12570
104c1213
JM
12571@end enumerate
12572
8e04817f
AC
12573@node Configurations
12574@chapter Configuration-Specific Information
104c1213 12575
8e04817f
AC
12576While nearly all @value{GDBN} commands are available for all native and
12577cross versions of the debugger, there are some exceptions. This chapter
12578describes things that are only available in certain configurations.
104c1213 12579
8e04817f
AC
12580There are three major categories of configurations: native
12581configurations, where the host and target are the same, embedded
12582operating system configurations, which are usually the same for several
12583different processor architectures, and bare embedded processors, which
12584are quite different from each other.
104c1213 12585
8e04817f
AC
12586@menu
12587* Native::
12588* Embedded OS::
12589* Embedded Processors::
12590* Architectures::
12591@end menu
104c1213 12592
8e04817f
AC
12593@node Native
12594@section Native
104c1213 12595
8e04817f
AC
12596This section describes details specific to particular native
12597configurations.
6cf7e474 12598
8e04817f
AC
12599@menu
12600* HP-UX:: HP-UX
7561d450 12601* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
12602* SVR4 Process Information:: SVR4 process information
12603* DJGPP Native:: Features specific to the DJGPP port
78c47bea 12604* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 12605* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 12606* Neutrino:: Features specific to QNX Neutrino
8e04817f 12607@end menu
6cf7e474 12608
8e04817f
AC
12609@node HP-UX
12610@subsection HP-UX
104c1213 12611
8e04817f
AC
12612On HP-UX systems, if you refer to a function or variable name that
12613begins with a dollar sign, @value{GDBN} searches for a user or system
12614name first, before it searches for a convenience variable.
104c1213 12615
9c16f35a 12616
7561d450
MK
12617@node BSD libkvm Interface
12618@subsection BSD libkvm Interface
12619
12620@cindex libkvm
12621@cindex kernel memory image
12622@cindex kernel crash dump
12623
12624BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
12625interface that provides a uniform interface for accessing kernel virtual
12626memory images, including live systems and crash dumps. @value{GDBN}
12627uses this interface to allow you to debug live kernels and kernel crash
12628dumps on many native BSD configurations. This is implemented as a
12629special @code{kvm} debugging target. For debugging a live system, load
12630the currently running kernel into @value{GDBN} and connect to the
12631@code{kvm} target:
12632
12633@smallexample
12634(@value{GDBP}) @b{target kvm}
12635@end smallexample
12636
12637For debugging crash dumps, provide the file name of the crash dump as an
12638argument:
12639
12640@smallexample
12641(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
12642@end smallexample
12643
12644Once connected to the @code{kvm} target, the following commands are
12645available:
12646
12647@table @code
12648@kindex kvm
12649@item kvm pcb
721c2651 12650Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
12651
12652@item kvm proc
12653Set current context from proc address. This command isn't available on
12654modern FreeBSD systems.
12655@end table
12656
8e04817f
AC
12657@node SVR4 Process Information
12658@subsection SVR4 process information
60bf7e09
EZ
12659@cindex /proc
12660@cindex examine process image
12661@cindex process info via @file{/proc}
104c1213 12662
60bf7e09
EZ
12663Many versions of SVR4 and compatible systems provide a facility called
12664@samp{/proc} that can be used to examine the image of a running
12665process using file-system subroutines. If @value{GDBN} is configured
12666for an operating system with this facility, the command @code{info
12667proc} is available to report information about the process running
12668your program, or about any process running on your system. @code{info
12669proc} works only on SVR4 systems that include the @code{procfs} code.
12670This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
12671Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 12672
8e04817f
AC
12673@table @code
12674@kindex info proc
60bf7e09 12675@cindex process ID
8e04817f 12676@item info proc
60bf7e09
EZ
12677@itemx info proc @var{process-id}
12678Summarize available information about any running process. If a
12679process ID is specified by @var{process-id}, display information about
12680that process; otherwise display information about the program being
12681debugged. The summary includes the debugged process ID, the command
12682line used to invoke it, its current working directory, and its
12683executable file's absolute file name.
12684
12685On some systems, @var{process-id} can be of the form
12686@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
12687within a process. If the optional @var{pid} part is missing, it means
12688a thread from the process being debugged (the leading @samp{/} still
12689needs to be present, or else @value{GDBN} will interpret the number as
12690a process ID rather than a thread ID).
6cf7e474 12691
8e04817f 12692@item info proc mappings
60bf7e09
EZ
12693@cindex memory address space mappings
12694Report the memory address space ranges accessible in the program, with
12695information on whether the process has read, write, or execute access
12696rights to each range. On @sc{gnu}/Linux systems, each memory range
12697includes the object file which is mapped to that range, instead of the
12698memory access rights to that range.
12699
12700@item info proc stat
12701@itemx info proc status
12702@cindex process detailed status information
12703These subcommands are specific to @sc{gnu}/Linux systems. They show
12704the process-related information, including the user ID and group ID;
12705how many threads are there in the process; its virtual memory usage;
12706the signals that are pending, blocked, and ignored; its TTY; its
12707consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 12708value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
12709(type @kbd{man 5 proc} from your shell prompt).
12710
12711@item info proc all
12712Show all the information about the process described under all of the
12713above @code{info proc} subcommands.
12714
8e04817f
AC
12715@ignore
12716@comment These sub-options of 'info proc' were not included when
12717@comment procfs.c was re-written. Keep their descriptions around
12718@comment against the day when someone finds the time to put them back in.
12719@kindex info proc times
12720@item info proc times
12721Starting time, user CPU time, and system CPU time for your program and
12722its children.
6cf7e474 12723
8e04817f
AC
12724@kindex info proc id
12725@item info proc id
12726Report on the process IDs related to your program: its own process ID,
12727the ID of its parent, the process group ID, and the session ID.
8e04817f 12728@end ignore
721c2651
EZ
12729
12730@item set procfs-trace
12731@kindex set procfs-trace
12732@cindex @code{procfs} API calls
12733This command enables and disables tracing of @code{procfs} API calls.
12734
12735@item show procfs-trace
12736@kindex show procfs-trace
12737Show the current state of @code{procfs} API call tracing.
12738
12739@item set procfs-file @var{file}
12740@kindex set procfs-file
12741Tell @value{GDBN} to write @code{procfs} API trace to the named
12742@var{file}. @value{GDBN} appends the trace info to the previous
12743contents of the file. The default is to display the trace on the
12744standard output.
12745
12746@item show procfs-file
12747@kindex show procfs-file
12748Show the file to which @code{procfs} API trace is written.
12749
12750@item proc-trace-entry
12751@itemx proc-trace-exit
12752@itemx proc-untrace-entry
12753@itemx proc-untrace-exit
12754@kindex proc-trace-entry
12755@kindex proc-trace-exit
12756@kindex proc-untrace-entry
12757@kindex proc-untrace-exit
12758These commands enable and disable tracing of entries into and exits
12759from the @code{syscall} interface.
12760
12761@item info pidlist
12762@kindex info pidlist
12763@cindex process list, QNX Neutrino
12764For QNX Neutrino only, this command displays the list of all the
12765processes and all the threads within each process.
12766
12767@item info meminfo
12768@kindex info meminfo
12769@cindex mapinfo list, QNX Neutrino
12770For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 12771@end table
104c1213 12772
8e04817f
AC
12773@node DJGPP Native
12774@subsection Features for Debugging @sc{djgpp} Programs
12775@cindex @sc{djgpp} debugging
12776@cindex native @sc{djgpp} debugging
12777@cindex MS-DOS-specific commands
104c1213 12778
514c4d71
EZ
12779@cindex DPMI
12780@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
12781MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
12782that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
12783top of real-mode DOS systems and their emulations.
104c1213 12784
8e04817f
AC
12785@value{GDBN} supports native debugging of @sc{djgpp} programs, and
12786defines a few commands specific to the @sc{djgpp} port. This
12787subsection describes those commands.
104c1213 12788
8e04817f
AC
12789@table @code
12790@kindex info dos
12791@item info dos
12792This is a prefix of @sc{djgpp}-specific commands which print
12793information about the target system and important OS structures.
f1251bdd 12794
8e04817f
AC
12795@kindex sysinfo
12796@cindex MS-DOS system info
12797@cindex free memory information (MS-DOS)
12798@item info dos sysinfo
12799This command displays assorted information about the underlying
12800platform: the CPU type and features, the OS version and flavor, the
12801DPMI version, and the available conventional and DPMI memory.
104c1213 12802
8e04817f
AC
12803@cindex GDT
12804@cindex LDT
12805@cindex IDT
12806@cindex segment descriptor tables
12807@cindex descriptor tables display
12808@item info dos gdt
12809@itemx info dos ldt
12810@itemx info dos idt
12811These 3 commands display entries from, respectively, Global, Local,
12812and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
12813tables are data structures which store a descriptor for each segment
12814that is currently in use. The segment's selector is an index into a
12815descriptor table; the table entry for that index holds the
12816descriptor's base address and limit, and its attributes and access
12817rights.
104c1213 12818
8e04817f
AC
12819A typical @sc{djgpp} program uses 3 segments: a code segment, a data
12820segment (used for both data and the stack), and a DOS segment (which
12821allows access to DOS/BIOS data structures and absolute addresses in
12822conventional memory). However, the DPMI host will usually define
12823additional segments in order to support the DPMI environment.
d4f3574e 12824
8e04817f
AC
12825@cindex garbled pointers
12826These commands allow to display entries from the descriptor tables.
12827Without an argument, all entries from the specified table are
12828displayed. An argument, which should be an integer expression, means
12829display a single entry whose index is given by the argument. For
12830example, here's a convenient way to display information about the
12831debugged program's data segment:
104c1213 12832
8e04817f
AC
12833@smallexample
12834@exdent @code{(@value{GDBP}) info dos ldt $ds}
12835@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
12836@end smallexample
104c1213 12837
8e04817f
AC
12838@noindent
12839This comes in handy when you want to see whether a pointer is outside
12840the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 12841
8e04817f
AC
12842@cindex page tables display (MS-DOS)
12843@item info dos pde
12844@itemx info dos pte
12845These two commands display entries from, respectively, the Page
12846Directory and the Page Tables. Page Directories and Page Tables are
12847data structures which control how virtual memory addresses are mapped
12848into physical addresses. A Page Table includes an entry for every
12849page of memory that is mapped into the program's address space; there
12850may be several Page Tables, each one holding up to 4096 entries. A
12851Page Directory has up to 4096 entries, one each for every Page Table
12852that is currently in use.
104c1213 12853
8e04817f
AC
12854Without an argument, @kbd{info dos pde} displays the entire Page
12855Directory, and @kbd{info dos pte} displays all the entries in all of
12856the Page Tables. An argument, an integer expression, given to the
12857@kbd{info dos pde} command means display only that entry from the Page
12858Directory table. An argument given to the @kbd{info dos pte} command
12859means display entries from a single Page Table, the one pointed to by
12860the specified entry in the Page Directory.
104c1213 12861
8e04817f
AC
12862@cindex direct memory access (DMA) on MS-DOS
12863These commands are useful when your program uses @dfn{DMA} (Direct
12864Memory Access), which needs physical addresses to program the DMA
12865controller.
104c1213 12866
8e04817f 12867These commands are supported only with some DPMI servers.
104c1213 12868
8e04817f
AC
12869@cindex physical address from linear address
12870@item info dos address-pte @var{addr}
12871This command displays the Page Table entry for a specified linear
514c4d71
EZ
12872address. The argument @var{addr} is a linear address which should
12873already have the appropriate segment's base address added to it,
12874because this command accepts addresses which may belong to @emph{any}
12875segment. For example, here's how to display the Page Table entry for
12876the page where a variable @code{i} is stored:
104c1213 12877
b383017d 12878@smallexample
8e04817f
AC
12879@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
12880@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 12881@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 12882@end smallexample
104c1213 12883
8e04817f
AC
12884@noindent
12885This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 12886whose physical base address is @code{0x02698000}, and shows all the
8e04817f 12887attributes of that page.
104c1213 12888
8e04817f
AC
12889Note that you must cast the addresses of variables to a @code{char *},
12890since otherwise the value of @code{__djgpp_base_address}, the base
12891address of all variables and functions in a @sc{djgpp} program, will
12892be added using the rules of C pointer arithmetics: if @code{i} is
12893declared an @code{int}, @value{GDBN} will add 4 times the value of
12894@code{__djgpp_base_address} to the address of @code{i}.
104c1213 12895
8e04817f
AC
12896Here's another example, it displays the Page Table entry for the
12897transfer buffer:
104c1213 12898
8e04817f
AC
12899@smallexample
12900@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
12901@exdent @code{Page Table entry for address 0x29110:}
12902@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
12903@end smallexample
104c1213 12904
8e04817f
AC
12905@noindent
12906(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
129073rd member of the @code{_go32_info_block} structure.) The output
12908clearly shows that this DPMI server maps the addresses in conventional
12909memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
12910linear (@code{0x29110}) addresses are identical.
104c1213 12911
8e04817f
AC
12912This command is supported only with some DPMI servers.
12913@end table
104c1213 12914
c45da7e6 12915@cindex DOS serial data link, remote debugging
a8f24a35
EZ
12916In addition to native debugging, the DJGPP port supports remote
12917debugging via a serial data link. The following commands are specific
12918to remote serial debugging in the DJGPP port of @value{GDBN}.
12919
12920@table @code
12921@kindex set com1base
12922@kindex set com1irq
12923@kindex set com2base
12924@kindex set com2irq
12925@kindex set com3base
12926@kindex set com3irq
12927@kindex set com4base
12928@kindex set com4irq
12929@item set com1base @var{addr}
12930This command sets the base I/O port address of the @file{COM1} serial
12931port.
12932
12933@item set com1irq @var{irq}
12934This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
12935for the @file{COM1} serial port.
12936
12937There are similar commands @samp{set com2base}, @samp{set com3irq},
12938etc.@: for setting the port address and the @code{IRQ} lines for the
12939other 3 COM ports.
12940
12941@kindex show com1base
12942@kindex show com1irq
12943@kindex show com2base
12944@kindex show com2irq
12945@kindex show com3base
12946@kindex show com3irq
12947@kindex show com4base
12948@kindex show com4irq
12949The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
12950display the current settings of the base address and the @code{IRQ}
12951lines used by the COM ports.
c45da7e6
EZ
12952
12953@item info serial
12954@kindex info serial
12955@cindex DOS serial port status
12956This command prints the status of the 4 DOS serial ports. For each
12957port, it prints whether it's active or not, its I/O base address and
12958IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
12959counts of various errors encountered so far.
a8f24a35
EZ
12960@end table
12961
12962
78c47bea
PM
12963@node Cygwin Native
12964@subsection Features for Debugging MS Windows PE executables
12965@cindex MS Windows debugging
12966@cindex native Cygwin debugging
12967@cindex Cygwin-specific commands
12968
be448670
CF
12969@value{GDBN} supports native debugging of MS Windows programs, including
12970DLLs with and without symbolic debugging information. There are various
12971additional Cygwin-specific commands, described in this subsection. The
12972subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
12973that have no debugging symbols.
12974
78c47bea
PM
12975
12976@table @code
12977@kindex info w32
12978@item info w32
12979This is a prefix of MS Windows specific commands which print
12980information about the target system and important OS structures.
12981
12982@item info w32 selector
12983This command displays information returned by
12984the Win32 API @code{GetThreadSelectorEntry} function.
12985It takes an optional argument that is evaluated to
12986a long value to give the information about this given selector.
12987Without argument, this command displays information
12988about the the six segment registers.
12989
12990@kindex info dll
12991@item info dll
12992This is a Cygwin specific alias of info shared.
12993
12994@kindex dll-symbols
12995@item dll-symbols
12996This command loads symbols from a dll similarly to
12997add-sym command but without the need to specify a base address.
12998
b383017d 12999@kindex set new-console
78c47bea 13000@item set new-console @var{mode}
b383017d 13001If @var{mode} is @code{on} the debuggee will
78c47bea
PM
13002be started in a new console on next start.
13003If @var{mode} is @code{off}i, the debuggee will
13004be started in the same console as the debugger.
13005
13006@kindex show new-console
13007@item show new-console
13008Displays whether a new console is used
13009when the debuggee is started.
13010
13011@kindex set new-group
13012@item set new-group @var{mode}
13013This boolean value controls whether the debuggee should
13014start a new group or stay in the same group as the debugger.
13015This affects the way the Windows OS handles
13016Ctrl-C.
13017
13018@kindex show new-group
13019@item show new-group
13020Displays current value of new-group boolean.
13021
13022@kindex set debugevents
13023@item set debugevents
13024This boolean value adds debug output concerning events seen by the debugger.
13025
13026@kindex set debugexec
13027@item set debugexec
b383017d 13028This boolean value adds debug output concerning execute events
78c47bea
PM
13029seen by the debugger.
13030
13031@kindex set debugexceptions
13032@item set debugexceptions
b383017d 13033This boolean value adds debug ouptut concerning exception events
78c47bea
PM
13034seen by the debugger.
13035
13036@kindex set debugmemory
13037@item set debugmemory
b383017d 13038This boolean value adds debug ouptut concerning memory events
78c47bea
PM
13039seen by the debugger.
13040
13041@kindex set shell
13042@item set shell
13043This boolean values specifies whether the debuggee is called
13044via a shell or directly (default value is on).
13045
13046@kindex show shell
13047@item show shell
13048Displays if the debuggee will be started with a shell.
13049
13050@end table
13051
be448670
CF
13052@menu
13053* Non-debug DLL symbols:: Support for DLLs without debugging symbols
13054@end menu
13055
13056@node Non-debug DLL symbols
13057@subsubsection Support for DLLs without debugging symbols
13058@cindex DLLs with no debugging symbols
13059@cindex Minimal symbols and DLLs
13060
13061Very often on windows, some of the DLLs that your program relies on do
13062not include symbolic debugging information (for example,
13063@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
13064symbols in a DLL, it relies on the minimal amount of symbolic
13065information contained in the DLL's export table. This subsubsection
13066describes working with such symbols, known internally to @value{GDBN} as
13067``minimal symbols''.
13068
13069Note that before the debugged program has started execution, no DLLs
13070will have been loaded. The easiest way around this problem is simply to
13071start the program --- either by setting a breakpoint or letting the
13072program run once to completion. It is also possible to force
13073@value{GDBN} to load a particular DLL before starting the executable ---
13074see the shared library information in @pxref{Files} or the
13075@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
13076explicitly loading symbols from a DLL with no debugging information will
13077cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
13078which may adversely affect symbol lookup performance.
13079
13080@subsubsection DLL name prefixes
13081
13082In keeping with the naming conventions used by the Microsoft debugging
13083tools, DLL export symbols are made available with a prefix based on the
13084DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
13085also entered into the symbol table, so @code{CreateFileA} is often
13086sufficient. In some cases there will be name clashes within a program
13087(particularly if the executable itself includes full debugging symbols)
13088necessitating the use of the fully qualified name when referring to the
13089contents of the DLL. Use single-quotes around the name to avoid the
13090exclamation mark (``!'') being interpreted as a language operator.
13091
13092Note that the internal name of the DLL may be all upper-case, even
13093though the file name of the DLL is lower-case, or vice-versa. Since
13094symbols within @value{GDBN} are @emph{case-sensitive} this may cause
13095some confusion. If in doubt, try the @code{info functions} and
13096@code{info variables} commands or even @code{maint print msymbols} (see
13097@pxref{Symbols}). Here's an example:
13098
13099@smallexample
f7dc1244 13100(@value{GDBP}) info function CreateFileA
be448670
CF
13101All functions matching regular expression "CreateFileA":
13102
13103Non-debugging symbols:
131040x77e885f4 CreateFileA
131050x77e885f4 KERNEL32!CreateFileA
13106@end smallexample
13107
13108@smallexample
f7dc1244 13109(@value{GDBP}) info function !
be448670
CF
13110All functions matching regular expression "!":
13111
13112Non-debugging symbols:
131130x6100114c cygwin1!__assert
131140x61004034 cygwin1!_dll_crt0@@0
131150x61004240 cygwin1!dll_crt0(per_process *)
13116[etc...]
13117@end smallexample
13118
13119@subsubsection Working with minimal symbols
13120
13121Symbols extracted from a DLL's export table do not contain very much
13122type information. All that @value{GDBN} can do is guess whether a symbol
13123refers to a function or variable depending on the linker section that
13124contains the symbol. Also note that the actual contents of the memory
13125contained in a DLL are not available unless the program is running. This
13126means that you cannot examine the contents of a variable or disassemble
13127a function within a DLL without a running program.
13128
13129Variables are generally treated as pointers and dereferenced
13130automatically. For this reason, it is often necessary to prefix a
13131variable name with the address-of operator (``&'') and provide explicit
13132type information in the command. Here's an example of the type of
13133problem:
13134
13135@smallexample
f7dc1244 13136(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
13137$1 = 268572168
13138@end smallexample
13139
13140@smallexample
f7dc1244 13141(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
131420x10021610: "\230y\""
13143@end smallexample
13144
13145And two possible solutions:
13146
13147@smallexample
f7dc1244 13148(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
13149$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
13150@end smallexample
13151
13152@smallexample
f7dc1244 13153(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 131540x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 13155(@value{GDBP}) x/x 0x10021608
be448670 131560x10021608: 0x0022fd98
f7dc1244 13157(@value{GDBP}) x/s 0x0022fd98
be448670
CF
131580x22fd98: "/cygdrive/c/mydirectory/myprogram"
13159@end smallexample
13160
13161Setting a break point within a DLL is possible even before the program
13162starts execution. However, under these circumstances, @value{GDBN} can't
13163examine the initial instructions of the function in order to skip the
13164function's frame set-up code. You can work around this by using ``*&''
13165to set the breakpoint at a raw memory address:
13166
13167@smallexample
f7dc1244 13168(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
13169Breakpoint 1 at 0x1e04eff0
13170@end smallexample
13171
13172The author of these extensions is not entirely convinced that setting a
13173break point within a shared DLL like @file{kernel32.dll} is completely
13174safe.
13175
14d6dd68
EZ
13176@node Hurd Native
13177@subsection Commands specific to @sc{gnu} Hurd systems
13178@cindex @sc{gnu} Hurd debugging
13179
13180This subsection describes @value{GDBN} commands specific to the
13181@sc{gnu} Hurd native debugging.
13182
13183@table @code
13184@item set signals
13185@itemx set sigs
13186@kindex set signals@r{, Hurd command}
13187@kindex set sigs@r{, Hurd command}
13188This command toggles the state of inferior signal interception by
13189@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
13190affected by this command. @code{sigs} is a shorthand alias for
13191@code{signals}.
13192
13193@item show signals
13194@itemx show sigs
13195@kindex show signals@r{, Hurd command}
13196@kindex show sigs@r{, Hurd command}
13197Show the current state of intercepting inferior's signals.
13198
13199@item set signal-thread
13200@itemx set sigthread
13201@kindex set signal-thread
13202@kindex set sigthread
13203This command tells @value{GDBN} which thread is the @code{libc} signal
13204thread. That thread is run when a signal is delivered to a running
13205process. @code{set sigthread} is the shorthand alias of @code{set
13206signal-thread}.
13207
13208@item show signal-thread
13209@itemx show sigthread
13210@kindex show signal-thread
13211@kindex show sigthread
13212These two commands show which thread will run when the inferior is
13213delivered a signal.
13214
13215@item set stopped
13216@kindex set stopped@r{, Hurd command}
13217This commands tells @value{GDBN} that the inferior process is stopped,
13218as with the @code{SIGSTOP} signal. The stopped process can be
13219continued by delivering a signal to it.
13220
13221@item show stopped
13222@kindex show stopped@r{, Hurd command}
13223This command shows whether @value{GDBN} thinks the debuggee is
13224stopped.
13225
13226@item set exceptions
13227@kindex set exceptions@r{, Hurd command}
13228Use this command to turn off trapping of exceptions in the inferior.
13229When exception trapping is off, neither breakpoints nor
13230single-stepping will work. To restore the default, set exception
13231trapping on.
13232
13233@item show exceptions
13234@kindex show exceptions@r{, Hurd command}
13235Show the current state of trapping exceptions in the inferior.
13236
13237@item set task pause
13238@kindex set task@r{, Hurd commands}
13239@cindex task attributes (@sc{gnu} Hurd)
13240@cindex pause current task (@sc{gnu} Hurd)
13241This command toggles task suspension when @value{GDBN} has control.
13242Setting it to on takes effect immediately, and the task is suspended
13243whenever @value{GDBN} gets control. Setting it to off will take
13244effect the next time the inferior is continued. If this option is set
13245to off, you can use @code{set thread default pause on} or @code{set
13246thread pause on} (see below) to pause individual threads.
13247
13248@item show task pause
13249@kindex show task@r{, Hurd commands}
13250Show the current state of task suspension.
13251
13252@item set task detach-suspend-count
13253@cindex task suspend count
13254@cindex detach from task, @sc{gnu} Hurd
13255This command sets the suspend count the task will be left with when
13256@value{GDBN} detaches from it.
13257
13258@item show task detach-suspend-count
13259Show the suspend count the task will be left with when detaching.
13260
13261@item set task exception-port
13262@itemx set task excp
13263@cindex task exception port, @sc{gnu} Hurd
13264This command sets the task exception port to which @value{GDBN} will
13265forward exceptions. The argument should be the value of the @dfn{send
13266rights} of the task. @code{set task excp} is a shorthand alias.
13267
13268@item set noninvasive
13269@cindex noninvasive task options
13270This command switches @value{GDBN} to a mode that is the least
13271invasive as far as interfering with the inferior is concerned. This
13272is the same as using @code{set task pause}, @code{set exceptions}, and
13273@code{set signals} to values opposite to the defaults.
13274
13275@item info send-rights
13276@itemx info receive-rights
13277@itemx info port-rights
13278@itemx info port-sets
13279@itemx info dead-names
13280@itemx info ports
13281@itemx info psets
13282@cindex send rights, @sc{gnu} Hurd
13283@cindex receive rights, @sc{gnu} Hurd
13284@cindex port rights, @sc{gnu} Hurd
13285@cindex port sets, @sc{gnu} Hurd
13286@cindex dead names, @sc{gnu} Hurd
13287These commands display information about, respectively, send rights,
13288receive rights, port rights, port sets, and dead names of a task.
13289There are also shorthand aliases: @code{info ports} for @code{info
13290port-rights} and @code{info psets} for @code{info port-sets}.
13291
13292@item set thread pause
13293@kindex set thread@r{, Hurd command}
13294@cindex thread properties, @sc{gnu} Hurd
13295@cindex pause current thread (@sc{gnu} Hurd)
13296This command toggles current thread suspension when @value{GDBN} has
13297control. Setting it to on takes effect immediately, and the current
13298thread is suspended whenever @value{GDBN} gets control. Setting it to
13299off will take effect the next time the inferior is continued.
13300Normally, this command has no effect, since when @value{GDBN} has
13301control, the whole task is suspended. However, if you used @code{set
13302task pause off} (see above), this command comes in handy to suspend
13303only the current thread.
13304
13305@item show thread pause
13306@kindex show thread@r{, Hurd command}
13307This command shows the state of current thread suspension.
13308
13309@item set thread run
13310This comamnd sets whether the current thread is allowed to run.
13311
13312@item show thread run
13313Show whether the current thread is allowed to run.
13314
13315@item set thread detach-suspend-count
13316@cindex thread suspend count, @sc{gnu} Hurd
13317@cindex detach from thread, @sc{gnu} Hurd
13318This command sets the suspend count @value{GDBN} will leave on a
13319thread when detaching. This number is relative to the suspend count
13320found by @value{GDBN} when it notices the thread; use @code{set thread
13321takeover-suspend-count} to force it to an absolute value.
13322
13323@item show thread detach-suspend-count
13324Show the suspend count @value{GDBN} will leave on the thread when
13325detaching.
13326
13327@item set thread exception-port
13328@itemx set thread excp
13329Set the thread exception port to which to forward exceptions. This
13330overrides the port set by @code{set task exception-port} (see above).
13331@code{set thread excp} is the shorthand alias.
13332
13333@item set thread takeover-suspend-count
13334Normally, @value{GDBN}'s thread suspend counts are relative to the
13335value @value{GDBN} finds when it notices each thread. This command
13336changes the suspend counts to be absolute instead.
13337
13338@item set thread default
13339@itemx show thread default
13340@cindex thread default settings, @sc{gnu} Hurd
13341Each of the above @code{set thread} commands has a @code{set thread
13342default} counterpart (e.g., @code{set thread default pause}, @code{set
13343thread default exception-port}, etc.). The @code{thread default}
13344variety of commands sets the default thread properties for all
13345threads; you can then change the properties of individual threads with
13346the non-default commands.
13347@end table
13348
13349
a64548ea
EZ
13350@node Neutrino
13351@subsection QNX Neutrino
13352@cindex QNX Neutrino
13353
13354@value{GDBN} provides the following commands specific to the QNX
13355Neutrino target:
13356
13357@table @code
13358@item set debug nto-debug
13359@kindex set debug nto-debug
13360When set to on, enables debugging messages specific to the QNX
13361Neutrino support.
13362
13363@item show debug nto-debug
13364@kindex show debug nto-debug
13365Show the current state of QNX Neutrino messages.
13366@end table
13367
13368
8e04817f
AC
13369@node Embedded OS
13370@section Embedded Operating Systems
104c1213 13371
8e04817f
AC
13372This section describes configurations involving the debugging of
13373embedded operating systems that are available for several different
13374architectures.
d4f3574e 13375
8e04817f
AC
13376@menu
13377* VxWorks:: Using @value{GDBN} with VxWorks
13378@end menu
104c1213 13379
8e04817f
AC
13380@value{GDBN} includes the ability to debug programs running on
13381various real-time operating systems.
104c1213 13382
8e04817f
AC
13383@node VxWorks
13384@subsection Using @value{GDBN} with VxWorks
104c1213 13385
8e04817f 13386@cindex VxWorks
104c1213 13387
8e04817f 13388@table @code
104c1213 13389
8e04817f
AC
13390@kindex target vxworks
13391@item target vxworks @var{machinename}
13392A VxWorks system, attached via TCP/IP. The argument @var{machinename}
13393is the target system's machine name or IP address.
104c1213 13394
8e04817f 13395@end table
104c1213 13396
8e04817f
AC
13397On VxWorks, @code{load} links @var{filename} dynamically on the
13398current target system as well as adding its symbols in @value{GDBN}.
104c1213 13399
8e04817f
AC
13400@value{GDBN} enables developers to spawn and debug tasks running on networked
13401VxWorks targets from a Unix host. Already-running tasks spawned from
13402the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
13403both the Unix host and on the VxWorks target. The program
13404@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
13405installed with the name @code{vxgdb}, to distinguish it from a
13406@value{GDBN} for debugging programs on the host itself.)
104c1213 13407
8e04817f
AC
13408@table @code
13409@item VxWorks-timeout @var{args}
13410@kindex vxworks-timeout
13411All VxWorks-based targets now support the option @code{vxworks-timeout}.
13412This option is set by the user, and @var{args} represents the number of
13413seconds @value{GDBN} waits for responses to rpc's. You might use this if
13414your VxWorks target is a slow software simulator or is on the far side
13415of a thin network line.
13416@end table
104c1213 13417
8e04817f
AC
13418The following information on connecting to VxWorks was current when
13419this manual was produced; newer releases of VxWorks may use revised
13420procedures.
104c1213 13421
4644b6e3 13422@findex INCLUDE_RDB
8e04817f
AC
13423To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
13424to include the remote debugging interface routines in the VxWorks
13425library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
13426VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
13427kernel. The resulting kernel contains @file{rdb.a}, and spawns the
13428source debugging task @code{tRdbTask} when VxWorks is booted. For more
13429information on configuring and remaking VxWorks, see the manufacturer's
13430manual.
13431@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 13432
8e04817f
AC
13433Once you have included @file{rdb.a} in your VxWorks system image and set
13434your Unix execution search path to find @value{GDBN}, you are ready to
13435run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
13436@code{vxgdb}, depending on your installation).
104c1213 13437
8e04817f 13438@value{GDBN} comes up showing the prompt:
104c1213 13439
474c8240 13440@smallexample
8e04817f 13441(vxgdb)
474c8240 13442@end smallexample
104c1213 13443
8e04817f
AC
13444@menu
13445* VxWorks Connection:: Connecting to VxWorks
13446* VxWorks Download:: VxWorks download
13447* VxWorks Attach:: Running tasks
13448@end menu
104c1213 13449
8e04817f
AC
13450@node VxWorks Connection
13451@subsubsection Connecting to VxWorks
104c1213 13452
8e04817f
AC
13453The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
13454network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 13455
474c8240 13456@smallexample
8e04817f 13457(vxgdb) target vxworks tt
474c8240 13458@end smallexample
104c1213 13459
8e04817f
AC
13460@need 750
13461@value{GDBN} displays messages like these:
104c1213 13462
8e04817f
AC
13463@smallexample
13464Attaching remote machine across net...
13465Connected to tt.
13466@end smallexample
104c1213 13467
8e04817f
AC
13468@need 1000
13469@value{GDBN} then attempts to read the symbol tables of any object modules
13470loaded into the VxWorks target since it was last booted. @value{GDBN} locates
13471these files by searching the directories listed in the command search
13472path (@pxref{Environment, ,Your program's environment}); if it fails
13473to find an object file, it displays a message such as:
5d161b24 13474
474c8240 13475@smallexample
8e04817f 13476prog.o: No such file or directory.
474c8240 13477@end smallexample
104c1213 13478
8e04817f
AC
13479When this happens, add the appropriate directory to the search path with
13480the @value{GDBN} command @code{path}, and execute the @code{target}
13481command again.
104c1213 13482
8e04817f
AC
13483@node VxWorks Download
13484@subsubsection VxWorks download
104c1213 13485
8e04817f
AC
13486@cindex download to VxWorks
13487If you have connected to the VxWorks target and you want to debug an
13488object that has not yet been loaded, you can use the @value{GDBN}
13489@code{load} command to download a file from Unix to VxWorks
13490incrementally. The object file given as an argument to the @code{load}
13491command is actually opened twice: first by the VxWorks target in order
13492to download the code, then by @value{GDBN} in order to read the symbol
13493table. This can lead to problems if the current working directories on
13494the two systems differ. If both systems have NFS mounted the same
13495filesystems, you can avoid these problems by using absolute paths.
13496Otherwise, it is simplest to set the working directory on both systems
13497to the directory in which the object file resides, and then to reference
13498the file by its name, without any path. For instance, a program
13499@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
13500and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
13501program, type this on VxWorks:
104c1213 13502
474c8240 13503@smallexample
8e04817f 13504-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 13505@end smallexample
104c1213 13506
8e04817f
AC
13507@noindent
13508Then, in @value{GDBN}, type:
104c1213 13509
474c8240 13510@smallexample
8e04817f
AC
13511(vxgdb) cd @var{hostpath}/vw/demo/rdb
13512(vxgdb) load prog.o
474c8240 13513@end smallexample
104c1213 13514
8e04817f 13515@value{GDBN} displays a response similar to this:
104c1213 13516
8e04817f
AC
13517@smallexample
13518Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
13519@end smallexample
104c1213 13520
8e04817f
AC
13521You can also use the @code{load} command to reload an object module
13522after editing and recompiling the corresponding source file. Note that
13523this makes @value{GDBN} delete all currently-defined breakpoints,
13524auto-displays, and convenience variables, and to clear the value
13525history. (This is necessary in order to preserve the integrity of
13526debugger's data structures that reference the target system's symbol
13527table.)
104c1213 13528
8e04817f
AC
13529@node VxWorks Attach
13530@subsubsection Running tasks
104c1213
JM
13531
13532@cindex running VxWorks tasks
13533You can also attach to an existing task using the @code{attach} command as
13534follows:
13535
474c8240 13536@smallexample
104c1213 13537(vxgdb) attach @var{task}
474c8240 13538@end smallexample
104c1213
JM
13539
13540@noindent
13541where @var{task} is the VxWorks hexadecimal task ID. The task can be running
13542or suspended when you attach to it. Running tasks are suspended at
13543the time of attachment.
13544
6d2ebf8b 13545@node Embedded Processors
104c1213
JM
13546@section Embedded Processors
13547
13548This section goes into details specific to particular embedded
13549configurations.
13550
c45da7e6
EZ
13551@cindex send command to simulator
13552Whenever a specific embedded processor has a simulator, @value{GDBN}
13553allows to send an arbitrary command to the simulator.
13554
13555@table @code
13556@item sim @var{command}
13557@kindex sim@r{, a command}
13558Send an arbitrary @var{command} string to the simulator. Consult the
13559documentation for the specific simulator in use for information about
13560acceptable commands.
13561@end table
13562
7d86b5d5 13563
104c1213 13564@menu
c45da7e6 13565* ARM:: ARM RDI
172c2a43
KI
13566* H8/300:: Renesas H8/300
13567* H8/500:: Renesas H8/500
13568* M32R/D:: Renesas M32R/D
104c1213 13569* M68K:: Motorola M68K
104c1213 13570* MIPS Embedded:: MIPS Embedded
a37295f9 13571* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
13572* PA:: HP PA Embedded
13573* PowerPC: PowerPC
172c2a43 13574* SH:: Renesas SH
104c1213
JM
13575* Sparclet:: Tsqware Sparclet
13576* Sparclite:: Fujitsu Sparclite
13577* ST2000:: Tandem ST2000
13578* Z8000:: Zilog Z8000
a64548ea
EZ
13579* AVR:: Atmel AVR
13580* CRIS:: CRIS
13581* Super-H:: Renesas Super-H
c45da7e6 13582* WinCE:: Windows CE child processes
104c1213
JM
13583@end menu
13584
6d2ebf8b 13585@node ARM
104c1213 13586@subsection ARM
c45da7e6 13587@cindex ARM RDI
104c1213
JM
13588
13589@table @code
8e04817f
AC
13590@kindex target rdi
13591@item target rdi @var{dev}
13592ARM Angel monitor, via RDI library interface to ADP protocol. You may
13593use this target to communicate with both boards running the Angel
13594monitor, or with the EmbeddedICE JTAG debug device.
13595
13596@kindex target rdp
13597@item target rdp @var{dev}
13598ARM Demon monitor.
13599
13600@end table
13601
e2f4edfd
EZ
13602@value{GDBN} provides the following ARM-specific commands:
13603
13604@table @code
13605@item set arm disassembler
13606@kindex set arm
13607This commands selects from a list of disassembly styles. The
13608@code{"std"} style is the standard style.
13609
13610@item show arm disassembler
13611@kindex show arm
13612Show the current disassembly style.
13613
13614@item set arm apcs32
13615@cindex ARM 32-bit mode
13616This command toggles ARM operation mode between 32-bit and 26-bit.
13617
13618@item show arm apcs32
13619Display the current usage of the ARM 32-bit mode.
13620
13621@item set arm fpu @var{fputype}
13622This command sets the ARM floating-point unit (FPU) type. The
13623argument @var{fputype} can be one of these:
13624
13625@table @code
13626@item auto
13627Determine the FPU type by querying the OS ABI.
13628@item softfpa
13629Software FPU, with mixed-endian doubles on little-endian ARM
13630processors.
13631@item fpa
13632GCC-compiled FPA co-processor.
13633@item softvfp
13634Software FPU with pure-endian doubles.
13635@item vfp
13636VFP co-processor.
13637@end table
13638
13639@item show arm fpu
13640Show the current type of the FPU.
13641
13642@item set arm abi
13643This command forces @value{GDBN} to use the specified ABI.
13644
13645@item show arm abi
13646Show the currently used ABI.
13647
13648@item set debug arm
13649Toggle whether to display ARM-specific debugging messages from the ARM
13650target support subsystem.
13651
13652@item show debug arm
13653Show whether ARM-specific debugging messages are enabled.
13654@end table
13655
c45da7e6
EZ
13656The following commands are available when an ARM target is debugged
13657using the RDI interface:
13658
13659@table @code
13660@item rdilogfile @r{[}@var{file}@r{]}
13661@kindex rdilogfile
13662@cindex ADP (Angel Debugger Protocol) logging
13663Set the filename for the ADP (Angel Debugger Protocol) packet log.
13664With an argument, sets the log file to the specified @var{file}. With
13665no argument, show the current log file name. The default log file is
13666@file{rdi.log}.
13667
13668@item rdilogenable @r{[}@var{arg}@r{]}
13669@kindex rdilogenable
13670Control logging of ADP packets. With an argument of 1 or @code{"yes"}
13671enables logging, with an argument 0 or @code{"no"} disables it. With
13672no arguments displays the current setting. When logging is enabled,
13673ADP packets exchanged between @value{GDBN} and the RDI target device
13674are logged to a file.
13675
13676@item set rdiromatzero
13677@kindex set rdiromatzero
13678@cindex ROM at zero address, RDI
13679Tell @value{GDBN} whether the target has ROM at address 0. If on,
13680vector catching is disabled, so that zero address can be used. If off
13681(the default), vector catching is enabled. For this command to take
13682effect, it needs to be invoked prior to the @code{target rdi} command.
13683
13684@item show rdiromatzero
13685@kindex show rdiromatzero
13686Show the current setting of ROM at zero address.
13687
13688@item set rdiheartbeat
13689@kindex set rdiheartbeat
13690@cindex RDI heartbeat
13691Enable or disable RDI heartbeat packets. It is not recommended to
13692turn on this option, since it confuses ARM and EPI JTAG interface, as
13693well as the Angel monitor.
13694
13695@item show rdiheartbeat
13696@kindex show rdiheartbeat
13697Show the setting of RDI heartbeat packets.
13698@end table
13699
e2f4edfd 13700
8e04817f 13701@node H8/300
172c2a43 13702@subsection Renesas H8/300
8e04817f
AC
13703
13704@table @code
13705
13706@kindex target hms@r{, with H8/300}
13707@item target hms @var{dev}
172c2a43 13708A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
13709Use special commands @code{device} and @code{speed} to control the serial
13710line and the communications speed used.
13711
13712@kindex target e7000@r{, with H8/300}
13713@item target e7000 @var{dev}
172c2a43 13714E7000 emulator for Renesas H8 and SH.
8e04817f
AC
13715
13716@kindex target sh3@r{, with H8/300}
13717@kindex target sh3e@r{, with H8/300}
13718@item target sh3 @var{dev}
13719@itemx target sh3e @var{dev}
172c2a43 13720Renesas SH-3 and SH-3E target systems.
8e04817f
AC
13721
13722@end table
13723
13724@cindex download to H8/300 or H8/500
13725@cindex H8/300 or H8/500 download
172c2a43
KI
13726@cindex download to Renesas SH
13727@cindex Renesas SH download
13728When you select remote debugging to a Renesas SH, H8/300, or H8/500
13729board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
13730board and also opens it as the current executable target for
13731@value{GDBN} on your host (like the @code{file} command).
13732
13733@value{GDBN} needs to know these things to talk to your
172c2a43 13734Renesas SH, H8/300, or H8/500:
8e04817f
AC
13735
13736@enumerate
13737@item
13738that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
13739for Renesas microprocessors, or @samp{target e7000}, the in-circuit
13740emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
13741the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
13742H8/300, or H8/500.)
13743
13744@item
172c2a43 13745what serial device connects your host to your Renesas board (the first
8e04817f
AC
13746serial device available on your host is the default).
13747
13748@item
13749what speed to use over the serial device.
13750@end enumerate
13751
13752@menu
172c2a43
KI
13753* Renesas Boards:: Connecting to Renesas boards.
13754* Renesas ICE:: Using the E7000 In-Circuit Emulator.
13755* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
13756@end menu
13757
172c2a43
KI
13758@node Renesas Boards
13759@subsubsection Connecting to Renesas boards
8e04817f
AC
13760
13761@c only for Unix hosts
13762@kindex device
172c2a43 13763@cindex serial device, Renesas micros
8e04817f
AC
13764Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
13765need to explicitly set the serial device. The default @var{port} is the
13766first available port on your host. This is only necessary on Unix
13767hosts, where it is typically something like @file{/dev/ttya}.
13768
13769@kindex speed
172c2a43 13770@cindex serial line speed, Renesas micros
8e04817f
AC
13771@code{@value{GDBN}} has another special command to set the communications
13772speed: @samp{speed @var{bps}}. This command also is only used from Unix
13773hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
13774the DOS @code{mode} command (for instance,
13775@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
13776
13777The @samp{device} and @samp{speed} commands are available only when you
172c2a43 13778use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
13779use a DOS host,
13780@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
13781called @code{asynctsr} to communicate with the development board
13782through a PC serial port. You must also use the DOS @code{mode} command
13783to set up the serial port on the DOS side.
13784
13785The following sample session illustrates the steps needed to start a
13786program under @value{GDBN} control on an H8/300. The example uses a
13787sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 13788the Renesas SH and the H8/500.
8e04817f
AC
13789
13790First hook up your development board. In this example, we use a
13791board attached to serial port @code{COM2}; if you use a different serial
13792port, substitute its name in the argument of the @code{mode} command.
13793When you call @code{asynctsr}, the auxiliary comms program used by the
13794debugger, you give it just the numeric part of the serial port's name;
13795for example, @samp{asyncstr 2} below runs @code{asyncstr} on
13796@code{COM2}.
13797
474c8240 13798@smallexample
8e04817f
AC
13799C:\H8300\TEST> asynctsr 2
13800C:\H8300\TEST> mode com2:9600,n,8,1,p
13801
13802Resident portion of MODE loaded
13803
13804COM2: 9600, n, 8, 1, p
13805
474c8240 13806@end smallexample
8e04817f
AC
13807
13808@quotation
13809@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
13810@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
13811disable it, or even boot without it, to use @code{asynctsr} to control
13812your development board.
13813@end quotation
13814
13815@kindex target hms@r{, and serial protocol}
13816Now that serial communications are set up, and the development board is
9c16f35a 13817connected, you can start up @value{GDBN}. Call @code{@value{GDBN}} with
8e04817f
AC
13818the name of your program as the argument. @code{@value{GDBN}} prompts
13819you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
13820commands to begin your debugging session: @samp{target hms} to specify
172c2a43 13821cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
13822download your program to the board. @code{load} displays the names of
13823the program's sections, and a @samp{*} for each 2K of data downloaded.
13824(If you want to refresh @value{GDBN} data on symbols or on the
13825executable file without downloading, use the @value{GDBN} commands
13826@code{file} or @code{symbol-file}. These commands, and @code{load}
13827itself, are described in @ref{Files,,Commands to specify files}.)
13828
13829@smallexample
13830(eg-C:\H8300\TEST) @value{GDBP} t.x
13831@value{GDBN} is free software and you are welcome to distribute copies
13832 of it under certain conditions; type "show copying" to see
13833 the conditions.
13834There is absolutely no warranty for @value{GDBN}; type "show warranty"
13835for details.
13836@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
13837(@value{GDBP}) target hms
13838Connected to remote H8/300 HMS system.
13839(@value{GDBP}) load t.x
13840.text : 0x8000 .. 0xabde ***********
13841.data : 0xabde .. 0xad30 *
13842.stack : 0xf000 .. 0xf014 *
13843@end smallexample
13844
13845At this point, you're ready to run or debug your program. From here on,
13846you can use all the usual @value{GDBN} commands. The @code{break} command
13847sets breakpoints; the @code{run} command starts your program;
13848@code{print} or @code{x} display data; the @code{continue} command
13849resumes execution after stopping at a breakpoint. You can use the
13850@code{help} command at any time to find out more about @value{GDBN} commands.
13851
13852Remember, however, that @emph{operating system} facilities aren't
13853available on your development board; for example, if your program hangs,
13854you can't send an interrupt---but you can press the @sc{reset} switch!
13855
13856Use the @sc{reset} button on the development board
13857@itemize @bullet
13858@item
13859to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
13860no way to pass an interrupt signal to the development board); and
13861
13862@item
13863to return to the @value{GDBN} command prompt after your program finishes
13864normally. The communications protocol provides no other way for @value{GDBN}
13865to detect program completion.
13866@end itemize
13867
13868In either case, @value{GDBN} sees the effect of a @sc{reset} on the
13869development board as a ``normal exit'' of your program.
13870
172c2a43 13871@node Renesas ICE
8e04817f
AC
13872@subsubsection Using the E7000 in-circuit emulator
13873
172c2a43 13874@kindex target e7000@r{, with Renesas ICE}
8e04817f 13875You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 13876Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
13877e7000} command to connect @value{GDBN} to your E7000:
13878
13879@table @code
13880@item target e7000 @var{port} @var{speed}
13881Use this form if your E7000 is connected to a serial port. The
13882@var{port} argument identifies what serial port to use (for example,
13883@samp{com2}). The third argument is the line speed in bits per second
13884(for example, @samp{9600}).
13885
13886@item target e7000 @var{hostname}
13887If your E7000 is installed as a host on a TCP/IP network, you can just
13888specify its hostname; @value{GDBN} uses @code{telnet} to connect.
13889@end table
13890
ba04e063
EZ
13891The following special commands are available when debugging with the
13892Renesas E7000 ICE:
13893
13894@table @code
13895@item e7000 @var{command}
13896@kindex e7000
13897@cindex send command to E7000 monitor
13898This sends the specified @var{command} to the E7000 monitor.
13899
13900@item ftplogin @var{machine} @var{username} @var{password} @var{dir}
13901@kindex ftplogin@r{, E7000}
13902This command records information for subsequent interface with the
13903E7000 monitor via the FTP protocol: @value{GDBN} will log into the
13904named @var{machine} using specified @var{username} and @var{password},
13905and then chdir to the named directory @var{dir}.
13906
13907@item ftpload @var{file}
13908@kindex ftpload@r{, E7000}
13909This command uses credentials recorded by @code{ftplogin} to fetch and
13910load the named @var{file} from the E7000 monitor.
13911
13912@item drain
13913@kindex drain@r{, E7000}
13914This command drains any pending text buffers stored on the E7000.
13915
13916@item set usehardbreakpoints
13917@itemx show usehardbreakpoints
13918@kindex set usehardbreakpoints@r{, E7000}
13919@kindex show usehardbreakpoints@r{, E7000}
13920@cindex hardware breakpoints, and E7000
13921These commands set and show the use of hardware breakpoints for all
13922breakpoints. @xref{Set Breaks, hardware-assisted breakpoint}, for
13923more information about using hardware breakpoints selectively.
13924@end table
13925
172c2a43
KI
13926@node Renesas Special
13927@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
13928
13929Some @value{GDBN} commands are available only for the H8/300:
13930
13931@table @code
13932
13933@kindex set machine
13934@kindex show machine
13935@item set machine h8300
13936@itemx set machine h8300h
13937Condition @value{GDBN} for one of the two variants of the H8/300
13938architecture with @samp{set machine}. You can use @samp{show machine}
13939to check which variant is currently in effect.
104c1213
JM
13940
13941@end table
13942
8e04817f
AC
13943@node H8/500
13944@subsection H8/500
104c1213
JM
13945
13946@table @code
13947
8e04817f
AC
13948@kindex set memory @var{mod}
13949@cindex memory models, H8/500
13950@item set memory @var{mod}
13951@itemx show memory
13952Specify which H8/500 memory model (@var{mod}) you are using with
13953@samp{set memory}; check which memory model is in effect with @samp{show
13954memory}. The accepted values for @var{mod} are @code{small},
13955@code{big}, @code{medium}, and @code{compact}.
104c1213 13956
8e04817f 13957@end table
104c1213 13958
8e04817f 13959@node M32R/D
ba04e063 13960@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
13961
13962@table @code
8e04817f
AC
13963@kindex target m32r
13964@item target m32r @var{dev}
172c2a43 13965Renesas M32R/D ROM monitor.
8e04817f 13966
fb3e19c0
KI
13967@kindex target m32rsdi
13968@item target m32rsdi @var{dev}
13969Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
13970@end table
13971
13972The following @value{GDBN} commands are specific to the M32R monitor:
13973
13974@table @code
13975@item set download-path @var{path}
13976@kindex set download-path
13977@cindex find downloadable @sc{srec} files (M32R)
13978Set the default path for finding donwloadable @sc{srec} files.
13979
13980@item show download-path
13981@kindex show download-path
13982Show the default path for downloadable @sc{srec} files.
fb3e19c0 13983
721c2651
EZ
13984@item set board-address @var{addr}
13985@kindex set board-address
13986@cindex M32-EVA target board address
13987Set the IP address for the M32R-EVA target board.
13988
13989@item show board-address
13990@kindex show board-address
13991Show the current IP address of the target board.
13992
13993@item set server-address @var{addr}
13994@kindex set server-address
13995@cindex download server address (M32R)
13996Set the IP address for the download server, which is the @value{GDBN}'s
13997host machine.
13998
13999@item show server-address
14000@kindex show server-address
14001Display the IP address of the download server.
14002
14003@item upload @r{[}@var{file}@r{]}
14004@kindex upload@r{, M32R}
14005Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
14006upload capability. If no @var{file} argument is given, the current
14007executable file is uploaded.
14008
14009@item tload @r{[}@var{file}@r{]}
14010@kindex tload@r{, M32R}
14011Test the @code{upload} command.
8e04817f
AC
14012@end table
14013
ba04e063
EZ
14014The following commands are available for M32R/SDI:
14015
14016@table @code
14017@item sdireset
14018@kindex sdireset
14019@cindex reset SDI connection, M32R
14020This command resets the SDI connection.
14021
14022@item sdistatus
14023@kindex sdistatus
14024This command shows the SDI connection status.
14025
14026@item debug_chaos
14027@kindex debug_chaos
14028@cindex M32R/Chaos debugging
14029Instructs the remote that M32R/Chaos debugging is to be used.
14030
14031@item use_debug_dma
14032@kindex use_debug_dma
14033Instructs the remote to use the DEBUG_DMA method of accessing memory.
14034
14035@item use_mon_code
14036@kindex use_mon_code
14037Instructs the remote to use the MON_CODE method of accessing memory.
14038
14039@item use_ib_break
14040@kindex use_ib_break
14041Instructs the remote to set breakpoints by IB break.
14042
14043@item use_dbt_break
14044@kindex use_dbt_break
14045Instructs the remote to set breakpoints by DBT.
14046@end table
14047
8e04817f
AC
14048@node M68K
14049@subsection M68k
14050
14051The Motorola m68k configuration includes ColdFire support, and
14052target command for the following ROM monitors.
14053
14054@table @code
14055
14056@kindex target abug
14057@item target abug @var{dev}
14058ABug ROM monitor for M68K.
14059
14060@kindex target cpu32bug
14061@item target cpu32bug @var{dev}
14062CPU32BUG monitor, running on a CPU32 (M68K) board.
14063
14064@kindex target dbug
14065@item target dbug @var{dev}
14066dBUG ROM monitor for Motorola ColdFire.
14067
14068@kindex target est
14069@item target est @var{dev}
14070EST-300 ICE monitor, running on a CPU32 (M68K) board.
14071
14072@kindex target rom68k
14073@item target rom68k @var{dev}
14074ROM 68K monitor, running on an M68K IDP board.
14075
14076@end table
14077
8e04817f
AC
14078@table @code
14079
14080@kindex target rombug
14081@item target rombug @var{dev}
14082ROMBUG ROM monitor for OS/9000.
14083
14084@end table
14085
8e04817f
AC
14086@node MIPS Embedded
14087@subsection MIPS Embedded
14088
14089@cindex MIPS boards
14090@value{GDBN} can use the MIPS remote debugging protocol to talk to a
14091MIPS board attached to a serial line. This is available when
14092you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 14093
8e04817f
AC
14094@need 1000
14095Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 14096
8e04817f
AC
14097@table @code
14098@item target mips @var{port}
14099@kindex target mips @var{port}
14100To run a program on the board, start up @code{@value{GDBP}} with the
14101name of your program as the argument. To connect to the board, use the
14102command @samp{target mips @var{port}}, where @var{port} is the name of
14103the serial port connected to the board. If the program has not already
14104been downloaded to the board, you may use the @code{load} command to
14105download it. You can then use all the usual @value{GDBN} commands.
104c1213 14106
8e04817f
AC
14107For example, this sequence connects to the target board through a serial
14108port, and loads and runs a program called @var{prog} through the
14109debugger:
104c1213 14110
474c8240 14111@smallexample
8e04817f
AC
14112host$ @value{GDBP} @var{prog}
14113@value{GDBN} is free software and @dots{}
14114(@value{GDBP}) target mips /dev/ttyb
14115(@value{GDBP}) load @var{prog}
14116(@value{GDBP}) run
474c8240 14117@end smallexample
104c1213 14118
8e04817f
AC
14119@item target mips @var{hostname}:@var{portnumber}
14120On some @value{GDBN} host configurations, you can specify a TCP
14121connection (for instance, to a serial line managed by a terminal
14122concentrator) instead of a serial port, using the syntax
14123@samp{@var{hostname}:@var{portnumber}}.
104c1213 14124
8e04817f
AC
14125@item target pmon @var{port}
14126@kindex target pmon @var{port}
14127PMON ROM monitor.
104c1213 14128
8e04817f
AC
14129@item target ddb @var{port}
14130@kindex target ddb @var{port}
14131NEC's DDB variant of PMON for Vr4300.
104c1213 14132
8e04817f
AC
14133@item target lsi @var{port}
14134@kindex target lsi @var{port}
14135LSI variant of PMON.
104c1213 14136
8e04817f
AC
14137@kindex target r3900
14138@item target r3900 @var{dev}
14139Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 14140
8e04817f
AC
14141@kindex target array
14142@item target array @var{dev}
14143Array Tech LSI33K RAID controller board.
104c1213 14144
8e04817f 14145@end table
104c1213 14146
104c1213 14147
8e04817f
AC
14148@noindent
14149@value{GDBN} also supports these special commands for MIPS targets:
104c1213 14150
8e04817f 14151@table @code
8e04817f
AC
14152@item set mipsfpu double
14153@itemx set mipsfpu single
14154@itemx set mipsfpu none
a64548ea 14155@itemx set mipsfpu auto
8e04817f
AC
14156@itemx show mipsfpu
14157@kindex set mipsfpu
14158@kindex show mipsfpu
14159@cindex MIPS remote floating point
14160@cindex floating point, MIPS remote
14161If your target board does not support the MIPS floating point
14162coprocessor, you should use the command @samp{set mipsfpu none} (if you
14163need this, you may wish to put the command in your @value{GDBN} init
14164file). This tells @value{GDBN} how to find the return value of
14165functions which return floating point values. It also allows
14166@value{GDBN} to avoid saving the floating point registers when calling
14167functions on the board. If you are using a floating point coprocessor
14168with only single precision floating point support, as on the @sc{r4650}
14169processor, use the command @samp{set mipsfpu single}. The default
14170double precision floating point coprocessor may be selected using
14171@samp{set mipsfpu double}.
104c1213 14172
8e04817f
AC
14173In previous versions the only choices were double precision or no
14174floating point, so @samp{set mipsfpu on} will select double precision
14175and @samp{set mipsfpu off} will select no floating point.
104c1213 14176
8e04817f
AC
14177As usual, you can inquire about the @code{mipsfpu} variable with
14178@samp{show mipsfpu}.
104c1213 14179
8e04817f
AC
14180@item set timeout @var{seconds}
14181@itemx set retransmit-timeout @var{seconds}
14182@itemx show timeout
14183@itemx show retransmit-timeout
14184@cindex @code{timeout}, MIPS protocol
14185@cindex @code{retransmit-timeout}, MIPS protocol
14186@kindex set timeout
14187@kindex show timeout
14188@kindex set retransmit-timeout
14189@kindex show retransmit-timeout
14190You can control the timeout used while waiting for a packet, in the MIPS
14191remote protocol, with the @code{set timeout @var{seconds}} command. The
14192default is 5 seconds. Similarly, you can control the timeout used while
14193waiting for an acknowledgement of a packet with the @code{set
14194retransmit-timeout @var{seconds}} command. The default is 3 seconds.
14195You can inspect both values with @code{show timeout} and @code{show
14196retransmit-timeout}. (These commands are @emph{only} available when
14197@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 14198
8e04817f
AC
14199The timeout set by @code{set timeout} does not apply when @value{GDBN}
14200is waiting for your program to stop. In that case, @value{GDBN} waits
14201forever because it has no way of knowing how long the program is going
14202to run before stopping.
ba04e063
EZ
14203
14204@item set syn-garbage-limit @var{num}
14205@kindex set syn-garbage-limit@r{, MIPS remote}
14206@cindex synchronize with remote MIPS target
14207Limit the maximum number of characters @value{GDBN} should ignore when
14208it tries to synchronize with the remote target. The default is 10
14209characters. Setting the limit to -1 means there's no limit.
14210
14211@item show syn-garbage-limit
14212@kindex show syn-garbage-limit@r{, MIPS remote}
14213Show the current limit on the number of characters to ignore when
14214trying to synchronize with the remote system.
14215
14216@item set monitor-prompt @var{prompt}
14217@kindex set monitor-prompt@r{, MIPS remote}
14218@cindex remote monitor prompt
14219Tell @value{GDBN} to expect the specified @var{prompt} string from the
14220remote monitor. The default depends on the target:
14221@table @asis
14222@item pmon target
14223@samp{PMON}
14224@item ddb target
14225@samp{NEC010}
14226@item lsi target
14227@samp{PMON>}
14228@end table
14229
14230@item show monitor-prompt
14231@kindex show monitor-prompt@r{, MIPS remote}
14232Show the current strings @value{GDBN} expects as the prompt from the
14233remote monitor.
14234
14235@item set monitor-warnings
14236@kindex set monitor-warnings@r{, MIPS remote}
14237Enable or disable monitor warnings about hardware breakpoints. This
14238has effect only for the @code{lsi} target. When on, @value{GDBN} will
14239display warning messages whose codes are returned by the @code{lsi}
14240PMON monitor for breakpoint commands.
14241
14242@item show monitor-warnings
14243@kindex show monitor-warnings@r{, MIPS remote}
14244Show the current setting of printing monitor warnings.
14245
14246@item pmon @var{command}
14247@kindex pmon@r{, MIPS remote}
14248@cindex send PMON command
14249This command allows sending an arbitrary @var{command} string to the
14250monitor. The monitor must be in debug mode for this to work.
8e04817f 14251@end table
104c1213 14252
a37295f9
MM
14253@node OpenRISC 1000
14254@subsection OpenRISC 1000
14255@cindex OpenRISC 1000
14256
14257@cindex or1k boards
14258See OR1k Architecture document (@uref{www.opencores.org}) for more information
14259about platform and commands.
14260
14261@table @code
14262
14263@kindex target jtag
14264@item target jtag jtag://@var{host}:@var{port}
14265
14266Connects to remote JTAG server.
14267JTAG remote server can be either an or1ksim or JTAG server,
14268connected via parallel port to the board.
14269
14270Example: @code{target jtag jtag://localhost:9999}
14271
14272@kindex or1ksim
14273@item or1ksim @var{command}
14274If connected to @code{or1ksim} OpenRISC 1000 Architectural
14275Simulator, proprietary commands can be executed.
14276
14277@kindex info or1k spr
14278@item info or1k spr
14279Displays spr groups.
14280
14281@item info or1k spr @var{group}
14282@itemx info or1k spr @var{groupno}
14283Displays register names in selected group.
14284
14285@item info or1k spr @var{group} @var{register}
14286@itemx info or1k spr @var{register}
14287@itemx info or1k spr @var{groupno} @var{registerno}
14288@itemx info or1k spr @var{registerno}
14289Shows information about specified spr register.
14290
14291@kindex spr
14292@item spr @var{group} @var{register} @var{value}
14293@itemx spr @var{register @var{value}}
14294@itemx spr @var{groupno} @var{registerno @var{value}}
14295@itemx spr @var{registerno @var{value}}
14296Writes @var{value} to specified spr register.
14297@end table
14298
14299Some implementations of OpenRISC 1000 Architecture also have hardware trace.
14300It is very similar to @value{GDBN} trace, except it does not interfere with normal
14301program execution and is thus much faster. Hardware breakpoints/watchpoint
14302triggers can be set using:
14303@table @code
14304@item $LEA/$LDATA
14305Load effective address/data
14306@item $SEA/$SDATA
14307Store effective address/data
14308@item $AEA/$ADATA
14309Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
14310@item $FETCH
14311Fetch data
14312@end table
14313
14314When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
14315@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
14316
14317@code{htrace} commands:
14318@cindex OpenRISC 1000 htrace
14319@table @code
14320@kindex hwatch
14321@item hwatch @var{conditional}
14322Set hardware watchpoint on combination of Load/Store Effecive Address(es)
14323or Data. For example:
14324
14325@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14326
14327@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14328
4644b6e3 14329@kindex htrace
a37295f9
MM
14330@item htrace info
14331Display information about current HW trace configuration.
14332
a37295f9
MM
14333@item htrace trigger @var{conditional}
14334Set starting criteria for HW trace.
14335
a37295f9
MM
14336@item htrace qualifier @var{conditional}
14337Set acquisition qualifier for HW trace.
14338
a37295f9
MM
14339@item htrace stop @var{conditional}
14340Set HW trace stopping criteria.
14341
f153cc92 14342@item htrace record [@var{data}]*
a37295f9
MM
14343Selects the data to be recorded, when qualifier is met and HW trace was
14344triggered.
14345
a37295f9 14346@item htrace enable
a37295f9
MM
14347@itemx htrace disable
14348Enables/disables the HW trace.
14349
f153cc92 14350@item htrace rewind [@var{filename}]
a37295f9
MM
14351Clears currently recorded trace data.
14352
14353If filename is specified, new trace file is made and any newly collected data
14354will be written there.
14355
f153cc92 14356@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
14357Prints trace buffer, using current record configuration.
14358
a37295f9
MM
14359@item htrace mode continuous
14360Set continuous trace mode.
14361
a37295f9
MM
14362@item htrace mode suspend
14363Set suspend trace mode.
14364
14365@end table
14366
8e04817f
AC
14367@node PowerPC
14368@subsection PowerPC
104c1213
JM
14369
14370@table @code
8e04817f
AC
14371@kindex target dink32
14372@item target dink32 @var{dev}
14373DINK32 ROM monitor.
104c1213 14374
8e04817f
AC
14375@kindex target ppcbug
14376@item target ppcbug @var{dev}
14377@kindex target ppcbug1
14378@item target ppcbug1 @var{dev}
14379PPCBUG ROM monitor for PowerPC.
104c1213 14380
8e04817f
AC
14381@kindex target sds
14382@item target sds @var{dev}
14383SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 14384@end table
8e04817f 14385
c45da7e6
EZ
14386@cindex SDS protocol
14387The following commands specifi to the SDS protocol are supported
14388by@value{GDBN}:
14389
14390@table @code
14391@item set sdstimeout @var{nsec}
14392@kindex set sdstimeout
14393Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
14394default is 2 seconds.
14395
14396@item show sdstimeout
14397@kindex show sdstimeout
14398Show the current value of the SDS timeout.
14399
14400@item sds @var{command}
14401@kindex sds@r{, a command}
14402Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
14403@end table
14404
c45da7e6 14405
8e04817f
AC
14406@node PA
14407@subsection HP PA Embedded
104c1213
JM
14408
14409@table @code
14410
8e04817f
AC
14411@kindex target op50n
14412@item target op50n @var{dev}
14413OP50N monitor, running on an OKI HPPA board.
14414
14415@kindex target w89k
14416@item target w89k @var{dev}
14417W89K monitor, running on a Winbond HPPA board.
104c1213
JM
14418
14419@end table
14420
8e04817f 14421@node SH
172c2a43 14422@subsection Renesas SH
104c1213
JM
14423
14424@table @code
14425
172c2a43 14426@kindex target hms@r{, with Renesas SH}
8e04817f 14427@item target hms @var{dev}
172c2a43 14428A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
14429commands @code{device} and @code{speed} to control the serial line and
14430the communications speed used.
104c1213 14431
172c2a43 14432@kindex target e7000@r{, with Renesas SH}
8e04817f 14433@item target e7000 @var{dev}
172c2a43 14434E7000 emulator for Renesas SH.
104c1213 14435
8e04817f
AC
14436@kindex target sh3@r{, with SH}
14437@kindex target sh3e@r{, with SH}
14438@item target sh3 @var{dev}
14439@item target sh3e @var{dev}
172c2a43 14440Renesas SH-3 and SH-3E target systems.
104c1213 14441
8e04817f 14442@end table
104c1213 14443
8e04817f
AC
14444@node Sparclet
14445@subsection Tsqware Sparclet
104c1213 14446
8e04817f
AC
14447@cindex Sparclet
14448
14449@value{GDBN} enables developers to debug tasks running on
14450Sparclet targets from a Unix host.
14451@value{GDBN} uses code that runs on
14452both the Unix host and on the Sparclet target. The program
14453@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 14454
8e04817f
AC
14455@table @code
14456@item remotetimeout @var{args}
14457@kindex remotetimeout
14458@value{GDBN} supports the option @code{remotetimeout}.
14459This option is set by the user, and @var{args} represents the number of
14460seconds @value{GDBN} waits for responses.
104c1213
JM
14461@end table
14462
8e04817f
AC
14463@cindex compiling, on Sparclet
14464When compiling for debugging, include the options @samp{-g} to get debug
14465information and @samp{-Ttext} to relocate the program to where you wish to
14466load it on the target. You may also want to add the options @samp{-n} or
14467@samp{-N} in order to reduce the size of the sections. Example:
104c1213 14468
474c8240 14469@smallexample
8e04817f 14470sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 14471@end smallexample
104c1213 14472
8e04817f 14473You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 14474
474c8240 14475@smallexample
8e04817f 14476sparclet-aout-objdump --headers --syms prog
474c8240 14477@end smallexample
104c1213 14478
8e04817f
AC
14479@cindex running, on Sparclet
14480Once you have set
14481your Unix execution search path to find @value{GDBN}, you are ready to
14482run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
14483(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 14484
8e04817f
AC
14485@value{GDBN} comes up showing the prompt:
14486
474c8240 14487@smallexample
8e04817f 14488(gdbslet)
474c8240 14489@end smallexample
104c1213
JM
14490
14491@menu
8e04817f
AC
14492* Sparclet File:: Setting the file to debug
14493* Sparclet Connection:: Connecting to Sparclet
14494* Sparclet Download:: Sparclet download
14495* Sparclet Execution:: Running and debugging
104c1213
JM
14496@end menu
14497
8e04817f
AC
14498@node Sparclet File
14499@subsubsection Setting file to debug
104c1213 14500
8e04817f 14501The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 14502
474c8240 14503@smallexample
8e04817f 14504(gdbslet) file prog
474c8240 14505@end smallexample
104c1213 14506
8e04817f
AC
14507@need 1000
14508@value{GDBN} then attempts to read the symbol table of @file{prog}.
14509@value{GDBN} locates
14510the file by searching the directories listed in the command search
14511path.
14512If the file was compiled with debug information (option "-g"), source
14513files will be searched as well.
14514@value{GDBN} locates
14515the source files by searching the directories listed in the directory search
14516path (@pxref{Environment, ,Your program's environment}).
14517If it fails
14518to find a file, it displays a message such as:
104c1213 14519
474c8240 14520@smallexample
8e04817f 14521prog: No such file or directory.
474c8240 14522@end smallexample
104c1213 14523
8e04817f
AC
14524When this happens, add the appropriate directories to the search paths with
14525the @value{GDBN} commands @code{path} and @code{dir}, and execute the
14526@code{target} command again.
104c1213 14527
8e04817f
AC
14528@node Sparclet Connection
14529@subsubsection Connecting to Sparclet
104c1213 14530
8e04817f
AC
14531The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
14532To connect to a target on serial port ``@code{ttya}'', type:
104c1213 14533
474c8240 14534@smallexample
8e04817f
AC
14535(gdbslet) target sparclet /dev/ttya
14536Remote target sparclet connected to /dev/ttya
14537main () at ../prog.c:3
474c8240 14538@end smallexample
104c1213 14539
8e04817f
AC
14540@need 750
14541@value{GDBN} displays messages like these:
104c1213 14542
474c8240 14543@smallexample
8e04817f 14544Connected to ttya.
474c8240 14545@end smallexample
104c1213 14546
8e04817f
AC
14547@node Sparclet Download
14548@subsubsection Sparclet download
104c1213 14549
8e04817f
AC
14550@cindex download to Sparclet
14551Once connected to the Sparclet target,
14552you can use the @value{GDBN}
14553@code{load} command to download the file from the host to the target.
14554The file name and load offset should be given as arguments to the @code{load}
14555command.
14556Since the file format is aout, the program must be loaded to the starting
14557address. You can use @code{objdump} to find out what this value is. The load
14558offset is an offset which is added to the VMA (virtual memory address)
14559of each of the file's sections.
14560For instance, if the program
14561@file{prog} was linked to text address 0x1201000, with data at 0x12010160
14562and bss at 0x12010170, in @value{GDBN}, type:
104c1213 14563
474c8240 14564@smallexample
8e04817f
AC
14565(gdbslet) load prog 0x12010000
14566Loading section .text, size 0xdb0 vma 0x12010000
474c8240 14567@end smallexample
104c1213 14568
8e04817f
AC
14569If the code is loaded at a different address then what the program was linked
14570to, you may need to use the @code{section} and @code{add-symbol-file} commands
14571to tell @value{GDBN} where to map the symbol table.
14572
14573@node Sparclet Execution
14574@subsubsection Running and debugging
14575
14576@cindex running and debugging Sparclet programs
14577You can now begin debugging the task using @value{GDBN}'s execution control
14578commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
14579manual for the list of commands.
14580
474c8240 14581@smallexample
8e04817f
AC
14582(gdbslet) b main
14583Breakpoint 1 at 0x12010000: file prog.c, line 3.
14584(gdbslet) run
14585Starting program: prog
14586Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
145873 char *symarg = 0;
14588(gdbslet) step
145894 char *execarg = "hello!";
14590(gdbslet)
474c8240 14591@end smallexample
8e04817f
AC
14592
14593@node Sparclite
14594@subsection Fujitsu Sparclite
104c1213
JM
14595
14596@table @code
14597
8e04817f
AC
14598@kindex target sparclite
14599@item target sparclite @var{dev}
14600Fujitsu sparclite boards, used only for the purpose of loading.
14601You must use an additional command to debug the program.
14602For example: target remote @var{dev} using @value{GDBN} standard
14603remote protocol.
104c1213
JM
14604
14605@end table
14606
8e04817f
AC
14607@node ST2000
14608@subsection Tandem ST2000
104c1213 14609
8e04817f
AC
14610@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
14611STDBUG protocol.
104c1213 14612
8e04817f
AC
14613To connect your ST2000 to the host system, see the manufacturer's
14614manual. Once the ST2000 is physically attached, you can run:
104c1213 14615
474c8240 14616@smallexample
8e04817f 14617target st2000 @var{dev} @var{speed}
474c8240 14618@end smallexample
104c1213 14619
8e04817f
AC
14620@noindent
14621to establish it as your debugging environment. @var{dev} is normally
14622the name of a serial device, such as @file{/dev/ttya}, connected to the
14623ST2000 via a serial line. You can instead specify @var{dev} as a TCP
14624connection (for example, to a serial line attached via a terminal
14625concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 14626
8e04817f
AC
14627The @code{load} and @code{attach} commands are @emph{not} defined for
14628this target; you must load your program into the ST2000 as you normally
14629would for standalone operation. @value{GDBN} reads debugging information
14630(such as symbols) from a separate, debugging version of the program
14631available on your host computer.
14632@c FIXME!! This is terribly vague; what little content is here is
14633@c basically hearsay.
104c1213 14634
8e04817f
AC
14635@cindex ST2000 auxiliary commands
14636These auxiliary @value{GDBN} commands are available to help you with the ST2000
14637environment:
104c1213 14638
8e04817f
AC
14639@table @code
14640@item st2000 @var{command}
14641@kindex st2000 @var{cmd}
14642@cindex STDBUG commands (ST2000)
14643@cindex commands to STDBUG (ST2000)
14644Send a @var{command} to the STDBUG monitor. See the manufacturer's
14645manual for available commands.
104c1213 14646
8e04817f
AC
14647@item connect
14648@cindex connect (to STDBUG)
14649Connect the controlling terminal to the STDBUG command monitor. When
14650you are done interacting with STDBUG, typing either of two character
14651sequences gets you back to the @value{GDBN} command prompt:
14652@kbd{@key{RET}~.} (Return, followed by tilde and period) or
14653@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
14654@end table
14655
8e04817f
AC
14656@node Z8000
14657@subsection Zilog Z8000
104c1213 14658
8e04817f
AC
14659@cindex Z8000
14660@cindex simulator, Z8000
14661@cindex Zilog Z8000 simulator
104c1213 14662
8e04817f
AC
14663When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
14664a Z8000 simulator.
14665
14666For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
14667unsegmented variant of the Z8000 architecture) or the Z8001 (the
14668segmented variant). The simulator recognizes which architecture is
14669appropriate by inspecting the object code.
104c1213 14670
8e04817f
AC
14671@table @code
14672@item target sim @var{args}
14673@kindex sim
14674@kindex target sim@r{, with Z8000}
14675Debug programs on a simulated CPU. If the simulator supports setup
14676options, specify them via @var{args}.
104c1213
JM
14677@end table
14678
8e04817f
AC
14679@noindent
14680After specifying this target, you can debug programs for the simulated
14681CPU in the same style as programs for your host computer; use the
14682@code{file} command to load a new program image, the @code{run} command
14683to run your program, and so on.
14684
14685As well as making available all the usual machine registers
14686(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
14687additional items of information as specially named registers:
104c1213
JM
14688
14689@table @code
14690
8e04817f
AC
14691@item cycles
14692Counts clock-ticks in the simulator.
104c1213 14693
8e04817f
AC
14694@item insts
14695Counts instructions run in the simulator.
104c1213 14696
8e04817f
AC
14697@item time
14698Execution time in 60ths of a second.
104c1213 14699
8e04817f 14700@end table
104c1213 14701
8e04817f
AC
14702You can refer to these values in @value{GDBN} expressions with the usual
14703conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
14704conditional breakpoint that suspends only after at least 5000
14705simulated clock ticks.
104c1213 14706
a64548ea
EZ
14707@node AVR
14708@subsection Atmel AVR
14709@cindex AVR
14710
14711When configured for debugging the Atmel AVR, @value{GDBN} supports the
14712following AVR-specific commands:
14713
14714@table @code
14715@item info io_registers
14716@kindex info io_registers@r{, AVR}
14717@cindex I/O registers (Atmel AVR)
14718This command displays information about the AVR I/O registers. For
14719each register, @value{GDBN} prints its number and value.
14720@end table
14721
14722@node CRIS
14723@subsection CRIS
14724@cindex CRIS
14725
14726When configured for debugging CRIS, @value{GDBN} provides the
14727following CRIS-specific commands:
14728
14729@table @code
14730@item set cris-version @var{ver}
14731@cindex CRIS version
e22e55c9
OF
14732Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
14733The CRIS version affects register names and sizes. This command is useful in
14734case autodetection of the CRIS version fails.
a64548ea
EZ
14735
14736@item show cris-version
14737Show the current CRIS version.
14738
14739@item set cris-dwarf2-cfi
14740@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
14741Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
14742Change to @samp{off} when using @code{gcc-cris} whose version is below
14743@code{R59}.
a64548ea
EZ
14744
14745@item show cris-dwarf2-cfi
14746Show the current state of using DWARF-2 CFI.
e22e55c9
OF
14747
14748@item set cris-mode @var{mode}
14749@cindex CRIS mode
14750Set the current CRIS mode to @var{mode}. It should only be changed when
14751debugging in guru mode, in which case it should be set to
14752@samp{guru} (the default is @samp{normal}).
14753
14754@item show cris-mode
14755Show the current CRIS mode.
a64548ea
EZ
14756@end table
14757
14758@node Super-H
14759@subsection Renesas Super-H
14760@cindex Super-H
14761
14762For the Renesas Super-H processor, @value{GDBN} provides these
14763commands:
14764
14765@table @code
14766@item regs
14767@kindex regs@r{, Super-H}
14768Show the values of all Super-H registers.
14769@end table
14770
c45da7e6
EZ
14771@node WinCE
14772@subsection Windows CE
14773@cindex Windows CE
14774
14775The following commands are available for Windows CE:
14776
14777@table @code
14778@item set remotedirectory @var{dir}
14779@kindex set remotedirectory
14780Tell @value{GDBN} to upload files from the named directory @var{dir}.
14781The default is @file{/gdb}, i.e.@: the root directory on the current
14782drive.
14783
14784@item show remotedirectory
14785@kindex show remotedirectory
14786Show the current value of the upload directory.
14787
14788@item set remoteupload @var{method}
14789@kindex set remoteupload
14790Set the method used to upload files to remote device. Valid values
14791for @var{method} are @samp{always}, @samp{newer}, and @samp{never}.
14792The default is @samp{newer}.
14793
14794@item show remoteupload
14795@kindex show remoteupload
14796Show the current setting of the upload method.
14797
14798@item set remoteaddhost
14799@kindex set remoteaddhost
14800Tell @value{GDBN} whether to add this host to the remote stub's
14801arguments when you debug over a network.
14802
14803@item show remoteaddhost
14804@kindex show remoteaddhost
14805Show whether to add this host to remote stub's arguments when
14806debugging over a network.
14807@end table
14808
a64548ea 14809
8e04817f
AC
14810@node Architectures
14811@section Architectures
104c1213 14812
8e04817f
AC
14813This section describes characteristics of architectures that affect
14814all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 14815
8e04817f 14816@menu
9c16f35a 14817* i386::
8e04817f
AC
14818* A29K::
14819* Alpha::
14820* MIPS::
a64548ea 14821* HPPA:: HP PA architecture
8e04817f 14822@end menu
104c1213 14823
9c16f35a
EZ
14824@node i386
14825@subsection x86 Architecture-specific issues.
14826
14827@table @code
14828@item set struct-convention @var{mode}
14829@kindex set struct-convention
14830@cindex struct return convention
14831@cindex struct/union returned in registers
14832Set the convention used by the inferior to return @code{struct}s and
14833@code{union}s from functions to @var{mode}. Possible values of
14834@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
14835default). @code{"default"} or @code{"pcc"} means that @code{struct}s
14836are returned on the stack, while @code{"reg"} means that a
14837@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
14838be returned in a register.
14839
14840@item show struct-convention
14841@kindex show struct-convention
14842Show the current setting of the convention to return @code{struct}s
14843from functions.
14844@end table
14845
8e04817f
AC
14846@node A29K
14847@subsection A29K
104c1213
JM
14848
14849@table @code
104c1213 14850
8e04817f
AC
14851@kindex set rstack_high_address
14852@cindex AMD 29K register stack
14853@cindex register stack, AMD29K
14854@item set rstack_high_address @var{address}
14855On AMD 29000 family processors, registers are saved in a separate
14856@dfn{register stack}. There is no way for @value{GDBN} to determine the
14857extent of this stack. Normally, @value{GDBN} just assumes that the
14858stack is ``large enough''. This may result in @value{GDBN} referencing
14859memory locations that do not exist. If necessary, you can get around
14860this problem by specifying the ending address of the register stack with
14861the @code{set rstack_high_address} command. The argument should be an
14862address, which you probably want to precede with @samp{0x} to specify in
14863hexadecimal.
104c1213 14864
8e04817f
AC
14865@kindex show rstack_high_address
14866@item show rstack_high_address
14867Display the current limit of the register stack, on AMD 29000 family
14868processors.
104c1213 14869
8e04817f 14870@end table
104c1213 14871
8e04817f
AC
14872@node Alpha
14873@subsection Alpha
104c1213 14874
8e04817f 14875See the following section.
104c1213 14876
8e04817f
AC
14877@node MIPS
14878@subsection MIPS
104c1213 14879
8e04817f
AC
14880@cindex stack on Alpha
14881@cindex stack on MIPS
14882@cindex Alpha stack
14883@cindex MIPS stack
14884Alpha- and MIPS-based computers use an unusual stack frame, which
14885sometimes requires @value{GDBN} to search backward in the object code to
14886find the beginning of a function.
104c1213 14887
8e04817f
AC
14888@cindex response time, MIPS debugging
14889To improve response time (especially for embedded applications, where
14890@value{GDBN} may be restricted to a slow serial line for this search)
14891you may want to limit the size of this search, using one of these
14892commands:
104c1213 14893
8e04817f
AC
14894@table @code
14895@cindex @code{heuristic-fence-post} (Alpha, MIPS)
14896@item set heuristic-fence-post @var{limit}
14897Restrict @value{GDBN} to examining at most @var{limit} bytes in its
14898search for the beginning of a function. A value of @var{0} (the
14899default) means there is no limit. However, except for @var{0}, the
14900larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
14901and therefore the longer it takes to run. You should only need to use
14902this command when debugging a stripped executable.
104c1213 14903
8e04817f
AC
14904@item show heuristic-fence-post
14905Display the current limit.
14906@end table
104c1213
JM
14907
14908@noindent
8e04817f
AC
14909These commands are available @emph{only} when @value{GDBN} is configured
14910for debugging programs on Alpha or MIPS processors.
104c1213 14911
a64548ea
EZ
14912Several MIPS-specific commands are available when debugging MIPS
14913programs:
14914
14915@table @code
14916@item set mips saved-gpreg-size @var{size}
14917@kindex set mips saved-gpreg-size
14918@cindex MIPS GP register size on stack
14919Set the size of MIPS general-purpose registers saved on the stack.
14920The argument @var{size} can be one of the following:
14921
14922@table @samp
14923@item 32
1492432-bit GP registers
14925@item 64
1492664-bit GP registers
14927@item auto
14928Use the target's default setting or autodetect the saved size from the
14929information contained in the executable. This is the default
14930@end table
14931
14932@item show mips saved-gpreg-size
14933@kindex show mips saved-gpreg-size
14934Show the current size of MIPS GP registers on the stack.
14935
14936@item set mips stack-arg-size @var{size}
14937@kindex set mips stack-arg-size
14938@cindex MIPS stack space for arguments
14939Set the amount of stack space reserved for arguments to functions.
14940The argument can be one of @code{"32"}, @code{"64"} or @code{"auto"}
14941(the default).
14942
14943@item set mips abi @var{arg}
14944@kindex set mips abi
14945@cindex set ABI for MIPS
14946Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
14947values of @var{arg} are:
14948
14949@table @samp
14950@item auto
14951The default ABI associated with the current binary (this is the
14952default).
14953@item o32
14954@item o64
14955@item n32
14956@item n64
14957@item eabi32
14958@item eabi64
14959@item auto
14960@end table
14961
14962@item show mips abi
14963@kindex show mips abi
14964Show the MIPS ABI used by @value{GDBN} to debug the inferior.
14965
14966@item set mipsfpu
14967@itemx show mipsfpu
14968@xref{MIPS Embedded, set mipsfpu}.
14969
14970@item set mips mask-address @var{arg}
14971@kindex set mips mask-address
14972@cindex MIPS addresses, masking
14973This command determines whether the most-significant 32 bits of 64-bit
14974MIPS addresses are masked off. The argument @var{arg} can be
14975@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
14976setting, which lets @value{GDBN} determine the correct value.
14977
14978@item show mips mask-address
14979@kindex show mips mask-address
14980Show whether the upper 32 bits of MIPS addresses are masked off or
14981not.
14982
14983@item set remote-mips64-transfers-32bit-regs
14984@kindex set remote-mips64-transfers-32bit-regs
14985This command controls compatibility with 64-bit MIPS targets that
14986transfer data in 32-bit quantities. If you have an old MIPS 64 target
14987that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
14988and 64 bits for other registers, set this option to @samp{on}.
14989
14990@item show remote-mips64-transfers-32bit-regs
14991@kindex show remote-mips64-transfers-32bit-regs
14992Show the current setting of compatibility with older MIPS 64 targets.
14993
14994@item set debug mips
14995@kindex set debug mips
14996This command turns on and off debugging messages for the MIPS-specific
14997target code in @value{GDBN}.
14998
14999@item show debug mips
15000@kindex show debug mips
15001Show the current setting of MIPS debugging messages.
15002@end table
15003
15004
15005@node HPPA
15006@subsection HPPA
15007@cindex HPPA support
15008
15009When @value{GDBN} is debugging te HP PA architecture, it provides the
15010following special commands:
15011
15012@table @code
15013@item set debug hppa
15014@kindex set debug hppa
15015THis command determines whether HPPA architecture specific debugging
15016messages are to be displayed.
15017
15018@item show debug hppa
15019Show whether HPPA debugging messages are displayed.
15020
15021@item maint print unwind @var{address}
15022@kindex maint print unwind@r{, HPPA}
15023This command displays the contents of the unwind table entry at the
15024given @var{address}.
15025
15026@end table
15027
104c1213 15028
8e04817f
AC
15029@node Controlling GDB
15030@chapter Controlling @value{GDBN}
15031
15032You can alter the way @value{GDBN} interacts with you by using the
15033@code{set} command. For commands controlling how @value{GDBN} displays
15034data, see @ref{Print Settings, ,Print settings}. Other settings are
15035described here.
15036
15037@menu
15038* Prompt:: Prompt
15039* Editing:: Command editing
d620b259 15040* Command History:: Command history
8e04817f
AC
15041* Screen Size:: Screen size
15042* Numbers:: Numbers
1e698235 15043* ABI:: Configuring the current ABI
8e04817f
AC
15044* Messages/Warnings:: Optional warnings and messages
15045* Debugging Output:: Optional messages about internal happenings
15046@end menu
15047
15048@node Prompt
15049@section Prompt
104c1213 15050
8e04817f 15051@cindex prompt
104c1213 15052
8e04817f
AC
15053@value{GDBN} indicates its readiness to read a command by printing a string
15054called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
15055can change the prompt string with the @code{set prompt} command. For
15056instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
15057the prompt in one of the @value{GDBN} sessions so that you can always tell
15058which one you are talking to.
104c1213 15059
8e04817f
AC
15060@emph{Note:} @code{set prompt} does not add a space for you after the
15061prompt you set. This allows you to set a prompt which ends in a space
15062or a prompt that does not.
104c1213 15063
8e04817f
AC
15064@table @code
15065@kindex set prompt
15066@item set prompt @var{newprompt}
15067Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 15068
8e04817f
AC
15069@kindex show prompt
15070@item show prompt
15071Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
15072@end table
15073
8e04817f
AC
15074@node Editing
15075@section Command editing
15076@cindex readline
15077@cindex command line editing
104c1213 15078
703663ab 15079@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
15080@sc{gnu} library provides consistent behavior for programs which provide a
15081command line interface to the user. Advantages are @sc{gnu} Emacs-style
15082or @dfn{vi}-style inline editing of commands, @code{csh}-like history
15083substitution, and a storage and recall of command history across
15084debugging sessions.
104c1213 15085
8e04817f
AC
15086You may control the behavior of command line editing in @value{GDBN} with the
15087command @code{set}.
104c1213 15088
8e04817f
AC
15089@table @code
15090@kindex set editing
15091@cindex editing
15092@item set editing
15093@itemx set editing on
15094Enable command line editing (enabled by default).
104c1213 15095
8e04817f
AC
15096@item set editing off
15097Disable command line editing.
104c1213 15098
8e04817f
AC
15099@kindex show editing
15100@item show editing
15101Show whether command line editing is enabled.
104c1213
JM
15102@end table
15103
703663ab
EZ
15104@xref{Command Line Editing}, for more details about the Readline
15105interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
15106encouraged to read that chapter.
15107
d620b259 15108@node Command History
8e04817f 15109@section Command history
703663ab 15110@cindex command history
8e04817f
AC
15111
15112@value{GDBN} can keep track of the commands you type during your
15113debugging sessions, so that you can be certain of precisely what
15114happened. Use these commands to manage the @value{GDBN} command
15115history facility.
104c1213 15116
703663ab
EZ
15117@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
15118package, to provide the history facility. @xref{Using History
15119Interactively}, for the detailed description of the History library.
15120
d620b259
NR
15121To issue a command to @value{GDBN} without affecting certain aspects of
15122the state which is seen by users, prefix it with @samp{server }. This
15123means that this command will not affect the command history, nor will it
15124affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
15125pressed on a line by itself.
15126
15127@cindex @code{server}, command prefix
15128The server prefix does not affect the recording of values into the value
15129history; to print a value without recording it into the value history,
15130use the @code{output} command instead of the @code{print} command.
15131
703663ab
EZ
15132Here is the description of @value{GDBN} commands related to command
15133history.
15134
104c1213 15135@table @code
8e04817f
AC
15136@cindex history substitution
15137@cindex history file
15138@kindex set history filename
4644b6e3 15139@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
15140@item set history filename @var{fname}
15141Set the name of the @value{GDBN} command history file to @var{fname}.
15142This is the file where @value{GDBN} reads an initial command history
15143list, and where it writes the command history from this session when it
15144exits. You can access this list through history expansion or through
15145the history command editing characters listed below. This file defaults
15146to the value of the environment variable @code{GDBHISTFILE}, or to
15147@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
15148is not set.
104c1213 15149
9c16f35a
EZ
15150@cindex save command history
15151@kindex set history save
8e04817f
AC
15152@item set history save
15153@itemx set history save on
15154Record command history in a file, whose name may be specified with the
15155@code{set history filename} command. By default, this option is disabled.
104c1213 15156
8e04817f
AC
15157@item set history save off
15158Stop recording command history in a file.
104c1213 15159
8e04817f 15160@cindex history size
9c16f35a 15161@kindex set history size
6fc08d32 15162@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
15163@item set history size @var{size}
15164Set the number of commands which @value{GDBN} keeps in its history list.
15165This defaults to the value of the environment variable
15166@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
15167@end table
15168
8e04817f 15169History expansion assigns special meaning to the character @kbd{!}.
703663ab 15170@xref{Event Designators}, for more details.
8e04817f 15171
703663ab 15172@cindex history expansion, turn on/off
8e04817f
AC
15173Since @kbd{!} is also the logical not operator in C, history expansion
15174is off by default. If you decide to enable history expansion with the
15175@code{set history expansion on} command, you may sometimes need to
15176follow @kbd{!} (when it is used as logical not, in an expression) with
15177a space or a tab to prevent it from being expanded. The readline
15178history facilities do not attempt substitution on the strings
15179@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
15180
15181The commands to control history expansion are:
104c1213
JM
15182
15183@table @code
8e04817f
AC
15184@item set history expansion on
15185@itemx set history expansion
703663ab 15186@kindex set history expansion
8e04817f 15187Enable history expansion. History expansion is off by default.
104c1213 15188
8e04817f
AC
15189@item set history expansion off
15190Disable history expansion.
104c1213 15191
8e04817f
AC
15192@c @group
15193@kindex show history
15194@item show history
15195@itemx show history filename
15196@itemx show history save
15197@itemx show history size
15198@itemx show history expansion
15199These commands display the state of the @value{GDBN} history parameters.
15200@code{show history} by itself displays all four states.
15201@c @end group
15202@end table
15203
15204@table @code
9c16f35a
EZ
15205@kindex show commands
15206@cindex show last commands
15207@cindex display command history
8e04817f
AC
15208@item show commands
15209Display the last ten commands in the command history.
104c1213 15210
8e04817f
AC
15211@item show commands @var{n}
15212Print ten commands centered on command number @var{n}.
15213
15214@item show commands +
15215Print ten commands just after the commands last printed.
104c1213
JM
15216@end table
15217
8e04817f
AC
15218@node Screen Size
15219@section Screen size
15220@cindex size of screen
15221@cindex pauses in output
104c1213 15222
8e04817f
AC
15223Certain commands to @value{GDBN} may produce large amounts of
15224information output to the screen. To help you read all of it,
15225@value{GDBN} pauses and asks you for input at the end of each page of
15226output. Type @key{RET} when you want to continue the output, or @kbd{q}
15227to discard the remaining output. Also, the screen width setting
15228determines when to wrap lines of output. Depending on what is being
15229printed, @value{GDBN} tries to break the line at a readable place,
15230rather than simply letting it overflow onto the following line.
15231
15232Normally @value{GDBN} knows the size of the screen from the terminal
15233driver software. For example, on Unix @value{GDBN} uses the termcap data base
15234together with the value of the @code{TERM} environment variable and the
15235@code{stty rows} and @code{stty cols} settings. If this is not correct,
15236you can override it with the @code{set height} and @code{set
15237width} commands:
15238
15239@table @code
15240@kindex set height
15241@kindex set width
15242@kindex show width
15243@kindex show height
15244@item set height @var{lpp}
15245@itemx show height
15246@itemx set width @var{cpl}
15247@itemx show width
15248These @code{set} commands specify a screen height of @var{lpp} lines and
15249a screen width of @var{cpl} characters. The associated @code{show}
15250commands display the current settings.
104c1213 15251
8e04817f
AC
15252If you specify a height of zero lines, @value{GDBN} does not pause during
15253output no matter how long the output is. This is useful if output is to a
15254file or to an editor buffer.
104c1213 15255
8e04817f
AC
15256Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
15257from wrapping its output.
9c16f35a
EZ
15258
15259@item set pagination on
15260@itemx set pagination off
15261@kindex set pagination
15262Turn the output pagination on or off; the default is on. Turning
15263pagination off is the alternative to @code{set height 0}.
15264
15265@item show pagination
15266@kindex show pagination
15267Show the current pagination mode.
104c1213
JM
15268@end table
15269
8e04817f
AC
15270@node Numbers
15271@section Numbers
15272@cindex number representation
15273@cindex entering numbers
104c1213 15274
8e04817f
AC
15275You can always enter numbers in octal, decimal, or hexadecimal in
15276@value{GDBN} by the usual conventions: octal numbers begin with
15277@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
15278begin with @samp{0x}. Numbers that neither begin with @samp{0} or
15279@samp{0x}, nor end with a @samp{.} are, by default, entered in base
1528010; likewise, the default display for numbers---when no particular
15281format is specified---is base 10. You can change the default base for
15282both input and output with the commands described below.
104c1213 15283
8e04817f
AC
15284@table @code
15285@kindex set input-radix
15286@item set input-radix @var{base}
15287Set the default base for numeric input. Supported choices
15288for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15289specified either unambiguously or using the current input radix; for
8e04817f 15290example, any of
104c1213 15291
8e04817f 15292@smallexample
9c16f35a
EZ
15293set input-radix 012
15294set input-radix 10.
15295set input-radix 0xa
8e04817f 15296@end smallexample
104c1213 15297
8e04817f 15298@noindent
9c16f35a 15299sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
15300leaves the input radix unchanged, no matter what it was, since
15301@samp{10}, being without any leading or trailing signs of its base, is
15302interpreted in the current radix. Thus, if the current radix is 16,
15303@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
15304change the radix.
104c1213 15305
8e04817f
AC
15306@kindex set output-radix
15307@item set output-radix @var{base}
15308Set the default base for numeric display. Supported choices
15309for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15310specified either unambiguously or using the current input radix.
104c1213 15311
8e04817f
AC
15312@kindex show input-radix
15313@item show input-radix
15314Display the current default base for numeric input.
104c1213 15315
8e04817f
AC
15316@kindex show output-radix
15317@item show output-radix
15318Display the current default base for numeric display.
9c16f35a
EZ
15319
15320@item set radix @r{[}@var{base}@r{]}
15321@itemx show radix
15322@kindex set radix
15323@kindex show radix
15324These commands set and show the default base for both input and output
15325of numbers. @code{set radix} sets the radix of input and output to
15326the same base; without an argument, it resets the radix back to its
15327default value of 10.
15328
8e04817f 15329@end table
104c1213 15330
1e698235
DJ
15331@node ABI
15332@section Configuring the current ABI
15333
15334@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
15335application automatically. However, sometimes you need to override its
15336conclusions. Use these commands to manage @value{GDBN}'s view of the
15337current ABI.
15338
98b45e30
DJ
15339@cindex OS ABI
15340@kindex set osabi
b4e9345d 15341@kindex show osabi
98b45e30
DJ
15342
15343One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 15344system targets, either via remote debugging or native emulation.
98b45e30
DJ
15345@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
15346but you can override its conclusion using the @code{set osabi} command.
15347One example where this is useful is in debugging of binaries which use
15348an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
15349not have the same identifying marks that the standard C library for your
15350platform provides.
15351
15352@table @code
15353@item show osabi
15354Show the OS ABI currently in use.
15355
15356@item set osabi
15357With no argument, show the list of registered available OS ABI's.
15358
15359@item set osabi @var{abi}
15360Set the current OS ABI to @var{abi}.
15361@end table
15362
1e698235 15363@cindex float promotion
1e698235
DJ
15364
15365Generally, the way that an argument of type @code{float} is passed to a
15366function depends on whether the function is prototyped. For a prototyped
15367(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
15368according to the architecture's convention for @code{float}. For unprototyped
15369(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
15370@code{double} and then passed.
15371
15372Unfortunately, some forms of debug information do not reliably indicate whether
15373a function is prototyped. If @value{GDBN} calls a function that is not marked
15374as prototyped, it consults @kbd{set coerce-float-to-double}.
15375
15376@table @code
a8f24a35 15377@kindex set coerce-float-to-double
1e698235
DJ
15378@item set coerce-float-to-double
15379@itemx set coerce-float-to-double on
15380Arguments of type @code{float} will be promoted to @code{double} when passed
15381to an unprototyped function. This is the default setting.
15382
15383@item set coerce-float-to-double off
15384Arguments of type @code{float} will be passed directly to unprototyped
15385functions.
9c16f35a
EZ
15386
15387@kindex show coerce-float-to-double
15388@item show coerce-float-to-double
15389Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
15390@end table
15391
f1212245
DJ
15392@kindex set cp-abi
15393@kindex show cp-abi
15394@value{GDBN} needs to know the ABI used for your program's C@t{++}
15395objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
15396used to build your application. @value{GDBN} only fully supports
15397programs with a single C@t{++} ABI; if your program contains code using
15398multiple C@t{++} ABI's or if @value{GDBN} can not identify your
15399program's ABI correctly, you can tell @value{GDBN} which ABI to use.
15400Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
15401before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
15402``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
15403use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
15404``auto''.
15405
15406@table @code
15407@item show cp-abi
15408Show the C@t{++} ABI currently in use.
15409
15410@item set cp-abi
15411With no argument, show the list of supported C@t{++} ABI's.
15412
15413@item set cp-abi @var{abi}
15414@itemx set cp-abi auto
15415Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
15416@end table
15417
8e04817f
AC
15418@node Messages/Warnings
15419@section Optional warnings and messages
104c1213 15420
9c16f35a
EZ
15421@cindex verbose operation
15422@cindex optional warnings
8e04817f
AC
15423By default, @value{GDBN} is silent about its inner workings. If you are
15424running on a slow machine, you may want to use the @code{set verbose}
15425command. This makes @value{GDBN} tell you when it does a lengthy
15426internal operation, so you will not think it has crashed.
104c1213 15427
8e04817f
AC
15428Currently, the messages controlled by @code{set verbose} are those
15429which announce that the symbol table for a source file is being read;
15430see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 15431
8e04817f
AC
15432@table @code
15433@kindex set verbose
15434@item set verbose on
15435Enables @value{GDBN} output of certain informational messages.
104c1213 15436
8e04817f
AC
15437@item set verbose off
15438Disables @value{GDBN} output of certain informational messages.
104c1213 15439
8e04817f
AC
15440@kindex show verbose
15441@item show verbose
15442Displays whether @code{set verbose} is on or off.
15443@end table
104c1213 15444
8e04817f
AC
15445By default, if @value{GDBN} encounters bugs in the symbol table of an
15446object file, it is silent; but if you are debugging a compiler, you may
15447find this information useful (@pxref{Symbol Errors, ,Errors reading
15448symbol files}).
104c1213 15449
8e04817f 15450@table @code
104c1213 15451
8e04817f
AC
15452@kindex set complaints
15453@item set complaints @var{limit}
15454Permits @value{GDBN} to output @var{limit} complaints about each type of
15455unusual symbols before becoming silent about the problem. Set
15456@var{limit} to zero to suppress all complaints; set it to a large number
15457to prevent complaints from being suppressed.
104c1213 15458
8e04817f
AC
15459@kindex show complaints
15460@item show complaints
15461Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 15462
8e04817f 15463@end table
104c1213 15464
8e04817f
AC
15465By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
15466lot of stupid questions to confirm certain commands. For example, if
15467you try to run a program which is already running:
104c1213 15468
474c8240 15469@smallexample
8e04817f
AC
15470(@value{GDBP}) run
15471The program being debugged has been started already.
15472Start it from the beginning? (y or n)
474c8240 15473@end smallexample
104c1213 15474
8e04817f
AC
15475If you are willing to unflinchingly face the consequences of your own
15476commands, you can disable this ``feature'':
104c1213 15477
8e04817f 15478@table @code
104c1213 15479
8e04817f
AC
15480@kindex set confirm
15481@cindex flinching
15482@cindex confirmation
15483@cindex stupid questions
15484@item set confirm off
15485Disables confirmation requests.
104c1213 15486
8e04817f
AC
15487@item set confirm on
15488Enables confirmation requests (the default).
104c1213 15489
8e04817f
AC
15490@kindex show confirm
15491@item show confirm
15492Displays state of confirmation requests.
15493
15494@end table
104c1213 15495
8e04817f
AC
15496@node Debugging Output
15497@section Optional messages about internal happenings
4644b6e3
EZ
15498@cindex optional debugging messages
15499
da316a69
EZ
15500@value{GDBN} has commands that enable optional debugging messages from
15501various @value{GDBN} subsystems; normally these commands are of
15502interest to @value{GDBN} maintainers, or when reporting a bug. This
15503section documents those commands.
15504
104c1213 15505@table @code
a8f24a35
EZ
15506@kindex set exec-done-display
15507@item set exec-done-display
15508Turns on or off the notification of asynchronous commands'
15509completion. When on, @value{GDBN} will print a message when an
15510asynchronous command finishes its execution. The default is off.
15511@kindex show exec-done-display
15512@item show exec-done-display
15513Displays the current setting of asynchronous command completion
15514notification.
4644b6e3
EZ
15515@kindex set debug
15516@cindex gdbarch debugging info
a8f24a35 15517@cindex architecture debugging info
8e04817f 15518@item set debug arch
a8f24a35 15519Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 15520@kindex show debug
8e04817f
AC
15521@item show debug arch
15522Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
15523@item set debug aix-thread
15524@cindex AIX threads
15525Display debugging messages about inner workings of the AIX thread
15526module.
15527@item show debug aix-thread
15528Show the current state of AIX thread debugging info display.
8e04817f 15529@item set debug event
4644b6e3 15530@cindex event debugging info
a8f24a35 15531Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 15532default is off.
8e04817f
AC
15533@item show debug event
15534Displays the current state of displaying @value{GDBN} event debugging
15535info.
8e04817f 15536@item set debug expression
4644b6e3 15537@cindex expression debugging info
721c2651
EZ
15538Turns on or off display of debugging info about @value{GDBN}
15539expression parsing. The default is off.
8e04817f 15540@item show debug expression
721c2651
EZ
15541Displays the current state of displaying debugging info about
15542@value{GDBN} expression parsing.
7453dc06 15543@item set debug frame
4644b6e3 15544@cindex frame debugging info
7453dc06
AC
15545Turns on or off display of @value{GDBN} frame debugging info. The
15546default is off.
7453dc06
AC
15547@item show debug frame
15548Displays the current state of displaying @value{GDBN} frame debugging
15549info.
30e91e0b
RC
15550@item set debug infrun
15551@cindex inferior debugging info
15552Turns on or off display of @value{GDBN} debugging info for running the inferior.
15553The default is off. @file{infrun.c} contains GDB's runtime state machine used
15554for implementing operations such as single-stepping the inferior.
15555@item show debug infrun
15556Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
15557@item set debug lin-lwp
15558@cindex @sc{gnu}/Linux LWP debug messages
15559@cindex Linux lightweight processes
721c2651 15560Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
15561@item show debug lin-lwp
15562Show the current state of Linux LWP debugging messages.
2b4855ab 15563@item set debug observer
4644b6e3 15564@cindex observer debugging info
2b4855ab
AC
15565Turns on or off display of @value{GDBN} observer debugging. This
15566includes info such as the notification of observable events.
2b4855ab
AC
15567@item show debug observer
15568Displays the current state of observer debugging.
8e04817f 15569@item set debug overload
4644b6e3 15570@cindex C@t{++} overload debugging info
8e04817f
AC
15571Turns on or off display of @value{GDBN} C@t{++} overload debugging
15572info. This includes info such as ranking of functions, etc. The default
15573is off.
8e04817f
AC
15574@item show debug overload
15575Displays the current state of displaying @value{GDBN} C@t{++} overload
15576debugging info.
8e04817f
AC
15577@cindex packets, reporting on stdout
15578@cindex serial connections, debugging
15579@item set debug remote
15580Turns on or off display of reports on all packets sent back and forth across
15581the serial line to the remote machine. The info is printed on the
15582@value{GDBN} standard output stream. The default is off.
8e04817f
AC
15583@item show debug remote
15584Displays the state of display of remote packets.
8e04817f
AC
15585@item set debug serial
15586Turns on or off display of @value{GDBN} serial debugging info. The
15587default is off.
8e04817f
AC
15588@item show debug serial
15589Displays the current state of displaying @value{GDBN} serial debugging
15590info.
c45da7e6
EZ
15591@item set debug solib-frv
15592@cindex FR-V shared-library debugging
15593Turns on or off debugging messages for FR-V shared-library code.
15594@item show debug solib-frv
15595Display the current state of FR-V shared-library code debugging
15596messages.
8e04817f 15597@item set debug target
4644b6e3 15598@cindex target debugging info
8e04817f
AC
15599Turns on or off display of @value{GDBN} target debugging info. This info
15600includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
15601default is 0. Set it to 1 to track events, and to 2 to also track the
15602value of large memory transfers. Changes to this flag do not take effect
15603until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
15604@item show debug target
15605Displays the current state of displaying @value{GDBN} target debugging
15606info.
c45da7e6 15607@item set debugvarobj
4644b6e3 15608@cindex variable object debugging info
8e04817f
AC
15609Turns on or off display of @value{GDBN} variable object debugging
15610info. The default is off.
c45da7e6 15611@item show debugvarobj
8e04817f
AC
15612Displays the current state of displaying @value{GDBN} variable object
15613debugging info.
15614@end table
104c1213 15615
8e04817f
AC
15616@node Sequences
15617@chapter Canned Sequences of Commands
104c1213 15618
8e04817f
AC
15619Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
15620command lists}), @value{GDBN} provides two ways to store sequences of
15621commands for execution as a unit: user-defined commands and command
15622files.
104c1213 15623
8e04817f
AC
15624@menu
15625* Define:: User-defined commands
15626* Hooks:: User-defined command hooks
15627* Command Files:: Command files
15628* Output:: Commands for controlled output
15629@end menu
104c1213 15630
8e04817f
AC
15631@node Define
15632@section User-defined commands
104c1213 15633
8e04817f
AC
15634@cindex user-defined command
15635A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
15636which you assign a new name as a command. This is done with the
15637@code{define} command. User commands may accept up to 10 arguments
15638separated by whitespace. Arguments are accessed within the user command
15639via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 15640
8e04817f
AC
15641@smallexample
15642define adder
15643 print $arg0 + $arg1 + $arg2
15644@end smallexample
104c1213
JM
15645
15646@noindent
8e04817f 15647To execute the command use:
104c1213 15648
8e04817f
AC
15649@smallexample
15650adder 1 2 3
15651@end smallexample
104c1213 15652
8e04817f
AC
15653@noindent
15654This defines the command @code{adder}, which prints the sum of
15655its three arguments. Note the arguments are text substitutions, so they may
15656reference variables, use complex expressions, or even perform inferior
15657functions calls.
104c1213
JM
15658
15659@table @code
104c1213 15660
8e04817f
AC
15661@kindex define
15662@item define @var{commandname}
15663Define a command named @var{commandname}. If there is already a command
15664by that name, you are asked to confirm that you want to redefine it.
104c1213 15665
8e04817f
AC
15666The definition of the command is made up of other @value{GDBN} command lines,
15667which are given following the @code{define} command. The end of these
15668commands is marked by a line containing @code{end}.
104c1213 15669
8e04817f
AC
15670@kindex if
15671@kindex else
15672@item if
09d4efe1 15673@itemx else
8e04817f
AC
15674Takes a single argument, which is an expression to evaluate.
15675It is followed by a series of commands that are executed
15676only if the expression is true (nonzero).
15677There can then optionally be a line @code{else}, followed
15678by a series of commands that are only executed if the expression
15679was false. The end of the list is marked by a line containing @code{end}.
104c1213 15680
8e04817f
AC
15681@kindex while
15682@item while
15683The syntax is similar to @code{if}: the command takes a single argument,
15684which is an expression to evaluate, and must be followed by the commands to
15685execute, one per line, terminated by an @code{end}.
15686The commands are executed repeatedly as long as the expression
15687evaluates to true.
104c1213 15688
8e04817f
AC
15689@kindex document
15690@item document @var{commandname}
15691Document the user-defined command @var{commandname}, so that it can be
15692accessed by @code{help}. The command @var{commandname} must already be
15693defined. This command reads lines of documentation just as @code{define}
15694reads the lines of the command definition, ending with @code{end}.
15695After the @code{document} command is finished, @code{help} on command
15696@var{commandname} displays the documentation you have written.
104c1213 15697
8e04817f
AC
15698You may use the @code{document} command again to change the
15699documentation of a command. Redefining the command with @code{define}
15700does not change the documentation.
104c1213 15701
c45da7e6
EZ
15702@kindex dont-repeat
15703@cindex don't repeat command
15704@item dont-repeat
15705Used inside a user-defined command, this tells @value{GDBN} that this
15706command should not be repeated when the user hits @key{RET}
15707(@pxref{Command Syntax, repeat last command}).
15708
8e04817f
AC
15709@kindex help user-defined
15710@item help user-defined
15711List all user-defined commands, with the first line of the documentation
15712(if any) for each.
104c1213 15713
8e04817f
AC
15714@kindex show user
15715@item show user
15716@itemx show user @var{commandname}
15717Display the @value{GDBN} commands used to define @var{commandname} (but
15718not its documentation). If no @var{commandname} is given, display the
15719definitions for all user-defined commands.
104c1213 15720
9c16f35a 15721@cindex infinite recusrion in user-defined commands
20f01a46
DH
15722@kindex show max-user-call-depth
15723@kindex set max-user-call-depth
15724@item show max-user-call-depth
5ca0cb28
DH
15725@itemx set max-user-call-depth
15726The value of @code{max-user-call-depth} controls how many recursion
15727levels are allowed in user-defined commands before GDB suspects an
15728infinite recursion and aborts the command.
20f01a46 15729
104c1213
JM
15730@end table
15731
8e04817f
AC
15732When user-defined commands are executed, the
15733commands of the definition are not printed. An error in any command
15734stops execution of the user-defined command.
104c1213 15735
8e04817f
AC
15736If used interactively, commands that would ask for confirmation proceed
15737without asking when used inside a user-defined command. Many @value{GDBN}
15738commands that normally print messages to say what they are doing omit the
15739messages when used in a user-defined command.
104c1213 15740
8e04817f
AC
15741@node Hooks
15742@section User-defined command hooks
15743@cindex command hooks
15744@cindex hooks, for commands
15745@cindex hooks, pre-command
104c1213 15746
8e04817f 15747@kindex hook
8e04817f
AC
15748You may define @dfn{hooks}, which are a special kind of user-defined
15749command. Whenever you run the command @samp{foo}, if the user-defined
15750command @samp{hook-foo} exists, it is executed (with no arguments)
15751before that command.
104c1213 15752
8e04817f
AC
15753@cindex hooks, post-command
15754@kindex hookpost
8e04817f
AC
15755A hook may also be defined which is run after the command you executed.
15756Whenever you run the command @samp{foo}, if the user-defined command
15757@samp{hookpost-foo} exists, it is executed (with no arguments) after
15758that command. Post-execution hooks may exist simultaneously with
15759pre-execution hooks, for the same command.
104c1213 15760
8e04817f 15761It is valid for a hook to call the command which it hooks. If this
9f1c6395 15762occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 15763
8e04817f
AC
15764@c It would be nice if hookpost could be passed a parameter indicating
15765@c if the command it hooks executed properly or not. FIXME!
104c1213 15766
8e04817f
AC
15767@kindex stop@r{, a pseudo-command}
15768In addition, a pseudo-command, @samp{stop} exists. Defining
15769(@samp{hook-stop}) makes the associated commands execute every time
15770execution stops in your program: before breakpoint commands are run,
15771displays are printed, or the stack frame is printed.
104c1213 15772
8e04817f
AC
15773For example, to ignore @code{SIGALRM} signals while
15774single-stepping, but treat them normally during normal execution,
15775you could define:
104c1213 15776
474c8240 15777@smallexample
8e04817f
AC
15778define hook-stop
15779handle SIGALRM nopass
15780end
104c1213 15781
8e04817f
AC
15782define hook-run
15783handle SIGALRM pass
15784end
104c1213 15785
8e04817f
AC
15786define hook-continue
15787handle SIGLARM pass
15788end
474c8240 15789@end smallexample
104c1213 15790
8e04817f 15791As a further example, to hook at the begining and end of the @code{echo}
b383017d 15792command, and to add extra text to the beginning and end of the message,
8e04817f 15793you could define:
104c1213 15794
474c8240 15795@smallexample
8e04817f
AC
15796define hook-echo
15797echo <<<---
15798end
104c1213 15799
8e04817f
AC
15800define hookpost-echo
15801echo --->>>\n
15802end
104c1213 15803
8e04817f
AC
15804(@value{GDBP}) echo Hello World
15805<<<---Hello World--->>>
15806(@value{GDBP})
104c1213 15807
474c8240 15808@end smallexample
104c1213 15809
8e04817f
AC
15810You can define a hook for any single-word command in @value{GDBN}, but
15811not for command aliases; you should define a hook for the basic command
15812name, e.g. @code{backtrace} rather than @code{bt}.
15813@c FIXME! So how does Joe User discover whether a command is an alias
15814@c or not?
15815If an error occurs during the execution of your hook, execution of
15816@value{GDBN} commands stops and @value{GDBN} issues a prompt
15817(before the command that you actually typed had a chance to run).
104c1213 15818
8e04817f
AC
15819If you try to define a hook which does not match any known command, you
15820get a warning from the @code{define} command.
c906108c 15821
8e04817f
AC
15822@node Command Files
15823@section Command files
c906108c 15824
8e04817f 15825@cindex command files
6fc08d32
EZ
15826A command file for @value{GDBN} is a text file made of lines that are
15827@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
15828also be included. An empty line in a command file does nothing; it
15829does not mean to repeat the last command, as it would from the
15830terminal.
c906108c 15831
6fc08d32
EZ
15832You can request the execution of a command file with the @code{source}
15833command:
c906108c 15834
8e04817f
AC
15835@table @code
15836@kindex source
15837@item source @var{filename}
15838Execute the command file @var{filename}.
c906108c
SS
15839@end table
15840
8e04817f 15841The lines in a command file are executed sequentially. They are not
a71ec265
DH
15842printed as they are executed. An error in any command terminates
15843execution of the command file and control is returned to the console.
c906108c 15844
8e04817f
AC
15845Commands that would ask for confirmation if used interactively proceed
15846without asking when used in a command file. Many @value{GDBN} commands that
15847normally print messages to say what they are doing omit the messages
15848when called from command files.
c906108c 15849
8e04817f
AC
15850@value{GDBN} also accepts command input from standard input. In this
15851mode, normal output goes to standard output and error output goes to
15852standard error. Errors in a command file supplied on standard input do
6fc08d32 15853not terminate execution of the command file---execution continues with
8e04817f 15854the next command.
c906108c 15855
474c8240 15856@smallexample
8e04817f 15857gdb < cmds > log 2>&1
474c8240 15858@end smallexample
c906108c 15859
8e04817f
AC
15860(The syntax above will vary depending on the shell used.) This example
15861will execute commands from the file @file{cmds}. All output and errors
15862would be directed to @file{log}.
c906108c 15863
8e04817f
AC
15864@node Output
15865@section Commands for controlled output
c906108c 15866
8e04817f
AC
15867During the execution of a command file or a user-defined command, normal
15868@value{GDBN} output is suppressed; the only output that appears is what is
15869explicitly printed by the commands in the definition. This section
15870describes three commands useful for generating exactly the output you
15871want.
c906108c
SS
15872
15873@table @code
8e04817f
AC
15874@kindex echo
15875@item echo @var{text}
15876@c I do not consider backslash-space a standard C escape sequence
15877@c because it is not in ANSI.
15878Print @var{text}. Nonprinting characters can be included in
15879@var{text} using C escape sequences, such as @samp{\n} to print a
15880newline. @strong{No newline is printed unless you specify one.}
15881In addition to the standard C escape sequences, a backslash followed
15882by a space stands for a space. This is useful for displaying a
15883string with spaces at the beginning or the end, since leading and
15884trailing spaces are otherwise trimmed from all arguments.
15885To print @samp{@w{ }and foo =@w{ }}, use the command
15886@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 15887
8e04817f
AC
15888A backslash at the end of @var{text} can be used, as in C, to continue
15889the command onto subsequent lines. For example,
c906108c 15890
474c8240 15891@smallexample
8e04817f
AC
15892echo This is some text\n\
15893which is continued\n\
15894onto several lines.\n
474c8240 15895@end smallexample
c906108c 15896
8e04817f 15897produces the same output as
c906108c 15898
474c8240 15899@smallexample
8e04817f
AC
15900echo This is some text\n
15901echo which is continued\n
15902echo onto several lines.\n
474c8240 15903@end smallexample
c906108c 15904
8e04817f
AC
15905@kindex output
15906@item output @var{expression}
15907Print the value of @var{expression} and nothing but that value: no
15908newlines, no @samp{$@var{nn} = }. The value is not entered in the
15909value history either. @xref{Expressions, ,Expressions}, for more information
15910on expressions.
c906108c 15911
8e04817f
AC
15912@item output/@var{fmt} @var{expression}
15913Print the value of @var{expression} in format @var{fmt}. You can use
15914the same formats as for @code{print}. @xref{Output Formats,,Output
15915formats}, for more information.
c906108c 15916
8e04817f
AC
15917@kindex printf
15918@item printf @var{string}, @var{expressions}@dots{}
15919Print the values of the @var{expressions} under the control of
15920@var{string}. The @var{expressions} are separated by commas and may be
15921either numbers or pointers. Their values are printed as specified by
15922@var{string}, exactly as if your program were to execute the C
15923subroutine
15924@c FIXME: the above implies that at least all ANSI C formats are
15925@c supported, but it isn't true: %E and %G don't work (or so it seems).
15926@c Either this is a bug, or the manual should document what formats are
15927@c supported.
c906108c 15928
474c8240 15929@smallexample
8e04817f 15930printf (@var{string}, @var{expressions}@dots{});
474c8240 15931@end smallexample
c906108c 15932
8e04817f 15933For example, you can print two values in hex like this:
c906108c 15934
8e04817f
AC
15935@smallexample
15936printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
15937@end smallexample
c906108c 15938
8e04817f
AC
15939The only backslash-escape sequences that you can use in the format
15940string are the simple ones that consist of backslash followed by a
15941letter.
c906108c
SS
15942@end table
15943
21c294e6
AC
15944@node Interpreters
15945@chapter Command Interpreters
15946@cindex command interpreters
15947
15948@value{GDBN} supports multiple command interpreters, and some command
15949infrastructure to allow users or user interface writers to switch
15950between interpreters or run commands in other interpreters.
15951
15952@value{GDBN} currently supports two command interpreters, the console
15953interpreter (sometimes called the command-line interpreter or @sc{cli})
15954and the machine interface interpreter (or @sc{gdb/mi}). This manual
15955describes both of these interfaces in great detail.
15956
15957By default, @value{GDBN} will start with the console interpreter.
15958However, the user may choose to start @value{GDBN} with another
15959interpreter by specifying the @option{-i} or @option{--interpreter}
15960startup options. Defined interpreters include:
15961
15962@table @code
15963@item console
15964@cindex console interpreter
15965The traditional console or command-line interpreter. This is the most often
15966used interpreter with @value{GDBN}. With no interpreter specified at runtime,
15967@value{GDBN} will use this interpreter.
15968
15969@item mi
15970@cindex mi interpreter
15971The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
15972by programs wishing to use @value{GDBN} as a backend for a debugger GUI
15973or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
15974Interface}.
15975
15976@item mi2
15977@cindex mi2 interpreter
15978The current @sc{gdb/mi} interface.
15979
15980@item mi1
15981@cindex mi1 interpreter
15982The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
15983
15984@end table
15985
15986@cindex invoke another interpreter
15987The interpreter being used by @value{GDBN} may not be dynamically
15988switched at runtime. Although possible, this could lead to a very
15989precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
15990enters the command "interpreter-set console" in a console view,
15991@value{GDBN} would switch to using the console interpreter, rendering
15992the IDE inoperable!
15993
15994@kindex interpreter-exec
15995Although you may only choose a single interpreter at startup, you may execute
15996commands in any interpreter from the current interpreter using the appropriate
15997command. If you are running the console interpreter, simply use the
15998@code{interpreter-exec} command:
15999
16000@smallexample
16001interpreter-exec mi "-data-list-register-names"
16002@end smallexample
16003
16004@sc{gdb/mi} has a similar command, although it is only available in versions of
16005@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
16006
8e04817f
AC
16007@node TUI
16008@chapter @value{GDBN} Text User Interface
16009@cindex TUI
d0d5df6f 16010@cindex Text User Interface
c906108c 16011
8e04817f
AC
16012@menu
16013* TUI Overview:: TUI overview
16014* TUI Keys:: TUI key bindings
7cf36c78 16015* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
16016* TUI Commands:: TUI specific commands
16017* TUI Configuration:: TUI configuration variables
16018@end menu
c906108c 16019
d0d5df6f
AC
16020The @value{GDBN} Text User Interface, TUI in short, is a terminal
16021interface which uses the @code{curses} library to show the source
16022file, the assembly output, the program registers and @value{GDBN}
16023commands in separate text windows.
16024
16025The TUI is enabled by invoking @value{GDBN} using either
16026@pindex gdbtui
16027@samp{gdbtui} or @samp{gdb -tui}.
c906108c 16028
8e04817f
AC
16029@node TUI Overview
16030@section TUI overview
c906108c 16031
8e04817f
AC
16032The TUI has two display modes that can be switched while
16033@value{GDBN} runs:
c906108c 16034
8e04817f
AC
16035@itemize @bullet
16036@item
16037A curses (or TUI) mode in which it displays several text
16038windows on the terminal.
c906108c 16039
8e04817f
AC
16040@item
16041A standard mode which corresponds to the @value{GDBN} configured without
16042the TUI.
16043@end itemize
c906108c 16044
8e04817f
AC
16045In the TUI mode, @value{GDBN} can display several text window
16046on the terminal:
c906108c 16047
8e04817f
AC
16048@table @emph
16049@item command
16050This window is the @value{GDBN} command window with the @value{GDBN}
16051prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
16052managed using readline but through the TUI. The @emph{command}
16053window is always visible.
c906108c 16054
8e04817f
AC
16055@item source
16056The source window shows the source file of the program. The current
16057line as well as active breakpoints are displayed in this window.
c906108c 16058
8e04817f
AC
16059@item assembly
16060The assembly window shows the disassembly output of the program.
c906108c 16061
8e04817f
AC
16062@item register
16063This window shows the processor registers. It detects when
16064a register is changed and when this is the case, registers that have
6a1b180d 16065changed are highlighted.
c906108c 16066
c906108c
SS
16067@end table
16068
269c21fe
SC
16069The source and assembly windows show the current program position
16070by highlighting the current line and marking them with the @samp{>} marker.
16071Breakpoints are also indicated with two markers. A first one
16072indicates the breakpoint type:
16073
16074@table @code
16075@item B
16076Breakpoint which was hit at least once.
16077
16078@item b
16079Breakpoint which was never hit.
16080
16081@item H
16082Hardware breakpoint which was hit at least once.
16083
16084@item h
16085Hardware breakpoint which was never hit.
16086
16087@end table
16088
16089The second marker indicates whether the breakpoint is enabled or not:
16090
16091@table @code
16092@item +
16093Breakpoint is enabled.
16094
16095@item -
16096Breakpoint is disabled.
16097
16098@end table
16099
8e04817f
AC
16100The source, assembly and register windows are attached to the thread
16101and the frame position. They are updated when the current thread
16102changes, when the frame changes or when the program counter changes.
16103These three windows are arranged by the TUI according to several
16104layouts. The layout defines which of these three windows are visible.
16105The following layouts are available:
c906108c 16106
8e04817f
AC
16107@itemize @bullet
16108@item
16109source
2df3850c 16110
8e04817f
AC
16111@item
16112assembly
16113
16114@item
16115source and assembly
16116
16117@item
16118source and registers
c906108c 16119
8e04817f
AC
16120@item
16121assembly and registers
2df3850c 16122
8e04817f 16123@end itemize
c906108c 16124
b7bb15bc
SC
16125On top of the command window a status line gives various information
16126concerning the current process begin debugged. The status line is
16127updated when the information it shows changes. The following fields
16128are displayed:
16129
16130@table @emph
16131@item target
16132Indicates the current gdb target
16133(@pxref{Targets, ,Specifying a Debugging Target}).
16134
16135@item process
16136Gives information about the current process or thread number.
16137When no process is being debugged, this field is set to @code{No process}.
16138
16139@item function
16140Gives the current function name for the selected frame.
16141The name is demangled if demangling is turned on (@pxref{Print Settings}).
16142When there is no symbol corresponding to the current program counter
16143the string @code{??} is displayed.
16144
16145@item line
16146Indicates the current line number for the selected frame.
16147When the current line number is not known the string @code{??} is displayed.
16148
16149@item pc
16150Indicates the current program counter address.
16151
16152@end table
16153
8e04817f
AC
16154@node TUI Keys
16155@section TUI Key Bindings
16156@cindex TUI key bindings
c906108c 16157
8e04817f
AC
16158The TUI installs several key bindings in the readline keymaps
16159(@pxref{Command Line Editing}).
16160They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
16161directly on the TUI layout and windows. The TUI also provides
16162a @emph{SingleKey} keymap which binds several keys directly to
16163@value{GDBN} commands. The following key bindings
8e04817f 16164are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 16165
8e04817f
AC
16166@table @kbd
16167@kindex C-x C-a
16168@item C-x C-a
16169@kindex C-x a
16170@itemx C-x a
16171@kindex C-x A
16172@itemx C-x A
16173Enter or leave the TUI mode. When the TUI mode is left,
16174the curses window management is left and @value{GDBN} operates using
16175its standard mode writing on the terminal directly. When the TUI
16176mode is entered, the control is given back to the curses windows.
16177The screen is then refreshed.
c906108c 16178
8e04817f
AC
16179@kindex C-x 1
16180@item C-x 1
16181Use a TUI layout with only one window. The layout will
16182either be @samp{source} or @samp{assembly}. When the TUI mode
16183is not active, it will switch to the TUI mode.
2df3850c 16184
8e04817f 16185Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 16186
8e04817f
AC
16187@kindex C-x 2
16188@item C-x 2
16189Use a TUI layout with at least two windows. When the current
16190layout shows already two windows, a next layout with two windows is used.
16191When a new layout is chosen, one window will always be common to the
16192previous layout and the new one.
c906108c 16193
8e04817f 16194Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 16195
72ffddc9
SC
16196@kindex C-x o
16197@item C-x o
16198Change the active window. The TUI associates several key bindings
16199(like scrolling and arrow keys) to the active window. This command
16200gives the focus to the next TUI window.
16201
16202Think of it as the Emacs @kbd{C-x o} binding.
16203
7cf36c78
SC
16204@kindex C-x s
16205@item C-x s
16206Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
16207(@pxref{TUI Single Key Mode}).
16208
c906108c
SS
16209@end table
16210
8e04817f 16211The following key bindings are handled only by the TUI mode:
5d161b24 16212
8e04817f
AC
16213@table @key
16214@kindex PgUp
16215@item PgUp
16216Scroll the active window one page up.
c906108c 16217
8e04817f
AC
16218@kindex PgDn
16219@item PgDn
16220Scroll the active window one page down.
c906108c 16221
8e04817f
AC
16222@kindex Up
16223@item Up
16224Scroll the active window one line up.
c906108c 16225
8e04817f
AC
16226@kindex Down
16227@item Down
16228Scroll the active window one line down.
c906108c 16229
8e04817f
AC
16230@kindex Left
16231@item Left
16232Scroll the active window one column left.
c906108c 16233
8e04817f
AC
16234@kindex Right
16235@item Right
16236Scroll the active window one column right.
c906108c 16237
8e04817f
AC
16238@kindex C-L
16239@item C-L
16240Refresh the screen.
c906108c 16241
8e04817f 16242@end table
c906108c 16243
8e04817f 16244In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
16245for scrolling. This means they are available for readline when the
16246active window is the command window. When the command window
16247does not have the focus, it is necessary to use other readline
16248key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 16249
7cf36c78
SC
16250@node TUI Single Key Mode
16251@section TUI Single Key Mode
16252@cindex TUI single key mode
16253
16254The TUI provides a @emph{SingleKey} mode in which it installs a particular
16255key binding in the readline keymaps to connect single keys to
b383017d 16256some gdb commands.
7cf36c78
SC
16257
16258@table @kbd
16259@kindex c @r{(SingleKey TUI key)}
16260@item c
16261continue
16262
16263@kindex d @r{(SingleKey TUI key)}
16264@item d
16265down
16266
16267@kindex f @r{(SingleKey TUI key)}
16268@item f
16269finish
16270
16271@kindex n @r{(SingleKey TUI key)}
16272@item n
16273next
16274
16275@kindex q @r{(SingleKey TUI key)}
16276@item q
16277exit the @emph{SingleKey} mode.
16278
16279@kindex r @r{(SingleKey TUI key)}
16280@item r
16281run
16282
16283@kindex s @r{(SingleKey TUI key)}
16284@item s
16285step
16286
16287@kindex u @r{(SingleKey TUI key)}
16288@item u
16289up
16290
16291@kindex v @r{(SingleKey TUI key)}
16292@item v
16293info locals
16294
16295@kindex w @r{(SingleKey TUI key)}
16296@item w
16297where
16298
16299@end table
16300
16301Other keys temporarily switch to the @value{GDBN} command prompt.
16302The key that was pressed is inserted in the editing buffer so that
16303it is possible to type most @value{GDBN} commands without interaction
16304with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
16305@emph{SingleKey} mode is restored. The only way to permanently leave
16306this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
16307
16308
8e04817f
AC
16309@node TUI Commands
16310@section TUI specific commands
16311@cindex TUI commands
16312
16313The TUI has specific commands to control the text windows.
16314These commands are always available, that is they do not depend on
16315the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
16316is in the standard mode, using these commands will automatically switch
16317in the TUI mode.
c906108c
SS
16318
16319@table @code
3d757584
SC
16320@item info win
16321@kindex info win
16322List and give the size of all displayed windows.
16323
8e04817f 16324@item layout next
4644b6e3 16325@kindex layout
8e04817f 16326Display the next layout.
2df3850c 16327
8e04817f 16328@item layout prev
8e04817f 16329Display the previous layout.
c906108c 16330
8e04817f 16331@item layout src
8e04817f 16332Display the source window only.
c906108c 16333
8e04817f 16334@item layout asm
8e04817f 16335Display the assembly window only.
c906108c 16336
8e04817f 16337@item layout split
8e04817f 16338Display the source and assembly window.
c906108c 16339
8e04817f 16340@item layout regs
8e04817f
AC
16341Display the register window together with the source or assembly window.
16342
16343@item focus next | prev | src | asm | regs | split
16344@kindex focus
16345Set the focus to the named window.
16346This command allows to change the active window so that scrolling keys
16347can be affected to another window.
c906108c 16348
8e04817f
AC
16349@item refresh
16350@kindex refresh
16351Refresh the screen. This is similar to using @key{C-L} key.
c906108c 16352
6a1b180d
SC
16353@item tui reg float
16354@kindex tui reg
16355Show the floating point registers in the register window.
16356
16357@item tui reg general
16358Show the general registers in the register window.
16359
16360@item tui reg next
16361Show the next register group. The list of register groups as well as
16362their order is target specific. The predefined register groups are the
16363following: @code{general}, @code{float}, @code{system}, @code{vector},
16364@code{all}, @code{save}, @code{restore}.
16365
16366@item tui reg system
16367Show the system registers in the register window.
16368
8e04817f
AC
16369@item update
16370@kindex update
16371Update the source window and the current execution point.
c906108c 16372
8e04817f
AC
16373@item winheight @var{name} +@var{count}
16374@itemx winheight @var{name} -@var{count}
16375@kindex winheight
16376Change the height of the window @var{name} by @var{count}
16377lines. Positive counts increase the height, while negative counts
16378decrease it.
2df3850c 16379
c45da7e6
EZ
16380@item tabset
16381@kindex tabset @var{nchars}
16382Set the width of tab stops to be @var{nchars} characters.
16383
c906108c
SS
16384@end table
16385
8e04817f
AC
16386@node TUI Configuration
16387@section TUI configuration variables
16388@cindex TUI configuration variables
c906108c 16389
8e04817f
AC
16390The TUI has several configuration variables that control the
16391appearance of windows on the terminal.
c906108c 16392
8e04817f
AC
16393@table @code
16394@item set tui border-kind @var{kind}
16395@kindex set tui border-kind
16396Select the border appearance for the source, assembly and register windows.
16397The possible values are the following:
16398@table @code
16399@item space
16400Use a space character to draw the border.
c906108c 16401
8e04817f
AC
16402@item ascii
16403Use ascii characters + - and | to draw the border.
c906108c 16404
8e04817f
AC
16405@item acs
16406Use the Alternate Character Set to draw the border. The border is
16407drawn using character line graphics if the terminal supports them.
c78b4128 16408
8e04817f 16409@end table
c78b4128 16410
8e04817f
AC
16411@item set tui active-border-mode @var{mode}
16412@kindex set tui active-border-mode
16413Select the attributes to display the border of the active window.
16414The possible values are @code{normal}, @code{standout}, @code{reverse},
16415@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 16416
8e04817f
AC
16417@item set tui border-mode @var{mode}
16418@kindex set tui border-mode
16419Select the attributes to display the border of other windows.
16420The @var{mode} can be one of the following:
16421@table @code
16422@item normal
16423Use normal attributes to display the border.
c906108c 16424
8e04817f
AC
16425@item standout
16426Use standout mode.
c906108c 16427
8e04817f
AC
16428@item reverse
16429Use reverse video mode.
c906108c 16430
8e04817f
AC
16431@item half
16432Use half bright mode.
c906108c 16433
8e04817f
AC
16434@item half-standout
16435Use half bright and standout mode.
c906108c 16436
8e04817f
AC
16437@item bold
16438Use extra bright or bold mode.
c78b4128 16439
8e04817f
AC
16440@item bold-standout
16441Use extra bright or bold and standout mode.
c78b4128 16442
8e04817f 16443@end table
c78b4128 16444
8e04817f 16445@end table
c78b4128 16446
8e04817f
AC
16447@node Emacs
16448@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 16449
8e04817f
AC
16450@cindex Emacs
16451@cindex @sc{gnu} Emacs
16452A special interface allows you to use @sc{gnu} Emacs to view (and
16453edit) the source files for the program you are debugging with
16454@value{GDBN}.
c906108c 16455
8e04817f
AC
16456To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
16457executable file you want to debug as an argument. This command starts
16458@value{GDBN} as a subprocess of Emacs, with input and output through a newly
16459created Emacs buffer.
16460@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 16461
8e04817f
AC
16462Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
16463things:
c906108c 16464
8e04817f
AC
16465@itemize @bullet
16466@item
16467All ``terminal'' input and output goes through the Emacs buffer.
16468@end itemize
c906108c 16469
8e04817f
AC
16470This applies both to @value{GDBN} commands and their output, and to the input
16471and output done by the program you are debugging.
bf0184be 16472
8e04817f
AC
16473This is useful because it means that you can copy the text of previous
16474commands and input them again; you can even use parts of the output
16475in this way.
bf0184be 16476
8e04817f
AC
16477All the facilities of Emacs' Shell mode are available for interacting
16478with your program. In particular, you can send signals the usual
16479way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
16480stop.
bf0184be 16481
8e04817f 16482@itemize @bullet
bf0184be 16483@item
8e04817f
AC
16484@value{GDBN} displays source code through Emacs.
16485@end itemize
bf0184be 16486
8e04817f
AC
16487Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
16488source file for that frame and puts an arrow (@samp{=>}) at the
16489left margin of the current line. Emacs uses a separate buffer for
16490source display, and splits the screen to show both your @value{GDBN} session
16491and the source.
bf0184be 16492
8e04817f
AC
16493Explicit @value{GDBN} @code{list} or search commands still produce output as
16494usual, but you probably have no reason to use them from Emacs.
c906108c 16495
64fabec2
AC
16496If you specify an absolute file name when prompted for the @kbd{M-x
16497gdb} argument, then Emacs sets your current working directory to where
16498your program resides. If you only specify the file name, then Emacs
16499sets your current working directory to to the directory associated
16500with the previous buffer. In this case, @value{GDBN} may find your
16501program by searching your environment's @code{PATH} variable, but on
16502some operating systems it might not find the source. So, although the
16503@value{GDBN} input and output session proceeds normally, the auxiliary
16504buffer does not display the current source and line of execution.
16505
16506The initial working directory of @value{GDBN} is printed on the top
16507line of the @value{GDBN} I/O buffer and this serves as a default for
16508the commands that specify files for @value{GDBN} to operate
16509on. @xref{Files, ,Commands to specify files}.
16510
16511By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
16512need to call @value{GDBN} by a different name (for example, if you
16513keep several configurations around, with different names) you can
16514customize the Emacs variable @code{gud-gdb-command-name} to run the
16515one you want.
8e04817f
AC
16516
16517In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
16518addition to the standard Shell mode commands:
c906108c 16519
8e04817f
AC
16520@table @kbd
16521@item C-h m
16522Describe the features of Emacs' @value{GDBN} Mode.
c906108c 16523
64fabec2 16524@item C-c C-s
8e04817f
AC
16525Execute to another source line, like the @value{GDBN} @code{step} command; also
16526update the display window to show the current file and location.
c906108c 16527
64fabec2 16528@item C-c C-n
8e04817f
AC
16529Execute to next source line in this function, skipping all function
16530calls, like the @value{GDBN} @code{next} command. Then update the display window
16531to show the current file and location.
c906108c 16532
64fabec2 16533@item C-c C-i
8e04817f
AC
16534Execute one instruction, like the @value{GDBN} @code{stepi} command; update
16535display window accordingly.
c906108c 16536
8e04817f
AC
16537@item C-c C-f
16538Execute until exit from the selected stack frame, like the @value{GDBN}
16539@code{finish} command.
c906108c 16540
64fabec2 16541@item C-c C-r
8e04817f
AC
16542Continue execution of your program, like the @value{GDBN} @code{continue}
16543command.
b433d00b 16544
64fabec2 16545@item C-c <
8e04817f
AC
16546Go up the number of frames indicated by the numeric argument
16547(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
16548like the @value{GDBN} @code{up} command.
b433d00b 16549
64fabec2 16550@item C-c >
8e04817f
AC
16551Go down the number of frames indicated by the numeric argument, like the
16552@value{GDBN} @code{down} command.
8e04817f 16553@end table
c906108c 16554
64fabec2 16555In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 16556tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 16557
64fabec2
AC
16558If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
16559shows a backtrace when the @value{GDBN} I/O buffer is current. Move
16560point to any frame in the stack and type @key{RET} to make it become the
16561current frame and display the associated source in the source buffer.
16562Alternatively, click @kbd{Mouse-2} to make the selected frame become the
16563current one.
16564
8e04817f
AC
16565If you accidentally delete the source-display buffer, an easy way to get
16566it back is to type the command @code{f} in the @value{GDBN} buffer, to
16567request a frame display; when you run under Emacs, this recreates
16568the source buffer if necessary to show you the context of the current
16569frame.
c906108c 16570
8e04817f
AC
16571The source files displayed in Emacs are in ordinary Emacs buffers
16572which are visiting the source files in the usual way. You can edit
16573the files with these buffers if you wish; but keep in mind that @value{GDBN}
16574communicates with Emacs in terms of line numbers. If you add or
16575delete lines from the text, the line numbers that @value{GDBN} knows cease
16576to correspond properly with the code.
b383017d 16577
64fabec2
AC
16578The description given here is for GNU Emacs version 21.3 and a more
16579detailed description of its interaction with @value{GDBN} is given in
16580the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 16581
8e04817f
AC
16582@c The following dropped because Epoch is nonstandard. Reactivate
16583@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
16584@ignore
16585@kindex Emacs Epoch environment
16586@kindex Epoch
16587@kindex inspect
c906108c 16588
8e04817f
AC
16589Version 18 of @sc{gnu} Emacs has a built-in window system
16590called the @code{epoch}
16591environment. Users of this environment can use a new command,
16592@code{inspect} which performs identically to @code{print} except that
16593each value is printed in its own window.
16594@end ignore
c906108c 16595
922fbb7b
AC
16596
16597@node GDB/MI
16598@chapter The @sc{gdb/mi} Interface
16599
16600@unnumberedsec Function and Purpose
16601
16602@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
16603@sc{gdb/mi} is a line based machine oriented text interface to
16604@value{GDBN} and is activated by specifying using the
16605@option{--interpreter} command line option (@pxref{Mode Options}). It
16606is specifically intended to support the development of systems which
16607use the debugger as just one small component of a larger system.
922fbb7b
AC
16608
16609This chapter is a specification of the @sc{gdb/mi} interface. It is written
16610in the form of a reference manual.
16611
16612Note that @sc{gdb/mi} is still under construction, so some of the
16613features described below are incomplete and subject to change.
16614
16615@unnumberedsec Notation and Terminology
16616
16617@cindex notational conventions, for @sc{gdb/mi}
16618This chapter uses the following notation:
16619
16620@itemize @bullet
16621@item
16622@code{|} separates two alternatives.
16623
16624@item
16625@code{[ @var{something} ]} indicates that @var{something} is optional:
16626it may or may not be given.
16627
16628@item
16629@code{( @var{group} )*} means that @var{group} inside the parentheses
16630may repeat zero or more times.
16631
16632@item
16633@code{( @var{group} )+} means that @var{group} inside the parentheses
16634may repeat one or more times.
16635
16636@item
16637@code{"@var{string}"} means a literal @var{string}.
16638@end itemize
16639
16640@ignore
16641@heading Dependencies
16642@end ignore
16643
16644@heading Acknowledgments
16645
16646In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
16647Elena Zannoni.
16648
16649@menu
16650* GDB/MI Command Syntax::
16651* GDB/MI Compatibility with CLI::
16652* GDB/MI Output Records::
16653* GDB/MI Command Description Format::
16654* GDB/MI Breakpoint Table Commands::
16655* GDB/MI Data Manipulation::
16656* GDB/MI Program Control::
16657* GDB/MI Miscellaneous Commands::
16658@ignore
16659* GDB/MI Kod Commands::
16660* GDB/MI Memory Overlay Commands::
16661* GDB/MI Signal Handling Commands::
16662@end ignore
16663* GDB/MI Stack Manipulation::
16664* GDB/MI Symbol Query::
16665* GDB/MI Target Manipulation::
16666* GDB/MI Thread Commands::
16667* GDB/MI Tracepoint Commands::
16668* GDB/MI Variable Objects::
16669@end menu
16670
16671@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16672@node GDB/MI Command Syntax
16673@section @sc{gdb/mi} Command Syntax
16674
16675@menu
16676* GDB/MI Input Syntax::
16677* GDB/MI Output Syntax::
16678* GDB/MI Simple Examples::
16679@end menu
16680
16681@node GDB/MI Input Syntax
16682@subsection @sc{gdb/mi} Input Syntax
16683
16684@cindex input syntax for @sc{gdb/mi}
16685@cindex @sc{gdb/mi}, input syntax
16686@table @code
16687@item @var{command} @expansion{}
16688@code{@var{cli-command} | @var{mi-command}}
16689
16690@item @var{cli-command} @expansion{}
16691@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
16692@var{cli-command} is any existing @value{GDBN} CLI command.
16693
16694@item @var{mi-command} @expansion{}
16695@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
16696@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
16697
16698@item @var{token} @expansion{}
16699"any sequence of digits"
16700
16701@item @var{option} @expansion{}
16702@code{"-" @var{parameter} [ " " @var{parameter} ]}
16703
16704@item @var{parameter} @expansion{}
16705@code{@var{non-blank-sequence} | @var{c-string}}
16706
16707@item @var{operation} @expansion{}
16708@emph{any of the operations described in this chapter}
16709
16710@item @var{non-blank-sequence} @expansion{}
16711@emph{anything, provided it doesn't contain special characters such as
16712"-", @var{nl}, """ and of course " "}
16713
16714@item @var{c-string} @expansion{}
16715@code{""" @var{seven-bit-iso-c-string-content} """}
16716
16717@item @var{nl} @expansion{}
16718@code{CR | CR-LF}
16719@end table
16720
16721@noindent
16722Notes:
16723
16724@itemize @bullet
16725@item
16726The CLI commands are still handled by the @sc{mi} interpreter; their
16727output is described below.
16728
16729@item
16730The @code{@var{token}}, when present, is passed back when the command
16731finishes.
16732
16733@item
16734Some @sc{mi} commands accept optional arguments as part of the parameter
16735list. Each option is identified by a leading @samp{-} (dash) and may be
16736followed by an optional argument parameter. Options occur first in the
16737parameter list and can be delimited from normal parameters using
16738@samp{--} (this is useful when some parameters begin with a dash).
16739@end itemize
16740
16741Pragmatics:
16742
16743@itemize @bullet
16744@item
16745We want easy access to the existing CLI syntax (for debugging).
16746
16747@item
16748We want it to be easy to spot a @sc{mi} operation.
16749@end itemize
16750
16751@node GDB/MI Output Syntax
16752@subsection @sc{gdb/mi} Output Syntax
16753
16754@cindex output syntax of @sc{gdb/mi}
16755@cindex @sc{gdb/mi}, output syntax
16756The output from @sc{gdb/mi} consists of zero or more out-of-band records
16757followed, optionally, by a single result record. This result record
16758is for the most recent command. The sequence of output records is
16759terminated by @samp{(@value{GDBP})}.
16760
16761If an input command was prefixed with a @code{@var{token}} then the
16762corresponding output for that command will also be prefixed by that same
16763@var{token}.
16764
16765@table @code
16766@item @var{output} @expansion{}
f7dc1244 16767@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
922fbb7b
AC
16768
16769@item @var{result-record} @expansion{}
16770@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
16771
16772@item @var{out-of-band-record} @expansion{}
16773@code{@var{async-record} | @var{stream-record}}
16774
16775@item @var{async-record} @expansion{}
16776@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
16777
16778@item @var{exec-async-output} @expansion{}
16779@code{[ @var{token} ] "*" @var{async-output}}
16780
16781@item @var{status-async-output} @expansion{}
16782@code{[ @var{token} ] "+" @var{async-output}}
16783
16784@item @var{notify-async-output} @expansion{}
16785@code{[ @var{token} ] "=" @var{async-output}}
16786
16787@item @var{async-output} @expansion{}
16788@code{@var{async-class} ( "," @var{result} )* @var{nl}}
16789
16790@item @var{result-class} @expansion{}
16791@code{"done" | "running" | "connected" | "error" | "exit"}
16792
16793@item @var{async-class} @expansion{}
16794@code{"stopped" | @var{others}} (where @var{others} will be added
16795depending on the needs---this is still in development).
16796
16797@item @var{result} @expansion{}
16798@code{ @var{variable} "=" @var{value}}
16799
16800@item @var{variable} @expansion{}
16801@code{ @var{string} }
16802
16803@item @var{value} @expansion{}
16804@code{ @var{const} | @var{tuple} | @var{list} }
16805
16806@item @var{const} @expansion{}
16807@code{@var{c-string}}
16808
16809@item @var{tuple} @expansion{}
16810@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
16811
16812@item @var{list} @expansion{}
16813@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
16814@var{result} ( "," @var{result} )* "]" }
16815
16816@item @var{stream-record} @expansion{}
16817@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
16818
16819@item @var{console-stream-output} @expansion{}
16820@code{"~" @var{c-string}}
16821
16822@item @var{target-stream-output} @expansion{}
16823@code{"@@" @var{c-string}}
16824
16825@item @var{log-stream-output} @expansion{}
16826@code{"&" @var{c-string}}
16827
16828@item @var{nl} @expansion{}
16829@code{CR | CR-LF}
16830
16831@item @var{token} @expansion{}
16832@emph{any sequence of digits}.
16833@end table
16834
16835@noindent
16836Notes:
16837
16838@itemize @bullet
16839@item
16840All output sequences end in a single line containing a period.
16841
16842@item
16843The @code{@var{token}} is from the corresponding request. If an execution
16844command is interrupted by the @samp{-exec-interrupt} command, the
16845@var{token} associated with the @samp{*stopped} message is the one of the
16846original execution command, not the one of the interrupt command.
16847
16848@item
16849@cindex status output in @sc{gdb/mi}
16850@var{status-async-output} contains on-going status information about the
16851progress of a slow operation. It can be discarded. All status output is
16852prefixed by @samp{+}.
16853
16854@item
16855@cindex async output in @sc{gdb/mi}
16856@var{exec-async-output} contains asynchronous state change on the target
16857(stopped, started, disappeared). All async output is prefixed by
16858@samp{*}.
16859
16860@item
16861@cindex notify output in @sc{gdb/mi}
16862@var{notify-async-output} contains supplementary information that the
16863client should handle (e.g., a new breakpoint information). All notify
16864output is prefixed by @samp{=}.
16865
16866@item
16867@cindex console output in @sc{gdb/mi}
16868@var{console-stream-output} is output that should be displayed as is in the
16869console. It is the textual response to a CLI command. All the console
16870output is prefixed by @samp{~}.
16871
16872@item
16873@cindex target output in @sc{gdb/mi}
16874@var{target-stream-output} is the output produced by the target program.
16875All the target output is prefixed by @samp{@@}.
16876
16877@item
16878@cindex log output in @sc{gdb/mi}
16879@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
16880instance messages that should be displayed as part of an error log. All
16881the log output is prefixed by @samp{&}.
16882
16883@item
16884@cindex list output in @sc{gdb/mi}
16885New @sc{gdb/mi} commands should only output @var{lists} containing
16886@var{values}.
16887
16888
16889@end itemize
16890
16891@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
16892details about the various output records.
16893
16894@node GDB/MI Simple Examples
16895@subsection Simple Examples of @sc{gdb/mi} Interaction
16896@cindex @sc{gdb/mi}, simple examples
16897
16898This subsection presents several simple examples of interaction using
16899the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
16900following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
16901the output received from @sc{gdb/mi}.
16902
16903@subsubheading Target Stop
16904@c Ummm... There is no "-stop" command. This assumes async, no?
16905Here's an example of stopping the inferior process:
16906
16907@smallexample
16908-> -stop
16909<- (@value{GDBP})
16910@end smallexample
16911
16912@noindent
16913and later:
16914
16915@smallexample
16916<- *stop,reason="stop",address="0x123",source="a.c:123"
16917<- (@value{GDBP})
16918@end smallexample
16919
16920@subsubheading Simple CLI Command
16921
16922Here's an example of a simple CLI command being passed through
16923@sc{gdb/mi} and on to the CLI.
16924
16925@smallexample
16926-> print 1+2
16927<- &"print 1+2\n"
16928<- ~"$1 = 3\n"
16929<- ^done
16930<- (@value{GDBP})
16931@end smallexample
16932
16933@subsubheading Command With Side Effects
16934
16935@smallexample
16936-> -symbol-file xyz.exe
16937<- *breakpoint,nr="3",address="0x123",source="a.c:123"
16938<- (@value{GDBP})
16939@end smallexample
16940
16941@subsubheading A Bad Command
16942
16943Here's what happens if you pass a non-existent command:
16944
16945@smallexample
16946-> -rubbish
16947<- ^error,msg="Undefined MI command: rubbish"
16948<- (@value{GDBP})
16949@end smallexample
16950
16951@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16952@node GDB/MI Compatibility with CLI
16953@section @sc{gdb/mi} Compatibility with CLI
16954
16955@cindex compatibility, @sc{gdb/mi} and CLI
16956@cindex @sc{gdb/mi}, compatibility with CLI
16957To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
16958accepts existing CLI commands. As specified by the syntax, such
16959commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
16960respond.
16961
16962This mechanism is provided as an aid to developers of @sc{gdb/mi}
16963clients and not as a reliable interface into the CLI. Since the command
16964is being interpreteted in an environment that assumes @sc{gdb/mi}
16965behaviour, the exact output of such commands is likely to end up being
16966an un-supported hybrid of @sc{gdb/mi} and CLI output.
16967
16968@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16969@node GDB/MI Output Records
16970@section @sc{gdb/mi} Output Records
16971
16972@menu
16973* GDB/MI Result Records::
16974* GDB/MI Stream Records::
16975* GDB/MI Out-of-band Records::
16976@end menu
16977
16978@node GDB/MI Result Records
16979@subsection @sc{gdb/mi} Result Records
16980
16981@cindex result records in @sc{gdb/mi}
16982@cindex @sc{gdb/mi}, result records
16983In addition to a number of out-of-band notifications, the response to a
16984@sc{gdb/mi} command includes one of the following result indications:
16985
16986@table @code
16987@findex ^done
16988@item "^done" [ "," @var{results} ]
16989The synchronous operation was successful, @code{@var{results}} are the return
16990values.
16991
16992@item "^running"
16993@findex ^running
16994@c Is this one correct? Should it be an out-of-band notification?
16995The asynchronous operation was successfully started. The target is
16996running.
16997
16998@item "^error" "," @var{c-string}
16999@findex ^error
17000The operation failed. The @code{@var{c-string}} contains the corresponding
17001error message.
17002@end table
17003
17004@node GDB/MI Stream Records
17005@subsection @sc{gdb/mi} Stream Records
17006
17007@cindex @sc{gdb/mi}, stream records
17008@cindex stream records in @sc{gdb/mi}
17009@value{GDBN} internally maintains a number of output streams: the console, the
17010target, and the log. The output intended for each of these streams is
17011funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
17012
17013Each stream record begins with a unique @dfn{prefix character} which
17014identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
17015Syntax}). In addition to the prefix, each stream record contains a
17016@code{@var{string-output}}. This is either raw text (with an implicit new
17017line) or a quoted C string (which does not contain an implicit newline).
17018
17019@table @code
17020@item "~" @var{string-output}
17021The console output stream contains text that should be displayed in the
17022CLI console window. It contains the textual responses to CLI commands.
17023
17024@item "@@" @var{string-output}
17025The target output stream contains any textual output from the running
17026target.
17027
17028@item "&" @var{string-output}
17029The log stream contains debugging messages being produced by @value{GDBN}'s
17030internals.
17031@end table
17032
17033@node GDB/MI Out-of-band Records
17034@subsection @sc{gdb/mi} Out-of-band Records
17035
17036@cindex out-of-band records in @sc{gdb/mi}
17037@cindex @sc{gdb/mi}, out-of-band records
17038@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
17039additional changes that have occurred. Those changes can either be a
17040consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
17041target activity (e.g., target stopped).
17042
17043The following is a preliminary list of possible out-of-band records.
034dad6f 17044In particular, the @var{exec-async-output} records.
922fbb7b
AC
17045
17046@table @code
034dad6f
BR
17047@item *stopped,reason="@var{reason}"
17048@end table
17049
17050@var{reason} can be one of the following:
17051
17052@table @code
17053@item breakpoint-hit
17054A breakpoint was reached.
17055@item watchpoint-trigger
17056A watchpoint was triggered.
17057@item read-watchpoint-trigger
17058A read watchpoint was triggered.
17059@item access-watchpoint-trigger
17060An access watchpoint was triggered.
17061@item function-finished
17062An -exec-finish or similar CLI command was accomplished.
17063@item location-reached
17064An -exec-until or similar CLI command was accomplished.
17065@item watchpoint-scope
17066A watchpoint has gone out of scope.
17067@item end-stepping-range
17068An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
17069similar CLI command was accomplished.
17070@item exited-signalled
17071The inferior exited because of a signal.
17072@item exited
17073The inferior exited.
17074@item exited-normally
17075The inferior exited normally.
17076@item signal-received
17077A signal was received by the inferior.
922fbb7b
AC
17078@end table
17079
17080
17081@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17082@node GDB/MI Command Description Format
17083@section @sc{gdb/mi} Command Description Format
17084
17085The remaining sections describe blocks of commands. Each block of
17086commands is laid out in a fashion similar to this section.
17087
17088Note the the line breaks shown in the examples are here only for
17089readability. They don't appear in the real output.
17090Also note that the commands with a non-available example (N.A.@:) are
17091not yet implemented.
17092
17093@subheading Motivation
17094
17095The motivation for this collection of commands.
17096
17097@subheading Introduction
17098
17099A brief introduction to this collection of commands as a whole.
17100
17101@subheading Commands
17102
17103For each command in the block, the following is described:
17104
17105@subsubheading Synopsis
17106
17107@smallexample
17108 -command @var{args}@dots{}
17109@end smallexample
17110
922fbb7b
AC
17111@subsubheading Result
17112
265eeb58 17113@subsubheading @value{GDBN} Command
922fbb7b 17114
265eeb58 17115The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
17116
17117@subsubheading Example
17118
922fbb7b
AC
17119@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17120@node GDB/MI Breakpoint Table Commands
17121@section @sc{gdb/mi} Breakpoint table commands
17122
17123@cindex breakpoint commands for @sc{gdb/mi}
17124@cindex @sc{gdb/mi}, breakpoint commands
17125This section documents @sc{gdb/mi} commands for manipulating
17126breakpoints.
17127
17128@subheading The @code{-break-after} Command
17129@findex -break-after
17130
17131@subsubheading Synopsis
17132
17133@smallexample
17134 -break-after @var{number} @var{count}
17135@end smallexample
17136
17137The breakpoint number @var{number} is not in effect until it has been
17138hit @var{count} times. To see how this is reflected in the output of
17139the @samp{-break-list} command, see the description of the
17140@samp{-break-list} command below.
17141
17142@subsubheading @value{GDBN} Command
17143
17144The corresponding @value{GDBN} command is @samp{ignore}.
17145
17146@subsubheading Example
17147
17148@smallexample
17149(@value{GDBP})
17150-break-insert main
17151^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
17152(@value{GDBP})
17153-break-after 1 3
17154~
17155^done
17156(@value{GDBP})
17157-break-list
17158^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17159hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17160@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17161@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17162@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17163@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17164@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17165body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17166addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
17167ignore="3"@}]@}
17168(@value{GDBP})
17169@end smallexample
17170
17171@ignore
17172@subheading The @code{-break-catch} Command
17173@findex -break-catch
17174
17175@subheading The @code{-break-commands} Command
17176@findex -break-commands
17177@end ignore
17178
17179
17180@subheading The @code{-break-condition} Command
17181@findex -break-condition
17182
17183@subsubheading Synopsis
17184
17185@smallexample
17186 -break-condition @var{number} @var{expr}
17187@end smallexample
17188
17189Breakpoint @var{number} will stop the program only if the condition in
17190@var{expr} is true. The condition becomes part of the
17191@samp{-break-list} output (see the description of the @samp{-break-list}
17192command below).
17193
17194@subsubheading @value{GDBN} Command
17195
17196The corresponding @value{GDBN} command is @samp{condition}.
17197
17198@subsubheading Example
17199
17200@smallexample
17201(@value{GDBP})
17202-break-condition 1 1
17203^done
17204(@value{GDBP})
17205-break-list
17206^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17207hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17208@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17209@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17210@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17211@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17212@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17213body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17214addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
17215times="0",ignore="3"@}]@}
17216(@value{GDBP})
17217@end smallexample
17218
17219@subheading The @code{-break-delete} Command
17220@findex -break-delete
17221
17222@subsubheading Synopsis
17223
17224@smallexample
17225 -break-delete ( @var{breakpoint} )+
17226@end smallexample
17227
17228Delete the breakpoint(s) whose number(s) are specified in the argument
17229list. This is obviously reflected in the breakpoint list.
17230
17231@subsubheading @value{GDBN} command
17232
17233The corresponding @value{GDBN} command is @samp{delete}.
17234
17235@subsubheading Example
17236
17237@smallexample
17238(@value{GDBP})
17239-break-delete 1
17240^done
17241(@value{GDBP})
17242-break-list
17243^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17244hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17245@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17246@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17247@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17248@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17249@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17250body=[]@}
17251(@value{GDBP})
17252@end smallexample
17253
17254@subheading The @code{-break-disable} Command
17255@findex -break-disable
17256
17257@subsubheading Synopsis
17258
17259@smallexample
17260 -break-disable ( @var{breakpoint} )+
17261@end smallexample
17262
17263Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
17264break list is now set to @samp{n} for the named @var{breakpoint}(s).
17265
17266@subsubheading @value{GDBN} Command
17267
17268The corresponding @value{GDBN} command is @samp{disable}.
17269
17270@subsubheading Example
17271
17272@smallexample
17273(@value{GDBP})
17274-break-disable 2
17275^done
17276(@value{GDBP})
17277-break-list
17278^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17279hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17280@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17281@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17282@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17283@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17284@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17285body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
17286addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17287(@value{GDBP})
17288@end smallexample
17289
17290@subheading The @code{-break-enable} Command
17291@findex -break-enable
17292
17293@subsubheading Synopsis
17294
17295@smallexample
17296 -break-enable ( @var{breakpoint} )+
17297@end smallexample
17298
17299Enable (previously disabled) @var{breakpoint}(s).
17300
17301@subsubheading @value{GDBN} Command
17302
17303The corresponding @value{GDBN} command is @samp{enable}.
17304
17305@subsubheading Example
17306
17307@smallexample
17308(@value{GDBP})
17309-break-enable 2
17310^done
17311(@value{GDBP})
17312-break-list
17313^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17314hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17315@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17316@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17317@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17318@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17319@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17320body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17321addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17322(@value{GDBP})
17323@end smallexample
17324
17325@subheading The @code{-break-info} Command
17326@findex -break-info
17327
17328@subsubheading Synopsis
17329
17330@smallexample
17331 -break-info @var{breakpoint}
17332@end smallexample
17333
17334@c REDUNDANT???
17335Get information about a single breakpoint.
17336
17337@subsubheading @value{GDBN} command
17338
17339The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
17340
17341@subsubheading Example
17342N.A.
17343
17344@subheading The @code{-break-insert} Command
17345@findex -break-insert
17346
17347@subsubheading Synopsis
17348
17349@smallexample
17350 -break-insert [ -t ] [ -h ] [ -r ]
17351 [ -c @var{condition} ] [ -i @var{ignore-count} ]
17352 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
17353@end smallexample
17354
17355@noindent
17356If specified, @var{line}, can be one of:
17357
17358@itemize @bullet
17359@item function
17360@c @item +offset
17361@c @item -offset
17362@c @item linenum
17363@item filename:linenum
17364@item filename:function
17365@item *address
17366@end itemize
17367
17368The possible optional parameters of this command are:
17369
17370@table @samp
17371@item -t
17372Insert a tempoary breakpoint.
17373@item -h
17374Insert a hardware breakpoint.
17375@item -c @var{condition}
17376Make the breakpoint conditional on @var{condition}.
17377@item -i @var{ignore-count}
17378Initialize the @var{ignore-count}.
17379@item -r
17380Insert a regular breakpoint in all the functions whose names match the
17381given regular expression. Other flags are not applicable to regular
17382expresson.
17383@end table
17384
17385@subsubheading Result
17386
17387The result is in the form:
17388
17389@smallexample
17390 ^done,bkptno="@var{number}",func="@var{funcname}",
17391 file="@var{filename}",line="@var{lineno}"
17392@end smallexample
17393
17394@noindent
17395where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
17396is the name of the function where the breakpoint was inserted,
17397@var{filename} is the name of the source file which contains this
17398function, and @var{lineno} is the source line number within that file.
17399
17400Note: this format is open to change.
17401@c An out-of-band breakpoint instead of part of the result?
17402
17403@subsubheading @value{GDBN} Command
17404
17405The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
17406@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
17407
17408@subsubheading Example
17409
17410@smallexample
17411(@value{GDBP})
17412-break-insert main
17413^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17414(@value{GDBP})
17415-break-insert -t foo
17416^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
17417(@value{GDBP})
17418-break-list
17419^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17420hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17421@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17422@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17423@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17424@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17425@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17426body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17427addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
17428bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
17429addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
17430(@value{GDBP})
17431-break-insert -r foo.*
17432~int foo(int, int);
17433^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
17434(@value{GDBP})
17435@end smallexample
17436
17437@subheading The @code{-break-list} Command
17438@findex -break-list
17439
17440@subsubheading Synopsis
17441
17442@smallexample
17443 -break-list
17444@end smallexample
17445
17446Displays the list of inserted breakpoints, showing the following fields:
17447
17448@table @samp
17449@item Number
17450number of the breakpoint
17451@item Type
17452type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
17453@item Disposition
17454should the breakpoint be deleted or disabled when it is hit: @samp{keep}
17455or @samp{nokeep}
17456@item Enabled
17457is the breakpoint enabled or no: @samp{y} or @samp{n}
17458@item Address
17459memory location at which the breakpoint is set
17460@item What
17461logical location of the breakpoint, expressed by function name, file
17462name, line number
17463@item Times
17464number of times the breakpoint has been hit
17465@end table
17466
17467If there are no breakpoints or watchpoints, the @code{BreakpointTable}
17468@code{body} field is an empty list.
17469
17470@subsubheading @value{GDBN} Command
17471
17472The corresponding @value{GDBN} command is @samp{info break}.
17473
17474@subsubheading Example
17475
17476@smallexample
17477(@value{GDBP})
17478-break-list
17479^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17480hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17481@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17482@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17483@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17484@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17485@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17486body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17487addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
17488bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17489addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
17490(@value{GDBP})
17491@end smallexample
17492
17493Here's an example of the result when there are no breakpoints:
17494
17495@smallexample
17496(@value{GDBP})
17497-break-list
17498^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17499hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17500@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17501@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17502@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17503@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17504@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17505body=[]@}
17506(@value{GDBP})
17507@end smallexample
17508
17509@subheading The @code{-break-watch} Command
17510@findex -break-watch
17511
17512@subsubheading Synopsis
17513
17514@smallexample
17515 -break-watch [ -a | -r ]
17516@end smallexample
17517
17518Create a watchpoint. With the @samp{-a} option it will create an
17519@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
17520read from or on a write to the memory location. With the @samp{-r}
17521option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
17522trigger only when the memory location is accessed for reading. Without
17523either of the options, the watchpoint created is a regular watchpoint,
17524i.e. it will trigger when the memory location is accessed for writing.
17525@xref{Set Watchpoints, , Setting watchpoints}.
17526
17527Note that @samp{-break-list} will report a single list of watchpoints and
17528breakpoints inserted.
17529
17530@subsubheading @value{GDBN} Command
17531
17532The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
17533@samp{rwatch}.
17534
17535@subsubheading Example
17536
17537Setting a watchpoint on a variable in the @code{main} function:
17538
17539@smallexample
17540(@value{GDBP})
17541-break-watch x
17542^done,wpt=@{number="2",exp="x"@}
17543(@value{GDBP})
17544-exec-continue
17545^running
17546^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
17547value=@{old="-268439212",new="55"@},
76ff342d
DJ
17548frame=@{func="main",args=[],file="recursive2.c",
17549fullname="/home/foo/bar/devo/myproject/recursive2.c",line="5"@}
922fbb7b
AC
17550(@value{GDBP})
17551@end smallexample
17552
17553Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
17554the program execution twice: first for the variable changing value, then
17555for the watchpoint going out of scope.
17556
17557@smallexample
17558(@value{GDBP})
17559-break-watch C
17560^done,wpt=@{number="5",exp="C"@}
17561(@value{GDBP})
17562-exec-continue
17563^running
17564^done,reason="watchpoint-trigger",
17565wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
17566frame=@{func="callee4",args=[],
76ff342d
DJ
17567file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17568fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17569(@value{GDBP})
17570-exec-continue
17571^running
17572^done,reason="watchpoint-scope",wpnum="5",
17573frame=@{func="callee3",args=[@{name="strarg",
17574value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17575file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17576fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17577(@value{GDBP})
17578@end smallexample
17579
17580Listing breakpoints and watchpoints, at different points in the program
17581execution. Note that once the watchpoint goes out of scope, it is
17582deleted.
17583
17584@smallexample
17585(@value{GDBP})
17586-break-watch C
17587^done,wpt=@{number="2",exp="C"@}
17588(@value{GDBP})
17589-break-list
17590^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17591hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17592@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17593@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17594@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17595@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17596@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17597body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17598addr="0x00010734",func="callee4",
17599file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17600bkpt=@{number="2",type="watchpoint",disp="keep",
17601enabled="y",addr="",what="C",times="0"@}]@}
17602(@value{GDBP})
17603-exec-continue
17604^running
17605^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
17606value=@{old="-276895068",new="3"@},
17607frame=@{func="callee4",args=[],
76ff342d
DJ
17608file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17609fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17610(@value{GDBP})
17611-break-list
17612^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17613hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17614@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17615@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17616@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17617@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17618@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17619body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17620addr="0x00010734",func="callee4",
17621file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17622bkpt=@{number="2",type="watchpoint",disp="keep",
17623enabled="y",addr="",what="C",times="-5"@}]@}
17624(@value{GDBP})
17625-exec-continue
17626^running
17627^done,reason="watchpoint-scope",wpnum="2",
17628frame=@{func="callee3",args=[@{name="strarg",
17629value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17630file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17631fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17632(@value{GDBP})
17633-break-list
17634^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17635hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17636@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17637@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17638@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17639@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17640@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17641body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17642addr="0x00010734",func="callee4",
17643file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
17644(@value{GDBP})
17645@end smallexample
17646
17647@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17648@node GDB/MI Data Manipulation
17649@section @sc{gdb/mi} Data Manipulation
17650
17651@cindex data manipulation, in @sc{gdb/mi}
17652@cindex @sc{gdb/mi}, data manipulation
17653This section describes the @sc{gdb/mi} commands that manipulate data:
17654examine memory and registers, evaluate expressions, etc.
17655
17656@c REMOVED FROM THE INTERFACE.
17657@c @subheading -data-assign
17658@c Change the value of a program variable. Plenty of side effects.
17659@c @subsubheading GDB command
17660@c set variable
17661@c @subsubheading Example
17662@c N.A.
17663
17664@subheading The @code{-data-disassemble} Command
17665@findex -data-disassemble
17666
17667@subsubheading Synopsis
17668
17669@smallexample
17670 -data-disassemble
17671 [ -s @var{start-addr} -e @var{end-addr} ]
17672 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
17673 -- @var{mode}
17674@end smallexample
17675
17676@noindent
17677Where:
17678
17679@table @samp
17680@item @var{start-addr}
17681is the beginning address (or @code{$pc})
17682@item @var{end-addr}
17683is the end address
17684@item @var{filename}
17685is the name of the file to disassemble
17686@item @var{linenum}
17687is the line number to disassemble around
17688@item @var{lines}
17689is the the number of disassembly lines to be produced. If it is -1,
17690the whole function will be disassembled, in case no @var{end-addr} is
17691specified. If @var{end-addr} is specified as a non-zero value, and
17692@var{lines} is lower than the number of disassembly lines between
17693@var{start-addr} and @var{end-addr}, only @var{lines} lines are
17694displayed; if @var{lines} is higher than the number of lines between
17695@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
17696are displayed.
17697@item @var{mode}
17698is either 0 (meaning only disassembly) or 1 (meaning mixed source and
17699disassembly).
17700@end table
17701
17702@subsubheading Result
17703
17704The output for each instruction is composed of four fields:
17705
17706@itemize @bullet
17707@item Address
17708@item Func-name
17709@item Offset
17710@item Instruction
17711@end itemize
17712
17713Note that whatever included in the instruction field, is not manipulated
17714directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
17715
17716@subsubheading @value{GDBN} Command
17717
17718There's no direct mapping from this command to the CLI.
17719
17720@subsubheading Example
17721
17722Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
17723
17724@smallexample
17725(@value{GDBP})
17726-data-disassemble -s $pc -e "$pc + 20" -- 0
17727^done,
17728asm_insns=[
17729@{address="0x000107c0",func-name="main",offset="4",
17730inst="mov 2, %o0"@},
17731@{address="0x000107c4",func-name="main",offset="8",
17732inst="sethi %hi(0x11800), %o2"@},
17733@{address="0x000107c8",func-name="main",offset="12",
17734inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
17735@{address="0x000107cc",func-name="main",offset="16",
17736inst="sethi %hi(0x11800), %o2"@},
17737@{address="0x000107d0",func-name="main",offset="20",
17738inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
17739(@value{GDBP})
17740@end smallexample
17741
17742Disassemble the whole @code{main} function. Line 32 is part of
17743@code{main}.
17744
17745@smallexample
17746-data-disassemble -f basics.c -l 32 -- 0
17747^done,asm_insns=[
17748@{address="0x000107bc",func-name="main",offset="0",
17749inst="save %sp, -112, %sp"@},
17750@{address="0x000107c0",func-name="main",offset="4",
17751inst="mov 2, %o0"@},
17752@{address="0x000107c4",func-name="main",offset="8",
17753inst="sethi %hi(0x11800), %o2"@},
17754[@dots{}]
17755@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
17756@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
17757(@value{GDBP})
17758@end smallexample
17759
17760Disassemble 3 instructions from the start of @code{main}:
17761
17762@smallexample
17763(@value{GDBP})
17764-data-disassemble -f basics.c -l 32 -n 3 -- 0
17765^done,asm_insns=[
17766@{address="0x000107bc",func-name="main",offset="0",
17767inst="save %sp, -112, %sp"@},
17768@{address="0x000107c0",func-name="main",offset="4",
17769inst="mov 2, %o0"@},
17770@{address="0x000107c4",func-name="main",offset="8",
17771inst="sethi %hi(0x11800), %o2"@}]
17772(@value{GDBP})
17773@end smallexample
17774
17775Disassemble 3 instructions from the start of @code{main} in mixed mode:
17776
17777@smallexample
17778(@value{GDBP})
17779-data-disassemble -f basics.c -l 32 -n 3 -- 1
17780^done,asm_insns=[
17781src_and_asm_line=@{line="31",
17782file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17783 testsuite/gdb.mi/basics.c",line_asm_insn=[
17784@{address="0x000107bc",func-name="main",offset="0",
17785inst="save %sp, -112, %sp"@}]@},
17786src_and_asm_line=@{line="32",
17787file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17788 testsuite/gdb.mi/basics.c",line_asm_insn=[
17789@{address="0x000107c0",func-name="main",offset="4",
17790inst="mov 2, %o0"@},
17791@{address="0x000107c4",func-name="main",offset="8",
17792inst="sethi %hi(0x11800), %o2"@}]@}]
17793(@value{GDBP})
17794@end smallexample
17795
17796
17797@subheading The @code{-data-evaluate-expression} Command
17798@findex -data-evaluate-expression
17799
17800@subsubheading Synopsis
17801
17802@smallexample
17803 -data-evaluate-expression @var{expr}
17804@end smallexample
17805
17806Evaluate @var{expr} as an expression. The expression could contain an
17807inferior function call. The function call will execute synchronously.
17808If the expression contains spaces, it must be enclosed in double quotes.
17809
17810@subsubheading @value{GDBN} Command
17811
17812The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
17813@samp{call}. In @code{gdbtk} only, there's a corresponding
17814@samp{gdb_eval} command.
17815
17816@subsubheading Example
17817
17818In the following example, the numbers that precede the commands are the
17819@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
17820Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
17821output.
17822
17823@smallexample
17824211-data-evaluate-expression A
17825211^done,value="1"
17826(@value{GDBP})
17827311-data-evaluate-expression &A
17828311^done,value="0xefffeb7c"
17829(@value{GDBP})
17830411-data-evaluate-expression A+3
17831411^done,value="4"
17832(@value{GDBP})
17833511-data-evaluate-expression "A + 3"
17834511^done,value="4"
17835(@value{GDBP})
17836@end smallexample
17837
17838
17839@subheading The @code{-data-list-changed-registers} Command
17840@findex -data-list-changed-registers
17841
17842@subsubheading Synopsis
17843
17844@smallexample
17845 -data-list-changed-registers
17846@end smallexample
17847
17848Display a list of the registers that have changed.
17849
17850@subsubheading @value{GDBN} Command
17851
17852@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
17853has the corresponding command @samp{gdb_changed_register_list}.
17854
17855@subsubheading Example
17856
17857On a PPC MBX board:
17858
17859@smallexample
17860(@value{GDBP})
17861-exec-continue
17862^running
17863
17864(@value{GDBP})
17865*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
76ff342d 17866args=[],file="try.c",fullname="/home/foo/bar/devo/myproject/try.c",line="5"@}
922fbb7b
AC
17867(@value{GDBP})
17868-data-list-changed-registers
17869^done,changed-registers=["0","1","2","4","5","6","7","8","9",
17870"10","11","13","14","15","16","17","18","19","20","21","22","23",
17871"24","25","26","27","28","30","31","64","65","66","67","69"]
17872(@value{GDBP})
17873@end smallexample
17874
17875
17876@subheading The @code{-data-list-register-names} Command
17877@findex -data-list-register-names
17878
17879@subsubheading Synopsis
17880
17881@smallexample
17882 -data-list-register-names [ ( @var{regno} )+ ]
17883@end smallexample
17884
17885Show a list of register names for the current target. If no arguments
17886are given, it shows a list of the names of all the registers. If
17887integer numbers are given as arguments, it will print a list of the
17888names of the registers corresponding to the arguments. To ensure
17889consistency between a register name and its number, the output list may
17890include empty register names.
17891
17892@subsubheading @value{GDBN} Command
17893
17894@value{GDBN} does not have a command which corresponds to
17895@samp{-data-list-register-names}. In @code{gdbtk} there is a
17896corresponding command @samp{gdb_regnames}.
17897
17898@subsubheading Example
17899
17900For the PPC MBX board:
17901@smallexample
17902(@value{GDBP})
17903-data-list-register-names
17904^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
17905"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
17906"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
17907"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
17908"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
17909"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
17910"", "pc","ps","cr","lr","ctr","xer"]
17911(@value{GDBP})
17912-data-list-register-names 1 2 3
17913^done,register-names=["r1","r2","r3"]
17914(@value{GDBP})
17915@end smallexample
17916
17917@subheading The @code{-data-list-register-values} Command
17918@findex -data-list-register-values
17919
17920@subsubheading Synopsis
17921
17922@smallexample
17923 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
17924@end smallexample
17925
17926Display the registers' contents. @var{fmt} is the format according to
17927which the registers' contents are to be returned, followed by an optional
17928list of numbers specifying the registers to display. A missing list of
17929numbers indicates that the contents of all the registers must be returned.
17930
17931Allowed formats for @var{fmt} are:
17932
17933@table @code
17934@item x
17935Hexadecimal
17936@item o
17937Octal
17938@item t
17939Binary
17940@item d
17941Decimal
17942@item r
17943Raw
17944@item N
17945Natural
17946@end table
17947
17948@subsubheading @value{GDBN} Command
17949
17950The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
17951all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
17952
17953@subsubheading Example
17954
17955For a PPC MBX board (note: line breaks are for readability only, they
17956don't appear in the actual output):
17957
17958@smallexample
17959(@value{GDBP})
17960-data-list-register-values r 64 65
17961^done,register-values=[@{number="64",value="0xfe00a300"@},
17962@{number="65",value="0x00029002"@}]
17963(@value{GDBP})
17964-data-list-register-values x
17965^done,register-values=[@{number="0",value="0xfe0043c8"@},
17966@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
17967@{number="3",value="0x0"@},@{number="4",value="0xa"@},
17968@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
17969@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
17970@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
17971@{number="11",value="0x1"@},@{number="12",value="0x0"@},
17972@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
17973@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
17974@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
17975@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
17976@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
17977@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
17978@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
17979@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
17980@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
17981@{number="31",value="0x0"@},@{number="32",value="0x0"@},
17982@{number="33",value="0x0"@},@{number="34",value="0x0"@},
17983@{number="35",value="0x0"@},@{number="36",value="0x0"@},
17984@{number="37",value="0x0"@},@{number="38",value="0x0"@},
17985@{number="39",value="0x0"@},@{number="40",value="0x0"@},
17986@{number="41",value="0x0"@},@{number="42",value="0x0"@},
17987@{number="43",value="0x0"@},@{number="44",value="0x0"@},
17988@{number="45",value="0x0"@},@{number="46",value="0x0"@},
17989@{number="47",value="0x0"@},@{number="48",value="0x0"@},
17990@{number="49",value="0x0"@},@{number="50",value="0x0"@},
17991@{number="51",value="0x0"@},@{number="52",value="0x0"@},
17992@{number="53",value="0x0"@},@{number="54",value="0x0"@},
17993@{number="55",value="0x0"@},@{number="56",value="0x0"@},
17994@{number="57",value="0x0"@},@{number="58",value="0x0"@},
17995@{number="59",value="0x0"@},@{number="60",value="0x0"@},
17996@{number="61",value="0x0"@},@{number="62",value="0x0"@},
17997@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
17998@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
17999@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
18000@{number="69",value="0x20002b03"@}]
18001(@value{GDBP})
18002@end smallexample
18003
18004
18005@subheading The @code{-data-read-memory} Command
18006@findex -data-read-memory
18007
18008@subsubheading Synopsis
18009
18010@smallexample
18011 -data-read-memory [ -o @var{byte-offset} ]
18012 @var{address} @var{word-format} @var{word-size}
18013 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
18014@end smallexample
18015
18016@noindent
18017where:
18018
18019@table @samp
18020@item @var{address}
18021An expression specifying the address of the first memory word to be
18022read. Complex expressions containing embedded white space should be
18023quoted using the C convention.
18024
18025@item @var{word-format}
18026The format to be used to print the memory words. The notation is the
18027same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
18028,Output formats}).
18029
18030@item @var{word-size}
18031The size of each memory word in bytes.
18032
18033@item @var{nr-rows}
18034The number of rows in the output table.
18035
18036@item @var{nr-cols}
18037The number of columns in the output table.
18038
18039@item @var{aschar}
18040If present, indicates that each row should include an @sc{ascii} dump. The
18041value of @var{aschar} is used as a padding character when a byte is not a
18042member of the printable @sc{ascii} character set (printable @sc{ascii}
18043characters are those whose code is between 32 and 126, inclusively).
18044
18045@item @var{byte-offset}
18046An offset to add to the @var{address} before fetching memory.
18047@end table
18048
18049This command displays memory contents as a table of @var{nr-rows} by
18050@var{nr-cols} words, each word being @var{word-size} bytes. In total,
18051@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
18052(returned as @samp{total-bytes}). Should less than the requested number
18053of bytes be returned by the target, the missing words are identified
18054using @samp{N/A}. The number of bytes read from the target is returned
18055in @samp{nr-bytes} and the starting address used to read memory in
18056@samp{addr}.
18057
18058The address of the next/previous row or page is available in
18059@samp{next-row} and @samp{prev-row}, @samp{next-page} and
18060@samp{prev-page}.
18061
18062@subsubheading @value{GDBN} Command
18063
18064The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
18065@samp{gdb_get_mem} memory read command.
18066
18067@subsubheading Example
18068
18069Read six bytes of memory starting at @code{bytes+6} but then offset by
18070@code{-6} bytes. Format as three rows of two columns. One byte per
18071word. Display each word in hex.
18072
18073@smallexample
18074(@value{GDBP})
180759-data-read-memory -o -6 -- bytes+6 x 1 3 2
180769^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
18077next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
18078prev-page="0x0000138a",memory=[
18079@{addr="0x00001390",data=["0x00","0x01"]@},
18080@{addr="0x00001392",data=["0x02","0x03"]@},
18081@{addr="0x00001394",data=["0x04","0x05"]@}]
18082(@value{GDBP})
18083@end smallexample
18084
18085Read two bytes of memory starting at address @code{shorts + 64} and
18086display as a single word formatted in decimal.
18087
18088@smallexample
18089(@value{GDBP})
180905-data-read-memory shorts+64 d 2 1 1
180915^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
18092next-row="0x00001512",prev-row="0x0000150e",
18093next-page="0x00001512",prev-page="0x0000150e",memory=[
18094@{addr="0x00001510",data=["128"]@}]
18095(@value{GDBP})
18096@end smallexample
18097
18098Read thirty two bytes of memory starting at @code{bytes+16} and format
18099as eight rows of four columns. Include a string encoding with @samp{x}
18100used as the non-printable character.
18101
18102@smallexample
18103(@value{GDBP})
181044-data-read-memory bytes+16 x 1 8 4 x
181054^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
18106next-row="0x000013c0",prev-row="0x0000139c",
18107next-page="0x000013c0",prev-page="0x00001380",memory=[
18108@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
18109@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
18110@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
18111@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
18112@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
18113@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
18114@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
18115@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
18116(@value{GDBP})
18117@end smallexample
18118
18119@subheading The @code{-display-delete} Command
18120@findex -display-delete
18121
18122@subsubheading Synopsis
18123
18124@smallexample
18125 -display-delete @var{number}
18126@end smallexample
18127
18128Delete the display @var{number}.
18129
18130@subsubheading @value{GDBN} Command
18131
18132The corresponding @value{GDBN} command is @samp{delete display}.
18133
18134@subsubheading Example
18135N.A.
18136
18137
18138@subheading The @code{-display-disable} Command
18139@findex -display-disable
18140
18141@subsubheading Synopsis
18142
18143@smallexample
18144 -display-disable @var{number}
18145@end smallexample
18146
18147Disable display @var{number}.
18148
18149@subsubheading @value{GDBN} Command
18150
18151The corresponding @value{GDBN} command is @samp{disable display}.
18152
18153@subsubheading Example
18154N.A.
18155
18156
18157@subheading The @code{-display-enable} Command
18158@findex -display-enable
18159
18160@subsubheading Synopsis
18161
18162@smallexample
18163 -display-enable @var{number}
18164@end smallexample
18165
18166Enable display @var{number}.
18167
18168@subsubheading @value{GDBN} Command
18169
18170The corresponding @value{GDBN} command is @samp{enable display}.
18171
18172@subsubheading Example
18173N.A.
18174
18175
18176@subheading The @code{-display-insert} Command
18177@findex -display-insert
18178
18179@subsubheading Synopsis
18180
18181@smallexample
18182 -display-insert @var{expression}
18183@end smallexample
18184
18185Display @var{expression} every time the program stops.
18186
18187@subsubheading @value{GDBN} Command
18188
18189The corresponding @value{GDBN} command is @samp{display}.
18190
18191@subsubheading Example
18192N.A.
18193
18194
18195@subheading The @code{-display-list} Command
18196@findex -display-list
18197
18198@subsubheading Synopsis
18199
18200@smallexample
18201 -display-list
18202@end smallexample
18203
18204List the displays. Do not show the current values.
18205
18206@subsubheading @value{GDBN} Command
18207
18208The corresponding @value{GDBN} command is @samp{info display}.
18209
18210@subsubheading Example
18211N.A.
18212
18213
18214@subheading The @code{-environment-cd} Command
18215@findex -environment-cd
18216
18217@subsubheading Synopsis
18218
18219@smallexample
18220 -environment-cd @var{pathdir}
18221@end smallexample
18222
18223Set @value{GDBN}'s working directory.
18224
18225@subsubheading @value{GDBN} Command
18226
18227The corresponding @value{GDBN} command is @samp{cd}.
18228
18229@subsubheading Example
18230
18231@smallexample
18232(@value{GDBP})
18233-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18234^done
18235(@value{GDBP})
18236@end smallexample
18237
18238
18239@subheading The @code{-environment-directory} Command
18240@findex -environment-directory
18241
18242@subsubheading Synopsis
18243
18244@smallexample
18245 -environment-directory [ -r ] [ @var{pathdir} ]+
18246@end smallexample
18247
18248Add directories @var{pathdir} to beginning of search path for source files.
18249If the @samp{-r} option is used, the search path is reset to the default
b383017d 18250search path. If directories @var{pathdir} are supplied in addition to the
922fbb7b
AC
18251@samp{-r} option, the search path is first reset and then addition
18252occurs as normal.
b383017d 18253Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18254multiple directories in a single command
18255results in the directories added to the beginning of the
18256search path in the same order they were presented in the command.
18257If blanks are needed as
18258part of a directory name, double-quotes should be used around
18259the name. In the command output, the path will show up separated
b383017d 18260by the system directory-separator character. The directory-seperator
922fbb7b
AC
18261character must not be used
18262in any directory name.
18263If no directories are specified, the current search path is displayed.
18264
18265@subsubheading @value{GDBN} Command
18266
18267The corresponding @value{GDBN} command is @samp{dir}.
18268
18269@subsubheading Example
18270
18271@smallexample
18272(@value{GDBP})
18273-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18274^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18275(@value{GDBP})
18276-environment-directory ""
18277^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18278(@value{GDBP})
18279-environment-directory -r /home/jjohnstn/src/gdb /usr/src
18280^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
18281(@value{GDBP})
18282-environment-directory -r
18283^done,source-path="$cdir:$cwd"
18284(@value{GDBP})
18285@end smallexample
18286
18287
18288@subheading The @code{-environment-path} Command
18289@findex -environment-path
18290
18291@subsubheading Synopsis
18292
18293@smallexample
18294 -environment-path [ -r ] [ @var{pathdir} ]+
18295@end smallexample
18296
18297Add directories @var{pathdir} to beginning of search path for object files.
18298If the @samp{-r} option is used, the search path is reset to the original
b383017d
RM
18299search path that existed at gdb start-up. If directories @var{pathdir} are
18300supplied in addition to the
922fbb7b
AC
18301@samp{-r} option, the search path is first reset and then addition
18302occurs as normal.
b383017d 18303Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18304multiple directories in a single command
18305results in the directories added to the beginning of the
18306search path in the same order they were presented in the command.
18307If blanks are needed as
18308part of a directory name, double-quotes should be used around
18309the name. In the command output, the path will show up separated
b383017d 18310by the system directory-separator character. The directory-seperator
922fbb7b
AC
18311character must not be used
18312in any directory name.
18313If no directories are specified, the current path is displayed.
18314
18315
18316@subsubheading @value{GDBN} Command
18317
18318The corresponding @value{GDBN} command is @samp{path}.
18319
18320@subsubheading Example
18321
18322@smallexample
18323(@value{GDBP})
b383017d 18324-environment-path
922fbb7b
AC
18325^done,path="/usr/bin"
18326(@value{GDBP})
18327-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
18328^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
18329(@value{GDBP})
18330-environment-path -r /usr/local/bin
18331^done,path="/usr/local/bin:/usr/bin"
18332(@value{GDBP})
18333@end smallexample
18334
18335
18336@subheading The @code{-environment-pwd} Command
18337@findex -environment-pwd
18338
18339@subsubheading Synopsis
18340
18341@smallexample
18342 -environment-pwd
18343@end smallexample
18344
18345Show the current working directory.
18346
18347@subsubheading @value{GDBN} command
18348
18349The corresponding @value{GDBN} command is @samp{pwd}.
18350
18351@subsubheading Example
18352
18353@smallexample
18354(@value{GDBP})
18355-environment-pwd
18356^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
18357(@value{GDBP})
18358@end smallexample
18359
18360@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18361@node GDB/MI Program Control
18362@section @sc{gdb/mi} Program control
18363
18364@subsubheading Program termination
18365
18366As a result of execution, the inferior program can run to completion, if
18367it doesn't encounter any breakpoints. In this case the output will
18368include an exit code, if the program has exited exceptionally.
18369
18370@subsubheading Examples
18371
18372@noindent
18373Program exited normally:
18374
18375@smallexample
18376(@value{GDBP})
18377-exec-run
18378^running
18379(@value{GDBP})
18380x = 55
18381*stopped,reason="exited-normally"
18382(@value{GDBP})
18383@end smallexample
18384
18385@noindent
18386Program exited exceptionally:
18387
18388@smallexample
18389(@value{GDBP})
18390-exec-run
18391^running
18392(@value{GDBP})
18393x = 55
18394*stopped,reason="exited",exit-code="01"
18395(@value{GDBP})
18396@end smallexample
18397
18398Another way the program can terminate is if it receives a signal such as
18399@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
18400
18401@smallexample
18402(@value{GDBP})
18403*stopped,reason="exited-signalled",signal-name="SIGINT",
18404signal-meaning="Interrupt"
18405@end smallexample
18406
18407
18408@subheading The @code{-exec-abort} Command
18409@findex -exec-abort
18410
18411@subsubheading Synopsis
18412
18413@smallexample
18414 -exec-abort
18415@end smallexample
18416
18417Kill the inferior running program.
18418
18419@subsubheading @value{GDBN} Command
18420
18421The corresponding @value{GDBN} command is @samp{kill}.
18422
18423@subsubheading Example
18424N.A.
18425
18426
18427@subheading The @code{-exec-arguments} Command
18428@findex -exec-arguments
18429
18430@subsubheading Synopsis
18431
18432@smallexample
18433 -exec-arguments @var{args}
18434@end smallexample
18435
18436Set the inferior program arguments, to be used in the next
18437@samp{-exec-run}.
18438
18439@subsubheading @value{GDBN} Command
18440
18441The corresponding @value{GDBN} command is @samp{set args}.
18442
18443@subsubheading Example
18444
18445@c FIXME!
18446Don't have one around.
18447
18448
18449@subheading The @code{-exec-continue} Command
18450@findex -exec-continue
18451
18452@subsubheading Synopsis
18453
18454@smallexample
18455 -exec-continue
18456@end smallexample
18457
18458Asynchronous command. Resumes the execution of the inferior program
18459until a breakpoint is encountered, or until the inferior exits.
18460
18461@subsubheading @value{GDBN} Command
18462
18463The corresponding @value{GDBN} corresponding is @samp{continue}.
18464
18465@subsubheading Example
18466
18467@smallexample
18468-exec-continue
18469^running
18470(@value{GDBP})
18471@@Hello world
18472*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
76ff342d 18473file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="13"@}
922fbb7b
AC
18474(@value{GDBP})
18475@end smallexample
18476
18477
18478@subheading The @code{-exec-finish} Command
18479@findex -exec-finish
18480
18481@subsubheading Synopsis
18482
18483@smallexample
18484 -exec-finish
18485@end smallexample
18486
18487Asynchronous command. Resumes the execution of the inferior program
18488until the current function is exited. Displays the results returned by
18489the function.
18490
18491@subsubheading @value{GDBN} Command
18492
18493The corresponding @value{GDBN} command is @samp{finish}.
18494
18495@subsubheading Example
18496
18497Function returning @code{void}.
18498
18499@smallexample
18500-exec-finish
18501^running
18502(@value{GDBP})
18503@@hello from foo
18504*stopped,reason="function-finished",frame=@{func="main",args=[],
76ff342d 18505file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="7"@}
922fbb7b
AC
18506(@value{GDBP})
18507@end smallexample
18508
18509Function returning other than @code{void}. The name of the internal
18510@value{GDBN} variable storing the result is printed, together with the
18511value itself.
18512
18513@smallexample
18514-exec-finish
18515^running
18516(@value{GDBP})
18517*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
18518args=[@{name="a",value="1"],@{name="b",value="9"@}@},
76ff342d 18519file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b
AC
18520gdb-result-var="$1",return-value="0"
18521(@value{GDBP})
18522@end smallexample
18523
18524
18525@subheading The @code{-exec-interrupt} Command
18526@findex -exec-interrupt
18527
18528@subsubheading Synopsis
18529
18530@smallexample
18531 -exec-interrupt
18532@end smallexample
18533
18534Asynchronous command. Interrupts the background execution of the target.
18535Note how the token associated with the stop message is the one for the
18536execution command that has been interrupted. The token for the interrupt
18537itself only appears in the @samp{^done} output. If the user is trying to
18538interrupt a non-running program, an error message will be printed.
18539
18540@subsubheading @value{GDBN} Command
18541
18542The corresponding @value{GDBN} command is @samp{interrupt}.
18543
18544@subsubheading Example
18545
18546@smallexample
18547(@value{GDBP})
18548111-exec-continue
18549111^running
18550
18551(@value{GDBP})
18552222-exec-interrupt
18553222^done
18554(@value{GDBP})
18555111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d
DJ
18556frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
18557fullname="/home/foo/bar/devo/myproject/try.c",line="13"@}
922fbb7b
AC
18558(@value{GDBP})
18559
18560(@value{GDBP})
18561-exec-interrupt
18562^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
18563(@value{GDBP})
18564@end smallexample
18565
18566
18567@subheading The @code{-exec-next} Command
18568@findex -exec-next
18569
18570@subsubheading Synopsis
18571
18572@smallexample
18573 -exec-next
18574@end smallexample
18575
18576Asynchronous command. Resumes execution of the inferior program, stopping
18577when the beginning of the next source line is reached.
18578
18579@subsubheading @value{GDBN} Command
18580
18581The corresponding @value{GDBN} command is @samp{next}.
18582
18583@subsubheading Example
18584
18585@smallexample
18586-exec-next
18587^running
18588(@value{GDBP})
18589*stopped,reason="end-stepping-range",line="8",file="hello.c"
18590(@value{GDBP})
18591@end smallexample
18592
18593
18594@subheading The @code{-exec-next-instruction} Command
18595@findex -exec-next-instruction
18596
18597@subsubheading Synopsis
18598
18599@smallexample
18600 -exec-next-instruction
18601@end smallexample
18602
18603Asynchronous command. Executes one machine instruction. If the
18604instruction is a function call continues until the function returns. If
18605the program stops at an instruction in the middle of a source line, the
18606address will be printed as well.
18607
18608@subsubheading @value{GDBN} Command
18609
18610The corresponding @value{GDBN} command is @samp{nexti}.
18611
18612@subsubheading Example
18613
18614@smallexample
18615(@value{GDBP})
18616-exec-next-instruction
18617^running
18618
18619(@value{GDBP})
18620*stopped,reason="end-stepping-range",
18621addr="0x000100d4",line="5",file="hello.c"
18622(@value{GDBP})
18623@end smallexample
18624
18625
18626@subheading The @code{-exec-return} Command
18627@findex -exec-return
18628
18629@subsubheading Synopsis
18630
18631@smallexample
18632 -exec-return
18633@end smallexample
18634
18635Makes current function return immediately. Doesn't execute the inferior.
18636Displays the new current frame.
18637
18638@subsubheading @value{GDBN} Command
18639
18640The corresponding @value{GDBN} command is @samp{return}.
18641
18642@subsubheading Example
18643
18644@smallexample
18645(@value{GDBP})
18646200-break-insert callee4
18647200^done,bkpt=@{number="1",addr="0x00010734",
18648file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
18649(@value{GDBP})
18650000-exec-run
18651000^running
18652(@value{GDBP})
18653000*stopped,reason="breakpoint-hit",bkptno="1",
18654frame=@{func="callee4",args=[],
76ff342d
DJ
18655file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18656fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
922fbb7b
AC
18657(@value{GDBP})
18658205-break-delete
18659205^done
18660(@value{GDBP})
18661111-exec-return
18662111^done,frame=@{level="0",func="callee3",
18663args=[@{name="strarg",
18664value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
18665file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18666fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
18667(@value{GDBP})
18668@end smallexample
18669
18670
18671@subheading The @code{-exec-run} Command
18672@findex -exec-run
18673
18674@subsubheading Synopsis
18675
18676@smallexample
18677 -exec-run
18678@end smallexample
18679
18680Asynchronous command. Starts execution of the inferior from the
18681beginning. The inferior executes until either a breakpoint is
18682encountered or the program exits.
18683
18684@subsubheading @value{GDBN} Command
18685
18686The corresponding @value{GDBN} command is @samp{run}.
18687
18688@subsubheading Example
18689
18690@smallexample
18691(@value{GDBP})
18692-break-insert main
18693^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
18694(@value{GDBP})
18695-exec-run
18696^running
18697(@value{GDBP})
18698*stopped,reason="breakpoint-hit",bkptno="1",
76ff342d
DJ
18699frame=@{func="main",args=[],file="recursive2.c",
18700fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}
922fbb7b
AC
18701(@value{GDBP})
18702@end smallexample
18703
18704
18705@subheading The @code{-exec-show-arguments} Command
18706@findex -exec-show-arguments
18707
18708@subsubheading Synopsis
18709
18710@smallexample
18711 -exec-show-arguments
18712@end smallexample
18713
18714Print the arguments of the program.
18715
18716@subsubheading @value{GDBN} Command
18717
18718The corresponding @value{GDBN} command is @samp{show args}.
18719
18720@subsubheading Example
18721N.A.
18722
18723@c @subheading -exec-signal
18724
18725@subheading The @code{-exec-step} Command
18726@findex -exec-step
18727
18728@subsubheading Synopsis
18729
18730@smallexample
18731 -exec-step
18732@end smallexample
18733
18734Asynchronous command. Resumes execution of the inferior program, stopping
18735when the beginning of the next source line is reached, if the next
18736source line is not a function call. If it is, stop at the first
18737instruction of the called function.
18738
18739@subsubheading @value{GDBN} Command
18740
18741The corresponding @value{GDBN} command is @samp{step}.
18742
18743@subsubheading Example
18744
18745Stepping into a function:
18746
18747@smallexample
18748-exec-step
18749^running
18750(@value{GDBP})
18751*stopped,reason="end-stepping-range",
18752frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d
DJ
18753@{name="b",value="0"@}],file="recursive2.c",
18754fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@}
922fbb7b
AC
18755(@value{GDBP})
18756@end smallexample
18757
18758Regular stepping:
18759
18760@smallexample
18761-exec-step
18762^running
18763(@value{GDBP})
18764*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
18765(@value{GDBP})
18766@end smallexample
18767
18768
18769@subheading The @code{-exec-step-instruction} Command
18770@findex -exec-step-instruction
18771
18772@subsubheading Synopsis
18773
18774@smallexample
18775 -exec-step-instruction
18776@end smallexample
18777
18778Asynchronous command. Resumes the inferior which executes one machine
18779instruction. The output, once @value{GDBN} has stopped, will vary depending on
18780whether we have stopped in the middle of a source line or not. In the
18781former case, the address at which the program stopped will be printed as
18782well.
18783
18784@subsubheading @value{GDBN} Command
18785
18786The corresponding @value{GDBN} command is @samp{stepi}.
18787
18788@subsubheading Example
18789
18790@smallexample
18791(@value{GDBP})
18792-exec-step-instruction
18793^running
18794
18795(@value{GDBP})
18796*stopped,reason="end-stepping-range",
76ff342d
DJ
18797frame=@{func="foo",args=[],file="try.c",
18798fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18799(@value{GDBP})
18800-exec-step-instruction
18801^running
18802
18803(@value{GDBP})
18804*stopped,reason="end-stepping-range",
76ff342d
DJ
18805frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
18806fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18807(@value{GDBP})
18808@end smallexample
18809
18810
18811@subheading The @code{-exec-until} Command
18812@findex -exec-until
18813
18814@subsubheading Synopsis
18815
18816@smallexample
18817 -exec-until [ @var{location} ]
18818@end smallexample
18819
18820Asynchronous command. Executes the inferior until the @var{location}
18821specified in the argument is reached. If there is no argument, the inferior
18822executes until a source line greater than the current one is reached.
18823The reason for stopping in this case will be @samp{location-reached}.
18824
18825@subsubheading @value{GDBN} Command
18826
18827The corresponding @value{GDBN} command is @samp{until}.
18828
18829@subsubheading Example
18830
18831@smallexample
18832(@value{GDBP})
18833-exec-until recursive2.c:6
18834^running
18835(@value{GDBP})
18836x = 55
18837*stopped,reason="location-reached",frame=@{func="main",args=[],
76ff342d 18838file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="6"@}
922fbb7b
AC
18839(@value{GDBP})
18840@end smallexample
18841
18842@ignore
18843@subheading -file-clear
18844Is this going away????
18845@end ignore
18846
18847
18848@subheading The @code{-file-exec-and-symbols} Command
18849@findex -file-exec-and-symbols
18850
18851@subsubheading Synopsis
18852
18853@smallexample
18854 -file-exec-and-symbols @var{file}
18855@end smallexample
18856
18857Specify the executable file to be debugged. This file is the one from
18858which the symbol table is also read. If no file is specified, the
18859command clears the executable and symbol information. If breakpoints
18860are set when using this command with no arguments, @value{GDBN} will produce
18861error messages. Otherwise, no output is produced, except a completion
18862notification.
18863
18864@subsubheading @value{GDBN} Command
18865
18866The corresponding @value{GDBN} command is @samp{file}.
18867
18868@subsubheading Example
18869
18870@smallexample
18871(@value{GDBP})
18872-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18873^done
18874(@value{GDBP})
18875@end smallexample
18876
18877
18878@subheading The @code{-file-exec-file} Command
18879@findex -file-exec-file
18880
18881@subsubheading Synopsis
18882
18883@smallexample
18884 -file-exec-file @var{file}
18885@end smallexample
18886
18887Specify the executable file to be debugged. Unlike
18888@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
18889from this file. If used without argument, @value{GDBN} clears the information
18890about the executable file. No output is produced, except a completion
18891notification.
18892
18893@subsubheading @value{GDBN} Command
18894
18895The corresponding @value{GDBN} command is @samp{exec-file}.
18896
18897@subsubheading Example
18898
18899@smallexample
18900(@value{GDBP})
18901-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18902^done
18903(@value{GDBP})
18904@end smallexample
18905
18906
18907@subheading The @code{-file-list-exec-sections} Command
18908@findex -file-list-exec-sections
18909
18910@subsubheading Synopsis
18911
18912@smallexample
18913 -file-list-exec-sections
18914@end smallexample
18915
18916List the sections of the current executable file.
18917
18918@subsubheading @value{GDBN} Command
18919
18920The @value{GDBN} command @samp{info file} shows, among the rest, the same
18921information as this command. @code{gdbtk} has a corresponding command
18922@samp{gdb_load_info}.
18923
18924@subsubheading Example
18925N.A.
18926
18927
1abaf70c
BR
18928@subheading The @code{-file-list-exec-source-file} Command
18929@findex -file-list-exec-source-file
18930
18931@subsubheading Synopsis
18932
18933@smallexample
18934 -file-list-exec-source-file
18935@end smallexample
18936
b383017d 18937List the line number, the current source file, and the absolute path
1abaf70c
BR
18938to the current source file for the current executable.
18939
18940@subsubheading @value{GDBN} Command
18941
18942There's no @value{GDBN} command which directly corresponds to this one.
18943
18944@subsubheading Example
18945
18946@smallexample
18947(@value{GDBP})
18948123-file-list-exec-source-file
18949123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
18950(@value{GDBP})
18951@end smallexample
18952
18953
922fbb7b
AC
18954@subheading The @code{-file-list-exec-source-files} Command
18955@findex -file-list-exec-source-files
18956
18957@subsubheading Synopsis
18958
18959@smallexample
18960 -file-list-exec-source-files
18961@end smallexample
18962
18963List the source files for the current executable.
18964
57c22c6c
BR
18965It will always output the filename, but only when GDB can find the absolute
18966file name of a source file, will it output the fullname.
18967
922fbb7b
AC
18968@subsubheading @value{GDBN} Command
18969
18970There's no @value{GDBN} command which directly corresponds to this one.
18971@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
18972
18973@subsubheading Example
57c22c6c
BR
18974@smallexample
18975(@value{GDBP})
18976-file-list-exec-source-files
18977^done,files=[
18978@{file=foo.c,fullname=/home/foo.c@},
18979@{file=/home/bar.c,fullname=/home/bar.c@},
18980@{file=gdb_could_not_find_fullpath.c@}]
18981(@value{GDBP})
18982@end smallexample
922fbb7b
AC
18983
18984@subheading The @code{-file-list-shared-libraries} Command
18985@findex -file-list-shared-libraries
18986
18987@subsubheading Synopsis
18988
18989@smallexample
18990 -file-list-shared-libraries
18991@end smallexample
18992
18993List the shared libraries in the program.
18994
18995@subsubheading @value{GDBN} Command
18996
18997The corresponding @value{GDBN} command is @samp{info shared}.
18998
18999@subsubheading Example
19000N.A.
19001
19002
19003@subheading The @code{-file-list-symbol-files} Command
19004@findex -file-list-symbol-files
19005
19006@subsubheading Synopsis
19007
19008@smallexample
19009 -file-list-symbol-files
19010@end smallexample
19011
19012List symbol files.
19013
19014@subsubheading @value{GDBN} Command
19015
19016The corresponding @value{GDBN} command is @samp{info file} (part of it).
19017
19018@subsubheading Example
19019N.A.
19020
19021
19022@subheading The @code{-file-symbol-file} Command
19023@findex -file-symbol-file
19024
19025@subsubheading Synopsis
19026
19027@smallexample
19028 -file-symbol-file @var{file}
19029@end smallexample
19030
19031Read symbol table info from the specified @var{file} argument. When
19032used without arguments, clears @value{GDBN}'s symbol table info. No output is
19033produced, except for a completion notification.
19034
19035@subsubheading @value{GDBN} Command
19036
19037The corresponding @value{GDBN} command is @samp{symbol-file}.
19038
19039@subsubheading Example
19040
19041@smallexample
19042(@value{GDBP})
19043-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
19044^done
19045(@value{GDBP})
19046@end smallexample
19047
19048@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19049@node GDB/MI Miscellaneous Commands
19050@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
19051
19052@c @subheading -gdb-complete
19053
19054@subheading The @code{-gdb-exit} Command
19055@findex -gdb-exit
19056
19057@subsubheading Synopsis
19058
19059@smallexample
19060 -gdb-exit
19061@end smallexample
19062
19063Exit @value{GDBN} immediately.
19064
19065@subsubheading @value{GDBN} Command
19066
19067Approximately corresponds to @samp{quit}.
19068
19069@subsubheading Example
19070
19071@smallexample
19072(@value{GDBP})
19073-gdb-exit
19074@end smallexample
19075
19076@subheading The @code{-gdb-set} Command
19077@findex -gdb-set
19078
19079@subsubheading Synopsis
19080
19081@smallexample
19082 -gdb-set
19083@end smallexample
19084
19085Set an internal @value{GDBN} variable.
19086@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
19087
19088@subsubheading @value{GDBN} Command
19089
19090The corresponding @value{GDBN} command is @samp{set}.
19091
19092@subsubheading Example
19093
19094@smallexample
19095(@value{GDBP})
19096-gdb-set $foo=3
19097^done
19098(@value{GDBP})
19099@end smallexample
19100
19101
19102@subheading The @code{-gdb-show} Command
19103@findex -gdb-show
19104
19105@subsubheading Synopsis
19106
19107@smallexample
19108 -gdb-show
19109@end smallexample
19110
19111Show the current value of a @value{GDBN} variable.
19112
19113@subsubheading @value{GDBN} command
19114
19115The corresponding @value{GDBN} command is @samp{show}.
19116
19117@subsubheading Example
19118
19119@smallexample
19120(@value{GDBP})
19121-gdb-show annotate
19122^done,value="0"
19123(@value{GDBP})
19124@end smallexample
19125
19126@c @subheading -gdb-source
19127
19128
19129@subheading The @code{-gdb-version} Command
19130@findex -gdb-version
19131
19132@subsubheading Synopsis
19133
19134@smallexample
19135 -gdb-version
19136@end smallexample
19137
19138Show version information for @value{GDBN}. Used mostly in testing.
19139
19140@subsubheading @value{GDBN} Command
19141
19142There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
19143information when you start an interactive session.
19144
19145@subsubheading Example
19146
19147@c This example modifies the actual output from GDB to avoid overfull
19148@c box in TeX.
19149@smallexample
19150(@value{GDBP})
19151-gdb-version
19152~GNU gdb 5.2.1
19153~Copyright 2000 Free Software Foundation, Inc.
19154~GDB is free software, covered by the GNU General Public License, and
19155~you are welcome to change it and/or distribute copies of it under
19156~ certain conditions.
19157~Type "show copying" to see the conditions.
19158~There is absolutely no warranty for GDB. Type "show warranty" for
19159~ details.
b383017d 19160~This GDB was configured as
922fbb7b
AC
19161 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
19162^done
19163(@value{GDBP})
19164@end smallexample
19165
19166@subheading The @code{-interpreter-exec} Command
19167@findex -interpreter-exec
19168
19169@subheading Synopsis
19170
19171@smallexample
19172-interpreter-exec @var{interpreter} @var{command}
19173@end smallexample
19174
19175Execute the specified @var{command} in the given @var{interpreter}.
19176
19177@subheading @value{GDBN} Command
19178
19179The corresponding @value{GDBN} command is @samp{interpreter-exec}.
19180
19181@subheading Example
19182
19183@smallexample
19184(@value{GDBP})
19185-interpreter-exec console "break main"
19186&"During symbol reading, couldn't parse type; debugger out of date?.\n"
19187&"During symbol reading, bad structure-type format.\n"
19188~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
19189^done
19190(@value{GDBP})
19191@end smallexample
19192
3cb3b8df
BR
19193@subheading The @code{-inferior-tty-set} Command
19194@findex -inferior-tty-set
19195
19196@subheading Synopsis
19197
19198@smallexample
19199-inferior-tty-set /dev/pts/1
19200@end smallexample
19201
19202Set terminal for future runs of the program being debugged.
19203
19204@subheading @value{GDBN} Command
19205
19206The corresponding @value{GDBN} command is @samp{set inferior-tty /dev/pts/1}.
19207
19208@subheading Example
19209
19210@smallexample
19211(@value{GDBP})
19212-inferior-tty-set /dev/pts/1
19213^done
19214(@value{GDBP})
19215@end smallexample
19216
19217@subheading The @code{-inferior-tty-show} Command
19218@findex -inferior-tty-show
19219
19220@subheading Synopsis
19221
19222@smallexample
19223-inferior-tty-show
19224@end smallexample
19225
19226Show terminal for future runs of program being debugged.
19227
19228@subheading @value{GDBN} Command
19229
38f1196a 19230The corresponding @value{GDBN} command is @samp{show inferior-tty}.
3cb3b8df
BR
19231
19232@subheading Example
19233
19234@smallexample
19235(@value{GDBP})
19236-inferior-tty-set /dev/pts/1
19237^done
19238(@value{GDBP})
19239-inferior-tty-show
19240^done,inferior_tty_terminal="/dev/pts/1"
19241(@value{GDBP})
19242@end smallexample
19243
922fbb7b
AC
19244@ignore
19245@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19246@node GDB/MI Kod Commands
19247@section @sc{gdb/mi} Kod Commands
19248
19249The Kod commands are not implemented.
19250
19251@c @subheading -kod-info
19252
19253@c @subheading -kod-list
19254
19255@c @subheading -kod-list-object-types
19256
19257@c @subheading -kod-show
19258
19259@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19260@node GDB/MI Memory Overlay Commands
19261@section @sc{gdb/mi} Memory Overlay Commands
19262
19263The memory overlay commands are not implemented.
19264
19265@c @subheading -overlay-auto
19266
19267@c @subheading -overlay-list-mapping-state
19268
19269@c @subheading -overlay-list-overlays
19270
19271@c @subheading -overlay-map
19272
19273@c @subheading -overlay-off
19274
19275@c @subheading -overlay-on
19276
19277@c @subheading -overlay-unmap
19278
19279@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19280@node GDB/MI Signal Handling Commands
19281@section @sc{gdb/mi} Signal Handling Commands
19282
19283Signal handling commands are not implemented.
19284
19285@c @subheading -signal-handle
19286
19287@c @subheading -signal-list-handle-actions
19288
19289@c @subheading -signal-list-signal-types
19290@end ignore
19291
19292
19293@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19294@node GDB/MI Stack Manipulation
19295@section @sc{gdb/mi} Stack Manipulation Commands
19296
dcaaae04
NR
19297
19298@subheading The @code{-stack-info-frame} Command
19299@findex -stack-info-frame
19300
19301@subsubheading Synopsis
19302
19303@smallexample
19304 -stack-info-frame
19305@end smallexample
19306
19307Get info on the selected frame.
19308
19309@subsubheading @value{GDBN} Command
19310
19311The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
19312(without arguments).
19313
19314@subsubheading Example
19315
19316@smallexample
19317(@value{GDBP})
19318-stack-info-frame
19319^done,frame=@{level="1",addr="0x0001076c",func="callee3",
19320file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19321fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
19322(@value{GDBP})
19323@end smallexample
19324
922fbb7b
AC
19325@subheading The @code{-stack-info-depth} Command
19326@findex -stack-info-depth
19327
19328@subsubheading Synopsis
19329
19330@smallexample
19331 -stack-info-depth [ @var{max-depth} ]
19332@end smallexample
19333
19334Return the depth of the stack. If the integer argument @var{max-depth}
19335is specified, do not count beyond @var{max-depth} frames.
19336
19337@subsubheading @value{GDBN} Command
19338
19339There's no equivalent @value{GDBN} command.
19340
19341@subsubheading Example
19342
19343For a stack with frame levels 0 through 11:
19344
19345@smallexample
19346(@value{GDBP})
19347-stack-info-depth
19348^done,depth="12"
19349(@value{GDBP})
19350-stack-info-depth 4
19351^done,depth="4"
19352(@value{GDBP})
19353-stack-info-depth 12
19354^done,depth="12"
19355(@value{GDBP})
19356-stack-info-depth 11
19357^done,depth="11"
19358(@value{GDBP})
19359-stack-info-depth 13
19360^done,depth="12"
19361(@value{GDBP})
19362@end smallexample
19363
19364@subheading The @code{-stack-list-arguments} Command
19365@findex -stack-list-arguments
19366
19367@subsubheading Synopsis
19368
19369@smallexample
19370 -stack-list-arguments @var{show-values}
19371 [ @var{low-frame} @var{high-frame} ]
19372@end smallexample
19373
19374Display a list of the arguments for the frames between @var{low-frame}
19375and @var{high-frame} (inclusive). If @var{low-frame} and
19376@var{high-frame} are not provided, list the arguments for the whole call
19377stack.
19378
19379The @var{show-values} argument must have a value of 0 or 1. A value of
193800 means that only the names of the arguments are listed, a value of 1
19381means that both names and values of the arguments are printed.
19382
19383@subsubheading @value{GDBN} Command
19384
19385@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
19386@samp{gdb_get_args} command which partially overlaps with the
19387functionality of @samp{-stack-list-arguments}.
19388
19389@subsubheading Example
19390
19391@smallexample
19392(@value{GDBP})
19393-stack-list-frames
19394^done,
19395stack=[
19396frame=@{level="0",addr="0x00010734",func="callee4",
76ff342d
DJ
19397file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19398fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
922fbb7b 19399frame=@{level="1",addr="0x0001076c",func="callee3",
76ff342d
DJ
19400file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19401fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
922fbb7b 19402frame=@{level="2",addr="0x0001078c",func="callee2",
76ff342d
DJ
19403file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19404fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
922fbb7b 19405frame=@{level="3",addr="0x000107b4",func="callee1",
76ff342d
DJ
19406file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19407fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
922fbb7b 19408frame=@{level="4",addr="0x000107e0",func="main",
76ff342d
DJ
19409file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19410fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
922fbb7b
AC
19411(@value{GDBP})
19412-stack-list-arguments 0
19413^done,
19414stack-args=[
19415frame=@{level="0",args=[]@},
19416frame=@{level="1",args=[name="strarg"]@},
19417frame=@{level="2",args=[name="intarg",name="strarg"]@},
19418frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
19419frame=@{level="4",args=[]@}]
19420(@value{GDBP})
19421-stack-list-arguments 1
19422^done,
19423stack-args=[
19424frame=@{level="0",args=[]@},
19425frame=@{level="1",
19426 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19427frame=@{level="2",args=[
19428@{name="intarg",value="2"@},
19429@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19430@{frame=@{level="3",args=[
19431@{name="intarg",value="2"@},
19432@{name="strarg",value="0x11940 \"A string argument.\""@},
19433@{name="fltarg",value="3.5"@}]@},
19434frame=@{level="4",args=[]@}]
19435(@value{GDBP})
19436-stack-list-arguments 0 2 2
19437^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
19438(@value{GDBP})
19439-stack-list-arguments 1 2 2
19440^done,stack-args=[frame=@{level="2",
19441args=[@{name="intarg",value="2"@},
19442@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
19443(@value{GDBP})
19444@end smallexample
19445
19446@c @subheading -stack-list-exception-handlers
19447
19448
19449@subheading The @code{-stack-list-frames} Command
19450@findex -stack-list-frames
19451
19452@subsubheading Synopsis
19453
19454@smallexample
19455 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
19456@end smallexample
19457
19458List the frames currently on the stack. For each frame it displays the
19459following info:
19460
19461@table @samp
19462@item @var{level}
19463The frame number, 0 being the topmost frame, i.e. the innermost function.
19464@item @var{addr}
19465The @code{$pc} value for that frame.
19466@item @var{func}
19467Function name.
19468@item @var{file}
19469File name of the source file where the function lives.
19470@item @var{line}
19471Line number corresponding to the @code{$pc}.
19472@end table
19473
19474If invoked without arguments, this command prints a backtrace for the
19475whole stack. If given two integer arguments, it shows the frames whose
19476levels are between the two arguments (inclusive). If the two arguments
19477are equal, it shows the single frame at the corresponding level.
19478
19479@subsubheading @value{GDBN} Command
19480
19481The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
19482
19483@subsubheading Example
19484
19485Full stack backtrace:
19486
19487@smallexample
19488(@value{GDBP})
19489-stack-list-frames
19490^done,stack=
19491[frame=@{level="0",addr="0x0001076c",func="foo",
76ff342d 19492 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@},
922fbb7b 19493frame=@{level="1",addr="0x000107a4",func="foo",
76ff342d 19494 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19495frame=@{level="2",addr="0x000107a4",func="foo",
76ff342d 19496 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19497frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19498 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19499frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19500 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19501frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19502 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19503frame=@{level="6",addr="0x000107a4",func="foo",
76ff342d 19504 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19505frame=@{level="7",addr="0x000107a4",func="foo",
76ff342d 19506 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19507frame=@{level="8",addr="0x000107a4",func="foo",
76ff342d 19508 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19509frame=@{level="9",addr="0x000107a4",func="foo",
76ff342d 19510 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19511frame=@{level="10",addr="0x000107a4",func="foo",
76ff342d 19512 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19513frame=@{level="11",addr="0x00010738",func="main",
76ff342d 19514 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}]
922fbb7b
AC
19515(@value{GDBP})
19516@end smallexample
19517
19518Show frames between @var{low_frame} and @var{high_frame}:
19519
19520@smallexample
19521(@value{GDBP})
19522-stack-list-frames 3 5
19523^done,stack=
19524[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19525 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19526frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19527 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19528frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19529 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19530(@value{GDBP})
19531@end smallexample
19532
19533Show a single frame:
19534
19535@smallexample
19536(@value{GDBP})
19537-stack-list-frames 3 3
19538^done,stack=
19539[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19540 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19541(@value{GDBP})
19542@end smallexample
19543
19544
19545@subheading The @code{-stack-list-locals} Command
19546@findex -stack-list-locals
19547
19548@subsubheading Synopsis
19549
19550@smallexample
19551 -stack-list-locals @var{print-values}
19552@end smallexample
19553
265eeb58
NR
19554Display the local variable names for the selected frame. If
19555@var{print-values} is 0 or @code{--no-values}, print only the names of
19556the variables; if it is 1 or @code{--all-values}, print also their
19557values; and if it is 2 or @code{--simple-values}, print the name,
19558type and value for simple data types and the name and type for arrays,
19559structures and unions. In this last case, a frontend can immediately
19560display the value of simple data types and create variable objects for
19561other data types when the the user wishes to explore their values in
bc8ced35 19562more detail.
922fbb7b
AC
19563
19564@subsubheading @value{GDBN} Command
19565
19566@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
19567
19568@subsubheading Example
19569
19570@smallexample
19571(@value{GDBP})
19572-stack-list-locals 0
19573^done,locals=[name="A",name="B",name="C"]
19574(@value{GDBP})
bc8ced35 19575-stack-list-locals --all-values
922fbb7b 19576^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
bc8ced35
NR
19577 @{name="C",value="@{1, 2, 3@}"@}]
19578-stack-list-locals --simple-values
19579^done,locals=[@{name="A",type="int",value="1"@},
19580 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
922fbb7b
AC
19581(@value{GDBP})
19582@end smallexample
19583
19584
19585@subheading The @code{-stack-select-frame} Command
19586@findex -stack-select-frame
19587
19588@subsubheading Synopsis
19589
19590@smallexample
19591 -stack-select-frame @var{framenum}
19592@end smallexample
19593
265eeb58 19594Change the selected frame. Select a different frame @var{framenum} on
922fbb7b
AC
19595the stack.
19596
19597@subsubheading @value{GDBN} Command
19598
19599The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
19600@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
19601
19602@subsubheading Example
19603
19604@smallexample
19605(@value{GDBP})
19606-stack-select-frame 2
19607^done
19608(@value{GDBP})
19609@end smallexample
19610
19611@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19612@node GDB/MI Symbol Query
19613@section @sc{gdb/mi} Symbol Query Commands
19614
19615
19616@subheading The @code{-symbol-info-address} Command
19617@findex -symbol-info-address
19618
19619@subsubheading Synopsis
19620
19621@smallexample
19622 -symbol-info-address @var{symbol}
19623@end smallexample
19624
19625Describe where @var{symbol} is stored.
19626
19627@subsubheading @value{GDBN} Command
19628
19629The corresponding @value{GDBN} command is @samp{info address}.
19630
19631@subsubheading Example
19632N.A.
19633
19634
19635@subheading The @code{-symbol-info-file} Command
19636@findex -symbol-info-file
19637
19638@subsubheading Synopsis
19639
19640@smallexample
19641 -symbol-info-file
19642@end smallexample
19643
19644Show the file for the symbol.
19645
19646@subsubheading @value{GDBN} Command
19647
19648There's no equivalent @value{GDBN} command. @code{gdbtk} has
19649@samp{gdb_find_file}.
19650
19651@subsubheading Example
19652N.A.
19653
19654
19655@subheading The @code{-symbol-info-function} Command
19656@findex -symbol-info-function
19657
19658@subsubheading Synopsis
19659
19660@smallexample
19661 -symbol-info-function
19662@end smallexample
19663
19664Show which function the symbol lives in.
19665
19666@subsubheading @value{GDBN} Command
19667
19668@samp{gdb_get_function} in @code{gdbtk}.
19669
19670@subsubheading Example
19671N.A.
19672
19673
19674@subheading The @code{-symbol-info-line} Command
19675@findex -symbol-info-line
19676
19677@subsubheading Synopsis
19678
19679@smallexample
19680 -symbol-info-line
19681@end smallexample
19682
19683Show the core addresses of the code for a source line.
19684
19685@subsubheading @value{GDBN} Command
19686
71952f4c 19687The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
19688@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
19689
19690@subsubheading Example
19691N.A.
19692
19693
19694@subheading The @code{-symbol-info-symbol} Command
19695@findex -symbol-info-symbol
19696
19697@subsubheading Synopsis
19698
19699@smallexample
19700 -symbol-info-symbol @var{addr}
19701@end smallexample
19702
19703Describe what symbol is at location @var{addr}.
19704
19705@subsubheading @value{GDBN} Command
19706
19707The corresponding @value{GDBN} command is @samp{info symbol}.
19708
19709@subsubheading Example
19710N.A.
19711
19712
19713@subheading The @code{-symbol-list-functions} Command
19714@findex -symbol-list-functions
19715
19716@subsubheading Synopsis
19717
19718@smallexample
19719 -symbol-list-functions
19720@end smallexample
19721
19722List the functions in the executable.
19723
19724@subsubheading @value{GDBN} Command
19725
19726@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
19727@samp{gdb_search} in @code{gdbtk}.
19728
19729@subsubheading Example
19730N.A.
19731
19732
32e7087d
JB
19733@subheading The @code{-symbol-list-lines} Command
19734@findex -symbol-list-lines
19735
19736@subsubheading Synopsis
19737
19738@smallexample
19739 -symbol-list-lines @var{filename}
19740@end smallexample
19741
19742Print the list of lines that contain code and their associated program
19743addresses for the given source filename. The entries are sorted in
19744ascending PC order.
19745
19746@subsubheading @value{GDBN} Command
19747
19748There is no corresponding @value{GDBN} command.
19749
19750@subsubheading Example
19751@smallexample
19752(@value{GDBP})
19753-symbol-list-lines basics.c
54ff5908 19754^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
19755(@value{GDBP})
19756@end smallexample
19757
19758
922fbb7b
AC
19759@subheading The @code{-symbol-list-types} Command
19760@findex -symbol-list-types
19761
19762@subsubheading Synopsis
19763
19764@smallexample
19765 -symbol-list-types
19766@end smallexample
19767
19768List all the type names.
19769
19770@subsubheading @value{GDBN} Command
19771
19772The corresponding commands are @samp{info types} in @value{GDBN},
19773@samp{gdb_search} in @code{gdbtk}.
19774
19775@subsubheading Example
19776N.A.
19777
19778
19779@subheading The @code{-symbol-list-variables} Command
19780@findex -symbol-list-variables
19781
19782@subsubheading Synopsis
19783
19784@smallexample
19785 -symbol-list-variables
19786@end smallexample
19787
19788List all the global and static variable names.
19789
19790@subsubheading @value{GDBN} Command
19791
19792@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
19793
19794@subsubheading Example
19795N.A.
19796
19797
19798@subheading The @code{-symbol-locate} Command
19799@findex -symbol-locate
19800
19801@subsubheading Synopsis
19802
19803@smallexample
19804 -symbol-locate
19805@end smallexample
19806
19807@subsubheading @value{GDBN} Command
19808
19809@samp{gdb_loc} in @code{gdbtk}.
19810
19811@subsubheading Example
19812N.A.
19813
19814
19815@subheading The @code{-symbol-type} Command
19816@findex -symbol-type
19817
19818@subsubheading Synopsis
19819
19820@smallexample
19821 -symbol-type @var{variable}
19822@end smallexample
19823
19824Show type of @var{variable}.
19825
19826@subsubheading @value{GDBN} Command
19827
19828The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
19829@samp{gdb_obj_variable}.
19830
19831@subsubheading Example
19832N.A.
19833
19834
19835@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19836@node GDB/MI Target Manipulation
19837@section @sc{gdb/mi} Target Manipulation Commands
19838
19839
19840@subheading The @code{-target-attach} Command
19841@findex -target-attach
19842
19843@subsubheading Synopsis
19844
19845@smallexample
19846 -target-attach @var{pid} | @var{file}
19847@end smallexample
19848
19849Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
19850
19851@subsubheading @value{GDBN} command
19852
19853The corresponding @value{GDBN} command is @samp{attach}.
19854
19855@subsubheading Example
19856N.A.
19857
19858
19859@subheading The @code{-target-compare-sections} Command
19860@findex -target-compare-sections
19861
19862@subsubheading Synopsis
19863
19864@smallexample
19865 -target-compare-sections [ @var{section} ]
19866@end smallexample
19867
19868Compare data of section @var{section} on target to the exec file.
19869Without the argument, all sections are compared.
19870
19871@subsubheading @value{GDBN} Command
19872
19873The @value{GDBN} equivalent is @samp{compare-sections}.
19874
19875@subsubheading Example
19876N.A.
19877
19878
19879@subheading The @code{-target-detach} Command
19880@findex -target-detach
19881
19882@subsubheading Synopsis
19883
19884@smallexample
19885 -target-detach
19886@end smallexample
19887
19888Disconnect from the remote target. There's no output.
19889
19890@subsubheading @value{GDBN} command
19891
19892The corresponding @value{GDBN} command is @samp{detach}.
19893
19894@subsubheading Example
19895
19896@smallexample
19897(@value{GDBP})
19898-target-detach
19899^done
19900(@value{GDBP})
19901@end smallexample
19902
19903
07f31aa6
DJ
19904@subheading The @code{-target-disconnect} Command
19905@findex -target-disconnect
19906
19907@subsubheading Synopsis
19908
19909@example
19910 -target-disconnect
19911@end example
19912
19913Disconnect from the remote target. There's no output.
19914
19915@subsubheading @value{GDBN} command
19916
19917The corresponding @value{GDBN} command is @samp{disconnect}.
19918
19919@subsubheading Example
19920
19921@smallexample
19922(@value{GDBP})
19923-target-disconnect
19924^done
19925(@value{GDBP})
19926@end smallexample
19927
19928
922fbb7b
AC
19929@subheading The @code{-target-download} Command
19930@findex -target-download
19931
19932@subsubheading Synopsis
19933
19934@smallexample
19935 -target-download
19936@end smallexample
19937
19938Loads the executable onto the remote target.
19939It prints out an update message every half second, which includes the fields:
19940
19941@table @samp
19942@item section
19943The name of the section.
19944@item section-sent
19945The size of what has been sent so far for that section.
19946@item section-size
19947The size of the section.
19948@item total-sent
19949The total size of what was sent so far (the current and the previous sections).
19950@item total-size
19951The size of the overall executable to download.
19952@end table
19953
19954@noindent
19955Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
19956@sc{gdb/mi} Output Syntax}).
19957
19958In addition, it prints the name and size of the sections, as they are
19959downloaded. These messages include the following fields:
19960
19961@table @samp
19962@item section
19963The name of the section.
19964@item section-size
19965The size of the section.
19966@item total-size
19967The size of the overall executable to download.
19968@end table
19969
19970@noindent
19971At the end, a summary is printed.
19972
19973@subsubheading @value{GDBN} Command
19974
19975The corresponding @value{GDBN} command is @samp{load}.
19976
19977@subsubheading Example
19978
19979Note: each status message appears on a single line. Here the messages
19980have been broken down so that they can fit onto a page.
19981
19982@smallexample
19983(@value{GDBP})
19984-target-download
19985+download,@{section=".text",section-size="6668",total-size="9880"@}
19986+download,@{section=".text",section-sent="512",section-size="6668",
19987total-sent="512",total-size="9880"@}
19988+download,@{section=".text",section-sent="1024",section-size="6668",
19989total-sent="1024",total-size="9880"@}
19990+download,@{section=".text",section-sent="1536",section-size="6668",
19991total-sent="1536",total-size="9880"@}
19992+download,@{section=".text",section-sent="2048",section-size="6668",
19993total-sent="2048",total-size="9880"@}
19994+download,@{section=".text",section-sent="2560",section-size="6668",
19995total-sent="2560",total-size="9880"@}
19996+download,@{section=".text",section-sent="3072",section-size="6668",
19997total-sent="3072",total-size="9880"@}
19998+download,@{section=".text",section-sent="3584",section-size="6668",
19999total-sent="3584",total-size="9880"@}
20000+download,@{section=".text",section-sent="4096",section-size="6668",
20001total-sent="4096",total-size="9880"@}
20002+download,@{section=".text",section-sent="4608",section-size="6668",
20003total-sent="4608",total-size="9880"@}
20004+download,@{section=".text",section-sent="5120",section-size="6668",
20005total-sent="5120",total-size="9880"@}
20006+download,@{section=".text",section-sent="5632",section-size="6668",
20007total-sent="5632",total-size="9880"@}
20008+download,@{section=".text",section-sent="6144",section-size="6668",
20009total-sent="6144",total-size="9880"@}
20010+download,@{section=".text",section-sent="6656",section-size="6668",
20011total-sent="6656",total-size="9880"@}
20012+download,@{section=".init",section-size="28",total-size="9880"@}
20013+download,@{section=".fini",section-size="28",total-size="9880"@}
20014+download,@{section=".data",section-size="3156",total-size="9880"@}
20015+download,@{section=".data",section-sent="512",section-size="3156",
20016total-sent="7236",total-size="9880"@}
20017+download,@{section=".data",section-sent="1024",section-size="3156",
20018total-sent="7748",total-size="9880"@}
20019+download,@{section=".data",section-sent="1536",section-size="3156",
20020total-sent="8260",total-size="9880"@}
20021+download,@{section=".data",section-sent="2048",section-size="3156",
20022total-sent="8772",total-size="9880"@}
20023+download,@{section=".data",section-sent="2560",section-size="3156",
20024total-sent="9284",total-size="9880"@}
20025+download,@{section=".data",section-sent="3072",section-size="3156",
20026total-sent="9796",total-size="9880"@}
20027^done,address="0x10004",load-size="9880",transfer-rate="6586",
20028write-rate="429"
20029(@value{GDBP})
20030@end smallexample
20031
20032
20033@subheading The @code{-target-exec-status} Command
20034@findex -target-exec-status
20035
20036@subsubheading Synopsis
20037
20038@smallexample
20039 -target-exec-status
20040@end smallexample
20041
20042Provide information on the state of the target (whether it is running or
20043not, for instance).
20044
20045@subsubheading @value{GDBN} Command
20046
20047There's no equivalent @value{GDBN} command.
20048
20049@subsubheading Example
20050N.A.
20051
20052
20053@subheading The @code{-target-list-available-targets} Command
20054@findex -target-list-available-targets
20055
20056@subsubheading Synopsis
20057
20058@smallexample
20059 -target-list-available-targets
20060@end smallexample
20061
20062List the possible targets to connect to.
20063
20064@subsubheading @value{GDBN} Command
20065
20066The corresponding @value{GDBN} command is @samp{help target}.
20067
20068@subsubheading Example
20069N.A.
20070
20071
20072@subheading The @code{-target-list-current-targets} Command
20073@findex -target-list-current-targets
20074
20075@subsubheading Synopsis
20076
20077@smallexample
20078 -target-list-current-targets
20079@end smallexample
20080
20081Describe the current target.
20082
20083@subsubheading @value{GDBN} Command
20084
20085The corresponding information is printed by @samp{info file} (among
20086other things).
20087
20088@subsubheading Example
20089N.A.
20090
20091
20092@subheading The @code{-target-list-parameters} Command
20093@findex -target-list-parameters
20094
20095@subsubheading Synopsis
20096
20097@smallexample
20098 -target-list-parameters
20099@end smallexample
20100
20101@c ????
20102
20103@subsubheading @value{GDBN} Command
20104
20105No equivalent.
20106
20107@subsubheading Example
20108N.A.
20109
20110
20111@subheading The @code{-target-select} Command
20112@findex -target-select
20113
20114@subsubheading Synopsis
20115
20116@smallexample
20117 -target-select @var{type} @var{parameters @dots{}}
20118@end smallexample
20119
20120Connect @value{GDBN} to the remote target. This command takes two args:
20121
20122@table @samp
20123@item @var{type}
20124The type of target, for instance @samp{async}, @samp{remote}, etc.
20125@item @var{parameters}
20126Device names, host names and the like. @xref{Target Commands, ,
20127Commands for managing targets}, for more details.
20128@end table
20129
20130The output is a connection notification, followed by the address at
20131which the target program is, in the following form:
20132
20133@smallexample
20134^connected,addr="@var{address}",func="@var{function name}",
20135 args=[@var{arg list}]
20136@end smallexample
20137
20138@subsubheading @value{GDBN} Command
20139
20140The corresponding @value{GDBN} command is @samp{target}.
20141
20142@subsubheading Example
20143
20144@smallexample
20145(@value{GDBP})
20146-target-select async /dev/ttya
20147^connected,addr="0xfe00a300",func="??",args=[]
20148(@value{GDBP})
20149@end smallexample
20150
20151@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20152@node GDB/MI Thread Commands
20153@section @sc{gdb/mi} Thread Commands
20154
20155
20156@subheading The @code{-thread-info} Command
20157@findex -thread-info
20158
20159@subsubheading Synopsis
20160
20161@smallexample
20162 -thread-info
20163@end smallexample
20164
20165@subsubheading @value{GDBN} command
20166
20167No equivalent.
20168
20169@subsubheading Example
20170N.A.
20171
20172
20173@subheading The @code{-thread-list-all-threads} Command
20174@findex -thread-list-all-threads
20175
20176@subsubheading Synopsis
20177
20178@smallexample
20179 -thread-list-all-threads
20180@end smallexample
20181
20182@subsubheading @value{GDBN} Command
20183
20184The equivalent @value{GDBN} command is @samp{info threads}.
20185
20186@subsubheading Example
20187N.A.
20188
20189
20190@subheading The @code{-thread-list-ids} Command
20191@findex -thread-list-ids
20192
20193@subsubheading Synopsis
20194
20195@smallexample
20196 -thread-list-ids
20197@end smallexample
20198
20199Produces a list of the currently known @value{GDBN} thread ids. At the
20200end of the list it also prints the total number of such threads.
20201
20202@subsubheading @value{GDBN} Command
20203
20204Part of @samp{info threads} supplies the same information.
20205
20206@subsubheading Example
20207
20208No threads present, besides the main process:
20209
20210@smallexample
20211(@value{GDBP})
20212-thread-list-ids
20213^done,thread-ids=@{@},number-of-threads="0"
20214(@value{GDBP})
20215@end smallexample
20216
20217
20218Several threads:
20219
20220@smallexample
20221(@value{GDBP})
20222-thread-list-ids
20223^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20224number-of-threads="3"
20225(@value{GDBP})
20226@end smallexample
20227
20228
20229@subheading The @code{-thread-select} Command
20230@findex -thread-select
20231
20232@subsubheading Synopsis
20233
20234@smallexample
20235 -thread-select @var{threadnum}
20236@end smallexample
20237
20238Make @var{threadnum} the current thread. It prints the number of the new
20239current thread, and the topmost frame for that thread.
20240
20241@subsubheading @value{GDBN} Command
20242
20243The corresponding @value{GDBN} command is @samp{thread}.
20244
20245@subsubheading Example
20246
20247@smallexample
20248(@value{GDBP})
20249-exec-next
20250^running
20251(@value{GDBP})
20252*stopped,reason="end-stepping-range",thread-id="2",line="187",
20253file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
20254(@value{GDBP})
20255-thread-list-ids
20256^done,
20257thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20258number-of-threads="3"
20259(@value{GDBP})
20260-thread-select 3
20261^done,new-thread-id="3",
20262frame=@{level="0",func="vprintf",
20263args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
20264@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
20265(@value{GDBP})
20266@end smallexample
20267
20268@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20269@node GDB/MI Tracepoint Commands
20270@section @sc{gdb/mi} Tracepoint Commands
20271
20272The tracepoint commands are not yet implemented.
20273
20274@c @subheading -trace-actions
20275
20276@c @subheading -trace-delete
20277
20278@c @subheading -trace-disable
20279
20280@c @subheading -trace-dump
20281
20282@c @subheading -trace-enable
20283
20284@c @subheading -trace-exists
20285
20286@c @subheading -trace-find
20287
20288@c @subheading -trace-frame-number
20289
20290@c @subheading -trace-info
20291
20292@c @subheading -trace-insert
20293
20294@c @subheading -trace-list
20295
20296@c @subheading -trace-pass-count
20297
20298@c @subheading -trace-save
20299
20300@c @subheading -trace-start
20301
20302@c @subheading -trace-stop
20303
20304
20305@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20306@node GDB/MI Variable Objects
20307@section @sc{gdb/mi} Variable Objects
20308
20309
20310@subheading Motivation for Variable Objects in @sc{gdb/mi}
20311
20312For the implementation of a variable debugger window (locals, watched
20313expressions, etc.), we are proposing the adaptation of the existing code
20314used by @code{Insight}.
20315
20316The two main reasons for that are:
20317
20318@enumerate 1
20319@item
20320It has been proven in practice (it is already on its second generation).
20321
20322@item
20323It will shorten development time (needless to say how important it is
20324now).
20325@end enumerate
20326
20327The original interface was designed to be used by Tcl code, so it was
20328slightly changed so it could be used through @sc{gdb/mi}. This section
20329describes the @sc{gdb/mi} operations that will be available and gives some
20330hints about their use.
20331
20332@emph{Note}: In addition to the set of operations described here, we
20333expect the @sc{gui} implementation of a variable window to require, at
20334least, the following operations:
20335
20336@itemize @bullet
20337@item @code{-gdb-show} @code{output-radix}
20338@item @code{-stack-list-arguments}
20339@item @code{-stack-list-locals}
20340@item @code{-stack-select-frame}
20341@end itemize
20342
20343@subheading Introduction to Variable Objects in @sc{gdb/mi}
20344
20345@cindex variable objects in @sc{gdb/mi}
20346The basic idea behind variable objects is the creation of a named object
20347to represent a variable, an expression, a memory location or even a CPU
20348register. For each object created, a set of operations is available for
20349examining or changing its properties.
20350
20351Furthermore, complex data types, such as C structures, are represented
20352in a tree format. For instance, the @code{struct} type variable is the
20353root and the children will represent the struct members. If a child
20354is itself of a complex type, it will also have children of its own.
20355Appropriate language differences are handled for C, C@t{++} and Java.
20356
20357When returning the actual values of the objects, this facility allows
20358for the individual selection of the display format used in the result
20359creation. It can be chosen among: binary, decimal, hexadecimal, octal
20360and natural. Natural refers to a default format automatically
20361chosen based on the variable type (like decimal for an @code{int}, hex
20362for pointers, etc.).
20363
20364The following is the complete set of @sc{gdb/mi} operations defined to
20365access this functionality:
20366
20367@multitable @columnfractions .4 .6
20368@item @strong{Operation}
20369@tab @strong{Description}
20370
20371@item @code{-var-create}
20372@tab create a variable object
20373@item @code{-var-delete}
20374@tab delete the variable object and its children
20375@item @code{-var-set-format}
20376@tab set the display format of this variable
20377@item @code{-var-show-format}
20378@tab show the display format of this variable
20379@item @code{-var-info-num-children}
20380@tab tells how many children this object has
20381@item @code{-var-list-children}
20382@tab return a list of the object's children
20383@item @code{-var-info-type}
20384@tab show the type of this variable object
20385@item @code{-var-info-expression}
20386@tab print what this variable object represents
20387@item @code{-var-show-attributes}
20388@tab is this variable editable? does it exist here?
20389@item @code{-var-evaluate-expression}
20390@tab get the value of this variable
20391@item @code{-var-assign}
20392@tab set the value of this variable
20393@item @code{-var-update}
20394@tab update the variable and its children
20395@end multitable
20396
20397In the next subsection we describe each operation in detail and suggest
20398how it can be used.
20399
20400@subheading Description And Use of Operations on Variable Objects
20401
20402@subheading The @code{-var-create} Command
20403@findex -var-create
20404
20405@subsubheading Synopsis
20406
20407@smallexample
20408 -var-create @{@var{name} | "-"@}
20409 @{@var{frame-addr} | "*"@} @var{expression}
20410@end smallexample
20411
20412This operation creates a variable object, which allows the monitoring of
20413a variable, the result of an expression, a memory cell or a CPU
20414register.
20415
20416The @var{name} parameter is the string by which the object can be
20417referenced. It must be unique. If @samp{-} is specified, the varobj
20418system will generate a string ``varNNNNNN'' automatically. It will be
20419unique provided that one does not specify @var{name} on that format.
20420The command fails if a duplicate name is found.
20421
20422The frame under which the expression should be evaluated can be
20423specified by @var{frame-addr}. A @samp{*} indicates that the current
20424frame should be used.
20425
20426@var{expression} is any expression valid on the current language set (must not
20427begin with a @samp{*}), or one of the following:
20428
20429@itemize @bullet
20430@item
20431@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
20432
20433@item
20434@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
20435
20436@item
20437@samp{$@var{regname}} --- a CPU register name
20438@end itemize
20439
20440@subsubheading Result
20441
20442This operation returns the name, number of children and the type of the
20443object created. Type is returned as a string as the ones generated by
20444the @value{GDBN} CLI:
20445
20446@smallexample
20447 name="@var{name}",numchild="N",type="@var{type}"
20448@end smallexample
20449
20450
20451@subheading The @code{-var-delete} Command
20452@findex -var-delete
20453
20454@subsubheading Synopsis
20455
20456@smallexample
20457 -var-delete @var{name}
20458@end smallexample
20459
20460Deletes a previously created variable object and all of its children.
20461
20462Returns an error if the object @var{name} is not found.
20463
20464
20465@subheading The @code{-var-set-format} Command
20466@findex -var-set-format
20467
20468@subsubheading Synopsis
20469
20470@smallexample
20471 -var-set-format @var{name} @var{format-spec}
20472@end smallexample
20473
20474Sets the output format for the value of the object @var{name} to be
20475@var{format-spec}.
20476
20477The syntax for the @var{format-spec} is as follows:
20478
20479@smallexample
20480 @var{format-spec} @expansion{}
20481 @{binary | decimal | hexadecimal | octal | natural@}
20482@end smallexample
20483
20484
20485@subheading The @code{-var-show-format} Command
20486@findex -var-show-format
20487
20488@subsubheading Synopsis
20489
20490@smallexample
20491 -var-show-format @var{name}
20492@end smallexample
20493
20494Returns the format used to display the value of the object @var{name}.
20495
20496@smallexample
20497 @var{format} @expansion{}
20498 @var{format-spec}
20499@end smallexample
20500
20501
20502@subheading The @code{-var-info-num-children} Command
20503@findex -var-info-num-children
20504
20505@subsubheading Synopsis
20506
20507@smallexample
20508 -var-info-num-children @var{name}
20509@end smallexample
20510
20511Returns the number of children of a variable object @var{name}:
20512
20513@smallexample
20514 numchild=@var{n}
20515@end smallexample
20516
20517
20518@subheading The @code{-var-list-children} Command
20519@findex -var-list-children
20520
20521@subsubheading Synopsis
20522
20523@smallexample
bc8ced35 20524 -var-list-children [@var{print-values}] @var{name}
922fbb7b 20525@end smallexample
265eeb58 20526@anchor{-var-list-children}
922fbb7b 20527
265eeb58
NR
20528Return a list of the children of the specified variable object and
20529create variable objects for them, if they do not already exist. With
20530a single argument or if @var{print-values} has a value for of 0 or
20531@code{--no-values}, print only the names of the variables; if
20532@var{print-values} is 1 or @code{--all-values}, also print their
20533values; and if it is 2 or @code{--simple-values} print the name and
20534value for simple data types and just the name for arrays, structures
20535and unions.
bc8ced35
NR
20536
20537@subsubheading Example
922fbb7b
AC
20538
20539@smallexample
bc8ced35
NR
20540(@value{GDBP})
20541 -var-list-children n
265eeb58 20542 ^done,numchild=@var{n},children=[@{name=@var{name},
922fbb7b 20543 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
bc8ced35
NR
20544(@value{GDBP})
20545 -var-list-children --all-values n
265eeb58 20546 ^done,numchild=@var{n},children=[@{name=@var{name},
bc8ced35 20547 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
20548@end smallexample
20549
20550
20551@subheading The @code{-var-info-type} Command
20552@findex -var-info-type
20553
20554@subsubheading Synopsis
20555
20556@smallexample
20557 -var-info-type @var{name}
20558@end smallexample
20559
20560Returns the type of the specified variable @var{name}. The type is
20561returned as a string in the same format as it is output by the
20562@value{GDBN} CLI:
20563
20564@smallexample
20565 type=@var{typename}
20566@end smallexample
20567
20568
20569@subheading The @code{-var-info-expression} Command
20570@findex -var-info-expression
20571
20572@subsubheading Synopsis
20573
20574@smallexample
20575 -var-info-expression @var{name}
20576@end smallexample
20577
20578Returns what is represented by the variable object @var{name}:
20579
20580@smallexample
20581 lang=@var{lang-spec},exp=@var{expression}
20582@end smallexample
20583
20584@noindent
20585where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
20586
20587@subheading The @code{-var-show-attributes} Command
20588@findex -var-show-attributes
20589
20590@subsubheading Synopsis
20591
20592@smallexample
20593 -var-show-attributes @var{name}
20594@end smallexample
20595
20596List attributes of the specified variable object @var{name}:
20597
20598@smallexample
20599 status=@var{attr} [ ( ,@var{attr} )* ]
20600@end smallexample
20601
20602@noindent
20603where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
20604
20605@subheading The @code{-var-evaluate-expression} Command
20606@findex -var-evaluate-expression
20607
20608@subsubheading Synopsis
20609
20610@smallexample
20611 -var-evaluate-expression @var{name}
20612@end smallexample
20613
20614Evaluates the expression that is represented by the specified variable
20615object and returns its value as a string in the current format specified
20616for the object:
20617
20618@smallexample
20619 value=@var{value}
20620@end smallexample
20621
20622Note that one must invoke @code{-var-list-children} for a variable
20623before the value of a child variable can be evaluated.
20624
20625@subheading The @code{-var-assign} Command
20626@findex -var-assign
20627
20628@subsubheading Synopsis
20629
20630@smallexample
20631 -var-assign @var{name} @var{expression}
20632@end smallexample
20633
20634Assigns the value of @var{expression} to the variable object specified
20635by @var{name}. The object must be @samp{editable}. If the variable's
b383017d 20636value is altered by the assign, the variable will show up in any
922fbb7b
AC
20637subsequent @code{-var-update} list.
20638
20639@subsubheading Example
20640
20641@smallexample
20642(@value{GDBP})
20643-var-assign var1 3
20644^done,value="3"
20645(@value{GDBP})
20646-var-update *
20647^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
20648(@value{GDBP})
20649@end smallexample
20650
20651@subheading The @code{-var-update} Command
20652@findex -var-update
20653
20654@subsubheading Synopsis
20655
20656@smallexample
265eeb58 20657 -var-update [@var{print-values}] @{@var{name} | "*"@}
922fbb7b
AC
20658@end smallexample
20659
20660Update the value of the variable object @var{name} by evaluating its
20661expression after fetching all the new values from memory or registers.
265eeb58
NR
20662A @samp{*} causes all existing variable objects to be updated. The
20663option @var{print-values} determines whether names and values, or just
20664names are printed in the manner described for
20665@code{@pxref{-var-list-children}}.
20666
20667@subsubheading Example
922fbb7b 20668
265eeb58
NR
20669@smallexample
20670(@value{GDBP})
20671-var-assign var1 3
20672^done,value="3"
20673(@value{GDBP})
20674-var-update --all-values var1
20675^done,changelist=[@{name="var1",value="3",in_scope="true",
20676type_changed="false"@}]
20677(@value{GDBP})
20678@end smallexample
922fbb7b
AC
20679
20680@node Annotations
20681@chapter @value{GDBN} Annotations
20682
086432e2
AC
20683This chapter describes annotations in @value{GDBN}. Annotations were
20684designed to interface @value{GDBN} to graphical user interfaces or other
20685similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
20686relatively high level.
20687
086432e2
AC
20688The annotation mechanism has largely been superseeded by @sc{gdb/mi}
20689(@pxref{GDB/MI}).
20690
922fbb7b
AC
20691@ignore
20692This is Edition @value{EDITION}, @value{DATE}.
20693@end ignore
20694
20695@menu
20696* Annotations Overview:: What annotations are; the general syntax.
922fbb7b
AC
20697* Prompting:: Annotations marking @value{GDBN}'s need for input.
20698* Errors:: Annotations for error messages.
922fbb7b
AC
20699* Invalidation:: Some annotations describe things now invalid.
20700* Annotations for Running::
20701 Whether the program is running, how it stopped, etc.
20702* Source Annotations:: Annotations describing source code.
922fbb7b
AC
20703@end menu
20704
20705@node Annotations Overview
20706@section What is an Annotation?
20707@cindex annotations
20708
922fbb7b
AC
20709Annotations start with a newline character, two @samp{control-z}
20710characters, and the name of the annotation. If there is no additional
20711information associated with this annotation, the name of the annotation
20712is followed immediately by a newline. If there is additional
20713information, the name of the annotation is followed by a space, the
20714additional information, and a newline. The additional information
20715cannot contain newline characters.
20716
20717Any output not beginning with a newline and two @samp{control-z}
20718characters denotes literal output from @value{GDBN}. Currently there is
20719no need for @value{GDBN} to output a newline followed by two
20720@samp{control-z} characters, but if there was such a need, the
20721annotations could be extended with an @samp{escape} annotation which
20722means those three characters as output.
20723
086432e2
AC
20724The annotation @var{level}, which is specified using the
20725@option{--annotate} command line option (@pxref{Mode Options}), controls
20726how much information @value{GDBN} prints together with its prompt,
20727values of expressions, source lines, and other types of output. Level 0
20728is for no anntations, level 1 is for use when @value{GDBN} is run as a
20729subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
20730for programs that control @value{GDBN}, and level 2 annotations have
20731been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
20732Interface, annotate, GDB's Obsolete Annotations}).
20733
20734@table @code
20735@kindex set annotate
20736@item set annotate @var{level}
e09f16f9 20737The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 20738annotations to the specified @var{level}.
9c16f35a
EZ
20739
20740@item show annotate
20741@kindex show annotate
20742Show the current annotation level.
09d4efe1
EZ
20743@end table
20744
20745This chapter describes level 3 annotations.
086432e2 20746
922fbb7b
AC
20747A simple example of starting up @value{GDBN} with annotations is:
20748
20749@smallexample
086432e2
AC
20750$ @kbd{gdb --annotate=3}
20751GNU gdb 6.0
20752Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
20753GDB is free software, covered by the GNU General Public License,
20754and you are welcome to change it and/or distribute copies of it
20755under certain conditions.
20756Type "show copying" to see the conditions.
20757There is absolutely no warranty for GDB. Type "show warranty"
20758for details.
086432e2 20759This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
20760
20761^Z^Zpre-prompt
f7dc1244 20762(@value{GDBP})
922fbb7b 20763^Z^Zprompt
086432e2 20764@kbd{quit}
922fbb7b
AC
20765
20766^Z^Zpost-prompt
b383017d 20767$
922fbb7b
AC
20768@end smallexample
20769
20770Here @samp{quit} is input to @value{GDBN}; the rest is output from
20771@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
20772denotes a @samp{control-z} character) are annotations; the rest is
20773output from @value{GDBN}.
20774
922fbb7b
AC
20775@node Prompting
20776@section Annotation for @value{GDBN} Input
20777
20778@cindex annotations for prompts
20779When @value{GDBN} prompts for input, it annotates this fact so it is possible
20780to know when to send output, when the output from a given command is
20781over, etc.
20782
20783Different kinds of input each have a different @dfn{input type}. Each
20784input type has three annotations: a @code{pre-} annotation, which
20785denotes the beginning of any prompt which is being output, a plain
20786annotation, which denotes the end of the prompt, and then a @code{post-}
20787annotation which denotes the end of any echo which may (or may not) be
20788associated with the input. For example, the @code{prompt} input type
20789features the following annotations:
20790
20791@smallexample
20792^Z^Zpre-prompt
20793^Z^Zprompt
20794^Z^Zpost-prompt
20795@end smallexample
20796
20797The input types are
20798
20799@table @code
20800@findex pre-prompt
20801@findex prompt
20802@findex post-prompt
20803@item prompt
20804When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
20805
20806@findex pre-commands
20807@findex commands
20808@findex post-commands
20809@item commands
20810When @value{GDBN} prompts for a set of commands, like in the @code{commands}
20811command. The annotations are repeated for each command which is input.
20812
20813@findex pre-overload-choice
20814@findex overload-choice
20815@findex post-overload-choice
20816@item overload-choice
20817When @value{GDBN} wants the user to select between various overloaded functions.
20818
20819@findex pre-query
20820@findex query
20821@findex post-query
20822@item query
20823When @value{GDBN} wants the user to confirm a potentially dangerous operation.
20824
20825@findex pre-prompt-for-continue
20826@findex prompt-for-continue
20827@findex post-prompt-for-continue
20828@item prompt-for-continue
20829When @value{GDBN} is asking the user to press return to continue. Note: Don't
20830expect this to work well; instead use @code{set height 0} to disable
20831prompting. This is because the counting of lines is buggy in the
20832presence of annotations.
20833@end table
20834
20835@node Errors
20836@section Errors
20837@cindex annotations for errors, warnings and interrupts
20838
20839@findex quit
20840@smallexample
20841^Z^Zquit
20842@end smallexample
20843
20844This annotation occurs right before @value{GDBN} responds to an interrupt.
20845
20846@findex error
20847@smallexample
20848^Z^Zerror
20849@end smallexample
20850
20851This annotation occurs right before @value{GDBN} responds to an error.
20852
20853Quit and error annotations indicate that any annotations which @value{GDBN} was
20854in the middle of may end abruptly. For example, if a
20855@code{value-history-begin} annotation is followed by a @code{error}, one
20856cannot expect to receive the matching @code{value-history-end}. One
20857cannot expect not to receive it either, however; an error annotation
20858does not necessarily mean that @value{GDBN} is immediately returning all the way
20859to the top level.
20860
20861@findex error-begin
20862A quit or error annotation may be preceded by
20863
20864@smallexample
20865^Z^Zerror-begin
20866@end smallexample
20867
20868Any output between that and the quit or error annotation is the error
20869message.
20870
20871Warning messages are not yet annotated.
20872@c If we want to change that, need to fix warning(), type_error(),
20873@c range_error(), and possibly other places.
20874
922fbb7b
AC
20875@node Invalidation
20876@section Invalidation Notices
20877
20878@cindex annotations for invalidation messages
20879The following annotations say that certain pieces of state may have
20880changed.
20881
20882@table @code
20883@findex frames-invalid
20884@item ^Z^Zframes-invalid
20885
20886The frames (for example, output from the @code{backtrace} command) may
20887have changed.
20888
20889@findex breakpoints-invalid
20890@item ^Z^Zbreakpoints-invalid
20891
20892The breakpoints may have changed. For example, the user just added or
20893deleted a breakpoint.
20894@end table
20895
20896@node Annotations for Running
20897@section Running the Program
20898@cindex annotations for running programs
20899
20900@findex starting
20901@findex stopping
20902When the program starts executing due to a @value{GDBN} command such as
b383017d 20903@code{step} or @code{continue},
922fbb7b
AC
20904
20905@smallexample
20906^Z^Zstarting
20907@end smallexample
20908
b383017d 20909is output. When the program stops,
922fbb7b
AC
20910
20911@smallexample
20912^Z^Zstopped
20913@end smallexample
20914
20915is output. Before the @code{stopped} annotation, a variety of
20916annotations describe how the program stopped.
20917
20918@table @code
20919@findex exited
20920@item ^Z^Zexited @var{exit-status}
20921The program exited, and @var{exit-status} is the exit status (zero for
20922successful exit, otherwise nonzero).
20923
20924@findex signalled
20925@findex signal-name
20926@findex signal-name-end
20927@findex signal-string
20928@findex signal-string-end
20929@item ^Z^Zsignalled
20930The program exited with a signal. After the @code{^Z^Zsignalled}, the
20931annotation continues:
20932
20933@smallexample
20934@var{intro-text}
20935^Z^Zsignal-name
20936@var{name}
20937^Z^Zsignal-name-end
20938@var{middle-text}
20939^Z^Zsignal-string
20940@var{string}
20941^Z^Zsignal-string-end
20942@var{end-text}
20943@end smallexample
20944
20945@noindent
20946where @var{name} is the name of the signal, such as @code{SIGILL} or
20947@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
20948as @code{Illegal Instruction} or @code{Segmentation fault}.
20949@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
20950user's benefit and have no particular format.
20951
20952@findex signal
20953@item ^Z^Zsignal
20954The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
20955just saying that the program received the signal, not that it was
20956terminated with it.
20957
20958@findex breakpoint
20959@item ^Z^Zbreakpoint @var{number}
20960The program hit breakpoint number @var{number}.
20961
20962@findex watchpoint
20963@item ^Z^Zwatchpoint @var{number}
20964The program hit watchpoint number @var{number}.
20965@end table
20966
20967@node Source Annotations
20968@section Displaying Source
20969@cindex annotations for source display
20970
20971@findex source
20972The following annotation is used instead of displaying source code:
20973
20974@smallexample
20975^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
20976@end smallexample
20977
20978where @var{filename} is an absolute file name indicating which source
20979file, @var{line} is the line number within that file (where 1 is the
20980first line in the file), @var{character} is the character position
20981within the file (where 0 is the first character in the file) (for most
20982debug formats this will necessarily point to the beginning of a line),
20983@var{middle} is @samp{middle} if @var{addr} is in the middle of the
20984line, or @samp{beg} if @var{addr} is at the beginning of the line, and
20985@var{addr} is the address in the target program associated with the
20986source which is being displayed. @var{addr} is in the form @samp{0x}
20987followed by one or more lowercase hex digits (note that this does not
20988depend on the language).
20989
8e04817f
AC
20990@node GDB Bugs
20991@chapter Reporting Bugs in @value{GDBN}
20992@cindex bugs in @value{GDBN}
20993@cindex reporting bugs in @value{GDBN}
c906108c 20994
8e04817f 20995Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 20996
8e04817f
AC
20997Reporting a bug may help you by bringing a solution to your problem, or it
20998may not. But in any case the principal function of a bug report is to help
20999the entire community by making the next version of @value{GDBN} work better. Bug
21000reports are your contribution to the maintenance of @value{GDBN}.
c906108c 21001
8e04817f
AC
21002In order for a bug report to serve its purpose, you must include the
21003information that enables us to fix the bug.
c4555f82
SC
21004
21005@menu
8e04817f
AC
21006* Bug Criteria:: Have you found a bug?
21007* Bug Reporting:: How to report bugs
c4555f82
SC
21008@end menu
21009
8e04817f
AC
21010@node Bug Criteria
21011@section Have you found a bug?
21012@cindex bug criteria
c4555f82 21013
8e04817f 21014If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
21015
21016@itemize @bullet
8e04817f
AC
21017@cindex fatal signal
21018@cindex debugger crash
21019@cindex crash of debugger
c4555f82 21020@item
8e04817f
AC
21021If the debugger gets a fatal signal, for any input whatever, that is a
21022@value{GDBN} bug. Reliable debuggers never crash.
21023
21024@cindex error on valid input
21025@item
21026If @value{GDBN} produces an error message for valid input, that is a
21027bug. (Note that if you're cross debugging, the problem may also be
21028somewhere in the connection to the target.)
c4555f82 21029
8e04817f 21030@cindex invalid input
c4555f82 21031@item
8e04817f
AC
21032If @value{GDBN} does not produce an error message for invalid input,
21033that is a bug. However, you should note that your idea of
21034``invalid input'' might be our idea of ``an extension'' or ``support
21035for traditional practice''.
21036
21037@item
21038If you are an experienced user of debugging tools, your suggestions
21039for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
21040@end itemize
21041
8e04817f
AC
21042@node Bug Reporting
21043@section How to report bugs
21044@cindex bug reports
21045@cindex @value{GDBN} bugs, reporting
21046
21047A number of companies and individuals offer support for @sc{gnu} products.
21048If you obtained @value{GDBN} from a support organization, we recommend you
21049contact that organization first.
21050
21051You can find contact information for many support companies and
21052individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
21053distribution.
21054@c should add a web page ref...
21055
129188f6
AC
21056In any event, we also recommend that you submit bug reports for
21057@value{GDBN}. The prefered method is to submit them directly using
21058@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
21059page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
21060be used.
8e04817f
AC
21061
21062@strong{Do not send bug reports to @samp{info-gdb}, or to
21063@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
21064not want to receive bug reports. Those that do have arranged to receive
21065@samp{bug-gdb}.
21066
21067The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
21068serves as a repeater. The mailing list and the newsgroup carry exactly
21069the same messages. Often people think of posting bug reports to the
21070newsgroup instead of mailing them. This appears to work, but it has one
21071problem which can be crucial: a newsgroup posting often lacks a mail
21072path back to the sender. Thus, if we need to ask for more information,
21073we may be unable to reach you. For this reason, it is better to send
21074bug reports to the mailing list.
c4555f82 21075
8e04817f
AC
21076The fundamental principle of reporting bugs usefully is this:
21077@strong{report all the facts}. If you are not sure whether to state a
21078fact or leave it out, state it!
c4555f82 21079
8e04817f
AC
21080Often people omit facts because they think they know what causes the
21081problem and assume that some details do not matter. Thus, you might
21082assume that the name of the variable you use in an example does not matter.
21083Well, probably it does not, but one cannot be sure. Perhaps the bug is a
21084stray memory reference which happens to fetch from the location where that
21085name is stored in memory; perhaps, if the name were different, the contents
21086of that location would fool the debugger into doing the right thing despite
21087the bug. Play it safe and give a specific, complete example. That is the
21088easiest thing for you to do, and the most helpful.
c4555f82 21089
8e04817f
AC
21090Keep in mind that the purpose of a bug report is to enable us to fix the
21091bug. It may be that the bug has been reported previously, but neither
21092you nor we can know that unless your bug report is complete and
21093self-contained.
c4555f82 21094
8e04817f
AC
21095Sometimes people give a few sketchy facts and ask, ``Does this ring a
21096bell?'' Those bug reports are useless, and we urge everyone to
21097@emph{refuse to respond to them} except to chide the sender to report
21098bugs properly.
21099
21100To enable us to fix the bug, you should include all these things:
c4555f82
SC
21101
21102@itemize @bullet
21103@item
8e04817f
AC
21104The version of @value{GDBN}. @value{GDBN} announces it if you start
21105with no arguments; you can also print it at any time using @code{show
21106version}.
c4555f82 21107
8e04817f
AC
21108Without this, we will not know whether there is any point in looking for
21109the bug in the current version of @value{GDBN}.
c4555f82
SC
21110
21111@item
8e04817f
AC
21112The type of machine you are using, and the operating system name and
21113version number.
c4555f82
SC
21114
21115@item
8e04817f
AC
21116What compiler (and its version) was used to compile @value{GDBN}---e.g.
21117``@value{GCC}--2.8.1''.
c4555f82
SC
21118
21119@item
8e04817f
AC
21120What compiler (and its version) was used to compile the program you are
21121debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
21122C Compiler''. For GCC, you can say @code{gcc --version} to get this
21123information; for other compilers, see the documentation for those
21124compilers.
c4555f82 21125
8e04817f
AC
21126@item
21127The command arguments you gave the compiler to compile your example and
21128observe the bug. For example, did you use @samp{-O}? To guarantee
21129you will not omit something important, list them all. A copy of the
21130Makefile (or the output from make) is sufficient.
c4555f82 21131
8e04817f
AC
21132If we were to try to guess the arguments, we would probably guess wrong
21133and then we might not encounter the bug.
c4555f82 21134
8e04817f
AC
21135@item
21136A complete input script, and all necessary source files, that will
21137reproduce the bug.
c4555f82 21138
8e04817f
AC
21139@item
21140A description of what behavior you observe that you believe is
21141incorrect. For example, ``It gets a fatal signal.''
c4555f82 21142
8e04817f
AC
21143Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
21144will certainly notice it. But if the bug is incorrect output, we might
21145not notice unless it is glaringly wrong. You might as well not give us
21146a chance to make a mistake.
c4555f82 21147
8e04817f
AC
21148Even if the problem you experience is a fatal signal, you should still
21149say so explicitly. Suppose something strange is going on, such as, your
21150copy of @value{GDBN} is out of synch, or you have encountered a bug in
21151the C library on your system. (This has happened!) Your copy might
21152crash and ours would not. If you told us to expect a crash, then when
21153ours fails to crash, we would know that the bug was not happening for
21154us. If you had not told us to expect a crash, then we would not be able
21155to draw any conclusion from our observations.
c4555f82 21156
e0c07bf0
MC
21157@pindex script
21158@cindex recording a session script
21159To collect all this information, you can use a session recording program
21160such as @command{script}, which is available on many Unix systems.
21161Just run your @value{GDBN} session inside @command{script} and then
21162include the @file{typescript} file with your bug report.
21163
21164Another way to record a @value{GDBN} session is to run @value{GDBN}
21165inside Emacs and then save the entire buffer to a file.
21166
8e04817f
AC
21167@item
21168If you wish to suggest changes to the @value{GDBN} source, send us context
21169diffs. If you even discuss something in the @value{GDBN} source, refer to
21170it by context, not by line number.
c4555f82 21171
8e04817f
AC
21172The line numbers in our development sources will not match those in your
21173sources. Your line numbers would convey no useful information to us.
c4555f82 21174
8e04817f 21175@end itemize
c4555f82 21176
8e04817f 21177Here are some things that are not necessary:
c4555f82 21178
8e04817f
AC
21179@itemize @bullet
21180@item
21181A description of the envelope of the bug.
c4555f82 21182
8e04817f
AC
21183Often people who encounter a bug spend a lot of time investigating
21184which changes to the input file will make the bug go away and which
21185changes will not affect it.
c4555f82 21186
8e04817f
AC
21187This is often time consuming and not very useful, because the way we
21188will find the bug is by running a single example under the debugger
21189with breakpoints, not by pure deduction from a series of examples.
21190We recommend that you save your time for something else.
c4555f82 21191
8e04817f
AC
21192Of course, if you can find a simpler example to report @emph{instead}
21193of the original one, that is a convenience for us. Errors in the
21194output will be easier to spot, running under the debugger will take
21195less time, and so on.
c4555f82 21196
8e04817f
AC
21197However, simplification is not vital; if you do not want to do this,
21198report the bug anyway and send us the entire test case you used.
c4555f82 21199
8e04817f
AC
21200@item
21201A patch for the bug.
c4555f82 21202
8e04817f
AC
21203A patch for the bug does help us if it is a good one. But do not omit
21204the necessary information, such as the test case, on the assumption that
21205a patch is all we need. We might see problems with your patch and decide
21206to fix the problem another way, or we might not understand it at all.
c4555f82 21207
8e04817f
AC
21208Sometimes with a program as complicated as @value{GDBN} it is very hard to
21209construct an example that will make the program follow a certain path
21210through the code. If you do not send us the example, we will not be able
21211to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 21212
8e04817f
AC
21213And if we cannot understand what bug you are trying to fix, or why your
21214patch should be an improvement, we will not install it. A test case will
21215help us to understand.
c4555f82 21216
8e04817f
AC
21217@item
21218A guess about what the bug is or what it depends on.
c4555f82 21219
8e04817f
AC
21220Such guesses are usually wrong. Even we cannot guess right about such
21221things without first using the debugger to find the facts.
21222@end itemize
c4555f82 21223
8e04817f
AC
21224@c The readline documentation is distributed with the readline code
21225@c and consists of the two following files:
21226@c rluser.texinfo
21227@c inc-hist.texinfo
21228@c Use -I with makeinfo to point to the appropriate directory,
21229@c environment var TEXINPUTS with TeX.
21230@include rluser.texinfo
21231@include inc-hist.texinfo
c4555f82 21232
c4555f82 21233
8e04817f
AC
21234@node Formatting Documentation
21235@appendix Formatting Documentation
c4555f82 21236
8e04817f
AC
21237@cindex @value{GDBN} reference card
21238@cindex reference card
21239The @value{GDBN} 4 release includes an already-formatted reference card, ready
21240for printing with PostScript or Ghostscript, in the @file{gdb}
21241subdirectory of the main source directory@footnote{In
21242@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
21243release.}. If you can use PostScript or Ghostscript with your printer,
21244you can print the reference card immediately with @file{refcard.ps}.
c4555f82 21245
8e04817f
AC
21246The release also includes the source for the reference card. You
21247can format it, using @TeX{}, by typing:
c4555f82 21248
474c8240 21249@smallexample
8e04817f 21250make refcard.dvi
474c8240 21251@end smallexample
c4555f82 21252
8e04817f
AC
21253The @value{GDBN} reference card is designed to print in @dfn{landscape}
21254mode on US ``letter'' size paper;
21255that is, on a sheet 11 inches wide by 8.5 inches
21256high. You will need to specify this form of printing as an option to
21257your @sc{dvi} output program.
c4555f82 21258
8e04817f 21259@cindex documentation
c4555f82 21260
8e04817f
AC
21261All the documentation for @value{GDBN} comes as part of the machine-readable
21262distribution. The documentation is written in Texinfo format, which is
21263a documentation system that uses a single source file to produce both
21264on-line information and a printed manual. You can use one of the Info
21265formatting commands to create the on-line version of the documentation
21266and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 21267
8e04817f
AC
21268@value{GDBN} includes an already formatted copy of the on-line Info
21269version of this manual in the @file{gdb} subdirectory. The main Info
21270file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
21271subordinate files matching @samp{gdb.info*} in the same directory. If
21272necessary, you can print out these files, or read them with any editor;
21273but they are easier to read using the @code{info} subsystem in @sc{gnu}
21274Emacs or the standalone @code{info} program, available as part of the
21275@sc{gnu} Texinfo distribution.
c4555f82 21276
8e04817f
AC
21277If you want to format these Info files yourself, you need one of the
21278Info formatting programs, such as @code{texinfo-format-buffer} or
21279@code{makeinfo}.
c4555f82 21280
8e04817f
AC
21281If you have @code{makeinfo} installed, and are in the top level
21282@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
21283version @value{GDBVN}), you can make the Info file by typing:
c4555f82 21284
474c8240 21285@smallexample
8e04817f
AC
21286cd gdb
21287make gdb.info
474c8240 21288@end smallexample
c4555f82 21289
8e04817f
AC
21290If you want to typeset and print copies of this manual, you need @TeX{},
21291a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
21292Texinfo definitions file.
c4555f82 21293
8e04817f
AC
21294@TeX{} is a typesetting program; it does not print files directly, but
21295produces output files called @sc{dvi} files. To print a typeset
21296document, you need a program to print @sc{dvi} files. If your system
21297has @TeX{} installed, chances are it has such a program. The precise
21298command to use depends on your system; @kbd{lpr -d} is common; another
21299(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
21300require a file name without any extension or a @samp{.dvi} extension.
c4555f82 21301
8e04817f
AC
21302@TeX{} also requires a macro definitions file called
21303@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
21304written in Texinfo format. On its own, @TeX{} cannot either read or
21305typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
21306and is located in the @file{gdb-@var{version-number}/texinfo}
21307directory.
c4555f82 21308
8e04817f
AC
21309If you have @TeX{} and a @sc{dvi} printer program installed, you can
21310typeset and print this manual. First switch to the the @file{gdb}
21311subdirectory of the main source directory (for example, to
21312@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 21313
474c8240 21314@smallexample
8e04817f 21315make gdb.dvi
474c8240 21316@end smallexample
c4555f82 21317
8e04817f 21318Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 21319
8e04817f
AC
21320@node Installing GDB
21321@appendix Installing @value{GDBN}
21322@cindex configuring @value{GDBN}
21323@cindex installation
94e91d6d 21324@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 21325
8e04817f
AC
21326@value{GDBN} comes with a @code{configure} script that automates the process
21327of preparing @value{GDBN} for installation; you can then use @code{make} to
21328build the @code{gdb} program.
21329@iftex
21330@c irrelevant in info file; it's as current as the code it lives with.
21331@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
21332look at the @file{README} file in the sources; we may have improved the
21333installation procedures since publishing this manual.}
21334@end iftex
c4555f82 21335
8e04817f
AC
21336The @value{GDBN} distribution includes all the source code you need for
21337@value{GDBN} in a single directory, whose name is usually composed by
21338appending the version number to @samp{gdb}.
c4555f82 21339
8e04817f
AC
21340For example, the @value{GDBN} version @value{GDBVN} distribution is in the
21341@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 21342
8e04817f
AC
21343@table @code
21344@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
21345script for configuring @value{GDBN} and all its supporting libraries
c4555f82 21346
8e04817f
AC
21347@item gdb-@value{GDBVN}/gdb
21348the source specific to @value{GDBN} itself
c4555f82 21349
8e04817f
AC
21350@item gdb-@value{GDBVN}/bfd
21351source for the Binary File Descriptor library
c906108c 21352
8e04817f
AC
21353@item gdb-@value{GDBVN}/include
21354@sc{gnu} include files
c906108c 21355
8e04817f
AC
21356@item gdb-@value{GDBVN}/libiberty
21357source for the @samp{-liberty} free software library
c906108c 21358
8e04817f
AC
21359@item gdb-@value{GDBVN}/opcodes
21360source for the library of opcode tables and disassemblers
c906108c 21361
8e04817f
AC
21362@item gdb-@value{GDBVN}/readline
21363source for the @sc{gnu} command-line interface
c906108c 21364
8e04817f
AC
21365@item gdb-@value{GDBVN}/glob
21366source for the @sc{gnu} filename pattern-matching subroutine
c906108c 21367
8e04817f
AC
21368@item gdb-@value{GDBVN}/mmalloc
21369source for the @sc{gnu} memory-mapped malloc package
21370@end table
c906108c 21371
8e04817f
AC
21372The simplest way to configure and build @value{GDBN} is to run @code{configure}
21373from the @file{gdb-@var{version-number}} source directory, which in
21374this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 21375
8e04817f
AC
21376First switch to the @file{gdb-@var{version-number}} source directory
21377if you are not already in it; then run @code{configure}. Pass the
21378identifier for the platform on which @value{GDBN} will run as an
21379argument.
c906108c 21380
8e04817f 21381For example:
c906108c 21382
474c8240 21383@smallexample
8e04817f
AC
21384cd gdb-@value{GDBVN}
21385./configure @var{host}
21386make
474c8240 21387@end smallexample
c906108c 21388
8e04817f
AC
21389@noindent
21390where @var{host} is an identifier such as @samp{sun4} or
21391@samp{decstation}, that identifies the platform where @value{GDBN} will run.
21392(You can often leave off @var{host}; @code{configure} tries to guess the
21393correct value by examining your system.)
c906108c 21394
8e04817f
AC
21395Running @samp{configure @var{host}} and then running @code{make} builds the
21396@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
21397libraries, then @code{gdb} itself. The configured source files, and the
21398binaries, are left in the corresponding source directories.
c906108c 21399
8e04817f
AC
21400@need 750
21401@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
21402system does not recognize this automatically when you run a different
21403shell, you may need to run @code{sh} on it explicitly:
c906108c 21404
474c8240 21405@smallexample
8e04817f 21406sh configure @var{host}
474c8240 21407@end smallexample
c906108c 21408
8e04817f
AC
21409If you run @code{configure} from a directory that contains source
21410directories for multiple libraries or programs, such as the
21411@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
21412creates configuration files for every directory level underneath (unless
21413you tell it not to, with the @samp{--norecursion} option).
21414
94e91d6d
MC
21415You should run the @code{configure} script from the top directory in the
21416source tree, the @file{gdb-@var{version-number}} directory. If you run
21417@code{configure} from one of the subdirectories, you will configure only
21418that subdirectory. That is usually not what you want. In particular,
21419if you run the first @code{configure} from the @file{gdb} subdirectory
21420of the @file{gdb-@var{version-number}} directory, you will omit the
21421configuration of @file{bfd}, @file{readline}, and other sibling
21422directories of the @file{gdb} subdirectory. This leads to build errors
21423about missing include files such as @file{bfd/bfd.h}.
c906108c 21424
8e04817f
AC
21425You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
21426However, you should make sure that the shell on your path (named by
21427the @samp{SHELL} environment variable) is publicly readable. Remember
21428that @value{GDBN} uses the shell to start your program---some systems refuse to
21429let @value{GDBN} debug child processes whose programs are not readable.
c906108c 21430
8e04817f
AC
21431@menu
21432* Separate Objdir:: Compiling @value{GDBN} in another directory
21433* Config Names:: Specifying names for hosts and targets
21434* Configure Options:: Summary of options for configure
21435@end menu
c906108c 21436
8e04817f
AC
21437@node Separate Objdir
21438@section Compiling @value{GDBN} in another directory
c906108c 21439
8e04817f
AC
21440If you want to run @value{GDBN} versions for several host or target machines,
21441you need a different @code{gdb} compiled for each combination of
21442host and target. @code{configure} is designed to make this easy by
21443allowing you to generate each configuration in a separate subdirectory,
21444rather than in the source directory. If your @code{make} program
21445handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
21446@code{make} in each of these directories builds the @code{gdb}
21447program specified there.
c906108c 21448
8e04817f
AC
21449To build @code{gdb} in a separate directory, run @code{configure}
21450with the @samp{--srcdir} option to specify where to find the source.
21451(You also need to specify a path to find @code{configure}
21452itself from your working directory. If the path to @code{configure}
21453would be the same as the argument to @samp{--srcdir}, you can leave out
21454the @samp{--srcdir} option; it is assumed.)
c906108c 21455
8e04817f
AC
21456For example, with version @value{GDBVN}, you can build @value{GDBN} in a
21457separate directory for a Sun 4 like this:
c906108c 21458
474c8240 21459@smallexample
8e04817f
AC
21460@group
21461cd gdb-@value{GDBVN}
21462mkdir ../gdb-sun4
21463cd ../gdb-sun4
21464../gdb-@value{GDBVN}/configure sun4
21465make
21466@end group
474c8240 21467@end smallexample
c906108c 21468
8e04817f
AC
21469When @code{configure} builds a configuration using a remote source
21470directory, it creates a tree for the binaries with the same structure
21471(and using the same names) as the tree under the source directory. In
21472the example, you'd find the Sun 4 library @file{libiberty.a} in the
21473directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
21474@file{gdb-sun4/gdb}.
c906108c 21475
94e91d6d
MC
21476Make sure that your path to the @file{configure} script has just one
21477instance of @file{gdb} in it. If your path to @file{configure} looks
21478like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
21479one subdirectory of @value{GDBN}, not the whole package. This leads to
21480build errors about missing include files such as @file{bfd/bfd.h}.
21481
8e04817f
AC
21482One popular reason to build several @value{GDBN} configurations in separate
21483directories is to configure @value{GDBN} for cross-compiling (where
21484@value{GDBN} runs on one machine---the @dfn{host}---while debugging
21485programs that run on another machine---the @dfn{target}).
21486You specify a cross-debugging target by
21487giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 21488
8e04817f
AC
21489When you run @code{make} to build a program or library, you must run
21490it in a configured directory---whatever directory you were in when you
21491called @code{configure} (or one of its subdirectories).
c906108c 21492
8e04817f
AC
21493The @code{Makefile} that @code{configure} generates in each source
21494directory also runs recursively. If you type @code{make} in a source
21495directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
21496directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
21497will build all the required libraries, and then build GDB.
c906108c 21498
8e04817f
AC
21499When you have multiple hosts or targets configured in separate
21500directories, you can run @code{make} on them in parallel (for example,
21501if they are NFS-mounted on each of the hosts); they will not interfere
21502with each other.
c906108c 21503
8e04817f
AC
21504@node Config Names
21505@section Specifying names for hosts and targets
c906108c 21506
8e04817f
AC
21507The specifications used for hosts and targets in the @code{configure}
21508script are based on a three-part naming scheme, but some short predefined
21509aliases are also supported. The full naming scheme encodes three pieces
21510of information in the following pattern:
c906108c 21511
474c8240 21512@smallexample
8e04817f 21513@var{architecture}-@var{vendor}-@var{os}
474c8240 21514@end smallexample
c906108c 21515
8e04817f
AC
21516For example, you can use the alias @code{sun4} as a @var{host} argument,
21517or as the value for @var{target} in a @code{--target=@var{target}}
21518option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 21519
8e04817f
AC
21520The @code{configure} script accompanying @value{GDBN} does not provide
21521any query facility to list all supported host and target names or
21522aliases. @code{configure} calls the Bourne shell script
21523@code{config.sub} to map abbreviations to full names; you can read the
21524script, if you wish, or you can use it to test your guesses on
21525abbreviations---for example:
c906108c 21526
8e04817f
AC
21527@smallexample
21528% sh config.sub i386-linux
21529i386-pc-linux-gnu
21530% sh config.sub alpha-linux
21531alpha-unknown-linux-gnu
21532% sh config.sub hp9k700
21533hppa1.1-hp-hpux
21534% sh config.sub sun4
21535sparc-sun-sunos4.1.1
21536% sh config.sub sun3
21537m68k-sun-sunos4.1.1
21538% sh config.sub i986v
21539Invalid configuration `i986v': machine `i986v' not recognized
21540@end smallexample
c906108c 21541
8e04817f
AC
21542@noindent
21543@code{config.sub} is also distributed in the @value{GDBN} source
21544directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 21545
8e04817f
AC
21546@node Configure Options
21547@section @code{configure} options
c906108c 21548
8e04817f
AC
21549Here is a summary of the @code{configure} options and arguments that
21550are most often useful for building @value{GDBN}. @code{configure} also has
21551several other options not listed here. @inforef{What Configure
21552Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 21553
474c8240 21554@smallexample
8e04817f
AC
21555configure @r{[}--help@r{]}
21556 @r{[}--prefix=@var{dir}@r{]}
21557 @r{[}--exec-prefix=@var{dir}@r{]}
21558 @r{[}--srcdir=@var{dirname}@r{]}
21559 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
21560 @r{[}--target=@var{target}@r{]}
21561 @var{host}
474c8240 21562@end smallexample
c906108c 21563
8e04817f
AC
21564@noindent
21565You may introduce options with a single @samp{-} rather than
21566@samp{--} if you prefer; but you may abbreviate option names if you use
21567@samp{--}.
c906108c 21568
8e04817f
AC
21569@table @code
21570@item --help
21571Display a quick summary of how to invoke @code{configure}.
c906108c 21572
8e04817f
AC
21573@item --prefix=@var{dir}
21574Configure the source to install programs and files under directory
21575@file{@var{dir}}.
c906108c 21576
8e04817f
AC
21577@item --exec-prefix=@var{dir}
21578Configure the source to install programs under directory
21579@file{@var{dir}}.
c906108c 21580
8e04817f
AC
21581@c avoid splitting the warning from the explanation:
21582@need 2000
21583@item --srcdir=@var{dirname}
21584@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
21585@code{make} that implements the @code{VPATH} feature.}@*
21586Use this option to make configurations in directories separate from the
21587@value{GDBN} source directories. Among other things, you can use this to
21588build (or maintain) several configurations simultaneously, in separate
21589directories. @code{configure} writes configuration specific files in
21590the current directory, but arranges for them to use the source in the
21591directory @var{dirname}. @code{configure} creates directories under
21592the working directory in parallel to the source directories below
21593@var{dirname}.
c906108c 21594
8e04817f
AC
21595@item --norecursion
21596Configure only the directory level where @code{configure} is executed; do not
21597propagate configuration to subdirectories.
c906108c 21598
8e04817f
AC
21599@item --target=@var{target}
21600Configure @value{GDBN} for cross-debugging programs running on the specified
21601@var{target}. Without this option, @value{GDBN} is configured to debug
21602programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 21603
8e04817f 21604There is no convenient way to generate a list of all available targets.
c906108c 21605
8e04817f
AC
21606@item @var{host} @dots{}
21607Configure @value{GDBN} to run on the specified @var{host}.
c906108c 21608
8e04817f
AC
21609There is no convenient way to generate a list of all available hosts.
21610@end table
c906108c 21611
8e04817f
AC
21612There are many other options available as well, but they are generally
21613needed for special purposes only.
c906108c 21614
8e04817f
AC
21615@node Maintenance Commands
21616@appendix Maintenance Commands
21617@cindex maintenance commands
21618@cindex internal commands
c906108c 21619
8e04817f 21620In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
21621includes a number of commands intended for @value{GDBN} developers,
21622that are not documented elsewhere in this manual. These commands are
da316a69
EZ
21623provided here for reference. (For commands that turn on debugging
21624messages, see @ref{Debugging Output}.)
c906108c 21625
8e04817f 21626@table @code
09d4efe1
EZ
21627@kindex maint agent
21628@item maint agent @var{expression}
21629Translate the given @var{expression} into remote agent bytecodes.
21630This command is useful for debugging the Agent Expression mechanism
21631(@pxref{Agent Expressions}).
21632
8e04817f
AC
21633@kindex maint info breakpoints
21634@item @anchor{maint info breakpoints}maint info breakpoints
21635Using the same format as @samp{info breakpoints}, display both the
21636breakpoints you've set explicitly, and those @value{GDBN} is using for
21637internal purposes. Internal breakpoints are shown with negative
21638breakpoint numbers. The type column identifies what kind of breakpoint
21639is shown:
c906108c 21640
8e04817f
AC
21641@table @code
21642@item breakpoint
21643Normal, explicitly set breakpoint.
c906108c 21644
8e04817f
AC
21645@item watchpoint
21646Normal, explicitly set watchpoint.
c906108c 21647
8e04817f
AC
21648@item longjmp
21649Internal breakpoint, used to handle correctly stepping through
21650@code{longjmp} calls.
c906108c 21651
8e04817f
AC
21652@item longjmp resume
21653Internal breakpoint at the target of a @code{longjmp}.
c906108c 21654
8e04817f
AC
21655@item until
21656Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 21657
8e04817f
AC
21658@item finish
21659Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 21660
8e04817f
AC
21661@item shlib events
21662Shared library events.
c906108c 21663
8e04817f 21664@end table
c906108c 21665
09d4efe1
EZ
21666@kindex maint check-symtabs
21667@item maint check-symtabs
21668Check the consistency of psymtabs and symtabs.
21669
21670@kindex maint cplus first_component
21671@item maint cplus first_component @var{name}
21672Print the first C@t{++} class/namespace component of @var{name}.
21673
21674@kindex maint cplus namespace
21675@item maint cplus namespace
21676Print the list of possible C@t{++} namespaces.
21677
21678@kindex maint demangle
21679@item maint demangle @var{name}
21680Demangle a C@t{++} or Objective-C manled @var{name}.
21681
21682@kindex maint deprecate
21683@kindex maint undeprecate
21684@cindex deprecated commands
21685@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
21686@itemx maint undeprecate @var{command}
21687Deprecate or undeprecate the named @var{command}. Deprecated commands
21688cause @value{GDBN} to issue a warning when you use them. The optional
21689argument @var{replacement} says which newer command should be used in
21690favor of the deprecated one; if it is given, @value{GDBN} will mention
21691the replacement as part of the warning.
21692
21693@kindex maint dump-me
21694@item maint dump-me
721c2651 21695@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 21696Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
21697This is supported only on systems which support aborting a program
21698with the @code{SIGQUIT} signal.
09d4efe1 21699
8d30a00d
AC
21700@kindex maint internal-error
21701@kindex maint internal-warning
09d4efe1
EZ
21702@item maint internal-error @r{[}@var{message-text}@r{]}
21703@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
21704Cause @value{GDBN} to call the internal function @code{internal_error}
21705or @code{internal_warning} and hence behave as though an internal error
21706or internal warning has been detected. In addition to reporting the
21707internal problem, these functions give the user the opportunity to
21708either quit @value{GDBN} or create a core file of the current
21709@value{GDBN} session.
21710
09d4efe1
EZ
21711These commands take an optional parameter @var{message-text} that is
21712used as the text of the error or warning message.
21713
21714Here's an example of using @code{indernal-error}:
21715
8d30a00d 21716@smallexample
f7dc1244 21717(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
21718@dots{}/maint.c:121: internal-error: testing, 1, 2
21719A problem internal to GDB has been detected. Further
21720debugging may prove unreliable.
21721Quit this debugging session? (y or n) @kbd{n}
21722Create a core file? (y or n) @kbd{n}
f7dc1244 21723(@value{GDBP})
8d30a00d
AC
21724@end smallexample
21725
09d4efe1
EZ
21726@kindex maint packet
21727@item maint packet @var{text}
21728If @value{GDBN} is talking to an inferior via the serial protocol,
21729then this command sends the string @var{text} to the inferior, and
21730displays the response packet. @value{GDBN} supplies the initial
21731@samp{$} character, the terminating @samp{#} character, and the
21732checksum.
21733
21734@kindex maint print architecture
21735@item maint print architecture @r{[}@var{file}@r{]}
21736Print the entire architecture configuration. The optional argument
21737@var{file} names the file where the output goes.
8d30a00d 21738
00905d52
AC
21739@kindex maint print dummy-frames
21740@item maint print dummy-frames
00905d52
AC
21741Prints the contents of @value{GDBN}'s internal dummy-frame stack.
21742
21743@smallexample
f7dc1244 21744(@value{GDBP}) @kbd{b add}
00905d52 21745@dots{}
f7dc1244 21746(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
21747Breakpoint 2, add (a=2, b=3) at @dots{}
2174858 return (a + b);
21749The program being debugged stopped while in a function called from GDB.
21750@dots{}
f7dc1244 21751(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
217520x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
21753 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
21754 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 21755(@value{GDBP})
00905d52
AC
21756@end smallexample
21757
21758Takes an optional file parameter.
21759
0680b120
AC
21760@kindex maint print registers
21761@kindex maint print raw-registers
21762@kindex maint print cooked-registers
617073a9 21763@kindex maint print register-groups
09d4efe1
EZ
21764@item maint print registers @r{[}@var{file}@r{]}
21765@itemx maint print raw-registers @r{[}@var{file}@r{]}
21766@itemx maint print cooked-registers @r{[}@var{file}@r{]}
21767@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
21768Print @value{GDBN}'s internal register data structures.
21769
617073a9
AC
21770The command @code{maint print raw-registers} includes the contents of
21771the raw register cache; the command @code{maint print cooked-registers}
21772includes the (cooked) value of all registers; and the command
21773@code{maint print register-groups} includes the groups that each
21774register is a member of. @xref{Registers,, Registers, gdbint,
21775@value{GDBN} Internals}.
0680b120 21776
09d4efe1
EZ
21777These commands take an optional parameter, a file name to which to
21778write the information.
0680b120 21779
617073a9 21780@kindex maint print reggroups
09d4efe1
EZ
21781@item maint print reggroups @r{[}@var{file}@r{]}
21782Print @value{GDBN}'s internal register group data structures. The
21783optional argument @var{file} tells to what file to write the
21784information.
617073a9 21785
09d4efe1 21786The register groups info looks like this:
617073a9
AC
21787
21788@smallexample
f7dc1244 21789(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
21790 Group Type
21791 general user
21792 float user
21793 all user
21794 vector user
21795 system user
21796 save internal
21797 restore internal
617073a9
AC
21798@end smallexample
21799
09d4efe1
EZ
21800@kindex flushregs
21801@item flushregs
21802This command forces @value{GDBN} to flush its internal register cache.
21803
21804@kindex maint print objfiles
21805@cindex info for known object files
21806@item maint print objfiles
21807Print a dump of all known object files. For each object file, this
21808command prints its name, address in memory, and all of its psymtabs
21809and symtabs.
21810
21811@kindex maint print statistics
21812@cindex bcache statistics
21813@item maint print statistics
21814This command prints, for each object file in the program, various data
21815about that object file followed by the byte cache (@dfn{bcache})
21816statistics for the object file. The objfile data includes the number
21817of minimal, partical, full, and stabs symbols, the number of types
21818defined by the objfile, the number of as yet unexpanded psym tables,
21819the number of line tables and string tables, and the amount of memory
21820used by the various tables. The bcache statistics include the counts,
21821sizes, and counts of duplicates of all and unique objects, max,
21822average, and median entry size, total memory used and its overhead and
21823savings, and various measures of the hash table size and chain
21824lengths.
21825
21826@kindex maint print type
21827@cindex type chain of a data type
21828@item maint print type @var{expr}
21829Print the type chain for a type specified by @var{expr}. The argument
21830can be either a type name or a symbol. If it is a symbol, the type of
21831that symbol is described. The type chain produced by this command is
21832a recursive definition of the data type as stored in @value{GDBN}'s
21833data structures, including its flags and contained types.
21834
21835@kindex maint set dwarf2 max-cache-age
21836@kindex maint show dwarf2 max-cache-age
21837@item maint set dwarf2 max-cache-age
21838@itemx maint show dwarf2 max-cache-age
21839Control the DWARF 2 compilation unit cache.
21840
21841@cindex DWARF 2 compilation units cache
21842In object files with inter-compilation-unit references, such as those
21843produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
21844reader needs to frequently refer to previously read compilation units.
21845This setting controls how long a compilation unit will remain in the
21846cache if it is not referenced. A higher limit means that cached
21847compilation units will be stored in memory longer, and more total
21848memory will be used. Setting it to zero disables caching, which will
21849slow down @value{GDBN} startup, but reduce memory consumption.
21850
e7ba9c65
DJ
21851@kindex maint set profile
21852@kindex maint show profile
21853@cindex profiling GDB
21854@item maint set profile
21855@itemx maint show profile
21856Control profiling of @value{GDBN}.
21857
21858Profiling will be disabled until you use the @samp{maint set profile}
21859command to enable it. When you enable profiling, the system will begin
21860collecting timing and execution count data; when you disable profiling or
21861exit @value{GDBN}, the results will be written to a log file. Remember that
21862if you use profiling, @value{GDBN} will overwrite the profiling log file
21863(often called @file{gmon.out}). If you have a record of important profiling
21864data in a @file{gmon.out} file, be sure to move it to a safe location.
21865
21866Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 21867compiled with the @samp{-pg} compiler option.
e7ba9c65 21868
09d4efe1
EZ
21869@kindex maint show-debug-regs
21870@cindex x86 hardware debug registers
21871@item maint show-debug-regs
21872Control whether to show variables that mirror the x86 hardware debug
21873registers. Use @code{ON} to enable, @code{OFF} to disable. If
21874enabled, the debug registers values are shown when GDB inserts or
21875removes a hardware breakpoint or watchpoint, and when the inferior
21876triggers a hardware-assisted breakpoint or watchpoint.
21877
21878@kindex maint space
21879@cindex memory used by commands
21880@item maint space
21881Control whether to display memory usage for each command. If set to a
21882nonzero value, @value{GDBN} will display how much memory each command
21883took, following the command's own output. This can also be requested
21884by invoking @value{GDBN} with the @option{--statistics} command-line
21885switch (@pxref{Mode Options}).
21886
21887@kindex maint time
21888@cindex time of command execution
21889@item maint time
21890Control whether to display the execution time for each command. If
21891set to a nonzero value, @value{GDBN} will display how much time it
21892took to execute each command, following the command's own output.
21893This can also be requested by invoking @value{GDBN} with the
21894@option{--statistics} command-line switch (@pxref{Mode Options}).
21895
21896@kindex maint translate-address
21897@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
21898Find the symbol stored at the location specified by the address
21899@var{addr} and an optional section name @var{section}. If found,
21900@value{GDBN} prints the name of the closest symbol and an offset from
21901the symbol's location to the specified address. This is similar to
21902the @code{info address} command (@pxref{Symbols}), except that this
21903command also allows to find symbols in other sections.
ae038cb0 21904
8e04817f 21905@end table
c906108c 21906
9c16f35a
EZ
21907The following command is useful for non-interactive invocations of
21908@value{GDBN}, such as in the test suite.
21909
21910@table @code
21911@item set watchdog @var{nsec}
21912@kindex set watchdog
21913@cindex watchdog timer
21914@cindex timeout for commands
21915Set the maximum number of seconds @value{GDBN} will wait for the
21916target operation to finish. If this time expires, @value{GDBN}
21917reports and error and the command is aborted.
21918
21919@item show watchdog
21920Show the current setting of the target wait timeout.
21921@end table
c906108c 21922
e0ce93ac 21923@node Remote Protocol
8e04817f 21924@appendix @value{GDBN} Remote Serial Protocol
c906108c 21925
ee2d5c50
AC
21926@menu
21927* Overview::
21928* Packets::
21929* Stop Reply Packets::
21930* General Query Packets::
21931* Register Packet Format::
21932* Examples::
0ce1b118 21933* File-I/O remote protocol extension::
ee2d5c50
AC
21934@end menu
21935
21936@node Overview
21937@section Overview
21938
8e04817f
AC
21939There may be occasions when you need to know something about the
21940protocol---for example, if there is only one serial port to your target
21941machine, you might want your program to do something special if it
21942recognizes a packet meant for @value{GDBN}.
c906108c 21943
d2c6833e 21944In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 21945transmitted and received data respectfully.
c906108c 21946
8e04817f
AC
21947@cindex protocol, @value{GDBN} remote serial
21948@cindex serial protocol, @value{GDBN} remote
21949@cindex remote serial protocol
21950All @value{GDBN} commands and responses (other than acknowledgments) are
21951sent as a @var{packet}. A @var{packet} is introduced with the character
21952@samp{$}, the actual @var{packet-data}, and the terminating character
21953@samp{#} followed by a two-digit @var{checksum}:
c906108c 21954
474c8240 21955@smallexample
8e04817f 21956@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 21957@end smallexample
8e04817f 21958@noindent
c906108c 21959
8e04817f
AC
21960@cindex checksum, for @value{GDBN} remote
21961@noindent
21962The two-digit @var{checksum} is computed as the modulo 256 sum of all
21963characters between the leading @samp{$} and the trailing @samp{#} (an
21964eight bit unsigned checksum).
c906108c 21965
8e04817f
AC
21966Implementors should note that prior to @value{GDBN} 5.0 the protocol
21967specification also included an optional two-digit @var{sequence-id}:
c906108c 21968
474c8240 21969@smallexample
8e04817f 21970@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 21971@end smallexample
c906108c 21972
8e04817f
AC
21973@cindex sequence-id, for @value{GDBN} remote
21974@noindent
21975That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
21976has never output @var{sequence-id}s. Stubs that handle packets added
21977since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 21978
8e04817f
AC
21979@cindex acknowledgment, for @value{GDBN} remote
21980When either the host or the target machine receives a packet, the first
21981response expected is an acknowledgment: either @samp{+} (to indicate
21982the package was received correctly) or @samp{-} (to request
21983retransmission):
c906108c 21984
474c8240 21985@smallexample
d2c6833e
AC
21986-> @code{$}@var{packet-data}@code{#}@var{checksum}
21987<- @code{+}
474c8240 21988@end smallexample
8e04817f 21989@noindent
53a5351d 21990
8e04817f
AC
21991The host (@value{GDBN}) sends @var{command}s, and the target (the
21992debugging stub incorporated in your program) sends a @var{response}. In
21993the case of step and continue @var{command}s, the response is only sent
21994when the operation has completed (the target has again stopped).
c906108c 21995
8e04817f
AC
21996@var{packet-data} consists of a sequence of characters with the
21997exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
21998exceptions).
c906108c 21999
8e04817f 22000Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 22001@cindex remote protocol, field separator
8e04817f 22002@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 22003@sc{hex} with leading zeros suppressed.
c906108c 22004
8e04817f
AC
22005Implementors should note that prior to @value{GDBN} 5.0, the character
22006@samp{:} could not appear as the third character in a packet (as it
22007would potentially conflict with the @var{sequence-id}).
c906108c 22008
8e04817f
AC
22009Response @var{data} can be run-length encoded to save space. A @samp{*}
22010means that the next character is an @sc{ascii} encoding giving a repeat count
22011which stands for that many repetitions of the character preceding the
22012@samp{*}. The encoding is @code{n+29}, yielding a printable character
22013where @code{n >=3} (which is where rle starts to win). The printable
22014characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
22015value greater than 126 should not be used.
c906108c 22016
8e04817f 22017So:
474c8240 22018@smallexample
8e04817f 22019"@code{0* }"
474c8240 22020@end smallexample
8e04817f
AC
22021@noindent
22022means the same as "0000".
c906108c 22023
8e04817f
AC
22024The error response returned for some packets includes a two character
22025error number. That number is not well defined.
c906108c 22026
8e04817f
AC
22027For any @var{command} not supported by the stub, an empty response
22028(@samp{$#00}) should be returned. That way it is possible to extend the
22029protocol. A newer @value{GDBN} can tell if a packet is supported based
22030on that response.
c906108c 22031
b383017d
RM
22032A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
22033@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 22034optional.
c906108c 22035
ee2d5c50
AC
22036@node Packets
22037@section Packets
22038
22039The following table provides a complete list of all currently defined
22040@var{command}s and their corresponding response @var{data}.
9c16f35a
EZ
22041@xref{File-I/O remote protocol extension}, for details about the File
22042I/O extension of the remote protocol.
ee2d5c50
AC
22043
22044@table @r
22045
22046@item @code{!} --- extended mode
22047@cindex @code{!} packet
22048
8e04817f
AC
22049Enable extended mode. In extended mode, the remote server is made
22050persistent. The @samp{R} packet is used to restart the program being
22051debugged.
ee2d5c50
AC
22052
22053Reply:
22054@table @samp
22055@item OK
8e04817f 22056The remote target both supports and has enabled extended mode.
ee2d5c50 22057@end table
c906108c 22058
ee2d5c50
AC
22059@item @code{?} --- last signal
22060@cindex @code{?} packet
c906108c 22061
ee2d5c50
AC
22062Indicate the reason the target halted. The reply is the same as for
22063step and continue.
c906108c 22064
ee2d5c50
AC
22065Reply:
22066@xref{Stop Reply Packets}, for the reply specifications.
22067
22068@item @code{a} --- reserved
22069
22070Reserved for future use.
22071
22072@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
22073@cindex @code{A} packet
c906108c 22074
8e04817f
AC
22075Initialized @samp{argv[]} array passed into program. @var{arglen}
22076specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
22077See @code{gdbserver} for more details.
22078
22079Reply:
22080@table @samp
22081@item OK
22082@item E@var{NN}
22083@end table
22084
22085@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
22086@cindex @code{b} packet
22087
22088Change the serial line speed to @var{baud}.
22089
22090JTC: @emph{When does the transport layer state change? When it's
22091received, or after the ACK is transmitted. In either case, there are
22092problems if the command or the acknowledgment packet is dropped.}
22093
22094Stan: @emph{If people really wanted to add something like this, and get
22095it working for the first time, they ought to modify ser-unix.c to send
22096some kind of out-of-band message to a specially-setup stub and have the
22097switch happen "in between" packets, so that from remote protocol's point
22098of view, nothing actually happened.}
22099
22100@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
22101@cindex @code{B} packet
22102
8e04817f 22103Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
22104breakpoint at @var{addr}.
22105
22106This packet has been replaced by the @samp{Z} and @samp{z} packets
22107(@pxref{insert breakpoint or watchpoint packet}).
c906108c 22108
ee2d5c50
AC
22109@item @code{c}@var{addr} --- continue
22110@cindex @code{c} packet
22111
22112@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 22113current address.
c906108c 22114
ee2d5c50
AC
22115Reply:
22116@xref{Stop Reply Packets}, for the reply specifications.
22117
22118@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
22119@cindex @code{C} packet
22120
8e04817f
AC
22121Continue with signal @var{sig} (hex signal number). If
22122@code{;}@var{addr} is omitted, resume at same address.
c906108c 22123
ee2d5c50
AC
22124Reply:
22125@xref{Stop Reply Packets}, for the reply specifications.
c906108c 22126
ee2d5c50
AC
22127@item @code{d} --- toggle debug @strong{(deprecated)}
22128@cindex @code{d} packet
22129
22130Toggle debug flag.
22131
22132@item @code{D} --- detach
22133@cindex @code{D} packet
22134
22135Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 22136before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
22137
22138Reply:
22139@table @samp
10fac096
NW
22140@item OK
22141for success
22142@item E@var{NN}
22143for an error
ee2d5c50 22144@end table
c906108c 22145
ee2d5c50 22146@item @code{e} --- reserved
c906108c 22147
ee2d5c50 22148Reserved for future use.
c906108c 22149
ee2d5c50 22150@item @code{E} --- reserved
c906108c 22151
ee2d5c50 22152Reserved for future use.
c906108c 22153
ee2d5c50
AC
22154@item @code{f} --- reserved
22155
22156Reserved for future use.
22157
0ce1b118
CV
22158@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
22159@cindex @code{F} packet
ee2d5c50 22160
0ce1b118
CV
22161This packet is send by @value{GDBN} as reply to a @code{F} request packet
22162sent by the target. This is part of the File-I/O protocol extension.
22163@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
22164
22165@item @code{g} --- read registers
22166@anchor{read registers packet}
22167@cindex @code{g} packet
22168
22169Read general registers.
22170
22171Reply:
22172@table @samp
22173@item @var{XX@dots{}}
8e04817f
AC
22174Each byte of register data is described by two hex digits. The bytes
22175with the register are transmitted in target byte order. The size of
22176each register and their position within the @samp{g} @var{packet} are
12c266ea
AC
22177determined by the @value{GDBN} internal macros
22178@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
22179specification of several standard @code{g} packets is specified below.
ee2d5c50
AC
22180@item E@var{NN}
22181for an error.
22182@end table
c906108c 22183
ee2d5c50
AC
22184@item @code{G}@var{XX@dots{}} --- write regs
22185@cindex @code{G} packet
c906108c 22186
ee2d5c50
AC
22187@xref{read registers packet}, for a description of the @var{XX@dots{}}
22188data.
22189
22190Reply:
22191@table @samp
22192@item OK
22193for success
22194@item E@var{NN}
22195for an error
22196@end table
22197
22198@item @code{h} --- reserved
22199
22200Reserved for future use.
22201
b383017d 22202@item @code{H}@var{c}@var{t@dots{}} --- set thread
ee2d5c50 22203@cindex @code{H} packet
c906108c 22204
8e04817f 22205Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
22206@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
22207should be @samp{c} for step and continue operations, @samp{g} for other
22208operations. The thread designator @var{t@dots{}} may be -1, meaning all
22209the threads, a thread number, or zero which means pick any thread.
22210
22211Reply:
22212@table @samp
22213@item OK
22214for success
22215@item E@var{NN}
22216for an error
22217@end table
c906108c 22218
8e04817f
AC
22219@c FIXME: JTC:
22220@c 'H': How restrictive (or permissive) is the thread model. If a
22221@c thread is selected and stopped, are other threads allowed
22222@c to continue to execute? As I mentioned above, I think the
22223@c semantics of each command when a thread is selected must be
22224@c described. For example:
22225@c
22226@c 'g': If the stub supports threads and a specific thread is
22227@c selected, returns the register block from that thread;
22228@c otherwise returns current registers.
22229@c
22230@c 'G' If the stub supports threads and a specific thread is
22231@c selected, sets the registers of the register block of
22232@c that thread; otherwise sets current registers.
c906108c 22233
ee2d5c50
AC
22234@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
22235@anchor{cycle step packet}
22236@cindex @code{i} packet
22237
8e04817f
AC
22238Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
22239present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
22240step starting at that address.
c906108c 22241
ee2d5c50
AC
22242@item @code{I} --- signal then cycle step @strong{(reserved)}
22243@cindex @code{I} packet
22244
22245@xref{step with signal packet}. @xref{cycle step packet}.
22246
22247@item @code{j} --- reserved
22248
22249Reserved for future use.
22250
22251@item @code{J} --- reserved
c906108c 22252
ee2d5c50 22253Reserved for future use.
c906108c 22254
ee2d5c50
AC
22255@item @code{k} --- kill request
22256@cindex @code{k} packet
c906108c 22257
ac282366 22258FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
22259thread context has been selected (i.e.@: does 'k' kill only that
22260thread?)}.
c906108c 22261
ee2d5c50 22262@item @code{K} --- reserved
c906108c 22263
ee2d5c50
AC
22264Reserved for future use.
22265
22266@item @code{l} --- reserved
22267
22268Reserved for future use.
22269
22270@item @code{L} --- reserved
22271
22272Reserved for future use.
22273
22274@item @code{m}@var{addr}@code{,}@var{length} --- read memory
22275@cindex @code{m} packet
c906108c 22276
8e04817f 22277Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 22278Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 22279assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 22280transfer mechanism is needed.}
c906108c 22281
ee2d5c50
AC
22282Reply:
22283@table @samp
22284@item @var{XX@dots{}}
22285@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
22286to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 22287that sized memory transfers are assumed using word aligned
ee2d5c50
AC
22288accesses. FIXME: @emph{A word aligned memory transfer mechanism is
22289needed.}
22290@item E@var{NN}
22291@var{NN} is errno
22292@end table
22293
22294@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
22295@cindex @code{M} packet
22296
8e04817f 22297Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
22298@var{XX@dots{}} is the data.
22299
22300Reply:
22301@table @samp
22302@item OK
22303for success
22304@item E@var{NN}
8e04817f
AC
22305for an error (this includes the case where only part of the data was
22306written).
ee2d5c50 22307@end table
c906108c 22308
ee2d5c50 22309@item @code{n} --- reserved
c906108c 22310
ee2d5c50 22311Reserved for future use.
c906108c 22312
ee2d5c50 22313@item @code{N} --- reserved
c906108c 22314
ee2d5c50 22315Reserved for future use.
c906108c 22316
ee2d5c50
AC
22317@item @code{o} --- reserved
22318
22319Reserved for future use.
22320
22321@item @code{O} --- reserved
22322
2e868123 22323@item @code{p}@var{hex number of register} --- read register packet
ee2d5c50
AC
22324@cindex @code{p} packet
22325
2e868123
AC
22326@xref{read registers packet}, for a description of how the returned
22327register value is encoded.
ee2d5c50
AC
22328
22329Reply:
22330@table @samp
2e868123
AC
22331@item @var{XX@dots{}}
22332the register's value
22333@item E@var{NN}
22334for an error
22335@item
22336Indicating an unrecognized @var{query}.
ee2d5c50
AC
22337@end table
22338
22339@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
22340@anchor{write register packet}
22341@cindex @code{P} packet
22342
22343Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 22344digits for each byte in the register (target byte order).
c906108c 22345
ee2d5c50
AC
22346Reply:
22347@table @samp
22348@item OK
22349for success
22350@item E@var{NN}
22351for an error
22352@end table
22353
22354@item @code{q}@var{query} --- general query
22355@anchor{general query packet}
22356@cindex @code{q} packet
22357
22358Request info about @var{query}. In general @value{GDBN} queries have a
22359leading upper case letter. Custom vendor queries should use a company
22360prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
22361be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
22362that they match the full @var{query} name.
22363
22364Reply:
22365@table @samp
22366@item @var{XX@dots{}}
22367Hex encoded data from query. The reply can not be empty.
22368@item E@var{NN}
22369error reply
8e04817f 22370@item
ee2d5c50
AC
22371Indicating an unrecognized @var{query}.
22372@end table
22373
22374@item @code{Q}@var{var}@code{=}@var{val} --- general set
22375@cindex @code{Q} packet
22376
22377Set value of @var{var} to @var{val}.
22378
22379@xref{general query packet}, for a discussion of naming conventions.
c906108c 22380
ee2d5c50
AC
22381@item @code{r} --- reset @strong{(deprecated)}
22382@cindex @code{r} packet
c906108c 22383
8e04817f 22384Reset the entire system.
c906108c 22385
ee2d5c50
AC
22386@item @code{R}@var{XX} --- remote restart
22387@cindex @code{R} packet
22388
8e04817f
AC
22389Restart the program being debugged. @var{XX}, while needed, is ignored.
22390This packet is only available in extended mode.
ee2d5c50
AC
22391
22392Reply:
22393@table @samp
22394@item @emph{no reply}
8e04817f 22395The @samp{R} packet has no reply.
ee2d5c50
AC
22396@end table
22397
22398@item @code{s}@var{addr} --- step
22399@cindex @code{s} packet
c906108c 22400
8e04817f
AC
22401@var{addr} is address to resume. If @var{addr} is omitted, resume at
22402same address.
c906108c 22403
ee2d5c50
AC
22404Reply:
22405@xref{Stop Reply Packets}, for the reply specifications.
22406
22407@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
22408@anchor{step with signal packet}
22409@cindex @code{S} packet
22410
8e04817f 22411Like @samp{C} but step not continue.
c906108c 22412
ee2d5c50
AC
22413Reply:
22414@xref{Stop Reply Packets}, for the reply specifications.
22415
b383017d 22416@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
ee2d5c50
AC
22417@cindex @code{t} packet
22418
8e04817f 22419Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
22420@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
22421@var{addr} must be at least 3 digits.
c906108c 22422
ee2d5c50
AC
22423@item @code{T}@var{XX} --- thread alive
22424@cindex @code{T} packet
c906108c 22425
ee2d5c50 22426Find out if the thread XX is alive.
c906108c 22427
ee2d5c50
AC
22428Reply:
22429@table @samp
22430@item OK
22431thread is still alive
22432@item E@var{NN}
22433thread is dead
22434@end table
22435
22436@item @code{u} --- reserved
22437
22438Reserved for future use.
22439
22440@item @code{U} --- reserved
22441
22442Reserved for future use.
22443
86d30acc 22444@item @code{v} --- verbose packet prefix
ee2d5c50 22445
86d30acc
DJ
22446Packets starting with @code{v} are identified by a multi-letter name,
22447up to the first @code{;} or @code{?} (or the end of the packet).
22448
22449@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
22450@cindex @code{vCont} packet
22451
22452Resume the inferior. Different actions may be specified for each thread.
22453If an action is specified with no @var{tid}, then it is applied to any
22454threads that don't have a specific action specified; if no default action is
22455specified then other threads should remain stopped. Specifying multiple
22456default actions is an error; specifying no actions is also an error.
22457Thread IDs are specified in hexadecimal. Currently supported actions are:
22458
22459@table @code
22460@item c
22461Continue.
22462@item C@var{sig}
22463Continue with signal @var{sig}. @var{sig} should be two hex digits.
22464@item s
22465Step.
22466@item S@var{sig}
22467Step with signal @var{sig}. @var{sig} should be two hex digits.
22468@end table
22469
22470The optional @var{addr} argument normally associated with these packets is
22471not supported in @code{vCont}.
22472
22473Reply:
22474@xref{Stop Reply Packets}, for the reply specifications.
22475
22476@item @code{vCont?} --- extended resume query
22477@cindex @code{vCont?} packet
22478
22479Query support for the @code{vCont} packet.
22480
22481Reply:
22482@table @samp
22483@item @code{vCont}[;@var{action}]...
22484The @code{vCont} packet is supported. Each @var{action} is a supported
22485command in the @code{vCont} packet.
22486@item
22487The @code{vCont} packet is not supported.
22488@end table
ee2d5c50
AC
22489
22490@item @code{V} --- reserved
c906108c 22491
ee2d5c50 22492Reserved for future use.
c906108c 22493
ee2d5c50 22494@item @code{w} --- reserved
c906108c 22495
ee2d5c50 22496Reserved for future use.
c906108c 22497
ee2d5c50 22498@item @code{W} --- reserved
c906108c 22499
ee2d5c50 22500Reserved for future use.
c906108c 22501
ee2d5c50
AC
22502@item @code{x} --- reserved
22503
22504Reserved for future use.
22505
22506@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
22507@cindex @code{X} packet
22508
22509@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
22510is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
69065f5d
AC
22511escaped using @code{0x7d}, and then XORed with @code{0x20}.
22512For example, @code{0x7d} would be transmitted as @code{0x7d 0x5d}.
c906108c 22513
ee2d5c50
AC
22514Reply:
22515@table @samp
22516@item OK
22517for success
22518@item E@var{NN}
22519for an error
22520@end table
22521
22522@item @code{y} --- reserved
c906108c 22523
ee2d5c50 22524Reserved for future use.
c906108c 22525
ee2d5c50
AC
22526@item @code{Y} reserved
22527
22528Reserved for future use.
22529
2f870471
AC
22530@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
22531@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
22532@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 22533@cindex @code{z} packet
2f870471 22534@cindex @code{Z} packets
ee2d5c50 22535
2f870471
AC
22536Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
22537watchpoint starting at address @var{address} and covering the next
22538@var{length} bytes.
ee2d5c50 22539
2f870471
AC
22540Each breakpoint and watchpoint packet @var{type} is documented
22541separately.
22542
512217c7
AC
22543@emph{Implementation notes: A remote target shall return an empty string
22544for an unrecognized breakpoint or watchpoint packet @var{type}. A
22545remote target shall support either both or neither of a given
2f870471
AC
22546@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
22547avoid potential problems with duplicate packets, the operations should
22548be implemented in an idempotent way.}
22549
22550@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
22551@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
22552@cindex @code{z0} packet
22553@cindex @code{Z0} packet
22554
22555Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
22556@code{addr} of size @code{length}.
22557
22558A memory breakpoint is implemented by replacing the instruction at
22559@var{addr} with a software breakpoint or trap instruction. The
22560@code{length} is used by targets that indicates the size of the
22561breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
22562@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 22563
2f870471
AC
22564@emph{Implementation note: It is possible for a target to copy or move
22565code that contains memory breakpoints (e.g., when implementing
22566overlays). The behavior of this packet, in the presence of such a
22567target, is not defined.}
c906108c 22568
ee2d5c50
AC
22569Reply:
22570@table @samp
2f870471
AC
22571@item OK
22572success
22573@item
22574not supported
ee2d5c50
AC
22575@item E@var{NN}
22576for an error
2f870471
AC
22577@end table
22578
22579@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
22580@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
22581@cindex @code{z1} packet
22582@cindex @code{Z1} packet
22583
22584Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
22585address @code{addr} of size @code{length}.
22586
22587A hardware breakpoint is implemented using a mechanism that is not
22588dependant on being able to modify the target's memory.
22589
22590@emph{Implementation note: A hardware breakpoint is not affected by code
22591movement.}
22592
22593Reply:
22594@table @samp
ee2d5c50 22595@item OK
2f870471
AC
22596success
22597@item
22598not supported
22599@item E@var{NN}
22600for an error
22601@end table
22602
22603@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
22604@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
22605@cindex @code{z2} packet
22606@cindex @code{Z2} packet
22607
22608Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
22609
22610Reply:
22611@table @samp
22612@item OK
22613success
22614@item
22615not supported
22616@item E@var{NN}
22617for an error
22618@end table
22619
22620@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
22621@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
22622@cindex @code{z3} packet
22623@cindex @code{Z3} packet
22624
2e834e49 22625Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
22626
22627Reply:
22628@table @samp
22629@item OK
22630success
22631@item
22632not supported
22633@item E@var{NN}
22634for an error
22635@end table
22636
2e834e49
HPN
22637@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
22638@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
22639@cindex @code{z4} packet
22640@cindex @code{Z4} packet
22641
22642Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
22643
22644Reply:
22645@table @samp
22646@item OK
22647success
22648@item
22649not supported
22650@item E@var{NN}
22651for an error
ee2d5c50
AC
22652@end table
22653
22654@end table
c906108c 22655
ee2d5c50
AC
22656@node Stop Reply Packets
22657@section Stop Reply Packets
22658@cindex stop reply packets
c906108c 22659
8e04817f
AC
22660The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
22661receive any of the below as a reply. In the case of the @samp{C},
22662@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
22663when the target halts. In the below the exact meaning of @samp{signal
22664number} is poorly defined. In general one of the UNIX signal numbering
22665conventions is used.
c906108c 22666
ee2d5c50 22667@table @samp
c906108c 22668
ee2d5c50
AC
22669@item S@var{AA}
22670@var{AA} is the signal number
c906108c 22671
8e04817f 22672@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
22673@cindex @code{T} packet reply
22674
8e04817f
AC
22675@var{AA} = two hex digit signal number; @var{n...} = register number
22676(hex), @var{r...} = target byte ordered register contents, size defined
12c266ea
AC
22677by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
22678@var{r...} = thread process ID, this is a hex integer; @var{n...} =
22679(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
22680address, this is a hex integer; @var{n...} = other string not starting
22681with valid hex digit. @value{GDBN} should ignore this @var{n...},
22682@var{r...} pair and go on to the next. This way we can extend the
22683protocol.
c906108c 22684
ee2d5c50
AC
22685@item W@var{AA}
22686
8e04817f 22687The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
22688applicable to certain targets.
22689
22690@item X@var{AA}
c906108c 22691
8e04817f 22692The process terminated with signal @var{AA}.
c906108c 22693
ee2d5c50 22694@item O@var{XX@dots{}}
c906108c 22695
ee2d5c50
AC
22696@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
22697any time while the program is running and the debugger should continue
22698to wait for @samp{W}, @samp{T}, etc.
22699
0ce1b118
CV
22700@item F@var{call-id}@code{,}@var{parameter@dots{}}
22701
22702@var{call-id} is the identifier which says which host system call should
22703be called. This is just the name of the function. Translation into the
22704correct system call is only applicable as it's defined in @value{GDBN}.
22705@xref{File-I/O remote protocol extension}, for a list of implemented
22706system calls.
22707
22708@var{parameter@dots{}} is a list of parameters as defined for this very
22709system call.
22710
22711The target replies with this packet when it expects @value{GDBN} to call
22712a host system call on behalf of the target. @value{GDBN} replies with
22713an appropriate @code{F} packet and keeps up waiting for the next reply
22714packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
22715@samp{s} action is expected to be continued.
22716@xref{File-I/O remote protocol extension}, for more details.
22717
ee2d5c50
AC
22718@end table
22719
22720@node General Query Packets
22721@section General Query Packets
9c16f35a 22722@cindex remote query requests
c906108c 22723
8e04817f 22724The following set and query packets have already been defined.
c906108c 22725
ee2d5c50 22726@table @r
c906108c 22727
ee2d5c50 22728@item @code{q}@code{C} --- current thread
9c16f35a
EZ
22729@cindex current thread, remote request
22730@cindex @code{qC} packet
ee2d5c50
AC
22731Return the current thread id.
22732
22733Reply:
22734@table @samp
22735@item @code{QC}@var{pid}
e1aac25b 22736Where @var{pid} is an unsigned hexidecimal process id.
ee2d5c50
AC
22737@item *
22738Any other reply implies the old pid.
22739@end table
22740
22741@item @code{q}@code{fThreadInfo} -- all thread ids
9c16f35a
EZ
22742@cindex list active threads, remote request
22743@cindex @code{qfThreadInfo} packet
ee2d5c50 22744@code{q}@code{sThreadInfo}
c906108c 22745
8e04817f
AC
22746Obtain a list of active thread ids from the target (OS). Since there
22747may be too many active threads to fit into one reply packet, this query
22748works iteratively: it may require more than one query/reply sequence to
22749obtain the entire list of threads. The first query of the sequence will
22750be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
22751sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
22752
22753NOTE: replaces the @code{qL} query (see below).
22754
22755Reply:
22756@table @samp
22757@item @code{m}@var{id}
22758A single thread id
22759@item @code{m}@var{id},@var{id}@dots{}
22760a comma-separated list of thread ids
22761@item @code{l}
22762(lower case 'el') denotes end of list.
22763@end table
22764
22765In response to each query, the target will reply with a list of one or
e1aac25b
JB
22766more thread ids, in big-endian unsigned hex, separated by commas.
22767@value{GDBN} will respond to each reply with a request for more thread
22768ids (using the @code{qs} form of the query), until the target responds
22769with @code{l} (lower-case el, for @code{'last'}).
c906108c 22770
ee2d5c50 22771@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
9c16f35a
EZ
22772@cindex thread attributes info, remote request
22773@cindex @code{qThreadExtraInfo} packet
ee2d5c50
AC
22774Where @var{id} is a thread-id in big-endian hex. Obtain a printable
22775string description of a thread's attributes from the target OS. This
22776string may contain anything that the target OS thinks is interesting for
22777@value{GDBN} to tell the user about the thread. The string is displayed
22778in @value{GDBN}'s @samp{info threads} display. Some examples of
22779possible thread extra info strings are ``Runnable'', or ``Blocked on
22780Mutex''.
22781
22782Reply:
22783@table @samp
22784@item @var{XX@dots{}}
22785Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
22786the printable string containing the extra information about the thread's
8e04817f 22787attributes.
ee2d5c50
AC
22788@end table
22789
22790@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 22791
8e04817f
AC
22792Obtain thread information from RTOS. Where: @var{startflag} (one hex
22793digit) is one to indicate the first query and zero to indicate a
22794subsequent query; @var{threadcount} (two hex digits) is the maximum
22795number of threads the response packet can contain; and @var{nextthread}
22796(eight hex digits), for subsequent queries (@var{startflag} is zero), is
22797returned in the response as @var{argthread}.
ee2d5c50
AC
22798
22799NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
22800(see above).
22801
22802Reply:
22803@table @samp
22804@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
22805Where: @var{count} (two hex digits) is the number of threads being
22806returned; @var{done} (one hex digit) is zero to indicate more threads
22807and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
22808digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
22809is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 22810digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 22811@end table
c906108c 22812
ee2d5c50 22813@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
9c16f35a
EZ
22814@cindex CRC of memory block, remote request
22815@cindex @code{qCRC} packet
ee2d5c50
AC
22816Reply:
22817@table @samp
22818@item @code{E}@var{NN}
22819An error (such as memory fault)
22820@item @code{C}@var{CRC32}
22821A 32 bit cyclic redundancy check of the specified memory region.
22822@end table
22823
22824@item @code{q}@code{Offsets} --- query sect offs
9c16f35a
EZ
22825@cindex section offsets, remote request
22826@cindex @code{qOffsets} packet
8e04817f
AC
22827Get section offsets that the target used when re-locating the downloaded
22828image. @emph{Note: while a @code{Bss} offset is included in the
22829response, @value{GDBN} ignores this and instead applies the @code{Data}
22830offset to the @code{Bss} section.}
c906108c 22831
ee2d5c50
AC
22832Reply:
22833@table @samp
22834@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
22835@end table
22836
22837@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
9c16f35a
EZ
22838@cindex thread information, remote request
22839@cindex @code{qP} packet
8e04817f
AC
22840Returns information on @var{threadid}. Where: @var{mode} is a hex
22841encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
22842
22843Reply:
22844@table @samp
22845@item *
22846@end table
22847
8e04817f 22848See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 22849
ee2d5c50 22850@item @code{q}@code{Rcmd,}@var{command} --- remote command
9c16f35a
EZ
22851@cindex execute remote command, remote request
22852@cindex @code{qRcmd} packet
ee2d5c50 22853@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
22854execution. Invalid commands should be reported using the output string.
22855Before the final result packet, the target may also respond with a
ee2d5c50
AC
22856number of intermediate @code{O}@var{output} console output packets.
22857@emph{Implementors should note that providing access to a stubs's
22858interpreter may have security implications}.
22859
22860Reply:
22861@table @samp
22862@item OK
8e04817f 22863A command response with no output.
ee2d5c50 22864@item @var{OUTPUT}
8e04817f 22865A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 22866@item @code{E}@var{NN}
8e04817f 22867Indicate a badly formed request.
ee2d5c50 22868@item @samp{}
8e04817f 22869When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50 22870@end table
9c16f35a 22871z
ee2d5c50 22872@item @code{qSymbol::} --- symbol lookup
9c16f35a
EZ
22873@cindex symbol lookup, remote request
22874@cindex @code{qSymbol} packet
8e04817f
AC
22875Notify the target that @value{GDBN} is prepared to serve symbol lookup
22876requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
22877
22878Reply:
22879@table @samp
22880@item @code{OK}
8e04817f 22881The target does not need to look up any (more) symbols.
ee2d5c50
AC
22882@item @code{qSymbol:}@var{sym_name}
22883The target requests the value of symbol @var{sym_name} (hex encoded).
22884@value{GDBN} may provide the value by using the
22885@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
22886@end table
22887
22888@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
22889
22890Set the value of @var{sym_name} to @var{sym_value}.
22891
22892@var{sym_name} (hex encoded) is the name of a symbol whose value the
22893target has previously requested.
22894
22895@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
22896@value{GDBN} cannot supply a value for @var{sym_name}, then this field
22897will be empty.
22898
22899Reply:
22900@table @samp
22901@item @code{OK}
8e04817f 22902The target does not need to look up any (more) symbols.
ee2d5c50
AC
22903@item @code{qSymbol:}@var{sym_name}
22904The target requests the value of a new symbol @var{sym_name} (hex
22905encoded). @value{GDBN} will continue to supply the values of symbols
22906(if available), until the target ceases to request them.
22907@end table
eb12ee30 22908
649e03f6 22909@item @code{qPart}:@var{object}:@code{read}:@var{annex}:@var{offset},@var{length} --- read special data
9c16f35a
EZ
22910@cindex read special object, remote request
22911@cindex @code{qPart} packet
649e03f6
RM
22912Read uninterpreted bytes from the target's special data area
22913identified by the keyword @code{object}.
22914Request @var{length} bytes starting at @var{offset} bytes into the data.
22915The content and encoding of @var{annex} is specific to the object;
22916it can supply additional details about what data to access.
22917
22918Here are the specific requests of this form defined so far.
22919All @samp{@code{qPart}:@var{object}:@code{read}:@dots{}}
22920requests use the same reply formats, listed below.
22921
22922@table @asis
22923@item @code{qPart}:@code{auxv}:@code{read}::@var{offset},@var{length}
721c2651
EZ
22924Access the target's @dfn{auxiliary vector}. @xref{OS Information,
22925auxiliary vector}, and see @ref{Remote configuration,
22926read-aux-vector-packet}. Note @var{annex} must be empty.
649e03f6
RM
22927@end table
22928
22929Reply:
22930@table @asis
22931@item @code{OK}
22932The @var{offset} in the request is at the end of the data.
22933There is no more data to be read.
22934
22935@item @var{XX@dots{}}
22936Hex encoded data bytes read.
22937This may be fewer bytes than the @var{length} in the request.
22938
22939@item @code{E00}
22940The request was malformed, or @var{annex} was invalid.
22941
22942@item @code{E}@var{nn}
22943The offset was invalid, or there was an error encountered reading the data.
22944@var{nn} is a hex-encoded @code{errno} value.
22945
22946@item @code{""} (empty)
22947An empty reply indicates the @var{object} or @var{annex} string was not
22948recognized by the stub.
22949@end table
22950
22951@item @code{qPart}:@var{object}:@code{write}:@var{annex}:@var{offset}:@var{data@dots{}}
9c16f35a 22952@cindex write data into object, remote request
649e03f6
RM
22953Write uninterpreted bytes into the target's special data area
22954identified by the keyword @code{object},
22955starting at @var{offset} bytes into the data.
22956@var{data@dots{}} is the hex-encoded data to be written.
22957The content and encoding of @var{annex} is specific to the object;
22958it can supply additional details about what data to access.
22959
22960No requests of this form are presently in use. This specification
22961serves as a placeholder to document the common format that new
22962specific request specifications ought to use.
22963
22964Reply:
22965@table @asis
22966@item @var{nn}
22967@var{nn} (hex encoded) is the number of bytes written.
22968This may be fewer bytes than supplied in the request.
22969
22970@item @code{E00}
22971The request was malformed, or @var{annex} was invalid.
22972
22973@item @code{E}@var{nn}
22974The offset was invalid, or there was an error encountered writing the data.
22975@var{nn} is a hex-encoded @code{errno} value.
22976
22977@item @code{""} (empty)
22978An empty reply indicates the @var{object} or @var{annex} string was not
22979recognized by the stub, or that the object does not support writing.
22980@end table
22981
22982@item @code{qPart}:@var{object}:@var{operation}:@dots{}
22983Requests of this form may be added in the future. When a stub does
22984not recognize the @var{object} keyword, or its support for
22985@var{object} does not recognize the @var{operation} keyword,
22986the stub must respond with an empty packet.
83761cbd
KB
22987
22988@item @code{qGetTLSAddr}:@var{thread-id},@var{offset},@var{lm} --- get thread local storage address
9c16f35a
EZ
22989@cindex get thread-local storage address, remote request
22990@cindex @code{qGetTLSAddr} packet
83761cbd
KB
22991Fetch the address associated with thread local storage specified
22992by @var{thread-id}, @var{offset}, and @var{lm}.
22993
22994@var{thread-id} is the (big endian, hex encoded) thread id associated with the
22995thread for which to fetch the TLS address.
22996
22997@var{offset} is the (big endian, hex encoded) offset associated with the
22998thread local variable. (This offset is obtained from the debug
22999information associated with the variable.)
23000
23001@var{lm} is the (big endian, hex encoded) OS/ABI specific encoding of the
23002the load module associated with the thread local storage. For example,
23003a @sc{gnu}/Linux system will pass the link map address of the shared
23004object associated with the thread local storage under consideration.
23005Other operating environments may choose to represent the load module
23006differently, so the precise meaning of this parameter will vary.
23007
23008Reply:
23009@table @asis
68c71a2e 23010@item @var{XX@dots{}}
83761cbd
KB
23011Hex encoded (big endian) bytes representing the address of the thread
23012local storage requested.
23013
23014@item @code{E}@var{nn} (where @var{nn} are hex digits)
23015An error occurred.
23016
23017@item @code{""} (empty)
23018An empty reply indicates that @code{qGetTLSAddr} is not supported by the stub.
23019@end table
23020
0abb7bc7
EZ
23021Use of this request packet is controlled by the @code{set remote
23022get-thread-local-storage-address} command (@pxref{Remote
23023configuration, set remote get-thread-local-storage-address}).
23024
ee2d5c50
AC
23025@end table
23026
23027@node Register Packet Format
23028@section Register Packet Format
eb12ee30 23029
8e04817f 23030The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
23031In the below, some thirty-two bit registers are transferred as
23032sixty-four bits. Those registers should be zero/sign extended (which?)
23033to fill the space allocated. Register bytes are transfered in target
23034byte order. The two nibbles within a register byte are transfered
23035most-significant - least-significant.
eb12ee30 23036
ee2d5c50 23037@table @r
eb12ee30 23038
8e04817f 23039@item MIPS32
ee2d5c50 23040
8e04817f
AC
23041All registers are transfered as thirty-two bit quantities in the order:
2304232 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
23043registers; fsr; fir; fp.
eb12ee30 23044
8e04817f 23045@item MIPS64
ee2d5c50 23046
8e04817f
AC
23047All registers are transfered as sixty-four bit quantities (including
23048thirty-two bit registers such as @code{sr}). The ordering is the same
23049as @code{MIPS32}.
eb12ee30 23050
ee2d5c50
AC
23051@end table
23052
23053@node Examples
23054@section Examples
eb12ee30 23055
8e04817f
AC
23056Example sequence of a target being re-started. Notice how the restart
23057does not get any direct output:
eb12ee30 23058
474c8240 23059@smallexample
d2c6833e
AC
23060-> @code{R00}
23061<- @code{+}
8e04817f 23062@emph{target restarts}
d2c6833e 23063-> @code{?}
8e04817f 23064<- @code{+}
d2c6833e
AC
23065<- @code{T001:1234123412341234}
23066-> @code{+}
474c8240 23067@end smallexample
eb12ee30 23068
8e04817f 23069Example sequence of a target being stepped by a single instruction:
eb12ee30 23070
474c8240 23071@smallexample
d2c6833e 23072-> @code{G1445@dots{}}
8e04817f 23073<- @code{+}
d2c6833e
AC
23074-> @code{s}
23075<- @code{+}
23076@emph{time passes}
23077<- @code{T001:1234123412341234}
8e04817f 23078-> @code{+}
d2c6833e 23079-> @code{g}
8e04817f 23080<- @code{+}
d2c6833e
AC
23081<- @code{1455@dots{}}
23082-> @code{+}
474c8240 23083@end smallexample
eb12ee30 23084
0ce1b118
CV
23085@node File-I/O remote protocol extension
23086@section File-I/O remote protocol extension
23087@cindex File-I/O remote protocol extension
23088
23089@menu
23090* File-I/O Overview::
23091* Protocol basics::
1d8b2f28
JB
23092* The F request packet::
23093* The F reply packet::
0ce1b118
CV
23094* Memory transfer::
23095* The Ctrl-C message::
23096* Console I/O::
23097* The isatty call::
23098* The system call::
23099* List of supported calls::
23100* Protocol specific representation of datatypes::
23101* Constants::
23102* File-I/O Examples::
23103@end menu
23104
23105@node File-I/O Overview
23106@subsection File-I/O Overview
23107@cindex file-i/o overview
23108
9c16f35a
EZ
23109The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
23110target to use the host's file system and console I/O when calling various
0ce1b118
CV
23111system calls. System calls on the target system are translated into a
23112remote protocol packet to the host system which then performs the needed
23113actions and returns with an adequate response packet to the target system.
23114This simulates file system operations even on targets that lack file systems.
23115
23116The protocol is defined host- and target-system independent. It uses
9c16f35a 23117its own independent representation of datatypes and values. Both,
0ce1b118
CV
23118@value{GDBN} and the target's @value{GDBN} stub are responsible for
23119translating the system dependent values into the unified protocol values
23120when data is transmitted.
23121
23122The communication is synchronous. A system call is possible only
23123when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
23124packets. While @value{GDBN} handles the request for a system call,
23125the target is stopped to allow deterministic access to the target's
23126memory. Therefore File-I/O is not interuptible by target signals. It
23127is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
23128
23129The target's request to perform a host system call does not finish
23130the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
23131after finishing the system call, the target returns to continuing the
23132previous activity (continue, step). No additional continue or step
23133request from @value{GDBN} is required.
23134
23135@smallexample
f7dc1244 23136(@value{GDBP}) continue
0ce1b118
CV
23137 <- target requests 'system call X'
23138 target is stopped, @value{GDBN} executes system call
23139 -> GDB returns result
23140 ... target continues, GDB returns to wait for the target
23141 <- target hits breakpoint and sends a Txx packet
23142@end smallexample
23143
23144The protocol is only used for files on the host file system and
23145for I/O on the console. Character or block special devices, pipes,
23146named pipes or sockets or any other communication method on the host
23147system are not supported by this protocol.
23148
23149@node Protocol basics
23150@subsection Protocol basics
23151@cindex protocol basics, file-i/o
23152
23153The File-I/O protocol uses the @code{F} packet, as request as well
23154as as reply packet. Since a File-I/O system call can only occur when
b383017d 23155@value{GDBN} is waiting for the continuing or stepping target, the
0ce1b118
CV
23156File-I/O request is a reply that @value{GDBN} has to expect as a result
23157of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
23158This @code{F} packet contains all information needed to allow @value{GDBN}
23159to call the appropriate host system call:
23160
23161@itemize @bullet
b383017d 23162@item
0ce1b118
CV
23163A unique identifier for the requested system call.
23164
23165@item
23166All parameters to the system call. Pointers are given as addresses
23167in the target memory address space. Pointers to strings are given as
b383017d 23168pointer/length pair. Numerical values are given as they are.
0ce1b118
CV
23169Numerical control values are given in a protocol specific representation.
23170
23171@end itemize
23172
23173At that point @value{GDBN} has to perform the following actions.
23174
23175@itemize @bullet
b383017d 23176@item
0ce1b118
CV
23177If parameter pointer values are given, which point to data needed as input
23178to a system call, @value{GDBN} requests this data from the target with a
23179standard @code{m} packet request. This additional communication has to be
23180expected by the target implementation and is handled as any other @code{m}
23181packet.
23182
23183@item
23184@value{GDBN} translates all value from protocol representation to host
23185representation as needed. Datatypes are coerced into the host types.
23186
23187@item
23188@value{GDBN} calls the system call
23189
23190@item
23191It then coerces datatypes back to protocol representation.
23192
23193@item
23194If pointer parameters in the request packet point to buffer space in which
23195a system call is expected to copy data to, the data is transmitted to the
23196target using a @code{M} or @code{X} packet. This packet has to be expected
23197by the target implementation and is handled as any other @code{M} or @code{X}
23198packet.
23199
23200@end itemize
23201
23202Eventually @value{GDBN} replies with another @code{F} packet which contains all
23203necessary information for the target to continue. This at least contains
23204
23205@itemize @bullet
23206@item
23207Return value.
23208
23209@item
23210@code{errno}, if has been changed by the system call.
23211
23212@item
23213``Ctrl-C'' flag.
23214
23215@end itemize
23216
23217After having done the needed type and value coercion, the target continues
23218the latest continue or step action.
23219
1d8b2f28 23220@node The F request packet
0ce1b118
CV
23221@subsection The @code{F} request packet
23222@cindex file-i/o request packet
23223@cindex @code{F} request packet
23224
23225The @code{F} request packet has the following format:
23226
23227@table @samp
23228
23229@smallexample
23230@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
23231@end smallexample
23232
23233@var{call-id} is the identifier to indicate the host system call to be called.
23234This is just the name of the function.
23235
23236@var{parameter@dots{}} are the parameters to the system call.
23237
b383017d 23238@end table
0ce1b118
CV
23239
23240Parameters are hexadecimal integer values, either the real values in case
23241of scalar datatypes, as pointers to target buffer space in case of compound
23242datatypes and unspecified memory areas or as pointer/length pairs in case
23243of string parameters. These are appended to the call-id, each separated
23244from its predecessor by a comma. All values are transmitted in ASCII
23245string representation, pointer/length pairs separated by a slash.
23246
1d8b2f28 23247@node The F reply packet
0ce1b118
CV
23248@subsection The @code{F} reply packet
23249@cindex file-i/o reply packet
23250@cindex @code{F} reply packet
23251
23252The @code{F} reply packet has the following format:
23253
23254@table @samp
23255
23256@smallexample
23257@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
23258@end smallexample
23259
23260@var{retcode} is the return code of the system call as hexadecimal value.
23261
23262@var{errno} is the errno set by the call, in protocol specific representation.
23263This parameter can be omitted if the call was successful.
23264
23265@var{Ctrl-C flag} is only send if the user requested a break. In this
23266case, @var{errno} must be send as well, even if the call was successful.
23267The @var{Ctrl-C flag} itself consists of the character 'C':
23268
23269@smallexample
23270F0,0,C
23271@end smallexample
23272
23273@noindent
23274or, if the call was interupted before the host call has been performed:
23275
23276@smallexample
23277F-1,4,C
23278@end smallexample
23279
23280@noindent
23281assuming 4 is the protocol specific representation of @code{EINTR}.
23282
23283@end table
23284
23285@node Memory transfer
23286@subsection Memory transfer
23287@cindex memory transfer, in file-i/o protocol
23288
23289Structured data which is transferred using a memory read or write as e.g.@:
23290a @code{struct stat} is expected to be in a protocol specific format with
23291all scalar multibyte datatypes being big endian. This should be done by
23292the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
23293it transfers memory to the target. Transferred pointers to structured
23294data should point to the already coerced data at any time.
23295
23296@node The Ctrl-C message
23297@subsection The Ctrl-C message
23298@cindex ctrl-c message, in file-i/o protocol
23299
23300A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
23301reply packet. In this case the target should behave, as if it had
23302gotten a break message. The meaning for the target is ``system call
23303interupted by @code{SIGINT}''. Consequentially, the target should actually stop
23304(as with a break message) and return to @value{GDBN} with a @code{T02}
b383017d 23305packet. In this case, it's important for the target to know, in which
0ce1b118
CV
23306state the system call was interrupted. Since this action is by design
23307not an atomic operation, we have to differ between two cases:
23308
23309@itemize @bullet
23310@item
23311The system call hasn't been performed on the host yet.
23312
23313@item
23314The system call on the host has been finished.
23315
23316@end itemize
23317
23318These two states can be distinguished by the target by the value of the
23319returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
23320call hasn't been performed. This is equivalent to the @code{EINTR} handling
23321on POSIX systems. In any other case, the target may presume that the
23322system call has been finished --- successful or not --- and should behave
23323as if the break message arrived right after the system call.
23324
23325@value{GDBN} must behave reliable. If the system call has not been called
23326yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
23327@code{errno} in the packet. If the system call on the host has been finished
23328before the user requests a break, the full action must be finshed by
23329@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
23330The @code{F} packet may only be send when either nothing has happened
23331or the full action has been completed.
23332
23333@node Console I/O
23334@subsection Console I/O
23335@cindex console i/o as part of file-i/o
23336
23337By default and if not explicitely closed by the target system, the file
23338descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
23339on the @value{GDBN} console is handled as any other file output operation
23340(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
23341by @value{GDBN} so that after the target read request from file descriptor
233420 all following typing is buffered until either one of the following
23343conditions is met:
23344
23345@itemize @bullet
23346@item
23347The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
23348@code{read}
23349system call is treated as finished.
23350
23351@item
23352The user presses @kbd{Enter}. This is treated as end of input with a trailing
23353line feed.
23354
23355@item
23356The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
23357character, especially no Ctrl-D is appended to the input.
23358
23359@end itemize
23360
23361If the user has typed more characters as fit in the buffer given to
23362the read call, the trailing characters are buffered in @value{GDBN} until
23363either another @code{read(0, @dots{})} is requested by the target or debugging
23364is stopped on users request.
23365
23366@node The isatty call
2eecc4ab 23367@subsection The @samp{isatty} function call
0ce1b118
CV
23368@cindex isatty call, file-i/o protocol
23369
23370A special case in this protocol is the library call @code{isatty} which
9c16f35a 23371is implemented as its own call inside of this protocol. It returns
0ce1b118
CV
233721 to the target if the file descriptor given as parameter is attached
23373to the @value{GDBN} console, 0 otherwise. Implementing through system calls
23374would require implementing @code{ioctl} and would be more complex than
23375needed.
23376
23377@node The system call
2eecc4ab 23378@subsection The @samp{system} function call
0ce1b118
CV
23379@cindex system call, file-i/o protocol
23380
23381The other special case in this protocol is the @code{system} call which
9c16f35a 23382is implemented as its own call, too. @value{GDBN} is taking over the full
0ce1b118
CV
23383task of calling the necessary host calls to perform the @code{system}
23384call. The return value of @code{system} is simplified before it's returned
23385to the target. Basically, the only signal transmitted back is @code{EINTR}
23386in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
23387entirely of the exit status of the called command.
23388
9c16f35a
EZ
23389Due to security concerns, the @code{system} call is by default refused
23390by @value{GDBN}. The user has to allow this call explicitly with the
23391@kbd{set remote system-call-allowed 1} command.
0ce1b118 23392
9c16f35a
EZ
23393@table @code
23394@item set remote system-call-allowed
23395@kindex set remote system-call-allowed
23396Control whether to allow the @code{system} calls in the File I/O
23397protocol for the remote target. The default is zero (disabled).
0ce1b118 23398
9c16f35a 23399@item show remote system-call-allowed
0ce1b118 23400@kindex show remote system-call-allowed
9c16f35a
EZ
23401Show the current setting of system calls for the remote File I/O
23402protocol.
0ce1b118
CV
23403@end table
23404
23405@node List of supported calls
23406@subsection List of supported calls
23407@cindex list of supported file-i/o calls
23408
23409@menu
23410* open::
23411* close::
23412* read::
23413* write::
23414* lseek::
23415* rename::
23416* unlink::
23417* stat/fstat::
23418* gettimeofday::
23419* isatty::
23420* system::
23421@end menu
23422
23423@node open
23424@unnumberedsubsubsec open
23425@cindex open, file-i/o system call
23426
23427@smallexample
23428@exdent Synopsis:
23429int open(const char *pathname, int flags);
23430int open(const char *pathname, int flags, mode_t mode);
23431
b383017d 23432@exdent Request:
0ce1b118
CV
23433Fopen,pathptr/len,flags,mode
23434@end smallexample
23435
23436@noindent
23437@code{flags} is the bitwise or of the following values:
23438
23439@table @code
b383017d 23440@item O_CREAT
0ce1b118
CV
23441If the file does not exist it will be created. The host
23442rules apply as far as file ownership and time stamps
23443are concerned.
23444
b383017d 23445@item O_EXCL
0ce1b118
CV
23446When used with O_CREAT, if the file already exists it is
23447an error and open() fails.
23448
b383017d 23449@item O_TRUNC
0ce1b118
CV
23450If the file already exists and the open mode allows
23451writing (O_RDWR or O_WRONLY is given) it will be
23452truncated to length 0.
23453
b383017d 23454@item O_APPEND
0ce1b118
CV
23455The file is opened in append mode.
23456
b383017d 23457@item O_RDONLY
0ce1b118
CV
23458The file is opened for reading only.
23459
b383017d 23460@item O_WRONLY
0ce1b118
CV
23461The file is opened for writing only.
23462
b383017d 23463@item O_RDWR
0ce1b118
CV
23464The file is opened for reading and writing.
23465
23466@noindent
23467Each other bit is silently ignored.
23468
23469@end table
23470
23471@noindent
23472@code{mode} is the bitwise or of the following values:
23473
23474@table @code
b383017d 23475@item S_IRUSR
0ce1b118
CV
23476User has read permission.
23477
b383017d 23478@item S_IWUSR
0ce1b118
CV
23479User has write permission.
23480
b383017d 23481@item S_IRGRP
0ce1b118
CV
23482Group has read permission.
23483
b383017d 23484@item S_IWGRP
0ce1b118
CV
23485Group has write permission.
23486
b383017d 23487@item S_IROTH
0ce1b118
CV
23488Others have read permission.
23489
b383017d 23490@item S_IWOTH
0ce1b118
CV
23491Others have write permission.
23492
23493@noindent
23494Each other bit is silently ignored.
23495
23496@end table
23497
23498@smallexample
23499@exdent Return value:
23500open returns the new file descriptor or -1 if an error
23501occured.
23502
23503@exdent Errors:
23504@end smallexample
23505
23506@table @code
b383017d 23507@item EEXIST
0ce1b118
CV
23508pathname already exists and O_CREAT and O_EXCL were used.
23509
b383017d 23510@item EISDIR
0ce1b118
CV
23511pathname refers to a directory.
23512
b383017d 23513@item EACCES
0ce1b118
CV
23514The requested access is not allowed.
23515
23516@item ENAMETOOLONG
23517pathname was too long.
23518
b383017d 23519@item ENOENT
0ce1b118
CV
23520A directory component in pathname does not exist.
23521
b383017d 23522@item ENODEV
0ce1b118
CV
23523pathname refers to a device, pipe, named pipe or socket.
23524
b383017d 23525@item EROFS
0ce1b118
CV
23526pathname refers to a file on a read-only filesystem and
23527write access was requested.
23528
b383017d 23529@item EFAULT
0ce1b118
CV
23530pathname is an invalid pointer value.
23531
b383017d 23532@item ENOSPC
0ce1b118
CV
23533No space on device to create the file.
23534
b383017d 23535@item EMFILE
0ce1b118
CV
23536The process already has the maximum number of files open.
23537
b383017d 23538@item ENFILE
0ce1b118
CV
23539The limit on the total number of files open on the system
23540has been reached.
23541
b383017d 23542@item EINTR
0ce1b118
CV
23543The call was interrupted by the user.
23544@end table
23545
23546@node close
23547@unnumberedsubsubsec close
23548@cindex close, file-i/o system call
23549
23550@smallexample
b383017d 23551@exdent Synopsis:
0ce1b118
CV
23552int close(int fd);
23553
b383017d 23554@exdent Request:
0ce1b118
CV
23555Fclose,fd
23556
23557@exdent Return value:
23558close returns zero on success, or -1 if an error occurred.
23559
23560@exdent Errors:
23561@end smallexample
23562
23563@table @code
b383017d 23564@item EBADF
0ce1b118
CV
23565fd isn't a valid open file descriptor.
23566
b383017d 23567@item EINTR
0ce1b118
CV
23568The call was interrupted by the user.
23569@end table
23570
23571@node read
23572@unnumberedsubsubsec read
23573@cindex read, file-i/o system call
23574
23575@smallexample
b383017d 23576@exdent Synopsis:
0ce1b118
CV
23577int read(int fd, void *buf, unsigned int count);
23578
b383017d 23579@exdent Request:
0ce1b118
CV
23580Fread,fd,bufptr,count
23581
23582@exdent Return value:
23583On success, the number of bytes read is returned.
23584Zero indicates end of file. If count is zero, read
b383017d 23585returns zero as well. On error, -1 is returned.
0ce1b118
CV
23586
23587@exdent Errors:
23588@end smallexample
23589
23590@table @code
b383017d 23591@item EBADF
0ce1b118
CV
23592fd is not a valid file descriptor or is not open for
23593reading.
23594
b383017d 23595@item EFAULT
0ce1b118
CV
23596buf is an invalid pointer value.
23597
b383017d 23598@item EINTR
0ce1b118
CV
23599The call was interrupted by the user.
23600@end table
23601
23602@node write
23603@unnumberedsubsubsec write
23604@cindex write, file-i/o system call
23605
23606@smallexample
b383017d 23607@exdent Synopsis:
0ce1b118
CV
23608int write(int fd, const void *buf, unsigned int count);
23609
b383017d 23610@exdent Request:
0ce1b118
CV
23611Fwrite,fd,bufptr,count
23612
23613@exdent Return value:
23614On success, the number of bytes written are returned.
23615Zero indicates nothing was written. On error, -1
23616is returned.
23617
23618@exdent Errors:
23619@end smallexample
23620
23621@table @code
b383017d 23622@item EBADF
0ce1b118
CV
23623fd is not a valid file descriptor or is not open for
23624writing.
23625
b383017d 23626@item EFAULT
0ce1b118
CV
23627buf is an invalid pointer value.
23628
b383017d 23629@item EFBIG
0ce1b118
CV
23630An attempt was made to write a file that exceeds the
23631host specific maximum file size allowed.
23632
b383017d 23633@item ENOSPC
0ce1b118
CV
23634No space on device to write the data.
23635
b383017d 23636@item EINTR
0ce1b118
CV
23637The call was interrupted by the user.
23638@end table
23639
23640@node lseek
23641@unnumberedsubsubsec lseek
23642@cindex lseek, file-i/o system call
23643
23644@smallexample
b383017d 23645@exdent Synopsis:
0ce1b118
CV
23646long lseek (int fd, long offset, int flag);
23647
b383017d 23648@exdent Request:
0ce1b118
CV
23649Flseek,fd,offset,flag
23650@end smallexample
23651
23652@code{flag} is one of:
23653
23654@table @code
b383017d 23655@item SEEK_SET
0ce1b118
CV
23656The offset is set to offset bytes.
23657
b383017d 23658@item SEEK_CUR
0ce1b118
CV
23659The offset is set to its current location plus offset
23660bytes.
23661
b383017d 23662@item SEEK_END
0ce1b118
CV
23663The offset is set to the size of the file plus offset
23664bytes.
23665@end table
23666
23667@smallexample
23668@exdent Return value:
23669On success, the resulting unsigned offset in bytes from
23670the beginning of the file is returned. Otherwise, a
23671value of -1 is returned.
23672
23673@exdent Errors:
23674@end smallexample
23675
23676@table @code
b383017d 23677@item EBADF
0ce1b118
CV
23678fd is not a valid open file descriptor.
23679
b383017d 23680@item ESPIPE
0ce1b118
CV
23681fd is associated with the @value{GDBN} console.
23682
b383017d 23683@item EINVAL
0ce1b118
CV
23684flag is not a proper value.
23685
b383017d 23686@item EINTR
0ce1b118
CV
23687The call was interrupted by the user.
23688@end table
23689
23690@node rename
23691@unnumberedsubsubsec rename
23692@cindex rename, file-i/o system call
23693
23694@smallexample
b383017d 23695@exdent Synopsis:
0ce1b118
CV
23696int rename(const char *oldpath, const char *newpath);
23697
b383017d 23698@exdent Request:
0ce1b118
CV
23699Frename,oldpathptr/len,newpathptr/len
23700
23701@exdent Return value:
23702On success, zero is returned. On error, -1 is returned.
23703
23704@exdent Errors:
23705@end smallexample
23706
23707@table @code
b383017d 23708@item EISDIR
0ce1b118
CV
23709newpath is an existing directory, but oldpath is not a
23710directory.
23711
b383017d 23712@item EEXIST
0ce1b118
CV
23713newpath is a non-empty directory.
23714
b383017d 23715@item EBUSY
0ce1b118
CV
23716oldpath or newpath is a directory that is in use by some
23717process.
23718
b383017d 23719@item EINVAL
0ce1b118
CV
23720An attempt was made to make a directory a subdirectory
23721of itself.
23722
b383017d 23723@item ENOTDIR
0ce1b118
CV
23724A component used as a directory in oldpath or new
23725path is not a directory. Or oldpath is a directory
23726and newpath exists but is not a directory.
23727
b383017d 23728@item EFAULT
0ce1b118
CV
23729oldpathptr or newpathptr are invalid pointer values.
23730
b383017d 23731@item EACCES
0ce1b118
CV
23732No access to the file or the path of the file.
23733
23734@item ENAMETOOLONG
b383017d 23735
0ce1b118
CV
23736oldpath or newpath was too long.
23737
b383017d 23738@item ENOENT
0ce1b118
CV
23739A directory component in oldpath or newpath does not exist.
23740
b383017d 23741@item EROFS
0ce1b118
CV
23742The file is on a read-only filesystem.
23743
b383017d 23744@item ENOSPC
0ce1b118
CV
23745The device containing the file has no room for the new
23746directory entry.
23747
b383017d 23748@item EINTR
0ce1b118
CV
23749The call was interrupted by the user.
23750@end table
23751
23752@node unlink
23753@unnumberedsubsubsec unlink
23754@cindex unlink, file-i/o system call
23755
23756@smallexample
b383017d 23757@exdent Synopsis:
0ce1b118
CV
23758int unlink(const char *pathname);
23759
b383017d 23760@exdent Request:
0ce1b118
CV
23761Funlink,pathnameptr/len
23762
23763@exdent Return value:
23764On success, zero is returned. On error, -1 is returned.
23765
23766@exdent Errors:
23767@end smallexample
23768
23769@table @code
b383017d 23770@item EACCES
0ce1b118
CV
23771No access to the file or the path of the file.
23772
b383017d 23773@item EPERM
0ce1b118
CV
23774The system does not allow unlinking of directories.
23775
b383017d 23776@item EBUSY
0ce1b118
CV
23777The file pathname cannot be unlinked because it's
23778being used by another process.
23779
b383017d 23780@item EFAULT
0ce1b118
CV
23781pathnameptr is an invalid pointer value.
23782
23783@item ENAMETOOLONG
23784pathname was too long.
23785
b383017d 23786@item ENOENT
0ce1b118
CV
23787A directory component in pathname does not exist.
23788
b383017d 23789@item ENOTDIR
0ce1b118
CV
23790A component of the path is not a directory.
23791
b383017d 23792@item EROFS
0ce1b118
CV
23793The file is on a read-only filesystem.
23794
b383017d 23795@item EINTR
0ce1b118
CV
23796The call was interrupted by the user.
23797@end table
23798
23799@node stat/fstat
23800@unnumberedsubsubsec stat/fstat
23801@cindex fstat, file-i/o system call
23802@cindex stat, file-i/o system call
23803
23804@smallexample
b383017d 23805@exdent Synopsis:
0ce1b118
CV
23806int stat(const char *pathname, struct stat *buf);
23807int fstat(int fd, struct stat *buf);
23808
b383017d 23809@exdent Request:
0ce1b118
CV
23810Fstat,pathnameptr/len,bufptr
23811Ffstat,fd,bufptr
23812
23813@exdent Return value:
23814On success, zero is returned. On error, -1 is returned.
23815
23816@exdent Errors:
23817@end smallexample
23818
23819@table @code
b383017d 23820@item EBADF
0ce1b118
CV
23821fd is not a valid open file.
23822
b383017d 23823@item ENOENT
0ce1b118
CV
23824A directory component in pathname does not exist or the
23825path is an empty string.
23826
b383017d 23827@item ENOTDIR
0ce1b118
CV
23828A component of the path is not a directory.
23829
b383017d 23830@item EFAULT
0ce1b118
CV
23831pathnameptr is an invalid pointer value.
23832
b383017d 23833@item EACCES
0ce1b118
CV
23834No access to the file or the path of the file.
23835
23836@item ENAMETOOLONG
23837pathname was too long.
23838
b383017d 23839@item EINTR
0ce1b118
CV
23840The call was interrupted by the user.
23841@end table
23842
23843@node gettimeofday
23844@unnumberedsubsubsec gettimeofday
23845@cindex gettimeofday, file-i/o system call
23846
23847@smallexample
b383017d 23848@exdent Synopsis:
0ce1b118
CV
23849int gettimeofday(struct timeval *tv, void *tz);
23850
b383017d 23851@exdent Request:
0ce1b118
CV
23852Fgettimeofday,tvptr,tzptr
23853
23854@exdent Return value:
23855On success, 0 is returned, -1 otherwise.
23856
23857@exdent Errors:
23858@end smallexample
23859
23860@table @code
b383017d 23861@item EINVAL
0ce1b118
CV
23862tz is a non-NULL pointer.
23863
b383017d 23864@item EFAULT
0ce1b118
CV
23865tvptr and/or tzptr is an invalid pointer value.
23866@end table
23867
23868@node isatty
23869@unnumberedsubsubsec isatty
23870@cindex isatty, file-i/o system call
23871
23872@smallexample
b383017d 23873@exdent Synopsis:
0ce1b118
CV
23874int isatty(int fd);
23875
b383017d 23876@exdent Request:
0ce1b118
CV
23877Fisatty,fd
23878
23879@exdent Return value:
23880Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
23881
23882@exdent Errors:
23883@end smallexample
23884
23885@table @code
b383017d 23886@item EINTR
0ce1b118
CV
23887The call was interrupted by the user.
23888@end table
23889
23890@node system
23891@unnumberedsubsubsec system
23892@cindex system, file-i/o system call
23893
23894@smallexample
b383017d 23895@exdent Synopsis:
0ce1b118
CV
23896int system(const char *command);
23897
b383017d 23898@exdent Request:
0ce1b118
CV
23899Fsystem,commandptr/len
23900
23901@exdent Return value:
23902The value returned is -1 on error and the return status
23903of the command otherwise. Only the exit status of the
23904command is returned, which is extracted from the hosts
23905system return value by calling WEXITSTATUS(retval).
23906In case /bin/sh could not be executed, 127 is returned.
23907
23908@exdent Errors:
23909@end smallexample
23910
23911@table @code
b383017d 23912@item EINTR
0ce1b118
CV
23913The call was interrupted by the user.
23914@end table
23915
23916@node Protocol specific representation of datatypes
23917@subsection Protocol specific representation of datatypes
23918@cindex protocol specific representation of datatypes, in file-i/o protocol
23919
23920@menu
23921* Integral datatypes::
23922* Pointer values::
23923* struct stat::
23924* struct timeval::
23925@end menu
23926
23927@node Integral datatypes
23928@unnumberedsubsubsec Integral datatypes
23929@cindex integral datatypes, in file-i/o protocol
23930
23931The integral datatypes used in the system calls are
23932
23933@smallexample
23934int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
23935@end smallexample
23936
23937@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
23938implemented as 32 bit values in this protocol.
23939
b383017d
RM
23940@code{Long} and @code{unsigned long} are implemented as 64 bit types.
23941
0ce1b118
CV
23942@xref{Limits}, for corresponding MIN and MAX values (similar to those
23943in @file{limits.h}) to allow range checking on host and target.
23944
23945@code{time_t} datatypes are defined as seconds since the Epoch.
23946
23947All integral datatypes transferred as part of a memory read or write of a
23948structured datatype e.g.@: a @code{struct stat} have to be given in big endian
23949byte order.
23950
23951@node Pointer values
23952@unnumberedsubsubsec Pointer values
23953@cindex pointer values, in file-i/o protocol
23954
23955Pointers to target data are transmitted as they are. An exception
23956is made for pointers to buffers for which the length isn't
23957transmitted as part of the function call, namely strings. Strings
23958are transmitted as a pointer/length pair, both as hex values, e.g.@:
23959
23960@smallexample
23961@code{1aaf/12}
23962@end smallexample
23963
23964@noindent
23965which is a pointer to data of length 18 bytes at position 0x1aaf.
23966The length is defined as the full string length in bytes, including
23967the trailing null byte. Example:
23968
23969@smallexample
23970``hello, world'' at address 0x123456
23971@end smallexample
23972
23973@noindent
23974is transmitted as
23975
23976@smallexample
23977@code{123456/d}
23978@end smallexample
23979
23980@node struct stat
23981@unnumberedsubsubsec struct stat
23982@cindex struct stat, in file-i/o protocol
23983
23984The buffer of type struct stat used by the target and @value{GDBN} is defined
23985as follows:
23986
23987@smallexample
23988struct stat @{
23989 unsigned int st_dev; /* device */
23990 unsigned int st_ino; /* inode */
23991 mode_t st_mode; /* protection */
23992 unsigned int st_nlink; /* number of hard links */
23993 unsigned int st_uid; /* user ID of owner */
23994 unsigned int st_gid; /* group ID of owner */
23995 unsigned int st_rdev; /* device type (if inode device) */
23996 unsigned long st_size; /* total size, in bytes */
23997 unsigned long st_blksize; /* blocksize for filesystem I/O */
23998 unsigned long st_blocks; /* number of blocks allocated */
23999 time_t st_atime; /* time of last access */
24000 time_t st_mtime; /* time of last modification */
24001 time_t st_ctime; /* time of last change */
24002@};
24003@end smallexample
24004
24005The integral datatypes are conforming to the definitions given in the
24006approriate section (see @ref{Integral datatypes}, for details) so this
24007structure is of size 64 bytes.
24008
24009The values of several fields have a restricted meaning and/or
24010range of values.
24011
24012@smallexample
24013st_dev: 0 file
24014 1 console
24015
24016st_ino: No valid meaning for the target. Transmitted unchanged.
24017
24018st_mode: Valid mode bits are described in Appendix C. Any other
24019 bits have currently no meaning for the target.
24020
24021st_uid: No valid meaning for the target. Transmitted unchanged.
24022
24023st_gid: No valid meaning for the target. Transmitted unchanged.
24024
24025st_rdev: No valid meaning for the target. Transmitted unchanged.
24026
24027st_atime, st_mtime, st_ctime:
24028 These values have a host and file system dependent
24029 accuracy. Especially on Windows hosts the file systems
24030 don't support exact timing values.
24031@end smallexample
24032
24033The target gets a struct stat of the above representation and is
24034responsible to coerce it to the target representation before
24035continuing.
24036
24037Note that due to size differences between the host and target
24038representation of stat members, these members could eventually
24039get truncated on the target.
24040
24041@node struct timeval
24042@unnumberedsubsubsec struct timeval
24043@cindex struct timeval, in file-i/o protocol
24044
24045The buffer of type struct timeval used by the target and @value{GDBN}
24046is defined as follows:
24047
24048@smallexample
b383017d 24049struct timeval @{
0ce1b118
CV
24050 time_t tv_sec; /* second */
24051 long tv_usec; /* microsecond */
24052@};
24053@end smallexample
24054
24055The integral datatypes are conforming to the definitions given in the
24056approriate section (see @ref{Integral datatypes}, for details) so this
24057structure is of size 8 bytes.
24058
24059@node Constants
24060@subsection Constants
24061@cindex constants, in file-i/o protocol
24062
24063The following values are used for the constants inside of the
24064protocol. @value{GDBN} and target are resposible to translate these
24065values before and after the call as needed.
24066
24067@menu
24068* Open flags::
24069* mode_t values::
24070* Errno values::
24071* Lseek flags::
24072* Limits::
24073@end menu
24074
24075@node Open flags
24076@unnumberedsubsubsec Open flags
24077@cindex open flags, in file-i/o protocol
24078
24079All values are given in hexadecimal representation.
24080
24081@smallexample
24082 O_RDONLY 0x0
24083 O_WRONLY 0x1
24084 O_RDWR 0x2
24085 O_APPEND 0x8
24086 O_CREAT 0x200
24087 O_TRUNC 0x400
24088 O_EXCL 0x800
24089@end smallexample
24090
24091@node mode_t values
24092@unnumberedsubsubsec mode_t values
24093@cindex mode_t values, in file-i/o protocol
24094
24095All values are given in octal representation.
24096
24097@smallexample
24098 S_IFREG 0100000
24099 S_IFDIR 040000
24100 S_IRUSR 0400
24101 S_IWUSR 0200
24102 S_IXUSR 0100
24103 S_IRGRP 040
24104 S_IWGRP 020
24105 S_IXGRP 010
24106 S_IROTH 04
24107 S_IWOTH 02
24108 S_IXOTH 01
24109@end smallexample
24110
24111@node Errno values
24112@unnumberedsubsubsec Errno values
24113@cindex errno values, in file-i/o protocol
24114
24115All values are given in decimal representation.
24116
24117@smallexample
24118 EPERM 1
24119 ENOENT 2
24120 EINTR 4
24121 EBADF 9
24122 EACCES 13
24123 EFAULT 14
24124 EBUSY 16
24125 EEXIST 17
24126 ENODEV 19
24127 ENOTDIR 20
24128 EISDIR 21
24129 EINVAL 22
24130 ENFILE 23
24131 EMFILE 24
24132 EFBIG 27
24133 ENOSPC 28
24134 ESPIPE 29
24135 EROFS 30
24136 ENAMETOOLONG 91
24137 EUNKNOWN 9999
24138@end smallexample
24139
24140 EUNKNOWN is used as a fallback error value if a host system returns
24141 any error value not in the list of supported error numbers.
24142
24143@node Lseek flags
24144@unnumberedsubsubsec Lseek flags
24145@cindex lseek flags, in file-i/o protocol
24146
24147@smallexample
24148 SEEK_SET 0
24149 SEEK_CUR 1
24150 SEEK_END 2
24151@end smallexample
24152
24153@node Limits
24154@unnumberedsubsubsec Limits
24155@cindex limits, in file-i/o protocol
24156
24157All values are given in decimal representation.
24158
24159@smallexample
24160 INT_MIN -2147483648
24161 INT_MAX 2147483647
24162 UINT_MAX 4294967295
24163 LONG_MIN -9223372036854775808
24164 LONG_MAX 9223372036854775807
24165 ULONG_MAX 18446744073709551615
24166@end smallexample
24167
24168@node File-I/O Examples
24169@subsection File-I/O Examples
24170@cindex file-i/o examples
24171
24172Example sequence of a write call, file descriptor 3, buffer is at target
24173address 0x1234, 6 bytes should be written:
24174
24175@smallexample
24176<- @code{Fwrite,3,1234,6}
24177@emph{request memory read from target}
24178-> @code{m1234,6}
24179<- XXXXXX
24180@emph{return "6 bytes written"}
24181-> @code{F6}
24182@end smallexample
24183
24184Example sequence of a read call, file descriptor 3, buffer is at target
24185address 0x1234, 6 bytes should be read:
24186
24187@smallexample
24188<- @code{Fread,3,1234,6}
24189@emph{request memory write to target}
24190-> @code{X1234,6:XXXXXX}
24191@emph{return "6 bytes read"}
24192-> @code{F6}
24193@end smallexample
24194
24195Example sequence of a read call, call fails on the host due to invalid
24196file descriptor (EBADF):
24197
24198@smallexample
24199<- @code{Fread,3,1234,6}
24200-> @code{F-1,9}
24201@end smallexample
24202
24203Example sequence of a read call, user presses Ctrl-C before syscall on
24204host is called:
24205
24206@smallexample
24207<- @code{Fread,3,1234,6}
24208-> @code{F-1,4,C}
24209<- @code{T02}
24210@end smallexample
24211
24212Example sequence of a read call, user presses Ctrl-C after syscall on
24213host is called:
24214
24215@smallexample
24216<- @code{Fread,3,1234,6}
24217-> @code{X1234,6:XXXXXX}
24218<- @code{T02}
24219@end smallexample
24220
f418dd93
DJ
24221@include agentexpr.texi
24222
aab4e0ec 24223@include gpl.texi
eb12ee30 24224
2154891a 24225@raisesections
6826cf00 24226@include fdl.texi
2154891a 24227@lowersections
6826cf00 24228
6d2ebf8b 24229@node Index
c906108c
SS
24230@unnumbered Index
24231
24232@printindex cp
24233
24234@tex
24235% I think something like @colophon should be in texinfo. In the
24236% meantime:
24237\long\def\colophon{\hbox to0pt{}\vfill
24238\centerline{The body of this manual is set in}
24239\centerline{\fontname\tenrm,}
24240\centerline{with headings in {\bf\fontname\tenbf}}
24241\centerline{and examples in {\tt\fontname\tentt}.}
24242\centerline{{\it\fontname\tenit\/},}
24243\centerline{{\bf\fontname\tenbf}, and}
24244\centerline{{\sl\fontname\tensl\/}}
24245\centerline{are used for emphasis.}\vfill}
24246\page\colophon
24247% Blame: doc@cygnus.com, 1991.
24248@end tex
24249
c906108c 24250@bye
This page took 1.892773 seconds and 4 git commands to generate.