2005-11-03 Wu Zhou <woodzltc@cn.ibm.com>
[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:
7ba3cf9c 352Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
353Jim Blandy (release 4.18);
354Jason Molenda (release 4.17);
355Stan Shebs (release 4.14);
356Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
357Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
358John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
359Jim Kingdon (releases 3.5, 3.4, and 3.3);
360and Randy Smith (releases 3.2, 3.1, and 3.0).
361
362Richard Stallman, assisted at various times by Peter TerMaat, Chris
363Hanson, and Richard Mlynarik, handled releases through 2.8.
364
b37052ae
EZ
365Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
366in @value{GDBN}, with significant additional contributions from Per
367Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
368demangler. Early work on C@t{++} was by Peter TerMaat (who also did
369much general update work leading to release 3.0).
c906108c 370
b37052ae 371@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
372object-file formats; BFD was a joint project of David V.
373Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
374
375David Johnson wrote the original COFF support; Pace Willison did
376the original support for encapsulated COFF.
377
0179ffac 378Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
379
380Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
381Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
382support.
383Jean-Daniel Fekete contributed Sun 386i support.
384Chris Hanson improved the HP9000 support.
385Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
386David Johnson contributed Encore Umax support.
387Jyrki Kuoppala contributed Altos 3068 support.
388Jeff Law contributed HP PA and SOM support.
389Keith Packard contributed NS32K support.
390Doug Rabson contributed Acorn Risc Machine support.
391Bob Rusk contributed Harris Nighthawk CX-UX support.
392Chris Smith contributed Convex support (and Fortran debugging).
393Jonathan Stone contributed Pyramid support.
394Michael Tiemann contributed SPARC support.
395Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
396Pace Willison contributed Intel 386 support.
397Jay Vosburgh contributed Symmetry support.
a37295f9 398Marko Mlinar contributed OpenRISC 1000 support.
c906108c 399
1104b9e7 400Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
401
402Rich Schaefer and Peter Schauer helped with support of SunOS shared
403libraries.
404
405Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
406about several machine instruction sets.
407
408Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
409remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
410contributed remote debugging modules for the i960, VxWorks, A29K UDI,
411and RDI targets, respectively.
412
413Brian Fox is the author of the readline libraries providing
414command-line editing and command history.
415
7a292a7a
SS
416Andrew Beers of SUNY Buffalo wrote the language-switching code, the
417Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 418
5d161b24 419Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 420He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 421symbols.
c906108c 422
f24c5e49
KI
423Hitachi America (now Renesas America), Ltd. sponsored the support for
424H8/300, H8/500, and Super-H processors.
c906108c
SS
425
426NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
427
f24c5e49
KI
428Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
429processors.
c906108c
SS
430
431Toshiba sponsored the support for the TX39 Mips processor.
432
433Matsushita sponsored the support for the MN10200 and MN10300 processors.
434
96a2c332 435Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
436
437Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
438watchpoints.
439
440Michael Snyder added support for tracepoints.
441
442Stu Grossman wrote gdbserver.
443
444Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 445nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
446
447The following people at the Hewlett-Packard Company contributed
448support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 449(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
d0d5df6f
AC
450compiler, and the Text User Interface (nee Terminal User Interface):
451Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
452Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
453provided HP-specific information in this manual.
c906108c 454
b37052ae
EZ
455DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
456Robert Hoehne made significant contributions to the DJGPP port.
457
96a2c332
SS
458Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
459development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
460fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
461Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
462Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
463Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
464Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
465addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
466JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
467Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
468Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
469Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
470Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
471Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
472Zuhn have made contributions both large and small.
c906108c 473
ffed4509
AC
474Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
475Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
476
e2e0bcd1
JB
477Jim Blandy added support for preprocessor macros, while working for Red
478Hat.
c906108c 479
a9967aef
AC
480Andrew Cagney designed @value{GDBN}'s architecture vector. Many
481people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
482Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
483Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
484Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
485with the migration of old architectures to this new framework.
486
6d2ebf8b 487@node Sample Session
c906108c
SS
488@chapter A Sample @value{GDBN} Session
489
490You can use this manual at your leisure to read all about @value{GDBN}.
491However, a handful of commands are enough to get started using the
492debugger. This chapter illustrates those commands.
493
494@iftex
495In this sample session, we emphasize user input like this: @b{input},
496to make it easier to pick out from the surrounding output.
497@end iftex
498
499@c FIXME: this example may not be appropriate for some configs, where
500@c FIXME...primary interest is in remote use.
501
502One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
503processor) exhibits the following bug: sometimes, when we change its
504quote strings from the default, the commands used to capture one macro
505definition within another stop working. In the following short @code{m4}
506session, we define a macro @code{foo} which expands to @code{0000}; we
507then use the @code{m4} built-in @code{defn} to define @code{bar} as the
508same thing. However, when we change the open quote string to
509@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
510procedure fails to define a new synonym @code{baz}:
511
512@smallexample
513$ @b{cd gnu/m4}
514$ @b{./m4}
515@b{define(foo,0000)}
516
517@b{foo}
5180000
519@b{define(bar,defn(`foo'))}
520
521@b{bar}
5220000
523@b{changequote(<QUOTE>,<UNQUOTE>)}
524
525@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
526@b{baz}
527@b{C-d}
528m4: End of input: 0: fatal error: EOF in string
529@end smallexample
530
531@noindent
532Let us use @value{GDBN} to try to see what is going on.
533
c906108c
SS
534@smallexample
535$ @b{@value{GDBP} m4}
536@c FIXME: this falsifies the exact text played out, to permit smallbook
537@c FIXME... format to come out better.
538@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 539 of it under certain conditions; type "show copying" to see
c906108c 540 the conditions.
5d161b24 541There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
542 for details.
543
544@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
545(@value{GDBP})
546@end smallexample
c906108c
SS
547
548@noindent
549@value{GDBN} reads only enough symbol data to know where to find the
550rest when needed; as a result, the first prompt comes up very quickly.
551We now tell @value{GDBN} to use a narrower display width than usual, so
552that examples fit in this manual.
553
554@smallexample
555(@value{GDBP}) @b{set width 70}
556@end smallexample
557
558@noindent
559We need to see how the @code{m4} built-in @code{changequote} works.
560Having looked at the source, we know the relevant subroutine is
561@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
562@code{break} command.
563
564@smallexample
565(@value{GDBP}) @b{break m4_changequote}
566Breakpoint 1 at 0x62f4: file builtin.c, line 879.
567@end smallexample
568
569@noindent
570Using the @code{run} command, we start @code{m4} running under @value{GDBN}
571control; as long as control does not reach the @code{m4_changequote}
572subroutine, the program runs as usual:
573
574@smallexample
575(@value{GDBP}) @b{run}
576Starting program: /work/Editorial/gdb/gnu/m4/m4
577@b{define(foo,0000)}
578
579@b{foo}
5800000
581@end smallexample
582
583@noindent
584To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
585suspends execution of @code{m4}, displaying information about the
586context where it stops.
587
588@smallexample
589@b{changequote(<QUOTE>,<UNQUOTE>)}
590
5d161b24 591Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
592 at builtin.c:879
593879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
594@end smallexample
595
596@noindent
597Now we use the command @code{n} (@code{next}) to advance execution to
598the next line of the current function.
599
600@smallexample
601(@value{GDBP}) @b{n}
602882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
603 : nil,
604@end smallexample
605
606@noindent
607@code{set_quotes} looks like a promising subroutine. We can go into it
608by using the command @code{s} (@code{step}) instead of @code{next}.
609@code{step} goes to the next line to be executed in @emph{any}
610subroutine, so it steps into @code{set_quotes}.
611
612@smallexample
613(@value{GDBP}) @b{s}
614set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
615 at input.c:530
616530 if (lquote != def_lquote)
617@end smallexample
618
619@noindent
620The display that shows the subroutine where @code{m4} is now
621suspended (and its arguments) is called a stack frame display. It
622shows a summary of the stack. We can use the @code{backtrace}
623command (which can also be spelled @code{bt}), to see where we are
624in the stack as a whole: the @code{backtrace} command displays a
625stack frame for each active subroutine.
626
627@smallexample
628(@value{GDBP}) @b{bt}
629#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
630 at input.c:530
5d161b24 631#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
632 at builtin.c:882
633#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
634#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
635 at macro.c:71
636#4 0x79dc in expand_input () at macro.c:40
637#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
638@end smallexample
639
640@noindent
641We step through a few more lines to see what happens. The first two
642times, we can use @samp{s}; the next two times we use @code{n} to avoid
643falling into the @code{xstrdup} subroutine.
644
645@smallexample
646(@value{GDBP}) @b{s}
6470x3b5c 532 if (rquote != def_rquote)
648(@value{GDBP}) @b{s}
6490x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
650def_lquote : xstrdup(lq);
651(@value{GDBP}) @b{n}
652536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
653 : xstrdup(rq);
654(@value{GDBP}) @b{n}
655538 len_lquote = strlen(rquote);
656@end smallexample
657
658@noindent
659The last line displayed looks a little odd; we can examine the variables
660@code{lquote} and @code{rquote} to see if they are in fact the new left
661and right quotes we specified. We use the command @code{p}
662(@code{print}) to see their values.
663
664@smallexample
665(@value{GDBP}) @b{p lquote}
666$1 = 0x35d40 "<QUOTE>"
667(@value{GDBP}) @b{p rquote}
668$2 = 0x35d50 "<UNQUOTE>"
669@end smallexample
670
671@noindent
672@code{lquote} and @code{rquote} are indeed the new left and right quotes.
673To look at some context, we can display ten lines of source
674surrounding the current line with the @code{l} (@code{list}) command.
675
676@smallexample
677(@value{GDBP}) @b{l}
678533 xfree(rquote);
679534
680535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
681 : xstrdup (lq);
682536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
683 : xstrdup (rq);
684537
685538 len_lquote = strlen(rquote);
686539 len_rquote = strlen(lquote);
687540 @}
688541
689542 void
690@end smallexample
691
692@noindent
693Let us step past the two lines that set @code{len_lquote} and
694@code{len_rquote}, and then examine the values of those variables.
695
696@smallexample
697(@value{GDBP}) @b{n}
698539 len_rquote = strlen(lquote);
699(@value{GDBP}) @b{n}
700540 @}
701(@value{GDBP}) @b{p len_lquote}
702$3 = 9
703(@value{GDBP}) @b{p len_rquote}
704$4 = 7
705@end smallexample
706
707@noindent
708That certainly looks wrong, assuming @code{len_lquote} and
709@code{len_rquote} are meant to be the lengths of @code{lquote} and
710@code{rquote} respectively. We can set them to better values using
711the @code{p} command, since it can print the value of
712any expression---and that expression can include subroutine calls and
713assignments.
714
715@smallexample
716(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
717$5 = 7
718(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
719$6 = 9
720@end smallexample
721
722@noindent
723Is that enough to fix the problem of using the new quotes with the
724@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
725executing with the @code{c} (@code{continue}) command, and then try the
726example that caused trouble initially:
727
728@smallexample
729(@value{GDBP}) @b{c}
730Continuing.
731
732@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
733
734baz
7350000
736@end smallexample
737
738@noindent
739Success! The new quotes now work just as well as the default ones. The
740problem seems to have been just the two typos defining the wrong
741lengths. We allow @code{m4} exit by giving it an EOF as input:
742
743@smallexample
744@b{C-d}
745Program exited normally.
746@end smallexample
747
748@noindent
749The message @samp{Program exited normally.} is from @value{GDBN}; it
750indicates @code{m4} has finished executing. We can end our @value{GDBN}
751session with the @value{GDBN} @code{quit} command.
752
753@smallexample
754(@value{GDBP}) @b{quit}
755@end smallexample
c906108c 756
6d2ebf8b 757@node Invocation
c906108c
SS
758@chapter Getting In and Out of @value{GDBN}
759
760This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 761The essentials are:
c906108c 762@itemize @bullet
5d161b24 763@item
53a5351d 764type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 765@item
c906108c
SS
766type @kbd{quit} or @kbd{C-d} to exit.
767@end itemize
768
769@menu
770* Invoking GDB:: How to start @value{GDBN}
771* Quitting GDB:: How to quit @value{GDBN}
772* Shell Commands:: How to use shell commands inside @value{GDBN}
0fac0b41 773* Logging output:: How to log @value{GDBN}'s output to a file
c906108c
SS
774@end menu
775
6d2ebf8b 776@node Invoking GDB
c906108c
SS
777@section Invoking @value{GDBN}
778
c906108c
SS
779Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
780@value{GDBN} reads commands from the terminal until you tell it to exit.
781
782You can also run @code{@value{GDBP}} with a variety of arguments and options,
783to specify more of your debugging environment at the outset.
784
c906108c
SS
785The command-line options described here are designed
786to cover a variety of situations; in some environments, some of these
5d161b24 787options may effectively be unavailable.
c906108c
SS
788
789The most usual way to start @value{GDBN} is with one argument,
790specifying an executable program:
791
474c8240 792@smallexample
c906108c 793@value{GDBP} @var{program}
474c8240 794@end smallexample
c906108c 795
c906108c
SS
796@noindent
797You can also start with both an executable program and a core file
798specified:
799
474c8240 800@smallexample
c906108c 801@value{GDBP} @var{program} @var{core}
474c8240 802@end smallexample
c906108c
SS
803
804You can, instead, specify a process ID as a second argument, if you want
805to debug a running process:
806
474c8240 807@smallexample
c906108c 808@value{GDBP} @var{program} 1234
474c8240 809@end smallexample
c906108c
SS
810
811@noindent
812would attach @value{GDBN} to process @code{1234} (unless you also have a file
813named @file{1234}; @value{GDBN} does check for a core file first).
814
c906108c 815Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
816complete operating system; when you use @value{GDBN} as a remote
817debugger attached to a bare board, there may not be any notion of
818``process'', and there is often no way to get a core dump. @value{GDBN}
819will warn you if it is unable to attach or to read core dumps.
c906108c 820
aa26fa3a
TT
821You can optionally have @code{@value{GDBP}} pass any arguments after the
822executable file to the inferior using @code{--args}. This option stops
823option processing.
474c8240 824@smallexample
aa26fa3a 825gdb --args gcc -O2 -c foo.c
474c8240 826@end smallexample
aa26fa3a
TT
827This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
828@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
829
96a2c332 830You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
831@value{GDBN}'s non-warranty, by specifying @code{-silent}:
832
833@smallexample
834@value{GDBP} -silent
835@end smallexample
836
837@noindent
838You can further control how @value{GDBN} starts up by using command-line
839options. @value{GDBN} itself can remind you of the options available.
840
841@noindent
842Type
843
474c8240 844@smallexample
c906108c 845@value{GDBP} -help
474c8240 846@end smallexample
c906108c
SS
847
848@noindent
849to display all available options and briefly describe their use
850(@samp{@value{GDBP} -h} is a shorter equivalent).
851
852All options and command line arguments you give are processed
853in sequential order. The order makes a difference when the
854@samp{-x} option is used.
855
856
857@menu
c906108c
SS
858* File Options:: Choosing files
859* Mode Options:: Choosing modes
6fc08d32 860* Startup:: What @value{GDBN} does during startup
c906108c
SS
861@end menu
862
6d2ebf8b 863@node File Options
c906108c
SS
864@subsection Choosing files
865
2df3850c 866When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
867specifying an executable file and core file (or process ID). This is
868the same as if the arguments were specified by the @samp{-se} and
19837790
MS
869@samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
870first argument that does not have an associated option flag as
871equivalent to the @samp{-se} option followed by that argument; and the
872second argument that does not have an associated option flag, if any, as
873equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
874If the second argument begins with a decimal digit, @value{GDBN} will
875first attempt to attach to it as a process, and if that fails, attempt
876to open it as a corefile. If you have a corefile whose name begins with
b383017d 877a digit, you can prevent @value{GDBN} from treating it as a pid by
79f12247 878prefixing it with @file{./}, eg. @file{./12345}.
7a292a7a
SS
879
880If @value{GDBN} has not been configured to included core file support,
881such as for most embedded targets, then it will complain about a second
882argument and ignore it.
c906108c
SS
883
884Many options have both long and short forms; both are shown in the
885following list. @value{GDBN} also recognizes the long forms if you truncate
886them, so long as enough of the option is present to be unambiguous.
887(If you prefer, you can flag option arguments with @samp{--} rather
888than @samp{-}, though we illustrate the more usual convention.)
889
d700128c
EZ
890@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
891@c way, both those who look for -foo and --foo in the index, will find
892@c it.
893
c906108c
SS
894@table @code
895@item -symbols @var{file}
896@itemx -s @var{file}
d700128c
EZ
897@cindex @code{--symbols}
898@cindex @code{-s}
c906108c
SS
899Read symbol table from file @var{file}.
900
901@item -exec @var{file}
902@itemx -e @var{file}
d700128c
EZ
903@cindex @code{--exec}
904@cindex @code{-e}
7a292a7a
SS
905Use file @var{file} as the executable file to execute when appropriate,
906and for examining pure data in conjunction with a core dump.
c906108c
SS
907
908@item -se @var{file}
d700128c 909@cindex @code{--se}
c906108c
SS
910Read symbol table from file @var{file} and use it as the executable
911file.
912
c906108c
SS
913@item -core @var{file}
914@itemx -c @var{file}
d700128c
EZ
915@cindex @code{--core}
916@cindex @code{-c}
b383017d 917Use file @var{file} as a core dump to examine.
c906108c
SS
918
919@item -c @var{number}
19837790
MS
920@item -pid @var{number}
921@itemx -p @var{number}
922@cindex @code{--pid}
923@cindex @code{-p}
924Connect to process ID @var{number}, as with the @code{attach} command.
925If there is no such process, @value{GDBN} will attempt to open a core
926file named @var{number}.
c906108c
SS
927
928@item -command @var{file}
929@itemx -x @var{file}
d700128c
EZ
930@cindex @code{--command}
931@cindex @code{-x}
c906108c
SS
932Execute @value{GDBN} commands from file @var{file}. @xref{Command
933Files,, Command files}.
934
935@item -directory @var{directory}
936@itemx -d @var{directory}
d700128c
EZ
937@cindex @code{--directory}
938@cindex @code{-d}
c906108c
SS
939Add @var{directory} to the path to search for source files.
940
c906108c
SS
941@item -r
942@itemx -readnow
d700128c
EZ
943@cindex @code{--readnow}
944@cindex @code{-r}
c906108c
SS
945Read each symbol file's entire symbol table immediately, rather than
946the default, which is to read it incrementally as it is needed.
947This makes startup slower, but makes future operations faster.
53a5351d 948
c906108c
SS
949@end table
950
6d2ebf8b 951@node Mode Options
c906108c
SS
952@subsection Choosing modes
953
954You can run @value{GDBN} in various alternative modes---for example, in
955batch mode or quiet mode.
956
957@table @code
958@item -nx
959@itemx -n
d700128c
EZ
960@cindex @code{--nx}
961@cindex @code{-n}
96565e91 962Do not execute commands found in any initialization files. Normally,
2df3850c
JM
963@value{GDBN} executes the commands in these files after all the command
964options and arguments have been processed. @xref{Command Files,,Command
965files}.
c906108c
SS
966
967@item -quiet
d700128c 968@itemx -silent
c906108c 969@itemx -q
d700128c
EZ
970@cindex @code{--quiet}
971@cindex @code{--silent}
972@cindex @code{-q}
c906108c
SS
973``Quiet''. Do not print the introductory and copyright messages. These
974messages are also suppressed in batch mode.
975
976@item -batch
d700128c 977@cindex @code{--batch}
c906108c
SS
978Run in batch mode. Exit with status @code{0} after processing all the
979command files specified with @samp{-x} (and all commands from
980initialization files, if not inhibited with @samp{-n}). Exit with
981nonzero status if an error occurs in executing the @value{GDBN} commands
982in the command files.
983
2df3850c
JM
984Batch mode may be useful for running @value{GDBN} as a filter, for
985example to download and run a program on another computer; in order to
986make this more useful, the message
c906108c 987
474c8240 988@smallexample
c906108c 989Program exited normally.
474c8240 990@end smallexample
c906108c
SS
991
992@noindent
2df3850c
JM
993(which is ordinarily issued whenever a program running under
994@value{GDBN} control terminates) is not issued when running in batch
995mode.
996
1a088d06
AS
997@item -batch-silent
998@cindex @code{--batch-silent}
999Run in batch mode exactly like @samp{-batch}, but totally silently. All
1000@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1001unaffected). This is much quieter than @samp{-silent} and would be useless
1002for an interactive session.
1003
1004This is particularly useful when using targets that give @samp{Loading section}
1005messages, for example.
1006
1007Note that targets that give their output via @value{GDBN}, as opposed to
1008writing directly to @code{stdout}, will also be made silent.
1009
2df3850c
JM
1010@item -nowindows
1011@itemx -nw
d700128c
EZ
1012@cindex @code{--nowindows}
1013@cindex @code{-nw}
2df3850c 1014``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1015(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1016interface. If no GUI is available, this option has no effect.
1017
1018@item -windows
1019@itemx -w
d700128c
EZ
1020@cindex @code{--windows}
1021@cindex @code{-w}
2df3850c
JM
1022If @value{GDBN} includes a GUI, then this option requires it to be
1023used if possible.
c906108c
SS
1024
1025@item -cd @var{directory}
d700128c 1026@cindex @code{--cd}
c906108c
SS
1027Run @value{GDBN} using @var{directory} as its working directory,
1028instead of the current directory.
1029
c906108c
SS
1030@item -fullname
1031@itemx -f
d700128c
EZ
1032@cindex @code{--fullname}
1033@cindex @code{-f}
7a292a7a
SS
1034@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1035subprocess. It tells @value{GDBN} to output the full file name and line
1036number in a standard, recognizable fashion each time a stack frame is
1037displayed (which includes each time your program stops). This
1038recognizable format looks like two @samp{\032} characters, followed by
1039the file name, line number and character position separated by colons,
1040and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1041@samp{\032} characters as a signal to display the source code for the
1042frame.
c906108c 1043
d700128c
EZ
1044@item -epoch
1045@cindex @code{--epoch}
1046The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1047@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1048routines so as to allow Epoch to display values of expressions in a
1049separate window.
1050
1051@item -annotate @var{level}
1052@cindex @code{--annotate}
1053This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1054effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1055(@pxref{Annotations}). The annotation @var{level} controls how much
1056information @value{GDBN} prints together with its prompt, values of
1057expressions, source lines, and other types of output. Level 0 is the
1058normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1059@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1060that control @value{GDBN}, and level 2 has been deprecated.
1061
265eeb58 1062The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1063(@pxref{GDB/MI}).
d700128c 1064
aa26fa3a
TT
1065@item --args
1066@cindex @code{--args}
1067Change interpretation of command line so that arguments following the
1068executable file are passed as command line arguments to the inferior.
1069This option stops option processing.
1070
2df3850c
JM
1071@item -baud @var{bps}
1072@itemx -b @var{bps}
d700128c
EZ
1073@cindex @code{--baud}
1074@cindex @code{-b}
c906108c
SS
1075Set the line speed (baud rate or bits per second) of any serial
1076interface used by @value{GDBN} for remote debugging.
c906108c 1077
f47b1503
AS
1078@item -l @var{timeout}
1079@cindex @code{-l}
1080Set the timeout (in seconds) of any communication used by @value{GDBN}
1081for remote debugging.
1082
c906108c 1083@item -tty @var{device}
d700128c
EZ
1084@itemx -t @var{device}
1085@cindex @code{--tty}
1086@cindex @code{-t}
c906108c
SS
1087Run using @var{device} for your program's standard input and output.
1088@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1089
53a5351d 1090@c resolve the situation of these eventually
c4555f82
SC
1091@item -tui
1092@cindex @code{--tui}
d0d5df6f
AC
1093Activate the @dfn{Text User Interface} when starting. The Text User
1094Interface manages several text windows on the terminal, showing
1095source, assembly, registers and @value{GDBN} command outputs
1096(@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1097Text User Interface can be enabled by invoking the program
1098@samp{gdbtui}. Do not use this option if you run @value{GDBN} from
1099Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1100
1101@c @item -xdb
d700128c 1102@c @cindex @code{--xdb}
53a5351d
JM
1103@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1104@c For information, see the file @file{xdb_trans.html}, which is usually
1105@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1106@c systems.
1107
d700128c
EZ
1108@item -interpreter @var{interp}
1109@cindex @code{--interpreter}
1110Use the interpreter @var{interp} for interface with the controlling
1111program or device. This option is meant to be set by programs which
94bbb2c0 1112communicate with @value{GDBN} using it as a back end.
21c294e6 1113@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1114
da0f9dcd 1115@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1116@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1117The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1118previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1119selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1120@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1121
1122@item -write
1123@cindex @code{--write}
1124Open the executable and core files for both reading and writing. This
1125is equivalent to the @samp{set write on} command inside @value{GDBN}
1126(@pxref{Patching}).
1127
1128@item -statistics
1129@cindex @code{--statistics}
1130This option causes @value{GDBN} to print statistics about time and
1131memory usage after it completes each command and returns to the prompt.
1132
1133@item -version
1134@cindex @code{--version}
1135This option causes @value{GDBN} to print its version number and
1136no-warranty blurb, and exit.
1137
c906108c
SS
1138@end table
1139
6fc08d32
EZ
1140@node Startup
1141@subsection What @value{GDBN} does during startup
1142@cindex @value{GDBN} startup
1143
1144Here's the description of what @value{GDBN} does during session startup:
1145
1146@enumerate
1147@item
1148Sets up the command interpreter as specified by the command line
1149(@pxref{Mode Options, interpreter}).
1150
1151@item
1152@cindex init file
1153Reads the @dfn{init file} (if any) in your home directory@footnote{On
1154DOS/Windows systems, the home directory is the one pointed to by the
1155@code{HOME} environment variable.} and executes all the commands in
1156that file.
1157
1158@item
1159Processes command line options and operands.
1160
1161@item
1162Reads and executes the commands from init file (if any) in the current
119b882a
EZ
1163working directory. This is only done if the current directory is
1164different from your home directory. Thus, you can have more than one
1165init file, one generic in your home directory, and another, specific
1166to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1167@value{GDBN}.
1168
1169@item
1170Reads command files specified by the @samp{-x} option. @xref{Command
1171Files}, for more details about @value{GDBN} command files.
1172
1173@item
1174Reads the command history recorded in the @dfn{history file}.
d620b259 1175@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1176files where @value{GDBN} records it.
1177@end enumerate
1178
1179Init files use the same syntax as @dfn{command files} (@pxref{Command
1180Files}) and are processed by @value{GDBN} in the same way. The init
1181file in your home directory can set options (such as @samp{set
1182complaints}) that affect subsequent processing of command line options
1183and operands. Init files are not executed if you use the @samp{-nx}
1184option (@pxref{Mode Options, ,Choosing modes}).
1185
1186@cindex init file name
1187@cindex @file{.gdbinit}
119b882a 1188The @value{GDBN} init files are normally called @file{.gdbinit}.
6fc08d32
EZ
1189On some configurations of @value{GDBN}, the init file is known by a
1190different name (these are typically environments where a specialized
1191form of @value{GDBN} may need to coexist with other forms, hence a
1192different name for the specialized version's init file). These are the
1193environments with special init file names:
1194
6fc08d32 1195@itemize @bullet
119b882a
EZ
1196@cindex @file{gdb.ini}
1197@item
1198The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1199the limitations of file names imposed by DOS filesystems. The Windows
1200ports of @value{GDBN} use the standard name, but if they find a
1201@file{gdb.ini} file, they warn you about that and suggest to rename
1202the file to the standard name.
1203
1204@cindex @file{.vxgdbinit}
6fc08d32
EZ
1205@item
1206VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
1207
1208@cindex @file{.os68gdbinit}
1209@item
1210OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
1211
1212@cindex @file{.esgdbinit}
1213@item
1214ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
1215
1216@item
1217CISCO 68k: @file{.cisco-gdbinit}
1218@end itemize
1219
1220
6d2ebf8b 1221@node Quitting GDB
c906108c
SS
1222@section Quitting @value{GDBN}
1223@cindex exiting @value{GDBN}
1224@cindex leaving @value{GDBN}
1225
1226@table @code
1227@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1228@kindex q @r{(@code{quit})}
96a2c332
SS
1229@item quit @r{[}@var{expression}@r{]}
1230@itemx q
1231To exit @value{GDBN}, use the @code{quit} command (abbreviated
1232@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1233do not supply @var{expression}, @value{GDBN} will terminate normally;
1234otherwise it will terminate using the result of @var{expression} as the
1235error code.
c906108c
SS
1236@end table
1237
1238@cindex interrupt
1239An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1240terminates the action of any @value{GDBN} command that is in progress and
1241returns to @value{GDBN} command level. It is safe to type the interrupt
1242character at any time because @value{GDBN} does not allow it to take effect
1243until a time when it is safe.
1244
c906108c
SS
1245If you have been using @value{GDBN} to control an attached process or
1246device, you can release it with the @code{detach} command
1247(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1248
6d2ebf8b 1249@node Shell Commands
c906108c
SS
1250@section Shell commands
1251
1252If you need to execute occasional shell commands during your
1253debugging session, there is no need to leave or suspend @value{GDBN}; you can
1254just use the @code{shell} command.
1255
1256@table @code
1257@kindex shell
1258@cindex shell escape
1259@item shell @var{command string}
1260Invoke a standard shell to execute @var{command string}.
c906108c 1261If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1262shell to run. Otherwise @value{GDBN} uses the default shell
1263(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1264@end table
1265
1266The utility @code{make} is often needed in development environments.
1267You do not have to use the @code{shell} command for this purpose in
1268@value{GDBN}:
1269
1270@table @code
1271@kindex make
1272@cindex calling make
1273@item make @var{make-args}
1274Execute the @code{make} program with the specified
1275arguments. This is equivalent to @samp{shell make @var{make-args}}.
1276@end table
1277
0fac0b41
DJ
1278@node Logging output
1279@section Logging output
1280@cindex logging @value{GDBN} output
9c16f35a 1281@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1282
1283You may want to save the output of @value{GDBN} commands to a file.
1284There are several commands to control @value{GDBN}'s logging.
1285
1286@table @code
1287@kindex set logging
1288@item set logging on
1289Enable logging.
1290@item set logging off
1291Disable logging.
9c16f35a 1292@cindex logging file name
0fac0b41
DJ
1293@item set logging file @var{file}
1294Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1295@item set logging overwrite [on|off]
1296By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1297you want @code{set logging on} to overwrite the logfile instead.
1298@item set logging redirect [on|off]
1299By default, @value{GDBN} output will go to both the terminal and the logfile.
1300Set @code{redirect} if you want output to go only to the log file.
1301@kindex show logging
1302@item show logging
1303Show the current values of the logging settings.
1304@end table
1305
6d2ebf8b 1306@node Commands
c906108c
SS
1307@chapter @value{GDBN} Commands
1308
1309You can abbreviate a @value{GDBN} command to the first few letters of the command
1310name, if that abbreviation is unambiguous; and you can repeat certain
1311@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1312key to get @value{GDBN} to fill out the rest of a word in a command (or to
1313show you the alternatives available, if there is more than one possibility).
1314
1315@menu
1316* Command Syntax:: How to give commands to @value{GDBN}
1317* Completion:: Command completion
1318* Help:: How to ask @value{GDBN} for help
1319@end menu
1320
6d2ebf8b 1321@node Command Syntax
c906108c
SS
1322@section Command syntax
1323
1324A @value{GDBN} command is a single line of input. There is no limit on
1325how long it can be. It starts with a command name, which is followed by
1326arguments whose meaning depends on the command name. For example, the
1327command @code{step} accepts an argument which is the number of times to
1328step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1329with no arguments. Some commands do not allow any arguments.
c906108c
SS
1330
1331@cindex abbreviation
1332@value{GDBN} command names may always be truncated if that abbreviation is
1333unambiguous. Other possible command abbreviations are listed in the
1334documentation for individual commands. In some cases, even ambiguous
1335abbreviations are allowed; for example, @code{s} is specially defined as
1336equivalent to @code{step} even though there are other commands whose
1337names start with @code{s}. You can test abbreviations by using them as
1338arguments to the @code{help} command.
1339
1340@cindex repeating commands
41afff9a 1341@kindex RET @r{(repeat last command)}
c906108c 1342A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1343repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1344will not repeat this way; these are commands whose unintentional
1345repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1346repeat. User-defined commands can disable this feature; see
1347@ref{Define, dont-repeat}.
c906108c
SS
1348
1349The @code{list} and @code{x} commands, when you repeat them with
1350@key{RET}, construct new arguments rather than repeating
1351exactly as typed. This permits easy scanning of source or memory.
1352
1353@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1354output, in a way similar to the common utility @code{more}
1355(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1356@key{RET} too many in this situation, @value{GDBN} disables command
1357repetition after any command that generates this sort of display.
1358
41afff9a 1359@kindex # @r{(a comment)}
c906108c
SS
1360@cindex comment
1361Any text from a @kbd{#} to the end of the line is a comment; it does
1362nothing. This is useful mainly in command files (@pxref{Command
1363Files,,Command files}).
1364
88118b3a
TT
1365@cindex repeating command sequences
1366@kindex C-o @r{(operate-and-get-next)}
1367The @kbd{C-o} binding is useful for repeating a complex sequence of
1368commands. This command accepts the current line, like @kbd{RET}, and
1369then fetches the next line relative to the current line from the history
1370for editing.
1371
6d2ebf8b 1372@node Completion
c906108c
SS
1373@section Command completion
1374
1375@cindex completion
1376@cindex word completion
1377@value{GDBN} can fill in the rest of a word in a command for you, if there is
1378only one possibility; it can also show you what the valid possibilities
1379are for the next word in a command, at any time. This works for @value{GDBN}
1380commands, @value{GDBN} subcommands, and the names of symbols in your program.
1381
1382Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1383of a word. If there is only one possibility, @value{GDBN} fills in the
1384word, and waits for you to finish the command (or press @key{RET} to
1385enter it). For example, if you type
1386
1387@c FIXME "@key" does not distinguish its argument sufficiently to permit
1388@c complete accuracy in these examples; space introduced for clarity.
1389@c If texinfo enhancements make it unnecessary, it would be nice to
1390@c replace " @key" by "@key" in the following...
474c8240 1391@smallexample
c906108c 1392(@value{GDBP}) info bre @key{TAB}
474c8240 1393@end smallexample
c906108c
SS
1394
1395@noindent
1396@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1397the only @code{info} subcommand beginning with @samp{bre}:
1398
474c8240 1399@smallexample
c906108c 1400(@value{GDBP}) info breakpoints
474c8240 1401@end smallexample
c906108c
SS
1402
1403@noindent
1404You can either press @key{RET} at this point, to run the @code{info
1405breakpoints} command, or backspace and enter something else, if
1406@samp{breakpoints} does not look like the command you expected. (If you
1407were sure you wanted @code{info breakpoints} in the first place, you
1408might as well just type @key{RET} immediately after @samp{info bre},
1409to exploit command abbreviations rather than command completion).
1410
1411If there is more than one possibility for the next word when you press
1412@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1413characters and try again, or just press @key{TAB} a second time;
1414@value{GDBN} displays all the possible completions for that word. For
1415example, you might want to set a breakpoint on a subroutine whose name
1416begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1417just sounds the bell. Typing @key{TAB} again displays all the
1418function names in your program that begin with those characters, for
1419example:
1420
474c8240 1421@smallexample
c906108c
SS
1422(@value{GDBP}) b make_ @key{TAB}
1423@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1424make_a_section_from_file make_environ
1425make_abs_section make_function_type
1426make_blockvector make_pointer_type
1427make_cleanup make_reference_type
c906108c
SS
1428make_command make_symbol_completion_list
1429(@value{GDBP}) b make_
474c8240 1430@end smallexample
c906108c
SS
1431
1432@noindent
1433After displaying the available possibilities, @value{GDBN} copies your
1434partial input (@samp{b make_} in the example) so you can finish the
1435command.
1436
1437If you just want to see the list of alternatives in the first place, you
b37052ae 1438can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1439means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1440key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1441one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1442
1443@cindex quotes in commands
1444@cindex completion of quoted strings
1445Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1446parentheses or other characters that @value{GDBN} normally excludes from
1447its notion of a word. To permit word completion to work in this
1448situation, you may enclose words in @code{'} (single quote marks) in
1449@value{GDBN} commands.
c906108c 1450
c906108c 1451The most likely situation where you might need this is in typing the
b37052ae
EZ
1452name of a C@t{++} function. This is because C@t{++} allows function
1453overloading (multiple definitions of the same function, distinguished
1454by argument type). For example, when you want to set a breakpoint you
1455may need to distinguish whether you mean the version of @code{name}
1456that takes an @code{int} parameter, @code{name(int)}, or the version
1457that takes a @code{float} parameter, @code{name(float)}. To use the
1458word-completion facilities in this situation, type a single quote
1459@code{'} at the beginning of the function name. This alerts
1460@value{GDBN} that it may need to consider more information than usual
1461when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1462
474c8240 1463@smallexample
96a2c332 1464(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1465bubble(double,double) bubble(int,int)
1466(@value{GDBP}) b 'bubble(
474c8240 1467@end smallexample
c906108c
SS
1468
1469In some cases, @value{GDBN} can tell that completing a name requires using
1470quotes. When this happens, @value{GDBN} inserts the quote for you (while
1471completing as much as it can) if you do not type the quote in the first
1472place:
1473
474c8240 1474@smallexample
c906108c
SS
1475(@value{GDBP}) b bub @key{TAB}
1476@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1477(@value{GDBP}) b 'bubble(
474c8240 1478@end smallexample
c906108c
SS
1479
1480@noindent
1481In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1482you have not yet started typing the argument list when you ask for
1483completion on an overloaded symbol.
1484
d4f3574e 1485For more information about overloaded functions, see @ref{C plus plus
b37052ae 1486expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1487overload-resolution off} to disable overload resolution;
b37052ae 1488see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1489
1490
6d2ebf8b 1491@node Help
c906108c
SS
1492@section Getting help
1493@cindex online documentation
1494@kindex help
1495
5d161b24 1496You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1497using the command @code{help}.
1498
1499@table @code
41afff9a 1500@kindex h @r{(@code{help})}
c906108c
SS
1501@item help
1502@itemx h
1503You can use @code{help} (abbreviated @code{h}) with no arguments to
1504display a short list of named classes of commands:
1505
1506@smallexample
1507(@value{GDBP}) help
1508List of classes of commands:
1509
2df3850c 1510aliases -- Aliases of other commands
c906108c 1511breakpoints -- Making program stop at certain points
2df3850c 1512data -- Examining data
c906108c 1513files -- Specifying and examining files
2df3850c
JM
1514internals -- Maintenance commands
1515obscure -- Obscure features
1516running -- Running the program
1517stack -- Examining the stack
c906108c
SS
1518status -- Status inquiries
1519support -- Support facilities
96a2c332
SS
1520tracepoints -- Tracing of program execution without@*
1521 stopping the program
c906108c 1522user-defined -- User-defined commands
c906108c 1523
5d161b24 1524Type "help" followed by a class name for a list of
c906108c 1525commands in that class.
5d161b24 1526Type "help" followed by command name for full
c906108c
SS
1527documentation.
1528Command name abbreviations are allowed if unambiguous.
1529(@value{GDBP})
1530@end smallexample
96a2c332 1531@c the above line break eliminates huge line overfull...
c906108c
SS
1532
1533@item help @var{class}
1534Using one of the general help classes as an argument, you can get a
1535list of the individual commands in that class. For example, here is the
1536help display for the class @code{status}:
1537
1538@smallexample
1539(@value{GDBP}) help status
1540Status inquiries.
1541
1542List of commands:
1543
1544@c Line break in "show" line falsifies real output, but needed
1545@c to fit in smallbook page size.
2df3850c
JM
1546info -- Generic command for showing things
1547 about the program being debugged
1548show -- Generic command for showing things
1549 about the debugger
c906108c 1550
5d161b24 1551Type "help" followed by command name for full
c906108c
SS
1552documentation.
1553Command name abbreviations are allowed if unambiguous.
1554(@value{GDBP})
1555@end smallexample
1556
1557@item help @var{command}
1558With a command name as @code{help} argument, @value{GDBN} displays a
1559short paragraph on how to use that command.
1560
6837a0a2
DB
1561@kindex apropos
1562@item apropos @var{args}
09d4efe1 1563The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2
DB
1564commands, and their documentation, for the regular expression specified in
1565@var{args}. It prints out all matches found. For example:
1566
1567@smallexample
1568apropos reload
1569@end smallexample
1570
b37052ae
EZ
1571@noindent
1572results in:
6837a0a2
DB
1573
1574@smallexample
6d2ebf8b
SS
1575@c @group
1576set symbol-reloading -- Set dynamic symbol table reloading
1577 multiple times in one run
1578show symbol-reloading -- Show dynamic symbol table reloading
1579 multiple times in one run
1580@c @end group
6837a0a2
DB
1581@end smallexample
1582
c906108c
SS
1583@kindex complete
1584@item complete @var{args}
1585The @code{complete @var{args}} command lists all the possible completions
1586for the beginning of a command. Use @var{args} to specify the beginning of the
1587command you want completed. For example:
1588
1589@smallexample
1590complete i
1591@end smallexample
1592
1593@noindent results in:
1594
1595@smallexample
1596@group
2df3850c
JM
1597if
1598ignore
c906108c
SS
1599info
1600inspect
c906108c
SS
1601@end group
1602@end smallexample
1603
1604@noindent This is intended for use by @sc{gnu} Emacs.
1605@end table
1606
1607In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1608and @code{show} to inquire about the state of your program, or the state
1609of @value{GDBN} itself. Each command supports many topics of inquiry; this
1610manual introduces each of them in the appropriate context. The listings
1611under @code{info} and under @code{show} in the Index point to
1612all the sub-commands. @xref{Index}.
1613
1614@c @group
1615@table @code
1616@kindex info
41afff9a 1617@kindex i @r{(@code{info})}
c906108c
SS
1618@item info
1619This command (abbreviated @code{i}) is for describing the state of your
1620program. For example, you can list the arguments given to your program
1621with @code{info args}, list the registers currently in use with @code{info
1622registers}, or list the breakpoints you have set with @code{info breakpoints}.
1623You can get a complete list of the @code{info} sub-commands with
1624@w{@code{help info}}.
1625
1626@kindex set
1627@item set
5d161b24 1628You can assign the result of an expression to an environment variable with
c906108c
SS
1629@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1630@code{set prompt $}.
1631
1632@kindex show
1633@item show
5d161b24 1634In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1635@value{GDBN} itself.
1636You can change most of the things you can @code{show}, by using the
1637related command @code{set}; for example, you can control what number
1638system is used for displays with @code{set radix}, or simply inquire
1639which is currently in use with @code{show radix}.
1640
1641@kindex info set
1642To display all the settable parameters and their current
1643values, you can use @code{show} with no arguments; you may also use
1644@code{info set}. Both commands produce the same display.
1645@c FIXME: "info set" violates the rule that "info" is for state of
1646@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1647@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1648@end table
1649@c @end group
1650
1651Here are three miscellaneous @code{show} subcommands, all of which are
1652exceptional in lacking corresponding @code{set} commands:
1653
1654@table @code
1655@kindex show version
9c16f35a 1656@cindex @value{GDBN} version number
c906108c
SS
1657@item show version
1658Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1659information in @value{GDBN} bug-reports. If multiple versions of
1660@value{GDBN} are in use at your site, you may need to determine which
1661version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1662commands are introduced, and old ones may wither away. Also, many
1663system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1664variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1665The version number is the same as the one announced when you start
1666@value{GDBN}.
c906108c
SS
1667
1668@kindex show copying
09d4efe1 1669@kindex info copying
9c16f35a 1670@cindex display @value{GDBN} copyright
c906108c 1671@item show copying
09d4efe1 1672@itemx info copying
c906108c
SS
1673Display information about permission for copying @value{GDBN}.
1674
1675@kindex show warranty
09d4efe1 1676@kindex info warranty
c906108c 1677@item show warranty
09d4efe1 1678@itemx info warranty
2df3850c 1679Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1680if your version of @value{GDBN} comes with one.
2df3850c 1681
c906108c
SS
1682@end table
1683
6d2ebf8b 1684@node Running
c906108c
SS
1685@chapter Running Programs Under @value{GDBN}
1686
1687When you run a program under @value{GDBN}, you must first generate
1688debugging information when you compile it.
7a292a7a
SS
1689
1690You may start @value{GDBN} with its arguments, if any, in an environment
1691of your choice. If you are doing native debugging, you may redirect
1692your program's input and output, debug an already running process, or
1693kill a child process.
c906108c
SS
1694
1695@menu
1696* Compilation:: Compiling for debugging
1697* Starting:: Starting your program
c906108c
SS
1698* Arguments:: Your program's arguments
1699* Environment:: Your program's environment
c906108c
SS
1700
1701* Working Directory:: Your program's working directory
1702* Input/Output:: Your program's input and output
1703* Attach:: Debugging an already-running process
1704* Kill Process:: Killing the child process
c906108c
SS
1705
1706* Threads:: Debugging programs with multiple threads
1707* Processes:: Debugging programs with multiple processes
1708@end menu
1709
6d2ebf8b 1710@node Compilation
c906108c
SS
1711@section Compiling for debugging
1712
1713In order to debug a program effectively, you need to generate
1714debugging information when you compile it. This debugging information
1715is stored in the object file; it describes the data type of each
1716variable or function and the correspondence between source line numbers
1717and addresses in the executable code.
1718
1719To request debugging information, specify the @samp{-g} option when you run
1720the compiler.
1721
514c4d71
EZ
1722Programs that are to be shipped to your customers are compiled with
1723optimizations, using the @samp{-O} compiler option. However, many
1724compilers are unable to handle the @samp{-g} and @samp{-O} options
1725together. Using those compilers, you cannot generate optimized
c906108c
SS
1726executables containing debugging information.
1727
514c4d71 1728@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1729without @samp{-O}, making it possible to debug optimized code. We
1730recommend that you @emph{always} use @samp{-g} whenever you compile a
1731program. You may think your program is correct, but there is no sense
1732in pushing your luck.
c906108c
SS
1733
1734@cindex optimized code, debugging
1735@cindex debugging optimized code
1736When you debug a program compiled with @samp{-g -O}, remember that the
1737optimizer is rearranging your code; the debugger shows you what is
1738really there. Do not be too surprised when the execution path does not
1739exactly match your source file! An extreme example: if you define a
1740variable, but never use it, @value{GDBN} never sees that
1741variable---because the compiler optimizes it out of existence.
1742
1743Some things do not work as well with @samp{-g -O} as with just
1744@samp{-g}, particularly on machines with instruction scheduling. If in
1745doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1746please report it to us as a bug (including a test case!).
15387254 1747@xref{Variables}, for more information about debugging optimized code.
c906108c
SS
1748
1749Older versions of the @sc{gnu} C compiler permitted a variant option
1750@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1751format; if your @sc{gnu} C compiler has this option, do not use it.
1752
514c4d71
EZ
1753@value{GDBN} knows about preprocessor macros and can show you their
1754expansion (@pxref{Macros}). Most compilers do not include information
1755about preprocessor macros in the debugging information if you specify
1756the @option{-g} flag alone, because this information is rather large.
1757Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1758provides macro information if you specify the options
1759@option{-gdwarf-2} and @option{-g3}; the former option requests
1760debugging information in the Dwarf 2 format, and the latter requests
1761``extra information''. In the future, we hope to find more compact
1762ways to represent macro information, so that it can be included with
1763@option{-g} alone.
1764
c906108c 1765@need 2000
6d2ebf8b 1766@node Starting
c906108c
SS
1767@section Starting your program
1768@cindex starting
1769@cindex running
1770
1771@table @code
1772@kindex run
41afff9a 1773@kindex r @r{(@code{run})}
c906108c
SS
1774@item run
1775@itemx r
7a292a7a
SS
1776Use the @code{run} command to start your program under @value{GDBN}.
1777You must first specify the program name (except on VxWorks) with an
1778argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1779@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1780(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1781
1782@end table
1783
c906108c
SS
1784If you are running your program in an execution environment that
1785supports processes, @code{run} creates an inferior process and makes
1786that process run your program. (In environments without processes,
1787@code{run} jumps to the start of your program.)
1788
1789The execution of a program is affected by certain information it
1790receives from its superior. @value{GDBN} provides ways to specify this
1791information, which you must do @emph{before} starting your program. (You
1792can change it after starting your program, but such changes only affect
1793your program the next time you start it.) This information may be
1794divided into four categories:
1795
1796@table @asis
1797@item The @emph{arguments.}
1798Specify the arguments to give your program as the arguments of the
1799@code{run} command. If a shell is available on your target, the shell
1800is used to pass the arguments, so that you may use normal conventions
1801(such as wildcard expansion or variable substitution) in describing
1802the arguments.
1803In Unix systems, you can control which shell is used with the
1804@code{SHELL} environment variable.
1805@xref{Arguments, ,Your program's arguments}.
1806
1807@item The @emph{environment.}
1808Your program normally inherits its environment from @value{GDBN}, but you can
1809use the @value{GDBN} commands @code{set environment} and @code{unset
1810environment} to change parts of the environment that affect
1811your program. @xref{Environment, ,Your program's environment}.
1812
1813@item The @emph{working directory.}
1814Your program inherits its working directory from @value{GDBN}. You can set
1815the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1816@xref{Working Directory, ,Your program's working directory}.
1817
1818@item The @emph{standard input and output.}
1819Your program normally uses the same device for standard input and
1820standard output as @value{GDBN} is using. You can redirect input and output
1821in the @code{run} command line, or you can use the @code{tty} command to
1822set a different device for your program.
1823@xref{Input/Output, ,Your program's input and output}.
1824
1825@cindex pipes
1826@emph{Warning:} While input and output redirection work, you cannot use
1827pipes to pass the output of the program you are debugging to another
1828program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1829wrong program.
1830@end table
c906108c
SS
1831
1832When you issue the @code{run} command, your program begins to execute
1833immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1834of how to arrange for your program to stop. Once your program has
1835stopped, you may call functions in your program, using the @code{print}
1836or @code{call} commands. @xref{Data, ,Examining Data}.
1837
1838If the modification time of your symbol file has changed since the last
1839time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1840table, and reads it again. When it does this, @value{GDBN} tries to retain
1841your current breakpoints.
1842
4e8b0763
JB
1843@table @code
1844@kindex start
1845@item start
1846@cindex run to main procedure
1847The name of the main procedure can vary from language to language.
1848With C or C@t{++}, the main procedure name is always @code{main}, but
1849other languages such as Ada do not require a specific name for their
1850main procedure. The debugger provides a convenient way to start the
1851execution of the program and to stop at the beginning of the main
1852procedure, depending on the language used.
1853
1854The @samp{start} command does the equivalent of setting a temporary
1855breakpoint at the beginning of the main procedure and then invoking
1856the @samp{run} command.
1857
f018e82f
EZ
1858@cindex elaboration phase
1859Some programs contain an @dfn{elaboration} phase where some startup code is
1860executed before the main procedure is called. This depends on the
1861languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1862constructors for static and global objects are executed before
1863@code{main} is called. It is therefore possible that the debugger stops
1864before reaching the main procedure. However, the temporary breakpoint
1865will remain to halt execution.
1866
1867Specify the arguments to give to your program as arguments to the
1868@samp{start} command. These arguments will be given verbatim to the
1869underlying @samp{run} command. Note that the same arguments will be
1870reused if no argument is provided during subsequent calls to
1871@samp{start} or @samp{run}.
1872
1873It is sometimes necessary to debug the program during elaboration. In
1874these cases, using the @code{start} command would stop the execution of
1875your program too late, as the program would have already completed the
1876elaboration phase. Under these circumstances, insert breakpoints in your
1877elaboration code before running your program.
1878@end table
1879
6d2ebf8b 1880@node Arguments
c906108c
SS
1881@section Your program's arguments
1882
1883@cindex arguments (to your program)
1884The arguments to your program can be specified by the arguments of the
5d161b24 1885@code{run} command.
c906108c
SS
1886They are passed to a shell, which expands wildcard characters and
1887performs redirection of I/O, and thence to your program. Your
1888@code{SHELL} environment variable (if it exists) specifies what shell
1889@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1890the default shell (@file{/bin/sh} on Unix).
1891
1892On non-Unix systems, the program is usually invoked directly by
1893@value{GDBN}, which emulates I/O redirection via the appropriate system
1894calls, and the wildcard characters are expanded by the startup code of
1895the program, not by the shell.
c906108c
SS
1896
1897@code{run} with no arguments uses the same arguments used by the previous
1898@code{run}, or those set by the @code{set args} command.
1899
c906108c 1900@table @code
41afff9a 1901@kindex set args
c906108c
SS
1902@item set args
1903Specify the arguments to be used the next time your program is run. If
1904@code{set args} has no arguments, @code{run} executes your program
1905with no arguments. Once you have run your program with arguments,
1906using @code{set args} before the next @code{run} is the only way to run
1907it again without arguments.
1908
1909@kindex show args
1910@item show args
1911Show the arguments to give your program when it is started.
1912@end table
1913
6d2ebf8b 1914@node Environment
c906108c
SS
1915@section Your program's environment
1916
1917@cindex environment (of your program)
1918The @dfn{environment} consists of a set of environment variables and
1919their values. Environment variables conventionally record such things as
1920your user name, your home directory, your terminal type, and your search
1921path for programs to run. Usually you set up environment variables with
1922the shell and they are inherited by all the other programs you run. When
1923debugging, it can be useful to try running your program with a modified
1924environment without having to start @value{GDBN} over again.
1925
1926@table @code
1927@kindex path
1928@item path @var{directory}
1929Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1930(the search path for executables) that will be passed to your program.
1931The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1932You may specify several directory names, separated by whitespace or by a
1933system-dependent separator character (@samp{:} on Unix, @samp{;} on
1934MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1935is moved to the front, so it is searched sooner.
c906108c
SS
1936
1937You can use the string @samp{$cwd} to refer to whatever is the current
1938working directory at the time @value{GDBN} searches the path. If you
1939use @samp{.} instead, it refers to the directory where you executed the
1940@code{path} command. @value{GDBN} replaces @samp{.} in the
1941@var{directory} argument (with the current path) before adding
1942@var{directory} to the search path.
1943@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1944@c document that, since repeating it would be a no-op.
1945
1946@kindex show paths
1947@item show paths
1948Display the list of search paths for executables (the @code{PATH}
1949environment variable).
1950
1951@kindex show environment
1952@item show environment @r{[}@var{varname}@r{]}
1953Print the value of environment variable @var{varname} to be given to
1954your program when it starts. If you do not supply @var{varname},
1955print the names and values of all environment variables to be given to
1956your program. You can abbreviate @code{environment} as @code{env}.
1957
1958@kindex set environment
53a5351d 1959@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1960Set environment variable @var{varname} to @var{value}. The value
1961changes for your program only, not for @value{GDBN} itself. @var{value} may
1962be any string; the values of environment variables are just strings, and
1963any interpretation is supplied by your program itself. The @var{value}
1964parameter is optional; if it is eliminated, the variable is set to a
1965null value.
1966@c "any string" here does not include leading, trailing
1967@c blanks. Gnu asks: does anyone care?
1968
1969For example, this command:
1970
474c8240 1971@smallexample
c906108c 1972set env USER = foo
474c8240 1973@end smallexample
c906108c
SS
1974
1975@noindent
d4f3574e 1976tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1977@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1978are not actually required.)
1979
1980@kindex unset environment
1981@item unset environment @var{varname}
1982Remove variable @var{varname} from the environment to be passed to your
1983program. This is different from @samp{set env @var{varname} =};
1984@code{unset environment} removes the variable from the environment,
1985rather than assigning it an empty value.
1986@end table
1987
d4f3574e
SS
1988@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1989the shell indicated
c906108c
SS
1990by your @code{SHELL} environment variable if it exists (or
1991@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1992that runs an initialization file---such as @file{.cshrc} for C-shell, or
1993@file{.bashrc} for BASH---any variables you set in that file affect
1994your program. You may wish to move setting of environment variables to
1995files that are only run when you sign on, such as @file{.login} or
1996@file{.profile}.
1997
6d2ebf8b 1998@node Working Directory
c906108c
SS
1999@section Your program's working directory
2000
2001@cindex working directory (of your program)
2002Each time you start your program with @code{run}, it inherits its
2003working directory from the current working directory of @value{GDBN}.
2004The @value{GDBN} working directory is initially whatever it inherited
2005from its parent process (typically the shell), but you can specify a new
2006working directory in @value{GDBN} with the @code{cd} command.
2007
2008The @value{GDBN} working directory also serves as a default for the commands
2009that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
2010specify files}.
2011
2012@table @code
2013@kindex cd
721c2651 2014@cindex change working directory
c906108c
SS
2015@item cd @var{directory}
2016Set the @value{GDBN} working directory to @var{directory}.
2017
2018@kindex pwd
2019@item pwd
2020Print the @value{GDBN} working directory.
2021@end table
2022
60bf7e09
EZ
2023It is generally impossible to find the current working directory of
2024the process being debugged (since a program can change its directory
2025during its run). If you work on a system where @value{GDBN} is
2026configured with the @file{/proc} support, you can use the @code{info
2027proc} command (@pxref{SVR4 Process Information}) to find out the
2028current working directory of the debuggee.
2029
6d2ebf8b 2030@node Input/Output
c906108c
SS
2031@section Your program's input and output
2032
2033@cindex redirection
2034@cindex i/o
2035@cindex terminal
2036By default, the program you run under @value{GDBN} does input and output to
5d161b24 2037the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2038to its own terminal modes to interact with you, but it records the terminal
2039modes your program was using and switches back to them when you continue
2040running your program.
2041
2042@table @code
2043@kindex info terminal
2044@item info terminal
2045Displays information recorded by @value{GDBN} about the terminal modes your
2046program is using.
2047@end table
2048
2049You can redirect your program's input and/or output using shell
2050redirection with the @code{run} command. For example,
2051
474c8240 2052@smallexample
c906108c 2053run > outfile
474c8240 2054@end smallexample
c906108c
SS
2055
2056@noindent
2057starts your program, diverting its output to the file @file{outfile}.
2058
2059@kindex tty
2060@cindex controlling terminal
2061Another way to specify where your program should do input and output is
2062with the @code{tty} command. This command accepts a file name as
2063argument, and causes this file to be the default for future @code{run}
2064commands. It also resets the controlling terminal for the child
2065process, for future @code{run} commands. For example,
2066
474c8240 2067@smallexample
c906108c 2068tty /dev/ttyb
474c8240 2069@end smallexample
c906108c
SS
2070
2071@noindent
2072directs that processes started with subsequent @code{run} commands
2073default to do input and output on the terminal @file{/dev/ttyb} and have
2074that as their controlling terminal.
2075
2076An explicit redirection in @code{run} overrides the @code{tty} command's
2077effect on the input/output device, but not its effect on the controlling
2078terminal.
2079
2080When you use the @code{tty} command or redirect input in the @code{run}
2081command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2082for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2083for @code{set inferior-tty}.
2084
2085@cindex inferior tty
2086@cindex set inferior controlling terminal
2087You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2088display the name of the terminal that will be used for future runs of your
2089program.
2090
2091@table @code
2092@item set inferior-tty /dev/ttyb
2093@kindex set inferior-tty
2094Set the tty for the program being debugged to /dev/ttyb.
2095
2096@item show inferior-tty
2097@kindex show inferior-tty
2098Show the current tty for the program being debugged.
2099@end table
c906108c 2100
6d2ebf8b 2101@node Attach
c906108c
SS
2102@section Debugging an already-running process
2103@kindex attach
2104@cindex attach
2105
2106@table @code
2107@item attach @var{process-id}
2108This command attaches to a running process---one that was started
2109outside @value{GDBN}. (@code{info files} shows your active
2110targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2111find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2112or with the @samp{jobs -l} shell command.
2113
2114@code{attach} does not repeat if you press @key{RET} a second time after
2115executing the command.
2116@end table
2117
2118To use @code{attach}, your program must be running in an environment
2119which supports processes; for example, @code{attach} does not work for
2120programs on bare-board targets that lack an operating system. You must
2121also have permission to send the process a signal.
2122
2123When you use @code{attach}, the debugger finds the program running in
2124the process first by looking in the current working directory, then (if
2125the program is not found) by using the source file search path
2126(@pxref{Source Path, ,Specifying source directories}). You can also use
2127the @code{file} command to load the program. @xref{Files, ,Commands to
2128Specify Files}.
2129
2130The first thing @value{GDBN} does after arranging to debug the specified
2131process is to stop it. You can examine and modify an attached process
53a5351d
JM
2132with all the @value{GDBN} commands that are ordinarily available when
2133you start processes with @code{run}. You can insert breakpoints; you
2134can step and continue; you can modify storage. If you would rather the
2135process continue running, you may use the @code{continue} command after
c906108c
SS
2136attaching @value{GDBN} to the process.
2137
2138@table @code
2139@kindex detach
2140@item detach
2141When you have finished debugging the attached process, you can use the
2142@code{detach} command to release it from @value{GDBN} control. Detaching
2143the process continues its execution. After the @code{detach} command,
2144that process and @value{GDBN} become completely independent once more, and you
2145are ready to @code{attach} another process or start one with @code{run}.
2146@code{detach} does not repeat if you press @key{RET} again after
2147executing the command.
2148@end table
2149
2150If you exit @value{GDBN} or use the @code{run} command while you have an
2151attached process, you kill that process. By default, @value{GDBN} asks
2152for confirmation if you try to do either of these things; you can
2153control whether or not you need to confirm by using the @code{set
2154confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2155messages}).
2156
6d2ebf8b 2157@node Kill Process
c906108c 2158@section Killing the child process
c906108c
SS
2159
2160@table @code
2161@kindex kill
2162@item kill
2163Kill the child process in which your program is running under @value{GDBN}.
2164@end table
2165
2166This command is useful if you wish to debug a core dump instead of a
2167running process. @value{GDBN} ignores any core dump file while your program
2168is running.
2169
2170On some operating systems, a program cannot be executed outside @value{GDBN}
2171while you have breakpoints set on it inside @value{GDBN}. You can use the
2172@code{kill} command in this situation to permit running your program
2173outside the debugger.
2174
2175The @code{kill} command is also useful if you wish to recompile and
2176relink your program, since on many systems it is impossible to modify an
2177executable file while it is running in a process. In this case, when you
2178next type @code{run}, @value{GDBN} notices that the file has changed, and
2179reads the symbol table again (while trying to preserve your current
2180breakpoint settings).
2181
6d2ebf8b 2182@node Threads
c906108c 2183@section Debugging programs with multiple threads
c906108c
SS
2184
2185@cindex threads of execution
2186@cindex multiple threads
2187@cindex switching threads
2188In some operating systems, such as HP-UX and Solaris, a single program
2189may have more than one @dfn{thread} of execution. The precise semantics
2190of threads differ from one operating system to another, but in general
2191the threads of a single program are akin to multiple processes---except
2192that they share one address space (that is, they can all examine and
2193modify the same variables). On the other hand, each thread has its own
2194registers and execution stack, and perhaps private memory.
2195
2196@value{GDBN} provides these facilities for debugging multi-thread
2197programs:
2198
2199@itemize @bullet
2200@item automatic notification of new threads
2201@item @samp{thread @var{threadno}}, a command to switch among threads
2202@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2203@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2204a command to apply a command to a list of threads
2205@item thread-specific breakpoints
2206@end itemize
2207
c906108c
SS
2208@quotation
2209@emph{Warning:} These facilities are not yet available on every
2210@value{GDBN} configuration where the operating system supports threads.
2211If your @value{GDBN} does not support threads, these commands have no
2212effect. For example, a system without thread support shows no output
2213from @samp{info threads}, and always rejects the @code{thread} command,
2214like this:
2215
2216@smallexample
2217(@value{GDBP}) info threads
2218(@value{GDBP}) thread 1
2219Thread ID 1 not known. Use the "info threads" command to
2220see the IDs of currently known threads.
2221@end smallexample
2222@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2223@c doesn't support threads"?
2224@end quotation
c906108c
SS
2225
2226@cindex focus of debugging
2227@cindex current thread
2228The @value{GDBN} thread debugging facility allows you to observe all
2229threads while your program runs---but whenever @value{GDBN} takes
2230control, one thread in particular is always the focus of debugging.
2231This thread is called the @dfn{current thread}. Debugging commands show
2232program information from the perspective of the current thread.
2233
41afff9a 2234@cindex @code{New} @var{systag} message
c906108c
SS
2235@cindex thread identifier (system)
2236@c FIXME-implementors!! It would be more helpful if the [New...] message
2237@c included GDB's numeric thread handle, so you could just go to that
2238@c thread without first checking `info threads'.
2239Whenever @value{GDBN} detects a new thread in your program, it displays
2240the target system's identification for the thread with a message in the
2241form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2242whose form varies depending on the particular system. For example, on
2243LynxOS, you might see
2244
474c8240 2245@smallexample
c906108c 2246[New process 35 thread 27]
474c8240 2247@end smallexample
c906108c
SS
2248
2249@noindent
2250when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2251the @var{systag} is simply something like @samp{process 368}, with no
2252further qualifier.
2253
2254@c FIXME!! (1) Does the [New...] message appear even for the very first
2255@c thread of a program, or does it only appear for the
6ca652b0 2256@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2257@c program?
2258@c (2) *Is* there necessarily a first thread always? Or do some
2259@c multithread systems permit starting a program with multiple
5d161b24 2260@c threads ab initio?
c906108c
SS
2261
2262@cindex thread number
2263@cindex thread identifier (GDB)
2264For debugging purposes, @value{GDBN} associates its own thread
2265number---always a single integer---with each thread in your program.
2266
2267@table @code
2268@kindex info threads
2269@item info threads
2270Display a summary of all threads currently in your
2271program. @value{GDBN} displays for each thread (in this order):
2272
2273@enumerate
09d4efe1
EZ
2274@item
2275the thread number assigned by @value{GDBN}
c906108c 2276
09d4efe1
EZ
2277@item
2278the target system's thread identifier (@var{systag})
c906108c 2279
09d4efe1
EZ
2280@item
2281the current stack frame summary for that thread
c906108c
SS
2282@end enumerate
2283
2284@noindent
2285An asterisk @samp{*} to the left of the @value{GDBN} thread number
2286indicates the current thread.
2287
5d161b24 2288For example,
c906108c
SS
2289@end table
2290@c end table here to get a little more width for example
2291
2292@smallexample
2293(@value{GDBP}) info threads
2294 3 process 35 thread 27 0x34e5 in sigpause ()
2295 2 process 35 thread 23 0x34e5 in sigpause ()
2296* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2297 at threadtest.c:68
2298@end smallexample
53a5351d
JM
2299
2300On HP-UX systems:
c906108c 2301
4644b6e3
EZ
2302@cindex debugging multithreaded programs (on HP-UX)
2303@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2304For debugging purposes, @value{GDBN} associates its own thread
2305number---a small integer assigned in thread-creation order---with each
2306thread in your program.
2307
41afff9a
EZ
2308@cindex @code{New} @var{systag} message, on HP-UX
2309@cindex thread identifier (system), on HP-UX
c906108c
SS
2310@c FIXME-implementors!! It would be more helpful if the [New...] message
2311@c included GDB's numeric thread handle, so you could just go to that
2312@c thread without first checking `info threads'.
2313Whenever @value{GDBN} detects a new thread in your program, it displays
2314both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2315form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2316whose form varies depending on the particular system. For example, on
2317HP-UX, you see
2318
474c8240 2319@smallexample
c906108c 2320[New thread 2 (system thread 26594)]
474c8240 2321@end smallexample
c906108c
SS
2322
2323@noindent
5d161b24 2324when @value{GDBN} notices a new thread.
c906108c
SS
2325
2326@table @code
4644b6e3 2327@kindex info threads (HP-UX)
c906108c
SS
2328@item info threads
2329Display a summary of all threads currently in your
2330program. @value{GDBN} displays for each thread (in this order):
2331
2332@enumerate
2333@item the thread number assigned by @value{GDBN}
2334
2335@item the target system's thread identifier (@var{systag})
2336
2337@item the current stack frame summary for that thread
2338@end enumerate
2339
2340@noindent
2341An asterisk @samp{*} to the left of the @value{GDBN} thread number
2342indicates the current thread.
2343
5d161b24 2344For example,
c906108c
SS
2345@end table
2346@c end table here to get a little more width for example
2347
474c8240 2348@smallexample
c906108c 2349(@value{GDBP}) info threads
6d2ebf8b
SS
2350 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2351 at quicksort.c:137
2352 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2353 from /usr/lib/libc.2
2354 1 system thread 27905 0x7b003498 in _brk () \@*
2355 from /usr/lib/libc.2
474c8240 2356@end smallexample
c906108c 2357
c45da7e6
EZ
2358On Solaris, you can display more information about user threads with a
2359Solaris-specific command:
2360
2361@table @code
2362@item maint info sol-threads
2363@kindex maint info sol-threads
2364@cindex thread info (Solaris)
2365Display info on Solaris user threads.
2366@end table
2367
c906108c
SS
2368@table @code
2369@kindex thread @var{threadno}
2370@item thread @var{threadno}
2371Make thread number @var{threadno} the current thread. The command
2372argument @var{threadno} is the internal @value{GDBN} thread number, as
2373shown in the first field of the @samp{info threads} display.
2374@value{GDBN} responds by displaying the system identifier of the thread
2375you selected, and its current stack frame summary:
2376
2377@smallexample
2378@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2379(@value{GDBP}) thread 2
c906108c 2380[Switching to process 35 thread 23]
c906108c
SS
23810x34e5 in sigpause ()
2382@end smallexample
2383
2384@noindent
2385As with the @samp{[New @dots{}]} message, the form of the text after
2386@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2387threads.
c906108c 2388
9c16f35a 2389@kindex thread apply
638ac427 2390@cindex apply command to several threads
c906108c
SS
2391@item thread apply [@var{threadno}] [@var{all}] @var{args}
2392The @code{thread apply} command allows you to apply a command to one or
2393more threads. Specify the numbers of the threads that you want affected
2394with the command argument @var{threadno}. @var{threadno} is the internal
2395@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2396threads} display. To apply a command to all threads, use
2397@code{thread apply all} @var{args}.
c906108c
SS
2398@end table
2399
2400@cindex automatic thread selection
2401@cindex switching threads automatically
2402@cindex threads, automatic switching
2403Whenever @value{GDBN} stops your program, due to a breakpoint or a
2404signal, it automatically selects the thread where that breakpoint or
2405signal happened. @value{GDBN} alerts you to the context switch with a
2406message of the form @samp{[Switching to @var{systag}]} to identify the
2407thread.
2408
2409@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2410more information about how @value{GDBN} behaves when you stop and start
2411programs with multiple threads.
2412
2413@xref{Set Watchpoints,,Setting watchpoints}, for information about
2414watchpoints in programs with multiple threads.
c906108c 2415
6d2ebf8b 2416@node Processes
c906108c
SS
2417@section Debugging programs with multiple processes
2418
2419@cindex fork, debugging programs which call
2420@cindex multiple processes
2421@cindex processes, multiple
53a5351d
JM
2422On most systems, @value{GDBN} has no special support for debugging
2423programs which create additional processes using the @code{fork}
2424function. When a program forks, @value{GDBN} will continue to debug the
2425parent process and the child process will run unimpeded. If you have
2426set a breakpoint in any code which the child then executes, the child
2427will get a @code{SIGTRAP} signal which (unless it catches the signal)
2428will cause it to terminate.
c906108c
SS
2429
2430However, if you want to debug the child process there is a workaround
2431which isn't too painful. Put a call to @code{sleep} in the code which
2432the child process executes after the fork. It may be useful to sleep
2433only if a certain environment variable is set, or a certain file exists,
2434so that the delay need not occur when you don't want to run @value{GDBN}
2435on the child. While the child is sleeping, use the @code{ps} program to
2436get its process ID. Then tell @value{GDBN} (a new invocation of
2437@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2438the child process (@pxref{Attach}). From that point on you can debug
c906108c 2439the child process just like any other process which you attached to.
c906108c 2440
b51970ac
DJ
2441On some systems, @value{GDBN} provides support for debugging programs that
2442create additional processes using the @code{fork} or @code{vfork} functions.
2443Currently, the only platforms with this feature are HP-UX (11.x and later
2444only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2445
2446By default, when a program forks, @value{GDBN} will continue to debug
2447the parent process and the child process will run unimpeded.
2448
2449If you want to follow the child process instead of the parent process,
2450use the command @w{@code{set follow-fork-mode}}.
2451
2452@table @code
2453@kindex set follow-fork-mode
2454@item set follow-fork-mode @var{mode}
2455Set the debugger response to a program call of @code{fork} or
2456@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 2457process. The @var{mode} argument can be:
c906108c
SS
2458
2459@table @code
2460@item parent
2461The original process is debugged after a fork. The child process runs
2df3850c 2462unimpeded. This is the default.
c906108c
SS
2463
2464@item child
2465The new process is debugged after a fork. The parent process runs
2466unimpeded.
2467
c906108c
SS
2468@end table
2469
9c16f35a 2470@kindex show follow-fork-mode
c906108c 2471@item show follow-fork-mode
2df3850c 2472Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2473@end table
2474
2475If you ask to debug a child process and a @code{vfork} is followed by an
2476@code{exec}, @value{GDBN} executes the new target up to the first
2477breakpoint in the new target. If you have a breakpoint set on
2478@code{main} in your original program, the breakpoint will also be set on
2479the child process's @code{main}.
2480
2481When a child process is spawned by @code{vfork}, you cannot debug the
2482child or parent until an @code{exec} call completes.
2483
2484If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2485call executes, the new target restarts. To restart the parent process,
2486use the @code{file} command with the parent executable name as its
2487argument.
2488
2489You can use the @code{catch} command to make @value{GDBN} stop whenever
2490a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2491Catchpoints, ,Setting catchpoints}.
c906108c 2492
6d2ebf8b 2493@node Stopping
c906108c
SS
2494@chapter Stopping and Continuing
2495
2496The principal purposes of using a debugger are so that you can stop your
2497program before it terminates; or so that, if your program runs into
2498trouble, you can investigate and find out why.
2499
7a292a7a
SS
2500Inside @value{GDBN}, your program may stop for any of several reasons,
2501such as a signal, a breakpoint, or reaching a new line after a
2502@value{GDBN} command such as @code{step}. You may then examine and
2503change variables, set new breakpoints or remove old ones, and then
2504continue execution. Usually, the messages shown by @value{GDBN} provide
2505ample explanation of the status of your program---but you can also
2506explicitly request this information at any time.
c906108c
SS
2507
2508@table @code
2509@kindex info program
2510@item info program
2511Display information about the status of your program: whether it is
7a292a7a 2512running or not, what process it is, and why it stopped.
c906108c
SS
2513@end table
2514
2515@menu
2516* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2517* Continuing and Stepping:: Resuming execution
c906108c 2518* Signals:: Signals
c906108c 2519* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2520@end menu
2521
6d2ebf8b 2522@node Breakpoints
c906108c
SS
2523@section Breakpoints, watchpoints, and catchpoints
2524
2525@cindex breakpoints
2526A @dfn{breakpoint} makes your program stop whenever a certain point in
2527the program is reached. For each breakpoint, you can add conditions to
2528control in finer detail whether your program stops. You can set
2529breakpoints with the @code{break} command and its variants (@pxref{Set
2530Breaks, ,Setting breakpoints}), to specify the place where your program
2531should stop by line number, function name or exact address in the
2532program.
2533
09d4efe1
EZ
2534On some systems, you can set breakpoints in shared libraries before
2535the executable is run. There is a minor limitation on HP-UX systems:
2536you must wait until the executable is run in order to set breakpoints
2537in shared library routines that are not called directly by the program
2538(for example, routines that are arguments in a @code{pthread_create}
2539call).
c906108c
SS
2540
2541@cindex watchpoints
2542@cindex memory tracing
2543@cindex breakpoint on memory address
2544@cindex breakpoint on variable modification
2545A @dfn{watchpoint} is a special breakpoint that stops your program
2546when the value of an expression changes. You must use a different
2547command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2548watchpoints}), but aside from that, you can manage a watchpoint like
2549any other breakpoint: you enable, disable, and delete both breakpoints
2550and watchpoints using the same commands.
2551
2552You can arrange to have values from your program displayed automatically
2553whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2554Automatic display}.
2555
2556@cindex catchpoints
2557@cindex breakpoint on events
2558A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2559when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2560exception or the loading of a library. As with watchpoints, you use a
2561different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2562catchpoints}), but aside from that, you can manage a catchpoint like any
2563other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2564@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2565
2566@cindex breakpoint numbers
2567@cindex numbers for breakpoints
2568@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2569catchpoint when you create it; these numbers are successive integers
2570starting with one. In many of the commands for controlling various
2571features of breakpoints you use the breakpoint number to say which
2572breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2573@dfn{disabled}; if disabled, it has no effect on your program until you
2574enable it again.
2575
c5394b80
JM
2576@cindex breakpoint ranges
2577@cindex ranges of breakpoints
2578Some @value{GDBN} commands accept a range of breakpoints on which to
2579operate. A breakpoint range is either a single breakpoint number, like
2580@samp{5}, or two such numbers, in increasing order, separated by a
2581hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2582all breakpoint in that range are operated on.
2583
c906108c
SS
2584@menu
2585* Set Breaks:: Setting breakpoints
2586* Set Watchpoints:: Setting watchpoints
2587* Set Catchpoints:: Setting catchpoints
2588* Delete Breaks:: Deleting breakpoints
2589* Disabling:: Disabling breakpoints
2590* Conditions:: Break conditions
2591* Break Commands:: Breakpoint command lists
c906108c 2592* Breakpoint Menus:: Breakpoint menus
d4f3574e 2593* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2594* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2595@end menu
2596
6d2ebf8b 2597@node Set Breaks
c906108c
SS
2598@subsection Setting breakpoints
2599
5d161b24 2600@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2601@c consider in particular declaration with/without initialization.
2602@c
2603@c FIXME 2 is there stuff on this already? break at fun start, already init?
2604
2605@kindex break
41afff9a
EZ
2606@kindex b @r{(@code{break})}
2607@vindex $bpnum@r{, convenience variable}
c906108c
SS
2608@cindex latest breakpoint
2609Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2610@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2611number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2612Vars,, Convenience variables}, for a discussion of what you can do with
2613convenience variables.
2614
2615You have several ways to say where the breakpoint should go.
2616
2617@table @code
2618@item break @var{function}
5d161b24 2619Set a breakpoint at entry to function @var{function}.
c906108c 2620When using source languages that permit overloading of symbols, such as
b37052ae 2621C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2622@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2623
2624@item break +@var{offset}
2625@itemx break -@var{offset}
2626Set a breakpoint some number of lines forward or back from the position
d4f3574e 2627at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2628(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2629
2630@item break @var{linenum}
2631Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2632The current source file is the last file whose source text was printed.
2633The breakpoint will stop your program just before it executes any of the
c906108c
SS
2634code on that line.
2635
2636@item break @var{filename}:@var{linenum}
2637Set a breakpoint at line @var{linenum} in source file @var{filename}.
2638
2639@item break @var{filename}:@var{function}
2640Set a breakpoint at entry to function @var{function} found in file
2641@var{filename}. Specifying a file name as well as a function name is
2642superfluous except when multiple files contain similarly named
2643functions.
2644
2645@item break *@var{address}
2646Set a breakpoint at address @var{address}. You can use this to set
2647breakpoints in parts of your program which do not have debugging
2648information or source files.
2649
2650@item break
2651When called without any arguments, @code{break} sets a breakpoint at
2652the next instruction to be executed in the selected stack frame
2653(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2654innermost, this makes your program stop as soon as control
2655returns to that frame. This is similar to the effect of a
2656@code{finish} command in the frame inside the selected frame---except
2657that @code{finish} does not leave an active breakpoint. If you use
2658@code{break} without an argument in the innermost frame, @value{GDBN} stops
2659the next time it reaches the current location; this may be useful
2660inside loops.
2661
2662@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2663least one instruction has been executed. If it did not do this, you
2664would be unable to proceed past a breakpoint without first disabling the
2665breakpoint. This rule applies whether or not the breakpoint already
2666existed when your program stopped.
2667
2668@item break @dots{} if @var{cond}
2669Set a breakpoint with condition @var{cond}; evaluate the expression
2670@var{cond} each time the breakpoint is reached, and stop only if the
2671value is nonzero---that is, if @var{cond} evaluates as true.
2672@samp{@dots{}} stands for one of the possible arguments described
2673above (or no argument) specifying where to break. @xref{Conditions,
2674,Break conditions}, for more information on breakpoint conditions.
2675
2676@kindex tbreak
2677@item tbreak @var{args}
2678Set a breakpoint enabled only for one stop. @var{args} are the
2679same as for the @code{break} command, and the breakpoint is set in the same
2680way, but the breakpoint is automatically deleted after the first time your
2681program stops there. @xref{Disabling, ,Disabling breakpoints}.
2682
c906108c 2683@kindex hbreak
ba04e063 2684@cindex hardware breakpoints
c906108c 2685@item hbreak @var{args}
d4f3574e
SS
2686Set a hardware-assisted breakpoint. @var{args} are the same as for the
2687@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2688breakpoint requires hardware support and some target hardware may not
2689have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2690debugging, so you can set a breakpoint at an instruction without
2691changing the instruction. This can be used with the new trap-generation
09d4efe1 2692provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
2693will generate traps when a program accesses some data or instruction
2694address that is assigned to the debug registers. However the hardware
2695breakpoint registers can take a limited number of breakpoints. For
2696example, on the DSU, only two data breakpoints can be set at a time, and
2697@value{GDBN} will reject this command if more than two are used. Delete
2698or disable unused hardware breakpoints before setting new ones
2699(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
9c16f35a
EZ
2700For remote targets, you can restrict the number of hardware
2701breakpoints @value{GDBN} will use, see @ref{set remote
2702hardware-breakpoint-limit}.
501eef12 2703
c906108c
SS
2704
2705@kindex thbreak
2706@item thbreak @var{args}
2707Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2708are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2709the same way. However, like the @code{tbreak} command,
c906108c
SS
2710the breakpoint is automatically deleted after the
2711first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2712command, the breakpoint requires hardware support and some target hardware
2713may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2714See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2715
2716@kindex rbreak
2717@cindex regular expression
c45da7e6
EZ
2718@cindex breakpoints in functions matching a regexp
2719@cindex set breakpoints in many functions
c906108c 2720@item rbreak @var{regex}
c906108c 2721Set breakpoints on all functions matching the regular expression
11cf8741
JM
2722@var{regex}. This command sets an unconditional breakpoint on all
2723matches, printing a list of all breakpoints it set. Once these
2724breakpoints are set, they are treated just like the breakpoints set with
2725the @code{break} command. You can delete them, disable them, or make
2726them conditional the same way as any other breakpoint.
2727
2728The syntax of the regular expression is the standard one used with tools
2729like @file{grep}. Note that this is different from the syntax used by
2730shells, so for instance @code{foo*} matches all functions that include
2731an @code{fo} followed by zero or more @code{o}s. There is an implicit
2732@code{.*} leading and trailing the regular expression you supply, so to
2733match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2734
f7dc1244 2735@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2736When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2737breakpoints on overloaded functions that are not members of any special
2738classes.
c906108c 2739
f7dc1244
EZ
2740@cindex set breakpoints on all functions
2741The @code{rbreak} command can be used to set breakpoints in
2742@strong{all} the functions in a program, like this:
2743
2744@smallexample
2745(@value{GDBP}) rbreak .
2746@end smallexample
2747
c906108c
SS
2748@kindex info breakpoints
2749@cindex @code{$_} and @code{info breakpoints}
2750@item info breakpoints @r{[}@var{n}@r{]}
2751@itemx info break @r{[}@var{n}@r{]}
2752@itemx info watchpoints @r{[}@var{n}@r{]}
2753Print a table of all breakpoints, watchpoints, and catchpoints set and
2754not deleted, with the following columns for each breakpoint:
2755
2756@table @emph
2757@item Breakpoint Numbers
2758@item Type
2759Breakpoint, watchpoint, or catchpoint.
2760@item Disposition
2761Whether the breakpoint is marked to be disabled or deleted when hit.
2762@item Enabled or Disabled
2763Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2764that are not enabled.
2765@item Address
2650777c
JJ
2766Where the breakpoint is in your program, as a memory address. If the
2767breakpoint is pending (see below for details) on a future load of a shared library, the address
2768will be listed as @samp{<PENDING>}.
c906108c
SS
2769@item What
2770Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
2771line number. For a pending breakpoint, the original string passed to
2772the breakpoint command will be listed as it cannot be resolved until
2773the appropriate shared library is loaded in the future.
c906108c
SS
2774@end table
2775
2776@noindent
2777If a breakpoint is conditional, @code{info break} shows the condition on
2778the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
2779are listed after that. A pending breakpoint is allowed to have a condition
2780specified for it. The condition is not parsed for validity until a shared
2781library is loaded that allows the pending breakpoint to resolve to a
2782valid location.
c906108c
SS
2783
2784@noindent
2785@code{info break} with a breakpoint
2786number @var{n} as argument lists only that breakpoint. The
2787convenience variable @code{$_} and the default examining-address for
2788the @code{x} command are set to the address of the last breakpoint
5d161b24 2789listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2790
2791@noindent
2792@code{info break} displays a count of the number of times the breakpoint
2793has been hit. This is especially useful in conjunction with the
2794@code{ignore} command. You can ignore a large number of breakpoint
2795hits, look at the breakpoint info to see how many times the breakpoint
2796was hit, and then run again, ignoring one less than that number. This
2797will get you quickly to the last hit of that breakpoint.
2798@end table
2799
2800@value{GDBN} allows you to set any number of breakpoints at the same place in
2801your program. There is nothing silly or meaningless about this. When
2802the breakpoints are conditional, this is even useful
2803(@pxref{Conditions, ,Break conditions}).
2804
2650777c 2805@cindex pending breakpoints
dd79a6cf
JJ
2806If a specified breakpoint location cannot be found, it may be due to the fact
2807that the location is in a shared library that is yet to be loaded. In such
2808a case, you may want @value{GDBN} to create a special breakpoint (known as
2809a @dfn{pending breakpoint}) that
2810attempts to resolve itself in the future when an appropriate shared library
2811gets loaded.
2812
2813Pending breakpoints are useful to set at the start of your
2650777c
JJ
2814@value{GDBN} session for locations that you know will be dynamically loaded
2815later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
2816a check is made to see if the load resolves any pending breakpoint locations.
2817If a pending breakpoint location gets resolved,
2818a regular breakpoint is created and the original pending breakpoint is removed.
2819
2820@value{GDBN} provides some additional commands for controlling pending
2821breakpoint support:
2822
2823@kindex set breakpoint pending
2824@kindex show breakpoint pending
2825@table @code
2826@item set breakpoint pending auto
2827This is the default behavior. When @value{GDBN} cannot find the breakpoint
2828location, it queries you whether a pending breakpoint should be created.
2829
2830@item set breakpoint pending on
2831This indicates that an unrecognized breakpoint location should automatically
2832result in a pending breakpoint being created.
2833
2834@item set breakpoint pending off
2835This indicates that pending breakpoints are not to be created. Any
2836unrecognized breakpoint location results in an error. This setting does
2837not affect any pending breakpoints previously created.
2838
2839@item show breakpoint pending
2840Show the current behavior setting for creating pending breakpoints.
2841@end table
2650777c 2842
649e03f6
RM
2843@cindex operations allowed on pending breakpoints
2844Normal breakpoint operations apply to pending breakpoints as well. You may
2845specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
2846breakpoint is reached. You can also enable or disable
2847the pending breakpoint. When you specify a condition for a pending breakpoint,
2848the parsing of the condition will be deferred until the point where the
2849pending breakpoint location is resolved. Disabling a pending breakpoint
2850tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
2851shared library load. When a pending breakpoint is re-enabled,
649e03f6 2852@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
2853This is done because any number of shared library loads could have
2854occurred since the time the breakpoint was disabled and one or more
2855of these loads could resolve the location.
2856
c906108c
SS
2857@cindex negative breakpoint numbers
2858@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2859@value{GDBN} itself sometimes sets breakpoints in your program for
2860special purposes, such as proper handling of @code{longjmp} (in C
2861programs). These internal breakpoints are assigned negative numbers,
2862starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2863You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2864@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2865
2866
6d2ebf8b 2867@node Set Watchpoints
c906108c
SS
2868@subsection Setting watchpoints
2869
2870@cindex setting watchpoints
c906108c
SS
2871You can use a watchpoint to stop execution whenever the value of an
2872expression changes, without having to predict a particular place where
2873this may happen.
2874
82f2d802
EZ
2875@cindex software watchpoints
2876@cindex hardware watchpoints
c906108c 2877Depending on your system, watchpoints may be implemented in software or
2df3850c 2878hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2879program and testing the variable's value each time, which is hundreds of
2880times slower than normal execution. (But this may still be worth it, to
2881catch errors where you have no clue what part of your program is the
2882culprit.)
2883
82f2d802
EZ
2884On some systems, such as HP-UX, @sc{gnu}/Linux and most other
2885x86-based targets, @value{GDBN} includes support for hardware
2886watchpoints, which do not slow down the running of your program.
c906108c
SS
2887
2888@table @code
2889@kindex watch
2890@item watch @var{expr}
2891Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2892is written into by the program and its value changes.
2893
2894@kindex rwatch
2895@item rwatch @var{expr}
09d4efe1
EZ
2896Set a watchpoint that will break when the value of @var{expr} is read
2897by the program.
c906108c
SS
2898
2899@kindex awatch
2900@item awatch @var{expr}
09d4efe1
EZ
2901Set a watchpoint that will break when @var{expr} is either read from
2902or written into by the program.
c906108c
SS
2903
2904@kindex info watchpoints
2905@item info watchpoints
2906This command prints a list of watchpoints, breakpoints, and catchpoints;
09d4efe1 2907it is the same as @code{info break} (@pxref{Set Breaks}).
c906108c
SS
2908@end table
2909
2910@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2911watchpoints execute very quickly, and the debugger reports a change in
2912value at the exact instruction where the change occurs. If @value{GDBN}
2913cannot set a hardware watchpoint, it sets a software watchpoint, which
2914executes more slowly and reports the change in value at the next
82f2d802
EZ
2915@emph{statement}, not the instruction, after the change occurs.
2916
82f2d802
EZ
2917@cindex use only software watchpoints
2918You can force @value{GDBN} to use only software watchpoints with the
2919@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
2920zero, @value{GDBN} will never try to use hardware watchpoints, even if
2921the underlying system supports them. (Note that hardware-assisted
2922watchpoints that were set @emph{before} setting
2923@code{can-use-hw-watchpoints} to zero will still use the hardware
2924mechanism of watching expressiion values.)
c906108c 2925
9c16f35a
EZ
2926@table @code
2927@item set can-use-hw-watchpoints
2928@kindex set can-use-hw-watchpoints
2929Set whether or not to use hardware watchpoints.
2930
2931@item show can-use-hw-watchpoints
2932@kindex show can-use-hw-watchpoints
2933Show the current mode of using hardware watchpoints.
2934@end table
2935
2936For remote targets, you can restrict the number of hardware
2937watchpoints @value{GDBN} will use, see @ref{set remote
2938hardware-breakpoint-limit}.
2939
c906108c
SS
2940When you issue the @code{watch} command, @value{GDBN} reports
2941
474c8240 2942@smallexample
c906108c 2943Hardware watchpoint @var{num}: @var{expr}
474c8240 2944@end smallexample
c906108c
SS
2945
2946@noindent
2947if it was able to set a hardware watchpoint.
2948
7be570e7
JM
2949Currently, the @code{awatch} and @code{rwatch} commands can only set
2950hardware watchpoints, because accesses to data that don't change the
2951value of the watched expression cannot be detected without examining
2952every instruction as it is being executed, and @value{GDBN} does not do
2953that currently. If @value{GDBN} finds that it is unable to set a
2954hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2955will print a message like this:
2956
2957@smallexample
2958Expression cannot be implemented with read/access watchpoint.
2959@end smallexample
2960
2961Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2962data type of the watched expression is wider than what a hardware
2963watchpoint on the target machine can handle. For example, some systems
2964can only watch regions that are up to 4 bytes wide; on such systems you
2965cannot set hardware watchpoints for an expression that yields a
2966double-precision floating-point number (which is typically 8 bytes
2967wide). As a work-around, it might be possible to break the large region
2968into a series of smaller ones and watch them with separate watchpoints.
2969
2970If you set too many hardware watchpoints, @value{GDBN} might be unable
2971to insert all of them when you resume the execution of your program.
2972Since the precise number of active watchpoints is unknown until such
2973time as the program is about to be resumed, @value{GDBN} might not be
2974able to warn you about this when you set the watchpoints, and the
2975warning will be printed only when the program is resumed:
2976
2977@smallexample
2978Hardware watchpoint @var{num}: Could not insert watchpoint
2979@end smallexample
2980
2981@noindent
2982If this happens, delete or disable some of the watchpoints.
2983
2984The SPARClite DSU will generate traps when a program accesses some data
2985or instruction address that is assigned to the debug registers. For the
2986data addresses, DSU facilitates the @code{watch} command. However the
2987hardware breakpoint registers can only take two data watchpoints, and
2988both watchpoints must be the same kind. For example, you can set two
2989watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2990@strong{or} two with @code{awatch} commands, but you cannot set one
2991watchpoint with one command and the other with a different command.
c906108c
SS
2992@value{GDBN} will reject the command if you try to mix watchpoints.
2993Delete or disable unused watchpoint commands before setting new ones.
2994
2995If you call a function interactively using @code{print} or @code{call},
2df3850c 2996any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2997kind of breakpoint or the call completes.
2998
7be570e7
JM
2999@value{GDBN} automatically deletes watchpoints that watch local
3000(automatic) variables, or expressions that involve such variables, when
3001they go out of scope, that is, when the execution leaves the block in
3002which these variables were defined. In particular, when the program
3003being debugged terminates, @emph{all} local variables go out of scope,
3004and so only watchpoints that watch global variables remain set. If you
3005rerun the program, you will need to set all such watchpoints again. One
3006way of doing that would be to set a code breakpoint at the entry to the
3007@code{main} function and when it breaks, set all the watchpoints.
3008
c906108c
SS
3009@quotation
3010@cindex watchpoints and threads
3011@cindex threads and watchpoints
c906108c
SS
3012@emph{Warning:} In multi-thread programs, watchpoints have only limited
3013usefulness. With the current watchpoint implementation, @value{GDBN}
3014can only watch the value of an expression @emph{in a single thread}. If
3015you are confident that the expression can only change due to the current
3016thread's activity (and if you are also confident that no other thread
3017can become current), then you can use watchpoints as usual. However,
3018@value{GDBN} may not notice when a non-current thread's activity changes
3019the expression.
53a5351d 3020
d4f3574e 3021@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
3022@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
3023have only limited usefulness. If @value{GDBN} creates a software
3024watchpoint, it can only watch the value of an expression @emph{in a
3025single thread}. If you are confident that the expression can only
3026change due to the current thread's activity (and if you are also
3027confident that no other thread can become current), then you can use
3028software watchpoints as usual. However, @value{GDBN} may not notice
3029when a non-current thread's activity changes the expression. (Hardware
3030watchpoints, in contrast, watch an expression in all threads.)
c906108c 3031@end quotation
c906108c 3032
501eef12
AC
3033@xref{set remote hardware-watchpoint-limit}.
3034
6d2ebf8b 3035@node Set Catchpoints
c906108c 3036@subsection Setting catchpoints
d4f3574e 3037@cindex catchpoints, setting
c906108c
SS
3038@cindex exception handlers
3039@cindex event handling
3040
3041You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 3042kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
3043shared library. Use the @code{catch} command to set a catchpoint.
3044
3045@table @code
3046@kindex catch
3047@item catch @var{event}
3048Stop when @var{event} occurs. @var{event} can be any of the following:
3049@table @code
3050@item throw
4644b6e3 3051@cindex stop on C@t{++} exceptions
b37052ae 3052The throwing of a C@t{++} exception.
c906108c
SS
3053
3054@item catch
b37052ae 3055The catching of a C@t{++} exception.
c906108c
SS
3056
3057@item exec
4644b6e3 3058@cindex break on fork/exec
c906108c
SS
3059A call to @code{exec}. This is currently only available for HP-UX.
3060
3061@item fork
c906108c
SS
3062A call to @code{fork}. This is currently only available for HP-UX.
3063
3064@item vfork
c906108c
SS
3065A call to @code{vfork}. This is currently only available for HP-UX.
3066
3067@item load
3068@itemx load @var{libname}
4644b6e3 3069@cindex break on load/unload of shared library
c906108c
SS
3070The dynamic loading of any shared library, or the loading of the library
3071@var{libname}. This is currently only available for HP-UX.
3072
3073@item unload
3074@itemx unload @var{libname}
c906108c
SS
3075The unloading of any dynamically loaded shared library, or the unloading
3076of the library @var{libname}. This is currently only available for HP-UX.
3077@end table
3078
3079@item tcatch @var{event}
3080Set a catchpoint that is enabled only for one stop. The catchpoint is
3081automatically deleted after the first time the event is caught.
3082
3083@end table
3084
3085Use the @code{info break} command to list the current catchpoints.
3086
b37052ae 3087There are currently some limitations to C@t{++} exception handling
c906108c
SS
3088(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3089
3090@itemize @bullet
3091@item
3092If you call a function interactively, @value{GDBN} normally returns
3093control to you when the function has finished executing. If the call
3094raises an exception, however, the call may bypass the mechanism that
3095returns control to you and cause your program either to abort or to
3096simply continue running until it hits a breakpoint, catches a signal
3097that @value{GDBN} is listening for, or exits. This is the case even if
3098you set a catchpoint for the exception; catchpoints on exceptions are
3099disabled within interactive calls.
3100
3101@item
3102You cannot raise an exception interactively.
3103
3104@item
3105You cannot install an exception handler interactively.
3106@end itemize
3107
3108@cindex raise exceptions
3109Sometimes @code{catch} is not the best way to debug exception handling:
3110if you need to know exactly where an exception is raised, it is better to
3111stop @emph{before} the exception handler is called, since that way you
3112can see the stack before any unwinding takes place. If you set a
3113breakpoint in an exception handler instead, it may not be easy to find
3114out where the exception was raised.
3115
3116To stop just before an exception handler is called, you need some
b37052ae 3117knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
3118raised by calling a library function named @code{__raise_exception}
3119which has the following ANSI C interface:
3120
474c8240 3121@smallexample
c906108c 3122 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
3123 @var{id} is the exception identifier. */
3124 void __raise_exception (void **addr, void *id);
474c8240 3125@end smallexample
c906108c
SS
3126
3127@noindent
3128To make the debugger catch all exceptions before any stack
3129unwinding takes place, set a breakpoint on @code{__raise_exception}
3130(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
3131
3132With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
3133that depends on the value of @var{id}, you can stop your program when
3134a specific exception is raised. You can use multiple conditional
3135breakpoints to stop your program when any of a number of exceptions are
3136raised.
3137
3138
6d2ebf8b 3139@node Delete Breaks
c906108c
SS
3140@subsection Deleting breakpoints
3141
3142@cindex clearing breakpoints, watchpoints, catchpoints
3143@cindex deleting breakpoints, watchpoints, catchpoints
3144It is often necessary to eliminate a breakpoint, watchpoint, or
3145catchpoint once it has done its job and you no longer want your program
3146to stop there. This is called @dfn{deleting} the breakpoint. A
3147breakpoint that has been deleted no longer exists; it is forgotten.
3148
3149With the @code{clear} command you can delete breakpoints according to
3150where they are in your program. With the @code{delete} command you can
3151delete individual breakpoints, watchpoints, or catchpoints by specifying
3152their breakpoint numbers.
3153
3154It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3155automatically ignores breakpoints on the first instruction to be executed
3156when you continue execution without changing the execution address.
3157
3158@table @code
3159@kindex clear
3160@item clear
3161Delete any breakpoints at the next instruction to be executed in the
3162selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3163the innermost frame is selected, this is a good way to delete a
3164breakpoint where your program just stopped.
3165
3166@item clear @var{function}
3167@itemx clear @var{filename}:@var{function}
09d4efe1 3168Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
3169
3170@item clear @var{linenum}
3171@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
3172Delete any breakpoints set at or within the code of the specified
3173@var{linenum} of the specified @var{filename}.
c906108c
SS
3174
3175@cindex delete breakpoints
3176@kindex delete
41afff9a 3177@kindex d @r{(@code{delete})}
c5394b80
JM
3178@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3179Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3180ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3181breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3182confirm off}). You can abbreviate this command as @code{d}.
3183@end table
3184
6d2ebf8b 3185@node Disabling
c906108c
SS
3186@subsection Disabling breakpoints
3187
4644b6e3 3188@cindex enable/disable a breakpoint
c906108c
SS
3189Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3190prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3191it had been deleted, but remembers the information on the breakpoint so
3192that you can @dfn{enable} it again later.
3193
3194You disable and enable breakpoints, watchpoints, and catchpoints with
3195the @code{enable} and @code{disable} commands, optionally specifying one
3196or more breakpoint numbers as arguments. Use @code{info break} or
3197@code{info watch} to print a list of breakpoints, watchpoints, and
3198catchpoints if you do not know which numbers to use.
3199
3200A breakpoint, watchpoint, or catchpoint can have any of four different
3201states of enablement:
3202
3203@itemize @bullet
3204@item
3205Enabled. The breakpoint stops your program. A breakpoint set
3206with the @code{break} command starts out in this state.
3207@item
3208Disabled. The breakpoint has no effect on your program.
3209@item
3210Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3211disabled.
c906108c
SS
3212@item
3213Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3214immediately after it does so it is deleted permanently. A breakpoint
3215set with the @code{tbreak} command starts out in this state.
c906108c
SS
3216@end itemize
3217
3218You can use the following commands to enable or disable breakpoints,
3219watchpoints, and catchpoints:
3220
3221@table @code
c906108c 3222@kindex disable
41afff9a 3223@kindex dis @r{(@code{disable})}
c5394b80 3224@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3225Disable the specified breakpoints---or all breakpoints, if none are
3226listed. A disabled breakpoint has no effect but is not forgotten. All
3227options such as ignore-counts, conditions and commands are remembered in
3228case the breakpoint is enabled again later. You may abbreviate
3229@code{disable} as @code{dis}.
3230
c906108c 3231@kindex enable
c5394b80 3232@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3233Enable the specified breakpoints (or all defined breakpoints). They
3234become effective once again in stopping your program.
3235
c5394b80 3236@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3237Enable the specified breakpoints temporarily. @value{GDBN} disables any
3238of these breakpoints immediately after stopping your program.
3239
c5394b80 3240@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3241Enable the specified breakpoints to work once, then die. @value{GDBN}
3242deletes any of these breakpoints as soon as your program stops there.
09d4efe1 3243Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
3244@end table
3245
d4f3574e
SS
3246@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3247@c confusing: tbreak is also initially enabled.
c906108c
SS
3248Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3249,Setting breakpoints}), breakpoints that you set are initially enabled;
3250subsequently, they become disabled or enabled only when you use one of
3251the commands above. (The command @code{until} can set and delete a
3252breakpoint of its own, but it does not change the state of your other
3253breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3254stepping}.)
3255
6d2ebf8b 3256@node Conditions
c906108c
SS
3257@subsection Break conditions
3258@cindex conditional breakpoints
3259@cindex breakpoint conditions
3260
3261@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3262@c in particular for a watchpoint?
c906108c
SS
3263The simplest sort of breakpoint breaks every time your program reaches a
3264specified place. You can also specify a @dfn{condition} for a
3265breakpoint. A condition is just a Boolean expression in your
3266programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3267a condition evaluates the expression each time your program reaches it,
3268and your program stops only if the condition is @emph{true}.
3269
3270This is the converse of using assertions for program validation; in that
3271situation, you want to stop when the assertion is violated---that is,
3272when the condition is false. In C, if you want to test an assertion expressed
3273by the condition @var{assert}, you should set the condition
3274@samp{! @var{assert}} on the appropriate breakpoint.
3275
3276Conditions are also accepted for watchpoints; you may not need them,
3277since a watchpoint is inspecting the value of an expression anyhow---but
3278it might be simpler, say, to just set a watchpoint on a variable name,
3279and specify a condition that tests whether the new value is an interesting
3280one.
3281
3282Break conditions can have side effects, and may even call functions in
3283your program. This can be useful, for example, to activate functions
3284that log program progress, or to use your own print functions to
3285format special data structures. The effects are completely predictable
3286unless there is another enabled breakpoint at the same address. (In
3287that case, @value{GDBN} might see the other breakpoint first and stop your
3288program without checking the condition of this one.) Note that
d4f3574e
SS
3289breakpoint commands are usually more convenient and flexible than break
3290conditions for the
c906108c
SS
3291purpose of performing side effects when a breakpoint is reached
3292(@pxref{Break Commands, ,Breakpoint command lists}).
3293
3294Break conditions can be specified when a breakpoint is set, by using
3295@samp{if} in the arguments to the @code{break} command. @xref{Set
3296Breaks, ,Setting breakpoints}. They can also be changed at any time
3297with the @code{condition} command.
53a5351d 3298
c906108c
SS
3299You can also use the @code{if} keyword with the @code{watch} command.
3300The @code{catch} command does not recognize the @code{if} keyword;
3301@code{condition} is the only way to impose a further condition on a
3302catchpoint.
c906108c
SS
3303
3304@table @code
3305@kindex condition
3306@item condition @var{bnum} @var{expression}
3307Specify @var{expression} as the break condition for breakpoint,
3308watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3309breakpoint @var{bnum} stops your program only if the value of
3310@var{expression} is true (nonzero, in C). When you use
3311@code{condition}, @value{GDBN} checks @var{expression} immediately for
3312syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3313referents in the context of your breakpoint. If @var{expression} uses
3314symbols not referenced in the context of the breakpoint, @value{GDBN}
3315prints an error message:
3316
474c8240 3317@smallexample
d4f3574e 3318No symbol "foo" in current context.
474c8240 3319@end smallexample
d4f3574e
SS
3320
3321@noindent
c906108c
SS
3322@value{GDBN} does
3323not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3324command (or a command that sets a breakpoint with a condition, like
3325@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3326
3327@item condition @var{bnum}
3328Remove the condition from breakpoint number @var{bnum}. It becomes
3329an ordinary unconditional breakpoint.
3330@end table
3331
3332@cindex ignore count (of breakpoint)
3333A special case of a breakpoint condition is to stop only when the
3334breakpoint has been reached a certain number of times. This is so
3335useful that there is a special way to do it, using the @dfn{ignore
3336count} of the breakpoint. Every breakpoint has an ignore count, which
3337is an integer. Most of the time, the ignore count is zero, and
3338therefore has no effect. But if your program reaches a breakpoint whose
3339ignore count is positive, then instead of stopping, it just decrements
3340the ignore count by one and continues. As a result, if the ignore count
3341value is @var{n}, the breakpoint does not stop the next @var{n} times
3342your program reaches it.
3343
3344@table @code
3345@kindex ignore
3346@item ignore @var{bnum} @var{count}
3347Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3348The next @var{count} times the breakpoint is reached, your program's
3349execution does not stop; other than to decrement the ignore count, @value{GDBN}
3350takes no action.
3351
3352To make the breakpoint stop the next time it is reached, specify
3353a count of zero.
3354
3355When you use @code{continue} to resume execution of your program from a
3356breakpoint, you can specify an ignore count directly as an argument to
3357@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3358Stepping,,Continuing and stepping}.
3359
3360If a breakpoint has a positive ignore count and a condition, the
3361condition is not checked. Once the ignore count reaches zero,
3362@value{GDBN} resumes checking the condition.
3363
3364You could achieve the effect of the ignore count with a condition such
3365as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3366is decremented each time. @xref{Convenience Vars, ,Convenience
3367variables}.
3368@end table
3369
3370Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3371
3372
6d2ebf8b 3373@node Break Commands
c906108c
SS
3374@subsection Breakpoint command lists
3375
3376@cindex breakpoint commands
3377You can give any breakpoint (or watchpoint or catchpoint) a series of
3378commands to execute when your program stops due to that breakpoint. For
3379example, you might want to print the values of certain expressions, or
3380enable other breakpoints.
3381
3382@table @code
3383@kindex commands
3384@kindex end
3385@item commands @r{[}@var{bnum}@r{]}
3386@itemx @dots{} @var{command-list} @dots{}
3387@itemx end
3388Specify a list of commands for breakpoint number @var{bnum}. The commands
3389themselves appear on the following lines. Type a line containing just
3390@code{end} to terminate the commands.
3391
3392To remove all commands from a breakpoint, type @code{commands} and
3393follow it immediately with @code{end}; that is, give no commands.
3394
3395With no @var{bnum} argument, @code{commands} refers to the last
3396breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3397recently encountered).
3398@end table
3399
3400Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3401disabled within a @var{command-list}.
3402
3403You can use breakpoint commands to start your program up again. Simply
3404use the @code{continue} command, or @code{step}, or any other command
3405that resumes execution.
3406
3407Any other commands in the command list, after a command that resumes
3408execution, are ignored. This is because any time you resume execution
3409(even with a simple @code{next} or @code{step}), you may encounter
3410another breakpoint---which could have its own command list, leading to
3411ambiguities about which list to execute.
3412
3413@kindex silent
3414If the first command you specify in a command list is @code{silent}, the
3415usual message about stopping at a breakpoint is not printed. This may
3416be desirable for breakpoints that are to print a specific message and
3417then continue. If none of the remaining commands print anything, you
3418see no sign that the breakpoint was reached. @code{silent} is
3419meaningful only at the beginning of a breakpoint command list.
3420
3421The commands @code{echo}, @code{output}, and @code{printf} allow you to
3422print precisely controlled output, and are often useful in silent
3423breakpoints. @xref{Output, ,Commands for controlled output}.
3424
3425For example, here is how you could use breakpoint commands to print the
3426value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3427
474c8240 3428@smallexample
c906108c
SS
3429break foo if x>0
3430commands
3431silent
3432printf "x is %d\n",x
3433cont
3434end
474c8240 3435@end smallexample
c906108c
SS
3436
3437One application for breakpoint commands is to compensate for one bug so
3438you can test for another. Put a breakpoint just after the erroneous line
3439of code, give it a condition to detect the case in which something
3440erroneous has been done, and give it commands to assign correct values
3441to any variables that need them. End with the @code{continue} command
3442so that your program does not stop, and start with the @code{silent}
3443command so that no output is produced. Here is an example:
3444
474c8240 3445@smallexample
c906108c
SS
3446break 403
3447commands
3448silent
3449set x = y + 4
3450cont
3451end
474c8240 3452@end smallexample
c906108c 3453
6d2ebf8b 3454@node Breakpoint Menus
c906108c
SS
3455@subsection Breakpoint menus
3456@cindex overloading
3457@cindex symbol overloading
3458
b383017d 3459Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3460single function name
c906108c
SS
3461to be defined several times, for application in different contexts.
3462This is called @dfn{overloading}. When a function name is overloaded,
3463@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3464a breakpoint. If you realize this is a problem, you can use
3465something like @samp{break @var{function}(@var{types})} to specify which
3466particular version of the function you want. Otherwise, @value{GDBN} offers
3467you a menu of numbered choices for different possible breakpoints, and
3468waits for your selection with the prompt @samp{>}. The first two
3469options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3470sets a breakpoint at each definition of @var{function}, and typing
3471@kbd{0} aborts the @code{break} command without setting any new
3472breakpoints.
3473
3474For example, the following session excerpt shows an attempt to set a
3475breakpoint at the overloaded symbol @code{String::after}.
3476We choose three particular definitions of that function name:
3477
3478@c FIXME! This is likely to change to show arg type lists, at least
3479@smallexample
3480@group
3481(@value{GDBP}) b String::after
3482[0] cancel
3483[1] all
3484[2] file:String.cc; line number:867
3485[3] file:String.cc; line number:860
3486[4] file:String.cc; line number:875
3487[5] file:String.cc; line number:853
3488[6] file:String.cc; line number:846
3489[7] file:String.cc; line number:735
3490> 2 4 6
3491Breakpoint 1 at 0xb26c: file String.cc, line 867.
3492Breakpoint 2 at 0xb344: file String.cc, line 875.
3493Breakpoint 3 at 0xafcc: file String.cc, line 846.
3494Multiple breakpoints were set.
3495Use the "delete" command to delete unwanted
3496 breakpoints.
3497(@value{GDBP})
3498@end group
3499@end smallexample
c906108c
SS
3500
3501@c @ifclear BARETARGET
6d2ebf8b 3502@node Error in Breakpoints
d4f3574e 3503@subsection ``Cannot insert breakpoints''
c906108c
SS
3504@c
3505@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3506@c
d4f3574e
SS
3507Under some operating systems, breakpoints cannot be used in a program if
3508any other process is running that program. In this situation,
5d161b24 3509attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3510@value{GDBN} to print an error message:
3511
474c8240 3512@smallexample
d4f3574e
SS
3513Cannot insert breakpoints.
3514The same program may be running in another process.
474c8240 3515@end smallexample
d4f3574e
SS
3516
3517When this happens, you have three ways to proceed:
3518
3519@enumerate
3520@item
3521Remove or disable the breakpoints, then continue.
3522
3523@item
5d161b24 3524Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3525name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3526that @value{GDBN} should run your program under that name.
d4f3574e
SS
3527Then start your program again.
3528
3529@item
3530Relink your program so that the text segment is nonsharable, using the
3531linker option @samp{-N}. The operating system limitation may not apply
3532to nonsharable executables.
3533@end enumerate
c906108c
SS
3534@c @end ifclear
3535
d4f3574e
SS
3536A similar message can be printed if you request too many active
3537hardware-assisted breakpoints and watchpoints:
3538
3539@c FIXME: the precise wording of this message may change; the relevant
3540@c source change is not committed yet (Sep 3, 1999).
3541@smallexample
3542Stopped; cannot insert breakpoints.
3543You may have requested too many hardware breakpoints and watchpoints.
3544@end smallexample
3545
3546@noindent
3547This message is printed when you attempt to resume the program, since
3548only then @value{GDBN} knows exactly how many hardware breakpoints and
3549watchpoints it needs to insert.
3550
3551When this message is printed, you need to disable or remove some of the
3552hardware-assisted breakpoints and watchpoints, and then continue.
3553
1485d690
KB
3554@node Breakpoint related warnings
3555@subsection ``Breakpoint address adjusted...''
3556@cindex breakpoint address adjusted
3557
3558Some processor architectures place constraints on the addresses at
3559which breakpoints may be placed. For architectures thus constrained,
3560@value{GDBN} will attempt to adjust the breakpoint's address to comply
3561with the constraints dictated by the architecture.
3562
3563One example of such an architecture is the Fujitsu FR-V. The FR-V is
3564a VLIW architecture in which a number of RISC-like instructions may be
3565bundled together for parallel execution. The FR-V architecture
3566constrains the location of a breakpoint instruction within such a
3567bundle to the instruction with the lowest address. @value{GDBN}
3568honors this constraint by adjusting a breakpoint's address to the
3569first in the bundle.
3570
3571It is not uncommon for optimized code to have bundles which contain
3572instructions from different source statements, thus it may happen that
3573a breakpoint's address will be adjusted from one source statement to
3574another. Since this adjustment may significantly alter @value{GDBN}'s
3575breakpoint related behavior from what the user expects, a warning is
3576printed when the breakpoint is first set and also when the breakpoint
3577is hit.
3578
3579A warning like the one below is printed when setting a breakpoint
3580that's been subject to address adjustment:
3581
3582@smallexample
3583warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3584@end smallexample
3585
3586Such warnings are printed both for user settable and @value{GDBN}'s
3587internal breakpoints. If you see one of these warnings, you should
3588verify that a breakpoint set at the adjusted address will have the
3589desired affect. If not, the breakpoint in question may be removed and
b383017d 3590other breakpoints may be set which will have the desired behavior.
1485d690
KB
3591E.g., it may be sufficient to place the breakpoint at a later
3592instruction. A conditional breakpoint may also be useful in some
3593cases to prevent the breakpoint from triggering too often.
3594
3595@value{GDBN} will also issue a warning when stopping at one of these
3596adjusted breakpoints:
3597
3598@smallexample
3599warning: Breakpoint 1 address previously adjusted from 0x00010414
3600to 0x00010410.
3601@end smallexample
3602
3603When this warning is encountered, it may be too late to take remedial
3604action except in cases where the breakpoint is hit earlier or more
3605frequently than expected.
d4f3574e 3606
6d2ebf8b 3607@node Continuing and Stepping
c906108c
SS
3608@section Continuing and stepping
3609
3610@cindex stepping
3611@cindex continuing
3612@cindex resuming execution
3613@dfn{Continuing} means resuming program execution until your program
3614completes normally. In contrast, @dfn{stepping} means executing just
3615one more ``step'' of your program, where ``step'' may mean either one
3616line of source code, or one machine instruction (depending on what
7a292a7a
SS
3617particular command you use). Either when continuing or when stepping,
3618your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3619it stops due to a signal, you may want to use @code{handle}, or use
3620@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3621
3622@table @code
3623@kindex continue
41afff9a
EZ
3624@kindex c @r{(@code{continue})}
3625@kindex fg @r{(resume foreground execution)}
c906108c
SS
3626@item continue @r{[}@var{ignore-count}@r{]}
3627@itemx c @r{[}@var{ignore-count}@r{]}
3628@itemx fg @r{[}@var{ignore-count}@r{]}
3629Resume program execution, at the address where your program last stopped;
3630any breakpoints set at that address are bypassed. The optional argument
3631@var{ignore-count} allows you to specify a further number of times to
3632ignore a breakpoint at this location; its effect is like that of
3633@code{ignore} (@pxref{Conditions, ,Break conditions}).
3634
3635The argument @var{ignore-count} is meaningful only when your program
3636stopped due to a breakpoint. At other times, the argument to
3637@code{continue} is ignored.
3638
d4f3574e
SS
3639The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3640debugged program is deemed to be the foreground program) are provided
3641purely for convenience, and have exactly the same behavior as
3642@code{continue}.
c906108c
SS
3643@end table
3644
3645To resume execution at a different place, you can use @code{return}
3646(@pxref{Returning, ,Returning from a function}) to go back to the
3647calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3648different address}) to go to an arbitrary location in your program.
3649
3650A typical technique for using stepping is to set a breakpoint
3651(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3652beginning of the function or the section of your program where a problem
3653is believed to lie, run your program until it stops at that breakpoint,
3654and then step through the suspect area, examining the variables that are
3655interesting, until you see the problem happen.
3656
3657@table @code
3658@kindex step
41afff9a 3659@kindex s @r{(@code{step})}
c906108c
SS
3660@item step
3661Continue running your program until control reaches a different source
3662line, then stop it and return control to @value{GDBN}. This command is
3663abbreviated @code{s}.
3664
3665@quotation
3666@c "without debugging information" is imprecise; actually "without line
3667@c numbers in the debugging information". (gcc -g1 has debugging info but
3668@c not line numbers). But it seems complex to try to make that
3669@c distinction here.
3670@emph{Warning:} If you use the @code{step} command while control is
3671within a function that was compiled without debugging information,
3672execution proceeds until control reaches a function that does have
3673debugging information. Likewise, it will not step into a function which
3674is compiled without debugging information. To step through functions
3675without debugging information, use the @code{stepi} command, described
3676below.
3677@end quotation
3678
4a92d011
EZ
3679The @code{step} command only stops at the first instruction of a source
3680line. This prevents the multiple stops that could otherwise occur in
3681@code{switch} statements, @code{for} loops, etc. @code{step} continues
3682to stop if a function that has debugging information is called within
3683the line. In other words, @code{step} @emph{steps inside} any functions
3684called within the line.
c906108c 3685
d4f3574e
SS
3686Also, the @code{step} command only enters a function if there is line
3687number information for the function. Otherwise it acts like the
5d161b24 3688@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3689on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3690was any debugging information about the routine.
c906108c
SS
3691
3692@item step @var{count}
3693Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3694breakpoint is reached, or a signal not related to stepping occurs before
3695@var{count} steps, stepping stops right away.
c906108c
SS
3696
3697@kindex next
41afff9a 3698@kindex n @r{(@code{next})}
c906108c
SS
3699@item next @r{[}@var{count}@r{]}
3700Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3701This is similar to @code{step}, but function calls that appear within
3702the line of code are executed without stopping. Execution stops when
3703control reaches a different line of code at the original stack level
3704that was executing when you gave the @code{next} command. This command
3705is abbreviated @code{n}.
c906108c
SS
3706
3707An argument @var{count} is a repeat count, as for @code{step}.
3708
3709
3710@c FIX ME!! Do we delete this, or is there a way it fits in with
3711@c the following paragraph? --- Vctoria
3712@c
3713@c @code{next} within a function that lacks debugging information acts like
3714@c @code{step}, but any function calls appearing within the code of the
3715@c function are executed without stopping.
3716
d4f3574e
SS
3717The @code{next} command only stops at the first instruction of a
3718source line. This prevents multiple stops that could otherwise occur in
4a92d011 3719@code{switch} statements, @code{for} loops, etc.
c906108c 3720
b90a5f51
CF
3721@kindex set step-mode
3722@item set step-mode
3723@cindex functions without line info, and stepping
3724@cindex stepping into functions with no line info
3725@itemx set step-mode on
4a92d011 3726The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3727stop at the first instruction of a function which contains no debug line
3728information rather than stepping over it.
3729
4a92d011
EZ
3730This is useful in cases where you may be interested in inspecting the
3731machine instructions of a function which has no symbolic info and do not
3732want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3733
3734@item set step-mode off
4a92d011 3735Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3736debug information. This is the default.
3737
9c16f35a
EZ
3738@item show step-mode
3739Show whether @value{GDBN} will stop in or step over functions without
3740source line debug information.
3741
c906108c
SS
3742@kindex finish
3743@item finish
3744Continue running until just after function in the selected stack frame
3745returns. Print the returned value (if any).
3746
3747Contrast this with the @code{return} command (@pxref{Returning,
3748,Returning from a function}).
3749
3750@kindex until
41afff9a 3751@kindex u @r{(@code{until})}
09d4efe1 3752@cindex run until specified location
c906108c
SS
3753@item until
3754@itemx u
3755Continue running until a source line past the current line, in the
3756current stack frame, is reached. This command is used to avoid single
3757stepping through a loop more than once. It is like the @code{next}
3758command, except that when @code{until} encounters a jump, it
3759automatically continues execution until the program counter is greater
3760than the address of the jump.
3761
3762This means that when you reach the end of a loop after single stepping
3763though it, @code{until} makes your program continue execution until it
3764exits the loop. In contrast, a @code{next} command at the end of a loop
3765simply steps back to the beginning of the loop, which forces you to step
3766through the next iteration.
3767
3768@code{until} always stops your program if it attempts to exit the current
3769stack frame.
3770
3771@code{until} may produce somewhat counterintuitive results if the order
3772of machine code does not match the order of the source lines. For
3773example, in the following excerpt from a debugging session, the @code{f}
3774(@code{frame}) command shows that execution is stopped at line
3775@code{206}; yet when we use @code{until}, we get to line @code{195}:
3776
474c8240 3777@smallexample
c906108c
SS
3778(@value{GDBP}) f
3779#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3780206 expand_input();
3781(@value{GDBP}) until
3782195 for ( ; argc > 0; NEXTARG) @{
474c8240 3783@end smallexample
c906108c
SS
3784
3785This happened because, for execution efficiency, the compiler had
3786generated code for the loop closure test at the end, rather than the
3787start, of the loop---even though the test in a C @code{for}-loop is
3788written before the body of the loop. The @code{until} command appeared
3789to step back to the beginning of the loop when it advanced to this
3790expression; however, it has not really gone to an earlier
3791statement---not in terms of the actual machine code.
3792
3793@code{until} with no argument works by means of single
3794instruction stepping, and hence is slower than @code{until} with an
3795argument.
3796
3797@item until @var{location}
3798@itemx u @var{location}
3799Continue running your program until either the specified location is
3800reached, or the current stack frame returns. @var{location} is any of
3801the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
3802,Setting breakpoints}). This form of the command uses breakpoints, and
3803hence is quicker than @code{until} without an argument. The specified
3804location is actually reached only if it is in the current frame. This
3805implies that @code{until} can be used to skip over recursive function
3806invocations. For instance in the code below, if the current location is
3807line @code{96}, issuing @code{until 99} will execute the program up to
3808line @code{99} in the same invocation of factorial, i.e. after the inner
3809invocations have returned.
3810
3811@smallexample
381294 int factorial (int value)
381395 @{
381496 if (value > 1) @{
381597 value *= factorial (value - 1);
381698 @}
381799 return (value);
3818100 @}
3819@end smallexample
3820
3821
3822@kindex advance @var{location}
3823@itemx advance @var{location}
09d4efe1
EZ
3824Continue running the program up to the given @var{location}. An argument is
3825required, which should be of the same form as arguments for the @code{break}
c60eb6f1
EZ
3826command. Execution will also stop upon exit from the current stack
3827frame. This command is similar to @code{until}, but @code{advance} will
3828not skip over recursive function calls, and the target location doesn't
3829have to be in the same frame as the current one.
3830
c906108c
SS
3831
3832@kindex stepi
41afff9a 3833@kindex si @r{(@code{stepi})}
c906108c 3834@item stepi
96a2c332 3835@itemx stepi @var{arg}
c906108c
SS
3836@itemx si
3837Execute one machine instruction, then stop and return to the debugger.
3838
3839It is often useful to do @samp{display/i $pc} when stepping by machine
3840instructions. This makes @value{GDBN} automatically display the next
3841instruction to be executed, each time your program stops. @xref{Auto
3842Display,, Automatic display}.
3843
3844An argument is a repeat count, as in @code{step}.
3845
3846@need 750
3847@kindex nexti
41afff9a 3848@kindex ni @r{(@code{nexti})}
c906108c 3849@item nexti
96a2c332 3850@itemx nexti @var{arg}
c906108c
SS
3851@itemx ni
3852Execute one machine instruction, but if it is a function call,
3853proceed until the function returns.
3854
3855An argument is a repeat count, as in @code{next}.
3856@end table
3857
6d2ebf8b 3858@node Signals
c906108c
SS
3859@section Signals
3860@cindex signals
3861
3862A signal is an asynchronous event that can happen in a program. The
3863operating system defines the possible kinds of signals, and gives each
3864kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3865signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3866@code{SIGSEGV} is the signal a program gets from referencing a place in
3867memory far away from all the areas in use; @code{SIGALRM} occurs when
3868the alarm clock timer goes off (which happens only if your program has
3869requested an alarm).
3870
3871@cindex fatal signals
3872Some signals, including @code{SIGALRM}, are a normal part of the
3873functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3874errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3875program has not specified in advance some other way to handle the signal.
3876@code{SIGINT} does not indicate an error in your program, but it is normally
3877fatal so it can carry out the purpose of the interrupt: to kill the program.
3878
3879@value{GDBN} has the ability to detect any occurrence of a signal in your
3880program. You can tell @value{GDBN} in advance what to do for each kind of
3881signal.
3882
3883@cindex handling signals
24f93129
EZ
3884Normally, @value{GDBN} is set up to let the non-erroneous signals like
3885@code{SIGALRM} be silently passed to your program
3886(so as not to interfere with their role in the program's functioning)
c906108c
SS
3887but to stop your program immediately whenever an error signal happens.
3888You can change these settings with the @code{handle} command.
3889
3890@table @code
3891@kindex info signals
09d4efe1 3892@kindex info handle
c906108c 3893@item info signals
96a2c332 3894@itemx info handle
c906108c
SS
3895Print a table of all the kinds of signals and how @value{GDBN} has been told to
3896handle each one. You can use this to see the signal numbers of all
3897the defined types of signals.
3898
d4f3574e 3899@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3900
3901@kindex handle
3902@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3903Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3904can be the number of a signal or its name (with or without the
24f93129 3905@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3906@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3907known signals. The @var{keywords} say what change to make.
c906108c
SS
3908@end table
3909
3910@c @group
3911The keywords allowed by the @code{handle} command can be abbreviated.
3912Their full names are:
3913
3914@table @code
3915@item nostop
3916@value{GDBN} should not stop your program when this signal happens. It may
3917still print a message telling you that the signal has come in.
3918
3919@item stop
3920@value{GDBN} should stop your program when this signal happens. This implies
3921the @code{print} keyword as well.
3922
3923@item print
3924@value{GDBN} should print a message when this signal happens.
3925
3926@item noprint
3927@value{GDBN} should not mention the occurrence of the signal at all. This
3928implies the @code{nostop} keyword as well.
3929
3930@item pass
5ece1a18 3931@itemx noignore
c906108c
SS
3932@value{GDBN} should allow your program to see this signal; your program
3933can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3934and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3935
3936@item nopass
5ece1a18 3937@itemx ignore
c906108c 3938@value{GDBN} should not allow your program to see this signal.
5ece1a18 3939@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3940@end table
3941@c @end group
3942
d4f3574e
SS
3943When a signal stops your program, the signal is not visible to the
3944program until you
c906108c
SS
3945continue. Your program sees the signal then, if @code{pass} is in
3946effect for the signal in question @emph{at that time}. In other words,
3947after @value{GDBN} reports a signal, you can use the @code{handle}
3948command with @code{pass} or @code{nopass} to control whether your
3949program sees that signal when you continue.
3950
24f93129
EZ
3951The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3952non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3953@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3954erroneous signals.
3955
c906108c
SS
3956You can also use the @code{signal} command to prevent your program from
3957seeing a signal, or cause it to see a signal it normally would not see,
3958or to give it any signal at any time. For example, if your program stopped
3959due to some sort of memory reference error, you might store correct
3960values into the erroneous variables and continue, hoping to see more
3961execution; but your program would probably terminate immediately as
3962a result of the fatal signal once it saw the signal. To prevent this,
3963you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3964program a signal}.
c906108c 3965
6d2ebf8b 3966@node Thread Stops
c906108c
SS
3967@section Stopping and starting multi-thread programs
3968
3969When your program has multiple threads (@pxref{Threads,, Debugging
3970programs with multiple threads}), you can choose whether to set
3971breakpoints on all threads, or on a particular thread.
3972
3973@table @code
3974@cindex breakpoints and threads
3975@cindex thread breakpoints
3976@kindex break @dots{} thread @var{threadno}
3977@item break @var{linespec} thread @var{threadno}
3978@itemx break @var{linespec} thread @var{threadno} if @dots{}
3979@var{linespec} specifies source lines; there are several ways of
3980writing them, but the effect is always to specify some source line.
3981
3982Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3983to specify that you only want @value{GDBN} to stop the program when a
3984particular thread reaches this breakpoint. @var{threadno} is one of the
3985numeric thread identifiers assigned by @value{GDBN}, shown in the first
3986column of the @samp{info threads} display.
3987
3988If you do not specify @samp{thread @var{threadno}} when you set a
3989breakpoint, the breakpoint applies to @emph{all} threads of your
3990program.
3991
3992You can use the @code{thread} qualifier on conditional breakpoints as
3993well; in this case, place @samp{thread @var{threadno}} before the
3994breakpoint condition, like this:
3995
3996@smallexample
2df3850c 3997(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3998@end smallexample
3999
4000@end table
4001
4002@cindex stopped threads
4003@cindex threads, stopped
4004Whenever your program stops under @value{GDBN} for any reason,
4005@emph{all} threads of execution stop, not just the current thread. This
4006allows you to examine the overall state of the program, including
4007switching between threads, without worrying that things may change
4008underfoot.
4009
36d86913
MC
4010@cindex thread breakpoints and system calls
4011@cindex system calls and thread breakpoints
4012@cindex premature return from system calls
4013There is an unfortunate side effect. If one thread stops for a
4014breakpoint, or for some other reason, and another thread is blocked in a
4015system call, then the system call may return prematurely. This is a
4016consequence of the interaction between multiple threads and the signals
4017that @value{GDBN} uses to implement breakpoints and other events that
4018stop execution.
4019
4020To handle this problem, your program should check the return value of
4021each system call and react appropriately. This is good programming
4022style anyways.
4023
4024For example, do not write code like this:
4025
4026@smallexample
4027 sleep (10);
4028@end smallexample
4029
4030The call to @code{sleep} will return early if a different thread stops
4031at a breakpoint or for some other reason.
4032
4033Instead, write this:
4034
4035@smallexample
4036 int unslept = 10;
4037 while (unslept > 0)
4038 unslept = sleep (unslept);
4039@end smallexample
4040
4041A system call is allowed to return early, so the system is still
4042conforming to its specification. But @value{GDBN} does cause your
4043multi-threaded program to behave differently than it would without
4044@value{GDBN}.
4045
4046Also, @value{GDBN} uses internal breakpoints in the thread library to
4047monitor certain events such as thread creation and thread destruction.
4048When such an event happens, a system call in another thread may return
4049prematurely, even though your program does not appear to stop.
4050
c906108c
SS
4051@cindex continuing threads
4052@cindex threads, continuing
4053Conversely, whenever you restart the program, @emph{all} threads start
4054executing. @emph{This is true even when single-stepping} with commands
5d161b24 4055like @code{step} or @code{next}.
c906108c
SS
4056
4057In particular, @value{GDBN} cannot single-step all threads in lockstep.
4058Since thread scheduling is up to your debugging target's operating
4059system (not controlled by @value{GDBN}), other threads may
4060execute more than one statement while the current thread completes a
4061single step. Moreover, in general other threads stop in the middle of a
4062statement, rather than at a clean statement boundary, when the program
4063stops.
4064
4065You might even find your program stopped in another thread after
4066continuing or even single-stepping. This happens whenever some other
4067thread runs into a breakpoint, a signal, or an exception before the
4068first thread completes whatever you requested.
4069
4070On some OSes, you can lock the OS scheduler and thus allow only a single
4071thread to run.
4072
4073@table @code
4074@item set scheduler-locking @var{mode}
9c16f35a
EZ
4075@cindex scheduler locking mode
4076@cindex lock scheduler
c906108c
SS
4077Set the scheduler locking mode. If it is @code{off}, then there is no
4078locking and any thread may run at any time. If @code{on}, then only the
4079current thread may run when the inferior is resumed. The @code{step}
4080mode optimizes for single-stepping. It stops other threads from
4081``seizing the prompt'' by preempting the current thread while you are
4082stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 4083when you step. They are more likely to run when you @samp{next} over a
c906108c 4084function call, and they are completely free to run when you use commands
d4f3574e 4085like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 4086thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 4087@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
4088
4089@item show scheduler-locking
4090Display the current scheduler locking mode.
4091@end table
4092
c906108c 4093
6d2ebf8b 4094@node Stack
c906108c
SS
4095@chapter Examining the Stack
4096
4097When your program has stopped, the first thing you need to know is where it
4098stopped and how it got there.
4099
4100@cindex call stack
5d161b24
DB
4101Each time your program performs a function call, information about the call
4102is generated.
4103That information includes the location of the call in your program,
4104the arguments of the call,
c906108c 4105and the local variables of the function being called.
5d161b24 4106The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
4107The stack frames are allocated in a region of memory called the @dfn{call
4108stack}.
4109
4110When your program stops, the @value{GDBN} commands for examining the
4111stack allow you to see all of this information.
4112
4113@cindex selected frame
4114One of the stack frames is @dfn{selected} by @value{GDBN} and many
4115@value{GDBN} commands refer implicitly to the selected frame. In
4116particular, whenever you ask @value{GDBN} for the value of a variable in
4117your program, the value is found in the selected frame. There are
4118special @value{GDBN} commands to select whichever frame you are
4119interested in. @xref{Selection, ,Selecting a frame}.
4120
4121When your program stops, @value{GDBN} automatically selects the
5d161b24 4122currently executing frame and describes it briefly, similar to the
c906108c
SS
4123@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
4124
4125@menu
4126* Frames:: Stack frames
4127* Backtrace:: Backtraces
4128* Selection:: Selecting a frame
4129* Frame Info:: Information on a frame
c906108c
SS
4130
4131@end menu
4132
6d2ebf8b 4133@node Frames
c906108c
SS
4134@section Stack frames
4135
d4f3574e 4136@cindex frame, definition
c906108c
SS
4137@cindex stack frame
4138The call stack is divided up into contiguous pieces called @dfn{stack
4139frames}, or @dfn{frames} for short; each frame is the data associated
4140with one call to one function. The frame contains the arguments given
4141to the function, the function's local variables, and the address at
4142which the function is executing.
4143
4144@cindex initial frame
4145@cindex outermost frame
4146@cindex innermost frame
4147When your program is started, the stack has only one frame, that of the
4148function @code{main}. This is called the @dfn{initial} frame or the
4149@dfn{outermost} frame. Each time a function is called, a new frame is
4150made. Each time a function returns, the frame for that function invocation
4151is eliminated. If a function is recursive, there can be many frames for
4152the same function. The frame for the function in which execution is
4153actually occurring is called the @dfn{innermost} frame. This is the most
4154recently created of all the stack frames that still exist.
4155
4156@cindex frame pointer
4157Inside your program, stack frames are identified by their addresses. A
4158stack frame consists of many bytes, each of which has its own address; each
4159kind of computer has a convention for choosing one byte whose
4160address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
4161in a register called the @dfn{frame pointer register}
4162(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
4163
4164@cindex frame number
4165@value{GDBN} assigns numbers to all existing stack frames, starting with
4166zero for the innermost frame, one for the frame that called it,
4167and so on upward. These numbers do not really exist in your program;
4168they are assigned by @value{GDBN} to give you a way of designating stack
4169frames in @value{GDBN} commands.
4170
6d2ebf8b
SS
4171@c The -fomit-frame-pointer below perennially causes hbox overflow
4172@c underflow problems.
c906108c
SS
4173@cindex frameless execution
4174Some compilers provide a way to compile functions so that they operate
6d2ebf8b 4175without stack frames. (For example, the @value{GCC} option
474c8240 4176@smallexample
6d2ebf8b 4177@samp{-fomit-frame-pointer}
474c8240 4178@end smallexample
6d2ebf8b 4179generates functions without a frame.)
c906108c
SS
4180This is occasionally done with heavily used library functions to save
4181the frame setup time. @value{GDBN} has limited facilities for dealing
4182with these function invocations. If the innermost function invocation
4183has no stack frame, @value{GDBN} nevertheless regards it as though
4184it had a separate frame, which is numbered zero as usual, allowing
4185correct tracing of the function call chain. However, @value{GDBN} has
4186no provision for frameless functions elsewhere in the stack.
4187
4188@table @code
d4f3574e 4189@kindex frame@r{, command}
41afff9a 4190@cindex current stack frame
c906108c 4191@item frame @var{args}
5d161b24 4192The @code{frame} command allows you to move from one stack frame to another,
c906108c 4193and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4194address of the frame or the stack frame number. Without an argument,
4195@code{frame} prints the current stack frame.
c906108c
SS
4196
4197@kindex select-frame
41afff9a 4198@cindex selecting frame silently
c906108c
SS
4199@item select-frame
4200The @code{select-frame} command allows you to move from one stack frame
4201to another without printing the frame. This is the silent version of
4202@code{frame}.
4203@end table
4204
6d2ebf8b 4205@node Backtrace
c906108c
SS
4206@section Backtraces
4207
09d4efe1
EZ
4208@cindex traceback
4209@cindex call stack traces
c906108c
SS
4210A backtrace is a summary of how your program got where it is. It shows one
4211line per frame, for many frames, starting with the currently executing
4212frame (frame zero), followed by its caller (frame one), and on up the
4213stack.
4214
4215@table @code
4216@kindex backtrace
41afff9a 4217@kindex bt @r{(@code{backtrace})}
c906108c
SS
4218@item backtrace
4219@itemx bt
4220Print a backtrace of the entire stack: one line per frame for all
4221frames in the stack.
4222
4223You can stop the backtrace at any time by typing the system interrupt
4224character, normally @kbd{C-c}.
4225
4226@item backtrace @var{n}
4227@itemx bt @var{n}
4228Similar, but print only the innermost @var{n} frames.
4229
4230@item backtrace -@var{n}
4231@itemx bt -@var{n}
4232Similar, but print only the outermost @var{n} frames.
0f061b69
NR
4233
4234@item backtrace full
4235Print the values of the local variables also.
4236@itemx bt full
c906108c
SS
4237@end table
4238
4239@kindex where
4240@kindex info stack
c906108c
SS
4241The names @code{where} and @code{info stack} (abbreviated @code{info s})
4242are additional aliases for @code{backtrace}.
4243
4244Each line in the backtrace shows the frame number and the function name.
4245The program counter value is also shown---unless you use @code{set
4246print address off}. The backtrace also shows the source file name and
4247line number, as well as the arguments to the function. The program
4248counter value is omitted if it is at the beginning of the code for that
4249line number.
4250
4251Here is an example of a backtrace. It was made with the command
4252@samp{bt 3}, so it shows the innermost three frames.
4253
4254@smallexample
4255@group
5d161b24 4256#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4257 at builtin.c:993
4258#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4259#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4260 at macro.c:71
4261(More stack frames follow...)
4262@end group
4263@end smallexample
4264
4265@noindent
4266The display for frame zero does not begin with a program counter
4267value, indicating that your program has stopped at the beginning of the
4268code for line @code{993} of @code{builtin.c}.
4269
18999be5
EZ
4270@cindex value optimized out, in backtrace
4271@cindex function call arguments, optimized out
4272If your program was compiled with optimizations, some compilers will
4273optimize away arguments passed to functions if those arguments are
4274never used after the call. Such optimizations generate code that
4275passes arguments through registers, but doesn't store those arguments
4276in the stack frame. @value{GDBN} has no way of displaying such
4277arguments in stack frames other than the innermost one. Here's what
4278such a backtrace might look like:
4279
4280@smallexample
4281@group
4282#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4283 at builtin.c:993
4284#1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
4285#2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
4286 at macro.c:71
4287(More stack frames follow...)
4288@end group
4289@end smallexample
4290
4291@noindent
4292The values of arguments that were not saved in their stack frames are
4293shown as @samp{<value optimized out>}.
4294
4295If you need to display the values of such optimized-out arguments,
4296either deduce that from other variables whose values depend on the one
4297you are interested in, or recompile without optimizations.
4298
a8f24a35
EZ
4299@cindex backtrace beyond @code{main} function
4300@cindex program entry point
4301@cindex startup code, and backtrace
25d29d70
AC
4302Most programs have a standard user entry point---a place where system
4303libraries and startup code transition into user code. For C this is
d416eeec
EZ
4304@code{main}@footnote{
4305Note that embedded programs (the so-called ``free-standing''
4306environment) are not required to have a @code{main} function as the
4307entry point. They could even have multiple entry points.}.
4308When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
4309it will terminate the backtrace, to avoid tracing into highly
4310system-specific (and generally uninteresting) code.
4311
4312If you need to examine the startup code, or limit the number of levels
4313in a backtrace, you can change this behavior:
95f90d25
DJ
4314
4315@table @code
25d29d70
AC
4316@item set backtrace past-main
4317@itemx set backtrace past-main on
4644b6e3 4318@kindex set backtrace
25d29d70
AC
4319Backtraces will continue past the user entry point.
4320
4321@item set backtrace past-main off
95f90d25
DJ
4322Backtraces will stop when they encounter the user entry point. This is the
4323default.
4324
25d29d70 4325@item show backtrace past-main
4644b6e3 4326@kindex show backtrace
25d29d70
AC
4327Display the current user entry point backtrace policy.
4328
2315ffec
RC
4329@item set backtrace past-entry
4330@itemx set backtrace past-entry on
a8f24a35 4331Backtraces will continue past the internal entry point of an application.
2315ffec
RC
4332This entry point is encoded by the linker when the application is built,
4333and is likely before the user entry point @code{main} (or equivalent) is called.
4334
4335@item set backtrace past-entry off
4336Backtraces will stop when they encouter the internal entry point of an
4337application. This is the default.
4338
4339@item show backtrace past-entry
4340Display the current internal entry point backtrace policy.
4341
25d29d70
AC
4342@item set backtrace limit @var{n}
4343@itemx set backtrace limit 0
4344@cindex backtrace limit
4345Limit the backtrace to @var{n} levels. A value of zero means
4346unlimited.
95f90d25 4347
25d29d70
AC
4348@item show backtrace limit
4349Display the current limit on backtrace levels.
95f90d25
DJ
4350@end table
4351
6d2ebf8b 4352@node Selection
c906108c
SS
4353@section Selecting a frame
4354
4355Most commands for examining the stack and other data in your program work on
4356whichever stack frame is selected at the moment. Here are the commands for
4357selecting a stack frame; all of them finish by printing a brief description
4358of the stack frame just selected.
4359
4360@table @code
d4f3574e 4361@kindex frame@r{, selecting}
41afff9a 4362@kindex f @r{(@code{frame})}
c906108c
SS
4363@item frame @var{n}
4364@itemx f @var{n}
4365Select frame number @var{n}. Recall that frame zero is the innermost
4366(currently executing) frame, frame one is the frame that called the
4367innermost one, and so on. The highest-numbered frame is the one for
4368@code{main}.
4369
4370@item frame @var{addr}
4371@itemx f @var{addr}
4372Select the frame at address @var{addr}. This is useful mainly if the
4373chaining of stack frames has been damaged by a bug, making it
4374impossible for @value{GDBN} to assign numbers properly to all frames. In
4375addition, this can be useful when your program has multiple stacks and
4376switches between them.
4377
c906108c
SS
4378On the SPARC architecture, @code{frame} needs two addresses to
4379select an arbitrary frame: a frame pointer and a stack pointer.
4380
4381On the MIPS and Alpha architecture, it needs two addresses: a stack
4382pointer and a program counter.
4383
4384On the 29k architecture, it needs three addresses: a register stack
4385pointer, a program counter, and a memory stack pointer.
c906108c
SS
4386
4387@kindex up
4388@item up @var{n}
4389Move @var{n} frames up the stack. For positive numbers @var{n}, this
4390advances toward the outermost frame, to higher frame numbers, to frames
4391that have existed longer. @var{n} defaults to one.
4392
4393@kindex down
41afff9a 4394@kindex do @r{(@code{down})}
c906108c
SS
4395@item down @var{n}
4396Move @var{n} frames down the stack. For positive numbers @var{n}, this
4397advances toward the innermost frame, to lower frame numbers, to frames
4398that were created more recently. @var{n} defaults to one. You may
4399abbreviate @code{down} as @code{do}.
4400@end table
4401
4402All of these commands end by printing two lines of output describing the
4403frame. The first line shows the frame number, the function name, the
4404arguments, and the source file and line number of execution in that
5d161b24 4405frame. The second line shows the text of that source line.
c906108c
SS
4406
4407@need 1000
4408For example:
4409
4410@smallexample
4411@group
4412(@value{GDBP}) up
4413#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4414 at env.c:10
441510 read_input_file (argv[i]);
4416@end group
4417@end smallexample
4418
4419After such a printout, the @code{list} command with no arguments
4420prints ten lines centered on the point of execution in the frame.
87885426
FN
4421You can also edit the program at the point of execution with your favorite
4422editing program by typing @code{edit}.
4423@xref{List, ,Printing source lines},
4424for details.
c906108c
SS
4425
4426@table @code
4427@kindex down-silently
4428@kindex up-silently
4429@item up-silently @var{n}
4430@itemx down-silently @var{n}
4431These two commands are variants of @code{up} and @code{down},
4432respectively; they differ in that they do their work silently, without
4433causing display of the new frame. They are intended primarily for use
4434in @value{GDBN} command scripts, where the output might be unnecessary and
4435distracting.
4436@end table
4437
6d2ebf8b 4438@node Frame Info
c906108c
SS
4439@section Information about a frame
4440
4441There are several other commands to print information about the selected
4442stack frame.
4443
4444@table @code
4445@item frame
4446@itemx f
4447When used without any argument, this command does not change which
4448frame is selected, but prints a brief description of the currently
4449selected stack frame. It can be abbreviated @code{f}. With an
4450argument, this command is used to select a stack frame.
4451@xref{Selection, ,Selecting a frame}.
4452
4453@kindex info frame
41afff9a 4454@kindex info f @r{(@code{info frame})}
c906108c
SS
4455@item info frame
4456@itemx info f
4457This command prints a verbose description of the selected stack frame,
4458including:
4459
4460@itemize @bullet
5d161b24
DB
4461@item
4462the address of the frame
c906108c
SS
4463@item
4464the address of the next frame down (called by this frame)
4465@item
4466the address of the next frame up (caller of this frame)
4467@item
4468the language in which the source code corresponding to this frame is written
4469@item
4470the address of the frame's arguments
4471@item
d4f3574e
SS
4472the address of the frame's local variables
4473@item
c906108c
SS
4474the program counter saved in it (the address of execution in the caller frame)
4475@item
4476which registers were saved in the frame
4477@end itemize
4478
4479@noindent The verbose description is useful when
4480something has gone wrong that has made the stack format fail to fit
4481the usual conventions.
4482
4483@item info frame @var{addr}
4484@itemx info f @var{addr}
4485Print a verbose description of the frame at address @var{addr}, without
4486selecting that frame. The selected frame remains unchanged by this
4487command. This requires the same kind of address (more than one for some
4488architectures) that you specify in the @code{frame} command.
4489@xref{Selection, ,Selecting a frame}.
4490
4491@kindex info args
4492@item info args
4493Print the arguments of the selected frame, each on a separate line.
4494
4495@item info locals
4496@kindex info locals
4497Print the local variables of the selected frame, each on a separate
4498line. These are all variables (declared either static or automatic)
4499accessible at the point of execution of the selected frame.
4500
c906108c 4501@kindex info catch
d4f3574e
SS
4502@cindex catch exceptions, list active handlers
4503@cindex exception handlers, how to list
c906108c
SS
4504@item info catch
4505Print a list of all the exception handlers that are active in the
4506current stack frame at the current point of execution. To see other
4507exception handlers, visit the associated frame (using the @code{up},
4508@code{down}, or @code{frame} commands); then type @code{info catch}.
4509@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4510
c906108c
SS
4511@end table
4512
c906108c 4513
6d2ebf8b 4514@node Source
c906108c
SS
4515@chapter Examining Source Files
4516
4517@value{GDBN} can print parts of your program's source, since the debugging
4518information recorded in the program tells @value{GDBN} what source files were
4519used to build it. When your program stops, @value{GDBN} spontaneously prints
4520the line where it stopped. Likewise, when you select a stack frame
4521(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4522execution in that frame has stopped. You can print other portions of
4523source files by explicit command.
4524
7a292a7a 4525If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4526prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4527@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4528
4529@menu
4530* List:: Printing source lines
87885426 4531* Edit:: Editing source files
c906108c 4532* Search:: Searching source files
c906108c
SS
4533* Source Path:: Specifying source directories
4534* Machine Code:: Source and machine code
4535@end menu
4536
6d2ebf8b 4537@node List
c906108c
SS
4538@section Printing source lines
4539
4540@kindex list
41afff9a 4541@kindex l @r{(@code{list})}
c906108c 4542To print lines from a source file, use the @code{list} command
5d161b24 4543(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4544There are several ways to specify what part of the file you want to print.
4545
4546Here are the forms of the @code{list} command most commonly used:
4547
4548@table @code
4549@item list @var{linenum}
4550Print lines centered around line number @var{linenum} in the
4551current source file.
4552
4553@item list @var{function}
4554Print lines centered around the beginning of function
4555@var{function}.
4556
4557@item list
4558Print more lines. If the last lines printed were printed with a
4559@code{list} command, this prints lines following the last lines
4560printed; however, if the last line printed was a solitary line printed
4561as part of displaying a stack frame (@pxref{Stack, ,Examining the
4562Stack}), this prints lines centered around that line.
4563
4564@item list -
4565Print lines just before the lines last printed.
4566@end table
4567
9c16f35a 4568@cindex @code{list}, how many lines to display
c906108c
SS
4569By default, @value{GDBN} prints ten source lines with any of these forms of
4570the @code{list} command. You can change this using @code{set listsize}:
4571
4572@table @code
4573@kindex set listsize
4574@item set listsize @var{count}
4575Make the @code{list} command display @var{count} source lines (unless
4576the @code{list} argument explicitly specifies some other number).
4577
4578@kindex show listsize
4579@item show listsize
4580Display the number of lines that @code{list} prints.
4581@end table
4582
4583Repeating a @code{list} command with @key{RET} discards the argument,
4584so it is equivalent to typing just @code{list}. This is more useful
4585than listing the same lines again. An exception is made for an
4586argument of @samp{-}; that argument is preserved in repetition so that
4587each repetition moves up in the source file.
4588
4589@cindex linespec
4590In general, the @code{list} command expects you to supply zero, one or two
4591@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4592of writing them, but the effect is always to specify some source line.
c906108c
SS
4593Here is a complete description of the possible arguments for @code{list}:
4594
4595@table @code
4596@item list @var{linespec}
4597Print lines centered around the line specified by @var{linespec}.
4598
4599@item list @var{first},@var{last}
4600Print lines from @var{first} to @var{last}. Both arguments are
4601linespecs.
4602
4603@item list ,@var{last}
4604Print lines ending with @var{last}.
4605
4606@item list @var{first},
4607Print lines starting with @var{first}.
4608
4609@item list +
4610Print lines just after the lines last printed.
4611
4612@item list -
4613Print lines just before the lines last printed.
4614
4615@item list
4616As described in the preceding table.
4617@end table
4618
4619Here are the ways of specifying a single source line---all the
4620kinds of linespec.
4621
4622@table @code
4623@item @var{number}
4624Specifies line @var{number} of the current source file.
4625When a @code{list} command has two linespecs, this refers to
4626the same source file as the first linespec.
4627
4628@item +@var{offset}
4629Specifies the line @var{offset} lines after the last line printed.
4630When used as the second linespec in a @code{list} command that has
4631two, this specifies the line @var{offset} lines down from the
4632first linespec.
4633
4634@item -@var{offset}
4635Specifies the line @var{offset} lines before the last line printed.
4636
4637@item @var{filename}:@var{number}
4638Specifies line @var{number} in the source file @var{filename}.
4639
4640@item @var{function}
4641Specifies the line that begins the body of the function @var{function}.
4642For example: in C, this is the line with the open brace.
4643
4644@item @var{filename}:@var{function}
4645Specifies the line of the open-brace that begins the body of the
4646function @var{function} in the file @var{filename}. You only need the
4647file name with a function name to avoid ambiguity when there are
4648identically named functions in different source files.
4649
4650@item *@var{address}
4651Specifies the line containing the program address @var{address}.
4652@var{address} may be any expression.
4653@end table
4654
87885426
FN
4655@node Edit
4656@section Editing source files
4657@cindex editing source files
4658
4659@kindex edit
4660@kindex e @r{(@code{edit})}
4661To edit the lines in a source file, use the @code{edit} command.
4662The editing program of your choice
4663is invoked with the current line set to
4664the active line in the program.
4665Alternatively, there are several ways to specify what part of the file you
4666want to print if you want to see other parts of the program.
4667
4668Here are the forms of the @code{edit} command most commonly used:
4669
4670@table @code
4671@item edit
4672Edit the current source file at the active line number in the program.
4673
4674@item edit @var{number}
4675Edit the current source file with @var{number} as the active line number.
4676
4677@item edit @var{function}
4678Edit the file containing @var{function} at the beginning of its definition.
4679
4680@item edit @var{filename}:@var{number}
4681Specifies line @var{number} in the source file @var{filename}.
4682
4683@item edit @var{filename}:@var{function}
4684Specifies the line that begins the body of the
4685function @var{function} in the file @var{filename}. You only need the
4686file name with a function name to avoid ambiguity when there are
4687identically named functions in different source files.
4688
4689@item edit *@var{address}
4690Specifies the line containing the program address @var{address}.
4691@var{address} may be any expression.
4692@end table
4693
4694@subsection Choosing your editor
4695You can customize @value{GDBN} to use any editor you want
4696@footnote{
4697The only restriction is that your editor (say @code{ex}), recognizes the
4698following command-line syntax:
10998722 4699@smallexample
87885426 4700ex +@var{number} file
10998722 4701@end smallexample
15387254
EZ
4702The optional numeric value +@var{number} specifies the number of the line in
4703the file where to start editing.}.
4704By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4705by setting the environment variable @code{EDITOR} before using
4706@value{GDBN}. For example, to configure @value{GDBN} to use the
4707@code{vi} editor, you could use these commands with the @code{sh} shell:
4708@smallexample
87885426
FN
4709EDITOR=/usr/bin/vi
4710export EDITOR
15387254 4711gdb @dots{}
10998722 4712@end smallexample
87885426 4713or in the @code{csh} shell,
10998722 4714@smallexample
87885426 4715setenv EDITOR /usr/bin/vi
15387254 4716gdb @dots{}
10998722 4717@end smallexample
87885426 4718
6d2ebf8b 4719@node Search
c906108c 4720@section Searching source files
15387254 4721@cindex searching source files
c906108c
SS
4722
4723There are two commands for searching through the current source file for a
4724regular expression.
4725
4726@table @code
4727@kindex search
4728@kindex forward-search
4729@item forward-search @var{regexp}
4730@itemx search @var{regexp}
4731The command @samp{forward-search @var{regexp}} checks each line,
4732starting with the one following the last line listed, for a match for
5d161b24 4733@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4734synonym @samp{search @var{regexp}} or abbreviate the command name as
4735@code{fo}.
4736
09d4efe1 4737@kindex reverse-search
c906108c
SS
4738@item reverse-search @var{regexp}
4739The command @samp{reverse-search @var{regexp}} checks each line, starting
4740with the one before the last line listed and going backward, for a match
4741for @var{regexp}. It lists the line that is found. You can abbreviate
4742this command as @code{rev}.
4743@end table
c906108c 4744
6d2ebf8b 4745@node Source Path
c906108c
SS
4746@section Specifying source directories
4747
4748@cindex source path
4749@cindex directories for source files
4750Executable programs sometimes do not record the directories of the source
4751files from which they were compiled, just the names. Even when they do,
4752the directories could be moved between the compilation and your debugging
4753session. @value{GDBN} has a list of directories to search for source files;
4754this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4755it tries all the directories in the list, in the order they are present
0b66e38c
EZ
4756in the list, until it finds a file with the desired name.
4757
4758For example, suppose an executable references the file
4759@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4760@file{/mnt/cross}. The file is first looked up literally; if this
4761fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4762fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4763message is printed. @value{GDBN} does not look up the parts of the
4764source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4765Likewise, the subdirectories of the source path are not searched: if
4766the source path is @file{/mnt/cross}, and the binary refers to
4767@file{foo.c}, @value{GDBN} would not find it under
4768@file{/mnt/cross/usr/src/foo-1.0/lib}.
4769
4770Plain file names, relative file names with leading directories, file
4771names containing dots, etc.@: are all treated as described above; for
4772instance, if the source path is @file{/mnt/cross}, and the source file
4773is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4774@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4775that---@file{/mnt/cross/foo.c}.
4776
4777Note that the executable search path is @emph{not} used to locate the
4778source files. Neither is the current working directory, unless it
4779happens to be in the source path.
c906108c
SS
4780
4781Whenever you reset or rearrange the source path, @value{GDBN} clears out
4782any information it has cached about where source files are found and where
4783each line is in the file.
4784
4785@kindex directory
4786@kindex dir
d4f3574e
SS
4787When you start @value{GDBN}, its source path includes only @samp{cdir}
4788and @samp{cwd}, in that order.
c906108c
SS
4789To add other directories, use the @code{directory} command.
4790
4791@table @code
4792@item directory @var{dirname} @dots{}
4793@item dir @var{dirname} @dots{}
4794Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4795directory names may be given to this command, separated by @samp{:}
4796(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4797part of absolute file names) or
c906108c
SS
4798whitespace. You may specify a directory that is already in the source
4799path; this moves it forward, so @value{GDBN} searches it sooner.
4800
4801@kindex cdir
4802@kindex cwd
41afff9a
EZ
4803@vindex $cdir@r{, convenience variable}
4804@vindex $cwdr@r{, convenience variable}
c906108c
SS
4805@cindex compilation directory
4806@cindex current directory
4807@cindex working directory
4808@cindex directory, current
4809@cindex directory, compilation
4810You can use the string @samp{$cdir} to refer to the compilation
4811directory (if one is recorded), and @samp{$cwd} to refer to the current
4812working directory. @samp{$cwd} is not the same as @samp{.}---the former
4813tracks the current working directory as it changes during your @value{GDBN}
4814session, while the latter is immediately expanded to the current
4815directory at the time you add an entry to the source path.
4816
4817@item directory
4818Reset the source path to empty again. This requires confirmation.
4819
4820@c RET-repeat for @code{directory} is explicitly disabled, but since
4821@c repeating it would be a no-op we do not say that. (thanks to RMS)
4822
4823@item show directories
4824@kindex show directories
4825Print the source path: show which directories it contains.
4826@end table
4827
4828If your source path is cluttered with directories that are no longer of
4829interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4830versions of source. You can correct the situation as follows:
4831
4832@enumerate
4833@item
4834Use @code{directory} with no argument to reset the source path to empty.
4835
4836@item
4837Use @code{directory} with suitable arguments to reinstall the
4838directories you want in the source path. You can add all the
4839directories in one command.
4840@end enumerate
4841
6d2ebf8b 4842@node Machine Code
c906108c 4843@section Source and machine code
15387254 4844@cindex source line and its code address
c906108c
SS
4845
4846You can use the command @code{info line} to map source lines to program
4847addresses (and vice versa), and the command @code{disassemble} to display
4848a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4849mode, the @code{info line} command causes the arrow to point to the
5d161b24 4850line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4851well as hex.
4852
4853@table @code
4854@kindex info line
4855@item info line @var{linespec}
4856Print the starting and ending addresses of the compiled code for
4857source line @var{linespec}. You can specify source lines in any of
4858the ways understood by the @code{list} command (@pxref{List, ,Printing
4859source lines}).
4860@end table
4861
4862For example, we can use @code{info line} to discover the location of
4863the object code for the first line of function
4864@code{m4_changequote}:
4865
d4f3574e
SS
4866@c FIXME: I think this example should also show the addresses in
4867@c symbolic form, as they usually would be displayed.
c906108c 4868@smallexample
96a2c332 4869(@value{GDBP}) info line m4_changequote
c906108c
SS
4870Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4871@end smallexample
4872
4873@noindent
15387254 4874@cindex code address and its source line
c906108c
SS
4875We can also inquire (using @code{*@var{addr}} as the form for
4876@var{linespec}) what source line covers a particular address:
4877@smallexample
4878(@value{GDBP}) info line *0x63ff
4879Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4880@end smallexample
4881
4882@cindex @code{$_} and @code{info line}
15387254 4883@cindex @code{x} command, default address
41afff9a 4884@kindex x@r{(examine), and} info line
c906108c
SS
4885After @code{info line}, the default address for the @code{x} command
4886is changed to the starting address of the line, so that @samp{x/i} is
4887sufficient to begin examining the machine code (@pxref{Memory,
4888,Examining memory}). Also, this address is saved as the value of the
4889convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4890variables}).
4891
4892@table @code
4893@kindex disassemble
4894@cindex assembly instructions
4895@cindex instructions, assembly
4896@cindex machine instructions
4897@cindex listing machine instructions
4898@item disassemble
4899This specialized command dumps a range of memory as machine
4900instructions. The default memory range is the function surrounding the
4901program counter of the selected frame. A single argument to this
4902command is a program counter value; @value{GDBN} dumps the function
4903surrounding this value. Two arguments specify a range of addresses
4904(first inclusive, second exclusive) to dump.
4905@end table
4906
c906108c
SS
4907The following example shows the disassembly of a range of addresses of
4908HP PA-RISC 2.0 code:
4909
4910@smallexample
4911(@value{GDBP}) disas 0x32c4 0x32e4
4912Dump of assembler code from 0x32c4 to 0x32e4:
49130x32c4 <main+204>: addil 0,dp
49140x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
49150x32cc <main+212>: ldil 0x3000,r31
49160x32d0 <main+216>: ble 0x3f8(sr4,r31)
49170x32d4 <main+220>: ldo 0(r31),rp
49180x32d8 <main+224>: addil -0x800,dp
49190x32dc <main+228>: ldo 0x588(r1),r26
49200x32e0 <main+232>: ldil 0x3000,r31
4921End of assembler dump.
4922@end smallexample
c906108c
SS
4923
4924Some architectures have more than one commonly-used set of instruction
4925mnemonics or other syntax.
4926
76d17f34
EZ
4927For programs that were dynamically linked and use shared libraries,
4928instructions that call functions or branch to locations in the shared
4929libraries might show a seemingly bogus location---it's actually a
4930location of the relocation table. On some architectures, @value{GDBN}
4931might be able to resolve these to actual function names.
4932
c906108c 4933@table @code
d4f3574e 4934@kindex set disassembly-flavor
d4f3574e
SS
4935@cindex Intel disassembly flavor
4936@cindex AT&T disassembly flavor
4937@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4938Select the instruction set to use when disassembling the
4939program via the @code{disassemble} or @code{x/i} commands.
4940
4941Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4942can set @var{instruction-set} to either @code{intel} or @code{att}.
4943The default is @code{att}, the AT&T flavor used by default by Unix
4944assemblers for x86-based targets.
9c16f35a
EZ
4945
4946@kindex show disassembly-flavor
4947@item show disassembly-flavor
4948Show the current setting of the disassembly flavor.
c906108c
SS
4949@end table
4950
4951
6d2ebf8b 4952@node Data
c906108c
SS
4953@chapter Examining Data
4954
4955@cindex printing data
4956@cindex examining data
4957@kindex print
4958@kindex inspect
4959@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4960@c document because it is nonstandard... Under Epoch it displays in a
4961@c different window or something like that.
4962The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4963command (abbreviated @code{p}), or its synonym @code{inspect}. It
4964evaluates and prints the value of an expression of the language your
4965program is written in (@pxref{Languages, ,Using @value{GDBN} with
4966Different Languages}).
c906108c
SS
4967
4968@table @code
d4f3574e
SS
4969@item print @var{expr}
4970@itemx print /@var{f} @var{expr}
4971@var{expr} is an expression (in the source language). By default the
4972value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4973you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4974@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4975formats}.
4976
4977@item print
4978@itemx print /@var{f}
15387254 4979@cindex reprint the last value
d4f3574e 4980If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4981@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4982conveniently inspect the same value in an alternative format.
4983@end table
4984
4985A more low-level way of examining data is with the @code{x} command.
4986It examines data in memory at a specified address and prints it in a
4987specified format. @xref{Memory, ,Examining memory}.
4988
7a292a7a 4989If you are interested in information about types, or about how the
d4f3574e
SS
4990fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4991command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4992Table}.
c906108c
SS
4993
4994@menu
4995* Expressions:: Expressions
4996* Variables:: Program variables
4997* Arrays:: Artificial arrays
4998* Output Formats:: Output formats
4999* Memory:: Examining memory
5000* Auto Display:: Automatic display
5001* Print Settings:: Print settings
5002* Value History:: Value history
5003* Convenience Vars:: Convenience variables
5004* Registers:: Registers
c906108c 5005* Floating Point Hardware:: Floating point hardware
53c69bd7 5006* Vector Unit:: Vector Unit
721c2651 5007* OS Information:: Auxiliary data provided by operating system
29e57380 5008* Memory Region Attributes:: Memory region attributes
16d9dec6 5009* Dump/Restore Files:: Copy between memory and a file
384ee23f 5010* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
5011* Character Sets:: Debugging programs that use a different
5012 character set than GDB does
09d4efe1 5013* Caching Remote Data:: Data caching for remote targets
c906108c
SS
5014@end menu
5015
6d2ebf8b 5016@node Expressions
c906108c
SS
5017@section Expressions
5018
5019@cindex expressions
5020@code{print} and many other @value{GDBN} commands accept an expression and
5021compute its value. Any kind of constant, variable or operator defined
5022by the programming language you are using is valid in an expression in
e2e0bcd1
JB
5023@value{GDBN}. This includes conditional expressions, function calls,
5024casts, and string constants. It also includes preprocessor macros, if
5025you compiled your program to include this information; see
5026@ref{Compilation}.
c906108c 5027
15387254 5028@cindex arrays in expressions
d4f3574e
SS
5029@value{GDBN} supports array constants in expressions input by
5030the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 5031you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 5032memory that is @code{malloc}ed in the target program.
c906108c 5033
c906108c
SS
5034Because C is so widespread, most of the expressions shown in examples in
5035this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
5036Languages}, for information on how to use expressions in other
5037languages.
5038
5039In this section, we discuss operators that you can use in @value{GDBN}
5040expressions regardless of your programming language.
5041
15387254 5042@cindex casts, in expressions
c906108c
SS
5043Casts are supported in all languages, not just in C, because it is so
5044useful to cast a number into a pointer in order to examine a structure
5045at that address in memory.
5046@c FIXME: casts supported---Mod2 true?
c906108c
SS
5047
5048@value{GDBN} supports these operators, in addition to those common
5049to programming languages:
5050
5051@table @code
5052@item @@
5053@samp{@@} is a binary operator for treating parts of memory as arrays.
5054@xref{Arrays, ,Artificial arrays}, for more information.
5055
5056@item ::
5057@samp{::} allows you to specify a variable in terms of the file or
5058function where it is defined. @xref{Variables, ,Program variables}.
5059
5060@cindex @{@var{type}@}
5061@cindex type casting memory
5062@cindex memory, viewing as typed object
5063@cindex casts, to view memory
5064@item @{@var{type}@} @var{addr}
5065Refers to an object of type @var{type} stored at address @var{addr} in
5066memory. @var{addr} may be any expression whose value is an integer or
5067pointer (but parentheses are required around binary operators, just as in
5068a cast). This construct is allowed regardless of what kind of data is
5069normally supposed to reside at @var{addr}.
5070@end table
5071
6d2ebf8b 5072@node Variables
c906108c
SS
5073@section Program variables
5074
5075The most common kind of expression to use is the name of a variable
5076in your program.
5077
5078Variables in expressions are understood in the selected stack frame
5079(@pxref{Selection, ,Selecting a frame}); they must be either:
5080
5081@itemize @bullet
5082@item
5083global (or file-static)
5084@end itemize
5085
5d161b24 5086@noindent or
c906108c
SS
5087
5088@itemize @bullet
5089@item
5090visible according to the scope rules of the
5091programming language from the point of execution in that frame
5d161b24 5092@end itemize
c906108c
SS
5093
5094@noindent This means that in the function
5095
474c8240 5096@smallexample
c906108c
SS
5097foo (a)
5098 int a;
5099@{
5100 bar (a);
5101 @{
5102 int b = test ();
5103 bar (b);
5104 @}
5105@}
474c8240 5106@end smallexample
c906108c
SS
5107
5108@noindent
5109you can examine and use the variable @code{a} whenever your program is
5110executing within the function @code{foo}, but you can only use or
5111examine the variable @code{b} while your program is executing inside
5112the block where @code{b} is declared.
5113
5114@cindex variable name conflict
5115There is an exception: you can refer to a variable or function whose
5116scope is a single source file even if the current execution point is not
5117in this file. But it is possible to have more than one such variable or
5118function with the same name (in different source files). If that
5119happens, referring to that name has unpredictable effects. If you wish,
5120you can specify a static variable in a particular function or file,
15387254 5121using the colon-colon (@code{::}) notation:
c906108c 5122
d4f3574e 5123@cindex colon-colon, context for variables/functions
c906108c
SS
5124@iftex
5125@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 5126@cindex @code{::}, context for variables/functions
c906108c 5127@end iftex
474c8240 5128@smallexample
c906108c
SS
5129@var{file}::@var{variable}
5130@var{function}::@var{variable}
474c8240 5131@end smallexample
c906108c
SS
5132
5133@noindent
5134Here @var{file} or @var{function} is the name of the context for the
5135static @var{variable}. In the case of file names, you can use quotes to
5136make sure @value{GDBN} parses the file name as a single word---for example,
5137to print a global value of @code{x} defined in @file{f2.c}:
5138
474c8240 5139@smallexample
c906108c 5140(@value{GDBP}) p 'f2.c'::x
474c8240 5141@end smallexample
c906108c 5142
b37052ae 5143@cindex C@t{++} scope resolution
c906108c 5144This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 5145use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
5146scope resolution operator in @value{GDBN} expressions.
5147@c FIXME: Um, so what happens in one of those rare cases where it's in
5148@c conflict?? --mew
c906108c
SS
5149
5150@cindex wrong values
5151@cindex variable values, wrong
15387254
EZ
5152@cindex function entry/exit, wrong values of variables
5153@cindex optimized code, wrong values of variables
c906108c
SS
5154@quotation
5155@emph{Warning:} Occasionally, a local variable may appear to have the
5156wrong value at certain points in a function---just after entry to a new
5157scope, and just before exit.
5158@end quotation
5159You may see this problem when you are stepping by machine instructions.
5160This is because, on most machines, it takes more than one instruction to
5161set up a stack frame (including local variable definitions); if you are
5162stepping by machine instructions, variables may appear to have the wrong
5163values until the stack frame is completely built. On exit, it usually
5164also takes more than one machine instruction to destroy a stack frame;
5165after you begin stepping through that group of instructions, local
5166variable definitions may be gone.
5167
5168This may also happen when the compiler does significant optimizations.
5169To be sure of always seeing accurate values, turn off all optimization
5170when compiling.
5171
d4f3574e
SS
5172@cindex ``No symbol "foo" in current context''
5173Another possible effect of compiler optimizations is to optimize
5174unused variables out of existence, or assign variables to registers (as
5175opposed to memory addresses). Depending on the support for such cases
5176offered by the debug info format used by the compiler, @value{GDBN}
5177might not be able to display values for such local variables. If that
5178happens, @value{GDBN} will print a message like this:
5179
474c8240 5180@smallexample
d4f3574e 5181No symbol "foo" in current context.
474c8240 5182@end smallexample
d4f3574e
SS
5183
5184To solve such problems, either recompile without optimizations, or use a
5185different debug info format, if the compiler supports several such
15387254 5186formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
5187usually supports the @option{-gstabs+} option. @option{-gstabs+}
5188produces debug info in a format that is superior to formats such as
5189COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5190an effective form for debug info. @xref{Debugging Options,,Options
5191for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
5192@xref{C, , Debugging C++}, for more info about debug info formats
5193that are best suited to C@t{++} programs.
d4f3574e 5194
ab1adacd
EZ
5195If you ask to print an object whose contents are unknown to
5196@value{GDBN}, e.g., because its data type is not completely specified
5197by the debug information, @value{GDBN} will say @samp{<incomplete
5198type>}. @xref{Symbols, incomplete type}, for more about this.
5199
6d2ebf8b 5200@node Arrays
c906108c
SS
5201@section Artificial arrays
5202
5203@cindex artificial array
15387254 5204@cindex arrays
41afff9a 5205@kindex @@@r{, referencing memory as an array}
c906108c
SS
5206It is often useful to print out several successive objects of the
5207same type in memory; a section of an array, or an array of
5208dynamically determined size for which only a pointer exists in the
5209program.
5210
5211You can do this by referring to a contiguous span of memory as an
5212@dfn{artificial array}, using the binary operator @samp{@@}. The left
5213operand of @samp{@@} should be the first element of the desired array
5214and be an individual object. The right operand should be the desired length
5215of the array. The result is an array value whose elements are all of
5216the type of the left argument. The first element is actually the left
5217argument; the second element comes from bytes of memory immediately
5218following those that hold the first element, and so on. Here is an
5219example. If a program says
5220
474c8240 5221@smallexample
c906108c 5222int *array = (int *) malloc (len * sizeof (int));
474c8240 5223@end smallexample
c906108c
SS
5224
5225@noindent
5226you can print the contents of @code{array} with
5227
474c8240 5228@smallexample
c906108c 5229p *array@@len
474c8240 5230@end smallexample
c906108c
SS
5231
5232The left operand of @samp{@@} must reside in memory. Array values made
5233with @samp{@@} in this way behave just like other arrays in terms of
5234subscripting, and are coerced to pointers when used in expressions.
5235Artificial arrays most often appear in expressions via the value history
5236(@pxref{Value History, ,Value history}), after printing one out.
5237
5238Another way to create an artificial array is to use a cast.
5239This re-interprets a value as if it were an array.
5240The value need not be in memory:
474c8240 5241@smallexample
c906108c
SS
5242(@value{GDBP}) p/x (short[2])0x12345678
5243$1 = @{0x1234, 0x5678@}
474c8240 5244@end smallexample
c906108c
SS
5245
5246As a convenience, if you leave the array length out (as in
c3f6f71d 5247@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5248the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5249@smallexample
c906108c
SS
5250(@value{GDBP}) p/x (short[])0x12345678
5251$2 = @{0x1234, 0x5678@}
474c8240 5252@end smallexample
c906108c
SS
5253
5254Sometimes the artificial array mechanism is not quite enough; in
5255moderately complex data structures, the elements of interest may not
5256actually be adjacent---for example, if you are interested in the values
5257of pointers in an array. One useful work-around in this situation is
5258to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5259variables}) as a counter in an expression that prints the first
5260interesting value, and then repeat that expression via @key{RET}. For
5261instance, suppose you have an array @code{dtab} of pointers to
5262structures, and you are interested in the values of a field @code{fv}
5263in each structure. Here is an example of what you might type:
5264
474c8240 5265@smallexample
c906108c
SS
5266set $i = 0
5267p dtab[$i++]->fv
5268@key{RET}
5269@key{RET}
5270@dots{}
474c8240 5271@end smallexample
c906108c 5272
6d2ebf8b 5273@node Output Formats
c906108c
SS
5274@section Output formats
5275
5276@cindex formatted output
5277@cindex output formats
5278By default, @value{GDBN} prints a value according to its data type. Sometimes
5279this is not what you want. For example, you might want to print a number
5280in hex, or a pointer in decimal. Or you might want to view data in memory
5281at a certain address as a character string or as an instruction. To do
5282these things, specify an @dfn{output format} when you print a value.
5283
5284The simplest use of output formats is to say how to print a value
5285already computed. This is done by starting the arguments of the
5286@code{print} command with a slash and a format letter. The format
5287letters supported are:
5288
5289@table @code
5290@item x
5291Regard the bits of the value as an integer, and print the integer in
5292hexadecimal.
5293
5294@item d
5295Print as integer in signed decimal.
5296
5297@item u
5298Print as integer in unsigned decimal.
5299
5300@item o
5301Print as integer in octal.
5302
5303@item t
5304Print as integer in binary. The letter @samp{t} stands for ``two''.
5305@footnote{@samp{b} cannot be used because these format letters are also
5306used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5307see @ref{Memory,,Examining memory}.}
c906108c
SS
5308
5309@item a
5310@cindex unknown address, locating
3d67e040 5311@cindex locate address
c906108c
SS
5312Print as an address, both absolute in hexadecimal and as an offset from
5313the nearest preceding symbol. You can use this format used to discover
5314where (in what function) an unknown address is located:
5315
474c8240 5316@smallexample
c906108c
SS
5317(@value{GDBP}) p/a 0x54320
5318$3 = 0x54320 <_initialize_vx+396>
474c8240 5319@end smallexample
c906108c 5320
3d67e040
EZ
5321@noindent
5322The command @code{info symbol 0x54320} yields similar results.
5323@xref{Symbols, info symbol}.
5324
c906108c 5325@item c
51274035
EZ
5326Regard as an integer and print it as a character constant. This
5327prints both the numerical value and its character representation. The
5328character representation is replaced with the octal escape @samp{\nnn}
5329for characters outside the 7-bit @sc{ascii} range.
c906108c
SS
5330
5331@item f
5332Regard the bits of the value as a floating point number and print
5333using typical floating point syntax.
5334@end table
5335
5336For example, to print the program counter in hex (@pxref{Registers}), type
5337
474c8240 5338@smallexample
c906108c 5339p/x $pc
474c8240 5340@end smallexample
c906108c
SS
5341
5342@noindent
5343Note that no space is required before the slash; this is because command
5344names in @value{GDBN} cannot contain a slash.
5345
5346To reprint the last value in the value history with a different format,
5347you can use the @code{print} command with just a format and no
5348expression. For example, @samp{p/x} reprints the last value in hex.
5349
6d2ebf8b 5350@node Memory
c906108c
SS
5351@section Examining memory
5352
5353You can use the command @code{x} (for ``examine'') to examine memory in
5354any of several formats, independently of your program's data types.
5355
5356@cindex examining memory
5357@table @code
41afff9a 5358@kindex x @r{(examine memory)}
c906108c
SS
5359@item x/@var{nfu} @var{addr}
5360@itemx x @var{addr}
5361@itemx x
5362Use the @code{x} command to examine memory.
5363@end table
5364
5365@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5366much memory to display and how to format it; @var{addr} is an
5367expression giving the address where you want to start displaying memory.
5368If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5369Several commands set convenient defaults for @var{addr}.
5370
5371@table @r
5372@item @var{n}, the repeat count
5373The repeat count is a decimal integer; the default is 1. It specifies
5374how much memory (counting by units @var{u}) to display.
5375@c This really is **decimal**; unaffected by 'set radix' as of GDB
5376@c 4.1.2.
5377
5378@item @var{f}, the display format
51274035
EZ
5379The display format is one of the formats used by @code{print}
5380(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
5381@samp{f}), and in addition @samp{s} (for null-terminated strings) and
5382@samp{i} (for machine instructions). The default is @samp{x}
5383(hexadecimal) initially. The default changes each time you use either
5384@code{x} or @code{print}.
c906108c
SS
5385
5386@item @var{u}, the unit size
5387The unit size is any of
5388
5389@table @code
5390@item b
5391Bytes.
5392@item h
5393Halfwords (two bytes).
5394@item w
5395Words (four bytes). This is the initial default.
5396@item g
5397Giant words (eight bytes).
5398@end table
5399
5400Each time you specify a unit size with @code{x}, that size becomes the
5401default unit the next time you use @code{x}. (For the @samp{s} and
5402@samp{i} formats, the unit size is ignored and is normally not written.)
5403
5404@item @var{addr}, starting display address
5405@var{addr} is the address where you want @value{GDBN} to begin displaying
5406memory. The expression need not have a pointer value (though it may);
5407it is always interpreted as an integer address of a byte of memory.
5408@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5409@var{addr} is usually just after the last address examined---but several
5410other commands also set the default address: @code{info breakpoints} (to
5411the address of the last breakpoint listed), @code{info line} (to the
5412starting address of a line), and @code{print} (if you use it to display
5413a value from memory).
5414@end table
5415
5416For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5417(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5418starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5419words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5420@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5421
5422Since the letters indicating unit sizes are all distinct from the
5423letters specifying output formats, you do not have to remember whether
5424unit size or format comes first; either order works. The output
5425specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5426(However, the count @var{n} must come first; @samp{wx4} does not work.)
5427
5428Even though the unit size @var{u} is ignored for the formats @samp{s}
5429and @samp{i}, you might still want to use a count @var{n}; for example,
5430@samp{3i} specifies that you want to see three machine instructions,
5431including any operands. The command @code{disassemble} gives an
d4f3574e 5432alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5433Code,,Source and machine code}.
5434
5435All the defaults for the arguments to @code{x} are designed to make it
5436easy to continue scanning memory with minimal specifications each time
5437you use @code{x}. For example, after you have inspected three machine
5438instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5439with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5440the repeat count @var{n} is used again; the other arguments default as
5441for successive uses of @code{x}.
5442
5443@cindex @code{$_}, @code{$__}, and value history
5444The addresses and contents printed by the @code{x} command are not saved
5445in the value history because there is often too much of them and they
5446would get in the way. Instead, @value{GDBN} makes these values available for
5447subsequent use in expressions as values of the convenience variables
5448@code{$_} and @code{$__}. After an @code{x} command, the last address
5449examined is available for use in expressions in the convenience variable
5450@code{$_}. The contents of that address, as examined, are available in
5451the convenience variable @code{$__}.
5452
5453If the @code{x} command has a repeat count, the address and contents saved
5454are from the last memory unit printed; this is not the same as the last
5455address printed if several units were printed on the last line of output.
5456
09d4efe1
EZ
5457@cindex remote memory comparison
5458@cindex verify remote memory image
5459When you are debugging a program running on a remote target machine
5460(@pxref{Remote}), you may wish to verify the program's image in the
5461remote machine's memory against the executable file you downloaded to
5462the target. The @code{compare-sections} command is provided for such
5463situations.
5464
5465@table @code
5466@kindex compare-sections
5467@item compare-sections @r{[}@var{section-name}@r{]}
5468Compare the data of a loadable section @var{section-name} in the
5469executable file of the program being debugged with the same section in
5470the remote machine's memory, and report any mismatches. With no
5471arguments, compares all loadable sections. This command's
5472availability depends on the target's support for the @code{"qCRC"}
5473remote request.
5474@end table
5475
6d2ebf8b 5476@node Auto Display
c906108c
SS
5477@section Automatic display
5478@cindex automatic display
5479@cindex display of expressions
5480
5481If you find that you want to print the value of an expression frequently
5482(to see how it changes), you might want to add it to the @dfn{automatic
5483display list} so that @value{GDBN} prints its value each time your program stops.
5484Each expression added to the list is given a number to identify it;
5485to remove an expression from the list, you specify that number.
5486The automatic display looks like this:
5487
474c8240 5488@smallexample
c906108c
SS
54892: foo = 38
54903: bar[5] = (struct hack *) 0x3804
474c8240 5491@end smallexample
c906108c
SS
5492
5493@noindent
5494This display shows item numbers, expressions and their current values. As with
5495displays you request manually using @code{x} or @code{print}, you can
5496specify the output format you prefer; in fact, @code{display} decides
5497whether to use @code{print} or @code{x} depending on how elaborate your
5498format specification is---it uses @code{x} if you specify a unit size,
5499or one of the two formats (@samp{i} and @samp{s}) that are only
5500supported by @code{x}; otherwise it uses @code{print}.
5501
5502@table @code
5503@kindex display
d4f3574e
SS
5504@item display @var{expr}
5505Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5506each time your program stops. @xref{Expressions, ,Expressions}.
5507
5508@code{display} does not repeat if you press @key{RET} again after using it.
5509
d4f3574e 5510@item display/@var{fmt} @var{expr}
c906108c 5511For @var{fmt} specifying only a display format and not a size or
d4f3574e 5512count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5513arrange to display it each time in the specified format @var{fmt}.
5514@xref{Output Formats,,Output formats}.
5515
5516@item display/@var{fmt} @var{addr}
5517For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5518number of units, add the expression @var{addr} as a memory address to
5519be examined each time your program stops. Examining means in effect
5520doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5521@end table
5522
5523For example, @samp{display/i $pc} can be helpful, to see the machine
5524instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5525is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5526
5527@table @code
5528@kindex delete display
5529@kindex undisplay
5530@item undisplay @var{dnums}@dots{}
5531@itemx delete display @var{dnums}@dots{}
5532Remove item numbers @var{dnums} from the list of expressions to display.
5533
5534@code{undisplay} does not repeat if you press @key{RET} after using it.
5535(Otherwise you would just get the error @samp{No display number @dots{}}.)
5536
5537@kindex disable display
5538@item disable display @var{dnums}@dots{}
5539Disable the display of item numbers @var{dnums}. A disabled display
5540item is not printed automatically, but is not forgotten. It may be
5541enabled again later.
5542
5543@kindex enable display
5544@item enable display @var{dnums}@dots{}
5545Enable display of item numbers @var{dnums}. It becomes effective once
5546again in auto display of its expression, until you specify otherwise.
5547
5548@item display
5549Display the current values of the expressions on the list, just as is
5550done when your program stops.
5551
5552@kindex info display
5553@item info display
5554Print the list of expressions previously set up to display
5555automatically, each one with its item number, but without showing the
5556values. This includes disabled expressions, which are marked as such.
5557It also includes expressions which would not be displayed right now
5558because they refer to automatic variables not currently available.
5559@end table
5560
15387254 5561@cindex display disabled out of scope
c906108c
SS
5562If a display expression refers to local variables, then it does not make
5563sense outside the lexical context for which it was set up. Such an
5564expression is disabled when execution enters a context where one of its
5565variables is not defined. For example, if you give the command
5566@code{display last_char} while inside a function with an argument
5567@code{last_char}, @value{GDBN} displays this argument while your program
5568continues to stop inside that function. When it stops elsewhere---where
5569there is no variable @code{last_char}---the display is disabled
5570automatically. The next time your program stops where @code{last_char}
5571is meaningful, you can enable the display expression once again.
5572
6d2ebf8b 5573@node Print Settings
c906108c
SS
5574@section Print settings
5575
5576@cindex format options
5577@cindex print settings
5578@value{GDBN} provides the following ways to control how arrays, structures,
5579and symbols are printed.
5580
5581@noindent
5582These settings are useful for debugging programs in any language:
5583
5584@table @code
4644b6e3 5585@kindex set print
c906108c
SS
5586@item set print address
5587@itemx set print address on
4644b6e3 5588@cindex print/don't print memory addresses
c906108c
SS
5589@value{GDBN} prints memory addresses showing the location of stack
5590traces, structure values, pointer values, breakpoints, and so forth,
5591even when it also displays the contents of those addresses. The default
5592is @code{on}. For example, this is what a stack frame display looks like with
5593@code{set print address on}:
5594
5595@smallexample
5596@group
5597(@value{GDBP}) f
5598#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5599 at input.c:530
5600530 if (lquote != def_lquote)
5601@end group
5602@end smallexample
5603
5604@item set print address off
5605Do not print addresses when displaying their contents. For example,
5606this is the same stack frame displayed with @code{set print address off}:
5607
5608@smallexample
5609@group
5610(@value{GDBP}) set print addr off
5611(@value{GDBP}) f
5612#0 set_quotes (lq="<<", rq=">>") at input.c:530
5613530 if (lquote != def_lquote)
5614@end group
5615@end smallexample
5616
5617You can use @samp{set print address off} to eliminate all machine
5618dependent displays from the @value{GDBN} interface. For example, with
5619@code{print address off}, you should get the same text for backtraces on
5620all machines---whether or not they involve pointer arguments.
5621
4644b6e3 5622@kindex show print
c906108c
SS
5623@item show print address
5624Show whether or not addresses are to be printed.
5625@end table
5626
5627When @value{GDBN} prints a symbolic address, it normally prints the
5628closest earlier symbol plus an offset. If that symbol does not uniquely
5629identify the address (for example, it is a name whose scope is a single
5630source file), you may need to clarify. One way to do this is with
5631@code{info line}, for example @samp{info line *0x4537}. Alternately,
5632you can set @value{GDBN} to print the source file and line number when
5633it prints a symbolic address:
5634
5635@table @code
c906108c 5636@item set print symbol-filename on
9c16f35a
EZ
5637@cindex source file and line of a symbol
5638@cindex symbol, source file and line
c906108c
SS
5639Tell @value{GDBN} to print the source file name and line number of a
5640symbol in the symbolic form of an address.
5641
5642@item set print symbol-filename off
5643Do not print source file name and line number of a symbol. This is the
5644default.
5645
c906108c
SS
5646@item show print symbol-filename
5647Show whether or not @value{GDBN} will print the source file name and
5648line number of a symbol in the symbolic form of an address.
5649@end table
5650
5651Another situation where it is helpful to show symbol filenames and line
5652numbers is when disassembling code; @value{GDBN} shows you the line
5653number and source file that corresponds to each instruction.
5654
5655Also, you may wish to see the symbolic form only if the address being
5656printed is reasonably close to the closest earlier symbol:
5657
5658@table @code
c906108c 5659@item set print max-symbolic-offset @var{max-offset}
4644b6e3 5660@cindex maximum value for offset of closest symbol
c906108c
SS
5661Tell @value{GDBN} to only display the symbolic form of an address if the
5662offset between the closest earlier symbol and the address is less than
5d161b24 5663@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5664to always print the symbolic form of an address if any symbol precedes it.
5665
c906108c
SS
5666@item show print max-symbolic-offset
5667Ask how large the maximum offset is that @value{GDBN} prints in a
5668symbolic address.
5669@end table
5670
5671@cindex wild pointer, interpreting
5672@cindex pointer, finding referent
5673If you have a pointer and you are not sure where it points, try
5674@samp{set print symbol-filename on}. Then you can determine the name
5675and source file location of the variable where it points, using
5676@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5677For example, here @value{GDBN} shows that a variable @code{ptt} points
5678at another variable @code{t}, defined in @file{hi2.c}:
5679
474c8240 5680@smallexample
c906108c
SS
5681(@value{GDBP}) set print symbol-filename on
5682(@value{GDBP}) p/a ptt
5683$4 = 0xe008 <t in hi2.c>
474c8240 5684@end smallexample
c906108c
SS
5685
5686@quotation
5687@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5688does not show the symbol name and filename of the referent, even with
5689the appropriate @code{set print} options turned on.
5690@end quotation
5691
5692Other settings control how different kinds of objects are printed:
5693
5694@table @code
c906108c
SS
5695@item set print array
5696@itemx set print array on
4644b6e3 5697@cindex pretty print arrays
c906108c
SS
5698Pretty print arrays. This format is more convenient to read,
5699but uses more space. The default is off.
5700
5701@item set print array off
5702Return to compressed format for arrays.
5703
c906108c
SS
5704@item show print array
5705Show whether compressed or pretty format is selected for displaying
5706arrays.
5707
3c9c013a
JB
5708@cindex print array indexes
5709@item set print array-indexes
5710@itemx set print array-indexes on
5711Print the index of each element when displaying arrays. May be more
5712convenient to locate a given element in the array or quickly find the
5713index of a given element in that printed array. The default is off.
5714
5715@item set print array-indexes off
5716Stop printing element indexes when displaying arrays.
5717
5718@item show print array-indexes
5719Show whether the index of each element is printed when displaying
5720arrays.
5721
c906108c 5722@item set print elements @var{number-of-elements}
4644b6e3 5723@cindex number of array elements to print
9c16f35a 5724@cindex limit on number of printed array elements
c906108c
SS
5725Set a limit on how many elements of an array @value{GDBN} will print.
5726If @value{GDBN} is printing a large array, it stops printing after it has
5727printed the number of elements set by the @code{set print elements} command.
5728This limit also applies to the display of strings.
d4f3574e 5729When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5730Setting @var{number-of-elements} to zero means that the printing is unlimited.
5731
c906108c
SS
5732@item show print elements
5733Display the number of elements of a large array that @value{GDBN} will print.
5734If the number is 0, then the printing is unlimited.
5735
9c16f35a
EZ
5736@item set print repeats
5737@cindex repeated array elements
5738Set the threshold for suppressing display of repeated array
5739elelments. When the number of consecutive identical elements of an
5740array exceeds the threshold, @value{GDBN} prints the string
5741@code{"<repeats @var{n} times>"}, where @var{n} is the number of
5742identical repetitions, instead of displaying the identical elements
5743themselves. Setting the threshold to zero will cause all elements to
5744be individually printed. The default threshold is 10.
5745
5746@item show print repeats
5747Display the current threshold for printing repeated identical
5748elements.
5749
c906108c 5750@item set print null-stop
4644b6e3 5751@cindex @sc{null} elements in arrays
c906108c 5752Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5753@sc{null} is encountered. This is useful when large arrays actually
c906108c 5754contain only short strings.
d4f3574e 5755The default is off.
c906108c 5756
9c16f35a
EZ
5757@item show print null-stop
5758Show whether @value{GDBN} stops printing an array on the first
5759@sc{null} character.
5760
c906108c 5761@item set print pretty on
9c16f35a
EZ
5762@cindex print structures in indented form
5763@cindex indentation in structure display
5d161b24 5764Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5765per line, like this:
5766
5767@smallexample
5768@group
5769$1 = @{
5770 next = 0x0,
5771 flags = @{
5772 sweet = 1,
5773 sour = 1
5774 @},
5775 meat = 0x54 "Pork"
5776@}
5777@end group
5778@end smallexample
5779
5780@item set print pretty off
5781Cause @value{GDBN} to print structures in a compact format, like this:
5782
5783@smallexample
5784@group
5785$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5786meat = 0x54 "Pork"@}
5787@end group
5788@end smallexample
5789
5790@noindent
5791This is the default format.
5792
c906108c
SS
5793@item show print pretty
5794Show which format @value{GDBN} is using to print structures.
5795
c906108c 5796@item set print sevenbit-strings on
4644b6e3
EZ
5797@cindex eight-bit characters in strings
5798@cindex octal escapes in strings
c906108c
SS
5799Print using only seven-bit characters; if this option is set,
5800@value{GDBN} displays any eight-bit characters (in strings or
5801character values) using the notation @code{\}@var{nnn}. This setting is
5802best if you are working in English (@sc{ascii}) and you use the
5803high-order bit of characters as a marker or ``meta'' bit.
5804
5805@item set print sevenbit-strings off
5806Print full eight-bit characters. This allows the use of more
5807international character sets, and is the default.
5808
c906108c
SS
5809@item show print sevenbit-strings
5810Show whether or not @value{GDBN} is printing only seven-bit characters.
5811
c906108c 5812@item set print union on
4644b6e3 5813@cindex unions in structures, printing
9c16f35a
EZ
5814Tell @value{GDBN} to print unions which are contained in structures
5815and other unions. This is the default setting.
c906108c
SS
5816
5817@item set print union off
9c16f35a
EZ
5818Tell @value{GDBN} not to print unions which are contained in
5819structures and other unions. @value{GDBN} will print @code{"@{...@}"}
5820instead.
c906108c 5821
c906108c
SS
5822@item show print union
5823Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 5824structures and other unions.
c906108c
SS
5825
5826For example, given the declarations
5827
5828@smallexample
5829typedef enum @{Tree, Bug@} Species;
5830typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5831typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5832 Bug_forms;
5833
5834struct thing @{
5835 Species it;
5836 union @{
5837 Tree_forms tree;
5838 Bug_forms bug;
5839 @} form;
5840@};
5841
5842struct thing foo = @{Tree, @{Acorn@}@};
5843@end smallexample
5844
5845@noindent
5846with @code{set print union on} in effect @samp{p foo} would print
5847
5848@smallexample
5849$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5850@end smallexample
5851
5852@noindent
5853and with @code{set print union off} in effect it would print
5854
5855@smallexample
5856$1 = @{it = Tree, form = @{...@}@}
5857@end smallexample
9c16f35a
EZ
5858
5859@noindent
5860@code{set print union} affects programs written in C-like languages
5861and in Pascal.
c906108c
SS
5862@end table
5863
c906108c
SS
5864@need 1000
5865@noindent
b37052ae 5866These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5867
5868@table @code
4644b6e3 5869@cindex demangling C@t{++} names
c906108c
SS
5870@item set print demangle
5871@itemx set print demangle on
b37052ae 5872Print C@t{++} names in their source form rather than in the encoded
c906108c 5873(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5874linkage. The default is on.
c906108c 5875
c906108c 5876@item show print demangle
b37052ae 5877Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 5878
c906108c
SS
5879@item set print asm-demangle
5880@itemx set print asm-demangle on
b37052ae 5881Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5882in assembler code printouts such as instruction disassemblies.
5883The default is off.
5884
c906108c 5885@item show print asm-demangle
b37052ae 5886Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5887or demangled form.
5888
b37052ae
EZ
5889@cindex C@t{++} symbol decoding style
5890@cindex symbol decoding style, C@t{++}
a8f24a35 5891@kindex set demangle-style
c906108c
SS
5892@item set demangle-style @var{style}
5893Choose among several encoding schemes used by different compilers to
b37052ae 5894represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5895
5896@table @code
5897@item auto
5898Allow @value{GDBN} to choose a decoding style by inspecting your program.
5899
5900@item gnu
b37052ae 5901Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5902This is the default.
c906108c
SS
5903
5904@item hp
b37052ae 5905Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5906
5907@item lucid
b37052ae 5908Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5909
5910@item arm
b37052ae 5911Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5912@strong{Warning:} this setting alone is not sufficient to allow
5913debugging @code{cfront}-generated executables. @value{GDBN} would
5914require further enhancement to permit that.
5915
5916@end table
5917If you omit @var{style}, you will see a list of possible formats.
5918
c906108c 5919@item show demangle-style
b37052ae 5920Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 5921
c906108c
SS
5922@item set print object
5923@itemx set print object on
4644b6e3 5924@cindex derived type of an object, printing
9c16f35a 5925@cindex display derived types
c906108c
SS
5926When displaying a pointer to an object, identify the @emph{actual}
5927(derived) type of the object rather than the @emph{declared} type, using
5928the virtual function table.
5929
5930@item set print object off
5931Display only the declared type of objects, without reference to the
5932virtual function table. This is the default setting.
5933
c906108c
SS
5934@item show print object
5935Show whether actual, or declared, object types are displayed.
5936
c906108c
SS
5937@item set print static-members
5938@itemx set print static-members on
4644b6e3 5939@cindex static members of C@t{++} objects
b37052ae 5940Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5941
5942@item set print static-members off
b37052ae 5943Do not print static members when displaying a C@t{++} object.
c906108c 5944
c906108c 5945@item show print static-members
9c16f35a
EZ
5946Show whether C@t{++} static members are printed or not.
5947
5948@item set print pascal_static-members
5949@itemx set print pascal_static-members on
5950@cindex static members of Pacal objects
5951@cindex Pacal objects, static members display
5952Print static members when displaying a Pascal object. The default is on.
5953
5954@item set print pascal_static-members off
5955Do not print static members when displaying a Pascal object.
5956
5957@item show print pascal_static-members
5958Show whether Pascal static members are printed or not.
c906108c
SS
5959
5960@c These don't work with HP ANSI C++ yet.
c906108c
SS
5961@item set print vtbl
5962@itemx set print vtbl on
4644b6e3 5963@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
5964@cindex virtual functions (C@t{++}) display
5965@cindex VTBL display
b37052ae 5966Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5967(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5968ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5969
5970@item set print vtbl off
b37052ae 5971Do not pretty print C@t{++} virtual function tables.
c906108c 5972
c906108c 5973@item show print vtbl
b37052ae 5974Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5975@end table
c906108c 5976
6d2ebf8b 5977@node Value History
c906108c
SS
5978@section Value history
5979
5980@cindex value history
9c16f35a 5981@cindex history of values printed by @value{GDBN}
5d161b24
DB
5982Values printed by the @code{print} command are saved in the @value{GDBN}
5983@dfn{value history}. This allows you to refer to them in other expressions.
5984Values are kept until the symbol table is re-read or discarded
5985(for example with the @code{file} or @code{symbol-file} commands).
5986When the symbol table changes, the value history is discarded,
5987since the values may contain pointers back to the types defined in the
c906108c
SS
5988symbol table.
5989
5990@cindex @code{$}
5991@cindex @code{$$}
5992@cindex history number
5993The values printed are given @dfn{history numbers} by which you can
5994refer to them. These are successive integers starting with one.
5995@code{print} shows you the history number assigned to a value by
5996printing @samp{$@var{num} = } before the value; here @var{num} is the
5997history number.
5998
5999To refer to any previous value, use @samp{$} followed by the value's
6000history number. The way @code{print} labels its output is designed to
6001remind you of this. Just @code{$} refers to the most recent value in
6002the history, and @code{$$} refers to the value before that.
6003@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
6004is the value just prior to @code{$$}, @code{$$1} is equivalent to
6005@code{$$}, and @code{$$0} is equivalent to @code{$}.
6006
6007For example, suppose you have just printed a pointer to a structure and
6008want to see the contents of the structure. It suffices to type
6009
474c8240 6010@smallexample
c906108c 6011p *$
474c8240 6012@end smallexample
c906108c
SS
6013
6014If you have a chain of structures where the component @code{next} points
6015to the next one, you can print the contents of the next one with this:
6016
474c8240 6017@smallexample
c906108c 6018p *$.next
474c8240 6019@end smallexample
c906108c
SS
6020
6021@noindent
6022You can print successive links in the chain by repeating this
6023command---which you can do by just typing @key{RET}.
6024
6025Note that the history records values, not expressions. If the value of
6026@code{x} is 4 and you type these commands:
6027
474c8240 6028@smallexample
c906108c
SS
6029print x
6030set x=5
474c8240 6031@end smallexample
c906108c
SS
6032
6033@noindent
6034then the value recorded in the value history by the @code{print} command
6035remains 4 even though the value of @code{x} has changed.
6036
6037@table @code
6038@kindex show values
6039@item show values
6040Print the last ten values in the value history, with their item numbers.
6041This is like @samp{p@ $$9} repeated ten times, except that @code{show
6042values} does not change the history.
6043
6044@item show values @var{n}
6045Print ten history values centered on history item number @var{n}.
6046
6047@item show values +
6048Print ten history values just after the values last printed. If no more
6049values are available, @code{show values +} produces no display.
6050@end table
6051
6052Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
6053same effect as @samp{show values +}.
6054
6d2ebf8b 6055@node Convenience Vars
c906108c
SS
6056@section Convenience variables
6057
6058@cindex convenience variables
9c16f35a 6059@cindex user-defined variables
c906108c
SS
6060@value{GDBN} provides @dfn{convenience variables} that you can use within
6061@value{GDBN} to hold on to a value and refer to it later. These variables
6062exist entirely within @value{GDBN}; they are not part of your program, and
6063setting a convenience variable has no direct effect on further execution
6064of your program. That is why you can use them freely.
6065
6066Convenience variables are prefixed with @samp{$}. Any name preceded by
6067@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 6068the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
6069(Value history references, in contrast, are @emph{numbers} preceded
6070by @samp{$}. @xref{Value History, ,Value history}.)
6071
6072You can save a value in a convenience variable with an assignment
6073expression, just as you would set a variable in your program.
6074For example:
6075
474c8240 6076@smallexample
c906108c 6077set $foo = *object_ptr
474c8240 6078@end smallexample
c906108c
SS
6079
6080@noindent
6081would save in @code{$foo} the value contained in the object pointed to by
6082@code{object_ptr}.
6083
6084Using a convenience variable for the first time creates it, but its
6085value is @code{void} until you assign a new value. You can alter the
6086value with another assignment at any time.
6087
6088Convenience variables have no fixed types. You can assign a convenience
6089variable any type of value, including structures and arrays, even if
6090that variable already has a value of a different type. The convenience
6091variable, when used as an expression, has the type of its current value.
6092
6093@table @code
6094@kindex show convenience
9c16f35a 6095@cindex show all user variables
c906108c
SS
6096@item show convenience
6097Print a list of convenience variables used so far, and their values.
d4f3574e 6098Abbreviated @code{show conv}.
c906108c
SS
6099@end table
6100
6101One of the ways to use a convenience variable is as a counter to be
6102incremented or a pointer to be advanced. For example, to print
6103a field from successive elements of an array of structures:
6104
474c8240 6105@smallexample
c906108c
SS
6106set $i = 0
6107print bar[$i++]->contents
474c8240 6108@end smallexample
c906108c 6109
d4f3574e
SS
6110@noindent
6111Repeat that command by typing @key{RET}.
c906108c
SS
6112
6113Some convenience variables are created automatically by @value{GDBN} and given
6114values likely to be useful.
6115
6116@table @code
41afff9a 6117@vindex $_@r{, convenience variable}
c906108c
SS
6118@item $_
6119The variable @code{$_} is automatically set by the @code{x} command to
6120the last address examined (@pxref{Memory, ,Examining memory}). Other
6121commands which provide a default address for @code{x} to examine also
6122set @code{$_} to that address; these commands include @code{info line}
6123and @code{info breakpoint}. The type of @code{$_} is @code{void *}
6124except when set by the @code{x} command, in which case it is a pointer
6125to the type of @code{$__}.
6126
41afff9a 6127@vindex $__@r{, convenience variable}
c906108c
SS
6128@item $__
6129The variable @code{$__} is automatically set by the @code{x} command
6130to the value found in the last address examined. Its type is chosen
6131to match the format in which the data was printed.
6132
6133@item $_exitcode
41afff9a 6134@vindex $_exitcode@r{, convenience variable}
c906108c
SS
6135The variable @code{$_exitcode} is automatically set to the exit code when
6136the program being debugged terminates.
6137@end table
6138
53a5351d
JM
6139On HP-UX systems, if you refer to a function or variable name that
6140begins with a dollar sign, @value{GDBN} searches for a user or system
6141name first, before it searches for a convenience variable.
c906108c 6142
6d2ebf8b 6143@node Registers
c906108c
SS
6144@section Registers
6145
6146@cindex registers
6147You can refer to machine register contents, in expressions, as variables
6148with names starting with @samp{$}. The names of registers are different
6149for each machine; use @code{info registers} to see the names used on
6150your machine.
6151
6152@table @code
6153@kindex info registers
6154@item info registers
6155Print the names and values of all registers except floating-point
c85508ee 6156and vector registers (in the selected stack frame).
c906108c
SS
6157
6158@kindex info all-registers
6159@cindex floating point registers
6160@item info all-registers
6161Print the names and values of all registers, including floating-point
c85508ee 6162and vector registers (in the selected stack frame).
c906108c
SS
6163
6164@item info registers @var{regname} @dots{}
6165Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
6166As discussed in detail below, register values are normally relative to
6167the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
6168the machine you are using, with or without the initial @samp{$}.
6169@end table
6170
e09f16f9
EZ
6171@cindex stack pointer register
6172@cindex program counter register
6173@cindex process status register
6174@cindex frame pointer register
6175@cindex standard registers
c906108c
SS
6176@value{GDBN} has four ``standard'' register names that are available (in
6177expressions) on most machines---whenever they do not conflict with an
6178architecture's canonical mnemonics for registers. The register names
6179@code{$pc} and @code{$sp} are used for the program counter register and
6180the stack pointer. @code{$fp} is used for a register that contains a
6181pointer to the current stack frame, and @code{$ps} is used for a
6182register that contains the processor status. For example,
6183you could print the program counter in hex with
6184
474c8240 6185@smallexample
c906108c 6186p/x $pc
474c8240 6187@end smallexample
c906108c
SS
6188
6189@noindent
6190or print the instruction to be executed next with
6191
474c8240 6192@smallexample
c906108c 6193x/i $pc
474c8240 6194@end smallexample
c906108c
SS
6195
6196@noindent
6197or add four to the stack pointer@footnote{This is a way of removing
6198one word from the stack, on machines where stacks grow downward in
6199memory (most machines, nowadays). This assumes that the innermost
6200stack frame is selected; setting @code{$sp} is not allowed when other
6201stack frames are selected. To pop entire frames off the stack,
6202regardless of machine architecture, use @code{return};
d4f3574e 6203see @ref{Returning, ,Returning from a function}.} with
c906108c 6204
474c8240 6205@smallexample
c906108c 6206set $sp += 4
474c8240 6207@end smallexample
c906108c
SS
6208
6209Whenever possible, these four standard register names are available on
6210your machine even though the machine has different canonical mnemonics,
6211so long as there is no conflict. The @code{info registers} command
6212shows the canonical names. For example, on the SPARC, @code{info
6213registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
6214can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6215is an alias for the @sc{eflags} register.
c906108c
SS
6216
6217@value{GDBN} always considers the contents of an ordinary register as an
6218integer when the register is examined in this way. Some machines have
6219special registers which can hold nothing but floating point; these
6220registers are considered to have floating point values. There is no way
6221to refer to the contents of an ordinary register as floating point value
6222(although you can @emph{print} it as a floating point value with
6223@samp{print/f $@var{regname}}).
6224
6225Some registers have distinct ``raw'' and ``virtual'' data formats. This
6226means that the data format in which the register contents are saved by
6227the operating system is not the same one that your program normally
6228sees. For example, the registers of the 68881 floating point
6229coprocessor are always saved in ``extended'' (raw) format, but all C
6230programs expect to work with ``double'' (virtual) format. In such
5d161b24 6231cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
6232that makes sense for your program), but the @code{info registers} command
6233prints the data in both formats.
6234
6235Normally, register values are relative to the selected stack frame
6236(@pxref{Selection, ,Selecting a frame}). This means that you get the
6237value that the register would contain if all stack frames farther in
6238were exited and their saved registers restored. In order to see the
6239true contents of hardware registers, you must select the innermost
6240frame (with @samp{frame 0}).
6241
6242However, @value{GDBN} must deduce where registers are saved, from the machine
6243code generated by your compiler. If some registers are not saved, or if
6244@value{GDBN} is unable to locate the saved registers, the selected stack
6245frame makes no difference.
6246
6d2ebf8b 6247@node Floating Point Hardware
c906108c
SS
6248@section Floating point hardware
6249@cindex floating point
6250
6251Depending on the configuration, @value{GDBN} may be able to give
6252you more information about the status of the floating point hardware.
6253
6254@table @code
6255@kindex info float
6256@item info float
6257Display hardware-dependent information about the floating
6258point unit. The exact contents and layout vary depending on the
6259floating point chip. Currently, @samp{info float} is supported on
6260the ARM and x86 machines.
6261@end table
c906108c 6262
e76f1f2e
AC
6263@node Vector Unit
6264@section Vector Unit
6265@cindex vector unit
6266
6267Depending on the configuration, @value{GDBN} may be able to give you
6268more information about the status of the vector unit.
6269
6270@table @code
6271@kindex info vector
6272@item info vector
6273Display information about the vector unit. The exact contents and
6274layout vary depending on the hardware.
6275@end table
6276
721c2651
EZ
6277@node OS Information
6278@section Operating system auxiliary information
6279@cindex OS information
6280
6281@value{GDBN} provides interfaces to useful OS facilities that can help
6282you debug your program.
6283
6284@cindex @code{ptrace} system call
6285@cindex @code{struct user} contents
6286When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6287machines), it interfaces with the inferior via the @code{ptrace}
6288system call. The operating system creates a special sata structure,
6289called @code{struct user}, for this interface. You can use the
6290command @code{info udot} to display the contents of this data
6291structure.
6292
6293@table @code
6294@item info udot
6295@kindex info udot
6296Display the contents of the @code{struct user} maintained by the OS
6297kernel for the program being debugged. @value{GDBN} displays the
6298contents of @code{struct user} as a list of hex numbers, similar to
6299the @code{examine} command.
6300@end table
6301
b383017d
RM
6302@cindex auxiliary vector
6303@cindex vector, auxiliary
b383017d
RM
6304Some operating systems supply an @dfn{auxiliary vector} to programs at
6305startup. This is akin to the arguments and environment that you
6306specify for a program, but contains a system-dependent variety of
6307binary values that tell system libraries important details about the
6308hardware, operating system, and process. Each value's purpose is
6309identified by an integer tag; the meanings are well-known but system-specific.
6310Depending on the configuration and operating system facilities,
9c16f35a
EZ
6311@value{GDBN} may be able to show you this information. For remote
6312targets, this functionality may further depend on the remote stub's
6313support of the @samp{qPart:auxv:read} packet, see @ref{Remote
6314configuration, auxiliary vector}.
b383017d
RM
6315
6316@table @code
6317@kindex info auxv
6318@item info auxv
6319Display the auxiliary vector of the inferior, which can be either a
e4937fc1 6320live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
6321numerically, and also shows names and text descriptions for recognized
6322tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 6323pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
6324most appropriate form for a recognized tag, and in hexadecimal for
6325an unrecognized tag.
6326@end table
6327
721c2651 6328
29e57380 6329@node Memory Region Attributes
b383017d 6330@section Memory region attributes
29e57380
C
6331@cindex memory region attributes
6332
b383017d
RM
6333@dfn{Memory region attributes} allow you to describe special handling
6334required by regions of your target's memory. @value{GDBN} uses attributes
29e57380
C
6335to determine whether to allow certain types of memory accesses; whether to
6336use specific width accesses; and whether to cache target memory.
6337
6338Defined memory regions can be individually enabled and disabled. When a
6339memory region is disabled, @value{GDBN} uses the default attributes when
6340accessing memory in that region. Similarly, if no memory regions have
6341been defined, @value{GDBN} uses the default attributes when accessing
6342all memory.
6343
b383017d 6344When a memory region is defined, it is given a number to identify it;
29e57380
C
6345to enable, disable, or remove a memory region, you specify that number.
6346
6347@table @code
6348@kindex mem
bfac230e 6349@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
6350Define a memory region bounded by @var{lower} and @var{upper} with
6351attributes @var{attributes}@dots{}, and add it to the list of regions
6352monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
6353case: it is treated as the the target's maximum memory address.
bfac230e 6354(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
6355
6356@kindex delete mem
6357@item delete mem @var{nums}@dots{}
09d4efe1
EZ
6358Remove memory regions @var{nums}@dots{} from the list of regions
6359monitored by @value{GDBN}.
29e57380
C
6360
6361@kindex disable mem
6362@item disable mem @var{nums}@dots{}
09d4efe1 6363Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 6364A disabled memory region is not forgotten.
29e57380
C
6365It may be enabled again later.
6366
6367@kindex enable mem
6368@item enable mem @var{nums}@dots{}
09d4efe1 6369Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
6370
6371@kindex info mem
6372@item info mem
6373Print a table of all defined memory regions, with the following columns
09d4efe1 6374for each region:
29e57380
C
6375
6376@table @emph
6377@item Memory Region Number
6378@item Enabled or Disabled.
b383017d 6379Enabled memory regions are marked with @samp{y}.
29e57380
C
6380Disabled memory regions are marked with @samp{n}.
6381
6382@item Lo Address
6383The address defining the inclusive lower bound of the memory region.
6384
6385@item Hi Address
6386The address defining the exclusive upper bound of the memory region.
6387
6388@item Attributes
6389The list of attributes set for this memory region.
6390@end table
6391@end table
6392
6393
6394@subsection Attributes
6395
b383017d 6396@subsubsection Memory Access Mode
29e57380
C
6397The access mode attributes set whether @value{GDBN} may make read or
6398write accesses to a memory region.
6399
6400While these attributes prevent @value{GDBN} from performing invalid
6401memory accesses, they do nothing to prevent the target system, I/O DMA,
6402etc. from accessing memory.
6403
6404@table @code
6405@item ro
6406Memory is read only.
6407@item wo
6408Memory is write only.
6409@item rw
6ca652b0 6410Memory is read/write. This is the default.
29e57380
C
6411@end table
6412
6413@subsubsection Memory Access Size
6414The acccess size attributes tells @value{GDBN} to use specific sized
6415accesses in the memory region. Often memory mapped device registers
6416require specific sized accesses. If no access size attribute is
6417specified, @value{GDBN} may use accesses of any size.
6418
6419@table @code
6420@item 8
6421Use 8 bit memory accesses.
6422@item 16
6423Use 16 bit memory accesses.
6424@item 32
6425Use 32 bit memory accesses.
6426@item 64
6427Use 64 bit memory accesses.
6428@end table
6429
6430@c @subsubsection Hardware/Software Breakpoints
6431@c The hardware/software breakpoint attributes set whether @value{GDBN}
6432@c will use hardware or software breakpoints for the internal breakpoints
6433@c used by the step, next, finish, until, etc. commands.
6434@c
6435@c @table @code
6436@c @item hwbreak
b383017d 6437@c Always use hardware breakpoints
29e57380
C
6438@c @item swbreak (default)
6439@c @end table
6440
6441@subsubsection Data Cache
6442The data cache attributes set whether @value{GDBN} will cache target
6443memory. While this generally improves performance by reducing debug
6444protocol overhead, it can lead to incorrect results because @value{GDBN}
6445does not know about volatile variables or memory mapped device
6446registers.
6447
6448@table @code
6449@item cache
b383017d 6450Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6451@item nocache
6452Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6453@end table
6454
6455@c @subsubsection Memory Write Verification
b383017d 6456@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6457@c will re-reads data after each write to verify the write was successful.
6458@c
6459@c @table @code
6460@c @item verify
6461@c @item noverify (default)
6462@c @end table
6463
16d9dec6
MS
6464@node Dump/Restore Files
6465@section Copy between memory and a file
6466@cindex dump/restore files
6467@cindex append data to a file
6468@cindex dump data to a file
6469@cindex restore data from a file
16d9dec6 6470
df5215a6
JB
6471You can use the commands @code{dump}, @code{append}, and
6472@code{restore} to copy data between target memory and a file. The
6473@code{dump} and @code{append} commands write data to a file, and the
6474@code{restore} command reads data from a file back into the inferior's
6475memory. Files may be in binary, Motorola S-record, Intel hex, or
6476Tektronix Hex format; however, @value{GDBN} can only append to binary
6477files.
6478
6479@table @code
6480
6481@kindex dump
6482@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6483@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6484Dump the contents of memory from @var{start_addr} to @var{end_addr},
6485or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6486
df5215a6 6487The @var{format} parameter may be any one of:
16d9dec6 6488@table @code
df5215a6
JB
6489@item binary
6490Raw binary form.
6491@item ihex
6492Intel hex format.
6493@item srec
6494Motorola S-record format.
6495@item tekhex
6496Tektronix Hex format.
6497@end table
6498
6499@value{GDBN} uses the same definitions of these formats as the
6500@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6501@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6502form.
6503
6504@kindex append
6505@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6506@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6507Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 6508or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
6509(@value{GDBN} can only append data to files in raw binary form.)
6510
6511@kindex restore
6512@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6513Restore the contents of file @var{filename} into memory. The
6514@code{restore} command can automatically recognize any known @sc{bfd}
6515file format, except for raw binary. To restore a raw binary file you
6516must specify the optional keyword @code{binary} after the filename.
16d9dec6 6517
b383017d 6518If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6519contained in the file. Binary files always start at address zero, so
6520they will be restored at address @var{bias}. Other bfd files have
6521a built-in location; they will be restored at offset @var{bias}
6522from that location.
6523
6524If @var{start} and/or @var{end} are non-zero, then only data between
6525file offset @var{start} and file offset @var{end} will be restored.
b383017d 6526These offsets are relative to the addresses in the file, before
16d9dec6
MS
6527the @var{bias} argument is applied.
6528
6529@end table
6530
384ee23f
EZ
6531@node Core File Generation
6532@section How to Produce a Core File from Your Program
6533@cindex dump core from inferior
6534
6535A @dfn{core file} or @dfn{core dump} is a file that records the memory
6536image of a running process and its process status (register values
6537etc.). Its primary use is post-mortem debugging of a program that
6538crashed while it ran outside a debugger. A program that crashes
6539automatically produces a core file, unless this feature is disabled by
6540the user. @xref{Files}, for information on invoking @value{GDBN} in
6541the post-mortem debugging mode.
6542
6543Occasionally, you may wish to produce a core file of the program you
6544are debugging in order to preserve a snapshot of its state.
6545@value{GDBN} has a special command for that.
6546
6547@table @code
6548@kindex gcore
6549@kindex generate-core-file
6550@item generate-core-file [@var{file}]
6551@itemx gcore [@var{file}]
6552Produce a core dump of the inferior process. The optional argument
6553@var{file} specifies the file name where to put the core dump. If not
6554specified, the file name defaults to @file{core.@var{pid}}, where
6555@var{pid} is the inferior process ID.
6556
6557Note that this command is implemented only for some systems (as of
6558this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6559@end table
6560
a0eb71c5
KB
6561@node Character Sets
6562@section Character Sets
6563@cindex character sets
6564@cindex charset
6565@cindex translating between character sets
6566@cindex host character set
6567@cindex target character set
6568
6569If the program you are debugging uses a different character set to
6570represent characters and strings than the one @value{GDBN} uses itself,
6571@value{GDBN} can automatically translate between the character sets for
6572you. The character set @value{GDBN} uses we call the @dfn{host
6573character set}; the one the inferior program uses we call the
6574@dfn{target character set}.
6575
6576For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6577uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6578remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6579running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6580then the host character set is Latin-1, and the target character set is
6581@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6582target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6583@sc{ebcdic} and Latin 1 as you print character or string values, or use
6584character and string literals in expressions.
6585
6586@value{GDBN} has no way to automatically recognize which character set
6587the inferior program uses; you must tell it, using the @code{set
6588target-charset} command, described below.
6589
6590Here are the commands for controlling @value{GDBN}'s character set
6591support:
6592
6593@table @code
6594@item set target-charset @var{charset}
6595@kindex set target-charset
6596Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6597character set names @value{GDBN} recognizes below, but if you type
6598@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6599list the target character sets it supports.
a0eb71c5
KB
6600@end table
6601
6602@table @code
6603@item set host-charset @var{charset}
6604@kindex set host-charset
6605Set the current host character set to @var{charset}.
6606
6607By default, @value{GDBN} uses a host character set appropriate to the
6608system it is running on; you can override that default using the
6609@code{set host-charset} command.
6610
6611@value{GDBN} can only use certain character sets as its host character
6612set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6613indicate which can be host character sets, but if you type
6614@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6615list the host character sets it supports.
a0eb71c5
KB
6616
6617@item set charset @var{charset}
6618@kindex set charset
e33d66ec
EZ
6619Set the current host and target character sets to @var{charset}. As
6620above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6621@value{GDBN} will list the name of the character sets that can be used
6622for both host and target.
6623
a0eb71c5
KB
6624
6625@item show charset
a0eb71c5 6626@kindex show charset
b383017d 6627Show the names of the current host and target charsets.
e33d66ec
EZ
6628
6629@itemx show host-charset
a0eb71c5 6630@kindex show host-charset
b383017d 6631Show the name of the current host charset.
e33d66ec
EZ
6632
6633@itemx show target-charset
a0eb71c5 6634@kindex show target-charset
b383017d 6635Show the name of the current target charset.
a0eb71c5
KB
6636
6637@end table
6638
6639@value{GDBN} currently includes support for the following character
6640sets:
6641
6642@table @code
6643
6644@item ASCII
6645@cindex ASCII character set
6646Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6647character set.
6648
6649@item ISO-8859-1
6650@cindex ISO 8859-1 character set
6651@cindex ISO Latin 1 character set
e33d66ec 6652The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6653characters needed for French, German, and Spanish. @value{GDBN} can use
6654this as its host character set.
6655
6656@item EBCDIC-US
6657@itemx IBM1047
6658@cindex EBCDIC character set
6659@cindex IBM1047 character set
6660Variants of the @sc{ebcdic} character set, used on some of IBM's
6661mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6662@value{GDBN} cannot use these as its host character set.
6663
6664@end table
6665
6666Note that these are all single-byte character sets. More work inside
6667GDB is needed to support multi-byte or variable-width character
6668encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6669
6670Here is an example of @value{GDBN}'s character set support in action.
6671Assume that the following source code has been placed in the file
6672@file{charset-test.c}:
6673
6674@smallexample
6675#include <stdio.h>
6676
6677char ascii_hello[]
6678 = @{72, 101, 108, 108, 111, 44, 32, 119,
6679 111, 114, 108, 100, 33, 10, 0@};
6680char ibm1047_hello[]
6681 = @{200, 133, 147, 147, 150, 107, 64, 166,
6682 150, 153, 147, 132, 90, 37, 0@};
6683
6684main ()
6685@{
6686 printf ("Hello, world!\n");
6687@}
10998722 6688@end smallexample
a0eb71c5
KB
6689
6690In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6691containing the string @samp{Hello, world!} followed by a newline,
6692encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6693
6694We compile the program, and invoke the debugger on it:
6695
6696@smallexample
6697$ gcc -g charset-test.c -o charset-test
6698$ gdb -nw charset-test
6699GNU gdb 2001-12-19-cvs
6700Copyright 2001 Free Software Foundation, Inc.
6701@dots{}
f7dc1244 6702(@value{GDBP})
10998722 6703@end smallexample
a0eb71c5
KB
6704
6705We can use the @code{show charset} command to see what character sets
6706@value{GDBN} is currently using to interpret and display characters and
6707strings:
6708
6709@smallexample
f7dc1244 6710(@value{GDBP}) show charset
e33d66ec 6711The current host and target character set is `ISO-8859-1'.
f7dc1244 6712(@value{GDBP})
10998722 6713@end smallexample
a0eb71c5
KB
6714
6715For the sake of printing this manual, let's use @sc{ascii} as our
6716initial character set:
6717@smallexample
f7dc1244
EZ
6718(@value{GDBP}) set charset ASCII
6719(@value{GDBP}) show charset
e33d66ec 6720The current host and target character set is `ASCII'.
f7dc1244 6721(@value{GDBP})
10998722 6722@end smallexample
a0eb71c5
KB
6723
6724Let's assume that @sc{ascii} is indeed the correct character set for our
6725host system --- in other words, let's assume that if @value{GDBN} prints
6726characters using the @sc{ascii} character set, our terminal will display
6727them properly. Since our current target character set is also
6728@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6729
6730@smallexample
f7dc1244 6731(@value{GDBP}) print ascii_hello
a0eb71c5 6732$1 = 0x401698 "Hello, world!\n"
f7dc1244 6733(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6734$2 = 72 'H'
f7dc1244 6735(@value{GDBP})
10998722 6736@end smallexample
a0eb71c5
KB
6737
6738@value{GDBN} uses the target character set for character and string
6739literals you use in expressions:
6740
6741@smallexample
f7dc1244 6742(@value{GDBP}) print '+'
a0eb71c5 6743$3 = 43 '+'
f7dc1244 6744(@value{GDBP})
10998722 6745@end smallexample
a0eb71c5
KB
6746
6747The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6748character.
6749
6750@value{GDBN} relies on the user to tell it which character set the
6751target program uses. If we print @code{ibm1047_hello} while our target
6752character set is still @sc{ascii}, we get jibberish:
6753
6754@smallexample
f7dc1244 6755(@value{GDBP}) print ibm1047_hello
a0eb71c5 6756$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 6757(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6758$5 = 200 '\310'
f7dc1244 6759(@value{GDBP})
10998722 6760@end smallexample
a0eb71c5 6761
e33d66ec 6762If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6763@value{GDBN} tells us the character sets it supports:
6764
6765@smallexample
f7dc1244 6766(@value{GDBP}) set target-charset
b383017d 6767ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 6768(@value{GDBP}) set target-charset
10998722 6769@end smallexample
a0eb71c5
KB
6770
6771We can select @sc{ibm1047} as our target character set, and examine the
6772program's strings again. Now the @sc{ascii} string is wrong, but
6773@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6774target character set, @sc{ibm1047}, to the host character set,
6775@sc{ascii}, and they display correctly:
6776
6777@smallexample
f7dc1244
EZ
6778(@value{GDBP}) set target-charset IBM1047
6779(@value{GDBP}) show charset
e33d66ec
EZ
6780The current host character set is `ASCII'.
6781The current target character set is `IBM1047'.
f7dc1244 6782(@value{GDBP}) print ascii_hello
a0eb71c5 6783$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 6784(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6785$7 = 72 '\110'
f7dc1244 6786(@value{GDBP}) print ibm1047_hello
a0eb71c5 6787$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 6788(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6789$9 = 200 'H'
f7dc1244 6790(@value{GDBP})
10998722 6791@end smallexample
a0eb71c5
KB
6792
6793As above, @value{GDBN} uses the target character set for character and
6794string literals you use in expressions:
6795
6796@smallexample
f7dc1244 6797(@value{GDBP}) print '+'
a0eb71c5 6798$10 = 78 '+'
f7dc1244 6799(@value{GDBP})
10998722 6800@end smallexample
a0eb71c5 6801
e33d66ec 6802The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6803character.
6804
09d4efe1
EZ
6805@node Caching Remote Data
6806@section Caching Data of Remote Targets
6807@cindex caching data of remote targets
6808
6809@value{GDBN} can cache data exchanged between the debugger and a
6810remote target (@pxref{Remote}). Such caching generally improves
6811performance, because it reduces the overhead of the remote protocol by
6812bundling memory reads and writes into large chunks. Unfortunately,
6813@value{GDBN} does not currently know anything about volatile
6814registers, and thus data caching will produce incorrect results when
6815volatile registers are in use.
6816
6817@table @code
6818@kindex set remotecache
6819@item set remotecache on
6820@itemx set remotecache off
6821Set caching state for remote targets. When @code{ON}, use data
6822caching. By default, this option is @code{OFF}.
6823
6824@kindex show remotecache
6825@item show remotecache
6826Show the current state of data caching for remote targets.
6827
6828@kindex info dcache
6829@item info dcache
6830Print the information about the data cache performance. The
6831information displayed includes: the dcache width and depth; and for
6832each cache line, how many times it was referenced, and its data and
6833state (dirty, bad, ok, etc.). This command is useful for debugging
6834the data cache operation.
6835@end table
6836
a0eb71c5 6837
e2e0bcd1
JB
6838@node Macros
6839@chapter C Preprocessor Macros
6840
49efadf5 6841Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
6842``preprocessor macros'' which expand into strings of tokens.
6843@value{GDBN} can evaluate expressions containing macro invocations, show
6844the result of macro expansion, and show a macro's definition, including
6845where it was defined.
6846
6847You may need to compile your program specially to provide @value{GDBN}
6848with information about preprocessor macros. Most compilers do not
6849include macros in their debugging information, even when you compile
6850with the @option{-g} flag. @xref{Compilation}.
6851
6852A program may define a macro at one point, remove that definition later,
6853and then provide a different definition after that. Thus, at different
6854points in the program, a macro may have different definitions, or have
6855no definition at all. If there is a current stack frame, @value{GDBN}
6856uses the macros in scope at that frame's source code line. Otherwise,
6857@value{GDBN} uses the macros in scope at the current listing location;
6858see @ref{List}.
6859
6860At the moment, @value{GDBN} does not support the @code{##}
6861token-splicing operator, the @code{#} stringification operator, or
6862variable-arity macros.
6863
6864Whenever @value{GDBN} evaluates an expression, it always expands any
6865macro invocations present in the expression. @value{GDBN} also provides
6866the following commands for working with macros explicitly.
6867
6868@table @code
6869
6870@kindex macro expand
6871@cindex macro expansion, showing the results of preprocessor
6872@cindex preprocessor macro expansion, showing the results of
6873@cindex expanding preprocessor macros
6874@item macro expand @var{expression}
6875@itemx macro exp @var{expression}
6876Show the results of expanding all preprocessor macro invocations in
6877@var{expression}. Since @value{GDBN} simply expands macros, but does
6878not parse the result, @var{expression} need not be a valid expression;
6879it can be any string of tokens.
6880
09d4efe1 6881@kindex macro exp1
e2e0bcd1
JB
6882@item macro expand-once @var{expression}
6883@itemx macro exp1 @var{expression}
4644b6e3 6884@cindex expand macro once
e2e0bcd1
JB
6885@i{(This command is not yet implemented.)} Show the results of
6886expanding those preprocessor macro invocations that appear explicitly in
6887@var{expression}. Macro invocations appearing in that expansion are
6888left unchanged. This command allows you to see the effect of a
6889particular macro more clearly, without being confused by further
6890expansions. Since @value{GDBN} simply expands macros, but does not
6891parse the result, @var{expression} need not be a valid expression; it
6892can be any string of tokens.
6893
475b0867 6894@kindex info macro
e2e0bcd1
JB
6895@cindex macro definition, showing
6896@cindex definition, showing a macro's
475b0867 6897@item info macro @var{macro}
e2e0bcd1
JB
6898Show the definition of the macro named @var{macro}, and describe the
6899source location where that definition was established.
6900
6901@kindex macro define
6902@cindex user-defined macros
6903@cindex defining macros interactively
6904@cindex macros, user-defined
6905@item macro define @var{macro} @var{replacement-list}
6906@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6907@i{(This command is not yet implemented.)} Introduce a definition for a
6908preprocessor macro named @var{macro}, invocations of which are replaced
6909by the tokens given in @var{replacement-list}. The first form of this
6910command defines an ``object-like'' macro, which takes no arguments; the
6911second form defines a ``function-like'' macro, which takes the arguments
6912given in @var{arglist}.
6913
6914A definition introduced by this command is in scope in every expression
6915evaluated in @value{GDBN}, until it is removed with the @command{macro
6916undef} command, described below. The definition overrides all
6917definitions for @var{macro} present in the program being debugged, as
6918well as any previous user-supplied definition.
6919
6920@kindex macro undef
6921@item macro undef @var{macro}
6922@i{(This command is not yet implemented.)} Remove any user-supplied
6923definition for the macro named @var{macro}. This command only affects
6924definitions provided with the @command{macro define} command, described
6925above; it cannot remove definitions present in the program being
6926debugged.
6927
09d4efe1
EZ
6928@kindex macro list
6929@item macro list
6930@i{(This command is not yet implemented.)} List all the macros
6931defined using the @code{macro define} command.
e2e0bcd1
JB
6932@end table
6933
6934@cindex macros, example of debugging with
6935Here is a transcript showing the above commands in action. First, we
6936show our source files:
6937
6938@smallexample
6939$ cat sample.c
6940#include <stdio.h>
6941#include "sample.h"
6942
6943#define M 42
6944#define ADD(x) (M + x)
6945
6946main ()
6947@{
6948#define N 28
6949 printf ("Hello, world!\n");
6950#undef N
6951 printf ("We're so creative.\n");
6952#define N 1729
6953 printf ("Goodbye, world!\n");
6954@}
6955$ cat sample.h
6956#define Q <
6957$
6958@end smallexample
6959
6960Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6961We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6962compiler includes information about preprocessor macros in the debugging
6963information.
6964
6965@smallexample
6966$ gcc -gdwarf-2 -g3 sample.c -o sample
6967$
6968@end smallexample
6969
6970Now, we start @value{GDBN} on our sample program:
6971
6972@smallexample
6973$ gdb -nw sample
6974GNU gdb 2002-05-06-cvs
6975Copyright 2002 Free Software Foundation, Inc.
6976GDB is free software, @dots{}
f7dc1244 6977(@value{GDBP})
e2e0bcd1
JB
6978@end smallexample
6979
6980We can expand macros and examine their definitions, even when the
6981program is not running. @value{GDBN} uses the current listing position
6982to decide which macro definitions are in scope:
6983
6984@smallexample
f7dc1244 6985(@value{GDBP}) list main
e2e0bcd1
JB
69863
69874 #define M 42
69885 #define ADD(x) (M + x)
69896
69907 main ()
69918 @{
69929 #define N 28
699310 printf ("Hello, world!\n");
699411 #undef N
699512 printf ("We're so creative.\n");
f7dc1244 6996(@value{GDBP}) info macro ADD
e2e0bcd1
JB
6997Defined at /home/jimb/gdb/macros/play/sample.c:5
6998#define ADD(x) (M + x)
f7dc1244 6999(@value{GDBP}) info macro Q
e2e0bcd1
JB
7000Defined at /home/jimb/gdb/macros/play/sample.h:1
7001 included at /home/jimb/gdb/macros/play/sample.c:2
7002#define Q <
f7dc1244 7003(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 7004expands to: (42 + 1)
f7dc1244 7005(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 7006expands to: once (M + 1)
f7dc1244 7007(@value{GDBP})
e2e0bcd1
JB
7008@end smallexample
7009
7010In the example above, note that @command{macro expand-once} expands only
7011the macro invocation explicit in the original text --- the invocation of
7012@code{ADD} --- but does not expand the invocation of the macro @code{M},
7013which was introduced by @code{ADD}.
7014
7015Once the program is running, GDB uses the macro definitions in force at
7016the source line of the current stack frame:
7017
7018@smallexample
f7dc1244 7019(@value{GDBP}) break main
e2e0bcd1 7020Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 7021(@value{GDBP}) run
b383017d 7022Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
7023
7024Breakpoint 1, main () at sample.c:10
702510 printf ("Hello, world!\n");
f7dc1244 7026(@value{GDBP})
e2e0bcd1
JB
7027@end smallexample
7028
7029At line 10, the definition of the macro @code{N} at line 9 is in force:
7030
7031@smallexample
f7dc1244 7032(@value{GDBP}) info macro N
e2e0bcd1
JB
7033Defined at /home/jimb/gdb/macros/play/sample.c:9
7034#define N 28
f7dc1244 7035(@value{GDBP}) macro expand N Q M
e2e0bcd1 7036expands to: 28 < 42
f7dc1244 7037(@value{GDBP}) print N Q M
e2e0bcd1 7038$1 = 1
f7dc1244 7039(@value{GDBP})
e2e0bcd1
JB
7040@end smallexample
7041
7042As we step over directives that remove @code{N}'s definition, and then
7043give it a new definition, @value{GDBN} finds the definition (or lack
7044thereof) in force at each point:
7045
7046@smallexample
f7dc1244 7047(@value{GDBP}) next
e2e0bcd1
JB
7048Hello, world!
704912 printf ("We're so creative.\n");
f7dc1244 7050(@value{GDBP}) info macro N
e2e0bcd1
JB
7051The symbol `N' has no definition as a C/C++ preprocessor macro
7052at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 7053(@value{GDBP}) next
e2e0bcd1
JB
7054We're so creative.
705514 printf ("Goodbye, world!\n");
f7dc1244 7056(@value{GDBP}) info macro N
e2e0bcd1
JB
7057Defined at /home/jimb/gdb/macros/play/sample.c:13
7058#define N 1729
f7dc1244 7059(@value{GDBP}) macro expand N Q M
e2e0bcd1 7060expands to: 1729 < 42
f7dc1244 7061(@value{GDBP}) print N Q M
e2e0bcd1 7062$2 = 0
f7dc1244 7063(@value{GDBP})
e2e0bcd1
JB
7064@end smallexample
7065
7066
b37052ae
EZ
7067@node Tracepoints
7068@chapter Tracepoints
7069@c This chapter is based on the documentation written by Michael
7070@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
7071
7072@cindex tracepoints
7073In some applications, it is not feasible for the debugger to interrupt
7074the program's execution long enough for the developer to learn
7075anything helpful about its behavior. If the program's correctness
7076depends on its real-time behavior, delays introduced by a debugger
7077might cause the program to change its behavior drastically, or perhaps
7078fail, even when the code itself is correct. It is useful to be able
7079to observe the program's behavior without interrupting it.
7080
7081Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
7082specify locations in the program, called @dfn{tracepoints}, and
7083arbitrary expressions to evaluate when those tracepoints are reached.
7084Later, using the @code{tfind} command, you can examine the values
7085those expressions had when the program hit the tracepoints. The
7086expressions may also denote objects in memory---structures or arrays,
7087for example---whose values @value{GDBN} should record; while visiting
7088a particular tracepoint, you may inspect those objects as if they were
7089in memory at that moment. However, because @value{GDBN} records these
7090values without interacting with you, it can do so quickly and
7091unobtrusively, hopefully not disturbing the program's behavior.
7092
7093The tracepoint facility is currently available only for remote
2c0069bb
EZ
7094targets. @xref{Targets}. In addition, your remote target must know how
7095to collect trace data. This functionality is implemented in the remote
7096stub; however, none of the stubs distributed with @value{GDBN} support
7097tracepoints as of this writing.
b37052ae
EZ
7098
7099This chapter describes the tracepoint commands and features.
7100
7101@menu
b383017d
RM
7102* Set Tracepoints::
7103* Analyze Collected Data::
7104* Tracepoint Variables::
b37052ae
EZ
7105@end menu
7106
7107@node Set Tracepoints
7108@section Commands to Set Tracepoints
7109
7110Before running such a @dfn{trace experiment}, an arbitrary number of
7111tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
7112tracepoint has a number assigned to it by @value{GDBN}. Like with
7113breakpoints, tracepoint numbers are successive integers starting from
7114one. Many of the commands associated with tracepoints take the
7115tracepoint number as their argument, to identify which tracepoint to
7116work on.
7117
7118For each tracepoint, you can specify, in advance, some arbitrary set
7119of data that you want the target to collect in the trace buffer when
7120it hits that tracepoint. The collected data can include registers,
7121local variables, or global data. Later, you can use @value{GDBN}
7122commands to examine the values these data had at the time the
7123tracepoint was hit.
7124
7125This section describes commands to set tracepoints and associated
7126conditions and actions.
7127
7128@menu
b383017d
RM
7129* Create and Delete Tracepoints::
7130* Enable and Disable Tracepoints::
7131* Tracepoint Passcounts::
7132* Tracepoint Actions::
7133* Listing Tracepoints::
7134* Starting and Stopping Trace Experiment::
b37052ae
EZ
7135@end menu
7136
7137@node Create and Delete Tracepoints
7138@subsection Create and Delete Tracepoints
7139
7140@table @code
7141@cindex set tracepoint
7142@kindex trace
7143@item trace
7144The @code{trace} command is very similar to the @code{break} command.
7145Its argument can be a source line, a function name, or an address in
7146the target program. @xref{Set Breaks}. The @code{trace} command
7147defines a tracepoint, which is a point in the target program where the
7148debugger will briefly stop, collect some data, and then allow the
7149program to continue. Setting a tracepoint or changing its commands
7150doesn't take effect until the next @code{tstart} command; thus, you
7151cannot change the tracepoint attributes once a trace experiment is
7152running.
7153
7154Here are some examples of using the @code{trace} command:
7155
7156@smallexample
7157(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
7158
7159(@value{GDBP}) @b{trace +2} // 2 lines forward
7160
7161(@value{GDBP}) @b{trace my_function} // first source line of function
7162
7163(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
7164
7165(@value{GDBP}) @b{trace *0x2117c4} // an address
7166@end smallexample
7167
7168@noindent
7169You can abbreviate @code{trace} as @code{tr}.
7170
7171@vindex $tpnum
7172@cindex last tracepoint number
7173@cindex recent tracepoint number
7174@cindex tracepoint number
7175The convenience variable @code{$tpnum} records the tracepoint number
7176of the most recently set tracepoint.
7177
7178@kindex delete tracepoint
7179@cindex tracepoint deletion
7180@item delete tracepoint @r{[}@var{num}@r{]}
7181Permanently delete one or more tracepoints. With no argument, the
7182default is to delete all tracepoints.
7183
7184Examples:
7185
7186@smallexample
7187(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7188
7189(@value{GDBP}) @b{delete trace} // remove all tracepoints
7190@end smallexample
7191
7192@noindent
7193You can abbreviate this command as @code{del tr}.
7194@end table
7195
7196@node Enable and Disable Tracepoints
7197@subsection Enable and Disable Tracepoints
7198
7199@table @code
7200@kindex disable tracepoint
7201@item disable tracepoint @r{[}@var{num}@r{]}
7202Disable tracepoint @var{num}, or all tracepoints if no argument
7203@var{num} is given. A disabled tracepoint will have no effect during
7204the next trace experiment, but it is not forgotten. You can re-enable
7205a disabled tracepoint using the @code{enable tracepoint} command.
7206
7207@kindex enable tracepoint
7208@item enable tracepoint @r{[}@var{num}@r{]}
7209Enable tracepoint @var{num}, or all tracepoints. The enabled
7210tracepoints will become effective the next time a trace experiment is
7211run.
7212@end table
7213
7214@node Tracepoint Passcounts
7215@subsection Tracepoint Passcounts
7216
7217@table @code
7218@kindex passcount
7219@cindex tracepoint pass count
7220@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7221Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7222automatically stop a trace experiment. If a tracepoint's passcount is
7223@var{n}, then the trace experiment will be automatically stopped on
7224the @var{n}'th time that tracepoint is hit. If the tracepoint number
7225@var{num} is not specified, the @code{passcount} command sets the
7226passcount of the most recently defined tracepoint. If no passcount is
7227given, the trace experiment will run until stopped explicitly by the
7228user.
7229
7230Examples:
7231
7232@smallexample
b383017d 7233(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 7234@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
7235
7236(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 7237@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
7238(@value{GDBP}) @b{trace foo}
7239(@value{GDBP}) @b{pass 3}
7240(@value{GDBP}) @b{trace bar}
7241(@value{GDBP}) @b{pass 2}
7242(@value{GDBP}) @b{trace baz}
7243(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
7244@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7245@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7246@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
7247@end smallexample
7248@end table
7249
7250@node Tracepoint Actions
7251@subsection Tracepoint Action Lists
7252
7253@table @code
7254@kindex actions
7255@cindex tracepoint actions
7256@item actions @r{[}@var{num}@r{]}
7257This command will prompt for a list of actions to be taken when the
7258tracepoint is hit. If the tracepoint number @var{num} is not
7259specified, this command sets the actions for the one that was most
7260recently defined (so that you can define a tracepoint and then say
7261@code{actions} without bothering about its number). You specify the
7262actions themselves on the following lines, one action at a time, and
7263terminate the actions list with a line containing just @code{end}. So
7264far, the only defined actions are @code{collect} and
7265@code{while-stepping}.
7266
7267@cindex remove actions from a tracepoint
7268To remove all actions from a tracepoint, type @samp{actions @var{num}}
7269and follow it immediately with @samp{end}.
7270
7271@smallexample
7272(@value{GDBP}) @b{collect @var{data}} // collect some data
7273
6826cf00 7274(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 7275
6826cf00 7276(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
7277@end smallexample
7278
7279In the following example, the action list begins with @code{collect}
7280commands indicating the things to be collected when the tracepoint is
7281hit. Then, in order to single-step and collect additional data
7282following the tracepoint, a @code{while-stepping} command is used,
7283followed by the list of things to be collected while stepping. The
7284@code{while-stepping} command is terminated by its own separate
7285@code{end} command. Lastly, the action list is terminated by an
7286@code{end} command.
7287
7288@smallexample
7289(@value{GDBP}) @b{trace foo}
7290(@value{GDBP}) @b{actions}
7291Enter actions for tracepoint 1, one per line:
7292> collect bar,baz
7293> collect $regs
7294> while-stepping 12
7295 > collect $fp, $sp
7296 > end
7297end
7298@end smallexample
7299
7300@kindex collect @r{(tracepoints)}
7301@item collect @var{expr1}, @var{expr2}, @dots{}
7302Collect values of the given expressions when the tracepoint is hit.
7303This command accepts a comma-separated list of any valid expressions.
7304In addition to global, static, or local variables, the following
7305special arguments are supported:
7306
7307@table @code
7308@item $regs
7309collect all registers
7310
7311@item $args
7312collect all function arguments
7313
7314@item $locals
7315collect all local variables.
7316@end table
7317
7318You can give several consecutive @code{collect} commands, each one
7319with a single argument, or one @code{collect} command with several
7320arguments separated by commas: the effect is the same.
7321
f5c37c66
EZ
7322The command @code{info scope} (@pxref{Symbols, info scope}) is
7323particularly useful for figuring out what data to collect.
7324
b37052ae
EZ
7325@kindex while-stepping @r{(tracepoints)}
7326@item while-stepping @var{n}
7327Perform @var{n} single-step traces after the tracepoint, collecting
7328new data at each step. The @code{while-stepping} command is
7329followed by the list of what to collect while stepping (followed by
7330its own @code{end} command):
7331
7332@smallexample
7333> while-stepping 12
7334 > collect $regs, myglobal
7335 > end
7336>
7337@end smallexample
7338
7339@noindent
7340You may abbreviate @code{while-stepping} as @code{ws} or
7341@code{stepping}.
7342@end table
7343
7344@node Listing Tracepoints
7345@subsection Listing Tracepoints
7346
7347@table @code
7348@kindex info tracepoints
09d4efe1 7349@kindex info tp
b37052ae
EZ
7350@cindex information about tracepoints
7351@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 7352Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 7353a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
7354defined so far. For each tracepoint, the following information is
7355shown:
7356
7357@itemize @bullet
7358@item
7359its number
7360@item
7361whether it is enabled or disabled
7362@item
7363its address
7364@item
7365its passcount as given by the @code{passcount @var{n}} command
7366@item
7367its step count as given by the @code{while-stepping @var{n}} command
7368@item
7369where in the source files is the tracepoint set
7370@item
7371its action list as given by the @code{actions} command
7372@end itemize
7373
7374@smallexample
7375(@value{GDBP}) @b{info trace}
7376Num Enb Address PassC StepC What
73771 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
73782 y 0x0020dc64 0 0 in g_test at g_test.c:1375
73793 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
7380(@value{GDBP})
7381@end smallexample
7382
7383@noindent
7384This command can be abbreviated @code{info tp}.
7385@end table
7386
7387@node Starting and Stopping Trace Experiment
7388@subsection Starting and Stopping Trace Experiment
7389
7390@table @code
7391@kindex tstart
7392@cindex start a new trace experiment
7393@cindex collected data discarded
7394@item tstart
7395This command takes no arguments. It starts the trace experiment, and
7396begins collecting data. This has the side effect of discarding all
7397the data collected in the trace buffer during the previous trace
7398experiment.
7399
7400@kindex tstop
7401@cindex stop a running trace experiment
7402@item tstop
7403This command takes no arguments. It ends the trace experiment, and
7404stops collecting data.
7405
68c71a2e 7406@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
7407automatically if any tracepoint's passcount is reached
7408(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7409
7410@kindex tstatus
7411@cindex status of trace data collection
7412@cindex trace experiment, status of
7413@item tstatus
7414This command displays the status of the current trace data
7415collection.
7416@end table
7417
7418Here is an example of the commands we described so far:
7419
7420@smallexample
7421(@value{GDBP}) @b{trace gdb_c_test}
7422(@value{GDBP}) @b{actions}
7423Enter actions for tracepoint #1, one per line.
7424> collect $regs,$locals,$args
7425> while-stepping 11
7426 > collect $regs
7427 > end
7428> end
7429(@value{GDBP}) @b{tstart}
7430 [time passes @dots{}]
7431(@value{GDBP}) @b{tstop}
7432@end smallexample
7433
7434
7435@node Analyze Collected Data
7436@section Using the collected data
7437
7438After the tracepoint experiment ends, you use @value{GDBN} commands
7439for examining the trace data. The basic idea is that each tracepoint
7440collects a trace @dfn{snapshot} every time it is hit and another
7441snapshot every time it single-steps. All these snapshots are
7442consecutively numbered from zero and go into a buffer, and you can
7443examine them later. The way you examine them is to @dfn{focus} on a
7444specific trace snapshot. When the remote stub is focused on a trace
7445snapshot, it will respond to all @value{GDBN} requests for memory and
7446registers by reading from the buffer which belongs to that snapshot,
7447rather than from @emph{real} memory or registers of the program being
7448debugged. This means that @strong{all} @value{GDBN} commands
7449(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7450behave as if we were currently debugging the program state as it was
7451when the tracepoint occurred. Any requests for data that are not in
7452the buffer will fail.
7453
7454@menu
7455* tfind:: How to select a trace snapshot
7456* tdump:: How to display all data for a snapshot
7457* save-tracepoints:: How to save tracepoints for a future run
7458@end menu
7459
7460@node tfind
7461@subsection @code{tfind @var{n}}
7462
7463@kindex tfind
7464@cindex select trace snapshot
7465@cindex find trace snapshot
7466The basic command for selecting a trace snapshot from the buffer is
7467@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7468counting from zero. If no argument @var{n} is given, the next
7469snapshot is selected.
7470
7471Here are the various forms of using the @code{tfind} command.
7472
7473@table @code
7474@item tfind start
7475Find the first snapshot in the buffer. This is a synonym for
7476@code{tfind 0} (since 0 is the number of the first snapshot).
7477
7478@item tfind none
7479Stop debugging trace snapshots, resume @emph{live} debugging.
7480
7481@item tfind end
7482Same as @samp{tfind none}.
7483
7484@item tfind
7485No argument means find the next trace snapshot.
7486
7487@item tfind -
7488Find the previous trace snapshot before the current one. This permits
7489retracing earlier steps.
7490
7491@item tfind tracepoint @var{num}
7492Find the next snapshot associated with tracepoint @var{num}. Search
7493proceeds forward from the last examined trace snapshot. If no
7494argument @var{num} is given, it means find the next snapshot collected
7495for the same tracepoint as the current snapshot.
7496
7497@item tfind pc @var{addr}
7498Find the next snapshot associated with the value @var{addr} of the
7499program counter. Search proceeds forward from the last examined trace
7500snapshot. If no argument @var{addr} is given, it means find the next
7501snapshot with the same value of PC as the current snapshot.
7502
7503@item tfind outside @var{addr1}, @var{addr2}
7504Find the next snapshot whose PC is outside the given range of
7505addresses.
7506
7507@item tfind range @var{addr1}, @var{addr2}
7508Find the next snapshot whose PC is between @var{addr1} and
7509@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7510
7511@item tfind line @r{[}@var{file}:@r{]}@var{n}
7512Find the next snapshot associated with the source line @var{n}. If
7513the optional argument @var{file} is given, refer to line @var{n} in
7514that source file. Search proceeds forward from the last examined
7515trace snapshot. If no argument @var{n} is given, it means find the
7516next line other than the one currently being examined; thus saying
7517@code{tfind line} repeatedly can appear to have the same effect as
7518stepping from line to line in a @emph{live} debugging session.
7519@end table
7520
7521The default arguments for the @code{tfind} commands are specifically
7522designed to make it easy to scan through the trace buffer. For
7523instance, @code{tfind} with no argument selects the next trace
7524snapshot, and @code{tfind -} with no argument selects the previous
7525trace snapshot. So, by giving one @code{tfind} command, and then
7526simply hitting @key{RET} repeatedly you can examine all the trace
7527snapshots in order. Or, by saying @code{tfind -} and then hitting
7528@key{RET} repeatedly you can examine the snapshots in reverse order.
7529The @code{tfind line} command with no argument selects the snapshot
7530for the next source line executed. The @code{tfind pc} command with
7531no argument selects the next snapshot with the same program counter
7532(PC) as the current frame. The @code{tfind tracepoint} command with
7533no argument selects the next trace snapshot collected by the same
7534tracepoint as the current one.
7535
7536In addition to letting you scan through the trace buffer manually,
7537these commands make it easy to construct @value{GDBN} scripts that
7538scan through the trace buffer and print out whatever collected data
7539you are interested in. Thus, if we want to examine the PC, FP, and SP
7540registers from each trace frame in the buffer, we can say this:
7541
7542@smallexample
7543(@value{GDBP}) @b{tfind start}
7544(@value{GDBP}) @b{while ($trace_frame != -1)}
7545> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7546 $trace_frame, $pc, $sp, $fp
7547> tfind
7548> end
7549
7550Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7551Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7552Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7553Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7554Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7555Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7556Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7557Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7558Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7559Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7560Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7561@end smallexample
7562
7563Or, if we want to examine the variable @code{X} at each source line in
7564the buffer:
7565
7566@smallexample
7567(@value{GDBP}) @b{tfind start}
7568(@value{GDBP}) @b{while ($trace_frame != -1)}
7569> printf "Frame %d, X == %d\n", $trace_frame, X
7570> tfind line
7571> end
7572
7573Frame 0, X = 1
7574Frame 7, X = 2
7575Frame 13, X = 255
7576@end smallexample
7577
7578@node tdump
7579@subsection @code{tdump}
7580@kindex tdump
7581@cindex dump all data collected at tracepoint
7582@cindex tracepoint data, display
7583
7584This command takes no arguments. It prints all the data collected at
7585the current trace snapshot.
7586
7587@smallexample
7588(@value{GDBP}) @b{trace 444}
7589(@value{GDBP}) @b{actions}
7590Enter actions for tracepoint #2, one per line:
7591> collect $regs, $locals, $args, gdb_long_test
7592> end
7593
7594(@value{GDBP}) @b{tstart}
7595
7596(@value{GDBP}) @b{tfind line 444}
7597#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7598at gdb_test.c:444
7599444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7600
7601(@value{GDBP}) @b{tdump}
7602Data collected at tracepoint 2, trace frame 1:
7603d0 0xc4aa0085 -995491707
7604d1 0x18 24
7605d2 0x80 128
7606d3 0x33 51
7607d4 0x71aea3d 119204413
7608d5 0x22 34
7609d6 0xe0 224
7610d7 0x380035 3670069
7611a0 0x19e24a 1696330
7612a1 0x3000668 50333288
7613a2 0x100 256
7614a3 0x322000 3284992
7615a4 0x3000698 50333336
7616a5 0x1ad3cc 1758156
7617fp 0x30bf3c 0x30bf3c
7618sp 0x30bf34 0x30bf34
7619ps 0x0 0
7620pc 0x20b2c8 0x20b2c8
7621fpcontrol 0x0 0
7622fpstatus 0x0 0
7623fpiaddr 0x0 0
7624p = 0x20e5b4 "gdb-test"
7625p1 = (void *) 0x11
7626p2 = (void *) 0x22
7627p3 = (void *) 0x33
7628p4 = (void *) 0x44
7629p5 = (void *) 0x55
7630p6 = (void *) 0x66
7631gdb_long_test = 17 '\021'
7632
7633(@value{GDBP})
7634@end smallexample
7635
7636@node save-tracepoints
7637@subsection @code{save-tracepoints @var{filename}}
7638@kindex save-tracepoints
7639@cindex save tracepoints for future sessions
7640
7641This command saves all current tracepoint definitions together with
7642their actions and passcounts, into a file @file{@var{filename}}
7643suitable for use in a later debugging session. To read the saved
7644tracepoint definitions, use the @code{source} command (@pxref{Command
7645Files}).
7646
7647@node Tracepoint Variables
7648@section Convenience Variables for Tracepoints
7649@cindex tracepoint variables
7650@cindex convenience variables for tracepoints
7651
7652@table @code
7653@vindex $trace_frame
7654@item (int) $trace_frame
7655The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7656snapshot is selected.
7657
7658@vindex $tracepoint
7659@item (int) $tracepoint
7660The tracepoint for the current trace snapshot.
7661
7662@vindex $trace_line
7663@item (int) $trace_line
7664The line number for the current trace snapshot.
7665
7666@vindex $trace_file
7667@item (char []) $trace_file
7668The source file for the current trace snapshot.
7669
7670@vindex $trace_func
7671@item (char []) $trace_func
7672The name of the function containing @code{$tracepoint}.
7673@end table
7674
7675Note: @code{$trace_file} is not suitable for use in @code{printf},
7676use @code{output} instead.
7677
7678Here's a simple example of using these convenience variables for
7679stepping through all the trace snapshots and printing some of their
7680data.
7681
7682@smallexample
7683(@value{GDBP}) @b{tfind start}
7684
7685(@value{GDBP}) @b{while $trace_frame != -1}
7686> output $trace_file
7687> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7688> tfind
7689> end
7690@end smallexample
7691
df0cd8c5
JB
7692@node Overlays
7693@chapter Debugging Programs That Use Overlays
7694@cindex overlays
7695
7696If your program is too large to fit completely in your target system's
7697memory, you can sometimes use @dfn{overlays} to work around this
7698problem. @value{GDBN} provides some support for debugging programs that
7699use overlays.
7700
7701@menu
7702* How Overlays Work:: A general explanation of overlays.
7703* Overlay Commands:: Managing overlays in @value{GDBN}.
7704* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7705 mapped by asking the inferior.
7706* Overlay Sample Program:: A sample program using overlays.
7707@end menu
7708
7709@node How Overlays Work
7710@section How Overlays Work
7711@cindex mapped overlays
7712@cindex unmapped overlays
7713@cindex load address, overlay's
7714@cindex mapped address
7715@cindex overlay area
7716
7717Suppose you have a computer whose instruction address space is only 64
7718kilobytes long, but which has much more memory which can be accessed by
7719other means: special instructions, segment registers, or memory
7720management hardware, for example. Suppose further that you want to
7721adapt a program which is larger than 64 kilobytes to run on this system.
7722
7723One solution is to identify modules of your program which are relatively
7724independent, and need not call each other directly; call these modules
7725@dfn{overlays}. Separate the overlays from the main program, and place
7726their machine code in the larger memory. Place your main program in
7727instruction memory, but leave at least enough space there to hold the
7728largest overlay as well.
7729
7730Now, to call a function located in an overlay, you must first copy that
7731overlay's machine code from the large memory into the space set aside
7732for it in the instruction memory, and then jump to its entry point
7733there.
7734
c928edc0
AC
7735@c NB: In the below the mapped area's size is greater or equal to the
7736@c size of all overlays. This is intentional to remind the developer
7737@c that overlays don't necessarily need to be the same size.
7738
474c8240 7739@smallexample
df0cd8c5 7740@group
c928edc0
AC
7741 Data Instruction Larger
7742Address Space Address Space Address Space
7743+-----------+ +-----------+ +-----------+
7744| | | | | |
7745+-----------+ +-----------+ +-----------+<-- overlay 1
7746| program | | main | .----| overlay 1 | load address
7747| variables | | program | | +-----------+
7748| and heap | | | | | |
7749+-----------+ | | | +-----------+<-- overlay 2
7750| | +-----------+ | | | load address
7751+-----------+ | | | .-| overlay 2 |
7752 | | | | | |
7753 mapped --->+-----------+ | | +-----------+
7754 address | | | | | |
7755 | overlay | <-' | | |
7756 | area | <---' +-----------+<-- overlay 3
7757 | | <---. | | load address
7758 +-----------+ `--| overlay 3 |
7759 | | | |
7760 +-----------+ | |
7761 +-----------+
7762 | |
7763 +-----------+
7764
7765 @anchor{A code overlay}A code overlay
df0cd8c5 7766@end group
474c8240 7767@end smallexample
df0cd8c5 7768
c928edc0
AC
7769The diagram (@pxref{A code overlay}) shows a system with separate data
7770and instruction address spaces. To map an overlay, the program copies
7771its code from the larger address space to the instruction address space.
7772Since the overlays shown here all use the same mapped address, only one
7773may be mapped at a time. For a system with a single address space for
7774data and instructions, the diagram would be similar, except that the
7775program variables and heap would share an address space with the main
7776program and the overlay area.
df0cd8c5
JB
7777
7778An overlay loaded into instruction memory and ready for use is called a
7779@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7780instruction memory. An overlay not present (or only partially present)
7781in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7782is its address in the larger memory. The mapped address is also called
7783the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7784called the @dfn{load memory address}, or @dfn{LMA}.
7785
7786Unfortunately, overlays are not a completely transparent way to adapt a
7787program to limited instruction memory. They introduce a new set of
7788global constraints you must keep in mind as you design your program:
7789
7790@itemize @bullet
7791
7792@item
7793Before calling or returning to a function in an overlay, your program
7794must make sure that overlay is actually mapped. Otherwise, the call or
7795return will transfer control to the right address, but in the wrong
7796overlay, and your program will probably crash.
7797
7798@item
7799If the process of mapping an overlay is expensive on your system, you
7800will need to choose your overlays carefully to minimize their effect on
7801your program's performance.
7802
7803@item
7804The executable file you load onto your system must contain each
7805overlay's instructions, appearing at the overlay's load address, not its
7806mapped address. However, each overlay's instructions must be relocated
7807and its symbols defined as if the overlay were at its mapped address.
7808You can use GNU linker scripts to specify different load and relocation
7809addresses for pieces of your program; see @ref{Overlay Description,,,
7810ld.info, Using ld: the GNU linker}.
7811
7812@item
7813The procedure for loading executable files onto your system must be able
7814to load their contents into the larger address space as well as the
7815instruction and data spaces.
7816
7817@end itemize
7818
7819The overlay system described above is rather simple, and could be
7820improved in many ways:
7821
7822@itemize @bullet
7823
7824@item
7825If your system has suitable bank switch registers or memory management
7826hardware, you could use those facilities to make an overlay's load area
7827contents simply appear at their mapped address in instruction space.
7828This would probably be faster than copying the overlay to its mapped
7829area in the usual way.
7830
7831@item
7832If your overlays are small enough, you could set aside more than one
7833overlay area, and have more than one overlay mapped at a time.
7834
7835@item
7836You can use overlays to manage data, as well as instructions. In
7837general, data overlays are even less transparent to your design than
7838code overlays: whereas code overlays only require care when you call or
7839return to functions, data overlays require care every time you access
7840the data. Also, if you change the contents of a data overlay, you
7841must copy its contents back out to its load address before you can copy a
7842different data overlay into the same mapped area.
7843
7844@end itemize
7845
7846
7847@node Overlay Commands
7848@section Overlay Commands
7849
7850To use @value{GDBN}'s overlay support, each overlay in your program must
7851correspond to a separate section of the executable file. The section's
7852virtual memory address and load memory address must be the overlay's
7853mapped and load addresses. Identifying overlays with sections allows
7854@value{GDBN} to determine the appropriate address of a function or
7855variable, depending on whether the overlay is mapped or not.
7856
7857@value{GDBN}'s overlay commands all start with the word @code{overlay};
7858you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7859
7860@table @code
7861@item overlay off
4644b6e3 7862@kindex overlay
df0cd8c5
JB
7863Disable @value{GDBN}'s overlay support. When overlay support is
7864disabled, @value{GDBN} assumes that all functions and variables are
7865always present at their mapped addresses. By default, @value{GDBN}'s
7866overlay support is disabled.
7867
7868@item overlay manual
df0cd8c5
JB
7869@cindex manual overlay debugging
7870Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7871relies on you to tell it which overlays are mapped, and which are not,
7872using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7873commands described below.
7874
7875@item overlay map-overlay @var{overlay}
7876@itemx overlay map @var{overlay}
df0cd8c5
JB
7877@cindex map an overlay
7878Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7879be the name of the object file section containing the overlay. When an
7880overlay is mapped, @value{GDBN} assumes it can find the overlay's
7881functions and variables at their mapped addresses. @value{GDBN} assumes
7882that any other overlays whose mapped ranges overlap that of
7883@var{overlay} are now unmapped.
7884
7885@item overlay unmap-overlay @var{overlay}
7886@itemx overlay unmap @var{overlay}
df0cd8c5
JB
7887@cindex unmap an overlay
7888Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7889must be the name of the object file section containing the overlay.
7890When an overlay is unmapped, @value{GDBN} assumes it can find the
7891overlay's functions and variables at their load addresses.
7892
7893@item overlay auto
df0cd8c5
JB
7894Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7895consults a data structure the overlay manager maintains in the inferior
7896to see which overlays are mapped. For details, see @ref{Automatic
7897Overlay Debugging}.
7898
7899@item overlay load-target
7900@itemx overlay load
df0cd8c5
JB
7901@cindex reloading the overlay table
7902Re-read the overlay table from the inferior. Normally, @value{GDBN}
7903re-reads the table @value{GDBN} automatically each time the inferior
7904stops, so this command should only be necessary if you have changed the
7905overlay mapping yourself using @value{GDBN}. This command is only
7906useful when using automatic overlay debugging.
7907
7908@item overlay list-overlays
7909@itemx overlay list
7910@cindex listing mapped overlays
7911Display a list of the overlays currently mapped, along with their mapped
7912addresses, load addresses, and sizes.
7913
7914@end table
7915
7916Normally, when @value{GDBN} prints a code address, it includes the name
7917of the function the address falls in:
7918
474c8240 7919@smallexample
f7dc1244 7920(@value{GDBP}) print main
df0cd8c5 7921$3 = @{int ()@} 0x11a0 <main>
474c8240 7922@end smallexample
df0cd8c5
JB
7923@noindent
7924When overlay debugging is enabled, @value{GDBN} recognizes code in
7925unmapped overlays, and prints the names of unmapped functions with
7926asterisks around them. For example, if @code{foo} is a function in an
7927unmapped overlay, @value{GDBN} prints it this way:
7928
474c8240 7929@smallexample
f7dc1244 7930(@value{GDBP}) overlay list
df0cd8c5 7931No sections are mapped.
f7dc1244 7932(@value{GDBP}) print foo
df0cd8c5 7933$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7934@end smallexample
df0cd8c5
JB
7935@noindent
7936When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7937name normally:
7938
474c8240 7939@smallexample
f7dc1244 7940(@value{GDBP}) overlay list
b383017d 7941Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 7942 mapped at 0x1016 - 0x104a
f7dc1244 7943(@value{GDBP}) print foo
df0cd8c5 7944$6 = @{int (int)@} 0x1016 <foo>
474c8240 7945@end smallexample
df0cd8c5
JB
7946
7947When overlay debugging is enabled, @value{GDBN} can find the correct
7948address for functions and variables in an overlay, whether or not the
7949overlay is mapped. This allows most @value{GDBN} commands, like
7950@code{break} and @code{disassemble}, to work normally, even on unmapped
7951code. However, @value{GDBN}'s breakpoint support has some limitations:
7952
7953@itemize @bullet
7954@item
7955@cindex breakpoints in overlays
7956@cindex overlays, setting breakpoints in
7957You can set breakpoints in functions in unmapped overlays, as long as
7958@value{GDBN} can write to the overlay at its load address.
7959@item
7960@value{GDBN} can not set hardware or simulator-based breakpoints in
7961unmapped overlays. However, if you set a breakpoint at the end of your
7962overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7963you are using manual overlay management), @value{GDBN} will re-set its
7964breakpoints properly.
7965@end itemize
7966
7967
7968@node Automatic Overlay Debugging
7969@section Automatic Overlay Debugging
7970@cindex automatic overlay debugging
7971
7972@value{GDBN} can automatically track which overlays are mapped and which
7973are not, given some simple co-operation from the overlay manager in the
7974inferior. If you enable automatic overlay debugging with the
7975@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7976looks in the inferior's memory for certain variables describing the
7977current state of the overlays.
7978
7979Here are the variables your overlay manager must define to support
7980@value{GDBN}'s automatic overlay debugging:
7981
7982@table @asis
7983
7984@item @code{_ovly_table}:
7985This variable must be an array of the following structures:
7986
474c8240 7987@smallexample
df0cd8c5
JB
7988struct
7989@{
7990 /* The overlay's mapped address. */
7991 unsigned long vma;
7992
7993 /* The size of the overlay, in bytes. */
7994 unsigned long size;
7995
7996 /* The overlay's load address. */
7997 unsigned long lma;
7998
7999 /* Non-zero if the overlay is currently mapped;
8000 zero otherwise. */
8001 unsigned long mapped;
8002@}
474c8240 8003@end smallexample
df0cd8c5
JB
8004
8005@item @code{_novlys}:
8006This variable must be a four-byte signed integer, holding the total
8007number of elements in @code{_ovly_table}.
8008
8009@end table
8010
8011To decide whether a particular overlay is mapped or not, @value{GDBN}
8012looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
8013@code{lma} members equal the VMA and LMA of the overlay's section in the
8014executable file. When @value{GDBN} finds a matching entry, it consults
8015the entry's @code{mapped} member to determine whether the overlay is
8016currently mapped.
8017
81d46470 8018In addition, your overlay manager may define a function called
def71bfa 8019@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
8020will silently set a breakpoint there. If the overlay manager then
8021calls this function whenever it has changed the overlay table, this
8022will enable @value{GDBN} to accurately keep track of which overlays
8023are in program memory, and update any breakpoints that may be set
b383017d 8024in overlays. This will allow breakpoints to work even if the
81d46470
MS
8025overlays are kept in ROM or other non-writable memory while they
8026are not being executed.
df0cd8c5
JB
8027
8028@node Overlay Sample Program
8029@section Overlay Sample Program
8030@cindex overlay example program
8031
8032When linking a program which uses overlays, you must place the overlays
8033at their load addresses, while relocating them to run at their mapped
8034addresses. To do this, you must write a linker script (@pxref{Overlay
8035Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
8036since linker scripts are specific to a particular host system, target
8037architecture, and target memory layout, this manual cannot provide
8038portable sample code demonstrating @value{GDBN}'s overlay support.
8039
8040However, the @value{GDBN} source distribution does contain an overlaid
8041program, with linker scripts for a few systems, as part of its test
8042suite. The program consists of the following files from
8043@file{gdb/testsuite/gdb.base}:
8044
8045@table @file
8046@item overlays.c
8047The main program file.
8048@item ovlymgr.c
8049A simple overlay manager, used by @file{overlays.c}.
8050@item foo.c
8051@itemx bar.c
8052@itemx baz.c
8053@itemx grbx.c
8054Overlay modules, loaded and used by @file{overlays.c}.
8055@item d10v.ld
8056@itemx m32r.ld
8057Linker scripts for linking the test program on the @code{d10v-elf}
8058and @code{m32r-elf} targets.
8059@end table
8060
8061You can build the test program using the @code{d10v-elf} GCC
8062cross-compiler like this:
8063
474c8240 8064@smallexample
df0cd8c5
JB
8065$ d10v-elf-gcc -g -c overlays.c
8066$ d10v-elf-gcc -g -c ovlymgr.c
8067$ d10v-elf-gcc -g -c foo.c
8068$ d10v-elf-gcc -g -c bar.c
8069$ d10v-elf-gcc -g -c baz.c
8070$ d10v-elf-gcc -g -c grbx.c
8071$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
8072 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 8073@end smallexample
df0cd8c5
JB
8074
8075The build process is identical for any other architecture, except that
8076you must substitute the appropriate compiler and linker script for the
8077target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
8078
8079
6d2ebf8b 8080@node Languages
c906108c
SS
8081@chapter Using @value{GDBN} with Different Languages
8082@cindex languages
8083
c906108c
SS
8084Although programming languages generally have common aspects, they are
8085rarely expressed in the same manner. For instance, in ANSI C,
8086dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
8087Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 8088represented (and displayed) differently. Hex numbers in C appear as
c906108c 8089@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
8090
8091@cindex working language
8092Language-specific information is built into @value{GDBN} for some languages,
8093allowing you to express operations like the above in your program's
8094native language, and allowing @value{GDBN} to output values in a manner
8095consistent with the syntax of your program's native language. The
8096language you use to build expressions is called the @dfn{working
8097language}.
8098
8099@menu
8100* Setting:: Switching between source languages
8101* Show:: Displaying the language
c906108c 8102* Checks:: Type and range checks
9c16f35a 8103* Supported languages:: Supported languages
4e562065 8104* Unsupported languages:: Unsupported languages
c906108c
SS
8105@end menu
8106
6d2ebf8b 8107@node Setting
c906108c
SS
8108@section Switching between source languages
8109
8110There are two ways to control the working language---either have @value{GDBN}
8111set it automatically, or select it manually yourself. You can use the
8112@code{set language} command for either purpose. On startup, @value{GDBN}
8113defaults to setting the language automatically. The working language is
8114used to determine how expressions you type are interpreted, how values
8115are printed, etc.
8116
8117In addition to the working language, every source file that
8118@value{GDBN} knows about has its own working language. For some object
8119file formats, the compiler might indicate which language a particular
8120source file is in. However, most of the time @value{GDBN} infers the
8121language from the name of the file. The language of a source file
b37052ae 8122controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 8123show each frame appropriately for its own language. There is no way to
d4f3574e
SS
8124set the language of a source file from within @value{GDBN}, but you can
8125set the language associated with a filename extension. @xref{Show, ,
8126Displaying the language}.
c906108c
SS
8127
8128This is most commonly a problem when you use a program, such
5d161b24 8129as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
8130another language. In that case, make the
8131program use @code{#line} directives in its C output; that way
8132@value{GDBN} will know the correct language of the source code of the original
8133program, and will display that source code, not the generated C code.
8134
8135@menu
8136* Filenames:: Filename extensions and languages.
8137* Manually:: Setting the working language manually
8138* Automatically:: Having @value{GDBN} infer the source language
8139@end menu
8140
6d2ebf8b 8141@node Filenames
c906108c
SS
8142@subsection List of filename extensions and languages
8143
8144If a source file name ends in one of the following extensions, then
8145@value{GDBN} infers that its language is the one indicated.
8146
8147@table @file
e07c999f
PH
8148@item .ada
8149@itemx .ads
8150@itemx .adb
8151@itemx .a
8152Ada source file.
c906108c
SS
8153
8154@item .c
8155C source file
8156
8157@item .C
8158@itemx .cc
8159@itemx .cp
8160@itemx .cpp
8161@itemx .cxx
8162@itemx .c++
b37052ae 8163C@t{++} source file
c906108c 8164
b37303ee
AF
8165@item .m
8166Objective-C source file
8167
c906108c
SS
8168@item .f
8169@itemx .F
8170Fortran source file
8171
c906108c
SS
8172@item .mod
8173Modula-2 source file
c906108c
SS
8174
8175@item .s
8176@itemx .S
8177Assembler source file. This actually behaves almost like C, but
8178@value{GDBN} does not skip over function prologues when stepping.
8179@end table
8180
8181In addition, you may set the language associated with a filename
8182extension. @xref{Show, , Displaying the language}.
8183
6d2ebf8b 8184@node Manually
c906108c
SS
8185@subsection Setting the working language
8186
8187If you allow @value{GDBN} to set the language automatically,
8188expressions are interpreted the same way in your debugging session and
8189your program.
8190
8191@kindex set language
8192If you wish, you may set the language manually. To do this, issue the
8193command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 8194a language, such as
c906108c 8195@code{c} or @code{modula-2}.
c906108c
SS
8196For a list of the supported languages, type @samp{set language}.
8197
c906108c
SS
8198Setting the language manually prevents @value{GDBN} from updating the working
8199language automatically. This can lead to confusion if you try
8200to debug a program when the working language is not the same as the
8201source language, when an expression is acceptable to both
8202languages---but means different things. For instance, if the current
8203source file were written in C, and @value{GDBN} was parsing Modula-2, a
8204command such as:
8205
474c8240 8206@smallexample
c906108c 8207print a = b + c
474c8240 8208@end smallexample
c906108c
SS
8209
8210@noindent
8211might not have the effect you intended. In C, this means to add
8212@code{b} and @code{c} and place the result in @code{a}. The result
8213printed would be the value of @code{a}. In Modula-2, this means to compare
8214@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 8215
6d2ebf8b 8216@node Automatically
c906108c
SS
8217@subsection Having @value{GDBN} infer the source language
8218
8219To have @value{GDBN} set the working language automatically, use
8220@samp{set language local} or @samp{set language auto}. @value{GDBN}
8221then infers the working language. That is, when your program stops in a
8222frame (usually by encountering a breakpoint), @value{GDBN} sets the
8223working language to the language recorded for the function in that
8224frame. If the language for a frame is unknown (that is, if the function
8225or block corresponding to the frame was defined in a source file that
8226does not have a recognized extension), the current working language is
8227not changed, and @value{GDBN} issues a warning.
8228
8229This may not seem necessary for most programs, which are written
8230entirely in one source language. However, program modules and libraries
8231written in one source language can be used by a main program written in
8232a different source language. Using @samp{set language auto} in this
8233case frees you from having to set the working language manually.
8234
6d2ebf8b 8235@node Show
c906108c 8236@section Displaying the language
c906108c
SS
8237
8238The following commands help you find out which language is the
8239working language, and also what language source files were written in.
8240
c906108c
SS
8241@table @code
8242@item show language
9c16f35a 8243@kindex show language
c906108c
SS
8244Display the current working language. This is the
8245language you can use with commands such as @code{print} to
8246build and compute expressions that may involve variables in your program.
8247
8248@item info frame
4644b6e3 8249@kindex info frame@r{, show the source language}
5d161b24 8250Display the source language for this frame. This language becomes the
c906108c 8251working language if you use an identifier from this frame.
5d161b24 8252@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
8253information listed here.
8254
8255@item info source
4644b6e3 8256@kindex info source@r{, show the source language}
c906108c 8257Display the source language of this source file.
5d161b24 8258@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
8259information listed here.
8260@end table
8261
8262In unusual circumstances, you may have source files with extensions
8263not in the standard list. You can then set the extension associated
8264with a language explicitly:
8265
c906108c 8266@table @code
09d4efe1 8267@item set extension-language @var{ext} @var{language}
9c16f35a 8268@kindex set extension-language
09d4efe1
EZ
8269Tell @value{GDBN} that source files with extension @var{ext} are to be
8270assumed as written in the source language @var{language}.
c906108c
SS
8271
8272@item info extensions
9c16f35a 8273@kindex info extensions
c906108c
SS
8274List all the filename extensions and the associated languages.
8275@end table
8276
6d2ebf8b 8277@node Checks
c906108c
SS
8278@section Type and range checking
8279
8280@quotation
8281@emph{Warning:} In this release, the @value{GDBN} commands for type and range
8282checking are included, but they do not yet have any effect. This
8283section documents the intended facilities.
8284@end quotation
8285@c FIXME remove warning when type/range code added
8286
8287Some languages are designed to guard you against making seemingly common
8288errors through a series of compile- and run-time checks. These include
8289checking the type of arguments to functions and operators, and making
8290sure mathematical overflows are caught at run time. Checks such as
8291these help to ensure a program's correctness once it has been compiled
8292by eliminating type mismatches, and providing active checks for range
8293errors when your program is running.
8294
8295@value{GDBN} can check for conditions like the above if you wish.
9c16f35a
EZ
8296Although @value{GDBN} does not check the statements in your program,
8297it can check expressions entered directly into @value{GDBN} for
8298evaluation via the @code{print} command, for example. As with the
8299working language, @value{GDBN} can also decide whether or not to check
8300automatically based on your program's source language.
8301@xref{Supported languages, ,Supported languages}, for the default
8302settings of supported languages.
c906108c
SS
8303
8304@menu
8305* Type Checking:: An overview of type checking
8306* Range Checking:: An overview of range checking
8307@end menu
8308
8309@cindex type checking
8310@cindex checks, type
6d2ebf8b 8311@node Type Checking
c906108c
SS
8312@subsection An overview of type checking
8313
8314Some languages, such as Modula-2, are strongly typed, meaning that the
8315arguments to operators and functions have to be of the correct type,
8316otherwise an error occurs. These checks prevent type mismatch
8317errors from ever causing any run-time problems. For example,
8318
8319@smallexample
83201 + 2 @result{} 3
8321@exdent but
8322@error{} 1 + 2.3
8323@end smallexample
8324
8325The second example fails because the @code{CARDINAL} 1 is not
8326type-compatible with the @code{REAL} 2.3.
8327
5d161b24
DB
8328For the expressions you use in @value{GDBN} commands, you can tell the
8329@value{GDBN} type checker to skip checking;
8330to treat any mismatches as errors and abandon the expression;
8331or to only issue warnings when type mismatches occur,
c906108c
SS
8332but evaluate the expression anyway. When you choose the last of
8333these, @value{GDBN} evaluates expressions like the second example above, but
8334also issues a warning.
8335
5d161b24
DB
8336Even if you turn type checking off, there may be other reasons
8337related to type that prevent @value{GDBN} from evaluating an expression.
8338For instance, @value{GDBN} does not know how to add an @code{int} and
8339a @code{struct foo}. These particular type errors have nothing to do
8340with the language in use, and usually arise from expressions, such as
c906108c
SS
8341the one described above, which make little sense to evaluate anyway.
8342
8343Each language defines to what degree it is strict about type. For
8344instance, both Modula-2 and C require the arguments to arithmetical
8345operators to be numbers. In C, enumerated types and pointers can be
8346represented as numbers, so that they are valid arguments to mathematical
9c16f35a 8347operators. @xref{Supported languages, ,Supported languages}, for further
c906108c
SS
8348details on specific languages.
8349
8350@value{GDBN} provides some additional commands for controlling the type checker:
8351
c906108c
SS
8352@kindex set check type
8353@kindex show check type
8354@table @code
8355@item set check type auto
8356Set type checking on or off based on the current working language.
9c16f35a 8357@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8358each language.
8359
8360@item set check type on
8361@itemx set check type off
8362Set type checking on or off, overriding the default setting for the
8363current working language. Issue a warning if the setting does not
8364match the language default. If any type mismatches occur in
d4f3574e 8365evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
8366message and aborts evaluation of the expression.
8367
8368@item set check type warn
8369Cause the type checker to issue warnings, but to always attempt to
8370evaluate the expression. Evaluating the expression may still
8371be impossible for other reasons. For example, @value{GDBN} cannot add
8372numbers and structures.
8373
8374@item show type
5d161b24 8375Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
8376is setting it automatically.
8377@end table
8378
8379@cindex range checking
8380@cindex checks, range
6d2ebf8b 8381@node Range Checking
c906108c
SS
8382@subsection An overview of range checking
8383
8384In some languages (such as Modula-2), it is an error to exceed the
8385bounds of a type; this is enforced with run-time checks. Such range
8386checking is meant to ensure program correctness by making sure
8387computations do not overflow, or indices on an array element access do
8388not exceed the bounds of the array.
8389
8390For expressions you use in @value{GDBN} commands, you can tell
8391@value{GDBN} to treat range errors in one of three ways: ignore them,
8392always treat them as errors and abandon the expression, or issue
8393warnings but evaluate the expression anyway.
8394
8395A range error can result from numerical overflow, from exceeding an
8396array index bound, or when you type a constant that is not a member
8397of any type. Some languages, however, do not treat overflows as an
8398error. In many implementations of C, mathematical overflow causes the
8399result to ``wrap around'' to lower values---for example, if @var{m} is
8400the largest integer value, and @var{s} is the smallest, then
8401
474c8240 8402@smallexample
c906108c 8403@var{m} + 1 @result{} @var{s}
474c8240 8404@end smallexample
c906108c
SS
8405
8406This, too, is specific to individual languages, and in some cases
9c16f35a 8407specific to individual compilers or machines. @xref{Supported languages, ,
c906108c
SS
8408Supported languages}, for further details on specific languages.
8409
8410@value{GDBN} provides some additional commands for controlling the range checker:
8411
c906108c
SS
8412@kindex set check range
8413@kindex show check range
8414@table @code
8415@item set check range auto
8416Set range checking on or off based on the current working language.
9c16f35a 8417@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8418each language.
8419
8420@item set check range on
8421@itemx set check range off
8422Set range checking on or off, overriding the default setting for the
8423current working language. A warning is issued if the setting does not
c3f6f71d
JM
8424match the language default. If a range error occurs and range checking is on,
8425then a message is printed and evaluation of the expression is aborted.
c906108c
SS
8426
8427@item set check range warn
8428Output messages when the @value{GDBN} range checker detects a range error,
8429but attempt to evaluate the expression anyway. Evaluating the
8430expression may still be impossible for other reasons, such as accessing
8431memory that the process does not own (a typical example from many Unix
8432systems).
8433
8434@item show range
8435Show the current setting of the range checker, and whether or not it is
8436being set automatically by @value{GDBN}.
8437@end table
c906108c 8438
9c16f35a 8439@node Supported languages
c906108c 8440@section Supported languages
c906108c 8441
9c16f35a
EZ
8442@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
8443assembly, Modula-2, and Ada.
cce74817 8444@c This is false ...
c906108c
SS
8445Some @value{GDBN} features may be used in expressions regardless of the
8446language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8447and the @samp{@{type@}addr} construct (@pxref{Expressions,
8448,Expressions}) can be used with the constructs of any supported
8449language.
8450
8451The following sections detail to what degree each source language is
8452supported by @value{GDBN}. These sections are not meant to be language
8453tutorials or references, but serve only as a reference guide to what the
8454@value{GDBN} expression parser accepts, and what input and output
8455formats should look like for different languages. There are many good
8456books written on each of these languages; please look to these for a
8457language reference or tutorial.
8458
c906108c 8459@menu
b37303ee 8460* C:: C and C@t{++}
b383017d 8461* Objective-C:: Objective-C
09d4efe1 8462* Fortran:: Fortran
9c16f35a 8463* Pascal:: Pascal
b37303ee 8464* Modula-2:: Modula-2
e07c999f 8465* Ada:: Ada
c906108c
SS
8466@end menu
8467
6d2ebf8b 8468@node C
b37052ae 8469@subsection C and C@t{++}
7a292a7a 8470
b37052ae
EZ
8471@cindex C and C@t{++}
8472@cindex expressions in C or C@t{++}
c906108c 8473
b37052ae 8474Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8475to both languages. Whenever this is the case, we discuss those languages
8476together.
8477
41afff9a
EZ
8478@cindex C@t{++}
8479@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8480@cindex @sc{gnu} C@t{++}
8481The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8482compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8483effectively, you must compile your C@t{++} programs with a supported
8484C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8485compiler (@code{aCC}).
8486
0179ffac
DC
8487For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8488format; if it doesn't work on your system, try the stabs+ debugging
8489format. You can select those formats explicitly with the @code{g++}
8490command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8491@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8492CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8493
c906108c 8494@menu
b37052ae
EZ
8495* C Operators:: C and C@t{++} operators
8496* C Constants:: C and C@t{++} constants
8497* C plus plus expressions:: C@t{++} expressions
8498* C Defaults:: Default settings for C and C@t{++}
8499* C Checks:: C and C@t{++} type and range checks
c906108c 8500* Debugging C:: @value{GDBN} and C
b37052ae 8501* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8502@end menu
c906108c 8503
6d2ebf8b 8504@node C Operators
b37052ae 8505@subsubsection C and C@t{++} operators
7a292a7a 8506
b37052ae 8507@cindex C and C@t{++} operators
c906108c
SS
8508
8509Operators must be defined on values of specific types. For instance,
8510@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8511often defined on groups of types.
c906108c 8512
b37052ae 8513For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8514
8515@itemize @bullet
53a5351d 8516
c906108c 8517@item
c906108c 8518@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8519specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8520
8521@item
d4f3574e
SS
8522@emph{Floating-point types} include @code{float}, @code{double}, and
8523@code{long double} (if supported by the target platform).
c906108c
SS
8524
8525@item
53a5351d 8526@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8527
8528@item
8529@emph{Scalar types} include all of the above.
53a5351d 8530
c906108c
SS
8531@end itemize
8532
8533@noindent
8534The following operators are supported. They are listed here
8535in order of increasing precedence:
8536
8537@table @code
8538@item ,
8539The comma or sequencing operator. Expressions in a comma-separated list
8540are evaluated from left to right, with the result of the entire
8541expression being the last expression evaluated.
8542
8543@item =
8544Assignment. The value of an assignment expression is the value
8545assigned. Defined on scalar types.
8546
8547@item @var{op}=
8548Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8549and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8550@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8551@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8552@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8553
8554@item ?:
8555The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8556of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8557integral type.
8558
8559@item ||
8560Logical @sc{or}. Defined on integral types.
8561
8562@item &&
8563Logical @sc{and}. Defined on integral types.
8564
8565@item |
8566Bitwise @sc{or}. Defined on integral types.
8567
8568@item ^
8569Bitwise exclusive-@sc{or}. Defined on integral types.
8570
8571@item &
8572Bitwise @sc{and}. Defined on integral types.
8573
8574@item ==@r{, }!=
8575Equality and inequality. Defined on scalar types. The value of these
8576expressions is 0 for false and non-zero for true.
8577
8578@item <@r{, }>@r{, }<=@r{, }>=
8579Less than, greater than, less than or equal, greater than or equal.
8580Defined on scalar types. The value of these expressions is 0 for false
8581and non-zero for true.
8582
8583@item <<@r{, }>>
8584left shift, and right shift. Defined on integral types.
8585
8586@item @@
8587The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8588
8589@item +@r{, }-
8590Addition and subtraction. Defined on integral types, floating-point types and
8591pointer types.
8592
8593@item *@r{, }/@r{, }%
8594Multiplication, division, and modulus. Multiplication and division are
8595defined on integral and floating-point types. Modulus is defined on
8596integral types.
8597
8598@item ++@r{, }--
8599Increment and decrement. When appearing before a variable, the
8600operation is performed before the variable is used in an expression;
8601when appearing after it, the variable's value is used before the
8602operation takes place.
8603
8604@item *
8605Pointer dereferencing. Defined on pointer types. Same precedence as
8606@code{++}.
8607
8608@item &
8609Address operator. Defined on variables. Same precedence as @code{++}.
8610
b37052ae
EZ
8611For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8612allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8613(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8614where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8615stored.
c906108c
SS
8616
8617@item -
8618Negative. Defined on integral and floating-point types. Same
8619precedence as @code{++}.
8620
8621@item !
8622Logical negation. Defined on integral types. Same precedence as
8623@code{++}.
8624
8625@item ~
8626Bitwise complement operator. Defined on integral types. Same precedence as
8627@code{++}.
8628
8629
8630@item .@r{, }->
8631Structure member, and pointer-to-structure member. For convenience,
8632@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8633pointer based on the stored type information.
8634Defined on @code{struct} and @code{union} data.
8635
c906108c
SS
8636@item .*@r{, }->*
8637Dereferences of pointers to members.
c906108c
SS
8638
8639@item []
8640Array indexing. @code{@var{a}[@var{i}]} is defined as
8641@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8642
8643@item ()
8644Function parameter list. Same precedence as @code{->}.
8645
c906108c 8646@item ::
b37052ae 8647C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8648and @code{class} types.
c906108c
SS
8649
8650@item ::
7a292a7a
SS
8651Doubled colons also represent the @value{GDBN} scope operator
8652(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8653above.
c906108c
SS
8654@end table
8655
c906108c
SS
8656If an operator is redefined in the user code, @value{GDBN} usually
8657attempts to invoke the redefined version instead of using the operator's
8658predefined meaning.
c906108c 8659
c906108c 8660@menu
5d161b24 8661* C Constants::
c906108c
SS
8662@end menu
8663
6d2ebf8b 8664@node C Constants
b37052ae 8665@subsubsection C and C@t{++} constants
c906108c 8666
b37052ae 8667@cindex C and C@t{++} constants
c906108c 8668
b37052ae 8669@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8670following ways:
c906108c
SS
8671
8672@itemize @bullet
8673@item
8674Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8675specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8676by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8677@samp{l}, specifying that the constant should be treated as a
8678@code{long} value.
8679
8680@item
8681Floating point constants are a sequence of digits, followed by a decimal
8682point, followed by a sequence of digits, and optionally followed by an
8683exponent. An exponent is of the form:
8684@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8685sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8686A floating-point constant may also end with a letter @samp{f} or
8687@samp{F}, specifying that the constant should be treated as being of
8688the @code{float} (as opposed to the default @code{double}) type; or with
8689a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8690constant.
c906108c
SS
8691
8692@item
8693Enumerated constants consist of enumerated identifiers, or their
8694integral equivalents.
8695
8696@item
8697Character constants are a single character surrounded by single quotes
8698(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8699(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8700be represented by a letter or by @dfn{escape sequences}, which are of
8701the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8702of the character's ordinal value; or of the form @samp{\@var{x}}, where
8703@samp{@var{x}} is a predefined special character---for example,
8704@samp{\n} for newline.
8705
8706@item
96a2c332
SS
8707String constants are a sequence of character constants surrounded by
8708double quotes (@code{"}). Any valid character constant (as described
8709above) may appear. Double quotes within the string must be preceded by
8710a backslash, so for instance @samp{"a\"b'c"} is a string of five
8711characters.
c906108c
SS
8712
8713@item
8714Pointer constants are an integral value. You can also write pointers
8715to constants using the C operator @samp{&}.
8716
8717@item
8718Array constants are comma-separated lists surrounded by braces @samp{@{}
8719and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8720integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8721and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8722@end itemize
8723
c906108c 8724@menu
5d161b24
DB
8725* C plus plus expressions::
8726* C Defaults::
8727* C Checks::
c906108c 8728
5d161b24 8729* Debugging C::
c906108c
SS
8730@end menu
8731
6d2ebf8b 8732@node C plus plus expressions
b37052ae
EZ
8733@subsubsection C@t{++} expressions
8734
8735@cindex expressions in C@t{++}
8736@value{GDBN} expression handling can interpret most C@t{++} expressions.
8737
0179ffac
DC
8738@cindex debugging C@t{++} programs
8739@cindex C@t{++} compilers
8740@cindex debug formats and C@t{++}
8741@cindex @value{NGCC} and C@t{++}
c906108c 8742@quotation
b37052ae 8743@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8744proper compiler and the proper debug format. Currently, @value{GDBN}
8745works best when debugging C@t{++} code that is compiled with
8746@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8747@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8748stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8749stabs+ as their default debug format, so you usually don't need to
8750specify a debug format explicitly. Other compilers and/or debug formats
8751are likely to work badly or not at all when using @value{GDBN} to debug
8752C@t{++} code.
c906108c 8753@end quotation
c906108c
SS
8754
8755@enumerate
8756
8757@cindex member functions
8758@item
8759Member function calls are allowed; you can use expressions like
8760
474c8240 8761@smallexample
c906108c 8762count = aml->GetOriginal(x, y)
474c8240 8763@end smallexample
c906108c 8764
41afff9a 8765@vindex this@r{, inside C@t{++} member functions}
b37052ae 8766@cindex namespace in C@t{++}
c906108c
SS
8767@item
8768While a member function is active (in the selected stack frame), your
8769expressions have the same namespace available as the member function;
8770that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8771pointer @code{this} following the same rules as C@t{++}.
c906108c 8772
c906108c 8773@cindex call overloaded functions
d4f3574e 8774@cindex overloaded functions, calling
b37052ae 8775@cindex type conversions in C@t{++}
c906108c
SS
8776@item
8777You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8778call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8779perform overload resolution involving user-defined type conversions,
8780calls to constructors, or instantiations of templates that do not exist
8781in the program. It also cannot handle ellipsis argument lists or
8782default arguments.
8783
8784It does perform integral conversions and promotions, floating-point
8785promotions, arithmetic conversions, pointer conversions, conversions of
8786class objects to base classes, and standard conversions such as those of
8787functions or arrays to pointers; it requires an exact match on the
8788number of function arguments.
8789
8790Overload resolution is always performed, unless you have specified
8791@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8792,@value{GDBN} features for C@t{++}}.
c906108c 8793
d4f3574e 8794You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8795explicit function signature to call an overloaded function, as in
8796@smallexample
8797p 'foo(char,int)'('x', 13)
8798@end smallexample
d4f3574e 8799
c906108c 8800The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8801see @ref{Completion, ,Command completion}.
c906108c 8802
c906108c
SS
8803@cindex reference declarations
8804@item
b37052ae
EZ
8805@value{GDBN} understands variables declared as C@t{++} references; you can use
8806them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8807dereferenced.
8808
8809In the parameter list shown when @value{GDBN} displays a frame, the values of
8810reference variables are not displayed (unlike other variables); this
8811avoids clutter, since references are often used for large structures.
8812The @emph{address} of a reference variable is always shown, unless
8813you have specified @samp{set print address off}.
8814
8815@item
b37052ae 8816@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8817expressions can use it just as expressions in your program do. Since
8818one scope may be defined in another, you can use @code{::} repeatedly if
8819necessary, for example in an expression like
8820@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8821resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8822debugging (@pxref{Variables, ,Program variables}).
8823@end enumerate
8824
b37052ae 8825In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8826calling virtual functions correctly, printing out virtual bases of
8827objects, calling functions in a base subobject, casting objects, and
8828invoking user-defined operators.
c906108c 8829
6d2ebf8b 8830@node C Defaults
b37052ae 8831@subsubsection C and C@t{++} defaults
7a292a7a 8832
b37052ae 8833@cindex C and C@t{++} defaults
c906108c 8834
c906108c
SS
8835If you allow @value{GDBN} to set type and range checking automatically, they
8836both default to @code{off} whenever the working language changes to
b37052ae 8837C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8838selects the working language.
c906108c
SS
8839
8840If you allow @value{GDBN} to set the language automatically, it
8841recognizes source files whose names end with @file{.c}, @file{.C}, or
8842@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8843these files, it sets the working language to C or C@t{++}.
c906108c
SS
8844@xref{Automatically, ,Having @value{GDBN} infer the source language},
8845for further details.
8846
c906108c
SS
8847@c Type checking is (a) primarily motivated by Modula-2, and (b)
8848@c unimplemented. If (b) changes, it might make sense to let this node
8849@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8850
6d2ebf8b 8851@node C Checks
b37052ae 8852@subsubsection C and C@t{++} type and range checks
7a292a7a 8853
b37052ae 8854@cindex C and C@t{++} checks
c906108c 8855
b37052ae 8856By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8857is not used. However, if you turn type checking on, @value{GDBN}
8858considers two variables type equivalent if:
8859
8860@itemize @bullet
8861@item
8862The two variables are structured and have the same structure, union, or
8863enumerated tag.
8864
8865@item
8866The two variables have the same type name, or types that have been
8867declared equivalent through @code{typedef}.
8868
8869@ignore
8870@c leaving this out because neither J Gilmore nor R Pesch understand it.
8871@c FIXME--beers?
8872@item
8873The two @code{struct}, @code{union}, or @code{enum} variables are
8874declared in the same declaration. (Note: this may not be true for all C
8875compilers.)
8876@end ignore
8877@end itemize
8878
8879Range checking, if turned on, is done on mathematical operations. Array
8880indices are not checked, since they are often used to index a pointer
8881that is not itself an array.
c906108c 8882
6d2ebf8b 8883@node Debugging C
c906108c 8884@subsubsection @value{GDBN} and C
c906108c
SS
8885
8886The @code{set print union} and @code{show print union} commands apply to
8887the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8888inside a @code{struct} or @code{class} is also printed. Otherwise, it
8889appears as @samp{@{...@}}.
c906108c
SS
8890
8891The @code{@@} operator aids in the debugging of dynamic arrays, formed
8892with pointers and a memory allocation function. @xref{Expressions,
8893,Expressions}.
8894
c906108c 8895@menu
5d161b24 8896* Debugging C plus plus::
c906108c
SS
8897@end menu
8898
6d2ebf8b 8899@node Debugging C plus plus
b37052ae 8900@subsubsection @value{GDBN} features for C@t{++}
c906108c 8901
b37052ae 8902@cindex commands for C@t{++}
7a292a7a 8903
b37052ae
EZ
8904Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8905designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8906
8907@table @code
8908@cindex break in overloaded functions
8909@item @r{breakpoint menus}
8910When you want a breakpoint in a function whose name is overloaded,
8911@value{GDBN} breakpoint menus help you specify which function definition
8912you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8913
b37052ae 8914@cindex overloading in C@t{++}
c906108c
SS
8915@item rbreak @var{regex}
8916Setting breakpoints using regular expressions is helpful for setting
8917breakpoints on overloaded functions that are not members of any special
8918classes.
8919@xref{Set Breaks, ,Setting breakpoints}.
8920
b37052ae 8921@cindex C@t{++} exception handling
c906108c
SS
8922@item catch throw
8923@itemx catch catch
b37052ae 8924Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8925Catchpoints, , Setting catchpoints}.
8926
8927@cindex inheritance
8928@item ptype @var{typename}
8929Print inheritance relationships as well as other information for type
8930@var{typename}.
8931@xref{Symbols, ,Examining the Symbol Table}.
8932
b37052ae 8933@cindex C@t{++} symbol display
c906108c
SS
8934@item set print demangle
8935@itemx show print demangle
8936@itemx set print asm-demangle
8937@itemx show print asm-demangle
b37052ae
EZ
8938Control whether C@t{++} symbols display in their source form, both when
8939displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8940@xref{Print Settings, ,Print settings}.
8941
8942@item set print object
8943@itemx show print object
8944Choose whether to print derived (actual) or declared types of objects.
8945@xref{Print Settings, ,Print settings}.
8946
8947@item set print vtbl
8948@itemx show print vtbl
8949Control the format for printing virtual function tables.
8950@xref{Print Settings, ,Print settings}.
c906108c 8951(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8952ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8953
8954@kindex set overload-resolution
d4f3574e 8955@cindex overloaded functions, overload resolution
c906108c 8956@item set overload-resolution on
b37052ae 8957Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8958is on. For overloaded functions, @value{GDBN} evaluates the arguments
8959and searches for a function whose signature matches the argument types,
b37052ae 8960using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8961expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8962message.
8963
8964@item set overload-resolution off
b37052ae 8965Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8966overloaded functions that are not class member functions, @value{GDBN}
8967chooses the first function of the specified name that it finds in the
8968symbol table, whether or not its arguments are of the correct type. For
8969overloaded functions that are class member functions, @value{GDBN}
8970searches for a function whose signature @emph{exactly} matches the
8971argument types.
c906108c 8972
9c16f35a
EZ
8973@kindex show overload-resolution
8974@item show overload-resolution
8975Show the current setting of overload resolution.
8976
c906108c
SS
8977@item @r{Overloaded symbol names}
8978You can specify a particular definition of an overloaded symbol, using
b37052ae 8979the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
8980@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8981also use the @value{GDBN} command-line word completion facilities to list the
8982available choices, or to finish the type list for you.
8983@xref{Completion,, Command completion}, for details on how to do this.
8984@end table
c906108c 8985
b37303ee
AF
8986@node Objective-C
8987@subsection Objective-C
8988
8989@cindex Objective-C
8990This section provides information about some commands and command
721c2651
EZ
8991options that are useful for debugging Objective-C code. See also
8992@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
8993few more commands specific to Objective-C support.
b37303ee
AF
8994
8995@menu
b383017d
RM
8996* Method Names in Commands::
8997* The Print Command with Objective-C::
b37303ee
AF
8998@end menu
8999
9000@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
9001@subsubsection Method Names in Commands
9002
9003The following commands have been extended to accept Objective-C method
9004names as line specifications:
9005
9006@kindex clear@r{, and Objective-C}
9007@kindex break@r{, and Objective-C}
9008@kindex info line@r{, and Objective-C}
9009@kindex jump@r{, and Objective-C}
9010@kindex list@r{, and Objective-C}
9011@itemize
9012@item @code{clear}
9013@item @code{break}
9014@item @code{info line}
9015@item @code{jump}
9016@item @code{list}
9017@end itemize
9018
9019A fully qualified Objective-C method name is specified as
9020
9021@smallexample
9022-[@var{Class} @var{methodName}]
9023@end smallexample
9024
c552b3bb
JM
9025where the minus sign is used to indicate an instance method and a
9026plus sign (not shown) is used to indicate a class method. The class
9027name @var{Class} and method name @var{methodName} are enclosed in
9028brackets, similar to the way messages are specified in Objective-C
9029source code. For example, to set a breakpoint at the @code{create}
9030instance method of class @code{Fruit} in the program currently being
9031debugged, enter:
b37303ee
AF
9032
9033@smallexample
9034break -[Fruit create]
9035@end smallexample
9036
9037To list ten program lines around the @code{initialize} class method,
9038enter:
9039
9040@smallexample
9041list +[NSText initialize]
9042@end smallexample
9043
c552b3bb
JM
9044In the current version of @value{GDBN}, the plus or minus sign is
9045required. In future versions of @value{GDBN}, the plus or minus
9046sign will be optional, but you can use it to narrow the search. It
9047is also possible to specify just a method name:
b37303ee
AF
9048
9049@smallexample
9050break create
9051@end smallexample
9052
9053You must specify the complete method name, including any colons. If
9054your program's source files contain more than one @code{create} method,
9055you'll be presented with a numbered list of classes that implement that
9056method. Indicate your choice by number, or type @samp{0} to exit if
9057none apply.
9058
9059As another example, to clear a breakpoint established at the
9060@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
9061
9062@smallexample
9063clear -[NSWindow makeKeyAndOrderFront:]
9064@end smallexample
9065
9066@node The Print Command with Objective-C
9067@subsubsection The Print Command With Objective-C
721c2651 9068@cindex Objective-C, print objects
c552b3bb
JM
9069@kindex print-object
9070@kindex po @r{(@code{print-object})}
b37303ee 9071
c552b3bb 9072The print command has also been extended to accept methods. For example:
b37303ee
AF
9073
9074@smallexample
c552b3bb 9075print -[@var{object} hash]
b37303ee
AF
9076@end smallexample
9077
9078@cindex print an Objective-C object description
c552b3bb
JM
9079@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
9080@noindent
9081will tell @value{GDBN} to send the @code{hash} message to @var{object}
9082and print the result. Also, an additional command has been added,
9083@code{print-object} or @code{po} for short, which is meant to print
9084the description of an object. However, this command may only work
9085with certain Objective-C libraries that have a particular hook
9086function, @code{_NSPrintForDebugger}, defined.
b37303ee 9087
09d4efe1
EZ
9088@node Fortran
9089@subsection Fortran
9090@cindex Fortran-specific support in @value{GDBN}
9091
9092@table @code
9093@cindex @code{COMMON} blocks, Fortran
9094@kindex info common
9095@item info common @r{[}@var{common-name}@r{]}
9096This command prints the values contained in the Fortran @code{COMMON}
9097block whose name is @var{common-name}. With no argument, the names of
9098all @code{COMMON} blocks visible at current program location are
9099printed.
9100@end table
9101
a8f24a35
EZ
9102Fortran symbols are usually case-insensitive, so @value{GDBN} by
9103default uses case-insensitive matches for Fortran symbols. You can
9104change that with the @samp{set case-insensitive} command, see
9105@ref{Symbols}, for the details.
9106
9c16f35a
EZ
9107@node Pascal
9108@subsection Pascal
9109
9110@cindex Pascal support in @value{GDBN}, limitations
9111Debugging Pascal programs which use sets, subranges, file variables, or
9112nested functions does not currently work. @value{GDBN} does not support
9113entering expressions, printing values, or similar features using Pascal
9114syntax.
9115
9116The Pascal-specific command @code{set print pascal_static-members}
9117controls whether static members of Pascal objects are displayed.
9118@xref{Print Settings, pascal_static-members}.
9119
09d4efe1 9120@node Modula-2
c906108c 9121@subsection Modula-2
7a292a7a 9122
d4f3574e 9123@cindex Modula-2, @value{GDBN} support
c906108c
SS
9124
9125The extensions made to @value{GDBN} to support Modula-2 only support
9126output from the @sc{gnu} Modula-2 compiler (which is currently being
9127developed). Other Modula-2 compilers are not currently supported, and
9128attempting to debug executables produced by them is most likely
9129to give an error as @value{GDBN} reads in the executable's symbol
9130table.
9131
9132@cindex expressions in Modula-2
9133@menu
9134* M2 Operators:: Built-in operators
9135* Built-In Func/Proc:: Built-in functions and procedures
9136* M2 Constants:: Modula-2 constants
9137* M2 Defaults:: Default settings for Modula-2
9138* Deviations:: Deviations from standard Modula-2
9139* M2 Checks:: Modula-2 type and range checks
9140* M2 Scope:: The scope operators @code{::} and @code{.}
9141* GDB/M2:: @value{GDBN} and Modula-2
9142@end menu
9143
6d2ebf8b 9144@node M2 Operators
c906108c
SS
9145@subsubsection Operators
9146@cindex Modula-2 operators
9147
9148Operators must be defined on values of specific types. For instance,
9149@code{+} is defined on numbers, but not on structures. Operators are
9150often defined on groups of types. For the purposes of Modula-2, the
9151following definitions hold:
9152
9153@itemize @bullet
9154
9155@item
9156@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
9157their subranges.
9158
9159@item
9160@emph{Character types} consist of @code{CHAR} and its subranges.
9161
9162@item
9163@emph{Floating-point types} consist of @code{REAL}.
9164
9165@item
9166@emph{Pointer types} consist of anything declared as @code{POINTER TO
9167@var{type}}.
9168
9169@item
9170@emph{Scalar types} consist of all of the above.
9171
9172@item
9173@emph{Set types} consist of @code{SET} and @code{BITSET} types.
9174
9175@item
9176@emph{Boolean types} consist of @code{BOOLEAN}.
9177@end itemize
9178
9179@noindent
9180The following operators are supported, and appear in order of
9181increasing precedence:
9182
9183@table @code
9184@item ,
9185Function argument or array index separator.
9186
9187@item :=
9188Assignment. The value of @var{var} @code{:=} @var{value} is
9189@var{value}.
9190
9191@item <@r{, }>
9192Less than, greater than on integral, floating-point, or enumerated
9193types.
9194
9195@item <=@r{, }>=
96a2c332 9196Less than or equal to, greater than or equal to
c906108c
SS
9197on integral, floating-point and enumerated types, or set inclusion on
9198set types. Same precedence as @code{<}.
9199
9200@item =@r{, }<>@r{, }#
9201Equality and two ways of expressing inequality, valid on scalar types.
9202Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9203available for inequality, since @code{#} conflicts with the script
9204comment character.
9205
9206@item IN
9207Set membership. Defined on set types and the types of their members.
9208Same precedence as @code{<}.
9209
9210@item OR
9211Boolean disjunction. Defined on boolean types.
9212
9213@item AND@r{, }&
d4f3574e 9214Boolean conjunction. Defined on boolean types.
c906108c
SS
9215
9216@item @@
9217The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9218
9219@item +@r{, }-
9220Addition and subtraction on integral and floating-point types, or union
9221and difference on set types.
9222
9223@item *
9224Multiplication on integral and floating-point types, or set intersection
9225on set types.
9226
9227@item /
9228Division on floating-point types, or symmetric set difference on set
9229types. Same precedence as @code{*}.
9230
9231@item DIV@r{, }MOD
9232Integer division and remainder. Defined on integral types. Same
9233precedence as @code{*}.
9234
9235@item -
9236Negative. Defined on @code{INTEGER} and @code{REAL} data.
9237
9238@item ^
9239Pointer dereferencing. Defined on pointer types.
9240
9241@item NOT
9242Boolean negation. Defined on boolean types. Same precedence as
9243@code{^}.
9244
9245@item .
9246@code{RECORD} field selector. Defined on @code{RECORD} data. Same
9247precedence as @code{^}.
9248
9249@item []
9250Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
9251
9252@item ()
9253Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
9254as @code{^}.
9255
9256@item ::@r{, }.
9257@value{GDBN} and Modula-2 scope operators.
9258@end table
9259
9260@quotation
9261@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
9262treats the use of the operator @code{IN}, or the use of operators
9263@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
9264@code{<=}, and @code{>=} on sets as an error.
9265@end quotation
9266
cb51c4e0 9267
6d2ebf8b 9268@node Built-In Func/Proc
c906108c 9269@subsubsection Built-in functions and procedures
cb51c4e0 9270@cindex Modula-2 built-ins
c906108c
SS
9271
9272Modula-2 also makes available several built-in procedures and functions.
9273In describing these, the following metavariables are used:
9274
9275@table @var
9276
9277@item a
9278represents an @code{ARRAY} variable.
9279
9280@item c
9281represents a @code{CHAR} constant or variable.
9282
9283@item i
9284represents a variable or constant of integral type.
9285
9286@item m
9287represents an identifier that belongs to a set. Generally used in the
9288same function with the metavariable @var{s}. The type of @var{s} should
9289be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
9290
9291@item n
9292represents a variable or constant of integral or floating-point type.
9293
9294@item r
9295represents a variable or constant of floating-point type.
9296
9297@item t
9298represents a type.
9299
9300@item v
9301represents a variable.
9302
9303@item x
9304represents a variable or constant of one of many types. See the
9305explanation of the function for details.
9306@end table
9307
9308All Modula-2 built-in procedures also return a result, described below.
9309
9310@table @code
9311@item ABS(@var{n})
9312Returns the absolute value of @var{n}.
9313
9314@item CAP(@var{c})
9315If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 9316equivalent, otherwise it returns its argument.
c906108c
SS
9317
9318@item CHR(@var{i})
9319Returns the character whose ordinal value is @var{i}.
9320
9321@item DEC(@var{v})
c3f6f71d 9322Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9323
9324@item DEC(@var{v},@var{i})
9325Decrements the value in the variable @var{v} by @var{i}. Returns the
9326new value.
9327
9328@item EXCL(@var{m},@var{s})
9329Removes the element @var{m} from the set @var{s}. Returns the new
9330set.
9331
9332@item FLOAT(@var{i})
9333Returns the floating point equivalent of the integer @var{i}.
9334
9335@item HIGH(@var{a})
9336Returns the index of the last member of @var{a}.
9337
9338@item INC(@var{v})
c3f6f71d 9339Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9340
9341@item INC(@var{v},@var{i})
9342Increments the value in the variable @var{v} by @var{i}. Returns the
9343new value.
9344
9345@item INCL(@var{m},@var{s})
9346Adds the element @var{m} to the set @var{s} if it is not already
9347there. Returns the new set.
9348
9349@item MAX(@var{t})
9350Returns the maximum value of the type @var{t}.
9351
9352@item MIN(@var{t})
9353Returns the minimum value of the type @var{t}.
9354
9355@item ODD(@var{i})
9356Returns boolean TRUE if @var{i} is an odd number.
9357
9358@item ORD(@var{x})
9359Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
9360value of a character is its @sc{ascii} value (on machines supporting the
9361@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
9362integral, character and enumerated types.
9363
9364@item SIZE(@var{x})
9365Returns the size of its argument. @var{x} can be a variable or a type.
9366
9367@item TRUNC(@var{r})
9368Returns the integral part of @var{r}.
9369
9370@item VAL(@var{t},@var{i})
9371Returns the member of the type @var{t} whose ordinal value is @var{i}.
9372@end table
9373
9374@quotation
9375@emph{Warning:} Sets and their operations are not yet supported, so
9376@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
9377an error.
9378@end quotation
9379
9380@cindex Modula-2 constants
6d2ebf8b 9381@node M2 Constants
c906108c
SS
9382@subsubsection Constants
9383
9384@value{GDBN} allows you to express the constants of Modula-2 in the following
9385ways:
9386
9387@itemize @bullet
9388
9389@item
9390Integer constants are simply a sequence of digits. When used in an
9391expression, a constant is interpreted to be type-compatible with the
9392rest of the expression. Hexadecimal integers are specified by a
9393trailing @samp{H}, and octal integers by a trailing @samp{B}.
9394
9395@item
9396Floating point constants appear as a sequence of digits, followed by a
9397decimal point and another sequence of digits. An optional exponent can
9398then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
9399@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
9400digits of the floating point constant must be valid decimal (base 10)
9401digits.
9402
9403@item
9404Character constants consist of a single character enclosed by a pair of
9405like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 9406also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
9407followed by a @samp{C}.
9408
9409@item
9410String constants consist of a sequence of characters enclosed by a
9411pair of like quotes, either single (@code{'}) or double (@code{"}).
9412Escape sequences in the style of C are also allowed. @xref{C
b37052ae 9413Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
9414sequences.
9415
9416@item
9417Enumerated constants consist of an enumerated identifier.
9418
9419@item
9420Boolean constants consist of the identifiers @code{TRUE} and
9421@code{FALSE}.
9422
9423@item
9424Pointer constants consist of integral values only.
9425
9426@item
9427Set constants are not yet supported.
9428@end itemize
9429
6d2ebf8b 9430@node M2 Defaults
c906108c
SS
9431@subsubsection Modula-2 defaults
9432@cindex Modula-2 defaults
9433
9434If type and range checking are set automatically by @value{GDBN}, they
9435both default to @code{on} whenever the working language changes to
d4f3574e 9436Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
9437selected the working language.
9438
9439If you allow @value{GDBN} to set the language automatically, then entering
9440code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 9441working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
9442the language automatically}, for further details.
9443
6d2ebf8b 9444@node Deviations
c906108c
SS
9445@subsubsection Deviations from standard Modula-2
9446@cindex Modula-2, deviations from
9447
9448A few changes have been made to make Modula-2 programs easier to debug.
9449This is done primarily via loosening its type strictness:
9450
9451@itemize @bullet
9452@item
9453Unlike in standard Modula-2, pointer constants can be formed by
9454integers. This allows you to modify pointer variables during
9455debugging. (In standard Modula-2, the actual address contained in a
9456pointer variable is hidden from you; it can only be modified
9457through direct assignment to another pointer variable or expression that
9458returned a pointer.)
9459
9460@item
9461C escape sequences can be used in strings and characters to represent
9462non-printable characters. @value{GDBN} prints out strings with these
9463escape sequences embedded. Single non-printable characters are
9464printed using the @samp{CHR(@var{nnn})} format.
9465
9466@item
9467The assignment operator (@code{:=}) returns the value of its right-hand
9468argument.
9469
9470@item
9471All built-in procedures both modify @emph{and} return their argument.
9472@end itemize
9473
6d2ebf8b 9474@node M2 Checks
c906108c
SS
9475@subsubsection Modula-2 type and range checks
9476@cindex Modula-2 checks
9477
9478@quotation
9479@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9480range checking.
9481@end quotation
9482@c FIXME remove warning when type/range checks added
9483
9484@value{GDBN} considers two Modula-2 variables type equivalent if:
9485
9486@itemize @bullet
9487@item
9488They are of types that have been declared equivalent via a @code{TYPE
9489@var{t1} = @var{t2}} statement
9490
9491@item
9492They have been declared on the same line. (Note: This is true of the
9493@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9494@end itemize
9495
9496As long as type checking is enabled, any attempt to combine variables
9497whose types are not equivalent is an error.
9498
9499Range checking is done on all mathematical operations, assignment, array
9500index bounds, and all built-in functions and procedures.
9501
6d2ebf8b 9502@node M2 Scope
c906108c
SS
9503@subsubsection The scope operators @code{::} and @code{.}
9504@cindex scope
41afff9a 9505@cindex @code{.}, Modula-2 scope operator
c906108c
SS
9506@cindex colon, doubled as scope operator
9507@ifinfo
41afff9a 9508@vindex colon-colon@r{, in Modula-2}
c906108c
SS
9509@c Info cannot handle :: but TeX can.
9510@end ifinfo
9511@iftex
41afff9a 9512@vindex ::@r{, in Modula-2}
c906108c
SS
9513@end iftex
9514
9515There are a few subtle differences between the Modula-2 scope operator
9516(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9517similar syntax:
9518
474c8240 9519@smallexample
c906108c
SS
9520
9521@var{module} . @var{id}
9522@var{scope} :: @var{id}
474c8240 9523@end smallexample
c906108c
SS
9524
9525@noindent
9526where @var{scope} is the name of a module or a procedure,
9527@var{module} the name of a module, and @var{id} is any declared
9528identifier within your program, except another module.
9529
9530Using the @code{::} operator makes @value{GDBN} search the scope
9531specified by @var{scope} for the identifier @var{id}. If it is not
9532found in the specified scope, then @value{GDBN} searches all scopes
9533enclosing the one specified by @var{scope}.
9534
9535Using the @code{.} operator makes @value{GDBN} search the current scope for
9536the identifier specified by @var{id} that was imported from the
9537definition module specified by @var{module}. With this operator, it is
9538an error if the identifier @var{id} was not imported from definition
9539module @var{module}, or if @var{id} is not an identifier in
9540@var{module}.
9541
6d2ebf8b 9542@node GDB/M2
c906108c
SS
9543@subsubsection @value{GDBN} and Modula-2
9544
9545Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9546Five subcommands of @code{set print} and @code{show print} apply
b37052ae 9547specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 9548@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 9549apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
9550analogue in Modula-2.
9551
9552The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 9553with any language, is not useful with Modula-2. Its
c906108c 9554intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 9555created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 9556address can be specified by an integral constant, the construct
d4f3574e 9557@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
9558
9559@cindex @code{#} in Modula-2
9560In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9561interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 9562
e07c999f
PH
9563@node Ada
9564@subsection Ada
9565@cindex Ada
9566
9567The extensions made to @value{GDBN} for Ada only support
9568output from the @sc{gnu} Ada (GNAT) compiler.
9569Other Ada compilers are not currently supported, and
9570attempting to debug executables produced by them is most likely
9571to be difficult.
9572
9573
9574@cindex expressions in Ada
9575@menu
9576* Ada Mode Intro:: General remarks on the Ada syntax
9577 and semantics supported by Ada mode
9578 in @value{GDBN}.
9579* Omissions from Ada:: Restrictions on the Ada expression syntax.
9580* Additions to Ada:: Extensions of the Ada expression syntax.
9581* Stopping Before Main Program:: Debugging the program during elaboration.
9582* Ada Glitches:: Known peculiarities of Ada mode.
9583@end menu
9584
9585@node Ada Mode Intro
9586@subsubsection Introduction
9587@cindex Ada mode, general
9588
9589The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9590syntax, with some extensions.
9591The philosophy behind the design of this subset is
9592
9593@itemize @bullet
9594@item
9595That @value{GDBN} should provide basic literals and access to operations for
9596arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9597leaving more sophisticated computations to subprograms written into the
9598program (which therefore may be called from @value{GDBN}).
9599
9600@item
9601That type safety and strict adherence to Ada language restrictions
9602are not particularly important to the @value{GDBN} user.
9603
9604@item
9605That brevity is important to the @value{GDBN} user.
9606@end itemize
9607
9608Thus, for brevity, the debugger acts as if there were
9609implicit @code{with} and @code{use} clauses in effect for all user-written
9610packages, making it unnecessary to fully qualify most names with
9611their packages, regardless of context. Where this causes ambiguity,
9612@value{GDBN} asks the user's intent.
9613
9614The debugger will start in Ada mode if it detects an Ada main program.
9615As for other languages, it will enter Ada mode when stopped in a program that
9616was translated from an Ada source file.
9617
9618While in Ada mode, you may use `@t{--}' for comments. This is useful
9619mostly for documenting command files. The standard @value{GDBN} comment
9620(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9621middle (to allow based literals).
9622
9623The debugger supports limited overloading. Given a subprogram call in which
9624the function symbol has multiple definitions, it will use the number of
9625actual parameters and some information about their types to attempt to narrow
9626the set of definitions. It also makes very limited use of context, preferring
9627procedures to functions in the context of the @code{call} command, and
9628functions to procedures elsewhere.
9629
9630@node Omissions from Ada
9631@subsubsection Omissions from Ada
9632@cindex Ada, omissions from
9633
9634Here are the notable omissions from the subset:
9635
9636@itemize @bullet
9637@item
9638Only a subset of the attributes are supported:
9639
9640@itemize @minus
9641@item
9642@t{'First}, @t{'Last}, and @t{'Length}
9643 on array objects (not on types and subtypes).
9644
9645@item
9646@t{'Min} and @t{'Max}.
9647
9648@item
9649@t{'Pos} and @t{'Val}.
9650
9651@item
9652@t{'Tag}.
9653
9654@item
9655@t{'Range} on array objects (not subtypes), but only as the right
9656operand of the membership (@code{in}) operator.
9657
9658@item
9659@t{'Access}, @t{'Unchecked_Access}, and
9660@t{'Unrestricted_Access} (a GNAT extension).
9661
9662@item
9663@t{'Address}.
9664@end itemize
9665
9666@item
9667The names in
9668@code{Characters.Latin_1} are not available and
9669concatenation is not implemented. Thus, escape characters in strings are
9670not currently available.
9671
9672@item
9673Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9674equality of representations. They will generally work correctly
9675for strings and arrays whose elements have integer or enumeration types.
9676They may not work correctly for arrays whose element
9677types have user-defined equality, for arrays of real values
9678(in particular, IEEE-conformant floating point, because of negative
9679zeroes and NaNs), and for arrays whose elements contain unused bits with
9680indeterminate values.
9681
9682@item
9683The other component-by-component array operations (@code{and}, @code{or},
9684@code{xor}, @code{not}, and relational tests other than equality)
9685are not implemented.
9686
9687@item
9688There are no record or array aggregates.
9689
9690@item
9691Calls to dispatching subprograms are not implemented.
9692
9693@item
9694The overloading algorithm is much more limited (i.e., less selective)
9695than that of real Ada. It makes only limited use of the context in which a subexpression
9696appears to resolve its meaning, and it is much looser in its rules for allowing
9697type matches. As a result, some function calls will be ambiguous, and the user
9698will be asked to choose the proper resolution.
9699
9700@item
9701The @code{new} operator is not implemented.
9702
9703@item
9704Entry calls are not implemented.
9705
9706@item
9707Aside from printing, arithmetic operations on the native VAX floating-point
9708formats are not supported.
9709
9710@item
9711It is not possible to slice a packed array.
9712@end itemize
9713
9714@node Additions to Ada
9715@subsubsection Additions to Ada
9716@cindex Ada, deviations from
9717
9718As it does for other languages, @value{GDBN} makes certain generic
9719extensions to Ada (@pxref{Expressions}):
9720
9721@itemize @bullet
9722@item
9723If the expression @var{E} is a variable residing in memory
9724(typically a local variable or array element) and @var{N} is
9725a positive integer, then @code{@var{E}@@@var{N}} displays the values of
9726@var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
9727In Ada, this operator is generally not necessary, since its prime use
9728is in displaying parts of an array, and slicing will usually do this in Ada.
9729However, there are occasional uses when debugging programs
9730in which certain debugging information has been optimized away.
9731
9732@item
9733@code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
9734in function or file @var{B}.'' When @var{B} is a file name, you must typically
9735surround it in single quotes.
9736
9737@item
9738The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
9739@var{type} that appears at address @var{addr}.''
9740
9741@item
9742A name starting with @samp{$} is a convenience variable
9743(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
9744@end itemize
9745
9746In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
9747to Ada:
9748
9749@itemize @bullet
9750@item
9751The assignment statement is allowed as an expression, returning
9752its right-hand operand as its value. Thus, you may enter
9753
9754@smallexample
9755set x := y + 3
9756print A(tmp := y + 1)
9757@end smallexample
9758
9759@item
9760The semicolon is allowed as an ``operator,'' returning as its value
9761the value of its right-hand operand.
9762This allows, for example,
9763complex conditional breaks:
9764
9765@smallexample
9766break f
9767condition 1 (report(i); k += 1; A(k) > 100)
9768@end smallexample
9769
9770@item
9771Rather than use catenation and symbolic character names to introduce special
9772characters into strings, one may instead use a special bracket notation,
9773which is also used to print strings. A sequence of characters of the form
9774@samp{["@var{XX}"]} within a string or character literal denotes the
9775(single) character whose numeric encoding is @var{XX} in hexadecimal. The
9776sequence of characters @samp{["""]} also denotes a single quotation mark
9777in strings. For example,
9778@smallexample
9779 "One line.["0a"]Next line.["0a"]"
9780@end smallexample
9781@noindent
9782contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
9783period.
9784
9785@item
9786The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
9787@t{'Max} is optional (and is ignored in any case). For example, it is valid
9788to write
9789
9790@smallexample
9791print 'max(x, y)
9792@end smallexample
9793
9794@item
9795When printing arrays, @value{GDBN} uses positional notation when the
9796array has a lower bound of 1, and uses a modified named notation otherwise.
9797For example, a one-dimensional array of three integers with a lower bound of 3 might print as
9798
9799@smallexample
9800(3 => 10, 17, 1)
9801@end smallexample
9802
9803@noindent
9804That is, in contrast to valid Ada, only the first component has a @code{=>}
9805clause.
9806
9807@item
9808You may abbreviate attributes in expressions with any unique,
9809multi-character subsequence of
9810their names (an exact match gets preference).
9811For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
9812in place of @t{a'length}.
9813
9814@item
9815@cindex quoting Ada internal identifiers
9816Since Ada is case-insensitive, the debugger normally maps identifiers you type
9817to lower case. The GNAT compiler uses upper-case characters for
9818some of its internal identifiers, which are normally of no interest to users.
9819For the rare occasions when you actually have to look at them,
9820enclose them in angle brackets to avoid the lower-case mapping.
9821For example,
9822@smallexample
9823@value{GDBP} print <JMPBUF_SAVE>[0]
9824@end smallexample
9825
9826@item
9827Printing an object of class-wide type or dereferencing an
9828access-to-class-wide value will display all the components of the object's
9829specific type (as indicated by its run-time tag). Likewise, component
9830selection on such a value will operate on the specific type of the
9831object.
9832
9833@end itemize
9834
9835@node Stopping Before Main Program
9836@subsubsection Stopping at the Very Beginning
9837
9838@cindex breakpointing Ada elaboration code
9839It is sometimes necessary to debug the program during elaboration, and
9840before reaching the main procedure.
9841As defined in the Ada Reference
9842Manual, the elaboration code is invoked from a procedure called
9843@code{adainit}. To run your program up to the beginning of
9844elaboration, simply use the following two commands:
9845@code{tbreak adainit} and @code{run}.
9846
9847@node Ada Glitches
9848@subsubsection Known Peculiarities of Ada Mode
9849@cindex Ada, problems
9850
9851Besides the omissions listed previously (@pxref{Omissions from Ada}),
9852we know of several problems with and limitations of Ada mode in
9853@value{GDBN},
9854some of which will be fixed with planned future releases of the debugger
9855and the GNU Ada compiler.
9856
9857@itemize @bullet
9858@item
9859Currently, the debugger
9860has insufficient information to determine whether certain pointers represent
9861pointers to objects or the objects themselves.
9862Thus, the user may have to tack an extra @code{.all} after an expression
9863to get it printed properly.
9864
9865@item
9866Static constants that the compiler chooses not to materialize as objects in
9867storage are invisible to the debugger.
9868
9869@item
9870Named parameter associations in function argument lists are ignored (the
9871argument lists are treated as positional).
9872
9873@item
9874Many useful library packages are currently invisible to the debugger.
9875
9876@item
9877Fixed-point arithmetic, conversions, input, and output is carried out using
9878floating-point arithmetic, and may give results that only approximate those on
9879the host machine.
9880
9881@item
9882The type of the @t{'Address} attribute may not be @code{System.Address}.
9883
9884@item
9885The GNAT compiler never generates the prefix @code{Standard} for any of
9886the standard symbols defined by the Ada language. @value{GDBN} knows about
9887this: it will strip the prefix from names when you use it, and will never
9888look for a name you have so qualified among local symbols, nor match against
9889symbols in other packages or subprograms. If you have
9890defined entities anywhere in your program other than parameters and
9891local variables whose simple names match names in @code{Standard},
9892GNAT's lack of qualification here can cause confusion. When this happens,
9893you can usually resolve the confusion
9894by qualifying the problematic names with package
9895@code{Standard} explicitly.
9896@end itemize
9897
4e562065
JB
9898@node Unsupported languages
9899@section Unsupported languages
9900
9901@cindex unsupported languages
9902@cindex minimal language
9903In addition to the other fully-supported programming languages,
9904@value{GDBN} also provides a pseudo-language, called @code{minimal}.
9905It does not represent a real programming language, but provides a set
9906of capabilities close to what the C or assembly languages provide.
9907This should allow most simple operations to be performed while debugging
9908an application that uses a language currently not supported by @value{GDBN}.
9909
9910If the language is set to @code{auto}, @value{GDBN} will automatically
9911select this language if the current frame corresponds to an unsupported
9912language.
9913
6d2ebf8b 9914@node Symbols
c906108c
SS
9915@chapter Examining the Symbol Table
9916
d4f3574e 9917The commands described in this chapter allow you to inquire about the
c906108c
SS
9918symbols (names of variables, functions and types) defined in your
9919program. This information is inherent in the text of your program and
9920does not change as your program executes. @value{GDBN} finds it in your
9921program's symbol table, in the file indicated when you started @value{GDBN}
9922(@pxref{File Options, ,Choosing files}), or by one of the
9923file-management commands (@pxref{Files, ,Commands to specify files}).
9924
9925@cindex symbol names
9926@cindex names of symbols
9927@cindex quoting names
9928Occasionally, you may need to refer to symbols that contain unusual
9929characters, which @value{GDBN} ordinarily treats as word delimiters. The
9930most frequent case is in referring to static variables in other
9931source files (@pxref{Variables,,Program variables}). File names
9932are recorded in object files as debugging symbols, but @value{GDBN} would
9933ordinarily parse a typical file name, like @file{foo.c}, as the three words
9934@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
9935@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
9936
474c8240 9937@smallexample
c906108c 9938p 'foo.c'::x
474c8240 9939@end smallexample
c906108c
SS
9940
9941@noindent
9942looks up the value of @code{x} in the scope of the file @file{foo.c}.
9943
9944@table @code
a8f24a35
EZ
9945@cindex case-insensitive symbol names
9946@cindex case sensitivity in symbol names
9947@kindex set case-sensitive
9948@item set case-sensitive on
9949@itemx set case-sensitive off
9950@itemx set case-sensitive auto
9951Normally, when @value{GDBN} looks up symbols, it matches their names
9952with case sensitivity determined by the current source language.
9953Occasionally, you may wish to control that. The command @code{set
9954case-sensitive} lets you do that by specifying @code{on} for
9955case-sensitive matches or @code{off} for case-insensitive ones. If
9956you specify @code{auto}, case sensitivity is reset to the default
9957suitable for the source language. The default is case-sensitive
9958matches for all languages except for Fortran, for which the default is
9959case-insensitive matches.
9960
9c16f35a
EZ
9961@kindex show case-sensitive
9962@item show case-sensitive
a8f24a35
EZ
9963This command shows the current setting of case sensitivity for symbols
9964lookups.
9965
c906108c 9966@kindex info address
b37052ae 9967@cindex address of a symbol
c906108c
SS
9968@item info address @var{symbol}
9969Describe where the data for @var{symbol} is stored. For a register
9970variable, this says which register it is kept in. For a non-register
9971local variable, this prints the stack-frame offset at which the variable
9972is always stored.
9973
9974Note the contrast with @samp{print &@var{symbol}}, which does not work
9975at all for a register variable, and for a stack local variable prints
9976the exact address of the current instantiation of the variable.
9977
3d67e040 9978@kindex info symbol
b37052ae 9979@cindex symbol from address
9c16f35a 9980@cindex closest symbol and offset for an address
3d67e040
EZ
9981@item info symbol @var{addr}
9982Print the name of a symbol which is stored at the address @var{addr}.
9983If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
9984nearest symbol and an offset from it:
9985
474c8240 9986@smallexample
3d67e040
EZ
9987(@value{GDBP}) info symbol 0x54320
9988_initialize_vx + 396 in section .text
474c8240 9989@end smallexample
3d67e040
EZ
9990
9991@noindent
9992This is the opposite of the @code{info address} command. You can use
9993it to find out the name of a variable or a function given its address.
9994
c906108c 9995@kindex whatis
d4f3574e
SS
9996@item whatis @var{expr}
9997Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
9998actually evaluated, and any side-effecting operations (such as
9999assignments or function calls) inside it do not take place.
10000@xref{Expressions, ,Expressions}.
10001
10002@item whatis
10003Print the data type of @code{$}, the last value in the value history.
10004
10005@kindex ptype
10006@item ptype @var{typename}
10007Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
10008the name of a type, or for C code it may have the form @samp{class
10009@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
10010@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 10011
d4f3574e 10012@item ptype @var{expr}
c906108c 10013@itemx ptype
d4f3574e 10014Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
10015differs from @code{whatis} by printing a detailed description, instead
10016of just the name of the type.
10017
10018For example, for this variable declaration:
10019
474c8240 10020@smallexample
c906108c 10021struct complex @{double real; double imag;@} v;
474c8240 10022@end smallexample
c906108c
SS
10023
10024@noindent
10025the two commands give this output:
10026
474c8240 10027@smallexample
c906108c
SS
10028@group
10029(@value{GDBP}) whatis v
10030type = struct complex
10031(@value{GDBP}) ptype v
10032type = struct complex @{
10033 double real;
10034 double imag;
10035@}
10036@end group
474c8240 10037@end smallexample
c906108c
SS
10038
10039@noindent
10040As with @code{whatis}, using @code{ptype} without an argument refers to
10041the type of @code{$}, the last value in the value history.
10042
ab1adacd
EZ
10043@cindex incomplete type
10044Sometimes, programs use opaque data types or incomplete specifications
10045of complex data structure. If the debug information included in the
10046program does not allow @value{GDBN} to display a full declaration of
10047the data type, it will say @samp{<incomplete type>}. For example,
10048given these declarations:
10049
10050@smallexample
10051 struct foo;
10052 struct foo *fooptr;
10053@end smallexample
10054
10055@noindent
10056but no definition for @code{struct foo} itself, @value{GDBN} will say:
10057
10058@smallexample
10059 (gdb) ptype foo
10060 $1 = <incomplete type>
10061@end smallexample
10062
10063@noindent
10064``Incomplete type'' is C terminology for data types that are not
10065completely specified.
10066
c906108c
SS
10067@kindex info types
10068@item info types @var{regexp}
10069@itemx info types
09d4efe1
EZ
10070Print a brief description of all types whose names match the regular
10071expression @var{regexp} (or all types in your program, if you supply
10072no argument). Each complete typename is matched as though it were a
10073complete line; thus, @samp{i type value} gives information on all
10074types in your program whose names include the string @code{value}, but
10075@samp{i type ^value$} gives information only on types whose complete
10076name is @code{value}.
c906108c
SS
10077
10078This command differs from @code{ptype} in two ways: first, like
10079@code{whatis}, it does not print a detailed description; second, it
10080lists all source files where a type is defined.
10081
b37052ae
EZ
10082@kindex info scope
10083@cindex local variables
09d4efe1 10084@item info scope @var{location}
b37052ae 10085List all the variables local to a particular scope. This command
09d4efe1
EZ
10086accepts a @var{location} argument---a function name, a source line, or
10087an address preceded by a @samp{*}, and prints all the variables local
10088to the scope defined by that location. For example:
b37052ae
EZ
10089
10090@smallexample
10091(@value{GDBP}) @b{info scope command_line_handler}
10092Scope for command_line_handler:
10093Symbol rl is an argument at stack/frame offset 8, length 4.
10094Symbol linebuffer is in static storage at address 0x150a18, length 4.
10095Symbol linelength is in static storage at address 0x150a1c, length 4.
10096Symbol p is a local variable in register $esi, length 4.
10097Symbol p1 is a local variable in register $ebx, length 4.
10098Symbol nline is a local variable in register $edx, length 4.
10099Symbol repeat is a local variable at frame offset -8, length 4.
10100@end smallexample
10101
f5c37c66
EZ
10102@noindent
10103This command is especially useful for determining what data to collect
10104during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
10105collect}.
10106
c906108c
SS
10107@kindex info source
10108@item info source
919d772c
JB
10109Show information about the current source file---that is, the source file for
10110the function containing the current point of execution:
10111@itemize @bullet
10112@item
10113the name of the source file, and the directory containing it,
10114@item
10115the directory it was compiled in,
10116@item
10117its length, in lines,
10118@item
10119which programming language it is written in,
10120@item
10121whether the executable includes debugging information for that file, and
10122if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
10123@item
10124whether the debugging information includes information about
10125preprocessor macros.
10126@end itemize
10127
c906108c
SS
10128
10129@kindex info sources
10130@item info sources
10131Print the names of all source files in your program for which there is
10132debugging information, organized into two lists: files whose symbols
10133have already been read, and files whose symbols will be read when needed.
10134
10135@kindex info functions
10136@item info functions
10137Print the names and data types of all defined functions.
10138
10139@item info functions @var{regexp}
10140Print the names and data types of all defined functions
10141whose names contain a match for regular expression @var{regexp}.
10142Thus, @samp{info fun step} finds all functions whose names
10143include @code{step}; @samp{info fun ^step} finds those whose names
b383017d
RM
10144start with @code{step}. If a function name contains characters
10145that conflict with the regular expression language (eg.
1c5dfdad 10146@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
10147
10148@kindex info variables
10149@item info variables
10150Print the names and data types of all variables that are declared
6ca652b0 10151outside of functions (i.e.@: excluding local variables).
c906108c
SS
10152
10153@item info variables @var{regexp}
10154Print the names and data types of all variables (except for local
10155variables) whose names contain a match for regular expression
10156@var{regexp}.
10157
b37303ee 10158@kindex info classes
721c2651 10159@cindex Objective-C, classes and selectors
b37303ee
AF
10160@item info classes
10161@itemx info classes @var{regexp}
10162Display all Objective-C classes in your program, or
10163(with the @var{regexp} argument) all those matching a particular regular
10164expression.
10165
10166@kindex info selectors
10167@item info selectors
10168@itemx info selectors @var{regexp}
10169Display all Objective-C selectors in your program, or
10170(with the @var{regexp} argument) all those matching a particular regular
10171expression.
10172
c906108c
SS
10173@ignore
10174This was never implemented.
10175@kindex info methods
10176@item info methods
10177@itemx info methods @var{regexp}
10178The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
10179methods within C@t{++} program, or (with the @var{regexp} argument) a
10180specific set of methods found in the various C@t{++} classes. Many
10181C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
10182from the @code{ptype} command can be overwhelming and hard to use. The
10183@code{info-methods} command filters the methods, printing only those
10184which match the regular-expression @var{regexp}.
10185@end ignore
10186
c906108c
SS
10187@cindex reloading symbols
10188Some systems allow individual object files that make up your program to
7a292a7a
SS
10189be replaced without stopping and restarting your program. For example,
10190in VxWorks you can simply recompile a defective object file and keep on
10191running. If you are running on one of these systems, you can allow
10192@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
10193
10194@table @code
10195@kindex set symbol-reloading
10196@item set symbol-reloading on
10197Replace symbol definitions for the corresponding source file when an
10198object file with a particular name is seen again.
10199
10200@item set symbol-reloading off
6d2ebf8b
SS
10201Do not replace symbol definitions when encountering object files of the
10202same name more than once. This is the default state; if you are not
10203running on a system that permits automatic relinking of modules, you
10204should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
10205may discard symbols when linking large programs, that may contain
10206several modules (from different directories or libraries) with the same
10207name.
c906108c
SS
10208
10209@kindex show symbol-reloading
10210@item show symbol-reloading
10211Show the current @code{on} or @code{off} setting.
10212@end table
c906108c 10213
9c16f35a 10214@cindex opaque data types
c906108c
SS
10215@kindex set opaque-type-resolution
10216@item set opaque-type-resolution on
10217Tell @value{GDBN} to resolve opaque types. An opaque type is a type
10218declared as a pointer to a @code{struct}, @code{class}, or
10219@code{union}---for example, @code{struct MyType *}---that is used in one
10220source file although the full declaration of @code{struct MyType} is in
10221another source file. The default is on.
10222
10223A change in the setting of this subcommand will not take effect until
10224the next time symbols for a file are loaded.
10225
10226@item set opaque-type-resolution off
10227Tell @value{GDBN} not to resolve opaque types. In this case, the type
10228is printed as follows:
10229@smallexample
10230@{<no data fields>@}
10231@end smallexample
10232
10233@kindex show opaque-type-resolution
10234@item show opaque-type-resolution
10235Show whether opaque types are resolved or not.
c906108c
SS
10236
10237@kindex maint print symbols
10238@cindex symbol dump
10239@kindex maint print psymbols
10240@cindex partial symbol dump
10241@item maint print symbols @var{filename}
10242@itemx maint print psymbols @var{filename}
10243@itemx maint print msymbols @var{filename}
10244Write a dump of debugging symbol data into the file @var{filename}.
10245These commands are used to debug the @value{GDBN} symbol-reading code. Only
10246symbols with debugging data are included. If you use @samp{maint print
10247symbols}, @value{GDBN} includes all the symbols for which it has already
10248collected full details: that is, @var{filename} reflects symbols for
10249only those files whose symbols @value{GDBN} has read. You can use the
10250command @code{info sources} to find out which files these are. If you
10251use @samp{maint print psymbols} instead, the dump shows information about
10252symbols that @value{GDBN} only knows partially---that is, symbols defined in
10253files that @value{GDBN} has skimmed, but not yet read completely. Finally,
10254@samp{maint print msymbols} dumps just the minimal symbol information
10255required for each object file from which @value{GDBN} has read some symbols.
10256@xref{Files, ,Commands to specify files}, for a discussion of how
10257@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 10258
5e7b2f39
JB
10259@kindex maint info symtabs
10260@kindex maint info psymtabs
44ea7b70
JB
10261@cindex listing @value{GDBN}'s internal symbol tables
10262@cindex symbol tables, listing @value{GDBN}'s internal
10263@cindex full symbol tables, listing @value{GDBN}'s internal
10264@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
10265@item maint info symtabs @r{[} @var{regexp} @r{]}
10266@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
10267
10268List the @code{struct symtab} or @code{struct partial_symtab}
10269structures whose names match @var{regexp}. If @var{regexp} is not
10270given, list them all. The output includes expressions which you can
10271copy into a @value{GDBN} debugging this one to examine a particular
10272structure in more detail. For example:
10273
10274@smallexample
5e7b2f39 10275(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
10276@{ objfile /home/gnu/build/gdb/gdb
10277 ((struct objfile *) 0x82e69d0)
b383017d 10278 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10279 ((struct partial_symtab *) 0x8474b10)
10280 readin no
10281 fullname (null)
10282 text addresses 0x814d3c8 -- 0x8158074
10283 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
10284 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
10285 dependencies (none)
10286 @}
10287@}
5e7b2f39 10288(@value{GDBP}) maint info symtabs
44ea7b70
JB
10289(@value{GDBP})
10290@end smallexample
10291@noindent
10292We see that there is one partial symbol table whose filename contains
10293the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
10294and we see that @value{GDBN} has not read in any symtabs yet at all.
10295If we set a breakpoint on a function, that will cause @value{GDBN} to
10296read the symtab for the compilation unit containing that function:
10297
10298@smallexample
10299(@value{GDBP}) break dwarf2_psymtab_to_symtab
10300Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
10301line 1574.
5e7b2f39 10302(@value{GDBP}) maint info symtabs
b383017d 10303@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 10304 ((struct objfile *) 0x82e69d0)
b383017d 10305 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10306 ((struct symtab *) 0x86c1f38)
10307 dirname (null)
10308 fullname (null)
10309 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
10310 debugformat DWARF 2
10311 @}
10312@}
b383017d 10313(@value{GDBP})
44ea7b70 10314@end smallexample
c906108c
SS
10315@end table
10316
44ea7b70 10317
6d2ebf8b 10318@node Altering
c906108c
SS
10319@chapter Altering Execution
10320
10321Once you think you have found an error in your program, you might want to
10322find out for certain whether correcting the apparent error would lead to
10323correct results in the rest of the run. You can find the answer by
10324experiment, using the @value{GDBN} features for altering execution of the
10325program.
10326
10327For example, you can store new values into variables or memory
7a292a7a
SS
10328locations, give your program a signal, restart it at a different
10329address, or even return prematurely from a function.
c906108c
SS
10330
10331@menu
10332* Assignment:: Assignment to variables
10333* Jumping:: Continuing at a different address
c906108c 10334* Signaling:: Giving your program a signal
c906108c
SS
10335* Returning:: Returning from a function
10336* Calling:: Calling your program's functions
10337* Patching:: Patching your program
10338@end menu
10339
6d2ebf8b 10340@node Assignment
c906108c
SS
10341@section Assignment to variables
10342
10343@cindex assignment
10344@cindex setting variables
10345To alter the value of a variable, evaluate an assignment expression.
10346@xref{Expressions, ,Expressions}. For example,
10347
474c8240 10348@smallexample
c906108c 10349print x=4
474c8240 10350@end smallexample
c906108c
SS
10351
10352@noindent
10353stores the value 4 into the variable @code{x}, and then prints the
5d161b24 10354value of the assignment expression (which is 4).
c906108c
SS
10355@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
10356information on operators in supported languages.
c906108c
SS
10357
10358@kindex set variable
10359@cindex variables, setting
10360If you are not interested in seeing the value of the assignment, use the
10361@code{set} command instead of the @code{print} command. @code{set} is
10362really the same as @code{print} except that the expression's value is
10363not printed and is not put in the value history (@pxref{Value History,
10364,Value history}). The expression is evaluated only for its effects.
10365
c906108c
SS
10366If the beginning of the argument string of the @code{set} command
10367appears identical to a @code{set} subcommand, use the @code{set
10368variable} command instead of just @code{set}. This command is identical
10369to @code{set} except for its lack of subcommands. For example, if your
10370program has a variable @code{width}, you get an error if you try to set
10371a new value with just @samp{set width=13}, because @value{GDBN} has the
10372command @code{set width}:
10373
474c8240 10374@smallexample
c906108c
SS
10375(@value{GDBP}) whatis width
10376type = double
10377(@value{GDBP}) p width
10378$4 = 13
10379(@value{GDBP}) set width=47
10380Invalid syntax in expression.
474c8240 10381@end smallexample
c906108c
SS
10382
10383@noindent
10384The invalid expression, of course, is @samp{=47}. In
10385order to actually set the program's variable @code{width}, use
10386
474c8240 10387@smallexample
c906108c 10388(@value{GDBP}) set var width=47
474c8240 10389@end smallexample
53a5351d 10390
c906108c
SS
10391Because the @code{set} command has many subcommands that can conflict
10392with the names of program variables, it is a good idea to use the
10393@code{set variable} command instead of just @code{set}. For example, if
10394your program has a variable @code{g}, you run into problems if you try
10395to set a new value with just @samp{set g=4}, because @value{GDBN} has
10396the command @code{set gnutarget}, abbreviated @code{set g}:
10397
474c8240 10398@smallexample
c906108c
SS
10399@group
10400(@value{GDBP}) whatis g
10401type = double
10402(@value{GDBP}) p g
10403$1 = 1
10404(@value{GDBP}) set g=4
2df3850c 10405(@value{GDBP}) p g
c906108c
SS
10406$2 = 1
10407(@value{GDBP}) r
10408The program being debugged has been started already.
10409Start it from the beginning? (y or n) y
10410Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
10411"/home/smith/cc_progs/a.out": can't open to read symbols:
10412 Invalid bfd target.
c906108c
SS
10413(@value{GDBP}) show g
10414The current BFD target is "=4".
10415@end group
474c8240 10416@end smallexample
c906108c
SS
10417
10418@noindent
10419The program variable @code{g} did not change, and you silently set the
10420@code{gnutarget} to an invalid value. In order to set the variable
10421@code{g}, use
10422
474c8240 10423@smallexample
c906108c 10424(@value{GDBP}) set var g=4
474c8240 10425@end smallexample
c906108c
SS
10426
10427@value{GDBN} allows more implicit conversions in assignments than C; you can
10428freely store an integer value into a pointer variable or vice versa,
10429and you can convert any structure to any other structure that is the
10430same length or shorter.
10431@comment FIXME: how do structs align/pad in these conversions?
10432@comment /doc@cygnus.com 18dec1990
10433
10434To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
10435construct to generate a value of specified type at a specified address
10436(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
10437to memory location @code{0x83040} as an integer (which implies a certain size
10438and representation in memory), and
10439
474c8240 10440@smallexample
c906108c 10441set @{int@}0x83040 = 4
474c8240 10442@end smallexample
c906108c
SS
10443
10444@noindent
10445stores the value 4 into that memory location.
10446
6d2ebf8b 10447@node Jumping
c906108c
SS
10448@section Continuing at a different address
10449
10450Ordinarily, when you continue your program, you do so at the place where
10451it stopped, with the @code{continue} command. You can instead continue at
10452an address of your own choosing, with the following commands:
10453
10454@table @code
10455@kindex jump
10456@item jump @var{linespec}
10457Resume execution at line @var{linespec}. Execution stops again
10458immediately if there is a breakpoint there. @xref{List, ,Printing
10459source lines}, for a description of the different forms of
10460@var{linespec}. It is common practice to use the @code{tbreak} command
10461in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
10462breakpoints}.
10463
10464The @code{jump} command does not change the current stack frame, or
10465the stack pointer, or the contents of any memory location or any
10466register other than the program counter. If line @var{linespec} is in
10467a different function from the one currently executing, the results may
10468be bizarre if the two functions expect different patterns of arguments or
10469of local variables. For this reason, the @code{jump} command requests
10470confirmation if the specified line is not in the function currently
10471executing. However, even bizarre results are predictable if you are
10472well acquainted with the machine-language code of your program.
10473
10474@item jump *@var{address}
10475Resume execution at the instruction at address @var{address}.
10476@end table
10477
c906108c 10478@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
10479On many systems, you can get much the same effect as the @code{jump}
10480command by storing a new value into the register @code{$pc}. The
10481difference is that this does not start your program running; it only
10482changes the address of where it @emph{will} run when you continue. For
10483example,
c906108c 10484
474c8240 10485@smallexample
c906108c 10486set $pc = 0x485
474c8240 10487@end smallexample
c906108c
SS
10488
10489@noindent
10490makes the next @code{continue} command or stepping command execute at
10491address @code{0x485}, rather than at the address where your program stopped.
10492@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
10493
10494The most common occasion to use the @code{jump} command is to back
10495up---perhaps with more breakpoints set---over a portion of a program
10496that has already executed, in order to examine its execution in more
10497detail.
10498
c906108c 10499@c @group
6d2ebf8b 10500@node Signaling
c906108c 10501@section Giving your program a signal
9c16f35a 10502@cindex deliver a signal to a program
c906108c
SS
10503
10504@table @code
10505@kindex signal
10506@item signal @var{signal}
10507Resume execution where your program stopped, but immediately give it the
10508signal @var{signal}. @var{signal} can be the name or the number of a
10509signal. For example, on many systems @code{signal 2} and @code{signal
10510SIGINT} are both ways of sending an interrupt signal.
10511
10512Alternatively, if @var{signal} is zero, continue execution without
10513giving a signal. This is useful when your program stopped on account of
10514a signal and would ordinary see the signal when resumed with the
10515@code{continue} command; @samp{signal 0} causes it to resume without a
10516signal.
10517
10518@code{signal} does not repeat when you press @key{RET} a second time
10519after executing the command.
10520@end table
10521@c @end group
10522
10523Invoking the @code{signal} command is not the same as invoking the
10524@code{kill} utility from the shell. Sending a signal with @code{kill}
10525causes @value{GDBN} to decide what to do with the signal depending on
10526the signal handling tables (@pxref{Signals}). The @code{signal} command
10527passes the signal directly to your program.
10528
c906108c 10529
6d2ebf8b 10530@node Returning
c906108c
SS
10531@section Returning from a function
10532
10533@table @code
10534@cindex returning from a function
10535@kindex return
10536@item return
10537@itemx return @var{expression}
10538You can cancel execution of a function call with the @code{return}
10539command. If you give an
10540@var{expression} argument, its value is used as the function's return
10541value.
10542@end table
10543
10544When you use @code{return}, @value{GDBN} discards the selected stack frame
10545(and all frames within it). You can think of this as making the
10546discarded frame return prematurely. If you wish to specify a value to
10547be returned, give that value as the argument to @code{return}.
10548
10549This pops the selected stack frame (@pxref{Selection, ,Selecting a
10550frame}), and any other frames inside of it, leaving its caller as the
10551innermost remaining frame. That frame becomes selected. The
10552specified value is stored in the registers used for returning values
10553of functions.
10554
10555The @code{return} command does not resume execution; it leaves the
10556program stopped in the state that would exist if the function had just
10557returned. In contrast, the @code{finish} command (@pxref{Continuing
10558and Stepping, ,Continuing and stepping}) resumes execution until the
10559selected stack frame returns naturally.
10560
6d2ebf8b 10561@node Calling
c906108c
SS
10562@section Calling program functions
10563
f8568604 10564@table @code
c906108c 10565@cindex calling functions
f8568604
EZ
10566@cindex inferior functions, calling
10567@item print @var{expr}
9c16f35a 10568Evaluate the expression @var{expr} and display the resuling value.
f8568604
EZ
10569@var{expr} may include calls to functions in the program being
10570debugged.
10571
c906108c 10572@kindex call
c906108c
SS
10573@item call @var{expr}
10574Evaluate the expression @var{expr} without displaying @code{void}
10575returned values.
c906108c
SS
10576
10577You can use this variant of the @code{print} command if you want to
f8568604
EZ
10578execute a function from your program that does not return anything
10579(a.k.a.@: @dfn{a void function}), but without cluttering the output
10580with @code{void} returned values that @value{GDBN} will otherwise
10581print. If the result is not void, it is printed and saved in the
10582value history.
10583@end table
10584
9c16f35a
EZ
10585It is possible for the function you call via the @code{print} or
10586@code{call} command to generate a signal (e.g., if there's a bug in
10587the function, or if you passed it incorrect arguments). What happens
10588in that case is controlled by the @code{set unwindonsignal} command.
10589
10590@table @code
10591@item set unwindonsignal
10592@kindex set unwindonsignal
10593@cindex unwind stack in called functions
10594@cindex call dummy stack unwinding
10595Set unwinding of the stack if a signal is received while in a function
10596that @value{GDBN} called in the program being debugged. If set to on,
10597@value{GDBN} unwinds the stack it created for the call and restores
10598the context to what it was before the call. If set to off (the
10599default), @value{GDBN} stops in the frame where the signal was
10600received.
10601
10602@item show unwindonsignal
10603@kindex show unwindonsignal
10604Show the current setting of stack unwinding in the functions called by
10605@value{GDBN}.
10606@end table
10607
f8568604
EZ
10608@cindex weak alias functions
10609Sometimes, a function you wish to call is actually a @dfn{weak alias}
10610for another function. In such case, @value{GDBN} might not pick up
10611the type information, including the types of the function arguments,
10612which causes @value{GDBN} to call the inferior function incorrectly.
10613As a result, the called function will function erroneously and may
10614even crash. A solution to that is to use the name of the aliased
10615function instead.
c906108c 10616
6d2ebf8b 10617@node Patching
c906108c 10618@section Patching programs
7a292a7a 10619
c906108c
SS
10620@cindex patching binaries
10621@cindex writing into executables
c906108c 10622@cindex writing into corefiles
c906108c 10623
7a292a7a
SS
10624By default, @value{GDBN} opens the file containing your program's
10625executable code (or the corefile) read-only. This prevents accidental
10626alterations to machine code; but it also prevents you from intentionally
10627patching your program's binary.
c906108c
SS
10628
10629If you'd like to be able to patch the binary, you can specify that
10630explicitly with the @code{set write} command. For example, you might
10631want to turn on internal debugging flags, or even to make emergency
10632repairs.
10633
10634@table @code
10635@kindex set write
10636@item set write on
10637@itemx set write off
7a292a7a
SS
10638If you specify @samp{set write on}, @value{GDBN} opens executable and
10639core files for both reading and writing; if you specify @samp{set write
c906108c
SS
10640off} (the default), @value{GDBN} opens them read-only.
10641
10642If you have already loaded a file, you must load it again (using the
7a292a7a
SS
10643@code{exec-file} or @code{core-file} command) after changing @code{set
10644write}, for your new setting to take effect.
c906108c
SS
10645
10646@item show write
10647@kindex show write
7a292a7a
SS
10648Display whether executable files and core files are opened for writing
10649as well as reading.
c906108c
SS
10650@end table
10651
6d2ebf8b 10652@node GDB Files
c906108c
SS
10653@chapter @value{GDBN} Files
10654
7a292a7a
SS
10655@value{GDBN} needs to know the file name of the program to be debugged,
10656both in order to read its symbol table and in order to start your
10657program. To debug a core dump of a previous run, you must also tell
10658@value{GDBN} the name of the core dump file.
c906108c
SS
10659
10660@menu
10661* Files:: Commands to specify files
5b5d99cf 10662* Separate Debug Files:: Debugging information in separate files
c906108c
SS
10663* Symbol Errors:: Errors reading symbol files
10664@end menu
10665
6d2ebf8b 10666@node Files
c906108c 10667@section Commands to specify files
c906108c 10668
7a292a7a 10669@cindex symbol table
c906108c 10670@cindex core dump file
7a292a7a
SS
10671
10672You may want to specify executable and core dump file names. The usual
10673way to do this is at start-up time, using the arguments to
10674@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
10675Out of @value{GDBN}}).
c906108c
SS
10676
10677Occasionally it is necessary to change to a different file during a
397ca115
EZ
10678@value{GDBN} session. Or you may run @value{GDBN} and forget to
10679specify a file you want to use. Or you are debugging a remote target
10680via @code{gdbserver} (@pxref{Server, file}). In these situations the
10681@value{GDBN} commands to specify new files are useful.
c906108c
SS
10682
10683@table @code
10684@cindex executable file
10685@kindex file
10686@item file @var{filename}
10687Use @var{filename} as the program to be debugged. It is read for its
10688symbols and for the contents of pure memory. It is also the program
10689executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
10690directory and the file is not found in the @value{GDBN} working directory,
10691@value{GDBN} uses the environment variable @code{PATH} as a list of
10692directories to search, just as the shell does when looking for a program
10693to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
10694and your program, using the @code{path} command.
10695
fc8be69e
EZ
10696@cindex unlinked object files
10697@cindex patching object files
10698You can load unlinked object @file{.o} files into @value{GDBN} using
10699the @code{file} command. You will not be able to ``run'' an object
10700file, but you can disassemble functions and inspect variables. Also,
10701if the underlying BFD functionality supports it, you could use
10702@kbd{gdb -write} to patch object files using this technique. Note
10703that @value{GDBN} can neither interpret nor modify relocations in this
10704case, so branches and some initialized variables will appear to go to
10705the wrong place. But this feature is still handy from time to time.
10706
c906108c
SS
10707@item file
10708@code{file} with no argument makes @value{GDBN} discard any information it
10709has on both executable file and the symbol table.
10710
10711@kindex exec-file
10712@item exec-file @r{[} @var{filename} @r{]}
10713Specify that the program to be run (but not the symbol table) is found
10714in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
10715if necessary to locate your program. Omitting @var{filename} means to
10716discard information on the executable file.
10717
10718@kindex symbol-file
10719@item symbol-file @r{[} @var{filename} @r{]}
10720Read symbol table information from file @var{filename}. @code{PATH} is
10721searched when necessary. Use the @code{file} command to get both symbol
10722table and program to run from the same file.
10723
10724@code{symbol-file} with no argument clears out @value{GDBN} information on your
10725program's symbol table.
10726
5d161b24 10727The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
10728of its convenience variables, the value history, and all breakpoints and
10729auto-display expressions. This is because they may contain pointers to
10730the internal data recording symbols and data types, which are part of
10731the old symbol table data being discarded inside @value{GDBN}.
10732
10733@code{symbol-file} does not repeat if you press @key{RET} again after
10734executing it once.
10735
10736When @value{GDBN} is configured for a particular environment, it
10737understands debugging information in whatever format is the standard
10738generated for that environment; you may use either a @sc{gnu} compiler, or
10739other compilers that adhere to the local conventions.
c906108c
SS
10740Best results are usually obtained from @sc{gnu} compilers; for example,
10741using @code{@value{GCC}} you can generate debugging information for
10742optimized code.
c906108c
SS
10743
10744For most kinds of object files, with the exception of old SVR3 systems
10745using COFF, the @code{symbol-file} command does not normally read the
10746symbol table in full right away. Instead, it scans the symbol table
10747quickly to find which source files and which symbols are present. The
10748details are read later, one source file at a time, as they are needed.
10749
10750The purpose of this two-stage reading strategy is to make @value{GDBN}
10751start up faster. For the most part, it is invisible except for
10752occasional pauses while the symbol table details for a particular source
10753file are being read. (The @code{set verbose} command can turn these
10754pauses into messages if desired. @xref{Messages/Warnings, ,Optional
10755warnings and messages}.)
10756
c906108c
SS
10757We have not implemented the two-stage strategy for COFF yet. When the
10758symbol table is stored in COFF format, @code{symbol-file} reads the
10759symbol table data in full right away. Note that ``stabs-in-COFF''
10760still does the two-stage strategy, since the debug info is actually
10761in stabs format.
10762
10763@kindex readnow
10764@cindex reading symbols immediately
10765@cindex symbols, reading immediately
a94ab193
EZ
10766@item symbol-file @var{filename} @r{[} -readnow @r{]}
10767@itemx file @var{filename} @r{[} -readnow @r{]}
c906108c
SS
10768You can override the @value{GDBN} two-stage strategy for reading symbol
10769tables by using the @samp{-readnow} option with any of the commands that
10770load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 10771entire symbol table available.
c906108c 10772
c906108c
SS
10773@c FIXME: for now no mention of directories, since this seems to be in
10774@c flux. 13mar1992 status is that in theory GDB would look either in
10775@c current dir or in same dir as myprog; but issues like competing
10776@c GDB's, or clutter in system dirs, mean that in practice right now
10777@c only current dir is used. FFish says maybe a special GDB hierarchy
10778@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
10779@c files.
10780
c906108c 10781@kindex core-file
09d4efe1 10782@item core-file @r{[}@var{filename}@r{]}
4644b6e3 10783@itemx core
c906108c
SS
10784Specify the whereabouts of a core dump file to be used as the ``contents
10785of memory''. Traditionally, core files contain only some parts of the
10786address space of the process that generated them; @value{GDBN} can access the
10787executable file itself for other parts.
10788
10789@code{core-file} with no argument specifies that no core file is
10790to be used.
10791
10792Note that the core file is ignored when your program is actually running
7a292a7a
SS
10793under @value{GDBN}. So, if you have been running your program and you
10794wish to debug a core file instead, you must kill the subprocess in which
10795the program is running. To do this, use the @code{kill} command
c906108c 10796(@pxref{Kill Process, ,Killing the child process}).
c906108c 10797
c906108c
SS
10798@kindex add-symbol-file
10799@cindex dynamic linking
10800@item add-symbol-file @var{filename} @var{address}
a94ab193 10801@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
17d9d558 10802@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
10803The @code{add-symbol-file} command reads additional symbol table
10804information from the file @var{filename}. You would use this command
10805when @var{filename} has been dynamically loaded (by some other means)
10806into the program that is running. @var{address} should be the memory
10807address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
10808this out for itself. You can additionally specify an arbitrary number
10809of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
10810section name and base address for that section. You can specify any
10811@var{address} as an expression.
c906108c
SS
10812
10813The symbol table of the file @var{filename} is added to the symbol table
10814originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
10815@code{add-symbol-file} command any number of times; the new symbol data
10816thus read keeps adding to the old. To discard all old symbol data
10817instead, use the @code{symbol-file} command without any arguments.
c906108c 10818
17d9d558
JB
10819@cindex relocatable object files, reading symbols from
10820@cindex object files, relocatable, reading symbols from
10821@cindex reading symbols from relocatable object files
10822@cindex symbols, reading from relocatable object files
10823@cindex @file{.o} files, reading symbols from
10824Although @var{filename} is typically a shared library file, an
10825executable file, or some other object file which has been fully
10826relocated for loading into a process, you can also load symbolic
10827information from relocatable @file{.o} files, as long as:
10828
10829@itemize @bullet
10830@item
10831the file's symbolic information refers only to linker symbols defined in
10832that file, not to symbols defined by other object files,
10833@item
10834every section the file's symbolic information refers to has actually
10835been loaded into the inferior, as it appears in the file, and
10836@item
10837you can determine the address at which every section was loaded, and
10838provide these to the @code{add-symbol-file} command.
10839@end itemize
10840
10841@noindent
10842Some embedded operating systems, like Sun Chorus and VxWorks, can load
10843relocatable files into an already running program; such systems
10844typically make the requirements above easy to meet. However, it's
10845important to recognize that many native systems use complex link
49efadf5 10846procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
10847assembly, for example) that make the requirements difficult to meet. In
10848general, one cannot assume that using @code{add-symbol-file} to read a
10849relocatable object file's symbolic information will have the same effect
10850as linking the relocatable object file into the program in the normal
10851way.
10852
c906108c
SS
10853@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
10854
c45da7e6
EZ
10855@kindex add-symbol-file-from-memory
10856@cindex @code{syscall DSO}
10857@cindex load symbols from memory
10858@item add-symbol-file-from-memory @var{address}
10859Load symbols from the given @var{address} in a dynamically loaded
10860object file whose image is mapped directly into the inferior's memory.
10861For example, the Linux kernel maps a @code{syscall DSO} into each
10862process's address space; this DSO provides kernel-specific code for
10863some system calls. The argument can be any expression whose
10864evaluation yields the address of the file's shared object file header.
10865For this command to work, you must have used @code{symbol-file} or
10866@code{exec-file} commands in advance.
10867
09d4efe1
EZ
10868@kindex add-shared-symbol-files
10869@kindex assf
10870@item add-shared-symbol-files @var{library-file}
10871@itemx assf @var{library-file}
10872The @code{add-shared-symbol-files} command can currently be used only
10873in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
10874alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
10875@value{GDBN} automatically looks for shared libraries, however if
10876@value{GDBN} does not find yours, you can invoke
10877@code{add-shared-symbol-files}. It takes one argument: the shared
10878library's file name. @code{assf} is a shorthand alias for
10879@code{add-shared-symbol-files}.
c906108c 10880
c906108c 10881@kindex section
09d4efe1
EZ
10882@item section @var{section} @var{addr}
10883The @code{section} command changes the base address of the named
10884@var{section} of the exec file to @var{addr}. This can be used if the
10885exec file does not contain section addresses, (such as in the
10886@code{a.out} format), or when the addresses specified in the file
10887itself are wrong. Each section must be changed separately. The
10888@code{info files} command, described below, lists all the sections and
10889their addresses.
c906108c
SS
10890
10891@kindex info files
10892@kindex info target
10893@item info files
10894@itemx info target
7a292a7a
SS
10895@code{info files} and @code{info target} are synonymous; both print the
10896current target (@pxref{Targets, ,Specifying a Debugging Target}),
10897including the names of the executable and core dump files currently in
10898use by @value{GDBN}, and the files from which symbols were loaded. The
10899command @code{help target} lists all possible targets rather than
10900current ones.
10901
fe95c787
MS
10902@kindex maint info sections
10903@item maint info sections
10904Another command that can give you extra information about program sections
10905is @code{maint info sections}. In addition to the section information
10906displayed by @code{info files}, this command displays the flags and file
10907offset of each section in the executable and core dump files. In addition,
10908@code{maint info sections} provides the following command options (which
10909may be arbitrarily combined):
10910
10911@table @code
10912@item ALLOBJ
10913Display sections for all loaded object files, including shared libraries.
10914@item @var{sections}
6600abed 10915Display info only for named @var{sections}.
fe95c787
MS
10916@item @var{section-flags}
10917Display info only for sections for which @var{section-flags} are true.
10918The section flags that @value{GDBN} currently knows about are:
10919@table @code
10920@item ALLOC
10921Section will have space allocated in the process when loaded.
10922Set for all sections except those containing debug information.
10923@item LOAD
10924Section will be loaded from the file into the child process memory.
10925Set for pre-initialized code and data, clear for @code{.bss} sections.
10926@item RELOC
10927Section needs to be relocated before loading.
10928@item READONLY
10929Section cannot be modified by the child process.
10930@item CODE
10931Section contains executable code only.
6600abed 10932@item DATA
fe95c787
MS
10933Section contains data only (no executable code).
10934@item ROM
10935Section will reside in ROM.
10936@item CONSTRUCTOR
10937Section contains data for constructor/destructor lists.
10938@item HAS_CONTENTS
10939Section is not empty.
10940@item NEVER_LOAD
10941An instruction to the linker to not output the section.
10942@item COFF_SHARED_LIBRARY
10943A notification to the linker that the section contains
10944COFF shared library information.
10945@item IS_COMMON
10946Section contains common symbols.
10947@end table
10948@end table
6763aef9 10949@kindex set trust-readonly-sections
9c16f35a 10950@cindex read-only sections
6763aef9
MS
10951@item set trust-readonly-sections on
10952Tell @value{GDBN} that readonly sections in your object file
6ca652b0 10953really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
10954In that case, @value{GDBN} can fetch values from these sections
10955out of the object file, rather than from the target program.
10956For some targets (notably embedded ones), this can be a significant
10957enhancement to debugging performance.
10958
10959The default is off.
10960
10961@item set trust-readonly-sections off
15110bc3 10962Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
10963the contents of the section might change while the program is running,
10964and must therefore be fetched from the target when needed.
9c16f35a
EZ
10965
10966@item show trust-readonly-sections
10967Show the current setting of trusting readonly sections.
c906108c
SS
10968@end table
10969
10970All file-specifying commands allow both absolute and relative file names
10971as arguments. @value{GDBN} always converts the file name to an absolute file
10972name and remembers it that way.
10973
c906108c 10974@cindex shared libraries
9c16f35a
EZ
10975@value{GDBN} supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
10976and IBM RS/6000 AIX shared libraries.
53a5351d 10977
c906108c
SS
10978@value{GDBN} automatically loads symbol definitions from shared libraries
10979when you use the @code{run} command, or when you examine a core file.
10980(Before you issue the @code{run} command, @value{GDBN} does not understand
10981references to a function in a shared library, however---unless you are
10982debugging a core file).
53a5351d
JM
10983
10984On HP-UX, if the program loads a library explicitly, @value{GDBN}
10985automatically loads the symbols at the time of the @code{shl_load} call.
10986
c906108c
SS
10987@c FIXME: some @value{GDBN} release may permit some refs to undef
10988@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
10989@c FIXME...lib; check this from time to time when updating manual
10990
b7209cb4
FF
10991There are times, however, when you may wish to not automatically load
10992symbol definitions from shared libraries, such as when they are
10993particularly large or there are many of them.
10994
10995To control the automatic loading of shared library symbols, use the
10996commands:
10997
10998@table @code
10999@kindex set auto-solib-add
11000@item set auto-solib-add @var{mode}
11001If @var{mode} is @code{on}, symbols from all shared object libraries
11002will be loaded automatically when the inferior begins execution, you
11003attach to an independently started inferior, or when the dynamic linker
11004informs @value{GDBN} that a new library has been loaded. If @var{mode}
11005is @code{off}, symbols must be loaded manually, using the
11006@code{sharedlibrary} command. The default value is @code{on}.
11007
dcaf7c2c
EZ
11008@cindex memory used for symbol tables
11009If your program uses lots of shared libraries with debug info that
11010takes large amounts of memory, you can decrease the @value{GDBN}
11011memory footprint by preventing it from automatically loading the
11012symbols from shared libraries. To that end, type @kbd{set
11013auto-solib-add off} before running the inferior, then load each
11014library whose debug symbols you do need with @kbd{sharedlibrary
11015@var{regexp}}, where @var{regexp} is a regular expresion that matches
11016the libraries whose symbols you want to be loaded.
11017
b7209cb4
FF
11018@kindex show auto-solib-add
11019@item show auto-solib-add
11020Display the current autoloading mode.
11021@end table
11022
c45da7e6 11023@cindex load shared library
b7209cb4
FF
11024To explicitly load shared library symbols, use the @code{sharedlibrary}
11025command:
11026
c906108c
SS
11027@table @code
11028@kindex info sharedlibrary
11029@kindex info share
11030@item info share
11031@itemx info sharedlibrary
11032Print the names of the shared libraries which are currently loaded.
11033
11034@kindex sharedlibrary
11035@kindex share
11036@item sharedlibrary @var{regex}
11037@itemx share @var{regex}
c906108c
SS
11038Load shared object library symbols for files matching a
11039Unix regular expression.
11040As with files loaded automatically, it only loads shared libraries
11041required by your program for a core file or after typing @code{run}. If
11042@var{regex} is omitted all shared libraries required by your program are
11043loaded.
c45da7e6
EZ
11044
11045@item nosharedlibrary
11046@kindex nosharedlibrary
11047@cindex unload symbols from shared libraries
11048Unload all shared object library symbols. This discards all symbols
11049that have been loaded from all shared libraries. Symbols from shared
11050libraries that were loaded by explicit user requests are not
11051discarded.
c906108c
SS
11052@end table
11053
721c2651
EZ
11054Sometimes you may wish that @value{GDBN} stops and gives you control
11055when any of shared library events happen. Use the @code{set
11056stop-on-solib-events} command for this:
11057
11058@table @code
11059@item set stop-on-solib-events
11060@kindex set stop-on-solib-events
11061This command controls whether @value{GDBN} should give you control
11062when the dynamic linker notifies it about some shared library event.
11063The most common event of interest is loading or unloading of a new
11064shared library.
11065
11066@item show stop-on-solib-events
11067@kindex show stop-on-solib-events
11068Show whether @value{GDBN} stops and gives you control when shared
11069library events happen.
11070@end table
11071
f5ebfba0
DJ
11072Shared libraries are also supported in many cross or remote debugging
11073configurations. A copy of the target's libraries need to be present on the
11074host system; they need to be the same as the target libraries, although the
11075copies on the target can be stripped as long as the copies on the host are
11076not.
11077
59b7b46f
EZ
11078@cindex where to look for shared libraries
11079For remote debugging, you need to tell @value{GDBN} where the target
11080libraries are, so that it can load the correct copies---otherwise, it
11081may try to load the host's libraries. @value{GDBN} has two variables
11082to specify the search directories for target libraries.
f5ebfba0
DJ
11083
11084@table @code
59b7b46f 11085@cindex prefix for shared library file names
f5ebfba0
DJ
11086@kindex set solib-absolute-prefix
11087@item set solib-absolute-prefix @var{path}
11088If this variable is set, @var{path} will be used as a prefix for any
11089absolute shared library paths; many runtime loaders store the absolute
11090paths to the shared library in the target program's memory. If you use
11091@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
11092out in the same way that they are on the target, with e.g.@: a
11093@file{/usr/lib} hierarchy under @var{path}.
11094
59b7b46f
EZ
11095@cindex default value of @samp{solib-absolute-prefix}
11096@cindex @samp{--with-sysroot}
f5ebfba0
DJ
11097You can set the default value of @samp{solib-absolute-prefix} by using the
11098configure-time @samp{--with-sysroot} option.
11099
11100@kindex show solib-absolute-prefix
11101@item show solib-absolute-prefix
11102Display the current shared library prefix.
11103
11104@kindex set solib-search-path
11105@item set solib-search-path @var{path}
11106If this variable is set, @var{path} is a colon-separated list of directories
11107to search for shared libraries. @samp{solib-search-path} is used after
11108@samp{solib-absolute-prefix} fails to locate the library, or if the path to
11109the library is relative instead of absolute. If you want to use
11110@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
11111set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
11112@value{GDBN} from finding your host's libraries.
11113
11114@kindex show solib-search-path
11115@item show solib-search-path
11116Display the current shared library search path.
11117@end table
11118
5b5d99cf
JB
11119
11120@node Separate Debug Files
11121@section Debugging Information in Separate Files
11122@cindex separate debugging information files
11123@cindex debugging information in separate files
11124@cindex @file{.debug} subdirectories
11125@cindex debugging information directory, global
11126@cindex global debugging information directory
11127
11128@value{GDBN} allows you to put a program's debugging information in a
11129file separate from the executable itself, in a way that allows
11130@value{GDBN} to find and load the debugging information automatically.
11131Since debugging information can be very large --- sometimes larger
11132than the executable code itself --- some systems distribute debugging
11133information for their executables in separate files, which users can
11134install only when they need to debug a problem.
11135
11136If an executable's debugging information has been extracted to a
11137separate file, the executable should contain a @dfn{debug link} giving
11138the name of the debugging information file (with no directory
11139components), and a checksum of its contents. (The exact form of a
11140debug link is described below.) If the full name of the directory
11141containing the executable is @var{execdir}, and the executable has a
11142debug link that specifies the name @var{debugfile}, then @value{GDBN}
11143will automatically search for the debugging information file in three
11144places:
11145
11146@itemize @bullet
11147@item
11148the directory containing the executable file (that is, it will look
11149for a file named @file{@var{execdir}/@var{debugfile}},
11150@item
11151a subdirectory of that directory named @file{.debug} (that is, the
11152file @file{@var{execdir}/.debug/@var{debugfile}}, and
11153@item
11154a subdirectory of the global debug file directory that includes the
11155executable's full path, and the name from the link (that is, the file
11156@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
11157@var{globaldebugdir} is the global debug file directory, and
11158@var{execdir} has been turned into a relative path).
11159@end itemize
11160@noindent
11161@value{GDBN} checks under each of these names for a debugging
11162information file whose checksum matches that given in the link, and
11163reads the debugging information from the first one it finds.
11164
11165So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
11166which has a link containing the name @file{ls.debug}, and the global
11167debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
11168for debug information in @file{/usr/bin/ls.debug},
11169@file{/usr/bin/.debug/ls.debug}, and
11170@file{/usr/lib/debug/usr/bin/ls.debug}.
11171
11172You can set the global debugging info directory's name, and view the
11173name @value{GDBN} is currently using.
11174
11175@table @code
11176
11177@kindex set debug-file-directory
11178@item set debug-file-directory @var{directory}
11179Set the directory which @value{GDBN} searches for separate debugging
11180information files to @var{directory}.
11181
11182@kindex show debug-file-directory
11183@item show debug-file-directory
11184Show the directory @value{GDBN} searches for separate debugging
11185information files.
11186
11187@end table
11188
11189@cindex @code{.gnu_debuglink} sections
11190@cindex debug links
11191A debug link is a special section of the executable file named
11192@code{.gnu_debuglink}. The section must contain:
11193
11194@itemize
11195@item
11196A filename, with any leading directory components removed, followed by
11197a zero byte,
11198@item
11199zero to three bytes of padding, as needed to reach the next four-byte
11200boundary within the section, and
11201@item
11202a four-byte CRC checksum, stored in the same endianness used for the
11203executable file itself. The checksum is computed on the debugging
11204information file's full contents by the function given below, passing
11205zero as the @var{crc} argument.
11206@end itemize
11207
11208Any executable file format can carry a debug link, as long as it can
11209contain a section named @code{.gnu_debuglink} with the contents
11210described above.
11211
11212The debugging information file itself should be an ordinary
11213executable, containing a full set of linker symbols, sections, and
11214debugging information. The sections of the debugging information file
11215should have the same names, addresses and sizes as the original file,
11216but they need not contain any data --- much like a @code{.bss} section
11217in an ordinary executable.
11218
11219As of December 2002, there is no standard GNU utility to produce
11220separated executable / debugging information file pairs. Ulrich
11221Drepper's @file{elfutils} package, starting with version 0.53,
11222contains a version of the @code{strip} command such that the command
11223@kbd{strip foo -f foo.debug} removes the debugging information from
11224the executable file @file{foo}, places it in the file
11225@file{foo.debug}, and leaves behind a debug link in @file{foo}.
11226
11227Since there are many different ways to compute CRC's (different
11228polynomials, reversals, byte ordering, etc.), the simplest way to
11229describe the CRC used in @code{.gnu_debuglink} sections is to give the
11230complete code for a function that computes it:
11231
4644b6e3 11232@kindex gnu_debuglink_crc32
5b5d99cf
JB
11233@smallexample
11234unsigned long
11235gnu_debuglink_crc32 (unsigned long crc,
11236 unsigned char *buf, size_t len)
11237@{
11238 static const unsigned long crc32_table[256] =
11239 @{
11240 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11241 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11242 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11243 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11244 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11245 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11246 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11247 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11248 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11249 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11250 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11251 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11252 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11253 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11254 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11255 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11256 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11257 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11258 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11259 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11260 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11261 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11262 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11263 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11264 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11265 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11266 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11267 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11268 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11269 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11270 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11271 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11272 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11273 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11274 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11275 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11276 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11277 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11278 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11279 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11280 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11281 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11282 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11283 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11284 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11285 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11286 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11287 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11288 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11289 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11290 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11291 0x2d02ef8d
11292 @};
11293 unsigned char *end;
11294
11295 crc = ~crc & 0xffffffff;
11296 for (end = buf + len; buf < end; ++buf)
11297 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 11298 return ~crc & 0xffffffff;
5b5d99cf
JB
11299@}
11300@end smallexample
11301
11302
6d2ebf8b 11303@node Symbol Errors
c906108c
SS
11304@section Errors reading symbol files
11305
11306While reading a symbol file, @value{GDBN} occasionally encounters problems,
11307such as symbol types it does not recognize, or known bugs in compiler
11308output. By default, @value{GDBN} does not notify you of such problems, since
11309they are relatively common and primarily of interest to people
11310debugging compilers. If you are interested in seeing information
11311about ill-constructed symbol tables, you can either ask @value{GDBN} to print
11312only one message about each such type of problem, no matter how many
11313times the problem occurs; or you can ask @value{GDBN} to print more messages,
11314to see how many times the problems occur, with the @code{set
11315complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
11316messages}).
11317
11318The messages currently printed, and their meanings, include:
11319
11320@table @code
11321@item inner block not inside outer block in @var{symbol}
11322
11323The symbol information shows where symbol scopes begin and end
11324(such as at the start of a function or a block of statements). This
11325error indicates that an inner scope block is not fully contained
11326in its outer scope blocks.
11327
11328@value{GDBN} circumvents the problem by treating the inner block as if it had
11329the same scope as the outer block. In the error message, @var{symbol}
11330may be shown as ``@code{(don't know)}'' if the outer block is not a
11331function.
11332
11333@item block at @var{address} out of order
11334
11335The symbol information for symbol scope blocks should occur in
11336order of increasing addresses. This error indicates that it does not
11337do so.
11338
11339@value{GDBN} does not circumvent this problem, and has trouble
11340locating symbols in the source file whose symbols it is reading. (You
11341can often determine what source file is affected by specifying
11342@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
11343messages}.)
11344
11345@item bad block start address patched
11346
11347The symbol information for a symbol scope block has a start address
11348smaller than the address of the preceding source line. This is known
11349to occur in the SunOS 4.1.1 (and earlier) C compiler.
11350
11351@value{GDBN} circumvents the problem by treating the symbol scope block as
11352starting on the previous source line.
11353
11354@item bad string table offset in symbol @var{n}
11355
11356@cindex foo
11357Symbol number @var{n} contains a pointer into the string table which is
11358larger than the size of the string table.
11359
11360@value{GDBN} circumvents the problem by considering the symbol to have the
11361name @code{foo}, which may cause other problems if many symbols end up
11362with this name.
11363
11364@item unknown symbol type @code{0x@var{nn}}
11365
7a292a7a
SS
11366The symbol information contains new data types that @value{GDBN} does
11367not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 11368uncomprehended information, in hexadecimal.
c906108c 11369
7a292a7a
SS
11370@value{GDBN} circumvents the error by ignoring this symbol information.
11371This usually allows you to debug your program, though certain symbols
c906108c 11372are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
11373debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
11374on @code{complain}, then go up to the function @code{read_dbx_symtab}
11375and examine @code{*bufp} to see the symbol.
c906108c
SS
11376
11377@item stub type has NULL name
c906108c 11378
7a292a7a 11379@value{GDBN} could not find the full definition for a struct or class.
c906108c 11380
7a292a7a 11381@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 11382The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
11383information that recent versions of the compiler should have output for
11384it.
c906108c
SS
11385
11386@item info mismatch between compiler and debugger
11387
11388@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 11389
c906108c
SS
11390@end table
11391
6d2ebf8b 11392@node Targets
c906108c 11393@chapter Specifying a Debugging Target
7a292a7a 11394
c906108c 11395@cindex debugging target
c906108c 11396A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
11397
11398Often, @value{GDBN} runs in the same host environment as your program;
11399in that case, the debugging target is specified as a side effect when
11400you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
11401flexibility---for example, running @value{GDBN} on a physically separate
11402host, or controlling a standalone system over a serial port or a
53a5351d
JM
11403realtime system over a TCP/IP connection---you can use the @code{target}
11404command to specify one of the target types configured for @value{GDBN}
11405(@pxref{Target Commands, ,Commands for managing targets}).
c906108c 11406
a8f24a35
EZ
11407@cindex target architecture
11408It is possible to build @value{GDBN} for several different @dfn{target
11409architectures}. When @value{GDBN} is built like that, you can choose
11410one of the available architectures with the @kbd{set architecture}
11411command.
11412
11413@table @code
11414@kindex set architecture
11415@kindex show architecture
11416@item set architecture @var{arch}
11417This command sets the current target architecture to @var{arch}. The
11418value of @var{arch} can be @code{"auto"}, in addition to one of the
11419supported architectures.
11420
11421@item show architecture
11422Show the current target architecture.
9c16f35a
EZ
11423
11424@item set processor
11425@itemx processor
11426@kindex set processor
11427@kindex show processor
11428These are alias commands for, respectively, @code{set architecture}
11429and @code{show architecture}.
a8f24a35
EZ
11430@end table
11431
c906108c
SS
11432@menu
11433* Active Targets:: Active targets
11434* Target Commands:: Commands for managing targets
c906108c
SS
11435* Byte Order:: Choosing target byte order
11436* Remote:: Remote debugging
96baa820 11437* KOD:: Kernel Object Display
c906108c
SS
11438
11439@end menu
11440
6d2ebf8b 11441@node Active Targets
c906108c 11442@section Active targets
7a292a7a 11443
c906108c
SS
11444@cindex stacking targets
11445@cindex active targets
11446@cindex multiple targets
11447
c906108c 11448There are three classes of targets: processes, core files, and
7a292a7a
SS
11449executable files. @value{GDBN} can work concurrently on up to three
11450active targets, one in each class. This allows you to (for example)
11451start a process and inspect its activity without abandoning your work on
11452a core file.
c906108c
SS
11453
11454For example, if you execute @samp{gdb a.out}, then the executable file
11455@code{a.out} is the only active target. If you designate a core file as
11456well---presumably from a prior run that crashed and coredumped---then
11457@value{GDBN} has two active targets and uses them in tandem, looking
11458first in the corefile target, then in the executable file, to satisfy
11459requests for memory addresses. (Typically, these two classes of target
11460are complementary, since core files contain only a program's
11461read-write memory---variables and so on---plus machine status, while
11462executable files contain only the program text and initialized data.)
c906108c
SS
11463
11464When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
11465target as well. When a process target is active, all @value{GDBN}
11466commands requesting memory addresses refer to that target; addresses in
11467an active core file or executable file target are obscured while the
11468process target is active.
c906108c 11469
7a292a7a
SS
11470Use the @code{core-file} and @code{exec-file} commands to select a new
11471core file or executable target (@pxref{Files, ,Commands to specify
c906108c 11472files}). To specify as a target a process that is already running, use
7a292a7a
SS
11473the @code{attach} command (@pxref{Attach, ,Debugging an already-running
11474process}).
c906108c 11475
6d2ebf8b 11476@node Target Commands
c906108c
SS
11477@section Commands for managing targets
11478
11479@table @code
11480@item target @var{type} @var{parameters}
7a292a7a
SS
11481Connects the @value{GDBN} host environment to a target machine or
11482process. A target is typically a protocol for talking to debugging
11483facilities. You use the argument @var{type} to specify the type or
11484protocol of the target machine.
c906108c
SS
11485
11486Further @var{parameters} are interpreted by the target protocol, but
11487typically include things like device names or host names to connect
11488with, process numbers, and baud rates.
c906108c
SS
11489
11490The @code{target} command does not repeat if you press @key{RET} again
11491after executing the command.
11492
11493@kindex help target
11494@item help target
11495Displays the names of all targets available. To display targets
11496currently selected, use either @code{info target} or @code{info files}
11497(@pxref{Files, ,Commands to specify files}).
11498
11499@item help target @var{name}
11500Describe a particular target, including any parameters necessary to
11501select it.
11502
11503@kindex set gnutarget
11504@item set gnutarget @var{args}
5d161b24 11505@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 11506knows whether it is reading an @dfn{executable},
5d161b24
DB
11507a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
11508with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
11509with @code{gnutarget} the @code{target} refers to a program, not a machine.
11510
d4f3574e 11511@quotation
c906108c
SS
11512@emph{Warning:} To specify a file format with @code{set gnutarget},
11513you must know the actual BFD name.
d4f3574e 11514@end quotation
c906108c 11515
d4f3574e
SS
11516@noindent
11517@xref{Files, , Commands to specify files}.
c906108c 11518
5d161b24 11519@kindex show gnutarget
c906108c
SS
11520@item show gnutarget
11521Use the @code{show gnutarget} command to display what file format
11522@code{gnutarget} is set to read. If you have not set @code{gnutarget},
11523@value{GDBN} will determine the file format for each file automatically,
11524and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11525@end table
11526
4644b6e3 11527@cindex common targets
c906108c
SS
11528Here are some common targets (available, or not, depending on the GDB
11529configuration):
c906108c
SS
11530
11531@table @code
4644b6e3 11532@kindex target
c906108c 11533@item target exec @var{program}
4644b6e3 11534@cindex executable file target
c906108c
SS
11535An executable file. @samp{target exec @var{program}} is the same as
11536@samp{exec-file @var{program}}.
11537
c906108c 11538@item target core @var{filename}
4644b6e3 11539@cindex core dump file target
c906108c
SS
11540A core dump file. @samp{target core @var{filename}} is the same as
11541@samp{core-file @var{filename}}.
c906108c 11542
c906108c 11543@item target remote @var{dev}
4644b6e3 11544@cindex remote target
c906108c
SS
11545Remote serial target in GDB-specific protocol. The argument @var{dev}
11546specifies what serial device to use for the connection (e.g.
11547@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 11548supports the @code{load} command. This is only useful if you have
c906108c
SS
11549some other way of getting the stub to the target system, and you can put
11550it somewhere in memory where it won't get clobbered by the download.
11551
c906108c 11552@item target sim
4644b6e3 11553@cindex built-in simulator target
2df3850c 11554Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 11555In general,
474c8240 11556@smallexample
104c1213
JM
11557 target sim
11558 load
11559 run
474c8240 11560@end smallexample
d4f3574e 11561@noindent
104c1213 11562works; however, you cannot assume that a specific memory map, device
d4f3574e 11563drivers, or even basic I/O is available, although some simulators do
104c1213
JM
11564provide these. For info about any processor-specific simulator details,
11565see the appropriate section in @ref{Embedded Processors, ,Embedded
11566Processors}.
11567
c906108c
SS
11568@end table
11569
104c1213 11570Some configurations may include these targets as well:
c906108c
SS
11571
11572@table @code
11573
c906108c 11574@item target nrom @var{dev}
4644b6e3 11575@cindex NetROM ROM emulator target
c906108c
SS
11576NetROM ROM emulator. This target only supports downloading.
11577
c906108c
SS
11578@end table
11579
5d161b24 11580Different targets are available on different configurations of @value{GDBN};
c906108c 11581your configuration may have more or fewer targets.
c906108c 11582
721c2651
EZ
11583Many remote targets require you to download the executable's code once
11584you've successfully established a connection. You may wish to control
11585various aspects of this process, such as the size of the data chunks
11586used by @value{GDBN} to download program parts to the remote target.
a8f24a35
EZ
11587
11588@table @code
11589@kindex set download-write-size
11590@item set download-write-size @var{size}
11591Set the write size used when downloading a program. Only used when
11592downloading a program onto a remote target. Specify zero or a
11593negative value to disable blocked writes. The actual size of each
11594transfer is also limited by the size of the target packet and the
11595memory cache.
11596
11597@kindex show download-write-size
11598@item show download-write-size
721c2651 11599@kindex show download-write-size
a8f24a35 11600Show the current value of the write size.
721c2651
EZ
11601
11602@item set hash
11603@kindex set hash@r{, for remote monitors}
11604@cindex hash mark while downloading
11605This command controls whether a hash mark @samp{#} is displayed while
11606downloading a file to the remote monitor. If on, a hash mark is
11607displayed after each S-record is successfully downloaded to the
11608monitor.
11609
11610@item show hash
11611@kindex show hash@r{, for remote monitors}
11612Show the current status of displaying the hash mark.
11613
11614@item set debug monitor
11615@kindex set debug monitor
11616@cindex display remote monitor communications
11617Enable or disable display of communications messages between
11618@value{GDBN} and the remote monitor.
11619
11620@item show debug monitor
11621@kindex show debug monitor
11622Show the current status of displaying communications between
11623@value{GDBN} and the remote monitor.
a8f24a35 11624@end table
c906108c
SS
11625
11626@table @code
11627
11628@kindex load @var{filename}
11629@item load @var{filename}
c906108c
SS
11630Depending on what remote debugging facilities are configured into
11631@value{GDBN}, the @code{load} command may be available. Where it exists, it
11632is meant to make @var{filename} (an executable) available for debugging
11633on the remote system---by downloading, or dynamic linking, for example.
11634@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
11635the @code{add-symbol-file} command.
11636
11637If your @value{GDBN} does not have a @code{load} command, attempting to
11638execute it gets the error message ``@code{You can't do that when your
11639target is @dots{}}''
c906108c
SS
11640
11641The file is loaded at whatever address is specified in the executable.
11642For some object file formats, you can specify the load address when you
11643link the program; for other formats, like a.out, the object file format
11644specifies a fixed address.
11645@c FIXME! This would be a good place for an xref to the GNU linker doc.
11646
c906108c
SS
11647@code{load} does not repeat if you press @key{RET} again after using it.
11648@end table
11649
6d2ebf8b 11650@node Byte Order
c906108c 11651@section Choosing target byte order
7a292a7a 11652
c906108c
SS
11653@cindex choosing target byte order
11654@cindex target byte order
c906108c 11655
172c2a43 11656Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
11657offer the ability to run either big-endian or little-endian byte
11658orders. Usually the executable or symbol will include a bit to
11659designate the endian-ness, and you will not need to worry about
11660which to use. However, you may still find it useful to adjust
d4f3574e 11661@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
11662
11663@table @code
4644b6e3 11664@kindex set endian
c906108c
SS
11665@item set endian big
11666Instruct @value{GDBN} to assume the target is big-endian.
11667
c906108c
SS
11668@item set endian little
11669Instruct @value{GDBN} to assume the target is little-endian.
11670
c906108c
SS
11671@item set endian auto
11672Instruct @value{GDBN} to use the byte order associated with the
11673executable.
11674
11675@item show endian
11676Display @value{GDBN}'s current idea of the target byte order.
11677
11678@end table
11679
11680Note that these commands merely adjust interpretation of symbolic
11681data on the host, and that they have absolutely no effect on the
11682target system.
11683
6d2ebf8b 11684@node Remote
c906108c
SS
11685@section Remote debugging
11686@cindex remote debugging
11687
11688If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
11689@value{GDBN} in the usual way, it is often useful to use remote debugging.
11690For example, you might use remote debugging on an operating system kernel,
c906108c
SS
11691or on a small system which does not have a general purpose operating system
11692powerful enough to run a full-featured debugger.
11693
11694Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
11695to make this work with particular debugging targets. In addition,
5d161b24 11696@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
11697but not specific to any particular target system) which you can use if you
11698write the remote stubs---the code that runs on the remote system to
11699communicate with @value{GDBN}.
11700
11701Other remote targets may be available in your
11702configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 11703
c45da7e6
EZ
11704Once you've connected to the remote target, @value{GDBN} allows you to
11705send arbitrary commands to the remote monitor:
11706
11707@table @code
11708@item remote @var{command}
11709@kindex remote@r{, a command}
11710@cindex send command to remote monitor
11711Send an arbitrary @var{command} string to the remote monitor.
11712@end table
11713
11714
6f05cf9f
AC
11715@node KOD
11716@section Kernel Object Display
6f05cf9f 11717@cindex kernel object display
6f05cf9f
AC
11718@cindex KOD
11719
11720Some targets support kernel object display. Using this facility,
11721@value{GDBN} communicates specially with the underlying operating system
11722and can display information about operating system-level objects such as
11723mutexes and other synchronization objects. Exactly which objects can be
11724displayed is determined on a per-OS basis.
11725
3bbe9696 11726@kindex set os
6f05cf9f
AC
11727Use the @code{set os} command to set the operating system. This tells
11728@value{GDBN} which kernel object display module to initialize:
11729
474c8240 11730@smallexample
6f05cf9f 11731(@value{GDBP}) set os cisco
474c8240 11732@end smallexample
6f05cf9f 11733
3bbe9696
EZ
11734@kindex show os
11735The associated command @code{show os} displays the operating system
11736set with the @code{set os} command; if no operating system has been
11737set, @code{show os} will display an empty string @samp{""}.
11738
6f05cf9f
AC
11739If @code{set os} succeeds, @value{GDBN} will display some information
11740about the operating system, and will create a new @code{info} command
11741which can be used to query the target. The @code{info} command is named
11742after the operating system:
c906108c 11743
3bbe9696 11744@kindex info cisco
474c8240 11745@smallexample
6f05cf9f
AC
11746(@value{GDBP}) info cisco
11747List of Cisco Kernel Objects
11748Object Description
11749any Any and all objects
474c8240 11750@end smallexample
6f05cf9f
AC
11751
11752Further subcommands can be used to query about particular objects known
11753by the kernel.
11754
3bbe9696
EZ
11755There is currently no way to determine whether a given operating
11756system is supported other than to try setting it with @kbd{set os
11757@var{name}}, where @var{name} is the name of the operating system you
11758want to try.
6f05cf9f
AC
11759
11760
11761@node Remote Debugging
11762@chapter Debugging remote programs
11763
6b2f586d 11764@menu
07f31aa6 11765* Connecting:: Connecting to a remote target
6b2f586d
AC
11766* Server:: Using the gdbserver program
11767* NetWare:: Using the gdbserve.nlm program
501eef12 11768* Remote configuration:: Remote configuration
6b2f586d 11769* remote stub:: Implementing a remote stub
6b2f586d
AC
11770@end menu
11771
07f31aa6
DJ
11772@node Connecting
11773@section Connecting to a remote target
11774
11775On the @value{GDBN} host machine, you will need an unstripped copy of
11776your program, since @value{GDBN} needs symobl and debugging information.
11777Start up @value{GDBN} as usual, using the name of the local copy of your
11778program as the first argument.
11779
11780@cindex serial line, @code{target remote}
11781If you're using a serial line, you may want to give @value{GDBN} the
11782@w{@samp{--baud}} option, or use the @code{set remotebaud} command
9c16f35a
EZ
11783(@pxref{Remote configuration, set remotebaud}) before the
11784@code{target} command.
07f31aa6
DJ
11785
11786After that, use @code{target remote} to establish communications with
11787the target machine. Its argument specifies how to communicate---either
11788via a devicename attached to a direct serial line, or a TCP or UDP port
11789(possibly to a terminal server which in turn has a serial line to the
11790target). For example, to use a serial line connected to the device
11791named @file{/dev/ttyb}:
11792
11793@smallexample
11794target remote /dev/ttyb
11795@end smallexample
11796
11797@cindex TCP port, @code{target remote}
11798To use a TCP connection, use an argument of the form
11799@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
11800For example, to connect to port 2828 on a
11801terminal server named @code{manyfarms}:
11802
11803@smallexample
11804target remote manyfarms:2828
11805@end smallexample
11806
11807If your remote target is actually running on the same machine as
11808your debugger session (e.g.@: a simulator of your target running on
11809the same host), you can omit the hostname. For example, to connect
11810to port 1234 on your local machine:
11811
11812@smallexample
11813target remote :1234
11814@end smallexample
11815@noindent
11816
11817Note that the colon is still required here.
11818
11819@cindex UDP port, @code{target remote}
11820To use a UDP connection, use an argument of the form
11821@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
11822on a terminal server named @code{manyfarms}:
11823
11824@smallexample
11825target remote udp:manyfarms:2828
11826@end smallexample
11827
11828When using a UDP connection for remote debugging, you should keep in mind
11829that the `U' stands for ``Unreliable''. UDP can silently drop packets on
11830busy or unreliable networks, which will cause havoc with your debugging
11831session.
11832
11833Now you can use all the usual commands to examine and change data and to
11834step and continue the remote program.
11835
11836@cindex interrupting remote programs
11837@cindex remote programs, interrupting
11838Whenever @value{GDBN} is waiting for the remote program, if you type the
11839interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
11840program. This may or may not succeed, depending in part on the hardware
11841and the serial drivers the remote system uses. If you type the
11842interrupt character once again, @value{GDBN} displays this prompt:
11843
11844@smallexample
11845Interrupted while waiting for the program.
11846Give up (and stop debugging it)? (y or n)
11847@end smallexample
11848
11849If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
11850(If you decide you want to try again later, you can use @samp{target
11851remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
11852goes back to waiting.
11853
11854@table @code
11855@kindex detach (remote)
11856@item detach
11857When you have finished debugging the remote program, you can use the
11858@code{detach} command to release it from @value{GDBN} control.
11859Detaching from the target normally resumes its execution, but the results
11860will depend on your particular remote stub. After the @code{detach}
11861command, @value{GDBN} is free to connect to another target.
11862
11863@kindex disconnect
11864@item disconnect
11865The @code{disconnect} command behaves like @code{detach}, except that
11866the target is generally not resumed. It will wait for @value{GDBN}
11867(this instance or another one) to connect and continue debugging. After
11868the @code{disconnect} command, @value{GDBN} is again free to connect to
11869another target.
09d4efe1
EZ
11870
11871@cindex send command to remote monitor
11872@kindex monitor
11873@item monitor @var{cmd}
11874This command allows you to send commands directly to the remote
11875monitor.
07f31aa6
DJ
11876@end table
11877
6f05cf9f
AC
11878@node Server
11879@section Using the @code{gdbserver} program
11880
11881@kindex gdbserver
11882@cindex remote connection without stubs
11883@code{gdbserver} is a control program for Unix-like systems, which
11884allows you to connect your program with a remote @value{GDBN} via
11885@code{target remote}---but without linking in the usual debugging stub.
11886
11887@code{gdbserver} is not a complete replacement for the debugging stubs,
11888because it requires essentially the same operating-system facilities
11889that @value{GDBN} itself does. In fact, a system that can run
11890@code{gdbserver} to connect to a remote @value{GDBN} could also run
11891@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
11892because it is a much smaller program than @value{GDBN} itself. It is
11893also easier to port than all of @value{GDBN}, so you may be able to get
11894started more quickly on a new system by using @code{gdbserver}.
11895Finally, if you develop code for real-time systems, you may find that
11896the tradeoffs involved in real-time operation make it more convenient to
11897do as much development work as possible on another system, for example
11898by cross-compiling. You can use @code{gdbserver} to make a similar
11899choice for debugging.
11900
11901@value{GDBN} and @code{gdbserver} communicate via either a serial line
11902or a TCP connection, using the standard @value{GDBN} remote serial
11903protocol.
11904
11905@table @emph
11906@item On the target machine,
11907you need to have a copy of the program you want to debug.
11908@code{gdbserver} does not need your program's symbol table, so you can
11909strip the program if necessary to save space. @value{GDBN} on the host
11910system does all the symbol handling.
11911
11912To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 11913the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
11914syntax is:
11915
11916@smallexample
11917target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
11918@end smallexample
11919
11920@var{comm} is either a device name (to use a serial line) or a TCP
11921hostname and portnumber. For example, to debug Emacs with the argument
11922@samp{foo.txt} and communicate with @value{GDBN} over the serial port
11923@file{/dev/com1}:
11924
11925@smallexample
11926target> gdbserver /dev/com1 emacs foo.txt
11927@end smallexample
11928
11929@code{gdbserver} waits passively for the host @value{GDBN} to communicate
11930with it.
11931
11932To use a TCP connection instead of a serial line:
11933
11934@smallexample
11935target> gdbserver host:2345 emacs foo.txt
11936@end smallexample
11937
11938The only difference from the previous example is the first argument,
11939specifying that you are communicating with the host @value{GDBN} via
11940TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
11941expect a TCP connection from machine @samp{host} to local TCP port 2345.
11942(Currently, the @samp{host} part is ignored.) You can choose any number
11943you want for the port number as long as it does not conflict with any
11944TCP ports already in use on the target system (for example, @code{23} is
11945reserved for @code{telnet}).@footnote{If you choose a port number that
11946conflicts with another service, @code{gdbserver} prints an error message
11947and exits.} You must use the same port number with the host @value{GDBN}
11948@code{target remote} command.
11949
56460a61
DJ
11950On some targets, @code{gdbserver} can also attach to running programs.
11951This is accomplished via the @code{--attach} argument. The syntax is:
11952
11953@smallexample
11954target> gdbserver @var{comm} --attach @var{pid}
11955@end smallexample
11956
11957@var{pid} is the process ID of a currently running process. It isn't necessary
11958to point @code{gdbserver} at a binary for the running process.
11959
b1fe9455
DJ
11960@pindex pidof
11961@cindex attach to a program by name
11962You can debug processes by name instead of process ID if your target has the
11963@code{pidof} utility:
11964
11965@smallexample
11966target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
11967@end smallexample
11968
11969In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
11970has multiple threads, most versions of @code{pidof} support the
11971@code{-s} option to only return the first process ID.
11972
07f31aa6
DJ
11973@item On the host machine,
11974connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
11975For TCP connections, you must start up @code{gdbserver} prior to using
11976the @code{target remote} command. Otherwise you may get an error whose
11977text depends on the host system, but which usually looks something like
07f31aa6 11978@samp{Connection refused}. You don't need to use the @code{load}
397ca115
EZ
11979command in @value{GDBN} when using @code{gdbserver}, since the program is
11980already on the target. However, if you want to load the symbols (as
11981you normally would), do that with the @code{file} command, and issue
11982it @emph{before} connecting to the server; otherwise, you will get an
11983error message saying @code{"Program is already running"}, since the
11984program is considered running after the connection.
07f31aa6 11985
6f05cf9f
AC
11986@end table
11987
11988@node NetWare
11989@section Using the @code{gdbserve.nlm} program
11990
11991@kindex gdbserve.nlm
11992@code{gdbserve.nlm} is a control program for NetWare systems, which
11993allows you to connect your program with a remote @value{GDBN} via
11994@code{target remote}.
11995
11996@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
11997using the standard @value{GDBN} remote serial protocol.
11998
11999@table @emph
12000@item On the target machine,
12001you need to have a copy of the program you want to debug.
12002@code{gdbserve.nlm} does not need your program's symbol table, so you
12003can strip the program if necessary to save space. @value{GDBN} on the
12004host system does all the symbol handling.
12005
12006To use the server, you must tell it how to communicate with
12007@value{GDBN}; the name of your program; and the arguments for your
12008program. The syntax is:
12009
12010@smallexample
12011load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
12012 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
12013@end smallexample
12014
12015@var{board} and @var{port} specify the serial line; @var{baud} specifies
12016the baud rate used by the connection. @var{port} and @var{node} default
12017to 0, @var{baud} defaults to 9600@dmn{bps}.
12018
12019For example, to debug Emacs with the argument @samp{foo.txt}and
12020communicate with @value{GDBN} over serial port number 2 or board 1
12021using a 19200@dmn{bps} connection:
12022
12023@smallexample
12024load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
12025@end smallexample
12026
07f31aa6
DJ
12027@item
12028On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
12029Connecting to a remote target}).
6f05cf9f 12030
6f05cf9f
AC
12031@end table
12032
501eef12
AC
12033@node Remote configuration
12034@section Remote configuration
12035
9c16f35a
EZ
12036@kindex set remote
12037@kindex show remote
12038This section documents the configuration options available when
12039debugging remote programs. For the options related to the File I/O
12040extensions of the remote protocol, see @ref{The system call,
12041system-call-allowed}.
501eef12
AC
12042
12043@table @code
9c16f35a
EZ
12044@item set remoteaddresssize @var{bits}
12045@cindex adress size for remote targets
12046@cindex bits in remote address
12047Set the maximum size of address in a memory packet to the specified
12048number of bits. @value{GDBN} will mask off the address bits above
12049that number, when it passes addresses to the remote target. The
12050default value is the number of bits in the target's address.
12051
12052@item show remoteaddresssize
12053Show the current value of remote address size in bits.
12054
12055@item set remotebaud @var{n}
12056@cindex baud rate for remote targets
12057Set the baud rate for the remote serial I/O to @var{n} baud. The
12058value is used to set the speed of the serial port used for debugging
12059remote targets.
12060
12061@item show remotebaud
12062Show the current speed of the remote connection.
12063
12064@item set remotebreak
12065@cindex interrupt remote programs
12066@cindex BREAK signal instead of Ctrl-C
12067If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
12068when you press the @key{Ctrl-C} key to interrupt the program running
12069on the remote. If set to off, @value{GDBN} sends the @samp{Strl-C}
12070character instead. The default is off, since most remote systems
12071expect to see @samp{Ctrl-C} as the interrupt signal.
12072
12073@item show remotebreak
12074Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
12075interrupt the remote program.
12076
12077@item set remotedebug
12078@cindex debug remote protocol
12079@cindex remote protocol debugging
12080@cindex display remote packets
12081Control the debugging of the remote protocol. When enabled, each
12082packet sent to or received from the remote target is displayed. The
12083defaults is off.
12084
12085@item show remotedebug
12086Show the current setting of the remote protocol debugging.
12087
12088@item set remotedevice @var{device}
12089@cindex serial port name
12090Set the name of the serial port through which to communicate to the
12091remote target to @var{device}. This is the device used by
12092@value{GDBN} to open the serial communications line to the remote
12093target. There's no default, so you must set a valid port name for the
12094remote serial communications to work. (Some varieties of the
12095@code{target} command accept the port name as part of their
12096arguments.)
12097
12098@item show remotedevice
12099Show the current name of the serial port.
12100
12101@item set remotelogbase @var{base}
12102Set the base (a.k.a.@: radix) of logging serial protocol
12103communications to @var{base}. Supported values of @var{base} are:
12104@code{ascii}, @code{octal}, and @code{hex}. The default is
12105@code{ascii}.
12106
12107@item show remotelogbase
12108Show the current setting of the radix for logging remote serial
12109protocol.
12110
12111@item set remotelogfile @var{file}
12112@cindex record serial communications on file
12113Record remote serial communications on the named @var{file}. The
12114default is not to record at all.
12115
12116@item show remotelogfile.
12117Show the current setting of the file name on which to record the
12118serial communications.
12119
12120@item set remotetimeout @var{num}
12121@cindex timeout for serial communications
12122@cindex remote timeout
12123Set the timeout limit to wait for the remote target to respond to
12124@var{num} seconds. The default is 2 seconds.
12125
12126@item show remotetimeout
12127Show the current number of seconds to wait for the remote target
12128responses.
12129
12130@cindex limit hardware breakpoints and watchpoints
12131@cindex remote target, limit break- and watchpoints
501eef12
AC
12132@anchor{set remote hardware-watchpoint-limit}
12133@anchor{set remote hardware-breakpoint-limit}
12134@item set remote hardware-watchpoint-limit @var{limit}
12135@itemx set remote hardware-breakpoint-limit @var{limit}
12136Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
12137watchpoints. A limit of -1, the default, is treated as unlimited.
9c16f35a
EZ
12138
12139@item set remote fetch-register-packet
12140@itemx set remote set-register-packet
12141@itemx set remote P-packet
12142@itemx set remote p-packet
12143@cindex P-packet
12144@cindex fetch registers from remote targets
12145@cindex set registers in remote targets
12146Determine whether @value{GDBN} can set and fetch registers from the
12147remote target using the @samp{P} packets. The default depends on the
12148remote stub's support of the @samp{P} packets (@value{GDBN} queries
12149the stub when this packet is first required).
12150
12151@item show remote fetch-register-packet
12152@itemx show remote set-register-packet
12153@itemx show remote P-packet
12154@itemx show remote p-packet
12155Show the current setting of using the @samp{P} packets for setting and
12156fetching registers from the remote target.
12157
12158@cindex binary downloads
12159@cindex X-packet
12160@item set remote binary-download-packet
12161@itemx set remote X-packet
12162Determine whether @value{GDBN} sends downloads in binary mode using
12163the @samp{X} packets. The default is on.
12164
12165@item show remote binary-download-packet
12166@itemx show remote X-packet
12167Show the current setting of using the @samp{X} packets for binary
12168downloads.
12169
12170@item set remote read-aux-vector-packet
12171@cindex auxiliary vector of remote target
12172@cindex @code{auxv}, and remote targets
12173Set the use of the remote protocol's @samp{qPart:auxv:read} (target
12174auxiliary vector read) request. This request is used to fetch the
721c2651
EZ
12175remote target's @dfn{auxiliary vector}, see @ref{OS Information,
12176Auxiliary Vector}. The default setting depends on the remote stub's
12177support of this request (@value{GDBN} queries the stub when this
12178request is first required). @xref{General Query Packets, qPart}, for
12179more information about this request.
9c16f35a
EZ
12180
12181@item show remote read-aux-vector-packet
12182Show the current setting of use of the @samp{qPart:auxv:read} request.
12183
12184@item set remote symbol-lookup-packet
12185@cindex remote symbol lookup request
12186Set the use of the remote protocol's @samp{qSymbol} (target symbol
12187lookup) request. This request is used to communicate symbol
12188information to the remote target, e.g., whenever a new shared library
12189is loaded by the remote (@pxref{Files, shared libraries}). The
12190default setting depends on the remote stub's support of this request
12191(@value{GDBN} queries the stub when this request is first required).
12192@xref{General Query Packets, qSymbol}, for more information about this
12193request.
12194
12195@item show remote symbol-lookup-packet
12196Show the current setting of use of the @samp{qSymbol} request.
12197
12198@item set remote verbose-resume-packet
12199@cindex resume remote target
12200@cindex signal thread, and remote targets
12201@cindex single-step thread, and remote targets
12202@cindex thread-specific operations on remote targets
12203Set the use of the remote protocol's @samp{vCont} (descriptive resume)
12204request. This request is used to resume specific threads in the
12205remote target, and to single-step or signal them. The default setting
12206depends on the remote stub's support of this request (@value{GDBN}
12207queries the stub when this request is first required). This setting
12208affects debugging of multithreaded programs: if @samp{vCont} cannot be
12209used, @value{GDBN} might be unable to single-step a specific thread,
12210especially under @code{set scheduler-locking off}; it is also
12211impossible to pause a specific thread. @xref{Packets, vCont}, for
12212more details.
12213
12214@item show remote verbose-resume-packet
12215Show the current setting of use of the @samp{vCont} request
12216
12217@item set remote software-breakpoint-packet
12218@itemx set remote hardware-breakpoint-packet
12219@itemx set remote write-watchpoint-packet
12220@itemx set remote read-watchpoint-packet
12221@itemx set remote access-watchpoint-packet
12222@itemx set remote Z-packet
12223@cindex Z-packet
12224@cindex remote hardware breakpoints and watchpoints
12225These commands enable or disable the use of @samp{Z} packets for
12226setting breakpoints and watchpoints in the remote target. The default
12227depends on the remote stub's support of the @samp{Z} packets
12228(@value{GDBN} queries the stub when each packet is first required).
12229The command @code{set remote Z-packet}, kept for back-compatibility,
12230turns on or off all the features that require the use of @samp{Z}
12231packets.
12232
12233@item show remote software-breakpoint-packet
12234@itemx show remote hardware-breakpoint-packet
12235@itemx show remote write-watchpoint-packet
12236@itemx show remote read-watchpoint-packet
12237@itemx show remote access-watchpoint-packet
12238@itemx show remote Z-packet
12239Show the current setting of @samp{Z} packets usage.
0abb7bc7
EZ
12240
12241@item set remote get-thread-local-storage-address
12242@kindex set remote get-thread-local-storage-address
12243@cindex thread local storage of remote targets
12244This command enables or disables the use of the @samp{qGetTLSAddr}
12245(Get Thread Local Storage Address) request packet. The default
12246depends on whether the remote stub supports this request.
12247@xref{General Query Packets, qGetTLSAddr}, for more details about this
12248packet.
12249
12250@item show remote get-thread-local-storage-address
12251@kindex show remote get-thread-local-storage-address
12252Show the current setting of @samp{qGetTLSAddr} packet usage.
501eef12
AC
12253@end table
12254
6f05cf9f
AC
12255@node remote stub
12256@section Implementing a remote stub
7a292a7a 12257
8e04817f
AC
12258@cindex debugging stub, example
12259@cindex remote stub, example
12260@cindex stub example, remote debugging
12261The stub files provided with @value{GDBN} implement the target side of the
12262communication protocol, and the @value{GDBN} side is implemented in the
12263@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
12264these subroutines to communicate, and ignore the details. (If you're
12265implementing your own stub file, you can still ignore the details: start
12266with one of the existing stub files. @file{sparc-stub.c} is the best
12267organized, and therefore the easiest to read.)
12268
104c1213
JM
12269@cindex remote serial debugging, overview
12270To debug a program running on another machine (the debugging
12271@dfn{target} machine), you must first arrange for all the usual
12272prerequisites for the program to run by itself. For example, for a C
12273program, you need:
c906108c 12274
104c1213
JM
12275@enumerate
12276@item
12277A startup routine to set up the C runtime environment; these usually
12278have a name like @file{crt0}. The startup routine may be supplied by
12279your hardware supplier, or you may have to write your own.
96baa820 12280
5d161b24 12281@item
d4f3574e 12282A C subroutine library to support your program's
104c1213 12283subroutine calls, notably managing input and output.
96baa820 12284
104c1213
JM
12285@item
12286A way of getting your program to the other machine---for example, a
12287download program. These are often supplied by the hardware
12288manufacturer, but you may have to write your own from hardware
12289documentation.
12290@end enumerate
96baa820 12291
104c1213
JM
12292The next step is to arrange for your program to use a serial port to
12293communicate with the machine where @value{GDBN} is running (the @dfn{host}
12294machine). In general terms, the scheme looks like this:
96baa820 12295
104c1213
JM
12296@table @emph
12297@item On the host,
12298@value{GDBN} already understands how to use this protocol; when everything
12299else is set up, you can simply use the @samp{target remote} command
12300(@pxref{Targets,,Specifying a Debugging Target}).
12301
12302@item On the target,
12303you must link with your program a few special-purpose subroutines that
12304implement the @value{GDBN} remote serial protocol. The file containing these
12305subroutines is called a @dfn{debugging stub}.
12306
12307On certain remote targets, you can use an auxiliary program
12308@code{gdbserver} instead of linking a stub into your program.
12309@xref{Server,,Using the @code{gdbserver} program}, for details.
12310@end table
96baa820 12311
104c1213
JM
12312The debugging stub is specific to the architecture of the remote
12313machine; for example, use @file{sparc-stub.c} to debug programs on
12314@sc{sparc} boards.
96baa820 12315
104c1213
JM
12316@cindex remote serial stub list
12317These working remote stubs are distributed with @value{GDBN}:
96baa820 12318
104c1213
JM
12319@table @code
12320
12321@item i386-stub.c
41afff9a 12322@cindex @file{i386-stub.c}
104c1213
JM
12323@cindex Intel
12324@cindex i386
12325For Intel 386 and compatible architectures.
12326
12327@item m68k-stub.c
41afff9a 12328@cindex @file{m68k-stub.c}
104c1213
JM
12329@cindex Motorola 680x0
12330@cindex m680x0
12331For Motorola 680x0 architectures.
12332
12333@item sh-stub.c
41afff9a 12334@cindex @file{sh-stub.c}
172c2a43 12335@cindex Renesas
104c1213 12336@cindex SH
172c2a43 12337For Renesas SH architectures.
104c1213
JM
12338
12339@item sparc-stub.c
41afff9a 12340@cindex @file{sparc-stub.c}
104c1213
JM
12341@cindex Sparc
12342For @sc{sparc} architectures.
12343
12344@item sparcl-stub.c
41afff9a 12345@cindex @file{sparcl-stub.c}
104c1213
JM
12346@cindex Fujitsu
12347@cindex SparcLite
12348For Fujitsu @sc{sparclite} architectures.
12349
12350@end table
12351
12352The @file{README} file in the @value{GDBN} distribution may list other
12353recently added stubs.
12354
12355@menu
12356* Stub Contents:: What the stub can do for you
12357* Bootstrapping:: What you must do for the stub
12358* Debug Session:: Putting it all together
104c1213
JM
12359@end menu
12360
6d2ebf8b 12361@node Stub Contents
6f05cf9f 12362@subsection What the stub can do for you
104c1213
JM
12363
12364@cindex remote serial stub
12365The debugging stub for your architecture supplies these three
12366subroutines:
12367
12368@table @code
12369@item set_debug_traps
4644b6e3 12370@findex set_debug_traps
104c1213
JM
12371@cindex remote serial stub, initialization
12372This routine arranges for @code{handle_exception} to run when your
12373program stops. You must call this subroutine explicitly near the
12374beginning of your program.
12375
12376@item handle_exception
4644b6e3 12377@findex handle_exception
104c1213
JM
12378@cindex remote serial stub, main routine
12379This is the central workhorse, but your program never calls it
12380explicitly---the setup code arranges for @code{handle_exception} to
12381run when a trap is triggered.
12382
12383@code{handle_exception} takes control when your program stops during
12384execution (for example, on a breakpoint), and mediates communications
12385with @value{GDBN} on the host machine. This is where the communications
12386protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 12387representative on the target machine. It begins by sending summary
104c1213
JM
12388information on the state of your program, then continues to execute,
12389retrieving and transmitting any information @value{GDBN} needs, until you
12390execute a @value{GDBN} command that makes your program resume; at that point,
12391@code{handle_exception} returns control to your own code on the target
5d161b24 12392machine.
104c1213
JM
12393
12394@item breakpoint
12395@cindex @code{breakpoint} subroutine, remote
12396Use this auxiliary subroutine to make your program contain a
12397breakpoint. Depending on the particular situation, this may be the only
12398way for @value{GDBN} to get control. For instance, if your target
12399machine has some sort of interrupt button, you won't need to call this;
12400pressing the interrupt button transfers control to
12401@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
12402simply receiving characters on the serial port may also trigger a trap;
12403again, in that situation, you don't need to call @code{breakpoint} from
12404your own program---simply running @samp{target remote} from the host
5d161b24 12405@value{GDBN} session gets control.
104c1213
JM
12406
12407Call @code{breakpoint} if none of these is true, or if you simply want
12408to make certain your program stops at a predetermined point for the
12409start of your debugging session.
12410@end table
12411
6d2ebf8b 12412@node Bootstrapping
6f05cf9f 12413@subsection What you must do for the stub
104c1213
JM
12414
12415@cindex remote stub, support routines
12416The debugging stubs that come with @value{GDBN} are set up for a particular
12417chip architecture, but they have no information about the rest of your
12418debugging target machine.
12419
12420First of all you need to tell the stub how to communicate with the
12421serial port.
12422
12423@table @code
12424@item int getDebugChar()
4644b6e3 12425@findex getDebugChar
104c1213
JM
12426Write this subroutine to read a single character from the serial port.
12427It may be identical to @code{getchar} for your target system; a
12428different name is used to allow you to distinguish the two if you wish.
12429
12430@item void putDebugChar(int)
4644b6e3 12431@findex putDebugChar
104c1213 12432Write this subroutine to write a single character to the serial port.
5d161b24 12433It may be identical to @code{putchar} for your target system; a
104c1213
JM
12434different name is used to allow you to distinguish the two if you wish.
12435@end table
12436
12437@cindex control C, and remote debugging
12438@cindex interrupting remote targets
12439If you want @value{GDBN} to be able to stop your program while it is
12440running, you need to use an interrupt-driven serial driver, and arrange
12441for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
12442character). That is the character which @value{GDBN} uses to tell the
12443remote system to stop.
12444
12445Getting the debugging target to return the proper status to @value{GDBN}
12446probably requires changes to the standard stub; one quick and dirty way
12447is to just execute a breakpoint instruction (the ``dirty'' part is that
12448@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
12449
12450Other routines you need to supply are:
12451
12452@table @code
12453@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 12454@findex exceptionHandler
104c1213
JM
12455Write this function to install @var{exception_address} in the exception
12456handling tables. You need to do this because the stub does not have any
12457way of knowing what the exception handling tables on your target system
12458are like (for example, the processor's table might be in @sc{rom},
12459containing entries which point to a table in @sc{ram}).
12460@var{exception_number} is the exception number which should be changed;
12461its meaning is architecture-dependent (for example, different numbers
12462might represent divide by zero, misaligned access, etc). When this
12463exception occurs, control should be transferred directly to
12464@var{exception_address}, and the processor state (stack, registers,
12465and so on) should be just as it is when a processor exception occurs. So if
12466you want to use a jump instruction to reach @var{exception_address}, it
12467should be a simple jump, not a jump to subroutine.
12468
12469For the 386, @var{exception_address} should be installed as an interrupt
12470gate so that interrupts are masked while the handler runs. The gate
12471should be at privilege level 0 (the most privileged level). The
12472@sc{sparc} and 68k stubs are able to mask interrupts themselves without
12473help from @code{exceptionHandler}.
12474
12475@item void flush_i_cache()
4644b6e3 12476@findex flush_i_cache
d4f3574e 12477On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
12478instruction cache, if any, on your target machine. If there is no
12479instruction cache, this subroutine may be a no-op.
12480
12481On target machines that have instruction caches, @value{GDBN} requires this
12482function to make certain that the state of your program is stable.
12483@end table
12484
12485@noindent
12486You must also make sure this library routine is available:
12487
12488@table @code
12489@item void *memset(void *, int, int)
4644b6e3 12490@findex memset
104c1213
JM
12491This is the standard library function @code{memset} that sets an area of
12492memory to a known value. If you have one of the free versions of
12493@code{libc.a}, @code{memset} can be found there; otherwise, you must
12494either obtain it from your hardware manufacturer, or write your own.
12495@end table
12496
12497If you do not use the GNU C compiler, you may need other standard
12498library subroutines as well; this varies from one stub to another,
12499but in general the stubs are likely to use any of the common library
d4f3574e 12500subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
12501
12502
6d2ebf8b 12503@node Debug Session
6f05cf9f 12504@subsection Putting it all together
104c1213
JM
12505
12506@cindex remote serial debugging summary
12507In summary, when your program is ready to debug, you must follow these
12508steps.
12509
12510@enumerate
12511@item
6d2ebf8b 12512Make sure you have defined the supporting low-level routines
104c1213
JM
12513(@pxref{Bootstrapping,,What you must do for the stub}):
12514@display
12515@code{getDebugChar}, @code{putDebugChar},
12516@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
12517@end display
12518
12519@item
12520Insert these lines near the top of your program:
12521
474c8240 12522@smallexample
104c1213
JM
12523set_debug_traps();
12524breakpoint();
474c8240 12525@end smallexample
104c1213
JM
12526
12527@item
12528For the 680x0 stub only, you need to provide a variable called
12529@code{exceptionHook}. Normally you just use:
12530
474c8240 12531@smallexample
104c1213 12532void (*exceptionHook)() = 0;
474c8240 12533@end smallexample
104c1213 12534
d4f3574e 12535@noindent
104c1213 12536but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 12537function in your program, that function is called when
104c1213
JM
12538@code{@value{GDBN}} continues after stopping on a trap (for example, bus
12539error). The function indicated by @code{exceptionHook} is called with
12540one parameter: an @code{int} which is the exception number.
12541
12542@item
12543Compile and link together: your program, the @value{GDBN} debugging stub for
12544your target architecture, and the supporting subroutines.
12545
12546@item
12547Make sure you have a serial connection between your target machine and
12548the @value{GDBN} host, and identify the serial port on the host.
12549
12550@item
12551@c The "remote" target now provides a `load' command, so we should
12552@c document that. FIXME.
12553Download your program to your target machine (or get it there by
12554whatever means the manufacturer provides), and start it.
12555
12556@item
07f31aa6
DJ
12557Start @value{GDBN} on the host, and connect to the target
12558(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 12559
104c1213
JM
12560@end enumerate
12561
8e04817f
AC
12562@node Configurations
12563@chapter Configuration-Specific Information
104c1213 12564
8e04817f
AC
12565While nearly all @value{GDBN} commands are available for all native and
12566cross versions of the debugger, there are some exceptions. This chapter
12567describes things that are only available in certain configurations.
104c1213 12568
8e04817f
AC
12569There are three major categories of configurations: native
12570configurations, where the host and target are the same, embedded
12571operating system configurations, which are usually the same for several
12572different processor architectures, and bare embedded processors, which
12573are quite different from each other.
104c1213 12574
8e04817f
AC
12575@menu
12576* Native::
12577* Embedded OS::
12578* Embedded Processors::
12579* Architectures::
12580@end menu
104c1213 12581
8e04817f
AC
12582@node Native
12583@section Native
104c1213 12584
8e04817f
AC
12585This section describes details specific to particular native
12586configurations.
6cf7e474 12587
8e04817f
AC
12588@menu
12589* HP-UX:: HP-UX
7561d450 12590* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
12591* SVR4 Process Information:: SVR4 process information
12592* DJGPP Native:: Features specific to the DJGPP port
78c47bea 12593* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 12594* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 12595* Neutrino:: Features specific to QNX Neutrino
8e04817f 12596@end menu
6cf7e474 12597
8e04817f
AC
12598@node HP-UX
12599@subsection HP-UX
104c1213 12600
8e04817f
AC
12601On HP-UX systems, if you refer to a function or variable name that
12602begins with a dollar sign, @value{GDBN} searches for a user or system
12603name first, before it searches for a convenience variable.
104c1213 12604
9c16f35a 12605
7561d450
MK
12606@node BSD libkvm Interface
12607@subsection BSD libkvm Interface
12608
12609@cindex libkvm
12610@cindex kernel memory image
12611@cindex kernel crash dump
12612
12613BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
12614interface that provides a uniform interface for accessing kernel virtual
12615memory images, including live systems and crash dumps. @value{GDBN}
12616uses this interface to allow you to debug live kernels and kernel crash
12617dumps on many native BSD configurations. This is implemented as a
12618special @code{kvm} debugging target. For debugging a live system, load
12619the currently running kernel into @value{GDBN} and connect to the
12620@code{kvm} target:
12621
12622@smallexample
12623(@value{GDBP}) @b{target kvm}
12624@end smallexample
12625
12626For debugging crash dumps, provide the file name of the crash dump as an
12627argument:
12628
12629@smallexample
12630(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
12631@end smallexample
12632
12633Once connected to the @code{kvm} target, the following commands are
12634available:
12635
12636@table @code
12637@kindex kvm
12638@item kvm pcb
721c2651 12639Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
12640
12641@item kvm proc
12642Set current context from proc address. This command isn't available on
12643modern FreeBSD systems.
12644@end table
12645
8e04817f
AC
12646@node SVR4 Process Information
12647@subsection SVR4 process information
60bf7e09
EZ
12648@cindex /proc
12649@cindex examine process image
12650@cindex process info via @file{/proc}
104c1213 12651
60bf7e09
EZ
12652Many versions of SVR4 and compatible systems provide a facility called
12653@samp{/proc} that can be used to examine the image of a running
12654process using file-system subroutines. If @value{GDBN} is configured
12655for an operating system with this facility, the command @code{info
12656proc} is available to report information about the process running
12657your program, or about any process running on your system. @code{info
12658proc} works only on SVR4 systems that include the @code{procfs} code.
12659This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
12660Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 12661
8e04817f
AC
12662@table @code
12663@kindex info proc
60bf7e09 12664@cindex process ID
8e04817f 12665@item info proc
60bf7e09
EZ
12666@itemx info proc @var{process-id}
12667Summarize available information about any running process. If a
12668process ID is specified by @var{process-id}, display information about
12669that process; otherwise display information about the program being
12670debugged. The summary includes the debugged process ID, the command
12671line used to invoke it, its current working directory, and its
12672executable file's absolute file name.
12673
12674On some systems, @var{process-id} can be of the form
12675@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
12676within a process. If the optional @var{pid} part is missing, it means
12677a thread from the process being debugged (the leading @samp{/} still
12678needs to be present, or else @value{GDBN} will interpret the number as
12679a process ID rather than a thread ID).
6cf7e474 12680
8e04817f 12681@item info proc mappings
60bf7e09
EZ
12682@cindex memory address space mappings
12683Report the memory address space ranges accessible in the program, with
12684information on whether the process has read, write, or execute access
12685rights to each range. On @sc{gnu}/Linux systems, each memory range
12686includes the object file which is mapped to that range, instead of the
12687memory access rights to that range.
12688
12689@item info proc stat
12690@itemx info proc status
12691@cindex process detailed status information
12692These subcommands are specific to @sc{gnu}/Linux systems. They show
12693the process-related information, including the user ID and group ID;
12694how many threads are there in the process; its virtual memory usage;
12695the signals that are pending, blocked, and ignored; its TTY; its
12696consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 12697value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
12698(type @kbd{man 5 proc} from your shell prompt).
12699
12700@item info proc all
12701Show all the information about the process described under all of the
12702above @code{info proc} subcommands.
12703
8e04817f
AC
12704@ignore
12705@comment These sub-options of 'info proc' were not included when
12706@comment procfs.c was re-written. Keep their descriptions around
12707@comment against the day when someone finds the time to put them back in.
12708@kindex info proc times
12709@item info proc times
12710Starting time, user CPU time, and system CPU time for your program and
12711its children.
6cf7e474 12712
8e04817f
AC
12713@kindex info proc id
12714@item info proc id
12715Report on the process IDs related to your program: its own process ID,
12716the ID of its parent, the process group ID, and the session ID.
8e04817f 12717@end ignore
721c2651
EZ
12718
12719@item set procfs-trace
12720@kindex set procfs-trace
12721@cindex @code{procfs} API calls
12722This command enables and disables tracing of @code{procfs} API calls.
12723
12724@item show procfs-trace
12725@kindex show procfs-trace
12726Show the current state of @code{procfs} API call tracing.
12727
12728@item set procfs-file @var{file}
12729@kindex set procfs-file
12730Tell @value{GDBN} to write @code{procfs} API trace to the named
12731@var{file}. @value{GDBN} appends the trace info to the previous
12732contents of the file. The default is to display the trace on the
12733standard output.
12734
12735@item show procfs-file
12736@kindex show procfs-file
12737Show the file to which @code{procfs} API trace is written.
12738
12739@item proc-trace-entry
12740@itemx proc-trace-exit
12741@itemx proc-untrace-entry
12742@itemx proc-untrace-exit
12743@kindex proc-trace-entry
12744@kindex proc-trace-exit
12745@kindex proc-untrace-entry
12746@kindex proc-untrace-exit
12747These commands enable and disable tracing of entries into and exits
12748from the @code{syscall} interface.
12749
12750@item info pidlist
12751@kindex info pidlist
12752@cindex process list, QNX Neutrino
12753For QNX Neutrino only, this command displays the list of all the
12754processes and all the threads within each process.
12755
12756@item info meminfo
12757@kindex info meminfo
12758@cindex mapinfo list, QNX Neutrino
12759For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 12760@end table
104c1213 12761
8e04817f
AC
12762@node DJGPP Native
12763@subsection Features for Debugging @sc{djgpp} Programs
12764@cindex @sc{djgpp} debugging
12765@cindex native @sc{djgpp} debugging
12766@cindex MS-DOS-specific commands
104c1213 12767
514c4d71
EZ
12768@cindex DPMI
12769@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
12770MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
12771that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
12772top of real-mode DOS systems and their emulations.
104c1213 12773
8e04817f
AC
12774@value{GDBN} supports native debugging of @sc{djgpp} programs, and
12775defines a few commands specific to the @sc{djgpp} port. This
12776subsection describes those commands.
104c1213 12777
8e04817f
AC
12778@table @code
12779@kindex info dos
12780@item info dos
12781This is a prefix of @sc{djgpp}-specific commands which print
12782information about the target system and important OS structures.
f1251bdd 12783
8e04817f
AC
12784@kindex sysinfo
12785@cindex MS-DOS system info
12786@cindex free memory information (MS-DOS)
12787@item info dos sysinfo
12788This command displays assorted information about the underlying
12789platform: the CPU type and features, the OS version and flavor, the
12790DPMI version, and the available conventional and DPMI memory.
104c1213 12791
8e04817f
AC
12792@cindex GDT
12793@cindex LDT
12794@cindex IDT
12795@cindex segment descriptor tables
12796@cindex descriptor tables display
12797@item info dos gdt
12798@itemx info dos ldt
12799@itemx info dos idt
12800These 3 commands display entries from, respectively, Global, Local,
12801and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
12802tables are data structures which store a descriptor for each segment
12803that is currently in use. The segment's selector is an index into a
12804descriptor table; the table entry for that index holds the
12805descriptor's base address and limit, and its attributes and access
12806rights.
104c1213 12807
8e04817f
AC
12808A typical @sc{djgpp} program uses 3 segments: a code segment, a data
12809segment (used for both data and the stack), and a DOS segment (which
12810allows access to DOS/BIOS data structures and absolute addresses in
12811conventional memory). However, the DPMI host will usually define
12812additional segments in order to support the DPMI environment.
d4f3574e 12813
8e04817f
AC
12814@cindex garbled pointers
12815These commands allow to display entries from the descriptor tables.
12816Without an argument, all entries from the specified table are
12817displayed. An argument, which should be an integer expression, means
12818display a single entry whose index is given by the argument. For
12819example, here's a convenient way to display information about the
12820debugged program's data segment:
104c1213 12821
8e04817f
AC
12822@smallexample
12823@exdent @code{(@value{GDBP}) info dos ldt $ds}
12824@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
12825@end smallexample
104c1213 12826
8e04817f
AC
12827@noindent
12828This comes in handy when you want to see whether a pointer is outside
12829the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 12830
8e04817f
AC
12831@cindex page tables display (MS-DOS)
12832@item info dos pde
12833@itemx info dos pte
12834These two commands display entries from, respectively, the Page
12835Directory and the Page Tables. Page Directories and Page Tables are
12836data structures which control how virtual memory addresses are mapped
12837into physical addresses. A Page Table includes an entry for every
12838page of memory that is mapped into the program's address space; there
12839may be several Page Tables, each one holding up to 4096 entries. A
12840Page Directory has up to 4096 entries, one each for every Page Table
12841that is currently in use.
104c1213 12842
8e04817f
AC
12843Without an argument, @kbd{info dos pde} displays the entire Page
12844Directory, and @kbd{info dos pte} displays all the entries in all of
12845the Page Tables. An argument, an integer expression, given to the
12846@kbd{info dos pde} command means display only that entry from the Page
12847Directory table. An argument given to the @kbd{info dos pte} command
12848means display entries from a single Page Table, the one pointed to by
12849the specified entry in the Page Directory.
104c1213 12850
8e04817f
AC
12851@cindex direct memory access (DMA) on MS-DOS
12852These commands are useful when your program uses @dfn{DMA} (Direct
12853Memory Access), which needs physical addresses to program the DMA
12854controller.
104c1213 12855
8e04817f 12856These commands are supported only with some DPMI servers.
104c1213 12857
8e04817f
AC
12858@cindex physical address from linear address
12859@item info dos address-pte @var{addr}
12860This command displays the Page Table entry for a specified linear
514c4d71
EZ
12861address. The argument @var{addr} is a linear address which should
12862already have the appropriate segment's base address added to it,
12863because this command accepts addresses which may belong to @emph{any}
12864segment. For example, here's how to display the Page Table entry for
12865the page where a variable @code{i} is stored:
104c1213 12866
b383017d 12867@smallexample
8e04817f
AC
12868@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
12869@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 12870@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 12871@end smallexample
104c1213 12872
8e04817f
AC
12873@noindent
12874This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 12875whose physical base address is @code{0x02698000}, and shows all the
8e04817f 12876attributes of that page.
104c1213 12877
8e04817f
AC
12878Note that you must cast the addresses of variables to a @code{char *},
12879since otherwise the value of @code{__djgpp_base_address}, the base
12880address of all variables and functions in a @sc{djgpp} program, will
12881be added using the rules of C pointer arithmetics: if @code{i} is
12882declared an @code{int}, @value{GDBN} will add 4 times the value of
12883@code{__djgpp_base_address} to the address of @code{i}.
104c1213 12884
8e04817f
AC
12885Here's another example, it displays the Page Table entry for the
12886transfer buffer:
104c1213 12887
8e04817f
AC
12888@smallexample
12889@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
12890@exdent @code{Page Table entry for address 0x29110:}
12891@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
12892@end smallexample
104c1213 12893
8e04817f
AC
12894@noindent
12895(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
128963rd member of the @code{_go32_info_block} structure.) The output
12897clearly shows that this DPMI server maps the addresses in conventional
12898memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
12899linear (@code{0x29110}) addresses are identical.
104c1213 12900
8e04817f
AC
12901This command is supported only with some DPMI servers.
12902@end table
104c1213 12903
c45da7e6 12904@cindex DOS serial data link, remote debugging
a8f24a35
EZ
12905In addition to native debugging, the DJGPP port supports remote
12906debugging via a serial data link. The following commands are specific
12907to remote serial debugging in the DJGPP port of @value{GDBN}.
12908
12909@table @code
12910@kindex set com1base
12911@kindex set com1irq
12912@kindex set com2base
12913@kindex set com2irq
12914@kindex set com3base
12915@kindex set com3irq
12916@kindex set com4base
12917@kindex set com4irq
12918@item set com1base @var{addr}
12919This command sets the base I/O port address of the @file{COM1} serial
12920port.
12921
12922@item set com1irq @var{irq}
12923This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
12924for the @file{COM1} serial port.
12925
12926There are similar commands @samp{set com2base}, @samp{set com3irq},
12927etc.@: for setting the port address and the @code{IRQ} lines for the
12928other 3 COM ports.
12929
12930@kindex show com1base
12931@kindex show com1irq
12932@kindex show com2base
12933@kindex show com2irq
12934@kindex show com3base
12935@kindex show com3irq
12936@kindex show com4base
12937@kindex show com4irq
12938The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
12939display the current settings of the base address and the @code{IRQ}
12940lines used by the COM ports.
c45da7e6
EZ
12941
12942@item info serial
12943@kindex info serial
12944@cindex DOS serial port status
12945This command prints the status of the 4 DOS serial ports. For each
12946port, it prints whether it's active or not, its I/O base address and
12947IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
12948counts of various errors encountered so far.
a8f24a35
EZ
12949@end table
12950
12951
78c47bea
PM
12952@node Cygwin Native
12953@subsection Features for Debugging MS Windows PE executables
12954@cindex MS Windows debugging
12955@cindex native Cygwin debugging
12956@cindex Cygwin-specific commands
12957
be448670
CF
12958@value{GDBN} supports native debugging of MS Windows programs, including
12959DLLs with and without symbolic debugging information. There are various
12960additional Cygwin-specific commands, described in this subsection. The
12961subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
12962that have no debugging symbols.
12963
78c47bea
PM
12964
12965@table @code
12966@kindex info w32
12967@item info w32
12968This is a prefix of MS Windows specific commands which print
12969information about the target system and important OS structures.
12970
12971@item info w32 selector
12972This command displays information returned by
12973the Win32 API @code{GetThreadSelectorEntry} function.
12974It takes an optional argument that is evaluated to
12975a long value to give the information about this given selector.
12976Without argument, this command displays information
12977about the the six segment registers.
12978
12979@kindex info dll
12980@item info dll
12981This is a Cygwin specific alias of info shared.
12982
12983@kindex dll-symbols
12984@item dll-symbols
12985This command loads symbols from a dll similarly to
12986add-sym command but without the need to specify a base address.
12987
b383017d 12988@kindex set new-console
78c47bea 12989@item set new-console @var{mode}
b383017d 12990If @var{mode} is @code{on} the debuggee will
78c47bea
PM
12991be started in a new console on next start.
12992If @var{mode} is @code{off}i, the debuggee will
12993be started in the same console as the debugger.
12994
12995@kindex show new-console
12996@item show new-console
12997Displays whether a new console is used
12998when the debuggee is started.
12999
13000@kindex set new-group
13001@item set new-group @var{mode}
13002This boolean value controls whether the debuggee should
13003start a new group or stay in the same group as the debugger.
13004This affects the way the Windows OS handles
13005Ctrl-C.
13006
13007@kindex show new-group
13008@item show new-group
13009Displays current value of new-group boolean.
13010
13011@kindex set debugevents
13012@item set debugevents
13013This boolean value adds debug output concerning events seen by the debugger.
13014
13015@kindex set debugexec
13016@item set debugexec
b383017d 13017This boolean value adds debug output concerning execute events
78c47bea
PM
13018seen by the debugger.
13019
13020@kindex set debugexceptions
13021@item set debugexceptions
b383017d 13022This boolean value adds debug ouptut concerning exception events
78c47bea
PM
13023seen by the debugger.
13024
13025@kindex set debugmemory
13026@item set debugmemory
b383017d 13027This boolean value adds debug ouptut concerning memory events
78c47bea
PM
13028seen by the debugger.
13029
13030@kindex set shell
13031@item set shell
13032This boolean values specifies whether the debuggee is called
13033via a shell or directly (default value is on).
13034
13035@kindex show shell
13036@item show shell
13037Displays if the debuggee will be started with a shell.
13038
13039@end table
13040
be448670
CF
13041@menu
13042* Non-debug DLL symbols:: Support for DLLs without debugging symbols
13043@end menu
13044
13045@node Non-debug DLL symbols
13046@subsubsection Support for DLLs without debugging symbols
13047@cindex DLLs with no debugging symbols
13048@cindex Minimal symbols and DLLs
13049
13050Very often on windows, some of the DLLs that your program relies on do
13051not include symbolic debugging information (for example,
13052@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
13053symbols in a DLL, it relies on the minimal amount of symbolic
13054information contained in the DLL's export table. This subsubsection
13055describes working with such symbols, known internally to @value{GDBN} as
13056``minimal symbols''.
13057
13058Note that before the debugged program has started execution, no DLLs
13059will have been loaded. The easiest way around this problem is simply to
13060start the program --- either by setting a breakpoint or letting the
13061program run once to completion. It is also possible to force
13062@value{GDBN} to load a particular DLL before starting the executable ---
13063see the shared library information in @pxref{Files} or the
13064@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
13065explicitly loading symbols from a DLL with no debugging information will
13066cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
13067which may adversely affect symbol lookup performance.
13068
13069@subsubsection DLL name prefixes
13070
13071In keeping with the naming conventions used by the Microsoft debugging
13072tools, DLL export symbols are made available with a prefix based on the
13073DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
13074also entered into the symbol table, so @code{CreateFileA} is often
13075sufficient. In some cases there will be name clashes within a program
13076(particularly if the executable itself includes full debugging symbols)
13077necessitating the use of the fully qualified name when referring to the
13078contents of the DLL. Use single-quotes around the name to avoid the
13079exclamation mark (``!'') being interpreted as a language operator.
13080
13081Note that the internal name of the DLL may be all upper-case, even
13082though the file name of the DLL is lower-case, or vice-versa. Since
13083symbols within @value{GDBN} are @emph{case-sensitive} this may cause
13084some confusion. If in doubt, try the @code{info functions} and
13085@code{info variables} commands or even @code{maint print msymbols} (see
13086@pxref{Symbols}). Here's an example:
13087
13088@smallexample
f7dc1244 13089(@value{GDBP}) info function CreateFileA
be448670
CF
13090All functions matching regular expression "CreateFileA":
13091
13092Non-debugging symbols:
130930x77e885f4 CreateFileA
130940x77e885f4 KERNEL32!CreateFileA
13095@end smallexample
13096
13097@smallexample
f7dc1244 13098(@value{GDBP}) info function !
be448670
CF
13099All functions matching regular expression "!":
13100
13101Non-debugging symbols:
131020x6100114c cygwin1!__assert
131030x61004034 cygwin1!_dll_crt0@@0
131040x61004240 cygwin1!dll_crt0(per_process *)
13105[etc...]
13106@end smallexample
13107
13108@subsubsection Working with minimal symbols
13109
13110Symbols extracted from a DLL's export table do not contain very much
13111type information. All that @value{GDBN} can do is guess whether a symbol
13112refers to a function or variable depending on the linker section that
13113contains the symbol. Also note that the actual contents of the memory
13114contained in a DLL are not available unless the program is running. This
13115means that you cannot examine the contents of a variable or disassemble
13116a function within a DLL without a running program.
13117
13118Variables are generally treated as pointers and dereferenced
13119automatically. For this reason, it is often necessary to prefix a
13120variable name with the address-of operator (``&'') and provide explicit
13121type information in the command. Here's an example of the type of
13122problem:
13123
13124@smallexample
f7dc1244 13125(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
13126$1 = 268572168
13127@end smallexample
13128
13129@smallexample
f7dc1244 13130(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
131310x10021610: "\230y\""
13132@end smallexample
13133
13134And two possible solutions:
13135
13136@smallexample
f7dc1244 13137(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
13138$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
13139@end smallexample
13140
13141@smallexample
f7dc1244 13142(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 131430x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 13144(@value{GDBP}) x/x 0x10021608
be448670 131450x10021608: 0x0022fd98
f7dc1244 13146(@value{GDBP}) x/s 0x0022fd98
be448670
CF
131470x22fd98: "/cygdrive/c/mydirectory/myprogram"
13148@end smallexample
13149
13150Setting a break point within a DLL is possible even before the program
13151starts execution. However, under these circumstances, @value{GDBN} can't
13152examine the initial instructions of the function in order to skip the
13153function's frame set-up code. You can work around this by using ``*&''
13154to set the breakpoint at a raw memory address:
13155
13156@smallexample
f7dc1244 13157(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
13158Breakpoint 1 at 0x1e04eff0
13159@end smallexample
13160
13161The author of these extensions is not entirely convinced that setting a
13162break point within a shared DLL like @file{kernel32.dll} is completely
13163safe.
13164
14d6dd68
EZ
13165@node Hurd Native
13166@subsection Commands specific to @sc{gnu} Hurd systems
13167@cindex @sc{gnu} Hurd debugging
13168
13169This subsection describes @value{GDBN} commands specific to the
13170@sc{gnu} Hurd native debugging.
13171
13172@table @code
13173@item set signals
13174@itemx set sigs
13175@kindex set signals@r{, Hurd command}
13176@kindex set sigs@r{, Hurd command}
13177This command toggles the state of inferior signal interception by
13178@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
13179affected by this command. @code{sigs} is a shorthand alias for
13180@code{signals}.
13181
13182@item show signals
13183@itemx show sigs
13184@kindex show signals@r{, Hurd command}
13185@kindex show sigs@r{, Hurd command}
13186Show the current state of intercepting inferior's signals.
13187
13188@item set signal-thread
13189@itemx set sigthread
13190@kindex set signal-thread
13191@kindex set sigthread
13192This command tells @value{GDBN} which thread is the @code{libc} signal
13193thread. That thread is run when a signal is delivered to a running
13194process. @code{set sigthread} is the shorthand alias of @code{set
13195signal-thread}.
13196
13197@item show signal-thread
13198@itemx show sigthread
13199@kindex show signal-thread
13200@kindex show sigthread
13201These two commands show which thread will run when the inferior is
13202delivered a signal.
13203
13204@item set stopped
13205@kindex set stopped@r{, Hurd command}
13206This commands tells @value{GDBN} that the inferior process is stopped,
13207as with the @code{SIGSTOP} signal. The stopped process can be
13208continued by delivering a signal to it.
13209
13210@item show stopped
13211@kindex show stopped@r{, Hurd command}
13212This command shows whether @value{GDBN} thinks the debuggee is
13213stopped.
13214
13215@item set exceptions
13216@kindex set exceptions@r{, Hurd command}
13217Use this command to turn off trapping of exceptions in the inferior.
13218When exception trapping is off, neither breakpoints nor
13219single-stepping will work. To restore the default, set exception
13220trapping on.
13221
13222@item show exceptions
13223@kindex show exceptions@r{, Hurd command}
13224Show the current state of trapping exceptions in the inferior.
13225
13226@item set task pause
13227@kindex set task@r{, Hurd commands}
13228@cindex task attributes (@sc{gnu} Hurd)
13229@cindex pause current task (@sc{gnu} Hurd)
13230This command toggles task suspension when @value{GDBN} has control.
13231Setting it to on takes effect immediately, and the task is suspended
13232whenever @value{GDBN} gets control. Setting it to off will take
13233effect the next time the inferior is continued. If this option is set
13234to off, you can use @code{set thread default pause on} or @code{set
13235thread pause on} (see below) to pause individual threads.
13236
13237@item show task pause
13238@kindex show task@r{, Hurd commands}
13239Show the current state of task suspension.
13240
13241@item set task detach-suspend-count
13242@cindex task suspend count
13243@cindex detach from task, @sc{gnu} Hurd
13244This command sets the suspend count the task will be left with when
13245@value{GDBN} detaches from it.
13246
13247@item show task detach-suspend-count
13248Show the suspend count the task will be left with when detaching.
13249
13250@item set task exception-port
13251@itemx set task excp
13252@cindex task exception port, @sc{gnu} Hurd
13253This command sets the task exception port to which @value{GDBN} will
13254forward exceptions. The argument should be the value of the @dfn{send
13255rights} of the task. @code{set task excp} is a shorthand alias.
13256
13257@item set noninvasive
13258@cindex noninvasive task options
13259This command switches @value{GDBN} to a mode that is the least
13260invasive as far as interfering with the inferior is concerned. This
13261is the same as using @code{set task pause}, @code{set exceptions}, and
13262@code{set signals} to values opposite to the defaults.
13263
13264@item info send-rights
13265@itemx info receive-rights
13266@itemx info port-rights
13267@itemx info port-sets
13268@itemx info dead-names
13269@itemx info ports
13270@itemx info psets
13271@cindex send rights, @sc{gnu} Hurd
13272@cindex receive rights, @sc{gnu} Hurd
13273@cindex port rights, @sc{gnu} Hurd
13274@cindex port sets, @sc{gnu} Hurd
13275@cindex dead names, @sc{gnu} Hurd
13276These commands display information about, respectively, send rights,
13277receive rights, port rights, port sets, and dead names of a task.
13278There are also shorthand aliases: @code{info ports} for @code{info
13279port-rights} and @code{info psets} for @code{info port-sets}.
13280
13281@item set thread pause
13282@kindex set thread@r{, Hurd command}
13283@cindex thread properties, @sc{gnu} Hurd
13284@cindex pause current thread (@sc{gnu} Hurd)
13285This command toggles current thread suspension when @value{GDBN} has
13286control. Setting it to on takes effect immediately, and the current
13287thread is suspended whenever @value{GDBN} gets control. Setting it to
13288off will take effect the next time the inferior is continued.
13289Normally, this command has no effect, since when @value{GDBN} has
13290control, the whole task is suspended. However, if you used @code{set
13291task pause off} (see above), this command comes in handy to suspend
13292only the current thread.
13293
13294@item show thread pause
13295@kindex show thread@r{, Hurd command}
13296This command shows the state of current thread suspension.
13297
13298@item set thread run
13299This comamnd sets whether the current thread is allowed to run.
13300
13301@item show thread run
13302Show whether the current thread is allowed to run.
13303
13304@item set thread detach-suspend-count
13305@cindex thread suspend count, @sc{gnu} Hurd
13306@cindex detach from thread, @sc{gnu} Hurd
13307This command sets the suspend count @value{GDBN} will leave on a
13308thread when detaching. This number is relative to the suspend count
13309found by @value{GDBN} when it notices the thread; use @code{set thread
13310takeover-suspend-count} to force it to an absolute value.
13311
13312@item show thread detach-suspend-count
13313Show the suspend count @value{GDBN} will leave on the thread when
13314detaching.
13315
13316@item set thread exception-port
13317@itemx set thread excp
13318Set the thread exception port to which to forward exceptions. This
13319overrides the port set by @code{set task exception-port} (see above).
13320@code{set thread excp} is the shorthand alias.
13321
13322@item set thread takeover-suspend-count
13323Normally, @value{GDBN}'s thread suspend counts are relative to the
13324value @value{GDBN} finds when it notices each thread. This command
13325changes the suspend counts to be absolute instead.
13326
13327@item set thread default
13328@itemx show thread default
13329@cindex thread default settings, @sc{gnu} Hurd
13330Each of the above @code{set thread} commands has a @code{set thread
13331default} counterpart (e.g., @code{set thread default pause}, @code{set
13332thread default exception-port}, etc.). The @code{thread default}
13333variety of commands sets the default thread properties for all
13334threads; you can then change the properties of individual threads with
13335the non-default commands.
13336@end table
13337
13338
a64548ea
EZ
13339@node Neutrino
13340@subsection QNX Neutrino
13341@cindex QNX Neutrino
13342
13343@value{GDBN} provides the following commands specific to the QNX
13344Neutrino target:
13345
13346@table @code
13347@item set debug nto-debug
13348@kindex set debug nto-debug
13349When set to on, enables debugging messages specific to the QNX
13350Neutrino support.
13351
13352@item show debug nto-debug
13353@kindex show debug nto-debug
13354Show the current state of QNX Neutrino messages.
13355@end table
13356
13357
8e04817f
AC
13358@node Embedded OS
13359@section Embedded Operating Systems
104c1213 13360
8e04817f
AC
13361This section describes configurations involving the debugging of
13362embedded operating systems that are available for several different
13363architectures.
d4f3574e 13364
8e04817f
AC
13365@menu
13366* VxWorks:: Using @value{GDBN} with VxWorks
13367@end menu
104c1213 13368
8e04817f
AC
13369@value{GDBN} includes the ability to debug programs running on
13370various real-time operating systems.
104c1213 13371
8e04817f
AC
13372@node VxWorks
13373@subsection Using @value{GDBN} with VxWorks
104c1213 13374
8e04817f 13375@cindex VxWorks
104c1213 13376
8e04817f 13377@table @code
104c1213 13378
8e04817f
AC
13379@kindex target vxworks
13380@item target vxworks @var{machinename}
13381A VxWorks system, attached via TCP/IP. The argument @var{machinename}
13382is the target system's machine name or IP address.
104c1213 13383
8e04817f 13384@end table
104c1213 13385
8e04817f
AC
13386On VxWorks, @code{load} links @var{filename} dynamically on the
13387current target system as well as adding its symbols in @value{GDBN}.
104c1213 13388
8e04817f
AC
13389@value{GDBN} enables developers to spawn and debug tasks running on networked
13390VxWorks targets from a Unix host. Already-running tasks spawned from
13391the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
13392both the Unix host and on the VxWorks target. The program
13393@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
13394installed with the name @code{vxgdb}, to distinguish it from a
13395@value{GDBN} for debugging programs on the host itself.)
104c1213 13396
8e04817f
AC
13397@table @code
13398@item VxWorks-timeout @var{args}
13399@kindex vxworks-timeout
13400All VxWorks-based targets now support the option @code{vxworks-timeout}.
13401This option is set by the user, and @var{args} represents the number of
13402seconds @value{GDBN} waits for responses to rpc's. You might use this if
13403your VxWorks target is a slow software simulator or is on the far side
13404of a thin network line.
13405@end table
104c1213 13406
8e04817f
AC
13407The following information on connecting to VxWorks was current when
13408this manual was produced; newer releases of VxWorks may use revised
13409procedures.
104c1213 13410
4644b6e3 13411@findex INCLUDE_RDB
8e04817f
AC
13412To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
13413to include the remote debugging interface routines in the VxWorks
13414library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
13415VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
13416kernel. The resulting kernel contains @file{rdb.a}, and spawns the
13417source debugging task @code{tRdbTask} when VxWorks is booted. For more
13418information on configuring and remaking VxWorks, see the manufacturer's
13419manual.
13420@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 13421
8e04817f
AC
13422Once you have included @file{rdb.a} in your VxWorks system image and set
13423your Unix execution search path to find @value{GDBN}, you are ready to
13424run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
13425@code{vxgdb}, depending on your installation).
104c1213 13426
8e04817f 13427@value{GDBN} comes up showing the prompt:
104c1213 13428
474c8240 13429@smallexample
8e04817f 13430(vxgdb)
474c8240 13431@end smallexample
104c1213 13432
8e04817f
AC
13433@menu
13434* VxWorks Connection:: Connecting to VxWorks
13435* VxWorks Download:: VxWorks download
13436* VxWorks Attach:: Running tasks
13437@end menu
104c1213 13438
8e04817f
AC
13439@node VxWorks Connection
13440@subsubsection Connecting to VxWorks
104c1213 13441
8e04817f
AC
13442The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
13443network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 13444
474c8240 13445@smallexample
8e04817f 13446(vxgdb) target vxworks tt
474c8240 13447@end smallexample
104c1213 13448
8e04817f
AC
13449@need 750
13450@value{GDBN} displays messages like these:
104c1213 13451
8e04817f
AC
13452@smallexample
13453Attaching remote machine across net...
13454Connected to tt.
13455@end smallexample
104c1213 13456
8e04817f
AC
13457@need 1000
13458@value{GDBN} then attempts to read the symbol tables of any object modules
13459loaded into the VxWorks target since it was last booted. @value{GDBN} locates
13460these files by searching the directories listed in the command search
13461path (@pxref{Environment, ,Your program's environment}); if it fails
13462to find an object file, it displays a message such as:
5d161b24 13463
474c8240 13464@smallexample
8e04817f 13465prog.o: No such file or directory.
474c8240 13466@end smallexample
104c1213 13467
8e04817f
AC
13468When this happens, add the appropriate directory to the search path with
13469the @value{GDBN} command @code{path}, and execute the @code{target}
13470command again.
104c1213 13471
8e04817f
AC
13472@node VxWorks Download
13473@subsubsection VxWorks download
104c1213 13474
8e04817f
AC
13475@cindex download to VxWorks
13476If you have connected to the VxWorks target and you want to debug an
13477object that has not yet been loaded, you can use the @value{GDBN}
13478@code{load} command to download a file from Unix to VxWorks
13479incrementally. The object file given as an argument to the @code{load}
13480command is actually opened twice: first by the VxWorks target in order
13481to download the code, then by @value{GDBN} in order to read the symbol
13482table. This can lead to problems if the current working directories on
13483the two systems differ. If both systems have NFS mounted the same
13484filesystems, you can avoid these problems by using absolute paths.
13485Otherwise, it is simplest to set the working directory on both systems
13486to the directory in which the object file resides, and then to reference
13487the file by its name, without any path. For instance, a program
13488@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
13489and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
13490program, type this on VxWorks:
104c1213 13491
474c8240 13492@smallexample
8e04817f 13493-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 13494@end smallexample
104c1213 13495
8e04817f
AC
13496@noindent
13497Then, in @value{GDBN}, type:
104c1213 13498
474c8240 13499@smallexample
8e04817f
AC
13500(vxgdb) cd @var{hostpath}/vw/demo/rdb
13501(vxgdb) load prog.o
474c8240 13502@end smallexample
104c1213 13503
8e04817f 13504@value{GDBN} displays a response similar to this:
104c1213 13505
8e04817f
AC
13506@smallexample
13507Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
13508@end smallexample
104c1213 13509
8e04817f
AC
13510You can also use the @code{load} command to reload an object module
13511after editing and recompiling the corresponding source file. Note that
13512this makes @value{GDBN} delete all currently-defined breakpoints,
13513auto-displays, and convenience variables, and to clear the value
13514history. (This is necessary in order to preserve the integrity of
13515debugger's data structures that reference the target system's symbol
13516table.)
104c1213 13517
8e04817f
AC
13518@node VxWorks Attach
13519@subsubsection Running tasks
104c1213
JM
13520
13521@cindex running VxWorks tasks
13522You can also attach to an existing task using the @code{attach} command as
13523follows:
13524
474c8240 13525@smallexample
104c1213 13526(vxgdb) attach @var{task}
474c8240 13527@end smallexample
104c1213
JM
13528
13529@noindent
13530where @var{task} is the VxWorks hexadecimal task ID. The task can be running
13531or suspended when you attach to it. Running tasks are suspended at
13532the time of attachment.
13533
6d2ebf8b 13534@node Embedded Processors
104c1213
JM
13535@section Embedded Processors
13536
13537This section goes into details specific to particular embedded
13538configurations.
13539
c45da7e6
EZ
13540@cindex send command to simulator
13541Whenever a specific embedded processor has a simulator, @value{GDBN}
13542allows to send an arbitrary command to the simulator.
13543
13544@table @code
13545@item sim @var{command}
13546@kindex sim@r{, a command}
13547Send an arbitrary @var{command} string to the simulator. Consult the
13548documentation for the specific simulator in use for information about
13549acceptable commands.
13550@end table
13551
7d86b5d5 13552
104c1213 13553@menu
c45da7e6 13554* ARM:: ARM RDI
172c2a43
KI
13555* H8/300:: Renesas H8/300
13556* H8/500:: Renesas H8/500
13557* M32R/D:: Renesas M32R/D
104c1213 13558* M68K:: Motorola M68K
104c1213 13559* MIPS Embedded:: MIPS Embedded
a37295f9 13560* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
13561* PA:: HP PA Embedded
13562* PowerPC: PowerPC
172c2a43 13563* SH:: Renesas SH
104c1213
JM
13564* Sparclet:: Tsqware Sparclet
13565* Sparclite:: Fujitsu Sparclite
13566* ST2000:: Tandem ST2000
13567* Z8000:: Zilog Z8000
a64548ea
EZ
13568* AVR:: Atmel AVR
13569* CRIS:: CRIS
13570* Super-H:: Renesas Super-H
c45da7e6 13571* WinCE:: Windows CE child processes
104c1213
JM
13572@end menu
13573
6d2ebf8b 13574@node ARM
104c1213 13575@subsection ARM
c45da7e6 13576@cindex ARM RDI
104c1213
JM
13577
13578@table @code
8e04817f
AC
13579@kindex target rdi
13580@item target rdi @var{dev}
13581ARM Angel monitor, via RDI library interface to ADP protocol. You may
13582use this target to communicate with both boards running the Angel
13583monitor, or with the EmbeddedICE JTAG debug device.
13584
13585@kindex target rdp
13586@item target rdp @var{dev}
13587ARM Demon monitor.
13588
13589@end table
13590
e2f4edfd
EZ
13591@value{GDBN} provides the following ARM-specific commands:
13592
13593@table @code
13594@item set arm disassembler
13595@kindex set arm
13596This commands selects from a list of disassembly styles. The
13597@code{"std"} style is the standard style.
13598
13599@item show arm disassembler
13600@kindex show arm
13601Show the current disassembly style.
13602
13603@item set arm apcs32
13604@cindex ARM 32-bit mode
13605This command toggles ARM operation mode between 32-bit and 26-bit.
13606
13607@item show arm apcs32
13608Display the current usage of the ARM 32-bit mode.
13609
13610@item set arm fpu @var{fputype}
13611This command sets the ARM floating-point unit (FPU) type. The
13612argument @var{fputype} can be one of these:
13613
13614@table @code
13615@item auto
13616Determine the FPU type by querying the OS ABI.
13617@item softfpa
13618Software FPU, with mixed-endian doubles on little-endian ARM
13619processors.
13620@item fpa
13621GCC-compiled FPA co-processor.
13622@item softvfp
13623Software FPU with pure-endian doubles.
13624@item vfp
13625VFP co-processor.
13626@end table
13627
13628@item show arm fpu
13629Show the current type of the FPU.
13630
13631@item set arm abi
13632This command forces @value{GDBN} to use the specified ABI.
13633
13634@item show arm abi
13635Show the currently used ABI.
13636
13637@item set debug arm
13638Toggle whether to display ARM-specific debugging messages from the ARM
13639target support subsystem.
13640
13641@item show debug arm
13642Show whether ARM-specific debugging messages are enabled.
13643@end table
13644
c45da7e6
EZ
13645The following commands are available when an ARM target is debugged
13646using the RDI interface:
13647
13648@table @code
13649@item rdilogfile @r{[}@var{file}@r{]}
13650@kindex rdilogfile
13651@cindex ADP (Angel Debugger Protocol) logging
13652Set the filename for the ADP (Angel Debugger Protocol) packet log.
13653With an argument, sets the log file to the specified @var{file}. With
13654no argument, show the current log file name. The default log file is
13655@file{rdi.log}.
13656
13657@item rdilogenable @r{[}@var{arg}@r{]}
13658@kindex rdilogenable
13659Control logging of ADP packets. With an argument of 1 or @code{"yes"}
13660enables logging, with an argument 0 or @code{"no"} disables it. With
13661no arguments displays the current setting. When logging is enabled,
13662ADP packets exchanged between @value{GDBN} and the RDI target device
13663are logged to a file.
13664
13665@item set rdiromatzero
13666@kindex set rdiromatzero
13667@cindex ROM at zero address, RDI
13668Tell @value{GDBN} whether the target has ROM at address 0. If on,
13669vector catching is disabled, so that zero address can be used. If off
13670(the default), vector catching is enabled. For this command to take
13671effect, it needs to be invoked prior to the @code{target rdi} command.
13672
13673@item show rdiromatzero
13674@kindex show rdiromatzero
13675Show the current setting of ROM at zero address.
13676
13677@item set rdiheartbeat
13678@kindex set rdiheartbeat
13679@cindex RDI heartbeat
13680Enable or disable RDI heartbeat packets. It is not recommended to
13681turn on this option, since it confuses ARM and EPI JTAG interface, as
13682well as the Angel monitor.
13683
13684@item show rdiheartbeat
13685@kindex show rdiheartbeat
13686Show the setting of RDI heartbeat packets.
13687@end table
13688
e2f4edfd 13689
8e04817f 13690@node H8/300
172c2a43 13691@subsection Renesas H8/300
8e04817f
AC
13692
13693@table @code
13694
13695@kindex target hms@r{, with H8/300}
13696@item target hms @var{dev}
172c2a43 13697A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
13698Use special commands @code{device} and @code{speed} to control the serial
13699line and the communications speed used.
13700
13701@kindex target e7000@r{, with H8/300}
13702@item target e7000 @var{dev}
172c2a43 13703E7000 emulator for Renesas H8 and SH.
8e04817f
AC
13704
13705@kindex target sh3@r{, with H8/300}
13706@kindex target sh3e@r{, with H8/300}
13707@item target sh3 @var{dev}
13708@itemx target sh3e @var{dev}
172c2a43 13709Renesas SH-3 and SH-3E target systems.
8e04817f
AC
13710
13711@end table
13712
13713@cindex download to H8/300 or H8/500
13714@cindex H8/300 or H8/500 download
172c2a43
KI
13715@cindex download to Renesas SH
13716@cindex Renesas SH download
13717When you select remote debugging to a Renesas SH, H8/300, or H8/500
13718board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
13719board and also opens it as the current executable target for
13720@value{GDBN} on your host (like the @code{file} command).
13721
13722@value{GDBN} needs to know these things to talk to your
172c2a43 13723Renesas SH, H8/300, or H8/500:
8e04817f
AC
13724
13725@enumerate
13726@item
13727that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
13728for Renesas microprocessors, or @samp{target e7000}, the in-circuit
13729emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
13730the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
13731H8/300, or H8/500.)
13732
13733@item
172c2a43 13734what serial device connects your host to your Renesas board (the first
8e04817f
AC
13735serial device available on your host is the default).
13736
13737@item
13738what speed to use over the serial device.
13739@end enumerate
13740
13741@menu
172c2a43
KI
13742* Renesas Boards:: Connecting to Renesas boards.
13743* Renesas ICE:: Using the E7000 In-Circuit Emulator.
13744* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
13745@end menu
13746
172c2a43
KI
13747@node Renesas Boards
13748@subsubsection Connecting to Renesas boards
8e04817f
AC
13749
13750@c only for Unix hosts
13751@kindex device
172c2a43 13752@cindex serial device, Renesas micros
8e04817f
AC
13753Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
13754need to explicitly set the serial device. The default @var{port} is the
13755first available port on your host. This is only necessary on Unix
13756hosts, where it is typically something like @file{/dev/ttya}.
13757
13758@kindex speed
172c2a43 13759@cindex serial line speed, Renesas micros
8e04817f
AC
13760@code{@value{GDBN}} has another special command to set the communications
13761speed: @samp{speed @var{bps}}. This command also is only used from Unix
13762hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
13763the DOS @code{mode} command (for instance,
13764@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
13765
13766The @samp{device} and @samp{speed} commands are available only when you
172c2a43 13767use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
13768use a DOS host,
13769@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
13770called @code{asynctsr} to communicate with the development board
13771through a PC serial port. You must also use the DOS @code{mode} command
13772to set up the serial port on the DOS side.
13773
13774The following sample session illustrates the steps needed to start a
13775program under @value{GDBN} control on an H8/300. The example uses a
13776sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 13777the Renesas SH and the H8/500.
8e04817f
AC
13778
13779First hook up your development board. In this example, we use a
13780board attached to serial port @code{COM2}; if you use a different serial
13781port, substitute its name in the argument of the @code{mode} command.
13782When you call @code{asynctsr}, the auxiliary comms program used by the
13783debugger, you give it just the numeric part of the serial port's name;
13784for example, @samp{asyncstr 2} below runs @code{asyncstr} on
13785@code{COM2}.
13786
474c8240 13787@smallexample
8e04817f
AC
13788C:\H8300\TEST> asynctsr 2
13789C:\H8300\TEST> mode com2:9600,n,8,1,p
13790
13791Resident portion of MODE loaded
13792
13793COM2: 9600, n, 8, 1, p
13794
474c8240 13795@end smallexample
8e04817f
AC
13796
13797@quotation
13798@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
13799@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
13800disable it, or even boot without it, to use @code{asynctsr} to control
13801your development board.
13802@end quotation
13803
13804@kindex target hms@r{, and serial protocol}
13805Now that serial communications are set up, and the development board is
9c16f35a 13806connected, you can start up @value{GDBN}. Call @code{@value{GDBN}} with
8e04817f
AC
13807the name of your program as the argument. @code{@value{GDBN}} prompts
13808you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
13809commands to begin your debugging session: @samp{target hms} to specify
172c2a43 13810cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
13811download your program to the board. @code{load} displays the names of
13812the program's sections, and a @samp{*} for each 2K of data downloaded.
13813(If you want to refresh @value{GDBN} data on symbols or on the
13814executable file without downloading, use the @value{GDBN} commands
13815@code{file} or @code{symbol-file}. These commands, and @code{load}
13816itself, are described in @ref{Files,,Commands to specify files}.)
13817
13818@smallexample
13819(eg-C:\H8300\TEST) @value{GDBP} t.x
13820@value{GDBN} is free software and you are welcome to distribute copies
13821 of it under certain conditions; type "show copying" to see
13822 the conditions.
13823There is absolutely no warranty for @value{GDBN}; type "show warranty"
13824for details.
13825@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
13826(@value{GDBP}) target hms
13827Connected to remote H8/300 HMS system.
13828(@value{GDBP}) load t.x
13829.text : 0x8000 .. 0xabde ***********
13830.data : 0xabde .. 0xad30 *
13831.stack : 0xf000 .. 0xf014 *
13832@end smallexample
13833
13834At this point, you're ready to run or debug your program. From here on,
13835you can use all the usual @value{GDBN} commands. The @code{break} command
13836sets breakpoints; the @code{run} command starts your program;
13837@code{print} or @code{x} display data; the @code{continue} command
13838resumes execution after stopping at a breakpoint. You can use the
13839@code{help} command at any time to find out more about @value{GDBN} commands.
13840
13841Remember, however, that @emph{operating system} facilities aren't
13842available on your development board; for example, if your program hangs,
13843you can't send an interrupt---but you can press the @sc{reset} switch!
13844
13845Use the @sc{reset} button on the development board
13846@itemize @bullet
13847@item
13848to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
13849no way to pass an interrupt signal to the development board); and
13850
13851@item
13852to return to the @value{GDBN} command prompt after your program finishes
13853normally. The communications protocol provides no other way for @value{GDBN}
13854to detect program completion.
13855@end itemize
13856
13857In either case, @value{GDBN} sees the effect of a @sc{reset} on the
13858development board as a ``normal exit'' of your program.
13859
172c2a43 13860@node Renesas ICE
8e04817f
AC
13861@subsubsection Using the E7000 in-circuit emulator
13862
172c2a43 13863@kindex target e7000@r{, with Renesas ICE}
8e04817f 13864You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 13865Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
13866e7000} command to connect @value{GDBN} to your E7000:
13867
13868@table @code
13869@item target e7000 @var{port} @var{speed}
13870Use this form if your E7000 is connected to a serial port. The
13871@var{port} argument identifies what serial port to use (for example,
13872@samp{com2}). The third argument is the line speed in bits per second
13873(for example, @samp{9600}).
13874
13875@item target e7000 @var{hostname}
13876If your E7000 is installed as a host on a TCP/IP network, you can just
13877specify its hostname; @value{GDBN} uses @code{telnet} to connect.
13878@end table
13879
ba04e063
EZ
13880The following special commands are available when debugging with the
13881Renesas E7000 ICE:
13882
13883@table @code
13884@item e7000 @var{command}
13885@kindex e7000
13886@cindex send command to E7000 monitor
13887This sends the specified @var{command} to the E7000 monitor.
13888
13889@item ftplogin @var{machine} @var{username} @var{password} @var{dir}
13890@kindex ftplogin@r{, E7000}
13891This command records information for subsequent interface with the
13892E7000 monitor via the FTP protocol: @value{GDBN} will log into the
13893named @var{machine} using specified @var{username} and @var{password},
13894and then chdir to the named directory @var{dir}.
13895
13896@item ftpload @var{file}
13897@kindex ftpload@r{, E7000}
13898This command uses credentials recorded by @code{ftplogin} to fetch and
13899load the named @var{file} from the E7000 monitor.
13900
13901@item drain
13902@kindex drain@r{, E7000}
13903This command drains any pending text buffers stored on the E7000.
13904
13905@item set usehardbreakpoints
13906@itemx show usehardbreakpoints
13907@kindex set usehardbreakpoints@r{, E7000}
13908@kindex show usehardbreakpoints@r{, E7000}
13909@cindex hardware breakpoints, and E7000
13910These commands set and show the use of hardware breakpoints for all
13911breakpoints. @xref{Set Breaks, hardware-assisted breakpoint}, for
13912more information about using hardware breakpoints selectively.
13913@end table
13914
172c2a43
KI
13915@node Renesas Special
13916@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
13917
13918Some @value{GDBN} commands are available only for the H8/300:
13919
13920@table @code
13921
13922@kindex set machine
13923@kindex show machine
13924@item set machine h8300
13925@itemx set machine h8300h
13926Condition @value{GDBN} for one of the two variants of the H8/300
13927architecture with @samp{set machine}. You can use @samp{show machine}
13928to check which variant is currently in effect.
104c1213
JM
13929
13930@end table
13931
8e04817f
AC
13932@node H8/500
13933@subsection H8/500
104c1213
JM
13934
13935@table @code
13936
8e04817f
AC
13937@kindex set memory @var{mod}
13938@cindex memory models, H8/500
13939@item set memory @var{mod}
13940@itemx show memory
13941Specify which H8/500 memory model (@var{mod}) you are using with
13942@samp{set memory}; check which memory model is in effect with @samp{show
13943memory}. The accepted values for @var{mod} are @code{small},
13944@code{big}, @code{medium}, and @code{compact}.
104c1213 13945
8e04817f 13946@end table
104c1213 13947
8e04817f 13948@node M32R/D
ba04e063 13949@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
13950
13951@table @code
8e04817f
AC
13952@kindex target m32r
13953@item target m32r @var{dev}
172c2a43 13954Renesas M32R/D ROM monitor.
8e04817f 13955
fb3e19c0
KI
13956@kindex target m32rsdi
13957@item target m32rsdi @var{dev}
13958Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
13959@end table
13960
13961The following @value{GDBN} commands are specific to the M32R monitor:
13962
13963@table @code
13964@item set download-path @var{path}
13965@kindex set download-path
13966@cindex find downloadable @sc{srec} files (M32R)
13967Set the default path for finding donwloadable @sc{srec} files.
13968
13969@item show download-path
13970@kindex show download-path
13971Show the default path for downloadable @sc{srec} files.
fb3e19c0 13972
721c2651
EZ
13973@item set board-address @var{addr}
13974@kindex set board-address
13975@cindex M32-EVA target board address
13976Set the IP address for the M32R-EVA target board.
13977
13978@item show board-address
13979@kindex show board-address
13980Show the current IP address of the target board.
13981
13982@item set server-address @var{addr}
13983@kindex set server-address
13984@cindex download server address (M32R)
13985Set the IP address for the download server, which is the @value{GDBN}'s
13986host machine.
13987
13988@item show server-address
13989@kindex show server-address
13990Display the IP address of the download server.
13991
13992@item upload @r{[}@var{file}@r{]}
13993@kindex upload@r{, M32R}
13994Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
13995upload capability. If no @var{file} argument is given, the current
13996executable file is uploaded.
13997
13998@item tload @r{[}@var{file}@r{]}
13999@kindex tload@r{, M32R}
14000Test the @code{upload} command.
8e04817f
AC
14001@end table
14002
ba04e063
EZ
14003The following commands are available for M32R/SDI:
14004
14005@table @code
14006@item sdireset
14007@kindex sdireset
14008@cindex reset SDI connection, M32R
14009This command resets the SDI connection.
14010
14011@item sdistatus
14012@kindex sdistatus
14013This command shows the SDI connection status.
14014
14015@item debug_chaos
14016@kindex debug_chaos
14017@cindex M32R/Chaos debugging
14018Instructs the remote that M32R/Chaos debugging is to be used.
14019
14020@item use_debug_dma
14021@kindex use_debug_dma
14022Instructs the remote to use the DEBUG_DMA method of accessing memory.
14023
14024@item use_mon_code
14025@kindex use_mon_code
14026Instructs the remote to use the MON_CODE method of accessing memory.
14027
14028@item use_ib_break
14029@kindex use_ib_break
14030Instructs the remote to set breakpoints by IB break.
14031
14032@item use_dbt_break
14033@kindex use_dbt_break
14034Instructs the remote to set breakpoints by DBT.
14035@end table
14036
8e04817f
AC
14037@node M68K
14038@subsection M68k
14039
14040The Motorola m68k configuration includes ColdFire support, and
14041target command for the following ROM monitors.
14042
14043@table @code
14044
14045@kindex target abug
14046@item target abug @var{dev}
14047ABug ROM monitor for M68K.
14048
14049@kindex target cpu32bug
14050@item target cpu32bug @var{dev}
14051CPU32BUG monitor, running on a CPU32 (M68K) board.
14052
14053@kindex target dbug
14054@item target dbug @var{dev}
14055dBUG ROM monitor for Motorola ColdFire.
14056
14057@kindex target est
14058@item target est @var{dev}
14059EST-300 ICE monitor, running on a CPU32 (M68K) board.
14060
14061@kindex target rom68k
14062@item target rom68k @var{dev}
14063ROM 68K monitor, running on an M68K IDP board.
14064
14065@end table
14066
8e04817f
AC
14067@table @code
14068
14069@kindex target rombug
14070@item target rombug @var{dev}
14071ROMBUG ROM monitor for OS/9000.
14072
14073@end table
14074
8e04817f
AC
14075@node MIPS Embedded
14076@subsection MIPS Embedded
14077
14078@cindex MIPS boards
14079@value{GDBN} can use the MIPS remote debugging protocol to talk to a
14080MIPS board attached to a serial line. This is available when
14081you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 14082
8e04817f
AC
14083@need 1000
14084Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 14085
8e04817f
AC
14086@table @code
14087@item target mips @var{port}
14088@kindex target mips @var{port}
14089To run a program on the board, start up @code{@value{GDBP}} with the
14090name of your program as the argument. To connect to the board, use the
14091command @samp{target mips @var{port}}, where @var{port} is the name of
14092the serial port connected to the board. If the program has not already
14093been downloaded to the board, you may use the @code{load} command to
14094download it. You can then use all the usual @value{GDBN} commands.
104c1213 14095
8e04817f
AC
14096For example, this sequence connects to the target board through a serial
14097port, and loads and runs a program called @var{prog} through the
14098debugger:
104c1213 14099
474c8240 14100@smallexample
8e04817f
AC
14101host$ @value{GDBP} @var{prog}
14102@value{GDBN} is free software and @dots{}
14103(@value{GDBP}) target mips /dev/ttyb
14104(@value{GDBP}) load @var{prog}
14105(@value{GDBP}) run
474c8240 14106@end smallexample
104c1213 14107
8e04817f
AC
14108@item target mips @var{hostname}:@var{portnumber}
14109On some @value{GDBN} host configurations, you can specify a TCP
14110connection (for instance, to a serial line managed by a terminal
14111concentrator) instead of a serial port, using the syntax
14112@samp{@var{hostname}:@var{portnumber}}.
104c1213 14113
8e04817f
AC
14114@item target pmon @var{port}
14115@kindex target pmon @var{port}
14116PMON ROM monitor.
104c1213 14117
8e04817f
AC
14118@item target ddb @var{port}
14119@kindex target ddb @var{port}
14120NEC's DDB variant of PMON for Vr4300.
104c1213 14121
8e04817f
AC
14122@item target lsi @var{port}
14123@kindex target lsi @var{port}
14124LSI variant of PMON.
104c1213 14125
8e04817f
AC
14126@kindex target r3900
14127@item target r3900 @var{dev}
14128Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 14129
8e04817f
AC
14130@kindex target array
14131@item target array @var{dev}
14132Array Tech LSI33K RAID controller board.
104c1213 14133
8e04817f 14134@end table
104c1213 14135
104c1213 14136
8e04817f
AC
14137@noindent
14138@value{GDBN} also supports these special commands for MIPS targets:
104c1213 14139
8e04817f 14140@table @code
8e04817f
AC
14141@item set mipsfpu double
14142@itemx set mipsfpu single
14143@itemx set mipsfpu none
a64548ea 14144@itemx set mipsfpu auto
8e04817f
AC
14145@itemx show mipsfpu
14146@kindex set mipsfpu
14147@kindex show mipsfpu
14148@cindex MIPS remote floating point
14149@cindex floating point, MIPS remote
14150If your target board does not support the MIPS floating point
14151coprocessor, you should use the command @samp{set mipsfpu none} (if you
14152need this, you may wish to put the command in your @value{GDBN} init
14153file). This tells @value{GDBN} how to find the return value of
14154functions which return floating point values. It also allows
14155@value{GDBN} to avoid saving the floating point registers when calling
14156functions on the board. If you are using a floating point coprocessor
14157with only single precision floating point support, as on the @sc{r4650}
14158processor, use the command @samp{set mipsfpu single}. The default
14159double precision floating point coprocessor may be selected using
14160@samp{set mipsfpu double}.
104c1213 14161
8e04817f
AC
14162In previous versions the only choices were double precision or no
14163floating point, so @samp{set mipsfpu on} will select double precision
14164and @samp{set mipsfpu off} will select no floating point.
104c1213 14165
8e04817f
AC
14166As usual, you can inquire about the @code{mipsfpu} variable with
14167@samp{show mipsfpu}.
104c1213 14168
8e04817f
AC
14169@item set timeout @var{seconds}
14170@itemx set retransmit-timeout @var{seconds}
14171@itemx show timeout
14172@itemx show retransmit-timeout
14173@cindex @code{timeout}, MIPS protocol
14174@cindex @code{retransmit-timeout}, MIPS protocol
14175@kindex set timeout
14176@kindex show timeout
14177@kindex set retransmit-timeout
14178@kindex show retransmit-timeout
14179You can control the timeout used while waiting for a packet, in the MIPS
14180remote protocol, with the @code{set timeout @var{seconds}} command. The
14181default is 5 seconds. Similarly, you can control the timeout used while
14182waiting for an acknowledgement of a packet with the @code{set
14183retransmit-timeout @var{seconds}} command. The default is 3 seconds.
14184You can inspect both values with @code{show timeout} and @code{show
14185retransmit-timeout}. (These commands are @emph{only} available when
14186@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 14187
8e04817f
AC
14188The timeout set by @code{set timeout} does not apply when @value{GDBN}
14189is waiting for your program to stop. In that case, @value{GDBN} waits
14190forever because it has no way of knowing how long the program is going
14191to run before stopping.
ba04e063
EZ
14192
14193@item set syn-garbage-limit @var{num}
14194@kindex set syn-garbage-limit@r{, MIPS remote}
14195@cindex synchronize with remote MIPS target
14196Limit the maximum number of characters @value{GDBN} should ignore when
14197it tries to synchronize with the remote target. The default is 10
14198characters. Setting the limit to -1 means there's no limit.
14199
14200@item show syn-garbage-limit
14201@kindex show syn-garbage-limit@r{, MIPS remote}
14202Show the current limit on the number of characters to ignore when
14203trying to synchronize with the remote system.
14204
14205@item set monitor-prompt @var{prompt}
14206@kindex set monitor-prompt@r{, MIPS remote}
14207@cindex remote monitor prompt
14208Tell @value{GDBN} to expect the specified @var{prompt} string from the
14209remote monitor. The default depends on the target:
14210@table @asis
14211@item pmon target
14212@samp{PMON}
14213@item ddb target
14214@samp{NEC010}
14215@item lsi target
14216@samp{PMON>}
14217@end table
14218
14219@item show monitor-prompt
14220@kindex show monitor-prompt@r{, MIPS remote}
14221Show the current strings @value{GDBN} expects as the prompt from the
14222remote monitor.
14223
14224@item set monitor-warnings
14225@kindex set monitor-warnings@r{, MIPS remote}
14226Enable or disable monitor warnings about hardware breakpoints. This
14227has effect only for the @code{lsi} target. When on, @value{GDBN} will
14228display warning messages whose codes are returned by the @code{lsi}
14229PMON monitor for breakpoint commands.
14230
14231@item show monitor-warnings
14232@kindex show monitor-warnings@r{, MIPS remote}
14233Show the current setting of printing monitor warnings.
14234
14235@item pmon @var{command}
14236@kindex pmon@r{, MIPS remote}
14237@cindex send PMON command
14238This command allows sending an arbitrary @var{command} string to the
14239monitor. The monitor must be in debug mode for this to work.
8e04817f 14240@end table
104c1213 14241
a37295f9
MM
14242@node OpenRISC 1000
14243@subsection OpenRISC 1000
14244@cindex OpenRISC 1000
14245
14246@cindex or1k boards
14247See OR1k Architecture document (@uref{www.opencores.org}) for more information
14248about platform and commands.
14249
14250@table @code
14251
14252@kindex target jtag
14253@item target jtag jtag://@var{host}:@var{port}
14254
14255Connects to remote JTAG server.
14256JTAG remote server can be either an or1ksim or JTAG server,
14257connected via parallel port to the board.
14258
14259Example: @code{target jtag jtag://localhost:9999}
14260
14261@kindex or1ksim
14262@item or1ksim @var{command}
14263If connected to @code{or1ksim} OpenRISC 1000 Architectural
14264Simulator, proprietary commands can be executed.
14265
14266@kindex info or1k spr
14267@item info or1k spr
14268Displays spr groups.
14269
14270@item info or1k spr @var{group}
14271@itemx info or1k spr @var{groupno}
14272Displays register names in selected group.
14273
14274@item info or1k spr @var{group} @var{register}
14275@itemx info or1k spr @var{register}
14276@itemx info or1k spr @var{groupno} @var{registerno}
14277@itemx info or1k spr @var{registerno}
14278Shows information about specified spr register.
14279
14280@kindex spr
14281@item spr @var{group} @var{register} @var{value}
14282@itemx spr @var{register @var{value}}
14283@itemx spr @var{groupno} @var{registerno @var{value}}
14284@itemx spr @var{registerno @var{value}}
14285Writes @var{value} to specified spr register.
14286@end table
14287
14288Some implementations of OpenRISC 1000 Architecture also have hardware trace.
14289It is very similar to @value{GDBN} trace, except it does not interfere with normal
14290program execution and is thus much faster. Hardware breakpoints/watchpoint
14291triggers can be set using:
14292@table @code
14293@item $LEA/$LDATA
14294Load effective address/data
14295@item $SEA/$SDATA
14296Store effective address/data
14297@item $AEA/$ADATA
14298Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
14299@item $FETCH
14300Fetch data
14301@end table
14302
14303When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
14304@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
14305
14306@code{htrace} commands:
14307@cindex OpenRISC 1000 htrace
14308@table @code
14309@kindex hwatch
14310@item hwatch @var{conditional}
14311Set hardware watchpoint on combination of Load/Store Effecive Address(es)
14312or Data. For example:
14313
14314@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14315
14316@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14317
4644b6e3 14318@kindex htrace
a37295f9
MM
14319@item htrace info
14320Display information about current HW trace configuration.
14321
a37295f9
MM
14322@item htrace trigger @var{conditional}
14323Set starting criteria for HW trace.
14324
a37295f9
MM
14325@item htrace qualifier @var{conditional}
14326Set acquisition qualifier for HW trace.
14327
a37295f9
MM
14328@item htrace stop @var{conditional}
14329Set HW trace stopping criteria.
14330
f153cc92 14331@item htrace record [@var{data}]*
a37295f9
MM
14332Selects the data to be recorded, when qualifier is met and HW trace was
14333triggered.
14334
a37295f9 14335@item htrace enable
a37295f9
MM
14336@itemx htrace disable
14337Enables/disables the HW trace.
14338
f153cc92 14339@item htrace rewind [@var{filename}]
a37295f9
MM
14340Clears currently recorded trace data.
14341
14342If filename is specified, new trace file is made and any newly collected data
14343will be written there.
14344
f153cc92 14345@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
14346Prints trace buffer, using current record configuration.
14347
a37295f9
MM
14348@item htrace mode continuous
14349Set continuous trace mode.
14350
a37295f9
MM
14351@item htrace mode suspend
14352Set suspend trace mode.
14353
14354@end table
14355
8e04817f
AC
14356@node PowerPC
14357@subsection PowerPC
104c1213
JM
14358
14359@table @code
8e04817f
AC
14360@kindex target dink32
14361@item target dink32 @var{dev}
14362DINK32 ROM monitor.
104c1213 14363
8e04817f
AC
14364@kindex target ppcbug
14365@item target ppcbug @var{dev}
14366@kindex target ppcbug1
14367@item target ppcbug1 @var{dev}
14368PPCBUG ROM monitor for PowerPC.
104c1213 14369
8e04817f
AC
14370@kindex target sds
14371@item target sds @var{dev}
14372SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 14373@end table
8e04817f 14374
c45da7e6
EZ
14375@cindex SDS protocol
14376The following commands specifi to the SDS protocol are supported
14377by@value{GDBN}:
14378
14379@table @code
14380@item set sdstimeout @var{nsec}
14381@kindex set sdstimeout
14382Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
14383default is 2 seconds.
14384
14385@item show sdstimeout
14386@kindex show sdstimeout
14387Show the current value of the SDS timeout.
14388
14389@item sds @var{command}
14390@kindex sds@r{, a command}
14391Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
14392@end table
14393
c45da7e6 14394
8e04817f
AC
14395@node PA
14396@subsection HP PA Embedded
104c1213
JM
14397
14398@table @code
14399
8e04817f
AC
14400@kindex target op50n
14401@item target op50n @var{dev}
14402OP50N monitor, running on an OKI HPPA board.
14403
14404@kindex target w89k
14405@item target w89k @var{dev}
14406W89K monitor, running on a Winbond HPPA board.
104c1213
JM
14407
14408@end table
14409
8e04817f 14410@node SH
172c2a43 14411@subsection Renesas SH
104c1213
JM
14412
14413@table @code
14414
172c2a43 14415@kindex target hms@r{, with Renesas SH}
8e04817f 14416@item target hms @var{dev}
172c2a43 14417A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
14418commands @code{device} and @code{speed} to control the serial line and
14419the communications speed used.
104c1213 14420
172c2a43 14421@kindex target e7000@r{, with Renesas SH}
8e04817f 14422@item target e7000 @var{dev}
172c2a43 14423E7000 emulator for Renesas SH.
104c1213 14424
8e04817f
AC
14425@kindex target sh3@r{, with SH}
14426@kindex target sh3e@r{, with SH}
14427@item target sh3 @var{dev}
14428@item target sh3e @var{dev}
172c2a43 14429Renesas SH-3 and SH-3E target systems.
104c1213 14430
8e04817f 14431@end table
104c1213 14432
8e04817f
AC
14433@node Sparclet
14434@subsection Tsqware Sparclet
104c1213 14435
8e04817f
AC
14436@cindex Sparclet
14437
14438@value{GDBN} enables developers to debug tasks running on
14439Sparclet targets from a Unix host.
14440@value{GDBN} uses code that runs on
14441both the Unix host and on the Sparclet target. The program
14442@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 14443
8e04817f
AC
14444@table @code
14445@item remotetimeout @var{args}
14446@kindex remotetimeout
14447@value{GDBN} supports the option @code{remotetimeout}.
14448This option is set by the user, and @var{args} represents the number of
14449seconds @value{GDBN} waits for responses.
104c1213
JM
14450@end table
14451
8e04817f
AC
14452@cindex compiling, on Sparclet
14453When compiling for debugging, include the options @samp{-g} to get debug
14454information and @samp{-Ttext} to relocate the program to where you wish to
14455load it on the target. You may also want to add the options @samp{-n} or
14456@samp{-N} in order to reduce the size of the sections. Example:
104c1213 14457
474c8240 14458@smallexample
8e04817f 14459sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 14460@end smallexample
104c1213 14461
8e04817f 14462You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 14463
474c8240 14464@smallexample
8e04817f 14465sparclet-aout-objdump --headers --syms prog
474c8240 14466@end smallexample
104c1213 14467
8e04817f
AC
14468@cindex running, on Sparclet
14469Once you have set
14470your Unix execution search path to find @value{GDBN}, you are ready to
14471run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
14472(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 14473
8e04817f
AC
14474@value{GDBN} comes up showing the prompt:
14475
474c8240 14476@smallexample
8e04817f 14477(gdbslet)
474c8240 14478@end smallexample
104c1213
JM
14479
14480@menu
8e04817f
AC
14481* Sparclet File:: Setting the file to debug
14482* Sparclet Connection:: Connecting to Sparclet
14483* Sparclet Download:: Sparclet download
14484* Sparclet Execution:: Running and debugging
104c1213
JM
14485@end menu
14486
8e04817f
AC
14487@node Sparclet File
14488@subsubsection Setting file to debug
104c1213 14489
8e04817f 14490The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 14491
474c8240 14492@smallexample
8e04817f 14493(gdbslet) file prog
474c8240 14494@end smallexample
104c1213 14495
8e04817f
AC
14496@need 1000
14497@value{GDBN} then attempts to read the symbol table of @file{prog}.
14498@value{GDBN} locates
14499the file by searching the directories listed in the command search
14500path.
14501If the file was compiled with debug information (option "-g"), source
14502files will be searched as well.
14503@value{GDBN} locates
14504the source files by searching the directories listed in the directory search
14505path (@pxref{Environment, ,Your program's environment}).
14506If it fails
14507to find a file, it displays a message such as:
104c1213 14508
474c8240 14509@smallexample
8e04817f 14510prog: No such file or directory.
474c8240 14511@end smallexample
104c1213 14512
8e04817f
AC
14513When this happens, add the appropriate directories to the search paths with
14514the @value{GDBN} commands @code{path} and @code{dir}, and execute the
14515@code{target} command again.
104c1213 14516
8e04817f
AC
14517@node Sparclet Connection
14518@subsubsection Connecting to Sparclet
104c1213 14519
8e04817f
AC
14520The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
14521To connect to a target on serial port ``@code{ttya}'', type:
104c1213 14522
474c8240 14523@smallexample
8e04817f
AC
14524(gdbslet) target sparclet /dev/ttya
14525Remote target sparclet connected to /dev/ttya
14526main () at ../prog.c:3
474c8240 14527@end smallexample
104c1213 14528
8e04817f
AC
14529@need 750
14530@value{GDBN} displays messages like these:
104c1213 14531
474c8240 14532@smallexample
8e04817f 14533Connected to ttya.
474c8240 14534@end smallexample
104c1213 14535
8e04817f
AC
14536@node Sparclet Download
14537@subsubsection Sparclet download
104c1213 14538
8e04817f
AC
14539@cindex download to Sparclet
14540Once connected to the Sparclet target,
14541you can use the @value{GDBN}
14542@code{load} command to download the file from the host to the target.
14543The file name and load offset should be given as arguments to the @code{load}
14544command.
14545Since the file format is aout, the program must be loaded to the starting
14546address. You can use @code{objdump} to find out what this value is. The load
14547offset is an offset which is added to the VMA (virtual memory address)
14548of each of the file's sections.
14549For instance, if the program
14550@file{prog} was linked to text address 0x1201000, with data at 0x12010160
14551and bss at 0x12010170, in @value{GDBN}, type:
104c1213 14552
474c8240 14553@smallexample
8e04817f
AC
14554(gdbslet) load prog 0x12010000
14555Loading section .text, size 0xdb0 vma 0x12010000
474c8240 14556@end smallexample
104c1213 14557
8e04817f
AC
14558If the code is loaded at a different address then what the program was linked
14559to, you may need to use the @code{section} and @code{add-symbol-file} commands
14560to tell @value{GDBN} where to map the symbol table.
14561
14562@node Sparclet Execution
14563@subsubsection Running and debugging
14564
14565@cindex running and debugging Sparclet programs
14566You can now begin debugging the task using @value{GDBN}'s execution control
14567commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
14568manual for the list of commands.
14569
474c8240 14570@smallexample
8e04817f
AC
14571(gdbslet) b main
14572Breakpoint 1 at 0x12010000: file prog.c, line 3.
14573(gdbslet) run
14574Starting program: prog
14575Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
145763 char *symarg = 0;
14577(gdbslet) step
145784 char *execarg = "hello!";
14579(gdbslet)
474c8240 14580@end smallexample
8e04817f
AC
14581
14582@node Sparclite
14583@subsection Fujitsu Sparclite
104c1213
JM
14584
14585@table @code
14586
8e04817f
AC
14587@kindex target sparclite
14588@item target sparclite @var{dev}
14589Fujitsu sparclite boards, used only for the purpose of loading.
14590You must use an additional command to debug the program.
14591For example: target remote @var{dev} using @value{GDBN} standard
14592remote protocol.
104c1213
JM
14593
14594@end table
14595
8e04817f
AC
14596@node ST2000
14597@subsection Tandem ST2000
104c1213 14598
8e04817f
AC
14599@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
14600STDBUG protocol.
104c1213 14601
8e04817f
AC
14602To connect your ST2000 to the host system, see the manufacturer's
14603manual. Once the ST2000 is physically attached, you can run:
104c1213 14604
474c8240 14605@smallexample
8e04817f 14606target st2000 @var{dev} @var{speed}
474c8240 14607@end smallexample
104c1213 14608
8e04817f
AC
14609@noindent
14610to establish it as your debugging environment. @var{dev} is normally
14611the name of a serial device, such as @file{/dev/ttya}, connected to the
14612ST2000 via a serial line. You can instead specify @var{dev} as a TCP
14613connection (for example, to a serial line attached via a terminal
14614concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 14615
8e04817f
AC
14616The @code{load} and @code{attach} commands are @emph{not} defined for
14617this target; you must load your program into the ST2000 as you normally
14618would for standalone operation. @value{GDBN} reads debugging information
14619(such as symbols) from a separate, debugging version of the program
14620available on your host computer.
14621@c FIXME!! This is terribly vague; what little content is here is
14622@c basically hearsay.
104c1213 14623
8e04817f
AC
14624@cindex ST2000 auxiliary commands
14625These auxiliary @value{GDBN} commands are available to help you with the ST2000
14626environment:
104c1213 14627
8e04817f
AC
14628@table @code
14629@item st2000 @var{command}
14630@kindex st2000 @var{cmd}
14631@cindex STDBUG commands (ST2000)
14632@cindex commands to STDBUG (ST2000)
14633Send a @var{command} to the STDBUG monitor. See the manufacturer's
14634manual for available commands.
104c1213 14635
8e04817f
AC
14636@item connect
14637@cindex connect (to STDBUG)
14638Connect the controlling terminal to the STDBUG command monitor. When
14639you are done interacting with STDBUG, typing either of two character
14640sequences gets you back to the @value{GDBN} command prompt:
14641@kbd{@key{RET}~.} (Return, followed by tilde and period) or
14642@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
14643@end table
14644
8e04817f
AC
14645@node Z8000
14646@subsection Zilog Z8000
104c1213 14647
8e04817f
AC
14648@cindex Z8000
14649@cindex simulator, Z8000
14650@cindex Zilog Z8000 simulator
104c1213 14651
8e04817f
AC
14652When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
14653a Z8000 simulator.
14654
14655For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
14656unsegmented variant of the Z8000 architecture) or the Z8001 (the
14657segmented variant). The simulator recognizes which architecture is
14658appropriate by inspecting the object code.
104c1213 14659
8e04817f
AC
14660@table @code
14661@item target sim @var{args}
14662@kindex sim
14663@kindex target sim@r{, with Z8000}
14664Debug programs on a simulated CPU. If the simulator supports setup
14665options, specify them via @var{args}.
104c1213
JM
14666@end table
14667
8e04817f
AC
14668@noindent
14669After specifying this target, you can debug programs for the simulated
14670CPU in the same style as programs for your host computer; use the
14671@code{file} command to load a new program image, the @code{run} command
14672to run your program, and so on.
14673
14674As well as making available all the usual machine registers
14675(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
14676additional items of information as specially named registers:
104c1213
JM
14677
14678@table @code
14679
8e04817f
AC
14680@item cycles
14681Counts clock-ticks in the simulator.
104c1213 14682
8e04817f
AC
14683@item insts
14684Counts instructions run in the simulator.
104c1213 14685
8e04817f
AC
14686@item time
14687Execution time in 60ths of a second.
104c1213 14688
8e04817f 14689@end table
104c1213 14690
8e04817f
AC
14691You can refer to these values in @value{GDBN} expressions with the usual
14692conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
14693conditional breakpoint that suspends only after at least 5000
14694simulated clock ticks.
104c1213 14695
a64548ea
EZ
14696@node AVR
14697@subsection Atmel AVR
14698@cindex AVR
14699
14700When configured for debugging the Atmel AVR, @value{GDBN} supports the
14701following AVR-specific commands:
14702
14703@table @code
14704@item info io_registers
14705@kindex info io_registers@r{, AVR}
14706@cindex I/O registers (Atmel AVR)
14707This command displays information about the AVR I/O registers. For
14708each register, @value{GDBN} prints its number and value.
14709@end table
14710
14711@node CRIS
14712@subsection CRIS
14713@cindex CRIS
14714
14715When configured for debugging CRIS, @value{GDBN} provides the
14716following CRIS-specific commands:
14717
14718@table @code
14719@item set cris-version @var{ver}
14720@cindex CRIS version
e22e55c9
OF
14721Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
14722The CRIS version affects register names and sizes. This command is useful in
14723case autodetection of the CRIS version fails.
a64548ea
EZ
14724
14725@item show cris-version
14726Show the current CRIS version.
14727
14728@item set cris-dwarf2-cfi
14729@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
14730Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
14731Change to @samp{off} when using @code{gcc-cris} whose version is below
14732@code{R59}.
a64548ea
EZ
14733
14734@item show cris-dwarf2-cfi
14735Show the current state of using DWARF-2 CFI.
e22e55c9
OF
14736
14737@item set cris-mode @var{mode}
14738@cindex CRIS mode
14739Set the current CRIS mode to @var{mode}. It should only be changed when
14740debugging in guru mode, in which case it should be set to
14741@samp{guru} (the default is @samp{normal}).
14742
14743@item show cris-mode
14744Show the current CRIS mode.
a64548ea
EZ
14745@end table
14746
14747@node Super-H
14748@subsection Renesas Super-H
14749@cindex Super-H
14750
14751For the Renesas Super-H processor, @value{GDBN} provides these
14752commands:
14753
14754@table @code
14755@item regs
14756@kindex regs@r{, Super-H}
14757Show the values of all Super-H registers.
14758@end table
14759
c45da7e6
EZ
14760@node WinCE
14761@subsection Windows CE
14762@cindex Windows CE
14763
14764The following commands are available for Windows CE:
14765
14766@table @code
14767@item set remotedirectory @var{dir}
14768@kindex set remotedirectory
14769Tell @value{GDBN} to upload files from the named directory @var{dir}.
14770The default is @file{/gdb}, i.e.@: the root directory on the current
14771drive.
14772
14773@item show remotedirectory
14774@kindex show remotedirectory
14775Show the current value of the upload directory.
14776
14777@item set remoteupload @var{method}
14778@kindex set remoteupload
14779Set the method used to upload files to remote device. Valid values
14780for @var{method} are @samp{always}, @samp{newer}, and @samp{never}.
14781The default is @samp{newer}.
14782
14783@item show remoteupload
14784@kindex show remoteupload
14785Show the current setting of the upload method.
14786
14787@item set remoteaddhost
14788@kindex set remoteaddhost
14789Tell @value{GDBN} whether to add this host to the remote stub's
14790arguments when you debug over a network.
14791
14792@item show remoteaddhost
14793@kindex show remoteaddhost
14794Show whether to add this host to remote stub's arguments when
14795debugging over a network.
14796@end table
14797
a64548ea 14798
8e04817f
AC
14799@node Architectures
14800@section Architectures
104c1213 14801
8e04817f
AC
14802This section describes characteristics of architectures that affect
14803all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 14804
8e04817f 14805@menu
9c16f35a 14806* i386::
8e04817f
AC
14807* A29K::
14808* Alpha::
14809* MIPS::
a64548ea 14810* HPPA:: HP PA architecture
8e04817f 14811@end menu
104c1213 14812
9c16f35a
EZ
14813@node i386
14814@subsection x86 Architecture-specific issues.
14815
14816@table @code
14817@item set struct-convention @var{mode}
14818@kindex set struct-convention
14819@cindex struct return convention
14820@cindex struct/union returned in registers
14821Set the convention used by the inferior to return @code{struct}s and
14822@code{union}s from functions to @var{mode}. Possible values of
14823@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
14824default). @code{"default"} or @code{"pcc"} means that @code{struct}s
14825are returned on the stack, while @code{"reg"} means that a
14826@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
14827be returned in a register.
14828
14829@item show struct-convention
14830@kindex show struct-convention
14831Show the current setting of the convention to return @code{struct}s
14832from functions.
14833@end table
14834
8e04817f
AC
14835@node A29K
14836@subsection A29K
104c1213
JM
14837
14838@table @code
104c1213 14839
8e04817f
AC
14840@kindex set rstack_high_address
14841@cindex AMD 29K register stack
14842@cindex register stack, AMD29K
14843@item set rstack_high_address @var{address}
14844On AMD 29000 family processors, registers are saved in a separate
14845@dfn{register stack}. There is no way for @value{GDBN} to determine the
14846extent of this stack. Normally, @value{GDBN} just assumes that the
14847stack is ``large enough''. This may result in @value{GDBN} referencing
14848memory locations that do not exist. If necessary, you can get around
14849this problem by specifying the ending address of the register stack with
14850the @code{set rstack_high_address} command. The argument should be an
14851address, which you probably want to precede with @samp{0x} to specify in
14852hexadecimal.
104c1213 14853
8e04817f
AC
14854@kindex show rstack_high_address
14855@item show rstack_high_address
14856Display the current limit of the register stack, on AMD 29000 family
14857processors.
104c1213 14858
8e04817f 14859@end table
104c1213 14860
8e04817f
AC
14861@node Alpha
14862@subsection Alpha
104c1213 14863
8e04817f 14864See the following section.
104c1213 14865
8e04817f
AC
14866@node MIPS
14867@subsection MIPS
104c1213 14868
8e04817f
AC
14869@cindex stack on Alpha
14870@cindex stack on MIPS
14871@cindex Alpha stack
14872@cindex MIPS stack
14873Alpha- and MIPS-based computers use an unusual stack frame, which
14874sometimes requires @value{GDBN} to search backward in the object code to
14875find the beginning of a function.
104c1213 14876
8e04817f
AC
14877@cindex response time, MIPS debugging
14878To improve response time (especially for embedded applications, where
14879@value{GDBN} may be restricted to a slow serial line for this search)
14880you may want to limit the size of this search, using one of these
14881commands:
104c1213 14882
8e04817f
AC
14883@table @code
14884@cindex @code{heuristic-fence-post} (Alpha, MIPS)
14885@item set heuristic-fence-post @var{limit}
14886Restrict @value{GDBN} to examining at most @var{limit} bytes in its
14887search for the beginning of a function. A value of @var{0} (the
14888default) means there is no limit. However, except for @var{0}, the
14889larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
14890and therefore the longer it takes to run. You should only need to use
14891this command when debugging a stripped executable.
104c1213 14892
8e04817f
AC
14893@item show heuristic-fence-post
14894Display the current limit.
14895@end table
104c1213
JM
14896
14897@noindent
8e04817f
AC
14898These commands are available @emph{only} when @value{GDBN} is configured
14899for debugging programs on Alpha or MIPS processors.
104c1213 14900
a64548ea
EZ
14901Several MIPS-specific commands are available when debugging MIPS
14902programs:
14903
14904@table @code
14905@item set mips saved-gpreg-size @var{size}
14906@kindex set mips saved-gpreg-size
14907@cindex MIPS GP register size on stack
14908Set the size of MIPS general-purpose registers saved on the stack.
14909The argument @var{size} can be one of the following:
14910
14911@table @samp
14912@item 32
1491332-bit GP registers
14914@item 64
1491564-bit GP registers
14916@item auto
14917Use the target's default setting or autodetect the saved size from the
14918information contained in the executable. This is the default
14919@end table
14920
14921@item show mips saved-gpreg-size
14922@kindex show mips saved-gpreg-size
14923Show the current size of MIPS GP registers on the stack.
14924
14925@item set mips stack-arg-size @var{size}
14926@kindex set mips stack-arg-size
14927@cindex MIPS stack space for arguments
14928Set the amount of stack space reserved for arguments to functions.
14929The argument can be one of @code{"32"}, @code{"64"} or @code{"auto"}
14930(the default).
14931
14932@item set mips abi @var{arg}
14933@kindex set mips abi
14934@cindex set ABI for MIPS
14935Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
14936values of @var{arg} are:
14937
14938@table @samp
14939@item auto
14940The default ABI associated with the current binary (this is the
14941default).
14942@item o32
14943@item o64
14944@item n32
14945@item n64
14946@item eabi32
14947@item eabi64
14948@item auto
14949@end table
14950
14951@item show mips abi
14952@kindex show mips abi
14953Show the MIPS ABI used by @value{GDBN} to debug the inferior.
14954
14955@item set mipsfpu
14956@itemx show mipsfpu
14957@xref{MIPS Embedded, set mipsfpu}.
14958
14959@item set mips mask-address @var{arg}
14960@kindex set mips mask-address
14961@cindex MIPS addresses, masking
14962This command determines whether the most-significant 32 bits of 64-bit
14963MIPS addresses are masked off. The argument @var{arg} can be
14964@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
14965setting, which lets @value{GDBN} determine the correct value.
14966
14967@item show mips mask-address
14968@kindex show mips mask-address
14969Show whether the upper 32 bits of MIPS addresses are masked off or
14970not.
14971
14972@item set remote-mips64-transfers-32bit-regs
14973@kindex set remote-mips64-transfers-32bit-regs
14974This command controls compatibility with 64-bit MIPS targets that
14975transfer data in 32-bit quantities. If you have an old MIPS 64 target
14976that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
14977and 64 bits for other registers, set this option to @samp{on}.
14978
14979@item show remote-mips64-transfers-32bit-regs
14980@kindex show remote-mips64-transfers-32bit-regs
14981Show the current setting of compatibility with older MIPS 64 targets.
14982
14983@item set debug mips
14984@kindex set debug mips
14985This command turns on and off debugging messages for the MIPS-specific
14986target code in @value{GDBN}.
14987
14988@item show debug mips
14989@kindex show debug mips
14990Show the current setting of MIPS debugging messages.
14991@end table
14992
14993
14994@node HPPA
14995@subsection HPPA
14996@cindex HPPA support
14997
14998When @value{GDBN} is debugging te HP PA architecture, it provides the
14999following special commands:
15000
15001@table @code
15002@item set debug hppa
15003@kindex set debug hppa
15004THis command determines whether HPPA architecture specific debugging
15005messages are to be displayed.
15006
15007@item show debug hppa
15008Show whether HPPA debugging messages are displayed.
15009
15010@item maint print unwind @var{address}
15011@kindex maint print unwind@r{, HPPA}
15012This command displays the contents of the unwind table entry at the
15013given @var{address}.
15014
15015@end table
15016
104c1213 15017
8e04817f
AC
15018@node Controlling GDB
15019@chapter Controlling @value{GDBN}
15020
15021You can alter the way @value{GDBN} interacts with you by using the
15022@code{set} command. For commands controlling how @value{GDBN} displays
15023data, see @ref{Print Settings, ,Print settings}. Other settings are
15024described here.
15025
15026@menu
15027* Prompt:: Prompt
15028* Editing:: Command editing
d620b259 15029* Command History:: Command history
8e04817f
AC
15030* Screen Size:: Screen size
15031* Numbers:: Numbers
1e698235 15032* ABI:: Configuring the current ABI
8e04817f
AC
15033* Messages/Warnings:: Optional warnings and messages
15034* Debugging Output:: Optional messages about internal happenings
15035@end menu
15036
15037@node Prompt
15038@section Prompt
104c1213 15039
8e04817f 15040@cindex prompt
104c1213 15041
8e04817f
AC
15042@value{GDBN} indicates its readiness to read a command by printing a string
15043called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
15044can change the prompt string with the @code{set prompt} command. For
15045instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
15046the prompt in one of the @value{GDBN} sessions so that you can always tell
15047which one you are talking to.
104c1213 15048
8e04817f
AC
15049@emph{Note:} @code{set prompt} does not add a space for you after the
15050prompt you set. This allows you to set a prompt which ends in a space
15051or a prompt that does not.
104c1213 15052
8e04817f
AC
15053@table @code
15054@kindex set prompt
15055@item set prompt @var{newprompt}
15056Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 15057
8e04817f
AC
15058@kindex show prompt
15059@item show prompt
15060Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
15061@end table
15062
8e04817f
AC
15063@node Editing
15064@section Command editing
15065@cindex readline
15066@cindex command line editing
104c1213 15067
703663ab 15068@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
15069@sc{gnu} library provides consistent behavior for programs which provide a
15070command line interface to the user. Advantages are @sc{gnu} Emacs-style
15071or @dfn{vi}-style inline editing of commands, @code{csh}-like history
15072substitution, and a storage and recall of command history across
15073debugging sessions.
104c1213 15074
8e04817f
AC
15075You may control the behavior of command line editing in @value{GDBN} with the
15076command @code{set}.
104c1213 15077
8e04817f
AC
15078@table @code
15079@kindex set editing
15080@cindex editing
15081@item set editing
15082@itemx set editing on
15083Enable command line editing (enabled by default).
104c1213 15084
8e04817f
AC
15085@item set editing off
15086Disable command line editing.
104c1213 15087
8e04817f
AC
15088@kindex show editing
15089@item show editing
15090Show whether command line editing is enabled.
104c1213
JM
15091@end table
15092
703663ab
EZ
15093@xref{Command Line Editing}, for more details about the Readline
15094interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
15095encouraged to read that chapter.
15096
d620b259 15097@node Command History
8e04817f 15098@section Command history
703663ab 15099@cindex command history
8e04817f
AC
15100
15101@value{GDBN} can keep track of the commands you type during your
15102debugging sessions, so that you can be certain of precisely what
15103happened. Use these commands to manage the @value{GDBN} command
15104history facility.
104c1213 15105
703663ab
EZ
15106@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
15107package, to provide the history facility. @xref{Using History
15108Interactively}, for the detailed description of the History library.
15109
d620b259
NR
15110To issue a command to @value{GDBN} without affecting certain aspects of
15111the state which is seen by users, prefix it with @samp{server }. This
15112means that this command will not affect the command history, nor will it
15113affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
15114pressed on a line by itself.
15115
15116@cindex @code{server}, command prefix
15117The server prefix does not affect the recording of values into the value
15118history; to print a value without recording it into the value history,
15119use the @code{output} command instead of the @code{print} command.
15120
703663ab
EZ
15121Here is the description of @value{GDBN} commands related to command
15122history.
15123
104c1213 15124@table @code
8e04817f
AC
15125@cindex history substitution
15126@cindex history file
15127@kindex set history filename
4644b6e3 15128@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
15129@item set history filename @var{fname}
15130Set the name of the @value{GDBN} command history file to @var{fname}.
15131This is the file where @value{GDBN} reads an initial command history
15132list, and where it writes the command history from this session when it
15133exits. You can access this list through history expansion or through
15134the history command editing characters listed below. This file defaults
15135to the value of the environment variable @code{GDBHISTFILE}, or to
15136@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
15137is not set.
104c1213 15138
9c16f35a
EZ
15139@cindex save command history
15140@kindex set history save
8e04817f
AC
15141@item set history save
15142@itemx set history save on
15143Record command history in a file, whose name may be specified with the
15144@code{set history filename} command. By default, this option is disabled.
104c1213 15145
8e04817f
AC
15146@item set history save off
15147Stop recording command history in a file.
104c1213 15148
8e04817f 15149@cindex history size
9c16f35a 15150@kindex set history size
6fc08d32 15151@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
15152@item set history size @var{size}
15153Set the number of commands which @value{GDBN} keeps in its history list.
15154This defaults to the value of the environment variable
15155@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
15156@end table
15157
8e04817f 15158History expansion assigns special meaning to the character @kbd{!}.
703663ab 15159@xref{Event Designators}, for more details.
8e04817f 15160
703663ab 15161@cindex history expansion, turn on/off
8e04817f
AC
15162Since @kbd{!} is also the logical not operator in C, history expansion
15163is off by default. If you decide to enable history expansion with the
15164@code{set history expansion on} command, you may sometimes need to
15165follow @kbd{!} (when it is used as logical not, in an expression) with
15166a space or a tab to prevent it from being expanded. The readline
15167history facilities do not attempt substitution on the strings
15168@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
15169
15170The commands to control history expansion are:
104c1213
JM
15171
15172@table @code
8e04817f
AC
15173@item set history expansion on
15174@itemx set history expansion
703663ab 15175@kindex set history expansion
8e04817f 15176Enable history expansion. History expansion is off by default.
104c1213 15177
8e04817f
AC
15178@item set history expansion off
15179Disable history expansion.
104c1213 15180
8e04817f
AC
15181@c @group
15182@kindex show history
15183@item show history
15184@itemx show history filename
15185@itemx show history save
15186@itemx show history size
15187@itemx show history expansion
15188These commands display the state of the @value{GDBN} history parameters.
15189@code{show history} by itself displays all four states.
15190@c @end group
15191@end table
15192
15193@table @code
9c16f35a
EZ
15194@kindex show commands
15195@cindex show last commands
15196@cindex display command history
8e04817f
AC
15197@item show commands
15198Display the last ten commands in the command history.
104c1213 15199
8e04817f
AC
15200@item show commands @var{n}
15201Print ten commands centered on command number @var{n}.
15202
15203@item show commands +
15204Print ten commands just after the commands last printed.
104c1213
JM
15205@end table
15206
8e04817f
AC
15207@node Screen Size
15208@section Screen size
15209@cindex size of screen
15210@cindex pauses in output
104c1213 15211
8e04817f
AC
15212Certain commands to @value{GDBN} may produce large amounts of
15213information output to the screen. To help you read all of it,
15214@value{GDBN} pauses and asks you for input at the end of each page of
15215output. Type @key{RET} when you want to continue the output, or @kbd{q}
15216to discard the remaining output. Also, the screen width setting
15217determines when to wrap lines of output. Depending on what is being
15218printed, @value{GDBN} tries to break the line at a readable place,
15219rather than simply letting it overflow onto the following line.
15220
15221Normally @value{GDBN} knows the size of the screen from the terminal
15222driver software. For example, on Unix @value{GDBN} uses the termcap data base
15223together with the value of the @code{TERM} environment variable and the
15224@code{stty rows} and @code{stty cols} settings. If this is not correct,
15225you can override it with the @code{set height} and @code{set
15226width} commands:
15227
15228@table @code
15229@kindex set height
15230@kindex set width
15231@kindex show width
15232@kindex show height
15233@item set height @var{lpp}
15234@itemx show height
15235@itemx set width @var{cpl}
15236@itemx show width
15237These @code{set} commands specify a screen height of @var{lpp} lines and
15238a screen width of @var{cpl} characters. The associated @code{show}
15239commands display the current settings.
104c1213 15240
8e04817f
AC
15241If you specify a height of zero lines, @value{GDBN} does not pause during
15242output no matter how long the output is. This is useful if output is to a
15243file or to an editor buffer.
104c1213 15244
8e04817f
AC
15245Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
15246from wrapping its output.
9c16f35a
EZ
15247
15248@item set pagination on
15249@itemx set pagination off
15250@kindex set pagination
15251Turn the output pagination on or off; the default is on. Turning
15252pagination off is the alternative to @code{set height 0}.
15253
15254@item show pagination
15255@kindex show pagination
15256Show the current pagination mode.
104c1213
JM
15257@end table
15258
8e04817f
AC
15259@node Numbers
15260@section Numbers
15261@cindex number representation
15262@cindex entering numbers
104c1213 15263
8e04817f
AC
15264You can always enter numbers in octal, decimal, or hexadecimal in
15265@value{GDBN} by the usual conventions: octal numbers begin with
15266@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
15267begin with @samp{0x}. Numbers that neither begin with @samp{0} or
15268@samp{0x}, nor end with a @samp{.} are, by default, entered in base
1526910; likewise, the default display for numbers---when no particular
15270format is specified---is base 10. You can change the default base for
15271both input and output with the commands described below.
104c1213 15272
8e04817f
AC
15273@table @code
15274@kindex set input-radix
15275@item set input-radix @var{base}
15276Set the default base for numeric input. Supported choices
15277for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15278specified either unambiguously or using the current input radix; for
8e04817f 15279example, any of
104c1213 15280
8e04817f 15281@smallexample
9c16f35a
EZ
15282set input-radix 012
15283set input-radix 10.
15284set input-radix 0xa
8e04817f 15285@end smallexample
104c1213 15286
8e04817f 15287@noindent
9c16f35a 15288sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
15289leaves the input radix unchanged, no matter what it was, since
15290@samp{10}, being without any leading or trailing signs of its base, is
15291interpreted in the current radix. Thus, if the current radix is 16,
15292@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
15293change the radix.
104c1213 15294
8e04817f
AC
15295@kindex set output-radix
15296@item set output-radix @var{base}
15297Set the default base for numeric display. Supported choices
15298for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15299specified either unambiguously or using the current input radix.
104c1213 15300
8e04817f
AC
15301@kindex show input-radix
15302@item show input-radix
15303Display the current default base for numeric input.
104c1213 15304
8e04817f
AC
15305@kindex show output-radix
15306@item show output-radix
15307Display the current default base for numeric display.
9c16f35a
EZ
15308
15309@item set radix @r{[}@var{base}@r{]}
15310@itemx show radix
15311@kindex set radix
15312@kindex show radix
15313These commands set and show the default base for both input and output
15314of numbers. @code{set radix} sets the radix of input and output to
15315the same base; without an argument, it resets the radix back to its
15316default value of 10.
15317
8e04817f 15318@end table
104c1213 15319
1e698235
DJ
15320@node ABI
15321@section Configuring the current ABI
15322
15323@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
15324application automatically. However, sometimes you need to override its
15325conclusions. Use these commands to manage @value{GDBN}'s view of the
15326current ABI.
15327
98b45e30
DJ
15328@cindex OS ABI
15329@kindex set osabi
b4e9345d 15330@kindex show osabi
98b45e30
DJ
15331
15332One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 15333system targets, either via remote debugging or native emulation.
98b45e30
DJ
15334@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
15335but you can override its conclusion using the @code{set osabi} command.
15336One example where this is useful is in debugging of binaries which use
15337an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
15338not have the same identifying marks that the standard C library for your
15339platform provides.
15340
15341@table @code
15342@item show osabi
15343Show the OS ABI currently in use.
15344
15345@item set osabi
15346With no argument, show the list of registered available OS ABI's.
15347
15348@item set osabi @var{abi}
15349Set the current OS ABI to @var{abi}.
15350@end table
15351
1e698235 15352@cindex float promotion
1e698235
DJ
15353
15354Generally, the way that an argument of type @code{float} is passed to a
15355function depends on whether the function is prototyped. For a prototyped
15356(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
15357according to the architecture's convention for @code{float}. For unprototyped
15358(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
15359@code{double} and then passed.
15360
15361Unfortunately, some forms of debug information do not reliably indicate whether
15362a function is prototyped. If @value{GDBN} calls a function that is not marked
15363as prototyped, it consults @kbd{set coerce-float-to-double}.
15364
15365@table @code
a8f24a35 15366@kindex set coerce-float-to-double
1e698235
DJ
15367@item set coerce-float-to-double
15368@itemx set coerce-float-to-double on
15369Arguments of type @code{float} will be promoted to @code{double} when passed
15370to an unprototyped function. This is the default setting.
15371
15372@item set coerce-float-to-double off
15373Arguments of type @code{float} will be passed directly to unprototyped
15374functions.
9c16f35a
EZ
15375
15376@kindex show coerce-float-to-double
15377@item show coerce-float-to-double
15378Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
15379@end table
15380
f1212245
DJ
15381@kindex set cp-abi
15382@kindex show cp-abi
15383@value{GDBN} needs to know the ABI used for your program's C@t{++}
15384objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
15385used to build your application. @value{GDBN} only fully supports
15386programs with a single C@t{++} ABI; if your program contains code using
15387multiple C@t{++} ABI's or if @value{GDBN} can not identify your
15388program's ABI correctly, you can tell @value{GDBN} which ABI to use.
15389Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
15390before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
15391``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
15392use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
15393``auto''.
15394
15395@table @code
15396@item show cp-abi
15397Show the C@t{++} ABI currently in use.
15398
15399@item set cp-abi
15400With no argument, show the list of supported C@t{++} ABI's.
15401
15402@item set cp-abi @var{abi}
15403@itemx set cp-abi auto
15404Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
15405@end table
15406
8e04817f
AC
15407@node Messages/Warnings
15408@section Optional warnings and messages
104c1213 15409
9c16f35a
EZ
15410@cindex verbose operation
15411@cindex optional warnings
8e04817f
AC
15412By default, @value{GDBN} is silent about its inner workings. If you are
15413running on a slow machine, you may want to use the @code{set verbose}
15414command. This makes @value{GDBN} tell you when it does a lengthy
15415internal operation, so you will not think it has crashed.
104c1213 15416
8e04817f
AC
15417Currently, the messages controlled by @code{set verbose} are those
15418which announce that the symbol table for a source file is being read;
15419see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 15420
8e04817f
AC
15421@table @code
15422@kindex set verbose
15423@item set verbose on
15424Enables @value{GDBN} output of certain informational messages.
104c1213 15425
8e04817f
AC
15426@item set verbose off
15427Disables @value{GDBN} output of certain informational messages.
104c1213 15428
8e04817f
AC
15429@kindex show verbose
15430@item show verbose
15431Displays whether @code{set verbose} is on or off.
15432@end table
104c1213 15433
8e04817f
AC
15434By default, if @value{GDBN} encounters bugs in the symbol table of an
15435object file, it is silent; but if you are debugging a compiler, you may
15436find this information useful (@pxref{Symbol Errors, ,Errors reading
15437symbol files}).
104c1213 15438
8e04817f 15439@table @code
104c1213 15440
8e04817f
AC
15441@kindex set complaints
15442@item set complaints @var{limit}
15443Permits @value{GDBN} to output @var{limit} complaints about each type of
15444unusual symbols before becoming silent about the problem. Set
15445@var{limit} to zero to suppress all complaints; set it to a large number
15446to prevent complaints from being suppressed.
104c1213 15447
8e04817f
AC
15448@kindex show complaints
15449@item show complaints
15450Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 15451
8e04817f 15452@end table
104c1213 15453
8e04817f
AC
15454By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
15455lot of stupid questions to confirm certain commands. For example, if
15456you try to run a program which is already running:
104c1213 15457
474c8240 15458@smallexample
8e04817f
AC
15459(@value{GDBP}) run
15460The program being debugged has been started already.
15461Start it from the beginning? (y or n)
474c8240 15462@end smallexample
104c1213 15463
8e04817f
AC
15464If you are willing to unflinchingly face the consequences of your own
15465commands, you can disable this ``feature'':
104c1213 15466
8e04817f 15467@table @code
104c1213 15468
8e04817f
AC
15469@kindex set confirm
15470@cindex flinching
15471@cindex confirmation
15472@cindex stupid questions
15473@item set confirm off
15474Disables confirmation requests.
104c1213 15475
8e04817f
AC
15476@item set confirm on
15477Enables confirmation requests (the default).
104c1213 15478
8e04817f
AC
15479@kindex show confirm
15480@item show confirm
15481Displays state of confirmation requests.
15482
15483@end table
104c1213 15484
8e04817f
AC
15485@node Debugging Output
15486@section Optional messages about internal happenings
4644b6e3
EZ
15487@cindex optional debugging messages
15488
da316a69
EZ
15489@value{GDBN} has commands that enable optional debugging messages from
15490various @value{GDBN} subsystems; normally these commands are of
15491interest to @value{GDBN} maintainers, or when reporting a bug. This
15492section documents those commands.
15493
104c1213 15494@table @code
a8f24a35
EZ
15495@kindex set exec-done-display
15496@item set exec-done-display
15497Turns on or off the notification of asynchronous commands'
15498completion. When on, @value{GDBN} will print a message when an
15499asynchronous command finishes its execution. The default is off.
15500@kindex show exec-done-display
15501@item show exec-done-display
15502Displays the current setting of asynchronous command completion
15503notification.
4644b6e3
EZ
15504@kindex set debug
15505@cindex gdbarch debugging info
a8f24a35 15506@cindex architecture debugging info
8e04817f 15507@item set debug arch
a8f24a35 15508Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 15509@kindex show debug
8e04817f
AC
15510@item show debug arch
15511Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
15512@item set debug aix-thread
15513@cindex AIX threads
15514Display debugging messages about inner workings of the AIX thread
15515module.
15516@item show debug aix-thread
15517Show the current state of AIX thread debugging info display.
8e04817f 15518@item set debug event
4644b6e3 15519@cindex event debugging info
a8f24a35 15520Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 15521default is off.
8e04817f
AC
15522@item show debug event
15523Displays the current state of displaying @value{GDBN} event debugging
15524info.
8e04817f 15525@item set debug expression
4644b6e3 15526@cindex expression debugging info
721c2651
EZ
15527Turns on or off display of debugging info about @value{GDBN}
15528expression parsing. The default is off.
8e04817f 15529@item show debug expression
721c2651
EZ
15530Displays the current state of displaying debugging info about
15531@value{GDBN} expression parsing.
7453dc06 15532@item set debug frame
4644b6e3 15533@cindex frame debugging info
7453dc06
AC
15534Turns on or off display of @value{GDBN} frame debugging info. The
15535default is off.
7453dc06
AC
15536@item show debug frame
15537Displays the current state of displaying @value{GDBN} frame debugging
15538info.
30e91e0b
RC
15539@item set debug infrun
15540@cindex inferior debugging info
15541Turns on or off display of @value{GDBN} debugging info for running the inferior.
15542The default is off. @file{infrun.c} contains GDB's runtime state machine used
15543for implementing operations such as single-stepping the inferior.
15544@item show debug infrun
15545Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
15546@item set debug lin-lwp
15547@cindex @sc{gnu}/Linux LWP debug messages
15548@cindex Linux lightweight processes
721c2651 15549Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
15550@item show debug lin-lwp
15551Show the current state of Linux LWP debugging messages.
2b4855ab 15552@item set debug observer
4644b6e3 15553@cindex observer debugging info
2b4855ab
AC
15554Turns on or off display of @value{GDBN} observer debugging. This
15555includes info such as the notification of observable events.
2b4855ab
AC
15556@item show debug observer
15557Displays the current state of observer debugging.
8e04817f 15558@item set debug overload
4644b6e3 15559@cindex C@t{++} overload debugging info
8e04817f
AC
15560Turns on or off display of @value{GDBN} C@t{++} overload debugging
15561info. This includes info such as ranking of functions, etc. The default
15562is off.
8e04817f
AC
15563@item show debug overload
15564Displays the current state of displaying @value{GDBN} C@t{++} overload
15565debugging info.
8e04817f
AC
15566@cindex packets, reporting on stdout
15567@cindex serial connections, debugging
15568@item set debug remote
15569Turns on or off display of reports on all packets sent back and forth across
15570the serial line to the remote machine. The info is printed on the
15571@value{GDBN} standard output stream. The default is off.
8e04817f
AC
15572@item show debug remote
15573Displays the state of display of remote packets.
8e04817f
AC
15574@item set debug serial
15575Turns on or off display of @value{GDBN} serial debugging info. The
15576default is off.
8e04817f
AC
15577@item show debug serial
15578Displays the current state of displaying @value{GDBN} serial debugging
15579info.
c45da7e6
EZ
15580@item set debug solib-frv
15581@cindex FR-V shared-library debugging
15582Turns on or off debugging messages for FR-V shared-library code.
15583@item show debug solib-frv
15584Display the current state of FR-V shared-library code debugging
15585messages.
8e04817f 15586@item set debug target
4644b6e3 15587@cindex target debugging info
8e04817f
AC
15588Turns on or off display of @value{GDBN} target debugging info. This info
15589includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
15590default is 0. Set it to 1 to track events, and to 2 to also track the
15591value of large memory transfers. Changes to this flag do not take effect
15592until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
15593@item show debug target
15594Displays the current state of displaying @value{GDBN} target debugging
15595info.
c45da7e6 15596@item set debugvarobj
4644b6e3 15597@cindex variable object debugging info
8e04817f
AC
15598Turns on or off display of @value{GDBN} variable object debugging
15599info. The default is off.
c45da7e6 15600@item show debugvarobj
8e04817f
AC
15601Displays the current state of displaying @value{GDBN} variable object
15602debugging info.
15603@end table
104c1213 15604
8e04817f
AC
15605@node Sequences
15606@chapter Canned Sequences of Commands
104c1213 15607
8e04817f
AC
15608Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
15609command lists}), @value{GDBN} provides two ways to store sequences of
15610commands for execution as a unit: user-defined commands and command
15611files.
104c1213 15612
8e04817f
AC
15613@menu
15614* Define:: User-defined commands
15615* Hooks:: User-defined command hooks
15616* Command Files:: Command files
15617* Output:: Commands for controlled output
15618@end menu
104c1213 15619
8e04817f
AC
15620@node Define
15621@section User-defined commands
104c1213 15622
8e04817f
AC
15623@cindex user-defined command
15624A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
15625which you assign a new name as a command. This is done with the
15626@code{define} command. User commands may accept up to 10 arguments
15627separated by whitespace. Arguments are accessed within the user command
15628via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 15629
8e04817f
AC
15630@smallexample
15631define adder
15632 print $arg0 + $arg1 + $arg2
15633@end smallexample
104c1213
JM
15634
15635@noindent
8e04817f 15636To execute the command use:
104c1213 15637
8e04817f
AC
15638@smallexample
15639adder 1 2 3
15640@end smallexample
104c1213 15641
8e04817f
AC
15642@noindent
15643This defines the command @code{adder}, which prints the sum of
15644its three arguments. Note the arguments are text substitutions, so they may
15645reference variables, use complex expressions, or even perform inferior
15646functions calls.
104c1213
JM
15647
15648@table @code
104c1213 15649
8e04817f
AC
15650@kindex define
15651@item define @var{commandname}
15652Define a command named @var{commandname}. If there is already a command
15653by that name, you are asked to confirm that you want to redefine it.
104c1213 15654
8e04817f
AC
15655The definition of the command is made up of other @value{GDBN} command lines,
15656which are given following the @code{define} command. The end of these
15657commands is marked by a line containing @code{end}.
104c1213 15658
8e04817f
AC
15659@kindex if
15660@kindex else
15661@item if
09d4efe1 15662@itemx else
8e04817f
AC
15663Takes a single argument, which is an expression to evaluate.
15664It is followed by a series of commands that are executed
15665only if the expression is true (nonzero).
15666There can then optionally be a line @code{else}, followed
15667by a series of commands that are only executed if the expression
15668was false. The end of the list is marked by a line containing @code{end}.
104c1213 15669
8e04817f
AC
15670@kindex while
15671@item while
15672The syntax is similar to @code{if}: the command takes a single argument,
15673which is an expression to evaluate, and must be followed by the commands to
15674execute, one per line, terminated by an @code{end}.
15675The commands are executed repeatedly as long as the expression
15676evaluates to true.
104c1213 15677
8e04817f
AC
15678@kindex document
15679@item document @var{commandname}
15680Document the user-defined command @var{commandname}, so that it can be
15681accessed by @code{help}. The command @var{commandname} must already be
15682defined. This command reads lines of documentation just as @code{define}
15683reads the lines of the command definition, ending with @code{end}.
15684After the @code{document} command is finished, @code{help} on command
15685@var{commandname} displays the documentation you have written.
104c1213 15686
8e04817f
AC
15687You may use the @code{document} command again to change the
15688documentation of a command. Redefining the command with @code{define}
15689does not change the documentation.
104c1213 15690
c45da7e6
EZ
15691@kindex dont-repeat
15692@cindex don't repeat command
15693@item dont-repeat
15694Used inside a user-defined command, this tells @value{GDBN} that this
15695command should not be repeated when the user hits @key{RET}
15696(@pxref{Command Syntax, repeat last command}).
15697
8e04817f
AC
15698@kindex help user-defined
15699@item help user-defined
15700List all user-defined commands, with the first line of the documentation
15701(if any) for each.
104c1213 15702
8e04817f
AC
15703@kindex show user
15704@item show user
15705@itemx show user @var{commandname}
15706Display the @value{GDBN} commands used to define @var{commandname} (but
15707not its documentation). If no @var{commandname} is given, display the
15708definitions for all user-defined commands.
104c1213 15709
9c16f35a 15710@cindex infinite recusrion in user-defined commands
20f01a46
DH
15711@kindex show max-user-call-depth
15712@kindex set max-user-call-depth
15713@item show max-user-call-depth
5ca0cb28
DH
15714@itemx set max-user-call-depth
15715The value of @code{max-user-call-depth} controls how many recursion
15716levels are allowed in user-defined commands before GDB suspects an
15717infinite recursion and aborts the command.
20f01a46 15718
104c1213
JM
15719@end table
15720
8e04817f
AC
15721When user-defined commands are executed, the
15722commands of the definition are not printed. An error in any command
15723stops execution of the user-defined command.
104c1213 15724
8e04817f
AC
15725If used interactively, commands that would ask for confirmation proceed
15726without asking when used inside a user-defined command. Many @value{GDBN}
15727commands that normally print messages to say what they are doing omit the
15728messages when used in a user-defined command.
104c1213 15729
8e04817f
AC
15730@node Hooks
15731@section User-defined command hooks
15732@cindex command hooks
15733@cindex hooks, for commands
15734@cindex hooks, pre-command
104c1213 15735
8e04817f 15736@kindex hook
8e04817f
AC
15737You may define @dfn{hooks}, which are a special kind of user-defined
15738command. Whenever you run the command @samp{foo}, if the user-defined
15739command @samp{hook-foo} exists, it is executed (with no arguments)
15740before that command.
104c1213 15741
8e04817f
AC
15742@cindex hooks, post-command
15743@kindex hookpost
8e04817f
AC
15744A hook may also be defined which is run after the command you executed.
15745Whenever you run the command @samp{foo}, if the user-defined command
15746@samp{hookpost-foo} exists, it is executed (with no arguments) after
15747that command. Post-execution hooks may exist simultaneously with
15748pre-execution hooks, for the same command.
104c1213 15749
8e04817f 15750It is valid for a hook to call the command which it hooks. If this
9f1c6395 15751occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 15752
8e04817f
AC
15753@c It would be nice if hookpost could be passed a parameter indicating
15754@c if the command it hooks executed properly or not. FIXME!
104c1213 15755
8e04817f
AC
15756@kindex stop@r{, a pseudo-command}
15757In addition, a pseudo-command, @samp{stop} exists. Defining
15758(@samp{hook-stop}) makes the associated commands execute every time
15759execution stops in your program: before breakpoint commands are run,
15760displays are printed, or the stack frame is printed.
104c1213 15761
8e04817f
AC
15762For example, to ignore @code{SIGALRM} signals while
15763single-stepping, but treat them normally during normal execution,
15764you could define:
104c1213 15765
474c8240 15766@smallexample
8e04817f
AC
15767define hook-stop
15768handle SIGALRM nopass
15769end
104c1213 15770
8e04817f
AC
15771define hook-run
15772handle SIGALRM pass
15773end
104c1213 15774
8e04817f
AC
15775define hook-continue
15776handle SIGLARM pass
15777end
474c8240 15778@end smallexample
104c1213 15779
8e04817f 15780As a further example, to hook at the begining and end of the @code{echo}
b383017d 15781command, and to add extra text to the beginning and end of the message,
8e04817f 15782you could define:
104c1213 15783
474c8240 15784@smallexample
8e04817f
AC
15785define hook-echo
15786echo <<<---
15787end
104c1213 15788
8e04817f
AC
15789define hookpost-echo
15790echo --->>>\n
15791end
104c1213 15792
8e04817f
AC
15793(@value{GDBP}) echo Hello World
15794<<<---Hello World--->>>
15795(@value{GDBP})
104c1213 15796
474c8240 15797@end smallexample
104c1213 15798
8e04817f
AC
15799You can define a hook for any single-word command in @value{GDBN}, but
15800not for command aliases; you should define a hook for the basic command
15801name, e.g. @code{backtrace} rather than @code{bt}.
15802@c FIXME! So how does Joe User discover whether a command is an alias
15803@c or not?
15804If an error occurs during the execution of your hook, execution of
15805@value{GDBN} commands stops and @value{GDBN} issues a prompt
15806(before the command that you actually typed had a chance to run).
104c1213 15807
8e04817f
AC
15808If you try to define a hook which does not match any known command, you
15809get a warning from the @code{define} command.
c906108c 15810
8e04817f
AC
15811@node Command Files
15812@section Command files
c906108c 15813
8e04817f 15814@cindex command files
6fc08d32
EZ
15815A command file for @value{GDBN} is a text file made of lines that are
15816@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
15817also be included. An empty line in a command file does nothing; it
15818does not mean to repeat the last command, as it would from the
15819terminal.
c906108c 15820
6fc08d32
EZ
15821You can request the execution of a command file with the @code{source}
15822command:
c906108c 15823
8e04817f
AC
15824@table @code
15825@kindex source
15826@item source @var{filename}
15827Execute the command file @var{filename}.
c906108c
SS
15828@end table
15829
8e04817f 15830The lines in a command file are executed sequentially. They are not
a71ec265
DH
15831printed as they are executed. An error in any command terminates
15832execution of the command file and control is returned to the console.
c906108c 15833
8e04817f
AC
15834Commands that would ask for confirmation if used interactively proceed
15835without asking when used in a command file. Many @value{GDBN} commands that
15836normally print messages to say what they are doing omit the messages
15837when called from command files.
c906108c 15838
8e04817f
AC
15839@value{GDBN} also accepts command input from standard input. In this
15840mode, normal output goes to standard output and error output goes to
15841standard error. Errors in a command file supplied on standard input do
6fc08d32 15842not terminate execution of the command file---execution continues with
8e04817f 15843the next command.
c906108c 15844
474c8240 15845@smallexample
8e04817f 15846gdb < cmds > log 2>&1
474c8240 15847@end smallexample
c906108c 15848
8e04817f
AC
15849(The syntax above will vary depending on the shell used.) This example
15850will execute commands from the file @file{cmds}. All output and errors
15851would be directed to @file{log}.
c906108c 15852
8e04817f
AC
15853@node Output
15854@section Commands for controlled output
c906108c 15855
8e04817f
AC
15856During the execution of a command file or a user-defined command, normal
15857@value{GDBN} output is suppressed; the only output that appears is what is
15858explicitly printed by the commands in the definition. This section
15859describes three commands useful for generating exactly the output you
15860want.
c906108c
SS
15861
15862@table @code
8e04817f
AC
15863@kindex echo
15864@item echo @var{text}
15865@c I do not consider backslash-space a standard C escape sequence
15866@c because it is not in ANSI.
15867Print @var{text}. Nonprinting characters can be included in
15868@var{text} using C escape sequences, such as @samp{\n} to print a
15869newline. @strong{No newline is printed unless you specify one.}
15870In addition to the standard C escape sequences, a backslash followed
15871by a space stands for a space. This is useful for displaying a
15872string with spaces at the beginning or the end, since leading and
15873trailing spaces are otherwise trimmed from all arguments.
15874To print @samp{@w{ }and foo =@w{ }}, use the command
15875@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 15876
8e04817f
AC
15877A backslash at the end of @var{text} can be used, as in C, to continue
15878the command onto subsequent lines. For example,
c906108c 15879
474c8240 15880@smallexample
8e04817f
AC
15881echo This is some text\n\
15882which is continued\n\
15883onto several lines.\n
474c8240 15884@end smallexample
c906108c 15885
8e04817f 15886produces the same output as
c906108c 15887
474c8240 15888@smallexample
8e04817f
AC
15889echo This is some text\n
15890echo which is continued\n
15891echo onto several lines.\n
474c8240 15892@end smallexample
c906108c 15893
8e04817f
AC
15894@kindex output
15895@item output @var{expression}
15896Print the value of @var{expression} and nothing but that value: no
15897newlines, no @samp{$@var{nn} = }. The value is not entered in the
15898value history either. @xref{Expressions, ,Expressions}, for more information
15899on expressions.
c906108c 15900
8e04817f
AC
15901@item output/@var{fmt} @var{expression}
15902Print the value of @var{expression} in format @var{fmt}. You can use
15903the same formats as for @code{print}. @xref{Output Formats,,Output
15904formats}, for more information.
c906108c 15905
8e04817f
AC
15906@kindex printf
15907@item printf @var{string}, @var{expressions}@dots{}
15908Print the values of the @var{expressions} under the control of
15909@var{string}. The @var{expressions} are separated by commas and may be
15910either numbers or pointers. Their values are printed as specified by
15911@var{string}, exactly as if your program were to execute the C
15912subroutine
15913@c FIXME: the above implies that at least all ANSI C formats are
15914@c supported, but it isn't true: %E and %G don't work (or so it seems).
15915@c Either this is a bug, or the manual should document what formats are
15916@c supported.
c906108c 15917
474c8240 15918@smallexample
8e04817f 15919printf (@var{string}, @var{expressions}@dots{});
474c8240 15920@end smallexample
c906108c 15921
8e04817f 15922For example, you can print two values in hex like this:
c906108c 15923
8e04817f
AC
15924@smallexample
15925printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
15926@end smallexample
c906108c 15927
8e04817f
AC
15928The only backslash-escape sequences that you can use in the format
15929string are the simple ones that consist of backslash followed by a
15930letter.
c906108c
SS
15931@end table
15932
21c294e6
AC
15933@node Interpreters
15934@chapter Command Interpreters
15935@cindex command interpreters
15936
15937@value{GDBN} supports multiple command interpreters, and some command
15938infrastructure to allow users or user interface writers to switch
15939between interpreters or run commands in other interpreters.
15940
15941@value{GDBN} currently supports two command interpreters, the console
15942interpreter (sometimes called the command-line interpreter or @sc{cli})
15943and the machine interface interpreter (or @sc{gdb/mi}). This manual
15944describes both of these interfaces in great detail.
15945
15946By default, @value{GDBN} will start with the console interpreter.
15947However, the user may choose to start @value{GDBN} with another
15948interpreter by specifying the @option{-i} or @option{--interpreter}
15949startup options. Defined interpreters include:
15950
15951@table @code
15952@item console
15953@cindex console interpreter
15954The traditional console or command-line interpreter. This is the most often
15955used interpreter with @value{GDBN}. With no interpreter specified at runtime,
15956@value{GDBN} will use this interpreter.
15957
15958@item mi
15959@cindex mi interpreter
15960The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
15961by programs wishing to use @value{GDBN} as a backend for a debugger GUI
15962or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
15963Interface}.
15964
15965@item mi2
15966@cindex mi2 interpreter
15967The current @sc{gdb/mi} interface.
15968
15969@item mi1
15970@cindex mi1 interpreter
15971The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
15972
15973@end table
15974
15975@cindex invoke another interpreter
15976The interpreter being used by @value{GDBN} may not be dynamically
15977switched at runtime. Although possible, this could lead to a very
15978precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
15979enters the command "interpreter-set console" in a console view,
15980@value{GDBN} would switch to using the console interpreter, rendering
15981the IDE inoperable!
15982
15983@kindex interpreter-exec
15984Although you may only choose a single interpreter at startup, you may execute
15985commands in any interpreter from the current interpreter using the appropriate
15986command. If you are running the console interpreter, simply use the
15987@code{interpreter-exec} command:
15988
15989@smallexample
15990interpreter-exec mi "-data-list-register-names"
15991@end smallexample
15992
15993@sc{gdb/mi} has a similar command, although it is only available in versions of
15994@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
15995
8e04817f
AC
15996@node TUI
15997@chapter @value{GDBN} Text User Interface
15998@cindex TUI
d0d5df6f 15999@cindex Text User Interface
c906108c 16000
8e04817f
AC
16001@menu
16002* TUI Overview:: TUI overview
16003* TUI Keys:: TUI key bindings
7cf36c78 16004* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
16005* TUI Commands:: TUI specific commands
16006* TUI Configuration:: TUI configuration variables
16007@end menu
c906108c 16008
d0d5df6f
AC
16009The @value{GDBN} Text User Interface, TUI in short, is a terminal
16010interface which uses the @code{curses} library to show the source
16011file, the assembly output, the program registers and @value{GDBN}
16012commands in separate text windows.
16013
16014The TUI is enabled by invoking @value{GDBN} using either
16015@pindex gdbtui
16016@samp{gdbtui} or @samp{gdb -tui}.
c906108c 16017
8e04817f
AC
16018@node TUI Overview
16019@section TUI overview
c906108c 16020
8e04817f
AC
16021The TUI has two display modes that can be switched while
16022@value{GDBN} runs:
c906108c 16023
8e04817f
AC
16024@itemize @bullet
16025@item
16026A curses (or TUI) mode in which it displays several text
16027windows on the terminal.
c906108c 16028
8e04817f
AC
16029@item
16030A standard mode which corresponds to the @value{GDBN} configured without
16031the TUI.
16032@end itemize
c906108c 16033
8e04817f
AC
16034In the TUI mode, @value{GDBN} can display several text window
16035on the terminal:
c906108c 16036
8e04817f
AC
16037@table @emph
16038@item command
16039This window is the @value{GDBN} command window with the @value{GDBN}
16040prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
16041managed using readline but through the TUI. The @emph{command}
16042window is always visible.
c906108c 16043
8e04817f
AC
16044@item source
16045The source window shows the source file of the program. The current
16046line as well as active breakpoints are displayed in this window.
c906108c 16047
8e04817f
AC
16048@item assembly
16049The assembly window shows the disassembly output of the program.
c906108c 16050
8e04817f
AC
16051@item register
16052This window shows the processor registers. It detects when
16053a register is changed and when this is the case, registers that have
6a1b180d 16054changed are highlighted.
c906108c 16055
c906108c
SS
16056@end table
16057
269c21fe
SC
16058The source and assembly windows show the current program position
16059by highlighting the current line and marking them with the @samp{>} marker.
16060Breakpoints are also indicated with two markers. A first one
16061indicates the breakpoint type:
16062
16063@table @code
16064@item B
16065Breakpoint which was hit at least once.
16066
16067@item b
16068Breakpoint which was never hit.
16069
16070@item H
16071Hardware breakpoint which was hit at least once.
16072
16073@item h
16074Hardware breakpoint which was never hit.
16075
16076@end table
16077
16078The second marker indicates whether the breakpoint is enabled or not:
16079
16080@table @code
16081@item +
16082Breakpoint is enabled.
16083
16084@item -
16085Breakpoint is disabled.
16086
16087@end table
16088
8e04817f
AC
16089The source, assembly and register windows are attached to the thread
16090and the frame position. They are updated when the current thread
16091changes, when the frame changes or when the program counter changes.
16092These three windows are arranged by the TUI according to several
16093layouts. The layout defines which of these three windows are visible.
16094The following layouts are available:
c906108c 16095
8e04817f
AC
16096@itemize @bullet
16097@item
16098source
2df3850c 16099
8e04817f
AC
16100@item
16101assembly
16102
16103@item
16104source and assembly
16105
16106@item
16107source and registers
c906108c 16108
8e04817f
AC
16109@item
16110assembly and registers
2df3850c 16111
8e04817f 16112@end itemize
c906108c 16113
b7bb15bc
SC
16114On top of the command window a status line gives various information
16115concerning the current process begin debugged. The status line is
16116updated when the information it shows changes. The following fields
16117are displayed:
16118
16119@table @emph
16120@item target
16121Indicates the current gdb target
16122(@pxref{Targets, ,Specifying a Debugging Target}).
16123
16124@item process
16125Gives information about the current process or thread number.
16126When no process is being debugged, this field is set to @code{No process}.
16127
16128@item function
16129Gives the current function name for the selected frame.
16130The name is demangled if demangling is turned on (@pxref{Print Settings}).
16131When there is no symbol corresponding to the current program counter
16132the string @code{??} is displayed.
16133
16134@item line
16135Indicates the current line number for the selected frame.
16136When the current line number is not known the string @code{??} is displayed.
16137
16138@item pc
16139Indicates the current program counter address.
16140
16141@end table
16142
8e04817f
AC
16143@node TUI Keys
16144@section TUI Key Bindings
16145@cindex TUI key bindings
c906108c 16146
8e04817f
AC
16147The TUI installs several key bindings in the readline keymaps
16148(@pxref{Command Line Editing}).
16149They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
16150directly on the TUI layout and windows. The TUI also provides
16151a @emph{SingleKey} keymap which binds several keys directly to
16152@value{GDBN} commands. The following key bindings
8e04817f 16153are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 16154
8e04817f
AC
16155@table @kbd
16156@kindex C-x C-a
16157@item C-x C-a
16158@kindex C-x a
16159@itemx C-x a
16160@kindex C-x A
16161@itemx C-x A
16162Enter or leave the TUI mode. When the TUI mode is left,
16163the curses window management is left and @value{GDBN} operates using
16164its standard mode writing on the terminal directly. When the TUI
16165mode is entered, the control is given back to the curses windows.
16166The screen is then refreshed.
c906108c 16167
8e04817f
AC
16168@kindex C-x 1
16169@item C-x 1
16170Use a TUI layout with only one window. The layout will
16171either be @samp{source} or @samp{assembly}. When the TUI mode
16172is not active, it will switch to the TUI mode.
2df3850c 16173
8e04817f 16174Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 16175
8e04817f
AC
16176@kindex C-x 2
16177@item C-x 2
16178Use a TUI layout with at least two windows. When the current
16179layout shows already two windows, a next layout with two windows is used.
16180When a new layout is chosen, one window will always be common to the
16181previous layout and the new one.
c906108c 16182
8e04817f 16183Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 16184
72ffddc9
SC
16185@kindex C-x o
16186@item C-x o
16187Change the active window. The TUI associates several key bindings
16188(like scrolling and arrow keys) to the active window. This command
16189gives the focus to the next TUI window.
16190
16191Think of it as the Emacs @kbd{C-x o} binding.
16192
7cf36c78
SC
16193@kindex C-x s
16194@item C-x s
16195Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
16196(@pxref{TUI Single Key Mode}).
16197
c906108c
SS
16198@end table
16199
8e04817f 16200The following key bindings are handled only by the TUI mode:
5d161b24 16201
8e04817f
AC
16202@table @key
16203@kindex PgUp
16204@item PgUp
16205Scroll the active window one page up.
c906108c 16206
8e04817f
AC
16207@kindex PgDn
16208@item PgDn
16209Scroll the active window one page down.
c906108c 16210
8e04817f
AC
16211@kindex Up
16212@item Up
16213Scroll the active window one line up.
c906108c 16214
8e04817f
AC
16215@kindex Down
16216@item Down
16217Scroll the active window one line down.
c906108c 16218
8e04817f
AC
16219@kindex Left
16220@item Left
16221Scroll the active window one column left.
c906108c 16222
8e04817f
AC
16223@kindex Right
16224@item Right
16225Scroll the active window one column right.
c906108c 16226
8e04817f
AC
16227@kindex C-L
16228@item C-L
16229Refresh the screen.
c906108c 16230
8e04817f 16231@end table
c906108c 16232
8e04817f 16233In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
16234for scrolling. This means they are available for readline when the
16235active window is the command window. When the command window
16236does not have the focus, it is necessary to use other readline
16237key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 16238
7cf36c78
SC
16239@node TUI Single Key Mode
16240@section TUI Single Key Mode
16241@cindex TUI single key mode
16242
16243The TUI provides a @emph{SingleKey} mode in which it installs a particular
16244key binding in the readline keymaps to connect single keys to
b383017d 16245some gdb commands.
7cf36c78
SC
16246
16247@table @kbd
16248@kindex c @r{(SingleKey TUI key)}
16249@item c
16250continue
16251
16252@kindex d @r{(SingleKey TUI key)}
16253@item d
16254down
16255
16256@kindex f @r{(SingleKey TUI key)}
16257@item f
16258finish
16259
16260@kindex n @r{(SingleKey TUI key)}
16261@item n
16262next
16263
16264@kindex q @r{(SingleKey TUI key)}
16265@item q
16266exit the @emph{SingleKey} mode.
16267
16268@kindex r @r{(SingleKey TUI key)}
16269@item r
16270run
16271
16272@kindex s @r{(SingleKey TUI key)}
16273@item s
16274step
16275
16276@kindex u @r{(SingleKey TUI key)}
16277@item u
16278up
16279
16280@kindex v @r{(SingleKey TUI key)}
16281@item v
16282info locals
16283
16284@kindex w @r{(SingleKey TUI key)}
16285@item w
16286where
16287
16288@end table
16289
16290Other keys temporarily switch to the @value{GDBN} command prompt.
16291The key that was pressed is inserted in the editing buffer so that
16292it is possible to type most @value{GDBN} commands without interaction
16293with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
16294@emph{SingleKey} mode is restored. The only way to permanently leave
16295this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
16296
16297
8e04817f
AC
16298@node TUI Commands
16299@section TUI specific commands
16300@cindex TUI commands
16301
16302The TUI has specific commands to control the text windows.
16303These commands are always available, that is they do not depend on
16304the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
16305is in the standard mode, using these commands will automatically switch
16306in the TUI mode.
c906108c
SS
16307
16308@table @code
3d757584
SC
16309@item info win
16310@kindex info win
16311List and give the size of all displayed windows.
16312
8e04817f 16313@item layout next
4644b6e3 16314@kindex layout
8e04817f 16315Display the next layout.
2df3850c 16316
8e04817f 16317@item layout prev
8e04817f 16318Display the previous layout.
c906108c 16319
8e04817f 16320@item layout src
8e04817f 16321Display the source window only.
c906108c 16322
8e04817f 16323@item layout asm
8e04817f 16324Display the assembly window only.
c906108c 16325
8e04817f 16326@item layout split
8e04817f 16327Display the source and assembly window.
c906108c 16328
8e04817f 16329@item layout regs
8e04817f
AC
16330Display the register window together with the source or assembly window.
16331
16332@item focus next | prev | src | asm | regs | split
16333@kindex focus
16334Set the focus to the named window.
16335This command allows to change the active window so that scrolling keys
16336can be affected to another window.
c906108c 16337
8e04817f
AC
16338@item refresh
16339@kindex refresh
16340Refresh the screen. This is similar to using @key{C-L} key.
c906108c 16341
6a1b180d
SC
16342@item tui reg float
16343@kindex tui reg
16344Show the floating point registers in the register window.
16345
16346@item tui reg general
16347Show the general registers in the register window.
16348
16349@item tui reg next
16350Show the next register group. The list of register groups as well as
16351their order is target specific. The predefined register groups are the
16352following: @code{general}, @code{float}, @code{system}, @code{vector},
16353@code{all}, @code{save}, @code{restore}.
16354
16355@item tui reg system
16356Show the system registers in the register window.
16357
8e04817f
AC
16358@item update
16359@kindex update
16360Update the source window and the current execution point.
c906108c 16361
8e04817f
AC
16362@item winheight @var{name} +@var{count}
16363@itemx winheight @var{name} -@var{count}
16364@kindex winheight
16365Change the height of the window @var{name} by @var{count}
16366lines. Positive counts increase the height, while negative counts
16367decrease it.
2df3850c 16368
c45da7e6
EZ
16369@item tabset
16370@kindex tabset @var{nchars}
16371Set the width of tab stops to be @var{nchars} characters.
16372
c906108c
SS
16373@end table
16374
8e04817f
AC
16375@node TUI Configuration
16376@section TUI configuration variables
16377@cindex TUI configuration variables
c906108c 16378
8e04817f
AC
16379The TUI has several configuration variables that control the
16380appearance of windows on the terminal.
c906108c 16381
8e04817f
AC
16382@table @code
16383@item set tui border-kind @var{kind}
16384@kindex set tui border-kind
16385Select the border appearance for the source, assembly and register windows.
16386The possible values are the following:
16387@table @code
16388@item space
16389Use a space character to draw the border.
c906108c 16390
8e04817f
AC
16391@item ascii
16392Use ascii characters + - and | to draw the border.
c906108c 16393
8e04817f
AC
16394@item acs
16395Use the Alternate Character Set to draw the border. The border is
16396drawn using character line graphics if the terminal supports them.
c78b4128 16397
8e04817f 16398@end table
c78b4128 16399
8e04817f
AC
16400@item set tui active-border-mode @var{mode}
16401@kindex set tui active-border-mode
16402Select the attributes to display the border of the active window.
16403The possible values are @code{normal}, @code{standout}, @code{reverse},
16404@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 16405
8e04817f
AC
16406@item set tui border-mode @var{mode}
16407@kindex set tui border-mode
16408Select the attributes to display the border of other windows.
16409The @var{mode} can be one of the following:
16410@table @code
16411@item normal
16412Use normal attributes to display the border.
c906108c 16413
8e04817f
AC
16414@item standout
16415Use standout mode.
c906108c 16416
8e04817f
AC
16417@item reverse
16418Use reverse video mode.
c906108c 16419
8e04817f
AC
16420@item half
16421Use half bright mode.
c906108c 16422
8e04817f
AC
16423@item half-standout
16424Use half bright and standout mode.
c906108c 16425
8e04817f
AC
16426@item bold
16427Use extra bright or bold mode.
c78b4128 16428
8e04817f
AC
16429@item bold-standout
16430Use extra bright or bold and standout mode.
c78b4128 16431
8e04817f 16432@end table
c78b4128 16433
8e04817f 16434@end table
c78b4128 16435
8e04817f
AC
16436@node Emacs
16437@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 16438
8e04817f
AC
16439@cindex Emacs
16440@cindex @sc{gnu} Emacs
16441A special interface allows you to use @sc{gnu} Emacs to view (and
16442edit) the source files for the program you are debugging with
16443@value{GDBN}.
c906108c 16444
8e04817f
AC
16445To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
16446executable file you want to debug as an argument. This command starts
16447@value{GDBN} as a subprocess of Emacs, with input and output through a newly
16448created Emacs buffer.
16449@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 16450
8e04817f
AC
16451Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
16452things:
c906108c 16453
8e04817f
AC
16454@itemize @bullet
16455@item
16456All ``terminal'' input and output goes through the Emacs buffer.
16457@end itemize
c906108c 16458
8e04817f
AC
16459This applies both to @value{GDBN} commands and their output, and to the input
16460and output done by the program you are debugging.
bf0184be 16461
8e04817f
AC
16462This is useful because it means that you can copy the text of previous
16463commands and input them again; you can even use parts of the output
16464in this way.
bf0184be 16465
8e04817f
AC
16466All the facilities of Emacs' Shell mode are available for interacting
16467with your program. In particular, you can send signals the usual
16468way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
16469stop.
bf0184be 16470
8e04817f 16471@itemize @bullet
bf0184be 16472@item
8e04817f
AC
16473@value{GDBN} displays source code through Emacs.
16474@end itemize
bf0184be 16475
8e04817f
AC
16476Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
16477source file for that frame and puts an arrow (@samp{=>}) at the
16478left margin of the current line. Emacs uses a separate buffer for
16479source display, and splits the screen to show both your @value{GDBN} session
16480and the source.
bf0184be 16481
8e04817f
AC
16482Explicit @value{GDBN} @code{list} or search commands still produce output as
16483usual, but you probably have no reason to use them from Emacs.
c906108c 16484
64fabec2
AC
16485If you specify an absolute file name when prompted for the @kbd{M-x
16486gdb} argument, then Emacs sets your current working directory to where
16487your program resides. If you only specify the file name, then Emacs
16488sets your current working directory to to the directory associated
16489with the previous buffer. In this case, @value{GDBN} may find your
16490program by searching your environment's @code{PATH} variable, but on
16491some operating systems it might not find the source. So, although the
16492@value{GDBN} input and output session proceeds normally, the auxiliary
16493buffer does not display the current source and line of execution.
16494
16495The initial working directory of @value{GDBN} is printed on the top
16496line of the @value{GDBN} I/O buffer and this serves as a default for
16497the commands that specify files for @value{GDBN} to operate
16498on. @xref{Files, ,Commands to specify files}.
16499
16500By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
16501need to call @value{GDBN} by a different name (for example, if you
16502keep several configurations around, with different names) you can
16503customize the Emacs variable @code{gud-gdb-command-name} to run the
16504one you want.
8e04817f
AC
16505
16506In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
16507addition to the standard Shell mode commands:
c906108c 16508
8e04817f
AC
16509@table @kbd
16510@item C-h m
16511Describe the features of Emacs' @value{GDBN} Mode.
c906108c 16512
64fabec2 16513@item C-c C-s
8e04817f
AC
16514Execute to another source line, like the @value{GDBN} @code{step} command; also
16515update the display window to show the current file and location.
c906108c 16516
64fabec2 16517@item C-c C-n
8e04817f
AC
16518Execute to next source line in this function, skipping all function
16519calls, like the @value{GDBN} @code{next} command. Then update the display window
16520to show the current file and location.
c906108c 16521
64fabec2 16522@item C-c C-i
8e04817f
AC
16523Execute one instruction, like the @value{GDBN} @code{stepi} command; update
16524display window accordingly.
c906108c 16525
8e04817f
AC
16526@item C-c C-f
16527Execute until exit from the selected stack frame, like the @value{GDBN}
16528@code{finish} command.
c906108c 16529
64fabec2 16530@item C-c C-r
8e04817f
AC
16531Continue execution of your program, like the @value{GDBN} @code{continue}
16532command.
b433d00b 16533
64fabec2 16534@item C-c <
8e04817f
AC
16535Go up the number of frames indicated by the numeric argument
16536(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
16537like the @value{GDBN} @code{up} command.
b433d00b 16538
64fabec2 16539@item C-c >
8e04817f
AC
16540Go down the number of frames indicated by the numeric argument, like the
16541@value{GDBN} @code{down} command.
8e04817f 16542@end table
c906108c 16543
64fabec2 16544In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 16545tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 16546
64fabec2
AC
16547If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
16548shows a backtrace when the @value{GDBN} I/O buffer is current. Move
16549point to any frame in the stack and type @key{RET} to make it become the
16550current frame and display the associated source in the source buffer.
16551Alternatively, click @kbd{Mouse-2} to make the selected frame become the
16552current one.
16553
8e04817f
AC
16554If you accidentally delete the source-display buffer, an easy way to get
16555it back is to type the command @code{f} in the @value{GDBN} buffer, to
16556request a frame display; when you run under Emacs, this recreates
16557the source buffer if necessary to show you the context of the current
16558frame.
c906108c 16559
8e04817f
AC
16560The source files displayed in Emacs are in ordinary Emacs buffers
16561which are visiting the source files in the usual way. You can edit
16562the files with these buffers if you wish; but keep in mind that @value{GDBN}
16563communicates with Emacs in terms of line numbers. If you add or
16564delete lines from the text, the line numbers that @value{GDBN} knows cease
16565to correspond properly with the code.
b383017d 16566
64fabec2
AC
16567The description given here is for GNU Emacs version 21.3 and a more
16568detailed description of its interaction with @value{GDBN} is given in
16569the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 16570
8e04817f
AC
16571@c The following dropped because Epoch is nonstandard. Reactivate
16572@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
16573@ignore
16574@kindex Emacs Epoch environment
16575@kindex Epoch
16576@kindex inspect
c906108c 16577
8e04817f
AC
16578Version 18 of @sc{gnu} Emacs has a built-in window system
16579called the @code{epoch}
16580environment. Users of this environment can use a new command,
16581@code{inspect} which performs identically to @code{print} except that
16582each value is printed in its own window.
16583@end ignore
c906108c 16584
922fbb7b
AC
16585
16586@node GDB/MI
16587@chapter The @sc{gdb/mi} Interface
16588
16589@unnumberedsec Function and Purpose
16590
16591@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
16592@sc{gdb/mi} is a line based machine oriented text interface to
16593@value{GDBN} and is activated by specifying using the
16594@option{--interpreter} command line option (@pxref{Mode Options}). It
16595is specifically intended to support the development of systems which
16596use the debugger as just one small component of a larger system.
922fbb7b
AC
16597
16598This chapter is a specification of the @sc{gdb/mi} interface. It is written
16599in the form of a reference manual.
16600
16601Note that @sc{gdb/mi} is still under construction, so some of the
16602features described below are incomplete and subject to change.
16603
16604@unnumberedsec Notation and Terminology
16605
16606@cindex notational conventions, for @sc{gdb/mi}
16607This chapter uses the following notation:
16608
16609@itemize @bullet
16610@item
16611@code{|} separates two alternatives.
16612
16613@item
16614@code{[ @var{something} ]} indicates that @var{something} is optional:
16615it may or may not be given.
16616
16617@item
16618@code{( @var{group} )*} means that @var{group} inside the parentheses
16619may repeat zero or more times.
16620
16621@item
16622@code{( @var{group} )+} means that @var{group} inside the parentheses
16623may repeat one or more times.
16624
16625@item
16626@code{"@var{string}"} means a literal @var{string}.
16627@end itemize
16628
16629@ignore
16630@heading Dependencies
16631@end ignore
16632
16633@heading Acknowledgments
16634
16635In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
16636Elena Zannoni.
16637
16638@menu
16639* GDB/MI Command Syntax::
16640* GDB/MI Compatibility with CLI::
16641* GDB/MI Output Records::
16642* GDB/MI Command Description Format::
16643* GDB/MI Breakpoint Table Commands::
16644* GDB/MI Data Manipulation::
16645* GDB/MI Program Control::
16646* GDB/MI Miscellaneous Commands::
16647@ignore
16648* GDB/MI Kod Commands::
16649* GDB/MI Memory Overlay Commands::
16650* GDB/MI Signal Handling Commands::
16651@end ignore
16652* GDB/MI Stack Manipulation::
16653* GDB/MI Symbol Query::
16654* GDB/MI Target Manipulation::
16655* GDB/MI Thread Commands::
16656* GDB/MI Tracepoint Commands::
16657* GDB/MI Variable Objects::
16658@end menu
16659
16660@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16661@node GDB/MI Command Syntax
16662@section @sc{gdb/mi} Command Syntax
16663
16664@menu
16665* GDB/MI Input Syntax::
16666* GDB/MI Output Syntax::
16667* GDB/MI Simple Examples::
16668@end menu
16669
16670@node GDB/MI Input Syntax
16671@subsection @sc{gdb/mi} Input Syntax
16672
16673@cindex input syntax for @sc{gdb/mi}
16674@cindex @sc{gdb/mi}, input syntax
16675@table @code
16676@item @var{command} @expansion{}
16677@code{@var{cli-command} | @var{mi-command}}
16678
16679@item @var{cli-command} @expansion{}
16680@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
16681@var{cli-command} is any existing @value{GDBN} CLI command.
16682
16683@item @var{mi-command} @expansion{}
16684@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
16685@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
16686
16687@item @var{token} @expansion{}
16688"any sequence of digits"
16689
16690@item @var{option} @expansion{}
16691@code{"-" @var{parameter} [ " " @var{parameter} ]}
16692
16693@item @var{parameter} @expansion{}
16694@code{@var{non-blank-sequence} | @var{c-string}}
16695
16696@item @var{operation} @expansion{}
16697@emph{any of the operations described in this chapter}
16698
16699@item @var{non-blank-sequence} @expansion{}
16700@emph{anything, provided it doesn't contain special characters such as
16701"-", @var{nl}, """ and of course " "}
16702
16703@item @var{c-string} @expansion{}
16704@code{""" @var{seven-bit-iso-c-string-content} """}
16705
16706@item @var{nl} @expansion{}
16707@code{CR | CR-LF}
16708@end table
16709
16710@noindent
16711Notes:
16712
16713@itemize @bullet
16714@item
16715The CLI commands are still handled by the @sc{mi} interpreter; their
16716output is described below.
16717
16718@item
16719The @code{@var{token}}, when present, is passed back when the command
16720finishes.
16721
16722@item
16723Some @sc{mi} commands accept optional arguments as part of the parameter
16724list. Each option is identified by a leading @samp{-} (dash) and may be
16725followed by an optional argument parameter. Options occur first in the
16726parameter list and can be delimited from normal parameters using
16727@samp{--} (this is useful when some parameters begin with a dash).
16728@end itemize
16729
16730Pragmatics:
16731
16732@itemize @bullet
16733@item
16734We want easy access to the existing CLI syntax (for debugging).
16735
16736@item
16737We want it to be easy to spot a @sc{mi} operation.
16738@end itemize
16739
16740@node GDB/MI Output Syntax
16741@subsection @sc{gdb/mi} Output Syntax
16742
16743@cindex output syntax of @sc{gdb/mi}
16744@cindex @sc{gdb/mi}, output syntax
16745The output from @sc{gdb/mi} consists of zero or more out-of-band records
16746followed, optionally, by a single result record. This result record
16747is for the most recent command. The sequence of output records is
16748terminated by @samp{(@value{GDBP})}.
16749
16750If an input command was prefixed with a @code{@var{token}} then the
16751corresponding output for that command will also be prefixed by that same
16752@var{token}.
16753
16754@table @code
16755@item @var{output} @expansion{}
f7dc1244 16756@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
922fbb7b
AC
16757
16758@item @var{result-record} @expansion{}
16759@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
16760
16761@item @var{out-of-band-record} @expansion{}
16762@code{@var{async-record} | @var{stream-record}}
16763
16764@item @var{async-record} @expansion{}
16765@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
16766
16767@item @var{exec-async-output} @expansion{}
16768@code{[ @var{token} ] "*" @var{async-output}}
16769
16770@item @var{status-async-output} @expansion{}
16771@code{[ @var{token} ] "+" @var{async-output}}
16772
16773@item @var{notify-async-output} @expansion{}
16774@code{[ @var{token} ] "=" @var{async-output}}
16775
16776@item @var{async-output} @expansion{}
16777@code{@var{async-class} ( "," @var{result} )* @var{nl}}
16778
16779@item @var{result-class} @expansion{}
16780@code{"done" | "running" | "connected" | "error" | "exit"}
16781
16782@item @var{async-class} @expansion{}
16783@code{"stopped" | @var{others}} (where @var{others} will be added
16784depending on the needs---this is still in development).
16785
16786@item @var{result} @expansion{}
16787@code{ @var{variable} "=" @var{value}}
16788
16789@item @var{variable} @expansion{}
16790@code{ @var{string} }
16791
16792@item @var{value} @expansion{}
16793@code{ @var{const} | @var{tuple} | @var{list} }
16794
16795@item @var{const} @expansion{}
16796@code{@var{c-string}}
16797
16798@item @var{tuple} @expansion{}
16799@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
16800
16801@item @var{list} @expansion{}
16802@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
16803@var{result} ( "," @var{result} )* "]" }
16804
16805@item @var{stream-record} @expansion{}
16806@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
16807
16808@item @var{console-stream-output} @expansion{}
16809@code{"~" @var{c-string}}
16810
16811@item @var{target-stream-output} @expansion{}
16812@code{"@@" @var{c-string}}
16813
16814@item @var{log-stream-output} @expansion{}
16815@code{"&" @var{c-string}}
16816
16817@item @var{nl} @expansion{}
16818@code{CR | CR-LF}
16819
16820@item @var{token} @expansion{}
16821@emph{any sequence of digits}.
16822@end table
16823
16824@noindent
16825Notes:
16826
16827@itemize @bullet
16828@item
16829All output sequences end in a single line containing a period.
16830
16831@item
16832The @code{@var{token}} is from the corresponding request. If an execution
16833command is interrupted by the @samp{-exec-interrupt} command, the
16834@var{token} associated with the @samp{*stopped} message is the one of the
16835original execution command, not the one of the interrupt command.
16836
16837@item
16838@cindex status output in @sc{gdb/mi}
16839@var{status-async-output} contains on-going status information about the
16840progress of a slow operation. It can be discarded. All status output is
16841prefixed by @samp{+}.
16842
16843@item
16844@cindex async output in @sc{gdb/mi}
16845@var{exec-async-output} contains asynchronous state change on the target
16846(stopped, started, disappeared). All async output is prefixed by
16847@samp{*}.
16848
16849@item
16850@cindex notify output in @sc{gdb/mi}
16851@var{notify-async-output} contains supplementary information that the
16852client should handle (e.g., a new breakpoint information). All notify
16853output is prefixed by @samp{=}.
16854
16855@item
16856@cindex console output in @sc{gdb/mi}
16857@var{console-stream-output} is output that should be displayed as is in the
16858console. It is the textual response to a CLI command. All the console
16859output is prefixed by @samp{~}.
16860
16861@item
16862@cindex target output in @sc{gdb/mi}
16863@var{target-stream-output} is the output produced by the target program.
16864All the target output is prefixed by @samp{@@}.
16865
16866@item
16867@cindex log output in @sc{gdb/mi}
16868@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
16869instance messages that should be displayed as part of an error log. All
16870the log output is prefixed by @samp{&}.
16871
16872@item
16873@cindex list output in @sc{gdb/mi}
16874New @sc{gdb/mi} commands should only output @var{lists} containing
16875@var{values}.
16876
16877
16878@end itemize
16879
16880@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
16881details about the various output records.
16882
16883@node GDB/MI Simple Examples
16884@subsection Simple Examples of @sc{gdb/mi} Interaction
16885@cindex @sc{gdb/mi}, simple examples
16886
16887This subsection presents several simple examples of interaction using
16888the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
16889following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
16890the output received from @sc{gdb/mi}.
16891
16892@subsubheading Target Stop
16893@c Ummm... There is no "-stop" command. This assumes async, no?
16894Here's an example of stopping the inferior process:
16895
16896@smallexample
16897-> -stop
16898<- (@value{GDBP})
16899@end smallexample
16900
16901@noindent
16902and later:
16903
16904@smallexample
16905<- *stop,reason="stop",address="0x123",source="a.c:123"
16906<- (@value{GDBP})
16907@end smallexample
16908
16909@subsubheading Simple CLI Command
16910
16911Here's an example of a simple CLI command being passed through
16912@sc{gdb/mi} and on to the CLI.
16913
16914@smallexample
16915-> print 1+2
16916<- &"print 1+2\n"
16917<- ~"$1 = 3\n"
16918<- ^done
16919<- (@value{GDBP})
16920@end smallexample
16921
16922@subsubheading Command With Side Effects
16923
16924@smallexample
16925-> -symbol-file xyz.exe
16926<- *breakpoint,nr="3",address="0x123",source="a.c:123"
16927<- (@value{GDBP})
16928@end smallexample
16929
16930@subsubheading A Bad Command
16931
16932Here's what happens if you pass a non-existent command:
16933
16934@smallexample
16935-> -rubbish
16936<- ^error,msg="Undefined MI command: rubbish"
16937<- (@value{GDBP})
16938@end smallexample
16939
16940@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16941@node GDB/MI Compatibility with CLI
16942@section @sc{gdb/mi} Compatibility with CLI
16943
16944@cindex compatibility, @sc{gdb/mi} and CLI
16945@cindex @sc{gdb/mi}, compatibility with CLI
16946To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
16947accepts existing CLI commands. As specified by the syntax, such
16948commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
16949respond.
16950
16951This mechanism is provided as an aid to developers of @sc{gdb/mi}
16952clients and not as a reliable interface into the CLI. Since the command
16953is being interpreteted in an environment that assumes @sc{gdb/mi}
16954behaviour, the exact output of such commands is likely to end up being
16955an un-supported hybrid of @sc{gdb/mi} and CLI output.
16956
16957@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16958@node GDB/MI Output Records
16959@section @sc{gdb/mi} Output Records
16960
16961@menu
16962* GDB/MI Result Records::
16963* GDB/MI Stream Records::
16964* GDB/MI Out-of-band Records::
16965@end menu
16966
16967@node GDB/MI Result Records
16968@subsection @sc{gdb/mi} Result Records
16969
16970@cindex result records in @sc{gdb/mi}
16971@cindex @sc{gdb/mi}, result records
16972In addition to a number of out-of-band notifications, the response to a
16973@sc{gdb/mi} command includes one of the following result indications:
16974
16975@table @code
16976@findex ^done
16977@item "^done" [ "," @var{results} ]
16978The synchronous operation was successful, @code{@var{results}} are the return
16979values.
16980
16981@item "^running"
16982@findex ^running
16983@c Is this one correct? Should it be an out-of-band notification?
16984The asynchronous operation was successfully started. The target is
16985running.
16986
16987@item "^error" "," @var{c-string}
16988@findex ^error
16989The operation failed. The @code{@var{c-string}} contains the corresponding
16990error message.
16991@end table
16992
16993@node GDB/MI Stream Records
16994@subsection @sc{gdb/mi} Stream Records
16995
16996@cindex @sc{gdb/mi}, stream records
16997@cindex stream records in @sc{gdb/mi}
16998@value{GDBN} internally maintains a number of output streams: the console, the
16999target, and the log. The output intended for each of these streams is
17000funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
17001
17002Each stream record begins with a unique @dfn{prefix character} which
17003identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
17004Syntax}). In addition to the prefix, each stream record contains a
17005@code{@var{string-output}}. This is either raw text (with an implicit new
17006line) or a quoted C string (which does not contain an implicit newline).
17007
17008@table @code
17009@item "~" @var{string-output}
17010The console output stream contains text that should be displayed in the
17011CLI console window. It contains the textual responses to CLI commands.
17012
17013@item "@@" @var{string-output}
17014The target output stream contains any textual output from the running
17015target.
17016
17017@item "&" @var{string-output}
17018The log stream contains debugging messages being produced by @value{GDBN}'s
17019internals.
17020@end table
17021
17022@node GDB/MI Out-of-band Records
17023@subsection @sc{gdb/mi} Out-of-band Records
17024
17025@cindex out-of-band records in @sc{gdb/mi}
17026@cindex @sc{gdb/mi}, out-of-band records
17027@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
17028additional changes that have occurred. Those changes can either be a
17029consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
17030target activity (e.g., target stopped).
17031
17032The following is a preliminary list of possible out-of-band records.
034dad6f 17033In particular, the @var{exec-async-output} records.
922fbb7b
AC
17034
17035@table @code
034dad6f
BR
17036@item *stopped,reason="@var{reason}"
17037@end table
17038
17039@var{reason} can be one of the following:
17040
17041@table @code
17042@item breakpoint-hit
17043A breakpoint was reached.
17044@item watchpoint-trigger
17045A watchpoint was triggered.
17046@item read-watchpoint-trigger
17047A read watchpoint was triggered.
17048@item access-watchpoint-trigger
17049An access watchpoint was triggered.
17050@item function-finished
17051An -exec-finish or similar CLI command was accomplished.
17052@item location-reached
17053An -exec-until or similar CLI command was accomplished.
17054@item watchpoint-scope
17055A watchpoint has gone out of scope.
17056@item end-stepping-range
17057An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
17058similar CLI command was accomplished.
17059@item exited-signalled
17060The inferior exited because of a signal.
17061@item exited
17062The inferior exited.
17063@item exited-normally
17064The inferior exited normally.
17065@item signal-received
17066A signal was received by the inferior.
922fbb7b
AC
17067@end table
17068
17069
17070@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17071@node GDB/MI Command Description Format
17072@section @sc{gdb/mi} Command Description Format
17073
17074The remaining sections describe blocks of commands. Each block of
17075commands is laid out in a fashion similar to this section.
17076
17077Note the the line breaks shown in the examples are here only for
17078readability. They don't appear in the real output.
17079Also note that the commands with a non-available example (N.A.@:) are
17080not yet implemented.
17081
17082@subheading Motivation
17083
17084The motivation for this collection of commands.
17085
17086@subheading Introduction
17087
17088A brief introduction to this collection of commands as a whole.
17089
17090@subheading Commands
17091
17092For each command in the block, the following is described:
17093
17094@subsubheading Synopsis
17095
17096@smallexample
17097 -command @var{args}@dots{}
17098@end smallexample
17099
922fbb7b
AC
17100@subsubheading Result
17101
265eeb58 17102@subsubheading @value{GDBN} Command
922fbb7b 17103
265eeb58 17104The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
17105
17106@subsubheading Example
17107
922fbb7b
AC
17108@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17109@node GDB/MI Breakpoint Table Commands
17110@section @sc{gdb/mi} Breakpoint table commands
17111
17112@cindex breakpoint commands for @sc{gdb/mi}
17113@cindex @sc{gdb/mi}, breakpoint commands
17114This section documents @sc{gdb/mi} commands for manipulating
17115breakpoints.
17116
17117@subheading The @code{-break-after} Command
17118@findex -break-after
17119
17120@subsubheading Synopsis
17121
17122@smallexample
17123 -break-after @var{number} @var{count}
17124@end smallexample
17125
17126The breakpoint number @var{number} is not in effect until it has been
17127hit @var{count} times. To see how this is reflected in the output of
17128the @samp{-break-list} command, see the description of the
17129@samp{-break-list} command below.
17130
17131@subsubheading @value{GDBN} Command
17132
17133The corresponding @value{GDBN} command is @samp{ignore}.
17134
17135@subsubheading Example
17136
17137@smallexample
17138(@value{GDBP})
17139-break-insert main
17140^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
17141(@value{GDBP})
17142-break-after 1 3
17143~
17144^done
17145(@value{GDBP})
17146-break-list
17147^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17148hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17149@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17150@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17151@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17152@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17153@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17154body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17155addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
17156ignore="3"@}]@}
17157(@value{GDBP})
17158@end smallexample
17159
17160@ignore
17161@subheading The @code{-break-catch} Command
17162@findex -break-catch
17163
17164@subheading The @code{-break-commands} Command
17165@findex -break-commands
17166@end ignore
17167
17168
17169@subheading The @code{-break-condition} Command
17170@findex -break-condition
17171
17172@subsubheading Synopsis
17173
17174@smallexample
17175 -break-condition @var{number} @var{expr}
17176@end smallexample
17177
17178Breakpoint @var{number} will stop the program only if the condition in
17179@var{expr} is true. The condition becomes part of the
17180@samp{-break-list} output (see the description of the @samp{-break-list}
17181command below).
17182
17183@subsubheading @value{GDBN} Command
17184
17185The corresponding @value{GDBN} command is @samp{condition}.
17186
17187@subsubheading Example
17188
17189@smallexample
17190(@value{GDBP})
17191-break-condition 1 1
17192^done
17193(@value{GDBP})
17194-break-list
17195^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17196hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17197@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17198@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17199@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17200@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17201@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17202body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17203addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
17204times="0",ignore="3"@}]@}
17205(@value{GDBP})
17206@end smallexample
17207
17208@subheading The @code{-break-delete} Command
17209@findex -break-delete
17210
17211@subsubheading Synopsis
17212
17213@smallexample
17214 -break-delete ( @var{breakpoint} )+
17215@end smallexample
17216
17217Delete the breakpoint(s) whose number(s) are specified in the argument
17218list. This is obviously reflected in the breakpoint list.
17219
17220@subsubheading @value{GDBN} command
17221
17222The corresponding @value{GDBN} command is @samp{delete}.
17223
17224@subsubheading Example
17225
17226@smallexample
17227(@value{GDBP})
17228-break-delete 1
17229^done
17230(@value{GDBP})
17231-break-list
17232^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17233hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17234@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17235@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17236@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17237@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17238@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17239body=[]@}
17240(@value{GDBP})
17241@end smallexample
17242
17243@subheading The @code{-break-disable} Command
17244@findex -break-disable
17245
17246@subsubheading Synopsis
17247
17248@smallexample
17249 -break-disable ( @var{breakpoint} )+
17250@end smallexample
17251
17252Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
17253break list is now set to @samp{n} for the named @var{breakpoint}(s).
17254
17255@subsubheading @value{GDBN} Command
17256
17257The corresponding @value{GDBN} command is @samp{disable}.
17258
17259@subsubheading Example
17260
17261@smallexample
17262(@value{GDBP})
17263-break-disable 2
17264^done
17265(@value{GDBP})
17266-break-list
17267^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17268hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17269@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17270@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17271@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17272@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17273@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17274body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
17275addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17276(@value{GDBP})
17277@end smallexample
17278
17279@subheading The @code{-break-enable} Command
17280@findex -break-enable
17281
17282@subsubheading Synopsis
17283
17284@smallexample
17285 -break-enable ( @var{breakpoint} )+
17286@end smallexample
17287
17288Enable (previously disabled) @var{breakpoint}(s).
17289
17290@subsubheading @value{GDBN} Command
17291
17292The corresponding @value{GDBN} command is @samp{enable}.
17293
17294@subsubheading Example
17295
17296@smallexample
17297(@value{GDBP})
17298-break-enable 2
17299^done
17300(@value{GDBP})
17301-break-list
17302^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17303hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17304@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17305@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17306@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17307@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17308@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17309body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17310addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17311(@value{GDBP})
17312@end smallexample
17313
17314@subheading The @code{-break-info} Command
17315@findex -break-info
17316
17317@subsubheading Synopsis
17318
17319@smallexample
17320 -break-info @var{breakpoint}
17321@end smallexample
17322
17323@c REDUNDANT???
17324Get information about a single breakpoint.
17325
17326@subsubheading @value{GDBN} command
17327
17328The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
17329
17330@subsubheading Example
17331N.A.
17332
17333@subheading The @code{-break-insert} Command
17334@findex -break-insert
17335
17336@subsubheading Synopsis
17337
17338@smallexample
17339 -break-insert [ -t ] [ -h ] [ -r ]
17340 [ -c @var{condition} ] [ -i @var{ignore-count} ]
17341 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
17342@end smallexample
17343
17344@noindent
17345If specified, @var{line}, can be one of:
17346
17347@itemize @bullet
17348@item function
17349@c @item +offset
17350@c @item -offset
17351@c @item linenum
17352@item filename:linenum
17353@item filename:function
17354@item *address
17355@end itemize
17356
17357The possible optional parameters of this command are:
17358
17359@table @samp
17360@item -t
17361Insert a tempoary breakpoint.
17362@item -h
17363Insert a hardware breakpoint.
17364@item -c @var{condition}
17365Make the breakpoint conditional on @var{condition}.
17366@item -i @var{ignore-count}
17367Initialize the @var{ignore-count}.
17368@item -r
17369Insert a regular breakpoint in all the functions whose names match the
17370given regular expression. Other flags are not applicable to regular
17371expresson.
17372@end table
17373
17374@subsubheading Result
17375
17376The result is in the form:
17377
17378@smallexample
17379 ^done,bkptno="@var{number}",func="@var{funcname}",
17380 file="@var{filename}",line="@var{lineno}"
17381@end smallexample
17382
17383@noindent
17384where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
17385is the name of the function where the breakpoint was inserted,
17386@var{filename} is the name of the source file which contains this
17387function, and @var{lineno} is the source line number within that file.
17388
17389Note: this format is open to change.
17390@c An out-of-band breakpoint instead of part of the result?
17391
17392@subsubheading @value{GDBN} Command
17393
17394The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
17395@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
17396
17397@subsubheading Example
17398
17399@smallexample
17400(@value{GDBP})
17401-break-insert main
17402^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17403(@value{GDBP})
17404-break-insert -t foo
17405^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
17406(@value{GDBP})
17407-break-list
17408^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17409hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17410@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17411@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17412@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17413@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17414@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17415body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17416addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
17417bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
17418addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
17419(@value{GDBP})
17420-break-insert -r foo.*
17421~int foo(int, int);
17422^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
17423(@value{GDBP})
17424@end smallexample
17425
17426@subheading The @code{-break-list} Command
17427@findex -break-list
17428
17429@subsubheading Synopsis
17430
17431@smallexample
17432 -break-list
17433@end smallexample
17434
17435Displays the list of inserted breakpoints, showing the following fields:
17436
17437@table @samp
17438@item Number
17439number of the breakpoint
17440@item Type
17441type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
17442@item Disposition
17443should the breakpoint be deleted or disabled when it is hit: @samp{keep}
17444or @samp{nokeep}
17445@item Enabled
17446is the breakpoint enabled or no: @samp{y} or @samp{n}
17447@item Address
17448memory location at which the breakpoint is set
17449@item What
17450logical location of the breakpoint, expressed by function name, file
17451name, line number
17452@item Times
17453number of times the breakpoint has been hit
17454@end table
17455
17456If there are no breakpoints or watchpoints, the @code{BreakpointTable}
17457@code{body} field is an empty list.
17458
17459@subsubheading @value{GDBN} Command
17460
17461The corresponding @value{GDBN} command is @samp{info break}.
17462
17463@subsubheading Example
17464
17465@smallexample
17466(@value{GDBP})
17467-break-list
17468^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17469hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17470@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17471@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17472@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17473@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17474@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17475body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17476addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
17477bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17478addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
17479(@value{GDBP})
17480@end smallexample
17481
17482Here's an example of the result when there are no breakpoints:
17483
17484@smallexample
17485(@value{GDBP})
17486-break-list
17487^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17488hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17489@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17490@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17491@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17492@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17493@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17494body=[]@}
17495(@value{GDBP})
17496@end smallexample
17497
17498@subheading The @code{-break-watch} Command
17499@findex -break-watch
17500
17501@subsubheading Synopsis
17502
17503@smallexample
17504 -break-watch [ -a | -r ]
17505@end smallexample
17506
17507Create a watchpoint. With the @samp{-a} option it will create an
17508@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
17509read from or on a write to the memory location. With the @samp{-r}
17510option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
17511trigger only when the memory location is accessed for reading. Without
17512either of the options, the watchpoint created is a regular watchpoint,
17513i.e. it will trigger when the memory location is accessed for writing.
17514@xref{Set Watchpoints, , Setting watchpoints}.
17515
17516Note that @samp{-break-list} will report a single list of watchpoints and
17517breakpoints inserted.
17518
17519@subsubheading @value{GDBN} Command
17520
17521The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
17522@samp{rwatch}.
17523
17524@subsubheading Example
17525
17526Setting a watchpoint on a variable in the @code{main} function:
17527
17528@smallexample
17529(@value{GDBP})
17530-break-watch x
17531^done,wpt=@{number="2",exp="x"@}
17532(@value{GDBP})
17533-exec-continue
17534^running
17535^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
17536value=@{old="-268439212",new="55"@},
76ff342d
DJ
17537frame=@{func="main",args=[],file="recursive2.c",
17538fullname="/home/foo/bar/devo/myproject/recursive2.c",line="5"@}
922fbb7b
AC
17539(@value{GDBP})
17540@end smallexample
17541
17542Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
17543the program execution twice: first for the variable changing value, then
17544for the watchpoint going out of scope.
17545
17546@smallexample
17547(@value{GDBP})
17548-break-watch C
17549^done,wpt=@{number="5",exp="C"@}
17550(@value{GDBP})
17551-exec-continue
17552^running
17553^done,reason="watchpoint-trigger",
17554wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
17555frame=@{func="callee4",args=[],
76ff342d
DJ
17556file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17557fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17558(@value{GDBP})
17559-exec-continue
17560^running
17561^done,reason="watchpoint-scope",wpnum="5",
17562frame=@{func="callee3",args=[@{name="strarg",
17563value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17564file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17565fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17566(@value{GDBP})
17567@end smallexample
17568
17569Listing breakpoints and watchpoints, at different points in the program
17570execution. Note that once the watchpoint goes out of scope, it is
17571deleted.
17572
17573@smallexample
17574(@value{GDBP})
17575-break-watch C
17576^done,wpt=@{number="2",exp="C"@}
17577(@value{GDBP})
17578-break-list
17579^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17580hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17581@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17582@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17583@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17584@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17585@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17586body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17587addr="0x00010734",func="callee4",
17588file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17589bkpt=@{number="2",type="watchpoint",disp="keep",
17590enabled="y",addr="",what="C",times="0"@}]@}
17591(@value{GDBP})
17592-exec-continue
17593^running
17594^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
17595value=@{old="-276895068",new="3"@},
17596frame=@{func="callee4",args=[],
76ff342d
DJ
17597file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17598fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17599(@value{GDBP})
17600-break-list
17601^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17602hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17603@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17604@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17605@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17606@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17607@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17608body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17609addr="0x00010734",func="callee4",
17610file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17611bkpt=@{number="2",type="watchpoint",disp="keep",
17612enabled="y",addr="",what="C",times="-5"@}]@}
17613(@value{GDBP})
17614-exec-continue
17615^running
17616^done,reason="watchpoint-scope",wpnum="2",
17617frame=@{func="callee3",args=[@{name="strarg",
17618value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17619file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17620fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17621(@value{GDBP})
17622-break-list
17623^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17624hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17625@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17626@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17627@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17628@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17629@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17630body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17631addr="0x00010734",func="callee4",
17632file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
17633(@value{GDBP})
17634@end smallexample
17635
17636@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17637@node GDB/MI Data Manipulation
17638@section @sc{gdb/mi} Data Manipulation
17639
17640@cindex data manipulation, in @sc{gdb/mi}
17641@cindex @sc{gdb/mi}, data manipulation
17642This section describes the @sc{gdb/mi} commands that manipulate data:
17643examine memory and registers, evaluate expressions, etc.
17644
17645@c REMOVED FROM THE INTERFACE.
17646@c @subheading -data-assign
17647@c Change the value of a program variable. Plenty of side effects.
17648@c @subsubheading GDB command
17649@c set variable
17650@c @subsubheading Example
17651@c N.A.
17652
17653@subheading The @code{-data-disassemble} Command
17654@findex -data-disassemble
17655
17656@subsubheading Synopsis
17657
17658@smallexample
17659 -data-disassemble
17660 [ -s @var{start-addr} -e @var{end-addr} ]
17661 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
17662 -- @var{mode}
17663@end smallexample
17664
17665@noindent
17666Where:
17667
17668@table @samp
17669@item @var{start-addr}
17670is the beginning address (or @code{$pc})
17671@item @var{end-addr}
17672is the end address
17673@item @var{filename}
17674is the name of the file to disassemble
17675@item @var{linenum}
17676is the line number to disassemble around
17677@item @var{lines}
17678is the the number of disassembly lines to be produced. If it is -1,
17679the whole function will be disassembled, in case no @var{end-addr} is
17680specified. If @var{end-addr} is specified as a non-zero value, and
17681@var{lines} is lower than the number of disassembly lines between
17682@var{start-addr} and @var{end-addr}, only @var{lines} lines are
17683displayed; if @var{lines} is higher than the number of lines between
17684@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
17685are displayed.
17686@item @var{mode}
17687is either 0 (meaning only disassembly) or 1 (meaning mixed source and
17688disassembly).
17689@end table
17690
17691@subsubheading Result
17692
17693The output for each instruction is composed of four fields:
17694
17695@itemize @bullet
17696@item Address
17697@item Func-name
17698@item Offset
17699@item Instruction
17700@end itemize
17701
17702Note that whatever included in the instruction field, is not manipulated
17703directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
17704
17705@subsubheading @value{GDBN} Command
17706
17707There's no direct mapping from this command to the CLI.
17708
17709@subsubheading Example
17710
17711Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
17712
17713@smallexample
17714(@value{GDBP})
17715-data-disassemble -s $pc -e "$pc + 20" -- 0
17716^done,
17717asm_insns=[
17718@{address="0x000107c0",func-name="main",offset="4",
17719inst="mov 2, %o0"@},
17720@{address="0x000107c4",func-name="main",offset="8",
17721inst="sethi %hi(0x11800), %o2"@},
17722@{address="0x000107c8",func-name="main",offset="12",
17723inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
17724@{address="0x000107cc",func-name="main",offset="16",
17725inst="sethi %hi(0x11800), %o2"@},
17726@{address="0x000107d0",func-name="main",offset="20",
17727inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
17728(@value{GDBP})
17729@end smallexample
17730
17731Disassemble the whole @code{main} function. Line 32 is part of
17732@code{main}.
17733
17734@smallexample
17735-data-disassemble -f basics.c -l 32 -- 0
17736^done,asm_insns=[
17737@{address="0x000107bc",func-name="main",offset="0",
17738inst="save %sp, -112, %sp"@},
17739@{address="0x000107c0",func-name="main",offset="4",
17740inst="mov 2, %o0"@},
17741@{address="0x000107c4",func-name="main",offset="8",
17742inst="sethi %hi(0x11800), %o2"@},
17743[@dots{}]
17744@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
17745@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
17746(@value{GDBP})
17747@end smallexample
17748
17749Disassemble 3 instructions from the start of @code{main}:
17750
17751@smallexample
17752(@value{GDBP})
17753-data-disassemble -f basics.c -l 32 -n 3 -- 0
17754^done,asm_insns=[
17755@{address="0x000107bc",func-name="main",offset="0",
17756inst="save %sp, -112, %sp"@},
17757@{address="0x000107c0",func-name="main",offset="4",
17758inst="mov 2, %o0"@},
17759@{address="0x000107c4",func-name="main",offset="8",
17760inst="sethi %hi(0x11800), %o2"@}]
17761(@value{GDBP})
17762@end smallexample
17763
17764Disassemble 3 instructions from the start of @code{main} in mixed mode:
17765
17766@smallexample
17767(@value{GDBP})
17768-data-disassemble -f basics.c -l 32 -n 3 -- 1
17769^done,asm_insns=[
17770src_and_asm_line=@{line="31",
17771file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17772 testsuite/gdb.mi/basics.c",line_asm_insn=[
17773@{address="0x000107bc",func-name="main",offset="0",
17774inst="save %sp, -112, %sp"@}]@},
17775src_and_asm_line=@{line="32",
17776file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17777 testsuite/gdb.mi/basics.c",line_asm_insn=[
17778@{address="0x000107c0",func-name="main",offset="4",
17779inst="mov 2, %o0"@},
17780@{address="0x000107c4",func-name="main",offset="8",
17781inst="sethi %hi(0x11800), %o2"@}]@}]
17782(@value{GDBP})
17783@end smallexample
17784
17785
17786@subheading The @code{-data-evaluate-expression} Command
17787@findex -data-evaluate-expression
17788
17789@subsubheading Synopsis
17790
17791@smallexample
17792 -data-evaluate-expression @var{expr}
17793@end smallexample
17794
17795Evaluate @var{expr} as an expression. The expression could contain an
17796inferior function call. The function call will execute synchronously.
17797If the expression contains spaces, it must be enclosed in double quotes.
17798
17799@subsubheading @value{GDBN} Command
17800
17801The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
17802@samp{call}. In @code{gdbtk} only, there's a corresponding
17803@samp{gdb_eval} command.
17804
17805@subsubheading Example
17806
17807In the following example, the numbers that precede the commands are the
17808@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
17809Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
17810output.
17811
17812@smallexample
17813211-data-evaluate-expression A
17814211^done,value="1"
17815(@value{GDBP})
17816311-data-evaluate-expression &A
17817311^done,value="0xefffeb7c"
17818(@value{GDBP})
17819411-data-evaluate-expression A+3
17820411^done,value="4"
17821(@value{GDBP})
17822511-data-evaluate-expression "A + 3"
17823511^done,value="4"
17824(@value{GDBP})
17825@end smallexample
17826
17827
17828@subheading The @code{-data-list-changed-registers} Command
17829@findex -data-list-changed-registers
17830
17831@subsubheading Synopsis
17832
17833@smallexample
17834 -data-list-changed-registers
17835@end smallexample
17836
17837Display a list of the registers that have changed.
17838
17839@subsubheading @value{GDBN} Command
17840
17841@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
17842has the corresponding command @samp{gdb_changed_register_list}.
17843
17844@subsubheading Example
17845
17846On a PPC MBX board:
17847
17848@smallexample
17849(@value{GDBP})
17850-exec-continue
17851^running
17852
17853(@value{GDBP})
17854*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
76ff342d 17855args=[],file="try.c",fullname="/home/foo/bar/devo/myproject/try.c",line="5"@}
922fbb7b
AC
17856(@value{GDBP})
17857-data-list-changed-registers
17858^done,changed-registers=["0","1","2","4","5","6","7","8","9",
17859"10","11","13","14","15","16","17","18","19","20","21","22","23",
17860"24","25","26","27","28","30","31","64","65","66","67","69"]
17861(@value{GDBP})
17862@end smallexample
17863
17864
17865@subheading The @code{-data-list-register-names} Command
17866@findex -data-list-register-names
17867
17868@subsubheading Synopsis
17869
17870@smallexample
17871 -data-list-register-names [ ( @var{regno} )+ ]
17872@end smallexample
17873
17874Show a list of register names for the current target. If no arguments
17875are given, it shows a list of the names of all the registers. If
17876integer numbers are given as arguments, it will print a list of the
17877names of the registers corresponding to the arguments. To ensure
17878consistency between a register name and its number, the output list may
17879include empty register names.
17880
17881@subsubheading @value{GDBN} Command
17882
17883@value{GDBN} does not have a command which corresponds to
17884@samp{-data-list-register-names}. In @code{gdbtk} there is a
17885corresponding command @samp{gdb_regnames}.
17886
17887@subsubheading Example
17888
17889For the PPC MBX board:
17890@smallexample
17891(@value{GDBP})
17892-data-list-register-names
17893^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
17894"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
17895"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
17896"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
17897"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
17898"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
17899"", "pc","ps","cr","lr","ctr","xer"]
17900(@value{GDBP})
17901-data-list-register-names 1 2 3
17902^done,register-names=["r1","r2","r3"]
17903(@value{GDBP})
17904@end smallexample
17905
17906@subheading The @code{-data-list-register-values} Command
17907@findex -data-list-register-values
17908
17909@subsubheading Synopsis
17910
17911@smallexample
17912 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
17913@end smallexample
17914
17915Display the registers' contents. @var{fmt} is the format according to
17916which the registers' contents are to be returned, followed by an optional
17917list of numbers specifying the registers to display. A missing list of
17918numbers indicates that the contents of all the registers must be returned.
17919
17920Allowed formats for @var{fmt} are:
17921
17922@table @code
17923@item x
17924Hexadecimal
17925@item o
17926Octal
17927@item t
17928Binary
17929@item d
17930Decimal
17931@item r
17932Raw
17933@item N
17934Natural
17935@end table
17936
17937@subsubheading @value{GDBN} Command
17938
17939The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
17940all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
17941
17942@subsubheading Example
17943
17944For a PPC MBX board (note: line breaks are for readability only, they
17945don't appear in the actual output):
17946
17947@smallexample
17948(@value{GDBP})
17949-data-list-register-values r 64 65
17950^done,register-values=[@{number="64",value="0xfe00a300"@},
17951@{number="65",value="0x00029002"@}]
17952(@value{GDBP})
17953-data-list-register-values x
17954^done,register-values=[@{number="0",value="0xfe0043c8"@},
17955@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
17956@{number="3",value="0x0"@},@{number="4",value="0xa"@},
17957@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
17958@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
17959@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
17960@{number="11",value="0x1"@},@{number="12",value="0x0"@},
17961@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
17962@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
17963@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
17964@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
17965@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
17966@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
17967@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
17968@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
17969@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
17970@{number="31",value="0x0"@},@{number="32",value="0x0"@},
17971@{number="33",value="0x0"@},@{number="34",value="0x0"@},
17972@{number="35",value="0x0"@},@{number="36",value="0x0"@},
17973@{number="37",value="0x0"@},@{number="38",value="0x0"@},
17974@{number="39",value="0x0"@},@{number="40",value="0x0"@},
17975@{number="41",value="0x0"@},@{number="42",value="0x0"@},
17976@{number="43",value="0x0"@},@{number="44",value="0x0"@},
17977@{number="45",value="0x0"@},@{number="46",value="0x0"@},
17978@{number="47",value="0x0"@},@{number="48",value="0x0"@},
17979@{number="49",value="0x0"@},@{number="50",value="0x0"@},
17980@{number="51",value="0x0"@},@{number="52",value="0x0"@},
17981@{number="53",value="0x0"@},@{number="54",value="0x0"@},
17982@{number="55",value="0x0"@},@{number="56",value="0x0"@},
17983@{number="57",value="0x0"@},@{number="58",value="0x0"@},
17984@{number="59",value="0x0"@},@{number="60",value="0x0"@},
17985@{number="61",value="0x0"@},@{number="62",value="0x0"@},
17986@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
17987@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
17988@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
17989@{number="69",value="0x20002b03"@}]
17990(@value{GDBP})
17991@end smallexample
17992
17993
17994@subheading The @code{-data-read-memory} Command
17995@findex -data-read-memory
17996
17997@subsubheading Synopsis
17998
17999@smallexample
18000 -data-read-memory [ -o @var{byte-offset} ]
18001 @var{address} @var{word-format} @var{word-size}
18002 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
18003@end smallexample
18004
18005@noindent
18006where:
18007
18008@table @samp
18009@item @var{address}
18010An expression specifying the address of the first memory word to be
18011read. Complex expressions containing embedded white space should be
18012quoted using the C convention.
18013
18014@item @var{word-format}
18015The format to be used to print the memory words. The notation is the
18016same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
18017,Output formats}).
18018
18019@item @var{word-size}
18020The size of each memory word in bytes.
18021
18022@item @var{nr-rows}
18023The number of rows in the output table.
18024
18025@item @var{nr-cols}
18026The number of columns in the output table.
18027
18028@item @var{aschar}
18029If present, indicates that each row should include an @sc{ascii} dump. The
18030value of @var{aschar} is used as a padding character when a byte is not a
18031member of the printable @sc{ascii} character set (printable @sc{ascii}
18032characters are those whose code is between 32 and 126, inclusively).
18033
18034@item @var{byte-offset}
18035An offset to add to the @var{address} before fetching memory.
18036@end table
18037
18038This command displays memory contents as a table of @var{nr-rows} by
18039@var{nr-cols} words, each word being @var{word-size} bytes. In total,
18040@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
18041(returned as @samp{total-bytes}). Should less than the requested number
18042of bytes be returned by the target, the missing words are identified
18043using @samp{N/A}. The number of bytes read from the target is returned
18044in @samp{nr-bytes} and the starting address used to read memory in
18045@samp{addr}.
18046
18047The address of the next/previous row or page is available in
18048@samp{next-row} and @samp{prev-row}, @samp{next-page} and
18049@samp{prev-page}.
18050
18051@subsubheading @value{GDBN} Command
18052
18053The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
18054@samp{gdb_get_mem} memory read command.
18055
18056@subsubheading Example
18057
18058Read six bytes of memory starting at @code{bytes+6} but then offset by
18059@code{-6} bytes. Format as three rows of two columns. One byte per
18060word. Display each word in hex.
18061
18062@smallexample
18063(@value{GDBP})
180649-data-read-memory -o -6 -- bytes+6 x 1 3 2
180659^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
18066next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
18067prev-page="0x0000138a",memory=[
18068@{addr="0x00001390",data=["0x00","0x01"]@},
18069@{addr="0x00001392",data=["0x02","0x03"]@},
18070@{addr="0x00001394",data=["0x04","0x05"]@}]
18071(@value{GDBP})
18072@end smallexample
18073
18074Read two bytes of memory starting at address @code{shorts + 64} and
18075display as a single word formatted in decimal.
18076
18077@smallexample
18078(@value{GDBP})
180795-data-read-memory shorts+64 d 2 1 1
180805^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
18081next-row="0x00001512",prev-row="0x0000150e",
18082next-page="0x00001512",prev-page="0x0000150e",memory=[
18083@{addr="0x00001510",data=["128"]@}]
18084(@value{GDBP})
18085@end smallexample
18086
18087Read thirty two bytes of memory starting at @code{bytes+16} and format
18088as eight rows of four columns. Include a string encoding with @samp{x}
18089used as the non-printable character.
18090
18091@smallexample
18092(@value{GDBP})
180934-data-read-memory bytes+16 x 1 8 4 x
180944^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
18095next-row="0x000013c0",prev-row="0x0000139c",
18096next-page="0x000013c0",prev-page="0x00001380",memory=[
18097@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
18098@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
18099@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
18100@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
18101@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
18102@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
18103@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
18104@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
18105(@value{GDBP})
18106@end smallexample
18107
18108@subheading The @code{-display-delete} Command
18109@findex -display-delete
18110
18111@subsubheading Synopsis
18112
18113@smallexample
18114 -display-delete @var{number}
18115@end smallexample
18116
18117Delete the display @var{number}.
18118
18119@subsubheading @value{GDBN} Command
18120
18121The corresponding @value{GDBN} command is @samp{delete display}.
18122
18123@subsubheading Example
18124N.A.
18125
18126
18127@subheading The @code{-display-disable} Command
18128@findex -display-disable
18129
18130@subsubheading Synopsis
18131
18132@smallexample
18133 -display-disable @var{number}
18134@end smallexample
18135
18136Disable display @var{number}.
18137
18138@subsubheading @value{GDBN} Command
18139
18140The corresponding @value{GDBN} command is @samp{disable display}.
18141
18142@subsubheading Example
18143N.A.
18144
18145
18146@subheading The @code{-display-enable} Command
18147@findex -display-enable
18148
18149@subsubheading Synopsis
18150
18151@smallexample
18152 -display-enable @var{number}
18153@end smallexample
18154
18155Enable display @var{number}.
18156
18157@subsubheading @value{GDBN} Command
18158
18159The corresponding @value{GDBN} command is @samp{enable display}.
18160
18161@subsubheading Example
18162N.A.
18163
18164
18165@subheading The @code{-display-insert} Command
18166@findex -display-insert
18167
18168@subsubheading Synopsis
18169
18170@smallexample
18171 -display-insert @var{expression}
18172@end smallexample
18173
18174Display @var{expression} every time the program stops.
18175
18176@subsubheading @value{GDBN} Command
18177
18178The corresponding @value{GDBN} command is @samp{display}.
18179
18180@subsubheading Example
18181N.A.
18182
18183
18184@subheading The @code{-display-list} Command
18185@findex -display-list
18186
18187@subsubheading Synopsis
18188
18189@smallexample
18190 -display-list
18191@end smallexample
18192
18193List the displays. Do not show the current values.
18194
18195@subsubheading @value{GDBN} Command
18196
18197The corresponding @value{GDBN} command is @samp{info display}.
18198
18199@subsubheading Example
18200N.A.
18201
18202
18203@subheading The @code{-environment-cd} Command
18204@findex -environment-cd
18205
18206@subsubheading Synopsis
18207
18208@smallexample
18209 -environment-cd @var{pathdir}
18210@end smallexample
18211
18212Set @value{GDBN}'s working directory.
18213
18214@subsubheading @value{GDBN} Command
18215
18216The corresponding @value{GDBN} command is @samp{cd}.
18217
18218@subsubheading Example
18219
18220@smallexample
18221(@value{GDBP})
18222-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18223^done
18224(@value{GDBP})
18225@end smallexample
18226
18227
18228@subheading The @code{-environment-directory} Command
18229@findex -environment-directory
18230
18231@subsubheading Synopsis
18232
18233@smallexample
18234 -environment-directory [ -r ] [ @var{pathdir} ]+
18235@end smallexample
18236
18237Add directories @var{pathdir} to beginning of search path for source files.
18238If the @samp{-r} option is used, the search path is reset to the default
b383017d 18239search path. If directories @var{pathdir} are supplied in addition to the
922fbb7b
AC
18240@samp{-r} option, the search path is first reset and then addition
18241occurs as normal.
b383017d 18242Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18243multiple directories in a single command
18244results in the directories added to the beginning of the
18245search path in the same order they were presented in the command.
18246If blanks are needed as
18247part of a directory name, double-quotes should be used around
18248the name. In the command output, the path will show up separated
b383017d 18249by the system directory-separator character. The directory-seperator
922fbb7b
AC
18250character must not be used
18251in any directory name.
18252If no directories are specified, the current search path is displayed.
18253
18254@subsubheading @value{GDBN} Command
18255
18256The corresponding @value{GDBN} command is @samp{dir}.
18257
18258@subsubheading Example
18259
18260@smallexample
18261(@value{GDBP})
18262-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18263^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18264(@value{GDBP})
18265-environment-directory ""
18266^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18267(@value{GDBP})
18268-environment-directory -r /home/jjohnstn/src/gdb /usr/src
18269^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
18270(@value{GDBP})
18271-environment-directory -r
18272^done,source-path="$cdir:$cwd"
18273(@value{GDBP})
18274@end smallexample
18275
18276
18277@subheading The @code{-environment-path} Command
18278@findex -environment-path
18279
18280@subsubheading Synopsis
18281
18282@smallexample
18283 -environment-path [ -r ] [ @var{pathdir} ]+
18284@end smallexample
18285
18286Add directories @var{pathdir} to beginning of search path for object files.
18287If the @samp{-r} option is used, the search path is reset to the original
b383017d
RM
18288search path that existed at gdb start-up. If directories @var{pathdir} are
18289supplied in addition to the
922fbb7b
AC
18290@samp{-r} option, the search path is first reset and then addition
18291occurs as normal.
b383017d 18292Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18293multiple directories in a single command
18294results in the directories added to the beginning of the
18295search path in the same order they were presented in the command.
18296If blanks are needed as
18297part of a directory name, double-quotes should be used around
18298the name. In the command output, the path will show up separated
b383017d 18299by the system directory-separator character. The directory-seperator
922fbb7b
AC
18300character must not be used
18301in any directory name.
18302If no directories are specified, the current path is displayed.
18303
18304
18305@subsubheading @value{GDBN} Command
18306
18307The corresponding @value{GDBN} command is @samp{path}.
18308
18309@subsubheading Example
18310
18311@smallexample
18312(@value{GDBP})
b383017d 18313-environment-path
922fbb7b
AC
18314^done,path="/usr/bin"
18315(@value{GDBP})
18316-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
18317^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
18318(@value{GDBP})
18319-environment-path -r /usr/local/bin
18320^done,path="/usr/local/bin:/usr/bin"
18321(@value{GDBP})
18322@end smallexample
18323
18324
18325@subheading The @code{-environment-pwd} Command
18326@findex -environment-pwd
18327
18328@subsubheading Synopsis
18329
18330@smallexample
18331 -environment-pwd
18332@end smallexample
18333
18334Show the current working directory.
18335
18336@subsubheading @value{GDBN} command
18337
18338The corresponding @value{GDBN} command is @samp{pwd}.
18339
18340@subsubheading Example
18341
18342@smallexample
18343(@value{GDBP})
18344-environment-pwd
18345^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
18346(@value{GDBP})
18347@end smallexample
18348
18349@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18350@node GDB/MI Program Control
18351@section @sc{gdb/mi} Program control
18352
18353@subsubheading Program termination
18354
18355As a result of execution, the inferior program can run to completion, if
18356it doesn't encounter any breakpoints. In this case the output will
18357include an exit code, if the program has exited exceptionally.
18358
18359@subsubheading Examples
18360
18361@noindent
18362Program exited normally:
18363
18364@smallexample
18365(@value{GDBP})
18366-exec-run
18367^running
18368(@value{GDBP})
18369x = 55
18370*stopped,reason="exited-normally"
18371(@value{GDBP})
18372@end smallexample
18373
18374@noindent
18375Program exited exceptionally:
18376
18377@smallexample
18378(@value{GDBP})
18379-exec-run
18380^running
18381(@value{GDBP})
18382x = 55
18383*stopped,reason="exited",exit-code="01"
18384(@value{GDBP})
18385@end smallexample
18386
18387Another way the program can terminate is if it receives a signal such as
18388@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
18389
18390@smallexample
18391(@value{GDBP})
18392*stopped,reason="exited-signalled",signal-name="SIGINT",
18393signal-meaning="Interrupt"
18394@end smallexample
18395
18396
18397@subheading The @code{-exec-abort} Command
18398@findex -exec-abort
18399
18400@subsubheading Synopsis
18401
18402@smallexample
18403 -exec-abort
18404@end smallexample
18405
18406Kill the inferior running program.
18407
18408@subsubheading @value{GDBN} Command
18409
18410The corresponding @value{GDBN} command is @samp{kill}.
18411
18412@subsubheading Example
18413N.A.
18414
18415
18416@subheading The @code{-exec-arguments} Command
18417@findex -exec-arguments
18418
18419@subsubheading Synopsis
18420
18421@smallexample
18422 -exec-arguments @var{args}
18423@end smallexample
18424
18425Set the inferior program arguments, to be used in the next
18426@samp{-exec-run}.
18427
18428@subsubheading @value{GDBN} Command
18429
18430The corresponding @value{GDBN} command is @samp{set args}.
18431
18432@subsubheading Example
18433
18434@c FIXME!
18435Don't have one around.
18436
18437
18438@subheading The @code{-exec-continue} Command
18439@findex -exec-continue
18440
18441@subsubheading Synopsis
18442
18443@smallexample
18444 -exec-continue
18445@end smallexample
18446
18447Asynchronous command. Resumes the execution of the inferior program
18448until a breakpoint is encountered, or until the inferior exits.
18449
18450@subsubheading @value{GDBN} Command
18451
18452The corresponding @value{GDBN} corresponding is @samp{continue}.
18453
18454@subsubheading Example
18455
18456@smallexample
18457-exec-continue
18458^running
18459(@value{GDBP})
18460@@Hello world
18461*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
76ff342d 18462file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="13"@}
922fbb7b
AC
18463(@value{GDBP})
18464@end smallexample
18465
18466
18467@subheading The @code{-exec-finish} Command
18468@findex -exec-finish
18469
18470@subsubheading Synopsis
18471
18472@smallexample
18473 -exec-finish
18474@end smallexample
18475
18476Asynchronous command. Resumes the execution of the inferior program
18477until the current function is exited. Displays the results returned by
18478the function.
18479
18480@subsubheading @value{GDBN} Command
18481
18482The corresponding @value{GDBN} command is @samp{finish}.
18483
18484@subsubheading Example
18485
18486Function returning @code{void}.
18487
18488@smallexample
18489-exec-finish
18490^running
18491(@value{GDBP})
18492@@hello from foo
18493*stopped,reason="function-finished",frame=@{func="main",args=[],
76ff342d 18494file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="7"@}
922fbb7b
AC
18495(@value{GDBP})
18496@end smallexample
18497
18498Function returning other than @code{void}. The name of the internal
18499@value{GDBN} variable storing the result is printed, together with the
18500value itself.
18501
18502@smallexample
18503-exec-finish
18504^running
18505(@value{GDBP})
18506*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
18507args=[@{name="a",value="1"],@{name="b",value="9"@}@},
76ff342d 18508file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b
AC
18509gdb-result-var="$1",return-value="0"
18510(@value{GDBP})
18511@end smallexample
18512
18513
18514@subheading The @code{-exec-interrupt} Command
18515@findex -exec-interrupt
18516
18517@subsubheading Synopsis
18518
18519@smallexample
18520 -exec-interrupt
18521@end smallexample
18522
18523Asynchronous command. Interrupts the background execution of the target.
18524Note how the token associated with the stop message is the one for the
18525execution command that has been interrupted. The token for the interrupt
18526itself only appears in the @samp{^done} output. If the user is trying to
18527interrupt a non-running program, an error message will be printed.
18528
18529@subsubheading @value{GDBN} Command
18530
18531The corresponding @value{GDBN} command is @samp{interrupt}.
18532
18533@subsubheading Example
18534
18535@smallexample
18536(@value{GDBP})
18537111-exec-continue
18538111^running
18539
18540(@value{GDBP})
18541222-exec-interrupt
18542222^done
18543(@value{GDBP})
18544111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d
DJ
18545frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
18546fullname="/home/foo/bar/devo/myproject/try.c",line="13"@}
922fbb7b
AC
18547(@value{GDBP})
18548
18549(@value{GDBP})
18550-exec-interrupt
18551^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
18552(@value{GDBP})
18553@end smallexample
18554
18555
18556@subheading The @code{-exec-next} Command
18557@findex -exec-next
18558
18559@subsubheading Synopsis
18560
18561@smallexample
18562 -exec-next
18563@end smallexample
18564
18565Asynchronous command. Resumes execution of the inferior program, stopping
18566when the beginning of the next source line is reached.
18567
18568@subsubheading @value{GDBN} Command
18569
18570The corresponding @value{GDBN} command is @samp{next}.
18571
18572@subsubheading Example
18573
18574@smallexample
18575-exec-next
18576^running
18577(@value{GDBP})
18578*stopped,reason="end-stepping-range",line="8",file="hello.c"
18579(@value{GDBP})
18580@end smallexample
18581
18582
18583@subheading The @code{-exec-next-instruction} Command
18584@findex -exec-next-instruction
18585
18586@subsubheading Synopsis
18587
18588@smallexample
18589 -exec-next-instruction
18590@end smallexample
18591
18592Asynchronous command. Executes one machine instruction. If the
18593instruction is a function call continues until the function returns. If
18594the program stops at an instruction in the middle of a source line, the
18595address will be printed as well.
18596
18597@subsubheading @value{GDBN} Command
18598
18599The corresponding @value{GDBN} command is @samp{nexti}.
18600
18601@subsubheading Example
18602
18603@smallexample
18604(@value{GDBP})
18605-exec-next-instruction
18606^running
18607
18608(@value{GDBP})
18609*stopped,reason="end-stepping-range",
18610addr="0x000100d4",line="5",file="hello.c"
18611(@value{GDBP})
18612@end smallexample
18613
18614
18615@subheading The @code{-exec-return} Command
18616@findex -exec-return
18617
18618@subsubheading Synopsis
18619
18620@smallexample
18621 -exec-return
18622@end smallexample
18623
18624Makes current function return immediately. Doesn't execute the inferior.
18625Displays the new current frame.
18626
18627@subsubheading @value{GDBN} Command
18628
18629The corresponding @value{GDBN} command is @samp{return}.
18630
18631@subsubheading Example
18632
18633@smallexample
18634(@value{GDBP})
18635200-break-insert callee4
18636200^done,bkpt=@{number="1",addr="0x00010734",
18637file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
18638(@value{GDBP})
18639000-exec-run
18640000^running
18641(@value{GDBP})
18642000*stopped,reason="breakpoint-hit",bkptno="1",
18643frame=@{func="callee4",args=[],
76ff342d
DJ
18644file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18645fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
922fbb7b
AC
18646(@value{GDBP})
18647205-break-delete
18648205^done
18649(@value{GDBP})
18650111-exec-return
18651111^done,frame=@{level="0",func="callee3",
18652args=[@{name="strarg",
18653value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
18654file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18655fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
18656(@value{GDBP})
18657@end smallexample
18658
18659
18660@subheading The @code{-exec-run} Command
18661@findex -exec-run
18662
18663@subsubheading Synopsis
18664
18665@smallexample
18666 -exec-run
18667@end smallexample
18668
18669Asynchronous command. Starts execution of the inferior from the
18670beginning. The inferior executes until either a breakpoint is
18671encountered or the program exits.
18672
18673@subsubheading @value{GDBN} Command
18674
18675The corresponding @value{GDBN} command is @samp{run}.
18676
18677@subsubheading Example
18678
18679@smallexample
18680(@value{GDBP})
18681-break-insert main
18682^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
18683(@value{GDBP})
18684-exec-run
18685^running
18686(@value{GDBP})
18687*stopped,reason="breakpoint-hit",bkptno="1",
76ff342d
DJ
18688frame=@{func="main",args=[],file="recursive2.c",
18689fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}
922fbb7b
AC
18690(@value{GDBP})
18691@end smallexample
18692
18693
18694@subheading The @code{-exec-show-arguments} Command
18695@findex -exec-show-arguments
18696
18697@subsubheading Synopsis
18698
18699@smallexample
18700 -exec-show-arguments
18701@end smallexample
18702
18703Print the arguments of the program.
18704
18705@subsubheading @value{GDBN} Command
18706
18707The corresponding @value{GDBN} command is @samp{show args}.
18708
18709@subsubheading Example
18710N.A.
18711
18712@c @subheading -exec-signal
18713
18714@subheading The @code{-exec-step} Command
18715@findex -exec-step
18716
18717@subsubheading Synopsis
18718
18719@smallexample
18720 -exec-step
18721@end smallexample
18722
18723Asynchronous command. Resumes execution of the inferior program, stopping
18724when the beginning of the next source line is reached, if the next
18725source line is not a function call. If it is, stop at the first
18726instruction of the called function.
18727
18728@subsubheading @value{GDBN} Command
18729
18730The corresponding @value{GDBN} command is @samp{step}.
18731
18732@subsubheading Example
18733
18734Stepping into a function:
18735
18736@smallexample
18737-exec-step
18738^running
18739(@value{GDBP})
18740*stopped,reason="end-stepping-range",
18741frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d
DJ
18742@{name="b",value="0"@}],file="recursive2.c",
18743fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@}
922fbb7b
AC
18744(@value{GDBP})
18745@end smallexample
18746
18747Regular stepping:
18748
18749@smallexample
18750-exec-step
18751^running
18752(@value{GDBP})
18753*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
18754(@value{GDBP})
18755@end smallexample
18756
18757
18758@subheading The @code{-exec-step-instruction} Command
18759@findex -exec-step-instruction
18760
18761@subsubheading Synopsis
18762
18763@smallexample
18764 -exec-step-instruction
18765@end smallexample
18766
18767Asynchronous command. Resumes the inferior which executes one machine
18768instruction. The output, once @value{GDBN} has stopped, will vary depending on
18769whether we have stopped in the middle of a source line or not. In the
18770former case, the address at which the program stopped will be printed as
18771well.
18772
18773@subsubheading @value{GDBN} Command
18774
18775The corresponding @value{GDBN} command is @samp{stepi}.
18776
18777@subsubheading Example
18778
18779@smallexample
18780(@value{GDBP})
18781-exec-step-instruction
18782^running
18783
18784(@value{GDBP})
18785*stopped,reason="end-stepping-range",
76ff342d
DJ
18786frame=@{func="foo",args=[],file="try.c",
18787fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18788(@value{GDBP})
18789-exec-step-instruction
18790^running
18791
18792(@value{GDBP})
18793*stopped,reason="end-stepping-range",
76ff342d
DJ
18794frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
18795fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18796(@value{GDBP})
18797@end smallexample
18798
18799
18800@subheading The @code{-exec-until} Command
18801@findex -exec-until
18802
18803@subsubheading Synopsis
18804
18805@smallexample
18806 -exec-until [ @var{location} ]
18807@end smallexample
18808
18809Asynchronous command. Executes the inferior until the @var{location}
18810specified in the argument is reached. If there is no argument, the inferior
18811executes until a source line greater than the current one is reached.
18812The reason for stopping in this case will be @samp{location-reached}.
18813
18814@subsubheading @value{GDBN} Command
18815
18816The corresponding @value{GDBN} command is @samp{until}.
18817
18818@subsubheading Example
18819
18820@smallexample
18821(@value{GDBP})
18822-exec-until recursive2.c:6
18823^running
18824(@value{GDBP})
18825x = 55
18826*stopped,reason="location-reached",frame=@{func="main",args=[],
76ff342d 18827file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="6"@}
922fbb7b
AC
18828(@value{GDBP})
18829@end smallexample
18830
18831@ignore
18832@subheading -file-clear
18833Is this going away????
18834@end ignore
18835
18836
18837@subheading The @code{-file-exec-and-symbols} Command
18838@findex -file-exec-and-symbols
18839
18840@subsubheading Synopsis
18841
18842@smallexample
18843 -file-exec-and-symbols @var{file}
18844@end smallexample
18845
18846Specify the executable file to be debugged. This file is the one from
18847which the symbol table is also read. If no file is specified, the
18848command clears the executable and symbol information. If breakpoints
18849are set when using this command with no arguments, @value{GDBN} will produce
18850error messages. Otherwise, no output is produced, except a completion
18851notification.
18852
18853@subsubheading @value{GDBN} Command
18854
18855The corresponding @value{GDBN} command is @samp{file}.
18856
18857@subsubheading Example
18858
18859@smallexample
18860(@value{GDBP})
18861-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18862^done
18863(@value{GDBP})
18864@end smallexample
18865
18866
18867@subheading The @code{-file-exec-file} Command
18868@findex -file-exec-file
18869
18870@subsubheading Synopsis
18871
18872@smallexample
18873 -file-exec-file @var{file}
18874@end smallexample
18875
18876Specify the executable file to be debugged. Unlike
18877@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
18878from this file. If used without argument, @value{GDBN} clears the information
18879about the executable file. No output is produced, except a completion
18880notification.
18881
18882@subsubheading @value{GDBN} Command
18883
18884The corresponding @value{GDBN} command is @samp{exec-file}.
18885
18886@subsubheading Example
18887
18888@smallexample
18889(@value{GDBP})
18890-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18891^done
18892(@value{GDBP})
18893@end smallexample
18894
18895
18896@subheading The @code{-file-list-exec-sections} Command
18897@findex -file-list-exec-sections
18898
18899@subsubheading Synopsis
18900
18901@smallexample
18902 -file-list-exec-sections
18903@end smallexample
18904
18905List the sections of the current executable file.
18906
18907@subsubheading @value{GDBN} Command
18908
18909The @value{GDBN} command @samp{info file} shows, among the rest, the same
18910information as this command. @code{gdbtk} has a corresponding command
18911@samp{gdb_load_info}.
18912
18913@subsubheading Example
18914N.A.
18915
18916
1abaf70c
BR
18917@subheading The @code{-file-list-exec-source-file} Command
18918@findex -file-list-exec-source-file
18919
18920@subsubheading Synopsis
18921
18922@smallexample
18923 -file-list-exec-source-file
18924@end smallexample
18925
b383017d 18926List the line number, the current source file, and the absolute path
1abaf70c
BR
18927to the current source file for the current executable.
18928
18929@subsubheading @value{GDBN} Command
18930
18931There's no @value{GDBN} command which directly corresponds to this one.
18932
18933@subsubheading Example
18934
18935@smallexample
18936(@value{GDBP})
18937123-file-list-exec-source-file
18938123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
18939(@value{GDBP})
18940@end smallexample
18941
18942
922fbb7b
AC
18943@subheading The @code{-file-list-exec-source-files} Command
18944@findex -file-list-exec-source-files
18945
18946@subsubheading Synopsis
18947
18948@smallexample
18949 -file-list-exec-source-files
18950@end smallexample
18951
18952List the source files for the current executable.
18953
57c22c6c
BR
18954It will always output the filename, but only when GDB can find the absolute
18955file name of a source file, will it output the fullname.
18956
922fbb7b
AC
18957@subsubheading @value{GDBN} Command
18958
18959There's no @value{GDBN} command which directly corresponds to this one.
18960@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
18961
18962@subsubheading Example
57c22c6c
BR
18963@smallexample
18964(@value{GDBP})
18965-file-list-exec-source-files
18966^done,files=[
18967@{file=foo.c,fullname=/home/foo.c@},
18968@{file=/home/bar.c,fullname=/home/bar.c@},
18969@{file=gdb_could_not_find_fullpath.c@}]
18970(@value{GDBP})
18971@end smallexample
922fbb7b
AC
18972
18973@subheading The @code{-file-list-shared-libraries} Command
18974@findex -file-list-shared-libraries
18975
18976@subsubheading Synopsis
18977
18978@smallexample
18979 -file-list-shared-libraries
18980@end smallexample
18981
18982List the shared libraries in the program.
18983
18984@subsubheading @value{GDBN} Command
18985
18986The corresponding @value{GDBN} command is @samp{info shared}.
18987
18988@subsubheading Example
18989N.A.
18990
18991
18992@subheading The @code{-file-list-symbol-files} Command
18993@findex -file-list-symbol-files
18994
18995@subsubheading Synopsis
18996
18997@smallexample
18998 -file-list-symbol-files
18999@end smallexample
19000
19001List symbol files.
19002
19003@subsubheading @value{GDBN} Command
19004
19005The corresponding @value{GDBN} command is @samp{info file} (part of it).
19006
19007@subsubheading Example
19008N.A.
19009
19010
19011@subheading The @code{-file-symbol-file} Command
19012@findex -file-symbol-file
19013
19014@subsubheading Synopsis
19015
19016@smallexample
19017 -file-symbol-file @var{file}
19018@end smallexample
19019
19020Read symbol table info from the specified @var{file} argument. When
19021used without arguments, clears @value{GDBN}'s symbol table info. No output is
19022produced, except for a completion notification.
19023
19024@subsubheading @value{GDBN} Command
19025
19026The corresponding @value{GDBN} command is @samp{symbol-file}.
19027
19028@subsubheading Example
19029
19030@smallexample
19031(@value{GDBP})
19032-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
19033^done
19034(@value{GDBP})
19035@end smallexample
19036
19037@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19038@node GDB/MI Miscellaneous Commands
19039@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
19040
19041@c @subheading -gdb-complete
19042
19043@subheading The @code{-gdb-exit} Command
19044@findex -gdb-exit
19045
19046@subsubheading Synopsis
19047
19048@smallexample
19049 -gdb-exit
19050@end smallexample
19051
19052Exit @value{GDBN} immediately.
19053
19054@subsubheading @value{GDBN} Command
19055
19056Approximately corresponds to @samp{quit}.
19057
19058@subsubheading Example
19059
19060@smallexample
19061(@value{GDBP})
19062-gdb-exit
19063@end smallexample
19064
19065@subheading The @code{-gdb-set} Command
19066@findex -gdb-set
19067
19068@subsubheading Synopsis
19069
19070@smallexample
19071 -gdb-set
19072@end smallexample
19073
19074Set an internal @value{GDBN} variable.
19075@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
19076
19077@subsubheading @value{GDBN} Command
19078
19079The corresponding @value{GDBN} command is @samp{set}.
19080
19081@subsubheading Example
19082
19083@smallexample
19084(@value{GDBP})
19085-gdb-set $foo=3
19086^done
19087(@value{GDBP})
19088@end smallexample
19089
19090
19091@subheading The @code{-gdb-show} Command
19092@findex -gdb-show
19093
19094@subsubheading Synopsis
19095
19096@smallexample
19097 -gdb-show
19098@end smallexample
19099
19100Show the current value of a @value{GDBN} variable.
19101
19102@subsubheading @value{GDBN} command
19103
19104The corresponding @value{GDBN} command is @samp{show}.
19105
19106@subsubheading Example
19107
19108@smallexample
19109(@value{GDBP})
19110-gdb-show annotate
19111^done,value="0"
19112(@value{GDBP})
19113@end smallexample
19114
19115@c @subheading -gdb-source
19116
19117
19118@subheading The @code{-gdb-version} Command
19119@findex -gdb-version
19120
19121@subsubheading Synopsis
19122
19123@smallexample
19124 -gdb-version
19125@end smallexample
19126
19127Show version information for @value{GDBN}. Used mostly in testing.
19128
19129@subsubheading @value{GDBN} Command
19130
19131There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
19132information when you start an interactive session.
19133
19134@subsubheading Example
19135
19136@c This example modifies the actual output from GDB to avoid overfull
19137@c box in TeX.
19138@smallexample
19139(@value{GDBP})
19140-gdb-version
19141~GNU gdb 5.2.1
19142~Copyright 2000 Free Software Foundation, Inc.
19143~GDB is free software, covered by the GNU General Public License, and
19144~you are welcome to change it and/or distribute copies of it under
19145~ certain conditions.
19146~Type "show copying" to see the conditions.
19147~There is absolutely no warranty for GDB. Type "show warranty" for
19148~ details.
b383017d 19149~This GDB was configured as
922fbb7b
AC
19150 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
19151^done
19152(@value{GDBP})
19153@end smallexample
19154
19155@subheading The @code{-interpreter-exec} Command
19156@findex -interpreter-exec
19157
19158@subheading Synopsis
19159
19160@smallexample
19161-interpreter-exec @var{interpreter} @var{command}
19162@end smallexample
19163
19164Execute the specified @var{command} in the given @var{interpreter}.
19165
19166@subheading @value{GDBN} Command
19167
19168The corresponding @value{GDBN} command is @samp{interpreter-exec}.
19169
19170@subheading Example
19171
19172@smallexample
19173(@value{GDBP})
19174-interpreter-exec console "break main"
19175&"During symbol reading, couldn't parse type; debugger out of date?.\n"
19176&"During symbol reading, bad structure-type format.\n"
19177~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
19178^done
19179(@value{GDBP})
19180@end smallexample
19181
3cb3b8df
BR
19182@subheading The @code{-inferior-tty-set} Command
19183@findex -inferior-tty-set
19184
19185@subheading Synopsis
19186
19187@smallexample
19188-inferior-tty-set /dev/pts/1
19189@end smallexample
19190
19191Set terminal for future runs of the program being debugged.
19192
19193@subheading @value{GDBN} Command
19194
19195The corresponding @value{GDBN} command is @samp{set inferior-tty /dev/pts/1}.
19196
19197@subheading Example
19198
19199@smallexample
19200(@value{GDBP})
19201-inferior-tty-set /dev/pts/1
19202^done
19203(@value{GDBP})
19204@end smallexample
19205
19206@subheading The @code{-inferior-tty-show} Command
19207@findex -inferior-tty-show
19208
19209@subheading Synopsis
19210
19211@smallexample
19212-inferior-tty-show
19213@end smallexample
19214
19215Show terminal for future runs of program being debugged.
19216
19217@subheading @value{GDBN} Command
19218
38f1196a 19219The corresponding @value{GDBN} command is @samp{show inferior-tty}.
3cb3b8df
BR
19220
19221@subheading Example
19222
19223@smallexample
19224(@value{GDBP})
19225-inferior-tty-set /dev/pts/1
19226^done
19227(@value{GDBP})
19228-inferior-tty-show
19229^done,inferior_tty_terminal="/dev/pts/1"
19230(@value{GDBP})
19231@end smallexample
19232
922fbb7b
AC
19233@ignore
19234@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19235@node GDB/MI Kod Commands
19236@section @sc{gdb/mi} Kod Commands
19237
19238The Kod commands are not implemented.
19239
19240@c @subheading -kod-info
19241
19242@c @subheading -kod-list
19243
19244@c @subheading -kod-list-object-types
19245
19246@c @subheading -kod-show
19247
19248@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19249@node GDB/MI Memory Overlay Commands
19250@section @sc{gdb/mi} Memory Overlay Commands
19251
19252The memory overlay commands are not implemented.
19253
19254@c @subheading -overlay-auto
19255
19256@c @subheading -overlay-list-mapping-state
19257
19258@c @subheading -overlay-list-overlays
19259
19260@c @subheading -overlay-map
19261
19262@c @subheading -overlay-off
19263
19264@c @subheading -overlay-on
19265
19266@c @subheading -overlay-unmap
19267
19268@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19269@node GDB/MI Signal Handling Commands
19270@section @sc{gdb/mi} Signal Handling Commands
19271
19272Signal handling commands are not implemented.
19273
19274@c @subheading -signal-handle
19275
19276@c @subheading -signal-list-handle-actions
19277
19278@c @subheading -signal-list-signal-types
19279@end ignore
19280
19281
19282@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19283@node GDB/MI Stack Manipulation
19284@section @sc{gdb/mi} Stack Manipulation Commands
19285
dcaaae04
NR
19286
19287@subheading The @code{-stack-info-frame} Command
19288@findex -stack-info-frame
19289
19290@subsubheading Synopsis
19291
19292@smallexample
19293 -stack-info-frame
19294@end smallexample
19295
19296Get info on the selected frame.
19297
19298@subsubheading @value{GDBN} Command
19299
19300The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
19301(without arguments).
19302
19303@subsubheading Example
19304
19305@smallexample
19306(@value{GDBP})
19307-stack-info-frame
19308^done,frame=@{level="1",addr="0x0001076c",func="callee3",
19309file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19310fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
19311(@value{GDBP})
19312@end smallexample
19313
922fbb7b
AC
19314@subheading The @code{-stack-info-depth} Command
19315@findex -stack-info-depth
19316
19317@subsubheading Synopsis
19318
19319@smallexample
19320 -stack-info-depth [ @var{max-depth} ]
19321@end smallexample
19322
19323Return the depth of the stack. If the integer argument @var{max-depth}
19324is specified, do not count beyond @var{max-depth} frames.
19325
19326@subsubheading @value{GDBN} Command
19327
19328There's no equivalent @value{GDBN} command.
19329
19330@subsubheading Example
19331
19332For a stack with frame levels 0 through 11:
19333
19334@smallexample
19335(@value{GDBP})
19336-stack-info-depth
19337^done,depth="12"
19338(@value{GDBP})
19339-stack-info-depth 4
19340^done,depth="4"
19341(@value{GDBP})
19342-stack-info-depth 12
19343^done,depth="12"
19344(@value{GDBP})
19345-stack-info-depth 11
19346^done,depth="11"
19347(@value{GDBP})
19348-stack-info-depth 13
19349^done,depth="12"
19350(@value{GDBP})
19351@end smallexample
19352
19353@subheading The @code{-stack-list-arguments} Command
19354@findex -stack-list-arguments
19355
19356@subsubheading Synopsis
19357
19358@smallexample
19359 -stack-list-arguments @var{show-values}
19360 [ @var{low-frame} @var{high-frame} ]
19361@end smallexample
19362
19363Display a list of the arguments for the frames between @var{low-frame}
19364and @var{high-frame} (inclusive). If @var{low-frame} and
19365@var{high-frame} are not provided, list the arguments for the whole call
19366stack.
19367
19368The @var{show-values} argument must have a value of 0 or 1. A value of
193690 means that only the names of the arguments are listed, a value of 1
19370means that both names and values of the arguments are printed.
19371
19372@subsubheading @value{GDBN} Command
19373
19374@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
19375@samp{gdb_get_args} command which partially overlaps with the
19376functionality of @samp{-stack-list-arguments}.
19377
19378@subsubheading Example
19379
19380@smallexample
19381(@value{GDBP})
19382-stack-list-frames
19383^done,
19384stack=[
19385frame=@{level="0",addr="0x00010734",func="callee4",
76ff342d
DJ
19386file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19387fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
922fbb7b 19388frame=@{level="1",addr="0x0001076c",func="callee3",
76ff342d
DJ
19389file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19390fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
922fbb7b 19391frame=@{level="2",addr="0x0001078c",func="callee2",
76ff342d
DJ
19392file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19393fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
922fbb7b 19394frame=@{level="3",addr="0x000107b4",func="callee1",
76ff342d
DJ
19395file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19396fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
922fbb7b 19397frame=@{level="4",addr="0x000107e0",func="main",
76ff342d
DJ
19398file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19399fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
922fbb7b
AC
19400(@value{GDBP})
19401-stack-list-arguments 0
19402^done,
19403stack-args=[
19404frame=@{level="0",args=[]@},
19405frame=@{level="1",args=[name="strarg"]@},
19406frame=@{level="2",args=[name="intarg",name="strarg"]@},
19407frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
19408frame=@{level="4",args=[]@}]
19409(@value{GDBP})
19410-stack-list-arguments 1
19411^done,
19412stack-args=[
19413frame=@{level="0",args=[]@},
19414frame=@{level="1",
19415 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19416frame=@{level="2",args=[
19417@{name="intarg",value="2"@},
19418@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19419@{frame=@{level="3",args=[
19420@{name="intarg",value="2"@},
19421@{name="strarg",value="0x11940 \"A string argument.\""@},
19422@{name="fltarg",value="3.5"@}]@},
19423frame=@{level="4",args=[]@}]
19424(@value{GDBP})
19425-stack-list-arguments 0 2 2
19426^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
19427(@value{GDBP})
19428-stack-list-arguments 1 2 2
19429^done,stack-args=[frame=@{level="2",
19430args=[@{name="intarg",value="2"@},
19431@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
19432(@value{GDBP})
19433@end smallexample
19434
19435@c @subheading -stack-list-exception-handlers
19436
19437
19438@subheading The @code{-stack-list-frames} Command
19439@findex -stack-list-frames
19440
19441@subsubheading Synopsis
19442
19443@smallexample
19444 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
19445@end smallexample
19446
19447List the frames currently on the stack. For each frame it displays the
19448following info:
19449
19450@table @samp
19451@item @var{level}
19452The frame number, 0 being the topmost frame, i.e. the innermost function.
19453@item @var{addr}
19454The @code{$pc} value for that frame.
19455@item @var{func}
19456Function name.
19457@item @var{file}
19458File name of the source file where the function lives.
19459@item @var{line}
19460Line number corresponding to the @code{$pc}.
19461@end table
19462
19463If invoked without arguments, this command prints a backtrace for the
19464whole stack. If given two integer arguments, it shows the frames whose
19465levels are between the two arguments (inclusive). If the two arguments
19466are equal, it shows the single frame at the corresponding level.
19467
19468@subsubheading @value{GDBN} Command
19469
19470The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
19471
19472@subsubheading Example
19473
19474Full stack backtrace:
19475
19476@smallexample
19477(@value{GDBP})
19478-stack-list-frames
19479^done,stack=
19480[frame=@{level="0",addr="0x0001076c",func="foo",
76ff342d 19481 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@},
922fbb7b 19482frame=@{level="1",addr="0x000107a4",func="foo",
76ff342d 19483 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19484frame=@{level="2",addr="0x000107a4",func="foo",
76ff342d 19485 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19486frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19487 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19488frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19489 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19490frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19491 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19492frame=@{level="6",addr="0x000107a4",func="foo",
76ff342d 19493 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19494frame=@{level="7",addr="0x000107a4",func="foo",
76ff342d 19495 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19496frame=@{level="8",addr="0x000107a4",func="foo",
76ff342d 19497 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19498frame=@{level="9",addr="0x000107a4",func="foo",
76ff342d 19499 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19500frame=@{level="10",addr="0x000107a4",func="foo",
76ff342d 19501 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19502frame=@{level="11",addr="0x00010738",func="main",
76ff342d 19503 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}]
922fbb7b
AC
19504(@value{GDBP})
19505@end smallexample
19506
19507Show frames between @var{low_frame} and @var{high_frame}:
19508
19509@smallexample
19510(@value{GDBP})
19511-stack-list-frames 3 5
19512^done,stack=
19513[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19514 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19515frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19516 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19517frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19518 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19519(@value{GDBP})
19520@end smallexample
19521
19522Show a single frame:
19523
19524@smallexample
19525(@value{GDBP})
19526-stack-list-frames 3 3
19527^done,stack=
19528[frame=@{level="3",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
19533
19534@subheading The @code{-stack-list-locals} Command
19535@findex -stack-list-locals
19536
19537@subsubheading Synopsis
19538
19539@smallexample
19540 -stack-list-locals @var{print-values}
19541@end smallexample
19542
265eeb58
NR
19543Display the local variable names for the selected frame. If
19544@var{print-values} is 0 or @code{--no-values}, print only the names of
19545the variables; if it is 1 or @code{--all-values}, print also their
19546values; and if it is 2 or @code{--simple-values}, print the name,
19547type and value for simple data types and the name and type for arrays,
19548structures and unions. In this last case, a frontend can immediately
19549display the value of simple data types and create variable objects for
19550other data types when the the user wishes to explore their values in
bc8ced35 19551more detail.
922fbb7b
AC
19552
19553@subsubheading @value{GDBN} Command
19554
19555@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
19556
19557@subsubheading Example
19558
19559@smallexample
19560(@value{GDBP})
19561-stack-list-locals 0
19562^done,locals=[name="A",name="B",name="C"]
19563(@value{GDBP})
bc8ced35 19564-stack-list-locals --all-values
922fbb7b 19565^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
bc8ced35
NR
19566 @{name="C",value="@{1, 2, 3@}"@}]
19567-stack-list-locals --simple-values
19568^done,locals=[@{name="A",type="int",value="1"@},
19569 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
922fbb7b
AC
19570(@value{GDBP})
19571@end smallexample
19572
19573
19574@subheading The @code{-stack-select-frame} Command
19575@findex -stack-select-frame
19576
19577@subsubheading Synopsis
19578
19579@smallexample
19580 -stack-select-frame @var{framenum}
19581@end smallexample
19582
265eeb58 19583Change the selected frame. Select a different frame @var{framenum} on
922fbb7b
AC
19584the stack.
19585
19586@subsubheading @value{GDBN} Command
19587
19588The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
19589@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
19590
19591@subsubheading Example
19592
19593@smallexample
19594(@value{GDBP})
19595-stack-select-frame 2
19596^done
19597(@value{GDBP})
19598@end smallexample
19599
19600@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19601@node GDB/MI Symbol Query
19602@section @sc{gdb/mi} Symbol Query Commands
19603
19604
19605@subheading The @code{-symbol-info-address} Command
19606@findex -symbol-info-address
19607
19608@subsubheading Synopsis
19609
19610@smallexample
19611 -symbol-info-address @var{symbol}
19612@end smallexample
19613
19614Describe where @var{symbol} is stored.
19615
19616@subsubheading @value{GDBN} Command
19617
19618The corresponding @value{GDBN} command is @samp{info address}.
19619
19620@subsubheading Example
19621N.A.
19622
19623
19624@subheading The @code{-symbol-info-file} Command
19625@findex -symbol-info-file
19626
19627@subsubheading Synopsis
19628
19629@smallexample
19630 -symbol-info-file
19631@end smallexample
19632
19633Show the file for the symbol.
19634
19635@subsubheading @value{GDBN} Command
19636
19637There's no equivalent @value{GDBN} command. @code{gdbtk} has
19638@samp{gdb_find_file}.
19639
19640@subsubheading Example
19641N.A.
19642
19643
19644@subheading The @code{-symbol-info-function} Command
19645@findex -symbol-info-function
19646
19647@subsubheading Synopsis
19648
19649@smallexample
19650 -symbol-info-function
19651@end smallexample
19652
19653Show which function the symbol lives in.
19654
19655@subsubheading @value{GDBN} Command
19656
19657@samp{gdb_get_function} in @code{gdbtk}.
19658
19659@subsubheading Example
19660N.A.
19661
19662
19663@subheading The @code{-symbol-info-line} Command
19664@findex -symbol-info-line
19665
19666@subsubheading Synopsis
19667
19668@smallexample
19669 -symbol-info-line
19670@end smallexample
19671
19672Show the core addresses of the code for a source line.
19673
19674@subsubheading @value{GDBN} Command
19675
71952f4c 19676The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
19677@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
19678
19679@subsubheading Example
19680N.A.
19681
19682
19683@subheading The @code{-symbol-info-symbol} Command
19684@findex -symbol-info-symbol
19685
19686@subsubheading Synopsis
19687
19688@smallexample
19689 -symbol-info-symbol @var{addr}
19690@end smallexample
19691
19692Describe what symbol is at location @var{addr}.
19693
19694@subsubheading @value{GDBN} Command
19695
19696The corresponding @value{GDBN} command is @samp{info symbol}.
19697
19698@subsubheading Example
19699N.A.
19700
19701
19702@subheading The @code{-symbol-list-functions} Command
19703@findex -symbol-list-functions
19704
19705@subsubheading Synopsis
19706
19707@smallexample
19708 -symbol-list-functions
19709@end smallexample
19710
19711List the functions in the executable.
19712
19713@subsubheading @value{GDBN} Command
19714
19715@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
19716@samp{gdb_search} in @code{gdbtk}.
19717
19718@subsubheading Example
19719N.A.
19720
19721
32e7087d
JB
19722@subheading The @code{-symbol-list-lines} Command
19723@findex -symbol-list-lines
19724
19725@subsubheading Synopsis
19726
19727@smallexample
19728 -symbol-list-lines @var{filename}
19729@end smallexample
19730
19731Print the list of lines that contain code and their associated program
19732addresses for the given source filename. The entries are sorted in
19733ascending PC order.
19734
19735@subsubheading @value{GDBN} Command
19736
19737There is no corresponding @value{GDBN} command.
19738
19739@subsubheading Example
19740@smallexample
19741(@value{GDBP})
19742-symbol-list-lines basics.c
54ff5908 19743^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
19744(@value{GDBP})
19745@end smallexample
19746
19747
922fbb7b
AC
19748@subheading The @code{-symbol-list-types} Command
19749@findex -symbol-list-types
19750
19751@subsubheading Synopsis
19752
19753@smallexample
19754 -symbol-list-types
19755@end smallexample
19756
19757List all the type names.
19758
19759@subsubheading @value{GDBN} Command
19760
19761The corresponding commands are @samp{info types} in @value{GDBN},
19762@samp{gdb_search} in @code{gdbtk}.
19763
19764@subsubheading Example
19765N.A.
19766
19767
19768@subheading The @code{-symbol-list-variables} Command
19769@findex -symbol-list-variables
19770
19771@subsubheading Synopsis
19772
19773@smallexample
19774 -symbol-list-variables
19775@end smallexample
19776
19777List all the global and static variable names.
19778
19779@subsubheading @value{GDBN} Command
19780
19781@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
19782
19783@subsubheading Example
19784N.A.
19785
19786
19787@subheading The @code{-symbol-locate} Command
19788@findex -symbol-locate
19789
19790@subsubheading Synopsis
19791
19792@smallexample
19793 -symbol-locate
19794@end smallexample
19795
19796@subsubheading @value{GDBN} Command
19797
19798@samp{gdb_loc} in @code{gdbtk}.
19799
19800@subsubheading Example
19801N.A.
19802
19803
19804@subheading The @code{-symbol-type} Command
19805@findex -symbol-type
19806
19807@subsubheading Synopsis
19808
19809@smallexample
19810 -symbol-type @var{variable}
19811@end smallexample
19812
19813Show type of @var{variable}.
19814
19815@subsubheading @value{GDBN} Command
19816
19817The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
19818@samp{gdb_obj_variable}.
19819
19820@subsubheading Example
19821N.A.
19822
19823
19824@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19825@node GDB/MI Target Manipulation
19826@section @sc{gdb/mi} Target Manipulation Commands
19827
19828
19829@subheading The @code{-target-attach} Command
19830@findex -target-attach
19831
19832@subsubheading Synopsis
19833
19834@smallexample
19835 -target-attach @var{pid} | @var{file}
19836@end smallexample
19837
19838Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
19839
19840@subsubheading @value{GDBN} command
19841
19842The corresponding @value{GDBN} command is @samp{attach}.
19843
19844@subsubheading Example
19845N.A.
19846
19847
19848@subheading The @code{-target-compare-sections} Command
19849@findex -target-compare-sections
19850
19851@subsubheading Synopsis
19852
19853@smallexample
19854 -target-compare-sections [ @var{section} ]
19855@end smallexample
19856
19857Compare data of section @var{section} on target to the exec file.
19858Without the argument, all sections are compared.
19859
19860@subsubheading @value{GDBN} Command
19861
19862The @value{GDBN} equivalent is @samp{compare-sections}.
19863
19864@subsubheading Example
19865N.A.
19866
19867
19868@subheading The @code{-target-detach} Command
19869@findex -target-detach
19870
19871@subsubheading Synopsis
19872
19873@smallexample
19874 -target-detach
19875@end smallexample
19876
19877Disconnect from the remote target. There's no output.
19878
19879@subsubheading @value{GDBN} command
19880
19881The corresponding @value{GDBN} command is @samp{detach}.
19882
19883@subsubheading Example
19884
19885@smallexample
19886(@value{GDBP})
19887-target-detach
19888^done
19889(@value{GDBP})
19890@end smallexample
19891
19892
07f31aa6
DJ
19893@subheading The @code{-target-disconnect} Command
19894@findex -target-disconnect
19895
19896@subsubheading Synopsis
19897
19898@example
19899 -target-disconnect
19900@end example
19901
19902Disconnect from the remote target. There's no output.
19903
19904@subsubheading @value{GDBN} command
19905
19906The corresponding @value{GDBN} command is @samp{disconnect}.
19907
19908@subsubheading Example
19909
19910@smallexample
19911(@value{GDBP})
19912-target-disconnect
19913^done
19914(@value{GDBP})
19915@end smallexample
19916
19917
922fbb7b
AC
19918@subheading The @code{-target-download} Command
19919@findex -target-download
19920
19921@subsubheading Synopsis
19922
19923@smallexample
19924 -target-download
19925@end smallexample
19926
19927Loads the executable onto the remote target.
19928It prints out an update message every half second, which includes the fields:
19929
19930@table @samp
19931@item section
19932The name of the section.
19933@item section-sent
19934The size of what has been sent so far for that section.
19935@item section-size
19936The size of the section.
19937@item total-sent
19938The total size of what was sent so far (the current and the previous sections).
19939@item total-size
19940The size of the overall executable to download.
19941@end table
19942
19943@noindent
19944Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
19945@sc{gdb/mi} Output Syntax}).
19946
19947In addition, it prints the name and size of the sections, as they are
19948downloaded. These messages include the following fields:
19949
19950@table @samp
19951@item section
19952The name of the section.
19953@item section-size
19954The size of the section.
19955@item total-size
19956The size of the overall executable to download.
19957@end table
19958
19959@noindent
19960At the end, a summary is printed.
19961
19962@subsubheading @value{GDBN} Command
19963
19964The corresponding @value{GDBN} command is @samp{load}.
19965
19966@subsubheading Example
19967
19968Note: each status message appears on a single line. Here the messages
19969have been broken down so that they can fit onto a page.
19970
19971@smallexample
19972(@value{GDBP})
19973-target-download
19974+download,@{section=".text",section-size="6668",total-size="9880"@}
19975+download,@{section=".text",section-sent="512",section-size="6668",
19976total-sent="512",total-size="9880"@}
19977+download,@{section=".text",section-sent="1024",section-size="6668",
19978total-sent="1024",total-size="9880"@}
19979+download,@{section=".text",section-sent="1536",section-size="6668",
19980total-sent="1536",total-size="9880"@}
19981+download,@{section=".text",section-sent="2048",section-size="6668",
19982total-sent="2048",total-size="9880"@}
19983+download,@{section=".text",section-sent="2560",section-size="6668",
19984total-sent="2560",total-size="9880"@}
19985+download,@{section=".text",section-sent="3072",section-size="6668",
19986total-sent="3072",total-size="9880"@}
19987+download,@{section=".text",section-sent="3584",section-size="6668",
19988total-sent="3584",total-size="9880"@}
19989+download,@{section=".text",section-sent="4096",section-size="6668",
19990total-sent="4096",total-size="9880"@}
19991+download,@{section=".text",section-sent="4608",section-size="6668",
19992total-sent="4608",total-size="9880"@}
19993+download,@{section=".text",section-sent="5120",section-size="6668",
19994total-sent="5120",total-size="9880"@}
19995+download,@{section=".text",section-sent="5632",section-size="6668",
19996total-sent="5632",total-size="9880"@}
19997+download,@{section=".text",section-sent="6144",section-size="6668",
19998total-sent="6144",total-size="9880"@}
19999+download,@{section=".text",section-sent="6656",section-size="6668",
20000total-sent="6656",total-size="9880"@}
20001+download,@{section=".init",section-size="28",total-size="9880"@}
20002+download,@{section=".fini",section-size="28",total-size="9880"@}
20003+download,@{section=".data",section-size="3156",total-size="9880"@}
20004+download,@{section=".data",section-sent="512",section-size="3156",
20005total-sent="7236",total-size="9880"@}
20006+download,@{section=".data",section-sent="1024",section-size="3156",
20007total-sent="7748",total-size="9880"@}
20008+download,@{section=".data",section-sent="1536",section-size="3156",
20009total-sent="8260",total-size="9880"@}
20010+download,@{section=".data",section-sent="2048",section-size="3156",
20011total-sent="8772",total-size="9880"@}
20012+download,@{section=".data",section-sent="2560",section-size="3156",
20013total-sent="9284",total-size="9880"@}
20014+download,@{section=".data",section-sent="3072",section-size="3156",
20015total-sent="9796",total-size="9880"@}
20016^done,address="0x10004",load-size="9880",transfer-rate="6586",
20017write-rate="429"
20018(@value{GDBP})
20019@end smallexample
20020
20021
20022@subheading The @code{-target-exec-status} Command
20023@findex -target-exec-status
20024
20025@subsubheading Synopsis
20026
20027@smallexample
20028 -target-exec-status
20029@end smallexample
20030
20031Provide information on the state of the target (whether it is running or
20032not, for instance).
20033
20034@subsubheading @value{GDBN} Command
20035
20036There's no equivalent @value{GDBN} command.
20037
20038@subsubheading Example
20039N.A.
20040
20041
20042@subheading The @code{-target-list-available-targets} Command
20043@findex -target-list-available-targets
20044
20045@subsubheading Synopsis
20046
20047@smallexample
20048 -target-list-available-targets
20049@end smallexample
20050
20051List the possible targets to connect to.
20052
20053@subsubheading @value{GDBN} Command
20054
20055The corresponding @value{GDBN} command is @samp{help target}.
20056
20057@subsubheading Example
20058N.A.
20059
20060
20061@subheading The @code{-target-list-current-targets} Command
20062@findex -target-list-current-targets
20063
20064@subsubheading Synopsis
20065
20066@smallexample
20067 -target-list-current-targets
20068@end smallexample
20069
20070Describe the current target.
20071
20072@subsubheading @value{GDBN} Command
20073
20074The corresponding information is printed by @samp{info file} (among
20075other things).
20076
20077@subsubheading Example
20078N.A.
20079
20080
20081@subheading The @code{-target-list-parameters} Command
20082@findex -target-list-parameters
20083
20084@subsubheading Synopsis
20085
20086@smallexample
20087 -target-list-parameters
20088@end smallexample
20089
20090@c ????
20091
20092@subsubheading @value{GDBN} Command
20093
20094No equivalent.
20095
20096@subsubheading Example
20097N.A.
20098
20099
20100@subheading The @code{-target-select} Command
20101@findex -target-select
20102
20103@subsubheading Synopsis
20104
20105@smallexample
20106 -target-select @var{type} @var{parameters @dots{}}
20107@end smallexample
20108
20109Connect @value{GDBN} to the remote target. This command takes two args:
20110
20111@table @samp
20112@item @var{type}
20113The type of target, for instance @samp{async}, @samp{remote}, etc.
20114@item @var{parameters}
20115Device names, host names and the like. @xref{Target Commands, ,
20116Commands for managing targets}, for more details.
20117@end table
20118
20119The output is a connection notification, followed by the address at
20120which the target program is, in the following form:
20121
20122@smallexample
20123^connected,addr="@var{address}",func="@var{function name}",
20124 args=[@var{arg list}]
20125@end smallexample
20126
20127@subsubheading @value{GDBN} Command
20128
20129The corresponding @value{GDBN} command is @samp{target}.
20130
20131@subsubheading Example
20132
20133@smallexample
20134(@value{GDBP})
20135-target-select async /dev/ttya
20136^connected,addr="0xfe00a300",func="??",args=[]
20137(@value{GDBP})
20138@end smallexample
20139
20140@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20141@node GDB/MI Thread Commands
20142@section @sc{gdb/mi} Thread Commands
20143
20144
20145@subheading The @code{-thread-info} Command
20146@findex -thread-info
20147
20148@subsubheading Synopsis
20149
20150@smallexample
20151 -thread-info
20152@end smallexample
20153
20154@subsubheading @value{GDBN} command
20155
20156No equivalent.
20157
20158@subsubheading Example
20159N.A.
20160
20161
20162@subheading The @code{-thread-list-all-threads} Command
20163@findex -thread-list-all-threads
20164
20165@subsubheading Synopsis
20166
20167@smallexample
20168 -thread-list-all-threads
20169@end smallexample
20170
20171@subsubheading @value{GDBN} Command
20172
20173The equivalent @value{GDBN} command is @samp{info threads}.
20174
20175@subsubheading Example
20176N.A.
20177
20178
20179@subheading The @code{-thread-list-ids} Command
20180@findex -thread-list-ids
20181
20182@subsubheading Synopsis
20183
20184@smallexample
20185 -thread-list-ids
20186@end smallexample
20187
20188Produces a list of the currently known @value{GDBN} thread ids. At the
20189end of the list it also prints the total number of such threads.
20190
20191@subsubheading @value{GDBN} Command
20192
20193Part of @samp{info threads} supplies the same information.
20194
20195@subsubheading Example
20196
20197No threads present, besides the main process:
20198
20199@smallexample
20200(@value{GDBP})
20201-thread-list-ids
20202^done,thread-ids=@{@},number-of-threads="0"
20203(@value{GDBP})
20204@end smallexample
20205
20206
20207Several threads:
20208
20209@smallexample
20210(@value{GDBP})
20211-thread-list-ids
20212^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20213number-of-threads="3"
20214(@value{GDBP})
20215@end smallexample
20216
20217
20218@subheading The @code{-thread-select} Command
20219@findex -thread-select
20220
20221@subsubheading Synopsis
20222
20223@smallexample
20224 -thread-select @var{threadnum}
20225@end smallexample
20226
20227Make @var{threadnum} the current thread. It prints the number of the new
20228current thread, and the topmost frame for that thread.
20229
20230@subsubheading @value{GDBN} Command
20231
20232The corresponding @value{GDBN} command is @samp{thread}.
20233
20234@subsubheading Example
20235
20236@smallexample
20237(@value{GDBP})
20238-exec-next
20239^running
20240(@value{GDBP})
20241*stopped,reason="end-stepping-range",thread-id="2",line="187",
20242file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
20243(@value{GDBP})
20244-thread-list-ids
20245^done,
20246thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20247number-of-threads="3"
20248(@value{GDBP})
20249-thread-select 3
20250^done,new-thread-id="3",
20251frame=@{level="0",func="vprintf",
20252args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
20253@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
20254(@value{GDBP})
20255@end smallexample
20256
20257@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20258@node GDB/MI Tracepoint Commands
20259@section @sc{gdb/mi} Tracepoint Commands
20260
20261The tracepoint commands are not yet implemented.
20262
20263@c @subheading -trace-actions
20264
20265@c @subheading -trace-delete
20266
20267@c @subheading -trace-disable
20268
20269@c @subheading -trace-dump
20270
20271@c @subheading -trace-enable
20272
20273@c @subheading -trace-exists
20274
20275@c @subheading -trace-find
20276
20277@c @subheading -trace-frame-number
20278
20279@c @subheading -trace-info
20280
20281@c @subheading -trace-insert
20282
20283@c @subheading -trace-list
20284
20285@c @subheading -trace-pass-count
20286
20287@c @subheading -trace-save
20288
20289@c @subheading -trace-start
20290
20291@c @subheading -trace-stop
20292
20293
20294@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20295@node GDB/MI Variable Objects
20296@section @sc{gdb/mi} Variable Objects
20297
20298
20299@subheading Motivation for Variable Objects in @sc{gdb/mi}
20300
20301For the implementation of a variable debugger window (locals, watched
20302expressions, etc.), we are proposing the adaptation of the existing code
20303used by @code{Insight}.
20304
20305The two main reasons for that are:
20306
20307@enumerate 1
20308@item
20309It has been proven in practice (it is already on its second generation).
20310
20311@item
20312It will shorten development time (needless to say how important it is
20313now).
20314@end enumerate
20315
20316The original interface was designed to be used by Tcl code, so it was
20317slightly changed so it could be used through @sc{gdb/mi}. This section
20318describes the @sc{gdb/mi} operations that will be available and gives some
20319hints about their use.
20320
20321@emph{Note}: In addition to the set of operations described here, we
20322expect the @sc{gui} implementation of a variable window to require, at
20323least, the following operations:
20324
20325@itemize @bullet
20326@item @code{-gdb-show} @code{output-radix}
20327@item @code{-stack-list-arguments}
20328@item @code{-stack-list-locals}
20329@item @code{-stack-select-frame}
20330@end itemize
20331
20332@subheading Introduction to Variable Objects in @sc{gdb/mi}
20333
20334@cindex variable objects in @sc{gdb/mi}
20335The basic idea behind variable objects is the creation of a named object
20336to represent a variable, an expression, a memory location or even a CPU
20337register. For each object created, a set of operations is available for
20338examining or changing its properties.
20339
20340Furthermore, complex data types, such as C structures, are represented
20341in a tree format. For instance, the @code{struct} type variable is the
20342root and the children will represent the struct members. If a child
20343is itself of a complex type, it will also have children of its own.
20344Appropriate language differences are handled for C, C@t{++} and Java.
20345
20346When returning the actual values of the objects, this facility allows
20347for the individual selection of the display format used in the result
20348creation. It can be chosen among: binary, decimal, hexadecimal, octal
20349and natural. Natural refers to a default format automatically
20350chosen based on the variable type (like decimal for an @code{int}, hex
20351for pointers, etc.).
20352
20353The following is the complete set of @sc{gdb/mi} operations defined to
20354access this functionality:
20355
20356@multitable @columnfractions .4 .6
20357@item @strong{Operation}
20358@tab @strong{Description}
20359
20360@item @code{-var-create}
20361@tab create a variable object
20362@item @code{-var-delete}
20363@tab delete the variable object and its children
20364@item @code{-var-set-format}
20365@tab set the display format of this variable
20366@item @code{-var-show-format}
20367@tab show the display format of this variable
20368@item @code{-var-info-num-children}
20369@tab tells how many children this object has
20370@item @code{-var-list-children}
20371@tab return a list of the object's children
20372@item @code{-var-info-type}
20373@tab show the type of this variable object
20374@item @code{-var-info-expression}
20375@tab print what this variable object represents
20376@item @code{-var-show-attributes}
20377@tab is this variable editable? does it exist here?
20378@item @code{-var-evaluate-expression}
20379@tab get the value of this variable
20380@item @code{-var-assign}
20381@tab set the value of this variable
20382@item @code{-var-update}
20383@tab update the variable and its children
20384@end multitable
20385
20386In the next subsection we describe each operation in detail and suggest
20387how it can be used.
20388
20389@subheading Description And Use of Operations on Variable Objects
20390
20391@subheading The @code{-var-create} Command
20392@findex -var-create
20393
20394@subsubheading Synopsis
20395
20396@smallexample
20397 -var-create @{@var{name} | "-"@}
20398 @{@var{frame-addr} | "*"@} @var{expression}
20399@end smallexample
20400
20401This operation creates a variable object, which allows the monitoring of
20402a variable, the result of an expression, a memory cell or a CPU
20403register.
20404
20405The @var{name} parameter is the string by which the object can be
20406referenced. It must be unique. If @samp{-} is specified, the varobj
20407system will generate a string ``varNNNNNN'' automatically. It will be
20408unique provided that one does not specify @var{name} on that format.
20409The command fails if a duplicate name is found.
20410
20411The frame under which the expression should be evaluated can be
20412specified by @var{frame-addr}. A @samp{*} indicates that the current
20413frame should be used.
20414
20415@var{expression} is any expression valid on the current language set (must not
20416begin with a @samp{*}), or one of the following:
20417
20418@itemize @bullet
20419@item
20420@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
20421
20422@item
20423@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
20424
20425@item
20426@samp{$@var{regname}} --- a CPU register name
20427@end itemize
20428
20429@subsubheading Result
20430
20431This operation returns the name, number of children and the type of the
20432object created. Type is returned as a string as the ones generated by
20433the @value{GDBN} CLI:
20434
20435@smallexample
20436 name="@var{name}",numchild="N",type="@var{type}"
20437@end smallexample
20438
20439
20440@subheading The @code{-var-delete} Command
20441@findex -var-delete
20442
20443@subsubheading Synopsis
20444
20445@smallexample
20446 -var-delete @var{name}
20447@end smallexample
20448
20449Deletes a previously created variable object and all of its children.
20450
20451Returns an error if the object @var{name} is not found.
20452
20453
20454@subheading The @code{-var-set-format} Command
20455@findex -var-set-format
20456
20457@subsubheading Synopsis
20458
20459@smallexample
20460 -var-set-format @var{name} @var{format-spec}
20461@end smallexample
20462
20463Sets the output format for the value of the object @var{name} to be
20464@var{format-spec}.
20465
20466The syntax for the @var{format-spec} is as follows:
20467
20468@smallexample
20469 @var{format-spec} @expansion{}
20470 @{binary | decimal | hexadecimal | octal | natural@}
20471@end smallexample
20472
20473
20474@subheading The @code{-var-show-format} Command
20475@findex -var-show-format
20476
20477@subsubheading Synopsis
20478
20479@smallexample
20480 -var-show-format @var{name}
20481@end smallexample
20482
20483Returns the format used to display the value of the object @var{name}.
20484
20485@smallexample
20486 @var{format} @expansion{}
20487 @var{format-spec}
20488@end smallexample
20489
20490
20491@subheading The @code{-var-info-num-children} Command
20492@findex -var-info-num-children
20493
20494@subsubheading Synopsis
20495
20496@smallexample
20497 -var-info-num-children @var{name}
20498@end smallexample
20499
20500Returns the number of children of a variable object @var{name}:
20501
20502@smallexample
20503 numchild=@var{n}
20504@end smallexample
20505
20506
20507@subheading The @code{-var-list-children} Command
20508@findex -var-list-children
20509
20510@subsubheading Synopsis
20511
20512@smallexample
bc8ced35 20513 -var-list-children [@var{print-values}] @var{name}
922fbb7b 20514@end smallexample
265eeb58 20515@anchor{-var-list-children}
922fbb7b 20516
265eeb58
NR
20517Return a list of the children of the specified variable object and
20518create variable objects for them, if they do not already exist. With
20519a single argument or if @var{print-values} has a value for of 0 or
20520@code{--no-values}, print only the names of the variables; if
20521@var{print-values} is 1 or @code{--all-values}, also print their
20522values; and if it is 2 or @code{--simple-values} print the name and
20523value for simple data types and just the name for arrays, structures
20524and unions.
bc8ced35
NR
20525
20526@subsubheading Example
922fbb7b
AC
20527
20528@smallexample
bc8ced35
NR
20529(@value{GDBP})
20530 -var-list-children n
265eeb58 20531 ^done,numchild=@var{n},children=[@{name=@var{name},
922fbb7b 20532 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
bc8ced35
NR
20533(@value{GDBP})
20534 -var-list-children --all-values n
265eeb58 20535 ^done,numchild=@var{n},children=[@{name=@var{name},
bc8ced35 20536 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
20537@end smallexample
20538
20539
20540@subheading The @code{-var-info-type} Command
20541@findex -var-info-type
20542
20543@subsubheading Synopsis
20544
20545@smallexample
20546 -var-info-type @var{name}
20547@end smallexample
20548
20549Returns the type of the specified variable @var{name}. The type is
20550returned as a string in the same format as it is output by the
20551@value{GDBN} CLI:
20552
20553@smallexample
20554 type=@var{typename}
20555@end smallexample
20556
20557
20558@subheading The @code{-var-info-expression} Command
20559@findex -var-info-expression
20560
20561@subsubheading Synopsis
20562
20563@smallexample
20564 -var-info-expression @var{name}
20565@end smallexample
20566
20567Returns what is represented by the variable object @var{name}:
20568
20569@smallexample
20570 lang=@var{lang-spec},exp=@var{expression}
20571@end smallexample
20572
20573@noindent
20574where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
20575
20576@subheading The @code{-var-show-attributes} Command
20577@findex -var-show-attributes
20578
20579@subsubheading Synopsis
20580
20581@smallexample
20582 -var-show-attributes @var{name}
20583@end smallexample
20584
20585List attributes of the specified variable object @var{name}:
20586
20587@smallexample
20588 status=@var{attr} [ ( ,@var{attr} )* ]
20589@end smallexample
20590
20591@noindent
20592where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
20593
20594@subheading The @code{-var-evaluate-expression} Command
20595@findex -var-evaluate-expression
20596
20597@subsubheading Synopsis
20598
20599@smallexample
20600 -var-evaluate-expression @var{name}
20601@end smallexample
20602
20603Evaluates the expression that is represented by the specified variable
20604object and returns its value as a string in the current format specified
20605for the object:
20606
20607@smallexample
20608 value=@var{value}
20609@end smallexample
20610
20611Note that one must invoke @code{-var-list-children} for a variable
20612before the value of a child variable can be evaluated.
20613
20614@subheading The @code{-var-assign} Command
20615@findex -var-assign
20616
20617@subsubheading Synopsis
20618
20619@smallexample
20620 -var-assign @var{name} @var{expression}
20621@end smallexample
20622
20623Assigns the value of @var{expression} to the variable object specified
20624by @var{name}. The object must be @samp{editable}. If the variable's
b383017d 20625value is altered by the assign, the variable will show up in any
922fbb7b
AC
20626subsequent @code{-var-update} list.
20627
20628@subsubheading Example
20629
20630@smallexample
20631(@value{GDBP})
20632-var-assign var1 3
20633^done,value="3"
20634(@value{GDBP})
20635-var-update *
20636^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
20637(@value{GDBP})
20638@end smallexample
20639
20640@subheading The @code{-var-update} Command
20641@findex -var-update
20642
20643@subsubheading Synopsis
20644
20645@smallexample
265eeb58 20646 -var-update [@var{print-values}] @{@var{name} | "*"@}
922fbb7b
AC
20647@end smallexample
20648
20649Update the value of the variable object @var{name} by evaluating its
20650expression after fetching all the new values from memory or registers.
265eeb58 20651A @samp{*} causes all existing variable objects to be updated. The
656d5e12
EZ
20652option @var{print-values} determines whether names both and values, or
20653just names are printed in the manner described for
20654@code{-var-list-children} (@pxref{-var-list-children}).
265eeb58
NR
20655
20656@subsubheading Example
922fbb7b 20657
265eeb58
NR
20658@smallexample
20659(@value{GDBP})
20660-var-assign var1 3
20661^done,value="3"
20662(@value{GDBP})
20663-var-update --all-values var1
20664^done,changelist=[@{name="var1",value="3",in_scope="true",
20665type_changed="false"@}]
20666(@value{GDBP})
20667@end smallexample
922fbb7b
AC
20668
20669@node Annotations
20670@chapter @value{GDBN} Annotations
20671
086432e2
AC
20672This chapter describes annotations in @value{GDBN}. Annotations were
20673designed to interface @value{GDBN} to graphical user interfaces or other
20674similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
20675relatively high level.
20676
086432e2
AC
20677The annotation mechanism has largely been superseeded by @sc{gdb/mi}
20678(@pxref{GDB/MI}).
20679
922fbb7b
AC
20680@ignore
20681This is Edition @value{EDITION}, @value{DATE}.
20682@end ignore
20683
20684@menu
20685* Annotations Overview:: What annotations are; the general syntax.
922fbb7b
AC
20686* Prompting:: Annotations marking @value{GDBN}'s need for input.
20687* Errors:: Annotations for error messages.
922fbb7b
AC
20688* Invalidation:: Some annotations describe things now invalid.
20689* Annotations for Running::
20690 Whether the program is running, how it stopped, etc.
20691* Source Annotations:: Annotations describing source code.
922fbb7b
AC
20692@end menu
20693
20694@node Annotations Overview
20695@section What is an Annotation?
20696@cindex annotations
20697
922fbb7b
AC
20698Annotations start with a newline character, two @samp{control-z}
20699characters, and the name of the annotation. If there is no additional
20700information associated with this annotation, the name of the annotation
20701is followed immediately by a newline. If there is additional
20702information, the name of the annotation is followed by a space, the
20703additional information, and a newline. The additional information
20704cannot contain newline characters.
20705
20706Any output not beginning with a newline and two @samp{control-z}
20707characters denotes literal output from @value{GDBN}. Currently there is
20708no need for @value{GDBN} to output a newline followed by two
20709@samp{control-z} characters, but if there was such a need, the
20710annotations could be extended with an @samp{escape} annotation which
20711means those three characters as output.
20712
086432e2
AC
20713The annotation @var{level}, which is specified using the
20714@option{--annotate} command line option (@pxref{Mode Options}), controls
20715how much information @value{GDBN} prints together with its prompt,
20716values of expressions, source lines, and other types of output. Level 0
20717is for no anntations, level 1 is for use when @value{GDBN} is run as a
20718subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
20719for programs that control @value{GDBN}, and level 2 annotations have
20720been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
20721Interface, annotate, GDB's Obsolete Annotations}).
20722
20723@table @code
20724@kindex set annotate
20725@item set annotate @var{level}
e09f16f9 20726The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 20727annotations to the specified @var{level}.
9c16f35a
EZ
20728
20729@item show annotate
20730@kindex show annotate
20731Show the current annotation level.
09d4efe1
EZ
20732@end table
20733
20734This chapter describes level 3 annotations.
086432e2 20735
922fbb7b
AC
20736A simple example of starting up @value{GDBN} with annotations is:
20737
20738@smallexample
086432e2
AC
20739$ @kbd{gdb --annotate=3}
20740GNU gdb 6.0
20741Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
20742GDB is free software, covered by the GNU General Public License,
20743and you are welcome to change it and/or distribute copies of it
20744under certain conditions.
20745Type "show copying" to see the conditions.
20746There is absolutely no warranty for GDB. Type "show warranty"
20747for details.
086432e2 20748This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
20749
20750^Z^Zpre-prompt
f7dc1244 20751(@value{GDBP})
922fbb7b 20752^Z^Zprompt
086432e2 20753@kbd{quit}
922fbb7b
AC
20754
20755^Z^Zpost-prompt
b383017d 20756$
922fbb7b
AC
20757@end smallexample
20758
20759Here @samp{quit} is input to @value{GDBN}; the rest is output from
20760@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
20761denotes a @samp{control-z} character) are annotations; the rest is
20762output from @value{GDBN}.
20763
922fbb7b
AC
20764@node Prompting
20765@section Annotation for @value{GDBN} Input
20766
20767@cindex annotations for prompts
20768When @value{GDBN} prompts for input, it annotates this fact so it is possible
20769to know when to send output, when the output from a given command is
20770over, etc.
20771
20772Different kinds of input each have a different @dfn{input type}. Each
20773input type has three annotations: a @code{pre-} annotation, which
20774denotes the beginning of any prompt which is being output, a plain
20775annotation, which denotes the end of the prompt, and then a @code{post-}
20776annotation which denotes the end of any echo which may (or may not) be
20777associated with the input. For example, the @code{prompt} input type
20778features the following annotations:
20779
20780@smallexample
20781^Z^Zpre-prompt
20782^Z^Zprompt
20783^Z^Zpost-prompt
20784@end smallexample
20785
20786The input types are
20787
20788@table @code
20789@findex pre-prompt
20790@findex prompt
20791@findex post-prompt
20792@item prompt
20793When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
20794
20795@findex pre-commands
20796@findex commands
20797@findex post-commands
20798@item commands
20799When @value{GDBN} prompts for a set of commands, like in the @code{commands}
20800command. The annotations are repeated for each command which is input.
20801
20802@findex pre-overload-choice
20803@findex overload-choice
20804@findex post-overload-choice
20805@item overload-choice
20806When @value{GDBN} wants the user to select between various overloaded functions.
20807
20808@findex pre-query
20809@findex query
20810@findex post-query
20811@item query
20812When @value{GDBN} wants the user to confirm a potentially dangerous operation.
20813
20814@findex pre-prompt-for-continue
20815@findex prompt-for-continue
20816@findex post-prompt-for-continue
20817@item prompt-for-continue
20818When @value{GDBN} is asking the user to press return to continue. Note: Don't
20819expect this to work well; instead use @code{set height 0} to disable
20820prompting. This is because the counting of lines is buggy in the
20821presence of annotations.
20822@end table
20823
20824@node Errors
20825@section Errors
20826@cindex annotations for errors, warnings and interrupts
20827
20828@findex quit
20829@smallexample
20830^Z^Zquit
20831@end smallexample
20832
20833This annotation occurs right before @value{GDBN} responds to an interrupt.
20834
20835@findex error
20836@smallexample
20837^Z^Zerror
20838@end smallexample
20839
20840This annotation occurs right before @value{GDBN} responds to an error.
20841
20842Quit and error annotations indicate that any annotations which @value{GDBN} was
20843in the middle of may end abruptly. For example, if a
20844@code{value-history-begin} annotation is followed by a @code{error}, one
20845cannot expect to receive the matching @code{value-history-end}. One
20846cannot expect not to receive it either, however; an error annotation
20847does not necessarily mean that @value{GDBN} is immediately returning all the way
20848to the top level.
20849
20850@findex error-begin
20851A quit or error annotation may be preceded by
20852
20853@smallexample
20854^Z^Zerror-begin
20855@end smallexample
20856
20857Any output between that and the quit or error annotation is the error
20858message.
20859
20860Warning messages are not yet annotated.
20861@c If we want to change that, need to fix warning(), type_error(),
20862@c range_error(), and possibly other places.
20863
922fbb7b
AC
20864@node Invalidation
20865@section Invalidation Notices
20866
20867@cindex annotations for invalidation messages
20868The following annotations say that certain pieces of state may have
20869changed.
20870
20871@table @code
20872@findex frames-invalid
20873@item ^Z^Zframes-invalid
20874
20875The frames (for example, output from the @code{backtrace} command) may
20876have changed.
20877
20878@findex breakpoints-invalid
20879@item ^Z^Zbreakpoints-invalid
20880
20881The breakpoints may have changed. For example, the user just added or
20882deleted a breakpoint.
20883@end table
20884
20885@node Annotations for Running
20886@section Running the Program
20887@cindex annotations for running programs
20888
20889@findex starting
20890@findex stopping
20891When the program starts executing due to a @value{GDBN} command such as
b383017d 20892@code{step} or @code{continue},
922fbb7b
AC
20893
20894@smallexample
20895^Z^Zstarting
20896@end smallexample
20897
b383017d 20898is output. When the program stops,
922fbb7b
AC
20899
20900@smallexample
20901^Z^Zstopped
20902@end smallexample
20903
20904is output. Before the @code{stopped} annotation, a variety of
20905annotations describe how the program stopped.
20906
20907@table @code
20908@findex exited
20909@item ^Z^Zexited @var{exit-status}
20910The program exited, and @var{exit-status} is the exit status (zero for
20911successful exit, otherwise nonzero).
20912
20913@findex signalled
20914@findex signal-name
20915@findex signal-name-end
20916@findex signal-string
20917@findex signal-string-end
20918@item ^Z^Zsignalled
20919The program exited with a signal. After the @code{^Z^Zsignalled}, the
20920annotation continues:
20921
20922@smallexample
20923@var{intro-text}
20924^Z^Zsignal-name
20925@var{name}
20926^Z^Zsignal-name-end
20927@var{middle-text}
20928^Z^Zsignal-string
20929@var{string}
20930^Z^Zsignal-string-end
20931@var{end-text}
20932@end smallexample
20933
20934@noindent
20935where @var{name} is the name of the signal, such as @code{SIGILL} or
20936@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
20937as @code{Illegal Instruction} or @code{Segmentation fault}.
20938@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
20939user's benefit and have no particular format.
20940
20941@findex signal
20942@item ^Z^Zsignal
20943The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
20944just saying that the program received the signal, not that it was
20945terminated with it.
20946
20947@findex breakpoint
20948@item ^Z^Zbreakpoint @var{number}
20949The program hit breakpoint number @var{number}.
20950
20951@findex watchpoint
20952@item ^Z^Zwatchpoint @var{number}
20953The program hit watchpoint number @var{number}.
20954@end table
20955
20956@node Source Annotations
20957@section Displaying Source
20958@cindex annotations for source display
20959
20960@findex source
20961The following annotation is used instead of displaying source code:
20962
20963@smallexample
20964^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
20965@end smallexample
20966
20967where @var{filename} is an absolute file name indicating which source
20968file, @var{line} is the line number within that file (where 1 is the
20969first line in the file), @var{character} is the character position
20970within the file (where 0 is the first character in the file) (for most
20971debug formats this will necessarily point to the beginning of a line),
20972@var{middle} is @samp{middle} if @var{addr} is in the middle of the
20973line, or @samp{beg} if @var{addr} is at the beginning of the line, and
20974@var{addr} is the address in the target program associated with the
20975source which is being displayed. @var{addr} is in the form @samp{0x}
20976followed by one or more lowercase hex digits (note that this does not
20977depend on the language).
20978
8e04817f
AC
20979@node GDB Bugs
20980@chapter Reporting Bugs in @value{GDBN}
20981@cindex bugs in @value{GDBN}
20982@cindex reporting bugs in @value{GDBN}
c906108c 20983
8e04817f 20984Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 20985
8e04817f
AC
20986Reporting a bug may help you by bringing a solution to your problem, or it
20987may not. But in any case the principal function of a bug report is to help
20988the entire community by making the next version of @value{GDBN} work better. Bug
20989reports are your contribution to the maintenance of @value{GDBN}.
c906108c 20990
8e04817f
AC
20991In order for a bug report to serve its purpose, you must include the
20992information that enables us to fix the bug.
c4555f82
SC
20993
20994@menu
8e04817f
AC
20995* Bug Criteria:: Have you found a bug?
20996* Bug Reporting:: How to report bugs
c4555f82
SC
20997@end menu
20998
8e04817f
AC
20999@node Bug Criteria
21000@section Have you found a bug?
21001@cindex bug criteria
c4555f82 21002
8e04817f 21003If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
21004
21005@itemize @bullet
8e04817f
AC
21006@cindex fatal signal
21007@cindex debugger crash
21008@cindex crash of debugger
c4555f82 21009@item
8e04817f
AC
21010If the debugger gets a fatal signal, for any input whatever, that is a
21011@value{GDBN} bug. Reliable debuggers never crash.
21012
21013@cindex error on valid input
21014@item
21015If @value{GDBN} produces an error message for valid input, that is a
21016bug. (Note that if you're cross debugging, the problem may also be
21017somewhere in the connection to the target.)
c4555f82 21018
8e04817f 21019@cindex invalid input
c4555f82 21020@item
8e04817f
AC
21021If @value{GDBN} does not produce an error message for invalid input,
21022that is a bug. However, you should note that your idea of
21023``invalid input'' might be our idea of ``an extension'' or ``support
21024for traditional practice''.
21025
21026@item
21027If you are an experienced user of debugging tools, your suggestions
21028for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
21029@end itemize
21030
8e04817f
AC
21031@node Bug Reporting
21032@section How to report bugs
21033@cindex bug reports
21034@cindex @value{GDBN} bugs, reporting
21035
21036A number of companies and individuals offer support for @sc{gnu} products.
21037If you obtained @value{GDBN} from a support organization, we recommend you
21038contact that organization first.
21039
21040You can find contact information for many support companies and
21041individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
21042distribution.
21043@c should add a web page ref...
21044
129188f6
AC
21045In any event, we also recommend that you submit bug reports for
21046@value{GDBN}. The prefered method is to submit them directly using
21047@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
21048page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
21049be used.
8e04817f
AC
21050
21051@strong{Do not send bug reports to @samp{info-gdb}, or to
21052@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
21053not want to receive bug reports. Those that do have arranged to receive
21054@samp{bug-gdb}.
21055
21056The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
21057serves as a repeater. The mailing list and the newsgroup carry exactly
21058the same messages. Often people think of posting bug reports to the
21059newsgroup instead of mailing them. This appears to work, but it has one
21060problem which can be crucial: a newsgroup posting often lacks a mail
21061path back to the sender. Thus, if we need to ask for more information,
21062we may be unable to reach you. For this reason, it is better to send
21063bug reports to the mailing list.
c4555f82 21064
8e04817f
AC
21065The fundamental principle of reporting bugs usefully is this:
21066@strong{report all the facts}. If you are not sure whether to state a
21067fact or leave it out, state it!
c4555f82 21068
8e04817f
AC
21069Often people omit facts because they think they know what causes the
21070problem and assume that some details do not matter. Thus, you might
21071assume that the name of the variable you use in an example does not matter.
21072Well, probably it does not, but one cannot be sure. Perhaps the bug is a
21073stray memory reference which happens to fetch from the location where that
21074name is stored in memory; perhaps, if the name were different, the contents
21075of that location would fool the debugger into doing the right thing despite
21076the bug. Play it safe and give a specific, complete example. That is the
21077easiest thing for you to do, and the most helpful.
c4555f82 21078
8e04817f
AC
21079Keep in mind that the purpose of a bug report is to enable us to fix the
21080bug. It may be that the bug has been reported previously, but neither
21081you nor we can know that unless your bug report is complete and
21082self-contained.
c4555f82 21083
8e04817f
AC
21084Sometimes people give a few sketchy facts and ask, ``Does this ring a
21085bell?'' Those bug reports are useless, and we urge everyone to
21086@emph{refuse to respond to them} except to chide the sender to report
21087bugs properly.
21088
21089To enable us to fix the bug, you should include all these things:
c4555f82
SC
21090
21091@itemize @bullet
21092@item
8e04817f
AC
21093The version of @value{GDBN}. @value{GDBN} announces it if you start
21094with no arguments; you can also print it at any time using @code{show
21095version}.
c4555f82 21096
8e04817f
AC
21097Without this, we will not know whether there is any point in looking for
21098the bug in the current version of @value{GDBN}.
c4555f82
SC
21099
21100@item
8e04817f
AC
21101The type of machine you are using, and the operating system name and
21102version number.
c4555f82
SC
21103
21104@item
8e04817f
AC
21105What compiler (and its version) was used to compile @value{GDBN}---e.g.
21106``@value{GCC}--2.8.1''.
c4555f82
SC
21107
21108@item
8e04817f
AC
21109What compiler (and its version) was used to compile the program you are
21110debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
21111C Compiler''. For GCC, you can say @code{gcc --version} to get this
21112information; for other compilers, see the documentation for those
21113compilers.
c4555f82 21114
8e04817f
AC
21115@item
21116The command arguments you gave the compiler to compile your example and
21117observe the bug. For example, did you use @samp{-O}? To guarantee
21118you will not omit something important, list them all. A copy of the
21119Makefile (or the output from make) is sufficient.
c4555f82 21120
8e04817f
AC
21121If we were to try to guess the arguments, we would probably guess wrong
21122and then we might not encounter the bug.
c4555f82 21123
8e04817f
AC
21124@item
21125A complete input script, and all necessary source files, that will
21126reproduce the bug.
c4555f82 21127
8e04817f
AC
21128@item
21129A description of what behavior you observe that you believe is
21130incorrect. For example, ``It gets a fatal signal.''
c4555f82 21131
8e04817f
AC
21132Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
21133will certainly notice it. But if the bug is incorrect output, we might
21134not notice unless it is glaringly wrong. You might as well not give us
21135a chance to make a mistake.
c4555f82 21136
8e04817f
AC
21137Even if the problem you experience is a fatal signal, you should still
21138say so explicitly. Suppose something strange is going on, such as, your
21139copy of @value{GDBN} is out of synch, or you have encountered a bug in
21140the C library on your system. (This has happened!) Your copy might
21141crash and ours would not. If you told us to expect a crash, then when
21142ours fails to crash, we would know that the bug was not happening for
21143us. If you had not told us to expect a crash, then we would not be able
21144to draw any conclusion from our observations.
c4555f82 21145
e0c07bf0
MC
21146@pindex script
21147@cindex recording a session script
21148To collect all this information, you can use a session recording program
21149such as @command{script}, which is available on many Unix systems.
21150Just run your @value{GDBN} session inside @command{script} and then
21151include the @file{typescript} file with your bug report.
21152
21153Another way to record a @value{GDBN} session is to run @value{GDBN}
21154inside Emacs and then save the entire buffer to a file.
21155
8e04817f
AC
21156@item
21157If you wish to suggest changes to the @value{GDBN} source, send us context
21158diffs. If you even discuss something in the @value{GDBN} source, refer to
21159it by context, not by line number.
c4555f82 21160
8e04817f
AC
21161The line numbers in our development sources will not match those in your
21162sources. Your line numbers would convey no useful information to us.
c4555f82 21163
8e04817f 21164@end itemize
c4555f82 21165
8e04817f 21166Here are some things that are not necessary:
c4555f82 21167
8e04817f
AC
21168@itemize @bullet
21169@item
21170A description of the envelope of the bug.
c4555f82 21171
8e04817f
AC
21172Often people who encounter a bug spend a lot of time investigating
21173which changes to the input file will make the bug go away and which
21174changes will not affect it.
c4555f82 21175
8e04817f
AC
21176This is often time consuming and not very useful, because the way we
21177will find the bug is by running a single example under the debugger
21178with breakpoints, not by pure deduction from a series of examples.
21179We recommend that you save your time for something else.
c4555f82 21180
8e04817f
AC
21181Of course, if you can find a simpler example to report @emph{instead}
21182of the original one, that is a convenience for us. Errors in the
21183output will be easier to spot, running under the debugger will take
21184less time, and so on.
c4555f82 21185
8e04817f
AC
21186However, simplification is not vital; if you do not want to do this,
21187report the bug anyway and send us the entire test case you used.
c4555f82 21188
8e04817f
AC
21189@item
21190A patch for the bug.
c4555f82 21191
8e04817f
AC
21192A patch for the bug does help us if it is a good one. But do not omit
21193the necessary information, such as the test case, on the assumption that
21194a patch is all we need. We might see problems with your patch and decide
21195to fix the problem another way, or we might not understand it at all.
c4555f82 21196
8e04817f
AC
21197Sometimes with a program as complicated as @value{GDBN} it is very hard to
21198construct an example that will make the program follow a certain path
21199through the code. If you do not send us the example, we will not be able
21200to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 21201
8e04817f
AC
21202And if we cannot understand what bug you are trying to fix, or why your
21203patch should be an improvement, we will not install it. A test case will
21204help us to understand.
c4555f82 21205
8e04817f
AC
21206@item
21207A guess about what the bug is or what it depends on.
c4555f82 21208
8e04817f
AC
21209Such guesses are usually wrong. Even we cannot guess right about such
21210things without first using the debugger to find the facts.
21211@end itemize
c4555f82 21212
8e04817f
AC
21213@c The readline documentation is distributed with the readline code
21214@c and consists of the two following files:
21215@c rluser.texinfo
21216@c inc-hist.texinfo
21217@c Use -I with makeinfo to point to the appropriate directory,
21218@c environment var TEXINPUTS with TeX.
21219@include rluser.texinfo
21220@include inc-hist.texinfo
c4555f82 21221
c4555f82 21222
8e04817f
AC
21223@node Formatting Documentation
21224@appendix Formatting Documentation
c4555f82 21225
8e04817f
AC
21226@cindex @value{GDBN} reference card
21227@cindex reference card
21228The @value{GDBN} 4 release includes an already-formatted reference card, ready
21229for printing with PostScript or Ghostscript, in the @file{gdb}
21230subdirectory of the main source directory@footnote{In
21231@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
21232release.}. If you can use PostScript or Ghostscript with your printer,
21233you can print the reference card immediately with @file{refcard.ps}.
c4555f82 21234
8e04817f
AC
21235The release also includes the source for the reference card. You
21236can format it, using @TeX{}, by typing:
c4555f82 21237
474c8240 21238@smallexample
8e04817f 21239make refcard.dvi
474c8240 21240@end smallexample
c4555f82 21241
8e04817f
AC
21242The @value{GDBN} reference card is designed to print in @dfn{landscape}
21243mode on US ``letter'' size paper;
21244that is, on a sheet 11 inches wide by 8.5 inches
21245high. You will need to specify this form of printing as an option to
21246your @sc{dvi} output program.
c4555f82 21247
8e04817f 21248@cindex documentation
c4555f82 21249
8e04817f
AC
21250All the documentation for @value{GDBN} comes as part of the machine-readable
21251distribution. The documentation is written in Texinfo format, which is
21252a documentation system that uses a single source file to produce both
21253on-line information and a printed manual. You can use one of the Info
21254formatting commands to create the on-line version of the documentation
21255and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 21256
8e04817f
AC
21257@value{GDBN} includes an already formatted copy of the on-line Info
21258version of this manual in the @file{gdb} subdirectory. The main Info
21259file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
21260subordinate files matching @samp{gdb.info*} in the same directory. If
21261necessary, you can print out these files, or read them with any editor;
21262but they are easier to read using the @code{info} subsystem in @sc{gnu}
21263Emacs or the standalone @code{info} program, available as part of the
21264@sc{gnu} Texinfo distribution.
c4555f82 21265
8e04817f
AC
21266If you want to format these Info files yourself, you need one of the
21267Info formatting programs, such as @code{texinfo-format-buffer} or
21268@code{makeinfo}.
c4555f82 21269
8e04817f
AC
21270If you have @code{makeinfo} installed, and are in the top level
21271@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
21272version @value{GDBVN}), you can make the Info file by typing:
c4555f82 21273
474c8240 21274@smallexample
8e04817f
AC
21275cd gdb
21276make gdb.info
474c8240 21277@end smallexample
c4555f82 21278
8e04817f
AC
21279If you want to typeset and print copies of this manual, you need @TeX{},
21280a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
21281Texinfo definitions file.
c4555f82 21282
8e04817f
AC
21283@TeX{} is a typesetting program; it does not print files directly, but
21284produces output files called @sc{dvi} files. To print a typeset
21285document, you need a program to print @sc{dvi} files. If your system
21286has @TeX{} installed, chances are it has such a program. The precise
21287command to use depends on your system; @kbd{lpr -d} is common; another
21288(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
21289require a file name without any extension or a @samp{.dvi} extension.
c4555f82 21290
8e04817f
AC
21291@TeX{} also requires a macro definitions file called
21292@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
21293written in Texinfo format. On its own, @TeX{} cannot either read or
21294typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
21295and is located in the @file{gdb-@var{version-number}/texinfo}
21296directory.
c4555f82 21297
8e04817f
AC
21298If you have @TeX{} and a @sc{dvi} printer program installed, you can
21299typeset and print this manual. First switch to the the @file{gdb}
21300subdirectory of the main source directory (for example, to
21301@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 21302
474c8240 21303@smallexample
8e04817f 21304make gdb.dvi
474c8240 21305@end smallexample
c4555f82 21306
8e04817f 21307Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 21308
8e04817f
AC
21309@node Installing GDB
21310@appendix Installing @value{GDBN}
21311@cindex configuring @value{GDBN}
21312@cindex installation
94e91d6d 21313@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 21314
8e04817f
AC
21315@value{GDBN} comes with a @code{configure} script that automates the process
21316of preparing @value{GDBN} for installation; you can then use @code{make} to
21317build the @code{gdb} program.
21318@iftex
21319@c irrelevant in info file; it's as current as the code it lives with.
21320@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
21321look at the @file{README} file in the sources; we may have improved the
21322installation procedures since publishing this manual.}
21323@end iftex
c4555f82 21324
8e04817f
AC
21325The @value{GDBN} distribution includes all the source code you need for
21326@value{GDBN} in a single directory, whose name is usually composed by
21327appending the version number to @samp{gdb}.
c4555f82 21328
8e04817f
AC
21329For example, the @value{GDBN} version @value{GDBVN} distribution is in the
21330@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 21331
8e04817f
AC
21332@table @code
21333@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
21334script for configuring @value{GDBN} and all its supporting libraries
c4555f82 21335
8e04817f
AC
21336@item gdb-@value{GDBVN}/gdb
21337the source specific to @value{GDBN} itself
c4555f82 21338
8e04817f
AC
21339@item gdb-@value{GDBVN}/bfd
21340source for the Binary File Descriptor library
c906108c 21341
8e04817f
AC
21342@item gdb-@value{GDBVN}/include
21343@sc{gnu} include files
c906108c 21344
8e04817f
AC
21345@item gdb-@value{GDBVN}/libiberty
21346source for the @samp{-liberty} free software library
c906108c 21347
8e04817f
AC
21348@item gdb-@value{GDBVN}/opcodes
21349source for the library of opcode tables and disassemblers
c906108c 21350
8e04817f
AC
21351@item gdb-@value{GDBVN}/readline
21352source for the @sc{gnu} command-line interface
c906108c 21353
8e04817f
AC
21354@item gdb-@value{GDBVN}/glob
21355source for the @sc{gnu} filename pattern-matching subroutine
c906108c 21356
8e04817f
AC
21357@item gdb-@value{GDBVN}/mmalloc
21358source for the @sc{gnu} memory-mapped malloc package
21359@end table
c906108c 21360
8e04817f
AC
21361The simplest way to configure and build @value{GDBN} is to run @code{configure}
21362from the @file{gdb-@var{version-number}} source directory, which in
21363this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 21364
8e04817f
AC
21365First switch to the @file{gdb-@var{version-number}} source directory
21366if you are not already in it; then run @code{configure}. Pass the
21367identifier for the platform on which @value{GDBN} will run as an
21368argument.
c906108c 21369
8e04817f 21370For example:
c906108c 21371
474c8240 21372@smallexample
8e04817f
AC
21373cd gdb-@value{GDBVN}
21374./configure @var{host}
21375make
474c8240 21376@end smallexample
c906108c 21377
8e04817f
AC
21378@noindent
21379where @var{host} is an identifier such as @samp{sun4} or
21380@samp{decstation}, that identifies the platform where @value{GDBN} will run.
21381(You can often leave off @var{host}; @code{configure} tries to guess the
21382correct value by examining your system.)
c906108c 21383
8e04817f
AC
21384Running @samp{configure @var{host}} and then running @code{make} builds the
21385@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
21386libraries, then @code{gdb} itself. The configured source files, and the
21387binaries, are left in the corresponding source directories.
c906108c 21388
8e04817f
AC
21389@need 750
21390@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
21391system does not recognize this automatically when you run a different
21392shell, you may need to run @code{sh} on it explicitly:
c906108c 21393
474c8240 21394@smallexample
8e04817f 21395sh configure @var{host}
474c8240 21396@end smallexample
c906108c 21397
8e04817f
AC
21398If you run @code{configure} from a directory that contains source
21399directories for multiple libraries or programs, such as the
21400@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
21401creates configuration files for every directory level underneath (unless
21402you tell it not to, with the @samp{--norecursion} option).
21403
94e91d6d
MC
21404You should run the @code{configure} script from the top directory in the
21405source tree, the @file{gdb-@var{version-number}} directory. If you run
21406@code{configure} from one of the subdirectories, you will configure only
21407that subdirectory. That is usually not what you want. In particular,
21408if you run the first @code{configure} from the @file{gdb} subdirectory
21409of the @file{gdb-@var{version-number}} directory, you will omit the
21410configuration of @file{bfd}, @file{readline}, and other sibling
21411directories of the @file{gdb} subdirectory. This leads to build errors
21412about missing include files such as @file{bfd/bfd.h}.
c906108c 21413
8e04817f
AC
21414You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
21415However, you should make sure that the shell on your path (named by
21416the @samp{SHELL} environment variable) is publicly readable. Remember
21417that @value{GDBN} uses the shell to start your program---some systems refuse to
21418let @value{GDBN} debug child processes whose programs are not readable.
c906108c 21419
8e04817f
AC
21420@menu
21421* Separate Objdir:: Compiling @value{GDBN} in another directory
21422* Config Names:: Specifying names for hosts and targets
21423* Configure Options:: Summary of options for configure
21424@end menu
c906108c 21425
8e04817f
AC
21426@node Separate Objdir
21427@section Compiling @value{GDBN} in another directory
c906108c 21428
8e04817f
AC
21429If you want to run @value{GDBN} versions for several host or target machines,
21430you need a different @code{gdb} compiled for each combination of
21431host and target. @code{configure} is designed to make this easy by
21432allowing you to generate each configuration in a separate subdirectory,
21433rather than in the source directory. If your @code{make} program
21434handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
21435@code{make} in each of these directories builds the @code{gdb}
21436program specified there.
c906108c 21437
8e04817f
AC
21438To build @code{gdb} in a separate directory, run @code{configure}
21439with the @samp{--srcdir} option to specify where to find the source.
21440(You also need to specify a path to find @code{configure}
21441itself from your working directory. If the path to @code{configure}
21442would be the same as the argument to @samp{--srcdir}, you can leave out
21443the @samp{--srcdir} option; it is assumed.)
c906108c 21444
8e04817f
AC
21445For example, with version @value{GDBVN}, you can build @value{GDBN} in a
21446separate directory for a Sun 4 like this:
c906108c 21447
474c8240 21448@smallexample
8e04817f
AC
21449@group
21450cd gdb-@value{GDBVN}
21451mkdir ../gdb-sun4
21452cd ../gdb-sun4
21453../gdb-@value{GDBVN}/configure sun4
21454make
21455@end group
474c8240 21456@end smallexample
c906108c 21457
8e04817f
AC
21458When @code{configure} builds a configuration using a remote source
21459directory, it creates a tree for the binaries with the same structure
21460(and using the same names) as the tree under the source directory. In
21461the example, you'd find the Sun 4 library @file{libiberty.a} in the
21462directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
21463@file{gdb-sun4/gdb}.
c906108c 21464
94e91d6d
MC
21465Make sure that your path to the @file{configure} script has just one
21466instance of @file{gdb} in it. If your path to @file{configure} looks
21467like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
21468one subdirectory of @value{GDBN}, not the whole package. This leads to
21469build errors about missing include files such as @file{bfd/bfd.h}.
21470
8e04817f
AC
21471One popular reason to build several @value{GDBN} configurations in separate
21472directories is to configure @value{GDBN} for cross-compiling (where
21473@value{GDBN} runs on one machine---the @dfn{host}---while debugging
21474programs that run on another machine---the @dfn{target}).
21475You specify a cross-debugging target by
21476giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 21477
8e04817f
AC
21478When you run @code{make} to build a program or library, you must run
21479it in a configured directory---whatever directory you were in when you
21480called @code{configure} (or one of its subdirectories).
c906108c 21481
8e04817f
AC
21482The @code{Makefile} that @code{configure} generates in each source
21483directory also runs recursively. If you type @code{make} in a source
21484directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
21485directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
21486will build all the required libraries, and then build GDB.
c906108c 21487
8e04817f
AC
21488When you have multiple hosts or targets configured in separate
21489directories, you can run @code{make} on them in parallel (for example,
21490if they are NFS-mounted on each of the hosts); they will not interfere
21491with each other.
c906108c 21492
8e04817f
AC
21493@node Config Names
21494@section Specifying names for hosts and targets
c906108c 21495
8e04817f
AC
21496The specifications used for hosts and targets in the @code{configure}
21497script are based on a three-part naming scheme, but some short predefined
21498aliases are also supported. The full naming scheme encodes three pieces
21499of information in the following pattern:
c906108c 21500
474c8240 21501@smallexample
8e04817f 21502@var{architecture}-@var{vendor}-@var{os}
474c8240 21503@end smallexample
c906108c 21504
8e04817f
AC
21505For example, you can use the alias @code{sun4} as a @var{host} argument,
21506or as the value for @var{target} in a @code{--target=@var{target}}
21507option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 21508
8e04817f
AC
21509The @code{configure} script accompanying @value{GDBN} does not provide
21510any query facility to list all supported host and target names or
21511aliases. @code{configure} calls the Bourne shell script
21512@code{config.sub} to map abbreviations to full names; you can read the
21513script, if you wish, or you can use it to test your guesses on
21514abbreviations---for example:
c906108c 21515
8e04817f
AC
21516@smallexample
21517% sh config.sub i386-linux
21518i386-pc-linux-gnu
21519% sh config.sub alpha-linux
21520alpha-unknown-linux-gnu
21521% sh config.sub hp9k700
21522hppa1.1-hp-hpux
21523% sh config.sub sun4
21524sparc-sun-sunos4.1.1
21525% sh config.sub sun3
21526m68k-sun-sunos4.1.1
21527% sh config.sub i986v
21528Invalid configuration `i986v': machine `i986v' not recognized
21529@end smallexample
c906108c 21530
8e04817f
AC
21531@noindent
21532@code{config.sub} is also distributed in the @value{GDBN} source
21533directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 21534
8e04817f
AC
21535@node Configure Options
21536@section @code{configure} options
c906108c 21537
8e04817f
AC
21538Here is a summary of the @code{configure} options and arguments that
21539are most often useful for building @value{GDBN}. @code{configure} also has
21540several other options not listed here. @inforef{What Configure
21541Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 21542
474c8240 21543@smallexample
8e04817f
AC
21544configure @r{[}--help@r{]}
21545 @r{[}--prefix=@var{dir}@r{]}
21546 @r{[}--exec-prefix=@var{dir}@r{]}
21547 @r{[}--srcdir=@var{dirname}@r{]}
21548 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
21549 @r{[}--target=@var{target}@r{]}
21550 @var{host}
474c8240 21551@end smallexample
c906108c 21552
8e04817f
AC
21553@noindent
21554You may introduce options with a single @samp{-} rather than
21555@samp{--} if you prefer; but you may abbreviate option names if you use
21556@samp{--}.
c906108c 21557
8e04817f
AC
21558@table @code
21559@item --help
21560Display a quick summary of how to invoke @code{configure}.
c906108c 21561
8e04817f
AC
21562@item --prefix=@var{dir}
21563Configure the source to install programs and files under directory
21564@file{@var{dir}}.
c906108c 21565
8e04817f
AC
21566@item --exec-prefix=@var{dir}
21567Configure the source to install programs under directory
21568@file{@var{dir}}.
c906108c 21569
8e04817f
AC
21570@c avoid splitting the warning from the explanation:
21571@need 2000
21572@item --srcdir=@var{dirname}
21573@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
21574@code{make} that implements the @code{VPATH} feature.}@*
21575Use this option to make configurations in directories separate from the
21576@value{GDBN} source directories. Among other things, you can use this to
21577build (or maintain) several configurations simultaneously, in separate
21578directories. @code{configure} writes configuration specific files in
21579the current directory, but arranges for them to use the source in the
21580directory @var{dirname}. @code{configure} creates directories under
21581the working directory in parallel to the source directories below
21582@var{dirname}.
c906108c 21583
8e04817f
AC
21584@item --norecursion
21585Configure only the directory level where @code{configure} is executed; do not
21586propagate configuration to subdirectories.
c906108c 21587
8e04817f
AC
21588@item --target=@var{target}
21589Configure @value{GDBN} for cross-debugging programs running on the specified
21590@var{target}. Without this option, @value{GDBN} is configured to debug
21591programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 21592
8e04817f 21593There is no convenient way to generate a list of all available targets.
c906108c 21594
8e04817f
AC
21595@item @var{host} @dots{}
21596Configure @value{GDBN} to run on the specified @var{host}.
c906108c 21597
8e04817f
AC
21598There is no convenient way to generate a list of all available hosts.
21599@end table
c906108c 21600
8e04817f
AC
21601There are many other options available as well, but they are generally
21602needed for special purposes only.
c906108c 21603
8e04817f
AC
21604@node Maintenance Commands
21605@appendix Maintenance Commands
21606@cindex maintenance commands
21607@cindex internal commands
c906108c 21608
8e04817f 21609In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
21610includes a number of commands intended for @value{GDBN} developers,
21611that are not documented elsewhere in this manual. These commands are
da316a69
EZ
21612provided here for reference. (For commands that turn on debugging
21613messages, see @ref{Debugging Output}.)
c906108c 21614
8e04817f 21615@table @code
09d4efe1
EZ
21616@kindex maint agent
21617@item maint agent @var{expression}
21618Translate the given @var{expression} into remote agent bytecodes.
21619This command is useful for debugging the Agent Expression mechanism
21620(@pxref{Agent Expressions}).
21621
8e04817f
AC
21622@kindex maint info breakpoints
21623@item @anchor{maint info breakpoints}maint info breakpoints
21624Using the same format as @samp{info breakpoints}, display both the
21625breakpoints you've set explicitly, and those @value{GDBN} is using for
21626internal purposes. Internal breakpoints are shown with negative
21627breakpoint numbers. The type column identifies what kind of breakpoint
21628is shown:
c906108c 21629
8e04817f
AC
21630@table @code
21631@item breakpoint
21632Normal, explicitly set breakpoint.
c906108c 21633
8e04817f
AC
21634@item watchpoint
21635Normal, explicitly set watchpoint.
c906108c 21636
8e04817f
AC
21637@item longjmp
21638Internal breakpoint, used to handle correctly stepping through
21639@code{longjmp} calls.
c906108c 21640
8e04817f
AC
21641@item longjmp resume
21642Internal breakpoint at the target of a @code{longjmp}.
c906108c 21643
8e04817f
AC
21644@item until
21645Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 21646
8e04817f
AC
21647@item finish
21648Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 21649
8e04817f
AC
21650@item shlib events
21651Shared library events.
c906108c 21652
8e04817f 21653@end table
c906108c 21654
09d4efe1
EZ
21655@kindex maint check-symtabs
21656@item maint check-symtabs
21657Check the consistency of psymtabs and symtabs.
21658
21659@kindex maint cplus first_component
21660@item maint cplus first_component @var{name}
21661Print the first C@t{++} class/namespace component of @var{name}.
21662
21663@kindex maint cplus namespace
21664@item maint cplus namespace
21665Print the list of possible C@t{++} namespaces.
21666
21667@kindex maint demangle
21668@item maint demangle @var{name}
21669Demangle a C@t{++} or Objective-C manled @var{name}.
21670
21671@kindex maint deprecate
21672@kindex maint undeprecate
21673@cindex deprecated commands
21674@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
21675@itemx maint undeprecate @var{command}
21676Deprecate or undeprecate the named @var{command}. Deprecated commands
21677cause @value{GDBN} to issue a warning when you use them. The optional
21678argument @var{replacement} says which newer command should be used in
21679favor of the deprecated one; if it is given, @value{GDBN} will mention
21680the replacement as part of the warning.
21681
21682@kindex maint dump-me
21683@item maint dump-me
721c2651 21684@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 21685Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
21686This is supported only on systems which support aborting a program
21687with the @code{SIGQUIT} signal.
09d4efe1 21688
8d30a00d
AC
21689@kindex maint internal-error
21690@kindex maint internal-warning
09d4efe1
EZ
21691@item maint internal-error @r{[}@var{message-text}@r{]}
21692@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
21693Cause @value{GDBN} to call the internal function @code{internal_error}
21694or @code{internal_warning} and hence behave as though an internal error
21695or internal warning has been detected. In addition to reporting the
21696internal problem, these functions give the user the opportunity to
21697either quit @value{GDBN} or create a core file of the current
21698@value{GDBN} session.
21699
09d4efe1
EZ
21700These commands take an optional parameter @var{message-text} that is
21701used as the text of the error or warning message.
21702
21703Here's an example of using @code{indernal-error}:
21704
8d30a00d 21705@smallexample
f7dc1244 21706(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
21707@dots{}/maint.c:121: internal-error: testing, 1, 2
21708A problem internal to GDB has been detected. Further
21709debugging may prove unreliable.
21710Quit this debugging session? (y or n) @kbd{n}
21711Create a core file? (y or n) @kbd{n}
f7dc1244 21712(@value{GDBP})
8d30a00d
AC
21713@end smallexample
21714
09d4efe1
EZ
21715@kindex maint packet
21716@item maint packet @var{text}
21717If @value{GDBN} is talking to an inferior via the serial protocol,
21718then this command sends the string @var{text} to the inferior, and
21719displays the response packet. @value{GDBN} supplies the initial
21720@samp{$} character, the terminating @samp{#} character, and the
21721checksum.
21722
21723@kindex maint print architecture
21724@item maint print architecture @r{[}@var{file}@r{]}
21725Print the entire architecture configuration. The optional argument
21726@var{file} names the file where the output goes.
8d30a00d 21727
00905d52
AC
21728@kindex maint print dummy-frames
21729@item maint print dummy-frames
00905d52
AC
21730Prints the contents of @value{GDBN}'s internal dummy-frame stack.
21731
21732@smallexample
f7dc1244 21733(@value{GDBP}) @kbd{b add}
00905d52 21734@dots{}
f7dc1244 21735(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
21736Breakpoint 2, add (a=2, b=3) at @dots{}
2173758 return (a + b);
21738The program being debugged stopped while in a function called from GDB.
21739@dots{}
f7dc1244 21740(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
217410x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
21742 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
21743 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 21744(@value{GDBP})
00905d52
AC
21745@end smallexample
21746
21747Takes an optional file parameter.
21748
0680b120
AC
21749@kindex maint print registers
21750@kindex maint print raw-registers
21751@kindex maint print cooked-registers
617073a9 21752@kindex maint print register-groups
09d4efe1
EZ
21753@item maint print registers @r{[}@var{file}@r{]}
21754@itemx maint print raw-registers @r{[}@var{file}@r{]}
21755@itemx maint print cooked-registers @r{[}@var{file}@r{]}
21756@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
21757Print @value{GDBN}'s internal register data structures.
21758
617073a9
AC
21759The command @code{maint print raw-registers} includes the contents of
21760the raw register cache; the command @code{maint print cooked-registers}
21761includes the (cooked) value of all registers; and the command
21762@code{maint print register-groups} includes the groups that each
21763register is a member of. @xref{Registers,, Registers, gdbint,
21764@value{GDBN} Internals}.
0680b120 21765
09d4efe1
EZ
21766These commands take an optional parameter, a file name to which to
21767write the information.
0680b120 21768
617073a9 21769@kindex maint print reggroups
09d4efe1
EZ
21770@item maint print reggroups @r{[}@var{file}@r{]}
21771Print @value{GDBN}'s internal register group data structures. The
21772optional argument @var{file} tells to what file to write the
21773information.
617073a9 21774
09d4efe1 21775The register groups info looks like this:
617073a9
AC
21776
21777@smallexample
f7dc1244 21778(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
21779 Group Type
21780 general user
21781 float user
21782 all user
21783 vector user
21784 system user
21785 save internal
21786 restore internal
617073a9
AC
21787@end smallexample
21788
09d4efe1
EZ
21789@kindex flushregs
21790@item flushregs
21791This command forces @value{GDBN} to flush its internal register cache.
21792
21793@kindex maint print objfiles
21794@cindex info for known object files
21795@item maint print objfiles
21796Print a dump of all known object files. For each object file, this
21797command prints its name, address in memory, and all of its psymtabs
21798and symtabs.
21799
21800@kindex maint print statistics
21801@cindex bcache statistics
21802@item maint print statistics
21803This command prints, for each object file in the program, various data
21804about that object file followed by the byte cache (@dfn{bcache})
21805statistics for the object file. The objfile data includes the number
21806of minimal, partical, full, and stabs symbols, the number of types
21807defined by the objfile, the number of as yet unexpanded psym tables,
21808the number of line tables and string tables, and the amount of memory
21809used by the various tables. The bcache statistics include the counts,
21810sizes, and counts of duplicates of all and unique objects, max,
21811average, and median entry size, total memory used and its overhead and
21812savings, and various measures of the hash table size and chain
21813lengths.
21814
21815@kindex maint print type
21816@cindex type chain of a data type
21817@item maint print type @var{expr}
21818Print the type chain for a type specified by @var{expr}. The argument
21819can be either a type name or a symbol. If it is a symbol, the type of
21820that symbol is described. The type chain produced by this command is
21821a recursive definition of the data type as stored in @value{GDBN}'s
21822data structures, including its flags and contained types.
21823
21824@kindex maint set dwarf2 max-cache-age
21825@kindex maint show dwarf2 max-cache-age
21826@item maint set dwarf2 max-cache-age
21827@itemx maint show dwarf2 max-cache-age
21828Control the DWARF 2 compilation unit cache.
21829
21830@cindex DWARF 2 compilation units cache
21831In object files with inter-compilation-unit references, such as those
21832produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
21833reader needs to frequently refer to previously read compilation units.
21834This setting controls how long a compilation unit will remain in the
21835cache if it is not referenced. A higher limit means that cached
21836compilation units will be stored in memory longer, and more total
21837memory will be used. Setting it to zero disables caching, which will
21838slow down @value{GDBN} startup, but reduce memory consumption.
21839
e7ba9c65
DJ
21840@kindex maint set profile
21841@kindex maint show profile
21842@cindex profiling GDB
21843@item maint set profile
21844@itemx maint show profile
21845Control profiling of @value{GDBN}.
21846
21847Profiling will be disabled until you use the @samp{maint set profile}
21848command to enable it. When you enable profiling, the system will begin
21849collecting timing and execution count data; when you disable profiling or
21850exit @value{GDBN}, the results will be written to a log file. Remember that
21851if you use profiling, @value{GDBN} will overwrite the profiling log file
21852(often called @file{gmon.out}). If you have a record of important profiling
21853data in a @file{gmon.out} file, be sure to move it to a safe location.
21854
21855Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 21856compiled with the @samp{-pg} compiler option.
e7ba9c65 21857
09d4efe1
EZ
21858@kindex maint show-debug-regs
21859@cindex x86 hardware debug registers
21860@item maint show-debug-regs
21861Control whether to show variables that mirror the x86 hardware debug
21862registers. Use @code{ON} to enable, @code{OFF} to disable. If
21863enabled, the debug registers values are shown when GDB inserts or
21864removes a hardware breakpoint or watchpoint, and when the inferior
21865triggers a hardware-assisted breakpoint or watchpoint.
21866
21867@kindex maint space
21868@cindex memory used by commands
21869@item maint space
21870Control whether to display memory usage for each command. If set to a
21871nonzero value, @value{GDBN} will display how much memory each command
21872took, following the command's own output. This can also be requested
21873by invoking @value{GDBN} with the @option{--statistics} command-line
21874switch (@pxref{Mode Options}).
21875
21876@kindex maint time
21877@cindex time of command execution
21878@item maint time
21879Control whether to display the execution time for each command. If
21880set to a nonzero value, @value{GDBN} will display how much time it
21881took to execute each command, following the command's own output.
21882This can also be requested by invoking @value{GDBN} with the
21883@option{--statistics} command-line switch (@pxref{Mode Options}).
21884
21885@kindex maint translate-address
21886@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
21887Find the symbol stored at the location specified by the address
21888@var{addr} and an optional section name @var{section}. If found,
21889@value{GDBN} prints the name of the closest symbol and an offset from
21890the symbol's location to the specified address. This is similar to
21891the @code{info address} command (@pxref{Symbols}), except that this
21892command also allows to find symbols in other sections.
ae038cb0 21893
8e04817f 21894@end table
c906108c 21895
9c16f35a
EZ
21896The following command is useful for non-interactive invocations of
21897@value{GDBN}, such as in the test suite.
21898
21899@table @code
21900@item set watchdog @var{nsec}
21901@kindex set watchdog
21902@cindex watchdog timer
21903@cindex timeout for commands
21904Set the maximum number of seconds @value{GDBN} will wait for the
21905target operation to finish. If this time expires, @value{GDBN}
21906reports and error and the command is aborted.
21907
21908@item show watchdog
21909Show the current setting of the target wait timeout.
21910@end table
c906108c 21911
e0ce93ac 21912@node Remote Protocol
8e04817f 21913@appendix @value{GDBN} Remote Serial Protocol
c906108c 21914
ee2d5c50
AC
21915@menu
21916* Overview::
21917* Packets::
21918* Stop Reply Packets::
21919* General Query Packets::
21920* Register Packet Format::
21921* Examples::
0ce1b118 21922* File-I/O remote protocol extension::
ee2d5c50
AC
21923@end menu
21924
21925@node Overview
21926@section Overview
21927
8e04817f
AC
21928There may be occasions when you need to know something about the
21929protocol---for example, if there is only one serial port to your target
21930machine, you might want your program to do something special if it
21931recognizes a packet meant for @value{GDBN}.
c906108c 21932
d2c6833e 21933In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 21934transmitted and received data respectfully.
c906108c 21935
8e04817f
AC
21936@cindex protocol, @value{GDBN} remote serial
21937@cindex serial protocol, @value{GDBN} remote
21938@cindex remote serial protocol
21939All @value{GDBN} commands and responses (other than acknowledgments) are
21940sent as a @var{packet}. A @var{packet} is introduced with the character
21941@samp{$}, the actual @var{packet-data}, and the terminating character
21942@samp{#} followed by a two-digit @var{checksum}:
c906108c 21943
474c8240 21944@smallexample
8e04817f 21945@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 21946@end smallexample
8e04817f 21947@noindent
c906108c 21948
8e04817f
AC
21949@cindex checksum, for @value{GDBN} remote
21950@noindent
21951The two-digit @var{checksum} is computed as the modulo 256 sum of all
21952characters between the leading @samp{$} and the trailing @samp{#} (an
21953eight bit unsigned checksum).
c906108c 21954
8e04817f
AC
21955Implementors should note that prior to @value{GDBN} 5.0 the protocol
21956specification also included an optional two-digit @var{sequence-id}:
c906108c 21957
474c8240 21958@smallexample
8e04817f 21959@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 21960@end smallexample
c906108c 21961
8e04817f
AC
21962@cindex sequence-id, for @value{GDBN} remote
21963@noindent
21964That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
21965has never output @var{sequence-id}s. Stubs that handle packets added
21966since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 21967
8e04817f
AC
21968@cindex acknowledgment, for @value{GDBN} remote
21969When either the host or the target machine receives a packet, the first
21970response expected is an acknowledgment: either @samp{+} (to indicate
21971the package was received correctly) or @samp{-} (to request
21972retransmission):
c906108c 21973
474c8240 21974@smallexample
d2c6833e
AC
21975-> @code{$}@var{packet-data}@code{#}@var{checksum}
21976<- @code{+}
474c8240 21977@end smallexample
8e04817f 21978@noindent
53a5351d 21979
8e04817f
AC
21980The host (@value{GDBN}) sends @var{command}s, and the target (the
21981debugging stub incorporated in your program) sends a @var{response}. In
21982the case of step and continue @var{command}s, the response is only sent
21983when the operation has completed (the target has again stopped).
c906108c 21984
8e04817f
AC
21985@var{packet-data} consists of a sequence of characters with the
21986exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
21987exceptions).
c906108c 21988
8e04817f 21989Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 21990@cindex remote protocol, field separator
8e04817f 21991@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 21992@sc{hex} with leading zeros suppressed.
c906108c 21993
8e04817f
AC
21994Implementors should note that prior to @value{GDBN} 5.0, the character
21995@samp{:} could not appear as the third character in a packet (as it
21996would potentially conflict with the @var{sequence-id}).
c906108c 21997
8e04817f
AC
21998Response @var{data} can be run-length encoded to save space. A @samp{*}
21999means that the next character is an @sc{ascii} encoding giving a repeat count
22000which stands for that many repetitions of the character preceding the
22001@samp{*}. The encoding is @code{n+29}, yielding a printable character
22002where @code{n >=3} (which is where rle starts to win). The printable
22003characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
22004value greater than 126 should not be used.
c906108c 22005
8e04817f 22006So:
474c8240 22007@smallexample
8e04817f 22008"@code{0* }"
474c8240 22009@end smallexample
8e04817f
AC
22010@noindent
22011means the same as "0000".
c906108c 22012
8e04817f
AC
22013The error response returned for some packets includes a two character
22014error number. That number is not well defined.
c906108c 22015
8e04817f
AC
22016For any @var{command} not supported by the stub, an empty response
22017(@samp{$#00}) should be returned. That way it is possible to extend the
22018protocol. A newer @value{GDBN} can tell if a packet is supported based
22019on that response.
c906108c 22020
b383017d
RM
22021A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
22022@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 22023optional.
c906108c 22024
ee2d5c50
AC
22025@node Packets
22026@section Packets
22027
22028The following table provides a complete list of all currently defined
22029@var{command}s and their corresponding response @var{data}.
9c16f35a
EZ
22030@xref{File-I/O remote protocol extension}, for details about the File
22031I/O extension of the remote protocol.
ee2d5c50
AC
22032
22033@table @r
22034
22035@item @code{!} --- extended mode
22036@cindex @code{!} packet
22037
8e04817f
AC
22038Enable extended mode. In extended mode, the remote server is made
22039persistent. The @samp{R} packet is used to restart the program being
22040debugged.
ee2d5c50
AC
22041
22042Reply:
22043@table @samp
22044@item OK
8e04817f 22045The remote target both supports and has enabled extended mode.
ee2d5c50 22046@end table
c906108c 22047
ee2d5c50
AC
22048@item @code{?} --- last signal
22049@cindex @code{?} packet
c906108c 22050
ee2d5c50
AC
22051Indicate the reason the target halted. The reply is the same as for
22052step and continue.
c906108c 22053
ee2d5c50
AC
22054Reply:
22055@xref{Stop Reply Packets}, for the reply specifications.
22056
22057@item @code{a} --- reserved
22058
22059Reserved for future use.
22060
22061@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
22062@cindex @code{A} packet
c906108c 22063
8e04817f
AC
22064Initialized @samp{argv[]} array passed into program. @var{arglen}
22065specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
22066See @code{gdbserver} for more details.
22067
22068Reply:
22069@table @samp
22070@item OK
22071@item E@var{NN}
22072@end table
22073
22074@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
22075@cindex @code{b} packet
22076
22077Change the serial line speed to @var{baud}.
22078
22079JTC: @emph{When does the transport layer state change? When it's
22080received, or after the ACK is transmitted. In either case, there are
22081problems if the command or the acknowledgment packet is dropped.}
22082
22083Stan: @emph{If people really wanted to add something like this, and get
22084it working for the first time, they ought to modify ser-unix.c to send
22085some kind of out-of-band message to a specially-setup stub and have the
22086switch happen "in between" packets, so that from remote protocol's point
22087of view, nothing actually happened.}
22088
22089@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
22090@cindex @code{B} packet
22091
8e04817f 22092Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
22093breakpoint at @var{addr}.
22094
22095This packet has been replaced by the @samp{Z} and @samp{z} packets
22096(@pxref{insert breakpoint or watchpoint packet}).
c906108c 22097
ee2d5c50
AC
22098@item @code{c}@var{addr} --- continue
22099@cindex @code{c} packet
22100
22101@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 22102current address.
c906108c 22103
ee2d5c50
AC
22104Reply:
22105@xref{Stop Reply Packets}, for the reply specifications.
22106
22107@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
22108@cindex @code{C} packet
22109
8e04817f
AC
22110Continue with signal @var{sig} (hex signal number). If
22111@code{;}@var{addr} is omitted, resume at same address.
c906108c 22112
ee2d5c50
AC
22113Reply:
22114@xref{Stop Reply Packets}, for the reply specifications.
c906108c 22115
ee2d5c50
AC
22116@item @code{d} --- toggle debug @strong{(deprecated)}
22117@cindex @code{d} packet
22118
22119Toggle debug flag.
22120
22121@item @code{D} --- detach
22122@cindex @code{D} packet
22123
22124Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 22125before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
22126
22127Reply:
22128@table @samp
10fac096
NW
22129@item OK
22130for success
22131@item E@var{NN}
22132for an error
ee2d5c50 22133@end table
c906108c 22134
ee2d5c50 22135@item @code{e} --- reserved
c906108c 22136
ee2d5c50 22137Reserved for future use.
c906108c 22138
ee2d5c50 22139@item @code{E} --- reserved
c906108c 22140
ee2d5c50 22141Reserved for future use.
c906108c 22142
ee2d5c50
AC
22143@item @code{f} --- reserved
22144
22145Reserved for future use.
22146
0ce1b118
CV
22147@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
22148@cindex @code{F} packet
ee2d5c50 22149
0ce1b118
CV
22150This packet is send by @value{GDBN} as reply to a @code{F} request packet
22151sent by the target. This is part of the File-I/O protocol extension.
22152@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
22153
22154@item @code{g} --- read registers
22155@anchor{read registers packet}
22156@cindex @code{g} packet
22157
22158Read general registers.
22159
22160Reply:
22161@table @samp
22162@item @var{XX@dots{}}
8e04817f
AC
22163Each byte of register data is described by two hex digits. The bytes
22164with the register are transmitted in target byte order. The size of
22165each register and their position within the @samp{g} @var{packet} are
12c266ea
AC
22166determined by the @value{GDBN} internal macros
22167@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
22168specification of several standard @code{g} packets is specified below.
ee2d5c50
AC
22169@item E@var{NN}
22170for an error.
22171@end table
c906108c 22172
ee2d5c50
AC
22173@item @code{G}@var{XX@dots{}} --- write regs
22174@cindex @code{G} packet
c906108c 22175
ee2d5c50
AC
22176@xref{read registers packet}, for a description of the @var{XX@dots{}}
22177data.
22178
22179Reply:
22180@table @samp
22181@item OK
22182for success
22183@item E@var{NN}
22184for an error
22185@end table
22186
22187@item @code{h} --- reserved
22188
22189Reserved for future use.
22190
b383017d 22191@item @code{H}@var{c}@var{t@dots{}} --- set thread
ee2d5c50 22192@cindex @code{H} packet
c906108c 22193
8e04817f 22194Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
22195@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
22196should be @samp{c} for step and continue operations, @samp{g} for other
22197operations. The thread designator @var{t@dots{}} may be -1, meaning all
22198the threads, a thread number, or zero which means pick any thread.
22199
22200Reply:
22201@table @samp
22202@item OK
22203for success
22204@item E@var{NN}
22205for an error
22206@end table
c906108c 22207
8e04817f
AC
22208@c FIXME: JTC:
22209@c 'H': How restrictive (or permissive) is the thread model. If a
22210@c thread is selected and stopped, are other threads allowed
22211@c to continue to execute? As I mentioned above, I think the
22212@c semantics of each command when a thread is selected must be
22213@c described. For example:
22214@c
22215@c 'g': If the stub supports threads and a specific thread is
22216@c selected, returns the register block from that thread;
22217@c otherwise returns current registers.
22218@c
22219@c 'G' If the stub supports threads and a specific thread is
22220@c selected, sets the registers of the register block of
22221@c that thread; otherwise sets current registers.
c906108c 22222
ee2d5c50
AC
22223@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
22224@anchor{cycle step packet}
22225@cindex @code{i} packet
22226
8e04817f
AC
22227Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
22228present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
22229step starting at that address.
c906108c 22230
ee2d5c50
AC
22231@item @code{I} --- signal then cycle step @strong{(reserved)}
22232@cindex @code{I} packet
22233
22234@xref{step with signal packet}. @xref{cycle step packet}.
22235
22236@item @code{j} --- reserved
22237
22238Reserved for future use.
22239
22240@item @code{J} --- reserved
c906108c 22241
ee2d5c50 22242Reserved for future use.
c906108c 22243
ee2d5c50
AC
22244@item @code{k} --- kill request
22245@cindex @code{k} packet
c906108c 22246
ac282366 22247FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
22248thread context has been selected (i.e.@: does 'k' kill only that
22249thread?)}.
c906108c 22250
ee2d5c50 22251@item @code{K} --- reserved
c906108c 22252
ee2d5c50
AC
22253Reserved for future use.
22254
22255@item @code{l} --- reserved
22256
22257Reserved for future use.
22258
22259@item @code{L} --- reserved
22260
22261Reserved for future use.
22262
22263@item @code{m}@var{addr}@code{,}@var{length} --- read memory
22264@cindex @code{m} packet
c906108c 22265
8e04817f 22266Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 22267Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 22268assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 22269transfer mechanism is needed.}
c906108c 22270
ee2d5c50
AC
22271Reply:
22272@table @samp
22273@item @var{XX@dots{}}
22274@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
22275to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 22276that sized memory transfers are assumed using word aligned
ee2d5c50
AC
22277accesses. FIXME: @emph{A word aligned memory transfer mechanism is
22278needed.}
22279@item E@var{NN}
22280@var{NN} is errno
22281@end table
22282
22283@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
22284@cindex @code{M} packet
22285
8e04817f 22286Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
22287@var{XX@dots{}} is the data.
22288
22289Reply:
22290@table @samp
22291@item OK
22292for success
22293@item E@var{NN}
8e04817f
AC
22294for an error (this includes the case where only part of the data was
22295written).
ee2d5c50 22296@end table
c906108c 22297
ee2d5c50 22298@item @code{n} --- reserved
c906108c 22299
ee2d5c50 22300Reserved for future use.
c906108c 22301
ee2d5c50 22302@item @code{N} --- reserved
c906108c 22303
ee2d5c50 22304Reserved for future use.
c906108c 22305
ee2d5c50
AC
22306@item @code{o} --- reserved
22307
22308Reserved for future use.
22309
22310@item @code{O} --- reserved
22311
2e868123 22312@item @code{p}@var{hex number of register} --- read register packet
ee2d5c50
AC
22313@cindex @code{p} packet
22314
2e868123
AC
22315@xref{read registers packet}, for a description of how the returned
22316register value is encoded.
ee2d5c50
AC
22317
22318Reply:
22319@table @samp
2e868123
AC
22320@item @var{XX@dots{}}
22321the register's value
22322@item E@var{NN}
22323for an error
22324@item
22325Indicating an unrecognized @var{query}.
ee2d5c50
AC
22326@end table
22327
22328@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
22329@anchor{write register packet}
22330@cindex @code{P} packet
22331
22332Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 22333digits for each byte in the register (target byte order).
c906108c 22334
ee2d5c50
AC
22335Reply:
22336@table @samp
22337@item OK
22338for success
22339@item E@var{NN}
22340for an error
22341@end table
22342
22343@item @code{q}@var{query} --- general query
22344@anchor{general query packet}
22345@cindex @code{q} packet
22346
22347Request info about @var{query}. In general @value{GDBN} queries have a
22348leading upper case letter. Custom vendor queries should use a company
22349prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
22350be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
22351that they match the full @var{query} name.
22352
22353Reply:
22354@table @samp
22355@item @var{XX@dots{}}
22356Hex encoded data from query. The reply can not be empty.
22357@item E@var{NN}
22358error reply
8e04817f 22359@item
ee2d5c50
AC
22360Indicating an unrecognized @var{query}.
22361@end table
22362
22363@item @code{Q}@var{var}@code{=}@var{val} --- general set
22364@cindex @code{Q} packet
22365
22366Set value of @var{var} to @var{val}.
22367
22368@xref{general query packet}, for a discussion of naming conventions.
c906108c 22369
ee2d5c50
AC
22370@item @code{r} --- reset @strong{(deprecated)}
22371@cindex @code{r} packet
c906108c 22372
8e04817f 22373Reset the entire system.
c906108c 22374
ee2d5c50
AC
22375@item @code{R}@var{XX} --- remote restart
22376@cindex @code{R} packet
22377
8e04817f
AC
22378Restart the program being debugged. @var{XX}, while needed, is ignored.
22379This packet is only available in extended mode.
ee2d5c50
AC
22380
22381Reply:
22382@table @samp
22383@item @emph{no reply}
8e04817f 22384The @samp{R} packet has no reply.
ee2d5c50
AC
22385@end table
22386
22387@item @code{s}@var{addr} --- step
22388@cindex @code{s} packet
c906108c 22389
8e04817f
AC
22390@var{addr} is address to resume. If @var{addr} is omitted, resume at
22391same address.
c906108c 22392
ee2d5c50
AC
22393Reply:
22394@xref{Stop Reply Packets}, for the reply specifications.
22395
22396@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
22397@anchor{step with signal packet}
22398@cindex @code{S} packet
22399
8e04817f 22400Like @samp{C} but step not continue.
c906108c 22401
ee2d5c50
AC
22402Reply:
22403@xref{Stop Reply Packets}, for the reply specifications.
22404
b383017d 22405@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
ee2d5c50
AC
22406@cindex @code{t} packet
22407
8e04817f 22408Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
22409@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
22410@var{addr} must be at least 3 digits.
c906108c 22411
ee2d5c50
AC
22412@item @code{T}@var{XX} --- thread alive
22413@cindex @code{T} packet
c906108c 22414
ee2d5c50 22415Find out if the thread XX is alive.
c906108c 22416
ee2d5c50
AC
22417Reply:
22418@table @samp
22419@item OK
22420thread is still alive
22421@item E@var{NN}
22422thread is dead
22423@end table
22424
22425@item @code{u} --- reserved
22426
22427Reserved for future use.
22428
22429@item @code{U} --- reserved
22430
22431Reserved for future use.
22432
86d30acc 22433@item @code{v} --- verbose packet prefix
ee2d5c50 22434
86d30acc
DJ
22435Packets starting with @code{v} are identified by a multi-letter name,
22436up to the first @code{;} or @code{?} (or the end of the packet).
22437
22438@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
22439@cindex @code{vCont} packet
22440
22441Resume the inferior. Different actions may be specified for each thread.
22442If an action is specified with no @var{tid}, then it is applied to any
22443threads that don't have a specific action specified; if no default action is
22444specified then other threads should remain stopped. Specifying multiple
22445default actions is an error; specifying no actions is also an error.
22446Thread IDs are specified in hexadecimal. Currently supported actions are:
22447
22448@table @code
22449@item c
22450Continue.
22451@item C@var{sig}
22452Continue with signal @var{sig}. @var{sig} should be two hex digits.
22453@item s
22454Step.
22455@item S@var{sig}
22456Step with signal @var{sig}. @var{sig} should be two hex digits.
22457@end table
22458
22459The optional @var{addr} argument normally associated with these packets is
22460not supported in @code{vCont}.
22461
22462Reply:
22463@xref{Stop Reply Packets}, for the reply specifications.
22464
22465@item @code{vCont?} --- extended resume query
22466@cindex @code{vCont?} packet
22467
22468Query support for the @code{vCont} packet.
22469
22470Reply:
22471@table @samp
22472@item @code{vCont}[;@var{action}]...
22473The @code{vCont} packet is supported. Each @var{action} is a supported
22474command in the @code{vCont} packet.
22475@item
22476The @code{vCont} packet is not supported.
22477@end table
ee2d5c50
AC
22478
22479@item @code{V} --- reserved
c906108c 22480
ee2d5c50 22481Reserved for future use.
c906108c 22482
ee2d5c50 22483@item @code{w} --- reserved
c906108c 22484
ee2d5c50 22485Reserved for future use.
c906108c 22486
ee2d5c50 22487@item @code{W} --- reserved
c906108c 22488
ee2d5c50 22489Reserved for future use.
c906108c 22490
ee2d5c50
AC
22491@item @code{x} --- reserved
22492
22493Reserved for future use.
22494
22495@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
22496@cindex @code{X} packet
22497
22498@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
22499is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
69065f5d
AC
22500escaped using @code{0x7d}, and then XORed with @code{0x20}.
22501For example, @code{0x7d} would be transmitted as @code{0x7d 0x5d}.
c906108c 22502
ee2d5c50
AC
22503Reply:
22504@table @samp
22505@item OK
22506for success
22507@item E@var{NN}
22508for an error
22509@end table
22510
22511@item @code{y} --- reserved
c906108c 22512
ee2d5c50 22513Reserved for future use.
c906108c 22514
ee2d5c50
AC
22515@item @code{Y} reserved
22516
22517Reserved for future use.
22518
2f870471
AC
22519@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
22520@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
22521@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 22522@cindex @code{z} packet
2f870471 22523@cindex @code{Z} packets
ee2d5c50 22524
2f870471
AC
22525Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
22526watchpoint starting at address @var{address} and covering the next
22527@var{length} bytes.
ee2d5c50 22528
2f870471
AC
22529Each breakpoint and watchpoint packet @var{type} is documented
22530separately.
22531
512217c7
AC
22532@emph{Implementation notes: A remote target shall return an empty string
22533for an unrecognized breakpoint or watchpoint packet @var{type}. A
22534remote target shall support either both or neither of a given
2f870471
AC
22535@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
22536avoid potential problems with duplicate packets, the operations should
22537be implemented in an idempotent way.}
22538
22539@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
22540@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
22541@cindex @code{z0} packet
22542@cindex @code{Z0} packet
22543
22544Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
22545@code{addr} of size @code{length}.
22546
22547A memory breakpoint is implemented by replacing the instruction at
22548@var{addr} with a software breakpoint or trap instruction. The
22549@code{length} is used by targets that indicates the size of the
22550breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
22551@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 22552
2f870471
AC
22553@emph{Implementation note: It is possible for a target to copy or move
22554code that contains memory breakpoints (e.g., when implementing
22555overlays). The behavior of this packet, in the presence of such a
22556target, is not defined.}
c906108c 22557
ee2d5c50
AC
22558Reply:
22559@table @samp
2f870471
AC
22560@item OK
22561success
22562@item
22563not supported
ee2d5c50
AC
22564@item E@var{NN}
22565for an error
2f870471
AC
22566@end table
22567
22568@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
22569@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
22570@cindex @code{z1} packet
22571@cindex @code{Z1} packet
22572
22573Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
22574address @code{addr} of size @code{length}.
22575
22576A hardware breakpoint is implemented using a mechanism that is not
22577dependant on being able to modify the target's memory.
22578
22579@emph{Implementation note: A hardware breakpoint is not affected by code
22580movement.}
22581
22582Reply:
22583@table @samp
ee2d5c50 22584@item OK
2f870471
AC
22585success
22586@item
22587not supported
22588@item E@var{NN}
22589for an error
22590@end table
22591
22592@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
22593@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
22594@cindex @code{z2} packet
22595@cindex @code{Z2} packet
22596
22597Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
22598
22599Reply:
22600@table @samp
22601@item OK
22602success
22603@item
22604not supported
22605@item E@var{NN}
22606for an error
22607@end table
22608
22609@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
22610@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
22611@cindex @code{z3} packet
22612@cindex @code{Z3} packet
22613
2e834e49 22614Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
22615
22616Reply:
22617@table @samp
22618@item OK
22619success
22620@item
22621not supported
22622@item E@var{NN}
22623for an error
22624@end table
22625
2e834e49
HPN
22626@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
22627@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
22628@cindex @code{z4} packet
22629@cindex @code{Z4} packet
22630
22631Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
22632
22633Reply:
22634@table @samp
22635@item OK
22636success
22637@item
22638not supported
22639@item E@var{NN}
22640for an error
ee2d5c50
AC
22641@end table
22642
22643@end table
c906108c 22644
ee2d5c50
AC
22645@node Stop Reply Packets
22646@section Stop Reply Packets
22647@cindex stop reply packets
c906108c 22648
8e04817f
AC
22649The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
22650receive any of the below as a reply. In the case of the @samp{C},
22651@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
22652when the target halts. In the below the exact meaning of @samp{signal
22653number} is poorly defined. In general one of the UNIX signal numbering
22654conventions is used.
c906108c 22655
ee2d5c50 22656@table @samp
c906108c 22657
ee2d5c50
AC
22658@item S@var{AA}
22659@var{AA} is the signal number
c906108c 22660
8e04817f 22661@item @code{T}@var{AA}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}
ee2d5c50
AC
22662@cindex @code{T} packet reply
22663
8e04817f
AC
22664@var{AA} = two hex digit signal number; @var{n...} = register number
22665(hex), @var{r...} = target byte ordered register contents, size defined
12c266ea
AC
22666by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
22667@var{r...} = thread process ID, this is a hex integer; @var{n...} =
22668(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
22669address, this is a hex integer; @var{n...} = other string not starting
22670with valid hex digit. @value{GDBN} should ignore this @var{n...},
22671@var{r...} pair and go on to the next. This way we can extend the
22672protocol.
c906108c 22673
ee2d5c50
AC
22674@item W@var{AA}
22675
8e04817f 22676The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
22677applicable to certain targets.
22678
22679@item X@var{AA}
c906108c 22680
8e04817f 22681The process terminated with signal @var{AA}.
c906108c 22682
ee2d5c50 22683@item O@var{XX@dots{}}
c906108c 22684
ee2d5c50
AC
22685@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
22686any time while the program is running and the debugger should continue
22687to wait for @samp{W}, @samp{T}, etc.
22688
0ce1b118
CV
22689@item F@var{call-id}@code{,}@var{parameter@dots{}}
22690
22691@var{call-id} is the identifier which says which host system call should
22692be called. This is just the name of the function. Translation into the
22693correct system call is only applicable as it's defined in @value{GDBN}.
22694@xref{File-I/O remote protocol extension}, for a list of implemented
22695system calls.
22696
22697@var{parameter@dots{}} is a list of parameters as defined for this very
22698system call.
22699
22700The target replies with this packet when it expects @value{GDBN} to call
22701a host system call on behalf of the target. @value{GDBN} replies with
22702an appropriate @code{F} packet and keeps up waiting for the next reply
22703packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
22704@samp{s} action is expected to be continued.
22705@xref{File-I/O remote protocol extension}, for more details.
22706
ee2d5c50
AC
22707@end table
22708
22709@node General Query Packets
22710@section General Query Packets
9c16f35a 22711@cindex remote query requests
c906108c 22712
8e04817f 22713The following set and query packets have already been defined.
c906108c 22714
ee2d5c50 22715@table @r
c906108c 22716
ee2d5c50 22717@item @code{q}@code{C} --- current thread
9c16f35a
EZ
22718@cindex current thread, remote request
22719@cindex @code{qC} packet
ee2d5c50
AC
22720Return the current thread id.
22721
22722Reply:
22723@table @samp
22724@item @code{QC}@var{pid}
e1aac25b 22725Where @var{pid} is an unsigned hexidecimal process id.
ee2d5c50
AC
22726@item *
22727Any other reply implies the old pid.
22728@end table
22729
22730@item @code{q}@code{fThreadInfo} -- all thread ids
9c16f35a
EZ
22731@cindex list active threads, remote request
22732@cindex @code{qfThreadInfo} packet
ee2d5c50 22733@code{q}@code{sThreadInfo}
c906108c 22734
8e04817f
AC
22735Obtain a list of active thread ids from the target (OS). Since there
22736may be too many active threads to fit into one reply packet, this query
22737works iteratively: it may require more than one query/reply sequence to
22738obtain the entire list of threads. The first query of the sequence will
22739be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
22740sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
22741
22742NOTE: replaces the @code{qL} query (see below).
22743
22744Reply:
22745@table @samp
22746@item @code{m}@var{id}
22747A single thread id
22748@item @code{m}@var{id},@var{id}@dots{}
22749a comma-separated list of thread ids
22750@item @code{l}
22751(lower case 'el') denotes end of list.
22752@end table
22753
22754In response to each query, the target will reply with a list of one or
e1aac25b
JB
22755more thread ids, in big-endian unsigned hex, separated by commas.
22756@value{GDBN} will respond to each reply with a request for more thread
22757ids (using the @code{qs} form of the query), until the target responds
22758with @code{l} (lower-case el, for @code{'last'}).
c906108c 22759
ee2d5c50 22760@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
9c16f35a
EZ
22761@cindex thread attributes info, remote request
22762@cindex @code{qThreadExtraInfo} packet
ee2d5c50
AC
22763Where @var{id} is a thread-id in big-endian hex. Obtain a printable
22764string description of a thread's attributes from the target OS. This
22765string may contain anything that the target OS thinks is interesting for
22766@value{GDBN} to tell the user about the thread. The string is displayed
22767in @value{GDBN}'s @samp{info threads} display. Some examples of
22768possible thread extra info strings are ``Runnable'', or ``Blocked on
22769Mutex''.
22770
22771Reply:
22772@table @samp
22773@item @var{XX@dots{}}
22774Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
22775the printable string containing the extra information about the thread's
8e04817f 22776attributes.
ee2d5c50
AC
22777@end table
22778
22779@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 22780
8e04817f
AC
22781Obtain thread information from RTOS. Where: @var{startflag} (one hex
22782digit) is one to indicate the first query and zero to indicate a
22783subsequent query; @var{threadcount} (two hex digits) is the maximum
22784number of threads the response packet can contain; and @var{nextthread}
22785(eight hex digits), for subsequent queries (@var{startflag} is zero), is
22786returned in the response as @var{argthread}.
ee2d5c50
AC
22787
22788NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
22789(see above).
22790
22791Reply:
22792@table @samp
22793@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
22794Where: @var{count} (two hex digits) is the number of threads being
22795returned; @var{done} (one hex digit) is zero to indicate more threads
22796and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
22797digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
22798is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 22799digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 22800@end table
c906108c 22801
ee2d5c50 22802@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
9c16f35a
EZ
22803@cindex CRC of memory block, remote request
22804@cindex @code{qCRC} packet
ee2d5c50
AC
22805Reply:
22806@table @samp
22807@item @code{E}@var{NN}
22808An error (such as memory fault)
22809@item @code{C}@var{CRC32}
22810A 32 bit cyclic redundancy check of the specified memory region.
22811@end table
22812
22813@item @code{q}@code{Offsets} --- query sect offs
9c16f35a
EZ
22814@cindex section offsets, remote request
22815@cindex @code{qOffsets} packet
8e04817f
AC
22816Get section offsets that the target used when re-locating the downloaded
22817image. @emph{Note: while a @code{Bss} offset is included in the
22818response, @value{GDBN} ignores this and instead applies the @code{Data}
22819offset to the @code{Bss} section.}
c906108c 22820
ee2d5c50
AC
22821Reply:
22822@table @samp
22823@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
22824@end table
22825
22826@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
9c16f35a
EZ
22827@cindex thread information, remote request
22828@cindex @code{qP} packet
8e04817f
AC
22829Returns information on @var{threadid}. Where: @var{mode} is a hex
22830encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
22831
22832Reply:
22833@table @samp
22834@item *
22835@end table
22836
8e04817f 22837See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 22838
ee2d5c50 22839@item @code{q}@code{Rcmd,}@var{command} --- remote command
9c16f35a
EZ
22840@cindex execute remote command, remote request
22841@cindex @code{qRcmd} packet
ee2d5c50 22842@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
22843execution. Invalid commands should be reported using the output string.
22844Before the final result packet, the target may also respond with a
ee2d5c50
AC
22845number of intermediate @code{O}@var{output} console output packets.
22846@emph{Implementors should note that providing access to a stubs's
22847interpreter may have security implications}.
22848
22849Reply:
22850@table @samp
22851@item OK
8e04817f 22852A command response with no output.
ee2d5c50 22853@item @var{OUTPUT}
8e04817f 22854A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 22855@item @code{E}@var{NN}
8e04817f 22856Indicate a badly formed request.
ee2d5c50 22857@item @samp{}
8e04817f 22858When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50 22859@end table
9c16f35a 22860z
ee2d5c50 22861@item @code{qSymbol::} --- symbol lookup
9c16f35a
EZ
22862@cindex symbol lookup, remote request
22863@cindex @code{qSymbol} packet
8e04817f
AC
22864Notify the target that @value{GDBN} is prepared to serve symbol lookup
22865requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
22866
22867Reply:
22868@table @samp
22869@item @code{OK}
8e04817f 22870The target does not need to look up any (more) symbols.
ee2d5c50
AC
22871@item @code{qSymbol:}@var{sym_name}
22872The target requests the value of symbol @var{sym_name} (hex encoded).
22873@value{GDBN} may provide the value by using the
22874@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
22875@end table
22876
22877@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
22878
22879Set the value of @var{sym_name} to @var{sym_value}.
22880
22881@var{sym_name} (hex encoded) is the name of a symbol whose value the
22882target has previously requested.
22883
22884@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
22885@value{GDBN} cannot supply a value for @var{sym_name}, then this field
22886will be empty.
22887
22888Reply:
22889@table @samp
22890@item @code{OK}
8e04817f 22891The target does not need to look up any (more) symbols.
ee2d5c50
AC
22892@item @code{qSymbol:}@var{sym_name}
22893The target requests the value of a new symbol @var{sym_name} (hex
22894encoded). @value{GDBN} will continue to supply the values of symbols
22895(if available), until the target ceases to request them.
22896@end table
eb12ee30 22897
649e03f6 22898@item @code{qPart}:@var{object}:@code{read}:@var{annex}:@var{offset},@var{length} --- read special data
9c16f35a
EZ
22899@cindex read special object, remote request
22900@cindex @code{qPart} packet
649e03f6
RM
22901Read uninterpreted bytes from the target's special data area
22902identified by the keyword @code{object}.
22903Request @var{length} bytes starting at @var{offset} bytes into the data.
22904The content and encoding of @var{annex} is specific to the object;
22905it can supply additional details about what data to access.
22906
22907Here are the specific requests of this form defined so far.
22908All @samp{@code{qPart}:@var{object}:@code{read}:@dots{}}
22909requests use the same reply formats, listed below.
22910
22911@table @asis
22912@item @code{qPart}:@code{auxv}:@code{read}::@var{offset},@var{length}
721c2651
EZ
22913Access the target's @dfn{auxiliary vector}. @xref{OS Information,
22914auxiliary vector}, and see @ref{Remote configuration,
22915read-aux-vector-packet}. Note @var{annex} must be empty.
649e03f6
RM
22916@end table
22917
22918Reply:
22919@table @asis
22920@item @code{OK}
22921The @var{offset} in the request is at the end of the data.
22922There is no more data to be read.
22923
22924@item @var{XX@dots{}}
22925Hex encoded data bytes read.
22926This may be fewer bytes than the @var{length} in the request.
22927
22928@item @code{E00}
22929The request was malformed, or @var{annex} was invalid.
22930
22931@item @code{E}@var{nn}
22932The offset was invalid, or there was an error encountered reading the data.
22933@var{nn} is a hex-encoded @code{errno} value.
22934
22935@item @code{""} (empty)
22936An empty reply indicates the @var{object} or @var{annex} string was not
22937recognized by the stub.
22938@end table
22939
22940@item @code{qPart}:@var{object}:@code{write}:@var{annex}:@var{offset}:@var{data@dots{}}
9c16f35a 22941@cindex write data into object, remote request
649e03f6
RM
22942Write uninterpreted bytes into the target's special data area
22943identified by the keyword @code{object},
22944starting at @var{offset} bytes into the data.
22945@var{data@dots{}} is the hex-encoded data to be written.
22946The content and encoding of @var{annex} is specific to the object;
22947it can supply additional details about what data to access.
22948
22949No requests of this form are presently in use. This specification
22950serves as a placeholder to document the common format that new
22951specific request specifications ought to use.
22952
22953Reply:
22954@table @asis
22955@item @var{nn}
22956@var{nn} (hex encoded) is the number of bytes written.
22957This may be fewer bytes than supplied in the request.
22958
22959@item @code{E00}
22960The request was malformed, or @var{annex} was invalid.
22961
22962@item @code{E}@var{nn}
22963The offset was invalid, or there was an error encountered writing the data.
22964@var{nn} is a hex-encoded @code{errno} value.
22965
22966@item @code{""} (empty)
22967An empty reply indicates the @var{object} or @var{annex} string was not
22968recognized by the stub, or that the object does not support writing.
22969@end table
22970
22971@item @code{qPart}:@var{object}:@var{operation}:@dots{}
22972Requests of this form may be added in the future. When a stub does
22973not recognize the @var{object} keyword, or its support for
22974@var{object} does not recognize the @var{operation} keyword,
22975the stub must respond with an empty packet.
83761cbd
KB
22976
22977@item @code{qGetTLSAddr}:@var{thread-id},@var{offset},@var{lm} --- get thread local storage address
9c16f35a
EZ
22978@cindex get thread-local storage address, remote request
22979@cindex @code{qGetTLSAddr} packet
83761cbd
KB
22980Fetch the address associated with thread local storage specified
22981by @var{thread-id}, @var{offset}, and @var{lm}.
22982
22983@var{thread-id} is the (big endian, hex encoded) thread id associated with the
22984thread for which to fetch the TLS address.
22985
22986@var{offset} is the (big endian, hex encoded) offset associated with the
22987thread local variable. (This offset is obtained from the debug
22988information associated with the variable.)
22989
22990@var{lm} is the (big endian, hex encoded) OS/ABI specific encoding of the
22991the load module associated with the thread local storage. For example,
22992a @sc{gnu}/Linux system will pass the link map address of the shared
22993object associated with the thread local storage under consideration.
22994Other operating environments may choose to represent the load module
22995differently, so the precise meaning of this parameter will vary.
22996
22997Reply:
22998@table @asis
68c71a2e 22999@item @var{XX@dots{}}
83761cbd
KB
23000Hex encoded (big endian) bytes representing the address of the thread
23001local storage requested.
23002
23003@item @code{E}@var{nn} (where @var{nn} are hex digits)
23004An error occurred.
23005
23006@item @code{""} (empty)
23007An empty reply indicates that @code{qGetTLSAddr} is not supported by the stub.
23008@end table
23009
0abb7bc7
EZ
23010Use of this request packet is controlled by the @code{set remote
23011get-thread-local-storage-address} command (@pxref{Remote
23012configuration, set remote get-thread-local-storage-address}).
23013
ee2d5c50
AC
23014@end table
23015
23016@node Register Packet Format
23017@section Register Packet Format
eb12ee30 23018
8e04817f 23019The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
23020In the below, some thirty-two bit registers are transferred as
23021sixty-four bits. Those registers should be zero/sign extended (which?)
23022to fill the space allocated. Register bytes are transfered in target
23023byte order. The two nibbles within a register byte are transfered
23024most-significant - least-significant.
eb12ee30 23025
ee2d5c50 23026@table @r
eb12ee30 23027
8e04817f 23028@item MIPS32
ee2d5c50 23029
8e04817f
AC
23030All registers are transfered as thirty-two bit quantities in the order:
2303132 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
23032registers; fsr; fir; fp.
eb12ee30 23033
8e04817f 23034@item MIPS64
ee2d5c50 23035
8e04817f
AC
23036All registers are transfered as sixty-four bit quantities (including
23037thirty-two bit registers such as @code{sr}). The ordering is the same
23038as @code{MIPS32}.
eb12ee30 23039
ee2d5c50
AC
23040@end table
23041
23042@node Examples
23043@section Examples
eb12ee30 23044
8e04817f
AC
23045Example sequence of a target being re-started. Notice how the restart
23046does not get any direct output:
eb12ee30 23047
474c8240 23048@smallexample
d2c6833e
AC
23049-> @code{R00}
23050<- @code{+}
8e04817f 23051@emph{target restarts}
d2c6833e 23052-> @code{?}
8e04817f 23053<- @code{+}
d2c6833e
AC
23054<- @code{T001:1234123412341234}
23055-> @code{+}
474c8240 23056@end smallexample
eb12ee30 23057
8e04817f 23058Example sequence of a target being stepped by a single instruction:
eb12ee30 23059
474c8240 23060@smallexample
d2c6833e 23061-> @code{G1445@dots{}}
8e04817f 23062<- @code{+}
d2c6833e
AC
23063-> @code{s}
23064<- @code{+}
23065@emph{time passes}
23066<- @code{T001:1234123412341234}
8e04817f 23067-> @code{+}
d2c6833e 23068-> @code{g}
8e04817f 23069<- @code{+}
d2c6833e
AC
23070<- @code{1455@dots{}}
23071-> @code{+}
474c8240 23072@end smallexample
eb12ee30 23073
0ce1b118
CV
23074@node File-I/O remote protocol extension
23075@section File-I/O remote protocol extension
23076@cindex File-I/O remote protocol extension
23077
23078@menu
23079* File-I/O Overview::
23080* Protocol basics::
1d8b2f28
JB
23081* The F request packet::
23082* The F reply packet::
0ce1b118
CV
23083* Memory transfer::
23084* The Ctrl-C message::
23085* Console I/O::
23086* The isatty call::
23087* The system call::
23088* List of supported calls::
23089* Protocol specific representation of datatypes::
23090* Constants::
23091* File-I/O Examples::
23092@end menu
23093
23094@node File-I/O Overview
23095@subsection File-I/O Overview
23096@cindex file-i/o overview
23097
9c16f35a
EZ
23098The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
23099target to use the host's file system and console I/O when calling various
0ce1b118
CV
23100system calls. System calls on the target system are translated into a
23101remote protocol packet to the host system which then performs the needed
23102actions and returns with an adequate response packet to the target system.
23103This simulates file system operations even on targets that lack file systems.
23104
23105The protocol is defined host- and target-system independent. It uses
9c16f35a 23106its own independent representation of datatypes and values. Both,
0ce1b118
CV
23107@value{GDBN} and the target's @value{GDBN} stub are responsible for
23108translating the system dependent values into the unified protocol values
23109when data is transmitted.
23110
23111The communication is synchronous. A system call is possible only
23112when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
23113packets. While @value{GDBN} handles the request for a system call,
23114the target is stopped to allow deterministic access to the target's
23115memory. Therefore File-I/O is not interuptible by target signals. It
23116is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
23117
23118The target's request to perform a host system call does not finish
23119the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
23120after finishing the system call, the target returns to continuing the
23121previous activity (continue, step). No additional continue or step
23122request from @value{GDBN} is required.
23123
23124@smallexample
f7dc1244 23125(@value{GDBP}) continue
0ce1b118
CV
23126 <- target requests 'system call X'
23127 target is stopped, @value{GDBN} executes system call
23128 -> GDB returns result
23129 ... target continues, GDB returns to wait for the target
23130 <- target hits breakpoint and sends a Txx packet
23131@end smallexample
23132
23133The protocol is only used for files on the host file system and
23134for I/O on the console. Character or block special devices, pipes,
23135named pipes or sockets or any other communication method on the host
23136system are not supported by this protocol.
23137
23138@node Protocol basics
23139@subsection Protocol basics
23140@cindex protocol basics, file-i/o
23141
23142The File-I/O protocol uses the @code{F} packet, as request as well
23143as as reply packet. Since a File-I/O system call can only occur when
b383017d 23144@value{GDBN} is waiting for the continuing or stepping target, the
0ce1b118
CV
23145File-I/O request is a reply that @value{GDBN} has to expect as a result
23146of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
23147This @code{F} packet contains all information needed to allow @value{GDBN}
23148to call the appropriate host system call:
23149
23150@itemize @bullet
b383017d 23151@item
0ce1b118
CV
23152A unique identifier for the requested system call.
23153
23154@item
23155All parameters to the system call. Pointers are given as addresses
23156in the target memory address space. Pointers to strings are given as
b383017d 23157pointer/length pair. Numerical values are given as they are.
0ce1b118
CV
23158Numerical control values are given in a protocol specific representation.
23159
23160@end itemize
23161
23162At that point @value{GDBN} has to perform the following actions.
23163
23164@itemize @bullet
b383017d 23165@item
0ce1b118
CV
23166If parameter pointer values are given, which point to data needed as input
23167to a system call, @value{GDBN} requests this data from the target with a
23168standard @code{m} packet request. This additional communication has to be
23169expected by the target implementation and is handled as any other @code{m}
23170packet.
23171
23172@item
23173@value{GDBN} translates all value from protocol representation to host
23174representation as needed. Datatypes are coerced into the host types.
23175
23176@item
23177@value{GDBN} calls the system call
23178
23179@item
23180It then coerces datatypes back to protocol representation.
23181
23182@item
23183If pointer parameters in the request packet point to buffer space in which
23184a system call is expected to copy data to, the data is transmitted to the
23185target using a @code{M} or @code{X} packet. This packet has to be expected
23186by the target implementation and is handled as any other @code{M} or @code{X}
23187packet.
23188
23189@end itemize
23190
23191Eventually @value{GDBN} replies with another @code{F} packet which contains all
23192necessary information for the target to continue. This at least contains
23193
23194@itemize @bullet
23195@item
23196Return value.
23197
23198@item
23199@code{errno}, if has been changed by the system call.
23200
23201@item
23202``Ctrl-C'' flag.
23203
23204@end itemize
23205
23206After having done the needed type and value coercion, the target continues
23207the latest continue or step action.
23208
1d8b2f28 23209@node The F request packet
0ce1b118
CV
23210@subsection The @code{F} request packet
23211@cindex file-i/o request packet
23212@cindex @code{F} request packet
23213
23214The @code{F} request packet has the following format:
23215
23216@table @samp
23217
23218@smallexample
23219@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
23220@end smallexample
23221
23222@var{call-id} is the identifier to indicate the host system call to be called.
23223This is just the name of the function.
23224
23225@var{parameter@dots{}} are the parameters to the system call.
23226
b383017d 23227@end table
0ce1b118
CV
23228
23229Parameters are hexadecimal integer values, either the real values in case
23230of scalar datatypes, as pointers to target buffer space in case of compound
23231datatypes and unspecified memory areas or as pointer/length pairs in case
23232of string parameters. These are appended to the call-id, each separated
23233from its predecessor by a comma. All values are transmitted in ASCII
23234string representation, pointer/length pairs separated by a slash.
23235
1d8b2f28 23236@node The F reply packet
0ce1b118
CV
23237@subsection The @code{F} reply packet
23238@cindex file-i/o reply packet
23239@cindex @code{F} reply packet
23240
23241The @code{F} reply packet has the following format:
23242
23243@table @samp
23244
23245@smallexample
23246@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
23247@end smallexample
23248
23249@var{retcode} is the return code of the system call as hexadecimal value.
23250
23251@var{errno} is the errno set by the call, in protocol specific representation.
23252This parameter can be omitted if the call was successful.
23253
23254@var{Ctrl-C flag} is only send if the user requested a break. In this
23255case, @var{errno} must be send as well, even if the call was successful.
23256The @var{Ctrl-C flag} itself consists of the character 'C':
23257
23258@smallexample
23259F0,0,C
23260@end smallexample
23261
23262@noindent
23263or, if the call was interupted before the host call has been performed:
23264
23265@smallexample
23266F-1,4,C
23267@end smallexample
23268
23269@noindent
23270assuming 4 is the protocol specific representation of @code{EINTR}.
23271
23272@end table
23273
23274@node Memory transfer
23275@subsection Memory transfer
23276@cindex memory transfer, in file-i/o protocol
23277
23278Structured data which is transferred using a memory read or write as e.g.@:
23279a @code{struct stat} is expected to be in a protocol specific format with
23280all scalar multibyte datatypes being big endian. This should be done by
23281the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
23282it transfers memory to the target. Transferred pointers to structured
23283data should point to the already coerced data at any time.
23284
23285@node The Ctrl-C message
23286@subsection The Ctrl-C message
23287@cindex ctrl-c message, in file-i/o protocol
23288
23289A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
23290reply packet. In this case the target should behave, as if it had
23291gotten a break message. The meaning for the target is ``system call
23292interupted by @code{SIGINT}''. Consequentially, the target should actually stop
23293(as with a break message) and return to @value{GDBN} with a @code{T02}
b383017d 23294packet. In this case, it's important for the target to know, in which
0ce1b118
CV
23295state the system call was interrupted. Since this action is by design
23296not an atomic operation, we have to differ between two cases:
23297
23298@itemize @bullet
23299@item
23300The system call hasn't been performed on the host yet.
23301
23302@item
23303The system call on the host has been finished.
23304
23305@end itemize
23306
23307These two states can be distinguished by the target by the value of the
23308returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
23309call hasn't been performed. This is equivalent to the @code{EINTR} handling
23310on POSIX systems. In any other case, the target may presume that the
23311system call has been finished --- successful or not --- and should behave
23312as if the break message arrived right after the system call.
23313
23314@value{GDBN} must behave reliable. If the system call has not been called
23315yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
23316@code{errno} in the packet. If the system call on the host has been finished
23317before the user requests a break, the full action must be finshed by
23318@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
23319The @code{F} packet may only be send when either nothing has happened
23320or the full action has been completed.
23321
23322@node Console I/O
23323@subsection Console I/O
23324@cindex console i/o as part of file-i/o
23325
23326By default and if not explicitely closed by the target system, the file
23327descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
23328on the @value{GDBN} console is handled as any other file output operation
23329(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
23330by @value{GDBN} so that after the target read request from file descriptor
233310 all following typing is buffered until either one of the following
23332conditions is met:
23333
23334@itemize @bullet
23335@item
23336The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
23337@code{read}
23338system call is treated as finished.
23339
23340@item
23341The user presses @kbd{Enter}. This is treated as end of input with a trailing
23342line feed.
23343
23344@item
23345The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
23346character, especially no Ctrl-D is appended to the input.
23347
23348@end itemize
23349
23350If the user has typed more characters as fit in the buffer given to
23351the read call, the trailing characters are buffered in @value{GDBN} until
23352either another @code{read(0, @dots{})} is requested by the target or debugging
23353is stopped on users request.
23354
23355@node The isatty call
2eecc4ab 23356@subsection The @samp{isatty} function call
0ce1b118
CV
23357@cindex isatty call, file-i/o protocol
23358
23359A special case in this protocol is the library call @code{isatty} which
9c16f35a 23360is implemented as its own call inside of this protocol. It returns
0ce1b118
CV
233611 to the target if the file descriptor given as parameter is attached
23362to the @value{GDBN} console, 0 otherwise. Implementing through system calls
23363would require implementing @code{ioctl} and would be more complex than
23364needed.
23365
23366@node The system call
2eecc4ab 23367@subsection The @samp{system} function call
0ce1b118
CV
23368@cindex system call, file-i/o protocol
23369
23370The other special case in this protocol is the @code{system} call which
9c16f35a 23371is implemented as its own call, too. @value{GDBN} is taking over the full
0ce1b118
CV
23372task of calling the necessary host calls to perform the @code{system}
23373call. The return value of @code{system} is simplified before it's returned
23374to the target. Basically, the only signal transmitted back is @code{EINTR}
23375in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
23376entirely of the exit status of the called command.
23377
9c16f35a
EZ
23378Due to security concerns, the @code{system} call is by default refused
23379by @value{GDBN}. The user has to allow this call explicitly with the
23380@kbd{set remote system-call-allowed 1} command.
0ce1b118 23381
9c16f35a
EZ
23382@table @code
23383@item set remote system-call-allowed
23384@kindex set remote system-call-allowed
23385Control whether to allow the @code{system} calls in the File I/O
23386protocol for the remote target. The default is zero (disabled).
0ce1b118 23387
9c16f35a 23388@item show remote system-call-allowed
0ce1b118 23389@kindex show remote system-call-allowed
9c16f35a
EZ
23390Show the current setting of system calls for the remote File I/O
23391protocol.
0ce1b118
CV
23392@end table
23393
23394@node List of supported calls
23395@subsection List of supported calls
23396@cindex list of supported file-i/o calls
23397
23398@menu
23399* open::
23400* close::
23401* read::
23402* write::
23403* lseek::
23404* rename::
23405* unlink::
23406* stat/fstat::
23407* gettimeofday::
23408* isatty::
23409* system::
23410@end menu
23411
23412@node open
23413@unnumberedsubsubsec open
23414@cindex open, file-i/o system call
23415
23416@smallexample
23417@exdent Synopsis:
23418int open(const char *pathname, int flags);
23419int open(const char *pathname, int flags, mode_t mode);
23420
b383017d 23421@exdent Request:
0ce1b118
CV
23422Fopen,pathptr/len,flags,mode
23423@end smallexample
23424
23425@noindent
23426@code{flags} is the bitwise or of the following values:
23427
23428@table @code
b383017d 23429@item O_CREAT
0ce1b118
CV
23430If the file does not exist it will be created. The host
23431rules apply as far as file ownership and time stamps
23432are concerned.
23433
b383017d 23434@item O_EXCL
0ce1b118
CV
23435When used with O_CREAT, if the file already exists it is
23436an error and open() fails.
23437
b383017d 23438@item O_TRUNC
0ce1b118
CV
23439If the file already exists and the open mode allows
23440writing (O_RDWR or O_WRONLY is given) it will be
23441truncated to length 0.
23442
b383017d 23443@item O_APPEND
0ce1b118
CV
23444The file is opened in append mode.
23445
b383017d 23446@item O_RDONLY
0ce1b118
CV
23447The file is opened for reading only.
23448
b383017d 23449@item O_WRONLY
0ce1b118
CV
23450The file is opened for writing only.
23451
b383017d 23452@item O_RDWR
0ce1b118
CV
23453The file is opened for reading and writing.
23454
23455@noindent
23456Each other bit is silently ignored.
23457
23458@end table
23459
23460@noindent
23461@code{mode} is the bitwise or of the following values:
23462
23463@table @code
b383017d 23464@item S_IRUSR
0ce1b118
CV
23465User has read permission.
23466
b383017d 23467@item S_IWUSR
0ce1b118
CV
23468User has write permission.
23469
b383017d 23470@item S_IRGRP
0ce1b118
CV
23471Group has read permission.
23472
b383017d 23473@item S_IWGRP
0ce1b118
CV
23474Group has write permission.
23475
b383017d 23476@item S_IROTH
0ce1b118
CV
23477Others have read permission.
23478
b383017d 23479@item S_IWOTH
0ce1b118
CV
23480Others have write permission.
23481
23482@noindent
23483Each other bit is silently ignored.
23484
23485@end table
23486
23487@smallexample
23488@exdent Return value:
23489open returns the new file descriptor or -1 if an error
23490occured.
23491
23492@exdent Errors:
23493@end smallexample
23494
23495@table @code
b383017d 23496@item EEXIST
0ce1b118
CV
23497pathname already exists and O_CREAT and O_EXCL were used.
23498
b383017d 23499@item EISDIR
0ce1b118
CV
23500pathname refers to a directory.
23501
b383017d 23502@item EACCES
0ce1b118
CV
23503The requested access is not allowed.
23504
23505@item ENAMETOOLONG
23506pathname was too long.
23507
b383017d 23508@item ENOENT
0ce1b118
CV
23509A directory component in pathname does not exist.
23510
b383017d 23511@item ENODEV
0ce1b118
CV
23512pathname refers to a device, pipe, named pipe or socket.
23513
b383017d 23514@item EROFS
0ce1b118
CV
23515pathname refers to a file on a read-only filesystem and
23516write access was requested.
23517
b383017d 23518@item EFAULT
0ce1b118
CV
23519pathname is an invalid pointer value.
23520
b383017d 23521@item ENOSPC
0ce1b118
CV
23522No space on device to create the file.
23523
b383017d 23524@item EMFILE
0ce1b118
CV
23525The process already has the maximum number of files open.
23526
b383017d 23527@item ENFILE
0ce1b118
CV
23528The limit on the total number of files open on the system
23529has been reached.
23530
b383017d 23531@item EINTR
0ce1b118
CV
23532The call was interrupted by the user.
23533@end table
23534
23535@node close
23536@unnumberedsubsubsec close
23537@cindex close, file-i/o system call
23538
23539@smallexample
b383017d 23540@exdent Synopsis:
0ce1b118
CV
23541int close(int fd);
23542
b383017d 23543@exdent Request:
0ce1b118
CV
23544Fclose,fd
23545
23546@exdent Return value:
23547close returns zero on success, or -1 if an error occurred.
23548
23549@exdent Errors:
23550@end smallexample
23551
23552@table @code
b383017d 23553@item EBADF
0ce1b118
CV
23554fd isn't a valid open file descriptor.
23555
b383017d 23556@item EINTR
0ce1b118
CV
23557The call was interrupted by the user.
23558@end table
23559
23560@node read
23561@unnumberedsubsubsec read
23562@cindex read, file-i/o system call
23563
23564@smallexample
b383017d 23565@exdent Synopsis:
0ce1b118
CV
23566int read(int fd, void *buf, unsigned int count);
23567
b383017d 23568@exdent Request:
0ce1b118
CV
23569Fread,fd,bufptr,count
23570
23571@exdent Return value:
23572On success, the number of bytes read is returned.
23573Zero indicates end of file. If count is zero, read
b383017d 23574returns zero as well. On error, -1 is returned.
0ce1b118
CV
23575
23576@exdent Errors:
23577@end smallexample
23578
23579@table @code
b383017d 23580@item EBADF
0ce1b118
CV
23581fd is not a valid file descriptor or is not open for
23582reading.
23583
b383017d 23584@item EFAULT
0ce1b118
CV
23585buf is an invalid pointer value.
23586
b383017d 23587@item EINTR
0ce1b118
CV
23588The call was interrupted by the user.
23589@end table
23590
23591@node write
23592@unnumberedsubsubsec write
23593@cindex write, file-i/o system call
23594
23595@smallexample
b383017d 23596@exdent Synopsis:
0ce1b118
CV
23597int write(int fd, const void *buf, unsigned int count);
23598
b383017d 23599@exdent Request:
0ce1b118
CV
23600Fwrite,fd,bufptr,count
23601
23602@exdent Return value:
23603On success, the number of bytes written are returned.
23604Zero indicates nothing was written. On error, -1
23605is returned.
23606
23607@exdent Errors:
23608@end smallexample
23609
23610@table @code
b383017d 23611@item EBADF
0ce1b118
CV
23612fd is not a valid file descriptor or is not open for
23613writing.
23614
b383017d 23615@item EFAULT
0ce1b118
CV
23616buf is an invalid pointer value.
23617
b383017d 23618@item EFBIG
0ce1b118
CV
23619An attempt was made to write a file that exceeds the
23620host specific maximum file size allowed.
23621
b383017d 23622@item ENOSPC
0ce1b118
CV
23623No space on device to write the data.
23624
b383017d 23625@item EINTR
0ce1b118
CV
23626The call was interrupted by the user.
23627@end table
23628
23629@node lseek
23630@unnumberedsubsubsec lseek
23631@cindex lseek, file-i/o system call
23632
23633@smallexample
b383017d 23634@exdent Synopsis:
0ce1b118
CV
23635long lseek (int fd, long offset, int flag);
23636
b383017d 23637@exdent Request:
0ce1b118
CV
23638Flseek,fd,offset,flag
23639@end smallexample
23640
23641@code{flag} is one of:
23642
23643@table @code
b383017d 23644@item SEEK_SET
0ce1b118
CV
23645The offset is set to offset bytes.
23646
b383017d 23647@item SEEK_CUR
0ce1b118
CV
23648The offset is set to its current location plus offset
23649bytes.
23650
b383017d 23651@item SEEK_END
0ce1b118
CV
23652The offset is set to the size of the file plus offset
23653bytes.
23654@end table
23655
23656@smallexample
23657@exdent Return value:
23658On success, the resulting unsigned offset in bytes from
23659the beginning of the file is returned. Otherwise, a
23660value of -1 is returned.
23661
23662@exdent Errors:
23663@end smallexample
23664
23665@table @code
b383017d 23666@item EBADF
0ce1b118
CV
23667fd is not a valid open file descriptor.
23668
b383017d 23669@item ESPIPE
0ce1b118
CV
23670fd is associated with the @value{GDBN} console.
23671
b383017d 23672@item EINVAL
0ce1b118
CV
23673flag is not a proper value.
23674
b383017d 23675@item EINTR
0ce1b118
CV
23676The call was interrupted by the user.
23677@end table
23678
23679@node rename
23680@unnumberedsubsubsec rename
23681@cindex rename, file-i/o system call
23682
23683@smallexample
b383017d 23684@exdent Synopsis:
0ce1b118
CV
23685int rename(const char *oldpath, const char *newpath);
23686
b383017d 23687@exdent Request:
0ce1b118
CV
23688Frename,oldpathptr/len,newpathptr/len
23689
23690@exdent Return value:
23691On success, zero is returned. On error, -1 is returned.
23692
23693@exdent Errors:
23694@end smallexample
23695
23696@table @code
b383017d 23697@item EISDIR
0ce1b118
CV
23698newpath is an existing directory, but oldpath is not a
23699directory.
23700
b383017d 23701@item EEXIST
0ce1b118
CV
23702newpath is a non-empty directory.
23703
b383017d 23704@item EBUSY
0ce1b118
CV
23705oldpath or newpath is a directory that is in use by some
23706process.
23707
b383017d 23708@item EINVAL
0ce1b118
CV
23709An attempt was made to make a directory a subdirectory
23710of itself.
23711
b383017d 23712@item ENOTDIR
0ce1b118
CV
23713A component used as a directory in oldpath or new
23714path is not a directory. Or oldpath is a directory
23715and newpath exists but is not a directory.
23716
b383017d 23717@item EFAULT
0ce1b118
CV
23718oldpathptr or newpathptr are invalid pointer values.
23719
b383017d 23720@item EACCES
0ce1b118
CV
23721No access to the file or the path of the file.
23722
23723@item ENAMETOOLONG
b383017d 23724
0ce1b118
CV
23725oldpath or newpath was too long.
23726
b383017d 23727@item ENOENT
0ce1b118
CV
23728A directory component in oldpath or newpath does not exist.
23729
b383017d 23730@item EROFS
0ce1b118
CV
23731The file is on a read-only filesystem.
23732
b383017d 23733@item ENOSPC
0ce1b118
CV
23734The device containing the file has no room for the new
23735directory entry.
23736
b383017d 23737@item EINTR
0ce1b118
CV
23738The call was interrupted by the user.
23739@end table
23740
23741@node unlink
23742@unnumberedsubsubsec unlink
23743@cindex unlink, file-i/o system call
23744
23745@smallexample
b383017d 23746@exdent Synopsis:
0ce1b118
CV
23747int unlink(const char *pathname);
23748
b383017d 23749@exdent Request:
0ce1b118
CV
23750Funlink,pathnameptr/len
23751
23752@exdent Return value:
23753On success, zero is returned. On error, -1 is returned.
23754
23755@exdent Errors:
23756@end smallexample
23757
23758@table @code
b383017d 23759@item EACCES
0ce1b118
CV
23760No access to the file or the path of the file.
23761
b383017d 23762@item EPERM
0ce1b118
CV
23763The system does not allow unlinking of directories.
23764
b383017d 23765@item EBUSY
0ce1b118
CV
23766The file pathname cannot be unlinked because it's
23767being used by another process.
23768
b383017d 23769@item EFAULT
0ce1b118
CV
23770pathnameptr is an invalid pointer value.
23771
23772@item ENAMETOOLONG
23773pathname was too long.
23774
b383017d 23775@item ENOENT
0ce1b118
CV
23776A directory component in pathname does not exist.
23777
b383017d 23778@item ENOTDIR
0ce1b118
CV
23779A component of the path is not a directory.
23780
b383017d 23781@item EROFS
0ce1b118
CV
23782The file is on a read-only filesystem.
23783
b383017d 23784@item EINTR
0ce1b118
CV
23785The call was interrupted by the user.
23786@end table
23787
23788@node stat/fstat
23789@unnumberedsubsubsec stat/fstat
23790@cindex fstat, file-i/o system call
23791@cindex stat, file-i/o system call
23792
23793@smallexample
b383017d 23794@exdent Synopsis:
0ce1b118
CV
23795int stat(const char *pathname, struct stat *buf);
23796int fstat(int fd, struct stat *buf);
23797
b383017d 23798@exdent Request:
0ce1b118
CV
23799Fstat,pathnameptr/len,bufptr
23800Ffstat,fd,bufptr
23801
23802@exdent Return value:
23803On success, zero is returned. On error, -1 is returned.
23804
23805@exdent Errors:
23806@end smallexample
23807
23808@table @code
b383017d 23809@item EBADF
0ce1b118
CV
23810fd is not a valid open file.
23811
b383017d 23812@item ENOENT
0ce1b118
CV
23813A directory component in pathname does not exist or the
23814path is an empty string.
23815
b383017d 23816@item ENOTDIR
0ce1b118
CV
23817A component of the path is not a directory.
23818
b383017d 23819@item EFAULT
0ce1b118
CV
23820pathnameptr is an invalid pointer value.
23821
b383017d 23822@item EACCES
0ce1b118
CV
23823No access to the file or the path of the file.
23824
23825@item ENAMETOOLONG
23826pathname was too long.
23827
b383017d 23828@item EINTR
0ce1b118
CV
23829The call was interrupted by the user.
23830@end table
23831
23832@node gettimeofday
23833@unnumberedsubsubsec gettimeofday
23834@cindex gettimeofday, file-i/o system call
23835
23836@smallexample
b383017d 23837@exdent Synopsis:
0ce1b118
CV
23838int gettimeofday(struct timeval *tv, void *tz);
23839
b383017d 23840@exdent Request:
0ce1b118
CV
23841Fgettimeofday,tvptr,tzptr
23842
23843@exdent Return value:
23844On success, 0 is returned, -1 otherwise.
23845
23846@exdent Errors:
23847@end smallexample
23848
23849@table @code
b383017d 23850@item EINVAL
0ce1b118
CV
23851tz is a non-NULL pointer.
23852
b383017d 23853@item EFAULT
0ce1b118
CV
23854tvptr and/or tzptr is an invalid pointer value.
23855@end table
23856
23857@node isatty
23858@unnumberedsubsubsec isatty
23859@cindex isatty, file-i/o system call
23860
23861@smallexample
b383017d 23862@exdent Synopsis:
0ce1b118
CV
23863int isatty(int fd);
23864
b383017d 23865@exdent Request:
0ce1b118
CV
23866Fisatty,fd
23867
23868@exdent Return value:
23869Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
23870
23871@exdent Errors:
23872@end smallexample
23873
23874@table @code
b383017d 23875@item EINTR
0ce1b118
CV
23876The call was interrupted by the user.
23877@end table
23878
23879@node system
23880@unnumberedsubsubsec system
23881@cindex system, file-i/o system call
23882
23883@smallexample
b383017d 23884@exdent Synopsis:
0ce1b118
CV
23885int system(const char *command);
23886
b383017d 23887@exdent Request:
0ce1b118
CV
23888Fsystem,commandptr/len
23889
23890@exdent Return value:
23891The value returned is -1 on error and the return status
23892of the command otherwise. Only the exit status of the
23893command is returned, which is extracted from the hosts
23894system return value by calling WEXITSTATUS(retval).
23895In case /bin/sh could not be executed, 127 is returned.
23896
23897@exdent Errors:
23898@end smallexample
23899
23900@table @code
b383017d 23901@item EINTR
0ce1b118
CV
23902The call was interrupted by the user.
23903@end table
23904
23905@node Protocol specific representation of datatypes
23906@subsection Protocol specific representation of datatypes
23907@cindex protocol specific representation of datatypes, in file-i/o protocol
23908
23909@menu
23910* Integral datatypes::
23911* Pointer values::
23912* struct stat::
23913* struct timeval::
23914@end menu
23915
23916@node Integral datatypes
23917@unnumberedsubsubsec Integral datatypes
23918@cindex integral datatypes, in file-i/o protocol
23919
23920The integral datatypes used in the system calls are
23921
23922@smallexample
23923int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
23924@end smallexample
23925
23926@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
23927implemented as 32 bit values in this protocol.
23928
b383017d
RM
23929@code{Long} and @code{unsigned long} are implemented as 64 bit types.
23930
0ce1b118
CV
23931@xref{Limits}, for corresponding MIN and MAX values (similar to those
23932in @file{limits.h}) to allow range checking on host and target.
23933
23934@code{time_t} datatypes are defined as seconds since the Epoch.
23935
23936All integral datatypes transferred as part of a memory read or write of a
23937structured datatype e.g.@: a @code{struct stat} have to be given in big endian
23938byte order.
23939
23940@node Pointer values
23941@unnumberedsubsubsec Pointer values
23942@cindex pointer values, in file-i/o protocol
23943
23944Pointers to target data are transmitted as they are. An exception
23945is made for pointers to buffers for which the length isn't
23946transmitted as part of the function call, namely strings. Strings
23947are transmitted as a pointer/length pair, both as hex values, e.g.@:
23948
23949@smallexample
23950@code{1aaf/12}
23951@end smallexample
23952
23953@noindent
23954which is a pointer to data of length 18 bytes at position 0x1aaf.
23955The length is defined as the full string length in bytes, including
23956the trailing null byte. Example:
23957
23958@smallexample
23959``hello, world'' at address 0x123456
23960@end smallexample
23961
23962@noindent
23963is transmitted as
23964
23965@smallexample
23966@code{123456/d}
23967@end smallexample
23968
23969@node struct stat
23970@unnumberedsubsubsec struct stat
23971@cindex struct stat, in file-i/o protocol
23972
23973The buffer of type struct stat used by the target and @value{GDBN} is defined
23974as follows:
23975
23976@smallexample
23977struct stat @{
23978 unsigned int st_dev; /* device */
23979 unsigned int st_ino; /* inode */
23980 mode_t st_mode; /* protection */
23981 unsigned int st_nlink; /* number of hard links */
23982 unsigned int st_uid; /* user ID of owner */
23983 unsigned int st_gid; /* group ID of owner */
23984 unsigned int st_rdev; /* device type (if inode device) */
23985 unsigned long st_size; /* total size, in bytes */
23986 unsigned long st_blksize; /* blocksize for filesystem I/O */
23987 unsigned long st_blocks; /* number of blocks allocated */
23988 time_t st_atime; /* time of last access */
23989 time_t st_mtime; /* time of last modification */
23990 time_t st_ctime; /* time of last change */
23991@};
23992@end smallexample
23993
23994The integral datatypes are conforming to the definitions given in the
23995approriate section (see @ref{Integral datatypes}, for details) so this
23996structure is of size 64 bytes.
23997
23998The values of several fields have a restricted meaning and/or
23999range of values.
24000
24001@smallexample
24002st_dev: 0 file
24003 1 console
24004
24005st_ino: No valid meaning for the target. Transmitted unchanged.
24006
24007st_mode: Valid mode bits are described in Appendix C. Any other
24008 bits have currently no meaning for the target.
24009
24010st_uid: No valid meaning for the target. Transmitted unchanged.
24011
24012st_gid: No valid meaning for the target. Transmitted unchanged.
24013
24014st_rdev: No valid meaning for the target. Transmitted unchanged.
24015
24016st_atime, st_mtime, st_ctime:
24017 These values have a host and file system dependent
24018 accuracy. Especially on Windows hosts the file systems
24019 don't support exact timing values.
24020@end smallexample
24021
24022The target gets a struct stat of the above representation and is
24023responsible to coerce it to the target representation before
24024continuing.
24025
24026Note that due to size differences between the host and target
24027representation of stat members, these members could eventually
24028get truncated on the target.
24029
24030@node struct timeval
24031@unnumberedsubsubsec struct timeval
24032@cindex struct timeval, in file-i/o protocol
24033
24034The buffer of type struct timeval used by the target and @value{GDBN}
24035is defined as follows:
24036
24037@smallexample
b383017d 24038struct timeval @{
0ce1b118
CV
24039 time_t tv_sec; /* second */
24040 long tv_usec; /* microsecond */
24041@};
24042@end smallexample
24043
24044The integral datatypes are conforming to the definitions given in the
24045approriate section (see @ref{Integral datatypes}, for details) so this
24046structure is of size 8 bytes.
24047
24048@node Constants
24049@subsection Constants
24050@cindex constants, in file-i/o protocol
24051
24052The following values are used for the constants inside of the
24053protocol. @value{GDBN} and target are resposible to translate these
24054values before and after the call as needed.
24055
24056@menu
24057* Open flags::
24058* mode_t values::
24059* Errno values::
24060* Lseek flags::
24061* Limits::
24062@end menu
24063
24064@node Open flags
24065@unnumberedsubsubsec Open flags
24066@cindex open flags, in file-i/o protocol
24067
24068All values are given in hexadecimal representation.
24069
24070@smallexample
24071 O_RDONLY 0x0
24072 O_WRONLY 0x1
24073 O_RDWR 0x2
24074 O_APPEND 0x8
24075 O_CREAT 0x200
24076 O_TRUNC 0x400
24077 O_EXCL 0x800
24078@end smallexample
24079
24080@node mode_t values
24081@unnumberedsubsubsec mode_t values
24082@cindex mode_t values, in file-i/o protocol
24083
24084All values are given in octal representation.
24085
24086@smallexample
24087 S_IFREG 0100000
24088 S_IFDIR 040000
24089 S_IRUSR 0400
24090 S_IWUSR 0200
24091 S_IXUSR 0100
24092 S_IRGRP 040
24093 S_IWGRP 020
24094 S_IXGRP 010
24095 S_IROTH 04
24096 S_IWOTH 02
24097 S_IXOTH 01
24098@end smallexample
24099
24100@node Errno values
24101@unnumberedsubsubsec Errno values
24102@cindex errno values, in file-i/o protocol
24103
24104All values are given in decimal representation.
24105
24106@smallexample
24107 EPERM 1
24108 ENOENT 2
24109 EINTR 4
24110 EBADF 9
24111 EACCES 13
24112 EFAULT 14
24113 EBUSY 16
24114 EEXIST 17
24115 ENODEV 19
24116 ENOTDIR 20
24117 EISDIR 21
24118 EINVAL 22
24119 ENFILE 23
24120 EMFILE 24
24121 EFBIG 27
24122 ENOSPC 28
24123 ESPIPE 29
24124 EROFS 30
24125 ENAMETOOLONG 91
24126 EUNKNOWN 9999
24127@end smallexample
24128
24129 EUNKNOWN is used as a fallback error value if a host system returns
24130 any error value not in the list of supported error numbers.
24131
24132@node Lseek flags
24133@unnumberedsubsubsec Lseek flags
24134@cindex lseek flags, in file-i/o protocol
24135
24136@smallexample
24137 SEEK_SET 0
24138 SEEK_CUR 1
24139 SEEK_END 2
24140@end smallexample
24141
24142@node Limits
24143@unnumberedsubsubsec Limits
24144@cindex limits, in file-i/o protocol
24145
24146All values are given in decimal representation.
24147
24148@smallexample
24149 INT_MIN -2147483648
24150 INT_MAX 2147483647
24151 UINT_MAX 4294967295
24152 LONG_MIN -9223372036854775808
24153 LONG_MAX 9223372036854775807
24154 ULONG_MAX 18446744073709551615
24155@end smallexample
24156
24157@node File-I/O Examples
24158@subsection File-I/O Examples
24159@cindex file-i/o examples
24160
24161Example sequence of a write call, file descriptor 3, buffer is at target
24162address 0x1234, 6 bytes should be written:
24163
24164@smallexample
24165<- @code{Fwrite,3,1234,6}
24166@emph{request memory read from target}
24167-> @code{m1234,6}
24168<- XXXXXX
24169@emph{return "6 bytes written"}
24170-> @code{F6}
24171@end smallexample
24172
24173Example sequence of a read call, file descriptor 3, buffer is at target
24174address 0x1234, 6 bytes should be read:
24175
24176@smallexample
24177<- @code{Fread,3,1234,6}
24178@emph{request memory write to target}
24179-> @code{X1234,6:XXXXXX}
24180@emph{return "6 bytes read"}
24181-> @code{F6}
24182@end smallexample
24183
24184Example sequence of a read call, call fails on the host due to invalid
24185file descriptor (EBADF):
24186
24187@smallexample
24188<- @code{Fread,3,1234,6}
24189-> @code{F-1,9}
24190@end smallexample
24191
24192Example sequence of a read call, user presses Ctrl-C before syscall on
24193host is called:
24194
24195@smallexample
24196<- @code{Fread,3,1234,6}
24197-> @code{F-1,4,C}
24198<- @code{T02}
24199@end smallexample
24200
24201Example sequence of a read call, user presses Ctrl-C after syscall on
24202host is called:
24203
24204@smallexample
24205<- @code{Fread,3,1234,6}
24206-> @code{X1234,6:XXXXXX}
24207<- @code{T02}
24208@end smallexample
24209
f418dd93
DJ
24210@include agentexpr.texi
24211
aab4e0ec 24212@include gpl.texi
eb12ee30 24213
2154891a 24214@raisesections
6826cf00 24215@include fdl.texi
2154891a 24216@lowersections
6826cf00 24217
6d2ebf8b 24218@node Index
c906108c
SS
24219@unnumbered Index
24220
24221@printindex cp
24222
24223@tex
24224% I think something like @colophon should be in texinfo. In the
24225% meantime:
24226\long\def\colophon{\hbox to0pt{}\vfill
24227\centerline{The body of this manual is set in}
24228\centerline{\fontname\tenrm,}
24229\centerline{with headings in {\bf\fontname\tenbf}}
24230\centerline{and examples in {\tt\fontname\tentt}.}
24231\centerline{{\it\fontname\tenit\/},}
24232\centerline{{\bf\fontname\tenbf}, and}
24233\centerline{{\sl\fontname\tensl\/}}
24234\centerline{are used for emphasis.}\vfill}
24235\page\colophon
24236% Blame: doc@cygnus.com, 1991.
24237@end tex
24238
c906108c 24239@bye
This page took 1.849385 seconds and 4 git commands to generate.