PR tdep/2029
[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
839c27b7
EZ
2427@item thread apply [@var{threadno}] [@var{all}] @var{command}
2428The @code{thread apply} command allows you to apply the named
2429@var{command} to one or more threads. Specify the numbers of the
2430threads that you want affected with the command argument
2431@var{threadno}. It can be a single thread number, one of the numbers
2432shown in the first field of the @samp{info threads} display; or it
2433could be a range of thread numbers, as in @code{2-4}. To apply a
2434command to all threads, type @kbd{thread apply all @var{command}}.
c906108c
SS
2435@end table
2436
2437@cindex automatic thread selection
2438@cindex switching threads automatically
2439@cindex threads, automatic switching
2440Whenever @value{GDBN} stops your program, due to a breakpoint or a
2441signal, it automatically selects the thread where that breakpoint or
2442signal happened. @value{GDBN} alerts you to the context switch with a
2443message of the form @samp{[Switching to @var{systag}]} to identify the
2444thread.
2445
2446@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2447more information about how @value{GDBN} behaves when you stop and start
2448programs with multiple threads.
2449
2450@xref{Set Watchpoints,,Setting watchpoints}, for information about
2451watchpoints in programs with multiple threads.
c906108c 2452
6d2ebf8b 2453@node Processes
c906108c
SS
2454@section Debugging programs with multiple processes
2455
2456@cindex fork, debugging programs which call
2457@cindex multiple processes
2458@cindex processes, multiple
53a5351d
JM
2459On most systems, @value{GDBN} has no special support for debugging
2460programs which create additional processes using the @code{fork}
2461function. When a program forks, @value{GDBN} will continue to debug the
2462parent process and the child process will run unimpeded. If you have
2463set a breakpoint in any code which the child then executes, the child
2464will get a @code{SIGTRAP} signal which (unless it catches the signal)
2465will cause it to terminate.
c906108c
SS
2466
2467However, if you want to debug the child process there is a workaround
2468which isn't too painful. Put a call to @code{sleep} in the code which
2469the child process executes after the fork. It may be useful to sleep
2470only if a certain environment variable is set, or a certain file exists,
2471so that the delay need not occur when you don't want to run @value{GDBN}
2472on the child. While the child is sleeping, use the @code{ps} program to
2473get its process ID. Then tell @value{GDBN} (a new invocation of
2474@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2475the child process (@pxref{Attach}). From that point on you can debug
c906108c 2476the child process just like any other process which you attached to.
c906108c 2477
b51970ac
DJ
2478On some systems, @value{GDBN} provides support for debugging programs that
2479create additional processes using the @code{fork} or @code{vfork} functions.
2480Currently, the only platforms with this feature are HP-UX (11.x and later
2481only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2482
2483By default, when a program forks, @value{GDBN} will continue to debug
2484the parent process and the child process will run unimpeded.
2485
2486If you want to follow the child process instead of the parent process,
2487use the command @w{@code{set follow-fork-mode}}.
2488
2489@table @code
2490@kindex set follow-fork-mode
2491@item set follow-fork-mode @var{mode}
2492Set the debugger response to a program call of @code{fork} or
2493@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 2494process. The @var{mode} argument can be:
c906108c
SS
2495
2496@table @code
2497@item parent
2498The original process is debugged after a fork. The child process runs
2df3850c 2499unimpeded. This is the default.
c906108c
SS
2500
2501@item child
2502The new process is debugged after a fork. The parent process runs
2503unimpeded.
2504
c906108c
SS
2505@end table
2506
9c16f35a 2507@kindex show follow-fork-mode
c906108c 2508@item show follow-fork-mode
2df3850c 2509Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2510@end table
2511
5c95884b
MS
2512@cindex debugging multiple processes
2513On Linux, if you want to debug both the parent and child processes, use the
2514command @w{@code{set detach-on-fork}}.
2515
2516@table @code
2517@kindex set detach-on-fork
2518@item set detach-on-fork @var{mode}
2519Tells gdb whether to detach one of the processes after a fork, or
2520retain debugger control over them both.
2521
2522@table @code
2523@item on
2524The child process (or parent process, depending on the value of
2525@code{follow-fork-mode}) will be detached and allowed to run
2526independently. This is the default.
2527
2528@item off
2529Both processes will be held under the control of @value{GDBN}.
2530One process (child or parent, depending on the value of
2531@code{follow-fork-mode}) is debugged as usual, while the other
2532is held suspended.
2533
2534@end table
2535
2536@kindex show detach-on-follow
2537@item show detach-on-follow
2538Show whether detach-on-follow mode is on/off.
2539@end table
2540
2541If you choose to set @var{detach-on-follow} mode off, then
2542@value{GDBN} will retain control of all forked processes (including
2543nested forks). You can list the forked processes under the control of
2544@value{GDBN} by using the @w{@code{info forks}} command, and switch
2545from one fork to another by using the @w{@code{fork}} command.
2546
2547@table @code
2548@kindex info forks
2549@item info forks
2550Print a list of all forked processes under the control of @value{GDBN}.
2551The listing will include a fork id, a process id, and the current
2552position (program counter) of the process.
2553
2554
2555@kindex fork @var{fork-id}
2556@item fork @var{fork-id}
2557Make fork number @var{fork-id} the current process. The argument
2558@var{fork-id} is the internal fork number assigned by @value{GDBN},
2559as shown in the first field of the @samp{info forks} display.
2560
2561@end table
2562
2563To quit debugging one of the forked processes, you can either detach
2564from it by using the @w{@code{detach-fork}} command (allowing it to
2565run independently), or delete (and kill) it using the
2566@w{@code{delete-fork}} command.
2567
2568@table @code
2569@kindex detach-fork @var{fork-id}
2570@item detach-fork @var{fork-id}
2571Detach from the process identified by @value{GDBN} fork number
2572@var{fork-id}, and remove it from the fork list. The process will be
2573allowed to run independently.
2574
2575@kindex delete-fork @var{fork-id}
2576@item delete-fork @var{fork-id}
2577Kill the process identified by @value{GDBN} fork number @var{fork-id},
2578and remove it from the fork list.
2579
2580@end table
2581
c906108c
SS
2582If you ask to debug a child process and a @code{vfork} is followed by an
2583@code{exec}, @value{GDBN} executes the new target up to the first
2584breakpoint in the new target. If you have a breakpoint set on
2585@code{main} in your original program, the breakpoint will also be set on
2586the child process's @code{main}.
2587
2588When a child process is spawned by @code{vfork}, you cannot debug the
2589child or parent until an @code{exec} call completes.
2590
2591If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2592call executes, the new target restarts. To restart the parent process,
2593use the @code{file} command with the parent executable name as its
2594argument.
2595
2596You can use the @code{catch} command to make @value{GDBN} stop whenever
2597a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2598Catchpoints, ,Setting catchpoints}.
c906108c 2599
5c95884b
MS
2600@node Checkpoint/Restart
2601@section Setting a @emph{bookmark} to return to later
2602
2603@cindex checkpoint
2604@cindex restart
2605@cindex bookmark
2606@cindex snapshot of a process
2607@cindex rewind program state
2608
2609On certain operating systems@footnote{Currently, only
2610@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
2611program's state, called a @dfn{checkpoint}, and come back to it
2612later.
2613
2614Returning to a checkpoint effectively undoes everything that has
2615happened in the program since the @code{checkpoint} was saved. This
2616includes changes in memory, registers, and even (within some limits)
2617system state. Effectively, it is like going back in time to the
2618moment when the checkpoint was saved.
2619
2620Thus, if you're stepping thru a program and you think you're
2621getting close to the point where things go wrong, you can save
2622a checkpoint. Then, if you accidentally go too far and miss
2623the critical statement, instead of having to restart your program
2624from the beginning, you can just go back to the checkpoint and
2625start again from there.
2626
2627This can be especially useful if it takes a lot of time or
2628steps to reach the point where you think the bug occurs.
2629
2630To use the @code{checkpoint}/@code{restart} method of debugging:
2631
2632@table @code
2633@kindex checkpoint
2634@item checkpoint
2635Save a snapshot of the debugged program's current execution state.
2636The @code{checkpoint} command takes no arguments, but each checkpoint
2637is assigned a small integer id, similar to a breakpoint id.
2638
2639@kindex info checkpoints
2640@item info checkpoints
2641List the checkpoints that have been saved in the current debugging
2642session. For each checkpoint, the following information will be
2643listed:
2644
2645@table @code
2646@item Checkpoint ID
2647@item Process ID
2648@item Code Address
2649@item Source line, or label
2650@end table
2651
2652@kindex restart @var{checkpoint-id}
2653@item restart @var{checkpoint-id}
2654Restore the program state that was saved as checkpoint number
2655@var{checkpoint-id}. All program variables, registers, stack frames
2656etc.@: will be returned to the values that they had when the checkpoint
2657was saved. In essence, gdb will ``wind back the clock'' to the point
2658in time when the checkpoint was saved.
2659
2660Note that breakpoints, @value{GDBN} variables, command history etc.
2661are not affected by restoring a checkpoint. In general, a checkpoint
2662only restores things that reside in the program being debugged, not in
2663the debugger.
2664
2665@kindex delete-checkpoint @var{checkpoint-id}
2666@item delete-checkpoint @var{checkpoint-id}
2667Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
2668
2669@end table
2670
2671Returning to a previously saved checkpoint will restore the user state
2672of the program being debugged, plus a significant subset of the system
2673(OS) state, including file pointers. It won't ``un-write'' data from
2674a file, but it will rewind the file pointer to the previous location,
2675so that the previously written data can be overwritten. For files
2676opened in read mode, the pointer will also be restored so that the
2677previously read data can be read again.
2678
2679Of course, characters that have been sent to a printer (or other
2680external device) cannot be ``snatched back'', and characters received
2681from eg.@: a serial device can be removed from internal program buffers,
2682but they cannot be ``pushed back'' into the serial pipeline, ready to
2683be received again. Similarly, the actual contents of files that have
2684been changed cannot be restored (at this time).
2685
2686However, within those constraints, you actually can ``rewind'' your
2687program to a previously saved point in time, and begin debugging it
2688again --- and you can change the course of events so as to debug a
2689different execution path this time.
2690
2691@cindex checkpoints and process id
2692Finally, there is one bit of internal program state that will be
2693different when you return to a checkpoint --- the program's process
2694id. Each checkpoint will have a unique process id (or @var{pid}),
2695and each will be different from the program's original @var{pid}.
2696If your program has saved a local copy of its process id, this could
2697potentially pose a problem.
2698
2699@subsection A non-obvious benefit of using checkpoints
2700
2701On some systems such as @sc{gnu}/Linux, address space randomization
2702is performed on new processes for security reasons. This makes it
2703difficult or impossible to set a breakpoint, or watchpoint, on an
2704absolute address if you have to restart the program, since the
2705absolute location of a symbol will change from one execution to the
2706next.
2707
2708A checkpoint, however, is an @emph{identical} copy of a process.
2709Therefore if you create a checkpoint at (eg.@:) the start of main,
2710and simply return to that checkpoint instead of restarting the
2711process, you can avoid the effects of address randomization and
2712your symbols will all stay in the same place.
2713
6d2ebf8b 2714@node Stopping
c906108c
SS
2715@chapter Stopping and Continuing
2716
2717The principal purposes of using a debugger are so that you can stop your
2718program before it terminates; or so that, if your program runs into
2719trouble, you can investigate and find out why.
2720
7a292a7a
SS
2721Inside @value{GDBN}, your program may stop for any of several reasons,
2722such as a signal, a breakpoint, or reaching a new line after a
2723@value{GDBN} command such as @code{step}. You may then examine and
2724change variables, set new breakpoints or remove old ones, and then
2725continue execution. Usually, the messages shown by @value{GDBN} provide
2726ample explanation of the status of your program---but you can also
2727explicitly request this information at any time.
c906108c
SS
2728
2729@table @code
2730@kindex info program
2731@item info program
2732Display information about the status of your program: whether it is
7a292a7a 2733running or not, what process it is, and why it stopped.
c906108c
SS
2734@end table
2735
2736@menu
2737* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2738* Continuing and Stepping:: Resuming execution
c906108c 2739* Signals:: Signals
c906108c 2740* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2741@end menu
2742
6d2ebf8b 2743@node Breakpoints
c906108c
SS
2744@section Breakpoints, watchpoints, and catchpoints
2745
2746@cindex breakpoints
2747A @dfn{breakpoint} makes your program stop whenever a certain point in
2748the program is reached. For each breakpoint, you can add conditions to
2749control in finer detail whether your program stops. You can set
2750breakpoints with the @code{break} command and its variants (@pxref{Set
2751Breaks, ,Setting breakpoints}), to specify the place where your program
2752should stop by line number, function name or exact address in the
2753program.
2754
09d4efe1
EZ
2755On some systems, you can set breakpoints in shared libraries before
2756the executable is run. There is a minor limitation on HP-UX systems:
2757you must wait until the executable is run in order to set breakpoints
2758in shared library routines that are not called directly by the program
2759(for example, routines that are arguments in a @code{pthread_create}
2760call).
c906108c
SS
2761
2762@cindex watchpoints
2763@cindex memory tracing
2764@cindex breakpoint on memory address
2765@cindex breakpoint on variable modification
2766A @dfn{watchpoint} is a special breakpoint that stops your program
2767when the value of an expression changes. You must use a different
2768command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2769watchpoints}), but aside from that, you can manage a watchpoint like
2770any other breakpoint: you enable, disable, and delete both breakpoints
2771and watchpoints using the same commands.
2772
2773You can arrange to have values from your program displayed automatically
2774whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2775Automatic display}.
2776
2777@cindex catchpoints
2778@cindex breakpoint on events
2779A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2780when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2781exception or the loading of a library. As with watchpoints, you use a
2782different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2783catchpoints}), but aside from that, you can manage a catchpoint like any
2784other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2785@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2786
2787@cindex breakpoint numbers
2788@cindex numbers for breakpoints
2789@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2790catchpoint when you create it; these numbers are successive integers
2791starting with one. In many of the commands for controlling various
2792features of breakpoints you use the breakpoint number to say which
2793breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2794@dfn{disabled}; if disabled, it has no effect on your program until you
2795enable it again.
2796
c5394b80
JM
2797@cindex breakpoint ranges
2798@cindex ranges of breakpoints
2799Some @value{GDBN} commands accept a range of breakpoints on which to
2800operate. A breakpoint range is either a single breakpoint number, like
2801@samp{5}, or two such numbers, in increasing order, separated by a
2802hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2803all breakpoint in that range are operated on.
2804
c906108c
SS
2805@menu
2806* Set Breaks:: Setting breakpoints
2807* Set Watchpoints:: Setting watchpoints
2808* Set Catchpoints:: Setting catchpoints
2809* Delete Breaks:: Deleting breakpoints
2810* Disabling:: Disabling breakpoints
2811* Conditions:: Break conditions
2812* Break Commands:: Breakpoint command lists
c906108c 2813* Breakpoint Menus:: Breakpoint menus
d4f3574e 2814* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2815* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2816@end menu
2817
6d2ebf8b 2818@node Set Breaks
c906108c
SS
2819@subsection Setting breakpoints
2820
5d161b24 2821@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2822@c consider in particular declaration with/without initialization.
2823@c
2824@c FIXME 2 is there stuff on this already? break at fun start, already init?
2825
2826@kindex break
41afff9a
EZ
2827@kindex b @r{(@code{break})}
2828@vindex $bpnum@r{, convenience variable}
c906108c
SS
2829@cindex latest breakpoint
2830Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2831@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2832number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2833Vars,, Convenience variables}, for a discussion of what you can do with
2834convenience variables.
2835
2836You have several ways to say where the breakpoint should go.
2837
2838@table @code
2839@item break @var{function}
5d161b24 2840Set a breakpoint at entry to function @var{function}.
c906108c 2841When using source languages that permit overloading of symbols, such as
b37052ae 2842C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2843@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2844
2845@item break +@var{offset}
2846@itemx break -@var{offset}
2847Set a breakpoint some number of lines forward or back from the position
d4f3574e 2848at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2849(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2850
2851@item break @var{linenum}
2852Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2853The current source file is the last file whose source text was printed.
2854The breakpoint will stop your program just before it executes any of the
c906108c
SS
2855code on that line.
2856
2857@item break @var{filename}:@var{linenum}
2858Set a breakpoint at line @var{linenum} in source file @var{filename}.
2859
2860@item break @var{filename}:@var{function}
2861Set a breakpoint at entry to function @var{function} found in file
2862@var{filename}. Specifying a file name as well as a function name is
2863superfluous except when multiple files contain similarly named
2864functions.
2865
2866@item break *@var{address}
2867Set a breakpoint at address @var{address}. You can use this to set
2868breakpoints in parts of your program which do not have debugging
2869information or source files.
2870
2871@item break
2872When called without any arguments, @code{break} sets a breakpoint at
2873the next instruction to be executed in the selected stack frame
2874(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2875innermost, this makes your program stop as soon as control
2876returns to that frame. This is similar to the effect of a
2877@code{finish} command in the frame inside the selected frame---except
2878that @code{finish} does not leave an active breakpoint. If you use
2879@code{break} without an argument in the innermost frame, @value{GDBN} stops
2880the next time it reaches the current location; this may be useful
2881inside loops.
2882
2883@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2884least one instruction has been executed. If it did not do this, you
2885would be unable to proceed past a breakpoint without first disabling the
2886breakpoint. This rule applies whether or not the breakpoint already
2887existed when your program stopped.
2888
2889@item break @dots{} if @var{cond}
2890Set a breakpoint with condition @var{cond}; evaluate the expression
2891@var{cond} each time the breakpoint is reached, and stop only if the
2892value is nonzero---that is, if @var{cond} evaluates as true.
2893@samp{@dots{}} stands for one of the possible arguments described
2894above (or no argument) specifying where to break. @xref{Conditions,
2895,Break conditions}, for more information on breakpoint conditions.
2896
2897@kindex tbreak
2898@item tbreak @var{args}
2899Set a breakpoint enabled only for one stop. @var{args} are the
2900same as for the @code{break} command, and the breakpoint is set in the same
2901way, but the breakpoint is automatically deleted after the first time your
2902program stops there. @xref{Disabling, ,Disabling breakpoints}.
2903
c906108c 2904@kindex hbreak
ba04e063 2905@cindex hardware breakpoints
c906108c 2906@item hbreak @var{args}
d4f3574e
SS
2907Set a hardware-assisted breakpoint. @var{args} are the same as for the
2908@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2909breakpoint requires hardware support and some target hardware may not
2910have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2911debugging, so you can set a breakpoint at an instruction without
2912changing the instruction. This can be used with the new trap-generation
09d4efe1 2913provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
2914will generate traps when a program accesses some data or instruction
2915address that is assigned to the debug registers. However the hardware
2916breakpoint registers can take a limited number of breakpoints. For
2917example, on the DSU, only two data breakpoints can be set at a time, and
2918@value{GDBN} will reject this command if more than two are used. Delete
2919or disable unused hardware breakpoints before setting new ones
2920(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
9c16f35a
EZ
2921For remote targets, you can restrict the number of hardware
2922breakpoints @value{GDBN} will use, see @ref{set remote
2923hardware-breakpoint-limit}.
501eef12 2924
c906108c
SS
2925
2926@kindex thbreak
2927@item thbreak @var{args}
2928Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2929are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2930the same way. However, like the @code{tbreak} command,
c906108c
SS
2931the breakpoint is automatically deleted after the
2932first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2933command, the breakpoint requires hardware support and some target hardware
2934may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2935See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2936
2937@kindex rbreak
2938@cindex regular expression
c45da7e6
EZ
2939@cindex breakpoints in functions matching a regexp
2940@cindex set breakpoints in many functions
c906108c 2941@item rbreak @var{regex}
c906108c 2942Set breakpoints on all functions matching the regular expression
11cf8741
JM
2943@var{regex}. This command sets an unconditional breakpoint on all
2944matches, printing a list of all breakpoints it set. Once these
2945breakpoints are set, they are treated just like the breakpoints set with
2946the @code{break} command. You can delete them, disable them, or make
2947them conditional the same way as any other breakpoint.
2948
2949The syntax of the regular expression is the standard one used with tools
2950like @file{grep}. Note that this is different from the syntax used by
2951shells, so for instance @code{foo*} matches all functions that include
2952an @code{fo} followed by zero or more @code{o}s. There is an implicit
2953@code{.*} leading and trailing the regular expression you supply, so to
2954match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2955
f7dc1244 2956@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2957When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2958breakpoints on overloaded functions that are not members of any special
2959classes.
c906108c 2960
f7dc1244
EZ
2961@cindex set breakpoints on all functions
2962The @code{rbreak} command can be used to set breakpoints in
2963@strong{all} the functions in a program, like this:
2964
2965@smallexample
2966(@value{GDBP}) rbreak .
2967@end smallexample
2968
c906108c
SS
2969@kindex info breakpoints
2970@cindex @code{$_} and @code{info breakpoints}
2971@item info breakpoints @r{[}@var{n}@r{]}
2972@itemx info break @r{[}@var{n}@r{]}
2973@itemx info watchpoints @r{[}@var{n}@r{]}
2974Print a table of all breakpoints, watchpoints, and catchpoints set and
2975not deleted, with the following columns for each breakpoint:
2976
2977@table @emph
2978@item Breakpoint Numbers
2979@item Type
2980Breakpoint, watchpoint, or catchpoint.
2981@item Disposition
2982Whether the breakpoint is marked to be disabled or deleted when hit.
2983@item Enabled or Disabled
2984Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2985that are not enabled.
2986@item Address
2650777c
JJ
2987Where the breakpoint is in your program, as a memory address. If the
2988breakpoint is pending (see below for details) on a future load of a shared library, the address
2989will be listed as @samp{<PENDING>}.
c906108c
SS
2990@item What
2991Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
2992line number. For a pending breakpoint, the original string passed to
2993the breakpoint command will be listed as it cannot be resolved until
2994the appropriate shared library is loaded in the future.
c906108c
SS
2995@end table
2996
2997@noindent
2998If a breakpoint is conditional, @code{info break} shows the condition on
2999the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
3000are listed after that. A pending breakpoint is allowed to have a condition
3001specified for it. The condition is not parsed for validity until a shared
3002library is loaded that allows the pending breakpoint to resolve to a
3003valid location.
c906108c
SS
3004
3005@noindent
3006@code{info break} with a breakpoint
3007number @var{n} as argument lists only that breakpoint. The
3008convenience variable @code{$_} and the default examining-address for
3009the @code{x} command are set to the address of the last breakpoint
5d161b24 3010listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
3011
3012@noindent
3013@code{info break} displays a count of the number of times the breakpoint
3014has been hit. This is especially useful in conjunction with the
3015@code{ignore} command. You can ignore a large number of breakpoint
3016hits, look at the breakpoint info to see how many times the breakpoint
3017was hit, and then run again, ignoring one less than that number. This
3018will get you quickly to the last hit of that breakpoint.
3019@end table
3020
3021@value{GDBN} allows you to set any number of breakpoints at the same place in
3022your program. There is nothing silly or meaningless about this. When
3023the breakpoints are conditional, this is even useful
3024(@pxref{Conditions, ,Break conditions}).
3025
2650777c 3026@cindex pending breakpoints
dd79a6cf
JJ
3027If a specified breakpoint location cannot be found, it may be due to the fact
3028that the location is in a shared library that is yet to be loaded. In such
3029a case, you may want @value{GDBN} to create a special breakpoint (known as
3030a @dfn{pending breakpoint}) that
3031attempts to resolve itself in the future when an appropriate shared library
3032gets loaded.
3033
3034Pending breakpoints are useful to set at the start of your
2650777c
JJ
3035@value{GDBN} session for locations that you know will be dynamically loaded
3036later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
3037a check is made to see if the load resolves any pending breakpoint locations.
3038If a pending breakpoint location gets resolved,
3039a regular breakpoint is created and the original pending breakpoint is removed.
3040
3041@value{GDBN} provides some additional commands for controlling pending
3042breakpoint support:
3043
3044@kindex set breakpoint pending
3045@kindex show breakpoint pending
3046@table @code
3047@item set breakpoint pending auto
3048This is the default behavior. When @value{GDBN} cannot find the breakpoint
3049location, it queries you whether a pending breakpoint should be created.
3050
3051@item set breakpoint pending on
3052This indicates that an unrecognized breakpoint location should automatically
3053result in a pending breakpoint being created.
3054
3055@item set breakpoint pending off
3056This indicates that pending breakpoints are not to be created. Any
3057unrecognized breakpoint location results in an error. This setting does
3058not affect any pending breakpoints previously created.
3059
3060@item show breakpoint pending
3061Show the current behavior setting for creating pending breakpoints.
3062@end table
2650777c 3063
649e03f6
RM
3064@cindex operations allowed on pending breakpoints
3065Normal breakpoint operations apply to pending breakpoints as well. You may
3066specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
3067breakpoint is reached. You can also enable or disable
3068the pending breakpoint. When you specify a condition for a pending breakpoint,
3069the parsing of the condition will be deferred until the point where the
3070pending breakpoint location is resolved. Disabling a pending breakpoint
3071tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
3072shared library load. When a pending breakpoint is re-enabled,
649e03f6 3073@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
3074This is done because any number of shared library loads could have
3075occurred since the time the breakpoint was disabled and one or more
3076of these loads could resolve the location.
3077
c906108c
SS
3078@cindex negative breakpoint numbers
3079@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
3080@value{GDBN} itself sometimes sets breakpoints in your program for
3081special purposes, such as proper handling of @code{longjmp} (in C
3082programs). These internal breakpoints are assigned negative numbers,
3083starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 3084You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 3085@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
3086
3087
6d2ebf8b 3088@node Set Watchpoints
c906108c
SS
3089@subsection Setting watchpoints
3090
3091@cindex setting watchpoints
c906108c
SS
3092You can use a watchpoint to stop execution whenever the value of an
3093expression changes, without having to predict a particular place where
3094this may happen.
3095
82f2d802
EZ
3096@cindex software watchpoints
3097@cindex hardware watchpoints
c906108c 3098Depending on your system, watchpoints may be implemented in software or
2df3850c 3099hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
3100program and testing the variable's value each time, which is hundreds of
3101times slower than normal execution. (But this may still be worth it, to
3102catch errors where you have no clue what part of your program is the
3103culprit.)
3104
82f2d802
EZ
3105On some systems, such as HP-UX, @sc{gnu}/Linux and most other
3106x86-based targets, @value{GDBN} includes support for hardware
3107watchpoints, which do not slow down the running of your program.
c906108c
SS
3108
3109@table @code
3110@kindex watch
3111@item watch @var{expr}
3112Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
3113is written into by the program and its value changes.
3114
3115@kindex rwatch
3116@item rwatch @var{expr}
09d4efe1
EZ
3117Set a watchpoint that will break when the value of @var{expr} is read
3118by the program.
c906108c
SS
3119
3120@kindex awatch
3121@item awatch @var{expr}
09d4efe1
EZ
3122Set a watchpoint that will break when @var{expr} is either read from
3123or written into by the program.
c906108c
SS
3124
3125@kindex info watchpoints
3126@item info watchpoints
3127This command prints a list of watchpoints, breakpoints, and catchpoints;
09d4efe1 3128it is the same as @code{info break} (@pxref{Set Breaks}).
c906108c
SS
3129@end table
3130
3131@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
3132watchpoints execute very quickly, and the debugger reports a change in
3133value at the exact instruction where the change occurs. If @value{GDBN}
3134cannot set a hardware watchpoint, it sets a software watchpoint, which
3135executes more slowly and reports the change in value at the next
82f2d802
EZ
3136@emph{statement}, not the instruction, after the change occurs.
3137
82f2d802
EZ
3138@cindex use only software watchpoints
3139You can force @value{GDBN} to use only software watchpoints with the
3140@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
3141zero, @value{GDBN} will never try to use hardware watchpoints, even if
3142the underlying system supports them. (Note that hardware-assisted
3143watchpoints that were set @emph{before} setting
3144@code{can-use-hw-watchpoints} to zero will still use the hardware
3145mechanism of watching expressiion values.)
c906108c 3146
9c16f35a
EZ
3147@table @code
3148@item set can-use-hw-watchpoints
3149@kindex set can-use-hw-watchpoints
3150Set whether or not to use hardware watchpoints.
3151
3152@item show can-use-hw-watchpoints
3153@kindex show can-use-hw-watchpoints
3154Show the current mode of using hardware watchpoints.
3155@end table
3156
3157For remote targets, you can restrict the number of hardware
3158watchpoints @value{GDBN} will use, see @ref{set remote
3159hardware-breakpoint-limit}.
3160
c906108c
SS
3161When you issue the @code{watch} command, @value{GDBN} reports
3162
474c8240 3163@smallexample
c906108c 3164Hardware watchpoint @var{num}: @var{expr}
474c8240 3165@end smallexample
c906108c
SS
3166
3167@noindent
3168if it was able to set a hardware watchpoint.
3169
7be570e7
JM
3170Currently, the @code{awatch} and @code{rwatch} commands can only set
3171hardware watchpoints, because accesses to data that don't change the
3172value of the watched expression cannot be detected without examining
3173every instruction as it is being executed, and @value{GDBN} does not do
3174that currently. If @value{GDBN} finds that it is unable to set a
3175hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
3176will print a message like this:
3177
3178@smallexample
3179Expression cannot be implemented with read/access watchpoint.
3180@end smallexample
3181
3182Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
3183data type of the watched expression is wider than what a hardware
3184watchpoint on the target machine can handle. For example, some systems
3185can only watch regions that are up to 4 bytes wide; on such systems you
3186cannot set hardware watchpoints for an expression that yields a
3187double-precision floating-point number (which is typically 8 bytes
3188wide). As a work-around, it might be possible to break the large region
3189into a series of smaller ones and watch them with separate watchpoints.
3190
3191If you set too many hardware watchpoints, @value{GDBN} might be unable
3192to insert all of them when you resume the execution of your program.
3193Since the precise number of active watchpoints is unknown until such
3194time as the program is about to be resumed, @value{GDBN} might not be
3195able to warn you about this when you set the watchpoints, and the
3196warning will be printed only when the program is resumed:
3197
3198@smallexample
3199Hardware watchpoint @var{num}: Could not insert watchpoint
3200@end smallexample
3201
3202@noindent
3203If this happens, delete or disable some of the watchpoints.
3204
3205The SPARClite DSU will generate traps when a program accesses some data
3206or instruction address that is assigned to the debug registers. For the
3207data addresses, DSU facilitates the @code{watch} command. However the
3208hardware breakpoint registers can only take two data watchpoints, and
3209both watchpoints must be the same kind. For example, you can set two
3210watchpoints with @code{watch} commands, two with @code{rwatch} commands,
3211@strong{or} two with @code{awatch} commands, but you cannot set one
3212watchpoint with one command and the other with a different command.
c906108c
SS
3213@value{GDBN} will reject the command if you try to mix watchpoints.
3214Delete or disable unused watchpoint commands before setting new ones.
3215
3216If you call a function interactively using @code{print} or @code{call},
2df3850c 3217any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
3218kind of breakpoint or the call completes.
3219
7be570e7
JM
3220@value{GDBN} automatically deletes watchpoints that watch local
3221(automatic) variables, or expressions that involve such variables, when
3222they go out of scope, that is, when the execution leaves the block in
3223which these variables were defined. In particular, when the program
3224being debugged terminates, @emph{all} local variables go out of scope,
3225and so only watchpoints that watch global variables remain set. If you
3226rerun the program, you will need to set all such watchpoints again. One
3227way of doing that would be to set a code breakpoint at the entry to the
3228@code{main} function and when it breaks, set all the watchpoints.
3229
c906108c
SS
3230@quotation
3231@cindex watchpoints and threads
3232@cindex threads and watchpoints
c906108c
SS
3233@emph{Warning:} In multi-thread programs, watchpoints have only limited
3234usefulness. With the current watchpoint implementation, @value{GDBN}
3235can only watch the value of an expression @emph{in a single thread}. If
3236you are confident that the expression can only change due to the current
3237thread's activity (and if you are also confident that no other thread
3238can become current), then you can use watchpoints as usual. However,
3239@value{GDBN} may not notice when a non-current thread's activity changes
3240the expression.
53a5351d 3241
d4f3574e 3242@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
3243@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
3244have only limited usefulness. If @value{GDBN} creates a software
3245watchpoint, it can only watch the value of an expression @emph{in a
3246single thread}. If you are confident that the expression can only
3247change due to the current thread's activity (and if you are also
3248confident that no other thread can become current), then you can use
3249software watchpoints as usual. However, @value{GDBN} may not notice
3250when a non-current thread's activity changes the expression. (Hardware
3251watchpoints, in contrast, watch an expression in all threads.)
c906108c 3252@end quotation
c906108c 3253
501eef12
AC
3254@xref{set remote hardware-watchpoint-limit}.
3255
6d2ebf8b 3256@node Set Catchpoints
c906108c 3257@subsection Setting catchpoints
d4f3574e 3258@cindex catchpoints, setting
c906108c
SS
3259@cindex exception handlers
3260@cindex event handling
3261
3262You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 3263kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
3264shared library. Use the @code{catch} command to set a catchpoint.
3265
3266@table @code
3267@kindex catch
3268@item catch @var{event}
3269Stop when @var{event} occurs. @var{event} can be any of the following:
3270@table @code
3271@item throw
4644b6e3 3272@cindex stop on C@t{++} exceptions
b37052ae 3273The throwing of a C@t{++} exception.
c906108c
SS
3274
3275@item catch
b37052ae 3276The catching of a C@t{++} exception.
c906108c
SS
3277
3278@item exec
4644b6e3 3279@cindex break on fork/exec
c906108c
SS
3280A call to @code{exec}. This is currently only available for HP-UX.
3281
3282@item fork
c906108c
SS
3283A call to @code{fork}. This is currently only available for HP-UX.
3284
3285@item vfork
c906108c
SS
3286A call to @code{vfork}. This is currently only available for HP-UX.
3287
3288@item load
3289@itemx load @var{libname}
4644b6e3 3290@cindex break on load/unload of shared library
c906108c
SS
3291The dynamic loading of any shared library, or the loading of the library
3292@var{libname}. This is currently only available for HP-UX.
3293
3294@item unload
3295@itemx unload @var{libname}
c906108c
SS
3296The unloading of any dynamically loaded shared library, or the unloading
3297of the library @var{libname}. This is currently only available for HP-UX.
3298@end table
3299
3300@item tcatch @var{event}
3301Set a catchpoint that is enabled only for one stop. The catchpoint is
3302automatically deleted after the first time the event is caught.
3303
3304@end table
3305
3306Use the @code{info break} command to list the current catchpoints.
3307
b37052ae 3308There are currently some limitations to C@t{++} exception handling
c906108c
SS
3309(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3310
3311@itemize @bullet
3312@item
3313If you call a function interactively, @value{GDBN} normally returns
3314control to you when the function has finished executing. If the call
3315raises an exception, however, the call may bypass the mechanism that
3316returns control to you and cause your program either to abort or to
3317simply continue running until it hits a breakpoint, catches a signal
3318that @value{GDBN} is listening for, or exits. This is the case even if
3319you set a catchpoint for the exception; catchpoints on exceptions are
3320disabled within interactive calls.
3321
3322@item
3323You cannot raise an exception interactively.
3324
3325@item
3326You cannot install an exception handler interactively.
3327@end itemize
3328
3329@cindex raise exceptions
3330Sometimes @code{catch} is not the best way to debug exception handling:
3331if you need to know exactly where an exception is raised, it is better to
3332stop @emph{before} the exception handler is called, since that way you
3333can see the stack before any unwinding takes place. If you set a
3334breakpoint in an exception handler instead, it may not be easy to find
3335out where the exception was raised.
3336
3337To stop just before an exception handler is called, you need some
b37052ae 3338knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
3339raised by calling a library function named @code{__raise_exception}
3340which has the following ANSI C interface:
3341
474c8240 3342@smallexample
c906108c 3343 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
3344 @var{id} is the exception identifier. */
3345 void __raise_exception (void **addr, void *id);
474c8240 3346@end smallexample
c906108c
SS
3347
3348@noindent
3349To make the debugger catch all exceptions before any stack
3350unwinding takes place, set a breakpoint on @code{__raise_exception}
3351(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
3352
3353With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
3354that depends on the value of @var{id}, you can stop your program when
3355a specific exception is raised. You can use multiple conditional
3356breakpoints to stop your program when any of a number of exceptions are
3357raised.
3358
3359
6d2ebf8b 3360@node Delete Breaks
c906108c
SS
3361@subsection Deleting breakpoints
3362
3363@cindex clearing breakpoints, watchpoints, catchpoints
3364@cindex deleting breakpoints, watchpoints, catchpoints
3365It is often necessary to eliminate a breakpoint, watchpoint, or
3366catchpoint once it has done its job and you no longer want your program
3367to stop there. This is called @dfn{deleting} the breakpoint. A
3368breakpoint that has been deleted no longer exists; it is forgotten.
3369
3370With the @code{clear} command you can delete breakpoints according to
3371where they are in your program. With the @code{delete} command you can
3372delete individual breakpoints, watchpoints, or catchpoints by specifying
3373their breakpoint numbers.
3374
3375It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3376automatically ignores breakpoints on the first instruction to be executed
3377when you continue execution without changing the execution address.
3378
3379@table @code
3380@kindex clear
3381@item clear
3382Delete any breakpoints at the next instruction to be executed in the
3383selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3384the innermost frame is selected, this is a good way to delete a
3385breakpoint where your program just stopped.
3386
3387@item clear @var{function}
3388@itemx clear @var{filename}:@var{function}
09d4efe1 3389Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
3390
3391@item clear @var{linenum}
3392@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
3393Delete any breakpoints set at or within the code of the specified
3394@var{linenum} of the specified @var{filename}.
c906108c
SS
3395
3396@cindex delete breakpoints
3397@kindex delete
41afff9a 3398@kindex d @r{(@code{delete})}
c5394b80
JM
3399@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3400Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3401ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3402breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3403confirm off}). You can abbreviate this command as @code{d}.
3404@end table
3405
6d2ebf8b 3406@node Disabling
c906108c
SS
3407@subsection Disabling breakpoints
3408
4644b6e3 3409@cindex enable/disable a breakpoint
c906108c
SS
3410Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3411prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3412it had been deleted, but remembers the information on the breakpoint so
3413that you can @dfn{enable} it again later.
3414
3415You disable and enable breakpoints, watchpoints, and catchpoints with
3416the @code{enable} and @code{disable} commands, optionally specifying one
3417or more breakpoint numbers as arguments. Use @code{info break} or
3418@code{info watch} to print a list of breakpoints, watchpoints, and
3419catchpoints if you do not know which numbers to use.
3420
3421A breakpoint, watchpoint, or catchpoint can have any of four different
3422states of enablement:
3423
3424@itemize @bullet
3425@item
3426Enabled. The breakpoint stops your program. A breakpoint set
3427with the @code{break} command starts out in this state.
3428@item
3429Disabled. The breakpoint has no effect on your program.
3430@item
3431Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3432disabled.
c906108c
SS
3433@item
3434Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3435immediately after it does so it is deleted permanently. A breakpoint
3436set with the @code{tbreak} command starts out in this state.
c906108c
SS
3437@end itemize
3438
3439You can use the following commands to enable or disable breakpoints,
3440watchpoints, and catchpoints:
3441
3442@table @code
c906108c 3443@kindex disable
41afff9a 3444@kindex dis @r{(@code{disable})}
c5394b80 3445@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3446Disable the specified breakpoints---or all breakpoints, if none are
3447listed. A disabled breakpoint has no effect but is not forgotten. All
3448options such as ignore-counts, conditions and commands are remembered in
3449case the breakpoint is enabled again later. You may abbreviate
3450@code{disable} as @code{dis}.
3451
c906108c 3452@kindex enable
c5394b80 3453@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3454Enable the specified breakpoints (or all defined breakpoints). They
3455become effective once again in stopping your program.
3456
c5394b80 3457@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3458Enable the specified breakpoints temporarily. @value{GDBN} disables any
3459of these breakpoints immediately after stopping your program.
3460
c5394b80 3461@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3462Enable the specified breakpoints to work once, then die. @value{GDBN}
3463deletes any of these breakpoints as soon as your program stops there.
09d4efe1 3464Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
3465@end table
3466
d4f3574e
SS
3467@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3468@c confusing: tbreak is also initially enabled.
c906108c
SS
3469Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3470,Setting breakpoints}), breakpoints that you set are initially enabled;
3471subsequently, they become disabled or enabled only when you use one of
3472the commands above. (The command @code{until} can set and delete a
3473breakpoint of its own, but it does not change the state of your other
3474breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3475stepping}.)
3476
6d2ebf8b 3477@node Conditions
c906108c
SS
3478@subsection Break conditions
3479@cindex conditional breakpoints
3480@cindex breakpoint conditions
3481
3482@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3483@c in particular for a watchpoint?
c906108c
SS
3484The simplest sort of breakpoint breaks every time your program reaches a
3485specified place. You can also specify a @dfn{condition} for a
3486breakpoint. A condition is just a Boolean expression in your
3487programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3488a condition evaluates the expression each time your program reaches it,
3489and your program stops only if the condition is @emph{true}.
3490
3491This is the converse of using assertions for program validation; in that
3492situation, you want to stop when the assertion is violated---that is,
3493when the condition is false. In C, if you want to test an assertion expressed
3494by the condition @var{assert}, you should set the condition
3495@samp{! @var{assert}} on the appropriate breakpoint.
3496
3497Conditions are also accepted for watchpoints; you may not need them,
3498since a watchpoint is inspecting the value of an expression anyhow---but
3499it might be simpler, say, to just set a watchpoint on a variable name,
3500and specify a condition that tests whether the new value is an interesting
3501one.
3502
3503Break conditions can have side effects, and may even call functions in
3504your program. This can be useful, for example, to activate functions
3505that log program progress, or to use your own print functions to
3506format special data structures. The effects are completely predictable
3507unless there is another enabled breakpoint at the same address. (In
3508that case, @value{GDBN} might see the other breakpoint first and stop your
3509program without checking the condition of this one.) Note that
d4f3574e
SS
3510breakpoint commands are usually more convenient and flexible than break
3511conditions for the
c906108c
SS
3512purpose of performing side effects when a breakpoint is reached
3513(@pxref{Break Commands, ,Breakpoint command lists}).
3514
3515Break conditions can be specified when a breakpoint is set, by using
3516@samp{if} in the arguments to the @code{break} command. @xref{Set
3517Breaks, ,Setting breakpoints}. They can also be changed at any time
3518with the @code{condition} command.
53a5351d 3519
c906108c
SS
3520You can also use the @code{if} keyword with the @code{watch} command.
3521The @code{catch} command does not recognize the @code{if} keyword;
3522@code{condition} is the only way to impose a further condition on a
3523catchpoint.
c906108c
SS
3524
3525@table @code
3526@kindex condition
3527@item condition @var{bnum} @var{expression}
3528Specify @var{expression} as the break condition for breakpoint,
3529watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3530breakpoint @var{bnum} stops your program only if the value of
3531@var{expression} is true (nonzero, in C). When you use
3532@code{condition}, @value{GDBN} checks @var{expression} immediately for
3533syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3534referents in the context of your breakpoint. If @var{expression} uses
3535symbols not referenced in the context of the breakpoint, @value{GDBN}
3536prints an error message:
3537
474c8240 3538@smallexample
d4f3574e 3539No symbol "foo" in current context.
474c8240 3540@end smallexample
d4f3574e
SS
3541
3542@noindent
c906108c
SS
3543@value{GDBN} does
3544not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3545command (or a command that sets a breakpoint with a condition, like
3546@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3547
3548@item condition @var{bnum}
3549Remove the condition from breakpoint number @var{bnum}. It becomes
3550an ordinary unconditional breakpoint.
3551@end table
3552
3553@cindex ignore count (of breakpoint)
3554A special case of a breakpoint condition is to stop only when the
3555breakpoint has been reached a certain number of times. This is so
3556useful that there is a special way to do it, using the @dfn{ignore
3557count} of the breakpoint. Every breakpoint has an ignore count, which
3558is an integer. Most of the time, the ignore count is zero, and
3559therefore has no effect. But if your program reaches a breakpoint whose
3560ignore count is positive, then instead of stopping, it just decrements
3561the ignore count by one and continues. As a result, if the ignore count
3562value is @var{n}, the breakpoint does not stop the next @var{n} times
3563your program reaches it.
3564
3565@table @code
3566@kindex ignore
3567@item ignore @var{bnum} @var{count}
3568Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3569The next @var{count} times the breakpoint is reached, your program's
3570execution does not stop; other than to decrement the ignore count, @value{GDBN}
3571takes no action.
3572
3573To make the breakpoint stop the next time it is reached, specify
3574a count of zero.
3575
3576When you use @code{continue} to resume execution of your program from a
3577breakpoint, you can specify an ignore count directly as an argument to
3578@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3579Stepping,,Continuing and stepping}.
3580
3581If a breakpoint has a positive ignore count and a condition, the
3582condition is not checked. Once the ignore count reaches zero,
3583@value{GDBN} resumes checking the condition.
3584
3585You could achieve the effect of the ignore count with a condition such
3586as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3587is decremented each time. @xref{Convenience Vars, ,Convenience
3588variables}.
3589@end table
3590
3591Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3592
3593
6d2ebf8b 3594@node Break Commands
c906108c
SS
3595@subsection Breakpoint command lists
3596
3597@cindex breakpoint commands
3598You can give any breakpoint (or watchpoint or catchpoint) a series of
3599commands to execute when your program stops due to that breakpoint. For
3600example, you might want to print the values of certain expressions, or
3601enable other breakpoints.
3602
3603@table @code
3604@kindex commands
ca91424e 3605@kindex end@r{ (breakpoint commands)}
c906108c
SS
3606@item commands @r{[}@var{bnum}@r{]}
3607@itemx @dots{} @var{command-list} @dots{}
3608@itemx end
3609Specify a list of commands for breakpoint number @var{bnum}. The commands
3610themselves appear on the following lines. Type a line containing just
3611@code{end} to terminate the commands.
3612
3613To remove all commands from a breakpoint, type @code{commands} and
3614follow it immediately with @code{end}; that is, give no commands.
3615
3616With no @var{bnum} argument, @code{commands} refers to the last
3617breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3618recently encountered).
3619@end table
3620
3621Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3622disabled within a @var{command-list}.
3623
3624You can use breakpoint commands to start your program up again. Simply
3625use the @code{continue} command, or @code{step}, or any other command
3626that resumes execution.
3627
3628Any other commands in the command list, after a command that resumes
3629execution, are ignored. This is because any time you resume execution
3630(even with a simple @code{next} or @code{step}), you may encounter
3631another breakpoint---which could have its own command list, leading to
3632ambiguities about which list to execute.
3633
3634@kindex silent
3635If the first command you specify in a command list is @code{silent}, the
3636usual message about stopping at a breakpoint is not printed. This may
3637be desirable for breakpoints that are to print a specific message and
3638then continue. If none of the remaining commands print anything, you
3639see no sign that the breakpoint was reached. @code{silent} is
3640meaningful only at the beginning of a breakpoint command list.
3641
3642The commands @code{echo}, @code{output}, and @code{printf} allow you to
3643print precisely controlled output, and are often useful in silent
3644breakpoints. @xref{Output, ,Commands for controlled output}.
3645
3646For example, here is how you could use breakpoint commands to print the
3647value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3648
474c8240 3649@smallexample
c906108c
SS
3650break foo if x>0
3651commands
3652silent
3653printf "x is %d\n",x
3654cont
3655end
474c8240 3656@end smallexample
c906108c
SS
3657
3658One application for breakpoint commands is to compensate for one bug so
3659you can test for another. Put a breakpoint just after the erroneous line
3660of code, give it a condition to detect the case in which something
3661erroneous has been done, and give it commands to assign correct values
3662to any variables that need them. End with the @code{continue} command
3663so that your program does not stop, and start with the @code{silent}
3664command so that no output is produced. Here is an example:
3665
474c8240 3666@smallexample
c906108c
SS
3667break 403
3668commands
3669silent
3670set x = y + 4
3671cont
3672end
474c8240 3673@end smallexample
c906108c 3674
6d2ebf8b 3675@node Breakpoint Menus
c906108c
SS
3676@subsection Breakpoint menus
3677@cindex overloading
3678@cindex symbol overloading
3679
b383017d 3680Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3681single function name
c906108c
SS
3682to be defined several times, for application in different contexts.
3683This is called @dfn{overloading}. When a function name is overloaded,
3684@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3685a breakpoint. If you realize this is a problem, you can use
3686something like @samp{break @var{function}(@var{types})} to specify which
3687particular version of the function you want. Otherwise, @value{GDBN} offers
3688you a menu of numbered choices for different possible breakpoints, and
3689waits for your selection with the prompt @samp{>}. The first two
3690options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3691sets a breakpoint at each definition of @var{function}, and typing
3692@kbd{0} aborts the @code{break} command without setting any new
3693breakpoints.
3694
3695For example, the following session excerpt shows an attempt to set a
3696breakpoint at the overloaded symbol @code{String::after}.
3697We choose three particular definitions of that function name:
3698
3699@c FIXME! This is likely to change to show arg type lists, at least
3700@smallexample
3701@group
3702(@value{GDBP}) b String::after
3703[0] cancel
3704[1] all
3705[2] file:String.cc; line number:867
3706[3] file:String.cc; line number:860
3707[4] file:String.cc; line number:875
3708[5] file:String.cc; line number:853
3709[6] file:String.cc; line number:846
3710[7] file:String.cc; line number:735
3711> 2 4 6
3712Breakpoint 1 at 0xb26c: file String.cc, line 867.
3713Breakpoint 2 at 0xb344: file String.cc, line 875.
3714Breakpoint 3 at 0xafcc: file String.cc, line 846.
3715Multiple breakpoints were set.
3716Use the "delete" command to delete unwanted
3717 breakpoints.
3718(@value{GDBP})
3719@end group
3720@end smallexample
c906108c
SS
3721
3722@c @ifclear BARETARGET
6d2ebf8b 3723@node Error in Breakpoints
d4f3574e 3724@subsection ``Cannot insert breakpoints''
c906108c
SS
3725@c
3726@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3727@c
d4f3574e
SS
3728Under some operating systems, breakpoints cannot be used in a program if
3729any other process is running that program. In this situation,
5d161b24 3730attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3731@value{GDBN} to print an error message:
3732
474c8240 3733@smallexample
d4f3574e
SS
3734Cannot insert breakpoints.
3735The same program may be running in another process.
474c8240 3736@end smallexample
d4f3574e
SS
3737
3738When this happens, you have three ways to proceed:
3739
3740@enumerate
3741@item
3742Remove or disable the breakpoints, then continue.
3743
3744@item
5d161b24 3745Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3746name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3747that @value{GDBN} should run your program under that name.
d4f3574e
SS
3748Then start your program again.
3749
3750@item
3751Relink your program so that the text segment is nonsharable, using the
3752linker option @samp{-N}. The operating system limitation may not apply
3753to nonsharable executables.
3754@end enumerate
c906108c
SS
3755@c @end ifclear
3756
d4f3574e
SS
3757A similar message can be printed if you request too many active
3758hardware-assisted breakpoints and watchpoints:
3759
3760@c FIXME: the precise wording of this message may change; the relevant
3761@c source change is not committed yet (Sep 3, 1999).
3762@smallexample
3763Stopped; cannot insert breakpoints.
3764You may have requested too many hardware breakpoints and watchpoints.
3765@end smallexample
3766
3767@noindent
3768This message is printed when you attempt to resume the program, since
3769only then @value{GDBN} knows exactly how many hardware breakpoints and
3770watchpoints it needs to insert.
3771
3772When this message is printed, you need to disable or remove some of the
3773hardware-assisted breakpoints and watchpoints, and then continue.
3774
1485d690
KB
3775@node Breakpoint related warnings
3776@subsection ``Breakpoint address adjusted...''
3777@cindex breakpoint address adjusted
3778
3779Some processor architectures place constraints on the addresses at
3780which breakpoints may be placed. For architectures thus constrained,
3781@value{GDBN} will attempt to adjust the breakpoint's address to comply
3782with the constraints dictated by the architecture.
3783
3784One example of such an architecture is the Fujitsu FR-V. The FR-V is
3785a VLIW architecture in which a number of RISC-like instructions may be
3786bundled together for parallel execution. The FR-V architecture
3787constrains the location of a breakpoint instruction within such a
3788bundle to the instruction with the lowest address. @value{GDBN}
3789honors this constraint by adjusting a breakpoint's address to the
3790first in the bundle.
3791
3792It is not uncommon for optimized code to have bundles which contain
3793instructions from different source statements, thus it may happen that
3794a breakpoint's address will be adjusted from one source statement to
3795another. Since this adjustment may significantly alter @value{GDBN}'s
3796breakpoint related behavior from what the user expects, a warning is
3797printed when the breakpoint is first set and also when the breakpoint
3798is hit.
3799
3800A warning like the one below is printed when setting a breakpoint
3801that's been subject to address adjustment:
3802
3803@smallexample
3804warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3805@end smallexample
3806
3807Such warnings are printed both for user settable and @value{GDBN}'s
3808internal breakpoints. If you see one of these warnings, you should
3809verify that a breakpoint set at the adjusted address will have the
3810desired affect. If not, the breakpoint in question may be removed and
b383017d 3811other breakpoints may be set which will have the desired behavior.
1485d690
KB
3812E.g., it may be sufficient to place the breakpoint at a later
3813instruction. A conditional breakpoint may also be useful in some
3814cases to prevent the breakpoint from triggering too often.
3815
3816@value{GDBN} will also issue a warning when stopping at one of these
3817adjusted breakpoints:
3818
3819@smallexample
3820warning: Breakpoint 1 address previously adjusted from 0x00010414
3821to 0x00010410.
3822@end smallexample
3823
3824When this warning is encountered, it may be too late to take remedial
3825action except in cases where the breakpoint is hit earlier or more
3826frequently than expected.
d4f3574e 3827
6d2ebf8b 3828@node Continuing and Stepping
c906108c
SS
3829@section Continuing and stepping
3830
3831@cindex stepping
3832@cindex continuing
3833@cindex resuming execution
3834@dfn{Continuing} means resuming program execution until your program
3835completes normally. In contrast, @dfn{stepping} means executing just
3836one more ``step'' of your program, where ``step'' may mean either one
3837line of source code, or one machine instruction (depending on what
7a292a7a
SS
3838particular command you use). Either when continuing or when stepping,
3839your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3840it stops due to a signal, you may want to use @code{handle}, or use
3841@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3842
3843@table @code
3844@kindex continue
41afff9a
EZ
3845@kindex c @r{(@code{continue})}
3846@kindex fg @r{(resume foreground execution)}
c906108c
SS
3847@item continue @r{[}@var{ignore-count}@r{]}
3848@itemx c @r{[}@var{ignore-count}@r{]}
3849@itemx fg @r{[}@var{ignore-count}@r{]}
3850Resume program execution, at the address where your program last stopped;
3851any breakpoints set at that address are bypassed. The optional argument
3852@var{ignore-count} allows you to specify a further number of times to
3853ignore a breakpoint at this location; its effect is like that of
3854@code{ignore} (@pxref{Conditions, ,Break conditions}).
3855
3856The argument @var{ignore-count} is meaningful only when your program
3857stopped due to a breakpoint. At other times, the argument to
3858@code{continue} is ignored.
3859
d4f3574e
SS
3860The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3861debugged program is deemed to be the foreground program) are provided
3862purely for convenience, and have exactly the same behavior as
3863@code{continue}.
c906108c
SS
3864@end table
3865
3866To resume execution at a different place, you can use @code{return}
3867(@pxref{Returning, ,Returning from a function}) to go back to the
3868calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3869different address}) to go to an arbitrary location in your program.
3870
3871A typical technique for using stepping is to set a breakpoint
3872(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3873beginning of the function or the section of your program where a problem
3874is believed to lie, run your program until it stops at that breakpoint,
3875and then step through the suspect area, examining the variables that are
3876interesting, until you see the problem happen.
3877
3878@table @code
3879@kindex step
41afff9a 3880@kindex s @r{(@code{step})}
c906108c
SS
3881@item step
3882Continue running your program until control reaches a different source
3883line, then stop it and return control to @value{GDBN}. This command is
3884abbreviated @code{s}.
3885
3886@quotation
3887@c "without debugging information" is imprecise; actually "without line
3888@c numbers in the debugging information". (gcc -g1 has debugging info but
3889@c not line numbers). But it seems complex to try to make that
3890@c distinction here.
3891@emph{Warning:} If you use the @code{step} command while control is
3892within a function that was compiled without debugging information,
3893execution proceeds until control reaches a function that does have
3894debugging information. Likewise, it will not step into a function which
3895is compiled without debugging information. To step through functions
3896without debugging information, use the @code{stepi} command, described
3897below.
3898@end quotation
3899
4a92d011
EZ
3900The @code{step} command only stops at the first instruction of a source
3901line. This prevents the multiple stops that could otherwise occur in
3902@code{switch} statements, @code{for} loops, etc. @code{step} continues
3903to stop if a function that has debugging information is called within
3904the line. In other words, @code{step} @emph{steps inside} any functions
3905called within the line.
c906108c 3906
d4f3574e
SS
3907Also, the @code{step} command only enters a function if there is line
3908number information for the function. Otherwise it acts like the
5d161b24 3909@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3910on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3911was any debugging information about the routine.
c906108c
SS
3912
3913@item step @var{count}
3914Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3915breakpoint is reached, or a signal not related to stepping occurs before
3916@var{count} steps, stepping stops right away.
c906108c
SS
3917
3918@kindex next
41afff9a 3919@kindex n @r{(@code{next})}
c906108c
SS
3920@item next @r{[}@var{count}@r{]}
3921Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3922This is similar to @code{step}, but function calls that appear within
3923the line of code are executed without stopping. Execution stops when
3924control reaches a different line of code at the original stack level
3925that was executing when you gave the @code{next} command. This command
3926is abbreviated @code{n}.
c906108c
SS
3927
3928An argument @var{count} is a repeat count, as for @code{step}.
3929
3930
3931@c FIX ME!! Do we delete this, or is there a way it fits in with
3932@c the following paragraph? --- Vctoria
3933@c
3934@c @code{next} within a function that lacks debugging information acts like
3935@c @code{step}, but any function calls appearing within the code of the
3936@c function are executed without stopping.
3937
d4f3574e
SS
3938The @code{next} command only stops at the first instruction of a
3939source line. This prevents multiple stops that could otherwise occur in
4a92d011 3940@code{switch} statements, @code{for} loops, etc.
c906108c 3941
b90a5f51
CF
3942@kindex set step-mode
3943@item set step-mode
3944@cindex functions without line info, and stepping
3945@cindex stepping into functions with no line info
3946@itemx set step-mode on
4a92d011 3947The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3948stop at the first instruction of a function which contains no debug line
3949information rather than stepping over it.
3950
4a92d011
EZ
3951This is useful in cases where you may be interested in inspecting the
3952machine instructions of a function which has no symbolic info and do not
3953want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3954
3955@item set step-mode off
4a92d011 3956Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3957debug information. This is the default.
3958
9c16f35a
EZ
3959@item show step-mode
3960Show whether @value{GDBN} will stop in or step over functions without
3961source line debug information.
3962
c906108c
SS
3963@kindex finish
3964@item finish
3965Continue running until just after function in the selected stack frame
3966returns. Print the returned value (if any).
3967
3968Contrast this with the @code{return} command (@pxref{Returning,
3969,Returning from a function}).
3970
3971@kindex until
41afff9a 3972@kindex u @r{(@code{until})}
09d4efe1 3973@cindex run until specified location
c906108c
SS
3974@item until
3975@itemx u
3976Continue running until a source line past the current line, in the
3977current stack frame, is reached. This command is used to avoid single
3978stepping through a loop more than once. It is like the @code{next}
3979command, except that when @code{until} encounters a jump, it
3980automatically continues execution until the program counter is greater
3981than the address of the jump.
3982
3983This means that when you reach the end of a loop after single stepping
3984though it, @code{until} makes your program continue execution until it
3985exits the loop. In contrast, a @code{next} command at the end of a loop
3986simply steps back to the beginning of the loop, which forces you to step
3987through the next iteration.
3988
3989@code{until} always stops your program if it attempts to exit the current
3990stack frame.
3991
3992@code{until} may produce somewhat counterintuitive results if the order
3993of machine code does not match the order of the source lines. For
3994example, in the following excerpt from a debugging session, the @code{f}
3995(@code{frame}) command shows that execution is stopped at line
3996@code{206}; yet when we use @code{until}, we get to line @code{195}:
3997
474c8240 3998@smallexample
c906108c
SS
3999(@value{GDBP}) f
4000#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
4001206 expand_input();
4002(@value{GDBP}) until
4003195 for ( ; argc > 0; NEXTARG) @{
474c8240 4004@end smallexample
c906108c
SS
4005
4006This happened because, for execution efficiency, the compiler had
4007generated code for the loop closure test at the end, rather than the
4008start, of the loop---even though the test in a C @code{for}-loop is
4009written before the body of the loop. The @code{until} command appeared
4010to step back to the beginning of the loop when it advanced to this
4011expression; however, it has not really gone to an earlier
4012statement---not in terms of the actual machine code.
4013
4014@code{until} with no argument works by means of single
4015instruction stepping, and hence is slower than @code{until} with an
4016argument.
4017
4018@item until @var{location}
4019@itemx u @var{location}
4020Continue running your program until either the specified location is
4021reached, or the current stack frame returns. @var{location} is any of
4022the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
4023,Setting breakpoints}). This form of the command uses breakpoints, and
4024hence is quicker than @code{until} without an argument. The specified
4025location is actually reached only if it is in the current frame. This
4026implies that @code{until} can be used to skip over recursive function
4027invocations. For instance in the code below, if the current location is
4028line @code{96}, issuing @code{until 99} will execute the program up to
4029line @code{99} in the same invocation of factorial, i.e. after the inner
4030invocations have returned.
4031
4032@smallexample
403394 int factorial (int value)
403495 @{
403596 if (value > 1) @{
403697 value *= factorial (value - 1);
403798 @}
403899 return (value);
4039100 @}
4040@end smallexample
4041
4042
4043@kindex advance @var{location}
4044@itemx advance @var{location}
09d4efe1
EZ
4045Continue running the program up to the given @var{location}. An argument is
4046required, which should be of the same form as arguments for the @code{break}
c60eb6f1
EZ
4047command. Execution will also stop upon exit from the current stack
4048frame. This command is similar to @code{until}, but @code{advance} will
4049not skip over recursive function calls, and the target location doesn't
4050have to be in the same frame as the current one.
4051
c906108c
SS
4052
4053@kindex stepi
41afff9a 4054@kindex si @r{(@code{stepi})}
c906108c 4055@item stepi
96a2c332 4056@itemx stepi @var{arg}
c906108c
SS
4057@itemx si
4058Execute one machine instruction, then stop and return to the debugger.
4059
4060It is often useful to do @samp{display/i $pc} when stepping by machine
4061instructions. This makes @value{GDBN} automatically display the next
4062instruction to be executed, each time your program stops. @xref{Auto
4063Display,, Automatic display}.
4064
4065An argument is a repeat count, as in @code{step}.
4066
4067@need 750
4068@kindex nexti
41afff9a 4069@kindex ni @r{(@code{nexti})}
c906108c 4070@item nexti
96a2c332 4071@itemx nexti @var{arg}
c906108c
SS
4072@itemx ni
4073Execute one machine instruction, but if it is a function call,
4074proceed until the function returns.
4075
4076An argument is a repeat count, as in @code{next}.
4077@end table
4078
6d2ebf8b 4079@node Signals
c906108c
SS
4080@section Signals
4081@cindex signals
4082
4083A signal is an asynchronous event that can happen in a program. The
4084operating system defines the possible kinds of signals, and gives each
4085kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 4086signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
4087@code{SIGSEGV} is the signal a program gets from referencing a place in
4088memory far away from all the areas in use; @code{SIGALRM} occurs when
4089the alarm clock timer goes off (which happens only if your program has
4090requested an alarm).
4091
4092@cindex fatal signals
4093Some signals, including @code{SIGALRM}, are a normal part of the
4094functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 4095errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
4096program has not specified in advance some other way to handle the signal.
4097@code{SIGINT} does not indicate an error in your program, but it is normally
4098fatal so it can carry out the purpose of the interrupt: to kill the program.
4099
4100@value{GDBN} has the ability to detect any occurrence of a signal in your
4101program. You can tell @value{GDBN} in advance what to do for each kind of
4102signal.
4103
4104@cindex handling signals
24f93129
EZ
4105Normally, @value{GDBN} is set up to let the non-erroneous signals like
4106@code{SIGALRM} be silently passed to your program
4107(so as not to interfere with their role in the program's functioning)
c906108c
SS
4108but to stop your program immediately whenever an error signal happens.
4109You can change these settings with the @code{handle} command.
4110
4111@table @code
4112@kindex info signals
09d4efe1 4113@kindex info handle
c906108c 4114@item info signals
96a2c332 4115@itemx info handle
c906108c
SS
4116Print a table of all the kinds of signals and how @value{GDBN} has been told to
4117handle each one. You can use this to see the signal numbers of all
4118the defined types of signals.
4119
d4f3574e 4120@code{info handle} is an alias for @code{info signals}.
c906108c
SS
4121
4122@kindex handle
4123@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
4124Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
4125can be the number of a signal or its name (with or without the
24f93129 4126@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
4127@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
4128known signals. The @var{keywords} say what change to make.
c906108c
SS
4129@end table
4130
4131@c @group
4132The keywords allowed by the @code{handle} command can be abbreviated.
4133Their full names are:
4134
4135@table @code
4136@item nostop
4137@value{GDBN} should not stop your program when this signal happens. It may
4138still print a message telling you that the signal has come in.
4139
4140@item stop
4141@value{GDBN} should stop your program when this signal happens. This implies
4142the @code{print} keyword as well.
4143
4144@item print
4145@value{GDBN} should print a message when this signal happens.
4146
4147@item noprint
4148@value{GDBN} should not mention the occurrence of the signal at all. This
4149implies the @code{nostop} keyword as well.
4150
4151@item pass
5ece1a18 4152@itemx noignore
c906108c
SS
4153@value{GDBN} should allow your program to see this signal; your program
4154can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 4155and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
4156
4157@item nopass
5ece1a18 4158@itemx ignore
c906108c 4159@value{GDBN} should not allow your program to see this signal.
5ece1a18 4160@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
4161@end table
4162@c @end group
4163
d4f3574e
SS
4164When a signal stops your program, the signal is not visible to the
4165program until you
c906108c
SS
4166continue. Your program sees the signal then, if @code{pass} is in
4167effect for the signal in question @emph{at that time}. In other words,
4168after @value{GDBN} reports a signal, you can use the @code{handle}
4169command with @code{pass} or @code{nopass} to control whether your
4170program sees that signal when you continue.
4171
24f93129
EZ
4172The default is set to @code{nostop}, @code{noprint}, @code{pass} for
4173non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
4174@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
4175erroneous signals.
4176
c906108c
SS
4177You can also use the @code{signal} command to prevent your program from
4178seeing a signal, or cause it to see a signal it normally would not see,
4179or to give it any signal at any time. For example, if your program stopped
4180due to some sort of memory reference error, you might store correct
4181values into the erroneous variables and continue, hoping to see more
4182execution; but your program would probably terminate immediately as
4183a result of the fatal signal once it saw the signal. To prevent this,
4184you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 4185program a signal}.
c906108c 4186
6d2ebf8b 4187@node Thread Stops
c906108c
SS
4188@section Stopping and starting multi-thread programs
4189
4190When your program has multiple threads (@pxref{Threads,, Debugging
4191programs with multiple threads}), you can choose whether to set
4192breakpoints on all threads, or on a particular thread.
4193
4194@table @code
4195@cindex breakpoints and threads
4196@cindex thread breakpoints
4197@kindex break @dots{} thread @var{threadno}
4198@item break @var{linespec} thread @var{threadno}
4199@itemx break @var{linespec} thread @var{threadno} if @dots{}
4200@var{linespec} specifies source lines; there are several ways of
4201writing them, but the effect is always to specify some source line.
4202
4203Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
4204to specify that you only want @value{GDBN} to stop the program when a
4205particular thread reaches this breakpoint. @var{threadno} is one of the
4206numeric thread identifiers assigned by @value{GDBN}, shown in the first
4207column of the @samp{info threads} display.
4208
4209If you do not specify @samp{thread @var{threadno}} when you set a
4210breakpoint, the breakpoint applies to @emph{all} threads of your
4211program.
4212
4213You can use the @code{thread} qualifier on conditional breakpoints as
4214well; in this case, place @samp{thread @var{threadno}} before the
4215breakpoint condition, like this:
4216
4217@smallexample
2df3850c 4218(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
4219@end smallexample
4220
4221@end table
4222
4223@cindex stopped threads
4224@cindex threads, stopped
4225Whenever your program stops under @value{GDBN} for any reason,
4226@emph{all} threads of execution stop, not just the current thread. This
4227allows you to examine the overall state of the program, including
4228switching between threads, without worrying that things may change
4229underfoot.
4230
36d86913
MC
4231@cindex thread breakpoints and system calls
4232@cindex system calls and thread breakpoints
4233@cindex premature return from system calls
4234There is an unfortunate side effect. If one thread stops for a
4235breakpoint, or for some other reason, and another thread is blocked in a
4236system call, then the system call may return prematurely. This is a
4237consequence of the interaction between multiple threads and the signals
4238that @value{GDBN} uses to implement breakpoints and other events that
4239stop execution.
4240
4241To handle this problem, your program should check the return value of
4242each system call and react appropriately. This is good programming
4243style anyways.
4244
4245For example, do not write code like this:
4246
4247@smallexample
4248 sleep (10);
4249@end smallexample
4250
4251The call to @code{sleep} will return early if a different thread stops
4252at a breakpoint or for some other reason.
4253
4254Instead, write this:
4255
4256@smallexample
4257 int unslept = 10;
4258 while (unslept > 0)
4259 unslept = sleep (unslept);
4260@end smallexample
4261
4262A system call is allowed to return early, so the system is still
4263conforming to its specification. But @value{GDBN} does cause your
4264multi-threaded program to behave differently than it would without
4265@value{GDBN}.
4266
4267Also, @value{GDBN} uses internal breakpoints in the thread library to
4268monitor certain events such as thread creation and thread destruction.
4269When such an event happens, a system call in another thread may return
4270prematurely, even though your program does not appear to stop.
4271
c906108c
SS
4272@cindex continuing threads
4273@cindex threads, continuing
4274Conversely, whenever you restart the program, @emph{all} threads start
4275executing. @emph{This is true even when single-stepping} with commands
5d161b24 4276like @code{step} or @code{next}.
c906108c
SS
4277
4278In particular, @value{GDBN} cannot single-step all threads in lockstep.
4279Since thread scheduling is up to your debugging target's operating
4280system (not controlled by @value{GDBN}), other threads may
4281execute more than one statement while the current thread completes a
4282single step. Moreover, in general other threads stop in the middle of a
4283statement, rather than at a clean statement boundary, when the program
4284stops.
4285
4286You might even find your program stopped in another thread after
4287continuing or even single-stepping. This happens whenever some other
4288thread runs into a breakpoint, a signal, or an exception before the
4289first thread completes whatever you requested.
4290
4291On some OSes, you can lock the OS scheduler and thus allow only a single
4292thread to run.
4293
4294@table @code
4295@item set scheduler-locking @var{mode}
9c16f35a
EZ
4296@cindex scheduler locking mode
4297@cindex lock scheduler
c906108c
SS
4298Set the scheduler locking mode. If it is @code{off}, then there is no
4299locking and any thread may run at any time. If @code{on}, then only the
4300current thread may run when the inferior is resumed. The @code{step}
4301mode optimizes for single-stepping. It stops other threads from
4302``seizing the prompt'' by preempting the current thread while you are
4303stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 4304when you step. They are more likely to run when you @samp{next} over a
c906108c 4305function call, and they are completely free to run when you use commands
d4f3574e 4306like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 4307thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 4308@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
4309
4310@item show scheduler-locking
4311Display the current scheduler locking mode.
4312@end table
4313
c906108c 4314
6d2ebf8b 4315@node Stack
c906108c
SS
4316@chapter Examining the Stack
4317
4318When your program has stopped, the first thing you need to know is where it
4319stopped and how it got there.
4320
4321@cindex call stack
5d161b24
DB
4322Each time your program performs a function call, information about the call
4323is generated.
4324That information includes the location of the call in your program,
4325the arguments of the call,
c906108c 4326and the local variables of the function being called.
5d161b24 4327The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
4328The stack frames are allocated in a region of memory called the @dfn{call
4329stack}.
4330
4331When your program stops, the @value{GDBN} commands for examining the
4332stack allow you to see all of this information.
4333
4334@cindex selected frame
4335One of the stack frames is @dfn{selected} by @value{GDBN} and many
4336@value{GDBN} commands refer implicitly to the selected frame. In
4337particular, whenever you ask @value{GDBN} for the value of a variable in
4338your program, the value is found in the selected frame. There are
4339special @value{GDBN} commands to select whichever frame you are
4340interested in. @xref{Selection, ,Selecting a frame}.
4341
4342When your program stops, @value{GDBN} automatically selects the
5d161b24 4343currently executing frame and describes it briefly, similar to the
c906108c
SS
4344@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
4345
4346@menu
4347* Frames:: Stack frames
4348* Backtrace:: Backtraces
4349* Selection:: Selecting a frame
4350* Frame Info:: Information on a frame
c906108c
SS
4351
4352@end menu
4353
6d2ebf8b 4354@node Frames
c906108c
SS
4355@section Stack frames
4356
d4f3574e 4357@cindex frame, definition
c906108c
SS
4358@cindex stack frame
4359The call stack is divided up into contiguous pieces called @dfn{stack
4360frames}, or @dfn{frames} for short; each frame is the data associated
4361with one call to one function. The frame contains the arguments given
4362to the function, the function's local variables, and the address at
4363which the function is executing.
4364
4365@cindex initial frame
4366@cindex outermost frame
4367@cindex innermost frame
4368When your program is started, the stack has only one frame, that of the
4369function @code{main}. This is called the @dfn{initial} frame or the
4370@dfn{outermost} frame. Each time a function is called, a new frame is
4371made. Each time a function returns, the frame for that function invocation
4372is eliminated. If a function is recursive, there can be many frames for
4373the same function. The frame for the function in which execution is
4374actually occurring is called the @dfn{innermost} frame. This is the most
4375recently created of all the stack frames that still exist.
4376
4377@cindex frame pointer
4378Inside your program, stack frames are identified by their addresses. A
4379stack frame consists of many bytes, each of which has its own address; each
4380kind of computer has a convention for choosing one byte whose
4381address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
4382in a register called the @dfn{frame pointer register}
4383(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
4384
4385@cindex frame number
4386@value{GDBN} assigns numbers to all existing stack frames, starting with
4387zero for the innermost frame, one for the frame that called it,
4388and so on upward. These numbers do not really exist in your program;
4389they are assigned by @value{GDBN} to give you a way of designating stack
4390frames in @value{GDBN} commands.
4391
6d2ebf8b
SS
4392@c The -fomit-frame-pointer below perennially causes hbox overflow
4393@c underflow problems.
c906108c
SS
4394@cindex frameless execution
4395Some compilers provide a way to compile functions so that they operate
6d2ebf8b 4396without stack frames. (For example, the @value{GCC} option
474c8240 4397@smallexample
6d2ebf8b 4398@samp{-fomit-frame-pointer}
474c8240 4399@end smallexample
6d2ebf8b 4400generates functions without a frame.)
c906108c
SS
4401This is occasionally done with heavily used library functions to save
4402the frame setup time. @value{GDBN} has limited facilities for dealing
4403with these function invocations. If the innermost function invocation
4404has no stack frame, @value{GDBN} nevertheless regards it as though
4405it had a separate frame, which is numbered zero as usual, allowing
4406correct tracing of the function call chain. However, @value{GDBN} has
4407no provision for frameless functions elsewhere in the stack.
4408
4409@table @code
d4f3574e 4410@kindex frame@r{, command}
41afff9a 4411@cindex current stack frame
c906108c 4412@item frame @var{args}
5d161b24 4413The @code{frame} command allows you to move from one stack frame to another,
c906108c 4414and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4415address of the frame or the stack frame number. Without an argument,
4416@code{frame} prints the current stack frame.
c906108c
SS
4417
4418@kindex select-frame
41afff9a 4419@cindex selecting frame silently
c906108c
SS
4420@item select-frame
4421The @code{select-frame} command allows you to move from one stack frame
4422to another without printing the frame. This is the silent version of
4423@code{frame}.
4424@end table
4425
6d2ebf8b 4426@node Backtrace
c906108c
SS
4427@section Backtraces
4428
09d4efe1
EZ
4429@cindex traceback
4430@cindex call stack traces
c906108c
SS
4431A backtrace is a summary of how your program got where it is. It shows one
4432line per frame, for many frames, starting with the currently executing
4433frame (frame zero), followed by its caller (frame one), and on up the
4434stack.
4435
4436@table @code
4437@kindex backtrace
41afff9a 4438@kindex bt @r{(@code{backtrace})}
c906108c
SS
4439@item backtrace
4440@itemx bt
4441Print a backtrace of the entire stack: one line per frame for all
4442frames in the stack.
4443
4444You can stop the backtrace at any time by typing the system interrupt
4445character, normally @kbd{C-c}.
4446
4447@item backtrace @var{n}
4448@itemx bt @var{n}
4449Similar, but print only the innermost @var{n} frames.
4450
4451@item backtrace -@var{n}
4452@itemx bt -@var{n}
4453Similar, but print only the outermost @var{n} frames.
0f061b69
NR
4454
4455@item backtrace full
4456Print the values of the local variables also.
4457@itemx bt full
c906108c
SS
4458@end table
4459
4460@kindex where
4461@kindex info stack
c906108c
SS
4462The names @code{where} and @code{info stack} (abbreviated @code{info s})
4463are additional aliases for @code{backtrace}.
4464
839c27b7
EZ
4465@cindex multiple threads, backtrace
4466In a multi-threaded program, @value{GDBN} by default shows the
4467backtrace only for the current thread. To display the backtrace for
4468several or all of the threads, use the command @code{thread apply}
4469(@pxref{Threads, thread apply}). For example, if you type @kbd{thread
4470apply all backtrace}, @value{GDBN} will display the backtrace for all
4471the threads; this is handy when you debug a core dump of a
4472multi-threaded program.
4473
c906108c
SS
4474Each line in the backtrace shows the frame number and the function name.
4475The program counter value is also shown---unless you use @code{set
4476print address off}. The backtrace also shows the source file name and
4477line number, as well as the arguments to the function. The program
4478counter value is omitted if it is at the beginning of the code for that
4479line number.
4480
4481Here is an example of a backtrace. It was made with the command
4482@samp{bt 3}, so it shows the innermost three frames.
4483
4484@smallexample
4485@group
5d161b24 4486#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4487 at builtin.c:993
4488#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4489#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4490 at macro.c:71
4491(More stack frames follow...)
4492@end group
4493@end smallexample
4494
4495@noindent
4496The display for frame zero does not begin with a program counter
4497value, indicating that your program has stopped at the beginning of the
4498code for line @code{993} of @code{builtin.c}.
4499
18999be5
EZ
4500@cindex value optimized out, in backtrace
4501@cindex function call arguments, optimized out
4502If your program was compiled with optimizations, some compilers will
4503optimize away arguments passed to functions if those arguments are
4504never used after the call. Such optimizations generate code that
4505passes arguments through registers, but doesn't store those arguments
4506in the stack frame. @value{GDBN} has no way of displaying such
4507arguments in stack frames other than the innermost one. Here's what
4508such a backtrace might look like:
4509
4510@smallexample
4511@group
4512#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4513 at builtin.c:993
4514#1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
4515#2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
4516 at macro.c:71
4517(More stack frames follow...)
4518@end group
4519@end smallexample
4520
4521@noindent
4522The values of arguments that were not saved in their stack frames are
4523shown as @samp{<value optimized out>}.
4524
4525If you need to display the values of such optimized-out arguments,
4526either deduce that from other variables whose values depend on the one
4527you are interested in, or recompile without optimizations.
4528
a8f24a35
EZ
4529@cindex backtrace beyond @code{main} function
4530@cindex program entry point
4531@cindex startup code, and backtrace
25d29d70
AC
4532Most programs have a standard user entry point---a place where system
4533libraries and startup code transition into user code. For C this is
d416eeec
EZ
4534@code{main}@footnote{
4535Note that embedded programs (the so-called ``free-standing''
4536environment) are not required to have a @code{main} function as the
4537entry point. They could even have multiple entry points.}.
4538When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
4539it will terminate the backtrace, to avoid tracing into highly
4540system-specific (and generally uninteresting) code.
4541
4542If you need to examine the startup code, or limit the number of levels
4543in a backtrace, you can change this behavior:
95f90d25
DJ
4544
4545@table @code
25d29d70
AC
4546@item set backtrace past-main
4547@itemx set backtrace past-main on
4644b6e3 4548@kindex set backtrace
25d29d70
AC
4549Backtraces will continue past the user entry point.
4550
4551@item set backtrace past-main off
95f90d25
DJ
4552Backtraces will stop when they encounter the user entry point. This is the
4553default.
4554
25d29d70 4555@item show backtrace past-main
4644b6e3 4556@kindex show backtrace
25d29d70
AC
4557Display the current user entry point backtrace policy.
4558
2315ffec
RC
4559@item set backtrace past-entry
4560@itemx set backtrace past-entry on
a8f24a35 4561Backtraces will continue past the internal entry point of an application.
2315ffec
RC
4562This entry point is encoded by the linker when the application is built,
4563and is likely before the user entry point @code{main} (or equivalent) is called.
4564
4565@item set backtrace past-entry off
4566Backtraces will stop when they encouter the internal entry point of an
4567application. This is the default.
4568
4569@item show backtrace past-entry
4570Display the current internal entry point backtrace policy.
4571
25d29d70
AC
4572@item set backtrace limit @var{n}
4573@itemx set backtrace limit 0
4574@cindex backtrace limit
4575Limit the backtrace to @var{n} levels. A value of zero means
4576unlimited.
95f90d25 4577
25d29d70
AC
4578@item show backtrace limit
4579Display the current limit on backtrace levels.
95f90d25
DJ
4580@end table
4581
6d2ebf8b 4582@node Selection
c906108c
SS
4583@section Selecting a frame
4584
4585Most commands for examining the stack and other data in your program work on
4586whichever stack frame is selected at the moment. Here are the commands for
4587selecting a stack frame; all of them finish by printing a brief description
4588of the stack frame just selected.
4589
4590@table @code
d4f3574e 4591@kindex frame@r{, selecting}
41afff9a 4592@kindex f @r{(@code{frame})}
c906108c
SS
4593@item frame @var{n}
4594@itemx f @var{n}
4595Select frame number @var{n}. Recall that frame zero is the innermost
4596(currently executing) frame, frame one is the frame that called the
4597innermost one, and so on. The highest-numbered frame is the one for
4598@code{main}.
4599
4600@item frame @var{addr}
4601@itemx f @var{addr}
4602Select the frame at address @var{addr}. This is useful mainly if the
4603chaining of stack frames has been damaged by a bug, making it
4604impossible for @value{GDBN} to assign numbers properly to all frames. In
4605addition, this can be useful when your program has multiple stacks and
4606switches between them.
4607
c906108c
SS
4608On the SPARC architecture, @code{frame} needs two addresses to
4609select an arbitrary frame: a frame pointer and a stack pointer.
4610
4611On the MIPS and Alpha architecture, it needs two addresses: a stack
4612pointer and a program counter.
4613
4614On the 29k architecture, it needs three addresses: a register stack
4615pointer, a program counter, and a memory stack pointer.
c906108c
SS
4616
4617@kindex up
4618@item up @var{n}
4619Move @var{n} frames up the stack. For positive numbers @var{n}, this
4620advances toward the outermost frame, to higher frame numbers, to frames
4621that have existed longer. @var{n} defaults to one.
4622
4623@kindex down
41afff9a 4624@kindex do @r{(@code{down})}
c906108c
SS
4625@item down @var{n}
4626Move @var{n} frames down the stack. For positive numbers @var{n}, this
4627advances toward the innermost frame, to lower frame numbers, to frames
4628that were created more recently. @var{n} defaults to one. You may
4629abbreviate @code{down} as @code{do}.
4630@end table
4631
4632All of these commands end by printing two lines of output describing the
4633frame. The first line shows the frame number, the function name, the
4634arguments, and the source file and line number of execution in that
5d161b24 4635frame. The second line shows the text of that source line.
c906108c
SS
4636
4637@need 1000
4638For example:
4639
4640@smallexample
4641@group
4642(@value{GDBP}) up
4643#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4644 at env.c:10
464510 read_input_file (argv[i]);
4646@end group
4647@end smallexample
4648
4649After such a printout, the @code{list} command with no arguments
4650prints ten lines centered on the point of execution in the frame.
87885426
FN
4651You can also edit the program at the point of execution with your favorite
4652editing program by typing @code{edit}.
4653@xref{List, ,Printing source lines},
4654for details.
c906108c
SS
4655
4656@table @code
4657@kindex down-silently
4658@kindex up-silently
4659@item up-silently @var{n}
4660@itemx down-silently @var{n}
4661These two commands are variants of @code{up} and @code{down},
4662respectively; they differ in that they do their work silently, without
4663causing display of the new frame. They are intended primarily for use
4664in @value{GDBN} command scripts, where the output might be unnecessary and
4665distracting.
4666@end table
4667
6d2ebf8b 4668@node Frame Info
c906108c
SS
4669@section Information about a frame
4670
4671There are several other commands to print information about the selected
4672stack frame.
4673
4674@table @code
4675@item frame
4676@itemx f
4677When used without any argument, this command does not change which
4678frame is selected, but prints a brief description of the currently
4679selected stack frame. It can be abbreviated @code{f}. With an
4680argument, this command is used to select a stack frame.
4681@xref{Selection, ,Selecting a frame}.
4682
4683@kindex info frame
41afff9a 4684@kindex info f @r{(@code{info frame})}
c906108c
SS
4685@item info frame
4686@itemx info f
4687This command prints a verbose description of the selected stack frame,
4688including:
4689
4690@itemize @bullet
5d161b24
DB
4691@item
4692the address of the frame
c906108c
SS
4693@item
4694the address of the next frame down (called by this frame)
4695@item
4696the address of the next frame up (caller of this frame)
4697@item
4698the language in which the source code corresponding to this frame is written
4699@item
4700the address of the frame's arguments
4701@item
d4f3574e
SS
4702the address of the frame's local variables
4703@item
c906108c
SS
4704the program counter saved in it (the address of execution in the caller frame)
4705@item
4706which registers were saved in the frame
4707@end itemize
4708
4709@noindent The verbose description is useful when
4710something has gone wrong that has made the stack format fail to fit
4711the usual conventions.
4712
4713@item info frame @var{addr}
4714@itemx info f @var{addr}
4715Print a verbose description of the frame at address @var{addr}, without
4716selecting that frame. The selected frame remains unchanged by this
4717command. This requires the same kind of address (more than one for some
4718architectures) that you specify in the @code{frame} command.
4719@xref{Selection, ,Selecting a frame}.
4720
4721@kindex info args
4722@item info args
4723Print the arguments of the selected frame, each on a separate line.
4724
4725@item info locals
4726@kindex info locals
4727Print the local variables of the selected frame, each on a separate
4728line. These are all variables (declared either static or automatic)
4729accessible at the point of execution of the selected frame.
4730
c906108c 4731@kindex info catch
d4f3574e
SS
4732@cindex catch exceptions, list active handlers
4733@cindex exception handlers, how to list
c906108c
SS
4734@item info catch
4735Print a list of all the exception handlers that are active in the
4736current stack frame at the current point of execution. To see other
4737exception handlers, visit the associated frame (using the @code{up},
4738@code{down}, or @code{frame} commands); then type @code{info catch}.
4739@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4740
c906108c
SS
4741@end table
4742
c906108c 4743
6d2ebf8b 4744@node Source
c906108c
SS
4745@chapter Examining Source Files
4746
4747@value{GDBN} can print parts of your program's source, since the debugging
4748information recorded in the program tells @value{GDBN} what source files were
4749used to build it. When your program stops, @value{GDBN} spontaneously prints
4750the line where it stopped. Likewise, when you select a stack frame
4751(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4752execution in that frame has stopped. You can print other portions of
4753source files by explicit command.
4754
7a292a7a 4755If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4756prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4757@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4758
4759@menu
4760* List:: Printing source lines
87885426 4761* Edit:: Editing source files
c906108c 4762* Search:: Searching source files
c906108c
SS
4763* Source Path:: Specifying source directories
4764* Machine Code:: Source and machine code
4765@end menu
4766
6d2ebf8b 4767@node List
c906108c
SS
4768@section Printing source lines
4769
4770@kindex list
41afff9a 4771@kindex l @r{(@code{list})}
c906108c 4772To print lines from a source file, use the @code{list} command
5d161b24 4773(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4774There are several ways to specify what part of the file you want to print.
4775
4776Here are the forms of the @code{list} command most commonly used:
4777
4778@table @code
4779@item list @var{linenum}
4780Print lines centered around line number @var{linenum} in the
4781current source file.
4782
4783@item list @var{function}
4784Print lines centered around the beginning of function
4785@var{function}.
4786
4787@item list
4788Print more lines. If the last lines printed were printed with a
4789@code{list} command, this prints lines following the last lines
4790printed; however, if the last line printed was a solitary line printed
4791as part of displaying a stack frame (@pxref{Stack, ,Examining the
4792Stack}), this prints lines centered around that line.
4793
4794@item list -
4795Print lines just before the lines last printed.
4796@end table
4797
9c16f35a 4798@cindex @code{list}, how many lines to display
c906108c
SS
4799By default, @value{GDBN} prints ten source lines with any of these forms of
4800the @code{list} command. You can change this using @code{set listsize}:
4801
4802@table @code
4803@kindex set listsize
4804@item set listsize @var{count}
4805Make the @code{list} command display @var{count} source lines (unless
4806the @code{list} argument explicitly specifies some other number).
4807
4808@kindex show listsize
4809@item show listsize
4810Display the number of lines that @code{list} prints.
4811@end table
4812
4813Repeating a @code{list} command with @key{RET} discards the argument,
4814so it is equivalent to typing just @code{list}. This is more useful
4815than listing the same lines again. An exception is made for an
4816argument of @samp{-}; that argument is preserved in repetition so that
4817each repetition moves up in the source file.
4818
4819@cindex linespec
4820In general, the @code{list} command expects you to supply zero, one or two
4821@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4822of writing them, but the effect is always to specify some source line.
c906108c
SS
4823Here is a complete description of the possible arguments for @code{list}:
4824
4825@table @code
4826@item list @var{linespec}
4827Print lines centered around the line specified by @var{linespec}.
4828
4829@item list @var{first},@var{last}
4830Print lines from @var{first} to @var{last}. Both arguments are
4831linespecs.
4832
4833@item list ,@var{last}
4834Print lines ending with @var{last}.
4835
4836@item list @var{first},
4837Print lines starting with @var{first}.
4838
4839@item list +
4840Print lines just after the lines last printed.
4841
4842@item list -
4843Print lines just before the lines last printed.
4844
4845@item list
4846As described in the preceding table.
4847@end table
4848
4849Here are the ways of specifying a single source line---all the
4850kinds of linespec.
4851
4852@table @code
4853@item @var{number}
4854Specifies line @var{number} of the current source file.
4855When a @code{list} command has two linespecs, this refers to
4856the same source file as the first linespec.
4857
4858@item +@var{offset}
4859Specifies the line @var{offset} lines after the last line printed.
4860When used as the second linespec in a @code{list} command that has
4861two, this specifies the line @var{offset} lines down from the
4862first linespec.
4863
4864@item -@var{offset}
4865Specifies the line @var{offset} lines before the last line printed.
4866
4867@item @var{filename}:@var{number}
4868Specifies line @var{number} in the source file @var{filename}.
4869
4870@item @var{function}
4871Specifies the line that begins the body of the function @var{function}.
4872For example: in C, this is the line with the open brace.
4873
4874@item @var{filename}:@var{function}
4875Specifies the line of the open-brace that begins the body of the
4876function @var{function} in the file @var{filename}. You only need the
4877file name with a function name to avoid ambiguity when there are
4878identically named functions in different source files.
4879
4880@item *@var{address}
4881Specifies the line containing the program address @var{address}.
4882@var{address} may be any expression.
4883@end table
4884
87885426
FN
4885@node Edit
4886@section Editing source files
4887@cindex editing source files
4888
4889@kindex edit
4890@kindex e @r{(@code{edit})}
4891To edit the lines in a source file, use the @code{edit} command.
4892The editing program of your choice
4893is invoked with the current line set to
4894the active line in the program.
4895Alternatively, there are several ways to specify what part of the file you
4896want to print if you want to see other parts of the program.
4897
4898Here are the forms of the @code{edit} command most commonly used:
4899
4900@table @code
4901@item edit
4902Edit the current source file at the active line number in the program.
4903
4904@item edit @var{number}
4905Edit the current source file with @var{number} as the active line number.
4906
4907@item edit @var{function}
4908Edit the file containing @var{function} at the beginning of its definition.
4909
4910@item edit @var{filename}:@var{number}
4911Specifies line @var{number} in the source file @var{filename}.
4912
4913@item edit @var{filename}:@var{function}
4914Specifies the line that begins the body of the
4915function @var{function} in the file @var{filename}. You only need the
4916file name with a function name to avoid ambiguity when there are
4917identically named functions in different source files.
4918
4919@item edit *@var{address}
4920Specifies the line containing the program address @var{address}.
4921@var{address} may be any expression.
4922@end table
4923
4924@subsection Choosing your editor
4925You can customize @value{GDBN} to use any editor you want
4926@footnote{
4927The only restriction is that your editor (say @code{ex}), recognizes the
4928following command-line syntax:
10998722 4929@smallexample
87885426 4930ex +@var{number} file
10998722 4931@end smallexample
15387254
EZ
4932The optional numeric value +@var{number} specifies the number of the line in
4933the file where to start editing.}.
4934By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4935by setting the environment variable @code{EDITOR} before using
4936@value{GDBN}. For example, to configure @value{GDBN} to use the
4937@code{vi} editor, you could use these commands with the @code{sh} shell:
4938@smallexample
87885426
FN
4939EDITOR=/usr/bin/vi
4940export EDITOR
15387254 4941gdb @dots{}
10998722 4942@end smallexample
87885426 4943or in the @code{csh} shell,
10998722 4944@smallexample
87885426 4945setenv EDITOR /usr/bin/vi
15387254 4946gdb @dots{}
10998722 4947@end smallexample
87885426 4948
6d2ebf8b 4949@node Search
c906108c 4950@section Searching source files
15387254 4951@cindex searching source files
c906108c
SS
4952
4953There are two commands for searching through the current source file for a
4954regular expression.
4955
4956@table @code
4957@kindex search
4958@kindex forward-search
4959@item forward-search @var{regexp}
4960@itemx search @var{regexp}
4961The command @samp{forward-search @var{regexp}} checks each line,
4962starting with the one following the last line listed, for a match for
5d161b24 4963@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4964synonym @samp{search @var{regexp}} or abbreviate the command name as
4965@code{fo}.
4966
09d4efe1 4967@kindex reverse-search
c906108c
SS
4968@item reverse-search @var{regexp}
4969The command @samp{reverse-search @var{regexp}} checks each line, starting
4970with the one before the last line listed and going backward, for a match
4971for @var{regexp}. It lists the line that is found. You can abbreviate
4972this command as @code{rev}.
4973@end table
c906108c 4974
6d2ebf8b 4975@node Source Path
c906108c
SS
4976@section Specifying source directories
4977
4978@cindex source path
4979@cindex directories for source files
4980Executable programs sometimes do not record the directories of the source
4981files from which they were compiled, just the names. Even when they do,
4982the directories could be moved between the compilation and your debugging
4983session. @value{GDBN} has a list of directories to search for source files;
4984this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4985it tries all the directories in the list, in the order they are present
0b66e38c
EZ
4986in the list, until it finds a file with the desired name.
4987
4988For example, suppose an executable references the file
4989@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4990@file{/mnt/cross}. The file is first looked up literally; if this
4991fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4992fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4993message is printed. @value{GDBN} does not look up the parts of the
4994source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4995Likewise, the subdirectories of the source path are not searched: if
4996the source path is @file{/mnt/cross}, and the binary refers to
4997@file{foo.c}, @value{GDBN} would not find it under
4998@file{/mnt/cross/usr/src/foo-1.0/lib}.
4999
5000Plain file names, relative file names with leading directories, file
5001names containing dots, etc.@: are all treated as described above; for
5002instance, if the source path is @file{/mnt/cross}, and the source file
5003is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
5004@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
5005that---@file{/mnt/cross/foo.c}.
5006
5007Note that the executable search path is @emph{not} used to locate the
5008source files. Neither is the current working directory, unless it
5009happens to be in the source path.
c906108c
SS
5010
5011Whenever you reset or rearrange the source path, @value{GDBN} clears out
5012any information it has cached about where source files are found and where
5013each line is in the file.
5014
5015@kindex directory
5016@kindex dir
d4f3574e
SS
5017When you start @value{GDBN}, its source path includes only @samp{cdir}
5018and @samp{cwd}, in that order.
c906108c
SS
5019To add other directories, use the @code{directory} command.
5020
5021@table @code
5022@item directory @var{dirname} @dots{}
5023@item dir @var{dirname} @dots{}
5024Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
5025directory names may be given to this command, separated by @samp{:}
5026(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
5027part of absolute file names) or
c906108c
SS
5028whitespace. You may specify a directory that is already in the source
5029path; this moves it forward, so @value{GDBN} searches it sooner.
5030
5031@kindex cdir
5032@kindex cwd
41afff9a
EZ
5033@vindex $cdir@r{, convenience variable}
5034@vindex $cwdr@r{, convenience variable}
c906108c
SS
5035@cindex compilation directory
5036@cindex current directory
5037@cindex working directory
5038@cindex directory, current
5039@cindex directory, compilation
5040You can use the string @samp{$cdir} to refer to the compilation
5041directory (if one is recorded), and @samp{$cwd} to refer to the current
5042working directory. @samp{$cwd} is not the same as @samp{.}---the former
5043tracks the current working directory as it changes during your @value{GDBN}
5044session, while the latter is immediately expanded to the current
5045directory at the time you add an entry to the source path.
5046
5047@item directory
5048Reset the source path to empty again. This requires confirmation.
5049
5050@c RET-repeat for @code{directory} is explicitly disabled, but since
5051@c repeating it would be a no-op we do not say that. (thanks to RMS)
5052
5053@item show directories
5054@kindex show directories
5055Print the source path: show which directories it contains.
5056@end table
5057
5058If your source path is cluttered with directories that are no longer of
5059interest, @value{GDBN} may sometimes cause confusion by finding the wrong
5060versions of source. You can correct the situation as follows:
5061
5062@enumerate
5063@item
5064Use @code{directory} with no argument to reset the source path to empty.
5065
5066@item
5067Use @code{directory} with suitable arguments to reinstall the
5068directories you want in the source path. You can add all the
5069directories in one command.
5070@end enumerate
5071
6d2ebf8b 5072@node Machine Code
c906108c 5073@section Source and machine code
15387254 5074@cindex source line and its code address
c906108c
SS
5075
5076You can use the command @code{info line} to map source lines to program
5077addresses (and vice versa), and the command @code{disassemble} to display
5078a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 5079mode, the @code{info line} command causes the arrow to point to the
5d161b24 5080line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
5081well as hex.
5082
5083@table @code
5084@kindex info line
5085@item info line @var{linespec}
5086Print the starting and ending addresses of the compiled code for
5087source line @var{linespec}. You can specify source lines in any of
5088the ways understood by the @code{list} command (@pxref{List, ,Printing
5089source lines}).
5090@end table
5091
5092For example, we can use @code{info line} to discover the location of
5093the object code for the first line of function
5094@code{m4_changequote}:
5095
d4f3574e
SS
5096@c FIXME: I think this example should also show the addresses in
5097@c symbolic form, as they usually would be displayed.
c906108c 5098@smallexample
96a2c332 5099(@value{GDBP}) info line m4_changequote
c906108c
SS
5100Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
5101@end smallexample
5102
5103@noindent
15387254 5104@cindex code address and its source line
c906108c
SS
5105We can also inquire (using @code{*@var{addr}} as the form for
5106@var{linespec}) what source line covers a particular address:
5107@smallexample
5108(@value{GDBP}) info line *0x63ff
5109Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
5110@end smallexample
5111
5112@cindex @code{$_} and @code{info line}
15387254 5113@cindex @code{x} command, default address
41afff9a 5114@kindex x@r{(examine), and} info line
c906108c
SS
5115After @code{info line}, the default address for the @code{x} command
5116is changed to the starting address of the line, so that @samp{x/i} is
5117sufficient to begin examining the machine code (@pxref{Memory,
5118,Examining memory}). Also, this address is saved as the value of the
5119convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
5120variables}).
5121
5122@table @code
5123@kindex disassemble
5124@cindex assembly instructions
5125@cindex instructions, assembly
5126@cindex machine instructions
5127@cindex listing machine instructions
5128@item disassemble
5129This specialized command dumps a range of memory as machine
5130instructions. The default memory range is the function surrounding the
5131program counter of the selected frame. A single argument to this
5132command is a program counter value; @value{GDBN} dumps the function
5133surrounding this value. Two arguments specify a range of addresses
5134(first inclusive, second exclusive) to dump.
5135@end table
5136
c906108c
SS
5137The following example shows the disassembly of a range of addresses of
5138HP PA-RISC 2.0 code:
5139
5140@smallexample
5141(@value{GDBP}) disas 0x32c4 0x32e4
5142Dump of assembler code from 0x32c4 to 0x32e4:
51430x32c4 <main+204>: addil 0,dp
51440x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
51450x32cc <main+212>: ldil 0x3000,r31
51460x32d0 <main+216>: ble 0x3f8(sr4,r31)
51470x32d4 <main+220>: ldo 0(r31),rp
51480x32d8 <main+224>: addil -0x800,dp
51490x32dc <main+228>: ldo 0x588(r1),r26
51500x32e0 <main+232>: ldil 0x3000,r31
5151End of assembler dump.
5152@end smallexample
c906108c
SS
5153
5154Some architectures have more than one commonly-used set of instruction
5155mnemonics or other syntax.
5156
76d17f34
EZ
5157For programs that were dynamically linked and use shared libraries,
5158instructions that call functions or branch to locations in the shared
5159libraries might show a seemingly bogus location---it's actually a
5160location of the relocation table. On some architectures, @value{GDBN}
5161might be able to resolve these to actual function names.
5162
c906108c 5163@table @code
d4f3574e 5164@kindex set disassembly-flavor
d4f3574e
SS
5165@cindex Intel disassembly flavor
5166@cindex AT&T disassembly flavor
5167@item set disassembly-flavor @var{instruction-set}
c906108c
SS
5168Select the instruction set to use when disassembling the
5169program via the @code{disassemble} or @code{x/i} commands.
5170
5171Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
5172can set @var{instruction-set} to either @code{intel} or @code{att}.
5173The default is @code{att}, the AT&T flavor used by default by Unix
5174assemblers for x86-based targets.
9c16f35a
EZ
5175
5176@kindex show disassembly-flavor
5177@item show disassembly-flavor
5178Show the current setting of the disassembly flavor.
c906108c
SS
5179@end table
5180
5181
6d2ebf8b 5182@node Data
c906108c
SS
5183@chapter Examining Data
5184
5185@cindex printing data
5186@cindex examining data
5187@kindex print
5188@kindex inspect
5189@c "inspect" is not quite a synonym if you are using Epoch, which we do not
5190@c document because it is nonstandard... Under Epoch it displays in a
5191@c different window or something like that.
5192The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
5193command (abbreviated @code{p}), or its synonym @code{inspect}. It
5194evaluates and prints the value of an expression of the language your
5195program is written in (@pxref{Languages, ,Using @value{GDBN} with
5196Different Languages}).
c906108c
SS
5197
5198@table @code
d4f3574e
SS
5199@item print @var{expr}
5200@itemx print /@var{f} @var{expr}
5201@var{expr} is an expression (in the source language). By default the
5202value of @var{expr} is printed in a format appropriate to its data type;
c906108c 5203you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 5204@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
5205formats}.
5206
5207@item print
5208@itemx print /@var{f}
15387254 5209@cindex reprint the last value
d4f3574e 5210If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
5211@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
5212conveniently inspect the same value in an alternative format.
5213@end table
5214
5215A more low-level way of examining data is with the @code{x} command.
5216It examines data in memory at a specified address and prints it in a
5217specified format. @xref{Memory, ,Examining memory}.
5218
7a292a7a 5219If you are interested in information about types, or about how the
d4f3574e
SS
5220fields of a struct or a class are declared, use the @code{ptype @var{exp}}
5221command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 5222Table}.
c906108c
SS
5223
5224@menu
5225* Expressions:: Expressions
5226* Variables:: Program variables
5227* Arrays:: Artificial arrays
5228* Output Formats:: Output formats
5229* Memory:: Examining memory
5230* Auto Display:: Automatic display
5231* Print Settings:: Print settings
5232* Value History:: Value history
5233* Convenience Vars:: Convenience variables
5234* Registers:: Registers
c906108c 5235* Floating Point Hardware:: Floating point hardware
53c69bd7 5236* Vector Unit:: Vector Unit
721c2651 5237* OS Information:: Auxiliary data provided by operating system
29e57380 5238* Memory Region Attributes:: Memory region attributes
16d9dec6 5239* Dump/Restore Files:: Copy between memory and a file
384ee23f 5240* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
5241* Character Sets:: Debugging programs that use a different
5242 character set than GDB does
09d4efe1 5243* Caching Remote Data:: Data caching for remote targets
c906108c
SS
5244@end menu
5245
6d2ebf8b 5246@node Expressions
c906108c
SS
5247@section Expressions
5248
5249@cindex expressions
5250@code{print} and many other @value{GDBN} commands accept an expression and
5251compute its value. Any kind of constant, variable or operator defined
5252by the programming language you are using is valid in an expression in
e2e0bcd1
JB
5253@value{GDBN}. This includes conditional expressions, function calls,
5254casts, and string constants. It also includes preprocessor macros, if
5255you compiled your program to include this information; see
5256@ref{Compilation}.
c906108c 5257
15387254 5258@cindex arrays in expressions
d4f3574e
SS
5259@value{GDBN} supports array constants in expressions input by
5260the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 5261you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 5262memory that is @code{malloc}ed in the target program.
c906108c 5263
c906108c
SS
5264Because C is so widespread, most of the expressions shown in examples in
5265this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
5266Languages}, for information on how to use expressions in other
5267languages.
5268
5269In this section, we discuss operators that you can use in @value{GDBN}
5270expressions regardless of your programming language.
5271
15387254 5272@cindex casts, in expressions
c906108c
SS
5273Casts are supported in all languages, not just in C, because it is so
5274useful to cast a number into a pointer in order to examine a structure
5275at that address in memory.
5276@c FIXME: casts supported---Mod2 true?
c906108c
SS
5277
5278@value{GDBN} supports these operators, in addition to those common
5279to programming languages:
5280
5281@table @code
5282@item @@
5283@samp{@@} is a binary operator for treating parts of memory as arrays.
5284@xref{Arrays, ,Artificial arrays}, for more information.
5285
5286@item ::
5287@samp{::} allows you to specify a variable in terms of the file or
5288function where it is defined. @xref{Variables, ,Program variables}.
5289
5290@cindex @{@var{type}@}
5291@cindex type casting memory
5292@cindex memory, viewing as typed object
5293@cindex casts, to view memory
5294@item @{@var{type}@} @var{addr}
5295Refers to an object of type @var{type} stored at address @var{addr} in
5296memory. @var{addr} may be any expression whose value is an integer or
5297pointer (but parentheses are required around binary operators, just as in
5298a cast). This construct is allowed regardless of what kind of data is
5299normally supposed to reside at @var{addr}.
5300@end table
5301
6d2ebf8b 5302@node Variables
c906108c
SS
5303@section Program variables
5304
5305The most common kind of expression to use is the name of a variable
5306in your program.
5307
5308Variables in expressions are understood in the selected stack frame
5309(@pxref{Selection, ,Selecting a frame}); they must be either:
5310
5311@itemize @bullet
5312@item
5313global (or file-static)
5314@end itemize
5315
5d161b24 5316@noindent or
c906108c
SS
5317
5318@itemize @bullet
5319@item
5320visible according to the scope rules of the
5321programming language from the point of execution in that frame
5d161b24 5322@end itemize
c906108c
SS
5323
5324@noindent This means that in the function
5325
474c8240 5326@smallexample
c906108c
SS
5327foo (a)
5328 int a;
5329@{
5330 bar (a);
5331 @{
5332 int b = test ();
5333 bar (b);
5334 @}
5335@}
474c8240 5336@end smallexample
c906108c
SS
5337
5338@noindent
5339you can examine and use the variable @code{a} whenever your program is
5340executing within the function @code{foo}, but you can only use or
5341examine the variable @code{b} while your program is executing inside
5342the block where @code{b} is declared.
5343
5344@cindex variable name conflict
5345There is an exception: you can refer to a variable or function whose
5346scope is a single source file even if the current execution point is not
5347in this file. But it is possible to have more than one such variable or
5348function with the same name (in different source files). If that
5349happens, referring to that name has unpredictable effects. If you wish,
5350you can specify a static variable in a particular function or file,
15387254 5351using the colon-colon (@code{::}) notation:
c906108c 5352
d4f3574e 5353@cindex colon-colon, context for variables/functions
c906108c
SS
5354@iftex
5355@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 5356@cindex @code{::}, context for variables/functions
c906108c 5357@end iftex
474c8240 5358@smallexample
c906108c
SS
5359@var{file}::@var{variable}
5360@var{function}::@var{variable}
474c8240 5361@end smallexample
c906108c
SS
5362
5363@noindent
5364Here @var{file} or @var{function} is the name of the context for the
5365static @var{variable}. In the case of file names, you can use quotes to
5366make sure @value{GDBN} parses the file name as a single word---for example,
5367to print a global value of @code{x} defined in @file{f2.c}:
5368
474c8240 5369@smallexample
c906108c 5370(@value{GDBP}) p 'f2.c'::x
474c8240 5371@end smallexample
c906108c 5372
b37052ae 5373@cindex C@t{++} scope resolution
c906108c 5374This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 5375use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
5376scope resolution operator in @value{GDBN} expressions.
5377@c FIXME: Um, so what happens in one of those rare cases where it's in
5378@c conflict?? --mew
c906108c
SS
5379
5380@cindex wrong values
5381@cindex variable values, wrong
15387254
EZ
5382@cindex function entry/exit, wrong values of variables
5383@cindex optimized code, wrong values of variables
c906108c
SS
5384@quotation
5385@emph{Warning:} Occasionally, a local variable may appear to have the
5386wrong value at certain points in a function---just after entry to a new
5387scope, and just before exit.
5388@end quotation
5389You may see this problem when you are stepping by machine instructions.
5390This is because, on most machines, it takes more than one instruction to
5391set up a stack frame (including local variable definitions); if you are
5392stepping by machine instructions, variables may appear to have the wrong
5393values until the stack frame is completely built. On exit, it usually
5394also takes more than one machine instruction to destroy a stack frame;
5395after you begin stepping through that group of instructions, local
5396variable definitions may be gone.
5397
5398This may also happen when the compiler does significant optimizations.
5399To be sure of always seeing accurate values, turn off all optimization
5400when compiling.
5401
d4f3574e
SS
5402@cindex ``No symbol "foo" in current context''
5403Another possible effect of compiler optimizations is to optimize
5404unused variables out of existence, or assign variables to registers (as
5405opposed to memory addresses). Depending on the support for such cases
5406offered by the debug info format used by the compiler, @value{GDBN}
5407might not be able to display values for such local variables. If that
5408happens, @value{GDBN} will print a message like this:
5409
474c8240 5410@smallexample
d4f3574e 5411No symbol "foo" in current context.
474c8240 5412@end smallexample
d4f3574e
SS
5413
5414To solve such problems, either recompile without optimizations, or use a
5415different debug info format, if the compiler supports several such
15387254 5416formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
5417usually supports the @option{-gstabs+} option. @option{-gstabs+}
5418produces debug info in a format that is superior to formats such as
5419COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5420an effective form for debug info. @xref{Debugging Options,,Options
5421for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
5422@xref{C, , Debugging C++}, for more info about debug info formats
5423that are best suited to C@t{++} programs.
d4f3574e 5424
ab1adacd
EZ
5425If you ask to print an object whose contents are unknown to
5426@value{GDBN}, e.g., because its data type is not completely specified
5427by the debug information, @value{GDBN} will say @samp{<incomplete
5428type>}. @xref{Symbols, incomplete type}, for more about this.
5429
6d2ebf8b 5430@node Arrays
c906108c
SS
5431@section Artificial arrays
5432
5433@cindex artificial array
15387254 5434@cindex arrays
41afff9a 5435@kindex @@@r{, referencing memory as an array}
c906108c
SS
5436It is often useful to print out several successive objects of the
5437same type in memory; a section of an array, or an array of
5438dynamically determined size for which only a pointer exists in the
5439program.
5440
5441You can do this by referring to a contiguous span of memory as an
5442@dfn{artificial array}, using the binary operator @samp{@@}. The left
5443operand of @samp{@@} should be the first element of the desired array
5444and be an individual object. The right operand should be the desired length
5445of the array. The result is an array value whose elements are all of
5446the type of the left argument. The first element is actually the left
5447argument; the second element comes from bytes of memory immediately
5448following those that hold the first element, and so on. Here is an
5449example. If a program says
5450
474c8240 5451@smallexample
c906108c 5452int *array = (int *) malloc (len * sizeof (int));
474c8240 5453@end smallexample
c906108c
SS
5454
5455@noindent
5456you can print the contents of @code{array} with
5457
474c8240 5458@smallexample
c906108c 5459p *array@@len
474c8240 5460@end smallexample
c906108c
SS
5461
5462The left operand of @samp{@@} must reside in memory. Array values made
5463with @samp{@@} in this way behave just like other arrays in terms of
5464subscripting, and are coerced to pointers when used in expressions.
5465Artificial arrays most often appear in expressions via the value history
5466(@pxref{Value History, ,Value history}), after printing one out.
5467
5468Another way to create an artificial array is to use a cast.
5469This re-interprets a value as if it were an array.
5470The value need not be in memory:
474c8240 5471@smallexample
c906108c
SS
5472(@value{GDBP}) p/x (short[2])0x12345678
5473$1 = @{0x1234, 0x5678@}
474c8240 5474@end smallexample
c906108c
SS
5475
5476As a convenience, if you leave the array length out (as in
c3f6f71d 5477@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5478the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5479@smallexample
c906108c
SS
5480(@value{GDBP}) p/x (short[])0x12345678
5481$2 = @{0x1234, 0x5678@}
474c8240 5482@end smallexample
c906108c
SS
5483
5484Sometimes the artificial array mechanism is not quite enough; in
5485moderately complex data structures, the elements of interest may not
5486actually be adjacent---for example, if you are interested in the values
5487of pointers in an array. One useful work-around in this situation is
5488to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5489variables}) as a counter in an expression that prints the first
5490interesting value, and then repeat that expression via @key{RET}. For
5491instance, suppose you have an array @code{dtab} of pointers to
5492structures, and you are interested in the values of a field @code{fv}
5493in each structure. Here is an example of what you might type:
5494
474c8240 5495@smallexample
c906108c
SS
5496set $i = 0
5497p dtab[$i++]->fv
5498@key{RET}
5499@key{RET}
5500@dots{}
474c8240 5501@end smallexample
c906108c 5502
6d2ebf8b 5503@node Output Formats
c906108c
SS
5504@section Output formats
5505
5506@cindex formatted output
5507@cindex output formats
5508By default, @value{GDBN} prints a value according to its data type. Sometimes
5509this is not what you want. For example, you might want to print a number
5510in hex, or a pointer in decimal. Or you might want to view data in memory
5511at a certain address as a character string or as an instruction. To do
5512these things, specify an @dfn{output format} when you print a value.
5513
5514The simplest use of output formats is to say how to print a value
5515already computed. This is done by starting the arguments of the
5516@code{print} command with a slash and a format letter. The format
5517letters supported are:
5518
5519@table @code
5520@item x
5521Regard the bits of the value as an integer, and print the integer in
5522hexadecimal.
5523
5524@item d
5525Print as integer in signed decimal.
5526
5527@item u
5528Print as integer in unsigned decimal.
5529
5530@item o
5531Print as integer in octal.
5532
5533@item t
5534Print as integer in binary. The letter @samp{t} stands for ``two''.
5535@footnote{@samp{b} cannot be used because these format letters are also
5536used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5537see @ref{Memory,,Examining memory}.}
c906108c
SS
5538
5539@item a
5540@cindex unknown address, locating
3d67e040 5541@cindex locate address
c906108c
SS
5542Print as an address, both absolute in hexadecimal and as an offset from
5543the nearest preceding symbol. You can use this format used to discover
5544where (in what function) an unknown address is located:
5545
474c8240 5546@smallexample
c906108c
SS
5547(@value{GDBP}) p/a 0x54320
5548$3 = 0x54320 <_initialize_vx+396>
474c8240 5549@end smallexample
c906108c 5550
3d67e040
EZ
5551@noindent
5552The command @code{info symbol 0x54320} yields similar results.
5553@xref{Symbols, info symbol}.
5554
c906108c 5555@item c
51274035
EZ
5556Regard as an integer and print it as a character constant. This
5557prints both the numerical value and its character representation. The
5558character representation is replaced with the octal escape @samp{\nnn}
5559for characters outside the 7-bit @sc{ascii} range.
c906108c
SS
5560
5561@item f
5562Regard the bits of the value as a floating point number and print
5563using typical floating point syntax.
5564@end table
5565
5566For example, to print the program counter in hex (@pxref{Registers}), type
5567
474c8240 5568@smallexample
c906108c 5569p/x $pc
474c8240 5570@end smallexample
c906108c
SS
5571
5572@noindent
5573Note that no space is required before the slash; this is because command
5574names in @value{GDBN} cannot contain a slash.
5575
5576To reprint the last value in the value history with a different format,
5577you can use the @code{print} command with just a format and no
5578expression. For example, @samp{p/x} reprints the last value in hex.
5579
6d2ebf8b 5580@node Memory
c906108c
SS
5581@section Examining memory
5582
5583You can use the command @code{x} (for ``examine'') to examine memory in
5584any of several formats, independently of your program's data types.
5585
5586@cindex examining memory
5587@table @code
41afff9a 5588@kindex x @r{(examine memory)}
c906108c
SS
5589@item x/@var{nfu} @var{addr}
5590@itemx x @var{addr}
5591@itemx x
5592Use the @code{x} command to examine memory.
5593@end table
5594
5595@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5596much memory to display and how to format it; @var{addr} is an
5597expression giving the address where you want to start displaying memory.
5598If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5599Several commands set convenient defaults for @var{addr}.
5600
5601@table @r
5602@item @var{n}, the repeat count
5603The repeat count is a decimal integer; the default is 1. It specifies
5604how much memory (counting by units @var{u}) to display.
5605@c This really is **decimal**; unaffected by 'set radix' as of GDB
5606@c 4.1.2.
5607
5608@item @var{f}, the display format
51274035
EZ
5609The display format is one of the formats used by @code{print}
5610(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
5611@samp{f}), and in addition @samp{s} (for null-terminated strings) and
5612@samp{i} (for machine instructions). The default is @samp{x}
5613(hexadecimal) initially. The default changes each time you use either
5614@code{x} or @code{print}.
c906108c
SS
5615
5616@item @var{u}, the unit size
5617The unit size is any of
5618
5619@table @code
5620@item b
5621Bytes.
5622@item h
5623Halfwords (two bytes).
5624@item w
5625Words (four bytes). This is the initial default.
5626@item g
5627Giant words (eight bytes).
5628@end table
5629
5630Each time you specify a unit size with @code{x}, that size becomes the
5631default unit the next time you use @code{x}. (For the @samp{s} and
5632@samp{i} formats, the unit size is ignored and is normally not written.)
5633
5634@item @var{addr}, starting display address
5635@var{addr} is the address where you want @value{GDBN} to begin displaying
5636memory. The expression need not have a pointer value (though it may);
5637it is always interpreted as an integer address of a byte of memory.
5638@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5639@var{addr} is usually just after the last address examined---but several
5640other commands also set the default address: @code{info breakpoints} (to
5641the address of the last breakpoint listed), @code{info line} (to the
5642starting address of a line), and @code{print} (if you use it to display
5643a value from memory).
5644@end table
5645
5646For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5647(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5648starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5649words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5650@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5651
5652Since the letters indicating unit sizes are all distinct from the
5653letters specifying output formats, you do not have to remember whether
5654unit size or format comes first; either order works. The output
5655specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5656(However, the count @var{n} must come first; @samp{wx4} does not work.)
5657
5658Even though the unit size @var{u} is ignored for the formats @samp{s}
5659and @samp{i}, you might still want to use a count @var{n}; for example,
5660@samp{3i} specifies that you want to see three machine instructions,
5661including any operands. The command @code{disassemble} gives an
d4f3574e 5662alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5663Code,,Source and machine code}.
5664
5665All the defaults for the arguments to @code{x} are designed to make it
5666easy to continue scanning memory with minimal specifications each time
5667you use @code{x}. For example, after you have inspected three machine
5668instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5669with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5670the repeat count @var{n} is used again; the other arguments default as
5671for successive uses of @code{x}.
5672
5673@cindex @code{$_}, @code{$__}, and value history
5674The addresses and contents printed by the @code{x} command are not saved
5675in the value history because there is often too much of them and they
5676would get in the way. Instead, @value{GDBN} makes these values available for
5677subsequent use in expressions as values of the convenience variables
5678@code{$_} and @code{$__}. After an @code{x} command, the last address
5679examined is available for use in expressions in the convenience variable
5680@code{$_}. The contents of that address, as examined, are available in
5681the convenience variable @code{$__}.
5682
5683If the @code{x} command has a repeat count, the address and contents saved
5684are from the last memory unit printed; this is not the same as the last
5685address printed if several units were printed on the last line of output.
5686
09d4efe1
EZ
5687@cindex remote memory comparison
5688@cindex verify remote memory image
5689When you are debugging a program running on a remote target machine
5690(@pxref{Remote}), you may wish to verify the program's image in the
5691remote machine's memory against the executable file you downloaded to
5692the target. The @code{compare-sections} command is provided for such
5693situations.
5694
5695@table @code
5696@kindex compare-sections
5697@item compare-sections @r{[}@var{section-name}@r{]}
5698Compare the data of a loadable section @var{section-name} in the
5699executable file of the program being debugged with the same section in
5700the remote machine's memory, and report any mismatches. With no
5701arguments, compares all loadable sections. This command's
5702availability depends on the target's support for the @code{"qCRC"}
5703remote request.
5704@end table
5705
6d2ebf8b 5706@node Auto Display
c906108c
SS
5707@section Automatic display
5708@cindex automatic display
5709@cindex display of expressions
5710
5711If you find that you want to print the value of an expression frequently
5712(to see how it changes), you might want to add it to the @dfn{automatic
5713display list} so that @value{GDBN} prints its value each time your program stops.
5714Each expression added to the list is given a number to identify it;
5715to remove an expression from the list, you specify that number.
5716The automatic display looks like this:
5717
474c8240 5718@smallexample
c906108c
SS
57192: foo = 38
57203: bar[5] = (struct hack *) 0x3804
474c8240 5721@end smallexample
c906108c
SS
5722
5723@noindent
5724This display shows item numbers, expressions and their current values. As with
5725displays you request manually using @code{x} or @code{print}, you can
5726specify the output format you prefer; in fact, @code{display} decides
5727whether to use @code{print} or @code{x} depending on how elaborate your
5728format specification is---it uses @code{x} if you specify a unit size,
5729or one of the two formats (@samp{i} and @samp{s}) that are only
5730supported by @code{x}; otherwise it uses @code{print}.
5731
5732@table @code
5733@kindex display
d4f3574e
SS
5734@item display @var{expr}
5735Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5736each time your program stops. @xref{Expressions, ,Expressions}.
5737
5738@code{display} does not repeat if you press @key{RET} again after using it.
5739
d4f3574e 5740@item display/@var{fmt} @var{expr}
c906108c 5741For @var{fmt} specifying only a display format and not a size or
d4f3574e 5742count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5743arrange to display it each time in the specified format @var{fmt}.
5744@xref{Output Formats,,Output formats}.
5745
5746@item display/@var{fmt} @var{addr}
5747For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5748number of units, add the expression @var{addr} as a memory address to
5749be examined each time your program stops. Examining means in effect
5750doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5751@end table
5752
5753For example, @samp{display/i $pc} can be helpful, to see the machine
5754instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5755is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5756
5757@table @code
5758@kindex delete display
5759@kindex undisplay
5760@item undisplay @var{dnums}@dots{}
5761@itemx delete display @var{dnums}@dots{}
5762Remove item numbers @var{dnums} from the list of expressions to display.
5763
5764@code{undisplay} does not repeat if you press @key{RET} after using it.
5765(Otherwise you would just get the error @samp{No display number @dots{}}.)
5766
5767@kindex disable display
5768@item disable display @var{dnums}@dots{}
5769Disable the display of item numbers @var{dnums}. A disabled display
5770item is not printed automatically, but is not forgotten. It may be
5771enabled again later.
5772
5773@kindex enable display
5774@item enable display @var{dnums}@dots{}
5775Enable display of item numbers @var{dnums}. It becomes effective once
5776again in auto display of its expression, until you specify otherwise.
5777
5778@item display
5779Display the current values of the expressions on the list, just as is
5780done when your program stops.
5781
5782@kindex info display
5783@item info display
5784Print the list of expressions previously set up to display
5785automatically, each one with its item number, but without showing the
5786values. This includes disabled expressions, which are marked as such.
5787It also includes expressions which would not be displayed right now
5788because they refer to automatic variables not currently available.
5789@end table
5790
15387254 5791@cindex display disabled out of scope
c906108c
SS
5792If a display expression refers to local variables, then it does not make
5793sense outside the lexical context for which it was set up. Such an
5794expression is disabled when execution enters a context where one of its
5795variables is not defined. For example, if you give the command
5796@code{display last_char} while inside a function with an argument
5797@code{last_char}, @value{GDBN} displays this argument while your program
5798continues to stop inside that function. When it stops elsewhere---where
5799there is no variable @code{last_char}---the display is disabled
5800automatically. The next time your program stops where @code{last_char}
5801is meaningful, you can enable the display expression once again.
5802
6d2ebf8b 5803@node Print Settings
c906108c
SS
5804@section Print settings
5805
5806@cindex format options
5807@cindex print settings
5808@value{GDBN} provides the following ways to control how arrays, structures,
5809and symbols are printed.
5810
5811@noindent
5812These settings are useful for debugging programs in any language:
5813
5814@table @code
4644b6e3 5815@kindex set print
c906108c
SS
5816@item set print address
5817@itemx set print address on
4644b6e3 5818@cindex print/don't print memory addresses
c906108c
SS
5819@value{GDBN} prints memory addresses showing the location of stack
5820traces, structure values, pointer values, breakpoints, and so forth,
5821even when it also displays the contents of those addresses. The default
5822is @code{on}. For example, this is what a stack frame display looks like with
5823@code{set print address on}:
5824
5825@smallexample
5826@group
5827(@value{GDBP}) f
5828#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5829 at input.c:530
5830530 if (lquote != def_lquote)
5831@end group
5832@end smallexample
5833
5834@item set print address off
5835Do not print addresses when displaying their contents. For example,
5836this is the same stack frame displayed with @code{set print address off}:
5837
5838@smallexample
5839@group
5840(@value{GDBP}) set print addr off
5841(@value{GDBP}) f
5842#0 set_quotes (lq="<<", rq=">>") at input.c:530
5843530 if (lquote != def_lquote)
5844@end group
5845@end smallexample
5846
5847You can use @samp{set print address off} to eliminate all machine
5848dependent displays from the @value{GDBN} interface. For example, with
5849@code{print address off}, you should get the same text for backtraces on
5850all machines---whether or not they involve pointer arguments.
5851
4644b6e3 5852@kindex show print
c906108c
SS
5853@item show print address
5854Show whether or not addresses are to be printed.
5855@end table
5856
5857When @value{GDBN} prints a symbolic address, it normally prints the
5858closest earlier symbol plus an offset. If that symbol does not uniquely
5859identify the address (for example, it is a name whose scope is a single
5860source file), you may need to clarify. One way to do this is with
5861@code{info line}, for example @samp{info line *0x4537}. Alternately,
5862you can set @value{GDBN} to print the source file and line number when
5863it prints a symbolic address:
5864
5865@table @code
c906108c 5866@item set print symbol-filename on
9c16f35a
EZ
5867@cindex source file and line of a symbol
5868@cindex symbol, source file and line
c906108c
SS
5869Tell @value{GDBN} to print the source file name and line number of a
5870symbol in the symbolic form of an address.
5871
5872@item set print symbol-filename off
5873Do not print source file name and line number of a symbol. This is the
5874default.
5875
c906108c
SS
5876@item show print symbol-filename
5877Show whether or not @value{GDBN} will print the source file name and
5878line number of a symbol in the symbolic form of an address.
5879@end table
5880
5881Another situation where it is helpful to show symbol filenames and line
5882numbers is when disassembling code; @value{GDBN} shows you the line
5883number and source file that corresponds to each instruction.
5884
5885Also, you may wish to see the symbolic form only if the address being
5886printed is reasonably close to the closest earlier symbol:
5887
5888@table @code
c906108c 5889@item set print max-symbolic-offset @var{max-offset}
4644b6e3 5890@cindex maximum value for offset of closest symbol
c906108c
SS
5891Tell @value{GDBN} to only display the symbolic form of an address if the
5892offset between the closest earlier symbol and the address is less than
5d161b24 5893@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5894to always print the symbolic form of an address if any symbol precedes it.
5895
c906108c
SS
5896@item show print max-symbolic-offset
5897Ask how large the maximum offset is that @value{GDBN} prints in a
5898symbolic address.
5899@end table
5900
5901@cindex wild pointer, interpreting
5902@cindex pointer, finding referent
5903If you have a pointer and you are not sure where it points, try
5904@samp{set print symbol-filename on}. Then you can determine the name
5905and source file location of the variable where it points, using
5906@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5907For example, here @value{GDBN} shows that a variable @code{ptt} points
5908at another variable @code{t}, defined in @file{hi2.c}:
5909
474c8240 5910@smallexample
c906108c
SS
5911(@value{GDBP}) set print symbol-filename on
5912(@value{GDBP}) p/a ptt
5913$4 = 0xe008 <t in hi2.c>
474c8240 5914@end smallexample
c906108c
SS
5915
5916@quotation
5917@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5918does not show the symbol name and filename of the referent, even with
5919the appropriate @code{set print} options turned on.
5920@end quotation
5921
5922Other settings control how different kinds of objects are printed:
5923
5924@table @code
c906108c
SS
5925@item set print array
5926@itemx set print array on
4644b6e3 5927@cindex pretty print arrays
c906108c
SS
5928Pretty print arrays. This format is more convenient to read,
5929but uses more space. The default is off.
5930
5931@item set print array off
5932Return to compressed format for arrays.
5933
c906108c
SS
5934@item show print array
5935Show whether compressed or pretty format is selected for displaying
5936arrays.
5937
3c9c013a
JB
5938@cindex print array indexes
5939@item set print array-indexes
5940@itemx set print array-indexes on
5941Print the index of each element when displaying arrays. May be more
5942convenient to locate a given element in the array or quickly find the
5943index of a given element in that printed array. The default is off.
5944
5945@item set print array-indexes off
5946Stop printing element indexes when displaying arrays.
5947
5948@item show print array-indexes
5949Show whether the index of each element is printed when displaying
5950arrays.
5951
c906108c 5952@item set print elements @var{number-of-elements}
4644b6e3 5953@cindex number of array elements to print
9c16f35a 5954@cindex limit on number of printed array elements
c906108c
SS
5955Set a limit on how many elements of an array @value{GDBN} will print.
5956If @value{GDBN} is printing a large array, it stops printing after it has
5957printed the number of elements set by the @code{set print elements} command.
5958This limit also applies to the display of strings.
d4f3574e 5959When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5960Setting @var{number-of-elements} to zero means that the printing is unlimited.
5961
c906108c
SS
5962@item show print elements
5963Display the number of elements of a large array that @value{GDBN} will print.
5964If the number is 0, then the printing is unlimited.
5965
9c16f35a
EZ
5966@item set print repeats
5967@cindex repeated array elements
5968Set the threshold for suppressing display of repeated array
5969elelments. When the number of consecutive identical elements of an
5970array exceeds the threshold, @value{GDBN} prints the string
5971@code{"<repeats @var{n} times>"}, where @var{n} is the number of
5972identical repetitions, instead of displaying the identical elements
5973themselves. Setting the threshold to zero will cause all elements to
5974be individually printed. The default threshold is 10.
5975
5976@item show print repeats
5977Display the current threshold for printing repeated identical
5978elements.
5979
c906108c 5980@item set print null-stop
4644b6e3 5981@cindex @sc{null} elements in arrays
c906108c 5982Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5983@sc{null} is encountered. This is useful when large arrays actually
c906108c 5984contain only short strings.
d4f3574e 5985The default is off.
c906108c 5986
9c16f35a
EZ
5987@item show print null-stop
5988Show whether @value{GDBN} stops printing an array on the first
5989@sc{null} character.
5990
c906108c 5991@item set print pretty on
9c16f35a
EZ
5992@cindex print structures in indented form
5993@cindex indentation in structure display
5d161b24 5994Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5995per line, like this:
5996
5997@smallexample
5998@group
5999$1 = @{
6000 next = 0x0,
6001 flags = @{
6002 sweet = 1,
6003 sour = 1
6004 @},
6005 meat = 0x54 "Pork"
6006@}
6007@end group
6008@end smallexample
6009
6010@item set print pretty off
6011Cause @value{GDBN} to print structures in a compact format, like this:
6012
6013@smallexample
6014@group
6015$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
6016meat = 0x54 "Pork"@}
6017@end group
6018@end smallexample
6019
6020@noindent
6021This is the default format.
6022
c906108c
SS
6023@item show print pretty
6024Show which format @value{GDBN} is using to print structures.
6025
c906108c 6026@item set print sevenbit-strings on
4644b6e3
EZ
6027@cindex eight-bit characters in strings
6028@cindex octal escapes in strings
c906108c
SS
6029Print using only seven-bit characters; if this option is set,
6030@value{GDBN} displays any eight-bit characters (in strings or
6031character values) using the notation @code{\}@var{nnn}. This setting is
6032best if you are working in English (@sc{ascii}) and you use the
6033high-order bit of characters as a marker or ``meta'' bit.
6034
6035@item set print sevenbit-strings off
6036Print full eight-bit characters. This allows the use of more
6037international character sets, and is the default.
6038
c906108c
SS
6039@item show print sevenbit-strings
6040Show whether or not @value{GDBN} is printing only seven-bit characters.
6041
c906108c 6042@item set print union on
4644b6e3 6043@cindex unions in structures, printing
9c16f35a
EZ
6044Tell @value{GDBN} to print unions which are contained in structures
6045and other unions. This is the default setting.
c906108c
SS
6046
6047@item set print union off
9c16f35a
EZ
6048Tell @value{GDBN} not to print unions which are contained in
6049structures and other unions. @value{GDBN} will print @code{"@{...@}"}
6050instead.
c906108c 6051
c906108c
SS
6052@item show print union
6053Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 6054structures and other unions.
c906108c
SS
6055
6056For example, given the declarations
6057
6058@smallexample
6059typedef enum @{Tree, Bug@} Species;
6060typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 6061typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
6062 Bug_forms;
6063
6064struct thing @{
6065 Species it;
6066 union @{
6067 Tree_forms tree;
6068 Bug_forms bug;
6069 @} form;
6070@};
6071
6072struct thing foo = @{Tree, @{Acorn@}@};
6073@end smallexample
6074
6075@noindent
6076with @code{set print union on} in effect @samp{p foo} would print
6077
6078@smallexample
6079$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
6080@end smallexample
6081
6082@noindent
6083and with @code{set print union off} in effect it would print
6084
6085@smallexample
6086$1 = @{it = Tree, form = @{...@}@}
6087@end smallexample
9c16f35a
EZ
6088
6089@noindent
6090@code{set print union} affects programs written in C-like languages
6091and in Pascal.
c906108c
SS
6092@end table
6093
c906108c
SS
6094@need 1000
6095@noindent
b37052ae 6096These settings are of interest when debugging C@t{++} programs:
c906108c
SS
6097
6098@table @code
4644b6e3 6099@cindex demangling C@t{++} names
c906108c
SS
6100@item set print demangle
6101@itemx set print demangle on
b37052ae 6102Print C@t{++} names in their source form rather than in the encoded
c906108c 6103(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 6104linkage. The default is on.
c906108c 6105
c906108c 6106@item show print demangle
b37052ae 6107Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 6108
c906108c
SS
6109@item set print asm-demangle
6110@itemx set print asm-demangle on
b37052ae 6111Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
6112in assembler code printouts such as instruction disassemblies.
6113The default is off.
6114
c906108c 6115@item show print asm-demangle
b37052ae 6116Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
6117or demangled form.
6118
b37052ae
EZ
6119@cindex C@t{++} symbol decoding style
6120@cindex symbol decoding style, C@t{++}
a8f24a35 6121@kindex set demangle-style
c906108c
SS
6122@item set demangle-style @var{style}
6123Choose among several encoding schemes used by different compilers to
b37052ae 6124represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
6125
6126@table @code
6127@item auto
6128Allow @value{GDBN} to choose a decoding style by inspecting your program.
6129
6130@item gnu
b37052ae 6131Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 6132This is the default.
c906108c
SS
6133
6134@item hp
b37052ae 6135Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
6136
6137@item lucid
b37052ae 6138Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
6139
6140@item arm
b37052ae 6141Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
6142@strong{Warning:} this setting alone is not sufficient to allow
6143debugging @code{cfront}-generated executables. @value{GDBN} would
6144require further enhancement to permit that.
6145
6146@end table
6147If you omit @var{style}, you will see a list of possible formats.
6148
c906108c 6149@item show demangle-style
b37052ae 6150Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 6151
c906108c
SS
6152@item set print object
6153@itemx set print object on
4644b6e3 6154@cindex derived type of an object, printing
9c16f35a 6155@cindex display derived types
c906108c
SS
6156When displaying a pointer to an object, identify the @emph{actual}
6157(derived) type of the object rather than the @emph{declared} type, using
6158the virtual function table.
6159
6160@item set print object off
6161Display only the declared type of objects, without reference to the
6162virtual function table. This is the default setting.
6163
c906108c
SS
6164@item show print object
6165Show whether actual, or declared, object types are displayed.
6166
c906108c
SS
6167@item set print static-members
6168@itemx set print static-members on
4644b6e3 6169@cindex static members of C@t{++} objects
b37052ae 6170Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
6171
6172@item set print static-members off
b37052ae 6173Do not print static members when displaying a C@t{++} object.
c906108c 6174
c906108c 6175@item show print static-members
9c16f35a
EZ
6176Show whether C@t{++} static members are printed or not.
6177
6178@item set print pascal_static-members
6179@itemx set print pascal_static-members on
6180@cindex static members of Pacal objects
6181@cindex Pacal objects, static members display
6182Print static members when displaying a Pascal object. The default is on.
6183
6184@item set print pascal_static-members off
6185Do not print static members when displaying a Pascal object.
6186
6187@item show print pascal_static-members
6188Show whether Pascal static members are printed or not.
c906108c
SS
6189
6190@c These don't work with HP ANSI C++ yet.
c906108c
SS
6191@item set print vtbl
6192@itemx set print vtbl on
4644b6e3 6193@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
6194@cindex virtual functions (C@t{++}) display
6195@cindex VTBL display
b37052ae 6196Pretty print C@t{++} virtual function tables. The default is off.
c906108c 6197(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 6198ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
6199
6200@item set print vtbl off
b37052ae 6201Do not pretty print C@t{++} virtual function tables.
c906108c 6202
c906108c 6203@item show print vtbl
b37052ae 6204Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 6205@end table
c906108c 6206
6d2ebf8b 6207@node Value History
c906108c
SS
6208@section Value history
6209
6210@cindex value history
9c16f35a 6211@cindex history of values printed by @value{GDBN}
5d161b24
DB
6212Values printed by the @code{print} command are saved in the @value{GDBN}
6213@dfn{value history}. This allows you to refer to them in other expressions.
6214Values are kept until the symbol table is re-read or discarded
6215(for example with the @code{file} or @code{symbol-file} commands).
6216When the symbol table changes, the value history is discarded,
6217since the values may contain pointers back to the types defined in the
c906108c
SS
6218symbol table.
6219
6220@cindex @code{$}
6221@cindex @code{$$}
6222@cindex history number
6223The values printed are given @dfn{history numbers} by which you can
6224refer to them. These are successive integers starting with one.
6225@code{print} shows you the history number assigned to a value by
6226printing @samp{$@var{num} = } before the value; here @var{num} is the
6227history number.
6228
6229To refer to any previous value, use @samp{$} followed by the value's
6230history number. The way @code{print} labels its output is designed to
6231remind you of this. Just @code{$} refers to the most recent value in
6232the history, and @code{$$} refers to the value before that.
6233@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
6234is the value just prior to @code{$$}, @code{$$1} is equivalent to
6235@code{$$}, and @code{$$0} is equivalent to @code{$}.
6236
6237For example, suppose you have just printed a pointer to a structure and
6238want to see the contents of the structure. It suffices to type
6239
474c8240 6240@smallexample
c906108c 6241p *$
474c8240 6242@end smallexample
c906108c
SS
6243
6244If you have a chain of structures where the component @code{next} points
6245to the next one, you can print the contents of the next one with this:
6246
474c8240 6247@smallexample
c906108c 6248p *$.next
474c8240 6249@end smallexample
c906108c
SS
6250
6251@noindent
6252You can print successive links in the chain by repeating this
6253command---which you can do by just typing @key{RET}.
6254
6255Note that the history records values, not expressions. If the value of
6256@code{x} is 4 and you type these commands:
6257
474c8240 6258@smallexample
c906108c
SS
6259print x
6260set x=5
474c8240 6261@end smallexample
c906108c
SS
6262
6263@noindent
6264then the value recorded in the value history by the @code{print} command
6265remains 4 even though the value of @code{x} has changed.
6266
6267@table @code
6268@kindex show values
6269@item show values
6270Print the last ten values in the value history, with their item numbers.
6271This is like @samp{p@ $$9} repeated ten times, except that @code{show
6272values} does not change the history.
6273
6274@item show values @var{n}
6275Print ten history values centered on history item number @var{n}.
6276
6277@item show values +
6278Print ten history values just after the values last printed. If no more
6279values are available, @code{show values +} produces no display.
6280@end table
6281
6282Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
6283same effect as @samp{show values +}.
6284
6d2ebf8b 6285@node Convenience Vars
c906108c
SS
6286@section Convenience variables
6287
6288@cindex convenience variables
9c16f35a 6289@cindex user-defined variables
c906108c
SS
6290@value{GDBN} provides @dfn{convenience variables} that you can use within
6291@value{GDBN} to hold on to a value and refer to it later. These variables
6292exist entirely within @value{GDBN}; they are not part of your program, and
6293setting a convenience variable has no direct effect on further execution
6294of your program. That is why you can use them freely.
6295
6296Convenience variables are prefixed with @samp{$}. Any name preceded by
6297@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 6298the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
6299(Value history references, in contrast, are @emph{numbers} preceded
6300by @samp{$}. @xref{Value History, ,Value history}.)
6301
6302You can save a value in a convenience variable with an assignment
6303expression, just as you would set a variable in your program.
6304For example:
6305
474c8240 6306@smallexample
c906108c 6307set $foo = *object_ptr
474c8240 6308@end smallexample
c906108c
SS
6309
6310@noindent
6311would save in @code{$foo} the value contained in the object pointed to by
6312@code{object_ptr}.
6313
6314Using a convenience variable for the first time creates it, but its
6315value is @code{void} until you assign a new value. You can alter the
6316value with another assignment at any time.
6317
6318Convenience variables have no fixed types. You can assign a convenience
6319variable any type of value, including structures and arrays, even if
6320that variable already has a value of a different type. The convenience
6321variable, when used as an expression, has the type of its current value.
6322
6323@table @code
6324@kindex show convenience
9c16f35a 6325@cindex show all user variables
c906108c
SS
6326@item show convenience
6327Print a list of convenience variables used so far, and their values.
d4f3574e 6328Abbreviated @code{show conv}.
53e5f3cf
AS
6329
6330@kindex init-if-undefined
6331@cindex convenience variables, initializing
6332@item init-if-undefined $@var{variable} = @var{expression}
6333Set a convenience variable if it has not already been set. This is useful
6334for user-defined commands that keep some state. It is similar, in concept,
6335to using local static variables with initializers in C (except that
6336convenience variables are global). It can also be used to allow users to
6337override default values used in a command script.
6338
6339If the variable is already defined then the expression is not evaluated so
6340any side-effects do not occur.
c906108c
SS
6341@end table
6342
6343One of the ways to use a convenience variable is as a counter to be
6344incremented or a pointer to be advanced. For example, to print
6345a field from successive elements of an array of structures:
6346
474c8240 6347@smallexample
c906108c
SS
6348set $i = 0
6349print bar[$i++]->contents
474c8240 6350@end smallexample
c906108c 6351
d4f3574e
SS
6352@noindent
6353Repeat that command by typing @key{RET}.
c906108c
SS
6354
6355Some convenience variables are created automatically by @value{GDBN} and given
6356values likely to be useful.
6357
6358@table @code
41afff9a 6359@vindex $_@r{, convenience variable}
c906108c
SS
6360@item $_
6361The variable @code{$_} is automatically set by the @code{x} command to
6362the last address examined (@pxref{Memory, ,Examining memory}). Other
6363commands which provide a default address for @code{x} to examine also
6364set @code{$_} to that address; these commands include @code{info line}
6365and @code{info breakpoint}. The type of @code{$_} is @code{void *}
6366except when set by the @code{x} command, in which case it is a pointer
6367to the type of @code{$__}.
6368
41afff9a 6369@vindex $__@r{, convenience variable}
c906108c
SS
6370@item $__
6371The variable @code{$__} is automatically set by the @code{x} command
6372to the value found in the last address examined. Its type is chosen
6373to match the format in which the data was printed.
6374
6375@item $_exitcode
41afff9a 6376@vindex $_exitcode@r{, convenience variable}
c906108c
SS
6377The variable @code{$_exitcode} is automatically set to the exit code when
6378the program being debugged terminates.
6379@end table
6380
53a5351d
JM
6381On HP-UX systems, if you refer to a function or variable name that
6382begins with a dollar sign, @value{GDBN} searches for a user or system
6383name first, before it searches for a convenience variable.
c906108c 6384
6d2ebf8b 6385@node Registers
c906108c
SS
6386@section Registers
6387
6388@cindex registers
6389You can refer to machine register contents, in expressions, as variables
6390with names starting with @samp{$}. The names of registers are different
6391for each machine; use @code{info registers} to see the names used on
6392your machine.
6393
6394@table @code
6395@kindex info registers
6396@item info registers
6397Print the names and values of all registers except floating-point
c85508ee 6398and vector registers (in the selected stack frame).
c906108c
SS
6399
6400@kindex info all-registers
6401@cindex floating point registers
6402@item info all-registers
6403Print the names and values of all registers, including floating-point
c85508ee 6404and vector registers (in the selected stack frame).
c906108c
SS
6405
6406@item info registers @var{regname} @dots{}
6407Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
6408As discussed in detail below, register values are normally relative to
6409the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
6410the machine you are using, with or without the initial @samp{$}.
6411@end table
6412
e09f16f9
EZ
6413@cindex stack pointer register
6414@cindex program counter register
6415@cindex process status register
6416@cindex frame pointer register
6417@cindex standard registers
c906108c
SS
6418@value{GDBN} has four ``standard'' register names that are available (in
6419expressions) on most machines---whenever they do not conflict with an
6420architecture's canonical mnemonics for registers. The register names
6421@code{$pc} and @code{$sp} are used for the program counter register and
6422the stack pointer. @code{$fp} is used for a register that contains a
6423pointer to the current stack frame, and @code{$ps} is used for a
6424register that contains the processor status. For example,
6425you could print the program counter in hex with
6426
474c8240 6427@smallexample
c906108c 6428p/x $pc
474c8240 6429@end smallexample
c906108c
SS
6430
6431@noindent
6432or print the instruction to be executed next with
6433
474c8240 6434@smallexample
c906108c 6435x/i $pc
474c8240 6436@end smallexample
c906108c
SS
6437
6438@noindent
6439or add four to the stack pointer@footnote{This is a way of removing
6440one word from the stack, on machines where stacks grow downward in
6441memory (most machines, nowadays). This assumes that the innermost
6442stack frame is selected; setting @code{$sp} is not allowed when other
6443stack frames are selected. To pop entire frames off the stack,
6444regardless of machine architecture, use @code{return};
d4f3574e 6445see @ref{Returning, ,Returning from a function}.} with
c906108c 6446
474c8240 6447@smallexample
c906108c 6448set $sp += 4
474c8240 6449@end smallexample
c906108c
SS
6450
6451Whenever possible, these four standard register names are available on
6452your machine even though the machine has different canonical mnemonics,
6453so long as there is no conflict. The @code{info registers} command
6454shows the canonical names. For example, on the SPARC, @code{info
6455registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
6456can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6457is an alias for the @sc{eflags} register.
c906108c
SS
6458
6459@value{GDBN} always considers the contents of an ordinary register as an
6460integer when the register is examined in this way. Some machines have
6461special registers which can hold nothing but floating point; these
6462registers are considered to have floating point values. There is no way
6463to refer to the contents of an ordinary register as floating point value
6464(although you can @emph{print} it as a floating point value with
6465@samp{print/f $@var{regname}}).
6466
6467Some registers have distinct ``raw'' and ``virtual'' data formats. This
6468means that the data format in which the register contents are saved by
6469the operating system is not the same one that your program normally
6470sees. For example, the registers of the 68881 floating point
6471coprocessor are always saved in ``extended'' (raw) format, but all C
6472programs expect to work with ``double'' (virtual) format. In such
5d161b24 6473cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
6474that makes sense for your program), but the @code{info registers} command
6475prints the data in both formats.
6476
36b80e65
EZ
6477@cindex SSE registers (x86)
6478@cindex MMX registers (x86)
6479Some machines have special registers whose contents can be interpreted
6480in several different ways. For example, modern x86-based machines
6481have SSE and MMX registers that can hold several values packed
6482together in several different formats. @value{GDBN} refers to such
6483registers in @code{struct} notation:
6484
6485@smallexample
6486(@value{GDBP}) print $xmm1
6487$1 = @{
6488 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
6489 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
6490 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
6491 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
6492 v4_int32 = @{0, 20657912, 11, 13@},
6493 v2_int64 = @{88725056443645952, 55834574859@},
6494 uint128 = 0x0000000d0000000b013b36f800000000
6495@}
6496@end smallexample
6497
6498@noindent
6499To set values of such registers, you need to tell @value{GDBN} which
6500view of the register you wish to change, as if you were assigning
6501value to a @code{struct} member:
6502
6503@smallexample
6504 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
6505@end smallexample
6506
c906108c
SS
6507Normally, register values are relative to the selected stack frame
6508(@pxref{Selection, ,Selecting a frame}). This means that you get the
6509value that the register would contain if all stack frames farther in
6510were exited and their saved registers restored. In order to see the
6511true contents of hardware registers, you must select the innermost
6512frame (with @samp{frame 0}).
6513
6514However, @value{GDBN} must deduce where registers are saved, from the machine
6515code generated by your compiler. If some registers are not saved, or if
6516@value{GDBN} is unable to locate the saved registers, the selected stack
6517frame makes no difference.
6518
6d2ebf8b 6519@node Floating Point Hardware
c906108c
SS
6520@section Floating point hardware
6521@cindex floating point
6522
6523Depending on the configuration, @value{GDBN} may be able to give
6524you more information about the status of the floating point hardware.
6525
6526@table @code
6527@kindex info float
6528@item info float
6529Display hardware-dependent information about the floating
6530point unit. The exact contents and layout vary depending on the
6531floating point chip. Currently, @samp{info float} is supported on
6532the ARM and x86 machines.
6533@end table
c906108c 6534
e76f1f2e
AC
6535@node Vector Unit
6536@section Vector Unit
6537@cindex vector unit
6538
6539Depending on the configuration, @value{GDBN} may be able to give you
6540more information about the status of the vector unit.
6541
6542@table @code
6543@kindex info vector
6544@item info vector
6545Display information about the vector unit. The exact contents and
6546layout vary depending on the hardware.
6547@end table
6548
721c2651
EZ
6549@node OS Information
6550@section Operating system auxiliary information
6551@cindex OS information
6552
6553@value{GDBN} provides interfaces to useful OS facilities that can help
6554you debug your program.
6555
6556@cindex @code{ptrace} system call
6557@cindex @code{struct user} contents
6558When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6559machines), it interfaces with the inferior via the @code{ptrace}
6560system call. The operating system creates a special sata structure,
6561called @code{struct user}, for this interface. You can use the
6562command @code{info udot} to display the contents of this data
6563structure.
6564
6565@table @code
6566@item info udot
6567@kindex info udot
6568Display the contents of the @code{struct user} maintained by the OS
6569kernel for the program being debugged. @value{GDBN} displays the
6570contents of @code{struct user} as a list of hex numbers, similar to
6571the @code{examine} command.
6572@end table
6573
b383017d
RM
6574@cindex auxiliary vector
6575@cindex vector, auxiliary
b383017d
RM
6576Some operating systems supply an @dfn{auxiliary vector} to programs at
6577startup. This is akin to the arguments and environment that you
6578specify for a program, but contains a system-dependent variety of
6579binary values that tell system libraries important details about the
6580hardware, operating system, and process. Each value's purpose is
6581identified by an integer tag; the meanings are well-known but system-specific.
6582Depending on the configuration and operating system facilities,
9c16f35a
EZ
6583@value{GDBN} may be able to show you this information. For remote
6584targets, this functionality may further depend on the remote stub's
6585support of the @samp{qPart:auxv:read} packet, see @ref{Remote
6586configuration, auxiliary vector}.
b383017d
RM
6587
6588@table @code
6589@kindex info auxv
6590@item info auxv
6591Display the auxiliary vector of the inferior, which can be either a
e4937fc1 6592live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
6593numerically, and also shows names and text descriptions for recognized
6594tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 6595pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
6596most appropriate form for a recognized tag, and in hexadecimal for
6597an unrecognized tag.
6598@end table
6599
721c2651 6600
29e57380 6601@node Memory Region Attributes
b383017d 6602@section Memory region attributes
29e57380
C
6603@cindex memory region attributes
6604
b383017d
RM
6605@dfn{Memory region attributes} allow you to describe special handling
6606required by regions of your target's memory. @value{GDBN} uses attributes
29e57380
C
6607to determine whether to allow certain types of memory accesses; whether to
6608use specific width accesses; and whether to cache target memory.
6609
6610Defined memory regions can be individually enabled and disabled. When a
6611memory region is disabled, @value{GDBN} uses the default attributes when
6612accessing memory in that region. Similarly, if no memory regions have
6613been defined, @value{GDBN} uses the default attributes when accessing
6614all memory.
6615
b383017d 6616When a memory region is defined, it is given a number to identify it;
29e57380
C
6617to enable, disable, or remove a memory region, you specify that number.
6618
6619@table @code
6620@kindex mem
bfac230e 6621@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
6622Define a memory region bounded by @var{lower} and @var{upper} with
6623attributes @var{attributes}@dots{}, and add it to the list of regions
6624monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
6625case: it is treated as the the target's maximum memory address.
bfac230e 6626(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
6627
6628@kindex delete mem
6629@item delete mem @var{nums}@dots{}
09d4efe1
EZ
6630Remove memory regions @var{nums}@dots{} from the list of regions
6631monitored by @value{GDBN}.
29e57380
C
6632
6633@kindex disable mem
6634@item disable mem @var{nums}@dots{}
09d4efe1 6635Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 6636A disabled memory region is not forgotten.
29e57380
C
6637It may be enabled again later.
6638
6639@kindex enable mem
6640@item enable mem @var{nums}@dots{}
09d4efe1 6641Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
6642
6643@kindex info mem
6644@item info mem
6645Print a table of all defined memory regions, with the following columns
09d4efe1 6646for each region:
29e57380
C
6647
6648@table @emph
6649@item Memory Region Number
6650@item Enabled or Disabled.
b383017d 6651Enabled memory regions are marked with @samp{y}.
29e57380
C
6652Disabled memory regions are marked with @samp{n}.
6653
6654@item Lo Address
6655The address defining the inclusive lower bound of the memory region.
6656
6657@item Hi Address
6658The address defining the exclusive upper bound of the memory region.
6659
6660@item Attributes
6661The list of attributes set for this memory region.
6662@end table
6663@end table
6664
6665
6666@subsection Attributes
6667
b383017d 6668@subsubsection Memory Access Mode
29e57380
C
6669The access mode attributes set whether @value{GDBN} may make read or
6670write accesses to a memory region.
6671
6672While these attributes prevent @value{GDBN} from performing invalid
6673memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 6674etc.@: from accessing memory.
29e57380
C
6675
6676@table @code
6677@item ro
6678Memory is read only.
6679@item wo
6680Memory is write only.
6681@item rw
6ca652b0 6682Memory is read/write. This is the default.
29e57380
C
6683@end table
6684
6685@subsubsection Memory Access Size
6686The acccess size attributes tells @value{GDBN} to use specific sized
6687accesses in the memory region. Often memory mapped device registers
6688require specific sized accesses. If no access size attribute is
6689specified, @value{GDBN} may use accesses of any size.
6690
6691@table @code
6692@item 8
6693Use 8 bit memory accesses.
6694@item 16
6695Use 16 bit memory accesses.
6696@item 32
6697Use 32 bit memory accesses.
6698@item 64
6699Use 64 bit memory accesses.
6700@end table
6701
6702@c @subsubsection Hardware/Software Breakpoints
6703@c The hardware/software breakpoint attributes set whether @value{GDBN}
6704@c will use hardware or software breakpoints for the internal breakpoints
6705@c used by the step, next, finish, until, etc. commands.
6706@c
6707@c @table @code
6708@c @item hwbreak
b383017d 6709@c Always use hardware breakpoints
29e57380
C
6710@c @item swbreak (default)
6711@c @end table
6712
6713@subsubsection Data Cache
6714The data cache attributes set whether @value{GDBN} will cache target
6715memory. While this generally improves performance by reducing debug
6716protocol overhead, it can lead to incorrect results because @value{GDBN}
6717does not know about volatile variables or memory mapped device
6718registers.
6719
6720@table @code
6721@item cache
b383017d 6722Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6723@item nocache
6724Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6725@end table
6726
6727@c @subsubsection Memory Write Verification
b383017d 6728@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6729@c will re-reads data after each write to verify the write was successful.
6730@c
6731@c @table @code
6732@c @item verify
6733@c @item noverify (default)
6734@c @end table
6735
16d9dec6
MS
6736@node Dump/Restore Files
6737@section Copy between memory and a file
6738@cindex dump/restore files
6739@cindex append data to a file
6740@cindex dump data to a file
6741@cindex restore data from a file
16d9dec6 6742
df5215a6
JB
6743You can use the commands @code{dump}, @code{append}, and
6744@code{restore} to copy data between target memory and a file. The
6745@code{dump} and @code{append} commands write data to a file, and the
6746@code{restore} command reads data from a file back into the inferior's
6747memory. Files may be in binary, Motorola S-record, Intel hex, or
6748Tektronix Hex format; however, @value{GDBN} can only append to binary
6749files.
6750
6751@table @code
6752
6753@kindex dump
6754@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6755@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6756Dump the contents of memory from @var{start_addr} to @var{end_addr},
6757or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6758
df5215a6 6759The @var{format} parameter may be any one of:
16d9dec6 6760@table @code
df5215a6
JB
6761@item binary
6762Raw binary form.
6763@item ihex
6764Intel hex format.
6765@item srec
6766Motorola S-record format.
6767@item tekhex
6768Tektronix Hex format.
6769@end table
6770
6771@value{GDBN} uses the same definitions of these formats as the
6772@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6773@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6774form.
6775
6776@kindex append
6777@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6778@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6779Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 6780or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
6781(@value{GDBN} can only append data to files in raw binary form.)
6782
6783@kindex restore
6784@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6785Restore the contents of file @var{filename} into memory. The
6786@code{restore} command can automatically recognize any known @sc{bfd}
6787file format, except for raw binary. To restore a raw binary file you
6788must specify the optional keyword @code{binary} after the filename.
16d9dec6 6789
b383017d 6790If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6791contained in the file. Binary files always start at address zero, so
6792they will be restored at address @var{bias}. Other bfd files have
6793a built-in location; they will be restored at offset @var{bias}
6794from that location.
6795
6796If @var{start} and/or @var{end} are non-zero, then only data between
6797file offset @var{start} and file offset @var{end} will be restored.
b383017d 6798These offsets are relative to the addresses in the file, before
16d9dec6
MS
6799the @var{bias} argument is applied.
6800
6801@end table
6802
384ee23f
EZ
6803@node Core File Generation
6804@section How to Produce a Core File from Your Program
6805@cindex dump core from inferior
6806
6807A @dfn{core file} or @dfn{core dump} is a file that records the memory
6808image of a running process and its process status (register values
6809etc.). Its primary use is post-mortem debugging of a program that
6810crashed while it ran outside a debugger. A program that crashes
6811automatically produces a core file, unless this feature is disabled by
6812the user. @xref{Files}, for information on invoking @value{GDBN} in
6813the post-mortem debugging mode.
6814
6815Occasionally, you may wish to produce a core file of the program you
6816are debugging in order to preserve a snapshot of its state.
6817@value{GDBN} has a special command for that.
6818
6819@table @code
6820@kindex gcore
6821@kindex generate-core-file
6822@item generate-core-file [@var{file}]
6823@itemx gcore [@var{file}]
6824Produce a core dump of the inferior process. The optional argument
6825@var{file} specifies the file name where to put the core dump. If not
6826specified, the file name defaults to @file{core.@var{pid}}, where
6827@var{pid} is the inferior process ID.
6828
6829Note that this command is implemented only for some systems (as of
6830this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6831@end table
6832
a0eb71c5
KB
6833@node Character Sets
6834@section Character Sets
6835@cindex character sets
6836@cindex charset
6837@cindex translating between character sets
6838@cindex host character set
6839@cindex target character set
6840
6841If the program you are debugging uses a different character set to
6842represent characters and strings than the one @value{GDBN} uses itself,
6843@value{GDBN} can automatically translate between the character sets for
6844you. The character set @value{GDBN} uses we call the @dfn{host
6845character set}; the one the inferior program uses we call the
6846@dfn{target character set}.
6847
6848For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6849uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6850remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6851running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6852then the host character set is Latin-1, and the target character set is
6853@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6854target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6855@sc{ebcdic} and Latin 1 as you print character or string values, or use
6856character and string literals in expressions.
6857
6858@value{GDBN} has no way to automatically recognize which character set
6859the inferior program uses; you must tell it, using the @code{set
6860target-charset} command, described below.
6861
6862Here are the commands for controlling @value{GDBN}'s character set
6863support:
6864
6865@table @code
6866@item set target-charset @var{charset}
6867@kindex set target-charset
6868Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6869character set names @value{GDBN} recognizes below, but if you type
6870@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6871list the target character sets it supports.
a0eb71c5
KB
6872@end table
6873
6874@table @code
6875@item set host-charset @var{charset}
6876@kindex set host-charset
6877Set the current host character set to @var{charset}.
6878
6879By default, @value{GDBN} uses a host character set appropriate to the
6880system it is running on; you can override that default using the
6881@code{set host-charset} command.
6882
6883@value{GDBN} can only use certain character sets as its host character
6884set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6885indicate which can be host character sets, but if you type
6886@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6887list the host character sets it supports.
a0eb71c5
KB
6888
6889@item set charset @var{charset}
6890@kindex set charset
e33d66ec
EZ
6891Set the current host and target character sets to @var{charset}. As
6892above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6893@value{GDBN} will list the name of the character sets that can be used
6894for both host and target.
6895
a0eb71c5
KB
6896
6897@item show charset
a0eb71c5 6898@kindex show charset
b383017d 6899Show the names of the current host and target charsets.
e33d66ec
EZ
6900
6901@itemx show host-charset
a0eb71c5 6902@kindex show host-charset
b383017d 6903Show the name of the current host charset.
e33d66ec
EZ
6904
6905@itemx show target-charset
a0eb71c5 6906@kindex show target-charset
b383017d 6907Show the name of the current target charset.
a0eb71c5
KB
6908
6909@end table
6910
6911@value{GDBN} currently includes support for the following character
6912sets:
6913
6914@table @code
6915
6916@item ASCII
6917@cindex ASCII character set
6918Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6919character set.
6920
6921@item ISO-8859-1
6922@cindex ISO 8859-1 character set
6923@cindex ISO Latin 1 character set
e33d66ec 6924The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6925characters needed for French, German, and Spanish. @value{GDBN} can use
6926this as its host character set.
6927
6928@item EBCDIC-US
6929@itemx IBM1047
6930@cindex EBCDIC character set
6931@cindex IBM1047 character set
6932Variants of the @sc{ebcdic} character set, used on some of IBM's
6933mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6934@value{GDBN} cannot use these as its host character set.
6935
6936@end table
6937
6938Note that these are all single-byte character sets. More work inside
6939GDB is needed to support multi-byte or variable-width character
6940encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6941
6942Here is an example of @value{GDBN}'s character set support in action.
6943Assume that the following source code has been placed in the file
6944@file{charset-test.c}:
6945
6946@smallexample
6947#include <stdio.h>
6948
6949char ascii_hello[]
6950 = @{72, 101, 108, 108, 111, 44, 32, 119,
6951 111, 114, 108, 100, 33, 10, 0@};
6952char ibm1047_hello[]
6953 = @{200, 133, 147, 147, 150, 107, 64, 166,
6954 150, 153, 147, 132, 90, 37, 0@};
6955
6956main ()
6957@{
6958 printf ("Hello, world!\n");
6959@}
10998722 6960@end smallexample
a0eb71c5
KB
6961
6962In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6963containing the string @samp{Hello, world!} followed by a newline,
6964encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6965
6966We compile the program, and invoke the debugger on it:
6967
6968@smallexample
6969$ gcc -g charset-test.c -o charset-test
6970$ gdb -nw charset-test
6971GNU gdb 2001-12-19-cvs
6972Copyright 2001 Free Software Foundation, Inc.
6973@dots{}
f7dc1244 6974(@value{GDBP})
10998722 6975@end smallexample
a0eb71c5
KB
6976
6977We can use the @code{show charset} command to see what character sets
6978@value{GDBN} is currently using to interpret and display characters and
6979strings:
6980
6981@smallexample
f7dc1244 6982(@value{GDBP}) show charset
e33d66ec 6983The current host and target character set is `ISO-8859-1'.
f7dc1244 6984(@value{GDBP})
10998722 6985@end smallexample
a0eb71c5
KB
6986
6987For the sake of printing this manual, let's use @sc{ascii} as our
6988initial character set:
6989@smallexample
f7dc1244
EZ
6990(@value{GDBP}) set charset ASCII
6991(@value{GDBP}) show charset
e33d66ec 6992The current host and target character set is `ASCII'.
f7dc1244 6993(@value{GDBP})
10998722 6994@end smallexample
a0eb71c5
KB
6995
6996Let's assume that @sc{ascii} is indeed the correct character set for our
6997host system --- in other words, let's assume that if @value{GDBN} prints
6998characters using the @sc{ascii} character set, our terminal will display
6999them properly. Since our current target character set is also
7000@sc{ascii}, the contents of @code{ascii_hello} print legibly:
7001
7002@smallexample
f7dc1244 7003(@value{GDBP}) print ascii_hello
a0eb71c5 7004$1 = 0x401698 "Hello, world!\n"
f7dc1244 7005(@value{GDBP}) print ascii_hello[0]
a0eb71c5 7006$2 = 72 'H'
f7dc1244 7007(@value{GDBP})
10998722 7008@end smallexample
a0eb71c5
KB
7009
7010@value{GDBN} uses the target character set for character and string
7011literals you use in expressions:
7012
7013@smallexample
f7dc1244 7014(@value{GDBP}) print '+'
a0eb71c5 7015$3 = 43 '+'
f7dc1244 7016(@value{GDBP})
10998722 7017@end smallexample
a0eb71c5
KB
7018
7019The @sc{ascii} character set uses the number 43 to encode the @samp{+}
7020character.
7021
7022@value{GDBN} relies on the user to tell it which character set the
7023target program uses. If we print @code{ibm1047_hello} while our target
7024character set is still @sc{ascii}, we get jibberish:
7025
7026@smallexample
f7dc1244 7027(@value{GDBP}) print ibm1047_hello
a0eb71c5 7028$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 7029(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 7030$5 = 200 '\310'
f7dc1244 7031(@value{GDBP})
10998722 7032@end smallexample
a0eb71c5 7033
e33d66ec 7034If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
7035@value{GDBN} tells us the character sets it supports:
7036
7037@smallexample
f7dc1244 7038(@value{GDBP}) set target-charset
b383017d 7039ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 7040(@value{GDBP}) set target-charset
10998722 7041@end smallexample
a0eb71c5
KB
7042
7043We can select @sc{ibm1047} as our target character set, and examine the
7044program's strings again. Now the @sc{ascii} string is wrong, but
7045@value{GDBN} translates the contents of @code{ibm1047_hello} from the
7046target character set, @sc{ibm1047}, to the host character set,
7047@sc{ascii}, and they display correctly:
7048
7049@smallexample
f7dc1244
EZ
7050(@value{GDBP}) set target-charset IBM1047
7051(@value{GDBP}) show charset
e33d66ec
EZ
7052The current host character set is `ASCII'.
7053The current target character set is `IBM1047'.
f7dc1244 7054(@value{GDBP}) print ascii_hello
a0eb71c5 7055$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 7056(@value{GDBP}) print ascii_hello[0]
a0eb71c5 7057$7 = 72 '\110'
f7dc1244 7058(@value{GDBP}) print ibm1047_hello
a0eb71c5 7059$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 7060(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 7061$9 = 200 'H'
f7dc1244 7062(@value{GDBP})
10998722 7063@end smallexample
a0eb71c5
KB
7064
7065As above, @value{GDBN} uses the target character set for character and
7066string literals you use in expressions:
7067
7068@smallexample
f7dc1244 7069(@value{GDBP}) print '+'
a0eb71c5 7070$10 = 78 '+'
f7dc1244 7071(@value{GDBP})
10998722 7072@end smallexample
a0eb71c5 7073
e33d66ec 7074The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
7075character.
7076
09d4efe1
EZ
7077@node Caching Remote Data
7078@section Caching Data of Remote Targets
7079@cindex caching data of remote targets
7080
7081@value{GDBN} can cache data exchanged between the debugger and a
7082remote target (@pxref{Remote}). Such caching generally improves
7083performance, because it reduces the overhead of the remote protocol by
7084bundling memory reads and writes into large chunks. Unfortunately,
7085@value{GDBN} does not currently know anything about volatile
7086registers, and thus data caching will produce incorrect results when
7087volatile registers are in use.
7088
7089@table @code
7090@kindex set remotecache
7091@item set remotecache on
7092@itemx set remotecache off
7093Set caching state for remote targets. When @code{ON}, use data
7094caching. By default, this option is @code{OFF}.
7095
7096@kindex show remotecache
7097@item show remotecache
7098Show the current state of data caching for remote targets.
7099
7100@kindex info dcache
7101@item info dcache
7102Print the information about the data cache performance. The
7103information displayed includes: the dcache width and depth; and for
7104each cache line, how many times it was referenced, and its data and
7105state (dirty, bad, ok, etc.). This command is useful for debugging
7106the data cache operation.
7107@end table
7108
a0eb71c5 7109
e2e0bcd1
JB
7110@node Macros
7111@chapter C Preprocessor Macros
7112
49efadf5 7113Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
7114``preprocessor macros'' which expand into strings of tokens.
7115@value{GDBN} can evaluate expressions containing macro invocations, show
7116the result of macro expansion, and show a macro's definition, including
7117where it was defined.
7118
7119You may need to compile your program specially to provide @value{GDBN}
7120with information about preprocessor macros. Most compilers do not
7121include macros in their debugging information, even when you compile
7122with the @option{-g} flag. @xref{Compilation}.
7123
7124A program may define a macro at one point, remove that definition later,
7125and then provide a different definition after that. Thus, at different
7126points in the program, a macro may have different definitions, or have
7127no definition at all. If there is a current stack frame, @value{GDBN}
7128uses the macros in scope at that frame's source code line. Otherwise,
7129@value{GDBN} uses the macros in scope at the current listing location;
7130see @ref{List}.
7131
7132At the moment, @value{GDBN} does not support the @code{##}
7133token-splicing operator, the @code{#} stringification operator, or
7134variable-arity macros.
7135
7136Whenever @value{GDBN} evaluates an expression, it always expands any
7137macro invocations present in the expression. @value{GDBN} also provides
7138the following commands for working with macros explicitly.
7139
7140@table @code
7141
7142@kindex macro expand
7143@cindex macro expansion, showing the results of preprocessor
7144@cindex preprocessor macro expansion, showing the results of
7145@cindex expanding preprocessor macros
7146@item macro expand @var{expression}
7147@itemx macro exp @var{expression}
7148Show the results of expanding all preprocessor macro invocations in
7149@var{expression}. Since @value{GDBN} simply expands macros, but does
7150not parse the result, @var{expression} need not be a valid expression;
7151it can be any string of tokens.
7152
09d4efe1 7153@kindex macro exp1
e2e0bcd1
JB
7154@item macro expand-once @var{expression}
7155@itemx macro exp1 @var{expression}
4644b6e3 7156@cindex expand macro once
e2e0bcd1
JB
7157@i{(This command is not yet implemented.)} Show the results of
7158expanding those preprocessor macro invocations that appear explicitly in
7159@var{expression}. Macro invocations appearing in that expansion are
7160left unchanged. This command allows you to see the effect of a
7161particular macro more clearly, without being confused by further
7162expansions. Since @value{GDBN} simply expands macros, but does not
7163parse the result, @var{expression} need not be a valid expression; it
7164can be any string of tokens.
7165
475b0867 7166@kindex info macro
e2e0bcd1
JB
7167@cindex macro definition, showing
7168@cindex definition, showing a macro's
475b0867 7169@item info macro @var{macro}
e2e0bcd1
JB
7170Show the definition of the macro named @var{macro}, and describe the
7171source location where that definition was established.
7172
7173@kindex macro define
7174@cindex user-defined macros
7175@cindex defining macros interactively
7176@cindex macros, user-defined
7177@item macro define @var{macro} @var{replacement-list}
7178@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
7179@i{(This command is not yet implemented.)} Introduce a definition for a
7180preprocessor macro named @var{macro}, invocations of which are replaced
7181by the tokens given in @var{replacement-list}. The first form of this
7182command defines an ``object-like'' macro, which takes no arguments; the
7183second form defines a ``function-like'' macro, which takes the arguments
7184given in @var{arglist}.
7185
7186A definition introduced by this command is in scope in every expression
7187evaluated in @value{GDBN}, until it is removed with the @command{macro
7188undef} command, described below. The definition overrides all
7189definitions for @var{macro} present in the program being debugged, as
7190well as any previous user-supplied definition.
7191
7192@kindex macro undef
7193@item macro undef @var{macro}
7194@i{(This command is not yet implemented.)} Remove any user-supplied
7195definition for the macro named @var{macro}. This command only affects
7196definitions provided with the @command{macro define} command, described
7197above; it cannot remove definitions present in the program being
7198debugged.
7199
09d4efe1
EZ
7200@kindex macro list
7201@item macro list
7202@i{(This command is not yet implemented.)} List all the macros
7203defined using the @code{macro define} command.
e2e0bcd1
JB
7204@end table
7205
7206@cindex macros, example of debugging with
7207Here is a transcript showing the above commands in action. First, we
7208show our source files:
7209
7210@smallexample
7211$ cat sample.c
7212#include <stdio.h>
7213#include "sample.h"
7214
7215#define M 42
7216#define ADD(x) (M + x)
7217
7218main ()
7219@{
7220#define N 28
7221 printf ("Hello, world!\n");
7222#undef N
7223 printf ("We're so creative.\n");
7224#define N 1729
7225 printf ("Goodbye, world!\n");
7226@}
7227$ cat sample.h
7228#define Q <
7229$
7230@end smallexample
7231
7232Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
7233We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
7234compiler includes information about preprocessor macros in the debugging
7235information.
7236
7237@smallexample
7238$ gcc -gdwarf-2 -g3 sample.c -o sample
7239$
7240@end smallexample
7241
7242Now, we start @value{GDBN} on our sample program:
7243
7244@smallexample
7245$ gdb -nw sample
7246GNU gdb 2002-05-06-cvs
7247Copyright 2002 Free Software Foundation, Inc.
7248GDB is free software, @dots{}
f7dc1244 7249(@value{GDBP})
e2e0bcd1
JB
7250@end smallexample
7251
7252We can expand macros and examine their definitions, even when the
7253program is not running. @value{GDBN} uses the current listing position
7254to decide which macro definitions are in scope:
7255
7256@smallexample
f7dc1244 7257(@value{GDBP}) list main
e2e0bcd1
JB
72583
72594 #define M 42
72605 #define ADD(x) (M + x)
72616
72627 main ()
72638 @{
72649 #define N 28
726510 printf ("Hello, world!\n");
726611 #undef N
726712 printf ("We're so creative.\n");
f7dc1244 7268(@value{GDBP}) info macro ADD
e2e0bcd1
JB
7269Defined at /home/jimb/gdb/macros/play/sample.c:5
7270#define ADD(x) (M + x)
f7dc1244 7271(@value{GDBP}) info macro Q
e2e0bcd1
JB
7272Defined at /home/jimb/gdb/macros/play/sample.h:1
7273 included at /home/jimb/gdb/macros/play/sample.c:2
7274#define Q <
f7dc1244 7275(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 7276expands to: (42 + 1)
f7dc1244 7277(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 7278expands to: once (M + 1)
f7dc1244 7279(@value{GDBP})
e2e0bcd1
JB
7280@end smallexample
7281
7282In the example above, note that @command{macro expand-once} expands only
7283the macro invocation explicit in the original text --- the invocation of
7284@code{ADD} --- but does not expand the invocation of the macro @code{M},
7285which was introduced by @code{ADD}.
7286
7287Once the program is running, GDB uses the macro definitions in force at
7288the source line of the current stack frame:
7289
7290@smallexample
f7dc1244 7291(@value{GDBP}) break main
e2e0bcd1 7292Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 7293(@value{GDBP}) run
b383017d 7294Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
7295
7296Breakpoint 1, main () at sample.c:10
729710 printf ("Hello, world!\n");
f7dc1244 7298(@value{GDBP})
e2e0bcd1
JB
7299@end smallexample
7300
7301At line 10, the definition of the macro @code{N} at line 9 is in force:
7302
7303@smallexample
f7dc1244 7304(@value{GDBP}) info macro N
e2e0bcd1
JB
7305Defined at /home/jimb/gdb/macros/play/sample.c:9
7306#define N 28
f7dc1244 7307(@value{GDBP}) macro expand N Q M
e2e0bcd1 7308expands to: 28 < 42
f7dc1244 7309(@value{GDBP}) print N Q M
e2e0bcd1 7310$1 = 1
f7dc1244 7311(@value{GDBP})
e2e0bcd1
JB
7312@end smallexample
7313
7314As we step over directives that remove @code{N}'s definition, and then
7315give it a new definition, @value{GDBN} finds the definition (or lack
7316thereof) in force at each point:
7317
7318@smallexample
f7dc1244 7319(@value{GDBP}) next
e2e0bcd1
JB
7320Hello, world!
732112 printf ("We're so creative.\n");
f7dc1244 7322(@value{GDBP}) info macro N
e2e0bcd1
JB
7323The symbol `N' has no definition as a C/C++ preprocessor macro
7324at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 7325(@value{GDBP}) next
e2e0bcd1
JB
7326We're so creative.
732714 printf ("Goodbye, world!\n");
f7dc1244 7328(@value{GDBP}) info macro N
e2e0bcd1
JB
7329Defined at /home/jimb/gdb/macros/play/sample.c:13
7330#define N 1729
f7dc1244 7331(@value{GDBP}) macro expand N Q M
e2e0bcd1 7332expands to: 1729 < 42
f7dc1244 7333(@value{GDBP}) print N Q M
e2e0bcd1 7334$2 = 0
f7dc1244 7335(@value{GDBP})
e2e0bcd1
JB
7336@end smallexample
7337
7338
b37052ae
EZ
7339@node Tracepoints
7340@chapter Tracepoints
7341@c This chapter is based on the documentation written by Michael
7342@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
7343
7344@cindex tracepoints
7345In some applications, it is not feasible for the debugger to interrupt
7346the program's execution long enough for the developer to learn
7347anything helpful about its behavior. If the program's correctness
7348depends on its real-time behavior, delays introduced by a debugger
7349might cause the program to change its behavior drastically, or perhaps
7350fail, even when the code itself is correct. It is useful to be able
7351to observe the program's behavior without interrupting it.
7352
7353Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
7354specify locations in the program, called @dfn{tracepoints}, and
7355arbitrary expressions to evaluate when those tracepoints are reached.
7356Later, using the @code{tfind} command, you can examine the values
7357those expressions had when the program hit the tracepoints. The
7358expressions may also denote objects in memory---structures or arrays,
7359for example---whose values @value{GDBN} should record; while visiting
7360a particular tracepoint, you may inspect those objects as if they were
7361in memory at that moment. However, because @value{GDBN} records these
7362values without interacting with you, it can do so quickly and
7363unobtrusively, hopefully not disturbing the program's behavior.
7364
7365The tracepoint facility is currently available only for remote
9d29849a
JB
7366targets. @xref{Targets}. In addition, your remote target must know
7367how to collect trace data. This functionality is implemented in the
7368remote stub; however, none of the stubs distributed with @value{GDBN}
7369support tracepoints as of this writing. The format of the remote
7370packets used to implement tracepoints are described in @ref{Tracepoint
7371Packets}.
b37052ae
EZ
7372
7373This chapter describes the tracepoint commands and features.
7374
7375@menu
b383017d
RM
7376* Set Tracepoints::
7377* Analyze Collected Data::
7378* Tracepoint Variables::
b37052ae
EZ
7379@end menu
7380
7381@node Set Tracepoints
7382@section Commands to Set Tracepoints
7383
7384Before running such a @dfn{trace experiment}, an arbitrary number of
7385tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
7386tracepoint has a number assigned to it by @value{GDBN}. Like with
7387breakpoints, tracepoint numbers are successive integers starting from
7388one. Many of the commands associated with tracepoints take the
7389tracepoint number as their argument, to identify which tracepoint to
7390work on.
7391
7392For each tracepoint, you can specify, in advance, some arbitrary set
7393of data that you want the target to collect in the trace buffer when
7394it hits that tracepoint. The collected data can include registers,
7395local variables, or global data. Later, you can use @value{GDBN}
7396commands to examine the values these data had at the time the
7397tracepoint was hit.
7398
7399This section describes commands to set tracepoints and associated
7400conditions and actions.
7401
7402@menu
b383017d
RM
7403* Create and Delete Tracepoints::
7404* Enable and Disable Tracepoints::
7405* Tracepoint Passcounts::
7406* Tracepoint Actions::
7407* Listing Tracepoints::
7408* Starting and Stopping Trace Experiment::
b37052ae
EZ
7409@end menu
7410
7411@node Create and Delete Tracepoints
7412@subsection Create and Delete Tracepoints
7413
7414@table @code
7415@cindex set tracepoint
7416@kindex trace
7417@item trace
7418The @code{trace} command is very similar to the @code{break} command.
7419Its argument can be a source line, a function name, or an address in
7420the target program. @xref{Set Breaks}. The @code{trace} command
7421defines a tracepoint, which is a point in the target program where the
7422debugger will briefly stop, collect some data, and then allow the
7423program to continue. Setting a tracepoint or changing its commands
7424doesn't take effect until the next @code{tstart} command; thus, you
7425cannot change the tracepoint attributes once a trace experiment is
7426running.
7427
7428Here are some examples of using the @code{trace} command:
7429
7430@smallexample
7431(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
7432
7433(@value{GDBP}) @b{trace +2} // 2 lines forward
7434
7435(@value{GDBP}) @b{trace my_function} // first source line of function
7436
7437(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
7438
7439(@value{GDBP}) @b{trace *0x2117c4} // an address
7440@end smallexample
7441
7442@noindent
7443You can abbreviate @code{trace} as @code{tr}.
7444
7445@vindex $tpnum
7446@cindex last tracepoint number
7447@cindex recent tracepoint number
7448@cindex tracepoint number
7449The convenience variable @code{$tpnum} records the tracepoint number
7450of the most recently set tracepoint.
7451
7452@kindex delete tracepoint
7453@cindex tracepoint deletion
7454@item delete tracepoint @r{[}@var{num}@r{]}
7455Permanently delete one or more tracepoints. With no argument, the
7456default is to delete all tracepoints.
7457
7458Examples:
7459
7460@smallexample
7461(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7462
7463(@value{GDBP}) @b{delete trace} // remove all tracepoints
7464@end smallexample
7465
7466@noindent
7467You can abbreviate this command as @code{del tr}.
7468@end table
7469
7470@node Enable and Disable Tracepoints
7471@subsection Enable and Disable Tracepoints
7472
7473@table @code
7474@kindex disable tracepoint
7475@item disable tracepoint @r{[}@var{num}@r{]}
7476Disable tracepoint @var{num}, or all tracepoints if no argument
7477@var{num} is given. A disabled tracepoint will have no effect during
7478the next trace experiment, but it is not forgotten. You can re-enable
7479a disabled tracepoint using the @code{enable tracepoint} command.
7480
7481@kindex enable tracepoint
7482@item enable tracepoint @r{[}@var{num}@r{]}
7483Enable tracepoint @var{num}, or all tracepoints. The enabled
7484tracepoints will become effective the next time a trace experiment is
7485run.
7486@end table
7487
7488@node Tracepoint Passcounts
7489@subsection Tracepoint Passcounts
7490
7491@table @code
7492@kindex passcount
7493@cindex tracepoint pass count
7494@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7495Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7496automatically stop a trace experiment. If a tracepoint's passcount is
7497@var{n}, then the trace experiment will be automatically stopped on
7498the @var{n}'th time that tracepoint is hit. If the tracepoint number
7499@var{num} is not specified, the @code{passcount} command sets the
7500passcount of the most recently defined tracepoint. If no passcount is
7501given, the trace experiment will run until stopped explicitly by the
7502user.
7503
7504Examples:
7505
7506@smallexample
b383017d 7507(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 7508@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
7509
7510(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 7511@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
7512(@value{GDBP}) @b{trace foo}
7513(@value{GDBP}) @b{pass 3}
7514(@value{GDBP}) @b{trace bar}
7515(@value{GDBP}) @b{pass 2}
7516(@value{GDBP}) @b{trace baz}
7517(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
7518@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7519@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7520@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
7521@end smallexample
7522@end table
7523
7524@node Tracepoint Actions
7525@subsection Tracepoint Action Lists
7526
7527@table @code
7528@kindex actions
7529@cindex tracepoint actions
7530@item actions @r{[}@var{num}@r{]}
7531This command will prompt for a list of actions to be taken when the
7532tracepoint is hit. If the tracepoint number @var{num} is not
7533specified, this command sets the actions for the one that was most
7534recently defined (so that you can define a tracepoint and then say
7535@code{actions} without bothering about its number). You specify the
7536actions themselves on the following lines, one action at a time, and
7537terminate the actions list with a line containing just @code{end}. So
7538far, the only defined actions are @code{collect} and
7539@code{while-stepping}.
7540
7541@cindex remove actions from a tracepoint
7542To remove all actions from a tracepoint, type @samp{actions @var{num}}
7543and follow it immediately with @samp{end}.
7544
7545@smallexample
7546(@value{GDBP}) @b{collect @var{data}} // collect some data
7547
6826cf00 7548(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 7549
6826cf00 7550(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
7551@end smallexample
7552
7553In the following example, the action list begins with @code{collect}
7554commands indicating the things to be collected when the tracepoint is
7555hit. Then, in order to single-step and collect additional data
7556following the tracepoint, a @code{while-stepping} command is used,
7557followed by the list of things to be collected while stepping. The
7558@code{while-stepping} command is terminated by its own separate
7559@code{end} command. Lastly, the action list is terminated by an
7560@code{end} command.
7561
7562@smallexample
7563(@value{GDBP}) @b{trace foo}
7564(@value{GDBP}) @b{actions}
7565Enter actions for tracepoint 1, one per line:
7566> collect bar,baz
7567> collect $regs
7568> while-stepping 12
7569 > collect $fp, $sp
7570 > end
7571end
7572@end smallexample
7573
7574@kindex collect @r{(tracepoints)}
7575@item collect @var{expr1}, @var{expr2}, @dots{}
7576Collect values of the given expressions when the tracepoint is hit.
7577This command accepts a comma-separated list of any valid expressions.
7578In addition to global, static, or local variables, the following
7579special arguments are supported:
7580
7581@table @code
7582@item $regs
7583collect all registers
7584
7585@item $args
7586collect all function arguments
7587
7588@item $locals
7589collect all local variables.
7590@end table
7591
7592You can give several consecutive @code{collect} commands, each one
7593with a single argument, or one @code{collect} command with several
7594arguments separated by commas: the effect is the same.
7595
f5c37c66
EZ
7596The command @code{info scope} (@pxref{Symbols, info scope}) is
7597particularly useful for figuring out what data to collect.
7598
b37052ae
EZ
7599@kindex while-stepping @r{(tracepoints)}
7600@item while-stepping @var{n}
7601Perform @var{n} single-step traces after the tracepoint, collecting
7602new data at each step. The @code{while-stepping} command is
7603followed by the list of what to collect while stepping (followed by
7604its own @code{end} command):
7605
7606@smallexample
7607> while-stepping 12
7608 > collect $regs, myglobal
7609 > end
7610>
7611@end smallexample
7612
7613@noindent
7614You may abbreviate @code{while-stepping} as @code{ws} or
7615@code{stepping}.
7616@end table
7617
7618@node Listing Tracepoints
7619@subsection Listing Tracepoints
7620
7621@table @code
7622@kindex info tracepoints
09d4efe1 7623@kindex info tp
b37052ae
EZ
7624@cindex information about tracepoints
7625@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 7626Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 7627a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
7628defined so far. For each tracepoint, the following information is
7629shown:
7630
7631@itemize @bullet
7632@item
7633its number
7634@item
7635whether it is enabled or disabled
7636@item
7637its address
7638@item
7639its passcount as given by the @code{passcount @var{n}} command
7640@item
7641its step count as given by the @code{while-stepping @var{n}} command
7642@item
7643where in the source files is the tracepoint set
7644@item
7645its action list as given by the @code{actions} command
7646@end itemize
7647
7648@smallexample
7649(@value{GDBP}) @b{info trace}
7650Num Enb Address PassC StepC What
76511 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
76522 y 0x0020dc64 0 0 in g_test at g_test.c:1375
76533 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
7654(@value{GDBP})
7655@end smallexample
7656
7657@noindent
7658This command can be abbreviated @code{info tp}.
7659@end table
7660
7661@node Starting and Stopping Trace Experiment
7662@subsection Starting and Stopping Trace Experiment
7663
7664@table @code
7665@kindex tstart
7666@cindex start a new trace experiment
7667@cindex collected data discarded
7668@item tstart
7669This command takes no arguments. It starts the trace experiment, and
7670begins collecting data. This has the side effect of discarding all
7671the data collected in the trace buffer during the previous trace
7672experiment.
7673
7674@kindex tstop
7675@cindex stop a running trace experiment
7676@item tstop
7677This command takes no arguments. It ends the trace experiment, and
7678stops collecting data.
7679
68c71a2e 7680@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
7681automatically if any tracepoint's passcount is reached
7682(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7683
7684@kindex tstatus
7685@cindex status of trace data collection
7686@cindex trace experiment, status of
7687@item tstatus
7688This command displays the status of the current trace data
7689collection.
7690@end table
7691
7692Here is an example of the commands we described so far:
7693
7694@smallexample
7695(@value{GDBP}) @b{trace gdb_c_test}
7696(@value{GDBP}) @b{actions}
7697Enter actions for tracepoint #1, one per line.
7698> collect $regs,$locals,$args
7699> while-stepping 11
7700 > collect $regs
7701 > end
7702> end
7703(@value{GDBP}) @b{tstart}
7704 [time passes @dots{}]
7705(@value{GDBP}) @b{tstop}
7706@end smallexample
7707
7708
7709@node Analyze Collected Data
7710@section Using the collected data
7711
7712After the tracepoint experiment ends, you use @value{GDBN} commands
7713for examining the trace data. The basic idea is that each tracepoint
7714collects a trace @dfn{snapshot} every time it is hit and another
7715snapshot every time it single-steps. All these snapshots are
7716consecutively numbered from zero and go into a buffer, and you can
7717examine them later. The way you examine them is to @dfn{focus} on a
7718specific trace snapshot. When the remote stub is focused on a trace
7719snapshot, it will respond to all @value{GDBN} requests for memory and
7720registers by reading from the buffer which belongs to that snapshot,
7721rather than from @emph{real} memory or registers of the program being
7722debugged. This means that @strong{all} @value{GDBN} commands
7723(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7724behave as if we were currently debugging the program state as it was
7725when the tracepoint occurred. Any requests for data that are not in
7726the buffer will fail.
7727
7728@menu
7729* tfind:: How to select a trace snapshot
7730* tdump:: How to display all data for a snapshot
7731* save-tracepoints:: How to save tracepoints for a future run
7732@end menu
7733
7734@node tfind
7735@subsection @code{tfind @var{n}}
7736
7737@kindex tfind
7738@cindex select trace snapshot
7739@cindex find trace snapshot
7740The basic command for selecting a trace snapshot from the buffer is
7741@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7742counting from zero. If no argument @var{n} is given, the next
7743snapshot is selected.
7744
7745Here are the various forms of using the @code{tfind} command.
7746
7747@table @code
7748@item tfind start
7749Find the first snapshot in the buffer. This is a synonym for
7750@code{tfind 0} (since 0 is the number of the first snapshot).
7751
7752@item tfind none
7753Stop debugging trace snapshots, resume @emph{live} debugging.
7754
7755@item tfind end
7756Same as @samp{tfind none}.
7757
7758@item tfind
7759No argument means find the next trace snapshot.
7760
7761@item tfind -
7762Find the previous trace snapshot before the current one. This permits
7763retracing earlier steps.
7764
7765@item tfind tracepoint @var{num}
7766Find the next snapshot associated with tracepoint @var{num}. Search
7767proceeds forward from the last examined trace snapshot. If no
7768argument @var{num} is given, it means find the next snapshot collected
7769for the same tracepoint as the current snapshot.
7770
7771@item tfind pc @var{addr}
7772Find the next snapshot associated with the value @var{addr} of the
7773program counter. Search proceeds forward from the last examined trace
7774snapshot. If no argument @var{addr} is given, it means find the next
7775snapshot with the same value of PC as the current snapshot.
7776
7777@item tfind outside @var{addr1}, @var{addr2}
7778Find the next snapshot whose PC is outside the given range of
7779addresses.
7780
7781@item tfind range @var{addr1}, @var{addr2}
7782Find the next snapshot whose PC is between @var{addr1} and
7783@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7784
7785@item tfind line @r{[}@var{file}:@r{]}@var{n}
7786Find the next snapshot associated with the source line @var{n}. If
7787the optional argument @var{file} is given, refer to line @var{n} in
7788that source file. Search proceeds forward from the last examined
7789trace snapshot. If no argument @var{n} is given, it means find the
7790next line other than the one currently being examined; thus saying
7791@code{tfind line} repeatedly can appear to have the same effect as
7792stepping from line to line in a @emph{live} debugging session.
7793@end table
7794
7795The default arguments for the @code{tfind} commands are specifically
7796designed to make it easy to scan through the trace buffer. For
7797instance, @code{tfind} with no argument selects the next trace
7798snapshot, and @code{tfind -} with no argument selects the previous
7799trace snapshot. So, by giving one @code{tfind} command, and then
7800simply hitting @key{RET} repeatedly you can examine all the trace
7801snapshots in order. Or, by saying @code{tfind -} and then hitting
7802@key{RET} repeatedly you can examine the snapshots in reverse order.
7803The @code{tfind line} command with no argument selects the snapshot
7804for the next source line executed. The @code{tfind pc} command with
7805no argument selects the next snapshot with the same program counter
7806(PC) as the current frame. The @code{tfind tracepoint} command with
7807no argument selects the next trace snapshot collected by the same
7808tracepoint as the current one.
7809
7810In addition to letting you scan through the trace buffer manually,
7811these commands make it easy to construct @value{GDBN} scripts that
7812scan through the trace buffer and print out whatever collected data
7813you are interested in. Thus, if we want to examine the PC, FP, and SP
7814registers from each trace frame in the buffer, we can say this:
7815
7816@smallexample
7817(@value{GDBP}) @b{tfind start}
7818(@value{GDBP}) @b{while ($trace_frame != -1)}
7819> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7820 $trace_frame, $pc, $sp, $fp
7821> tfind
7822> end
7823
7824Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7825Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7826Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7827Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7828Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7829Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7830Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7831Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7832Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7833Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7834Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7835@end smallexample
7836
7837Or, if we want to examine the variable @code{X} at each source line in
7838the buffer:
7839
7840@smallexample
7841(@value{GDBP}) @b{tfind start}
7842(@value{GDBP}) @b{while ($trace_frame != -1)}
7843> printf "Frame %d, X == %d\n", $trace_frame, X
7844> tfind line
7845> end
7846
7847Frame 0, X = 1
7848Frame 7, X = 2
7849Frame 13, X = 255
7850@end smallexample
7851
7852@node tdump
7853@subsection @code{tdump}
7854@kindex tdump
7855@cindex dump all data collected at tracepoint
7856@cindex tracepoint data, display
7857
7858This command takes no arguments. It prints all the data collected at
7859the current trace snapshot.
7860
7861@smallexample
7862(@value{GDBP}) @b{trace 444}
7863(@value{GDBP}) @b{actions}
7864Enter actions for tracepoint #2, one per line:
7865> collect $regs, $locals, $args, gdb_long_test
7866> end
7867
7868(@value{GDBP}) @b{tstart}
7869
7870(@value{GDBP}) @b{tfind line 444}
7871#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7872at gdb_test.c:444
7873444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7874
7875(@value{GDBP}) @b{tdump}
7876Data collected at tracepoint 2, trace frame 1:
7877d0 0xc4aa0085 -995491707
7878d1 0x18 24
7879d2 0x80 128
7880d3 0x33 51
7881d4 0x71aea3d 119204413
7882d5 0x22 34
7883d6 0xe0 224
7884d7 0x380035 3670069
7885a0 0x19e24a 1696330
7886a1 0x3000668 50333288
7887a2 0x100 256
7888a3 0x322000 3284992
7889a4 0x3000698 50333336
7890a5 0x1ad3cc 1758156
7891fp 0x30bf3c 0x30bf3c
7892sp 0x30bf34 0x30bf34
7893ps 0x0 0
7894pc 0x20b2c8 0x20b2c8
7895fpcontrol 0x0 0
7896fpstatus 0x0 0
7897fpiaddr 0x0 0
7898p = 0x20e5b4 "gdb-test"
7899p1 = (void *) 0x11
7900p2 = (void *) 0x22
7901p3 = (void *) 0x33
7902p4 = (void *) 0x44
7903p5 = (void *) 0x55
7904p6 = (void *) 0x66
7905gdb_long_test = 17 '\021'
7906
7907(@value{GDBP})
7908@end smallexample
7909
7910@node save-tracepoints
7911@subsection @code{save-tracepoints @var{filename}}
7912@kindex save-tracepoints
7913@cindex save tracepoints for future sessions
7914
7915This command saves all current tracepoint definitions together with
7916their actions and passcounts, into a file @file{@var{filename}}
7917suitable for use in a later debugging session. To read the saved
7918tracepoint definitions, use the @code{source} command (@pxref{Command
7919Files}).
7920
7921@node Tracepoint Variables
7922@section Convenience Variables for Tracepoints
7923@cindex tracepoint variables
7924@cindex convenience variables for tracepoints
7925
7926@table @code
7927@vindex $trace_frame
7928@item (int) $trace_frame
7929The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7930snapshot is selected.
7931
7932@vindex $tracepoint
7933@item (int) $tracepoint
7934The tracepoint for the current trace snapshot.
7935
7936@vindex $trace_line
7937@item (int) $trace_line
7938The line number for the current trace snapshot.
7939
7940@vindex $trace_file
7941@item (char []) $trace_file
7942The source file for the current trace snapshot.
7943
7944@vindex $trace_func
7945@item (char []) $trace_func
7946The name of the function containing @code{$tracepoint}.
7947@end table
7948
7949Note: @code{$trace_file} is not suitable for use in @code{printf},
7950use @code{output} instead.
7951
7952Here's a simple example of using these convenience variables for
7953stepping through all the trace snapshots and printing some of their
7954data.
7955
7956@smallexample
7957(@value{GDBP}) @b{tfind start}
7958
7959(@value{GDBP}) @b{while $trace_frame != -1}
7960> output $trace_file
7961> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7962> tfind
7963> end
7964@end smallexample
7965
df0cd8c5
JB
7966@node Overlays
7967@chapter Debugging Programs That Use Overlays
7968@cindex overlays
7969
7970If your program is too large to fit completely in your target system's
7971memory, you can sometimes use @dfn{overlays} to work around this
7972problem. @value{GDBN} provides some support for debugging programs that
7973use overlays.
7974
7975@menu
7976* How Overlays Work:: A general explanation of overlays.
7977* Overlay Commands:: Managing overlays in @value{GDBN}.
7978* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7979 mapped by asking the inferior.
7980* Overlay Sample Program:: A sample program using overlays.
7981@end menu
7982
7983@node How Overlays Work
7984@section How Overlays Work
7985@cindex mapped overlays
7986@cindex unmapped overlays
7987@cindex load address, overlay's
7988@cindex mapped address
7989@cindex overlay area
7990
7991Suppose you have a computer whose instruction address space is only 64
7992kilobytes long, but which has much more memory which can be accessed by
7993other means: special instructions, segment registers, or memory
7994management hardware, for example. Suppose further that you want to
7995adapt a program which is larger than 64 kilobytes to run on this system.
7996
7997One solution is to identify modules of your program which are relatively
7998independent, and need not call each other directly; call these modules
7999@dfn{overlays}. Separate the overlays from the main program, and place
8000their machine code in the larger memory. Place your main program in
8001instruction memory, but leave at least enough space there to hold the
8002largest overlay as well.
8003
8004Now, to call a function located in an overlay, you must first copy that
8005overlay's machine code from the large memory into the space set aside
8006for it in the instruction memory, and then jump to its entry point
8007there.
8008
c928edc0
AC
8009@c NB: In the below the mapped area's size is greater or equal to the
8010@c size of all overlays. This is intentional to remind the developer
8011@c that overlays don't necessarily need to be the same size.
8012
474c8240 8013@smallexample
df0cd8c5 8014@group
c928edc0
AC
8015 Data Instruction Larger
8016Address Space Address Space Address Space
8017+-----------+ +-----------+ +-----------+
8018| | | | | |
8019+-----------+ +-----------+ +-----------+<-- overlay 1
8020| program | | main | .----| overlay 1 | load address
8021| variables | | program | | +-----------+
8022| and heap | | | | | |
8023+-----------+ | | | +-----------+<-- overlay 2
8024| | +-----------+ | | | load address
8025+-----------+ | | | .-| overlay 2 |
8026 | | | | | |
8027 mapped --->+-----------+ | | +-----------+
8028 address | | | | | |
8029 | overlay | <-' | | |
8030 | area | <---' +-----------+<-- overlay 3
8031 | | <---. | | load address
8032 +-----------+ `--| overlay 3 |
8033 | | | |
8034 +-----------+ | |
8035 +-----------+
8036 | |
8037 +-----------+
8038
8039 @anchor{A code overlay}A code overlay
df0cd8c5 8040@end group
474c8240 8041@end smallexample
df0cd8c5 8042
c928edc0
AC
8043The diagram (@pxref{A code overlay}) shows a system with separate data
8044and instruction address spaces. To map an overlay, the program copies
8045its code from the larger address space to the instruction address space.
8046Since the overlays shown here all use the same mapped address, only one
8047may be mapped at a time. For a system with a single address space for
8048data and instructions, the diagram would be similar, except that the
8049program variables and heap would share an address space with the main
8050program and the overlay area.
df0cd8c5
JB
8051
8052An overlay loaded into instruction memory and ready for use is called a
8053@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
8054instruction memory. An overlay not present (or only partially present)
8055in instruction memory is called @dfn{unmapped}; its @dfn{load address}
8056is its address in the larger memory. The mapped address is also called
8057the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
8058called the @dfn{load memory address}, or @dfn{LMA}.
8059
8060Unfortunately, overlays are not a completely transparent way to adapt a
8061program to limited instruction memory. They introduce a new set of
8062global constraints you must keep in mind as you design your program:
8063
8064@itemize @bullet
8065
8066@item
8067Before calling or returning to a function in an overlay, your program
8068must make sure that overlay is actually mapped. Otherwise, the call or
8069return will transfer control to the right address, but in the wrong
8070overlay, and your program will probably crash.
8071
8072@item
8073If the process of mapping an overlay is expensive on your system, you
8074will need to choose your overlays carefully to minimize their effect on
8075your program's performance.
8076
8077@item
8078The executable file you load onto your system must contain each
8079overlay's instructions, appearing at the overlay's load address, not its
8080mapped address. However, each overlay's instructions must be relocated
8081and its symbols defined as if the overlay were at its mapped address.
8082You can use GNU linker scripts to specify different load and relocation
8083addresses for pieces of your program; see @ref{Overlay Description,,,
8084ld.info, Using ld: the GNU linker}.
8085
8086@item
8087The procedure for loading executable files onto your system must be able
8088to load their contents into the larger address space as well as the
8089instruction and data spaces.
8090
8091@end itemize
8092
8093The overlay system described above is rather simple, and could be
8094improved in many ways:
8095
8096@itemize @bullet
8097
8098@item
8099If your system has suitable bank switch registers or memory management
8100hardware, you could use those facilities to make an overlay's load area
8101contents simply appear at their mapped address in instruction space.
8102This would probably be faster than copying the overlay to its mapped
8103area in the usual way.
8104
8105@item
8106If your overlays are small enough, you could set aside more than one
8107overlay area, and have more than one overlay mapped at a time.
8108
8109@item
8110You can use overlays to manage data, as well as instructions. In
8111general, data overlays are even less transparent to your design than
8112code overlays: whereas code overlays only require care when you call or
8113return to functions, data overlays require care every time you access
8114the data. Also, if you change the contents of a data overlay, you
8115must copy its contents back out to its load address before you can copy a
8116different data overlay into the same mapped area.
8117
8118@end itemize
8119
8120
8121@node Overlay Commands
8122@section Overlay Commands
8123
8124To use @value{GDBN}'s overlay support, each overlay in your program must
8125correspond to a separate section of the executable file. The section's
8126virtual memory address and load memory address must be the overlay's
8127mapped and load addresses. Identifying overlays with sections allows
8128@value{GDBN} to determine the appropriate address of a function or
8129variable, depending on whether the overlay is mapped or not.
8130
8131@value{GDBN}'s overlay commands all start with the word @code{overlay};
8132you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
8133
8134@table @code
8135@item overlay off
4644b6e3 8136@kindex overlay
df0cd8c5
JB
8137Disable @value{GDBN}'s overlay support. When overlay support is
8138disabled, @value{GDBN} assumes that all functions and variables are
8139always present at their mapped addresses. By default, @value{GDBN}'s
8140overlay support is disabled.
8141
8142@item overlay manual
df0cd8c5
JB
8143@cindex manual overlay debugging
8144Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
8145relies on you to tell it which overlays are mapped, and which are not,
8146using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
8147commands described below.
8148
8149@item overlay map-overlay @var{overlay}
8150@itemx overlay map @var{overlay}
df0cd8c5
JB
8151@cindex map an overlay
8152Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
8153be the name of the object file section containing the overlay. When an
8154overlay is mapped, @value{GDBN} assumes it can find the overlay's
8155functions and variables at their mapped addresses. @value{GDBN} assumes
8156that any other overlays whose mapped ranges overlap that of
8157@var{overlay} are now unmapped.
8158
8159@item overlay unmap-overlay @var{overlay}
8160@itemx overlay unmap @var{overlay}
df0cd8c5
JB
8161@cindex unmap an overlay
8162Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
8163must be the name of the object file section containing the overlay.
8164When an overlay is unmapped, @value{GDBN} assumes it can find the
8165overlay's functions and variables at their load addresses.
8166
8167@item overlay auto
df0cd8c5
JB
8168Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
8169consults a data structure the overlay manager maintains in the inferior
8170to see which overlays are mapped. For details, see @ref{Automatic
8171Overlay Debugging}.
8172
8173@item overlay load-target
8174@itemx overlay load
df0cd8c5
JB
8175@cindex reloading the overlay table
8176Re-read the overlay table from the inferior. Normally, @value{GDBN}
8177re-reads the table @value{GDBN} automatically each time the inferior
8178stops, so this command should only be necessary if you have changed the
8179overlay mapping yourself using @value{GDBN}. This command is only
8180useful when using automatic overlay debugging.
8181
8182@item overlay list-overlays
8183@itemx overlay list
8184@cindex listing mapped overlays
8185Display a list of the overlays currently mapped, along with their mapped
8186addresses, load addresses, and sizes.
8187
8188@end table
8189
8190Normally, when @value{GDBN} prints a code address, it includes the name
8191of the function the address falls in:
8192
474c8240 8193@smallexample
f7dc1244 8194(@value{GDBP}) print main
df0cd8c5 8195$3 = @{int ()@} 0x11a0 <main>
474c8240 8196@end smallexample
df0cd8c5
JB
8197@noindent
8198When overlay debugging is enabled, @value{GDBN} recognizes code in
8199unmapped overlays, and prints the names of unmapped functions with
8200asterisks around them. For example, if @code{foo} is a function in an
8201unmapped overlay, @value{GDBN} prints it this way:
8202
474c8240 8203@smallexample
f7dc1244 8204(@value{GDBP}) overlay list
df0cd8c5 8205No sections are mapped.
f7dc1244 8206(@value{GDBP}) print foo
df0cd8c5 8207$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 8208@end smallexample
df0cd8c5
JB
8209@noindent
8210When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
8211name normally:
8212
474c8240 8213@smallexample
f7dc1244 8214(@value{GDBP}) overlay list
b383017d 8215Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 8216 mapped at 0x1016 - 0x104a
f7dc1244 8217(@value{GDBP}) print foo
df0cd8c5 8218$6 = @{int (int)@} 0x1016 <foo>
474c8240 8219@end smallexample
df0cd8c5
JB
8220
8221When overlay debugging is enabled, @value{GDBN} can find the correct
8222address for functions and variables in an overlay, whether or not the
8223overlay is mapped. This allows most @value{GDBN} commands, like
8224@code{break} and @code{disassemble}, to work normally, even on unmapped
8225code. However, @value{GDBN}'s breakpoint support has some limitations:
8226
8227@itemize @bullet
8228@item
8229@cindex breakpoints in overlays
8230@cindex overlays, setting breakpoints in
8231You can set breakpoints in functions in unmapped overlays, as long as
8232@value{GDBN} can write to the overlay at its load address.
8233@item
8234@value{GDBN} can not set hardware or simulator-based breakpoints in
8235unmapped overlays. However, if you set a breakpoint at the end of your
8236overlay manager (and tell @value{GDBN} which overlays are now mapped, if
8237you are using manual overlay management), @value{GDBN} will re-set its
8238breakpoints properly.
8239@end itemize
8240
8241
8242@node Automatic Overlay Debugging
8243@section Automatic Overlay Debugging
8244@cindex automatic overlay debugging
8245
8246@value{GDBN} can automatically track which overlays are mapped and which
8247are not, given some simple co-operation from the overlay manager in the
8248inferior. If you enable automatic overlay debugging with the
8249@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
8250looks in the inferior's memory for certain variables describing the
8251current state of the overlays.
8252
8253Here are the variables your overlay manager must define to support
8254@value{GDBN}'s automatic overlay debugging:
8255
8256@table @asis
8257
8258@item @code{_ovly_table}:
8259This variable must be an array of the following structures:
8260
474c8240 8261@smallexample
df0cd8c5
JB
8262struct
8263@{
8264 /* The overlay's mapped address. */
8265 unsigned long vma;
8266
8267 /* The size of the overlay, in bytes. */
8268 unsigned long size;
8269
8270 /* The overlay's load address. */
8271 unsigned long lma;
8272
8273 /* Non-zero if the overlay is currently mapped;
8274 zero otherwise. */
8275 unsigned long mapped;
8276@}
474c8240 8277@end smallexample
df0cd8c5
JB
8278
8279@item @code{_novlys}:
8280This variable must be a four-byte signed integer, holding the total
8281number of elements in @code{_ovly_table}.
8282
8283@end table
8284
8285To decide whether a particular overlay is mapped or not, @value{GDBN}
8286looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
8287@code{lma} members equal the VMA and LMA of the overlay's section in the
8288executable file. When @value{GDBN} finds a matching entry, it consults
8289the entry's @code{mapped} member to determine whether the overlay is
8290currently mapped.
8291
81d46470 8292In addition, your overlay manager may define a function called
def71bfa 8293@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
8294will silently set a breakpoint there. If the overlay manager then
8295calls this function whenever it has changed the overlay table, this
8296will enable @value{GDBN} to accurately keep track of which overlays
8297are in program memory, and update any breakpoints that may be set
b383017d 8298in overlays. This will allow breakpoints to work even if the
81d46470
MS
8299overlays are kept in ROM or other non-writable memory while they
8300are not being executed.
df0cd8c5
JB
8301
8302@node Overlay Sample Program
8303@section Overlay Sample Program
8304@cindex overlay example program
8305
8306When linking a program which uses overlays, you must place the overlays
8307at their load addresses, while relocating them to run at their mapped
8308addresses. To do this, you must write a linker script (@pxref{Overlay
8309Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
8310since linker scripts are specific to a particular host system, target
8311architecture, and target memory layout, this manual cannot provide
8312portable sample code demonstrating @value{GDBN}'s overlay support.
8313
8314However, the @value{GDBN} source distribution does contain an overlaid
8315program, with linker scripts for a few systems, as part of its test
8316suite. The program consists of the following files from
8317@file{gdb/testsuite/gdb.base}:
8318
8319@table @file
8320@item overlays.c
8321The main program file.
8322@item ovlymgr.c
8323A simple overlay manager, used by @file{overlays.c}.
8324@item foo.c
8325@itemx bar.c
8326@itemx baz.c
8327@itemx grbx.c
8328Overlay modules, loaded and used by @file{overlays.c}.
8329@item d10v.ld
8330@itemx m32r.ld
8331Linker scripts for linking the test program on the @code{d10v-elf}
8332and @code{m32r-elf} targets.
8333@end table
8334
8335You can build the test program using the @code{d10v-elf} GCC
8336cross-compiler like this:
8337
474c8240 8338@smallexample
df0cd8c5
JB
8339$ d10v-elf-gcc -g -c overlays.c
8340$ d10v-elf-gcc -g -c ovlymgr.c
8341$ d10v-elf-gcc -g -c foo.c
8342$ d10v-elf-gcc -g -c bar.c
8343$ d10v-elf-gcc -g -c baz.c
8344$ d10v-elf-gcc -g -c grbx.c
8345$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
8346 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 8347@end smallexample
df0cd8c5
JB
8348
8349The build process is identical for any other architecture, except that
8350you must substitute the appropriate compiler and linker script for the
8351target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
8352
8353
6d2ebf8b 8354@node Languages
c906108c
SS
8355@chapter Using @value{GDBN} with Different Languages
8356@cindex languages
8357
c906108c
SS
8358Although programming languages generally have common aspects, they are
8359rarely expressed in the same manner. For instance, in ANSI C,
8360dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
8361Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 8362represented (and displayed) differently. Hex numbers in C appear as
c906108c 8363@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
8364
8365@cindex working language
8366Language-specific information is built into @value{GDBN} for some languages,
8367allowing you to express operations like the above in your program's
8368native language, and allowing @value{GDBN} to output values in a manner
8369consistent with the syntax of your program's native language. The
8370language you use to build expressions is called the @dfn{working
8371language}.
8372
8373@menu
8374* Setting:: Switching between source languages
8375* Show:: Displaying the language
c906108c 8376* Checks:: Type and range checks
9c16f35a 8377* Supported languages:: Supported languages
4e562065 8378* Unsupported languages:: Unsupported languages
c906108c
SS
8379@end menu
8380
6d2ebf8b 8381@node Setting
c906108c
SS
8382@section Switching between source languages
8383
8384There are two ways to control the working language---either have @value{GDBN}
8385set it automatically, or select it manually yourself. You can use the
8386@code{set language} command for either purpose. On startup, @value{GDBN}
8387defaults to setting the language automatically. The working language is
8388used to determine how expressions you type are interpreted, how values
8389are printed, etc.
8390
8391In addition to the working language, every source file that
8392@value{GDBN} knows about has its own working language. For some object
8393file formats, the compiler might indicate which language a particular
8394source file is in. However, most of the time @value{GDBN} infers the
8395language from the name of the file. The language of a source file
b37052ae 8396controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 8397show each frame appropriately for its own language. There is no way to
d4f3574e
SS
8398set the language of a source file from within @value{GDBN}, but you can
8399set the language associated with a filename extension. @xref{Show, ,
8400Displaying the language}.
c906108c
SS
8401
8402This is most commonly a problem when you use a program, such
5d161b24 8403as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
8404another language. In that case, make the
8405program use @code{#line} directives in its C output; that way
8406@value{GDBN} will know the correct language of the source code of the original
8407program, and will display that source code, not the generated C code.
8408
8409@menu
8410* Filenames:: Filename extensions and languages.
8411* Manually:: Setting the working language manually
8412* Automatically:: Having @value{GDBN} infer the source language
8413@end menu
8414
6d2ebf8b 8415@node Filenames
c906108c
SS
8416@subsection List of filename extensions and languages
8417
8418If a source file name ends in one of the following extensions, then
8419@value{GDBN} infers that its language is the one indicated.
8420
8421@table @file
e07c999f
PH
8422@item .ada
8423@itemx .ads
8424@itemx .adb
8425@itemx .a
8426Ada source file.
c906108c
SS
8427
8428@item .c
8429C source file
8430
8431@item .C
8432@itemx .cc
8433@itemx .cp
8434@itemx .cpp
8435@itemx .cxx
8436@itemx .c++
b37052ae 8437C@t{++} source file
c906108c 8438
b37303ee
AF
8439@item .m
8440Objective-C source file
8441
c906108c
SS
8442@item .f
8443@itemx .F
8444Fortran source file
8445
c906108c
SS
8446@item .mod
8447Modula-2 source file
c906108c
SS
8448
8449@item .s
8450@itemx .S
8451Assembler source file. This actually behaves almost like C, but
8452@value{GDBN} does not skip over function prologues when stepping.
8453@end table
8454
8455In addition, you may set the language associated with a filename
8456extension. @xref{Show, , Displaying the language}.
8457
6d2ebf8b 8458@node Manually
c906108c
SS
8459@subsection Setting the working language
8460
8461If you allow @value{GDBN} to set the language automatically,
8462expressions are interpreted the same way in your debugging session and
8463your program.
8464
8465@kindex set language
8466If you wish, you may set the language manually. To do this, issue the
8467command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 8468a language, such as
c906108c 8469@code{c} or @code{modula-2}.
c906108c
SS
8470For a list of the supported languages, type @samp{set language}.
8471
c906108c
SS
8472Setting the language manually prevents @value{GDBN} from updating the working
8473language automatically. This can lead to confusion if you try
8474to debug a program when the working language is not the same as the
8475source language, when an expression is acceptable to both
8476languages---but means different things. For instance, if the current
8477source file were written in C, and @value{GDBN} was parsing Modula-2, a
8478command such as:
8479
474c8240 8480@smallexample
c906108c 8481print a = b + c
474c8240 8482@end smallexample
c906108c
SS
8483
8484@noindent
8485might not have the effect you intended. In C, this means to add
8486@code{b} and @code{c} and place the result in @code{a}. The result
8487printed would be the value of @code{a}. In Modula-2, this means to compare
8488@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 8489
6d2ebf8b 8490@node Automatically
c906108c
SS
8491@subsection Having @value{GDBN} infer the source language
8492
8493To have @value{GDBN} set the working language automatically, use
8494@samp{set language local} or @samp{set language auto}. @value{GDBN}
8495then infers the working language. That is, when your program stops in a
8496frame (usually by encountering a breakpoint), @value{GDBN} sets the
8497working language to the language recorded for the function in that
8498frame. If the language for a frame is unknown (that is, if the function
8499or block corresponding to the frame was defined in a source file that
8500does not have a recognized extension), the current working language is
8501not changed, and @value{GDBN} issues a warning.
8502
8503This may not seem necessary for most programs, which are written
8504entirely in one source language. However, program modules and libraries
8505written in one source language can be used by a main program written in
8506a different source language. Using @samp{set language auto} in this
8507case frees you from having to set the working language manually.
8508
6d2ebf8b 8509@node Show
c906108c 8510@section Displaying the language
c906108c
SS
8511
8512The following commands help you find out which language is the
8513working language, and also what language source files were written in.
8514
c906108c
SS
8515@table @code
8516@item show language
9c16f35a 8517@kindex show language
c906108c
SS
8518Display the current working language. This is the
8519language you can use with commands such as @code{print} to
8520build and compute expressions that may involve variables in your program.
8521
8522@item info frame
4644b6e3 8523@kindex info frame@r{, show the source language}
5d161b24 8524Display the source language for this frame. This language becomes the
c906108c 8525working language if you use an identifier from this frame.
5d161b24 8526@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
8527information listed here.
8528
8529@item info source
4644b6e3 8530@kindex info source@r{, show the source language}
c906108c 8531Display the source language of this source file.
5d161b24 8532@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
8533information listed here.
8534@end table
8535
8536In unusual circumstances, you may have source files with extensions
8537not in the standard list. You can then set the extension associated
8538with a language explicitly:
8539
c906108c 8540@table @code
09d4efe1 8541@item set extension-language @var{ext} @var{language}
9c16f35a 8542@kindex set extension-language
09d4efe1
EZ
8543Tell @value{GDBN} that source files with extension @var{ext} are to be
8544assumed as written in the source language @var{language}.
c906108c
SS
8545
8546@item info extensions
9c16f35a 8547@kindex info extensions
c906108c
SS
8548List all the filename extensions and the associated languages.
8549@end table
8550
6d2ebf8b 8551@node Checks
c906108c
SS
8552@section Type and range checking
8553
8554@quotation
8555@emph{Warning:} In this release, the @value{GDBN} commands for type and range
8556checking are included, but they do not yet have any effect. This
8557section documents the intended facilities.
8558@end quotation
8559@c FIXME remove warning when type/range code added
8560
8561Some languages are designed to guard you against making seemingly common
8562errors through a series of compile- and run-time checks. These include
8563checking the type of arguments to functions and operators, and making
8564sure mathematical overflows are caught at run time. Checks such as
8565these help to ensure a program's correctness once it has been compiled
8566by eliminating type mismatches, and providing active checks for range
8567errors when your program is running.
8568
8569@value{GDBN} can check for conditions like the above if you wish.
9c16f35a
EZ
8570Although @value{GDBN} does not check the statements in your program,
8571it can check expressions entered directly into @value{GDBN} for
8572evaluation via the @code{print} command, for example. As with the
8573working language, @value{GDBN} can also decide whether or not to check
8574automatically based on your program's source language.
8575@xref{Supported languages, ,Supported languages}, for the default
8576settings of supported languages.
c906108c
SS
8577
8578@menu
8579* Type Checking:: An overview of type checking
8580* Range Checking:: An overview of range checking
8581@end menu
8582
8583@cindex type checking
8584@cindex checks, type
6d2ebf8b 8585@node Type Checking
c906108c
SS
8586@subsection An overview of type checking
8587
8588Some languages, such as Modula-2, are strongly typed, meaning that the
8589arguments to operators and functions have to be of the correct type,
8590otherwise an error occurs. These checks prevent type mismatch
8591errors from ever causing any run-time problems. For example,
8592
8593@smallexample
85941 + 2 @result{} 3
8595@exdent but
8596@error{} 1 + 2.3
8597@end smallexample
8598
8599The second example fails because the @code{CARDINAL} 1 is not
8600type-compatible with the @code{REAL} 2.3.
8601
5d161b24
DB
8602For the expressions you use in @value{GDBN} commands, you can tell the
8603@value{GDBN} type checker to skip checking;
8604to treat any mismatches as errors and abandon the expression;
8605or to only issue warnings when type mismatches occur,
c906108c
SS
8606but evaluate the expression anyway. When you choose the last of
8607these, @value{GDBN} evaluates expressions like the second example above, but
8608also issues a warning.
8609
5d161b24
DB
8610Even if you turn type checking off, there may be other reasons
8611related to type that prevent @value{GDBN} from evaluating an expression.
8612For instance, @value{GDBN} does not know how to add an @code{int} and
8613a @code{struct foo}. These particular type errors have nothing to do
8614with the language in use, and usually arise from expressions, such as
c906108c
SS
8615the one described above, which make little sense to evaluate anyway.
8616
8617Each language defines to what degree it is strict about type. For
8618instance, both Modula-2 and C require the arguments to arithmetical
8619operators to be numbers. In C, enumerated types and pointers can be
8620represented as numbers, so that they are valid arguments to mathematical
9c16f35a 8621operators. @xref{Supported languages, ,Supported languages}, for further
c906108c
SS
8622details on specific languages.
8623
8624@value{GDBN} provides some additional commands for controlling the type checker:
8625
c906108c
SS
8626@kindex set check type
8627@kindex show check type
8628@table @code
8629@item set check type auto
8630Set type checking on or off based on the current working language.
9c16f35a 8631@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8632each language.
8633
8634@item set check type on
8635@itemx set check type off
8636Set type checking on or off, overriding the default setting for the
8637current working language. Issue a warning if the setting does not
8638match the language default. If any type mismatches occur in
d4f3574e 8639evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
8640message and aborts evaluation of the expression.
8641
8642@item set check type warn
8643Cause the type checker to issue warnings, but to always attempt to
8644evaluate the expression. Evaluating the expression may still
8645be impossible for other reasons. For example, @value{GDBN} cannot add
8646numbers and structures.
8647
8648@item show type
5d161b24 8649Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
8650is setting it automatically.
8651@end table
8652
8653@cindex range checking
8654@cindex checks, range
6d2ebf8b 8655@node Range Checking
c906108c
SS
8656@subsection An overview of range checking
8657
8658In some languages (such as Modula-2), it is an error to exceed the
8659bounds of a type; this is enforced with run-time checks. Such range
8660checking is meant to ensure program correctness by making sure
8661computations do not overflow, or indices on an array element access do
8662not exceed the bounds of the array.
8663
8664For expressions you use in @value{GDBN} commands, you can tell
8665@value{GDBN} to treat range errors in one of three ways: ignore them,
8666always treat them as errors and abandon the expression, or issue
8667warnings but evaluate the expression anyway.
8668
8669A range error can result from numerical overflow, from exceeding an
8670array index bound, or when you type a constant that is not a member
8671of any type. Some languages, however, do not treat overflows as an
8672error. In many implementations of C, mathematical overflow causes the
8673result to ``wrap around'' to lower values---for example, if @var{m} is
8674the largest integer value, and @var{s} is the smallest, then
8675
474c8240 8676@smallexample
c906108c 8677@var{m} + 1 @result{} @var{s}
474c8240 8678@end smallexample
c906108c
SS
8679
8680This, too, is specific to individual languages, and in some cases
9c16f35a 8681specific to individual compilers or machines. @xref{Supported languages, ,
c906108c
SS
8682Supported languages}, for further details on specific languages.
8683
8684@value{GDBN} provides some additional commands for controlling the range checker:
8685
c906108c
SS
8686@kindex set check range
8687@kindex show check range
8688@table @code
8689@item set check range auto
8690Set range checking on or off based on the current working language.
9c16f35a 8691@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8692each language.
8693
8694@item set check range on
8695@itemx set check range off
8696Set range checking on or off, overriding the default setting for the
8697current working language. A warning is issued if the setting does not
c3f6f71d
JM
8698match the language default. If a range error occurs and range checking is on,
8699then a message is printed and evaluation of the expression is aborted.
c906108c
SS
8700
8701@item set check range warn
8702Output messages when the @value{GDBN} range checker detects a range error,
8703but attempt to evaluate the expression anyway. Evaluating the
8704expression may still be impossible for other reasons, such as accessing
8705memory that the process does not own (a typical example from many Unix
8706systems).
8707
8708@item show range
8709Show the current setting of the range checker, and whether or not it is
8710being set automatically by @value{GDBN}.
8711@end table
c906108c 8712
9c16f35a 8713@node Supported languages
c906108c 8714@section Supported languages
c906108c 8715
9c16f35a
EZ
8716@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
8717assembly, Modula-2, and Ada.
cce74817 8718@c This is false ...
c906108c
SS
8719Some @value{GDBN} features may be used in expressions regardless of the
8720language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8721and the @samp{@{type@}addr} construct (@pxref{Expressions,
8722,Expressions}) can be used with the constructs of any supported
8723language.
8724
8725The following sections detail to what degree each source language is
8726supported by @value{GDBN}. These sections are not meant to be language
8727tutorials or references, but serve only as a reference guide to what the
8728@value{GDBN} expression parser accepts, and what input and output
8729formats should look like for different languages. There are many good
8730books written on each of these languages; please look to these for a
8731language reference or tutorial.
8732
c906108c 8733@menu
b37303ee 8734* C:: C and C@t{++}
b383017d 8735* Objective-C:: Objective-C
09d4efe1 8736* Fortran:: Fortran
9c16f35a 8737* Pascal:: Pascal
b37303ee 8738* Modula-2:: Modula-2
e07c999f 8739* Ada:: Ada
c906108c
SS
8740@end menu
8741
6d2ebf8b 8742@node C
b37052ae 8743@subsection C and C@t{++}
7a292a7a 8744
b37052ae
EZ
8745@cindex C and C@t{++}
8746@cindex expressions in C or C@t{++}
c906108c 8747
b37052ae 8748Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8749to both languages. Whenever this is the case, we discuss those languages
8750together.
8751
41afff9a
EZ
8752@cindex C@t{++}
8753@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8754@cindex @sc{gnu} C@t{++}
8755The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8756compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8757effectively, you must compile your C@t{++} programs with a supported
8758C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8759compiler (@code{aCC}).
8760
0179ffac
DC
8761For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8762format; if it doesn't work on your system, try the stabs+ debugging
8763format. You can select those formats explicitly with the @code{g++}
8764command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8765@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8766CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8767
c906108c 8768@menu
b37052ae
EZ
8769* C Operators:: C and C@t{++} operators
8770* C Constants:: C and C@t{++} constants
8771* C plus plus expressions:: C@t{++} expressions
8772* C Defaults:: Default settings for C and C@t{++}
8773* C Checks:: C and C@t{++} type and range checks
c906108c 8774* Debugging C:: @value{GDBN} and C
b37052ae 8775* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8776@end menu
c906108c 8777
6d2ebf8b 8778@node C Operators
b37052ae 8779@subsubsection C and C@t{++} operators
7a292a7a 8780
b37052ae 8781@cindex C and C@t{++} operators
c906108c
SS
8782
8783Operators must be defined on values of specific types. For instance,
8784@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8785often defined on groups of types.
c906108c 8786
b37052ae 8787For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8788
8789@itemize @bullet
53a5351d 8790
c906108c 8791@item
c906108c 8792@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8793specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8794
8795@item
d4f3574e
SS
8796@emph{Floating-point types} include @code{float}, @code{double}, and
8797@code{long double} (if supported by the target platform).
c906108c
SS
8798
8799@item
53a5351d 8800@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8801
8802@item
8803@emph{Scalar types} include all of the above.
53a5351d 8804
c906108c
SS
8805@end itemize
8806
8807@noindent
8808The following operators are supported. They are listed here
8809in order of increasing precedence:
8810
8811@table @code
8812@item ,
8813The comma or sequencing operator. Expressions in a comma-separated list
8814are evaluated from left to right, with the result of the entire
8815expression being the last expression evaluated.
8816
8817@item =
8818Assignment. The value of an assignment expression is the value
8819assigned. Defined on scalar types.
8820
8821@item @var{op}=
8822Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8823and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8824@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8825@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8826@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8827
8828@item ?:
8829The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8830of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8831integral type.
8832
8833@item ||
8834Logical @sc{or}. Defined on integral types.
8835
8836@item &&
8837Logical @sc{and}. Defined on integral types.
8838
8839@item |
8840Bitwise @sc{or}. Defined on integral types.
8841
8842@item ^
8843Bitwise exclusive-@sc{or}. Defined on integral types.
8844
8845@item &
8846Bitwise @sc{and}. Defined on integral types.
8847
8848@item ==@r{, }!=
8849Equality and inequality. Defined on scalar types. The value of these
8850expressions is 0 for false and non-zero for true.
8851
8852@item <@r{, }>@r{, }<=@r{, }>=
8853Less than, greater than, less than or equal, greater than or equal.
8854Defined on scalar types. The value of these expressions is 0 for false
8855and non-zero for true.
8856
8857@item <<@r{, }>>
8858left shift, and right shift. Defined on integral types.
8859
8860@item @@
8861The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8862
8863@item +@r{, }-
8864Addition and subtraction. Defined on integral types, floating-point types and
8865pointer types.
8866
8867@item *@r{, }/@r{, }%
8868Multiplication, division, and modulus. Multiplication and division are
8869defined on integral and floating-point types. Modulus is defined on
8870integral types.
8871
8872@item ++@r{, }--
8873Increment and decrement. When appearing before a variable, the
8874operation is performed before the variable is used in an expression;
8875when appearing after it, the variable's value is used before the
8876operation takes place.
8877
8878@item *
8879Pointer dereferencing. Defined on pointer types. Same precedence as
8880@code{++}.
8881
8882@item &
8883Address operator. Defined on variables. Same precedence as @code{++}.
8884
b37052ae
EZ
8885For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8886allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8887(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8888where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8889stored.
c906108c
SS
8890
8891@item -
8892Negative. Defined on integral and floating-point types. Same
8893precedence as @code{++}.
8894
8895@item !
8896Logical negation. Defined on integral types. Same precedence as
8897@code{++}.
8898
8899@item ~
8900Bitwise complement operator. Defined on integral types. Same precedence as
8901@code{++}.
8902
8903
8904@item .@r{, }->
8905Structure member, and pointer-to-structure member. For convenience,
8906@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8907pointer based on the stored type information.
8908Defined on @code{struct} and @code{union} data.
8909
c906108c
SS
8910@item .*@r{, }->*
8911Dereferences of pointers to members.
c906108c
SS
8912
8913@item []
8914Array indexing. @code{@var{a}[@var{i}]} is defined as
8915@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8916
8917@item ()
8918Function parameter list. Same precedence as @code{->}.
8919
c906108c 8920@item ::
b37052ae 8921C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8922and @code{class} types.
c906108c
SS
8923
8924@item ::
7a292a7a
SS
8925Doubled colons also represent the @value{GDBN} scope operator
8926(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8927above.
c906108c
SS
8928@end table
8929
c906108c
SS
8930If an operator is redefined in the user code, @value{GDBN} usually
8931attempts to invoke the redefined version instead of using the operator's
8932predefined meaning.
c906108c 8933
c906108c 8934@menu
5d161b24 8935* C Constants::
c906108c
SS
8936@end menu
8937
6d2ebf8b 8938@node C Constants
b37052ae 8939@subsubsection C and C@t{++} constants
c906108c 8940
b37052ae 8941@cindex C and C@t{++} constants
c906108c 8942
b37052ae 8943@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8944following ways:
c906108c
SS
8945
8946@itemize @bullet
8947@item
8948Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8949specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8950by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8951@samp{l}, specifying that the constant should be treated as a
8952@code{long} value.
8953
8954@item
8955Floating point constants are a sequence of digits, followed by a decimal
8956point, followed by a sequence of digits, and optionally followed by an
8957exponent. An exponent is of the form:
8958@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8959sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8960A floating-point constant may also end with a letter @samp{f} or
8961@samp{F}, specifying that the constant should be treated as being of
8962the @code{float} (as opposed to the default @code{double}) type; or with
8963a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8964constant.
c906108c
SS
8965
8966@item
8967Enumerated constants consist of enumerated identifiers, or their
8968integral equivalents.
8969
8970@item
8971Character constants are a single character surrounded by single quotes
8972(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8973(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8974be represented by a letter or by @dfn{escape sequences}, which are of
8975the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8976of the character's ordinal value; or of the form @samp{\@var{x}}, where
8977@samp{@var{x}} is a predefined special character---for example,
8978@samp{\n} for newline.
8979
8980@item
96a2c332
SS
8981String constants are a sequence of character constants surrounded by
8982double quotes (@code{"}). Any valid character constant (as described
8983above) may appear. Double quotes within the string must be preceded by
8984a backslash, so for instance @samp{"a\"b'c"} is a string of five
8985characters.
c906108c
SS
8986
8987@item
8988Pointer constants are an integral value. You can also write pointers
8989to constants using the C operator @samp{&}.
8990
8991@item
8992Array constants are comma-separated lists surrounded by braces @samp{@{}
8993and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8994integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8995and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8996@end itemize
8997
c906108c 8998@menu
5d161b24
DB
8999* C plus plus expressions::
9000* C Defaults::
9001* C Checks::
c906108c 9002
5d161b24 9003* Debugging C::
c906108c
SS
9004@end menu
9005
6d2ebf8b 9006@node C plus plus expressions
b37052ae
EZ
9007@subsubsection C@t{++} expressions
9008
9009@cindex expressions in C@t{++}
9010@value{GDBN} expression handling can interpret most C@t{++} expressions.
9011
0179ffac
DC
9012@cindex debugging C@t{++} programs
9013@cindex C@t{++} compilers
9014@cindex debug formats and C@t{++}
9015@cindex @value{NGCC} and C@t{++}
c906108c 9016@quotation
b37052ae 9017@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
9018proper compiler and the proper debug format. Currently, @value{GDBN}
9019works best when debugging C@t{++} code that is compiled with
9020@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
9021@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
9022stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
9023stabs+ as their default debug format, so you usually don't need to
9024specify a debug format explicitly. Other compilers and/or debug formats
9025are likely to work badly or not at all when using @value{GDBN} to debug
9026C@t{++} code.
c906108c 9027@end quotation
c906108c
SS
9028
9029@enumerate
9030
9031@cindex member functions
9032@item
9033Member function calls are allowed; you can use expressions like
9034
474c8240 9035@smallexample
c906108c 9036count = aml->GetOriginal(x, y)
474c8240 9037@end smallexample
c906108c 9038
41afff9a 9039@vindex this@r{, inside C@t{++} member functions}
b37052ae 9040@cindex namespace in C@t{++}
c906108c
SS
9041@item
9042While a member function is active (in the selected stack frame), your
9043expressions have the same namespace available as the member function;
9044that is, @value{GDBN} allows implicit references to the class instance
b37052ae 9045pointer @code{this} following the same rules as C@t{++}.
c906108c 9046
c906108c 9047@cindex call overloaded functions
d4f3574e 9048@cindex overloaded functions, calling
b37052ae 9049@cindex type conversions in C@t{++}
c906108c
SS
9050@item
9051You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 9052call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
9053perform overload resolution involving user-defined type conversions,
9054calls to constructors, or instantiations of templates that do not exist
9055in the program. It also cannot handle ellipsis argument lists or
9056default arguments.
9057
9058It does perform integral conversions and promotions, floating-point
9059promotions, arithmetic conversions, pointer conversions, conversions of
9060class objects to base classes, and standard conversions such as those of
9061functions or arrays to pointers; it requires an exact match on the
9062number of function arguments.
9063
9064Overload resolution is always performed, unless you have specified
9065@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 9066,@value{GDBN} features for C@t{++}}.
c906108c 9067
d4f3574e 9068You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
9069explicit function signature to call an overloaded function, as in
9070@smallexample
9071p 'foo(char,int)'('x', 13)
9072@end smallexample
d4f3574e 9073
c906108c 9074The @value{GDBN} command-completion facility can simplify this;
d4f3574e 9075see @ref{Completion, ,Command completion}.
c906108c 9076
c906108c
SS
9077@cindex reference declarations
9078@item
b37052ae
EZ
9079@value{GDBN} understands variables declared as C@t{++} references; you can use
9080them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
9081dereferenced.
9082
9083In the parameter list shown when @value{GDBN} displays a frame, the values of
9084reference variables are not displayed (unlike other variables); this
9085avoids clutter, since references are often used for large structures.
9086The @emph{address} of a reference variable is always shown, unless
9087you have specified @samp{set print address off}.
9088
9089@item
b37052ae 9090@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
9091expressions can use it just as expressions in your program do. Since
9092one scope may be defined in another, you can use @code{::} repeatedly if
9093necessary, for example in an expression like
9094@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 9095resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
9096debugging (@pxref{Variables, ,Program variables}).
9097@end enumerate
9098
b37052ae 9099In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
9100calling virtual functions correctly, printing out virtual bases of
9101objects, calling functions in a base subobject, casting objects, and
9102invoking user-defined operators.
c906108c 9103
6d2ebf8b 9104@node C Defaults
b37052ae 9105@subsubsection C and C@t{++} defaults
7a292a7a 9106
b37052ae 9107@cindex C and C@t{++} defaults
c906108c 9108
c906108c
SS
9109If you allow @value{GDBN} to set type and range checking automatically, they
9110both default to @code{off} whenever the working language changes to
b37052ae 9111C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 9112selects the working language.
c906108c
SS
9113
9114If you allow @value{GDBN} to set the language automatically, it
9115recognizes source files whose names end with @file{.c}, @file{.C}, or
9116@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 9117these files, it sets the working language to C or C@t{++}.
c906108c
SS
9118@xref{Automatically, ,Having @value{GDBN} infer the source language},
9119for further details.
9120
c906108c
SS
9121@c Type checking is (a) primarily motivated by Modula-2, and (b)
9122@c unimplemented. If (b) changes, it might make sense to let this node
9123@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 9124
6d2ebf8b 9125@node C Checks
b37052ae 9126@subsubsection C and C@t{++} type and range checks
7a292a7a 9127
b37052ae 9128@cindex C and C@t{++} checks
c906108c 9129
b37052ae 9130By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
9131is not used. However, if you turn type checking on, @value{GDBN}
9132considers two variables type equivalent if:
9133
9134@itemize @bullet
9135@item
9136The two variables are structured and have the same structure, union, or
9137enumerated tag.
9138
9139@item
9140The two variables have the same type name, or types that have been
9141declared equivalent through @code{typedef}.
9142
9143@ignore
9144@c leaving this out because neither J Gilmore nor R Pesch understand it.
9145@c FIXME--beers?
9146@item
9147The two @code{struct}, @code{union}, or @code{enum} variables are
9148declared in the same declaration. (Note: this may not be true for all C
9149compilers.)
9150@end ignore
9151@end itemize
9152
9153Range checking, if turned on, is done on mathematical operations. Array
9154indices are not checked, since they are often used to index a pointer
9155that is not itself an array.
c906108c 9156
6d2ebf8b 9157@node Debugging C
c906108c 9158@subsubsection @value{GDBN} and C
c906108c
SS
9159
9160The @code{set print union} and @code{show print union} commands apply to
9161the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
9162inside a @code{struct} or @code{class} is also printed. Otherwise, it
9163appears as @samp{@{...@}}.
c906108c
SS
9164
9165The @code{@@} operator aids in the debugging of dynamic arrays, formed
9166with pointers and a memory allocation function. @xref{Expressions,
9167,Expressions}.
9168
c906108c 9169@menu
5d161b24 9170* Debugging C plus plus::
c906108c
SS
9171@end menu
9172
6d2ebf8b 9173@node Debugging C plus plus
b37052ae 9174@subsubsection @value{GDBN} features for C@t{++}
c906108c 9175
b37052ae 9176@cindex commands for C@t{++}
7a292a7a 9177
b37052ae
EZ
9178Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
9179designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
9180
9181@table @code
9182@cindex break in overloaded functions
9183@item @r{breakpoint menus}
9184When you want a breakpoint in a function whose name is overloaded,
9185@value{GDBN} breakpoint menus help you specify which function definition
9186you want. @xref{Breakpoint Menus,,Breakpoint menus}.
9187
b37052ae 9188@cindex overloading in C@t{++}
c906108c
SS
9189@item rbreak @var{regex}
9190Setting breakpoints using regular expressions is helpful for setting
9191breakpoints on overloaded functions that are not members of any special
9192classes.
9193@xref{Set Breaks, ,Setting breakpoints}.
9194
b37052ae 9195@cindex C@t{++} exception handling
c906108c
SS
9196@item catch throw
9197@itemx catch catch
b37052ae 9198Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
9199Catchpoints, , Setting catchpoints}.
9200
9201@cindex inheritance
9202@item ptype @var{typename}
9203Print inheritance relationships as well as other information for type
9204@var{typename}.
9205@xref{Symbols, ,Examining the Symbol Table}.
9206
b37052ae 9207@cindex C@t{++} symbol display
c906108c
SS
9208@item set print demangle
9209@itemx show print demangle
9210@itemx set print asm-demangle
9211@itemx show print asm-demangle
b37052ae
EZ
9212Control whether C@t{++} symbols display in their source form, both when
9213displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
9214@xref{Print Settings, ,Print settings}.
9215
9216@item set print object
9217@itemx show print object
9218Choose whether to print derived (actual) or declared types of objects.
9219@xref{Print Settings, ,Print settings}.
9220
9221@item set print vtbl
9222@itemx show print vtbl
9223Control the format for printing virtual function tables.
9224@xref{Print Settings, ,Print settings}.
c906108c 9225(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 9226ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
9227
9228@kindex set overload-resolution
d4f3574e 9229@cindex overloaded functions, overload resolution
c906108c 9230@item set overload-resolution on
b37052ae 9231Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
9232is on. For overloaded functions, @value{GDBN} evaluates the arguments
9233and searches for a function whose signature matches the argument types,
b37052ae 9234using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 9235expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
9236message.
9237
9238@item set overload-resolution off
b37052ae 9239Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
9240overloaded functions that are not class member functions, @value{GDBN}
9241chooses the first function of the specified name that it finds in the
9242symbol table, whether or not its arguments are of the correct type. For
9243overloaded functions that are class member functions, @value{GDBN}
9244searches for a function whose signature @emph{exactly} matches the
9245argument types.
c906108c 9246
9c16f35a
EZ
9247@kindex show overload-resolution
9248@item show overload-resolution
9249Show the current setting of overload resolution.
9250
c906108c
SS
9251@item @r{Overloaded symbol names}
9252You can specify a particular definition of an overloaded symbol, using
b37052ae 9253the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
9254@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
9255also use the @value{GDBN} command-line word completion facilities to list the
9256available choices, or to finish the type list for you.
9257@xref{Completion,, Command completion}, for details on how to do this.
9258@end table
c906108c 9259
b37303ee
AF
9260@node Objective-C
9261@subsection Objective-C
9262
9263@cindex Objective-C
9264This section provides information about some commands and command
721c2651
EZ
9265options that are useful for debugging Objective-C code. See also
9266@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
9267few more commands specific to Objective-C support.
b37303ee
AF
9268
9269@menu
b383017d
RM
9270* Method Names in Commands::
9271* The Print Command with Objective-C::
b37303ee
AF
9272@end menu
9273
9274@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
9275@subsubsection Method Names in Commands
9276
9277The following commands have been extended to accept Objective-C method
9278names as line specifications:
9279
9280@kindex clear@r{, and Objective-C}
9281@kindex break@r{, and Objective-C}
9282@kindex info line@r{, and Objective-C}
9283@kindex jump@r{, and Objective-C}
9284@kindex list@r{, and Objective-C}
9285@itemize
9286@item @code{clear}
9287@item @code{break}
9288@item @code{info line}
9289@item @code{jump}
9290@item @code{list}
9291@end itemize
9292
9293A fully qualified Objective-C method name is specified as
9294
9295@smallexample
9296-[@var{Class} @var{methodName}]
9297@end smallexample
9298
c552b3bb
JM
9299where the minus sign is used to indicate an instance method and a
9300plus sign (not shown) is used to indicate a class method. The class
9301name @var{Class} and method name @var{methodName} are enclosed in
9302brackets, similar to the way messages are specified in Objective-C
9303source code. For example, to set a breakpoint at the @code{create}
9304instance method of class @code{Fruit} in the program currently being
9305debugged, enter:
b37303ee
AF
9306
9307@smallexample
9308break -[Fruit create]
9309@end smallexample
9310
9311To list ten program lines around the @code{initialize} class method,
9312enter:
9313
9314@smallexample
9315list +[NSText initialize]
9316@end smallexample
9317
c552b3bb
JM
9318In the current version of @value{GDBN}, the plus or minus sign is
9319required. In future versions of @value{GDBN}, the plus or minus
9320sign will be optional, but you can use it to narrow the search. It
9321is also possible to specify just a method name:
b37303ee
AF
9322
9323@smallexample
9324break create
9325@end smallexample
9326
9327You must specify the complete method name, including any colons. If
9328your program's source files contain more than one @code{create} method,
9329you'll be presented with a numbered list of classes that implement that
9330method. Indicate your choice by number, or type @samp{0} to exit if
9331none apply.
9332
9333As another example, to clear a breakpoint established at the
9334@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
9335
9336@smallexample
9337clear -[NSWindow makeKeyAndOrderFront:]
9338@end smallexample
9339
9340@node The Print Command with Objective-C
9341@subsubsection The Print Command With Objective-C
721c2651 9342@cindex Objective-C, print objects
c552b3bb
JM
9343@kindex print-object
9344@kindex po @r{(@code{print-object})}
b37303ee 9345
c552b3bb 9346The print command has also been extended to accept methods. For example:
b37303ee
AF
9347
9348@smallexample
c552b3bb 9349print -[@var{object} hash]
b37303ee
AF
9350@end smallexample
9351
9352@cindex print an Objective-C object description
c552b3bb
JM
9353@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
9354@noindent
9355will tell @value{GDBN} to send the @code{hash} message to @var{object}
9356and print the result. Also, an additional command has been added,
9357@code{print-object} or @code{po} for short, which is meant to print
9358the description of an object. However, this command may only work
9359with certain Objective-C libraries that have a particular hook
9360function, @code{_NSPrintForDebugger}, defined.
b37303ee 9361
09d4efe1
EZ
9362@node Fortran
9363@subsection Fortran
9364@cindex Fortran-specific support in @value{GDBN}
9365
814e32d7
WZ
9366@value{GDBN} can be used to debug programs written in Fortran, but it
9367currently supports only the features of Fortran 77 language.
9368
9369@cindex trailing underscore, in Fortran symbols
9370Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
9371among them) append an underscore to the names of variables and
9372functions. When you debug programs compiled by those compilers, you
9373will need to refer to variables and functions with a trailing
9374underscore.
9375
9376@menu
9377* Fortran Operators:: Fortran operators and expressions
9378* Fortran Defaults:: Default settings for Fortran
9379* Special Fortran commands:: Special @value{GDBN} commands for Fortran
9380@end menu
9381
9382@node Fortran Operators
9383@subsubsection Fortran operators and expressions
9384
9385@cindex Fortran operators and expressions
9386
9387Operators must be defined on values of specific types. For instance,
9388@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 9389arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
9390
9391@table @code
9392@item **
9393The exponentiation operator. It raises the first operand to the power
9394of the second one.
9395
9396@item :
9397The range operator. Normally used in the form of array(low:high) to
9398represent a section of array.
9399@end table
9400
9401@node Fortran Defaults
9402@subsubsection Fortran Defaults
9403
9404@cindex Fortran Defaults
9405
9406Fortran symbols are usually case-insensitive, so @value{GDBN} by
9407default uses case-insensitive matches for Fortran symbols. You can
9408change that with the @samp{set case-insensitive} command, see
9409@ref{Symbols}, for the details.
9410
9411@node Special Fortran commands
9412@subsubsection Special Fortran commands
9413
9414@cindex Special Fortran commands
9415
9416@value{GDBN} had some commands to support Fortran specific feature,
9417such as common block displaying.
9418
09d4efe1
EZ
9419@table @code
9420@cindex @code{COMMON} blocks, Fortran
9421@kindex info common
9422@item info common @r{[}@var{common-name}@r{]}
9423This command prints the values contained in the Fortran @code{COMMON}
9424block whose name is @var{common-name}. With no argument, the names of
9425all @code{COMMON} blocks visible at current program location are
9426printed.
9427@end table
9428
9c16f35a
EZ
9429@node Pascal
9430@subsection Pascal
9431
9432@cindex Pascal support in @value{GDBN}, limitations
9433Debugging Pascal programs which use sets, subranges, file variables, or
9434nested functions does not currently work. @value{GDBN} does not support
9435entering expressions, printing values, or similar features using Pascal
9436syntax.
9437
9438The Pascal-specific command @code{set print pascal_static-members}
9439controls whether static members of Pascal objects are displayed.
9440@xref{Print Settings, pascal_static-members}.
9441
09d4efe1 9442@node Modula-2
c906108c 9443@subsection Modula-2
7a292a7a 9444
d4f3574e 9445@cindex Modula-2, @value{GDBN} support
c906108c
SS
9446
9447The extensions made to @value{GDBN} to support Modula-2 only support
9448output from the @sc{gnu} Modula-2 compiler (which is currently being
9449developed). Other Modula-2 compilers are not currently supported, and
9450attempting to debug executables produced by them is most likely
9451to give an error as @value{GDBN} reads in the executable's symbol
9452table.
9453
9454@cindex expressions in Modula-2
9455@menu
9456* M2 Operators:: Built-in operators
9457* Built-In Func/Proc:: Built-in functions and procedures
9458* M2 Constants:: Modula-2 constants
9459* M2 Defaults:: Default settings for Modula-2
9460* Deviations:: Deviations from standard Modula-2
9461* M2 Checks:: Modula-2 type and range checks
9462* M2 Scope:: The scope operators @code{::} and @code{.}
9463* GDB/M2:: @value{GDBN} and Modula-2
9464@end menu
9465
6d2ebf8b 9466@node M2 Operators
c906108c
SS
9467@subsubsection Operators
9468@cindex Modula-2 operators
9469
9470Operators must be defined on values of specific types. For instance,
9471@code{+} is defined on numbers, but not on structures. Operators are
9472often defined on groups of types. For the purposes of Modula-2, the
9473following definitions hold:
9474
9475@itemize @bullet
9476
9477@item
9478@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
9479their subranges.
9480
9481@item
9482@emph{Character types} consist of @code{CHAR} and its subranges.
9483
9484@item
9485@emph{Floating-point types} consist of @code{REAL}.
9486
9487@item
9488@emph{Pointer types} consist of anything declared as @code{POINTER TO
9489@var{type}}.
9490
9491@item
9492@emph{Scalar types} consist of all of the above.
9493
9494@item
9495@emph{Set types} consist of @code{SET} and @code{BITSET} types.
9496
9497@item
9498@emph{Boolean types} consist of @code{BOOLEAN}.
9499@end itemize
9500
9501@noindent
9502The following operators are supported, and appear in order of
9503increasing precedence:
9504
9505@table @code
9506@item ,
9507Function argument or array index separator.
9508
9509@item :=
9510Assignment. The value of @var{var} @code{:=} @var{value} is
9511@var{value}.
9512
9513@item <@r{, }>
9514Less than, greater than on integral, floating-point, or enumerated
9515types.
9516
9517@item <=@r{, }>=
96a2c332 9518Less than or equal to, greater than or equal to
c906108c
SS
9519on integral, floating-point and enumerated types, or set inclusion on
9520set types. Same precedence as @code{<}.
9521
9522@item =@r{, }<>@r{, }#
9523Equality and two ways of expressing inequality, valid on scalar types.
9524Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9525available for inequality, since @code{#} conflicts with the script
9526comment character.
9527
9528@item IN
9529Set membership. Defined on set types and the types of their members.
9530Same precedence as @code{<}.
9531
9532@item OR
9533Boolean disjunction. Defined on boolean types.
9534
9535@item AND@r{, }&
d4f3574e 9536Boolean conjunction. Defined on boolean types.
c906108c
SS
9537
9538@item @@
9539The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9540
9541@item +@r{, }-
9542Addition and subtraction on integral and floating-point types, or union
9543and difference on set types.
9544
9545@item *
9546Multiplication on integral and floating-point types, or set intersection
9547on set types.
9548
9549@item /
9550Division on floating-point types, or symmetric set difference on set
9551types. Same precedence as @code{*}.
9552
9553@item DIV@r{, }MOD
9554Integer division and remainder. Defined on integral types. Same
9555precedence as @code{*}.
9556
9557@item -
9558Negative. Defined on @code{INTEGER} and @code{REAL} data.
9559
9560@item ^
9561Pointer dereferencing. Defined on pointer types.
9562
9563@item NOT
9564Boolean negation. Defined on boolean types. Same precedence as
9565@code{^}.
9566
9567@item .
9568@code{RECORD} field selector. Defined on @code{RECORD} data. Same
9569precedence as @code{^}.
9570
9571@item []
9572Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
9573
9574@item ()
9575Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
9576as @code{^}.
9577
9578@item ::@r{, }.
9579@value{GDBN} and Modula-2 scope operators.
9580@end table
9581
9582@quotation
9583@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
9584treats the use of the operator @code{IN}, or the use of operators
9585@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
9586@code{<=}, and @code{>=} on sets as an error.
9587@end quotation
9588
cb51c4e0 9589
6d2ebf8b 9590@node Built-In Func/Proc
c906108c 9591@subsubsection Built-in functions and procedures
cb51c4e0 9592@cindex Modula-2 built-ins
c906108c
SS
9593
9594Modula-2 also makes available several built-in procedures and functions.
9595In describing these, the following metavariables are used:
9596
9597@table @var
9598
9599@item a
9600represents an @code{ARRAY} variable.
9601
9602@item c
9603represents a @code{CHAR} constant or variable.
9604
9605@item i
9606represents a variable or constant of integral type.
9607
9608@item m
9609represents an identifier that belongs to a set. Generally used in the
9610same function with the metavariable @var{s}. The type of @var{s} should
9611be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
9612
9613@item n
9614represents a variable or constant of integral or floating-point type.
9615
9616@item r
9617represents a variable or constant of floating-point type.
9618
9619@item t
9620represents a type.
9621
9622@item v
9623represents a variable.
9624
9625@item x
9626represents a variable or constant of one of many types. See the
9627explanation of the function for details.
9628@end table
9629
9630All Modula-2 built-in procedures also return a result, described below.
9631
9632@table @code
9633@item ABS(@var{n})
9634Returns the absolute value of @var{n}.
9635
9636@item CAP(@var{c})
9637If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 9638equivalent, otherwise it returns its argument.
c906108c
SS
9639
9640@item CHR(@var{i})
9641Returns the character whose ordinal value is @var{i}.
9642
9643@item DEC(@var{v})
c3f6f71d 9644Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9645
9646@item DEC(@var{v},@var{i})
9647Decrements the value in the variable @var{v} by @var{i}. Returns the
9648new value.
9649
9650@item EXCL(@var{m},@var{s})
9651Removes the element @var{m} from the set @var{s}. Returns the new
9652set.
9653
9654@item FLOAT(@var{i})
9655Returns the floating point equivalent of the integer @var{i}.
9656
9657@item HIGH(@var{a})
9658Returns the index of the last member of @var{a}.
9659
9660@item INC(@var{v})
c3f6f71d 9661Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9662
9663@item INC(@var{v},@var{i})
9664Increments the value in the variable @var{v} by @var{i}. Returns the
9665new value.
9666
9667@item INCL(@var{m},@var{s})
9668Adds the element @var{m} to the set @var{s} if it is not already
9669there. Returns the new set.
9670
9671@item MAX(@var{t})
9672Returns the maximum value of the type @var{t}.
9673
9674@item MIN(@var{t})
9675Returns the minimum value of the type @var{t}.
9676
9677@item ODD(@var{i})
9678Returns boolean TRUE if @var{i} is an odd number.
9679
9680@item ORD(@var{x})
9681Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
9682value of a character is its @sc{ascii} value (on machines supporting the
9683@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
9684integral, character and enumerated types.
9685
9686@item SIZE(@var{x})
9687Returns the size of its argument. @var{x} can be a variable or a type.
9688
9689@item TRUNC(@var{r})
9690Returns the integral part of @var{r}.
9691
9692@item VAL(@var{t},@var{i})
9693Returns the member of the type @var{t} whose ordinal value is @var{i}.
9694@end table
9695
9696@quotation
9697@emph{Warning:} Sets and their operations are not yet supported, so
9698@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
9699an error.
9700@end quotation
9701
9702@cindex Modula-2 constants
6d2ebf8b 9703@node M2 Constants
c906108c
SS
9704@subsubsection Constants
9705
9706@value{GDBN} allows you to express the constants of Modula-2 in the following
9707ways:
9708
9709@itemize @bullet
9710
9711@item
9712Integer constants are simply a sequence of digits. When used in an
9713expression, a constant is interpreted to be type-compatible with the
9714rest of the expression. Hexadecimal integers are specified by a
9715trailing @samp{H}, and octal integers by a trailing @samp{B}.
9716
9717@item
9718Floating point constants appear as a sequence of digits, followed by a
9719decimal point and another sequence of digits. An optional exponent can
9720then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
9721@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
9722digits of the floating point constant must be valid decimal (base 10)
9723digits.
9724
9725@item
9726Character constants consist of a single character enclosed by a pair of
9727like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 9728also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
9729followed by a @samp{C}.
9730
9731@item
9732String constants consist of a sequence of characters enclosed by a
9733pair of like quotes, either single (@code{'}) or double (@code{"}).
9734Escape sequences in the style of C are also allowed. @xref{C
b37052ae 9735Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
9736sequences.
9737
9738@item
9739Enumerated constants consist of an enumerated identifier.
9740
9741@item
9742Boolean constants consist of the identifiers @code{TRUE} and
9743@code{FALSE}.
9744
9745@item
9746Pointer constants consist of integral values only.
9747
9748@item
9749Set constants are not yet supported.
9750@end itemize
9751
6d2ebf8b 9752@node M2 Defaults
c906108c
SS
9753@subsubsection Modula-2 defaults
9754@cindex Modula-2 defaults
9755
9756If type and range checking are set automatically by @value{GDBN}, they
9757both default to @code{on} whenever the working language changes to
d4f3574e 9758Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
9759selected the working language.
9760
9761If you allow @value{GDBN} to set the language automatically, then entering
9762code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 9763working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
9764the language automatically}, for further details.
9765
6d2ebf8b 9766@node Deviations
c906108c
SS
9767@subsubsection Deviations from standard Modula-2
9768@cindex Modula-2, deviations from
9769
9770A few changes have been made to make Modula-2 programs easier to debug.
9771This is done primarily via loosening its type strictness:
9772
9773@itemize @bullet
9774@item
9775Unlike in standard Modula-2, pointer constants can be formed by
9776integers. This allows you to modify pointer variables during
9777debugging. (In standard Modula-2, the actual address contained in a
9778pointer variable is hidden from you; it can only be modified
9779through direct assignment to another pointer variable or expression that
9780returned a pointer.)
9781
9782@item
9783C escape sequences can be used in strings and characters to represent
9784non-printable characters. @value{GDBN} prints out strings with these
9785escape sequences embedded. Single non-printable characters are
9786printed using the @samp{CHR(@var{nnn})} format.
9787
9788@item
9789The assignment operator (@code{:=}) returns the value of its right-hand
9790argument.
9791
9792@item
9793All built-in procedures both modify @emph{and} return their argument.
9794@end itemize
9795
6d2ebf8b 9796@node M2 Checks
c906108c
SS
9797@subsubsection Modula-2 type and range checks
9798@cindex Modula-2 checks
9799
9800@quotation
9801@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9802range checking.
9803@end quotation
9804@c FIXME remove warning when type/range checks added
9805
9806@value{GDBN} considers two Modula-2 variables type equivalent if:
9807
9808@itemize @bullet
9809@item
9810They are of types that have been declared equivalent via a @code{TYPE
9811@var{t1} = @var{t2}} statement
9812
9813@item
9814They have been declared on the same line. (Note: This is true of the
9815@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9816@end itemize
9817
9818As long as type checking is enabled, any attempt to combine variables
9819whose types are not equivalent is an error.
9820
9821Range checking is done on all mathematical operations, assignment, array
9822index bounds, and all built-in functions and procedures.
9823
6d2ebf8b 9824@node M2 Scope
c906108c
SS
9825@subsubsection The scope operators @code{::} and @code{.}
9826@cindex scope
41afff9a 9827@cindex @code{.}, Modula-2 scope operator
c906108c
SS
9828@cindex colon, doubled as scope operator
9829@ifinfo
41afff9a 9830@vindex colon-colon@r{, in Modula-2}
c906108c
SS
9831@c Info cannot handle :: but TeX can.
9832@end ifinfo
9833@iftex
41afff9a 9834@vindex ::@r{, in Modula-2}
c906108c
SS
9835@end iftex
9836
9837There are a few subtle differences between the Modula-2 scope operator
9838(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9839similar syntax:
9840
474c8240 9841@smallexample
c906108c
SS
9842
9843@var{module} . @var{id}
9844@var{scope} :: @var{id}
474c8240 9845@end smallexample
c906108c
SS
9846
9847@noindent
9848where @var{scope} is the name of a module or a procedure,
9849@var{module} the name of a module, and @var{id} is any declared
9850identifier within your program, except another module.
9851
9852Using the @code{::} operator makes @value{GDBN} search the scope
9853specified by @var{scope} for the identifier @var{id}. If it is not
9854found in the specified scope, then @value{GDBN} searches all scopes
9855enclosing the one specified by @var{scope}.
9856
9857Using the @code{.} operator makes @value{GDBN} search the current scope for
9858the identifier specified by @var{id} that was imported from the
9859definition module specified by @var{module}. With this operator, it is
9860an error if the identifier @var{id} was not imported from definition
9861module @var{module}, or if @var{id} is not an identifier in
9862@var{module}.
9863
6d2ebf8b 9864@node GDB/M2
c906108c
SS
9865@subsubsection @value{GDBN} and Modula-2
9866
9867Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9868Five subcommands of @code{set print} and @code{show print} apply
b37052ae 9869specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 9870@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 9871apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
9872analogue in Modula-2.
9873
9874The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 9875with any language, is not useful with Modula-2. Its
c906108c 9876intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 9877created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 9878address can be specified by an integral constant, the construct
d4f3574e 9879@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
9880
9881@cindex @code{#} in Modula-2
9882In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9883interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 9884
e07c999f
PH
9885@node Ada
9886@subsection Ada
9887@cindex Ada
9888
9889The extensions made to @value{GDBN} for Ada only support
9890output from the @sc{gnu} Ada (GNAT) compiler.
9891Other Ada compilers are not currently supported, and
9892attempting to debug executables produced by them is most likely
9893to be difficult.
9894
9895
9896@cindex expressions in Ada
9897@menu
9898* Ada Mode Intro:: General remarks on the Ada syntax
9899 and semantics supported by Ada mode
9900 in @value{GDBN}.
9901* Omissions from Ada:: Restrictions on the Ada expression syntax.
9902* Additions to Ada:: Extensions of the Ada expression syntax.
9903* Stopping Before Main Program:: Debugging the program during elaboration.
9904* Ada Glitches:: Known peculiarities of Ada mode.
9905@end menu
9906
9907@node Ada Mode Intro
9908@subsubsection Introduction
9909@cindex Ada mode, general
9910
9911The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9912syntax, with some extensions.
9913The philosophy behind the design of this subset is
9914
9915@itemize @bullet
9916@item
9917That @value{GDBN} should provide basic literals and access to operations for
9918arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9919leaving more sophisticated computations to subprograms written into the
9920program (which therefore may be called from @value{GDBN}).
9921
9922@item
9923That type safety and strict adherence to Ada language restrictions
9924are not particularly important to the @value{GDBN} user.
9925
9926@item
9927That brevity is important to the @value{GDBN} user.
9928@end itemize
9929
9930Thus, for brevity, the debugger acts as if there were
9931implicit @code{with} and @code{use} clauses in effect for all user-written
9932packages, making it unnecessary to fully qualify most names with
9933their packages, regardless of context. Where this causes ambiguity,
9934@value{GDBN} asks the user's intent.
9935
9936The debugger will start in Ada mode if it detects an Ada main program.
9937As for other languages, it will enter Ada mode when stopped in a program that
9938was translated from an Ada source file.
9939
9940While in Ada mode, you may use `@t{--}' for comments. This is useful
9941mostly for documenting command files. The standard @value{GDBN} comment
9942(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9943middle (to allow based literals).
9944
9945The debugger supports limited overloading. Given a subprogram call in which
9946the function symbol has multiple definitions, it will use the number of
9947actual parameters and some information about their types to attempt to narrow
9948the set of definitions. It also makes very limited use of context, preferring
9949procedures to functions in the context of the @code{call} command, and
9950functions to procedures elsewhere.
9951
9952@node Omissions from Ada
9953@subsubsection Omissions from Ada
9954@cindex Ada, omissions from
9955
9956Here are the notable omissions from the subset:
9957
9958@itemize @bullet
9959@item
9960Only a subset of the attributes are supported:
9961
9962@itemize @minus
9963@item
9964@t{'First}, @t{'Last}, and @t{'Length}
9965 on array objects (not on types and subtypes).
9966
9967@item
9968@t{'Min} and @t{'Max}.
9969
9970@item
9971@t{'Pos} and @t{'Val}.
9972
9973@item
9974@t{'Tag}.
9975
9976@item
9977@t{'Range} on array objects (not subtypes), but only as the right
9978operand of the membership (@code{in}) operator.
9979
9980@item
9981@t{'Access}, @t{'Unchecked_Access}, and
9982@t{'Unrestricted_Access} (a GNAT extension).
9983
9984@item
9985@t{'Address}.
9986@end itemize
9987
9988@item
9989The names in
9990@code{Characters.Latin_1} are not available and
9991concatenation is not implemented. Thus, escape characters in strings are
9992not currently available.
9993
9994@item
9995Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9996equality of representations. They will generally work correctly
9997for strings and arrays whose elements have integer or enumeration types.
9998They may not work correctly for arrays whose element
9999types have user-defined equality, for arrays of real values
10000(in particular, IEEE-conformant floating point, because of negative
10001zeroes and NaNs), and for arrays whose elements contain unused bits with
10002indeterminate values.
10003
10004@item
10005The other component-by-component array operations (@code{and}, @code{or},
10006@code{xor}, @code{not}, and relational tests other than equality)
10007are not implemented.
10008
10009@item
860701dc
PH
10010@cindex array aggregates (Ada)
10011@cindex record aggregates (Ada)
10012@cindex aggregates (Ada)
10013There is limited support for array and record aggregates. They are
10014permitted only on the right sides of assignments, as in these examples:
10015
10016@smallexample
10017set An_Array := (1, 2, 3, 4, 5, 6)
10018set An_Array := (1, others => 0)
10019set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
10020set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
10021set A_Record := (1, "Peter", True);
10022set A_Record := (Name => "Peter", Id => 1, Alive => True)
10023@end smallexample
10024
10025Changing a
10026discriminant's value by assigning an aggregate has an
10027undefined effect if that discriminant is used within the record.
10028However, you can first modify discriminants by directly assigning to
10029them (which normally would not be allowed in Ada), and then performing an
10030aggregate assignment. For example, given a variable @code{A_Rec}
10031declared to have a type such as:
10032
10033@smallexample
10034type Rec (Len : Small_Integer := 0) is record
10035 Id : Integer;
10036 Vals : IntArray (1 .. Len);
10037end record;
10038@end smallexample
10039
10040you can assign a value with a different size of @code{Vals} with two
10041assignments:
10042
10043@smallexample
10044set A_Rec.Len := 4
10045set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
10046@end smallexample
10047
10048As this example also illustrates, @value{GDBN} is very loose about the usual
10049rules concerning aggregates. You may leave out some of the
10050components of an array or record aggregate (such as the @code{Len}
10051component in the assignment to @code{A_Rec} above); they will retain their
10052original values upon assignment. You may freely use dynamic values as
10053indices in component associations. You may even use overlapping or
10054redundant component associations, although which component values are
10055assigned in such cases is not defined.
e07c999f
PH
10056
10057@item
10058Calls to dispatching subprograms are not implemented.
10059
10060@item
10061The overloading algorithm is much more limited (i.e., less selective)
10062than that of real Ada. It makes only limited use of the context in which a subexpression
10063appears to resolve its meaning, and it is much looser in its rules for allowing
10064type matches. As a result, some function calls will be ambiguous, and the user
10065will be asked to choose the proper resolution.
10066
10067@item
10068The @code{new} operator is not implemented.
10069
10070@item
10071Entry calls are not implemented.
10072
10073@item
10074Aside from printing, arithmetic operations on the native VAX floating-point
10075formats are not supported.
10076
10077@item
10078It is not possible to slice a packed array.
10079@end itemize
10080
10081@node Additions to Ada
10082@subsubsection Additions to Ada
10083@cindex Ada, deviations from
10084
10085As it does for other languages, @value{GDBN} makes certain generic
10086extensions to Ada (@pxref{Expressions}):
10087
10088@itemize @bullet
10089@item
10090If the expression @var{E} is a variable residing in memory
10091(typically a local variable or array element) and @var{N} is
10092a positive integer, then @code{@var{E}@@@var{N}} displays the values of
10093@var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
10094In Ada, this operator is generally not necessary, since its prime use
10095is in displaying parts of an array, and slicing will usually do this in Ada.
10096However, there are occasional uses when debugging programs
10097in which certain debugging information has been optimized away.
10098
10099@item
10100@code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
10101in function or file @var{B}.'' When @var{B} is a file name, you must typically
10102surround it in single quotes.
10103
10104@item
10105The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
10106@var{type} that appears at address @var{addr}.''
10107
10108@item
10109A name starting with @samp{$} is a convenience variable
10110(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
10111@end itemize
10112
10113In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
10114to Ada:
10115
10116@itemize @bullet
10117@item
10118The assignment statement is allowed as an expression, returning
10119its right-hand operand as its value. Thus, you may enter
10120
10121@smallexample
10122set x := y + 3
10123print A(tmp := y + 1)
10124@end smallexample
10125
10126@item
10127The semicolon is allowed as an ``operator,'' returning as its value
10128the value of its right-hand operand.
10129This allows, for example,
10130complex conditional breaks:
10131
10132@smallexample
10133break f
10134condition 1 (report(i); k += 1; A(k) > 100)
10135@end smallexample
10136
10137@item
10138Rather than use catenation and symbolic character names to introduce special
10139characters into strings, one may instead use a special bracket notation,
10140which is also used to print strings. A sequence of characters of the form
10141@samp{["@var{XX}"]} within a string or character literal denotes the
10142(single) character whose numeric encoding is @var{XX} in hexadecimal. The
10143sequence of characters @samp{["""]} also denotes a single quotation mark
10144in strings. For example,
10145@smallexample
10146 "One line.["0a"]Next line.["0a"]"
10147@end smallexample
10148@noindent
10149contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
10150period.
10151
10152@item
10153The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
10154@t{'Max} is optional (and is ignored in any case). For example, it is valid
10155to write
10156
10157@smallexample
10158print 'max(x, y)
10159@end smallexample
10160
10161@item
10162When printing arrays, @value{GDBN} uses positional notation when the
10163array has a lower bound of 1, and uses a modified named notation otherwise.
10164For example, a one-dimensional array of three integers with a lower bound of 3 might print as
10165
10166@smallexample
10167(3 => 10, 17, 1)
10168@end smallexample
10169
10170@noindent
10171That is, in contrast to valid Ada, only the first component has a @code{=>}
10172clause.
10173
10174@item
10175You may abbreviate attributes in expressions with any unique,
10176multi-character subsequence of
10177their names (an exact match gets preference).
10178For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
10179in place of @t{a'length}.
10180
10181@item
10182@cindex quoting Ada internal identifiers
10183Since Ada is case-insensitive, the debugger normally maps identifiers you type
10184to lower case. The GNAT compiler uses upper-case characters for
10185some of its internal identifiers, which are normally of no interest to users.
10186For the rare occasions when you actually have to look at them,
10187enclose them in angle brackets to avoid the lower-case mapping.
10188For example,
10189@smallexample
10190@value{GDBP} print <JMPBUF_SAVE>[0]
10191@end smallexample
10192
10193@item
10194Printing an object of class-wide type or dereferencing an
10195access-to-class-wide value will display all the components of the object's
10196specific type (as indicated by its run-time tag). Likewise, component
10197selection on such a value will operate on the specific type of the
10198object.
10199
10200@end itemize
10201
10202@node Stopping Before Main Program
10203@subsubsection Stopping at the Very Beginning
10204
10205@cindex breakpointing Ada elaboration code
10206It is sometimes necessary to debug the program during elaboration, and
10207before reaching the main procedure.
10208As defined in the Ada Reference
10209Manual, the elaboration code is invoked from a procedure called
10210@code{adainit}. To run your program up to the beginning of
10211elaboration, simply use the following two commands:
10212@code{tbreak adainit} and @code{run}.
10213
10214@node Ada Glitches
10215@subsubsection Known Peculiarities of Ada Mode
10216@cindex Ada, problems
10217
10218Besides the omissions listed previously (@pxref{Omissions from Ada}),
10219we know of several problems with and limitations of Ada mode in
10220@value{GDBN},
10221some of which will be fixed with planned future releases of the debugger
10222and the GNU Ada compiler.
10223
10224@itemize @bullet
10225@item
10226Currently, the debugger
10227has insufficient information to determine whether certain pointers represent
10228pointers to objects or the objects themselves.
10229Thus, the user may have to tack an extra @code{.all} after an expression
10230to get it printed properly.
10231
10232@item
10233Static constants that the compiler chooses not to materialize as objects in
10234storage are invisible to the debugger.
10235
10236@item
10237Named parameter associations in function argument lists are ignored (the
10238argument lists are treated as positional).
10239
10240@item
10241Many useful library packages are currently invisible to the debugger.
10242
10243@item
10244Fixed-point arithmetic, conversions, input, and output is carried out using
10245floating-point arithmetic, and may give results that only approximate those on
10246the host machine.
10247
10248@item
10249The type of the @t{'Address} attribute may not be @code{System.Address}.
10250
10251@item
10252The GNAT compiler never generates the prefix @code{Standard} for any of
10253the standard symbols defined by the Ada language. @value{GDBN} knows about
10254this: it will strip the prefix from names when you use it, and will never
10255look for a name you have so qualified among local symbols, nor match against
10256symbols in other packages or subprograms. If you have
10257defined entities anywhere in your program other than parameters and
10258local variables whose simple names match names in @code{Standard},
10259GNAT's lack of qualification here can cause confusion. When this happens,
10260you can usually resolve the confusion
10261by qualifying the problematic names with package
10262@code{Standard} explicitly.
10263@end itemize
10264
4e562065
JB
10265@node Unsupported languages
10266@section Unsupported languages
10267
10268@cindex unsupported languages
10269@cindex minimal language
10270In addition to the other fully-supported programming languages,
10271@value{GDBN} also provides a pseudo-language, called @code{minimal}.
10272It does not represent a real programming language, but provides a set
10273of capabilities close to what the C or assembly languages provide.
10274This should allow most simple operations to be performed while debugging
10275an application that uses a language currently not supported by @value{GDBN}.
10276
10277If the language is set to @code{auto}, @value{GDBN} will automatically
10278select this language if the current frame corresponds to an unsupported
10279language.
10280
6d2ebf8b 10281@node Symbols
c906108c
SS
10282@chapter Examining the Symbol Table
10283
d4f3574e 10284The commands described in this chapter allow you to inquire about the
c906108c
SS
10285symbols (names of variables, functions and types) defined in your
10286program. This information is inherent in the text of your program and
10287does not change as your program executes. @value{GDBN} finds it in your
10288program's symbol table, in the file indicated when you started @value{GDBN}
10289(@pxref{File Options, ,Choosing files}), or by one of the
10290file-management commands (@pxref{Files, ,Commands to specify files}).
10291
10292@cindex symbol names
10293@cindex names of symbols
10294@cindex quoting names
10295Occasionally, you may need to refer to symbols that contain unusual
10296characters, which @value{GDBN} ordinarily treats as word delimiters. The
10297most frequent case is in referring to static variables in other
10298source files (@pxref{Variables,,Program variables}). File names
10299are recorded in object files as debugging symbols, but @value{GDBN} would
10300ordinarily parse a typical file name, like @file{foo.c}, as the three words
10301@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
10302@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
10303
474c8240 10304@smallexample
c906108c 10305p 'foo.c'::x
474c8240 10306@end smallexample
c906108c
SS
10307
10308@noindent
10309looks up the value of @code{x} in the scope of the file @file{foo.c}.
10310
10311@table @code
a8f24a35
EZ
10312@cindex case-insensitive symbol names
10313@cindex case sensitivity in symbol names
10314@kindex set case-sensitive
10315@item set case-sensitive on
10316@itemx set case-sensitive off
10317@itemx set case-sensitive auto
10318Normally, when @value{GDBN} looks up symbols, it matches their names
10319with case sensitivity determined by the current source language.
10320Occasionally, you may wish to control that. The command @code{set
10321case-sensitive} lets you do that by specifying @code{on} for
10322case-sensitive matches or @code{off} for case-insensitive ones. If
10323you specify @code{auto}, case sensitivity is reset to the default
10324suitable for the source language. The default is case-sensitive
10325matches for all languages except for Fortran, for which the default is
10326case-insensitive matches.
10327
9c16f35a
EZ
10328@kindex show case-sensitive
10329@item show case-sensitive
a8f24a35
EZ
10330This command shows the current setting of case sensitivity for symbols
10331lookups.
10332
c906108c 10333@kindex info address
b37052ae 10334@cindex address of a symbol
c906108c
SS
10335@item info address @var{symbol}
10336Describe where the data for @var{symbol} is stored. For a register
10337variable, this says which register it is kept in. For a non-register
10338local variable, this prints the stack-frame offset at which the variable
10339is always stored.
10340
10341Note the contrast with @samp{print &@var{symbol}}, which does not work
10342at all for a register variable, and for a stack local variable prints
10343the exact address of the current instantiation of the variable.
10344
3d67e040 10345@kindex info symbol
b37052ae 10346@cindex symbol from address
9c16f35a 10347@cindex closest symbol and offset for an address
3d67e040
EZ
10348@item info symbol @var{addr}
10349Print the name of a symbol which is stored at the address @var{addr}.
10350If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
10351nearest symbol and an offset from it:
10352
474c8240 10353@smallexample
3d67e040
EZ
10354(@value{GDBP}) info symbol 0x54320
10355_initialize_vx + 396 in section .text
474c8240 10356@end smallexample
3d67e040
EZ
10357
10358@noindent
10359This is the opposite of the @code{info address} command. You can use
10360it to find out the name of a variable or a function given its address.
10361
c906108c 10362@kindex whatis
d4f3574e
SS
10363@item whatis @var{expr}
10364Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
10365actually evaluated, and any side-effecting operations (such as
10366assignments or function calls) inside it do not take place.
10367@xref{Expressions, ,Expressions}.
10368
10369@item whatis
10370Print the data type of @code{$}, the last value in the value history.
10371
10372@kindex ptype
10373@item ptype @var{typename}
10374Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
10375the name of a type, or for C code it may have the form @samp{class
10376@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
10377@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 10378
d4f3574e 10379@item ptype @var{expr}
c906108c 10380@itemx ptype
d4f3574e 10381Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
10382differs from @code{whatis} by printing a detailed description, instead
10383of just the name of the type.
10384
10385For example, for this variable declaration:
10386
474c8240 10387@smallexample
c906108c 10388struct complex @{double real; double imag;@} v;
474c8240 10389@end smallexample
c906108c
SS
10390
10391@noindent
10392the two commands give this output:
10393
474c8240 10394@smallexample
c906108c
SS
10395@group
10396(@value{GDBP}) whatis v
10397type = struct complex
10398(@value{GDBP}) ptype v
10399type = struct complex @{
10400 double real;
10401 double imag;
10402@}
10403@end group
474c8240 10404@end smallexample
c906108c
SS
10405
10406@noindent
10407As with @code{whatis}, using @code{ptype} without an argument refers to
10408the type of @code{$}, the last value in the value history.
10409
ab1adacd
EZ
10410@cindex incomplete type
10411Sometimes, programs use opaque data types or incomplete specifications
10412of complex data structure. If the debug information included in the
10413program does not allow @value{GDBN} to display a full declaration of
10414the data type, it will say @samp{<incomplete type>}. For example,
10415given these declarations:
10416
10417@smallexample
10418 struct foo;
10419 struct foo *fooptr;
10420@end smallexample
10421
10422@noindent
10423but no definition for @code{struct foo} itself, @value{GDBN} will say:
10424
10425@smallexample
10426 (gdb) ptype foo
10427 $1 = <incomplete type>
10428@end smallexample
10429
10430@noindent
10431``Incomplete type'' is C terminology for data types that are not
10432completely specified.
10433
c906108c
SS
10434@kindex info types
10435@item info types @var{regexp}
10436@itemx info types
09d4efe1
EZ
10437Print a brief description of all types whose names match the regular
10438expression @var{regexp} (or all types in your program, if you supply
10439no argument). Each complete typename is matched as though it were a
10440complete line; thus, @samp{i type value} gives information on all
10441types in your program whose names include the string @code{value}, but
10442@samp{i type ^value$} gives information only on types whose complete
10443name is @code{value}.
c906108c
SS
10444
10445This command differs from @code{ptype} in two ways: first, like
10446@code{whatis}, it does not print a detailed description; second, it
10447lists all source files where a type is defined.
10448
b37052ae
EZ
10449@kindex info scope
10450@cindex local variables
09d4efe1 10451@item info scope @var{location}
b37052ae 10452List all the variables local to a particular scope. This command
09d4efe1
EZ
10453accepts a @var{location} argument---a function name, a source line, or
10454an address preceded by a @samp{*}, and prints all the variables local
10455to the scope defined by that location. For example:
b37052ae
EZ
10456
10457@smallexample
10458(@value{GDBP}) @b{info scope command_line_handler}
10459Scope for command_line_handler:
10460Symbol rl is an argument at stack/frame offset 8, length 4.
10461Symbol linebuffer is in static storage at address 0x150a18, length 4.
10462Symbol linelength is in static storage at address 0x150a1c, length 4.
10463Symbol p is a local variable in register $esi, length 4.
10464Symbol p1 is a local variable in register $ebx, length 4.
10465Symbol nline is a local variable in register $edx, length 4.
10466Symbol repeat is a local variable at frame offset -8, length 4.
10467@end smallexample
10468
f5c37c66
EZ
10469@noindent
10470This command is especially useful for determining what data to collect
10471during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
10472collect}.
10473
c906108c
SS
10474@kindex info source
10475@item info source
919d772c
JB
10476Show information about the current source file---that is, the source file for
10477the function containing the current point of execution:
10478@itemize @bullet
10479@item
10480the name of the source file, and the directory containing it,
10481@item
10482the directory it was compiled in,
10483@item
10484its length, in lines,
10485@item
10486which programming language it is written in,
10487@item
10488whether the executable includes debugging information for that file, and
10489if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
10490@item
10491whether the debugging information includes information about
10492preprocessor macros.
10493@end itemize
10494
c906108c
SS
10495
10496@kindex info sources
10497@item info sources
10498Print the names of all source files in your program for which there is
10499debugging information, organized into two lists: files whose symbols
10500have already been read, and files whose symbols will be read when needed.
10501
10502@kindex info functions
10503@item info functions
10504Print the names and data types of all defined functions.
10505
10506@item info functions @var{regexp}
10507Print the names and data types of all defined functions
10508whose names contain a match for regular expression @var{regexp}.
10509Thus, @samp{info fun step} finds all functions whose names
10510include @code{step}; @samp{info fun ^step} finds those whose names
b383017d 10511start with @code{step}. If a function name contains characters
c1468174 10512that conflict with the regular expression language (e.g.@:
1c5dfdad 10513@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
10514
10515@kindex info variables
10516@item info variables
10517Print the names and data types of all variables that are declared
6ca652b0 10518outside of functions (i.e.@: excluding local variables).
c906108c
SS
10519
10520@item info variables @var{regexp}
10521Print the names and data types of all variables (except for local
10522variables) whose names contain a match for regular expression
10523@var{regexp}.
10524
b37303ee 10525@kindex info classes
721c2651 10526@cindex Objective-C, classes and selectors
b37303ee
AF
10527@item info classes
10528@itemx info classes @var{regexp}
10529Display all Objective-C classes in your program, or
10530(with the @var{regexp} argument) all those matching a particular regular
10531expression.
10532
10533@kindex info selectors
10534@item info selectors
10535@itemx info selectors @var{regexp}
10536Display all Objective-C selectors in your program, or
10537(with the @var{regexp} argument) all those matching a particular regular
10538expression.
10539
c906108c
SS
10540@ignore
10541This was never implemented.
10542@kindex info methods
10543@item info methods
10544@itemx info methods @var{regexp}
10545The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
10546methods within C@t{++} program, or (with the @var{regexp} argument) a
10547specific set of methods found in the various C@t{++} classes. Many
10548C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
10549from the @code{ptype} command can be overwhelming and hard to use. The
10550@code{info-methods} command filters the methods, printing only those
10551which match the regular-expression @var{regexp}.
10552@end ignore
10553
c906108c
SS
10554@cindex reloading symbols
10555Some systems allow individual object files that make up your program to
7a292a7a
SS
10556be replaced without stopping and restarting your program. For example,
10557in VxWorks you can simply recompile a defective object file and keep on
10558running. If you are running on one of these systems, you can allow
10559@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
10560
10561@table @code
10562@kindex set symbol-reloading
10563@item set symbol-reloading on
10564Replace symbol definitions for the corresponding source file when an
10565object file with a particular name is seen again.
10566
10567@item set symbol-reloading off
6d2ebf8b
SS
10568Do not replace symbol definitions when encountering object files of the
10569same name more than once. This is the default state; if you are not
10570running on a system that permits automatic relinking of modules, you
10571should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
10572may discard symbols when linking large programs, that may contain
10573several modules (from different directories or libraries) with the same
10574name.
c906108c
SS
10575
10576@kindex show symbol-reloading
10577@item show symbol-reloading
10578Show the current @code{on} or @code{off} setting.
10579@end table
c906108c 10580
9c16f35a 10581@cindex opaque data types
c906108c
SS
10582@kindex set opaque-type-resolution
10583@item set opaque-type-resolution on
10584Tell @value{GDBN} to resolve opaque types. An opaque type is a type
10585declared as a pointer to a @code{struct}, @code{class}, or
10586@code{union}---for example, @code{struct MyType *}---that is used in one
10587source file although the full declaration of @code{struct MyType} is in
10588another source file. The default is on.
10589
10590A change in the setting of this subcommand will not take effect until
10591the next time symbols for a file are loaded.
10592
10593@item set opaque-type-resolution off
10594Tell @value{GDBN} not to resolve opaque types. In this case, the type
10595is printed as follows:
10596@smallexample
10597@{<no data fields>@}
10598@end smallexample
10599
10600@kindex show opaque-type-resolution
10601@item show opaque-type-resolution
10602Show whether opaque types are resolved or not.
c906108c
SS
10603
10604@kindex maint print symbols
10605@cindex symbol dump
10606@kindex maint print psymbols
10607@cindex partial symbol dump
10608@item maint print symbols @var{filename}
10609@itemx maint print psymbols @var{filename}
10610@itemx maint print msymbols @var{filename}
10611Write a dump of debugging symbol data into the file @var{filename}.
10612These commands are used to debug the @value{GDBN} symbol-reading code. Only
10613symbols with debugging data are included. If you use @samp{maint print
10614symbols}, @value{GDBN} includes all the symbols for which it has already
10615collected full details: that is, @var{filename} reflects symbols for
10616only those files whose symbols @value{GDBN} has read. You can use the
10617command @code{info sources} to find out which files these are. If you
10618use @samp{maint print psymbols} instead, the dump shows information about
10619symbols that @value{GDBN} only knows partially---that is, symbols defined in
10620files that @value{GDBN} has skimmed, but not yet read completely. Finally,
10621@samp{maint print msymbols} dumps just the minimal symbol information
10622required for each object file from which @value{GDBN} has read some symbols.
10623@xref{Files, ,Commands to specify files}, for a discussion of how
10624@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 10625
5e7b2f39
JB
10626@kindex maint info symtabs
10627@kindex maint info psymtabs
44ea7b70
JB
10628@cindex listing @value{GDBN}'s internal symbol tables
10629@cindex symbol tables, listing @value{GDBN}'s internal
10630@cindex full symbol tables, listing @value{GDBN}'s internal
10631@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
10632@item maint info symtabs @r{[} @var{regexp} @r{]}
10633@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
10634
10635List the @code{struct symtab} or @code{struct partial_symtab}
10636structures whose names match @var{regexp}. If @var{regexp} is not
10637given, list them all. The output includes expressions which you can
10638copy into a @value{GDBN} debugging this one to examine a particular
10639structure in more detail. For example:
10640
10641@smallexample
5e7b2f39 10642(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
10643@{ objfile /home/gnu/build/gdb/gdb
10644 ((struct objfile *) 0x82e69d0)
b383017d 10645 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10646 ((struct partial_symtab *) 0x8474b10)
10647 readin no
10648 fullname (null)
10649 text addresses 0x814d3c8 -- 0x8158074
10650 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
10651 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
10652 dependencies (none)
10653 @}
10654@}
5e7b2f39 10655(@value{GDBP}) maint info symtabs
44ea7b70
JB
10656(@value{GDBP})
10657@end smallexample
10658@noindent
10659We see that there is one partial symbol table whose filename contains
10660the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
10661and we see that @value{GDBN} has not read in any symtabs yet at all.
10662If we set a breakpoint on a function, that will cause @value{GDBN} to
10663read the symtab for the compilation unit containing that function:
10664
10665@smallexample
10666(@value{GDBP}) break dwarf2_psymtab_to_symtab
10667Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
10668line 1574.
5e7b2f39 10669(@value{GDBP}) maint info symtabs
b383017d 10670@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 10671 ((struct objfile *) 0x82e69d0)
b383017d 10672 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10673 ((struct symtab *) 0x86c1f38)
10674 dirname (null)
10675 fullname (null)
10676 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
10677 debugformat DWARF 2
10678 @}
10679@}
b383017d 10680(@value{GDBP})
44ea7b70 10681@end smallexample
c906108c
SS
10682@end table
10683
44ea7b70 10684
6d2ebf8b 10685@node Altering
c906108c
SS
10686@chapter Altering Execution
10687
10688Once you think you have found an error in your program, you might want to
10689find out for certain whether correcting the apparent error would lead to
10690correct results in the rest of the run. You can find the answer by
10691experiment, using the @value{GDBN} features for altering execution of the
10692program.
10693
10694For example, you can store new values into variables or memory
7a292a7a
SS
10695locations, give your program a signal, restart it at a different
10696address, or even return prematurely from a function.
c906108c
SS
10697
10698@menu
10699* Assignment:: Assignment to variables
10700* Jumping:: Continuing at a different address
c906108c 10701* Signaling:: Giving your program a signal
c906108c
SS
10702* Returning:: Returning from a function
10703* Calling:: Calling your program's functions
10704* Patching:: Patching your program
10705@end menu
10706
6d2ebf8b 10707@node Assignment
c906108c
SS
10708@section Assignment to variables
10709
10710@cindex assignment
10711@cindex setting variables
10712To alter the value of a variable, evaluate an assignment expression.
10713@xref{Expressions, ,Expressions}. For example,
10714
474c8240 10715@smallexample
c906108c 10716print x=4
474c8240 10717@end smallexample
c906108c
SS
10718
10719@noindent
10720stores the value 4 into the variable @code{x}, and then prints the
5d161b24 10721value of the assignment expression (which is 4).
c906108c
SS
10722@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
10723information on operators in supported languages.
c906108c
SS
10724
10725@kindex set variable
10726@cindex variables, setting
10727If you are not interested in seeing the value of the assignment, use the
10728@code{set} command instead of the @code{print} command. @code{set} is
10729really the same as @code{print} except that the expression's value is
10730not printed and is not put in the value history (@pxref{Value History,
10731,Value history}). The expression is evaluated only for its effects.
10732
c906108c
SS
10733If the beginning of the argument string of the @code{set} command
10734appears identical to a @code{set} subcommand, use the @code{set
10735variable} command instead of just @code{set}. This command is identical
10736to @code{set} except for its lack of subcommands. For example, if your
10737program has a variable @code{width}, you get an error if you try to set
10738a new value with just @samp{set width=13}, because @value{GDBN} has the
10739command @code{set width}:
10740
474c8240 10741@smallexample
c906108c
SS
10742(@value{GDBP}) whatis width
10743type = double
10744(@value{GDBP}) p width
10745$4 = 13
10746(@value{GDBP}) set width=47
10747Invalid syntax in expression.
474c8240 10748@end smallexample
c906108c
SS
10749
10750@noindent
10751The invalid expression, of course, is @samp{=47}. In
10752order to actually set the program's variable @code{width}, use
10753
474c8240 10754@smallexample
c906108c 10755(@value{GDBP}) set var width=47
474c8240 10756@end smallexample
53a5351d 10757
c906108c
SS
10758Because the @code{set} command has many subcommands that can conflict
10759with the names of program variables, it is a good idea to use the
10760@code{set variable} command instead of just @code{set}. For example, if
10761your program has a variable @code{g}, you run into problems if you try
10762to set a new value with just @samp{set g=4}, because @value{GDBN} has
10763the command @code{set gnutarget}, abbreviated @code{set g}:
10764
474c8240 10765@smallexample
c906108c
SS
10766@group
10767(@value{GDBP}) whatis g
10768type = double
10769(@value{GDBP}) p g
10770$1 = 1
10771(@value{GDBP}) set g=4
2df3850c 10772(@value{GDBP}) p g
c906108c
SS
10773$2 = 1
10774(@value{GDBP}) r
10775The program being debugged has been started already.
10776Start it from the beginning? (y or n) y
10777Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
10778"/home/smith/cc_progs/a.out": can't open to read symbols:
10779 Invalid bfd target.
c906108c
SS
10780(@value{GDBP}) show g
10781The current BFD target is "=4".
10782@end group
474c8240 10783@end smallexample
c906108c
SS
10784
10785@noindent
10786The program variable @code{g} did not change, and you silently set the
10787@code{gnutarget} to an invalid value. In order to set the variable
10788@code{g}, use
10789
474c8240 10790@smallexample
c906108c 10791(@value{GDBP}) set var g=4
474c8240 10792@end smallexample
c906108c
SS
10793
10794@value{GDBN} allows more implicit conversions in assignments than C; you can
10795freely store an integer value into a pointer variable or vice versa,
10796and you can convert any structure to any other structure that is the
10797same length or shorter.
10798@comment FIXME: how do structs align/pad in these conversions?
10799@comment /doc@cygnus.com 18dec1990
10800
10801To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
10802construct to generate a value of specified type at a specified address
10803(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
10804to memory location @code{0x83040} as an integer (which implies a certain size
10805and representation in memory), and
10806
474c8240 10807@smallexample
c906108c 10808set @{int@}0x83040 = 4
474c8240 10809@end smallexample
c906108c
SS
10810
10811@noindent
10812stores the value 4 into that memory location.
10813
6d2ebf8b 10814@node Jumping
c906108c
SS
10815@section Continuing at a different address
10816
10817Ordinarily, when you continue your program, you do so at the place where
10818it stopped, with the @code{continue} command. You can instead continue at
10819an address of your own choosing, with the following commands:
10820
10821@table @code
10822@kindex jump
10823@item jump @var{linespec}
10824Resume execution at line @var{linespec}. Execution stops again
10825immediately if there is a breakpoint there. @xref{List, ,Printing
10826source lines}, for a description of the different forms of
10827@var{linespec}. It is common practice to use the @code{tbreak} command
10828in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
10829breakpoints}.
10830
10831The @code{jump} command does not change the current stack frame, or
10832the stack pointer, or the contents of any memory location or any
10833register other than the program counter. If line @var{linespec} is in
10834a different function from the one currently executing, the results may
10835be bizarre if the two functions expect different patterns of arguments or
10836of local variables. For this reason, the @code{jump} command requests
10837confirmation if the specified line is not in the function currently
10838executing. However, even bizarre results are predictable if you are
10839well acquainted with the machine-language code of your program.
10840
10841@item jump *@var{address}
10842Resume execution at the instruction at address @var{address}.
10843@end table
10844
c906108c 10845@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
10846On many systems, you can get much the same effect as the @code{jump}
10847command by storing a new value into the register @code{$pc}. The
10848difference is that this does not start your program running; it only
10849changes the address of where it @emph{will} run when you continue. For
10850example,
c906108c 10851
474c8240 10852@smallexample
c906108c 10853set $pc = 0x485
474c8240 10854@end smallexample
c906108c
SS
10855
10856@noindent
10857makes the next @code{continue} command or stepping command execute at
10858address @code{0x485}, rather than at the address where your program stopped.
10859@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
10860
10861The most common occasion to use the @code{jump} command is to back
10862up---perhaps with more breakpoints set---over a portion of a program
10863that has already executed, in order to examine its execution in more
10864detail.
10865
c906108c 10866@c @group
6d2ebf8b 10867@node Signaling
c906108c 10868@section Giving your program a signal
9c16f35a 10869@cindex deliver a signal to a program
c906108c
SS
10870
10871@table @code
10872@kindex signal
10873@item signal @var{signal}
10874Resume execution where your program stopped, but immediately give it the
10875signal @var{signal}. @var{signal} can be the name or the number of a
10876signal. For example, on many systems @code{signal 2} and @code{signal
10877SIGINT} are both ways of sending an interrupt signal.
10878
10879Alternatively, if @var{signal} is zero, continue execution without
10880giving a signal. This is useful when your program stopped on account of
10881a signal and would ordinary see the signal when resumed with the
10882@code{continue} command; @samp{signal 0} causes it to resume without a
10883signal.
10884
10885@code{signal} does not repeat when you press @key{RET} a second time
10886after executing the command.
10887@end table
10888@c @end group
10889
10890Invoking the @code{signal} command is not the same as invoking the
10891@code{kill} utility from the shell. Sending a signal with @code{kill}
10892causes @value{GDBN} to decide what to do with the signal depending on
10893the signal handling tables (@pxref{Signals}). The @code{signal} command
10894passes the signal directly to your program.
10895
c906108c 10896
6d2ebf8b 10897@node Returning
c906108c
SS
10898@section Returning from a function
10899
10900@table @code
10901@cindex returning from a function
10902@kindex return
10903@item return
10904@itemx return @var{expression}
10905You can cancel execution of a function call with the @code{return}
10906command. If you give an
10907@var{expression} argument, its value is used as the function's return
10908value.
10909@end table
10910
10911When you use @code{return}, @value{GDBN} discards the selected stack frame
10912(and all frames within it). You can think of this as making the
10913discarded frame return prematurely. If you wish to specify a value to
10914be returned, give that value as the argument to @code{return}.
10915
10916This pops the selected stack frame (@pxref{Selection, ,Selecting a
10917frame}), and any other frames inside of it, leaving its caller as the
10918innermost remaining frame. That frame becomes selected. The
10919specified value is stored in the registers used for returning values
10920of functions.
10921
10922The @code{return} command does not resume execution; it leaves the
10923program stopped in the state that would exist if the function had just
10924returned. In contrast, the @code{finish} command (@pxref{Continuing
10925and Stepping, ,Continuing and stepping}) resumes execution until the
10926selected stack frame returns naturally.
10927
6d2ebf8b 10928@node Calling
c906108c
SS
10929@section Calling program functions
10930
f8568604 10931@table @code
c906108c 10932@cindex calling functions
f8568604
EZ
10933@cindex inferior functions, calling
10934@item print @var{expr}
9c16f35a 10935Evaluate the expression @var{expr} and display the resuling value.
f8568604
EZ
10936@var{expr} may include calls to functions in the program being
10937debugged.
10938
c906108c 10939@kindex call
c906108c
SS
10940@item call @var{expr}
10941Evaluate the expression @var{expr} without displaying @code{void}
10942returned values.
c906108c
SS
10943
10944You can use this variant of the @code{print} command if you want to
f8568604
EZ
10945execute a function from your program that does not return anything
10946(a.k.a.@: @dfn{a void function}), but without cluttering the output
10947with @code{void} returned values that @value{GDBN} will otherwise
10948print. If the result is not void, it is printed and saved in the
10949value history.
10950@end table
10951
9c16f35a
EZ
10952It is possible for the function you call via the @code{print} or
10953@code{call} command to generate a signal (e.g., if there's a bug in
10954the function, or if you passed it incorrect arguments). What happens
10955in that case is controlled by the @code{set unwindonsignal} command.
10956
10957@table @code
10958@item set unwindonsignal
10959@kindex set unwindonsignal
10960@cindex unwind stack in called functions
10961@cindex call dummy stack unwinding
10962Set unwinding of the stack if a signal is received while in a function
10963that @value{GDBN} called in the program being debugged. If set to on,
10964@value{GDBN} unwinds the stack it created for the call and restores
10965the context to what it was before the call. If set to off (the
10966default), @value{GDBN} stops in the frame where the signal was
10967received.
10968
10969@item show unwindonsignal
10970@kindex show unwindonsignal
10971Show the current setting of stack unwinding in the functions called by
10972@value{GDBN}.
10973@end table
10974
f8568604
EZ
10975@cindex weak alias functions
10976Sometimes, a function you wish to call is actually a @dfn{weak alias}
10977for another function. In such case, @value{GDBN} might not pick up
10978the type information, including the types of the function arguments,
10979which causes @value{GDBN} to call the inferior function incorrectly.
10980As a result, the called function will function erroneously and may
10981even crash. A solution to that is to use the name of the aliased
10982function instead.
c906108c 10983
6d2ebf8b 10984@node Patching
c906108c 10985@section Patching programs
7a292a7a 10986
c906108c
SS
10987@cindex patching binaries
10988@cindex writing into executables
c906108c 10989@cindex writing into corefiles
c906108c 10990
7a292a7a
SS
10991By default, @value{GDBN} opens the file containing your program's
10992executable code (or the corefile) read-only. This prevents accidental
10993alterations to machine code; but it also prevents you from intentionally
10994patching your program's binary.
c906108c
SS
10995
10996If you'd like to be able to patch the binary, you can specify that
10997explicitly with the @code{set write} command. For example, you might
10998want to turn on internal debugging flags, or even to make emergency
10999repairs.
11000
11001@table @code
11002@kindex set write
11003@item set write on
11004@itemx set write off
7a292a7a
SS
11005If you specify @samp{set write on}, @value{GDBN} opens executable and
11006core files for both reading and writing; if you specify @samp{set write
c906108c
SS
11007off} (the default), @value{GDBN} opens them read-only.
11008
11009If you have already loaded a file, you must load it again (using the
7a292a7a
SS
11010@code{exec-file} or @code{core-file} command) after changing @code{set
11011write}, for your new setting to take effect.
c906108c
SS
11012
11013@item show write
11014@kindex show write
7a292a7a
SS
11015Display whether executable files and core files are opened for writing
11016as well as reading.
c906108c
SS
11017@end table
11018
6d2ebf8b 11019@node GDB Files
c906108c
SS
11020@chapter @value{GDBN} Files
11021
7a292a7a
SS
11022@value{GDBN} needs to know the file name of the program to be debugged,
11023both in order to read its symbol table and in order to start your
11024program. To debug a core dump of a previous run, you must also tell
11025@value{GDBN} the name of the core dump file.
c906108c
SS
11026
11027@menu
11028* Files:: Commands to specify files
5b5d99cf 11029* Separate Debug Files:: Debugging information in separate files
c906108c
SS
11030* Symbol Errors:: Errors reading symbol files
11031@end menu
11032
6d2ebf8b 11033@node Files
c906108c 11034@section Commands to specify files
c906108c 11035
7a292a7a 11036@cindex symbol table
c906108c 11037@cindex core dump file
7a292a7a
SS
11038
11039You may want to specify executable and core dump file names. The usual
11040way to do this is at start-up time, using the arguments to
11041@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
11042Out of @value{GDBN}}).
c906108c
SS
11043
11044Occasionally it is necessary to change to a different file during a
397ca115
EZ
11045@value{GDBN} session. Or you may run @value{GDBN} and forget to
11046specify a file you want to use. Or you are debugging a remote target
11047via @code{gdbserver} (@pxref{Server, file}). In these situations the
11048@value{GDBN} commands to specify new files are useful.
c906108c
SS
11049
11050@table @code
11051@cindex executable file
11052@kindex file
11053@item file @var{filename}
11054Use @var{filename} as the program to be debugged. It is read for its
11055symbols and for the contents of pure memory. It is also the program
11056executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
11057directory and the file is not found in the @value{GDBN} working directory,
11058@value{GDBN} uses the environment variable @code{PATH} as a list of
11059directories to search, just as the shell does when looking for a program
11060to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
11061and your program, using the @code{path} command.
11062
fc8be69e
EZ
11063@cindex unlinked object files
11064@cindex patching object files
11065You can load unlinked object @file{.o} files into @value{GDBN} using
11066the @code{file} command. You will not be able to ``run'' an object
11067file, but you can disassemble functions and inspect variables. Also,
11068if the underlying BFD functionality supports it, you could use
11069@kbd{gdb -write} to patch object files using this technique. Note
11070that @value{GDBN} can neither interpret nor modify relocations in this
11071case, so branches and some initialized variables will appear to go to
11072the wrong place. But this feature is still handy from time to time.
11073
c906108c
SS
11074@item file
11075@code{file} with no argument makes @value{GDBN} discard any information it
11076has on both executable file and the symbol table.
11077
11078@kindex exec-file
11079@item exec-file @r{[} @var{filename} @r{]}
11080Specify that the program to be run (but not the symbol table) is found
11081in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
11082if necessary to locate your program. Omitting @var{filename} means to
11083discard information on the executable file.
11084
11085@kindex symbol-file
11086@item symbol-file @r{[} @var{filename} @r{]}
11087Read symbol table information from file @var{filename}. @code{PATH} is
11088searched when necessary. Use the @code{file} command to get both symbol
11089table and program to run from the same file.
11090
11091@code{symbol-file} with no argument clears out @value{GDBN} information on your
11092program's symbol table.
11093
5d161b24 11094The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
11095of its convenience variables, the value history, and all breakpoints and
11096auto-display expressions. This is because they may contain pointers to
11097the internal data recording symbols and data types, which are part of
11098the old symbol table data being discarded inside @value{GDBN}.
11099
11100@code{symbol-file} does not repeat if you press @key{RET} again after
11101executing it once.
11102
11103When @value{GDBN} is configured for a particular environment, it
11104understands debugging information in whatever format is the standard
11105generated for that environment; you may use either a @sc{gnu} compiler, or
11106other compilers that adhere to the local conventions.
c906108c
SS
11107Best results are usually obtained from @sc{gnu} compilers; for example,
11108using @code{@value{GCC}} you can generate debugging information for
11109optimized code.
c906108c
SS
11110
11111For most kinds of object files, with the exception of old SVR3 systems
11112using COFF, the @code{symbol-file} command does not normally read the
11113symbol table in full right away. Instead, it scans the symbol table
11114quickly to find which source files and which symbols are present. The
11115details are read later, one source file at a time, as they are needed.
11116
11117The purpose of this two-stage reading strategy is to make @value{GDBN}
11118start up faster. For the most part, it is invisible except for
11119occasional pauses while the symbol table details for a particular source
11120file are being read. (The @code{set verbose} command can turn these
11121pauses into messages if desired. @xref{Messages/Warnings, ,Optional
11122warnings and messages}.)
11123
c906108c
SS
11124We have not implemented the two-stage strategy for COFF yet. When the
11125symbol table is stored in COFF format, @code{symbol-file} reads the
11126symbol table data in full right away. Note that ``stabs-in-COFF''
11127still does the two-stage strategy, since the debug info is actually
11128in stabs format.
11129
11130@kindex readnow
11131@cindex reading symbols immediately
11132@cindex symbols, reading immediately
a94ab193
EZ
11133@item symbol-file @var{filename} @r{[} -readnow @r{]}
11134@itemx file @var{filename} @r{[} -readnow @r{]}
c906108c
SS
11135You can override the @value{GDBN} two-stage strategy for reading symbol
11136tables by using the @samp{-readnow} option with any of the commands that
11137load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 11138entire symbol table available.
c906108c 11139
c906108c
SS
11140@c FIXME: for now no mention of directories, since this seems to be in
11141@c flux. 13mar1992 status is that in theory GDB would look either in
11142@c current dir or in same dir as myprog; but issues like competing
11143@c GDB's, or clutter in system dirs, mean that in practice right now
11144@c only current dir is used. FFish says maybe a special GDB hierarchy
11145@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
11146@c files.
11147
c906108c 11148@kindex core-file
09d4efe1 11149@item core-file @r{[}@var{filename}@r{]}
4644b6e3 11150@itemx core
c906108c
SS
11151Specify the whereabouts of a core dump file to be used as the ``contents
11152of memory''. Traditionally, core files contain only some parts of the
11153address space of the process that generated them; @value{GDBN} can access the
11154executable file itself for other parts.
11155
11156@code{core-file} with no argument specifies that no core file is
11157to be used.
11158
11159Note that the core file is ignored when your program is actually running
7a292a7a
SS
11160under @value{GDBN}. So, if you have been running your program and you
11161wish to debug a core file instead, you must kill the subprocess in which
11162the program is running. To do this, use the @code{kill} command
c906108c 11163(@pxref{Kill Process, ,Killing the child process}).
c906108c 11164
c906108c
SS
11165@kindex add-symbol-file
11166@cindex dynamic linking
11167@item add-symbol-file @var{filename} @var{address}
a94ab193 11168@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
17d9d558 11169@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
11170The @code{add-symbol-file} command reads additional symbol table
11171information from the file @var{filename}. You would use this command
11172when @var{filename} has been dynamically loaded (by some other means)
11173into the program that is running. @var{address} should be the memory
11174address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
11175this out for itself. You can additionally specify an arbitrary number
11176of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
11177section name and base address for that section. You can specify any
11178@var{address} as an expression.
c906108c
SS
11179
11180The symbol table of the file @var{filename} is added to the symbol table
11181originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
11182@code{add-symbol-file} command any number of times; the new symbol data
11183thus read keeps adding to the old. To discard all old symbol data
11184instead, use the @code{symbol-file} command without any arguments.
c906108c 11185
17d9d558
JB
11186@cindex relocatable object files, reading symbols from
11187@cindex object files, relocatable, reading symbols from
11188@cindex reading symbols from relocatable object files
11189@cindex symbols, reading from relocatable object files
11190@cindex @file{.o} files, reading symbols from
11191Although @var{filename} is typically a shared library file, an
11192executable file, or some other object file which has been fully
11193relocated for loading into a process, you can also load symbolic
11194information from relocatable @file{.o} files, as long as:
11195
11196@itemize @bullet
11197@item
11198the file's symbolic information refers only to linker symbols defined in
11199that file, not to symbols defined by other object files,
11200@item
11201every section the file's symbolic information refers to has actually
11202been loaded into the inferior, as it appears in the file, and
11203@item
11204you can determine the address at which every section was loaded, and
11205provide these to the @code{add-symbol-file} command.
11206@end itemize
11207
11208@noindent
11209Some embedded operating systems, like Sun Chorus and VxWorks, can load
11210relocatable files into an already running program; such systems
11211typically make the requirements above easy to meet. However, it's
11212important to recognize that many native systems use complex link
49efadf5 11213procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
11214assembly, for example) that make the requirements difficult to meet. In
11215general, one cannot assume that using @code{add-symbol-file} to read a
11216relocatable object file's symbolic information will have the same effect
11217as linking the relocatable object file into the program in the normal
11218way.
11219
c906108c
SS
11220@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
11221
c45da7e6
EZ
11222@kindex add-symbol-file-from-memory
11223@cindex @code{syscall DSO}
11224@cindex load symbols from memory
11225@item add-symbol-file-from-memory @var{address}
11226Load symbols from the given @var{address} in a dynamically loaded
11227object file whose image is mapped directly into the inferior's memory.
11228For example, the Linux kernel maps a @code{syscall DSO} into each
11229process's address space; this DSO provides kernel-specific code for
11230some system calls. The argument can be any expression whose
11231evaluation yields the address of the file's shared object file header.
11232For this command to work, you must have used @code{symbol-file} or
11233@code{exec-file} commands in advance.
11234
09d4efe1
EZ
11235@kindex add-shared-symbol-files
11236@kindex assf
11237@item add-shared-symbol-files @var{library-file}
11238@itemx assf @var{library-file}
11239The @code{add-shared-symbol-files} command can currently be used only
11240in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
11241alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
11242@value{GDBN} automatically looks for shared libraries, however if
11243@value{GDBN} does not find yours, you can invoke
11244@code{add-shared-symbol-files}. It takes one argument: the shared
11245library's file name. @code{assf} is a shorthand alias for
11246@code{add-shared-symbol-files}.
c906108c 11247
c906108c 11248@kindex section
09d4efe1
EZ
11249@item section @var{section} @var{addr}
11250The @code{section} command changes the base address of the named
11251@var{section} of the exec file to @var{addr}. This can be used if the
11252exec file does not contain section addresses, (such as in the
11253@code{a.out} format), or when the addresses specified in the file
11254itself are wrong. Each section must be changed separately. The
11255@code{info files} command, described below, lists all the sections and
11256their addresses.
c906108c
SS
11257
11258@kindex info files
11259@kindex info target
11260@item info files
11261@itemx info target
7a292a7a
SS
11262@code{info files} and @code{info target} are synonymous; both print the
11263current target (@pxref{Targets, ,Specifying a Debugging Target}),
11264including the names of the executable and core dump files currently in
11265use by @value{GDBN}, and the files from which symbols were loaded. The
11266command @code{help target} lists all possible targets rather than
11267current ones.
11268
fe95c787
MS
11269@kindex maint info sections
11270@item maint info sections
11271Another command that can give you extra information about program sections
11272is @code{maint info sections}. In addition to the section information
11273displayed by @code{info files}, this command displays the flags and file
11274offset of each section in the executable and core dump files. In addition,
11275@code{maint info sections} provides the following command options (which
11276may be arbitrarily combined):
11277
11278@table @code
11279@item ALLOBJ
11280Display sections for all loaded object files, including shared libraries.
11281@item @var{sections}
6600abed 11282Display info only for named @var{sections}.
fe95c787
MS
11283@item @var{section-flags}
11284Display info only for sections for which @var{section-flags} are true.
11285The section flags that @value{GDBN} currently knows about are:
11286@table @code
11287@item ALLOC
11288Section will have space allocated in the process when loaded.
11289Set for all sections except those containing debug information.
11290@item LOAD
11291Section will be loaded from the file into the child process memory.
11292Set for pre-initialized code and data, clear for @code{.bss} sections.
11293@item RELOC
11294Section needs to be relocated before loading.
11295@item READONLY
11296Section cannot be modified by the child process.
11297@item CODE
11298Section contains executable code only.
6600abed 11299@item DATA
fe95c787
MS
11300Section contains data only (no executable code).
11301@item ROM
11302Section will reside in ROM.
11303@item CONSTRUCTOR
11304Section contains data for constructor/destructor lists.
11305@item HAS_CONTENTS
11306Section is not empty.
11307@item NEVER_LOAD
11308An instruction to the linker to not output the section.
11309@item COFF_SHARED_LIBRARY
11310A notification to the linker that the section contains
11311COFF shared library information.
11312@item IS_COMMON
11313Section contains common symbols.
11314@end table
11315@end table
6763aef9 11316@kindex set trust-readonly-sections
9c16f35a 11317@cindex read-only sections
6763aef9
MS
11318@item set trust-readonly-sections on
11319Tell @value{GDBN} that readonly sections in your object file
6ca652b0 11320really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
11321In that case, @value{GDBN} can fetch values from these sections
11322out of the object file, rather than from the target program.
11323For some targets (notably embedded ones), this can be a significant
11324enhancement to debugging performance.
11325
11326The default is off.
11327
11328@item set trust-readonly-sections off
15110bc3 11329Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
11330the contents of the section might change while the program is running,
11331and must therefore be fetched from the target when needed.
9c16f35a
EZ
11332
11333@item show trust-readonly-sections
11334Show the current setting of trusting readonly sections.
c906108c
SS
11335@end table
11336
11337All file-specifying commands allow both absolute and relative file names
11338as arguments. @value{GDBN} always converts the file name to an absolute file
11339name and remembers it that way.
11340
c906108c 11341@cindex shared libraries
9c16f35a
EZ
11342@value{GDBN} supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
11343and IBM RS/6000 AIX shared libraries.
53a5351d 11344
c906108c
SS
11345@value{GDBN} automatically loads symbol definitions from shared libraries
11346when you use the @code{run} command, or when you examine a core file.
11347(Before you issue the @code{run} command, @value{GDBN} does not understand
11348references to a function in a shared library, however---unless you are
11349debugging a core file).
53a5351d
JM
11350
11351On HP-UX, if the program loads a library explicitly, @value{GDBN}
11352automatically loads the symbols at the time of the @code{shl_load} call.
11353
c906108c
SS
11354@c FIXME: some @value{GDBN} release may permit some refs to undef
11355@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
11356@c FIXME...lib; check this from time to time when updating manual
11357
b7209cb4
FF
11358There are times, however, when you may wish to not automatically load
11359symbol definitions from shared libraries, such as when they are
11360particularly large or there are many of them.
11361
11362To control the automatic loading of shared library symbols, use the
11363commands:
11364
11365@table @code
11366@kindex set auto-solib-add
11367@item set auto-solib-add @var{mode}
11368If @var{mode} is @code{on}, symbols from all shared object libraries
11369will be loaded automatically when the inferior begins execution, you
11370attach to an independently started inferior, or when the dynamic linker
11371informs @value{GDBN} that a new library has been loaded. If @var{mode}
11372is @code{off}, symbols must be loaded manually, using the
11373@code{sharedlibrary} command. The default value is @code{on}.
11374
dcaf7c2c
EZ
11375@cindex memory used for symbol tables
11376If your program uses lots of shared libraries with debug info that
11377takes large amounts of memory, you can decrease the @value{GDBN}
11378memory footprint by preventing it from automatically loading the
11379symbols from shared libraries. To that end, type @kbd{set
11380auto-solib-add off} before running the inferior, then load each
11381library whose debug symbols you do need with @kbd{sharedlibrary
11382@var{regexp}}, where @var{regexp} is a regular expresion that matches
11383the libraries whose symbols you want to be loaded.
11384
b7209cb4
FF
11385@kindex show auto-solib-add
11386@item show auto-solib-add
11387Display the current autoloading mode.
11388@end table
11389
c45da7e6 11390@cindex load shared library
b7209cb4
FF
11391To explicitly load shared library symbols, use the @code{sharedlibrary}
11392command:
11393
c906108c
SS
11394@table @code
11395@kindex info sharedlibrary
11396@kindex info share
11397@item info share
11398@itemx info sharedlibrary
11399Print the names of the shared libraries which are currently loaded.
11400
11401@kindex sharedlibrary
11402@kindex share
11403@item sharedlibrary @var{regex}
11404@itemx share @var{regex}
c906108c
SS
11405Load shared object library symbols for files matching a
11406Unix regular expression.
11407As with files loaded automatically, it only loads shared libraries
11408required by your program for a core file or after typing @code{run}. If
11409@var{regex} is omitted all shared libraries required by your program are
11410loaded.
c45da7e6
EZ
11411
11412@item nosharedlibrary
11413@kindex nosharedlibrary
11414@cindex unload symbols from shared libraries
11415Unload all shared object library symbols. This discards all symbols
11416that have been loaded from all shared libraries. Symbols from shared
11417libraries that were loaded by explicit user requests are not
11418discarded.
c906108c
SS
11419@end table
11420
721c2651
EZ
11421Sometimes you may wish that @value{GDBN} stops and gives you control
11422when any of shared library events happen. Use the @code{set
11423stop-on-solib-events} command for this:
11424
11425@table @code
11426@item set stop-on-solib-events
11427@kindex set stop-on-solib-events
11428This command controls whether @value{GDBN} should give you control
11429when the dynamic linker notifies it about some shared library event.
11430The most common event of interest is loading or unloading of a new
11431shared library.
11432
11433@item show stop-on-solib-events
11434@kindex show stop-on-solib-events
11435Show whether @value{GDBN} stops and gives you control when shared
11436library events happen.
11437@end table
11438
f5ebfba0
DJ
11439Shared libraries are also supported in many cross or remote debugging
11440configurations. A copy of the target's libraries need to be present on the
11441host system; they need to be the same as the target libraries, although the
11442copies on the target can be stripped as long as the copies on the host are
11443not.
11444
59b7b46f
EZ
11445@cindex where to look for shared libraries
11446For remote debugging, you need to tell @value{GDBN} where the target
11447libraries are, so that it can load the correct copies---otherwise, it
11448may try to load the host's libraries. @value{GDBN} has two variables
11449to specify the search directories for target libraries.
f5ebfba0
DJ
11450
11451@table @code
59b7b46f 11452@cindex prefix for shared library file names
f5ebfba0
DJ
11453@kindex set solib-absolute-prefix
11454@item set solib-absolute-prefix @var{path}
11455If this variable is set, @var{path} will be used as a prefix for any
11456absolute shared library paths; many runtime loaders store the absolute
11457paths to the shared library in the target program's memory. If you use
11458@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
11459out in the same way that they are on the target, with e.g.@: a
11460@file{/usr/lib} hierarchy under @var{path}.
11461
59b7b46f
EZ
11462@cindex default value of @samp{solib-absolute-prefix}
11463@cindex @samp{--with-sysroot}
f5ebfba0
DJ
11464You can set the default value of @samp{solib-absolute-prefix} by using the
11465configure-time @samp{--with-sysroot} option.
11466
11467@kindex show solib-absolute-prefix
11468@item show solib-absolute-prefix
11469Display the current shared library prefix.
11470
11471@kindex set solib-search-path
11472@item set solib-search-path @var{path}
11473If this variable is set, @var{path} is a colon-separated list of directories
11474to search for shared libraries. @samp{solib-search-path} is used after
11475@samp{solib-absolute-prefix} fails to locate the library, or if the path to
11476the library is relative instead of absolute. If you want to use
11477@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
11478set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
11479@value{GDBN} from finding your host's libraries.
11480
11481@kindex show solib-search-path
11482@item show solib-search-path
11483Display the current shared library search path.
11484@end table
11485
5b5d99cf
JB
11486
11487@node Separate Debug Files
11488@section Debugging Information in Separate Files
11489@cindex separate debugging information files
11490@cindex debugging information in separate files
11491@cindex @file{.debug} subdirectories
11492@cindex debugging information directory, global
11493@cindex global debugging information directory
11494
11495@value{GDBN} allows you to put a program's debugging information in a
11496file separate from the executable itself, in a way that allows
11497@value{GDBN} to find and load the debugging information automatically.
11498Since debugging information can be very large --- sometimes larger
11499than the executable code itself --- some systems distribute debugging
11500information for their executables in separate files, which users can
11501install only when they need to debug a problem.
11502
11503If an executable's debugging information has been extracted to a
11504separate file, the executable should contain a @dfn{debug link} giving
11505the name of the debugging information file (with no directory
11506components), and a checksum of its contents. (The exact form of a
11507debug link is described below.) If the full name of the directory
11508containing the executable is @var{execdir}, and the executable has a
11509debug link that specifies the name @var{debugfile}, then @value{GDBN}
11510will automatically search for the debugging information file in three
11511places:
11512
11513@itemize @bullet
11514@item
11515the directory containing the executable file (that is, it will look
11516for a file named @file{@var{execdir}/@var{debugfile}},
11517@item
11518a subdirectory of that directory named @file{.debug} (that is, the
11519file @file{@var{execdir}/.debug/@var{debugfile}}, and
11520@item
11521a subdirectory of the global debug file directory that includes the
11522executable's full path, and the name from the link (that is, the file
11523@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
11524@var{globaldebugdir} is the global debug file directory, and
11525@var{execdir} has been turned into a relative path).
11526@end itemize
11527@noindent
11528@value{GDBN} checks under each of these names for a debugging
11529information file whose checksum matches that given in the link, and
11530reads the debugging information from the first one it finds.
11531
11532So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
11533which has a link containing the name @file{ls.debug}, and the global
11534debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
11535for debug information in @file{/usr/bin/ls.debug},
11536@file{/usr/bin/.debug/ls.debug}, and
11537@file{/usr/lib/debug/usr/bin/ls.debug}.
11538
11539You can set the global debugging info directory's name, and view the
11540name @value{GDBN} is currently using.
11541
11542@table @code
11543
11544@kindex set debug-file-directory
11545@item set debug-file-directory @var{directory}
11546Set the directory which @value{GDBN} searches for separate debugging
11547information files to @var{directory}.
11548
11549@kindex show debug-file-directory
11550@item show debug-file-directory
11551Show the directory @value{GDBN} searches for separate debugging
11552information files.
11553
11554@end table
11555
11556@cindex @code{.gnu_debuglink} sections
11557@cindex debug links
11558A debug link is a special section of the executable file named
11559@code{.gnu_debuglink}. The section must contain:
11560
11561@itemize
11562@item
11563A filename, with any leading directory components removed, followed by
11564a zero byte,
11565@item
11566zero to three bytes of padding, as needed to reach the next four-byte
11567boundary within the section, and
11568@item
11569a four-byte CRC checksum, stored in the same endianness used for the
11570executable file itself. The checksum is computed on the debugging
11571information file's full contents by the function given below, passing
11572zero as the @var{crc} argument.
11573@end itemize
11574
11575Any executable file format can carry a debug link, as long as it can
11576contain a section named @code{.gnu_debuglink} with the contents
11577described above.
11578
11579The debugging information file itself should be an ordinary
11580executable, containing a full set of linker symbols, sections, and
11581debugging information. The sections of the debugging information file
11582should have the same names, addresses and sizes as the original file,
11583but they need not contain any data --- much like a @code{.bss} section
11584in an ordinary executable.
11585
11586As of December 2002, there is no standard GNU utility to produce
11587separated executable / debugging information file pairs. Ulrich
11588Drepper's @file{elfutils} package, starting with version 0.53,
11589contains a version of the @code{strip} command such that the command
11590@kbd{strip foo -f foo.debug} removes the debugging information from
11591the executable file @file{foo}, places it in the file
11592@file{foo.debug}, and leaves behind a debug link in @file{foo}.
11593
11594Since there are many different ways to compute CRC's (different
11595polynomials, reversals, byte ordering, etc.), the simplest way to
11596describe the CRC used in @code{.gnu_debuglink} sections is to give the
11597complete code for a function that computes it:
11598
4644b6e3 11599@kindex gnu_debuglink_crc32
5b5d99cf
JB
11600@smallexample
11601unsigned long
11602gnu_debuglink_crc32 (unsigned long crc,
11603 unsigned char *buf, size_t len)
11604@{
11605 static const unsigned long crc32_table[256] =
11606 @{
11607 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11608 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11609 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11610 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11611 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11612 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11613 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11614 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11615 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11616 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11617 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11618 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11619 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11620 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11621 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11622 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11623 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11624 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11625 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11626 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11627 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11628 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11629 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11630 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11631 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11632 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11633 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11634 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11635 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11636 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11637 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11638 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11639 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11640 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11641 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11642 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11643 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11644 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11645 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11646 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11647 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11648 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11649 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11650 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11651 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11652 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11653 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11654 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11655 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11656 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11657 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11658 0x2d02ef8d
11659 @};
11660 unsigned char *end;
11661
11662 crc = ~crc & 0xffffffff;
11663 for (end = buf + len; buf < end; ++buf)
11664 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 11665 return ~crc & 0xffffffff;
5b5d99cf
JB
11666@}
11667@end smallexample
11668
11669
6d2ebf8b 11670@node Symbol Errors
c906108c
SS
11671@section Errors reading symbol files
11672
11673While reading a symbol file, @value{GDBN} occasionally encounters problems,
11674such as symbol types it does not recognize, or known bugs in compiler
11675output. By default, @value{GDBN} does not notify you of such problems, since
11676they are relatively common and primarily of interest to people
11677debugging compilers. If you are interested in seeing information
11678about ill-constructed symbol tables, you can either ask @value{GDBN} to print
11679only one message about each such type of problem, no matter how many
11680times the problem occurs; or you can ask @value{GDBN} to print more messages,
11681to see how many times the problems occur, with the @code{set
11682complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
11683messages}).
11684
11685The messages currently printed, and their meanings, include:
11686
11687@table @code
11688@item inner block not inside outer block in @var{symbol}
11689
11690The symbol information shows where symbol scopes begin and end
11691(such as at the start of a function or a block of statements). This
11692error indicates that an inner scope block is not fully contained
11693in its outer scope blocks.
11694
11695@value{GDBN} circumvents the problem by treating the inner block as if it had
11696the same scope as the outer block. In the error message, @var{symbol}
11697may be shown as ``@code{(don't know)}'' if the outer block is not a
11698function.
11699
11700@item block at @var{address} out of order
11701
11702The symbol information for symbol scope blocks should occur in
11703order of increasing addresses. This error indicates that it does not
11704do so.
11705
11706@value{GDBN} does not circumvent this problem, and has trouble
11707locating symbols in the source file whose symbols it is reading. (You
11708can often determine what source file is affected by specifying
11709@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
11710messages}.)
11711
11712@item bad block start address patched
11713
11714The symbol information for a symbol scope block has a start address
11715smaller than the address of the preceding source line. This is known
11716to occur in the SunOS 4.1.1 (and earlier) C compiler.
11717
11718@value{GDBN} circumvents the problem by treating the symbol scope block as
11719starting on the previous source line.
11720
11721@item bad string table offset in symbol @var{n}
11722
11723@cindex foo
11724Symbol number @var{n} contains a pointer into the string table which is
11725larger than the size of the string table.
11726
11727@value{GDBN} circumvents the problem by considering the symbol to have the
11728name @code{foo}, which may cause other problems if many symbols end up
11729with this name.
11730
11731@item unknown symbol type @code{0x@var{nn}}
11732
7a292a7a
SS
11733The symbol information contains new data types that @value{GDBN} does
11734not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 11735uncomprehended information, in hexadecimal.
c906108c 11736
7a292a7a
SS
11737@value{GDBN} circumvents the error by ignoring this symbol information.
11738This usually allows you to debug your program, though certain symbols
c906108c 11739are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
11740debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
11741on @code{complain}, then go up to the function @code{read_dbx_symtab}
11742and examine @code{*bufp} to see the symbol.
c906108c
SS
11743
11744@item stub type has NULL name
c906108c 11745
7a292a7a 11746@value{GDBN} could not find the full definition for a struct or class.
c906108c 11747
7a292a7a 11748@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 11749The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
11750information that recent versions of the compiler should have output for
11751it.
c906108c
SS
11752
11753@item info mismatch between compiler and debugger
11754
11755@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 11756
c906108c
SS
11757@end table
11758
6d2ebf8b 11759@node Targets
c906108c 11760@chapter Specifying a Debugging Target
7a292a7a 11761
c906108c 11762@cindex debugging target
c906108c 11763A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
11764
11765Often, @value{GDBN} runs in the same host environment as your program;
11766in that case, the debugging target is specified as a side effect when
11767you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
11768flexibility---for example, running @value{GDBN} on a physically separate
11769host, or controlling a standalone system over a serial port or a
53a5351d
JM
11770realtime system over a TCP/IP connection---you can use the @code{target}
11771command to specify one of the target types configured for @value{GDBN}
11772(@pxref{Target Commands, ,Commands for managing targets}).
c906108c 11773
a8f24a35
EZ
11774@cindex target architecture
11775It is possible to build @value{GDBN} for several different @dfn{target
11776architectures}. When @value{GDBN} is built like that, you can choose
11777one of the available architectures with the @kbd{set architecture}
11778command.
11779
11780@table @code
11781@kindex set architecture
11782@kindex show architecture
11783@item set architecture @var{arch}
11784This command sets the current target architecture to @var{arch}. The
11785value of @var{arch} can be @code{"auto"}, in addition to one of the
11786supported architectures.
11787
11788@item show architecture
11789Show the current target architecture.
9c16f35a
EZ
11790
11791@item set processor
11792@itemx processor
11793@kindex set processor
11794@kindex show processor
11795These are alias commands for, respectively, @code{set architecture}
11796and @code{show architecture}.
a8f24a35
EZ
11797@end table
11798
c906108c
SS
11799@menu
11800* Active Targets:: Active targets
11801* Target Commands:: Commands for managing targets
c906108c
SS
11802* Byte Order:: Choosing target byte order
11803* Remote:: Remote debugging
96baa820 11804* KOD:: Kernel Object Display
c906108c
SS
11805
11806@end menu
11807
6d2ebf8b 11808@node Active Targets
c906108c 11809@section Active targets
7a292a7a 11810
c906108c
SS
11811@cindex stacking targets
11812@cindex active targets
11813@cindex multiple targets
11814
c906108c 11815There are three classes of targets: processes, core files, and
7a292a7a
SS
11816executable files. @value{GDBN} can work concurrently on up to three
11817active targets, one in each class. This allows you to (for example)
11818start a process and inspect its activity without abandoning your work on
11819a core file.
c906108c
SS
11820
11821For example, if you execute @samp{gdb a.out}, then the executable file
11822@code{a.out} is the only active target. If you designate a core file as
11823well---presumably from a prior run that crashed and coredumped---then
11824@value{GDBN} has two active targets and uses them in tandem, looking
11825first in the corefile target, then in the executable file, to satisfy
11826requests for memory addresses. (Typically, these two classes of target
11827are complementary, since core files contain only a program's
11828read-write memory---variables and so on---plus machine status, while
11829executable files contain only the program text and initialized data.)
c906108c
SS
11830
11831When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
11832target as well. When a process target is active, all @value{GDBN}
11833commands requesting memory addresses refer to that target; addresses in
11834an active core file or executable file target are obscured while the
11835process target is active.
c906108c 11836
7a292a7a
SS
11837Use the @code{core-file} and @code{exec-file} commands to select a new
11838core file or executable target (@pxref{Files, ,Commands to specify
c906108c 11839files}). To specify as a target a process that is already running, use
7a292a7a
SS
11840the @code{attach} command (@pxref{Attach, ,Debugging an already-running
11841process}).
c906108c 11842
6d2ebf8b 11843@node Target Commands
c906108c
SS
11844@section Commands for managing targets
11845
11846@table @code
11847@item target @var{type} @var{parameters}
7a292a7a
SS
11848Connects the @value{GDBN} host environment to a target machine or
11849process. A target is typically a protocol for talking to debugging
11850facilities. You use the argument @var{type} to specify the type or
11851protocol of the target machine.
c906108c
SS
11852
11853Further @var{parameters} are interpreted by the target protocol, but
11854typically include things like device names or host names to connect
11855with, process numbers, and baud rates.
c906108c
SS
11856
11857The @code{target} command does not repeat if you press @key{RET} again
11858after executing the command.
11859
11860@kindex help target
11861@item help target
11862Displays the names of all targets available. To display targets
11863currently selected, use either @code{info target} or @code{info files}
11864(@pxref{Files, ,Commands to specify files}).
11865
11866@item help target @var{name}
11867Describe a particular target, including any parameters necessary to
11868select it.
11869
11870@kindex set gnutarget
11871@item set gnutarget @var{args}
5d161b24 11872@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 11873knows whether it is reading an @dfn{executable},
5d161b24
DB
11874a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
11875with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
11876with @code{gnutarget} the @code{target} refers to a program, not a machine.
11877
d4f3574e 11878@quotation
c906108c
SS
11879@emph{Warning:} To specify a file format with @code{set gnutarget},
11880you must know the actual BFD name.
d4f3574e 11881@end quotation
c906108c 11882
d4f3574e
SS
11883@noindent
11884@xref{Files, , Commands to specify files}.
c906108c 11885
5d161b24 11886@kindex show gnutarget
c906108c
SS
11887@item show gnutarget
11888Use the @code{show gnutarget} command to display what file format
11889@code{gnutarget} is set to read. If you have not set @code{gnutarget},
11890@value{GDBN} will determine the file format for each file automatically,
11891and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11892@end table
11893
4644b6e3 11894@cindex common targets
c906108c
SS
11895Here are some common targets (available, or not, depending on the GDB
11896configuration):
c906108c
SS
11897
11898@table @code
4644b6e3 11899@kindex target
c906108c 11900@item target exec @var{program}
4644b6e3 11901@cindex executable file target
c906108c
SS
11902An executable file. @samp{target exec @var{program}} is the same as
11903@samp{exec-file @var{program}}.
11904
c906108c 11905@item target core @var{filename}
4644b6e3 11906@cindex core dump file target
c906108c
SS
11907A core dump file. @samp{target core @var{filename}} is the same as
11908@samp{core-file @var{filename}}.
c906108c 11909
c906108c 11910@item target remote @var{dev}
4644b6e3 11911@cindex remote target
c906108c 11912Remote serial target in GDB-specific protocol. The argument @var{dev}
c1468174 11913specifies what serial device to use for the connection (e.g.@:
c906108c 11914@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 11915supports the @code{load} command. This is only useful if you have
c906108c
SS
11916some other way of getting the stub to the target system, and you can put
11917it somewhere in memory where it won't get clobbered by the download.
11918
c906108c 11919@item target sim
4644b6e3 11920@cindex built-in simulator target
2df3850c 11921Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 11922In general,
474c8240 11923@smallexample
104c1213
JM
11924 target sim
11925 load
11926 run
474c8240 11927@end smallexample
d4f3574e 11928@noindent
104c1213 11929works; however, you cannot assume that a specific memory map, device
d4f3574e 11930drivers, or even basic I/O is available, although some simulators do
104c1213
JM
11931provide these. For info about any processor-specific simulator details,
11932see the appropriate section in @ref{Embedded Processors, ,Embedded
11933Processors}.
11934
c906108c
SS
11935@end table
11936
104c1213 11937Some configurations may include these targets as well:
c906108c
SS
11938
11939@table @code
11940
c906108c 11941@item target nrom @var{dev}
4644b6e3 11942@cindex NetROM ROM emulator target
c906108c
SS
11943NetROM ROM emulator. This target only supports downloading.
11944
c906108c
SS
11945@end table
11946
5d161b24 11947Different targets are available on different configurations of @value{GDBN};
c906108c 11948your configuration may have more or fewer targets.
c906108c 11949
721c2651
EZ
11950Many remote targets require you to download the executable's code once
11951you've successfully established a connection. You may wish to control
11952various aspects of this process, such as the size of the data chunks
11953used by @value{GDBN} to download program parts to the remote target.
a8f24a35
EZ
11954
11955@table @code
11956@kindex set download-write-size
11957@item set download-write-size @var{size}
11958Set the write size used when downloading a program. Only used when
11959downloading a program onto a remote target. Specify zero or a
11960negative value to disable blocked writes. The actual size of each
11961transfer is also limited by the size of the target packet and the
11962memory cache.
11963
11964@kindex show download-write-size
11965@item show download-write-size
721c2651 11966@kindex show download-write-size
a8f24a35 11967Show the current value of the write size.
721c2651
EZ
11968
11969@item set hash
11970@kindex set hash@r{, for remote monitors}
11971@cindex hash mark while downloading
11972This command controls whether a hash mark @samp{#} is displayed while
11973downloading a file to the remote monitor. If on, a hash mark is
11974displayed after each S-record is successfully downloaded to the
11975monitor.
11976
11977@item show hash
11978@kindex show hash@r{, for remote monitors}
11979Show the current status of displaying the hash mark.
11980
11981@item set debug monitor
11982@kindex set debug monitor
11983@cindex display remote monitor communications
11984Enable or disable display of communications messages between
11985@value{GDBN} and the remote monitor.
11986
11987@item show debug monitor
11988@kindex show debug monitor
11989Show the current status of displaying communications between
11990@value{GDBN} and the remote monitor.
a8f24a35 11991@end table
c906108c
SS
11992
11993@table @code
11994
11995@kindex load @var{filename}
11996@item load @var{filename}
c906108c
SS
11997Depending on what remote debugging facilities are configured into
11998@value{GDBN}, the @code{load} command may be available. Where it exists, it
11999is meant to make @var{filename} (an executable) available for debugging
12000on the remote system---by downloading, or dynamic linking, for example.
12001@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
12002the @code{add-symbol-file} command.
12003
12004If your @value{GDBN} does not have a @code{load} command, attempting to
12005execute it gets the error message ``@code{You can't do that when your
12006target is @dots{}}''
c906108c
SS
12007
12008The file is loaded at whatever address is specified in the executable.
12009For some object file formats, you can specify the load address when you
12010link the program; for other formats, like a.out, the object file format
12011specifies a fixed address.
12012@c FIXME! This would be a good place for an xref to the GNU linker doc.
12013
c906108c
SS
12014@code{load} does not repeat if you press @key{RET} again after using it.
12015@end table
12016
6d2ebf8b 12017@node Byte Order
c906108c 12018@section Choosing target byte order
7a292a7a 12019
c906108c
SS
12020@cindex choosing target byte order
12021@cindex target byte order
c906108c 12022
172c2a43 12023Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
12024offer the ability to run either big-endian or little-endian byte
12025orders. Usually the executable or symbol will include a bit to
12026designate the endian-ness, and you will not need to worry about
12027which to use. However, you may still find it useful to adjust
d4f3574e 12028@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
12029
12030@table @code
4644b6e3 12031@kindex set endian
c906108c
SS
12032@item set endian big
12033Instruct @value{GDBN} to assume the target is big-endian.
12034
c906108c
SS
12035@item set endian little
12036Instruct @value{GDBN} to assume the target is little-endian.
12037
c906108c
SS
12038@item set endian auto
12039Instruct @value{GDBN} to use the byte order associated with the
12040executable.
12041
12042@item show endian
12043Display @value{GDBN}'s current idea of the target byte order.
12044
12045@end table
12046
12047Note that these commands merely adjust interpretation of symbolic
12048data on the host, and that they have absolutely no effect on the
12049target system.
12050
6d2ebf8b 12051@node Remote
c906108c
SS
12052@section Remote debugging
12053@cindex remote debugging
12054
12055If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
12056@value{GDBN} in the usual way, it is often useful to use remote debugging.
12057For example, you might use remote debugging on an operating system kernel,
c906108c
SS
12058or on a small system which does not have a general purpose operating system
12059powerful enough to run a full-featured debugger.
12060
12061Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
12062to make this work with particular debugging targets. In addition,
5d161b24 12063@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
12064but not specific to any particular target system) which you can use if you
12065write the remote stubs---the code that runs on the remote system to
12066communicate with @value{GDBN}.
12067
12068Other remote targets may be available in your
12069configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 12070
c45da7e6
EZ
12071Once you've connected to the remote target, @value{GDBN} allows you to
12072send arbitrary commands to the remote monitor:
12073
12074@table @code
12075@item remote @var{command}
12076@kindex remote@r{, a command}
12077@cindex send command to remote monitor
12078Send an arbitrary @var{command} string to the remote monitor.
12079@end table
12080
12081
6f05cf9f
AC
12082@node KOD
12083@section Kernel Object Display
6f05cf9f 12084@cindex kernel object display
6f05cf9f
AC
12085@cindex KOD
12086
12087Some targets support kernel object display. Using this facility,
12088@value{GDBN} communicates specially with the underlying operating system
12089and can display information about operating system-level objects such as
12090mutexes and other synchronization objects. Exactly which objects can be
12091displayed is determined on a per-OS basis.
12092
3bbe9696 12093@kindex set os
6f05cf9f
AC
12094Use the @code{set os} command to set the operating system. This tells
12095@value{GDBN} which kernel object display module to initialize:
12096
474c8240 12097@smallexample
6f05cf9f 12098(@value{GDBP}) set os cisco
474c8240 12099@end smallexample
6f05cf9f 12100
3bbe9696
EZ
12101@kindex show os
12102The associated command @code{show os} displays the operating system
12103set with the @code{set os} command; if no operating system has been
12104set, @code{show os} will display an empty string @samp{""}.
12105
6f05cf9f
AC
12106If @code{set os} succeeds, @value{GDBN} will display some information
12107about the operating system, and will create a new @code{info} command
12108which can be used to query the target. The @code{info} command is named
12109after the operating system:
c906108c 12110
3bbe9696 12111@kindex info cisco
474c8240 12112@smallexample
6f05cf9f
AC
12113(@value{GDBP}) info cisco
12114List of Cisco Kernel Objects
12115Object Description
12116any Any and all objects
474c8240 12117@end smallexample
6f05cf9f
AC
12118
12119Further subcommands can be used to query about particular objects known
12120by the kernel.
12121
3bbe9696
EZ
12122There is currently no way to determine whether a given operating
12123system is supported other than to try setting it with @kbd{set os
12124@var{name}}, where @var{name} is the name of the operating system you
12125want to try.
6f05cf9f
AC
12126
12127
12128@node Remote Debugging
12129@chapter Debugging remote programs
12130
6b2f586d 12131@menu
07f31aa6 12132* Connecting:: Connecting to a remote target
6b2f586d
AC
12133* Server:: Using the gdbserver program
12134* NetWare:: Using the gdbserve.nlm program
501eef12 12135* Remote configuration:: Remote configuration
6b2f586d 12136* remote stub:: Implementing a remote stub
6b2f586d
AC
12137@end menu
12138
07f31aa6
DJ
12139@node Connecting
12140@section Connecting to a remote target
12141
12142On the @value{GDBN} host machine, you will need an unstripped copy of
12143your program, since @value{GDBN} needs symobl and debugging information.
12144Start up @value{GDBN} as usual, using the name of the local copy of your
12145program as the first argument.
12146
12147@cindex serial line, @code{target remote}
12148If you're using a serial line, you may want to give @value{GDBN} the
12149@w{@samp{--baud}} option, or use the @code{set remotebaud} command
9c16f35a
EZ
12150(@pxref{Remote configuration, set remotebaud}) before the
12151@code{target} command.
07f31aa6
DJ
12152
12153After that, use @code{target remote} to establish communications with
12154the target machine. Its argument specifies how to communicate---either
12155via a devicename attached to a direct serial line, or a TCP or UDP port
12156(possibly to a terminal server which in turn has a serial line to the
12157target). For example, to use a serial line connected to the device
12158named @file{/dev/ttyb}:
12159
12160@smallexample
12161target remote /dev/ttyb
12162@end smallexample
12163
12164@cindex TCP port, @code{target remote}
12165To use a TCP connection, use an argument of the form
12166@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
12167For example, to connect to port 2828 on a
12168terminal server named @code{manyfarms}:
12169
12170@smallexample
12171target remote manyfarms:2828
12172@end smallexample
12173
12174If your remote target is actually running on the same machine as
12175your debugger session (e.g.@: a simulator of your target running on
12176the same host), you can omit the hostname. For example, to connect
12177to port 1234 on your local machine:
12178
12179@smallexample
12180target remote :1234
12181@end smallexample
12182@noindent
12183
12184Note that the colon is still required here.
12185
12186@cindex UDP port, @code{target remote}
12187To use a UDP connection, use an argument of the form
12188@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
12189on a terminal server named @code{manyfarms}:
12190
12191@smallexample
12192target remote udp:manyfarms:2828
12193@end smallexample
12194
12195When using a UDP connection for remote debugging, you should keep in mind
12196that the `U' stands for ``Unreliable''. UDP can silently drop packets on
12197busy or unreliable networks, which will cause havoc with your debugging
12198session.
12199
12200Now you can use all the usual commands to examine and change data and to
12201step and continue the remote program.
12202
12203@cindex interrupting remote programs
12204@cindex remote programs, interrupting
12205Whenever @value{GDBN} is waiting for the remote program, if you type the
12206interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
12207program. This may or may not succeed, depending in part on the hardware
12208and the serial drivers the remote system uses. If you type the
12209interrupt character once again, @value{GDBN} displays this prompt:
12210
12211@smallexample
12212Interrupted while waiting for the program.
12213Give up (and stop debugging it)? (y or n)
12214@end smallexample
12215
12216If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
12217(If you decide you want to try again later, you can use @samp{target
12218remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
12219goes back to waiting.
12220
12221@table @code
12222@kindex detach (remote)
12223@item detach
12224When you have finished debugging the remote program, you can use the
12225@code{detach} command to release it from @value{GDBN} control.
12226Detaching from the target normally resumes its execution, but the results
12227will depend on your particular remote stub. After the @code{detach}
12228command, @value{GDBN} is free to connect to another target.
12229
12230@kindex disconnect
12231@item disconnect
12232The @code{disconnect} command behaves like @code{detach}, except that
12233the target is generally not resumed. It will wait for @value{GDBN}
12234(this instance or another one) to connect and continue debugging. After
12235the @code{disconnect} command, @value{GDBN} is again free to connect to
12236another target.
09d4efe1
EZ
12237
12238@cindex send command to remote monitor
fad38dfa
EZ
12239@cindex extend @value{GDBN} for remote targets
12240@cindex add new commands for external monitor
09d4efe1
EZ
12241@kindex monitor
12242@item monitor @var{cmd}
fad38dfa
EZ
12243This command allows you to send arbitrary commands directly to the
12244remote monitor. Since @value{GDBN} doesn't care about the commands it
12245sends like this, this command is the way to extend @value{GDBN}---you
12246can add new commands that only the external monitor will understand
12247and implement.
07f31aa6
DJ
12248@end table
12249
6f05cf9f
AC
12250@node Server
12251@section Using the @code{gdbserver} program
12252
12253@kindex gdbserver
12254@cindex remote connection without stubs
12255@code{gdbserver} is a control program for Unix-like systems, which
12256allows you to connect your program with a remote @value{GDBN} via
12257@code{target remote}---but without linking in the usual debugging stub.
12258
12259@code{gdbserver} is not a complete replacement for the debugging stubs,
12260because it requires essentially the same operating-system facilities
12261that @value{GDBN} itself does. In fact, a system that can run
12262@code{gdbserver} to connect to a remote @value{GDBN} could also run
12263@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
12264because it is a much smaller program than @value{GDBN} itself. It is
12265also easier to port than all of @value{GDBN}, so you may be able to get
12266started more quickly on a new system by using @code{gdbserver}.
12267Finally, if you develop code for real-time systems, you may find that
12268the tradeoffs involved in real-time operation make it more convenient to
12269do as much development work as possible on another system, for example
12270by cross-compiling. You can use @code{gdbserver} to make a similar
12271choice for debugging.
12272
12273@value{GDBN} and @code{gdbserver} communicate via either a serial line
12274or a TCP connection, using the standard @value{GDBN} remote serial
12275protocol.
12276
12277@table @emph
12278@item On the target machine,
12279you need to have a copy of the program you want to debug.
12280@code{gdbserver} does not need your program's symbol table, so you can
12281strip the program if necessary to save space. @value{GDBN} on the host
12282system does all the symbol handling.
12283
12284To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 12285the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
12286syntax is:
12287
12288@smallexample
12289target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
12290@end smallexample
12291
12292@var{comm} is either a device name (to use a serial line) or a TCP
12293hostname and portnumber. For example, to debug Emacs with the argument
12294@samp{foo.txt} and communicate with @value{GDBN} over the serial port
12295@file{/dev/com1}:
12296
12297@smallexample
12298target> gdbserver /dev/com1 emacs foo.txt
12299@end smallexample
12300
12301@code{gdbserver} waits passively for the host @value{GDBN} to communicate
12302with it.
12303
12304To use a TCP connection instead of a serial line:
12305
12306@smallexample
12307target> gdbserver host:2345 emacs foo.txt
12308@end smallexample
12309
12310The only difference from the previous example is the first argument,
12311specifying that you are communicating with the host @value{GDBN} via
12312TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
12313expect a TCP connection from machine @samp{host} to local TCP port 2345.
12314(Currently, the @samp{host} part is ignored.) You can choose any number
12315you want for the port number as long as it does not conflict with any
12316TCP ports already in use on the target system (for example, @code{23} is
12317reserved for @code{telnet}).@footnote{If you choose a port number that
12318conflicts with another service, @code{gdbserver} prints an error message
12319and exits.} You must use the same port number with the host @value{GDBN}
12320@code{target remote} command.
12321
56460a61
DJ
12322On some targets, @code{gdbserver} can also attach to running programs.
12323This is accomplished via the @code{--attach} argument. The syntax is:
12324
12325@smallexample
12326target> gdbserver @var{comm} --attach @var{pid}
12327@end smallexample
12328
12329@var{pid} is the process ID of a currently running process. It isn't necessary
12330to point @code{gdbserver} at a binary for the running process.
12331
b1fe9455
DJ
12332@pindex pidof
12333@cindex attach to a program by name
12334You can debug processes by name instead of process ID if your target has the
12335@code{pidof} utility:
12336
12337@smallexample
12338target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
12339@end smallexample
12340
12341In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
12342has multiple threads, most versions of @code{pidof} support the
12343@code{-s} option to only return the first process ID.
12344
07f31aa6
DJ
12345@item On the host machine,
12346connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
12347For TCP connections, you must start up @code{gdbserver} prior to using
12348the @code{target remote} command. Otherwise you may get an error whose
12349text depends on the host system, but which usually looks something like
07f31aa6 12350@samp{Connection refused}. You don't need to use the @code{load}
397ca115
EZ
12351command in @value{GDBN} when using @code{gdbserver}, since the program is
12352already on the target. However, if you want to load the symbols (as
12353you normally would), do that with the @code{file} command, and issue
12354it @emph{before} connecting to the server; otherwise, you will get an
12355error message saying @code{"Program is already running"}, since the
12356program is considered running after the connection.
07f31aa6 12357
6f05cf9f
AC
12358@end table
12359
12360@node NetWare
12361@section Using the @code{gdbserve.nlm} program
12362
12363@kindex gdbserve.nlm
12364@code{gdbserve.nlm} is a control program for NetWare systems, which
12365allows you to connect your program with a remote @value{GDBN} via
12366@code{target remote}.
12367
12368@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
12369using the standard @value{GDBN} remote serial protocol.
12370
12371@table @emph
12372@item On the target machine,
12373you need to have a copy of the program you want to debug.
12374@code{gdbserve.nlm} does not need your program's symbol table, so you
12375can strip the program if necessary to save space. @value{GDBN} on the
12376host system does all the symbol handling.
12377
12378To use the server, you must tell it how to communicate with
12379@value{GDBN}; the name of your program; and the arguments for your
12380program. The syntax is:
12381
12382@smallexample
12383load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
12384 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
12385@end smallexample
12386
12387@var{board} and @var{port} specify the serial line; @var{baud} specifies
12388the baud rate used by the connection. @var{port} and @var{node} default
12389to 0, @var{baud} defaults to 9600@dmn{bps}.
12390
12391For example, to debug Emacs with the argument @samp{foo.txt}and
12392communicate with @value{GDBN} over serial port number 2 or board 1
12393using a 19200@dmn{bps} connection:
12394
12395@smallexample
12396load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
12397@end smallexample
12398
07f31aa6
DJ
12399@item
12400On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
12401Connecting to a remote target}).
6f05cf9f 12402
6f05cf9f
AC
12403@end table
12404
501eef12
AC
12405@node Remote configuration
12406@section Remote configuration
12407
9c16f35a
EZ
12408@kindex set remote
12409@kindex show remote
12410This section documents the configuration options available when
12411debugging remote programs. For the options related to the File I/O
12412extensions of the remote protocol, see @ref{The system call,
12413system-call-allowed}.
501eef12
AC
12414
12415@table @code
9c16f35a
EZ
12416@item set remoteaddresssize @var{bits}
12417@cindex adress size for remote targets
12418@cindex bits in remote address
12419Set the maximum size of address in a memory packet to the specified
12420number of bits. @value{GDBN} will mask off the address bits above
12421that number, when it passes addresses to the remote target. The
12422default value is the number of bits in the target's address.
12423
12424@item show remoteaddresssize
12425Show the current value of remote address size in bits.
12426
12427@item set remotebaud @var{n}
12428@cindex baud rate for remote targets
12429Set the baud rate for the remote serial I/O to @var{n} baud. The
12430value is used to set the speed of the serial port used for debugging
12431remote targets.
12432
12433@item show remotebaud
12434Show the current speed of the remote connection.
12435
12436@item set remotebreak
12437@cindex interrupt remote programs
12438@cindex BREAK signal instead of Ctrl-C
9a6253be 12439@anchor{set remotebreak}
9c16f35a
EZ
12440If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
12441when you press the @key{Ctrl-C} key to interrupt the program running
9a7a1b36 12442on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
12443character instead. The default is off, since most remote systems
12444expect to see @samp{Ctrl-C} as the interrupt signal.
12445
12446@item show remotebreak
12447Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
12448interrupt the remote program.
12449
12450@item set remotedebug
12451@cindex debug remote protocol
12452@cindex remote protocol debugging
12453@cindex display remote packets
12454Control the debugging of the remote protocol. When enabled, each
12455packet sent to or received from the remote target is displayed. The
12456defaults is off.
12457
12458@item show remotedebug
12459Show the current setting of the remote protocol debugging.
12460
12461@item set remotedevice @var{device}
12462@cindex serial port name
12463Set the name of the serial port through which to communicate to the
12464remote target to @var{device}. This is the device used by
12465@value{GDBN} to open the serial communications line to the remote
12466target. There's no default, so you must set a valid port name for the
12467remote serial communications to work. (Some varieties of the
12468@code{target} command accept the port name as part of their
12469arguments.)
12470
12471@item show remotedevice
12472Show the current name of the serial port.
12473
12474@item set remotelogbase @var{base}
12475Set the base (a.k.a.@: radix) of logging serial protocol
12476communications to @var{base}. Supported values of @var{base} are:
12477@code{ascii}, @code{octal}, and @code{hex}. The default is
12478@code{ascii}.
12479
12480@item show remotelogbase
12481Show the current setting of the radix for logging remote serial
12482protocol.
12483
12484@item set remotelogfile @var{file}
12485@cindex record serial communications on file
12486Record remote serial communications on the named @var{file}. The
12487default is not to record at all.
12488
12489@item show remotelogfile.
12490Show the current setting of the file name on which to record the
12491serial communications.
12492
12493@item set remotetimeout @var{num}
12494@cindex timeout for serial communications
12495@cindex remote timeout
12496Set the timeout limit to wait for the remote target to respond to
12497@var{num} seconds. The default is 2 seconds.
12498
12499@item show remotetimeout
12500Show the current number of seconds to wait for the remote target
12501responses.
12502
12503@cindex limit hardware breakpoints and watchpoints
12504@cindex remote target, limit break- and watchpoints
501eef12
AC
12505@anchor{set remote hardware-watchpoint-limit}
12506@anchor{set remote hardware-breakpoint-limit}
12507@item set remote hardware-watchpoint-limit @var{limit}
12508@itemx set remote hardware-breakpoint-limit @var{limit}
12509Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
12510watchpoints. A limit of -1, the default, is treated as unlimited.
9c16f35a
EZ
12511
12512@item set remote fetch-register-packet
12513@itemx set remote set-register-packet
12514@itemx set remote P-packet
12515@itemx set remote p-packet
12516@cindex P-packet
12517@cindex fetch registers from remote targets
12518@cindex set registers in remote targets
12519Determine whether @value{GDBN} can set and fetch registers from the
12520remote target using the @samp{P} packets. The default depends on the
12521remote stub's support of the @samp{P} packets (@value{GDBN} queries
12522the stub when this packet is first required).
12523
12524@item show remote fetch-register-packet
12525@itemx show remote set-register-packet
12526@itemx show remote P-packet
12527@itemx show remote p-packet
12528Show the current setting of using the @samp{P} packets for setting and
12529fetching registers from the remote target.
12530
12531@cindex binary downloads
12532@cindex X-packet
12533@item set remote binary-download-packet
12534@itemx set remote X-packet
12535Determine whether @value{GDBN} sends downloads in binary mode using
12536the @samp{X} packets. The default is on.
12537
12538@item show remote binary-download-packet
12539@itemx show remote X-packet
12540Show the current setting of using the @samp{X} packets for binary
12541downloads.
12542
12543@item set remote read-aux-vector-packet
12544@cindex auxiliary vector of remote target
12545@cindex @code{auxv}, and remote targets
12546Set the use of the remote protocol's @samp{qPart:auxv:read} (target
12547auxiliary vector read) request. This request is used to fetch the
721c2651
EZ
12548remote target's @dfn{auxiliary vector}, see @ref{OS Information,
12549Auxiliary Vector}. The default setting depends on the remote stub's
12550support of this request (@value{GDBN} queries the stub when this
12551request is first required). @xref{General Query Packets, qPart}, for
12552more information about this request.
9c16f35a
EZ
12553
12554@item show remote read-aux-vector-packet
12555Show the current setting of use of the @samp{qPart:auxv:read} request.
12556
12557@item set remote symbol-lookup-packet
12558@cindex remote symbol lookup request
12559Set the use of the remote protocol's @samp{qSymbol} (target symbol
12560lookup) request. This request is used to communicate symbol
12561information to the remote target, e.g., whenever a new shared library
12562is loaded by the remote (@pxref{Files, shared libraries}). The
12563default setting depends on the remote stub's support of this request
12564(@value{GDBN} queries the stub when this request is first required).
12565@xref{General Query Packets, qSymbol}, for more information about this
12566request.
12567
12568@item show remote symbol-lookup-packet
12569Show the current setting of use of the @samp{qSymbol} request.
12570
12571@item set remote verbose-resume-packet
12572@cindex resume remote target
12573@cindex signal thread, and remote targets
12574@cindex single-step thread, and remote targets
12575@cindex thread-specific operations on remote targets
12576Set the use of the remote protocol's @samp{vCont} (descriptive resume)
12577request. This request is used to resume specific threads in the
12578remote target, and to single-step or signal them. The default setting
12579depends on the remote stub's support of this request (@value{GDBN}
12580queries the stub when this request is first required). This setting
12581affects debugging of multithreaded programs: if @samp{vCont} cannot be
12582used, @value{GDBN} might be unable to single-step a specific thread,
12583especially under @code{set scheduler-locking off}; it is also
12584impossible to pause a specific thread. @xref{Packets, vCont}, for
12585more details.
12586
12587@item show remote verbose-resume-packet
12588Show the current setting of use of the @samp{vCont} request
12589
12590@item set remote software-breakpoint-packet
12591@itemx set remote hardware-breakpoint-packet
12592@itemx set remote write-watchpoint-packet
12593@itemx set remote read-watchpoint-packet
12594@itemx set remote access-watchpoint-packet
12595@itemx set remote Z-packet
12596@cindex Z-packet
12597@cindex remote hardware breakpoints and watchpoints
12598These commands enable or disable the use of @samp{Z} packets for
12599setting breakpoints and watchpoints in the remote target. The default
12600depends on the remote stub's support of the @samp{Z} packets
12601(@value{GDBN} queries the stub when each packet is first required).
12602The command @code{set remote Z-packet}, kept for back-compatibility,
12603turns on or off all the features that require the use of @samp{Z}
12604packets.
12605
12606@item show remote software-breakpoint-packet
12607@itemx show remote hardware-breakpoint-packet
12608@itemx show remote write-watchpoint-packet
12609@itemx show remote read-watchpoint-packet
12610@itemx show remote access-watchpoint-packet
12611@itemx show remote Z-packet
12612Show the current setting of @samp{Z} packets usage.
0abb7bc7
EZ
12613
12614@item set remote get-thread-local-storage-address
12615@kindex set remote get-thread-local-storage-address
12616@cindex thread local storage of remote targets
12617This command enables or disables the use of the @samp{qGetTLSAddr}
12618(Get Thread Local Storage Address) request packet. The default
12619depends on whether the remote stub supports this request.
12620@xref{General Query Packets, qGetTLSAddr}, for more details about this
12621packet.
12622
12623@item show remote get-thread-local-storage-address
12624@kindex show remote get-thread-local-storage-address
12625Show the current setting of @samp{qGetTLSAddr} packet usage.
501eef12
AC
12626@end table
12627
6f05cf9f
AC
12628@node remote stub
12629@section Implementing a remote stub
7a292a7a 12630
8e04817f
AC
12631@cindex debugging stub, example
12632@cindex remote stub, example
12633@cindex stub example, remote debugging
12634The stub files provided with @value{GDBN} implement the target side of the
12635communication protocol, and the @value{GDBN} side is implemented in the
12636@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
12637these subroutines to communicate, and ignore the details. (If you're
12638implementing your own stub file, you can still ignore the details: start
12639with one of the existing stub files. @file{sparc-stub.c} is the best
12640organized, and therefore the easiest to read.)
12641
104c1213
JM
12642@cindex remote serial debugging, overview
12643To debug a program running on another machine (the debugging
12644@dfn{target} machine), you must first arrange for all the usual
12645prerequisites for the program to run by itself. For example, for a C
12646program, you need:
c906108c 12647
104c1213
JM
12648@enumerate
12649@item
12650A startup routine to set up the C runtime environment; these usually
12651have a name like @file{crt0}. The startup routine may be supplied by
12652your hardware supplier, or you may have to write your own.
96baa820 12653
5d161b24 12654@item
d4f3574e 12655A C subroutine library to support your program's
104c1213 12656subroutine calls, notably managing input and output.
96baa820 12657
104c1213
JM
12658@item
12659A way of getting your program to the other machine---for example, a
12660download program. These are often supplied by the hardware
12661manufacturer, but you may have to write your own from hardware
12662documentation.
12663@end enumerate
96baa820 12664
104c1213
JM
12665The next step is to arrange for your program to use a serial port to
12666communicate with the machine where @value{GDBN} is running (the @dfn{host}
12667machine). In general terms, the scheme looks like this:
96baa820 12668
104c1213
JM
12669@table @emph
12670@item On the host,
12671@value{GDBN} already understands how to use this protocol; when everything
12672else is set up, you can simply use the @samp{target remote} command
12673(@pxref{Targets,,Specifying a Debugging Target}).
12674
12675@item On the target,
12676you must link with your program a few special-purpose subroutines that
12677implement the @value{GDBN} remote serial protocol. The file containing these
12678subroutines is called a @dfn{debugging stub}.
12679
12680On certain remote targets, you can use an auxiliary program
12681@code{gdbserver} instead of linking a stub into your program.
12682@xref{Server,,Using the @code{gdbserver} program}, for details.
12683@end table
96baa820 12684
104c1213
JM
12685The debugging stub is specific to the architecture of the remote
12686machine; for example, use @file{sparc-stub.c} to debug programs on
12687@sc{sparc} boards.
96baa820 12688
104c1213
JM
12689@cindex remote serial stub list
12690These working remote stubs are distributed with @value{GDBN}:
96baa820 12691
104c1213
JM
12692@table @code
12693
12694@item i386-stub.c
41afff9a 12695@cindex @file{i386-stub.c}
104c1213
JM
12696@cindex Intel
12697@cindex i386
12698For Intel 386 and compatible architectures.
12699
12700@item m68k-stub.c
41afff9a 12701@cindex @file{m68k-stub.c}
104c1213
JM
12702@cindex Motorola 680x0
12703@cindex m680x0
12704For Motorola 680x0 architectures.
12705
12706@item sh-stub.c
41afff9a 12707@cindex @file{sh-stub.c}
172c2a43 12708@cindex Renesas
104c1213 12709@cindex SH
172c2a43 12710For Renesas SH architectures.
104c1213
JM
12711
12712@item sparc-stub.c
41afff9a 12713@cindex @file{sparc-stub.c}
104c1213
JM
12714@cindex Sparc
12715For @sc{sparc} architectures.
12716
12717@item sparcl-stub.c
41afff9a 12718@cindex @file{sparcl-stub.c}
104c1213
JM
12719@cindex Fujitsu
12720@cindex SparcLite
12721For Fujitsu @sc{sparclite} architectures.
12722
12723@end table
12724
12725The @file{README} file in the @value{GDBN} distribution may list other
12726recently added stubs.
12727
12728@menu
12729* Stub Contents:: What the stub can do for you
12730* Bootstrapping:: What you must do for the stub
12731* Debug Session:: Putting it all together
104c1213
JM
12732@end menu
12733
6d2ebf8b 12734@node Stub Contents
6f05cf9f 12735@subsection What the stub can do for you
104c1213
JM
12736
12737@cindex remote serial stub
12738The debugging stub for your architecture supplies these three
12739subroutines:
12740
12741@table @code
12742@item set_debug_traps
4644b6e3 12743@findex set_debug_traps
104c1213
JM
12744@cindex remote serial stub, initialization
12745This routine arranges for @code{handle_exception} to run when your
12746program stops. You must call this subroutine explicitly near the
12747beginning of your program.
12748
12749@item handle_exception
4644b6e3 12750@findex handle_exception
104c1213
JM
12751@cindex remote serial stub, main routine
12752This is the central workhorse, but your program never calls it
12753explicitly---the setup code arranges for @code{handle_exception} to
12754run when a trap is triggered.
12755
12756@code{handle_exception} takes control when your program stops during
12757execution (for example, on a breakpoint), and mediates communications
12758with @value{GDBN} on the host machine. This is where the communications
12759protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 12760representative on the target machine. It begins by sending summary
104c1213
JM
12761information on the state of your program, then continues to execute,
12762retrieving and transmitting any information @value{GDBN} needs, until you
12763execute a @value{GDBN} command that makes your program resume; at that point,
12764@code{handle_exception} returns control to your own code on the target
5d161b24 12765machine.
104c1213
JM
12766
12767@item breakpoint
12768@cindex @code{breakpoint} subroutine, remote
12769Use this auxiliary subroutine to make your program contain a
12770breakpoint. Depending on the particular situation, this may be the only
12771way for @value{GDBN} to get control. For instance, if your target
12772machine has some sort of interrupt button, you won't need to call this;
12773pressing the interrupt button transfers control to
12774@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
12775simply receiving characters on the serial port may also trigger a trap;
12776again, in that situation, you don't need to call @code{breakpoint} from
12777your own program---simply running @samp{target remote} from the host
5d161b24 12778@value{GDBN} session gets control.
104c1213
JM
12779
12780Call @code{breakpoint} if none of these is true, or if you simply want
12781to make certain your program stops at a predetermined point for the
12782start of your debugging session.
12783@end table
12784
6d2ebf8b 12785@node Bootstrapping
6f05cf9f 12786@subsection What you must do for the stub
104c1213
JM
12787
12788@cindex remote stub, support routines
12789The debugging stubs that come with @value{GDBN} are set up for a particular
12790chip architecture, but they have no information about the rest of your
12791debugging target machine.
12792
12793First of all you need to tell the stub how to communicate with the
12794serial port.
12795
12796@table @code
12797@item int getDebugChar()
4644b6e3 12798@findex getDebugChar
104c1213
JM
12799Write this subroutine to read a single character from the serial port.
12800It may be identical to @code{getchar} for your target system; a
12801different name is used to allow you to distinguish the two if you wish.
12802
12803@item void putDebugChar(int)
4644b6e3 12804@findex putDebugChar
104c1213 12805Write this subroutine to write a single character to the serial port.
5d161b24 12806It may be identical to @code{putchar} for your target system; a
104c1213
JM
12807different name is used to allow you to distinguish the two if you wish.
12808@end table
12809
12810@cindex control C, and remote debugging
12811@cindex interrupting remote targets
12812If you want @value{GDBN} to be able to stop your program while it is
12813running, you need to use an interrupt-driven serial driver, and arrange
12814for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
12815character). That is the character which @value{GDBN} uses to tell the
12816remote system to stop.
12817
12818Getting the debugging target to return the proper status to @value{GDBN}
12819probably requires changes to the standard stub; one quick and dirty way
12820is to just execute a breakpoint instruction (the ``dirty'' part is that
12821@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
12822
12823Other routines you need to supply are:
12824
12825@table @code
12826@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 12827@findex exceptionHandler
104c1213
JM
12828Write this function to install @var{exception_address} in the exception
12829handling tables. You need to do this because the stub does not have any
12830way of knowing what the exception handling tables on your target system
12831are like (for example, the processor's table might be in @sc{rom},
12832containing entries which point to a table in @sc{ram}).
12833@var{exception_number} is the exception number which should be changed;
12834its meaning is architecture-dependent (for example, different numbers
12835might represent divide by zero, misaligned access, etc). When this
12836exception occurs, control should be transferred directly to
12837@var{exception_address}, and the processor state (stack, registers,
12838and so on) should be just as it is when a processor exception occurs. So if
12839you want to use a jump instruction to reach @var{exception_address}, it
12840should be a simple jump, not a jump to subroutine.
12841
12842For the 386, @var{exception_address} should be installed as an interrupt
12843gate so that interrupts are masked while the handler runs. The gate
12844should be at privilege level 0 (the most privileged level). The
12845@sc{sparc} and 68k stubs are able to mask interrupts themselves without
12846help from @code{exceptionHandler}.
12847
12848@item void flush_i_cache()
4644b6e3 12849@findex flush_i_cache
d4f3574e 12850On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
12851instruction cache, if any, on your target machine. If there is no
12852instruction cache, this subroutine may be a no-op.
12853
12854On target machines that have instruction caches, @value{GDBN} requires this
12855function to make certain that the state of your program is stable.
12856@end table
12857
12858@noindent
12859You must also make sure this library routine is available:
12860
12861@table @code
12862@item void *memset(void *, int, int)
4644b6e3 12863@findex memset
104c1213
JM
12864This is the standard library function @code{memset} that sets an area of
12865memory to a known value. If you have one of the free versions of
12866@code{libc.a}, @code{memset} can be found there; otherwise, you must
12867either obtain it from your hardware manufacturer, or write your own.
12868@end table
12869
12870If you do not use the GNU C compiler, you may need other standard
12871library subroutines as well; this varies from one stub to another,
12872but in general the stubs are likely to use any of the common library
d4f3574e 12873subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
12874
12875
6d2ebf8b 12876@node Debug Session
6f05cf9f 12877@subsection Putting it all together
104c1213
JM
12878
12879@cindex remote serial debugging summary
12880In summary, when your program is ready to debug, you must follow these
12881steps.
12882
12883@enumerate
12884@item
6d2ebf8b 12885Make sure you have defined the supporting low-level routines
104c1213
JM
12886(@pxref{Bootstrapping,,What you must do for the stub}):
12887@display
12888@code{getDebugChar}, @code{putDebugChar},
12889@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
12890@end display
12891
12892@item
12893Insert these lines near the top of your program:
12894
474c8240 12895@smallexample
104c1213
JM
12896set_debug_traps();
12897breakpoint();
474c8240 12898@end smallexample
104c1213
JM
12899
12900@item
12901For the 680x0 stub only, you need to provide a variable called
12902@code{exceptionHook}. Normally you just use:
12903
474c8240 12904@smallexample
104c1213 12905void (*exceptionHook)() = 0;
474c8240 12906@end smallexample
104c1213 12907
d4f3574e 12908@noindent
104c1213 12909but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 12910function in your program, that function is called when
104c1213
JM
12911@code{@value{GDBN}} continues after stopping on a trap (for example, bus
12912error). The function indicated by @code{exceptionHook} is called with
12913one parameter: an @code{int} which is the exception number.
12914
12915@item
12916Compile and link together: your program, the @value{GDBN} debugging stub for
12917your target architecture, and the supporting subroutines.
12918
12919@item
12920Make sure you have a serial connection between your target machine and
12921the @value{GDBN} host, and identify the serial port on the host.
12922
12923@item
12924@c The "remote" target now provides a `load' command, so we should
12925@c document that. FIXME.
12926Download your program to your target machine (or get it there by
12927whatever means the manufacturer provides), and start it.
12928
12929@item
07f31aa6
DJ
12930Start @value{GDBN} on the host, and connect to the target
12931(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 12932
104c1213
JM
12933@end enumerate
12934
8e04817f
AC
12935@node Configurations
12936@chapter Configuration-Specific Information
104c1213 12937
8e04817f
AC
12938While nearly all @value{GDBN} commands are available for all native and
12939cross versions of the debugger, there are some exceptions. This chapter
12940describes things that are only available in certain configurations.
104c1213 12941
8e04817f
AC
12942There are three major categories of configurations: native
12943configurations, where the host and target are the same, embedded
12944operating system configurations, which are usually the same for several
12945different processor architectures, and bare embedded processors, which
12946are quite different from each other.
104c1213 12947
8e04817f
AC
12948@menu
12949* Native::
12950* Embedded OS::
12951* Embedded Processors::
12952* Architectures::
12953@end menu
104c1213 12954
8e04817f
AC
12955@node Native
12956@section Native
104c1213 12957
8e04817f
AC
12958This section describes details specific to particular native
12959configurations.
6cf7e474 12960
8e04817f
AC
12961@menu
12962* HP-UX:: HP-UX
7561d450 12963* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
12964* SVR4 Process Information:: SVR4 process information
12965* DJGPP Native:: Features specific to the DJGPP port
78c47bea 12966* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 12967* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 12968* Neutrino:: Features specific to QNX Neutrino
8e04817f 12969@end menu
6cf7e474 12970
8e04817f
AC
12971@node HP-UX
12972@subsection HP-UX
104c1213 12973
8e04817f
AC
12974On HP-UX systems, if you refer to a function or variable name that
12975begins with a dollar sign, @value{GDBN} searches for a user or system
12976name first, before it searches for a convenience variable.
104c1213 12977
9c16f35a 12978
7561d450
MK
12979@node BSD libkvm Interface
12980@subsection BSD libkvm Interface
12981
12982@cindex libkvm
12983@cindex kernel memory image
12984@cindex kernel crash dump
12985
12986BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
12987interface that provides a uniform interface for accessing kernel virtual
12988memory images, including live systems and crash dumps. @value{GDBN}
12989uses this interface to allow you to debug live kernels and kernel crash
12990dumps on many native BSD configurations. This is implemented as a
12991special @code{kvm} debugging target. For debugging a live system, load
12992the currently running kernel into @value{GDBN} and connect to the
12993@code{kvm} target:
12994
12995@smallexample
12996(@value{GDBP}) @b{target kvm}
12997@end smallexample
12998
12999For debugging crash dumps, provide the file name of the crash dump as an
13000argument:
13001
13002@smallexample
13003(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
13004@end smallexample
13005
13006Once connected to the @code{kvm} target, the following commands are
13007available:
13008
13009@table @code
13010@kindex kvm
13011@item kvm pcb
721c2651 13012Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
13013
13014@item kvm proc
13015Set current context from proc address. This command isn't available on
13016modern FreeBSD systems.
13017@end table
13018
8e04817f
AC
13019@node SVR4 Process Information
13020@subsection SVR4 process information
60bf7e09
EZ
13021@cindex /proc
13022@cindex examine process image
13023@cindex process info via @file{/proc}
104c1213 13024
60bf7e09
EZ
13025Many versions of SVR4 and compatible systems provide a facility called
13026@samp{/proc} that can be used to examine the image of a running
13027process using file-system subroutines. If @value{GDBN} is configured
13028for an operating system with this facility, the command @code{info
13029proc} is available to report information about the process running
13030your program, or about any process running on your system. @code{info
13031proc} works only on SVR4 systems that include the @code{procfs} code.
13032This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
13033Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 13034
8e04817f
AC
13035@table @code
13036@kindex info proc
60bf7e09 13037@cindex process ID
8e04817f 13038@item info proc
60bf7e09
EZ
13039@itemx info proc @var{process-id}
13040Summarize available information about any running process. If a
13041process ID is specified by @var{process-id}, display information about
13042that process; otherwise display information about the program being
13043debugged. The summary includes the debugged process ID, the command
13044line used to invoke it, its current working directory, and its
13045executable file's absolute file name.
13046
13047On some systems, @var{process-id} can be of the form
13048@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
13049within a process. If the optional @var{pid} part is missing, it means
13050a thread from the process being debugged (the leading @samp{/} still
13051needs to be present, or else @value{GDBN} will interpret the number as
13052a process ID rather than a thread ID).
6cf7e474 13053
8e04817f 13054@item info proc mappings
60bf7e09
EZ
13055@cindex memory address space mappings
13056Report the memory address space ranges accessible in the program, with
13057information on whether the process has read, write, or execute access
13058rights to each range. On @sc{gnu}/Linux systems, each memory range
13059includes the object file which is mapped to that range, instead of the
13060memory access rights to that range.
13061
13062@item info proc stat
13063@itemx info proc status
13064@cindex process detailed status information
13065These subcommands are specific to @sc{gnu}/Linux systems. They show
13066the process-related information, including the user ID and group ID;
13067how many threads are there in the process; its virtual memory usage;
13068the signals that are pending, blocked, and ignored; its TTY; its
13069consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 13070value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
13071(type @kbd{man 5 proc} from your shell prompt).
13072
13073@item info proc all
13074Show all the information about the process described under all of the
13075above @code{info proc} subcommands.
13076
8e04817f
AC
13077@ignore
13078@comment These sub-options of 'info proc' were not included when
13079@comment procfs.c was re-written. Keep their descriptions around
13080@comment against the day when someone finds the time to put them back in.
13081@kindex info proc times
13082@item info proc times
13083Starting time, user CPU time, and system CPU time for your program and
13084its children.
6cf7e474 13085
8e04817f
AC
13086@kindex info proc id
13087@item info proc id
13088Report on the process IDs related to your program: its own process ID,
13089the ID of its parent, the process group ID, and the session ID.
8e04817f 13090@end ignore
721c2651
EZ
13091
13092@item set procfs-trace
13093@kindex set procfs-trace
13094@cindex @code{procfs} API calls
13095This command enables and disables tracing of @code{procfs} API calls.
13096
13097@item show procfs-trace
13098@kindex show procfs-trace
13099Show the current state of @code{procfs} API call tracing.
13100
13101@item set procfs-file @var{file}
13102@kindex set procfs-file
13103Tell @value{GDBN} to write @code{procfs} API trace to the named
13104@var{file}. @value{GDBN} appends the trace info to the previous
13105contents of the file. The default is to display the trace on the
13106standard output.
13107
13108@item show procfs-file
13109@kindex show procfs-file
13110Show the file to which @code{procfs} API trace is written.
13111
13112@item proc-trace-entry
13113@itemx proc-trace-exit
13114@itemx proc-untrace-entry
13115@itemx proc-untrace-exit
13116@kindex proc-trace-entry
13117@kindex proc-trace-exit
13118@kindex proc-untrace-entry
13119@kindex proc-untrace-exit
13120These commands enable and disable tracing of entries into and exits
13121from the @code{syscall} interface.
13122
13123@item info pidlist
13124@kindex info pidlist
13125@cindex process list, QNX Neutrino
13126For QNX Neutrino only, this command displays the list of all the
13127processes and all the threads within each process.
13128
13129@item info meminfo
13130@kindex info meminfo
13131@cindex mapinfo list, QNX Neutrino
13132For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 13133@end table
104c1213 13134
8e04817f
AC
13135@node DJGPP Native
13136@subsection Features for Debugging @sc{djgpp} Programs
13137@cindex @sc{djgpp} debugging
13138@cindex native @sc{djgpp} debugging
13139@cindex MS-DOS-specific commands
104c1213 13140
514c4d71
EZ
13141@cindex DPMI
13142@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
13143MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
13144that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
13145top of real-mode DOS systems and their emulations.
104c1213 13146
8e04817f
AC
13147@value{GDBN} supports native debugging of @sc{djgpp} programs, and
13148defines a few commands specific to the @sc{djgpp} port. This
13149subsection describes those commands.
104c1213 13150
8e04817f
AC
13151@table @code
13152@kindex info dos
13153@item info dos
13154This is a prefix of @sc{djgpp}-specific commands which print
13155information about the target system and important OS structures.
f1251bdd 13156
8e04817f
AC
13157@kindex sysinfo
13158@cindex MS-DOS system info
13159@cindex free memory information (MS-DOS)
13160@item info dos sysinfo
13161This command displays assorted information about the underlying
13162platform: the CPU type and features, the OS version and flavor, the
13163DPMI version, and the available conventional and DPMI memory.
104c1213 13164
8e04817f
AC
13165@cindex GDT
13166@cindex LDT
13167@cindex IDT
13168@cindex segment descriptor tables
13169@cindex descriptor tables display
13170@item info dos gdt
13171@itemx info dos ldt
13172@itemx info dos idt
13173These 3 commands display entries from, respectively, Global, Local,
13174and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
13175tables are data structures which store a descriptor for each segment
13176that is currently in use. The segment's selector is an index into a
13177descriptor table; the table entry for that index holds the
13178descriptor's base address and limit, and its attributes and access
13179rights.
104c1213 13180
8e04817f
AC
13181A typical @sc{djgpp} program uses 3 segments: a code segment, a data
13182segment (used for both data and the stack), and a DOS segment (which
13183allows access to DOS/BIOS data structures and absolute addresses in
13184conventional memory). However, the DPMI host will usually define
13185additional segments in order to support the DPMI environment.
d4f3574e 13186
8e04817f
AC
13187@cindex garbled pointers
13188These commands allow to display entries from the descriptor tables.
13189Without an argument, all entries from the specified table are
13190displayed. An argument, which should be an integer expression, means
13191display a single entry whose index is given by the argument. For
13192example, here's a convenient way to display information about the
13193debugged program's data segment:
104c1213 13194
8e04817f
AC
13195@smallexample
13196@exdent @code{(@value{GDBP}) info dos ldt $ds}
13197@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
13198@end smallexample
104c1213 13199
8e04817f
AC
13200@noindent
13201This comes in handy when you want to see whether a pointer is outside
13202the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 13203
8e04817f
AC
13204@cindex page tables display (MS-DOS)
13205@item info dos pde
13206@itemx info dos pte
13207These two commands display entries from, respectively, the Page
13208Directory and the Page Tables. Page Directories and Page Tables are
13209data structures which control how virtual memory addresses are mapped
13210into physical addresses. A Page Table includes an entry for every
13211page of memory that is mapped into the program's address space; there
13212may be several Page Tables, each one holding up to 4096 entries. A
13213Page Directory has up to 4096 entries, one each for every Page Table
13214that is currently in use.
104c1213 13215
8e04817f
AC
13216Without an argument, @kbd{info dos pde} displays the entire Page
13217Directory, and @kbd{info dos pte} displays all the entries in all of
13218the Page Tables. An argument, an integer expression, given to the
13219@kbd{info dos pde} command means display only that entry from the Page
13220Directory table. An argument given to the @kbd{info dos pte} command
13221means display entries from a single Page Table, the one pointed to by
13222the specified entry in the Page Directory.
104c1213 13223
8e04817f
AC
13224@cindex direct memory access (DMA) on MS-DOS
13225These commands are useful when your program uses @dfn{DMA} (Direct
13226Memory Access), which needs physical addresses to program the DMA
13227controller.
104c1213 13228
8e04817f 13229These commands are supported only with some DPMI servers.
104c1213 13230
8e04817f
AC
13231@cindex physical address from linear address
13232@item info dos address-pte @var{addr}
13233This command displays the Page Table entry for a specified linear
514c4d71
EZ
13234address. The argument @var{addr} is a linear address which should
13235already have the appropriate segment's base address added to it,
13236because this command accepts addresses which may belong to @emph{any}
13237segment. For example, here's how to display the Page Table entry for
13238the page where a variable @code{i} is stored:
104c1213 13239
b383017d 13240@smallexample
8e04817f
AC
13241@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
13242@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 13243@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 13244@end smallexample
104c1213 13245
8e04817f
AC
13246@noindent
13247This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 13248whose physical base address is @code{0x02698000}, and shows all the
8e04817f 13249attributes of that page.
104c1213 13250
8e04817f
AC
13251Note that you must cast the addresses of variables to a @code{char *},
13252since otherwise the value of @code{__djgpp_base_address}, the base
13253address of all variables and functions in a @sc{djgpp} program, will
13254be added using the rules of C pointer arithmetics: if @code{i} is
13255declared an @code{int}, @value{GDBN} will add 4 times the value of
13256@code{__djgpp_base_address} to the address of @code{i}.
104c1213 13257
8e04817f
AC
13258Here's another example, it displays the Page Table entry for the
13259transfer buffer:
104c1213 13260
8e04817f
AC
13261@smallexample
13262@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
13263@exdent @code{Page Table entry for address 0x29110:}
13264@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
13265@end smallexample
104c1213 13266
8e04817f
AC
13267@noindent
13268(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
132693rd member of the @code{_go32_info_block} structure.) The output
13270clearly shows that this DPMI server maps the addresses in conventional
13271memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
13272linear (@code{0x29110}) addresses are identical.
104c1213 13273
8e04817f
AC
13274This command is supported only with some DPMI servers.
13275@end table
104c1213 13276
c45da7e6 13277@cindex DOS serial data link, remote debugging
a8f24a35
EZ
13278In addition to native debugging, the DJGPP port supports remote
13279debugging via a serial data link. The following commands are specific
13280to remote serial debugging in the DJGPP port of @value{GDBN}.
13281
13282@table @code
13283@kindex set com1base
13284@kindex set com1irq
13285@kindex set com2base
13286@kindex set com2irq
13287@kindex set com3base
13288@kindex set com3irq
13289@kindex set com4base
13290@kindex set com4irq
13291@item set com1base @var{addr}
13292This command sets the base I/O port address of the @file{COM1} serial
13293port.
13294
13295@item set com1irq @var{irq}
13296This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
13297for the @file{COM1} serial port.
13298
13299There are similar commands @samp{set com2base}, @samp{set com3irq},
13300etc.@: for setting the port address and the @code{IRQ} lines for the
13301other 3 COM ports.
13302
13303@kindex show com1base
13304@kindex show com1irq
13305@kindex show com2base
13306@kindex show com2irq
13307@kindex show com3base
13308@kindex show com3irq
13309@kindex show com4base
13310@kindex show com4irq
13311The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
13312display the current settings of the base address and the @code{IRQ}
13313lines used by the COM ports.
c45da7e6
EZ
13314
13315@item info serial
13316@kindex info serial
13317@cindex DOS serial port status
13318This command prints the status of the 4 DOS serial ports. For each
13319port, it prints whether it's active or not, its I/O base address and
13320IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
13321counts of various errors encountered so far.
a8f24a35
EZ
13322@end table
13323
13324
78c47bea
PM
13325@node Cygwin Native
13326@subsection Features for Debugging MS Windows PE executables
13327@cindex MS Windows debugging
13328@cindex native Cygwin debugging
13329@cindex Cygwin-specific commands
13330
be448670
CF
13331@value{GDBN} supports native debugging of MS Windows programs, including
13332DLLs with and without symbolic debugging information. There are various
13333additional Cygwin-specific commands, described in this subsection. The
13334subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
13335that have no debugging symbols.
13336
78c47bea
PM
13337
13338@table @code
13339@kindex info w32
13340@item info w32
13341This is a prefix of MS Windows specific commands which print
13342information about the target system and important OS structures.
13343
13344@item info w32 selector
13345This command displays information returned by
13346the Win32 API @code{GetThreadSelectorEntry} function.
13347It takes an optional argument that is evaluated to
13348a long value to give the information about this given selector.
13349Without argument, this command displays information
13350about the the six segment registers.
13351
13352@kindex info dll
13353@item info dll
13354This is a Cygwin specific alias of info shared.
13355
13356@kindex dll-symbols
13357@item dll-symbols
13358This command loads symbols from a dll similarly to
13359add-sym command but without the need to specify a base address.
13360
b383017d 13361@kindex set new-console
78c47bea 13362@item set new-console @var{mode}
b383017d 13363If @var{mode} is @code{on} the debuggee will
78c47bea
PM
13364be started in a new console on next start.
13365If @var{mode} is @code{off}i, the debuggee will
13366be started in the same console as the debugger.
13367
13368@kindex show new-console
13369@item show new-console
13370Displays whether a new console is used
13371when the debuggee is started.
13372
13373@kindex set new-group
13374@item set new-group @var{mode}
13375This boolean value controls whether the debuggee should
13376start a new group or stay in the same group as the debugger.
13377This affects the way the Windows OS handles
13378Ctrl-C.
13379
13380@kindex show new-group
13381@item show new-group
13382Displays current value of new-group boolean.
13383
13384@kindex set debugevents
13385@item set debugevents
13386This boolean value adds debug output concerning events seen by the debugger.
13387
13388@kindex set debugexec
13389@item set debugexec
b383017d 13390This boolean value adds debug output concerning execute events
78c47bea
PM
13391seen by the debugger.
13392
13393@kindex set debugexceptions
13394@item set debugexceptions
b383017d 13395This boolean value adds debug ouptut concerning exception events
78c47bea
PM
13396seen by the debugger.
13397
13398@kindex set debugmemory
13399@item set debugmemory
b383017d 13400This boolean value adds debug ouptut concerning memory events
78c47bea
PM
13401seen by the debugger.
13402
13403@kindex set shell
13404@item set shell
13405This boolean values specifies whether the debuggee is called
13406via a shell or directly (default value is on).
13407
13408@kindex show shell
13409@item show shell
13410Displays if the debuggee will be started with a shell.
13411
13412@end table
13413
be448670
CF
13414@menu
13415* Non-debug DLL symbols:: Support for DLLs without debugging symbols
13416@end menu
13417
13418@node Non-debug DLL symbols
13419@subsubsection Support for DLLs without debugging symbols
13420@cindex DLLs with no debugging symbols
13421@cindex Minimal symbols and DLLs
13422
13423Very often on windows, some of the DLLs that your program relies on do
13424not include symbolic debugging information (for example,
13425@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
13426symbols in a DLL, it relies on the minimal amount of symbolic
13427information contained in the DLL's export table. This subsubsection
13428describes working with such symbols, known internally to @value{GDBN} as
13429``minimal symbols''.
13430
13431Note that before the debugged program has started execution, no DLLs
13432will have been loaded. The easiest way around this problem is simply to
13433start the program --- either by setting a breakpoint or letting the
13434program run once to completion. It is also possible to force
13435@value{GDBN} to load a particular DLL before starting the executable ---
13436see the shared library information in @pxref{Files} or the
13437@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
13438explicitly loading symbols from a DLL with no debugging information will
13439cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
13440which may adversely affect symbol lookup performance.
13441
13442@subsubsection DLL name prefixes
13443
13444In keeping with the naming conventions used by the Microsoft debugging
13445tools, DLL export symbols are made available with a prefix based on the
13446DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
13447also entered into the symbol table, so @code{CreateFileA} is often
13448sufficient. In some cases there will be name clashes within a program
13449(particularly if the executable itself includes full debugging symbols)
13450necessitating the use of the fully qualified name when referring to the
13451contents of the DLL. Use single-quotes around the name to avoid the
13452exclamation mark (``!'') being interpreted as a language operator.
13453
13454Note that the internal name of the DLL may be all upper-case, even
13455though the file name of the DLL is lower-case, or vice-versa. Since
13456symbols within @value{GDBN} are @emph{case-sensitive} this may cause
13457some confusion. If in doubt, try the @code{info functions} and
13458@code{info variables} commands or even @code{maint print msymbols} (see
13459@pxref{Symbols}). Here's an example:
13460
13461@smallexample
f7dc1244 13462(@value{GDBP}) info function CreateFileA
be448670
CF
13463All functions matching regular expression "CreateFileA":
13464
13465Non-debugging symbols:
134660x77e885f4 CreateFileA
134670x77e885f4 KERNEL32!CreateFileA
13468@end smallexample
13469
13470@smallexample
f7dc1244 13471(@value{GDBP}) info function !
be448670
CF
13472All functions matching regular expression "!":
13473
13474Non-debugging symbols:
134750x6100114c cygwin1!__assert
134760x61004034 cygwin1!_dll_crt0@@0
134770x61004240 cygwin1!dll_crt0(per_process *)
13478[etc...]
13479@end smallexample
13480
13481@subsubsection Working with minimal symbols
13482
13483Symbols extracted from a DLL's export table do not contain very much
13484type information. All that @value{GDBN} can do is guess whether a symbol
13485refers to a function or variable depending on the linker section that
13486contains the symbol. Also note that the actual contents of the memory
13487contained in a DLL are not available unless the program is running. This
13488means that you cannot examine the contents of a variable or disassemble
13489a function within a DLL without a running program.
13490
13491Variables are generally treated as pointers and dereferenced
13492automatically. For this reason, it is often necessary to prefix a
13493variable name with the address-of operator (``&'') and provide explicit
13494type information in the command. Here's an example of the type of
13495problem:
13496
13497@smallexample
f7dc1244 13498(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
13499$1 = 268572168
13500@end smallexample
13501
13502@smallexample
f7dc1244 13503(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
135040x10021610: "\230y\""
13505@end smallexample
13506
13507And two possible solutions:
13508
13509@smallexample
f7dc1244 13510(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
13511$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
13512@end smallexample
13513
13514@smallexample
f7dc1244 13515(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 135160x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 13517(@value{GDBP}) x/x 0x10021608
be448670 135180x10021608: 0x0022fd98
f7dc1244 13519(@value{GDBP}) x/s 0x0022fd98
be448670
CF
135200x22fd98: "/cygdrive/c/mydirectory/myprogram"
13521@end smallexample
13522
13523Setting a break point within a DLL is possible even before the program
13524starts execution. However, under these circumstances, @value{GDBN} can't
13525examine the initial instructions of the function in order to skip the
13526function's frame set-up code. You can work around this by using ``*&''
13527to set the breakpoint at a raw memory address:
13528
13529@smallexample
f7dc1244 13530(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
13531Breakpoint 1 at 0x1e04eff0
13532@end smallexample
13533
13534The author of these extensions is not entirely convinced that setting a
13535break point within a shared DLL like @file{kernel32.dll} is completely
13536safe.
13537
14d6dd68
EZ
13538@node Hurd Native
13539@subsection Commands specific to @sc{gnu} Hurd systems
13540@cindex @sc{gnu} Hurd debugging
13541
13542This subsection describes @value{GDBN} commands specific to the
13543@sc{gnu} Hurd native debugging.
13544
13545@table @code
13546@item set signals
13547@itemx set sigs
13548@kindex set signals@r{, Hurd command}
13549@kindex set sigs@r{, Hurd command}
13550This command toggles the state of inferior signal interception by
13551@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
13552affected by this command. @code{sigs} is a shorthand alias for
13553@code{signals}.
13554
13555@item show signals
13556@itemx show sigs
13557@kindex show signals@r{, Hurd command}
13558@kindex show sigs@r{, Hurd command}
13559Show the current state of intercepting inferior's signals.
13560
13561@item set signal-thread
13562@itemx set sigthread
13563@kindex set signal-thread
13564@kindex set sigthread
13565This command tells @value{GDBN} which thread is the @code{libc} signal
13566thread. That thread is run when a signal is delivered to a running
13567process. @code{set sigthread} is the shorthand alias of @code{set
13568signal-thread}.
13569
13570@item show signal-thread
13571@itemx show sigthread
13572@kindex show signal-thread
13573@kindex show sigthread
13574These two commands show which thread will run when the inferior is
13575delivered a signal.
13576
13577@item set stopped
13578@kindex set stopped@r{, Hurd command}
13579This commands tells @value{GDBN} that the inferior process is stopped,
13580as with the @code{SIGSTOP} signal. The stopped process can be
13581continued by delivering a signal to it.
13582
13583@item show stopped
13584@kindex show stopped@r{, Hurd command}
13585This command shows whether @value{GDBN} thinks the debuggee is
13586stopped.
13587
13588@item set exceptions
13589@kindex set exceptions@r{, Hurd command}
13590Use this command to turn off trapping of exceptions in the inferior.
13591When exception trapping is off, neither breakpoints nor
13592single-stepping will work. To restore the default, set exception
13593trapping on.
13594
13595@item show exceptions
13596@kindex show exceptions@r{, Hurd command}
13597Show the current state of trapping exceptions in the inferior.
13598
13599@item set task pause
13600@kindex set task@r{, Hurd commands}
13601@cindex task attributes (@sc{gnu} Hurd)
13602@cindex pause current task (@sc{gnu} Hurd)
13603This command toggles task suspension when @value{GDBN} has control.
13604Setting it to on takes effect immediately, and the task is suspended
13605whenever @value{GDBN} gets control. Setting it to off will take
13606effect the next time the inferior is continued. If this option is set
13607to off, you can use @code{set thread default pause on} or @code{set
13608thread pause on} (see below) to pause individual threads.
13609
13610@item show task pause
13611@kindex show task@r{, Hurd commands}
13612Show the current state of task suspension.
13613
13614@item set task detach-suspend-count
13615@cindex task suspend count
13616@cindex detach from task, @sc{gnu} Hurd
13617This command sets the suspend count the task will be left with when
13618@value{GDBN} detaches from it.
13619
13620@item show task detach-suspend-count
13621Show the suspend count the task will be left with when detaching.
13622
13623@item set task exception-port
13624@itemx set task excp
13625@cindex task exception port, @sc{gnu} Hurd
13626This command sets the task exception port to which @value{GDBN} will
13627forward exceptions. The argument should be the value of the @dfn{send
13628rights} of the task. @code{set task excp} is a shorthand alias.
13629
13630@item set noninvasive
13631@cindex noninvasive task options
13632This command switches @value{GDBN} to a mode that is the least
13633invasive as far as interfering with the inferior is concerned. This
13634is the same as using @code{set task pause}, @code{set exceptions}, and
13635@code{set signals} to values opposite to the defaults.
13636
13637@item info send-rights
13638@itemx info receive-rights
13639@itemx info port-rights
13640@itemx info port-sets
13641@itemx info dead-names
13642@itemx info ports
13643@itemx info psets
13644@cindex send rights, @sc{gnu} Hurd
13645@cindex receive rights, @sc{gnu} Hurd
13646@cindex port rights, @sc{gnu} Hurd
13647@cindex port sets, @sc{gnu} Hurd
13648@cindex dead names, @sc{gnu} Hurd
13649These commands display information about, respectively, send rights,
13650receive rights, port rights, port sets, and dead names of a task.
13651There are also shorthand aliases: @code{info ports} for @code{info
13652port-rights} and @code{info psets} for @code{info port-sets}.
13653
13654@item set thread pause
13655@kindex set thread@r{, Hurd command}
13656@cindex thread properties, @sc{gnu} Hurd
13657@cindex pause current thread (@sc{gnu} Hurd)
13658This command toggles current thread suspension when @value{GDBN} has
13659control. Setting it to on takes effect immediately, and the current
13660thread is suspended whenever @value{GDBN} gets control. Setting it to
13661off will take effect the next time the inferior is continued.
13662Normally, this command has no effect, since when @value{GDBN} has
13663control, the whole task is suspended. However, if you used @code{set
13664task pause off} (see above), this command comes in handy to suspend
13665only the current thread.
13666
13667@item show thread pause
13668@kindex show thread@r{, Hurd command}
13669This command shows the state of current thread suspension.
13670
13671@item set thread run
13672This comamnd sets whether the current thread is allowed to run.
13673
13674@item show thread run
13675Show whether the current thread is allowed to run.
13676
13677@item set thread detach-suspend-count
13678@cindex thread suspend count, @sc{gnu} Hurd
13679@cindex detach from thread, @sc{gnu} Hurd
13680This command sets the suspend count @value{GDBN} will leave on a
13681thread when detaching. This number is relative to the suspend count
13682found by @value{GDBN} when it notices the thread; use @code{set thread
13683takeover-suspend-count} to force it to an absolute value.
13684
13685@item show thread detach-suspend-count
13686Show the suspend count @value{GDBN} will leave on the thread when
13687detaching.
13688
13689@item set thread exception-port
13690@itemx set thread excp
13691Set the thread exception port to which to forward exceptions. This
13692overrides the port set by @code{set task exception-port} (see above).
13693@code{set thread excp} is the shorthand alias.
13694
13695@item set thread takeover-suspend-count
13696Normally, @value{GDBN}'s thread suspend counts are relative to the
13697value @value{GDBN} finds when it notices each thread. This command
13698changes the suspend counts to be absolute instead.
13699
13700@item set thread default
13701@itemx show thread default
13702@cindex thread default settings, @sc{gnu} Hurd
13703Each of the above @code{set thread} commands has a @code{set thread
13704default} counterpart (e.g., @code{set thread default pause}, @code{set
13705thread default exception-port}, etc.). The @code{thread default}
13706variety of commands sets the default thread properties for all
13707threads; you can then change the properties of individual threads with
13708the non-default commands.
13709@end table
13710
13711
a64548ea
EZ
13712@node Neutrino
13713@subsection QNX Neutrino
13714@cindex QNX Neutrino
13715
13716@value{GDBN} provides the following commands specific to the QNX
13717Neutrino target:
13718
13719@table @code
13720@item set debug nto-debug
13721@kindex set debug nto-debug
13722When set to on, enables debugging messages specific to the QNX
13723Neutrino support.
13724
13725@item show debug nto-debug
13726@kindex show debug nto-debug
13727Show the current state of QNX Neutrino messages.
13728@end table
13729
13730
8e04817f
AC
13731@node Embedded OS
13732@section Embedded Operating Systems
104c1213 13733
8e04817f
AC
13734This section describes configurations involving the debugging of
13735embedded operating systems that are available for several different
13736architectures.
d4f3574e 13737
8e04817f
AC
13738@menu
13739* VxWorks:: Using @value{GDBN} with VxWorks
13740@end menu
104c1213 13741
8e04817f
AC
13742@value{GDBN} includes the ability to debug programs running on
13743various real-time operating systems.
104c1213 13744
8e04817f
AC
13745@node VxWorks
13746@subsection Using @value{GDBN} with VxWorks
104c1213 13747
8e04817f 13748@cindex VxWorks
104c1213 13749
8e04817f 13750@table @code
104c1213 13751
8e04817f
AC
13752@kindex target vxworks
13753@item target vxworks @var{machinename}
13754A VxWorks system, attached via TCP/IP. The argument @var{machinename}
13755is the target system's machine name or IP address.
104c1213 13756
8e04817f 13757@end table
104c1213 13758
8e04817f
AC
13759On VxWorks, @code{load} links @var{filename} dynamically on the
13760current target system as well as adding its symbols in @value{GDBN}.
104c1213 13761
8e04817f
AC
13762@value{GDBN} enables developers to spawn and debug tasks running on networked
13763VxWorks targets from a Unix host. Already-running tasks spawned from
13764the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
13765both the Unix host and on the VxWorks target. The program
13766@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
13767installed with the name @code{vxgdb}, to distinguish it from a
13768@value{GDBN} for debugging programs on the host itself.)
104c1213 13769
8e04817f
AC
13770@table @code
13771@item VxWorks-timeout @var{args}
13772@kindex vxworks-timeout
13773All VxWorks-based targets now support the option @code{vxworks-timeout}.
13774This option is set by the user, and @var{args} represents the number of
13775seconds @value{GDBN} waits for responses to rpc's. You might use this if
13776your VxWorks target is a slow software simulator or is on the far side
13777of a thin network line.
13778@end table
104c1213 13779
8e04817f
AC
13780The following information on connecting to VxWorks was current when
13781this manual was produced; newer releases of VxWorks may use revised
13782procedures.
104c1213 13783
4644b6e3 13784@findex INCLUDE_RDB
8e04817f
AC
13785To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
13786to include the remote debugging interface routines in the VxWorks
13787library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
13788VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
13789kernel. The resulting kernel contains @file{rdb.a}, and spawns the
13790source debugging task @code{tRdbTask} when VxWorks is booted. For more
13791information on configuring and remaking VxWorks, see the manufacturer's
13792manual.
13793@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 13794
8e04817f
AC
13795Once you have included @file{rdb.a} in your VxWorks system image and set
13796your Unix execution search path to find @value{GDBN}, you are ready to
13797run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
13798@code{vxgdb}, depending on your installation).
104c1213 13799
8e04817f 13800@value{GDBN} comes up showing the prompt:
104c1213 13801
474c8240 13802@smallexample
8e04817f 13803(vxgdb)
474c8240 13804@end smallexample
104c1213 13805
8e04817f
AC
13806@menu
13807* VxWorks Connection:: Connecting to VxWorks
13808* VxWorks Download:: VxWorks download
13809* VxWorks Attach:: Running tasks
13810@end menu
104c1213 13811
8e04817f
AC
13812@node VxWorks Connection
13813@subsubsection Connecting to VxWorks
104c1213 13814
8e04817f
AC
13815The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
13816network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 13817
474c8240 13818@smallexample
8e04817f 13819(vxgdb) target vxworks tt
474c8240 13820@end smallexample
104c1213 13821
8e04817f
AC
13822@need 750
13823@value{GDBN} displays messages like these:
104c1213 13824
8e04817f
AC
13825@smallexample
13826Attaching remote machine across net...
13827Connected to tt.
13828@end smallexample
104c1213 13829
8e04817f
AC
13830@need 1000
13831@value{GDBN} then attempts to read the symbol tables of any object modules
13832loaded into the VxWorks target since it was last booted. @value{GDBN} locates
13833these files by searching the directories listed in the command search
13834path (@pxref{Environment, ,Your program's environment}); if it fails
13835to find an object file, it displays a message such as:
5d161b24 13836
474c8240 13837@smallexample
8e04817f 13838prog.o: No such file or directory.
474c8240 13839@end smallexample
104c1213 13840
8e04817f
AC
13841When this happens, add the appropriate directory to the search path with
13842the @value{GDBN} command @code{path}, and execute the @code{target}
13843command again.
104c1213 13844
8e04817f
AC
13845@node VxWorks Download
13846@subsubsection VxWorks download
104c1213 13847
8e04817f
AC
13848@cindex download to VxWorks
13849If you have connected to the VxWorks target and you want to debug an
13850object that has not yet been loaded, you can use the @value{GDBN}
13851@code{load} command to download a file from Unix to VxWorks
13852incrementally. The object file given as an argument to the @code{load}
13853command is actually opened twice: first by the VxWorks target in order
13854to download the code, then by @value{GDBN} in order to read the symbol
13855table. This can lead to problems if the current working directories on
13856the two systems differ. If both systems have NFS mounted the same
13857filesystems, you can avoid these problems by using absolute paths.
13858Otherwise, it is simplest to set the working directory on both systems
13859to the directory in which the object file resides, and then to reference
13860the file by its name, without any path. For instance, a program
13861@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
13862and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
13863program, type this on VxWorks:
104c1213 13864
474c8240 13865@smallexample
8e04817f 13866-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 13867@end smallexample
104c1213 13868
8e04817f
AC
13869@noindent
13870Then, in @value{GDBN}, type:
104c1213 13871
474c8240 13872@smallexample
8e04817f
AC
13873(vxgdb) cd @var{hostpath}/vw/demo/rdb
13874(vxgdb) load prog.o
474c8240 13875@end smallexample
104c1213 13876
8e04817f 13877@value{GDBN} displays a response similar to this:
104c1213 13878
8e04817f
AC
13879@smallexample
13880Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
13881@end smallexample
104c1213 13882
8e04817f
AC
13883You can also use the @code{load} command to reload an object module
13884after editing and recompiling the corresponding source file. Note that
13885this makes @value{GDBN} delete all currently-defined breakpoints,
13886auto-displays, and convenience variables, and to clear the value
13887history. (This is necessary in order to preserve the integrity of
13888debugger's data structures that reference the target system's symbol
13889table.)
104c1213 13890
8e04817f
AC
13891@node VxWorks Attach
13892@subsubsection Running tasks
104c1213
JM
13893
13894@cindex running VxWorks tasks
13895You can also attach to an existing task using the @code{attach} command as
13896follows:
13897
474c8240 13898@smallexample
104c1213 13899(vxgdb) attach @var{task}
474c8240 13900@end smallexample
104c1213
JM
13901
13902@noindent
13903where @var{task} is the VxWorks hexadecimal task ID. The task can be running
13904or suspended when you attach to it. Running tasks are suspended at
13905the time of attachment.
13906
6d2ebf8b 13907@node Embedded Processors
104c1213
JM
13908@section Embedded Processors
13909
13910This section goes into details specific to particular embedded
13911configurations.
13912
c45da7e6
EZ
13913@cindex send command to simulator
13914Whenever a specific embedded processor has a simulator, @value{GDBN}
13915allows to send an arbitrary command to the simulator.
13916
13917@table @code
13918@item sim @var{command}
13919@kindex sim@r{, a command}
13920Send an arbitrary @var{command} string to the simulator. Consult the
13921documentation for the specific simulator in use for information about
13922acceptable commands.
13923@end table
13924
7d86b5d5 13925
104c1213 13926@menu
c45da7e6 13927* ARM:: ARM RDI
172c2a43
KI
13928* H8/300:: Renesas H8/300
13929* H8/500:: Renesas H8/500
13930* M32R/D:: Renesas M32R/D
104c1213 13931* M68K:: Motorola M68K
104c1213 13932* MIPS Embedded:: MIPS Embedded
a37295f9 13933* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
13934* PA:: HP PA Embedded
13935* PowerPC: PowerPC
172c2a43 13936* SH:: Renesas SH
104c1213
JM
13937* Sparclet:: Tsqware Sparclet
13938* Sparclite:: Fujitsu Sparclite
13939* ST2000:: Tandem ST2000
13940* Z8000:: Zilog Z8000
a64548ea
EZ
13941* AVR:: Atmel AVR
13942* CRIS:: CRIS
13943* Super-H:: Renesas Super-H
c45da7e6 13944* WinCE:: Windows CE child processes
104c1213
JM
13945@end menu
13946
6d2ebf8b 13947@node ARM
104c1213 13948@subsection ARM
c45da7e6 13949@cindex ARM RDI
104c1213
JM
13950
13951@table @code
8e04817f
AC
13952@kindex target rdi
13953@item target rdi @var{dev}
13954ARM Angel monitor, via RDI library interface to ADP protocol. You may
13955use this target to communicate with both boards running the Angel
13956monitor, or with the EmbeddedICE JTAG debug device.
13957
13958@kindex target rdp
13959@item target rdp @var{dev}
13960ARM Demon monitor.
13961
13962@end table
13963
e2f4edfd
EZ
13964@value{GDBN} provides the following ARM-specific commands:
13965
13966@table @code
13967@item set arm disassembler
13968@kindex set arm
13969This commands selects from a list of disassembly styles. The
13970@code{"std"} style is the standard style.
13971
13972@item show arm disassembler
13973@kindex show arm
13974Show the current disassembly style.
13975
13976@item set arm apcs32
13977@cindex ARM 32-bit mode
13978This command toggles ARM operation mode between 32-bit and 26-bit.
13979
13980@item show arm apcs32
13981Display the current usage of the ARM 32-bit mode.
13982
13983@item set arm fpu @var{fputype}
13984This command sets the ARM floating-point unit (FPU) type. The
13985argument @var{fputype} can be one of these:
13986
13987@table @code
13988@item auto
13989Determine the FPU type by querying the OS ABI.
13990@item softfpa
13991Software FPU, with mixed-endian doubles on little-endian ARM
13992processors.
13993@item fpa
13994GCC-compiled FPA co-processor.
13995@item softvfp
13996Software FPU with pure-endian doubles.
13997@item vfp
13998VFP co-processor.
13999@end table
14000
14001@item show arm fpu
14002Show the current type of the FPU.
14003
14004@item set arm abi
14005This command forces @value{GDBN} to use the specified ABI.
14006
14007@item show arm abi
14008Show the currently used ABI.
14009
14010@item set debug arm
14011Toggle whether to display ARM-specific debugging messages from the ARM
14012target support subsystem.
14013
14014@item show debug arm
14015Show whether ARM-specific debugging messages are enabled.
14016@end table
14017
c45da7e6
EZ
14018The following commands are available when an ARM target is debugged
14019using the RDI interface:
14020
14021@table @code
14022@item rdilogfile @r{[}@var{file}@r{]}
14023@kindex rdilogfile
14024@cindex ADP (Angel Debugger Protocol) logging
14025Set the filename for the ADP (Angel Debugger Protocol) packet log.
14026With an argument, sets the log file to the specified @var{file}. With
14027no argument, show the current log file name. The default log file is
14028@file{rdi.log}.
14029
14030@item rdilogenable @r{[}@var{arg}@r{]}
14031@kindex rdilogenable
14032Control logging of ADP packets. With an argument of 1 or @code{"yes"}
14033enables logging, with an argument 0 or @code{"no"} disables it. With
14034no arguments displays the current setting. When logging is enabled,
14035ADP packets exchanged between @value{GDBN} and the RDI target device
14036are logged to a file.
14037
14038@item set rdiromatzero
14039@kindex set rdiromatzero
14040@cindex ROM at zero address, RDI
14041Tell @value{GDBN} whether the target has ROM at address 0. If on,
14042vector catching is disabled, so that zero address can be used. If off
14043(the default), vector catching is enabled. For this command to take
14044effect, it needs to be invoked prior to the @code{target rdi} command.
14045
14046@item show rdiromatzero
14047@kindex show rdiromatzero
14048Show the current setting of ROM at zero address.
14049
14050@item set rdiheartbeat
14051@kindex set rdiheartbeat
14052@cindex RDI heartbeat
14053Enable or disable RDI heartbeat packets. It is not recommended to
14054turn on this option, since it confuses ARM and EPI JTAG interface, as
14055well as the Angel monitor.
14056
14057@item show rdiheartbeat
14058@kindex show rdiheartbeat
14059Show the setting of RDI heartbeat packets.
14060@end table
14061
e2f4edfd 14062
8e04817f 14063@node H8/300
172c2a43 14064@subsection Renesas H8/300
8e04817f
AC
14065
14066@table @code
14067
14068@kindex target hms@r{, with H8/300}
14069@item target hms @var{dev}
172c2a43 14070A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
14071Use special commands @code{device} and @code{speed} to control the serial
14072line and the communications speed used.
14073
14074@kindex target e7000@r{, with H8/300}
14075@item target e7000 @var{dev}
172c2a43 14076E7000 emulator for Renesas H8 and SH.
8e04817f
AC
14077
14078@kindex target sh3@r{, with H8/300}
14079@kindex target sh3e@r{, with H8/300}
14080@item target sh3 @var{dev}
14081@itemx target sh3e @var{dev}
172c2a43 14082Renesas SH-3 and SH-3E target systems.
8e04817f
AC
14083
14084@end table
14085
14086@cindex download to H8/300 or H8/500
14087@cindex H8/300 or H8/500 download
172c2a43
KI
14088@cindex download to Renesas SH
14089@cindex Renesas SH download
14090When you select remote debugging to a Renesas SH, H8/300, or H8/500
14091board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
14092board and also opens it as the current executable target for
14093@value{GDBN} on your host (like the @code{file} command).
14094
14095@value{GDBN} needs to know these things to talk to your
172c2a43 14096Renesas SH, H8/300, or H8/500:
8e04817f
AC
14097
14098@enumerate
14099@item
14100that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
14101for Renesas microprocessors, or @samp{target e7000}, the in-circuit
14102emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
14103the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
14104H8/300, or H8/500.)
14105
14106@item
172c2a43 14107what serial device connects your host to your Renesas board (the first
8e04817f
AC
14108serial device available on your host is the default).
14109
14110@item
14111what speed to use over the serial device.
14112@end enumerate
14113
14114@menu
172c2a43
KI
14115* Renesas Boards:: Connecting to Renesas boards.
14116* Renesas ICE:: Using the E7000 In-Circuit Emulator.
14117* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
14118@end menu
14119
172c2a43
KI
14120@node Renesas Boards
14121@subsubsection Connecting to Renesas boards
8e04817f
AC
14122
14123@c only for Unix hosts
14124@kindex device
172c2a43 14125@cindex serial device, Renesas micros
8e04817f
AC
14126Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
14127need to explicitly set the serial device. The default @var{port} is the
14128first available port on your host. This is only necessary on Unix
14129hosts, where it is typically something like @file{/dev/ttya}.
14130
14131@kindex speed
172c2a43 14132@cindex serial line speed, Renesas micros
8e04817f
AC
14133@code{@value{GDBN}} has another special command to set the communications
14134speed: @samp{speed @var{bps}}. This command also is only used from Unix
14135hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
14136the DOS @code{mode} command (for instance,
14137@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
14138
14139The @samp{device} and @samp{speed} commands are available only when you
172c2a43 14140use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
14141use a DOS host,
14142@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
14143called @code{asynctsr} to communicate with the development board
14144through a PC serial port. You must also use the DOS @code{mode} command
14145to set up the serial port on the DOS side.
14146
14147The following sample session illustrates the steps needed to start a
14148program under @value{GDBN} control on an H8/300. The example uses a
14149sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 14150the Renesas SH and the H8/500.
8e04817f
AC
14151
14152First hook up your development board. In this example, we use a
14153board attached to serial port @code{COM2}; if you use a different serial
14154port, substitute its name in the argument of the @code{mode} command.
14155When you call @code{asynctsr}, the auxiliary comms program used by the
14156debugger, you give it just the numeric part of the serial port's name;
14157for example, @samp{asyncstr 2} below runs @code{asyncstr} on
14158@code{COM2}.
14159
474c8240 14160@smallexample
8e04817f
AC
14161C:\H8300\TEST> asynctsr 2
14162C:\H8300\TEST> mode com2:9600,n,8,1,p
14163
14164Resident portion of MODE loaded
14165
14166COM2: 9600, n, 8, 1, p
14167
474c8240 14168@end smallexample
8e04817f
AC
14169
14170@quotation
14171@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
14172@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
14173disable it, or even boot without it, to use @code{asynctsr} to control
14174your development board.
14175@end quotation
14176
14177@kindex target hms@r{, and serial protocol}
14178Now that serial communications are set up, and the development board is
9c16f35a 14179connected, you can start up @value{GDBN}. Call @code{@value{GDBN}} with
8e04817f
AC
14180the name of your program as the argument. @code{@value{GDBN}} prompts
14181you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
14182commands to begin your debugging session: @samp{target hms} to specify
172c2a43 14183cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
14184download your program to the board. @code{load} displays the names of
14185the program's sections, and a @samp{*} for each 2K of data downloaded.
14186(If you want to refresh @value{GDBN} data on symbols or on the
14187executable file without downloading, use the @value{GDBN} commands
14188@code{file} or @code{symbol-file}. These commands, and @code{load}
14189itself, are described in @ref{Files,,Commands to specify files}.)
14190
14191@smallexample
14192(eg-C:\H8300\TEST) @value{GDBP} t.x
14193@value{GDBN} is free software and you are welcome to distribute copies
14194 of it under certain conditions; type "show copying" to see
14195 the conditions.
14196There is absolutely no warranty for @value{GDBN}; type "show warranty"
14197for details.
14198@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
14199(@value{GDBP}) target hms
14200Connected to remote H8/300 HMS system.
14201(@value{GDBP}) load t.x
14202.text : 0x8000 .. 0xabde ***********
14203.data : 0xabde .. 0xad30 *
14204.stack : 0xf000 .. 0xf014 *
14205@end smallexample
14206
14207At this point, you're ready to run or debug your program. From here on,
14208you can use all the usual @value{GDBN} commands. The @code{break} command
14209sets breakpoints; the @code{run} command starts your program;
14210@code{print} or @code{x} display data; the @code{continue} command
14211resumes execution after stopping at a breakpoint. You can use the
14212@code{help} command at any time to find out more about @value{GDBN} commands.
14213
14214Remember, however, that @emph{operating system} facilities aren't
14215available on your development board; for example, if your program hangs,
14216you can't send an interrupt---but you can press the @sc{reset} switch!
14217
14218Use the @sc{reset} button on the development board
14219@itemize @bullet
14220@item
14221to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
14222no way to pass an interrupt signal to the development board); and
14223
14224@item
14225to return to the @value{GDBN} command prompt after your program finishes
14226normally. The communications protocol provides no other way for @value{GDBN}
14227to detect program completion.
14228@end itemize
14229
14230In either case, @value{GDBN} sees the effect of a @sc{reset} on the
14231development board as a ``normal exit'' of your program.
14232
172c2a43 14233@node Renesas ICE
8e04817f
AC
14234@subsubsection Using the E7000 in-circuit emulator
14235
172c2a43 14236@kindex target e7000@r{, with Renesas ICE}
8e04817f 14237You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 14238Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
14239e7000} command to connect @value{GDBN} to your E7000:
14240
14241@table @code
14242@item target e7000 @var{port} @var{speed}
14243Use this form if your E7000 is connected to a serial port. The
14244@var{port} argument identifies what serial port to use (for example,
14245@samp{com2}). The third argument is the line speed in bits per second
14246(for example, @samp{9600}).
14247
14248@item target e7000 @var{hostname}
14249If your E7000 is installed as a host on a TCP/IP network, you can just
14250specify its hostname; @value{GDBN} uses @code{telnet} to connect.
14251@end table
14252
ba04e063
EZ
14253The following special commands are available when debugging with the
14254Renesas E7000 ICE:
14255
14256@table @code
14257@item e7000 @var{command}
14258@kindex e7000
14259@cindex send command to E7000 monitor
14260This sends the specified @var{command} to the E7000 monitor.
14261
14262@item ftplogin @var{machine} @var{username} @var{password} @var{dir}
14263@kindex ftplogin@r{, E7000}
14264This command records information for subsequent interface with the
14265E7000 monitor via the FTP protocol: @value{GDBN} will log into the
14266named @var{machine} using specified @var{username} and @var{password},
14267and then chdir to the named directory @var{dir}.
14268
14269@item ftpload @var{file}
14270@kindex ftpload@r{, E7000}
14271This command uses credentials recorded by @code{ftplogin} to fetch and
14272load the named @var{file} from the E7000 monitor.
14273
14274@item drain
14275@kindex drain@r{, E7000}
14276This command drains any pending text buffers stored on the E7000.
14277
14278@item set usehardbreakpoints
14279@itemx show usehardbreakpoints
14280@kindex set usehardbreakpoints@r{, E7000}
14281@kindex show usehardbreakpoints@r{, E7000}
14282@cindex hardware breakpoints, and E7000
14283These commands set and show the use of hardware breakpoints for all
14284breakpoints. @xref{Set Breaks, hardware-assisted breakpoint}, for
14285more information about using hardware breakpoints selectively.
14286@end table
14287
172c2a43
KI
14288@node Renesas Special
14289@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
14290
14291Some @value{GDBN} commands are available only for the H8/300:
14292
14293@table @code
14294
14295@kindex set machine
14296@kindex show machine
14297@item set machine h8300
14298@itemx set machine h8300h
14299Condition @value{GDBN} for one of the two variants of the H8/300
14300architecture with @samp{set machine}. You can use @samp{show machine}
14301to check which variant is currently in effect.
104c1213
JM
14302
14303@end table
14304
8e04817f
AC
14305@node H8/500
14306@subsection H8/500
104c1213
JM
14307
14308@table @code
14309
8e04817f
AC
14310@kindex set memory @var{mod}
14311@cindex memory models, H8/500
14312@item set memory @var{mod}
14313@itemx show memory
14314Specify which H8/500 memory model (@var{mod}) you are using with
14315@samp{set memory}; check which memory model is in effect with @samp{show
14316memory}. The accepted values for @var{mod} are @code{small},
14317@code{big}, @code{medium}, and @code{compact}.
104c1213 14318
8e04817f 14319@end table
104c1213 14320
8e04817f 14321@node M32R/D
ba04e063 14322@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
14323
14324@table @code
8e04817f
AC
14325@kindex target m32r
14326@item target m32r @var{dev}
172c2a43 14327Renesas M32R/D ROM monitor.
8e04817f 14328
fb3e19c0
KI
14329@kindex target m32rsdi
14330@item target m32rsdi @var{dev}
14331Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
14332@end table
14333
14334The following @value{GDBN} commands are specific to the M32R monitor:
14335
14336@table @code
14337@item set download-path @var{path}
14338@kindex set download-path
14339@cindex find downloadable @sc{srec} files (M32R)
14340Set the default path for finding donwloadable @sc{srec} files.
14341
14342@item show download-path
14343@kindex show download-path
14344Show the default path for downloadable @sc{srec} files.
fb3e19c0 14345
721c2651
EZ
14346@item set board-address @var{addr}
14347@kindex set board-address
14348@cindex M32-EVA target board address
14349Set the IP address for the M32R-EVA target board.
14350
14351@item show board-address
14352@kindex show board-address
14353Show the current IP address of the target board.
14354
14355@item set server-address @var{addr}
14356@kindex set server-address
14357@cindex download server address (M32R)
14358Set the IP address for the download server, which is the @value{GDBN}'s
14359host machine.
14360
14361@item show server-address
14362@kindex show server-address
14363Display the IP address of the download server.
14364
14365@item upload @r{[}@var{file}@r{]}
14366@kindex upload@r{, M32R}
14367Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
14368upload capability. If no @var{file} argument is given, the current
14369executable file is uploaded.
14370
14371@item tload @r{[}@var{file}@r{]}
14372@kindex tload@r{, M32R}
14373Test the @code{upload} command.
8e04817f
AC
14374@end table
14375
ba04e063
EZ
14376The following commands are available for M32R/SDI:
14377
14378@table @code
14379@item sdireset
14380@kindex sdireset
14381@cindex reset SDI connection, M32R
14382This command resets the SDI connection.
14383
14384@item sdistatus
14385@kindex sdistatus
14386This command shows the SDI connection status.
14387
14388@item debug_chaos
14389@kindex debug_chaos
14390@cindex M32R/Chaos debugging
14391Instructs the remote that M32R/Chaos debugging is to be used.
14392
14393@item use_debug_dma
14394@kindex use_debug_dma
14395Instructs the remote to use the DEBUG_DMA method of accessing memory.
14396
14397@item use_mon_code
14398@kindex use_mon_code
14399Instructs the remote to use the MON_CODE method of accessing memory.
14400
14401@item use_ib_break
14402@kindex use_ib_break
14403Instructs the remote to set breakpoints by IB break.
14404
14405@item use_dbt_break
14406@kindex use_dbt_break
14407Instructs the remote to set breakpoints by DBT.
14408@end table
14409
8e04817f
AC
14410@node M68K
14411@subsection M68k
14412
14413The Motorola m68k configuration includes ColdFire support, and
14414target command for the following ROM monitors.
14415
14416@table @code
14417
14418@kindex target abug
14419@item target abug @var{dev}
14420ABug ROM monitor for M68K.
14421
14422@kindex target cpu32bug
14423@item target cpu32bug @var{dev}
14424CPU32BUG monitor, running on a CPU32 (M68K) board.
14425
14426@kindex target dbug
14427@item target dbug @var{dev}
14428dBUG ROM monitor for Motorola ColdFire.
14429
14430@kindex target est
14431@item target est @var{dev}
14432EST-300 ICE monitor, running on a CPU32 (M68K) board.
14433
14434@kindex target rom68k
14435@item target rom68k @var{dev}
14436ROM 68K monitor, running on an M68K IDP board.
14437
14438@end table
14439
8e04817f
AC
14440@table @code
14441
14442@kindex target rombug
14443@item target rombug @var{dev}
14444ROMBUG ROM monitor for OS/9000.
14445
14446@end table
14447
8e04817f
AC
14448@node MIPS Embedded
14449@subsection MIPS Embedded
14450
14451@cindex MIPS boards
14452@value{GDBN} can use the MIPS remote debugging protocol to talk to a
14453MIPS board attached to a serial line. This is available when
14454you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 14455
8e04817f
AC
14456@need 1000
14457Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 14458
8e04817f
AC
14459@table @code
14460@item target mips @var{port}
14461@kindex target mips @var{port}
14462To run a program on the board, start up @code{@value{GDBP}} with the
14463name of your program as the argument. To connect to the board, use the
14464command @samp{target mips @var{port}}, where @var{port} is the name of
14465the serial port connected to the board. If the program has not already
14466been downloaded to the board, you may use the @code{load} command to
14467download it. You can then use all the usual @value{GDBN} commands.
104c1213 14468
8e04817f
AC
14469For example, this sequence connects to the target board through a serial
14470port, and loads and runs a program called @var{prog} through the
14471debugger:
104c1213 14472
474c8240 14473@smallexample
8e04817f
AC
14474host$ @value{GDBP} @var{prog}
14475@value{GDBN} is free software and @dots{}
14476(@value{GDBP}) target mips /dev/ttyb
14477(@value{GDBP}) load @var{prog}
14478(@value{GDBP}) run
474c8240 14479@end smallexample
104c1213 14480
8e04817f
AC
14481@item target mips @var{hostname}:@var{portnumber}
14482On some @value{GDBN} host configurations, you can specify a TCP
14483connection (for instance, to a serial line managed by a terminal
14484concentrator) instead of a serial port, using the syntax
14485@samp{@var{hostname}:@var{portnumber}}.
104c1213 14486
8e04817f
AC
14487@item target pmon @var{port}
14488@kindex target pmon @var{port}
14489PMON ROM monitor.
104c1213 14490
8e04817f
AC
14491@item target ddb @var{port}
14492@kindex target ddb @var{port}
14493NEC's DDB variant of PMON for Vr4300.
104c1213 14494
8e04817f
AC
14495@item target lsi @var{port}
14496@kindex target lsi @var{port}
14497LSI variant of PMON.
104c1213 14498
8e04817f
AC
14499@kindex target r3900
14500@item target r3900 @var{dev}
14501Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 14502
8e04817f
AC
14503@kindex target array
14504@item target array @var{dev}
14505Array Tech LSI33K RAID controller board.
104c1213 14506
8e04817f 14507@end table
104c1213 14508
104c1213 14509
8e04817f
AC
14510@noindent
14511@value{GDBN} also supports these special commands for MIPS targets:
104c1213 14512
8e04817f 14513@table @code
8e04817f
AC
14514@item set mipsfpu double
14515@itemx set mipsfpu single
14516@itemx set mipsfpu none
a64548ea 14517@itemx set mipsfpu auto
8e04817f
AC
14518@itemx show mipsfpu
14519@kindex set mipsfpu
14520@kindex show mipsfpu
14521@cindex MIPS remote floating point
14522@cindex floating point, MIPS remote
14523If your target board does not support the MIPS floating point
14524coprocessor, you should use the command @samp{set mipsfpu none} (if you
14525need this, you may wish to put the command in your @value{GDBN} init
14526file). This tells @value{GDBN} how to find the return value of
14527functions which return floating point values. It also allows
14528@value{GDBN} to avoid saving the floating point registers when calling
14529functions on the board. If you are using a floating point coprocessor
14530with only single precision floating point support, as on the @sc{r4650}
14531processor, use the command @samp{set mipsfpu single}. The default
14532double precision floating point coprocessor may be selected using
14533@samp{set mipsfpu double}.
104c1213 14534
8e04817f
AC
14535In previous versions the only choices were double precision or no
14536floating point, so @samp{set mipsfpu on} will select double precision
14537and @samp{set mipsfpu off} will select no floating point.
104c1213 14538
8e04817f
AC
14539As usual, you can inquire about the @code{mipsfpu} variable with
14540@samp{show mipsfpu}.
104c1213 14541
8e04817f
AC
14542@item set timeout @var{seconds}
14543@itemx set retransmit-timeout @var{seconds}
14544@itemx show timeout
14545@itemx show retransmit-timeout
14546@cindex @code{timeout}, MIPS protocol
14547@cindex @code{retransmit-timeout}, MIPS protocol
14548@kindex set timeout
14549@kindex show timeout
14550@kindex set retransmit-timeout
14551@kindex show retransmit-timeout
14552You can control the timeout used while waiting for a packet, in the MIPS
14553remote protocol, with the @code{set timeout @var{seconds}} command. The
14554default is 5 seconds. Similarly, you can control the timeout used while
14555waiting for an acknowledgement of a packet with the @code{set
14556retransmit-timeout @var{seconds}} command. The default is 3 seconds.
14557You can inspect both values with @code{show timeout} and @code{show
14558retransmit-timeout}. (These commands are @emph{only} available when
14559@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 14560
8e04817f
AC
14561The timeout set by @code{set timeout} does not apply when @value{GDBN}
14562is waiting for your program to stop. In that case, @value{GDBN} waits
14563forever because it has no way of knowing how long the program is going
14564to run before stopping.
ba04e063
EZ
14565
14566@item set syn-garbage-limit @var{num}
14567@kindex set syn-garbage-limit@r{, MIPS remote}
14568@cindex synchronize with remote MIPS target
14569Limit the maximum number of characters @value{GDBN} should ignore when
14570it tries to synchronize with the remote target. The default is 10
14571characters. Setting the limit to -1 means there's no limit.
14572
14573@item show syn-garbage-limit
14574@kindex show syn-garbage-limit@r{, MIPS remote}
14575Show the current limit on the number of characters to ignore when
14576trying to synchronize with the remote system.
14577
14578@item set monitor-prompt @var{prompt}
14579@kindex set monitor-prompt@r{, MIPS remote}
14580@cindex remote monitor prompt
14581Tell @value{GDBN} to expect the specified @var{prompt} string from the
14582remote monitor. The default depends on the target:
14583@table @asis
14584@item pmon target
14585@samp{PMON}
14586@item ddb target
14587@samp{NEC010}
14588@item lsi target
14589@samp{PMON>}
14590@end table
14591
14592@item show monitor-prompt
14593@kindex show monitor-prompt@r{, MIPS remote}
14594Show the current strings @value{GDBN} expects as the prompt from the
14595remote monitor.
14596
14597@item set monitor-warnings
14598@kindex set monitor-warnings@r{, MIPS remote}
14599Enable or disable monitor warnings about hardware breakpoints. This
14600has effect only for the @code{lsi} target. When on, @value{GDBN} will
14601display warning messages whose codes are returned by the @code{lsi}
14602PMON monitor for breakpoint commands.
14603
14604@item show monitor-warnings
14605@kindex show monitor-warnings@r{, MIPS remote}
14606Show the current setting of printing monitor warnings.
14607
14608@item pmon @var{command}
14609@kindex pmon@r{, MIPS remote}
14610@cindex send PMON command
14611This command allows sending an arbitrary @var{command} string to the
14612monitor. The monitor must be in debug mode for this to work.
8e04817f 14613@end table
104c1213 14614
a37295f9
MM
14615@node OpenRISC 1000
14616@subsection OpenRISC 1000
14617@cindex OpenRISC 1000
14618
14619@cindex or1k boards
14620See OR1k Architecture document (@uref{www.opencores.org}) for more information
14621about platform and commands.
14622
14623@table @code
14624
14625@kindex target jtag
14626@item target jtag jtag://@var{host}:@var{port}
14627
14628Connects to remote JTAG server.
14629JTAG remote server can be either an or1ksim or JTAG server,
14630connected via parallel port to the board.
14631
14632Example: @code{target jtag jtag://localhost:9999}
14633
14634@kindex or1ksim
14635@item or1ksim @var{command}
14636If connected to @code{or1ksim} OpenRISC 1000 Architectural
14637Simulator, proprietary commands can be executed.
14638
14639@kindex info or1k spr
14640@item info or1k spr
14641Displays spr groups.
14642
14643@item info or1k spr @var{group}
14644@itemx info or1k spr @var{groupno}
14645Displays register names in selected group.
14646
14647@item info or1k spr @var{group} @var{register}
14648@itemx info or1k spr @var{register}
14649@itemx info or1k spr @var{groupno} @var{registerno}
14650@itemx info or1k spr @var{registerno}
14651Shows information about specified spr register.
14652
14653@kindex spr
14654@item spr @var{group} @var{register} @var{value}
14655@itemx spr @var{register @var{value}}
14656@itemx spr @var{groupno} @var{registerno @var{value}}
14657@itemx spr @var{registerno @var{value}}
14658Writes @var{value} to specified spr register.
14659@end table
14660
14661Some implementations of OpenRISC 1000 Architecture also have hardware trace.
14662It is very similar to @value{GDBN} trace, except it does not interfere with normal
14663program execution and is thus much faster. Hardware breakpoints/watchpoint
14664triggers can be set using:
14665@table @code
14666@item $LEA/$LDATA
14667Load effective address/data
14668@item $SEA/$SDATA
14669Store effective address/data
14670@item $AEA/$ADATA
14671Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
14672@item $FETCH
14673Fetch data
14674@end table
14675
14676When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
14677@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
14678
14679@code{htrace} commands:
14680@cindex OpenRISC 1000 htrace
14681@table @code
14682@kindex hwatch
14683@item hwatch @var{conditional}
14684Set hardware watchpoint on combination of Load/Store Effecive Address(es)
14685or Data. For example:
14686
14687@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14688
14689@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14690
4644b6e3 14691@kindex htrace
a37295f9
MM
14692@item htrace info
14693Display information about current HW trace configuration.
14694
a37295f9
MM
14695@item htrace trigger @var{conditional}
14696Set starting criteria for HW trace.
14697
a37295f9
MM
14698@item htrace qualifier @var{conditional}
14699Set acquisition qualifier for HW trace.
14700
a37295f9
MM
14701@item htrace stop @var{conditional}
14702Set HW trace stopping criteria.
14703
f153cc92 14704@item htrace record [@var{data}]*
a37295f9
MM
14705Selects the data to be recorded, when qualifier is met and HW trace was
14706triggered.
14707
a37295f9 14708@item htrace enable
a37295f9
MM
14709@itemx htrace disable
14710Enables/disables the HW trace.
14711
f153cc92 14712@item htrace rewind [@var{filename}]
a37295f9
MM
14713Clears currently recorded trace data.
14714
14715If filename is specified, new trace file is made and any newly collected data
14716will be written there.
14717
f153cc92 14718@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
14719Prints trace buffer, using current record configuration.
14720
a37295f9
MM
14721@item htrace mode continuous
14722Set continuous trace mode.
14723
a37295f9
MM
14724@item htrace mode suspend
14725Set suspend trace mode.
14726
14727@end table
14728
8e04817f
AC
14729@node PowerPC
14730@subsection PowerPC
104c1213
JM
14731
14732@table @code
8e04817f
AC
14733@kindex target dink32
14734@item target dink32 @var{dev}
14735DINK32 ROM monitor.
104c1213 14736
8e04817f
AC
14737@kindex target ppcbug
14738@item target ppcbug @var{dev}
14739@kindex target ppcbug1
14740@item target ppcbug1 @var{dev}
14741PPCBUG ROM monitor for PowerPC.
104c1213 14742
8e04817f
AC
14743@kindex target sds
14744@item target sds @var{dev}
14745SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 14746@end table
8e04817f 14747
c45da7e6
EZ
14748@cindex SDS protocol
14749The following commands specifi to the SDS protocol are supported
14750by@value{GDBN}:
14751
14752@table @code
14753@item set sdstimeout @var{nsec}
14754@kindex set sdstimeout
14755Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
14756default is 2 seconds.
14757
14758@item show sdstimeout
14759@kindex show sdstimeout
14760Show the current value of the SDS timeout.
14761
14762@item sds @var{command}
14763@kindex sds@r{, a command}
14764Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
14765@end table
14766
c45da7e6 14767
8e04817f
AC
14768@node PA
14769@subsection HP PA Embedded
104c1213
JM
14770
14771@table @code
14772
8e04817f
AC
14773@kindex target op50n
14774@item target op50n @var{dev}
14775OP50N monitor, running on an OKI HPPA board.
14776
14777@kindex target w89k
14778@item target w89k @var{dev}
14779W89K monitor, running on a Winbond HPPA board.
104c1213
JM
14780
14781@end table
14782
8e04817f 14783@node SH
172c2a43 14784@subsection Renesas SH
104c1213
JM
14785
14786@table @code
14787
172c2a43 14788@kindex target hms@r{, with Renesas SH}
8e04817f 14789@item target hms @var{dev}
172c2a43 14790A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
14791commands @code{device} and @code{speed} to control the serial line and
14792the communications speed used.
104c1213 14793
172c2a43 14794@kindex target e7000@r{, with Renesas SH}
8e04817f 14795@item target e7000 @var{dev}
172c2a43 14796E7000 emulator for Renesas SH.
104c1213 14797
8e04817f
AC
14798@kindex target sh3@r{, with SH}
14799@kindex target sh3e@r{, with SH}
14800@item target sh3 @var{dev}
14801@item target sh3e @var{dev}
172c2a43 14802Renesas SH-3 and SH-3E target systems.
104c1213 14803
8e04817f 14804@end table
104c1213 14805
8e04817f
AC
14806@node Sparclet
14807@subsection Tsqware Sparclet
104c1213 14808
8e04817f
AC
14809@cindex Sparclet
14810
14811@value{GDBN} enables developers to debug tasks running on
14812Sparclet targets from a Unix host.
14813@value{GDBN} uses code that runs on
14814both the Unix host and on the Sparclet target. The program
14815@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 14816
8e04817f
AC
14817@table @code
14818@item remotetimeout @var{args}
14819@kindex remotetimeout
14820@value{GDBN} supports the option @code{remotetimeout}.
14821This option is set by the user, and @var{args} represents the number of
14822seconds @value{GDBN} waits for responses.
104c1213
JM
14823@end table
14824
8e04817f
AC
14825@cindex compiling, on Sparclet
14826When compiling for debugging, include the options @samp{-g} to get debug
14827information and @samp{-Ttext} to relocate the program to where you wish to
14828load it on the target. You may also want to add the options @samp{-n} or
14829@samp{-N} in order to reduce the size of the sections. Example:
104c1213 14830
474c8240 14831@smallexample
8e04817f 14832sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 14833@end smallexample
104c1213 14834
8e04817f 14835You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 14836
474c8240 14837@smallexample
8e04817f 14838sparclet-aout-objdump --headers --syms prog
474c8240 14839@end smallexample
104c1213 14840
8e04817f
AC
14841@cindex running, on Sparclet
14842Once you have set
14843your Unix execution search path to find @value{GDBN}, you are ready to
14844run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
14845(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 14846
8e04817f
AC
14847@value{GDBN} comes up showing the prompt:
14848
474c8240 14849@smallexample
8e04817f 14850(gdbslet)
474c8240 14851@end smallexample
104c1213
JM
14852
14853@menu
8e04817f
AC
14854* Sparclet File:: Setting the file to debug
14855* Sparclet Connection:: Connecting to Sparclet
14856* Sparclet Download:: Sparclet download
14857* Sparclet Execution:: Running and debugging
104c1213
JM
14858@end menu
14859
8e04817f
AC
14860@node Sparclet File
14861@subsubsection Setting file to debug
104c1213 14862
8e04817f 14863The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 14864
474c8240 14865@smallexample
8e04817f 14866(gdbslet) file prog
474c8240 14867@end smallexample
104c1213 14868
8e04817f
AC
14869@need 1000
14870@value{GDBN} then attempts to read the symbol table of @file{prog}.
14871@value{GDBN} locates
14872the file by searching the directories listed in the command search
14873path.
14874If the file was compiled with debug information (option "-g"), source
14875files will be searched as well.
14876@value{GDBN} locates
14877the source files by searching the directories listed in the directory search
14878path (@pxref{Environment, ,Your program's environment}).
14879If it fails
14880to find a file, it displays a message such as:
104c1213 14881
474c8240 14882@smallexample
8e04817f 14883prog: No such file or directory.
474c8240 14884@end smallexample
104c1213 14885
8e04817f
AC
14886When this happens, add the appropriate directories to the search paths with
14887the @value{GDBN} commands @code{path} and @code{dir}, and execute the
14888@code{target} command again.
104c1213 14889
8e04817f
AC
14890@node Sparclet Connection
14891@subsubsection Connecting to Sparclet
104c1213 14892
8e04817f
AC
14893The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
14894To connect to a target on serial port ``@code{ttya}'', type:
104c1213 14895
474c8240 14896@smallexample
8e04817f
AC
14897(gdbslet) target sparclet /dev/ttya
14898Remote target sparclet connected to /dev/ttya
14899main () at ../prog.c:3
474c8240 14900@end smallexample
104c1213 14901
8e04817f
AC
14902@need 750
14903@value{GDBN} displays messages like these:
104c1213 14904
474c8240 14905@smallexample
8e04817f 14906Connected to ttya.
474c8240 14907@end smallexample
104c1213 14908
8e04817f
AC
14909@node Sparclet Download
14910@subsubsection Sparclet download
104c1213 14911
8e04817f
AC
14912@cindex download to Sparclet
14913Once connected to the Sparclet target,
14914you can use the @value{GDBN}
14915@code{load} command to download the file from the host to the target.
14916The file name and load offset should be given as arguments to the @code{load}
14917command.
14918Since the file format is aout, the program must be loaded to the starting
14919address. You can use @code{objdump} to find out what this value is. The load
14920offset is an offset which is added to the VMA (virtual memory address)
14921of each of the file's sections.
14922For instance, if the program
14923@file{prog} was linked to text address 0x1201000, with data at 0x12010160
14924and bss at 0x12010170, in @value{GDBN}, type:
104c1213 14925
474c8240 14926@smallexample
8e04817f
AC
14927(gdbslet) load prog 0x12010000
14928Loading section .text, size 0xdb0 vma 0x12010000
474c8240 14929@end smallexample
104c1213 14930
8e04817f
AC
14931If the code is loaded at a different address then what the program was linked
14932to, you may need to use the @code{section} and @code{add-symbol-file} commands
14933to tell @value{GDBN} where to map the symbol table.
14934
14935@node Sparclet Execution
14936@subsubsection Running and debugging
14937
14938@cindex running and debugging Sparclet programs
14939You can now begin debugging the task using @value{GDBN}'s execution control
14940commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
14941manual for the list of commands.
14942
474c8240 14943@smallexample
8e04817f
AC
14944(gdbslet) b main
14945Breakpoint 1 at 0x12010000: file prog.c, line 3.
14946(gdbslet) run
14947Starting program: prog
14948Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
149493 char *symarg = 0;
14950(gdbslet) step
149514 char *execarg = "hello!";
14952(gdbslet)
474c8240 14953@end smallexample
8e04817f
AC
14954
14955@node Sparclite
14956@subsection Fujitsu Sparclite
104c1213
JM
14957
14958@table @code
14959
8e04817f
AC
14960@kindex target sparclite
14961@item target sparclite @var{dev}
14962Fujitsu sparclite boards, used only for the purpose of loading.
14963You must use an additional command to debug the program.
14964For example: target remote @var{dev} using @value{GDBN} standard
14965remote protocol.
104c1213
JM
14966
14967@end table
14968
8e04817f
AC
14969@node ST2000
14970@subsection Tandem ST2000
104c1213 14971
8e04817f
AC
14972@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
14973STDBUG protocol.
104c1213 14974
8e04817f
AC
14975To connect your ST2000 to the host system, see the manufacturer's
14976manual. Once the ST2000 is physically attached, you can run:
104c1213 14977
474c8240 14978@smallexample
8e04817f 14979target st2000 @var{dev} @var{speed}
474c8240 14980@end smallexample
104c1213 14981
8e04817f
AC
14982@noindent
14983to establish it as your debugging environment. @var{dev} is normally
14984the name of a serial device, such as @file{/dev/ttya}, connected to the
14985ST2000 via a serial line. You can instead specify @var{dev} as a TCP
14986connection (for example, to a serial line attached via a terminal
14987concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 14988
8e04817f
AC
14989The @code{load} and @code{attach} commands are @emph{not} defined for
14990this target; you must load your program into the ST2000 as you normally
14991would for standalone operation. @value{GDBN} reads debugging information
14992(such as symbols) from a separate, debugging version of the program
14993available on your host computer.
14994@c FIXME!! This is terribly vague; what little content is here is
14995@c basically hearsay.
104c1213 14996
8e04817f
AC
14997@cindex ST2000 auxiliary commands
14998These auxiliary @value{GDBN} commands are available to help you with the ST2000
14999environment:
104c1213 15000
8e04817f
AC
15001@table @code
15002@item st2000 @var{command}
15003@kindex st2000 @var{cmd}
15004@cindex STDBUG commands (ST2000)
15005@cindex commands to STDBUG (ST2000)
15006Send a @var{command} to the STDBUG monitor. See the manufacturer's
15007manual for available commands.
104c1213 15008
8e04817f
AC
15009@item connect
15010@cindex connect (to STDBUG)
15011Connect the controlling terminal to the STDBUG command monitor. When
15012you are done interacting with STDBUG, typing either of two character
15013sequences gets you back to the @value{GDBN} command prompt:
15014@kbd{@key{RET}~.} (Return, followed by tilde and period) or
15015@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
15016@end table
15017
8e04817f
AC
15018@node Z8000
15019@subsection Zilog Z8000
104c1213 15020
8e04817f
AC
15021@cindex Z8000
15022@cindex simulator, Z8000
15023@cindex Zilog Z8000 simulator
104c1213 15024
8e04817f
AC
15025When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
15026a Z8000 simulator.
15027
15028For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
15029unsegmented variant of the Z8000 architecture) or the Z8001 (the
15030segmented variant). The simulator recognizes which architecture is
15031appropriate by inspecting the object code.
104c1213 15032
8e04817f
AC
15033@table @code
15034@item target sim @var{args}
15035@kindex sim
15036@kindex target sim@r{, with Z8000}
15037Debug programs on a simulated CPU. If the simulator supports setup
15038options, specify them via @var{args}.
104c1213
JM
15039@end table
15040
8e04817f
AC
15041@noindent
15042After specifying this target, you can debug programs for the simulated
15043CPU in the same style as programs for your host computer; use the
15044@code{file} command to load a new program image, the @code{run} command
15045to run your program, and so on.
15046
15047As well as making available all the usual machine registers
15048(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
15049additional items of information as specially named registers:
104c1213
JM
15050
15051@table @code
15052
8e04817f
AC
15053@item cycles
15054Counts clock-ticks in the simulator.
104c1213 15055
8e04817f
AC
15056@item insts
15057Counts instructions run in the simulator.
104c1213 15058
8e04817f
AC
15059@item time
15060Execution time in 60ths of a second.
104c1213 15061
8e04817f 15062@end table
104c1213 15063
8e04817f
AC
15064You can refer to these values in @value{GDBN} expressions with the usual
15065conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
15066conditional breakpoint that suspends only after at least 5000
15067simulated clock ticks.
104c1213 15068
a64548ea
EZ
15069@node AVR
15070@subsection Atmel AVR
15071@cindex AVR
15072
15073When configured for debugging the Atmel AVR, @value{GDBN} supports the
15074following AVR-specific commands:
15075
15076@table @code
15077@item info io_registers
15078@kindex info io_registers@r{, AVR}
15079@cindex I/O registers (Atmel AVR)
15080This command displays information about the AVR I/O registers. For
15081each register, @value{GDBN} prints its number and value.
15082@end table
15083
15084@node CRIS
15085@subsection CRIS
15086@cindex CRIS
15087
15088When configured for debugging CRIS, @value{GDBN} provides the
15089following CRIS-specific commands:
15090
15091@table @code
15092@item set cris-version @var{ver}
15093@cindex CRIS version
e22e55c9
OF
15094Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
15095The CRIS version affects register names and sizes. This command is useful in
15096case autodetection of the CRIS version fails.
a64548ea
EZ
15097
15098@item show cris-version
15099Show the current CRIS version.
15100
15101@item set cris-dwarf2-cfi
15102@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
15103Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
15104Change to @samp{off} when using @code{gcc-cris} whose version is below
15105@code{R59}.
a64548ea
EZ
15106
15107@item show cris-dwarf2-cfi
15108Show the current state of using DWARF-2 CFI.
e22e55c9
OF
15109
15110@item set cris-mode @var{mode}
15111@cindex CRIS mode
15112Set the current CRIS mode to @var{mode}. It should only be changed when
15113debugging in guru mode, in which case it should be set to
15114@samp{guru} (the default is @samp{normal}).
15115
15116@item show cris-mode
15117Show the current CRIS mode.
a64548ea
EZ
15118@end table
15119
15120@node Super-H
15121@subsection Renesas Super-H
15122@cindex Super-H
15123
15124For the Renesas Super-H processor, @value{GDBN} provides these
15125commands:
15126
15127@table @code
15128@item regs
15129@kindex regs@r{, Super-H}
15130Show the values of all Super-H registers.
15131@end table
15132
c45da7e6
EZ
15133@node WinCE
15134@subsection Windows CE
15135@cindex Windows CE
15136
15137The following commands are available for Windows CE:
15138
15139@table @code
15140@item set remotedirectory @var{dir}
15141@kindex set remotedirectory
15142Tell @value{GDBN} to upload files from the named directory @var{dir}.
15143The default is @file{/gdb}, i.e.@: the root directory on the current
15144drive.
15145
15146@item show remotedirectory
15147@kindex show remotedirectory
15148Show the current value of the upload directory.
15149
15150@item set remoteupload @var{method}
15151@kindex set remoteupload
15152Set the method used to upload files to remote device. Valid values
15153for @var{method} are @samp{always}, @samp{newer}, and @samp{never}.
15154The default is @samp{newer}.
15155
15156@item show remoteupload
15157@kindex show remoteupload
15158Show the current setting of the upload method.
15159
15160@item set remoteaddhost
15161@kindex set remoteaddhost
15162Tell @value{GDBN} whether to add this host to the remote stub's
15163arguments when you debug over a network.
15164
15165@item show remoteaddhost
15166@kindex show remoteaddhost
15167Show whether to add this host to remote stub's arguments when
15168debugging over a network.
15169@end table
15170
a64548ea 15171
8e04817f
AC
15172@node Architectures
15173@section Architectures
104c1213 15174
8e04817f
AC
15175This section describes characteristics of architectures that affect
15176all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 15177
8e04817f 15178@menu
9c16f35a 15179* i386::
8e04817f
AC
15180* A29K::
15181* Alpha::
15182* MIPS::
a64548ea 15183* HPPA:: HP PA architecture
8e04817f 15184@end menu
104c1213 15185
9c16f35a
EZ
15186@node i386
15187@subsection x86 Architecture-specific issues.
15188
15189@table @code
15190@item set struct-convention @var{mode}
15191@kindex set struct-convention
15192@cindex struct return convention
15193@cindex struct/union returned in registers
15194Set the convention used by the inferior to return @code{struct}s and
15195@code{union}s from functions to @var{mode}. Possible values of
15196@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
15197default). @code{"default"} or @code{"pcc"} means that @code{struct}s
15198are returned on the stack, while @code{"reg"} means that a
15199@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
15200be returned in a register.
15201
15202@item show struct-convention
15203@kindex show struct-convention
15204Show the current setting of the convention to return @code{struct}s
15205from functions.
15206@end table
15207
8e04817f
AC
15208@node A29K
15209@subsection A29K
104c1213
JM
15210
15211@table @code
104c1213 15212
8e04817f
AC
15213@kindex set rstack_high_address
15214@cindex AMD 29K register stack
15215@cindex register stack, AMD29K
15216@item set rstack_high_address @var{address}
15217On AMD 29000 family processors, registers are saved in a separate
15218@dfn{register stack}. There is no way for @value{GDBN} to determine the
15219extent of this stack. Normally, @value{GDBN} just assumes that the
15220stack is ``large enough''. This may result in @value{GDBN} referencing
15221memory locations that do not exist. If necessary, you can get around
15222this problem by specifying the ending address of the register stack with
15223the @code{set rstack_high_address} command. The argument should be an
15224address, which you probably want to precede with @samp{0x} to specify in
15225hexadecimal.
104c1213 15226
8e04817f
AC
15227@kindex show rstack_high_address
15228@item show rstack_high_address
15229Display the current limit of the register stack, on AMD 29000 family
15230processors.
104c1213 15231
8e04817f 15232@end table
104c1213 15233
8e04817f
AC
15234@node Alpha
15235@subsection Alpha
104c1213 15236
8e04817f 15237See the following section.
104c1213 15238
8e04817f
AC
15239@node MIPS
15240@subsection MIPS
104c1213 15241
8e04817f
AC
15242@cindex stack on Alpha
15243@cindex stack on MIPS
15244@cindex Alpha stack
15245@cindex MIPS stack
15246Alpha- and MIPS-based computers use an unusual stack frame, which
15247sometimes requires @value{GDBN} to search backward in the object code to
15248find the beginning of a function.
104c1213 15249
8e04817f
AC
15250@cindex response time, MIPS debugging
15251To improve response time (especially for embedded applications, where
15252@value{GDBN} may be restricted to a slow serial line for this search)
15253you may want to limit the size of this search, using one of these
15254commands:
104c1213 15255
8e04817f
AC
15256@table @code
15257@cindex @code{heuristic-fence-post} (Alpha, MIPS)
15258@item set heuristic-fence-post @var{limit}
15259Restrict @value{GDBN} to examining at most @var{limit} bytes in its
15260search for the beginning of a function. A value of @var{0} (the
15261default) means there is no limit. However, except for @var{0}, the
15262larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
15263and therefore the longer it takes to run. You should only need to use
15264this command when debugging a stripped executable.
104c1213 15265
8e04817f
AC
15266@item show heuristic-fence-post
15267Display the current limit.
15268@end table
104c1213
JM
15269
15270@noindent
8e04817f
AC
15271These commands are available @emph{only} when @value{GDBN} is configured
15272for debugging programs on Alpha or MIPS processors.
104c1213 15273
a64548ea
EZ
15274Several MIPS-specific commands are available when debugging MIPS
15275programs:
15276
15277@table @code
15278@item set mips saved-gpreg-size @var{size}
15279@kindex set mips saved-gpreg-size
15280@cindex MIPS GP register size on stack
15281Set the size of MIPS general-purpose registers saved on the stack.
15282The argument @var{size} can be one of the following:
15283
15284@table @samp
15285@item 32
1528632-bit GP registers
15287@item 64
1528864-bit GP registers
15289@item auto
15290Use the target's default setting or autodetect the saved size from the
15291information contained in the executable. This is the default
15292@end table
15293
15294@item show mips saved-gpreg-size
15295@kindex show mips saved-gpreg-size
15296Show the current size of MIPS GP registers on the stack.
15297
15298@item set mips stack-arg-size @var{size}
15299@kindex set mips stack-arg-size
15300@cindex MIPS stack space for arguments
15301Set the amount of stack space reserved for arguments to functions.
15302The argument can be one of @code{"32"}, @code{"64"} or @code{"auto"}
15303(the default).
15304
15305@item set mips abi @var{arg}
15306@kindex set mips abi
15307@cindex set ABI for MIPS
15308Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
15309values of @var{arg} are:
15310
15311@table @samp
15312@item auto
15313The default ABI associated with the current binary (this is the
15314default).
15315@item o32
15316@item o64
15317@item n32
15318@item n64
15319@item eabi32
15320@item eabi64
15321@item auto
15322@end table
15323
15324@item show mips abi
15325@kindex show mips abi
15326Show the MIPS ABI used by @value{GDBN} to debug the inferior.
15327
15328@item set mipsfpu
15329@itemx show mipsfpu
15330@xref{MIPS Embedded, set mipsfpu}.
15331
15332@item set mips mask-address @var{arg}
15333@kindex set mips mask-address
15334@cindex MIPS addresses, masking
15335This command determines whether the most-significant 32 bits of 64-bit
15336MIPS addresses are masked off. The argument @var{arg} can be
15337@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
15338setting, which lets @value{GDBN} determine the correct value.
15339
15340@item show mips mask-address
15341@kindex show mips mask-address
15342Show whether the upper 32 bits of MIPS addresses are masked off or
15343not.
15344
15345@item set remote-mips64-transfers-32bit-regs
15346@kindex set remote-mips64-transfers-32bit-regs
15347This command controls compatibility with 64-bit MIPS targets that
15348transfer data in 32-bit quantities. If you have an old MIPS 64 target
15349that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
15350and 64 bits for other registers, set this option to @samp{on}.
15351
15352@item show remote-mips64-transfers-32bit-regs
15353@kindex show remote-mips64-transfers-32bit-regs
15354Show the current setting of compatibility with older MIPS 64 targets.
15355
15356@item set debug mips
15357@kindex set debug mips
15358This command turns on and off debugging messages for the MIPS-specific
15359target code in @value{GDBN}.
15360
15361@item show debug mips
15362@kindex show debug mips
15363Show the current setting of MIPS debugging messages.
15364@end table
15365
15366
15367@node HPPA
15368@subsection HPPA
15369@cindex HPPA support
15370
15371When @value{GDBN} is debugging te HP PA architecture, it provides the
15372following special commands:
15373
15374@table @code
15375@item set debug hppa
15376@kindex set debug hppa
15377THis command determines whether HPPA architecture specific debugging
15378messages are to be displayed.
15379
15380@item show debug hppa
15381Show whether HPPA debugging messages are displayed.
15382
15383@item maint print unwind @var{address}
15384@kindex maint print unwind@r{, HPPA}
15385This command displays the contents of the unwind table entry at the
15386given @var{address}.
15387
15388@end table
15389
104c1213 15390
8e04817f
AC
15391@node Controlling GDB
15392@chapter Controlling @value{GDBN}
15393
15394You can alter the way @value{GDBN} interacts with you by using the
15395@code{set} command. For commands controlling how @value{GDBN} displays
15396data, see @ref{Print Settings, ,Print settings}. Other settings are
15397described here.
15398
15399@menu
15400* Prompt:: Prompt
15401* Editing:: Command editing
d620b259 15402* Command History:: Command history
8e04817f
AC
15403* Screen Size:: Screen size
15404* Numbers:: Numbers
1e698235 15405* ABI:: Configuring the current ABI
8e04817f
AC
15406* Messages/Warnings:: Optional warnings and messages
15407* Debugging Output:: Optional messages about internal happenings
15408@end menu
15409
15410@node Prompt
15411@section Prompt
104c1213 15412
8e04817f 15413@cindex prompt
104c1213 15414
8e04817f
AC
15415@value{GDBN} indicates its readiness to read a command by printing a string
15416called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
15417can change the prompt string with the @code{set prompt} command. For
15418instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
15419the prompt in one of the @value{GDBN} sessions so that you can always tell
15420which one you are talking to.
104c1213 15421
8e04817f
AC
15422@emph{Note:} @code{set prompt} does not add a space for you after the
15423prompt you set. This allows you to set a prompt which ends in a space
15424or a prompt that does not.
104c1213 15425
8e04817f
AC
15426@table @code
15427@kindex set prompt
15428@item set prompt @var{newprompt}
15429Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 15430
8e04817f
AC
15431@kindex show prompt
15432@item show prompt
15433Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
15434@end table
15435
8e04817f
AC
15436@node Editing
15437@section Command editing
15438@cindex readline
15439@cindex command line editing
104c1213 15440
703663ab 15441@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
15442@sc{gnu} library provides consistent behavior for programs which provide a
15443command line interface to the user. Advantages are @sc{gnu} Emacs-style
15444or @dfn{vi}-style inline editing of commands, @code{csh}-like history
15445substitution, and a storage and recall of command history across
15446debugging sessions.
104c1213 15447
8e04817f
AC
15448You may control the behavior of command line editing in @value{GDBN} with the
15449command @code{set}.
104c1213 15450
8e04817f
AC
15451@table @code
15452@kindex set editing
15453@cindex editing
15454@item set editing
15455@itemx set editing on
15456Enable command line editing (enabled by default).
104c1213 15457
8e04817f
AC
15458@item set editing off
15459Disable command line editing.
104c1213 15460
8e04817f
AC
15461@kindex show editing
15462@item show editing
15463Show whether command line editing is enabled.
104c1213
JM
15464@end table
15465
703663ab
EZ
15466@xref{Command Line Editing}, for more details about the Readline
15467interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
15468encouraged to read that chapter.
15469
d620b259 15470@node Command History
8e04817f 15471@section Command history
703663ab 15472@cindex command history
8e04817f
AC
15473
15474@value{GDBN} can keep track of the commands you type during your
15475debugging sessions, so that you can be certain of precisely what
15476happened. Use these commands to manage the @value{GDBN} command
15477history facility.
104c1213 15478
703663ab
EZ
15479@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
15480package, to provide the history facility. @xref{Using History
15481Interactively}, for the detailed description of the History library.
15482
d620b259
NR
15483To issue a command to @value{GDBN} without affecting certain aspects of
15484the state which is seen by users, prefix it with @samp{server }. This
15485means that this command will not affect the command history, nor will it
15486affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
15487pressed on a line by itself.
15488
15489@cindex @code{server}, command prefix
15490The server prefix does not affect the recording of values into the value
15491history; to print a value without recording it into the value history,
15492use the @code{output} command instead of the @code{print} command.
15493
703663ab
EZ
15494Here is the description of @value{GDBN} commands related to command
15495history.
15496
104c1213 15497@table @code
8e04817f
AC
15498@cindex history substitution
15499@cindex history file
15500@kindex set history filename
4644b6e3 15501@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
15502@item set history filename @var{fname}
15503Set the name of the @value{GDBN} command history file to @var{fname}.
15504This is the file where @value{GDBN} reads an initial command history
15505list, and where it writes the command history from this session when it
15506exits. You can access this list through history expansion or through
15507the history command editing characters listed below. This file defaults
15508to the value of the environment variable @code{GDBHISTFILE}, or to
15509@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
15510is not set.
104c1213 15511
9c16f35a
EZ
15512@cindex save command history
15513@kindex set history save
8e04817f
AC
15514@item set history save
15515@itemx set history save on
15516Record command history in a file, whose name may be specified with the
15517@code{set history filename} command. By default, this option is disabled.
104c1213 15518
8e04817f
AC
15519@item set history save off
15520Stop recording command history in a file.
104c1213 15521
8e04817f 15522@cindex history size
9c16f35a 15523@kindex set history size
6fc08d32 15524@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
15525@item set history size @var{size}
15526Set the number of commands which @value{GDBN} keeps in its history list.
15527This defaults to the value of the environment variable
15528@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
15529@end table
15530
8e04817f 15531History expansion assigns special meaning to the character @kbd{!}.
703663ab 15532@xref{Event Designators}, for more details.
8e04817f 15533
703663ab 15534@cindex history expansion, turn on/off
8e04817f
AC
15535Since @kbd{!} is also the logical not operator in C, history expansion
15536is off by default. If you decide to enable history expansion with the
15537@code{set history expansion on} command, you may sometimes need to
15538follow @kbd{!} (when it is used as logical not, in an expression) with
15539a space or a tab to prevent it from being expanded. The readline
15540history facilities do not attempt substitution on the strings
15541@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
15542
15543The commands to control history expansion are:
104c1213
JM
15544
15545@table @code
8e04817f
AC
15546@item set history expansion on
15547@itemx set history expansion
703663ab 15548@kindex set history expansion
8e04817f 15549Enable history expansion. History expansion is off by default.
104c1213 15550
8e04817f
AC
15551@item set history expansion off
15552Disable history expansion.
104c1213 15553
8e04817f
AC
15554@c @group
15555@kindex show history
15556@item show history
15557@itemx show history filename
15558@itemx show history save
15559@itemx show history size
15560@itemx show history expansion
15561These commands display the state of the @value{GDBN} history parameters.
15562@code{show history} by itself displays all four states.
15563@c @end group
15564@end table
15565
15566@table @code
9c16f35a
EZ
15567@kindex show commands
15568@cindex show last commands
15569@cindex display command history
8e04817f
AC
15570@item show commands
15571Display the last ten commands in the command history.
104c1213 15572
8e04817f
AC
15573@item show commands @var{n}
15574Print ten commands centered on command number @var{n}.
15575
15576@item show commands +
15577Print ten commands just after the commands last printed.
104c1213
JM
15578@end table
15579
8e04817f
AC
15580@node Screen Size
15581@section Screen size
15582@cindex size of screen
15583@cindex pauses in output
104c1213 15584
8e04817f
AC
15585Certain commands to @value{GDBN} may produce large amounts of
15586information output to the screen. To help you read all of it,
15587@value{GDBN} pauses and asks you for input at the end of each page of
15588output. Type @key{RET} when you want to continue the output, or @kbd{q}
15589to discard the remaining output. Also, the screen width setting
15590determines when to wrap lines of output. Depending on what is being
15591printed, @value{GDBN} tries to break the line at a readable place,
15592rather than simply letting it overflow onto the following line.
15593
15594Normally @value{GDBN} knows the size of the screen from the terminal
15595driver software. For example, on Unix @value{GDBN} uses the termcap data base
15596together with the value of the @code{TERM} environment variable and the
15597@code{stty rows} and @code{stty cols} settings. If this is not correct,
15598you can override it with the @code{set height} and @code{set
15599width} commands:
15600
15601@table @code
15602@kindex set height
15603@kindex set width
15604@kindex show width
15605@kindex show height
15606@item set height @var{lpp}
15607@itemx show height
15608@itemx set width @var{cpl}
15609@itemx show width
15610These @code{set} commands specify a screen height of @var{lpp} lines and
15611a screen width of @var{cpl} characters. The associated @code{show}
15612commands display the current settings.
104c1213 15613
8e04817f
AC
15614If you specify a height of zero lines, @value{GDBN} does not pause during
15615output no matter how long the output is. This is useful if output is to a
15616file or to an editor buffer.
104c1213 15617
8e04817f
AC
15618Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
15619from wrapping its output.
9c16f35a
EZ
15620
15621@item set pagination on
15622@itemx set pagination off
15623@kindex set pagination
15624Turn the output pagination on or off; the default is on. Turning
15625pagination off is the alternative to @code{set height 0}.
15626
15627@item show pagination
15628@kindex show pagination
15629Show the current pagination mode.
104c1213
JM
15630@end table
15631
8e04817f
AC
15632@node Numbers
15633@section Numbers
15634@cindex number representation
15635@cindex entering numbers
104c1213 15636
8e04817f
AC
15637You can always enter numbers in octal, decimal, or hexadecimal in
15638@value{GDBN} by the usual conventions: octal numbers begin with
15639@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
15640begin with @samp{0x}. Numbers that neither begin with @samp{0} or
15641@samp{0x}, nor end with a @samp{.} are, by default, entered in base
1564210; likewise, the default display for numbers---when no particular
15643format is specified---is base 10. You can change the default base for
15644both input and output with the commands described below.
104c1213 15645
8e04817f
AC
15646@table @code
15647@kindex set input-radix
15648@item set input-radix @var{base}
15649Set the default base for numeric input. Supported choices
15650for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15651specified either unambiguously or using the current input radix; for
8e04817f 15652example, any of
104c1213 15653
8e04817f 15654@smallexample
9c16f35a
EZ
15655set input-radix 012
15656set input-radix 10.
15657set input-radix 0xa
8e04817f 15658@end smallexample
104c1213 15659
8e04817f 15660@noindent
9c16f35a 15661sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
15662leaves the input radix unchanged, no matter what it was, since
15663@samp{10}, being without any leading or trailing signs of its base, is
15664interpreted in the current radix. Thus, if the current radix is 16,
15665@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
15666change the radix.
104c1213 15667
8e04817f
AC
15668@kindex set output-radix
15669@item set output-radix @var{base}
15670Set the default base for numeric display. Supported choices
15671for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15672specified either unambiguously or using the current input radix.
104c1213 15673
8e04817f
AC
15674@kindex show input-radix
15675@item show input-radix
15676Display the current default base for numeric input.
104c1213 15677
8e04817f
AC
15678@kindex show output-radix
15679@item show output-radix
15680Display the current default base for numeric display.
9c16f35a
EZ
15681
15682@item set radix @r{[}@var{base}@r{]}
15683@itemx show radix
15684@kindex set radix
15685@kindex show radix
15686These commands set and show the default base for both input and output
15687of numbers. @code{set radix} sets the radix of input and output to
15688the same base; without an argument, it resets the radix back to its
15689default value of 10.
15690
8e04817f 15691@end table
104c1213 15692
1e698235
DJ
15693@node ABI
15694@section Configuring the current ABI
15695
15696@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
15697application automatically. However, sometimes you need to override its
15698conclusions. Use these commands to manage @value{GDBN}'s view of the
15699current ABI.
15700
98b45e30
DJ
15701@cindex OS ABI
15702@kindex set osabi
b4e9345d 15703@kindex show osabi
98b45e30
DJ
15704
15705One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 15706system targets, either via remote debugging or native emulation.
98b45e30
DJ
15707@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
15708but you can override its conclusion using the @code{set osabi} command.
15709One example where this is useful is in debugging of binaries which use
15710an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
15711not have the same identifying marks that the standard C library for your
15712platform provides.
15713
15714@table @code
15715@item show osabi
15716Show the OS ABI currently in use.
15717
15718@item set osabi
15719With no argument, show the list of registered available OS ABI's.
15720
15721@item set osabi @var{abi}
15722Set the current OS ABI to @var{abi}.
15723@end table
15724
1e698235 15725@cindex float promotion
1e698235
DJ
15726
15727Generally, the way that an argument of type @code{float} is passed to a
15728function depends on whether the function is prototyped. For a prototyped
15729(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
15730according to the architecture's convention for @code{float}. For unprototyped
15731(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
15732@code{double} and then passed.
15733
15734Unfortunately, some forms of debug information do not reliably indicate whether
15735a function is prototyped. If @value{GDBN} calls a function that is not marked
15736as prototyped, it consults @kbd{set coerce-float-to-double}.
15737
15738@table @code
a8f24a35 15739@kindex set coerce-float-to-double
1e698235
DJ
15740@item set coerce-float-to-double
15741@itemx set coerce-float-to-double on
15742Arguments of type @code{float} will be promoted to @code{double} when passed
15743to an unprototyped function. This is the default setting.
15744
15745@item set coerce-float-to-double off
15746Arguments of type @code{float} will be passed directly to unprototyped
15747functions.
9c16f35a
EZ
15748
15749@kindex show coerce-float-to-double
15750@item show coerce-float-to-double
15751Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
15752@end table
15753
f1212245
DJ
15754@kindex set cp-abi
15755@kindex show cp-abi
15756@value{GDBN} needs to know the ABI used for your program's C@t{++}
15757objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
15758used to build your application. @value{GDBN} only fully supports
15759programs with a single C@t{++} ABI; if your program contains code using
15760multiple C@t{++} ABI's or if @value{GDBN} can not identify your
15761program's ABI correctly, you can tell @value{GDBN} which ABI to use.
15762Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
15763before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
15764``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
15765use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
15766``auto''.
15767
15768@table @code
15769@item show cp-abi
15770Show the C@t{++} ABI currently in use.
15771
15772@item set cp-abi
15773With no argument, show the list of supported C@t{++} ABI's.
15774
15775@item set cp-abi @var{abi}
15776@itemx set cp-abi auto
15777Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
15778@end table
15779
8e04817f
AC
15780@node Messages/Warnings
15781@section Optional warnings and messages
104c1213 15782
9c16f35a
EZ
15783@cindex verbose operation
15784@cindex optional warnings
8e04817f
AC
15785By default, @value{GDBN} is silent about its inner workings. If you are
15786running on a slow machine, you may want to use the @code{set verbose}
15787command. This makes @value{GDBN} tell you when it does a lengthy
15788internal operation, so you will not think it has crashed.
104c1213 15789
8e04817f
AC
15790Currently, the messages controlled by @code{set verbose} are those
15791which announce that the symbol table for a source file is being read;
15792see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 15793
8e04817f
AC
15794@table @code
15795@kindex set verbose
15796@item set verbose on
15797Enables @value{GDBN} output of certain informational messages.
104c1213 15798
8e04817f
AC
15799@item set verbose off
15800Disables @value{GDBN} output of certain informational messages.
104c1213 15801
8e04817f
AC
15802@kindex show verbose
15803@item show verbose
15804Displays whether @code{set verbose} is on or off.
15805@end table
104c1213 15806
8e04817f
AC
15807By default, if @value{GDBN} encounters bugs in the symbol table of an
15808object file, it is silent; but if you are debugging a compiler, you may
15809find this information useful (@pxref{Symbol Errors, ,Errors reading
15810symbol files}).
104c1213 15811
8e04817f 15812@table @code
104c1213 15813
8e04817f
AC
15814@kindex set complaints
15815@item set complaints @var{limit}
15816Permits @value{GDBN} to output @var{limit} complaints about each type of
15817unusual symbols before becoming silent about the problem. Set
15818@var{limit} to zero to suppress all complaints; set it to a large number
15819to prevent complaints from being suppressed.
104c1213 15820
8e04817f
AC
15821@kindex show complaints
15822@item show complaints
15823Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 15824
8e04817f 15825@end table
104c1213 15826
8e04817f
AC
15827By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
15828lot of stupid questions to confirm certain commands. For example, if
15829you try to run a program which is already running:
104c1213 15830
474c8240 15831@smallexample
8e04817f
AC
15832(@value{GDBP}) run
15833The program being debugged has been started already.
15834Start it from the beginning? (y or n)
474c8240 15835@end smallexample
104c1213 15836
8e04817f
AC
15837If you are willing to unflinchingly face the consequences of your own
15838commands, you can disable this ``feature'':
104c1213 15839
8e04817f 15840@table @code
104c1213 15841
8e04817f
AC
15842@kindex set confirm
15843@cindex flinching
15844@cindex confirmation
15845@cindex stupid questions
15846@item set confirm off
15847Disables confirmation requests.
104c1213 15848
8e04817f
AC
15849@item set confirm on
15850Enables confirmation requests (the default).
104c1213 15851
8e04817f
AC
15852@kindex show confirm
15853@item show confirm
15854Displays state of confirmation requests.
15855
15856@end table
104c1213 15857
8e04817f
AC
15858@node Debugging Output
15859@section Optional messages about internal happenings
4644b6e3
EZ
15860@cindex optional debugging messages
15861
da316a69
EZ
15862@value{GDBN} has commands that enable optional debugging messages from
15863various @value{GDBN} subsystems; normally these commands are of
15864interest to @value{GDBN} maintainers, or when reporting a bug. This
15865section documents those commands.
15866
104c1213 15867@table @code
a8f24a35
EZ
15868@kindex set exec-done-display
15869@item set exec-done-display
15870Turns on or off the notification of asynchronous commands'
15871completion. When on, @value{GDBN} will print a message when an
15872asynchronous command finishes its execution. The default is off.
15873@kindex show exec-done-display
15874@item show exec-done-display
15875Displays the current setting of asynchronous command completion
15876notification.
4644b6e3
EZ
15877@kindex set debug
15878@cindex gdbarch debugging info
a8f24a35 15879@cindex architecture debugging info
8e04817f 15880@item set debug arch
a8f24a35 15881Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 15882@kindex show debug
8e04817f
AC
15883@item show debug arch
15884Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
15885@item set debug aix-thread
15886@cindex AIX threads
15887Display debugging messages about inner workings of the AIX thread
15888module.
15889@item show debug aix-thread
15890Show the current state of AIX thread debugging info display.
8e04817f 15891@item set debug event
4644b6e3 15892@cindex event debugging info
a8f24a35 15893Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 15894default is off.
8e04817f
AC
15895@item show debug event
15896Displays the current state of displaying @value{GDBN} event debugging
15897info.
8e04817f 15898@item set debug expression
4644b6e3 15899@cindex expression debugging info
721c2651
EZ
15900Turns on or off display of debugging info about @value{GDBN}
15901expression parsing. The default is off.
8e04817f 15902@item show debug expression
721c2651
EZ
15903Displays the current state of displaying debugging info about
15904@value{GDBN} expression parsing.
7453dc06 15905@item set debug frame
4644b6e3 15906@cindex frame debugging info
7453dc06
AC
15907Turns on or off display of @value{GDBN} frame debugging info. The
15908default is off.
7453dc06
AC
15909@item show debug frame
15910Displays the current state of displaying @value{GDBN} frame debugging
15911info.
30e91e0b
RC
15912@item set debug infrun
15913@cindex inferior debugging info
15914Turns on or off display of @value{GDBN} debugging info for running the inferior.
15915The default is off. @file{infrun.c} contains GDB's runtime state machine used
15916for implementing operations such as single-stepping the inferior.
15917@item show debug infrun
15918Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
15919@item set debug lin-lwp
15920@cindex @sc{gnu}/Linux LWP debug messages
15921@cindex Linux lightweight processes
721c2651 15922Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
15923@item show debug lin-lwp
15924Show the current state of Linux LWP debugging messages.
2b4855ab 15925@item set debug observer
4644b6e3 15926@cindex observer debugging info
2b4855ab
AC
15927Turns on or off display of @value{GDBN} observer debugging. This
15928includes info such as the notification of observable events.
2b4855ab
AC
15929@item show debug observer
15930Displays the current state of observer debugging.
8e04817f 15931@item set debug overload
4644b6e3 15932@cindex C@t{++} overload debugging info
8e04817f 15933Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 15934info. This includes info such as ranking of functions, etc. The default
8e04817f 15935is off.
8e04817f
AC
15936@item show debug overload
15937Displays the current state of displaying @value{GDBN} C@t{++} overload
15938debugging info.
8e04817f
AC
15939@cindex packets, reporting on stdout
15940@cindex serial connections, debugging
15941@item set debug remote
15942Turns on or off display of reports on all packets sent back and forth across
15943the serial line to the remote machine. The info is printed on the
15944@value{GDBN} standard output stream. The default is off.
8e04817f
AC
15945@item show debug remote
15946Displays the state of display of remote packets.
8e04817f
AC
15947@item set debug serial
15948Turns on or off display of @value{GDBN} serial debugging info. The
15949default is off.
8e04817f
AC
15950@item show debug serial
15951Displays the current state of displaying @value{GDBN} serial debugging
15952info.
c45da7e6
EZ
15953@item set debug solib-frv
15954@cindex FR-V shared-library debugging
15955Turns on or off debugging messages for FR-V shared-library code.
15956@item show debug solib-frv
15957Display the current state of FR-V shared-library code debugging
15958messages.
8e04817f 15959@item set debug target
4644b6e3 15960@cindex target debugging info
8e04817f
AC
15961Turns on or off display of @value{GDBN} target debugging info. This info
15962includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
15963default is 0. Set it to 1 to track events, and to 2 to also track the
15964value of large memory transfers. Changes to this flag do not take effect
15965until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
15966@item show debug target
15967Displays the current state of displaying @value{GDBN} target debugging
15968info.
c45da7e6 15969@item set debugvarobj
4644b6e3 15970@cindex variable object debugging info
8e04817f
AC
15971Turns on or off display of @value{GDBN} variable object debugging
15972info. The default is off.
c45da7e6 15973@item show debugvarobj
8e04817f
AC
15974Displays the current state of displaying @value{GDBN} variable object
15975debugging info.
15976@end table
104c1213 15977
8e04817f
AC
15978@node Sequences
15979@chapter Canned Sequences of Commands
104c1213 15980
8e04817f
AC
15981Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
15982command lists}), @value{GDBN} provides two ways to store sequences of
15983commands for execution as a unit: user-defined commands and command
15984files.
104c1213 15985
8e04817f 15986@menu
fcc73fe3
EZ
15987* Define:: How to define your own commands
15988* Hooks:: Hooks for user-defined commands
15989* Command Files:: How to write scripts of commands to be stored in a file
15990* Output:: Commands for controlled output
8e04817f 15991@end menu
104c1213 15992
8e04817f
AC
15993@node Define
15994@section User-defined commands
104c1213 15995
8e04817f 15996@cindex user-defined command
fcc73fe3 15997@cindex arguments, to user-defined commands
8e04817f
AC
15998A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
15999which you assign a new name as a command. This is done with the
16000@code{define} command. User commands may accept up to 10 arguments
16001separated by whitespace. Arguments are accessed within the user command
c03c782f 16002via @code{$arg0@dots{}$arg9}. A trivial example:
104c1213 16003
8e04817f
AC
16004@smallexample
16005define adder
16006 print $arg0 + $arg1 + $arg2
c03c782f 16007end
8e04817f 16008@end smallexample
104c1213
JM
16009
16010@noindent
8e04817f 16011To execute the command use:
104c1213 16012
8e04817f
AC
16013@smallexample
16014adder 1 2 3
16015@end smallexample
104c1213 16016
8e04817f
AC
16017@noindent
16018This defines the command @code{adder}, which prints the sum of
16019its three arguments. Note the arguments are text substitutions, so they may
16020reference variables, use complex expressions, or even perform inferior
16021functions calls.
104c1213 16022
fcc73fe3
EZ
16023@cindex argument count in user-defined commands
16024@cindex how many arguments (user-defined commands)
c03c782f
AS
16025In addition, @code{$argc} may be used to find out how many arguments have
16026been passed. This expands to a number in the range 0@dots{}10.
16027
16028@smallexample
16029define adder
16030 if $argc == 2
16031 print $arg0 + $arg1
16032 end
16033 if $argc == 3
16034 print $arg0 + $arg1 + $arg2
16035 end
16036end
16037@end smallexample
16038
104c1213 16039@table @code
104c1213 16040
8e04817f
AC
16041@kindex define
16042@item define @var{commandname}
16043Define a command named @var{commandname}. If there is already a command
16044by that name, you are asked to confirm that you want to redefine it.
104c1213 16045
8e04817f
AC
16046The definition of the command is made up of other @value{GDBN} command lines,
16047which are given following the @code{define} command. The end of these
16048commands is marked by a line containing @code{end}.
104c1213 16049
8e04817f 16050@kindex document
ca91424e 16051@kindex end@r{ (user-defined commands)}
8e04817f
AC
16052@item document @var{commandname}
16053Document the user-defined command @var{commandname}, so that it can be
16054accessed by @code{help}. The command @var{commandname} must already be
16055defined. This command reads lines of documentation just as @code{define}
16056reads the lines of the command definition, ending with @code{end}.
16057After the @code{document} command is finished, @code{help} on command
16058@var{commandname} displays the documentation you have written.
104c1213 16059
8e04817f
AC
16060You may use the @code{document} command again to change the
16061documentation of a command. Redefining the command with @code{define}
16062does not change the documentation.
104c1213 16063
c45da7e6
EZ
16064@kindex dont-repeat
16065@cindex don't repeat command
16066@item dont-repeat
16067Used inside a user-defined command, this tells @value{GDBN} that this
16068command should not be repeated when the user hits @key{RET}
16069(@pxref{Command Syntax, repeat last command}).
16070
8e04817f
AC
16071@kindex help user-defined
16072@item help user-defined
16073List all user-defined commands, with the first line of the documentation
16074(if any) for each.
104c1213 16075
8e04817f
AC
16076@kindex show user
16077@item show user
16078@itemx show user @var{commandname}
16079Display the @value{GDBN} commands used to define @var{commandname} (but
16080not its documentation). If no @var{commandname} is given, display the
16081definitions for all user-defined commands.
104c1213 16082
fcc73fe3 16083@cindex infinite recursion in user-defined commands
20f01a46
DH
16084@kindex show max-user-call-depth
16085@kindex set max-user-call-depth
16086@item show max-user-call-depth
5ca0cb28
DH
16087@itemx set max-user-call-depth
16088The value of @code{max-user-call-depth} controls how many recursion
16089levels are allowed in user-defined commands before GDB suspects an
16090infinite recursion and aborts the command.
104c1213
JM
16091@end table
16092
fcc73fe3
EZ
16093In addition to the above commands, user-defined commands frequently
16094use control flow commands, described in @ref{Command Files}.
16095
8e04817f
AC
16096When user-defined commands are executed, the
16097commands of the definition are not printed. An error in any command
16098stops execution of the user-defined command.
104c1213 16099
8e04817f
AC
16100If used interactively, commands that would ask for confirmation proceed
16101without asking when used inside a user-defined command. Many @value{GDBN}
16102commands that normally print messages to say what they are doing omit the
16103messages when used in a user-defined command.
104c1213 16104
8e04817f
AC
16105@node Hooks
16106@section User-defined command hooks
16107@cindex command hooks
16108@cindex hooks, for commands
16109@cindex hooks, pre-command
104c1213 16110
8e04817f 16111@kindex hook
8e04817f
AC
16112You may define @dfn{hooks}, which are a special kind of user-defined
16113command. Whenever you run the command @samp{foo}, if the user-defined
16114command @samp{hook-foo} exists, it is executed (with no arguments)
16115before that command.
104c1213 16116
8e04817f
AC
16117@cindex hooks, post-command
16118@kindex hookpost
8e04817f
AC
16119A hook may also be defined which is run after the command you executed.
16120Whenever you run the command @samp{foo}, if the user-defined command
16121@samp{hookpost-foo} exists, it is executed (with no arguments) after
16122that command. Post-execution hooks may exist simultaneously with
16123pre-execution hooks, for the same command.
104c1213 16124
8e04817f 16125It is valid for a hook to call the command which it hooks. If this
9f1c6395 16126occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 16127
8e04817f
AC
16128@c It would be nice if hookpost could be passed a parameter indicating
16129@c if the command it hooks executed properly or not. FIXME!
104c1213 16130
8e04817f
AC
16131@kindex stop@r{, a pseudo-command}
16132In addition, a pseudo-command, @samp{stop} exists. Defining
16133(@samp{hook-stop}) makes the associated commands execute every time
16134execution stops in your program: before breakpoint commands are run,
16135displays are printed, or the stack frame is printed.
104c1213 16136
8e04817f
AC
16137For example, to ignore @code{SIGALRM} signals while
16138single-stepping, but treat them normally during normal execution,
16139you could define:
104c1213 16140
474c8240 16141@smallexample
8e04817f
AC
16142define hook-stop
16143handle SIGALRM nopass
16144end
104c1213 16145
8e04817f
AC
16146define hook-run
16147handle SIGALRM pass
16148end
104c1213 16149
8e04817f
AC
16150define hook-continue
16151handle SIGLARM pass
16152end
474c8240 16153@end smallexample
104c1213 16154
8e04817f 16155As a further example, to hook at the begining and end of the @code{echo}
b383017d 16156command, and to add extra text to the beginning and end of the message,
8e04817f 16157you could define:
104c1213 16158
474c8240 16159@smallexample
8e04817f
AC
16160define hook-echo
16161echo <<<---
16162end
104c1213 16163
8e04817f
AC
16164define hookpost-echo
16165echo --->>>\n
16166end
104c1213 16167
8e04817f
AC
16168(@value{GDBP}) echo Hello World
16169<<<---Hello World--->>>
16170(@value{GDBP})
104c1213 16171
474c8240 16172@end smallexample
104c1213 16173
8e04817f
AC
16174You can define a hook for any single-word command in @value{GDBN}, but
16175not for command aliases; you should define a hook for the basic command
c1468174 16176name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
16177@c FIXME! So how does Joe User discover whether a command is an alias
16178@c or not?
16179If an error occurs during the execution of your hook, execution of
16180@value{GDBN} commands stops and @value{GDBN} issues a prompt
16181(before the command that you actually typed had a chance to run).
104c1213 16182
8e04817f
AC
16183If you try to define a hook which does not match any known command, you
16184get a warning from the @code{define} command.
c906108c 16185
8e04817f
AC
16186@node Command Files
16187@section Command files
c906108c 16188
8e04817f 16189@cindex command files
fcc73fe3 16190@cindex scripting commands
6fc08d32
EZ
16191A command file for @value{GDBN} is a text file made of lines that are
16192@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
16193also be included. An empty line in a command file does nothing; it
16194does not mean to repeat the last command, as it would from the
16195terminal.
c906108c 16196
6fc08d32
EZ
16197You can request the execution of a command file with the @code{source}
16198command:
c906108c 16199
8e04817f
AC
16200@table @code
16201@kindex source
ca91424e 16202@cindex execute commands from a file
8e04817f
AC
16203@item source @var{filename}
16204Execute the command file @var{filename}.
c906108c
SS
16205@end table
16206
fcc73fe3
EZ
16207The lines in a command file are generally executed sequentially,
16208unless the order of execution is changed by one of the
16209@emph{flow-control commands} described below. The commands are not
a71ec265
DH
16210printed as they are executed. An error in any command terminates
16211execution of the command file and control is returned to the console.
c906108c 16212
8e04817f
AC
16213Commands that would ask for confirmation if used interactively proceed
16214without asking when used in a command file. Many @value{GDBN} commands that
16215normally print messages to say what they are doing omit the messages
16216when called from command files.
c906108c 16217
8e04817f
AC
16218@value{GDBN} also accepts command input from standard input. In this
16219mode, normal output goes to standard output and error output goes to
16220standard error. Errors in a command file supplied on standard input do
6fc08d32 16221not terminate execution of the command file---execution continues with
8e04817f 16222the next command.
c906108c 16223
474c8240 16224@smallexample
8e04817f 16225gdb < cmds > log 2>&1
474c8240 16226@end smallexample
c906108c 16227
8e04817f
AC
16228(The syntax above will vary depending on the shell used.) This example
16229will execute commands from the file @file{cmds}. All output and errors
16230would be directed to @file{log}.
c906108c 16231
fcc73fe3
EZ
16232Since commands stored on command files tend to be more general than
16233commands typed interactively, they frequently need to deal with
16234complicated situations, such as different or unexpected values of
16235variables and symbols, changes in how the program being debugged is
16236built, etc. @value{GDBN} provides a set of flow-control commands to
16237deal with these complexities. Using these commands, you can write
16238complex scripts that loop over data structures, execute commands
16239conditionally, etc.
16240
16241@table @code
16242@kindex if
16243@kindex else
16244@item if
16245@itemx else
16246This command allows to include in your script conditionally executed
16247commands. The @code{if} command takes a single argument, which is an
16248expression to evaluate. It is followed by a series of commands that
16249are executed only if the expression is true (its value is nonzero).
16250There can then optionally be an @code{else} line, followed by a series
16251of commands that are only executed if the expression was false. The
16252end of the list is marked by a line containing @code{end}.
16253
16254@kindex while
16255@item while
16256This command allows to write loops. Its syntax is similar to
16257@code{if}: the command takes a single argument, which is an expression
16258to evaluate, and must be followed by the commands to execute, one per
16259line, terminated by an @code{end}. These commands are called the
16260@dfn{body} of the loop. The commands in the body of @code{while} are
16261executed repeatedly as long as the expression evaluates to true.
16262
16263@kindex loop_break
16264@item loop_break
16265This command exits the @code{while} loop in whose body it is included.
16266Execution of the script continues after that @code{while}s @code{end}
16267line.
16268
16269@kindex loop_continue
16270@item loop_continue
16271This command skips the execution of the rest of the body of commands
16272in the @code{while} loop in whose body it is included. Execution
16273branches to the beginning of the @code{while} loop, where it evaluates
16274the controlling expression.
ca91424e
EZ
16275
16276@kindex end@r{ (if/else/while commands)}
16277@item end
16278Terminate the block of commands that are the body of @code{if},
16279@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
16280@end table
16281
16282
8e04817f
AC
16283@node Output
16284@section Commands for controlled output
c906108c 16285
8e04817f
AC
16286During the execution of a command file or a user-defined command, normal
16287@value{GDBN} output is suppressed; the only output that appears is what is
16288explicitly printed by the commands in the definition. This section
16289describes three commands useful for generating exactly the output you
16290want.
c906108c
SS
16291
16292@table @code
8e04817f
AC
16293@kindex echo
16294@item echo @var{text}
16295@c I do not consider backslash-space a standard C escape sequence
16296@c because it is not in ANSI.
16297Print @var{text}. Nonprinting characters can be included in
16298@var{text} using C escape sequences, such as @samp{\n} to print a
16299newline. @strong{No newline is printed unless you specify one.}
16300In addition to the standard C escape sequences, a backslash followed
16301by a space stands for a space. This is useful for displaying a
16302string with spaces at the beginning or the end, since leading and
16303trailing spaces are otherwise trimmed from all arguments.
16304To print @samp{@w{ }and foo =@w{ }}, use the command
16305@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 16306
8e04817f
AC
16307A backslash at the end of @var{text} can be used, as in C, to continue
16308the command onto subsequent lines. For example,
c906108c 16309
474c8240 16310@smallexample
8e04817f
AC
16311echo This is some text\n\
16312which is continued\n\
16313onto several lines.\n
474c8240 16314@end smallexample
c906108c 16315
8e04817f 16316produces the same output as
c906108c 16317
474c8240 16318@smallexample
8e04817f
AC
16319echo This is some text\n
16320echo which is continued\n
16321echo onto several lines.\n
474c8240 16322@end smallexample
c906108c 16323
8e04817f
AC
16324@kindex output
16325@item output @var{expression}
16326Print the value of @var{expression} and nothing but that value: no
16327newlines, no @samp{$@var{nn} = }. The value is not entered in the
16328value history either. @xref{Expressions, ,Expressions}, for more information
16329on expressions.
c906108c 16330
8e04817f
AC
16331@item output/@var{fmt} @var{expression}
16332Print the value of @var{expression} in format @var{fmt}. You can use
16333the same formats as for @code{print}. @xref{Output Formats,,Output
16334formats}, for more information.
c906108c 16335
8e04817f
AC
16336@kindex printf
16337@item printf @var{string}, @var{expressions}@dots{}
16338Print the values of the @var{expressions} under the control of
16339@var{string}. The @var{expressions} are separated by commas and may be
16340either numbers or pointers. Their values are printed as specified by
16341@var{string}, exactly as if your program were to execute the C
16342subroutine
16343@c FIXME: the above implies that at least all ANSI C formats are
16344@c supported, but it isn't true: %E and %G don't work (or so it seems).
16345@c Either this is a bug, or the manual should document what formats are
16346@c supported.
c906108c 16347
474c8240 16348@smallexample
8e04817f 16349printf (@var{string}, @var{expressions}@dots{});
474c8240 16350@end smallexample
c906108c 16351
8e04817f 16352For example, you can print two values in hex like this:
c906108c 16353
8e04817f
AC
16354@smallexample
16355printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
16356@end smallexample
c906108c 16357
8e04817f
AC
16358The only backslash-escape sequences that you can use in the format
16359string are the simple ones that consist of backslash followed by a
16360letter.
c906108c
SS
16361@end table
16362
21c294e6
AC
16363@node Interpreters
16364@chapter Command Interpreters
16365@cindex command interpreters
16366
16367@value{GDBN} supports multiple command interpreters, and some command
16368infrastructure to allow users or user interface writers to switch
16369between interpreters or run commands in other interpreters.
16370
16371@value{GDBN} currently supports two command interpreters, the console
16372interpreter (sometimes called the command-line interpreter or @sc{cli})
16373and the machine interface interpreter (or @sc{gdb/mi}). This manual
16374describes both of these interfaces in great detail.
16375
16376By default, @value{GDBN} will start with the console interpreter.
16377However, the user may choose to start @value{GDBN} with another
16378interpreter by specifying the @option{-i} or @option{--interpreter}
16379startup options. Defined interpreters include:
16380
16381@table @code
16382@item console
16383@cindex console interpreter
16384The traditional console or command-line interpreter. This is the most often
16385used interpreter with @value{GDBN}. With no interpreter specified at runtime,
16386@value{GDBN} will use this interpreter.
16387
16388@item mi
16389@cindex mi interpreter
16390The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
16391by programs wishing to use @value{GDBN} as a backend for a debugger GUI
16392or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
16393Interface}.
16394
16395@item mi2
16396@cindex mi2 interpreter
16397The current @sc{gdb/mi} interface.
16398
16399@item mi1
16400@cindex mi1 interpreter
16401The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
16402
16403@end table
16404
16405@cindex invoke another interpreter
16406The interpreter being used by @value{GDBN} may not be dynamically
16407switched at runtime. Although possible, this could lead to a very
16408precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
16409enters the command "interpreter-set console" in a console view,
16410@value{GDBN} would switch to using the console interpreter, rendering
16411the IDE inoperable!
16412
16413@kindex interpreter-exec
16414Although you may only choose a single interpreter at startup, you may execute
16415commands in any interpreter from the current interpreter using the appropriate
16416command. If you are running the console interpreter, simply use the
16417@code{interpreter-exec} command:
16418
16419@smallexample
16420interpreter-exec mi "-data-list-register-names"
16421@end smallexample
16422
16423@sc{gdb/mi} has a similar command, although it is only available in versions of
16424@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
16425
8e04817f
AC
16426@node TUI
16427@chapter @value{GDBN} Text User Interface
16428@cindex TUI
d0d5df6f 16429@cindex Text User Interface
c906108c 16430
8e04817f
AC
16431@menu
16432* TUI Overview:: TUI overview
16433* TUI Keys:: TUI key bindings
7cf36c78 16434* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
16435* TUI Commands:: TUI specific commands
16436* TUI Configuration:: TUI configuration variables
16437@end menu
c906108c 16438
d0d5df6f
AC
16439The @value{GDBN} Text User Interface, TUI in short, is a terminal
16440interface which uses the @code{curses} library to show the source
16441file, the assembly output, the program registers and @value{GDBN}
16442commands in separate text windows.
16443
16444The TUI is enabled by invoking @value{GDBN} using either
16445@pindex gdbtui
16446@samp{gdbtui} or @samp{gdb -tui}.
c906108c 16447
8e04817f
AC
16448@node TUI Overview
16449@section TUI overview
c906108c 16450
8e04817f
AC
16451The TUI has two display modes that can be switched while
16452@value{GDBN} runs:
c906108c 16453
8e04817f
AC
16454@itemize @bullet
16455@item
16456A curses (or TUI) mode in which it displays several text
16457windows on the terminal.
c906108c 16458
8e04817f
AC
16459@item
16460A standard mode which corresponds to the @value{GDBN} configured without
16461the TUI.
16462@end itemize
c906108c 16463
8e04817f
AC
16464In the TUI mode, @value{GDBN} can display several text window
16465on the terminal:
c906108c 16466
8e04817f
AC
16467@table @emph
16468@item command
16469This window is the @value{GDBN} command window with the @value{GDBN}
16470prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
16471managed using readline but through the TUI. The @emph{command}
16472window is always visible.
c906108c 16473
8e04817f
AC
16474@item source
16475The source window shows the source file of the program. The current
16476line as well as active breakpoints are displayed in this window.
c906108c 16477
8e04817f
AC
16478@item assembly
16479The assembly window shows the disassembly output of the program.
c906108c 16480
8e04817f
AC
16481@item register
16482This window shows the processor registers. It detects when
16483a register is changed and when this is the case, registers that have
6a1b180d 16484changed are highlighted.
c906108c 16485
c906108c
SS
16486@end table
16487
269c21fe
SC
16488The source and assembly windows show the current program position
16489by highlighting the current line and marking them with the @samp{>} marker.
16490Breakpoints are also indicated with two markers. A first one
16491indicates the breakpoint type:
16492
16493@table @code
16494@item B
16495Breakpoint which was hit at least once.
16496
16497@item b
16498Breakpoint which was never hit.
16499
16500@item H
16501Hardware breakpoint which was hit at least once.
16502
16503@item h
16504Hardware breakpoint which was never hit.
16505
16506@end table
16507
16508The second marker indicates whether the breakpoint is enabled or not:
16509
16510@table @code
16511@item +
16512Breakpoint is enabled.
16513
16514@item -
16515Breakpoint is disabled.
16516
16517@end table
16518
8e04817f
AC
16519The source, assembly and register windows are attached to the thread
16520and the frame position. They are updated when the current thread
16521changes, when the frame changes or when the program counter changes.
16522These three windows are arranged by the TUI according to several
16523layouts. The layout defines which of these three windows are visible.
16524The following layouts are available:
c906108c 16525
8e04817f
AC
16526@itemize @bullet
16527@item
16528source
2df3850c 16529
8e04817f
AC
16530@item
16531assembly
16532
16533@item
16534source and assembly
16535
16536@item
16537source and registers
c906108c 16538
8e04817f
AC
16539@item
16540assembly and registers
2df3850c 16541
8e04817f 16542@end itemize
c906108c 16543
b7bb15bc
SC
16544On top of the command window a status line gives various information
16545concerning the current process begin debugged. The status line is
16546updated when the information it shows changes. The following fields
16547are displayed:
16548
16549@table @emph
16550@item target
16551Indicates the current gdb target
16552(@pxref{Targets, ,Specifying a Debugging Target}).
16553
16554@item process
16555Gives information about the current process or thread number.
16556When no process is being debugged, this field is set to @code{No process}.
16557
16558@item function
16559Gives the current function name for the selected frame.
16560The name is demangled if demangling is turned on (@pxref{Print Settings}).
16561When there is no symbol corresponding to the current program counter
16562the string @code{??} is displayed.
16563
16564@item line
16565Indicates the current line number for the selected frame.
16566When the current line number is not known the string @code{??} is displayed.
16567
16568@item pc
16569Indicates the current program counter address.
16570
16571@end table
16572
8e04817f
AC
16573@node TUI Keys
16574@section TUI Key Bindings
16575@cindex TUI key bindings
c906108c 16576
8e04817f
AC
16577The TUI installs several key bindings in the readline keymaps
16578(@pxref{Command Line Editing}).
16579They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
16580directly on the TUI layout and windows. The TUI also provides
16581a @emph{SingleKey} keymap which binds several keys directly to
16582@value{GDBN} commands. The following key bindings
8e04817f 16583are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 16584
8e04817f
AC
16585@table @kbd
16586@kindex C-x C-a
16587@item C-x C-a
16588@kindex C-x a
16589@itemx C-x a
16590@kindex C-x A
16591@itemx C-x A
16592Enter or leave the TUI mode. When the TUI mode is left,
16593the curses window management is left and @value{GDBN} operates using
16594its standard mode writing on the terminal directly. When the TUI
16595mode is entered, the control is given back to the curses windows.
16596The screen is then refreshed.
c906108c 16597
8e04817f
AC
16598@kindex C-x 1
16599@item C-x 1
16600Use a TUI layout with only one window. The layout will
16601either be @samp{source} or @samp{assembly}. When the TUI mode
16602is not active, it will switch to the TUI mode.
2df3850c 16603
8e04817f 16604Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 16605
8e04817f
AC
16606@kindex C-x 2
16607@item C-x 2
16608Use a TUI layout with at least two windows. When the current
16609layout shows already two windows, a next layout with two windows is used.
16610When a new layout is chosen, one window will always be common to the
16611previous layout and the new one.
c906108c 16612
8e04817f 16613Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 16614
72ffddc9
SC
16615@kindex C-x o
16616@item C-x o
16617Change the active window. The TUI associates several key bindings
16618(like scrolling and arrow keys) to the active window. This command
16619gives the focus to the next TUI window.
16620
16621Think of it as the Emacs @kbd{C-x o} binding.
16622
7cf36c78
SC
16623@kindex C-x s
16624@item C-x s
16625Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
16626(@pxref{TUI Single Key Mode}).
16627
c906108c
SS
16628@end table
16629
8e04817f 16630The following key bindings are handled only by the TUI mode:
5d161b24 16631
8e04817f
AC
16632@table @key
16633@kindex PgUp
16634@item PgUp
16635Scroll the active window one page up.
c906108c 16636
8e04817f
AC
16637@kindex PgDn
16638@item PgDn
16639Scroll the active window one page down.
c906108c 16640
8e04817f
AC
16641@kindex Up
16642@item Up
16643Scroll the active window one line up.
c906108c 16644
8e04817f
AC
16645@kindex Down
16646@item Down
16647Scroll the active window one line down.
c906108c 16648
8e04817f
AC
16649@kindex Left
16650@item Left
16651Scroll the active window one column left.
c906108c 16652
8e04817f
AC
16653@kindex Right
16654@item Right
16655Scroll the active window one column right.
c906108c 16656
8e04817f
AC
16657@kindex C-L
16658@item C-L
16659Refresh the screen.
c906108c 16660
8e04817f 16661@end table
c906108c 16662
8e04817f 16663In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
16664for scrolling. This means they are available for readline when the
16665active window is the command window. When the command window
16666does not have the focus, it is necessary to use other readline
16667key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 16668
7cf36c78
SC
16669@node TUI Single Key Mode
16670@section TUI Single Key Mode
16671@cindex TUI single key mode
16672
16673The TUI provides a @emph{SingleKey} mode in which it installs a particular
16674key binding in the readline keymaps to connect single keys to
b383017d 16675some gdb commands.
7cf36c78
SC
16676
16677@table @kbd
16678@kindex c @r{(SingleKey TUI key)}
16679@item c
16680continue
16681
16682@kindex d @r{(SingleKey TUI key)}
16683@item d
16684down
16685
16686@kindex f @r{(SingleKey TUI key)}
16687@item f
16688finish
16689
16690@kindex n @r{(SingleKey TUI key)}
16691@item n
16692next
16693
16694@kindex q @r{(SingleKey TUI key)}
16695@item q
16696exit the @emph{SingleKey} mode.
16697
16698@kindex r @r{(SingleKey TUI key)}
16699@item r
16700run
16701
16702@kindex s @r{(SingleKey TUI key)}
16703@item s
16704step
16705
16706@kindex u @r{(SingleKey TUI key)}
16707@item u
16708up
16709
16710@kindex v @r{(SingleKey TUI key)}
16711@item v
16712info locals
16713
16714@kindex w @r{(SingleKey TUI key)}
16715@item w
16716where
16717
16718@end table
16719
16720Other keys temporarily switch to the @value{GDBN} command prompt.
16721The key that was pressed is inserted in the editing buffer so that
16722it is possible to type most @value{GDBN} commands without interaction
16723with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
16724@emph{SingleKey} mode is restored. The only way to permanently leave
16725this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
16726
16727
8e04817f
AC
16728@node TUI Commands
16729@section TUI specific commands
16730@cindex TUI commands
16731
16732The TUI has specific commands to control the text windows.
16733These commands are always available, that is they do not depend on
16734the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
16735is in the standard mode, using these commands will automatically switch
16736in the TUI mode.
c906108c
SS
16737
16738@table @code
3d757584
SC
16739@item info win
16740@kindex info win
16741List and give the size of all displayed windows.
16742
8e04817f 16743@item layout next
4644b6e3 16744@kindex layout
8e04817f 16745Display the next layout.
2df3850c 16746
8e04817f 16747@item layout prev
8e04817f 16748Display the previous layout.
c906108c 16749
8e04817f 16750@item layout src
8e04817f 16751Display the source window only.
c906108c 16752
8e04817f 16753@item layout asm
8e04817f 16754Display the assembly window only.
c906108c 16755
8e04817f 16756@item layout split
8e04817f 16757Display the source and assembly window.
c906108c 16758
8e04817f 16759@item layout regs
8e04817f
AC
16760Display the register window together with the source or assembly window.
16761
16762@item focus next | prev | src | asm | regs | split
16763@kindex focus
16764Set the focus to the named window.
16765This command allows to change the active window so that scrolling keys
16766can be affected to another window.
c906108c 16767
8e04817f
AC
16768@item refresh
16769@kindex refresh
16770Refresh the screen. This is similar to using @key{C-L} key.
c906108c 16771
6a1b180d
SC
16772@item tui reg float
16773@kindex tui reg
16774Show the floating point registers in the register window.
16775
16776@item tui reg general
16777Show the general registers in the register window.
16778
16779@item tui reg next
16780Show the next register group. The list of register groups as well as
16781their order is target specific. The predefined register groups are the
16782following: @code{general}, @code{float}, @code{system}, @code{vector},
16783@code{all}, @code{save}, @code{restore}.
16784
16785@item tui reg system
16786Show the system registers in the register window.
16787
8e04817f
AC
16788@item update
16789@kindex update
16790Update the source window and the current execution point.
c906108c 16791
8e04817f
AC
16792@item winheight @var{name} +@var{count}
16793@itemx winheight @var{name} -@var{count}
16794@kindex winheight
16795Change the height of the window @var{name} by @var{count}
16796lines. Positive counts increase the height, while negative counts
16797decrease it.
2df3850c 16798
c45da7e6
EZ
16799@item tabset
16800@kindex tabset @var{nchars}
16801Set the width of tab stops to be @var{nchars} characters.
16802
c906108c
SS
16803@end table
16804
8e04817f
AC
16805@node TUI Configuration
16806@section TUI configuration variables
16807@cindex TUI configuration variables
c906108c 16808
8e04817f
AC
16809The TUI has several configuration variables that control the
16810appearance of windows on the terminal.
c906108c 16811
8e04817f
AC
16812@table @code
16813@item set tui border-kind @var{kind}
16814@kindex set tui border-kind
16815Select the border appearance for the source, assembly and register windows.
16816The possible values are the following:
16817@table @code
16818@item space
16819Use a space character to draw the border.
c906108c 16820
8e04817f
AC
16821@item ascii
16822Use ascii characters + - and | to draw the border.
c906108c 16823
8e04817f
AC
16824@item acs
16825Use the Alternate Character Set to draw the border. The border is
16826drawn using character line graphics if the terminal supports them.
c78b4128 16827
8e04817f 16828@end table
c78b4128 16829
8e04817f
AC
16830@item set tui active-border-mode @var{mode}
16831@kindex set tui active-border-mode
16832Select the attributes to display the border of the active window.
16833The possible values are @code{normal}, @code{standout}, @code{reverse},
16834@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 16835
8e04817f
AC
16836@item set tui border-mode @var{mode}
16837@kindex set tui border-mode
16838Select the attributes to display the border of other windows.
16839The @var{mode} can be one of the following:
16840@table @code
16841@item normal
16842Use normal attributes to display the border.
c906108c 16843
8e04817f
AC
16844@item standout
16845Use standout mode.
c906108c 16846
8e04817f
AC
16847@item reverse
16848Use reverse video mode.
c906108c 16849
8e04817f
AC
16850@item half
16851Use half bright mode.
c906108c 16852
8e04817f
AC
16853@item half-standout
16854Use half bright and standout mode.
c906108c 16855
8e04817f
AC
16856@item bold
16857Use extra bright or bold mode.
c78b4128 16858
8e04817f
AC
16859@item bold-standout
16860Use extra bright or bold and standout mode.
c78b4128 16861
8e04817f 16862@end table
c78b4128 16863
8e04817f 16864@end table
c78b4128 16865
8e04817f
AC
16866@node Emacs
16867@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 16868
8e04817f
AC
16869@cindex Emacs
16870@cindex @sc{gnu} Emacs
16871A special interface allows you to use @sc{gnu} Emacs to view (and
16872edit) the source files for the program you are debugging with
16873@value{GDBN}.
c906108c 16874
8e04817f
AC
16875To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
16876executable file you want to debug as an argument. This command starts
16877@value{GDBN} as a subprocess of Emacs, with input and output through a newly
16878created Emacs buffer.
16879@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 16880
8e04817f
AC
16881Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
16882things:
c906108c 16883
8e04817f
AC
16884@itemize @bullet
16885@item
16886All ``terminal'' input and output goes through the Emacs buffer.
16887@end itemize
c906108c 16888
8e04817f
AC
16889This applies both to @value{GDBN} commands and their output, and to the input
16890and output done by the program you are debugging.
bf0184be 16891
8e04817f
AC
16892This is useful because it means that you can copy the text of previous
16893commands and input them again; you can even use parts of the output
16894in this way.
bf0184be 16895
8e04817f
AC
16896All the facilities of Emacs' Shell mode are available for interacting
16897with your program. In particular, you can send signals the usual
16898way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
16899stop.
bf0184be 16900
8e04817f 16901@itemize @bullet
bf0184be 16902@item
8e04817f
AC
16903@value{GDBN} displays source code through Emacs.
16904@end itemize
bf0184be 16905
8e04817f
AC
16906Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
16907source file for that frame and puts an arrow (@samp{=>}) at the
16908left margin of the current line. Emacs uses a separate buffer for
16909source display, and splits the screen to show both your @value{GDBN} session
16910and the source.
bf0184be 16911
8e04817f
AC
16912Explicit @value{GDBN} @code{list} or search commands still produce output as
16913usual, but you probably have no reason to use them from Emacs.
c906108c 16914
64fabec2
AC
16915If you specify an absolute file name when prompted for the @kbd{M-x
16916gdb} argument, then Emacs sets your current working directory to where
16917your program resides. If you only specify the file name, then Emacs
16918sets your current working directory to to the directory associated
16919with the previous buffer. In this case, @value{GDBN} may find your
16920program by searching your environment's @code{PATH} variable, but on
16921some operating systems it might not find the source. So, although the
16922@value{GDBN} input and output session proceeds normally, the auxiliary
16923buffer does not display the current source and line of execution.
16924
16925The initial working directory of @value{GDBN} is printed on the top
16926line of the @value{GDBN} I/O buffer and this serves as a default for
16927the commands that specify files for @value{GDBN} to operate
16928on. @xref{Files, ,Commands to specify files}.
16929
16930By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
16931need to call @value{GDBN} by a different name (for example, if you
16932keep several configurations around, with different names) you can
16933customize the Emacs variable @code{gud-gdb-command-name} to run the
16934one you want.
8e04817f
AC
16935
16936In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
16937addition to the standard Shell mode commands:
c906108c 16938
8e04817f
AC
16939@table @kbd
16940@item C-h m
16941Describe the features of Emacs' @value{GDBN} Mode.
c906108c 16942
64fabec2 16943@item C-c C-s
8e04817f
AC
16944Execute to another source line, like the @value{GDBN} @code{step} command; also
16945update the display window to show the current file and location.
c906108c 16946
64fabec2 16947@item C-c C-n
8e04817f
AC
16948Execute to next source line in this function, skipping all function
16949calls, like the @value{GDBN} @code{next} command. Then update the display window
16950to show the current file and location.
c906108c 16951
64fabec2 16952@item C-c C-i
8e04817f
AC
16953Execute one instruction, like the @value{GDBN} @code{stepi} command; update
16954display window accordingly.
c906108c 16955
8e04817f
AC
16956@item C-c C-f
16957Execute until exit from the selected stack frame, like the @value{GDBN}
16958@code{finish} command.
c906108c 16959
64fabec2 16960@item C-c C-r
8e04817f
AC
16961Continue execution of your program, like the @value{GDBN} @code{continue}
16962command.
b433d00b 16963
64fabec2 16964@item C-c <
8e04817f
AC
16965Go up the number of frames indicated by the numeric argument
16966(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
16967like the @value{GDBN} @code{up} command.
b433d00b 16968
64fabec2 16969@item C-c >
8e04817f
AC
16970Go down the number of frames indicated by the numeric argument, like the
16971@value{GDBN} @code{down} command.
8e04817f 16972@end table
c906108c 16973
64fabec2 16974In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 16975tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 16976
64fabec2
AC
16977If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
16978shows a backtrace when the @value{GDBN} I/O buffer is current. Move
16979point to any frame in the stack and type @key{RET} to make it become the
16980current frame and display the associated source in the source buffer.
16981Alternatively, click @kbd{Mouse-2} to make the selected frame become the
16982current one.
16983
8e04817f
AC
16984If you accidentally delete the source-display buffer, an easy way to get
16985it back is to type the command @code{f} in the @value{GDBN} buffer, to
16986request a frame display; when you run under Emacs, this recreates
16987the source buffer if necessary to show you the context of the current
16988frame.
c906108c 16989
8e04817f
AC
16990The source files displayed in Emacs are in ordinary Emacs buffers
16991which are visiting the source files in the usual way. You can edit
16992the files with these buffers if you wish; but keep in mind that @value{GDBN}
16993communicates with Emacs in terms of line numbers. If you add or
16994delete lines from the text, the line numbers that @value{GDBN} knows cease
16995to correspond properly with the code.
b383017d 16996
64fabec2
AC
16997The description given here is for GNU Emacs version 21.3 and a more
16998detailed description of its interaction with @value{GDBN} is given in
16999the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 17000
8e04817f
AC
17001@c The following dropped because Epoch is nonstandard. Reactivate
17002@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
17003@ignore
17004@kindex Emacs Epoch environment
17005@kindex Epoch
17006@kindex inspect
c906108c 17007
8e04817f
AC
17008Version 18 of @sc{gnu} Emacs has a built-in window system
17009called the @code{epoch}
17010environment. Users of this environment can use a new command,
17011@code{inspect} which performs identically to @code{print} except that
17012each value is printed in its own window.
17013@end ignore
c906108c 17014
922fbb7b
AC
17015
17016@node GDB/MI
17017@chapter The @sc{gdb/mi} Interface
17018
17019@unnumberedsec Function and Purpose
17020
17021@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
17022@sc{gdb/mi} is a line based machine oriented text interface to
17023@value{GDBN} and is activated by specifying using the
17024@option{--interpreter} command line option (@pxref{Mode Options}). It
17025is specifically intended to support the development of systems which
17026use the debugger as just one small component of a larger system.
922fbb7b
AC
17027
17028This chapter is a specification of the @sc{gdb/mi} interface. It is written
17029in the form of a reference manual.
17030
17031Note that @sc{gdb/mi} is still under construction, so some of the
17032features described below are incomplete and subject to change.
17033
17034@unnumberedsec Notation and Terminology
17035
17036@cindex notational conventions, for @sc{gdb/mi}
17037This chapter uses the following notation:
17038
17039@itemize @bullet
17040@item
17041@code{|} separates two alternatives.
17042
17043@item
17044@code{[ @var{something} ]} indicates that @var{something} is optional:
17045it may or may not be given.
17046
17047@item
17048@code{( @var{group} )*} means that @var{group} inside the parentheses
17049may repeat zero or more times.
17050
17051@item
17052@code{( @var{group} )+} means that @var{group} inside the parentheses
17053may repeat one or more times.
17054
17055@item
17056@code{"@var{string}"} means a literal @var{string}.
17057@end itemize
17058
17059@ignore
17060@heading Dependencies
17061@end ignore
17062
17063@heading Acknowledgments
17064
17065In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
17066Elena Zannoni.
17067
17068@menu
17069* GDB/MI Command Syntax::
17070* GDB/MI Compatibility with CLI::
17071* GDB/MI Output Records::
17072* GDB/MI Command Description Format::
17073* GDB/MI Breakpoint Table Commands::
17074* GDB/MI Data Manipulation::
17075* GDB/MI Program Control::
17076* GDB/MI Miscellaneous Commands::
17077@ignore
17078* GDB/MI Kod Commands::
17079* GDB/MI Memory Overlay Commands::
17080* GDB/MI Signal Handling Commands::
17081@end ignore
17082* GDB/MI Stack Manipulation::
17083* GDB/MI Symbol Query::
17084* GDB/MI Target Manipulation::
17085* GDB/MI Thread Commands::
17086* GDB/MI Tracepoint Commands::
17087* GDB/MI Variable Objects::
17088@end menu
17089
17090@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17091@node GDB/MI Command Syntax
17092@section @sc{gdb/mi} Command Syntax
17093
17094@menu
17095* GDB/MI Input Syntax::
17096* GDB/MI Output Syntax::
17097* GDB/MI Simple Examples::
17098@end menu
17099
17100@node GDB/MI Input Syntax
17101@subsection @sc{gdb/mi} Input Syntax
17102
17103@cindex input syntax for @sc{gdb/mi}
17104@cindex @sc{gdb/mi}, input syntax
17105@table @code
17106@item @var{command} @expansion{}
17107@code{@var{cli-command} | @var{mi-command}}
17108
17109@item @var{cli-command} @expansion{}
17110@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
17111@var{cli-command} is any existing @value{GDBN} CLI command.
17112
17113@item @var{mi-command} @expansion{}
17114@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
17115@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
17116
17117@item @var{token} @expansion{}
17118"any sequence of digits"
17119
17120@item @var{option} @expansion{}
17121@code{"-" @var{parameter} [ " " @var{parameter} ]}
17122
17123@item @var{parameter} @expansion{}
17124@code{@var{non-blank-sequence} | @var{c-string}}
17125
17126@item @var{operation} @expansion{}
17127@emph{any of the operations described in this chapter}
17128
17129@item @var{non-blank-sequence} @expansion{}
17130@emph{anything, provided it doesn't contain special characters such as
17131"-", @var{nl}, """ and of course " "}
17132
17133@item @var{c-string} @expansion{}
17134@code{""" @var{seven-bit-iso-c-string-content} """}
17135
17136@item @var{nl} @expansion{}
17137@code{CR | CR-LF}
17138@end table
17139
17140@noindent
17141Notes:
17142
17143@itemize @bullet
17144@item
17145The CLI commands are still handled by the @sc{mi} interpreter; their
17146output is described below.
17147
17148@item
17149The @code{@var{token}}, when present, is passed back when the command
17150finishes.
17151
17152@item
17153Some @sc{mi} commands accept optional arguments as part of the parameter
17154list. Each option is identified by a leading @samp{-} (dash) and may be
17155followed by an optional argument parameter. Options occur first in the
17156parameter list and can be delimited from normal parameters using
17157@samp{--} (this is useful when some parameters begin with a dash).
17158@end itemize
17159
17160Pragmatics:
17161
17162@itemize @bullet
17163@item
17164We want easy access to the existing CLI syntax (for debugging).
17165
17166@item
17167We want it to be easy to spot a @sc{mi} operation.
17168@end itemize
17169
17170@node GDB/MI Output Syntax
17171@subsection @sc{gdb/mi} Output Syntax
17172
17173@cindex output syntax of @sc{gdb/mi}
17174@cindex @sc{gdb/mi}, output syntax
17175The output from @sc{gdb/mi} consists of zero or more out-of-band records
17176followed, optionally, by a single result record. This result record
17177is for the most recent command. The sequence of output records is
17178terminated by @samp{(@value{GDBP})}.
17179
17180If an input command was prefixed with a @code{@var{token}} then the
17181corresponding output for that command will also be prefixed by that same
17182@var{token}.
17183
17184@table @code
17185@item @var{output} @expansion{}
f7dc1244 17186@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
922fbb7b
AC
17187
17188@item @var{result-record} @expansion{}
17189@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
17190
17191@item @var{out-of-band-record} @expansion{}
17192@code{@var{async-record} | @var{stream-record}}
17193
17194@item @var{async-record} @expansion{}
17195@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
17196
17197@item @var{exec-async-output} @expansion{}
17198@code{[ @var{token} ] "*" @var{async-output}}
17199
17200@item @var{status-async-output} @expansion{}
17201@code{[ @var{token} ] "+" @var{async-output}}
17202
17203@item @var{notify-async-output} @expansion{}
17204@code{[ @var{token} ] "=" @var{async-output}}
17205
17206@item @var{async-output} @expansion{}
17207@code{@var{async-class} ( "," @var{result} )* @var{nl}}
17208
17209@item @var{result-class} @expansion{}
17210@code{"done" | "running" | "connected" | "error" | "exit"}
17211
17212@item @var{async-class} @expansion{}
17213@code{"stopped" | @var{others}} (where @var{others} will be added
17214depending on the needs---this is still in development).
17215
17216@item @var{result} @expansion{}
17217@code{ @var{variable} "=" @var{value}}
17218
17219@item @var{variable} @expansion{}
17220@code{ @var{string} }
17221
17222@item @var{value} @expansion{}
17223@code{ @var{const} | @var{tuple} | @var{list} }
17224
17225@item @var{const} @expansion{}
17226@code{@var{c-string}}
17227
17228@item @var{tuple} @expansion{}
17229@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
17230
17231@item @var{list} @expansion{}
17232@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
17233@var{result} ( "," @var{result} )* "]" }
17234
17235@item @var{stream-record} @expansion{}
17236@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
17237
17238@item @var{console-stream-output} @expansion{}
17239@code{"~" @var{c-string}}
17240
17241@item @var{target-stream-output} @expansion{}
17242@code{"@@" @var{c-string}}
17243
17244@item @var{log-stream-output} @expansion{}
17245@code{"&" @var{c-string}}
17246
17247@item @var{nl} @expansion{}
17248@code{CR | CR-LF}
17249
17250@item @var{token} @expansion{}
17251@emph{any sequence of digits}.
17252@end table
17253
17254@noindent
17255Notes:
17256
17257@itemize @bullet
17258@item
17259All output sequences end in a single line containing a period.
17260
17261@item
17262The @code{@var{token}} is from the corresponding request. If an execution
17263command is interrupted by the @samp{-exec-interrupt} command, the
17264@var{token} associated with the @samp{*stopped} message is the one of the
17265original execution command, not the one of the interrupt command.
17266
17267@item
17268@cindex status output in @sc{gdb/mi}
17269@var{status-async-output} contains on-going status information about the
17270progress of a slow operation. It can be discarded. All status output is
17271prefixed by @samp{+}.
17272
17273@item
17274@cindex async output in @sc{gdb/mi}
17275@var{exec-async-output} contains asynchronous state change on the target
17276(stopped, started, disappeared). All async output is prefixed by
17277@samp{*}.
17278
17279@item
17280@cindex notify output in @sc{gdb/mi}
17281@var{notify-async-output} contains supplementary information that the
17282client should handle (e.g., a new breakpoint information). All notify
17283output is prefixed by @samp{=}.
17284
17285@item
17286@cindex console output in @sc{gdb/mi}
17287@var{console-stream-output} is output that should be displayed as is in the
17288console. It is the textual response to a CLI command. All the console
17289output is prefixed by @samp{~}.
17290
17291@item
17292@cindex target output in @sc{gdb/mi}
17293@var{target-stream-output} is the output produced by the target program.
17294All the target output is prefixed by @samp{@@}.
17295
17296@item
17297@cindex log output in @sc{gdb/mi}
17298@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
17299instance messages that should be displayed as part of an error log. All
17300the log output is prefixed by @samp{&}.
17301
17302@item
17303@cindex list output in @sc{gdb/mi}
17304New @sc{gdb/mi} commands should only output @var{lists} containing
17305@var{values}.
17306
17307
17308@end itemize
17309
17310@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
17311details about the various output records.
17312
17313@node GDB/MI Simple Examples
17314@subsection Simple Examples of @sc{gdb/mi} Interaction
17315@cindex @sc{gdb/mi}, simple examples
17316
17317This subsection presents several simple examples of interaction using
17318the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
17319following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
17320the output received from @sc{gdb/mi}.
17321
17322@subsubheading Target Stop
17323@c Ummm... There is no "-stop" command. This assumes async, no?
17324Here's an example of stopping the inferior process:
17325
17326@smallexample
17327-> -stop
17328<- (@value{GDBP})
17329@end smallexample
17330
17331@noindent
17332and later:
17333
17334@smallexample
17335<- *stop,reason="stop",address="0x123",source="a.c:123"
17336<- (@value{GDBP})
17337@end smallexample
17338
17339@subsubheading Simple CLI Command
17340
17341Here's an example of a simple CLI command being passed through
17342@sc{gdb/mi} and on to the CLI.
17343
17344@smallexample
17345-> print 1+2
17346<- &"print 1+2\n"
17347<- ~"$1 = 3\n"
17348<- ^done
17349<- (@value{GDBP})
17350@end smallexample
17351
17352@subsubheading Command With Side Effects
17353
17354@smallexample
17355-> -symbol-file xyz.exe
17356<- *breakpoint,nr="3",address="0x123",source="a.c:123"
17357<- (@value{GDBP})
17358@end smallexample
17359
17360@subsubheading A Bad Command
17361
17362Here's what happens if you pass a non-existent command:
17363
17364@smallexample
17365-> -rubbish
17366<- ^error,msg="Undefined MI command: rubbish"
17367<- (@value{GDBP})
17368@end smallexample
17369
17370@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17371@node GDB/MI Compatibility with CLI
17372@section @sc{gdb/mi} Compatibility with CLI
17373
17374@cindex compatibility, @sc{gdb/mi} and CLI
17375@cindex @sc{gdb/mi}, compatibility with CLI
17376To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
17377accepts existing CLI commands. As specified by the syntax, such
17378commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
17379respond.
17380
17381This mechanism is provided as an aid to developers of @sc{gdb/mi}
17382clients and not as a reliable interface into the CLI. Since the command
17383is being interpreteted in an environment that assumes @sc{gdb/mi}
17384behaviour, the exact output of such commands is likely to end up being
17385an un-supported hybrid of @sc{gdb/mi} and CLI output.
17386
17387@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17388@node GDB/MI Output Records
17389@section @sc{gdb/mi} Output Records
17390
17391@menu
17392* GDB/MI Result Records::
17393* GDB/MI Stream Records::
17394* GDB/MI Out-of-band Records::
17395@end menu
17396
17397@node GDB/MI Result Records
17398@subsection @sc{gdb/mi} Result Records
17399
17400@cindex result records in @sc{gdb/mi}
17401@cindex @sc{gdb/mi}, result records
17402In addition to a number of out-of-band notifications, the response to a
17403@sc{gdb/mi} command includes one of the following result indications:
17404
17405@table @code
17406@findex ^done
17407@item "^done" [ "," @var{results} ]
17408The synchronous operation was successful, @code{@var{results}} are the return
17409values.
17410
17411@item "^running"
17412@findex ^running
17413@c Is this one correct? Should it be an out-of-band notification?
17414The asynchronous operation was successfully started. The target is
17415running.
17416
17417@item "^error" "," @var{c-string}
17418@findex ^error
17419The operation failed. The @code{@var{c-string}} contains the corresponding
17420error message.
17421@end table
17422
17423@node GDB/MI Stream Records
17424@subsection @sc{gdb/mi} Stream Records
17425
17426@cindex @sc{gdb/mi}, stream records
17427@cindex stream records in @sc{gdb/mi}
17428@value{GDBN} internally maintains a number of output streams: the console, the
17429target, and the log. The output intended for each of these streams is
17430funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
17431
17432Each stream record begins with a unique @dfn{prefix character} which
17433identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
17434Syntax}). In addition to the prefix, each stream record contains a
17435@code{@var{string-output}}. This is either raw text (with an implicit new
17436line) or a quoted C string (which does not contain an implicit newline).
17437
17438@table @code
17439@item "~" @var{string-output}
17440The console output stream contains text that should be displayed in the
17441CLI console window. It contains the textual responses to CLI commands.
17442
17443@item "@@" @var{string-output}
17444The target output stream contains any textual output from the running
17445target.
17446
17447@item "&" @var{string-output}
17448The log stream contains debugging messages being produced by @value{GDBN}'s
17449internals.
17450@end table
17451
17452@node GDB/MI Out-of-band Records
17453@subsection @sc{gdb/mi} Out-of-band Records
17454
17455@cindex out-of-band records in @sc{gdb/mi}
17456@cindex @sc{gdb/mi}, out-of-band records
17457@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
17458additional changes that have occurred. Those changes can either be a
17459consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
17460target activity (e.g., target stopped).
17461
17462The following is a preliminary list of possible out-of-band records.
034dad6f 17463In particular, the @var{exec-async-output} records.
922fbb7b
AC
17464
17465@table @code
034dad6f
BR
17466@item *stopped,reason="@var{reason}"
17467@end table
17468
17469@var{reason} can be one of the following:
17470
17471@table @code
17472@item breakpoint-hit
17473A breakpoint was reached.
17474@item watchpoint-trigger
17475A watchpoint was triggered.
17476@item read-watchpoint-trigger
17477A read watchpoint was triggered.
17478@item access-watchpoint-trigger
17479An access watchpoint was triggered.
17480@item function-finished
17481An -exec-finish or similar CLI command was accomplished.
17482@item location-reached
17483An -exec-until or similar CLI command was accomplished.
17484@item watchpoint-scope
17485A watchpoint has gone out of scope.
17486@item end-stepping-range
17487An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
17488similar CLI command was accomplished.
17489@item exited-signalled
17490The inferior exited because of a signal.
17491@item exited
17492The inferior exited.
17493@item exited-normally
17494The inferior exited normally.
17495@item signal-received
17496A signal was received by the inferior.
922fbb7b
AC
17497@end table
17498
17499
17500@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17501@node GDB/MI Command Description Format
17502@section @sc{gdb/mi} Command Description Format
17503
17504The remaining sections describe blocks of commands. Each block of
17505commands is laid out in a fashion similar to this section.
17506
17507Note the the line breaks shown in the examples are here only for
17508readability. They don't appear in the real output.
17509Also note that the commands with a non-available example (N.A.@:) are
17510not yet implemented.
17511
17512@subheading Motivation
17513
17514The motivation for this collection of commands.
17515
17516@subheading Introduction
17517
17518A brief introduction to this collection of commands as a whole.
17519
17520@subheading Commands
17521
17522For each command in the block, the following is described:
17523
17524@subsubheading Synopsis
17525
17526@smallexample
17527 -command @var{args}@dots{}
17528@end smallexample
17529
922fbb7b
AC
17530@subsubheading Result
17531
265eeb58 17532@subsubheading @value{GDBN} Command
922fbb7b 17533
265eeb58 17534The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
17535
17536@subsubheading Example
17537
922fbb7b
AC
17538@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17539@node GDB/MI Breakpoint Table Commands
17540@section @sc{gdb/mi} Breakpoint table commands
17541
17542@cindex breakpoint commands for @sc{gdb/mi}
17543@cindex @sc{gdb/mi}, breakpoint commands
17544This section documents @sc{gdb/mi} commands for manipulating
17545breakpoints.
17546
17547@subheading The @code{-break-after} Command
17548@findex -break-after
17549
17550@subsubheading Synopsis
17551
17552@smallexample
17553 -break-after @var{number} @var{count}
17554@end smallexample
17555
17556The breakpoint number @var{number} is not in effect until it has been
17557hit @var{count} times. To see how this is reflected in the output of
17558the @samp{-break-list} command, see the description of the
17559@samp{-break-list} command below.
17560
17561@subsubheading @value{GDBN} Command
17562
17563The corresponding @value{GDBN} command is @samp{ignore}.
17564
17565@subsubheading Example
17566
17567@smallexample
17568(@value{GDBP})
17569-break-insert main
17570^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
17571(@value{GDBP})
17572-break-after 1 3
17573~
17574^done
17575(@value{GDBP})
17576-break-list
17577^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17578hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17579@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17580@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17581@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17582@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17583@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17584body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17585addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
17586ignore="3"@}]@}
17587(@value{GDBP})
17588@end smallexample
17589
17590@ignore
17591@subheading The @code{-break-catch} Command
17592@findex -break-catch
17593
17594@subheading The @code{-break-commands} Command
17595@findex -break-commands
17596@end ignore
17597
17598
17599@subheading The @code{-break-condition} Command
17600@findex -break-condition
17601
17602@subsubheading Synopsis
17603
17604@smallexample
17605 -break-condition @var{number} @var{expr}
17606@end smallexample
17607
17608Breakpoint @var{number} will stop the program only if the condition in
17609@var{expr} is true. The condition becomes part of the
17610@samp{-break-list} output (see the description of the @samp{-break-list}
17611command below).
17612
17613@subsubheading @value{GDBN} Command
17614
17615The corresponding @value{GDBN} command is @samp{condition}.
17616
17617@subsubheading Example
17618
17619@smallexample
17620(@value{GDBP})
17621-break-condition 1 1
17622^done
17623(@value{GDBP})
17624-break-list
17625^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17626hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17627@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17628@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17629@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17630@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17631@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17632body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17633addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
17634times="0",ignore="3"@}]@}
17635(@value{GDBP})
17636@end smallexample
17637
17638@subheading The @code{-break-delete} Command
17639@findex -break-delete
17640
17641@subsubheading Synopsis
17642
17643@smallexample
17644 -break-delete ( @var{breakpoint} )+
17645@end smallexample
17646
17647Delete the breakpoint(s) whose number(s) are specified in the argument
17648list. This is obviously reflected in the breakpoint list.
17649
17650@subsubheading @value{GDBN} command
17651
17652The corresponding @value{GDBN} command is @samp{delete}.
17653
17654@subsubheading Example
17655
17656@smallexample
17657(@value{GDBP})
17658-break-delete 1
17659^done
17660(@value{GDBP})
17661-break-list
17662^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17663hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17664@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17665@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17666@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17667@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17668@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17669body=[]@}
17670(@value{GDBP})
17671@end smallexample
17672
17673@subheading The @code{-break-disable} Command
17674@findex -break-disable
17675
17676@subsubheading Synopsis
17677
17678@smallexample
17679 -break-disable ( @var{breakpoint} )+
17680@end smallexample
17681
17682Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
17683break list is now set to @samp{n} for the named @var{breakpoint}(s).
17684
17685@subsubheading @value{GDBN} Command
17686
17687The corresponding @value{GDBN} command is @samp{disable}.
17688
17689@subsubheading Example
17690
17691@smallexample
17692(@value{GDBP})
17693-break-disable 2
17694^done
17695(@value{GDBP})
17696-break-list
17697^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17698hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17699@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17700@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17701@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17702@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17703@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17704body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
17705addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17706(@value{GDBP})
17707@end smallexample
17708
17709@subheading The @code{-break-enable} Command
17710@findex -break-enable
17711
17712@subsubheading Synopsis
17713
17714@smallexample
17715 -break-enable ( @var{breakpoint} )+
17716@end smallexample
17717
17718Enable (previously disabled) @var{breakpoint}(s).
17719
17720@subsubheading @value{GDBN} Command
17721
17722The corresponding @value{GDBN} command is @samp{enable}.
17723
17724@subsubheading Example
17725
17726@smallexample
17727(@value{GDBP})
17728-break-enable 2
17729^done
17730(@value{GDBP})
17731-break-list
17732^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17733hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17734@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17735@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17736@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17737@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17738@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17739body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17740addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17741(@value{GDBP})
17742@end smallexample
17743
17744@subheading The @code{-break-info} Command
17745@findex -break-info
17746
17747@subsubheading Synopsis
17748
17749@smallexample
17750 -break-info @var{breakpoint}
17751@end smallexample
17752
17753@c REDUNDANT???
17754Get information about a single breakpoint.
17755
17756@subsubheading @value{GDBN} command
17757
17758The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
17759
17760@subsubheading Example
17761N.A.
17762
17763@subheading The @code{-break-insert} Command
17764@findex -break-insert
17765
17766@subsubheading Synopsis
17767
17768@smallexample
17769 -break-insert [ -t ] [ -h ] [ -r ]
17770 [ -c @var{condition} ] [ -i @var{ignore-count} ]
17771 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
17772@end smallexample
17773
17774@noindent
17775If specified, @var{line}, can be one of:
17776
17777@itemize @bullet
17778@item function
17779@c @item +offset
17780@c @item -offset
17781@c @item linenum
17782@item filename:linenum
17783@item filename:function
17784@item *address
17785@end itemize
17786
17787The possible optional parameters of this command are:
17788
17789@table @samp
17790@item -t
17791Insert a tempoary breakpoint.
17792@item -h
17793Insert a hardware breakpoint.
17794@item -c @var{condition}
17795Make the breakpoint conditional on @var{condition}.
17796@item -i @var{ignore-count}
17797Initialize the @var{ignore-count}.
17798@item -r
17799Insert a regular breakpoint in all the functions whose names match the
17800given regular expression. Other flags are not applicable to regular
17801expresson.
17802@end table
17803
17804@subsubheading Result
17805
17806The result is in the form:
17807
17808@smallexample
17809 ^done,bkptno="@var{number}",func="@var{funcname}",
17810 file="@var{filename}",line="@var{lineno}"
17811@end smallexample
17812
17813@noindent
17814where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
17815is the name of the function where the breakpoint was inserted,
17816@var{filename} is the name of the source file which contains this
17817function, and @var{lineno} is the source line number within that file.
17818
17819Note: this format is open to change.
17820@c An out-of-band breakpoint instead of part of the result?
17821
17822@subsubheading @value{GDBN} Command
17823
17824The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
17825@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
17826
17827@subsubheading Example
17828
17829@smallexample
17830(@value{GDBP})
17831-break-insert main
17832^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17833(@value{GDBP})
17834-break-insert -t foo
17835^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
17836(@value{GDBP})
17837-break-list
17838^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17839hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17840@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17841@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17842@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17843@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17844@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17845body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17846addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
17847bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
17848addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
17849(@value{GDBP})
17850-break-insert -r foo.*
17851~int foo(int, int);
17852^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
17853(@value{GDBP})
17854@end smallexample
17855
17856@subheading The @code{-break-list} Command
17857@findex -break-list
17858
17859@subsubheading Synopsis
17860
17861@smallexample
17862 -break-list
17863@end smallexample
17864
17865Displays the list of inserted breakpoints, showing the following fields:
17866
17867@table @samp
17868@item Number
17869number of the breakpoint
17870@item Type
17871type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
17872@item Disposition
17873should the breakpoint be deleted or disabled when it is hit: @samp{keep}
17874or @samp{nokeep}
17875@item Enabled
17876is the breakpoint enabled or no: @samp{y} or @samp{n}
17877@item Address
17878memory location at which the breakpoint is set
17879@item What
17880logical location of the breakpoint, expressed by function name, file
17881name, line number
17882@item Times
17883number of times the breakpoint has been hit
17884@end table
17885
17886If there are no breakpoints or watchpoints, the @code{BreakpointTable}
17887@code{body} field is an empty list.
17888
17889@subsubheading @value{GDBN} Command
17890
17891The corresponding @value{GDBN} command is @samp{info break}.
17892
17893@subsubheading Example
17894
17895@smallexample
17896(@value{GDBP})
17897-break-list
17898^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17899hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17900@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17901@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17902@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17903@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17904@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17905body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17906addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
17907bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17908addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
17909(@value{GDBP})
17910@end smallexample
17911
17912Here's an example of the result when there are no breakpoints:
17913
17914@smallexample
17915(@value{GDBP})
17916-break-list
17917^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17918hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17919@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17920@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17921@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17922@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17923@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17924body=[]@}
17925(@value{GDBP})
17926@end smallexample
17927
17928@subheading The @code{-break-watch} Command
17929@findex -break-watch
17930
17931@subsubheading Synopsis
17932
17933@smallexample
17934 -break-watch [ -a | -r ]
17935@end smallexample
17936
17937Create a watchpoint. With the @samp{-a} option it will create an
17938@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
17939read from or on a write to the memory location. With the @samp{-r}
17940option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
17941trigger only when the memory location is accessed for reading. Without
17942either of the options, the watchpoint created is a regular watchpoint,
17943i.e. it will trigger when the memory location is accessed for writing.
17944@xref{Set Watchpoints, , Setting watchpoints}.
17945
17946Note that @samp{-break-list} will report a single list of watchpoints and
17947breakpoints inserted.
17948
17949@subsubheading @value{GDBN} Command
17950
17951The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
17952@samp{rwatch}.
17953
17954@subsubheading Example
17955
17956Setting a watchpoint on a variable in the @code{main} function:
17957
17958@smallexample
17959(@value{GDBP})
17960-break-watch x
17961^done,wpt=@{number="2",exp="x"@}
17962(@value{GDBP})
17963-exec-continue
17964^running
17965^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
17966value=@{old="-268439212",new="55"@},
76ff342d
DJ
17967frame=@{func="main",args=[],file="recursive2.c",
17968fullname="/home/foo/bar/devo/myproject/recursive2.c",line="5"@}
922fbb7b
AC
17969(@value{GDBP})
17970@end smallexample
17971
17972Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
17973the program execution twice: first for the variable changing value, then
17974for the watchpoint going out of scope.
17975
17976@smallexample
17977(@value{GDBP})
17978-break-watch C
17979^done,wpt=@{number="5",exp="C"@}
17980(@value{GDBP})
17981-exec-continue
17982^running
17983^done,reason="watchpoint-trigger",
17984wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
17985frame=@{func="callee4",args=[],
76ff342d
DJ
17986file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17987fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17988(@value{GDBP})
17989-exec-continue
17990^running
17991^done,reason="watchpoint-scope",wpnum="5",
17992frame=@{func="callee3",args=[@{name="strarg",
17993value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17994file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17995fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17996(@value{GDBP})
17997@end smallexample
17998
17999Listing breakpoints and watchpoints, at different points in the program
18000execution. Note that once the watchpoint goes out of scope, it is
18001deleted.
18002
18003@smallexample
18004(@value{GDBP})
18005-break-watch C
18006^done,wpt=@{number="2",exp="C"@}
18007(@value{GDBP})
18008-break-list
18009^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18010hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18011@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18012@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18013@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18014@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18015@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18016body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18017addr="0x00010734",func="callee4",
18018file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
18019bkpt=@{number="2",type="watchpoint",disp="keep",
18020enabled="y",addr="",what="C",times="0"@}]@}
18021(@value{GDBP})
18022-exec-continue
18023^running
18024^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
18025value=@{old="-276895068",new="3"@},
18026frame=@{func="callee4",args=[],
76ff342d
DJ
18027file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18028fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
18029(@value{GDBP})
18030-break-list
18031^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18032hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18033@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18034@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18035@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18036@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18037@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18038body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18039addr="0x00010734",func="callee4",
18040file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
18041bkpt=@{number="2",type="watchpoint",disp="keep",
18042enabled="y",addr="",what="C",times="-5"@}]@}
18043(@value{GDBP})
18044-exec-continue
18045^running
18046^done,reason="watchpoint-scope",wpnum="2",
18047frame=@{func="callee3",args=[@{name="strarg",
18048value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
18049file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18050fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
18051(@value{GDBP})
18052-break-list
18053^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18054hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18055@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18056@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18057@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18058@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18059@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18060body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18061addr="0x00010734",func="callee4",
18062file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
18063(@value{GDBP})
18064@end smallexample
18065
18066@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18067@node GDB/MI Data Manipulation
18068@section @sc{gdb/mi} Data Manipulation
18069
18070@cindex data manipulation, in @sc{gdb/mi}
18071@cindex @sc{gdb/mi}, data manipulation
18072This section describes the @sc{gdb/mi} commands that manipulate data:
18073examine memory and registers, evaluate expressions, etc.
18074
18075@c REMOVED FROM THE INTERFACE.
18076@c @subheading -data-assign
18077@c Change the value of a program variable. Plenty of side effects.
18078@c @subsubheading GDB command
18079@c set variable
18080@c @subsubheading Example
18081@c N.A.
18082
18083@subheading The @code{-data-disassemble} Command
18084@findex -data-disassemble
18085
18086@subsubheading Synopsis
18087
18088@smallexample
18089 -data-disassemble
18090 [ -s @var{start-addr} -e @var{end-addr} ]
18091 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
18092 -- @var{mode}
18093@end smallexample
18094
18095@noindent
18096Where:
18097
18098@table @samp
18099@item @var{start-addr}
18100is the beginning address (or @code{$pc})
18101@item @var{end-addr}
18102is the end address
18103@item @var{filename}
18104is the name of the file to disassemble
18105@item @var{linenum}
18106is the line number to disassemble around
18107@item @var{lines}
18108is the the number of disassembly lines to be produced. If it is -1,
18109the whole function will be disassembled, in case no @var{end-addr} is
18110specified. If @var{end-addr} is specified as a non-zero value, and
18111@var{lines} is lower than the number of disassembly lines between
18112@var{start-addr} and @var{end-addr}, only @var{lines} lines are
18113displayed; if @var{lines} is higher than the number of lines between
18114@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
18115are displayed.
18116@item @var{mode}
18117is either 0 (meaning only disassembly) or 1 (meaning mixed source and
18118disassembly).
18119@end table
18120
18121@subsubheading Result
18122
18123The output for each instruction is composed of four fields:
18124
18125@itemize @bullet
18126@item Address
18127@item Func-name
18128@item Offset
18129@item Instruction
18130@end itemize
18131
18132Note that whatever included in the instruction field, is not manipulated
18133directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
18134
18135@subsubheading @value{GDBN} Command
18136
18137There's no direct mapping from this command to the CLI.
18138
18139@subsubheading Example
18140
18141Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
18142
18143@smallexample
18144(@value{GDBP})
18145-data-disassemble -s $pc -e "$pc + 20" -- 0
18146^done,
18147asm_insns=[
18148@{address="0x000107c0",func-name="main",offset="4",
18149inst="mov 2, %o0"@},
18150@{address="0x000107c4",func-name="main",offset="8",
18151inst="sethi %hi(0x11800), %o2"@},
18152@{address="0x000107c8",func-name="main",offset="12",
18153inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
18154@{address="0x000107cc",func-name="main",offset="16",
18155inst="sethi %hi(0x11800), %o2"@},
18156@{address="0x000107d0",func-name="main",offset="20",
18157inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
18158(@value{GDBP})
18159@end smallexample
18160
18161Disassemble the whole @code{main} function. Line 32 is part of
18162@code{main}.
18163
18164@smallexample
18165-data-disassemble -f basics.c -l 32 -- 0
18166^done,asm_insns=[
18167@{address="0x000107bc",func-name="main",offset="0",
18168inst="save %sp, -112, %sp"@},
18169@{address="0x000107c0",func-name="main",offset="4",
18170inst="mov 2, %o0"@},
18171@{address="0x000107c4",func-name="main",offset="8",
18172inst="sethi %hi(0x11800), %o2"@},
18173[@dots{}]
18174@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
18175@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
18176(@value{GDBP})
18177@end smallexample
18178
18179Disassemble 3 instructions from the start of @code{main}:
18180
18181@smallexample
18182(@value{GDBP})
18183-data-disassemble -f basics.c -l 32 -n 3 -- 0
18184^done,asm_insns=[
18185@{address="0x000107bc",func-name="main",offset="0",
18186inst="save %sp, -112, %sp"@},
18187@{address="0x000107c0",func-name="main",offset="4",
18188inst="mov 2, %o0"@},
18189@{address="0x000107c4",func-name="main",offset="8",
18190inst="sethi %hi(0x11800), %o2"@}]
18191(@value{GDBP})
18192@end smallexample
18193
18194Disassemble 3 instructions from the start of @code{main} in mixed mode:
18195
18196@smallexample
18197(@value{GDBP})
18198-data-disassemble -f basics.c -l 32 -n 3 -- 1
18199^done,asm_insns=[
18200src_and_asm_line=@{line="31",
18201file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
18202 testsuite/gdb.mi/basics.c",line_asm_insn=[
18203@{address="0x000107bc",func-name="main",offset="0",
18204inst="save %sp, -112, %sp"@}]@},
18205src_and_asm_line=@{line="32",
18206file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
18207 testsuite/gdb.mi/basics.c",line_asm_insn=[
18208@{address="0x000107c0",func-name="main",offset="4",
18209inst="mov 2, %o0"@},
18210@{address="0x000107c4",func-name="main",offset="8",
18211inst="sethi %hi(0x11800), %o2"@}]@}]
18212(@value{GDBP})
18213@end smallexample
18214
18215
18216@subheading The @code{-data-evaluate-expression} Command
18217@findex -data-evaluate-expression
18218
18219@subsubheading Synopsis
18220
18221@smallexample
18222 -data-evaluate-expression @var{expr}
18223@end smallexample
18224
18225Evaluate @var{expr} as an expression. The expression could contain an
18226inferior function call. The function call will execute synchronously.
18227If the expression contains spaces, it must be enclosed in double quotes.
18228
18229@subsubheading @value{GDBN} Command
18230
18231The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
18232@samp{call}. In @code{gdbtk} only, there's a corresponding
18233@samp{gdb_eval} command.
18234
18235@subsubheading Example
18236
18237In the following example, the numbers that precede the commands are the
18238@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
18239Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
18240output.
18241
18242@smallexample
18243211-data-evaluate-expression A
18244211^done,value="1"
18245(@value{GDBP})
18246311-data-evaluate-expression &A
18247311^done,value="0xefffeb7c"
18248(@value{GDBP})
18249411-data-evaluate-expression A+3
18250411^done,value="4"
18251(@value{GDBP})
18252511-data-evaluate-expression "A + 3"
18253511^done,value="4"
18254(@value{GDBP})
18255@end smallexample
18256
18257
18258@subheading The @code{-data-list-changed-registers} Command
18259@findex -data-list-changed-registers
18260
18261@subsubheading Synopsis
18262
18263@smallexample
18264 -data-list-changed-registers
18265@end smallexample
18266
18267Display a list of the registers that have changed.
18268
18269@subsubheading @value{GDBN} Command
18270
18271@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
18272has the corresponding command @samp{gdb_changed_register_list}.
18273
18274@subsubheading Example
18275
18276On a PPC MBX board:
18277
18278@smallexample
18279(@value{GDBP})
18280-exec-continue
18281^running
18282
18283(@value{GDBP})
18284*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
76ff342d 18285args=[],file="try.c",fullname="/home/foo/bar/devo/myproject/try.c",line="5"@}
922fbb7b
AC
18286(@value{GDBP})
18287-data-list-changed-registers
18288^done,changed-registers=["0","1","2","4","5","6","7","8","9",
18289"10","11","13","14","15","16","17","18","19","20","21","22","23",
18290"24","25","26","27","28","30","31","64","65","66","67","69"]
18291(@value{GDBP})
18292@end smallexample
18293
18294
18295@subheading The @code{-data-list-register-names} Command
18296@findex -data-list-register-names
18297
18298@subsubheading Synopsis
18299
18300@smallexample
18301 -data-list-register-names [ ( @var{regno} )+ ]
18302@end smallexample
18303
18304Show a list of register names for the current target. If no arguments
18305are given, it shows a list of the names of all the registers. If
18306integer numbers are given as arguments, it will print a list of the
18307names of the registers corresponding to the arguments. To ensure
18308consistency between a register name and its number, the output list may
18309include empty register names.
18310
18311@subsubheading @value{GDBN} Command
18312
18313@value{GDBN} does not have a command which corresponds to
18314@samp{-data-list-register-names}. In @code{gdbtk} there is a
18315corresponding command @samp{gdb_regnames}.
18316
18317@subsubheading Example
18318
18319For the PPC MBX board:
18320@smallexample
18321(@value{GDBP})
18322-data-list-register-names
18323^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
18324"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
18325"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
18326"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
18327"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
18328"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
18329"", "pc","ps","cr","lr","ctr","xer"]
18330(@value{GDBP})
18331-data-list-register-names 1 2 3
18332^done,register-names=["r1","r2","r3"]
18333(@value{GDBP})
18334@end smallexample
18335
18336@subheading The @code{-data-list-register-values} Command
18337@findex -data-list-register-values
18338
18339@subsubheading Synopsis
18340
18341@smallexample
18342 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
18343@end smallexample
18344
18345Display the registers' contents. @var{fmt} is the format according to
18346which the registers' contents are to be returned, followed by an optional
18347list of numbers specifying the registers to display. A missing list of
18348numbers indicates that the contents of all the registers must be returned.
18349
18350Allowed formats for @var{fmt} are:
18351
18352@table @code
18353@item x
18354Hexadecimal
18355@item o
18356Octal
18357@item t
18358Binary
18359@item d
18360Decimal
18361@item r
18362Raw
18363@item N
18364Natural
18365@end table
18366
18367@subsubheading @value{GDBN} Command
18368
18369The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
18370all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
18371
18372@subsubheading Example
18373
18374For a PPC MBX board (note: line breaks are for readability only, they
18375don't appear in the actual output):
18376
18377@smallexample
18378(@value{GDBP})
18379-data-list-register-values r 64 65
18380^done,register-values=[@{number="64",value="0xfe00a300"@},
18381@{number="65",value="0x00029002"@}]
18382(@value{GDBP})
18383-data-list-register-values x
18384^done,register-values=[@{number="0",value="0xfe0043c8"@},
18385@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
18386@{number="3",value="0x0"@},@{number="4",value="0xa"@},
18387@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
18388@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
18389@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
18390@{number="11",value="0x1"@},@{number="12",value="0x0"@},
18391@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
18392@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
18393@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
18394@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
18395@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
18396@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
18397@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
18398@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
18399@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
18400@{number="31",value="0x0"@},@{number="32",value="0x0"@},
18401@{number="33",value="0x0"@},@{number="34",value="0x0"@},
18402@{number="35",value="0x0"@},@{number="36",value="0x0"@},
18403@{number="37",value="0x0"@},@{number="38",value="0x0"@},
18404@{number="39",value="0x0"@},@{number="40",value="0x0"@},
18405@{number="41",value="0x0"@},@{number="42",value="0x0"@},
18406@{number="43",value="0x0"@},@{number="44",value="0x0"@},
18407@{number="45",value="0x0"@},@{number="46",value="0x0"@},
18408@{number="47",value="0x0"@},@{number="48",value="0x0"@},
18409@{number="49",value="0x0"@},@{number="50",value="0x0"@},
18410@{number="51",value="0x0"@},@{number="52",value="0x0"@},
18411@{number="53",value="0x0"@},@{number="54",value="0x0"@},
18412@{number="55",value="0x0"@},@{number="56",value="0x0"@},
18413@{number="57",value="0x0"@},@{number="58",value="0x0"@},
18414@{number="59",value="0x0"@},@{number="60",value="0x0"@},
18415@{number="61",value="0x0"@},@{number="62",value="0x0"@},
18416@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
18417@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
18418@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
18419@{number="69",value="0x20002b03"@}]
18420(@value{GDBP})
18421@end smallexample
18422
18423
18424@subheading The @code{-data-read-memory} Command
18425@findex -data-read-memory
18426
18427@subsubheading Synopsis
18428
18429@smallexample
18430 -data-read-memory [ -o @var{byte-offset} ]
18431 @var{address} @var{word-format} @var{word-size}
18432 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
18433@end smallexample
18434
18435@noindent
18436where:
18437
18438@table @samp
18439@item @var{address}
18440An expression specifying the address of the first memory word to be
18441read. Complex expressions containing embedded white space should be
18442quoted using the C convention.
18443
18444@item @var{word-format}
18445The format to be used to print the memory words. The notation is the
18446same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
18447,Output formats}).
18448
18449@item @var{word-size}
18450The size of each memory word in bytes.
18451
18452@item @var{nr-rows}
18453The number of rows in the output table.
18454
18455@item @var{nr-cols}
18456The number of columns in the output table.
18457
18458@item @var{aschar}
18459If present, indicates that each row should include an @sc{ascii} dump. The
18460value of @var{aschar} is used as a padding character when a byte is not a
18461member of the printable @sc{ascii} character set (printable @sc{ascii}
18462characters are those whose code is between 32 and 126, inclusively).
18463
18464@item @var{byte-offset}
18465An offset to add to the @var{address} before fetching memory.
18466@end table
18467
18468This command displays memory contents as a table of @var{nr-rows} by
18469@var{nr-cols} words, each word being @var{word-size} bytes. In total,
18470@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
18471(returned as @samp{total-bytes}). Should less than the requested number
18472of bytes be returned by the target, the missing words are identified
18473using @samp{N/A}. The number of bytes read from the target is returned
18474in @samp{nr-bytes} and the starting address used to read memory in
18475@samp{addr}.
18476
18477The address of the next/previous row or page is available in
18478@samp{next-row} and @samp{prev-row}, @samp{next-page} and
18479@samp{prev-page}.
18480
18481@subsubheading @value{GDBN} Command
18482
18483The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
18484@samp{gdb_get_mem} memory read command.
18485
18486@subsubheading Example
18487
18488Read six bytes of memory starting at @code{bytes+6} but then offset by
18489@code{-6} bytes. Format as three rows of two columns. One byte per
18490word. Display each word in hex.
18491
18492@smallexample
18493(@value{GDBP})
184949-data-read-memory -o -6 -- bytes+6 x 1 3 2
184959^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
18496next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
18497prev-page="0x0000138a",memory=[
18498@{addr="0x00001390",data=["0x00","0x01"]@},
18499@{addr="0x00001392",data=["0x02","0x03"]@},
18500@{addr="0x00001394",data=["0x04","0x05"]@}]
18501(@value{GDBP})
18502@end smallexample
18503
18504Read two bytes of memory starting at address @code{shorts + 64} and
18505display as a single word formatted in decimal.
18506
18507@smallexample
18508(@value{GDBP})
185095-data-read-memory shorts+64 d 2 1 1
185105^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
18511next-row="0x00001512",prev-row="0x0000150e",
18512next-page="0x00001512",prev-page="0x0000150e",memory=[
18513@{addr="0x00001510",data=["128"]@}]
18514(@value{GDBP})
18515@end smallexample
18516
18517Read thirty two bytes of memory starting at @code{bytes+16} and format
18518as eight rows of four columns. Include a string encoding with @samp{x}
18519used as the non-printable character.
18520
18521@smallexample
18522(@value{GDBP})
185234-data-read-memory bytes+16 x 1 8 4 x
185244^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
18525next-row="0x000013c0",prev-row="0x0000139c",
18526next-page="0x000013c0",prev-page="0x00001380",memory=[
18527@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
18528@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
18529@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
18530@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
18531@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
18532@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
18533@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
18534@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
18535(@value{GDBP})
18536@end smallexample
18537
18538@subheading The @code{-display-delete} Command
18539@findex -display-delete
18540
18541@subsubheading Synopsis
18542
18543@smallexample
18544 -display-delete @var{number}
18545@end smallexample
18546
18547Delete the display @var{number}.
18548
18549@subsubheading @value{GDBN} Command
18550
18551The corresponding @value{GDBN} command is @samp{delete display}.
18552
18553@subsubheading Example
18554N.A.
18555
18556
18557@subheading The @code{-display-disable} Command
18558@findex -display-disable
18559
18560@subsubheading Synopsis
18561
18562@smallexample
18563 -display-disable @var{number}
18564@end smallexample
18565
18566Disable display @var{number}.
18567
18568@subsubheading @value{GDBN} Command
18569
18570The corresponding @value{GDBN} command is @samp{disable display}.
18571
18572@subsubheading Example
18573N.A.
18574
18575
18576@subheading The @code{-display-enable} Command
18577@findex -display-enable
18578
18579@subsubheading Synopsis
18580
18581@smallexample
18582 -display-enable @var{number}
18583@end smallexample
18584
18585Enable display @var{number}.
18586
18587@subsubheading @value{GDBN} Command
18588
18589The corresponding @value{GDBN} command is @samp{enable display}.
18590
18591@subsubheading Example
18592N.A.
18593
18594
18595@subheading The @code{-display-insert} Command
18596@findex -display-insert
18597
18598@subsubheading Synopsis
18599
18600@smallexample
18601 -display-insert @var{expression}
18602@end smallexample
18603
18604Display @var{expression} every time the program stops.
18605
18606@subsubheading @value{GDBN} Command
18607
18608The corresponding @value{GDBN} command is @samp{display}.
18609
18610@subsubheading Example
18611N.A.
18612
18613
18614@subheading The @code{-display-list} Command
18615@findex -display-list
18616
18617@subsubheading Synopsis
18618
18619@smallexample
18620 -display-list
18621@end smallexample
18622
18623List the displays. Do not show the current values.
18624
18625@subsubheading @value{GDBN} Command
18626
18627The corresponding @value{GDBN} command is @samp{info display}.
18628
18629@subsubheading Example
18630N.A.
18631
18632
18633@subheading The @code{-environment-cd} Command
18634@findex -environment-cd
18635
18636@subsubheading Synopsis
18637
18638@smallexample
18639 -environment-cd @var{pathdir}
18640@end smallexample
18641
18642Set @value{GDBN}'s working directory.
18643
18644@subsubheading @value{GDBN} Command
18645
18646The corresponding @value{GDBN} command is @samp{cd}.
18647
18648@subsubheading Example
18649
18650@smallexample
18651(@value{GDBP})
18652-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18653^done
18654(@value{GDBP})
18655@end smallexample
18656
18657
18658@subheading The @code{-environment-directory} Command
18659@findex -environment-directory
18660
18661@subsubheading Synopsis
18662
18663@smallexample
18664 -environment-directory [ -r ] [ @var{pathdir} ]+
18665@end smallexample
18666
18667Add directories @var{pathdir} to beginning of search path for source files.
18668If the @samp{-r} option is used, the search path is reset to the default
b383017d 18669search path. If directories @var{pathdir} are supplied in addition to the
922fbb7b
AC
18670@samp{-r} option, the search path is first reset and then addition
18671occurs as normal.
b383017d 18672Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18673multiple directories in a single command
18674results in the directories added to the beginning of the
18675search path in the same order they were presented in the command.
18676If blanks are needed as
18677part of a directory name, double-quotes should be used around
18678the name. In the command output, the path will show up separated
b383017d 18679by the system directory-separator character. The directory-seperator
922fbb7b
AC
18680character must not be used
18681in any directory name.
18682If no directories are specified, the current search path is displayed.
18683
18684@subsubheading @value{GDBN} Command
18685
18686The corresponding @value{GDBN} command is @samp{dir}.
18687
18688@subsubheading Example
18689
18690@smallexample
18691(@value{GDBP})
18692-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18693^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18694(@value{GDBP})
18695-environment-directory ""
18696^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18697(@value{GDBP})
18698-environment-directory -r /home/jjohnstn/src/gdb /usr/src
18699^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
18700(@value{GDBP})
18701-environment-directory -r
18702^done,source-path="$cdir:$cwd"
18703(@value{GDBP})
18704@end smallexample
18705
18706
18707@subheading The @code{-environment-path} Command
18708@findex -environment-path
18709
18710@subsubheading Synopsis
18711
18712@smallexample
18713 -environment-path [ -r ] [ @var{pathdir} ]+
18714@end smallexample
18715
18716Add directories @var{pathdir} to beginning of search path for object files.
18717If the @samp{-r} option is used, the search path is reset to the original
b383017d
RM
18718search path that existed at gdb start-up. If directories @var{pathdir} are
18719supplied in addition to the
922fbb7b
AC
18720@samp{-r} option, the search path is first reset and then addition
18721occurs as normal.
b383017d 18722Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18723multiple directories in a single command
18724results in the directories added to the beginning of the
18725search path in the same order they were presented in the command.
18726If blanks are needed as
18727part of a directory name, double-quotes should be used around
18728the name. In the command output, the path will show up separated
b383017d 18729by the system directory-separator character. The directory-seperator
922fbb7b
AC
18730character must not be used
18731in any directory name.
18732If no directories are specified, the current path is displayed.
18733
18734
18735@subsubheading @value{GDBN} Command
18736
18737The corresponding @value{GDBN} command is @samp{path}.
18738
18739@subsubheading Example
18740
18741@smallexample
18742(@value{GDBP})
b383017d 18743-environment-path
922fbb7b
AC
18744^done,path="/usr/bin"
18745(@value{GDBP})
18746-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
18747^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
18748(@value{GDBP})
18749-environment-path -r /usr/local/bin
18750^done,path="/usr/local/bin:/usr/bin"
18751(@value{GDBP})
18752@end smallexample
18753
18754
18755@subheading The @code{-environment-pwd} Command
18756@findex -environment-pwd
18757
18758@subsubheading Synopsis
18759
18760@smallexample
18761 -environment-pwd
18762@end smallexample
18763
18764Show the current working directory.
18765
18766@subsubheading @value{GDBN} command
18767
18768The corresponding @value{GDBN} command is @samp{pwd}.
18769
18770@subsubheading Example
18771
18772@smallexample
18773(@value{GDBP})
18774-environment-pwd
18775^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
18776(@value{GDBP})
18777@end smallexample
18778
18779@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18780@node GDB/MI Program Control
18781@section @sc{gdb/mi} Program control
18782
18783@subsubheading Program termination
18784
18785As a result of execution, the inferior program can run to completion, if
18786it doesn't encounter any breakpoints. In this case the output will
18787include an exit code, if the program has exited exceptionally.
18788
18789@subsubheading Examples
18790
18791@noindent
18792Program exited normally:
18793
18794@smallexample
18795(@value{GDBP})
18796-exec-run
18797^running
18798(@value{GDBP})
18799x = 55
18800*stopped,reason="exited-normally"
18801(@value{GDBP})
18802@end smallexample
18803
18804@noindent
18805Program exited exceptionally:
18806
18807@smallexample
18808(@value{GDBP})
18809-exec-run
18810^running
18811(@value{GDBP})
18812x = 55
18813*stopped,reason="exited",exit-code="01"
18814(@value{GDBP})
18815@end smallexample
18816
18817Another way the program can terminate is if it receives a signal such as
18818@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
18819
18820@smallexample
18821(@value{GDBP})
18822*stopped,reason="exited-signalled",signal-name="SIGINT",
18823signal-meaning="Interrupt"
18824@end smallexample
18825
18826
18827@subheading The @code{-exec-abort} Command
18828@findex -exec-abort
18829
18830@subsubheading Synopsis
18831
18832@smallexample
18833 -exec-abort
18834@end smallexample
18835
18836Kill the inferior running program.
18837
18838@subsubheading @value{GDBN} Command
18839
18840The corresponding @value{GDBN} command is @samp{kill}.
18841
18842@subsubheading Example
18843N.A.
18844
18845
18846@subheading The @code{-exec-arguments} Command
18847@findex -exec-arguments
18848
18849@subsubheading Synopsis
18850
18851@smallexample
18852 -exec-arguments @var{args}
18853@end smallexample
18854
18855Set the inferior program arguments, to be used in the next
18856@samp{-exec-run}.
18857
18858@subsubheading @value{GDBN} Command
18859
18860The corresponding @value{GDBN} command is @samp{set args}.
18861
18862@subsubheading Example
18863
18864@c FIXME!
18865Don't have one around.
18866
18867
18868@subheading The @code{-exec-continue} Command
18869@findex -exec-continue
18870
18871@subsubheading Synopsis
18872
18873@smallexample
18874 -exec-continue
18875@end smallexample
18876
18877Asynchronous command. Resumes the execution of the inferior program
18878until a breakpoint is encountered, or until the inferior exits.
18879
18880@subsubheading @value{GDBN} Command
18881
18882The corresponding @value{GDBN} corresponding is @samp{continue}.
18883
18884@subsubheading Example
18885
18886@smallexample
18887-exec-continue
18888^running
18889(@value{GDBP})
18890@@Hello world
18891*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
76ff342d 18892file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="13"@}
922fbb7b
AC
18893(@value{GDBP})
18894@end smallexample
18895
18896
18897@subheading The @code{-exec-finish} Command
18898@findex -exec-finish
18899
18900@subsubheading Synopsis
18901
18902@smallexample
18903 -exec-finish
18904@end smallexample
18905
18906Asynchronous command. Resumes the execution of the inferior program
18907until the current function is exited. Displays the results returned by
18908the function.
18909
18910@subsubheading @value{GDBN} Command
18911
18912The corresponding @value{GDBN} command is @samp{finish}.
18913
18914@subsubheading Example
18915
18916Function returning @code{void}.
18917
18918@smallexample
18919-exec-finish
18920^running
18921(@value{GDBP})
18922@@hello from foo
18923*stopped,reason="function-finished",frame=@{func="main",args=[],
76ff342d 18924file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="7"@}
922fbb7b
AC
18925(@value{GDBP})
18926@end smallexample
18927
18928Function returning other than @code{void}. The name of the internal
18929@value{GDBN} variable storing the result is printed, together with the
18930value itself.
18931
18932@smallexample
18933-exec-finish
18934^running
18935(@value{GDBP})
18936*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
18937args=[@{name="a",value="1"],@{name="b",value="9"@}@},
76ff342d 18938file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b
AC
18939gdb-result-var="$1",return-value="0"
18940(@value{GDBP})
18941@end smallexample
18942
18943
18944@subheading The @code{-exec-interrupt} Command
18945@findex -exec-interrupt
18946
18947@subsubheading Synopsis
18948
18949@smallexample
18950 -exec-interrupt
18951@end smallexample
18952
18953Asynchronous command. Interrupts the background execution of the target.
18954Note how the token associated with the stop message is the one for the
18955execution command that has been interrupted. The token for the interrupt
18956itself only appears in the @samp{^done} output. If the user is trying to
18957interrupt a non-running program, an error message will be printed.
18958
18959@subsubheading @value{GDBN} Command
18960
18961The corresponding @value{GDBN} command is @samp{interrupt}.
18962
18963@subsubheading Example
18964
18965@smallexample
18966(@value{GDBP})
18967111-exec-continue
18968111^running
18969
18970(@value{GDBP})
18971222-exec-interrupt
18972222^done
18973(@value{GDBP})
18974111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d
DJ
18975frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
18976fullname="/home/foo/bar/devo/myproject/try.c",line="13"@}
922fbb7b
AC
18977(@value{GDBP})
18978
18979(@value{GDBP})
18980-exec-interrupt
18981^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
18982(@value{GDBP})
18983@end smallexample
18984
18985
18986@subheading The @code{-exec-next} Command
18987@findex -exec-next
18988
18989@subsubheading Synopsis
18990
18991@smallexample
18992 -exec-next
18993@end smallexample
18994
18995Asynchronous command. Resumes execution of the inferior program, stopping
18996when the beginning of the next source line is reached.
18997
18998@subsubheading @value{GDBN} Command
18999
19000The corresponding @value{GDBN} command is @samp{next}.
19001
19002@subsubheading Example
19003
19004@smallexample
19005-exec-next
19006^running
19007(@value{GDBP})
19008*stopped,reason="end-stepping-range",line="8",file="hello.c"
19009(@value{GDBP})
19010@end smallexample
19011
19012
19013@subheading The @code{-exec-next-instruction} Command
19014@findex -exec-next-instruction
19015
19016@subsubheading Synopsis
19017
19018@smallexample
19019 -exec-next-instruction
19020@end smallexample
19021
19022Asynchronous command. Executes one machine instruction. If the
19023instruction is a function call continues until the function returns. If
19024the program stops at an instruction in the middle of a source line, the
19025address will be printed as well.
19026
19027@subsubheading @value{GDBN} Command
19028
19029The corresponding @value{GDBN} command is @samp{nexti}.
19030
19031@subsubheading Example
19032
19033@smallexample
19034(@value{GDBP})
19035-exec-next-instruction
19036^running
19037
19038(@value{GDBP})
19039*stopped,reason="end-stepping-range",
19040addr="0x000100d4",line="5",file="hello.c"
19041(@value{GDBP})
19042@end smallexample
19043
19044
19045@subheading The @code{-exec-return} Command
19046@findex -exec-return
19047
19048@subsubheading Synopsis
19049
19050@smallexample
19051 -exec-return
19052@end smallexample
19053
19054Makes current function return immediately. Doesn't execute the inferior.
19055Displays the new current frame.
19056
19057@subsubheading @value{GDBN} Command
19058
19059The corresponding @value{GDBN} command is @samp{return}.
19060
19061@subsubheading Example
19062
19063@smallexample
19064(@value{GDBP})
19065200-break-insert callee4
19066200^done,bkpt=@{number="1",addr="0x00010734",
19067file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
19068(@value{GDBP})
19069000-exec-run
19070000^running
19071(@value{GDBP})
19072000*stopped,reason="breakpoint-hit",bkptno="1",
19073frame=@{func="callee4",args=[],
76ff342d
DJ
19074file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19075fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
922fbb7b
AC
19076(@value{GDBP})
19077205-break-delete
19078205^done
19079(@value{GDBP})
19080111-exec-return
19081111^done,frame=@{level="0",func="callee3",
19082args=[@{name="strarg",
19083value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
19084file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19085fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
19086(@value{GDBP})
19087@end smallexample
19088
19089
19090@subheading The @code{-exec-run} Command
19091@findex -exec-run
19092
19093@subsubheading Synopsis
19094
19095@smallexample
19096 -exec-run
19097@end smallexample
19098
19099Asynchronous command. Starts execution of the inferior from the
19100beginning. The inferior executes until either a breakpoint is
19101encountered or the program exits.
19102
19103@subsubheading @value{GDBN} Command
19104
19105The corresponding @value{GDBN} command is @samp{run}.
19106
19107@subsubheading Example
19108
19109@smallexample
19110(@value{GDBP})
19111-break-insert main
19112^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
19113(@value{GDBP})
19114-exec-run
19115^running
19116(@value{GDBP})
19117*stopped,reason="breakpoint-hit",bkptno="1",
76ff342d
DJ
19118frame=@{func="main",args=[],file="recursive2.c",
19119fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}
922fbb7b
AC
19120(@value{GDBP})
19121@end smallexample
19122
19123
19124@subheading The @code{-exec-show-arguments} Command
19125@findex -exec-show-arguments
19126
19127@subsubheading Synopsis
19128
19129@smallexample
19130 -exec-show-arguments
19131@end smallexample
19132
19133Print the arguments of the program.
19134
19135@subsubheading @value{GDBN} Command
19136
19137The corresponding @value{GDBN} command is @samp{show args}.
19138
19139@subsubheading Example
19140N.A.
19141
19142@c @subheading -exec-signal
19143
19144@subheading The @code{-exec-step} Command
19145@findex -exec-step
19146
19147@subsubheading Synopsis
19148
19149@smallexample
19150 -exec-step
19151@end smallexample
19152
19153Asynchronous command. Resumes execution of the inferior program, stopping
19154when the beginning of the next source line is reached, if the next
19155source line is not a function call. If it is, stop at the first
19156instruction of the called function.
19157
19158@subsubheading @value{GDBN} Command
19159
19160The corresponding @value{GDBN} command is @samp{step}.
19161
19162@subsubheading Example
19163
19164Stepping into a function:
19165
19166@smallexample
19167-exec-step
19168^running
19169(@value{GDBP})
19170*stopped,reason="end-stepping-range",
19171frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d
DJ
19172@{name="b",value="0"@}],file="recursive2.c",
19173fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@}
922fbb7b
AC
19174(@value{GDBP})
19175@end smallexample
19176
19177Regular stepping:
19178
19179@smallexample
19180-exec-step
19181^running
19182(@value{GDBP})
19183*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
19184(@value{GDBP})
19185@end smallexample
19186
19187
19188@subheading The @code{-exec-step-instruction} Command
19189@findex -exec-step-instruction
19190
19191@subsubheading Synopsis
19192
19193@smallexample
19194 -exec-step-instruction
19195@end smallexample
19196
19197Asynchronous command. Resumes the inferior which executes one machine
19198instruction. The output, once @value{GDBN} has stopped, will vary depending on
19199whether we have stopped in the middle of a source line or not. In the
19200former case, the address at which the program stopped will be printed as
19201well.
19202
19203@subsubheading @value{GDBN} Command
19204
19205The corresponding @value{GDBN} command is @samp{stepi}.
19206
19207@subsubheading Example
19208
19209@smallexample
19210(@value{GDBP})
19211-exec-step-instruction
19212^running
19213
19214(@value{GDBP})
19215*stopped,reason="end-stepping-range",
76ff342d
DJ
19216frame=@{func="foo",args=[],file="try.c",
19217fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
19218(@value{GDBP})
19219-exec-step-instruction
19220^running
19221
19222(@value{GDBP})
19223*stopped,reason="end-stepping-range",
76ff342d
DJ
19224frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
19225fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
19226(@value{GDBP})
19227@end smallexample
19228
19229
19230@subheading The @code{-exec-until} Command
19231@findex -exec-until
19232
19233@subsubheading Synopsis
19234
19235@smallexample
19236 -exec-until [ @var{location} ]
19237@end smallexample
19238
19239Asynchronous command. Executes the inferior until the @var{location}
19240specified in the argument is reached. If there is no argument, the inferior
19241executes until a source line greater than the current one is reached.
19242The reason for stopping in this case will be @samp{location-reached}.
19243
19244@subsubheading @value{GDBN} Command
19245
19246The corresponding @value{GDBN} command is @samp{until}.
19247
19248@subsubheading Example
19249
19250@smallexample
19251(@value{GDBP})
19252-exec-until recursive2.c:6
19253^running
19254(@value{GDBP})
19255x = 55
19256*stopped,reason="location-reached",frame=@{func="main",args=[],
76ff342d 19257file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="6"@}
922fbb7b
AC
19258(@value{GDBP})
19259@end smallexample
19260
19261@ignore
19262@subheading -file-clear
19263Is this going away????
19264@end ignore
19265
19266
19267@subheading The @code{-file-exec-and-symbols} Command
19268@findex -file-exec-and-symbols
19269
19270@subsubheading Synopsis
19271
19272@smallexample
19273 -file-exec-and-symbols @var{file}
19274@end smallexample
19275
19276Specify the executable file to be debugged. This file is the one from
19277which the symbol table is also read. If no file is specified, the
19278command clears the executable and symbol information. If breakpoints
19279are set when using this command with no arguments, @value{GDBN} will produce
19280error messages. Otherwise, no output is produced, except a completion
19281notification.
19282
19283@subsubheading @value{GDBN} Command
19284
19285The corresponding @value{GDBN} command is @samp{file}.
19286
19287@subsubheading Example
19288
19289@smallexample
19290(@value{GDBP})
19291-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
19292^done
19293(@value{GDBP})
19294@end smallexample
19295
19296
19297@subheading The @code{-file-exec-file} Command
19298@findex -file-exec-file
19299
19300@subsubheading Synopsis
19301
19302@smallexample
19303 -file-exec-file @var{file}
19304@end smallexample
19305
19306Specify the executable file to be debugged. Unlike
19307@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
19308from this file. If used without argument, @value{GDBN} clears the information
19309about the executable file. No output is produced, except a completion
19310notification.
19311
19312@subsubheading @value{GDBN} Command
19313
19314The corresponding @value{GDBN} command is @samp{exec-file}.
19315
19316@subsubheading Example
19317
19318@smallexample
19319(@value{GDBP})
19320-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
19321^done
19322(@value{GDBP})
19323@end smallexample
19324
19325
19326@subheading The @code{-file-list-exec-sections} Command
19327@findex -file-list-exec-sections
19328
19329@subsubheading Synopsis
19330
19331@smallexample
19332 -file-list-exec-sections
19333@end smallexample
19334
19335List the sections of the current executable file.
19336
19337@subsubheading @value{GDBN} Command
19338
19339The @value{GDBN} command @samp{info file} shows, among the rest, the same
19340information as this command. @code{gdbtk} has a corresponding command
19341@samp{gdb_load_info}.
19342
19343@subsubheading Example
19344N.A.
19345
19346
1abaf70c
BR
19347@subheading The @code{-file-list-exec-source-file} Command
19348@findex -file-list-exec-source-file
19349
19350@subsubheading Synopsis
19351
19352@smallexample
19353 -file-list-exec-source-file
19354@end smallexample
19355
b383017d 19356List the line number, the current source file, and the absolute path
1abaf70c
BR
19357to the current source file for the current executable.
19358
19359@subsubheading @value{GDBN} Command
19360
19361There's no @value{GDBN} command which directly corresponds to this one.
19362
19363@subsubheading Example
19364
19365@smallexample
19366(@value{GDBP})
19367123-file-list-exec-source-file
19368123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
19369(@value{GDBP})
19370@end smallexample
19371
19372
922fbb7b
AC
19373@subheading The @code{-file-list-exec-source-files} Command
19374@findex -file-list-exec-source-files
19375
19376@subsubheading Synopsis
19377
19378@smallexample
19379 -file-list-exec-source-files
19380@end smallexample
19381
19382List the source files for the current executable.
19383
57c22c6c
BR
19384It will always output the filename, but only when GDB can find the absolute
19385file name of a source file, will it output the fullname.
19386
922fbb7b
AC
19387@subsubheading @value{GDBN} Command
19388
19389There's no @value{GDBN} command which directly corresponds to this one.
19390@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
19391
19392@subsubheading Example
57c22c6c
BR
19393@smallexample
19394(@value{GDBP})
19395-file-list-exec-source-files
19396^done,files=[
19397@{file=foo.c,fullname=/home/foo.c@},
19398@{file=/home/bar.c,fullname=/home/bar.c@},
19399@{file=gdb_could_not_find_fullpath.c@}]
19400(@value{GDBP})
19401@end smallexample
922fbb7b
AC
19402
19403@subheading The @code{-file-list-shared-libraries} Command
19404@findex -file-list-shared-libraries
19405
19406@subsubheading Synopsis
19407
19408@smallexample
19409 -file-list-shared-libraries
19410@end smallexample
19411
19412List the shared libraries in the program.
19413
19414@subsubheading @value{GDBN} Command
19415
19416The corresponding @value{GDBN} command is @samp{info shared}.
19417
19418@subsubheading Example
19419N.A.
19420
19421
19422@subheading The @code{-file-list-symbol-files} Command
19423@findex -file-list-symbol-files
19424
19425@subsubheading Synopsis
19426
19427@smallexample
19428 -file-list-symbol-files
19429@end smallexample
19430
19431List symbol files.
19432
19433@subsubheading @value{GDBN} Command
19434
19435The corresponding @value{GDBN} command is @samp{info file} (part of it).
19436
19437@subsubheading Example
19438N.A.
19439
19440
19441@subheading The @code{-file-symbol-file} Command
19442@findex -file-symbol-file
19443
19444@subsubheading Synopsis
19445
19446@smallexample
19447 -file-symbol-file @var{file}
19448@end smallexample
19449
19450Read symbol table info from the specified @var{file} argument. When
19451used without arguments, clears @value{GDBN}'s symbol table info. No output is
19452produced, except for a completion notification.
19453
19454@subsubheading @value{GDBN} Command
19455
19456The corresponding @value{GDBN} command is @samp{symbol-file}.
19457
19458@subsubheading Example
19459
19460@smallexample
19461(@value{GDBP})
19462-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
19463^done
19464(@value{GDBP})
19465@end smallexample
19466
19467@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19468@node GDB/MI Miscellaneous Commands
19469@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
19470
19471@c @subheading -gdb-complete
19472
19473@subheading The @code{-gdb-exit} Command
19474@findex -gdb-exit
19475
19476@subsubheading Synopsis
19477
19478@smallexample
19479 -gdb-exit
19480@end smallexample
19481
19482Exit @value{GDBN} immediately.
19483
19484@subsubheading @value{GDBN} Command
19485
19486Approximately corresponds to @samp{quit}.
19487
19488@subsubheading Example
19489
19490@smallexample
19491(@value{GDBP})
19492-gdb-exit
19493@end smallexample
19494
19495@subheading The @code{-gdb-set} Command
19496@findex -gdb-set
19497
19498@subsubheading Synopsis
19499
19500@smallexample
19501 -gdb-set
19502@end smallexample
19503
19504Set an internal @value{GDBN} variable.
19505@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
19506
19507@subsubheading @value{GDBN} Command
19508
19509The corresponding @value{GDBN} command is @samp{set}.
19510
19511@subsubheading Example
19512
19513@smallexample
19514(@value{GDBP})
19515-gdb-set $foo=3
19516^done
19517(@value{GDBP})
19518@end smallexample
19519
19520
19521@subheading The @code{-gdb-show} Command
19522@findex -gdb-show
19523
19524@subsubheading Synopsis
19525
19526@smallexample
19527 -gdb-show
19528@end smallexample
19529
19530Show the current value of a @value{GDBN} variable.
19531
19532@subsubheading @value{GDBN} command
19533
19534The corresponding @value{GDBN} command is @samp{show}.
19535
19536@subsubheading Example
19537
19538@smallexample
19539(@value{GDBP})
19540-gdb-show annotate
19541^done,value="0"
19542(@value{GDBP})
19543@end smallexample
19544
19545@c @subheading -gdb-source
19546
19547
19548@subheading The @code{-gdb-version} Command
19549@findex -gdb-version
19550
19551@subsubheading Synopsis
19552
19553@smallexample
19554 -gdb-version
19555@end smallexample
19556
19557Show version information for @value{GDBN}. Used mostly in testing.
19558
19559@subsubheading @value{GDBN} Command
19560
19561There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
19562information when you start an interactive session.
19563
19564@subsubheading Example
19565
19566@c This example modifies the actual output from GDB to avoid overfull
19567@c box in TeX.
19568@smallexample
19569(@value{GDBP})
19570-gdb-version
19571~GNU gdb 5.2.1
19572~Copyright 2000 Free Software Foundation, Inc.
19573~GDB is free software, covered by the GNU General Public License, and
19574~you are welcome to change it and/or distribute copies of it under
19575~ certain conditions.
19576~Type "show copying" to see the conditions.
19577~There is absolutely no warranty for GDB. Type "show warranty" for
19578~ details.
b383017d 19579~This GDB was configured as
922fbb7b
AC
19580 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
19581^done
19582(@value{GDBP})
19583@end smallexample
19584
19585@subheading The @code{-interpreter-exec} Command
19586@findex -interpreter-exec
19587
19588@subheading Synopsis
19589
19590@smallexample
19591-interpreter-exec @var{interpreter} @var{command}
19592@end smallexample
19593
19594Execute the specified @var{command} in the given @var{interpreter}.
19595
19596@subheading @value{GDBN} Command
19597
19598The corresponding @value{GDBN} command is @samp{interpreter-exec}.
19599
19600@subheading Example
19601
19602@smallexample
19603(@value{GDBP})
19604-interpreter-exec console "break main"
19605&"During symbol reading, couldn't parse type; debugger out of date?.\n"
19606&"During symbol reading, bad structure-type format.\n"
19607~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
19608^done
19609(@value{GDBP})
19610@end smallexample
19611
3cb3b8df
BR
19612@subheading The @code{-inferior-tty-set} Command
19613@findex -inferior-tty-set
19614
19615@subheading Synopsis
19616
19617@smallexample
19618-inferior-tty-set /dev/pts/1
19619@end smallexample
19620
19621Set terminal for future runs of the program being debugged.
19622
19623@subheading @value{GDBN} Command
19624
19625The corresponding @value{GDBN} command is @samp{set inferior-tty /dev/pts/1}.
19626
19627@subheading Example
19628
19629@smallexample
19630(@value{GDBP})
19631-inferior-tty-set /dev/pts/1
19632^done
19633(@value{GDBP})
19634@end smallexample
19635
19636@subheading The @code{-inferior-tty-show} Command
19637@findex -inferior-tty-show
19638
19639@subheading Synopsis
19640
19641@smallexample
19642-inferior-tty-show
19643@end smallexample
19644
19645Show terminal for future runs of program being debugged.
19646
19647@subheading @value{GDBN} Command
19648
38f1196a 19649The corresponding @value{GDBN} command is @samp{show inferior-tty}.
3cb3b8df
BR
19650
19651@subheading Example
19652
19653@smallexample
19654(@value{GDBP})
19655-inferior-tty-set /dev/pts/1
19656^done
19657(@value{GDBP})
19658-inferior-tty-show
19659^done,inferior_tty_terminal="/dev/pts/1"
19660(@value{GDBP})
19661@end smallexample
19662
922fbb7b
AC
19663@ignore
19664@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19665@node GDB/MI Kod Commands
19666@section @sc{gdb/mi} Kod Commands
19667
19668The Kod commands are not implemented.
19669
19670@c @subheading -kod-info
19671
19672@c @subheading -kod-list
19673
19674@c @subheading -kod-list-object-types
19675
19676@c @subheading -kod-show
19677
19678@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19679@node GDB/MI Memory Overlay Commands
19680@section @sc{gdb/mi} Memory Overlay Commands
19681
19682The memory overlay commands are not implemented.
19683
19684@c @subheading -overlay-auto
19685
19686@c @subheading -overlay-list-mapping-state
19687
19688@c @subheading -overlay-list-overlays
19689
19690@c @subheading -overlay-map
19691
19692@c @subheading -overlay-off
19693
19694@c @subheading -overlay-on
19695
19696@c @subheading -overlay-unmap
19697
19698@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19699@node GDB/MI Signal Handling Commands
19700@section @sc{gdb/mi} Signal Handling Commands
19701
19702Signal handling commands are not implemented.
19703
19704@c @subheading -signal-handle
19705
19706@c @subheading -signal-list-handle-actions
19707
19708@c @subheading -signal-list-signal-types
19709@end ignore
19710
19711
19712@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19713@node GDB/MI Stack Manipulation
19714@section @sc{gdb/mi} Stack Manipulation Commands
19715
dcaaae04
NR
19716
19717@subheading The @code{-stack-info-frame} Command
19718@findex -stack-info-frame
19719
19720@subsubheading Synopsis
19721
19722@smallexample
19723 -stack-info-frame
19724@end smallexample
19725
19726Get info on the selected frame.
19727
19728@subsubheading @value{GDBN} Command
19729
19730The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
19731(without arguments).
19732
19733@subsubheading Example
19734
19735@smallexample
19736(@value{GDBP})
19737-stack-info-frame
19738^done,frame=@{level="1",addr="0x0001076c",func="callee3",
19739file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19740fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
19741(@value{GDBP})
19742@end smallexample
19743
922fbb7b
AC
19744@subheading The @code{-stack-info-depth} Command
19745@findex -stack-info-depth
19746
19747@subsubheading Synopsis
19748
19749@smallexample
19750 -stack-info-depth [ @var{max-depth} ]
19751@end smallexample
19752
19753Return the depth of the stack. If the integer argument @var{max-depth}
19754is specified, do not count beyond @var{max-depth} frames.
19755
19756@subsubheading @value{GDBN} Command
19757
19758There's no equivalent @value{GDBN} command.
19759
19760@subsubheading Example
19761
19762For a stack with frame levels 0 through 11:
19763
19764@smallexample
19765(@value{GDBP})
19766-stack-info-depth
19767^done,depth="12"
19768(@value{GDBP})
19769-stack-info-depth 4
19770^done,depth="4"
19771(@value{GDBP})
19772-stack-info-depth 12
19773^done,depth="12"
19774(@value{GDBP})
19775-stack-info-depth 11
19776^done,depth="11"
19777(@value{GDBP})
19778-stack-info-depth 13
19779^done,depth="12"
19780(@value{GDBP})
19781@end smallexample
19782
19783@subheading The @code{-stack-list-arguments} Command
19784@findex -stack-list-arguments
19785
19786@subsubheading Synopsis
19787
19788@smallexample
19789 -stack-list-arguments @var{show-values}
19790 [ @var{low-frame} @var{high-frame} ]
19791@end smallexample
19792
19793Display a list of the arguments for the frames between @var{low-frame}
19794and @var{high-frame} (inclusive). If @var{low-frame} and
19795@var{high-frame} are not provided, list the arguments for the whole call
19796stack.
19797
19798The @var{show-values} argument must have a value of 0 or 1. A value of
197990 means that only the names of the arguments are listed, a value of 1
19800means that both names and values of the arguments are printed.
19801
19802@subsubheading @value{GDBN} Command
19803
19804@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
19805@samp{gdb_get_args} command which partially overlaps with the
19806functionality of @samp{-stack-list-arguments}.
19807
19808@subsubheading Example
19809
19810@smallexample
19811(@value{GDBP})
19812-stack-list-frames
19813^done,
19814stack=[
19815frame=@{level="0",addr="0x00010734",func="callee4",
76ff342d
DJ
19816file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19817fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
922fbb7b 19818frame=@{level="1",addr="0x0001076c",func="callee3",
76ff342d
DJ
19819file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19820fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
922fbb7b 19821frame=@{level="2",addr="0x0001078c",func="callee2",
76ff342d
DJ
19822file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19823fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
922fbb7b 19824frame=@{level="3",addr="0x000107b4",func="callee1",
76ff342d
DJ
19825file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19826fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
922fbb7b 19827frame=@{level="4",addr="0x000107e0",func="main",
76ff342d
DJ
19828file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19829fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
922fbb7b
AC
19830(@value{GDBP})
19831-stack-list-arguments 0
19832^done,
19833stack-args=[
19834frame=@{level="0",args=[]@},
19835frame=@{level="1",args=[name="strarg"]@},
19836frame=@{level="2",args=[name="intarg",name="strarg"]@},
19837frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
19838frame=@{level="4",args=[]@}]
19839(@value{GDBP})
19840-stack-list-arguments 1
19841^done,
19842stack-args=[
19843frame=@{level="0",args=[]@},
19844frame=@{level="1",
19845 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19846frame=@{level="2",args=[
19847@{name="intarg",value="2"@},
19848@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19849@{frame=@{level="3",args=[
19850@{name="intarg",value="2"@},
19851@{name="strarg",value="0x11940 \"A string argument.\""@},
19852@{name="fltarg",value="3.5"@}]@},
19853frame=@{level="4",args=[]@}]
19854(@value{GDBP})
19855-stack-list-arguments 0 2 2
19856^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
19857(@value{GDBP})
19858-stack-list-arguments 1 2 2
19859^done,stack-args=[frame=@{level="2",
19860args=[@{name="intarg",value="2"@},
19861@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
19862(@value{GDBP})
19863@end smallexample
19864
19865@c @subheading -stack-list-exception-handlers
19866
19867
19868@subheading The @code{-stack-list-frames} Command
19869@findex -stack-list-frames
19870
19871@subsubheading Synopsis
19872
19873@smallexample
19874 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
19875@end smallexample
19876
19877List the frames currently on the stack. For each frame it displays the
19878following info:
19879
19880@table @samp
19881@item @var{level}
19882The frame number, 0 being the topmost frame, i.e. the innermost function.
19883@item @var{addr}
19884The @code{$pc} value for that frame.
19885@item @var{func}
19886Function name.
19887@item @var{file}
19888File name of the source file where the function lives.
19889@item @var{line}
19890Line number corresponding to the @code{$pc}.
19891@end table
19892
19893If invoked without arguments, this command prints a backtrace for the
19894whole stack. If given two integer arguments, it shows the frames whose
19895levels are between the two arguments (inclusive). If the two arguments
19896are equal, it shows the single frame at the corresponding level.
19897
19898@subsubheading @value{GDBN} Command
19899
19900The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
19901
19902@subsubheading Example
19903
19904Full stack backtrace:
19905
19906@smallexample
19907(@value{GDBP})
19908-stack-list-frames
19909^done,stack=
19910[frame=@{level="0",addr="0x0001076c",func="foo",
76ff342d 19911 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@},
922fbb7b 19912frame=@{level="1",addr="0x000107a4",func="foo",
76ff342d 19913 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19914frame=@{level="2",addr="0x000107a4",func="foo",
76ff342d 19915 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19916frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19917 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19918frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19919 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19920frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19921 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19922frame=@{level="6",addr="0x000107a4",func="foo",
76ff342d 19923 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19924frame=@{level="7",addr="0x000107a4",func="foo",
76ff342d 19925 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19926frame=@{level="8",addr="0x000107a4",func="foo",
76ff342d 19927 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19928frame=@{level="9",addr="0x000107a4",func="foo",
76ff342d 19929 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19930frame=@{level="10",addr="0x000107a4",func="foo",
76ff342d 19931 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19932frame=@{level="11",addr="0x00010738",func="main",
76ff342d 19933 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}]
922fbb7b
AC
19934(@value{GDBP})
19935@end smallexample
19936
19937Show frames between @var{low_frame} and @var{high_frame}:
19938
19939@smallexample
19940(@value{GDBP})
19941-stack-list-frames 3 5
19942^done,stack=
19943[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19944 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19945frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19946 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19947frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19948 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19949(@value{GDBP})
19950@end smallexample
19951
19952Show a single frame:
19953
19954@smallexample
19955(@value{GDBP})
19956-stack-list-frames 3 3
19957^done,stack=
19958[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19959 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19960(@value{GDBP})
19961@end smallexample
19962
19963
19964@subheading The @code{-stack-list-locals} Command
19965@findex -stack-list-locals
19966
19967@subsubheading Synopsis
19968
19969@smallexample
19970 -stack-list-locals @var{print-values}
19971@end smallexample
19972
265eeb58
NR
19973Display the local variable names for the selected frame. If
19974@var{print-values} is 0 or @code{--no-values}, print only the names of
19975the variables; if it is 1 or @code{--all-values}, print also their
19976values; and if it is 2 or @code{--simple-values}, print the name,
19977type and value for simple data types and the name and type for arrays,
19978structures and unions. In this last case, a frontend can immediately
19979display the value of simple data types and create variable objects for
19980other data types when the the user wishes to explore their values in
bc8ced35 19981more detail.
922fbb7b
AC
19982
19983@subsubheading @value{GDBN} Command
19984
19985@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
19986
19987@subsubheading Example
19988
19989@smallexample
19990(@value{GDBP})
19991-stack-list-locals 0
19992^done,locals=[name="A",name="B",name="C"]
19993(@value{GDBP})
bc8ced35 19994-stack-list-locals --all-values
922fbb7b 19995^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
bc8ced35
NR
19996 @{name="C",value="@{1, 2, 3@}"@}]
19997-stack-list-locals --simple-values
19998^done,locals=[@{name="A",type="int",value="1"@},
19999 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
922fbb7b
AC
20000(@value{GDBP})
20001@end smallexample
20002
20003
20004@subheading The @code{-stack-select-frame} Command
20005@findex -stack-select-frame
20006
20007@subsubheading Synopsis
20008
20009@smallexample
20010 -stack-select-frame @var{framenum}
20011@end smallexample
20012
265eeb58 20013Change the selected frame. Select a different frame @var{framenum} on
922fbb7b
AC
20014the stack.
20015
20016@subsubheading @value{GDBN} Command
20017
20018The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
20019@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
20020
20021@subsubheading Example
20022
20023@smallexample
20024(@value{GDBP})
20025-stack-select-frame 2
20026^done
20027(@value{GDBP})
20028@end smallexample
20029
20030@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20031@node GDB/MI Symbol Query
20032@section @sc{gdb/mi} Symbol Query Commands
20033
20034
20035@subheading The @code{-symbol-info-address} Command
20036@findex -symbol-info-address
20037
20038@subsubheading Synopsis
20039
20040@smallexample
20041 -symbol-info-address @var{symbol}
20042@end smallexample
20043
20044Describe where @var{symbol} is stored.
20045
20046@subsubheading @value{GDBN} Command
20047
20048The corresponding @value{GDBN} command is @samp{info address}.
20049
20050@subsubheading Example
20051N.A.
20052
20053
20054@subheading The @code{-symbol-info-file} Command
20055@findex -symbol-info-file
20056
20057@subsubheading Synopsis
20058
20059@smallexample
20060 -symbol-info-file
20061@end smallexample
20062
20063Show the file for the symbol.
20064
20065@subsubheading @value{GDBN} Command
20066
20067There's no equivalent @value{GDBN} command. @code{gdbtk} has
20068@samp{gdb_find_file}.
20069
20070@subsubheading Example
20071N.A.
20072
20073
20074@subheading The @code{-symbol-info-function} Command
20075@findex -symbol-info-function
20076
20077@subsubheading Synopsis
20078
20079@smallexample
20080 -symbol-info-function
20081@end smallexample
20082
20083Show which function the symbol lives in.
20084
20085@subsubheading @value{GDBN} Command
20086
20087@samp{gdb_get_function} in @code{gdbtk}.
20088
20089@subsubheading Example
20090N.A.
20091
20092
20093@subheading The @code{-symbol-info-line} Command
20094@findex -symbol-info-line
20095
20096@subsubheading Synopsis
20097
20098@smallexample
20099 -symbol-info-line
20100@end smallexample
20101
20102Show the core addresses of the code for a source line.
20103
20104@subsubheading @value{GDBN} Command
20105
71952f4c 20106The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
20107@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
20108
20109@subsubheading Example
20110N.A.
20111
20112
20113@subheading The @code{-symbol-info-symbol} Command
20114@findex -symbol-info-symbol
20115
20116@subsubheading Synopsis
20117
20118@smallexample
20119 -symbol-info-symbol @var{addr}
20120@end smallexample
20121
20122Describe what symbol is at location @var{addr}.
20123
20124@subsubheading @value{GDBN} Command
20125
20126The corresponding @value{GDBN} command is @samp{info symbol}.
20127
20128@subsubheading Example
20129N.A.
20130
20131
20132@subheading The @code{-symbol-list-functions} Command
20133@findex -symbol-list-functions
20134
20135@subsubheading Synopsis
20136
20137@smallexample
20138 -symbol-list-functions
20139@end smallexample
20140
20141List the functions in the executable.
20142
20143@subsubheading @value{GDBN} Command
20144
20145@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
20146@samp{gdb_search} in @code{gdbtk}.
20147
20148@subsubheading Example
20149N.A.
20150
20151
32e7087d
JB
20152@subheading The @code{-symbol-list-lines} Command
20153@findex -symbol-list-lines
20154
20155@subsubheading Synopsis
20156
20157@smallexample
20158 -symbol-list-lines @var{filename}
20159@end smallexample
20160
20161Print the list of lines that contain code and their associated program
20162addresses for the given source filename. The entries are sorted in
20163ascending PC order.
20164
20165@subsubheading @value{GDBN} Command
20166
20167There is no corresponding @value{GDBN} command.
20168
20169@subsubheading Example
20170@smallexample
20171(@value{GDBP})
20172-symbol-list-lines basics.c
54ff5908 20173^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
20174(@value{GDBP})
20175@end smallexample
20176
20177
922fbb7b
AC
20178@subheading The @code{-symbol-list-types} Command
20179@findex -symbol-list-types
20180
20181@subsubheading Synopsis
20182
20183@smallexample
20184 -symbol-list-types
20185@end smallexample
20186
20187List all the type names.
20188
20189@subsubheading @value{GDBN} Command
20190
20191The corresponding commands are @samp{info types} in @value{GDBN},
20192@samp{gdb_search} in @code{gdbtk}.
20193
20194@subsubheading Example
20195N.A.
20196
20197
20198@subheading The @code{-symbol-list-variables} Command
20199@findex -symbol-list-variables
20200
20201@subsubheading Synopsis
20202
20203@smallexample
20204 -symbol-list-variables
20205@end smallexample
20206
20207List all the global and static variable names.
20208
20209@subsubheading @value{GDBN} Command
20210
20211@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
20212
20213@subsubheading Example
20214N.A.
20215
20216
20217@subheading The @code{-symbol-locate} Command
20218@findex -symbol-locate
20219
20220@subsubheading Synopsis
20221
20222@smallexample
20223 -symbol-locate
20224@end smallexample
20225
20226@subsubheading @value{GDBN} Command
20227
20228@samp{gdb_loc} in @code{gdbtk}.
20229
20230@subsubheading Example
20231N.A.
20232
20233
20234@subheading The @code{-symbol-type} Command
20235@findex -symbol-type
20236
20237@subsubheading Synopsis
20238
20239@smallexample
20240 -symbol-type @var{variable}
20241@end smallexample
20242
20243Show type of @var{variable}.
20244
20245@subsubheading @value{GDBN} Command
20246
20247The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
20248@samp{gdb_obj_variable}.
20249
20250@subsubheading Example
20251N.A.
20252
20253
20254@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20255@node GDB/MI Target Manipulation
20256@section @sc{gdb/mi} Target Manipulation Commands
20257
20258
20259@subheading The @code{-target-attach} Command
20260@findex -target-attach
20261
20262@subsubheading Synopsis
20263
20264@smallexample
20265 -target-attach @var{pid} | @var{file}
20266@end smallexample
20267
20268Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
20269
20270@subsubheading @value{GDBN} command
20271
20272The corresponding @value{GDBN} command is @samp{attach}.
20273
20274@subsubheading Example
20275N.A.
20276
20277
20278@subheading The @code{-target-compare-sections} Command
20279@findex -target-compare-sections
20280
20281@subsubheading Synopsis
20282
20283@smallexample
20284 -target-compare-sections [ @var{section} ]
20285@end smallexample
20286
20287Compare data of section @var{section} on target to the exec file.
20288Without the argument, all sections are compared.
20289
20290@subsubheading @value{GDBN} Command
20291
20292The @value{GDBN} equivalent is @samp{compare-sections}.
20293
20294@subsubheading Example
20295N.A.
20296
20297
20298@subheading The @code{-target-detach} Command
20299@findex -target-detach
20300
20301@subsubheading Synopsis
20302
20303@smallexample
20304 -target-detach
20305@end smallexample
20306
20307Disconnect from the remote target. There's no output.
20308
20309@subsubheading @value{GDBN} command
20310
20311The corresponding @value{GDBN} command is @samp{detach}.
20312
20313@subsubheading Example
20314
20315@smallexample
20316(@value{GDBP})
20317-target-detach
20318^done
20319(@value{GDBP})
20320@end smallexample
20321
20322
07f31aa6
DJ
20323@subheading The @code{-target-disconnect} Command
20324@findex -target-disconnect
20325
20326@subsubheading Synopsis
20327
20328@example
20329 -target-disconnect
20330@end example
20331
20332Disconnect from the remote target. There's no output.
20333
20334@subsubheading @value{GDBN} command
20335
20336The corresponding @value{GDBN} command is @samp{disconnect}.
20337
20338@subsubheading Example
20339
20340@smallexample
20341(@value{GDBP})
20342-target-disconnect
20343^done
20344(@value{GDBP})
20345@end smallexample
20346
20347
922fbb7b
AC
20348@subheading The @code{-target-download} Command
20349@findex -target-download
20350
20351@subsubheading Synopsis
20352
20353@smallexample
20354 -target-download
20355@end smallexample
20356
20357Loads the executable onto the remote target.
20358It prints out an update message every half second, which includes the fields:
20359
20360@table @samp
20361@item section
20362The name of the section.
20363@item section-sent
20364The size of what has been sent so far for that section.
20365@item section-size
20366The size of the section.
20367@item total-sent
20368The total size of what was sent so far (the current and the previous sections).
20369@item total-size
20370The size of the overall executable to download.
20371@end table
20372
20373@noindent
20374Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
20375@sc{gdb/mi} Output Syntax}).
20376
20377In addition, it prints the name and size of the sections, as they are
20378downloaded. These messages include the following fields:
20379
20380@table @samp
20381@item section
20382The name of the section.
20383@item section-size
20384The size of the section.
20385@item total-size
20386The size of the overall executable to download.
20387@end table
20388
20389@noindent
20390At the end, a summary is printed.
20391
20392@subsubheading @value{GDBN} Command
20393
20394The corresponding @value{GDBN} command is @samp{load}.
20395
20396@subsubheading Example
20397
20398Note: each status message appears on a single line. Here the messages
20399have been broken down so that they can fit onto a page.
20400
20401@smallexample
20402(@value{GDBP})
20403-target-download
20404+download,@{section=".text",section-size="6668",total-size="9880"@}
20405+download,@{section=".text",section-sent="512",section-size="6668",
20406total-sent="512",total-size="9880"@}
20407+download,@{section=".text",section-sent="1024",section-size="6668",
20408total-sent="1024",total-size="9880"@}
20409+download,@{section=".text",section-sent="1536",section-size="6668",
20410total-sent="1536",total-size="9880"@}
20411+download,@{section=".text",section-sent="2048",section-size="6668",
20412total-sent="2048",total-size="9880"@}
20413+download,@{section=".text",section-sent="2560",section-size="6668",
20414total-sent="2560",total-size="9880"@}
20415+download,@{section=".text",section-sent="3072",section-size="6668",
20416total-sent="3072",total-size="9880"@}
20417+download,@{section=".text",section-sent="3584",section-size="6668",
20418total-sent="3584",total-size="9880"@}
20419+download,@{section=".text",section-sent="4096",section-size="6668",
20420total-sent="4096",total-size="9880"@}
20421+download,@{section=".text",section-sent="4608",section-size="6668",
20422total-sent="4608",total-size="9880"@}
20423+download,@{section=".text",section-sent="5120",section-size="6668",
20424total-sent="5120",total-size="9880"@}
20425+download,@{section=".text",section-sent="5632",section-size="6668",
20426total-sent="5632",total-size="9880"@}
20427+download,@{section=".text",section-sent="6144",section-size="6668",
20428total-sent="6144",total-size="9880"@}
20429+download,@{section=".text",section-sent="6656",section-size="6668",
20430total-sent="6656",total-size="9880"@}
20431+download,@{section=".init",section-size="28",total-size="9880"@}
20432+download,@{section=".fini",section-size="28",total-size="9880"@}
20433+download,@{section=".data",section-size="3156",total-size="9880"@}
20434+download,@{section=".data",section-sent="512",section-size="3156",
20435total-sent="7236",total-size="9880"@}
20436+download,@{section=".data",section-sent="1024",section-size="3156",
20437total-sent="7748",total-size="9880"@}
20438+download,@{section=".data",section-sent="1536",section-size="3156",
20439total-sent="8260",total-size="9880"@}
20440+download,@{section=".data",section-sent="2048",section-size="3156",
20441total-sent="8772",total-size="9880"@}
20442+download,@{section=".data",section-sent="2560",section-size="3156",
20443total-sent="9284",total-size="9880"@}
20444+download,@{section=".data",section-sent="3072",section-size="3156",
20445total-sent="9796",total-size="9880"@}
20446^done,address="0x10004",load-size="9880",transfer-rate="6586",
20447write-rate="429"
20448(@value{GDBP})
20449@end smallexample
20450
20451
20452@subheading The @code{-target-exec-status} Command
20453@findex -target-exec-status
20454
20455@subsubheading Synopsis
20456
20457@smallexample
20458 -target-exec-status
20459@end smallexample
20460
20461Provide information on the state of the target (whether it is running or
20462not, for instance).
20463
20464@subsubheading @value{GDBN} Command
20465
20466There's no equivalent @value{GDBN} command.
20467
20468@subsubheading Example
20469N.A.
20470
20471
20472@subheading The @code{-target-list-available-targets} Command
20473@findex -target-list-available-targets
20474
20475@subsubheading Synopsis
20476
20477@smallexample
20478 -target-list-available-targets
20479@end smallexample
20480
20481List the possible targets to connect to.
20482
20483@subsubheading @value{GDBN} Command
20484
20485The corresponding @value{GDBN} command is @samp{help target}.
20486
20487@subsubheading Example
20488N.A.
20489
20490
20491@subheading The @code{-target-list-current-targets} Command
20492@findex -target-list-current-targets
20493
20494@subsubheading Synopsis
20495
20496@smallexample
20497 -target-list-current-targets
20498@end smallexample
20499
20500Describe the current target.
20501
20502@subsubheading @value{GDBN} Command
20503
20504The corresponding information is printed by @samp{info file} (among
20505other things).
20506
20507@subsubheading Example
20508N.A.
20509
20510
20511@subheading The @code{-target-list-parameters} Command
20512@findex -target-list-parameters
20513
20514@subsubheading Synopsis
20515
20516@smallexample
20517 -target-list-parameters
20518@end smallexample
20519
20520@c ????
20521
20522@subsubheading @value{GDBN} Command
20523
20524No equivalent.
20525
20526@subsubheading Example
20527N.A.
20528
20529
20530@subheading The @code{-target-select} Command
20531@findex -target-select
20532
20533@subsubheading Synopsis
20534
20535@smallexample
20536 -target-select @var{type} @var{parameters @dots{}}
20537@end smallexample
20538
20539Connect @value{GDBN} to the remote target. This command takes two args:
20540
20541@table @samp
20542@item @var{type}
20543The type of target, for instance @samp{async}, @samp{remote}, etc.
20544@item @var{parameters}
20545Device names, host names and the like. @xref{Target Commands, ,
20546Commands for managing targets}, for more details.
20547@end table
20548
20549The output is a connection notification, followed by the address at
20550which the target program is, in the following form:
20551
20552@smallexample
20553^connected,addr="@var{address}",func="@var{function name}",
20554 args=[@var{arg list}]
20555@end smallexample
20556
20557@subsubheading @value{GDBN} Command
20558
20559The corresponding @value{GDBN} command is @samp{target}.
20560
20561@subsubheading Example
20562
20563@smallexample
20564(@value{GDBP})
20565-target-select async /dev/ttya
20566^connected,addr="0xfe00a300",func="??",args=[]
20567(@value{GDBP})
20568@end smallexample
20569
20570@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20571@node GDB/MI Thread Commands
20572@section @sc{gdb/mi} Thread Commands
20573
20574
20575@subheading The @code{-thread-info} Command
20576@findex -thread-info
20577
20578@subsubheading Synopsis
20579
20580@smallexample
20581 -thread-info
20582@end smallexample
20583
20584@subsubheading @value{GDBN} command
20585
20586No equivalent.
20587
20588@subsubheading Example
20589N.A.
20590
20591
20592@subheading The @code{-thread-list-all-threads} Command
20593@findex -thread-list-all-threads
20594
20595@subsubheading Synopsis
20596
20597@smallexample
20598 -thread-list-all-threads
20599@end smallexample
20600
20601@subsubheading @value{GDBN} Command
20602
20603The equivalent @value{GDBN} command is @samp{info threads}.
20604
20605@subsubheading Example
20606N.A.
20607
20608
20609@subheading The @code{-thread-list-ids} Command
20610@findex -thread-list-ids
20611
20612@subsubheading Synopsis
20613
20614@smallexample
20615 -thread-list-ids
20616@end smallexample
20617
20618Produces a list of the currently known @value{GDBN} thread ids. At the
20619end of the list it also prints the total number of such threads.
20620
20621@subsubheading @value{GDBN} Command
20622
20623Part of @samp{info threads} supplies the same information.
20624
20625@subsubheading Example
20626
20627No threads present, besides the main process:
20628
20629@smallexample
20630(@value{GDBP})
20631-thread-list-ids
20632^done,thread-ids=@{@},number-of-threads="0"
20633(@value{GDBP})
20634@end smallexample
20635
20636
20637Several threads:
20638
20639@smallexample
20640(@value{GDBP})
20641-thread-list-ids
20642^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20643number-of-threads="3"
20644(@value{GDBP})
20645@end smallexample
20646
20647
20648@subheading The @code{-thread-select} Command
20649@findex -thread-select
20650
20651@subsubheading Synopsis
20652
20653@smallexample
20654 -thread-select @var{threadnum}
20655@end smallexample
20656
20657Make @var{threadnum} the current thread. It prints the number of the new
20658current thread, and the topmost frame for that thread.
20659
20660@subsubheading @value{GDBN} Command
20661
20662The corresponding @value{GDBN} command is @samp{thread}.
20663
20664@subsubheading Example
20665
20666@smallexample
20667(@value{GDBP})
20668-exec-next
20669^running
20670(@value{GDBP})
20671*stopped,reason="end-stepping-range",thread-id="2",line="187",
20672file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
20673(@value{GDBP})
20674-thread-list-ids
20675^done,
20676thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20677number-of-threads="3"
20678(@value{GDBP})
20679-thread-select 3
20680^done,new-thread-id="3",
20681frame=@{level="0",func="vprintf",
20682args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
20683@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
20684(@value{GDBP})
20685@end smallexample
20686
20687@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20688@node GDB/MI Tracepoint Commands
20689@section @sc{gdb/mi} Tracepoint Commands
20690
20691The tracepoint commands are not yet implemented.
20692
20693@c @subheading -trace-actions
20694
20695@c @subheading -trace-delete
20696
20697@c @subheading -trace-disable
20698
20699@c @subheading -trace-dump
20700
20701@c @subheading -trace-enable
20702
20703@c @subheading -trace-exists
20704
20705@c @subheading -trace-find
20706
20707@c @subheading -trace-frame-number
20708
20709@c @subheading -trace-info
20710
20711@c @subheading -trace-insert
20712
20713@c @subheading -trace-list
20714
20715@c @subheading -trace-pass-count
20716
20717@c @subheading -trace-save
20718
20719@c @subheading -trace-start
20720
20721@c @subheading -trace-stop
20722
20723
20724@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20725@node GDB/MI Variable Objects
20726@section @sc{gdb/mi} Variable Objects
20727
20728
20729@subheading Motivation for Variable Objects in @sc{gdb/mi}
20730
20731For the implementation of a variable debugger window (locals, watched
20732expressions, etc.), we are proposing the adaptation of the existing code
20733used by @code{Insight}.
20734
20735The two main reasons for that are:
20736
20737@enumerate 1
20738@item
20739It has been proven in practice (it is already on its second generation).
20740
20741@item
20742It will shorten development time (needless to say how important it is
20743now).
20744@end enumerate
20745
20746The original interface was designed to be used by Tcl code, so it was
20747slightly changed so it could be used through @sc{gdb/mi}. This section
20748describes the @sc{gdb/mi} operations that will be available and gives some
20749hints about their use.
20750
20751@emph{Note}: In addition to the set of operations described here, we
20752expect the @sc{gui} implementation of a variable window to require, at
20753least, the following operations:
20754
20755@itemize @bullet
20756@item @code{-gdb-show} @code{output-radix}
20757@item @code{-stack-list-arguments}
20758@item @code{-stack-list-locals}
20759@item @code{-stack-select-frame}
20760@end itemize
20761
20762@subheading Introduction to Variable Objects in @sc{gdb/mi}
20763
20764@cindex variable objects in @sc{gdb/mi}
20765The basic idea behind variable objects is the creation of a named object
20766to represent a variable, an expression, a memory location or even a CPU
20767register. For each object created, a set of operations is available for
20768examining or changing its properties.
20769
20770Furthermore, complex data types, such as C structures, are represented
20771in a tree format. For instance, the @code{struct} type variable is the
20772root and the children will represent the struct members. If a child
20773is itself of a complex type, it will also have children of its own.
20774Appropriate language differences are handled for C, C@t{++} and Java.
20775
20776When returning the actual values of the objects, this facility allows
20777for the individual selection of the display format used in the result
20778creation. It can be chosen among: binary, decimal, hexadecimal, octal
20779and natural. Natural refers to a default format automatically
20780chosen based on the variable type (like decimal for an @code{int}, hex
20781for pointers, etc.).
20782
20783The following is the complete set of @sc{gdb/mi} operations defined to
20784access this functionality:
20785
20786@multitable @columnfractions .4 .6
20787@item @strong{Operation}
20788@tab @strong{Description}
20789
20790@item @code{-var-create}
20791@tab create a variable object
20792@item @code{-var-delete}
20793@tab delete the variable object and its children
20794@item @code{-var-set-format}
20795@tab set the display format of this variable
20796@item @code{-var-show-format}
20797@tab show the display format of this variable
20798@item @code{-var-info-num-children}
20799@tab tells how many children this object has
20800@item @code{-var-list-children}
20801@tab return a list of the object's children
20802@item @code{-var-info-type}
20803@tab show the type of this variable object
20804@item @code{-var-info-expression}
20805@tab print what this variable object represents
20806@item @code{-var-show-attributes}
20807@tab is this variable editable? does it exist here?
20808@item @code{-var-evaluate-expression}
20809@tab get the value of this variable
20810@item @code{-var-assign}
20811@tab set the value of this variable
20812@item @code{-var-update}
20813@tab update the variable and its children
20814@end multitable
20815
20816In the next subsection we describe each operation in detail and suggest
20817how it can be used.
20818
20819@subheading Description And Use of Operations on Variable Objects
20820
20821@subheading The @code{-var-create} Command
20822@findex -var-create
20823
20824@subsubheading Synopsis
20825
20826@smallexample
20827 -var-create @{@var{name} | "-"@}
20828 @{@var{frame-addr} | "*"@} @var{expression}
20829@end smallexample
20830
20831This operation creates a variable object, which allows the monitoring of
20832a variable, the result of an expression, a memory cell or a CPU
20833register.
20834
20835The @var{name} parameter is the string by which the object can be
20836referenced. It must be unique. If @samp{-} is specified, the varobj
20837system will generate a string ``varNNNNNN'' automatically. It will be
20838unique provided that one does not specify @var{name} on that format.
20839The command fails if a duplicate name is found.
20840
20841The frame under which the expression should be evaluated can be
20842specified by @var{frame-addr}. A @samp{*} indicates that the current
20843frame should be used.
20844
20845@var{expression} is any expression valid on the current language set (must not
20846begin with a @samp{*}), or one of the following:
20847
20848@itemize @bullet
20849@item
20850@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
20851
20852@item
20853@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
20854
20855@item
20856@samp{$@var{regname}} --- a CPU register name
20857@end itemize
20858
20859@subsubheading Result
20860
20861This operation returns the name, number of children and the type of the
20862object created. Type is returned as a string as the ones generated by
20863the @value{GDBN} CLI:
20864
20865@smallexample
20866 name="@var{name}",numchild="N",type="@var{type}"
20867@end smallexample
20868
20869
20870@subheading The @code{-var-delete} Command
20871@findex -var-delete
20872
20873@subsubheading Synopsis
20874
20875@smallexample
20876 -var-delete @var{name}
20877@end smallexample
20878
20879Deletes a previously created variable object and all of its children.
20880
20881Returns an error if the object @var{name} is not found.
20882
20883
20884@subheading The @code{-var-set-format} Command
20885@findex -var-set-format
20886
20887@subsubheading Synopsis
20888
20889@smallexample
20890 -var-set-format @var{name} @var{format-spec}
20891@end smallexample
20892
20893Sets the output format for the value of the object @var{name} to be
20894@var{format-spec}.
20895
20896The syntax for the @var{format-spec} is as follows:
20897
20898@smallexample
20899 @var{format-spec} @expansion{}
20900 @{binary | decimal | hexadecimal | octal | natural@}
20901@end smallexample
20902
20903
20904@subheading The @code{-var-show-format} Command
20905@findex -var-show-format
20906
20907@subsubheading Synopsis
20908
20909@smallexample
20910 -var-show-format @var{name}
20911@end smallexample
20912
20913Returns the format used to display the value of the object @var{name}.
20914
20915@smallexample
20916 @var{format} @expansion{}
20917 @var{format-spec}
20918@end smallexample
20919
20920
20921@subheading The @code{-var-info-num-children} Command
20922@findex -var-info-num-children
20923
20924@subsubheading Synopsis
20925
20926@smallexample
20927 -var-info-num-children @var{name}
20928@end smallexample
20929
20930Returns the number of children of a variable object @var{name}:
20931
20932@smallexample
20933 numchild=@var{n}
20934@end smallexample
20935
20936
20937@subheading The @code{-var-list-children} Command
20938@findex -var-list-children
20939
20940@subsubheading Synopsis
20941
20942@smallexample
bc8ced35 20943 -var-list-children [@var{print-values}] @var{name}
922fbb7b 20944@end smallexample
265eeb58 20945@anchor{-var-list-children}
922fbb7b 20946
265eeb58
NR
20947Return a list of the children of the specified variable object and
20948create variable objects for them, if they do not already exist. With
20949a single argument or if @var{print-values} has a value for of 0 or
20950@code{--no-values}, print only the names of the variables; if
20951@var{print-values} is 1 or @code{--all-values}, also print their
20952values; and if it is 2 or @code{--simple-values} print the name and
20953value for simple data types and just the name for arrays, structures
20954and unions.
bc8ced35
NR
20955
20956@subsubheading Example
922fbb7b
AC
20957
20958@smallexample
bc8ced35
NR
20959(@value{GDBP})
20960 -var-list-children n
265eeb58 20961 ^done,numchild=@var{n},children=[@{name=@var{name},
922fbb7b 20962 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
bc8ced35
NR
20963(@value{GDBP})
20964 -var-list-children --all-values n
265eeb58 20965 ^done,numchild=@var{n},children=[@{name=@var{name},
bc8ced35 20966 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
20967@end smallexample
20968
20969
20970@subheading The @code{-var-info-type} Command
20971@findex -var-info-type
20972
20973@subsubheading Synopsis
20974
20975@smallexample
20976 -var-info-type @var{name}
20977@end smallexample
20978
20979Returns the type of the specified variable @var{name}. The type is
20980returned as a string in the same format as it is output by the
20981@value{GDBN} CLI:
20982
20983@smallexample
20984 type=@var{typename}
20985@end smallexample
20986
20987
20988@subheading The @code{-var-info-expression} Command
20989@findex -var-info-expression
20990
20991@subsubheading Synopsis
20992
20993@smallexample
20994 -var-info-expression @var{name}
20995@end smallexample
20996
20997Returns what is represented by the variable object @var{name}:
20998
20999@smallexample
21000 lang=@var{lang-spec},exp=@var{expression}
21001@end smallexample
21002
21003@noindent
21004where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
21005
21006@subheading The @code{-var-show-attributes} Command
21007@findex -var-show-attributes
21008
21009@subsubheading Synopsis
21010
21011@smallexample
21012 -var-show-attributes @var{name}
21013@end smallexample
21014
21015List attributes of the specified variable object @var{name}:
21016
21017@smallexample
21018 status=@var{attr} [ ( ,@var{attr} )* ]
21019@end smallexample
21020
21021@noindent
21022where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
21023
21024@subheading The @code{-var-evaluate-expression} Command
21025@findex -var-evaluate-expression
21026
21027@subsubheading Synopsis
21028
21029@smallexample
21030 -var-evaluate-expression @var{name}
21031@end smallexample
21032
21033Evaluates the expression that is represented by the specified variable
21034object and returns its value as a string in the current format specified
21035for the object:
21036
21037@smallexample
21038 value=@var{value}
21039@end smallexample
21040
21041Note that one must invoke @code{-var-list-children} for a variable
21042before the value of a child variable can be evaluated.
21043
21044@subheading The @code{-var-assign} Command
21045@findex -var-assign
21046
21047@subsubheading Synopsis
21048
21049@smallexample
21050 -var-assign @var{name} @var{expression}
21051@end smallexample
21052
21053Assigns the value of @var{expression} to the variable object specified
21054by @var{name}. The object must be @samp{editable}. If the variable's
b383017d 21055value is altered by the assign, the variable will show up in any
922fbb7b
AC
21056subsequent @code{-var-update} list.
21057
21058@subsubheading Example
21059
21060@smallexample
21061(@value{GDBP})
21062-var-assign var1 3
21063^done,value="3"
21064(@value{GDBP})
21065-var-update *
21066^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
21067(@value{GDBP})
21068@end smallexample
21069
21070@subheading The @code{-var-update} Command
21071@findex -var-update
21072
21073@subsubheading Synopsis
21074
21075@smallexample
265eeb58 21076 -var-update [@var{print-values}] @{@var{name} | "*"@}
922fbb7b
AC
21077@end smallexample
21078
21079Update the value of the variable object @var{name} by evaluating its
21080expression after fetching all the new values from memory or registers.
265eeb58 21081A @samp{*} causes all existing variable objects to be updated. The
656d5e12
EZ
21082option @var{print-values} determines whether names both and values, or
21083just names are printed in the manner described for
21084@code{-var-list-children} (@pxref{-var-list-children}).
265eeb58
NR
21085
21086@subsubheading Example
922fbb7b 21087
265eeb58
NR
21088@smallexample
21089(@value{GDBP})
21090-var-assign var1 3
21091^done,value="3"
21092(@value{GDBP})
21093-var-update --all-values var1
21094^done,changelist=[@{name="var1",value="3",in_scope="true",
21095type_changed="false"@}]
21096(@value{GDBP})
21097@end smallexample
922fbb7b
AC
21098
21099@node Annotations
21100@chapter @value{GDBN} Annotations
21101
086432e2
AC
21102This chapter describes annotations in @value{GDBN}. Annotations were
21103designed to interface @value{GDBN} to graphical user interfaces or other
21104similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
21105relatively high level.
21106
086432e2
AC
21107The annotation mechanism has largely been superseeded by @sc{gdb/mi}
21108(@pxref{GDB/MI}).
21109
922fbb7b
AC
21110@ignore
21111This is Edition @value{EDITION}, @value{DATE}.
21112@end ignore
21113
21114@menu
21115* Annotations Overview:: What annotations are; the general syntax.
922fbb7b
AC
21116* Prompting:: Annotations marking @value{GDBN}'s need for input.
21117* Errors:: Annotations for error messages.
922fbb7b
AC
21118* Invalidation:: Some annotations describe things now invalid.
21119* Annotations for Running::
21120 Whether the program is running, how it stopped, etc.
21121* Source Annotations:: Annotations describing source code.
922fbb7b
AC
21122@end menu
21123
21124@node Annotations Overview
21125@section What is an Annotation?
21126@cindex annotations
21127
922fbb7b
AC
21128Annotations start with a newline character, two @samp{control-z}
21129characters, and the name of the annotation. If there is no additional
21130information associated with this annotation, the name of the annotation
21131is followed immediately by a newline. If there is additional
21132information, the name of the annotation is followed by a space, the
21133additional information, and a newline. The additional information
21134cannot contain newline characters.
21135
21136Any output not beginning with a newline and two @samp{control-z}
21137characters denotes literal output from @value{GDBN}. Currently there is
21138no need for @value{GDBN} to output a newline followed by two
21139@samp{control-z} characters, but if there was such a need, the
21140annotations could be extended with an @samp{escape} annotation which
21141means those three characters as output.
21142
086432e2
AC
21143The annotation @var{level}, which is specified using the
21144@option{--annotate} command line option (@pxref{Mode Options}), controls
21145how much information @value{GDBN} prints together with its prompt,
21146values of expressions, source lines, and other types of output. Level 0
21147is for no anntations, level 1 is for use when @value{GDBN} is run as a
21148subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
21149for programs that control @value{GDBN}, and level 2 annotations have
21150been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
21151Interface, annotate, GDB's Obsolete Annotations}).
21152
21153@table @code
21154@kindex set annotate
21155@item set annotate @var{level}
e09f16f9 21156The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 21157annotations to the specified @var{level}.
9c16f35a
EZ
21158
21159@item show annotate
21160@kindex show annotate
21161Show the current annotation level.
09d4efe1
EZ
21162@end table
21163
21164This chapter describes level 3 annotations.
086432e2 21165
922fbb7b
AC
21166A simple example of starting up @value{GDBN} with annotations is:
21167
21168@smallexample
086432e2
AC
21169$ @kbd{gdb --annotate=3}
21170GNU gdb 6.0
21171Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
21172GDB is free software, covered by the GNU General Public License,
21173and you are welcome to change it and/or distribute copies of it
21174under certain conditions.
21175Type "show copying" to see the conditions.
21176There is absolutely no warranty for GDB. Type "show warranty"
21177for details.
086432e2 21178This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
21179
21180^Z^Zpre-prompt
f7dc1244 21181(@value{GDBP})
922fbb7b 21182^Z^Zprompt
086432e2 21183@kbd{quit}
922fbb7b
AC
21184
21185^Z^Zpost-prompt
b383017d 21186$
922fbb7b
AC
21187@end smallexample
21188
21189Here @samp{quit} is input to @value{GDBN}; the rest is output from
21190@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
21191denotes a @samp{control-z} character) are annotations; the rest is
21192output from @value{GDBN}.
21193
922fbb7b
AC
21194@node Prompting
21195@section Annotation for @value{GDBN} Input
21196
21197@cindex annotations for prompts
21198When @value{GDBN} prompts for input, it annotates this fact so it is possible
21199to know when to send output, when the output from a given command is
21200over, etc.
21201
21202Different kinds of input each have a different @dfn{input type}. Each
21203input type has three annotations: a @code{pre-} annotation, which
21204denotes the beginning of any prompt which is being output, a plain
21205annotation, which denotes the end of the prompt, and then a @code{post-}
21206annotation which denotes the end of any echo which may (or may not) be
21207associated with the input. For example, the @code{prompt} input type
21208features the following annotations:
21209
21210@smallexample
21211^Z^Zpre-prompt
21212^Z^Zprompt
21213^Z^Zpost-prompt
21214@end smallexample
21215
21216The input types are
21217
21218@table @code
21219@findex pre-prompt
21220@findex prompt
21221@findex post-prompt
21222@item prompt
21223When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
21224
21225@findex pre-commands
21226@findex commands
21227@findex post-commands
21228@item commands
21229When @value{GDBN} prompts for a set of commands, like in the @code{commands}
21230command. The annotations are repeated for each command which is input.
21231
21232@findex pre-overload-choice
21233@findex overload-choice
21234@findex post-overload-choice
21235@item overload-choice
21236When @value{GDBN} wants the user to select between various overloaded functions.
21237
21238@findex pre-query
21239@findex query
21240@findex post-query
21241@item query
21242When @value{GDBN} wants the user to confirm a potentially dangerous operation.
21243
21244@findex pre-prompt-for-continue
21245@findex prompt-for-continue
21246@findex post-prompt-for-continue
21247@item prompt-for-continue
21248When @value{GDBN} is asking the user to press return to continue. Note: Don't
21249expect this to work well; instead use @code{set height 0} to disable
21250prompting. This is because the counting of lines is buggy in the
21251presence of annotations.
21252@end table
21253
21254@node Errors
21255@section Errors
21256@cindex annotations for errors, warnings and interrupts
21257
21258@findex quit
21259@smallexample
21260^Z^Zquit
21261@end smallexample
21262
21263This annotation occurs right before @value{GDBN} responds to an interrupt.
21264
21265@findex error
21266@smallexample
21267^Z^Zerror
21268@end smallexample
21269
21270This annotation occurs right before @value{GDBN} responds to an error.
21271
21272Quit and error annotations indicate that any annotations which @value{GDBN} was
21273in the middle of may end abruptly. For example, if a
21274@code{value-history-begin} annotation is followed by a @code{error}, one
21275cannot expect to receive the matching @code{value-history-end}. One
21276cannot expect not to receive it either, however; an error annotation
21277does not necessarily mean that @value{GDBN} is immediately returning all the way
21278to the top level.
21279
21280@findex error-begin
21281A quit or error annotation may be preceded by
21282
21283@smallexample
21284^Z^Zerror-begin
21285@end smallexample
21286
21287Any output between that and the quit or error annotation is the error
21288message.
21289
21290Warning messages are not yet annotated.
21291@c If we want to change that, need to fix warning(), type_error(),
21292@c range_error(), and possibly other places.
21293
922fbb7b
AC
21294@node Invalidation
21295@section Invalidation Notices
21296
21297@cindex annotations for invalidation messages
21298The following annotations say that certain pieces of state may have
21299changed.
21300
21301@table @code
21302@findex frames-invalid
21303@item ^Z^Zframes-invalid
21304
21305The frames (for example, output from the @code{backtrace} command) may
21306have changed.
21307
21308@findex breakpoints-invalid
21309@item ^Z^Zbreakpoints-invalid
21310
21311The breakpoints may have changed. For example, the user just added or
21312deleted a breakpoint.
21313@end table
21314
21315@node Annotations for Running
21316@section Running the Program
21317@cindex annotations for running programs
21318
21319@findex starting
21320@findex stopping
21321When the program starts executing due to a @value{GDBN} command such as
b383017d 21322@code{step} or @code{continue},
922fbb7b
AC
21323
21324@smallexample
21325^Z^Zstarting
21326@end smallexample
21327
b383017d 21328is output. When the program stops,
922fbb7b
AC
21329
21330@smallexample
21331^Z^Zstopped
21332@end smallexample
21333
21334is output. Before the @code{stopped} annotation, a variety of
21335annotations describe how the program stopped.
21336
21337@table @code
21338@findex exited
21339@item ^Z^Zexited @var{exit-status}
21340The program exited, and @var{exit-status} is the exit status (zero for
21341successful exit, otherwise nonzero).
21342
21343@findex signalled
21344@findex signal-name
21345@findex signal-name-end
21346@findex signal-string
21347@findex signal-string-end
21348@item ^Z^Zsignalled
21349The program exited with a signal. After the @code{^Z^Zsignalled}, the
21350annotation continues:
21351
21352@smallexample
21353@var{intro-text}
21354^Z^Zsignal-name
21355@var{name}
21356^Z^Zsignal-name-end
21357@var{middle-text}
21358^Z^Zsignal-string
21359@var{string}
21360^Z^Zsignal-string-end
21361@var{end-text}
21362@end smallexample
21363
21364@noindent
21365where @var{name} is the name of the signal, such as @code{SIGILL} or
21366@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
21367as @code{Illegal Instruction} or @code{Segmentation fault}.
21368@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
21369user's benefit and have no particular format.
21370
21371@findex signal
21372@item ^Z^Zsignal
21373The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
21374just saying that the program received the signal, not that it was
21375terminated with it.
21376
21377@findex breakpoint
21378@item ^Z^Zbreakpoint @var{number}
21379The program hit breakpoint number @var{number}.
21380
21381@findex watchpoint
21382@item ^Z^Zwatchpoint @var{number}
21383The program hit watchpoint number @var{number}.
21384@end table
21385
21386@node Source Annotations
21387@section Displaying Source
21388@cindex annotations for source display
21389
21390@findex source
21391The following annotation is used instead of displaying source code:
21392
21393@smallexample
21394^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
21395@end smallexample
21396
21397where @var{filename} is an absolute file name indicating which source
21398file, @var{line} is the line number within that file (where 1 is the
21399first line in the file), @var{character} is the character position
21400within the file (where 0 is the first character in the file) (for most
21401debug formats this will necessarily point to the beginning of a line),
21402@var{middle} is @samp{middle} if @var{addr} is in the middle of the
21403line, or @samp{beg} if @var{addr} is at the beginning of the line, and
21404@var{addr} is the address in the target program associated with the
21405source which is being displayed. @var{addr} is in the form @samp{0x}
21406followed by one or more lowercase hex digits (note that this does not
21407depend on the language).
21408
8e04817f
AC
21409@node GDB Bugs
21410@chapter Reporting Bugs in @value{GDBN}
21411@cindex bugs in @value{GDBN}
21412@cindex reporting bugs in @value{GDBN}
c906108c 21413
8e04817f 21414Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 21415
8e04817f
AC
21416Reporting a bug may help you by bringing a solution to your problem, or it
21417may not. But in any case the principal function of a bug report is to help
21418the entire community by making the next version of @value{GDBN} work better. Bug
21419reports are your contribution to the maintenance of @value{GDBN}.
c906108c 21420
8e04817f
AC
21421In order for a bug report to serve its purpose, you must include the
21422information that enables us to fix the bug.
c4555f82
SC
21423
21424@menu
8e04817f
AC
21425* Bug Criteria:: Have you found a bug?
21426* Bug Reporting:: How to report bugs
c4555f82
SC
21427@end menu
21428
8e04817f
AC
21429@node Bug Criteria
21430@section Have you found a bug?
21431@cindex bug criteria
c4555f82 21432
8e04817f 21433If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
21434
21435@itemize @bullet
8e04817f
AC
21436@cindex fatal signal
21437@cindex debugger crash
21438@cindex crash of debugger
c4555f82 21439@item
8e04817f
AC
21440If the debugger gets a fatal signal, for any input whatever, that is a
21441@value{GDBN} bug. Reliable debuggers never crash.
21442
21443@cindex error on valid input
21444@item
21445If @value{GDBN} produces an error message for valid input, that is a
21446bug. (Note that if you're cross debugging, the problem may also be
21447somewhere in the connection to the target.)
c4555f82 21448
8e04817f 21449@cindex invalid input
c4555f82 21450@item
8e04817f
AC
21451If @value{GDBN} does not produce an error message for invalid input,
21452that is a bug. However, you should note that your idea of
21453``invalid input'' might be our idea of ``an extension'' or ``support
21454for traditional practice''.
21455
21456@item
21457If you are an experienced user of debugging tools, your suggestions
21458for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
21459@end itemize
21460
8e04817f
AC
21461@node Bug Reporting
21462@section How to report bugs
21463@cindex bug reports
21464@cindex @value{GDBN} bugs, reporting
21465
21466A number of companies and individuals offer support for @sc{gnu} products.
21467If you obtained @value{GDBN} from a support organization, we recommend you
21468contact that organization first.
21469
21470You can find contact information for many support companies and
21471individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
21472distribution.
21473@c should add a web page ref...
21474
129188f6
AC
21475In any event, we also recommend that you submit bug reports for
21476@value{GDBN}. The prefered method is to submit them directly using
21477@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
21478page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
21479be used.
8e04817f
AC
21480
21481@strong{Do not send bug reports to @samp{info-gdb}, or to
21482@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
21483not want to receive bug reports. Those that do have arranged to receive
21484@samp{bug-gdb}.
21485
21486The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
21487serves as a repeater. The mailing list and the newsgroup carry exactly
21488the same messages. Often people think of posting bug reports to the
21489newsgroup instead of mailing them. This appears to work, but it has one
21490problem which can be crucial: a newsgroup posting often lacks a mail
21491path back to the sender. Thus, if we need to ask for more information,
21492we may be unable to reach you. For this reason, it is better to send
21493bug reports to the mailing list.
c4555f82 21494
8e04817f
AC
21495The fundamental principle of reporting bugs usefully is this:
21496@strong{report all the facts}. If you are not sure whether to state a
21497fact or leave it out, state it!
c4555f82 21498
8e04817f
AC
21499Often people omit facts because they think they know what causes the
21500problem and assume that some details do not matter. Thus, you might
21501assume that the name of the variable you use in an example does not matter.
21502Well, probably it does not, but one cannot be sure. Perhaps the bug is a
21503stray memory reference which happens to fetch from the location where that
21504name is stored in memory; perhaps, if the name were different, the contents
21505of that location would fool the debugger into doing the right thing despite
21506the bug. Play it safe and give a specific, complete example. That is the
21507easiest thing for you to do, and the most helpful.
c4555f82 21508
8e04817f
AC
21509Keep in mind that the purpose of a bug report is to enable us to fix the
21510bug. It may be that the bug has been reported previously, but neither
21511you nor we can know that unless your bug report is complete and
21512self-contained.
c4555f82 21513
8e04817f
AC
21514Sometimes people give a few sketchy facts and ask, ``Does this ring a
21515bell?'' Those bug reports are useless, and we urge everyone to
21516@emph{refuse to respond to them} except to chide the sender to report
21517bugs properly.
21518
21519To enable us to fix the bug, you should include all these things:
c4555f82
SC
21520
21521@itemize @bullet
21522@item
8e04817f
AC
21523The version of @value{GDBN}. @value{GDBN} announces it if you start
21524with no arguments; you can also print it at any time using @code{show
21525version}.
c4555f82 21526
8e04817f
AC
21527Without this, we will not know whether there is any point in looking for
21528the bug in the current version of @value{GDBN}.
c4555f82
SC
21529
21530@item
8e04817f
AC
21531The type of machine you are using, and the operating system name and
21532version number.
c4555f82
SC
21533
21534@item
c1468174 21535What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 21536``@value{GCC}--2.8.1''.
c4555f82
SC
21537
21538@item
8e04817f 21539What compiler (and its version) was used to compile the program you are
c1468174 21540debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
8e04817f
AC
21541C Compiler''. For GCC, you can say @code{gcc --version} to get this
21542information; for other compilers, see the documentation for those
21543compilers.
c4555f82 21544
8e04817f
AC
21545@item
21546The command arguments you gave the compiler to compile your example and
21547observe the bug. For example, did you use @samp{-O}? To guarantee
21548you will not omit something important, list them all. A copy of the
21549Makefile (or the output from make) is sufficient.
c4555f82 21550
8e04817f
AC
21551If we were to try to guess the arguments, we would probably guess wrong
21552and then we might not encounter the bug.
c4555f82 21553
8e04817f
AC
21554@item
21555A complete input script, and all necessary source files, that will
21556reproduce the bug.
c4555f82 21557
8e04817f
AC
21558@item
21559A description of what behavior you observe that you believe is
21560incorrect. For example, ``It gets a fatal signal.''
c4555f82 21561
8e04817f
AC
21562Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
21563will certainly notice it. But if the bug is incorrect output, we might
21564not notice unless it is glaringly wrong. You might as well not give us
21565a chance to make a mistake.
c4555f82 21566
8e04817f
AC
21567Even if the problem you experience is a fatal signal, you should still
21568say so explicitly. Suppose something strange is going on, such as, your
21569copy of @value{GDBN} is out of synch, or you have encountered a bug in
21570the C library on your system. (This has happened!) Your copy might
21571crash and ours would not. If you told us to expect a crash, then when
21572ours fails to crash, we would know that the bug was not happening for
21573us. If you had not told us to expect a crash, then we would not be able
21574to draw any conclusion from our observations.
c4555f82 21575
e0c07bf0
MC
21576@pindex script
21577@cindex recording a session script
21578To collect all this information, you can use a session recording program
21579such as @command{script}, which is available on many Unix systems.
21580Just run your @value{GDBN} session inside @command{script} and then
21581include the @file{typescript} file with your bug report.
21582
21583Another way to record a @value{GDBN} session is to run @value{GDBN}
21584inside Emacs and then save the entire buffer to a file.
21585
8e04817f
AC
21586@item
21587If you wish to suggest changes to the @value{GDBN} source, send us context
21588diffs. If you even discuss something in the @value{GDBN} source, refer to
21589it by context, not by line number.
c4555f82 21590
8e04817f
AC
21591The line numbers in our development sources will not match those in your
21592sources. Your line numbers would convey no useful information to us.
c4555f82 21593
8e04817f 21594@end itemize
c4555f82 21595
8e04817f 21596Here are some things that are not necessary:
c4555f82 21597
8e04817f
AC
21598@itemize @bullet
21599@item
21600A description of the envelope of the bug.
c4555f82 21601
8e04817f
AC
21602Often people who encounter a bug spend a lot of time investigating
21603which changes to the input file will make the bug go away and which
21604changes will not affect it.
c4555f82 21605
8e04817f
AC
21606This is often time consuming and not very useful, because the way we
21607will find the bug is by running a single example under the debugger
21608with breakpoints, not by pure deduction from a series of examples.
21609We recommend that you save your time for something else.
c4555f82 21610
8e04817f
AC
21611Of course, if you can find a simpler example to report @emph{instead}
21612of the original one, that is a convenience for us. Errors in the
21613output will be easier to spot, running under the debugger will take
21614less time, and so on.
c4555f82 21615
8e04817f
AC
21616However, simplification is not vital; if you do not want to do this,
21617report the bug anyway and send us the entire test case you used.
c4555f82 21618
8e04817f
AC
21619@item
21620A patch for the bug.
c4555f82 21621
8e04817f
AC
21622A patch for the bug does help us if it is a good one. But do not omit
21623the necessary information, such as the test case, on the assumption that
21624a patch is all we need. We might see problems with your patch and decide
21625to fix the problem another way, or we might not understand it at all.
c4555f82 21626
8e04817f
AC
21627Sometimes with a program as complicated as @value{GDBN} it is very hard to
21628construct an example that will make the program follow a certain path
21629through the code. If you do not send us the example, we will not be able
21630to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 21631
8e04817f
AC
21632And if we cannot understand what bug you are trying to fix, or why your
21633patch should be an improvement, we will not install it. A test case will
21634help us to understand.
c4555f82 21635
8e04817f
AC
21636@item
21637A guess about what the bug is or what it depends on.
c4555f82 21638
8e04817f
AC
21639Such guesses are usually wrong. Even we cannot guess right about such
21640things without first using the debugger to find the facts.
21641@end itemize
c4555f82 21642
8e04817f
AC
21643@c The readline documentation is distributed with the readline code
21644@c and consists of the two following files:
21645@c rluser.texinfo
21646@c inc-hist.texinfo
21647@c Use -I with makeinfo to point to the appropriate directory,
21648@c environment var TEXINPUTS with TeX.
21649@include rluser.texinfo
21650@include inc-hist.texinfo
c4555f82 21651
c4555f82 21652
8e04817f
AC
21653@node Formatting Documentation
21654@appendix Formatting Documentation
c4555f82 21655
8e04817f
AC
21656@cindex @value{GDBN} reference card
21657@cindex reference card
21658The @value{GDBN} 4 release includes an already-formatted reference card, ready
21659for printing with PostScript or Ghostscript, in the @file{gdb}
21660subdirectory of the main source directory@footnote{In
21661@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
21662release.}. If you can use PostScript or Ghostscript with your printer,
21663you can print the reference card immediately with @file{refcard.ps}.
c4555f82 21664
8e04817f
AC
21665The release also includes the source for the reference card. You
21666can format it, using @TeX{}, by typing:
c4555f82 21667
474c8240 21668@smallexample
8e04817f 21669make refcard.dvi
474c8240 21670@end smallexample
c4555f82 21671
8e04817f
AC
21672The @value{GDBN} reference card is designed to print in @dfn{landscape}
21673mode on US ``letter'' size paper;
21674that is, on a sheet 11 inches wide by 8.5 inches
21675high. You will need to specify this form of printing as an option to
21676your @sc{dvi} output program.
c4555f82 21677
8e04817f 21678@cindex documentation
c4555f82 21679
8e04817f
AC
21680All the documentation for @value{GDBN} comes as part of the machine-readable
21681distribution. The documentation is written in Texinfo format, which is
21682a documentation system that uses a single source file to produce both
21683on-line information and a printed manual. You can use one of the Info
21684formatting commands to create the on-line version of the documentation
21685and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 21686
8e04817f
AC
21687@value{GDBN} includes an already formatted copy of the on-line Info
21688version of this manual in the @file{gdb} subdirectory. The main Info
21689file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
21690subordinate files matching @samp{gdb.info*} in the same directory. If
21691necessary, you can print out these files, or read them with any editor;
21692but they are easier to read using the @code{info} subsystem in @sc{gnu}
21693Emacs or the standalone @code{info} program, available as part of the
21694@sc{gnu} Texinfo distribution.
c4555f82 21695
8e04817f
AC
21696If you want to format these Info files yourself, you need one of the
21697Info formatting programs, such as @code{texinfo-format-buffer} or
21698@code{makeinfo}.
c4555f82 21699
8e04817f
AC
21700If you have @code{makeinfo} installed, and are in the top level
21701@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
21702version @value{GDBVN}), you can make the Info file by typing:
c4555f82 21703
474c8240 21704@smallexample
8e04817f
AC
21705cd gdb
21706make gdb.info
474c8240 21707@end smallexample
c4555f82 21708
8e04817f
AC
21709If you want to typeset and print copies of this manual, you need @TeX{},
21710a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
21711Texinfo definitions file.
c4555f82 21712
8e04817f
AC
21713@TeX{} is a typesetting program; it does not print files directly, but
21714produces output files called @sc{dvi} files. To print a typeset
21715document, you need a program to print @sc{dvi} files. If your system
21716has @TeX{} installed, chances are it has such a program. The precise
21717command to use depends on your system; @kbd{lpr -d} is common; another
21718(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
21719require a file name without any extension or a @samp{.dvi} extension.
c4555f82 21720
8e04817f
AC
21721@TeX{} also requires a macro definitions file called
21722@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
21723written in Texinfo format. On its own, @TeX{} cannot either read or
21724typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
21725and is located in the @file{gdb-@var{version-number}/texinfo}
21726directory.
c4555f82 21727
8e04817f
AC
21728If you have @TeX{} and a @sc{dvi} printer program installed, you can
21729typeset and print this manual. First switch to the the @file{gdb}
21730subdirectory of the main source directory (for example, to
21731@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 21732
474c8240 21733@smallexample
8e04817f 21734make gdb.dvi
474c8240 21735@end smallexample
c4555f82 21736
8e04817f 21737Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 21738
8e04817f
AC
21739@node Installing GDB
21740@appendix Installing @value{GDBN}
21741@cindex configuring @value{GDBN}
21742@cindex installation
94e91d6d 21743@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 21744
8e04817f
AC
21745@value{GDBN} comes with a @code{configure} script that automates the process
21746of preparing @value{GDBN} for installation; you can then use @code{make} to
21747build the @code{gdb} program.
21748@iftex
21749@c irrelevant in info file; it's as current as the code it lives with.
21750@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
21751look at the @file{README} file in the sources; we may have improved the
21752installation procedures since publishing this manual.}
21753@end iftex
c4555f82 21754
8e04817f
AC
21755The @value{GDBN} distribution includes all the source code you need for
21756@value{GDBN} in a single directory, whose name is usually composed by
21757appending the version number to @samp{gdb}.
c4555f82 21758
8e04817f
AC
21759For example, the @value{GDBN} version @value{GDBVN} distribution is in the
21760@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 21761
8e04817f
AC
21762@table @code
21763@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
21764script for configuring @value{GDBN} and all its supporting libraries
c4555f82 21765
8e04817f
AC
21766@item gdb-@value{GDBVN}/gdb
21767the source specific to @value{GDBN} itself
c4555f82 21768
8e04817f
AC
21769@item gdb-@value{GDBVN}/bfd
21770source for the Binary File Descriptor library
c906108c 21771
8e04817f
AC
21772@item gdb-@value{GDBVN}/include
21773@sc{gnu} include files
c906108c 21774
8e04817f
AC
21775@item gdb-@value{GDBVN}/libiberty
21776source for the @samp{-liberty} free software library
c906108c 21777
8e04817f
AC
21778@item gdb-@value{GDBVN}/opcodes
21779source for the library of opcode tables and disassemblers
c906108c 21780
8e04817f
AC
21781@item gdb-@value{GDBVN}/readline
21782source for the @sc{gnu} command-line interface
c906108c 21783
8e04817f
AC
21784@item gdb-@value{GDBVN}/glob
21785source for the @sc{gnu} filename pattern-matching subroutine
c906108c 21786
8e04817f
AC
21787@item gdb-@value{GDBVN}/mmalloc
21788source for the @sc{gnu} memory-mapped malloc package
21789@end table
c906108c 21790
8e04817f
AC
21791The simplest way to configure and build @value{GDBN} is to run @code{configure}
21792from the @file{gdb-@var{version-number}} source directory, which in
21793this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 21794
8e04817f
AC
21795First switch to the @file{gdb-@var{version-number}} source directory
21796if you are not already in it; then run @code{configure}. Pass the
21797identifier for the platform on which @value{GDBN} will run as an
21798argument.
c906108c 21799
8e04817f 21800For example:
c906108c 21801
474c8240 21802@smallexample
8e04817f
AC
21803cd gdb-@value{GDBVN}
21804./configure @var{host}
21805make
474c8240 21806@end smallexample
c906108c 21807
8e04817f
AC
21808@noindent
21809where @var{host} is an identifier such as @samp{sun4} or
21810@samp{decstation}, that identifies the platform where @value{GDBN} will run.
21811(You can often leave off @var{host}; @code{configure} tries to guess the
21812correct value by examining your system.)
c906108c 21813
8e04817f
AC
21814Running @samp{configure @var{host}} and then running @code{make} builds the
21815@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
21816libraries, then @code{gdb} itself. The configured source files, and the
21817binaries, are left in the corresponding source directories.
c906108c 21818
8e04817f
AC
21819@need 750
21820@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
21821system does not recognize this automatically when you run a different
21822shell, you may need to run @code{sh} on it explicitly:
c906108c 21823
474c8240 21824@smallexample
8e04817f 21825sh configure @var{host}
474c8240 21826@end smallexample
c906108c 21827
8e04817f
AC
21828If you run @code{configure} from a directory that contains source
21829directories for multiple libraries or programs, such as the
21830@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
21831creates configuration files for every directory level underneath (unless
21832you tell it not to, with the @samp{--norecursion} option).
21833
94e91d6d
MC
21834You should run the @code{configure} script from the top directory in the
21835source tree, the @file{gdb-@var{version-number}} directory. If you run
21836@code{configure} from one of the subdirectories, you will configure only
21837that subdirectory. That is usually not what you want. In particular,
21838if you run the first @code{configure} from the @file{gdb} subdirectory
21839of the @file{gdb-@var{version-number}} directory, you will omit the
21840configuration of @file{bfd}, @file{readline}, and other sibling
21841directories of the @file{gdb} subdirectory. This leads to build errors
21842about missing include files such as @file{bfd/bfd.h}.
c906108c 21843
8e04817f
AC
21844You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
21845However, you should make sure that the shell on your path (named by
21846the @samp{SHELL} environment variable) is publicly readable. Remember
21847that @value{GDBN} uses the shell to start your program---some systems refuse to
21848let @value{GDBN} debug child processes whose programs are not readable.
c906108c 21849
8e04817f
AC
21850@menu
21851* Separate Objdir:: Compiling @value{GDBN} in another directory
21852* Config Names:: Specifying names for hosts and targets
21853* Configure Options:: Summary of options for configure
21854@end menu
c906108c 21855
8e04817f
AC
21856@node Separate Objdir
21857@section Compiling @value{GDBN} in another directory
c906108c 21858
8e04817f
AC
21859If you want to run @value{GDBN} versions for several host or target machines,
21860you need a different @code{gdb} compiled for each combination of
21861host and target. @code{configure} is designed to make this easy by
21862allowing you to generate each configuration in a separate subdirectory,
21863rather than in the source directory. If your @code{make} program
21864handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
21865@code{make} in each of these directories builds the @code{gdb}
21866program specified there.
c906108c 21867
8e04817f
AC
21868To build @code{gdb} in a separate directory, run @code{configure}
21869with the @samp{--srcdir} option to specify where to find the source.
21870(You also need to specify a path to find @code{configure}
21871itself from your working directory. If the path to @code{configure}
21872would be the same as the argument to @samp{--srcdir}, you can leave out
21873the @samp{--srcdir} option; it is assumed.)
c906108c 21874
8e04817f
AC
21875For example, with version @value{GDBVN}, you can build @value{GDBN} in a
21876separate directory for a Sun 4 like this:
c906108c 21877
474c8240 21878@smallexample
8e04817f
AC
21879@group
21880cd gdb-@value{GDBVN}
21881mkdir ../gdb-sun4
21882cd ../gdb-sun4
21883../gdb-@value{GDBVN}/configure sun4
21884make
21885@end group
474c8240 21886@end smallexample
c906108c 21887
8e04817f
AC
21888When @code{configure} builds a configuration using a remote source
21889directory, it creates a tree for the binaries with the same structure
21890(and using the same names) as the tree under the source directory. In
21891the example, you'd find the Sun 4 library @file{libiberty.a} in the
21892directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
21893@file{gdb-sun4/gdb}.
c906108c 21894
94e91d6d
MC
21895Make sure that your path to the @file{configure} script has just one
21896instance of @file{gdb} in it. If your path to @file{configure} looks
21897like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
21898one subdirectory of @value{GDBN}, not the whole package. This leads to
21899build errors about missing include files such as @file{bfd/bfd.h}.
21900
8e04817f
AC
21901One popular reason to build several @value{GDBN} configurations in separate
21902directories is to configure @value{GDBN} for cross-compiling (where
21903@value{GDBN} runs on one machine---the @dfn{host}---while debugging
21904programs that run on another machine---the @dfn{target}).
21905You specify a cross-debugging target by
21906giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 21907
8e04817f
AC
21908When you run @code{make} to build a program or library, you must run
21909it in a configured directory---whatever directory you were in when you
21910called @code{configure} (or one of its subdirectories).
c906108c 21911
8e04817f
AC
21912The @code{Makefile} that @code{configure} generates in each source
21913directory also runs recursively. If you type @code{make} in a source
21914directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
21915directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
21916will build all the required libraries, and then build GDB.
c906108c 21917
8e04817f
AC
21918When you have multiple hosts or targets configured in separate
21919directories, you can run @code{make} on them in parallel (for example,
21920if they are NFS-mounted on each of the hosts); they will not interfere
21921with each other.
c906108c 21922
8e04817f
AC
21923@node Config Names
21924@section Specifying names for hosts and targets
c906108c 21925
8e04817f
AC
21926The specifications used for hosts and targets in the @code{configure}
21927script are based on a three-part naming scheme, but some short predefined
21928aliases are also supported. The full naming scheme encodes three pieces
21929of information in the following pattern:
c906108c 21930
474c8240 21931@smallexample
8e04817f 21932@var{architecture}-@var{vendor}-@var{os}
474c8240 21933@end smallexample
c906108c 21934
8e04817f
AC
21935For example, you can use the alias @code{sun4} as a @var{host} argument,
21936or as the value for @var{target} in a @code{--target=@var{target}}
21937option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 21938
8e04817f
AC
21939The @code{configure} script accompanying @value{GDBN} does not provide
21940any query facility to list all supported host and target names or
21941aliases. @code{configure} calls the Bourne shell script
21942@code{config.sub} to map abbreviations to full names; you can read the
21943script, if you wish, or you can use it to test your guesses on
21944abbreviations---for example:
c906108c 21945
8e04817f
AC
21946@smallexample
21947% sh config.sub i386-linux
21948i386-pc-linux-gnu
21949% sh config.sub alpha-linux
21950alpha-unknown-linux-gnu
21951% sh config.sub hp9k700
21952hppa1.1-hp-hpux
21953% sh config.sub sun4
21954sparc-sun-sunos4.1.1
21955% sh config.sub sun3
21956m68k-sun-sunos4.1.1
21957% sh config.sub i986v
21958Invalid configuration `i986v': machine `i986v' not recognized
21959@end smallexample
c906108c 21960
8e04817f
AC
21961@noindent
21962@code{config.sub} is also distributed in the @value{GDBN} source
21963directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 21964
8e04817f
AC
21965@node Configure Options
21966@section @code{configure} options
c906108c 21967
8e04817f
AC
21968Here is a summary of the @code{configure} options and arguments that
21969are most often useful for building @value{GDBN}. @code{configure} also has
21970several other options not listed here. @inforef{What Configure
21971Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 21972
474c8240 21973@smallexample
8e04817f
AC
21974configure @r{[}--help@r{]}
21975 @r{[}--prefix=@var{dir}@r{]}
21976 @r{[}--exec-prefix=@var{dir}@r{]}
21977 @r{[}--srcdir=@var{dirname}@r{]}
21978 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
21979 @r{[}--target=@var{target}@r{]}
21980 @var{host}
474c8240 21981@end smallexample
c906108c 21982
8e04817f
AC
21983@noindent
21984You may introduce options with a single @samp{-} rather than
21985@samp{--} if you prefer; but you may abbreviate option names if you use
21986@samp{--}.
c906108c 21987
8e04817f
AC
21988@table @code
21989@item --help
21990Display a quick summary of how to invoke @code{configure}.
c906108c 21991
8e04817f
AC
21992@item --prefix=@var{dir}
21993Configure the source to install programs and files under directory
21994@file{@var{dir}}.
c906108c 21995
8e04817f
AC
21996@item --exec-prefix=@var{dir}
21997Configure the source to install programs under directory
21998@file{@var{dir}}.
c906108c 21999
8e04817f
AC
22000@c avoid splitting the warning from the explanation:
22001@need 2000
22002@item --srcdir=@var{dirname}
22003@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
22004@code{make} that implements the @code{VPATH} feature.}@*
22005Use this option to make configurations in directories separate from the
22006@value{GDBN} source directories. Among other things, you can use this to
22007build (or maintain) several configurations simultaneously, in separate
22008directories. @code{configure} writes configuration specific files in
22009the current directory, but arranges for them to use the source in the
22010directory @var{dirname}. @code{configure} creates directories under
22011the working directory in parallel to the source directories below
22012@var{dirname}.
c906108c 22013
8e04817f
AC
22014@item --norecursion
22015Configure only the directory level where @code{configure} is executed; do not
22016propagate configuration to subdirectories.
c906108c 22017
8e04817f
AC
22018@item --target=@var{target}
22019Configure @value{GDBN} for cross-debugging programs running on the specified
22020@var{target}. Without this option, @value{GDBN} is configured to debug
22021programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 22022
8e04817f 22023There is no convenient way to generate a list of all available targets.
c906108c 22024
8e04817f
AC
22025@item @var{host} @dots{}
22026Configure @value{GDBN} to run on the specified @var{host}.
c906108c 22027
8e04817f
AC
22028There is no convenient way to generate a list of all available hosts.
22029@end table
c906108c 22030
8e04817f
AC
22031There are many other options available as well, but they are generally
22032needed for special purposes only.
c906108c 22033
8e04817f
AC
22034@node Maintenance Commands
22035@appendix Maintenance Commands
22036@cindex maintenance commands
22037@cindex internal commands
c906108c 22038
8e04817f 22039In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
22040includes a number of commands intended for @value{GDBN} developers,
22041that are not documented elsewhere in this manual. These commands are
da316a69
EZ
22042provided here for reference. (For commands that turn on debugging
22043messages, see @ref{Debugging Output}.)
c906108c 22044
8e04817f 22045@table @code
09d4efe1
EZ
22046@kindex maint agent
22047@item maint agent @var{expression}
22048Translate the given @var{expression} into remote agent bytecodes.
22049This command is useful for debugging the Agent Expression mechanism
22050(@pxref{Agent Expressions}).
22051
8e04817f
AC
22052@kindex maint info breakpoints
22053@item @anchor{maint info breakpoints}maint info breakpoints
22054Using the same format as @samp{info breakpoints}, display both the
22055breakpoints you've set explicitly, and those @value{GDBN} is using for
22056internal purposes. Internal breakpoints are shown with negative
22057breakpoint numbers. The type column identifies what kind of breakpoint
22058is shown:
c906108c 22059
8e04817f
AC
22060@table @code
22061@item breakpoint
22062Normal, explicitly set breakpoint.
c906108c 22063
8e04817f
AC
22064@item watchpoint
22065Normal, explicitly set watchpoint.
c906108c 22066
8e04817f
AC
22067@item longjmp
22068Internal breakpoint, used to handle correctly stepping through
22069@code{longjmp} calls.
c906108c 22070
8e04817f
AC
22071@item longjmp resume
22072Internal breakpoint at the target of a @code{longjmp}.
c906108c 22073
8e04817f
AC
22074@item until
22075Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 22076
8e04817f
AC
22077@item finish
22078Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 22079
8e04817f
AC
22080@item shlib events
22081Shared library events.
c906108c 22082
8e04817f 22083@end table
c906108c 22084
09d4efe1
EZ
22085@kindex maint check-symtabs
22086@item maint check-symtabs
22087Check the consistency of psymtabs and symtabs.
22088
22089@kindex maint cplus first_component
22090@item maint cplus first_component @var{name}
22091Print the first C@t{++} class/namespace component of @var{name}.
22092
22093@kindex maint cplus namespace
22094@item maint cplus namespace
22095Print the list of possible C@t{++} namespaces.
22096
22097@kindex maint demangle
22098@item maint demangle @var{name}
22099Demangle a C@t{++} or Objective-C manled @var{name}.
22100
22101@kindex maint deprecate
22102@kindex maint undeprecate
22103@cindex deprecated commands
22104@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
22105@itemx maint undeprecate @var{command}
22106Deprecate or undeprecate the named @var{command}. Deprecated commands
22107cause @value{GDBN} to issue a warning when you use them. The optional
22108argument @var{replacement} says which newer command should be used in
22109favor of the deprecated one; if it is given, @value{GDBN} will mention
22110the replacement as part of the warning.
22111
22112@kindex maint dump-me
22113@item maint dump-me
721c2651 22114@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 22115Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
22116This is supported only on systems which support aborting a program
22117with the @code{SIGQUIT} signal.
09d4efe1 22118
8d30a00d
AC
22119@kindex maint internal-error
22120@kindex maint internal-warning
09d4efe1
EZ
22121@item maint internal-error @r{[}@var{message-text}@r{]}
22122@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
22123Cause @value{GDBN} to call the internal function @code{internal_error}
22124or @code{internal_warning} and hence behave as though an internal error
22125or internal warning has been detected. In addition to reporting the
22126internal problem, these functions give the user the opportunity to
22127either quit @value{GDBN} or create a core file of the current
22128@value{GDBN} session.
22129
09d4efe1
EZ
22130These commands take an optional parameter @var{message-text} that is
22131used as the text of the error or warning message.
22132
22133Here's an example of using @code{indernal-error}:
22134
8d30a00d 22135@smallexample
f7dc1244 22136(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
22137@dots{}/maint.c:121: internal-error: testing, 1, 2
22138A problem internal to GDB has been detected. Further
22139debugging may prove unreliable.
22140Quit this debugging session? (y or n) @kbd{n}
22141Create a core file? (y or n) @kbd{n}
f7dc1244 22142(@value{GDBP})
8d30a00d
AC
22143@end smallexample
22144
09d4efe1
EZ
22145@kindex maint packet
22146@item maint packet @var{text}
22147If @value{GDBN} is talking to an inferior via the serial protocol,
22148then this command sends the string @var{text} to the inferior, and
22149displays the response packet. @value{GDBN} supplies the initial
22150@samp{$} character, the terminating @samp{#} character, and the
22151checksum.
22152
22153@kindex maint print architecture
22154@item maint print architecture @r{[}@var{file}@r{]}
22155Print the entire architecture configuration. The optional argument
22156@var{file} names the file where the output goes.
8d30a00d 22157
00905d52
AC
22158@kindex maint print dummy-frames
22159@item maint print dummy-frames
00905d52
AC
22160Prints the contents of @value{GDBN}'s internal dummy-frame stack.
22161
22162@smallexample
f7dc1244 22163(@value{GDBP}) @kbd{b add}
00905d52 22164@dots{}
f7dc1244 22165(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
22166Breakpoint 2, add (a=2, b=3) at @dots{}
2216758 return (a + b);
22168The program being debugged stopped while in a function called from GDB.
22169@dots{}
f7dc1244 22170(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
221710x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
22172 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
22173 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 22174(@value{GDBP})
00905d52
AC
22175@end smallexample
22176
22177Takes an optional file parameter.
22178
0680b120
AC
22179@kindex maint print registers
22180@kindex maint print raw-registers
22181@kindex maint print cooked-registers
617073a9 22182@kindex maint print register-groups
09d4efe1
EZ
22183@item maint print registers @r{[}@var{file}@r{]}
22184@itemx maint print raw-registers @r{[}@var{file}@r{]}
22185@itemx maint print cooked-registers @r{[}@var{file}@r{]}
22186@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
22187Print @value{GDBN}'s internal register data structures.
22188
617073a9
AC
22189The command @code{maint print raw-registers} includes the contents of
22190the raw register cache; the command @code{maint print cooked-registers}
22191includes the (cooked) value of all registers; and the command
22192@code{maint print register-groups} includes the groups that each
22193register is a member of. @xref{Registers,, Registers, gdbint,
22194@value{GDBN} Internals}.
0680b120 22195
09d4efe1
EZ
22196These commands take an optional parameter, a file name to which to
22197write the information.
0680b120 22198
617073a9 22199@kindex maint print reggroups
09d4efe1
EZ
22200@item maint print reggroups @r{[}@var{file}@r{]}
22201Print @value{GDBN}'s internal register group data structures. The
22202optional argument @var{file} tells to what file to write the
22203information.
617073a9 22204
09d4efe1 22205The register groups info looks like this:
617073a9
AC
22206
22207@smallexample
f7dc1244 22208(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
22209 Group Type
22210 general user
22211 float user
22212 all user
22213 vector user
22214 system user
22215 save internal
22216 restore internal
617073a9
AC
22217@end smallexample
22218
09d4efe1
EZ
22219@kindex flushregs
22220@item flushregs
22221This command forces @value{GDBN} to flush its internal register cache.
22222
22223@kindex maint print objfiles
22224@cindex info for known object files
22225@item maint print objfiles
22226Print a dump of all known object files. For each object file, this
22227command prints its name, address in memory, and all of its psymtabs
22228and symtabs.
22229
22230@kindex maint print statistics
22231@cindex bcache statistics
22232@item maint print statistics
22233This command prints, for each object file in the program, various data
22234about that object file followed by the byte cache (@dfn{bcache})
22235statistics for the object file. The objfile data includes the number
22236of minimal, partical, full, and stabs symbols, the number of types
22237defined by the objfile, the number of as yet unexpanded psym tables,
22238the number of line tables and string tables, and the amount of memory
22239used by the various tables. The bcache statistics include the counts,
22240sizes, and counts of duplicates of all and unique objects, max,
22241average, and median entry size, total memory used and its overhead and
22242savings, and various measures of the hash table size and chain
22243lengths.
22244
22245@kindex maint print type
22246@cindex type chain of a data type
22247@item maint print type @var{expr}
22248Print the type chain for a type specified by @var{expr}. The argument
22249can be either a type name or a symbol. If it is a symbol, the type of
22250that symbol is described. The type chain produced by this command is
22251a recursive definition of the data type as stored in @value{GDBN}'s
22252data structures, including its flags and contained types.
22253
22254@kindex maint set dwarf2 max-cache-age
22255@kindex maint show dwarf2 max-cache-age
22256@item maint set dwarf2 max-cache-age
22257@itemx maint show dwarf2 max-cache-age
22258Control the DWARF 2 compilation unit cache.
22259
22260@cindex DWARF 2 compilation units cache
22261In object files with inter-compilation-unit references, such as those
22262produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
22263reader needs to frequently refer to previously read compilation units.
22264This setting controls how long a compilation unit will remain in the
22265cache if it is not referenced. A higher limit means that cached
22266compilation units will be stored in memory longer, and more total
22267memory will be used. Setting it to zero disables caching, which will
22268slow down @value{GDBN} startup, but reduce memory consumption.
22269
e7ba9c65
DJ
22270@kindex maint set profile
22271@kindex maint show profile
22272@cindex profiling GDB
22273@item maint set profile
22274@itemx maint show profile
22275Control profiling of @value{GDBN}.
22276
22277Profiling will be disabled until you use the @samp{maint set profile}
22278command to enable it. When you enable profiling, the system will begin
22279collecting timing and execution count data; when you disable profiling or
22280exit @value{GDBN}, the results will be written to a log file. Remember that
22281if you use profiling, @value{GDBN} will overwrite the profiling log file
22282(often called @file{gmon.out}). If you have a record of important profiling
22283data in a @file{gmon.out} file, be sure to move it to a safe location.
22284
22285Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 22286compiled with the @samp{-pg} compiler option.
e7ba9c65 22287
09d4efe1
EZ
22288@kindex maint show-debug-regs
22289@cindex x86 hardware debug registers
22290@item maint show-debug-regs
22291Control whether to show variables that mirror the x86 hardware debug
22292registers. Use @code{ON} to enable, @code{OFF} to disable. If
22293enabled, the debug registers values are shown when GDB inserts or
22294removes a hardware breakpoint or watchpoint, and when the inferior
22295triggers a hardware-assisted breakpoint or watchpoint.
22296
22297@kindex maint space
22298@cindex memory used by commands
22299@item maint space
22300Control whether to display memory usage for each command. If set to a
22301nonzero value, @value{GDBN} will display how much memory each command
22302took, following the command's own output. This can also be requested
22303by invoking @value{GDBN} with the @option{--statistics} command-line
22304switch (@pxref{Mode Options}).
22305
22306@kindex maint time
22307@cindex time of command execution
22308@item maint time
22309Control whether to display the execution time for each command. If
22310set to a nonzero value, @value{GDBN} will display how much time it
22311took to execute each command, following the command's own output.
22312This can also be requested by invoking @value{GDBN} with the
22313@option{--statistics} command-line switch (@pxref{Mode Options}).
22314
22315@kindex maint translate-address
22316@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
22317Find the symbol stored at the location specified by the address
22318@var{addr} and an optional section name @var{section}. If found,
22319@value{GDBN} prints the name of the closest symbol and an offset from
22320the symbol's location to the specified address. This is similar to
22321the @code{info address} command (@pxref{Symbols}), except that this
22322command also allows to find symbols in other sections.
ae038cb0 22323
8e04817f 22324@end table
c906108c 22325
9c16f35a
EZ
22326The following command is useful for non-interactive invocations of
22327@value{GDBN}, such as in the test suite.
22328
22329@table @code
22330@item set watchdog @var{nsec}
22331@kindex set watchdog
22332@cindex watchdog timer
22333@cindex timeout for commands
22334Set the maximum number of seconds @value{GDBN} will wait for the
22335target operation to finish. If this time expires, @value{GDBN}
22336reports and error and the command is aborted.
22337
22338@item show watchdog
22339Show the current setting of the target wait timeout.
22340@end table
c906108c 22341
e0ce93ac 22342@node Remote Protocol
8e04817f 22343@appendix @value{GDBN} Remote Serial Protocol
c906108c 22344
ee2d5c50
AC
22345@menu
22346* Overview::
22347* Packets::
22348* Stop Reply Packets::
22349* General Query Packets::
22350* Register Packet Format::
9d29849a 22351* Tracepoint Packets::
9a6253be 22352* Interrupts::
ee2d5c50 22353* Examples::
0ce1b118 22354* File-I/O remote protocol extension::
ee2d5c50
AC
22355@end menu
22356
22357@node Overview
22358@section Overview
22359
8e04817f
AC
22360There may be occasions when you need to know something about the
22361protocol---for example, if there is only one serial port to your target
22362machine, you might want your program to do something special if it
22363recognizes a packet meant for @value{GDBN}.
c906108c 22364
d2c6833e 22365In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 22366transmitted and received data respectfully.
c906108c 22367
8e04817f
AC
22368@cindex protocol, @value{GDBN} remote serial
22369@cindex serial protocol, @value{GDBN} remote
22370@cindex remote serial protocol
22371All @value{GDBN} commands and responses (other than acknowledgments) are
22372sent as a @var{packet}. A @var{packet} is introduced with the character
22373@samp{$}, the actual @var{packet-data}, and the terminating character
22374@samp{#} followed by a two-digit @var{checksum}:
c906108c 22375
474c8240 22376@smallexample
8e04817f 22377@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 22378@end smallexample
8e04817f 22379@noindent
c906108c 22380
8e04817f
AC
22381@cindex checksum, for @value{GDBN} remote
22382@noindent
22383The two-digit @var{checksum} is computed as the modulo 256 sum of all
22384characters between the leading @samp{$} and the trailing @samp{#} (an
22385eight bit unsigned checksum).
c906108c 22386
8e04817f
AC
22387Implementors should note that prior to @value{GDBN} 5.0 the protocol
22388specification also included an optional two-digit @var{sequence-id}:
c906108c 22389
474c8240 22390@smallexample
8e04817f 22391@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 22392@end smallexample
c906108c 22393
8e04817f
AC
22394@cindex sequence-id, for @value{GDBN} remote
22395@noindent
22396That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
22397has never output @var{sequence-id}s. Stubs that handle packets added
22398since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 22399
8e04817f
AC
22400@cindex acknowledgment, for @value{GDBN} remote
22401When either the host or the target machine receives a packet, the first
22402response expected is an acknowledgment: either @samp{+} (to indicate
22403the package was received correctly) or @samp{-} (to request
22404retransmission):
c906108c 22405
474c8240 22406@smallexample
d2c6833e
AC
22407-> @code{$}@var{packet-data}@code{#}@var{checksum}
22408<- @code{+}
474c8240 22409@end smallexample
8e04817f 22410@noindent
53a5351d 22411
8e04817f
AC
22412The host (@value{GDBN}) sends @var{command}s, and the target (the
22413debugging stub incorporated in your program) sends a @var{response}. In
22414the case of step and continue @var{command}s, the response is only sent
22415when the operation has completed (the target has again stopped).
c906108c 22416
8e04817f
AC
22417@var{packet-data} consists of a sequence of characters with the
22418exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
22419exceptions).
c906108c 22420
8e04817f 22421Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 22422@cindex remote protocol, field separator
8e04817f 22423@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 22424@sc{hex} with leading zeros suppressed.
c906108c 22425
8e04817f
AC
22426Implementors should note that prior to @value{GDBN} 5.0, the character
22427@samp{:} could not appear as the third character in a packet (as it
22428would potentially conflict with the @var{sequence-id}).
c906108c 22429
8e04817f
AC
22430Response @var{data} can be run-length encoded to save space. A @samp{*}
22431means that the next character is an @sc{ascii} encoding giving a repeat count
22432which stands for that many repetitions of the character preceding the
22433@samp{*}. The encoding is @code{n+29}, yielding a printable character
22434where @code{n >=3} (which is where rle starts to win). The printable
22435characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
22436value greater than 126 should not be used.
c906108c 22437
8e04817f 22438So:
474c8240 22439@smallexample
8e04817f 22440"@code{0* }"
474c8240 22441@end smallexample
8e04817f
AC
22442@noindent
22443means the same as "0000".
c906108c 22444
8e04817f
AC
22445The error response returned for some packets includes a two character
22446error number. That number is not well defined.
c906108c 22447
8e04817f
AC
22448For any @var{command} not supported by the stub, an empty response
22449(@samp{$#00}) should be returned. That way it is possible to extend the
22450protocol. A newer @value{GDBN} can tell if a packet is supported based
22451on that response.
c906108c 22452
b383017d
RM
22453A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
22454@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 22455optional.
c906108c 22456
ee2d5c50
AC
22457@node Packets
22458@section Packets
22459
22460The following table provides a complete list of all currently defined
22461@var{command}s and their corresponding response @var{data}.
9c16f35a
EZ
22462@xref{File-I/O remote protocol extension}, for details about the File
22463I/O extension of the remote protocol.
ee2d5c50 22464
b8ff78ce
JB
22465Each packet's description has a template showing the packet's overall
22466syntax, followed by an explanation of the packet's meaning. We
22467include spaces in some of the templates for clarity; these are not
22468part of the packet's syntax. No @value{GDBN} packet uses spaces to
22469separate its components. For example, a template like @samp{foo
22470@var{bar} @var{baz}} describes a packet beginning with the three ASCII
22471bytes @samp{foo}, followed by a @var{bar}, followed directly by a
22472@var{baz}. GDB does not transmit a space character between the
22473@samp{foo} and the @var{bar}, or between the @var{bar} and the
22474@var{baz}.
22475
8ffe2530
JB
22476Note that all packet forms beginning with an upper- or lower-case
22477letter, other than those described here, are reserved for future use.
22478
b8ff78ce 22479Here are the packet descriptions.
ee2d5c50 22480
b8ff78ce 22481@table @samp
ee2d5c50 22482
b8ff78ce
JB
22483@item !
22484@cindex @samp{!} packet
8e04817f
AC
22485Enable extended mode. In extended mode, the remote server is made
22486persistent. The @samp{R} packet is used to restart the program being
22487debugged.
ee2d5c50
AC
22488
22489Reply:
22490@table @samp
22491@item OK
8e04817f 22492The remote target both supports and has enabled extended mode.
ee2d5c50 22493@end table
c906108c 22494
b8ff78ce
JB
22495@item ?
22496@cindex @samp{?} packet
ee2d5c50
AC
22497Indicate the reason the target halted. The reply is the same as for
22498step and continue.
c906108c 22499
ee2d5c50
AC
22500Reply:
22501@xref{Stop Reply Packets}, for the reply specifications.
22502
b8ff78ce
JB
22503@item A @var{arglen},@var{argnum},@var{arg},@dots{}
22504@cindex @samp{A} packet
22505Initialized @code{argv[]} array passed into program. @var{arglen}
22506specifies the number of bytes in the hex encoded byte stream
22507@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
22508
22509Reply:
22510@table @samp
22511@item OK
b8ff78ce
JB
22512The arguments were set.
22513@item E @var{NN}
22514An error occurred.
ee2d5c50
AC
22515@end table
22516
b8ff78ce
JB
22517@item b @var{baud}
22518@cindex @samp{b} packet
22519(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
22520Change the serial line speed to @var{baud}.
22521
22522JTC: @emph{When does the transport layer state change? When it's
22523received, or after the ACK is transmitted. In either case, there are
22524problems if the command or the acknowledgment packet is dropped.}
22525
22526Stan: @emph{If people really wanted to add something like this, and get
22527it working for the first time, they ought to modify ser-unix.c to send
22528some kind of out-of-band message to a specially-setup stub and have the
22529switch happen "in between" packets, so that from remote protocol's point
22530of view, nothing actually happened.}
22531
b8ff78ce
JB
22532@item B @var{addr},@var{mode}
22533@cindex @samp{B} packet
8e04817f 22534Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
22535breakpoint at @var{addr}.
22536
b8ff78ce 22537Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 22538(@pxref{insert breakpoint or watchpoint packet}).
c906108c 22539
b8ff78ce
JB
22540@item c @var{addr}
22541@cindex @samp{c} packet
22542Continue. @var{addr} is address to resume. If @var{addr} is omitted,
22543resume at current address.
c906108c 22544
ee2d5c50
AC
22545Reply:
22546@xref{Stop Reply Packets}, for the reply specifications.
22547
b8ff78ce
JB
22548@item C @var{sig};@var{addr}
22549@cindex @samp{C} packet
8e04817f 22550Continue with signal @var{sig} (hex signal number). If
b8ff78ce 22551@samp{;@var{addr}} is omitted, resume at same address.
c906108c 22552
ee2d5c50
AC
22553Reply:
22554@xref{Stop Reply Packets}, for the reply specifications.
c906108c 22555
b8ff78ce
JB
22556@item d
22557@cindex @samp{d} packet
ee2d5c50
AC
22558Toggle debug flag.
22559
b8ff78ce
JB
22560Don't use this packet; instead, define a general set packet
22561(@pxref{General Query Packets}).
ee2d5c50 22562
b8ff78ce
JB
22563@item D
22564@cindex @samp{D} packet
ee2d5c50 22565Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 22566before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
22567
22568Reply:
22569@table @samp
10fac096
NW
22570@item OK
22571for success
b8ff78ce 22572@item E @var{NN}
10fac096 22573for an error
ee2d5c50 22574@end table
c906108c 22575
b8ff78ce
JB
22576@item F @var{RC},@var{EE},@var{CF};@var{XX}
22577@cindex @samp{F} packet
22578A reply from @value{GDBN} to an @samp{F} packet sent by the target.
22579This is part of the File-I/O protocol extension. @xref{File-I/O
22580remote protocol extension}, for the specification.
ee2d5c50 22581
b8ff78ce 22582@item g
ee2d5c50 22583@anchor{read registers packet}
b8ff78ce 22584@cindex @samp{g} packet
ee2d5c50
AC
22585Read general registers.
22586
22587Reply:
22588@table @samp
22589@item @var{XX@dots{}}
8e04817f
AC
22590Each byte of register data is described by two hex digits. The bytes
22591with the register are transmitted in target byte order. The size of
b8ff78ce 22592each register and their position within the @samp{g} packet are
12c266ea 22593determined by the @value{GDBN} internal macros
b8ff78ce
JB
22594@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{REGISTER_NAME} macros. The
22595specification of several standard @samp{g} packets is specified below.
22596@item E @var{NN}
ee2d5c50
AC
22597for an error.
22598@end table
c906108c 22599
b8ff78ce
JB
22600@item G @var{XX@dots{}}
22601@cindex @samp{G} packet
22602Write general registers. @xref{read registers packet}, for a
22603description of the @var{XX@dots{}} data.
ee2d5c50
AC
22604
22605Reply:
22606@table @samp
22607@item OK
22608for success
b8ff78ce 22609@item E @var{NN}
ee2d5c50
AC
22610for an error
22611@end table
22612
b8ff78ce
JB
22613@item H @var{c} @var{t}
22614@cindex @samp{H} packet
8e04817f 22615Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
22616@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
22617should be @samp{c} for step and continue operations, @samp{g} for other
b8ff78ce
JB
22618operations. The thread designator @var{t} may be @samp{-1}, meaning all
22619the threads, a thread number, or @samp{0} which means pick any thread.
ee2d5c50
AC
22620
22621Reply:
22622@table @samp
22623@item OK
22624for success
b8ff78ce 22625@item E @var{NN}
ee2d5c50
AC
22626for an error
22627@end table
c906108c 22628
8e04817f
AC
22629@c FIXME: JTC:
22630@c 'H': How restrictive (or permissive) is the thread model. If a
22631@c thread is selected and stopped, are other threads allowed
22632@c to continue to execute? As I mentioned above, I think the
22633@c semantics of each command when a thread is selected must be
22634@c described. For example:
22635@c
22636@c 'g': If the stub supports threads and a specific thread is
22637@c selected, returns the register block from that thread;
22638@c otherwise returns current registers.
22639@c
22640@c 'G' If the stub supports threads and a specific thread is
22641@c selected, sets the registers of the register block of
22642@c that thread; otherwise sets current registers.
c906108c 22643
b8ff78ce 22644@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 22645@anchor{cycle step packet}
b8ff78ce
JB
22646@cindex @samp{i} packet
22647Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
22648present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
22649step starting at that address.
c906108c 22650
b8ff78ce
JB
22651@item I
22652@cindex @samp{I} packet
22653Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
22654step packet}.
ee2d5c50 22655
b8ff78ce
JB
22656@item k
22657@cindex @samp{k} packet
22658Kill request.
c906108c 22659
ac282366 22660FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
22661thread context has been selected (i.e.@: does 'k' kill only that
22662thread?)}.
c906108c 22663
b8ff78ce
JB
22664@item m @var{addr},@var{length}
22665@cindex @samp{m} packet
8e04817f 22666Read @var{length} bytes of memory starting at address @var{addr}.
fb031cdf
JB
22667Note that @var{addr} may not be aligned to any particular boundary.
22668
22669The stub need not use any particular size or alignment when gathering
22670data from memory for the response; even if @var{addr} is word-aligned
22671and @var{length} is a multiple of the word size, the stub is free to
22672use byte accesses, or not. For this reason, this packet may not be
22673suitable for accessing memory-mapped I/O devices.
c43c5473
JB
22674@cindex alignment of remote memory accesses
22675@cindex size of remote memory accesses
22676@cindex memory, alignment and size of remote accesses
c906108c 22677
ee2d5c50
AC
22678Reply:
22679@table @samp
22680@item @var{XX@dots{}}
b8ff78ce
JB
22681Memory contents; each byte is transmitted as a two-digit hexidecimal
22682number. The reply may contain fewer bytes than requested if the
22683server was able to read only part of the region of memory.
22684@item E @var{NN}
ee2d5c50
AC
22685@var{NN} is errno
22686@end table
22687
b8ff78ce
JB
22688@item M @var{addr},@var{length}:@var{XX@dots{}}
22689@cindex @samp{M} packet
8e04817f 22690Write @var{length} bytes of memory starting at address @var{addr}.
b8ff78ce
JB
22691@var{XX@dots{}} is the data; each byte is transmitted as a two-digit
22692hexidecimal number.
ee2d5c50
AC
22693
22694Reply:
22695@table @samp
22696@item OK
22697for success
b8ff78ce 22698@item E @var{NN}
8e04817f
AC
22699for an error (this includes the case where only part of the data was
22700written).
ee2d5c50 22701@end table
c906108c 22702
b8ff78ce
JB
22703@item p @var{n}
22704@cindex @samp{p} packet
22705Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
22706@xref{read registers packet}, for a description of how the returned
22707register value is encoded.
ee2d5c50
AC
22708
22709Reply:
22710@table @samp
2e868123
AC
22711@item @var{XX@dots{}}
22712the register's value
b8ff78ce 22713@item E @var{NN}
2e868123
AC
22714for an error
22715@item
22716Indicating an unrecognized @var{query}.
ee2d5c50
AC
22717@end table
22718
b8ff78ce 22719@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 22720@anchor{write register packet}
b8ff78ce
JB
22721@cindex @samp{P} packet
22722Write register @var{n@dots{}} with value @var{r@dots{}}. The register
22723number @var{n} is in hexidecimal, and @var{r@dots{}} contains two hex
8e04817f 22724digits for each byte in the register (target byte order).
c906108c 22725
ee2d5c50
AC
22726Reply:
22727@table @samp
22728@item OK
22729for success
b8ff78ce 22730@item E @var{NN}
ee2d5c50
AC
22731for an error
22732@end table
22733
5f3bebba
JB
22734@item q @var{name} @var{params}@dots{}
22735@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 22736@cindex @samp{q} packet
b8ff78ce 22737@cindex @samp{Q} packet
5f3bebba
JB
22738General query (@samp{q}) and set (@samp{Q}). These packets are
22739described fully in @ref{General Query Packets}.
c906108c 22740
b8ff78ce
JB
22741@item r
22742@cindex @samp{r} packet
8e04817f 22743Reset the entire system.
c906108c 22744
b8ff78ce 22745Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 22746
b8ff78ce
JB
22747@item R @var{XX}
22748@cindex @samp{R} packet
8e04817f
AC
22749Restart the program being debugged. @var{XX}, while needed, is ignored.
22750This packet is only available in extended mode.
ee2d5c50 22751
8e04817f 22752The @samp{R} packet has no reply.
ee2d5c50 22753
b8ff78ce
JB
22754@item s @var{addr}
22755@cindex @samp{s} packet
22756Single step. @var{addr} is the address at which to resume. If
22757@var{addr} is omitted, resume at same address.
c906108c 22758
ee2d5c50
AC
22759Reply:
22760@xref{Stop Reply Packets}, for the reply specifications.
22761
b8ff78ce 22762@item S @var{sig};@var{addr}
ee2d5c50 22763@anchor{step with signal packet}
b8ff78ce
JB
22764@cindex @samp{S} packet
22765Step with signal. This is analogous to the @samp{C} packet, but
22766requests a single-step, rather than a normal resumption of execution.
c906108c 22767
ee2d5c50
AC
22768Reply:
22769@xref{Stop Reply Packets}, for the reply specifications.
22770
b8ff78ce
JB
22771@item t @var{addr}:@var{PP},@var{MM}
22772@cindex @samp{t} packet
8e04817f 22773Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
22774@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
22775@var{addr} must be at least 3 digits.
c906108c 22776
b8ff78ce
JB
22777@item T @var{XX}
22778@cindex @samp{T} packet
ee2d5c50 22779Find out if the thread XX is alive.
c906108c 22780
ee2d5c50
AC
22781Reply:
22782@table @samp
22783@item OK
22784thread is still alive
b8ff78ce 22785@item E @var{NN}
ee2d5c50
AC
22786thread is dead
22787@end table
22788
b8ff78ce
JB
22789@item v
22790Packets starting with @samp{v} are identified by a multi-letter name,
22791up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 22792
b8ff78ce
JB
22793@item vCont@r{[};@var{action}@r{[}:@var{tid}@r{]]}@dots{}
22794@cindex @samp{vCont} packet
22795Resume the inferior, specifying different actions for each thread.
86d30acc
DJ
22796If an action is specified with no @var{tid}, then it is applied to any
22797threads that don't have a specific action specified; if no default action is
22798specified then other threads should remain stopped. Specifying multiple
22799default actions is an error; specifying no actions is also an error.
22800Thread IDs are specified in hexadecimal. Currently supported actions are:
22801
b8ff78ce 22802@table @samp
86d30acc
DJ
22803@item c
22804Continue.
b8ff78ce 22805@item C @var{sig}
86d30acc
DJ
22806Continue with signal @var{sig}. @var{sig} should be two hex digits.
22807@item s
22808Step.
b8ff78ce 22809@item S @var{sig}
86d30acc
DJ
22810Step with signal @var{sig}. @var{sig} should be two hex digits.
22811@end table
22812
22813The optional @var{addr} argument normally associated with these packets is
b8ff78ce 22814not supported in @samp{vCont}.
86d30acc
DJ
22815
22816Reply:
22817@xref{Stop Reply Packets}, for the reply specifications.
22818
b8ff78ce
JB
22819@item vCont?
22820@cindex @samp{vCont?} packet
22821Request a list of actions supporetd by the @samp{vCont} packet.
86d30acc
DJ
22822
22823Reply:
22824@table @samp
b8ff78ce
JB
22825@item vCont@r{[};@var{action}@dots{}@r{]}
22826The @samp{vCont} packet is supported. Each @var{action} is a supported
22827command in the @samp{vCont} packet.
86d30acc 22828@item
b8ff78ce 22829The @samp{vCont} packet is not supported.
86d30acc 22830@end table
ee2d5c50 22831
b8ff78ce 22832@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 22833@anchor{X packet}
b8ff78ce
JB
22834@cindex @samp{X} packet
22835Write data to memory, where the data is transmitted in binary.
22836@var{addr} is address, @var{length} is number of bytes,
22837@samp{@var{XX}@dots{}} is binary data. The bytes @code{0x23}
22838(@sc{ascii} @samp{#}), @code{0x24} (@sc{ascii} @samp{$}), and
22839@code{0x7d} (@sc{ascii} @samp{@}}) are escaped using @code{0x7d}
22840(@sc{ascii} @samp{@}}), and then XORed with @code{0x20}. For example,
22841the byte @code{0x7d} would be transmitted as the two bytes @code{0x7d
228420x5d}.
c906108c 22843
ee2d5c50
AC
22844Reply:
22845@table @samp
22846@item OK
22847for success
b8ff78ce 22848@item E @var{NN}
ee2d5c50
AC
22849for an error
22850@end table
22851
b8ff78ce
JB
22852@item z @var{type},@var{addr},@var{length}
22853@itemx Z @var{type},@var{addr},@var{length}
2f870471 22854@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
22855@cindex @samp{z} packet
22856@cindex @samp{Z} packets
22857Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
2f870471
AC
22858watchpoint starting at address @var{address} and covering the next
22859@var{length} bytes.
ee2d5c50 22860
2f870471
AC
22861Each breakpoint and watchpoint packet @var{type} is documented
22862separately.
22863
512217c7
AC
22864@emph{Implementation notes: A remote target shall return an empty string
22865for an unrecognized breakpoint or watchpoint packet @var{type}. A
22866remote target shall support either both or neither of a given
b8ff78ce 22867@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
22868avoid potential problems with duplicate packets, the operations should
22869be implemented in an idempotent way.}
22870
b8ff78ce
JB
22871@item z0,@var{addr},@var{length}
22872@itemx Z0,@var{addr},@var{length}
22873@cindex @samp{z0} packet
22874@cindex @samp{Z0} packet
22875Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
22876@var{addr} of size @var{length}.
2f870471
AC
22877
22878A memory breakpoint is implemented by replacing the instruction at
22879@var{addr} with a software breakpoint or trap instruction. The
b8ff78ce 22880@var{length} is used by targets that indicates the size of the
2f870471
AC
22881breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
22882@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 22883
2f870471
AC
22884@emph{Implementation note: It is possible for a target to copy or move
22885code that contains memory breakpoints (e.g., when implementing
22886overlays). The behavior of this packet, in the presence of such a
22887target, is not defined.}
c906108c 22888
ee2d5c50
AC
22889Reply:
22890@table @samp
2f870471
AC
22891@item OK
22892success
22893@item
22894not supported
b8ff78ce 22895@item E @var{NN}
ee2d5c50 22896for an error
2f870471
AC
22897@end table
22898
b8ff78ce
JB
22899@item z1,@var{addr},@var{length}
22900@itemx Z1,@var{addr},@var{length}
22901@cindex @samp{z1} packet
22902@cindex @samp{Z1} packet
22903Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
22904address @var{addr} of size @var{length}.
2f870471
AC
22905
22906A hardware breakpoint is implemented using a mechanism that is not
22907dependant on being able to modify the target's memory.
22908
22909@emph{Implementation note: A hardware breakpoint is not affected by code
22910movement.}
22911
22912Reply:
22913@table @samp
ee2d5c50 22914@item OK
2f870471
AC
22915success
22916@item
22917not supported
b8ff78ce 22918@item E @var{NN}
2f870471
AC
22919for an error
22920@end table
22921
b8ff78ce
JB
22922@item z2,@var{addr},@var{length}
22923@itemx Z2,@var{addr},@var{length}
22924@cindex @samp{z2} packet
22925@cindex @samp{Z2} packet
22926Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint.
2f870471
AC
22927
22928Reply:
22929@table @samp
22930@item OK
22931success
22932@item
22933not supported
b8ff78ce 22934@item E @var{NN}
2f870471
AC
22935for an error
22936@end table
22937
b8ff78ce
JB
22938@item z3,@var{addr},@var{length}
22939@itemx Z3,@var{addr},@var{length}
22940@cindex @samp{z3} packet
22941@cindex @samp{Z3} packet
22942Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint.
2f870471
AC
22943
22944Reply:
22945@table @samp
22946@item OK
22947success
22948@item
22949not supported
b8ff78ce 22950@item E @var{NN}
2f870471
AC
22951for an error
22952@end table
22953
b8ff78ce
JB
22954@item z4,@var{addr},@var{length}
22955@itemx Z4,@var{addr},@var{length}
22956@cindex @samp{z4} packet
22957@cindex @samp{Z4} packet
22958Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint.
2f870471
AC
22959
22960Reply:
22961@table @samp
22962@item OK
22963success
22964@item
22965not supported
b8ff78ce 22966@item E @var{NN}
2f870471 22967for an error
ee2d5c50
AC
22968@end table
22969
22970@end table
c906108c 22971
ee2d5c50
AC
22972@node Stop Reply Packets
22973@section Stop Reply Packets
22974@cindex stop reply packets
c906108c 22975
8e04817f
AC
22976The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
22977receive any of the below as a reply. In the case of the @samp{C},
22978@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
b8ff78ce
JB
22979when the target halts. In the below the exact meaning of @dfn{signal
22980number} is poorly defined. In general one of the UNIX signal
22981numbering conventions is used.
c906108c 22982
b8ff78ce
JB
22983As in the description of request packets, we include spaces in the
22984reply templates for clarity; these are not part of the reply packet's
22985syntax. No @value{GDBN} stop reply packet uses spaces to separate its
22986components.
c906108c 22987
b8ff78ce 22988@table @samp
ee2d5c50 22989
b8ff78ce
JB
22990@item S @var{AA}
22991The program received signal number @var{AA} (a two-digit hexidecimal
22992number).
c906108c 22993
b8ff78ce
JB
22994@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
22995@cindex @samp{T} packet reply
22996The program received signal number @var{AA} (a two-digit hexidecimal
22997number). Single-step and breakpoint traps are reported this way. The
22998@samp{@var{n}:@var{r}} pairs give the values of important registers or
22999other information:
23000@enumerate
23001@item
23002If @var{n} is a hexidecimal number, it is a register number, and the
23003corresponding @var{r} gives that register's value. @var{r} is a
23004series of bytes in target byte order, with each byte given by a
23005two-digit hex number.
23006@item
23007If @var{n} is @samp{thread}, then @var{r} is the thread process ID, in
23008hex.
23009@item
23010If @var{n} is @samp{watch}, @samp{rwatch}, or @samp{awatch}, then the
23011packet indicates a watchpoint hit, and @var{r} is the data address, in
23012hex.
23013@item
23014Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
23015and go on to the next; this allows us to extend the protocol in the
23016future.
23017@end enumerate
ee2d5c50 23018
b8ff78ce 23019@item W @var{AA}
8e04817f 23020The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
23021applicable to certain targets.
23022
b8ff78ce 23023@item X @var{AA}
8e04817f 23024The process terminated with signal @var{AA}.
c906108c 23025
b8ff78ce
JB
23026@item O @var{XX}@dots{}
23027@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
23028written as the program's console output. This can happen at any time
23029while the program is running and the debugger should continue to wait
23030for @samp{W}, @samp{T}, etc.
0ce1b118 23031
b8ff78ce 23032@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
23033@var{call-id} is the identifier which says which host system call should
23034be called. This is just the name of the function. Translation into the
23035correct system call is only applicable as it's defined in @value{GDBN}.
23036@xref{File-I/O remote protocol extension}, for a list of implemented
23037system calls.
23038
b8ff78ce
JB
23039@samp{@var{parameter}@dots{}} is a list of parameters as defined for
23040this very system call.
0ce1b118 23041
b8ff78ce
JB
23042The target replies with this packet when it expects @value{GDBN} to
23043call a host system call on behalf of the target. @value{GDBN} replies
23044with an appropriate @samp{F} packet and keeps up waiting for the next
23045reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
23046or @samp{s} action is expected to be continued. @xref{File-I/O remote
23047protocol extension}, for more details.
0ce1b118 23048
ee2d5c50
AC
23049@end table
23050
23051@node General Query Packets
23052@section General Query Packets
9c16f35a 23053@cindex remote query requests
c906108c 23054
5f3bebba
JB
23055Packets starting with @samp{q} are @dfn{general query packets};
23056packets starting with @samp{Q} are @dfn{general set packets}. General
23057query and set packets are a semi-unified form for retrieving and
23058sending information to and from the stub.
23059
23060The initial letter of a query or set packet is followed by a name
23061indicating what sort of thing the packet applies to. For example,
23062@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
23063definitions with the stub. These packet names follow some
23064conventions:
23065
23066@itemize @bullet
23067@item
23068The name must not contain commas, colons or semicolons.
23069@item
23070Most @value{GDBN} query and set packets have a leading upper case
23071letter.
23072@item
23073The names of custom vendor packets should use a company prefix, in
23074lower case, followed by a period. For example, packets designed at
23075the Acme Corporation might begin with @samp{qacme.foo} (for querying
23076foos) or @samp{Qacme.bar} (for setting bars).
23077@end itemize
23078
23079A query or set packet may optionally be followed by a @samp{,} or
23080@samp{;} separated list. Stubs must be careful to match the full
23081packet name, in case packet names have common prefixes.
c906108c 23082
b8ff78ce
JB
23083Like the descriptions of the other packets, each description here
23084has a template showing the packet's overall syntax, followed by an
23085explanation of the packet's meaning. We include spaces in some of the
23086templates for clarity; these are not part of the packet's syntax. No
23087@value{GDBN} packet uses spaces to separate its components.
23088
5f3bebba
JB
23089Here are the currently defined query and set packets:
23090
b8ff78ce 23091@table @samp
c906108c 23092
b8ff78ce 23093@item qC
9c16f35a 23094@cindex current thread, remote request
b8ff78ce 23095@cindex @samp{qC} packet
ee2d5c50
AC
23096Return the current thread id.
23097
23098Reply:
23099@table @samp
b8ff78ce 23100@item QC @var{pid}
e1aac25b 23101Where @var{pid} is an unsigned hexidecimal process id.
b8ff78ce 23102@item @r{(anything else)}
ee2d5c50
AC
23103Any other reply implies the old pid.
23104@end table
23105
b8ff78ce 23106@item qCRC:@var{addr},@var{length}
ff2587ec 23107@cindex CRC of memory block, remote request
b8ff78ce
JB
23108@cindex @samp{qCRC} packet
23109Compute the CRC checksum of a block of memory.
ff2587ec
WZ
23110Reply:
23111@table @samp
b8ff78ce 23112@item E @var{NN}
ff2587ec 23113An error (such as memory fault)
b8ff78ce
JB
23114@item C @var{crc32}
23115The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
23116@end table
23117
b8ff78ce
JB
23118@item qfThreadInfo
23119@itemx qsThreadInfo
9c16f35a 23120@cindex list active threads, remote request
b8ff78ce
JB
23121@cindex @samp{qfThreadInfo} packet
23122@cindex @samp{qsThreadInfo} packet
23123Obtain a list of all active thread ids from the target (OS). Since there
8e04817f
AC
23124may be too many active threads to fit into one reply packet, this query
23125works iteratively: it may require more than one query/reply sequence to
23126obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
23127be the @samp{qfThreadInfo} query; subsequent queries in the
23128sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 23129
b8ff78ce 23130NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
23131
23132Reply:
23133@table @samp
b8ff78ce 23134@item m @var{id}
ee2d5c50 23135A single thread id
b8ff78ce 23136@item m @var{id},@var{id}@dots{}
ee2d5c50 23137a comma-separated list of thread ids
b8ff78ce
JB
23138@item l
23139(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
23140@end table
23141
23142In response to each query, the target will reply with a list of one or
e1aac25b
JB
23143more thread ids, in big-endian unsigned hex, separated by commas.
23144@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce
JB
23145ids (using the @samp{qs} form of the query), until the target responds
23146with @samp{l} (lower-case el, for @dfn{last}).
c906108c 23147
b8ff78ce 23148@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 23149@cindex get thread-local storage address, remote request
b8ff78ce 23150@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
23151Fetch the address associated with thread local storage specified
23152by @var{thread-id}, @var{offset}, and @var{lm}.
23153
23154@var{thread-id} is the (big endian, hex encoded) thread id associated with the
23155thread for which to fetch the TLS address.
23156
23157@var{offset} is the (big endian, hex encoded) offset associated with the
23158thread local variable. (This offset is obtained from the debug
23159information associated with the variable.)
23160
23161@var{lm} is the (big endian, hex encoded) OS/ABI specific encoding of the
23162the load module associated with the thread local storage. For example,
23163a @sc{gnu}/Linux system will pass the link map address of the shared
23164object associated with the thread local storage under consideration.
23165Other operating environments may choose to represent the load module
23166differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
23167
23168Reply:
b8ff78ce
JB
23169@table @samp
23170@item @var{XX}@dots{}
ff2587ec
WZ
23171Hex encoded (big endian) bytes representing the address of the thread
23172local storage requested.
23173
b8ff78ce
JB
23174@item E @var{nn}
23175An error occurred. @var{nn} are hex digits.
ff2587ec 23176
b8ff78ce
JB
23177@item
23178An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
23179@end table
23180
ff2587ec
WZ
23181Use of this request packet is controlled by the @code{set remote
23182get-thread-local-storage-address} command (@pxref{Remote
23183configuration, set remote get-thread-local-storage-address}).
23184
b8ff78ce 23185@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
23186Obtain thread information from RTOS. Where: @var{startflag} (one hex
23187digit) is one to indicate the first query and zero to indicate a
23188subsequent query; @var{threadcount} (two hex digits) is the maximum
23189number of threads the response packet can contain; and @var{nextthread}
23190(eight hex digits), for subsequent queries (@var{startflag} is zero), is
23191returned in the response as @var{argthread}.
ee2d5c50 23192
b8ff78ce 23193Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
23194
23195Reply:
23196@table @samp
b8ff78ce 23197@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
23198Where: @var{count} (two hex digits) is the number of threads being
23199returned; @var{done} (one hex digit) is zero to indicate more threads
23200and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 23201digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
ee2d5c50 23202is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 23203digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 23204@end table
c906108c 23205
b8ff78ce 23206@item qOffsets
9c16f35a 23207@cindex section offsets, remote request
b8ff78ce 23208@cindex @samp{qOffsets} packet
8e04817f
AC
23209Get section offsets that the target used when re-locating the downloaded
23210image. @emph{Note: while a @code{Bss} offset is included in the
23211response, @value{GDBN} ignores this and instead applies the @code{Data}
23212offset to the @code{Bss} section.}
c906108c 23213
ee2d5c50
AC
23214Reply:
23215@table @samp
b8ff78ce 23216@item Text=@var{xxx};Data=@var{yyy};Bss=@var{zzz}
ee2d5c50
AC
23217@end table
23218
b8ff78ce 23219@item qP @var{mode} @var{threadid}
9c16f35a 23220@cindex thread information, remote request
b8ff78ce 23221@cindex @samp{qP} packet
8e04817f
AC
23222Returns information on @var{threadid}. Where: @var{mode} is a hex
23223encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50 23224
b8ff78ce 23225Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 23226
b8ff78ce 23227@item qPart:@var{object}:read:@var{annex}:@var{offset},@var{length}
9c16f35a 23228@cindex read special object, remote request
b8ff78ce 23229@cindex @samp{qPart} packet
649e03f6 23230Read uninterpreted bytes from the target's special data area
b8ff78ce
JB
23231identified by the keyword @var{object}. Request @var{length} bytes
23232starting at @var{offset} bytes into the data. The content and
23233encoding of @var{annex} is specific to the object; it can supply
23234additional details about what data to access.
649e03f6 23235
b8ff78ce
JB
23236Here are the specific requests of this form defined so far. All
23237@samp{qPart:@var{object}:read:@dots{}} requests use the same reply
23238formats, listed below.
649e03f6 23239
b8ff78ce
JB
23240@table @samp
23241@item qPart:auxv:read::@var{offset},@var{length}
721c2651
EZ
23242Access the target's @dfn{auxiliary vector}. @xref{OS Information,
23243auxiliary vector}, and see @ref{Remote configuration,
23244read-aux-vector-packet}. Note @var{annex} must be empty.
649e03f6
RM
23245@end table
23246
23247Reply:
b8ff78ce
JB
23248@table @samp
23249@item OK
649e03f6
RM
23250The @var{offset} in the request is at the end of the data.
23251There is no more data to be read.
23252
b8ff78ce 23253@item @var{XX}@dots{}
649e03f6
RM
23254Hex encoded data bytes read.
23255This may be fewer bytes than the @var{length} in the request.
23256
b8ff78ce 23257@item E00
649e03f6
RM
23258The request was malformed, or @var{annex} was invalid.
23259
b8ff78ce 23260@item E @var{nn}
649e03f6
RM
23261The offset was invalid, or there was an error encountered reading the data.
23262@var{nn} is a hex-encoded @code{errno} value.
23263
b8ff78ce 23264@item
649e03f6
RM
23265An empty reply indicates the @var{object} or @var{annex} string was not
23266recognized by the stub.
23267@end table
23268
b8ff78ce 23269@item qPart:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
9c16f35a 23270@cindex write data into object, remote request
649e03f6 23271Write uninterpreted bytes into the target's special data area
b8ff78ce
JB
23272identified by the keyword @var{object}, starting at @var{offset} bytes
23273into the data. @samp{@var{data}@dots{}} is the hex-encoded data to be
23274written. The content and encoding of @var{annex} is specific to the
23275object; it can supply additional details about what data to access.
649e03f6
RM
23276
23277No requests of this form are presently in use. This specification
23278serves as a placeholder to document the common format that new
23279specific request specifications ought to use.
23280
23281Reply:
b8ff78ce 23282@table @samp
649e03f6
RM
23283@item @var{nn}
23284@var{nn} (hex encoded) is the number of bytes written.
23285This may be fewer bytes than supplied in the request.
23286
b8ff78ce 23287@item E00
649e03f6
RM
23288The request was malformed, or @var{annex} was invalid.
23289
b8ff78ce 23290@item E @var{nn}
649e03f6
RM
23291The offset was invalid, or there was an error encountered writing the data.
23292@var{nn} is a hex-encoded @code{errno} value.
23293
b8ff78ce 23294@item
649e03f6
RM
23295An empty reply indicates the @var{object} or @var{annex} string was not
23296recognized by the stub, or that the object does not support writing.
23297@end table
23298
b8ff78ce 23299@item qPart:@var{object}:@var{operation}:@dots{}
649e03f6
RM
23300Requests of this form may be added in the future. When a stub does
23301not recognize the @var{object} keyword, or its support for
b8ff78ce
JB
23302@var{object} does not recognize the @var{operation} keyword, the stub
23303must respond with an empty packet.
83761cbd 23304
b8ff78ce 23305@item qRcmd,@var{command}
ff2587ec 23306@cindex execute remote command, remote request
b8ff78ce 23307@cindex @samp{qRcmd} packet
ff2587ec 23308@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
23309execution. Invalid commands should be reported using the output
23310string. Before the final result packet, the target may also respond
23311with a number of intermediate @samp{O@var{output}} console output
23312packets. @emph{Implementors should note that providing access to a
23313stubs's interpreter may have security implications}.
fa93a9d8 23314
ff2587ec
WZ
23315Reply:
23316@table @samp
23317@item OK
23318A command response with no output.
23319@item @var{OUTPUT}
23320A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 23321@item E @var{NN}
ff2587ec 23322Indicate a badly formed request.
b8ff78ce
JB
23323@item
23324An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 23325@end table
fa93a9d8 23326
b8ff78ce 23327@item qSymbol::
ff2587ec 23328@cindex symbol lookup, remote request
b8ff78ce 23329@cindex @samp{qSymbol} packet
ff2587ec
WZ
23330Notify the target that @value{GDBN} is prepared to serve symbol lookup
23331requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
23332
23333Reply:
ff2587ec 23334@table @samp
b8ff78ce 23335@item OK
ff2587ec 23336The target does not need to look up any (more) symbols.
b8ff78ce 23337@item qSymbol:@var{sym_name}
ff2587ec
WZ
23338The target requests the value of symbol @var{sym_name} (hex encoded).
23339@value{GDBN} may provide the value by using the
b8ff78ce
JB
23340@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
23341below.
ff2587ec 23342@end table
83761cbd 23343
b8ff78ce 23344@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
23345Set the value of @var{sym_name} to @var{sym_value}.
23346
23347@var{sym_name} (hex encoded) is the name of a symbol whose value the
23348target has previously requested.
23349
23350@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
23351@value{GDBN} cannot supply a value for @var{sym_name}, then this field
23352will be empty.
23353
23354Reply:
23355@table @samp
b8ff78ce 23356@item OK
ff2587ec 23357The target does not need to look up any (more) symbols.
b8ff78ce 23358@item qSymbol:@var{sym_name}
ff2587ec
WZ
23359The target requests the value of a new symbol @var{sym_name} (hex
23360encoded). @value{GDBN} will continue to supply the values of symbols
23361(if available), until the target ceases to request them.
fa93a9d8 23362@end table
0abb7bc7 23363
9d29849a
JB
23364@item QTDP
23365@itemx QTFrame
23366@xref{Tracepoint Packets}.
23367
b8ff78ce 23368@item qThreadExtraInfo,@var{id}
ff2587ec 23369@cindex thread attributes info, remote request
b8ff78ce
JB
23370@cindex @samp{qThreadExtraInfo} packet
23371Obtain a printable string description of a thread's attributes from
23372the target OS. @var{id} is a thread-id in big-endian hex. This
23373string may contain anything that the target OS thinks is interesting
23374for @value{GDBN} to tell the user about the thread. The string is
23375displayed in @value{GDBN}'s @code{info threads} display. Some
23376examples of possible thread extra info strings are @samp{Runnable}, or
23377@samp{Blocked on Mutex}.
ff2587ec
WZ
23378
23379Reply:
23380@table @samp
b8ff78ce
JB
23381@item @var{XX}@dots{}
23382Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
23383comprising the printable string containing the extra information about
23384the thread's attributes.
ff2587ec 23385@end table
814e32d7 23386
9d29849a
JB
23387@item QTStart
23388@itemx QTStop
23389@itemx QTinit
23390@itemx QTro
23391@itemx qTStatus
23392@xref{Tracepoint Packets}.
23393
ee2d5c50
AC
23394@end table
23395
23396@node Register Packet Format
23397@section Register Packet Format
eb12ee30 23398
b8ff78ce 23399The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
23400In the below, some thirty-two bit registers are transferred as
23401sixty-four bits. Those registers should be zero/sign extended (which?)
23402to fill the space allocated. Register bytes are transfered in target
23403byte order. The two nibbles within a register byte are transfered
23404most-significant - least-significant.
eb12ee30 23405
ee2d5c50 23406@table @r
eb12ee30 23407
8e04817f 23408@item MIPS32
ee2d5c50 23409
8e04817f
AC
23410All registers are transfered as thirty-two bit quantities in the order:
2341132 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
23412registers; fsr; fir; fp.
eb12ee30 23413
8e04817f 23414@item MIPS64
ee2d5c50 23415
8e04817f
AC
23416All registers are transfered as sixty-four bit quantities (including
23417thirty-two bit registers such as @code{sr}). The ordering is the same
23418as @code{MIPS32}.
eb12ee30 23419
ee2d5c50
AC
23420@end table
23421
9d29849a
JB
23422@node Tracepoint Packets
23423@section Tracepoint Packets
23424@cindex tracepoint packets
23425@cindex packets, tracepoint
23426
23427Here we describe the packets @value{GDBN} uses to implement
23428tracepoints (@pxref{Tracepoints}).
23429
23430@table @samp
23431
23432@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}@r{[}-@r{]}
23433Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
23434is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
23435the tracepoint is disabled. @var{step} is the tracepoint's step
23436count, and @var{pass} is its pass count. If the trailing @samp{-} is
23437present, further @samp{QTDP} packets will follow to specify this
23438tracepoint's actions.
23439
23440Replies:
23441@table @samp
23442@item OK
23443The packet was understood and carried out.
23444@item
23445The packet was not recognized.
23446@end table
23447
23448@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
23449Define actions to be taken when a tracepoint is hit. @var{n} and
23450@var{addr} must be the same as in the initial @samp{QTDP} packet for
23451this tracepoint. This packet may only be sent immediately after
23452another @samp{QTDP} packet that ended with a @samp{-}. If the
23453trailing @samp{-} is present, further @samp{QTDP} packets will follow,
23454specifying more actions for this tracepoint.
23455
23456In the series of action packets for a given tracepoint, at most one
23457can have an @samp{S} before its first @var{action}. If such a packet
23458is sent, it and the following packets define ``while-stepping''
23459actions. Any prior packets define ordinary actions --- that is, those
23460taken when the tracepoint is first hit. If no action packet has an
23461@samp{S}, then all the packets in the series specify ordinary
23462tracepoint actions.
23463
23464The @samp{@var{action}@dots{}} portion of the packet is a series of
23465actions, concatenated without separators. Each action has one of the
23466following forms:
23467
23468@table @samp
23469
23470@item R @var{mask}
23471Collect the registers whose bits are set in @var{mask}. @var{mask} is
23472a hexidecimal number whose @var{i}'th bit is set if register number
23473@var{i} should be collected. (The least significant bit is numbered
23474zero.) Note that @var{mask} may be any number of digits long; it may
23475not fit in a 32-bit word.
23476
23477@item M @var{basereg},@var{offset},@var{len}
23478Collect @var{len} bytes of memory starting at the address in register
23479number @var{basereg}, plus @var{offset}. If @var{basereg} is
23480@samp{-1}, then the range has a fixed address: @var{offset} is the
23481address of the lowest byte to collect. The @var{basereg},
23482@var{offset}, and @var{len} parameters are all unsigned hexidecimal
23483values (the @samp{-1} value for @var{basereg} is a special case).
23484
23485@item X @var{len},@var{expr}
23486Evaluate @var{expr}, whose length is @var{len}, and collect memory as
23487it directs. @var{expr} is an agent expression, as described in
23488@ref{Agent Expressions}. Each byte of the expression is encoded as a
23489two-digit hex number in the packet; @var{len} is the number of bytes
23490in the expression (and thus one-half the number of hex digits in the
23491packet).
23492
23493@end table
23494
23495Any number of actions may be packed together in a single @samp{QTDP}
23496packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
23497length (400 bytes, for many stubs). There may be only one @samp{R}
23498action per tracepoint, and it must precede any @samp{M} or @samp{X}
23499actions. Any registers referred to by @samp{M} and @samp{X} actions
23500must be collected by a preceding @samp{R} action. (The
23501``while-stepping'' actions are treated as if they were attached to a
23502separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
23503
23504Replies:
23505@table @samp
23506@item OK
23507The packet was understood and carried out.
23508@item
23509The packet was not recognized.
23510@end table
23511
23512@item QTFrame:@var{n}
23513Select the @var{n}'th tracepoint frame from the buffer, and use the
23514register and memory contents recorded there to answer subsequent
23515request packets from @value{GDBN}.
23516
23517A successful reply from the stub indicates that the stub has found the
23518requested frame. The response is a series of parts, concatenated
23519without separators, describing the frame we selected. Each part has
23520one of the following forms:
23521
23522@table @samp
23523@item F @var{f}
23524The selected frame is number @var{n} in the trace frame buffer;
23525@var{f} is a hexidecimal number. If @var{f} is @samp{-1}, then there
23526was no frame matching the criteria in the request packet.
23527
23528@item T @var{t}
23529The selected trace frame records a hit of tracepoint number @var{t};
23530@var{t} is a hexidecimal number.
23531
23532@end table
23533
23534@item QTFrame:pc:@var{addr}
23535Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
23536currently selected frame whose PC is @var{addr};
23537@var{addr} is a hexidecimal number.
23538
23539@item QTFrame:tdp:@var{t}
23540Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
23541currently selected frame that is a hit of tracepoint @var{t}; @var{t}
23542is a hexidecimal number.
23543
23544@item QTFrame:range:@var{start}:@var{end}
23545Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
23546currently selected frame whose PC is between @var{start} (inclusive)
23547and @var{end} (exclusive); @var{start} and @var{end} are hexidecimal
23548numbers.
23549
23550@item QTFrame:outside:@var{start}:@var{end}
23551Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
23552frame @emph{outside} the given range of addresses.
23553
23554@item QTStart
23555Begin the tracepoint experiment. Begin collecting data from tracepoint
23556hits in the trace frame buffer.
23557
23558@item QTStop
23559End the tracepoint experiment. Stop collecting trace frames.
23560
23561@item QTinit
23562Clear the table of tracepoints, and empty the trace frame buffer.
23563
23564@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
23565Establish the given ranges of memory as ``transparent''. The stub
23566will answer requests for these ranges from memory's current contents,
23567if they were not collected as part of the tracepoint hit.
23568
23569@value{GDBN} uses this to mark read-only regions of memory, like those
23570containing program code. Since these areas never change, they should
23571still have the same contents they did when the tracepoint was hit, so
23572there's no reason for the stub to refuse to provide their contents.
23573
23574@item qTStatus
23575Ask the stub if there is a trace experiment running right now.
23576
23577Replies:
23578@table @samp
23579@item T0
23580There is no trace experiment running.
23581@item T1
23582There is a trace experiment running.
23583@end table
23584
23585@end table
23586
23587
9a6253be
KB
23588@node Interrupts
23589@section Interrupts
23590@cindex interrupts (remote protocol)
23591
23592When a program on the remote target is running, @value{GDBN} may
23593attempt to interrupt it by sending a @samp{Ctrl-C} or a @code{BREAK},
23594control of which is specified via @value{GDBN}'s @samp{remotebreak}
23595setting (@pxref{set remotebreak}).
23596
23597The precise meaning of @code{BREAK} is defined by the transport
23598mechanism and may, in fact, be undefined. @value{GDBN} does
23599not currently define a @code{BREAK} mechanism for any of the network
23600interfaces.
23601
23602@samp{Ctrl-C}, on the other hand, is defined and implemented for all
23603transport mechanisms. It is represented by sending the single byte
23604@code{0x03} without any of the usual packet overhead described in
23605the Overview section (@pxref{Overview}). When a @code{0x03} byte is
23606transmitted as part of a packet, it is considered to be packet data
23607and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
23608(@pxref{X packet}, used for binary downloads, may include an unescaped
23609@code{0x03} as part of its packet.
23610
23611Stubs are not required to recognize these interrupt mechanisms and the
23612precise meaning associated with receipt of the interrupt is
23613implementation defined. If the stub is successful at interrupting the
23614running program, it is expected that it will send one of the Stop
23615Reply Packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
23616of successfully stopping the program. Interrupts received while the
23617program is stopped will be discarded.
23618
ee2d5c50
AC
23619@node Examples
23620@section Examples
eb12ee30 23621
8e04817f
AC
23622Example sequence of a target being re-started. Notice how the restart
23623does not get any direct output:
eb12ee30 23624
474c8240 23625@smallexample
d2c6833e
AC
23626-> @code{R00}
23627<- @code{+}
8e04817f 23628@emph{target restarts}
d2c6833e 23629-> @code{?}
8e04817f 23630<- @code{+}
d2c6833e
AC
23631<- @code{T001:1234123412341234}
23632-> @code{+}
474c8240 23633@end smallexample
eb12ee30 23634
8e04817f 23635Example sequence of a target being stepped by a single instruction:
eb12ee30 23636
474c8240 23637@smallexample
d2c6833e 23638-> @code{G1445@dots{}}
8e04817f 23639<- @code{+}
d2c6833e
AC
23640-> @code{s}
23641<- @code{+}
23642@emph{time passes}
23643<- @code{T001:1234123412341234}
8e04817f 23644-> @code{+}
d2c6833e 23645-> @code{g}
8e04817f 23646<- @code{+}
d2c6833e
AC
23647<- @code{1455@dots{}}
23648-> @code{+}
474c8240 23649@end smallexample
eb12ee30 23650
0ce1b118
CV
23651@node File-I/O remote protocol extension
23652@section File-I/O remote protocol extension
23653@cindex File-I/O remote protocol extension
23654
23655@menu
23656* File-I/O Overview::
23657* Protocol basics::
1d8b2f28
JB
23658* The F request packet::
23659* The F reply packet::
0ce1b118
CV
23660* Memory transfer::
23661* The Ctrl-C message::
23662* Console I/O::
23663* The isatty call::
23664* The system call::
23665* List of supported calls::
23666* Protocol specific representation of datatypes::
23667* Constants::
23668* File-I/O Examples::
23669@end menu
23670
23671@node File-I/O Overview
23672@subsection File-I/O Overview
23673@cindex file-i/o overview
23674
9c16f35a
EZ
23675The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
23676target to use the host's file system and console I/O when calling various
0ce1b118
CV
23677system calls. System calls on the target system are translated into a
23678remote protocol packet to the host system which then performs the needed
23679actions and returns with an adequate response packet to the target system.
23680This simulates file system operations even on targets that lack file systems.
23681
23682The protocol is defined host- and target-system independent. It uses
9c16f35a 23683its own independent representation of datatypes and values. Both,
0ce1b118
CV
23684@value{GDBN} and the target's @value{GDBN} stub are responsible for
23685translating the system dependent values into the unified protocol values
23686when data is transmitted.
23687
23688The communication is synchronous. A system call is possible only
23689when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
23690packets. While @value{GDBN} handles the request for a system call,
23691the target is stopped to allow deterministic access to the target's
23692memory. Therefore File-I/O is not interuptible by target signals. It
23693is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
23694
23695The target's request to perform a host system call does not finish
23696the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
23697after finishing the system call, the target returns to continuing the
23698previous activity (continue, step). No additional continue or step
23699request from @value{GDBN} is required.
23700
23701@smallexample
f7dc1244 23702(@value{GDBP}) continue
0ce1b118
CV
23703 <- target requests 'system call X'
23704 target is stopped, @value{GDBN} executes system call
23705 -> GDB returns result
23706 ... target continues, GDB returns to wait for the target
23707 <- target hits breakpoint and sends a Txx packet
23708@end smallexample
23709
23710The protocol is only used for files on the host file system and
23711for I/O on the console. Character or block special devices, pipes,
23712named pipes or sockets or any other communication method on the host
23713system are not supported by this protocol.
23714
23715@node Protocol basics
23716@subsection Protocol basics
23717@cindex protocol basics, file-i/o
23718
23719The File-I/O protocol uses the @code{F} packet, as request as well
23720as as reply packet. Since a File-I/O system call can only occur when
b383017d 23721@value{GDBN} is waiting for the continuing or stepping target, the
0ce1b118
CV
23722File-I/O request is a reply that @value{GDBN} has to expect as a result
23723of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
23724This @code{F} packet contains all information needed to allow @value{GDBN}
23725to call the appropriate host system call:
23726
23727@itemize @bullet
b383017d 23728@item
0ce1b118
CV
23729A unique identifier for the requested system call.
23730
23731@item
23732All parameters to the system call. Pointers are given as addresses
23733in the target memory address space. Pointers to strings are given as
b383017d 23734pointer/length pair. Numerical values are given as they are.
0ce1b118
CV
23735Numerical control values are given in a protocol specific representation.
23736
23737@end itemize
23738
23739At that point @value{GDBN} has to perform the following actions.
23740
23741@itemize @bullet
b383017d 23742@item
0ce1b118
CV
23743If parameter pointer values are given, which point to data needed as input
23744to a system call, @value{GDBN} requests this data from the target with a
23745standard @code{m} packet request. This additional communication has to be
23746expected by the target implementation and is handled as any other @code{m}
23747packet.
23748
23749@item
23750@value{GDBN} translates all value from protocol representation to host
23751representation as needed. Datatypes are coerced into the host types.
23752
23753@item
23754@value{GDBN} calls the system call
23755
23756@item
23757It then coerces datatypes back to protocol representation.
23758
23759@item
23760If pointer parameters in the request packet point to buffer space in which
23761a system call is expected to copy data to, the data is transmitted to the
23762target using a @code{M} or @code{X} packet. This packet has to be expected
23763by the target implementation and is handled as any other @code{M} or @code{X}
23764packet.
23765
23766@end itemize
23767
23768Eventually @value{GDBN} replies with another @code{F} packet which contains all
23769necessary information for the target to continue. This at least contains
23770
23771@itemize @bullet
23772@item
23773Return value.
23774
23775@item
23776@code{errno}, if has been changed by the system call.
23777
23778@item
23779``Ctrl-C'' flag.
23780
23781@end itemize
23782
23783After having done the needed type and value coercion, the target continues
23784the latest continue or step action.
23785
1d8b2f28 23786@node The F request packet
0ce1b118
CV
23787@subsection The @code{F} request packet
23788@cindex file-i/o request packet
23789@cindex @code{F} request packet
23790
23791The @code{F} request packet has the following format:
23792
23793@table @samp
23794
23795@smallexample
23796@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
23797@end smallexample
23798
23799@var{call-id} is the identifier to indicate the host system call to be called.
23800This is just the name of the function.
23801
23802@var{parameter@dots{}} are the parameters to the system call.
23803
b383017d 23804@end table
0ce1b118
CV
23805
23806Parameters are hexadecimal integer values, either the real values in case
23807of scalar datatypes, as pointers to target buffer space in case of compound
23808datatypes and unspecified memory areas or as pointer/length pairs in case
23809of string parameters. These are appended to the call-id, each separated
23810from its predecessor by a comma. All values are transmitted in ASCII
23811string representation, pointer/length pairs separated by a slash.
23812
1d8b2f28 23813@node The F reply packet
0ce1b118
CV
23814@subsection The @code{F} reply packet
23815@cindex file-i/o reply packet
23816@cindex @code{F} reply packet
23817
23818The @code{F} reply packet has the following format:
23819
23820@table @samp
23821
23822@smallexample
23823@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
23824@end smallexample
23825
23826@var{retcode} is the return code of the system call as hexadecimal value.
23827
23828@var{errno} is the errno set by the call, in protocol specific representation.
23829This parameter can be omitted if the call was successful.
23830
23831@var{Ctrl-C flag} is only send if the user requested a break. In this
23832case, @var{errno} must be send as well, even if the call was successful.
23833The @var{Ctrl-C flag} itself consists of the character 'C':
23834
23835@smallexample
23836F0,0,C
23837@end smallexample
23838
23839@noindent
23840or, if the call was interupted before the host call has been performed:
23841
23842@smallexample
23843F-1,4,C
23844@end smallexample
23845
23846@noindent
23847assuming 4 is the protocol specific representation of @code{EINTR}.
23848
23849@end table
23850
23851@node Memory transfer
23852@subsection Memory transfer
23853@cindex memory transfer, in file-i/o protocol
23854
23855Structured data which is transferred using a memory read or write as e.g.@:
23856a @code{struct stat} is expected to be in a protocol specific format with
23857all scalar multibyte datatypes being big endian. This should be done by
23858the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
23859it transfers memory to the target. Transferred pointers to structured
23860data should point to the already coerced data at any time.
23861
23862@node The Ctrl-C message
23863@subsection The Ctrl-C message
23864@cindex ctrl-c message, in file-i/o protocol
23865
23866A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
23867reply packet. In this case the target should behave, as if it had
23868gotten a break message. The meaning for the target is ``system call
23869interupted by @code{SIGINT}''. Consequentially, the target should actually stop
23870(as with a break message) and return to @value{GDBN} with a @code{T02}
b383017d 23871packet. In this case, it's important for the target to know, in which
0ce1b118
CV
23872state the system call was interrupted. Since this action is by design
23873not an atomic operation, we have to differ between two cases:
23874
23875@itemize @bullet
23876@item
23877The system call hasn't been performed on the host yet.
23878
23879@item
23880The system call on the host has been finished.
23881
23882@end itemize
23883
23884These two states can be distinguished by the target by the value of the
23885returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
23886call hasn't been performed. This is equivalent to the @code{EINTR} handling
23887on POSIX systems. In any other case, the target may presume that the
23888system call has been finished --- successful or not --- and should behave
23889as if the break message arrived right after the system call.
23890
23891@value{GDBN} must behave reliable. If the system call has not been called
23892yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
23893@code{errno} in the packet. If the system call on the host has been finished
23894before the user requests a break, the full action must be finshed by
23895@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
23896The @code{F} packet may only be send when either nothing has happened
23897or the full action has been completed.
23898
23899@node Console I/O
23900@subsection Console I/O
23901@cindex console i/o as part of file-i/o
23902
23903By default and if not explicitely closed by the target system, the file
23904descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
23905on the @value{GDBN} console is handled as any other file output operation
23906(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
23907by @value{GDBN} so that after the target read request from file descriptor
239080 all following typing is buffered until either one of the following
23909conditions is met:
23910
23911@itemize @bullet
23912@item
23913The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
23914@code{read}
23915system call is treated as finished.
23916
23917@item
23918The user presses @kbd{Enter}. This is treated as end of input with a trailing
23919line feed.
23920
23921@item
23922The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
23923character, especially no Ctrl-D is appended to the input.
23924
23925@end itemize
23926
23927If the user has typed more characters as fit in the buffer given to
23928the read call, the trailing characters are buffered in @value{GDBN} until
23929either another @code{read(0, @dots{})} is requested by the target or debugging
23930is stopped on users request.
23931
23932@node The isatty call
2eecc4ab 23933@subsection The @samp{isatty} function call
0ce1b118
CV
23934@cindex isatty call, file-i/o protocol
23935
23936A special case in this protocol is the library call @code{isatty} which
9c16f35a 23937is implemented as its own call inside of this protocol. It returns
0ce1b118
CV
239381 to the target if the file descriptor given as parameter is attached
23939to the @value{GDBN} console, 0 otherwise. Implementing through system calls
23940would require implementing @code{ioctl} and would be more complex than
23941needed.
23942
23943@node The system call
2eecc4ab 23944@subsection The @samp{system} function call
0ce1b118
CV
23945@cindex system call, file-i/o protocol
23946
23947The other special case in this protocol is the @code{system} call which
9c16f35a 23948is implemented as its own call, too. @value{GDBN} is taking over the full
0ce1b118
CV
23949task of calling the necessary host calls to perform the @code{system}
23950call. The return value of @code{system} is simplified before it's returned
23951to the target. Basically, the only signal transmitted back is @code{EINTR}
23952in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
23953entirely of the exit status of the called command.
23954
9c16f35a
EZ
23955Due to security concerns, the @code{system} call is by default refused
23956by @value{GDBN}. The user has to allow this call explicitly with the
23957@kbd{set remote system-call-allowed 1} command.
0ce1b118 23958
9c16f35a
EZ
23959@table @code
23960@item set remote system-call-allowed
23961@kindex set remote system-call-allowed
23962Control whether to allow the @code{system} calls in the File I/O
23963protocol for the remote target. The default is zero (disabled).
0ce1b118 23964
9c16f35a 23965@item show remote system-call-allowed
0ce1b118 23966@kindex show remote system-call-allowed
9c16f35a
EZ
23967Show the current setting of system calls for the remote File I/O
23968protocol.
0ce1b118
CV
23969@end table
23970
23971@node List of supported calls
23972@subsection List of supported calls
23973@cindex list of supported file-i/o calls
23974
23975@menu
23976* open::
23977* close::
23978* read::
23979* write::
23980* lseek::
23981* rename::
23982* unlink::
23983* stat/fstat::
23984* gettimeofday::
23985* isatty::
23986* system::
23987@end menu
23988
23989@node open
23990@unnumberedsubsubsec open
23991@cindex open, file-i/o system call
23992
23993@smallexample
23994@exdent Synopsis:
23995int open(const char *pathname, int flags);
23996int open(const char *pathname, int flags, mode_t mode);
23997
b383017d 23998@exdent Request:
0ce1b118
CV
23999Fopen,pathptr/len,flags,mode
24000@end smallexample
24001
24002@noindent
24003@code{flags} is the bitwise or of the following values:
24004
24005@table @code
b383017d 24006@item O_CREAT
0ce1b118
CV
24007If the file does not exist it will be created. The host
24008rules apply as far as file ownership and time stamps
24009are concerned.
24010
b383017d 24011@item O_EXCL
0ce1b118
CV
24012When used with O_CREAT, if the file already exists it is
24013an error and open() fails.
24014
b383017d 24015@item O_TRUNC
0ce1b118
CV
24016If the file already exists and the open mode allows
24017writing (O_RDWR or O_WRONLY is given) it will be
24018truncated to length 0.
24019
b383017d 24020@item O_APPEND
0ce1b118
CV
24021The file is opened in append mode.
24022
b383017d 24023@item O_RDONLY
0ce1b118
CV
24024The file is opened for reading only.
24025
b383017d 24026@item O_WRONLY
0ce1b118
CV
24027The file is opened for writing only.
24028
b383017d 24029@item O_RDWR
0ce1b118
CV
24030The file is opened for reading and writing.
24031
24032@noindent
24033Each other bit is silently ignored.
24034
24035@end table
24036
24037@noindent
24038@code{mode} is the bitwise or of the following values:
24039
24040@table @code
b383017d 24041@item S_IRUSR
0ce1b118
CV
24042User has read permission.
24043
b383017d 24044@item S_IWUSR
0ce1b118
CV
24045User has write permission.
24046
b383017d 24047@item S_IRGRP
0ce1b118
CV
24048Group has read permission.
24049
b383017d 24050@item S_IWGRP
0ce1b118
CV
24051Group has write permission.
24052
b383017d 24053@item S_IROTH
0ce1b118
CV
24054Others have read permission.
24055
b383017d 24056@item S_IWOTH
0ce1b118
CV
24057Others have write permission.
24058
24059@noindent
24060Each other bit is silently ignored.
24061
24062@end table
24063
24064@smallexample
24065@exdent Return value:
24066open returns the new file descriptor or -1 if an error
24067occured.
24068
24069@exdent Errors:
24070@end smallexample
24071
24072@table @code
b383017d 24073@item EEXIST
0ce1b118
CV
24074pathname already exists and O_CREAT and O_EXCL were used.
24075
b383017d 24076@item EISDIR
0ce1b118
CV
24077pathname refers to a directory.
24078
b383017d 24079@item EACCES
0ce1b118
CV
24080The requested access is not allowed.
24081
24082@item ENAMETOOLONG
24083pathname was too long.
24084
b383017d 24085@item ENOENT
0ce1b118
CV
24086A directory component in pathname does not exist.
24087
b383017d 24088@item ENODEV
0ce1b118
CV
24089pathname refers to a device, pipe, named pipe or socket.
24090
b383017d 24091@item EROFS
0ce1b118
CV
24092pathname refers to a file on a read-only filesystem and
24093write access was requested.
24094
b383017d 24095@item EFAULT
0ce1b118
CV
24096pathname is an invalid pointer value.
24097
b383017d 24098@item ENOSPC
0ce1b118
CV
24099No space on device to create the file.
24100
b383017d 24101@item EMFILE
0ce1b118
CV
24102The process already has the maximum number of files open.
24103
b383017d 24104@item ENFILE
0ce1b118
CV
24105The limit on the total number of files open on the system
24106has been reached.
24107
b383017d 24108@item EINTR
0ce1b118
CV
24109The call was interrupted by the user.
24110@end table
24111
24112@node close
24113@unnumberedsubsubsec close
24114@cindex close, file-i/o system call
24115
24116@smallexample
b383017d 24117@exdent Synopsis:
0ce1b118
CV
24118int close(int fd);
24119
b383017d 24120@exdent Request:
0ce1b118
CV
24121Fclose,fd
24122
24123@exdent Return value:
24124close returns zero on success, or -1 if an error occurred.
24125
24126@exdent Errors:
24127@end smallexample
24128
24129@table @code
b383017d 24130@item EBADF
0ce1b118
CV
24131fd isn't a valid open file descriptor.
24132
b383017d 24133@item EINTR
0ce1b118
CV
24134The call was interrupted by the user.
24135@end table
24136
24137@node read
24138@unnumberedsubsubsec read
24139@cindex read, file-i/o system call
24140
24141@smallexample
b383017d 24142@exdent Synopsis:
0ce1b118
CV
24143int read(int fd, void *buf, unsigned int count);
24144
b383017d 24145@exdent Request:
0ce1b118
CV
24146Fread,fd,bufptr,count
24147
24148@exdent Return value:
24149On success, the number of bytes read is returned.
24150Zero indicates end of file. If count is zero, read
b383017d 24151returns zero as well. On error, -1 is returned.
0ce1b118
CV
24152
24153@exdent Errors:
24154@end smallexample
24155
24156@table @code
b383017d 24157@item EBADF
0ce1b118
CV
24158fd is not a valid file descriptor or is not open for
24159reading.
24160
b383017d 24161@item EFAULT
0ce1b118
CV
24162buf is an invalid pointer value.
24163
b383017d 24164@item EINTR
0ce1b118
CV
24165The call was interrupted by the user.
24166@end table
24167
24168@node write
24169@unnumberedsubsubsec write
24170@cindex write, file-i/o system call
24171
24172@smallexample
b383017d 24173@exdent Synopsis:
0ce1b118
CV
24174int write(int fd, const void *buf, unsigned int count);
24175
b383017d 24176@exdent Request:
0ce1b118
CV
24177Fwrite,fd,bufptr,count
24178
24179@exdent Return value:
24180On success, the number of bytes written are returned.
24181Zero indicates nothing was written. On error, -1
24182is returned.
24183
24184@exdent Errors:
24185@end smallexample
24186
24187@table @code
b383017d 24188@item EBADF
0ce1b118
CV
24189fd is not a valid file descriptor or is not open for
24190writing.
24191
b383017d 24192@item EFAULT
0ce1b118
CV
24193buf is an invalid pointer value.
24194
b383017d 24195@item EFBIG
0ce1b118
CV
24196An attempt was made to write a file that exceeds the
24197host specific maximum file size allowed.
24198
b383017d 24199@item ENOSPC
0ce1b118
CV
24200No space on device to write the data.
24201
b383017d 24202@item EINTR
0ce1b118
CV
24203The call was interrupted by the user.
24204@end table
24205
24206@node lseek
24207@unnumberedsubsubsec lseek
24208@cindex lseek, file-i/o system call
24209
24210@smallexample
b383017d 24211@exdent Synopsis:
0ce1b118
CV
24212long lseek (int fd, long offset, int flag);
24213
b383017d 24214@exdent Request:
0ce1b118
CV
24215Flseek,fd,offset,flag
24216@end smallexample
24217
24218@code{flag} is one of:
24219
24220@table @code
b383017d 24221@item SEEK_SET
0ce1b118
CV
24222The offset is set to offset bytes.
24223
b383017d 24224@item SEEK_CUR
0ce1b118
CV
24225The offset is set to its current location plus offset
24226bytes.
24227
b383017d 24228@item SEEK_END
0ce1b118
CV
24229The offset is set to the size of the file plus offset
24230bytes.
24231@end table
24232
24233@smallexample
24234@exdent Return value:
24235On success, the resulting unsigned offset in bytes from
24236the beginning of the file is returned. Otherwise, a
24237value of -1 is returned.
24238
24239@exdent Errors:
24240@end smallexample
24241
24242@table @code
b383017d 24243@item EBADF
0ce1b118
CV
24244fd is not a valid open file descriptor.
24245
b383017d 24246@item ESPIPE
0ce1b118
CV
24247fd is associated with the @value{GDBN} console.
24248
b383017d 24249@item EINVAL
0ce1b118
CV
24250flag is not a proper value.
24251
b383017d 24252@item EINTR
0ce1b118
CV
24253The call was interrupted by the user.
24254@end table
24255
24256@node rename
24257@unnumberedsubsubsec rename
24258@cindex rename, file-i/o system call
24259
24260@smallexample
b383017d 24261@exdent Synopsis:
0ce1b118
CV
24262int rename(const char *oldpath, const char *newpath);
24263
b383017d 24264@exdent Request:
0ce1b118
CV
24265Frename,oldpathptr/len,newpathptr/len
24266
24267@exdent Return value:
24268On success, zero is returned. On error, -1 is returned.
24269
24270@exdent Errors:
24271@end smallexample
24272
24273@table @code
b383017d 24274@item EISDIR
0ce1b118
CV
24275newpath is an existing directory, but oldpath is not a
24276directory.
24277
b383017d 24278@item EEXIST
0ce1b118
CV
24279newpath is a non-empty directory.
24280
b383017d 24281@item EBUSY
0ce1b118
CV
24282oldpath or newpath is a directory that is in use by some
24283process.
24284
b383017d 24285@item EINVAL
0ce1b118
CV
24286An attempt was made to make a directory a subdirectory
24287of itself.
24288
b383017d 24289@item ENOTDIR
0ce1b118
CV
24290A component used as a directory in oldpath or new
24291path is not a directory. Or oldpath is a directory
24292and newpath exists but is not a directory.
24293
b383017d 24294@item EFAULT
0ce1b118
CV
24295oldpathptr or newpathptr are invalid pointer values.
24296
b383017d 24297@item EACCES
0ce1b118
CV
24298No access to the file or the path of the file.
24299
24300@item ENAMETOOLONG
b383017d 24301
0ce1b118
CV
24302oldpath or newpath was too long.
24303
b383017d 24304@item ENOENT
0ce1b118
CV
24305A directory component in oldpath or newpath does not exist.
24306
b383017d 24307@item EROFS
0ce1b118
CV
24308The file is on a read-only filesystem.
24309
b383017d 24310@item ENOSPC
0ce1b118
CV
24311The device containing the file has no room for the new
24312directory entry.
24313
b383017d 24314@item EINTR
0ce1b118
CV
24315The call was interrupted by the user.
24316@end table
24317
24318@node unlink
24319@unnumberedsubsubsec unlink
24320@cindex unlink, file-i/o system call
24321
24322@smallexample
b383017d 24323@exdent Synopsis:
0ce1b118
CV
24324int unlink(const char *pathname);
24325
b383017d 24326@exdent Request:
0ce1b118
CV
24327Funlink,pathnameptr/len
24328
24329@exdent Return value:
24330On success, zero is returned. On error, -1 is returned.
24331
24332@exdent Errors:
24333@end smallexample
24334
24335@table @code
b383017d 24336@item EACCES
0ce1b118
CV
24337No access to the file or the path of the file.
24338
b383017d 24339@item EPERM
0ce1b118
CV
24340The system does not allow unlinking of directories.
24341
b383017d 24342@item EBUSY
0ce1b118
CV
24343The file pathname cannot be unlinked because it's
24344being used by another process.
24345
b383017d 24346@item EFAULT
0ce1b118
CV
24347pathnameptr is an invalid pointer value.
24348
24349@item ENAMETOOLONG
24350pathname was too long.
24351
b383017d 24352@item ENOENT
0ce1b118
CV
24353A directory component in pathname does not exist.
24354
b383017d 24355@item ENOTDIR
0ce1b118
CV
24356A component of the path is not a directory.
24357
b383017d 24358@item EROFS
0ce1b118
CV
24359The file is on a read-only filesystem.
24360
b383017d 24361@item EINTR
0ce1b118
CV
24362The call was interrupted by the user.
24363@end table
24364
24365@node stat/fstat
24366@unnumberedsubsubsec stat/fstat
24367@cindex fstat, file-i/o system call
24368@cindex stat, file-i/o system call
24369
24370@smallexample
b383017d 24371@exdent Synopsis:
0ce1b118
CV
24372int stat(const char *pathname, struct stat *buf);
24373int fstat(int fd, struct stat *buf);
24374
b383017d 24375@exdent Request:
0ce1b118
CV
24376Fstat,pathnameptr/len,bufptr
24377Ffstat,fd,bufptr
24378
24379@exdent Return value:
24380On success, zero is returned. On error, -1 is returned.
24381
24382@exdent Errors:
24383@end smallexample
24384
24385@table @code
b383017d 24386@item EBADF
0ce1b118
CV
24387fd is not a valid open file.
24388
b383017d 24389@item ENOENT
0ce1b118
CV
24390A directory component in pathname does not exist or the
24391path is an empty string.
24392
b383017d 24393@item ENOTDIR
0ce1b118
CV
24394A component of the path is not a directory.
24395
b383017d 24396@item EFAULT
0ce1b118
CV
24397pathnameptr is an invalid pointer value.
24398
b383017d 24399@item EACCES
0ce1b118
CV
24400No access to the file or the path of the file.
24401
24402@item ENAMETOOLONG
24403pathname was too long.
24404
b383017d 24405@item EINTR
0ce1b118
CV
24406The call was interrupted by the user.
24407@end table
24408
24409@node gettimeofday
24410@unnumberedsubsubsec gettimeofday
24411@cindex gettimeofday, file-i/o system call
24412
24413@smallexample
b383017d 24414@exdent Synopsis:
0ce1b118
CV
24415int gettimeofday(struct timeval *tv, void *tz);
24416
b383017d 24417@exdent Request:
0ce1b118
CV
24418Fgettimeofday,tvptr,tzptr
24419
24420@exdent Return value:
24421On success, 0 is returned, -1 otherwise.
24422
24423@exdent Errors:
24424@end smallexample
24425
24426@table @code
b383017d 24427@item EINVAL
0ce1b118
CV
24428tz is a non-NULL pointer.
24429
b383017d 24430@item EFAULT
0ce1b118
CV
24431tvptr and/or tzptr is an invalid pointer value.
24432@end table
24433
24434@node isatty
24435@unnumberedsubsubsec isatty
24436@cindex isatty, file-i/o system call
24437
24438@smallexample
b383017d 24439@exdent Synopsis:
0ce1b118
CV
24440int isatty(int fd);
24441
b383017d 24442@exdent Request:
0ce1b118
CV
24443Fisatty,fd
24444
24445@exdent Return value:
24446Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
24447
24448@exdent Errors:
24449@end smallexample
24450
24451@table @code
b383017d 24452@item EINTR
0ce1b118
CV
24453The call was interrupted by the user.
24454@end table
24455
24456@node system
24457@unnumberedsubsubsec system
24458@cindex system, file-i/o system call
24459
24460@smallexample
b383017d 24461@exdent Synopsis:
0ce1b118
CV
24462int system(const char *command);
24463
b383017d 24464@exdent Request:
0ce1b118
CV
24465Fsystem,commandptr/len
24466
24467@exdent Return value:
24468The value returned is -1 on error and the return status
24469of the command otherwise. Only the exit status of the
24470command is returned, which is extracted from the hosts
24471system return value by calling WEXITSTATUS(retval).
24472In case /bin/sh could not be executed, 127 is returned.
24473
24474@exdent Errors:
24475@end smallexample
24476
24477@table @code
b383017d 24478@item EINTR
0ce1b118
CV
24479The call was interrupted by the user.
24480@end table
24481
24482@node Protocol specific representation of datatypes
24483@subsection Protocol specific representation of datatypes
24484@cindex protocol specific representation of datatypes, in file-i/o protocol
24485
24486@menu
24487* Integral datatypes::
24488* Pointer values::
24489* struct stat::
24490* struct timeval::
24491@end menu
24492
24493@node Integral datatypes
24494@unnumberedsubsubsec Integral datatypes
24495@cindex integral datatypes, in file-i/o protocol
24496
24497The integral datatypes used in the system calls are
24498
24499@smallexample
24500int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
24501@end smallexample
24502
24503@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
24504implemented as 32 bit values in this protocol.
24505
b383017d
RM
24506@code{Long} and @code{unsigned long} are implemented as 64 bit types.
24507
0ce1b118
CV
24508@xref{Limits}, for corresponding MIN and MAX values (similar to those
24509in @file{limits.h}) to allow range checking on host and target.
24510
24511@code{time_t} datatypes are defined as seconds since the Epoch.
24512
24513All integral datatypes transferred as part of a memory read or write of a
24514structured datatype e.g.@: a @code{struct stat} have to be given in big endian
24515byte order.
24516
24517@node Pointer values
24518@unnumberedsubsubsec Pointer values
24519@cindex pointer values, in file-i/o protocol
24520
24521Pointers to target data are transmitted as they are. An exception
24522is made for pointers to buffers for which the length isn't
24523transmitted as part of the function call, namely strings. Strings
24524are transmitted as a pointer/length pair, both as hex values, e.g.@:
24525
24526@smallexample
24527@code{1aaf/12}
24528@end smallexample
24529
24530@noindent
24531which is a pointer to data of length 18 bytes at position 0x1aaf.
24532The length is defined as the full string length in bytes, including
24533the trailing null byte. Example:
24534
24535@smallexample
24536``hello, world'' at address 0x123456
24537@end smallexample
24538
24539@noindent
24540is transmitted as
24541
24542@smallexample
24543@code{123456/d}
24544@end smallexample
24545
24546@node struct stat
24547@unnumberedsubsubsec struct stat
24548@cindex struct stat, in file-i/o protocol
24549
24550The buffer of type struct stat used by the target and @value{GDBN} is defined
24551as follows:
24552
24553@smallexample
24554struct stat @{
24555 unsigned int st_dev; /* device */
24556 unsigned int st_ino; /* inode */
24557 mode_t st_mode; /* protection */
24558 unsigned int st_nlink; /* number of hard links */
24559 unsigned int st_uid; /* user ID of owner */
24560 unsigned int st_gid; /* group ID of owner */
24561 unsigned int st_rdev; /* device type (if inode device) */
24562 unsigned long st_size; /* total size, in bytes */
24563 unsigned long st_blksize; /* blocksize for filesystem I/O */
24564 unsigned long st_blocks; /* number of blocks allocated */
24565 time_t st_atime; /* time of last access */
24566 time_t st_mtime; /* time of last modification */
24567 time_t st_ctime; /* time of last change */
24568@};
24569@end smallexample
24570
24571The integral datatypes are conforming to the definitions given in the
24572approriate section (see @ref{Integral datatypes}, for details) so this
24573structure is of size 64 bytes.
24574
24575The values of several fields have a restricted meaning and/or
24576range of values.
24577
24578@smallexample
24579st_dev: 0 file
24580 1 console
24581
24582st_ino: No valid meaning for the target. Transmitted unchanged.
24583
24584st_mode: Valid mode bits are described in Appendix C. Any other
24585 bits have currently no meaning for the target.
24586
24587st_uid: No valid meaning for the target. Transmitted unchanged.
24588
24589st_gid: No valid meaning for the target. Transmitted unchanged.
24590
24591st_rdev: No valid meaning for the target. Transmitted unchanged.
24592
24593st_atime, st_mtime, st_ctime:
24594 These values have a host and file system dependent
24595 accuracy. Especially on Windows hosts the file systems
24596 don't support exact timing values.
24597@end smallexample
24598
24599The target gets a struct stat of the above representation and is
24600responsible to coerce it to the target representation before
24601continuing.
24602
24603Note that due to size differences between the host and target
24604representation of stat members, these members could eventually
24605get truncated on the target.
24606
24607@node struct timeval
24608@unnumberedsubsubsec struct timeval
24609@cindex struct timeval, in file-i/o protocol
24610
24611The buffer of type struct timeval used by the target and @value{GDBN}
24612is defined as follows:
24613
24614@smallexample
b383017d 24615struct timeval @{
0ce1b118
CV
24616 time_t tv_sec; /* second */
24617 long tv_usec; /* microsecond */
24618@};
24619@end smallexample
24620
24621The integral datatypes are conforming to the definitions given in the
24622approriate section (see @ref{Integral datatypes}, for details) so this
24623structure is of size 8 bytes.
24624
24625@node Constants
24626@subsection Constants
24627@cindex constants, in file-i/o protocol
24628
24629The following values are used for the constants inside of the
24630protocol. @value{GDBN} and target are resposible to translate these
24631values before and after the call as needed.
24632
24633@menu
24634* Open flags::
24635* mode_t values::
24636* Errno values::
24637* Lseek flags::
24638* Limits::
24639@end menu
24640
24641@node Open flags
24642@unnumberedsubsubsec Open flags
24643@cindex open flags, in file-i/o protocol
24644
24645All values are given in hexadecimal representation.
24646
24647@smallexample
24648 O_RDONLY 0x0
24649 O_WRONLY 0x1
24650 O_RDWR 0x2
24651 O_APPEND 0x8
24652 O_CREAT 0x200
24653 O_TRUNC 0x400
24654 O_EXCL 0x800
24655@end smallexample
24656
24657@node mode_t values
24658@unnumberedsubsubsec mode_t values
24659@cindex mode_t values, in file-i/o protocol
24660
24661All values are given in octal representation.
24662
24663@smallexample
24664 S_IFREG 0100000
24665 S_IFDIR 040000
24666 S_IRUSR 0400
24667 S_IWUSR 0200
24668 S_IXUSR 0100
24669 S_IRGRP 040
24670 S_IWGRP 020
24671 S_IXGRP 010
24672 S_IROTH 04
24673 S_IWOTH 02
24674 S_IXOTH 01
24675@end smallexample
24676
24677@node Errno values
24678@unnumberedsubsubsec Errno values
24679@cindex errno values, in file-i/o protocol
24680
24681All values are given in decimal representation.
24682
24683@smallexample
24684 EPERM 1
24685 ENOENT 2
24686 EINTR 4
24687 EBADF 9
24688 EACCES 13
24689 EFAULT 14
24690 EBUSY 16
24691 EEXIST 17
24692 ENODEV 19
24693 ENOTDIR 20
24694 EISDIR 21
24695 EINVAL 22
24696 ENFILE 23
24697 EMFILE 24
24698 EFBIG 27
24699 ENOSPC 28
24700 ESPIPE 29
24701 EROFS 30
24702 ENAMETOOLONG 91
24703 EUNKNOWN 9999
24704@end smallexample
24705
24706 EUNKNOWN is used as a fallback error value if a host system returns
24707 any error value not in the list of supported error numbers.
24708
24709@node Lseek flags
24710@unnumberedsubsubsec Lseek flags
24711@cindex lseek flags, in file-i/o protocol
24712
24713@smallexample
24714 SEEK_SET 0
24715 SEEK_CUR 1
24716 SEEK_END 2
24717@end smallexample
24718
24719@node Limits
24720@unnumberedsubsubsec Limits
24721@cindex limits, in file-i/o protocol
24722
24723All values are given in decimal representation.
24724
24725@smallexample
24726 INT_MIN -2147483648
24727 INT_MAX 2147483647
24728 UINT_MAX 4294967295
24729 LONG_MIN -9223372036854775808
24730 LONG_MAX 9223372036854775807
24731 ULONG_MAX 18446744073709551615
24732@end smallexample
24733
24734@node File-I/O Examples
24735@subsection File-I/O Examples
24736@cindex file-i/o examples
24737
24738Example sequence of a write call, file descriptor 3, buffer is at target
24739address 0x1234, 6 bytes should be written:
24740
24741@smallexample
24742<- @code{Fwrite,3,1234,6}
24743@emph{request memory read from target}
24744-> @code{m1234,6}
24745<- XXXXXX
24746@emph{return "6 bytes written"}
24747-> @code{F6}
24748@end smallexample
24749
24750Example sequence of a read call, file descriptor 3, buffer is at target
24751address 0x1234, 6 bytes should be read:
24752
24753@smallexample
24754<- @code{Fread,3,1234,6}
24755@emph{request memory write to target}
24756-> @code{X1234,6:XXXXXX}
24757@emph{return "6 bytes read"}
24758-> @code{F6}
24759@end smallexample
24760
24761Example sequence of a read call, call fails on the host due to invalid
24762file descriptor (EBADF):
24763
24764@smallexample
24765<- @code{Fread,3,1234,6}
24766-> @code{F-1,9}
24767@end smallexample
24768
24769Example sequence of a read call, user presses Ctrl-C before syscall on
24770host is called:
24771
24772@smallexample
24773<- @code{Fread,3,1234,6}
24774-> @code{F-1,4,C}
24775<- @code{T02}
24776@end smallexample
24777
24778Example sequence of a read call, user presses Ctrl-C after syscall on
24779host is called:
24780
24781@smallexample
24782<- @code{Fread,3,1234,6}
24783-> @code{X1234,6:XXXXXX}
24784<- @code{T02}
24785@end smallexample
24786
f418dd93
DJ
24787@include agentexpr.texi
24788
aab4e0ec 24789@include gpl.texi
eb12ee30 24790
2154891a 24791@raisesections
6826cf00 24792@include fdl.texi
2154891a 24793@lowersections
6826cf00 24794
6d2ebf8b 24795@node Index
c906108c
SS
24796@unnumbered Index
24797
24798@printindex cp
24799
24800@tex
24801% I think something like @colophon should be in texinfo. In the
24802% meantime:
24803\long\def\colophon{\hbox to0pt{}\vfill
24804\centerline{The body of this manual is set in}
24805\centerline{\fontname\tenrm,}
24806\centerline{with headings in {\bf\fontname\tenbf}}
24807\centerline{and examples in {\tt\fontname\tentt}.}
24808\centerline{{\it\fontname\tenit\/},}
24809\centerline{{\bf\fontname\tenbf}, and}
24810\centerline{{\sl\fontname\tensl\/}}
24811\centerline{are used for emphasis.}\vfill}
24812\page\colophon
24813% Blame: doc@cygnus.com, 1991.
24814@end tex
24815
c906108c 24816@bye
This page took 2.110119 seconds and 4 git commands to generate.