* i386-tdep.c (i386_mxcsr_type): New variable.
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
c02a867d 2@c Copyright (C) 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 91Published by the Free Software Foundation @*
c02a867d
EZ
9251 Franklin Street, Fifth Floor,
93Boston, MA 02110-1301, 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
c1468174 878prefixing it with @file{./}, e.g.@: @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
8a5a3c82
AS
935@item -eval-command @var{command}
936@itemx -ex @var{command}
937@cindex @code{--eval-command}
938@cindex @code{-ex}
939Execute a single @value{GDBN} command.
940
941This option may be used multiple times to call multiple commands. It may
942also be interleaved with @samp{-command} as required.
943
944@smallexample
945@value{GDBP} -ex 'target sim' -ex 'load' \
946 -x setbreakpoints -ex 'run' a.out
947@end smallexample
948
c906108c
SS
949@item -directory @var{directory}
950@itemx -d @var{directory}
d700128c
EZ
951@cindex @code{--directory}
952@cindex @code{-d}
c906108c
SS
953Add @var{directory} to the path to search for source files.
954
c906108c
SS
955@item -r
956@itemx -readnow
d700128c
EZ
957@cindex @code{--readnow}
958@cindex @code{-r}
c906108c
SS
959Read each symbol file's entire symbol table immediately, rather than
960the default, which is to read it incrementally as it is needed.
961This makes startup slower, but makes future operations faster.
53a5351d 962
c906108c
SS
963@end table
964
6d2ebf8b 965@node Mode Options
c906108c
SS
966@subsection Choosing modes
967
968You can run @value{GDBN} in various alternative modes---for example, in
969batch mode or quiet mode.
970
971@table @code
972@item -nx
973@itemx -n
d700128c
EZ
974@cindex @code{--nx}
975@cindex @code{-n}
96565e91 976Do not execute commands found in any initialization files. Normally,
2df3850c
JM
977@value{GDBN} executes the commands in these files after all the command
978options and arguments have been processed. @xref{Command Files,,Command
979files}.
c906108c
SS
980
981@item -quiet
d700128c 982@itemx -silent
c906108c 983@itemx -q
d700128c
EZ
984@cindex @code{--quiet}
985@cindex @code{--silent}
986@cindex @code{-q}
c906108c
SS
987``Quiet''. Do not print the introductory and copyright messages. These
988messages are also suppressed in batch mode.
989
990@item -batch
d700128c 991@cindex @code{--batch}
c906108c
SS
992Run in batch mode. Exit with status @code{0} after processing all the
993command files specified with @samp{-x} (and all commands from
994initialization files, if not inhibited with @samp{-n}). Exit with
995nonzero status if an error occurs in executing the @value{GDBN} commands
996in the command files.
997
2df3850c
JM
998Batch mode may be useful for running @value{GDBN} as a filter, for
999example to download and run a program on another computer; in order to
1000make this more useful, the message
c906108c 1001
474c8240 1002@smallexample
c906108c 1003Program exited normally.
474c8240 1004@end smallexample
c906108c
SS
1005
1006@noindent
2df3850c
JM
1007(which is ordinarily issued whenever a program running under
1008@value{GDBN} control terminates) is not issued when running in batch
1009mode.
1010
1a088d06
AS
1011@item -batch-silent
1012@cindex @code{--batch-silent}
1013Run in batch mode exactly like @samp{-batch}, but totally silently. All
1014@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1015unaffected). This is much quieter than @samp{-silent} and would be useless
1016for an interactive session.
1017
1018This is particularly useful when using targets that give @samp{Loading section}
1019messages, for example.
1020
1021Note that targets that give their output via @value{GDBN}, as opposed to
1022writing directly to @code{stdout}, will also be made silent.
1023
4b0ad762
AS
1024@item -return-child-result
1025@cindex @code{--return-child-result}
1026The return code from @value{GDBN} will be the return code from the child
1027process (the process being debugged), with the following exceptions:
1028
1029@itemize @bullet
1030@item
1031@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1032internal error. In this case the exit code is the same as it would have been
1033without @samp{-return-child-result}.
1034@item
1035The user quits with an explicit value. E.g., @samp{quit 1}.
1036@item
1037The child process never runs, or is not allowed to terminate, in which case
1038the exit code will be -1.
1039@end itemize
1040
1041This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1042when @value{GDBN} is being used as a remote program loader or simulator
1043interface.
1044
2df3850c
JM
1045@item -nowindows
1046@itemx -nw
d700128c
EZ
1047@cindex @code{--nowindows}
1048@cindex @code{-nw}
2df3850c 1049``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1050(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1051interface. If no GUI is available, this option has no effect.
1052
1053@item -windows
1054@itemx -w
d700128c
EZ
1055@cindex @code{--windows}
1056@cindex @code{-w}
2df3850c
JM
1057If @value{GDBN} includes a GUI, then this option requires it to be
1058used if possible.
c906108c
SS
1059
1060@item -cd @var{directory}
d700128c 1061@cindex @code{--cd}
c906108c
SS
1062Run @value{GDBN} using @var{directory} as its working directory,
1063instead of the current directory.
1064
c906108c
SS
1065@item -fullname
1066@itemx -f
d700128c
EZ
1067@cindex @code{--fullname}
1068@cindex @code{-f}
7a292a7a
SS
1069@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1070subprocess. It tells @value{GDBN} to output the full file name and line
1071number in a standard, recognizable fashion each time a stack frame is
1072displayed (which includes each time your program stops). This
1073recognizable format looks like two @samp{\032} characters, followed by
1074the file name, line number and character position separated by colons,
1075and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1076@samp{\032} characters as a signal to display the source code for the
1077frame.
c906108c 1078
d700128c
EZ
1079@item -epoch
1080@cindex @code{--epoch}
1081The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1082@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1083routines so as to allow Epoch to display values of expressions in a
1084separate window.
1085
1086@item -annotate @var{level}
1087@cindex @code{--annotate}
1088This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1089effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1090(@pxref{Annotations}). The annotation @var{level} controls how much
1091information @value{GDBN} prints together with its prompt, values of
1092expressions, source lines, and other types of output. Level 0 is the
1093normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1094@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1095that control @value{GDBN}, and level 2 has been deprecated.
1096
265eeb58 1097The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1098(@pxref{GDB/MI}).
d700128c 1099
aa26fa3a
TT
1100@item --args
1101@cindex @code{--args}
1102Change interpretation of command line so that arguments following the
1103executable file are passed as command line arguments to the inferior.
1104This option stops option processing.
1105
2df3850c
JM
1106@item -baud @var{bps}
1107@itemx -b @var{bps}
d700128c
EZ
1108@cindex @code{--baud}
1109@cindex @code{-b}
c906108c
SS
1110Set the line speed (baud rate or bits per second) of any serial
1111interface used by @value{GDBN} for remote debugging.
c906108c 1112
f47b1503
AS
1113@item -l @var{timeout}
1114@cindex @code{-l}
1115Set the timeout (in seconds) of any communication used by @value{GDBN}
1116for remote debugging.
1117
c906108c 1118@item -tty @var{device}
d700128c
EZ
1119@itemx -t @var{device}
1120@cindex @code{--tty}
1121@cindex @code{-t}
c906108c
SS
1122Run using @var{device} for your program's standard input and output.
1123@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1124
53a5351d 1125@c resolve the situation of these eventually
c4555f82
SC
1126@item -tui
1127@cindex @code{--tui}
d0d5df6f
AC
1128Activate the @dfn{Text User Interface} when starting. The Text User
1129Interface manages several text windows on the terminal, showing
1130source, assembly, registers and @value{GDBN} command outputs
1131(@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1132Text User Interface can be enabled by invoking the program
1133@samp{gdbtui}. Do not use this option if you run @value{GDBN} from
1134Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1135
1136@c @item -xdb
d700128c 1137@c @cindex @code{--xdb}
53a5351d
JM
1138@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1139@c For information, see the file @file{xdb_trans.html}, which is usually
1140@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1141@c systems.
1142
d700128c
EZ
1143@item -interpreter @var{interp}
1144@cindex @code{--interpreter}
1145Use the interpreter @var{interp} for interface with the controlling
1146program or device. This option is meant to be set by programs which
94bbb2c0 1147communicate with @value{GDBN} using it as a back end.
21c294e6 1148@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1149
da0f9dcd 1150@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1151@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1152The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1153previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1154selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1155@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1156
1157@item -write
1158@cindex @code{--write}
1159Open the executable and core files for both reading and writing. This
1160is equivalent to the @samp{set write on} command inside @value{GDBN}
1161(@pxref{Patching}).
1162
1163@item -statistics
1164@cindex @code{--statistics}
1165This option causes @value{GDBN} to print statistics about time and
1166memory usage after it completes each command and returns to the prompt.
1167
1168@item -version
1169@cindex @code{--version}
1170This option causes @value{GDBN} to print its version number and
1171no-warranty blurb, and exit.
1172
c906108c
SS
1173@end table
1174
6fc08d32
EZ
1175@node Startup
1176@subsection What @value{GDBN} does during startup
1177@cindex @value{GDBN} startup
1178
1179Here's the description of what @value{GDBN} does during session startup:
1180
1181@enumerate
1182@item
1183Sets up the command interpreter as specified by the command line
1184(@pxref{Mode Options, interpreter}).
1185
1186@item
1187@cindex init file
1188Reads the @dfn{init file} (if any) in your home directory@footnote{On
1189DOS/Windows systems, the home directory is the one pointed to by the
1190@code{HOME} environment variable.} and executes all the commands in
1191that file.
1192
1193@item
1194Processes command line options and operands.
1195
1196@item
1197Reads and executes the commands from init file (if any) in the current
119b882a
EZ
1198working directory. This is only done if the current directory is
1199different from your home directory. Thus, you can have more than one
1200init file, one generic in your home directory, and another, specific
1201to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1202@value{GDBN}.
1203
1204@item
1205Reads command files specified by the @samp{-x} option. @xref{Command
1206Files}, for more details about @value{GDBN} command files.
1207
1208@item
1209Reads the command history recorded in the @dfn{history file}.
d620b259 1210@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1211files where @value{GDBN} records it.
1212@end enumerate
1213
1214Init files use the same syntax as @dfn{command files} (@pxref{Command
1215Files}) and are processed by @value{GDBN} in the same way. The init
1216file in your home directory can set options (such as @samp{set
1217complaints}) that affect subsequent processing of command line options
1218and operands. Init files are not executed if you use the @samp{-nx}
1219option (@pxref{Mode Options, ,Choosing modes}).
1220
1221@cindex init file name
1222@cindex @file{.gdbinit}
119b882a 1223The @value{GDBN} init files are normally called @file{.gdbinit}.
6fc08d32
EZ
1224On some configurations of @value{GDBN}, the init file is known by a
1225different name (these are typically environments where a specialized
1226form of @value{GDBN} may need to coexist with other forms, hence a
1227different name for the specialized version's init file). These are the
1228environments with special init file names:
1229
6fc08d32 1230@itemize @bullet
119b882a
EZ
1231@cindex @file{gdb.ini}
1232@item
1233The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1234the limitations of file names imposed by DOS filesystems. The Windows
1235ports of @value{GDBN} use the standard name, but if they find a
1236@file{gdb.ini} file, they warn you about that and suggest to rename
1237the file to the standard name.
1238
1239@cindex @file{.vxgdbinit}
6fc08d32
EZ
1240@item
1241VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
1242
1243@cindex @file{.os68gdbinit}
1244@item
1245OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
1246
1247@cindex @file{.esgdbinit}
1248@item
1249ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
1250
1251@item
1252CISCO 68k: @file{.cisco-gdbinit}
1253@end itemize
1254
1255
6d2ebf8b 1256@node Quitting GDB
c906108c
SS
1257@section Quitting @value{GDBN}
1258@cindex exiting @value{GDBN}
1259@cindex leaving @value{GDBN}
1260
1261@table @code
1262@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1263@kindex q @r{(@code{quit})}
96a2c332
SS
1264@item quit @r{[}@var{expression}@r{]}
1265@itemx q
1266To exit @value{GDBN}, use the @code{quit} command (abbreviated
1267@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1268do not supply @var{expression}, @value{GDBN} will terminate normally;
1269otherwise it will terminate using the result of @var{expression} as the
1270error code.
c906108c
SS
1271@end table
1272
1273@cindex interrupt
1274An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1275terminates the action of any @value{GDBN} command that is in progress and
1276returns to @value{GDBN} command level. It is safe to type the interrupt
1277character at any time because @value{GDBN} does not allow it to take effect
1278until a time when it is safe.
1279
c906108c
SS
1280If you have been using @value{GDBN} to control an attached process or
1281device, you can release it with the @code{detach} command
1282(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1283
6d2ebf8b 1284@node Shell Commands
c906108c
SS
1285@section Shell commands
1286
1287If you need to execute occasional shell commands during your
1288debugging session, there is no need to leave or suspend @value{GDBN}; you can
1289just use the @code{shell} command.
1290
1291@table @code
1292@kindex shell
1293@cindex shell escape
1294@item shell @var{command string}
1295Invoke a standard shell to execute @var{command string}.
c906108c 1296If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1297shell to run. Otherwise @value{GDBN} uses the default shell
1298(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1299@end table
1300
1301The utility @code{make} is often needed in development environments.
1302You do not have to use the @code{shell} command for this purpose in
1303@value{GDBN}:
1304
1305@table @code
1306@kindex make
1307@cindex calling make
1308@item make @var{make-args}
1309Execute the @code{make} program with the specified
1310arguments. This is equivalent to @samp{shell make @var{make-args}}.
1311@end table
1312
0fac0b41
DJ
1313@node Logging output
1314@section Logging output
1315@cindex logging @value{GDBN} output
9c16f35a 1316@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1317
1318You may want to save the output of @value{GDBN} commands to a file.
1319There are several commands to control @value{GDBN}'s logging.
1320
1321@table @code
1322@kindex set logging
1323@item set logging on
1324Enable logging.
1325@item set logging off
1326Disable logging.
9c16f35a 1327@cindex logging file name
0fac0b41
DJ
1328@item set logging file @var{file}
1329Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1330@item set logging overwrite [on|off]
1331By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1332you want @code{set logging on} to overwrite the logfile instead.
1333@item set logging redirect [on|off]
1334By default, @value{GDBN} output will go to both the terminal and the logfile.
1335Set @code{redirect} if you want output to go only to the log file.
1336@kindex show logging
1337@item show logging
1338Show the current values of the logging settings.
1339@end table
1340
6d2ebf8b 1341@node Commands
c906108c
SS
1342@chapter @value{GDBN} Commands
1343
1344You can abbreviate a @value{GDBN} command to the first few letters of the command
1345name, if that abbreviation is unambiguous; and you can repeat certain
1346@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1347key to get @value{GDBN} to fill out the rest of a word in a command (or to
1348show you the alternatives available, if there is more than one possibility).
1349
1350@menu
1351* Command Syntax:: How to give commands to @value{GDBN}
1352* Completion:: Command completion
1353* Help:: How to ask @value{GDBN} for help
1354@end menu
1355
6d2ebf8b 1356@node Command Syntax
c906108c
SS
1357@section Command syntax
1358
1359A @value{GDBN} command is a single line of input. There is no limit on
1360how long it can be. It starts with a command name, which is followed by
1361arguments whose meaning depends on the command name. For example, the
1362command @code{step} accepts an argument which is the number of times to
1363step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1364with no arguments. Some commands do not allow any arguments.
c906108c
SS
1365
1366@cindex abbreviation
1367@value{GDBN} command names may always be truncated if that abbreviation is
1368unambiguous. Other possible command abbreviations are listed in the
1369documentation for individual commands. In some cases, even ambiguous
1370abbreviations are allowed; for example, @code{s} is specially defined as
1371equivalent to @code{step} even though there are other commands whose
1372names start with @code{s}. You can test abbreviations by using them as
1373arguments to the @code{help} command.
1374
1375@cindex repeating commands
41afff9a 1376@kindex RET @r{(repeat last command)}
c906108c 1377A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1378repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1379will not repeat this way; these are commands whose unintentional
1380repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1381repeat. User-defined commands can disable this feature; see
1382@ref{Define, dont-repeat}.
c906108c
SS
1383
1384The @code{list} and @code{x} commands, when you repeat them with
1385@key{RET}, construct new arguments rather than repeating
1386exactly as typed. This permits easy scanning of source or memory.
1387
1388@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1389output, in a way similar to the common utility @code{more}
1390(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1391@key{RET} too many in this situation, @value{GDBN} disables command
1392repetition after any command that generates this sort of display.
1393
41afff9a 1394@kindex # @r{(a comment)}
c906108c
SS
1395@cindex comment
1396Any text from a @kbd{#} to the end of the line is a comment; it does
1397nothing. This is useful mainly in command files (@pxref{Command
1398Files,,Command files}).
1399
88118b3a
TT
1400@cindex repeating command sequences
1401@kindex C-o @r{(operate-and-get-next)}
1402The @kbd{C-o} binding is useful for repeating a complex sequence of
1403commands. This command accepts the current line, like @kbd{RET}, and
1404then fetches the next line relative to the current line from the history
1405for editing.
1406
6d2ebf8b 1407@node Completion
c906108c
SS
1408@section Command completion
1409
1410@cindex completion
1411@cindex word completion
1412@value{GDBN} can fill in the rest of a word in a command for you, if there is
1413only one possibility; it can also show you what the valid possibilities
1414are for the next word in a command, at any time. This works for @value{GDBN}
1415commands, @value{GDBN} subcommands, and the names of symbols in your program.
1416
1417Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1418of a word. If there is only one possibility, @value{GDBN} fills in the
1419word, and waits for you to finish the command (or press @key{RET} to
1420enter it). For example, if you type
1421
1422@c FIXME "@key" does not distinguish its argument sufficiently to permit
1423@c complete accuracy in these examples; space introduced for clarity.
1424@c If texinfo enhancements make it unnecessary, it would be nice to
1425@c replace " @key" by "@key" in the following...
474c8240 1426@smallexample
c906108c 1427(@value{GDBP}) info bre @key{TAB}
474c8240 1428@end smallexample
c906108c
SS
1429
1430@noindent
1431@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1432the only @code{info} subcommand beginning with @samp{bre}:
1433
474c8240 1434@smallexample
c906108c 1435(@value{GDBP}) info breakpoints
474c8240 1436@end smallexample
c906108c
SS
1437
1438@noindent
1439You can either press @key{RET} at this point, to run the @code{info
1440breakpoints} command, or backspace and enter something else, if
1441@samp{breakpoints} does not look like the command you expected. (If you
1442were sure you wanted @code{info breakpoints} in the first place, you
1443might as well just type @key{RET} immediately after @samp{info bre},
1444to exploit command abbreviations rather than command completion).
1445
1446If there is more than one possibility for the next word when you press
1447@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1448characters and try again, or just press @key{TAB} a second time;
1449@value{GDBN} displays all the possible completions for that word. For
1450example, you might want to set a breakpoint on a subroutine whose name
1451begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1452just sounds the bell. Typing @key{TAB} again displays all the
1453function names in your program that begin with those characters, for
1454example:
1455
474c8240 1456@smallexample
c906108c
SS
1457(@value{GDBP}) b make_ @key{TAB}
1458@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1459make_a_section_from_file make_environ
1460make_abs_section make_function_type
1461make_blockvector make_pointer_type
1462make_cleanup make_reference_type
c906108c
SS
1463make_command make_symbol_completion_list
1464(@value{GDBP}) b make_
474c8240 1465@end smallexample
c906108c
SS
1466
1467@noindent
1468After displaying the available possibilities, @value{GDBN} copies your
1469partial input (@samp{b make_} in the example) so you can finish the
1470command.
1471
1472If you just want to see the list of alternatives in the first place, you
b37052ae 1473can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1474means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1475key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1476one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1477
1478@cindex quotes in commands
1479@cindex completion of quoted strings
1480Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1481parentheses or other characters that @value{GDBN} normally excludes from
1482its notion of a word. To permit word completion to work in this
1483situation, you may enclose words in @code{'} (single quote marks) in
1484@value{GDBN} commands.
c906108c 1485
c906108c 1486The most likely situation where you might need this is in typing the
b37052ae
EZ
1487name of a C@t{++} function. This is because C@t{++} allows function
1488overloading (multiple definitions of the same function, distinguished
1489by argument type). For example, when you want to set a breakpoint you
1490may need to distinguish whether you mean the version of @code{name}
1491that takes an @code{int} parameter, @code{name(int)}, or the version
1492that takes a @code{float} parameter, @code{name(float)}. To use the
1493word-completion facilities in this situation, type a single quote
1494@code{'} at the beginning of the function name. This alerts
1495@value{GDBN} that it may need to consider more information than usual
1496when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1497
474c8240 1498@smallexample
96a2c332 1499(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1500bubble(double,double) bubble(int,int)
1501(@value{GDBP}) b 'bubble(
474c8240 1502@end smallexample
c906108c
SS
1503
1504In some cases, @value{GDBN} can tell that completing a name requires using
1505quotes. When this happens, @value{GDBN} inserts the quote for you (while
1506completing as much as it can) if you do not type the quote in the first
1507place:
1508
474c8240 1509@smallexample
c906108c
SS
1510(@value{GDBP}) b bub @key{TAB}
1511@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1512(@value{GDBP}) b 'bubble(
474c8240 1513@end smallexample
c906108c
SS
1514
1515@noindent
1516In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1517you have not yet started typing the argument list when you ask for
1518completion on an overloaded symbol.
1519
d4f3574e 1520For more information about overloaded functions, see @ref{C plus plus
b37052ae 1521expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1522overload-resolution off} to disable overload resolution;
b37052ae 1523see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1524
1525
6d2ebf8b 1526@node Help
c906108c
SS
1527@section Getting help
1528@cindex online documentation
1529@kindex help
1530
5d161b24 1531You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1532using the command @code{help}.
1533
1534@table @code
41afff9a 1535@kindex h @r{(@code{help})}
c906108c
SS
1536@item help
1537@itemx h
1538You can use @code{help} (abbreviated @code{h}) with no arguments to
1539display a short list of named classes of commands:
1540
1541@smallexample
1542(@value{GDBP}) help
1543List of classes of commands:
1544
2df3850c 1545aliases -- Aliases of other commands
c906108c 1546breakpoints -- Making program stop at certain points
2df3850c 1547data -- Examining data
c906108c 1548files -- Specifying and examining files
2df3850c
JM
1549internals -- Maintenance commands
1550obscure -- Obscure features
1551running -- Running the program
1552stack -- Examining the stack
c906108c
SS
1553status -- Status inquiries
1554support -- Support facilities
96a2c332
SS
1555tracepoints -- Tracing of program execution without@*
1556 stopping the program
c906108c 1557user-defined -- User-defined commands
c906108c 1558
5d161b24 1559Type "help" followed by a class name for a list of
c906108c 1560commands in that class.
5d161b24 1561Type "help" followed by command name for full
c906108c
SS
1562documentation.
1563Command name abbreviations are allowed if unambiguous.
1564(@value{GDBP})
1565@end smallexample
96a2c332 1566@c the above line break eliminates huge line overfull...
c906108c
SS
1567
1568@item help @var{class}
1569Using one of the general help classes as an argument, you can get a
1570list of the individual commands in that class. For example, here is the
1571help display for the class @code{status}:
1572
1573@smallexample
1574(@value{GDBP}) help status
1575Status inquiries.
1576
1577List of commands:
1578
1579@c Line break in "show" line falsifies real output, but needed
1580@c to fit in smallbook page size.
2df3850c
JM
1581info -- Generic command for showing things
1582 about the program being debugged
1583show -- Generic command for showing things
1584 about the debugger
c906108c 1585
5d161b24 1586Type "help" followed by command name for full
c906108c
SS
1587documentation.
1588Command name abbreviations are allowed if unambiguous.
1589(@value{GDBP})
1590@end smallexample
1591
1592@item help @var{command}
1593With a command name as @code{help} argument, @value{GDBN} displays a
1594short paragraph on how to use that command.
1595
6837a0a2
DB
1596@kindex apropos
1597@item apropos @var{args}
09d4efe1 1598The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2
DB
1599commands, and their documentation, for the regular expression specified in
1600@var{args}. It prints out all matches found. For example:
1601
1602@smallexample
1603apropos reload
1604@end smallexample
1605
b37052ae
EZ
1606@noindent
1607results in:
6837a0a2
DB
1608
1609@smallexample
6d2ebf8b
SS
1610@c @group
1611set symbol-reloading -- Set dynamic symbol table reloading
1612 multiple times in one run
1613show symbol-reloading -- Show dynamic symbol table reloading
1614 multiple times in one run
1615@c @end group
6837a0a2
DB
1616@end smallexample
1617
c906108c
SS
1618@kindex complete
1619@item complete @var{args}
1620The @code{complete @var{args}} command lists all the possible completions
1621for the beginning of a command. Use @var{args} to specify the beginning of the
1622command you want completed. For example:
1623
1624@smallexample
1625complete i
1626@end smallexample
1627
1628@noindent results in:
1629
1630@smallexample
1631@group
2df3850c
JM
1632if
1633ignore
c906108c
SS
1634info
1635inspect
c906108c
SS
1636@end group
1637@end smallexample
1638
1639@noindent This is intended for use by @sc{gnu} Emacs.
1640@end table
1641
1642In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1643and @code{show} to inquire about the state of your program, or the state
1644of @value{GDBN} itself. Each command supports many topics of inquiry; this
1645manual introduces each of them in the appropriate context. The listings
1646under @code{info} and under @code{show} in the Index point to
1647all the sub-commands. @xref{Index}.
1648
1649@c @group
1650@table @code
1651@kindex info
41afff9a 1652@kindex i @r{(@code{info})}
c906108c
SS
1653@item info
1654This command (abbreviated @code{i}) is for describing the state of your
1655program. For example, you can list the arguments given to your program
1656with @code{info args}, list the registers currently in use with @code{info
1657registers}, or list the breakpoints you have set with @code{info breakpoints}.
1658You can get a complete list of the @code{info} sub-commands with
1659@w{@code{help info}}.
1660
1661@kindex set
1662@item set
5d161b24 1663You can assign the result of an expression to an environment variable with
c906108c
SS
1664@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1665@code{set prompt $}.
1666
1667@kindex show
1668@item show
5d161b24 1669In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1670@value{GDBN} itself.
1671You can change most of the things you can @code{show}, by using the
1672related command @code{set}; for example, you can control what number
1673system is used for displays with @code{set radix}, or simply inquire
1674which is currently in use with @code{show radix}.
1675
1676@kindex info set
1677To display all the settable parameters and their current
1678values, you can use @code{show} with no arguments; you may also use
1679@code{info set}. Both commands produce the same display.
1680@c FIXME: "info set" violates the rule that "info" is for state of
1681@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1682@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1683@end table
1684@c @end group
1685
1686Here are three miscellaneous @code{show} subcommands, all of which are
1687exceptional in lacking corresponding @code{set} commands:
1688
1689@table @code
1690@kindex show version
9c16f35a 1691@cindex @value{GDBN} version number
c906108c
SS
1692@item show version
1693Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1694information in @value{GDBN} bug-reports. If multiple versions of
1695@value{GDBN} are in use at your site, you may need to determine which
1696version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1697commands are introduced, and old ones may wither away. Also, many
1698system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1699variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1700The version number is the same as the one announced when you start
1701@value{GDBN}.
c906108c
SS
1702
1703@kindex show copying
09d4efe1 1704@kindex info copying
9c16f35a 1705@cindex display @value{GDBN} copyright
c906108c 1706@item show copying
09d4efe1 1707@itemx info copying
c906108c
SS
1708Display information about permission for copying @value{GDBN}.
1709
1710@kindex show warranty
09d4efe1 1711@kindex info warranty
c906108c 1712@item show warranty
09d4efe1 1713@itemx info warranty
2df3850c 1714Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1715if your version of @value{GDBN} comes with one.
2df3850c 1716
c906108c
SS
1717@end table
1718
6d2ebf8b 1719@node Running
c906108c
SS
1720@chapter Running Programs Under @value{GDBN}
1721
1722When you run a program under @value{GDBN}, you must first generate
1723debugging information when you compile it.
7a292a7a
SS
1724
1725You may start @value{GDBN} with its arguments, if any, in an environment
1726of your choice. If you are doing native debugging, you may redirect
1727your program's input and output, debug an already running process, or
1728kill a child process.
c906108c
SS
1729
1730@menu
1731* Compilation:: Compiling for debugging
1732* Starting:: Starting your program
c906108c
SS
1733* Arguments:: Your program's arguments
1734* Environment:: Your program's environment
c906108c
SS
1735
1736* Working Directory:: Your program's working directory
1737* Input/Output:: Your program's input and output
1738* Attach:: Debugging an already-running process
1739* Kill Process:: Killing the child process
c906108c
SS
1740
1741* Threads:: Debugging programs with multiple threads
1742* Processes:: Debugging programs with multiple processes
5c95884b 1743* Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
c906108c
SS
1744@end menu
1745
6d2ebf8b 1746@node Compilation
c906108c
SS
1747@section Compiling for debugging
1748
1749In order to debug a program effectively, you need to generate
1750debugging information when you compile it. This debugging information
1751is stored in the object file; it describes the data type of each
1752variable or function and the correspondence between source line numbers
1753and addresses in the executable code.
1754
1755To request debugging information, specify the @samp{-g} option when you run
1756the compiler.
1757
514c4d71
EZ
1758Programs that are to be shipped to your customers are compiled with
1759optimizations, using the @samp{-O} compiler option. However, many
1760compilers are unable to handle the @samp{-g} and @samp{-O} options
1761together. Using those compilers, you cannot generate optimized
c906108c
SS
1762executables containing debugging information.
1763
514c4d71 1764@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1765without @samp{-O}, making it possible to debug optimized code. We
1766recommend that you @emph{always} use @samp{-g} whenever you compile a
1767program. You may think your program is correct, but there is no sense
1768in pushing your luck.
c906108c
SS
1769
1770@cindex optimized code, debugging
1771@cindex debugging optimized code
1772When you debug a program compiled with @samp{-g -O}, remember that the
1773optimizer is rearranging your code; the debugger shows you what is
1774really there. Do not be too surprised when the execution path does not
1775exactly match your source file! An extreme example: if you define a
1776variable, but never use it, @value{GDBN} never sees that
1777variable---because the compiler optimizes it out of existence.
1778
1779Some things do not work as well with @samp{-g -O} as with just
1780@samp{-g}, particularly on machines with instruction scheduling. If in
1781doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1782please report it to us as a bug (including a test case!).
15387254 1783@xref{Variables}, for more information about debugging optimized code.
c906108c
SS
1784
1785Older versions of the @sc{gnu} C compiler permitted a variant option
1786@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1787format; if your @sc{gnu} C compiler has this option, do not use it.
1788
514c4d71
EZ
1789@value{GDBN} knows about preprocessor macros and can show you their
1790expansion (@pxref{Macros}). Most compilers do not include information
1791about preprocessor macros in the debugging information if you specify
1792the @option{-g} flag alone, because this information is rather large.
1793Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1794provides macro information if you specify the options
1795@option{-gdwarf-2} and @option{-g3}; the former option requests
1796debugging information in the Dwarf 2 format, and the latter requests
1797``extra information''. In the future, we hope to find more compact
1798ways to represent macro information, so that it can be included with
1799@option{-g} alone.
1800
c906108c 1801@need 2000
6d2ebf8b 1802@node Starting
c906108c
SS
1803@section Starting your program
1804@cindex starting
1805@cindex running
1806
1807@table @code
1808@kindex run
41afff9a 1809@kindex r @r{(@code{run})}
c906108c
SS
1810@item run
1811@itemx r
7a292a7a
SS
1812Use the @code{run} command to start your program under @value{GDBN}.
1813You must first specify the program name (except on VxWorks) with an
1814argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1815@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1816(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1817
1818@end table
1819
c906108c
SS
1820If you are running your program in an execution environment that
1821supports processes, @code{run} creates an inferior process and makes
1822that process run your program. (In environments without processes,
1823@code{run} jumps to the start of your program.)
1824
1825The execution of a program is affected by certain information it
1826receives from its superior. @value{GDBN} provides ways to specify this
1827information, which you must do @emph{before} starting your program. (You
1828can change it after starting your program, but such changes only affect
1829your program the next time you start it.) This information may be
1830divided into four categories:
1831
1832@table @asis
1833@item The @emph{arguments.}
1834Specify the arguments to give your program as the arguments of the
1835@code{run} command. If a shell is available on your target, the shell
1836is used to pass the arguments, so that you may use normal conventions
1837(such as wildcard expansion or variable substitution) in describing
1838the arguments.
1839In Unix systems, you can control which shell is used with the
1840@code{SHELL} environment variable.
1841@xref{Arguments, ,Your program's arguments}.
1842
1843@item The @emph{environment.}
1844Your program normally inherits its environment from @value{GDBN}, but you can
1845use the @value{GDBN} commands @code{set environment} and @code{unset
1846environment} to change parts of the environment that affect
1847your program. @xref{Environment, ,Your program's environment}.
1848
1849@item The @emph{working directory.}
1850Your program inherits its working directory from @value{GDBN}. You can set
1851the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1852@xref{Working Directory, ,Your program's working directory}.
1853
1854@item The @emph{standard input and output.}
1855Your program normally uses the same device for standard input and
1856standard output as @value{GDBN} is using. You can redirect input and output
1857in the @code{run} command line, or you can use the @code{tty} command to
1858set a different device for your program.
1859@xref{Input/Output, ,Your program's input and output}.
1860
1861@cindex pipes
1862@emph{Warning:} While input and output redirection work, you cannot use
1863pipes to pass the output of the program you are debugging to another
1864program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1865wrong program.
1866@end table
c906108c
SS
1867
1868When you issue the @code{run} command, your program begins to execute
1869immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1870of how to arrange for your program to stop. Once your program has
1871stopped, you may call functions in your program, using the @code{print}
1872or @code{call} commands. @xref{Data, ,Examining Data}.
1873
1874If the modification time of your symbol file has changed since the last
1875time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1876table, and reads it again. When it does this, @value{GDBN} tries to retain
1877your current breakpoints.
1878
4e8b0763
JB
1879@table @code
1880@kindex start
1881@item start
1882@cindex run to main procedure
1883The name of the main procedure can vary from language to language.
1884With C or C@t{++}, the main procedure name is always @code{main}, but
1885other languages such as Ada do not require a specific name for their
1886main procedure. The debugger provides a convenient way to start the
1887execution of the program and to stop at the beginning of the main
1888procedure, depending on the language used.
1889
1890The @samp{start} command does the equivalent of setting a temporary
1891breakpoint at the beginning of the main procedure and then invoking
1892the @samp{run} command.
1893
f018e82f
EZ
1894@cindex elaboration phase
1895Some programs contain an @dfn{elaboration} phase where some startup code is
1896executed before the main procedure is called. This depends on the
1897languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1898constructors for static and global objects are executed before
1899@code{main} is called. It is therefore possible that the debugger stops
1900before reaching the main procedure. However, the temporary breakpoint
1901will remain to halt execution.
1902
1903Specify the arguments to give to your program as arguments to the
1904@samp{start} command. These arguments will be given verbatim to the
1905underlying @samp{run} command. Note that the same arguments will be
1906reused if no argument is provided during subsequent calls to
1907@samp{start} or @samp{run}.
1908
1909It is sometimes necessary to debug the program during elaboration. In
1910these cases, using the @code{start} command would stop the execution of
1911your program too late, as the program would have already completed the
1912elaboration phase. Under these circumstances, insert breakpoints in your
1913elaboration code before running your program.
1914@end table
1915
6d2ebf8b 1916@node Arguments
c906108c
SS
1917@section Your program's arguments
1918
1919@cindex arguments (to your program)
1920The arguments to your program can be specified by the arguments of the
5d161b24 1921@code{run} command.
c906108c
SS
1922They are passed to a shell, which expands wildcard characters and
1923performs redirection of I/O, and thence to your program. Your
1924@code{SHELL} environment variable (if it exists) specifies what shell
1925@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1926the default shell (@file{/bin/sh} on Unix).
1927
1928On non-Unix systems, the program is usually invoked directly by
1929@value{GDBN}, which emulates I/O redirection via the appropriate system
1930calls, and the wildcard characters are expanded by the startup code of
1931the program, not by the shell.
c906108c
SS
1932
1933@code{run} with no arguments uses the same arguments used by the previous
1934@code{run}, or those set by the @code{set args} command.
1935
c906108c 1936@table @code
41afff9a 1937@kindex set args
c906108c
SS
1938@item set args
1939Specify the arguments to be used the next time your program is run. If
1940@code{set args} has no arguments, @code{run} executes your program
1941with no arguments. Once you have run your program with arguments,
1942using @code{set args} before the next @code{run} is the only way to run
1943it again without arguments.
1944
1945@kindex show args
1946@item show args
1947Show the arguments to give your program when it is started.
1948@end table
1949
6d2ebf8b 1950@node Environment
c906108c
SS
1951@section Your program's environment
1952
1953@cindex environment (of your program)
1954The @dfn{environment} consists of a set of environment variables and
1955their values. Environment variables conventionally record such things as
1956your user name, your home directory, your terminal type, and your search
1957path for programs to run. Usually you set up environment variables with
1958the shell and they are inherited by all the other programs you run. When
1959debugging, it can be useful to try running your program with a modified
1960environment without having to start @value{GDBN} over again.
1961
1962@table @code
1963@kindex path
1964@item path @var{directory}
1965Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1966(the search path for executables) that will be passed to your program.
1967The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1968You may specify several directory names, separated by whitespace or by a
1969system-dependent separator character (@samp{:} on Unix, @samp{;} on
1970MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1971is moved to the front, so it is searched sooner.
c906108c
SS
1972
1973You can use the string @samp{$cwd} to refer to whatever is the current
1974working directory at the time @value{GDBN} searches the path. If you
1975use @samp{.} instead, it refers to the directory where you executed the
1976@code{path} command. @value{GDBN} replaces @samp{.} in the
1977@var{directory} argument (with the current path) before adding
1978@var{directory} to the search path.
1979@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1980@c document that, since repeating it would be a no-op.
1981
1982@kindex show paths
1983@item show paths
1984Display the list of search paths for executables (the @code{PATH}
1985environment variable).
1986
1987@kindex show environment
1988@item show environment @r{[}@var{varname}@r{]}
1989Print the value of environment variable @var{varname} to be given to
1990your program when it starts. If you do not supply @var{varname},
1991print the names and values of all environment variables to be given to
1992your program. You can abbreviate @code{environment} as @code{env}.
1993
1994@kindex set environment
53a5351d 1995@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1996Set environment variable @var{varname} to @var{value}. The value
1997changes for your program only, not for @value{GDBN} itself. @var{value} may
1998be any string; the values of environment variables are just strings, and
1999any interpretation is supplied by your program itself. The @var{value}
2000parameter is optional; if it is eliminated, the variable is set to a
2001null value.
2002@c "any string" here does not include leading, trailing
2003@c blanks. Gnu asks: does anyone care?
2004
2005For example, this command:
2006
474c8240 2007@smallexample
c906108c 2008set env USER = foo
474c8240 2009@end smallexample
c906108c
SS
2010
2011@noindent
d4f3574e 2012tells the debugged program, when subsequently run, that its user is named
c906108c
SS
2013@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2014are not actually required.)
2015
2016@kindex unset environment
2017@item unset environment @var{varname}
2018Remove variable @var{varname} from the environment to be passed to your
2019program. This is different from @samp{set env @var{varname} =};
2020@code{unset environment} removes the variable from the environment,
2021rather than assigning it an empty value.
2022@end table
2023
d4f3574e
SS
2024@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2025the shell indicated
c906108c
SS
2026by your @code{SHELL} environment variable if it exists (or
2027@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2028that runs an initialization file---such as @file{.cshrc} for C-shell, or
2029@file{.bashrc} for BASH---any variables you set in that file affect
2030your program. You may wish to move setting of environment variables to
2031files that are only run when you sign on, such as @file{.login} or
2032@file{.profile}.
2033
6d2ebf8b 2034@node Working Directory
c906108c
SS
2035@section Your program's working directory
2036
2037@cindex working directory (of your program)
2038Each time you start your program with @code{run}, it inherits its
2039working directory from the current working directory of @value{GDBN}.
2040The @value{GDBN} working directory is initially whatever it inherited
2041from its parent process (typically the shell), but you can specify a new
2042working directory in @value{GDBN} with the @code{cd} command.
2043
2044The @value{GDBN} working directory also serves as a default for the commands
2045that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
2046specify files}.
2047
2048@table @code
2049@kindex cd
721c2651 2050@cindex change working directory
c906108c
SS
2051@item cd @var{directory}
2052Set the @value{GDBN} working directory to @var{directory}.
2053
2054@kindex pwd
2055@item pwd
2056Print the @value{GDBN} working directory.
2057@end table
2058
60bf7e09
EZ
2059It is generally impossible to find the current working directory of
2060the process being debugged (since a program can change its directory
2061during its run). If you work on a system where @value{GDBN} is
2062configured with the @file{/proc} support, you can use the @code{info
2063proc} command (@pxref{SVR4 Process Information}) to find out the
2064current working directory of the debuggee.
2065
6d2ebf8b 2066@node Input/Output
c906108c
SS
2067@section Your program's input and output
2068
2069@cindex redirection
2070@cindex i/o
2071@cindex terminal
2072By default, the program you run under @value{GDBN} does input and output to
5d161b24 2073the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2074to its own terminal modes to interact with you, but it records the terminal
2075modes your program was using and switches back to them when you continue
2076running your program.
2077
2078@table @code
2079@kindex info terminal
2080@item info terminal
2081Displays information recorded by @value{GDBN} about the terminal modes your
2082program is using.
2083@end table
2084
2085You can redirect your program's input and/or output using shell
2086redirection with the @code{run} command. For example,
2087
474c8240 2088@smallexample
c906108c 2089run > outfile
474c8240 2090@end smallexample
c906108c
SS
2091
2092@noindent
2093starts your program, diverting its output to the file @file{outfile}.
2094
2095@kindex tty
2096@cindex controlling terminal
2097Another way to specify where your program should do input and output is
2098with the @code{tty} command. This command accepts a file name as
2099argument, and causes this file to be the default for future @code{run}
2100commands. It also resets the controlling terminal for the child
2101process, for future @code{run} commands. For example,
2102
474c8240 2103@smallexample
c906108c 2104tty /dev/ttyb
474c8240 2105@end smallexample
c906108c
SS
2106
2107@noindent
2108directs that processes started with subsequent @code{run} commands
2109default to do input and output on the terminal @file{/dev/ttyb} and have
2110that as their controlling terminal.
2111
2112An explicit redirection in @code{run} overrides the @code{tty} command's
2113effect on the input/output device, but not its effect on the controlling
2114terminal.
2115
2116When you use the @code{tty} command or redirect input in the @code{run}
2117command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2118for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2119for @code{set inferior-tty}.
2120
2121@cindex inferior tty
2122@cindex set inferior controlling terminal
2123You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2124display the name of the terminal that will be used for future runs of your
2125program.
2126
2127@table @code
2128@item set inferior-tty /dev/ttyb
2129@kindex set inferior-tty
2130Set the tty for the program being debugged to /dev/ttyb.
2131
2132@item show inferior-tty
2133@kindex show inferior-tty
2134Show the current tty for the program being debugged.
2135@end table
c906108c 2136
6d2ebf8b 2137@node Attach
c906108c
SS
2138@section Debugging an already-running process
2139@kindex attach
2140@cindex attach
2141
2142@table @code
2143@item attach @var{process-id}
2144This command attaches to a running process---one that was started
2145outside @value{GDBN}. (@code{info files} shows your active
2146targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2147find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2148or with the @samp{jobs -l} shell command.
2149
2150@code{attach} does not repeat if you press @key{RET} a second time after
2151executing the command.
2152@end table
2153
2154To use @code{attach}, your program must be running in an environment
2155which supports processes; for example, @code{attach} does not work for
2156programs on bare-board targets that lack an operating system. You must
2157also have permission to send the process a signal.
2158
2159When you use @code{attach}, the debugger finds the program running in
2160the process first by looking in the current working directory, then (if
2161the program is not found) by using the source file search path
2162(@pxref{Source Path, ,Specifying source directories}). You can also use
2163the @code{file} command to load the program. @xref{Files, ,Commands to
2164Specify Files}.
2165
2166The first thing @value{GDBN} does after arranging to debug the specified
2167process is to stop it. You can examine and modify an attached process
53a5351d
JM
2168with all the @value{GDBN} commands that are ordinarily available when
2169you start processes with @code{run}. You can insert breakpoints; you
2170can step and continue; you can modify storage. If you would rather the
2171process continue running, you may use the @code{continue} command after
c906108c
SS
2172attaching @value{GDBN} to the process.
2173
2174@table @code
2175@kindex detach
2176@item detach
2177When you have finished debugging the attached process, you can use the
2178@code{detach} command to release it from @value{GDBN} control. Detaching
2179the process continues its execution. After the @code{detach} command,
2180that process and @value{GDBN} become completely independent once more, and you
2181are ready to @code{attach} another process or start one with @code{run}.
2182@code{detach} does not repeat if you press @key{RET} again after
2183executing the command.
2184@end table
2185
2186If you exit @value{GDBN} or use the @code{run} command while you have an
2187attached process, you kill that process. By default, @value{GDBN} asks
2188for confirmation if you try to do either of these things; you can
2189control whether or not you need to confirm by using the @code{set
2190confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2191messages}).
2192
6d2ebf8b 2193@node Kill Process
c906108c 2194@section Killing the child process
c906108c
SS
2195
2196@table @code
2197@kindex kill
2198@item kill
2199Kill the child process in which your program is running under @value{GDBN}.
2200@end table
2201
2202This command is useful if you wish to debug a core dump instead of a
2203running process. @value{GDBN} ignores any core dump file while your program
2204is running.
2205
2206On some operating systems, a program cannot be executed outside @value{GDBN}
2207while you have breakpoints set on it inside @value{GDBN}. You can use the
2208@code{kill} command in this situation to permit running your program
2209outside the debugger.
2210
2211The @code{kill} command is also useful if you wish to recompile and
2212relink your program, since on many systems it is impossible to modify an
2213executable file while it is running in a process. In this case, when you
2214next type @code{run}, @value{GDBN} notices that the file has changed, and
2215reads the symbol table again (while trying to preserve your current
2216breakpoint settings).
2217
6d2ebf8b 2218@node Threads
c906108c 2219@section Debugging programs with multiple threads
c906108c
SS
2220
2221@cindex threads of execution
2222@cindex multiple threads
2223@cindex switching threads
2224In some operating systems, such as HP-UX and Solaris, a single program
2225may have more than one @dfn{thread} of execution. The precise semantics
2226of threads differ from one operating system to another, but in general
2227the threads of a single program are akin to multiple processes---except
2228that they share one address space (that is, they can all examine and
2229modify the same variables). On the other hand, each thread has its own
2230registers and execution stack, and perhaps private memory.
2231
2232@value{GDBN} provides these facilities for debugging multi-thread
2233programs:
2234
2235@itemize @bullet
2236@item automatic notification of new threads
2237@item @samp{thread @var{threadno}}, a command to switch among threads
2238@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2239@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2240a command to apply a command to a list of threads
2241@item thread-specific breakpoints
2242@end itemize
2243
c906108c
SS
2244@quotation
2245@emph{Warning:} These facilities are not yet available on every
2246@value{GDBN} configuration where the operating system supports threads.
2247If your @value{GDBN} does not support threads, these commands have no
2248effect. For example, a system without thread support shows no output
2249from @samp{info threads}, and always rejects the @code{thread} command,
2250like this:
2251
2252@smallexample
2253(@value{GDBP}) info threads
2254(@value{GDBP}) thread 1
2255Thread ID 1 not known. Use the "info threads" command to
2256see the IDs of currently known threads.
2257@end smallexample
2258@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2259@c doesn't support threads"?
2260@end quotation
c906108c
SS
2261
2262@cindex focus of debugging
2263@cindex current thread
2264The @value{GDBN} thread debugging facility allows you to observe all
2265threads while your program runs---but whenever @value{GDBN} takes
2266control, one thread in particular is always the focus of debugging.
2267This thread is called the @dfn{current thread}. Debugging commands show
2268program information from the perspective of the current thread.
2269
41afff9a 2270@cindex @code{New} @var{systag} message
c906108c
SS
2271@cindex thread identifier (system)
2272@c FIXME-implementors!! It would be more helpful if the [New...] message
2273@c included GDB's numeric thread handle, so you could just go to that
2274@c thread without first checking `info threads'.
2275Whenever @value{GDBN} detects a new thread in your program, it displays
2276the target system's identification for the thread with a message in the
2277form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2278whose form varies depending on the particular system. For example, on
2279LynxOS, you might see
2280
474c8240 2281@smallexample
c906108c 2282[New process 35 thread 27]
474c8240 2283@end smallexample
c906108c
SS
2284
2285@noindent
2286when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2287the @var{systag} is simply something like @samp{process 368}, with no
2288further qualifier.
2289
2290@c FIXME!! (1) Does the [New...] message appear even for the very first
2291@c thread of a program, or does it only appear for the
6ca652b0 2292@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2293@c program?
2294@c (2) *Is* there necessarily a first thread always? Or do some
2295@c multithread systems permit starting a program with multiple
5d161b24 2296@c threads ab initio?
c906108c
SS
2297
2298@cindex thread number
2299@cindex thread identifier (GDB)
2300For debugging purposes, @value{GDBN} associates its own thread
2301number---always a single integer---with each thread in your program.
2302
2303@table @code
2304@kindex info threads
2305@item info threads
2306Display a summary of all threads currently in your
2307program. @value{GDBN} displays for each thread (in this order):
2308
2309@enumerate
09d4efe1
EZ
2310@item
2311the thread number assigned by @value{GDBN}
c906108c 2312
09d4efe1
EZ
2313@item
2314the target system's thread identifier (@var{systag})
c906108c 2315
09d4efe1
EZ
2316@item
2317the current stack frame summary for that thread
c906108c
SS
2318@end enumerate
2319
2320@noindent
2321An asterisk @samp{*} to the left of the @value{GDBN} thread number
2322indicates the current thread.
2323
5d161b24 2324For example,
c906108c
SS
2325@end table
2326@c end table here to get a little more width for example
2327
2328@smallexample
2329(@value{GDBP}) info threads
2330 3 process 35 thread 27 0x34e5 in sigpause ()
2331 2 process 35 thread 23 0x34e5 in sigpause ()
2332* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2333 at threadtest.c:68
2334@end smallexample
53a5351d
JM
2335
2336On HP-UX systems:
c906108c 2337
4644b6e3
EZ
2338@cindex debugging multithreaded programs (on HP-UX)
2339@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2340For debugging purposes, @value{GDBN} associates its own thread
2341number---a small integer assigned in thread-creation order---with each
2342thread in your program.
2343
41afff9a
EZ
2344@cindex @code{New} @var{systag} message, on HP-UX
2345@cindex thread identifier (system), on HP-UX
c906108c
SS
2346@c FIXME-implementors!! It would be more helpful if the [New...] message
2347@c included GDB's numeric thread handle, so you could just go to that
2348@c thread without first checking `info threads'.
2349Whenever @value{GDBN} detects a new thread in your program, it displays
2350both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2351form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2352whose form varies depending on the particular system. For example, on
2353HP-UX, you see
2354
474c8240 2355@smallexample
c906108c 2356[New thread 2 (system thread 26594)]
474c8240 2357@end smallexample
c906108c
SS
2358
2359@noindent
5d161b24 2360when @value{GDBN} notices a new thread.
c906108c
SS
2361
2362@table @code
4644b6e3 2363@kindex info threads (HP-UX)
c906108c
SS
2364@item info threads
2365Display a summary of all threads currently in your
2366program. @value{GDBN} displays for each thread (in this order):
2367
2368@enumerate
2369@item the thread number assigned by @value{GDBN}
2370
2371@item the target system's thread identifier (@var{systag})
2372
2373@item the current stack frame summary for that thread
2374@end enumerate
2375
2376@noindent
2377An asterisk @samp{*} to the left of the @value{GDBN} thread number
2378indicates the current thread.
2379
5d161b24 2380For example,
c906108c
SS
2381@end table
2382@c end table here to get a little more width for example
2383
474c8240 2384@smallexample
c906108c 2385(@value{GDBP}) info threads
6d2ebf8b
SS
2386 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2387 at quicksort.c:137
2388 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2389 from /usr/lib/libc.2
2390 1 system thread 27905 0x7b003498 in _brk () \@*
2391 from /usr/lib/libc.2
474c8240 2392@end smallexample
c906108c 2393
c45da7e6
EZ
2394On Solaris, you can display more information about user threads with a
2395Solaris-specific command:
2396
2397@table @code
2398@item maint info sol-threads
2399@kindex maint info sol-threads
2400@cindex thread info (Solaris)
2401Display info on Solaris user threads.
2402@end table
2403
c906108c
SS
2404@table @code
2405@kindex thread @var{threadno}
2406@item thread @var{threadno}
2407Make thread number @var{threadno} the current thread. The command
2408argument @var{threadno} is the internal @value{GDBN} thread number, as
2409shown in the first field of the @samp{info threads} display.
2410@value{GDBN} responds by displaying the system identifier of the thread
2411you selected, and its current stack frame summary:
2412
2413@smallexample
2414@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2415(@value{GDBP}) thread 2
c906108c 2416[Switching to process 35 thread 23]
c906108c
SS
24170x34e5 in sigpause ()
2418@end smallexample
2419
2420@noindent
2421As with the @samp{[New @dots{}]} message, the form of the text after
2422@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2423threads.
c906108c 2424
9c16f35a 2425@kindex thread apply
638ac427 2426@cindex apply command to several threads
c906108c
SS
2427@item thread apply [@var{threadno}] [@var{all}] @var{args}
2428The @code{thread apply} command allows you to apply a command to one or
2429more threads. Specify the numbers of the threads that you want affected
2430with the command argument @var{threadno}. @var{threadno} is the internal
2431@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2432threads} display. To apply a command to all threads, use
2433@code{thread apply all} @var{args}.
c906108c
SS
2434@end table
2435
2436@cindex automatic thread selection
2437@cindex switching threads automatically
2438@cindex threads, automatic switching
2439Whenever @value{GDBN} stops your program, due to a breakpoint or a
2440signal, it automatically selects the thread where that breakpoint or
2441signal happened. @value{GDBN} alerts you to the context switch with a
2442message of the form @samp{[Switching to @var{systag}]} to identify the
2443thread.
2444
2445@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2446more information about how @value{GDBN} behaves when you stop and start
2447programs with multiple threads.
2448
2449@xref{Set Watchpoints,,Setting watchpoints}, for information about
2450watchpoints in programs with multiple threads.
c906108c 2451
6d2ebf8b 2452@node Processes
c906108c
SS
2453@section Debugging programs with multiple processes
2454
2455@cindex fork, debugging programs which call
2456@cindex multiple processes
2457@cindex processes, multiple
53a5351d
JM
2458On most systems, @value{GDBN} has no special support for debugging
2459programs which create additional processes using the @code{fork}
2460function. When a program forks, @value{GDBN} will continue to debug the
2461parent process and the child process will run unimpeded. If you have
2462set a breakpoint in any code which the child then executes, the child
2463will get a @code{SIGTRAP} signal which (unless it catches the signal)
2464will cause it to terminate.
c906108c
SS
2465
2466However, if you want to debug the child process there is a workaround
2467which isn't too painful. Put a call to @code{sleep} in the code which
2468the child process executes after the fork. It may be useful to sleep
2469only if a certain environment variable is set, or a certain file exists,
2470so that the delay need not occur when you don't want to run @value{GDBN}
2471on the child. While the child is sleeping, use the @code{ps} program to
2472get its process ID. Then tell @value{GDBN} (a new invocation of
2473@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2474the child process (@pxref{Attach}). From that point on you can debug
c906108c 2475the child process just like any other process which you attached to.
c906108c 2476
b51970ac
DJ
2477On some systems, @value{GDBN} provides support for debugging programs that
2478create additional processes using the @code{fork} or @code{vfork} functions.
2479Currently, the only platforms with this feature are HP-UX (11.x and later
2480only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2481
2482By default, when a program forks, @value{GDBN} will continue to debug
2483the parent process and the child process will run unimpeded.
2484
2485If you want to follow the child process instead of the parent process,
2486use the command @w{@code{set follow-fork-mode}}.
2487
2488@table @code
2489@kindex set follow-fork-mode
2490@item set follow-fork-mode @var{mode}
2491Set the debugger response to a program call of @code{fork} or
2492@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 2493process. The @var{mode} argument can be:
c906108c
SS
2494
2495@table @code
2496@item parent
2497The original process is debugged after a fork. The child process runs
2df3850c 2498unimpeded. This is the default.
c906108c
SS
2499
2500@item child
2501The new process is debugged after a fork. The parent process runs
2502unimpeded.
2503
c906108c
SS
2504@end table
2505
9c16f35a 2506@kindex show follow-fork-mode
c906108c 2507@item show follow-fork-mode
2df3850c 2508Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2509@end table
2510
5c95884b
MS
2511@cindex debugging multiple processes
2512On Linux, if you want to debug both the parent and child processes, use the
2513command @w{@code{set detach-on-fork}}.
2514
2515@table @code
2516@kindex set detach-on-fork
2517@item set detach-on-fork @var{mode}
2518Tells gdb whether to detach one of the processes after a fork, or
2519retain debugger control over them both.
2520
2521@table @code
2522@item on
2523The child process (or parent process, depending on the value of
2524@code{follow-fork-mode}) will be detached and allowed to run
2525independently. This is the default.
2526
2527@item off
2528Both processes will be held under the control of @value{GDBN}.
2529One process (child or parent, depending on the value of
2530@code{follow-fork-mode}) is debugged as usual, while the other
2531is held suspended.
2532
2533@end table
2534
2535@kindex show detach-on-follow
2536@item show detach-on-follow
2537Show whether detach-on-follow mode is on/off.
2538@end table
2539
2540If you choose to set @var{detach-on-follow} mode off, then
2541@value{GDBN} will retain control of all forked processes (including
2542nested forks). You can list the forked processes under the control of
2543@value{GDBN} by using the @w{@code{info forks}} command, and switch
2544from one fork to another by using the @w{@code{fork}} command.
2545
2546@table @code
2547@kindex info forks
2548@item info forks
2549Print a list of all forked processes under the control of @value{GDBN}.
2550The listing will include a fork id, a process id, and the current
2551position (program counter) of the process.
2552
2553
2554@kindex fork @var{fork-id}
2555@item fork @var{fork-id}
2556Make fork number @var{fork-id} the current process. The argument
2557@var{fork-id} is the internal fork number assigned by @value{GDBN},
2558as shown in the first field of the @samp{info forks} display.
2559
2560@end table
2561
2562To quit debugging one of the forked processes, you can either detach
2563from it by using the @w{@code{detach-fork}} command (allowing it to
2564run independently), or delete (and kill) it using the
2565@w{@code{delete-fork}} command.
2566
2567@table @code
2568@kindex detach-fork @var{fork-id}
2569@item detach-fork @var{fork-id}
2570Detach from the process identified by @value{GDBN} fork number
2571@var{fork-id}, and remove it from the fork list. The process will be
2572allowed to run independently.
2573
2574@kindex delete-fork @var{fork-id}
2575@item delete-fork @var{fork-id}
2576Kill the process identified by @value{GDBN} fork number @var{fork-id},
2577and remove it from the fork list.
2578
2579@end table
2580
c906108c
SS
2581If you ask to debug a child process and a @code{vfork} is followed by an
2582@code{exec}, @value{GDBN} executes the new target up to the first
2583breakpoint in the new target. If you have a breakpoint set on
2584@code{main} in your original program, the breakpoint will also be set on
2585the child process's @code{main}.
2586
2587When a child process is spawned by @code{vfork}, you cannot debug the
2588child or parent until an @code{exec} call completes.
2589
2590If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2591call executes, the new target restarts. To restart the parent process,
2592use the @code{file} command with the parent executable name as its
2593argument.
2594
2595You can use the @code{catch} command to make @value{GDBN} stop whenever
2596a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2597Catchpoints, ,Setting catchpoints}.
c906108c 2598
5c95884b
MS
2599@node Checkpoint/Restart
2600@section Setting a @emph{bookmark} to return to later
2601
2602@cindex checkpoint
2603@cindex restart
2604@cindex bookmark
2605@cindex snapshot of a process
2606@cindex rewind program state
2607
2608On certain operating systems@footnote{Currently, only
2609@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
2610program's state, called a @dfn{checkpoint}, and come back to it
2611later.
2612
2613Returning to a checkpoint effectively undoes everything that has
2614happened in the program since the @code{checkpoint} was saved. This
2615includes changes in memory, registers, and even (within some limits)
2616system state. Effectively, it is like going back in time to the
2617moment when the checkpoint was saved.
2618
2619Thus, if you're stepping thru a program and you think you're
2620getting close to the point where things go wrong, you can save
2621a checkpoint. Then, if you accidentally go too far and miss
2622the critical statement, instead of having to restart your program
2623from the beginning, you can just go back to the checkpoint and
2624start again from there.
2625
2626This can be especially useful if it takes a lot of time or
2627steps to reach the point where you think the bug occurs.
2628
2629To use the @code{checkpoint}/@code{restart} method of debugging:
2630
2631@table @code
2632@kindex checkpoint
2633@item checkpoint
2634Save a snapshot of the debugged program's current execution state.
2635The @code{checkpoint} command takes no arguments, but each checkpoint
2636is assigned a small integer id, similar to a breakpoint id.
2637
2638@kindex info checkpoints
2639@item info checkpoints
2640List the checkpoints that have been saved in the current debugging
2641session. For each checkpoint, the following information will be
2642listed:
2643
2644@table @code
2645@item Checkpoint ID
2646@item Process ID
2647@item Code Address
2648@item Source line, or label
2649@end table
2650
2651@kindex restart @var{checkpoint-id}
2652@item restart @var{checkpoint-id}
2653Restore the program state that was saved as checkpoint number
2654@var{checkpoint-id}. All program variables, registers, stack frames
2655etc.@: will be returned to the values that they had when the checkpoint
2656was saved. In essence, gdb will ``wind back the clock'' to the point
2657in time when the checkpoint was saved.
2658
2659Note that breakpoints, @value{GDBN} variables, command history etc.
2660are not affected by restoring a checkpoint. In general, a checkpoint
2661only restores things that reside in the program being debugged, not in
2662the debugger.
2663
2664@kindex delete-checkpoint @var{checkpoint-id}
2665@item delete-checkpoint @var{checkpoint-id}
2666Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
2667
2668@end table
2669
2670Returning to a previously saved checkpoint will restore the user state
2671of the program being debugged, plus a significant subset of the system
2672(OS) state, including file pointers. It won't ``un-write'' data from
2673a file, but it will rewind the file pointer to the previous location,
2674so that the previously written data can be overwritten. For files
2675opened in read mode, the pointer will also be restored so that the
2676previously read data can be read again.
2677
2678Of course, characters that have been sent to a printer (or other
2679external device) cannot be ``snatched back'', and characters received
2680from eg.@: a serial device can be removed from internal program buffers,
2681but they cannot be ``pushed back'' into the serial pipeline, ready to
2682be received again. Similarly, the actual contents of files that have
2683been changed cannot be restored (at this time).
2684
2685However, within those constraints, you actually can ``rewind'' your
2686program to a previously saved point in time, and begin debugging it
2687again --- and you can change the course of events so as to debug a
2688different execution path this time.
2689
2690@cindex checkpoints and process id
2691Finally, there is one bit of internal program state that will be
2692different when you return to a checkpoint --- the program's process
2693id. Each checkpoint will have a unique process id (or @var{pid}),
2694and each will be different from the program's original @var{pid}.
2695If your program has saved a local copy of its process id, this could
2696potentially pose a problem.
2697
2698@subsection A non-obvious benefit of using checkpoints
2699
2700On some systems such as @sc{gnu}/Linux, address space randomization
2701is performed on new processes for security reasons. This makes it
2702difficult or impossible to set a breakpoint, or watchpoint, on an
2703absolute address if you have to restart the program, since the
2704absolute location of a symbol will change from one execution to the
2705next.
2706
2707A checkpoint, however, is an @emph{identical} copy of a process.
2708Therefore if you create a checkpoint at (eg.@:) the start of main,
2709and simply return to that checkpoint instead of restarting the
2710process, you can avoid the effects of address randomization and
2711your symbols will all stay in the same place.
2712
6d2ebf8b 2713@node Stopping
c906108c
SS
2714@chapter Stopping and Continuing
2715
2716The principal purposes of using a debugger are so that you can stop your
2717program before it terminates; or so that, if your program runs into
2718trouble, you can investigate and find out why.
2719
7a292a7a
SS
2720Inside @value{GDBN}, your program may stop for any of several reasons,
2721such as a signal, a breakpoint, or reaching a new line after a
2722@value{GDBN} command such as @code{step}. You may then examine and
2723change variables, set new breakpoints or remove old ones, and then
2724continue execution. Usually, the messages shown by @value{GDBN} provide
2725ample explanation of the status of your program---but you can also
2726explicitly request this information at any time.
c906108c
SS
2727
2728@table @code
2729@kindex info program
2730@item info program
2731Display information about the status of your program: whether it is
7a292a7a 2732running or not, what process it is, and why it stopped.
c906108c
SS
2733@end table
2734
2735@menu
2736* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2737* Continuing and Stepping:: Resuming execution
c906108c 2738* Signals:: Signals
c906108c 2739* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2740@end menu
2741
6d2ebf8b 2742@node Breakpoints
c906108c
SS
2743@section Breakpoints, watchpoints, and catchpoints
2744
2745@cindex breakpoints
2746A @dfn{breakpoint} makes your program stop whenever a certain point in
2747the program is reached. For each breakpoint, you can add conditions to
2748control in finer detail whether your program stops. You can set
2749breakpoints with the @code{break} command and its variants (@pxref{Set
2750Breaks, ,Setting breakpoints}), to specify the place where your program
2751should stop by line number, function name or exact address in the
2752program.
2753
09d4efe1
EZ
2754On some systems, you can set breakpoints in shared libraries before
2755the executable is run. There is a minor limitation on HP-UX systems:
2756you must wait until the executable is run in order to set breakpoints
2757in shared library routines that are not called directly by the program
2758(for example, routines that are arguments in a @code{pthread_create}
2759call).
c906108c
SS
2760
2761@cindex watchpoints
2762@cindex memory tracing
2763@cindex breakpoint on memory address
2764@cindex breakpoint on variable modification
2765A @dfn{watchpoint} is a special breakpoint that stops your program
2766when the value of an expression changes. You must use a different
2767command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2768watchpoints}), but aside from that, you can manage a watchpoint like
2769any other breakpoint: you enable, disable, and delete both breakpoints
2770and watchpoints using the same commands.
2771
2772You can arrange to have values from your program displayed automatically
2773whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2774Automatic display}.
2775
2776@cindex catchpoints
2777@cindex breakpoint on events
2778A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2779when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2780exception or the loading of a library. As with watchpoints, you use a
2781different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2782catchpoints}), but aside from that, you can manage a catchpoint like any
2783other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2784@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2785
2786@cindex breakpoint numbers
2787@cindex numbers for breakpoints
2788@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2789catchpoint when you create it; these numbers are successive integers
2790starting with one. In many of the commands for controlling various
2791features of breakpoints you use the breakpoint number to say which
2792breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2793@dfn{disabled}; if disabled, it has no effect on your program until you
2794enable it again.
2795
c5394b80
JM
2796@cindex breakpoint ranges
2797@cindex ranges of breakpoints
2798Some @value{GDBN} commands accept a range of breakpoints on which to
2799operate. A breakpoint range is either a single breakpoint number, like
2800@samp{5}, or two such numbers, in increasing order, separated by a
2801hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2802all breakpoint in that range are operated on.
2803
c906108c
SS
2804@menu
2805* Set Breaks:: Setting breakpoints
2806* Set Watchpoints:: Setting watchpoints
2807* Set Catchpoints:: Setting catchpoints
2808* Delete Breaks:: Deleting breakpoints
2809* Disabling:: Disabling breakpoints
2810* Conditions:: Break conditions
2811* Break Commands:: Breakpoint command lists
c906108c 2812* Breakpoint Menus:: Breakpoint menus
d4f3574e 2813* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2814* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2815@end menu
2816
6d2ebf8b 2817@node Set Breaks
c906108c
SS
2818@subsection Setting breakpoints
2819
5d161b24 2820@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2821@c consider in particular declaration with/without initialization.
2822@c
2823@c FIXME 2 is there stuff on this already? break at fun start, already init?
2824
2825@kindex break
41afff9a
EZ
2826@kindex b @r{(@code{break})}
2827@vindex $bpnum@r{, convenience variable}
c906108c
SS
2828@cindex latest breakpoint
2829Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2830@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2831number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2832Vars,, Convenience variables}, for a discussion of what you can do with
2833convenience variables.
2834
2835You have several ways to say where the breakpoint should go.
2836
2837@table @code
2838@item break @var{function}
5d161b24 2839Set a breakpoint at entry to function @var{function}.
c906108c 2840When using source languages that permit overloading of symbols, such as
b37052ae 2841C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2842@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2843
2844@item break +@var{offset}
2845@itemx break -@var{offset}
2846Set a breakpoint some number of lines forward or back from the position
d4f3574e 2847at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2848(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2849
2850@item break @var{linenum}
2851Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2852The current source file is the last file whose source text was printed.
2853The breakpoint will stop your program just before it executes any of the
c906108c
SS
2854code on that line.
2855
2856@item break @var{filename}:@var{linenum}
2857Set a breakpoint at line @var{linenum} in source file @var{filename}.
2858
2859@item break @var{filename}:@var{function}
2860Set a breakpoint at entry to function @var{function} found in file
2861@var{filename}. Specifying a file name as well as a function name is
2862superfluous except when multiple files contain similarly named
2863functions.
2864
2865@item break *@var{address}
2866Set a breakpoint at address @var{address}. You can use this to set
2867breakpoints in parts of your program which do not have debugging
2868information or source files.
2869
2870@item break
2871When called without any arguments, @code{break} sets a breakpoint at
2872the next instruction to be executed in the selected stack frame
2873(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2874innermost, this makes your program stop as soon as control
2875returns to that frame. This is similar to the effect of a
2876@code{finish} command in the frame inside the selected frame---except
2877that @code{finish} does not leave an active breakpoint. If you use
2878@code{break} without an argument in the innermost frame, @value{GDBN} stops
2879the next time it reaches the current location; this may be useful
2880inside loops.
2881
2882@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2883least one instruction has been executed. If it did not do this, you
2884would be unable to proceed past a breakpoint without first disabling the
2885breakpoint. This rule applies whether or not the breakpoint already
2886existed when your program stopped.
2887
2888@item break @dots{} if @var{cond}
2889Set a breakpoint with condition @var{cond}; evaluate the expression
2890@var{cond} each time the breakpoint is reached, and stop only if the
2891value is nonzero---that is, if @var{cond} evaluates as true.
2892@samp{@dots{}} stands for one of the possible arguments described
2893above (or no argument) specifying where to break. @xref{Conditions,
2894,Break conditions}, for more information on breakpoint conditions.
2895
2896@kindex tbreak
2897@item tbreak @var{args}
2898Set a breakpoint enabled only for one stop. @var{args} are the
2899same as for the @code{break} command, and the breakpoint is set in the same
2900way, but the breakpoint is automatically deleted after the first time your
2901program stops there. @xref{Disabling, ,Disabling breakpoints}.
2902
c906108c 2903@kindex hbreak
ba04e063 2904@cindex hardware breakpoints
c906108c 2905@item hbreak @var{args}
d4f3574e
SS
2906Set a hardware-assisted breakpoint. @var{args} are the same as for the
2907@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2908breakpoint requires hardware support and some target hardware may not
2909have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2910debugging, so you can set a breakpoint at an instruction without
2911changing the instruction. This can be used with the new trap-generation
09d4efe1 2912provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
2913will generate traps when a program accesses some data or instruction
2914address that is assigned to the debug registers. However the hardware
2915breakpoint registers can take a limited number of breakpoints. For
2916example, on the DSU, only two data breakpoints can be set at a time, and
2917@value{GDBN} will reject this command if more than two are used. Delete
2918or disable unused hardware breakpoints before setting new ones
2919(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
9c16f35a
EZ
2920For remote targets, you can restrict the number of hardware
2921breakpoints @value{GDBN} will use, see @ref{set remote
2922hardware-breakpoint-limit}.
501eef12 2923
c906108c
SS
2924
2925@kindex thbreak
2926@item thbreak @var{args}
2927Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2928are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2929the same way. However, like the @code{tbreak} command,
c906108c
SS
2930the breakpoint is automatically deleted after the
2931first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2932command, the breakpoint requires hardware support and some target hardware
2933may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2934See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2935
2936@kindex rbreak
2937@cindex regular expression
c45da7e6
EZ
2938@cindex breakpoints in functions matching a regexp
2939@cindex set breakpoints in many functions
c906108c 2940@item rbreak @var{regex}
c906108c 2941Set breakpoints on all functions matching the regular expression
11cf8741
JM
2942@var{regex}. This command sets an unconditional breakpoint on all
2943matches, printing a list of all breakpoints it set. Once these
2944breakpoints are set, they are treated just like the breakpoints set with
2945the @code{break} command. You can delete them, disable them, or make
2946them conditional the same way as any other breakpoint.
2947
2948The syntax of the regular expression is the standard one used with tools
2949like @file{grep}. Note that this is different from the syntax used by
2950shells, so for instance @code{foo*} matches all functions that include
2951an @code{fo} followed by zero or more @code{o}s. There is an implicit
2952@code{.*} leading and trailing the regular expression you supply, so to
2953match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2954
f7dc1244 2955@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2956When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2957breakpoints on overloaded functions that are not members of any special
2958classes.
c906108c 2959
f7dc1244
EZ
2960@cindex set breakpoints on all functions
2961The @code{rbreak} command can be used to set breakpoints in
2962@strong{all} the functions in a program, like this:
2963
2964@smallexample
2965(@value{GDBP}) rbreak .
2966@end smallexample
2967
c906108c
SS
2968@kindex info breakpoints
2969@cindex @code{$_} and @code{info breakpoints}
2970@item info breakpoints @r{[}@var{n}@r{]}
2971@itemx info break @r{[}@var{n}@r{]}
2972@itemx info watchpoints @r{[}@var{n}@r{]}
2973Print a table of all breakpoints, watchpoints, and catchpoints set and
2974not deleted, with the following columns for each breakpoint:
2975
2976@table @emph
2977@item Breakpoint Numbers
2978@item Type
2979Breakpoint, watchpoint, or catchpoint.
2980@item Disposition
2981Whether the breakpoint is marked to be disabled or deleted when hit.
2982@item Enabled or Disabled
2983Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2984that are not enabled.
2985@item Address
2650777c
JJ
2986Where the breakpoint is in your program, as a memory address. If the
2987breakpoint is pending (see below for details) on a future load of a shared library, the address
2988will be listed as @samp{<PENDING>}.
c906108c
SS
2989@item What
2990Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
2991line number. For a pending breakpoint, the original string passed to
2992the breakpoint command will be listed as it cannot be resolved until
2993the appropriate shared library is loaded in the future.
c906108c
SS
2994@end table
2995
2996@noindent
2997If a breakpoint is conditional, @code{info break} shows the condition on
2998the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
2999are listed after that. A pending breakpoint is allowed to have a condition
3000specified for it. The condition is not parsed for validity until a shared
3001library is loaded that allows the pending breakpoint to resolve to a
3002valid location.
c906108c
SS
3003
3004@noindent
3005@code{info break} with a breakpoint
3006number @var{n} as argument lists only that breakpoint. The
3007convenience variable @code{$_} and the default examining-address for
3008the @code{x} command are set to the address of the last breakpoint
5d161b24 3009listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
3010
3011@noindent
3012@code{info break} displays a count of the number of times the breakpoint
3013has been hit. This is especially useful in conjunction with the
3014@code{ignore} command. You can ignore a large number of breakpoint
3015hits, look at the breakpoint info to see how many times the breakpoint
3016was hit, and then run again, ignoring one less than that number. This
3017will get you quickly to the last hit of that breakpoint.
3018@end table
3019
3020@value{GDBN} allows you to set any number of breakpoints at the same place in
3021your program. There is nothing silly or meaningless about this. When
3022the breakpoints are conditional, this is even useful
3023(@pxref{Conditions, ,Break conditions}).
3024
2650777c 3025@cindex pending breakpoints
dd79a6cf
JJ
3026If a specified breakpoint location cannot be found, it may be due to the fact
3027that the location is in a shared library that is yet to be loaded. In such
3028a case, you may want @value{GDBN} to create a special breakpoint (known as
3029a @dfn{pending breakpoint}) that
3030attempts to resolve itself in the future when an appropriate shared library
3031gets loaded.
3032
3033Pending breakpoints are useful to set at the start of your
2650777c
JJ
3034@value{GDBN} session for locations that you know will be dynamically loaded
3035later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
3036a check is made to see if the load resolves any pending breakpoint locations.
3037If a pending breakpoint location gets resolved,
3038a regular breakpoint is created and the original pending breakpoint is removed.
3039
3040@value{GDBN} provides some additional commands for controlling pending
3041breakpoint support:
3042
3043@kindex set breakpoint pending
3044@kindex show breakpoint pending
3045@table @code
3046@item set breakpoint pending auto
3047This is the default behavior. When @value{GDBN} cannot find the breakpoint
3048location, it queries you whether a pending breakpoint should be created.
3049
3050@item set breakpoint pending on
3051This indicates that an unrecognized breakpoint location should automatically
3052result in a pending breakpoint being created.
3053
3054@item set breakpoint pending off
3055This indicates that pending breakpoints are not to be created. Any
3056unrecognized breakpoint location results in an error. This setting does
3057not affect any pending breakpoints previously created.
3058
3059@item show breakpoint pending
3060Show the current behavior setting for creating pending breakpoints.
3061@end table
2650777c 3062
649e03f6
RM
3063@cindex operations allowed on pending breakpoints
3064Normal breakpoint operations apply to pending breakpoints as well. You may
3065specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
3066breakpoint is reached. You can also enable or disable
3067the pending breakpoint. When you specify a condition for a pending breakpoint,
3068the parsing of the condition will be deferred until the point where the
3069pending breakpoint location is resolved. Disabling a pending breakpoint
3070tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
3071shared library load. When a pending breakpoint is re-enabled,
649e03f6 3072@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
3073This is done because any number of shared library loads could have
3074occurred since the time the breakpoint was disabled and one or more
3075of these loads could resolve the location.
3076
c906108c
SS
3077@cindex negative breakpoint numbers
3078@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
3079@value{GDBN} itself sometimes sets breakpoints in your program for
3080special purposes, such as proper handling of @code{longjmp} (in C
3081programs). These internal breakpoints are assigned negative numbers,
3082starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 3083You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 3084@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
3085
3086
6d2ebf8b 3087@node Set Watchpoints
c906108c
SS
3088@subsection Setting watchpoints
3089
3090@cindex setting watchpoints
c906108c
SS
3091You can use a watchpoint to stop execution whenever the value of an
3092expression changes, without having to predict a particular place where
3093this may happen.
3094
82f2d802
EZ
3095@cindex software watchpoints
3096@cindex hardware watchpoints
c906108c 3097Depending on your system, watchpoints may be implemented in software or
2df3850c 3098hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
3099program and testing the variable's value each time, which is hundreds of
3100times slower than normal execution. (But this may still be worth it, to
3101catch errors where you have no clue what part of your program is the
3102culprit.)
3103
82f2d802
EZ
3104On some systems, such as HP-UX, @sc{gnu}/Linux and most other
3105x86-based targets, @value{GDBN} includes support for hardware
3106watchpoints, which do not slow down the running of your program.
c906108c
SS
3107
3108@table @code
3109@kindex watch
3110@item watch @var{expr}
3111Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
3112is written into by the program and its value changes.
3113
3114@kindex rwatch
3115@item rwatch @var{expr}
09d4efe1
EZ
3116Set a watchpoint that will break when the value of @var{expr} is read
3117by the program.
c906108c
SS
3118
3119@kindex awatch
3120@item awatch @var{expr}
09d4efe1
EZ
3121Set a watchpoint that will break when @var{expr} is either read from
3122or written into by the program.
c906108c
SS
3123
3124@kindex info watchpoints
3125@item info watchpoints
3126This command prints a list of watchpoints, breakpoints, and catchpoints;
09d4efe1 3127it is the same as @code{info break} (@pxref{Set Breaks}).
c906108c
SS
3128@end table
3129
3130@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
3131watchpoints execute very quickly, and the debugger reports a change in
3132value at the exact instruction where the change occurs. If @value{GDBN}
3133cannot set a hardware watchpoint, it sets a software watchpoint, which
3134executes more slowly and reports the change in value at the next
82f2d802
EZ
3135@emph{statement}, not the instruction, after the change occurs.
3136
82f2d802
EZ
3137@cindex use only software watchpoints
3138You can force @value{GDBN} to use only software watchpoints with the
3139@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
3140zero, @value{GDBN} will never try to use hardware watchpoints, even if
3141the underlying system supports them. (Note that hardware-assisted
3142watchpoints that were set @emph{before} setting
3143@code{can-use-hw-watchpoints} to zero will still use the hardware
3144mechanism of watching expressiion values.)
c906108c 3145
9c16f35a
EZ
3146@table @code
3147@item set can-use-hw-watchpoints
3148@kindex set can-use-hw-watchpoints
3149Set whether or not to use hardware watchpoints.
3150
3151@item show can-use-hw-watchpoints
3152@kindex show can-use-hw-watchpoints
3153Show the current mode of using hardware watchpoints.
3154@end table
3155
3156For remote targets, you can restrict the number of hardware
3157watchpoints @value{GDBN} will use, see @ref{set remote
3158hardware-breakpoint-limit}.
3159
c906108c
SS
3160When you issue the @code{watch} command, @value{GDBN} reports
3161
474c8240 3162@smallexample
c906108c 3163Hardware watchpoint @var{num}: @var{expr}
474c8240 3164@end smallexample
c906108c
SS
3165
3166@noindent
3167if it was able to set a hardware watchpoint.
3168
7be570e7
JM
3169Currently, the @code{awatch} and @code{rwatch} commands can only set
3170hardware watchpoints, because accesses to data that don't change the
3171value of the watched expression cannot be detected without examining
3172every instruction as it is being executed, and @value{GDBN} does not do
3173that currently. If @value{GDBN} finds that it is unable to set a
3174hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
3175will print a message like this:
3176
3177@smallexample
3178Expression cannot be implemented with read/access watchpoint.
3179@end smallexample
3180
3181Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
3182data type of the watched expression is wider than what a hardware
3183watchpoint on the target machine can handle. For example, some systems
3184can only watch regions that are up to 4 bytes wide; on such systems you
3185cannot set hardware watchpoints for an expression that yields a
3186double-precision floating-point number (which is typically 8 bytes
3187wide). As a work-around, it might be possible to break the large region
3188into a series of smaller ones and watch them with separate watchpoints.
3189
3190If you set too many hardware watchpoints, @value{GDBN} might be unable
3191to insert all of them when you resume the execution of your program.
3192Since the precise number of active watchpoints is unknown until such
3193time as the program is about to be resumed, @value{GDBN} might not be
3194able to warn you about this when you set the watchpoints, and the
3195warning will be printed only when the program is resumed:
3196
3197@smallexample
3198Hardware watchpoint @var{num}: Could not insert watchpoint
3199@end smallexample
3200
3201@noindent
3202If this happens, delete or disable some of the watchpoints.
3203
3204The SPARClite DSU will generate traps when a program accesses some data
3205or instruction address that is assigned to the debug registers. For the
3206data addresses, DSU facilitates the @code{watch} command. However the
3207hardware breakpoint registers can only take two data watchpoints, and
3208both watchpoints must be the same kind. For example, you can set two
3209watchpoints with @code{watch} commands, two with @code{rwatch} commands,
3210@strong{or} two with @code{awatch} commands, but you cannot set one
3211watchpoint with one command and the other with a different command.
c906108c
SS
3212@value{GDBN} will reject the command if you try to mix watchpoints.
3213Delete or disable unused watchpoint commands before setting new ones.
3214
3215If you call a function interactively using @code{print} or @code{call},
2df3850c 3216any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
3217kind of breakpoint or the call completes.
3218
7be570e7
JM
3219@value{GDBN} automatically deletes watchpoints that watch local
3220(automatic) variables, or expressions that involve such variables, when
3221they go out of scope, that is, when the execution leaves the block in
3222which these variables were defined. In particular, when the program
3223being debugged terminates, @emph{all} local variables go out of scope,
3224and so only watchpoints that watch global variables remain set. If you
3225rerun the program, you will need to set all such watchpoints again. One
3226way of doing that would be to set a code breakpoint at the entry to the
3227@code{main} function and when it breaks, set all the watchpoints.
3228
c906108c
SS
3229@quotation
3230@cindex watchpoints and threads
3231@cindex threads and watchpoints
c906108c
SS
3232@emph{Warning:} In multi-thread programs, watchpoints have only limited
3233usefulness. With the current watchpoint implementation, @value{GDBN}
3234can only watch the value of an expression @emph{in a single thread}. If
3235you are confident that the expression can only change due to the current
3236thread's activity (and if you are also confident that no other thread
3237can become current), then you can use watchpoints as usual. However,
3238@value{GDBN} may not notice when a non-current thread's activity changes
3239the expression.
53a5351d 3240
d4f3574e 3241@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
3242@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
3243have only limited usefulness. If @value{GDBN} creates a software
3244watchpoint, it can only watch the value of an expression @emph{in a
3245single thread}. If you are confident that the expression can only
3246change due to the current thread's activity (and if you are also
3247confident that no other thread can become current), then you can use
3248software watchpoints as usual. However, @value{GDBN} may not notice
3249when a non-current thread's activity changes the expression. (Hardware
3250watchpoints, in contrast, watch an expression in all threads.)
c906108c 3251@end quotation
c906108c 3252
501eef12
AC
3253@xref{set remote hardware-watchpoint-limit}.
3254
6d2ebf8b 3255@node Set Catchpoints
c906108c 3256@subsection Setting catchpoints
d4f3574e 3257@cindex catchpoints, setting
c906108c
SS
3258@cindex exception handlers
3259@cindex event handling
3260
3261You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 3262kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
3263shared library. Use the @code{catch} command to set a catchpoint.
3264
3265@table @code
3266@kindex catch
3267@item catch @var{event}
3268Stop when @var{event} occurs. @var{event} can be any of the following:
3269@table @code
3270@item throw
4644b6e3 3271@cindex stop on C@t{++} exceptions
b37052ae 3272The throwing of a C@t{++} exception.
c906108c
SS
3273
3274@item catch
b37052ae 3275The catching of a C@t{++} exception.
c906108c
SS
3276
3277@item exec
4644b6e3 3278@cindex break on fork/exec
c906108c
SS
3279A call to @code{exec}. This is currently only available for HP-UX.
3280
3281@item fork
c906108c
SS
3282A call to @code{fork}. This is currently only available for HP-UX.
3283
3284@item vfork
c906108c
SS
3285A call to @code{vfork}. This is currently only available for HP-UX.
3286
3287@item load
3288@itemx load @var{libname}
4644b6e3 3289@cindex break on load/unload of shared library
c906108c
SS
3290The dynamic loading of any shared library, or the loading of the library
3291@var{libname}. This is currently only available for HP-UX.
3292
3293@item unload
3294@itemx unload @var{libname}
c906108c
SS
3295The unloading of any dynamically loaded shared library, or the unloading
3296of the library @var{libname}. This is currently only available for HP-UX.
3297@end table
3298
3299@item tcatch @var{event}
3300Set a catchpoint that is enabled only for one stop. The catchpoint is
3301automatically deleted after the first time the event is caught.
3302
3303@end table
3304
3305Use the @code{info break} command to list the current catchpoints.
3306
b37052ae 3307There are currently some limitations to C@t{++} exception handling
c906108c
SS
3308(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3309
3310@itemize @bullet
3311@item
3312If you call a function interactively, @value{GDBN} normally returns
3313control to you when the function has finished executing. If the call
3314raises an exception, however, the call may bypass the mechanism that
3315returns control to you and cause your program either to abort or to
3316simply continue running until it hits a breakpoint, catches a signal
3317that @value{GDBN} is listening for, or exits. This is the case even if
3318you set a catchpoint for the exception; catchpoints on exceptions are
3319disabled within interactive calls.
3320
3321@item
3322You cannot raise an exception interactively.
3323
3324@item
3325You cannot install an exception handler interactively.
3326@end itemize
3327
3328@cindex raise exceptions
3329Sometimes @code{catch} is not the best way to debug exception handling:
3330if you need to know exactly where an exception is raised, it is better to
3331stop @emph{before} the exception handler is called, since that way you
3332can see the stack before any unwinding takes place. If you set a
3333breakpoint in an exception handler instead, it may not be easy to find
3334out where the exception was raised.
3335
3336To stop just before an exception handler is called, you need some
b37052ae 3337knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
3338raised by calling a library function named @code{__raise_exception}
3339which has the following ANSI C interface:
3340
474c8240 3341@smallexample
c906108c 3342 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
3343 @var{id} is the exception identifier. */
3344 void __raise_exception (void **addr, void *id);
474c8240 3345@end smallexample
c906108c
SS
3346
3347@noindent
3348To make the debugger catch all exceptions before any stack
3349unwinding takes place, set a breakpoint on @code{__raise_exception}
3350(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
3351
3352With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
3353that depends on the value of @var{id}, you can stop your program when
3354a specific exception is raised. You can use multiple conditional
3355breakpoints to stop your program when any of a number of exceptions are
3356raised.
3357
3358
6d2ebf8b 3359@node Delete Breaks
c906108c
SS
3360@subsection Deleting breakpoints
3361
3362@cindex clearing breakpoints, watchpoints, catchpoints
3363@cindex deleting breakpoints, watchpoints, catchpoints
3364It is often necessary to eliminate a breakpoint, watchpoint, or
3365catchpoint once it has done its job and you no longer want your program
3366to stop there. This is called @dfn{deleting} the breakpoint. A
3367breakpoint that has been deleted no longer exists; it is forgotten.
3368
3369With the @code{clear} command you can delete breakpoints according to
3370where they are in your program. With the @code{delete} command you can
3371delete individual breakpoints, watchpoints, or catchpoints by specifying
3372their breakpoint numbers.
3373
3374It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3375automatically ignores breakpoints on the first instruction to be executed
3376when you continue execution without changing the execution address.
3377
3378@table @code
3379@kindex clear
3380@item clear
3381Delete any breakpoints at the next instruction to be executed in the
3382selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3383the innermost frame is selected, this is a good way to delete a
3384breakpoint where your program just stopped.
3385
3386@item clear @var{function}
3387@itemx clear @var{filename}:@var{function}
09d4efe1 3388Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
3389
3390@item clear @var{linenum}
3391@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
3392Delete any breakpoints set at or within the code of the specified
3393@var{linenum} of the specified @var{filename}.
c906108c
SS
3394
3395@cindex delete breakpoints
3396@kindex delete
41afff9a 3397@kindex d @r{(@code{delete})}
c5394b80
JM
3398@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3399Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3400ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3401breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3402confirm off}). You can abbreviate this command as @code{d}.
3403@end table
3404
6d2ebf8b 3405@node Disabling
c906108c
SS
3406@subsection Disabling breakpoints
3407
4644b6e3 3408@cindex enable/disable a breakpoint
c906108c
SS
3409Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3410prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3411it had been deleted, but remembers the information on the breakpoint so
3412that you can @dfn{enable} it again later.
3413
3414You disable and enable breakpoints, watchpoints, and catchpoints with
3415the @code{enable} and @code{disable} commands, optionally specifying one
3416or more breakpoint numbers as arguments. Use @code{info break} or
3417@code{info watch} to print a list of breakpoints, watchpoints, and
3418catchpoints if you do not know which numbers to use.
3419
3420A breakpoint, watchpoint, or catchpoint can have any of four different
3421states of enablement:
3422
3423@itemize @bullet
3424@item
3425Enabled. The breakpoint stops your program. A breakpoint set
3426with the @code{break} command starts out in this state.
3427@item
3428Disabled. The breakpoint has no effect on your program.
3429@item
3430Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3431disabled.
c906108c
SS
3432@item
3433Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3434immediately after it does so it is deleted permanently. A breakpoint
3435set with the @code{tbreak} command starts out in this state.
c906108c
SS
3436@end itemize
3437
3438You can use the following commands to enable or disable breakpoints,
3439watchpoints, and catchpoints:
3440
3441@table @code
c906108c 3442@kindex disable
41afff9a 3443@kindex dis @r{(@code{disable})}
c5394b80 3444@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3445Disable the specified breakpoints---or all breakpoints, if none are
3446listed. A disabled breakpoint has no effect but is not forgotten. All
3447options such as ignore-counts, conditions and commands are remembered in
3448case the breakpoint is enabled again later. You may abbreviate
3449@code{disable} as @code{dis}.
3450
c906108c 3451@kindex enable
c5394b80 3452@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3453Enable the specified breakpoints (or all defined breakpoints). They
3454become effective once again in stopping your program.
3455
c5394b80 3456@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3457Enable the specified breakpoints temporarily. @value{GDBN} disables any
3458of these breakpoints immediately after stopping your program.
3459
c5394b80 3460@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3461Enable the specified breakpoints to work once, then die. @value{GDBN}
3462deletes any of these breakpoints as soon as your program stops there.
09d4efe1 3463Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
3464@end table
3465
d4f3574e
SS
3466@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3467@c confusing: tbreak is also initially enabled.
c906108c
SS
3468Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3469,Setting breakpoints}), breakpoints that you set are initially enabled;
3470subsequently, they become disabled or enabled only when you use one of
3471the commands above. (The command @code{until} can set and delete a
3472breakpoint of its own, but it does not change the state of your other
3473breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3474stepping}.)
3475
6d2ebf8b 3476@node Conditions
c906108c
SS
3477@subsection Break conditions
3478@cindex conditional breakpoints
3479@cindex breakpoint conditions
3480
3481@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3482@c in particular for a watchpoint?
c906108c
SS
3483The simplest sort of breakpoint breaks every time your program reaches a
3484specified place. You can also specify a @dfn{condition} for a
3485breakpoint. A condition is just a Boolean expression in your
3486programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3487a condition evaluates the expression each time your program reaches it,
3488and your program stops only if the condition is @emph{true}.
3489
3490This is the converse of using assertions for program validation; in that
3491situation, you want to stop when the assertion is violated---that is,
3492when the condition is false. In C, if you want to test an assertion expressed
3493by the condition @var{assert}, you should set the condition
3494@samp{! @var{assert}} on the appropriate breakpoint.
3495
3496Conditions are also accepted for watchpoints; you may not need them,
3497since a watchpoint is inspecting the value of an expression anyhow---but
3498it might be simpler, say, to just set a watchpoint on a variable name,
3499and specify a condition that tests whether the new value is an interesting
3500one.
3501
3502Break conditions can have side effects, and may even call functions in
3503your program. This can be useful, for example, to activate functions
3504that log program progress, or to use your own print functions to
3505format special data structures. The effects are completely predictable
3506unless there is another enabled breakpoint at the same address. (In
3507that case, @value{GDBN} might see the other breakpoint first and stop your
3508program without checking the condition of this one.) Note that
d4f3574e
SS
3509breakpoint commands are usually more convenient and flexible than break
3510conditions for the
c906108c
SS
3511purpose of performing side effects when a breakpoint is reached
3512(@pxref{Break Commands, ,Breakpoint command lists}).
3513
3514Break conditions can be specified when a breakpoint is set, by using
3515@samp{if} in the arguments to the @code{break} command. @xref{Set
3516Breaks, ,Setting breakpoints}. They can also be changed at any time
3517with the @code{condition} command.
53a5351d 3518
c906108c
SS
3519You can also use the @code{if} keyword with the @code{watch} command.
3520The @code{catch} command does not recognize the @code{if} keyword;
3521@code{condition} is the only way to impose a further condition on a
3522catchpoint.
c906108c
SS
3523
3524@table @code
3525@kindex condition
3526@item condition @var{bnum} @var{expression}
3527Specify @var{expression} as the break condition for breakpoint,
3528watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3529breakpoint @var{bnum} stops your program only if the value of
3530@var{expression} is true (nonzero, in C). When you use
3531@code{condition}, @value{GDBN} checks @var{expression} immediately for
3532syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3533referents in the context of your breakpoint. If @var{expression} uses
3534symbols not referenced in the context of the breakpoint, @value{GDBN}
3535prints an error message:
3536
474c8240 3537@smallexample
d4f3574e 3538No symbol "foo" in current context.
474c8240 3539@end smallexample
d4f3574e
SS
3540
3541@noindent
c906108c
SS
3542@value{GDBN} does
3543not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3544command (or a command that sets a breakpoint with a condition, like
3545@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3546
3547@item condition @var{bnum}
3548Remove the condition from breakpoint number @var{bnum}. It becomes
3549an ordinary unconditional breakpoint.
3550@end table
3551
3552@cindex ignore count (of breakpoint)
3553A special case of a breakpoint condition is to stop only when the
3554breakpoint has been reached a certain number of times. This is so
3555useful that there is a special way to do it, using the @dfn{ignore
3556count} of the breakpoint. Every breakpoint has an ignore count, which
3557is an integer. Most of the time, the ignore count is zero, and
3558therefore has no effect. But if your program reaches a breakpoint whose
3559ignore count is positive, then instead of stopping, it just decrements
3560the ignore count by one and continues. As a result, if the ignore count
3561value is @var{n}, the breakpoint does not stop the next @var{n} times
3562your program reaches it.
3563
3564@table @code
3565@kindex ignore
3566@item ignore @var{bnum} @var{count}
3567Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3568The next @var{count} times the breakpoint is reached, your program's
3569execution does not stop; other than to decrement the ignore count, @value{GDBN}
3570takes no action.
3571
3572To make the breakpoint stop the next time it is reached, specify
3573a count of zero.
3574
3575When you use @code{continue} to resume execution of your program from a
3576breakpoint, you can specify an ignore count directly as an argument to
3577@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3578Stepping,,Continuing and stepping}.
3579
3580If a breakpoint has a positive ignore count and a condition, the
3581condition is not checked. Once the ignore count reaches zero,
3582@value{GDBN} resumes checking the condition.
3583
3584You could achieve the effect of the ignore count with a condition such
3585as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3586is decremented each time. @xref{Convenience Vars, ,Convenience
3587variables}.
3588@end table
3589
3590Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3591
3592
6d2ebf8b 3593@node Break Commands
c906108c
SS
3594@subsection Breakpoint command lists
3595
3596@cindex breakpoint commands
3597You can give any breakpoint (or watchpoint or catchpoint) a series of
3598commands to execute when your program stops due to that breakpoint. For
3599example, you might want to print the values of certain expressions, or
3600enable other breakpoints.
3601
3602@table @code
3603@kindex commands
ca91424e 3604@kindex end@r{ (breakpoint commands)}
c906108c
SS
3605@item commands @r{[}@var{bnum}@r{]}
3606@itemx @dots{} @var{command-list} @dots{}
3607@itemx end
3608Specify a list of commands for breakpoint number @var{bnum}. The commands
3609themselves appear on the following lines. Type a line containing just
3610@code{end} to terminate the commands.
3611
3612To remove all commands from a breakpoint, type @code{commands} and
3613follow it immediately with @code{end}; that is, give no commands.
3614
3615With no @var{bnum} argument, @code{commands} refers to the last
3616breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3617recently encountered).
3618@end table
3619
3620Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3621disabled within a @var{command-list}.
3622
3623You can use breakpoint commands to start your program up again. Simply
3624use the @code{continue} command, or @code{step}, or any other command
3625that resumes execution.
3626
3627Any other commands in the command list, after a command that resumes
3628execution, are ignored. This is because any time you resume execution
3629(even with a simple @code{next} or @code{step}), you may encounter
3630another breakpoint---which could have its own command list, leading to
3631ambiguities about which list to execute.
3632
3633@kindex silent
3634If the first command you specify in a command list is @code{silent}, the
3635usual message about stopping at a breakpoint is not printed. This may
3636be desirable for breakpoints that are to print a specific message and
3637then continue. If none of the remaining commands print anything, you
3638see no sign that the breakpoint was reached. @code{silent} is
3639meaningful only at the beginning of a breakpoint command list.
3640
3641The commands @code{echo}, @code{output}, and @code{printf} allow you to
3642print precisely controlled output, and are often useful in silent
3643breakpoints. @xref{Output, ,Commands for controlled output}.
3644
3645For example, here is how you could use breakpoint commands to print the
3646value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3647
474c8240 3648@smallexample
c906108c
SS
3649break foo if x>0
3650commands
3651silent
3652printf "x is %d\n",x
3653cont
3654end
474c8240 3655@end smallexample
c906108c
SS
3656
3657One application for breakpoint commands is to compensate for one bug so
3658you can test for another. Put a breakpoint just after the erroneous line
3659of code, give it a condition to detect the case in which something
3660erroneous has been done, and give it commands to assign correct values
3661to any variables that need them. End with the @code{continue} command
3662so that your program does not stop, and start with the @code{silent}
3663command so that no output is produced. Here is an example:
3664
474c8240 3665@smallexample
c906108c
SS
3666break 403
3667commands
3668silent
3669set x = y + 4
3670cont
3671end
474c8240 3672@end smallexample
c906108c 3673
6d2ebf8b 3674@node Breakpoint Menus
c906108c
SS
3675@subsection Breakpoint menus
3676@cindex overloading
3677@cindex symbol overloading
3678
b383017d 3679Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3680single function name
c906108c
SS
3681to be defined several times, for application in different contexts.
3682This is called @dfn{overloading}. When a function name is overloaded,
3683@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3684a breakpoint. If you realize this is a problem, you can use
3685something like @samp{break @var{function}(@var{types})} to specify which
3686particular version of the function you want. Otherwise, @value{GDBN} offers
3687you a menu of numbered choices for different possible breakpoints, and
3688waits for your selection with the prompt @samp{>}. The first two
3689options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3690sets a breakpoint at each definition of @var{function}, and typing
3691@kbd{0} aborts the @code{break} command without setting any new
3692breakpoints.
3693
3694For example, the following session excerpt shows an attempt to set a
3695breakpoint at the overloaded symbol @code{String::after}.
3696We choose three particular definitions of that function name:
3697
3698@c FIXME! This is likely to change to show arg type lists, at least
3699@smallexample
3700@group
3701(@value{GDBP}) b String::after
3702[0] cancel
3703[1] all
3704[2] file:String.cc; line number:867
3705[3] file:String.cc; line number:860
3706[4] file:String.cc; line number:875
3707[5] file:String.cc; line number:853
3708[6] file:String.cc; line number:846
3709[7] file:String.cc; line number:735
3710> 2 4 6
3711Breakpoint 1 at 0xb26c: file String.cc, line 867.
3712Breakpoint 2 at 0xb344: file String.cc, line 875.
3713Breakpoint 3 at 0xafcc: file String.cc, line 846.
3714Multiple breakpoints were set.
3715Use the "delete" command to delete unwanted
3716 breakpoints.
3717(@value{GDBP})
3718@end group
3719@end smallexample
c906108c
SS
3720
3721@c @ifclear BARETARGET
6d2ebf8b 3722@node Error in Breakpoints
d4f3574e 3723@subsection ``Cannot insert breakpoints''
c906108c
SS
3724@c
3725@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3726@c
d4f3574e
SS
3727Under some operating systems, breakpoints cannot be used in a program if
3728any other process is running that program. In this situation,
5d161b24 3729attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3730@value{GDBN} to print an error message:
3731
474c8240 3732@smallexample
d4f3574e
SS
3733Cannot insert breakpoints.
3734The same program may be running in another process.
474c8240 3735@end smallexample
d4f3574e
SS
3736
3737When this happens, you have three ways to proceed:
3738
3739@enumerate
3740@item
3741Remove or disable the breakpoints, then continue.
3742
3743@item
5d161b24 3744Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3745name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3746that @value{GDBN} should run your program under that name.
d4f3574e
SS
3747Then start your program again.
3748
3749@item
3750Relink your program so that the text segment is nonsharable, using the
3751linker option @samp{-N}. The operating system limitation may not apply
3752to nonsharable executables.
3753@end enumerate
c906108c
SS
3754@c @end ifclear
3755
d4f3574e
SS
3756A similar message can be printed if you request too many active
3757hardware-assisted breakpoints and watchpoints:
3758
3759@c FIXME: the precise wording of this message may change; the relevant
3760@c source change is not committed yet (Sep 3, 1999).
3761@smallexample
3762Stopped; cannot insert breakpoints.
3763You may have requested too many hardware breakpoints and watchpoints.
3764@end smallexample
3765
3766@noindent
3767This message is printed when you attempt to resume the program, since
3768only then @value{GDBN} knows exactly how many hardware breakpoints and
3769watchpoints it needs to insert.
3770
3771When this message is printed, you need to disable or remove some of the
3772hardware-assisted breakpoints and watchpoints, and then continue.
3773
1485d690
KB
3774@node Breakpoint related warnings
3775@subsection ``Breakpoint address adjusted...''
3776@cindex breakpoint address adjusted
3777
3778Some processor architectures place constraints on the addresses at
3779which breakpoints may be placed. For architectures thus constrained,
3780@value{GDBN} will attempt to adjust the breakpoint's address to comply
3781with the constraints dictated by the architecture.
3782
3783One example of such an architecture is the Fujitsu FR-V. The FR-V is
3784a VLIW architecture in which a number of RISC-like instructions may be
3785bundled together for parallel execution. The FR-V architecture
3786constrains the location of a breakpoint instruction within such a
3787bundle to the instruction with the lowest address. @value{GDBN}
3788honors this constraint by adjusting a breakpoint's address to the
3789first in the bundle.
3790
3791It is not uncommon for optimized code to have bundles which contain
3792instructions from different source statements, thus it may happen that
3793a breakpoint's address will be adjusted from one source statement to
3794another. Since this adjustment may significantly alter @value{GDBN}'s
3795breakpoint related behavior from what the user expects, a warning is
3796printed when the breakpoint is first set and also when the breakpoint
3797is hit.
3798
3799A warning like the one below is printed when setting a breakpoint
3800that's been subject to address adjustment:
3801
3802@smallexample
3803warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3804@end smallexample
3805
3806Such warnings are printed both for user settable and @value{GDBN}'s
3807internal breakpoints. If you see one of these warnings, you should
3808verify that a breakpoint set at the adjusted address will have the
3809desired affect. If not, the breakpoint in question may be removed and
b383017d 3810other breakpoints may be set which will have the desired behavior.
1485d690
KB
3811E.g., it may be sufficient to place the breakpoint at a later
3812instruction. A conditional breakpoint may also be useful in some
3813cases to prevent the breakpoint from triggering too often.
3814
3815@value{GDBN} will also issue a warning when stopping at one of these
3816adjusted breakpoints:
3817
3818@smallexample
3819warning: Breakpoint 1 address previously adjusted from 0x00010414
3820to 0x00010410.
3821@end smallexample
3822
3823When this warning is encountered, it may be too late to take remedial
3824action except in cases where the breakpoint is hit earlier or more
3825frequently than expected.
d4f3574e 3826
6d2ebf8b 3827@node Continuing and Stepping
c906108c
SS
3828@section Continuing and stepping
3829
3830@cindex stepping
3831@cindex continuing
3832@cindex resuming execution
3833@dfn{Continuing} means resuming program execution until your program
3834completes normally. In contrast, @dfn{stepping} means executing just
3835one more ``step'' of your program, where ``step'' may mean either one
3836line of source code, or one machine instruction (depending on what
7a292a7a
SS
3837particular command you use). Either when continuing or when stepping,
3838your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3839it stops due to a signal, you may want to use @code{handle}, or use
3840@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3841
3842@table @code
3843@kindex continue
41afff9a
EZ
3844@kindex c @r{(@code{continue})}
3845@kindex fg @r{(resume foreground execution)}
c906108c
SS
3846@item continue @r{[}@var{ignore-count}@r{]}
3847@itemx c @r{[}@var{ignore-count}@r{]}
3848@itemx fg @r{[}@var{ignore-count}@r{]}
3849Resume program execution, at the address where your program last stopped;
3850any breakpoints set at that address are bypassed. The optional argument
3851@var{ignore-count} allows you to specify a further number of times to
3852ignore a breakpoint at this location; its effect is like that of
3853@code{ignore} (@pxref{Conditions, ,Break conditions}).
3854
3855The argument @var{ignore-count} is meaningful only when your program
3856stopped due to a breakpoint. At other times, the argument to
3857@code{continue} is ignored.
3858
d4f3574e
SS
3859The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3860debugged program is deemed to be the foreground program) are provided
3861purely for convenience, and have exactly the same behavior as
3862@code{continue}.
c906108c
SS
3863@end table
3864
3865To resume execution at a different place, you can use @code{return}
3866(@pxref{Returning, ,Returning from a function}) to go back to the
3867calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3868different address}) to go to an arbitrary location in your program.
3869
3870A typical technique for using stepping is to set a breakpoint
3871(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3872beginning of the function or the section of your program where a problem
3873is believed to lie, run your program until it stops at that breakpoint,
3874and then step through the suspect area, examining the variables that are
3875interesting, until you see the problem happen.
3876
3877@table @code
3878@kindex step
41afff9a 3879@kindex s @r{(@code{step})}
c906108c
SS
3880@item step
3881Continue running your program until control reaches a different source
3882line, then stop it and return control to @value{GDBN}. This command is
3883abbreviated @code{s}.
3884
3885@quotation
3886@c "without debugging information" is imprecise; actually "without line
3887@c numbers in the debugging information". (gcc -g1 has debugging info but
3888@c not line numbers). But it seems complex to try to make that
3889@c distinction here.
3890@emph{Warning:} If you use the @code{step} command while control is
3891within a function that was compiled without debugging information,
3892execution proceeds until control reaches a function that does have
3893debugging information. Likewise, it will not step into a function which
3894is compiled without debugging information. To step through functions
3895without debugging information, use the @code{stepi} command, described
3896below.
3897@end quotation
3898
4a92d011
EZ
3899The @code{step} command only stops at the first instruction of a source
3900line. This prevents the multiple stops that could otherwise occur in
3901@code{switch} statements, @code{for} loops, etc. @code{step} continues
3902to stop if a function that has debugging information is called within
3903the line. In other words, @code{step} @emph{steps inside} any functions
3904called within the line.
c906108c 3905
d4f3574e
SS
3906Also, the @code{step} command only enters a function if there is line
3907number information for the function. Otherwise it acts like the
5d161b24 3908@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3909on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3910was any debugging information about the routine.
c906108c
SS
3911
3912@item step @var{count}
3913Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3914breakpoint is reached, or a signal not related to stepping occurs before
3915@var{count} steps, stepping stops right away.
c906108c
SS
3916
3917@kindex next
41afff9a 3918@kindex n @r{(@code{next})}
c906108c
SS
3919@item next @r{[}@var{count}@r{]}
3920Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3921This is similar to @code{step}, but function calls that appear within
3922the line of code are executed without stopping. Execution stops when
3923control reaches a different line of code at the original stack level
3924that was executing when you gave the @code{next} command. This command
3925is abbreviated @code{n}.
c906108c
SS
3926
3927An argument @var{count} is a repeat count, as for @code{step}.
3928
3929
3930@c FIX ME!! Do we delete this, or is there a way it fits in with
3931@c the following paragraph? --- Vctoria
3932@c
3933@c @code{next} within a function that lacks debugging information acts like
3934@c @code{step}, but any function calls appearing within the code of the
3935@c function are executed without stopping.
3936
d4f3574e
SS
3937The @code{next} command only stops at the first instruction of a
3938source line. This prevents multiple stops that could otherwise occur in
4a92d011 3939@code{switch} statements, @code{for} loops, etc.
c906108c 3940
b90a5f51
CF
3941@kindex set step-mode
3942@item set step-mode
3943@cindex functions without line info, and stepping
3944@cindex stepping into functions with no line info
3945@itemx set step-mode on
4a92d011 3946The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3947stop at the first instruction of a function which contains no debug line
3948information rather than stepping over it.
3949
4a92d011
EZ
3950This is useful in cases where you may be interested in inspecting the
3951machine instructions of a function which has no symbolic info and do not
3952want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3953
3954@item set step-mode off
4a92d011 3955Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3956debug information. This is the default.
3957
9c16f35a
EZ
3958@item show step-mode
3959Show whether @value{GDBN} will stop in or step over functions without
3960source line debug information.
3961
c906108c
SS
3962@kindex finish
3963@item finish
3964Continue running until just after function in the selected stack frame
3965returns. Print the returned value (if any).
3966
3967Contrast this with the @code{return} command (@pxref{Returning,
3968,Returning from a function}).
3969
3970@kindex until
41afff9a 3971@kindex u @r{(@code{until})}
09d4efe1 3972@cindex run until specified location
c906108c
SS
3973@item until
3974@itemx u
3975Continue running until a source line past the current line, in the
3976current stack frame, is reached. This command is used to avoid single
3977stepping through a loop more than once. It is like the @code{next}
3978command, except that when @code{until} encounters a jump, it
3979automatically continues execution until the program counter is greater
3980than the address of the jump.
3981
3982This means that when you reach the end of a loop after single stepping
3983though it, @code{until} makes your program continue execution until it
3984exits the loop. In contrast, a @code{next} command at the end of a loop
3985simply steps back to the beginning of the loop, which forces you to step
3986through the next iteration.
3987
3988@code{until} always stops your program if it attempts to exit the current
3989stack frame.
3990
3991@code{until} may produce somewhat counterintuitive results if the order
3992of machine code does not match the order of the source lines. For
3993example, in the following excerpt from a debugging session, the @code{f}
3994(@code{frame}) command shows that execution is stopped at line
3995@code{206}; yet when we use @code{until}, we get to line @code{195}:
3996
474c8240 3997@smallexample
c906108c
SS
3998(@value{GDBP}) f
3999#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
4000206 expand_input();
4001(@value{GDBP}) until
4002195 for ( ; argc > 0; NEXTARG) @{
474c8240 4003@end smallexample
c906108c
SS
4004
4005This happened because, for execution efficiency, the compiler had
4006generated code for the loop closure test at the end, rather than the
4007start, of the loop---even though the test in a C @code{for}-loop is
4008written before the body of the loop. The @code{until} command appeared
4009to step back to the beginning of the loop when it advanced to this
4010expression; however, it has not really gone to an earlier
4011statement---not in terms of the actual machine code.
4012
4013@code{until} with no argument works by means of single
4014instruction stepping, and hence is slower than @code{until} with an
4015argument.
4016
4017@item until @var{location}
4018@itemx u @var{location}
4019Continue running your program until either the specified location is
4020reached, or the current stack frame returns. @var{location} is any of
4021the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
4022,Setting breakpoints}). This form of the command uses breakpoints, and
4023hence is quicker than @code{until} without an argument. The specified
4024location is actually reached only if it is in the current frame. This
4025implies that @code{until} can be used to skip over recursive function
4026invocations. For instance in the code below, if the current location is
4027line @code{96}, issuing @code{until 99} will execute the program up to
4028line @code{99} in the same invocation of factorial, i.e. after the inner
4029invocations have returned.
4030
4031@smallexample
403294 int factorial (int value)
403395 @{
403496 if (value > 1) @{
403597 value *= factorial (value - 1);
403698 @}
403799 return (value);
4038100 @}
4039@end smallexample
4040
4041
4042@kindex advance @var{location}
4043@itemx advance @var{location}
09d4efe1
EZ
4044Continue running the program up to the given @var{location}. An argument is
4045required, which should be of the same form as arguments for the @code{break}
c60eb6f1
EZ
4046command. Execution will also stop upon exit from the current stack
4047frame. This command is similar to @code{until}, but @code{advance} will
4048not skip over recursive function calls, and the target location doesn't
4049have to be in the same frame as the current one.
4050
c906108c
SS
4051
4052@kindex stepi
41afff9a 4053@kindex si @r{(@code{stepi})}
c906108c 4054@item stepi
96a2c332 4055@itemx stepi @var{arg}
c906108c
SS
4056@itemx si
4057Execute one machine instruction, then stop and return to the debugger.
4058
4059It is often useful to do @samp{display/i $pc} when stepping by machine
4060instructions. This makes @value{GDBN} automatically display the next
4061instruction to be executed, each time your program stops. @xref{Auto
4062Display,, Automatic display}.
4063
4064An argument is a repeat count, as in @code{step}.
4065
4066@need 750
4067@kindex nexti
41afff9a 4068@kindex ni @r{(@code{nexti})}
c906108c 4069@item nexti
96a2c332 4070@itemx nexti @var{arg}
c906108c
SS
4071@itemx ni
4072Execute one machine instruction, but if it is a function call,
4073proceed until the function returns.
4074
4075An argument is a repeat count, as in @code{next}.
4076@end table
4077
6d2ebf8b 4078@node Signals
c906108c
SS
4079@section Signals
4080@cindex signals
4081
4082A signal is an asynchronous event that can happen in a program. The
4083operating system defines the possible kinds of signals, and gives each
4084kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 4085signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
4086@code{SIGSEGV} is the signal a program gets from referencing a place in
4087memory far away from all the areas in use; @code{SIGALRM} occurs when
4088the alarm clock timer goes off (which happens only if your program has
4089requested an alarm).
4090
4091@cindex fatal signals
4092Some signals, including @code{SIGALRM}, are a normal part of the
4093functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 4094errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
4095program has not specified in advance some other way to handle the signal.
4096@code{SIGINT} does not indicate an error in your program, but it is normally
4097fatal so it can carry out the purpose of the interrupt: to kill the program.
4098
4099@value{GDBN} has the ability to detect any occurrence of a signal in your
4100program. You can tell @value{GDBN} in advance what to do for each kind of
4101signal.
4102
4103@cindex handling signals
24f93129
EZ
4104Normally, @value{GDBN} is set up to let the non-erroneous signals like
4105@code{SIGALRM} be silently passed to your program
4106(so as not to interfere with their role in the program's functioning)
c906108c
SS
4107but to stop your program immediately whenever an error signal happens.
4108You can change these settings with the @code{handle} command.
4109
4110@table @code
4111@kindex info signals
09d4efe1 4112@kindex info handle
c906108c 4113@item info signals
96a2c332 4114@itemx info handle
c906108c
SS
4115Print a table of all the kinds of signals and how @value{GDBN} has been told to
4116handle each one. You can use this to see the signal numbers of all
4117the defined types of signals.
4118
d4f3574e 4119@code{info handle} is an alias for @code{info signals}.
c906108c
SS
4120
4121@kindex handle
4122@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
4123Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
4124can be the number of a signal or its name (with or without the
24f93129 4125@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
4126@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
4127known signals. The @var{keywords} say what change to make.
c906108c
SS
4128@end table
4129
4130@c @group
4131The keywords allowed by the @code{handle} command can be abbreviated.
4132Their full names are:
4133
4134@table @code
4135@item nostop
4136@value{GDBN} should not stop your program when this signal happens. It may
4137still print a message telling you that the signal has come in.
4138
4139@item stop
4140@value{GDBN} should stop your program when this signal happens. This implies
4141the @code{print} keyword as well.
4142
4143@item print
4144@value{GDBN} should print a message when this signal happens.
4145
4146@item noprint
4147@value{GDBN} should not mention the occurrence of the signal at all. This
4148implies the @code{nostop} keyword as well.
4149
4150@item pass
5ece1a18 4151@itemx noignore
c906108c
SS
4152@value{GDBN} should allow your program to see this signal; your program
4153can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 4154and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
4155
4156@item nopass
5ece1a18 4157@itemx ignore
c906108c 4158@value{GDBN} should not allow your program to see this signal.
5ece1a18 4159@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
4160@end table
4161@c @end group
4162
d4f3574e
SS
4163When a signal stops your program, the signal is not visible to the
4164program until you
c906108c
SS
4165continue. Your program sees the signal then, if @code{pass} is in
4166effect for the signal in question @emph{at that time}. In other words,
4167after @value{GDBN} reports a signal, you can use the @code{handle}
4168command with @code{pass} or @code{nopass} to control whether your
4169program sees that signal when you continue.
4170
24f93129
EZ
4171The default is set to @code{nostop}, @code{noprint}, @code{pass} for
4172non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
4173@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
4174erroneous signals.
4175
c906108c
SS
4176You can also use the @code{signal} command to prevent your program from
4177seeing a signal, or cause it to see a signal it normally would not see,
4178or to give it any signal at any time. For example, if your program stopped
4179due to some sort of memory reference error, you might store correct
4180values into the erroneous variables and continue, hoping to see more
4181execution; but your program would probably terminate immediately as
4182a result of the fatal signal once it saw the signal. To prevent this,
4183you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 4184program a signal}.
c906108c 4185
6d2ebf8b 4186@node Thread Stops
c906108c
SS
4187@section Stopping and starting multi-thread programs
4188
4189When your program has multiple threads (@pxref{Threads,, Debugging
4190programs with multiple threads}), you can choose whether to set
4191breakpoints on all threads, or on a particular thread.
4192
4193@table @code
4194@cindex breakpoints and threads
4195@cindex thread breakpoints
4196@kindex break @dots{} thread @var{threadno}
4197@item break @var{linespec} thread @var{threadno}
4198@itemx break @var{linespec} thread @var{threadno} if @dots{}
4199@var{linespec} specifies source lines; there are several ways of
4200writing them, but the effect is always to specify some source line.
4201
4202Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
4203to specify that you only want @value{GDBN} to stop the program when a
4204particular thread reaches this breakpoint. @var{threadno} is one of the
4205numeric thread identifiers assigned by @value{GDBN}, shown in the first
4206column of the @samp{info threads} display.
4207
4208If you do not specify @samp{thread @var{threadno}} when you set a
4209breakpoint, the breakpoint applies to @emph{all} threads of your
4210program.
4211
4212You can use the @code{thread} qualifier on conditional breakpoints as
4213well; in this case, place @samp{thread @var{threadno}} before the
4214breakpoint condition, like this:
4215
4216@smallexample
2df3850c 4217(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
4218@end smallexample
4219
4220@end table
4221
4222@cindex stopped threads
4223@cindex threads, stopped
4224Whenever your program stops under @value{GDBN} for any reason,
4225@emph{all} threads of execution stop, not just the current thread. This
4226allows you to examine the overall state of the program, including
4227switching between threads, without worrying that things may change
4228underfoot.
4229
36d86913
MC
4230@cindex thread breakpoints and system calls
4231@cindex system calls and thread breakpoints
4232@cindex premature return from system calls
4233There is an unfortunate side effect. If one thread stops for a
4234breakpoint, or for some other reason, and another thread is blocked in a
4235system call, then the system call may return prematurely. This is a
4236consequence of the interaction between multiple threads and the signals
4237that @value{GDBN} uses to implement breakpoints and other events that
4238stop execution.
4239
4240To handle this problem, your program should check the return value of
4241each system call and react appropriately. This is good programming
4242style anyways.
4243
4244For example, do not write code like this:
4245
4246@smallexample
4247 sleep (10);
4248@end smallexample
4249
4250The call to @code{sleep} will return early if a different thread stops
4251at a breakpoint or for some other reason.
4252
4253Instead, write this:
4254
4255@smallexample
4256 int unslept = 10;
4257 while (unslept > 0)
4258 unslept = sleep (unslept);
4259@end smallexample
4260
4261A system call is allowed to return early, so the system is still
4262conforming to its specification. But @value{GDBN} does cause your
4263multi-threaded program to behave differently than it would without
4264@value{GDBN}.
4265
4266Also, @value{GDBN} uses internal breakpoints in the thread library to
4267monitor certain events such as thread creation and thread destruction.
4268When such an event happens, a system call in another thread may return
4269prematurely, even though your program does not appear to stop.
4270
c906108c
SS
4271@cindex continuing threads
4272@cindex threads, continuing
4273Conversely, whenever you restart the program, @emph{all} threads start
4274executing. @emph{This is true even when single-stepping} with commands
5d161b24 4275like @code{step} or @code{next}.
c906108c
SS
4276
4277In particular, @value{GDBN} cannot single-step all threads in lockstep.
4278Since thread scheduling is up to your debugging target's operating
4279system (not controlled by @value{GDBN}), other threads may
4280execute more than one statement while the current thread completes a
4281single step. Moreover, in general other threads stop in the middle of a
4282statement, rather than at a clean statement boundary, when the program
4283stops.
4284
4285You might even find your program stopped in another thread after
4286continuing or even single-stepping. This happens whenever some other
4287thread runs into a breakpoint, a signal, or an exception before the
4288first thread completes whatever you requested.
4289
4290On some OSes, you can lock the OS scheduler and thus allow only a single
4291thread to run.
4292
4293@table @code
4294@item set scheduler-locking @var{mode}
9c16f35a
EZ
4295@cindex scheduler locking mode
4296@cindex lock scheduler
c906108c
SS
4297Set the scheduler locking mode. If it is @code{off}, then there is no
4298locking and any thread may run at any time. If @code{on}, then only the
4299current thread may run when the inferior is resumed. The @code{step}
4300mode optimizes for single-stepping. It stops other threads from
4301``seizing the prompt'' by preempting the current thread while you are
4302stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 4303when you step. They are more likely to run when you @samp{next} over a
c906108c 4304function call, and they are completely free to run when you use commands
d4f3574e 4305like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 4306thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 4307@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
4308
4309@item show scheduler-locking
4310Display the current scheduler locking mode.
4311@end table
4312
c906108c 4313
6d2ebf8b 4314@node Stack
c906108c
SS
4315@chapter Examining the Stack
4316
4317When your program has stopped, the first thing you need to know is where it
4318stopped and how it got there.
4319
4320@cindex call stack
5d161b24
DB
4321Each time your program performs a function call, information about the call
4322is generated.
4323That information includes the location of the call in your program,
4324the arguments of the call,
c906108c 4325and the local variables of the function being called.
5d161b24 4326The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
4327The stack frames are allocated in a region of memory called the @dfn{call
4328stack}.
4329
4330When your program stops, the @value{GDBN} commands for examining the
4331stack allow you to see all of this information.
4332
4333@cindex selected frame
4334One of the stack frames is @dfn{selected} by @value{GDBN} and many
4335@value{GDBN} commands refer implicitly to the selected frame. In
4336particular, whenever you ask @value{GDBN} for the value of a variable in
4337your program, the value is found in the selected frame. There are
4338special @value{GDBN} commands to select whichever frame you are
4339interested in. @xref{Selection, ,Selecting a frame}.
4340
4341When your program stops, @value{GDBN} automatically selects the
5d161b24 4342currently executing frame and describes it briefly, similar to the
c906108c
SS
4343@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
4344
4345@menu
4346* Frames:: Stack frames
4347* Backtrace:: Backtraces
4348* Selection:: Selecting a frame
4349* Frame Info:: Information on a frame
c906108c
SS
4350
4351@end menu
4352
6d2ebf8b 4353@node Frames
c906108c
SS
4354@section Stack frames
4355
d4f3574e 4356@cindex frame, definition
c906108c
SS
4357@cindex stack frame
4358The call stack is divided up into contiguous pieces called @dfn{stack
4359frames}, or @dfn{frames} for short; each frame is the data associated
4360with one call to one function. The frame contains the arguments given
4361to the function, the function's local variables, and the address at
4362which the function is executing.
4363
4364@cindex initial frame
4365@cindex outermost frame
4366@cindex innermost frame
4367When your program is started, the stack has only one frame, that of the
4368function @code{main}. This is called the @dfn{initial} frame or the
4369@dfn{outermost} frame. Each time a function is called, a new frame is
4370made. Each time a function returns, the frame for that function invocation
4371is eliminated. If a function is recursive, there can be many frames for
4372the same function. The frame for the function in which execution is
4373actually occurring is called the @dfn{innermost} frame. This is the most
4374recently created of all the stack frames that still exist.
4375
4376@cindex frame pointer
4377Inside your program, stack frames are identified by their addresses. A
4378stack frame consists of many bytes, each of which has its own address; each
4379kind of computer has a convention for choosing one byte whose
4380address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
4381in a register called the @dfn{frame pointer register}
4382(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
4383
4384@cindex frame number
4385@value{GDBN} assigns numbers to all existing stack frames, starting with
4386zero for the innermost frame, one for the frame that called it,
4387and so on upward. These numbers do not really exist in your program;
4388they are assigned by @value{GDBN} to give you a way of designating stack
4389frames in @value{GDBN} commands.
4390
6d2ebf8b
SS
4391@c The -fomit-frame-pointer below perennially causes hbox overflow
4392@c underflow problems.
c906108c
SS
4393@cindex frameless execution
4394Some compilers provide a way to compile functions so that they operate
6d2ebf8b 4395without stack frames. (For example, the @value{GCC} option
474c8240 4396@smallexample
6d2ebf8b 4397@samp{-fomit-frame-pointer}
474c8240 4398@end smallexample
6d2ebf8b 4399generates functions without a frame.)
c906108c
SS
4400This is occasionally done with heavily used library functions to save
4401the frame setup time. @value{GDBN} has limited facilities for dealing
4402with these function invocations. If the innermost function invocation
4403has no stack frame, @value{GDBN} nevertheless regards it as though
4404it had a separate frame, which is numbered zero as usual, allowing
4405correct tracing of the function call chain. However, @value{GDBN} has
4406no provision for frameless functions elsewhere in the stack.
4407
4408@table @code
d4f3574e 4409@kindex frame@r{, command}
41afff9a 4410@cindex current stack frame
c906108c 4411@item frame @var{args}
5d161b24 4412The @code{frame} command allows you to move from one stack frame to another,
c906108c 4413and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4414address of the frame or the stack frame number. Without an argument,
4415@code{frame} prints the current stack frame.
c906108c
SS
4416
4417@kindex select-frame
41afff9a 4418@cindex selecting frame silently
c906108c
SS
4419@item select-frame
4420The @code{select-frame} command allows you to move from one stack frame
4421to another without printing the frame. This is the silent version of
4422@code{frame}.
4423@end table
4424
6d2ebf8b 4425@node Backtrace
c906108c
SS
4426@section Backtraces
4427
09d4efe1
EZ
4428@cindex traceback
4429@cindex call stack traces
c906108c
SS
4430A backtrace is a summary of how your program got where it is. It shows one
4431line per frame, for many frames, starting with the currently executing
4432frame (frame zero), followed by its caller (frame one), and on up the
4433stack.
4434
4435@table @code
4436@kindex backtrace
41afff9a 4437@kindex bt @r{(@code{backtrace})}
c906108c
SS
4438@item backtrace
4439@itemx bt
4440Print a backtrace of the entire stack: one line per frame for all
4441frames in the stack.
4442
4443You can stop the backtrace at any time by typing the system interrupt
4444character, normally @kbd{C-c}.
4445
4446@item backtrace @var{n}
4447@itemx bt @var{n}
4448Similar, but print only the innermost @var{n} frames.
4449
4450@item backtrace -@var{n}
4451@itemx bt -@var{n}
4452Similar, but print only the outermost @var{n} frames.
0f061b69
NR
4453
4454@item backtrace full
4455Print the values of the local variables also.
4456@itemx bt full
c906108c
SS
4457@end table
4458
4459@kindex where
4460@kindex info stack
c906108c
SS
4461The names @code{where} and @code{info stack} (abbreviated @code{info s})
4462are additional aliases for @code{backtrace}.
4463
4464Each line in the backtrace shows the frame number and the function name.
4465The program counter value is also shown---unless you use @code{set
4466print address off}. The backtrace also shows the source file name and
4467line number, as well as the arguments to the function. The program
4468counter value is omitted if it is at the beginning of the code for that
4469line number.
4470
4471Here is an example of a backtrace. It was made with the command
4472@samp{bt 3}, so it shows the innermost three frames.
4473
4474@smallexample
4475@group
5d161b24 4476#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4477 at builtin.c:993
4478#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4479#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4480 at macro.c:71
4481(More stack frames follow...)
4482@end group
4483@end smallexample
4484
4485@noindent
4486The display for frame zero does not begin with a program counter
4487value, indicating that your program has stopped at the beginning of the
4488code for line @code{993} of @code{builtin.c}.
4489
18999be5
EZ
4490@cindex value optimized out, in backtrace
4491@cindex function call arguments, optimized out
4492If your program was compiled with optimizations, some compilers will
4493optimize away arguments passed to functions if those arguments are
4494never used after the call. Such optimizations generate code that
4495passes arguments through registers, but doesn't store those arguments
4496in the stack frame. @value{GDBN} has no way of displaying such
4497arguments in stack frames other than the innermost one. Here's what
4498such a backtrace might look like:
4499
4500@smallexample
4501@group
4502#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4503 at builtin.c:993
4504#1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
4505#2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
4506 at macro.c:71
4507(More stack frames follow...)
4508@end group
4509@end smallexample
4510
4511@noindent
4512The values of arguments that were not saved in their stack frames are
4513shown as @samp{<value optimized out>}.
4514
4515If you need to display the values of such optimized-out arguments,
4516either deduce that from other variables whose values depend on the one
4517you are interested in, or recompile without optimizations.
4518
a8f24a35
EZ
4519@cindex backtrace beyond @code{main} function
4520@cindex program entry point
4521@cindex startup code, and backtrace
25d29d70
AC
4522Most programs have a standard user entry point---a place where system
4523libraries and startup code transition into user code. For C this is
d416eeec
EZ
4524@code{main}@footnote{
4525Note that embedded programs (the so-called ``free-standing''
4526environment) are not required to have a @code{main} function as the
4527entry point. They could even have multiple entry points.}.
4528When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
4529it will terminate the backtrace, to avoid tracing into highly
4530system-specific (and generally uninteresting) code.
4531
4532If you need to examine the startup code, or limit the number of levels
4533in a backtrace, you can change this behavior:
95f90d25
DJ
4534
4535@table @code
25d29d70
AC
4536@item set backtrace past-main
4537@itemx set backtrace past-main on
4644b6e3 4538@kindex set backtrace
25d29d70
AC
4539Backtraces will continue past the user entry point.
4540
4541@item set backtrace past-main off
95f90d25
DJ
4542Backtraces will stop when they encounter the user entry point. This is the
4543default.
4544
25d29d70 4545@item show backtrace past-main
4644b6e3 4546@kindex show backtrace
25d29d70
AC
4547Display the current user entry point backtrace policy.
4548
2315ffec
RC
4549@item set backtrace past-entry
4550@itemx set backtrace past-entry on
a8f24a35 4551Backtraces will continue past the internal entry point of an application.
2315ffec
RC
4552This entry point is encoded by the linker when the application is built,
4553and is likely before the user entry point @code{main} (or equivalent) is called.
4554
4555@item set backtrace past-entry off
4556Backtraces will stop when they encouter the internal entry point of an
4557application. This is the default.
4558
4559@item show backtrace past-entry
4560Display the current internal entry point backtrace policy.
4561
25d29d70
AC
4562@item set backtrace limit @var{n}
4563@itemx set backtrace limit 0
4564@cindex backtrace limit
4565Limit the backtrace to @var{n} levels. A value of zero means
4566unlimited.
95f90d25 4567
25d29d70
AC
4568@item show backtrace limit
4569Display the current limit on backtrace levels.
95f90d25
DJ
4570@end table
4571
6d2ebf8b 4572@node Selection
c906108c
SS
4573@section Selecting a frame
4574
4575Most commands for examining the stack and other data in your program work on
4576whichever stack frame is selected at the moment. Here are the commands for
4577selecting a stack frame; all of them finish by printing a brief description
4578of the stack frame just selected.
4579
4580@table @code
d4f3574e 4581@kindex frame@r{, selecting}
41afff9a 4582@kindex f @r{(@code{frame})}
c906108c
SS
4583@item frame @var{n}
4584@itemx f @var{n}
4585Select frame number @var{n}. Recall that frame zero is the innermost
4586(currently executing) frame, frame one is the frame that called the
4587innermost one, and so on. The highest-numbered frame is the one for
4588@code{main}.
4589
4590@item frame @var{addr}
4591@itemx f @var{addr}
4592Select the frame at address @var{addr}. This is useful mainly if the
4593chaining of stack frames has been damaged by a bug, making it
4594impossible for @value{GDBN} to assign numbers properly to all frames. In
4595addition, this can be useful when your program has multiple stacks and
4596switches between them.
4597
c906108c
SS
4598On the SPARC architecture, @code{frame} needs two addresses to
4599select an arbitrary frame: a frame pointer and a stack pointer.
4600
4601On the MIPS and Alpha architecture, it needs two addresses: a stack
4602pointer and a program counter.
4603
4604On the 29k architecture, it needs three addresses: a register stack
4605pointer, a program counter, and a memory stack pointer.
c906108c
SS
4606
4607@kindex up
4608@item up @var{n}
4609Move @var{n} frames up the stack. For positive numbers @var{n}, this
4610advances toward the outermost frame, to higher frame numbers, to frames
4611that have existed longer. @var{n} defaults to one.
4612
4613@kindex down
41afff9a 4614@kindex do @r{(@code{down})}
c906108c
SS
4615@item down @var{n}
4616Move @var{n} frames down the stack. For positive numbers @var{n}, this
4617advances toward the innermost frame, to lower frame numbers, to frames
4618that were created more recently. @var{n} defaults to one. You may
4619abbreviate @code{down} as @code{do}.
4620@end table
4621
4622All of these commands end by printing two lines of output describing the
4623frame. The first line shows the frame number, the function name, the
4624arguments, and the source file and line number of execution in that
5d161b24 4625frame. The second line shows the text of that source line.
c906108c
SS
4626
4627@need 1000
4628For example:
4629
4630@smallexample
4631@group
4632(@value{GDBP}) up
4633#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4634 at env.c:10
463510 read_input_file (argv[i]);
4636@end group
4637@end smallexample
4638
4639After such a printout, the @code{list} command with no arguments
4640prints ten lines centered on the point of execution in the frame.
87885426
FN
4641You can also edit the program at the point of execution with your favorite
4642editing program by typing @code{edit}.
4643@xref{List, ,Printing source lines},
4644for details.
c906108c
SS
4645
4646@table @code
4647@kindex down-silently
4648@kindex up-silently
4649@item up-silently @var{n}
4650@itemx down-silently @var{n}
4651These two commands are variants of @code{up} and @code{down},
4652respectively; they differ in that they do their work silently, without
4653causing display of the new frame. They are intended primarily for use
4654in @value{GDBN} command scripts, where the output might be unnecessary and
4655distracting.
4656@end table
4657
6d2ebf8b 4658@node Frame Info
c906108c
SS
4659@section Information about a frame
4660
4661There are several other commands to print information about the selected
4662stack frame.
4663
4664@table @code
4665@item frame
4666@itemx f
4667When used without any argument, this command does not change which
4668frame is selected, but prints a brief description of the currently
4669selected stack frame. It can be abbreviated @code{f}. With an
4670argument, this command is used to select a stack frame.
4671@xref{Selection, ,Selecting a frame}.
4672
4673@kindex info frame
41afff9a 4674@kindex info f @r{(@code{info frame})}
c906108c
SS
4675@item info frame
4676@itemx info f
4677This command prints a verbose description of the selected stack frame,
4678including:
4679
4680@itemize @bullet
5d161b24
DB
4681@item
4682the address of the frame
c906108c
SS
4683@item
4684the address of the next frame down (called by this frame)
4685@item
4686the address of the next frame up (caller of this frame)
4687@item
4688the language in which the source code corresponding to this frame is written
4689@item
4690the address of the frame's arguments
4691@item
d4f3574e
SS
4692the address of the frame's local variables
4693@item
c906108c
SS
4694the program counter saved in it (the address of execution in the caller frame)
4695@item
4696which registers were saved in the frame
4697@end itemize
4698
4699@noindent The verbose description is useful when
4700something has gone wrong that has made the stack format fail to fit
4701the usual conventions.
4702
4703@item info frame @var{addr}
4704@itemx info f @var{addr}
4705Print a verbose description of the frame at address @var{addr}, without
4706selecting that frame. The selected frame remains unchanged by this
4707command. This requires the same kind of address (more than one for some
4708architectures) that you specify in the @code{frame} command.
4709@xref{Selection, ,Selecting a frame}.
4710
4711@kindex info args
4712@item info args
4713Print the arguments of the selected frame, each on a separate line.
4714
4715@item info locals
4716@kindex info locals
4717Print the local variables of the selected frame, each on a separate
4718line. These are all variables (declared either static or automatic)
4719accessible at the point of execution of the selected frame.
4720
c906108c 4721@kindex info catch
d4f3574e
SS
4722@cindex catch exceptions, list active handlers
4723@cindex exception handlers, how to list
c906108c
SS
4724@item info catch
4725Print a list of all the exception handlers that are active in the
4726current stack frame at the current point of execution. To see other
4727exception handlers, visit the associated frame (using the @code{up},
4728@code{down}, or @code{frame} commands); then type @code{info catch}.
4729@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4730
c906108c
SS
4731@end table
4732
c906108c 4733
6d2ebf8b 4734@node Source
c906108c
SS
4735@chapter Examining Source Files
4736
4737@value{GDBN} can print parts of your program's source, since the debugging
4738information recorded in the program tells @value{GDBN} what source files were
4739used to build it. When your program stops, @value{GDBN} spontaneously prints
4740the line where it stopped. Likewise, when you select a stack frame
4741(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4742execution in that frame has stopped. You can print other portions of
4743source files by explicit command.
4744
7a292a7a 4745If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4746prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4747@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4748
4749@menu
4750* List:: Printing source lines
87885426 4751* Edit:: Editing source files
c906108c 4752* Search:: Searching source files
c906108c
SS
4753* Source Path:: Specifying source directories
4754* Machine Code:: Source and machine code
4755@end menu
4756
6d2ebf8b 4757@node List
c906108c
SS
4758@section Printing source lines
4759
4760@kindex list
41afff9a 4761@kindex l @r{(@code{list})}
c906108c 4762To print lines from a source file, use the @code{list} command
5d161b24 4763(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4764There are several ways to specify what part of the file you want to print.
4765
4766Here are the forms of the @code{list} command most commonly used:
4767
4768@table @code
4769@item list @var{linenum}
4770Print lines centered around line number @var{linenum} in the
4771current source file.
4772
4773@item list @var{function}
4774Print lines centered around the beginning of function
4775@var{function}.
4776
4777@item list
4778Print more lines. If the last lines printed were printed with a
4779@code{list} command, this prints lines following the last lines
4780printed; however, if the last line printed was a solitary line printed
4781as part of displaying a stack frame (@pxref{Stack, ,Examining the
4782Stack}), this prints lines centered around that line.
4783
4784@item list -
4785Print lines just before the lines last printed.
4786@end table
4787
9c16f35a 4788@cindex @code{list}, how many lines to display
c906108c
SS
4789By default, @value{GDBN} prints ten source lines with any of these forms of
4790the @code{list} command. You can change this using @code{set listsize}:
4791
4792@table @code
4793@kindex set listsize
4794@item set listsize @var{count}
4795Make the @code{list} command display @var{count} source lines (unless
4796the @code{list} argument explicitly specifies some other number).
4797
4798@kindex show listsize
4799@item show listsize
4800Display the number of lines that @code{list} prints.
4801@end table
4802
4803Repeating a @code{list} command with @key{RET} discards the argument,
4804so it is equivalent to typing just @code{list}. This is more useful
4805than listing the same lines again. An exception is made for an
4806argument of @samp{-}; that argument is preserved in repetition so that
4807each repetition moves up in the source file.
4808
4809@cindex linespec
4810In general, the @code{list} command expects you to supply zero, one or two
4811@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4812of writing them, but the effect is always to specify some source line.
c906108c
SS
4813Here is a complete description of the possible arguments for @code{list}:
4814
4815@table @code
4816@item list @var{linespec}
4817Print lines centered around the line specified by @var{linespec}.
4818
4819@item list @var{first},@var{last}
4820Print lines from @var{first} to @var{last}. Both arguments are
4821linespecs.
4822
4823@item list ,@var{last}
4824Print lines ending with @var{last}.
4825
4826@item list @var{first},
4827Print lines starting with @var{first}.
4828
4829@item list +
4830Print lines just after the lines last printed.
4831
4832@item list -
4833Print lines just before the lines last printed.
4834
4835@item list
4836As described in the preceding table.
4837@end table
4838
4839Here are the ways of specifying a single source line---all the
4840kinds of linespec.
4841
4842@table @code
4843@item @var{number}
4844Specifies line @var{number} of the current source file.
4845When a @code{list} command has two linespecs, this refers to
4846the same source file as the first linespec.
4847
4848@item +@var{offset}
4849Specifies the line @var{offset} lines after the last line printed.
4850When used as the second linespec in a @code{list} command that has
4851two, this specifies the line @var{offset} lines down from the
4852first linespec.
4853
4854@item -@var{offset}
4855Specifies the line @var{offset} lines before the last line printed.
4856
4857@item @var{filename}:@var{number}
4858Specifies line @var{number} in the source file @var{filename}.
4859
4860@item @var{function}
4861Specifies the line that begins the body of the function @var{function}.
4862For example: in C, this is the line with the open brace.
4863
4864@item @var{filename}:@var{function}
4865Specifies the line of the open-brace that begins the body of the
4866function @var{function} in the file @var{filename}. You only need the
4867file name with a function name to avoid ambiguity when there are
4868identically named functions in different source files.
4869
4870@item *@var{address}
4871Specifies the line containing the program address @var{address}.
4872@var{address} may be any expression.
4873@end table
4874
87885426
FN
4875@node Edit
4876@section Editing source files
4877@cindex editing source files
4878
4879@kindex edit
4880@kindex e @r{(@code{edit})}
4881To edit the lines in a source file, use the @code{edit} command.
4882The editing program of your choice
4883is invoked with the current line set to
4884the active line in the program.
4885Alternatively, there are several ways to specify what part of the file you
4886want to print if you want to see other parts of the program.
4887
4888Here are the forms of the @code{edit} command most commonly used:
4889
4890@table @code
4891@item edit
4892Edit the current source file at the active line number in the program.
4893
4894@item edit @var{number}
4895Edit the current source file with @var{number} as the active line number.
4896
4897@item edit @var{function}
4898Edit the file containing @var{function} at the beginning of its definition.
4899
4900@item edit @var{filename}:@var{number}
4901Specifies line @var{number} in the source file @var{filename}.
4902
4903@item edit @var{filename}:@var{function}
4904Specifies the line that begins the body of the
4905function @var{function} in the file @var{filename}. You only need the
4906file name with a function name to avoid ambiguity when there are
4907identically named functions in different source files.
4908
4909@item edit *@var{address}
4910Specifies the line containing the program address @var{address}.
4911@var{address} may be any expression.
4912@end table
4913
4914@subsection Choosing your editor
4915You can customize @value{GDBN} to use any editor you want
4916@footnote{
4917The only restriction is that your editor (say @code{ex}), recognizes the
4918following command-line syntax:
10998722 4919@smallexample
87885426 4920ex +@var{number} file
10998722 4921@end smallexample
15387254
EZ
4922The optional numeric value +@var{number} specifies the number of the line in
4923the file where to start editing.}.
4924By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4925by setting the environment variable @code{EDITOR} before using
4926@value{GDBN}. For example, to configure @value{GDBN} to use the
4927@code{vi} editor, you could use these commands with the @code{sh} shell:
4928@smallexample
87885426
FN
4929EDITOR=/usr/bin/vi
4930export EDITOR
15387254 4931gdb @dots{}
10998722 4932@end smallexample
87885426 4933or in the @code{csh} shell,
10998722 4934@smallexample
87885426 4935setenv EDITOR /usr/bin/vi
15387254 4936gdb @dots{}
10998722 4937@end smallexample
87885426 4938
6d2ebf8b 4939@node Search
c906108c 4940@section Searching source files
15387254 4941@cindex searching source files
c906108c
SS
4942
4943There are two commands for searching through the current source file for a
4944regular expression.
4945
4946@table @code
4947@kindex search
4948@kindex forward-search
4949@item forward-search @var{regexp}
4950@itemx search @var{regexp}
4951The command @samp{forward-search @var{regexp}} checks each line,
4952starting with the one following the last line listed, for a match for
5d161b24 4953@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4954synonym @samp{search @var{regexp}} or abbreviate the command name as
4955@code{fo}.
4956
09d4efe1 4957@kindex reverse-search
c906108c
SS
4958@item reverse-search @var{regexp}
4959The command @samp{reverse-search @var{regexp}} checks each line, starting
4960with the one before the last line listed and going backward, for a match
4961for @var{regexp}. It lists the line that is found. You can abbreviate
4962this command as @code{rev}.
4963@end table
c906108c 4964
6d2ebf8b 4965@node Source Path
c906108c
SS
4966@section Specifying source directories
4967
4968@cindex source path
4969@cindex directories for source files
4970Executable programs sometimes do not record the directories of the source
4971files from which they were compiled, just the names. Even when they do,
4972the directories could be moved between the compilation and your debugging
4973session. @value{GDBN} has a list of directories to search for source files;
4974this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4975it tries all the directories in the list, in the order they are present
0b66e38c
EZ
4976in the list, until it finds a file with the desired name.
4977
4978For example, suppose an executable references the file
4979@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4980@file{/mnt/cross}. The file is first looked up literally; if this
4981fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4982fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4983message is printed. @value{GDBN} does not look up the parts of the
4984source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4985Likewise, the subdirectories of the source path are not searched: if
4986the source path is @file{/mnt/cross}, and the binary refers to
4987@file{foo.c}, @value{GDBN} would not find it under
4988@file{/mnt/cross/usr/src/foo-1.0/lib}.
4989
4990Plain file names, relative file names with leading directories, file
4991names containing dots, etc.@: are all treated as described above; for
4992instance, if the source path is @file{/mnt/cross}, and the source file
4993is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4994@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4995that---@file{/mnt/cross/foo.c}.
4996
4997Note that the executable search path is @emph{not} used to locate the
4998source files. Neither is the current working directory, unless it
4999happens to be in the source path.
c906108c
SS
5000
5001Whenever you reset or rearrange the source path, @value{GDBN} clears out
5002any information it has cached about where source files are found and where
5003each line is in the file.
5004
5005@kindex directory
5006@kindex dir
d4f3574e
SS
5007When you start @value{GDBN}, its source path includes only @samp{cdir}
5008and @samp{cwd}, in that order.
c906108c
SS
5009To add other directories, use the @code{directory} command.
5010
5011@table @code
5012@item directory @var{dirname} @dots{}
5013@item dir @var{dirname} @dots{}
5014Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
5015directory names may be given to this command, separated by @samp{:}
5016(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
5017part of absolute file names) or
c906108c
SS
5018whitespace. You may specify a directory that is already in the source
5019path; this moves it forward, so @value{GDBN} searches it sooner.
5020
5021@kindex cdir
5022@kindex cwd
41afff9a
EZ
5023@vindex $cdir@r{, convenience variable}
5024@vindex $cwdr@r{, convenience variable}
c906108c
SS
5025@cindex compilation directory
5026@cindex current directory
5027@cindex working directory
5028@cindex directory, current
5029@cindex directory, compilation
5030You can use the string @samp{$cdir} to refer to the compilation
5031directory (if one is recorded), and @samp{$cwd} to refer to the current
5032working directory. @samp{$cwd} is not the same as @samp{.}---the former
5033tracks the current working directory as it changes during your @value{GDBN}
5034session, while the latter is immediately expanded to the current
5035directory at the time you add an entry to the source path.
5036
5037@item directory
5038Reset the source path to empty again. This requires confirmation.
5039
5040@c RET-repeat for @code{directory} is explicitly disabled, but since
5041@c repeating it would be a no-op we do not say that. (thanks to RMS)
5042
5043@item show directories
5044@kindex show directories
5045Print the source path: show which directories it contains.
5046@end table
5047
5048If your source path is cluttered with directories that are no longer of
5049interest, @value{GDBN} may sometimes cause confusion by finding the wrong
5050versions of source. You can correct the situation as follows:
5051
5052@enumerate
5053@item
5054Use @code{directory} with no argument to reset the source path to empty.
5055
5056@item
5057Use @code{directory} with suitable arguments to reinstall the
5058directories you want in the source path. You can add all the
5059directories in one command.
5060@end enumerate
5061
6d2ebf8b 5062@node Machine Code
c906108c 5063@section Source and machine code
15387254 5064@cindex source line and its code address
c906108c
SS
5065
5066You can use the command @code{info line} to map source lines to program
5067addresses (and vice versa), and the command @code{disassemble} to display
5068a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 5069mode, the @code{info line} command causes the arrow to point to the
5d161b24 5070line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
5071well as hex.
5072
5073@table @code
5074@kindex info line
5075@item info line @var{linespec}
5076Print the starting and ending addresses of the compiled code for
5077source line @var{linespec}. You can specify source lines in any of
5078the ways understood by the @code{list} command (@pxref{List, ,Printing
5079source lines}).
5080@end table
5081
5082For example, we can use @code{info line} to discover the location of
5083the object code for the first line of function
5084@code{m4_changequote}:
5085
d4f3574e
SS
5086@c FIXME: I think this example should also show the addresses in
5087@c symbolic form, as they usually would be displayed.
c906108c 5088@smallexample
96a2c332 5089(@value{GDBP}) info line m4_changequote
c906108c
SS
5090Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
5091@end smallexample
5092
5093@noindent
15387254 5094@cindex code address and its source line
c906108c
SS
5095We can also inquire (using @code{*@var{addr}} as the form for
5096@var{linespec}) what source line covers a particular address:
5097@smallexample
5098(@value{GDBP}) info line *0x63ff
5099Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
5100@end smallexample
5101
5102@cindex @code{$_} and @code{info line}
15387254 5103@cindex @code{x} command, default address
41afff9a 5104@kindex x@r{(examine), and} info line
c906108c
SS
5105After @code{info line}, the default address for the @code{x} command
5106is changed to the starting address of the line, so that @samp{x/i} is
5107sufficient to begin examining the machine code (@pxref{Memory,
5108,Examining memory}). Also, this address is saved as the value of the
5109convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
5110variables}).
5111
5112@table @code
5113@kindex disassemble
5114@cindex assembly instructions
5115@cindex instructions, assembly
5116@cindex machine instructions
5117@cindex listing machine instructions
5118@item disassemble
5119This specialized command dumps a range of memory as machine
5120instructions. The default memory range is the function surrounding the
5121program counter of the selected frame. A single argument to this
5122command is a program counter value; @value{GDBN} dumps the function
5123surrounding this value. Two arguments specify a range of addresses
5124(first inclusive, second exclusive) to dump.
5125@end table
5126
c906108c
SS
5127The following example shows the disassembly of a range of addresses of
5128HP PA-RISC 2.0 code:
5129
5130@smallexample
5131(@value{GDBP}) disas 0x32c4 0x32e4
5132Dump of assembler code from 0x32c4 to 0x32e4:
51330x32c4 <main+204>: addil 0,dp
51340x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
51350x32cc <main+212>: ldil 0x3000,r31
51360x32d0 <main+216>: ble 0x3f8(sr4,r31)
51370x32d4 <main+220>: ldo 0(r31),rp
51380x32d8 <main+224>: addil -0x800,dp
51390x32dc <main+228>: ldo 0x588(r1),r26
51400x32e0 <main+232>: ldil 0x3000,r31
5141End of assembler dump.
5142@end smallexample
c906108c
SS
5143
5144Some architectures have more than one commonly-used set of instruction
5145mnemonics or other syntax.
5146
76d17f34
EZ
5147For programs that were dynamically linked and use shared libraries,
5148instructions that call functions or branch to locations in the shared
5149libraries might show a seemingly bogus location---it's actually a
5150location of the relocation table. On some architectures, @value{GDBN}
5151might be able to resolve these to actual function names.
5152
c906108c 5153@table @code
d4f3574e 5154@kindex set disassembly-flavor
d4f3574e
SS
5155@cindex Intel disassembly flavor
5156@cindex AT&T disassembly flavor
5157@item set disassembly-flavor @var{instruction-set}
c906108c
SS
5158Select the instruction set to use when disassembling the
5159program via the @code{disassemble} or @code{x/i} commands.
5160
5161Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
5162can set @var{instruction-set} to either @code{intel} or @code{att}.
5163The default is @code{att}, the AT&T flavor used by default by Unix
5164assemblers for x86-based targets.
9c16f35a
EZ
5165
5166@kindex show disassembly-flavor
5167@item show disassembly-flavor
5168Show the current setting of the disassembly flavor.
c906108c
SS
5169@end table
5170
5171
6d2ebf8b 5172@node Data
c906108c
SS
5173@chapter Examining Data
5174
5175@cindex printing data
5176@cindex examining data
5177@kindex print
5178@kindex inspect
5179@c "inspect" is not quite a synonym if you are using Epoch, which we do not
5180@c document because it is nonstandard... Under Epoch it displays in a
5181@c different window or something like that.
5182The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
5183command (abbreviated @code{p}), or its synonym @code{inspect}. It
5184evaluates and prints the value of an expression of the language your
5185program is written in (@pxref{Languages, ,Using @value{GDBN} with
5186Different Languages}).
c906108c
SS
5187
5188@table @code
d4f3574e
SS
5189@item print @var{expr}
5190@itemx print /@var{f} @var{expr}
5191@var{expr} is an expression (in the source language). By default the
5192value of @var{expr} is printed in a format appropriate to its data type;
c906108c 5193you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 5194@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
5195formats}.
5196
5197@item print
5198@itemx print /@var{f}
15387254 5199@cindex reprint the last value
d4f3574e 5200If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
5201@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
5202conveniently inspect the same value in an alternative format.
5203@end table
5204
5205A more low-level way of examining data is with the @code{x} command.
5206It examines data in memory at a specified address and prints it in a
5207specified format. @xref{Memory, ,Examining memory}.
5208
7a292a7a 5209If you are interested in information about types, or about how the
d4f3574e
SS
5210fields of a struct or a class are declared, use the @code{ptype @var{exp}}
5211command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 5212Table}.
c906108c
SS
5213
5214@menu
5215* Expressions:: Expressions
5216* Variables:: Program variables
5217* Arrays:: Artificial arrays
5218* Output Formats:: Output formats
5219* Memory:: Examining memory
5220* Auto Display:: Automatic display
5221* Print Settings:: Print settings
5222* Value History:: Value history
5223* Convenience Vars:: Convenience variables
5224* Registers:: Registers
c906108c 5225* Floating Point Hardware:: Floating point hardware
53c69bd7 5226* Vector Unit:: Vector Unit
721c2651 5227* OS Information:: Auxiliary data provided by operating system
29e57380 5228* Memory Region Attributes:: Memory region attributes
16d9dec6 5229* Dump/Restore Files:: Copy between memory and a file
384ee23f 5230* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
5231* Character Sets:: Debugging programs that use a different
5232 character set than GDB does
09d4efe1 5233* Caching Remote Data:: Data caching for remote targets
c906108c
SS
5234@end menu
5235
6d2ebf8b 5236@node Expressions
c906108c
SS
5237@section Expressions
5238
5239@cindex expressions
5240@code{print} and many other @value{GDBN} commands accept an expression and
5241compute its value. Any kind of constant, variable or operator defined
5242by the programming language you are using is valid in an expression in
e2e0bcd1
JB
5243@value{GDBN}. This includes conditional expressions, function calls,
5244casts, and string constants. It also includes preprocessor macros, if
5245you compiled your program to include this information; see
5246@ref{Compilation}.
c906108c 5247
15387254 5248@cindex arrays in expressions
d4f3574e
SS
5249@value{GDBN} supports array constants in expressions input by
5250the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 5251you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 5252memory that is @code{malloc}ed in the target program.
c906108c 5253
c906108c
SS
5254Because C is so widespread, most of the expressions shown in examples in
5255this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
5256Languages}, for information on how to use expressions in other
5257languages.
5258
5259In this section, we discuss operators that you can use in @value{GDBN}
5260expressions regardless of your programming language.
5261
15387254 5262@cindex casts, in expressions
c906108c
SS
5263Casts are supported in all languages, not just in C, because it is so
5264useful to cast a number into a pointer in order to examine a structure
5265at that address in memory.
5266@c FIXME: casts supported---Mod2 true?
c906108c
SS
5267
5268@value{GDBN} supports these operators, in addition to those common
5269to programming languages:
5270
5271@table @code
5272@item @@
5273@samp{@@} is a binary operator for treating parts of memory as arrays.
5274@xref{Arrays, ,Artificial arrays}, for more information.
5275
5276@item ::
5277@samp{::} allows you to specify a variable in terms of the file or
5278function where it is defined. @xref{Variables, ,Program variables}.
5279
5280@cindex @{@var{type}@}
5281@cindex type casting memory
5282@cindex memory, viewing as typed object
5283@cindex casts, to view memory
5284@item @{@var{type}@} @var{addr}
5285Refers to an object of type @var{type} stored at address @var{addr} in
5286memory. @var{addr} may be any expression whose value is an integer or
5287pointer (but parentheses are required around binary operators, just as in
5288a cast). This construct is allowed regardless of what kind of data is
5289normally supposed to reside at @var{addr}.
5290@end table
5291
6d2ebf8b 5292@node Variables
c906108c
SS
5293@section Program variables
5294
5295The most common kind of expression to use is the name of a variable
5296in your program.
5297
5298Variables in expressions are understood in the selected stack frame
5299(@pxref{Selection, ,Selecting a frame}); they must be either:
5300
5301@itemize @bullet
5302@item
5303global (or file-static)
5304@end itemize
5305
5d161b24 5306@noindent or
c906108c
SS
5307
5308@itemize @bullet
5309@item
5310visible according to the scope rules of the
5311programming language from the point of execution in that frame
5d161b24 5312@end itemize
c906108c
SS
5313
5314@noindent This means that in the function
5315
474c8240 5316@smallexample
c906108c
SS
5317foo (a)
5318 int a;
5319@{
5320 bar (a);
5321 @{
5322 int b = test ();
5323 bar (b);
5324 @}
5325@}
474c8240 5326@end smallexample
c906108c
SS
5327
5328@noindent
5329you can examine and use the variable @code{a} whenever your program is
5330executing within the function @code{foo}, but you can only use or
5331examine the variable @code{b} while your program is executing inside
5332the block where @code{b} is declared.
5333
5334@cindex variable name conflict
5335There is an exception: you can refer to a variable or function whose
5336scope is a single source file even if the current execution point is not
5337in this file. But it is possible to have more than one such variable or
5338function with the same name (in different source files). If that
5339happens, referring to that name has unpredictable effects. If you wish,
5340you can specify a static variable in a particular function or file,
15387254 5341using the colon-colon (@code{::}) notation:
c906108c 5342
d4f3574e 5343@cindex colon-colon, context for variables/functions
c906108c
SS
5344@iftex
5345@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 5346@cindex @code{::}, context for variables/functions
c906108c 5347@end iftex
474c8240 5348@smallexample
c906108c
SS
5349@var{file}::@var{variable}
5350@var{function}::@var{variable}
474c8240 5351@end smallexample
c906108c
SS
5352
5353@noindent
5354Here @var{file} or @var{function} is the name of the context for the
5355static @var{variable}. In the case of file names, you can use quotes to
5356make sure @value{GDBN} parses the file name as a single word---for example,
5357to print a global value of @code{x} defined in @file{f2.c}:
5358
474c8240 5359@smallexample
c906108c 5360(@value{GDBP}) p 'f2.c'::x
474c8240 5361@end smallexample
c906108c 5362
b37052ae 5363@cindex C@t{++} scope resolution
c906108c 5364This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 5365use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
5366scope resolution operator in @value{GDBN} expressions.
5367@c FIXME: Um, so what happens in one of those rare cases where it's in
5368@c conflict?? --mew
c906108c
SS
5369
5370@cindex wrong values
5371@cindex variable values, wrong
15387254
EZ
5372@cindex function entry/exit, wrong values of variables
5373@cindex optimized code, wrong values of variables
c906108c
SS
5374@quotation
5375@emph{Warning:} Occasionally, a local variable may appear to have the
5376wrong value at certain points in a function---just after entry to a new
5377scope, and just before exit.
5378@end quotation
5379You may see this problem when you are stepping by machine instructions.
5380This is because, on most machines, it takes more than one instruction to
5381set up a stack frame (including local variable definitions); if you are
5382stepping by machine instructions, variables may appear to have the wrong
5383values until the stack frame is completely built. On exit, it usually
5384also takes more than one machine instruction to destroy a stack frame;
5385after you begin stepping through that group of instructions, local
5386variable definitions may be gone.
5387
5388This may also happen when the compiler does significant optimizations.
5389To be sure of always seeing accurate values, turn off all optimization
5390when compiling.
5391
d4f3574e
SS
5392@cindex ``No symbol "foo" in current context''
5393Another possible effect of compiler optimizations is to optimize
5394unused variables out of existence, or assign variables to registers (as
5395opposed to memory addresses). Depending on the support for such cases
5396offered by the debug info format used by the compiler, @value{GDBN}
5397might not be able to display values for such local variables. If that
5398happens, @value{GDBN} will print a message like this:
5399
474c8240 5400@smallexample
d4f3574e 5401No symbol "foo" in current context.
474c8240 5402@end smallexample
d4f3574e
SS
5403
5404To solve such problems, either recompile without optimizations, or use a
5405different debug info format, if the compiler supports several such
15387254 5406formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
5407usually supports the @option{-gstabs+} option. @option{-gstabs+}
5408produces debug info in a format that is superior to formats such as
5409COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5410an effective form for debug info. @xref{Debugging Options,,Options
5411for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
5412@xref{C, , Debugging C++}, for more info about debug info formats
5413that are best suited to C@t{++} programs.
d4f3574e 5414
ab1adacd
EZ
5415If you ask to print an object whose contents are unknown to
5416@value{GDBN}, e.g., because its data type is not completely specified
5417by the debug information, @value{GDBN} will say @samp{<incomplete
5418type>}. @xref{Symbols, incomplete type}, for more about this.
5419
6d2ebf8b 5420@node Arrays
c906108c
SS
5421@section Artificial arrays
5422
5423@cindex artificial array
15387254 5424@cindex arrays
41afff9a 5425@kindex @@@r{, referencing memory as an array}
c906108c
SS
5426It is often useful to print out several successive objects of the
5427same type in memory; a section of an array, or an array of
5428dynamically determined size for which only a pointer exists in the
5429program.
5430
5431You can do this by referring to a contiguous span of memory as an
5432@dfn{artificial array}, using the binary operator @samp{@@}. The left
5433operand of @samp{@@} should be the first element of the desired array
5434and be an individual object. The right operand should be the desired length
5435of the array. The result is an array value whose elements are all of
5436the type of the left argument. The first element is actually the left
5437argument; the second element comes from bytes of memory immediately
5438following those that hold the first element, and so on. Here is an
5439example. If a program says
5440
474c8240 5441@smallexample
c906108c 5442int *array = (int *) malloc (len * sizeof (int));
474c8240 5443@end smallexample
c906108c
SS
5444
5445@noindent
5446you can print the contents of @code{array} with
5447
474c8240 5448@smallexample
c906108c 5449p *array@@len
474c8240 5450@end smallexample
c906108c
SS
5451
5452The left operand of @samp{@@} must reside in memory. Array values made
5453with @samp{@@} in this way behave just like other arrays in terms of
5454subscripting, and are coerced to pointers when used in expressions.
5455Artificial arrays most often appear in expressions via the value history
5456(@pxref{Value History, ,Value history}), after printing one out.
5457
5458Another way to create an artificial array is to use a cast.
5459This re-interprets a value as if it were an array.
5460The value need not be in memory:
474c8240 5461@smallexample
c906108c
SS
5462(@value{GDBP}) p/x (short[2])0x12345678
5463$1 = @{0x1234, 0x5678@}
474c8240 5464@end smallexample
c906108c
SS
5465
5466As a convenience, if you leave the array length out (as in
c3f6f71d 5467@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5468the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5469@smallexample
c906108c
SS
5470(@value{GDBP}) p/x (short[])0x12345678
5471$2 = @{0x1234, 0x5678@}
474c8240 5472@end smallexample
c906108c
SS
5473
5474Sometimes the artificial array mechanism is not quite enough; in
5475moderately complex data structures, the elements of interest may not
5476actually be adjacent---for example, if you are interested in the values
5477of pointers in an array. One useful work-around in this situation is
5478to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5479variables}) as a counter in an expression that prints the first
5480interesting value, and then repeat that expression via @key{RET}. For
5481instance, suppose you have an array @code{dtab} of pointers to
5482structures, and you are interested in the values of a field @code{fv}
5483in each structure. Here is an example of what you might type:
5484
474c8240 5485@smallexample
c906108c
SS
5486set $i = 0
5487p dtab[$i++]->fv
5488@key{RET}
5489@key{RET}
5490@dots{}
474c8240 5491@end smallexample
c906108c 5492
6d2ebf8b 5493@node Output Formats
c906108c
SS
5494@section Output formats
5495
5496@cindex formatted output
5497@cindex output formats
5498By default, @value{GDBN} prints a value according to its data type. Sometimes
5499this is not what you want. For example, you might want to print a number
5500in hex, or a pointer in decimal. Or you might want to view data in memory
5501at a certain address as a character string or as an instruction. To do
5502these things, specify an @dfn{output format} when you print a value.
5503
5504The simplest use of output formats is to say how to print a value
5505already computed. This is done by starting the arguments of the
5506@code{print} command with a slash and a format letter. The format
5507letters supported are:
5508
5509@table @code
5510@item x
5511Regard the bits of the value as an integer, and print the integer in
5512hexadecimal.
5513
5514@item d
5515Print as integer in signed decimal.
5516
5517@item u
5518Print as integer in unsigned decimal.
5519
5520@item o
5521Print as integer in octal.
5522
5523@item t
5524Print as integer in binary. The letter @samp{t} stands for ``two''.
5525@footnote{@samp{b} cannot be used because these format letters are also
5526used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5527see @ref{Memory,,Examining memory}.}
c906108c
SS
5528
5529@item a
5530@cindex unknown address, locating
3d67e040 5531@cindex locate address
c906108c
SS
5532Print as an address, both absolute in hexadecimal and as an offset from
5533the nearest preceding symbol. You can use this format used to discover
5534where (in what function) an unknown address is located:
5535
474c8240 5536@smallexample
c906108c
SS
5537(@value{GDBP}) p/a 0x54320
5538$3 = 0x54320 <_initialize_vx+396>
474c8240 5539@end smallexample
c906108c 5540
3d67e040
EZ
5541@noindent
5542The command @code{info symbol 0x54320} yields similar results.
5543@xref{Symbols, info symbol}.
5544
c906108c 5545@item c
51274035
EZ
5546Regard as an integer and print it as a character constant. This
5547prints both the numerical value and its character representation. The
5548character representation is replaced with the octal escape @samp{\nnn}
5549for characters outside the 7-bit @sc{ascii} range.
c906108c
SS
5550
5551@item f
5552Regard the bits of the value as a floating point number and print
5553using typical floating point syntax.
5554@end table
5555
5556For example, to print the program counter in hex (@pxref{Registers}), type
5557
474c8240 5558@smallexample
c906108c 5559p/x $pc
474c8240 5560@end smallexample
c906108c
SS
5561
5562@noindent
5563Note that no space is required before the slash; this is because command
5564names in @value{GDBN} cannot contain a slash.
5565
5566To reprint the last value in the value history with a different format,
5567you can use the @code{print} command with just a format and no
5568expression. For example, @samp{p/x} reprints the last value in hex.
5569
6d2ebf8b 5570@node Memory
c906108c
SS
5571@section Examining memory
5572
5573You can use the command @code{x} (for ``examine'') to examine memory in
5574any of several formats, independently of your program's data types.
5575
5576@cindex examining memory
5577@table @code
41afff9a 5578@kindex x @r{(examine memory)}
c906108c
SS
5579@item x/@var{nfu} @var{addr}
5580@itemx x @var{addr}
5581@itemx x
5582Use the @code{x} command to examine memory.
5583@end table
5584
5585@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5586much memory to display and how to format it; @var{addr} is an
5587expression giving the address where you want to start displaying memory.
5588If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5589Several commands set convenient defaults for @var{addr}.
5590
5591@table @r
5592@item @var{n}, the repeat count
5593The repeat count is a decimal integer; the default is 1. It specifies
5594how much memory (counting by units @var{u}) to display.
5595@c This really is **decimal**; unaffected by 'set radix' as of GDB
5596@c 4.1.2.
5597
5598@item @var{f}, the display format
51274035
EZ
5599The display format is one of the formats used by @code{print}
5600(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
5601@samp{f}), and in addition @samp{s} (for null-terminated strings) and
5602@samp{i} (for machine instructions). The default is @samp{x}
5603(hexadecimal) initially. The default changes each time you use either
5604@code{x} or @code{print}.
c906108c
SS
5605
5606@item @var{u}, the unit size
5607The unit size is any of
5608
5609@table @code
5610@item b
5611Bytes.
5612@item h
5613Halfwords (two bytes).
5614@item w
5615Words (four bytes). This is the initial default.
5616@item g
5617Giant words (eight bytes).
5618@end table
5619
5620Each time you specify a unit size with @code{x}, that size becomes the
5621default unit the next time you use @code{x}. (For the @samp{s} and
5622@samp{i} formats, the unit size is ignored and is normally not written.)
5623
5624@item @var{addr}, starting display address
5625@var{addr} is the address where you want @value{GDBN} to begin displaying
5626memory. The expression need not have a pointer value (though it may);
5627it is always interpreted as an integer address of a byte of memory.
5628@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5629@var{addr} is usually just after the last address examined---but several
5630other commands also set the default address: @code{info breakpoints} (to
5631the address of the last breakpoint listed), @code{info line} (to the
5632starting address of a line), and @code{print} (if you use it to display
5633a value from memory).
5634@end table
5635
5636For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5637(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5638starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5639words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5640@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5641
5642Since the letters indicating unit sizes are all distinct from the
5643letters specifying output formats, you do not have to remember whether
5644unit size or format comes first; either order works. The output
5645specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5646(However, the count @var{n} must come first; @samp{wx4} does not work.)
5647
5648Even though the unit size @var{u} is ignored for the formats @samp{s}
5649and @samp{i}, you might still want to use a count @var{n}; for example,
5650@samp{3i} specifies that you want to see three machine instructions,
5651including any operands. The command @code{disassemble} gives an
d4f3574e 5652alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5653Code,,Source and machine code}.
5654
5655All the defaults for the arguments to @code{x} are designed to make it
5656easy to continue scanning memory with minimal specifications each time
5657you use @code{x}. For example, after you have inspected three machine
5658instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5659with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5660the repeat count @var{n} is used again; the other arguments default as
5661for successive uses of @code{x}.
5662
5663@cindex @code{$_}, @code{$__}, and value history
5664The addresses and contents printed by the @code{x} command are not saved
5665in the value history because there is often too much of them and they
5666would get in the way. Instead, @value{GDBN} makes these values available for
5667subsequent use in expressions as values of the convenience variables
5668@code{$_} and @code{$__}. After an @code{x} command, the last address
5669examined is available for use in expressions in the convenience variable
5670@code{$_}. The contents of that address, as examined, are available in
5671the convenience variable @code{$__}.
5672
5673If the @code{x} command has a repeat count, the address and contents saved
5674are from the last memory unit printed; this is not the same as the last
5675address printed if several units were printed on the last line of output.
5676
09d4efe1
EZ
5677@cindex remote memory comparison
5678@cindex verify remote memory image
5679When you are debugging a program running on a remote target machine
5680(@pxref{Remote}), you may wish to verify the program's image in the
5681remote machine's memory against the executable file you downloaded to
5682the target. The @code{compare-sections} command is provided for such
5683situations.
5684
5685@table @code
5686@kindex compare-sections
5687@item compare-sections @r{[}@var{section-name}@r{]}
5688Compare the data of a loadable section @var{section-name} in the
5689executable file of the program being debugged with the same section in
5690the remote machine's memory, and report any mismatches. With no
5691arguments, compares all loadable sections. This command's
5692availability depends on the target's support for the @code{"qCRC"}
5693remote request.
5694@end table
5695
6d2ebf8b 5696@node Auto Display
c906108c
SS
5697@section Automatic display
5698@cindex automatic display
5699@cindex display of expressions
5700
5701If you find that you want to print the value of an expression frequently
5702(to see how it changes), you might want to add it to the @dfn{automatic
5703display list} so that @value{GDBN} prints its value each time your program stops.
5704Each expression added to the list is given a number to identify it;
5705to remove an expression from the list, you specify that number.
5706The automatic display looks like this:
5707
474c8240 5708@smallexample
c906108c
SS
57092: foo = 38
57103: bar[5] = (struct hack *) 0x3804
474c8240 5711@end smallexample
c906108c
SS
5712
5713@noindent
5714This display shows item numbers, expressions and their current values. As with
5715displays you request manually using @code{x} or @code{print}, you can
5716specify the output format you prefer; in fact, @code{display} decides
5717whether to use @code{print} or @code{x} depending on how elaborate your
5718format specification is---it uses @code{x} if you specify a unit size,
5719or one of the two formats (@samp{i} and @samp{s}) that are only
5720supported by @code{x}; otherwise it uses @code{print}.
5721
5722@table @code
5723@kindex display
d4f3574e
SS
5724@item display @var{expr}
5725Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5726each time your program stops. @xref{Expressions, ,Expressions}.
5727
5728@code{display} does not repeat if you press @key{RET} again after using it.
5729
d4f3574e 5730@item display/@var{fmt} @var{expr}
c906108c 5731For @var{fmt} specifying only a display format and not a size or
d4f3574e 5732count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5733arrange to display it each time in the specified format @var{fmt}.
5734@xref{Output Formats,,Output formats}.
5735
5736@item display/@var{fmt} @var{addr}
5737For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5738number of units, add the expression @var{addr} as a memory address to
5739be examined each time your program stops. Examining means in effect
5740doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5741@end table
5742
5743For example, @samp{display/i $pc} can be helpful, to see the machine
5744instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5745is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5746
5747@table @code
5748@kindex delete display
5749@kindex undisplay
5750@item undisplay @var{dnums}@dots{}
5751@itemx delete display @var{dnums}@dots{}
5752Remove item numbers @var{dnums} from the list of expressions to display.
5753
5754@code{undisplay} does not repeat if you press @key{RET} after using it.
5755(Otherwise you would just get the error @samp{No display number @dots{}}.)
5756
5757@kindex disable display
5758@item disable display @var{dnums}@dots{}
5759Disable the display of item numbers @var{dnums}. A disabled display
5760item is not printed automatically, but is not forgotten. It may be
5761enabled again later.
5762
5763@kindex enable display
5764@item enable display @var{dnums}@dots{}
5765Enable display of item numbers @var{dnums}. It becomes effective once
5766again in auto display of its expression, until you specify otherwise.
5767
5768@item display
5769Display the current values of the expressions on the list, just as is
5770done when your program stops.
5771
5772@kindex info display
5773@item info display
5774Print the list of expressions previously set up to display
5775automatically, each one with its item number, but without showing the
5776values. This includes disabled expressions, which are marked as such.
5777It also includes expressions which would not be displayed right now
5778because they refer to automatic variables not currently available.
5779@end table
5780
15387254 5781@cindex display disabled out of scope
c906108c
SS
5782If a display expression refers to local variables, then it does not make
5783sense outside the lexical context for which it was set up. Such an
5784expression is disabled when execution enters a context where one of its
5785variables is not defined. For example, if you give the command
5786@code{display last_char} while inside a function with an argument
5787@code{last_char}, @value{GDBN} displays this argument while your program
5788continues to stop inside that function. When it stops elsewhere---where
5789there is no variable @code{last_char}---the display is disabled
5790automatically. The next time your program stops where @code{last_char}
5791is meaningful, you can enable the display expression once again.
5792
6d2ebf8b 5793@node Print Settings
c906108c
SS
5794@section Print settings
5795
5796@cindex format options
5797@cindex print settings
5798@value{GDBN} provides the following ways to control how arrays, structures,
5799and symbols are printed.
5800
5801@noindent
5802These settings are useful for debugging programs in any language:
5803
5804@table @code
4644b6e3 5805@kindex set print
c906108c
SS
5806@item set print address
5807@itemx set print address on
4644b6e3 5808@cindex print/don't print memory addresses
c906108c
SS
5809@value{GDBN} prints memory addresses showing the location of stack
5810traces, structure values, pointer values, breakpoints, and so forth,
5811even when it also displays the contents of those addresses. The default
5812is @code{on}. For example, this is what a stack frame display looks like with
5813@code{set print address on}:
5814
5815@smallexample
5816@group
5817(@value{GDBP}) f
5818#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5819 at input.c:530
5820530 if (lquote != def_lquote)
5821@end group
5822@end smallexample
5823
5824@item set print address off
5825Do not print addresses when displaying their contents. For example,
5826this is the same stack frame displayed with @code{set print address off}:
5827
5828@smallexample
5829@group
5830(@value{GDBP}) set print addr off
5831(@value{GDBP}) f
5832#0 set_quotes (lq="<<", rq=">>") at input.c:530
5833530 if (lquote != def_lquote)
5834@end group
5835@end smallexample
5836
5837You can use @samp{set print address off} to eliminate all machine
5838dependent displays from the @value{GDBN} interface. For example, with
5839@code{print address off}, you should get the same text for backtraces on
5840all machines---whether or not they involve pointer arguments.
5841
4644b6e3 5842@kindex show print
c906108c
SS
5843@item show print address
5844Show whether or not addresses are to be printed.
5845@end table
5846
5847When @value{GDBN} prints a symbolic address, it normally prints the
5848closest earlier symbol plus an offset. If that symbol does not uniquely
5849identify the address (for example, it is a name whose scope is a single
5850source file), you may need to clarify. One way to do this is with
5851@code{info line}, for example @samp{info line *0x4537}. Alternately,
5852you can set @value{GDBN} to print the source file and line number when
5853it prints a symbolic address:
5854
5855@table @code
c906108c 5856@item set print symbol-filename on
9c16f35a
EZ
5857@cindex source file and line of a symbol
5858@cindex symbol, source file and line
c906108c
SS
5859Tell @value{GDBN} to print the source file name and line number of a
5860symbol in the symbolic form of an address.
5861
5862@item set print symbol-filename off
5863Do not print source file name and line number of a symbol. This is the
5864default.
5865
c906108c
SS
5866@item show print symbol-filename
5867Show whether or not @value{GDBN} will print the source file name and
5868line number of a symbol in the symbolic form of an address.
5869@end table
5870
5871Another situation where it is helpful to show symbol filenames and line
5872numbers is when disassembling code; @value{GDBN} shows you the line
5873number and source file that corresponds to each instruction.
5874
5875Also, you may wish to see the symbolic form only if the address being
5876printed is reasonably close to the closest earlier symbol:
5877
5878@table @code
c906108c 5879@item set print max-symbolic-offset @var{max-offset}
4644b6e3 5880@cindex maximum value for offset of closest symbol
c906108c
SS
5881Tell @value{GDBN} to only display the symbolic form of an address if the
5882offset between the closest earlier symbol and the address is less than
5d161b24 5883@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5884to always print the symbolic form of an address if any symbol precedes it.
5885
c906108c
SS
5886@item show print max-symbolic-offset
5887Ask how large the maximum offset is that @value{GDBN} prints in a
5888symbolic address.
5889@end table
5890
5891@cindex wild pointer, interpreting
5892@cindex pointer, finding referent
5893If you have a pointer and you are not sure where it points, try
5894@samp{set print symbol-filename on}. Then you can determine the name
5895and source file location of the variable where it points, using
5896@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5897For example, here @value{GDBN} shows that a variable @code{ptt} points
5898at another variable @code{t}, defined in @file{hi2.c}:
5899
474c8240 5900@smallexample
c906108c
SS
5901(@value{GDBP}) set print symbol-filename on
5902(@value{GDBP}) p/a ptt
5903$4 = 0xe008 <t in hi2.c>
474c8240 5904@end smallexample
c906108c
SS
5905
5906@quotation
5907@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5908does not show the symbol name and filename of the referent, even with
5909the appropriate @code{set print} options turned on.
5910@end quotation
5911
5912Other settings control how different kinds of objects are printed:
5913
5914@table @code
c906108c
SS
5915@item set print array
5916@itemx set print array on
4644b6e3 5917@cindex pretty print arrays
c906108c
SS
5918Pretty print arrays. This format is more convenient to read,
5919but uses more space. The default is off.
5920
5921@item set print array off
5922Return to compressed format for arrays.
5923
c906108c
SS
5924@item show print array
5925Show whether compressed or pretty format is selected for displaying
5926arrays.
5927
3c9c013a
JB
5928@cindex print array indexes
5929@item set print array-indexes
5930@itemx set print array-indexes on
5931Print the index of each element when displaying arrays. May be more
5932convenient to locate a given element in the array or quickly find the
5933index of a given element in that printed array. The default is off.
5934
5935@item set print array-indexes off
5936Stop printing element indexes when displaying arrays.
5937
5938@item show print array-indexes
5939Show whether the index of each element is printed when displaying
5940arrays.
5941
c906108c 5942@item set print elements @var{number-of-elements}
4644b6e3 5943@cindex number of array elements to print
9c16f35a 5944@cindex limit on number of printed array elements
c906108c
SS
5945Set a limit on how many elements of an array @value{GDBN} will print.
5946If @value{GDBN} is printing a large array, it stops printing after it has
5947printed the number of elements set by the @code{set print elements} command.
5948This limit also applies to the display of strings.
d4f3574e 5949When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5950Setting @var{number-of-elements} to zero means that the printing is unlimited.
5951
c906108c
SS
5952@item show print elements
5953Display the number of elements of a large array that @value{GDBN} will print.
5954If the number is 0, then the printing is unlimited.
5955
9c16f35a
EZ
5956@item set print repeats
5957@cindex repeated array elements
5958Set the threshold for suppressing display of repeated array
5959elelments. When the number of consecutive identical elements of an
5960array exceeds the threshold, @value{GDBN} prints the string
5961@code{"<repeats @var{n} times>"}, where @var{n} is the number of
5962identical repetitions, instead of displaying the identical elements
5963themselves. Setting the threshold to zero will cause all elements to
5964be individually printed. The default threshold is 10.
5965
5966@item show print repeats
5967Display the current threshold for printing repeated identical
5968elements.
5969
c906108c 5970@item set print null-stop
4644b6e3 5971@cindex @sc{null} elements in arrays
c906108c 5972Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5973@sc{null} is encountered. This is useful when large arrays actually
c906108c 5974contain only short strings.
d4f3574e 5975The default is off.
c906108c 5976
9c16f35a
EZ
5977@item show print null-stop
5978Show whether @value{GDBN} stops printing an array on the first
5979@sc{null} character.
5980
c906108c 5981@item set print pretty on
9c16f35a
EZ
5982@cindex print structures in indented form
5983@cindex indentation in structure display
5d161b24 5984Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5985per line, like this:
5986
5987@smallexample
5988@group
5989$1 = @{
5990 next = 0x0,
5991 flags = @{
5992 sweet = 1,
5993 sour = 1
5994 @},
5995 meat = 0x54 "Pork"
5996@}
5997@end group
5998@end smallexample
5999
6000@item set print pretty off
6001Cause @value{GDBN} to print structures in a compact format, like this:
6002
6003@smallexample
6004@group
6005$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
6006meat = 0x54 "Pork"@}
6007@end group
6008@end smallexample
6009
6010@noindent
6011This is the default format.
6012
c906108c
SS
6013@item show print pretty
6014Show which format @value{GDBN} is using to print structures.
6015
c906108c 6016@item set print sevenbit-strings on
4644b6e3
EZ
6017@cindex eight-bit characters in strings
6018@cindex octal escapes in strings
c906108c
SS
6019Print using only seven-bit characters; if this option is set,
6020@value{GDBN} displays any eight-bit characters (in strings or
6021character values) using the notation @code{\}@var{nnn}. This setting is
6022best if you are working in English (@sc{ascii}) and you use the
6023high-order bit of characters as a marker or ``meta'' bit.
6024
6025@item set print sevenbit-strings off
6026Print full eight-bit characters. This allows the use of more
6027international character sets, and is the default.
6028
c906108c
SS
6029@item show print sevenbit-strings
6030Show whether or not @value{GDBN} is printing only seven-bit characters.
6031
c906108c 6032@item set print union on
4644b6e3 6033@cindex unions in structures, printing
9c16f35a
EZ
6034Tell @value{GDBN} to print unions which are contained in structures
6035and other unions. This is the default setting.
c906108c
SS
6036
6037@item set print union off
9c16f35a
EZ
6038Tell @value{GDBN} not to print unions which are contained in
6039structures and other unions. @value{GDBN} will print @code{"@{...@}"}
6040instead.
c906108c 6041
c906108c
SS
6042@item show print union
6043Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 6044structures and other unions.
c906108c
SS
6045
6046For example, given the declarations
6047
6048@smallexample
6049typedef enum @{Tree, Bug@} Species;
6050typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 6051typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
6052 Bug_forms;
6053
6054struct thing @{
6055 Species it;
6056 union @{
6057 Tree_forms tree;
6058 Bug_forms bug;
6059 @} form;
6060@};
6061
6062struct thing foo = @{Tree, @{Acorn@}@};
6063@end smallexample
6064
6065@noindent
6066with @code{set print union on} in effect @samp{p foo} would print
6067
6068@smallexample
6069$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
6070@end smallexample
6071
6072@noindent
6073and with @code{set print union off} in effect it would print
6074
6075@smallexample
6076$1 = @{it = Tree, form = @{...@}@}
6077@end smallexample
9c16f35a
EZ
6078
6079@noindent
6080@code{set print union} affects programs written in C-like languages
6081and in Pascal.
c906108c
SS
6082@end table
6083
c906108c
SS
6084@need 1000
6085@noindent
b37052ae 6086These settings are of interest when debugging C@t{++} programs:
c906108c
SS
6087
6088@table @code
4644b6e3 6089@cindex demangling C@t{++} names
c906108c
SS
6090@item set print demangle
6091@itemx set print demangle on
b37052ae 6092Print C@t{++} names in their source form rather than in the encoded
c906108c 6093(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 6094linkage. The default is on.
c906108c 6095
c906108c 6096@item show print demangle
b37052ae 6097Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 6098
c906108c
SS
6099@item set print asm-demangle
6100@itemx set print asm-demangle on
b37052ae 6101Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
6102in assembler code printouts such as instruction disassemblies.
6103The default is off.
6104
c906108c 6105@item show print asm-demangle
b37052ae 6106Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
6107or demangled form.
6108
b37052ae
EZ
6109@cindex C@t{++} symbol decoding style
6110@cindex symbol decoding style, C@t{++}
a8f24a35 6111@kindex set demangle-style
c906108c
SS
6112@item set demangle-style @var{style}
6113Choose among several encoding schemes used by different compilers to
b37052ae 6114represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
6115
6116@table @code
6117@item auto
6118Allow @value{GDBN} to choose a decoding style by inspecting your program.
6119
6120@item gnu
b37052ae 6121Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 6122This is the default.
c906108c
SS
6123
6124@item hp
b37052ae 6125Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
6126
6127@item lucid
b37052ae 6128Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
6129
6130@item arm
b37052ae 6131Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
6132@strong{Warning:} this setting alone is not sufficient to allow
6133debugging @code{cfront}-generated executables. @value{GDBN} would
6134require further enhancement to permit that.
6135
6136@end table
6137If you omit @var{style}, you will see a list of possible formats.
6138
c906108c 6139@item show demangle-style
b37052ae 6140Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 6141
c906108c
SS
6142@item set print object
6143@itemx set print object on
4644b6e3 6144@cindex derived type of an object, printing
9c16f35a 6145@cindex display derived types
c906108c
SS
6146When displaying a pointer to an object, identify the @emph{actual}
6147(derived) type of the object rather than the @emph{declared} type, using
6148the virtual function table.
6149
6150@item set print object off
6151Display only the declared type of objects, without reference to the
6152virtual function table. This is the default setting.
6153
c906108c
SS
6154@item show print object
6155Show whether actual, or declared, object types are displayed.
6156
c906108c
SS
6157@item set print static-members
6158@itemx set print static-members on
4644b6e3 6159@cindex static members of C@t{++} objects
b37052ae 6160Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
6161
6162@item set print static-members off
b37052ae 6163Do not print static members when displaying a C@t{++} object.
c906108c 6164
c906108c 6165@item show print static-members
9c16f35a
EZ
6166Show whether C@t{++} static members are printed or not.
6167
6168@item set print pascal_static-members
6169@itemx set print pascal_static-members on
6170@cindex static members of Pacal objects
6171@cindex Pacal objects, static members display
6172Print static members when displaying a Pascal object. The default is on.
6173
6174@item set print pascal_static-members off
6175Do not print static members when displaying a Pascal object.
6176
6177@item show print pascal_static-members
6178Show whether Pascal static members are printed or not.
c906108c
SS
6179
6180@c These don't work with HP ANSI C++ yet.
c906108c
SS
6181@item set print vtbl
6182@itemx set print vtbl on
4644b6e3 6183@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
6184@cindex virtual functions (C@t{++}) display
6185@cindex VTBL display
b37052ae 6186Pretty print C@t{++} virtual function tables. The default is off.
c906108c 6187(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 6188ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
6189
6190@item set print vtbl off
b37052ae 6191Do not pretty print C@t{++} virtual function tables.
c906108c 6192
c906108c 6193@item show print vtbl
b37052ae 6194Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 6195@end table
c906108c 6196
6d2ebf8b 6197@node Value History
c906108c
SS
6198@section Value history
6199
6200@cindex value history
9c16f35a 6201@cindex history of values printed by @value{GDBN}
5d161b24
DB
6202Values printed by the @code{print} command are saved in the @value{GDBN}
6203@dfn{value history}. This allows you to refer to them in other expressions.
6204Values are kept until the symbol table is re-read or discarded
6205(for example with the @code{file} or @code{symbol-file} commands).
6206When the symbol table changes, the value history is discarded,
6207since the values may contain pointers back to the types defined in the
c906108c
SS
6208symbol table.
6209
6210@cindex @code{$}
6211@cindex @code{$$}
6212@cindex history number
6213The values printed are given @dfn{history numbers} by which you can
6214refer to them. These are successive integers starting with one.
6215@code{print} shows you the history number assigned to a value by
6216printing @samp{$@var{num} = } before the value; here @var{num} is the
6217history number.
6218
6219To refer to any previous value, use @samp{$} followed by the value's
6220history number. The way @code{print} labels its output is designed to
6221remind you of this. Just @code{$} refers to the most recent value in
6222the history, and @code{$$} refers to the value before that.
6223@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
6224is the value just prior to @code{$$}, @code{$$1} is equivalent to
6225@code{$$}, and @code{$$0} is equivalent to @code{$}.
6226
6227For example, suppose you have just printed a pointer to a structure and
6228want to see the contents of the structure. It suffices to type
6229
474c8240 6230@smallexample
c906108c 6231p *$
474c8240 6232@end smallexample
c906108c
SS
6233
6234If you have a chain of structures where the component @code{next} points
6235to the next one, you can print the contents of the next one with this:
6236
474c8240 6237@smallexample
c906108c 6238p *$.next
474c8240 6239@end smallexample
c906108c
SS
6240
6241@noindent
6242You can print successive links in the chain by repeating this
6243command---which you can do by just typing @key{RET}.
6244
6245Note that the history records values, not expressions. If the value of
6246@code{x} is 4 and you type these commands:
6247
474c8240 6248@smallexample
c906108c
SS
6249print x
6250set x=5
474c8240 6251@end smallexample
c906108c
SS
6252
6253@noindent
6254then the value recorded in the value history by the @code{print} command
6255remains 4 even though the value of @code{x} has changed.
6256
6257@table @code
6258@kindex show values
6259@item show values
6260Print the last ten values in the value history, with their item numbers.
6261This is like @samp{p@ $$9} repeated ten times, except that @code{show
6262values} does not change the history.
6263
6264@item show values @var{n}
6265Print ten history values centered on history item number @var{n}.
6266
6267@item show values +
6268Print ten history values just after the values last printed. If no more
6269values are available, @code{show values +} produces no display.
6270@end table
6271
6272Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
6273same effect as @samp{show values +}.
6274
6d2ebf8b 6275@node Convenience Vars
c906108c
SS
6276@section Convenience variables
6277
6278@cindex convenience variables
9c16f35a 6279@cindex user-defined variables
c906108c
SS
6280@value{GDBN} provides @dfn{convenience variables} that you can use within
6281@value{GDBN} to hold on to a value and refer to it later. These variables
6282exist entirely within @value{GDBN}; they are not part of your program, and
6283setting a convenience variable has no direct effect on further execution
6284of your program. That is why you can use them freely.
6285
6286Convenience variables are prefixed with @samp{$}. Any name preceded by
6287@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 6288the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
6289(Value history references, in contrast, are @emph{numbers} preceded
6290by @samp{$}. @xref{Value History, ,Value history}.)
6291
6292You can save a value in a convenience variable with an assignment
6293expression, just as you would set a variable in your program.
6294For example:
6295
474c8240 6296@smallexample
c906108c 6297set $foo = *object_ptr
474c8240 6298@end smallexample
c906108c
SS
6299
6300@noindent
6301would save in @code{$foo} the value contained in the object pointed to by
6302@code{object_ptr}.
6303
6304Using a convenience variable for the first time creates it, but its
6305value is @code{void} until you assign a new value. You can alter the
6306value with another assignment at any time.
6307
6308Convenience variables have no fixed types. You can assign a convenience
6309variable any type of value, including structures and arrays, even if
6310that variable already has a value of a different type. The convenience
6311variable, when used as an expression, has the type of its current value.
6312
6313@table @code
6314@kindex show convenience
9c16f35a 6315@cindex show all user variables
c906108c
SS
6316@item show convenience
6317Print a list of convenience variables used so far, and their values.
d4f3574e 6318Abbreviated @code{show conv}.
53e5f3cf
AS
6319
6320@kindex init-if-undefined
6321@cindex convenience variables, initializing
6322@item init-if-undefined $@var{variable} = @var{expression}
6323Set a convenience variable if it has not already been set. This is useful
6324for user-defined commands that keep some state. It is similar, in concept,
6325to using local static variables with initializers in C (except that
6326convenience variables are global). It can also be used to allow users to
6327override default values used in a command script.
6328
6329If the variable is already defined then the expression is not evaluated so
6330any side-effects do not occur.
c906108c
SS
6331@end table
6332
6333One of the ways to use a convenience variable is as a counter to be
6334incremented or a pointer to be advanced. For example, to print
6335a field from successive elements of an array of structures:
6336
474c8240 6337@smallexample
c906108c
SS
6338set $i = 0
6339print bar[$i++]->contents
474c8240 6340@end smallexample
c906108c 6341
d4f3574e
SS
6342@noindent
6343Repeat that command by typing @key{RET}.
c906108c
SS
6344
6345Some convenience variables are created automatically by @value{GDBN} and given
6346values likely to be useful.
6347
6348@table @code
41afff9a 6349@vindex $_@r{, convenience variable}
c906108c
SS
6350@item $_
6351The variable @code{$_} is automatically set by the @code{x} command to
6352the last address examined (@pxref{Memory, ,Examining memory}). Other
6353commands which provide a default address for @code{x} to examine also
6354set @code{$_} to that address; these commands include @code{info line}
6355and @code{info breakpoint}. The type of @code{$_} is @code{void *}
6356except when set by the @code{x} command, in which case it is a pointer
6357to the type of @code{$__}.
6358
41afff9a 6359@vindex $__@r{, convenience variable}
c906108c
SS
6360@item $__
6361The variable @code{$__} is automatically set by the @code{x} command
6362to the value found in the last address examined. Its type is chosen
6363to match the format in which the data was printed.
6364
6365@item $_exitcode
41afff9a 6366@vindex $_exitcode@r{, convenience variable}
c906108c
SS
6367The variable @code{$_exitcode} is automatically set to the exit code when
6368the program being debugged terminates.
6369@end table
6370
53a5351d
JM
6371On HP-UX systems, if you refer to a function or variable name that
6372begins with a dollar sign, @value{GDBN} searches for a user or system
6373name first, before it searches for a convenience variable.
c906108c 6374
6d2ebf8b 6375@node Registers
c906108c
SS
6376@section Registers
6377
6378@cindex registers
6379You can refer to machine register contents, in expressions, as variables
6380with names starting with @samp{$}. The names of registers are different
6381for each machine; use @code{info registers} to see the names used on
6382your machine.
6383
6384@table @code
6385@kindex info registers
6386@item info registers
6387Print the names and values of all registers except floating-point
c85508ee 6388and vector registers (in the selected stack frame).
c906108c
SS
6389
6390@kindex info all-registers
6391@cindex floating point registers
6392@item info all-registers
6393Print the names and values of all registers, including floating-point
c85508ee 6394and vector registers (in the selected stack frame).
c906108c
SS
6395
6396@item info registers @var{regname} @dots{}
6397Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
6398As discussed in detail below, register values are normally relative to
6399the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
6400the machine you are using, with or without the initial @samp{$}.
6401@end table
6402
e09f16f9
EZ
6403@cindex stack pointer register
6404@cindex program counter register
6405@cindex process status register
6406@cindex frame pointer register
6407@cindex standard registers
c906108c
SS
6408@value{GDBN} has four ``standard'' register names that are available (in
6409expressions) on most machines---whenever they do not conflict with an
6410architecture's canonical mnemonics for registers. The register names
6411@code{$pc} and @code{$sp} are used for the program counter register and
6412the stack pointer. @code{$fp} is used for a register that contains a
6413pointer to the current stack frame, and @code{$ps} is used for a
6414register that contains the processor status. For example,
6415you could print the program counter in hex with
6416
474c8240 6417@smallexample
c906108c 6418p/x $pc
474c8240 6419@end smallexample
c906108c
SS
6420
6421@noindent
6422or print the instruction to be executed next with
6423
474c8240 6424@smallexample
c906108c 6425x/i $pc
474c8240 6426@end smallexample
c906108c
SS
6427
6428@noindent
6429or add four to the stack pointer@footnote{This is a way of removing
6430one word from the stack, on machines where stacks grow downward in
6431memory (most machines, nowadays). This assumes that the innermost
6432stack frame is selected; setting @code{$sp} is not allowed when other
6433stack frames are selected. To pop entire frames off the stack,
6434regardless of machine architecture, use @code{return};
d4f3574e 6435see @ref{Returning, ,Returning from a function}.} with
c906108c 6436
474c8240 6437@smallexample
c906108c 6438set $sp += 4
474c8240 6439@end smallexample
c906108c
SS
6440
6441Whenever possible, these four standard register names are available on
6442your machine even though the machine has different canonical mnemonics,
6443so long as there is no conflict. The @code{info registers} command
6444shows the canonical names. For example, on the SPARC, @code{info
6445registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
6446can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6447is an alias for the @sc{eflags} register.
c906108c
SS
6448
6449@value{GDBN} always considers the contents of an ordinary register as an
6450integer when the register is examined in this way. Some machines have
6451special registers which can hold nothing but floating point; these
6452registers are considered to have floating point values. There is no way
6453to refer to the contents of an ordinary register as floating point value
6454(although you can @emph{print} it as a floating point value with
6455@samp{print/f $@var{regname}}).
6456
6457Some registers have distinct ``raw'' and ``virtual'' data formats. This
6458means that the data format in which the register contents are saved by
6459the operating system is not the same one that your program normally
6460sees. For example, the registers of the 68881 floating point
6461coprocessor are always saved in ``extended'' (raw) format, but all C
6462programs expect to work with ``double'' (virtual) format. In such
5d161b24 6463cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
6464that makes sense for your program), but the @code{info registers} command
6465prints the data in both formats.
6466
36b80e65
EZ
6467@cindex SSE registers (x86)
6468@cindex MMX registers (x86)
6469Some machines have special registers whose contents can be interpreted
6470in several different ways. For example, modern x86-based machines
6471have SSE and MMX registers that can hold several values packed
6472together in several different formats. @value{GDBN} refers to such
6473registers in @code{struct} notation:
6474
6475@smallexample
6476(@value{GDBP}) print $xmm1
6477$1 = @{
6478 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
6479 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
6480 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
6481 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
6482 v4_int32 = @{0, 20657912, 11, 13@},
6483 v2_int64 = @{88725056443645952, 55834574859@},
6484 uint128 = 0x0000000d0000000b013b36f800000000
6485@}
6486@end smallexample
6487
6488@noindent
6489To set values of such registers, you need to tell @value{GDBN} which
6490view of the register you wish to change, as if you were assigning
6491value to a @code{struct} member:
6492
6493@smallexample
6494 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
6495@end smallexample
6496
c906108c
SS
6497Normally, register values are relative to the selected stack frame
6498(@pxref{Selection, ,Selecting a frame}). This means that you get the
6499value that the register would contain if all stack frames farther in
6500were exited and their saved registers restored. In order to see the
6501true contents of hardware registers, you must select the innermost
6502frame (with @samp{frame 0}).
6503
6504However, @value{GDBN} must deduce where registers are saved, from the machine
6505code generated by your compiler. If some registers are not saved, or if
6506@value{GDBN} is unable to locate the saved registers, the selected stack
6507frame makes no difference.
6508
6d2ebf8b 6509@node Floating Point Hardware
c906108c
SS
6510@section Floating point hardware
6511@cindex floating point
6512
6513Depending on the configuration, @value{GDBN} may be able to give
6514you more information about the status of the floating point hardware.
6515
6516@table @code
6517@kindex info float
6518@item info float
6519Display hardware-dependent information about the floating
6520point unit. The exact contents and layout vary depending on the
6521floating point chip. Currently, @samp{info float} is supported on
6522the ARM and x86 machines.
6523@end table
c906108c 6524
e76f1f2e
AC
6525@node Vector Unit
6526@section Vector Unit
6527@cindex vector unit
6528
6529Depending on the configuration, @value{GDBN} may be able to give you
6530more information about the status of the vector unit.
6531
6532@table @code
6533@kindex info vector
6534@item info vector
6535Display information about the vector unit. The exact contents and
6536layout vary depending on the hardware.
6537@end table
6538
721c2651
EZ
6539@node OS Information
6540@section Operating system auxiliary information
6541@cindex OS information
6542
6543@value{GDBN} provides interfaces to useful OS facilities that can help
6544you debug your program.
6545
6546@cindex @code{ptrace} system call
6547@cindex @code{struct user} contents
6548When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6549machines), it interfaces with the inferior via the @code{ptrace}
6550system call. The operating system creates a special sata structure,
6551called @code{struct user}, for this interface. You can use the
6552command @code{info udot} to display the contents of this data
6553structure.
6554
6555@table @code
6556@item info udot
6557@kindex info udot
6558Display the contents of the @code{struct user} maintained by the OS
6559kernel for the program being debugged. @value{GDBN} displays the
6560contents of @code{struct user} as a list of hex numbers, similar to
6561the @code{examine} command.
6562@end table
6563
b383017d
RM
6564@cindex auxiliary vector
6565@cindex vector, auxiliary
b383017d
RM
6566Some operating systems supply an @dfn{auxiliary vector} to programs at
6567startup. This is akin to the arguments and environment that you
6568specify for a program, but contains a system-dependent variety of
6569binary values that tell system libraries important details about the
6570hardware, operating system, and process. Each value's purpose is
6571identified by an integer tag; the meanings are well-known but system-specific.
6572Depending on the configuration and operating system facilities,
9c16f35a
EZ
6573@value{GDBN} may be able to show you this information. For remote
6574targets, this functionality may further depend on the remote stub's
6575support of the @samp{qPart:auxv:read} packet, see @ref{Remote
6576configuration, auxiliary vector}.
b383017d
RM
6577
6578@table @code
6579@kindex info auxv
6580@item info auxv
6581Display the auxiliary vector of the inferior, which can be either a
e4937fc1 6582live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
6583numerically, and also shows names and text descriptions for recognized
6584tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 6585pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
6586most appropriate form for a recognized tag, and in hexadecimal for
6587an unrecognized tag.
6588@end table
6589
721c2651 6590
29e57380 6591@node Memory Region Attributes
b383017d 6592@section Memory region attributes
29e57380
C
6593@cindex memory region attributes
6594
b383017d
RM
6595@dfn{Memory region attributes} allow you to describe special handling
6596required by regions of your target's memory. @value{GDBN} uses attributes
29e57380
C
6597to determine whether to allow certain types of memory accesses; whether to
6598use specific width accesses; and whether to cache target memory.
6599
6600Defined memory regions can be individually enabled and disabled. When a
6601memory region is disabled, @value{GDBN} uses the default attributes when
6602accessing memory in that region. Similarly, if no memory regions have
6603been defined, @value{GDBN} uses the default attributes when accessing
6604all memory.
6605
b383017d 6606When a memory region is defined, it is given a number to identify it;
29e57380
C
6607to enable, disable, or remove a memory region, you specify that number.
6608
6609@table @code
6610@kindex mem
bfac230e 6611@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
6612Define a memory region bounded by @var{lower} and @var{upper} with
6613attributes @var{attributes}@dots{}, and add it to the list of regions
6614monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
6615case: it is treated as the the target's maximum memory address.
bfac230e 6616(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
6617
6618@kindex delete mem
6619@item delete mem @var{nums}@dots{}
09d4efe1
EZ
6620Remove memory regions @var{nums}@dots{} from the list of regions
6621monitored by @value{GDBN}.
29e57380
C
6622
6623@kindex disable mem
6624@item disable mem @var{nums}@dots{}
09d4efe1 6625Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 6626A disabled memory region is not forgotten.
29e57380
C
6627It may be enabled again later.
6628
6629@kindex enable mem
6630@item enable mem @var{nums}@dots{}
09d4efe1 6631Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
6632
6633@kindex info mem
6634@item info mem
6635Print a table of all defined memory regions, with the following columns
09d4efe1 6636for each region:
29e57380
C
6637
6638@table @emph
6639@item Memory Region Number
6640@item Enabled or Disabled.
b383017d 6641Enabled memory regions are marked with @samp{y}.
29e57380
C
6642Disabled memory regions are marked with @samp{n}.
6643
6644@item Lo Address
6645The address defining the inclusive lower bound of the memory region.
6646
6647@item Hi Address
6648The address defining the exclusive upper bound of the memory region.
6649
6650@item Attributes
6651The list of attributes set for this memory region.
6652@end table
6653@end table
6654
6655
6656@subsection Attributes
6657
b383017d 6658@subsubsection Memory Access Mode
29e57380
C
6659The access mode attributes set whether @value{GDBN} may make read or
6660write accesses to a memory region.
6661
6662While these attributes prevent @value{GDBN} from performing invalid
6663memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 6664etc.@: from accessing memory.
29e57380
C
6665
6666@table @code
6667@item ro
6668Memory is read only.
6669@item wo
6670Memory is write only.
6671@item rw
6ca652b0 6672Memory is read/write. This is the default.
29e57380
C
6673@end table
6674
6675@subsubsection Memory Access Size
6676The acccess size attributes tells @value{GDBN} to use specific sized
6677accesses in the memory region. Often memory mapped device registers
6678require specific sized accesses. If no access size attribute is
6679specified, @value{GDBN} may use accesses of any size.
6680
6681@table @code
6682@item 8
6683Use 8 bit memory accesses.
6684@item 16
6685Use 16 bit memory accesses.
6686@item 32
6687Use 32 bit memory accesses.
6688@item 64
6689Use 64 bit memory accesses.
6690@end table
6691
6692@c @subsubsection Hardware/Software Breakpoints
6693@c The hardware/software breakpoint attributes set whether @value{GDBN}
6694@c will use hardware or software breakpoints for the internal breakpoints
6695@c used by the step, next, finish, until, etc. commands.
6696@c
6697@c @table @code
6698@c @item hwbreak
b383017d 6699@c Always use hardware breakpoints
29e57380
C
6700@c @item swbreak (default)
6701@c @end table
6702
6703@subsubsection Data Cache
6704The data cache attributes set whether @value{GDBN} will cache target
6705memory. While this generally improves performance by reducing debug
6706protocol overhead, it can lead to incorrect results because @value{GDBN}
6707does not know about volatile variables or memory mapped device
6708registers.
6709
6710@table @code
6711@item cache
b383017d 6712Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6713@item nocache
6714Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6715@end table
6716
6717@c @subsubsection Memory Write Verification
b383017d 6718@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6719@c will re-reads data after each write to verify the write was successful.
6720@c
6721@c @table @code
6722@c @item verify
6723@c @item noverify (default)
6724@c @end table
6725
16d9dec6
MS
6726@node Dump/Restore Files
6727@section Copy between memory and a file
6728@cindex dump/restore files
6729@cindex append data to a file
6730@cindex dump data to a file
6731@cindex restore data from a file
16d9dec6 6732
df5215a6
JB
6733You can use the commands @code{dump}, @code{append}, and
6734@code{restore} to copy data between target memory and a file. The
6735@code{dump} and @code{append} commands write data to a file, and the
6736@code{restore} command reads data from a file back into the inferior's
6737memory. Files may be in binary, Motorola S-record, Intel hex, or
6738Tektronix Hex format; however, @value{GDBN} can only append to binary
6739files.
6740
6741@table @code
6742
6743@kindex dump
6744@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6745@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6746Dump the contents of memory from @var{start_addr} to @var{end_addr},
6747or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6748
df5215a6 6749The @var{format} parameter may be any one of:
16d9dec6 6750@table @code
df5215a6
JB
6751@item binary
6752Raw binary form.
6753@item ihex
6754Intel hex format.
6755@item srec
6756Motorola S-record format.
6757@item tekhex
6758Tektronix Hex format.
6759@end table
6760
6761@value{GDBN} uses the same definitions of these formats as the
6762@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6763@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6764form.
6765
6766@kindex append
6767@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6768@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6769Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 6770or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
6771(@value{GDBN} can only append data to files in raw binary form.)
6772
6773@kindex restore
6774@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6775Restore the contents of file @var{filename} into memory. The
6776@code{restore} command can automatically recognize any known @sc{bfd}
6777file format, except for raw binary. To restore a raw binary file you
6778must specify the optional keyword @code{binary} after the filename.
16d9dec6 6779
b383017d 6780If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6781contained in the file. Binary files always start at address zero, so
6782they will be restored at address @var{bias}. Other bfd files have
6783a built-in location; they will be restored at offset @var{bias}
6784from that location.
6785
6786If @var{start} and/or @var{end} are non-zero, then only data between
6787file offset @var{start} and file offset @var{end} will be restored.
b383017d 6788These offsets are relative to the addresses in the file, before
16d9dec6
MS
6789the @var{bias} argument is applied.
6790
6791@end table
6792
384ee23f
EZ
6793@node Core File Generation
6794@section How to Produce a Core File from Your Program
6795@cindex dump core from inferior
6796
6797A @dfn{core file} or @dfn{core dump} is a file that records the memory
6798image of a running process and its process status (register values
6799etc.). Its primary use is post-mortem debugging of a program that
6800crashed while it ran outside a debugger. A program that crashes
6801automatically produces a core file, unless this feature is disabled by
6802the user. @xref{Files}, for information on invoking @value{GDBN} in
6803the post-mortem debugging mode.
6804
6805Occasionally, you may wish to produce a core file of the program you
6806are debugging in order to preserve a snapshot of its state.
6807@value{GDBN} has a special command for that.
6808
6809@table @code
6810@kindex gcore
6811@kindex generate-core-file
6812@item generate-core-file [@var{file}]
6813@itemx gcore [@var{file}]
6814Produce a core dump of the inferior process. The optional argument
6815@var{file} specifies the file name where to put the core dump. If not
6816specified, the file name defaults to @file{core.@var{pid}}, where
6817@var{pid} is the inferior process ID.
6818
6819Note that this command is implemented only for some systems (as of
6820this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6821@end table
6822
a0eb71c5
KB
6823@node Character Sets
6824@section Character Sets
6825@cindex character sets
6826@cindex charset
6827@cindex translating between character sets
6828@cindex host character set
6829@cindex target character set
6830
6831If the program you are debugging uses a different character set to
6832represent characters and strings than the one @value{GDBN} uses itself,
6833@value{GDBN} can automatically translate between the character sets for
6834you. The character set @value{GDBN} uses we call the @dfn{host
6835character set}; the one the inferior program uses we call the
6836@dfn{target character set}.
6837
6838For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6839uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6840remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6841running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6842then the host character set is Latin-1, and the target character set is
6843@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6844target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6845@sc{ebcdic} and Latin 1 as you print character or string values, or use
6846character and string literals in expressions.
6847
6848@value{GDBN} has no way to automatically recognize which character set
6849the inferior program uses; you must tell it, using the @code{set
6850target-charset} command, described below.
6851
6852Here are the commands for controlling @value{GDBN}'s character set
6853support:
6854
6855@table @code
6856@item set target-charset @var{charset}
6857@kindex set target-charset
6858Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6859character set names @value{GDBN} recognizes below, but if you type
6860@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6861list the target character sets it supports.
a0eb71c5
KB
6862@end table
6863
6864@table @code
6865@item set host-charset @var{charset}
6866@kindex set host-charset
6867Set the current host character set to @var{charset}.
6868
6869By default, @value{GDBN} uses a host character set appropriate to the
6870system it is running on; you can override that default using the
6871@code{set host-charset} command.
6872
6873@value{GDBN} can only use certain character sets as its host character
6874set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6875indicate which can be host character sets, but if you type
6876@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6877list the host character sets it supports.
a0eb71c5
KB
6878
6879@item set charset @var{charset}
6880@kindex set charset
e33d66ec
EZ
6881Set the current host and target character sets to @var{charset}. As
6882above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6883@value{GDBN} will list the name of the character sets that can be used
6884for both host and target.
6885
a0eb71c5
KB
6886
6887@item show charset
a0eb71c5 6888@kindex show charset
b383017d 6889Show the names of the current host and target charsets.
e33d66ec
EZ
6890
6891@itemx show host-charset
a0eb71c5 6892@kindex show host-charset
b383017d 6893Show the name of the current host charset.
e33d66ec
EZ
6894
6895@itemx show target-charset
a0eb71c5 6896@kindex show target-charset
b383017d 6897Show the name of the current target charset.
a0eb71c5
KB
6898
6899@end table
6900
6901@value{GDBN} currently includes support for the following character
6902sets:
6903
6904@table @code
6905
6906@item ASCII
6907@cindex ASCII character set
6908Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6909character set.
6910
6911@item ISO-8859-1
6912@cindex ISO 8859-1 character set
6913@cindex ISO Latin 1 character set
e33d66ec 6914The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6915characters needed for French, German, and Spanish. @value{GDBN} can use
6916this as its host character set.
6917
6918@item EBCDIC-US
6919@itemx IBM1047
6920@cindex EBCDIC character set
6921@cindex IBM1047 character set
6922Variants of the @sc{ebcdic} character set, used on some of IBM's
6923mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6924@value{GDBN} cannot use these as its host character set.
6925
6926@end table
6927
6928Note that these are all single-byte character sets. More work inside
6929GDB is needed to support multi-byte or variable-width character
6930encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6931
6932Here is an example of @value{GDBN}'s character set support in action.
6933Assume that the following source code has been placed in the file
6934@file{charset-test.c}:
6935
6936@smallexample
6937#include <stdio.h>
6938
6939char ascii_hello[]
6940 = @{72, 101, 108, 108, 111, 44, 32, 119,
6941 111, 114, 108, 100, 33, 10, 0@};
6942char ibm1047_hello[]
6943 = @{200, 133, 147, 147, 150, 107, 64, 166,
6944 150, 153, 147, 132, 90, 37, 0@};
6945
6946main ()
6947@{
6948 printf ("Hello, world!\n");
6949@}
10998722 6950@end smallexample
a0eb71c5
KB
6951
6952In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6953containing the string @samp{Hello, world!} followed by a newline,
6954encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6955
6956We compile the program, and invoke the debugger on it:
6957
6958@smallexample
6959$ gcc -g charset-test.c -o charset-test
6960$ gdb -nw charset-test
6961GNU gdb 2001-12-19-cvs
6962Copyright 2001 Free Software Foundation, Inc.
6963@dots{}
f7dc1244 6964(@value{GDBP})
10998722 6965@end smallexample
a0eb71c5
KB
6966
6967We can use the @code{show charset} command to see what character sets
6968@value{GDBN} is currently using to interpret and display characters and
6969strings:
6970
6971@smallexample
f7dc1244 6972(@value{GDBP}) show charset
e33d66ec 6973The current host and target character set is `ISO-8859-1'.
f7dc1244 6974(@value{GDBP})
10998722 6975@end smallexample
a0eb71c5
KB
6976
6977For the sake of printing this manual, let's use @sc{ascii} as our
6978initial character set:
6979@smallexample
f7dc1244
EZ
6980(@value{GDBP}) set charset ASCII
6981(@value{GDBP}) show charset
e33d66ec 6982The current host and target character set is `ASCII'.
f7dc1244 6983(@value{GDBP})
10998722 6984@end smallexample
a0eb71c5
KB
6985
6986Let's assume that @sc{ascii} is indeed the correct character set for our
6987host system --- in other words, let's assume that if @value{GDBN} prints
6988characters using the @sc{ascii} character set, our terminal will display
6989them properly. Since our current target character set is also
6990@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6991
6992@smallexample
f7dc1244 6993(@value{GDBP}) print ascii_hello
a0eb71c5 6994$1 = 0x401698 "Hello, world!\n"
f7dc1244 6995(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6996$2 = 72 'H'
f7dc1244 6997(@value{GDBP})
10998722 6998@end smallexample
a0eb71c5
KB
6999
7000@value{GDBN} uses the target character set for character and string
7001literals you use in expressions:
7002
7003@smallexample
f7dc1244 7004(@value{GDBP}) print '+'
a0eb71c5 7005$3 = 43 '+'
f7dc1244 7006(@value{GDBP})
10998722 7007@end smallexample
a0eb71c5
KB
7008
7009The @sc{ascii} character set uses the number 43 to encode the @samp{+}
7010character.
7011
7012@value{GDBN} relies on the user to tell it which character set the
7013target program uses. If we print @code{ibm1047_hello} while our target
7014character set is still @sc{ascii}, we get jibberish:
7015
7016@smallexample
f7dc1244 7017(@value{GDBP}) print ibm1047_hello
a0eb71c5 7018$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 7019(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 7020$5 = 200 '\310'
f7dc1244 7021(@value{GDBP})
10998722 7022@end smallexample
a0eb71c5 7023
e33d66ec 7024If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
7025@value{GDBN} tells us the character sets it supports:
7026
7027@smallexample
f7dc1244 7028(@value{GDBP}) set target-charset
b383017d 7029ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 7030(@value{GDBP}) set target-charset
10998722 7031@end smallexample
a0eb71c5
KB
7032
7033We can select @sc{ibm1047} as our target character set, and examine the
7034program's strings again. Now the @sc{ascii} string is wrong, but
7035@value{GDBN} translates the contents of @code{ibm1047_hello} from the
7036target character set, @sc{ibm1047}, to the host character set,
7037@sc{ascii}, and they display correctly:
7038
7039@smallexample
f7dc1244
EZ
7040(@value{GDBP}) set target-charset IBM1047
7041(@value{GDBP}) show charset
e33d66ec
EZ
7042The current host character set is `ASCII'.
7043The current target character set is `IBM1047'.
f7dc1244 7044(@value{GDBP}) print ascii_hello
a0eb71c5 7045$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 7046(@value{GDBP}) print ascii_hello[0]
a0eb71c5 7047$7 = 72 '\110'
f7dc1244 7048(@value{GDBP}) print ibm1047_hello
a0eb71c5 7049$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 7050(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 7051$9 = 200 'H'
f7dc1244 7052(@value{GDBP})
10998722 7053@end smallexample
a0eb71c5
KB
7054
7055As above, @value{GDBN} uses the target character set for character and
7056string literals you use in expressions:
7057
7058@smallexample
f7dc1244 7059(@value{GDBP}) print '+'
a0eb71c5 7060$10 = 78 '+'
f7dc1244 7061(@value{GDBP})
10998722 7062@end smallexample
a0eb71c5 7063
e33d66ec 7064The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
7065character.
7066
09d4efe1
EZ
7067@node Caching Remote Data
7068@section Caching Data of Remote Targets
7069@cindex caching data of remote targets
7070
7071@value{GDBN} can cache data exchanged between the debugger and a
7072remote target (@pxref{Remote}). Such caching generally improves
7073performance, because it reduces the overhead of the remote protocol by
7074bundling memory reads and writes into large chunks. Unfortunately,
7075@value{GDBN} does not currently know anything about volatile
7076registers, and thus data caching will produce incorrect results when
7077volatile registers are in use.
7078
7079@table @code
7080@kindex set remotecache
7081@item set remotecache on
7082@itemx set remotecache off
7083Set caching state for remote targets. When @code{ON}, use data
7084caching. By default, this option is @code{OFF}.
7085
7086@kindex show remotecache
7087@item show remotecache
7088Show the current state of data caching for remote targets.
7089
7090@kindex info dcache
7091@item info dcache
7092Print the information about the data cache performance. The
7093information displayed includes: the dcache width and depth; and for
7094each cache line, how many times it was referenced, and its data and
7095state (dirty, bad, ok, etc.). This command is useful for debugging
7096the data cache operation.
7097@end table
7098
a0eb71c5 7099
e2e0bcd1
JB
7100@node Macros
7101@chapter C Preprocessor Macros
7102
49efadf5 7103Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
7104``preprocessor macros'' which expand into strings of tokens.
7105@value{GDBN} can evaluate expressions containing macro invocations, show
7106the result of macro expansion, and show a macro's definition, including
7107where it was defined.
7108
7109You may need to compile your program specially to provide @value{GDBN}
7110with information about preprocessor macros. Most compilers do not
7111include macros in their debugging information, even when you compile
7112with the @option{-g} flag. @xref{Compilation}.
7113
7114A program may define a macro at one point, remove that definition later,
7115and then provide a different definition after that. Thus, at different
7116points in the program, a macro may have different definitions, or have
7117no definition at all. If there is a current stack frame, @value{GDBN}
7118uses the macros in scope at that frame's source code line. Otherwise,
7119@value{GDBN} uses the macros in scope at the current listing location;
7120see @ref{List}.
7121
7122At the moment, @value{GDBN} does not support the @code{##}
7123token-splicing operator, the @code{#} stringification operator, or
7124variable-arity macros.
7125
7126Whenever @value{GDBN} evaluates an expression, it always expands any
7127macro invocations present in the expression. @value{GDBN} also provides
7128the following commands for working with macros explicitly.
7129
7130@table @code
7131
7132@kindex macro expand
7133@cindex macro expansion, showing the results of preprocessor
7134@cindex preprocessor macro expansion, showing the results of
7135@cindex expanding preprocessor macros
7136@item macro expand @var{expression}
7137@itemx macro exp @var{expression}
7138Show the results of expanding all preprocessor macro invocations in
7139@var{expression}. Since @value{GDBN} simply expands macros, but does
7140not parse the result, @var{expression} need not be a valid expression;
7141it can be any string of tokens.
7142
09d4efe1 7143@kindex macro exp1
e2e0bcd1
JB
7144@item macro expand-once @var{expression}
7145@itemx macro exp1 @var{expression}
4644b6e3 7146@cindex expand macro once
e2e0bcd1
JB
7147@i{(This command is not yet implemented.)} Show the results of
7148expanding those preprocessor macro invocations that appear explicitly in
7149@var{expression}. Macro invocations appearing in that expansion are
7150left unchanged. This command allows you to see the effect of a
7151particular macro more clearly, without being confused by further
7152expansions. Since @value{GDBN} simply expands macros, but does not
7153parse the result, @var{expression} need not be a valid expression; it
7154can be any string of tokens.
7155
475b0867 7156@kindex info macro
e2e0bcd1
JB
7157@cindex macro definition, showing
7158@cindex definition, showing a macro's
475b0867 7159@item info macro @var{macro}
e2e0bcd1
JB
7160Show the definition of the macro named @var{macro}, and describe the
7161source location where that definition was established.
7162
7163@kindex macro define
7164@cindex user-defined macros
7165@cindex defining macros interactively
7166@cindex macros, user-defined
7167@item macro define @var{macro} @var{replacement-list}
7168@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
7169@i{(This command is not yet implemented.)} Introduce a definition for a
7170preprocessor macro named @var{macro}, invocations of which are replaced
7171by the tokens given in @var{replacement-list}. The first form of this
7172command defines an ``object-like'' macro, which takes no arguments; the
7173second form defines a ``function-like'' macro, which takes the arguments
7174given in @var{arglist}.
7175
7176A definition introduced by this command is in scope in every expression
7177evaluated in @value{GDBN}, until it is removed with the @command{macro
7178undef} command, described below. The definition overrides all
7179definitions for @var{macro} present in the program being debugged, as
7180well as any previous user-supplied definition.
7181
7182@kindex macro undef
7183@item macro undef @var{macro}
7184@i{(This command is not yet implemented.)} Remove any user-supplied
7185definition for the macro named @var{macro}. This command only affects
7186definitions provided with the @command{macro define} command, described
7187above; it cannot remove definitions present in the program being
7188debugged.
7189
09d4efe1
EZ
7190@kindex macro list
7191@item macro list
7192@i{(This command is not yet implemented.)} List all the macros
7193defined using the @code{macro define} command.
e2e0bcd1
JB
7194@end table
7195
7196@cindex macros, example of debugging with
7197Here is a transcript showing the above commands in action. First, we
7198show our source files:
7199
7200@smallexample
7201$ cat sample.c
7202#include <stdio.h>
7203#include "sample.h"
7204
7205#define M 42
7206#define ADD(x) (M + x)
7207
7208main ()
7209@{
7210#define N 28
7211 printf ("Hello, world!\n");
7212#undef N
7213 printf ("We're so creative.\n");
7214#define N 1729
7215 printf ("Goodbye, world!\n");
7216@}
7217$ cat sample.h
7218#define Q <
7219$
7220@end smallexample
7221
7222Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
7223We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
7224compiler includes information about preprocessor macros in the debugging
7225information.
7226
7227@smallexample
7228$ gcc -gdwarf-2 -g3 sample.c -o sample
7229$
7230@end smallexample
7231
7232Now, we start @value{GDBN} on our sample program:
7233
7234@smallexample
7235$ gdb -nw sample
7236GNU gdb 2002-05-06-cvs
7237Copyright 2002 Free Software Foundation, Inc.
7238GDB is free software, @dots{}
f7dc1244 7239(@value{GDBP})
e2e0bcd1
JB
7240@end smallexample
7241
7242We can expand macros and examine their definitions, even when the
7243program is not running. @value{GDBN} uses the current listing position
7244to decide which macro definitions are in scope:
7245
7246@smallexample
f7dc1244 7247(@value{GDBP}) list main
e2e0bcd1
JB
72483
72494 #define M 42
72505 #define ADD(x) (M + x)
72516
72527 main ()
72538 @{
72549 #define N 28
725510 printf ("Hello, world!\n");
725611 #undef N
725712 printf ("We're so creative.\n");
f7dc1244 7258(@value{GDBP}) info macro ADD
e2e0bcd1
JB
7259Defined at /home/jimb/gdb/macros/play/sample.c:5
7260#define ADD(x) (M + x)
f7dc1244 7261(@value{GDBP}) info macro Q
e2e0bcd1
JB
7262Defined at /home/jimb/gdb/macros/play/sample.h:1
7263 included at /home/jimb/gdb/macros/play/sample.c:2
7264#define Q <
f7dc1244 7265(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 7266expands to: (42 + 1)
f7dc1244 7267(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 7268expands to: once (M + 1)
f7dc1244 7269(@value{GDBP})
e2e0bcd1
JB
7270@end smallexample
7271
7272In the example above, note that @command{macro expand-once} expands only
7273the macro invocation explicit in the original text --- the invocation of
7274@code{ADD} --- but does not expand the invocation of the macro @code{M},
7275which was introduced by @code{ADD}.
7276
7277Once the program is running, GDB uses the macro definitions in force at
7278the source line of the current stack frame:
7279
7280@smallexample
f7dc1244 7281(@value{GDBP}) break main
e2e0bcd1 7282Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 7283(@value{GDBP}) run
b383017d 7284Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
7285
7286Breakpoint 1, main () at sample.c:10
728710 printf ("Hello, world!\n");
f7dc1244 7288(@value{GDBP})
e2e0bcd1
JB
7289@end smallexample
7290
7291At line 10, the definition of the macro @code{N} at line 9 is in force:
7292
7293@smallexample
f7dc1244 7294(@value{GDBP}) info macro N
e2e0bcd1
JB
7295Defined at /home/jimb/gdb/macros/play/sample.c:9
7296#define N 28
f7dc1244 7297(@value{GDBP}) macro expand N Q M
e2e0bcd1 7298expands to: 28 < 42
f7dc1244 7299(@value{GDBP}) print N Q M
e2e0bcd1 7300$1 = 1
f7dc1244 7301(@value{GDBP})
e2e0bcd1
JB
7302@end smallexample
7303
7304As we step over directives that remove @code{N}'s definition, and then
7305give it a new definition, @value{GDBN} finds the definition (or lack
7306thereof) in force at each point:
7307
7308@smallexample
f7dc1244 7309(@value{GDBP}) next
e2e0bcd1
JB
7310Hello, world!
731112 printf ("We're so creative.\n");
f7dc1244 7312(@value{GDBP}) info macro N
e2e0bcd1
JB
7313The symbol `N' has no definition as a C/C++ preprocessor macro
7314at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 7315(@value{GDBP}) next
e2e0bcd1
JB
7316We're so creative.
731714 printf ("Goodbye, world!\n");
f7dc1244 7318(@value{GDBP}) info macro N
e2e0bcd1
JB
7319Defined at /home/jimb/gdb/macros/play/sample.c:13
7320#define N 1729
f7dc1244 7321(@value{GDBP}) macro expand N Q M
e2e0bcd1 7322expands to: 1729 < 42
f7dc1244 7323(@value{GDBP}) print N Q M
e2e0bcd1 7324$2 = 0
f7dc1244 7325(@value{GDBP})
e2e0bcd1
JB
7326@end smallexample
7327
7328
b37052ae
EZ
7329@node Tracepoints
7330@chapter Tracepoints
7331@c This chapter is based on the documentation written by Michael
7332@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
7333
7334@cindex tracepoints
7335In some applications, it is not feasible for the debugger to interrupt
7336the program's execution long enough for the developer to learn
7337anything helpful about its behavior. If the program's correctness
7338depends on its real-time behavior, delays introduced by a debugger
7339might cause the program to change its behavior drastically, or perhaps
7340fail, even when the code itself is correct. It is useful to be able
7341to observe the program's behavior without interrupting it.
7342
7343Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
7344specify locations in the program, called @dfn{tracepoints}, and
7345arbitrary expressions to evaluate when those tracepoints are reached.
7346Later, using the @code{tfind} command, you can examine the values
7347those expressions had when the program hit the tracepoints. The
7348expressions may also denote objects in memory---structures or arrays,
7349for example---whose values @value{GDBN} should record; while visiting
7350a particular tracepoint, you may inspect those objects as if they were
7351in memory at that moment. However, because @value{GDBN} records these
7352values without interacting with you, it can do so quickly and
7353unobtrusively, hopefully not disturbing the program's behavior.
7354
7355The tracepoint facility is currently available only for remote
9d29849a
JB
7356targets. @xref{Targets}. In addition, your remote target must know
7357how to collect trace data. This functionality is implemented in the
7358remote stub; however, none of the stubs distributed with @value{GDBN}
7359support tracepoints as of this writing. The format of the remote
7360packets used to implement tracepoints are described in @ref{Tracepoint
7361Packets}.
b37052ae
EZ
7362
7363This chapter describes the tracepoint commands and features.
7364
7365@menu
b383017d
RM
7366* Set Tracepoints::
7367* Analyze Collected Data::
7368* Tracepoint Variables::
b37052ae
EZ
7369@end menu
7370
7371@node Set Tracepoints
7372@section Commands to Set Tracepoints
7373
7374Before running such a @dfn{trace experiment}, an arbitrary number of
7375tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
7376tracepoint has a number assigned to it by @value{GDBN}. Like with
7377breakpoints, tracepoint numbers are successive integers starting from
7378one. Many of the commands associated with tracepoints take the
7379tracepoint number as their argument, to identify which tracepoint to
7380work on.
7381
7382For each tracepoint, you can specify, in advance, some arbitrary set
7383of data that you want the target to collect in the trace buffer when
7384it hits that tracepoint. The collected data can include registers,
7385local variables, or global data. Later, you can use @value{GDBN}
7386commands to examine the values these data had at the time the
7387tracepoint was hit.
7388
7389This section describes commands to set tracepoints and associated
7390conditions and actions.
7391
7392@menu
b383017d
RM
7393* Create and Delete Tracepoints::
7394* Enable and Disable Tracepoints::
7395* Tracepoint Passcounts::
7396* Tracepoint Actions::
7397* Listing Tracepoints::
7398* Starting and Stopping Trace Experiment::
b37052ae
EZ
7399@end menu
7400
7401@node Create and Delete Tracepoints
7402@subsection Create and Delete Tracepoints
7403
7404@table @code
7405@cindex set tracepoint
7406@kindex trace
7407@item trace
7408The @code{trace} command is very similar to the @code{break} command.
7409Its argument can be a source line, a function name, or an address in
7410the target program. @xref{Set Breaks}. The @code{trace} command
7411defines a tracepoint, which is a point in the target program where the
7412debugger will briefly stop, collect some data, and then allow the
7413program to continue. Setting a tracepoint or changing its commands
7414doesn't take effect until the next @code{tstart} command; thus, you
7415cannot change the tracepoint attributes once a trace experiment is
7416running.
7417
7418Here are some examples of using the @code{trace} command:
7419
7420@smallexample
7421(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
7422
7423(@value{GDBP}) @b{trace +2} // 2 lines forward
7424
7425(@value{GDBP}) @b{trace my_function} // first source line of function
7426
7427(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
7428
7429(@value{GDBP}) @b{trace *0x2117c4} // an address
7430@end smallexample
7431
7432@noindent
7433You can abbreviate @code{trace} as @code{tr}.
7434
7435@vindex $tpnum
7436@cindex last tracepoint number
7437@cindex recent tracepoint number
7438@cindex tracepoint number
7439The convenience variable @code{$tpnum} records the tracepoint number
7440of the most recently set tracepoint.
7441
7442@kindex delete tracepoint
7443@cindex tracepoint deletion
7444@item delete tracepoint @r{[}@var{num}@r{]}
7445Permanently delete one or more tracepoints. With no argument, the
7446default is to delete all tracepoints.
7447
7448Examples:
7449
7450@smallexample
7451(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7452
7453(@value{GDBP}) @b{delete trace} // remove all tracepoints
7454@end smallexample
7455
7456@noindent
7457You can abbreviate this command as @code{del tr}.
7458@end table
7459
7460@node Enable and Disable Tracepoints
7461@subsection Enable and Disable Tracepoints
7462
7463@table @code
7464@kindex disable tracepoint
7465@item disable tracepoint @r{[}@var{num}@r{]}
7466Disable tracepoint @var{num}, or all tracepoints if no argument
7467@var{num} is given. A disabled tracepoint will have no effect during
7468the next trace experiment, but it is not forgotten. You can re-enable
7469a disabled tracepoint using the @code{enable tracepoint} command.
7470
7471@kindex enable tracepoint
7472@item enable tracepoint @r{[}@var{num}@r{]}
7473Enable tracepoint @var{num}, or all tracepoints. The enabled
7474tracepoints will become effective the next time a trace experiment is
7475run.
7476@end table
7477
7478@node Tracepoint Passcounts
7479@subsection Tracepoint Passcounts
7480
7481@table @code
7482@kindex passcount
7483@cindex tracepoint pass count
7484@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7485Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7486automatically stop a trace experiment. If a tracepoint's passcount is
7487@var{n}, then the trace experiment will be automatically stopped on
7488the @var{n}'th time that tracepoint is hit. If the tracepoint number
7489@var{num} is not specified, the @code{passcount} command sets the
7490passcount of the most recently defined tracepoint. If no passcount is
7491given, the trace experiment will run until stopped explicitly by the
7492user.
7493
7494Examples:
7495
7496@smallexample
b383017d 7497(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 7498@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
7499
7500(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 7501@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
7502(@value{GDBP}) @b{trace foo}
7503(@value{GDBP}) @b{pass 3}
7504(@value{GDBP}) @b{trace bar}
7505(@value{GDBP}) @b{pass 2}
7506(@value{GDBP}) @b{trace baz}
7507(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
7508@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7509@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7510@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
7511@end smallexample
7512@end table
7513
7514@node Tracepoint Actions
7515@subsection Tracepoint Action Lists
7516
7517@table @code
7518@kindex actions
7519@cindex tracepoint actions
7520@item actions @r{[}@var{num}@r{]}
7521This command will prompt for a list of actions to be taken when the
7522tracepoint is hit. If the tracepoint number @var{num} is not
7523specified, this command sets the actions for the one that was most
7524recently defined (so that you can define a tracepoint and then say
7525@code{actions} without bothering about its number). You specify the
7526actions themselves on the following lines, one action at a time, and
7527terminate the actions list with a line containing just @code{end}. So
7528far, the only defined actions are @code{collect} and
7529@code{while-stepping}.
7530
7531@cindex remove actions from a tracepoint
7532To remove all actions from a tracepoint, type @samp{actions @var{num}}
7533and follow it immediately with @samp{end}.
7534
7535@smallexample
7536(@value{GDBP}) @b{collect @var{data}} // collect some data
7537
6826cf00 7538(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 7539
6826cf00 7540(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
7541@end smallexample
7542
7543In the following example, the action list begins with @code{collect}
7544commands indicating the things to be collected when the tracepoint is
7545hit. Then, in order to single-step and collect additional data
7546following the tracepoint, a @code{while-stepping} command is used,
7547followed by the list of things to be collected while stepping. The
7548@code{while-stepping} command is terminated by its own separate
7549@code{end} command. Lastly, the action list is terminated by an
7550@code{end} command.
7551
7552@smallexample
7553(@value{GDBP}) @b{trace foo}
7554(@value{GDBP}) @b{actions}
7555Enter actions for tracepoint 1, one per line:
7556> collect bar,baz
7557> collect $regs
7558> while-stepping 12
7559 > collect $fp, $sp
7560 > end
7561end
7562@end smallexample
7563
7564@kindex collect @r{(tracepoints)}
7565@item collect @var{expr1}, @var{expr2}, @dots{}
7566Collect values of the given expressions when the tracepoint is hit.
7567This command accepts a comma-separated list of any valid expressions.
7568In addition to global, static, or local variables, the following
7569special arguments are supported:
7570
7571@table @code
7572@item $regs
7573collect all registers
7574
7575@item $args
7576collect all function arguments
7577
7578@item $locals
7579collect all local variables.
7580@end table
7581
7582You can give several consecutive @code{collect} commands, each one
7583with a single argument, or one @code{collect} command with several
7584arguments separated by commas: the effect is the same.
7585
f5c37c66
EZ
7586The command @code{info scope} (@pxref{Symbols, info scope}) is
7587particularly useful for figuring out what data to collect.
7588
b37052ae
EZ
7589@kindex while-stepping @r{(tracepoints)}
7590@item while-stepping @var{n}
7591Perform @var{n} single-step traces after the tracepoint, collecting
7592new data at each step. The @code{while-stepping} command is
7593followed by the list of what to collect while stepping (followed by
7594its own @code{end} command):
7595
7596@smallexample
7597> while-stepping 12
7598 > collect $regs, myglobal
7599 > end
7600>
7601@end smallexample
7602
7603@noindent
7604You may abbreviate @code{while-stepping} as @code{ws} or
7605@code{stepping}.
7606@end table
7607
7608@node Listing Tracepoints
7609@subsection Listing Tracepoints
7610
7611@table @code
7612@kindex info tracepoints
09d4efe1 7613@kindex info tp
b37052ae
EZ
7614@cindex information about tracepoints
7615@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 7616Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 7617a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
7618defined so far. For each tracepoint, the following information is
7619shown:
7620
7621@itemize @bullet
7622@item
7623its number
7624@item
7625whether it is enabled or disabled
7626@item
7627its address
7628@item
7629its passcount as given by the @code{passcount @var{n}} command
7630@item
7631its step count as given by the @code{while-stepping @var{n}} command
7632@item
7633where in the source files is the tracepoint set
7634@item
7635its action list as given by the @code{actions} command
7636@end itemize
7637
7638@smallexample
7639(@value{GDBP}) @b{info trace}
7640Num Enb Address PassC StepC What
76411 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
76422 y 0x0020dc64 0 0 in g_test at g_test.c:1375
76433 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
7644(@value{GDBP})
7645@end smallexample
7646
7647@noindent
7648This command can be abbreviated @code{info tp}.
7649@end table
7650
7651@node Starting and Stopping Trace Experiment
7652@subsection Starting and Stopping Trace Experiment
7653
7654@table @code
7655@kindex tstart
7656@cindex start a new trace experiment
7657@cindex collected data discarded
7658@item tstart
7659This command takes no arguments. It starts the trace experiment, and
7660begins collecting data. This has the side effect of discarding all
7661the data collected in the trace buffer during the previous trace
7662experiment.
7663
7664@kindex tstop
7665@cindex stop a running trace experiment
7666@item tstop
7667This command takes no arguments. It ends the trace experiment, and
7668stops collecting data.
7669
68c71a2e 7670@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
7671automatically if any tracepoint's passcount is reached
7672(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7673
7674@kindex tstatus
7675@cindex status of trace data collection
7676@cindex trace experiment, status of
7677@item tstatus
7678This command displays the status of the current trace data
7679collection.
7680@end table
7681
7682Here is an example of the commands we described so far:
7683
7684@smallexample
7685(@value{GDBP}) @b{trace gdb_c_test}
7686(@value{GDBP}) @b{actions}
7687Enter actions for tracepoint #1, one per line.
7688> collect $regs,$locals,$args
7689> while-stepping 11
7690 > collect $regs
7691 > end
7692> end
7693(@value{GDBP}) @b{tstart}
7694 [time passes @dots{}]
7695(@value{GDBP}) @b{tstop}
7696@end smallexample
7697
7698
7699@node Analyze Collected Data
7700@section Using the collected data
7701
7702After the tracepoint experiment ends, you use @value{GDBN} commands
7703for examining the trace data. The basic idea is that each tracepoint
7704collects a trace @dfn{snapshot} every time it is hit and another
7705snapshot every time it single-steps. All these snapshots are
7706consecutively numbered from zero and go into a buffer, and you can
7707examine them later. The way you examine them is to @dfn{focus} on a
7708specific trace snapshot. When the remote stub is focused on a trace
7709snapshot, it will respond to all @value{GDBN} requests for memory and
7710registers by reading from the buffer which belongs to that snapshot,
7711rather than from @emph{real} memory or registers of the program being
7712debugged. This means that @strong{all} @value{GDBN} commands
7713(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7714behave as if we were currently debugging the program state as it was
7715when the tracepoint occurred. Any requests for data that are not in
7716the buffer will fail.
7717
7718@menu
7719* tfind:: How to select a trace snapshot
7720* tdump:: How to display all data for a snapshot
7721* save-tracepoints:: How to save tracepoints for a future run
7722@end menu
7723
7724@node tfind
7725@subsection @code{tfind @var{n}}
7726
7727@kindex tfind
7728@cindex select trace snapshot
7729@cindex find trace snapshot
7730The basic command for selecting a trace snapshot from the buffer is
7731@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7732counting from zero. If no argument @var{n} is given, the next
7733snapshot is selected.
7734
7735Here are the various forms of using the @code{tfind} command.
7736
7737@table @code
7738@item tfind start
7739Find the first snapshot in the buffer. This is a synonym for
7740@code{tfind 0} (since 0 is the number of the first snapshot).
7741
7742@item tfind none
7743Stop debugging trace snapshots, resume @emph{live} debugging.
7744
7745@item tfind end
7746Same as @samp{tfind none}.
7747
7748@item tfind
7749No argument means find the next trace snapshot.
7750
7751@item tfind -
7752Find the previous trace snapshot before the current one. This permits
7753retracing earlier steps.
7754
7755@item tfind tracepoint @var{num}
7756Find the next snapshot associated with tracepoint @var{num}. Search
7757proceeds forward from the last examined trace snapshot. If no
7758argument @var{num} is given, it means find the next snapshot collected
7759for the same tracepoint as the current snapshot.
7760
7761@item tfind pc @var{addr}
7762Find the next snapshot associated with the value @var{addr} of the
7763program counter. Search proceeds forward from the last examined trace
7764snapshot. If no argument @var{addr} is given, it means find the next
7765snapshot with the same value of PC as the current snapshot.
7766
7767@item tfind outside @var{addr1}, @var{addr2}
7768Find the next snapshot whose PC is outside the given range of
7769addresses.
7770
7771@item tfind range @var{addr1}, @var{addr2}
7772Find the next snapshot whose PC is between @var{addr1} and
7773@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7774
7775@item tfind line @r{[}@var{file}:@r{]}@var{n}
7776Find the next snapshot associated with the source line @var{n}. If
7777the optional argument @var{file} is given, refer to line @var{n} in
7778that source file. Search proceeds forward from the last examined
7779trace snapshot. If no argument @var{n} is given, it means find the
7780next line other than the one currently being examined; thus saying
7781@code{tfind line} repeatedly can appear to have the same effect as
7782stepping from line to line in a @emph{live} debugging session.
7783@end table
7784
7785The default arguments for the @code{tfind} commands are specifically
7786designed to make it easy to scan through the trace buffer. For
7787instance, @code{tfind} with no argument selects the next trace
7788snapshot, and @code{tfind -} with no argument selects the previous
7789trace snapshot. So, by giving one @code{tfind} command, and then
7790simply hitting @key{RET} repeatedly you can examine all the trace
7791snapshots in order. Or, by saying @code{tfind -} and then hitting
7792@key{RET} repeatedly you can examine the snapshots in reverse order.
7793The @code{tfind line} command with no argument selects the snapshot
7794for the next source line executed. The @code{tfind pc} command with
7795no argument selects the next snapshot with the same program counter
7796(PC) as the current frame. The @code{tfind tracepoint} command with
7797no argument selects the next trace snapshot collected by the same
7798tracepoint as the current one.
7799
7800In addition to letting you scan through the trace buffer manually,
7801these commands make it easy to construct @value{GDBN} scripts that
7802scan through the trace buffer and print out whatever collected data
7803you are interested in. Thus, if we want to examine the PC, FP, and SP
7804registers from each trace frame in the buffer, we can say this:
7805
7806@smallexample
7807(@value{GDBP}) @b{tfind start}
7808(@value{GDBP}) @b{while ($trace_frame != -1)}
7809> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7810 $trace_frame, $pc, $sp, $fp
7811> tfind
7812> end
7813
7814Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7815Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7816Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7817Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7818Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7819Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7820Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7821Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7822Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7823Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7824Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7825@end smallexample
7826
7827Or, if we want to examine the variable @code{X} at each source line in
7828the buffer:
7829
7830@smallexample
7831(@value{GDBP}) @b{tfind start}
7832(@value{GDBP}) @b{while ($trace_frame != -1)}
7833> printf "Frame %d, X == %d\n", $trace_frame, X
7834> tfind line
7835> end
7836
7837Frame 0, X = 1
7838Frame 7, X = 2
7839Frame 13, X = 255
7840@end smallexample
7841
7842@node tdump
7843@subsection @code{tdump}
7844@kindex tdump
7845@cindex dump all data collected at tracepoint
7846@cindex tracepoint data, display
7847
7848This command takes no arguments. It prints all the data collected at
7849the current trace snapshot.
7850
7851@smallexample
7852(@value{GDBP}) @b{trace 444}
7853(@value{GDBP}) @b{actions}
7854Enter actions for tracepoint #2, one per line:
7855> collect $regs, $locals, $args, gdb_long_test
7856> end
7857
7858(@value{GDBP}) @b{tstart}
7859
7860(@value{GDBP}) @b{tfind line 444}
7861#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7862at gdb_test.c:444
7863444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7864
7865(@value{GDBP}) @b{tdump}
7866Data collected at tracepoint 2, trace frame 1:
7867d0 0xc4aa0085 -995491707
7868d1 0x18 24
7869d2 0x80 128
7870d3 0x33 51
7871d4 0x71aea3d 119204413
7872d5 0x22 34
7873d6 0xe0 224
7874d7 0x380035 3670069
7875a0 0x19e24a 1696330
7876a1 0x3000668 50333288
7877a2 0x100 256
7878a3 0x322000 3284992
7879a4 0x3000698 50333336
7880a5 0x1ad3cc 1758156
7881fp 0x30bf3c 0x30bf3c
7882sp 0x30bf34 0x30bf34
7883ps 0x0 0
7884pc 0x20b2c8 0x20b2c8
7885fpcontrol 0x0 0
7886fpstatus 0x0 0
7887fpiaddr 0x0 0
7888p = 0x20e5b4 "gdb-test"
7889p1 = (void *) 0x11
7890p2 = (void *) 0x22
7891p3 = (void *) 0x33
7892p4 = (void *) 0x44
7893p5 = (void *) 0x55
7894p6 = (void *) 0x66
7895gdb_long_test = 17 '\021'
7896
7897(@value{GDBP})
7898@end smallexample
7899
7900@node save-tracepoints
7901@subsection @code{save-tracepoints @var{filename}}
7902@kindex save-tracepoints
7903@cindex save tracepoints for future sessions
7904
7905This command saves all current tracepoint definitions together with
7906their actions and passcounts, into a file @file{@var{filename}}
7907suitable for use in a later debugging session. To read the saved
7908tracepoint definitions, use the @code{source} command (@pxref{Command
7909Files}).
7910
7911@node Tracepoint Variables
7912@section Convenience Variables for Tracepoints
7913@cindex tracepoint variables
7914@cindex convenience variables for tracepoints
7915
7916@table @code
7917@vindex $trace_frame
7918@item (int) $trace_frame
7919The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7920snapshot is selected.
7921
7922@vindex $tracepoint
7923@item (int) $tracepoint
7924The tracepoint for the current trace snapshot.
7925
7926@vindex $trace_line
7927@item (int) $trace_line
7928The line number for the current trace snapshot.
7929
7930@vindex $trace_file
7931@item (char []) $trace_file
7932The source file for the current trace snapshot.
7933
7934@vindex $trace_func
7935@item (char []) $trace_func
7936The name of the function containing @code{$tracepoint}.
7937@end table
7938
7939Note: @code{$trace_file} is not suitable for use in @code{printf},
7940use @code{output} instead.
7941
7942Here's a simple example of using these convenience variables for
7943stepping through all the trace snapshots and printing some of their
7944data.
7945
7946@smallexample
7947(@value{GDBP}) @b{tfind start}
7948
7949(@value{GDBP}) @b{while $trace_frame != -1}
7950> output $trace_file
7951> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7952> tfind
7953> end
7954@end smallexample
7955
df0cd8c5
JB
7956@node Overlays
7957@chapter Debugging Programs That Use Overlays
7958@cindex overlays
7959
7960If your program is too large to fit completely in your target system's
7961memory, you can sometimes use @dfn{overlays} to work around this
7962problem. @value{GDBN} provides some support for debugging programs that
7963use overlays.
7964
7965@menu
7966* How Overlays Work:: A general explanation of overlays.
7967* Overlay Commands:: Managing overlays in @value{GDBN}.
7968* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7969 mapped by asking the inferior.
7970* Overlay Sample Program:: A sample program using overlays.
7971@end menu
7972
7973@node How Overlays Work
7974@section How Overlays Work
7975@cindex mapped overlays
7976@cindex unmapped overlays
7977@cindex load address, overlay's
7978@cindex mapped address
7979@cindex overlay area
7980
7981Suppose you have a computer whose instruction address space is only 64
7982kilobytes long, but which has much more memory which can be accessed by
7983other means: special instructions, segment registers, or memory
7984management hardware, for example. Suppose further that you want to
7985adapt a program which is larger than 64 kilobytes to run on this system.
7986
7987One solution is to identify modules of your program which are relatively
7988independent, and need not call each other directly; call these modules
7989@dfn{overlays}. Separate the overlays from the main program, and place
7990their machine code in the larger memory. Place your main program in
7991instruction memory, but leave at least enough space there to hold the
7992largest overlay as well.
7993
7994Now, to call a function located in an overlay, you must first copy that
7995overlay's machine code from the large memory into the space set aside
7996for it in the instruction memory, and then jump to its entry point
7997there.
7998
c928edc0
AC
7999@c NB: In the below the mapped area's size is greater or equal to the
8000@c size of all overlays. This is intentional to remind the developer
8001@c that overlays don't necessarily need to be the same size.
8002
474c8240 8003@smallexample
df0cd8c5 8004@group
c928edc0
AC
8005 Data Instruction Larger
8006Address Space Address Space Address Space
8007+-----------+ +-----------+ +-----------+
8008| | | | | |
8009+-----------+ +-----------+ +-----------+<-- overlay 1
8010| program | | main | .----| overlay 1 | load address
8011| variables | | program | | +-----------+
8012| and heap | | | | | |
8013+-----------+ | | | +-----------+<-- overlay 2
8014| | +-----------+ | | | load address
8015+-----------+ | | | .-| overlay 2 |
8016 | | | | | |
8017 mapped --->+-----------+ | | +-----------+
8018 address | | | | | |
8019 | overlay | <-' | | |
8020 | area | <---' +-----------+<-- overlay 3
8021 | | <---. | | load address
8022 +-----------+ `--| overlay 3 |
8023 | | | |
8024 +-----------+ | |
8025 +-----------+
8026 | |
8027 +-----------+
8028
8029 @anchor{A code overlay}A code overlay
df0cd8c5 8030@end group
474c8240 8031@end smallexample
df0cd8c5 8032
c928edc0
AC
8033The diagram (@pxref{A code overlay}) shows a system with separate data
8034and instruction address spaces. To map an overlay, the program copies
8035its code from the larger address space to the instruction address space.
8036Since the overlays shown here all use the same mapped address, only one
8037may be mapped at a time. For a system with a single address space for
8038data and instructions, the diagram would be similar, except that the
8039program variables and heap would share an address space with the main
8040program and the overlay area.
df0cd8c5
JB
8041
8042An overlay loaded into instruction memory and ready for use is called a
8043@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
8044instruction memory. An overlay not present (or only partially present)
8045in instruction memory is called @dfn{unmapped}; its @dfn{load address}
8046is its address in the larger memory. The mapped address is also called
8047the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
8048called the @dfn{load memory address}, or @dfn{LMA}.
8049
8050Unfortunately, overlays are not a completely transparent way to adapt a
8051program to limited instruction memory. They introduce a new set of
8052global constraints you must keep in mind as you design your program:
8053
8054@itemize @bullet
8055
8056@item
8057Before calling or returning to a function in an overlay, your program
8058must make sure that overlay is actually mapped. Otherwise, the call or
8059return will transfer control to the right address, but in the wrong
8060overlay, and your program will probably crash.
8061
8062@item
8063If the process of mapping an overlay is expensive on your system, you
8064will need to choose your overlays carefully to minimize their effect on
8065your program's performance.
8066
8067@item
8068The executable file you load onto your system must contain each
8069overlay's instructions, appearing at the overlay's load address, not its
8070mapped address. However, each overlay's instructions must be relocated
8071and its symbols defined as if the overlay were at its mapped address.
8072You can use GNU linker scripts to specify different load and relocation
8073addresses for pieces of your program; see @ref{Overlay Description,,,
8074ld.info, Using ld: the GNU linker}.
8075
8076@item
8077The procedure for loading executable files onto your system must be able
8078to load their contents into the larger address space as well as the
8079instruction and data spaces.
8080
8081@end itemize
8082
8083The overlay system described above is rather simple, and could be
8084improved in many ways:
8085
8086@itemize @bullet
8087
8088@item
8089If your system has suitable bank switch registers or memory management
8090hardware, you could use those facilities to make an overlay's load area
8091contents simply appear at their mapped address in instruction space.
8092This would probably be faster than copying the overlay to its mapped
8093area in the usual way.
8094
8095@item
8096If your overlays are small enough, you could set aside more than one
8097overlay area, and have more than one overlay mapped at a time.
8098
8099@item
8100You can use overlays to manage data, as well as instructions. In
8101general, data overlays are even less transparent to your design than
8102code overlays: whereas code overlays only require care when you call or
8103return to functions, data overlays require care every time you access
8104the data. Also, if you change the contents of a data overlay, you
8105must copy its contents back out to its load address before you can copy a
8106different data overlay into the same mapped area.
8107
8108@end itemize
8109
8110
8111@node Overlay Commands
8112@section Overlay Commands
8113
8114To use @value{GDBN}'s overlay support, each overlay in your program must
8115correspond to a separate section of the executable file. The section's
8116virtual memory address and load memory address must be the overlay's
8117mapped and load addresses. Identifying overlays with sections allows
8118@value{GDBN} to determine the appropriate address of a function or
8119variable, depending on whether the overlay is mapped or not.
8120
8121@value{GDBN}'s overlay commands all start with the word @code{overlay};
8122you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
8123
8124@table @code
8125@item overlay off
4644b6e3 8126@kindex overlay
df0cd8c5
JB
8127Disable @value{GDBN}'s overlay support. When overlay support is
8128disabled, @value{GDBN} assumes that all functions and variables are
8129always present at their mapped addresses. By default, @value{GDBN}'s
8130overlay support is disabled.
8131
8132@item overlay manual
df0cd8c5
JB
8133@cindex manual overlay debugging
8134Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
8135relies on you to tell it which overlays are mapped, and which are not,
8136using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
8137commands described below.
8138
8139@item overlay map-overlay @var{overlay}
8140@itemx overlay map @var{overlay}
df0cd8c5
JB
8141@cindex map an overlay
8142Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
8143be the name of the object file section containing the overlay. When an
8144overlay is mapped, @value{GDBN} assumes it can find the overlay's
8145functions and variables at their mapped addresses. @value{GDBN} assumes
8146that any other overlays whose mapped ranges overlap that of
8147@var{overlay} are now unmapped.
8148
8149@item overlay unmap-overlay @var{overlay}
8150@itemx overlay unmap @var{overlay}
df0cd8c5
JB
8151@cindex unmap an overlay
8152Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
8153must be the name of the object file section containing the overlay.
8154When an overlay is unmapped, @value{GDBN} assumes it can find the
8155overlay's functions and variables at their load addresses.
8156
8157@item overlay auto
df0cd8c5
JB
8158Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
8159consults a data structure the overlay manager maintains in the inferior
8160to see which overlays are mapped. For details, see @ref{Automatic
8161Overlay Debugging}.
8162
8163@item overlay load-target
8164@itemx overlay load
df0cd8c5
JB
8165@cindex reloading the overlay table
8166Re-read the overlay table from the inferior. Normally, @value{GDBN}
8167re-reads the table @value{GDBN} automatically each time the inferior
8168stops, so this command should only be necessary if you have changed the
8169overlay mapping yourself using @value{GDBN}. This command is only
8170useful when using automatic overlay debugging.
8171
8172@item overlay list-overlays
8173@itemx overlay list
8174@cindex listing mapped overlays
8175Display a list of the overlays currently mapped, along with their mapped
8176addresses, load addresses, and sizes.
8177
8178@end table
8179
8180Normally, when @value{GDBN} prints a code address, it includes the name
8181of the function the address falls in:
8182
474c8240 8183@smallexample
f7dc1244 8184(@value{GDBP}) print main
df0cd8c5 8185$3 = @{int ()@} 0x11a0 <main>
474c8240 8186@end smallexample
df0cd8c5
JB
8187@noindent
8188When overlay debugging is enabled, @value{GDBN} recognizes code in
8189unmapped overlays, and prints the names of unmapped functions with
8190asterisks around them. For example, if @code{foo} is a function in an
8191unmapped overlay, @value{GDBN} prints it this way:
8192
474c8240 8193@smallexample
f7dc1244 8194(@value{GDBP}) overlay list
df0cd8c5 8195No sections are mapped.
f7dc1244 8196(@value{GDBP}) print foo
df0cd8c5 8197$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 8198@end smallexample
df0cd8c5
JB
8199@noindent
8200When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
8201name normally:
8202
474c8240 8203@smallexample
f7dc1244 8204(@value{GDBP}) overlay list
b383017d 8205Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 8206 mapped at 0x1016 - 0x104a
f7dc1244 8207(@value{GDBP}) print foo
df0cd8c5 8208$6 = @{int (int)@} 0x1016 <foo>
474c8240 8209@end smallexample
df0cd8c5
JB
8210
8211When overlay debugging is enabled, @value{GDBN} can find the correct
8212address for functions and variables in an overlay, whether or not the
8213overlay is mapped. This allows most @value{GDBN} commands, like
8214@code{break} and @code{disassemble}, to work normally, even on unmapped
8215code. However, @value{GDBN}'s breakpoint support has some limitations:
8216
8217@itemize @bullet
8218@item
8219@cindex breakpoints in overlays
8220@cindex overlays, setting breakpoints in
8221You can set breakpoints in functions in unmapped overlays, as long as
8222@value{GDBN} can write to the overlay at its load address.
8223@item
8224@value{GDBN} can not set hardware or simulator-based breakpoints in
8225unmapped overlays. However, if you set a breakpoint at the end of your
8226overlay manager (and tell @value{GDBN} which overlays are now mapped, if
8227you are using manual overlay management), @value{GDBN} will re-set its
8228breakpoints properly.
8229@end itemize
8230
8231
8232@node Automatic Overlay Debugging
8233@section Automatic Overlay Debugging
8234@cindex automatic overlay debugging
8235
8236@value{GDBN} can automatically track which overlays are mapped and which
8237are not, given some simple co-operation from the overlay manager in the
8238inferior. If you enable automatic overlay debugging with the
8239@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
8240looks in the inferior's memory for certain variables describing the
8241current state of the overlays.
8242
8243Here are the variables your overlay manager must define to support
8244@value{GDBN}'s automatic overlay debugging:
8245
8246@table @asis
8247
8248@item @code{_ovly_table}:
8249This variable must be an array of the following structures:
8250
474c8240 8251@smallexample
df0cd8c5
JB
8252struct
8253@{
8254 /* The overlay's mapped address. */
8255 unsigned long vma;
8256
8257 /* The size of the overlay, in bytes. */
8258 unsigned long size;
8259
8260 /* The overlay's load address. */
8261 unsigned long lma;
8262
8263 /* Non-zero if the overlay is currently mapped;
8264 zero otherwise. */
8265 unsigned long mapped;
8266@}
474c8240 8267@end smallexample
df0cd8c5
JB
8268
8269@item @code{_novlys}:
8270This variable must be a four-byte signed integer, holding the total
8271number of elements in @code{_ovly_table}.
8272
8273@end table
8274
8275To decide whether a particular overlay is mapped or not, @value{GDBN}
8276looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
8277@code{lma} members equal the VMA and LMA of the overlay's section in the
8278executable file. When @value{GDBN} finds a matching entry, it consults
8279the entry's @code{mapped} member to determine whether the overlay is
8280currently mapped.
8281
81d46470 8282In addition, your overlay manager may define a function called
def71bfa 8283@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
8284will silently set a breakpoint there. If the overlay manager then
8285calls this function whenever it has changed the overlay table, this
8286will enable @value{GDBN} to accurately keep track of which overlays
8287are in program memory, and update any breakpoints that may be set
b383017d 8288in overlays. This will allow breakpoints to work even if the
81d46470
MS
8289overlays are kept in ROM or other non-writable memory while they
8290are not being executed.
df0cd8c5
JB
8291
8292@node Overlay Sample Program
8293@section Overlay Sample Program
8294@cindex overlay example program
8295
8296When linking a program which uses overlays, you must place the overlays
8297at their load addresses, while relocating them to run at their mapped
8298addresses. To do this, you must write a linker script (@pxref{Overlay
8299Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
8300since linker scripts are specific to a particular host system, target
8301architecture, and target memory layout, this manual cannot provide
8302portable sample code demonstrating @value{GDBN}'s overlay support.
8303
8304However, the @value{GDBN} source distribution does contain an overlaid
8305program, with linker scripts for a few systems, as part of its test
8306suite. The program consists of the following files from
8307@file{gdb/testsuite/gdb.base}:
8308
8309@table @file
8310@item overlays.c
8311The main program file.
8312@item ovlymgr.c
8313A simple overlay manager, used by @file{overlays.c}.
8314@item foo.c
8315@itemx bar.c
8316@itemx baz.c
8317@itemx grbx.c
8318Overlay modules, loaded and used by @file{overlays.c}.
8319@item d10v.ld
8320@itemx m32r.ld
8321Linker scripts for linking the test program on the @code{d10v-elf}
8322and @code{m32r-elf} targets.
8323@end table
8324
8325You can build the test program using the @code{d10v-elf} GCC
8326cross-compiler like this:
8327
474c8240 8328@smallexample
df0cd8c5
JB
8329$ d10v-elf-gcc -g -c overlays.c
8330$ d10v-elf-gcc -g -c ovlymgr.c
8331$ d10v-elf-gcc -g -c foo.c
8332$ d10v-elf-gcc -g -c bar.c
8333$ d10v-elf-gcc -g -c baz.c
8334$ d10v-elf-gcc -g -c grbx.c
8335$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
8336 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 8337@end smallexample
df0cd8c5
JB
8338
8339The build process is identical for any other architecture, except that
8340you must substitute the appropriate compiler and linker script for the
8341target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
8342
8343
6d2ebf8b 8344@node Languages
c906108c
SS
8345@chapter Using @value{GDBN} with Different Languages
8346@cindex languages
8347
c906108c
SS
8348Although programming languages generally have common aspects, they are
8349rarely expressed in the same manner. For instance, in ANSI C,
8350dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
8351Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 8352represented (and displayed) differently. Hex numbers in C appear as
c906108c 8353@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
8354
8355@cindex working language
8356Language-specific information is built into @value{GDBN} for some languages,
8357allowing you to express operations like the above in your program's
8358native language, and allowing @value{GDBN} to output values in a manner
8359consistent with the syntax of your program's native language. The
8360language you use to build expressions is called the @dfn{working
8361language}.
8362
8363@menu
8364* Setting:: Switching between source languages
8365* Show:: Displaying the language
c906108c 8366* Checks:: Type and range checks
9c16f35a 8367* Supported languages:: Supported languages
4e562065 8368* Unsupported languages:: Unsupported languages
c906108c
SS
8369@end menu
8370
6d2ebf8b 8371@node Setting
c906108c
SS
8372@section Switching between source languages
8373
8374There are two ways to control the working language---either have @value{GDBN}
8375set it automatically, or select it manually yourself. You can use the
8376@code{set language} command for either purpose. On startup, @value{GDBN}
8377defaults to setting the language automatically. The working language is
8378used to determine how expressions you type are interpreted, how values
8379are printed, etc.
8380
8381In addition to the working language, every source file that
8382@value{GDBN} knows about has its own working language. For some object
8383file formats, the compiler might indicate which language a particular
8384source file is in. However, most of the time @value{GDBN} infers the
8385language from the name of the file. The language of a source file
b37052ae 8386controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 8387show each frame appropriately for its own language. There is no way to
d4f3574e
SS
8388set the language of a source file from within @value{GDBN}, but you can
8389set the language associated with a filename extension. @xref{Show, ,
8390Displaying the language}.
c906108c
SS
8391
8392This is most commonly a problem when you use a program, such
5d161b24 8393as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
8394another language. In that case, make the
8395program use @code{#line} directives in its C output; that way
8396@value{GDBN} will know the correct language of the source code of the original
8397program, and will display that source code, not the generated C code.
8398
8399@menu
8400* Filenames:: Filename extensions and languages.
8401* Manually:: Setting the working language manually
8402* Automatically:: Having @value{GDBN} infer the source language
8403@end menu
8404
6d2ebf8b 8405@node Filenames
c906108c
SS
8406@subsection List of filename extensions and languages
8407
8408If a source file name ends in one of the following extensions, then
8409@value{GDBN} infers that its language is the one indicated.
8410
8411@table @file
e07c999f
PH
8412@item .ada
8413@itemx .ads
8414@itemx .adb
8415@itemx .a
8416Ada source file.
c906108c
SS
8417
8418@item .c
8419C source file
8420
8421@item .C
8422@itemx .cc
8423@itemx .cp
8424@itemx .cpp
8425@itemx .cxx
8426@itemx .c++
b37052ae 8427C@t{++} source file
c906108c 8428
b37303ee
AF
8429@item .m
8430Objective-C source file
8431
c906108c
SS
8432@item .f
8433@itemx .F
8434Fortran source file
8435
c906108c
SS
8436@item .mod
8437Modula-2 source file
c906108c
SS
8438
8439@item .s
8440@itemx .S
8441Assembler source file. This actually behaves almost like C, but
8442@value{GDBN} does not skip over function prologues when stepping.
8443@end table
8444
8445In addition, you may set the language associated with a filename
8446extension. @xref{Show, , Displaying the language}.
8447
6d2ebf8b 8448@node Manually
c906108c
SS
8449@subsection Setting the working language
8450
8451If you allow @value{GDBN} to set the language automatically,
8452expressions are interpreted the same way in your debugging session and
8453your program.
8454
8455@kindex set language
8456If you wish, you may set the language manually. To do this, issue the
8457command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 8458a language, such as
c906108c 8459@code{c} or @code{modula-2}.
c906108c
SS
8460For a list of the supported languages, type @samp{set language}.
8461
c906108c
SS
8462Setting the language manually prevents @value{GDBN} from updating the working
8463language automatically. This can lead to confusion if you try
8464to debug a program when the working language is not the same as the
8465source language, when an expression is acceptable to both
8466languages---but means different things. For instance, if the current
8467source file were written in C, and @value{GDBN} was parsing Modula-2, a
8468command such as:
8469
474c8240 8470@smallexample
c906108c 8471print a = b + c
474c8240 8472@end smallexample
c906108c
SS
8473
8474@noindent
8475might not have the effect you intended. In C, this means to add
8476@code{b} and @code{c} and place the result in @code{a}. The result
8477printed would be the value of @code{a}. In Modula-2, this means to compare
8478@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 8479
6d2ebf8b 8480@node Automatically
c906108c
SS
8481@subsection Having @value{GDBN} infer the source language
8482
8483To have @value{GDBN} set the working language automatically, use
8484@samp{set language local} or @samp{set language auto}. @value{GDBN}
8485then infers the working language. That is, when your program stops in a
8486frame (usually by encountering a breakpoint), @value{GDBN} sets the
8487working language to the language recorded for the function in that
8488frame. If the language for a frame is unknown (that is, if the function
8489or block corresponding to the frame was defined in a source file that
8490does not have a recognized extension), the current working language is
8491not changed, and @value{GDBN} issues a warning.
8492
8493This may not seem necessary for most programs, which are written
8494entirely in one source language. However, program modules and libraries
8495written in one source language can be used by a main program written in
8496a different source language. Using @samp{set language auto} in this
8497case frees you from having to set the working language manually.
8498
6d2ebf8b 8499@node Show
c906108c 8500@section Displaying the language
c906108c
SS
8501
8502The following commands help you find out which language is the
8503working language, and also what language source files were written in.
8504
c906108c
SS
8505@table @code
8506@item show language
9c16f35a 8507@kindex show language
c906108c
SS
8508Display the current working language. This is the
8509language you can use with commands such as @code{print} to
8510build and compute expressions that may involve variables in your program.
8511
8512@item info frame
4644b6e3 8513@kindex info frame@r{, show the source language}
5d161b24 8514Display the source language for this frame. This language becomes the
c906108c 8515working language if you use an identifier from this frame.
5d161b24 8516@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
8517information listed here.
8518
8519@item info source
4644b6e3 8520@kindex info source@r{, show the source language}
c906108c 8521Display the source language of this source file.
5d161b24 8522@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
8523information listed here.
8524@end table
8525
8526In unusual circumstances, you may have source files with extensions
8527not in the standard list. You can then set the extension associated
8528with a language explicitly:
8529
c906108c 8530@table @code
09d4efe1 8531@item set extension-language @var{ext} @var{language}
9c16f35a 8532@kindex set extension-language
09d4efe1
EZ
8533Tell @value{GDBN} that source files with extension @var{ext} are to be
8534assumed as written in the source language @var{language}.
c906108c
SS
8535
8536@item info extensions
9c16f35a 8537@kindex info extensions
c906108c
SS
8538List all the filename extensions and the associated languages.
8539@end table
8540
6d2ebf8b 8541@node Checks
c906108c
SS
8542@section Type and range checking
8543
8544@quotation
8545@emph{Warning:} In this release, the @value{GDBN} commands for type and range
8546checking are included, but they do not yet have any effect. This
8547section documents the intended facilities.
8548@end quotation
8549@c FIXME remove warning when type/range code added
8550
8551Some languages are designed to guard you against making seemingly common
8552errors through a series of compile- and run-time checks. These include
8553checking the type of arguments to functions and operators, and making
8554sure mathematical overflows are caught at run time. Checks such as
8555these help to ensure a program's correctness once it has been compiled
8556by eliminating type mismatches, and providing active checks for range
8557errors when your program is running.
8558
8559@value{GDBN} can check for conditions like the above if you wish.
9c16f35a
EZ
8560Although @value{GDBN} does not check the statements in your program,
8561it can check expressions entered directly into @value{GDBN} for
8562evaluation via the @code{print} command, for example. As with the
8563working language, @value{GDBN} can also decide whether or not to check
8564automatically based on your program's source language.
8565@xref{Supported languages, ,Supported languages}, for the default
8566settings of supported languages.
c906108c
SS
8567
8568@menu
8569* Type Checking:: An overview of type checking
8570* Range Checking:: An overview of range checking
8571@end menu
8572
8573@cindex type checking
8574@cindex checks, type
6d2ebf8b 8575@node Type Checking
c906108c
SS
8576@subsection An overview of type checking
8577
8578Some languages, such as Modula-2, are strongly typed, meaning that the
8579arguments to operators and functions have to be of the correct type,
8580otherwise an error occurs. These checks prevent type mismatch
8581errors from ever causing any run-time problems. For example,
8582
8583@smallexample
85841 + 2 @result{} 3
8585@exdent but
8586@error{} 1 + 2.3
8587@end smallexample
8588
8589The second example fails because the @code{CARDINAL} 1 is not
8590type-compatible with the @code{REAL} 2.3.
8591
5d161b24
DB
8592For the expressions you use in @value{GDBN} commands, you can tell the
8593@value{GDBN} type checker to skip checking;
8594to treat any mismatches as errors and abandon the expression;
8595or to only issue warnings when type mismatches occur,
c906108c
SS
8596but evaluate the expression anyway. When you choose the last of
8597these, @value{GDBN} evaluates expressions like the second example above, but
8598also issues a warning.
8599
5d161b24
DB
8600Even if you turn type checking off, there may be other reasons
8601related to type that prevent @value{GDBN} from evaluating an expression.
8602For instance, @value{GDBN} does not know how to add an @code{int} and
8603a @code{struct foo}. These particular type errors have nothing to do
8604with the language in use, and usually arise from expressions, such as
c906108c
SS
8605the one described above, which make little sense to evaluate anyway.
8606
8607Each language defines to what degree it is strict about type. For
8608instance, both Modula-2 and C require the arguments to arithmetical
8609operators to be numbers. In C, enumerated types and pointers can be
8610represented as numbers, so that they are valid arguments to mathematical
9c16f35a 8611operators. @xref{Supported languages, ,Supported languages}, for further
c906108c
SS
8612details on specific languages.
8613
8614@value{GDBN} provides some additional commands for controlling the type checker:
8615
c906108c
SS
8616@kindex set check type
8617@kindex show check type
8618@table @code
8619@item set check type auto
8620Set type checking on or off based on the current working language.
9c16f35a 8621@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8622each language.
8623
8624@item set check type on
8625@itemx set check type off
8626Set type checking on or off, overriding the default setting for the
8627current working language. Issue a warning if the setting does not
8628match the language default. If any type mismatches occur in
d4f3574e 8629evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
8630message and aborts evaluation of the expression.
8631
8632@item set check type warn
8633Cause the type checker to issue warnings, but to always attempt to
8634evaluate the expression. Evaluating the expression may still
8635be impossible for other reasons. For example, @value{GDBN} cannot add
8636numbers and structures.
8637
8638@item show type
5d161b24 8639Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
8640is setting it automatically.
8641@end table
8642
8643@cindex range checking
8644@cindex checks, range
6d2ebf8b 8645@node Range Checking
c906108c
SS
8646@subsection An overview of range checking
8647
8648In some languages (such as Modula-2), it is an error to exceed the
8649bounds of a type; this is enforced with run-time checks. Such range
8650checking is meant to ensure program correctness by making sure
8651computations do not overflow, or indices on an array element access do
8652not exceed the bounds of the array.
8653
8654For expressions you use in @value{GDBN} commands, you can tell
8655@value{GDBN} to treat range errors in one of three ways: ignore them,
8656always treat them as errors and abandon the expression, or issue
8657warnings but evaluate the expression anyway.
8658
8659A range error can result from numerical overflow, from exceeding an
8660array index bound, or when you type a constant that is not a member
8661of any type. Some languages, however, do not treat overflows as an
8662error. In many implementations of C, mathematical overflow causes the
8663result to ``wrap around'' to lower values---for example, if @var{m} is
8664the largest integer value, and @var{s} is the smallest, then
8665
474c8240 8666@smallexample
c906108c 8667@var{m} + 1 @result{} @var{s}
474c8240 8668@end smallexample
c906108c
SS
8669
8670This, too, is specific to individual languages, and in some cases
9c16f35a 8671specific to individual compilers or machines. @xref{Supported languages, ,
c906108c
SS
8672Supported languages}, for further details on specific languages.
8673
8674@value{GDBN} provides some additional commands for controlling the range checker:
8675
c906108c
SS
8676@kindex set check range
8677@kindex show check range
8678@table @code
8679@item set check range auto
8680Set range checking on or off based on the current working language.
9c16f35a 8681@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8682each language.
8683
8684@item set check range on
8685@itemx set check range off
8686Set range checking on or off, overriding the default setting for the
8687current working language. A warning is issued if the setting does not
c3f6f71d
JM
8688match the language default. If a range error occurs and range checking is on,
8689then a message is printed and evaluation of the expression is aborted.
c906108c
SS
8690
8691@item set check range warn
8692Output messages when the @value{GDBN} range checker detects a range error,
8693but attempt to evaluate the expression anyway. Evaluating the
8694expression may still be impossible for other reasons, such as accessing
8695memory that the process does not own (a typical example from many Unix
8696systems).
8697
8698@item show range
8699Show the current setting of the range checker, and whether or not it is
8700being set automatically by @value{GDBN}.
8701@end table
c906108c 8702
9c16f35a 8703@node Supported languages
c906108c 8704@section Supported languages
c906108c 8705
9c16f35a
EZ
8706@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
8707assembly, Modula-2, and Ada.
cce74817 8708@c This is false ...
c906108c
SS
8709Some @value{GDBN} features may be used in expressions regardless of the
8710language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8711and the @samp{@{type@}addr} construct (@pxref{Expressions,
8712,Expressions}) can be used with the constructs of any supported
8713language.
8714
8715The following sections detail to what degree each source language is
8716supported by @value{GDBN}. These sections are not meant to be language
8717tutorials or references, but serve only as a reference guide to what the
8718@value{GDBN} expression parser accepts, and what input and output
8719formats should look like for different languages. There are many good
8720books written on each of these languages; please look to these for a
8721language reference or tutorial.
8722
c906108c 8723@menu
b37303ee 8724* C:: C and C@t{++}
b383017d 8725* Objective-C:: Objective-C
09d4efe1 8726* Fortran:: Fortran
9c16f35a 8727* Pascal:: Pascal
b37303ee 8728* Modula-2:: Modula-2
e07c999f 8729* Ada:: Ada
c906108c
SS
8730@end menu
8731
6d2ebf8b 8732@node C
b37052ae 8733@subsection C and C@t{++}
7a292a7a 8734
b37052ae
EZ
8735@cindex C and C@t{++}
8736@cindex expressions in C or C@t{++}
c906108c 8737
b37052ae 8738Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8739to both languages. Whenever this is the case, we discuss those languages
8740together.
8741
41afff9a
EZ
8742@cindex C@t{++}
8743@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8744@cindex @sc{gnu} C@t{++}
8745The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8746compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8747effectively, you must compile your C@t{++} programs with a supported
8748C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8749compiler (@code{aCC}).
8750
0179ffac
DC
8751For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8752format; if it doesn't work on your system, try the stabs+ debugging
8753format. You can select those formats explicitly with the @code{g++}
8754command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8755@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8756CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8757
c906108c 8758@menu
b37052ae
EZ
8759* C Operators:: C and C@t{++} operators
8760* C Constants:: C and C@t{++} constants
8761* C plus plus expressions:: C@t{++} expressions
8762* C Defaults:: Default settings for C and C@t{++}
8763* C Checks:: C and C@t{++} type and range checks
c906108c 8764* Debugging C:: @value{GDBN} and C
b37052ae 8765* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8766@end menu
c906108c 8767
6d2ebf8b 8768@node C Operators
b37052ae 8769@subsubsection C and C@t{++} operators
7a292a7a 8770
b37052ae 8771@cindex C and C@t{++} operators
c906108c
SS
8772
8773Operators must be defined on values of specific types. For instance,
8774@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8775often defined on groups of types.
c906108c 8776
b37052ae 8777For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8778
8779@itemize @bullet
53a5351d 8780
c906108c 8781@item
c906108c 8782@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8783specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8784
8785@item
d4f3574e
SS
8786@emph{Floating-point types} include @code{float}, @code{double}, and
8787@code{long double} (if supported by the target platform).
c906108c
SS
8788
8789@item
53a5351d 8790@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8791
8792@item
8793@emph{Scalar types} include all of the above.
53a5351d 8794
c906108c
SS
8795@end itemize
8796
8797@noindent
8798The following operators are supported. They are listed here
8799in order of increasing precedence:
8800
8801@table @code
8802@item ,
8803The comma or sequencing operator. Expressions in a comma-separated list
8804are evaluated from left to right, with the result of the entire
8805expression being the last expression evaluated.
8806
8807@item =
8808Assignment. The value of an assignment expression is the value
8809assigned. Defined on scalar types.
8810
8811@item @var{op}=
8812Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8813and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8814@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8815@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8816@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8817
8818@item ?:
8819The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8820of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8821integral type.
8822
8823@item ||
8824Logical @sc{or}. Defined on integral types.
8825
8826@item &&
8827Logical @sc{and}. Defined on integral types.
8828
8829@item |
8830Bitwise @sc{or}. Defined on integral types.
8831
8832@item ^
8833Bitwise exclusive-@sc{or}. Defined on integral types.
8834
8835@item &
8836Bitwise @sc{and}. Defined on integral types.
8837
8838@item ==@r{, }!=
8839Equality and inequality. Defined on scalar types. The value of these
8840expressions is 0 for false and non-zero for true.
8841
8842@item <@r{, }>@r{, }<=@r{, }>=
8843Less than, greater than, less than or equal, greater than or equal.
8844Defined on scalar types. The value of these expressions is 0 for false
8845and non-zero for true.
8846
8847@item <<@r{, }>>
8848left shift, and right shift. Defined on integral types.
8849
8850@item @@
8851The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8852
8853@item +@r{, }-
8854Addition and subtraction. Defined on integral types, floating-point types and
8855pointer types.
8856
8857@item *@r{, }/@r{, }%
8858Multiplication, division, and modulus. Multiplication and division are
8859defined on integral and floating-point types. Modulus is defined on
8860integral types.
8861
8862@item ++@r{, }--
8863Increment and decrement. When appearing before a variable, the
8864operation is performed before the variable is used in an expression;
8865when appearing after it, the variable's value is used before the
8866operation takes place.
8867
8868@item *
8869Pointer dereferencing. Defined on pointer types. Same precedence as
8870@code{++}.
8871
8872@item &
8873Address operator. Defined on variables. Same precedence as @code{++}.
8874
b37052ae
EZ
8875For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8876allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8877(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8878where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8879stored.
c906108c
SS
8880
8881@item -
8882Negative. Defined on integral and floating-point types. Same
8883precedence as @code{++}.
8884
8885@item !
8886Logical negation. Defined on integral types. Same precedence as
8887@code{++}.
8888
8889@item ~
8890Bitwise complement operator. Defined on integral types. Same precedence as
8891@code{++}.
8892
8893
8894@item .@r{, }->
8895Structure member, and pointer-to-structure member. For convenience,
8896@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8897pointer based on the stored type information.
8898Defined on @code{struct} and @code{union} data.
8899
c906108c
SS
8900@item .*@r{, }->*
8901Dereferences of pointers to members.
c906108c
SS
8902
8903@item []
8904Array indexing. @code{@var{a}[@var{i}]} is defined as
8905@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8906
8907@item ()
8908Function parameter list. Same precedence as @code{->}.
8909
c906108c 8910@item ::
b37052ae 8911C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8912and @code{class} types.
c906108c
SS
8913
8914@item ::
7a292a7a
SS
8915Doubled colons also represent the @value{GDBN} scope operator
8916(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8917above.
c906108c
SS
8918@end table
8919
c906108c
SS
8920If an operator is redefined in the user code, @value{GDBN} usually
8921attempts to invoke the redefined version instead of using the operator's
8922predefined meaning.
c906108c 8923
c906108c 8924@menu
5d161b24 8925* C Constants::
c906108c
SS
8926@end menu
8927
6d2ebf8b 8928@node C Constants
b37052ae 8929@subsubsection C and C@t{++} constants
c906108c 8930
b37052ae 8931@cindex C and C@t{++} constants
c906108c 8932
b37052ae 8933@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8934following ways:
c906108c
SS
8935
8936@itemize @bullet
8937@item
8938Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8939specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8940by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8941@samp{l}, specifying that the constant should be treated as a
8942@code{long} value.
8943
8944@item
8945Floating point constants are a sequence of digits, followed by a decimal
8946point, followed by a sequence of digits, and optionally followed by an
8947exponent. An exponent is of the form:
8948@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8949sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8950A floating-point constant may also end with a letter @samp{f} or
8951@samp{F}, specifying that the constant should be treated as being of
8952the @code{float} (as opposed to the default @code{double}) type; or with
8953a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8954constant.
c906108c
SS
8955
8956@item
8957Enumerated constants consist of enumerated identifiers, or their
8958integral equivalents.
8959
8960@item
8961Character constants are a single character surrounded by single quotes
8962(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8963(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8964be represented by a letter or by @dfn{escape sequences}, which are of
8965the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8966of the character's ordinal value; or of the form @samp{\@var{x}}, where
8967@samp{@var{x}} is a predefined special character---for example,
8968@samp{\n} for newline.
8969
8970@item
96a2c332
SS
8971String constants are a sequence of character constants surrounded by
8972double quotes (@code{"}). Any valid character constant (as described
8973above) may appear. Double quotes within the string must be preceded by
8974a backslash, so for instance @samp{"a\"b'c"} is a string of five
8975characters.
c906108c
SS
8976
8977@item
8978Pointer constants are an integral value. You can also write pointers
8979to constants using the C operator @samp{&}.
8980
8981@item
8982Array constants are comma-separated lists surrounded by braces @samp{@{}
8983and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8984integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8985and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8986@end itemize
8987
c906108c 8988@menu
5d161b24
DB
8989* C plus plus expressions::
8990* C Defaults::
8991* C Checks::
c906108c 8992
5d161b24 8993* Debugging C::
c906108c
SS
8994@end menu
8995
6d2ebf8b 8996@node C plus plus expressions
b37052ae
EZ
8997@subsubsection C@t{++} expressions
8998
8999@cindex expressions in C@t{++}
9000@value{GDBN} expression handling can interpret most C@t{++} expressions.
9001
0179ffac
DC
9002@cindex debugging C@t{++} programs
9003@cindex C@t{++} compilers
9004@cindex debug formats and C@t{++}
9005@cindex @value{NGCC} and C@t{++}
c906108c 9006@quotation
b37052ae 9007@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
9008proper compiler and the proper debug format. Currently, @value{GDBN}
9009works best when debugging C@t{++} code that is compiled with
9010@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
9011@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
9012stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
9013stabs+ as their default debug format, so you usually don't need to
9014specify a debug format explicitly. Other compilers and/or debug formats
9015are likely to work badly or not at all when using @value{GDBN} to debug
9016C@t{++} code.
c906108c 9017@end quotation
c906108c
SS
9018
9019@enumerate
9020
9021@cindex member functions
9022@item
9023Member function calls are allowed; you can use expressions like
9024
474c8240 9025@smallexample
c906108c 9026count = aml->GetOriginal(x, y)
474c8240 9027@end smallexample
c906108c 9028
41afff9a 9029@vindex this@r{, inside C@t{++} member functions}
b37052ae 9030@cindex namespace in C@t{++}
c906108c
SS
9031@item
9032While a member function is active (in the selected stack frame), your
9033expressions have the same namespace available as the member function;
9034that is, @value{GDBN} allows implicit references to the class instance
b37052ae 9035pointer @code{this} following the same rules as C@t{++}.
c906108c 9036
c906108c 9037@cindex call overloaded functions
d4f3574e 9038@cindex overloaded functions, calling
b37052ae 9039@cindex type conversions in C@t{++}
c906108c
SS
9040@item
9041You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 9042call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
9043perform overload resolution involving user-defined type conversions,
9044calls to constructors, or instantiations of templates that do not exist
9045in the program. It also cannot handle ellipsis argument lists or
9046default arguments.
9047
9048It does perform integral conversions and promotions, floating-point
9049promotions, arithmetic conversions, pointer conversions, conversions of
9050class objects to base classes, and standard conversions such as those of
9051functions or arrays to pointers; it requires an exact match on the
9052number of function arguments.
9053
9054Overload resolution is always performed, unless you have specified
9055@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 9056,@value{GDBN} features for C@t{++}}.
c906108c 9057
d4f3574e 9058You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
9059explicit function signature to call an overloaded function, as in
9060@smallexample
9061p 'foo(char,int)'('x', 13)
9062@end smallexample
d4f3574e 9063
c906108c 9064The @value{GDBN} command-completion facility can simplify this;
d4f3574e 9065see @ref{Completion, ,Command completion}.
c906108c 9066
c906108c
SS
9067@cindex reference declarations
9068@item
b37052ae
EZ
9069@value{GDBN} understands variables declared as C@t{++} references; you can use
9070them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
9071dereferenced.
9072
9073In the parameter list shown when @value{GDBN} displays a frame, the values of
9074reference variables are not displayed (unlike other variables); this
9075avoids clutter, since references are often used for large structures.
9076The @emph{address} of a reference variable is always shown, unless
9077you have specified @samp{set print address off}.
9078
9079@item
b37052ae 9080@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
9081expressions can use it just as expressions in your program do. Since
9082one scope may be defined in another, you can use @code{::} repeatedly if
9083necessary, for example in an expression like
9084@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 9085resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
9086debugging (@pxref{Variables, ,Program variables}).
9087@end enumerate
9088
b37052ae 9089In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
9090calling virtual functions correctly, printing out virtual bases of
9091objects, calling functions in a base subobject, casting objects, and
9092invoking user-defined operators.
c906108c 9093
6d2ebf8b 9094@node C Defaults
b37052ae 9095@subsubsection C and C@t{++} defaults
7a292a7a 9096
b37052ae 9097@cindex C and C@t{++} defaults
c906108c 9098
c906108c
SS
9099If you allow @value{GDBN} to set type and range checking automatically, they
9100both default to @code{off} whenever the working language changes to
b37052ae 9101C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 9102selects the working language.
c906108c
SS
9103
9104If you allow @value{GDBN} to set the language automatically, it
9105recognizes source files whose names end with @file{.c}, @file{.C}, or
9106@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 9107these files, it sets the working language to C or C@t{++}.
c906108c
SS
9108@xref{Automatically, ,Having @value{GDBN} infer the source language},
9109for further details.
9110
c906108c
SS
9111@c Type checking is (a) primarily motivated by Modula-2, and (b)
9112@c unimplemented. If (b) changes, it might make sense to let this node
9113@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 9114
6d2ebf8b 9115@node C Checks
b37052ae 9116@subsubsection C and C@t{++} type and range checks
7a292a7a 9117
b37052ae 9118@cindex C and C@t{++} checks
c906108c 9119
b37052ae 9120By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
9121is not used. However, if you turn type checking on, @value{GDBN}
9122considers two variables type equivalent if:
9123
9124@itemize @bullet
9125@item
9126The two variables are structured and have the same structure, union, or
9127enumerated tag.
9128
9129@item
9130The two variables have the same type name, or types that have been
9131declared equivalent through @code{typedef}.
9132
9133@ignore
9134@c leaving this out because neither J Gilmore nor R Pesch understand it.
9135@c FIXME--beers?
9136@item
9137The two @code{struct}, @code{union}, or @code{enum} variables are
9138declared in the same declaration. (Note: this may not be true for all C
9139compilers.)
9140@end ignore
9141@end itemize
9142
9143Range checking, if turned on, is done on mathematical operations. Array
9144indices are not checked, since they are often used to index a pointer
9145that is not itself an array.
c906108c 9146
6d2ebf8b 9147@node Debugging C
c906108c 9148@subsubsection @value{GDBN} and C
c906108c
SS
9149
9150The @code{set print union} and @code{show print union} commands apply to
9151the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
9152inside a @code{struct} or @code{class} is also printed. Otherwise, it
9153appears as @samp{@{...@}}.
c906108c
SS
9154
9155The @code{@@} operator aids in the debugging of dynamic arrays, formed
9156with pointers and a memory allocation function. @xref{Expressions,
9157,Expressions}.
9158
c906108c 9159@menu
5d161b24 9160* Debugging C plus plus::
c906108c
SS
9161@end menu
9162
6d2ebf8b 9163@node Debugging C plus plus
b37052ae 9164@subsubsection @value{GDBN} features for C@t{++}
c906108c 9165
b37052ae 9166@cindex commands for C@t{++}
7a292a7a 9167
b37052ae
EZ
9168Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
9169designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
9170
9171@table @code
9172@cindex break in overloaded functions
9173@item @r{breakpoint menus}
9174When you want a breakpoint in a function whose name is overloaded,
9175@value{GDBN} breakpoint menus help you specify which function definition
9176you want. @xref{Breakpoint Menus,,Breakpoint menus}.
9177
b37052ae 9178@cindex overloading in C@t{++}
c906108c
SS
9179@item rbreak @var{regex}
9180Setting breakpoints using regular expressions is helpful for setting
9181breakpoints on overloaded functions that are not members of any special
9182classes.
9183@xref{Set Breaks, ,Setting breakpoints}.
9184
b37052ae 9185@cindex C@t{++} exception handling
c906108c
SS
9186@item catch throw
9187@itemx catch catch
b37052ae 9188Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
9189Catchpoints, , Setting catchpoints}.
9190
9191@cindex inheritance
9192@item ptype @var{typename}
9193Print inheritance relationships as well as other information for type
9194@var{typename}.
9195@xref{Symbols, ,Examining the Symbol Table}.
9196
b37052ae 9197@cindex C@t{++} symbol display
c906108c
SS
9198@item set print demangle
9199@itemx show print demangle
9200@itemx set print asm-demangle
9201@itemx show print asm-demangle
b37052ae
EZ
9202Control whether C@t{++} symbols display in their source form, both when
9203displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
9204@xref{Print Settings, ,Print settings}.
9205
9206@item set print object
9207@itemx show print object
9208Choose whether to print derived (actual) or declared types of objects.
9209@xref{Print Settings, ,Print settings}.
9210
9211@item set print vtbl
9212@itemx show print vtbl
9213Control the format for printing virtual function tables.
9214@xref{Print Settings, ,Print settings}.
c906108c 9215(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 9216ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
9217
9218@kindex set overload-resolution
d4f3574e 9219@cindex overloaded functions, overload resolution
c906108c 9220@item set overload-resolution on
b37052ae 9221Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
9222is on. For overloaded functions, @value{GDBN} evaluates the arguments
9223and searches for a function whose signature matches the argument types,
b37052ae 9224using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 9225expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
9226message.
9227
9228@item set overload-resolution off
b37052ae 9229Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
9230overloaded functions that are not class member functions, @value{GDBN}
9231chooses the first function of the specified name that it finds in the
9232symbol table, whether or not its arguments are of the correct type. For
9233overloaded functions that are class member functions, @value{GDBN}
9234searches for a function whose signature @emph{exactly} matches the
9235argument types.
c906108c 9236
9c16f35a
EZ
9237@kindex show overload-resolution
9238@item show overload-resolution
9239Show the current setting of overload resolution.
9240
c906108c
SS
9241@item @r{Overloaded symbol names}
9242You can specify a particular definition of an overloaded symbol, using
b37052ae 9243the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
9244@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
9245also use the @value{GDBN} command-line word completion facilities to list the
9246available choices, or to finish the type list for you.
9247@xref{Completion,, Command completion}, for details on how to do this.
9248@end table
c906108c 9249
b37303ee
AF
9250@node Objective-C
9251@subsection Objective-C
9252
9253@cindex Objective-C
9254This section provides information about some commands and command
721c2651
EZ
9255options that are useful for debugging Objective-C code. See also
9256@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
9257few more commands specific to Objective-C support.
b37303ee
AF
9258
9259@menu
b383017d
RM
9260* Method Names in Commands::
9261* The Print Command with Objective-C::
b37303ee
AF
9262@end menu
9263
9264@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
9265@subsubsection Method Names in Commands
9266
9267The following commands have been extended to accept Objective-C method
9268names as line specifications:
9269
9270@kindex clear@r{, and Objective-C}
9271@kindex break@r{, and Objective-C}
9272@kindex info line@r{, and Objective-C}
9273@kindex jump@r{, and Objective-C}
9274@kindex list@r{, and Objective-C}
9275@itemize
9276@item @code{clear}
9277@item @code{break}
9278@item @code{info line}
9279@item @code{jump}
9280@item @code{list}
9281@end itemize
9282
9283A fully qualified Objective-C method name is specified as
9284
9285@smallexample
9286-[@var{Class} @var{methodName}]
9287@end smallexample
9288
c552b3bb
JM
9289where the minus sign is used to indicate an instance method and a
9290plus sign (not shown) is used to indicate a class method. The class
9291name @var{Class} and method name @var{methodName} are enclosed in
9292brackets, similar to the way messages are specified in Objective-C
9293source code. For example, to set a breakpoint at the @code{create}
9294instance method of class @code{Fruit} in the program currently being
9295debugged, enter:
b37303ee
AF
9296
9297@smallexample
9298break -[Fruit create]
9299@end smallexample
9300
9301To list ten program lines around the @code{initialize} class method,
9302enter:
9303
9304@smallexample
9305list +[NSText initialize]
9306@end smallexample
9307
c552b3bb
JM
9308In the current version of @value{GDBN}, the plus or minus sign is
9309required. In future versions of @value{GDBN}, the plus or minus
9310sign will be optional, but you can use it to narrow the search. It
9311is also possible to specify just a method name:
b37303ee
AF
9312
9313@smallexample
9314break create
9315@end smallexample
9316
9317You must specify the complete method name, including any colons. If
9318your program's source files contain more than one @code{create} method,
9319you'll be presented with a numbered list of classes that implement that
9320method. Indicate your choice by number, or type @samp{0} to exit if
9321none apply.
9322
9323As another example, to clear a breakpoint established at the
9324@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
9325
9326@smallexample
9327clear -[NSWindow makeKeyAndOrderFront:]
9328@end smallexample
9329
9330@node The Print Command with Objective-C
9331@subsubsection The Print Command With Objective-C
721c2651 9332@cindex Objective-C, print objects
c552b3bb
JM
9333@kindex print-object
9334@kindex po @r{(@code{print-object})}
b37303ee 9335
c552b3bb 9336The print command has also been extended to accept methods. For example:
b37303ee
AF
9337
9338@smallexample
c552b3bb 9339print -[@var{object} hash]
b37303ee
AF
9340@end smallexample
9341
9342@cindex print an Objective-C object description
c552b3bb
JM
9343@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
9344@noindent
9345will tell @value{GDBN} to send the @code{hash} message to @var{object}
9346and print the result. Also, an additional command has been added,
9347@code{print-object} or @code{po} for short, which is meant to print
9348the description of an object. However, this command may only work
9349with certain Objective-C libraries that have a particular hook
9350function, @code{_NSPrintForDebugger}, defined.
b37303ee 9351
09d4efe1
EZ
9352@node Fortran
9353@subsection Fortran
9354@cindex Fortran-specific support in @value{GDBN}
9355
814e32d7
WZ
9356@value{GDBN} can be used to debug programs written in Fortran, but it
9357currently supports only the features of Fortran 77 language.
9358
9359@cindex trailing underscore, in Fortran symbols
9360Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
9361among them) append an underscore to the names of variables and
9362functions. When you debug programs compiled by those compilers, you
9363will need to refer to variables and functions with a trailing
9364underscore.
9365
9366@menu
9367* Fortran Operators:: Fortran operators and expressions
9368* Fortran Defaults:: Default settings for Fortran
9369* Special Fortran commands:: Special @value{GDBN} commands for Fortran
9370@end menu
9371
9372@node Fortran Operators
9373@subsubsection Fortran operators and expressions
9374
9375@cindex Fortran operators and expressions
9376
9377Operators must be defined on values of specific types. For instance,
9378@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 9379arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
9380
9381@table @code
9382@item **
9383The exponentiation operator. It raises the first operand to the power
9384of the second one.
9385
9386@item :
9387The range operator. Normally used in the form of array(low:high) to
9388represent a section of array.
9389@end table
9390
9391@node Fortran Defaults
9392@subsubsection Fortran Defaults
9393
9394@cindex Fortran Defaults
9395
9396Fortran symbols are usually case-insensitive, so @value{GDBN} by
9397default uses case-insensitive matches for Fortran symbols. You can
9398change that with the @samp{set case-insensitive} command, see
9399@ref{Symbols}, for the details.
9400
9401@node Special Fortran commands
9402@subsubsection Special Fortran commands
9403
9404@cindex Special Fortran commands
9405
9406@value{GDBN} had some commands to support Fortran specific feature,
9407such as common block displaying.
9408
09d4efe1
EZ
9409@table @code
9410@cindex @code{COMMON} blocks, Fortran
9411@kindex info common
9412@item info common @r{[}@var{common-name}@r{]}
9413This command prints the values contained in the Fortran @code{COMMON}
9414block whose name is @var{common-name}. With no argument, the names of
9415all @code{COMMON} blocks visible at current program location are
9416printed.
9417@end table
9418
9c16f35a
EZ
9419@node Pascal
9420@subsection Pascal
9421
9422@cindex Pascal support in @value{GDBN}, limitations
9423Debugging Pascal programs which use sets, subranges, file variables, or
9424nested functions does not currently work. @value{GDBN} does not support
9425entering expressions, printing values, or similar features using Pascal
9426syntax.
9427
9428The Pascal-specific command @code{set print pascal_static-members}
9429controls whether static members of Pascal objects are displayed.
9430@xref{Print Settings, pascal_static-members}.
9431
09d4efe1 9432@node Modula-2
c906108c 9433@subsection Modula-2
7a292a7a 9434
d4f3574e 9435@cindex Modula-2, @value{GDBN} support
c906108c
SS
9436
9437The extensions made to @value{GDBN} to support Modula-2 only support
9438output from the @sc{gnu} Modula-2 compiler (which is currently being
9439developed). Other Modula-2 compilers are not currently supported, and
9440attempting to debug executables produced by them is most likely
9441to give an error as @value{GDBN} reads in the executable's symbol
9442table.
9443
9444@cindex expressions in Modula-2
9445@menu
9446* M2 Operators:: Built-in operators
9447* Built-In Func/Proc:: Built-in functions and procedures
9448* M2 Constants:: Modula-2 constants
9449* M2 Defaults:: Default settings for Modula-2
9450* Deviations:: Deviations from standard Modula-2
9451* M2 Checks:: Modula-2 type and range checks
9452* M2 Scope:: The scope operators @code{::} and @code{.}
9453* GDB/M2:: @value{GDBN} and Modula-2
9454@end menu
9455
6d2ebf8b 9456@node M2 Operators
c906108c
SS
9457@subsubsection Operators
9458@cindex Modula-2 operators
9459
9460Operators must be defined on values of specific types. For instance,
9461@code{+} is defined on numbers, but not on structures. Operators are
9462often defined on groups of types. For the purposes of Modula-2, the
9463following definitions hold:
9464
9465@itemize @bullet
9466
9467@item
9468@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
9469their subranges.
9470
9471@item
9472@emph{Character types} consist of @code{CHAR} and its subranges.
9473
9474@item
9475@emph{Floating-point types} consist of @code{REAL}.
9476
9477@item
9478@emph{Pointer types} consist of anything declared as @code{POINTER TO
9479@var{type}}.
9480
9481@item
9482@emph{Scalar types} consist of all of the above.
9483
9484@item
9485@emph{Set types} consist of @code{SET} and @code{BITSET} types.
9486
9487@item
9488@emph{Boolean types} consist of @code{BOOLEAN}.
9489@end itemize
9490
9491@noindent
9492The following operators are supported, and appear in order of
9493increasing precedence:
9494
9495@table @code
9496@item ,
9497Function argument or array index separator.
9498
9499@item :=
9500Assignment. The value of @var{var} @code{:=} @var{value} is
9501@var{value}.
9502
9503@item <@r{, }>
9504Less than, greater than on integral, floating-point, or enumerated
9505types.
9506
9507@item <=@r{, }>=
96a2c332 9508Less than or equal to, greater than or equal to
c906108c
SS
9509on integral, floating-point and enumerated types, or set inclusion on
9510set types. Same precedence as @code{<}.
9511
9512@item =@r{, }<>@r{, }#
9513Equality and two ways of expressing inequality, valid on scalar types.
9514Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9515available for inequality, since @code{#} conflicts with the script
9516comment character.
9517
9518@item IN
9519Set membership. Defined on set types and the types of their members.
9520Same precedence as @code{<}.
9521
9522@item OR
9523Boolean disjunction. Defined on boolean types.
9524
9525@item AND@r{, }&
d4f3574e 9526Boolean conjunction. Defined on boolean types.
c906108c
SS
9527
9528@item @@
9529The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9530
9531@item +@r{, }-
9532Addition and subtraction on integral and floating-point types, or union
9533and difference on set types.
9534
9535@item *
9536Multiplication on integral and floating-point types, or set intersection
9537on set types.
9538
9539@item /
9540Division on floating-point types, or symmetric set difference on set
9541types. Same precedence as @code{*}.
9542
9543@item DIV@r{, }MOD
9544Integer division and remainder. Defined on integral types. Same
9545precedence as @code{*}.
9546
9547@item -
9548Negative. Defined on @code{INTEGER} and @code{REAL} data.
9549
9550@item ^
9551Pointer dereferencing. Defined on pointer types.
9552
9553@item NOT
9554Boolean negation. Defined on boolean types. Same precedence as
9555@code{^}.
9556
9557@item .
9558@code{RECORD} field selector. Defined on @code{RECORD} data. Same
9559precedence as @code{^}.
9560
9561@item []
9562Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
9563
9564@item ()
9565Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
9566as @code{^}.
9567
9568@item ::@r{, }.
9569@value{GDBN} and Modula-2 scope operators.
9570@end table
9571
9572@quotation
9573@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
9574treats the use of the operator @code{IN}, or the use of operators
9575@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
9576@code{<=}, and @code{>=} on sets as an error.
9577@end quotation
9578
cb51c4e0 9579
6d2ebf8b 9580@node Built-In Func/Proc
c906108c 9581@subsubsection Built-in functions and procedures
cb51c4e0 9582@cindex Modula-2 built-ins
c906108c
SS
9583
9584Modula-2 also makes available several built-in procedures and functions.
9585In describing these, the following metavariables are used:
9586
9587@table @var
9588
9589@item a
9590represents an @code{ARRAY} variable.
9591
9592@item c
9593represents a @code{CHAR} constant or variable.
9594
9595@item i
9596represents a variable or constant of integral type.
9597
9598@item m
9599represents an identifier that belongs to a set. Generally used in the
9600same function with the metavariable @var{s}. The type of @var{s} should
9601be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
9602
9603@item n
9604represents a variable or constant of integral or floating-point type.
9605
9606@item r
9607represents a variable or constant of floating-point type.
9608
9609@item t
9610represents a type.
9611
9612@item v
9613represents a variable.
9614
9615@item x
9616represents a variable or constant of one of many types. See the
9617explanation of the function for details.
9618@end table
9619
9620All Modula-2 built-in procedures also return a result, described below.
9621
9622@table @code
9623@item ABS(@var{n})
9624Returns the absolute value of @var{n}.
9625
9626@item CAP(@var{c})
9627If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 9628equivalent, otherwise it returns its argument.
c906108c
SS
9629
9630@item CHR(@var{i})
9631Returns the character whose ordinal value is @var{i}.
9632
9633@item DEC(@var{v})
c3f6f71d 9634Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9635
9636@item DEC(@var{v},@var{i})
9637Decrements the value in the variable @var{v} by @var{i}. Returns the
9638new value.
9639
9640@item EXCL(@var{m},@var{s})
9641Removes the element @var{m} from the set @var{s}. Returns the new
9642set.
9643
9644@item FLOAT(@var{i})
9645Returns the floating point equivalent of the integer @var{i}.
9646
9647@item HIGH(@var{a})
9648Returns the index of the last member of @var{a}.
9649
9650@item INC(@var{v})
c3f6f71d 9651Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9652
9653@item INC(@var{v},@var{i})
9654Increments the value in the variable @var{v} by @var{i}. Returns the
9655new value.
9656
9657@item INCL(@var{m},@var{s})
9658Adds the element @var{m} to the set @var{s} if it is not already
9659there. Returns the new set.
9660
9661@item MAX(@var{t})
9662Returns the maximum value of the type @var{t}.
9663
9664@item MIN(@var{t})
9665Returns the minimum value of the type @var{t}.
9666
9667@item ODD(@var{i})
9668Returns boolean TRUE if @var{i} is an odd number.
9669
9670@item ORD(@var{x})
9671Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
9672value of a character is its @sc{ascii} value (on machines supporting the
9673@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
9674integral, character and enumerated types.
9675
9676@item SIZE(@var{x})
9677Returns the size of its argument. @var{x} can be a variable or a type.
9678
9679@item TRUNC(@var{r})
9680Returns the integral part of @var{r}.
9681
9682@item VAL(@var{t},@var{i})
9683Returns the member of the type @var{t} whose ordinal value is @var{i}.
9684@end table
9685
9686@quotation
9687@emph{Warning:} Sets and their operations are not yet supported, so
9688@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
9689an error.
9690@end quotation
9691
9692@cindex Modula-2 constants
6d2ebf8b 9693@node M2 Constants
c906108c
SS
9694@subsubsection Constants
9695
9696@value{GDBN} allows you to express the constants of Modula-2 in the following
9697ways:
9698
9699@itemize @bullet
9700
9701@item
9702Integer constants are simply a sequence of digits. When used in an
9703expression, a constant is interpreted to be type-compatible with the
9704rest of the expression. Hexadecimal integers are specified by a
9705trailing @samp{H}, and octal integers by a trailing @samp{B}.
9706
9707@item
9708Floating point constants appear as a sequence of digits, followed by a
9709decimal point and another sequence of digits. An optional exponent can
9710then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
9711@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
9712digits of the floating point constant must be valid decimal (base 10)
9713digits.
9714
9715@item
9716Character constants consist of a single character enclosed by a pair of
9717like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 9718also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
9719followed by a @samp{C}.
9720
9721@item
9722String constants consist of a sequence of characters enclosed by a
9723pair of like quotes, either single (@code{'}) or double (@code{"}).
9724Escape sequences in the style of C are also allowed. @xref{C
b37052ae 9725Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
9726sequences.
9727
9728@item
9729Enumerated constants consist of an enumerated identifier.
9730
9731@item
9732Boolean constants consist of the identifiers @code{TRUE} and
9733@code{FALSE}.
9734
9735@item
9736Pointer constants consist of integral values only.
9737
9738@item
9739Set constants are not yet supported.
9740@end itemize
9741
6d2ebf8b 9742@node M2 Defaults
c906108c
SS
9743@subsubsection Modula-2 defaults
9744@cindex Modula-2 defaults
9745
9746If type and range checking are set automatically by @value{GDBN}, they
9747both default to @code{on} whenever the working language changes to
d4f3574e 9748Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
9749selected the working language.
9750
9751If you allow @value{GDBN} to set the language automatically, then entering
9752code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 9753working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
9754the language automatically}, for further details.
9755
6d2ebf8b 9756@node Deviations
c906108c
SS
9757@subsubsection Deviations from standard Modula-2
9758@cindex Modula-2, deviations from
9759
9760A few changes have been made to make Modula-2 programs easier to debug.
9761This is done primarily via loosening its type strictness:
9762
9763@itemize @bullet
9764@item
9765Unlike in standard Modula-2, pointer constants can be formed by
9766integers. This allows you to modify pointer variables during
9767debugging. (In standard Modula-2, the actual address contained in a
9768pointer variable is hidden from you; it can only be modified
9769through direct assignment to another pointer variable or expression that
9770returned a pointer.)
9771
9772@item
9773C escape sequences can be used in strings and characters to represent
9774non-printable characters. @value{GDBN} prints out strings with these
9775escape sequences embedded. Single non-printable characters are
9776printed using the @samp{CHR(@var{nnn})} format.
9777
9778@item
9779The assignment operator (@code{:=}) returns the value of its right-hand
9780argument.
9781
9782@item
9783All built-in procedures both modify @emph{and} return their argument.
9784@end itemize
9785
6d2ebf8b 9786@node M2 Checks
c906108c
SS
9787@subsubsection Modula-2 type and range checks
9788@cindex Modula-2 checks
9789
9790@quotation
9791@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9792range checking.
9793@end quotation
9794@c FIXME remove warning when type/range checks added
9795
9796@value{GDBN} considers two Modula-2 variables type equivalent if:
9797
9798@itemize @bullet
9799@item
9800They are of types that have been declared equivalent via a @code{TYPE
9801@var{t1} = @var{t2}} statement
9802
9803@item
9804They have been declared on the same line. (Note: This is true of the
9805@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9806@end itemize
9807
9808As long as type checking is enabled, any attempt to combine variables
9809whose types are not equivalent is an error.
9810
9811Range checking is done on all mathematical operations, assignment, array
9812index bounds, and all built-in functions and procedures.
9813
6d2ebf8b 9814@node M2 Scope
c906108c
SS
9815@subsubsection The scope operators @code{::} and @code{.}
9816@cindex scope
41afff9a 9817@cindex @code{.}, Modula-2 scope operator
c906108c
SS
9818@cindex colon, doubled as scope operator
9819@ifinfo
41afff9a 9820@vindex colon-colon@r{, in Modula-2}
c906108c
SS
9821@c Info cannot handle :: but TeX can.
9822@end ifinfo
9823@iftex
41afff9a 9824@vindex ::@r{, in Modula-2}
c906108c
SS
9825@end iftex
9826
9827There are a few subtle differences between the Modula-2 scope operator
9828(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9829similar syntax:
9830
474c8240 9831@smallexample
c906108c
SS
9832
9833@var{module} . @var{id}
9834@var{scope} :: @var{id}
474c8240 9835@end smallexample
c906108c
SS
9836
9837@noindent
9838where @var{scope} is the name of a module or a procedure,
9839@var{module} the name of a module, and @var{id} is any declared
9840identifier within your program, except another module.
9841
9842Using the @code{::} operator makes @value{GDBN} search the scope
9843specified by @var{scope} for the identifier @var{id}. If it is not
9844found in the specified scope, then @value{GDBN} searches all scopes
9845enclosing the one specified by @var{scope}.
9846
9847Using the @code{.} operator makes @value{GDBN} search the current scope for
9848the identifier specified by @var{id} that was imported from the
9849definition module specified by @var{module}. With this operator, it is
9850an error if the identifier @var{id} was not imported from definition
9851module @var{module}, or if @var{id} is not an identifier in
9852@var{module}.
9853
6d2ebf8b 9854@node GDB/M2
c906108c
SS
9855@subsubsection @value{GDBN} and Modula-2
9856
9857Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9858Five subcommands of @code{set print} and @code{show print} apply
b37052ae 9859specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 9860@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 9861apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
9862analogue in Modula-2.
9863
9864The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 9865with any language, is not useful with Modula-2. Its
c906108c 9866intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 9867created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 9868address can be specified by an integral constant, the construct
d4f3574e 9869@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
9870
9871@cindex @code{#} in Modula-2
9872In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9873interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 9874
e07c999f
PH
9875@node Ada
9876@subsection Ada
9877@cindex Ada
9878
9879The extensions made to @value{GDBN} for Ada only support
9880output from the @sc{gnu} Ada (GNAT) compiler.
9881Other Ada compilers are not currently supported, and
9882attempting to debug executables produced by them is most likely
9883to be difficult.
9884
9885
9886@cindex expressions in Ada
9887@menu
9888* Ada Mode Intro:: General remarks on the Ada syntax
9889 and semantics supported by Ada mode
9890 in @value{GDBN}.
9891* Omissions from Ada:: Restrictions on the Ada expression syntax.
9892* Additions to Ada:: Extensions of the Ada expression syntax.
9893* Stopping Before Main Program:: Debugging the program during elaboration.
9894* Ada Glitches:: Known peculiarities of Ada mode.
9895@end menu
9896
9897@node Ada Mode Intro
9898@subsubsection Introduction
9899@cindex Ada mode, general
9900
9901The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9902syntax, with some extensions.
9903The philosophy behind the design of this subset is
9904
9905@itemize @bullet
9906@item
9907That @value{GDBN} should provide basic literals and access to operations for
9908arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9909leaving more sophisticated computations to subprograms written into the
9910program (which therefore may be called from @value{GDBN}).
9911
9912@item
9913That type safety and strict adherence to Ada language restrictions
9914are not particularly important to the @value{GDBN} user.
9915
9916@item
9917That brevity is important to the @value{GDBN} user.
9918@end itemize
9919
9920Thus, for brevity, the debugger acts as if there were
9921implicit @code{with} and @code{use} clauses in effect for all user-written
9922packages, making it unnecessary to fully qualify most names with
9923their packages, regardless of context. Where this causes ambiguity,
9924@value{GDBN} asks the user's intent.
9925
9926The debugger will start in Ada mode if it detects an Ada main program.
9927As for other languages, it will enter Ada mode when stopped in a program that
9928was translated from an Ada source file.
9929
9930While in Ada mode, you may use `@t{--}' for comments. This is useful
9931mostly for documenting command files. The standard @value{GDBN} comment
9932(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9933middle (to allow based literals).
9934
9935The debugger supports limited overloading. Given a subprogram call in which
9936the function symbol has multiple definitions, it will use the number of
9937actual parameters and some information about their types to attempt to narrow
9938the set of definitions. It also makes very limited use of context, preferring
9939procedures to functions in the context of the @code{call} command, and
9940functions to procedures elsewhere.
9941
9942@node Omissions from Ada
9943@subsubsection Omissions from Ada
9944@cindex Ada, omissions from
9945
9946Here are the notable omissions from the subset:
9947
9948@itemize @bullet
9949@item
9950Only a subset of the attributes are supported:
9951
9952@itemize @minus
9953@item
9954@t{'First}, @t{'Last}, and @t{'Length}
9955 on array objects (not on types and subtypes).
9956
9957@item
9958@t{'Min} and @t{'Max}.
9959
9960@item
9961@t{'Pos} and @t{'Val}.
9962
9963@item
9964@t{'Tag}.
9965
9966@item
9967@t{'Range} on array objects (not subtypes), but only as the right
9968operand of the membership (@code{in}) operator.
9969
9970@item
9971@t{'Access}, @t{'Unchecked_Access}, and
9972@t{'Unrestricted_Access} (a GNAT extension).
9973
9974@item
9975@t{'Address}.
9976@end itemize
9977
9978@item
9979The names in
9980@code{Characters.Latin_1} are not available and
9981concatenation is not implemented. Thus, escape characters in strings are
9982not currently available.
9983
9984@item
9985Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9986equality of representations. They will generally work correctly
9987for strings and arrays whose elements have integer or enumeration types.
9988They may not work correctly for arrays whose element
9989types have user-defined equality, for arrays of real values
9990(in particular, IEEE-conformant floating point, because of negative
9991zeroes and NaNs), and for arrays whose elements contain unused bits with
9992indeterminate values.
9993
9994@item
9995The other component-by-component array operations (@code{and}, @code{or},
9996@code{xor}, @code{not}, and relational tests other than equality)
9997are not implemented.
9998
9999@item
860701dc
PH
10000@cindex array aggregates (Ada)
10001@cindex record aggregates (Ada)
10002@cindex aggregates (Ada)
10003There is limited support for array and record aggregates. They are
10004permitted only on the right sides of assignments, as in these examples:
10005
10006@smallexample
10007set An_Array := (1, 2, 3, 4, 5, 6)
10008set An_Array := (1, others => 0)
10009set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
10010set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
10011set A_Record := (1, "Peter", True);
10012set A_Record := (Name => "Peter", Id => 1, Alive => True)
10013@end smallexample
10014
10015Changing a
10016discriminant's value by assigning an aggregate has an
10017undefined effect if that discriminant is used within the record.
10018However, you can first modify discriminants by directly assigning to
10019them (which normally would not be allowed in Ada), and then performing an
10020aggregate assignment. For example, given a variable @code{A_Rec}
10021declared to have a type such as:
10022
10023@smallexample
10024type Rec (Len : Small_Integer := 0) is record
10025 Id : Integer;
10026 Vals : IntArray (1 .. Len);
10027end record;
10028@end smallexample
10029
10030you can assign a value with a different size of @code{Vals} with two
10031assignments:
10032
10033@smallexample
10034set A_Rec.Len := 4
10035set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
10036@end smallexample
10037
10038As this example also illustrates, @value{GDBN} is very loose about the usual
10039rules concerning aggregates. You may leave out some of the
10040components of an array or record aggregate (such as the @code{Len}
10041component in the assignment to @code{A_Rec} above); they will retain their
10042original values upon assignment. You may freely use dynamic values as
10043indices in component associations. You may even use overlapping or
10044redundant component associations, although which component values are
10045assigned in such cases is not defined.
e07c999f
PH
10046
10047@item
10048Calls to dispatching subprograms are not implemented.
10049
10050@item
10051The overloading algorithm is much more limited (i.e., less selective)
10052than that of real Ada. It makes only limited use of the context in which a subexpression
10053appears to resolve its meaning, and it is much looser in its rules for allowing
10054type matches. As a result, some function calls will be ambiguous, and the user
10055will be asked to choose the proper resolution.
10056
10057@item
10058The @code{new} operator is not implemented.
10059
10060@item
10061Entry calls are not implemented.
10062
10063@item
10064Aside from printing, arithmetic operations on the native VAX floating-point
10065formats are not supported.
10066
10067@item
10068It is not possible to slice a packed array.
10069@end itemize
10070
10071@node Additions to Ada
10072@subsubsection Additions to Ada
10073@cindex Ada, deviations from
10074
10075As it does for other languages, @value{GDBN} makes certain generic
10076extensions to Ada (@pxref{Expressions}):
10077
10078@itemize @bullet
10079@item
10080If the expression @var{E} is a variable residing in memory
10081(typically a local variable or array element) and @var{N} is
10082a positive integer, then @code{@var{E}@@@var{N}} displays the values of
10083@var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
10084In Ada, this operator is generally not necessary, since its prime use
10085is in displaying parts of an array, and slicing will usually do this in Ada.
10086However, there are occasional uses when debugging programs
10087in which certain debugging information has been optimized away.
10088
10089@item
10090@code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
10091in function or file @var{B}.'' When @var{B} is a file name, you must typically
10092surround it in single quotes.
10093
10094@item
10095The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
10096@var{type} that appears at address @var{addr}.''
10097
10098@item
10099A name starting with @samp{$} is a convenience variable
10100(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
10101@end itemize
10102
10103In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
10104to Ada:
10105
10106@itemize @bullet
10107@item
10108The assignment statement is allowed as an expression, returning
10109its right-hand operand as its value. Thus, you may enter
10110
10111@smallexample
10112set x := y + 3
10113print A(tmp := y + 1)
10114@end smallexample
10115
10116@item
10117The semicolon is allowed as an ``operator,'' returning as its value
10118the value of its right-hand operand.
10119This allows, for example,
10120complex conditional breaks:
10121
10122@smallexample
10123break f
10124condition 1 (report(i); k += 1; A(k) > 100)
10125@end smallexample
10126
10127@item
10128Rather than use catenation and symbolic character names to introduce special
10129characters into strings, one may instead use a special bracket notation,
10130which is also used to print strings. A sequence of characters of the form
10131@samp{["@var{XX}"]} within a string or character literal denotes the
10132(single) character whose numeric encoding is @var{XX} in hexadecimal. The
10133sequence of characters @samp{["""]} also denotes a single quotation mark
10134in strings. For example,
10135@smallexample
10136 "One line.["0a"]Next line.["0a"]"
10137@end smallexample
10138@noindent
10139contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
10140period.
10141
10142@item
10143The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
10144@t{'Max} is optional (and is ignored in any case). For example, it is valid
10145to write
10146
10147@smallexample
10148print 'max(x, y)
10149@end smallexample
10150
10151@item
10152When printing arrays, @value{GDBN} uses positional notation when the
10153array has a lower bound of 1, and uses a modified named notation otherwise.
10154For example, a one-dimensional array of three integers with a lower bound of 3 might print as
10155
10156@smallexample
10157(3 => 10, 17, 1)
10158@end smallexample
10159
10160@noindent
10161That is, in contrast to valid Ada, only the first component has a @code{=>}
10162clause.
10163
10164@item
10165You may abbreviate attributes in expressions with any unique,
10166multi-character subsequence of
10167their names (an exact match gets preference).
10168For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
10169in place of @t{a'length}.
10170
10171@item
10172@cindex quoting Ada internal identifiers
10173Since Ada is case-insensitive, the debugger normally maps identifiers you type
10174to lower case. The GNAT compiler uses upper-case characters for
10175some of its internal identifiers, which are normally of no interest to users.
10176For the rare occasions when you actually have to look at them,
10177enclose them in angle brackets to avoid the lower-case mapping.
10178For example,
10179@smallexample
10180@value{GDBP} print <JMPBUF_SAVE>[0]
10181@end smallexample
10182
10183@item
10184Printing an object of class-wide type or dereferencing an
10185access-to-class-wide value will display all the components of the object's
10186specific type (as indicated by its run-time tag). Likewise, component
10187selection on such a value will operate on the specific type of the
10188object.
10189
10190@end itemize
10191
10192@node Stopping Before Main Program
10193@subsubsection Stopping at the Very Beginning
10194
10195@cindex breakpointing Ada elaboration code
10196It is sometimes necessary to debug the program during elaboration, and
10197before reaching the main procedure.
10198As defined in the Ada Reference
10199Manual, the elaboration code is invoked from a procedure called
10200@code{adainit}. To run your program up to the beginning of
10201elaboration, simply use the following two commands:
10202@code{tbreak adainit} and @code{run}.
10203
10204@node Ada Glitches
10205@subsubsection Known Peculiarities of Ada Mode
10206@cindex Ada, problems
10207
10208Besides the omissions listed previously (@pxref{Omissions from Ada}),
10209we know of several problems with and limitations of Ada mode in
10210@value{GDBN},
10211some of which will be fixed with planned future releases of the debugger
10212and the GNU Ada compiler.
10213
10214@itemize @bullet
10215@item
10216Currently, the debugger
10217has insufficient information to determine whether certain pointers represent
10218pointers to objects or the objects themselves.
10219Thus, the user may have to tack an extra @code{.all} after an expression
10220to get it printed properly.
10221
10222@item
10223Static constants that the compiler chooses not to materialize as objects in
10224storage are invisible to the debugger.
10225
10226@item
10227Named parameter associations in function argument lists are ignored (the
10228argument lists are treated as positional).
10229
10230@item
10231Many useful library packages are currently invisible to the debugger.
10232
10233@item
10234Fixed-point arithmetic, conversions, input, and output is carried out using
10235floating-point arithmetic, and may give results that only approximate those on
10236the host machine.
10237
10238@item
10239The type of the @t{'Address} attribute may not be @code{System.Address}.
10240
10241@item
10242The GNAT compiler never generates the prefix @code{Standard} for any of
10243the standard symbols defined by the Ada language. @value{GDBN} knows about
10244this: it will strip the prefix from names when you use it, and will never
10245look for a name you have so qualified among local symbols, nor match against
10246symbols in other packages or subprograms. If you have
10247defined entities anywhere in your program other than parameters and
10248local variables whose simple names match names in @code{Standard},
10249GNAT's lack of qualification here can cause confusion. When this happens,
10250you can usually resolve the confusion
10251by qualifying the problematic names with package
10252@code{Standard} explicitly.
10253@end itemize
10254
4e562065
JB
10255@node Unsupported languages
10256@section Unsupported languages
10257
10258@cindex unsupported languages
10259@cindex minimal language
10260In addition to the other fully-supported programming languages,
10261@value{GDBN} also provides a pseudo-language, called @code{minimal}.
10262It does not represent a real programming language, but provides a set
10263of capabilities close to what the C or assembly languages provide.
10264This should allow most simple operations to be performed while debugging
10265an application that uses a language currently not supported by @value{GDBN}.
10266
10267If the language is set to @code{auto}, @value{GDBN} will automatically
10268select this language if the current frame corresponds to an unsupported
10269language.
10270
6d2ebf8b 10271@node Symbols
c906108c
SS
10272@chapter Examining the Symbol Table
10273
d4f3574e 10274The commands described in this chapter allow you to inquire about the
c906108c
SS
10275symbols (names of variables, functions and types) defined in your
10276program. This information is inherent in the text of your program and
10277does not change as your program executes. @value{GDBN} finds it in your
10278program's symbol table, in the file indicated when you started @value{GDBN}
10279(@pxref{File Options, ,Choosing files}), or by one of the
10280file-management commands (@pxref{Files, ,Commands to specify files}).
10281
10282@cindex symbol names
10283@cindex names of symbols
10284@cindex quoting names
10285Occasionally, you may need to refer to symbols that contain unusual
10286characters, which @value{GDBN} ordinarily treats as word delimiters. The
10287most frequent case is in referring to static variables in other
10288source files (@pxref{Variables,,Program variables}). File names
10289are recorded in object files as debugging symbols, but @value{GDBN} would
10290ordinarily parse a typical file name, like @file{foo.c}, as the three words
10291@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
10292@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
10293
474c8240 10294@smallexample
c906108c 10295p 'foo.c'::x
474c8240 10296@end smallexample
c906108c
SS
10297
10298@noindent
10299looks up the value of @code{x} in the scope of the file @file{foo.c}.
10300
10301@table @code
a8f24a35
EZ
10302@cindex case-insensitive symbol names
10303@cindex case sensitivity in symbol names
10304@kindex set case-sensitive
10305@item set case-sensitive on
10306@itemx set case-sensitive off
10307@itemx set case-sensitive auto
10308Normally, when @value{GDBN} looks up symbols, it matches their names
10309with case sensitivity determined by the current source language.
10310Occasionally, you may wish to control that. The command @code{set
10311case-sensitive} lets you do that by specifying @code{on} for
10312case-sensitive matches or @code{off} for case-insensitive ones. If
10313you specify @code{auto}, case sensitivity is reset to the default
10314suitable for the source language. The default is case-sensitive
10315matches for all languages except for Fortran, for which the default is
10316case-insensitive matches.
10317
9c16f35a
EZ
10318@kindex show case-sensitive
10319@item show case-sensitive
a8f24a35
EZ
10320This command shows the current setting of case sensitivity for symbols
10321lookups.
10322
c906108c 10323@kindex info address
b37052ae 10324@cindex address of a symbol
c906108c
SS
10325@item info address @var{symbol}
10326Describe where the data for @var{symbol} is stored. For a register
10327variable, this says which register it is kept in. For a non-register
10328local variable, this prints the stack-frame offset at which the variable
10329is always stored.
10330
10331Note the contrast with @samp{print &@var{symbol}}, which does not work
10332at all for a register variable, and for a stack local variable prints
10333the exact address of the current instantiation of the variable.
10334
3d67e040 10335@kindex info symbol
b37052ae 10336@cindex symbol from address
9c16f35a 10337@cindex closest symbol and offset for an address
3d67e040
EZ
10338@item info symbol @var{addr}
10339Print the name of a symbol which is stored at the address @var{addr}.
10340If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
10341nearest symbol and an offset from it:
10342
474c8240 10343@smallexample
3d67e040
EZ
10344(@value{GDBP}) info symbol 0x54320
10345_initialize_vx + 396 in section .text
474c8240 10346@end smallexample
3d67e040
EZ
10347
10348@noindent
10349This is the opposite of the @code{info address} command. You can use
10350it to find out the name of a variable or a function given its address.
10351
c906108c 10352@kindex whatis
d4f3574e
SS
10353@item whatis @var{expr}
10354Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
10355actually evaluated, and any side-effecting operations (such as
10356assignments or function calls) inside it do not take place.
10357@xref{Expressions, ,Expressions}.
10358
10359@item whatis
10360Print the data type of @code{$}, the last value in the value history.
10361
10362@kindex ptype
10363@item ptype @var{typename}
10364Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
10365the name of a type, or for C code it may have the form @samp{class
10366@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
10367@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 10368
d4f3574e 10369@item ptype @var{expr}
c906108c 10370@itemx ptype
d4f3574e 10371Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
10372differs from @code{whatis} by printing a detailed description, instead
10373of just the name of the type.
10374
10375For example, for this variable declaration:
10376
474c8240 10377@smallexample
c906108c 10378struct complex @{double real; double imag;@} v;
474c8240 10379@end smallexample
c906108c
SS
10380
10381@noindent
10382the two commands give this output:
10383
474c8240 10384@smallexample
c906108c
SS
10385@group
10386(@value{GDBP}) whatis v
10387type = struct complex
10388(@value{GDBP}) ptype v
10389type = struct complex @{
10390 double real;
10391 double imag;
10392@}
10393@end group
474c8240 10394@end smallexample
c906108c
SS
10395
10396@noindent
10397As with @code{whatis}, using @code{ptype} without an argument refers to
10398the type of @code{$}, the last value in the value history.
10399
ab1adacd
EZ
10400@cindex incomplete type
10401Sometimes, programs use opaque data types or incomplete specifications
10402of complex data structure. If the debug information included in the
10403program does not allow @value{GDBN} to display a full declaration of
10404the data type, it will say @samp{<incomplete type>}. For example,
10405given these declarations:
10406
10407@smallexample
10408 struct foo;
10409 struct foo *fooptr;
10410@end smallexample
10411
10412@noindent
10413but no definition for @code{struct foo} itself, @value{GDBN} will say:
10414
10415@smallexample
10416 (gdb) ptype foo
10417 $1 = <incomplete type>
10418@end smallexample
10419
10420@noindent
10421``Incomplete type'' is C terminology for data types that are not
10422completely specified.
10423
c906108c
SS
10424@kindex info types
10425@item info types @var{regexp}
10426@itemx info types
09d4efe1
EZ
10427Print a brief description of all types whose names match the regular
10428expression @var{regexp} (or all types in your program, if you supply
10429no argument). Each complete typename is matched as though it were a
10430complete line; thus, @samp{i type value} gives information on all
10431types in your program whose names include the string @code{value}, but
10432@samp{i type ^value$} gives information only on types whose complete
10433name is @code{value}.
c906108c
SS
10434
10435This command differs from @code{ptype} in two ways: first, like
10436@code{whatis}, it does not print a detailed description; second, it
10437lists all source files where a type is defined.
10438
b37052ae
EZ
10439@kindex info scope
10440@cindex local variables
09d4efe1 10441@item info scope @var{location}
b37052ae 10442List all the variables local to a particular scope. This command
09d4efe1
EZ
10443accepts a @var{location} argument---a function name, a source line, or
10444an address preceded by a @samp{*}, and prints all the variables local
10445to the scope defined by that location. For example:
b37052ae
EZ
10446
10447@smallexample
10448(@value{GDBP}) @b{info scope command_line_handler}
10449Scope for command_line_handler:
10450Symbol rl is an argument at stack/frame offset 8, length 4.
10451Symbol linebuffer is in static storage at address 0x150a18, length 4.
10452Symbol linelength is in static storage at address 0x150a1c, length 4.
10453Symbol p is a local variable in register $esi, length 4.
10454Symbol p1 is a local variable in register $ebx, length 4.
10455Symbol nline is a local variable in register $edx, length 4.
10456Symbol repeat is a local variable at frame offset -8, length 4.
10457@end smallexample
10458
f5c37c66
EZ
10459@noindent
10460This command is especially useful for determining what data to collect
10461during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
10462collect}.
10463
c906108c
SS
10464@kindex info source
10465@item info source
919d772c
JB
10466Show information about the current source file---that is, the source file for
10467the function containing the current point of execution:
10468@itemize @bullet
10469@item
10470the name of the source file, and the directory containing it,
10471@item
10472the directory it was compiled in,
10473@item
10474its length, in lines,
10475@item
10476which programming language it is written in,
10477@item
10478whether the executable includes debugging information for that file, and
10479if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
10480@item
10481whether the debugging information includes information about
10482preprocessor macros.
10483@end itemize
10484
c906108c
SS
10485
10486@kindex info sources
10487@item info sources
10488Print the names of all source files in your program for which there is
10489debugging information, organized into two lists: files whose symbols
10490have already been read, and files whose symbols will be read when needed.
10491
10492@kindex info functions
10493@item info functions
10494Print the names and data types of all defined functions.
10495
10496@item info functions @var{regexp}
10497Print the names and data types of all defined functions
10498whose names contain a match for regular expression @var{regexp}.
10499Thus, @samp{info fun step} finds all functions whose names
10500include @code{step}; @samp{info fun ^step} finds those whose names
b383017d 10501start with @code{step}. If a function name contains characters
c1468174 10502that conflict with the regular expression language (e.g.@:
1c5dfdad 10503@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
10504
10505@kindex info variables
10506@item info variables
10507Print the names and data types of all variables that are declared
6ca652b0 10508outside of functions (i.e.@: excluding local variables).
c906108c
SS
10509
10510@item info variables @var{regexp}
10511Print the names and data types of all variables (except for local
10512variables) whose names contain a match for regular expression
10513@var{regexp}.
10514
b37303ee 10515@kindex info classes
721c2651 10516@cindex Objective-C, classes and selectors
b37303ee
AF
10517@item info classes
10518@itemx info classes @var{regexp}
10519Display all Objective-C classes in your program, or
10520(with the @var{regexp} argument) all those matching a particular regular
10521expression.
10522
10523@kindex info selectors
10524@item info selectors
10525@itemx info selectors @var{regexp}
10526Display all Objective-C selectors in your program, or
10527(with the @var{regexp} argument) all those matching a particular regular
10528expression.
10529
c906108c
SS
10530@ignore
10531This was never implemented.
10532@kindex info methods
10533@item info methods
10534@itemx info methods @var{regexp}
10535The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
10536methods within C@t{++} program, or (with the @var{regexp} argument) a
10537specific set of methods found in the various C@t{++} classes. Many
10538C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
10539from the @code{ptype} command can be overwhelming and hard to use. The
10540@code{info-methods} command filters the methods, printing only those
10541which match the regular-expression @var{regexp}.
10542@end ignore
10543
c906108c
SS
10544@cindex reloading symbols
10545Some systems allow individual object files that make up your program to
7a292a7a
SS
10546be replaced without stopping and restarting your program. For example,
10547in VxWorks you can simply recompile a defective object file and keep on
10548running. If you are running on one of these systems, you can allow
10549@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
10550
10551@table @code
10552@kindex set symbol-reloading
10553@item set symbol-reloading on
10554Replace symbol definitions for the corresponding source file when an
10555object file with a particular name is seen again.
10556
10557@item set symbol-reloading off
6d2ebf8b
SS
10558Do not replace symbol definitions when encountering object files of the
10559same name more than once. This is the default state; if you are not
10560running on a system that permits automatic relinking of modules, you
10561should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
10562may discard symbols when linking large programs, that may contain
10563several modules (from different directories or libraries) with the same
10564name.
c906108c
SS
10565
10566@kindex show symbol-reloading
10567@item show symbol-reloading
10568Show the current @code{on} or @code{off} setting.
10569@end table
c906108c 10570
9c16f35a 10571@cindex opaque data types
c906108c
SS
10572@kindex set opaque-type-resolution
10573@item set opaque-type-resolution on
10574Tell @value{GDBN} to resolve opaque types. An opaque type is a type
10575declared as a pointer to a @code{struct}, @code{class}, or
10576@code{union}---for example, @code{struct MyType *}---that is used in one
10577source file although the full declaration of @code{struct MyType} is in
10578another source file. The default is on.
10579
10580A change in the setting of this subcommand will not take effect until
10581the next time symbols for a file are loaded.
10582
10583@item set opaque-type-resolution off
10584Tell @value{GDBN} not to resolve opaque types. In this case, the type
10585is printed as follows:
10586@smallexample
10587@{<no data fields>@}
10588@end smallexample
10589
10590@kindex show opaque-type-resolution
10591@item show opaque-type-resolution
10592Show whether opaque types are resolved or not.
c906108c
SS
10593
10594@kindex maint print symbols
10595@cindex symbol dump
10596@kindex maint print psymbols
10597@cindex partial symbol dump
10598@item maint print symbols @var{filename}
10599@itemx maint print psymbols @var{filename}
10600@itemx maint print msymbols @var{filename}
10601Write a dump of debugging symbol data into the file @var{filename}.
10602These commands are used to debug the @value{GDBN} symbol-reading code. Only
10603symbols with debugging data are included. If you use @samp{maint print
10604symbols}, @value{GDBN} includes all the symbols for which it has already
10605collected full details: that is, @var{filename} reflects symbols for
10606only those files whose symbols @value{GDBN} has read. You can use the
10607command @code{info sources} to find out which files these are. If you
10608use @samp{maint print psymbols} instead, the dump shows information about
10609symbols that @value{GDBN} only knows partially---that is, symbols defined in
10610files that @value{GDBN} has skimmed, but not yet read completely. Finally,
10611@samp{maint print msymbols} dumps just the minimal symbol information
10612required for each object file from which @value{GDBN} has read some symbols.
10613@xref{Files, ,Commands to specify files}, for a discussion of how
10614@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 10615
5e7b2f39
JB
10616@kindex maint info symtabs
10617@kindex maint info psymtabs
44ea7b70
JB
10618@cindex listing @value{GDBN}'s internal symbol tables
10619@cindex symbol tables, listing @value{GDBN}'s internal
10620@cindex full symbol tables, listing @value{GDBN}'s internal
10621@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
10622@item maint info symtabs @r{[} @var{regexp} @r{]}
10623@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
10624
10625List the @code{struct symtab} or @code{struct partial_symtab}
10626structures whose names match @var{regexp}. If @var{regexp} is not
10627given, list them all. The output includes expressions which you can
10628copy into a @value{GDBN} debugging this one to examine a particular
10629structure in more detail. For example:
10630
10631@smallexample
5e7b2f39 10632(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
10633@{ objfile /home/gnu/build/gdb/gdb
10634 ((struct objfile *) 0x82e69d0)
b383017d 10635 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10636 ((struct partial_symtab *) 0x8474b10)
10637 readin no
10638 fullname (null)
10639 text addresses 0x814d3c8 -- 0x8158074
10640 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
10641 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
10642 dependencies (none)
10643 @}
10644@}
5e7b2f39 10645(@value{GDBP}) maint info symtabs
44ea7b70
JB
10646(@value{GDBP})
10647@end smallexample
10648@noindent
10649We see that there is one partial symbol table whose filename contains
10650the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
10651and we see that @value{GDBN} has not read in any symtabs yet at all.
10652If we set a breakpoint on a function, that will cause @value{GDBN} to
10653read the symtab for the compilation unit containing that function:
10654
10655@smallexample
10656(@value{GDBP}) break dwarf2_psymtab_to_symtab
10657Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
10658line 1574.
5e7b2f39 10659(@value{GDBP}) maint info symtabs
b383017d 10660@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 10661 ((struct objfile *) 0x82e69d0)
b383017d 10662 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10663 ((struct symtab *) 0x86c1f38)
10664 dirname (null)
10665 fullname (null)
10666 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
10667 debugformat DWARF 2
10668 @}
10669@}
b383017d 10670(@value{GDBP})
44ea7b70 10671@end smallexample
c906108c
SS
10672@end table
10673
44ea7b70 10674
6d2ebf8b 10675@node Altering
c906108c
SS
10676@chapter Altering Execution
10677
10678Once you think you have found an error in your program, you might want to
10679find out for certain whether correcting the apparent error would lead to
10680correct results in the rest of the run. You can find the answer by
10681experiment, using the @value{GDBN} features for altering execution of the
10682program.
10683
10684For example, you can store new values into variables or memory
7a292a7a
SS
10685locations, give your program a signal, restart it at a different
10686address, or even return prematurely from a function.
c906108c
SS
10687
10688@menu
10689* Assignment:: Assignment to variables
10690* Jumping:: Continuing at a different address
c906108c 10691* Signaling:: Giving your program a signal
c906108c
SS
10692* Returning:: Returning from a function
10693* Calling:: Calling your program's functions
10694* Patching:: Patching your program
10695@end menu
10696
6d2ebf8b 10697@node Assignment
c906108c
SS
10698@section Assignment to variables
10699
10700@cindex assignment
10701@cindex setting variables
10702To alter the value of a variable, evaluate an assignment expression.
10703@xref{Expressions, ,Expressions}. For example,
10704
474c8240 10705@smallexample
c906108c 10706print x=4
474c8240 10707@end smallexample
c906108c
SS
10708
10709@noindent
10710stores the value 4 into the variable @code{x}, and then prints the
5d161b24 10711value of the assignment expression (which is 4).
c906108c
SS
10712@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
10713information on operators in supported languages.
c906108c
SS
10714
10715@kindex set variable
10716@cindex variables, setting
10717If you are not interested in seeing the value of the assignment, use the
10718@code{set} command instead of the @code{print} command. @code{set} is
10719really the same as @code{print} except that the expression's value is
10720not printed and is not put in the value history (@pxref{Value History,
10721,Value history}). The expression is evaluated only for its effects.
10722
c906108c
SS
10723If the beginning of the argument string of the @code{set} command
10724appears identical to a @code{set} subcommand, use the @code{set
10725variable} command instead of just @code{set}. This command is identical
10726to @code{set} except for its lack of subcommands. For example, if your
10727program has a variable @code{width}, you get an error if you try to set
10728a new value with just @samp{set width=13}, because @value{GDBN} has the
10729command @code{set width}:
10730
474c8240 10731@smallexample
c906108c
SS
10732(@value{GDBP}) whatis width
10733type = double
10734(@value{GDBP}) p width
10735$4 = 13
10736(@value{GDBP}) set width=47
10737Invalid syntax in expression.
474c8240 10738@end smallexample
c906108c
SS
10739
10740@noindent
10741The invalid expression, of course, is @samp{=47}. In
10742order to actually set the program's variable @code{width}, use
10743
474c8240 10744@smallexample
c906108c 10745(@value{GDBP}) set var width=47
474c8240 10746@end smallexample
53a5351d 10747
c906108c
SS
10748Because the @code{set} command has many subcommands that can conflict
10749with the names of program variables, it is a good idea to use the
10750@code{set variable} command instead of just @code{set}. For example, if
10751your program has a variable @code{g}, you run into problems if you try
10752to set a new value with just @samp{set g=4}, because @value{GDBN} has
10753the command @code{set gnutarget}, abbreviated @code{set g}:
10754
474c8240 10755@smallexample
c906108c
SS
10756@group
10757(@value{GDBP}) whatis g
10758type = double
10759(@value{GDBP}) p g
10760$1 = 1
10761(@value{GDBP}) set g=4
2df3850c 10762(@value{GDBP}) p g
c906108c
SS
10763$2 = 1
10764(@value{GDBP}) r
10765The program being debugged has been started already.
10766Start it from the beginning? (y or n) y
10767Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
10768"/home/smith/cc_progs/a.out": can't open to read symbols:
10769 Invalid bfd target.
c906108c
SS
10770(@value{GDBP}) show g
10771The current BFD target is "=4".
10772@end group
474c8240 10773@end smallexample
c906108c
SS
10774
10775@noindent
10776The program variable @code{g} did not change, and you silently set the
10777@code{gnutarget} to an invalid value. In order to set the variable
10778@code{g}, use
10779
474c8240 10780@smallexample
c906108c 10781(@value{GDBP}) set var g=4
474c8240 10782@end smallexample
c906108c
SS
10783
10784@value{GDBN} allows more implicit conversions in assignments than C; you can
10785freely store an integer value into a pointer variable or vice versa,
10786and you can convert any structure to any other structure that is the
10787same length or shorter.
10788@comment FIXME: how do structs align/pad in these conversions?
10789@comment /doc@cygnus.com 18dec1990
10790
10791To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
10792construct to generate a value of specified type at a specified address
10793(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
10794to memory location @code{0x83040} as an integer (which implies a certain size
10795and representation in memory), and
10796
474c8240 10797@smallexample
c906108c 10798set @{int@}0x83040 = 4
474c8240 10799@end smallexample
c906108c
SS
10800
10801@noindent
10802stores the value 4 into that memory location.
10803
6d2ebf8b 10804@node Jumping
c906108c
SS
10805@section Continuing at a different address
10806
10807Ordinarily, when you continue your program, you do so at the place where
10808it stopped, with the @code{continue} command. You can instead continue at
10809an address of your own choosing, with the following commands:
10810
10811@table @code
10812@kindex jump
10813@item jump @var{linespec}
10814Resume execution at line @var{linespec}. Execution stops again
10815immediately if there is a breakpoint there. @xref{List, ,Printing
10816source lines}, for a description of the different forms of
10817@var{linespec}. It is common practice to use the @code{tbreak} command
10818in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
10819breakpoints}.
10820
10821The @code{jump} command does not change the current stack frame, or
10822the stack pointer, or the contents of any memory location or any
10823register other than the program counter. If line @var{linespec} is in
10824a different function from the one currently executing, the results may
10825be bizarre if the two functions expect different patterns of arguments or
10826of local variables. For this reason, the @code{jump} command requests
10827confirmation if the specified line is not in the function currently
10828executing. However, even bizarre results are predictable if you are
10829well acquainted with the machine-language code of your program.
10830
10831@item jump *@var{address}
10832Resume execution at the instruction at address @var{address}.
10833@end table
10834
c906108c 10835@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
10836On many systems, you can get much the same effect as the @code{jump}
10837command by storing a new value into the register @code{$pc}. The
10838difference is that this does not start your program running; it only
10839changes the address of where it @emph{will} run when you continue. For
10840example,
c906108c 10841
474c8240 10842@smallexample
c906108c 10843set $pc = 0x485
474c8240 10844@end smallexample
c906108c
SS
10845
10846@noindent
10847makes the next @code{continue} command or stepping command execute at
10848address @code{0x485}, rather than at the address where your program stopped.
10849@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
10850
10851The most common occasion to use the @code{jump} command is to back
10852up---perhaps with more breakpoints set---over a portion of a program
10853that has already executed, in order to examine its execution in more
10854detail.
10855
c906108c 10856@c @group
6d2ebf8b 10857@node Signaling
c906108c 10858@section Giving your program a signal
9c16f35a 10859@cindex deliver a signal to a program
c906108c
SS
10860
10861@table @code
10862@kindex signal
10863@item signal @var{signal}
10864Resume execution where your program stopped, but immediately give it the
10865signal @var{signal}. @var{signal} can be the name or the number of a
10866signal. For example, on many systems @code{signal 2} and @code{signal
10867SIGINT} are both ways of sending an interrupt signal.
10868
10869Alternatively, if @var{signal} is zero, continue execution without
10870giving a signal. This is useful when your program stopped on account of
10871a signal and would ordinary see the signal when resumed with the
10872@code{continue} command; @samp{signal 0} causes it to resume without a
10873signal.
10874
10875@code{signal} does not repeat when you press @key{RET} a second time
10876after executing the command.
10877@end table
10878@c @end group
10879
10880Invoking the @code{signal} command is not the same as invoking the
10881@code{kill} utility from the shell. Sending a signal with @code{kill}
10882causes @value{GDBN} to decide what to do with the signal depending on
10883the signal handling tables (@pxref{Signals}). The @code{signal} command
10884passes the signal directly to your program.
10885
c906108c 10886
6d2ebf8b 10887@node Returning
c906108c
SS
10888@section Returning from a function
10889
10890@table @code
10891@cindex returning from a function
10892@kindex return
10893@item return
10894@itemx return @var{expression}
10895You can cancel execution of a function call with the @code{return}
10896command. If you give an
10897@var{expression} argument, its value is used as the function's return
10898value.
10899@end table
10900
10901When you use @code{return}, @value{GDBN} discards the selected stack frame
10902(and all frames within it). You can think of this as making the
10903discarded frame return prematurely. If you wish to specify a value to
10904be returned, give that value as the argument to @code{return}.
10905
10906This pops the selected stack frame (@pxref{Selection, ,Selecting a
10907frame}), and any other frames inside of it, leaving its caller as the
10908innermost remaining frame. That frame becomes selected. The
10909specified value is stored in the registers used for returning values
10910of functions.
10911
10912The @code{return} command does not resume execution; it leaves the
10913program stopped in the state that would exist if the function had just
10914returned. In contrast, the @code{finish} command (@pxref{Continuing
10915and Stepping, ,Continuing and stepping}) resumes execution until the
10916selected stack frame returns naturally.
10917
6d2ebf8b 10918@node Calling
c906108c
SS
10919@section Calling program functions
10920
f8568604 10921@table @code
c906108c 10922@cindex calling functions
f8568604
EZ
10923@cindex inferior functions, calling
10924@item print @var{expr}
9c16f35a 10925Evaluate the expression @var{expr} and display the resuling value.
f8568604
EZ
10926@var{expr} may include calls to functions in the program being
10927debugged.
10928
c906108c 10929@kindex call
c906108c
SS
10930@item call @var{expr}
10931Evaluate the expression @var{expr} without displaying @code{void}
10932returned values.
c906108c
SS
10933
10934You can use this variant of the @code{print} command if you want to
f8568604
EZ
10935execute a function from your program that does not return anything
10936(a.k.a.@: @dfn{a void function}), but without cluttering the output
10937with @code{void} returned values that @value{GDBN} will otherwise
10938print. If the result is not void, it is printed and saved in the
10939value history.
10940@end table
10941
9c16f35a
EZ
10942It is possible for the function you call via the @code{print} or
10943@code{call} command to generate a signal (e.g., if there's a bug in
10944the function, or if you passed it incorrect arguments). What happens
10945in that case is controlled by the @code{set unwindonsignal} command.
10946
10947@table @code
10948@item set unwindonsignal
10949@kindex set unwindonsignal
10950@cindex unwind stack in called functions
10951@cindex call dummy stack unwinding
10952Set unwinding of the stack if a signal is received while in a function
10953that @value{GDBN} called in the program being debugged. If set to on,
10954@value{GDBN} unwinds the stack it created for the call and restores
10955the context to what it was before the call. If set to off (the
10956default), @value{GDBN} stops in the frame where the signal was
10957received.
10958
10959@item show unwindonsignal
10960@kindex show unwindonsignal
10961Show the current setting of stack unwinding in the functions called by
10962@value{GDBN}.
10963@end table
10964
f8568604
EZ
10965@cindex weak alias functions
10966Sometimes, a function you wish to call is actually a @dfn{weak alias}
10967for another function. In such case, @value{GDBN} might not pick up
10968the type information, including the types of the function arguments,
10969which causes @value{GDBN} to call the inferior function incorrectly.
10970As a result, the called function will function erroneously and may
10971even crash. A solution to that is to use the name of the aliased
10972function instead.
c906108c 10973
6d2ebf8b 10974@node Patching
c906108c 10975@section Patching programs
7a292a7a 10976
c906108c
SS
10977@cindex patching binaries
10978@cindex writing into executables
c906108c 10979@cindex writing into corefiles
c906108c 10980
7a292a7a
SS
10981By default, @value{GDBN} opens the file containing your program's
10982executable code (or the corefile) read-only. This prevents accidental
10983alterations to machine code; but it also prevents you from intentionally
10984patching your program's binary.
c906108c
SS
10985
10986If you'd like to be able to patch the binary, you can specify that
10987explicitly with the @code{set write} command. For example, you might
10988want to turn on internal debugging flags, or even to make emergency
10989repairs.
10990
10991@table @code
10992@kindex set write
10993@item set write on
10994@itemx set write off
7a292a7a
SS
10995If you specify @samp{set write on}, @value{GDBN} opens executable and
10996core files for both reading and writing; if you specify @samp{set write
c906108c
SS
10997off} (the default), @value{GDBN} opens them read-only.
10998
10999If you have already loaded a file, you must load it again (using the
7a292a7a
SS
11000@code{exec-file} or @code{core-file} command) after changing @code{set
11001write}, for your new setting to take effect.
c906108c
SS
11002
11003@item show write
11004@kindex show write
7a292a7a
SS
11005Display whether executable files and core files are opened for writing
11006as well as reading.
c906108c
SS
11007@end table
11008
6d2ebf8b 11009@node GDB Files
c906108c
SS
11010@chapter @value{GDBN} Files
11011
7a292a7a
SS
11012@value{GDBN} needs to know the file name of the program to be debugged,
11013both in order to read its symbol table and in order to start your
11014program. To debug a core dump of a previous run, you must also tell
11015@value{GDBN} the name of the core dump file.
c906108c
SS
11016
11017@menu
11018* Files:: Commands to specify files
5b5d99cf 11019* Separate Debug Files:: Debugging information in separate files
c906108c
SS
11020* Symbol Errors:: Errors reading symbol files
11021@end menu
11022
6d2ebf8b 11023@node Files
c906108c 11024@section Commands to specify files
c906108c 11025
7a292a7a 11026@cindex symbol table
c906108c 11027@cindex core dump file
7a292a7a
SS
11028
11029You may want to specify executable and core dump file names. The usual
11030way to do this is at start-up time, using the arguments to
11031@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
11032Out of @value{GDBN}}).
c906108c
SS
11033
11034Occasionally it is necessary to change to a different file during a
397ca115
EZ
11035@value{GDBN} session. Or you may run @value{GDBN} and forget to
11036specify a file you want to use. Or you are debugging a remote target
11037via @code{gdbserver} (@pxref{Server, file}). In these situations the
11038@value{GDBN} commands to specify new files are useful.
c906108c
SS
11039
11040@table @code
11041@cindex executable file
11042@kindex file
11043@item file @var{filename}
11044Use @var{filename} as the program to be debugged. It is read for its
11045symbols and for the contents of pure memory. It is also the program
11046executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
11047directory and the file is not found in the @value{GDBN} working directory,
11048@value{GDBN} uses the environment variable @code{PATH} as a list of
11049directories to search, just as the shell does when looking for a program
11050to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
11051and your program, using the @code{path} command.
11052
fc8be69e
EZ
11053@cindex unlinked object files
11054@cindex patching object files
11055You can load unlinked object @file{.o} files into @value{GDBN} using
11056the @code{file} command. You will not be able to ``run'' an object
11057file, but you can disassemble functions and inspect variables. Also,
11058if the underlying BFD functionality supports it, you could use
11059@kbd{gdb -write} to patch object files using this technique. Note
11060that @value{GDBN} can neither interpret nor modify relocations in this
11061case, so branches and some initialized variables will appear to go to
11062the wrong place. But this feature is still handy from time to time.
11063
c906108c
SS
11064@item file
11065@code{file} with no argument makes @value{GDBN} discard any information it
11066has on both executable file and the symbol table.
11067
11068@kindex exec-file
11069@item exec-file @r{[} @var{filename} @r{]}
11070Specify that the program to be run (but not the symbol table) is found
11071in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
11072if necessary to locate your program. Omitting @var{filename} means to
11073discard information on the executable file.
11074
11075@kindex symbol-file
11076@item symbol-file @r{[} @var{filename} @r{]}
11077Read symbol table information from file @var{filename}. @code{PATH} is
11078searched when necessary. Use the @code{file} command to get both symbol
11079table and program to run from the same file.
11080
11081@code{symbol-file} with no argument clears out @value{GDBN} information on your
11082program's symbol table.
11083
5d161b24 11084The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
11085of its convenience variables, the value history, and all breakpoints and
11086auto-display expressions. This is because they may contain pointers to
11087the internal data recording symbols and data types, which are part of
11088the old symbol table data being discarded inside @value{GDBN}.
11089
11090@code{symbol-file} does not repeat if you press @key{RET} again after
11091executing it once.
11092
11093When @value{GDBN} is configured for a particular environment, it
11094understands debugging information in whatever format is the standard
11095generated for that environment; you may use either a @sc{gnu} compiler, or
11096other compilers that adhere to the local conventions.
c906108c
SS
11097Best results are usually obtained from @sc{gnu} compilers; for example,
11098using @code{@value{GCC}} you can generate debugging information for
11099optimized code.
c906108c
SS
11100
11101For most kinds of object files, with the exception of old SVR3 systems
11102using COFF, the @code{symbol-file} command does not normally read the
11103symbol table in full right away. Instead, it scans the symbol table
11104quickly to find which source files and which symbols are present. The
11105details are read later, one source file at a time, as they are needed.
11106
11107The purpose of this two-stage reading strategy is to make @value{GDBN}
11108start up faster. For the most part, it is invisible except for
11109occasional pauses while the symbol table details for a particular source
11110file are being read. (The @code{set verbose} command can turn these
11111pauses into messages if desired. @xref{Messages/Warnings, ,Optional
11112warnings and messages}.)
11113
c906108c
SS
11114We have not implemented the two-stage strategy for COFF yet. When the
11115symbol table is stored in COFF format, @code{symbol-file} reads the
11116symbol table data in full right away. Note that ``stabs-in-COFF''
11117still does the two-stage strategy, since the debug info is actually
11118in stabs format.
11119
11120@kindex readnow
11121@cindex reading symbols immediately
11122@cindex symbols, reading immediately
a94ab193
EZ
11123@item symbol-file @var{filename} @r{[} -readnow @r{]}
11124@itemx file @var{filename} @r{[} -readnow @r{]}
c906108c
SS
11125You can override the @value{GDBN} two-stage strategy for reading symbol
11126tables by using the @samp{-readnow} option with any of the commands that
11127load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 11128entire symbol table available.
c906108c 11129
c906108c
SS
11130@c FIXME: for now no mention of directories, since this seems to be in
11131@c flux. 13mar1992 status is that in theory GDB would look either in
11132@c current dir or in same dir as myprog; but issues like competing
11133@c GDB's, or clutter in system dirs, mean that in practice right now
11134@c only current dir is used. FFish says maybe a special GDB hierarchy
11135@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
11136@c files.
11137
c906108c 11138@kindex core-file
09d4efe1 11139@item core-file @r{[}@var{filename}@r{]}
4644b6e3 11140@itemx core
c906108c
SS
11141Specify the whereabouts of a core dump file to be used as the ``contents
11142of memory''. Traditionally, core files contain only some parts of the
11143address space of the process that generated them; @value{GDBN} can access the
11144executable file itself for other parts.
11145
11146@code{core-file} with no argument specifies that no core file is
11147to be used.
11148
11149Note that the core file is ignored when your program is actually running
7a292a7a
SS
11150under @value{GDBN}. So, if you have been running your program and you
11151wish to debug a core file instead, you must kill the subprocess in which
11152the program is running. To do this, use the @code{kill} command
c906108c 11153(@pxref{Kill Process, ,Killing the child process}).
c906108c 11154
c906108c
SS
11155@kindex add-symbol-file
11156@cindex dynamic linking
11157@item add-symbol-file @var{filename} @var{address}
a94ab193 11158@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
17d9d558 11159@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
11160The @code{add-symbol-file} command reads additional symbol table
11161information from the file @var{filename}. You would use this command
11162when @var{filename} has been dynamically loaded (by some other means)
11163into the program that is running. @var{address} should be the memory
11164address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
11165this out for itself. You can additionally specify an arbitrary number
11166of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
11167section name and base address for that section. You can specify any
11168@var{address} as an expression.
c906108c
SS
11169
11170The symbol table of the file @var{filename} is added to the symbol table
11171originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
11172@code{add-symbol-file} command any number of times; the new symbol data
11173thus read keeps adding to the old. To discard all old symbol data
11174instead, use the @code{symbol-file} command without any arguments.
c906108c 11175
17d9d558
JB
11176@cindex relocatable object files, reading symbols from
11177@cindex object files, relocatable, reading symbols from
11178@cindex reading symbols from relocatable object files
11179@cindex symbols, reading from relocatable object files
11180@cindex @file{.o} files, reading symbols from
11181Although @var{filename} is typically a shared library file, an
11182executable file, or some other object file which has been fully
11183relocated for loading into a process, you can also load symbolic
11184information from relocatable @file{.o} files, as long as:
11185
11186@itemize @bullet
11187@item
11188the file's symbolic information refers only to linker symbols defined in
11189that file, not to symbols defined by other object files,
11190@item
11191every section the file's symbolic information refers to has actually
11192been loaded into the inferior, as it appears in the file, and
11193@item
11194you can determine the address at which every section was loaded, and
11195provide these to the @code{add-symbol-file} command.
11196@end itemize
11197
11198@noindent
11199Some embedded operating systems, like Sun Chorus and VxWorks, can load
11200relocatable files into an already running program; such systems
11201typically make the requirements above easy to meet. However, it's
11202important to recognize that many native systems use complex link
49efadf5 11203procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
11204assembly, for example) that make the requirements difficult to meet. In
11205general, one cannot assume that using @code{add-symbol-file} to read a
11206relocatable object file's symbolic information will have the same effect
11207as linking the relocatable object file into the program in the normal
11208way.
11209
c906108c
SS
11210@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
11211
c45da7e6
EZ
11212@kindex add-symbol-file-from-memory
11213@cindex @code{syscall DSO}
11214@cindex load symbols from memory
11215@item add-symbol-file-from-memory @var{address}
11216Load symbols from the given @var{address} in a dynamically loaded
11217object file whose image is mapped directly into the inferior's memory.
11218For example, the Linux kernel maps a @code{syscall DSO} into each
11219process's address space; this DSO provides kernel-specific code for
11220some system calls. The argument can be any expression whose
11221evaluation yields the address of the file's shared object file header.
11222For this command to work, you must have used @code{symbol-file} or
11223@code{exec-file} commands in advance.
11224
09d4efe1
EZ
11225@kindex add-shared-symbol-files
11226@kindex assf
11227@item add-shared-symbol-files @var{library-file}
11228@itemx assf @var{library-file}
11229The @code{add-shared-symbol-files} command can currently be used only
11230in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
11231alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
11232@value{GDBN} automatically looks for shared libraries, however if
11233@value{GDBN} does not find yours, you can invoke
11234@code{add-shared-symbol-files}. It takes one argument: the shared
11235library's file name. @code{assf} is a shorthand alias for
11236@code{add-shared-symbol-files}.
c906108c 11237
c906108c 11238@kindex section
09d4efe1
EZ
11239@item section @var{section} @var{addr}
11240The @code{section} command changes the base address of the named
11241@var{section} of the exec file to @var{addr}. This can be used if the
11242exec file does not contain section addresses, (such as in the
11243@code{a.out} format), or when the addresses specified in the file
11244itself are wrong. Each section must be changed separately. The
11245@code{info files} command, described below, lists all the sections and
11246their addresses.
c906108c
SS
11247
11248@kindex info files
11249@kindex info target
11250@item info files
11251@itemx info target
7a292a7a
SS
11252@code{info files} and @code{info target} are synonymous; both print the
11253current target (@pxref{Targets, ,Specifying a Debugging Target}),
11254including the names of the executable and core dump files currently in
11255use by @value{GDBN}, and the files from which symbols were loaded. The
11256command @code{help target} lists all possible targets rather than
11257current ones.
11258
fe95c787
MS
11259@kindex maint info sections
11260@item maint info sections
11261Another command that can give you extra information about program sections
11262is @code{maint info sections}. In addition to the section information
11263displayed by @code{info files}, this command displays the flags and file
11264offset of each section in the executable and core dump files. In addition,
11265@code{maint info sections} provides the following command options (which
11266may be arbitrarily combined):
11267
11268@table @code
11269@item ALLOBJ
11270Display sections for all loaded object files, including shared libraries.
11271@item @var{sections}
6600abed 11272Display info only for named @var{sections}.
fe95c787
MS
11273@item @var{section-flags}
11274Display info only for sections for which @var{section-flags} are true.
11275The section flags that @value{GDBN} currently knows about are:
11276@table @code
11277@item ALLOC
11278Section will have space allocated in the process when loaded.
11279Set for all sections except those containing debug information.
11280@item LOAD
11281Section will be loaded from the file into the child process memory.
11282Set for pre-initialized code and data, clear for @code{.bss} sections.
11283@item RELOC
11284Section needs to be relocated before loading.
11285@item READONLY
11286Section cannot be modified by the child process.
11287@item CODE
11288Section contains executable code only.
6600abed 11289@item DATA
fe95c787
MS
11290Section contains data only (no executable code).
11291@item ROM
11292Section will reside in ROM.
11293@item CONSTRUCTOR
11294Section contains data for constructor/destructor lists.
11295@item HAS_CONTENTS
11296Section is not empty.
11297@item NEVER_LOAD
11298An instruction to the linker to not output the section.
11299@item COFF_SHARED_LIBRARY
11300A notification to the linker that the section contains
11301COFF shared library information.
11302@item IS_COMMON
11303Section contains common symbols.
11304@end table
11305@end table
6763aef9 11306@kindex set trust-readonly-sections
9c16f35a 11307@cindex read-only sections
6763aef9
MS
11308@item set trust-readonly-sections on
11309Tell @value{GDBN} that readonly sections in your object file
6ca652b0 11310really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
11311In that case, @value{GDBN} can fetch values from these sections
11312out of the object file, rather than from the target program.
11313For some targets (notably embedded ones), this can be a significant
11314enhancement to debugging performance.
11315
11316The default is off.
11317
11318@item set trust-readonly-sections off
15110bc3 11319Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
11320the contents of the section might change while the program is running,
11321and must therefore be fetched from the target when needed.
9c16f35a
EZ
11322
11323@item show trust-readonly-sections
11324Show the current setting of trusting readonly sections.
c906108c
SS
11325@end table
11326
11327All file-specifying commands allow both absolute and relative file names
11328as arguments. @value{GDBN} always converts the file name to an absolute file
11329name and remembers it that way.
11330
c906108c 11331@cindex shared libraries
9c16f35a
EZ
11332@value{GDBN} supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
11333and IBM RS/6000 AIX shared libraries.
53a5351d 11334
c906108c
SS
11335@value{GDBN} automatically loads symbol definitions from shared libraries
11336when you use the @code{run} command, or when you examine a core file.
11337(Before you issue the @code{run} command, @value{GDBN} does not understand
11338references to a function in a shared library, however---unless you are
11339debugging a core file).
53a5351d
JM
11340
11341On HP-UX, if the program loads a library explicitly, @value{GDBN}
11342automatically loads the symbols at the time of the @code{shl_load} call.
11343
c906108c
SS
11344@c FIXME: some @value{GDBN} release may permit some refs to undef
11345@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
11346@c FIXME...lib; check this from time to time when updating manual
11347
b7209cb4
FF
11348There are times, however, when you may wish to not automatically load
11349symbol definitions from shared libraries, such as when they are
11350particularly large or there are many of them.
11351
11352To control the automatic loading of shared library symbols, use the
11353commands:
11354
11355@table @code
11356@kindex set auto-solib-add
11357@item set auto-solib-add @var{mode}
11358If @var{mode} is @code{on}, symbols from all shared object libraries
11359will be loaded automatically when the inferior begins execution, you
11360attach to an independently started inferior, or when the dynamic linker
11361informs @value{GDBN} that a new library has been loaded. If @var{mode}
11362is @code{off}, symbols must be loaded manually, using the
11363@code{sharedlibrary} command. The default value is @code{on}.
11364
dcaf7c2c
EZ
11365@cindex memory used for symbol tables
11366If your program uses lots of shared libraries with debug info that
11367takes large amounts of memory, you can decrease the @value{GDBN}
11368memory footprint by preventing it from automatically loading the
11369symbols from shared libraries. To that end, type @kbd{set
11370auto-solib-add off} before running the inferior, then load each
11371library whose debug symbols you do need with @kbd{sharedlibrary
11372@var{regexp}}, where @var{regexp} is a regular expresion that matches
11373the libraries whose symbols you want to be loaded.
11374
b7209cb4
FF
11375@kindex show auto-solib-add
11376@item show auto-solib-add
11377Display the current autoloading mode.
11378@end table
11379
c45da7e6 11380@cindex load shared library
b7209cb4
FF
11381To explicitly load shared library symbols, use the @code{sharedlibrary}
11382command:
11383
c906108c
SS
11384@table @code
11385@kindex info sharedlibrary
11386@kindex info share
11387@item info share
11388@itemx info sharedlibrary
11389Print the names of the shared libraries which are currently loaded.
11390
11391@kindex sharedlibrary
11392@kindex share
11393@item sharedlibrary @var{regex}
11394@itemx share @var{regex}
c906108c
SS
11395Load shared object library symbols for files matching a
11396Unix regular expression.
11397As with files loaded automatically, it only loads shared libraries
11398required by your program for a core file or after typing @code{run}. If
11399@var{regex} is omitted all shared libraries required by your program are
11400loaded.
c45da7e6
EZ
11401
11402@item nosharedlibrary
11403@kindex nosharedlibrary
11404@cindex unload symbols from shared libraries
11405Unload all shared object library symbols. This discards all symbols
11406that have been loaded from all shared libraries. Symbols from shared
11407libraries that were loaded by explicit user requests are not
11408discarded.
c906108c
SS
11409@end table
11410
721c2651
EZ
11411Sometimes you may wish that @value{GDBN} stops and gives you control
11412when any of shared library events happen. Use the @code{set
11413stop-on-solib-events} command for this:
11414
11415@table @code
11416@item set stop-on-solib-events
11417@kindex set stop-on-solib-events
11418This command controls whether @value{GDBN} should give you control
11419when the dynamic linker notifies it about some shared library event.
11420The most common event of interest is loading or unloading of a new
11421shared library.
11422
11423@item show stop-on-solib-events
11424@kindex show stop-on-solib-events
11425Show whether @value{GDBN} stops and gives you control when shared
11426library events happen.
11427@end table
11428
f5ebfba0
DJ
11429Shared libraries are also supported in many cross or remote debugging
11430configurations. A copy of the target's libraries need to be present on the
11431host system; they need to be the same as the target libraries, although the
11432copies on the target can be stripped as long as the copies on the host are
11433not.
11434
59b7b46f
EZ
11435@cindex where to look for shared libraries
11436For remote debugging, you need to tell @value{GDBN} where the target
11437libraries are, so that it can load the correct copies---otherwise, it
11438may try to load the host's libraries. @value{GDBN} has two variables
11439to specify the search directories for target libraries.
f5ebfba0
DJ
11440
11441@table @code
59b7b46f 11442@cindex prefix for shared library file names
f5ebfba0
DJ
11443@kindex set solib-absolute-prefix
11444@item set solib-absolute-prefix @var{path}
11445If this variable is set, @var{path} will be used as a prefix for any
11446absolute shared library paths; many runtime loaders store the absolute
11447paths to the shared library in the target program's memory. If you use
11448@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
11449out in the same way that they are on the target, with e.g.@: a
11450@file{/usr/lib} hierarchy under @var{path}.
11451
59b7b46f
EZ
11452@cindex default value of @samp{solib-absolute-prefix}
11453@cindex @samp{--with-sysroot}
f5ebfba0
DJ
11454You can set the default value of @samp{solib-absolute-prefix} by using the
11455configure-time @samp{--with-sysroot} option.
11456
11457@kindex show solib-absolute-prefix
11458@item show solib-absolute-prefix
11459Display the current shared library prefix.
11460
11461@kindex set solib-search-path
11462@item set solib-search-path @var{path}
11463If this variable is set, @var{path} is a colon-separated list of directories
11464to search for shared libraries. @samp{solib-search-path} is used after
11465@samp{solib-absolute-prefix} fails to locate the library, or if the path to
11466the library is relative instead of absolute. If you want to use
11467@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
11468set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
11469@value{GDBN} from finding your host's libraries.
11470
11471@kindex show solib-search-path
11472@item show solib-search-path
11473Display the current shared library search path.
11474@end table
11475
5b5d99cf
JB
11476
11477@node Separate Debug Files
11478@section Debugging Information in Separate Files
11479@cindex separate debugging information files
11480@cindex debugging information in separate files
11481@cindex @file{.debug} subdirectories
11482@cindex debugging information directory, global
11483@cindex global debugging information directory
11484
11485@value{GDBN} allows you to put a program's debugging information in a
11486file separate from the executable itself, in a way that allows
11487@value{GDBN} to find and load the debugging information automatically.
11488Since debugging information can be very large --- sometimes larger
11489than the executable code itself --- some systems distribute debugging
11490information for their executables in separate files, which users can
11491install only when they need to debug a problem.
11492
11493If an executable's debugging information has been extracted to a
11494separate file, the executable should contain a @dfn{debug link} giving
11495the name of the debugging information file (with no directory
11496components), and a checksum of its contents. (The exact form of a
11497debug link is described below.) If the full name of the directory
11498containing the executable is @var{execdir}, and the executable has a
11499debug link that specifies the name @var{debugfile}, then @value{GDBN}
11500will automatically search for the debugging information file in three
11501places:
11502
11503@itemize @bullet
11504@item
11505the directory containing the executable file (that is, it will look
11506for a file named @file{@var{execdir}/@var{debugfile}},
11507@item
11508a subdirectory of that directory named @file{.debug} (that is, the
11509file @file{@var{execdir}/.debug/@var{debugfile}}, and
11510@item
11511a subdirectory of the global debug file directory that includes the
11512executable's full path, and the name from the link (that is, the file
11513@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
11514@var{globaldebugdir} is the global debug file directory, and
11515@var{execdir} has been turned into a relative path).
11516@end itemize
11517@noindent
11518@value{GDBN} checks under each of these names for a debugging
11519information file whose checksum matches that given in the link, and
11520reads the debugging information from the first one it finds.
11521
11522So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
11523which has a link containing the name @file{ls.debug}, and the global
11524debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
11525for debug information in @file{/usr/bin/ls.debug},
11526@file{/usr/bin/.debug/ls.debug}, and
11527@file{/usr/lib/debug/usr/bin/ls.debug}.
11528
11529You can set the global debugging info directory's name, and view the
11530name @value{GDBN} is currently using.
11531
11532@table @code
11533
11534@kindex set debug-file-directory
11535@item set debug-file-directory @var{directory}
11536Set the directory which @value{GDBN} searches for separate debugging
11537information files to @var{directory}.
11538
11539@kindex show debug-file-directory
11540@item show debug-file-directory
11541Show the directory @value{GDBN} searches for separate debugging
11542information files.
11543
11544@end table
11545
11546@cindex @code{.gnu_debuglink} sections
11547@cindex debug links
11548A debug link is a special section of the executable file named
11549@code{.gnu_debuglink}. The section must contain:
11550
11551@itemize
11552@item
11553A filename, with any leading directory components removed, followed by
11554a zero byte,
11555@item
11556zero to three bytes of padding, as needed to reach the next four-byte
11557boundary within the section, and
11558@item
11559a four-byte CRC checksum, stored in the same endianness used for the
11560executable file itself. The checksum is computed on the debugging
11561information file's full contents by the function given below, passing
11562zero as the @var{crc} argument.
11563@end itemize
11564
11565Any executable file format can carry a debug link, as long as it can
11566contain a section named @code{.gnu_debuglink} with the contents
11567described above.
11568
11569The debugging information file itself should be an ordinary
11570executable, containing a full set of linker symbols, sections, and
11571debugging information. The sections of the debugging information file
11572should have the same names, addresses and sizes as the original file,
11573but they need not contain any data --- much like a @code{.bss} section
11574in an ordinary executable.
11575
11576As of December 2002, there is no standard GNU utility to produce
11577separated executable / debugging information file pairs. Ulrich
11578Drepper's @file{elfutils} package, starting with version 0.53,
11579contains a version of the @code{strip} command such that the command
11580@kbd{strip foo -f foo.debug} removes the debugging information from
11581the executable file @file{foo}, places it in the file
11582@file{foo.debug}, and leaves behind a debug link in @file{foo}.
11583
11584Since there are many different ways to compute CRC's (different
11585polynomials, reversals, byte ordering, etc.), the simplest way to
11586describe the CRC used in @code{.gnu_debuglink} sections is to give the
11587complete code for a function that computes it:
11588
4644b6e3 11589@kindex gnu_debuglink_crc32
5b5d99cf
JB
11590@smallexample
11591unsigned long
11592gnu_debuglink_crc32 (unsigned long crc,
11593 unsigned char *buf, size_t len)
11594@{
11595 static const unsigned long crc32_table[256] =
11596 @{
11597 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11598 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11599 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11600 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11601 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11602 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11603 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11604 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11605 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11606 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11607 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11608 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11609 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11610 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11611 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11612 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11613 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11614 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11615 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11616 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11617 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11618 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11619 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11620 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11621 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11622 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11623 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11624 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11625 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11626 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11627 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11628 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11629 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11630 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11631 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11632 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11633 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11634 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11635 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11636 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11637 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11638 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11639 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11640 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11641 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11642 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11643 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11644 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11645 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11646 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11647 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11648 0x2d02ef8d
11649 @};
11650 unsigned char *end;
11651
11652 crc = ~crc & 0xffffffff;
11653 for (end = buf + len; buf < end; ++buf)
11654 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 11655 return ~crc & 0xffffffff;
5b5d99cf
JB
11656@}
11657@end smallexample
11658
11659
6d2ebf8b 11660@node Symbol Errors
c906108c
SS
11661@section Errors reading symbol files
11662
11663While reading a symbol file, @value{GDBN} occasionally encounters problems,
11664such as symbol types it does not recognize, or known bugs in compiler
11665output. By default, @value{GDBN} does not notify you of such problems, since
11666they are relatively common and primarily of interest to people
11667debugging compilers. If you are interested in seeing information
11668about ill-constructed symbol tables, you can either ask @value{GDBN} to print
11669only one message about each such type of problem, no matter how many
11670times the problem occurs; or you can ask @value{GDBN} to print more messages,
11671to see how many times the problems occur, with the @code{set
11672complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
11673messages}).
11674
11675The messages currently printed, and their meanings, include:
11676
11677@table @code
11678@item inner block not inside outer block in @var{symbol}
11679
11680The symbol information shows where symbol scopes begin and end
11681(such as at the start of a function or a block of statements). This
11682error indicates that an inner scope block is not fully contained
11683in its outer scope blocks.
11684
11685@value{GDBN} circumvents the problem by treating the inner block as if it had
11686the same scope as the outer block. In the error message, @var{symbol}
11687may be shown as ``@code{(don't know)}'' if the outer block is not a
11688function.
11689
11690@item block at @var{address} out of order
11691
11692The symbol information for symbol scope blocks should occur in
11693order of increasing addresses. This error indicates that it does not
11694do so.
11695
11696@value{GDBN} does not circumvent this problem, and has trouble
11697locating symbols in the source file whose symbols it is reading. (You
11698can often determine what source file is affected by specifying
11699@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
11700messages}.)
11701
11702@item bad block start address patched
11703
11704The symbol information for a symbol scope block has a start address
11705smaller than the address of the preceding source line. This is known
11706to occur in the SunOS 4.1.1 (and earlier) C compiler.
11707
11708@value{GDBN} circumvents the problem by treating the symbol scope block as
11709starting on the previous source line.
11710
11711@item bad string table offset in symbol @var{n}
11712
11713@cindex foo
11714Symbol number @var{n} contains a pointer into the string table which is
11715larger than the size of the string table.
11716
11717@value{GDBN} circumvents the problem by considering the symbol to have the
11718name @code{foo}, which may cause other problems if many symbols end up
11719with this name.
11720
11721@item unknown symbol type @code{0x@var{nn}}
11722
7a292a7a
SS
11723The symbol information contains new data types that @value{GDBN} does
11724not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 11725uncomprehended information, in hexadecimal.
c906108c 11726
7a292a7a
SS
11727@value{GDBN} circumvents the error by ignoring this symbol information.
11728This usually allows you to debug your program, though certain symbols
c906108c 11729are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
11730debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
11731on @code{complain}, then go up to the function @code{read_dbx_symtab}
11732and examine @code{*bufp} to see the symbol.
c906108c
SS
11733
11734@item stub type has NULL name
c906108c 11735
7a292a7a 11736@value{GDBN} could not find the full definition for a struct or class.
c906108c 11737
7a292a7a 11738@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 11739The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
11740information that recent versions of the compiler should have output for
11741it.
c906108c
SS
11742
11743@item info mismatch between compiler and debugger
11744
11745@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 11746
c906108c
SS
11747@end table
11748
6d2ebf8b 11749@node Targets
c906108c 11750@chapter Specifying a Debugging Target
7a292a7a 11751
c906108c 11752@cindex debugging target
c906108c 11753A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
11754
11755Often, @value{GDBN} runs in the same host environment as your program;
11756in that case, the debugging target is specified as a side effect when
11757you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
11758flexibility---for example, running @value{GDBN} on a physically separate
11759host, or controlling a standalone system over a serial port or a
53a5351d
JM
11760realtime system over a TCP/IP connection---you can use the @code{target}
11761command to specify one of the target types configured for @value{GDBN}
11762(@pxref{Target Commands, ,Commands for managing targets}).
c906108c 11763
a8f24a35
EZ
11764@cindex target architecture
11765It is possible to build @value{GDBN} for several different @dfn{target
11766architectures}. When @value{GDBN} is built like that, you can choose
11767one of the available architectures with the @kbd{set architecture}
11768command.
11769
11770@table @code
11771@kindex set architecture
11772@kindex show architecture
11773@item set architecture @var{arch}
11774This command sets the current target architecture to @var{arch}. The
11775value of @var{arch} can be @code{"auto"}, in addition to one of the
11776supported architectures.
11777
11778@item show architecture
11779Show the current target architecture.
9c16f35a
EZ
11780
11781@item set processor
11782@itemx processor
11783@kindex set processor
11784@kindex show processor
11785These are alias commands for, respectively, @code{set architecture}
11786and @code{show architecture}.
a8f24a35
EZ
11787@end table
11788
c906108c
SS
11789@menu
11790* Active Targets:: Active targets
11791* Target Commands:: Commands for managing targets
c906108c
SS
11792* Byte Order:: Choosing target byte order
11793* Remote:: Remote debugging
96baa820 11794* KOD:: Kernel Object Display
c906108c
SS
11795
11796@end menu
11797
6d2ebf8b 11798@node Active Targets
c906108c 11799@section Active targets
7a292a7a 11800
c906108c
SS
11801@cindex stacking targets
11802@cindex active targets
11803@cindex multiple targets
11804
c906108c 11805There are three classes of targets: processes, core files, and
7a292a7a
SS
11806executable files. @value{GDBN} can work concurrently on up to three
11807active targets, one in each class. This allows you to (for example)
11808start a process and inspect its activity without abandoning your work on
11809a core file.
c906108c
SS
11810
11811For example, if you execute @samp{gdb a.out}, then the executable file
11812@code{a.out} is the only active target. If you designate a core file as
11813well---presumably from a prior run that crashed and coredumped---then
11814@value{GDBN} has two active targets and uses them in tandem, looking
11815first in the corefile target, then in the executable file, to satisfy
11816requests for memory addresses. (Typically, these two classes of target
11817are complementary, since core files contain only a program's
11818read-write memory---variables and so on---plus machine status, while
11819executable files contain only the program text and initialized data.)
c906108c
SS
11820
11821When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
11822target as well. When a process target is active, all @value{GDBN}
11823commands requesting memory addresses refer to that target; addresses in
11824an active core file or executable file target are obscured while the
11825process target is active.
c906108c 11826
7a292a7a
SS
11827Use the @code{core-file} and @code{exec-file} commands to select a new
11828core file or executable target (@pxref{Files, ,Commands to specify
c906108c 11829files}). To specify as a target a process that is already running, use
7a292a7a
SS
11830the @code{attach} command (@pxref{Attach, ,Debugging an already-running
11831process}).
c906108c 11832
6d2ebf8b 11833@node Target Commands
c906108c
SS
11834@section Commands for managing targets
11835
11836@table @code
11837@item target @var{type} @var{parameters}
7a292a7a
SS
11838Connects the @value{GDBN} host environment to a target machine or
11839process. A target is typically a protocol for talking to debugging
11840facilities. You use the argument @var{type} to specify the type or
11841protocol of the target machine.
c906108c
SS
11842
11843Further @var{parameters} are interpreted by the target protocol, but
11844typically include things like device names or host names to connect
11845with, process numbers, and baud rates.
c906108c
SS
11846
11847The @code{target} command does not repeat if you press @key{RET} again
11848after executing the command.
11849
11850@kindex help target
11851@item help target
11852Displays the names of all targets available. To display targets
11853currently selected, use either @code{info target} or @code{info files}
11854(@pxref{Files, ,Commands to specify files}).
11855
11856@item help target @var{name}
11857Describe a particular target, including any parameters necessary to
11858select it.
11859
11860@kindex set gnutarget
11861@item set gnutarget @var{args}
5d161b24 11862@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 11863knows whether it is reading an @dfn{executable},
5d161b24
DB
11864a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
11865with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
11866with @code{gnutarget} the @code{target} refers to a program, not a machine.
11867
d4f3574e 11868@quotation
c906108c
SS
11869@emph{Warning:} To specify a file format with @code{set gnutarget},
11870you must know the actual BFD name.
d4f3574e 11871@end quotation
c906108c 11872
d4f3574e
SS
11873@noindent
11874@xref{Files, , Commands to specify files}.
c906108c 11875
5d161b24 11876@kindex show gnutarget
c906108c
SS
11877@item show gnutarget
11878Use the @code{show gnutarget} command to display what file format
11879@code{gnutarget} is set to read. If you have not set @code{gnutarget},
11880@value{GDBN} will determine the file format for each file automatically,
11881and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11882@end table
11883
4644b6e3 11884@cindex common targets
c906108c
SS
11885Here are some common targets (available, or not, depending on the GDB
11886configuration):
c906108c
SS
11887
11888@table @code
4644b6e3 11889@kindex target
c906108c 11890@item target exec @var{program}
4644b6e3 11891@cindex executable file target
c906108c
SS
11892An executable file. @samp{target exec @var{program}} is the same as
11893@samp{exec-file @var{program}}.
11894
c906108c 11895@item target core @var{filename}
4644b6e3 11896@cindex core dump file target
c906108c
SS
11897A core dump file. @samp{target core @var{filename}} is the same as
11898@samp{core-file @var{filename}}.
c906108c 11899
c906108c 11900@item target remote @var{dev}
4644b6e3 11901@cindex remote target
c906108c 11902Remote serial target in GDB-specific protocol. The argument @var{dev}
c1468174 11903specifies what serial device to use for the connection (e.g.@:
c906108c 11904@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 11905supports the @code{load} command. This is only useful if you have
c906108c
SS
11906some other way of getting the stub to the target system, and you can put
11907it somewhere in memory where it won't get clobbered by the download.
11908
c906108c 11909@item target sim
4644b6e3 11910@cindex built-in simulator target
2df3850c 11911Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 11912In general,
474c8240 11913@smallexample
104c1213
JM
11914 target sim
11915 load
11916 run
474c8240 11917@end smallexample
d4f3574e 11918@noindent
104c1213 11919works; however, you cannot assume that a specific memory map, device
d4f3574e 11920drivers, or even basic I/O is available, although some simulators do
104c1213
JM
11921provide these. For info about any processor-specific simulator details,
11922see the appropriate section in @ref{Embedded Processors, ,Embedded
11923Processors}.
11924
c906108c
SS
11925@end table
11926
104c1213 11927Some configurations may include these targets as well:
c906108c
SS
11928
11929@table @code
11930
c906108c 11931@item target nrom @var{dev}
4644b6e3 11932@cindex NetROM ROM emulator target
c906108c
SS
11933NetROM ROM emulator. This target only supports downloading.
11934
c906108c
SS
11935@end table
11936
5d161b24 11937Different targets are available on different configurations of @value{GDBN};
c906108c 11938your configuration may have more or fewer targets.
c906108c 11939
721c2651
EZ
11940Many remote targets require you to download the executable's code once
11941you've successfully established a connection. You may wish to control
11942various aspects of this process, such as the size of the data chunks
11943used by @value{GDBN} to download program parts to the remote target.
a8f24a35
EZ
11944
11945@table @code
11946@kindex set download-write-size
11947@item set download-write-size @var{size}
11948Set the write size used when downloading a program. Only used when
11949downloading a program onto a remote target. Specify zero or a
11950negative value to disable blocked writes. The actual size of each
11951transfer is also limited by the size of the target packet and the
11952memory cache.
11953
11954@kindex show download-write-size
11955@item show download-write-size
721c2651 11956@kindex show download-write-size
a8f24a35 11957Show the current value of the write size.
721c2651
EZ
11958
11959@item set hash
11960@kindex set hash@r{, for remote monitors}
11961@cindex hash mark while downloading
11962This command controls whether a hash mark @samp{#} is displayed while
11963downloading a file to the remote monitor. If on, a hash mark is
11964displayed after each S-record is successfully downloaded to the
11965monitor.
11966
11967@item show hash
11968@kindex show hash@r{, for remote monitors}
11969Show the current status of displaying the hash mark.
11970
11971@item set debug monitor
11972@kindex set debug monitor
11973@cindex display remote monitor communications
11974Enable or disable display of communications messages between
11975@value{GDBN} and the remote monitor.
11976
11977@item show debug monitor
11978@kindex show debug monitor
11979Show the current status of displaying communications between
11980@value{GDBN} and the remote monitor.
a8f24a35 11981@end table
c906108c
SS
11982
11983@table @code
11984
11985@kindex load @var{filename}
11986@item load @var{filename}
c906108c
SS
11987Depending on what remote debugging facilities are configured into
11988@value{GDBN}, the @code{load} command may be available. Where it exists, it
11989is meant to make @var{filename} (an executable) available for debugging
11990on the remote system---by downloading, or dynamic linking, for example.
11991@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
11992the @code{add-symbol-file} command.
11993
11994If your @value{GDBN} does not have a @code{load} command, attempting to
11995execute it gets the error message ``@code{You can't do that when your
11996target is @dots{}}''
c906108c
SS
11997
11998The file is loaded at whatever address is specified in the executable.
11999For some object file formats, you can specify the load address when you
12000link the program; for other formats, like a.out, the object file format
12001specifies a fixed address.
12002@c FIXME! This would be a good place for an xref to the GNU linker doc.
12003
c906108c
SS
12004@code{load} does not repeat if you press @key{RET} again after using it.
12005@end table
12006
6d2ebf8b 12007@node Byte Order
c906108c 12008@section Choosing target byte order
7a292a7a 12009
c906108c
SS
12010@cindex choosing target byte order
12011@cindex target byte order
c906108c 12012
172c2a43 12013Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
12014offer the ability to run either big-endian or little-endian byte
12015orders. Usually the executable or symbol will include a bit to
12016designate the endian-ness, and you will not need to worry about
12017which to use. However, you may still find it useful to adjust
d4f3574e 12018@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
12019
12020@table @code
4644b6e3 12021@kindex set endian
c906108c
SS
12022@item set endian big
12023Instruct @value{GDBN} to assume the target is big-endian.
12024
c906108c
SS
12025@item set endian little
12026Instruct @value{GDBN} to assume the target is little-endian.
12027
c906108c
SS
12028@item set endian auto
12029Instruct @value{GDBN} to use the byte order associated with the
12030executable.
12031
12032@item show endian
12033Display @value{GDBN}'s current idea of the target byte order.
12034
12035@end table
12036
12037Note that these commands merely adjust interpretation of symbolic
12038data on the host, and that they have absolutely no effect on the
12039target system.
12040
6d2ebf8b 12041@node Remote
c906108c
SS
12042@section Remote debugging
12043@cindex remote debugging
12044
12045If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
12046@value{GDBN} in the usual way, it is often useful to use remote debugging.
12047For example, you might use remote debugging on an operating system kernel,
c906108c
SS
12048or on a small system which does not have a general purpose operating system
12049powerful enough to run a full-featured debugger.
12050
12051Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
12052to make this work with particular debugging targets. In addition,
5d161b24 12053@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
12054but not specific to any particular target system) which you can use if you
12055write the remote stubs---the code that runs on the remote system to
12056communicate with @value{GDBN}.
12057
12058Other remote targets may be available in your
12059configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 12060
c45da7e6
EZ
12061Once you've connected to the remote target, @value{GDBN} allows you to
12062send arbitrary commands to the remote monitor:
12063
12064@table @code
12065@item remote @var{command}
12066@kindex remote@r{, a command}
12067@cindex send command to remote monitor
12068Send an arbitrary @var{command} string to the remote monitor.
12069@end table
12070
12071
6f05cf9f
AC
12072@node KOD
12073@section Kernel Object Display
6f05cf9f 12074@cindex kernel object display
6f05cf9f
AC
12075@cindex KOD
12076
12077Some targets support kernel object display. Using this facility,
12078@value{GDBN} communicates specially with the underlying operating system
12079and can display information about operating system-level objects such as
12080mutexes and other synchronization objects. Exactly which objects can be
12081displayed is determined on a per-OS basis.
12082
3bbe9696 12083@kindex set os
6f05cf9f
AC
12084Use the @code{set os} command to set the operating system. This tells
12085@value{GDBN} which kernel object display module to initialize:
12086
474c8240 12087@smallexample
6f05cf9f 12088(@value{GDBP}) set os cisco
474c8240 12089@end smallexample
6f05cf9f 12090
3bbe9696
EZ
12091@kindex show os
12092The associated command @code{show os} displays the operating system
12093set with the @code{set os} command; if no operating system has been
12094set, @code{show os} will display an empty string @samp{""}.
12095
6f05cf9f
AC
12096If @code{set os} succeeds, @value{GDBN} will display some information
12097about the operating system, and will create a new @code{info} command
12098which can be used to query the target. The @code{info} command is named
12099after the operating system:
c906108c 12100
3bbe9696 12101@kindex info cisco
474c8240 12102@smallexample
6f05cf9f
AC
12103(@value{GDBP}) info cisco
12104List of Cisco Kernel Objects
12105Object Description
12106any Any and all objects
474c8240 12107@end smallexample
6f05cf9f
AC
12108
12109Further subcommands can be used to query about particular objects known
12110by the kernel.
12111
3bbe9696
EZ
12112There is currently no way to determine whether a given operating
12113system is supported other than to try setting it with @kbd{set os
12114@var{name}}, where @var{name} is the name of the operating system you
12115want to try.
6f05cf9f
AC
12116
12117
12118@node Remote Debugging
12119@chapter Debugging remote programs
12120
6b2f586d 12121@menu
07f31aa6 12122* Connecting:: Connecting to a remote target
6b2f586d
AC
12123* Server:: Using the gdbserver program
12124* NetWare:: Using the gdbserve.nlm program
501eef12 12125* Remote configuration:: Remote configuration
6b2f586d 12126* remote stub:: Implementing a remote stub
6b2f586d
AC
12127@end menu
12128
07f31aa6
DJ
12129@node Connecting
12130@section Connecting to a remote target
12131
12132On the @value{GDBN} host machine, you will need an unstripped copy of
12133your program, since @value{GDBN} needs symobl and debugging information.
12134Start up @value{GDBN} as usual, using the name of the local copy of your
12135program as the first argument.
12136
12137@cindex serial line, @code{target remote}
12138If you're using a serial line, you may want to give @value{GDBN} the
12139@w{@samp{--baud}} option, or use the @code{set remotebaud} command
9c16f35a
EZ
12140(@pxref{Remote configuration, set remotebaud}) before the
12141@code{target} command.
07f31aa6
DJ
12142
12143After that, use @code{target remote} to establish communications with
12144the target machine. Its argument specifies how to communicate---either
12145via a devicename attached to a direct serial line, or a TCP or UDP port
12146(possibly to a terminal server which in turn has a serial line to the
12147target). For example, to use a serial line connected to the device
12148named @file{/dev/ttyb}:
12149
12150@smallexample
12151target remote /dev/ttyb
12152@end smallexample
12153
12154@cindex TCP port, @code{target remote}
12155To use a TCP connection, use an argument of the form
12156@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
12157For example, to connect to port 2828 on a
12158terminal server named @code{manyfarms}:
12159
12160@smallexample
12161target remote manyfarms:2828
12162@end smallexample
12163
12164If your remote target is actually running on the same machine as
12165your debugger session (e.g.@: a simulator of your target running on
12166the same host), you can omit the hostname. For example, to connect
12167to port 1234 on your local machine:
12168
12169@smallexample
12170target remote :1234
12171@end smallexample
12172@noindent
12173
12174Note that the colon is still required here.
12175
12176@cindex UDP port, @code{target remote}
12177To use a UDP connection, use an argument of the form
12178@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
12179on a terminal server named @code{manyfarms}:
12180
12181@smallexample
12182target remote udp:manyfarms:2828
12183@end smallexample
12184
12185When using a UDP connection for remote debugging, you should keep in mind
12186that the `U' stands for ``Unreliable''. UDP can silently drop packets on
12187busy or unreliable networks, which will cause havoc with your debugging
12188session.
12189
12190Now you can use all the usual commands to examine and change data and to
12191step and continue the remote program.
12192
12193@cindex interrupting remote programs
12194@cindex remote programs, interrupting
12195Whenever @value{GDBN} is waiting for the remote program, if you type the
12196interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
12197program. This may or may not succeed, depending in part on the hardware
12198and the serial drivers the remote system uses. If you type the
12199interrupt character once again, @value{GDBN} displays this prompt:
12200
12201@smallexample
12202Interrupted while waiting for the program.
12203Give up (and stop debugging it)? (y or n)
12204@end smallexample
12205
12206If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
12207(If you decide you want to try again later, you can use @samp{target
12208remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
12209goes back to waiting.
12210
12211@table @code
12212@kindex detach (remote)
12213@item detach
12214When you have finished debugging the remote program, you can use the
12215@code{detach} command to release it from @value{GDBN} control.
12216Detaching from the target normally resumes its execution, but the results
12217will depend on your particular remote stub. After the @code{detach}
12218command, @value{GDBN} is free to connect to another target.
12219
12220@kindex disconnect
12221@item disconnect
12222The @code{disconnect} command behaves like @code{detach}, except that
12223the target is generally not resumed. It will wait for @value{GDBN}
12224(this instance or another one) to connect and continue debugging. After
12225the @code{disconnect} command, @value{GDBN} is again free to connect to
12226another target.
09d4efe1
EZ
12227
12228@cindex send command to remote monitor
fad38dfa
EZ
12229@cindex extend @value{GDBN} for remote targets
12230@cindex add new commands for external monitor
09d4efe1
EZ
12231@kindex monitor
12232@item monitor @var{cmd}
fad38dfa
EZ
12233This command allows you to send arbitrary commands directly to the
12234remote monitor. Since @value{GDBN} doesn't care about the commands it
12235sends like this, this command is the way to extend @value{GDBN}---you
12236can add new commands that only the external monitor will understand
12237and implement.
07f31aa6
DJ
12238@end table
12239
6f05cf9f
AC
12240@node Server
12241@section Using the @code{gdbserver} program
12242
12243@kindex gdbserver
12244@cindex remote connection without stubs
12245@code{gdbserver} is a control program for Unix-like systems, which
12246allows you to connect your program with a remote @value{GDBN} via
12247@code{target remote}---but without linking in the usual debugging stub.
12248
12249@code{gdbserver} is not a complete replacement for the debugging stubs,
12250because it requires essentially the same operating-system facilities
12251that @value{GDBN} itself does. In fact, a system that can run
12252@code{gdbserver} to connect to a remote @value{GDBN} could also run
12253@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
12254because it is a much smaller program than @value{GDBN} itself. It is
12255also easier to port than all of @value{GDBN}, so you may be able to get
12256started more quickly on a new system by using @code{gdbserver}.
12257Finally, if you develop code for real-time systems, you may find that
12258the tradeoffs involved in real-time operation make it more convenient to
12259do as much development work as possible on another system, for example
12260by cross-compiling. You can use @code{gdbserver} to make a similar
12261choice for debugging.
12262
12263@value{GDBN} and @code{gdbserver} communicate via either a serial line
12264or a TCP connection, using the standard @value{GDBN} remote serial
12265protocol.
12266
12267@table @emph
12268@item On the target machine,
12269you need to have a copy of the program you want to debug.
12270@code{gdbserver} does not need your program's symbol table, so you can
12271strip the program if necessary to save space. @value{GDBN} on the host
12272system does all the symbol handling.
12273
12274To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 12275the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
12276syntax is:
12277
12278@smallexample
12279target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
12280@end smallexample
12281
12282@var{comm} is either a device name (to use a serial line) or a TCP
12283hostname and portnumber. For example, to debug Emacs with the argument
12284@samp{foo.txt} and communicate with @value{GDBN} over the serial port
12285@file{/dev/com1}:
12286
12287@smallexample
12288target> gdbserver /dev/com1 emacs foo.txt
12289@end smallexample
12290
12291@code{gdbserver} waits passively for the host @value{GDBN} to communicate
12292with it.
12293
12294To use a TCP connection instead of a serial line:
12295
12296@smallexample
12297target> gdbserver host:2345 emacs foo.txt
12298@end smallexample
12299
12300The only difference from the previous example is the first argument,
12301specifying that you are communicating with the host @value{GDBN} via
12302TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
12303expect a TCP connection from machine @samp{host} to local TCP port 2345.
12304(Currently, the @samp{host} part is ignored.) You can choose any number
12305you want for the port number as long as it does not conflict with any
12306TCP ports already in use on the target system (for example, @code{23} is
12307reserved for @code{telnet}).@footnote{If you choose a port number that
12308conflicts with another service, @code{gdbserver} prints an error message
12309and exits.} You must use the same port number with the host @value{GDBN}
12310@code{target remote} command.
12311
56460a61
DJ
12312On some targets, @code{gdbserver} can also attach to running programs.
12313This is accomplished via the @code{--attach} argument. The syntax is:
12314
12315@smallexample
12316target> gdbserver @var{comm} --attach @var{pid}
12317@end smallexample
12318
12319@var{pid} is the process ID of a currently running process. It isn't necessary
12320to point @code{gdbserver} at a binary for the running process.
12321
b1fe9455
DJ
12322@pindex pidof
12323@cindex attach to a program by name
12324You can debug processes by name instead of process ID if your target has the
12325@code{pidof} utility:
12326
12327@smallexample
12328target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
12329@end smallexample
12330
12331In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
12332has multiple threads, most versions of @code{pidof} support the
12333@code{-s} option to only return the first process ID.
12334
07f31aa6
DJ
12335@item On the host machine,
12336connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
12337For TCP connections, you must start up @code{gdbserver} prior to using
12338the @code{target remote} command. Otherwise you may get an error whose
12339text depends on the host system, but which usually looks something like
07f31aa6 12340@samp{Connection refused}. You don't need to use the @code{load}
397ca115
EZ
12341command in @value{GDBN} when using @code{gdbserver}, since the program is
12342already on the target. However, if you want to load the symbols (as
12343you normally would), do that with the @code{file} command, and issue
12344it @emph{before} connecting to the server; otherwise, you will get an
12345error message saying @code{"Program is already running"}, since the
12346program is considered running after the connection.
07f31aa6 12347
6f05cf9f
AC
12348@end table
12349
12350@node NetWare
12351@section Using the @code{gdbserve.nlm} program
12352
12353@kindex gdbserve.nlm
12354@code{gdbserve.nlm} is a control program for NetWare systems, which
12355allows you to connect your program with a remote @value{GDBN} via
12356@code{target remote}.
12357
12358@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
12359using the standard @value{GDBN} remote serial protocol.
12360
12361@table @emph
12362@item On the target machine,
12363you need to have a copy of the program you want to debug.
12364@code{gdbserve.nlm} does not need your program's symbol table, so you
12365can strip the program if necessary to save space. @value{GDBN} on the
12366host system does all the symbol handling.
12367
12368To use the server, you must tell it how to communicate with
12369@value{GDBN}; the name of your program; and the arguments for your
12370program. The syntax is:
12371
12372@smallexample
12373load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
12374 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
12375@end smallexample
12376
12377@var{board} and @var{port} specify the serial line; @var{baud} specifies
12378the baud rate used by the connection. @var{port} and @var{node} default
12379to 0, @var{baud} defaults to 9600@dmn{bps}.
12380
12381For example, to debug Emacs with the argument @samp{foo.txt}and
12382communicate with @value{GDBN} over serial port number 2 or board 1
12383using a 19200@dmn{bps} connection:
12384
12385@smallexample
12386load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
12387@end smallexample
12388
07f31aa6
DJ
12389@item
12390On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
12391Connecting to a remote target}).
6f05cf9f 12392
6f05cf9f
AC
12393@end table
12394
501eef12
AC
12395@node Remote configuration
12396@section Remote configuration
12397
9c16f35a
EZ
12398@kindex set remote
12399@kindex show remote
12400This section documents the configuration options available when
12401debugging remote programs. For the options related to the File I/O
12402extensions of the remote protocol, see @ref{The system call,
12403system-call-allowed}.
501eef12
AC
12404
12405@table @code
9c16f35a
EZ
12406@item set remoteaddresssize @var{bits}
12407@cindex adress size for remote targets
12408@cindex bits in remote address
12409Set the maximum size of address in a memory packet to the specified
12410number of bits. @value{GDBN} will mask off the address bits above
12411that number, when it passes addresses to the remote target. The
12412default value is the number of bits in the target's address.
12413
12414@item show remoteaddresssize
12415Show the current value of remote address size in bits.
12416
12417@item set remotebaud @var{n}
12418@cindex baud rate for remote targets
12419Set the baud rate for the remote serial I/O to @var{n} baud. The
12420value is used to set the speed of the serial port used for debugging
12421remote targets.
12422
12423@item show remotebaud
12424Show the current speed of the remote connection.
12425
12426@item set remotebreak
12427@cindex interrupt remote programs
12428@cindex BREAK signal instead of Ctrl-C
9a6253be 12429@anchor{set remotebreak}
9c16f35a
EZ
12430If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
12431when you press the @key{Ctrl-C} key to interrupt the program running
9a7a1b36 12432on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
12433character instead. The default is off, since most remote systems
12434expect to see @samp{Ctrl-C} as the interrupt signal.
12435
12436@item show remotebreak
12437Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
12438interrupt the remote program.
12439
12440@item set remotedebug
12441@cindex debug remote protocol
12442@cindex remote protocol debugging
12443@cindex display remote packets
12444Control the debugging of the remote protocol. When enabled, each
12445packet sent to or received from the remote target is displayed. The
12446defaults is off.
12447
12448@item show remotedebug
12449Show the current setting of the remote protocol debugging.
12450
12451@item set remotedevice @var{device}
12452@cindex serial port name
12453Set the name of the serial port through which to communicate to the
12454remote target to @var{device}. This is the device used by
12455@value{GDBN} to open the serial communications line to the remote
12456target. There's no default, so you must set a valid port name for the
12457remote serial communications to work. (Some varieties of the
12458@code{target} command accept the port name as part of their
12459arguments.)
12460
12461@item show remotedevice
12462Show the current name of the serial port.
12463
12464@item set remotelogbase @var{base}
12465Set the base (a.k.a.@: radix) of logging serial protocol
12466communications to @var{base}. Supported values of @var{base} are:
12467@code{ascii}, @code{octal}, and @code{hex}. The default is
12468@code{ascii}.
12469
12470@item show remotelogbase
12471Show the current setting of the radix for logging remote serial
12472protocol.
12473
12474@item set remotelogfile @var{file}
12475@cindex record serial communications on file
12476Record remote serial communications on the named @var{file}. The
12477default is not to record at all.
12478
12479@item show remotelogfile.
12480Show the current setting of the file name on which to record the
12481serial communications.
12482
12483@item set remotetimeout @var{num}
12484@cindex timeout for serial communications
12485@cindex remote timeout
12486Set the timeout limit to wait for the remote target to respond to
12487@var{num} seconds. The default is 2 seconds.
12488
12489@item show remotetimeout
12490Show the current number of seconds to wait for the remote target
12491responses.
12492
12493@cindex limit hardware breakpoints and watchpoints
12494@cindex remote target, limit break- and watchpoints
501eef12
AC
12495@anchor{set remote hardware-watchpoint-limit}
12496@anchor{set remote hardware-breakpoint-limit}
12497@item set remote hardware-watchpoint-limit @var{limit}
12498@itemx set remote hardware-breakpoint-limit @var{limit}
12499Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
12500watchpoints. A limit of -1, the default, is treated as unlimited.
9c16f35a
EZ
12501
12502@item set remote fetch-register-packet
12503@itemx set remote set-register-packet
12504@itemx set remote P-packet
12505@itemx set remote p-packet
12506@cindex P-packet
12507@cindex fetch registers from remote targets
12508@cindex set registers in remote targets
12509Determine whether @value{GDBN} can set and fetch registers from the
12510remote target using the @samp{P} packets. The default depends on the
12511remote stub's support of the @samp{P} packets (@value{GDBN} queries
12512the stub when this packet is first required).
12513
12514@item show remote fetch-register-packet
12515@itemx show remote set-register-packet
12516@itemx show remote P-packet
12517@itemx show remote p-packet
12518Show the current setting of using the @samp{P} packets for setting and
12519fetching registers from the remote target.
12520
12521@cindex binary downloads
12522@cindex X-packet
12523@item set remote binary-download-packet
12524@itemx set remote X-packet
12525Determine whether @value{GDBN} sends downloads in binary mode using
12526the @samp{X} packets. The default is on.
12527
12528@item show remote binary-download-packet
12529@itemx show remote X-packet
12530Show the current setting of using the @samp{X} packets for binary
12531downloads.
12532
12533@item set remote read-aux-vector-packet
12534@cindex auxiliary vector of remote target
12535@cindex @code{auxv}, and remote targets
12536Set the use of the remote protocol's @samp{qPart:auxv:read} (target
12537auxiliary vector read) request. This request is used to fetch the
721c2651
EZ
12538remote target's @dfn{auxiliary vector}, see @ref{OS Information,
12539Auxiliary Vector}. The default setting depends on the remote stub's
12540support of this request (@value{GDBN} queries the stub when this
12541request is first required). @xref{General Query Packets, qPart}, for
12542more information about this request.
9c16f35a
EZ
12543
12544@item show remote read-aux-vector-packet
12545Show the current setting of use of the @samp{qPart:auxv:read} request.
12546
12547@item set remote symbol-lookup-packet
12548@cindex remote symbol lookup request
12549Set the use of the remote protocol's @samp{qSymbol} (target symbol
12550lookup) request. This request is used to communicate symbol
12551information to the remote target, e.g., whenever a new shared library
12552is loaded by the remote (@pxref{Files, shared libraries}). The
12553default setting depends on the remote stub's support of this request
12554(@value{GDBN} queries the stub when this request is first required).
12555@xref{General Query Packets, qSymbol}, for more information about this
12556request.
12557
12558@item show remote symbol-lookup-packet
12559Show the current setting of use of the @samp{qSymbol} request.
12560
12561@item set remote verbose-resume-packet
12562@cindex resume remote target
12563@cindex signal thread, and remote targets
12564@cindex single-step thread, and remote targets
12565@cindex thread-specific operations on remote targets
12566Set the use of the remote protocol's @samp{vCont} (descriptive resume)
12567request. This request is used to resume specific threads in the
12568remote target, and to single-step or signal them. The default setting
12569depends on the remote stub's support of this request (@value{GDBN}
12570queries the stub when this request is first required). This setting
12571affects debugging of multithreaded programs: if @samp{vCont} cannot be
12572used, @value{GDBN} might be unable to single-step a specific thread,
12573especially under @code{set scheduler-locking off}; it is also
12574impossible to pause a specific thread. @xref{Packets, vCont}, for
12575more details.
12576
12577@item show remote verbose-resume-packet
12578Show the current setting of use of the @samp{vCont} request
12579
12580@item set remote software-breakpoint-packet
12581@itemx set remote hardware-breakpoint-packet
12582@itemx set remote write-watchpoint-packet
12583@itemx set remote read-watchpoint-packet
12584@itemx set remote access-watchpoint-packet
12585@itemx set remote Z-packet
12586@cindex Z-packet
12587@cindex remote hardware breakpoints and watchpoints
12588These commands enable or disable the use of @samp{Z} packets for
12589setting breakpoints and watchpoints in the remote target. The default
12590depends on the remote stub's support of the @samp{Z} packets
12591(@value{GDBN} queries the stub when each packet is first required).
12592The command @code{set remote Z-packet}, kept for back-compatibility,
12593turns on or off all the features that require the use of @samp{Z}
12594packets.
12595
12596@item show remote software-breakpoint-packet
12597@itemx show remote hardware-breakpoint-packet
12598@itemx show remote write-watchpoint-packet
12599@itemx show remote read-watchpoint-packet
12600@itemx show remote access-watchpoint-packet
12601@itemx show remote Z-packet
12602Show the current setting of @samp{Z} packets usage.
0abb7bc7
EZ
12603
12604@item set remote get-thread-local-storage-address
12605@kindex set remote get-thread-local-storage-address
12606@cindex thread local storage of remote targets
12607This command enables or disables the use of the @samp{qGetTLSAddr}
12608(Get Thread Local Storage Address) request packet. The default
12609depends on whether the remote stub supports this request.
12610@xref{General Query Packets, qGetTLSAddr}, for more details about this
12611packet.
12612
12613@item show remote get-thread-local-storage-address
12614@kindex show remote get-thread-local-storage-address
12615Show the current setting of @samp{qGetTLSAddr} packet usage.
501eef12
AC
12616@end table
12617
6f05cf9f
AC
12618@node remote stub
12619@section Implementing a remote stub
7a292a7a 12620
8e04817f
AC
12621@cindex debugging stub, example
12622@cindex remote stub, example
12623@cindex stub example, remote debugging
12624The stub files provided with @value{GDBN} implement the target side of the
12625communication protocol, and the @value{GDBN} side is implemented in the
12626@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
12627these subroutines to communicate, and ignore the details. (If you're
12628implementing your own stub file, you can still ignore the details: start
12629with one of the existing stub files. @file{sparc-stub.c} is the best
12630organized, and therefore the easiest to read.)
12631
104c1213
JM
12632@cindex remote serial debugging, overview
12633To debug a program running on another machine (the debugging
12634@dfn{target} machine), you must first arrange for all the usual
12635prerequisites for the program to run by itself. For example, for a C
12636program, you need:
c906108c 12637
104c1213
JM
12638@enumerate
12639@item
12640A startup routine to set up the C runtime environment; these usually
12641have a name like @file{crt0}. The startup routine may be supplied by
12642your hardware supplier, or you may have to write your own.
96baa820 12643
5d161b24 12644@item
d4f3574e 12645A C subroutine library to support your program's
104c1213 12646subroutine calls, notably managing input and output.
96baa820 12647
104c1213
JM
12648@item
12649A way of getting your program to the other machine---for example, a
12650download program. These are often supplied by the hardware
12651manufacturer, but you may have to write your own from hardware
12652documentation.
12653@end enumerate
96baa820 12654
104c1213
JM
12655The next step is to arrange for your program to use a serial port to
12656communicate with the machine where @value{GDBN} is running (the @dfn{host}
12657machine). In general terms, the scheme looks like this:
96baa820 12658
104c1213
JM
12659@table @emph
12660@item On the host,
12661@value{GDBN} already understands how to use this protocol; when everything
12662else is set up, you can simply use the @samp{target remote} command
12663(@pxref{Targets,,Specifying a Debugging Target}).
12664
12665@item On the target,
12666you must link with your program a few special-purpose subroutines that
12667implement the @value{GDBN} remote serial protocol. The file containing these
12668subroutines is called a @dfn{debugging stub}.
12669
12670On certain remote targets, you can use an auxiliary program
12671@code{gdbserver} instead of linking a stub into your program.
12672@xref{Server,,Using the @code{gdbserver} program}, for details.
12673@end table
96baa820 12674
104c1213
JM
12675The debugging stub is specific to the architecture of the remote
12676machine; for example, use @file{sparc-stub.c} to debug programs on
12677@sc{sparc} boards.
96baa820 12678
104c1213
JM
12679@cindex remote serial stub list
12680These working remote stubs are distributed with @value{GDBN}:
96baa820 12681
104c1213
JM
12682@table @code
12683
12684@item i386-stub.c
41afff9a 12685@cindex @file{i386-stub.c}
104c1213
JM
12686@cindex Intel
12687@cindex i386
12688For Intel 386 and compatible architectures.
12689
12690@item m68k-stub.c
41afff9a 12691@cindex @file{m68k-stub.c}
104c1213
JM
12692@cindex Motorola 680x0
12693@cindex m680x0
12694For Motorola 680x0 architectures.
12695
12696@item sh-stub.c
41afff9a 12697@cindex @file{sh-stub.c}
172c2a43 12698@cindex Renesas
104c1213 12699@cindex SH
172c2a43 12700For Renesas SH architectures.
104c1213
JM
12701
12702@item sparc-stub.c
41afff9a 12703@cindex @file{sparc-stub.c}
104c1213
JM
12704@cindex Sparc
12705For @sc{sparc} architectures.
12706
12707@item sparcl-stub.c
41afff9a 12708@cindex @file{sparcl-stub.c}
104c1213
JM
12709@cindex Fujitsu
12710@cindex SparcLite
12711For Fujitsu @sc{sparclite} architectures.
12712
12713@end table
12714
12715The @file{README} file in the @value{GDBN} distribution may list other
12716recently added stubs.
12717
12718@menu
12719* Stub Contents:: What the stub can do for you
12720* Bootstrapping:: What you must do for the stub
12721* Debug Session:: Putting it all together
104c1213
JM
12722@end menu
12723
6d2ebf8b 12724@node Stub Contents
6f05cf9f 12725@subsection What the stub can do for you
104c1213
JM
12726
12727@cindex remote serial stub
12728The debugging stub for your architecture supplies these three
12729subroutines:
12730
12731@table @code
12732@item set_debug_traps
4644b6e3 12733@findex set_debug_traps
104c1213
JM
12734@cindex remote serial stub, initialization
12735This routine arranges for @code{handle_exception} to run when your
12736program stops. You must call this subroutine explicitly near the
12737beginning of your program.
12738
12739@item handle_exception
4644b6e3 12740@findex handle_exception
104c1213
JM
12741@cindex remote serial stub, main routine
12742This is the central workhorse, but your program never calls it
12743explicitly---the setup code arranges for @code{handle_exception} to
12744run when a trap is triggered.
12745
12746@code{handle_exception} takes control when your program stops during
12747execution (for example, on a breakpoint), and mediates communications
12748with @value{GDBN} on the host machine. This is where the communications
12749protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 12750representative on the target machine. It begins by sending summary
104c1213
JM
12751information on the state of your program, then continues to execute,
12752retrieving and transmitting any information @value{GDBN} needs, until you
12753execute a @value{GDBN} command that makes your program resume; at that point,
12754@code{handle_exception} returns control to your own code on the target
5d161b24 12755machine.
104c1213
JM
12756
12757@item breakpoint
12758@cindex @code{breakpoint} subroutine, remote
12759Use this auxiliary subroutine to make your program contain a
12760breakpoint. Depending on the particular situation, this may be the only
12761way for @value{GDBN} to get control. For instance, if your target
12762machine has some sort of interrupt button, you won't need to call this;
12763pressing the interrupt button transfers control to
12764@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
12765simply receiving characters on the serial port may also trigger a trap;
12766again, in that situation, you don't need to call @code{breakpoint} from
12767your own program---simply running @samp{target remote} from the host
5d161b24 12768@value{GDBN} session gets control.
104c1213
JM
12769
12770Call @code{breakpoint} if none of these is true, or if you simply want
12771to make certain your program stops at a predetermined point for the
12772start of your debugging session.
12773@end table
12774
6d2ebf8b 12775@node Bootstrapping
6f05cf9f 12776@subsection What you must do for the stub
104c1213
JM
12777
12778@cindex remote stub, support routines
12779The debugging stubs that come with @value{GDBN} are set up for a particular
12780chip architecture, but they have no information about the rest of your
12781debugging target machine.
12782
12783First of all you need to tell the stub how to communicate with the
12784serial port.
12785
12786@table @code
12787@item int getDebugChar()
4644b6e3 12788@findex getDebugChar
104c1213
JM
12789Write this subroutine to read a single character from the serial port.
12790It may be identical to @code{getchar} for your target system; a
12791different name is used to allow you to distinguish the two if you wish.
12792
12793@item void putDebugChar(int)
4644b6e3 12794@findex putDebugChar
104c1213 12795Write this subroutine to write a single character to the serial port.
5d161b24 12796It may be identical to @code{putchar} for your target system; a
104c1213
JM
12797different name is used to allow you to distinguish the two if you wish.
12798@end table
12799
12800@cindex control C, and remote debugging
12801@cindex interrupting remote targets
12802If you want @value{GDBN} to be able to stop your program while it is
12803running, you need to use an interrupt-driven serial driver, and arrange
12804for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
12805character). That is the character which @value{GDBN} uses to tell the
12806remote system to stop.
12807
12808Getting the debugging target to return the proper status to @value{GDBN}
12809probably requires changes to the standard stub; one quick and dirty way
12810is to just execute a breakpoint instruction (the ``dirty'' part is that
12811@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
12812
12813Other routines you need to supply are:
12814
12815@table @code
12816@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 12817@findex exceptionHandler
104c1213
JM
12818Write this function to install @var{exception_address} in the exception
12819handling tables. You need to do this because the stub does not have any
12820way of knowing what the exception handling tables on your target system
12821are like (for example, the processor's table might be in @sc{rom},
12822containing entries which point to a table in @sc{ram}).
12823@var{exception_number} is the exception number which should be changed;
12824its meaning is architecture-dependent (for example, different numbers
12825might represent divide by zero, misaligned access, etc). When this
12826exception occurs, control should be transferred directly to
12827@var{exception_address}, and the processor state (stack, registers,
12828and so on) should be just as it is when a processor exception occurs. So if
12829you want to use a jump instruction to reach @var{exception_address}, it
12830should be a simple jump, not a jump to subroutine.
12831
12832For the 386, @var{exception_address} should be installed as an interrupt
12833gate so that interrupts are masked while the handler runs. The gate
12834should be at privilege level 0 (the most privileged level). The
12835@sc{sparc} and 68k stubs are able to mask interrupts themselves without
12836help from @code{exceptionHandler}.
12837
12838@item void flush_i_cache()
4644b6e3 12839@findex flush_i_cache
d4f3574e 12840On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
12841instruction cache, if any, on your target machine. If there is no
12842instruction cache, this subroutine may be a no-op.
12843
12844On target machines that have instruction caches, @value{GDBN} requires this
12845function to make certain that the state of your program is stable.
12846@end table
12847
12848@noindent
12849You must also make sure this library routine is available:
12850
12851@table @code
12852@item void *memset(void *, int, int)
4644b6e3 12853@findex memset
104c1213
JM
12854This is the standard library function @code{memset} that sets an area of
12855memory to a known value. If you have one of the free versions of
12856@code{libc.a}, @code{memset} can be found there; otherwise, you must
12857either obtain it from your hardware manufacturer, or write your own.
12858@end table
12859
12860If you do not use the GNU C compiler, you may need other standard
12861library subroutines as well; this varies from one stub to another,
12862but in general the stubs are likely to use any of the common library
d4f3574e 12863subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
12864
12865
6d2ebf8b 12866@node Debug Session
6f05cf9f 12867@subsection Putting it all together
104c1213
JM
12868
12869@cindex remote serial debugging summary
12870In summary, when your program is ready to debug, you must follow these
12871steps.
12872
12873@enumerate
12874@item
6d2ebf8b 12875Make sure you have defined the supporting low-level routines
104c1213
JM
12876(@pxref{Bootstrapping,,What you must do for the stub}):
12877@display
12878@code{getDebugChar}, @code{putDebugChar},
12879@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
12880@end display
12881
12882@item
12883Insert these lines near the top of your program:
12884
474c8240 12885@smallexample
104c1213
JM
12886set_debug_traps();
12887breakpoint();
474c8240 12888@end smallexample
104c1213
JM
12889
12890@item
12891For the 680x0 stub only, you need to provide a variable called
12892@code{exceptionHook}. Normally you just use:
12893
474c8240 12894@smallexample
104c1213 12895void (*exceptionHook)() = 0;
474c8240 12896@end smallexample
104c1213 12897
d4f3574e 12898@noindent
104c1213 12899but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 12900function in your program, that function is called when
104c1213
JM
12901@code{@value{GDBN}} continues after stopping on a trap (for example, bus
12902error). The function indicated by @code{exceptionHook} is called with
12903one parameter: an @code{int} which is the exception number.
12904
12905@item
12906Compile and link together: your program, the @value{GDBN} debugging stub for
12907your target architecture, and the supporting subroutines.
12908
12909@item
12910Make sure you have a serial connection between your target machine and
12911the @value{GDBN} host, and identify the serial port on the host.
12912
12913@item
12914@c The "remote" target now provides a `load' command, so we should
12915@c document that. FIXME.
12916Download your program to your target machine (or get it there by
12917whatever means the manufacturer provides), and start it.
12918
12919@item
07f31aa6
DJ
12920Start @value{GDBN} on the host, and connect to the target
12921(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 12922
104c1213
JM
12923@end enumerate
12924
8e04817f
AC
12925@node Configurations
12926@chapter Configuration-Specific Information
104c1213 12927
8e04817f
AC
12928While nearly all @value{GDBN} commands are available for all native and
12929cross versions of the debugger, there are some exceptions. This chapter
12930describes things that are only available in certain configurations.
104c1213 12931
8e04817f
AC
12932There are three major categories of configurations: native
12933configurations, where the host and target are the same, embedded
12934operating system configurations, which are usually the same for several
12935different processor architectures, and bare embedded processors, which
12936are quite different from each other.
104c1213 12937
8e04817f
AC
12938@menu
12939* Native::
12940* Embedded OS::
12941* Embedded Processors::
12942* Architectures::
12943@end menu
104c1213 12944
8e04817f
AC
12945@node Native
12946@section Native
104c1213 12947
8e04817f
AC
12948This section describes details specific to particular native
12949configurations.
6cf7e474 12950
8e04817f
AC
12951@menu
12952* HP-UX:: HP-UX
7561d450 12953* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
12954* SVR4 Process Information:: SVR4 process information
12955* DJGPP Native:: Features specific to the DJGPP port
78c47bea 12956* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 12957* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 12958* Neutrino:: Features specific to QNX Neutrino
8e04817f 12959@end menu
6cf7e474 12960
8e04817f
AC
12961@node HP-UX
12962@subsection HP-UX
104c1213 12963
8e04817f
AC
12964On HP-UX systems, if you refer to a function or variable name that
12965begins with a dollar sign, @value{GDBN} searches for a user or system
12966name first, before it searches for a convenience variable.
104c1213 12967
9c16f35a 12968
7561d450
MK
12969@node BSD libkvm Interface
12970@subsection BSD libkvm Interface
12971
12972@cindex libkvm
12973@cindex kernel memory image
12974@cindex kernel crash dump
12975
12976BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
12977interface that provides a uniform interface for accessing kernel virtual
12978memory images, including live systems and crash dumps. @value{GDBN}
12979uses this interface to allow you to debug live kernels and kernel crash
12980dumps on many native BSD configurations. This is implemented as a
12981special @code{kvm} debugging target. For debugging a live system, load
12982the currently running kernel into @value{GDBN} and connect to the
12983@code{kvm} target:
12984
12985@smallexample
12986(@value{GDBP}) @b{target kvm}
12987@end smallexample
12988
12989For debugging crash dumps, provide the file name of the crash dump as an
12990argument:
12991
12992@smallexample
12993(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
12994@end smallexample
12995
12996Once connected to the @code{kvm} target, the following commands are
12997available:
12998
12999@table @code
13000@kindex kvm
13001@item kvm pcb
721c2651 13002Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
13003
13004@item kvm proc
13005Set current context from proc address. This command isn't available on
13006modern FreeBSD systems.
13007@end table
13008
8e04817f
AC
13009@node SVR4 Process Information
13010@subsection SVR4 process information
60bf7e09
EZ
13011@cindex /proc
13012@cindex examine process image
13013@cindex process info via @file{/proc}
104c1213 13014
60bf7e09
EZ
13015Many versions of SVR4 and compatible systems provide a facility called
13016@samp{/proc} that can be used to examine the image of a running
13017process using file-system subroutines. If @value{GDBN} is configured
13018for an operating system with this facility, the command @code{info
13019proc} is available to report information about the process running
13020your program, or about any process running on your system. @code{info
13021proc} works only on SVR4 systems that include the @code{procfs} code.
13022This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
13023Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 13024
8e04817f
AC
13025@table @code
13026@kindex info proc
60bf7e09 13027@cindex process ID
8e04817f 13028@item info proc
60bf7e09
EZ
13029@itemx info proc @var{process-id}
13030Summarize available information about any running process. If a
13031process ID is specified by @var{process-id}, display information about
13032that process; otherwise display information about the program being
13033debugged. The summary includes the debugged process ID, the command
13034line used to invoke it, its current working directory, and its
13035executable file's absolute file name.
13036
13037On some systems, @var{process-id} can be of the form
13038@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
13039within a process. If the optional @var{pid} part is missing, it means
13040a thread from the process being debugged (the leading @samp{/} still
13041needs to be present, or else @value{GDBN} will interpret the number as
13042a process ID rather than a thread ID).
6cf7e474 13043
8e04817f 13044@item info proc mappings
60bf7e09
EZ
13045@cindex memory address space mappings
13046Report the memory address space ranges accessible in the program, with
13047information on whether the process has read, write, or execute access
13048rights to each range. On @sc{gnu}/Linux systems, each memory range
13049includes the object file which is mapped to that range, instead of the
13050memory access rights to that range.
13051
13052@item info proc stat
13053@itemx info proc status
13054@cindex process detailed status information
13055These subcommands are specific to @sc{gnu}/Linux systems. They show
13056the process-related information, including the user ID and group ID;
13057how many threads are there in the process; its virtual memory usage;
13058the signals that are pending, blocked, and ignored; its TTY; its
13059consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 13060value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
13061(type @kbd{man 5 proc} from your shell prompt).
13062
13063@item info proc all
13064Show all the information about the process described under all of the
13065above @code{info proc} subcommands.
13066
8e04817f
AC
13067@ignore
13068@comment These sub-options of 'info proc' were not included when
13069@comment procfs.c was re-written. Keep their descriptions around
13070@comment against the day when someone finds the time to put them back in.
13071@kindex info proc times
13072@item info proc times
13073Starting time, user CPU time, and system CPU time for your program and
13074its children.
6cf7e474 13075
8e04817f
AC
13076@kindex info proc id
13077@item info proc id
13078Report on the process IDs related to your program: its own process ID,
13079the ID of its parent, the process group ID, and the session ID.
8e04817f 13080@end ignore
721c2651
EZ
13081
13082@item set procfs-trace
13083@kindex set procfs-trace
13084@cindex @code{procfs} API calls
13085This command enables and disables tracing of @code{procfs} API calls.
13086
13087@item show procfs-trace
13088@kindex show procfs-trace
13089Show the current state of @code{procfs} API call tracing.
13090
13091@item set procfs-file @var{file}
13092@kindex set procfs-file
13093Tell @value{GDBN} to write @code{procfs} API trace to the named
13094@var{file}. @value{GDBN} appends the trace info to the previous
13095contents of the file. The default is to display the trace on the
13096standard output.
13097
13098@item show procfs-file
13099@kindex show procfs-file
13100Show the file to which @code{procfs} API trace is written.
13101
13102@item proc-trace-entry
13103@itemx proc-trace-exit
13104@itemx proc-untrace-entry
13105@itemx proc-untrace-exit
13106@kindex proc-trace-entry
13107@kindex proc-trace-exit
13108@kindex proc-untrace-entry
13109@kindex proc-untrace-exit
13110These commands enable and disable tracing of entries into and exits
13111from the @code{syscall} interface.
13112
13113@item info pidlist
13114@kindex info pidlist
13115@cindex process list, QNX Neutrino
13116For QNX Neutrino only, this command displays the list of all the
13117processes and all the threads within each process.
13118
13119@item info meminfo
13120@kindex info meminfo
13121@cindex mapinfo list, QNX Neutrino
13122For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 13123@end table
104c1213 13124
8e04817f
AC
13125@node DJGPP Native
13126@subsection Features for Debugging @sc{djgpp} Programs
13127@cindex @sc{djgpp} debugging
13128@cindex native @sc{djgpp} debugging
13129@cindex MS-DOS-specific commands
104c1213 13130
514c4d71
EZ
13131@cindex DPMI
13132@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
13133MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
13134that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
13135top of real-mode DOS systems and their emulations.
104c1213 13136
8e04817f
AC
13137@value{GDBN} supports native debugging of @sc{djgpp} programs, and
13138defines a few commands specific to the @sc{djgpp} port. This
13139subsection describes those commands.
104c1213 13140
8e04817f
AC
13141@table @code
13142@kindex info dos
13143@item info dos
13144This is a prefix of @sc{djgpp}-specific commands which print
13145information about the target system and important OS structures.
f1251bdd 13146
8e04817f
AC
13147@kindex sysinfo
13148@cindex MS-DOS system info
13149@cindex free memory information (MS-DOS)
13150@item info dos sysinfo
13151This command displays assorted information about the underlying
13152platform: the CPU type and features, the OS version and flavor, the
13153DPMI version, and the available conventional and DPMI memory.
104c1213 13154
8e04817f
AC
13155@cindex GDT
13156@cindex LDT
13157@cindex IDT
13158@cindex segment descriptor tables
13159@cindex descriptor tables display
13160@item info dos gdt
13161@itemx info dos ldt
13162@itemx info dos idt
13163These 3 commands display entries from, respectively, Global, Local,
13164and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
13165tables are data structures which store a descriptor for each segment
13166that is currently in use. The segment's selector is an index into a
13167descriptor table; the table entry for that index holds the
13168descriptor's base address and limit, and its attributes and access
13169rights.
104c1213 13170
8e04817f
AC
13171A typical @sc{djgpp} program uses 3 segments: a code segment, a data
13172segment (used for both data and the stack), and a DOS segment (which
13173allows access to DOS/BIOS data structures and absolute addresses in
13174conventional memory). However, the DPMI host will usually define
13175additional segments in order to support the DPMI environment.
d4f3574e 13176
8e04817f
AC
13177@cindex garbled pointers
13178These commands allow to display entries from the descriptor tables.
13179Without an argument, all entries from the specified table are
13180displayed. An argument, which should be an integer expression, means
13181display a single entry whose index is given by the argument. For
13182example, here's a convenient way to display information about the
13183debugged program's data segment:
104c1213 13184
8e04817f
AC
13185@smallexample
13186@exdent @code{(@value{GDBP}) info dos ldt $ds}
13187@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
13188@end smallexample
104c1213 13189
8e04817f
AC
13190@noindent
13191This comes in handy when you want to see whether a pointer is outside
13192the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 13193
8e04817f
AC
13194@cindex page tables display (MS-DOS)
13195@item info dos pde
13196@itemx info dos pte
13197These two commands display entries from, respectively, the Page
13198Directory and the Page Tables. Page Directories and Page Tables are
13199data structures which control how virtual memory addresses are mapped
13200into physical addresses. A Page Table includes an entry for every
13201page of memory that is mapped into the program's address space; there
13202may be several Page Tables, each one holding up to 4096 entries. A
13203Page Directory has up to 4096 entries, one each for every Page Table
13204that is currently in use.
104c1213 13205
8e04817f
AC
13206Without an argument, @kbd{info dos pde} displays the entire Page
13207Directory, and @kbd{info dos pte} displays all the entries in all of
13208the Page Tables. An argument, an integer expression, given to the
13209@kbd{info dos pde} command means display only that entry from the Page
13210Directory table. An argument given to the @kbd{info dos pte} command
13211means display entries from a single Page Table, the one pointed to by
13212the specified entry in the Page Directory.
104c1213 13213
8e04817f
AC
13214@cindex direct memory access (DMA) on MS-DOS
13215These commands are useful when your program uses @dfn{DMA} (Direct
13216Memory Access), which needs physical addresses to program the DMA
13217controller.
104c1213 13218
8e04817f 13219These commands are supported only with some DPMI servers.
104c1213 13220
8e04817f
AC
13221@cindex physical address from linear address
13222@item info dos address-pte @var{addr}
13223This command displays the Page Table entry for a specified linear
514c4d71
EZ
13224address. The argument @var{addr} is a linear address which should
13225already have the appropriate segment's base address added to it,
13226because this command accepts addresses which may belong to @emph{any}
13227segment. For example, here's how to display the Page Table entry for
13228the page where a variable @code{i} is stored:
104c1213 13229
b383017d 13230@smallexample
8e04817f
AC
13231@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
13232@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 13233@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 13234@end smallexample
104c1213 13235
8e04817f
AC
13236@noindent
13237This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 13238whose physical base address is @code{0x02698000}, and shows all the
8e04817f 13239attributes of that page.
104c1213 13240
8e04817f
AC
13241Note that you must cast the addresses of variables to a @code{char *},
13242since otherwise the value of @code{__djgpp_base_address}, the base
13243address of all variables and functions in a @sc{djgpp} program, will
13244be added using the rules of C pointer arithmetics: if @code{i} is
13245declared an @code{int}, @value{GDBN} will add 4 times the value of
13246@code{__djgpp_base_address} to the address of @code{i}.
104c1213 13247
8e04817f
AC
13248Here's another example, it displays the Page Table entry for the
13249transfer buffer:
104c1213 13250
8e04817f
AC
13251@smallexample
13252@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
13253@exdent @code{Page Table entry for address 0x29110:}
13254@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
13255@end smallexample
104c1213 13256
8e04817f
AC
13257@noindent
13258(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
132593rd member of the @code{_go32_info_block} structure.) The output
13260clearly shows that this DPMI server maps the addresses in conventional
13261memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
13262linear (@code{0x29110}) addresses are identical.
104c1213 13263
8e04817f
AC
13264This command is supported only with some DPMI servers.
13265@end table
104c1213 13266
c45da7e6 13267@cindex DOS serial data link, remote debugging
a8f24a35
EZ
13268In addition to native debugging, the DJGPP port supports remote
13269debugging via a serial data link. The following commands are specific
13270to remote serial debugging in the DJGPP port of @value{GDBN}.
13271
13272@table @code
13273@kindex set com1base
13274@kindex set com1irq
13275@kindex set com2base
13276@kindex set com2irq
13277@kindex set com3base
13278@kindex set com3irq
13279@kindex set com4base
13280@kindex set com4irq
13281@item set com1base @var{addr}
13282This command sets the base I/O port address of the @file{COM1} serial
13283port.
13284
13285@item set com1irq @var{irq}
13286This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
13287for the @file{COM1} serial port.
13288
13289There are similar commands @samp{set com2base}, @samp{set com3irq},
13290etc.@: for setting the port address and the @code{IRQ} lines for the
13291other 3 COM ports.
13292
13293@kindex show com1base
13294@kindex show com1irq
13295@kindex show com2base
13296@kindex show com2irq
13297@kindex show com3base
13298@kindex show com3irq
13299@kindex show com4base
13300@kindex show com4irq
13301The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
13302display the current settings of the base address and the @code{IRQ}
13303lines used by the COM ports.
c45da7e6
EZ
13304
13305@item info serial
13306@kindex info serial
13307@cindex DOS serial port status
13308This command prints the status of the 4 DOS serial ports. For each
13309port, it prints whether it's active or not, its I/O base address and
13310IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
13311counts of various errors encountered so far.
a8f24a35
EZ
13312@end table
13313
13314
78c47bea
PM
13315@node Cygwin Native
13316@subsection Features for Debugging MS Windows PE executables
13317@cindex MS Windows debugging
13318@cindex native Cygwin debugging
13319@cindex Cygwin-specific commands
13320
be448670
CF
13321@value{GDBN} supports native debugging of MS Windows programs, including
13322DLLs with and without symbolic debugging information. There are various
13323additional Cygwin-specific commands, described in this subsection. The
13324subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
13325that have no debugging symbols.
13326
78c47bea
PM
13327
13328@table @code
13329@kindex info w32
13330@item info w32
13331This is a prefix of MS Windows specific commands which print
13332information about the target system and important OS structures.
13333
13334@item info w32 selector
13335This command displays information returned by
13336the Win32 API @code{GetThreadSelectorEntry} function.
13337It takes an optional argument that is evaluated to
13338a long value to give the information about this given selector.
13339Without argument, this command displays information
13340about the the six segment registers.
13341
13342@kindex info dll
13343@item info dll
13344This is a Cygwin specific alias of info shared.
13345
13346@kindex dll-symbols
13347@item dll-symbols
13348This command loads symbols from a dll similarly to
13349add-sym command but without the need to specify a base address.
13350
b383017d 13351@kindex set new-console
78c47bea 13352@item set new-console @var{mode}
b383017d 13353If @var{mode} is @code{on} the debuggee will
78c47bea
PM
13354be started in a new console on next start.
13355If @var{mode} is @code{off}i, the debuggee will
13356be started in the same console as the debugger.
13357
13358@kindex show new-console
13359@item show new-console
13360Displays whether a new console is used
13361when the debuggee is started.
13362
13363@kindex set new-group
13364@item set new-group @var{mode}
13365This boolean value controls whether the debuggee should
13366start a new group or stay in the same group as the debugger.
13367This affects the way the Windows OS handles
13368Ctrl-C.
13369
13370@kindex show new-group
13371@item show new-group
13372Displays current value of new-group boolean.
13373
13374@kindex set debugevents
13375@item set debugevents
13376This boolean value adds debug output concerning events seen by the debugger.
13377
13378@kindex set debugexec
13379@item set debugexec
b383017d 13380This boolean value adds debug output concerning execute events
78c47bea
PM
13381seen by the debugger.
13382
13383@kindex set debugexceptions
13384@item set debugexceptions
b383017d 13385This boolean value adds debug ouptut concerning exception events
78c47bea
PM
13386seen by the debugger.
13387
13388@kindex set debugmemory
13389@item set debugmemory
b383017d 13390This boolean value adds debug ouptut concerning memory events
78c47bea
PM
13391seen by the debugger.
13392
13393@kindex set shell
13394@item set shell
13395This boolean values specifies whether the debuggee is called
13396via a shell or directly (default value is on).
13397
13398@kindex show shell
13399@item show shell
13400Displays if the debuggee will be started with a shell.
13401
13402@end table
13403
be448670
CF
13404@menu
13405* Non-debug DLL symbols:: Support for DLLs without debugging symbols
13406@end menu
13407
13408@node Non-debug DLL symbols
13409@subsubsection Support for DLLs without debugging symbols
13410@cindex DLLs with no debugging symbols
13411@cindex Minimal symbols and DLLs
13412
13413Very often on windows, some of the DLLs that your program relies on do
13414not include symbolic debugging information (for example,
13415@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
13416symbols in a DLL, it relies on the minimal amount of symbolic
13417information contained in the DLL's export table. This subsubsection
13418describes working with such symbols, known internally to @value{GDBN} as
13419``minimal symbols''.
13420
13421Note that before the debugged program has started execution, no DLLs
13422will have been loaded. The easiest way around this problem is simply to
13423start the program --- either by setting a breakpoint or letting the
13424program run once to completion. It is also possible to force
13425@value{GDBN} to load a particular DLL before starting the executable ---
13426see the shared library information in @pxref{Files} or the
13427@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
13428explicitly loading symbols from a DLL with no debugging information will
13429cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
13430which may adversely affect symbol lookup performance.
13431
13432@subsubsection DLL name prefixes
13433
13434In keeping with the naming conventions used by the Microsoft debugging
13435tools, DLL export symbols are made available with a prefix based on the
13436DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
13437also entered into the symbol table, so @code{CreateFileA} is often
13438sufficient. In some cases there will be name clashes within a program
13439(particularly if the executable itself includes full debugging symbols)
13440necessitating the use of the fully qualified name when referring to the
13441contents of the DLL. Use single-quotes around the name to avoid the
13442exclamation mark (``!'') being interpreted as a language operator.
13443
13444Note that the internal name of the DLL may be all upper-case, even
13445though the file name of the DLL is lower-case, or vice-versa. Since
13446symbols within @value{GDBN} are @emph{case-sensitive} this may cause
13447some confusion. If in doubt, try the @code{info functions} and
13448@code{info variables} commands or even @code{maint print msymbols} (see
13449@pxref{Symbols}). Here's an example:
13450
13451@smallexample
f7dc1244 13452(@value{GDBP}) info function CreateFileA
be448670
CF
13453All functions matching regular expression "CreateFileA":
13454
13455Non-debugging symbols:
134560x77e885f4 CreateFileA
134570x77e885f4 KERNEL32!CreateFileA
13458@end smallexample
13459
13460@smallexample
f7dc1244 13461(@value{GDBP}) info function !
be448670
CF
13462All functions matching regular expression "!":
13463
13464Non-debugging symbols:
134650x6100114c cygwin1!__assert
134660x61004034 cygwin1!_dll_crt0@@0
134670x61004240 cygwin1!dll_crt0(per_process *)
13468[etc...]
13469@end smallexample
13470
13471@subsubsection Working with minimal symbols
13472
13473Symbols extracted from a DLL's export table do not contain very much
13474type information. All that @value{GDBN} can do is guess whether a symbol
13475refers to a function or variable depending on the linker section that
13476contains the symbol. Also note that the actual contents of the memory
13477contained in a DLL are not available unless the program is running. This
13478means that you cannot examine the contents of a variable or disassemble
13479a function within a DLL without a running program.
13480
13481Variables are generally treated as pointers and dereferenced
13482automatically. For this reason, it is often necessary to prefix a
13483variable name with the address-of operator (``&'') and provide explicit
13484type information in the command. Here's an example of the type of
13485problem:
13486
13487@smallexample
f7dc1244 13488(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
13489$1 = 268572168
13490@end smallexample
13491
13492@smallexample
f7dc1244 13493(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
134940x10021610: "\230y\""
13495@end smallexample
13496
13497And two possible solutions:
13498
13499@smallexample
f7dc1244 13500(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
13501$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
13502@end smallexample
13503
13504@smallexample
f7dc1244 13505(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 135060x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 13507(@value{GDBP}) x/x 0x10021608
be448670 135080x10021608: 0x0022fd98
f7dc1244 13509(@value{GDBP}) x/s 0x0022fd98
be448670
CF
135100x22fd98: "/cygdrive/c/mydirectory/myprogram"
13511@end smallexample
13512
13513Setting a break point within a DLL is possible even before the program
13514starts execution. However, under these circumstances, @value{GDBN} can't
13515examine the initial instructions of the function in order to skip the
13516function's frame set-up code. You can work around this by using ``*&''
13517to set the breakpoint at a raw memory address:
13518
13519@smallexample
f7dc1244 13520(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
13521Breakpoint 1 at 0x1e04eff0
13522@end smallexample
13523
13524The author of these extensions is not entirely convinced that setting a
13525break point within a shared DLL like @file{kernel32.dll} is completely
13526safe.
13527
14d6dd68
EZ
13528@node Hurd Native
13529@subsection Commands specific to @sc{gnu} Hurd systems
13530@cindex @sc{gnu} Hurd debugging
13531
13532This subsection describes @value{GDBN} commands specific to the
13533@sc{gnu} Hurd native debugging.
13534
13535@table @code
13536@item set signals
13537@itemx set sigs
13538@kindex set signals@r{, Hurd command}
13539@kindex set sigs@r{, Hurd command}
13540This command toggles the state of inferior signal interception by
13541@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
13542affected by this command. @code{sigs} is a shorthand alias for
13543@code{signals}.
13544
13545@item show signals
13546@itemx show sigs
13547@kindex show signals@r{, Hurd command}
13548@kindex show sigs@r{, Hurd command}
13549Show the current state of intercepting inferior's signals.
13550
13551@item set signal-thread
13552@itemx set sigthread
13553@kindex set signal-thread
13554@kindex set sigthread
13555This command tells @value{GDBN} which thread is the @code{libc} signal
13556thread. That thread is run when a signal is delivered to a running
13557process. @code{set sigthread} is the shorthand alias of @code{set
13558signal-thread}.
13559
13560@item show signal-thread
13561@itemx show sigthread
13562@kindex show signal-thread
13563@kindex show sigthread
13564These two commands show which thread will run when the inferior is
13565delivered a signal.
13566
13567@item set stopped
13568@kindex set stopped@r{, Hurd command}
13569This commands tells @value{GDBN} that the inferior process is stopped,
13570as with the @code{SIGSTOP} signal. The stopped process can be
13571continued by delivering a signal to it.
13572
13573@item show stopped
13574@kindex show stopped@r{, Hurd command}
13575This command shows whether @value{GDBN} thinks the debuggee is
13576stopped.
13577
13578@item set exceptions
13579@kindex set exceptions@r{, Hurd command}
13580Use this command to turn off trapping of exceptions in the inferior.
13581When exception trapping is off, neither breakpoints nor
13582single-stepping will work. To restore the default, set exception
13583trapping on.
13584
13585@item show exceptions
13586@kindex show exceptions@r{, Hurd command}
13587Show the current state of trapping exceptions in the inferior.
13588
13589@item set task pause
13590@kindex set task@r{, Hurd commands}
13591@cindex task attributes (@sc{gnu} Hurd)
13592@cindex pause current task (@sc{gnu} Hurd)
13593This command toggles task suspension when @value{GDBN} has control.
13594Setting it to on takes effect immediately, and the task is suspended
13595whenever @value{GDBN} gets control. Setting it to off will take
13596effect the next time the inferior is continued. If this option is set
13597to off, you can use @code{set thread default pause on} or @code{set
13598thread pause on} (see below) to pause individual threads.
13599
13600@item show task pause
13601@kindex show task@r{, Hurd commands}
13602Show the current state of task suspension.
13603
13604@item set task detach-suspend-count
13605@cindex task suspend count
13606@cindex detach from task, @sc{gnu} Hurd
13607This command sets the suspend count the task will be left with when
13608@value{GDBN} detaches from it.
13609
13610@item show task detach-suspend-count
13611Show the suspend count the task will be left with when detaching.
13612
13613@item set task exception-port
13614@itemx set task excp
13615@cindex task exception port, @sc{gnu} Hurd
13616This command sets the task exception port to which @value{GDBN} will
13617forward exceptions. The argument should be the value of the @dfn{send
13618rights} of the task. @code{set task excp} is a shorthand alias.
13619
13620@item set noninvasive
13621@cindex noninvasive task options
13622This command switches @value{GDBN} to a mode that is the least
13623invasive as far as interfering with the inferior is concerned. This
13624is the same as using @code{set task pause}, @code{set exceptions}, and
13625@code{set signals} to values opposite to the defaults.
13626
13627@item info send-rights
13628@itemx info receive-rights
13629@itemx info port-rights
13630@itemx info port-sets
13631@itemx info dead-names
13632@itemx info ports
13633@itemx info psets
13634@cindex send rights, @sc{gnu} Hurd
13635@cindex receive rights, @sc{gnu} Hurd
13636@cindex port rights, @sc{gnu} Hurd
13637@cindex port sets, @sc{gnu} Hurd
13638@cindex dead names, @sc{gnu} Hurd
13639These commands display information about, respectively, send rights,
13640receive rights, port rights, port sets, and dead names of a task.
13641There are also shorthand aliases: @code{info ports} for @code{info
13642port-rights} and @code{info psets} for @code{info port-sets}.
13643
13644@item set thread pause
13645@kindex set thread@r{, Hurd command}
13646@cindex thread properties, @sc{gnu} Hurd
13647@cindex pause current thread (@sc{gnu} Hurd)
13648This command toggles current thread suspension when @value{GDBN} has
13649control. Setting it to on takes effect immediately, and the current
13650thread is suspended whenever @value{GDBN} gets control. Setting it to
13651off will take effect the next time the inferior is continued.
13652Normally, this command has no effect, since when @value{GDBN} has
13653control, the whole task is suspended. However, if you used @code{set
13654task pause off} (see above), this command comes in handy to suspend
13655only the current thread.
13656
13657@item show thread pause
13658@kindex show thread@r{, Hurd command}
13659This command shows the state of current thread suspension.
13660
13661@item set thread run
13662This comamnd sets whether the current thread is allowed to run.
13663
13664@item show thread run
13665Show whether the current thread is allowed to run.
13666
13667@item set thread detach-suspend-count
13668@cindex thread suspend count, @sc{gnu} Hurd
13669@cindex detach from thread, @sc{gnu} Hurd
13670This command sets the suspend count @value{GDBN} will leave on a
13671thread when detaching. This number is relative to the suspend count
13672found by @value{GDBN} when it notices the thread; use @code{set thread
13673takeover-suspend-count} to force it to an absolute value.
13674
13675@item show thread detach-suspend-count
13676Show the suspend count @value{GDBN} will leave on the thread when
13677detaching.
13678
13679@item set thread exception-port
13680@itemx set thread excp
13681Set the thread exception port to which to forward exceptions. This
13682overrides the port set by @code{set task exception-port} (see above).
13683@code{set thread excp} is the shorthand alias.
13684
13685@item set thread takeover-suspend-count
13686Normally, @value{GDBN}'s thread suspend counts are relative to the
13687value @value{GDBN} finds when it notices each thread. This command
13688changes the suspend counts to be absolute instead.
13689
13690@item set thread default
13691@itemx show thread default
13692@cindex thread default settings, @sc{gnu} Hurd
13693Each of the above @code{set thread} commands has a @code{set thread
13694default} counterpart (e.g., @code{set thread default pause}, @code{set
13695thread default exception-port}, etc.). The @code{thread default}
13696variety of commands sets the default thread properties for all
13697threads; you can then change the properties of individual threads with
13698the non-default commands.
13699@end table
13700
13701
a64548ea
EZ
13702@node Neutrino
13703@subsection QNX Neutrino
13704@cindex QNX Neutrino
13705
13706@value{GDBN} provides the following commands specific to the QNX
13707Neutrino target:
13708
13709@table @code
13710@item set debug nto-debug
13711@kindex set debug nto-debug
13712When set to on, enables debugging messages specific to the QNX
13713Neutrino support.
13714
13715@item show debug nto-debug
13716@kindex show debug nto-debug
13717Show the current state of QNX Neutrino messages.
13718@end table
13719
13720
8e04817f
AC
13721@node Embedded OS
13722@section Embedded Operating Systems
104c1213 13723
8e04817f
AC
13724This section describes configurations involving the debugging of
13725embedded operating systems that are available for several different
13726architectures.
d4f3574e 13727
8e04817f
AC
13728@menu
13729* VxWorks:: Using @value{GDBN} with VxWorks
13730@end menu
104c1213 13731
8e04817f
AC
13732@value{GDBN} includes the ability to debug programs running on
13733various real-time operating systems.
104c1213 13734
8e04817f
AC
13735@node VxWorks
13736@subsection Using @value{GDBN} with VxWorks
104c1213 13737
8e04817f 13738@cindex VxWorks
104c1213 13739
8e04817f 13740@table @code
104c1213 13741
8e04817f
AC
13742@kindex target vxworks
13743@item target vxworks @var{machinename}
13744A VxWorks system, attached via TCP/IP. The argument @var{machinename}
13745is the target system's machine name or IP address.
104c1213 13746
8e04817f 13747@end table
104c1213 13748
8e04817f
AC
13749On VxWorks, @code{load} links @var{filename} dynamically on the
13750current target system as well as adding its symbols in @value{GDBN}.
104c1213 13751
8e04817f
AC
13752@value{GDBN} enables developers to spawn and debug tasks running on networked
13753VxWorks targets from a Unix host. Already-running tasks spawned from
13754the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
13755both the Unix host and on the VxWorks target. The program
13756@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
13757installed with the name @code{vxgdb}, to distinguish it from a
13758@value{GDBN} for debugging programs on the host itself.)
104c1213 13759
8e04817f
AC
13760@table @code
13761@item VxWorks-timeout @var{args}
13762@kindex vxworks-timeout
13763All VxWorks-based targets now support the option @code{vxworks-timeout}.
13764This option is set by the user, and @var{args} represents the number of
13765seconds @value{GDBN} waits for responses to rpc's. You might use this if
13766your VxWorks target is a slow software simulator or is on the far side
13767of a thin network line.
13768@end table
104c1213 13769
8e04817f
AC
13770The following information on connecting to VxWorks was current when
13771this manual was produced; newer releases of VxWorks may use revised
13772procedures.
104c1213 13773
4644b6e3 13774@findex INCLUDE_RDB
8e04817f
AC
13775To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
13776to include the remote debugging interface routines in the VxWorks
13777library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
13778VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
13779kernel. The resulting kernel contains @file{rdb.a}, and spawns the
13780source debugging task @code{tRdbTask} when VxWorks is booted. For more
13781information on configuring and remaking VxWorks, see the manufacturer's
13782manual.
13783@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 13784
8e04817f
AC
13785Once you have included @file{rdb.a} in your VxWorks system image and set
13786your Unix execution search path to find @value{GDBN}, you are ready to
13787run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
13788@code{vxgdb}, depending on your installation).
104c1213 13789
8e04817f 13790@value{GDBN} comes up showing the prompt:
104c1213 13791
474c8240 13792@smallexample
8e04817f 13793(vxgdb)
474c8240 13794@end smallexample
104c1213 13795
8e04817f
AC
13796@menu
13797* VxWorks Connection:: Connecting to VxWorks
13798* VxWorks Download:: VxWorks download
13799* VxWorks Attach:: Running tasks
13800@end menu
104c1213 13801
8e04817f
AC
13802@node VxWorks Connection
13803@subsubsection Connecting to VxWorks
104c1213 13804
8e04817f
AC
13805The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
13806network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 13807
474c8240 13808@smallexample
8e04817f 13809(vxgdb) target vxworks tt
474c8240 13810@end smallexample
104c1213 13811
8e04817f
AC
13812@need 750
13813@value{GDBN} displays messages like these:
104c1213 13814
8e04817f
AC
13815@smallexample
13816Attaching remote machine across net...
13817Connected to tt.
13818@end smallexample
104c1213 13819
8e04817f
AC
13820@need 1000
13821@value{GDBN} then attempts to read the symbol tables of any object modules
13822loaded into the VxWorks target since it was last booted. @value{GDBN} locates
13823these files by searching the directories listed in the command search
13824path (@pxref{Environment, ,Your program's environment}); if it fails
13825to find an object file, it displays a message such as:
5d161b24 13826
474c8240 13827@smallexample
8e04817f 13828prog.o: No such file or directory.
474c8240 13829@end smallexample
104c1213 13830
8e04817f
AC
13831When this happens, add the appropriate directory to the search path with
13832the @value{GDBN} command @code{path}, and execute the @code{target}
13833command again.
104c1213 13834
8e04817f
AC
13835@node VxWorks Download
13836@subsubsection VxWorks download
104c1213 13837
8e04817f
AC
13838@cindex download to VxWorks
13839If you have connected to the VxWorks target and you want to debug an
13840object that has not yet been loaded, you can use the @value{GDBN}
13841@code{load} command to download a file from Unix to VxWorks
13842incrementally. The object file given as an argument to the @code{load}
13843command is actually opened twice: first by the VxWorks target in order
13844to download the code, then by @value{GDBN} in order to read the symbol
13845table. This can lead to problems if the current working directories on
13846the two systems differ. If both systems have NFS mounted the same
13847filesystems, you can avoid these problems by using absolute paths.
13848Otherwise, it is simplest to set the working directory on both systems
13849to the directory in which the object file resides, and then to reference
13850the file by its name, without any path. For instance, a program
13851@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
13852and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
13853program, type this on VxWorks:
104c1213 13854
474c8240 13855@smallexample
8e04817f 13856-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 13857@end smallexample
104c1213 13858
8e04817f
AC
13859@noindent
13860Then, in @value{GDBN}, type:
104c1213 13861
474c8240 13862@smallexample
8e04817f
AC
13863(vxgdb) cd @var{hostpath}/vw/demo/rdb
13864(vxgdb) load prog.o
474c8240 13865@end smallexample
104c1213 13866
8e04817f 13867@value{GDBN} displays a response similar to this:
104c1213 13868
8e04817f
AC
13869@smallexample
13870Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
13871@end smallexample
104c1213 13872
8e04817f
AC
13873You can also use the @code{load} command to reload an object module
13874after editing and recompiling the corresponding source file. Note that
13875this makes @value{GDBN} delete all currently-defined breakpoints,
13876auto-displays, and convenience variables, and to clear the value
13877history. (This is necessary in order to preserve the integrity of
13878debugger's data structures that reference the target system's symbol
13879table.)
104c1213 13880
8e04817f
AC
13881@node VxWorks Attach
13882@subsubsection Running tasks
104c1213
JM
13883
13884@cindex running VxWorks tasks
13885You can also attach to an existing task using the @code{attach} command as
13886follows:
13887
474c8240 13888@smallexample
104c1213 13889(vxgdb) attach @var{task}
474c8240 13890@end smallexample
104c1213
JM
13891
13892@noindent
13893where @var{task} is the VxWorks hexadecimal task ID. The task can be running
13894or suspended when you attach to it. Running tasks are suspended at
13895the time of attachment.
13896
6d2ebf8b 13897@node Embedded Processors
104c1213
JM
13898@section Embedded Processors
13899
13900This section goes into details specific to particular embedded
13901configurations.
13902
c45da7e6
EZ
13903@cindex send command to simulator
13904Whenever a specific embedded processor has a simulator, @value{GDBN}
13905allows to send an arbitrary command to the simulator.
13906
13907@table @code
13908@item sim @var{command}
13909@kindex sim@r{, a command}
13910Send an arbitrary @var{command} string to the simulator. Consult the
13911documentation for the specific simulator in use for information about
13912acceptable commands.
13913@end table
13914
7d86b5d5 13915
104c1213 13916@menu
c45da7e6 13917* ARM:: ARM RDI
172c2a43
KI
13918* H8/300:: Renesas H8/300
13919* H8/500:: Renesas H8/500
13920* M32R/D:: Renesas M32R/D
104c1213 13921* M68K:: Motorola M68K
104c1213 13922* MIPS Embedded:: MIPS Embedded
a37295f9 13923* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
13924* PA:: HP PA Embedded
13925* PowerPC: PowerPC
172c2a43 13926* SH:: Renesas SH
104c1213
JM
13927* Sparclet:: Tsqware Sparclet
13928* Sparclite:: Fujitsu Sparclite
13929* ST2000:: Tandem ST2000
13930* Z8000:: Zilog Z8000
a64548ea
EZ
13931* AVR:: Atmel AVR
13932* CRIS:: CRIS
13933* Super-H:: Renesas Super-H
c45da7e6 13934* WinCE:: Windows CE child processes
104c1213
JM
13935@end menu
13936
6d2ebf8b 13937@node ARM
104c1213 13938@subsection ARM
c45da7e6 13939@cindex ARM RDI
104c1213
JM
13940
13941@table @code
8e04817f
AC
13942@kindex target rdi
13943@item target rdi @var{dev}
13944ARM Angel monitor, via RDI library interface to ADP protocol. You may
13945use this target to communicate with both boards running the Angel
13946monitor, or with the EmbeddedICE JTAG debug device.
13947
13948@kindex target rdp
13949@item target rdp @var{dev}
13950ARM Demon monitor.
13951
13952@end table
13953
e2f4edfd
EZ
13954@value{GDBN} provides the following ARM-specific commands:
13955
13956@table @code
13957@item set arm disassembler
13958@kindex set arm
13959This commands selects from a list of disassembly styles. The
13960@code{"std"} style is the standard style.
13961
13962@item show arm disassembler
13963@kindex show arm
13964Show the current disassembly style.
13965
13966@item set arm apcs32
13967@cindex ARM 32-bit mode
13968This command toggles ARM operation mode between 32-bit and 26-bit.
13969
13970@item show arm apcs32
13971Display the current usage of the ARM 32-bit mode.
13972
13973@item set arm fpu @var{fputype}
13974This command sets the ARM floating-point unit (FPU) type. The
13975argument @var{fputype} can be one of these:
13976
13977@table @code
13978@item auto
13979Determine the FPU type by querying the OS ABI.
13980@item softfpa
13981Software FPU, with mixed-endian doubles on little-endian ARM
13982processors.
13983@item fpa
13984GCC-compiled FPA co-processor.
13985@item softvfp
13986Software FPU with pure-endian doubles.
13987@item vfp
13988VFP co-processor.
13989@end table
13990
13991@item show arm fpu
13992Show the current type of the FPU.
13993
13994@item set arm abi
13995This command forces @value{GDBN} to use the specified ABI.
13996
13997@item show arm abi
13998Show the currently used ABI.
13999
14000@item set debug arm
14001Toggle whether to display ARM-specific debugging messages from the ARM
14002target support subsystem.
14003
14004@item show debug arm
14005Show whether ARM-specific debugging messages are enabled.
14006@end table
14007
c45da7e6
EZ
14008The following commands are available when an ARM target is debugged
14009using the RDI interface:
14010
14011@table @code
14012@item rdilogfile @r{[}@var{file}@r{]}
14013@kindex rdilogfile
14014@cindex ADP (Angel Debugger Protocol) logging
14015Set the filename for the ADP (Angel Debugger Protocol) packet log.
14016With an argument, sets the log file to the specified @var{file}. With
14017no argument, show the current log file name. The default log file is
14018@file{rdi.log}.
14019
14020@item rdilogenable @r{[}@var{arg}@r{]}
14021@kindex rdilogenable
14022Control logging of ADP packets. With an argument of 1 or @code{"yes"}
14023enables logging, with an argument 0 or @code{"no"} disables it. With
14024no arguments displays the current setting. When logging is enabled,
14025ADP packets exchanged between @value{GDBN} and the RDI target device
14026are logged to a file.
14027
14028@item set rdiromatzero
14029@kindex set rdiromatzero
14030@cindex ROM at zero address, RDI
14031Tell @value{GDBN} whether the target has ROM at address 0. If on,
14032vector catching is disabled, so that zero address can be used. If off
14033(the default), vector catching is enabled. For this command to take
14034effect, it needs to be invoked prior to the @code{target rdi} command.
14035
14036@item show rdiromatzero
14037@kindex show rdiromatzero
14038Show the current setting of ROM at zero address.
14039
14040@item set rdiheartbeat
14041@kindex set rdiheartbeat
14042@cindex RDI heartbeat
14043Enable or disable RDI heartbeat packets. It is not recommended to
14044turn on this option, since it confuses ARM and EPI JTAG interface, as
14045well as the Angel monitor.
14046
14047@item show rdiheartbeat
14048@kindex show rdiheartbeat
14049Show the setting of RDI heartbeat packets.
14050@end table
14051
e2f4edfd 14052
8e04817f 14053@node H8/300
172c2a43 14054@subsection Renesas H8/300
8e04817f
AC
14055
14056@table @code
14057
14058@kindex target hms@r{, with H8/300}
14059@item target hms @var{dev}
172c2a43 14060A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
14061Use special commands @code{device} and @code{speed} to control the serial
14062line and the communications speed used.
14063
14064@kindex target e7000@r{, with H8/300}
14065@item target e7000 @var{dev}
172c2a43 14066E7000 emulator for Renesas H8 and SH.
8e04817f
AC
14067
14068@kindex target sh3@r{, with H8/300}
14069@kindex target sh3e@r{, with H8/300}
14070@item target sh3 @var{dev}
14071@itemx target sh3e @var{dev}
172c2a43 14072Renesas SH-3 and SH-3E target systems.
8e04817f
AC
14073
14074@end table
14075
14076@cindex download to H8/300 or H8/500
14077@cindex H8/300 or H8/500 download
172c2a43
KI
14078@cindex download to Renesas SH
14079@cindex Renesas SH download
14080When you select remote debugging to a Renesas SH, H8/300, or H8/500
14081board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
14082board and also opens it as the current executable target for
14083@value{GDBN} on your host (like the @code{file} command).
14084
14085@value{GDBN} needs to know these things to talk to your
172c2a43 14086Renesas SH, H8/300, or H8/500:
8e04817f
AC
14087
14088@enumerate
14089@item
14090that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
14091for Renesas microprocessors, or @samp{target e7000}, the in-circuit
14092emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
14093the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
14094H8/300, or H8/500.)
14095
14096@item
172c2a43 14097what serial device connects your host to your Renesas board (the first
8e04817f
AC
14098serial device available on your host is the default).
14099
14100@item
14101what speed to use over the serial device.
14102@end enumerate
14103
14104@menu
172c2a43
KI
14105* Renesas Boards:: Connecting to Renesas boards.
14106* Renesas ICE:: Using the E7000 In-Circuit Emulator.
14107* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
14108@end menu
14109
172c2a43
KI
14110@node Renesas Boards
14111@subsubsection Connecting to Renesas boards
8e04817f
AC
14112
14113@c only for Unix hosts
14114@kindex device
172c2a43 14115@cindex serial device, Renesas micros
8e04817f
AC
14116Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
14117need to explicitly set the serial device. The default @var{port} is the
14118first available port on your host. This is only necessary on Unix
14119hosts, where it is typically something like @file{/dev/ttya}.
14120
14121@kindex speed
172c2a43 14122@cindex serial line speed, Renesas micros
8e04817f
AC
14123@code{@value{GDBN}} has another special command to set the communications
14124speed: @samp{speed @var{bps}}. This command also is only used from Unix
14125hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
14126the DOS @code{mode} command (for instance,
14127@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
14128
14129The @samp{device} and @samp{speed} commands are available only when you
172c2a43 14130use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
14131use a DOS host,
14132@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
14133called @code{asynctsr} to communicate with the development board
14134through a PC serial port. You must also use the DOS @code{mode} command
14135to set up the serial port on the DOS side.
14136
14137The following sample session illustrates the steps needed to start a
14138program under @value{GDBN} control on an H8/300. The example uses a
14139sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 14140the Renesas SH and the H8/500.
8e04817f
AC
14141
14142First hook up your development board. In this example, we use a
14143board attached to serial port @code{COM2}; if you use a different serial
14144port, substitute its name in the argument of the @code{mode} command.
14145When you call @code{asynctsr}, the auxiliary comms program used by the
14146debugger, you give it just the numeric part of the serial port's name;
14147for example, @samp{asyncstr 2} below runs @code{asyncstr} on
14148@code{COM2}.
14149
474c8240 14150@smallexample
8e04817f
AC
14151C:\H8300\TEST> asynctsr 2
14152C:\H8300\TEST> mode com2:9600,n,8,1,p
14153
14154Resident portion of MODE loaded
14155
14156COM2: 9600, n, 8, 1, p
14157
474c8240 14158@end smallexample
8e04817f
AC
14159
14160@quotation
14161@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
14162@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
14163disable it, or even boot without it, to use @code{asynctsr} to control
14164your development board.
14165@end quotation
14166
14167@kindex target hms@r{, and serial protocol}
14168Now that serial communications are set up, and the development board is
9c16f35a 14169connected, you can start up @value{GDBN}. Call @code{@value{GDBN}} with
8e04817f
AC
14170the name of your program as the argument. @code{@value{GDBN}} prompts
14171you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
14172commands to begin your debugging session: @samp{target hms} to specify
172c2a43 14173cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
14174download your program to the board. @code{load} displays the names of
14175the program's sections, and a @samp{*} for each 2K of data downloaded.
14176(If you want to refresh @value{GDBN} data on symbols or on the
14177executable file without downloading, use the @value{GDBN} commands
14178@code{file} or @code{symbol-file}. These commands, and @code{load}
14179itself, are described in @ref{Files,,Commands to specify files}.)
14180
14181@smallexample
14182(eg-C:\H8300\TEST) @value{GDBP} t.x
14183@value{GDBN} is free software and you are welcome to distribute copies
14184 of it under certain conditions; type "show copying" to see
14185 the conditions.
14186There is absolutely no warranty for @value{GDBN}; type "show warranty"
14187for details.
14188@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
14189(@value{GDBP}) target hms
14190Connected to remote H8/300 HMS system.
14191(@value{GDBP}) load t.x
14192.text : 0x8000 .. 0xabde ***********
14193.data : 0xabde .. 0xad30 *
14194.stack : 0xf000 .. 0xf014 *
14195@end smallexample
14196
14197At this point, you're ready to run or debug your program. From here on,
14198you can use all the usual @value{GDBN} commands. The @code{break} command
14199sets breakpoints; the @code{run} command starts your program;
14200@code{print} or @code{x} display data; the @code{continue} command
14201resumes execution after stopping at a breakpoint. You can use the
14202@code{help} command at any time to find out more about @value{GDBN} commands.
14203
14204Remember, however, that @emph{operating system} facilities aren't
14205available on your development board; for example, if your program hangs,
14206you can't send an interrupt---but you can press the @sc{reset} switch!
14207
14208Use the @sc{reset} button on the development board
14209@itemize @bullet
14210@item
14211to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
14212no way to pass an interrupt signal to the development board); and
14213
14214@item
14215to return to the @value{GDBN} command prompt after your program finishes
14216normally. The communications protocol provides no other way for @value{GDBN}
14217to detect program completion.
14218@end itemize
14219
14220In either case, @value{GDBN} sees the effect of a @sc{reset} on the
14221development board as a ``normal exit'' of your program.
14222
172c2a43 14223@node Renesas ICE
8e04817f
AC
14224@subsubsection Using the E7000 in-circuit emulator
14225
172c2a43 14226@kindex target e7000@r{, with Renesas ICE}
8e04817f 14227You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 14228Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
14229e7000} command to connect @value{GDBN} to your E7000:
14230
14231@table @code
14232@item target e7000 @var{port} @var{speed}
14233Use this form if your E7000 is connected to a serial port. The
14234@var{port} argument identifies what serial port to use (for example,
14235@samp{com2}). The third argument is the line speed in bits per second
14236(for example, @samp{9600}).
14237
14238@item target e7000 @var{hostname}
14239If your E7000 is installed as a host on a TCP/IP network, you can just
14240specify its hostname; @value{GDBN} uses @code{telnet} to connect.
14241@end table
14242
ba04e063
EZ
14243The following special commands are available when debugging with the
14244Renesas E7000 ICE:
14245
14246@table @code
14247@item e7000 @var{command}
14248@kindex e7000
14249@cindex send command to E7000 monitor
14250This sends the specified @var{command} to the E7000 monitor.
14251
14252@item ftplogin @var{machine} @var{username} @var{password} @var{dir}
14253@kindex ftplogin@r{, E7000}
14254This command records information for subsequent interface with the
14255E7000 monitor via the FTP protocol: @value{GDBN} will log into the
14256named @var{machine} using specified @var{username} and @var{password},
14257and then chdir to the named directory @var{dir}.
14258
14259@item ftpload @var{file}
14260@kindex ftpload@r{, E7000}
14261This command uses credentials recorded by @code{ftplogin} to fetch and
14262load the named @var{file} from the E7000 monitor.
14263
14264@item drain
14265@kindex drain@r{, E7000}
14266This command drains any pending text buffers stored on the E7000.
14267
14268@item set usehardbreakpoints
14269@itemx show usehardbreakpoints
14270@kindex set usehardbreakpoints@r{, E7000}
14271@kindex show usehardbreakpoints@r{, E7000}
14272@cindex hardware breakpoints, and E7000
14273These commands set and show the use of hardware breakpoints for all
14274breakpoints. @xref{Set Breaks, hardware-assisted breakpoint}, for
14275more information about using hardware breakpoints selectively.
14276@end table
14277
172c2a43
KI
14278@node Renesas Special
14279@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
14280
14281Some @value{GDBN} commands are available only for the H8/300:
14282
14283@table @code
14284
14285@kindex set machine
14286@kindex show machine
14287@item set machine h8300
14288@itemx set machine h8300h
14289Condition @value{GDBN} for one of the two variants of the H8/300
14290architecture with @samp{set machine}. You can use @samp{show machine}
14291to check which variant is currently in effect.
104c1213
JM
14292
14293@end table
14294
8e04817f
AC
14295@node H8/500
14296@subsection H8/500
104c1213
JM
14297
14298@table @code
14299
8e04817f
AC
14300@kindex set memory @var{mod}
14301@cindex memory models, H8/500
14302@item set memory @var{mod}
14303@itemx show memory
14304Specify which H8/500 memory model (@var{mod}) you are using with
14305@samp{set memory}; check which memory model is in effect with @samp{show
14306memory}. The accepted values for @var{mod} are @code{small},
14307@code{big}, @code{medium}, and @code{compact}.
104c1213 14308
8e04817f 14309@end table
104c1213 14310
8e04817f 14311@node M32R/D
ba04e063 14312@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
14313
14314@table @code
8e04817f
AC
14315@kindex target m32r
14316@item target m32r @var{dev}
172c2a43 14317Renesas M32R/D ROM monitor.
8e04817f 14318
fb3e19c0
KI
14319@kindex target m32rsdi
14320@item target m32rsdi @var{dev}
14321Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
14322@end table
14323
14324The following @value{GDBN} commands are specific to the M32R monitor:
14325
14326@table @code
14327@item set download-path @var{path}
14328@kindex set download-path
14329@cindex find downloadable @sc{srec} files (M32R)
14330Set the default path for finding donwloadable @sc{srec} files.
14331
14332@item show download-path
14333@kindex show download-path
14334Show the default path for downloadable @sc{srec} files.
fb3e19c0 14335
721c2651
EZ
14336@item set board-address @var{addr}
14337@kindex set board-address
14338@cindex M32-EVA target board address
14339Set the IP address for the M32R-EVA target board.
14340
14341@item show board-address
14342@kindex show board-address
14343Show the current IP address of the target board.
14344
14345@item set server-address @var{addr}
14346@kindex set server-address
14347@cindex download server address (M32R)
14348Set the IP address for the download server, which is the @value{GDBN}'s
14349host machine.
14350
14351@item show server-address
14352@kindex show server-address
14353Display the IP address of the download server.
14354
14355@item upload @r{[}@var{file}@r{]}
14356@kindex upload@r{, M32R}
14357Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
14358upload capability. If no @var{file} argument is given, the current
14359executable file is uploaded.
14360
14361@item tload @r{[}@var{file}@r{]}
14362@kindex tload@r{, M32R}
14363Test the @code{upload} command.
8e04817f
AC
14364@end table
14365
ba04e063
EZ
14366The following commands are available for M32R/SDI:
14367
14368@table @code
14369@item sdireset
14370@kindex sdireset
14371@cindex reset SDI connection, M32R
14372This command resets the SDI connection.
14373
14374@item sdistatus
14375@kindex sdistatus
14376This command shows the SDI connection status.
14377
14378@item debug_chaos
14379@kindex debug_chaos
14380@cindex M32R/Chaos debugging
14381Instructs the remote that M32R/Chaos debugging is to be used.
14382
14383@item use_debug_dma
14384@kindex use_debug_dma
14385Instructs the remote to use the DEBUG_DMA method of accessing memory.
14386
14387@item use_mon_code
14388@kindex use_mon_code
14389Instructs the remote to use the MON_CODE method of accessing memory.
14390
14391@item use_ib_break
14392@kindex use_ib_break
14393Instructs the remote to set breakpoints by IB break.
14394
14395@item use_dbt_break
14396@kindex use_dbt_break
14397Instructs the remote to set breakpoints by DBT.
14398@end table
14399
8e04817f
AC
14400@node M68K
14401@subsection M68k
14402
14403The Motorola m68k configuration includes ColdFire support, and
14404target command for the following ROM monitors.
14405
14406@table @code
14407
14408@kindex target abug
14409@item target abug @var{dev}
14410ABug ROM monitor for M68K.
14411
14412@kindex target cpu32bug
14413@item target cpu32bug @var{dev}
14414CPU32BUG monitor, running on a CPU32 (M68K) board.
14415
14416@kindex target dbug
14417@item target dbug @var{dev}
14418dBUG ROM monitor for Motorola ColdFire.
14419
14420@kindex target est
14421@item target est @var{dev}
14422EST-300 ICE monitor, running on a CPU32 (M68K) board.
14423
14424@kindex target rom68k
14425@item target rom68k @var{dev}
14426ROM 68K monitor, running on an M68K IDP board.
14427
14428@end table
14429
8e04817f
AC
14430@table @code
14431
14432@kindex target rombug
14433@item target rombug @var{dev}
14434ROMBUG ROM monitor for OS/9000.
14435
14436@end table
14437
8e04817f
AC
14438@node MIPS Embedded
14439@subsection MIPS Embedded
14440
14441@cindex MIPS boards
14442@value{GDBN} can use the MIPS remote debugging protocol to talk to a
14443MIPS board attached to a serial line. This is available when
14444you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 14445
8e04817f
AC
14446@need 1000
14447Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 14448
8e04817f
AC
14449@table @code
14450@item target mips @var{port}
14451@kindex target mips @var{port}
14452To run a program on the board, start up @code{@value{GDBP}} with the
14453name of your program as the argument. To connect to the board, use the
14454command @samp{target mips @var{port}}, where @var{port} is the name of
14455the serial port connected to the board. If the program has not already
14456been downloaded to the board, you may use the @code{load} command to
14457download it. You can then use all the usual @value{GDBN} commands.
104c1213 14458
8e04817f
AC
14459For example, this sequence connects to the target board through a serial
14460port, and loads and runs a program called @var{prog} through the
14461debugger:
104c1213 14462
474c8240 14463@smallexample
8e04817f
AC
14464host$ @value{GDBP} @var{prog}
14465@value{GDBN} is free software and @dots{}
14466(@value{GDBP}) target mips /dev/ttyb
14467(@value{GDBP}) load @var{prog}
14468(@value{GDBP}) run
474c8240 14469@end smallexample
104c1213 14470
8e04817f
AC
14471@item target mips @var{hostname}:@var{portnumber}
14472On some @value{GDBN} host configurations, you can specify a TCP
14473connection (for instance, to a serial line managed by a terminal
14474concentrator) instead of a serial port, using the syntax
14475@samp{@var{hostname}:@var{portnumber}}.
104c1213 14476
8e04817f
AC
14477@item target pmon @var{port}
14478@kindex target pmon @var{port}
14479PMON ROM monitor.
104c1213 14480
8e04817f
AC
14481@item target ddb @var{port}
14482@kindex target ddb @var{port}
14483NEC's DDB variant of PMON for Vr4300.
104c1213 14484
8e04817f
AC
14485@item target lsi @var{port}
14486@kindex target lsi @var{port}
14487LSI variant of PMON.
104c1213 14488
8e04817f
AC
14489@kindex target r3900
14490@item target r3900 @var{dev}
14491Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 14492
8e04817f
AC
14493@kindex target array
14494@item target array @var{dev}
14495Array Tech LSI33K RAID controller board.
104c1213 14496
8e04817f 14497@end table
104c1213 14498
104c1213 14499
8e04817f
AC
14500@noindent
14501@value{GDBN} also supports these special commands for MIPS targets:
104c1213 14502
8e04817f 14503@table @code
8e04817f
AC
14504@item set mipsfpu double
14505@itemx set mipsfpu single
14506@itemx set mipsfpu none
a64548ea 14507@itemx set mipsfpu auto
8e04817f
AC
14508@itemx show mipsfpu
14509@kindex set mipsfpu
14510@kindex show mipsfpu
14511@cindex MIPS remote floating point
14512@cindex floating point, MIPS remote
14513If your target board does not support the MIPS floating point
14514coprocessor, you should use the command @samp{set mipsfpu none} (if you
14515need this, you may wish to put the command in your @value{GDBN} init
14516file). This tells @value{GDBN} how to find the return value of
14517functions which return floating point values. It also allows
14518@value{GDBN} to avoid saving the floating point registers when calling
14519functions on the board. If you are using a floating point coprocessor
14520with only single precision floating point support, as on the @sc{r4650}
14521processor, use the command @samp{set mipsfpu single}. The default
14522double precision floating point coprocessor may be selected using
14523@samp{set mipsfpu double}.
104c1213 14524
8e04817f
AC
14525In previous versions the only choices were double precision or no
14526floating point, so @samp{set mipsfpu on} will select double precision
14527and @samp{set mipsfpu off} will select no floating point.
104c1213 14528
8e04817f
AC
14529As usual, you can inquire about the @code{mipsfpu} variable with
14530@samp{show mipsfpu}.
104c1213 14531
8e04817f
AC
14532@item set timeout @var{seconds}
14533@itemx set retransmit-timeout @var{seconds}
14534@itemx show timeout
14535@itemx show retransmit-timeout
14536@cindex @code{timeout}, MIPS protocol
14537@cindex @code{retransmit-timeout}, MIPS protocol
14538@kindex set timeout
14539@kindex show timeout
14540@kindex set retransmit-timeout
14541@kindex show retransmit-timeout
14542You can control the timeout used while waiting for a packet, in the MIPS
14543remote protocol, with the @code{set timeout @var{seconds}} command. The
14544default is 5 seconds. Similarly, you can control the timeout used while
14545waiting for an acknowledgement of a packet with the @code{set
14546retransmit-timeout @var{seconds}} command. The default is 3 seconds.
14547You can inspect both values with @code{show timeout} and @code{show
14548retransmit-timeout}. (These commands are @emph{only} available when
14549@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 14550
8e04817f
AC
14551The timeout set by @code{set timeout} does not apply when @value{GDBN}
14552is waiting for your program to stop. In that case, @value{GDBN} waits
14553forever because it has no way of knowing how long the program is going
14554to run before stopping.
ba04e063
EZ
14555
14556@item set syn-garbage-limit @var{num}
14557@kindex set syn-garbage-limit@r{, MIPS remote}
14558@cindex synchronize with remote MIPS target
14559Limit the maximum number of characters @value{GDBN} should ignore when
14560it tries to synchronize with the remote target. The default is 10
14561characters. Setting the limit to -1 means there's no limit.
14562
14563@item show syn-garbage-limit
14564@kindex show syn-garbage-limit@r{, MIPS remote}
14565Show the current limit on the number of characters to ignore when
14566trying to synchronize with the remote system.
14567
14568@item set monitor-prompt @var{prompt}
14569@kindex set monitor-prompt@r{, MIPS remote}
14570@cindex remote monitor prompt
14571Tell @value{GDBN} to expect the specified @var{prompt} string from the
14572remote monitor. The default depends on the target:
14573@table @asis
14574@item pmon target
14575@samp{PMON}
14576@item ddb target
14577@samp{NEC010}
14578@item lsi target
14579@samp{PMON>}
14580@end table
14581
14582@item show monitor-prompt
14583@kindex show monitor-prompt@r{, MIPS remote}
14584Show the current strings @value{GDBN} expects as the prompt from the
14585remote monitor.
14586
14587@item set monitor-warnings
14588@kindex set monitor-warnings@r{, MIPS remote}
14589Enable or disable monitor warnings about hardware breakpoints. This
14590has effect only for the @code{lsi} target. When on, @value{GDBN} will
14591display warning messages whose codes are returned by the @code{lsi}
14592PMON monitor for breakpoint commands.
14593
14594@item show monitor-warnings
14595@kindex show monitor-warnings@r{, MIPS remote}
14596Show the current setting of printing monitor warnings.
14597
14598@item pmon @var{command}
14599@kindex pmon@r{, MIPS remote}
14600@cindex send PMON command
14601This command allows sending an arbitrary @var{command} string to the
14602monitor. The monitor must be in debug mode for this to work.
8e04817f 14603@end table
104c1213 14604
a37295f9
MM
14605@node OpenRISC 1000
14606@subsection OpenRISC 1000
14607@cindex OpenRISC 1000
14608
14609@cindex or1k boards
14610See OR1k Architecture document (@uref{www.opencores.org}) for more information
14611about platform and commands.
14612
14613@table @code
14614
14615@kindex target jtag
14616@item target jtag jtag://@var{host}:@var{port}
14617
14618Connects to remote JTAG server.
14619JTAG remote server can be either an or1ksim or JTAG server,
14620connected via parallel port to the board.
14621
14622Example: @code{target jtag jtag://localhost:9999}
14623
14624@kindex or1ksim
14625@item or1ksim @var{command}
14626If connected to @code{or1ksim} OpenRISC 1000 Architectural
14627Simulator, proprietary commands can be executed.
14628
14629@kindex info or1k spr
14630@item info or1k spr
14631Displays spr groups.
14632
14633@item info or1k spr @var{group}
14634@itemx info or1k spr @var{groupno}
14635Displays register names in selected group.
14636
14637@item info or1k spr @var{group} @var{register}
14638@itemx info or1k spr @var{register}
14639@itemx info or1k spr @var{groupno} @var{registerno}
14640@itemx info or1k spr @var{registerno}
14641Shows information about specified spr register.
14642
14643@kindex spr
14644@item spr @var{group} @var{register} @var{value}
14645@itemx spr @var{register @var{value}}
14646@itemx spr @var{groupno} @var{registerno @var{value}}
14647@itemx spr @var{registerno @var{value}}
14648Writes @var{value} to specified spr register.
14649@end table
14650
14651Some implementations of OpenRISC 1000 Architecture also have hardware trace.
14652It is very similar to @value{GDBN} trace, except it does not interfere with normal
14653program execution and is thus much faster. Hardware breakpoints/watchpoint
14654triggers can be set using:
14655@table @code
14656@item $LEA/$LDATA
14657Load effective address/data
14658@item $SEA/$SDATA
14659Store effective address/data
14660@item $AEA/$ADATA
14661Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
14662@item $FETCH
14663Fetch data
14664@end table
14665
14666When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
14667@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
14668
14669@code{htrace} commands:
14670@cindex OpenRISC 1000 htrace
14671@table @code
14672@kindex hwatch
14673@item hwatch @var{conditional}
14674Set hardware watchpoint on combination of Load/Store Effecive Address(es)
14675or Data. For example:
14676
14677@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14678
14679@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14680
4644b6e3 14681@kindex htrace
a37295f9
MM
14682@item htrace info
14683Display information about current HW trace configuration.
14684
a37295f9
MM
14685@item htrace trigger @var{conditional}
14686Set starting criteria for HW trace.
14687
a37295f9
MM
14688@item htrace qualifier @var{conditional}
14689Set acquisition qualifier for HW trace.
14690
a37295f9
MM
14691@item htrace stop @var{conditional}
14692Set HW trace stopping criteria.
14693
f153cc92 14694@item htrace record [@var{data}]*
a37295f9
MM
14695Selects the data to be recorded, when qualifier is met and HW trace was
14696triggered.
14697
a37295f9 14698@item htrace enable
a37295f9
MM
14699@itemx htrace disable
14700Enables/disables the HW trace.
14701
f153cc92 14702@item htrace rewind [@var{filename}]
a37295f9
MM
14703Clears currently recorded trace data.
14704
14705If filename is specified, new trace file is made and any newly collected data
14706will be written there.
14707
f153cc92 14708@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
14709Prints trace buffer, using current record configuration.
14710
a37295f9
MM
14711@item htrace mode continuous
14712Set continuous trace mode.
14713
a37295f9
MM
14714@item htrace mode suspend
14715Set suspend trace mode.
14716
14717@end table
14718
8e04817f
AC
14719@node PowerPC
14720@subsection PowerPC
104c1213
JM
14721
14722@table @code
8e04817f
AC
14723@kindex target dink32
14724@item target dink32 @var{dev}
14725DINK32 ROM monitor.
104c1213 14726
8e04817f
AC
14727@kindex target ppcbug
14728@item target ppcbug @var{dev}
14729@kindex target ppcbug1
14730@item target ppcbug1 @var{dev}
14731PPCBUG ROM monitor for PowerPC.
104c1213 14732
8e04817f
AC
14733@kindex target sds
14734@item target sds @var{dev}
14735SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 14736@end table
8e04817f 14737
c45da7e6
EZ
14738@cindex SDS protocol
14739The following commands specifi to the SDS protocol are supported
14740by@value{GDBN}:
14741
14742@table @code
14743@item set sdstimeout @var{nsec}
14744@kindex set sdstimeout
14745Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
14746default is 2 seconds.
14747
14748@item show sdstimeout
14749@kindex show sdstimeout
14750Show the current value of the SDS timeout.
14751
14752@item sds @var{command}
14753@kindex sds@r{, a command}
14754Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
14755@end table
14756
c45da7e6 14757
8e04817f
AC
14758@node PA
14759@subsection HP PA Embedded
104c1213
JM
14760
14761@table @code
14762
8e04817f
AC
14763@kindex target op50n
14764@item target op50n @var{dev}
14765OP50N monitor, running on an OKI HPPA board.
14766
14767@kindex target w89k
14768@item target w89k @var{dev}
14769W89K monitor, running on a Winbond HPPA board.
104c1213
JM
14770
14771@end table
14772
8e04817f 14773@node SH
172c2a43 14774@subsection Renesas SH
104c1213
JM
14775
14776@table @code
14777
172c2a43 14778@kindex target hms@r{, with Renesas SH}
8e04817f 14779@item target hms @var{dev}
172c2a43 14780A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
14781commands @code{device} and @code{speed} to control the serial line and
14782the communications speed used.
104c1213 14783
172c2a43 14784@kindex target e7000@r{, with Renesas SH}
8e04817f 14785@item target e7000 @var{dev}
172c2a43 14786E7000 emulator for Renesas SH.
104c1213 14787
8e04817f
AC
14788@kindex target sh3@r{, with SH}
14789@kindex target sh3e@r{, with SH}
14790@item target sh3 @var{dev}
14791@item target sh3e @var{dev}
172c2a43 14792Renesas SH-3 and SH-3E target systems.
104c1213 14793
8e04817f 14794@end table
104c1213 14795
8e04817f
AC
14796@node Sparclet
14797@subsection Tsqware Sparclet
104c1213 14798
8e04817f
AC
14799@cindex Sparclet
14800
14801@value{GDBN} enables developers to debug tasks running on
14802Sparclet targets from a Unix host.
14803@value{GDBN} uses code that runs on
14804both the Unix host and on the Sparclet target. The program
14805@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 14806
8e04817f
AC
14807@table @code
14808@item remotetimeout @var{args}
14809@kindex remotetimeout
14810@value{GDBN} supports the option @code{remotetimeout}.
14811This option is set by the user, and @var{args} represents the number of
14812seconds @value{GDBN} waits for responses.
104c1213
JM
14813@end table
14814
8e04817f
AC
14815@cindex compiling, on Sparclet
14816When compiling for debugging, include the options @samp{-g} to get debug
14817information and @samp{-Ttext} to relocate the program to where you wish to
14818load it on the target. You may also want to add the options @samp{-n} or
14819@samp{-N} in order to reduce the size of the sections. Example:
104c1213 14820
474c8240 14821@smallexample
8e04817f 14822sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 14823@end smallexample
104c1213 14824
8e04817f 14825You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 14826
474c8240 14827@smallexample
8e04817f 14828sparclet-aout-objdump --headers --syms prog
474c8240 14829@end smallexample
104c1213 14830
8e04817f
AC
14831@cindex running, on Sparclet
14832Once you have set
14833your Unix execution search path to find @value{GDBN}, you are ready to
14834run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
14835(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 14836
8e04817f
AC
14837@value{GDBN} comes up showing the prompt:
14838
474c8240 14839@smallexample
8e04817f 14840(gdbslet)
474c8240 14841@end smallexample
104c1213
JM
14842
14843@menu
8e04817f
AC
14844* Sparclet File:: Setting the file to debug
14845* Sparclet Connection:: Connecting to Sparclet
14846* Sparclet Download:: Sparclet download
14847* Sparclet Execution:: Running and debugging
104c1213
JM
14848@end menu
14849
8e04817f
AC
14850@node Sparclet File
14851@subsubsection Setting file to debug
104c1213 14852
8e04817f 14853The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 14854
474c8240 14855@smallexample
8e04817f 14856(gdbslet) file prog
474c8240 14857@end smallexample
104c1213 14858
8e04817f
AC
14859@need 1000
14860@value{GDBN} then attempts to read the symbol table of @file{prog}.
14861@value{GDBN} locates
14862the file by searching the directories listed in the command search
14863path.
14864If the file was compiled with debug information (option "-g"), source
14865files will be searched as well.
14866@value{GDBN} locates
14867the source files by searching the directories listed in the directory search
14868path (@pxref{Environment, ,Your program's environment}).
14869If it fails
14870to find a file, it displays a message such as:
104c1213 14871
474c8240 14872@smallexample
8e04817f 14873prog: No such file or directory.
474c8240 14874@end smallexample
104c1213 14875
8e04817f
AC
14876When this happens, add the appropriate directories to the search paths with
14877the @value{GDBN} commands @code{path} and @code{dir}, and execute the
14878@code{target} command again.
104c1213 14879
8e04817f
AC
14880@node Sparclet Connection
14881@subsubsection Connecting to Sparclet
104c1213 14882
8e04817f
AC
14883The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
14884To connect to a target on serial port ``@code{ttya}'', type:
104c1213 14885
474c8240 14886@smallexample
8e04817f
AC
14887(gdbslet) target sparclet /dev/ttya
14888Remote target sparclet connected to /dev/ttya
14889main () at ../prog.c:3
474c8240 14890@end smallexample
104c1213 14891
8e04817f
AC
14892@need 750
14893@value{GDBN} displays messages like these:
104c1213 14894
474c8240 14895@smallexample
8e04817f 14896Connected to ttya.
474c8240 14897@end smallexample
104c1213 14898
8e04817f
AC
14899@node Sparclet Download
14900@subsubsection Sparclet download
104c1213 14901
8e04817f
AC
14902@cindex download to Sparclet
14903Once connected to the Sparclet target,
14904you can use the @value{GDBN}
14905@code{load} command to download the file from the host to the target.
14906The file name and load offset should be given as arguments to the @code{load}
14907command.
14908Since the file format is aout, the program must be loaded to the starting
14909address. You can use @code{objdump} to find out what this value is. The load
14910offset is an offset which is added to the VMA (virtual memory address)
14911of each of the file's sections.
14912For instance, if the program
14913@file{prog} was linked to text address 0x1201000, with data at 0x12010160
14914and bss at 0x12010170, in @value{GDBN}, type:
104c1213 14915
474c8240 14916@smallexample
8e04817f
AC
14917(gdbslet) load prog 0x12010000
14918Loading section .text, size 0xdb0 vma 0x12010000
474c8240 14919@end smallexample
104c1213 14920
8e04817f
AC
14921If the code is loaded at a different address then what the program was linked
14922to, you may need to use the @code{section} and @code{add-symbol-file} commands
14923to tell @value{GDBN} where to map the symbol table.
14924
14925@node Sparclet Execution
14926@subsubsection Running and debugging
14927
14928@cindex running and debugging Sparclet programs
14929You can now begin debugging the task using @value{GDBN}'s execution control
14930commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
14931manual for the list of commands.
14932
474c8240 14933@smallexample
8e04817f
AC
14934(gdbslet) b main
14935Breakpoint 1 at 0x12010000: file prog.c, line 3.
14936(gdbslet) run
14937Starting program: prog
14938Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
149393 char *symarg = 0;
14940(gdbslet) step
149414 char *execarg = "hello!";
14942(gdbslet)
474c8240 14943@end smallexample
8e04817f
AC
14944
14945@node Sparclite
14946@subsection Fujitsu Sparclite
104c1213
JM
14947
14948@table @code
14949
8e04817f
AC
14950@kindex target sparclite
14951@item target sparclite @var{dev}
14952Fujitsu sparclite boards, used only for the purpose of loading.
14953You must use an additional command to debug the program.
14954For example: target remote @var{dev} using @value{GDBN} standard
14955remote protocol.
104c1213
JM
14956
14957@end table
14958
8e04817f
AC
14959@node ST2000
14960@subsection Tandem ST2000
104c1213 14961
8e04817f
AC
14962@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
14963STDBUG protocol.
104c1213 14964
8e04817f
AC
14965To connect your ST2000 to the host system, see the manufacturer's
14966manual. Once the ST2000 is physically attached, you can run:
104c1213 14967
474c8240 14968@smallexample
8e04817f 14969target st2000 @var{dev} @var{speed}
474c8240 14970@end smallexample
104c1213 14971
8e04817f
AC
14972@noindent
14973to establish it as your debugging environment. @var{dev} is normally
14974the name of a serial device, such as @file{/dev/ttya}, connected to the
14975ST2000 via a serial line. You can instead specify @var{dev} as a TCP
14976connection (for example, to a serial line attached via a terminal
14977concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 14978
8e04817f
AC
14979The @code{load} and @code{attach} commands are @emph{not} defined for
14980this target; you must load your program into the ST2000 as you normally
14981would for standalone operation. @value{GDBN} reads debugging information
14982(such as symbols) from a separate, debugging version of the program
14983available on your host computer.
14984@c FIXME!! This is terribly vague; what little content is here is
14985@c basically hearsay.
104c1213 14986
8e04817f
AC
14987@cindex ST2000 auxiliary commands
14988These auxiliary @value{GDBN} commands are available to help you with the ST2000
14989environment:
104c1213 14990
8e04817f
AC
14991@table @code
14992@item st2000 @var{command}
14993@kindex st2000 @var{cmd}
14994@cindex STDBUG commands (ST2000)
14995@cindex commands to STDBUG (ST2000)
14996Send a @var{command} to the STDBUG monitor. See the manufacturer's
14997manual for available commands.
104c1213 14998
8e04817f
AC
14999@item connect
15000@cindex connect (to STDBUG)
15001Connect the controlling terminal to the STDBUG command monitor. When
15002you are done interacting with STDBUG, typing either of two character
15003sequences gets you back to the @value{GDBN} command prompt:
15004@kbd{@key{RET}~.} (Return, followed by tilde and period) or
15005@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
15006@end table
15007
8e04817f
AC
15008@node Z8000
15009@subsection Zilog Z8000
104c1213 15010
8e04817f
AC
15011@cindex Z8000
15012@cindex simulator, Z8000
15013@cindex Zilog Z8000 simulator
104c1213 15014
8e04817f
AC
15015When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
15016a Z8000 simulator.
15017
15018For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
15019unsegmented variant of the Z8000 architecture) or the Z8001 (the
15020segmented variant). The simulator recognizes which architecture is
15021appropriate by inspecting the object code.
104c1213 15022
8e04817f
AC
15023@table @code
15024@item target sim @var{args}
15025@kindex sim
15026@kindex target sim@r{, with Z8000}
15027Debug programs on a simulated CPU. If the simulator supports setup
15028options, specify them via @var{args}.
104c1213
JM
15029@end table
15030
8e04817f
AC
15031@noindent
15032After specifying this target, you can debug programs for the simulated
15033CPU in the same style as programs for your host computer; use the
15034@code{file} command to load a new program image, the @code{run} command
15035to run your program, and so on.
15036
15037As well as making available all the usual machine registers
15038(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
15039additional items of information as specially named registers:
104c1213
JM
15040
15041@table @code
15042
8e04817f
AC
15043@item cycles
15044Counts clock-ticks in the simulator.
104c1213 15045
8e04817f
AC
15046@item insts
15047Counts instructions run in the simulator.
104c1213 15048
8e04817f
AC
15049@item time
15050Execution time in 60ths of a second.
104c1213 15051
8e04817f 15052@end table
104c1213 15053
8e04817f
AC
15054You can refer to these values in @value{GDBN} expressions with the usual
15055conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
15056conditional breakpoint that suspends only after at least 5000
15057simulated clock ticks.
104c1213 15058
a64548ea
EZ
15059@node AVR
15060@subsection Atmel AVR
15061@cindex AVR
15062
15063When configured for debugging the Atmel AVR, @value{GDBN} supports the
15064following AVR-specific commands:
15065
15066@table @code
15067@item info io_registers
15068@kindex info io_registers@r{, AVR}
15069@cindex I/O registers (Atmel AVR)
15070This command displays information about the AVR I/O registers. For
15071each register, @value{GDBN} prints its number and value.
15072@end table
15073
15074@node CRIS
15075@subsection CRIS
15076@cindex CRIS
15077
15078When configured for debugging CRIS, @value{GDBN} provides the
15079following CRIS-specific commands:
15080
15081@table @code
15082@item set cris-version @var{ver}
15083@cindex CRIS version
e22e55c9
OF
15084Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
15085The CRIS version affects register names and sizes. This command is useful in
15086case autodetection of the CRIS version fails.
a64548ea
EZ
15087
15088@item show cris-version
15089Show the current CRIS version.
15090
15091@item set cris-dwarf2-cfi
15092@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
15093Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
15094Change to @samp{off} when using @code{gcc-cris} whose version is below
15095@code{R59}.
a64548ea
EZ
15096
15097@item show cris-dwarf2-cfi
15098Show the current state of using DWARF-2 CFI.
e22e55c9
OF
15099
15100@item set cris-mode @var{mode}
15101@cindex CRIS mode
15102Set the current CRIS mode to @var{mode}. It should only be changed when
15103debugging in guru mode, in which case it should be set to
15104@samp{guru} (the default is @samp{normal}).
15105
15106@item show cris-mode
15107Show the current CRIS mode.
a64548ea
EZ
15108@end table
15109
15110@node Super-H
15111@subsection Renesas Super-H
15112@cindex Super-H
15113
15114For the Renesas Super-H processor, @value{GDBN} provides these
15115commands:
15116
15117@table @code
15118@item regs
15119@kindex regs@r{, Super-H}
15120Show the values of all Super-H registers.
15121@end table
15122
c45da7e6
EZ
15123@node WinCE
15124@subsection Windows CE
15125@cindex Windows CE
15126
15127The following commands are available for Windows CE:
15128
15129@table @code
15130@item set remotedirectory @var{dir}
15131@kindex set remotedirectory
15132Tell @value{GDBN} to upload files from the named directory @var{dir}.
15133The default is @file{/gdb}, i.e.@: the root directory on the current
15134drive.
15135
15136@item show remotedirectory
15137@kindex show remotedirectory
15138Show the current value of the upload directory.
15139
15140@item set remoteupload @var{method}
15141@kindex set remoteupload
15142Set the method used to upload files to remote device. Valid values
15143for @var{method} are @samp{always}, @samp{newer}, and @samp{never}.
15144The default is @samp{newer}.
15145
15146@item show remoteupload
15147@kindex show remoteupload
15148Show the current setting of the upload method.
15149
15150@item set remoteaddhost
15151@kindex set remoteaddhost
15152Tell @value{GDBN} whether to add this host to the remote stub's
15153arguments when you debug over a network.
15154
15155@item show remoteaddhost
15156@kindex show remoteaddhost
15157Show whether to add this host to remote stub's arguments when
15158debugging over a network.
15159@end table
15160
a64548ea 15161
8e04817f
AC
15162@node Architectures
15163@section Architectures
104c1213 15164
8e04817f
AC
15165This section describes characteristics of architectures that affect
15166all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 15167
8e04817f 15168@menu
9c16f35a 15169* i386::
8e04817f
AC
15170* A29K::
15171* Alpha::
15172* MIPS::
a64548ea 15173* HPPA:: HP PA architecture
8e04817f 15174@end menu
104c1213 15175
9c16f35a
EZ
15176@node i386
15177@subsection x86 Architecture-specific issues.
15178
15179@table @code
15180@item set struct-convention @var{mode}
15181@kindex set struct-convention
15182@cindex struct return convention
15183@cindex struct/union returned in registers
15184Set the convention used by the inferior to return @code{struct}s and
15185@code{union}s from functions to @var{mode}. Possible values of
15186@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
15187default). @code{"default"} or @code{"pcc"} means that @code{struct}s
15188are returned on the stack, while @code{"reg"} means that a
15189@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
15190be returned in a register.
15191
15192@item show struct-convention
15193@kindex show struct-convention
15194Show the current setting of the convention to return @code{struct}s
15195from functions.
15196@end table
15197
8e04817f
AC
15198@node A29K
15199@subsection A29K
104c1213
JM
15200
15201@table @code
104c1213 15202
8e04817f
AC
15203@kindex set rstack_high_address
15204@cindex AMD 29K register stack
15205@cindex register stack, AMD29K
15206@item set rstack_high_address @var{address}
15207On AMD 29000 family processors, registers are saved in a separate
15208@dfn{register stack}. There is no way for @value{GDBN} to determine the
15209extent of this stack. Normally, @value{GDBN} just assumes that the
15210stack is ``large enough''. This may result in @value{GDBN} referencing
15211memory locations that do not exist. If necessary, you can get around
15212this problem by specifying the ending address of the register stack with
15213the @code{set rstack_high_address} command. The argument should be an
15214address, which you probably want to precede with @samp{0x} to specify in
15215hexadecimal.
104c1213 15216
8e04817f
AC
15217@kindex show rstack_high_address
15218@item show rstack_high_address
15219Display the current limit of the register stack, on AMD 29000 family
15220processors.
104c1213 15221
8e04817f 15222@end table
104c1213 15223
8e04817f
AC
15224@node Alpha
15225@subsection Alpha
104c1213 15226
8e04817f 15227See the following section.
104c1213 15228
8e04817f
AC
15229@node MIPS
15230@subsection MIPS
104c1213 15231
8e04817f
AC
15232@cindex stack on Alpha
15233@cindex stack on MIPS
15234@cindex Alpha stack
15235@cindex MIPS stack
15236Alpha- and MIPS-based computers use an unusual stack frame, which
15237sometimes requires @value{GDBN} to search backward in the object code to
15238find the beginning of a function.
104c1213 15239
8e04817f
AC
15240@cindex response time, MIPS debugging
15241To improve response time (especially for embedded applications, where
15242@value{GDBN} may be restricted to a slow serial line for this search)
15243you may want to limit the size of this search, using one of these
15244commands:
104c1213 15245
8e04817f
AC
15246@table @code
15247@cindex @code{heuristic-fence-post} (Alpha, MIPS)
15248@item set heuristic-fence-post @var{limit}
15249Restrict @value{GDBN} to examining at most @var{limit} bytes in its
15250search for the beginning of a function. A value of @var{0} (the
15251default) means there is no limit. However, except for @var{0}, the
15252larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
15253and therefore the longer it takes to run. You should only need to use
15254this command when debugging a stripped executable.
104c1213 15255
8e04817f
AC
15256@item show heuristic-fence-post
15257Display the current limit.
15258@end table
104c1213
JM
15259
15260@noindent
8e04817f
AC
15261These commands are available @emph{only} when @value{GDBN} is configured
15262for debugging programs on Alpha or MIPS processors.
104c1213 15263
a64548ea
EZ
15264Several MIPS-specific commands are available when debugging MIPS
15265programs:
15266
15267@table @code
15268@item set mips saved-gpreg-size @var{size}
15269@kindex set mips saved-gpreg-size
15270@cindex MIPS GP register size on stack
15271Set the size of MIPS general-purpose registers saved on the stack.
15272The argument @var{size} can be one of the following:
15273
15274@table @samp
15275@item 32
1527632-bit GP registers
15277@item 64
1527864-bit GP registers
15279@item auto
15280Use the target's default setting or autodetect the saved size from the
15281information contained in the executable. This is the default
15282@end table
15283
15284@item show mips saved-gpreg-size
15285@kindex show mips saved-gpreg-size
15286Show the current size of MIPS GP registers on the stack.
15287
15288@item set mips stack-arg-size @var{size}
15289@kindex set mips stack-arg-size
15290@cindex MIPS stack space for arguments
15291Set the amount of stack space reserved for arguments to functions.
15292The argument can be one of @code{"32"}, @code{"64"} or @code{"auto"}
15293(the default).
15294
15295@item set mips abi @var{arg}
15296@kindex set mips abi
15297@cindex set ABI for MIPS
15298Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
15299values of @var{arg} are:
15300
15301@table @samp
15302@item auto
15303The default ABI associated with the current binary (this is the
15304default).
15305@item o32
15306@item o64
15307@item n32
15308@item n64
15309@item eabi32
15310@item eabi64
15311@item auto
15312@end table
15313
15314@item show mips abi
15315@kindex show mips abi
15316Show the MIPS ABI used by @value{GDBN} to debug the inferior.
15317
15318@item set mipsfpu
15319@itemx show mipsfpu
15320@xref{MIPS Embedded, set mipsfpu}.
15321
15322@item set mips mask-address @var{arg}
15323@kindex set mips mask-address
15324@cindex MIPS addresses, masking
15325This command determines whether the most-significant 32 bits of 64-bit
15326MIPS addresses are masked off. The argument @var{arg} can be
15327@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
15328setting, which lets @value{GDBN} determine the correct value.
15329
15330@item show mips mask-address
15331@kindex show mips mask-address
15332Show whether the upper 32 bits of MIPS addresses are masked off or
15333not.
15334
15335@item set remote-mips64-transfers-32bit-regs
15336@kindex set remote-mips64-transfers-32bit-regs
15337This command controls compatibility with 64-bit MIPS targets that
15338transfer data in 32-bit quantities. If you have an old MIPS 64 target
15339that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
15340and 64 bits for other registers, set this option to @samp{on}.
15341
15342@item show remote-mips64-transfers-32bit-regs
15343@kindex show remote-mips64-transfers-32bit-regs
15344Show the current setting of compatibility with older MIPS 64 targets.
15345
15346@item set debug mips
15347@kindex set debug mips
15348This command turns on and off debugging messages for the MIPS-specific
15349target code in @value{GDBN}.
15350
15351@item show debug mips
15352@kindex show debug mips
15353Show the current setting of MIPS debugging messages.
15354@end table
15355
15356
15357@node HPPA
15358@subsection HPPA
15359@cindex HPPA support
15360
15361When @value{GDBN} is debugging te HP PA architecture, it provides the
15362following special commands:
15363
15364@table @code
15365@item set debug hppa
15366@kindex set debug hppa
15367THis command determines whether HPPA architecture specific debugging
15368messages are to be displayed.
15369
15370@item show debug hppa
15371Show whether HPPA debugging messages are displayed.
15372
15373@item maint print unwind @var{address}
15374@kindex maint print unwind@r{, HPPA}
15375This command displays the contents of the unwind table entry at the
15376given @var{address}.
15377
15378@end table
15379
104c1213 15380
8e04817f
AC
15381@node Controlling GDB
15382@chapter Controlling @value{GDBN}
15383
15384You can alter the way @value{GDBN} interacts with you by using the
15385@code{set} command. For commands controlling how @value{GDBN} displays
15386data, see @ref{Print Settings, ,Print settings}. Other settings are
15387described here.
15388
15389@menu
15390* Prompt:: Prompt
15391* Editing:: Command editing
d620b259 15392* Command History:: Command history
8e04817f
AC
15393* Screen Size:: Screen size
15394* Numbers:: Numbers
1e698235 15395* ABI:: Configuring the current ABI
8e04817f
AC
15396* Messages/Warnings:: Optional warnings and messages
15397* Debugging Output:: Optional messages about internal happenings
15398@end menu
15399
15400@node Prompt
15401@section Prompt
104c1213 15402
8e04817f 15403@cindex prompt
104c1213 15404
8e04817f
AC
15405@value{GDBN} indicates its readiness to read a command by printing a string
15406called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
15407can change the prompt string with the @code{set prompt} command. For
15408instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
15409the prompt in one of the @value{GDBN} sessions so that you can always tell
15410which one you are talking to.
104c1213 15411
8e04817f
AC
15412@emph{Note:} @code{set prompt} does not add a space for you after the
15413prompt you set. This allows you to set a prompt which ends in a space
15414or a prompt that does not.
104c1213 15415
8e04817f
AC
15416@table @code
15417@kindex set prompt
15418@item set prompt @var{newprompt}
15419Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 15420
8e04817f
AC
15421@kindex show prompt
15422@item show prompt
15423Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
15424@end table
15425
8e04817f
AC
15426@node Editing
15427@section Command editing
15428@cindex readline
15429@cindex command line editing
104c1213 15430
703663ab 15431@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
15432@sc{gnu} library provides consistent behavior for programs which provide a
15433command line interface to the user. Advantages are @sc{gnu} Emacs-style
15434or @dfn{vi}-style inline editing of commands, @code{csh}-like history
15435substitution, and a storage and recall of command history across
15436debugging sessions.
104c1213 15437
8e04817f
AC
15438You may control the behavior of command line editing in @value{GDBN} with the
15439command @code{set}.
104c1213 15440
8e04817f
AC
15441@table @code
15442@kindex set editing
15443@cindex editing
15444@item set editing
15445@itemx set editing on
15446Enable command line editing (enabled by default).
104c1213 15447
8e04817f
AC
15448@item set editing off
15449Disable command line editing.
104c1213 15450
8e04817f
AC
15451@kindex show editing
15452@item show editing
15453Show whether command line editing is enabled.
104c1213
JM
15454@end table
15455
703663ab
EZ
15456@xref{Command Line Editing}, for more details about the Readline
15457interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
15458encouraged to read that chapter.
15459
d620b259 15460@node Command History
8e04817f 15461@section Command history
703663ab 15462@cindex command history
8e04817f
AC
15463
15464@value{GDBN} can keep track of the commands you type during your
15465debugging sessions, so that you can be certain of precisely what
15466happened. Use these commands to manage the @value{GDBN} command
15467history facility.
104c1213 15468
703663ab
EZ
15469@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
15470package, to provide the history facility. @xref{Using History
15471Interactively}, for the detailed description of the History library.
15472
d620b259
NR
15473To issue a command to @value{GDBN} without affecting certain aspects of
15474the state which is seen by users, prefix it with @samp{server }. This
15475means that this command will not affect the command history, nor will it
15476affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
15477pressed on a line by itself.
15478
15479@cindex @code{server}, command prefix
15480The server prefix does not affect the recording of values into the value
15481history; to print a value without recording it into the value history,
15482use the @code{output} command instead of the @code{print} command.
15483
703663ab
EZ
15484Here is the description of @value{GDBN} commands related to command
15485history.
15486
104c1213 15487@table @code
8e04817f
AC
15488@cindex history substitution
15489@cindex history file
15490@kindex set history filename
4644b6e3 15491@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
15492@item set history filename @var{fname}
15493Set the name of the @value{GDBN} command history file to @var{fname}.
15494This is the file where @value{GDBN} reads an initial command history
15495list, and where it writes the command history from this session when it
15496exits. You can access this list through history expansion or through
15497the history command editing characters listed below. This file defaults
15498to the value of the environment variable @code{GDBHISTFILE}, or to
15499@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
15500is not set.
104c1213 15501
9c16f35a
EZ
15502@cindex save command history
15503@kindex set history save
8e04817f
AC
15504@item set history save
15505@itemx set history save on
15506Record command history in a file, whose name may be specified with the
15507@code{set history filename} command. By default, this option is disabled.
104c1213 15508
8e04817f
AC
15509@item set history save off
15510Stop recording command history in a file.
104c1213 15511
8e04817f 15512@cindex history size
9c16f35a 15513@kindex set history size
6fc08d32 15514@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
15515@item set history size @var{size}
15516Set the number of commands which @value{GDBN} keeps in its history list.
15517This defaults to the value of the environment variable
15518@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
15519@end table
15520
8e04817f 15521History expansion assigns special meaning to the character @kbd{!}.
703663ab 15522@xref{Event Designators}, for more details.
8e04817f 15523
703663ab 15524@cindex history expansion, turn on/off
8e04817f
AC
15525Since @kbd{!} is also the logical not operator in C, history expansion
15526is off by default. If you decide to enable history expansion with the
15527@code{set history expansion on} command, you may sometimes need to
15528follow @kbd{!} (when it is used as logical not, in an expression) with
15529a space or a tab to prevent it from being expanded. The readline
15530history facilities do not attempt substitution on the strings
15531@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
15532
15533The commands to control history expansion are:
104c1213
JM
15534
15535@table @code
8e04817f
AC
15536@item set history expansion on
15537@itemx set history expansion
703663ab 15538@kindex set history expansion
8e04817f 15539Enable history expansion. History expansion is off by default.
104c1213 15540
8e04817f
AC
15541@item set history expansion off
15542Disable history expansion.
104c1213 15543
8e04817f
AC
15544@c @group
15545@kindex show history
15546@item show history
15547@itemx show history filename
15548@itemx show history save
15549@itemx show history size
15550@itemx show history expansion
15551These commands display the state of the @value{GDBN} history parameters.
15552@code{show history} by itself displays all four states.
15553@c @end group
15554@end table
15555
15556@table @code
9c16f35a
EZ
15557@kindex show commands
15558@cindex show last commands
15559@cindex display command history
8e04817f
AC
15560@item show commands
15561Display the last ten commands in the command history.
104c1213 15562
8e04817f
AC
15563@item show commands @var{n}
15564Print ten commands centered on command number @var{n}.
15565
15566@item show commands +
15567Print ten commands just after the commands last printed.
104c1213
JM
15568@end table
15569
8e04817f
AC
15570@node Screen Size
15571@section Screen size
15572@cindex size of screen
15573@cindex pauses in output
104c1213 15574
8e04817f
AC
15575Certain commands to @value{GDBN} may produce large amounts of
15576information output to the screen. To help you read all of it,
15577@value{GDBN} pauses and asks you for input at the end of each page of
15578output. Type @key{RET} when you want to continue the output, or @kbd{q}
15579to discard the remaining output. Also, the screen width setting
15580determines when to wrap lines of output. Depending on what is being
15581printed, @value{GDBN} tries to break the line at a readable place,
15582rather than simply letting it overflow onto the following line.
15583
15584Normally @value{GDBN} knows the size of the screen from the terminal
15585driver software. For example, on Unix @value{GDBN} uses the termcap data base
15586together with the value of the @code{TERM} environment variable and the
15587@code{stty rows} and @code{stty cols} settings. If this is not correct,
15588you can override it with the @code{set height} and @code{set
15589width} commands:
15590
15591@table @code
15592@kindex set height
15593@kindex set width
15594@kindex show width
15595@kindex show height
15596@item set height @var{lpp}
15597@itemx show height
15598@itemx set width @var{cpl}
15599@itemx show width
15600These @code{set} commands specify a screen height of @var{lpp} lines and
15601a screen width of @var{cpl} characters. The associated @code{show}
15602commands display the current settings.
104c1213 15603
8e04817f
AC
15604If you specify a height of zero lines, @value{GDBN} does not pause during
15605output no matter how long the output is. This is useful if output is to a
15606file or to an editor buffer.
104c1213 15607
8e04817f
AC
15608Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
15609from wrapping its output.
9c16f35a
EZ
15610
15611@item set pagination on
15612@itemx set pagination off
15613@kindex set pagination
15614Turn the output pagination on or off; the default is on. Turning
15615pagination off is the alternative to @code{set height 0}.
15616
15617@item show pagination
15618@kindex show pagination
15619Show the current pagination mode.
104c1213
JM
15620@end table
15621
8e04817f
AC
15622@node Numbers
15623@section Numbers
15624@cindex number representation
15625@cindex entering numbers
104c1213 15626
8e04817f
AC
15627You can always enter numbers in octal, decimal, or hexadecimal in
15628@value{GDBN} by the usual conventions: octal numbers begin with
15629@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
15630begin with @samp{0x}. Numbers that neither begin with @samp{0} or
15631@samp{0x}, nor end with a @samp{.} are, by default, entered in base
1563210; likewise, the default display for numbers---when no particular
15633format is specified---is base 10. You can change the default base for
15634both input and output with the commands described below.
104c1213 15635
8e04817f
AC
15636@table @code
15637@kindex set input-radix
15638@item set input-radix @var{base}
15639Set the default base for numeric input. Supported choices
15640for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15641specified either unambiguously or using the current input radix; for
8e04817f 15642example, any of
104c1213 15643
8e04817f 15644@smallexample
9c16f35a
EZ
15645set input-radix 012
15646set input-radix 10.
15647set input-radix 0xa
8e04817f 15648@end smallexample
104c1213 15649
8e04817f 15650@noindent
9c16f35a 15651sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
15652leaves the input radix unchanged, no matter what it was, since
15653@samp{10}, being without any leading or trailing signs of its base, is
15654interpreted in the current radix. Thus, if the current radix is 16,
15655@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
15656change the radix.
104c1213 15657
8e04817f
AC
15658@kindex set output-radix
15659@item set output-radix @var{base}
15660Set the default base for numeric display. Supported choices
15661for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15662specified either unambiguously or using the current input radix.
104c1213 15663
8e04817f
AC
15664@kindex show input-radix
15665@item show input-radix
15666Display the current default base for numeric input.
104c1213 15667
8e04817f
AC
15668@kindex show output-radix
15669@item show output-radix
15670Display the current default base for numeric display.
9c16f35a
EZ
15671
15672@item set radix @r{[}@var{base}@r{]}
15673@itemx show radix
15674@kindex set radix
15675@kindex show radix
15676These commands set and show the default base for both input and output
15677of numbers. @code{set radix} sets the radix of input and output to
15678the same base; without an argument, it resets the radix back to its
15679default value of 10.
15680
8e04817f 15681@end table
104c1213 15682
1e698235
DJ
15683@node ABI
15684@section Configuring the current ABI
15685
15686@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
15687application automatically. However, sometimes you need to override its
15688conclusions. Use these commands to manage @value{GDBN}'s view of the
15689current ABI.
15690
98b45e30
DJ
15691@cindex OS ABI
15692@kindex set osabi
b4e9345d 15693@kindex show osabi
98b45e30
DJ
15694
15695One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 15696system targets, either via remote debugging or native emulation.
98b45e30
DJ
15697@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
15698but you can override its conclusion using the @code{set osabi} command.
15699One example where this is useful is in debugging of binaries which use
15700an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
15701not have the same identifying marks that the standard C library for your
15702platform provides.
15703
15704@table @code
15705@item show osabi
15706Show the OS ABI currently in use.
15707
15708@item set osabi
15709With no argument, show the list of registered available OS ABI's.
15710
15711@item set osabi @var{abi}
15712Set the current OS ABI to @var{abi}.
15713@end table
15714
1e698235 15715@cindex float promotion
1e698235
DJ
15716
15717Generally, the way that an argument of type @code{float} is passed to a
15718function depends on whether the function is prototyped. For a prototyped
15719(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
15720according to the architecture's convention for @code{float}. For unprototyped
15721(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
15722@code{double} and then passed.
15723
15724Unfortunately, some forms of debug information do not reliably indicate whether
15725a function is prototyped. If @value{GDBN} calls a function that is not marked
15726as prototyped, it consults @kbd{set coerce-float-to-double}.
15727
15728@table @code
a8f24a35 15729@kindex set coerce-float-to-double
1e698235
DJ
15730@item set coerce-float-to-double
15731@itemx set coerce-float-to-double on
15732Arguments of type @code{float} will be promoted to @code{double} when passed
15733to an unprototyped function. This is the default setting.
15734
15735@item set coerce-float-to-double off
15736Arguments of type @code{float} will be passed directly to unprototyped
15737functions.
9c16f35a
EZ
15738
15739@kindex show coerce-float-to-double
15740@item show coerce-float-to-double
15741Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
15742@end table
15743
f1212245
DJ
15744@kindex set cp-abi
15745@kindex show cp-abi
15746@value{GDBN} needs to know the ABI used for your program's C@t{++}
15747objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
15748used to build your application. @value{GDBN} only fully supports
15749programs with a single C@t{++} ABI; if your program contains code using
15750multiple C@t{++} ABI's or if @value{GDBN} can not identify your
15751program's ABI correctly, you can tell @value{GDBN} which ABI to use.
15752Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
15753before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
15754``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
15755use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
15756``auto''.
15757
15758@table @code
15759@item show cp-abi
15760Show the C@t{++} ABI currently in use.
15761
15762@item set cp-abi
15763With no argument, show the list of supported C@t{++} ABI's.
15764
15765@item set cp-abi @var{abi}
15766@itemx set cp-abi auto
15767Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
15768@end table
15769
8e04817f
AC
15770@node Messages/Warnings
15771@section Optional warnings and messages
104c1213 15772
9c16f35a
EZ
15773@cindex verbose operation
15774@cindex optional warnings
8e04817f
AC
15775By default, @value{GDBN} is silent about its inner workings. If you are
15776running on a slow machine, you may want to use the @code{set verbose}
15777command. This makes @value{GDBN} tell you when it does a lengthy
15778internal operation, so you will not think it has crashed.
104c1213 15779
8e04817f
AC
15780Currently, the messages controlled by @code{set verbose} are those
15781which announce that the symbol table for a source file is being read;
15782see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 15783
8e04817f
AC
15784@table @code
15785@kindex set verbose
15786@item set verbose on
15787Enables @value{GDBN} output of certain informational messages.
104c1213 15788
8e04817f
AC
15789@item set verbose off
15790Disables @value{GDBN} output of certain informational messages.
104c1213 15791
8e04817f
AC
15792@kindex show verbose
15793@item show verbose
15794Displays whether @code{set verbose} is on or off.
15795@end table
104c1213 15796
8e04817f
AC
15797By default, if @value{GDBN} encounters bugs in the symbol table of an
15798object file, it is silent; but if you are debugging a compiler, you may
15799find this information useful (@pxref{Symbol Errors, ,Errors reading
15800symbol files}).
104c1213 15801
8e04817f 15802@table @code
104c1213 15803
8e04817f
AC
15804@kindex set complaints
15805@item set complaints @var{limit}
15806Permits @value{GDBN} to output @var{limit} complaints about each type of
15807unusual symbols before becoming silent about the problem. Set
15808@var{limit} to zero to suppress all complaints; set it to a large number
15809to prevent complaints from being suppressed.
104c1213 15810
8e04817f
AC
15811@kindex show complaints
15812@item show complaints
15813Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 15814
8e04817f 15815@end table
104c1213 15816
8e04817f
AC
15817By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
15818lot of stupid questions to confirm certain commands. For example, if
15819you try to run a program which is already running:
104c1213 15820
474c8240 15821@smallexample
8e04817f
AC
15822(@value{GDBP}) run
15823The program being debugged has been started already.
15824Start it from the beginning? (y or n)
474c8240 15825@end smallexample
104c1213 15826
8e04817f
AC
15827If you are willing to unflinchingly face the consequences of your own
15828commands, you can disable this ``feature'':
104c1213 15829
8e04817f 15830@table @code
104c1213 15831
8e04817f
AC
15832@kindex set confirm
15833@cindex flinching
15834@cindex confirmation
15835@cindex stupid questions
15836@item set confirm off
15837Disables confirmation requests.
104c1213 15838
8e04817f
AC
15839@item set confirm on
15840Enables confirmation requests (the default).
104c1213 15841
8e04817f
AC
15842@kindex show confirm
15843@item show confirm
15844Displays state of confirmation requests.
15845
15846@end table
104c1213 15847
8e04817f
AC
15848@node Debugging Output
15849@section Optional messages about internal happenings
4644b6e3
EZ
15850@cindex optional debugging messages
15851
da316a69
EZ
15852@value{GDBN} has commands that enable optional debugging messages from
15853various @value{GDBN} subsystems; normally these commands are of
15854interest to @value{GDBN} maintainers, or when reporting a bug. This
15855section documents those commands.
15856
104c1213 15857@table @code
a8f24a35
EZ
15858@kindex set exec-done-display
15859@item set exec-done-display
15860Turns on or off the notification of asynchronous commands'
15861completion. When on, @value{GDBN} will print a message when an
15862asynchronous command finishes its execution. The default is off.
15863@kindex show exec-done-display
15864@item show exec-done-display
15865Displays the current setting of asynchronous command completion
15866notification.
4644b6e3
EZ
15867@kindex set debug
15868@cindex gdbarch debugging info
a8f24a35 15869@cindex architecture debugging info
8e04817f 15870@item set debug arch
a8f24a35 15871Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 15872@kindex show debug
8e04817f
AC
15873@item show debug arch
15874Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
15875@item set debug aix-thread
15876@cindex AIX threads
15877Display debugging messages about inner workings of the AIX thread
15878module.
15879@item show debug aix-thread
15880Show the current state of AIX thread debugging info display.
8e04817f 15881@item set debug event
4644b6e3 15882@cindex event debugging info
a8f24a35 15883Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 15884default is off.
8e04817f
AC
15885@item show debug event
15886Displays the current state of displaying @value{GDBN} event debugging
15887info.
8e04817f 15888@item set debug expression
4644b6e3 15889@cindex expression debugging info
721c2651
EZ
15890Turns on or off display of debugging info about @value{GDBN}
15891expression parsing. The default is off.
8e04817f 15892@item show debug expression
721c2651
EZ
15893Displays the current state of displaying debugging info about
15894@value{GDBN} expression parsing.
7453dc06 15895@item set debug frame
4644b6e3 15896@cindex frame debugging info
7453dc06
AC
15897Turns on or off display of @value{GDBN} frame debugging info. The
15898default is off.
7453dc06
AC
15899@item show debug frame
15900Displays the current state of displaying @value{GDBN} frame debugging
15901info.
30e91e0b
RC
15902@item set debug infrun
15903@cindex inferior debugging info
15904Turns on or off display of @value{GDBN} debugging info for running the inferior.
15905The default is off. @file{infrun.c} contains GDB's runtime state machine used
15906for implementing operations such as single-stepping the inferior.
15907@item show debug infrun
15908Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
15909@item set debug lin-lwp
15910@cindex @sc{gnu}/Linux LWP debug messages
15911@cindex Linux lightweight processes
721c2651 15912Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
15913@item show debug lin-lwp
15914Show the current state of Linux LWP debugging messages.
2b4855ab 15915@item set debug observer
4644b6e3 15916@cindex observer debugging info
2b4855ab
AC
15917Turns on or off display of @value{GDBN} observer debugging. This
15918includes info such as the notification of observable events.
2b4855ab
AC
15919@item show debug observer
15920Displays the current state of observer debugging.
8e04817f 15921@item set debug overload
4644b6e3 15922@cindex C@t{++} overload debugging info
8e04817f 15923Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 15924info. This includes info such as ranking of functions, etc. The default
8e04817f 15925is off.
8e04817f
AC
15926@item show debug overload
15927Displays the current state of displaying @value{GDBN} C@t{++} overload
15928debugging info.
8e04817f
AC
15929@cindex packets, reporting on stdout
15930@cindex serial connections, debugging
15931@item set debug remote
15932Turns on or off display of reports on all packets sent back and forth across
15933the serial line to the remote machine. The info is printed on the
15934@value{GDBN} standard output stream. The default is off.
8e04817f
AC
15935@item show debug remote
15936Displays the state of display of remote packets.
8e04817f
AC
15937@item set debug serial
15938Turns on or off display of @value{GDBN} serial debugging info. The
15939default is off.
8e04817f
AC
15940@item show debug serial
15941Displays the current state of displaying @value{GDBN} serial debugging
15942info.
c45da7e6
EZ
15943@item set debug solib-frv
15944@cindex FR-V shared-library debugging
15945Turns on or off debugging messages for FR-V shared-library code.
15946@item show debug solib-frv
15947Display the current state of FR-V shared-library code debugging
15948messages.
8e04817f 15949@item set debug target
4644b6e3 15950@cindex target debugging info
8e04817f
AC
15951Turns on or off display of @value{GDBN} target debugging info. This info
15952includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
15953default is 0. Set it to 1 to track events, and to 2 to also track the
15954value of large memory transfers. Changes to this flag do not take effect
15955until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
15956@item show debug target
15957Displays the current state of displaying @value{GDBN} target debugging
15958info.
c45da7e6 15959@item set debugvarobj
4644b6e3 15960@cindex variable object debugging info
8e04817f
AC
15961Turns on or off display of @value{GDBN} variable object debugging
15962info. The default is off.
c45da7e6 15963@item show debugvarobj
8e04817f
AC
15964Displays the current state of displaying @value{GDBN} variable object
15965debugging info.
15966@end table
104c1213 15967
8e04817f
AC
15968@node Sequences
15969@chapter Canned Sequences of Commands
104c1213 15970
8e04817f
AC
15971Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
15972command lists}), @value{GDBN} provides two ways to store sequences of
15973commands for execution as a unit: user-defined commands and command
15974files.
104c1213 15975
8e04817f 15976@menu
fcc73fe3
EZ
15977* Define:: How to define your own commands
15978* Hooks:: Hooks for user-defined commands
15979* Command Files:: How to write scripts of commands to be stored in a file
15980* Output:: Commands for controlled output
8e04817f 15981@end menu
104c1213 15982
8e04817f
AC
15983@node Define
15984@section User-defined commands
104c1213 15985
8e04817f 15986@cindex user-defined command
fcc73fe3 15987@cindex arguments, to user-defined commands
8e04817f
AC
15988A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
15989which you assign a new name as a command. This is done with the
15990@code{define} command. User commands may accept up to 10 arguments
15991separated by whitespace. Arguments are accessed within the user command
c03c782f 15992via @code{$arg0@dots{}$arg9}. A trivial example:
104c1213 15993
8e04817f
AC
15994@smallexample
15995define adder
15996 print $arg0 + $arg1 + $arg2
c03c782f 15997end
8e04817f 15998@end smallexample
104c1213
JM
15999
16000@noindent
8e04817f 16001To execute the command use:
104c1213 16002
8e04817f
AC
16003@smallexample
16004adder 1 2 3
16005@end smallexample
104c1213 16006
8e04817f
AC
16007@noindent
16008This defines the command @code{adder}, which prints the sum of
16009its three arguments. Note the arguments are text substitutions, so they may
16010reference variables, use complex expressions, or even perform inferior
16011functions calls.
104c1213 16012
fcc73fe3
EZ
16013@cindex argument count in user-defined commands
16014@cindex how many arguments (user-defined commands)
c03c782f
AS
16015In addition, @code{$argc} may be used to find out how many arguments have
16016been passed. This expands to a number in the range 0@dots{}10.
16017
16018@smallexample
16019define adder
16020 if $argc == 2
16021 print $arg0 + $arg1
16022 end
16023 if $argc == 3
16024 print $arg0 + $arg1 + $arg2
16025 end
16026end
16027@end smallexample
16028
104c1213 16029@table @code
104c1213 16030
8e04817f
AC
16031@kindex define
16032@item define @var{commandname}
16033Define a command named @var{commandname}. If there is already a command
16034by that name, you are asked to confirm that you want to redefine it.
104c1213 16035
8e04817f
AC
16036The definition of the command is made up of other @value{GDBN} command lines,
16037which are given following the @code{define} command. The end of these
16038commands is marked by a line containing @code{end}.
104c1213 16039
8e04817f 16040@kindex document
ca91424e 16041@kindex end@r{ (user-defined commands)}
8e04817f
AC
16042@item document @var{commandname}
16043Document the user-defined command @var{commandname}, so that it can be
16044accessed by @code{help}. The command @var{commandname} must already be
16045defined. This command reads lines of documentation just as @code{define}
16046reads the lines of the command definition, ending with @code{end}.
16047After the @code{document} command is finished, @code{help} on command
16048@var{commandname} displays the documentation you have written.
104c1213 16049
8e04817f
AC
16050You may use the @code{document} command again to change the
16051documentation of a command. Redefining the command with @code{define}
16052does not change the documentation.
104c1213 16053
c45da7e6
EZ
16054@kindex dont-repeat
16055@cindex don't repeat command
16056@item dont-repeat
16057Used inside a user-defined command, this tells @value{GDBN} that this
16058command should not be repeated when the user hits @key{RET}
16059(@pxref{Command Syntax, repeat last command}).
16060
8e04817f
AC
16061@kindex help user-defined
16062@item help user-defined
16063List all user-defined commands, with the first line of the documentation
16064(if any) for each.
104c1213 16065
8e04817f
AC
16066@kindex show user
16067@item show user
16068@itemx show user @var{commandname}
16069Display the @value{GDBN} commands used to define @var{commandname} (but
16070not its documentation). If no @var{commandname} is given, display the
16071definitions for all user-defined commands.
104c1213 16072
fcc73fe3 16073@cindex infinite recursion in user-defined commands
20f01a46
DH
16074@kindex show max-user-call-depth
16075@kindex set max-user-call-depth
16076@item show max-user-call-depth
5ca0cb28
DH
16077@itemx set max-user-call-depth
16078The value of @code{max-user-call-depth} controls how many recursion
16079levels are allowed in user-defined commands before GDB suspects an
16080infinite recursion and aborts the command.
104c1213
JM
16081@end table
16082
fcc73fe3
EZ
16083In addition to the above commands, user-defined commands frequently
16084use control flow commands, described in @ref{Command Files}.
16085
8e04817f
AC
16086When user-defined commands are executed, the
16087commands of the definition are not printed. An error in any command
16088stops execution of the user-defined command.
104c1213 16089
8e04817f
AC
16090If used interactively, commands that would ask for confirmation proceed
16091without asking when used inside a user-defined command. Many @value{GDBN}
16092commands that normally print messages to say what they are doing omit the
16093messages when used in a user-defined command.
104c1213 16094
8e04817f
AC
16095@node Hooks
16096@section User-defined command hooks
16097@cindex command hooks
16098@cindex hooks, for commands
16099@cindex hooks, pre-command
104c1213 16100
8e04817f 16101@kindex hook
8e04817f
AC
16102You may define @dfn{hooks}, which are a special kind of user-defined
16103command. Whenever you run the command @samp{foo}, if the user-defined
16104command @samp{hook-foo} exists, it is executed (with no arguments)
16105before that command.
104c1213 16106
8e04817f
AC
16107@cindex hooks, post-command
16108@kindex hookpost
8e04817f
AC
16109A hook may also be defined which is run after the command you executed.
16110Whenever you run the command @samp{foo}, if the user-defined command
16111@samp{hookpost-foo} exists, it is executed (with no arguments) after
16112that command. Post-execution hooks may exist simultaneously with
16113pre-execution hooks, for the same command.
104c1213 16114
8e04817f 16115It is valid for a hook to call the command which it hooks. If this
9f1c6395 16116occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 16117
8e04817f
AC
16118@c It would be nice if hookpost could be passed a parameter indicating
16119@c if the command it hooks executed properly or not. FIXME!
104c1213 16120
8e04817f
AC
16121@kindex stop@r{, a pseudo-command}
16122In addition, a pseudo-command, @samp{stop} exists. Defining
16123(@samp{hook-stop}) makes the associated commands execute every time
16124execution stops in your program: before breakpoint commands are run,
16125displays are printed, or the stack frame is printed.
104c1213 16126
8e04817f
AC
16127For example, to ignore @code{SIGALRM} signals while
16128single-stepping, but treat them normally during normal execution,
16129you could define:
104c1213 16130
474c8240 16131@smallexample
8e04817f
AC
16132define hook-stop
16133handle SIGALRM nopass
16134end
104c1213 16135
8e04817f
AC
16136define hook-run
16137handle SIGALRM pass
16138end
104c1213 16139
8e04817f
AC
16140define hook-continue
16141handle SIGLARM pass
16142end
474c8240 16143@end smallexample
104c1213 16144
8e04817f 16145As a further example, to hook at the begining and end of the @code{echo}
b383017d 16146command, and to add extra text to the beginning and end of the message,
8e04817f 16147you could define:
104c1213 16148
474c8240 16149@smallexample
8e04817f
AC
16150define hook-echo
16151echo <<<---
16152end
104c1213 16153
8e04817f
AC
16154define hookpost-echo
16155echo --->>>\n
16156end
104c1213 16157
8e04817f
AC
16158(@value{GDBP}) echo Hello World
16159<<<---Hello World--->>>
16160(@value{GDBP})
104c1213 16161
474c8240 16162@end smallexample
104c1213 16163
8e04817f
AC
16164You can define a hook for any single-word command in @value{GDBN}, but
16165not for command aliases; you should define a hook for the basic command
c1468174 16166name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
16167@c FIXME! So how does Joe User discover whether a command is an alias
16168@c or not?
16169If an error occurs during the execution of your hook, execution of
16170@value{GDBN} commands stops and @value{GDBN} issues a prompt
16171(before the command that you actually typed had a chance to run).
104c1213 16172
8e04817f
AC
16173If you try to define a hook which does not match any known command, you
16174get a warning from the @code{define} command.
c906108c 16175
8e04817f
AC
16176@node Command Files
16177@section Command files
c906108c 16178
8e04817f 16179@cindex command files
fcc73fe3 16180@cindex scripting commands
6fc08d32
EZ
16181A command file for @value{GDBN} is a text file made of lines that are
16182@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
16183also be included. An empty line in a command file does nothing; it
16184does not mean to repeat the last command, as it would from the
16185terminal.
c906108c 16186
6fc08d32
EZ
16187You can request the execution of a command file with the @code{source}
16188command:
c906108c 16189
8e04817f
AC
16190@table @code
16191@kindex source
ca91424e 16192@cindex execute commands from a file
8e04817f
AC
16193@item source @var{filename}
16194Execute the command file @var{filename}.
c906108c
SS
16195@end table
16196
fcc73fe3
EZ
16197The lines in a command file are generally executed sequentially,
16198unless the order of execution is changed by one of the
16199@emph{flow-control commands} described below. The commands are not
a71ec265
DH
16200printed as they are executed. An error in any command terminates
16201execution of the command file and control is returned to the console.
c906108c 16202
8e04817f
AC
16203Commands that would ask for confirmation if used interactively proceed
16204without asking when used in a command file. Many @value{GDBN} commands that
16205normally print messages to say what they are doing omit the messages
16206when called from command files.
c906108c 16207
8e04817f
AC
16208@value{GDBN} also accepts command input from standard input. In this
16209mode, normal output goes to standard output and error output goes to
16210standard error. Errors in a command file supplied on standard input do
6fc08d32 16211not terminate execution of the command file---execution continues with
8e04817f 16212the next command.
c906108c 16213
474c8240 16214@smallexample
8e04817f 16215gdb < cmds > log 2>&1
474c8240 16216@end smallexample
c906108c 16217
8e04817f
AC
16218(The syntax above will vary depending on the shell used.) This example
16219will execute commands from the file @file{cmds}. All output and errors
16220would be directed to @file{log}.
c906108c 16221
fcc73fe3
EZ
16222Since commands stored on command files tend to be more general than
16223commands typed interactively, they frequently need to deal with
16224complicated situations, such as different or unexpected values of
16225variables and symbols, changes in how the program being debugged is
16226built, etc. @value{GDBN} provides a set of flow-control commands to
16227deal with these complexities. Using these commands, you can write
16228complex scripts that loop over data structures, execute commands
16229conditionally, etc.
16230
16231@table @code
16232@kindex if
16233@kindex else
16234@item if
16235@itemx else
16236This command allows to include in your script conditionally executed
16237commands. The @code{if} command takes a single argument, which is an
16238expression to evaluate. It is followed by a series of commands that
16239are executed only if the expression is true (its value is nonzero).
16240There can then optionally be an @code{else} line, followed by a series
16241of commands that are only executed if the expression was false. The
16242end of the list is marked by a line containing @code{end}.
16243
16244@kindex while
16245@item while
16246This command allows to write loops. Its syntax is similar to
16247@code{if}: the command takes a single argument, which is an expression
16248to evaluate, and must be followed by the commands to execute, one per
16249line, terminated by an @code{end}. These commands are called the
16250@dfn{body} of the loop. The commands in the body of @code{while} are
16251executed repeatedly as long as the expression evaluates to true.
16252
16253@kindex loop_break
16254@item loop_break
16255This command exits the @code{while} loop in whose body it is included.
16256Execution of the script continues after that @code{while}s @code{end}
16257line.
16258
16259@kindex loop_continue
16260@item loop_continue
16261This command skips the execution of the rest of the body of commands
16262in the @code{while} loop in whose body it is included. Execution
16263branches to the beginning of the @code{while} loop, where it evaluates
16264the controlling expression.
ca91424e
EZ
16265
16266@kindex end@r{ (if/else/while commands)}
16267@item end
16268Terminate the block of commands that are the body of @code{if},
16269@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
16270@end table
16271
16272
8e04817f
AC
16273@node Output
16274@section Commands for controlled output
c906108c 16275
8e04817f
AC
16276During the execution of a command file or a user-defined command, normal
16277@value{GDBN} output is suppressed; the only output that appears is what is
16278explicitly printed by the commands in the definition. This section
16279describes three commands useful for generating exactly the output you
16280want.
c906108c
SS
16281
16282@table @code
8e04817f
AC
16283@kindex echo
16284@item echo @var{text}
16285@c I do not consider backslash-space a standard C escape sequence
16286@c because it is not in ANSI.
16287Print @var{text}. Nonprinting characters can be included in
16288@var{text} using C escape sequences, such as @samp{\n} to print a
16289newline. @strong{No newline is printed unless you specify one.}
16290In addition to the standard C escape sequences, a backslash followed
16291by a space stands for a space. This is useful for displaying a
16292string with spaces at the beginning or the end, since leading and
16293trailing spaces are otherwise trimmed from all arguments.
16294To print @samp{@w{ }and foo =@w{ }}, use the command
16295@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 16296
8e04817f
AC
16297A backslash at the end of @var{text} can be used, as in C, to continue
16298the command onto subsequent lines. For example,
c906108c 16299
474c8240 16300@smallexample
8e04817f
AC
16301echo This is some text\n\
16302which is continued\n\
16303onto several lines.\n
474c8240 16304@end smallexample
c906108c 16305
8e04817f 16306produces the same output as
c906108c 16307
474c8240 16308@smallexample
8e04817f
AC
16309echo This is some text\n
16310echo which is continued\n
16311echo onto several lines.\n
474c8240 16312@end smallexample
c906108c 16313
8e04817f
AC
16314@kindex output
16315@item output @var{expression}
16316Print the value of @var{expression} and nothing but that value: no
16317newlines, no @samp{$@var{nn} = }. The value is not entered in the
16318value history either. @xref{Expressions, ,Expressions}, for more information
16319on expressions.
c906108c 16320
8e04817f
AC
16321@item output/@var{fmt} @var{expression}
16322Print the value of @var{expression} in format @var{fmt}. You can use
16323the same formats as for @code{print}. @xref{Output Formats,,Output
16324formats}, for more information.
c906108c 16325
8e04817f
AC
16326@kindex printf
16327@item printf @var{string}, @var{expressions}@dots{}
16328Print the values of the @var{expressions} under the control of
16329@var{string}. The @var{expressions} are separated by commas and may be
16330either numbers or pointers. Their values are printed as specified by
16331@var{string}, exactly as if your program were to execute the C
16332subroutine
16333@c FIXME: the above implies that at least all ANSI C formats are
16334@c supported, but it isn't true: %E and %G don't work (or so it seems).
16335@c Either this is a bug, or the manual should document what formats are
16336@c supported.
c906108c 16337
474c8240 16338@smallexample
8e04817f 16339printf (@var{string}, @var{expressions}@dots{});
474c8240 16340@end smallexample
c906108c 16341
8e04817f 16342For example, you can print two values in hex like this:
c906108c 16343
8e04817f
AC
16344@smallexample
16345printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
16346@end smallexample
c906108c 16347
8e04817f
AC
16348The only backslash-escape sequences that you can use in the format
16349string are the simple ones that consist of backslash followed by a
16350letter.
c906108c
SS
16351@end table
16352
21c294e6
AC
16353@node Interpreters
16354@chapter Command Interpreters
16355@cindex command interpreters
16356
16357@value{GDBN} supports multiple command interpreters, and some command
16358infrastructure to allow users or user interface writers to switch
16359between interpreters or run commands in other interpreters.
16360
16361@value{GDBN} currently supports two command interpreters, the console
16362interpreter (sometimes called the command-line interpreter or @sc{cli})
16363and the machine interface interpreter (or @sc{gdb/mi}). This manual
16364describes both of these interfaces in great detail.
16365
16366By default, @value{GDBN} will start with the console interpreter.
16367However, the user may choose to start @value{GDBN} with another
16368interpreter by specifying the @option{-i} or @option{--interpreter}
16369startup options. Defined interpreters include:
16370
16371@table @code
16372@item console
16373@cindex console interpreter
16374The traditional console or command-line interpreter. This is the most often
16375used interpreter with @value{GDBN}. With no interpreter specified at runtime,
16376@value{GDBN} will use this interpreter.
16377
16378@item mi
16379@cindex mi interpreter
16380The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
16381by programs wishing to use @value{GDBN} as a backend for a debugger GUI
16382or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
16383Interface}.
16384
16385@item mi2
16386@cindex mi2 interpreter
16387The current @sc{gdb/mi} interface.
16388
16389@item mi1
16390@cindex mi1 interpreter
16391The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
16392
16393@end table
16394
16395@cindex invoke another interpreter
16396The interpreter being used by @value{GDBN} may not be dynamically
16397switched at runtime. Although possible, this could lead to a very
16398precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
16399enters the command "interpreter-set console" in a console view,
16400@value{GDBN} would switch to using the console interpreter, rendering
16401the IDE inoperable!
16402
16403@kindex interpreter-exec
16404Although you may only choose a single interpreter at startup, you may execute
16405commands in any interpreter from the current interpreter using the appropriate
16406command. If you are running the console interpreter, simply use the
16407@code{interpreter-exec} command:
16408
16409@smallexample
16410interpreter-exec mi "-data-list-register-names"
16411@end smallexample
16412
16413@sc{gdb/mi} has a similar command, although it is only available in versions of
16414@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
16415
8e04817f
AC
16416@node TUI
16417@chapter @value{GDBN} Text User Interface
16418@cindex TUI
d0d5df6f 16419@cindex Text User Interface
c906108c 16420
8e04817f
AC
16421@menu
16422* TUI Overview:: TUI overview
16423* TUI Keys:: TUI key bindings
7cf36c78 16424* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
16425* TUI Commands:: TUI specific commands
16426* TUI Configuration:: TUI configuration variables
16427@end menu
c906108c 16428
d0d5df6f
AC
16429The @value{GDBN} Text User Interface, TUI in short, is a terminal
16430interface which uses the @code{curses} library to show the source
16431file, the assembly output, the program registers and @value{GDBN}
16432commands in separate text windows.
16433
16434The TUI is enabled by invoking @value{GDBN} using either
16435@pindex gdbtui
16436@samp{gdbtui} or @samp{gdb -tui}.
c906108c 16437
8e04817f
AC
16438@node TUI Overview
16439@section TUI overview
c906108c 16440
8e04817f
AC
16441The TUI has two display modes that can be switched while
16442@value{GDBN} runs:
c906108c 16443
8e04817f
AC
16444@itemize @bullet
16445@item
16446A curses (or TUI) mode in which it displays several text
16447windows on the terminal.
c906108c 16448
8e04817f
AC
16449@item
16450A standard mode which corresponds to the @value{GDBN} configured without
16451the TUI.
16452@end itemize
c906108c 16453
8e04817f
AC
16454In the TUI mode, @value{GDBN} can display several text window
16455on the terminal:
c906108c 16456
8e04817f
AC
16457@table @emph
16458@item command
16459This window is the @value{GDBN} command window with the @value{GDBN}
16460prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
16461managed using readline but through the TUI. The @emph{command}
16462window is always visible.
c906108c 16463
8e04817f
AC
16464@item source
16465The source window shows the source file of the program. The current
16466line as well as active breakpoints are displayed in this window.
c906108c 16467
8e04817f
AC
16468@item assembly
16469The assembly window shows the disassembly output of the program.
c906108c 16470
8e04817f
AC
16471@item register
16472This window shows the processor registers. It detects when
16473a register is changed and when this is the case, registers that have
6a1b180d 16474changed are highlighted.
c906108c 16475
c906108c
SS
16476@end table
16477
269c21fe
SC
16478The source and assembly windows show the current program position
16479by highlighting the current line and marking them with the @samp{>} marker.
16480Breakpoints are also indicated with two markers. A first one
16481indicates the breakpoint type:
16482
16483@table @code
16484@item B
16485Breakpoint which was hit at least once.
16486
16487@item b
16488Breakpoint which was never hit.
16489
16490@item H
16491Hardware breakpoint which was hit at least once.
16492
16493@item h
16494Hardware breakpoint which was never hit.
16495
16496@end table
16497
16498The second marker indicates whether the breakpoint is enabled or not:
16499
16500@table @code
16501@item +
16502Breakpoint is enabled.
16503
16504@item -
16505Breakpoint is disabled.
16506
16507@end table
16508
8e04817f
AC
16509The source, assembly and register windows are attached to the thread
16510and the frame position. They are updated when the current thread
16511changes, when the frame changes or when the program counter changes.
16512These three windows are arranged by the TUI according to several
16513layouts. The layout defines which of these three windows are visible.
16514The following layouts are available:
c906108c 16515
8e04817f
AC
16516@itemize @bullet
16517@item
16518source
2df3850c 16519
8e04817f
AC
16520@item
16521assembly
16522
16523@item
16524source and assembly
16525
16526@item
16527source and registers
c906108c 16528
8e04817f
AC
16529@item
16530assembly and registers
2df3850c 16531
8e04817f 16532@end itemize
c906108c 16533
b7bb15bc
SC
16534On top of the command window a status line gives various information
16535concerning the current process begin debugged. The status line is
16536updated when the information it shows changes. The following fields
16537are displayed:
16538
16539@table @emph
16540@item target
16541Indicates the current gdb target
16542(@pxref{Targets, ,Specifying a Debugging Target}).
16543
16544@item process
16545Gives information about the current process or thread number.
16546When no process is being debugged, this field is set to @code{No process}.
16547
16548@item function
16549Gives the current function name for the selected frame.
16550The name is demangled if demangling is turned on (@pxref{Print Settings}).
16551When there is no symbol corresponding to the current program counter
16552the string @code{??} is displayed.
16553
16554@item line
16555Indicates the current line number for the selected frame.
16556When the current line number is not known the string @code{??} is displayed.
16557
16558@item pc
16559Indicates the current program counter address.
16560
16561@end table
16562
8e04817f
AC
16563@node TUI Keys
16564@section TUI Key Bindings
16565@cindex TUI key bindings
c906108c 16566
8e04817f
AC
16567The TUI installs several key bindings in the readline keymaps
16568(@pxref{Command Line Editing}).
16569They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
16570directly on the TUI layout and windows. The TUI also provides
16571a @emph{SingleKey} keymap which binds several keys directly to
16572@value{GDBN} commands. The following key bindings
8e04817f 16573are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 16574
8e04817f
AC
16575@table @kbd
16576@kindex C-x C-a
16577@item C-x C-a
16578@kindex C-x a
16579@itemx C-x a
16580@kindex C-x A
16581@itemx C-x A
16582Enter or leave the TUI mode. When the TUI mode is left,
16583the curses window management is left and @value{GDBN} operates using
16584its standard mode writing on the terminal directly. When the TUI
16585mode is entered, the control is given back to the curses windows.
16586The screen is then refreshed.
c906108c 16587
8e04817f
AC
16588@kindex C-x 1
16589@item C-x 1
16590Use a TUI layout with only one window. The layout will
16591either be @samp{source} or @samp{assembly}. When the TUI mode
16592is not active, it will switch to the TUI mode.
2df3850c 16593
8e04817f 16594Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 16595
8e04817f
AC
16596@kindex C-x 2
16597@item C-x 2
16598Use a TUI layout with at least two windows. When the current
16599layout shows already two windows, a next layout with two windows is used.
16600When a new layout is chosen, one window will always be common to the
16601previous layout and the new one.
c906108c 16602
8e04817f 16603Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 16604
72ffddc9
SC
16605@kindex C-x o
16606@item C-x o
16607Change the active window. The TUI associates several key bindings
16608(like scrolling and arrow keys) to the active window. This command
16609gives the focus to the next TUI window.
16610
16611Think of it as the Emacs @kbd{C-x o} binding.
16612
7cf36c78
SC
16613@kindex C-x s
16614@item C-x s
16615Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
16616(@pxref{TUI Single Key Mode}).
16617
c906108c
SS
16618@end table
16619
8e04817f 16620The following key bindings are handled only by the TUI mode:
5d161b24 16621
8e04817f
AC
16622@table @key
16623@kindex PgUp
16624@item PgUp
16625Scroll the active window one page up.
c906108c 16626
8e04817f
AC
16627@kindex PgDn
16628@item PgDn
16629Scroll the active window one page down.
c906108c 16630
8e04817f
AC
16631@kindex Up
16632@item Up
16633Scroll the active window one line up.
c906108c 16634
8e04817f
AC
16635@kindex Down
16636@item Down
16637Scroll the active window one line down.
c906108c 16638
8e04817f
AC
16639@kindex Left
16640@item Left
16641Scroll the active window one column left.
c906108c 16642
8e04817f
AC
16643@kindex Right
16644@item Right
16645Scroll the active window one column right.
c906108c 16646
8e04817f
AC
16647@kindex C-L
16648@item C-L
16649Refresh the screen.
c906108c 16650
8e04817f 16651@end table
c906108c 16652
8e04817f 16653In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
16654for scrolling. This means they are available for readline when the
16655active window is the command window. When the command window
16656does not have the focus, it is necessary to use other readline
16657key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 16658
7cf36c78
SC
16659@node TUI Single Key Mode
16660@section TUI Single Key Mode
16661@cindex TUI single key mode
16662
16663The TUI provides a @emph{SingleKey} mode in which it installs a particular
16664key binding in the readline keymaps to connect single keys to
b383017d 16665some gdb commands.
7cf36c78
SC
16666
16667@table @kbd
16668@kindex c @r{(SingleKey TUI key)}
16669@item c
16670continue
16671
16672@kindex d @r{(SingleKey TUI key)}
16673@item d
16674down
16675
16676@kindex f @r{(SingleKey TUI key)}
16677@item f
16678finish
16679
16680@kindex n @r{(SingleKey TUI key)}
16681@item n
16682next
16683
16684@kindex q @r{(SingleKey TUI key)}
16685@item q
16686exit the @emph{SingleKey} mode.
16687
16688@kindex r @r{(SingleKey TUI key)}
16689@item r
16690run
16691
16692@kindex s @r{(SingleKey TUI key)}
16693@item s
16694step
16695
16696@kindex u @r{(SingleKey TUI key)}
16697@item u
16698up
16699
16700@kindex v @r{(SingleKey TUI key)}
16701@item v
16702info locals
16703
16704@kindex w @r{(SingleKey TUI key)}
16705@item w
16706where
16707
16708@end table
16709
16710Other keys temporarily switch to the @value{GDBN} command prompt.
16711The key that was pressed is inserted in the editing buffer so that
16712it is possible to type most @value{GDBN} commands without interaction
16713with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
16714@emph{SingleKey} mode is restored. The only way to permanently leave
16715this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
16716
16717
8e04817f
AC
16718@node TUI Commands
16719@section TUI specific commands
16720@cindex TUI commands
16721
16722The TUI has specific commands to control the text windows.
16723These commands are always available, that is they do not depend on
16724the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
16725is in the standard mode, using these commands will automatically switch
16726in the TUI mode.
c906108c
SS
16727
16728@table @code
3d757584
SC
16729@item info win
16730@kindex info win
16731List and give the size of all displayed windows.
16732
8e04817f 16733@item layout next
4644b6e3 16734@kindex layout
8e04817f 16735Display the next layout.
2df3850c 16736
8e04817f 16737@item layout prev
8e04817f 16738Display the previous layout.
c906108c 16739
8e04817f 16740@item layout src
8e04817f 16741Display the source window only.
c906108c 16742
8e04817f 16743@item layout asm
8e04817f 16744Display the assembly window only.
c906108c 16745
8e04817f 16746@item layout split
8e04817f 16747Display the source and assembly window.
c906108c 16748
8e04817f 16749@item layout regs
8e04817f
AC
16750Display the register window together with the source or assembly window.
16751
16752@item focus next | prev | src | asm | regs | split
16753@kindex focus
16754Set the focus to the named window.
16755This command allows to change the active window so that scrolling keys
16756can be affected to another window.
c906108c 16757
8e04817f
AC
16758@item refresh
16759@kindex refresh
16760Refresh the screen. This is similar to using @key{C-L} key.
c906108c 16761
6a1b180d
SC
16762@item tui reg float
16763@kindex tui reg
16764Show the floating point registers in the register window.
16765
16766@item tui reg general
16767Show the general registers in the register window.
16768
16769@item tui reg next
16770Show the next register group. The list of register groups as well as
16771their order is target specific. The predefined register groups are the
16772following: @code{general}, @code{float}, @code{system}, @code{vector},
16773@code{all}, @code{save}, @code{restore}.
16774
16775@item tui reg system
16776Show the system registers in the register window.
16777
8e04817f
AC
16778@item update
16779@kindex update
16780Update the source window and the current execution point.
c906108c 16781
8e04817f
AC
16782@item winheight @var{name} +@var{count}
16783@itemx winheight @var{name} -@var{count}
16784@kindex winheight
16785Change the height of the window @var{name} by @var{count}
16786lines. Positive counts increase the height, while negative counts
16787decrease it.
2df3850c 16788
c45da7e6
EZ
16789@item tabset
16790@kindex tabset @var{nchars}
16791Set the width of tab stops to be @var{nchars} characters.
16792
c906108c
SS
16793@end table
16794
8e04817f
AC
16795@node TUI Configuration
16796@section TUI configuration variables
16797@cindex TUI configuration variables
c906108c 16798
8e04817f
AC
16799The TUI has several configuration variables that control the
16800appearance of windows on the terminal.
c906108c 16801
8e04817f
AC
16802@table @code
16803@item set tui border-kind @var{kind}
16804@kindex set tui border-kind
16805Select the border appearance for the source, assembly and register windows.
16806The possible values are the following:
16807@table @code
16808@item space
16809Use a space character to draw the border.
c906108c 16810
8e04817f
AC
16811@item ascii
16812Use ascii characters + - and | to draw the border.
c906108c 16813
8e04817f
AC
16814@item acs
16815Use the Alternate Character Set to draw the border. The border is
16816drawn using character line graphics if the terminal supports them.
c78b4128 16817
8e04817f 16818@end table
c78b4128 16819
8e04817f
AC
16820@item set tui active-border-mode @var{mode}
16821@kindex set tui active-border-mode
16822Select the attributes to display the border of the active window.
16823The possible values are @code{normal}, @code{standout}, @code{reverse},
16824@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 16825
8e04817f
AC
16826@item set tui border-mode @var{mode}
16827@kindex set tui border-mode
16828Select the attributes to display the border of other windows.
16829The @var{mode} can be one of the following:
16830@table @code
16831@item normal
16832Use normal attributes to display the border.
c906108c 16833
8e04817f
AC
16834@item standout
16835Use standout mode.
c906108c 16836
8e04817f
AC
16837@item reverse
16838Use reverse video mode.
c906108c 16839
8e04817f
AC
16840@item half
16841Use half bright mode.
c906108c 16842
8e04817f
AC
16843@item half-standout
16844Use half bright and standout mode.
c906108c 16845
8e04817f
AC
16846@item bold
16847Use extra bright or bold mode.
c78b4128 16848
8e04817f
AC
16849@item bold-standout
16850Use extra bright or bold and standout mode.
c78b4128 16851
8e04817f 16852@end table
c78b4128 16853
8e04817f 16854@end table
c78b4128 16855
8e04817f
AC
16856@node Emacs
16857@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 16858
8e04817f
AC
16859@cindex Emacs
16860@cindex @sc{gnu} Emacs
16861A special interface allows you to use @sc{gnu} Emacs to view (and
16862edit) the source files for the program you are debugging with
16863@value{GDBN}.
c906108c 16864
8e04817f
AC
16865To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
16866executable file you want to debug as an argument. This command starts
16867@value{GDBN} as a subprocess of Emacs, with input and output through a newly
16868created Emacs buffer.
16869@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 16870
8e04817f
AC
16871Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
16872things:
c906108c 16873
8e04817f
AC
16874@itemize @bullet
16875@item
16876All ``terminal'' input and output goes through the Emacs buffer.
16877@end itemize
c906108c 16878
8e04817f
AC
16879This applies both to @value{GDBN} commands and their output, and to the input
16880and output done by the program you are debugging.
bf0184be 16881
8e04817f
AC
16882This is useful because it means that you can copy the text of previous
16883commands and input them again; you can even use parts of the output
16884in this way.
bf0184be 16885
8e04817f
AC
16886All the facilities of Emacs' Shell mode are available for interacting
16887with your program. In particular, you can send signals the usual
16888way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
16889stop.
bf0184be 16890
8e04817f 16891@itemize @bullet
bf0184be 16892@item
8e04817f
AC
16893@value{GDBN} displays source code through Emacs.
16894@end itemize
bf0184be 16895
8e04817f
AC
16896Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
16897source file for that frame and puts an arrow (@samp{=>}) at the
16898left margin of the current line. Emacs uses a separate buffer for
16899source display, and splits the screen to show both your @value{GDBN} session
16900and the source.
bf0184be 16901
8e04817f
AC
16902Explicit @value{GDBN} @code{list} or search commands still produce output as
16903usual, but you probably have no reason to use them from Emacs.
c906108c 16904
64fabec2
AC
16905If you specify an absolute file name when prompted for the @kbd{M-x
16906gdb} argument, then Emacs sets your current working directory to where
16907your program resides. If you only specify the file name, then Emacs
16908sets your current working directory to to the directory associated
16909with the previous buffer. In this case, @value{GDBN} may find your
16910program by searching your environment's @code{PATH} variable, but on
16911some operating systems it might not find the source. So, although the
16912@value{GDBN} input and output session proceeds normally, the auxiliary
16913buffer does not display the current source and line of execution.
16914
16915The initial working directory of @value{GDBN} is printed on the top
16916line of the @value{GDBN} I/O buffer and this serves as a default for
16917the commands that specify files for @value{GDBN} to operate
16918on. @xref{Files, ,Commands to specify files}.
16919
16920By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
16921need to call @value{GDBN} by a different name (for example, if you
16922keep several configurations around, with different names) you can
16923customize the Emacs variable @code{gud-gdb-command-name} to run the
16924one you want.
8e04817f
AC
16925
16926In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
16927addition to the standard Shell mode commands:
c906108c 16928
8e04817f
AC
16929@table @kbd
16930@item C-h m
16931Describe the features of Emacs' @value{GDBN} Mode.
c906108c 16932
64fabec2 16933@item C-c C-s
8e04817f
AC
16934Execute to another source line, like the @value{GDBN} @code{step} command; also
16935update the display window to show the current file and location.
c906108c 16936
64fabec2 16937@item C-c C-n
8e04817f
AC
16938Execute to next source line in this function, skipping all function
16939calls, like the @value{GDBN} @code{next} command. Then update the display window
16940to show the current file and location.
c906108c 16941
64fabec2 16942@item C-c C-i
8e04817f
AC
16943Execute one instruction, like the @value{GDBN} @code{stepi} command; update
16944display window accordingly.
c906108c 16945
8e04817f
AC
16946@item C-c C-f
16947Execute until exit from the selected stack frame, like the @value{GDBN}
16948@code{finish} command.
c906108c 16949
64fabec2 16950@item C-c C-r
8e04817f
AC
16951Continue execution of your program, like the @value{GDBN} @code{continue}
16952command.
b433d00b 16953
64fabec2 16954@item C-c <
8e04817f
AC
16955Go up the number of frames indicated by the numeric argument
16956(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
16957like the @value{GDBN} @code{up} command.
b433d00b 16958
64fabec2 16959@item C-c >
8e04817f
AC
16960Go down the number of frames indicated by the numeric argument, like the
16961@value{GDBN} @code{down} command.
8e04817f 16962@end table
c906108c 16963
64fabec2 16964In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 16965tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 16966
64fabec2
AC
16967If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
16968shows a backtrace when the @value{GDBN} I/O buffer is current. Move
16969point to any frame in the stack and type @key{RET} to make it become the
16970current frame and display the associated source in the source buffer.
16971Alternatively, click @kbd{Mouse-2} to make the selected frame become the
16972current one.
16973
8e04817f
AC
16974If you accidentally delete the source-display buffer, an easy way to get
16975it back is to type the command @code{f} in the @value{GDBN} buffer, to
16976request a frame display; when you run under Emacs, this recreates
16977the source buffer if necessary to show you the context of the current
16978frame.
c906108c 16979
8e04817f
AC
16980The source files displayed in Emacs are in ordinary Emacs buffers
16981which are visiting the source files in the usual way. You can edit
16982the files with these buffers if you wish; but keep in mind that @value{GDBN}
16983communicates with Emacs in terms of line numbers. If you add or
16984delete lines from the text, the line numbers that @value{GDBN} knows cease
16985to correspond properly with the code.
b383017d 16986
64fabec2
AC
16987The description given here is for GNU Emacs version 21.3 and a more
16988detailed description of its interaction with @value{GDBN} is given in
16989the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 16990
8e04817f
AC
16991@c The following dropped because Epoch is nonstandard. Reactivate
16992@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
16993@ignore
16994@kindex Emacs Epoch environment
16995@kindex Epoch
16996@kindex inspect
c906108c 16997
8e04817f
AC
16998Version 18 of @sc{gnu} Emacs has a built-in window system
16999called the @code{epoch}
17000environment. Users of this environment can use a new command,
17001@code{inspect} which performs identically to @code{print} except that
17002each value is printed in its own window.
17003@end ignore
c906108c 17004
922fbb7b
AC
17005
17006@node GDB/MI
17007@chapter The @sc{gdb/mi} Interface
17008
17009@unnumberedsec Function and Purpose
17010
17011@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
17012@sc{gdb/mi} is a line based machine oriented text interface to
17013@value{GDBN} and is activated by specifying using the
17014@option{--interpreter} command line option (@pxref{Mode Options}). It
17015is specifically intended to support the development of systems which
17016use the debugger as just one small component of a larger system.
922fbb7b
AC
17017
17018This chapter is a specification of the @sc{gdb/mi} interface. It is written
17019in the form of a reference manual.
17020
17021Note that @sc{gdb/mi} is still under construction, so some of the
17022features described below are incomplete and subject to change.
17023
17024@unnumberedsec Notation and Terminology
17025
17026@cindex notational conventions, for @sc{gdb/mi}
17027This chapter uses the following notation:
17028
17029@itemize @bullet
17030@item
17031@code{|} separates two alternatives.
17032
17033@item
17034@code{[ @var{something} ]} indicates that @var{something} is optional:
17035it may or may not be given.
17036
17037@item
17038@code{( @var{group} )*} means that @var{group} inside the parentheses
17039may repeat zero or more times.
17040
17041@item
17042@code{( @var{group} )+} means that @var{group} inside the parentheses
17043may repeat one or more times.
17044
17045@item
17046@code{"@var{string}"} means a literal @var{string}.
17047@end itemize
17048
17049@ignore
17050@heading Dependencies
17051@end ignore
17052
17053@heading Acknowledgments
17054
17055In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
17056Elena Zannoni.
17057
17058@menu
17059* GDB/MI Command Syntax::
17060* GDB/MI Compatibility with CLI::
17061* GDB/MI Output Records::
17062* GDB/MI Command Description Format::
17063* GDB/MI Breakpoint Table Commands::
17064* GDB/MI Data Manipulation::
17065* GDB/MI Program Control::
17066* GDB/MI Miscellaneous Commands::
17067@ignore
17068* GDB/MI Kod Commands::
17069* GDB/MI Memory Overlay Commands::
17070* GDB/MI Signal Handling Commands::
17071@end ignore
17072* GDB/MI Stack Manipulation::
17073* GDB/MI Symbol Query::
17074* GDB/MI Target Manipulation::
17075* GDB/MI Thread Commands::
17076* GDB/MI Tracepoint Commands::
17077* GDB/MI Variable Objects::
17078@end menu
17079
17080@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17081@node GDB/MI Command Syntax
17082@section @sc{gdb/mi} Command Syntax
17083
17084@menu
17085* GDB/MI Input Syntax::
17086* GDB/MI Output Syntax::
17087* GDB/MI Simple Examples::
17088@end menu
17089
17090@node GDB/MI Input Syntax
17091@subsection @sc{gdb/mi} Input Syntax
17092
17093@cindex input syntax for @sc{gdb/mi}
17094@cindex @sc{gdb/mi}, input syntax
17095@table @code
17096@item @var{command} @expansion{}
17097@code{@var{cli-command} | @var{mi-command}}
17098
17099@item @var{cli-command} @expansion{}
17100@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
17101@var{cli-command} is any existing @value{GDBN} CLI command.
17102
17103@item @var{mi-command} @expansion{}
17104@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
17105@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
17106
17107@item @var{token} @expansion{}
17108"any sequence of digits"
17109
17110@item @var{option} @expansion{}
17111@code{"-" @var{parameter} [ " " @var{parameter} ]}
17112
17113@item @var{parameter} @expansion{}
17114@code{@var{non-blank-sequence} | @var{c-string}}
17115
17116@item @var{operation} @expansion{}
17117@emph{any of the operations described in this chapter}
17118
17119@item @var{non-blank-sequence} @expansion{}
17120@emph{anything, provided it doesn't contain special characters such as
17121"-", @var{nl}, """ and of course " "}
17122
17123@item @var{c-string} @expansion{}
17124@code{""" @var{seven-bit-iso-c-string-content} """}
17125
17126@item @var{nl} @expansion{}
17127@code{CR | CR-LF}
17128@end table
17129
17130@noindent
17131Notes:
17132
17133@itemize @bullet
17134@item
17135The CLI commands are still handled by the @sc{mi} interpreter; their
17136output is described below.
17137
17138@item
17139The @code{@var{token}}, when present, is passed back when the command
17140finishes.
17141
17142@item
17143Some @sc{mi} commands accept optional arguments as part of the parameter
17144list. Each option is identified by a leading @samp{-} (dash) and may be
17145followed by an optional argument parameter. Options occur first in the
17146parameter list and can be delimited from normal parameters using
17147@samp{--} (this is useful when some parameters begin with a dash).
17148@end itemize
17149
17150Pragmatics:
17151
17152@itemize @bullet
17153@item
17154We want easy access to the existing CLI syntax (for debugging).
17155
17156@item
17157We want it to be easy to spot a @sc{mi} operation.
17158@end itemize
17159
17160@node GDB/MI Output Syntax
17161@subsection @sc{gdb/mi} Output Syntax
17162
17163@cindex output syntax of @sc{gdb/mi}
17164@cindex @sc{gdb/mi}, output syntax
17165The output from @sc{gdb/mi} consists of zero or more out-of-band records
17166followed, optionally, by a single result record. This result record
17167is for the most recent command. The sequence of output records is
17168terminated by @samp{(@value{GDBP})}.
17169
17170If an input command was prefixed with a @code{@var{token}} then the
17171corresponding output for that command will also be prefixed by that same
17172@var{token}.
17173
17174@table @code
17175@item @var{output} @expansion{}
f7dc1244 17176@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
922fbb7b
AC
17177
17178@item @var{result-record} @expansion{}
17179@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
17180
17181@item @var{out-of-band-record} @expansion{}
17182@code{@var{async-record} | @var{stream-record}}
17183
17184@item @var{async-record} @expansion{}
17185@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
17186
17187@item @var{exec-async-output} @expansion{}
17188@code{[ @var{token} ] "*" @var{async-output}}
17189
17190@item @var{status-async-output} @expansion{}
17191@code{[ @var{token} ] "+" @var{async-output}}
17192
17193@item @var{notify-async-output} @expansion{}
17194@code{[ @var{token} ] "=" @var{async-output}}
17195
17196@item @var{async-output} @expansion{}
17197@code{@var{async-class} ( "," @var{result} )* @var{nl}}
17198
17199@item @var{result-class} @expansion{}
17200@code{"done" | "running" | "connected" | "error" | "exit"}
17201
17202@item @var{async-class} @expansion{}
17203@code{"stopped" | @var{others}} (where @var{others} will be added
17204depending on the needs---this is still in development).
17205
17206@item @var{result} @expansion{}
17207@code{ @var{variable} "=" @var{value}}
17208
17209@item @var{variable} @expansion{}
17210@code{ @var{string} }
17211
17212@item @var{value} @expansion{}
17213@code{ @var{const} | @var{tuple} | @var{list} }
17214
17215@item @var{const} @expansion{}
17216@code{@var{c-string}}
17217
17218@item @var{tuple} @expansion{}
17219@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
17220
17221@item @var{list} @expansion{}
17222@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
17223@var{result} ( "," @var{result} )* "]" }
17224
17225@item @var{stream-record} @expansion{}
17226@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
17227
17228@item @var{console-stream-output} @expansion{}
17229@code{"~" @var{c-string}}
17230
17231@item @var{target-stream-output} @expansion{}
17232@code{"@@" @var{c-string}}
17233
17234@item @var{log-stream-output} @expansion{}
17235@code{"&" @var{c-string}}
17236
17237@item @var{nl} @expansion{}
17238@code{CR | CR-LF}
17239
17240@item @var{token} @expansion{}
17241@emph{any sequence of digits}.
17242@end table
17243
17244@noindent
17245Notes:
17246
17247@itemize @bullet
17248@item
17249All output sequences end in a single line containing a period.
17250
17251@item
17252The @code{@var{token}} is from the corresponding request. If an execution
17253command is interrupted by the @samp{-exec-interrupt} command, the
17254@var{token} associated with the @samp{*stopped} message is the one of the
17255original execution command, not the one of the interrupt command.
17256
17257@item
17258@cindex status output in @sc{gdb/mi}
17259@var{status-async-output} contains on-going status information about the
17260progress of a slow operation. It can be discarded. All status output is
17261prefixed by @samp{+}.
17262
17263@item
17264@cindex async output in @sc{gdb/mi}
17265@var{exec-async-output} contains asynchronous state change on the target
17266(stopped, started, disappeared). All async output is prefixed by
17267@samp{*}.
17268
17269@item
17270@cindex notify output in @sc{gdb/mi}
17271@var{notify-async-output} contains supplementary information that the
17272client should handle (e.g., a new breakpoint information). All notify
17273output is prefixed by @samp{=}.
17274
17275@item
17276@cindex console output in @sc{gdb/mi}
17277@var{console-stream-output} is output that should be displayed as is in the
17278console. It is the textual response to a CLI command. All the console
17279output is prefixed by @samp{~}.
17280
17281@item
17282@cindex target output in @sc{gdb/mi}
17283@var{target-stream-output} is the output produced by the target program.
17284All the target output is prefixed by @samp{@@}.
17285
17286@item
17287@cindex log output in @sc{gdb/mi}
17288@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
17289instance messages that should be displayed as part of an error log. All
17290the log output is prefixed by @samp{&}.
17291
17292@item
17293@cindex list output in @sc{gdb/mi}
17294New @sc{gdb/mi} commands should only output @var{lists} containing
17295@var{values}.
17296
17297
17298@end itemize
17299
17300@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
17301details about the various output records.
17302
17303@node GDB/MI Simple Examples
17304@subsection Simple Examples of @sc{gdb/mi} Interaction
17305@cindex @sc{gdb/mi}, simple examples
17306
17307This subsection presents several simple examples of interaction using
17308the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
17309following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
17310the output received from @sc{gdb/mi}.
17311
17312@subsubheading Target Stop
17313@c Ummm... There is no "-stop" command. This assumes async, no?
17314Here's an example of stopping the inferior process:
17315
17316@smallexample
17317-> -stop
17318<- (@value{GDBP})
17319@end smallexample
17320
17321@noindent
17322and later:
17323
17324@smallexample
17325<- *stop,reason="stop",address="0x123",source="a.c:123"
17326<- (@value{GDBP})
17327@end smallexample
17328
17329@subsubheading Simple CLI Command
17330
17331Here's an example of a simple CLI command being passed through
17332@sc{gdb/mi} and on to the CLI.
17333
17334@smallexample
17335-> print 1+2
17336<- &"print 1+2\n"
17337<- ~"$1 = 3\n"
17338<- ^done
17339<- (@value{GDBP})
17340@end smallexample
17341
17342@subsubheading Command With Side Effects
17343
17344@smallexample
17345-> -symbol-file xyz.exe
17346<- *breakpoint,nr="3",address="0x123",source="a.c:123"
17347<- (@value{GDBP})
17348@end smallexample
17349
17350@subsubheading A Bad Command
17351
17352Here's what happens if you pass a non-existent command:
17353
17354@smallexample
17355-> -rubbish
17356<- ^error,msg="Undefined MI command: rubbish"
17357<- (@value{GDBP})
17358@end smallexample
17359
17360@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17361@node GDB/MI Compatibility with CLI
17362@section @sc{gdb/mi} Compatibility with CLI
17363
17364@cindex compatibility, @sc{gdb/mi} and CLI
17365@cindex @sc{gdb/mi}, compatibility with CLI
17366To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
17367accepts existing CLI commands. As specified by the syntax, such
17368commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
17369respond.
17370
17371This mechanism is provided as an aid to developers of @sc{gdb/mi}
17372clients and not as a reliable interface into the CLI. Since the command
17373is being interpreteted in an environment that assumes @sc{gdb/mi}
17374behaviour, the exact output of such commands is likely to end up being
17375an un-supported hybrid of @sc{gdb/mi} and CLI output.
17376
17377@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17378@node GDB/MI Output Records
17379@section @sc{gdb/mi} Output Records
17380
17381@menu
17382* GDB/MI Result Records::
17383* GDB/MI Stream Records::
17384* GDB/MI Out-of-band Records::
17385@end menu
17386
17387@node GDB/MI Result Records
17388@subsection @sc{gdb/mi} Result Records
17389
17390@cindex result records in @sc{gdb/mi}
17391@cindex @sc{gdb/mi}, result records
17392In addition to a number of out-of-band notifications, the response to a
17393@sc{gdb/mi} command includes one of the following result indications:
17394
17395@table @code
17396@findex ^done
17397@item "^done" [ "," @var{results} ]
17398The synchronous operation was successful, @code{@var{results}} are the return
17399values.
17400
17401@item "^running"
17402@findex ^running
17403@c Is this one correct? Should it be an out-of-band notification?
17404The asynchronous operation was successfully started. The target is
17405running.
17406
17407@item "^error" "," @var{c-string}
17408@findex ^error
17409The operation failed. The @code{@var{c-string}} contains the corresponding
17410error message.
17411@end table
17412
17413@node GDB/MI Stream Records
17414@subsection @sc{gdb/mi} Stream Records
17415
17416@cindex @sc{gdb/mi}, stream records
17417@cindex stream records in @sc{gdb/mi}
17418@value{GDBN} internally maintains a number of output streams: the console, the
17419target, and the log. The output intended for each of these streams is
17420funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
17421
17422Each stream record begins with a unique @dfn{prefix character} which
17423identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
17424Syntax}). In addition to the prefix, each stream record contains a
17425@code{@var{string-output}}. This is either raw text (with an implicit new
17426line) or a quoted C string (which does not contain an implicit newline).
17427
17428@table @code
17429@item "~" @var{string-output}
17430The console output stream contains text that should be displayed in the
17431CLI console window. It contains the textual responses to CLI commands.
17432
17433@item "@@" @var{string-output}
17434The target output stream contains any textual output from the running
17435target.
17436
17437@item "&" @var{string-output}
17438The log stream contains debugging messages being produced by @value{GDBN}'s
17439internals.
17440@end table
17441
17442@node GDB/MI Out-of-band Records
17443@subsection @sc{gdb/mi} Out-of-band Records
17444
17445@cindex out-of-band records in @sc{gdb/mi}
17446@cindex @sc{gdb/mi}, out-of-band records
17447@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
17448additional changes that have occurred. Those changes can either be a
17449consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
17450target activity (e.g., target stopped).
17451
17452The following is a preliminary list of possible out-of-band records.
034dad6f 17453In particular, the @var{exec-async-output} records.
922fbb7b
AC
17454
17455@table @code
034dad6f
BR
17456@item *stopped,reason="@var{reason}"
17457@end table
17458
17459@var{reason} can be one of the following:
17460
17461@table @code
17462@item breakpoint-hit
17463A breakpoint was reached.
17464@item watchpoint-trigger
17465A watchpoint was triggered.
17466@item read-watchpoint-trigger
17467A read watchpoint was triggered.
17468@item access-watchpoint-trigger
17469An access watchpoint was triggered.
17470@item function-finished
17471An -exec-finish or similar CLI command was accomplished.
17472@item location-reached
17473An -exec-until or similar CLI command was accomplished.
17474@item watchpoint-scope
17475A watchpoint has gone out of scope.
17476@item end-stepping-range
17477An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
17478similar CLI command was accomplished.
17479@item exited-signalled
17480The inferior exited because of a signal.
17481@item exited
17482The inferior exited.
17483@item exited-normally
17484The inferior exited normally.
17485@item signal-received
17486A signal was received by the inferior.
922fbb7b
AC
17487@end table
17488
17489
17490@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17491@node GDB/MI Command Description Format
17492@section @sc{gdb/mi} Command Description Format
17493
17494The remaining sections describe blocks of commands. Each block of
17495commands is laid out in a fashion similar to this section.
17496
17497Note the the line breaks shown in the examples are here only for
17498readability. They don't appear in the real output.
17499Also note that the commands with a non-available example (N.A.@:) are
17500not yet implemented.
17501
17502@subheading Motivation
17503
17504The motivation for this collection of commands.
17505
17506@subheading Introduction
17507
17508A brief introduction to this collection of commands as a whole.
17509
17510@subheading Commands
17511
17512For each command in the block, the following is described:
17513
17514@subsubheading Synopsis
17515
17516@smallexample
17517 -command @var{args}@dots{}
17518@end smallexample
17519
922fbb7b
AC
17520@subsubheading Result
17521
265eeb58 17522@subsubheading @value{GDBN} Command
922fbb7b 17523
265eeb58 17524The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
17525
17526@subsubheading Example
17527
922fbb7b
AC
17528@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17529@node GDB/MI Breakpoint Table Commands
17530@section @sc{gdb/mi} Breakpoint table commands
17531
17532@cindex breakpoint commands for @sc{gdb/mi}
17533@cindex @sc{gdb/mi}, breakpoint commands
17534This section documents @sc{gdb/mi} commands for manipulating
17535breakpoints.
17536
17537@subheading The @code{-break-after} Command
17538@findex -break-after
17539
17540@subsubheading Synopsis
17541
17542@smallexample
17543 -break-after @var{number} @var{count}
17544@end smallexample
17545
17546The breakpoint number @var{number} is not in effect until it has been
17547hit @var{count} times. To see how this is reflected in the output of
17548the @samp{-break-list} command, see the description of the
17549@samp{-break-list} command below.
17550
17551@subsubheading @value{GDBN} Command
17552
17553The corresponding @value{GDBN} command is @samp{ignore}.
17554
17555@subsubheading Example
17556
17557@smallexample
17558(@value{GDBP})
17559-break-insert main
17560^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
17561(@value{GDBP})
17562-break-after 1 3
17563~
17564^done
17565(@value{GDBP})
17566-break-list
17567^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17568hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17569@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17570@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17571@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17572@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17573@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17574body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17575addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
17576ignore="3"@}]@}
17577(@value{GDBP})
17578@end smallexample
17579
17580@ignore
17581@subheading The @code{-break-catch} Command
17582@findex -break-catch
17583
17584@subheading The @code{-break-commands} Command
17585@findex -break-commands
17586@end ignore
17587
17588
17589@subheading The @code{-break-condition} Command
17590@findex -break-condition
17591
17592@subsubheading Synopsis
17593
17594@smallexample
17595 -break-condition @var{number} @var{expr}
17596@end smallexample
17597
17598Breakpoint @var{number} will stop the program only if the condition in
17599@var{expr} is true. The condition becomes part of the
17600@samp{-break-list} output (see the description of the @samp{-break-list}
17601command below).
17602
17603@subsubheading @value{GDBN} Command
17604
17605The corresponding @value{GDBN} command is @samp{condition}.
17606
17607@subsubheading Example
17608
17609@smallexample
17610(@value{GDBP})
17611-break-condition 1 1
17612^done
17613(@value{GDBP})
17614-break-list
17615^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17616hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17617@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17618@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17619@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17620@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17621@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17622body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17623addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
17624times="0",ignore="3"@}]@}
17625(@value{GDBP})
17626@end smallexample
17627
17628@subheading The @code{-break-delete} Command
17629@findex -break-delete
17630
17631@subsubheading Synopsis
17632
17633@smallexample
17634 -break-delete ( @var{breakpoint} )+
17635@end smallexample
17636
17637Delete the breakpoint(s) whose number(s) are specified in the argument
17638list. This is obviously reflected in the breakpoint list.
17639
17640@subsubheading @value{GDBN} command
17641
17642The corresponding @value{GDBN} command is @samp{delete}.
17643
17644@subsubheading Example
17645
17646@smallexample
17647(@value{GDBP})
17648-break-delete 1
17649^done
17650(@value{GDBP})
17651-break-list
17652^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17653hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17654@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17655@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17656@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17657@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17658@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17659body=[]@}
17660(@value{GDBP})
17661@end smallexample
17662
17663@subheading The @code{-break-disable} Command
17664@findex -break-disable
17665
17666@subsubheading Synopsis
17667
17668@smallexample
17669 -break-disable ( @var{breakpoint} )+
17670@end smallexample
17671
17672Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
17673break list is now set to @samp{n} for the named @var{breakpoint}(s).
17674
17675@subsubheading @value{GDBN} Command
17676
17677The corresponding @value{GDBN} command is @samp{disable}.
17678
17679@subsubheading Example
17680
17681@smallexample
17682(@value{GDBP})
17683-break-disable 2
17684^done
17685(@value{GDBP})
17686-break-list
17687^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17688hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17689@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17690@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17691@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17692@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17693@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17694body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
17695addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17696(@value{GDBP})
17697@end smallexample
17698
17699@subheading The @code{-break-enable} Command
17700@findex -break-enable
17701
17702@subsubheading Synopsis
17703
17704@smallexample
17705 -break-enable ( @var{breakpoint} )+
17706@end smallexample
17707
17708Enable (previously disabled) @var{breakpoint}(s).
17709
17710@subsubheading @value{GDBN} Command
17711
17712The corresponding @value{GDBN} command is @samp{enable}.
17713
17714@subsubheading Example
17715
17716@smallexample
17717(@value{GDBP})
17718-break-enable 2
17719^done
17720(@value{GDBP})
17721-break-list
17722^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17723hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17724@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17725@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17726@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17727@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17728@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17729body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17730addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17731(@value{GDBP})
17732@end smallexample
17733
17734@subheading The @code{-break-info} Command
17735@findex -break-info
17736
17737@subsubheading Synopsis
17738
17739@smallexample
17740 -break-info @var{breakpoint}
17741@end smallexample
17742
17743@c REDUNDANT???
17744Get information about a single breakpoint.
17745
17746@subsubheading @value{GDBN} command
17747
17748The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
17749
17750@subsubheading Example
17751N.A.
17752
17753@subheading The @code{-break-insert} Command
17754@findex -break-insert
17755
17756@subsubheading Synopsis
17757
17758@smallexample
17759 -break-insert [ -t ] [ -h ] [ -r ]
17760 [ -c @var{condition} ] [ -i @var{ignore-count} ]
17761 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
17762@end smallexample
17763
17764@noindent
17765If specified, @var{line}, can be one of:
17766
17767@itemize @bullet
17768@item function
17769@c @item +offset
17770@c @item -offset
17771@c @item linenum
17772@item filename:linenum
17773@item filename:function
17774@item *address
17775@end itemize
17776
17777The possible optional parameters of this command are:
17778
17779@table @samp
17780@item -t
17781Insert a tempoary breakpoint.
17782@item -h
17783Insert a hardware breakpoint.
17784@item -c @var{condition}
17785Make the breakpoint conditional on @var{condition}.
17786@item -i @var{ignore-count}
17787Initialize the @var{ignore-count}.
17788@item -r
17789Insert a regular breakpoint in all the functions whose names match the
17790given regular expression. Other flags are not applicable to regular
17791expresson.
17792@end table
17793
17794@subsubheading Result
17795
17796The result is in the form:
17797
17798@smallexample
17799 ^done,bkptno="@var{number}",func="@var{funcname}",
17800 file="@var{filename}",line="@var{lineno}"
17801@end smallexample
17802
17803@noindent
17804where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
17805is the name of the function where the breakpoint was inserted,
17806@var{filename} is the name of the source file which contains this
17807function, and @var{lineno} is the source line number within that file.
17808
17809Note: this format is open to change.
17810@c An out-of-band breakpoint instead of part of the result?
17811
17812@subsubheading @value{GDBN} Command
17813
17814The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
17815@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
17816
17817@subsubheading Example
17818
17819@smallexample
17820(@value{GDBP})
17821-break-insert main
17822^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17823(@value{GDBP})
17824-break-insert -t foo
17825^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
17826(@value{GDBP})
17827-break-list
17828^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17829hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17830@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17831@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17832@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17833@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17834@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17835body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17836addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
17837bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
17838addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
17839(@value{GDBP})
17840-break-insert -r foo.*
17841~int foo(int, int);
17842^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
17843(@value{GDBP})
17844@end smallexample
17845
17846@subheading The @code{-break-list} Command
17847@findex -break-list
17848
17849@subsubheading Synopsis
17850
17851@smallexample
17852 -break-list
17853@end smallexample
17854
17855Displays the list of inserted breakpoints, showing the following fields:
17856
17857@table @samp
17858@item Number
17859number of the breakpoint
17860@item Type
17861type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
17862@item Disposition
17863should the breakpoint be deleted or disabled when it is hit: @samp{keep}
17864or @samp{nokeep}
17865@item Enabled
17866is the breakpoint enabled or no: @samp{y} or @samp{n}
17867@item Address
17868memory location at which the breakpoint is set
17869@item What
17870logical location of the breakpoint, expressed by function name, file
17871name, line number
17872@item Times
17873number of times the breakpoint has been hit
17874@end table
17875
17876If there are no breakpoints or watchpoints, the @code{BreakpointTable}
17877@code{body} field is an empty list.
17878
17879@subsubheading @value{GDBN} Command
17880
17881The corresponding @value{GDBN} command is @samp{info break}.
17882
17883@subsubheading Example
17884
17885@smallexample
17886(@value{GDBP})
17887-break-list
17888^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17889hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17890@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17891@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17892@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17893@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17894@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17895body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17896addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
17897bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17898addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
17899(@value{GDBP})
17900@end smallexample
17901
17902Here's an example of the result when there are no breakpoints:
17903
17904@smallexample
17905(@value{GDBP})
17906-break-list
17907^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17908hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17909@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17910@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17911@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17912@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17913@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17914body=[]@}
17915(@value{GDBP})
17916@end smallexample
17917
17918@subheading The @code{-break-watch} Command
17919@findex -break-watch
17920
17921@subsubheading Synopsis
17922
17923@smallexample
17924 -break-watch [ -a | -r ]
17925@end smallexample
17926
17927Create a watchpoint. With the @samp{-a} option it will create an
17928@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
17929read from or on a write to the memory location. With the @samp{-r}
17930option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
17931trigger only when the memory location is accessed for reading. Without
17932either of the options, the watchpoint created is a regular watchpoint,
17933i.e. it will trigger when the memory location is accessed for writing.
17934@xref{Set Watchpoints, , Setting watchpoints}.
17935
17936Note that @samp{-break-list} will report a single list of watchpoints and
17937breakpoints inserted.
17938
17939@subsubheading @value{GDBN} Command
17940
17941The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
17942@samp{rwatch}.
17943
17944@subsubheading Example
17945
17946Setting a watchpoint on a variable in the @code{main} function:
17947
17948@smallexample
17949(@value{GDBP})
17950-break-watch x
17951^done,wpt=@{number="2",exp="x"@}
17952(@value{GDBP})
17953-exec-continue
17954^running
17955^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
17956value=@{old="-268439212",new="55"@},
76ff342d
DJ
17957frame=@{func="main",args=[],file="recursive2.c",
17958fullname="/home/foo/bar/devo/myproject/recursive2.c",line="5"@}
922fbb7b
AC
17959(@value{GDBP})
17960@end smallexample
17961
17962Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
17963the program execution twice: first for the variable changing value, then
17964for the watchpoint going out of scope.
17965
17966@smallexample
17967(@value{GDBP})
17968-break-watch C
17969^done,wpt=@{number="5",exp="C"@}
17970(@value{GDBP})
17971-exec-continue
17972^running
17973^done,reason="watchpoint-trigger",
17974wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
17975frame=@{func="callee4",args=[],
76ff342d
DJ
17976file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17977fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17978(@value{GDBP})
17979-exec-continue
17980^running
17981^done,reason="watchpoint-scope",wpnum="5",
17982frame=@{func="callee3",args=[@{name="strarg",
17983value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17984file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17985fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17986(@value{GDBP})
17987@end smallexample
17988
17989Listing breakpoints and watchpoints, at different points in the program
17990execution. Note that once the watchpoint goes out of scope, it is
17991deleted.
17992
17993@smallexample
17994(@value{GDBP})
17995-break-watch C
17996^done,wpt=@{number="2",exp="C"@}
17997(@value{GDBP})
17998-break-list
17999^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18000hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18001@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18002@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18003@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18004@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18005@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18006body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18007addr="0x00010734",func="callee4",
18008file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
18009bkpt=@{number="2",type="watchpoint",disp="keep",
18010enabled="y",addr="",what="C",times="0"@}]@}
18011(@value{GDBP})
18012-exec-continue
18013^running
18014^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
18015value=@{old="-276895068",new="3"@},
18016frame=@{func="callee4",args=[],
76ff342d
DJ
18017file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18018fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
18019(@value{GDBP})
18020-break-list
18021^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18022hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18023@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18024@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18025@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18026@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18027@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18028body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18029addr="0x00010734",func="callee4",
18030file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
18031bkpt=@{number="2",type="watchpoint",disp="keep",
18032enabled="y",addr="",what="C",times="-5"@}]@}
18033(@value{GDBP})
18034-exec-continue
18035^running
18036^done,reason="watchpoint-scope",wpnum="2",
18037frame=@{func="callee3",args=[@{name="strarg",
18038value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
18039file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18040fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
18041(@value{GDBP})
18042-break-list
18043^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18044hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18045@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18046@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18047@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18048@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18049@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18050body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18051addr="0x00010734",func="callee4",
18052file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
18053(@value{GDBP})
18054@end smallexample
18055
18056@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18057@node GDB/MI Data Manipulation
18058@section @sc{gdb/mi} Data Manipulation
18059
18060@cindex data manipulation, in @sc{gdb/mi}
18061@cindex @sc{gdb/mi}, data manipulation
18062This section describes the @sc{gdb/mi} commands that manipulate data:
18063examine memory and registers, evaluate expressions, etc.
18064
18065@c REMOVED FROM THE INTERFACE.
18066@c @subheading -data-assign
18067@c Change the value of a program variable. Plenty of side effects.
18068@c @subsubheading GDB command
18069@c set variable
18070@c @subsubheading Example
18071@c N.A.
18072
18073@subheading The @code{-data-disassemble} Command
18074@findex -data-disassemble
18075
18076@subsubheading Synopsis
18077
18078@smallexample
18079 -data-disassemble
18080 [ -s @var{start-addr} -e @var{end-addr} ]
18081 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
18082 -- @var{mode}
18083@end smallexample
18084
18085@noindent
18086Where:
18087
18088@table @samp
18089@item @var{start-addr}
18090is the beginning address (or @code{$pc})
18091@item @var{end-addr}
18092is the end address
18093@item @var{filename}
18094is the name of the file to disassemble
18095@item @var{linenum}
18096is the line number to disassemble around
18097@item @var{lines}
18098is the the number of disassembly lines to be produced. If it is -1,
18099the whole function will be disassembled, in case no @var{end-addr} is
18100specified. If @var{end-addr} is specified as a non-zero value, and
18101@var{lines} is lower than the number of disassembly lines between
18102@var{start-addr} and @var{end-addr}, only @var{lines} lines are
18103displayed; if @var{lines} is higher than the number of lines between
18104@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
18105are displayed.
18106@item @var{mode}
18107is either 0 (meaning only disassembly) or 1 (meaning mixed source and
18108disassembly).
18109@end table
18110
18111@subsubheading Result
18112
18113The output for each instruction is composed of four fields:
18114
18115@itemize @bullet
18116@item Address
18117@item Func-name
18118@item Offset
18119@item Instruction
18120@end itemize
18121
18122Note that whatever included in the instruction field, is not manipulated
18123directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
18124
18125@subsubheading @value{GDBN} Command
18126
18127There's no direct mapping from this command to the CLI.
18128
18129@subsubheading Example
18130
18131Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
18132
18133@smallexample
18134(@value{GDBP})
18135-data-disassemble -s $pc -e "$pc + 20" -- 0
18136^done,
18137asm_insns=[
18138@{address="0x000107c0",func-name="main",offset="4",
18139inst="mov 2, %o0"@},
18140@{address="0x000107c4",func-name="main",offset="8",
18141inst="sethi %hi(0x11800), %o2"@},
18142@{address="0x000107c8",func-name="main",offset="12",
18143inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
18144@{address="0x000107cc",func-name="main",offset="16",
18145inst="sethi %hi(0x11800), %o2"@},
18146@{address="0x000107d0",func-name="main",offset="20",
18147inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
18148(@value{GDBP})
18149@end smallexample
18150
18151Disassemble the whole @code{main} function. Line 32 is part of
18152@code{main}.
18153
18154@smallexample
18155-data-disassemble -f basics.c -l 32 -- 0
18156^done,asm_insns=[
18157@{address="0x000107bc",func-name="main",offset="0",
18158inst="save %sp, -112, %sp"@},
18159@{address="0x000107c0",func-name="main",offset="4",
18160inst="mov 2, %o0"@},
18161@{address="0x000107c4",func-name="main",offset="8",
18162inst="sethi %hi(0x11800), %o2"@},
18163[@dots{}]
18164@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
18165@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
18166(@value{GDBP})
18167@end smallexample
18168
18169Disassemble 3 instructions from the start of @code{main}:
18170
18171@smallexample
18172(@value{GDBP})
18173-data-disassemble -f basics.c -l 32 -n 3 -- 0
18174^done,asm_insns=[
18175@{address="0x000107bc",func-name="main",offset="0",
18176inst="save %sp, -112, %sp"@},
18177@{address="0x000107c0",func-name="main",offset="4",
18178inst="mov 2, %o0"@},
18179@{address="0x000107c4",func-name="main",offset="8",
18180inst="sethi %hi(0x11800), %o2"@}]
18181(@value{GDBP})
18182@end smallexample
18183
18184Disassemble 3 instructions from the start of @code{main} in mixed mode:
18185
18186@smallexample
18187(@value{GDBP})
18188-data-disassemble -f basics.c -l 32 -n 3 -- 1
18189^done,asm_insns=[
18190src_and_asm_line=@{line="31",
18191file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
18192 testsuite/gdb.mi/basics.c",line_asm_insn=[
18193@{address="0x000107bc",func-name="main",offset="0",
18194inst="save %sp, -112, %sp"@}]@},
18195src_and_asm_line=@{line="32",
18196file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
18197 testsuite/gdb.mi/basics.c",line_asm_insn=[
18198@{address="0x000107c0",func-name="main",offset="4",
18199inst="mov 2, %o0"@},
18200@{address="0x000107c4",func-name="main",offset="8",
18201inst="sethi %hi(0x11800), %o2"@}]@}]
18202(@value{GDBP})
18203@end smallexample
18204
18205
18206@subheading The @code{-data-evaluate-expression} Command
18207@findex -data-evaluate-expression
18208
18209@subsubheading Synopsis
18210
18211@smallexample
18212 -data-evaluate-expression @var{expr}
18213@end smallexample
18214
18215Evaluate @var{expr} as an expression. The expression could contain an
18216inferior function call. The function call will execute synchronously.
18217If the expression contains spaces, it must be enclosed in double quotes.
18218
18219@subsubheading @value{GDBN} Command
18220
18221The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
18222@samp{call}. In @code{gdbtk} only, there's a corresponding
18223@samp{gdb_eval} command.
18224
18225@subsubheading Example
18226
18227In the following example, the numbers that precede the commands are the
18228@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
18229Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
18230output.
18231
18232@smallexample
18233211-data-evaluate-expression A
18234211^done,value="1"
18235(@value{GDBP})
18236311-data-evaluate-expression &A
18237311^done,value="0xefffeb7c"
18238(@value{GDBP})
18239411-data-evaluate-expression A+3
18240411^done,value="4"
18241(@value{GDBP})
18242511-data-evaluate-expression "A + 3"
18243511^done,value="4"
18244(@value{GDBP})
18245@end smallexample
18246
18247
18248@subheading The @code{-data-list-changed-registers} Command
18249@findex -data-list-changed-registers
18250
18251@subsubheading Synopsis
18252
18253@smallexample
18254 -data-list-changed-registers
18255@end smallexample
18256
18257Display a list of the registers that have changed.
18258
18259@subsubheading @value{GDBN} Command
18260
18261@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
18262has the corresponding command @samp{gdb_changed_register_list}.
18263
18264@subsubheading Example
18265
18266On a PPC MBX board:
18267
18268@smallexample
18269(@value{GDBP})
18270-exec-continue
18271^running
18272
18273(@value{GDBP})
18274*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
76ff342d 18275args=[],file="try.c",fullname="/home/foo/bar/devo/myproject/try.c",line="5"@}
922fbb7b
AC
18276(@value{GDBP})
18277-data-list-changed-registers
18278^done,changed-registers=["0","1","2","4","5","6","7","8","9",
18279"10","11","13","14","15","16","17","18","19","20","21","22","23",
18280"24","25","26","27","28","30","31","64","65","66","67","69"]
18281(@value{GDBP})
18282@end smallexample
18283
18284
18285@subheading The @code{-data-list-register-names} Command
18286@findex -data-list-register-names
18287
18288@subsubheading Synopsis
18289
18290@smallexample
18291 -data-list-register-names [ ( @var{regno} )+ ]
18292@end smallexample
18293
18294Show a list of register names for the current target. If no arguments
18295are given, it shows a list of the names of all the registers. If
18296integer numbers are given as arguments, it will print a list of the
18297names of the registers corresponding to the arguments. To ensure
18298consistency between a register name and its number, the output list may
18299include empty register names.
18300
18301@subsubheading @value{GDBN} Command
18302
18303@value{GDBN} does not have a command which corresponds to
18304@samp{-data-list-register-names}. In @code{gdbtk} there is a
18305corresponding command @samp{gdb_regnames}.
18306
18307@subsubheading Example
18308
18309For the PPC MBX board:
18310@smallexample
18311(@value{GDBP})
18312-data-list-register-names
18313^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
18314"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
18315"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
18316"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
18317"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
18318"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
18319"", "pc","ps","cr","lr","ctr","xer"]
18320(@value{GDBP})
18321-data-list-register-names 1 2 3
18322^done,register-names=["r1","r2","r3"]
18323(@value{GDBP})
18324@end smallexample
18325
18326@subheading The @code{-data-list-register-values} Command
18327@findex -data-list-register-values
18328
18329@subsubheading Synopsis
18330
18331@smallexample
18332 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
18333@end smallexample
18334
18335Display the registers' contents. @var{fmt} is the format according to
18336which the registers' contents are to be returned, followed by an optional
18337list of numbers specifying the registers to display. A missing list of
18338numbers indicates that the contents of all the registers must be returned.
18339
18340Allowed formats for @var{fmt} are:
18341
18342@table @code
18343@item x
18344Hexadecimal
18345@item o
18346Octal
18347@item t
18348Binary
18349@item d
18350Decimal
18351@item r
18352Raw
18353@item N
18354Natural
18355@end table
18356
18357@subsubheading @value{GDBN} Command
18358
18359The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
18360all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
18361
18362@subsubheading Example
18363
18364For a PPC MBX board (note: line breaks are for readability only, they
18365don't appear in the actual output):
18366
18367@smallexample
18368(@value{GDBP})
18369-data-list-register-values r 64 65
18370^done,register-values=[@{number="64",value="0xfe00a300"@},
18371@{number="65",value="0x00029002"@}]
18372(@value{GDBP})
18373-data-list-register-values x
18374^done,register-values=[@{number="0",value="0xfe0043c8"@},
18375@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
18376@{number="3",value="0x0"@},@{number="4",value="0xa"@},
18377@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
18378@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
18379@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
18380@{number="11",value="0x1"@},@{number="12",value="0x0"@},
18381@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
18382@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
18383@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
18384@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
18385@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
18386@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
18387@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
18388@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
18389@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
18390@{number="31",value="0x0"@},@{number="32",value="0x0"@},
18391@{number="33",value="0x0"@},@{number="34",value="0x0"@},
18392@{number="35",value="0x0"@},@{number="36",value="0x0"@},
18393@{number="37",value="0x0"@},@{number="38",value="0x0"@},
18394@{number="39",value="0x0"@},@{number="40",value="0x0"@},
18395@{number="41",value="0x0"@},@{number="42",value="0x0"@},
18396@{number="43",value="0x0"@},@{number="44",value="0x0"@},
18397@{number="45",value="0x0"@},@{number="46",value="0x0"@},
18398@{number="47",value="0x0"@},@{number="48",value="0x0"@},
18399@{number="49",value="0x0"@},@{number="50",value="0x0"@},
18400@{number="51",value="0x0"@},@{number="52",value="0x0"@},
18401@{number="53",value="0x0"@},@{number="54",value="0x0"@},
18402@{number="55",value="0x0"@},@{number="56",value="0x0"@},
18403@{number="57",value="0x0"@},@{number="58",value="0x0"@},
18404@{number="59",value="0x0"@},@{number="60",value="0x0"@},
18405@{number="61",value="0x0"@},@{number="62",value="0x0"@},
18406@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
18407@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
18408@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
18409@{number="69",value="0x20002b03"@}]
18410(@value{GDBP})
18411@end smallexample
18412
18413
18414@subheading The @code{-data-read-memory} Command
18415@findex -data-read-memory
18416
18417@subsubheading Synopsis
18418
18419@smallexample
18420 -data-read-memory [ -o @var{byte-offset} ]
18421 @var{address} @var{word-format} @var{word-size}
18422 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
18423@end smallexample
18424
18425@noindent
18426where:
18427
18428@table @samp
18429@item @var{address}
18430An expression specifying the address of the first memory word to be
18431read. Complex expressions containing embedded white space should be
18432quoted using the C convention.
18433
18434@item @var{word-format}
18435The format to be used to print the memory words. The notation is the
18436same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
18437,Output formats}).
18438
18439@item @var{word-size}
18440The size of each memory word in bytes.
18441
18442@item @var{nr-rows}
18443The number of rows in the output table.
18444
18445@item @var{nr-cols}
18446The number of columns in the output table.
18447
18448@item @var{aschar}
18449If present, indicates that each row should include an @sc{ascii} dump. The
18450value of @var{aschar} is used as a padding character when a byte is not a
18451member of the printable @sc{ascii} character set (printable @sc{ascii}
18452characters are those whose code is between 32 and 126, inclusively).
18453
18454@item @var{byte-offset}
18455An offset to add to the @var{address} before fetching memory.
18456@end table
18457
18458This command displays memory contents as a table of @var{nr-rows} by
18459@var{nr-cols} words, each word being @var{word-size} bytes. In total,
18460@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
18461(returned as @samp{total-bytes}). Should less than the requested number
18462of bytes be returned by the target, the missing words are identified
18463using @samp{N/A}. The number of bytes read from the target is returned
18464in @samp{nr-bytes} and the starting address used to read memory in
18465@samp{addr}.
18466
18467The address of the next/previous row or page is available in
18468@samp{next-row} and @samp{prev-row}, @samp{next-page} and
18469@samp{prev-page}.
18470
18471@subsubheading @value{GDBN} Command
18472
18473The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
18474@samp{gdb_get_mem} memory read command.
18475
18476@subsubheading Example
18477
18478Read six bytes of memory starting at @code{bytes+6} but then offset by
18479@code{-6} bytes. Format as three rows of two columns. One byte per
18480word. Display each word in hex.
18481
18482@smallexample
18483(@value{GDBP})
184849-data-read-memory -o -6 -- bytes+6 x 1 3 2
184859^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
18486next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
18487prev-page="0x0000138a",memory=[
18488@{addr="0x00001390",data=["0x00","0x01"]@},
18489@{addr="0x00001392",data=["0x02","0x03"]@},
18490@{addr="0x00001394",data=["0x04","0x05"]@}]
18491(@value{GDBP})
18492@end smallexample
18493
18494Read two bytes of memory starting at address @code{shorts + 64} and
18495display as a single word formatted in decimal.
18496
18497@smallexample
18498(@value{GDBP})
184995-data-read-memory shorts+64 d 2 1 1
185005^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
18501next-row="0x00001512",prev-row="0x0000150e",
18502next-page="0x00001512",prev-page="0x0000150e",memory=[
18503@{addr="0x00001510",data=["128"]@}]
18504(@value{GDBP})
18505@end smallexample
18506
18507Read thirty two bytes of memory starting at @code{bytes+16} and format
18508as eight rows of four columns. Include a string encoding with @samp{x}
18509used as the non-printable character.
18510
18511@smallexample
18512(@value{GDBP})
185134-data-read-memory bytes+16 x 1 8 4 x
185144^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
18515next-row="0x000013c0",prev-row="0x0000139c",
18516next-page="0x000013c0",prev-page="0x00001380",memory=[
18517@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
18518@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
18519@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
18520@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
18521@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
18522@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
18523@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
18524@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
18525(@value{GDBP})
18526@end smallexample
18527
18528@subheading The @code{-display-delete} Command
18529@findex -display-delete
18530
18531@subsubheading Synopsis
18532
18533@smallexample
18534 -display-delete @var{number}
18535@end smallexample
18536
18537Delete the display @var{number}.
18538
18539@subsubheading @value{GDBN} Command
18540
18541The corresponding @value{GDBN} command is @samp{delete display}.
18542
18543@subsubheading Example
18544N.A.
18545
18546
18547@subheading The @code{-display-disable} Command
18548@findex -display-disable
18549
18550@subsubheading Synopsis
18551
18552@smallexample
18553 -display-disable @var{number}
18554@end smallexample
18555
18556Disable display @var{number}.
18557
18558@subsubheading @value{GDBN} Command
18559
18560The corresponding @value{GDBN} command is @samp{disable display}.
18561
18562@subsubheading Example
18563N.A.
18564
18565
18566@subheading The @code{-display-enable} Command
18567@findex -display-enable
18568
18569@subsubheading Synopsis
18570
18571@smallexample
18572 -display-enable @var{number}
18573@end smallexample
18574
18575Enable display @var{number}.
18576
18577@subsubheading @value{GDBN} Command
18578
18579The corresponding @value{GDBN} command is @samp{enable display}.
18580
18581@subsubheading Example
18582N.A.
18583
18584
18585@subheading The @code{-display-insert} Command
18586@findex -display-insert
18587
18588@subsubheading Synopsis
18589
18590@smallexample
18591 -display-insert @var{expression}
18592@end smallexample
18593
18594Display @var{expression} every time the program stops.
18595
18596@subsubheading @value{GDBN} Command
18597
18598The corresponding @value{GDBN} command is @samp{display}.
18599
18600@subsubheading Example
18601N.A.
18602
18603
18604@subheading The @code{-display-list} Command
18605@findex -display-list
18606
18607@subsubheading Synopsis
18608
18609@smallexample
18610 -display-list
18611@end smallexample
18612
18613List the displays. Do not show the current values.
18614
18615@subsubheading @value{GDBN} Command
18616
18617The corresponding @value{GDBN} command is @samp{info display}.
18618
18619@subsubheading Example
18620N.A.
18621
18622
18623@subheading The @code{-environment-cd} Command
18624@findex -environment-cd
18625
18626@subsubheading Synopsis
18627
18628@smallexample
18629 -environment-cd @var{pathdir}
18630@end smallexample
18631
18632Set @value{GDBN}'s working directory.
18633
18634@subsubheading @value{GDBN} Command
18635
18636The corresponding @value{GDBN} command is @samp{cd}.
18637
18638@subsubheading Example
18639
18640@smallexample
18641(@value{GDBP})
18642-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18643^done
18644(@value{GDBP})
18645@end smallexample
18646
18647
18648@subheading The @code{-environment-directory} Command
18649@findex -environment-directory
18650
18651@subsubheading Synopsis
18652
18653@smallexample
18654 -environment-directory [ -r ] [ @var{pathdir} ]+
18655@end smallexample
18656
18657Add directories @var{pathdir} to beginning of search path for source files.
18658If the @samp{-r} option is used, the search path is reset to the default
b383017d 18659search path. If directories @var{pathdir} are supplied in addition to the
922fbb7b
AC
18660@samp{-r} option, the search path is first reset and then addition
18661occurs as normal.
b383017d 18662Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18663multiple directories in a single command
18664results in the directories added to the beginning of the
18665search path in the same order they were presented in the command.
18666If blanks are needed as
18667part of a directory name, double-quotes should be used around
18668the name. In the command output, the path will show up separated
b383017d 18669by the system directory-separator character. The directory-seperator
922fbb7b
AC
18670character must not be used
18671in any directory name.
18672If no directories are specified, the current search path is displayed.
18673
18674@subsubheading @value{GDBN} Command
18675
18676The corresponding @value{GDBN} command is @samp{dir}.
18677
18678@subsubheading Example
18679
18680@smallexample
18681(@value{GDBP})
18682-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18683^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18684(@value{GDBP})
18685-environment-directory ""
18686^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18687(@value{GDBP})
18688-environment-directory -r /home/jjohnstn/src/gdb /usr/src
18689^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
18690(@value{GDBP})
18691-environment-directory -r
18692^done,source-path="$cdir:$cwd"
18693(@value{GDBP})
18694@end smallexample
18695
18696
18697@subheading The @code{-environment-path} Command
18698@findex -environment-path
18699
18700@subsubheading Synopsis
18701
18702@smallexample
18703 -environment-path [ -r ] [ @var{pathdir} ]+
18704@end smallexample
18705
18706Add directories @var{pathdir} to beginning of search path for object files.
18707If the @samp{-r} option is used, the search path is reset to the original
b383017d
RM
18708search path that existed at gdb start-up. If directories @var{pathdir} are
18709supplied in addition to the
922fbb7b
AC
18710@samp{-r} option, the search path is first reset and then addition
18711occurs as normal.
b383017d 18712Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18713multiple directories in a single command
18714results in the directories added to the beginning of the
18715search path in the same order they were presented in the command.
18716If blanks are needed as
18717part of a directory name, double-quotes should be used around
18718the name. In the command output, the path will show up separated
b383017d 18719by the system directory-separator character. The directory-seperator
922fbb7b
AC
18720character must not be used
18721in any directory name.
18722If no directories are specified, the current path is displayed.
18723
18724
18725@subsubheading @value{GDBN} Command
18726
18727The corresponding @value{GDBN} command is @samp{path}.
18728
18729@subsubheading Example
18730
18731@smallexample
18732(@value{GDBP})
b383017d 18733-environment-path
922fbb7b
AC
18734^done,path="/usr/bin"
18735(@value{GDBP})
18736-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
18737^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
18738(@value{GDBP})
18739-environment-path -r /usr/local/bin
18740^done,path="/usr/local/bin:/usr/bin"
18741(@value{GDBP})
18742@end smallexample
18743
18744
18745@subheading The @code{-environment-pwd} Command
18746@findex -environment-pwd
18747
18748@subsubheading Synopsis
18749
18750@smallexample
18751 -environment-pwd
18752@end smallexample
18753
18754Show the current working directory.
18755
18756@subsubheading @value{GDBN} command
18757
18758The corresponding @value{GDBN} command is @samp{pwd}.
18759
18760@subsubheading Example
18761
18762@smallexample
18763(@value{GDBP})
18764-environment-pwd
18765^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
18766(@value{GDBP})
18767@end smallexample
18768
18769@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18770@node GDB/MI Program Control
18771@section @sc{gdb/mi} Program control
18772
18773@subsubheading Program termination
18774
18775As a result of execution, the inferior program can run to completion, if
18776it doesn't encounter any breakpoints. In this case the output will
18777include an exit code, if the program has exited exceptionally.
18778
18779@subsubheading Examples
18780
18781@noindent
18782Program exited normally:
18783
18784@smallexample
18785(@value{GDBP})
18786-exec-run
18787^running
18788(@value{GDBP})
18789x = 55
18790*stopped,reason="exited-normally"
18791(@value{GDBP})
18792@end smallexample
18793
18794@noindent
18795Program exited exceptionally:
18796
18797@smallexample
18798(@value{GDBP})
18799-exec-run
18800^running
18801(@value{GDBP})
18802x = 55
18803*stopped,reason="exited",exit-code="01"
18804(@value{GDBP})
18805@end smallexample
18806
18807Another way the program can terminate is if it receives a signal such as
18808@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
18809
18810@smallexample
18811(@value{GDBP})
18812*stopped,reason="exited-signalled",signal-name="SIGINT",
18813signal-meaning="Interrupt"
18814@end smallexample
18815
18816
18817@subheading The @code{-exec-abort} Command
18818@findex -exec-abort
18819
18820@subsubheading Synopsis
18821
18822@smallexample
18823 -exec-abort
18824@end smallexample
18825
18826Kill the inferior running program.
18827
18828@subsubheading @value{GDBN} Command
18829
18830The corresponding @value{GDBN} command is @samp{kill}.
18831
18832@subsubheading Example
18833N.A.
18834
18835
18836@subheading The @code{-exec-arguments} Command
18837@findex -exec-arguments
18838
18839@subsubheading Synopsis
18840
18841@smallexample
18842 -exec-arguments @var{args}
18843@end smallexample
18844
18845Set the inferior program arguments, to be used in the next
18846@samp{-exec-run}.
18847
18848@subsubheading @value{GDBN} Command
18849
18850The corresponding @value{GDBN} command is @samp{set args}.
18851
18852@subsubheading Example
18853
18854@c FIXME!
18855Don't have one around.
18856
18857
18858@subheading The @code{-exec-continue} Command
18859@findex -exec-continue
18860
18861@subsubheading Synopsis
18862
18863@smallexample
18864 -exec-continue
18865@end smallexample
18866
18867Asynchronous command. Resumes the execution of the inferior program
18868until a breakpoint is encountered, or until the inferior exits.
18869
18870@subsubheading @value{GDBN} Command
18871
18872The corresponding @value{GDBN} corresponding is @samp{continue}.
18873
18874@subsubheading Example
18875
18876@smallexample
18877-exec-continue
18878^running
18879(@value{GDBP})
18880@@Hello world
18881*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
76ff342d 18882file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="13"@}
922fbb7b
AC
18883(@value{GDBP})
18884@end smallexample
18885
18886
18887@subheading The @code{-exec-finish} Command
18888@findex -exec-finish
18889
18890@subsubheading Synopsis
18891
18892@smallexample
18893 -exec-finish
18894@end smallexample
18895
18896Asynchronous command. Resumes the execution of the inferior program
18897until the current function is exited. Displays the results returned by
18898the function.
18899
18900@subsubheading @value{GDBN} Command
18901
18902The corresponding @value{GDBN} command is @samp{finish}.
18903
18904@subsubheading Example
18905
18906Function returning @code{void}.
18907
18908@smallexample
18909-exec-finish
18910^running
18911(@value{GDBP})
18912@@hello from foo
18913*stopped,reason="function-finished",frame=@{func="main",args=[],
76ff342d 18914file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="7"@}
922fbb7b
AC
18915(@value{GDBP})
18916@end smallexample
18917
18918Function returning other than @code{void}. The name of the internal
18919@value{GDBN} variable storing the result is printed, together with the
18920value itself.
18921
18922@smallexample
18923-exec-finish
18924^running
18925(@value{GDBP})
18926*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
18927args=[@{name="a",value="1"],@{name="b",value="9"@}@},
76ff342d 18928file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b
AC
18929gdb-result-var="$1",return-value="0"
18930(@value{GDBP})
18931@end smallexample
18932
18933
18934@subheading The @code{-exec-interrupt} Command
18935@findex -exec-interrupt
18936
18937@subsubheading Synopsis
18938
18939@smallexample
18940 -exec-interrupt
18941@end smallexample
18942
18943Asynchronous command. Interrupts the background execution of the target.
18944Note how the token associated with the stop message is the one for the
18945execution command that has been interrupted. The token for the interrupt
18946itself only appears in the @samp{^done} output. If the user is trying to
18947interrupt a non-running program, an error message will be printed.
18948
18949@subsubheading @value{GDBN} Command
18950
18951The corresponding @value{GDBN} command is @samp{interrupt}.
18952
18953@subsubheading Example
18954
18955@smallexample
18956(@value{GDBP})
18957111-exec-continue
18958111^running
18959
18960(@value{GDBP})
18961222-exec-interrupt
18962222^done
18963(@value{GDBP})
18964111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d
DJ
18965frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
18966fullname="/home/foo/bar/devo/myproject/try.c",line="13"@}
922fbb7b
AC
18967(@value{GDBP})
18968
18969(@value{GDBP})
18970-exec-interrupt
18971^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
18972(@value{GDBP})
18973@end smallexample
18974
18975
18976@subheading The @code{-exec-next} Command
18977@findex -exec-next
18978
18979@subsubheading Synopsis
18980
18981@smallexample
18982 -exec-next
18983@end smallexample
18984
18985Asynchronous command. Resumes execution of the inferior program, stopping
18986when the beginning of the next source line is reached.
18987
18988@subsubheading @value{GDBN} Command
18989
18990The corresponding @value{GDBN} command is @samp{next}.
18991
18992@subsubheading Example
18993
18994@smallexample
18995-exec-next
18996^running
18997(@value{GDBP})
18998*stopped,reason="end-stepping-range",line="8",file="hello.c"
18999(@value{GDBP})
19000@end smallexample
19001
19002
19003@subheading The @code{-exec-next-instruction} Command
19004@findex -exec-next-instruction
19005
19006@subsubheading Synopsis
19007
19008@smallexample
19009 -exec-next-instruction
19010@end smallexample
19011
19012Asynchronous command. Executes one machine instruction. If the
19013instruction is a function call continues until the function returns. If
19014the program stops at an instruction in the middle of a source line, the
19015address will be printed as well.
19016
19017@subsubheading @value{GDBN} Command
19018
19019The corresponding @value{GDBN} command is @samp{nexti}.
19020
19021@subsubheading Example
19022
19023@smallexample
19024(@value{GDBP})
19025-exec-next-instruction
19026^running
19027
19028(@value{GDBP})
19029*stopped,reason="end-stepping-range",
19030addr="0x000100d4",line="5",file="hello.c"
19031(@value{GDBP})
19032@end smallexample
19033
19034
19035@subheading The @code{-exec-return} Command
19036@findex -exec-return
19037
19038@subsubheading Synopsis
19039
19040@smallexample
19041 -exec-return
19042@end smallexample
19043
19044Makes current function return immediately. Doesn't execute the inferior.
19045Displays the new current frame.
19046
19047@subsubheading @value{GDBN} Command
19048
19049The corresponding @value{GDBN} command is @samp{return}.
19050
19051@subsubheading Example
19052
19053@smallexample
19054(@value{GDBP})
19055200-break-insert callee4
19056200^done,bkpt=@{number="1",addr="0x00010734",
19057file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
19058(@value{GDBP})
19059000-exec-run
19060000^running
19061(@value{GDBP})
19062000*stopped,reason="breakpoint-hit",bkptno="1",
19063frame=@{func="callee4",args=[],
76ff342d
DJ
19064file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19065fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
922fbb7b
AC
19066(@value{GDBP})
19067205-break-delete
19068205^done
19069(@value{GDBP})
19070111-exec-return
19071111^done,frame=@{level="0",func="callee3",
19072args=[@{name="strarg",
19073value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
19074file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19075fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
19076(@value{GDBP})
19077@end smallexample
19078
19079
19080@subheading The @code{-exec-run} Command
19081@findex -exec-run
19082
19083@subsubheading Synopsis
19084
19085@smallexample
19086 -exec-run
19087@end smallexample
19088
19089Asynchronous command. Starts execution of the inferior from the
19090beginning. The inferior executes until either a breakpoint is
19091encountered or the program exits.
19092
19093@subsubheading @value{GDBN} Command
19094
19095The corresponding @value{GDBN} command is @samp{run}.
19096
19097@subsubheading Example
19098
19099@smallexample
19100(@value{GDBP})
19101-break-insert main
19102^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
19103(@value{GDBP})
19104-exec-run
19105^running
19106(@value{GDBP})
19107*stopped,reason="breakpoint-hit",bkptno="1",
76ff342d
DJ
19108frame=@{func="main",args=[],file="recursive2.c",
19109fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}
922fbb7b
AC
19110(@value{GDBP})
19111@end smallexample
19112
19113
19114@subheading The @code{-exec-show-arguments} Command
19115@findex -exec-show-arguments
19116
19117@subsubheading Synopsis
19118
19119@smallexample
19120 -exec-show-arguments
19121@end smallexample
19122
19123Print the arguments of the program.
19124
19125@subsubheading @value{GDBN} Command
19126
19127The corresponding @value{GDBN} command is @samp{show args}.
19128
19129@subsubheading Example
19130N.A.
19131
19132@c @subheading -exec-signal
19133
19134@subheading The @code{-exec-step} Command
19135@findex -exec-step
19136
19137@subsubheading Synopsis
19138
19139@smallexample
19140 -exec-step
19141@end smallexample
19142
19143Asynchronous command. Resumes execution of the inferior program, stopping
19144when the beginning of the next source line is reached, if the next
19145source line is not a function call. If it is, stop at the first
19146instruction of the called function.
19147
19148@subsubheading @value{GDBN} Command
19149
19150The corresponding @value{GDBN} command is @samp{step}.
19151
19152@subsubheading Example
19153
19154Stepping into a function:
19155
19156@smallexample
19157-exec-step
19158^running
19159(@value{GDBP})
19160*stopped,reason="end-stepping-range",
19161frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d
DJ
19162@{name="b",value="0"@}],file="recursive2.c",
19163fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@}
922fbb7b
AC
19164(@value{GDBP})
19165@end smallexample
19166
19167Regular stepping:
19168
19169@smallexample
19170-exec-step
19171^running
19172(@value{GDBP})
19173*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
19174(@value{GDBP})
19175@end smallexample
19176
19177
19178@subheading The @code{-exec-step-instruction} Command
19179@findex -exec-step-instruction
19180
19181@subsubheading Synopsis
19182
19183@smallexample
19184 -exec-step-instruction
19185@end smallexample
19186
19187Asynchronous command. Resumes the inferior which executes one machine
19188instruction. The output, once @value{GDBN} has stopped, will vary depending on
19189whether we have stopped in the middle of a source line or not. In the
19190former case, the address at which the program stopped will be printed as
19191well.
19192
19193@subsubheading @value{GDBN} Command
19194
19195The corresponding @value{GDBN} command is @samp{stepi}.
19196
19197@subsubheading Example
19198
19199@smallexample
19200(@value{GDBP})
19201-exec-step-instruction
19202^running
19203
19204(@value{GDBP})
19205*stopped,reason="end-stepping-range",
76ff342d
DJ
19206frame=@{func="foo",args=[],file="try.c",
19207fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
19208(@value{GDBP})
19209-exec-step-instruction
19210^running
19211
19212(@value{GDBP})
19213*stopped,reason="end-stepping-range",
76ff342d
DJ
19214frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
19215fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
19216(@value{GDBP})
19217@end smallexample
19218
19219
19220@subheading The @code{-exec-until} Command
19221@findex -exec-until
19222
19223@subsubheading Synopsis
19224
19225@smallexample
19226 -exec-until [ @var{location} ]
19227@end smallexample
19228
19229Asynchronous command. Executes the inferior until the @var{location}
19230specified in the argument is reached. If there is no argument, the inferior
19231executes until a source line greater than the current one is reached.
19232The reason for stopping in this case will be @samp{location-reached}.
19233
19234@subsubheading @value{GDBN} Command
19235
19236The corresponding @value{GDBN} command is @samp{until}.
19237
19238@subsubheading Example
19239
19240@smallexample
19241(@value{GDBP})
19242-exec-until recursive2.c:6
19243^running
19244(@value{GDBP})
19245x = 55
19246*stopped,reason="location-reached",frame=@{func="main",args=[],
76ff342d 19247file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="6"@}
922fbb7b
AC
19248(@value{GDBP})
19249@end smallexample
19250
19251@ignore
19252@subheading -file-clear
19253Is this going away????
19254@end ignore
19255
19256
19257@subheading The @code{-file-exec-and-symbols} Command
19258@findex -file-exec-and-symbols
19259
19260@subsubheading Synopsis
19261
19262@smallexample
19263 -file-exec-and-symbols @var{file}
19264@end smallexample
19265
19266Specify the executable file to be debugged. This file is the one from
19267which the symbol table is also read. If no file is specified, the
19268command clears the executable and symbol information. If breakpoints
19269are set when using this command with no arguments, @value{GDBN} will produce
19270error messages. Otherwise, no output is produced, except a completion
19271notification.
19272
19273@subsubheading @value{GDBN} Command
19274
19275The corresponding @value{GDBN} command is @samp{file}.
19276
19277@subsubheading Example
19278
19279@smallexample
19280(@value{GDBP})
19281-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
19282^done
19283(@value{GDBP})
19284@end smallexample
19285
19286
19287@subheading The @code{-file-exec-file} Command
19288@findex -file-exec-file
19289
19290@subsubheading Synopsis
19291
19292@smallexample
19293 -file-exec-file @var{file}
19294@end smallexample
19295
19296Specify the executable file to be debugged. Unlike
19297@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
19298from this file. If used without argument, @value{GDBN} clears the information
19299about the executable file. No output is produced, except a completion
19300notification.
19301
19302@subsubheading @value{GDBN} Command
19303
19304The corresponding @value{GDBN} command is @samp{exec-file}.
19305
19306@subsubheading Example
19307
19308@smallexample
19309(@value{GDBP})
19310-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
19311^done
19312(@value{GDBP})
19313@end smallexample
19314
19315
19316@subheading The @code{-file-list-exec-sections} Command
19317@findex -file-list-exec-sections
19318
19319@subsubheading Synopsis
19320
19321@smallexample
19322 -file-list-exec-sections
19323@end smallexample
19324
19325List the sections of the current executable file.
19326
19327@subsubheading @value{GDBN} Command
19328
19329The @value{GDBN} command @samp{info file} shows, among the rest, the same
19330information as this command. @code{gdbtk} has a corresponding command
19331@samp{gdb_load_info}.
19332
19333@subsubheading Example
19334N.A.
19335
19336
1abaf70c
BR
19337@subheading The @code{-file-list-exec-source-file} Command
19338@findex -file-list-exec-source-file
19339
19340@subsubheading Synopsis
19341
19342@smallexample
19343 -file-list-exec-source-file
19344@end smallexample
19345
b383017d 19346List the line number, the current source file, and the absolute path
1abaf70c
BR
19347to the current source file for the current executable.
19348
19349@subsubheading @value{GDBN} Command
19350
19351There's no @value{GDBN} command which directly corresponds to this one.
19352
19353@subsubheading Example
19354
19355@smallexample
19356(@value{GDBP})
19357123-file-list-exec-source-file
19358123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
19359(@value{GDBP})
19360@end smallexample
19361
19362
922fbb7b
AC
19363@subheading The @code{-file-list-exec-source-files} Command
19364@findex -file-list-exec-source-files
19365
19366@subsubheading Synopsis
19367
19368@smallexample
19369 -file-list-exec-source-files
19370@end smallexample
19371
19372List the source files for the current executable.
19373
57c22c6c
BR
19374It will always output the filename, but only when GDB can find the absolute
19375file name of a source file, will it output the fullname.
19376
922fbb7b
AC
19377@subsubheading @value{GDBN} Command
19378
19379There's no @value{GDBN} command which directly corresponds to this one.
19380@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
19381
19382@subsubheading Example
57c22c6c
BR
19383@smallexample
19384(@value{GDBP})
19385-file-list-exec-source-files
19386^done,files=[
19387@{file=foo.c,fullname=/home/foo.c@},
19388@{file=/home/bar.c,fullname=/home/bar.c@},
19389@{file=gdb_could_not_find_fullpath.c@}]
19390(@value{GDBP})
19391@end smallexample
922fbb7b
AC
19392
19393@subheading The @code{-file-list-shared-libraries} Command
19394@findex -file-list-shared-libraries
19395
19396@subsubheading Synopsis
19397
19398@smallexample
19399 -file-list-shared-libraries
19400@end smallexample
19401
19402List the shared libraries in the program.
19403
19404@subsubheading @value{GDBN} Command
19405
19406The corresponding @value{GDBN} command is @samp{info shared}.
19407
19408@subsubheading Example
19409N.A.
19410
19411
19412@subheading The @code{-file-list-symbol-files} Command
19413@findex -file-list-symbol-files
19414
19415@subsubheading Synopsis
19416
19417@smallexample
19418 -file-list-symbol-files
19419@end smallexample
19420
19421List symbol files.
19422
19423@subsubheading @value{GDBN} Command
19424
19425The corresponding @value{GDBN} command is @samp{info file} (part of it).
19426
19427@subsubheading Example
19428N.A.
19429
19430
19431@subheading The @code{-file-symbol-file} Command
19432@findex -file-symbol-file
19433
19434@subsubheading Synopsis
19435
19436@smallexample
19437 -file-symbol-file @var{file}
19438@end smallexample
19439
19440Read symbol table info from the specified @var{file} argument. When
19441used without arguments, clears @value{GDBN}'s symbol table info. No output is
19442produced, except for a completion notification.
19443
19444@subsubheading @value{GDBN} Command
19445
19446The corresponding @value{GDBN} command is @samp{symbol-file}.
19447
19448@subsubheading Example
19449
19450@smallexample
19451(@value{GDBP})
19452-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
19453^done
19454(@value{GDBP})
19455@end smallexample
19456
19457@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19458@node GDB/MI Miscellaneous Commands
19459@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
19460
19461@c @subheading -gdb-complete
19462
19463@subheading The @code{-gdb-exit} Command
19464@findex -gdb-exit
19465
19466@subsubheading Synopsis
19467
19468@smallexample
19469 -gdb-exit
19470@end smallexample
19471
19472Exit @value{GDBN} immediately.
19473
19474@subsubheading @value{GDBN} Command
19475
19476Approximately corresponds to @samp{quit}.
19477
19478@subsubheading Example
19479
19480@smallexample
19481(@value{GDBP})
19482-gdb-exit
19483@end smallexample
19484
19485@subheading The @code{-gdb-set} Command
19486@findex -gdb-set
19487
19488@subsubheading Synopsis
19489
19490@smallexample
19491 -gdb-set
19492@end smallexample
19493
19494Set an internal @value{GDBN} variable.
19495@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
19496
19497@subsubheading @value{GDBN} Command
19498
19499The corresponding @value{GDBN} command is @samp{set}.
19500
19501@subsubheading Example
19502
19503@smallexample
19504(@value{GDBP})
19505-gdb-set $foo=3
19506^done
19507(@value{GDBP})
19508@end smallexample
19509
19510
19511@subheading The @code{-gdb-show} Command
19512@findex -gdb-show
19513
19514@subsubheading Synopsis
19515
19516@smallexample
19517 -gdb-show
19518@end smallexample
19519
19520Show the current value of a @value{GDBN} variable.
19521
19522@subsubheading @value{GDBN} command
19523
19524The corresponding @value{GDBN} command is @samp{show}.
19525
19526@subsubheading Example
19527
19528@smallexample
19529(@value{GDBP})
19530-gdb-show annotate
19531^done,value="0"
19532(@value{GDBP})
19533@end smallexample
19534
19535@c @subheading -gdb-source
19536
19537
19538@subheading The @code{-gdb-version} Command
19539@findex -gdb-version
19540
19541@subsubheading Synopsis
19542
19543@smallexample
19544 -gdb-version
19545@end smallexample
19546
19547Show version information for @value{GDBN}. Used mostly in testing.
19548
19549@subsubheading @value{GDBN} Command
19550
19551There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
19552information when you start an interactive session.
19553
19554@subsubheading Example
19555
19556@c This example modifies the actual output from GDB to avoid overfull
19557@c box in TeX.
19558@smallexample
19559(@value{GDBP})
19560-gdb-version
19561~GNU gdb 5.2.1
19562~Copyright 2000 Free Software Foundation, Inc.
19563~GDB is free software, covered by the GNU General Public License, and
19564~you are welcome to change it and/or distribute copies of it under
19565~ certain conditions.
19566~Type "show copying" to see the conditions.
19567~There is absolutely no warranty for GDB. Type "show warranty" for
19568~ details.
b383017d 19569~This GDB was configured as
922fbb7b
AC
19570 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
19571^done
19572(@value{GDBP})
19573@end smallexample
19574
19575@subheading The @code{-interpreter-exec} Command
19576@findex -interpreter-exec
19577
19578@subheading Synopsis
19579
19580@smallexample
19581-interpreter-exec @var{interpreter} @var{command}
19582@end smallexample
19583
19584Execute the specified @var{command} in the given @var{interpreter}.
19585
19586@subheading @value{GDBN} Command
19587
19588The corresponding @value{GDBN} command is @samp{interpreter-exec}.
19589
19590@subheading Example
19591
19592@smallexample
19593(@value{GDBP})
19594-interpreter-exec console "break main"
19595&"During symbol reading, couldn't parse type; debugger out of date?.\n"
19596&"During symbol reading, bad structure-type format.\n"
19597~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
19598^done
19599(@value{GDBP})
19600@end smallexample
19601
3cb3b8df
BR
19602@subheading The @code{-inferior-tty-set} Command
19603@findex -inferior-tty-set
19604
19605@subheading Synopsis
19606
19607@smallexample
19608-inferior-tty-set /dev/pts/1
19609@end smallexample
19610
19611Set terminal for future runs of the program being debugged.
19612
19613@subheading @value{GDBN} Command
19614
19615The corresponding @value{GDBN} command is @samp{set inferior-tty /dev/pts/1}.
19616
19617@subheading Example
19618
19619@smallexample
19620(@value{GDBP})
19621-inferior-tty-set /dev/pts/1
19622^done
19623(@value{GDBP})
19624@end smallexample
19625
19626@subheading The @code{-inferior-tty-show} Command
19627@findex -inferior-tty-show
19628
19629@subheading Synopsis
19630
19631@smallexample
19632-inferior-tty-show
19633@end smallexample
19634
19635Show terminal for future runs of program being debugged.
19636
19637@subheading @value{GDBN} Command
19638
38f1196a 19639The corresponding @value{GDBN} command is @samp{show inferior-tty}.
3cb3b8df
BR
19640
19641@subheading Example
19642
19643@smallexample
19644(@value{GDBP})
19645-inferior-tty-set /dev/pts/1
19646^done
19647(@value{GDBP})
19648-inferior-tty-show
19649^done,inferior_tty_terminal="/dev/pts/1"
19650(@value{GDBP})
19651@end smallexample
19652
922fbb7b
AC
19653@ignore
19654@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19655@node GDB/MI Kod Commands
19656@section @sc{gdb/mi} Kod Commands
19657
19658The Kod commands are not implemented.
19659
19660@c @subheading -kod-info
19661
19662@c @subheading -kod-list
19663
19664@c @subheading -kod-list-object-types
19665
19666@c @subheading -kod-show
19667
19668@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19669@node GDB/MI Memory Overlay Commands
19670@section @sc{gdb/mi} Memory Overlay Commands
19671
19672The memory overlay commands are not implemented.
19673
19674@c @subheading -overlay-auto
19675
19676@c @subheading -overlay-list-mapping-state
19677
19678@c @subheading -overlay-list-overlays
19679
19680@c @subheading -overlay-map
19681
19682@c @subheading -overlay-off
19683
19684@c @subheading -overlay-on
19685
19686@c @subheading -overlay-unmap
19687
19688@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19689@node GDB/MI Signal Handling Commands
19690@section @sc{gdb/mi} Signal Handling Commands
19691
19692Signal handling commands are not implemented.
19693
19694@c @subheading -signal-handle
19695
19696@c @subheading -signal-list-handle-actions
19697
19698@c @subheading -signal-list-signal-types
19699@end ignore
19700
19701
19702@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19703@node GDB/MI Stack Manipulation
19704@section @sc{gdb/mi} Stack Manipulation Commands
19705
dcaaae04
NR
19706
19707@subheading The @code{-stack-info-frame} Command
19708@findex -stack-info-frame
19709
19710@subsubheading Synopsis
19711
19712@smallexample
19713 -stack-info-frame
19714@end smallexample
19715
19716Get info on the selected frame.
19717
19718@subsubheading @value{GDBN} Command
19719
19720The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
19721(without arguments).
19722
19723@subsubheading Example
19724
19725@smallexample
19726(@value{GDBP})
19727-stack-info-frame
19728^done,frame=@{level="1",addr="0x0001076c",func="callee3",
19729file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19730fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
19731(@value{GDBP})
19732@end smallexample
19733
922fbb7b
AC
19734@subheading The @code{-stack-info-depth} Command
19735@findex -stack-info-depth
19736
19737@subsubheading Synopsis
19738
19739@smallexample
19740 -stack-info-depth [ @var{max-depth} ]
19741@end smallexample
19742
19743Return the depth of the stack. If the integer argument @var{max-depth}
19744is specified, do not count beyond @var{max-depth} frames.
19745
19746@subsubheading @value{GDBN} Command
19747
19748There's no equivalent @value{GDBN} command.
19749
19750@subsubheading Example
19751
19752For a stack with frame levels 0 through 11:
19753
19754@smallexample
19755(@value{GDBP})
19756-stack-info-depth
19757^done,depth="12"
19758(@value{GDBP})
19759-stack-info-depth 4
19760^done,depth="4"
19761(@value{GDBP})
19762-stack-info-depth 12
19763^done,depth="12"
19764(@value{GDBP})
19765-stack-info-depth 11
19766^done,depth="11"
19767(@value{GDBP})
19768-stack-info-depth 13
19769^done,depth="12"
19770(@value{GDBP})
19771@end smallexample
19772
19773@subheading The @code{-stack-list-arguments} Command
19774@findex -stack-list-arguments
19775
19776@subsubheading Synopsis
19777
19778@smallexample
19779 -stack-list-arguments @var{show-values}
19780 [ @var{low-frame} @var{high-frame} ]
19781@end smallexample
19782
19783Display a list of the arguments for the frames between @var{low-frame}
19784and @var{high-frame} (inclusive). If @var{low-frame} and
19785@var{high-frame} are not provided, list the arguments for the whole call
19786stack.
19787
19788The @var{show-values} argument must have a value of 0 or 1. A value of
197890 means that only the names of the arguments are listed, a value of 1
19790means that both names and values of the arguments are printed.
19791
19792@subsubheading @value{GDBN} Command
19793
19794@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
19795@samp{gdb_get_args} command which partially overlaps with the
19796functionality of @samp{-stack-list-arguments}.
19797
19798@subsubheading Example
19799
19800@smallexample
19801(@value{GDBP})
19802-stack-list-frames
19803^done,
19804stack=[
19805frame=@{level="0",addr="0x00010734",func="callee4",
76ff342d
DJ
19806file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19807fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
922fbb7b 19808frame=@{level="1",addr="0x0001076c",func="callee3",
76ff342d
DJ
19809file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19810fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
922fbb7b 19811frame=@{level="2",addr="0x0001078c",func="callee2",
76ff342d
DJ
19812file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19813fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
922fbb7b 19814frame=@{level="3",addr="0x000107b4",func="callee1",
76ff342d
DJ
19815file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19816fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
922fbb7b 19817frame=@{level="4",addr="0x000107e0",func="main",
76ff342d
DJ
19818file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19819fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
922fbb7b
AC
19820(@value{GDBP})
19821-stack-list-arguments 0
19822^done,
19823stack-args=[
19824frame=@{level="0",args=[]@},
19825frame=@{level="1",args=[name="strarg"]@},
19826frame=@{level="2",args=[name="intarg",name="strarg"]@},
19827frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
19828frame=@{level="4",args=[]@}]
19829(@value{GDBP})
19830-stack-list-arguments 1
19831^done,
19832stack-args=[
19833frame=@{level="0",args=[]@},
19834frame=@{level="1",
19835 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19836frame=@{level="2",args=[
19837@{name="intarg",value="2"@},
19838@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19839@{frame=@{level="3",args=[
19840@{name="intarg",value="2"@},
19841@{name="strarg",value="0x11940 \"A string argument.\""@},
19842@{name="fltarg",value="3.5"@}]@},
19843frame=@{level="4",args=[]@}]
19844(@value{GDBP})
19845-stack-list-arguments 0 2 2
19846^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
19847(@value{GDBP})
19848-stack-list-arguments 1 2 2
19849^done,stack-args=[frame=@{level="2",
19850args=[@{name="intarg",value="2"@},
19851@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
19852(@value{GDBP})
19853@end smallexample
19854
19855@c @subheading -stack-list-exception-handlers
19856
19857
19858@subheading The @code{-stack-list-frames} Command
19859@findex -stack-list-frames
19860
19861@subsubheading Synopsis
19862
19863@smallexample
19864 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
19865@end smallexample
19866
19867List the frames currently on the stack. For each frame it displays the
19868following info:
19869
19870@table @samp
19871@item @var{level}
19872The frame number, 0 being the topmost frame, i.e. the innermost function.
19873@item @var{addr}
19874The @code{$pc} value for that frame.
19875@item @var{func}
19876Function name.
19877@item @var{file}
19878File name of the source file where the function lives.
19879@item @var{line}
19880Line number corresponding to the @code{$pc}.
19881@end table
19882
19883If invoked without arguments, this command prints a backtrace for the
19884whole stack. If given two integer arguments, it shows the frames whose
19885levels are between the two arguments (inclusive). If the two arguments
19886are equal, it shows the single frame at the corresponding level.
19887
19888@subsubheading @value{GDBN} Command
19889
19890The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
19891
19892@subsubheading Example
19893
19894Full stack backtrace:
19895
19896@smallexample
19897(@value{GDBP})
19898-stack-list-frames
19899^done,stack=
19900[frame=@{level="0",addr="0x0001076c",func="foo",
76ff342d 19901 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@},
922fbb7b 19902frame=@{level="1",addr="0x000107a4",func="foo",
76ff342d 19903 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19904frame=@{level="2",addr="0x000107a4",func="foo",
76ff342d 19905 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19906frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19907 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19908frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19909 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19910frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19911 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19912frame=@{level="6",addr="0x000107a4",func="foo",
76ff342d 19913 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19914frame=@{level="7",addr="0x000107a4",func="foo",
76ff342d 19915 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19916frame=@{level="8",addr="0x000107a4",func="foo",
76ff342d 19917 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19918frame=@{level="9",addr="0x000107a4",func="foo",
76ff342d 19919 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19920frame=@{level="10",addr="0x000107a4",func="foo",
76ff342d 19921 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19922frame=@{level="11",addr="0x00010738",func="main",
76ff342d 19923 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}]
922fbb7b
AC
19924(@value{GDBP})
19925@end smallexample
19926
19927Show frames between @var{low_frame} and @var{high_frame}:
19928
19929@smallexample
19930(@value{GDBP})
19931-stack-list-frames 3 5
19932^done,stack=
19933[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19934 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19935frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19936 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19937frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19938 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19939(@value{GDBP})
19940@end smallexample
19941
19942Show a single frame:
19943
19944@smallexample
19945(@value{GDBP})
19946-stack-list-frames 3 3
19947^done,stack=
19948[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19949 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19950(@value{GDBP})
19951@end smallexample
19952
19953
19954@subheading The @code{-stack-list-locals} Command
19955@findex -stack-list-locals
19956
19957@subsubheading Synopsis
19958
19959@smallexample
19960 -stack-list-locals @var{print-values}
19961@end smallexample
19962
265eeb58
NR
19963Display the local variable names for the selected frame. If
19964@var{print-values} is 0 or @code{--no-values}, print only the names of
19965the variables; if it is 1 or @code{--all-values}, print also their
19966values; and if it is 2 or @code{--simple-values}, print the name,
19967type and value for simple data types and the name and type for arrays,
19968structures and unions. In this last case, a frontend can immediately
19969display the value of simple data types and create variable objects for
19970other data types when the the user wishes to explore their values in
bc8ced35 19971more detail.
922fbb7b
AC
19972
19973@subsubheading @value{GDBN} Command
19974
19975@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
19976
19977@subsubheading Example
19978
19979@smallexample
19980(@value{GDBP})
19981-stack-list-locals 0
19982^done,locals=[name="A",name="B",name="C"]
19983(@value{GDBP})
bc8ced35 19984-stack-list-locals --all-values
922fbb7b 19985^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
bc8ced35
NR
19986 @{name="C",value="@{1, 2, 3@}"@}]
19987-stack-list-locals --simple-values
19988^done,locals=[@{name="A",type="int",value="1"@},
19989 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
922fbb7b
AC
19990(@value{GDBP})
19991@end smallexample
19992
19993
19994@subheading The @code{-stack-select-frame} Command
19995@findex -stack-select-frame
19996
19997@subsubheading Synopsis
19998
19999@smallexample
20000 -stack-select-frame @var{framenum}
20001@end smallexample
20002
265eeb58 20003Change the selected frame. Select a different frame @var{framenum} on
922fbb7b
AC
20004the stack.
20005
20006@subsubheading @value{GDBN} Command
20007
20008The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
20009@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
20010
20011@subsubheading Example
20012
20013@smallexample
20014(@value{GDBP})
20015-stack-select-frame 2
20016^done
20017(@value{GDBP})
20018@end smallexample
20019
20020@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20021@node GDB/MI Symbol Query
20022@section @sc{gdb/mi} Symbol Query Commands
20023
20024
20025@subheading The @code{-symbol-info-address} Command
20026@findex -symbol-info-address
20027
20028@subsubheading Synopsis
20029
20030@smallexample
20031 -symbol-info-address @var{symbol}
20032@end smallexample
20033
20034Describe where @var{symbol} is stored.
20035
20036@subsubheading @value{GDBN} Command
20037
20038The corresponding @value{GDBN} command is @samp{info address}.
20039
20040@subsubheading Example
20041N.A.
20042
20043
20044@subheading The @code{-symbol-info-file} Command
20045@findex -symbol-info-file
20046
20047@subsubheading Synopsis
20048
20049@smallexample
20050 -symbol-info-file
20051@end smallexample
20052
20053Show the file for the symbol.
20054
20055@subsubheading @value{GDBN} Command
20056
20057There's no equivalent @value{GDBN} command. @code{gdbtk} has
20058@samp{gdb_find_file}.
20059
20060@subsubheading Example
20061N.A.
20062
20063
20064@subheading The @code{-symbol-info-function} Command
20065@findex -symbol-info-function
20066
20067@subsubheading Synopsis
20068
20069@smallexample
20070 -symbol-info-function
20071@end smallexample
20072
20073Show which function the symbol lives in.
20074
20075@subsubheading @value{GDBN} Command
20076
20077@samp{gdb_get_function} in @code{gdbtk}.
20078
20079@subsubheading Example
20080N.A.
20081
20082
20083@subheading The @code{-symbol-info-line} Command
20084@findex -symbol-info-line
20085
20086@subsubheading Synopsis
20087
20088@smallexample
20089 -symbol-info-line
20090@end smallexample
20091
20092Show the core addresses of the code for a source line.
20093
20094@subsubheading @value{GDBN} Command
20095
71952f4c 20096The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
20097@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
20098
20099@subsubheading Example
20100N.A.
20101
20102
20103@subheading The @code{-symbol-info-symbol} Command
20104@findex -symbol-info-symbol
20105
20106@subsubheading Synopsis
20107
20108@smallexample
20109 -symbol-info-symbol @var{addr}
20110@end smallexample
20111
20112Describe what symbol is at location @var{addr}.
20113
20114@subsubheading @value{GDBN} Command
20115
20116The corresponding @value{GDBN} command is @samp{info symbol}.
20117
20118@subsubheading Example
20119N.A.
20120
20121
20122@subheading The @code{-symbol-list-functions} Command
20123@findex -symbol-list-functions
20124
20125@subsubheading Synopsis
20126
20127@smallexample
20128 -symbol-list-functions
20129@end smallexample
20130
20131List the functions in the executable.
20132
20133@subsubheading @value{GDBN} Command
20134
20135@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
20136@samp{gdb_search} in @code{gdbtk}.
20137
20138@subsubheading Example
20139N.A.
20140
20141
32e7087d
JB
20142@subheading The @code{-symbol-list-lines} Command
20143@findex -symbol-list-lines
20144
20145@subsubheading Synopsis
20146
20147@smallexample
20148 -symbol-list-lines @var{filename}
20149@end smallexample
20150
20151Print the list of lines that contain code and their associated program
20152addresses for the given source filename. The entries are sorted in
20153ascending PC order.
20154
20155@subsubheading @value{GDBN} Command
20156
20157There is no corresponding @value{GDBN} command.
20158
20159@subsubheading Example
20160@smallexample
20161(@value{GDBP})
20162-symbol-list-lines basics.c
54ff5908 20163^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
20164(@value{GDBP})
20165@end smallexample
20166
20167
922fbb7b
AC
20168@subheading The @code{-symbol-list-types} Command
20169@findex -symbol-list-types
20170
20171@subsubheading Synopsis
20172
20173@smallexample
20174 -symbol-list-types
20175@end smallexample
20176
20177List all the type names.
20178
20179@subsubheading @value{GDBN} Command
20180
20181The corresponding commands are @samp{info types} in @value{GDBN},
20182@samp{gdb_search} in @code{gdbtk}.
20183
20184@subsubheading Example
20185N.A.
20186
20187
20188@subheading The @code{-symbol-list-variables} Command
20189@findex -symbol-list-variables
20190
20191@subsubheading Synopsis
20192
20193@smallexample
20194 -symbol-list-variables
20195@end smallexample
20196
20197List all the global and static variable names.
20198
20199@subsubheading @value{GDBN} Command
20200
20201@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
20202
20203@subsubheading Example
20204N.A.
20205
20206
20207@subheading The @code{-symbol-locate} Command
20208@findex -symbol-locate
20209
20210@subsubheading Synopsis
20211
20212@smallexample
20213 -symbol-locate
20214@end smallexample
20215
20216@subsubheading @value{GDBN} Command
20217
20218@samp{gdb_loc} in @code{gdbtk}.
20219
20220@subsubheading Example
20221N.A.
20222
20223
20224@subheading The @code{-symbol-type} Command
20225@findex -symbol-type
20226
20227@subsubheading Synopsis
20228
20229@smallexample
20230 -symbol-type @var{variable}
20231@end smallexample
20232
20233Show type of @var{variable}.
20234
20235@subsubheading @value{GDBN} Command
20236
20237The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
20238@samp{gdb_obj_variable}.
20239
20240@subsubheading Example
20241N.A.
20242
20243
20244@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20245@node GDB/MI Target Manipulation
20246@section @sc{gdb/mi} Target Manipulation Commands
20247
20248
20249@subheading The @code{-target-attach} Command
20250@findex -target-attach
20251
20252@subsubheading Synopsis
20253
20254@smallexample
20255 -target-attach @var{pid} | @var{file}
20256@end smallexample
20257
20258Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
20259
20260@subsubheading @value{GDBN} command
20261
20262The corresponding @value{GDBN} command is @samp{attach}.
20263
20264@subsubheading Example
20265N.A.
20266
20267
20268@subheading The @code{-target-compare-sections} Command
20269@findex -target-compare-sections
20270
20271@subsubheading Synopsis
20272
20273@smallexample
20274 -target-compare-sections [ @var{section} ]
20275@end smallexample
20276
20277Compare data of section @var{section} on target to the exec file.
20278Without the argument, all sections are compared.
20279
20280@subsubheading @value{GDBN} Command
20281
20282The @value{GDBN} equivalent is @samp{compare-sections}.
20283
20284@subsubheading Example
20285N.A.
20286
20287
20288@subheading The @code{-target-detach} Command
20289@findex -target-detach
20290
20291@subsubheading Synopsis
20292
20293@smallexample
20294 -target-detach
20295@end smallexample
20296
20297Disconnect from the remote target. There's no output.
20298
20299@subsubheading @value{GDBN} command
20300
20301The corresponding @value{GDBN} command is @samp{detach}.
20302
20303@subsubheading Example
20304
20305@smallexample
20306(@value{GDBP})
20307-target-detach
20308^done
20309(@value{GDBP})
20310@end smallexample
20311
20312
07f31aa6
DJ
20313@subheading The @code{-target-disconnect} Command
20314@findex -target-disconnect
20315
20316@subsubheading Synopsis
20317
20318@example
20319 -target-disconnect
20320@end example
20321
20322Disconnect from the remote target. There's no output.
20323
20324@subsubheading @value{GDBN} command
20325
20326The corresponding @value{GDBN} command is @samp{disconnect}.
20327
20328@subsubheading Example
20329
20330@smallexample
20331(@value{GDBP})
20332-target-disconnect
20333^done
20334(@value{GDBP})
20335@end smallexample
20336
20337
922fbb7b
AC
20338@subheading The @code{-target-download} Command
20339@findex -target-download
20340
20341@subsubheading Synopsis
20342
20343@smallexample
20344 -target-download
20345@end smallexample
20346
20347Loads the executable onto the remote target.
20348It prints out an update message every half second, which includes the fields:
20349
20350@table @samp
20351@item section
20352The name of the section.
20353@item section-sent
20354The size of what has been sent so far for that section.
20355@item section-size
20356The size of the section.
20357@item total-sent
20358The total size of what was sent so far (the current and the previous sections).
20359@item total-size
20360The size of the overall executable to download.
20361@end table
20362
20363@noindent
20364Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
20365@sc{gdb/mi} Output Syntax}).
20366
20367In addition, it prints the name and size of the sections, as they are
20368downloaded. These messages include the following fields:
20369
20370@table @samp
20371@item section
20372The name of the section.
20373@item section-size
20374The size of the section.
20375@item total-size
20376The size of the overall executable to download.
20377@end table
20378
20379@noindent
20380At the end, a summary is printed.
20381
20382@subsubheading @value{GDBN} Command
20383
20384The corresponding @value{GDBN} command is @samp{load}.
20385
20386@subsubheading Example
20387
20388Note: each status message appears on a single line. Here the messages
20389have been broken down so that they can fit onto a page.
20390
20391@smallexample
20392(@value{GDBP})
20393-target-download
20394+download,@{section=".text",section-size="6668",total-size="9880"@}
20395+download,@{section=".text",section-sent="512",section-size="6668",
20396total-sent="512",total-size="9880"@}
20397+download,@{section=".text",section-sent="1024",section-size="6668",
20398total-sent="1024",total-size="9880"@}
20399+download,@{section=".text",section-sent="1536",section-size="6668",
20400total-sent="1536",total-size="9880"@}
20401+download,@{section=".text",section-sent="2048",section-size="6668",
20402total-sent="2048",total-size="9880"@}
20403+download,@{section=".text",section-sent="2560",section-size="6668",
20404total-sent="2560",total-size="9880"@}
20405+download,@{section=".text",section-sent="3072",section-size="6668",
20406total-sent="3072",total-size="9880"@}
20407+download,@{section=".text",section-sent="3584",section-size="6668",
20408total-sent="3584",total-size="9880"@}
20409+download,@{section=".text",section-sent="4096",section-size="6668",
20410total-sent="4096",total-size="9880"@}
20411+download,@{section=".text",section-sent="4608",section-size="6668",
20412total-sent="4608",total-size="9880"@}
20413+download,@{section=".text",section-sent="5120",section-size="6668",
20414total-sent="5120",total-size="9880"@}
20415+download,@{section=".text",section-sent="5632",section-size="6668",
20416total-sent="5632",total-size="9880"@}
20417+download,@{section=".text",section-sent="6144",section-size="6668",
20418total-sent="6144",total-size="9880"@}
20419+download,@{section=".text",section-sent="6656",section-size="6668",
20420total-sent="6656",total-size="9880"@}
20421+download,@{section=".init",section-size="28",total-size="9880"@}
20422+download,@{section=".fini",section-size="28",total-size="9880"@}
20423+download,@{section=".data",section-size="3156",total-size="9880"@}
20424+download,@{section=".data",section-sent="512",section-size="3156",
20425total-sent="7236",total-size="9880"@}
20426+download,@{section=".data",section-sent="1024",section-size="3156",
20427total-sent="7748",total-size="9880"@}
20428+download,@{section=".data",section-sent="1536",section-size="3156",
20429total-sent="8260",total-size="9880"@}
20430+download,@{section=".data",section-sent="2048",section-size="3156",
20431total-sent="8772",total-size="9880"@}
20432+download,@{section=".data",section-sent="2560",section-size="3156",
20433total-sent="9284",total-size="9880"@}
20434+download,@{section=".data",section-sent="3072",section-size="3156",
20435total-sent="9796",total-size="9880"@}
20436^done,address="0x10004",load-size="9880",transfer-rate="6586",
20437write-rate="429"
20438(@value{GDBP})
20439@end smallexample
20440
20441
20442@subheading The @code{-target-exec-status} Command
20443@findex -target-exec-status
20444
20445@subsubheading Synopsis
20446
20447@smallexample
20448 -target-exec-status
20449@end smallexample
20450
20451Provide information on the state of the target (whether it is running or
20452not, for instance).
20453
20454@subsubheading @value{GDBN} Command
20455
20456There's no equivalent @value{GDBN} command.
20457
20458@subsubheading Example
20459N.A.
20460
20461
20462@subheading The @code{-target-list-available-targets} Command
20463@findex -target-list-available-targets
20464
20465@subsubheading Synopsis
20466
20467@smallexample
20468 -target-list-available-targets
20469@end smallexample
20470
20471List the possible targets to connect to.
20472
20473@subsubheading @value{GDBN} Command
20474
20475The corresponding @value{GDBN} command is @samp{help target}.
20476
20477@subsubheading Example
20478N.A.
20479
20480
20481@subheading The @code{-target-list-current-targets} Command
20482@findex -target-list-current-targets
20483
20484@subsubheading Synopsis
20485
20486@smallexample
20487 -target-list-current-targets
20488@end smallexample
20489
20490Describe the current target.
20491
20492@subsubheading @value{GDBN} Command
20493
20494The corresponding information is printed by @samp{info file} (among
20495other things).
20496
20497@subsubheading Example
20498N.A.
20499
20500
20501@subheading The @code{-target-list-parameters} Command
20502@findex -target-list-parameters
20503
20504@subsubheading Synopsis
20505
20506@smallexample
20507 -target-list-parameters
20508@end smallexample
20509
20510@c ????
20511
20512@subsubheading @value{GDBN} Command
20513
20514No equivalent.
20515
20516@subsubheading Example
20517N.A.
20518
20519
20520@subheading The @code{-target-select} Command
20521@findex -target-select
20522
20523@subsubheading Synopsis
20524
20525@smallexample
20526 -target-select @var{type} @var{parameters @dots{}}
20527@end smallexample
20528
20529Connect @value{GDBN} to the remote target. This command takes two args:
20530
20531@table @samp
20532@item @var{type}
20533The type of target, for instance @samp{async}, @samp{remote}, etc.
20534@item @var{parameters}
20535Device names, host names and the like. @xref{Target Commands, ,
20536Commands for managing targets}, for more details.
20537@end table
20538
20539The output is a connection notification, followed by the address at
20540which the target program is, in the following form:
20541
20542@smallexample
20543^connected,addr="@var{address}",func="@var{function name}",
20544 args=[@var{arg list}]
20545@end smallexample
20546
20547@subsubheading @value{GDBN} Command
20548
20549The corresponding @value{GDBN} command is @samp{target}.
20550
20551@subsubheading Example
20552
20553@smallexample
20554(@value{GDBP})
20555-target-select async /dev/ttya
20556^connected,addr="0xfe00a300",func="??",args=[]
20557(@value{GDBP})
20558@end smallexample
20559
20560@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20561@node GDB/MI Thread Commands
20562@section @sc{gdb/mi} Thread Commands
20563
20564
20565@subheading The @code{-thread-info} Command
20566@findex -thread-info
20567
20568@subsubheading Synopsis
20569
20570@smallexample
20571 -thread-info
20572@end smallexample
20573
20574@subsubheading @value{GDBN} command
20575
20576No equivalent.
20577
20578@subsubheading Example
20579N.A.
20580
20581
20582@subheading The @code{-thread-list-all-threads} Command
20583@findex -thread-list-all-threads
20584
20585@subsubheading Synopsis
20586
20587@smallexample
20588 -thread-list-all-threads
20589@end smallexample
20590
20591@subsubheading @value{GDBN} Command
20592
20593The equivalent @value{GDBN} command is @samp{info threads}.
20594
20595@subsubheading Example
20596N.A.
20597
20598
20599@subheading The @code{-thread-list-ids} Command
20600@findex -thread-list-ids
20601
20602@subsubheading Synopsis
20603
20604@smallexample
20605 -thread-list-ids
20606@end smallexample
20607
20608Produces a list of the currently known @value{GDBN} thread ids. At the
20609end of the list it also prints the total number of such threads.
20610
20611@subsubheading @value{GDBN} Command
20612
20613Part of @samp{info threads} supplies the same information.
20614
20615@subsubheading Example
20616
20617No threads present, besides the main process:
20618
20619@smallexample
20620(@value{GDBP})
20621-thread-list-ids
20622^done,thread-ids=@{@},number-of-threads="0"
20623(@value{GDBP})
20624@end smallexample
20625
20626
20627Several threads:
20628
20629@smallexample
20630(@value{GDBP})
20631-thread-list-ids
20632^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20633number-of-threads="3"
20634(@value{GDBP})
20635@end smallexample
20636
20637
20638@subheading The @code{-thread-select} Command
20639@findex -thread-select
20640
20641@subsubheading Synopsis
20642
20643@smallexample
20644 -thread-select @var{threadnum}
20645@end smallexample
20646
20647Make @var{threadnum} the current thread. It prints the number of the new
20648current thread, and the topmost frame for that thread.
20649
20650@subsubheading @value{GDBN} Command
20651
20652The corresponding @value{GDBN} command is @samp{thread}.
20653
20654@subsubheading Example
20655
20656@smallexample
20657(@value{GDBP})
20658-exec-next
20659^running
20660(@value{GDBP})
20661*stopped,reason="end-stepping-range",thread-id="2",line="187",
20662file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
20663(@value{GDBP})
20664-thread-list-ids
20665^done,
20666thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20667number-of-threads="3"
20668(@value{GDBP})
20669-thread-select 3
20670^done,new-thread-id="3",
20671frame=@{level="0",func="vprintf",
20672args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
20673@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
20674(@value{GDBP})
20675@end smallexample
20676
20677@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20678@node GDB/MI Tracepoint Commands
20679@section @sc{gdb/mi} Tracepoint Commands
20680
20681The tracepoint commands are not yet implemented.
20682
20683@c @subheading -trace-actions
20684
20685@c @subheading -trace-delete
20686
20687@c @subheading -trace-disable
20688
20689@c @subheading -trace-dump
20690
20691@c @subheading -trace-enable
20692
20693@c @subheading -trace-exists
20694
20695@c @subheading -trace-find
20696
20697@c @subheading -trace-frame-number
20698
20699@c @subheading -trace-info
20700
20701@c @subheading -trace-insert
20702
20703@c @subheading -trace-list
20704
20705@c @subheading -trace-pass-count
20706
20707@c @subheading -trace-save
20708
20709@c @subheading -trace-start
20710
20711@c @subheading -trace-stop
20712
20713
20714@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20715@node GDB/MI Variable Objects
20716@section @sc{gdb/mi} Variable Objects
20717
20718
20719@subheading Motivation for Variable Objects in @sc{gdb/mi}
20720
20721For the implementation of a variable debugger window (locals, watched
20722expressions, etc.), we are proposing the adaptation of the existing code
20723used by @code{Insight}.
20724
20725The two main reasons for that are:
20726
20727@enumerate 1
20728@item
20729It has been proven in practice (it is already on its second generation).
20730
20731@item
20732It will shorten development time (needless to say how important it is
20733now).
20734@end enumerate
20735
20736The original interface was designed to be used by Tcl code, so it was
20737slightly changed so it could be used through @sc{gdb/mi}. This section
20738describes the @sc{gdb/mi} operations that will be available and gives some
20739hints about their use.
20740
20741@emph{Note}: In addition to the set of operations described here, we
20742expect the @sc{gui} implementation of a variable window to require, at
20743least, the following operations:
20744
20745@itemize @bullet
20746@item @code{-gdb-show} @code{output-radix}
20747@item @code{-stack-list-arguments}
20748@item @code{-stack-list-locals}
20749@item @code{-stack-select-frame}
20750@end itemize
20751
20752@subheading Introduction to Variable Objects in @sc{gdb/mi}
20753
20754@cindex variable objects in @sc{gdb/mi}
20755The basic idea behind variable objects is the creation of a named object
20756to represent a variable, an expression, a memory location or even a CPU
20757register. For each object created, a set of operations is available for
20758examining or changing its properties.
20759
20760Furthermore, complex data types, such as C structures, are represented
20761in a tree format. For instance, the @code{struct} type variable is the
20762root and the children will represent the struct members. If a child
20763is itself of a complex type, it will also have children of its own.
20764Appropriate language differences are handled for C, C@t{++} and Java.
20765
20766When returning the actual values of the objects, this facility allows
20767for the individual selection of the display format used in the result
20768creation. It can be chosen among: binary, decimal, hexadecimal, octal
20769and natural. Natural refers to a default format automatically
20770chosen based on the variable type (like decimal for an @code{int}, hex
20771for pointers, etc.).
20772
20773The following is the complete set of @sc{gdb/mi} operations defined to
20774access this functionality:
20775
20776@multitable @columnfractions .4 .6
20777@item @strong{Operation}
20778@tab @strong{Description}
20779
20780@item @code{-var-create}
20781@tab create a variable object
20782@item @code{-var-delete}
20783@tab delete the variable object and its children
20784@item @code{-var-set-format}
20785@tab set the display format of this variable
20786@item @code{-var-show-format}
20787@tab show the display format of this variable
20788@item @code{-var-info-num-children}
20789@tab tells how many children this object has
20790@item @code{-var-list-children}
20791@tab return a list of the object's children
20792@item @code{-var-info-type}
20793@tab show the type of this variable object
20794@item @code{-var-info-expression}
20795@tab print what this variable object represents
20796@item @code{-var-show-attributes}
20797@tab is this variable editable? does it exist here?
20798@item @code{-var-evaluate-expression}
20799@tab get the value of this variable
20800@item @code{-var-assign}
20801@tab set the value of this variable
20802@item @code{-var-update}
20803@tab update the variable and its children
20804@end multitable
20805
20806In the next subsection we describe each operation in detail and suggest
20807how it can be used.
20808
20809@subheading Description And Use of Operations on Variable Objects
20810
20811@subheading The @code{-var-create} Command
20812@findex -var-create
20813
20814@subsubheading Synopsis
20815
20816@smallexample
20817 -var-create @{@var{name} | "-"@}
20818 @{@var{frame-addr} | "*"@} @var{expression}
20819@end smallexample
20820
20821This operation creates a variable object, which allows the monitoring of
20822a variable, the result of an expression, a memory cell or a CPU
20823register.
20824
20825The @var{name} parameter is the string by which the object can be
20826referenced. It must be unique. If @samp{-} is specified, the varobj
20827system will generate a string ``varNNNNNN'' automatically. It will be
20828unique provided that one does not specify @var{name} on that format.
20829The command fails if a duplicate name is found.
20830
20831The frame under which the expression should be evaluated can be
20832specified by @var{frame-addr}. A @samp{*} indicates that the current
20833frame should be used.
20834
20835@var{expression} is any expression valid on the current language set (must not
20836begin with a @samp{*}), or one of the following:
20837
20838@itemize @bullet
20839@item
20840@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
20841
20842@item
20843@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
20844
20845@item
20846@samp{$@var{regname}} --- a CPU register name
20847@end itemize
20848
20849@subsubheading Result
20850
20851This operation returns the name, number of children and the type of the
20852object created. Type is returned as a string as the ones generated by
20853the @value{GDBN} CLI:
20854
20855@smallexample
20856 name="@var{name}",numchild="N",type="@var{type}"
20857@end smallexample
20858
20859
20860@subheading The @code{-var-delete} Command
20861@findex -var-delete
20862
20863@subsubheading Synopsis
20864
20865@smallexample
20866 -var-delete @var{name}
20867@end smallexample
20868
20869Deletes a previously created variable object and all of its children.
20870
20871Returns an error if the object @var{name} is not found.
20872
20873
20874@subheading The @code{-var-set-format} Command
20875@findex -var-set-format
20876
20877@subsubheading Synopsis
20878
20879@smallexample
20880 -var-set-format @var{name} @var{format-spec}
20881@end smallexample
20882
20883Sets the output format for the value of the object @var{name} to be
20884@var{format-spec}.
20885
20886The syntax for the @var{format-spec} is as follows:
20887
20888@smallexample
20889 @var{format-spec} @expansion{}
20890 @{binary | decimal | hexadecimal | octal | natural@}
20891@end smallexample
20892
20893
20894@subheading The @code{-var-show-format} Command
20895@findex -var-show-format
20896
20897@subsubheading Synopsis
20898
20899@smallexample
20900 -var-show-format @var{name}
20901@end smallexample
20902
20903Returns the format used to display the value of the object @var{name}.
20904
20905@smallexample
20906 @var{format} @expansion{}
20907 @var{format-spec}
20908@end smallexample
20909
20910
20911@subheading The @code{-var-info-num-children} Command
20912@findex -var-info-num-children
20913
20914@subsubheading Synopsis
20915
20916@smallexample
20917 -var-info-num-children @var{name}
20918@end smallexample
20919
20920Returns the number of children of a variable object @var{name}:
20921
20922@smallexample
20923 numchild=@var{n}
20924@end smallexample
20925
20926
20927@subheading The @code{-var-list-children} Command
20928@findex -var-list-children
20929
20930@subsubheading Synopsis
20931
20932@smallexample
bc8ced35 20933 -var-list-children [@var{print-values}] @var{name}
922fbb7b 20934@end smallexample
265eeb58 20935@anchor{-var-list-children}
922fbb7b 20936
265eeb58
NR
20937Return a list of the children of the specified variable object and
20938create variable objects for them, if they do not already exist. With
20939a single argument or if @var{print-values} has a value for of 0 or
20940@code{--no-values}, print only the names of the variables; if
20941@var{print-values} is 1 or @code{--all-values}, also print their
20942values; and if it is 2 or @code{--simple-values} print the name and
20943value for simple data types and just the name for arrays, structures
20944and unions.
bc8ced35
NR
20945
20946@subsubheading Example
922fbb7b
AC
20947
20948@smallexample
bc8ced35
NR
20949(@value{GDBP})
20950 -var-list-children n
265eeb58 20951 ^done,numchild=@var{n},children=[@{name=@var{name},
922fbb7b 20952 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
bc8ced35
NR
20953(@value{GDBP})
20954 -var-list-children --all-values n
265eeb58 20955 ^done,numchild=@var{n},children=[@{name=@var{name},
bc8ced35 20956 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
20957@end smallexample
20958
20959
20960@subheading The @code{-var-info-type} Command
20961@findex -var-info-type
20962
20963@subsubheading Synopsis
20964
20965@smallexample
20966 -var-info-type @var{name}
20967@end smallexample
20968
20969Returns the type of the specified variable @var{name}. The type is
20970returned as a string in the same format as it is output by the
20971@value{GDBN} CLI:
20972
20973@smallexample
20974 type=@var{typename}
20975@end smallexample
20976
20977
20978@subheading The @code{-var-info-expression} Command
20979@findex -var-info-expression
20980
20981@subsubheading Synopsis
20982
20983@smallexample
20984 -var-info-expression @var{name}
20985@end smallexample
20986
20987Returns what is represented by the variable object @var{name}:
20988
20989@smallexample
20990 lang=@var{lang-spec},exp=@var{expression}
20991@end smallexample
20992
20993@noindent
20994where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
20995
20996@subheading The @code{-var-show-attributes} Command
20997@findex -var-show-attributes
20998
20999@subsubheading Synopsis
21000
21001@smallexample
21002 -var-show-attributes @var{name}
21003@end smallexample
21004
21005List attributes of the specified variable object @var{name}:
21006
21007@smallexample
21008 status=@var{attr} [ ( ,@var{attr} )* ]
21009@end smallexample
21010
21011@noindent
21012where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
21013
21014@subheading The @code{-var-evaluate-expression} Command
21015@findex -var-evaluate-expression
21016
21017@subsubheading Synopsis
21018
21019@smallexample
21020 -var-evaluate-expression @var{name}
21021@end smallexample
21022
21023Evaluates the expression that is represented by the specified variable
21024object and returns its value as a string in the current format specified
21025for the object:
21026
21027@smallexample
21028 value=@var{value}
21029@end smallexample
21030
21031Note that one must invoke @code{-var-list-children} for a variable
21032before the value of a child variable can be evaluated.
21033
21034@subheading The @code{-var-assign} Command
21035@findex -var-assign
21036
21037@subsubheading Synopsis
21038
21039@smallexample
21040 -var-assign @var{name} @var{expression}
21041@end smallexample
21042
21043Assigns the value of @var{expression} to the variable object specified
21044by @var{name}. The object must be @samp{editable}. If the variable's
b383017d 21045value is altered by the assign, the variable will show up in any
922fbb7b
AC
21046subsequent @code{-var-update} list.
21047
21048@subsubheading Example
21049
21050@smallexample
21051(@value{GDBP})
21052-var-assign var1 3
21053^done,value="3"
21054(@value{GDBP})
21055-var-update *
21056^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
21057(@value{GDBP})
21058@end smallexample
21059
21060@subheading The @code{-var-update} Command
21061@findex -var-update
21062
21063@subsubheading Synopsis
21064
21065@smallexample
265eeb58 21066 -var-update [@var{print-values}] @{@var{name} | "*"@}
922fbb7b
AC
21067@end smallexample
21068
21069Update the value of the variable object @var{name} by evaluating its
21070expression after fetching all the new values from memory or registers.
265eeb58 21071A @samp{*} causes all existing variable objects to be updated. The
656d5e12
EZ
21072option @var{print-values} determines whether names both and values, or
21073just names are printed in the manner described for
21074@code{-var-list-children} (@pxref{-var-list-children}).
265eeb58
NR
21075
21076@subsubheading Example
922fbb7b 21077
265eeb58
NR
21078@smallexample
21079(@value{GDBP})
21080-var-assign var1 3
21081^done,value="3"
21082(@value{GDBP})
21083-var-update --all-values var1
21084^done,changelist=[@{name="var1",value="3",in_scope="true",
21085type_changed="false"@}]
21086(@value{GDBP})
21087@end smallexample
922fbb7b
AC
21088
21089@node Annotations
21090@chapter @value{GDBN} Annotations
21091
086432e2
AC
21092This chapter describes annotations in @value{GDBN}. Annotations were
21093designed to interface @value{GDBN} to graphical user interfaces or other
21094similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
21095relatively high level.
21096
086432e2
AC
21097The annotation mechanism has largely been superseeded by @sc{gdb/mi}
21098(@pxref{GDB/MI}).
21099
922fbb7b
AC
21100@ignore
21101This is Edition @value{EDITION}, @value{DATE}.
21102@end ignore
21103
21104@menu
21105* Annotations Overview:: What annotations are; the general syntax.
922fbb7b
AC
21106* Prompting:: Annotations marking @value{GDBN}'s need for input.
21107* Errors:: Annotations for error messages.
922fbb7b
AC
21108* Invalidation:: Some annotations describe things now invalid.
21109* Annotations for Running::
21110 Whether the program is running, how it stopped, etc.
21111* Source Annotations:: Annotations describing source code.
922fbb7b
AC
21112@end menu
21113
21114@node Annotations Overview
21115@section What is an Annotation?
21116@cindex annotations
21117
922fbb7b
AC
21118Annotations start with a newline character, two @samp{control-z}
21119characters, and the name of the annotation. If there is no additional
21120information associated with this annotation, the name of the annotation
21121is followed immediately by a newline. If there is additional
21122information, the name of the annotation is followed by a space, the
21123additional information, and a newline. The additional information
21124cannot contain newline characters.
21125
21126Any output not beginning with a newline and two @samp{control-z}
21127characters denotes literal output from @value{GDBN}. Currently there is
21128no need for @value{GDBN} to output a newline followed by two
21129@samp{control-z} characters, but if there was such a need, the
21130annotations could be extended with an @samp{escape} annotation which
21131means those three characters as output.
21132
086432e2
AC
21133The annotation @var{level}, which is specified using the
21134@option{--annotate} command line option (@pxref{Mode Options}), controls
21135how much information @value{GDBN} prints together with its prompt,
21136values of expressions, source lines, and other types of output. Level 0
21137is for no anntations, level 1 is for use when @value{GDBN} is run as a
21138subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
21139for programs that control @value{GDBN}, and level 2 annotations have
21140been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
21141Interface, annotate, GDB's Obsolete Annotations}).
21142
21143@table @code
21144@kindex set annotate
21145@item set annotate @var{level}
e09f16f9 21146The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 21147annotations to the specified @var{level}.
9c16f35a
EZ
21148
21149@item show annotate
21150@kindex show annotate
21151Show the current annotation level.
09d4efe1
EZ
21152@end table
21153
21154This chapter describes level 3 annotations.
086432e2 21155
922fbb7b
AC
21156A simple example of starting up @value{GDBN} with annotations is:
21157
21158@smallexample
086432e2
AC
21159$ @kbd{gdb --annotate=3}
21160GNU gdb 6.0
21161Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
21162GDB is free software, covered by the GNU General Public License,
21163and you are welcome to change it and/or distribute copies of it
21164under certain conditions.
21165Type "show copying" to see the conditions.
21166There is absolutely no warranty for GDB. Type "show warranty"
21167for details.
086432e2 21168This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
21169
21170^Z^Zpre-prompt
f7dc1244 21171(@value{GDBP})
922fbb7b 21172^Z^Zprompt
086432e2 21173@kbd{quit}
922fbb7b
AC
21174
21175^Z^Zpost-prompt
b383017d 21176$
922fbb7b
AC
21177@end smallexample
21178
21179Here @samp{quit} is input to @value{GDBN}; the rest is output from
21180@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
21181denotes a @samp{control-z} character) are annotations; the rest is
21182output from @value{GDBN}.
21183
922fbb7b
AC
21184@node Prompting
21185@section Annotation for @value{GDBN} Input
21186
21187@cindex annotations for prompts
21188When @value{GDBN} prompts for input, it annotates this fact so it is possible
21189to know when to send output, when the output from a given command is
21190over, etc.
21191
21192Different kinds of input each have a different @dfn{input type}. Each
21193input type has three annotations: a @code{pre-} annotation, which
21194denotes the beginning of any prompt which is being output, a plain
21195annotation, which denotes the end of the prompt, and then a @code{post-}
21196annotation which denotes the end of any echo which may (or may not) be
21197associated with the input. For example, the @code{prompt} input type
21198features the following annotations:
21199
21200@smallexample
21201^Z^Zpre-prompt
21202^Z^Zprompt
21203^Z^Zpost-prompt
21204@end smallexample
21205
21206The input types are
21207
21208@table @code
21209@findex pre-prompt
21210@findex prompt
21211@findex post-prompt
21212@item prompt
21213When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
21214
21215@findex pre-commands
21216@findex commands
21217@findex post-commands
21218@item commands
21219When @value{GDBN} prompts for a set of commands, like in the @code{commands}
21220command. The annotations are repeated for each command which is input.
21221
21222@findex pre-overload-choice
21223@findex overload-choice
21224@findex post-overload-choice
21225@item overload-choice
21226When @value{GDBN} wants the user to select between various overloaded functions.
21227
21228@findex pre-query
21229@findex query
21230@findex post-query
21231@item query
21232When @value{GDBN} wants the user to confirm a potentially dangerous operation.
21233
21234@findex pre-prompt-for-continue
21235@findex prompt-for-continue
21236@findex post-prompt-for-continue
21237@item prompt-for-continue
21238When @value{GDBN} is asking the user to press return to continue. Note: Don't
21239expect this to work well; instead use @code{set height 0} to disable
21240prompting. This is because the counting of lines is buggy in the
21241presence of annotations.
21242@end table
21243
21244@node Errors
21245@section Errors
21246@cindex annotations for errors, warnings and interrupts
21247
21248@findex quit
21249@smallexample
21250^Z^Zquit
21251@end smallexample
21252
21253This annotation occurs right before @value{GDBN} responds to an interrupt.
21254
21255@findex error
21256@smallexample
21257^Z^Zerror
21258@end smallexample
21259
21260This annotation occurs right before @value{GDBN} responds to an error.
21261
21262Quit and error annotations indicate that any annotations which @value{GDBN} was
21263in the middle of may end abruptly. For example, if a
21264@code{value-history-begin} annotation is followed by a @code{error}, one
21265cannot expect to receive the matching @code{value-history-end}. One
21266cannot expect not to receive it either, however; an error annotation
21267does not necessarily mean that @value{GDBN} is immediately returning all the way
21268to the top level.
21269
21270@findex error-begin
21271A quit or error annotation may be preceded by
21272
21273@smallexample
21274^Z^Zerror-begin
21275@end smallexample
21276
21277Any output between that and the quit or error annotation is the error
21278message.
21279
21280Warning messages are not yet annotated.
21281@c If we want to change that, need to fix warning(), type_error(),
21282@c range_error(), and possibly other places.
21283
922fbb7b
AC
21284@node Invalidation
21285@section Invalidation Notices
21286
21287@cindex annotations for invalidation messages
21288The following annotations say that certain pieces of state may have
21289changed.
21290
21291@table @code
21292@findex frames-invalid
21293@item ^Z^Zframes-invalid
21294
21295The frames (for example, output from the @code{backtrace} command) may
21296have changed.
21297
21298@findex breakpoints-invalid
21299@item ^Z^Zbreakpoints-invalid
21300
21301The breakpoints may have changed. For example, the user just added or
21302deleted a breakpoint.
21303@end table
21304
21305@node Annotations for Running
21306@section Running the Program
21307@cindex annotations for running programs
21308
21309@findex starting
21310@findex stopping
21311When the program starts executing due to a @value{GDBN} command such as
b383017d 21312@code{step} or @code{continue},
922fbb7b
AC
21313
21314@smallexample
21315^Z^Zstarting
21316@end smallexample
21317
b383017d 21318is output. When the program stops,
922fbb7b
AC
21319
21320@smallexample
21321^Z^Zstopped
21322@end smallexample
21323
21324is output. Before the @code{stopped} annotation, a variety of
21325annotations describe how the program stopped.
21326
21327@table @code
21328@findex exited
21329@item ^Z^Zexited @var{exit-status}
21330The program exited, and @var{exit-status} is the exit status (zero for
21331successful exit, otherwise nonzero).
21332
21333@findex signalled
21334@findex signal-name
21335@findex signal-name-end
21336@findex signal-string
21337@findex signal-string-end
21338@item ^Z^Zsignalled
21339The program exited with a signal. After the @code{^Z^Zsignalled}, the
21340annotation continues:
21341
21342@smallexample
21343@var{intro-text}
21344^Z^Zsignal-name
21345@var{name}
21346^Z^Zsignal-name-end
21347@var{middle-text}
21348^Z^Zsignal-string
21349@var{string}
21350^Z^Zsignal-string-end
21351@var{end-text}
21352@end smallexample
21353
21354@noindent
21355where @var{name} is the name of the signal, such as @code{SIGILL} or
21356@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
21357as @code{Illegal Instruction} or @code{Segmentation fault}.
21358@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
21359user's benefit and have no particular format.
21360
21361@findex signal
21362@item ^Z^Zsignal
21363The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
21364just saying that the program received the signal, not that it was
21365terminated with it.
21366
21367@findex breakpoint
21368@item ^Z^Zbreakpoint @var{number}
21369The program hit breakpoint number @var{number}.
21370
21371@findex watchpoint
21372@item ^Z^Zwatchpoint @var{number}
21373The program hit watchpoint number @var{number}.
21374@end table
21375
21376@node Source Annotations
21377@section Displaying Source
21378@cindex annotations for source display
21379
21380@findex source
21381The following annotation is used instead of displaying source code:
21382
21383@smallexample
21384^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
21385@end smallexample
21386
21387where @var{filename} is an absolute file name indicating which source
21388file, @var{line} is the line number within that file (where 1 is the
21389first line in the file), @var{character} is the character position
21390within the file (where 0 is the first character in the file) (for most
21391debug formats this will necessarily point to the beginning of a line),
21392@var{middle} is @samp{middle} if @var{addr} is in the middle of the
21393line, or @samp{beg} if @var{addr} is at the beginning of the line, and
21394@var{addr} is the address in the target program associated with the
21395source which is being displayed. @var{addr} is in the form @samp{0x}
21396followed by one or more lowercase hex digits (note that this does not
21397depend on the language).
21398
8e04817f
AC
21399@node GDB Bugs
21400@chapter Reporting Bugs in @value{GDBN}
21401@cindex bugs in @value{GDBN}
21402@cindex reporting bugs in @value{GDBN}
c906108c 21403
8e04817f 21404Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 21405
8e04817f
AC
21406Reporting a bug may help you by bringing a solution to your problem, or it
21407may not. But in any case the principal function of a bug report is to help
21408the entire community by making the next version of @value{GDBN} work better. Bug
21409reports are your contribution to the maintenance of @value{GDBN}.
c906108c 21410
8e04817f
AC
21411In order for a bug report to serve its purpose, you must include the
21412information that enables us to fix the bug.
c4555f82
SC
21413
21414@menu
8e04817f
AC
21415* Bug Criteria:: Have you found a bug?
21416* Bug Reporting:: How to report bugs
c4555f82
SC
21417@end menu
21418
8e04817f
AC
21419@node Bug Criteria
21420@section Have you found a bug?
21421@cindex bug criteria
c4555f82 21422
8e04817f 21423If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
21424
21425@itemize @bullet
8e04817f
AC
21426@cindex fatal signal
21427@cindex debugger crash
21428@cindex crash of debugger
c4555f82 21429@item
8e04817f
AC
21430If the debugger gets a fatal signal, for any input whatever, that is a
21431@value{GDBN} bug. Reliable debuggers never crash.
21432
21433@cindex error on valid input
21434@item
21435If @value{GDBN} produces an error message for valid input, that is a
21436bug. (Note that if you're cross debugging, the problem may also be
21437somewhere in the connection to the target.)
c4555f82 21438
8e04817f 21439@cindex invalid input
c4555f82 21440@item
8e04817f
AC
21441If @value{GDBN} does not produce an error message for invalid input,
21442that is a bug. However, you should note that your idea of
21443``invalid input'' might be our idea of ``an extension'' or ``support
21444for traditional practice''.
21445
21446@item
21447If you are an experienced user of debugging tools, your suggestions
21448for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
21449@end itemize
21450
8e04817f
AC
21451@node Bug Reporting
21452@section How to report bugs
21453@cindex bug reports
21454@cindex @value{GDBN} bugs, reporting
21455
21456A number of companies and individuals offer support for @sc{gnu} products.
21457If you obtained @value{GDBN} from a support organization, we recommend you
21458contact that organization first.
21459
21460You can find contact information for many support companies and
21461individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
21462distribution.
21463@c should add a web page ref...
21464
129188f6
AC
21465In any event, we also recommend that you submit bug reports for
21466@value{GDBN}. The prefered method is to submit them directly using
21467@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
21468page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
21469be used.
8e04817f
AC
21470
21471@strong{Do not send bug reports to @samp{info-gdb}, or to
21472@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
21473not want to receive bug reports. Those that do have arranged to receive
21474@samp{bug-gdb}.
21475
21476The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
21477serves as a repeater. The mailing list and the newsgroup carry exactly
21478the same messages. Often people think of posting bug reports to the
21479newsgroup instead of mailing them. This appears to work, but it has one
21480problem which can be crucial: a newsgroup posting often lacks a mail
21481path back to the sender. Thus, if we need to ask for more information,
21482we may be unable to reach you. For this reason, it is better to send
21483bug reports to the mailing list.
c4555f82 21484
8e04817f
AC
21485The fundamental principle of reporting bugs usefully is this:
21486@strong{report all the facts}. If you are not sure whether to state a
21487fact or leave it out, state it!
c4555f82 21488
8e04817f
AC
21489Often people omit facts because they think they know what causes the
21490problem and assume that some details do not matter. Thus, you might
21491assume that the name of the variable you use in an example does not matter.
21492Well, probably it does not, but one cannot be sure. Perhaps the bug is a
21493stray memory reference which happens to fetch from the location where that
21494name is stored in memory; perhaps, if the name were different, the contents
21495of that location would fool the debugger into doing the right thing despite
21496the bug. Play it safe and give a specific, complete example. That is the
21497easiest thing for you to do, and the most helpful.
c4555f82 21498
8e04817f
AC
21499Keep in mind that the purpose of a bug report is to enable us to fix the
21500bug. It may be that the bug has been reported previously, but neither
21501you nor we can know that unless your bug report is complete and
21502self-contained.
c4555f82 21503
8e04817f
AC
21504Sometimes people give a few sketchy facts and ask, ``Does this ring a
21505bell?'' Those bug reports are useless, and we urge everyone to
21506@emph{refuse to respond to them} except to chide the sender to report
21507bugs properly.
21508
21509To enable us to fix the bug, you should include all these things:
c4555f82
SC
21510
21511@itemize @bullet
21512@item
8e04817f
AC
21513The version of @value{GDBN}. @value{GDBN} announces it if you start
21514with no arguments; you can also print it at any time using @code{show
21515version}.
c4555f82 21516
8e04817f
AC
21517Without this, we will not know whether there is any point in looking for
21518the bug in the current version of @value{GDBN}.
c4555f82
SC
21519
21520@item
8e04817f
AC
21521The type of machine you are using, and the operating system name and
21522version number.
c4555f82
SC
21523
21524@item
c1468174 21525What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 21526``@value{GCC}--2.8.1''.
c4555f82
SC
21527
21528@item
8e04817f 21529What compiler (and its version) was used to compile the program you are
c1468174 21530debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
8e04817f
AC
21531C Compiler''. For GCC, you can say @code{gcc --version} to get this
21532information; for other compilers, see the documentation for those
21533compilers.
c4555f82 21534
8e04817f
AC
21535@item
21536The command arguments you gave the compiler to compile your example and
21537observe the bug. For example, did you use @samp{-O}? To guarantee
21538you will not omit something important, list them all. A copy of the
21539Makefile (or the output from make) is sufficient.
c4555f82 21540
8e04817f
AC
21541If we were to try to guess the arguments, we would probably guess wrong
21542and then we might not encounter the bug.
c4555f82 21543
8e04817f
AC
21544@item
21545A complete input script, and all necessary source files, that will
21546reproduce the bug.
c4555f82 21547
8e04817f
AC
21548@item
21549A description of what behavior you observe that you believe is
21550incorrect. For example, ``It gets a fatal signal.''
c4555f82 21551
8e04817f
AC
21552Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
21553will certainly notice it. But if the bug is incorrect output, we might
21554not notice unless it is glaringly wrong. You might as well not give us
21555a chance to make a mistake.
c4555f82 21556
8e04817f
AC
21557Even if the problem you experience is a fatal signal, you should still
21558say so explicitly. Suppose something strange is going on, such as, your
21559copy of @value{GDBN} is out of synch, or you have encountered a bug in
21560the C library on your system. (This has happened!) Your copy might
21561crash and ours would not. If you told us to expect a crash, then when
21562ours fails to crash, we would know that the bug was not happening for
21563us. If you had not told us to expect a crash, then we would not be able
21564to draw any conclusion from our observations.
c4555f82 21565
e0c07bf0
MC
21566@pindex script
21567@cindex recording a session script
21568To collect all this information, you can use a session recording program
21569such as @command{script}, which is available on many Unix systems.
21570Just run your @value{GDBN} session inside @command{script} and then
21571include the @file{typescript} file with your bug report.
21572
21573Another way to record a @value{GDBN} session is to run @value{GDBN}
21574inside Emacs and then save the entire buffer to a file.
21575
8e04817f
AC
21576@item
21577If you wish to suggest changes to the @value{GDBN} source, send us context
21578diffs. If you even discuss something in the @value{GDBN} source, refer to
21579it by context, not by line number.
c4555f82 21580
8e04817f
AC
21581The line numbers in our development sources will not match those in your
21582sources. Your line numbers would convey no useful information to us.
c4555f82 21583
8e04817f 21584@end itemize
c4555f82 21585
8e04817f 21586Here are some things that are not necessary:
c4555f82 21587
8e04817f
AC
21588@itemize @bullet
21589@item
21590A description of the envelope of the bug.
c4555f82 21591
8e04817f
AC
21592Often people who encounter a bug spend a lot of time investigating
21593which changes to the input file will make the bug go away and which
21594changes will not affect it.
c4555f82 21595
8e04817f
AC
21596This is often time consuming and not very useful, because the way we
21597will find the bug is by running a single example under the debugger
21598with breakpoints, not by pure deduction from a series of examples.
21599We recommend that you save your time for something else.
c4555f82 21600
8e04817f
AC
21601Of course, if you can find a simpler example to report @emph{instead}
21602of the original one, that is a convenience for us. Errors in the
21603output will be easier to spot, running under the debugger will take
21604less time, and so on.
c4555f82 21605
8e04817f
AC
21606However, simplification is not vital; if you do not want to do this,
21607report the bug anyway and send us the entire test case you used.
c4555f82 21608
8e04817f
AC
21609@item
21610A patch for the bug.
c4555f82 21611
8e04817f
AC
21612A patch for the bug does help us if it is a good one. But do not omit
21613the necessary information, such as the test case, on the assumption that
21614a patch is all we need. We might see problems with your patch and decide
21615to fix the problem another way, or we might not understand it at all.
c4555f82 21616
8e04817f
AC
21617Sometimes with a program as complicated as @value{GDBN} it is very hard to
21618construct an example that will make the program follow a certain path
21619through the code. If you do not send us the example, we will not be able
21620to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 21621
8e04817f
AC
21622And if we cannot understand what bug you are trying to fix, or why your
21623patch should be an improvement, we will not install it. A test case will
21624help us to understand.
c4555f82 21625
8e04817f
AC
21626@item
21627A guess about what the bug is or what it depends on.
c4555f82 21628
8e04817f
AC
21629Such guesses are usually wrong. Even we cannot guess right about such
21630things without first using the debugger to find the facts.
21631@end itemize
c4555f82 21632
8e04817f
AC
21633@c The readline documentation is distributed with the readline code
21634@c and consists of the two following files:
21635@c rluser.texinfo
21636@c inc-hist.texinfo
21637@c Use -I with makeinfo to point to the appropriate directory,
21638@c environment var TEXINPUTS with TeX.
21639@include rluser.texinfo
21640@include inc-hist.texinfo
c4555f82 21641
c4555f82 21642
8e04817f
AC
21643@node Formatting Documentation
21644@appendix Formatting Documentation
c4555f82 21645
8e04817f
AC
21646@cindex @value{GDBN} reference card
21647@cindex reference card
21648The @value{GDBN} 4 release includes an already-formatted reference card, ready
21649for printing with PostScript or Ghostscript, in the @file{gdb}
21650subdirectory of the main source directory@footnote{In
21651@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
21652release.}. If you can use PostScript or Ghostscript with your printer,
21653you can print the reference card immediately with @file{refcard.ps}.
c4555f82 21654
8e04817f
AC
21655The release also includes the source for the reference card. You
21656can format it, using @TeX{}, by typing:
c4555f82 21657
474c8240 21658@smallexample
8e04817f 21659make refcard.dvi
474c8240 21660@end smallexample
c4555f82 21661
8e04817f
AC
21662The @value{GDBN} reference card is designed to print in @dfn{landscape}
21663mode on US ``letter'' size paper;
21664that is, on a sheet 11 inches wide by 8.5 inches
21665high. You will need to specify this form of printing as an option to
21666your @sc{dvi} output program.
c4555f82 21667
8e04817f 21668@cindex documentation
c4555f82 21669
8e04817f
AC
21670All the documentation for @value{GDBN} comes as part of the machine-readable
21671distribution. The documentation is written in Texinfo format, which is
21672a documentation system that uses a single source file to produce both
21673on-line information and a printed manual. You can use one of the Info
21674formatting commands to create the on-line version of the documentation
21675and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 21676
8e04817f
AC
21677@value{GDBN} includes an already formatted copy of the on-line Info
21678version of this manual in the @file{gdb} subdirectory. The main Info
21679file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
21680subordinate files matching @samp{gdb.info*} in the same directory. If
21681necessary, you can print out these files, or read them with any editor;
21682but they are easier to read using the @code{info} subsystem in @sc{gnu}
21683Emacs or the standalone @code{info} program, available as part of the
21684@sc{gnu} Texinfo distribution.
c4555f82 21685
8e04817f
AC
21686If you want to format these Info files yourself, you need one of the
21687Info formatting programs, such as @code{texinfo-format-buffer} or
21688@code{makeinfo}.
c4555f82 21689
8e04817f
AC
21690If you have @code{makeinfo} installed, and are in the top level
21691@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
21692version @value{GDBVN}), you can make the Info file by typing:
c4555f82 21693
474c8240 21694@smallexample
8e04817f
AC
21695cd gdb
21696make gdb.info
474c8240 21697@end smallexample
c4555f82 21698
8e04817f
AC
21699If you want to typeset and print copies of this manual, you need @TeX{},
21700a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
21701Texinfo definitions file.
c4555f82 21702
8e04817f
AC
21703@TeX{} is a typesetting program; it does not print files directly, but
21704produces output files called @sc{dvi} files. To print a typeset
21705document, you need a program to print @sc{dvi} files. If your system
21706has @TeX{} installed, chances are it has such a program. The precise
21707command to use depends on your system; @kbd{lpr -d} is common; another
21708(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
21709require a file name without any extension or a @samp{.dvi} extension.
c4555f82 21710
8e04817f
AC
21711@TeX{} also requires a macro definitions file called
21712@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
21713written in Texinfo format. On its own, @TeX{} cannot either read or
21714typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
21715and is located in the @file{gdb-@var{version-number}/texinfo}
21716directory.
c4555f82 21717
8e04817f
AC
21718If you have @TeX{} and a @sc{dvi} printer program installed, you can
21719typeset and print this manual. First switch to the the @file{gdb}
21720subdirectory of the main source directory (for example, to
21721@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 21722
474c8240 21723@smallexample
8e04817f 21724make gdb.dvi
474c8240 21725@end smallexample
c4555f82 21726
8e04817f 21727Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 21728
8e04817f
AC
21729@node Installing GDB
21730@appendix Installing @value{GDBN}
21731@cindex configuring @value{GDBN}
21732@cindex installation
94e91d6d 21733@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 21734
8e04817f
AC
21735@value{GDBN} comes with a @code{configure} script that automates the process
21736of preparing @value{GDBN} for installation; you can then use @code{make} to
21737build the @code{gdb} program.
21738@iftex
21739@c irrelevant in info file; it's as current as the code it lives with.
21740@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
21741look at the @file{README} file in the sources; we may have improved the
21742installation procedures since publishing this manual.}
21743@end iftex
c4555f82 21744
8e04817f
AC
21745The @value{GDBN} distribution includes all the source code you need for
21746@value{GDBN} in a single directory, whose name is usually composed by
21747appending the version number to @samp{gdb}.
c4555f82 21748
8e04817f
AC
21749For example, the @value{GDBN} version @value{GDBVN} distribution is in the
21750@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 21751
8e04817f
AC
21752@table @code
21753@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
21754script for configuring @value{GDBN} and all its supporting libraries
c4555f82 21755
8e04817f
AC
21756@item gdb-@value{GDBVN}/gdb
21757the source specific to @value{GDBN} itself
c4555f82 21758
8e04817f
AC
21759@item gdb-@value{GDBVN}/bfd
21760source for the Binary File Descriptor library
c906108c 21761
8e04817f
AC
21762@item gdb-@value{GDBVN}/include
21763@sc{gnu} include files
c906108c 21764
8e04817f
AC
21765@item gdb-@value{GDBVN}/libiberty
21766source for the @samp{-liberty} free software library
c906108c 21767
8e04817f
AC
21768@item gdb-@value{GDBVN}/opcodes
21769source for the library of opcode tables and disassemblers
c906108c 21770
8e04817f
AC
21771@item gdb-@value{GDBVN}/readline
21772source for the @sc{gnu} command-line interface
c906108c 21773
8e04817f
AC
21774@item gdb-@value{GDBVN}/glob
21775source for the @sc{gnu} filename pattern-matching subroutine
c906108c 21776
8e04817f
AC
21777@item gdb-@value{GDBVN}/mmalloc
21778source for the @sc{gnu} memory-mapped malloc package
21779@end table
c906108c 21780
8e04817f
AC
21781The simplest way to configure and build @value{GDBN} is to run @code{configure}
21782from the @file{gdb-@var{version-number}} source directory, which in
21783this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 21784
8e04817f
AC
21785First switch to the @file{gdb-@var{version-number}} source directory
21786if you are not already in it; then run @code{configure}. Pass the
21787identifier for the platform on which @value{GDBN} will run as an
21788argument.
c906108c 21789
8e04817f 21790For example:
c906108c 21791
474c8240 21792@smallexample
8e04817f
AC
21793cd gdb-@value{GDBVN}
21794./configure @var{host}
21795make
474c8240 21796@end smallexample
c906108c 21797
8e04817f
AC
21798@noindent
21799where @var{host} is an identifier such as @samp{sun4} or
21800@samp{decstation}, that identifies the platform where @value{GDBN} will run.
21801(You can often leave off @var{host}; @code{configure} tries to guess the
21802correct value by examining your system.)
c906108c 21803
8e04817f
AC
21804Running @samp{configure @var{host}} and then running @code{make} builds the
21805@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
21806libraries, then @code{gdb} itself. The configured source files, and the
21807binaries, are left in the corresponding source directories.
c906108c 21808
8e04817f
AC
21809@need 750
21810@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
21811system does not recognize this automatically when you run a different
21812shell, you may need to run @code{sh} on it explicitly:
c906108c 21813
474c8240 21814@smallexample
8e04817f 21815sh configure @var{host}
474c8240 21816@end smallexample
c906108c 21817
8e04817f
AC
21818If you run @code{configure} from a directory that contains source
21819directories for multiple libraries or programs, such as the
21820@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
21821creates configuration files for every directory level underneath (unless
21822you tell it not to, with the @samp{--norecursion} option).
21823
94e91d6d
MC
21824You should run the @code{configure} script from the top directory in the
21825source tree, the @file{gdb-@var{version-number}} directory. If you run
21826@code{configure} from one of the subdirectories, you will configure only
21827that subdirectory. That is usually not what you want. In particular,
21828if you run the first @code{configure} from the @file{gdb} subdirectory
21829of the @file{gdb-@var{version-number}} directory, you will omit the
21830configuration of @file{bfd}, @file{readline}, and other sibling
21831directories of the @file{gdb} subdirectory. This leads to build errors
21832about missing include files such as @file{bfd/bfd.h}.
c906108c 21833
8e04817f
AC
21834You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
21835However, you should make sure that the shell on your path (named by
21836the @samp{SHELL} environment variable) is publicly readable. Remember
21837that @value{GDBN} uses the shell to start your program---some systems refuse to
21838let @value{GDBN} debug child processes whose programs are not readable.
c906108c 21839
8e04817f
AC
21840@menu
21841* Separate Objdir:: Compiling @value{GDBN} in another directory
21842* Config Names:: Specifying names for hosts and targets
21843* Configure Options:: Summary of options for configure
21844@end menu
c906108c 21845
8e04817f
AC
21846@node Separate Objdir
21847@section Compiling @value{GDBN} in another directory
c906108c 21848
8e04817f
AC
21849If you want to run @value{GDBN} versions for several host or target machines,
21850you need a different @code{gdb} compiled for each combination of
21851host and target. @code{configure} is designed to make this easy by
21852allowing you to generate each configuration in a separate subdirectory,
21853rather than in the source directory. If your @code{make} program
21854handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
21855@code{make} in each of these directories builds the @code{gdb}
21856program specified there.
c906108c 21857
8e04817f
AC
21858To build @code{gdb} in a separate directory, run @code{configure}
21859with the @samp{--srcdir} option to specify where to find the source.
21860(You also need to specify a path to find @code{configure}
21861itself from your working directory. If the path to @code{configure}
21862would be the same as the argument to @samp{--srcdir}, you can leave out
21863the @samp{--srcdir} option; it is assumed.)
c906108c 21864
8e04817f
AC
21865For example, with version @value{GDBVN}, you can build @value{GDBN} in a
21866separate directory for a Sun 4 like this:
c906108c 21867
474c8240 21868@smallexample
8e04817f
AC
21869@group
21870cd gdb-@value{GDBVN}
21871mkdir ../gdb-sun4
21872cd ../gdb-sun4
21873../gdb-@value{GDBVN}/configure sun4
21874make
21875@end group
474c8240 21876@end smallexample
c906108c 21877
8e04817f
AC
21878When @code{configure} builds a configuration using a remote source
21879directory, it creates a tree for the binaries with the same structure
21880(and using the same names) as the tree under the source directory. In
21881the example, you'd find the Sun 4 library @file{libiberty.a} in the
21882directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
21883@file{gdb-sun4/gdb}.
c906108c 21884
94e91d6d
MC
21885Make sure that your path to the @file{configure} script has just one
21886instance of @file{gdb} in it. If your path to @file{configure} looks
21887like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
21888one subdirectory of @value{GDBN}, not the whole package. This leads to
21889build errors about missing include files such as @file{bfd/bfd.h}.
21890
8e04817f
AC
21891One popular reason to build several @value{GDBN} configurations in separate
21892directories is to configure @value{GDBN} for cross-compiling (where
21893@value{GDBN} runs on one machine---the @dfn{host}---while debugging
21894programs that run on another machine---the @dfn{target}).
21895You specify a cross-debugging target by
21896giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 21897
8e04817f
AC
21898When you run @code{make} to build a program or library, you must run
21899it in a configured directory---whatever directory you were in when you
21900called @code{configure} (or one of its subdirectories).
c906108c 21901
8e04817f
AC
21902The @code{Makefile} that @code{configure} generates in each source
21903directory also runs recursively. If you type @code{make} in a source
21904directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
21905directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
21906will build all the required libraries, and then build GDB.
c906108c 21907
8e04817f
AC
21908When you have multiple hosts or targets configured in separate
21909directories, you can run @code{make} on them in parallel (for example,
21910if they are NFS-mounted on each of the hosts); they will not interfere
21911with each other.
c906108c 21912
8e04817f
AC
21913@node Config Names
21914@section Specifying names for hosts and targets
c906108c 21915
8e04817f
AC
21916The specifications used for hosts and targets in the @code{configure}
21917script are based on a three-part naming scheme, but some short predefined
21918aliases are also supported. The full naming scheme encodes three pieces
21919of information in the following pattern:
c906108c 21920
474c8240 21921@smallexample
8e04817f 21922@var{architecture}-@var{vendor}-@var{os}
474c8240 21923@end smallexample
c906108c 21924
8e04817f
AC
21925For example, you can use the alias @code{sun4} as a @var{host} argument,
21926or as the value for @var{target} in a @code{--target=@var{target}}
21927option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 21928
8e04817f
AC
21929The @code{configure} script accompanying @value{GDBN} does not provide
21930any query facility to list all supported host and target names or
21931aliases. @code{configure} calls the Bourne shell script
21932@code{config.sub} to map abbreviations to full names; you can read the
21933script, if you wish, or you can use it to test your guesses on
21934abbreviations---for example:
c906108c 21935
8e04817f
AC
21936@smallexample
21937% sh config.sub i386-linux
21938i386-pc-linux-gnu
21939% sh config.sub alpha-linux
21940alpha-unknown-linux-gnu
21941% sh config.sub hp9k700
21942hppa1.1-hp-hpux
21943% sh config.sub sun4
21944sparc-sun-sunos4.1.1
21945% sh config.sub sun3
21946m68k-sun-sunos4.1.1
21947% sh config.sub i986v
21948Invalid configuration `i986v': machine `i986v' not recognized
21949@end smallexample
c906108c 21950
8e04817f
AC
21951@noindent
21952@code{config.sub} is also distributed in the @value{GDBN} source
21953directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 21954
8e04817f
AC
21955@node Configure Options
21956@section @code{configure} options
c906108c 21957
8e04817f
AC
21958Here is a summary of the @code{configure} options and arguments that
21959are most often useful for building @value{GDBN}. @code{configure} also has
21960several other options not listed here. @inforef{What Configure
21961Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 21962
474c8240 21963@smallexample
8e04817f
AC
21964configure @r{[}--help@r{]}
21965 @r{[}--prefix=@var{dir}@r{]}
21966 @r{[}--exec-prefix=@var{dir}@r{]}
21967 @r{[}--srcdir=@var{dirname}@r{]}
21968 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
21969 @r{[}--target=@var{target}@r{]}
21970 @var{host}
474c8240 21971@end smallexample
c906108c 21972
8e04817f
AC
21973@noindent
21974You may introduce options with a single @samp{-} rather than
21975@samp{--} if you prefer; but you may abbreviate option names if you use
21976@samp{--}.
c906108c 21977
8e04817f
AC
21978@table @code
21979@item --help
21980Display a quick summary of how to invoke @code{configure}.
c906108c 21981
8e04817f
AC
21982@item --prefix=@var{dir}
21983Configure the source to install programs and files under directory
21984@file{@var{dir}}.
c906108c 21985
8e04817f
AC
21986@item --exec-prefix=@var{dir}
21987Configure the source to install programs under directory
21988@file{@var{dir}}.
c906108c 21989
8e04817f
AC
21990@c avoid splitting the warning from the explanation:
21991@need 2000
21992@item --srcdir=@var{dirname}
21993@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
21994@code{make} that implements the @code{VPATH} feature.}@*
21995Use this option to make configurations in directories separate from the
21996@value{GDBN} source directories. Among other things, you can use this to
21997build (or maintain) several configurations simultaneously, in separate
21998directories. @code{configure} writes configuration specific files in
21999the current directory, but arranges for them to use the source in the
22000directory @var{dirname}. @code{configure} creates directories under
22001the working directory in parallel to the source directories below
22002@var{dirname}.
c906108c 22003
8e04817f
AC
22004@item --norecursion
22005Configure only the directory level where @code{configure} is executed; do not
22006propagate configuration to subdirectories.
c906108c 22007
8e04817f
AC
22008@item --target=@var{target}
22009Configure @value{GDBN} for cross-debugging programs running on the specified
22010@var{target}. Without this option, @value{GDBN} is configured to debug
22011programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 22012
8e04817f 22013There is no convenient way to generate a list of all available targets.
c906108c 22014
8e04817f
AC
22015@item @var{host} @dots{}
22016Configure @value{GDBN} to run on the specified @var{host}.
c906108c 22017
8e04817f
AC
22018There is no convenient way to generate a list of all available hosts.
22019@end table
c906108c 22020
8e04817f
AC
22021There are many other options available as well, but they are generally
22022needed for special purposes only.
c906108c 22023
8e04817f
AC
22024@node Maintenance Commands
22025@appendix Maintenance Commands
22026@cindex maintenance commands
22027@cindex internal commands
c906108c 22028
8e04817f 22029In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
22030includes a number of commands intended for @value{GDBN} developers,
22031that are not documented elsewhere in this manual. These commands are
da316a69
EZ
22032provided here for reference. (For commands that turn on debugging
22033messages, see @ref{Debugging Output}.)
c906108c 22034
8e04817f 22035@table @code
09d4efe1
EZ
22036@kindex maint agent
22037@item maint agent @var{expression}
22038Translate the given @var{expression} into remote agent bytecodes.
22039This command is useful for debugging the Agent Expression mechanism
22040(@pxref{Agent Expressions}).
22041
8e04817f
AC
22042@kindex maint info breakpoints
22043@item @anchor{maint info breakpoints}maint info breakpoints
22044Using the same format as @samp{info breakpoints}, display both the
22045breakpoints you've set explicitly, and those @value{GDBN} is using for
22046internal purposes. Internal breakpoints are shown with negative
22047breakpoint numbers. The type column identifies what kind of breakpoint
22048is shown:
c906108c 22049
8e04817f
AC
22050@table @code
22051@item breakpoint
22052Normal, explicitly set breakpoint.
c906108c 22053
8e04817f
AC
22054@item watchpoint
22055Normal, explicitly set watchpoint.
c906108c 22056
8e04817f
AC
22057@item longjmp
22058Internal breakpoint, used to handle correctly stepping through
22059@code{longjmp} calls.
c906108c 22060
8e04817f
AC
22061@item longjmp resume
22062Internal breakpoint at the target of a @code{longjmp}.
c906108c 22063
8e04817f
AC
22064@item until
22065Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 22066
8e04817f
AC
22067@item finish
22068Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 22069
8e04817f
AC
22070@item shlib events
22071Shared library events.
c906108c 22072
8e04817f 22073@end table
c906108c 22074
09d4efe1
EZ
22075@kindex maint check-symtabs
22076@item maint check-symtabs
22077Check the consistency of psymtabs and symtabs.
22078
22079@kindex maint cplus first_component
22080@item maint cplus first_component @var{name}
22081Print the first C@t{++} class/namespace component of @var{name}.
22082
22083@kindex maint cplus namespace
22084@item maint cplus namespace
22085Print the list of possible C@t{++} namespaces.
22086
22087@kindex maint demangle
22088@item maint demangle @var{name}
22089Demangle a C@t{++} or Objective-C manled @var{name}.
22090
22091@kindex maint deprecate
22092@kindex maint undeprecate
22093@cindex deprecated commands
22094@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
22095@itemx maint undeprecate @var{command}
22096Deprecate or undeprecate the named @var{command}. Deprecated commands
22097cause @value{GDBN} to issue a warning when you use them. The optional
22098argument @var{replacement} says which newer command should be used in
22099favor of the deprecated one; if it is given, @value{GDBN} will mention
22100the replacement as part of the warning.
22101
22102@kindex maint dump-me
22103@item maint dump-me
721c2651 22104@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 22105Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
22106This is supported only on systems which support aborting a program
22107with the @code{SIGQUIT} signal.
09d4efe1 22108
8d30a00d
AC
22109@kindex maint internal-error
22110@kindex maint internal-warning
09d4efe1
EZ
22111@item maint internal-error @r{[}@var{message-text}@r{]}
22112@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
22113Cause @value{GDBN} to call the internal function @code{internal_error}
22114or @code{internal_warning} and hence behave as though an internal error
22115or internal warning has been detected. In addition to reporting the
22116internal problem, these functions give the user the opportunity to
22117either quit @value{GDBN} or create a core file of the current
22118@value{GDBN} session.
22119
09d4efe1
EZ
22120These commands take an optional parameter @var{message-text} that is
22121used as the text of the error or warning message.
22122
22123Here's an example of using @code{indernal-error}:
22124
8d30a00d 22125@smallexample
f7dc1244 22126(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
22127@dots{}/maint.c:121: internal-error: testing, 1, 2
22128A problem internal to GDB has been detected. Further
22129debugging may prove unreliable.
22130Quit this debugging session? (y or n) @kbd{n}
22131Create a core file? (y or n) @kbd{n}
f7dc1244 22132(@value{GDBP})
8d30a00d
AC
22133@end smallexample
22134
09d4efe1
EZ
22135@kindex maint packet
22136@item maint packet @var{text}
22137If @value{GDBN} is talking to an inferior via the serial protocol,
22138then this command sends the string @var{text} to the inferior, and
22139displays the response packet. @value{GDBN} supplies the initial
22140@samp{$} character, the terminating @samp{#} character, and the
22141checksum.
22142
22143@kindex maint print architecture
22144@item maint print architecture @r{[}@var{file}@r{]}
22145Print the entire architecture configuration. The optional argument
22146@var{file} names the file where the output goes.
8d30a00d 22147
00905d52
AC
22148@kindex maint print dummy-frames
22149@item maint print dummy-frames
00905d52
AC
22150Prints the contents of @value{GDBN}'s internal dummy-frame stack.
22151
22152@smallexample
f7dc1244 22153(@value{GDBP}) @kbd{b add}
00905d52 22154@dots{}
f7dc1244 22155(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
22156Breakpoint 2, add (a=2, b=3) at @dots{}
2215758 return (a + b);
22158The program being debugged stopped while in a function called from GDB.
22159@dots{}
f7dc1244 22160(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
221610x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
22162 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
22163 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 22164(@value{GDBP})
00905d52
AC
22165@end smallexample
22166
22167Takes an optional file parameter.
22168
0680b120
AC
22169@kindex maint print registers
22170@kindex maint print raw-registers
22171@kindex maint print cooked-registers
617073a9 22172@kindex maint print register-groups
09d4efe1
EZ
22173@item maint print registers @r{[}@var{file}@r{]}
22174@itemx maint print raw-registers @r{[}@var{file}@r{]}
22175@itemx maint print cooked-registers @r{[}@var{file}@r{]}
22176@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
22177Print @value{GDBN}'s internal register data structures.
22178
617073a9
AC
22179The command @code{maint print raw-registers} includes the contents of
22180the raw register cache; the command @code{maint print cooked-registers}
22181includes the (cooked) value of all registers; and the command
22182@code{maint print register-groups} includes the groups that each
22183register is a member of. @xref{Registers,, Registers, gdbint,
22184@value{GDBN} Internals}.
0680b120 22185
09d4efe1
EZ
22186These commands take an optional parameter, a file name to which to
22187write the information.
0680b120 22188
617073a9 22189@kindex maint print reggroups
09d4efe1
EZ
22190@item maint print reggroups @r{[}@var{file}@r{]}
22191Print @value{GDBN}'s internal register group data structures. The
22192optional argument @var{file} tells to what file to write the
22193information.
617073a9 22194
09d4efe1 22195The register groups info looks like this:
617073a9
AC
22196
22197@smallexample
f7dc1244 22198(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
22199 Group Type
22200 general user
22201 float user
22202 all user
22203 vector user
22204 system user
22205 save internal
22206 restore internal
617073a9
AC
22207@end smallexample
22208
09d4efe1
EZ
22209@kindex flushregs
22210@item flushregs
22211This command forces @value{GDBN} to flush its internal register cache.
22212
22213@kindex maint print objfiles
22214@cindex info for known object files
22215@item maint print objfiles
22216Print a dump of all known object files. For each object file, this
22217command prints its name, address in memory, and all of its psymtabs
22218and symtabs.
22219
22220@kindex maint print statistics
22221@cindex bcache statistics
22222@item maint print statistics
22223This command prints, for each object file in the program, various data
22224about that object file followed by the byte cache (@dfn{bcache})
22225statistics for the object file. The objfile data includes the number
22226of minimal, partical, full, and stabs symbols, the number of types
22227defined by the objfile, the number of as yet unexpanded psym tables,
22228the number of line tables and string tables, and the amount of memory
22229used by the various tables. The bcache statistics include the counts,
22230sizes, and counts of duplicates of all and unique objects, max,
22231average, and median entry size, total memory used and its overhead and
22232savings, and various measures of the hash table size and chain
22233lengths.
22234
22235@kindex maint print type
22236@cindex type chain of a data type
22237@item maint print type @var{expr}
22238Print the type chain for a type specified by @var{expr}. The argument
22239can be either a type name or a symbol. If it is a symbol, the type of
22240that symbol is described. The type chain produced by this command is
22241a recursive definition of the data type as stored in @value{GDBN}'s
22242data structures, including its flags and contained types.
22243
22244@kindex maint set dwarf2 max-cache-age
22245@kindex maint show dwarf2 max-cache-age
22246@item maint set dwarf2 max-cache-age
22247@itemx maint show dwarf2 max-cache-age
22248Control the DWARF 2 compilation unit cache.
22249
22250@cindex DWARF 2 compilation units cache
22251In object files with inter-compilation-unit references, such as those
22252produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
22253reader needs to frequently refer to previously read compilation units.
22254This setting controls how long a compilation unit will remain in the
22255cache if it is not referenced. A higher limit means that cached
22256compilation units will be stored in memory longer, and more total
22257memory will be used. Setting it to zero disables caching, which will
22258slow down @value{GDBN} startup, but reduce memory consumption.
22259
e7ba9c65
DJ
22260@kindex maint set profile
22261@kindex maint show profile
22262@cindex profiling GDB
22263@item maint set profile
22264@itemx maint show profile
22265Control profiling of @value{GDBN}.
22266
22267Profiling will be disabled until you use the @samp{maint set profile}
22268command to enable it. When you enable profiling, the system will begin
22269collecting timing and execution count data; when you disable profiling or
22270exit @value{GDBN}, the results will be written to a log file. Remember that
22271if you use profiling, @value{GDBN} will overwrite the profiling log file
22272(often called @file{gmon.out}). If you have a record of important profiling
22273data in a @file{gmon.out} file, be sure to move it to a safe location.
22274
22275Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 22276compiled with the @samp{-pg} compiler option.
e7ba9c65 22277
09d4efe1
EZ
22278@kindex maint show-debug-regs
22279@cindex x86 hardware debug registers
22280@item maint show-debug-regs
22281Control whether to show variables that mirror the x86 hardware debug
22282registers. Use @code{ON} to enable, @code{OFF} to disable. If
22283enabled, the debug registers values are shown when GDB inserts or
22284removes a hardware breakpoint or watchpoint, and when the inferior
22285triggers a hardware-assisted breakpoint or watchpoint.
22286
22287@kindex maint space
22288@cindex memory used by commands
22289@item maint space
22290Control whether to display memory usage for each command. If set to a
22291nonzero value, @value{GDBN} will display how much memory each command
22292took, following the command's own output. This can also be requested
22293by invoking @value{GDBN} with the @option{--statistics} command-line
22294switch (@pxref{Mode Options}).
22295
22296@kindex maint time
22297@cindex time of command execution
22298@item maint time
22299Control whether to display the execution time for each command. If
22300set to a nonzero value, @value{GDBN} will display how much time it
22301took to execute each command, following the command's own output.
22302This can also be requested by invoking @value{GDBN} with the
22303@option{--statistics} command-line switch (@pxref{Mode Options}).
22304
22305@kindex maint translate-address
22306@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
22307Find the symbol stored at the location specified by the address
22308@var{addr} and an optional section name @var{section}. If found,
22309@value{GDBN} prints the name of the closest symbol and an offset from
22310the symbol's location to the specified address. This is similar to
22311the @code{info address} command (@pxref{Symbols}), except that this
22312command also allows to find symbols in other sections.
ae038cb0 22313
8e04817f 22314@end table
c906108c 22315
9c16f35a
EZ
22316The following command is useful for non-interactive invocations of
22317@value{GDBN}, such as in the test suite.
22318
22319@table @code
22320@item set watchdog @var{nsec}
22321@kindex set watchdog
22322@cindex watchdog timer
22323@cindex timeout for commands
22324Set the maximum number of seconds @value{GDBN} will wait for the
22325target operation to finish. If this time expires, @value{GDBN}
22326reports and error and the command is aborted.
22327
22328@item show watchdog
22329Show the current setting of the target wait timeout.
22330@end table
c906108c 22331
e0ce93ac 22332@node Remote Protocol
8e04817f 22333@appendix @value{GDBN} Remote Serial Protocol
c906108c 22334
ee2d5c50
AC
22335@menu
22336* Overview::
22337* Packets::
22338* Stop Reply Packets::
22339* General Query Packets::
22340* Register Packet Format::
9d29849a 22341* Tracepoint Packets::
9a6253be 22342* Interrupts::
ee2d5c50 22343* Examples::
0ce1b118 22344* File-I/O remote protocol extension::
ee2d5c50
AC
22345@end menu
22346
22347@node Overview
22348@section Overview
22349
8e04817f
AC
22350There may be occasions when you need to know something about the
22351protocol---for example, if there is only one serial port to your target
22352machine, you might want your program to do something special if it
22353recognizes a packet meant for @value{GDBN}.
c906108c 22354
d2c6833e 22355In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 22356transmitted and received data respectfully.
c906108c 22357
8e04817f
AC
22358@cindex protocol, @value{GDBN} remote serial
22359@cindex serial protocol, @value{GDBN} remote
22360@cindex remote serial protocol
22361All @value{GDBN} commands and responses (other than acknowledgments) are
22362sent as a @var{packet}. A @var{packet} is introduced with the character
22363@samp{$}, the actual @var{packet-data}, and the terminating character
22364@samp{#} followed by a two-digit @var{checksum}:
c906108c 22365
474c8240 22366@smallexample
8e04817f 22367@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 22368@end smallexample
8e04817f 22369@noindent
c906108c 22370
8e04817f
AC
22371@cindex checksum, for @value{GDBN} remote
22372@noindent
22373The two-digit @var{checksum} is computed as the modulo 256 sum of all
22374characters between the leading @samp{$} and the trailing @samp{#} (an
22375eight bit unsigned checksum).
c906108c 22376
8e04817f
AC
22377Implementors should note that prior to @value{GDBN} 5.0 the protocol
22378specification also included an optional two-digit @var{sequence-id}:
c906108c 22379
474c8240 22380@smallexample
8e04817f 22381@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 22382@end smallexample
c906108c 22383
8e04817f
AC
22384@cindex sequence-id, for @value{GDBN} remote
22385@noindent
22386That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
22387has never output @var{sequence-id}s. Stubs that handle packets added
22388since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 22389
8e04817f
AC
22390@cindex acknowledgment, for @value{GDBN} remote
22391When either the host or the target machine receives a packet, the first
22392response expected is an acknowledgment: either @samp{+} (to indicate
22393the package was received correctly) or @samp{-} (to request
22394retransmission):
c906108c 22395
474c8240 22396@smallexample
d2c6833e
AC
22397-> @code{$}@var{packet-data}@code{#}@var{checksum}
22398<- @code{+}
474c8240 22399@end smallexample
8e04817f 22400@noindent
53a5351d 22401
8e04817f
AC
22402The host (@value{GDBN}) sends @var{command}s, and the target (the
22403debugging stub incorporated in your program) sends a @var{response}. In
22404the case of step and continue @var{command}s, the response is only sent
22405when the operation has completed (the target has again stopped).
c906108c 22406
8e04817f
AC
22407@var{packet-data} consists of a sequence of characters with the
22408exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
22409exceptions).
c906108c 22410
8e04817f 22411Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 22412@cindex remote protocol, field separator
8e04817f 22413@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 22414@sc{hex} with leading zeros suppressed.
c906108c 22415
8e04817f
AC
22416Implementors should note that prior to @value{GDBN} 5.0, the character
22417@samp{:} could not appear as the third character in a packet (as it
22418would potentially conflict with the @var{sequence-id}).
c906108c 22419
8e04817f
AC
22420Response @var{data} can be run-length encoded to save space. A @samp{*}
22421means that the next character is an @sc{ascii} encoding giving a repeat count
22422which stands for that many repetitions of the character preceding the
22423@samp{*}. The encoding is @code{n+29}, yielding a printable character
22424where @code{n >=3} (which is where rle starts to win). The printable
22425characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
22426value greater than 126 should not be used.
c906108c 22427
8e04817f 22428So:
474c8240 22429@smallexample
8e04817f 22430"@code{0* }"
474c8240 22431@end smallexample
8e04817f
AC
22432@noindent
22433means the same as "0000".
c906108c 22434
8e04817f
AC
22435The error response returned for some packets includes a two character
22436error number. That number is not well defined.
c906108c 22437
8e04817f
AC
22438For any @var{command} not supported by the stub, an empty response
22439(@samp{$#00}) should be returned. That way it is possible to extend the
22440protocol. A newer @value{GDBN} can tell if a packet is supported based
22441on that response.
c906108c 22442
b383017d
RM
22443A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
22444@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 22445optional.
c906108c 22446
ee2d5c50
AC
22447@node Packets
22448@section Packets
22449
22450The following table provides a complete list of all currently defined
22451@var{command}s and their corresponding response @var{data}.
9c16f35a
EZ
22452@xref{File-I/O remote protocol extension}, for details about the File
22453I/O extension of the remote protocol.
ee2d5c50 22454
b8ff78ce
JB
22455Each packet's description has a template showing the packet's overall
22456syntax, followed by an explanation of the packet's meaning. We
22457include spaces in some of the templates for clarity; these are not
22458part of the packet's syntax. No @value{GDBN} packet uses spaces to
22459separate its components. For example, a template like @samp{foo
22460@var{bar} @var{baz}} describes a packet beginning with the three ASCII
22461bytes @samp{foo}, followed by a @var{bar}, followed directly by a
22462@var{baz}. GDB does not transmit a space character between the
22463@samp{foo} and the @var{bar}, or between the @var{bar} and the
22464@var{baz}.
22465
8ffe2530
JB
22466Note that all packet forms beginning with an upper- or lower-case
22467letter, other than those described here, are reserved for future use.
22468
b8ff78ce 22469Here are the packet descriptions.
ee2d5c50 22470
b8ff78ce 22471@table @samp
ee2d5c50 22472
b8ff78ce
JB
22473@item !
22474@cindex @samp{!} packet
8e04817f
AC
22475Enable extended mode. In extended mode, the remote server is made
22476persistent. The @samp{R} packet is used to restart the program being
22477debugged.
ee2d5c50
AC
22478
22479Reply:
22480@table @samp
22481@item OK
8e04817f 22482The remote target both supports and has enabled extended mode.
ee2d5c50 22483@end table
c906108c 22484
b8ff78ce
JB
22485@item ?
22486@cindex @samp{?} packet
ee2d5c50
AC
22487Indicate the reason the target halted. The reply is the same as for
22488step and continue.
c906108c 22489
ee2d5c50
AC
22490Reply:
22491@xref{Stop Reply Packets}, for the reply specifications.
22492
b8ff78ce
JB
22493@item A @var{arglen},@var{argnum},@var{arg},@dots{}
22494@cindex @samp{A} packet
22495Initialized @code{argv[]} array passed into program. @var{arglen}
22496specifies the number of bytes in the hex encoded byte stream
22497@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
22498
22499Reply:
22500@table @samp
22501@item OK
b8ff78ce
JB
22502The arguments were set.
22503@item E @var{NN}
22504An error occurred.
ee2d5c50
AC
22505@end table
22506
b8ff78ce
JB
22507@item b @var{baud}
22508@cindex @samp{b} packet
22509(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
22510Change the serial line speed to @var{baud}.
22511
22512JTC: @emph{When does the transport layer state change? When it's
22513received, or after the ACK is transmitted. In either case, there are
22514problems if the command or the acknowledgment packet is dropped.}
22515
22516Stan: @emph{If people really wanted to add something like this, and get
22517it working for the first time, they ought to modify ser-unix.c to send
22518some kind of out-of-band message to a specially-setup stub and have the
22519switch happen "in between" packets, so that from remote protocol's point
22520of view, nothing actually happened.}
22521
b8ff78ce
JB
22522@item B @var{addr},@var{mode}
22523@cindex @samp{B} packet
8e04817f 22524Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
22525breakpoint at @var{addr}.
22526
b8ff78ce 22527Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 22528(@pxref{insert breakpoint or watchpoint packet}).
c906108c 22529
b8ff78ce
JB
22530@item c @var{addr}
22531@cindex @samp{c} packet
22532Continue. @var{addr} is address to resume. If @var{addr} is omitted,
22533resume at current address.
c906108c 22534
ee2d5c50
AC
22535Reply:
22536@xref{Stop Reply Packets}, for the reply specifications.
22537
b8ff78ce
JB
22538@item C @var{sig};@var{addr}
22539@cindex @samp{C} packet
8e04817f 22540Continue with signal @var{sig} (hex signal number). If
b8ff78ce 22541@samp{;@var{addr}} is omitted, resume at same address.
c906108c 22542
ee2d5c50
AC
22543Reply:
22544@xref{Stop Reply Packets}, for the reply specifications.
c906108c 22545
b8ff78ce
JB
22546@item d
22547@cindex @samp{d} packet
ee2d5c50
AC
22548Toggle debug flag.
22549
b8ff78ce
JB
22550Don't use this packet; instead, define a general set packet
22551(@pxref{General Query Packets}).
ee2d5c50 22552
b8ff78ce
JB
22553@item D
22554@cindex @samp{D} packet
ee2d5c50 22555Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 22556before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
22557
22558Reply:
22559@table @samp
10fac096
NW
22560@item OK
22561for success
b8ff78ce 22562@item E @var{NN}
10fac096 22563for an error
ee2d5c50 22564@end table
c906108c 22565
b8ff78ce
JB
22566@item F @var{RC},@var{EE},@var{CF};@var{XX}
22567@cindex @samp{F} packet
22568A reply from @value{GDBN} to an @samp{F} packet sent by the target.
22569This is part of the File-I/O protocol extension. @xref{File-I/O
22570remote protocol extension}, for the specification.
ee2d5c50 22571
b8ff78ce 22572@item g
ee2d5c50 22573@anchor{read registers packet}
b8ff78ce 22574@cindex @samp{g} packet
ee2d5c50
AC
22575Read general registers.
22576
22577Reply:
22578@table @samp
22579@item @var{XX@dots{}}
8e04817f
AC
22580Each byte of register data is described by two hex digits. The bytes
22581with the register are transmitted in target byte order. The size of
b8ff78ce 22582each register and their position within the @samp{g} packet are
12c266ea 22583determined by the @value{GDBN} internal macros
b8ff78ce
JB
22584@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{REGISTER_NAME} macros. The
22585specification of several standard @samp{g} packets is specified below.
22586@item E @var{NN}
ee2d5c50
AC
22587for an error.
22588@end table
c906108c 22589
b8ff78ce
JB
22590@item G @var{XX@dots{}}
22591@cindex @samp{G} packet
22592Write general registers. @xref{read registers packet}, for a
22593description of the @var{XX@dots{}} data.
ee2d5c50
AC
22594
22595Reply:
22596@table @samp
22597@item OK
22598for success
b8ff78ce 22599@item E @var{NN}
ee2d5c50
AC
22600for an error
22601@end table
22602
b8ff78ce
JB
22603@item H @var{c} @var{t}
22604@cindex @samp{H} packet
8e04817f 22605Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
22606@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
22607should be @samp{c} for step and continue operations, @samp{g} for other
b8ff78ce
JB
22608operations. The thread designator @var{t} may be @samp{-1}, meaning all
22609the threads, a thread number, or @samp{0} which means pick any thread.
ee2d5c50
AC
22610
22611Reply:
22612@table @samp
22613@item OK
22614for success
b8ff78ce 22615@item E @var{NN}
ee2d5c50
AC
22616for an error
22617@end table
c906108c 22618
8e04817f
AC
22619@c FIXME: JTC:
22620@c 'H': How restrictive (or permissive) is the thread model. If a
22621@c thread is selected and stopped, are other threads allowed
22622@c to continue to execute? As I mentioned above, I think the
22623@c semantics of each command when a thread is selected must be
22624@c described. For example:
22625@c
22626@c 'g': If the stub supports threads and a specific thread is
22627@c selected, returns the register block from that thread;
22628@c otherwise returns current registers.
22629@c
22630@c 'G' If the stub supports threads and a specific thread is
22631@c selected, sets the registers of the register block of
22632@c that thread; otherwise sets current registers.
c906108c 22633
b8ff78ce 22634@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 22635@anchor{cycle step packet}
b8ff78ce
JB
22636@cindex @samp{i} packet
22637Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
22638present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
22639step starting at that address.
c906108c 22640
b8ff78ce
JB
22641@item I
22642@cindex @samp{I} packet
22643Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
22644step packet}.
ee2d5c50 22645
b8ff78ce
JB
22646@item k
22647@cindex @samp{k} packet
22648Kill request.
c906108c 22649
ac282366 22650FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
22651thread context has been selected (i.e.@: does 'k' kill only that
22652thread?)}.
c906108c 22653
b8ff78ce
JB
22654@item m @var{addr},@var{length}
22655@cindex @samp{m} packet
8e04817f 22656Read @var{length} bytes of memory starting at address @var{addr}.
fb031cdf
JB
22657Note that @var{addr} may not be aligned to any particular boundary.
22658
22659The stub need not use any particular size or alignment when gathering
22660data from memory for the response; even if @var{addr} is word-aligned
22661and @var{length} is a multiple of the word size, the stub is free to
22662use byte accesses, or not. For this reason, this packet may not be
22663suitable for accessing memory-mapped I/O devices.
c43c5473
JB
22664@cindex alignment of remote memory accesses
22665@cindex size of remote memory accesses
22666@cindex memory, alignment and size of remote accesses
c906108c 22667
ee2d5c50
AC
22668Reply:
22669@table @samp
22670@item @var{XX@dots{}}
b8ff78ce
JB
22671Memory contents; each byte is transmitted as a two-digit hexidecimal
22672number. The reply may contain fewer bytes than requested if the
22673server was able to read only part of the region of memory.
22674@item E @var{NN}
ee2d5c50
AC
22675@var{NN} is errno
22676@end table
22677
b8ff78ce
JB
22678@item M @var{addr},@var{length}:@var{XX@dots{}}
22679@cindex @samp{M} packet
8e04817f 22680Write @var{length} bytes of memory starting at address @var{addr}.
b8ff78ce
JB
22681@var{XX@dots{}} is the data; each byte is transmitted as a two-digit
22682hexidecimal number.
ee2d5c50
AC
22683
22684Reply:
22685@table @samp
22686@item OK
22687for success
b8ff78ce 22688@item E @var{NN}
8e04817f
AC
22689for an error (this includes the case where only part of the data was
22690written).
ee2d5c50 22691@end table
c906108c 22692
b8ff78ce
JB
22693@item p @var{n}
22694@cindex @samp{p} packet
22695Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
22696@xref{read registers packet}, for a description of how the returned
22697register value is encoded.
ee2d5c50
AC
22698
22699Reply:
22700@table @samp
2e868123
AC
22701@item @var{XX@dots{}}
22702the register's value
b8ff78ce 22703@item E @var{NN}
2e868123
AC
22704for an error
22705@item
22706Indicating an unrecognized @var{query}.
ee2d5c50
AC
22707@end table
22708
b8ff78ce 22709@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 22710@anchor{write register packet}
b8ff78ce
JB
22711@cindex @samp{P} packet
22712Write register @var{n@dots{}} with value @var{r@dots{}}. The register
22713number @var{n} is in hexidecimal, and @var{r@dots{}} contains two hex
8e04817f 22714digits for each byte in the register (target byte order).
c906108c 22715
ee2d5c50
AC
22716Reply:
22717@table @samp
22718@item OK
22719for success
b8ff78ce 22720@item E @var{NN}
ee2d5c50
AC
22721for an error
22722@end table
22723
5f3bebba
JB
22724@item q @var{name} @var{params}@dots{}
22725@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 22726@cindex @samp{q} packet
b8ff78ce 22727@cindex @samp{Q} packet
5f3bebba
JB
22728General query (@samp{q}) and set (@samp{Q}). These packets are
22729described fully in @ref{General Query Packets}.
c906108c 22730
b8ff78ce
JB
22731@item r
22732@cindex @samp{r} packet
8e04817f 22733Reset the entire system.
c906108c 22734
b8ff78ce 22735Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 22736
b8ff78ce
JB
22737@item R @var{XX}
22738@cindex @samp{R} packet
8e04817f
AC
22739Restart the program being debugged. @var{XX}, while needed, is ignored.
22740This packet is only available in extended mode.
ee2d5c50 22741
8e04817f 22742The @samp{R} packet has no reply.
ee2d5c50 22743
b8ff78ce
JB
22744@item s @var{addr}
22745@cindex @samp{s} packet
22746Single step. @var{addr} is the address at which to resume. If
22747@var{addr} is omitted, resume at same address.
c906108c 22748
ee2d5c50
AC
22749Reply:
22750@xref{Stop Reply Packets}, for the reply specifications.
22751
b8ff78ce 22752@item S @var{sig};@var{addr}
ee2d5c50 22753@anchor{step with signal packet}
b8ff78ce
JB
22754@cindex @samp{S} packet
22755Step with signal. This is analogous to the @samp{C} packet, but
22756requests a single-step, rather than a normal resumption of execution.
c906108c 22757
ee2d5c50
AC
22758Reply:
22759@xref{Stop Reply Packets}, for the reply specifications.
22760
b8ff78ce
JB
22761@item t @var{addr}:@var{PP},@var{MM}
22762@cindex @samp{t} packet
8e04817f 22763Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
22764@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
22765@var{addr} must be at least 3 digits.
c906108c 22766
b8ff78ce
JB
22767@item T @var{XX}
22768@cindex @samp{T} packet
ee2d5c50 22769Find out if the thread XX is alive.
c906108c 22770
ee2d5c50
AC
22771Reply:
22772@table @samp
22773@item OK
22774thread is still alive
b8ff78ce 22775@item E @var{NN}
ee2d5c50
AC
22776thread is dead
22777@end table
22778
b8ff78ce
JB
22779@item v
22780Packets starting with @samp{v} are identified by a multi-letter name,
22781up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 22782
b8ff78ce
JB
22783@item vCont@r{[};@var{action}@r{[}:@var{tid}@r{]]}@dots{}
22784@cindex @samp{vCont} packet
22785Resume the inferior, specifying different actions for each thread.
86d30acc
DJ
22786If an action is specified with no @var{tid}, then it is applied to any
22787threads that don't have a specific action specified; if no default action is
22788specified then other threads should remain stopped. Specifying multiple
22789default actions is an error; specifying no actions is also an error.
22790Thread IDs are specified in hexadecimal. Currently supported actions are:
22791
b8ff78ce 22792@table @samp
86d30acc
DJ
22793@item c
22794Continue.
b8ff78ce 22795@item C @var{sig}
86d30acc
DJ
22796Continue with signal @var{sig}. @var{sig} should be two hex digits.
22797@item s
22798Step.
b8ff78ce 22799@item S @var{sig}
86d30acc
DJ
22800Step with signal @var{sig}. @var{sig} should be two hex digits.
22801@end table
22802
22803The optional @var{addr} argument normally associated with these packets is
b8ff78ce 22804not supported in @samp{vCont}.
86d30acc
DJ
22805
22806Reply:
22807@xref{Stop Reply Packets}, for the reply specifications.
22808
b8ff78ce
JB
22809@item vCont?
22810@cindex @samp{vCont?} packet
22811Request a list of actions supporetd by the @samp{vCont} packet.
86d30acc
DJ
22812
22813Reply:
22814@table @samp
b8ff78ce
JB
22815@item vCont@r{[};@var{action}@dots{}@r{]}
22816The @samp{vCont} packet is supported. Each @var{action} is a supported
22817command in the @samp{vCont} packet.
86d30acc 22818@item
b8ff78ce 22819The @samp{vCont} packet is not supported.
86d30acc 22820@end table
ee2d5c50 22821
b8ff78ce 22822@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 22823@anchor{X packet}
b8ff78ce
JB
22824@cindex @samp{X} packet
22825Write data to memory, where the data is transmitted in binary.
22826@var{addr} is address, @var{length} is number of bytes,
22827@samp{@var{XX}@dots{}} is binary data. The bytes @code{0x23}
22828(@sc{ascii} @samp{#}), @code{0x24} (@sc{ascii} @samp{$}), and
22829@code{0x7d} (@sc{ascii} @samp{@}}) are escaped using @code{0x7d}
22830(@sc{ascii} @samp{@}}), and then XORed with @code{0x20}. For example,
22831the byte @code{0x7d} would be transmitted as the two bytes @code{0x7d
228320x5d}.
c906108c 22833
ee2d5c50
AC
22834Reply:
22835@table @samp
22836@item OK
22837for success
b8ff78ce 22838@item E @var{NN}
ee2d5c50
AC
22839for an error
22840@end table
22841
b8ff78ce
JB
22842@item z @var{type},@var{addr},@var{length}
22843@itemx Z @var{type},@var{addr},@var{length}
2f870471 22844@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
22845@cindex @samp{z} packet
22846@cindex @samp{Z} packets
22847Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
2f870471
AC
22848watchpoint starting at address @var{address} and covering the next
22849@var{length} bytes.
ee2d5c50 22850
2f870471
AC
22851Each breakpoint and watchpoint packet @var{type} is documented
22852separately.
22853
512217c7
AC
22854@emph{Implementation notes: A remote target shall return an empty string
22855for an unrecognized breakpoint or watchpoint packet @var{type}. A
22856remote target shall support either both or neither of a given
b8ff78ce 22857@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
22858avoid potential problems with duplicate packets, the operations should
22859be implemented in an idempotent way.}
22860
b8ff78ce
JB
22861@item z0,@var{addr},@var{length}
22862@itemx Z0,@var{addr},@var{length}
22863@cindex @samp{z0} packet
22864@cindex @samp{Z0} packet
22865Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
22866@var{addr} of size @var{length}.
2f870471
AC
22867
22868A memory breakpoint is implemented by replacing the instruction at
22869@var{addr} with a software breakpoint or trap instruction. The
b8ff78ce 22870@var{length} is used by targets that indicates the size of the
2f870471
AC
22871breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
22872@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 22873
2f870471
AC
22874@emph{Implementation note: It is possible for a target to copy or move
22875code that contains memory breakpoints (e.g., when implementing
22876overlays). The behavior of this packet, in the presence of such a
22877target, is not defined.}
c906108c 22878
ee2d5c50
AC
22879Reply:
22880@table @samp
2f870471
AC
22881@item OK
22882success
22883@item
22884not supported
b8ff78ce 22885@item E @var{NN}
ee2d5c50 22886for an error
2f870471
AC
22887@end table
22888
b8ff78ce
JB
22889@item z1,@var{addr},@var{length}
22890@itemx Z1,@var{addr},@var{length}
22891@cindex @samp{z1} packet
22892@cindex @samp{Z1} packet
22893Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
22894address @var{addr} of size @var{length}.
2f870471
AC
22895
22896A hardware breakpoint is implemented using a mechanism that is not
22897dependant on being able to modify the target's memory.
22898
22899@emph{Implementation note: A hardware breakpoint is not affected by code
22900movement.}
22901
22902Reply:
22903@table @samp
ee2d5c50 22904@item OK
2f870471
AC
22905success
22906@item
22907not supported
b8ff78ce 22908@item E @var{NN}
2f870471
AC
22909for an error
22910@end table
22911
b8ff78ce
JB
22912@item z2,@var{addr},@var{length}
22913@itemx Z2,@var{addr},@var{length}
22914@cindex @samp{z2} packet
22915@cindex @samp{Z2} packet
22916Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint.
2f870471
AC
22917
22918Reply:
22919@table @samp
22920@item OK
22921success
22922@item
22923not supported
b8ff78ce 22924@item E @var{NN}
2f870471
AC
22925for an error
22926@end table
22927
b8ff78ce
JB
22928@item z3,@var{addr},@var{length}
22929@itemx Z3,@var{addr},@var{length}
22930@cindex @samp{z3} packet
22931@cindex @samp{Z3} packet
22932Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint.
2f870471
AC
22933
22934Reply:
22935@table @samp
22936@item OK
22937success
22938@item
22939not supported
b8ff78ce 22940@item E @var{NN}
2f870471
AC
22941for an error
22942@end table
22943
b8ff78ce
JB
22944@item z4,@var{addr},@var{length}
22945@itemx Z4,@var{addr},@var{length}
22946@cindex @samp{z4} packet
22947@cindex @samp{Z4} packet
22948Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint.
2f870471
AC
22949
22950Reply:
22951@table @samp
22952@item OK
22953success
22954@item
22955not supported
b8ff78ce 22956@item E @var{NN}
2f870471 22957for an error
ee2d5c50
AC
22958@end table
22959
22960@end table
c906108c 22961
ee2d5c50
AC
22962@node Stop Reply Packets
22963@section Stop Reply Packets
22964@cindex stop reply packets
c906108c 22965
8e04817f
AC
22966The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
22967receive any of the below as a reply. In the case of the @samp{C},
22968@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
b8ff78ce
JB
22969when the target halts. In the below the exact meaning of @dfn{signal
22970number} is poorly defined. In general one of the UNIX signal
22971numbering conventions is used.
c906108c 22972
b8ff78ce
JB
22973As in the description of request packets, we include spaces in the
22974reply templates for clarity; these are not part of the reply packet's
22975syntax. No @value{GDBN} stop reply packet uses spaces to separate its
22976components.
c906108c 22977
b8ff78ce 22978@table @samp
ee2d5c50 22979
b8ff78ce
JB
22980@item S @var{AA}
22981The program received signal number @var{AA} (a two-digit hexidecimal
22982number).
c906108c 22983
b8ff78ce
JB
22984@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
22985@cindex @samp{T} packet reply
22986The program received signal number @var{AA} (a two-digit hexidecimal
22987number). Single-step and breakpoint traps are reported this way. The
22988@samp{@var{n}:@var{r}} pairs give the values of important registers or
22989other information:
22990@enumerate
22991@item
22992If @var{n} is a hexidecimal number, it is a register number, and the
22993corresponding @var{r} gives that register's value. @var{r} is a
22994series of bytes in target byte order, with each byte given by a
22995two-digit hex number.
22996@item
22997If @var{n} is @samp{thread}, then @var{r} is the thread process ID, in
22998hex.
22999@item
23000If @var{n} is @samp{watch}, @samp{rwatch}, or @samp{awatch}, then the
23001packet indicates a watchpoint hit, and @var{r} is the data address, in
23002hex.
23003@item
23004Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
23005and go on to the next; this allows us to extend the protocol in the
23006future.
23007@end enumerate
ee2d5c50 23008
b8ff78ce 23009@item W @var{AA}
8e04817f 23010The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
23011applicable to certain targets.
23012
b8ff78ce 23013@item X @var{AA}
8e04817f 23014The process terminated with signal @var{AA}.
c906108c 23015
b8ff78ce
JB
23016@item O @var{XX}@dots{}
23017@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
23018written as the program's console output. This can happen at any time
23019while the program is running and the debugger should continue to wait
23020for @samp{W}, @samp{T}, etc.
0ce1b118 23021
b8ff78ce 23022@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
23023@var{call-id} is the identifier which says which host system call should
23024be called. This is just the name of the function. Translation into the
23025correct system call is only applicable as it's defined in @value{GDBN}.
23026@xref{File-I/O remote protocol extension}, for a list of implemented
23027system calls.
23028
b8ff78ce
JB
23029@samp{@var{parameter}@dots{}} is a list of parameters as defined for
23030this very system call.
0ce1b118 23031
b8ff78ce
JB
23032The target replies with this packet when it expects @value{GDBN} to
23033call a host system call on behalf of the target. @value{GDBN} replies
23034with an appropriate @samp{F} packet and keeps up waiting for the next
23035reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
23036or @samp{s} action is expected to be continued. @xref{File-I/O remote
23037protocol extension}, for more details.
0ce1b118 23038
ee2d5c50
AC
23039@end table
23040
23041@node General Query Packets
23042@section General Query Packets
9c16f35a 23043@cindex remote query requests
c906108c 23044
5f3bebba
JB
23045Packets starting with @samp{q} are @dfn{general query packets};
23046packets starting with @samp{Q} are @dfn{general set packets}. General
23047query and set packets are a semi-unified form for retrieving and
23048sending information to and from the stub.
23049
23050The initial letter of a query or set packet is followed by a name
23051indicating what sort of thing the packet applies to. For example,
23052@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
23053definitions with the stub. These packet names follow some
23054conventions:
23055
23056@itemize @bullet
23057@item
23058The name must not contain commas, colons or semicolons.
23059@item
23060Most @value{GDBN} query and set packets have a leading upper case
23061letter.
23062@item
23063The names of custom vendor packets should use a company prefix, in
23064lower case, followed by a period. For example, packets designed at
23065the Acme Corporation might begin with @samp{qacme.foo} (for querying
23066foos) or @samp{Qacme.bar} (for setting bars).
23067@end itemize
23068
23069A query or set packet may optionally be followed by a @samp{,} or
23070@samp{;} separated list. Stubs must be careful to match the full
23071packet name, in case packet names have common prefixes.
c906108c 23072
b8ff78ce
JB
23073Like the descriptions of the other packets, each description here
23074has a template showing the packet's overall syntax, followed by an
23075explanation of the packet's meaning. We include spaces in some of the
23076templates for clarity; these are not part of the packet's syntax. No
23077@value{GDBN} packet uses spaces to separate its components.
23078
5f3bebba
JB
23079Here are the currently defined query and set packets:
23080
b8ff78ce 23081@table @samp
c906108c 23082
b8ff78ce 23083@item qC
9c16f35a 23084@cindex current thread, remote request
b8ff78ce 23085@cindex @samp{qC} packet
ee2d5c50
AC
23086Return the current thread id.
23087
23088Reply:
23089@table @samp
b8ff78ce 23090@item QC @var{pid}
e1aac25b 23091Where @var{pid} is an unsigned hexidecimal process id.
b8ff78ce 23092@item @r{(anything else)}
ee2d5c50
AC
23093Any other reply implies the old pid.
23094@end table
23095
b8ff78ce 23096@item qCRC:@var{addr},@var{length}
ff2587ec 23097@cindex CRC of memory block, remote request
b8ff78ce
JB
23098@cindex @samp{qCRC} packet
23099Compute the CRC checksum of a block of memory.
ff2587ec
WZ
23100Reply:
23101@table @samp
b8ff78ce 23102@item E @var{NN}
ff2587ec 23103An error (such as memory fault)
b8ff78ce
JB
23104@item C @var{crc32}
23105The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
23106@end table
23107
b8ff78ce
JB
23108@item qfThreadInfo
23109@itemx qsThreadInfo
9c16f35a 23110@cindex list active threads, remote request
b8ff78ce
JB
23111@cindex @samp{qfThreadInfo} packet
23112@cindex @samp{qsThreadInfo} packet
23113Obtain a list of all active thread ids from the target (OS). Since there
8e04817f
AC
23114may be too many active threads to fit into one reply packet, this query
23115works iteratively: it may require more than one query/reply sequence to
23116obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
23117be the @samp{qfThreadInfo} query; subsequent queries in the
23118sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 23119
b8ff78ce 23120NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
23121
23122Reply:
23123@table @samp
b8ff78ce 23124@item m @var{id}
ee2d5c50 23125A single thread id
b8ff78ce 23126@item m @var{id},@var{id}@dots{}
ee2d5c50 23127a comma-separated list of thread ids
b8ff78ce
JB
23128@item l
23129(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
23130@end table
23131
23132In response to each query, the target will reply with a list of one or
e1aac25b
JB
23133more thread ids, in big-endian unsigned hex, separated by commas.
23134@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce
JB
23135ids (using the @samp{qs} form of the query), until the target responds
23136with @samp{l} (lower-case el, for @dfn{last}).
c906108c 23137
b8ff78ce 23138@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 23139@cindex get thread-local storage address, remote request
b8ff78ce 23140@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
23141Fetch the address associated with thread local storage specified
23142by @var{thread-id}, @var{offset}, and @var{lm}.
23143
23144@var{thread-id} is the (big endian, hex encoded) thread id associated with the
23145thread for which to fetch the TLS address.
23146
23147@var{offset} is the (big endian, hex encoded) offset associated with the
23148thread local variable. (This offset is obtained from the debug
23149information associated with the variable.)
23150
23151@var{lm} is the (big endian, hex encoded) OS/ABI specific encoding of the
23152the load module associated with the thread local storage. For example,
23153a @sc{gnu}/Linux system will pass the link map address of the shared
23154object associated with the thread local storage under consideration.
23155Other operating environments may choose to represent the load module
23156differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
23157
23158Reply:
b8ff78ce
JB
23159@table @samp
23160@item @var{XX}@dots{}
ff2587ec
WZ
23161Hex encoded (big endian) bytes representing the address of the thread
23162local storage requested.
23163
b8ff78ce
JB
23164@item E @var{nn}
23165An error occurred. @var{nn} are hex digits.
ff2587ec 23166
b8ff78ce
JB
23167@item
23168An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
23169@end table
23170
ff2587ec
WZ
23171Use of this request packet is controlled by the @code{set remote
23172get-thread-local-storage-address} command (@pxref{Remote
23173configuration, set remote get-thread-local-storage-address}).
23174
b8ff78ce 23175@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
23176Obtain thread information from RTOS. Where: @var{startflag} (one hex
23177digit) is one to indicate the first query and zero to indicate a
23178subsequent query; @var{threadcount} (two hex digits) is the maximum
23179number of threads the response packet can contain; and @var{nextthread}
23180(eight hex digits), for subsequent queries (@var{startflag} is zero), is
23181returned in the response as @var{argthread}.
ee2d5c50 23182
b8ff78ce 23183Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
23184
23185Reply:
23186@table @samp
b8ff78ce 23187@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
23188Where: @var{count} (two hex digits) is the number of threads being
23189returned; @var{done} (one hex digit) is zero to indicate more threads
23190and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 23191digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
ee2d5c50 23192is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 23193digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 23194@end table
c906108c 23195
b8ff78ce 23196@item qOffsets
9c16f35a 23197@cindex section offsets, remote request
b8ff78ce 23198@cindex @samp{qOffsets} packet
8e04817f
AC
23199Get section offsets that the target used when re-locating the downloaded
23200image. @emph{Note: while a @code{Bss} offset is included in the
23201response, @value{GDBN} ignores this and instead applies the @code{Data}
23202offset to the @code{Bss} section.}
c906108c 23203
ee2d5c50
AC
23204Reply:
23205@table @samp
b8ff78ce 23206@item Text=@var{xxx};Data=@var{yyy};Bss=@var{zzz}
ee2d5c50
AC
23207@end table
23208
b8ff78ce 23209@item qP @var{mode} @var{threadid}
9c16f35a 23210@cindex thread information, remote request
b8ff78ce 23211@cindex @samp{qP} packet
8e04817f
AC
23212Returns information on @var{threadid}. Where: @var{mode} is a hex
23213encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50 23214
b8ff78ce 23215Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 23216
b8ff78ce 23217@item qPart:@var{object}:read:@var{annex}:@var{offset},@var{length}
9c16f35a 23218@cindex read special object, remote request
b8ff78ce 23219@cindex @samp{qPart} packet
649e03f6 23220Read uninterpreted bytes from the target's special data area
b8ff78ce
JB
23221identified by the keyword @var{object}. Request @var{length} bytes
23222starting at @var{offset} bytes into the data. The content and
23223encoding of @var{annex} is specific to the object; it can supply
23224additional details about what data to access.
649e03f6 23225
b8ff78ce
JB
23226Here are the specific requests of this form defined so far. All
23227@samp{qPart:@var{object}:read:@dots{}} requests use the same reply
23228formats, listed below.
649e03f6 23229
b8ff78ce
JB
23230@table @samp
23231@item qPart:auxv:read::@var{offset},@var{length}
721c2651
EZ
23232Access the target's @dfn{auxiliary vector}. @xref{OS Information,
23233auxiliary vector}, and see @ref{Remote configuration,
23234read-aux-vector-packet}. Note @var{annex} must be empty.
649e03f6
RM
23235@end table
23236
23237Reply:
b8ff78ce
JB
23238@table @samp
23239@item OK
649e03f6
RM
23240The @var{offset} in the request is at the end of the data.
23241There is no more data to be read.
23242
b8ff78ce 23243@item @var{XX}@dots{}
649e03f6
RM
23244Hex encoded data bytes read.
23245This may be fewer bytes than the @var{length} in the request.
23246
b8ff78ce 23247@item E00
649e03f6
RM
23248The request was malformed, or @var{annex} was invalid.
23249
b8ff78ce 23250@item E @var{nn}
649e03f6
RM
23251The offset was invalid, or there was an error encountered reading the data.
23252@var{nn} is a hex-encoded @code{errno} value.
23253
b8ff78ce 23254@item
649e03f6
RM
23255An empty reply indicates the @var{object} or @var{annex} string was not
23256recognized by the stub.
23257@end table
23258
b8ff78ce 23259@item qPart:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
9c16f35a 23260@cindex write data into object, remote request
649e03f6 23261Write uninterpreted bytes into the target's special data area
b8ff78ce
JB
23262identified by the keyword @var{object}, starting at @var{offset} bytes
23263into the data. @samp{@var{data}@dots{}} is the hex-encoded data to be
23264written. The content and encoding of @var{annex} is specific to the
23265object; it can supply additional details about what data to access.
649e03f6
RM
23266
23267No requests of this form are presently in use. This specification
23268serves as a placeholder to document the common format that new
23269specific request specifications ought to use.
23270
23271Reply:
b8ff78ce 23272@table @samp
649e03f6
RM
23273@item @var{nn}
23274@var{nn} (hex encoded) is the number of bytes written.
23275This may be fewer bytes than supplied in the request.
23276
b8ff78ce 23277@item E00
649e03f6
RM
23278The request was malformed, or @var{annex} was invalid.
23279
b8ff78ce 23280@item E @var{nn}
649e03f6
RM
23281The offset was invalid, or there was an error encountered writing the data.
23282@var{nn} is a hex-encoded @code{errno} value.
23283
b8ff78ce 23284@item
649e03f6
RM
23285An empty reply indicates the @var{object} or @var{annex} string was not
23286recognized by the stub, or that the object does not support writing.
23287@end table
23288
b8ff78ce 23289@item qPart:@var{object}:@var{operation}:@dots{}
649e03f6
RM
23290Requests of this form may be added in the future. When a stub does
23291not recognize the @var{object} keyword, or its support for
b8ff78ce
JB
23292@var{object} does not recognize the @var{operation} keyword, the stub
23293must respond with an empty packet.
83761cbd 23294
b8ff78ce 23295@item qRcmd,@var{command}
ff2587ec 23296@cindex execute remote command, remote request
b8ff78ce 23297@cindex @samp{qRcmd} packet
ff2587ec 23298@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
23299execution. Invalid commands should be reported using the output
23300string. Before the final result packet, the target may also respond
23301with a number of intermediate @samp{O@var{output}} console output
23302packets. @emph{Implementors should note that providing access to a
23303stubs's interpreter may have security implications}.
fa93a9d8 23304
ff2587ec
WZ
23305Reply:
23306@table @samp
23307@item OK
23308A command response with no output.
23309@item @var{OUTPUT}
23310A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 23311@item E @var{NN}
ff2587ec 23312Indicate a badly formed request.
b8ff78ce
JB
23313@item
23314An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 23315@end table
fa93a9d8 23316
b8ff78ce 23317@item qSymbol::
ff2587ec 23318@cindex symbol lookup, remote request
b8ff78ce 23319@cindex @samp{qSymbol} packet
ff2587ec
WZ
23320Notify the target that @value{GDBN} is prepared to serve symbol lookup
23321requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
23322
23323Reply:
ff2587ec 23324@table @samp
b8ff78ce 23325@item OK
ff2587ec 23326The target does not need to look up any (more) symbols.
b8ff78ce 23327@item qSymbol:@var{sym_name}
ff2587ec
WZ
23328The target requests the value of symbol @var{sym_name} (hex encoded).
23329@value{GDBN} may provide the value by using the
b8ff78ce
JB
23330@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
23331below.
ff2587ec 23332@end table
83761cbd 23333
b8ff78ce 23334@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
23335Set the value of @var{sym_name} to @var{sym_value}.
23336
23337@var{sym_name} (hex encoded) is the name of a symbol whose value the
23338target has previously requested.
23339
23340@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
23341@value{GDBN} cannot supply a value for @var{sym_name}, then this field
23342will be empty.
23343
23344Reply:
23345@table @samp
b8ff78ce 23346@item OK
ff2587ec 23347The target does not need to look up any (more) symbols.
b8ff78ce 23348@item qSymbol:@var{sym_name}
ff2587ec
WZ
23349The target requests the value of a new symbol @var{sym_name} (hex
23350encoded). @value{GDBN} will continue to supply the values of symbols
23351(if available), until the target ceases to request them.
fa93a9d8 23352@end table
0abb7bc7 23353
9d29849a
JB
23354@item QTDP
23355@itemx QTFrame
23356@xref{Tracepoint Packets}.
23357
b8ff78ce 23358@item qThreadExtraInfo,@var{id}
ff2587ec 23359@cindex thread attributes info, remote request
b8ff78ce
JB
23360@cindex @samp{qThreadExtraInfo} packet
23361Obtain a printable string description of a thread's attributes from
23362the target OS. @var{id} is a thread-id in big-endian hex. This
23363string may contain anything that the target OS thinks is interesting
23364for @value{GDBN} to tell the user about the thread. The string is
23365displayed in @value{GDBN}'s @code{info threads} display. Some
23366examples of possible thread extra info strings are @samp{Runnable}, or
23367@samp{Blocked on Mutex}.
ff2587ec
WZ
23368
23369Reply:
23370@table @samp
b8ff78ce
JB
23371@item @var{XX}@dots{}
23372Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
23373comprising the printable string containing the extra information about
23374the thread's attributes.
ff2587ec 23375@end table
814e32d7 23376
9d29849a
JB
23377@item QTStart
23378@itemx QTStop
23379@itemx QTinit
23380@itemx QTro
23381@itemx qTStatus
23382@xref{Tracepoint Packets}.
23383
ee2d5c50
AC
23384@end table
23385
23386@node Register Packet Format
23387@section Register Packet Format
eb12ee30 23388
b8ff78ce 23389The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
23390In the below, some thirty-two bit registers are transferred as
23391sixty-four bits. Those registers should be zero/sign extended (which?)
23392to fill the space allocated. Register bytes are transfered in target
23393byte order. The two nibbles within a register byte are transfered
23394most-significant - least-significant.
eb12ee30 23395
ee2d5c50 23396@table @r
eb12ee30 23397
8e04817f 23398@item MIPS32
ee2d5c50 23399
8e04817f
AC
23400All registers are transfered as thirty-two bit quantities in the order:
2340132 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
23402registers; fsr; fir; fp.
eb12ee30 23403
8e04817f 23404@item MIPS64
ee2d5c50 23405
8e04817f
AC
23406All registers are transfered as sixty-four bit quantities (including
23407thirty-two bit registers such as @code{sr}). The ordering is the same
23408as @code{MIPS32}.
eb12ee30 23409
ee2d5c50
AC
23410@end table
23411
9d29849a
JB
23412@node Tracepoint Packets
23413@section Tracepoint Packets
23414@cindex tracepoint packets
23415@cindex packets, tracepoint
23416
23417Here we describe the packets @value{GDBN} uses to implement
23418tracepoints (@pxref{Tracepoints}).
23419
23420@table @samp
23421
23422@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}@r{[}-@r{]}
23423Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
23424is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
23425the tracepoint is disabled. @var{step} is the tracepoint's step
23426count, and @var{pass} is its pass count. If the trailing @samp{-} is
23427present, further @samp{QTDP} packets will follow to specify this
23428tracepoint's actions.
23429
23430Replies:
23431@table @samp
23432@item OK
23433The packet was understood and carried out.
23434@item
23435The packet was not recognized.
23436@end table
23437
23438@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
23439Define actions to be taken when a tracepoint is hit. @var{n} and
23440@var{addr} must be the same as in the initial @samp{QTDP} packet for
23441this tracepoint. This packet may only be sent immediately after
23442another @samp{QTDP} packet that ended with a @samp{-}. If the
23443trailing @samp{-} is present, further @samp{QTDP} packets will follow,
23444specifying more actions for this tracepoint.
23445
23446In the series of action packets for a given tracepoint, at most one
23447can have an @samp{S} before its first @var{action}. If such a packet
23448is sent, it and the following packets define ``while-stepping''
23449actions. Any prior packets define ordinary actions --- that is, those
23450taken when the tracepoint is first hit. If no action packet has an
23451@samp{S}, then all the packets in the series specify ordinary
23452tracepoint actions.
23453
23454The @samp{@var{action}@dots{}} portion of the packet is a series of
23455actions, concatenated without separators. Each action has one of the
23456following forms:
23457
23458@table @samp
23459
23460@item R @var{mask}
23461Collect the registers whose bits are set in @var{mask}. @var{mask} is
23462a hexidecimal number whose @var{i}'th bit is set if register number
23463@var{i} should be collected. (The least significant bit is numbered
23464zero.) Note that @var{mask} may be any number of digits long; it may
23465not fit in a 32-bit word.
23466
23467@item M @var{basereg},@var{offset},@var{len}
23468Collect @var{len} bytes of memory starting at the address in register
23469number @var{basereg}, plus @var{offset}. If @var{basereg} is
23470@samp{-1}, then the range has a fixed address: @var{offset} is the
23471address of the lowest byte to collect. The @var{basereg},
23472@var{offset}, and @var{len} parameters are all unsigned hexidecimal
23473values (the @samp{-1} value for @var{basereg} is a special case).
23474
23475@item X @var{len},@var{expr}
23476Evaluate @var{expr}, whose length is @var{len}, and collect memory as
23477it directs. @var{expr} is an agent expression, as described in
23478@ref{Agent Expressions}. Each byte of the expression is encoded as a
23479two-digit hex number in the packet; @var{len} is the number of bytes
23480in the expression (and thus one-half the number of hex digits in the
23481packet).
23482
23483@end table
23484
23485Any number of actions may be packed together in a single @samp{QTDP}
23486packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
23487length (400 bytes, for many stubs). There may be only one @samp{R}
23488action per tracepoint, and it must precede any @samp{M} or @samp{X}
23489actions. Any registers referred to by @samp{M} and @samp{X} actions
23490must be collected by a preceding @samp{R} action. (The
23491``while-stepping'' actions are treated as if they were attached to a
23492separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
23493
23494Replies:
23495@table @samp
23496@item OK
23497The packet was understood and carried out.
23498@item
23499The packet was not recognized.
23500@end table
23501
23502@item QTFrame:@var{n}
23503Select the @var{n}'th tracepoint frame from the buffer, and use the
23504register and memory contents recorded there to answer subsequent
23505request packets from @value{GDBN}.
23506
23507A successful reply from the stub indicates that the stub has found the
23508requested frame. The response is a series of parts, concatenated
23509without separators, describing the frame we selected. Each part has
23510one of the following forms:
23511
23512@table @samp
23513@item F @var{f}
23514The selected frame is number @var{n} in the trace frame buffer;
23515@var{f} is a hexidecimal number. If @var{f} is @samp{-1}, then there
23516was no frame matching the criteria in the request packet.
23517
23518@item T @var{t}
23519The selected trace frame records a hit of tracepoint number @var{t};
23520@var{t} is a hexidecimal number.
23521
23522@end table
23523
23524@item QTFrame:pc:@var{addr}
23525Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
23526currently selected frame whose PC is @var{addr};
23527@var{addr} is a hexidecimal number.
23528
23529@item QTFrame:tdp:@var{t}
23530Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
23531currently selected frame that is a hit of tracepoint @var{t}; @var{t}
23532is a hexidecimal number.
23533
23534@item QTFrame:range:@var{start}:@var{end}
23535Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
23536currently selected frame whose PC is between @var{start} (inclusive)
23537and @var{end} (exclusive); @var{start} and @var{end} are hexidecimal
23538numbers.
23539
23540@item QTFrame:outside:@var{start}:@var{end}
23541Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
23542frame @emph{outside} the given range of addresses.
23543
23544@item QTStart
23545Begin the tracepoint experiment. Begin collecting data from tracepoint
23546hits in the trace frame buffer.
23547
23548@item QTStop
23549End the tracepoint experiment. Stop collecting trace frames.
23550
23551@item QTinit
23552Clear the table of tracepoints, and empty the trace frame buffer.
23553
23554@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
23555Establish the given ranges of memory as ``transparent''. The stub
23556will answer requests for these ranges from memory's current contents,
23557if they were not collected as part of the tracepoint hit.
23558
23559@value{GDBN} uses this to mark read-only regions of memory, like those
23560containing program code. Since these areas never change, they should
23561still have the same contents they did when the tracepoint was hit, so
23562there's no reason for the stub to refuse to provide their contents.
23563
23564@item qTStatus
23565Ask the stub if there is a trace experiment running right now.
23566
23567Replies:
23568@table @samp
23569@item T0
23570There is no trace experiment running.
23571@item T1
23572There is a trace experiment running.
23573@end table
23574
23575@end table
23576
23577
9a6253be
KB
23578@node Interrupts
23579@section Interrupts
23580@cindex interrupts (remote protocol)
23581
23582When a program on the remote target is running, @value{GDBN} may
23583attempt to interrupt it by sending a @samp{Ctrl-C} or a @code{BREAK},
23584control of which is specified via @value{GDBN}'s @samp{remotebreak}
23585setting (@pxref{set remotebreak}).
23586
23587The precise meaning of @code{BREAK} is defined by the transport
23588mechanism and may, in fact, be undefined. @value{GDBN} does
23589not currently define a @code{BREAK} mechanism for any of the network
23590interfaces.
23591
23592@samp{Ctrl-C}, on the other hand, is defined and implemented for all
23593transport mechanisms. It is represented by sending the single byte
23594@code{0x03} without any of the usual packet overhead described in
23595the Overview section (@pxref{Overview}). When a @code{0x03} byte is
23596transmitted as part of a packet, it is considered to be packet data
23597and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
23598(@pxref{X packet}, used for binary downloads, may include an unescaped
23599@code{0x03} as part of its packet.
23600
23601Stubs are not required to recognize these interrupt mechanisms and the
23602precise meaning associated with receipt of the interrupt is
23603implementation defined. If the stub is successful at interrupting the
23604running program, it is expected that it will send one of the Stop
23605Reply Packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
23606of successfully stopping the program. Interrupts received while the
23607program is stopped will be discarded.
23608
ee2d5c50
AC
23609@node Examples
23610@section Examples
eb12ee30 23611
8e04817f
AC
23612Example sequence of a target being re-started. Notice how the restart
23613does not get any direct output:
eb12ee30 23614
474c8240 23615@smallexample
d2c6833e
AC
23616-> @code{R00}
23617<- @code{+}
8e04817f 23618@emph{target restarts}
d2c6833e 23619-> @code{?}
8e04817f 23620<- @code{+}
d2c6833e
AC
23621<- @code{T001:1234123412341234}
23622-> @code{+}
474c8240 23623@end smallexample
eb12ee30 23624
8e04817f 23625Example sequence of a target being stepped by a single instruction:
eb12ee30 23626
474c8240 23627@smallexample
d2c6833e 23628-> @code{G1445@dots{}}
8e04817f 23629<- @code{+}
d2c6833e
AC
23630-> @code{s}
23631<- @code{+}
23632@emph{time passes}
23633<- @code{T001:1234123412341234}
8e04817f 23634-> @code{+}
d2c6833e 23635-> @code{g}
8e04817f 23636<- @code{+}
d2c6833e
AC
23637<- @code{1455@dots{}}
23638-> @code{+}
474c8240 23639@end smallexample
eb12ee30 23640
0ce1b118
CV
23641@node File-I/O remote protocol extension
23642@section File-I/O remote protocol extension
23643@cindex File-I/O remote protocol extension
23644
23645@menu
23646* File-I/O Overview::
23647* Protocol basics::
1d8b2f28
JB
23648* The F request packet::
23649* The F reply packet::
0ce1b118
CV
23650* Memory transfer::
23651* The Ctrl-C message::
23652* Console I/O::
23653* The isatty call::
23654* The system call::
23655* List of supported calls::
23656* Protocol specific representation of datatypes::
23657* Constants::
23658* File-I/O Examples::
23659@end menu
23660
23661@node File-I/O Overview
23662@subsection File-I/O Overview
23663@cindex file-i/o overview
23664
9c16f35a
EZ
23665The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
23666target to use the host's file system and console I/O when calling various
0ce1b118
CV
23667system calls. System calls on the target system are translated into a
23668remote protocol packet to the host system which then performs the needed
23669actions and returns with an adequate response packet to the target system.
23670This simulates file system operations even on targets that lack file systems.
23671
23672The protocol is defined host- and target-system independent. It uses
9c16f35a 23673its own independent representation of datatypes and values. Both,
0ce1b118
CV
23674@value{GDBN} and the target's @value{GDBN} stub are responsible for
23675translating the system dependent values into the unified protocol values
23676when data is transmitted.
23677
23678The communication is synchronous. A system call is possible only
23679when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
23680packets. While @value{GDBN} handles the request for a system call,
23681the target is stopped to allow deterministic access to the target's
23682memory. Therefore File-I/O is not interuptible by target signals. It
23683is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
23684
23685The target's request to perform a host system call does not finish
23686the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
23687after finishing the system call, the target returns to continuing the
23688previous activity (continue, step). No additional continue or step
23689request from @value{GDBN} is required.
23690
23691@smallexample
f7dc1244 23692(@value{GDBP}) continue
0ce1b118
CV
23693 <- target requests 'system call X'
23694 target is stopped, @value{GDBN} executes system call
23695 -> GDB returns result
23696 ... target continues, GDB returns to wait for the target
23697 <- target hits breakpoint and sends a Txx packet
23698@end smallexample
23699
23700The protocol is only used for files on the host file system and
23701for I/O on the console. Character or block special devices, pipes,
23702named pipes or sockets or any other communication method on the host
23703system are not supported by this protocol.
23704
23705@node Protocol basics
23706@subsection Protocol basics
23707@cindex protocol basics, file-i/o
23708
23709The File-I/O protocol uses the @code{F} packet, as request as well
23710as as reply packet. Since a File-I/O system call can only occur when
b383017d 23711@value{GDBN} is waiting for the continuing or stepping target, the
0ce1b118
CV
23712File-I/O request is a reply that @value{GDBN} has to expect as a result
23713of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
23714This @code{F} packet contains all information needed to allow @value{GDBN}
23715to call the appropriate host system call:
23716
23717@itemize @bullet
b383017d 23718@item
0ce1b118
CV
23719A unique identifier for the requested system call.
23720
23721@item
23722All parameters to the system call. Pointers are given as addresses
23723in the target memory address space. Pointers to strings are given as
b383017d 23724pointer/length pair. Numerical values are given as they are.
0ce1b118
CV
23725Numerical control values are given in a protocol specific representation.
23726
23727@end itemize
23728
23729At that point @value{GDBN} has to perform the following actions.
23730
23731@itemize @bullet
b383017d 23732@item
0ce1b118
CV
23733If parameter pointer values are given, which point to data needed as input
23734to a system call, @value{GDBN} requests this data from the target with a
23735standard @code{m} packet request. This additional communication has to be
23736expected by the target implementation and is handled as any other @code{m}
23737packet.
23738
23739@item
23740@value{GDBN} translates all value from protocol representation to host
23741representation as needed. Datatypes are coerced into the host types.
23742
23743@item
23744@value{GDBN} calls the system call
23745
23746@item
23747It then coerces datatypes back to protocol representation.
23748
23749@item
23750If pointer parameters in the request packet point to buffer space in which
23751a system call is expected to copy data to, the data is transmitted to the
23752target using a @code{M} or @code{X} packet. This packet has to be expected
23753by the target implementation and is handled as any other @code{M} or @code{X}
23754packet.
23755
23756@end itemize
23757
23758Eventually @value{GDBN} replies with another @code{F} packet which contains all
23759necessary information for the target to continue. This at least contains
23760
23761@itemize @bullet
23762@item
23763Return value.
23764
23765@item
23766@code{errno}, if has been changed by the system call.
23767
23768@item
23769``Ctrl-C'' flag.
23770
23771@end itemize
23772
23773After having done the needed type and value coercion, the target continues
23774the latest continue or step action.
23775
1d8b2f28 23776@node The F request packet
0ce1b118
CV
23777@subsection The @code{F} request packet
23778@cindex file-i/o request packet
23779@cindex @code{F} request packet
23780
23781The @code{F} request packet has the following format:
23782
23783@table @samp
23784
23785@smallexample
23786@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
23787@end smallexample
23788
23789@var{call-id} is the identifier to indicate the host system call to be called.
23790This is just the name of the function.
23791
23792@var{parameter@dots{}} are the parameters to the system call.
23793
b383017d 23794@end table
0ce1b118
CV
23795
23796Parameters are hexadecimal integer values, either the real values in case
23797of scalar datatypes, as pointers to target buffer space in case of compound
23798datatypes and unspecified memory areas or as pointer/length pairs in case
23799of string parameters. These are appended to the call-id, each separated
23800from its predecessor by a comma. All values are transmitted in ASCII
23801string representation, pointer/length pairs separated by a slash.
23802
1d8b2f28 23803@node The F reply packet
0ce1b118
CV
23804@subsection The @code{F} reply packet
23805@cindex file-i/o reply packet
23806@cindex @code{F} reply packet
23807
23808The @code{F} reply packet has the following format:
23809
23810@table @samp
23811
23812@smallexample
23813@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
23814@end smallexample
23815
23816@var{retcode} is the return code of the system call as hexadecimal value.
23817
23818@var{errno} is the errno set by the call, in protocol specific representation.
23819This parameter can be omitted if the call was successful.
23820
23821@var{Ctrl-C flag} is only send if the user requested a break. In this
23822case, @var{errno} must be send as well, even if the call was successful.
23823The @var{Ctrl-C flag} itself consists of the character 'C':
23824
23825@smallexample
23826F0,0,C
23827@end smallexample
23828
23829@noindent
23830or, if the call was interupted before the host call has been performed:
23831
23832@smallexample
23833F-1,4,C
23834@end smallexample
23835
23836@noindent
23837assuming 4 is the protocol specific representation of @code{EINTR}.
23838
23839@end table
23840
23841@node Memory transfer
23842@subsection Memory transfer
23843@cindex memory transfer, in file-i/o protocol
23844
23845Structured data which is transferred using a memory read or write as e.g.@:
23846a @code{struct stat} is expected to be in a protocol specific format with
23847all scalar multibyte datatypes being big endian. This should be done by
23848the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
23849it transfers memory to the target. Transferred pointers to structured
23850data should point to the already coerced data at any time.
23851
23852@node The Ctrl-C message
23853@subsection The Ctrl-C message
23854@cindex ctrl-c message, in file-i/o protocol
23855
23856A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
23857reply packet. In this case the target should behave, as if it had
23858gotten a break message. The meaning for the target is ``system call
23859interupted by @code{SIGINT}''. Consequentially, the target should actually stop
23860(as with a break message) and return to @value{GDBN} with a @code{T02}
b383017d 23861packet. In this case, it's important for the target to know, in which
0ce1b118
CV
23862state the system call was interrupted. Since this action is by design
23863not an atomic operation, we have to differ between two cases:
23864
23865@itemize @bullet
23866@item
23867The system call hasn't been performed on the host yet.
23868
23869@item
23870The system call on the host has been finished.
23871
23872@end itemize
23873
23874These two states can be distinguished by the target by the value of the
23875returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
23876call hasn't been performed. This is equivalent to the @code{EINTR} handling
23877on POSIX systems. In any other case, the target may presume that the
23878system call has been finished --- successful or not --- and should behave
23879as if the break message arrived right after the system call.
23880
23881@value{GDBN} must behave reliable. If the system call has not been called
23882yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
23883@code{errno} in the packet. If the system call on the host has been finished
23884before the user requests a break, the full action must be finshed by
23885@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
23886The @code{F} packet may only be send when either nothing has happened
23887or the full action has been completed.
23888
23889@node Console I/O
23890@subsection Console I/O
23891@cindex console i/o as part of file-i/o
23892
23893By default and if not explicitely closed by the target system, the file
23894descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
23895on the @value{GDBN} console is handled as any other file output operation
23896(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
23897by @value{GDBN} so that after the target read request from file descriptor
238980 all following typing is buffered until either one of the following
23899conditions is met:
23900
23901@itemize @bullet
23902@item
23903The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
23904@code{read}
23905system call is treated as finished.
23906
23907@item
23908The user presses @kbd{Enter}. This is treated as end of input with a trailing
23909line feed.
23910
23911@item
23912The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
23913character, especially no Ctrl-D is appended to the input.
23914
23915@end itemize
23916
23917If the user has typed more characters as fit in the buffer given to
23918the read call, the trailing characters are buffered in @value{GDBN} until
23919either another @code{read(0, @dots{})} is requested by the target or debugging
23920is stopped on users request.
23921
23922@node The isatty call
2eecc4ab 23923@subsection The @samp{isatty} function call
0ce1b118
CV
23924@cindex isatty call, file-i/o protocol
23925
23926A special case in this protocol is the library call @code{isatty} which
9c16f35a 23927is implemented as its own call inside of this protocol. It returns
0ce1b118
CV
239281 to the target if the file descriptor given as parameter is attached
23929to the @value{GDBN} console, 0 otherwise. Implementing through system calls
23930would require implementing @code{ioctl} and would be more complex than
23931needed.
23932
23933@node The system call
2eecc4ab 23934@subsection The @samp{system} function call
0ce1b118
CV
23935@cindex system call, file-i/o protocol
23936
23937The other special case in this protocol is the @code{system} call which
9c16f35a 23938is implemented as its own call, too. @value{GDBN} is taking over the full
0ce1b118
CV
23939task of calling the necessary host calls to perform the @code{system}
23940call. The return value of @code{system} is simplified before it's returned
23941to the target. Basically, the only signal transmitted back is @code{EINTR}
23942in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
23943entirely of the exit status of the called command.
23944
9c16f35a
EZ
23945Due to security concerns, the @code{system} call is by default refused
23946by @value{GDBN}. The user has to allow this call explicitly with the
23947@kbd{set remote system-call-allowed 1} command.
0ce1b118 23948
9c16f35a
EZ
23949@table @code
23950@item set remote system-call-allowed
23951@kindex set remote system-call-allowed
23952Control whether to allow the @code{system} calls in the File I/O
23953protocol for the remote target. The default is zero (disabled).
0ce1b118 23954
9c16f35a 23955@item show remote system-call-allowed
0ce1b118 23956@kindex show remote system-call-allowed
9c16f35a
EZ
23957Show the current setting of system calls for the remote File I/O
23958protocol.
0ce1b118
CV
23959@end table
23960
23961@node List of supported calls
23962@subsection List of supported calls
23963@cindex list of supported file-i/o calls
23964
23965@menu
23966* open::
23967* close::
23968* read::
23969* write::
23970* lseek::
23971* rename::
23972* unlink::
23973* stat/fstat::
23974* gettimeofday::
23975* isatty::
23976* system::
23977@end menu
23978
23979@node open
23980@unnumberedsubsubsec open
23981@cindex open, file-i/o system call
23982
23983@smallexample
23984@exdent Synopsis:
23985int open(const char *pathname, int flags);
23986int open(const char *pathname, int flags, mode_t mode);
23987
b383017d 23988@exdent Request:
0ce1b118
CV
23989Fopen,pathptr/len,flags,mode
23990@end smallexample
23991
23992@noindent
23993@code{flags} is the bitwise or of the following values:
23994
23995@table @code
b383017d 23996@item O_CREAT
0ce1b118
CV
23997If the file does not exist it will be created. The host
23998rules apply as far as file ownership and time stamps
23999are concerned.
24000
b383017d 24001@item O_EXCL
0ce1b118
CV
24002When used with O_CREAT, if the file already exists it is
24003an error and open() fails.
24004
b383017d 24005@item O_TRUNC
0ce1b118
CV
24006If the file already exists and the open mode allows
24007writing (O_RDWR or O_WRONLY is given) it will be
24008truncated to length 0.
24009
b383017d 24010@item O_APPEND
0ce1b118
CV
24011The file is opened in append mode.
24012
b383017d 24013@item O_RDONLY
0ce1b118
CV
24014The file is opened for reading only.
24015
b383017d 24016@item O_WRONLY
0ce1b118
CV
24017The file is opened for writing only.
24018
b383017d 24019@item O_RDWR
0ce1b118
CV
24020The file is opened for reading and writing.
24021
24022@noindent
24023Each other bit is silently ignored.
24024
24025@end table
24026
24027@noindent
24028@code{mode} is the bitwise or of the following values:
24029
24030@table @code
b383017d 24031@item S_IRUSR
0ce1b118
CV
24032User has read permission.
24033
b383017d 24034@item S_IWUSR
0ce1b118
CV
24035User has write permission.
24036
b383017d 24037@item S_IRGRP
0ce1b118
CV
24038Group has read permission.
24039
b383017d 24040@item S_IWGRP
0ce1b118
CV
24041Group has write permission.
24042
b383017d 24043@item S_IROTH
0ce1b118
CV
24044Others have read permission.
24045
b383017d 24046@item S_IWOTH
0ce1b118
CV
24047Others have write permission.
24048
24049@noindent
24050Each other bit is silently ignored.
24051
24052@end table
24053
24054@smallexample
24055@exdent Return value:
24056open returns the new file descriptor or -1 if an error
24057occured.
24058
24059@exdent Errors:
24060@end smallexample
24061
24062@table @code
b383017d 24063@item EEXIST
0ce1b118
CV
24064pathname already exists and O_CREAT and O_EXCL were used.
24065
b383017d 24066@item EISDIR
0ce1b118
CV
24067pathname refers to a directory.
24068
b383017d 24069@item EACCES
0ce1b118
CV
24070The requested access is not allowed.
24071
24072@item ENAMETOOLONG
24073pathname was too long.
24074
b383017d 24075@item ENOENT
0ce1b118
CV
24076A directory component in pathname does not exist.
24077
b383017d 24078@item ENODEV
0ce1b118
CV
24079pathname refers to a device, pipe, named pipe or socket.
24080
b383017d 24081@item EROFS
0ce1b118
CV
24082pathname refers to a file on a read-only filesystem and
24083write access was requested.
24084
b383017d 24085@item EFAULT
0ce1b118
CV
24086pathname is an invalid pointer value.
24087
b383017d 24088@item ENOSPC
0ce1b118
CV
24089No space on device to create the file.
24090
b383017d 24091@item EMFILE
0ce1b118
CV
24092The process already has the maximum number of files open.
24093
b383017d 24094@item ENFILE
0ce1b118
CV
24095The limit on the total number of files open on the system
24096has been reached.
24097
b383017d 24098@item EINTR
0ce1b118
CV
24099The call was interrupted by the user.
24100@end table
24101
24102@node close
24103@unnumberedsubsubsec close
24104@cindex close, file-i/o system call
24105
24106@smallexample
b383017d 24107@exdent Synopsis:
0ce1b118
CV
24108int close(int fd);
24109
b383017d 24110@exdent Request:
0ce1b118
CV
24111Fclose,fd
24112
24113@exdent Return value:
24114close returns zero on success, or -1 if an error occurred.
24115
24116@exdent Errors:
24117@end smallexample
24118
24119@table @code
b383017d 24120@item EBADF
0ce1b118
CV
24121fd isn't a valid open file descriptor.
24122
b383017d 24123@item EINTR
0ce1b118
CV
24124The call was interrupted by the user.
24125@end table
24126
24127@node read
24128@unnumberedsubsubsec read
24129@cindex read, file-i/o system call
24130
24131@smallexample
b383017d 24132@exdent Synopsis:
0ce1b118
CV
24133int read(int fd, void *buf, unsigned int count);
24134
b383017d 24135@exdent Request:
0ce1b118
CV
24136Fread,fd,bufptr,count
24137
24138@exdent Return value:
24139On success, the number of bytes read is returned.
24140Zero indicates end of file. If count is zero, read
b383017d 24141returns zero as well. On error, -1 is returned.
0ce1b118
CV
24142
24143@exdent Errors:
24144@end smallexample
24145
24146@table @code
b383017d 24147@item EBADF
0ce1b118
CV
24148fd is not a valid file descriptor or is not open for
24149reading.
24150
b383017d 24151@item EFAULT
0ce1b118
CV
24152buf is an invalid pointer value.
24153
b383017d 24154@item EINTR
0ce1b118
CV
24155The call was interrupted by the user.
24156@end table
24157
24158@node write
24159@unnumberedsubsubsec write
24160@cindex write, file-i/o system call
24161
24162@smallexample
b383017d 24163@exdent Synopsis:
0ce1b118
CV
24164int write(int fd, const void *buf, unsigned int count);
24165
b383017d 24166@exdent Request:
0ce1b118
CV
24167Fwrite,fd,bufptr,count
24168
24169@exdent Return value:
24170On success, the number of bytes written are returned.
24171Zero indicates nothing was written. On error, -1
24172is returned.
24173
24174@exdent Errors:
24175@end smallexample
24176
24177@table @code
b383017d 24178@item EBADF
0ce1b118
CV
24179fd is not a valid file descriptor or is not open for
24180writing.
24181
b383017d 24182@item EFAULT
0ce1b118
CV
24183buf is an invalid pointer value.
24184
b383017d 24185@item EFBIG
0ce1b118
CV
24186An attempt was made to write a file that exceeds the
24187host specific maximum file size allowed.
24188
b383017d 24189@item ENOSPC
0ce1b118
CV
24190No space on device to write the data.
24191
b383017d 24192@item EINTR
0ce1b118
CV
24193The call was interrupted by the user.
24194@end table
24195
24196@node lseek
24197@unnumberedsubsubsec lseek
24198@cindex lseek, file-i/o system call
24199
24200@smallexample
b383017d 24201@exdent Synopsis:
0ce1b118
CV
24202long lseek (int fd, long offset, int flag);
24203
b383017d 24204@exdent Request:
0ce1b118
CV
24205Flseek,fd,offset,flag
24206@end smallexample
24207
24208@code{flag} is one of:
24209
24210@table @code
b383017d 24211@item SEEK_SET
0ce1b118
CV
24212The offset is set to offset bytes.
24213
b383017d 24214@item SEEK_CUR
0ce1b118
CV
24215The offset is set to its current location plus offset
24216bytes.
24217
b383017d 24218@item SEEK_END
0ce1b118
CV
24219The offset is set to the size of the file plus offset
24220bytes.
24221@end table
24222
24223@smallexample
24224@exdent Return value:
24225On success, the resulting unsigned offset in bytes from
24226the beginning of the file is returned. Otherwise, a
24227value of -1 is returned.
24228
24229@exdent Errors:
24230@end smallexample
24231
24232@table @code
b383017d 24233@item EBADF
0ce1b118
CV
24234fd is not a valid open file descriptor.
24235
b383017d 24236@item ESPIPE
0ce1b118
CV
24237fd is associated with the @value{GDBN} console.
24238
b383017d 24239@item EINVAL
0ce1b118
CV
24240flag is not a proper value.
24241
b383017d 24242@item EINTR
0ce1b118
CV
24243The call was interrupted by the user.
24244@end table
24245
24246@node rename
24247@unnumberedsubsubsec rename
24248@cindex rename, file-i/o system call
24249
24250@smallexample
b383017d 24251@exdent Synopsis:
0ce1b118
CV
24252int rename(const char *oldpath, const char *newpath);
24253
b383017d 24254@exdent Request:
0ce1b118
CV
24255Frename,oldpathptr/len,newpathptr/len
24256
24257@exdent Return value:
24258On success, zero is returned. On error, -1 is returned.
24259
24260@exdent Errors:
24261@end smallexample
24262
24263@table @code
b383017d 24264@item EISDIR
0ce1b118
CV
24265newpath is an existing directory, but oldpath is not a
24266directory.
24267
b383017d 24268@item EEXIST
0ce1b118
CV
24269newpath is a non-empty directory.
24270
b383017d 24271@item EBUSY
0ce1b118
CV
24272oldpath or newpath is a directory that is in use by some
24273process.
24274
b383017d 24275@item EINVAL
0ce1b118
CV
24276An attempt was made to make a directory a subdirectory
24277of itself.
24278
b383017d 24279@item ENOTDIR
0ce1b118
CV
24280A component used as a directory in oldpath or new
24281path is not a directory. Or oldpath is a directory
24282and newpath exists but is not a directory.
24283
b383017d 24284@item EFAULT
0ce1b118
CV
24285oldpathptr or newpathptr are invalid pointer values.
24286
b383017d 24287@item EACCES
0ce1b118
CV
24288No access to the file or the path of the file.
24289
24290@item ENAMETOOLONG
b383017d 24291
0ce1b118
CV
24292oldpath or newpath was too long.
24293
b383017d 24294@item ENOENT
0ce1b118
CV
24295A directory component in oldpath or newpath does not exist.
24296
b383017d 24297@item EROFS
0ce1b118
CV
24298The file is on a read-only filesystem.
24299
b383017d 24300@item ENOSPC
0ce1b118
CV
24301The device containing the file has no room for the new
24302directory entry.
24303
b383017d 24304@item EINTR
0ce1b118
CV
24305The call was interrupted by the user.
24306@end table
24307
24308@node unlink
24309@unnumberedsubsubsec unlink
24310@cindex unlink, file-i/o system call
24311
24312@smallexample
b383017d 24313@exdent Synopsis:
0ce1b118
CV
24314int unlink(const char *pathname);
24315
b383017d 24316@exdent Request:
0ce1b118
CV
24317Funlink,pathnameptr/len
24318
24319@exdent Return value:
24320On success, zero is returned. On error, -1 is returned.
24321
24322@exdent Errors:
24323@end smallexample
24324
24325@table @code
b383017d 24326@item EACCES
0ce1b118
CV
24327No access to the file or the path of the file.
24328
b383017d 24329@item EPERM
0ce1b118
CV
24330The system does not allow unlinking of directories.
24331
b383017d 24332@item EBUSY
0ce1b118
CV
24333The file pathname cannot be unlinked because it's
24334being used by another process.
24335
b383017d 24336@item EFAULT
0ce1b118
CV
24337pathnameptr is an invalid pointer value.
24338
24339@item ENAMETOOLONG
24340pathname was too long.
24341
b383017d 24342@item ENOENT
0ce1b118
CV
24343A directory component in pathname does not exist.
24344
b383017d 24345@item ENOTDIR
0ce1b118
CV
24346A component of the path is not a directory.
24347
b383017d 24348@item EROFS
0ce1b118
CV
24349The file is on a read-only filesystem.
24350
b383017d 24351@item EINTR
0ce1b118
CV
24352The call was interrupted by the user.
24353@end table
24354
24355@node stat/fstat
24356@unnumberedsubsubsec stat/fstat
24357@cindex fstat, file-i/o system call
24358@cindex stat, file-i/o system call
24359
24360@smallexample
b383017d 24361@exdent Synopsis:
0ce1b118
CV
24362int stat(const char *pathname, struct stat *buf);
24363int fstat(int fd, struct stat *buf);
24364
b383017d 24365@exdent Request:
0ce1b118
CV
24366Fstat,pathnameptr/len,bufptr
24367Ffstat,fd,bufptr
24368
24369@exdent Return value:
24370On success, zero is returned. On error, -1 is returned.
24371
24372@exdent Errors:
24373@end smallexample
24374
24375@table @code
b383017d 24376@item EBADF
0ce1b118
CV
24377fd is not a valid open file.
24378
b383017d 24379@item ENOENT
0ce1b118
CV
24380A directory component in pathname does not exist or the
24381path is an empty string.
24382
b383017d 24383@item ENOTDIR
0ce1b118
CV
24384A component of the path is not a directory.
24385
b383017d 24386@item EFAULT
0ce1b118
CV
24387pathnameptr is an invalid pointer value.
24388
b383017d 24389@item EACCES
0ce1b118
CV
24390No access to the file or the path of the file.
24391
24392@item ENAMETOOLONG
24393pathname was too long.
24394
b383017d 24395@item EINTR
0ce1b118
CV
24396The call was interrupted by the user.
24397@end table
24398
24399@node gettimeofday
24400@unnumberedsubsubsec gettimeofday
24401@cindex gettimeofday, file-i/o system call
24402
24403@smallexample
b383017d 24404@exdent Synopsis:
0ce1b118
CV
24405int gettimeofday(struct timeval *tv, void *tz);
24406
b383017d 24407@exdent Request:
0ce1b118
CV
24408Fgettimeofday,tvptr,tzptr
24409
24410@exdent Return value:
24411On success, 0 is returned, -1 otherwise.
24412
24413@exdent Errors:
24414@end smallexample
24415
24416@table @code
b383017d 24417@item EINVAL
0ce1b118
CV
24418tz is a non-NULL pointer.
24419
b383017d 24420@item EFAULT
0ce1b118
CV
24421tvptr and/or tzptr is an invalid pointer value.
24422@end table
24423
24424@node isatty
24425@unnumberedsubsubsec isatty
24426@cindex isatty, file-i/o system call
24427
24428@smallexample
b383017d 24429@exdent Synopsis:
0ce1b118
CV
24430int isatty(int fd);
24431
b383017d 24432@exdent Request:
0ce1b118
CV
24433Fisatty,fd
24434
24435@exdent Return value:
24436Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
24437
24438@exdent Errors:
24439@end smallexample
24440
24441@table @code
b383017d 24442@item EINTR
0ce1b118
CV
24443The call was interrupted by the user.
24444@end table
24445
24446@node system
24447@unnumberedsubsubsec system
24448@cindex system, file-i/o system call
24449
24450@smallexample
b383017d 24451@exdent Synopsis:
0ce1b118
CV
24452int system(const char *command);
24453
b383017d 24454@exdent Request:
0ce1b118
CV
24455Fsystem,commandptr/len
24456
24457@exdent Return value:
24458The value returned is -1 on error and the return status
24459of the command otherwise. Only the exit status of the
24460command is returned, which is extracted from the hosts
24461system return value by calling WEXITSTATUS(retval).
24462In case /bin/sh could not be executed, 127 is returned.
24463
24464@exdent Errors:
24465@end smallexample
24466
24467@table @code
b383017d 24468@item EINTR
0ce1b118
CV
24469The call was interrupted by the user.
24470@end table
24471
24472@node Protocol specific representation of datatypes
24473@subsection Protocol specific representation of datatypes
24474@cindex protocol specific representation of datatypes, in file-i/o protocol
24475
24476@menu
24477* Integral datatypes::
24478* Pointer values::
24479* struct stat::
24480* struct timeval::
24481@end menu
24482
24483@node Integral datatypes
24484@unnumberedsubsubsec Integral datatypes
24485@cindex integral datatypes, in file-i/o protocol
24486
24487The integral datatypes used in the system calls are
24488
24489@smallexample
24490int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
24491@end smallexample
24492
24493@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
24494implemented as 32 bit values in this protocol.
24495
b383017d
RM
24496@code{Long} and @code{unsigned long} are implemented as 64 bit types.
24497
0ce1b118
CV
24498@xref{Limits}, for corresponding MIN and MAX values (similar to those
24499in @file{limits.h}) to allow range checking on host and target.
24500
24501@code{time_t} datatypes are defined as seconds since the Epoch.
24502
24503All integral datatypes transferred as part of a memory read or write of a
24504structured datatype e.g.@: a @code{struct stat} have to be given in big endian
24505byte order.
24506
24507@node Pointer values
24508@unnumberedsubsubsec Pointer values
24509@cindex pointer values, in file-i/o protocol
24510
24511Pointers to target data are transmitted as they are. An exception
24512is made for pointers to buffers for which the length isn't
24513transmitted as part of the function call, namely strings. Strings
24514are transmitted as a pointer/length pair, both as hex values, e.g.@:
24515
24516@smallexample
24517@code{1aaf/12}
24518@end smallexample
24519
24520@noindent
24521which is a pointer to data of length 18 bytes at position 0x1aaf.
24522The length is defined as the full string length in bytes, including
24523the trailing null byte. Example:
24524
24525@smallexample
24526``hello, world'' at address 0x123456
24527@end smallexample
24528
24529@noindent
24530is transmitted as
24531
24532@smallexample
24533@code{123456/d}
24534@end smallexample
24535
24536@node struct stat
24537@unnumberedsubsubsec struct stat
24538@cindex struct stat, in file-i/o protocol
24539
24540The buffer of type struct stat used by the target and @value{GDBN} is defined
24541as follows:
24542
24543@smallexample
24544struct stat @{
24545 unsigned int st_dev; /* device */
24546 unsigned int st_ino; /* inode */
24547 mode_t st_mode; /* protection */
24548 unsigned int st_nlink; /* number of hard links */
24549 unsigned int st_uid; /* user ID of owner */
24550 unsigned int st_gid; /* group ID of owner */
24551 unsigned int st_rdev; /* device type (if inode device) */
24552 unsigned long st_size; /* total size, in bytes */
24553 unsigned long st_blksize; /* blocksize for filesystem I/O */
24554 unsigned long st_blocks; /* number of blocks allocated */
24555 time_t st_atime; /* time of last access */
24556 time_t st_mtime; /* time of last modification */
24557 time_t st_ctime; /* time of last change */
24558@};
24559@end smallexample
24560
24561The integral datatypes are conforming to the definitions given in the
24562approriate section (see @ref{Integral datatypes}, for details) so this
24563structure is of size 64 bytes.
24564
24565The values of several fields have a restricted meaning and/or
24566range of values.
24567
24568@smallexample
24569st_dev: 0 file
24570 1 console
24571
24572st_ino: No valid meaning for the target. Transmitted unchanged.
24573
24574st_mode: Valid mode bits are described in Appendix C. Any other
24575 bits have currently no meaning for the target.
24576
24577st_uid: No valid meaning for the target. Transmitted unchanged.
24578
24579st_gid: No valid meaning for the target. Transmitted unchanged.
24580
24581st_rdev: No valid meaning for the target. Transmitted unchanged.
24582
24583st_atime, st_mtime, st_ctime:
24584 These values have a host and file system dependent
24585 accuracy. Especially on Windows hosts the file systems
24586 don't support exact timing values.
24587@end smallexample
24588
24589The target gets a struct stat of the above representation and is
24590responsible to coerce it to the target representation before
24591continuing.
24592
24593Note that due to size differences between the host and target
24594representation of stat members, these members could eventually
24595get truncated on the target.
24596
24597@node struct timeval
24598@unnumberedsubsubsec struct timeval
24599@cindex struct timeval, in file-i/o protocol
24600
24601The buffer of type struct timeval used by the target and @value{GDBN}
24602is defined as follows:
24603
24604@smallexample
b383017d 24605struct timeval @{
0ce1b118
CV
24606 time_t tv_sec; /* second */
24607 long tv_usec; /* microsecond */
24608@};
24609@end smallexample
24610
24611The integral datatypes are conforming to the definitions given in the
24612approriate section (see @ref{Integral datatypes}, for details) so this
24613structure is of size 8 bytes.
24614
24615@node Constants
24616@subsection Constants
24617@cindex constants, in file-i/o protocol
24618
24619The following values are used for the constants inside of the
24620protocol. @value{GDBN} and target are resposible to translate these
24621values before and after the call as needed.
24622
24623@menu
24624* Open flags::
24625* mode_t values::
24626* Errno values::
24627* Lseek flags::
24628* Limits::
24629@end menu
24630
24631@node Open flags
24632@unnumberedsubsubsec Open flags
24633@cindex open flags, in file-i/o protocol
24634
24635All values are given in hexadecimal representation.
24636
24637@smallexample
24638 O_RDONLY 0x0
24639 O_WRONLY 0x1
24640 O_RDWR 0x2
24641 O_APPEND 0x8
24642 O_CREAT 0x200
24643 O_TRUNC 0x400
24644 O_EXCL 0x800
24645@end smallexample
24646
24647@node mode_t values
24648@unnumberedsubsubsec mode_t values
24649@cindex mode_t values, in file-i/o protocol
24650
24651All values are given in octal representation.
24652
24653@smallexample
24654 S_IFREG 0100000
24655 S_IFDIR 040000
24656 S_IRUSR 0400
24657 S_IWUSR 0200
24658 S_IXUSR 0100
24659 S_IRGRP 040
24660 S_IWGRP 020
24661 S_IXGRP 010
24662 S_IROTH 04
24663 S_IWOTH 02
24664 S_IXOTH 01
24665@end smallexample
24666
24667@node Errno values
24668@unnumberedsubsubsec Errno values
24669@cindex errno values, in file-i/o protocol
24670
24671All values are given in decimal representation.
24672
24673@smallexample
24674 EPERM 1
24675 ENOENT 2
24676 EINTR 4
24677 EBADF 9
24678 EACCES 13
24679 EFAULT 14
24680 EBUSY 16
24681 EEXIST 17
24682 ENODEV 19
24683 ENOTDIR 20
24684 EISDIR 21
24685 EINVAL 22
24686 ENFILE 23
24687 EMFILE 24
24688 EFBIG 27
24689 ENOSPC 28
24690 ESPIPE 29
24691 EROFS 30
24692 ENAMETOOLONG 91
24693 EUNKNOWN 9999
24694@end smallexample
24695
24696 EUNKNOWN is used as a fallback error value if a host system returns
24697 any error value not in the list of supported error numbers.
24698
24699@node Lseek flags
24700@unnumberedsubsubsec Lseek flags
24701@cindex lseek flags, in file-i/o protocol
24702
24703@smallexample
24704 SEEK_SET 0
24705 SEEK_CUR 1
24706 SEEK_END 2
24707@end smallexample
24708
24709@node Limits
24710@unnumberedsubsubsec Limits
24711@cindex limits, in file-i/o protocol
24712
24713All values are given in decimal representation.
24714
24715@smallexample
24716 INT_MIN -2147483648
24717 INT_MAX 2147483647
24718 UINT_MAX 4294967295
24719 LONG_MIN -9223372036854775808
24720 LONG_MAX 9223372036854775807
24721 ULONG_MAX 18446744073709551615
24722@end smallexample
24723
24724@node File-I/O Examples
24725@subsection File-I/O Examples
24726@cindex file-i/o examples
24727
24728Example sequence of a write call, file descriptor 3, buffer is at target
24729address 0x1234, 6 bytes should be written:
24730
24731@smallexample
24732<- @code{Fwrite,3,1234,6}
24733@emph{request memory read from target}
24734-> @code{m1234,6}
24735<- XXXXXX
24736@emph{return "6 bytes written"}
24737-> @code{F6}
24738@end smallexample
24739
24740Example sequence of a read call, file descriptor 3, buffer is at target
24741address 0x1234, 6 bytes should be read:
24742
24743@smallexample
24744<- @code{Fread,3,1234,6}
24745@emph{request memory write to target}
24746-> @code{X1234,6:XXXXXX}
24747@emph{return "6 bytes read"}
24748-> @code{F6}
24749@end smallexample
24750
24751Example sequence of a read call, call fails on the host due to invalid
24752file descriptor (EBADF):
24753
24754@smallexample
24755<- @code{Fread,3,1234,6}
24756-> @code{F-1,9}
24757@end smallexample
24758
24759Example sequence of a read call, user presses Ctrl-C before syscall on
24760host is called:
24761
24762@smallexample
24763<- @code{Fread,3,1234,6}
24764-> @code{F-1,4,C}
24765<- @code{T02}
24766@end smallexample
24767
24768Example sequence of a read call, user presses Ctrl-C after syscall on
24769host is called:
24770
24771@smallexample
24772<- @code{Fread,3,1234,6}
24773-> @code{X1234,6:XXXXXX}
24774<- @code{T02}
24775@end smallexample
24776
f418dd93
DJ
24777@include agentexpr.texi
24778
aab4e0ec 24779@include gpl.texi
eb12ee30 24780
2154891a 24781@raisesections
6826cf00 24782@include fdl.texi
2154891a 24783@lowersections
6826cf00 24784
6d2ebf8b 24785@node Index
c906108c
SS
24786@unnumbered Index
24787
24788@printindex cp
24789
24790@tex
24791% I think something like @colophon should be in texinfo. In the
24792% meantime:
24793\long\def\colophon{\hbox to0pt{}\vfill
24794\centerline{The body of this manual is set in}
24795\centerline{\fontname\tenrm,}
24796\centerline{with headings in {\bf\fontname\tenbf}}
24797\centerline{and examples in {\tt\fontname\tentt}.}
24798\centerline{{\it\fontname\tenit\/},}
24799\centerline{{\bf\fontname\tenbf}, and}
24800\centerline{{\sl\fontname\tensl\/}}
24801\centerline{are used for emphasis.}\vfill}
24802\page\colophon
24803% Blame: doc@cygnus.com, 1991.
24804@end tex
24805
c906108c 24806@bye
This page took 2.507507 seconds and 4 git commands to generate.