119370Spst\input texinfo      @c -*-texinfo-*-
298948Sobrien@c Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
3130809Smarcel@c 1999, 2000, 2001, 2002, 2003, 2004
419370Spst@c Free Software Foundation, Inc.
519370Spst@c
698948Sobrien@c %**start of header
719370Spst@c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
819370Spst@c of @set vars.  However, you can override filename with makeinfo -o.
919370Spst@setfilename gdb.info
1019370Spst@c
1119370Spst@include gdb-cfg.texi
1219370Spst@c
1319370Spst@settitle Debugging with @value{GDBN}
1419370Spst@setchapternewpage odd
1519370Spst@c %**end of header
1619370Spst
1719370Spst@iftex
1819370Spst@c @smallbook
1919370Spst@c @cropmarks
2019370Spst@end iftex
2119370Spst
2219370Spst@finalout
2319370Spst@syncodeindex ky cp
2419370Spst
2598948Sobrien@c readline appendices use @vindex, @findex and @ftable,
2698948Sobrien@c annotate.texi and gdbmi use @findex.
2719370Spst@syncodeindex vr cp
2898948Sobrien@syncodeindex fn cp
2919370Spst
3019370Spst@c !!set GDB manual's edition---not the same as GDB version!
31130809Smarcel@c This is updated by GNU Press.
3298948Sobrien@set EDITION Ninth
3319370Spst
34130809Smarcel@c !!set GDB edit command default editor
35130809Smarcel@set EDITOR /bin/ex
3619370Spst
3798948Sobrien@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
3819370Spst
3919370Spst@c This is a dir.info fragment to support semi-automated addition of
4098948Sobrien@c manuals to an info tree.
41130809Smarcel@dircategory Software development
4298948Sobrien@direntry
43130809Smarcel* Gdb: (gdb).                     The GNU debugger.
4498948Sobrien@end direntry
4598948Sobrien
4619370Spst@ifinfo
4719370SpstThis file documents the @sc{gnu} debugger @value{GDBN}.
4819370Spst
4919370Spst
50130809SmarcelThis is the @value{EDITION} Edition, of @cite{Debugging with
51130809Smarcel@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
52130809SmarcelVersion @value{GDBVN}.
5319370Spst
5498948SobrienCopyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,@*
55130809Smarcel              1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5619370Spst
5798948SobrienPermission is granted to copy, distribute and/or modify this document
5898948Sobrienunder the terms of the GNU Free Documentation License, Version 1.1 or
5998948Sobrienany later version published by the Free Software Foundation; with the
6098948SobrienInvariant Sections being ``Free Software'' and ``Free Software Needs
6198948SobrienFree Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
6298948Sobrienand with the Back-Cover Texts as in (a) below.
6319370Spst
6498948Sobrien(a) The Free Software Foundation's Back-Cover Text is: ``You have
6598948Sobrienfreedom to copy and modify this GNU Manual, like GNU software.  Copies
6698948Sobrienpublished by the Free Software Foundation raise funds for GNU
6798948Sobriendevelopment.''
6819370Spst@end ifinfo
6919370Spst
7019370Spst@titlepage
7119370Spst@title Debugging with @value{GDBN}
7219370Spst@subtitle The @sc{gnu} Source-Level Debugger
7319370Spst@sp 1
7446289Sdfr@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
7598948Sobrien@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
7619370Spst@page
7719370Spst@tex
7819370Spst{\parskip=0pt
7998948Sobrien\hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
8019370Spst\hfill {\it Debugging with @value{GDBN}}\par
8119370Spst\hfill \TeX{}info \texinfoversion\par
8219370Spst}
8319370Spst@end tex
8419370Spst
8519370Spst@vskip 0pt plus 1filll
8698948SobrienCopyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
87130809Smarcel1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
8819370Spst@sp 2
8919370SpstPublished by the Free Software Foundation @*
9019370Spst59 Temple Place - Suite 330, @*
9119370SpstBoston, MA 02111-1307 USA @*
9298948SobrienISBN 1-882114-77-9 @*
9319370Spst
9498948SobrienPermission is granted to copy, distribute and/or modify this document
9598948Sobrienunder the terms of the GNU Free Documentation License, Version 1.1 or
9698948Sobrienany later version published by the Free Software Foundation; with the
9798948SobrienInvariant Sections being ``Free Software'' and ``Free Software Needs
9898948SobrienFree Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
9998948Sobrienand with the Back-Cover Texts as in (a) below.
10019370Spst
10198948Sobrien(a) The Free Software Foundation's Back-Cover Text is: ``You have
10298948Sobrienfreedom to copy and modify this GNU Manual, like GNU software.  Copies
10398948Sobrienpublished by the Free Software Foundation raise funds for GNU
10498948Sobriendevelopment.''
10519370Spst@end titlepage
10619370Spst@page
10719370Spst
10898948Sobrien@ifnottex
10946289Sdfr@node Top, Summary, (dir), (dir)
11098948Sobrien
11119370Spst@top Debugging with @value{GDBN}
11219370Spst
11319370SpstThis file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
11419370Spst
115130809SmarcelThis is the @value{EDITION} Edition, for @value{GDBN} Version
11619370Spst@value{GDBVN}.
11719370Spst
118130809SmarcelCopyright (C) 1988-2004 Free Software Foundation, Inc.
11998948Sobrien
12019370Spst@menu
12119370Spst* Summary::                     Summary of @value{GDBN}
12219370Spst* Sample Session::              A sample @value{GDBN} session
12319370Spst
12419370Spst* Invocation::                  Getting in and out of @value{GDBN}
12519370Spst* Commands::                    @value{GDBN} commands
12619370Spst* Running::                     Running programs under @value{GDBN}
12719370Spst* Stopping::                    Stopping and continuing
12819370Spst* Stack::                       Examining the stack
12919370Spst* Source::                      Examining source files
13019370Spst* Data::                        Examining data
131130809Smarcel* Macros::                      Preprocessor Macros
13298948Sobrien* Tracepoints::                 Debugging remote targets non-intrusively
13398948Sobrien* Overlays::                    Debugging programs that use overlays
13498948Sobrien
13519370Spst* Languages::                   Using @value{GDBN} with different languages
13646289Sdfr
13719370Spst* Symbols::                     Examining the symbol table
13819370Spst* Altering::                    Altering execution
13919370Spst* GDB Files::                   @value{GDBN} files
14019370Spst* Targets::                     Specifying a debugging target
14198948Sobrien* Remote Debugging::            Debugging remote programs
14298948Sobrien* Configurations::              Configuration-specific information
14319370Spst* Controlling GDB::             Controlling @value{GDBN}
14419370Spst* Sequences::                   Canned sequences of commands
14598948Sobrien* TUI::                         @value{GDBN} Text User Interface
146130809Smarcel* Interpreters::		Command Interpreters
14719370Spst* Emacs::                       Using @value{GDBN} under @sc{gnu} Emacs
14898948Sobrien* Annotations::                 @value{GDBN}'s annotation interface.
14998948Sobrien* GDB/MI::                      @value{GDBN}'s Machine Interface.
15019370Spst
15119370Spst* GDB Bugs::                    Reporting bugs in @value{GDBN}
15219370Spst* Formatting Documentation::    How to format and print @value{GDBN} documentation
15346289Sdfr
15446289Sdfr* Command Line Editing::        Command Line Editing
15546289Sdfr* Using History Interactively:: Using History Interactively
15619370Spst* Installing GDB::              Installing GDB
15798948Sobrien* Maintenance Commands::        Maintenance Commands
15898948Sobrien* Remote Protocol::             GDB Remote Serial Protocol
159130809Smarcel* Agent Expressions::           The GDB Agent Expression Mechanism
16098948Sobrien* Copying::			GNU General Public License says
16198948Sobrien                                how you can copy and share GDB
16298948Sobrien* GNU Free Documentation License::  The license for this documentation
16346289Sdfr* Index::                       Index
16498948Sobrien@end menu
16546289Sdfr
16698948Sobrien@end ifnottex
16746289Sdfr
16898948Sobrien@contents
16946289Sdfr
17098948Sobrien@node Summary
17119370Spst@unnumbered Summary of @value{GDBN}
17219370Spst
17319370SpstThe purpose of a debugger such as @value{GDBN} is to allow you to see what is
17419370Spstgoing on ``inside'' another program while it executes---or what another
17519370Spstprogram was doing at the moment it crashed.
17619370Spst
17719370Spst@value{GDBN} can do four main kinds of things (plus other things in support of
17819370Spstthese) to help you catch bugs in the act:
17919370Spst
18019370Spst@itemize @bullet
18119370Spst@item
18219370SpstStart your program, specifying anything that might affect its behavior.
18319370Spst
18419370Spst@item
18519370SpstMake your program stop on specified conditions.
18619370Spst
18719370Spst@item
18819370SpstExamine what has happened, when your program has stopped.
18919370Spst
19019370Spst@item
19119370SpstChange things in your program, so you can experiment with correcting the
19219370Spsteffects of one bug and go on to learn about another.
19319370Spst@end itemize
19419370Spst
195130809SmarcelYou can use @value{GDBN} to debug programs written in C and C@t{++}.
19619370SpstFor more information, see @ref{Support,,Supported languages}.
19719370SpstFor more information, see @ref{C,,C and C++}.
19819370Spst
19998948Sobrien@cindex Modula-2
200130809SmarcelSupport for Modula-2 is partial.  For information on Modula-2, see
201130809Smarcel@ref{Modula-2,,Modula-2}.
20219370Spst
20398948Sobrien@cindex Pascal
20498948SobrienDebugging Pascal programs which use sets, subranges, file variables, or
20598948Sobriennested functions does not currently work.  @value{GDBN} does not support
20698948Sobrienentering expressions, printing values, or similar features using Pascal
20798948Sobriensyntax.
20819370Spst
20919370Spst@cindex Fortran
21019370Spst@value{GDBN} can be used to debug programs written in Fortran, although
21198948Sobrienit may be necessary to refer to some variables with a trailing
21298948Sobrienunderscore.
21319370Spst
214130809Smarcel@value{GDBN} can be used to debug programs written in Objective-C,
215130809Smarcelusing either the Apple/NeXT or the GNU Objective-C runtime.
216130809Smarcel
21719370Spst@menu
21819370Spst* Free Software::               Freely redistributable software
21919370Spst* Contributors::                Contributors to GDB
22019370Spst@end menu
22119370Spst
22298948Sobrien@node Free Software
22319370Spst@unnumberedsec Free software
22419370Spst
22598948Sobrien@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
22619370SpstGeneral Public License
22719370Spst(GPL).  The GPL gives you the freedom to copy or adapt a licensed
22819370Spstprogram---but every person getting a copy also gets with it the
22919370Spstfreedom to modify that copy (which means that they must get access to
23019370Spstthe source code), and the freedom to distribute further copies.
23119370SpstTypical software companies use copyrights to limit your freedoms; the
23219370SpstFree Software Foundation uses the GPL to preserve these freedoms.
23319370Spst
23419370SpstFundamentally, the General Public License is a license which says that
23519370Spstyou have these freedoms and that you cannot take these freedoms away
23619370Spstfrom anyone else.
23719370Spst
23898948Sobrien@unnumberedsec Free Software Needs Free Documentation
23919370Spst
24098948SobrienThe biggest deficiency in the free software community today is not in
24198948Sobrienthe software---it is the lack of good free documentation that we can
24298948Sobrieninclude with the free software.  Many of our most important
24398948Sobrienprograms do not come with free reference manuals and free introductory
24498948Sobrientexts.  Documentation is an essential part of any software package;
24598948Sobrienwhen an important free software package does not come with a free
24698948Sobrienmanual and a free tutorial, that is a major gap.  We have many such
24798948Sobriengaps today.
24898948Sobrien
24998948SobrienConsider Perl, for instance.  The tutorial manuals that people
25098948Sobriennormally use are non-free.  How did this come about?  Because the
25198948Sobrienauthors of those manuals published them with restrictive terms---no
25298948Sobriencopying, no modification, source files not available---which exclude
25398948Sobrienthem from the free software world.
25498948Sobrien
25598948SobrienThat wasn't the first time this sort of thing happened, and it was far
25698948Sobrienfrom the last.  Many times we have heard a GNU user eagerly describe a
25798948Sobrienmanual that he is writing, his intended contribution to the community,
25898948Sobrienonly to learn that he had ruined everything by signing a publication
25998948Sobriencontract to make it non-free.
26098948Sobrien
26198948SobrienFree documentation, like free software, is a matter of freedom, not
26298948Sobrienprice.  The problem with the non-free manual is not that publishers
26398948Sobriencharge a price for printed copies---that in itself is fine.  (The Free
26498948SobrienSoftware Foundation sells printed copies of manuals, too.)  The
26598948Sobrienproblem is the restrictions on the use of the manual.  Free manuals
26698948Sobrienare available in source code form, and give you permission to copy and
26798948Sobrienmodify.  Non-free manuals do not allow this.
26898948Sobrien
26998948SobrienThe criteria of freedom for a free manual are roughly the same as for
27098948Sobrienfree software.  Redistribution (including the normal kinds of
27198948Sobriencommercial redistribution) must be permitted, so that the manual can
27298948Sobrienaccompany every copy of the program, both on-line and on paper.
27398948Sobrien
27498948SobrienPermission for modification of the technical content is crucial too.
27598948SobrienWhen people modify the software, adding or changing features, if they
27698948Sobrienare conscientious they will change the manual too---so they can
27798948Sobrienprovide accurate and clear documentation for the modified program.  A
27898948Sobrienmanual that leaves you no choice but to write a new manual to document
27998948Sobriena changed version of the program is not really available to our
28098948Sobriencommunity.
28198948Sobrien
28298948SobrienSome kinds of limits on the way modification is handled are
28398948Sobrienacceptable.  For example, requirements to preserve the original
28498948Sobrienauthor's copyright notice, the distribution terms, or the list of
28598948Sobrienauthors, are ok.  It is also no problem to require modified versions
28698948Sobriento include notice that they were modified.  Even entire sections that
28798948Sobrienmay not be deleted or changed are acceptable, as long as they deal
28898948Sobrienwith nontechnical topics (like this one).  These kinds of restrictions
28998948Sobrienare acceptable because they don't obstruct the community's normal use
29098948Sobrienof the manual.
29198948Sobrien
29298948SobrienHowever, it must be possible to modify all the @emph{technical}
29398948Sobriencontent of the manual, and then distribute the result in all the usual
29498948Sobrienmedia, through all the usual channels.  Otherwise, the restrictions
29598948Sobrienobstruct the use of the manual, it is not free, and we need another
29698948Sobrienmanual to replace it.
29798948Sobrien
29898948SobrienPlease spread the word about this issue.  Our community continues to
29998948Sobrienlose manuals to proprietary publishing.  If we spread the word that
30098948Sobrienfree software needs free reference manuals and free tutorials, perhaps
30198948Sobrienthe next person who wants to contribute by writing documentation will
30298948Sobrienrealize, before it is too late, that only free manuals contribute to
30398948Sobrienthe free software community.
30498948Sobrien
30598948SobrienIf you are writing documentation, please insist on publishing it under
30698948Sobrienthe GNU Free Documentation License or another free documentation
30798948Sobrienlicense.  Remember that this decision requires your approval---you
30898948Sobriendon't have to let the publisher decide.  Some commercial publishers
30998948Sobrienwill use a free license if you insist, but they will not propose the
31098948Sobrienoption; it is up to you to raise the issue and say firmly that this is
31198948Sobrienwhat you want.  If the publisher you are dealing with refuses, please
31298948Sobrientry other publishers.  If you're not sure whether a proposed license
31398948Sobrienis free, write to @email{licensing@@gnu.org}.
31498948Sobrien
31598948SobrienYou can encourage commercial publishers to sell more free, copylefted
31698948Sobrienmanuals and tutorials by buying them, and particularly by buying
31798948Sobriencopies from the publishers that paid for their writing or for major
31898948Sobrienimprovements.  Meanwhile, try to avoid buying non-free documentation
31998948Sobrienat all.  Check the distribution terms of a manual before you buy it,
32098948Sobrienand insist that whoever seeks your business must respect your freedom.
32198948SobrienCheck the history of the book, and try to reward the publishers that
32298948Sobrienhave paid or pay the authors to work on it.
32398948Sobrien
32498948SobrienThe Free Software Foundation maintains a list of free documentation
32598948Sobrienpublished by other publishers, at
32698948Sobrien@url{http://www.fsf.org/doc/other-free-books.html}.
32798948Sobrien
32898948Sobrien@node Contributors
32998948Sobrien@unnumberedsec Contributors to @value{GDBN}
33098948Sobrien
33198948SobrienRichard Stallman was the original author of @value{GDBN}, and of many
33298948Sobrienother @sc{gnu} programs.  Many others have contributed to its
33398948Sobriendevelopment.  This section attempts to credit major contributors.  One
33498948Sobrienof the virtues of free software is that everyone is free to contribute
33598948Sobriento it; with regret, we cannot actually acknowledge everyone here.  The
33698948Sobrienfile @file{ChangeLog} in the @value{GDBN} distribution approximates a
33746289Sdfrblow-by-blow account.
33819370Spst
33919370SpstChanges much prior to version 2.0 are lost in the mists of time.
34019370Spst
34119370Spst@quotation
34219370Spst@emph{Plea:} Additions to this section are particularly welcome.  If you
34319370Spstor your friends (or enemies, to be evenhanded) have been unfairly
34419370Spstomitted from this list, we would like to add your names!
34519370Spst@end quotation
34619370Spst
34746289SdfrSo that they may not regard their many labors as thankless, we
34846289Sdfrparticularly thank those who shepherded @value{GDBN} through major
34946289Sdfrreleases:
350130809SmarcelAndrew Cagney (releases 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
35146289SdfrJim Blandy (release 4.18);
35246289SdfrJason Molenda (release 4.17);
35346289SdfrStan Shebs (release 4.14);
35446289SdfrFred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
35546289SdfrStu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
35619370SpstJohn Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
35719370SpstJim Kingdon (releases 3.5, 3.4, and 3.3);
35819370Spstand Randy Smith (releases 3.2, 3.1, and 3.0).
35919370Spst
36019370SpstRichard Stallman, assisted at various times by Peter TerMaat, Chris
36119370SpstHanson, and Richard Mlynarik, handled releases through 2.8.
36219370Spst
36398948SobrienMichael Tiemann is the author of most of the @sc{gnu} C@t{++} support
36498948Sobrienin @value{GDBN}, with significant additional contributions from Per
36598948SobrienBothner and Daniel Berlin.  James Clark wrote the @sc{gnu} C@t{++}
36698948Sobriendemangler.  Early work on C@t{++} was by Peter TerMaat (who also did
36798948Sobrienmuch general update work leading to release 3.0).
36819370Spst
36998948Sobrien@value{GDBN} uses the BFD subroutine library to examine multiple
37019370Spstobject-file formats; BFD was a joint project of David V.
37119370SpstHenkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
37219370Spst
37319370SpstDavid Johnson wrote the original COFF support; Pace Willison did
37419370Spstthe original support for encapsulated COFF.
37519370Spst
376130809SmarcelBrent Benson of Harris Computer Systems contributed DWARF 2 support.
37746289Sdfr
37819370SpstAdam de Boor and Bradley Davis contributed the ISI Optimum V support.
37919370SpstPer Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
38019370Spstsupport.
38119370SpstJean-Daniel Fekete contributed Sun 386i support.
38219370SpstChris Hanson improved the HP9000 support.
38319370SpstNoboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
38419370SpstDavid Johnson contributed Encore Umax support.
38519370SpstJyrki Kuoppala contributed Altos 3068 support.
38619370SpstJeff Law contributed HP PA and SOM support.
38719370SpstKeith Packard contributed NS32K support.
38819370SpstDoug Rabson contributed Acorn Risc Machine support.
38919370SpstBob Rusk contributed Harris Nighthawk CX-UX support.
39019370SpstChris Smith contributed Convex support (and Fortran debugging).
39119370SpstJonathan Stone contributed Pyramid support.
39219370SpstMichael Tiemann contributed SPARC support.
39319370SpstTim Tucker contributed support for the Gould NP1 and Gould Powernode.
39419370SpstPace Willison contributed Intel 386 support.
39519370SpstJay Vosburgh contributed Symmetry support.
396130809SmarcelMarko Mlinar contributed OpenRISC 1000 support.
39719370Spst
398130809SmarcelAndreas Schwab contributed M68K @sc{gnu}/Linux support.
39946289Sdfr
40019370SpstRich Schaefer and Peter Schauer helped with support of SunOS shared
40119370Spstlibraries.
40219370Spst
40346289SdfrJay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
40446289Sdfrabout several machine instruction sets.
40519370Spst
40646289SdfrPatrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
40746289Sdfrremote debugging.  Intel Corporation, Wind River Systems, AMD, and ARM
40846289Sdfrcontributed remote debugging modules for the i960, VxWorks, A29K UDI,
40946289Sdfrand RDI targets, respectively.
41019370Spst
41119370SpstBrian Fox is the author of the readline libraries providing
41219370Spstcommand-line editing and command history.
41319370Spst
41498948SobrienAndrew Beers of SUNY Buffalo wrote the language-switching code, the
41598948SobrienModula-2 support, and contributed the Languages chapter of this manual.
41619370Spst
41798948SobrienFred Fish wrote most of the support for Unix System Vr4.
41898948SobrienHe also enhanced the command-completion support to cover C@t{++} overloaded
41919370Spstsymbols.
42019370Spst
421130809SmarcelHitachi America (now Renesas America), Ltd. sponsored the support for
422130809SmarcelH8/300, H8/500, and Super-H processors.
42319370Spst
42446289SdfrNEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
42546289Sdfr
426130809SmarcelMitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
427130809Smarcelprocessors.
42846289Sdfr
42946289SdfrToshiba sponsored the support for the TX39 Mips processor.
43046289Sdfr
43146289SdfrMatsushita sponsored the support for the MN10200 and MN10300 processors.
43246289Sdfr
43398948SobrienFujitsu sponsored the support for SPARClite and FR30 processors.
43446289Sdfr
43519370SpstKung Hsu, Jeff Law, and Rick Sladkey added support for hardware
43619370Spstwatchpoints.
43719370Spst
43846289SdfrMichael Snyder added support for tracepoints.
43946289Sdfr
44019370SpstStu Grossman wrote gdbserver.
44119370Spst
44219370SpstJim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
44398948Sobriennearly innumerable bug fixes and cleanups throughout @value{GDBN}.
44419370Spst
44546289SdfrThe following people at the Hewlett-Packard Company contributed
44646289Sdfrsupport for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
44798948Sobrien(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
448130809Smarcelcompiler, and the Text User Interface (nee Terminal User Interface):
449130809SmarcelBen Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
450130809SmarcelSatish Pai, India Paul, Steve Rehrauer, and Elena Zannoni.  Kim Haase
451130809Smarcelprovided HP-specific information in this manual.
45246289Sdfr
45398948SobrienDJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
45498948SobrienRobert Hoehne made significant contributions to the DJGPP port.
45546289Sdfr
45698948SobrienCygnus Solutions has sponsored @value{GDBN} maintenance and much of its
45798948Sobriendevelopment since 1991.  Cygnus engineers who have worked on @value{GDBN}
45898948Sobrienfulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
45998948SobrienBuettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
46098948SobrienIngham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
46198948SobrienFernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
46298948SobrienRadouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni.  In
46398948Sobrienaddition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
46498948SobrienJT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
46598948SobrienEvans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
46698948SobrienHolcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
46798948SobrienJason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
46898948SobrienRomig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
46998948SobrienThomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
47098948SobrienZuhn have made contributions both large and small.
47146289Sdfr
472130809SmarcelJim Blandy added support for preprocessor macros, while working for Red
473130809SmarcelHat.
47498948Sobrien
47598948Sobrien@node Sample Session
47619370Spst@chapter A Sample @value{GDBN} Session
47719370Spst
47819370SpstYou can use this manual at your leisure to read all about @value{GDBN}.
47919370SpstHowever, a handful of commands are enough to get started using the
48019370Spstdebugger.  This chapter illustrates those commands.
48119370Spst
48219370Spst@iftex
48319370SpstIn this sample session, we emphasize user input like this: @b{input},
48419370Spstto make it easier to pick out from the surrounding output.
48519370Spst@end iftex
48619370Spst
48719370Spst@c FIXME: this example may not be appropriate for some configs, where
48819370Spst@c FIXME...primary interest is in remote use.
48919370Spst
49019370SpstOne of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
49119370Spstprocessor) exhibits the following bug: sometimes, when we change its
49219370Spstquote strings from the default, the commands used to capture one macro
49319370Spstdefinition within another stop working.  In the following short @code{m4}
49419370Spstsession, we define a macro @code{foo} which expands to @code{0000}; we
49519370Spstthen use the @code{m4} built-in @code{defn} to define @code{bar} as the
49619370Spstsame thing.  However, when we change the open quote string to
49719370Spst@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
49819370Spstprocedure fails to define a new synonym @code{baz}:
49919370Spst
50019370Spst@smallexample
50119370Spst$ @b{cd gnu/m4}
50219370Spst$ @b{./m4}
50319370Spst@b{define(foo,0000)}
50419370Spst
50519370Spst@b{foo}
50619370Spst0000
50719370Spst@b{define(bar,defn(`foo'))}
50819370Spst
50919370Spst@b{bar}
51019370Spst0000
51119370Spst@b{changequote(<QUOTE>,<UNQUOTE>)}
51219370Spst
51319370Spst@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
51419370Spst@b{baz}
51519370Spst@b{C-d}
51619370Spstm4: End of input: 0: fatal error: EOF in string
51719370Spst@end smallexample
51819370Spst
51919370Spst@noindent
52019370SpstLet us use @value{GDBN} to try to see what is going on.
52119370Spst
52219370Spst@smallexample
52319370Spst$ @b{@value{GDBP} m4}
52419370Spst@c FIXME: this falsifies the exact text played out, to permit smallbook
52519370Spst@c FIXME... format to come out better.
52619370Spst@value{GDBN} is free software and you are welcome to distribute copies
52798948Sobrien of it under certain conditions; type "show copying" to see
52819370Spst the conditions.
52998948SobrienThere is absolutely no warranty for @value{GDBN}; type "show warranty"
53019370Spst for details.
53119370Spst
53246289Sdfr@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
53319370Spst(@value{GDBP})
53419370Spst@end smallexample
53519370Spst
53619370Spst@noindent
53719370Spst@value{GDBN} reads only enough symbol data to know where to find the
53819370Spstrest when needed; as a result, the first prompt comes up very quickly.
53919370SpstWe now tell @value{GDBN} to use a narrower display width than usual, so
54019370Spstthat examples fit in this manual.
54119370Spst
54219370Spst@smallexample
54319370Spst(@value{GDBP}) @b{set width 70}
54419370Spst@end smallexample
54519370Spst
54619370Spst@noindent
54719370SpstWe need to see how the @code{m4} built-in @code{changequote} works.
54819370SpstHaving looked at the source, we know the relevant subroutine is
54919370Spst@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
55019370Spst@code{break} command.
55119370Spst
55219370Spst@smallexample
55319370Spst(@value{GDBP}) @b{break m4_changequote}
55419370SpstBreakpoint 1 at 0x62f4: file builtin.c, line 879.
55519370Spst@end smallexample
55619370Spst
55719370Spst@noindent
55819370SpstUsing the @code{run} command, we start @code{m4} running under @value{GDBN}
55919370Spstcontrol; as long as control does not reach the @code{m4_changequote}
56019370Spstsubroutine, the program runs as usual:
56119370Spst
56219370Spst@smallexample
56319370Spst(@value{GDBP}) @b{run}
56419370SpstStarting program: /work/Editorial/gdb/gnu/m4/m4
56519370Spst@b{define(foo,0000)}
56619370Spst
56719370Spst@b{foo}
56819370Spst0000
56919370Spst@end smallexample
57019370Spst
57119370Spst@noindent
57219370SpstTo trigger the breakpoint, we call @code{changequote}.  @value{GDBN}
57319370Spstsuspends execution of @code{m4}, displaying information about the
57419370Spstcontext where it stops.
57519370Spst
57619370Spst@smallexample
57719370Spst@b{changequote(<QUOTE>,<UNQUOTE>)}
57819370Spst
57998948SobrienBreakpoint 1, m4_changequote (argc=3, argv=0x33c70)
58019370Spst    at builtin.c:879
58119370Spst879         if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
58219370Spst@end smallexample
58319370Spst
58419370Spst@noindent
58519370SpstNow we use the command @code{n} (@code{next}) to advance execution to
58619370Spstthe next line of the current function.
58719370Spst
58819370Spst@smallexample
58919370Spst(@value{GDBP}) @b{n}
59019370Spst882         set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
59119370Spst : nil,
59219370Spst@end smallexample
59319370Spst
59419370Spst@noindent
59519370Spst@code{set_quotes} looks like a promising subroutine.  We can go into it
59619370Spstby using the command @code{s} (@code{step}) instead of @code{next}.
59719370Spst@code{step} goes to the next line to be executed in @emph{any}
59819370Spstsubroutine, so it steps into @code{set_quotes}.
59919370Spst
60019370Spst@smallexample
60119370Spst(@value{GDBP}) @b{s}
60219370Spstset_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
60319370Spst    at input.c:530
60419370Spst530         if (lquote != def_lquote)
60519370Spst@end smallexample
60619370Spst
60719370Spst@noindent
60819370SpstThe display that shows the subroutine where @code{m4} is now
60919370Spstsuspended (and its arguments) is called a stack frame display.  It
61019370Spstshows a summary of the stack.  We can use the @code{backtrace}
61119370Spstcommand (which can also be spelled @code{bt}), to see where we are
61219370Spstin the stack as a whole: the @code{backtrace} command displays a
61319370Spststack frame for each active subroutine.
61419370Spst
61519370Spst@smallexample
61619370Spst(@value{GDBP}) @b{bt}
61719370Spst#0  set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
61819370Spst    at input.c:530
61998948Sobrien#1  0x6344 in m4_changequote (argc=3, argv=0x33c70)
62019370Spst    at builtin.c:882
62119370Spst#2  0x8174 in expand_macro (sym=0x33320) at macro.c:242
62219370Spst#3  0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
62319370Spst    at macro.c:71
62419370Spst#4  0x79dc in expand_input () at macro.c:40
62519370Spst#5  0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
62619370Spst@end smallexample
62719370Spst
62819370Spst@noindent
62919370SpstWe step through a few more lines to see what happens.  The first two
63019370Spsttimes, we can use @samp{s}; the next two times we use @code{n} to avoid
63119370Spstfalling into the @code{xstrdup} subroutine.
63219370Spst
63319370Spst@smallexample
63419370Spst(@value{GDBP}) @b{s}
63519370Spst0x3b5c  532         if (rquote != def_rquote)
63619370Spst(@value{GDBP}) @b{s}
63719370Spst0x3b80  535         lquote = (lq == nil || *lq == '\0') ?  \
63819370Spstdef_lquote : xstrdup(lq);
63919370Spst(@value{GDBP}) @b{n}
64019370Spst536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
64119370Spst : xstrdup(rq);
64219370Spst(@value{GDBP}) @b{n}
64319370Spst538         len_lquote = strlen(rquote);
64419370Spst@end smallexample
64519370Spst
64619370Spst@noindent
64719370SpstThe last line displayed looks a little odd; we can examine the variables
64819370Spst@code{lquote} and @code{rquote} to see if they are in fact the new left
64919370Spstand right quotes we specified.  We use the command @code{p}
65019370Spst(@code{print}) to see their values.
65119370Spst
65219370Spst@smallexample
65319370Spst(@value{GDBP}) @b{p lquote}
65419370Spst$1 = 0x35d40 "<QUOTE>"
65519370Spst(@value{GDBP}) @b{p rquote}
65619370Spst$2 = 0x35d50 "<UNQUOTE>"
65719370Spst@end smallexample
65819370Spst
65919370Spst@noindent
66019370Spst@code{lquote} and @code{rquote} are indeed the new left and right quotes.
66119370SpstTo look at some context, we can display ten lines of source
66219370Spstsurrounding the current line with the @code{l} (@code{list}) command.
66319370Spst
66419370Spst@smallexample
66519370Spst(@value{GDBP}) @b{l}
66619370Spst533             xfree(rquote);
66719370Spst534
66819370Spst535         lquote = (lq == nil || *lq == '\0') ? def_lquote\
66919370Spst : xstrdup (lq);
67019370Spst536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
67119370Spst : xstrdup (rq);
67219370Spst537
67319370Spst538         len_lquote = strlen(rquote);
67419370Spst539         len_rquote = strlen(lquote);
67519370Spst540     @}
67619370Spst541
67719370Spst542     void
67819370Spst@end smallexample
67919370Spst
68019370Spst@noindent
68119370SpstLet us step past the two lines that set @code{len_lquote} and
68219370Spst@code{len_rquote}, and then examine the values of those variables.
68319370Spst
68419370Spst@smallexample
68519370Spst(@value{GDBP}) @b{n}
68619370Spst539         len_rquote = strlen(lquote);
68719370Spst(@value{GDBP}) @b{n}
68819370Spst540     @}
68919370Spst(@value{GDBP}) @b{p len_lquote}
69019370Spst$3 = 9
69119370Spst(@value{GDBP}) @b{p len_rquote}
69219370Spst$4 = 7
69319370Spst@end smallexample
69419370Spst
69519370Spst@noindent
69619370SpstThat certainly looks wrong, assuming @code{len_lquote} and
69719370Spst@code{len_rquote} are meant to be the lengths of @code{lquote} and
69819370Spst@code{rquote} respectively.  We can set them to better values using
69919370Spstthe @code{p} command, since it can print the value of
70019370Spstany expression---and that expression can include subroutine calls and
70119370Spstassignments.
70219370Spst
70319370Spst@smallexample
70419370Spst(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
70519370Spst$5 = 7
70619370Spst(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
70719370Spst$6 = 9
70819370Spst@end smallexample
70919370Spst
71019370Spst@noindent
71119370SpstIs that enough to fix the problem of using the new quotes with the
71219370Spst@code{m4} built-in @code{defn}?  We can allow @code{m4} to continue
71319370Spstexecuting with the @code{c} (@code{continue}) command, and then try the
71419370Spstexample that caused trouble initially:
71519370Spst
71619370Spst@smallexample
71719370Spst(@value{GDBP}) @b{c}
71819370SpstContinuing.
71919370Spst
72019370Spst@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
72119370Spst
72219370Spstbaz
72319370Spst0000
72419370Spst@end smallexample
72519370Spst
72619370Spst@noindent
72719370SpstSuccess!  The new quotes now work just as well as the default ones.  The
72819370Spstproblem seems to have been just the two typos defining the wrong
72919370Spstlengths.  We allow @code{m4} exit by giving it an EOF as input:
73019370Spst
73119370Spst@smallexample
73219370Spst@b{C-d}
73319370SpstProgram exited normally.
73419370Spst@end smallexample
73519370Spst
73619370Spst@noindent
73719370SpstThe message @samp{Program exited normally.} is from @value{GDBN}; it
73819370Spstindicates @code{m4} has finished executing.  We can end our @value{GDBN}
73919370Spstsession with the @value{GDBN} @code{quit} command.
74019370Spst
74119370Spst@smallexample
74219370Spst(@value{GDBP}) @b{quit}
74319370Spst@end smallexample
74419370Spst
74598948Sobrien@node Invocation
74619370Spst@chapter Getting In and Out of @value{GDBN}
74719370Spst
74819370SpstThis chapter discusses how to start @value{GDBN}, and how to get out of it.
74998948SobrienThe essentials are:
75019370Spst@itemize @bullet
75198948Sobrien@item
75298948Sobrientype @samp{@value{GDBP}} to start @value{GDBN}.
75398948Sobrien@item
75419370Spsttype @kbd{quit} or @kbd{C-d} to exit.
75519370Spst@end itemize
75619370Spst
75719370Spst@menu
75819370Spst* Invoking GDB::                How to start @value{GDBN}
75946289Sdfr* Quitting GDB::                How to quit @value{GDBN}
76019370Spst* Shell Commands::              How to use shell commands inside @value{GDBN}
761130809Smarcel* Logging output::              How to log @value{GDBN}'s output to a file
76219370Spst@end menu
76319370Spst
76498948Sobrien@node Invoking GDB
76519370Spst@section Invoking @value{GDBN}
76619370Spst
76719370SpstInvoke @value{GDBN} by running the program @code{@value{GDBP}}.  Once started,
76819370Spst@value{GDBN} reads commands from the terminal until you tell it to exit.
76919370Spst
77019370SpstYou can also run @code{@value{GDBP}} with a variety of arguments and options,
77119370Spstto specify more of your debugging environment at the outset.
77219370Spst
77319370SpstThe command-line options described here are designed
77419370Spstto cover a variety of situations; in some environments, some of these
77598948Sobrienoptions may effectively be unavailable.
77619370Spst
77719370SpstThe most usual way to start @value{GDBN} is with one argument,
77819370Spstspecifying an executable program:
77919370Spst
780130809Smarcel@smallexample
78119370Spst@value{GDBP} @var{program}
782130809Smarcel@end smallexample
78319370Spst
78419370Spst@noindent
78519370SpstYou can also start with both an executable program and a core file
78619370Spstspecified:
78719370Spst
788130809Smarcel@smallexample
78919370Spst@value{GDBP} @var{program} @var{core}
790130809Smarcel@end smallexample
79119370Spst
79219370SpstYou can, instead, specify a process ID as a second argument, if you want
79319370Spstto debug a running process:
79419370Spst
795130809Smarcel@smallexample
79619370Spst@value{GDBP} @var{program} 1234
797130809Smarcel@end smallexample
79819370Spst
79919370Spst@noindent
80019370Spstwould attach @value{GDBN} to process @code{1234} (unless you also have a file
80119370Spstnamed @file{1234}; @value{GDBN} does check for a core file first).
80219370Spst
80319370SpstTaking advantage of the second command-line argument requires a fairly
80498948Sobriencomplete operating system; when you use @value{GDBN} as a remote
80598948Sobriendebugger attached to a bare board, there may not be any notion of
80698948Sobrien``process'', and there is often no way to get a core dump.  @value{GDBN}
80798948Sobrienwill warn you if it is unable to attach or to read core dumps.
80819370Spst
80998948SobrienYou can optionally have @code{@value{GDBP}} pass any arguments after the
81098948Sobrienexecutable file to the inferior using @code{--args}.  This option stops
81198948Sobrienoption processing.
812130809Smarcel@smallexample
81398948Sobriengdb --args gcc -O2 -c foo.c
814130809Smarcel@end smallexample
81598948SobrienThis will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
81698948Sobrien@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
81798948Sobrien
81898948SobrienYou can run @code{@value{GDBP}} without printing the front material, which describes
81919370Spst@value{GDBN}'s non-warranty, by specifying @code{-silent}:
82019370Spst
82119370Spst@smallexample
82246289Sdfr@value{GDBP} -silent
82319370Spst@end smallexample
82419370Spst
82519370Spst@noindent
82619370SpstYou can further control how @value{GDBN} starts up by using command-line
82719370Spstoptions.  @value{GDBN} itself can remind you of the options available.
82819370Spst
82919370Spst@noindent
83019370SpstType
83119370Spst
832130809Smarcel@smallexample
83319370Spst@value{GDBP} -help
834130809Smarcel@end smallexample
83519370Spst
83619370Spst@noindent
83719370Spstto display all available options and briefly describe their use
83819370Spst(@samp{@value{GDBP} -h} is a shorter equivalent).
83919370Spst
84019370SpstAll options and command line arguments you give are processed
84119370Spstin sequential order.  The order makes a difference when the
84219370Spst@samp{-x} option is used.
84319370Spst
84419370Spst
84519370Spst@menu
84619370Spst* File Options::                Choosing files
84719370Spst* Mode Options::                Choosing modes
84819370Spst@end menu
84919370Spst
85019370Spst@node File Options
85119370Spst@subsection Choosing files
85219370Spst
85319370SpstWhen @value{GDBN} starts, it reads any arguments other than options as
85419370Spstspecifying an executable file and core file (or process ID).  This is
85519370Spstthe same as if the arguments were specified by the @samp{-se} and
85698948Sobrien@samp{-c} (or @samp{-p} options respectively.  (@value{GDBN} reads the
85798948Sobrienfirst argument that does not have an associated option flag as
85898948Sobrienequivalent to the @samp{-se} option followed by that argument; and the
85998948Sobriensecond argument that does not have an associated option flag, if any, as
86098948Sobrienequivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
86198948SobrienIf the second argument begins with a decimal digit, @value{GDBN} will
86298948Sobrienfirst attempt to attach to it as a process, and if that fails, attempt
86398948Sobriento open it as a corefile.  If you have a corefile whose name begins with
864130809Smarcela digit, you can prevent @value{GDBN} from treating it as a pid by
86598948Sobrienprefixing it with @file{./}, eg. @file{./12345}.
86619370Spst
86798948SobrienIf @value{GDBN} has not been configured to included core file support,
86898948Sobriensuch as for most embedded targets, then it will complain about a second
86998948Sobrienargument and ignore it.
87098948Sobrien
87119370SpstMany options have both long and short forms; both are shown in the
87219370Spstfollowing list.  @value{GDBN} also recognizes the long forms if you truncate
87319370Spstthem, so long as enough of the option is present to be unambiguous.
87419370Spst(If you prefer, you can flag option arguments with @samp{--} rather
87519370Spstthan @samp{-}, though we illustrate the more usual convention.)
87619370Spst
87798948Sobrien@c NOTE: the @cindex entries here use double dashes ON PURPOSE.  This
87898948Sobrien@c way, both those who look for -foo and --foo in the index, will find
87998948Sobrien@c it.
88098948Sobrien
88119370Spst@table @code
88219370Spst@item -symbols @var{file}
88319370Spst@itemx -s @var{file}
88498948Sobrien@cindex @code{--symbols}
88598948Sobrien@cindex @code{-s}
88619370SpstRead symbol table from file @var{file}.
88719370Spst
88819370Spst@item -exec @var{file}
88919370Spst@itemx -e @var{file}
89098948Sobrien@cindex @code{--exec}
89198948Sobrien@cindex @code{-e}
89298948SobrienUse file @var{file} as the executable file to execute when appropriate,
89398948Sobrienand for examining pure data in conjunction with a core dump.
89419370Spst
89519370Spst@item -se @var{file}
89698948Sobrien@cindex @code{--se}
89719370SpstRead symbol table from file @var{file} and use it as the executable
89819370Spstfile.
89919370Spst
90019370Spst@item -core @var{file}
90119370Spst@itemx -c @var{file}
90298948Sobrien@cindex @code{--core}
90398948Sobrien@cindex @code{-c}
904130809SmarcelUse file @var{file} as a core dump to examine.
90519370Spst
90619370Spst@item -c @var{number}
90798948Sobrien@item -pid @var{number}
90898948Sobrien@itemx -p @var{number}
90998948Sobrien@cindex @code{--pid}
91098948Sobrien@cindex @code{-p}
91198948SobrienConnect to process ID @var{number}, as with the @code{attach} command.
91298948SobrienIf there is no such process, @value{GDBN} will attempt to open a core
91398948Sobrienfile named @var{number}.
91419370Spst
91519370Spst@item -command @var{file}
91619370Spst@itemx -x @var{file}
91798948Sobrien@cindex @code{--command}
91898948Sobrien@cindex @code{-x}
91919370SpstExecute @value{GDBN} commands from file @var{file}.  @xref{Command
92019370SpstFiles,, Command files}.
92119370Spst
92219370Spst@item -directory @var{directory}
92319370Spst@itemx -d @var{directory}
92498948Sobrien@cindex @code{--directory}
92598948Sobrien@cindex @code{-d}
92619370SpstAdd @var{directory} to the path to search for source files.
92719370Spst
92819370Spst@item -m
92919370Spst@itemx -mapped
93098948Sobrien@cindex @code{--mapped}
93198948Sobrien@cindex @code{-m}
93219370Spst@emph{Warning: this option depends on operating system facilities that are not
93319370Spstsupported on all systems.}@*
93419370SpstIf memory-mapped files are available on your system through the @code{mmap}
93598948Sobriensystem call, you can use this option
93619370Spstto have @value{GDBN} write the symbols from your
93719370Spstprogram into a reusable file in the current directory.  If the program you are debugging is
93898948Sobriencalled @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
93919370SpstFuture @value{GDBN} debugging sessions notice the presence of this file,
94019370Spstand can quickly map in symbol information from it, rather than reading
94119370Spstthe symbol table from the executable program.
94219370Spst
94319370SpstThe @file{.syms} file is specific to the host machine where @value{GDBN}
94419370Spstis run.  It holds an exact image of the internal @value{GDBN} symbol
94519370Spsttable.  It cannot be shared across multiple host platforms.
94619370Spst
94719370Spst@item -r
94819370Spst@itemx -readnow
94998948Sobrien@cindex @code{--readnow}
95098948Sobrien@cindex @code{-r}
95119370SpstRead each symbol file's entire symbol table immediately, rather than
95219370Spstthe default, which is to read it incrementally as it is needed.
95319370SpstThis makes startup slower, but makes future operations faster.
95498948Sobrien
95519370Spst@end table
95619370Spst
95798948SobrienYou typically combine the @code{-mapped} and @code{-readnow} options in
95819370Spstorder to build a @file{.syms} file that contains complete symbol
95998948Sobrieninformation.  (@xref{Files,,Commands to specify files}, for information
96098948Sobrienon @file{.syms} files.)  A simple @value{GDBN} invocation to do nothing
96198948Sobrienbut build a @file{.syms} file for future use is:
96219370Spst
963130809Smarcel@smallexample
96498948Sobriengdb -batch -nx -mapped -readnow programname
965130809Smarcel@end smallexample
96619370Spst
96798948Sobrien@node Mode Options
96819370Spst@subsection Choosing modes
96919370Spst
97019370SpstYou can run @value{GDBN} in various alternative modes---for example, in
97119370Spstbatch mode or quiet mode.
97219370Spst
97319370Spst@table @code
97419370Spst@item -nx
97519370Spst@itemx -n
97698948Sobrien@cindex @code{--nx}
97798948Sobrien@cindex @code{-n}
97898948SobrienDo not execute commands found in any initialization files.  Normally,
97998948Sobrien@value{GDBN} executes the commands in these files after all the command
98098948Sobrienoptions and arguments have been processed.  @xref{Command Files,,Command
98198948Sobrienfiles}.
98219370Spst
98319370Spst@item -quiet
98498948Sobrien@itemx -silent
98519370Spst@itemx -q
98698948Sobrien@cindex @code{--quiet}
98798948Sobrien@cindex @code{--silent}
98898948Sobrien@cindex @code{-q}
98919370Spst``Quiet''.  Do not print the introductory and copyright messages.  These
99019370Spstmessages are also suppressed in batch mode.
99119370Spst
99219370Spst@item -batch
99398948Sobrien@cindex @code{--batch}
99419370SpstRun in batch mode.  Exit with status @code{0} after processing all the
99519370Spstcommand files specified with @samp{-x} (and all commands from
99619370Spstinitialization files, if not inhibited with @samp{-n}).  Exit with
99719370Spstnonzero status if an error occurs in executing the @value{GDBN} commands
99819370Spstin the command files.
99919370Spst
100098948SobrienBatch mode may be useful for running @value{GDBN} as a filter, for
100198948Sobrienexample to download and run a program on another computer; in order to
100298948Sobrienmake this more useful, the message
100319370Spst
1004130809Smarcel@smallexample
100519370SpstProgram exited normally.
1006130809Smarcel@end smallexample
100719370Spst
100819370Spst@noindent
100998948Sobrien(which is ordinarily issued whenever a program running under
101098948Sobrien@value{GDBN} control terminates) is not issued when running in batch
101198948Sobrienmode.
101219370Spst
101398948Sobrien@item -nowindows
101498948Sobrien@itemx -nw
101598948Sobrien@cindex @code{--nowindows}
101698948Sobrien@cindex @code{-nw}
101798948Sobrien``No windows''.  If @value{GDBN} comes with a graphical user interface
101898948Sobrien(GUI) built in, then this option tells @value{GDBN} to only use the command-line
101998948Sobrieninterface.  If no GUI is available, this option has no effect.
102098948Sobrien
102198948Sobrien@item -windows
102298948Sobrien@itemx -w
102398948Sobrien@cindex @code{--windows}
102498948Sobrien@cindex @code{-w}
102598948SobrienIf @value{GDBN} includes a GUI, then this option requires it to be
102698948Sobrienused if possible.
102798948Sobrien
102819370Spst@item -cd @var{directory}
102998948Sobrien@cindex @code{--cd}
103019370SpstRun @value{GDBN} using @var{directory} as its working directory,
103119370Spstinstead of the current directory.
103219370Spst
103319370Spst@item -fullname
103419370Spst@itemx -f
103598948Sobrien@cindex @code{--fullname}
103698948Sobrien@cindex @code{-f}
103798948Sobrien@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
103898948Sobriensubprocess.  It tells @value{GDBN} to output the full file name and line
103998948Sobriennumber in a standard, recognizable fashion each time a stack frame is
104098948Sobriendisplayed (which includes each time your program stops).  This
104198948Sobrienrecognizable format looks like two @samp{\032} characters, followed by
104298948Sobrienthe file name, line number and character position separated by colons,
104398948Sobrienand a newline.  The Emacs-to-@value{GDBN} interface program uses the two
104498948Sobrien@samp{\032} characters as a signal to display the source code for the
104598948Sobrienframe.
104619370Spst
104798948Sobrien@item -epoch
104898948Sobrien@cindex @code{--epoch}
104998948SobrienThe Epoch Emacs-@value{GDBN} interface sets this option when it runs
105098948Sobrien@value{GDBN} as a subprocess.  It tells @value{GDBN} to modify its print
105198948Sobrienroutines so as to allow Epoch to display values of expressions in a
105298948Sobrienseparate window.
105398948Sobrien
105498948Sobrien@item -annotate @var{level}
105598948Sobrien@cindex @code{--annotate}
105698948SobrienThis option sets the @dfn{annotation level} inside @value{GDBN}.  Its
105798948Sobrieneffect is identical to using @samp{set annotate @var{level}}
1058130809Smarcel(@pxref{Annotations}).  The annotation @var{level} controls how much
1059130809Smarcelinformation @value{GDBN} prints together with its prompt, values of
1060130809Smarcelexpressions, source lines, and other types of output.  Level 0 is the
1061130809Smarcelnormal, level 1 is for use when @value{GDBN} is run as a subprocess of
1062130809Smarcel@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1063130809Smarcelthat control @value{GDBN}, and level 2 has been deprecated.
106498948Sobrien
1065130809SmarcelThe annotation mechanism has largely been superseeded by @sc{gdb/mi}
1066130809Smarcel(@pxref{GDB/MI}).
1067130809Smarcel
106898948Sobrien@item -async
106998948Sobrien@cindex @code{--async}
107098948SobrienUse the asynchronous event loop for the command-line interface.
107198948Sobrien@value{GDBN} processes all events, such as user keyboard input, via a
107298948Sobrienspecial event loop.  This allows @value{GDBN} to accept and process user
107398948Sobriencommands in parallel with the debugged process being
107498948Sobrienrun@footnote{@value{GDBN} built with @sc{djgpp} tools for
107598948SobrienMS-DOS/MS-Windows supports this mode of operation, but the event loop is
107698948Sobriensuspended when the debuggee runs.}, so you don't need to wait for
107798948Sobriencontrol to return to @value{GDBN} before you type the next command.
107898948Sobrien(@emph{Note:} as of version 5.1, the target side of the asynchronous
107998948Sobrienoperation is not yet in place, so @samp{-async} does not work fully
108098948Sobrienyet.)
108198948Sobrien@c FIXME: when the target side of the event loop is done, the above NOTE
108298948Sobrien@c should be removed.
108398948Sobrien
108498948SobrienWhen the standard input is connected to a terminal device, @value{GDBN}
108598948Sobrienuses the asynchronous event loop by default, unless disabled by the
108698948Sobrien@samp{-noasync} option.
108798948Sobrien
108898948Sobrien@item -noasync
108998948Sobrien@cindex @code{--noasync}
109098948SobrienDisable the asynchronous event loop for the command-line interface.
109198948Sobrien
109298948Sobrien@item --args
109398948Sobrien@cindex @code{--args}
109498948SobrienChange interpretation of command line so that arguments following the
109598948Sobrienexecutable file are passed as command line arguments to the inferior.
109698948SobrienThis option stops option processing.
109798948Sobrien
109898948Sobrien@item -baud @var{bps}
109998948Sobrien@itemx -b @var{bps}
110098948Sobrien@cindex @code{--baud}
110198948Sobrien@cindex @code{-b}
110219370SpstSet the line speed (baud rate or bits per second) of any serial
110319370Spstinterface used by @value{GDBN} for remote debugging.
110419370Spst
110519370Spst@item -tty @var{device}
110698948Sobrien@itemx -t @var{device}
110798948Sobrien@cindex @code{--tty}
110898948Sobrien@cindex @code{-t}
110919370SpstRun using @var{device} for your program's standard input and output.
111019370Spst@c FIXME: kingdon thinks there is more to -tty.  Investigate.
111146289Sdfr
111298948Sobrien@c resolve the situation of these eventually
111346289Sdfr@item -tui
111498948Sobrien@cindex @code{--tui}
1115130809SmarcelActivate the @dfn{Text User Interface} when starting.  The Text User
1116130809SmarcelInterface manages several text windows on the terminal, showing
1117130809Smarcelsource, assembly, registers and @value{GDBN} command outputs
1118130809Smarcel(@pxref{TUI, ,@value{GDBN} Text User Interface}).  Alternatively, the
1119130809SmarcelText User Interface can be enabled by invoking the program
1120130809Smarcel@samp{gdbtui}.  Do not use this option if you run @value{GDBN} from
1121130809SmarcelEmacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
112246289Sdfr
112398948Sobrien@c @item -xdb
112498948Sobrien@c @cindex @code{--xdb}
112598948Sobrien@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
112698948Sobrien@c For information, see the file @file{xdb_trans.html}, which is usually
112798948Sobrien@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
112898948Sobrien@c systems.
112998948Sobrien
113098948Sobrien@item -interpreter @var{interp}
113198948Sobrien@cindex @code{--interpreter}
113298948SobrienUse the interpreter @var{interp} for interface with the controlling
113398948Sobrienprogram or device.  This option is meant to be set by programs which
113498948Sobriencommunicate with @value{GDBN} using it as a back end.
1135130809Smarcel@xref{Interpreters, , Command Interpreters}.
113698948Sobrien
1137130809Smarcel@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
1138130809Smarcel@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
1139130809SmarcelThe @sc{gdb/mi} Interface}) included since @var{GDBN} version 6.0.  The
1140130809Smarcelprevious @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1141130809Smarcelselected with @samp{--interpreter=mi1}, is deprecated.  Earlier
1142130809Smarcel@sc{gdb/mi} interfaces are no longer supported.
114398948Sobrien
114498948Sobrien@item -write
114598948Sobrien@cindex @code{--write}
114698948SobrienOpen the executable and core files for both reading and writing.  This
114798948Sobrienis equivalent to the @samp{set write on} command inside @value{GDBN}
114898948Sobrien(@pxref{Patching}).
114998948Sobrien
115098948Sobrien@item -statistics
115198948Sobrien@cindex @code{--statistics}
115298948SobrienThis option causes @value{GDBN} to print statistics about time and
115398948Sobrienmemory usage after it completes each command and returns to the prompt.
115498948Sobrien
115598948Sobrien@item -version
115698948Sobrien@cindex @code{--version}
115798948SobrienThis option causes @value{GDBN} to print its version number and
115898948Sobrienno-warranty blurb, and exit.
115998948Sobrien
116019370Spst@end table
116119370Spst
116298948Sobrien@node Quitting GDB
116319370Spst@section Quitting @value{GDBN}
116419370Spst@cindex exiting @value{GDBN}
116519370Spst@cindex leaving @value{GDBN}
116619370Spst
116719370Spst@table @code
116819370Spst@kindex quit @r{[}@var{expression}@r{]}
116998948Sobrien@kindex q @r{(@code{quit})}
117098948Sobrien@item quit @r{[}@var{expression}@r{]}
117198948Sobrien@itemx q
117298948SobrienTo exit @value{GDBN}, use the @code{quit} command (abbreviated
117398948Sobrien@code{q}), or type an end-of-file character (usually @kbd{C-d}).  If you
117498948Sobriendo not supply @var{expression}, @value{GDBN} will terminate normally;
117598948Sobrienotherwise it will terminate using the result of @var{expression} as the
117698948Sobrienerror code.
117719370Spst@end table
117819370Spst
117919370Spst@cindex interrupt
118019370SpstAn interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
118119370Spstterminates the action of any @value{GDBN} command that is in progress and
118219370Spstreturns to @value{GDBN} command level.  It is safe to type the interrupt
118319370Spstcharacter at any time because @value{GDBN} does not allow it to take effect
118419370Spstuntil a time when it is safe.
118519370Spst
118619370SpstIf you have been using @value{GDBN} to control an attached process or
118719370Spstdevice, you can release it with the @code{detach} command
118819370Spst(@pxref{Attach, ,Debugging an already-running process}).
118919370Spst
119098948Sobrien@node Shell Commands
119119370Spst@section Shell commands
119219370Spst
119319370SpstIf you need to execute occasional shell commands during your
119419370Spstdebugging session, there is no need to leave or suspend @value{GDBN}; you can
119519370Spstjust use the @code{shell} command.
119619370Spst
119719370Spst@table @code
119819370Spst@kindex shell
119919370Spst@cindex shell escape
120019370Spst@item shell @var{command string}
120146289SdfrInvoke a standard shell to execute @var{command string}.
120219370SpstIf it exists, the environment variable @code{SHELL} determines which
120398948Sobrienshell to run.  Otherwise @value{GDBN} uses the default shell
120498948Sobrien(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
120519370Spst@end table
120619370Spst
120719370SpstThe utility @code{make} is often needed in development environments.
120819370SpstYou do not have to use the @code{shell} command for this purpose in
120919370Spst@value{GDBN}:
121019370Spst
121119370Spst@table @code
121219370Spst@kindex make
121319370Spst@cindex calling make
121419370Spst@item make @var{make-args}
121519370SpstExecute the @code{make} program with the specified
121619370Spstarguments.  This is equivalent to @samp{shell make @var{make-args}}.
121719370Spst@end table
121819370Spst
1219130809Smarcel@node Logging output
1220130809Smarcel@section Logging output
1221130809Smarcel@cindex logging @value{GDBN} output
1222130809Smarcel
1223130809SmarcelYou may want to save the output of @value{GDBN} commands to a file.
1224130809SmarcelThere are several commands to control @value{GDBN}'s logging.
1225130809Smarcel
1226130809Smarcel@table @code
1227130809Smarcel@kindex set logging
1228130809Smarcel@item set logging on
1229130809SmarcelEnable logging.
1230130809Smarcel@item set logging off
1231130809SmarcelDisable logging.
1232130809Smarcel@item set logging file @var{file}
1233130809SmarcelChange the name of the current logfile.  The default logfile is @file{gdb.txt}.
1234130809Smarcel@item set logging overwrite [on|off]
1235130809SmarcelBy default, @value{GDBN} will append to the logfile.  Set @code{overwrite} if
1236130809Smarcelyou want @code{set logging on} to overwrite the logfile instead.
1237130809Smarcel@item set logging redirect [on|off]
1238130809SmarcelBy default, @value{GDBN} output will go to both the terminal and the logfile.
1239130809SmarcelSet @code{redirect} if you want output to go only to the log file.
1240130809Smarcel@kindex show logging
1241130809Smarcel@item show logging
1242130809SmarcelShow the current values of the logging settings.
1243130809Smarcel@end table
1244130809Smarcel
124598948Sobrien@node Commands
124619370Spst@chapter @value{GDBN} Commands
124719370Spst
124819370SpstYou can abbreviate a @value{GDBN} command to the first few letters of the command
124919370Spstname, if that abbreviation is unambiguous; and you can repeat certain
125019370Spst@value{GDBN} commands by typing just @key{RET}.  You can also use the @key{TAB}
125119370Spstkey to get @value{GDBN} to fill out the rest of a word in a command (or to
125219370Spstshow you the alternatives available, if there is more than one possibility).
125319370Spst
125419370Spst@menu
125519370Spst* Command Syntax::              How to give commands to @value{GDBN}
125619370Spst* Completion::                  Command completion
125719370Spst* Help::                        How to ask @value{GDBN} for help
125819370Spst@end menu
125919370Spst
126098948Sobrien@node Command Syntax
126119370Spst@section Command syntax
126219370Spst
126319370SpstA @value{GDBN} command is a single line of input.  There is no limit on
126419370Spsthow long it can be.  It starts with a command name, which is followed by
126519370Spstarguments whose meaning depends on the command name.  For example, the
126619370Spstcommand @code{step} accepts an argument which is the number of times to
126719370Spststep, as in @samp{step 5}.  You can also use the @code{step} command
126898948Sobrienwith no arguments.  Some commands do not allow any arguments.
126919370Spst
127019370Spst@cindex abbreviation
127119370Spst@value{GDBN} command names may always be truncated if that abbreviation is
127219370Spstunambiguous.  Other possible command abbreviations are listed in the
127319370Spstdocumentation for individual commands.  In some cases, even ambiguous
127419370Spstabbreviations are allowed; for example, @code{s} is specially defined as
127519370Spstequivalent to @code{step} even though there are other commands whose
127619370Spstnames start with @code{s}.  You can test abbreviations by using them as
127719370Spstarguments to the @code{help} command.
127819370Spst
127919370Spst@cindex repeating commands
128098948Sobrien@kindex RET @r{(repeat last command)}
128119370SpstA blank line as input to @value{GDBN} (typing just @key{RET}) means to
128298948Sobrienrepeat the previous command.  Certain commands (for example, @code{run})
128319370Spstwill not repeat this way; these are commands whose unintentional
128419370Spstrepetition might cause trouble and which you are unlikely to want to
128519370Spstrepeat.
128619370Spst
128719370SpstThe @code{list} and @code{x} commands, when you repeat them with
128819370Spst@key{RET}, construct new arguments rather than repeating
128919370Spstexactly as typed.  This permits easy scanning of source or memory.
129019370Spst
129119370Spst@value{GDBN} can also use @key{RET} in another way: to partition lengthy
129219370Spstoutput, in a way similar to the common utility @code{more}
129319370Spst(@pxref{Screen Size,,Screen size}).  Since it is easy to press one
129419370Spst@key{RET} too many in this situation, @value{GDBN} disables command
129519370Spstrepetition after any command that generates this sort of display.
129619370Spst
129798948Sobrien@kindex # @r{(a comment)}
129819370Spst@cindex comment
129919370SpstAny text from a @kbd{#} to the end of the line is a comment; it does
130019370Spstnothing.  This is useful mainly in command files (@pxref{Command
130119370SpstFiles,,Command files}).
130219370Spst
130398948Sobrien@cindex repeating command sequences
130498948Sobrien@kindex C-o @r{(operate-and-get-next)}
130598948SobrienThe @kbd{C-o} binding is useful for repeating a complex sequence of
130698948Sobriencommands.  This command accepts the current line, like @kbd{RET}, and
130798948Sobrienthen fetches the next line relative to the current line from the history
130898948Sobrienfor editing.
130998948Sobrien
131098948Sobrien@node Completion
131119370Spst@section Command completion
131219370Spst
131319370Spst@cindex completion
131419370Spst@cindex word completion
131519370Spst@value{GDBN} can fill in the rest of a word in a command for you, if there is
131619370Spstonly one possibility; it can also show you what the valid possibilities
131719370Spstare for the next word in a command, at any time.  This works for @value{GDBN}
131819370Spstcommands, @value{GDBN} subcommands, and the names of symbols in your program.
131919370Spst
132019370SpstPress the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
132119370Spstof a word.  If there is only one possibility, @value{GDBN} fills in the
132219370Spstword, and waits for you to finish the command (or press @key{RET} to
132319370Spstenter it).  For example, if you type
132419370Spst
132519370Spst@c FIXME "@key" does not distinguish its argument sufficiently to permit
132619370Spst@c complete accuracy in these examples; space introduced for clarity.
132719370Spst@c If texinfo enhancements make it unnecessary, it would be nice to
132819370Spst@c replace " @key" by "@key" in the following...
1329130809Smarcel@smallexample
133019370Spst(@value{GDBP}) info bre @key{TAB}
1331130809Smarcel@end smallexample
133219370Spst
133319370Spst@noindent
133419370Spst@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
133519370Spstthe only @code{info} subcommand beginning with @samp{bre}:
133619370Spst
1337130809Smarcel@smallexample
133819370Spst(@value{GDBP}) info breakpoints
1339130809Smarcel@end smallexample
134019370Spst
134119370Spst@noindent
134219370SpstYou can either press @key{RET} at this point, to run the @code{info
134319370Spstbreakpoints} command, or backspace and enter something else, if
134419370Spst@samp{breakpoints} does not look like the command you expected.  (If you
134519370Spstwere sure you wanted @code{info breakpoints} in the first place, you
134619370Spstmight as well just type @key{RET} immediately after @samp{info bre},
134719370Spstto exploit command abbreviations rather than command completion).
134819370Spst
134919370SpstIf there is more than one possibility for the next word when you press
135019370Spst@key{TAB}, @value{GDBN} sounds a bell.  You can either supply more
135119370Spstcharacters and try again, or just press @key{TAB} a second time;
135219370Spst@value{GDBN} displays all the possible completions for that word.  For
135319370Spstexample, you might want to set a breakpoint on a subroutine whose name
135419370Spstbegins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
135519370Spstjust sounds the bell.  Typing @key{TAB} again displays all the
135619370Spstfunction names in your program that begin with those characters, for
135719370Spstexample:
135819370Spst
1359130809Smarcel@smallexample
136019370Spst(@value{GDBP}) b make_ @key{TAB}
136119370Spst@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
136298948Sobrienmake_a_section_from_file     make_environ
136398948Sobrienmake_abs_section             make_function_type
136498948Sobrienmake_blockvector             make_pointer_type
136598948Sobrienmake_cleanup                 make_reference_type
136619370Spstmake_command                 make_symbol_completion_list
136719370Spst(@value{GDBP}) b make_
1368130809Smarcel@end smallexample
136919370Spst
137019370Spst@noindent
137119370SpstAfter displaying the available possibilities, @value{GDBN} copies your
137219370Spstpartial input (@samp{b make_} in the example) so you can finish the
137319370Spstcommand.
137419370Spst
137519370SpstIf you just want to see the list of alternatives in the first place, you
137698948Sobriencan press @kbd{M-?} rather than pressing @key{TAB} twice.  @kbd{M-?}
137798948Sobrienmeans @kbd{@key{META} ?}.  You can type this either by holding down a
137819370Spstkey designated as the @key{META} shift on your keyboard (if there is
137998948Sobrienone) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
138019370Spst
138119370Spst@cindex quotes in commands
138219370Spst@cindex completion of quoted strings
138319370SpstSometimes the string you need, while logically a ``word'', may contain
138498948Sobrienparentheses or other characters that @value{GDBN} normally excludes from
138598948Sobrienits notion of a word.  To permit word completion to work in this
138698948Sobriensituation, you may enclose words in @code{'} (single quote marks) in
138798948Sobrien@value{GDBN} commands.
138819370Spst
138919370SpstThe most likely situation where you might need this is in typing the
139098948Sobrienname of a C@t{++} function.  This is because C@t{++} allows function
139198948Sobrienoverloading (multiple definitions of the same function, distinguished
139298948Sobrienby argument type).  For example, when you want to set a breakpoint you
139398948Sobrienmay need to distinguish whether you mean the version of @code{name}
139498948Sobrienthat takes an @code{int} parameter, @code{name(int)}, or the version
139598948Sobrienthat takes a @code{float} parameter, @code{name(float)}.  To use the
139698948Sobrienword-completion facilities in this situation, type a single quote
139798948Sobrien@code{'} at the beginning of the function name.  This alerts
139898948Sobrien@value{GDBN} that it may need to consider more information than usual
139998948Sobrienwhen you press @key{TAB} or @kbd{M-?} to request word completion:
140019370Spst
1401130809Smarcel@smallexample
140298948Sobrien(@value{GDBP}) b 'bubble( @kbd{M-?}
140319370Spstbubble(double,double)    bubble(int,int)
140419370Spst(@value{GDBP}) b 'bubble(
1405130809Smarcel@end smallexample
140619370Spst
140719370SpstIn some cases, @value{GDBN} can tell that completing a name requires using
140819370Spstquotes.  When this happens, @value{GDBN} inserts the quote for you (while
140919370Spstcompleting as much as it can) if you do not type the quote in the first
141019370Spstplace:
141119370Spst
1412130809Smarcel@smallexample
141319370Spst(@value{GDBP}) b bub @key{TAB}
141419370Spst@exdent @value{GDBN} alters your input line to the following, and rings a bell:
141519370Spst(@value{GDBP}) b 'bubble(
1416130809Smarcel@end smallexample
141719370Spst
141819370Spst@noindent
141919370SpstIn general, @value{GDBN} can tell that a quote is needed (and inserts it) if
142019370Spstyou have not yet started typing the argument list when you ask for
142119370Spstcompletion on an overloaded symbol.
142246289Sdfr
142398948SobrienFor more information about overloaded functions, see @ref{C plus plus
142498948Sobrienexpressions, ,C@t{++} expressions}.  You can use the command @code{set
142546289Sdfroverload-resolution off} to disable overload resolution;
142698948Sobriensee @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
142719370Spst
142819370Spst
142998948Sobrien@node Help
143019370Spst@section Getting help
143119370Spst@cindex online documentation
143219370Spst@kindex help
143319370Spst
143498948SobrienYou can always ask @value{GDBN} itself for information on its commands,
143519370Spstusing the command @code{help}.
143619370Spst
143719370Spst@table @code
143898948Sobrien@kindex h @r{(@code{help})}
143919370Spst@item help
144019370Spst@itemx h
144119370SpstYou can use @code{help} (abbreviated @code{h}) with no arguments to
144219370Spstdisplay a short list of named classes of commands:
144319370Spst
144419370Spst@smallexample
144519370Spst(@value{GDBP}) help
144619370SpstList of classes of commands:
144719370Spst
144898948Sobrienaliases -- Aliases of other commands
144998948Sobrienbreakpoints -- Making program stop at certain points
145098948Sobriendata -- Examining data
145198948Sobrienfiles -- Specifying and examining files
145298948Sobrieninternals -- Maintenance commands
145398948Sobrienobscure -- Obscure features
145419370Spstrunning -- Running the program
145519370Spststack -- Examining the stack
145619370Spststatus -- Status inquiries
145719370Spstsupport -- Support facilities
145898948Sobrientracepoints -- Tracing of program execution without@*
145998948Sobrien               stopping the program
146019370Spstuser-defined -- User-defined commands
146119370Spst
146298948SobrienType "help" followed by a class name for a list of
146319370Spstcommands in that class.
146498948SobrienType "help" followed by command name for full
146519370Spstdocumentation.
146619370SpstCommand name abbreviations are allowed if unambiguous.
146719370Spst(@value{GDBP})
146819370Spst@end smallexample
146998948Sobrien@c the above line break eliminates huge line overfull...
147019370Spst
147119370Spst@item help @var{class}
147219370SpstUsing one of the general help classes as an argument, you can get a
147319370Spstlist of the individual commands in that class.  For example, here is the
147419370Spsthelp display for the class @code{status}:
147519370Spst
147619370Spst@smallexample
147719370Spst(@value{GDBP}) help status
147819370SpstStatus inquiries.
147919370Spst
148019370SpstList of commands:
148119370Spst
148219370Spst@c Line break in "show" line falsifies real output, but needed
148319370Spst@c to fit in smallbook page size.
148498948Sobrieninfo -- Generic command for showing things
148598948Sobrien about the program being debugged
148698948Sobrienshow -- Generic command for showing things
148798948Sobrien about the debugger
148819370Spst
148998948SobrienType "help" followed by command name for full
149019370Spstdocumentation.
149119370SpstCommand name abbreviations are allowed if unambiguous.
149219370Spst(@value{GDBP})
149319370Spst@end smallexample
149419370Spst
149519370Spst@item help @var{command}
149619370SpstWith a command name as @code{help} argument, @value{GDBN} displays a
149719370Spstshort paragraph on how to use that command.
149819370Spst
149998948Sobrien@kindex apropos
150098948Sobrien@item apropos @var{args}
150198948SobrienThe @code{apropos @var{args}} command searches through all of the @value{GDBN}
150298948Sobriencommands, and their documentation, for the regular expression specified in
150398948Sobrien@var{args}. It prints out all matches found. For example:
150498948Sobrien
150598948Sobrien@smallexample
150698948Sobrienapropos reload
150798948Sobrien@end smallexample
150898948Sobrien
150998948Sobrien@noindent
151098948Sobrienresults in:
151198948Sobrien
151298948Sobrien@smallexample
151398948Sobrien@c @group
151498948Sobrienset symbol-reloading -- Set dynamic symbol table reloading
151598948Sobrien                                 multiple times in one run
151698948Sobrienshow symbol-reloading -- Show dynamic symbol table reloading
151798948Sobrien                                 multiple times in one run
151898948Sobrien@c @end group
151998948Sobrien@end smallexample
152098948Sobrien
152119370Spst@kindex complete
152219370Spst@item complete @var{args}
152319370SpstThe @code{complete @var{args}} command lists all the possible completions
152419370Spstfor the beginning of a command.  Use @var{args} to specify the beginning of the
152519370Spstcommand you want completed.  For example:
152619370Spst
152719370Spst@smallexample
152819370Spstcomplete i
152919370Spst@end smallexample
153019370Spst
153119370Spst@noindent results in:
153219370Spst
153319370Spst@smallexample
153446289Sdfr@group
153598948Sobrienif
153698948Sobrienignore
153719370Spstinfo
153819370Spstinspect
153946289Sdfr@end group
154019370Spst@end smallexample
154119370Spst
154219370Spst@noindent This is intended for use by @sc{gnu} Emacs.
154319370Spst@end table
154419370Spst
154519370SpstIn addition to @code{help}, you can use the @value{GDBN} commands @code{info}
154619370Spstand @code{show} to inquire about the state of your program, or the state
154719370Spstof @value{GDBN} itself.  Each command supports many topics of inquiry; this
154819370Spstmanual introduces each of them in the appropriate context.  The listings
154919370Spstunder @code{info} and under @code{show} in the Index point to
155019370Spstall the sub-commands.  @xref{Index}.
155119370Spst
155219370Spst@c @group
155319370Spst@table @code
155419370Spst@kindex info
155598948Sobrien@kindex i @r{(@code{info})}
155619370Spst@item info
155719370SpstThis command (abbreviated @code{i}) is for describing the state of your
155819370Spstprogram.  For example, you can list the arguments given to your program
155919370Spstwith @code{info args}, list the registers currently in use with @code{info
156019370Spstregisters}, or list the breakpoints you have set with @code{info breakpoints}.
156119370SpstYou can get a complete list of the @code{info} sub-commands with
156219370Spst@w{@code{help info}}.
156319370Spst
156419370Spst@kindex set
156519370Spst@item set
156698948SobrienYou can assign the result of an expression to an environment variable with
156719370Spst@code{set}.  For example, you can set the @value{GDBN} prompt to a $-sign with
156819370Spst@code{set prompt $}.
156919370Spst
157019370Spst@kindex show
157119370Spst@item show
157298948SobrienIn contrast to @code{info}, @code{show} is for describing the state of
157319370Spst@value{GDBN} itself.
157419370SpstYou can change most of the things you can @code{show}, by using the
157519370Spstrelated command @code{set}; for example, you can control what number
157619370Spstsystem is used for displays with @code{set radix}, or simply inquire
157719370Spstwhich is currently in use with @code{show radix}.
157819370Spst
157919370Spst@kindex info set
158019370SpstTo display all the settable parameters and their current
158119370Spstvalues, you can use @code{show} with no arguments; you may also use
158219370Spst@code{info set}.  Both commands produce the same display.
158319370Spst@c FIXME: "info set" violates the rule that "info" is for state of
158419370Spst@c FIXME...program.  Ck w/ GNU: "info set" to be called something else,
158519370Spst@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
158619370Spst@end table
158719370Spst@c @end group
158819370Spst
158919370SpstHere are three miscellaneous @code{show} subcommands, all of which are
159019370Spstexceptional in lacking corresponding @code{set} commands:
159119370Spst
159219370Spst@table @code
159319370Spst@kindex show version
159419370Spst@cindex version number
159519370Spst@item show version
159619370SpstShow what version of @value{GDBN} is running.  You should include this
159798948Sobrieninformation in @value{GDBN} bug-reports.  If multiple versions of
159898948Sobrien@value{GDBN} are in use at your site, you may need to determine which
159998948Sobrienversion of @value{GDBN} you are running; as @value{GDBN} evolves, new
160098948Sobriencommands are introduced, and old ones may wither away.  Also, many
160198948Sobriensystem vendors ship variant versions of @value{GDBN}, and there are
160298948Sobrienvariant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
160398948SobrienThe version number is the same as the one announced when you start
160498948Sobrien@value{GDBN}.
160519370Spst
160619370Spst@kindex show copying
160719370Spst@item show copying
160819370SpstDisplay information about permission for copying @value{GDBN}.
160919370Spst
161019370Spst@kindex show warranty
161119370Spst@item show warranty
161298948SobrienDisplay the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
161398948Sobrienif your version of @value{GDBN} comes with one.
161498948Sobrien
161519370Spst@end table
161619370Spst
161798948Sobrien@node Running
161819370Spst@chapter Running Programs Under @value{GDBN}
161919370Spst
162019370SpstWhen you run a program under @value{GDBN}, you must first generate
162119370Spstdebugging information when you compile it.
162219370Spst
162398948SobrienYou may start @value{GDBN} with its arguments, if any, in an environment
162498948Sobrienof your choice.  If you are doing native debugging, you may redirect
162598948Sobrienyour program's input and output, debug an already running process, or
162698948Sobrienkill a child process.
162798948Sobrien
162819370Spst@menu
162919370Spst* Compilation::                 Compiling for debugging
163019370Spst* Starting::                    Starting your program
163119370Spst* Arguments::                   Your program's arguments
163219370Spst* Environment::                 Your program's environment
163346289Sdfr
163419370Spst* Working Directory::           Your program's working directory
163519370Spst* Input/Output::                Your program's input and output
163619370Spst* Attach::                      Debugging an already-running process
163719370Spst* Kill Process::                Killing the child process
163846289Sdfr
163946289Sdfr* Threads::                     Debugging programs with multiple threads
164019370Spst* Processes::                   Debugging programs with multiple processes
164119370Spst@end menu
164219370Spst
164398948Sobrien@node Compilation
164419370Spst@section Compiling for debugging
164519370Spst
164619370SpstIn order to debug a program effectively, you need to generate
164719370Spstdebugging information when you compile it.  This debugging information
164819370Spstis stored in the object file; it describes the data type of each
164919370Spstvariable or function and the correspondence between source line numbers
165019370Spstand addresses in the executable code.
165119370Spst
165219370SpstTo request debugging information, specify the @samp{-g} option when you run
165319370Spstthe compiler.
165419370Spst
1655130809SmarcelMost compilers do not include information about preprocessor macros in
1656130809Smarcelthe debugging information if you specify the @option{-g} flag alone,
1657130809Smarcelbecause this information is rather large.  Version 3.1 of @value{NGCC},
1658130809Smarcelthe @sc{gnu} C compiler, provides macro information if you specify the
1659130809Smarceloptions @option{-gdwarf-2} and @option{-g3}; the former option requests
1660130809Smarceldebugging information in the Dwarf 2 format, and the latter requests
1661130809Smarcel``extra information''.  In the future, we hope to find more compact ways
1662130809Smarcelto represent macro information, so that it can be included with
1663130809Smarcel@option{-g} alone.
1664130809Smarcel
166519370SpstMany C compilers are unable to handle the @samp{-g} and @samp{-O}
166619370Spstoptions together.  Using those compilers, you cannot generate optimized
166719370Spstexecutables containing debugging information.
166819370Spst
166998948Sobrien@value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
167098948Sobrienwithout @samp{-O}, making it possible to debug optimized code.  We
167198948Sobrienrecommend that you @emph{always} use @samp{-g} whenever you compile a
167298948Sobrienprogram.  You may think your program is correct, but there is no sense
167398948Sobrienin pushing your luck.
167419370Spst
167519370Spst@cindex optimized code, debugging
167619370Spst@cindex debugging optimized code
167719370SpstWhen you debug a program compiled with @samp{-g -O}, remember that the
167819370Spstoptimizer is rearranging your code; the debugger shows you what is
167919370Spstreally there.  Do not be too surprised when the execution path does not
168019370Spstexactly match your source file!  An extreme example: if you define a
168119370Spstvariable, but never use it, @value{GDBN} never sees that
168219370Spstvariable---because the compiler optimizes it out of existence.
168319370Spst
168419370SpstSome things do not work as well with @samp{-g -O} as with just
168519370Spst@samp{-g}, particularly on machines with instruction scheduling.  If in
168619370Spstdoubt, recompile with @samp{-g} alone, and if this fixes the problem,
168719370Spstplease report it to us as a bug (including a test case!).
168819370Spst
168919370SpstOlder versions of the @sc{gnu} C compiler permitted a variant option
169019370Spst@w{@samp{-gg}} for debugging information.  @value{GDBN} no longer supports this
169119370Spstformat; if your @sc{gnu} C compiler has this option, do not use it.
169219370Spst
169319370Spst@need 2000
169498948Sobrien@node Starting
169519370Spst@section Starting your program
169619370Spst@cindex starting
169719370Spst@cindex running
169819370Spst
169919370Spst@table @code
170019370Spst@kindex run
170198948Sobrien@kindex r @r{(@code{run})}
170219370Spst@item run
170319370Spst@itemx r
170498948SobrienUse the @code{run} command to start your program under @value{GDBN}.
170598948SobrienYou must first specify the program name (except on VxWorks) with an
170698948Sobrienargument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
170798948Sobrien@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
170898948Sobrien(@pxref{Files, ,Commands to specify files}).
170919370Spst
171019370Spst@end table
171119370Spst
171219370SpstIf you are running your program in an execution environment that
171319370Spstsupports processes, @code{run} creates an inferior process and makes
171419370Spstthat process run your program.  (In environments without processes,
171519370Spst@code{run} jumps to the start of your program.)
171619370Spst
171719370SpstThe execution of a program is affected by certain information it
171819370Spstreceives from its superior.  @value{GDBN} provides ways to specify this
171919370Spstinformation, which you must do @emph{before} starting your program.  (You
172019370Spstcan change it after starting your program, but such changes only affect
172119370Spstyour program the next time you start it.)  This information may be
172219370Spstdivided into four categories:
172319370Spst
172419370Spst@table @asis
172519370Spst@item The @emph{arguments.}
172619370SpstSpecify the arguments to give your program as the arguments of the
172719370Spst@code{run} command.  If a shell is available on your target, the shell
172819370Spstis used to pass the arguments, so that you may use normal conventions
172919370Spst(such as wildcard expansion or variable substitution) in describing
173046289Sdfrthe arguments.
173146289SdfrIn Unix systems, you can control which shell is used with the
173246289Sdfr@code{SHELL} environment variable.
173346289Sdfr@xref{Arguments, ,Your program's arguments}.
173419370Spst
173519370Spst@item The @emph{environment.}
173619370SpstYour program normally inherits its environment from @value{GDBN}, but you can
173719370Spstuse the @value{GDBN} commands @code{set environment} and @code{unset
173819370Spstenvironment} to change parts of the environment that affect
173919370Spstyour program.  @xref{Environment, ,Your program's environment}.
174019370Spst
174119370Spst@item The @emph{working directory.}
174219370SpstYour program inherits its working directory from @value{GDBN}.  You can set
174319370Spstthe @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
174419370Spst@xref{Working Directory, ,Your program's working directory}.
174519370Spst
174619370Spst@item The @emph{standard input and output.}
174719370SpstYour program normally uses the same device for standard input and
174819370Spststandard output as @value{GDBN} is using.  You can redirect input and output
174919370Spstin the @code{run} command line, or you can use the @code{tty} command to
175019370Spstset a different device for your program.
175119370Spst@xref{Input/Output, ,Your program's input and output}.
175219370Spst
175319370Spst@cindex pipes
175419370Spst@emph{Warning:} While input and output redirection work, you cannot use
175519370Spstpipes to pass the output of the program you are debugging to another
175619370Spstprogram; if you attempt this, @value{GDBN} is likely to wind up debugging the
175719370Spstwrong program.
175819370Spst@end table
175919370Spst
176019370SpstWhen you issue the @code{run} command, your program begins to execute
176119370Spstimmediately.  @xref{Stopping, ,Stopping and continuing}, for discussion
176219370Spstof how to arrange for your program to stop.  Once your program has
176319370Spststopped, you may call functions in your program, using the @code{print}
176419370Spstor @code{call} commands.  @xref{Data, ,Examining Data}.
176519370Spst
176619370SpstIf the modification time of your symbol file has changed since the last
176719370Spsttime @value{GDBN} read its symbols, @value{GDBN} discards its symbol
176819370Spsttable, and reads it again.  When it does this, @value{GDBN} tries to retain
176919370Spstyour current breakpoints.
177019370Spst
177198948Sobrien@node Arguments
177219370Spst@section Your program's arguments
177319370Spst
177419370Spst@cindex arguments (to your program)
177519370SpstThe arguments to your program can be specified by the arguments of the
177698948Sobrien@code{run} command.
177746289SdfrThey are passed to a shell, which expands wildcard characters and
177846289Sdfrperforms redirection of I/O, and thence to your program.  Your
177946289Sdfr@code{SHELL} environment variable (if it exists) specifies what shell
178046289Sdfr@value{GDBN} uses.  If you do not define @code{SHELL}, @value{GDBN} uses
178198948Sobrienthe default shell (@file{/bin/sh} on Unix).
178219370Spst
178398948SobrienOn non-Unix systems, the program is usually invoked directly by
178498948Sobrien@value{GDBN}, which emulates I/O redirection via the appropriate system
178598948Sobriencalls, and the wildcard characters are expanded by the startup code of
178698948Sobrienthe program, not by the shell.
178798948Sobrien
178819370Spst@code{run} with no arguments uses the same arguments used by the previous
178919370Spst@code{run}, or those set by the @code{set args} command.
179019370Spst
179198948Sobrien@table @code
179219370Spst@kindex set args
179319370Spst@item set args
179419370SpstSpecify the arguments to be used the next time your program is run.  If
179519370Spst@code{set args} has no arguments, @code{run} executes your program
179619370Spstwith no arguments.  Once you have run your program with arguments,
179719370Spstusing @code{set args} before the next @code{run} is the only way to run
179819370Spstit again without arguments.
179919370Spst
180019370Spst@kindex show args
180119370Spst@item show args
180219370SpstShow the arguments to give your program when it is started.
180319370Spst@end table
180419370Spst
180598948Sobrien@node Environment
180619370Spst@section Your program's environment
180719370Spst
180819370Spst@cindex environment (of your program)
180919370SpstThe @dfn{environment} consists of a set of environment variables and
181019370Spsttheir values.  Environment variables conventionally record such things as
181119370Spstyour user name, your home directory, your terminal type, and your search
181219370Spstpath for programs to run.  Usually you set up environment variables with
181319370Spstthe shell and they are inherited by all the other programs you run.  When
181419370Spstdebugging, it can be useful to try running your program with a modified
181519370Spstenvironment without having to start @value{GDBN} over again.
181619370Spst
181719370Spst@table @code
181819370Spst@kindex path
181919370Spst@item path @var{directory}
182019370SpstAdd @var{directory} to the front of the @code{PATH} environment variable
182198948Sobrien(the search path for executables) that will be passed to your program.
182298948SobrienThe value of @code{PATH} used by @value{GDBN} does not change.
182398948SobrienYou may specify several directory names, separated by whitespace or by a
182498948Sobriensystem-dependent separator character (@samp{:} on Unix, @samp{;} on
182598948SobrienMS-DOS and MS-Windows).  If @var{directory} is already in the path, it
182698948Sobrienis moved to the front, so it is searched sooner.
182719370Spst
182819370SpstYou can use the string @samp{$cwd} to refer to whatever is the current
182919370Spstworking directory at the time @value{GDBN} searches the path.  If you
183019370Spstuse @samp{.} instead, it refers to the directory where you executed the
183119370Spst@code{path} command.  @value{GDBN} replaces @samp{.} in the
183219370Spst@var{directory} argument (with the current path) before adding
183319370Spst@var{directory} to the search path.
183419370Spst@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
183519370Spst@c document that, since repeating it would be a no-op.
183619370Spst
183719370Spst@kindex show paths
183819370Spst@item show paths
183919370SpstDisplay the list of search paths for executables (the @code{PATH}
184019370Spstenvironment variable).
184119370Spst
184219370Spst@kindex show environment
184319370Spst@item show environment @r{[}@var{varname}@r{]}
184419370SpstPrint the value of environment variable @var{varname} to be given to
184519370Spstyour program when it starts.  If you do not supply @var{varname},
184619370Spstprint the names and values of all environment variables to be given to
184719370Spstyour program.  You can abbreviate @code{environment} as @code{env}.
184819370Spst
184919370Spst@kindex set environment
185098948Sobrien@item set environment @var{varname} @r{[}=@var{value}@r{]}
185119370SpstSet environment variable @var{varname} to @var{value}.  The value
185219370Spstchanges for your program only, not for @value{GDBN} itself.  @var{value} may
185319370Spstbe any string; the values of environment variables are just strings, and
185419370Spstany interpretation is supplied by your program itself.  The @var{value}
185519370Spstparameter is optional; if it is eliminated, the variable is set to a
185619370Spstnull value.
185719370Spst@c "any string" here does not include leading, trailing
185819370Spst@c blanks. Gnu asks: does anyone care?
185919370Spst
186019370SpstFor example, this command:
186119370Spst
1862130809Smarcel@smallexample
186319370Spstset env USER = foo
1864130809Smarcel@end smallexample
186519370Spst
186619370Spst@noindent
186798948Sobrientells the debugged program, when subsequently run, that its user is named
186819370Spst@samp{foo}.  (The spaces around @samp{=} are used for clarity here; they
186919370Spstare not actually required.)
187019370Spst
187119370Spst@kindex unset environment
187219370Spst@item unset environment @var{varname}
187319370SpstRemove variable @var{varname} from the environment to be passed to your
187419370Spstprogram.  This is different from @samp{set env @var{varname} =};
187519370Spst@code{unset environment} removes the variable from the environment,
187619370Spstrather than assigning it an empty value.
187719370Spst@end table
187819370Spst
187998948Sobrien@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
188098948Sobrienthe shell indicated
188119370Spstby your @code{SHELL} environment variable if it exists (or
188219370Spst@code{/bin/sh} if not).  If your @code{SHELL} variable names a shell
188319370Spstthat runs an initialization file---such as @file{.cshrc} for C-shell, or
188419370Spst@file{.bashrc} for BASH---any variables you set in that file affect
188519370Spstyour program.  You may wish to move setting of environment variables to
188619370Spstfiles that are only run when you sign on, such as @file{.login} or
188719370Spst@file{.profile}.
188819370Spst
188998948Sobrien@node Working Directory
189019370Spst@section Your program's working directory
189119370Spst
189219370Spst@cindex working directory (of your program)
189319370SpstEach time you start your program with @code{run}, it inherits its
189419370Spstworking directory from the current working directory of @value{GDBN}.
189519370SpstThe @value{GDBN} working directory is initially whatever it inherited
189619370Spstfrom its parent process (typically the shell), but you can specify a new
189719370Spstworking directory in @value{GDBN} with the @code{cd} command.
189819370Spst
189919370SpstThe @value{GDBN} working directory also serves as a default for the commands
190019370Spstthat specify files for @value{GDBN} to operate on.  @xref{Files, ,Commands to
190119370Spstspecify files}.
190219370Spst
190319370Spst@table @code
190419370Spst@kindex cd
190519370Spst@item cd @var{directory}
190619370SpstSet the @value{GDBN} working directory to @var{directory}.
190719370Spst
190819370Spst@kindex pwd
190919370Spst@item pwd
191019370SpstPrint the @value{GDBN} working directory.
191119370Spst@end table
191219370Spst
191398948Sobrien@node Input/Output
191419370Spst@section Your program's input and output
191519370Spst
191619370Spst@cindex redirection
191719370Spst@cindex i/o
191819370Spst@cindex terminal
191919370SpstBy default, the program you run under @value{GDBN} does input and output to
192098948Sobrienthe same terminal that @value{GDBN} uses.  @value{GDBN} switches the terminal
192119370Spstto its own terminal modes to interact with you, but it records the terminal
192219370Spstmodes your program was using and switches back to them when you continue
192319370Spstrunning your program.
192419370Spst
192519370Spst@table @code
192619370Spst@kindex info terminal
192719370Spst@item info terminal
192819370SpstDisplays information recorded by @value{GDBN} about the terminal modes your
192919370Spstprogram is using.
193019370Spst@end table
193119370Spst
193219370SpstYou can redirect your program's input and/or output using shell
193319370Spstredirection with the @code{run} command.  For example,
193419370Spst
1935130809Smarcel@smallexample
193619370Spstrun > outfile
1937130809Smarcel@end smallexample
193819370Spst
193919370Spst@noindent
194019370Spststarts your program, diverting its output to the file @file{outfile}.
194119370Spst
194219370Spst@kindex tty
194319370Spst@cindex controlling terminal
194419370SpstAnother way to specify where your program should do input and output is
194519370Spstwith the @code{tty} command.  This command accepts a file name as
194619370Spstargument, and causes this file to be the default for future @code{run}
194719370Spstcommands.  It also resets the controlling terminal for the child
194819370Spstprocess, for future @code{run} commands.  For example,
194919370Spst
1950130809Smarcel@smallexample
195119370Spsttty /dev/ttyb
1952130809Smarcel@end smallexample
195319370Spst
195419370Spst@noindent
195519370Spstdirects that processes started with subsequent @code{run} commands
195619370Spstdefault to do input and output on the terminal @file{/dev/ttyb} and have
195719370Spstthat as their controlling terminal.
195819370Spst
195919370SpstAn explicit redirection in @code{run} overrides the @code{tty} command's
196019370Spsteffect on the input/output device, but not its effect on the controlling
196119370Spstterminal.
196219370Spst
196319370SpstWhen you use the @code{tty} command or redirect input in the @code{run}
196419370Spstcommand, only the input @emph{for your program} is affected.  The input
196519370Spstfor @value{GDBN} still comes from your terminal.
196619370Spst
196798948Sobrien@node Attach
196819370Spst@section Debugging an already-running process
196919370Spst@kindex attach
197019370Spst@cindex attach
197119370Spst
197219370Spst@table @code
197319370Spst@item attach @var{process-id}
197419370SpstThis command attaches to a running process---one that was started
197519370Spstoutside @value{GDBN}.  (@code{info files} shows your active
197619370Spsttargets.)  The command takes as argument a process ID.  The usual way to
197719370Spstfind out the process-id of a Unix process is with the @code{ps} utility,
197819370Spstor with the @samp{jobs -l} shell command.
197919370Spst
198019370Spst@code{attach} does not repeat if you press @key{RET} a second time after
198119370Spstexecuting the command.
198219370Spst@end table
198319370Spst
198419370SpstTo use @code{attach}, your program must be running in an environment
198519370Spstwhich supports processes; for example, @code{attach} does not work for
198619370Spstprograms on bare-board targets that lack an operating system.  You must
198719370Spstalso have permission to send the process a signal.
198819370Spst
198946289SdfrWhen you use @code{attach}, the debugger finds the program running in
199046289Sdfrthe process first by looking in the current working directory, then (if
199146289Sdfrthe program is not found) by using the source file search path
199246289Sdfr(@pxref{Source Path, ,Specifying source directories}).  You can also use
199346289Sdfrthe @code{file} command to load the program.  @xref{Files, ,Commands to
199446289SdfrSpecify Files}.
199519370Spst
199619370SpstThe first thing @value{GDBN} does after arranging to debug the specified
199719370Spstprocess is to stop it.  You can examine and modify an attached process
199898948Sobrienwith all the @value{GDBN} commands that are ordinarily available when
199998948Sobrienyou start processes with @code{run}.  You can insert breakpoints; you
200098948Sobriencan step and continue; you can modify storage.  If you would rather the
200198948Sobrienprocess continue running, you may use the @code{continue} command after
200219370Spstattaching @value{GDBN} to the process.
200319370Spst
200419370Spst@table @code
200519370Spst@kindex detach
200619370Spst@item detach
200719370SpstWhen you have finished debugging the attached process, you can use the
200819370Spst@code{detach} command to release it from @value{GDBN} control.  Detaching
200919370Spstthe process continues its execution.  After the @code{detach} command,
201019370Spstthat process and @value{GDBN} become completely independent once more, and you
201119370Spstare ready to @code{attach} another process or start one with @code{run}.
201219370Spst@code{detach} does not repeat if you press @key{RET} again after
201319370Spstexecuting the command.
201419370Spst@end table
201519370Spst
201619370SpstIf you exit @value{GDBN} or use the @code{run} command while you have an
201719370Spstattached process, you kill that process.  By default, @value{GDBN} asks
201819370Spstfor confirmation if you try to do either of these things; you can
201919370Spstcontrol whether or not you need to confirm by using the @code{set
202019370Spstconfirm} command (@pxref{Messages/Warnings, ,Optional warnings and
202119370Spstmessages}).
202219370Spst
202398948Sobrien@node Kill Process
202419370Spst@section Killing the child process
202519370Spst
202619370Spst@table @code
202719370Spst@kindex kill
202819370Spst@item kill
202919370SpstKill the child process in which your program is running under @value{GDBN}.
203019370Spst@end table
203119370Spst
203219370SpstThis command is useful if you wish to debug a core dump instead of a
203319370Spstrunning process.  @value{GDBN} ignores any core dump file while your program
203419370Spstis running.
203519370Spst
203619370SpstOn some operating systems, a program cannot be executed outside @value{GDBN}
203719370Spstwhile you have breakpoints set on it inside @value{GDBN}.  You can use the
203819370Spst@code{kill} command in this situation to permit running your program
203919370Spstoutside the debugger.
204019370Spst
204119370SpstThe @code{kill} command is also useful if you wish to recompile and
204219370Spstrelink your program, since on many systems it is impossible to modify an
204319370Spstexecutable file while it is running in a process.  In this case, when you
204419370Spstnext type @code{run}, @value{GDBN} notices that the file has changed, and
204519370Spstreads the symbol table again (while trying to preserve your current
204619370Spstbreakpoint settings).
204719370Spst
204898948Sobrien@node Threads
204919370Spst@section Debugging programs with multiple threads
205019370Spst
205119370Spst@cindex threads of execution
205219370Spst@cindex multiple threads
205319370Spst@cindex switching threads
205446289SdfrIn some operating systems, such as HP-UX and Solaris, a single program
205546289Sdfrmay have more than one @dfn{thread} of execution.  The precise semantics
205646289Sdfrof threads differ from one operating system to another, but in general
205746289Sdfrthe threads of a single program are akin to multiple processes---except
205846289Sdfrthat they share one address space (that is, they can all examine and
205946289Sdfrmodify the same variables).  On the other hand, each thread has its own
206046289Sdfrregisters and execution stack, and perhaps private memory.
206119370Spst
206219370Spst@value{GDBN} provides these facilities for debugging multi-thread
206319370Spstprograms:
206419370Spst
206519370Spst@itemize @bullet
206619370Spst@item automatic notification of new threads
206719370Spst@item @samp{thread @var{threadno}}, a command to switch among threads
206819370Spst@item @samp{info threads}, a command to inquire about existing threads
206998948Sobrien@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
207019370Spsta command to apply a command to a list of threads
207119370Spst@item thread-specific breakpoints
207219370Spst@end itemize
207319370Spst
207419370Spst@quotation
207519370Spst@emph{Warning:} These facilities are not yet available on every
207619370Spst@value{GDBN} configuration where the operating system supports threads.
207719370SpstIf your @value{GDBN} does not support threads, these commands have no
207819370Spsteffect.  For example, a system without thread support shows no output
207919370Spstfrom @samp{info threads}, and always rejects the @code{thread} command,
208019370Spstlike this:
208119370Spst
208219370Spst@smallexample
208319370Spst(@value{GDBP}) info threads
208419370Spst(@value{GDBP}) thread 1
208519370SpstThread ID 1 not known.  Use the "info threads" command to
208619370Spstsee the IDs of currently known threads.
208719370Spst@end smallexample
208819370Spst@c FIXME to implementors: how hard would it be to say "sorry, this GDB
208919370Spst@c                        doesn't support threads"?
209019370Spst@end quotation
209119370Spst
209219370Spst@cindex focus of debugging
209319370Spst@cindex current thread
209419370SpstThe @value{GDBN} thread debugging facility allows you to observe all
209519370Spstthreads while your program runs---but whenever @value{GDBN} takes
209619370Spstcontrol, one thread in particular is always the focus of debugging.
209719370SpstThis thread is called the @dfn{current thread}.  Debugging commands show
209819370Spstprogram information from the perspective of the current thread.
209919370Spst
210098948Sobrien@cindex @code{New} @var{systag} message
210119370Spst@cindex thread identifier (system)
210219370Spst@c FIXME-implementors!! It would be more helpful if the [New...] message
210319370Spst@c included GDB's numeric thread handle, so you could just go to that
210419370Spst@c thread without first checking `info threads'.
210519370SpstWhenever @value{GDBN} detects a new thread in your program, it displays
210619370Spstthe target system's identification for the thread with a message in the
210719370Spstform @samp{[New @var{systag}]}.  @var{systag} is a thread identifier
210819370Spstwhose form varies depending on the particular system.  For example, on
210919370SpstLynxOS, you might see
211019370Spst
2111130809Smarcel@smallexample
211219370Spst[New process 35 thread 27]
2113130809Smarcel@end smallexample
211419370Spst
211519370Spst@noindent
211619370Spstwhen @value{GDBN} notices a new thread.  In contrast, on an SGI system,
211719370Spstthe @var{systag} is simply something like @samp{process 368}, with no
211819370Spstfurther qualifier.
211919370Spst
212019370Spst@c FIXME!! (1) Does the [New...] message appear even for the very first
212119370Spst@c         thread of a program, or does it only appear for the
212298948Sobrien@c         second---i.e.@: when it becomes obvious we have a multithread
212319370Spst@c         program?
212419370Spst@c         (2) *Is* there necessarily a first thread always?  Or do some
212519370Spst@c         multithread systems permit starting a program with multiple
212698948Sobrien@c         threads ab initio?
212719370Spst
212819370Spst@cindex thread number
212919370Spst@cindex thread identifier (GDB)
213019370SpstFor debugging purposes, @value{GDBN} associates its own thread
213119370Spstnumber---always a single integer---with each thread in your program.
213219370Spst
213319370Spst@table @code
213419370Spst@kindex info threads
213519370Spst@item info threads
213619370SpstDisplay a summary of all threads currently in your
213719370Spstprogram.  @value{GDBN} displays for each thread (in this order):
213819370Spst
213919370Spst@enumerate
214019370Spst@item the thread number assigned by @value{GDBN}
214119370Spst
214219370Spst@item the target system's thread identifier (@var{systag})
214319370Spst
214419370Spst@item the current stack frame summary for that thread
214519370Spst@end enumerate
214619370Spst
214719370Spst@noindent
214819370SpstAn asterisk @samp{*} to the left of the @value{GDBN} thread number
214919370Spstindicates the current thread.
215019370Spst
215198948SobrienFor example,
215219370Spst@end table
215319370Spst@c end table here to get a little more width for example
215419370Spst
215519370Spst@smallexample
215619370Spst(@value{GDBP}) info threads
215719370Spst  3 process 35 thread 27  0x34e5 in sigpause ()
215819370Spst  2 process 35 thread 23  0x34e5 in sigpause ()
215919370Spst* 1 process 35 thread 13  main (argc=1, argv=0x7ffffff8)
216019370Spst    at threadtest.c:68
216119370Spst@end smallexample
216219370Spst
216398948SobrienOn HP-UX systems:
216498948Sobrien
216546289Sdfr@cindex thread number
216646289Sdfr@cindex thread identifier (GDB)
216746289SdfrFor debugging purposes, @value{GDBN} associates its own thread
216846289Sdfrnumber---a small integer assigned in thread-creation order---with each
216946289Sdfrthread in your program.
217046289Sdfr
217198948Sobrien@cindex @code{New} @var{systag} message, on HP-UX
217298948Sobrien@cindex thread identifier (system), on HP-UX
217346289Sdfr@c FIXME-implementors!! It would be more helpful if the [New...] message
217446289Sdfr@c included GDB's numeric thread handle, so you could just go to that
217546289Sdfr@c thread without first checking `info threads'.
217646289SdfrWhenever @value{GDBN} detects a new thread in your program, it displays
217746289Sdfrboth @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
217846289Sdfrform @samp{[New @var{systag}]}.  @var{systag} is a thread identifier
217946289Sdfrwhose form varies depending on the particular system.  For example, on
218046289SdfrHP-UX, you see
218146289Sdfr
2182130809Smarcel@smallexample
218346289Sdfr[New thread 2 (system thread 26594)]
2184130809Smarcel@end smallexample
218546289Sdfr
218646289Sdfr@noindent
218798948Sobrienwhen @value{GDBN} notices a new thread.
218846289Sdfr
218919370Spst@table @code
219046289Sdfr@kindex info threads
219146289Sdfr@item info threads
219246289SdfrDisplay a summary of all threads currently in your
219346289Sdfrprogram.  @value{GDBN} displays for each thread (in this order):
219446289Sdfr
219546289Sdfr@enumerate
219646289Sdfr@item the thread number assigned by @value{GDBN}
219746289Sdfr
219846289Sdfr@item the target system's thread identifier (@var{systag})
219946289Sdfr
220046289Sdfr@item the current stack frame summary for that thread
220146289Sdfr@end enumerate
220246289Sdfr
220346289Sdfr@noindent
220446289SdfrAn asterisk @samp{*} to the left of the @value{GDBN} thread number
220546289Sdfrindicates the current thread.
220646289Sdfr
220798948SobrienFor example,
220846289Sdfr@end table
220946289Sdfr@c end table here to get a little more width for example
221046289Sdfr
2211130809Smarcel@smallexample
221246289Sdfr(@value{GDBP}) info threads
221398948Sobrien    * 3 system thread 26607  worker (wptr=0x7b09c318 "@@") \@*
221498948Sobrien                               at quicksort.c:137
221598948Sobrien      2 system thread 26606  0x7b0030d8 in __ksleep () \@*
221698948Sobrien                               from /usr/lib/libc.2
221798948Sobrien      1 system thread 27905  0x7b003498 in _brk () \@*
221898948Sobrien                               from /usr/lib/libc.2
2219130809Smarcel@end smallexample
222046289Sdfr
222146289Sdfr@table @code
222219370Spst@kindex thread @var{threadno}
222319370Spst@item thread @var{threadno}
222419370SpstMake thread number @var{threadno} the current thread.  The command
222519370Spstargument @var{threadno} is the internal @value{GDBN} thread number, as
222619370Spstshown in the first field of the @samp{info threads} display.
222719370Spst@value{GDBN} responds by displaying the system identifier of the thread
222819370Spstyou selected, and its current stack frame summary:
222919370Spst
223019370Spst@smallexample
223119370Spst@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
223219370Spst(@value{GDBP}) thread 2
223319370Spst[Switching to process 35 thread 23]
223419370Spst0x34e5 in sigpause ()
223519370Spst@end smallexample
223619370Spst
223719370Spst@noindent
223819370SpstAs with the @samp{[New @dots{}]} message, the form of the text after
223919370Spst@samp{Switching to} depends on your system's conventions for identifying
224098948Sobrienthreads.
224119370Spst
224219370Spst@kindex thread apply
224319370Spst@item thread apply [@var{threadno}] [@var{all}]  @var{args}
224419370SpstThe @code{thread apply} command allows you to apply a command to one or
224519370Spstmore threads.  Specify the numbers of the threads that you want affected
224619370Spstwith the command argument @var{threadno}.  @var{threadno} is the internal
224719370Spst@value{GDBN} thread number, as shown in the first field of the @samp{info
224898948Sobrienthreads} display.  To apply a command to all threads, use
224998948Sobrien@code{thread apply all} @var{args}.
225019370Spst@end table
225119370Spst
225219370Spst@cindex automatic thread selection
225319370Spst@cindex switching threads automatically
225419370Spst@cindex threads, automatic switching
225519370SpstWhenever @value{GDBN} stops your program, due to a breakpoint or a
225619370Spstsignal, it automatically selects the thread where that breakpoint or
225719370Spstsignal happened.  @value{GDBN} alerts you to the context switch with a
225819370Spstmessage of the form @samp{[Switching to @var{systag}]} to identify the
225919370Spstthread.
226019370Spst
226119370Spst@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
226219370Spstmore information about how @value{GDBN} behaves when you stop and start
226319370Spstprograms with multiple threads.
226419370Spst
226519370Spst@xref{Set Watchpoints,,Setting watchpoints}, for information about
226619370Spstwatchpoints in programs with multiple threads.
226719370Spst
226898948Sobrien@node Processes
226919370Spst@section Debugging programs with multiple processes
227019370Spst
227119370Spst@cindex fork, debugging programs which call
227219370Spst@cindex multiple processes
227319370Spst@cindex processes, multiple
227498948SobrienOn most systems, @value{GDBN} has no special support for debugging
227598948Sobrienprograms which create additional processes using the @code{fork}
227698948Sobrienfunction.  When a program forks, @value{GDBN} will continue to debug the
227798948Sobrienparent process and the child process will run unimpeded.  If you have
227898948Sobrienset a breakpoint in any code which the child then executes, the child
227998948Sobrienwill get a @code{SIGTRAP} signal which (unless it catches the signal)
228098948Sobrienwill cause it to terminate.
228119370Spst
228219370SpstHowever, if you want to debug the child process there is a workaround
228319370Spstwhich isn't too painful.  Put a call to @code{sleep} in the code which
228419370Spstthe child process executes after the fork.  It may be useful to sleep
228519370Spstonly if a certain environment variable is set, or a certain file exists,
228619370Spstso that the delay need not occur when you don't want to run @value{GDBN}
228719370Spston the child.  While the child is sleeping, use the @code{ps} program to
228819370Spstget its process ID.  Then tell @value{GDBN} (a new invocation of
228919370Spst@value{GDBN} if you are also debugging the parent process) to attach to
229098948Sobrienthe child process (@pxref{Attach}).  From that point on you can debug
229119370Spstthe child process just like any other process which you attached to.
229219370Spst
2293130809SmarcelOn some systems, @value{GDBN} provides support for debugging programs that
2294130809Smarcelcreate additional processes using the @code{fork} or @code{vfork} functions.
2295130809SmarcelCurrently, the only platforms with this feature are HP-UX (11.x and later
2296130809Smarcelonly?) and GNU/Linux (kernel version 2.5.60 and later).
229746289Sdfr
229846289SdfrBy default, when a program forks, @value{GDBN} will continue to debug
229946289Sdfrthe parent process and the child process will run unimpeded.
230046289Sdfr
230146289SdfrIf you want to follow the child process instead of the parent process,
230246289Sdfruse the command @w{@code{set follow-fork-mode}}.
230346289Sdfr
230446289Sdfr@table @code
230546289Sdfr@kindex set follow-fork-mode
230646289Sdfr@item set follow-fork-mode @var{mode}
230746289SdfrSet the debugger response to a program call of @code{fork} or
230846289Sdfr@code{vfork}.  A call to @code{fork} or @code{vfork} creates a new
230946289Sdfrprocess.  The @var{mode} can be:
231046289Sdfr
231146289Sdfr@table @code
231246289Sdfr@item parent
231346289SdfrThe original process is debugged after a fork.  The child process runs
231498948Sobrienunimpeded.  This is the default.
231546289Sdfr
231646289Sdfr@item child
231746289SdfrThe new process is debugged after a fork.  The parent process runs
231846289Sdfrunimpeded.
231946289Sdfr
232046289Sdfr@end table
232146289Sdfr
232246289Sdfr@item show follow-fork-mode
232398948SobrienDisplay the current debugger response to a @code{fork} or @code{vfork} call.
232446289Sdfr@end table
232546289Sdfr
232646289SdfrIf you ask to debug a child process and a @code{vfork} is followed by an
232746289Sdfr@code{exec}, @value{GDBN} executes the new target up to the first
232846289Sdfrbreakpoint in the new target.  If you have a breakpoint set on
232946289Sdfr@code{main} in your original program, the breakpoint will also be set on
233046289Sdfrthe child process's @code{main}.
233146289Sdfr
233246289SdfrWhen a child process is spawned by @code{vfork}, you cannot debug the
233346289Sdfrchild or parent until an @code{exec} call completes.
233446289Sdfr
233546289SdfrIf you issue a @code{run} command to @value{GDBN} after an @code{exec}
233646289Sdfrcall executes, the new target restarts.  To restart the parent process,
233746289Sdfruse the @code{file} command with the parent executable name as its
233846289Sdfrargument.
233946289Sdfr
234046289SdfrYou can use the @code{catch} command to make @value{GDBN} stop whenever
234146289Sdfra @code{fork}, @code{vfork}, or @code{exec} call is made.  @xref{Set
234246289SdfrCatchpoints, ,Setting catchpoints}.
234346289Sdfr
234498948Sobrien@node Stopping
234519370Spst@chapter Stopping and Continuing
234619370Spst
234719370SpstThe principal purposes of using a debugger are so that you can stop your
234819370Spstprogram before it terminates; or so that, if your program runs into
234919370Spsttrouble, you can investigate and find out why.
235019370Spst
235198948SobrienInside @value{GDBN}, your program may stop for any of several reasons,
235298948Sobriensuch as a signal, a breakpoint, or reaching a new line after a
235398948Sobrien@value{GDBN} command such as @code{step}.  You may then examine and
235498948Sobrienchange variables, set new breakpoints or remove old ones, and then
235598948Sobriencontinue execution.  Usually, the messages shown by @value{GDBN} provide
235698948Sobrienample explanation of the status of your program---but you can also
235798948Sobrienexplicitly request this information at any time.
235819370Spst
235919370Spst@table @code
236019370Spst@kindex info program
236119370Spst@item info program
236219370SpstDisplay information about the status of your program: whether it is
236398948Sobrienrunning or not, what process it is, and why it stopped.
236419370Spst@end table
236519370Spst
236619370Spst@menu
236746289Sdfr* Breakpoints::                 Breakpoints, watchpoints, and catchpoints
236819370Spst* Continuing and Stepping::     Resuming execution
236919370Spst* Signals::                     Signals
237046289Sdfr* Thread Stops::                Stopping and starting multi-thread programs
237119370Spst@end menu
237219370Spst
237398948Sobrien@node Breakpoints
237446289Sdfr@section Breakpoints, watchpoints, and catchpoints
237519370Spst
237619370Spst@cindex breakpoints
237719370SpstA @dfn{breakpoint} makes your program stop whenever a certain point in
237846289Sdfrthe program is reached.  For each breakpoint, you can add conditions to
237946289Sdfrcontrol in finer detail whether your program stops.  You can set
238046289Sdfrbreakpoints with the @code{break} command and its variants (@pxref{Set
238146289SdfrBreaks, ,Setting breakpoints}), to specify the place where your program
238246289Sdfrshould stop by line number, function name or exact address in the
238346289Sdfrprogram.
238419370Spst
238546289SdfrIn HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
238646289Sdfrbreakpoints in shared libraries before the executable is run.  There is
238746289Sdfra minor limitation on HP-UX systems: you must wait until the executable
238846289Sdfris run in order to set breakpoints in shared library routines that are
238946289Sdfrnot called directly by the program (for example, routines that are
239046289Sdfrarguments in a @code{pthread_create} call).
239119370Spst
239219370Spst@cindex watchpoints
239319370Spst@cindex memory tracing
239419370Spst@cindex breakpoint on memory address
239519370Spst@cindex breakpoint on variable modification
239619370SpstA @dfn{watchpoint} is a special breakpoint that stops your program
239719370Spstwhen the value of an expression changes.  You must use a different
239819370Spstcommand to set watchpoints (@pxref{Set Watchpoints, ,Setting
239919370Spstwatchpoints}), but aside from that, you can manage a watchpoint like
240019370Spstany other breakpoint: you enable, disable, and delete both breakpoints
240119370Spstand watchpoints using the same commands.
240219370Spst
240319370SpstYou can arrange to have values from your program displayed automatically
240419370Spstwhenever @value{GDBN} stops at a breakpoint.  @xref{Auto Display,,
240519370SpstAutomatic display}.
240619370Spst
240746289Sdfr@cindex catchpoints
240846289Sdfr@cindex breakpoint on events
240946289SdfrA @dfn{catchpoint} is another special breakpoint that stops your program
241098948Sobrienwhen a certain kind of event occurs, such as the throwing of a C@t{++}
241146289Sdfrexception or the loading of a library.  As with watchpoints, you use a
241246289Sdfrdifferent command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
241346289Sdfrcatchpoints}), but aside from that, you can manage a catchpoint like any
241446289Sdfrother breakpoint.  (To stop when your program receives a signal, use the
241598948Sobrien@code{handle} command; see @ref{Signals, ,Signals}.)
241646289Sdfr
241719370Spst@cindex breakpoint numbers
241819370Spst@cindex numbers for breakpoints
241946289Sdfr@value{GDBN} assigns a number to each breakpoint, watchpoint, or
242046289Sdfrcatchpoint when you create it; these numbers are successive integers
242146289Sdfrstarting with one.  In many of the commands for controlling various
242246289Sdfrfeatures of breakpoints you use the breakpoint number to say which
242346289Sdfrbreakpoint you want to change.  Each breakpoint may be @dfn{enabled} or
242446289Sdfr@dfn{disabled}; if disabled, it has no effect on your program until you
242546289Sdfrenable it again.
242619370Spst
242798948Sobrien@cindex breakpoint ranges
242898948Sobrien@cindex ranges of breakpoints
242998948SobrienSome @value{GDBN} commands accept a range of breakpoints on which to
243098948Sobrienoperate.  A breakpoint range is either a single breakpoint number, like
243198948Sobrien@samp{5}, or two such numbers, in increasing order, separated by a
243298948Sobrienhyphen, like @samp{5-7}.  When a breakpoint range is given to a command,
243398948Sobrienall breakpoint in that range are operated on.
243498948Sobrien
243519370Spst@menu
243619370Spst* Set Breaks::                  Setting breakpoints
243719370Spst* Set Watchpoints::             Setting watchpoints
243846289Sdfr* Set Catchpoints::             Setting catchpoints
243919370Spst* Delete Breaks::               Deleting breakpoints
244019370Spst* Disabling::                   Disabling breakpoints
244119370Spst* Conditions::                  Break conditions
244219370Spst* Break Commands::              Breakpoint command lists
244319370Spst* Breakpoint Menus::            Breakpoint menus
244498948Sobrien* Error in Breakpoints::        ``Cannot insert breakpoints''
2445130809Smarcel* Breakpoint related warnings:: ``Breakpoint address adjusted...''
244619370Spst@end menu
244719370Spst
244898948Sobrien@node Set Breaks
244919370Spst@subsection Setting breakpoints
245019370Spst
245198948Sobrien@c FIXME LMB what does GDB do if no code on line of breakpt?
245219370Spst@c       consider in particular declaration with/without initialization.
245319370Spst@c
245419370Spst@c FIXME 2 is there stuff on this already? break at fun start, already init?
245519370Spst
245619370Spst@kindex break
245798948Sobrien@kindex b @r{(@code{break})}
245898948Sobrien@vindex $bpnum@r{, convenience variable}
245919370Spst@cindex latest breakpoint
246019370SpstBreakpoints are set with the @code{break} command (abbreviated
246198948Sobrien@code{b}).  The debugger convenience variable @samp{$bpnum} records the
246298948Sobriennumber of the breakpoint you've set most recently; see @ref{Convenience
246319370SpstVars,, Convenience variables}, for a discussion of what you can do with
246419370Spstconvenience variables.
246519370Spst
246619370SpstYou have several ways to say where the breakpoint should go.
246719370Spst
246819370Spst@table @code
246919370Spst@item break @var{function}
247098948SobrienSet a breakpoint at entry to function @var{function}.
247119370SpstWhen using source languages that permit overloading of symbols, such as
247298948SobrienC@t{++}, @var{function} may refer to more than one possible place to break.
247319370Spst@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
247419370Spst
247519370Spst@item break +@var{offset}
247619370Spst@itemx break -@var{offset}
247719370SpstSet a breakpoint some number of lines forward or back from the position
247898948Sobrienat which execution stopped in the currently selected @dfn{stack frame}.
247998948Sobrien(@xref{Frames, ,Frames}, for a description of stack frames.)
248019370Spst
248119370Spst@item break @var{linenum}
248219370SpstSet a breakpoint at line @var{linenum} in the current source file.
248398948SobrienThe current source file is the last file whose source text was printed.
248498948SobrienThe breakpoint will stop your program just before it executes any of the
248519370Spstcode on that line.
248619370Spst
248719370Spst@item break @var{filename}:@var{linenum}
248819370SpstSet a breakpoint at line @var{linenum} in source file @var{filename}.
248919370Spst
249019370Spst@item break @var{filename}:@var{function}
249119370SpstSet a breakpoint at entry to function @var{function} found in file
249219370Spst@var{filename}.  Specifying a file name as well as a function name is
249319370Spstsuperfluous except when multiple files contain similarly named
249419370Spstfunctions.
249519370Spst
249619370Spst@item break *@var{address}
249719370SpstSet a breakpoint at address @var{address}.  You can use this to set
249819370Spstbreakpoints in parts of your program which do not have debugging
249919370Spstinformation or source files.
250019370Spst
250119370Spst@item break
250219370SpstWhen called without any arguments, @code{break} sets a breakpoint at
250319370Spstthe next instruction to be executed in the selected stack frame
250419370Spst(@pxref{Stack, ,Examining the Stack}).  In any selected frame but the
250519370Spstinnermost, this makes your program stop as soon as control
250619370Spstreturns to that frame.  This is similar to the effect of a
250719370Spst@code{finish} command in the frame inside the selected frame---except
250819370Spstthat @code{finish} does not leave an active breakpoint.  If you use
250919370Spst@code{break} without an argument in the innermost frame, @value{GDBN} stops
251019370Spstthe next time it reaches the current location; this may be useful
251119370Spstinside loops.
251219370Spst
251319370Spst@value{GDBN} normally ignores breakpoints when it resumes execution, until at
251419370Spstleast one instruction has been executed.  If it did not do this, you
251519370Spstwould be unable to proceed past a breakpoint without first disabling the
251619370Spstbreakpoint.  This rule applies whether or not the breakpoint already
251719370Spstexisted when your program stopped.
251819370Spst
251919370Spst@item break @dots{} if @var{cond}
252019370SpstSet a breakpoint with condition @var{cond}; evaluate the expression
252119370Spst@var{cond} each time the breakpoint is reached, and stop only if the
252219370Spstvalue is nonzero---that is, if @var{cond} evaluates as true.
252319370Spst@samp{@dots{}} stands for one of the possible arguments described
252419370Spstabove (or no argument) specifying where to break.  @xref{Conditions,
252519370Spst,Break conditions}, for more information on breakpoint conditions.
252619370Spst
252719370Spst@kindex tbreak
252819370Spst@item tbreak @var{args}
252919370SpstSet a breakpoint enabled only for one stop.  @var{args} are the
253019370Spstsame as for the @code{break} command, and the breakpoint is set in the same
253119370Spstway, but the breakpoint is automatically deleted after the first time your
253219370Spstprogram stops there.  @xref{Disabling, ,Disabling breakpoints}.
253319370Spst
253419370Spst@kindex hbreak
253519370Spst@item hbreak @var{args}
253698948SobrienSet a hardware-assisted breakpoint.  @var{args} are the same as for the
253798948Sobrien@code{break} command and the breakpoint is set in the same way, but the
253819370Spstbreakpoint requires hardware support and some target hardware may not
253919370Spsthave this support.  The main purpose of this is EPROM/ROM code
254098948Sobriendebugging, so you can set a breakpoint at an instruction without
254198948Sobrienchanging the instruction.  This can be used with the new trap-generation
254298948Sobrienprovided by SPARClite DSU and some x86-based targets.  These targets
254398948Sobrienwill generate traps when a program accesses some data or instruction
254498948Sobrienaddress that is assigned to the debug registers.  However the hardware
254598948Sobrienbreakpoint registers can take a limited number of breakpoints.  For
254698948Sobrienexample, on the DSU, only two data breakpoints can be set at a time, and
254798948Sobrien@value{GDBN} will reject this command if more than two are used.  Delete
254898948Sobrienor disable unused hardware breakpoints before setting new ones
254998948Sobrien(@pxref{Disabling, ,Disabling}).  @xref{Conditions, ,Break conditions}.
2550130809Smarcel@xref{set remote hardware-breakpoint-limit}.
255119370Spst
2552130809Smarcel
255319370Spst@kindex thbreak
255419370Spst@item thbreak @var{args}
255519370SpstSet a hardware-assisted breakpoint enabled only for one stop.  @var{args}
255619370Spstare the same as for the @code{hbreak} command and the breakpoint is set in
255798948Sobrienthe same way.  However, like the @code{tbreak} command,
255819370Spstthe breakpoint is automatically deleted after the
255919370Spstfirst time your program stops there.  Also, like the @code{hbreak}
256098948Sobriencommand, the breakpoint requires hardware support and some target hardware
256198948Sobrienmay not have this support.  @xref{Disabling, ,Disabling breakpoints}.
256298948SobrienSee also @ref{Conditions, ,Break conditions}.
256319370Spst
256419370Spst@kindex rbreak
256519370Spst@cindex regular expression
256619370Spst@item rbreak @var{regex}
256719370SpstSet breakpoints on all functions matching the regular expression
256898948Sobrien@var{regex}.  This command sets an unconditional breakpoint on all
256998948Sobrienmatches, printing a list of all breakpoints it set.  Once these
257098948Sobrienbreakpoints are set, they are treated just like the breakpoints set with
257198948Sobrienthe @code{break} command.  You can delete them, disable them, or make
257298948Sobrienthem conditional the same way as any other breakpoint.
257319370Spst
257498948SobrienThe syntax of the regular expression is the standard one used with tools
257598948Sobrienlike @file{grep}.  Note that this is different from the syntax used by
257698948Sobrienshells, so for instance @code{foo*} matches all functions that include
257798948Sobrienan @code{fo} followed by zero or more @code{o}s.  There is an implicit
257898948Sobrien@code{.*} leading and trailing the regular expression you supply, so to
257998948Sobrienmatch only functions that begin with @code{foo}, use @code{^foo}.
258098948Sobrien
258198948SobrienWhen debugging C@t{++} programs, @code{rbreak} is useful for setting
258219370Spstbreakpoints on overloaded functions that are not members of any special
258319370Spstclasses.
258419370Spst
258519370Spst@kindex info breakpoints
258619370Spst@cindex @code{$_} and @code{info breakpoints}
258719370Spst@item info breakpoints @r{[}@var{n}@r{]}
258819370Spst@itemx info break @r{[}@var{n}@r{]}
258919370Spst@itemx info watchpoints @r{[}@var{n}@r{]}
259046289SdfrPrint a table of all breakpoints, watchpoints, and catchpoints set and
259146289Sdfrnot deleted, with the following columns for each breakpoint:
259219370Spst
259319370Spst@table @emph
259419370Spst@item Breakpoint Numbers
259519370Spst@item Type
259646289SdfrBreakpoint, watchpoint, or catchpoint.
259719370Spst@item Disposition
259819370SpstWhether the breakpoint is marked to be disabled or deleted when hit.
259919370Spst@item Enabled or Disabled
260019370SpstEnabled breakpoints are marked with @samp{y}.  @samp{n} marks breakpoints
260119370Spstthat are not enabled.
260219370Spst@item Address
2603130809SmarcelWhere the breakpoint is in your program, as a memory address.  If the
2604130809Smarcelbreakpoint is pending (see below for details) on a future load of a shared library, the address
2605130809Smarcelwill be listed as @samp{<PENDING>}.
260619370Spst@item What
260719370SpstWhere the breakpoint is in the source for your program, as a file and
2608130809Smarcelline number.  For a pending breakpoint, the original string passed to
2609130809Smarcelthe breakpoint command will be listed as it cannot be resolved until
2610130809Smarcelthe appropriate shared library is loaded in the future.
261119370Spst@end table
261219370Spst
261319370Spst@noindent
261419370SpstIf a breakpoint is conditional, @code{info break} shows the condition on
261519370Spstthe line following the affected breakpoint; breakpoint commands, if any,
2616130809Smarcelare listed after that.  A pending breakpoint is allowed to have a condition
2617130809Smarcelspecified for it.  The condition is not parsed for validity until a shared
2618130809Smarcellibrary is loaded that allows the pending breakpoint to resolve to a
2619130809Smarcelvalid location.
262019370Spst
262119370Spst@noindent
262219370Spst@code{info break} with a breakpoint
262319370Spstnumber @var{n} as argument lists only that breakpoint.  The
262419370Spstconvenience variable @code{$_} and the default examining-address for
262519370Spstthe @code{x} command are set to the address of the last breakpoint
262698948Sobrienlisted (@pxref{Memory, ,Examining memory}).
262719370Spst
262819370Spst@noindent
262946289Sdfr@code{info break} displays a count of the number of times the breakpoint
263046289Sdfrhas been hit.  This is especially useful in conjunction with the
263146289Sdfr@code{ignore} command.  You can ignore a large number of breakpoint
263246289Sdfrhits, look at the breakpoint info to see how many times the breakpoint
263346289Sdfrwas hit, and then run again, ignoring one less than that number.  This
263446289Sdfrwill get you quickly to the last hit of that breakpoint.
263519370Spst@end table
263619370Spst
263719370Spst@value{GDBN} allows you to set any number of breakpoints at the same place in
263819370Spstyour program.  There is nothing silly or meaningless about this.  When
263919370Spstthe breakpoints are conditional, this is even useful
264019370Spst(@pxref{Conditions, ,Break conditions}).
264119370Spst
2642130809Smarcel@cindex pending breakpoints
2643130809SmarcelIf a specified breakpoint location cannot be found, it may be due to the fact
2644130809Smarcelthat the location is in a shared library that is yet to be loaded.  In such
2645130809Smarcela case, you may want @value{GDBN} to create a special breakpoint (known as
2646130809Smarcela @dfn{pending breakpoint}) that
2647130809Smarcelattempts to resolve itself in the future when an appropriate shared library
2648130809Smarcelgets loaded.
2649130809Smarcel
2650130809SmarcelPending breakpoints are useful to set at the start of your
2651130809Smarcel@value{GDBN} session for locations that you know will be dynamically loaded
2652130809Smarcellater by the program being debugged.  When shared libraries are loaded,
2653130809Smarcela check is made to see if the load resolves any pending breakpoint locations.
2654130809SmarcelIf a pending breakpoint location gets resolved,
2655130809Smarcela regular breakpoint is created and the original pending breakpoint is removed.
2656130809Smarcel
2657130809Smarcel@value{GDBN} provides some additional commands for controlling pending
2658130809Smarcelbreakpoint support:
2659130809Smarcel
2660130809Smarcel@kindex set breakpoint pending
2661130809Smarcel@kindex show breakpoint pending
2662130809Smarcel@table @code
2663130809Smarcel@item set breakpoint pending auto
2664130809SmarcelThis is the default behavior.  When @value{GDBN} cannot find the breakpoint
2665130809Smarcellocation, it queries you whether a pending breakpoint should be created.
2666130809Smarcel
2667130809Smarcel@item set breakpoint pending on
2668130809SmarcelThis indicates that an unrecognized breakpoint location should automatically
2669130809Smarcelresult in a pending breakpoint being created.
2670130809Smarcel
2671130809Smarcel@item set breakpoint pending off
2672130809SmarcelThis indicates that pending breakpoints are not to be created.  Any
2673130809Smarcelunrecognized breakpoint location results in an error.  This setting does
2674130809Smarcelnot affect any pending breakpoints previously created.
2675130809Smarcel
2676130809Smarcel@item show breakpoint pending
2677130809SmarcelShow the current behavior setting for creating pending breakpoints.
2678130809Smarcel@end table
2679130809Smarcel
2680130809Smarcel@cindex operations allowed on pending breakpoints
2681130809SmarcelNormal breakpoint operations apply to pending breakpoints as well.  You may
2682130809Smarcelspecify a condition for a pending breakpoint and/or commands to run when the
2683130809Smarcelbreakpoint is reached.  You can also enable or disable
2684130809Smarcelthe pending breakpoint.  When you specify a condition for a pending breakpoint,
2685130809Smarcelthe parsing of the condition will be deferred until the point where the
2686130809Smarcelpending breakpoint location is resolved.  Disabling a pending breakpoint
2687130809Smarceltells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
2688130809Smarcelshared library load.  When a pending breakpoint is re-enabled,
2689130809Smarcel@value{GDBN} checks to see if the location is already resolved.
2690130809SmarcelThis is done because any number of shared library loads could have
2691130809Smarceloccurred since the time the breakpoint was disabled and one or more
2692130809Smarcelof these loads could resolve the location.
2693130809Smarcel
269419370Spst@cindex negative breakpoint numbers
269519370Spst@cindex internal @value{GDBN} breakpoints
269698948Sobrien@value{GDBN} itself sometimes sets breakpoints in your program for
269798948Sobrienspecial purposes, such as proper handling of @code{longjmp} (in C
269898948Sobrienprograms).  These internal breakpoints are assigned negative numbers,
269998948Sobrienstarting with @code{-1}; @samp{info breakpoints} does not display them.
270019370SpstYou can see these breakpoints with the @value{GDBN} maintenance command
270198948Sobrien@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
270219370Spst
270319370Spst
270498948Sobrien@node Set Watchpoints
270519370Spst@subsection Setting watchpoints
270646289Sdfr
270719370Spst@cindex setting watchpoints
270846289Sdfr@cindex software watchpoints
270946289Sdfr@cindex hardware watchpoints
271019370SpstYou can use a watchpoint to stop execution whenever the value of an
271146289Sdfrexpression changes, without having to predict a particular place where
271246289Sdfrthis may happen.
271319370Spst
271446289SdfrDepending on your system, watchpoints may be implemented in software or
271598948Sobrienhardware.  @value{GDBN} does software watchpointing by single-stepping your
271646289Sdfrprogram and testing the variable's value each time, which is hundreds of
271746289Sdfrtimes slower than normal execution.  (But this may still be worth it, to
271846289Sdfrcatch errors where you have no clue what part of your program is the
271946289Sdfrculprit.)
272019370Spst
2721130809SmarcelOn some systems, such as HP-UX, @sc{gnu}/Linux and some other x86-based targets,
272298948Sobrien@value{GDBN} includes support for
272346289Sdfrhardware watchpoints, which do not slow down the running of your
272446289Sdfrprogram.
272519370Spst
272619370Spst@table @code
272719370Spst@kindex watch
272819370Spst@item watch @var{expr}
272919370SpstSet a watchpoint for an expression.  @value{GDBN} will break when @var{expr}
273019370Spstis written into by the program and its value changes.
273119370Spst
273219370Spst@kindex rwatch
273319370Spst@item rwatch @var{expr}
273446289SdfrSet a watchpoint that will break when watch @var{expr} is read by the program.
273519370Spst
273619370Spst@kindex awatch
273719370Spst@item awatch @var{expr}
273898948SobrienSet a watchpoint that will break when @var{expr} is either read or written into
273998948Sobrienby the program.
274019370Spst
274119370Spst@kindex info watchpoints
274219370Spst@item info watchpoints
274346289SdfrThis command prints a list of watchpoints, breakpoints, and catchpoints;
274446289Sdfrit is the same as @code{info break}.
274519370Spst@end table
274619370Spst
274746289Sdfr@value{GDBN} sets a @dfn{hardware watchpoint} if possible.  Hardware
274846289Sdfrwatchpoints execute very quickly, and the debugger reports a change in
274946289Sdfrvalue at the exact instruction where the change occurs.  If @value{GDBN}
275046289Sdfrcannot set a hardware watchpoint, it sets a software watchpoint, which
275146289Sdfrexecutes more slowly and reports the change in value at the next
275246289Sdfrstatement, not the instruction, after the change occurs.
275346289Sdfr
275446289SdfrWhen you issue the @code{watch} command, @value{GDBN} reports
275546289Sdfr
2756130809Smarcel@smallexample
275746289SdfrHardware watchpoint @var{num}: @var{expr}
2758130809Smarcel@end smallexample
275946289Sdfr
276046289Sdfr@noindent
276146289Sdfrif it was able to set a hardware watchpoint.
276246289Sdfr
276398948SobrienCurrently, the @code{awatch} and @code{rwatch} commands can only set
276498948Sobrienhardware watchpoints, because accesses to data that don't change the
276598948Sobrienvalue of the watched expression cannot be detected without examining
276698948Sobrienevery instruction as it is being executed, and @value{GDBN} does not do
276798948Sobrienthat currently.  If @value{GDBN} finds that it is unable to set a
276898948Sobrienhardware breakpoint with the @code{awatch} or @code{rwatch} command, it
276998948Sobrienwill print a message like this:
277098948Sobrien
277198948Sobrien@smallexample
277298948SobrienExpression cannot be implemented with read/access watchpoint.
277398948Sobrien@end smallexample
277498948Sobrien
277598948SobrienSometimes, @value{GDBN} cannot set a hardware watchpoint because the
277698948Sobriendata type of the watched expression is wider than what a hardware
277798948Sobrienwatchpoint on the target machine can handle.  For example, some systems
277898948Sobriencan only watch regions that are up to 4 bytes wide; on such systems you
277998948Sobriencannot set hardware watchpoints for an expression that yields a
278098948Sobriendouble-precision floating-point number (which is typically 8 bytes
278198948Sobrienwide).  As a work-around, it might be possible to break the large region
278298948Sobrieninto a series of smaller ones and watch them with separate watchpoints.
278398948Sobrien
278498948SobrienIf you set too many hardware watchpoints, @value{GDBN} might be unable
278598948Sobriento insert all of them when you resume the execution of your program.
278698948SobrienSince the precise number of active watchpoints is unknown until such
278798948Sobrientime as the program is about to be resumed, @value{GDBN} might not be
278898948Sobrienable to warn you about this when you set the watchpoints, and the
278998948Sobrienwarning will be printed only when the program is resumed:
279098948Sobrien
279198948Sobrien@smallexample
279298948SobrienHardware watchpoint @var{num}: Could not insert watchpoint
279398948Sobrien@end smallexample
279498948Sobrien
279598948Sobrien@noindent
279698948SobrienIf this happens, delete or disable some of the watchpoints.
279798948Sobrien
279898948SobrienThe SPARClite DSU will generate traps when a program accesses some data
279998948Sobrienor instruction address that is assigned to the debug registers.  For the
280098948Sobriendata addresses, DSU facilitates the @code{watch} command.  However the
280198948Sobrienhardware breakpoint registers can only take two data watchpoints, and
280298948Sobrienboth watchpoints must be the same kind.  For example, you can set two
280398948Sobrienwatchpoints with @code{watch} commands, two with @code{rwatch} commands,
280498948Sobrien@strong{or} two with @code{awatch} commands, but you cannot set one
280598948Sobrienwatchpoint with one command and the other with a different command.
280646289Sdfr@value{GDBN} will reject the command if you try to mix watchpoints.
280746289SdfrDelete or disable unused watchpoint commands before setting new ones.
280846289Sdfr
280946289SdfrIf you call a function interactively using @code{print} or @code{call},
281098948Sobrienany watchpoints you have set will be inactive until @value{GDBN} reaches another
281146289Sdfrkind of breakpoint or the call completes.
281246289Sdfr
281398948Sobrien@value{GDBN} automatically deletes watchpoints that watch local
281498948Sobrien(automatic) variables, or expressions that involve such variables, when
281598948Sobrienthey go out of scope, that is, when the execution leaves the block in
281698948Sobrienwhich these variables were defined.  In particular, when the program
281798948Sobrienbeing debugged terminates, @emph{all} local variables go out of scope,
281898948Sobrienand so only watchpoints that watch global variables remain set.  If you
281998948Sobrienrerun the program, you will need to set all such watchpoints again.  One
282098948Sobrienway of doing that would be to set a code breakpoint at the entry to the
282198948Sobrien@code{main} function and when it breaks, set all the watchpoints.
282298948Sobrien
282319370Spst@quotation
282419370Spst@cindex watchpoints and threads
282519370Spst@cindex threads and watchpoints
282646289Sdfr@emph{Warning:} In multi-thread programs, watchpoints have only limited
282719370Spstusefulness.  With the current watchpoint implementation, @value{GDBN}
282819370Spstcan only watch the value of an expression @emph{in a single thread}.  If
282919370Spstyou are confident that the expression can only change due to the current
283019370Spstthread's activity (and if you are also confident that no other thread
283119370Spstcan become current), then you can use watchpoints as usual.  However,
283219370Spst@value{GDBN} may not notice when a non-current thread's activity changes
283319370Spstthe expression.
283498948Sobrien
283598948Sobrien@c FIXME: this is almost identical to the previous paragraph.
283698948Sobrien@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
283798948Sobrienhave only limited usefulness.  If @value{GDBN} creates a software
283898948Sobrienwatchpoint, it can only watch the value of an expression @emph{in a
283998948Sobriensingle thread}.  If you are confident that the expression can only
284098948Sobrienchange due to the current thread's activity (and if you are also
284198948Sobrienconfident that no other thread can become current), then you can use
284298948Sobriensoftware watchpoints as usual.  However, @value{GDBN} may not notice
284398948Sobrienwhen a non-current thread's activity changes the expression.  (Hardware
284498948Sobrienwatchpoints, in contrast, watch an expression in all threads.)
284519370Spst@end quotation
284619370Spst
2847130809Smarcel@xref{set remote hardware-watchpoint-limit}.
2848130809Smarcel
284998948Sobrien@node Set Catchpoints
285046289Sdfr@subsection Setting catchpoints
285198948Sobrien@cindex catchpoints, setting
285219370Spst@cindex exception handlers
285346289Sdfr@cindex event handling
285419370Spst
285546289SdfrYou can use @dfn{catchpoints} to cause the debugger to stop for certain
285698948Sobrienkinds of program events, such as C@t{++} exceptions or the loading of a
285746289Sdfrshared library.  Use the @code{catch} command to set a catchpoint.
285819370Spst
285919370Spst@table @code
286019370Spst@kindex catch
286146289Sdfr@item catch @var{event}
286246289SdfrStop when @var{event} occurs.  @var{event} can be any of the following:
286346289Sdfr@table @code
286446289Sdfr@item throw
286546289Sdfr@kindex catch throw
286698948SobrienThe throwing of a C@t{++} exception.
286746289Sdfr
286846289Sdfr@item catch
286946289Sdfr@kindex catch catch
287098948SobrienThe catching of a C@t{++} exception.
287146289Sdfr
287246289Sdfr@item exec
287346289Sdfr@kindex catch exec
287446289SdfrA call to @code{exec}.  This is currently only available for HP-UX.
287546289Sdfr
287646289Sdfr@item fork
287746289Sdfr@kindex catch fork
287846289SdfrA call to @code{fork}.  This is currently only available for HP-UX.
287946289Sdfr
288046289Sdfr@item vfork
288146289Sdfr@kindex catch vfork
288246289SdfrA call to @code{vfork}.  This is currently only available for HP-UX.
288346289Sdfr
288446289Sdfr@item load
288546289Sdfr@itemx load @var{libname}
288646289Sdfr@kindex catch load
288746289SdfrThe dynamic loading of any shared library, or the loading of the library
288846289Sdfr@var{libname}.  This is currently only available for HP-UX.
288946289Sdfr
289046289Sdfr@item unload
289146289Sdfr@itemx unload @var{libname}
289246289Sdfr@kindex catch unload
289346289SdfrThe unloading of any dynamically loaded shared library, or the unloading
289446289Sdfrof the library @var{libname}.  This is currently only available for HP-UX.
289519370Spst@end table
289619370Spst
289746289Sdfr@item tcatch @var{event}
289846289SdfrSet a catchpoint that is enabled only for one stop.  The catchpoint is
289946289Sdfrautomatically deleted after the first time the event is caught.
290019370Spst
290146289Sdfr@end table
290219370Spst
290346289SdfrUse the @code{info break} command to list the current catchpoints.
290446289Sdfr
290598948SobrienThere are currently some limitations to C@t{++} exception handling
290646289Sdfr(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
290746289Sdfr
290819370Spst@itemize @bullet
290919370Spst@item
291019370SpstIf you call a function interactively, @value{GDBN} normally returns
291119370Spstcontrol to you when the function has finished executing.  If the call
291219370Spstraises an exception, however, the call may bypass the mechanism that
291346289Sdfrreturns control to you and cause your program either to abort or to
291446289Sdfrsimply continue running until it hits a breakpoint, catches a signal
291546289Sdfrthat @value{GDBN} is listening for, or exits.  This is the case even if
291646289Sdfryou set a catchpoint for the exception; catchpoints on exceptions are
291746289Sdfrdisabled within interactive calls.
291819370Spst
291919370Spst@item
292019370SpstYou cannot raise an exception interactively.
292119370Spst
292219370Spst@item
292319370SpstYou cannot install an exception handler interactively.
292419370Spst@end itemize
292519370Spst
292619370Spst@cindex raise exceptions
292719370SpstSometimes @code{catch} is not the best way to debug exception handling:
292819370Spstif you need to know exactly where an exception is raised, it is better to
292919370Spststop @emph{before} the exception handler is called, since that way you
293019370Spstcan see the stack before any unwinding takes place.  If you set a
293119370Spstbreakpoint in an exception handler instead, it may not be easy to find
293219370Spstout where the exception was raised.
293319370Spst
293419370SpstTo stop just before an exception handler is called, you need some
293598948Sobrienknowledge of the implementation.  In the case of @sc{gnu} C@t{++}, exceptions are
293619370Spstraised by calling a library function named @code{__raise_exception}
293719370Spstwhich has the following ANSI C interface:
293819370Spst
2939130809Smarcel@smallexample
294019370Spst    /* @var{addr} is where the exception identifier is stored.
294198948Sobrien       @var{id} is the exception identifier.  */
294298948Sobrien    void __raise_exception (void **addr, void *id);
2943130809Smarcel@end smallexample
294419370Spst
294519370Spst@noindent
294619370SpstTo make the debugger catch all exceptions before any stack
294719370Spstunwinding takes place, set a breakpoint on @code{__raise_exception}
294819370Spst(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
294919370Spst
295019370SpstWith a conditional breakpoint (@pxref{Conditions, ,Break conditions})
295119370Spstthat depends on the value of @var{id}, you can stop your program when
295219370Spsta specific exception is raised.  You can use multiple conditional
295319370Spstbreakpoints to stop your program when any of a number of exceptions are
295419370Spstraised.
295519370Spst
295646289Sdfr
295798948Sobrien@node Delete Breaks
295819370Spst@subsection Deleting breakpoints
295919370Spst
296046289Sdfr@cindex clearing breakpoints, watchpoints, catchpoints
296146289Sdfr@cindex deleting breakpoints, watchpoints, catchpoints
296246289SdfrIt is often necessary to eliminate a breakpoint, watchpoint, or
296346289Sdfrcatchpoint once it has done its job and you no longer want your program
296446289Sdfrto stop there.  This is called @dfn{deleting} the breakpoint.  A
296546289Sdfrbreakpoint that has been deleted no longer exists; it is forgotten.
296619370Spst
296719370SpstWith the @code{clear} command you can delete breakpoints according to
296819370Spstwhere they are in your program.  With the @code{delete} command you can
296946289Sdfrdelete individual breakpoints, watchpoints, or catchpoints by specifying
297046289Sdfrtheir breakpoint numbers.
297119370Spst
297219370SpstIt is not necessary to delete a breakpoint to proceed past it.  @value{GDBN}
297319370Spstautomatically ignores breakpoints on the first instruction to be executed
297419370Spstwhen you continue execution without changing the execution address.
297519370Spst
297619370Spst@table @code
297746289Sdfr@kindex clear
297819370Spst@item clear
297919370SpstDelete any breakpoints at the next instruction to be executed in the
298019370Spstselected stack frame (@pxref{Selection, ,Selecting a frame}).  When
298119370Spstthe innermost frame is selected, this is a good way to delete a
298219370Spstbreakpoint where your program just stopped.
298319370Spst
298419370Spst@item clear @var{function}
298519370Spst@itemx clear @var{filename}:@var{function}
298619370SpstDelete any breakpoints set at entry to the function @var{function}.
298719370Spst
298819370Spst@item clear @var{linenum}
298919370Spst@itemx clear @var{filename}:@var{linenum}
299019370SpstDelete any breakpoints set at or within the code of the specified line.
299119370Spst
299219370Spst@cindex delete breakpoints
299319370Spst@kindex delete
299498948Sobrien@kindex d @r{(@code{delete})}
299598948Sobrien@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
299698948SobrienDelete the breakpoints, watchpoints, or catchpoints of the breakpoint
299798948Sobrienranges specified as arguments.  If no argument is specified, delete all
299846289Sdfrbreakpoints (@value{GDBN} asks confirmation, unless you have @code{set
299946289Sdfrconfirm off}).  You can abbreviate this command as @code{d}.
300019370Spst@end table
300119370Spst
300298948Sobrien@node Disabling
300319370Spst@subsection Disabling breakpoints
300419370Spst
300519370Spst@kindex disable breakpoints
300619370Spst@kindex enable breakpoints
300746289SdfrRather than deleting a breakpoint, watchpoint, or catchpoint, you might
300846289Sdfrprefer to @dfn{disable} it.  This makes the breakpoint inoperative as if
300946289Sdfrit had been deleted, but remembers the information on the breakpoint so
301046289Sdfrthat you can @dfn{enable} it again later.
301119370Spst
301246289SdfrYou disable and enable breakpoints, watchpoints, and catchpoints with
301346289Sdfrthe @code{enable} and @code{disable} commands, optionally specifying one
301446289Sdfror more breakpoint numbers as arguments.  Use @code{info break} or
301546289Sdfr@code{info watch} to print a list of breakpoints, watchpoints, and
301646289Sdfrcatchpoints if you do not know which numbers to use.
301719370Spst
301846289SdfrA breakpoint, watchpoint, or catchpoint can have any of four different
301946289Sdfrstates of enablement:
302019370Spst
302119370Spst@itemize @bullet
302219370Spst@item
302319370SpstEnabled.  The breakpoint stops your program.  A breakpoint set
302419370Spstwith the @code{break} command starts out in this state.
302519370Spst@item
302619370SpstDisabled.  The breakpoint has no effect on your program.
302719370Spst@item
302819370SpstEnabled once.  The breakpoint stops your program, but then becomes
302998948Sobriendisabled.
303019370Spst@item
303119370SpstEnabled for deletion.  The breakpoint stops your program, but
303298948Sobrienimmediately after it does so it is deleted permanently.  A breakpoint
303398948Sobrienset with the @code{tbreak} command starts out in this state.
303419370Spst@end itemize
303519370Spst
303646289SdfrYou can use the following commands to enable or disable breakpoints,
303746289Sdfrwatchpoints, and catchpoints:
303819370Spst
303919370Spst@table @code
304019370Spst@kindex disable breakpoints
304119370Spst@kindex disable
304298948Sobrien@kindex dis @r{(@code{disable})}
304398948Sobrien@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
304419370SpstDisable the specified breakpoints---or all breakpoints, if none are
304519370Spstlisted.  A disabled breakpoint has no effect but is not forgotten.  All
304619370Spstoptions such as ignore-counts, conditions and commands are remembered in
304719370Spstcase the breakpoint is enabled again later.  You may abbreviate
304819370Spst@code{disable} as @code{dis}.
304919370Spst
305019370Spst@kindex enable breakpoints
305119370Spst@kindex enable
305298948Sobrien@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
305319370SpstEnable the specified breakpoints (or all defined breakpoints).  They
305419370Spstbecome effective once again in stopping your program.
305519370Spst
305698948Sobrien@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
305719370SpstEnable the specified breakpoints temporarily.  @value{GDBN} disables any
305819370Spstof these breakpoints immediately after stopping your program.
305919370Spst
306098948Sobrien@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
306119370SpstEnable the specified breakpoints to work once, then die.  @value{GDBN}
306219370Spstdeletes any of these breakpoints as soon as your program stops there.
306319370Spst@end table
306419370Spst
306598948Sobrien@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
306698948Sobrien@c confusing: tbreak is also initially enabled.
306719370SpstExcept for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
306819370Spst,Setting breakpoints}), breakpoints that you set are initially enabled;
306919370Spstsubsequently, they become disabled or enabled only when you use one of
307019370Spstthe commands above.  (The command @code{until} can set and delete a
307119370Spstbreakpoint of its own, but it does not change the state of your other
307219370Spstbreakpoints; see @ref{Continuing and Stepping, ,Continuing and
307319370Spststepping}.)
307419370Spst
307598948Sobrien@node Conditions
307619370Spst@subsection Break conditions
307719370Spst@cindex conditional breakpoints
307819370Spst@cindex breakpoint conditions
307919370Spst
308019370Spst@c FIXME what is scope of break condition expr?  Context where wanted?
308198948Sobrien@c      in particular for a watchpoint?
308219370SpstThe simplest sort of breakpoint breaks every time your program reaches a
308319370Spstspecified place.  You can also specify a @dfn{condition} for a
308419370Spstbreakpoint.  A condition is just a Boolean expression in your
308519370Spstprogramming language (@pxref{Expressions, ,Expressions}).  A breakpoint with
308619370Spsta condition evaluates the expression each time your program reaches it,
308719370Spstand your program stops only if the condition is @emph{true}.
308819370Spst
308919370SpstThis is the converse of using assertions for program validation; in that
309019370Spstsituation, you want to stop when the assertion is violated---that is,
309119370Spstwhen the condition is false.  In C, if you want to test an assertion expressed
309219370Spstby the condition @var{assert}, you should set the condition
309319370Spst@samp{! @var{assert}} on the appropriate breakpoint.
309419370Spst
309519370SpstConditions are also accepted for watchpoints; you may not need them,
309619370Spstsince a watchpoint is inspecting the value of an expression anyhow---but
309719370Spstit might be simpler, say, to just set a watchpoint on a variable name,
309819370Spstand specify a condition that tests whether the new value is an interesting
309919370Spstone.
310019370Spst
310119370SpstBreak conditions can have side effects, and may even call functions in
310219370Spstyour program.  This can be useful, for example, to activate functions
310319370Spstthat log program progress, or to use your own print functions to
310419370Spstformat special data structures. The effects are completely predictable
310519370Spstunless there is another enabled breakpoint at the same address.  (In
310619370Spstthat case, @value{GDBN} might see the other breakpoint first and stop your
310719370Spstprogram without checking the condition of this one.)  Note that
310898948Sobrienbreakpoint commands are usually more convenient and flexible than break
310998948Sobrienconditions for the
311019370Spstpurpose of performing side effects when a breakpoint is reached
311119370Spst(@pxref{Break Commands, ,Breakpoint command lists}).
311219370Spst
311319370SpstBreak conditions can be specified when a breakpoint is set, by using
311419370Spst@samp{if} in the arguments to the @code{break} command.  @xref{Set
311519370SpstBreaks, ,Setting breakpoints}.  They can also be changed at any time
311646289Sdfrwith the @code{condition} command.
311798948Sobrien
311846289SdfrYou can also use the @code{if} keyword with the @code{watch} command.
311946289SdfrThe @code{catch} command does not recognize the @code{if} keyword;
312046289Sdfr@code{condition} is the only way to impose a further condition on a
312146289Sdfrcatchpoint.
312219370Spst
312319370Spst@table @code
312419370Spst@kindex condition
312519370Spst@item condition @var{bnum} @var{expression}
312646289SdfrSpecify @var{expression} as the break condition for breakpoint,
312746289Sdfrwatchpoint, or catchpoint number @var{bnum}.  After you set a condition,
312846289Sdfrbreakpoint @var{bnum} stops your program only if the value of
312946289Sdfr@var{expression} is true (nonzero, in C).  When you use
313046289Sdfr@code{condition}, @value{GDBN} checks @var{expression} immediately for
313146289Sdfrsyntactic correctness, and to determine whether symbols in it have
313298948Sobrienreferents in the context of your breakpoint.  If @var{expression} uses
313398948Sobriensymbols not referenced in the context of the breakpoint, @value{GDBN}
313498948Sobrienprints an error message:
313598948Sobrien
3136130809Smarcel@smallexample
313798948SobrienNo symbol "foo" in current context.
3138130809Smarcel@end smallexample
313998948Sobrien
314098948Sobrien@noindent
314119370Spst@value{GDBN} does
314219370Spstnot actually evaluate @var{expression} at the time the @code{condition}
314398948Sobriencommand (or a command that sets a breakpoint with a condition, like
314498948Sobrien@code{break if @dots{}}) is given, however.  @xref{Expressions, ,Expressions}.
314519370Spst
314619370Spst@item condition @var{bnum}
314719370SpstRemove the condition from breakpoint number @var{bnum}.  It becomes
314819370Spstan ordinary unconditional breakpoint.
314919370Spst@end table
315019370Spst
315119370Spst@cindex ignore count (of breakpoint)
315219370SpstA special case of a breakpoint condition is to stop only when the
315319370Spstbreakpoint has been reached a certain number of times.  This is so
315419370Spstuseful that there is a special way to do it, using the @dfn{ignore
315519370Spstcount} of the breakpoint.  Every breakpoint has an ignore count, which
315619370Spstis an integer.  Most of the time, the ignore count is zero, and
315719370Spsttherefore has no effect.  But if your program reaches a breakpoint whose
315819370Spstignore count is positive, then instead of stopping, it just decrements
315919370Spstthe ignore count by one and continues.  As a result, if the ignore count
316019370Spstvalue is @var{n}, the breakpoint does not stop the next @var{n} times
316119370Spstyour program reaches it.
316219370Spst
316319370Spst@table @code
316419370Spst@kindex ignore
316519370Spst@item ignore @var{bnum} @var{count}
316619370SpstSet the ignore count of breakpoint number @var{bnum} to @var{count}.
316719370SpstThe next @var{count} times the breakpoint is reached, your program's
316819370Spstexecution does not stop; other than to decrement the ignore count, @value{GDBN}
316919370Spsttakes no action.
317019370Spst
317119370SpstTo make the breakpoint stop the next time it is reached, specify
317219370Spsta count of zero.
317319370Spst
317419370SpstWhen you use @code{continue} to resume execution of your program from a
317519370Spstbreakpoint, you can specify an ignore count directly as an argument to
317619370Spst@code{continue}, rather than using @code{ignore}.  @xref{Continuing and
317719370SpstStepping,,Continuing and stepping}.
317819370Spst
317919370SpstIf a breakpoint has a positive ignore count and a condition, the
318019370Spstcondition is not checked.  Once the ignore count reaches zero,
318119370Spst@value{GDBN} resumes checking the condition.
318219370Spst
318319370SpstYou could achieve the effect of the ignore count with a condition such
318419370Spstas @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
318519370Spstis decremented each time.  @xref{Convenience Vars, ,Convenience
318619370Spstvariables}.
318719370Spst@end table
318819370Spst
318946289SdfrIgnore counts apply to breakpoints, watchpoints, and catchpoints.
319046289Sdfr
319146289Sdfr
319298948Sobrien@node Break Commands
319319370Spst@subsection Breakpoint command lists
319419370Spst
319519370Spst@cindex breakpoint commands
319646289SdfrYou can give any breakpoint (or watchpoint or catchpoint) a series of
319746289Sdfrcommands to execute when your program stops due to that breakpoint.  For
319846289Sdfrexample, you might want to print the values of certain expressions, or
319946289Sdfrenable other breakpoints.
320019370Spst
320119370Spst@table @code
320219370Spst@kindex commands
320319370Spst@kindex end
320419370Spst@item commands @r{[}@var{bnum}@r{]}
320519370Spst@itemx @dots{} @var{command-list} @dots{}
320619370Spst@itemx end
320719370SpstSpecify a list of commands for breakpoint number @var{bnum}.  The commands
320819370Spstthemselves appear on the following lines.  Type a line containing just
320919370Spst@code{end} to terminate the commands.
321019370Spst
321119370SpstTo remove all commands from a breakpoint, type @code{commands} and
321219370Spstfollow it immediately with @code{end}; that is, give no commands.
321319370Spst
321419370SpstWith no @var{bnum} argument, @code{commands} refers to the last
321546289Sdfrbreakpoint, watchpoint, or catchpoint set (not to the breakpoint most
321646289Sdfrrecently encountered).
321719370Spst@end table
321819370Spst
321919370SpstPressing @key{RET} as a means of repeating the last @value{GDBN} command is
322019370Spstdisabled within a @var{command-list}.
322119370Spst
322219370SpstYou can use breakpoint commands to start your program up again.  Simply
322319370Spstuse the @code{continue} command, or @code{step}, or any other command
322419370Spstthat resumes execution.
322519370Spst
322619370SpstAny other commands in the command list, after a command that resumes
322719370Spstexecution, are ignored.  This is because any time you resume execution
322819370Spst(even with a simple @code{next} or @code{step}), you may encounter
322919370Spstanother breakpoint---which could have its own command list, leading to
323019370Spstambiguities about which list to execute.
323119370Spst
323219370Spst@kindex silent
323319370SpstIf the first command you specify in a command list is @code{silent}, the
323419370Spstusual message about stopping at a breakpoint is not printed.  This may
323519370Spstbe desirable for breakpoints that are to print a specific message and
323619370Spstthen continue.  If none of the remaining commands print anything, you
323719370Spstsee no sign that the breakpoint was reached.  @code{silent} is
323819370Spstmeaningful only at the beginning of a breakpoint command list.
323919370Spst
324019370SpstThe commands @code{echo}, @code{output}, and @code{printf} allow you to
324119370Spstprint precisely controlled output, and are often useful in silent
324219370Spstbreakpoints.  @xref{Output, ,Commands for controlled output}.
324319370Spst
324419370SpstFor example, here is how you could use breakpoint commands to print the
324519370Spstvalue of @code{x} at entry to @code{foo} whenever @code{x} is positive.
324619370Spst
3247130809Smarcel@smallexample
324819370Spstbreak foo if x>0
324919370Spstcommands
325019370Spstsilent
325119370Spstprintf "x is %d\n",x
325219370Spstcont
325319370Spstend
3254130809Smarcel@end smallexample
325519370Spst
325619370SpstOne application for breakpoint commands is to compensate for one bug so
325719370Spstyou can test for another.  Put a breakpoint just after the erroneous line
325819370Spstof code, give it a condition to detect the case in which something
325919370Spsterroneous has been done, and give it commands to assign correct values
326019370Spstto any variables that need them.  End with the @code{continue} command
326119370Spstso that your program does not stop, and start with the @code{silent}
326219370Spstcommand so that no output is produced.  Here is an example:
326319370Spst
3264130809Smarcel@smallexample
326519370Spstbreak 403
326619370Spstcommands
326719370Spstsilent
326819370Spstset x = y + 4
326919370Spstcont
327019370Spstend
3271130809Smarcel@end smallexample
327219370Spst
327398948Sobrien@node Breakpoint Menus
327419370Spst@subsection Breakpoint menus
327519370Spst@cindex overloading
327619370Spst@cindex symbol overloading
327719370Spst
3278130809SmarcelSome programming languages (notably C@t{++} and Objective-C) permit a
3279130809Smarcelsingle function name
328019370Spstto be defined several times, for application in different contexts.
328119370SpstThis is called @dfn{overloading}.  When a function name is overloaded,
328219370Spst@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
328319370Spsta breakpoint.  If you realize this is a problem, you can use
328419370Spstsomething like @samp{break @var{function}(@var{types})} to specify which
328519370Spstparticular version of the function you want.  Otherwise, @value{GDBN} offers
328619370Spstyou a menu of numbered choices for different possible breakpoints, and
328719370Spstwaits for your selection with the prompt @samp{>}.  The first two
328819370Spstoptions are always @samp{[0] cancel} and @samp{[1] all}.  Typing @kbd{1}
328919370Spstsets a breakpoint at each definition of @var{function}, and typing
329019370Spst@kbd{0} aborts the @code{break} command without setting any new
329119370Spstbreakpoints.
329219370Spst
329319370SpstFor example, the following session excerpt shows an attempt to set a
329419370Spstbreakpoint at the overloaded symbol @code{String::after}.
329519370SpstWe choose three particular definitions of that function name:
329619370Spst
329719370Spst@c FIXME! This is likely to change to show arg type lists, at least
329819370Spst@smallexample
329946289Sdfr@group
330019370Spst(@value{GDBP}) b String::after
330119370Spst[0] cancel
330219370Spst[1] all
330319370Spst[2] file:String.cc; line number:867
330419370Spst[3] file:String.cc; line number:860
330519370Spst[4] file:String.cc; line number:875
330619370Spst[5] file:String.cc; line number:853
330719370Spst[6] file:String.cc; line number:846
330819370Spst[7] file:String.cc; line number:735
330919370Spst> 2 4 6
331019370SpstBreakpoint 1 at 0xb26c: file String.cc, line 867.
331119370SpstBreakpoint 2 at 0xb344: file String.cc, line 875.
331219370SpstBreakpoint 3 at 0xafcc: file String.cc, line 846.
331319370SpstMultiple breakpoints were set.
331419370SpstUse the "delete" command to delete unwanted
331519370Spst breakpoints.
331619370Spst(@value{GDBP})
331746289Sdfr@end group
331819370Spst@end smallexample
331919370Spst
332019370Spst@c  @ifclear BARETARGET
332198948Sobrien@node Error in Breakpoints
332298948Sobrien@subsection ``Cannot insert breakpoints''
332319370Spst@c
332419370Spst@c  FIXME!! 14/6/95  Is there a real example of this?  Let's use it.
332519370Spst@c
332698948SobrienUnder some operating systems, breakpoints cannot be used in a program if
332798948Sobrienany other process is running that program.  In this situation,
332898948Sobrienattempting to run or continue a program with a breakpoint causes
332998948Sobrien@value{GDBN} to print an error message:
333098948Sobrien
3331130809Smarcel@smallexample
333298948SobrienCannot insert breakpoints.
333398948SobrienThe same program may be running in another process.
3334130809Smarcel@end smallexample
333598948Sobrien
333698948SobrienWhen this happens, you have three ways to proceed:
333798948Sobrien
333898948Sobrien@enumerate
333998948Sobrien@item
334098948SobrienRemove or disable the breakpoints, then continue.
334198948Sobrien
334298948Sobrien@item
334398948SobrienSuspend @value{GDBN}, and copy the file containing your program to a new
334498948Sobrienname.  Resume @value{GDBN} and use the @code{exec-file} command to specify
334598948Sobrienthat @value{GDBN} should run your program under that name.
334698948SobrienThen start your program again.
334798948Sobrien
334898948Sobrien@item
334998948SobrienRelink your program so that the text segment is nonsharable, using the
335098948Sobrienlinker option @samp{-N}.  The operating system limitation may not apply
335198948Sobriento nonsharable executables.
335298948Sobrien@end enumerate
335319370Spst@c  @end ifclear
335419370Spst
335598948SobrienA similar message can be printed if you request too many active
335698948Sobrienhardware-assisted breakpoints and watchpoints:
335798948Sobrien
335898948Sobrien@c FIXME: the precise wording of this message may change; the relevant
335998948Sobrien@c source change is not committed yet (Sep 3, 1999).
336098948Sobrien@smallexample
336198948SobrienStopped; cannot insert breakpoints.
336298948SobrienYou may have requested too many hardware breakpoints and watchpoints.
336398948Sobrien@end smallexample
336498948Sobrien
336598948Sobrien@noindent
336698948SobrienThis message is printed when you attempt to resume the program, since
336798948Sobrienonly then @value{GDBN} knows exactly how many hardware breakpoints and
336898948Sobrienwatchpoints it needs to insert.
336998948Sobrien
337098948SobrienWhen this message is printed, you need to disable or remove some of the
337198948Sobrienhardware-assisted breakpoints and watchpoints, and then continue.
337298948Sobrien
3373130809Smarcel@node Breakpoint related warnings
3374130809Smarcel@subsection ``Breakpoint address adjusted...''
3375130809Smarcel@cindex breakpoint address adjusted
337698948Sobrien
3377130809SmarcelSome processor architectures place constraints on the addresses at
3378130809Smarcelwhich breakpoints may be placed.  For architectures thus constrained,
3379130809Smarcel@value{GDBN} will attempt to adjust the breakpoint's address to comply
3380130809Smarcelwith the constraints dictated by the architecture.
3381130809Smarcel
3382130809SmarcelOne example of such an architecture is the Fujitsu FR-V.  The FR-V is
3383130809Smarcela VLIW architecture in which a number of RISC-like instructions may be
3384130809Smarcelbundled together for parallel execution.  The FR-V architecture
3385130809Smarcelconstrains the location of a breakpoint instruction within such a
3386130809Smarcelbundle to the instruction with the lowest address.  @value{GDBN}
3387130809Smarcelhonors this constraint by adjusting a breakpoint's address to the
3388130809Smarcelfirst in the bundle.
3389130809Smarcel
3390130809SmarcelIt is not uncommon for optimized code to have bundles which contain
3391130809Smarcelinstructions from different source statements, thus it may happen that
3392130809Smarcela breakpoint's address will be adjusted from one source statement to
3393130809Smarcelanother.  Since this adjustment may significantly alter @value{GDBN}'s
3394130809Smarcelbreakpoint related behavior from what the user expects, a warning is
3395130809Smarcelprinted when the breakpoint is first set and also when the breakpoint
3396130809Smarcelis hit.
3397130809Smarcel
3398130809SmarcelA warning like the one below is printed when setting a breakpoint
3399130809Smarcelthat's been subject to address adjustment:
3400130809Smarcel
3401130809Smarcel@smallexample
3402130809Smarcelwarning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3403130809Smarcel@end smallexample
3404130809Smarcel
3405130809SmarcelSuch warnings are printed both for user settable and @value{GDBN}'s
3406130809Smarcelinternal breakpoints.  If you see one of these warnings, you should
3407130809Smarcelverify that a breakpoint set at the adjusted address will have the
3408130809Smarceldesired affect.  If not, the breakpoint in question may be removed and
3409130809Smarcelother breakpoints may be set which will have the desired behavior.
3410130809SmarcelE.g., it may be sufficient to place the breakpoint at a later
3411130809Smarcelinstruction.  A conditional breakpoint may also be useful in some
3412130809Smarcelcases to prevent the breakpoint from triggering too often.
3413130809Smarcel
3414130809Smarcel@value{GDBN} will also issue a warning when stopping at one of these
3415130809Smarceladjusted breakpoints:
3416130809Smarcel
3417130809Smarcel@smallexample
3418130809Smarcelwarning: Breakpoint 1 address previously adjusted from 0x00010414
3419130809Smarcelto 0x00010410.
3420130809Smarcel@end smallexample
3421130809Smarcel
3422130809SmarcelWhen this warning is encountered, it may be too late to take remedial
3423130809Smarcelaction except in cases where the breakpoint is hit earlier or more
3424130809Smarcelfrequently than expected.
3425130809Smarcel
342698948Sobrien@node Continuing and Stepping
342719370Spst@section Continuing and stepping
342819370Spst
342919370Spst@cindex stepping
343019370Spst@cindex continuing
343119370Spst@cindex resuming execution
343219370Spst@dfn{Continuing} means resuming program execution until your program
343319370Spstcompletes normally.  In contrast, @dfn{stepping} means executing just
343419370Spstone more ``step'' of your program, where ``step'' may mean either one
343519370Spstline of source code, or one machine instruction (depending on what
343698948Sobrienparticular command you use).  Either when continuing or when stepping,
343798948Sobrienyour program may stop even sooner, due to a breakpoint or a signal.  (If
343898948Sobrienit stops due to a signal, you may want to use @code{handle}, or use
343998948Sobrien@samp{signal 0} to resume execution.  @xref{Signals, ,Signals}.)
344019370Spst
344119370Spst@table @code
344219370Spst@kindex continue
344398948Sobrien@kindex c @r{(@code{continue})}
344498948Sobrien@kindex fg @r{(resume foreground execution)}
344519370Spst@item continue @r{[}@var{ignore-count}@r{]}
344619370Spst@itemx c @r{[}@var{ignore-count}@r{]}
344719370Spst@itemx fg @r{[}@var{ignore-count}@r{]}
344819370SpstResume program execution, at the address where your program last stopped;
344919370Spstany breakpoints set at that address are bypassed.  The optional argument
345019370Spst@var{ignore-count} allows you to specify a further number of times to
345119370Spstignore a breakpoint at this location; its effect is like that of
345219370Spst@code{ignore} (@pxref{Conditions, ,Break conditions}).
345319370Spst
345419370SpstThe argument @var{ignore-count} is meaningful only when your program
345519370Spststopped due to a breakpoint.  At other times, the argument to
345619370Spst@code{continue} is ignored.
345719370Spst
345898948SobrienThe synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
345998948Sobriendebugged program is deemed to be the foreground program) are provided
346098948Sobrienpurely for convenience, and have exactly the same behavior as
346198948Sobrien@code{continue}.
346219370Spst@end table
346319370Spst
346419370SpstTo resume execution at a different place, you can use @code{return}
346519370Spst(@pxref{Returning, ,Returning from a function}) to go back to the
346619370Spstcalling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
346719370Spstdifferent address}) to go to an arbitrary location in your program.
346819370Spst
346919370SpstA typical technique for using stepping is to set a breakpoint
347046289Sdfr(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
347146289Sdfrbeginning of the function or the section of your program where a problem
347246289Sdfris believed to lie, run your program until it stops at that breakpoint,
347346289Sdfrand then step through the suspect area, examining the variables that are
347446289Sdfrinteresting, until you see the problem happen.
347519370Spst
347619370Spst@table @code
347719370Spst@kindex step
347898948Sobrien@kindex s @r{(@code{step})}
347919370Spst@item step
348019370SpstContinue running your program until control reaches a different source
348119370Spstline, then stop it and return control to @value{GDBN}.  This command is
348219370Spstabbreviated @code{s}.
348319370Spst
348419370Spst@quotation
348519370Spst@c "without debugging information" is imprecise; actually "without line
348619370Spst@c numbers in the debugging information".  (gcc -g1 has debugging info but
348719370Spst@c not line numbers).  But it seems complex to try to make that
348819370Spst@c distinction here.
348919370Spst@emph{Warning:} If you use the @code{step} command while control is
349019370Spstwithin a function that was compiled without debugging information,
349119370Spstexecution proceeds until control reaches a function that does have
349219370Spstdebugging information.  Likewise, it will not step into a function which
349319370Spstis compiled without debugging information.  To step through functions
349419370Spstwithout debugging information, use the @code{stepi} command, described
349519370Spstbelow.
349619370Spst@end quotation
349719370Spst
349898948SobrienThe @code{step} command only stops at the first instruction of a source
349998948Sobrienline.  This prevents the multiple stops that could otherwise occur in
350098948Sobrien@code{switch} statements, @code{for} loops, etc.  @code{step} continues
350198948Sobriento stop if a function that has debugging information is called within
350298948Sobrienthe line.  In other words, @code{step} @emph{steps inside} any functions
350398948Sobriencalled within the line.
350419370Spst
350598948SobrienAlso, the @code{step} command only enters a function if there is line
350698948Sobriennumber information for the function.  Otherwise it acts like the
350798948Sobrien@code{next} command.  This avoids problems when using @code{cc -gl}
350819370Spston MIPS machines.  Previously, @code{step} entered subroutines if there
350998948Sobrienwas any debugging information about the routine.
351019370Spst
351119370Spst@item step @var{count}
351219370SpstContinue running as in @code{step}, but do so @var{count} times.  If a
351398948Sobrienbreakpoint is reached, or a signal not related to stepping occurs before
351498948Sobrien@var{count} steps, stepping stops right away.
351519370Spst
351619370Spst@kindex next
351798948Sobrien@kindex n @r{(@code{next})}
351819370Spst@item next @r{[}@var{count}@r{]}
351919370SpstContinue to the next source line in the current (innermost) stack frame.
352098948SobrienThis is similar to @code{step}, but function calls that appear within
352198948Sobrienthe line of code are executed without stopping.  Execution stops when
352298948Sobriencontrol reaches a different line of code at the original stack level
352398948Sobrienthat was executing when you gave the @code{next} command.  This command
352498948Sobrienis abbreviated @code{n}.
352519370Spst
352619370SpstAn argument @var{count} is a repeat count, as for @code{step}.
352719370Spst
352819370Spst
352919370Spst@c  FIX ME!!  Do we delete this, or is there a way it fits in with
353019370Spst@c  the following paragraph?   ---  Vctoria
353119370Spst@c
353219370Spst@c  @code{next} within a function that lacks debugging information acts like
353319370Spst@c  @code{step}, but any function calls appearing within the code of the
353419370Spst@c  function are executed without stopping.
353519370Spst
353698948SobrienThe @code{next} command only stops at the first instruction of a
353798948Sobriensource line.  This prevents multiple stops that could otherwise occur in
353898948Sobrien@code{switch} statements, @code{for} loops, etc.
353919370Spst
354098948Sobrien@kindex set step-mode
354198948Sobrien@item set step-mode
354298948Sobrien@cindex functions without line info, and stepping
354398948Sobrien@cindex stepping into functions with no line info
354498948Sobrien@itemx set step-mode on
354598948SobrienThe @code{set step-mode on} command causes the @code{step} command to
354698948Sobrienstop at the first instruction of a function which contains no debug line
354798948Sobrieninformation rather than stepping over it.
354898948Sobrien
354998948SobrienThis is useful in cases where you may be interested in inspecting the
355098948Sobrienmachine instructions of a function which has no symbolic info and do not
355198948Sobrienwant @value{GDBN} to automatically skip over this function.
355298948Sobrien
355398948Sobrien@item set step-mode off
355498948SobrienCauses the @code{step} command to step over any functions which contains no
355598948Sobriendebug information.  This is the default.
355698948Sobrien
355719370Spst@kindex finish
355819370Spst@item finish
355919370SpstContinue running until just after function in the selected stack frame
356019370Spstreturns.  Print the returned value (if any).
356119370Spst
356219370SpstContrast this with the @code{return} command (@pxref{Returning,
356319370Spst,Returning from a function}).
356419370Spst
356519370Spst@kindex until
356698948Sobrien@kindex u @r{(@code{until})}
356719370Spst@item until
356846289Sdfr@itemx u
356919370SpstContinue running until a source line past the current line, in the
357019370Spstcurrent stack frame, is reached.  This command is used to avoid single
357119370Spststepping through a loop more than once.  It is like the @code{next}
357219370Spstcommand, except that when @code{until} encounters a jump, it
357319370Spstautomatically continues execution until the program counter is greater
357419370Spstthan the address of the jump.
357519370Spst
357619370SpstThis means that when you reach the end of a loop after single stepping
357719370Spstthough it, @code{until} makes your program continue execution until it
357819370Spstexits the loop.  In contrast, a @code{next} command at the end of a loop
357919370Spstsimply steps back to the beginning of the loop, which forces you to step
358019370Spstthrough the next iteration.
358119370Spst
358219370Spst@code{until} always stops your program if it attempts to exit the current
358319370Spststack frame.
358419370Spst
358519370Spst@code{until} may produce somewhat counterintuitive results if the order
358619370Spstof machine code does not match the order of the source lines.  For
358719370Spstexample, in the following excerpt from a debugging session, the @code{f}
358819370Spst(@code{frame}) command shows that execution is stopped at line
358919370Spst@code{206}; yet when we use @code{until}, we get to line @code{195}:
359019370Spst
3591130809Smarcel@smallexample
359219370Spst(@value{GDBP}) f
359319370Spst#0  main (argc=4, argv=0xf7fffae8) at m4.c:206
359419370Spst206                 expand_input();
359519370Spst(@value{GDBP}) until
359619370Spst195             for ( ; argc > 0; NEXTARG) @{
3597130809Smarcel@end smallexample
359819370Spst
359919370SpstThis happened because, for execution efficiency, the compiler had
360019370Spstgenerated code for the loop closure test at the end, rather than the
360119370Spststart, of the loop---even though the test in a C @code{for}-loop is
360219370Spstwritten before the body of the loop.  The @code{until} command appeared
360319370Spstto step back to the beginning of the loop when it advanced to this
360419370Spstexpression; however, it has not really gone to an earlier
360519370Spststatement---not in terms of the actual machine code.
360619370Spst
360719370Spst@code{until} with no argument works by means of single
360819370Spstinstruction stepping, and hence is slower than @code{until} with an
360919370Spstargument.
361019370Spst
361119370Spst@item until @var{location}
361219370Spst@itemx u @var{location}
361319370SpstContinue running your program until either the specified location is
361419370Spstreached, or the current stack frame returns.  @var{location} is any of
361519370Spstthe forms of argument acceptable to @code{break} (@pxref{Set Breaks,
3616130809Smarcel,Setting breakpoints}).  This form of the command uses breakpoints, and
3617130809Smarcelhence is quicker than @code{until} without an argument.  The specified
3618130809Smarcellocation is actually reached only if it is in the current frame.  This
3619130809Smarcelimplies that @code{until} can be used to skip over recursive function
3620130809Smarcelinvocations.  For instance in the code below, if the current location is
3621130809Smarcelline @code{96}, issuing @code{until 99} will execute the program up to
3622130809Smarcelline @code{99} in the same invocation of factorial, i.e. after the inner
3623130809Smarcelinvocations have returned.
362419370Spst
3625130809Smarcel@smallexample
3626130809Smarcel94	int factorial (int value)
3627130809Smarcel95	@{
3628130809Smarcel96	    if (value > 1) @{
3629130809Smarcel97            value *= factorial (value - 1);
3630130809Smarcel98	    @}
3631130809Smarcel99	    return (value);
3632130809Smarcel100     @}
3633130809Smarcel@end smallexample
3634130809Smarcel
3635130809Smarcel
3636130809Smarcel@kindex advance @var{location}
3637130809Smarcel@itemx advance @var{location}
3638130809SmarcelContinue running the program up to the given location.  An argument is
3639130809Smarcelrequired, anything of the same form as arguments for the @code{break}
3640130809Smarcelcommand.  Execution will also stop upon exit from the current stack
3641130809Smarcelframe.  This command is similar to @code{until}, but @code{advance} will
3642130809Smarcelnot skip over recursive function calls, and the target location doesn't
3643130809Smarcelhave to be in the same frame as the current one.
3644130809Smarcel
3645130809Smarcel
364619370Spst@kindex stepi
364798948Sobrien@kindex si @r{(@code{stepi})}
364819370Spst@item stepi
364998948Sobrien@itemx stepi @var{arg}
365019370Spst@itemx si
365119370SpstExecute one machine instruction, then stop and return to the debugger.
365219370Spst
365319370SpstIt is often useful to do @samp{display/i $pc} when stepping by machine
365419370Spstinstructions.  This makes @value{GDBN} automatically display the next
365519370Spstinstruction to be executed, each time your program stops.  @xref{Auto
365619370SpstDisplay,, Automatic display}.
365719370Spst
365819370SpstAn argument is a repeat count, as in @code{step}.
365919370Spst
366019370Spst@need 750
366119370Spst@kindex nexti
366298948Sobrien@kindex ni @r{(@code{nexti})}
366319370Spst@item nexti
366498948Sobrien@itemx nexti @var{arg}
366519370Spst@itemx ni
366619370SpstExecute one machine instruction, but if it is a function call,
366719370Spstproceed until the function returns.
366819370Spst
366919370SpstAn argument is a repeat count, as in @code{next}.
367019370Spst@end table
367119370Spst
367298948Sobrien@node Signals
367319370Spst@section Signals
367419370Spst@cindex signals
367519370Spst
367619370SpstA signal is an asynchronous event that can happen in a program.  The
367719370Spstoperating system defines the possible kinds of signals, and gives each
367819370Spstkind a name and a number.  For example, in Unix @code{SIGINT} is the
367998948Sobriensignal a program gets when you type an interrupt character (often @kbd{C-c});
368019370Spst@code{SIGSEGV} is the signal a program gets from referencing a place in
368119370Spstmemory far away from all the areas in use; @code{SIGALRM} occurs when
368219370Spstthe alarm clock timer goes off (which happens only if your program has
368319370Spstrequested an alarm).
368419370Spst
368519370Spst@cindex fatal signals
368619370SpstSome signals, including @code{SIGALRM}, are a normal part of the
368719370Spstfunctioning of your program.  Others, such as @code{SIGSEGV}, indicate
368898948Sobrienerrors; these signals are @dfn{fatal} (they kill your program immediately) if the
368919370Spstprogram has not specified in advance some other way to handle the signal.
369019370Spst@code{SIGINT} does not indicate an error in your program, but it is normally
369119370Spstfatal so it can carry out the purpose of the interrupt: to kill the program.
369219370Spst
369319370Spst@value{GDBN} has the ability to detect any occurrence of a signal in your
369419370Spstprogram.  You can tell @value{GDBN} in advance what to do for each kind of
369519370Spstsignal.
369619370Spst
369719370Spst@cindex handling signals
369898948SobrienNormally, @value{GDBN} is set up to let the non-erroneous signals like
369998948Sobrien@code{SIGALRM} be silently passed to your program
370098948Sobrien(so as not to interfere with their role in the program's functioning)
370119370Spstbut to stop your program immediately whenever an error signal happens.
370219370SpstYou can change these settings with the @code{handle} command.
370319370Spst
370419370Spst@table @code
370519370Spst@kindex info signals
370619370Spst@item info signals
370798948Sobrien@itemx info handle
370819370SpstPrint a table of all the kinds of signals and how @value{GDBN} has been told to
370919370Spsthandle each one.  You can use this to see the signal numbers of all
371019370Spstthe defined types of signals.
371119370Spst
371298948Sobrien@code{info handle} is an alias for @code{info signals}.
371319370Spst
371419370Spst@kindex handle
371519370Spst@item handle @var{signal} @var{keywords}@dots{}
371698948SobrienChange the way @value{GDBN} handles signal @var{signal}.  @var{signal}
371798948Sobriencan be the number of a signal or its name (with or without the
371898948Sobrien@samp{SIG} at the beginning); a list of signal numbers of the form
371998948Sobrien@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
372098948Sobrienknown signals.  The @var{keywords} say what change to make.
372119370Spst@end table
372219370Spst
372319370Spst@c @group
372419370SpstThe keywords allowed by the @code{handle} command can be abbreviated.
372519370SpstTheir full names are:
372619370Spst
372719370Spst@table @code
372819370Spst@item nostop
372919370Spst@value{GDBN} should not stop your program when this signal happens.  It may
373019370Spststill print a message telling you that the signal has come in.
373119370Spst
373219370Spst@item stop
373319370Spst@value{GDBN} should stop your program when this signal happens.  This implies
373419370Spstthe @code{print} keyword as well.
373519370Spst
373619370Spst@item print
373719370Spst@value{GDBN} should print a message when this signal happens.
373819370Spst
373919370Spst@item noprint
374019370Spst@value{GDBN} should not mention the occurrence of the signal at all.  This
374119370Spstimplies the @code{nostop} keyword as well.
374219370Spst
374319370Spst@item pass
374498948Sobrien@itemx noignore
374519370Spst@value{GDBN} should allow your program to see this signal; your program
374619370Spstcan handle the signal, or else it may terminate if the signal is fatal
374798948Sobrienand not handled.  @code{pass} and @code{noignore} are synonyms.
374819370Spst
374919370Spst@item nopass
375098948Sobrien@itemx ignore
375119370Spst@value{GDBN} should not allow your program to see this signal.
375298948Sobrien@code{nopass} and @code{ignore} are synonyms.
375319370Spst@end table
375419370Spst@c @end group
375519370Spst
375698948SobrienWhen a signal stops your program, the signal is not visible to the
375798948Sobrienprogram until you
375819370Spstcontinue.  Your program sees the signal then, if @code{pass} is in
375919370Spsteffect for the signal in question @emph{at that time}.  In other words,
376019370Spstafter @value{GDBN} reports a signal, you can use the @code{handle}
376119370Spstcommand with @code{pass} or @code{nopass} to control whether your
376219370Spstprogram sees that signal when you continue.
376319370Spst
376498948SobrienThe default is set to @code{nostop}, @code{noprint}, @code{pass} for
376598948Sobriennon-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
376698948Sobrien@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
376798948Sobrienerroneous signals.
376898948Sobrien
376919370SpstYou can also use the @code{signal} command to prevent your program from
377019370Spstseeing a signal, or cause it to see a signal it normally would not see,
377119370Spstor to give it any signal at any time.  For example, if your program stopped
377219370Spstdue to some sort of memory reference error, you might store correct
377319370Spstvalues into the erroneous variables and continue, hoping to see more
377419370Spstexecution; but your program would probably terminate immediately as
377519370Spsta result of the fatal signal once it saw the signal.  To prevent this,
377619370Spstyou can continue with @samp{signal 0}.  @xref{Signaling, ,Giving your
377798948Sobrienprogram a signal}.
377819370Spst
377998948Sobrien@node Thread Stops
378019370Spst@section Stopping and starting multi-thread programs
378119370Spst
378219370SpstWhen your program has multiple threads (@pxref{Threads,, Debugging
378319370Spstprograms with multiple threads}), you can choose whether to set
378419370Spstbreakpoints on all threads, or on a particular thread.
378519370Spst
378619370Spst@table @code
378719370Spst@cindex breakpoints and threads
378819370Spst@cindex thread breakpoints
378919370Spst@kindex break @dots{} thread @var{threadno}
379019370Spst@item break @var{linespec} thread @var{threadno}
379119370Spst@itemx break @var{linespec} thread @var{threadno} if @dots{}
379219370Spst@var{linespec} specifies source lines; there are several ways of
379319370Spstwriting them, but the effect is always to specify some source line.
379419370Spst
379519370SpstUse the qualifier @samp{thread @var{threadno}} with a breakpoint command
379619370Spstto specify that you only want @value{GDBN} to stop the program when a
379719370Spstparticular thread reaches this breakpoint.  @var{threadno} is one of the
379819370Spstnumeric thread identifiers assigned by @value{GDBN}, shown in the first
379919370Spstcolumn of the @samp{info threads} display.
380019370Spst
380119370SpstIf you do not specify @samp{thread @var{threadno}} when you set a
380219370Spstbreakpoint, the breakpoint applies to @emph{all} threads of your
380319370Spstprogram.
380419370Spst
380519370SpstYou can use the @code{thread} qualifier on conditional breakpoints as
380619370Spstwell; in this case, place @samp{thread @var{threadno}} before the
380719370Spstbreakpoint condition, like this:
380819370Spst
380919370Spst@smallexample
381098948Sobrien(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
381119370Spst@end smallexample
381219370Spst
381319370Spst@end table
381419370Spst
381519370Spst@cindex stopped threads
381619370Spst@cindex threads, stopped
381719370SpstWhenever your program stops under @value{GDBN} for any reason,
381819370Spst@emph{all} threads of execution stop, not just the current thread.  This
381919370Spstallows you to examine the overall state of the program, including
382019370Spstswitching between threads, without worrying that things may change
382119370Spstunderfoot.
382219370Spst
3823130809Smarcel@cindex thread breakpoints and system calls
3824130809Smarcel@cindex system calls and thread breakpoints
3825130809Smarcel@cindex premature return from system calls
3826130809SmarcelThere is an unfortunate side effect.  If one thread stops for a
3827130809Smarcelbreakpoint, or for some other reason, and another thread is blocked in a
3828130809Smarcelsystem call, then the system call may return prematurely.  This is a
3829130809Smarcelconsequence of the interaction between multiple threads and the signals
3830130809Smarcelthat @value{GDBN} uses to implement breakpoints and other events that
3831130809Smarcelstop execution.
3832130809Smarcel
3833130809SmarcelTo handle this problem, your program should check the return value of
3834130809Smarceleach system call and react appropriately.  This is good programming
3835130809Smarcelstyle anyways.
3836130809Smarcel
3837130809SmarcelFor example, do not write code like this:
3838130809Smarcel
3839130809Smarcel@smallexample
3840130809Smarcel  sleep (10);
3841130809Smarcel@end smallexample
3842130809Smarcel
3843130809SmarcelThe call to @code{sleep} will return early if a different thread stops
3844130809Smarcelat a breakpoint or for some other reason.
3845130809Smarcel
3846130809SmarcelInstead, write this:
3847130809Smarcel
3848130809Smarcel@smallexample
3849130809Smarcel  int unslept = 10;
3850130809Smarcel  while (unslept > 0)
3851130809Smarcel    unslept = sleep (unslept);
3852130809Smarcel@end smallexample
3853130809Smarcel
3854130809SmarcelA system call is allowed to return early, so the system is still
3855130809Smarcelconforming to its specification.  But @value{GDBN} does cause your
3856130809Smarcelmulti-threaded program to behave differently than it would without
3857130809Smarcel@value{GDBN}.
3858130809Smarcel
3859130809SmarcelAlso, @value{GDBN} uses internal breakpoints in the thread library to
3860130809Smarcelmonitor certain events such as thread creation and thread destruction.
3861130809SmarcelWhen such an event happens, a system call in another thread may return
3862130809Smarcelprematurely, even though your program does not appear to stop.
3863130809Smarcel
386419370Spst@cindex continuing threads
386519370Spst@cindex threads, continuing
386619370SpstConversely, whenever you restart the program, @emph{all} threads start
386719370Spstexecuting.  @emph{This is true even when single-stepping} with commands
386898948Sobrienlike @code{step} or @code{next}.
386919370Spst
387019370SpstIn particular, @value{GDBN} cannot single-step all threads in lockstep.
387119370SpstSince thread scheduling is up to your debugging target's operating
387219370Spstsystem (not controlled by @value{GDBN}), other threads may
387319370Spstexecute more than one statement while the current thread completes a
387419370Spstsingle step.  Moreover, in general other threads stop in the middle of a
387519370Spststatement, rather than at a clean statement boundary, when the program
387619370Spststops.
387719370Spst
387819370SpstYou might even find your program stopped in another thread after
387919370Spstcontinuing or even single-stepping.  This happens whenever some other
388019370Spstthread runs into a breakpoint, a signal, or an exception before the
388119370Spstfirst thread completes whatever you requested.
388246289Sdfr
388346289SdfrOn some OSes, you can lock the OS scheduler and thus allow only a single
388446289Sdfrthread to run.
388546289Sdfr
388646289Sdfr@table @code
388746289Sdfr@item set scheduler-locking @var{mode}
388846289SdfrSet the scheduler locking mode.  If it is @code{off}, then there is no
388946289Sdfrlocking and any thread may run at any time.  If @code{on}, then only the
389046289Sdfrcurrent thread may run when the inferior is resumed.  The @code{step}
389146289Sdfrmode optimizes for single-stepping.  It stops other threads from
389246289Sdfr``seizing the prompt'' by preempting the current thread while you are
389346289Sdfrstepping.  Other threads will only rarely (or never) get a chance to run
389498948Sobrienwhen you step.  They are more likely to run when you @samp{next} over a
389546289Sdfrfunction call, and they are completely free to run when you use commands
389698948Sobrienlike @samp{continue}, @samp{until}, or @samp{finish}.  However, unless another
389746289Sdfrthread hits a breakpoint during its timeslice, they will never steal the
389898948Sobrien@value{GDBN} prompt away from the thread that you are debugging.
389946289Sdfr
390046289Sdfr@item show scheduler-locking
390146289SdfrDisplay the current scheduler locking mode.
390246289Sdfr@end table
390346289Sdfr
390419370Spst
390598948Sobrien@node Stack
390619370Spst@chapter Examining the Stack
390719370Spst
390819370SpstWhen your program has stopped, the first thing you need to know is where it
390919370Spststopped and how it got there.
391019370Spst
391119370Spst@cindex call stack
391298948SobrienEach time your program performs a function call, information about the call
391398948Sobrienis generated.
391498948SobrienThat information includes the location of the call in your program,
391598948Sobrienthe arguments of the call,
391619370Spstand the local variables of the function being called.
391798948SobrienThe information is saved in a block of data called a @dfn{stack frame}.
391819370SpstThe stack frames are allocated in a region of memory called the @dfn{call
391919370Spststack}.
392019370Spst
392119370SpstWhen your program stops, the @value{GDBN} commands for examining the
392219370Spststack allow you to see all of this information.
392319370Spst
392419370Spst@cindex selected frame
392519370SpstOne of the stack frames is @dfn{selected} by @value{GDBN} and many
392619370Spst@value{GDBN} commands refer implicitly to the selected frame.  In
392719370Spstparticular, whenever you ask @value{GDBN} for the value of a variable in
392819370Spstyour program, the value is found in the selected frame.  There are
392919370Spstspecial @value{GDBN} commands to select whichever frame you are
393019370Spstinterested in. @xref{Selection, ,Selecting a frame}.
393119370Spst
393219370SpstWhen your program stops, @value{GDBN} automatically selects the
393398948Sobriencurrently executing frame and describes it briefly, similar to the
393419370Spst@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
393519370Spst
393619370Spst@menu
393719370Spst* Frames::                      Stack frames
393819370Spst* Backtrace::                   Backtraces
393919370Spst* Selection::                   Selecting a frame
394019370Spst* Frame Info::                  Information on a frame
394146289Sdfr
394219370Spst@end menu
394319370Spst
394498948Sobrien@node Frames
394519370Spst@section Stack frames
394619370Spst
394798948Sobrien@cindex frame, definition
394819370Spst@cindex stack frame
394919370SpstThe call stack is divided up into contiguous pieces called @dfn{stack
395019370Spstframes}, or @dfn{frames} for short; each frame is the data associated
395119370Spstwith one call to one function.  The frame contains the arguments given
395219370Spstto the function, the function's local variables, and the address at
395319370Spstwhich the function is executing.
395419370Spst
395519370Spst@cindex initial frame
395619370Spst@cindex outermost frame
395719370Spst@cindex innermost frame
395819370SpstWhen your program is started, the stack has only one frame, that of the
395919370Spstfunction @code{main}.  This is called the @dfn{initial} frame or the
396019370Spst@dfn{outermost} frame.  Each time a function is called, a new frame is
396119370Spstmade.  Each time a function returns, the frame for that function invocation
396219370Spstis eliminated.  If a function is recursive, there can be many frames for
396319370Spstthe same function.  The frame for the function in which execution is
396419370Spstactually occurring is called the @dfn{innermost} frame.  This is the most
396519370Spstrecently created of all the stack frames that still exist.
396619370Spst
396719370Spst@cindex frame pointer
396819370SpstInside your program, stack frames are identified by their addresses.  A
396919370Spststack frame consists of many bytes, each of which has its own address; each
397019370Spstkind of computer has a convention for choosing one byte whose
397119370Spstaddress serves as the address of the frame.  Usually this address is kept
397219370Spstin a register called the @dfn{frame pointer register} while execution is
397319370Spstgoing on in that frame.
397419370Spst
397519370Spst@cindex frame number
397619370Spst@value{GDBN} assigns numbers to all existing stack frames, starting with
397719370Spstzero for the innermost frame, one for the frame that called it,
397819370Spstand so on upward.  These numbers do not really exist in your program;
397919370Spstthey are assigned by @value{GDBN} to give you a way of designating stack
398019370Spstframes in @value{GDBN} commands.
398119370Spst
398298948Sobrien@c The -fomit-frame-pointer below perennially causes hbox overflow
398398948Sobrien@c underflow problems.
398419370Spst@cindex frameless execution
398519370SpstSome compilers provide a way to compile functions so that they operate
398698948Sobrienwithout stack frames.  (For example, the @value{GCC} option
3987130809Smarcel@smallexample
398898948Sobrien@samp{-fomit-frame-pointer}
3989130809Smarcel@end smallexample
399098948Sobriengenerates functions without a frame.)
399119370SpstThis is occasionally done with heavily used library functions to save
399219370Spstthe frame setup time.  @value{GDBN} has limited facilities for dealing
399319370Spstwith these function invocations.  If the innermost function invocation
399419370Spsthas no stack frame, @value{GDBN} nevertheless regards it as though
399519370Spstit had a separate frame, which is numbered zero as usual, allowing
399619370Spstcorrect tracing of the function call chain.  However, @value{GDBN} has
399719370Spstno provision for frameless functions elsewhere in the stack.
399819370Spst
399919370Spst@table @code
400098948Sobrien@kindex frame@r{, command}
400198948Sobrien@cindex current stack frame
400219370Spst@item frame @var{args}
400398948SobrienThe @code{frame} command allows you to move from one stack frame to another,
400419370Spstand to print the stack frame you select.  @var{args} may be either the
400598948Sobrienaddress of the frame or the stack frame number.  Without an argument,
400698948Sobrien@code{frame} prints the current stack frame.
400719370Spst
400819370Spst@kindex select-frame
400998948Sobrien@cindex selecting frame silently
401019370Spst@item select-frame
401119370SpstThe @code{select-frame} command allows you to move from one stack frame
401219370Spstto another without printing the frame.  This is the silent version of
401319370Spst@code{frame}.
401419370Spst@end table
401519370Spst
401698948Sobrien@node Backtrace
401719370Spst@section Backtraces
401819370Spst
401946289Sdfr@cindex backtraces
402046289Sdfr@cindex tracebacks
402146289Sdfr@cindex stack traces
402219370SpstA backtrace is a summary of how your program got where it is.  It shows one
402319370Spstline per frame, for many frames, starting with the currently executing
402419370Spstframe (frame zero), followed by its caller (frame one), and on up the
402519370Spststack.
402619370Spst
402719370Spst@table @code
402819370Spst@kindex backtrace
402998948Sobrien@kindex bt @r{(@code{backtrace})}
403019370Spst@item backtrace
403119370Spst@itemx bt
403219370SpstPrint a backtrace of the entire stack: one line per frame for all
403319370Spstframes in the stack.
403419370Spst
403519370SpstYou can stop the backtrace at any time by typing the system interrupt
403619370Spstcharacter, normally @kbd{C-c}.
403719370Spst
403819370Spst@item backtrace @var{n}
403919370Spst@itemx bt @var{n}
404019370SpstSimilar, but print only the innermost @var{n} frames.
404119370Spst
404219370Spst@item backtrace -@var{n}
404319370Spst@itemx bt -@var{n}
404419370SpstSimilar, but print only the outermost @var{n} frames.
404519370Spst@end table
404619370Spst
404719370Spst@kindex where
404819370Spst@kindex info stack
404998948Sobrien@kindex info s @r{(@code{info stack})}
405019370SpstThe names @code{where} and @code{info stack} (abbreviated @code{info s})
405119370Spstare additional aliases for @code{backtrace}.
405219370Spst
405319370SpstEach line in the backtrace shows the frame number and the function name.
405419370SpstThe program counter value is also shown---unless you use @code{set
405519370Spstprint address off}.  The backtrace also shows the source file name and
405619370Spstline number, as well as the arguments to the function.  The program
405719370Spstcounter value is omitted if it is at the beginning of the code for that
405819370Spstline number.
405919370Spst
406019370SpstHere is an example of a backtrace.  It was made with the command
406119370Spst@samp{bt 3}, so it shows the innermost three frames.
406219370Spst
406319370Spst@smallexample
406419370Spst@group
406598948Sobrien#0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
406619370Spst    at builtin.c:993
406719370Spst#1  0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
406819370Spst#2  0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
406919370Spst    at macro.c:71
407019370Spst(More stack frames follow...)
407119370Spst@end group
407219370Spst@end smallexample
407319370Spst
407419370Spst@noindent
407519370SpstThe display for frame zero does not begin with a program counter
407619370Spstvalue, indicating that your program has stopped at the beginning of the
407719370Spstcode for line @code{993} of @code{builtin.c}.
407819370Spst
4079130809Smarcel@kindex set backtrace past-main
4080130809Smarcel@kindex show backtrace past-main
4081130809Smarcel@kindex set backtrace limit
4082130809Smarcel@kindex show backtrace limit
4083130809Smarcel
4084130809SmarcelMost programs have a standard user entry point---a place where system
4085130809Smarcellibraries and startup code transition into user code.  For C this is
4086130809Smarcel@code{main}.  When @value{GDBN} finds the entry function in a backtrace
4087130809Smarcelit will terminate the backtrace, to avoid tracing into highly
4088130809Smarcelsystem-specific (and generally uninteresting) code.
4089130809Smarcel
4090130809SmarcelIf you need to examine the startup code, or limit the number of levels
4091130809Smarcelin a backtrace, you can change this behavior:
4092130809Smarcel
4093130809Smarcel@table @code
4094130809Smarcel@item set backtrace past-main
4095130809Smarcel@itemx set backtrace past-main on
4096130809SmarcelBacktraces will continue past the user entry point.
4097130809Smarcel
4098130809Smarcel@item set backtrace past-main off
4099130809SmarcelBacktraces will stop when they encounter the user entry point.  This is the
4100130809Smarceldefault.
4101130809Smarcel
4102130809Smarcel@item show backtrace past-main
4103130809SmarcelDisplay the current user entry point backtrace policy.
4104130809Smarcel
4105130809Smarcel@item set backtrace limit @var{n}
4106130809Smarcel@itemx set backtrace limit 0
4107130809Smarcel@cindex backtrace limit
4108130809SmarcelLimit the backtrace to @var{n} levels.  A value of zero means
4109130809Smarcelunlimited.
4110130809Smarcel
4111130809Smarcel@item show backtrace limit
4112130809SmarcelDisplay the current limit on backtrace levels.
4113130809Smarcel@end table
4114130809Smarcel
411598948Sobrien@node Selection
411619370Spst@section Selecting a frame
411719370Spst
411819370SpstMost commands for examining the stack and other data in your program work on
411919370Spstwhichever stack frame is selected at the moment.  Here are the commands for
412019370Spstselecting a stack frame; all of them finish by printing a brief description
412119370Spstof the stack frame just selected.
412219370Spst
412319370Spst@table @code
412498948Sobrien@kindex frame@r{, selecting}
412598948Sobrien@kindex f @r{(@code{frame})}
412619370Spst@item frame @var{n}
412719370Spst@itemx f @var{n}
412819370SpstSelect frame number @var{n}.  Recall that frame zero is the innermost
412919370Spst(currently executing) frame, frame one is the frame that called the
413019370Spstinnermost one, and so on.  The highest-numbered frame is the one for
413119370Spst@code{main}.
413219370Spst
413319370Spst@item frame @var{addr}
413419370Spst@itemx f @var{addr}
413519370SpstSelect the frame at address @var{addr}.  This is useful mainly if the
413619370Spstchaining of stack frames has been damaged by a bug, making it
413719370Spstimpossible for @value{GDBN} to assign numbers properly to all frames.  In
413819370Spstaddition, this can be useful when your program has multiple stacks and
413919370Spstswitches between them.
414019370Spst
414119370SpstOn the SPARC architecture, @code{frame} needs two addresses to
414219370Spstselect an arbitrary frame: a frame pointer and a stack pointer.
414319370Spst
414419370SpstOn the MIPS and Alpha architecture, it needs two addresses: a stack
414519370Spstpointer and a program counter.
414619370Spst
414719370SpstOn the 29k architecture, it needs three addresses: a register stack
414819370Spstpointer, a program counter, and a memory stack pointer.
414919370Spst@c note to future updaters: this is conditioned on a flag
415019370Spst@c SETUP_ARBITRARY_FRAME in the tm-*.h files.  The above is up to date
415119370Spst@c as of 27 Jan 1994.
415219370Spst
415319370Spst@kindex up
415419370Spst@item up @var{n}
415519370SpstMove @var{n} frames up the stack.  For positive numbers @var{n}, this
415619370Spstadvances toward the outermost frame, to higher frame numbers, to frames
415719370Spstthat have existed longer.  @var{n} defaults to one.
415819370Spst
415919370Spst@kindex down
416098948Sobrien@kindex do @r{(@code{down})}
416119370Spst@item down @var{n}
416219370SpstMove @var{n} frames down the stack.  For positive numbers @var{n}, this
416319370Spstadvances toward the innermost frame, to lower frame numbers, to frames
416419370Spstthat were created more recently.  @var{n} defaults to one.  You may
416519370Spstabbreviate @code{down} as @code{do}.
416619370Spst@end table
416719370Spst
416819370SpstAll of these commands end by printing two lines of output describing the
416919370Spstframe.  The first line shows the frame number, the function name, the
417019370Spstarguments, and the source file and line number of execution in that
417198948Sobrienframe.  The second line shows the text of that source line.
417219370Spst
417319370Spst@need 1000
417419370SpstFor example:
417519370Spst
417619370Spst@smallexample
417719370Spst@group
417819370Spst(@value{GDBP}) up
417919370Spst#1  0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
418019370Spst    at env.c:10
418119370Spst10              read_input_file (argv[i]);
418219370Spst@end group
418319370Spst@end smallexample
418419370Spst
418519370SpstAfter such a printout, the @code{list} command with no arguments
418619370Spstprints ten lines centered on the point of execution in the frame.
4187130809SmarcelYou can also edit the program at the point of execution with your favorite
4188130809Smarcelediting program by typing @code{edit}.
4189130809Smarcel@xref{List, ,Printing source lines},
4190130809Smarcelfor details.
419119370Spst
419219370Spst@table @code
419319370Spst@kindex down-silently
419419370Spst@kindex up-silently
419519370Spst@item up-silently @var{n}
419619370Spst@itemx down-silently @var{n}
419719370SpstThese two commands are variants of @code{up} and @code{down},
419819370Spstrespectively; they differ in that they do their work silently, without
419919370Spstcausing display of the new frame.  They are intended primarily for use
420019370Spstin @value{GDBN} command scripts, where the output might be unnecessary and
420119370Spstdistracting.
420219370Spst@end table
420319370Spst
420498948Sobrien@node Frame Info
420519370Spst@section Information about a frame
420619370Spst
420719370SpstThere are several other commands to print information about the selected
420819370Spststack frame.
420919370Spst
421019370Spst@table @code
421119370Spst@item frame
421219370Spst@itemx f
421319370SpstWhen used without any argument, this command does not change which
421419370Spstframe is selected, but prints a brief description of the currently
421519370Spstselected stack frame.  It can be abbreviated @code{f}.  With an
421619370Spstargument, this command is used to select a stack frame.
421719370Spst@xref{Selection, ,Selecting a frame}.
421819370Spst
421919370Spst@kindex info frame
422098948Sobrien@kindex info f @r{(@code{info frame})}
422119370Spst@item info frame
422219370Spst@itemx info f
422319370SpstThis command prints a verbose description of the selected stack frame,
422419370Spstincluding:
422519370Spst
422619370Spst@itemize @bullet
422719370Spst@item
422898948Sobrienthe address of the frame
422998948Sobrien@item
423019370Spstthe address of the next frame down (called by this frame)
423119370Spst@item
423219370Spstthe address of the next frame up (caller of this frame)
423319370Spst@item
423419370Spstthe language in which the source code corresponding to this frame is written
423519370Spst@item
423619370Spstthe address of the frame's arguments
423719370Spst@item
423898948Sobrienthe address of the frame's local variables
423998948Sobrien@item
424019370Spstthe program counter saved in it (the address of execution in the caller frame)
424119370Spst@item
424219370Spstwhich registers were saved in the frame
424319370Spst@end itemize
424419370Spst
424519370Spst@noindent The verbose description is useful when
424619370Spstsomething has gone wrong that has made the stack format fail to fit
424719370Spstthe usual conventions.
424819370Spst
424919370Spst@item info frame @var{addr}
425019370Spst@itemx info f @var{addr}
425119370SpstPrint a verbose description of the frame at address @var{addr}, without
425219370Spstselecting that frame.  The selected frame remains unchanged by this
425319370Spstcommand.  This requires the same kind of address (more than one for some
425419370Spstarchitectures) that you specify in the @code{frame} command.
425519370Spst@xref{Selection, ,Selecting a frame}.
425619370Spst
425719370Spst@kindex info args
425819370Spst@item info args
425919370SpstPrint the arguments of the selected frame, each on a separate line.
426019370Spst
426119370Spst@item info locals
426219370Spst@kindex info locals
426319370SpstPrint the local variables of the selected frame, each on a separate
426419370Spstline.  These are all variables (declared either static or automatic)
426519370Spstaccessible at the point of execution of the selected frame.
426619370Spst
426719370Spst@kindex info catch
426898948Sobrien@cindex catch exceptions, list active handlers
426998948Sobrien@cindex exception handlers, how to list
427019370Spst@item info catch
427119370SpstPrint a list of all the exception handlers that are active in the
427219370Spstcurrent stack frame at the current point of execution.  To see other
427319370Spstexception handlers, visit the associated frame (using the @code{up},
427419370Spst@code{down}, or @code{frame} commands); then type @code{info catch}.
427546289Sdfr@xref{Set Catchpoints, , Setting catchpoints}.
427619370Spst
427719370Spst@end table
427819370Spst
427919370Spst
428098948Sobrien@node Source
428119370Spst@chapter Examining Source Files
428219370Spst
428319370Spst@value{GDBN} can print parts of your program's source, since the debugging
428419370Spstinformation recorded in the program tells @value{GDBN} what source files were
428519370Spstused to build it.  When your program stops, @value{GDBN} spontaneously prints
428619370Spstthe line where it stopped.  Likewise, when you select a stack frame
428719370Spst(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
428819370Spstexecution in that frame has stopped.  You can print other portions of
428919370Spstsource files by explicit command.
429019370Spst
429198948SobrienIf you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
429298948Sobrienprefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
429398948Sobrien@value{GDBN} under @sc{gnu} Emacs}.
429419370Spst
429519370Spst@menu
429619370Spst* List::                        Printing source lines
4297130809Smarcel* Edit::                        Editing source files
429819370Spst* Search::                      Searching source files
429919370Spst* Source Path::                 Specifying source directories
430019370Spst* Machine Code::                Source and machine code
430119370Spst@end menu
430219370Spst
430398948Sobrien@node List
430419370Spst@section Printing source lines
430519370Spst
430619370Spst@kindex list
430798948Sobrien@kindex l @r{(@code{list})}
430819370SpstTo print lines from a source file, use the @code{list} command
430998948Sobrien(abbreviated @code{l}).  By default, ten lines are printed.
431019370SpstThere are several ways to specify what part of the file you want to print.
431119370Spst
431219370SpstHere are the forms of the @code{list} command most commonly used:
431319370Spst
431419370Spst@table @code
431519370Spst@item list @var{linenum}
431619370SpstPrint lines centered around line number @var{linenum} in the
431719370Spstcurrent source file.
431819370Spst
431919370Spst@item list @var{function}
432019370SpstPrint lines centered around the beginning of function
432119370Spst@var{function}.
432219370Spst
432319370Spst@item list
432419370SpstPrint more lines.  If the last lines printed were printed with a
432519370Spst@code{list} command, this prints lines following the last lines
432619370Spstprinted; however, if the last line printed was a solitary line printed
432719370Spstas part of displaying a stack frame (@pxref{Stack, ,Examining the
432819370SpstStack}), this prints lines centered around that line.
432919370Spst
433019370Spst@item list -
433119370SpstPrint lines just before the lines last printed.
433219370Spst@end table
433319370Spst
433419370SpstBy default, @value{GDBN} prints ten source lines with any of these forms of
433519370Spstthe @code{list} command.  You can change this using @code{set listsize}:
433619370Spst
433719370Spst@table @code
433819370Spst@kindex set listsize
433919370Spst@item set listsize @var{count}
434019370SpstMake the @code{list} command display @var{count} source lines (unless
434119370Spstthe @code{list} argument explicitly specifies some other number).
434219370Spst
434319370Spst@kindex show listsize
434419370Spst@item show listsize
434519370SpstDisplay the number of lines that @code{list} prints.
434619370Spst@end table
434719370Spst
434819370SpstRepeating a @code{list} command with @key{RET} discards the argument,
434919370Spstso it is equivalent to typing just @code{list}.  This is more useful
435019370Spstthan listing the same lines again.  An exception is made for an
435119370Spstargument of @samp{-}; that argument is preserved in repetition so that
435219370Spsteach repetition moves up in the source file.
435319370Spst
435419370Spst@cindex linespec
435519370SpstIn general, the @code{list} command expects you to supply zero, one or two
435619370Spst@dfn{linespecs}.  Linespecs specify source lines; there are several ways
435798948Sobrienof writing them, but the effect is always to specify some source line.
435819370SpstHere is a complete description of the possible arguments for @code{list}:
435919370Spst
436019370Spst@table @code
436119370Spst@item list @var{linespec}
436219370SpstPrint lines centered around the line specified by @var{linespec}.
436319370Spst
436419370Spst@item list @var{first},@var{last}
436519370SpstPrint lines from @var{first} to @var{last}.  Both arguments are
436619370Spstlinespecs.
436719370Spst
436819370Spst@item list ,@var{last}
436919370SpstPrint lines ending with @var{last}.
437019370Spst
437119370Spst@item list @var{first},
437219370SpstPrint lines starting with @var{first}.
437319370Spst
437419370Spst@item list +
437519370SpstPrint lines just after the lines last printed.
437619370Spst
437719370Spst@item list -
437819370SpstPrint lines just before the lines last printed.
437919370Spst
438019370Spst@item list
438119370SpstAs described in the preceding table.
438219370Spst@end table
438319370Spst
438419370SpstHere are the ways of specifying a single source line---all the
438519370Spstkinds of linespec.
438619370Spst
438719370Spst@table @code
438819370Spst@item @var{number}
438919370SpstSpecifies line @var{number} of the current source file.
439019370SpstWhen a @code{list} command has two linespecs, this refers to
439119370Spstthe same source file as the first linespec.
439219370Spst
439319370Spst@item +@var{offset}
439419370SpstSpecifies the line @var{offset} lines after the last line printed.
439519370SpstWhen used as the second linespec in a @code{list} command that has
439619370Spsttwo, this specifies the line @var{offset} lines down from the
439719370Spstfirst linespec.
439819370Spst
439919370Spst@item -@var{offset}
440019370SpstSpecifies the line @var{offset} lines before the last line printed.
440119370Spst
440219370Spst@item @var{filename}:@var{number}
440319370SpstSpecifies line @var{number} in the source file @var{filename}.
440419370Spst
440519370Spst@item @var{function}
440619370SpstSpecifies the line that begins the body of the function @var{function}.
440719370SpstFor example: in C, this is the line with the open brace.
440819370Spst
440919370Spst@item @var{filename}:@var{function}
441019370SpstSpecifies the line of the open-brace that begins the body of the
441119370Spstfunction @var{function} in the file @var{filename}.  You only need the
441219370Spstfile name with a function name to avoid ambiguity when there are
441319370Spstidentically named functions in different source files.
441419370Spst
441519370Spst@item *@var{address}
441619370SpstSpecifies the line containing the program address @var{address}.
441719370Spst@var{address} may be any expression.
441819370Spst@end table
441919370Spst
4420130809Smarcel@node Edit
4421130809Smarcel@section Editing source files
4422130809Smarcel@cindex editing source files
4423130809Smarcel
4424130809Smarcel@kindex edit
4425130809Smarcel@kindex e @r{(@code{edit})}
4426130809SmarcelTo edit the lines in a source file, use the @code{edit} command.
4427130809SmarcelThe editing program of your choice
4428130809Smarcelis invoked with the current line set to
4429130809Smarcelthe active line in the program.
4430130809SmarcelAlternatively, there are several ways to specify what part of the file you
4431130809Smarcelwant to print if you want to see other parts of the program.
4432130809Smarcel
4433130809SmarcelHere are the forms of the @code{edit} command most commonly used:
4434130809Smarcel
4435130809Smarcel@table @code
4436130809Smarcel@item edit
4437130809SmarcelEdit the current source file at the active line number in the program.
4438130809Smarcel
4439130809Smarcel@item edit @var{number}
4440130809SmarcelEdit the current source file with @var{number} as the active line number.
4441130809Smarcel
4442130809Smarcel@item edit @var{function}
4443130809SmarcelEdit the file containing @var{function} at the beginning of its definition.
4444130809Smarcel
4445130809Smarcel@item edit @var{filename}:@var{number}
4446130809SmarcelSpecifies line @var{number} in the source file @var{filename}.
4447130809Smarcel
4448130809Smarcel@item edit @var{filename}:@var{function}
4449130809SmarcelSpecifies the line that begins the body of the
4450130809Smarcelfunction @var{function} in the file @var{filename}.  You only need the
4451130809Smarcelfile name with a function name to avoid ambiguity when there are
4452130809Smarcelidentically named functions in different source files.
4453130809Smarcel
4454130809Smarcel@item edit *@var{address}
4455130809SmarcelSpecifies the line containing the program address @var{address}.
4456130809Smarcel@var{address} may be any expression.
4457130809Smarcel@end table
4458130809Smarcel
4459130809Smarcel@subsection Choosing your editor
4460130809SmarcelYou can customize @value{GDBN} to use any editor you want
4461130809Smarcel@footnote{
4462130809SmarcelThe only restriction is that your editor (say @code{ex}), recognizes the
4463130809Smarcelfollowing command-line syntax:
4464130809Smarcel@smallexample
4465130809Smarcelex +@var{number} file
4466130809Smarcel@end smallexample
4467130809SmarcelThe optional numeric value +@var{number} designates the active line in
4468130809Smarcelthe file.}.  By default, it is @value{EDITOR}, but you can change this
4469130809Smarcelby setting the environment variable @code{EDITOR} before using
4470130809Smarcel@value{GDBN}.  For example, to configure @value{GDBN} to use the
4471130809Smarcel@code{vi} editor, you could use these commands with the @code{sh} shell:
4472130809Smarcel@smallexample
4473130809SmarcelEDITOR=/usr/bin/vi
4474130809Smarcelexport EDITOR
4475130809Smarcelgdb ...
4476130809Smarcel@end smallexample
4477130809Smarcelor in the @code{csh} shell,
4478130809Smarcel@smallexample
4479130809Smarcelsetenv EDITOR /usr/bin/vi
4480130809Smarcelgdb ...
4481130809Smarcel@end smallexample
4482130809Smarcel
448398948Sobrien@node Search
448419370Spst@section Searching source files
448519370Spst@cindex searching
448619370Spst@kindex reverse-search
448719370Spst
448819370SpstThere are two commands for searching through the current source file for a
448919370Spstregular expression.
449019370Spst
449119370Spst@table @code
449219370Spst@kindex search
449319370Spst@kindex forward-search
449419370Spst@item forward-search @var{regexp}
449519370Spst@itemx search @var{regexp}
449619370SpstThe command @samp{forward-search @var{regexp}} checks each line,
449719370Spststarting with the one following the last line listed, for a match for
449898948Sobrien@var{regexp}.  It lists the line that is found.  You can use the
449919370Spstsynonym @samp{search @var{regexp}} or abbreviate the command name as
450019370Spst@code{fo}.
450119370Spst
450219370Spst@item reverse-search @var{regexp}
450319370SpstThe command @samp{reverse-search @var{regexp}} checks each line, starting
450419370Spstwith the one before the last line listed and going backward, for a match
450519370Spstfor @var{regexp}.  It lists the line that is found.  You can abbreviate
450619370Spstthis command as @code{rev}.
450719370Spst@end table
450819370Spst
450998948Sobrien@node Source Path
451019370Spst@section Specifying source directories
451119370Spst
451219370Spst@cindex source path
451319370Spst@cindex directories for source files
451419370SpstExecutable programs sometimes do not record the directories of the source
451519370Spstfiles from which they were compiled, just the names.  Even when they do,
451619370Spstthe directories could be moved between the compilation and your debugging
451719370Spstsession.  @value{GDBN} has a list of directories to search for source files;
451819370Spstthis is called the @dfn{source path}.  Each time @value{GDBN} wants a source file,
451919370Spstit tries all the directories in the list, in the order they are present
452019370Spstin the list, until it finds a file with the desired name.  Note that
452119370Spstthe executable search path is @emph{not} used for this purpose.  Neither is
452219370Spstthe current working directory, unless it happens to be in the source
452319370Spstpath.
452419370Spst
452519370SpstIf @value{GDBN} cannot find a source file in the source path, and the
452619370Spstobject program records a directory, @value{GDBN} tries that directory
452719370Spsttoo.  If the source path is empty, and there is no record of the
452819370Spstcompilation directory, @value{GDBN} looks in the current directory as a
452919370Spstlast resort.
453019370Spst
453119370SpstWhenever you reset or rearrange the source path, @value{GDBN} clears out
453219370Spstany information it has cached about where source files are found and where
453319370Spsteach line is in the file.
453419370Spst
453519370Spst@kindex directory
453619370Spst@kindex dir
453798948SobrienWhen you start @value{GDBN}, its source path includes only @samp{cdir}
453898948Sobrienand @samp{cwd}, in that order.
453919370SpstTo add other directories, use the @code{directory} command.
454019370Spst
454119370Spst@table @code
454219370Spst@item directory @var{dirname} @dots{}
454319370Spst@item dir @var{dirname} @dots{}
454419370SpstAdd directory @var{dirname} to the front of the source path.  Several
454598948Sobriendirectory names may be given to this command, separated by @samp{:}
454698948Sobrien(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
454798948Sobrienpart of absolute file names) or
454819370Spstwhitespace.  You may specify a directory that is already in the source
454919370Spstpath; this moves it forward, so @value{GDBN} searches it sooner.
455019370Spst
455119370Spst@kindex cdir
455219370Spst@kindex cwd
455398948Sobrien@vindex $cdir@r{, convenience variable}
455498948Sobrien@vindex $cwdr@r{, convenience variable}
455519370Spst@cindex compilation directory
455619370Spst@cindex current directory
455719370Spst@cindex working directory
455819370Spst@cindex directory, current
455919370Spst@cindex directory, compilation
456019370SpstYou can use the string @samp{$cdir} to refer to the compilation
456119370Spstdirectory (if one is recorded), and @samp{$cwd} to refer to the current
456219370Spstworking directory.  @samp{$cwd} is not the same as @samp{.}---the former
456319370Spsttracks the current working directory as it changes during your @value{GDBN}
456419370Spstsession, while the latter is immediately expanded to the current
456519370Spstdirectory at the time you add an entry to the source path.
456619370Spst
456719370Spst@item directory
456819370SpstReset the source path to empty again.  This requires confirmation.
456919370Spst
457019370Spst@c RET-repeat for @code{directory} is explicitly disabled, but since
457119370Spst@c repeating it would be a no-op we do not say that.  (thanks to RMS)
457219370Spst
457319370Spst@item show directories
457419370Spst@kindex show directories
457519370SpstPrint the source path: show which directories it contains.
457619370Spst@end table
457719370Spst
457819370SpstIf your source path is cluttered with directories that are no longer of
457919370Spstinterest, @value{GDBN} may sometimes cause confusion by finding the wrong
458019370Spstversions of source.  You can correct the situation as follows:
458119370Spst
458219370Spst@enumerate
458319370Spst@item
458419370SpstUse @code{directory} with no argument to reset the source path to empty.
458519370Spst
458619370Spst@item
458719370SpstUse @code{directory} with suitable arguments to reinstall the
458819370Spstdirectories you want in the source path.  You can add all the
458919370Spstdirectories in one command.
459019370Spst@end enumerate
459119370Spst
459298948Sobrien@node Machine Code
459319370Spst@section Source and machine code
459419370Spst
459519370SpstYou can use the command @code{info line} to map source lines to program
459619370Spstaddresses (and vice versa), and the command @code{disassemble} to display
459719370Spsta range of addresses as machine instructions.  When run under @sc{gnu} Emacs
459898948Sobrienmode, the @code{info line} command causes the arrow to point to the
459998948Sobrienline specified.  Also, @code{info line} prints addresses in symbolic form as
460019370Spstwell as hex.
460119370Spst
460219370Spst@table @code
460319370Spst@kindex info line
460419370Spst@item info line @var{linespec}
460519370SpstPrint the starting and ending addresses of the compiled code for
460619370Spstsource line @var{linespec}.  You can specify source lines in any of
460719370Spstthe ways understood by the @code{list} command (@pxref{List, ,Printing
460819370Spstsource lines}).
460919370Spst@end table
461019370Spst
461119370SpstFor example, we can use @code{info line} to discover the location of
461219370Spstthe object code for the first line of function
461319370Spst@code{m4_changequote}:
461419370Spst
461598948Sobrien@c FIXME: I think this example should also show the addresses in
461698948Sobrien@c symbolic form, as they usually would be displayed.
461719370Spst@smallexample
461898948Sobrien(@value{GDBP}) info line m4_changequote
461919370SpstLine 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
462019370Spst@end smallexample
462119370Spst
462219370Spst@noindent
462319370SpstWe can also inquire (using @code{*@var{addr}} as the form for
462419370Spst@var{linespec}) what source line covers a particular address:
462519370Spst@smallexample
462619370Spst(@value{GDBP}) info line *0x63ff
462719370SpstLine 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
462819370Spst@end smallexample
462919370Spst
463019370Spst@cindex @code{$_} and @code{info line}
463198948Sobrien@kindex x@r{(examine), and} info line
463219370SpstAfter @code{info line}, the default address for the @code{x} command
463319370Spstis changed to the starting address of the line, so that @samp{x/i} is
463419370Spstsufficient to begin examining the machine code (@pxref{Memory,
463519370Spst,Examining memory}).  Also, this address is saved as the value of the
463619370Spstconvenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
463719370Spstvariables}).
463819370Spst
463919370Spst@table @code
464019370Spst@kindex disassemble
464119370Spst@cindex assembly instructions
464219370Spst@cindex instructions, assembly
464319370Spst@cindex machine instructions
464419370Spst@cindex listing machine instructions
464519370Spst@item disassemble
464619370SpstThis specialized command dumps a range of memory as machine
464719370Spstinstructions.  The default memory range is the function surrounding the
464819370Spstprogram counter of the selected frame.  A single argument to this
464919370Spstcommand is a program counter value; @value{GDBN} dumps the function
465019370Spstsurrounding this value.  Two arguments specify a range of addresses
465119370Spst(first inclusive, second exclusive) to dump.
465219370Spst@end table
465319370Spst
465446289SdfrThe following example shows the disassembly of a range of addresses of
465546289SdfrHP PA-RISC 2.0 code:
465619370Spst
465719370Spst@smallexample
465846289Sdfr(@value{GDBP}) disas 0x32c4 0x32e4
465946289SdfrDump of assembler code from 0x32c4 to 0x32e4:
466046289Sdfr0x32c4 <main+204>:      addil 0,dp
466146289Sdfr0x32c8 <main+208>:      ldw 0x22c(sr0,r1),r26
466246289Sdfr0x32cc <main+212>:      ldil 0x3000,r31
466346289Sdfr0x32d0 <main+216>:      ble 0x3f8(sr4,r31)
466446289Sdfr0x32d4 <main+220>:      ldo 0(r31),rp
466546289Sdfr0x32d8 <main+224>:      addil -0x800,dp
466646289Sdfr0x32dc <main+228>:      ldo 0x588(r1),r26
466746289Sdfr0x32e0 <main+232>:      ldil 0x3000,r31
466819370SpstEnd of assembler dump.
466919370Spst@end smallexample
467019370Spst
467146289SdfrSome architectures have more than one commonly-used set of instruction
467246289Sdfrmnemonics or other syntax.
467346289Sdfr
467446289Sdfr@table @code
467598948Sobrien@kindex set disassembly-flavor
467646289Sdfr@cindex assembly instructions
467746289Sdfr@cindex instructions, assembly
467846289Sdfr@cindex machine instructions
467946289Sdfr@cindex listing machine instructions
468098948Sobrien@cindex Intel disassembly flavor
468198948Sobrien@cindex AT&T disassembly flavor
468298948Sobrien@item set disassembly-flavor @var{instruction-set}
468346289SdfrSelect the instruction set to use when disassembling the
468446289Sdfrprogram via the @code{disassemble} or @code{x/i} commands.
468546289Sdfr
468646289SdfrCurrently this command is only defined for the Intel x86 family.  You
468798948Sobriencan set @var{instruction-set} to either @code{intel} or @code{att}.
468898948SobrienThe default is @code{att}, the AT&T flavor used by default by Unix
468998948Sobrienassemblers for x86-based targets.
469046289Sdfr@end table
469146289Sdfr
469246289Sdfr
469398948Sobrien@node Data
469419370Spst@chapter Examining Data
469519370Spst
469619370Spst@cindex printing data
469719370Spst@cindex examining data
469819370Spst@kindex print
469919370Spst@kindex inspect
470019370Spst@c "inspect" is not quite a synonym if you are using Epoch, which we do not
470119370Spst@c document because it is nonstandard...  Under Epoch it displays in a
470219370Spst@c different window or something like that.
470319370SpstThe usual way to examine data in your program is with the @code{print}
470498948Sobriencommand (abbreviated @code{p}), or its synonym @code{inspect}.  It
470598948Sobrienevaluates and prints the value of an expression of the language your
470698948Sobrienprogram is written in (@pxref{Languages, ,Using @value{GDBN} with
470798948SobrienDifferent Languages}).
470819370Spst
470919370Spst@table @code
471098948Sobrien@item print @var{expr}
471198948Sobrien@itemx print /@var{f} @var{expr}
471298948Sobrien@var{expr} is an expression (in the source language).  By default the
471398948Sobrienvalue of @var{expr} is printed in a format appropriate to its data type;
471419370Spstyou can choose a different format by specifying @samp{/@var{f}}, where
471598948Sobrien@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
471619370Spstformats}.
471719370Spst
471819370Spst@item print
471919370Spst@itemx print /@var{f}
472098948SobrienIf you omit @var{expr}, @value{GDBN} displays the last value again (from the
472119370Spst@dfn{value history}; @pxref{Value History, ,Value history}).  This allows you to
472219370Spstconveniently inspect the same value in an alternative format.
472319370Spst@end table
472419370Spst
472519370SpstA more low-level way of examining data is with the @code{x} command.
472619370SpstIt examines data in memory at a specified address and prints it in a
472719370Spstspecified format.  @xref{Memory, ,Examining memory}.
472819370Spst
472998948SobrienIf you are interested in information about types, or about how the
473098948Sobrienfields of a struct or a class are declared, use the @code{ptype @var{exp}}
473198948Sobriencommand rather than @code{print}.  @xref{Symbols, ,Examining the Symbol
473298948SobrienTable}.
473319370Spst
473419370Spst@menu
473519370Spst* Expressions::                 Expressions
473619370Spst* Variables::                   Program variables
473719370Spst* Arrays::                      Artificial arrays
473819370Spst* Output Formats::              Output formats
473919370Spst* Memory::                      Examining memory
474019370Spst* Auto Display::                Automatic display
474119370Spst* Print Settings::              Print settings
474219370Spst* Value History::               Value history
474319370Spst* Convenience Vars::            Convenience variables
474419370Spst* Registers::                   Registers
474519370Spst* Floating Point Hardware::     Floating point hardware
4746130809Smarcel* Vector Unit::                 Vector Unit
4747130809Smarcel* Auxiliary Vector::            Auxiliary data provided by operating system
474898948Sobrien* Memory Region Attributes::    Memory region attributes
4749130809Smarcel* Dump/Restore Files::          Copy between memory and a file
4750130809Smarcel* Character Sets::              Debugging programs that use a different
4751130809Smarcel                                character set than GDB does
475219370Spst@end menu
475319370Spst
475498948Sobrien@node Expressions
475519370Spst@section Expressions
475619370Spst
475719370Spst@cindex expressions
475819370Spst@code{print} and many other @value{GDBN} commands accept an expression and
475919370Spstcompute its value.  Any kind of constant, variable or operator defined
476019370Spstby the programming language you are using is valid in an expression in
4761130809Smarcel@value{GDBN}.  This includes conditional expressions, function calls,
4762130809Smarcelcasts, and string constants.  It also includes preprocessor macros, if
4763130809Smarcelyou compiled your program to include this information; see
4764130809Smarcel@ref{Compilation}.
476519370Spst
476698948Sobrien@value{GDBN} supports array constants in expressions input by
476798948Sobrienthe user.  The syntax is @{@var{element}, @var{element}@dots{}@}.  For example,
476898948Sobrienyou can use the command @code{print @{1, 2, 3@}} to build up an array in
476998948Sobrienmemory that is @code{malloc}ed in the target program.
477019370Spst
477119370SpstBecause C is so widespread, most of the expressions shown in examples in
477219370Spstthis manual are in C.  @xref{Languages, , Using @value{GDBN} with Different
477319370SpstLanguages}, for information on how to use expressions in other
477419370Spstlanguages.
477519370Spst
477619370SpstIn this section, we discuss operators that you can use in @value{GDBN}
477719370Spstexpressions regardless of your programming language.
477819370Spst
477919370SpstCasts are supported in all languages, not just in C, because it is so
478019370Spstuseful to cast a number into a pointer in order to examine a structure
478119370Spstat that address in memory.
478219370Spst@c FIXME: casts supported---Mod2 true?
478319370Spst
478419370Spst@value{GDBN} supports these operators, in addition to those common
478519370Spstto programming languages:
478619370Spst
478719370Spst@table @code
478819370Spst@item @@
478919370Spst@samp{@@} is a binary operator for treating parts of memory as arrays.
479019370Spst@xref{Arrays, ,Artificial arrays}, for more information.
479119370Spst
479219370Spst@item ::
479319370Spst@samp{::} allows you to specify a variable in terms of the file or
479419370Spstfunction where it is defined.  @xref{Variables, ,Program variables}.
479519370Spst
479619370Spst@cindex @{@var{type}@}
479719370Spst@cindex type casting memory
479819370Spst@cindex memory, viewing as typed object
479919370Spst@cindex casts, to view memory
480019370Spst@item @{@var{type}@} @var{addr}
480119370SpstRefers to an object of type @var{type} stored at address @var{addr} in
480219370Spstmemory.  @var{addr} may be any expression whose value is an integer or
480319370Spstpointer (but parentheses are required around binary operators, just as in
480419370Spsta cast).  This construct is allowed regardless of what kind of data is
480519370Spstnormally supposed to reside at @var{addr}.
480619370Spst@end table
480719370Spst
480898948Sobrien@node Variables
480919370Spst@section Program variables
481019370Spst
481119370SpstThe most common kind of expression to use is the name of a variable
481219370Spstin your program.
481319370Spst
481419370SpstVariables in expressions are understood in the selected stack frame
481519370Spst(@pxref{Selection, ,Selecting a frame}); they must be either:
481619370Spst
481719370Spst@itemize @bullet
481819370Spst@item
481946289Sdfrglobal (or file-static)
482019370Spst@end itemize
482119370Spst
482298948Sobrien@noindent or
482319370Spst
482419370Spst@itemize @bullet
482519370Spst@item
482619370Spstvisible according to the scope rules of the
482719370Spstprogramming language from the point of execution in that frame
482898948Sobrien@end itemize
482919370Spst
483019370Spst@noindent This means that in the function
483119370Spst
4832130809Smarcel@smallexample
483319370Spstfoo (a)
483419370Spst     int a;
483519370Spst@{
483619370Spst  bar (a);
483719370Spst  @{
483819370Spst    int b = test ();
483919370Spst    bar (b);
484019370Spst  @}
484119370Spst@}
4842130809Smarcel@end smallexample
484319370Spst
484419370Spst@noindent
484519370Spstyou can examine and use the variable @code{a} whenever your program is
484619370Spstexecuting within the function @code{foo}, but you can only use or
484719370Spstexamine the variable @code{b} while your program is executing inside
484819370Spstthe block where @code{b} is declared.
484919370Spst
485019370Spst@cindex variable name conflict
485119370SpstThere is an exception: you can refer to a variable or function whose
485219370Spstscope is a single source file even if the current execution point is not
485319370Spstin this file.  But it is possible to have more than one such variable or
485419370Spstfunction with the same name (in different source files).  If that
485519370Spsthappens, referring to that name has unpredictable effects.  If you wish,
485619370Spstyou can specify a static variable in a particular function or file,
485719370Spstusing the colon-colon notation:
485819370Spst
485998948Sobrien@cindex colon-colon, context for variables/functions
486019370Spst@iftex
486119370Spst@c info cannot cope with a :: index entry, but why deprive hard copy readers?
486298948Sobrien@cindex @code{::}, context for variables/functions
486319370Spst@end iftex
4864130809Smarcel@smallexample
486519370Spst@var{file}::@var{variable}
486619370Spst@var{function}::@var{variable}
4867130809Smarcel@end smallexample
486819370Spst
486919370Spst@noindent
487019370SpstHere @var{file} or @var{function} is the name of the context for the
487119370Spststatic @var{variable}.  In the case of file names, you can use quotes to
487219370Spstmake sure @value{GDBN} parses the file name as a single word---for example,
487319370Spstto print a global value of @code{x} defined in @file{f2.c}:
487419370Spst
4875130809Smarcel@smallexample
487619370Spst(@value{GDBP}) p 'f2.c'::x
4877130809Smarcel@end smallexample
487819370Spst
487998948Sobrien@cindex C@t{++} scope resolution
488019370SpstThis use of @samp{::} is very rarely in conflict with the very similar
488198948Sobrienuse of the same notation in C@t{++}.  @value{GDBN} also supports use of the C@t{++}
488219370Spstscope resolution operator in @value{GDBN} expressions.
488319370Spst@c FIXME: Um, so what happens in one of those rare cases where it's in
488419370Spst@c conflict??  --mew
488519370Spst
488619370Spst@cindex wrong values
488719370Spst@cindex variable values, wrong
488819370Spst@quotation
488919370Spst@emph{Warning:} Occasionally, a local variable may appear to have the
489019370Spstwrong value at certain points in a function---just after entry to a new
489119370Spstscope, and just before exit.
489219370Spst@end quotation
489319370SpstYou may see this problem when you are stepping by machine instructions.
489419370SpstThis is because, on most machines, it takes more than one instruction to
489519370Spstset up a stack frame (including local variable definitions); if you are
489619370Spststepping by machine instructions, variables may appear to have the wrong
489719370Spstvalues until the stack frame is completely built.  On exit, it usually
489819370Spstalso takes more than one machine instruction to destroy a stack frame;
489919370Spstafter you begin stepping through that group of instructions, local
490019370Spstvariable definitions may be gone.
490119370Spst
490246289SdfrThis may also happen when the compiler does significant optimizations.
490346289SdfrTo be sure of always seeing accurate values, turn off all optimization
490446289Sdfrwhen compiling.
490546289Sdfr
490698948Sobrien@cindex ``No symbol "foo" in current context''
490798948SobrienAnother possible effect of compiler optimizations is to optimize
490898948Sobrienunused variables out of existence, or assign variables to registers (as
490998948Sobrienopposed to memory addresses).  Depending on the support for such cases
491098948Sobrienoffered by the debug info format used by the compiler, @value{GDBN}
491198948Sobrienmight not be able to display values for such local variables.  If that
491298948Sobrienhappens, @value{GDBN} will print a message like this:
491398948Sobrien
4914130809Smarcel@smallexample
491598948SobrienNo symbol "foo" in current context.
4916130809Smarcel@end smallexample
491798948Sobrien
491898948SobrienTo solve such problems, either recompile without optimizations, or use a
491998948Sobriendifferent debug info format, if the compiler supports several such
4920130809Smarcelformats.  For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler
4921130809Smarcelusually supports the @option{-gstabs+} option.  @option{-gstabs+}
4922130809Smarcelproduces debug info in a format that is superior to formats such as
4923130809SmarcelCOFF.  You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
4924130809Smarcelan effective form for debug info.  @xref{Debugging Options,,Options
4925130809Smarcelfor Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
492698948Sobrien
492798948Sobrien
492898948Sobrien@node Arrays
492919370Spst@section Artificial arrays
493019370Spst
493119370Spst@cindex artificial array
493298948Sobrien@kindex @@@r{, referencing memory as an array}
493319370SpstIt is often useful to print out several successive objects of the
493419370Spstsame type in memory; a section of an array, or an array of
493519370Spstdynamically determined size for which only a pointer exists in the
493619370Spstprogram.
493719370Spst
493819370SpstYou can do this by referring to a contiguous span of memory as an
493919370Spst@dfn{artificial array}, using the binary operator @samp{@@}.  The left
494019370Spstoperand of @samp{@@} should be the first element of the desired array
494119370Spstand be an individual object.  The right operand should be the desired length
494219370Spstof the array.  The result is an array value whose elements are all of
494319370Spstthe type of the left argument.  The first element is actually the left
494419370Spstargument; the second element comes from bytes of memory immediately
494519370Spstfollowing those that hold the first element, and so on.  Here is an
494619370Spstexample.  If a program says
494719370Spst
4948130809Smarcel@smallexample
494919370Spstint *array = (int *) malloc (len * sizeof (int));
4950130809Smarcel@end smallexample
495119370Spst
495219370Spst@noindent
495319370Spstyou can print the contents of @code{array} with
495419370Spst
4955130809Smarcel@smallexample
495619370Spstp *array@@len
4957130809Smarcel@end smallexample
495819370Spst
495919370SpstThe left operand of @samp{@@} must reside in memory.  Array values made
496019370Spstwith @samp{@@} in this way behave just like other arrays in terms of
496119370Spstsubscripting, and are coerced to pointers when used in expressions.
496219370SpstArtificial arrays most often appear in expressions via the value history
496319370Spst(@pxref{Value History, ,Value history}), after printing one out.
496419370Spst
496519370SpstAnother way to create an artificial array is to use a cast.
496619370SpstThis re-interprets a value as if it were an array.
496719370SpstThe value need not be in memory:
4968130809Smarcel@smallexample
496919370Spst(@value{GDBP}) p/x (short[2])0x12345678
497019370Spst$1 = @{0x1234, 0x5678@}
4971130809Smarcel@end smallexample
497219370Spst
497319370SpstAs a convenience, if you leave the array length out (as in
497498948Sobrien@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
497519370Spstthe value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
4976130809Smarcel@smallexample
497719370Spst(@value{GDBP}) p/x (short[])0x12345678
497819370Spst$2 = @{0x1234, 0x5678@}
4979130809Smarcel@end smallexample
498019370Spst
498119370SpstSometimes the artificial array mechanism is not quite enough; in
498219370Spstmoderately complex data structures, the elements of interest may not
498319370Spstactually be adjacent---for example, if you are interested in the values
498419370Spstof pointers in an array.  One useful work-around in this situation is
498519370Spstto use a convenience variable (@pxref{Convenience Vars, ,Convenience
498619370Spstvariables}) as a counter in an expression that prints the first
498719370Spstinteresting value, and then repeat that expression via @key{RET}.  For
498819370Spstinstance, suppose you have an array @code{dtab} of pointers to
498919370Spststructures, and you are interested in the values of a field @code{fv}
499019370Spstin each structure.  Here is an example of what you might type:
499119370Spst
4992130809Smarcel@smallexample
499319370Spstset $i = 0
499419370Spstp dtab[$i++]->fv
499519370Spst@key{RET}
499619370Spst@key{RET}
499719370Spst@dots{}
4998130809Smarcel@end smallexample
499919370Spst
500098948Sobrien@node Output Formats
500119370Spst@section Output formats
500219370Spst
500319370Spst@cindex formatted output
500419370Spst@cindex output formats
500519370SpstBy default, @value{GDBN} prints a value according to its data type.  Sometimes
500619370Spstthis is not what you want.  For example, you might want to print a number
500719370Spstin hex, or a pointer in decimal.  Or you might want to view data in memory
500819370Spstat a certain address as a character string or as an instruction.  To do
500919370Spstthese things, specify an @dfn{output format} when you print a value.
501019370Spst
501119370SpstThe simplest use of output formats is to say how to print a value
501219370Spstalready computed.  This is done by starting the arguments of the
501319370Spst@code{print} command with a slash and a format letter.  The format
501419370Spstletters supported are:
501519370Spst
501619370Spst@table @code
501719370Spst@item x
501819370SpstRegard the bits of the value as an integer, and print the integer in
501919370Spsthexadecimal.
502019370Spst
502119370Spst@item d
502219370SpstPrint as integer in signed decimal.
502319370Spst
502419370Spst@item u
502519370SpstPrint as integer in unsigned decimal.
502619370Spst
502719370Spst@item o
502819370SpstPrint as integer in octal.
502919370Spst
503019370Spst@item t
503119370SpstPrint as integer in binary.  The letter @samp{t} stands for ``two''.
503219370Spst@footnote{@samp{b} cannot be used because these format letters are also
503319370Spstused with the @code{x} command, where @samp{b} stands for ``byte'';
503498948Sobriensee @ref{Memory,,Examining memory}.}
503519370Spst
503619370Spst@item a
503719370Spst@cindex unknown address, locating
503898948Sobrien@cindex locate address
503919370SpstPrint as an address, both absolute in hexadecimal and as an offset from
504019370Spstthe nearest preceding symbol.  You can use this format used to discover
504119370Spstwhere (in what function) an unknown address is located:
504219370Spst
5043130809Smarcel@smallexample
504419370Spst(@value{GDBP}) p/a 0x54320
504519370Spst$3 = 0x54320 <_initialize_vx+396>
5046130809Smarcel@end smallexample
504719370Spst
504898948Sobrien@noindent
504998948SobrienThe command @code{info symbol 0x54320} yields similar results.
505098948Sobrien@xref{Symbols, info symbol}.
505198948Sobrien
505219370Spst@item c
505319370SpstRegard as an integer and print it as a character constant.
505419370Spst
505519370Spst@item f
505619370SpstRegard the bits of the value as a floating point number and print
505719370Spstusing typical floating point syntax.
505819370Spst@end table
505919370Spst
506019370SpstFor example, to print the program counter in hex (@pxref{Registers}), type
506119370Spst
5062130809Smarcel@smallexample
506319370Spstp/x $pc
5064130809Smarcel@end smallexample
506519370Spst
506619370Spst@noindent
506719370SpstNote that no space is required before the slash; this is because command
506819370Spstnames in @value{GDBN} cannot contain a slash.
506919370Spst
507019370SpstTo reprint the last value in the value history with a different format,
507119370Spstyou can use the @code{print} command with just a format and no
507219370Spstexpression.  For example, @samp{p/x} reprints the last value in hex.
507319370Spst
507498948Sobrien@node Memory
507519370Spst@section Examining memory
507619370Spst
507719370SpstYou can use the command @code{x} (for ``examine'') to examine memory in
507819370Spstany of several formats, independently of your program's data types.
507919370Spst
508019370Spst@cindex examining memory
508119370Spst@table @code
508298948Sobrien@kindex x @r{(examine memory)}
508319370Spst@item x/@var{nfu} @var{addr}
508419370Spst@itemx x @var{addr}
508519370Spst@itemx x
508619370SpstUse the @code{x} command to examine memory.
508719370Spst@end table
508819370Spst
508919370Spst@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
509019370Spstmuch memory to display and how to format it; @var{addr} is an
509119370Spstexpression giving the address where you want to start displaying memory.
509219370SpstIf you use defaults for @var{nfu}, you need not type the slash @samp{/}.
509319370SpstSeveral commands set convenient defaults for @var{addr}.
509419370Spst
509519370Spst@table @r
509619370Spst@item @var{n}, the repeat count
509719370SpstThe repeat count is a decimal integer; the default is 1.  It specifies
509819370Spsthow much memory (counting by units @var{u}) to display.
509919370Spst@c This really is **decimal**; unaffected by 'set radix' as of GDB
510019370Spst@c 4.1.2.
510119370Spst
510219370Spst@item @var{f}, the display format
510319370SpstThe display format is one of the formats used by @code{print},
510419370Spst@samp{s} (null-terminated string), or @samp{i} (machine instruction).
510519370SpstThe default is @samp{x} (hexadecimal) initially.
510619370SpstThe default changes each time you use either @code{x} or @code{print}.
510719370Spst
510819370Spst@item @var{u}, the unit size
510919370SpstThe unit size is any of
511019370Spst
511119370Spst@table @code
511219370Spst@item b
511319370SpstBytes.
511419370Spst@item h
511519370SpstHalfwords (two bytes).
511619370Spst@item w
511719370SpstWords (four bytes).  This is the initial default.
511819370Spst@item g
511919370SpstGiant words (eight bytes).
512019370Spst@end table
512119370Spst
512219370SpstEach time you specify a unit size with @code{x}, that size becomes the
512319370Spstdefault unit the next time you use @code{x}.  (For the @samp{s} and
512419370Spst@samp{i} formats, the unit size is ignored and is normally not written.)
512519370Spst
512619370Spst@item @var{addr}, starting display address
512719370Spst@var{addr} is the address where you want @value{GDBN} to begin displaying
512819370Spstmemory.  The expression need not have a pointer value (though it may);
512919370Spstit is always interpreted as an integer address of a byte of memory.
513019370Spst@xref{Expressions, ,Expressions}, for more information on expressions.  The default for
513119370Spst@var{addr} is usually just after the last address examined---but several
513219370Spstother commands also set the default address: @code{info breakpoints} (to
513319370Spstthe address of the last breakpoint listed), @code{info line} (to the
513419370Spststarting address of a line), and @code{print} (if you use it to display
513519370Spsta value from memory).
513619370Spst@end table
513719370Spst
513819370SpstFor example, @samp{x/3uh 0x54320} is a request to display three halfwords
513919370Spst(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
514019370Spststarting at address @code{0x54320}.  @samp{x/4xw $sp} prints the four
514119370Spstwords (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
514298948Sobrien@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
514319370Spst
514419370SpstSince the letters indicating unit sizes are all distinct from the
514519370Spstletters specifying output formats, you do not have to remember whether
514619370Spstunit size or format comes first; either order works.  The output
514719370Spstspecifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
514819370Spst(However, the count @var{n} must come first; @samp{wx4} does not work.)
514919370Spst
515019370SpstEven though the unit size @var{u} is ignored for the formats @samp{s}
515119370Spstand @samp{i}, you might still want to use a count @var{n}; for example,
515219370Spst@samp{3i} specifies that you want to see three machine instructions,
515319370Spstincluding any operands.  The command @code{disassemble} gives an
515498948Sobrienalternative way of inspecting machine instructions; see @ref{Machine
515519370SpstCode,,Source and machine code}.
515619370Spst
515719370SpstAll the defaults for the arguments to @code{x} are designed to make it
515819370Spsteasy to continue scanning memory with minimal specifications each time
515919370Spstyou use @code{x}.  For example, after you have inspected three machine
516019370Spstinstructions with @samp{x/3i @var{addr}}, you can inspect the next seven
516119370Spstwith just @samp{x/7}.  If you use @key{RET} to repeat the @code{x} command,
516219370Spstthe repeat count @var{n} is used again; the other arguments default as
516319370Spstfor successive uses of @code{x}.
516419370Spst
516519370Spst@cindex @code{$_}, @code{$__}, and value history
516619370SpstThe addresses and contents printed by the @code{x} command are not saved
516719370Spstin the value history because there is often too much of them and they
516819370Spstwould get in the way.  Instead, @value{GDBN} makes these values available for
516919370Spstsubsequent use in expressions as values of the convenience variables
517019370Spst@code{$_} and @code{$__}.  After an @code{x} command, the last address
517119370Spstexamined is available for use in expressions in the convenience variable
517219370Spst@code{$_}.  The contents of that address, as examined, are available in
517319370Spstthe convenience variable @code{$__}.
517419370Spst
517519370SpstIf the @code{x} command has a repeat count, the address and contents saved
517619370Spstare from the last memory unit printed; this is not the same as the last
517719370Spstaddress printed if several units were printed on the last line of output.
517819370Spst
517998948Sobrien@node Auto Display
518019370Spst@section Automatic display
518119370Spst@cindex automatic display
518219370Spst@cindex display of expressions
518319370Spst
518419370SpstIf you find that you want to print the value of an expression frequently
518519370Spst(to see how it changes), you might want to add it to the @dfn{automatic
518619370Spstdisplay list} so that @value{GDBN} prints its value each time your program stops.
518719370SpstEach expression added to the list is given a number to identify it;
518819370Spstto remove an expression from the list, you specify that number.
518919370SpstThe automatic display looks like this:
519019370Spst
5191130809Smarcel@smallexample
519219370Spst2: foo = 38
519319370Spst3: bar[5] = (struct hack *) 0x3804
5194130809Smarcel@end smallexample
519519370Spst
519619370Spst@noindent
519719370SpstThis display shows item numbers, expressions and their current values.  As with
519819370Spstdisplays you request manually using @code{x} or @code{print}, you can
519919370Spstspecify the output format you prefer; in fact, @code{display} decides
520019370Spstwhether to use @code{print} or @code{x} depending on how elaborate your
520119370Spstformat specification is---it uses @code{x} if you specify a unit size,
520219370Spstor one of the two formats (@samp{i} and @samp{s}) that are only
520319370Spstsupported by @code{x}; otherwise it uses @code{print}.
520419370Spst
520519370Spst@table @code
520619370Spst@kindex display
520798948Sobrien@item display @var{expr}
520898948SobrienAdd the expression @var{expr} to the list of expressions to display
520919370Spsteach time your program stops.  @xref{Expressions, ,Expressions}.
521019370Spst
521119370Spst@code{display} does not repeat if you press @key{RET} again after using it.
521219370Spst
521398948Sobrien@item display/@var{fmt} @var{expr}
521419370SpstFor @var{fmt} specifying only a display format and not a size or
521598948Sobriencount, add the expression @var{expr} to the auto-display list but
521619370Spstarrange to display it each time in the specified format @var{fmt}.
521719370Spst@xref{Output Formats,,Output formats}.
521819370Spst
521919370Spst@item display/@var{fmt} @var{addr}
522019370SpstFor @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
522119370Spstnumber of units, add the expression @var{addr} as a memory address to
522219370Spstbe examined each time your program stops.  Examining means in effect
522319370Spstdoing @samp{x/@var{fmt} @var{addr}}.  @xref{Memory, ,Examining memory}.
522419370Spst@end table
522519370Spst
522619370SpstFor example, @samp{display/i $pc} can be helpful, to see the machine
522719370Spstinstruction about to be executed each time execution stops (@samp{$pc}
522898948Sobrienis a common name for the program counter; @pxref{Registers, ,Registers}).
522919370Spst
523019370Spst@table @code
523119370Spst@kindex delete display
523219370Spst@kindex undisplay
523319370Spst@item undisplay @var{dnums}@dots{}
523419370Spst@itemx delete display @var{dnums}@dots{}
523519370SpstRemove item numbers @var{dnums} from the list of expressions to display.
523619370Spst
523719370Spst@code{undisplay} does not repeat if you press @key{RET} after using it.
523819370Spst(Otherwise you would just get the error @samp{No display number @dots{}}.)
523919370Spst
524019370Spst@kindex disable display
524119370Spst@item disable display @var{dnums}@dots{}
524219370SpstDisable the display of item numbers @var{dnums}.  A disabled display
524319370Spstitem is not printed automatically, but is not forgotten.  It may be
524419370Spstenabled again later.
524519370Spst
524619370Spst@kindex enable display
524719370Spst@item enable display @var{dnums}@dots{}
524819370SpstEnable display of item numbers @var{dnums}.  It becomes effective once
524919370Spstagain in auto display of its expression, until you specify otherwise.
525019370Spst
525119370Spst@item display
525219370SpstDisplay the current values of the expressions on the list, just as is
525319370Spstdone when your program stops.
525419370Spst
525519370Spst@kindex info display
525619370Spst@item info display
525719370SpstPrint the list of expressions previously set up to display
525819370Spstautomatically, each one with its item number, but without showing the
525919370Spstvalues.  This includes disabled expressions, which are marked as such.
526019370SpstIt also includes expressions which would not be displayed right now
526119370Spstbecause they refer to automatic variables not currently available.
526219370Spst@end table
526319370Spst
526419370SpstIf a display expression refers to local variables, then it does not make
526519370Spstsense outside the lexical context for which it was set up.  Such an
526619370Spstexpression is disabled when execution enters a context where one of its
526719370Spstvariables is not defined.  For example, if you give the command
526819370Spst@code{display last_char} while inside a function with an argument
526919370Spst@code{last_char}, @value{GDBN} displays this argument while your program
527019370Spstcontinues to stop inside that function.  When it stops elsewhere---where
527119370Spstthere is no variable @code{last_char}---the display is disabled
527219370Spstautomatically.  The next time your program stops where @code{last_char}
527319370Spstis meaningful, you can enable the display expression once again.
527419370Spst
527598948Sobrien@node Print Settings
527619370Spst@section Print settings
527719370Spst
527819370Spst@cindex format options
527919370Spst@cindex print settings
528019370Spst@value{GDBN} provides the following ways to control how arrays, structures,
528119370Spstand symbols are printed.
528219370Spst
528319370Spst@noindent
528419370SpstThese settings are useful for debugging programs in any language:
528519370Spst
528619370Spst@table @code
528719370Spst@kindex set print address
528819370Spst@item set print address
528919370Spst@itemx set print address on
529019370Spst@value{GDBN} prints memory addresses showing the location of stack
529119370Spsttraces, structure values, pointer values, breakpoints, and so forth,
529219370Spsteven when it also displays the contents of those addresses.  The default
529319370Spstis @code{on}.  For example, this is what a stack frame display looks like with
529419370Spst@code{set print address on}:
529519370Spst
529619370Spst@smallexample
529719370Spst@group
529819370Spst(@value{GDBP}) f
529919370Spst#0  set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
530019370Spst    at input.c:530
530119370Spst530         if (lquote != def_lquote)
530219370Spst@end group
530319370Spst@end smallexample
530419370Spst
530519370Spst@item set print address off
530619370SpstDo not print addresses when displaying their contents.  For example,
530719370Spstthis is the same stack frame displayed with @code{set print address off}:
530819370Spst
530919370Spst@smallexample
531019370Spst@group
531119370Spst(@value{GDBP}) set print addr off
531219370Spst(@value{GDBP}) f
531319370Spst#0  set_quotes (lq="<<", rq=">>") at input.c:530
531419370Spst530         if (lquote != def_lquote)
531519370Spst@end group
531619370Spst@end smallexample
531719370Spst
531819370SpstYou can use @samp{set print address off} to eliminate all machine
531919370Spstdependent displays from the @value{GDBN} interface.  For example, with
532019370Spst@code{print address off}, you should get the same text for backtraces on
532119370Spstall machines---whether or not they involve pointer arguments.
532219370Spst
532319370Spst@kindex show print address
532419370Spst@item show print address
532519370SpstShow whether or not addresses are to be printed.
532619370Spst@end table
532719370Spst
532819370SpstWhen @value{GDBN} prints a symbolic address, it normally prints the
532919370Spstclosest earlier symbol plus an offset.  If that symbol does not uniquely
533019370Spstidentify the address (for example, it is a name whose scope is a single
533119370Spstsource file), you may need to clarify.  One way to do this is with
533219370Spst@code{info line}, for example @samp{info line *0x4537}.  Alternately,
533319370Spstyou can set @value{GDBN} to print the source file and line number when
533419370Spstit prints a symbolic address:
533519370Spst
533619370Spst@table @code
533719370Spst@kindex set print symbol-filename
533819370Spst@item set print symbol-filename on
533919370SpstTell @value{GDBN} to print the source file name and line number of a
534019370Spstsymbol in the symbolic form of an address.
534119370Spst
534219370Spst@item set print symbol-filename off
534319370SpstDo not print source file name and line number of a symbol.  This is the
534419370Spstdefault.
534519370Spst
534619370Spst@kindex show print symbol-filename
534719370Spst@item show print symbol-filename
534819370SpstShow whether or not @value{GDBN} will print the source file name and
534919370Spstline number of a symbol in the symbolic form of an address.
535019370Spst@end table
535119370Spst
535219370SpstAnother situation where it is helpful to show symbol filenames and line
535319370Spstnumbers is when disassembling code; @value{GDBN} shows you the line
535419370Spstnumber and source file that corresponds to each instruction.
535519370Spst
535619370SpstAlso, you may wish to see the symbolic form only if the address being
535719370Spstprinted is reasonably close to the closest earlier symbol:
535819370Spst
535919370Spst@table @code
536019370Spst@kindex set print max-symbolic-offset
536119370Spst@item set print max-symbolic-offset @var{max-offset}
536219370SpstTell @value{GDBN} to only display the symbolic form of an address if the
536319370Spstoffset between the closest earlier symbol and the address is less than
536498948Sobrien@var{max-offset}.  The default is 0, which tells @value{GDBN}
536519370Spstto always print the symbolic form of an address if any symbol precedes it.
536619370Spst
536719370Spst@kindex show print max-symbolic-offset
536819370Spst@item show print max-symbolic-offset
536919370SpstAsk how large the maximum offset is that @value{GDBN} prints in a
537019370Spstsymbolic address.
537119370Spst@end table
537219370Spst
537319370Spst@cindex wild pointer, interpreting
537419370Spst@cindex pointer, finding referent
537519370SpstIf you have a pointer and you are not sure where it points, try
537619370Spst@samp{set print symbol-filename on}.  Then you can determine the name
537719370Spstand source file location of the variable where it points, using
537819370Spst@samp{p/a @var{pointer}}.  This interprets the address in symbolic form.
537919370SpstFor example, here @value{GDBN} shows that a variable @code{ptt} points
538019370Spstat another variable @code{t}, defined in @file{hi2.c}:
538119370Spst
5382130809Smarcel@smallexample
538319370Spst(@value{GDBP}) set print symbol-filename on
538419370Spst(@value{GDBP}) p/a ptt
538519370Spst$4 = 0xe008 <t in hi2.c>
5386130809Smarcel@end smallexample
538719370Spst
538819370Spst@quotation
538919370Spst@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
539019370Spstdoes not show the symbol name and filename of the referent, even with
539119370Spstthe appropriate @code{set print} options turned on.
539219370Spst@end quotation
539319370Spst
539419370SpstOther settings control how different kinds of objects are printed:
539519370Spst
539619370Spst@table @code
539719370Spst@kindex set print array
539819370Spst@item set print array
539919370Spst@itemx set print array on
540019370SpstPretty print arrays.  This format is more convenient to read,
540119370Spstbut uses more space.  The default is off.
540219370Spst
540319370Spst@item set print array off
540419370SpstReturn to compressed format for arrays.
540519370Spst
540619370Spst@kindex show print array
540719370Spst@item show print array
540819370SpstShow whether compressed or pretty format is selected for displaying
540919370Spstarrays.
541019370Spst
541119370Spst@kindex set print elements
541219370Spst@item set print elements @var{number-of-elements}
541319370SpstSet a limit on how many elements of an array @value{GDBN} will print.
541419370SpstIf @value{GDBN} is printing a large array, it stops printing after it has
541519370Spstprinted the number of elements set by the @code{set print elements} command.
541619370SpstThis limit also applies to the display of strings.
541798948SobrienWhen @value{GDBN} starts, this limit is set to 200.
541819370SpstSetting  @var{number-of-elements} to zero means that the printing is unlimited.
541919370Spst
542019370Spst@kindex show print elements
542119370Spst@item show print elements
542219370SpstDisplay the number of elements of a large array that @value{GDBN} will print.
542319370SpstIf the number is 0, then the printing is unlimited.
542419370Spst
542519370Spst@kindex set print null-stop
542619370Spst@item set print null-stop
542719370SpstCause @value{GDBN} to stop printing the characters of an array when the first
542898948Sobrien@sc{null} is encountered.  This is useful when large arrays actually
542919370Spstcontain only short strings.
543098948SobrienThe default is off.
543119370Spst
543219370Spst@kindex set print pretty
543319370Spst@item set print pretty on
543498948SobrienCause @value{GDBN} to print structures in an indented format with one member
543519370Spstper line, like this:
543619370Spst
543719370Spst@smallexample
543819370Spst@group
543919370Spst$1 = @{
544019370Spst  next = 0x0,
544119370Spst  flags = @{
544219370Spst    sweet = 1,
544319370Spst    sour = 1
544419370Spst  @},
544519370Spst  meat = 0x54 "Pork"
544619370Spst@}
544719370Spst@end group
544819370Spst@end smallexample
544919370Spst
545019370Spst@item set print pretty off
545119370SpstCause @value{GDBN} to print structures in a compact format, like this:
545219370Spst
545319370Spst@smallexample
545419370Spst@group
545519370Spst$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
545619370Spstmeat = 0x54 "Pork"@}
545719370Spst@end group
545819370Spst@end smallexample
545919370Spst
546019370Spst@noindent
546119370SpstThis is the default format.
546219370Spst
546319370Spst@kindex show print pretty
546419370Spst@item show print pretty
546519370SpstShow which format @value{GDBN} is using to print structures.
546619370Spst
546719370Spst@kindex set print sevenbit-strings
546819370Spst@item set print sevenbit-strings on
546919370SpstPrint using only seven-bit characters; if this option is set,
547019370Spst@value{GDBN} displays any eight-bit characters (in strings or
547119370Spstcharacter values) using the notation @code{\}@var{nnn}.  This setting is
547219370Spstbest if you are working in English (@sc{ascii}) and you use the
547319370Spsthigh-order bit of characters as a marker or ``meta'' bit.
547419370Spst
547519370Spst@item set print sevenbit-strings off
547619370SpstPrint full eight-bit characters.  This allows the use of more
547719370Spstinternational character sets, and is the default.
547819370Spst
547919370Spst@kindex show print sevenbit-strings
548019370Spst@item show print sevenbit-strings
548119370SpstShow whether or not @value{GDBN} is printing only seven-bit characters.
548219370Spst
548319370Spst@kindex set print union
548419370Spst@item set print union on
548598948SobrienTell @value{GDBN} to print unions which are contained in structures.  This
548619370Spstis the default setting.
548719370Spst
548819370Spst@item set print union off
548919370SpstTell @value{GDBN} not to print unions which are contained in structures.
549019370Spst
549119370Spst@kindex show print union
549219370Spst@item show print union
549319370SpstAsk @value{GDBN} whether or not it will print unions which are contained in
549419370Spststructures.
549519370Spst
549619370SpstFor example, given the declarations
549719370Spst
549819370Spst@smallexample
549919370Spsttypedef enum @{Tree, Bug@} Species;
550019370Spsttypedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
550198948Sobrientypedef enum @{Caterpillar, Cocoon, Butterfly@}
550219370Spst              Bug_forms;
550319370Spst
550419370Spststruct thing @{
550519370Spst  Species it;
550619370Spst  union @{
550719370Spst    Tree_forms tree;
550819370Spst    Bug_forms bug;
550919370Spst  @} form;
551019370Spst@};
551119370Spst
551219370Spststruct thing foo = @{Tree, @{Acorn@}@};
551319370Spst@end smallexample
551419370Spst
551519370Spst@noindent
551619370Spstwith @code{set print union on} in effect @samp{p foo} would print
551719370Spst
551819370Spst@smallexample
551919370Spst$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
552019370Spst@end smallexample
552119370Spst
552219370Spst@noindent
552319370Spstand with @code{set print union off} in effect it would print
552419370Spst
552519370Spst@smallexample
552619370Spst$1 = @{it = Tree, form = @{...@}@}
552719370Spst@end smallexample
552819370Spst@end table
552919370Spst
553019370Spst@need 1000
553119370Spst@noindent
553298948SobrienThese settings are of interest when debugging C@t{++} programs:
553319370Spst
553419370Spst@table @code
553519370Spst@cindex demangling
553619370Spst@kindex set print demangle
553719370Spst@item set print demangle
553819370Spst@itemx set print demangle on
553998948SobrienPrint C@t{++} names in their source form rather than in the encoded
554019370Spst(``mangled'') form passed to the assembler and linker for type-safe
554198948Sobrienlinkage.  The default is on.
554219370Spst
554319370Spst@kindex show print demangle
554419370Spst@item show print demangle
554598948SobrienShow whether C@t{++} names are printed in mangled or demangled form.
554619370Spst
554719370Spst@kindex set print asm-demangle
554819370Spst@item set print asm-demangle
554919370Spst@itemx set print asm-demangle on
555098948SobrienPrint C@t{++} names in their source form rather than their mangled form, even
555119370Spstin assembler code printouts such as instruction disassemblies.
555219370SpstThe default is off.
555319370Spst
555419370Spst@kindex show print asm-demangle
555519370Spst@item show print asm-demangle
555698948SobrienShow whether C@t{++} names in assembly listings are printed in mangled
555719370Spstor demangled form.
555819370Spst
555919370Spst@kindex set demangle-style
556098948Sobrien@cindex C@t{++} symbol decoding style
556198948Sobrien@cindex symbol decoding style, C@t{++}
556219370Spst@item set demangle-style @var{style}
556319370SpstChoose among several encoding schemes used by different compilers to
556498948Sobrienrepresent C@t{++} names.  The choices for @var{style} are currently:
556519370Spst
556619370Spst@table @code
556719370Spst@item auto
556819370SpstAllow @value{GDBN} to choose a decoding style by inspecting your program.
556919370Spst
557019370Spst@item gnu
557198948SobrienDecode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
557219370SpstThis is the default.
557319370Spst
557446289Sdfr@item hp
557598948SobrienDecode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
557646289Sdfr
557719370Spst@item lucid
557898948SobrienDecode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
557919370Spst
558019370Spst@item arm
558198948SobrienDecode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
558219370Spst@strong{Warning:} this setting alone is not sufficient to allow
558319370Spstdebugging @code{cfront}-generated executables.  @value{GDBN} would
558419370Spstrequire further enhancement to permit that.
558519370Spst
558619370Spst@end table
558746289SdfrIf you omit @var{style}, you will see a list of possible formats.
558819370Spst
558919370Spst@kindex show demangle-style
559019370Spst@item show demangle-style
559198948SobrienDisplay the encoding style currently in use for decoding C@t{++} symbols.
559219370Spst
559319370Spst@kindex set print object
559419370Spst@item set print object
559519370Spst@itemx set print object on
559619370SpstWhen displaying a pointer to an object, identify the @emph{actual}
559719370Spst(derived) type of the object rather than the @emph{declared} type, using
559819370Spstthe virtual function table.
559919370Spst
560019370Spst@item set print object off
560119370SpstDisplay only the declared type of objects, without reference to the
560219370Spstvirtual function table.  This is the default setting.
560319370Spst
560419370Spst@kindex show print object
560519370Spst@item show print object
560619370SpstShow whether actual, or declared, object types are displayed.
560719370Spst
560819370Spst@kindex set print static-members
560919370Spst@item set print static-members
561019370Spst@itemx set print static-members on
561198948SobrienPrint static members when displaying a C@t{++} object.  The default is on.
561219370Spst
561319370Spst@item set print static-members off
561498948SobrienDo not print static members when displaying a C@t{++} object.
561519370Spst
561619370Spst@kindex show print static-members
561719370Spst@item show print static-members
561898948SobrienShow whether C@t{++} static members are printed, or not.
561919370Spst
562046289Sdfr@c These don't work with HP ANSI C++ yet.
562119370Spst@kindex set print vtbl
562219370Spst@item set print vtbl
562319370Spst@itemx set print vtbl on
562498948SobrienPretty print C@t{++} virtual function tables.  The default is off.
562546289Sdfr(The @code{vtbl} commands do not work on programs compiled with the HP
562698948SobrienANSI C@t{++} compiler (@code{aCC}).)
562719370Spst
562819370Spst@item set print vtbl off
562998948SobrienDo not pretty print C@t{++} virtual function tables.
563019370Spst
563119370Spst@kindex show print vtbl
563219370Spst@item show print vtbl
563398948SobrienShow whether C@t{++} virtual function tables are pretty printed, or not.
563419370Spst@end table
563519370Spst
563698948Sobrien@node Value History
563719370Spst@section Value history
563819370Spst
563919370Spst@cindex value history
564098948SobrienValues printed by the @code{print} command are saved in the @value{GDBN}
564198948Sobrien@dfn{value history}.  This allows you to refer to them in other expressions.
564298948SobrienValues are kept until the symbol table is re-read or discarded
564398948Sobrien(for example with the @code{file} or @code{symbol-file} commands).
564498948SobrienWhen the symbol table changes, the value history is discarded,
564598948Sobriensince the values may contain pointers back to the types defined in the
564619370Spstsymbol table.
564719370Spst
564819370Spst@cindex @code{$}
564919370Spst@cindex @code{$$}
565019370Spst@cindex history number
565119370SpstThe values printed are given @dfn{history numbers} by which you can
565219370Spstrefer to them.  These are successive integers starting with one.
565319370Spst@code{print} shows you the history number assigned to a value by
565419370Spstprinting @samp{$@var{num} = } before the value; here @var{num} is the
565519370Spsthistory number.
565619370Spst
565719370SpstTo refer to any previous value, use @samp{$} followed by the value's
565819370Spsthistory number.  The way @code{print} labels its output is designed to
565919370Spstremind you of this.  Just @code{$} refers to the most recent value in
566019370Spstthe history, and @code{$$} refers to the value before that.
566119370Spst@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
566219370Spstis the value just prior to @code{$$}, @code{$$1} is equivalent to
566319370Spst@code{$$}, and @code{$$0} is equivalent to @code{$}.
566419370Spst
566519370SpstFor example, suppose you have just printed a pointer to a structure and
566619370Spstwant to see the contents of the structure.  It suffices to type
566719370Spst
5668130809Smarcel@smallexample
566919370Spstp *$
5670130809Smarcel@end smallexample
567119370Spst
567219370SpstIf you have a chain of structures where the component @code{next} points
567319370Spstto the next one, you can print the contents of the next one with this:
567419370Spst
5675130809Smarcel@smallexample
567619370Spstp *$.next
5677130809Smarcel@end smallexample
567819370Spst
567919370Spst@noindent
568019370SpstYou can print successive links in the chain by repeating this
568119370Spstcommand---which you can do by just typing @key{RET}.
568219370Spst
568319370SpstNote that the history records values, not expressions.  If the value of
568419370Spst@code{x} is 4 and you type these commands:
568519370Spst
5686130809Smarcel@smallexample
568719370Spstprint x
568819370Spstset x=5
5689130809Smarcel@end smallexample
569019370Spst
569119370Spst@noindent
569219370Spstthen the value recorded in the value history by the @code{print} command
569319370Spstremains 4 even though the value of @code{x} has changed.
569419370Spst
569519370Spst@table @code
569619370Spst@kindex show values
569719370Spst@item show values
569819370SpstPrint the last ten values in the value history, with their item numbers.
569919370SpstThis is like @samp{p@ $$9} repeated ten times, except that @code{show
570019370Spstvalues} does not change the history.
570119370Spst
570219370Spst@item show values @var{n}
570319370SpstPrint ten history values centered on history item number @var{n}.
570419370Spst
570519370Spst@item show values +
570619370SpstPrint ten history values just after the values last printed.  If no more
570719370Spstvalues are available, @code{show values +} produces no display.
570819370Spst@end table
570919370Spst
571019370SpstPressing @key{RET} to repeat @code{show values @var{n}} has exactly the
571119370Spstsame effect as @samp{show values +}.
571219370Spst
571398948Sobrien@node Convenience Vars
571419370Spst@section Convenience variables
571519370Spst
571619370Spst@cindex convenience variables
571719370Spst@value{GDBN} provides @dfn{convenience variables} that you can use within
571819370Spst@value{GDBN} to hold on to a value and refer to it later.  These variables
571919370Spstexist entirely within @value{GDBN}; they are not part of your program, and
572019370Spstsetting a convenience variable has no direct effect on further execution
572119370Spstof your program.  That is why you can use them freely.
572219370Spst
572319370SpstConvenience variables are prefixed with @samp{$}.  Any name preceded by
572419370Spst@samp{$} can be used for a convenience variable, unless it is one of
572598948Sobrienthe predefined machine-specific register names (@pxref{Registers, ,Registers}).
572619370Spst(Value history references, in contrast, are @emph{numbers} preceded
572719370Spstby @samp{$}.  @xref{Value History, ,Value history}.)
572819370Spst
572919370SpstYou can save a value in a convenience variable with an assignment
573019370Spstexpression, just as you would set a variable in your program.
573119370SpstFor example:
573219370Spst
5733130809Smarcel@smallexample
573419370Spstset $foo = *object_ptr
5735130809Smarcel@end smallexample
573619370Spst
573719370Spst@noindent
573819370Spstwould save in @code{$foo} the value contained in the object pointed to by
573919370Spst@code{object_ptr}.
574019370Spst
574119370SpstUsing a convenience variable for the first time creates it, but its
574219370Spstvalue is @code{void} until you assign a new value.  You can alter the
574319370Spstvalue with another assignment at any time.
574419370Spst
574519370SpstConvenience variables have no fixed types.  You can assign a convenience
574619370Spstvariable any type of value, including structures and arrays, even if
574719370Spstthat variable already has a value of a different type.  The convenience
574819370Spstvariable, when used as an expression, has the type of its current value.
574919370Spst
575019370Spst@table @code
575119370Spst@kindex show convenience
575219370Spst@item show convenience
575319370SpstPrint a list of convenience variables used so far, and their values.
575498948SobrienAbbreviated @code{show conv}.
575519370Spst@end table
575619370Spst
575719370SpstOne of the ways to use a convenience variable is as a counter to be
575819370Spstincremented or a pointer to be advanced.  For example, to print
575919370Spsta field from successive elements of an array of structures:
576019370Spst
5761130809Smarcel@smallexample
576219370Spstset $i = 0
576319370Spstprint bar[$i++]->contents
5764130809Smarcel@end smallexample
576519370Spst
576698948Sobrien@noindent
576798948SobrienRepeat that command by typing @key{RET}.
576819370Spst
576919370SpstSome convenience variables are created automatically by @value{GDBN} and given
577019370Spstvalues likely to be useful.
577119370Spst
577219370Spst@table @code
577398948Sobrien@vindex $_@r{, convenience variable}
577419370Spst@item $_
577519370SpstThe variable @code{$_} is automatically set by the @code{x} command to
577619370Spstthe last address examined (@pxref{Memory, ,Examining memory}).  Other
577719370Spstcommands which provide a default address for @code{x} to examine also
577819370Spstset @code{$_} to that address; these commands include @code{info line}
577919370Spstand @code{info breakpoint}.  The type of @code{$_} is @code{void *}
578019370Spstexcept when set by the @code{x} command, in which case it is a pointer
578119370Spstto the type of @code{$__}.
578219370Spst
578398948Sobrien@vindex $__@r{, convenience variable}
578419370Spst@item $__
578519370SpstThe variable @code{$__} is automatically set by the @code{x} command
578619370Spstto the value found in the last address examined.  Its type is chosen
578719370Spstto match the format in which the data was printed.
578819370Spst
578919370Spst@item $_exitcode
579098948Sobrien@vindex $_exitcode@r{, convenience variable}
579119370SpstThe variable @code{$_exitcode} is automatically set to the exit code when
579219370Spstthe program being debugged terminates.
579319370Spst@end table
579419370Spst
579598948SobrienOn HP-UX systems, if you refer to a function or variable name that
579698948Sobrienbegins with a dollar sign, @value{GDBN} searches for a user or system
579798948Sobrienname first, before it searches for a convenience variable.
579846289Sdfr
579998948Sobrien@node Registers
580019370Spst@section Registers
580119370Spst
580219370Spst@cindex registers
580319370SpstYou can refer to machine register contents, in expressions, as variables
580419370Spstwith names starting with @samp{$}.  The names of registers are different
580519370Spstfor each machine; use @code{info registers} to see the names used on
580619370Spstyour machine.
580719370Spst
580819370Spst@table @code
580919370Spst@kindex info registers
581019370Spst@item info registers
581119370SpstPrint the names and values of all registers except floating-point
5812130809Smarceland vector registers (in the selected stack frame).
581319370Spst
581419370Spst@kindex info all-registers
581519370Spst@cindex floating point registers
581619370Spst@item info all-registers
581719370SpstPrint the names and values of all registers, including floating-point
5818130809Smarceland vector registers (in the selected stack frame).
581919370Spst
582019370Spst@item info registers @var{regname} @dots{}
582119370SpstPrint the @dfn{relativized} value of each specified register @var{regname}.
582298948SobrienAs discussed in detail below, register values are normally relative to
582398948Sobrienthe selected stack frame.  @var{regname} may be any register name valid on
582419370Spstthe machine you are using, with or without the initial @samp{$}.
582519370Spst@end table
582619370Spst
582719370Spst@value{GDBN} has four ``standard'' register names that are available (in
582819370Spstexpressions) on most machines---whenever they do not conflict with an
582919370Spstarchitecture's canonical mnemonics for registers.  The register names
583019370Spst@code{$pc} and @code{$sp} are used for the program counter register and
583119370Spstthe stack pointer.  @code{$fp} is used for a register that contains a
583219370Spstpointer to the current stack frame, and @code{$ps} is used for a
583319370Spstregister that contains the processor status.  For example,
583419370Spstyou could print the program counter in hex with
583519370Spst
5836130809Smarcel@smallexample
583719370Spstp/x $pc
5838130809Smarcel@end smallexample
583919370Spst
584019370Spst@noindent
584119370Spstor print the instruction to be executed next with
584219370Spst
5843130809Smarcel@smallexample
584419370Spstx/i $pc
5845130809Smarcel@end smallexample
584619370Spst
584719370Spst@noindent
584819370Spstor add four to the stack pointer@footnote{This is a way of removing
584919370Spstone word from the stack, on machines where stacks grow downward in
585019370Spstmemory (most machines, nowadays).  This assumes that the innermost
585119370Spststack frame is selected; setting @code{$sp} is not allowed when other
585219370Spststack frames are selected.  To pop entire frames off the stack,
585319370Spstregardless of machine architecture, use @code{return};
585498948Sobriensee @ref{Returning, ,Returning from a function}.} with
585519370Spst
5856130809Smarcel@smallexample
585719370Spstset $sp += 4
5858130809Smarcel@end smallexample
585919370Spst
586019370SpstWhenever possible, these four standard register names are available on
586119370Spstyour machine even though the machine has different canonical mnemonics,
586219370Spstso long as there is no conflict.  The @code{info registers} command
586319370Spstshows the canonical names.  For example, on the SPARC, @code{info
586419370Spstregisters} displays the processor status register as @code{$psr} but you
586598948Sobriencan also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
586698948Sobrienis an alias for the @sc{eflags} register.
586719370Spst
586819370Spst@value{GDBN} always considers the contents of an ordinary register as an
586919370Spstinteger when the register is examined in this way.  Some machines have
587019370Spstspecial registers which can hold nothing but floating point; these
587119370Spstregisters are considered to have floating point values.  There is no way
587219370Spstto refer to the contents of an ordinary register as floating point value
587319370Spst(although you can @emph{print} it as a floating point value with
587419370Spst@samp{print/f $@var{regname}}).
587519370Spst
587619370SpstSome registers have distinct ``raw'' and ``virtual'' data formats.  This
587719370Spstmeans that the data format in which the register contents are saved by
587819370Spstthe operating system is not the same one that your program normally
587919370Spstsees.  For example, the registers of the 68881 floating point
588019370Spstcoprocessor are always saved in ``extended'' (raw) format, but all C
588119370Spstprograms expect to work with ``double'' (virtual) format.  In such
588298948Sobriencases, @value{GDBN} normally works with the virtual format only (the format
588319370Spstthat makes sense for your program), but the @code{info registers} command
588419370Spstprints the data in both formats.
588519370Spst
588619370SpstNormally, register values are relative to the selected stack frame
588719370Spst(@pxref{Selection, ,Selecting a frame}).  This means that you get the
588819370Spstvalue that the register would contain if all stack frames farther in
588919370Spstwere exited and their saved registers restored.  In order to see the
589019370Spsttrue contents of hardware registers, you must select the innermost
589119370Spstframe (with @samp{frame 0}).
589219370Spst
589319370SpstHowever, @value{GDBN} must deduce where registers are saved, from the machine
589419370Spstcode generated by your compiler.  If some registers are not saved, or if
589519370Spst@value{GDBN} is unable to locate the saved registers, the selected stack
589619370Spstframe makes no difference.
589719370Spst
589898948Sobrien@node Floating Point Hardware
589919370Spst@section Floating point hardware
590019370Spst@cindex floating point
590119370Spst
590219370SpstDepending on the configuration, @value{GDBN} may be able to give
590319370Spstyou more information about the status of the floating point hardware.
590419370Spst
590519370Spst@table @code
590619370Spst@kindex info float
590719370Spst@item info float
590819370SpstDisplay hardware-dependent information about the floating
590919370Spstpoint unit.  The exact contents and layout vary depending on the
591019370Spstfloating point chip.  Currently, @samp{info float} is supported on
591119370Spstthe ARM and x86 machines.
591219370Spst@end table
591319370Spst
5914130809Smarcel@node Vector Unit
5915130809Smarcel@section Vector Unit
5916130809Smarcel@cindex vector unit
5917130809Smarcel
5918130809SmarcelDepending on the configuration, @value{GDBN} may be able to give you
5919130809Smarcelmore information about the status of the vector unit.
5920130809Smarcel
5921130809Smarcel@table @code
5922130809Smarcel@kindex info vector
5923130809Smarcel@item info vector
5924130809SmarcelDisplay information about the vector unit.  The exact contents and
5925130809Smarcellayout vary depending on the hardware.
5926130809Smarcel@end table
5927130809Smarcel
5928130809Smarcel@node Auxiliary Vector
5929130809Smarcel@section Operating system auxiliary vector
5930130809Smarcel@cindex auxiliary vector
5931130809Smarcel@cindex vector, auxiliary
5932130809Smarcel
5933130809SmarcelSome operating systems supply an @dfn{auxiliary vector} to programs at
5934130809Smarcelstartup.  This is akin to the arguments and environment that you
5935130809Smarcelspecify for a program, but contains a system-dependent variety of
5936130809Smarcelbinary values that tell system libraries important details about the
5937130809Smarcelhardware, operating system, and process.  Each value's purpose is
5938130809Smarcelidentified by an integer tag; the meanings are well-known but system-specific.
5939130809SmarcelDepending on the configuration and operating system facilities,
5940130809Smarcel@value{GDBN} may be able to show you this information.
5941130809Smarcel
5942130809Smarcel@table @code
5943130809Smarcel@kindex info auxv
5944130809Smarcel@item info auxv
5945130809SmarcelDisplay the auxiliary vector of the inferior, which can be either a
5946130809Smarcellive process or a core dump file.  @value{GDBN} prints each tag value
5947130809Smarcelnumerically, and also shows names and text descriptions for recognized
5948130809Smarceltags.  Some values in the vector are numbers, some bit masks, and some
5949130809Smarcelpointers to strings or other data.  @value{GDBN} displays each value in the
5950130809Smarcelmost appropriate form for a recognized tag, and in hexadecimal for
5951130809Smarcelan unrecognized tag.
5952130809Smarcel@end table
5953130809Smarcel
595498948Sobrien@node Memory Region Attributes
5955130809Smarcel@section Memory region attributes
595698948Sobrien@cindex memory region attributes
595798948Sobrien
5958130809Smarcel@dfn{Memory region attributes} allow you to describe special handling
5959130809Smarcelrequired by regions of your target's memory.  @value{GDBN} uses attributes
596098948Sobriento determine whether to allow certain types of memory accesses; whether to
596198948Sobrienuse specific width accesses; and whether to cache target memory.
596298948Sobrien
596398948SobrienDefined memory regions can be individually enabled and disabled.  When a
596498948Sobrienmemory region is disabled, @value{GDBN} uses the default attributes when
596598948Sobrienaccessing memory in that region.  Similarly, if no memory regions have
596698948Sobrienbeen defined, @value{GDBN} uses the default attributes when accessing
596798948Sobrienall memory.
596898948Sobrien
5969130809SmarcelWhen a memory region is defined, it is given a number to identify it;
597098948Sobriento enable, disable, or remove a memory region, you specify that number.
597198948Sobrien
597298948Sobrien@table @code
597398948Sobrien@kindex mem
5974130809Smarcel@item mem @var{lower} @var{upper} @var{attributes}@dots{}
5975130809SmarcelDefine memory region bounded by @var{lower} and @var{upper} with
5976130809Smarcelattributes @var{attributes}@dots{}.  Note that @var{upper} == 0 is a
5977130809Smarcelspecial case: it is treated as the the target's maximum memory address.
5978130809Smarcel(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
597998948Sobrien
598098948Sobrien@kindex delete mem
598198948Sobrien@item delete mem @var{nums}@dots{}
598298948SobrienRemove memory regions @var{nums}@dots{}.
598398948Sobrien
598498948Sobrien@kindex disable mem
598598948Sobrien@item disable mem @var{nums}@dots{}
598698948SobrienDisable memory regions @var{nums}@dots{}.
5987130809SmarcelA disabled memory region is not forgotten.
598898948SobrienIt may be enabled again later.
598998948Sobrien
599098948Sobrien@kindex enable mem
599198948Sobrien@item enable mem @var{nums}@dots{}
599298948SobrienEnable memory regions @var{nums}@dots{}.
599398948Sobrien
599498948Sobrien@kindex info mem
599598948Sobrien@item info mem
599698948SobrienPrint a table of all defined memory regions, with the following columns
599798948Sobrienfor each region.
599898948Sobrien
599998948Sobrien@table @emph
600098948Sobrien@item Memory Region Number
600198948Sobrien@item Enabled or Disabled.
6002130809SmarcelEnabled memory regions are marked with @samp{y}.
600398948SobrienDisabled memory regions are marked with @samp{n}.
600498948Sobrien
600598948Sobrien@item Lo Address
600698948SobrienThe address defining the inclusive lower bound of the memory region.
600798948Sobrien
600898948Sobrien@item Hi Address
600998948SobrienThe address defining the exclusive upper bound of the memory region.
601098948Sobrien
601198948Sobrien@item Attributes
601298948SobrienThe list of attributes set for this memory region.
601398948Sobrien@end table
601498948Sobrien@end table
601598948Sobrien
601698948Sobrien
601798948Sobrien@subsection Attributes
601898948Sobrien
6019130809Smarcel@subsubsection Memory Access Mode
602098948SobrienThe access mode attributes set whether @value{GDBN} may make read or
602198948Sobrienwrite accesses to a memory region.
602298948Sobrien
602398948SobrienWhile these attributes prevent @value{GDBN} from performing invalid
602498948Sobrienmemory accesses, they do nothing to prevent the target system, I/O DMA,
602598948Sobrienetc. from accessing memory.
602698948Sobrien
602798948Sobrien@table @code
602898948Sobrien@item ro
602998948SobrienMemory is read only.
603098948Sobrien@item wo
603198948SobrienMemory is write only.
603298948Sobrien@item rw
603398948SobrienMemory is read/write.  This is the default.
603498948Sobrien@end table
603598948Sobrien
603698948Sobrien@subsubsection Memory Access Size
603798948SobrienThe acccess size attributes tells @value{GDBN} to use specific sized
603898948Sobrienaccesses in the memory region.  Often memory mapped device registers
603998948Sobrienrequire specific sized accesses.  If no access size attribute is
604098948Sobrienspecified, @value{GDBN} may use accesses of any size.
604198948Sobrien
604298948Sobrien@table @code
604398948Sobrien@item 8
604498948SobrienUse 8 bit memory accesses.
604598948Sobrien@item 16
604698948SobrienUse 16 bit memory accesses.
604798948Sobrien@item 32
604898948SobrienUse 32 bit memory accesses.
604998948Sobrien@item 64
605098948SobrienUse 64 bit memory accesses.
605198948Sobrien@end table
605298948Sobrien
605398948Sobrien@c @subsubsection Hardware/Software Breakpoints
605498948Sobrien@c The hardware/software breakpoint attributes set whether @value{GDBN}
605598948Sobrien@c will use hardware or software breakpoints for the internal breakpoints
605698948Sobrien@c used by the step, next, finish, until, etc. commands.
605798948Sobrien@c
605898948Sobrien@c @table @code
605998948Sobrien@c @item hwbreak
6060130809Smarcel@c Always use hardware breakpoints
606198948Sobrien@c @item swbreak (default)
606298948Sobrien@c @end table
606398948Sobrien
606498948Sobrien@subsubsection Data Cache
606598948SobrienThe data cache attributes set whether @value{GDBN} will cache target
606698948Sobrienmemory.  While this generally improves performance by reducing debug
606798948Sobrienprotocol overhead, it can lead to incorrect results because @value{GDBN}
606898948Sobriendoes not know about volatile variables or memory mapped device
606998948Sobrienregisters.
607098948Sobrien
607198948Sobrien@table @code
607298948Sobrien@item cache
6073130809SmarcelEnable @value{GDBN} to cache target memory.
607498948Sobrien@item nocache
607598948SobrienDisable @value{GDBN} from caching target memory.  This is the default.
607698948Sobrien@end table
607798948Sobrien
607898948Sobrien@c @subsubsection Memory Write Verification
6079130809Smarcel@c The memory write verification attributes set whether @value{GDBN}
608098948Sobrien@c will re-reads data after each write to verify the write was successful.
608198948Sobrien@c
608298948Sobrien@c @table @code
608398948Sobrien@c @item verify
608498948Sobrien@c @item noverify (default)
608598948Sobrien@c @end table
608698948Sobrien
6087130809Smarcel@node Dump/Restore Files
6088130809Smarcel@section Copy between memory and a file
6089130809Smarcel@cindex dump/restore files
6090130809Smarcel@cindex append data to a file
6091130809Smarcel@cindex dump data to a file
6092130809Smarcel@cindex restore data from a file
6093130809Smarcel
6094130809SmarcelYou can use the commands @code{dump}, @code{append}, and
6095130809Smarcel@code{restore} to copy data between target memory and a file.  The
6096130809Smarcel@code{dump} and @code{append} commands write data to a file, and the
6097130809Smarcel@code{restore} command reads data from a file back into the inferior's
6098130809Smarcelmemory.  Files may be in binary, Motorola S-record, Intel hex, or
6099130809SmarcelTektronix Hex format; however, @value{GDBN} can only append to binary
6100130809Smarcelfiles.
6101130809Smarcel
6102130809Smarcel@table @code
6103130809Smarcel
6104130809Smarcel@kindex dump
6105130809Smarcel@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6106130809Smarcel@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6107130809SmarcelDump the contents of memory from @var{start_addr} to @var{end_addr},
6108130809Smarcelor the value of @var{expr}, to @var{filename} in the given format.
6109130809Smarcel
6110130809SmarcelThe @var{format} parameter may be any one of:
6111130809Smarcel@table @code
6112130809Smarcel@item binary
6113130809SmarcelRaw binary form.
6114130809Smarcel@item ihex
6115130809SmarcelIntel hex format.
6116130809Smarcel@item srec
6117130809SmarcelMotorola S-record format.
6118130809Smarcel@item tekhex
6119130809SmarcelTektronix Hex format.
6120130809Smarcel@end table
6121130809Smarcel
6122130809Smarcel@value{GDBN} uses the same definitions of these formats as the
6123130809Smarcel@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}.  If
6124130809Smarcel@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6125130809Smarcelform.
6126130809Smarcel
6127130809Smarcel@kindex append
6128130809Smarcel@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6129130809Smarcel@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6130130809SmarcelAppend the contents of memory from @var{start_addr} to @var{end_addr},
6131130809Smarcelor the value of @var{expr}, to @var{filename}, in raw binary form.
6132130809Smarcel(@value{GDBN} can only append data to files in raw binary form.)
6133130809Smarcel
6134130809Smarcel@kindex restore
6135130809Smarcel@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6136130809SmarcelRestore the contents of file @var{filename} into memory.  The
6137130809Smarcel@code{restore} command can automatically recognize any known @sc{bfd}
6138130809Smarcelfile format, except for raw binary.  To restore a raw binary file you
6139130809Smarcelmust specify the optional keyword @code{binary} after the filename.
6140130809Smarcel
6141130809SmarcelIf @var{bias} is non-zero, its value will be added to the addresses
6142130809Smarcelcontained in the file.  Binary files always start at address zero, so
6143130809Smarcelthey will be restored at address @var{bias}.  Other bfd files have
6144130809Smarcela built-in location; they will be restored at offset @var{bias}
6145130809Smarcelfrom that location.
6146130809Smarcel
6147130809SmarcelIf @var{start} and/or @var{end} are non-zero, then only data between
6148130809Smarcelfile offset @var{start} and file offset @var{end} will be restored.
6149130809SmarcelThese offsets are relative to the addresses in the file, before
6150130809Smarcelthe @var{bias} argument is applied.
6151130809Smarcel
6152130809Smarcel@end table
6153130809Smarcel
6154130809Smarcel@node Character Sets
6155130809Smarcel@section Character Sets
6156130809Smarcel@cindex character sets
6157130809Smarcel@cindex charset
6158130809Smarcel@cindex translating between character sets
6159130809Smarcel@cindex host character set
6160130809Smarcel@cindex target character set
6161130809Smarcel
6162130809SmarcelIf the program you are debugging uses a different character set to
6163130809Smarcelrepresent characters and strings than the one @value{GDBN} uses itself,
6164130809Smarcel@value{GDBN} can automatically translate between the character sets for
6165130809Smarcelyou.  The character set @value{GDBN} uses we call the @dfn{host
6166130809Smarcelcharacter set}; the one the inferior program uses we call the
6167130809Smarcel@dfn{target character set}.
6168130809Smarcel
6169130809SmarcelFor example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6170130809Smarceluses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6171130809Smarcelremote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6172130809Smarcelrunning on an IBM mainframe, which uses the @sc{ebcdic} character set,
6173130809Smarcelthen the host character set is Latin-1, and the target character set is
6174130809Smarcel@sc{ebcdic}.  If you give @value{GDBN} the command @code{set
6175130809Smarceltarget-charset EBCDIC-US}, then @value{GDBN} translates between
6176130809Smarcel@sc{ebcdic} and Latin 1 as you print character or string values, or use
6177130809Smarcelcharacter and string literals in expressions.
6178130809Smarcel
6179130809Smarcel@value{GDBN} has no way to automatically recognize which character set
6180130809Smarcelthe inferior program uses; you must tell it, using the @code{set
6181130809Smarceltarget-charset} command, described below.
6182130809Smarcel
6183130809SmarcelHere are the commands for controlling @value{GDBN}'s character set
6184130809Smarcelsupport:
6185130809Smarcel
6186130809Smarcel@table @code
6187130809Smarcel@item set target-charset @var{charset}
6188130809Smarcel@kindex set target-charset
6189130809SmarcelSet the current target character set to @var{charset}.  We list the
6190130809Smarcelcharacter set names @value{GDBN} recognizes below, but if you type
6191130809Smarcel@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6192130809Smarcellist the target character sets it supports.
6193130809Smarcel@end table
6194130809Smarcel
6195130809Smarcel@table @code
6196130809Smarcel@item set host-charset @var{charset}
6197130809Smarcel@kindex set host-charset
6198130809SmarcelSet the current host character set to @var{charset}.
6199130809Smarcel
6200130809SmarcelBy default, @value{GDBN} uses a host character set appropriate to the
6201130809Smarcelsystem it is running on; you can override that default using the
6202130809Smarcel@code{set host-charset} command.
6203130809Smarcel
6204130809Smarcel@value{GDBN} can only use certain character sets as its host character
6205130809Smarcelset.  We list the character set names @value{GDBN} recognizes below, and
6206130809Smarcelindicate which can be host character sets, but if you type
6207130809Smarcel@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6208130809Smarcellist the host character sets it supports.
6209130809Smarcel
6210130809Smarcel@item set charset @var{charset}
6211130809Smarcel@kindex set charset
6212130809SmarcelSet the current host and target character sets to @var{charset}.  As
6213130809Smarcelabove, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6214130809Smarcel@value{GDBN} will list the name of the character sets that can be used
6215130809Smarcelfor both host and target.
6216130809Smarcel
6217130809Smarcel
6218130809Smarcel@item show charset
6219130809Smarcel@kindex show charset
6220130809SmarcelShow the names of the current host and target charsets.
6221130809Smarcel
6222130809Smarcel@itemx show host-charset
6223130809Smarcel@kindex show host-charset
6224130809SmarcelShow the name of the current host charset.
6225130809Smarcel
6226130809Smarcel@itemx show target-charset
6227130809Smarcel@kindex show target-charset
6228130809SmarcelShow the name of the current target charset.
6229130809Smarcel
6230130809Smarcel@end table
6231130809Smarcel
6232130809Smarcel@value{GDBN} currently includes support for the following character
6233130809Smarcelsets:
6234130809Smarcel
6235130809Smarcel@table @code
6236130809Smarcel
6237130809Smarcel@item ASCII
6238130809Smarcel@cindex ASCII character set
6239130809SmarcelSeven-bit U.S. @sc{ascii}.  @value{GDBN} can use this as its host
6240130809Smarcelcharacter set.
6241130809Smarcel
6242130809Smarcel@item ISO-8859-1
6243130809Smarcel@cindex ISO 8859-1 character set
6244130809Smarcel@cindex ISO Latin 1 character set
6245130809SmarcelThe ISO Latin 1 character set.  This extends @sc{ascii} with accented
6246130809Smarcelcharacters needed for French, German, and Spanish.  @value{GDBN} can use
6247130809Smarcelthis as its host character set.
6248130809Smarcel
6249130809Smarcel@item EBCDIC-US
6250130809Smarcel@itemx IBM1047
6251130809Smarcel@cindex EBCDIC character set
6252130809Smarcel@cindex IBM1047 character set
6253130809SmarcelVariants of the @sc{ebcdic} character set, used on some of IBM's
6254130809Smarcelmainframe operating systems.  (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6255130809Smarcel@value{GDBN} cannot use these as its host character set.
6256130809Smarcel
6257130809Smarcel@end table
6258130809Smarcel
6259130809SmarcelNote that these are all single-byte character sets.  More work inside
6260130809SmarcelGDB is needed to support multi-byte or variable-width character
6261130809Smarcelencodings, like the UTF-8 and UCS-2 encodings of Unicode.
6262130809Smarcel
6263130809SmarcelHere is an example of @value{GDBN}'s character set support in action.
6264130809SmarcelAssume that the following source code has been placed in the file
6265130809Smarcel@file{charset-test.c}:
6266130809Smarcel
6267130809Smarcel@smallexample
6268130809Smarcel#include <stdio.h>
6269130809Smarcel
6270130809Smarcelchar ascii_hello[]
6271130809Smarcel  = @{72, 101, 108, 108, 111, 44, 32, 119,
6272130809Smarcel     111, 114, 108, 100, 33, 10, 0@};
6273130809Smarcelchar ibm1047_hello[]
6274130809Smarcel  = @{200, 133, 147, 147, 150, 107, 64, 166,
6275130809Smarcel     150, 153, 147, 132, 90, 37, 0@};
6276130809Smarcel
6277130809Smarcelmain ()
6278130809Smarcel@{
6279130809Smarcel  printf ("Hello, world!\n");
6280130809Smarcel@}
6281130809Smarcel@end smallexample
6282130809Smarcel
6283130809SmarcelIn this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6284130809Smarcelcontaining the string @samp{Hello, world!} followed by a newline,
6285130809Smarcelencoded in the @sc{ascii} and @sc{ibm1047} character sets.
6286130809Smarcel
6287130809SmarcelWe compile the program, and invoke the debugger on it:
6288130809Smarcel
6289130809Smarcel@smallexample
6290130809Smarcel$ gcc -g charset-test.c -o charset-test
6291130809Smarcel$ gdb -nw charset-test
6292130809SmarcelGNU gdb 2001-12-19-cvs
6293130809SmarcelCopyright 2001 Free Software Foundation, Inc.
6294130809Smarcel@dots{}
6295130809Smarcel(gdb)
6296130809Smarcel@end smallexample
6297130809Smarcel
6298130809SmarcelWe can use the @code{show charset} command to see what character sets
6299130809Smarcel@value{GDBN} is currently using to interpret and display characters and
6300130809Smarcelstrings:
6301130809Smarcel
6302130809Smarcel@smallexample
6303130809Smarcel(gdb) show charset
6304130809SmarcelThe current host and target character set is `ISO-8859-1'.
6305130809Smarcel(gdb)
6306130809Smarcel@end smallexample
6307130809Smarcel
6308130809SmarcelFor the sake of printing this manual, let's use @sc{ascii} as our
6309130809Smarcelinitial character set:
6310130809Smarcel@smallexample
6311130809Smarcel(gdb) set charset ASCII
6312130809Smarcel(gdb) show charset
6313130809SmarcelThe current host and target character set is `ASCII'.
6314130809Smarcel(gdb)
6315130809Smarcel@end smallexample
6316130809Smarcel
6317130809SmarcelLet's assume that @sc{ascii} is indeed the correct character set for our
6318130809Smarcelhost system --- in other words, let's assume that if @value{GDBN} prints
6319130809Smarcelcharacters using the @sc{ascii} character set, our terminal will display
6320130809Smarcelthem properly.  Since our current target character set is also
6321130809Smarcel@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6322130809Smarcel
6323130809Smarcel@smallexample
6324130809Smarcel(gdb) print ascii_hello
6325130809Smarcel$1 = 0x401698 "Hello, world!\n"
6326130809Smarcel(gdb) print ascii_hello[0]
6327130809Smarcel$2 = 72 'H'
6328130809Smarcel(gdb)
6329130809Smarcel@end smallexample
6330130809Smarcel
6331130809Smarcel@value{GDBN} uses the target character set for character and string
6332130809Smarcelliterals you use in expressions:
6333130809Smarcel
6334130809Smarcel@smallexample
6335130809Smarcel(gdb) print '+'
6336130809Smarcel$3 = 43 '+'
6337130809Smarcel(gdb)
6338130809Smarcel@end smallexample
6339130809Smarcel
6340130809SmarcelThe @sc{ascii} character set uses the number 43 to encode the @samp{+}
6341130809Smarcelcharacter.
6342130809Smarcel
6343130809Smarcel@value{GDBN} relies on the user to tell it which character set the
6344130809Smarceltarget program uses.  If we print @code{ibm1047_hello} while our target
6345130809Smarcelcharacter set is still @sc{ascii}, we get jibberish:
6346130809Smarcel
6347130809Smarcel@smallexample
6348130809Smarcel(gdb) print ibm1047_hello
6349130809Smarcel$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
6350130809Smarcel(gdb) print ibm1047_hello[0]
6351130809Smarcel$5 = 200 '\310'
6352130809Smarcel(gdb)
6353130809Smarcel@end smallexample
6354130809Smarcel
6355130809SmarcelIf we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
6356130809Smarcel@value{GDBN} tells us the character sets it supports:
6357130809Smarcel
6358130809Smarcel@smallexample
6359130809Smarcel(gdb) set target-charset
6360130809SmarcelASCII       EBCDIC-US   IBM1047     ISO-8859-1
6361130809Smarcel(gdb) set target-charset
6362130809Smarcel@end smallexample
6363130809Smarcel
6364130809SmarcelWe can select @sc{ibm1047} as our target character set, and examine the
6365130809Smarcelprogram's strings again.  Now the @sc{ascii} string is wrong, but
6366130809Smarcel@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6367130809Smarceltarget character set, @sc{ibm1047}, to the host character set,
6368130809Smarcel@sc{ascii}, and they display correctly:
6369130809Smarcel
6370130809Smarcel@smallexample
6371130809Smarcel(gdb) set target-charset IBM1047
6372130809Smarcel(gdb) show charset
6373130809SmarcelThe current host character set is `ASCII'.
6374130809SmarcelThe current target character set is `IBM1047'.
6375130809Smarcel(gdb) print ascii_hello
6376130809Smarcel$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
6377130809Smarcel(gdb) print ascii_hello[0]
6378130809Smarcel$7 = 72 '\110'
6379130809Smarcel(gdb) print ibm1047_hello
6380130809Smarcel$8 = 0x4016a8 "Hello, world!\n"
6381130809Smarcel(gdb) print ibm1047_hello[0]
6382130809Smarcel$9 = 200 'H'
6383130809Smarcel(gdb)
6384130809Smarcel@end smallexample
6385130809Smarcel
6386130809SmarcelAs above, @value{GDBN} uses the target character set for character and
6387130809Smarcelstring literals you use in expressions:
6388130809Smarcel
6389130809Smarcel@smallexample
6390130809Smarcel(gdb) print '+'
6391130809Smarcel$10 = 78 '+'
6392130809Smarcel(gdb)
6393130809Smarcel@end smallexample
6394130809Smarcel
6395130809SmarcelThe @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
6396130809Smarcelcharacter.
6397130809Smarcel
6398130809Smarcel
6399130809Smarcel@node Macros
6400130809Smarcel@chapter C Preprocessor Macros
6401130809Smarcel
6402130809SmarcelSome languages, such as C and C@t{++}, provide a way to define and invoke
6403130809Smarcel``preprocessor macros'' which expand into strings of tokens.
6404130809Smarcel@value{GDBN} can evaluate expressions containing macro invocations, show
6405130809Smarcelthe result of macro expansion, and show a macro's definition, including
6406130809Smarcelwhere it was defined.
6407130809Smarcel
6408130809SmarcelYou may need to compile your program specially to provide @value{GDBN}
6409130809Smarcelwith information about preprocessor macros.  Most compilers do not
6410130809Smarcelinclude macros in their debugging information, even when you compile
6411130809Smarcelwith the @option{-g} flag.  @xref{Compilation}.
6412130809Smarcel
6413130809SmarcelA program may define a macro at one point, remove that definition later,
6414130809Smarceland then provide a different definition after that.  Thus, at different
6415130809Smarcelpoints in the program, a macro may have different definitions, or have
6416130809Smarcelno definition at all.  If there is a current stack frame, @value{GDBN}
6417130809Smarceluses the macros in scope at that frame's source code line.  Otherwise,
6418130809Smarcel@value{GDBN} uses the macros in scope at the current listing location;
6419130809Smarcelsee @ref{List}.
6420130809Smarcel
6421130809SmarcelAt the moment, @value{GDBN} does not support the @code{##}
6422130809Smarceltoken-splicing operator, the @code{#} stringification operator, or
6423130809Smarcelvariable-arity macros.
6424130809Smarcel
6425130809SmarcelWhenever @value{GDBN} evaluates an expression, it always expands any
6426130809Smarcelmacro invocations present in the expression.  @value{GDBN} also provides
6427130809Smarcelthe following commands for working with macros explicitly.
6428130809Smarcel
6429130809Smarcel@table @code
6430130809Smarcel
6431130809Smarcel@kindex macro expand
6432130809Smarcel@cindex macro expansion, showing the results of preprocessor
6433130809Smarcel@cindex preprocessor macro expansion, showing the results of
6434130809Smarcel@cindex expanding preprocessor macros
6435130809Smarcel@item macro expand @var{expression}
6436130809Smarcel@itemx macro exp @var{expression}
6437130809SmarcelShow the results of expanding all preprocessor macro invocations in
6438130809Smarcel@var{expression}.  Since @value{GDBN} simply expands macros, but does
6439130809Smarcelnot parse the result, @var{expression} need not be a valid expression;
6440130809Smarcelit can be any string of tokens.
6441130809Smarcel
6442130809Smarcel@kindex macro expand-once
6443130809Smarcel@item macro expand-once @var{expression}
6444130809Smarcel@itemx macro exp1 @var{expression}
6445130809Smarcel@i{(This command is not yet implemented.)}  Show the results of
6446130809Smarcelexpanding those preprocessor macro invocations that appear explicitly in
6447130809Smarcel@var{expression}.  Macro invocations appearing in that expansion are
6448130809Smarcelleft unchanged.  This command allows you to see the effect of a
6449130809Smarcelparticular macro more clearly, without being confused by further
6450130809Smarcelexpansions.  Since @value{GDBN} simply expands macros, but does not
6451130809Smarcelparse the result, @var{expression} need not be a valid expression; it
6452130809Smarcelcan be any string of tokens.
6453130809Smarcel
6454130809Smarcel@kindex info macro
6455130809Smarcel@cindex macro definition, showing
6456130809Smarcel@cindex definition, showing a macro's
6457130809Smarcel@item info macro @var{macro}
6458130809SmarcelShow the definition of the macro named @var{macro}, and describe the
6459130809Smarcelsource location where that definition was established.
6460130809Smarcel
6461130809Smarcel@kindex macro define
6462130809Smarcel@cindex user-defined macros
6463130809Smarcel@cindex defining macros interactively
6464130809Smarcel@cindex macros, user-defined
6465130809Smarcel@item macro define @var{macro} @var{replacement-list}
6466130809Smarcel@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6467130809Smarcel@i{(This command is not yet implemented.)}  Introduce a definition for a
6468130809Smarcelpreprocessor macro named @var{macro}, invocations of which are replaced
6469130809Smarcelby the tokens given in @var{replacement-list}.  The first form of this
6470130809Smarcelcommand defines an ``object-like'' macro, which takes no arguments; the
6471130809Smarcelsecond form defines a ``function-like'' macro, which takes the arguments
6472130809Smarcelgiven in @var{arglist}.
6473130809Smarcel
6474130809SmarcelA definition introduced by this command is in scope in every expression
6475130809Smarcelevaluated in @value{GDBN}, until it is removed with the @command{macro
6476130809Smarcelundef} command, described below.  The definition overrides all
6477130809Smarceldefinitions for @var{macro} present in the program being debugged, as
6478130809Smarcelwell as any previous user-supplied definition.
6479130809Smarcel
6480130809Smarcel@kindex macro undef
6481130809Smarcel@item macro undef @var{macro}
6482130809Smarcel@i{(This command is not yet implemented.)}  Remove any user-supplied
6483130809Smarceldefinition for the macro named @var{macro}.  This command only affects
6484130809Smarceldefinitions provided with the @command{macro define} command, described
6485130809Smarcelabove; it cannot remove definitions present in the program being
6486130809Smarceldebugged.
6487130809Smarcel
6488130809Smarcel@end table
6489130809Smarcel
6490130809Smarcel@cindex macros, example of debugging with
6491130809SmarcelHere is a transcript showing the above commands in action.  First, we
6492130809Smarcelshow our source files:
6493130809Smarcel
6494130809Smarcel@smallexample
6495130809Smarcel$ cat sample.c
6496130809Smarcel#include <stdio.h>
6497130809Smarcel#include "sample.h"
6498130809Smarcel
6499130809Smarcel#define M 42
6500130809Smarcel#define ADD(x) (M + x)
6501130809Smarcel
6502130809Smarcelmain ()
6503130809Smarcel@{
6504130809Smarcel#define N 28
6505130809Smarcel  printf ("Hello, world!\n");
6506130809Smarcel#undef N
6507130809Smarcel  printf ("We're so creative.\n");
6508130809Smarcel#define N 1729
6509130809Smarcel  printf ("Goodbye, world!\n");
6510130809Smarcel@}
6511130809Smarcel$ cat sample.h
6512130809Smarcel#define Q <
6513130809Smarcel$
6514130809Smarcel@end smallexample
6515130809Smarcel
6516130809SmarcelNow, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6517130809SmarcelWe pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6518130809Smarcelcompiler includes information about preprocessor macros in the debugging
6519130809Smarcelinformation.
6520130809Smarcel
6521130809Smarcel@smallexample
6522130809Smarcel$ gcc -gdwarf-2 -g3 sample.c -o sample
6523130809Smarcel$
6524130809Smarcel@end smallexample
6525130809Smarcel
6526130809SmarcelNow, we start @value{GDBN} on our sample program:
6527130809Smarcel
6528130809Smarcel@smallexample
6529130809Smarcel$ gdb -nw sample
6530130809SmarcelGNU gdb 2002-05-06-cvs
6531130809SmarcelCopyright 2002 Free Software Foundation, Inc.
6532130809SmarcelGDB is free software, @dots{}
6533130809Smarcel(gdb)
6534130809Smarcel@end smallexample
6535130809Smarcel
6536130809SmarcelWe can expand macros and examine their definitions, even when the
6537130809Smarcelprogram is not running.  @value{GDBN} uses the current listing position
6538130809Smarcelto decide which macro definitions are in scope:
6539130809Smarcel
6540130809Smarcel@smallexample
6541130809Smarcel(gdb) list main
6542130809Smarcel3
6543130809Smarcel4       #define M 42
6544130809Smarcel5       #define ADD(x) (M + x)
6545130809Smarcel6
6546130809Smarcel7       main ()
6547130809Smarcel8       @{
6548130809Smarcel9       #define N 28
6549130809Smarcel10        printf ("Hello, world!\n");
6550130809Smarcel11      #undef N
6551130809Smarcel12        printf ("We're so creative.\n");
6552130809Smarcel(gdb) info macro ADD
6553130809SmarcelDefined at /home/jimb/gdb/macros/play/sample.c:5
6554130809Smarcel#define ADD(x) (M + x)
6555130809Smarcel(gdb) info macro Q
6556130809SmarcelDefined at /home/jimb/gdb/macros/play/sample.h:1
6557130809Smarcel  included at /home/jimb/gdb/macros/play/sample.c:2
6558130809Smarcel#define Q <
6559130809Smarcel(gdb) macro expand ADD(1)
6560130809Smarcelexpands to: (42 + 1)
6561130809Smarcel(gdb) macro expand-once ADD(1)
6562130809Smarcelexpands to: once (M + 1)
6563130809Smarcel(gdb)
6564130809Smarcel@end smallexample
6565130809Smarcel
6566130809SmarcelIn the example above, note that @command{macro expand-once} expands only
6567130809Smarcelthe macro invocation explicit in the original text --- the invocation of
6568130809Smarcel@code{ADD} --- but does not expand the invocation of the macro @code{M},
6569130809Smarcelwhich was introduced by @code{ADD}.
6570130809Smarcel
6571130809SmarcelOnce the program is running, GDB uses the macro definitions in force at
6572130809Smarcelthe source line of the current stack frame:
6573130809Smarcel
6574130809Smarcel@smallexample
6575130809Smarcel(gdb) break main
6576130809SmarcelBreakpoint 1 at 0x8048370: file sample.c, line 10.
6577130809Smarcel(gdb) run
6578130809SmarcelStarting program: /home/jimb/gdb/macros/play/sample
6579130809Smarcel
6580130809SmarcelBreakpoint 1, main () at sample.c:10
6581130809Smarcel10        printf ("Hello, world!\n");
6582130809Smarcel(gdb)
6583130809Smarcel@end smallexample
6584130809Smarcel
6585130809SmarcelAt line 10, the definition of the macro @code{N} at line 9 is in force:
6586130809Smarcel
6587130809Smarcel@smallexample
6588130809Smarcel(gdb) info macro N
6589130809SmarcelDefined at /home/jimb/gdb/macros/play/sample.c:9
6590130809Smarcel#define N 28
6591130809Smarcel(gdb) macro expand N Q M
6592130809Smarcelexpands to: 28 < 42
6593130809Smarcel(gdb) print N Q M
6594130809Smarcel$1 = 1
6595130809Smarcel(gdb)
6596130809Smarcel@end smallexample
6597130809Smarcel
6598130809SmarcelAs we step over directives that remove @code{N}'s definition, and then
6599130809Smarcelgive it a new definition, @value{GDBN} finds the definition (or lack
6600130809Smarcelthereof) in force at each point:
6601130809Smarcel
6602130809Smarcel@smallexample
6603130809Smarcel(gdb) next
6604130809SmarcelHello, world!
6605130809Smarcel12        printf ("We're so creative.\n");
6606130809Smarcel(gdb) info macro N
6607130809SmarcelThe symbol `N' has no definition as a C/C++ preprocessor macro
6608130809Smarcelat /home/jimb/gdb/macros/play/sample.c:12
6609130809Smarcel(gdb) next
6610130809SmarcelWe're so creative.
6611130809Smarcel14        printf ("Goodbye, world!\n");
6612130809Smarcel(gdb) info macro N
6613130809SmarcelDefined at /home/jimb/gdb/macros/play/sample.c:13
6614130809Smarcel#define N 1729
6615130809Smarcel(gdb) macro expand N Q M
6616130809Smarcelexpands to: 1729 < 42
6617130809Smarcel(gdb) print N Q M
6618130809Smarcel$2 = 0
6619130809Smarcel(gdb)
6620130809Smarcel@end smallexample
6621130809Smarcel
6622130809Smarcel
662398948Sobrien@node Tracepoints
662498948Sobrien@chapter Tracepoints
662598948Sobrien@c This chapter is based on the documentation written by Michael
662698948Sobrien@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
662798948Sobrien
662898948Sobrien@cindex tracepoints
662998948SobrienIn some applications, it is not feasible for the debugger to interrupt
663098948Sobrienthe program's execution long enough for the developer to learn
663198948Sobrienanything helpful about its behavior.  If the program's correctness
663298948Sobriendepends on its real-time behavior, delays introduced by a debugger
663398948Sobrienmight cause the program to change its behavior drastically, or perhaps
663498948Sobrienfail, even when the code itself is correct.  It is useful to be able
663598948Sobriento observe the program's behavior without interrupting it.
663698948Sobrien
663798948SobrienUsing @value{GDBN}'s @code{trace} and @code{collect} commands, you can
663898948Sobrienspecify locations in the program, called @dfn{tracepoints}, and
663998948Sobrienarbitrary expressions to evaluate when those tracepoints are reached.
664098948SobrienLater, using the @code{tfind} command, you can examine the values
664198948Sobrienthose expressions had when the program hit the tracepoints.  The
664298948Sobrienexpressions may also denote objects in memory---structures or arrays,
664398948Sobrienfor example---whose values @value{GDBN} should record; while visiting
664498948Sobriena particular tracepoint, you may inspect those objects as if they were
664598948Sobrienin memory at that moment.  However, because @value{GDBN} records these
664698948Sobrienvalues without interacting with you, it can do so quickly and
664798948Sobrienunobtrusively, hopefully not disturbing the program's behavior.
664898948Sobrien
664998948SobrienThe tracepoint facility is currently available only for remote
665098948Sobrientargets.  @xref{Targets}.  In addition, your remote target must know how
665198948Sobriento collect trace data.  This functionality is implemented in the remote
665298948Sobrienstub; however, none of the stubs distributed with @value{GDBN} support
665398948Sobrientracepoints as of this writing.
665498948Sobrien
665598948SobrienThis chapter describes the tracepoint commands and features.
665698948Sobrien
665798948Sobrien@menu
6658130809Smarcel* Set Tracepoints::
6659130809Smarcel* Analyze Collected Data::
6660130809Smarcel* Tracepoint Variables::
666198948Sobrien@end menu
666298948Sobrien
666398948Sobrien@node Set Tracepoints
666498948Sobrien@section Commands to Set Tracepoints
666598948Sobrien
666698948SobrienBefore running such a @dfn{trace experiment}, an arbitrary number of
666798948Sobrientracepoints can be set.  Like a breakpoint (@pxref{Set Breaks}), a
666898948Sobrientracepoint has a number assigned to it by @value{GDBN}.  Like with
666998948Sobrienbreakpoints, tracepoint numbers are successive integers starting from
667098948Sobrienone.  Many of the commands associated with tracepoints take the
667198948Sobrientracepoint number as their argument, to identify which tracepoint to
667298948Sobrienwork on.
667398948Sobrien
667498948SobrienFor each tracepoint, you can specify, in advance, some arbitrary set
667598948Sobrienof data that you want the target to collect in the trace buffer when
667698948Sobrienit hits that tracepoint.  The collected data can include registers,
667798948Sobrienlocal variables, or global data.  Later, you can use @value{GDBN}
667898948Sobriencommands to examine the values these data had at the time the
667998948Sobrientracepoint was hit.
668098948Sobrien
668198948SobrienThis section describes commands to set tracepoints and associated
668298948Sobrienconditions and actions.
668398948Sobrien
668498948Sobrien@menu
6685130809Smarcel* Create and Delete Tracepoints::
6686130809Smarcel* Enable and Disable Tracepoints::
6687130809Smarcel* Tracepoint Passcounts::
6688130809Smarcel* Tracepoint Actions::
6689130809Smarcel* Listing Tracepoints::
6690130809Smarcel* Starting and Stopping Trace Experiment::
669198948Sobrien@end menu
669298948Sobrien
669398948Sobrien@node Create and Delete Tracepoints
669498948Sobrien@subsection Create and Delete Tracepoints
669598948Sobrien
669698948Sobrien@table @code
669798948Sobrien@cindex set tracepoint
669898948Sobrien@kindex trace
669998948Sobrien@item trace
670098948SobrienThe @code{trace} command is very similar to the @code{break} command.
670198948SobrienIts argument can be a source line, a function name, or an address in
670298948Sobrienthe target program.  @xref{Set Breaks}.  The @code{trace} command
670398948Sobriendefines a tracepoint, which is a point in the target program where the
670498948Sobriendebugger will briefly stop, collect some data, and then allow the
670598948Sobrienprogram to continue.  Setting a tracepoint or changing its commands
670698948Sobriendoesn't take effect until the next @code{tstart} command; thus, you
670798948Sobriencannot change the tracepoint attributes once a trace experiment is
670898948Sobrienrunning.
670998948Sobrien
671098948SobrienHere are some examples of using the @code{trace} command:
671198948Sobrien
671298948Sobrien@smallexample
671398948Sobrien(@value{GDBP}) @b{trace foo.c:121}    // a source file and line number
671498948Sobrien
671598948Sobrien(@value{GDBP}) @b{trace +2}           // 2 lines forward
671698948Sobrien
671798948Sobrien(@value{GDBP}) @b{trace my_function}  // first source line of function
671898948Sobrien
671998948Sobrien(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
672098948Sobrien
672198948Sobrien(@value{GDBP}) @b{trace *0x2117c4}    // an address
672298948Sobrien@end smallexample
672398948Sobrien
672498948Sobrien@noindent
672598948SobrienYou can abbreviate @code{trace} as @code{tr}.
672698948Sobrien
672798948Sobrien@vindex $tpnum
672898948Sobrien@cindex last tracepoint number
672998948Sobrien@cindex recent tracepoint number
673098948Sobrien@cindex tracepoint number
673198948SobrienThe convenience variable @code{$tpnum} records the tracepoint number
673298948Sobrienof the most recently set tracepoint.
673398948Sobrien
673498948Sobrien@kindex delete tracepoint
673598948Sobrien@cindex tracepoint deletion
673698948Sobrien@item delete tracepoint @r{[}@var{num}@r{]}
673798948SobrienPermanently delete one or more tracepoints.  With no argument, the
673898948Sobriendefault is to delete all tracepoints.
673998948Sobrien
674098948SobrienExamples:
674198948Sobrien
674298948Sobrien@smallexample
674398948Sobrien(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
674498948Sobrien
674598948Sobrien(@value{GDBP}) @b{delete trace}       // remove all tracepoints
674698948Sobrien@end smallexample
674798948Sobrien
674898948Sobrien@noindent
674998948SobrienYou can abbreviate this command as @code{del tr}.
675098948Sobrien@end table
675198948Sobrien
675298948Sobrien@node Enable and Disable Tracepoints
675398948Sobrien@subsection Enable and Disable Tracepoints
675498948Sobrien
675598948Sobrien@table @code
675698948Sobrien@kindex disable tracepoint
675798948Sobrien@item disable tracepoint @r{[}@var{num}@r{]}
675898948SobrienDisable tracepoint @var{num}, or all tracepoints if no argument
675998948Sobrien@var{num} is given.  A disabled tracepoint will have no effect during
676098948Sobrienthe next trace experiment, but it is not forgotten.  You can re-enable
676198948Sobriena disabled tracepoint using the @code{enable tracepoint} command.
676298948Sobrien
676398948Sobrien@kindex enable tracepoint
676498948Sobrien@item enable tracepoint @r{[}@var{num}@r{]}
676598948SobrienEnable tracepoint @var{num}, or all tracepoints.  The enabled
676698948Sobrientracepoints will become effective the next time a trace experiment is
676798948Sobrienrun.
676898948Sobrien@end table
676998948Sobrien
677098948Sobrien@node Tracepoint Passcounts
677198948Sobrien@subsection Tracepoint Passcounts
677298948Sobrien
677398948Sobrien@table @code
677498948Sobrien@kindex passcount
677598948Sobrien@cindex tracepoint pass count
677698948Sobrien@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
677798948SobrienSet the @dfn{passcount} of a tracepoint.  The passcount is a way to
677898948Sobrienautomatically stop a trace experiment.  If a tracepoint's passcount is
677998948Sobrien@var{n}, then the trace experiment will be automatically stopped on
678098948Sobrienthe @var{n}'th time that tracepoint is hit.  If the tracepoint number
678198948Sobrien@var{num} is not specified, the @code{passcount} command sets the
678298948Sobrienpasscount of the most recently defined tracepoint.  If no passcount is
678398948Sobriengiven, the trace experiment will run until stopped explicitly by the
678498948Sobrienuser.
678598948Sobrien
678698948SobrienExamples:
678798948Sobrien
678898948Sobrien@smallexample
6789130809Smarcel(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
679098948Sobrien@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
679198948Sobrien
679298948Sobrien(@value{GDBP}) @b{passcount 12}  // Stop on the 12th execution of the
679398948Sobrien@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
679498948Sobrien(@value{GDBP}) @b{trace foo}
679598948Sobrien(@value{GDBP}) @b{pass 3}
679698948Sobrien(@value{GDBP}) @b{trace bar}
679798948Sobrien(@value{GDBP}) @b{pass 2}
679898948Sobrien(@value{GDBP}) @b{trace baz}
679998948Sobrien(@value{GDBP}) @b{pass 1}        // Stop tracing when foo has been
680098948Sobrien@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
680198948Sobrien@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
680298948Sobrien@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
680398948Sobrien@end smallexample
680498948Sobrien@end table
680598948Sobrien
680698948Sobrien@node Tracepoint Actions
680798948Sobrien@subsection Tracepoint Action Lists
680898948Sobrien
680998948Sobrien@table @code
681098948Sobrien@kindex actions
681198948Sobrien@cindex tracepoint actions
681298948Sobrien@item actions @r{[}@var{num}@r{]}
681398948SobrienThis command will prompt for a list of actions to be taken when the
681498948Sobrientracepoint is hit.  If the tracepoint number @var{num} is not
681598948Sobrienspecified, this command sets the actions for the one that was most
681698948Sobrienrecently defined (so that you can define a tracepoint and then say
681798948Sobrien@code{actions} without bothering about its number).  You specify the
681898948Sobrienactions themselves on the following lines, one action at a time, and
681998948Sobrienterminate the actions list with a line containing just @code{end}.  So
682098948Sobrienfar, the only defined actions are @code{collect} and
682198948Sobrien@code{while-stepping}.
682298948Sobrien
682398948Sobrien@cindex remove actions from a tracepoint
682498948SobrienTo remove all actions from a tracepoint, type @samp{actions @var{num}}
682598948Sobrienand follow it immediately with @samp{end}.
682698948Sobrien
682798948Sobrien@smallexample
682898948Sobrien(@value{GDBP}) @b{collect @var{data}} // collect some data
682998948Sobrien
683098948Sobrien(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
683198948Sobrien
683298948Sobrien(@value{GDBP}) @b{end}              // signals the end of actions.
683398948Sobrien@end smallexample
683498948Sobrien
683598948SobrienIn the following example, the action list begins with @code{collect}
683698948Sobriencommands indicating the things to be collected when the tracepoint is
683798948Sobrienhit.  Then, in order to single-step and collect additional data
683898948Sobrienfollowing the tracepoint, a @code{while-stepping} command is used,
683998948Sobrienfollowed by the list of things to be collected while stepping.  The
684098948Sobrien@code{while-stepping} command is terminated by its own separate
684198948Sobrien@code{end} command.  Lastly, the action list is terminated by an
684298948Sobrien@code{end} command.
684398948Sobrien
684498948Sobrien@smallexample
684598948Sobrien(@value{GDBP}) @b{trace foo}
684698948Sobrien(@value{GDBP}) @b{actions}
684798948SobrienEnter actions for tracepoint 1, one per line:
684898948Sobrien> collect bar,baz
684998948Sobrien> collect $regs
685098948Sobrien> while-stepping 12
685198948Sobrien  > collect $fp, $sp
685298948Sobrien  > end
685398948Sobrienend
685498948Sobrien@end smallexample
685598948Sobrien
685698948Sobrien@kindex collect @r{(tracepoints)}
685798948Sobrien@item collect @var{expr1}, @var{expr2}, @dots{}
685898948SobrienCollect values of the given expressions when the tracepoint is hit.
685998948SobrienThis command accepts a comma-separated list of any valid expressions.
686098948SobrienIn addition to global, static, or local variables, the following
686198948Sobrienspecial arguments are supported:
686298948Sobrien
686398948Sobrien@table @code
686498948Sobrien@item $regs
686598948Sobriencollect all registers
686698948Sobrien
686798948Sobrien@item $args
686898948Sobriencollect all function arguments
686998948Sobrien
687098948Sobrien@item $locals
687198948Sobriencollect all local variables.
687298948Sobrien@end table
687398948Sobrien
687498948SobrienYou can give several consecutive @code{collect} commands, each one
687598948Sobrienwith a single argument, or one @code{collect} command with several
687698948Sobrienarguments separated by commas: the effect is the same.
687798948Sobrien
687898948SobrienThe command @code{info scope} (@pxref{Symbols, info scope}) is
687998948Sobrienparticularly useful for figuring out what data to collect.
688098948Sobrien
688198948Sobrien@kindex while-stepping @r{(tracepoints)}
688298948Sobrien@item while-stepping @var{n}
688398948SobrienPerform @var{n} single-step traces after the tracepoint, collecting
688498948Sobriennew data at each step.  The @code{while-stepping} command is
688598948Sobrienfollowed by the list of what to collect while stepping (followed by
688698948Sobrienits own @code{end} command):
688798948Sobrien
688898948Sobrien@smallexample
688998948Sobrien> while-stepping 12
689098948Sobrien  > collect $regs, myglobal
689198948Sobrien  > end
689298948Sobrien>
689398948Sobrien@end smallexample
689498948Sobrien
689598948Sobrien@noindent
689698948SobrienYou may abbreviate @code{while-stepping} as @code{ws} or
689798948Sobrien@code{stepping}.
689898948Sobrien@end table
689998948Sobrien
690098948Sobrien@node Listing Tracepoints
690198948Sobrien@subsection Listing Tracepoints
690298948Sobrien
690398948Sobrien@table @code
690498948Sobrien@kindex info tracepoints
690598948Sobrien@cindex information about tracepoints
690698948Sobrien@item info tracepoints @r{[}@var{num}@r{]}
690798948SobrienDisplay information about the tracepoint @var{num}.  If you don't specify
690898948Sobriena tracepoint number, displays information about all the tracepoints
690998948Sobriendefined so far.  For each tracepoint, the following information is
691098948Sobrienshown:
691198948Sobrien
691298948Sobrien@itemize @bullet
691398948Sobrien@item
691498948Sobrienits number
691598948Sobrien@item
691698948Sobrienwhether it is enabled or disabled
691798948Sobrien@item
691898948Sobrienits address
691998948Sobrien@item
692098948Sobrienits passcount as given by the @code{passcount @var{n}} command
692198948Sobrien@item
692298948Sobrienits step count as given by the @code{while-stepping @var{n}} command
692398948Sobrien@item
692498948Sobrienwhere in the source files is the tracepoint set
692598948Sobrien@item
692698948Sobrienits action list as given by the @code{actions} command
692798948Sobrien@end itemize
692898948Sobrien
692998948Sobrien@smallexample
693098948Sobrien(@value{GDBP}) @b{info trace}
693198948SobrienNum Enb Address    PassC StepC What
693298948Sobrien1   y   0x002117c4 0     0     <gdb_asm>
693398948Sobrien2   y   0x0020dc64 0     0     in g_test at g_test.c:1375
693498948Sobrien3   y   0x0020b1f4 0     0     in get_data at ../foo.c:41
693598948Sobrien(@value{GDBP})
693698948Sobrien@end smallexample
693798948Sobrien
693898948Sobrien@noindent
693998948SobrienThis command can be abbreviated @code{info tp}.
694098948Sobrien@end table
694198948Sobrien
694298948Sobrien@node Starting and Stopping Trace Experiment
694398948Sobrien@subsection Starting and Stopping Trace Experiment
694498948Sobrien
694598948Sobrien@table @code
694698948Sobrien@kindex tstart
694798948Sobrien@cindex start a new trace experiment
694898948Sobrien@cindex collected data discarded
694998948Sobrien@item tstart
695098948SobrienThis command takes no arguments.  It starts the trace experiment, and
695198948Sobrienbegins collecting data.  This has the side effect of discarding all
695298948Sobrienthe data collected in the trace buffer during the previous trace
695398948Sobrienexperiment.
695498948Sobrien
695598948Sobrien@kindex tstop
695698948Sobrien@cindex stop a running trace experiment
695798948Sobrien@item tstop
695898948SobrienThis command takes no arguments.  It ends the trace experiment, and
695998948Sobrienstops collecting data.
696098948Sobrien
696198948Sobrien@strong{Note:} a trace experiment and data collection may stop
696298948Sobrienautomatically if any tracepoint's passcount is reached
696398948Sobrien(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
696498948Sobrien
696598948Sobrien@kindex tstatus
696698948Sobrien@cindex status of trace data collection
696798948Sobrien@cindex trace experiment, status of
696898948Sobrien@item tstatus
696998948SobrienThis command displays the status of the current trace data
697098948Sobriencollection.
697198948Sobrien@end table
697298948Sobrien
697398948SobrienHere is an example of the commands we described so far:
697498948Sobrien
697598948Sobrien@smallexample
697698948Sobrien(@value{GDBP}) @b{trace gdb_c_test}
697798948Sobrien(@value{GDBP}) @b{actions}
697898948SobrienEnter actions for tracepoint #1, one per line.
697998948Sobrien> collect $regs,$locals,$args
698098948Sobrien> while-stepping 11
698198948Sobrien  > collect $regs
698298948Sobrien  > end
698398948Sobrien> end
698498948Sobrien(@value{GDBP}) @b{tstart}
698598948Sobrien	[time passes @dots{}]
698698948Sobrien(@value{GDBP}) @b{tstop}
698798948Sobrien@end smallexample
698898948Sobrien
698998948Sobrien
699098948Sobrien@node Analyze Collected Data
699198948Sobrien@section Using the collected data
699298948Sobrien
699398948SobrienAfter the tracepoint experiment ends, you use @value{GDBN} commands
699498948Sobrienfor examining the trace data.  The basic idea is that each tracepoint
699598948Sobriencollects a trace @dfn{snapshot} every time it is hit and another
699698948Sobriensnapshot every time it single-steps.  All these snapshots are
699798948Sobrienconsecutively numbered from zero and go into a buffer, and you can
699898948Sobrienexamine them later.  The way you examine them is to @dfn{focus} on a
699998948Sobrienspecific trace snapshot.  When the remote stub is focused on a trace
700098948Sobriensnapshot, it will respond to all @value{GDBN} requests for memory and
700198948Sobrienregisters by reading from the buffer which belongs to that snapshot,
700298948Sobrienrather than from @emph{real} memory or registers of the program being
700398948Sobriendebugged.  This means that @strong{all} @value{GDBN} commands
700498948Sobrien(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
700598948Sobrienbehave as if we were currently debugging the program state as it was
700698948Sobrienwhen the tracepoint occurred.  Any requests for data that are not in
700798948Sobrienthe buffer will fail.
700898948Sobrien
700998948Sobrien@menu
701098948Sobrien* tfind::                       How to select a trace snapshot
701198948Sobrien* tdump::                       How to display all data for a snapshot
701298948Sobrien* save-tracepoints::            How to save tracepoints for a future run
701398948Sobrien@end menu
701498948Sobrien
701598948Sobrien@node tfind
701698948Sobrien@subsection @code{tfind @var{n}}
701798948Sobrien
701898948Sobrien@kindex tfind
701998948Sobrien@cindex select trace snapshot
702098948Sobrien@cindex find trace snapshot
702198948SobrienThe basic command for selecting a trace snapshot from the buffer is
702298948Sobrien@code{tfind @var{n}}, which finds trace snapshot number @var{n},
702398948Sobriencounting from zero.  If no argument @var{n} is given, the next
702498948Sobriensnapshot is selected.
702598948Sobrien
702698948SobrienHere are the various forms of using the @code{tfind} command.
702798948Sobrien
702898948Sobrien@table @code
702998948Sobrien@item tfind start
703098948SobrienFind the first snapshot in the buffer.  This is a synonym for
703198948Sobrien@code{tfind 0} (since 0 is the number of the first snapshot).
703298948Sobrien
703398948Sobrien@item tfind none
703498948SobrienStop debugging trace snapshots, resume @emph{live} debugging.
703598948Sobrien
703698948Sobrien@item tfind end
703798948SobrienSame as @samp{tfind none}.
703898948Sobrien
703998948Sobrien@item tfind
704098948SobrienNo argument means find the next trace snapshot.
704198948Sobrien
704298948Sobrien@item tfind -
704398948SobrienFind the previous trace snapshot before the current one.  This permits
704498948Sobrienretracing earlier steps.
704598948Sobrien
704698948Sobrien@item tfind tracepoint @var{num}
704798948SobrienFind the next snapshot associated with tracepoint @var{num}.  Search
704898948Sobrienproceeds forward from the last examined trace snapshot.  If no
704998948Sobrienargument @var{num} is given, it means find the next snapshot collected
705098948Sobrienfor the same tracepoint as the current snapshot.
705198948Sobrien
705298948Sobrien@item tfind pc @var{addr}
705398948SobrienFind the next snapshot associated with the value @var{addr} of the
705498948Sobrienprogram counter.  Search proceeds forward from the last examined trace
705598948Sobriensnapshot.  If no argument @var{addr} is given, it means find the next
705698948Sobriensnapshot with the same value of PC as the current snapshot.
705798948Sobrien
705898948Sobrien@item tfind outside @var{addr1}, @var{addr2}
705998948SobrienFind the next snapshot whose PC is outside the given range of
706098948Sobrienaddresses.
706198948Sobrien
706298948Sobrien@item tfind range @var{addr1}, @var{addr2}
706398948SobrienFind the next snapshot whose PC is between @var{addr1} and
706498948Sobrien@var{addr2}.  @c FIXME: Is the range inclusive or exclusive?
706598948Sobrien
706698948Sobrien@item tfind line @r{[}@var{file}:@r{]}@var{n}
706798948SobrienFind the next snapshot associated with the source line @var{n}.  If
706898948Sobrienthe optional argument @var{file} is given, refer to line @var{n} in
706998948Sobrienthat source file.  Search proceeds forward from the last examined
707098948Sobrientrace snapshot.  If no argument @var{n} is given, it means find the
707198948Sobriennext line other than the one currently being examined; thus saying
707298948Sobrien@code{tfind line} repeatedly can appear to have the same effect as
707398948Sobrienstepping from line to line in a @emph{live} debugging session.
707498948Sobrien@end table
707598948Sobrien
707698948SobrienThe default arguments for the @code{tfind} commands are specifically
707798948Sobriendesigned to make it easy to scan through the trace buffer.  For
707898948Sobrieninstance, @code{tfind} with no argument selects the next trace
707998948Sobriensnapshot, and @code{tfind -} with no argument selects the previous
708098948Sobrientrace snapshot.  So, by giving one @code{tfind} command, and then
708198948Sobriensimply hitting @key{RET} repeatedly you can examine all the trace
708298948Sobriensnapshots in order.  Or, by saying @code{tfind -} and then hitting
708398948Sobrien@key{RET} repeatedly you can examine the snapshots in reverse order.
708498948SobrienThe @code{tfind line} command with no argument selects the snapshot
708598948Sobrienfor the next source line executed.  The @code{tfind pc} command with
708698948Sobrienno argument selects the next snapshot with the same program counter
708798948Sobrien(PC) as the current frame.  The @code{tfind tracepoint} command with
708898948Sobrienno argument selects the next trace snapshot collected by the same
708998948Sobrientracepoint as the current one.
709098948Sobrien
709198948SobrienIn addition to letting you scan through the trace buffer manually,
709298948Sobrienthese commands make it easy to construct @value{GDBN} scripts that
709398948Sobrienscan through the trace buffer and print out whatever collected data
709498948Sobrienyou are interested in.  Thus, if we want to examine the PC, FP, and SP
709598948Sobrienregisters from each trace frame in the buffer, we can say this:
709698948Sobrien
709798948Sobrien@smallexample
709898948Sobrien(@value{GDBP}) @b{tfind start}
709998948Sobrien(@value{GDBP}) @b{while ($trace_frame != -1)}
710098948Sobrien> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
710198948Sobrien          $trace_frame, $pc, $sp, $fp
710298948Sobrien> tfind
710398948Sobrien> end
710498948Sobrien
710598948SobrienFrame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
710698948SobrienFrame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
710798948SobrienFrame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
710898948SobrienFrame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
710998948SobrienFrame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
711098948SobrienFrame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
711198948SobrienFrame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
711298948SobrienFrame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
711398948SobrienFrame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
711498948SobrienFrame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
711598948SobrienFrame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
711698948Sobrien@end smallexample
711798948Sobrien
711898948SobrienOr, if we want to examine the variable @code{X} at each source line in
711998948Sobrienthe buffer:
712098948Sobrien
712198948Sobrien@smallexample
712298948Sobrien(@value{GDBP}) @b{tfind start}
712398948Sobrien(@value{GDBP}) @b{while ($trace_frame != -1)}
712498948Sobrien> printf "Frame %d, X == %d\n", $trace_frame, X
712598948Sobrien> tfind line
712698948Sobrien> end
712798948Sobrien
712898948SobrienFrame 0, X = 1
712998948SobrienFrame 7, X = 2
713098948SobrienFrame 13, X = 255
713198948Sobrien@end smallexample
713298948Sobrien
713398948Sobrien@node tdump
713498948Sobrien@subsection @code{tdump}
713598948Sobrien@kindex tdump
713698948Sobrien@cindex dump all data collected at tracepoint
713798948Sobrien@cindex tracepoint data, display
713898948Sobrien
713998948SobrienThis command takes no arguments.  It prints all the data collected at
714098948Sobrienthe current trace snapshot.
714198948Sobrien
714298948Sobrien@smallexample
714398948Sobrien(@value{GDBP}) @b{trace 444}
714498948Sobrien(@value{GDBP}) @b{actions}
714598948SobrienEnter actions for tracepoint #2, one per line:
714698948Sobrien> collect $regs, $locals, $args, gdb_long_test
714798948Sobrien> end
714898948Sobrien
714998948Sobrien(@value{GDBP}) @b{tstart}
715098948Sobrien
715198948Sobrien(@value{GDBP}) @b{tfind line 444}
715298948Sobrien#0  gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
715398948Sobrienat gdb_test.c:444
715498948Sobrien444        printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
715598948Sobrien
715698948Sobrien(@value{GDBP}) @b{tdump}
715798948SobrienData collected at tracepoint 2, trace frame 1:
715898948Sobriend0             0xc4aa0085       -995491707
715998948Sobriend1             0x18     24
716098948Sobriend2             0x80     128
716198948Sobriend3             0x33     51
716298948Sobriend4             0x71aea3d        119204413
716398948Sobriend5             0x22     34
716498948Sobriend6             0xe0     224
716598948Sobriend7             0x380035 3670069
716698948Sobriena0             0x19e24a 1696330
716798948Sobriena1             0x3000668        50333288
716898948Sobriena2             0x100    256
716998948Sobriena3             0x322000 3284992
717098948Sobriena4             0x3000698        50333336
717198948Sobriena5             0x1ad3cc 1758156
717298948Sobrienfp             0x30bf3c 0x30bf3c
717398948Sobriensp             0x30bf34 0x30bf34
717498948Sobrienps             0x0      0
717598948Sobrienpc             0x20b2c8 0x20b2c8
717698948Sobrienfpcontrol      0x0      0
717798948Sobrienfpstatus       0x0      0
717898948Sobrienfpiaddr        0x0      0
717998948Sobrienp = 0x20e5b4 "gdb-test"
718098948Sobrienp1 = (void *) 0x11
718198948Sobrienp2 = (void *) 0x22
718298948Sobrienp3 = (void *) 0x33
718398948Sobrienp4 = (void *) 0x44
718498948Sobrienp5 = (void *) 0x55
718598948Sobrienp6 = (void *) 0x66
718698948Sobriengdb_long_test = 17 '\021'
718798948Sobrien
718898948Sobrien(@value{GDBP})
718998948Sobrien@end smallexample
719098948Sobrien
719198948Sobrien@node save-tracepoints
719298948Sobrien@subsection @code{save-tracepoints @var{filename}}
719398948Sobrien@kindex save-tracepoints
719498948Sobrien@cindex save tracepoints for future sessions
719598948Sobrien
719698948SobrienThis command saves all current tracepoint definitions together with
719798948Sobrientheir actions and passcounts, into a file @file{@var{filename}}
719898948Sobriensuitable for use in a later debugging session.  To read the saved
719998948Sobrientracepoint definitions, use the @code{source} command (@pxref{Command
720098948SobrienFiles}).
720198948Sobrien
720298948Sobrien@node Tracepoint Variables
720398948Sobrien@section Convenience Variables for Tracepoints
720498948Sobrien@cindex tracepoint variables
720598948Sobrien@cindex convenience variables for tracepoints
720698948Sobrien
720798948Sobrien@table @code
720898948Sobrien@vindex $trace_frame
720998948Sobrien@item (int) $trace_frame
721098948SobrienThe current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
721198948Sobriensnapshot is selected.
721298948Sobrien
721398948Sobrien@vindex $tracepoint
721498948Sobrien@item (int) $tracepoint
721598948SobrienThe tracepoint for the current trace snapshot.
721698948Sobrien
721798948Sobrien@vindex $trace_line
721898948Sobrien@item (int) $trace_line
721998948SobrienThe line number for the current trace snapshot.
722098948Sobrien
722198948Sobrien@vindex $trace_file
722298948Sobrien@item (char []) $trace_file
722398948SobrienThe source file for the current trace snapshot.
722498948Sobrien
722598948Sobrien@vindex $trace_func
722698948Sobrien@item (char []) $trace_func
722798948SobrienThe name of the function containing @code{$tracepoint}.
722898948Sobrien@end table
722998948Sobrien
723098948SobrienNote: @code{$trace_file} is not suitable for use in @code{printf},
723198948Sobrienuse @code{output} instead.
723298948Sobrien
723398948SobrienHere's a simple example of using these convenience variables for
723498948Sobrienstepping through all the trace snapshots and printing some of their
723598948Sobriendata.
723698948Sobrien
723798948Sobrien@smallexample
723898948Sobrien(@value{GDBP}) @b{tfind start}
723998948Sobrien
724098948Sobrien(@value{GDBP}) @b{while $trace_frame != -1}
724198948Sobrien> output $trace_file
724298948Sobrien> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
724398948Sobrien> tfind
724498948Sobrien> end
724598948Sobrien@end smallexample
724698948Sobrien
724798948Sobrien@node Overlays
724898948Sobrien@chapter Debugging Programs That Use Overlays
724998948Sobrien@cindex overlays
725098948Sobrien
725198948SobrienIf your program is too large to fit completely in your target system's
725298948Sobrienmemory, you can sometimes use @dfn{overlays} to work around this
725398948Sobrienproblem.  @value{GDBN} provides some support for debugging programs that
725498948Sobrienuse overlays.
725598948Sobrien
725698948Sobrien@menu
725798948Sobrien* How Overlays Work::              A general explanation of overlays.
725898948Sobrien* Overlay Commands::               Managing overlays in @value{GDBN}.
725998948Sobrien* Automatic Overlay Debugging::    @value{GDBN} can find out which overlays are
726098948Sobrien                                   mapped by asking the inferior.
726198948Sobrien* Overlay Sample Program::         A sample program using overlays.
726298948Sobrien@end menu
726398948Sobrien
726498948Sobrien@node How Overlays Work
726598948Sobrien@section How Overlays Work
726698948Sobrien@cindex mapped overlays
726798948Sobrien@cindex unmapped overlays
726898948Sobrien@cindex load address, overlay's
726998948Sobrien@cindex mapped address
727098948Sobrien@cindex overlay area
727198948Sobrien
727298948SobrienSuppose you have a computer whose instruction address space is only 64
727398948Sobrienkilobytes long, but which has much more memory which can be accessed by
727498948Sobrienother means: special instructions, segment registers, or memory
727598948Sobrienmanagement hardware, for example.  Suppose further that you want to
727698948Sobrienadapt a program which is larger than 64 kilobytes to run on this system.
727798948Sobrien
727898948SobrienOne solution is to identify modules of your program which are relatively
727998948Sobrienindependent, and need not call each other directly; call these modules
728098948Sobrien@dfn{overlays}.  Separate the overlays from the main program, and place
728198948Sobrientheir machine code in the larger memory.  Place your main program in
728298948Sobrieninstruction memory, but leave at least enough space there to hold the
728398948Sobrienlargest overlay as well.
728498948Sobrien
728598948SobrienNow, to call a function located in an overlay, you must first copy that
728698948Sobrienoverlay's machine code from the large memory into the space set aside
728798948Sobrienfor it in the instruction memory, and then jump to its entry point
728898948Sobrienthere.
728998948Sobrien
729098948Sobrien@c NB:  In the below the mapped area's size is greater or equal to the
729198948Sobrien@c size of all overlays.  This is intentional to remind the developer
729298948Sobrien@c that overlays don't necessarily need to be the same size.
729398948Sobrien
7294130809Smarcel@smallexample
729598948Sobrien@group
729698948Sobrien    Data             Instruction            Larger
729798948SobrienAddress Space       Address Space        Address Space
729898948Sobrien+-----------+       +-----------+        +-----------+
729998948Sobrien|           |       |           |        |           |
730098948Sobrien+-----------+       +-----------+        +-----------+<-- overlay 1
730198948Sobrien| program   |       |   main    |   .----| overlay 1 | load address
730298948Sobrien| variables |       |  program  |   |    +-----------+
730398948Sobrien| and heap  |       |           |   |    |           |
730498948Sobrien+-----------+       |           |   |    +-----------+<-- overlay 2
730598948Sobrien|           |       +-----------+   |    |           | load address
730698948Sobrien+-----------+       |           |   |  .-| overlay 2 |
730798948Sobrien                    |           |   |  | |           |
730898948Sobrien         mapped --->+-----------+   |  | +-----------+
730998948Sobrien         address    |           |   |  | |           |
731098948Sobrien                    |  overlay  | <-'  | |           |
731198948Sobrien                    |   area    |  <---' +-----------+<-- overlay 3
731298948Sobrien                    |           | <---.  |           | load address
731398948Sobrien                    +-----------+     `--| overlay 3 |
731498948Sobrien                    |           |        |           |
731598948Sobrien                    +-----------+        |           |
731698948Sobrien                                         +-----------+
731798948Sobrien                                         |           |
731898948Sobrien                                         +-----------+
731998948Sobrien
732098948Sobrien                    @anchor{A code overlay}A code overlay
732198948Sobrien@end group
7322130809Smarcel@end smallexample
732398948Sobrien
732498948SobrienThe diagram (@pxref{A code overlay}) shows a system with separate data
732598948Sobrienand instruction address spaces.  To map an overlay, the program copies
732698948Sobrienits code from the larger address space to the instruction address space.
732798948SobrienSince the overlays shown here all use the same mapped address, only one
732898948Sobrienmay be mapped at a time.  For a system with a single address space for
732998948Sobriendata and instructions, the diagram would be similar, except that the
733098948Sobrienprogram variables and heap would share an address space with the main
733198948Sobrienprogram and the overlay area.
733298948Sobrien
733398948SobrienAn overlay loaded into instruction memory and ready for use is called a
733498948Sobrien@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
733598948Sobrieninstruction memory.  An overlay not present (or only partially present)
733698948Sobrienin instruction memory is called @dfn{unmapped}; its @dfn{load address}
733798948Sobrienis its address in the larger memory.  The mapped address is also called
733898948Sobrienthe @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
733998948Sobriencalled the @dfn{load memory address}, or @dfn{LMA}.
734098948Sobrien
734198948SobrienUnfortunately, overlays are not a completely transparent way to adapt a
734298948Sobrienprogram to limited instruction memory.  They introduce a new set of
734398948Sobrienglobal constraints you must keep in mind as you design your program:
734498948Sobrien
734598948Sobrien@itemize @bullet
734698948Sobrien
734798948Sobrien@item
734898948SobrienBefore calling or returning to a function in an overlay, your program
734998948Sobrienmust make sure that overlay is actually mapped.  Otherwise, the call or
735098948Sobrienreturn will transfer control to the right address, but in the wrong
735198948Sobrienoverlay, and your program will probably crash.
735298948Sobrien
735398948Sobrien@item
735498948SobrienIf the process of mapping an overlay is expensive on your system, you
735598948Sobrienwill need to choose your overlays carefully to minimize their effect on
735698948Sobrienyour program's performance.
735798948Sobrien
735898948Sobrien@item
735998948SobrienThe executable file you load onto your system must contain each
736098948Sobrienoverlay's instructions, appearing at the overlay's load address, not its
736198948Sobrienmapped address.  However, each overlay's instructions must be relocated
736298948Sobrienand its symbols defined as if the overlay were at its mapped address.
736398948SobrienYou can use GNU linker scripts to specify different load and relocation
736498948Sobrienaddresses for pieces of your program; see @ref{Overlay Description,,,
736598948Sobrienld.info, Using ld: the GNU linker}.
736698948Sobrien
736798948Sobrien@item
736898948SobrienThe procedure for loading executable files onto your system must be able
736998948Sobriento load their contents into the larger address space as well as the
737098948Sobrieninstruction and data spaces.
737198948Sobrien
737298948Sobrien@end itemize
737398948Sobrien
737498948SobrienThe overlay system described above is rather simple, and could be
737598948Sobrienimproved in many ways:
737698948Sobrien
737798948Sobrien@itemize @bullet
737898948Sobrien
737998948Sobrien@item
738098948SobrienIf your system has suitable bank switch registers or memory management
738198948Sobrienhardware, you could use those facilities to make an overlay's load area
738298948Sobriencontents simply appear at their mapped address in instruction space.
738398948SobrienThis would probably be faster than copying the overlay to its mapped
738498948Sobrienarea in the usual way.
738598948Sobrien
738698948Sobrien@item
738798948SobrienIf your overlays are small enough, you could set aside more than one
738898948Sobrienoverlay area, and have more than one overlay mapped at a time.
738998948Sobrien
739098948Sobrien@item
739198948SobrienYou can use overlays to manage data, as well as instructions.  In
739298948Sobriengeneral, data overlays are even less transparent to your design than
739398948Sobriencode overlays: whereas code overlays only require care when you call or
739498948Sobrienreturn to functions, data overlays require care every time you access
739598948Sobrienthe data.  Also, if you change the contents of a data overlay, you
739698948Sobrienmust copy its contents back out to its load address before you can copy a
739798948Sobriendifferent data overlay into the same mapped area.
739898948Sobrien
739998948Sobrien@end itemize
740098948Sobrien
740198948Sobrien
740298948Sobrien@node Overlay Commands
740398948Sobrien@section Overlay Commands
740498948Sobrien
740598948SobrienTo use @value{GDBN}'s overlay support, each overlay in your program must
740698948Sobriencorrespond to a separate section of the executable file.  The section's
740798948Sobrienvirtual memory address and load memory address must be the overlay's
740898948Sobrienmapped and load addresses.  Identifying overlays with sections allows
740998948Sobrien@value{GDBN} to determine the appropriate address of a function or
741098948Sobrienvariable, depending on whether the overlay is mapped or not.
741198948Sobrien
741298948Sobrien@value{GDBN}'s overlay commands all start with the word @code{overlay};
741398948Sobrienyou can abbreviate this as @code{ov} or @code{ovly}.  The commands are:
741498948Sobrien
741598948Sobrien@table @code
741698948Sobrien@item overlay off
741798948Sobrien@kindex overlay off
741898948SobrienDisable @value{GDBN}'s overlay support.  When overlay support is
741998948Sobriendisabled, @value{GDBN} assumes that all functions and variables are
742098948Sobrienalways present at their mapped addresses.  By default, @value{GDBN}'s
742198948Sobrienoverlay support is disabled.
742298948Sobrien
742398948Sobrien@item overlay manual
742498948Sobrien@kindex overlay manual
742598948Sobrien@cindex manual overlay debugging
742698948SobrienEnable @dfn{manual} overlay debugging.  In this mode, @value{GDBN}
742798948Sobrienrelies on you to tell it which overlays are mapped, and which are not,
742898948Sobrienusing the @code{overlay map-overlay} and @code{overlay unmap-overlay}
742998948Sobriencommands described below.
743098948Sobrien
743198948Sobrien@item overlay map-overlay @var{overlay}
743298948Sobrien@itemx overlay map @var{overlay}
743398948Sobrien@kindex overlay map-overlay
743498948Sobrien@cindex map an overlay
743598948SobrienTell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
743698948Sobrienbe the name of the object file section containing the overlay.  When an
743798948Sobrienoverlay is mapped, @value{GDBN} assumes it can find the overlay's
743898948Sobrienfunctions and variables at their mapped addresses.  @value{GDBN} assumes
743998948Sobrienthat any other overlays whose mapped ranges overlap that of
744098948Sobrien@var{overlay} are now unmapped.
744198948Sobrien
744298948Sobrien@item overlay unmap-overlay @var{overlay}
744398948Sobrien@itemx overlay unmap @var{overlay}
744498948Sobrien@kindex overlay unmap-overlay
744598948Sobrien@cindex unmap an overlay
744698948SobrienTell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
744798948Sobrienmust be the name of the object file section containing the overlay.
744898948SobrienWhen an overlay is unmapped, @value{GDBN} assumes it can find the
744998948Sobrienoverlay's functions and variables at their load addresses.
745098948Sobrien
745198948Sobrien@item overlay auto
745298948Sobrien@kindex overlay auto
745398948SobrienEnable @dfn{automatic} overlay debugging.  In this mode, @value{GDBN}
745498948Sobrienconsults a data structure the overlay manager maintains in the inferior
745598948Sobriento see which overlays are mapped.  For details, see @ref{Automatic
745698948SobrienOverlay Debugging}.
745798948Sobrien
745898948Sobrien@item overlay load-target
745998948Sobrien@itemx overlay load
746098948Sobrien@kindex overlay load-target
746198948Sobrien@cindex reloading the overlay table
746298948SobrienRe-read the overlay table from the inferior.  Normally, @value{GDBN}
746398948Sobrienre-reads the table @value{GDBN} automatically each time the inferior
746498948Sobrienstops, so this command should only be necessary if you have changed the
746598948Sobrienoverlay mapping yourself using @value{GDBN}.  This command is only
746698948Sobrienuseful when using automatic overlay debugging.
746798948Sobrien
746898948Sobrien@item overlay list-overlays
746998948Sobrien@itemx overlay list
747098948Sobrien@cindex listing mapped overlays
747198948SobrienDisplay a list of the overlays currently mapped, along with their mapped
747298948Sobrienaddresses, load addresses, and sizes.
747398948Sobrien
747498948Sobrien@end table
747598948Sobrien
747698948SobrienNormally, when @value{GDBN} prints a code address, it includes the name
747798948Sobrienof the function the address falls in:
747898948Sobrien
7479130809Smarcel@smallexample
748098948Sobrien(gdb) print main
748198948Sobrien$3 = @{int ()@} 0x11a0 <main>
7482130809Smarcel@end smallexample
748398948Sobrien@noindent
748498948SobrienWhen overlay debugging is enabled, @value{GDBN} recognizes code in
748598948Sobrienunmapped overlays, and prints the names of unmapped functions with
748698948Sobrienasterisks around them.  For example, if @code{foo} is a function in an
748798948Sobrienunmapped overlay, @value{GDBN} prints it this way:
748898948Sobrien
7489130809Smarcel@smallexample
749098948Sobrien(gdb) overlay list
749198948SobrienNo sections are mapped.
749298948Sobrien(gdb) print foo
749398948Sobrien$5 = @{int (int)@} 0x100000 <*foo*>
7494130809Smarcel@end smallexample
749598948Sobrien@noindent
749698948SobrienWhen @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
749798948Sobrienname normally:
749898948Sobrien
7499130809Smarcel@smallexample
750098948Sobrien(gdb) overlay list
7501130809SmarcelSection .ov.foo.text, loaded at 0x100000 - 0x100034,
750298948Sobrien        mapped at 0x1016 - 0x104a
750398948Sobrien(gdb) print foo
750498948Sobrien$6 = @{int (int)@} 0x1016 <foo>
7505130809Smarcel@end smallexample
750698948Sobrien
750798948SobrienWhen overlay debugging is enabled, @value{GDBN} can find the correct
750898948Sobrienaddress for functions and variables in an overlay, whether or not the
750998948Sobrienoverlay is mapped.  This allows most @value{GDBN} commands, like
751098948Sobrien@code{break} and @code{disassemble}, to work normally, even on unmapped
751198948Sobriencode.  However, @value{GDBN}'s breakpoint support has some limitations:
751298948Sobrien
751398948Sobrien@itemize @bullet
751498948Sobrien@item
751598948Sobrien@cindex breakpoints in overlays
751698948Sobrien@cindex overlays, setting breakpoints in
751798948SobrienYou can set breakpoints in functions in unmapped overlays, as long as
751898948Sobrien@value{GDBN} can write to the overlay at its load address.
751998948Sobrien@item
752098948Sobrien@value{GDBN} can not set hardware or simulator-based breakpoints in
752198948Sobrienunmapped overlays.  However, if you set a breakpoint at the end of your
752298948Sobrienoverlay manager (and tell @value{GDBN} which overlays are now mapped, if
752398948Sobrienyou are using manual overlay management), @value{GDBN} will re-set its
752498948Sobrienbreakpoints properly.
752598948Sobrien@end itemize
752698948Sobrien
752798948Sobrien
752898948Sobrien@node Automatic Overlay Debugging
752998948Sobrien@section Automatic Overlay Debugging
753098948Sobrien@cindex automatic overlay debugging
753198948Sobrien
753298948Sobrien@value{GDBN} can automatically track which overlays are mapped and which
753398948Sobrienare not, given some simple co-operation from the overlay manager in the
753498948Sobrieninferior.  If you enable automatic overlay debugging with the
753598948Sobrien@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
753698948Sobrienlooks in the inferior's memory for certain variables describing the
753798948Sobriencurrent state of the overlays.
753898948Sobrien
753998948SobrienHere are the variables your overlay manager must define to support
754098948Sobrien@value{GDBN}'s automatic overlay debugging:
754198948Sobrien
754298948Sobrien@table @asis
754398948Sobrien
754498948Sobrien@item @code{_ovly_table}:
754598948SobrienThis variable must be an array of the following structures:
754698948Sobrien
7547130809Smarcel@smallexample
754898948Sobrienstruct
754998948Sobrien@{
755098948Sobrien  /* The overlay's mapped address.  */
755198948Sobrien  unsigned long vma;
755298948Sobrien
755398948Sobrien  /* The size of the overlay, in bytes.  */
755498948Sobrien  unsigned long size;
755598948Sobrien
755698948Sobrien  /* The overlay's load address.  */
755798948Sobrien  unsigned long lma;
755898948Sobrien
755998948Sobrien  /* Non-zero if the overlay is currently mapped;
756098948Sobrien     zero otherwise.  */
756198948Sobrien  unsigned long mapped;
756298948Sobrien@}
7563130809Smarcel@end smallexample
756498948Sobrien
756598948Sobrien@item @code{_novlys}:
756698948SobrienThis variable must be a four-byte signed integer, holding the total
756798948Sobriennumber of elements in @code{_ovly_table}.
756898948Sobrien
756998948Sobrien@end table
757098948Sobrien
757198948SobrienTo decide whether a particular overlay is mapped or not, @value{GDBN}
757298948Sobrienlooks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
757398948Sobrien@code{lma} members equal the VMA and LMA of the overlay's section in the
757498948Sobrienexecutable file.  When @value{GDBN} finds a matching entry, it consults
757598948Sobrienthe entry's @code{mapped} member to determine whether the overlay is
757698948Sobriencurrently mapped.
757798948Sobrien
757898948SobrienIn addition, your overlay manager may define a function called
757998948Sobrien@code{_ovly_debug_event}.  If this function is defined, @value{GDBN}
758098948Sobrienwill silently set a breakpoint there.  If the overlay manager then
758198948Sobriencalls this function whenever it has changed the overlay table, this
758298948Sobrienwill enable @value{GDBN} to accurately keep track of which overlays
758398948Sobrienare in program memory, and update any breakpoints that may be set
7584130809Smarcelin overlays.  This will allow breakpoints to work even if the
758598948Sobrienoverlays are kept in ROM or other non-writable memory while they
758698948Sobrienare not being executed.
758798948Sobrien
758898948Sobrien@node Overlay Sample Program
758998948Sobrien@section Overlay Sample Program
759098948Sobrien@cindex overlay example program
759198948Sobrien
759298948SobrienWhen linking a program which uses overlays, you must place the overlays
759398948Sobrienat their load addresses, while relocating them to run at their mapped
759498948Sobrienaddresses.  To do this, you must write a linker script (@pxref{Overlay
759598948SobrienDescription,,, ld.info, Using ld: the GNU linker}).  Unfortunately,
759698948Sobriensince linker scripts are specific to a particular host system, target
759798948Sobrienarchitecture, and target memory layout, this manual cannot provide
759898948Sobrienportable sample code demonstrating @value{GDBN}'s overlay support.
759998948Sobrien
760098948SobrienHowever, the @value{GDBN} source distribution does contain an overlaid
760198948Sobrienprogram, with linker scripts for a few systems, as part of its test
760298948Sobriensuite.  The program consists of the following files from
760398948Sobrien@file{gdb/testsuite/gdb.base}:
760498948Sobrien
760598948Sobrien@table @file
760698948Sobrien@item overlays.c
760798948SobrienThe main program file.
760898948Sobrien@item ovlymgr.c
760998948SobrienA simple overlay manager, used by @file{overlays.c}.
761098948Sobrien@item foo.c
761198948Sobrien@itemx bar.c
761298948Sobrien@itemx baz.c
761398948Sobrien@itemx grbx.c
761498948SobrienOverlay modules, loaded and used by @file{overlays.c}.
761598948Sobrien@item d10v.ld
761698948Sobrien@itemx m32r.ld
761798948SobrienLinker scripts for linking the test program on the @code{d10v-elf}
761898948Sobrienand @code{m32r-elf} targets.
761998948Sobrien@end table
762098948Sobrien
762198948SobrienYou can build the test program using the @code{d10v-elf} GCC
762298948Sobriencross-compiler like this:
762398948Sobrien
7624130809Smarcel@smallexample
762598948Sobrien$ d10v-elf-gcc -g -c overlays.c
762698948Sobrien$ d10v-elf-gcc -g -c ovlymgr.c
762798948Sobrien$ d10v-elf-gcc -g -c foo.c
762898948Sobrien$ d10v-elf-gcc -g -c bar.c
762998948Sobrien$ d10v-elf-gcc -g -c baz.c
763098948Sobrien$ d10v-elf-gcc -g -c grbx.c
763198948Sobrien$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
763298948Sobrien                  baz.o grbx.o -Wl,-Td10v.ld -o overlays
7633130809Smarcel@end smallexample
763498948Sobrien
763598948SobrienThe build process is identical for any other architecture, except that
763698948Sobrienyou must substitute the appropriate compiler and linker script for the
763798948Sobrientarget system for @code{d10v-elf-gcc} and @code{d10v.ld}.
763898948Sobrien
763998948Sobrien
764098948Sobrien@node Languages
764119370Spst@chapter Using @value{GDBN} with Different Languages
764219370Spst@cindex languages
764319370Spst
764419370SpstAlthough programming languages generally have common aspects, they are
764519370Spstrarely expressed in the same manner.  For instance, in ANSI C,
764619370Spstdereferencing a pointer @code{p} is accomplished by @code{*p}, but in
764719370SpstModula-2, it is accomplished by @code{p^}.  Values can also be
764898948Sobrienrepresented (and displayed) differently.  Hex numbers in C appear as
764919370Spst@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
765019370Spst
765119370Spst@cindex working language
765219370SpstLanguage-specific information is built into @value{GDBN} for some languages,
765319370Spstallowing you to express operations like the above in your program's
765419370Spstnative language, and allowing @value{GDBN} to output values in a manner
765519370Spstconsistent with the syntax of your program's native language.  The
765619370Spstlanguage you use to build expressions is called the @dfn{working
765719370Spstlanguage}.
765819370Spst
765919370Spst@menu
766019370Spst* Setting::                     Switching between source languages
766119370Spst* Show::                        Displaying the language
766219370Spst* Checks::                      Type and range checks
766319370Spst* Support::                     Supported languages
7664130809Smarcel* Unsupported languages::       Unsupported languages
766519370Spst@end menu
766619370Spst
766798948Sobrien@node Setting
766819370Spst@section Switching between source languages
766919370Spst
767019370SpstThere are two ways to control the working language---either have @value{GDBN}
767119370Spstset it automatically, or select it manually yourself.  You can use the
767219370Spst@code{set language} command for either purpose.  On startup, @value{GDBN}
767319370Spstdefaults to setting the language automatically.  The working language is
767419370Spstused to determine how expressions you type are interpreted, how values
767519370Spstare printed, etc.
767619370Spst
767719370SpstIn addition to the working language, every source file that
767819370Spst@value{GDBN} knows about has its own working language.  For some object
767919370Spstfile formats, the compiler might indicate which language a particular
768019370Spstsource file is in.  However, most of the time @value{GDBN} infers the
768119370Spstlanguage from the name of the file.  The language of a source file
768298948Sobriencontrols whether C@t{++} names are demangled---this way @code{backtrace} can
768319370Spstshow each frame appropriately for its own language.  There is no way to
768498948Sobrienset the language of a source file from within @value{GDBN}, but you can
768598948Sobrienset the language associated with a filename extension.  @xref{Show, ,
768698948SobrienDisplaying the language}.
768719370Spst
768819370SpstThis is most commonly a problem when you use a program, such
768998948Sobrienas @code{cfront} or @code{f2c}, that generates C but is written in
769019370Spstanother language.  In that case, make the
769119370Spstprogram use @code{#line} directives in its C output; that way
769219370Spst@value{GDBN} will know the correct language of the source code of the original
769319370Spstprogram, and will display that source code, not the generated C code.
769419370Spst
769519370Spst@menu
769619370Spst* Filenames::                   Filename extensions and languages.
769719370Spst* Manually::                    Setting the working language manually
769819370Spst* Automatically::               Having @value{GDBN} infer the source language
769919370Spst@end menu
770019370Spst
770198948Sobrien@node Filenames
770219370Spst@subsection List of filename extensions and languages
770319370Spst
770419370SpstIf a source file name ends in one of the following extensions, then
770519370Spst@value{GDBN} infers that its language is the one indicated.
770619370Spst
770719370Spst@table @file
770819370Spst
770919370Spst@item .c
771019370SpstC source file
771119370Spst
771219370Spst@item .C
771319370Spst@itemx .cc
771446289Sdfr@itemx .cp
771546289Sdfr@itemx .cpp
771619370Spst@itemx .cxx
771719370Spst@itemx .c++
771898948SobrienC@t{++} source file
771919370Spst
7720130809Smarcel@item .m
7721130809SmarcelObjective-C source file
7722130809Smarcel
772346289Sdfr@item .f
772446289Sdfr@itemx .F
772546289SdfrFortran source file
772646289Sdfr
772746289Sdfr@item .mod
772846289SdfrModula-2 source file
772946289Sdfr
773019370Spst@item .s
773119370Spst@itemx .S
773219370SpstAssembler source file.  This actually behaves almost like C, but
773319370Spst@value{GDBN} does not skip over function prologues when stepping.
773419370Spst@end table
773519370Spst
773646289SdfrIn addition, you may set the language associated with a filename
773746289Sdfrextension.  @xref{Show, , Displaying the language}.
773846289Sdfr
773998948Sobrien@node Manually
774019370Spst@subsection Setting the working language
774119370Spst
774219370SpstIf you allow @value{GDBN} to set the language automatically,
774319370Spstexpressions are interpreted the same way in your debugging session and
774419370Spstyour program.
774519370Spst
774619370Spst@kindex set language
774719370SpstIf you wish, you may set the language manually.  To do this, issue the
774819370Spstcommand @samp{set language @var{lang}}, where @var{lang} is the name of
774998948Sobriena language, such as
775019370Spst@code{c} or @code{modula-2}.
775119370SpstFor a list of the supported languages, type @samp{set language}.
775219370Spst
775319370SpstSetting the language manually prevents @value{GDBN} from updating the working
775419370Spstlanguage automatically.  This can lead to confusion if you try
775519370Spstto debug a program when the working language is not the same as the
775619370Spstsource language, when an expression is acceptable to both
775719370Spstlanguages---but means different things.  For instance, if the current
775819370Spstsource file were written in C, and @value{GDBN} was parsing Modula-2, a
775919370Spstcommand such as:
776019370Spst
7761130809Smarcel@smallexample
776219370Spstprint a = b + c
7763130809Smarcel@end smallexample
776419370Spst
776519370Spst@noindent
776619370Spstmight not have the effect you intended.  In C, this means to add
776719370Spst@code{b} and @code{c} and place the result in @code{a}.  The result
776819370Spstprinted would be the value of @code{a}.  In Modula-2, this means to compare
776919370Spst@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
777019370Spst
777198948Sobrien@node Automatically
777219370Spst@subsection Having @value{GDBN} infer the source language
777319370Spst
777419370SpstTo have @value{GDBN} set the working language automatically, use
777519370Spst@samp{set language local} or @samp{set language auto}.  @value{GDBN}
777619370Spstthen infers the working language.  That is, when your program stops in a
777719370Spstframe (usually by encountering a breakpoint), @value{GDBN} sets the
777819370Spstworking language to the language recorded for the function in that
777919370Spstframe.  If the language for a frame is unknown (that is, if the function
778019370Spstor block corresponding to the frame was defined in a source file that
778119370Spstdoes not have a recognized extension), the current working language is
778219370Spstnot changed, and @value{GDBN} issues a warning.
778319370Spst
778419370SpstThis may not seem necessary for most programs, which are written
778519370Spstentirely in one source language.  However, program modules and libraries
778619370Spstwritten in one source language can be used by a main program written in
778719370Spsta different source language.  Using @samp{set language auto} in this
778819370Spstcase frees you from having to set the working language manually.
778919370Spst
779098948Sobrien@node Show
779119370Spst@section Displaying the language
779219370Spst
779319370SpstThe following commands help you find out which language is the
779419370Spstworking language, and also what language source files were written in.
779519370Spst
779619370Spst@kindex show language
779798948Sobrien@kindex info frame@r{, show the source language}
779898948Sobrien@kindex info source@r{, show the source language}
779919370Spst@table @code
780019370Spst@item show language
780119370SpstDisplay the current working language.  This is the
780219370Spstlanguage you can use with commands such as @code{print} to
780319370Spstbuild and compute expressions that may involve variables in your program.
780419370Spst
780519370Spst@item info frame
780698948SobrienDisplay the source language for this frame.  This language becomes the
780719370Spstworking language if you use an identifier from this frame.
780898948Sobrien@xref{Frame Info, ,Information about a frame}, to identify the other
780919370Spstinformation listed here.
781019370Spst
781119370Spst@item info source
781219370SpstDisplay the source language of this source file.
781398948Sobrien@xref{Symbols, ,Examining the Symbol Table}, to identify the other
781419370Spstinformation listed here.
781519370Spst@end table
781619370Spst
781746289SdfrIn unusual circumstances, you may have source files with extensions
781846289Sdfrnot in the standard list.  You can then set the extension associated
781946289Sdfrwith a language explicitly:
782046289Sdfr
782146289Sdfr@kindex set extension-language
782246289Sdfr@kindex info extensions
782346289Sdfr@table @code
782446289Sdfr@item set extension-language @var{.ext} @var{language}
782546289SdfrSet source files with extension @var{.ext} to be assumed to be in
782646289Sdfrthe source language @var{language}.
782746289Sdfr
782846289Sdfr@item info extensions
782946289SdfrList all the filename extensions and the associated languages.
783046289Sdfr@end table
783146289Sdfr
783298948Sobrien@node Checks
783319370Spst@section Type and range checking
783419370Spst
783519370Spst@quotation
783619370Spst@emph{Warning:} In this release, the @value{GDBN} commands for type and range
783719370Spstchecking are included, but they do not yet have any effect.  This
783819370Spstsection documents the intended facilities.
783919370Spst@end quotation
784019370Spst@c FIXME remove warning when type/range code added
784119370Spst
784219370SpstSome languages are designed to guard you against making seemingly common
784319370Spsterrors through a series of compile- and run-time checks.  These include
784419370Spstchecking the type of arguments to functions and operators, and making
784519370Spstsure mathematical overflows are caught at run time.  Checks such as
784619370Spstthese help to ensure a program's correctness once it has been compiled
784719370Spstby eliminating type mismatches, and providing active checks for range
784819370Spsterrors when your program is running.
784919370Spst
785019370Spst@value{GDBN} can check for conditions like the above if you wish.
785119370SpstAlthough @value{GDBN} does not check the statements in your program, it
785219370Spstcan check expressions entered directly into @value{GDBN} for evaluation via
785319370Spstthe @code{print} command, for example.  As with the working language,
785419370Spst@value{GDBN} can also decide whether or not to check automatically based on
785519370Spstyour program's source language.  @xref{Support, ,Supported languages},
785619370Spstfor the default settings of supported languages.
785719370Spst
785819370Spst@menu
785919370Spst* Type Checking::               An overview of type checking
786019370Spst* Range Checking::              An overview of range checking
786119370Spst@end menu
786219370Spst
786319370Spst@cindex type checking
786419370Spst@cindex checks, type
786598948Sobrien@node Type Checking
786619370Spst@subsection An overview of type checking
786719370Spst
786819370SpstSome languages, such as Modula-2, are strongly typed, meaning that the
786919370Spstarguments to operators and functions have to be of the correct type,
787019370Spstotherwise an error occurs.  These checks prevent type mismatch
787119370Spsterrors from ever causing any run-time problems.  For example,
787219370Spst
787319370Spst@smallexample
787419370Spst1 + 2 @result{} 3
787519370Spst@exdent but
787619370Spst@error{} 1 + 2.3
787719370Spst@end smallexample
787819370Spst
787919370SpstThe second example fails because the @code{CARDINAL} 1 is not
788019370Spsttype-compatible with the @code{REAL} 2.3.
788119370Spst
788298948SobrienFor the expressions you use in @value{GDBN} commands, you can tell the
788398948Sobrien@value{GDBN} type checker to skip checking;
788498948Sobriento treat any mismatches as errors and abandon the expression;
788598948Sobrienor to only issue warnings when type mismatches occur,
788619370Spstbut evaluate the expression anyway.  When you choose the last of
788719370Spstthese, @value{GDBN} evaluates expressions like the second example above, but
788819370Spstalso issues a warning.
788919370Spst
789098948SobrienEven if you turn type checking off, there may be other reasons
789198948Sobrienrelated to type that prevent @value{GDBN} from evaluating an expression.
789298948SobrienFor instance, @value{GDBN} does not know how to add an @code{int} and
789398948Sobriena @code{struct foo}.  These particular type errors have nothing to do
789498948Sobrienwith the language in use, and usually arise from expressions, such as
789519370Spstthe one described above, which make little sense to evaluate anyway.
789619370Spst
789719370SpstEach language defines to what degree it is strict about type.  For
789819370Spstinstance, both Modula-2 and C require the arguments to arithmetical
789919370Spstoperators to be numbers.  In C, enumerated types and pointers can be
790019370Spstrepresented as numbers, so that they are valid arguments to mathematical
790119370Spstoperators.  @xref{Support, ,Supported languages}, for further
790219370Spstdetails on specific languages.
790319370Spst
790419370Spst@value{GDBN} provides some additional commands for controlling the type checker:
790519370Spst
790698948Sobrien@kindex set check@r{, type}
790719370Spst@kindex set check type
790819370Spst@kindex show check type
790919370Spst@table @code
791019370Spst@item set check type auto
791119370SpstSet type checking on or off based on the current working language.
791219370Spst@xref{Support, ,Supported languages}, for the default settings for
791319370Spsteach language.
791419370Spst
791519370Spst@item set check type on
791619370Spst@itemx set check type off
791719370SpstSet type checking on or off, overriding the default setting for the
791819370Spstcurrent working language.  Issue a warning if the setting does not
791919370Spstmatch the language default.  If any type mismatches occur in
792098948Sobrienevaluating an expression while type checking is on, @value{GDBN} prints a
792119370Spstmessage and aborts evaluation of the expression.
792219370Spst
792319370Spst@item set check type warn
792419370SpstCause the type checker to issue warnings, but to always attempt to
792519370Spstevaluate the expression.  Evaluating the expression may still
792619370Spstbe impossible for other reasons.  For example, @value{GDBN} cannot add
792719370Spstnumbers and structures.
792819370Spst
792919370Spst@item show type
793098948SobrienShow the current setting of the type checker, and whether or not @value{GDBN}
793119370Spstis setting it automatically.
793219370Spst@end table
793319370Spst
793419370Spst@cindex range checking
793519370Spst@cindex checks, range
793698948Sobrien@node Range Checking
793719370Spst@subsection An overview of range checking
793819370Spst
793919370SpstIn some languages (such as Modula-2), it is an error to exceed the
794019370Spstbounds of a type; this is enforced with run-time checks.  Such range
794119370Spstchecking is meant to ensure program correctness by making sure
794219370Spstcomputations do not overflow, or indices on an array element access do
794319370Spstnot exceed the bounds of the array.
794419370Spst
794519370SpstFor expressions you use in @value{GDBN} commands, you can tell
794619370Spst@value{GDBN} to treat range errors in one of three ways: ignore them,
794719370Spstalways treat them as errors and abandon the expression, or issue
794819370Spstwarnings but evaluate the expression anyway.
794919370Spst
795019370SpstA range error can result from numerical overflow, from exceeding an
795119370Spstarray index bound, or when you type a constant that is not a member
795219370Spstof any type.  Some languages, however, do not treat overflows as an
795319370Spsterror.  In many implementations of C, mathematical overflow causes the
795419370Spstresult to ``wrap around'' to lower values---for example, if @var{m} is
795519370Spstthe largest integer value, and @var{s} is the smallest, then
795619370Spst
7957130809Smarcel@smallexample
795819370Spst@var{m} + 1 @result{} @var{s}
7959130809Smarcel@end smallexample
796019370Spst
796119370SpstThis, too, is specific to individual languages, and in some cases
796219370Spstspecific to individual compilers or machines.  @xref{Support, ,
796319370SpstSupported languages}, for further details on specific languages.
796419370Spst
796519370Spst@value{GDBN} provides some additional commands for controlling the range checker:
796619370Spst
796798948Sobrien@kindex set check@r{, range}
796819370Spst@kindex set check range
796919370Spst@kindex show check range
797019370Spst@table @code
797119370Spst@item set check range auto
797219370SpstSet range checking on or off based on the current working language.
797319370Spst@xref{Support, ,Supported languages}, for the default settings for
797419370Spsteach language.
797519370Spst
797619370Spst@item set check range on
797719370Spst@itemx set check range off
797819370SpstSet range checking on or off, overriding the default setting for the
797919370Spstcurrent working language.  A warning is issued if the setting does not
798098948Sobrienmatch the language default.  If a range error occurs and range checking is on,
798198948Sobrienthen a message is printed and evaluation of the expression is aborted.
798219370Spst
798319370Spst@item set check range warn
798419370SpstOutput messages when the @value{GDBN} range checker detects a range error,
798519370Spstbut attempt to evaluate the expression anyway.  Evaluating the
798619370Spstexpression may still be impossible for other reasons, such as accessing
798719370Spstmemory that the process does not own (a typical example from many Unix
798819370Spstsystems).
798919370Spst
799019370Spst@item show range
799119370SpstShow the current setting of the range checker, and whether or not it is
799219370Spstbeing set automatically by @value{GDBN}.
799319370Spst@end table
799419370Spst
799598948Sobrien@node Support
799619370Spst@section Supported languages
799719370Spst
7998130809Smarcel@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, assembly, and Modula-2.
799998948Sobrien@c This is false ...
800019370SpstSome @value{GDBN} features may be used in expressions regardless of the
800119370Spstlanguage you use: the @value{GDBN} @code{@@} and @code{::} operators,
800219370Spstand the @samp{@{type@}addr} construct (@pxref{Expressions,
800319370Spst,Expressions}) can be used with the constructs of any supported
800419370Spstlanguage.
800519370Spst
800619370SpstThe following sections detail to what degree each source language is
800719370Spstsupported by @value{GDBN}.  These sections are not meant to be language
800819370Spsttutorials or references, but serve only as a reference guide to what the
800919370Spst@value{GDBN} expression parser accepts, and what input and output
801019370Spstformats should look like for different languages.  There are many good
801119370Spstbooks written on each of these languages; please look to these for a
801219370Spstlanguage reference or tutorial.
801319370Spst
801419370Spst@menu
8015130809Smarcel* C::                           C and C@t{++}
8016130809Smarcel* Objective-C::                 Objective-C
8017130809Smarcel* Modula-2::                    Modula-2
801819370Spst@end menu
801919370Spst
802098948Sobrien@node C
802198948Sobrien@subsection C and C@t{++}
802219370Spst
802398948Sobrien@cindex C and C@t{++}
802498948Sobrien@cindex expressions in C or C@t{++}
802598948Sobrien
802698948SobrienSince C and C@t{++} are so closely related, many features of @value{GDBN} apply
802719370Spstto both languages.  Whenever this is the case, we discuss those languages
802819370Spsttogether.
802946289Sdfr
803098948Sobrien@cindex C@t{++}
803198948Sobrien@cindex @code{g++}, @sc{gnu} C@t{++} compiler
803298948Sobrien@cindex @sc{gnu} C@t{++}
803398948SobrienThe C@t{++} debugging facilities are jointly implemented by the C@t{++}
803498948Sobriencompiler and @value{GDBN}.  Therefore, to debug your C@t{++} code
803598948Sobrieneffectively, you must compile your C@t{++} programs with a supported
803698948SobrienC@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
803746289Sdfrcompiler (@code{aCC}).
803819370Spst
8039130809SmarcelFor best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8040130809Smarcelformat; if it doesn't work on your system, try the stabs+ debugging
8041130809Smarcelformat.  You can select those formats explicitly with the @code{g++}
8042130809Smarcelcommand-line options @option{-gdwarf-2} and @option{-gstabs+}.
8043130809Smarcel@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8044130809SmarcelCC, gcc.info, Using @sc{gnu} CC}.
804546289Sdfr
804619370Spst@menu
804798948Sobrien* C Operators::                 C and C@t{++} operators
804898948Sobrien* C Constants::                 C and C@t{++} constants
804998948Sobrien* C plus plus expressions::     C@t{++} expressions
805098948Sobrien* C Defaults::                  Default settings for C and C@t{++}
805198948Sobrien* C Checks::                    C and C@t{++} type and range checks
805298948Sobrien* Debugging C::                 @value{GDBN} and C
805398948Sobrien* Debugging C plus plus::       @value{GDBN} features for C@t{++}
805419370Spst@end menu
805546289Sdfr
805698948Sobrien@node C Operators
805798948Sobrien@subsubsection C and C@t{++} operators
805819370Spst
805998948Sobrien@cindex C and C@t{++} operators
806019370Spst
806119370SpstOperators must be defined on values of specific types.  For instance,
806219370Spst@code{+} is defined on numbers, but not on structures.  Operators are
806398948Sobrienoften defined on groups of types.
806419370Spst
806598948SobrienFor the purposes of C and C@t{++}, the following definitions hold:
806619370Spst
806719370Spst@itemize @bullet
806898948Sobrien
806919370Spst@item
807019370Spst@emph{Integral types} include @code{int} with any of its storage-class
807198948Sobrienspecifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
807219370Spst
807319370Spst@item
807498948Sobrien@emph{Floating-point types} include @code{float}, @code{double}, and
807598948Sobrien@code{long double} (if supported by the target platform).
807619370Spst
807719370Spst@item
807898948Sobrien@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
807919370Spst
808019370Spst@item
808119370Spst@emph{Scalar types} include all of the above.
808298948Sobrien
808319370Spst@end itemize
808419370Spst
808519370Spst@noindent
808619370SpstThe following operators are supported.  They are listed here
808719370Spstin order of increasing precedence:
808819370Spst
808919370Spst@table @code
809019370Spst@item ,
809119370SpstThe comma or sequencing operator.  Expressions in a comma-separated list
809219370Spstare evaluated from left to right, with the result of the entire
809319370Spstexpression being the last expression evaluated.
809419370Spst
809519370Spst@item =
809619370SpstAssignment.  The value of an assignment expression is the value
809719370Spstassigned.  Defined on scalar types.
809819370Spst
809919370Spst@item @var{op}=
810019370SpstUsed in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
810119370Spstand translated to @w{@code{@var{a} = @var{a op b}}}.
810298948Sobrien@w{@code{@var{op}=}} and @code{=} have the same precedence.
810319370Spst@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
810419370Spst@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
810519370Spst
810619370Spst@item ?:
810719370SpstThe ternary operator.  @code{@var{a} ? @var{b} : @var{c}} can be thought
810819370Spstof as:  if @var{a} then @var{b} else @var{c}.  @var{a} should be of an
810919370Spstintegral type.
811019370Spst
811119370Spst@item ||
811219370SpstLogical @sc{or}.  Defined on integral types.
811319370Spst
811419370Spst@item &&
811519370SpstLogical @sc{and}.  Defined on integral types.
811619370Spst
811719370Spst@item |
811819370SpstBitwise @sc{or}.  Defined on integral types.
811919370Spst
812019370Spst@item ^
812119370SpstBitwise exclusive-@sc{or}.  Defined on integral types.
812219370Spst
812319370Spst@item &
812419370SpstBitwise @sc{and}.  Defined on integral types.
812519370Spst
812619370Spst@item ==@r{, }!=
812719370SpstEquality and inequality.  Defined on scalar types.  The value of these
812819370Spstexpressions is 0 for false and non-zero for true.
812919370Spst
813019370Spst@item <@r{, }>@r{, }<=@r{, }>=
813119370SpstLess than, greater than, less than or equal, greater than or equal.
813219370SpstDefined on scalar types.  The value of these expressions is 0 for false
813319370Spstand non-zero for true.
813419370Spst
813519370Spst@item <<@r{, }>>
813619370Spstleft shift, and right shift.  Defined on integral types.
813719370Spst
813819370Spst@item @@
813919370SpstThe @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
814019370Spst
814119370Spst@item +@r{, }-
814219370SpstAddition and subtraction.  Defined on integral types, floating-point types and
814319370Spstpointer types.
814419370Spst
814519370Spst@item *@r{, }/@r{, }%
814619370SpstMultiplication, division, and modulus.  Multiplication and division are
814719370Spstdefined on integral and floating-point types.  Modulus is defined on
814819370Spstintegral types.
814919370Spst
815019370Spst@item ++@r{, }--
815119370SpstIncrement and decrement.  When appearing before a variable, the
815219370Spstoperation is performed before the variable is used in an expression;
815319370Spstwhen appearing after it, the variable's value is used before the
815419370Spstoperation takes place.
815519370Spst
815619370Spst@item *
815719370SpstPointer dereferencing.  Defined on pointer types.  Same precedence as
815819370Spst@code{++}.
815919370Spst
816019370Spst@item &
816119370SpstAddress operator.  Defined on variables.  Same precedence as @code{++}.
816219370Spst
816398948SobrienFor debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
816498948Sobrienallowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
816519370Spst(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
816698948Sobrienwhere a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
816719370Spststored.
816819370Spst
816919370Spst@item -
817019370SpstNegative.  Defined on integral and floating-point types.  Same
817119370Spstprecedence as @code{++}.
817219370Spst
817319370Spst@item !
817419370SpstLogical negation.  Defined on integral types.  Same precedence as
817519370Spst@code{++}.
817619370Spst
817719370Spst@item ~
817819370SpstBitwise complement operator.  Defined on integral types.  Same precedence as
817919370Spst@code{++}.
818019370Spst
818119370Spst
818219370Spst@item .@r{, }->
818319370SpstStructure member, and pointer-to-structure member.  For convenience,
818419370Spst@value{GDBN} regards the two as equivalent, choosing whether to dereference a
818519370Spstpointer based on the stored type information.
818619370SpstDefined on @code{struct} and @code{union} data.
818719370Spst
818846289Sdfr@item .*@r{, }->*
818946289SdfrDereferences of pointers to members.
819046289Sdfr
819119370Spst@item []
819219370SpstArray indexing.  @code{@var{a}[@var{i}]} is defined as
819319370Spst@code{*(@var{a}+@var{i})}.  Same precedence as @code{->}.
819419370Spst
819519370Spst@item ()
819619370SpstFunction parameter list.  Same precedence as @code{->}.
819719370Spst
819819370Spst@item ::
819998948SobrienC@t{++} scope resolution operator.  Defined on @code{struct}, @code{union},
820098948Sobrienand @code{class} types.
820119370Spst
820219370Spst@item ::
820398948SobrienDoubled colons also represent the @value{GDBN} scope operator
820498948Sobrien(@pxref{Expressions, ,Expressions}).  Same precedence as @code{::},
820598948Sobrienabove.
820619370Spst@end table
820719370Spst
820846289SdfrIf an operator is redefined in the user code, @value{GDBN} usually
820946289Sdfrattempts to invoke the redefined version instead of using the operator's
821046289Sdfrpredefined meaning.
821146289Sdfr
821246289Sdfr@menu
821398948Sobrien* C Constants::
821446289Sdfr@end menu
821546289Sdfr
821698948Sobrien@node C Constants
821798948Sobrien@subsubsection C and C@t{++} constants
821819370Spst
821998948Sobrien@cindex C and C@t{++} constants
822019370Spst
822198948Sobrien@value{GDBN} allows you to express the constants of C and C@t{++} in the
822219370Spstfollowing ways:
822319370Spst
822419370Spst@itemize @bullet
822519370Spst@item
822619370SpstInteger constants are a sequence of digits.  Octal constants are
822798948Sobrienspecified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
822898948Sobrienby a leading @samp{0x} or @samp{0X}.  Constants may also end with a letter
822919370Spst@samp{l}, specifying that the constant should be treated as a
823019370Spst@code{long} value.
823119370Spst
823219370Spst@item
823319370SpstFloating point constants are a sequence of digits, followed by a decimal
823419370Spstpoint, followed by a sequence of digits, and optionally followed by an
823519370Spstexponent.  An exponent is of the form:
823619370Spst@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
823719370Spstsequence of digits.  The @samp{+} is optional for positive exponents.
823898948SobrienA floating-point constant may also end with a letter @samp{f} or
823998948Sobrien@samp{F}, specifying that the constant should be treated as being of
824098948Sobrienthe @code{float} (as opposed to the default @code{double}) type; or with
824198948Sobriena letter @samp{l} or @samp{L}, which specifies a @code{long double}
824298948Sobrienconstant.
824319370Spst
824419370Spst@item
824519370SpstEnumerated constants consist of enumerated identifiers, or their
824619370Spstintegral equivalents.
824719370Spst
824819370Spst@item
824919370SpstCharacter constants are a single character surrounded by single quotes
825019370Spst(@code{'}), or a number---the ordinal value of the corresponding character
825198948Sobrien(usually its @sc{ascii} value).  Within quotes, the single character may
825219370Spstbe represented by a letter or by @dfn{escape sequences}, which are of
825319370Spstthe form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
825419370Spstof the character's ordinal value; or of the form @samp{\@var{x}}, where
825519370Spst@samp{@var{x}} is a predefined special character---for example,
825619370Spst@samp{\n} for newline.
825719370Spst
825819370Spst@item
825998948SobrienString constants are a sequence of character constants surrounded by
826098948Sobriendouble quotes (@code{"}).  Any valid character constant (as described
826198948Sobrienabove) may appear.  Double quotes within the string must be preceded by
826298948Sobriena backslash, so for instance @samp{"a\"b'c"} is a string of five
826398948Sobriencharacters.
826419370Spst
826519370Spst@item
826619370SpstPointer constants are an integral value.  You can also write pointers
826719370Spstto constants using the C operator @samp{&}.
826819370Spst
826919370Spst@item
827019370SpstArray constants are comma-separated lists surrounded by braces @samp{@{}
827119370Spstand @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
827219370Spstintegers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
827319370Spstand @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
827419370Spst@end itemize
827519370Spst
827646289Sdfr@menu
827798948Sobrien* C plus plus expressions::
827898948Sobrien* C Defaults::
827998948Sobrien* C Checks::
828046289Sdfr
828198948Sobrien* Debugging C::
828246289Sdfr@end menu
828346289Sdfr
828498948Sobrien@node C plus plus expressions
828598948Sobrien@subsubsection C@t{++} expressions
828619370Spst
828798948Sobrien@cindex expressions in C@t{++}
828898948Sobrien@value{GDBN} expression handling can interpret most C@t{++} expressions.
828919370Spst
8290130809Smarcel@cindex debugging C@t{++} programs
8291130809Smarcel@cindex C@t{++} compilers
8292130809Smarcel@cindex debug formats and C@t{++}
8293130809Smarcel@cindex @value{NGCC} and C@t{++}
829419370Spst@quotation
829598948Sobrien@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
8296130809Smarcelproper compiler and the proper debug format.  Currently, @value{GDBN}
8297130809Smarcelworks best when debugging C@t{++} code that is compiled with
8298130809Smarcel@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8299130809Smarcel@option{-gdwarf-2} or @option{-gstabs+}.  DWARF 2 is preferred over
8300130809Smarcelstabs+.  Most configurations of @value{NGCC} emit either DWARF 2 or
8301130809Smarcelstabs+ as their default debug format, so you usually don't need to
8302130809Smarcelspecify a debug format explicitly.  Other compilers and/or debug formats
8303130809Smarcelare likely to work badly or not at all when using @value{GDBN} to debug
8304130809SmarcelC@t{++} code.
830519370Spst@end quotation
830619370Spst
830719370Spst@enumerate
830819370Spst
830919370Spst@cindex member functions
831019370Spst@item
831119370SpstMember function calls are allowed; you can use expressions like
831219370Spst
8313130809Smarcel@smallexample
831419370Spstcount = aml->GetOriginal(x, y)
8315130809Smarcel@end smallexample
831619370Spst
831798948Sobrien@vindex this@r{, inside C@t{++} member functions}
831898948Sobrien@cindex namespace in C@t{++}
831919370Spst@item
832019370SpstWhile a member function is active (in the selected stack frame), your
832119370Spstexpressions have the same namespace available as the member function;
832219370Spstthat is, @value{GDBN} allows implicit references to the class instance
832398948Sobrienpointer @code{this} following the same rules as C@t{++}.
832419370Spst
832519370Spst@cindex call overloaded functions
832698948Sobrien@cindex overloaded functions, calling
832798948Sobrien@cindex type conversions in C@t{++}
832819370Spst@item
832919370SpstYou can call overloaded functions; @value{GDBN} resolves the function
833098948Sobriencall to the right definition, with some restrictions.  @value{GDBN} does not
833146289Sdfrperform overload resolution involving user-defined type conversions,
833246289Sdfrcalls to constructors, or instantiations of templates that do not exist
833346289Sdfrin the program.  It also cannot handle ellipsis argument lists or
833446289Sdfrdefault arguments.
833519370Spst
833646289SdfrIt does perform integral conversions and promotions, floating-point
833746289Sdfrpromotions, arithmetic conversions, pointer conversions, conversions of
833846289Sdfrclass objects to base classes, and standard conversions such as those of
833946289Sdfrfunctions or arrays to pointers; it requires an exact match on the
834046289Sdfrnumber of function arguments.
834146289Sdfr
834246289SdfrOverload resolution is always performed, unless you have specified
834346289Sdfr@code{set overload-resolution off}.  @xref{Debugging C plus plus,
834498948Sobrien,@value{GDBN} features for C@t{++}}.
834546289Sdfr
834698948SobrienYou must specify @code{set overload-resolution off} in order to use an
834746289Sdfrexplicit function signature to call an overloaded function, as in
834846289Sdfr@smallexample
834946289Sdfrp 'foo(char,int)'('x', 13)
835046289Sdfr@end smallexample
835198948Sobrien
835246289SdfrThe @value{GDBN} command-completion facility can simplify this;
835398948Sobriensee @ref{Completion, ,Command completion}.
835446289Sdfr
835519370Spst@cindex reference declarations
835619370Spst@item
835798948Sobrien@value{GDBN} understands variables declared as C@t{++} references; you can use
835898948Sobrienthem in expressions just as you do in C@t{++} source---they are automatically
835919370Spstdereferenced.
836019370Spst
836119370SpstIn the parameter list shown when @value{GDBN} displays a frame, the values of
836219370Spstreference variables are not displayed (unlike other variables); this
836319370Spstavoids clutter, since references are often used for large structures.
836419370SpstThe @emph{address} of a reference variable is always shown, unless
836519370Spstyou have specified @samp{set print address off}.
836619370Spst
836719370Spst@item
836898948Sobrien@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
836919370Spstexpressions can use it just as expressions in your program do.  Since
837019370Spstone scope may be defined in another, you can use @code{::} repeatedly if
837119370Spstnecessary, for example in an expression like
837219370Spst@samp{@var{scope1}::@var{scope2}::@var{name}}.  @value{GDBN} also allows
837398948Sobrienresolving name scope by reference to source files, in both C and C@t{++}
837419370Spstdebugging (@pxref{Variables, ,Program variables}).
837519370Spst@end enumerate
837619370Spst
837798948SobrienIn addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
837898948Sobriencalling virtual functions correctly, printing out virtual bases of
837998948Sobrienobjects, calling functions in a base subobject, casting objects, and
838098948Sobrieninvoking user-defined operators.
838146289Sdfr
838298948Sobrien@node C Defaults
838398948Sobrien@subsubsection C and C@t{++} defaults
838419370Spst
838598948Sobrien@cindex C and C@t{++} defaults
838698948Sobrien
838719370SpstIf you allow @value{GDBN} to set type and range checking automatically, they
838819370Spstboth default to @code{off} whenever the working language changes to
838998948SobrienC or C@t{++}.  This happens regardless of whether you or @value{GDBN}
839019370Spstselects the working language.
839119370Spst
839246289SdfrIf you allow @value{GDBN} to set the language automatically, it
839346289Sdfrrecognizes source files whose names end with @file{.c}, @file{.C}, or
839446289Sdfr@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
839598948Sobrienthese files, it sets the working language to C or C@t{++}.
839646289Sdfr@xref{Automatically, ,Having @value{GDBN} infer the source language},
839746289Sdfrfor further details.
839819370Spst
839919370Spst@c Type checking is (a) primarily motivated by Modula-2, and (b)
840019370Spst@c unimplemented.  If (b) changes, it might make sense to let this node
840119370Spst@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
840219370Spst
840398948Sobrien@node C Checks
840498948Sobrien@subsubsection C and C@t{++} type and range checks
840598948Sobrien
840698948Sobrien@cindex C and C@t{++} checks
840798948Sobrien
840898948SobrienBy default, when @value{GDBN} parses C or C@t{++} expressions, type checking
840919370Spstis not used.  However, if you turn type checking on, @value{GDBN}
841019370Spstconsiders two variables type equivalent if:
841119370Spst
841219370Spst@itemize @bullet
841319370Spst@item
841419370SpstThe two variables are structured and have the same structure, union, or
841519370Spstenumerated tag.
841619370Spst
841719370Spst@item
841819370SpstThe two variables have the same type name, or types that have been
841919370Spstdeclared equivalent through @code{typedef}.
842019370Spst
842119370Spst@ignore
842219370Spst@c leaving this out because neither J Gilmore nor R Pesch understand it.
842319370Spst@c FIXME--beers?
842419370Spst@item
842519370SpstThe two @code{struct}, @code{union}, or @code{enum} variables are
842619370Spstdeclared in the same declaration.  (Note: this may not be true for all C
842719370Spstcompilers.)
842819370Spst@end ignore
842919370Spst@end itemize
843019370Spst
843119370SpstRange checking, if turned on, is done on mathematical operations.  Array
843219370Spstindices are not checked, since they are often used to index a pointer
843319370Spstthat is not itself an array.
843419370Spst
843598948Sobrien@node Debugging C
843619370Spst@subsubsection @value{GDBN} and C
843719370Spst
843819370SpstThe @code{set print union} and @code{show print union} commands apply to
843919370Spstthe @code{union} type.  When set to @samp{on}, any @code{union} that is
844098948Sobrieninside a @code{struct} or @code{class} is also printed.  Otherwise, it
844198948Sobrienappears as @samp{@{...@}}.
844219370Spst
844319370SpstThe @code{@@} operator aids in the debugging of dynamic arrays, formed
844419370Spstwith pointers and a memory allocation function.  @xref{Expressions,
844519370Spst,Expressions}.
844619370Spst
844746289Sdfr@menu
844898948Sobrien* Debugging C plus plus::
844946289Sdfr@end menu
845046289Sdfr
845198948Sobrien@node Debugging C plus plus
845298948Sobrien@subsubsection @value{GDBN} features for C@t{++}
845319370Spst
845498948Sobrien@cindex commands for C@t{++}
845519370Spst
845698948SobrienSome @value{GDBN} commands are particularly useful with C@t{++}, and some are
845798948Sobriendesigned specifically for use with C@t{++}.  Here is a summary:
845898948Sobrien
845919370Spst@table @code
846019370Spst@cindex break in overloaded functions
846119370Spst@item @r{breakpoint menus}
846219370SpstWhen you want a breakpoint in a function whose name is overloaded,
846319370Spst@value{GDBN} breakpoint menus help you specify which function definition
846419370Spstyou want.  @xref{Breakpoint Menus,,Breakpoint menus}.
846519370Spst
846698948Sobrien@cindex overloading in C@t{++}
846719370Spst@item rbreak @var{regex}
846819370SpstSetting breakpoints using regular expressions is helpful for setting
846919370Spstbreakpoints on overloaded functions that are not members of any special
847019370Spstclasses.
847119370Spst@xref{Set Breaks, ,Setting breakpoints}.
847219370Spst
847398948Sobrien@cindex C@t{++} exception handling
847446289Sdfr@item catch throw
847546289Sdfr@itemx catch catch
847698948SobrienDebug C@t{++} exception handling using these commands.  @xref{Set
847746289SdfrCatchpoints, , Setting catchpoints}.
847819370Spst
847919370Spst@cindex inheritance
848019370Spst@item ptype @var{typename}
848119370SpstPrint inheritance relationships as well as other information for type
848219370Spst@var{typename}.
848319370Spst@xref{Symbols, ,Examining the Symbol Table}.
848419370Spst
848598948Sobrien@cindex C@t{++} symbol display
848619370Spst@item set print demangle
848719370Spst@itemx show print demangle
848819370Spst@itemx set print asm-demangle
848919370Spst@itemx show print asm-demangle
849098948SobrienControl whether C@t{++} symbols display in their source form, both when
849198948Sobriendisplaying code as C@t{++} source and when displaying disassemblies.
849219370Spst@xref{Print Settings, ,Print settings}.
849319370Spst
849419370Spst@item set print object
849519370Spst@itemx show print object
849619370SpstChoose whether to print derived (actual) or declared types of objects.
849719370Spst@xref{Print Settings, ,Print settings}.
849819370Spst
849919370Spst@item set print vtbl
850019370Spst@itemx show print vtbl
850119370SpstControl the format for printing virtual function tables.
850219370Spst@xref{Print Settings, ,Print settings}.
850346289Sdfr(The @code{vtbl} commands do not work on programs compiled with the HP
850498948SobrienANSI C@t{++} compiler (@code{aCC}).)
850519370Spst
850646289Sdfr@kindex set overload-resolution
850798948Sobrien@cindex overloaded functions, overload resolution
850846289Sdfr@item set overload-resolution on
850998948SobrienEnable overload resolution for C@t{++} expression evaluation.  The default
851046289Sdfris on.  For overloaded functions, @value{GDBN} evaluates the arguments
851146289Sdfrand searches for a function whose signature matches the argument types,
851298948Sobrienusing the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
851398948Sobrienexpressions}, for details).  If it cannot find a match, it emits a
851446289Sdfrmessage.
851546289Sdfr
851646289Sdfr@item set overload-resolution off
851798948SobrienDisable overload resolution for C@t{++} expression evaluation.  For
851846289Sdfroverloaded functions that are not class member functions, @value{GDBN}
851946289Sdfrchooses the first function of the specified name that it finds in the
852046289Sdfrsymbol table, whether or not its arguments are of the correct type.  For
852146289Sdfroverloaded functions that are class member functions, @value{GDBN}
852246289Sdfrsearches for a function whose signature @emph{exactly} matches the
852346289Sdfrargument types.
852446289Sdfr
852519370Spst@item @r{Overloaded symbol names}
852619370SpstYou can specify a particular definition of an overloaded symbol, using
852798948Sobrienthe same notation that is used to declare such symbols in C@t{++}: type
852819370Spst@code{@var{symbol}(@var{types})} rather than just @var{symbol}.  You can
852919370Spstalso use the @value{GDBN} command-line word completion facilities to list the
853019370Spstavailable choices, or to finish the type list for you.
853119370Spst@xref{Completion,, Command completion}, for details on how to do this.
853219370Spst@end table
853319370Spst
8534130809Smarcel@node Objective-C
8535130809Smarcel@subsection Objective-C
8536130809Smarcel
8537130809Smarcel@cindex Objective-C
8538130809SmarcelThis section provides information about some commands and command
8539130809Smarceloptions that are useful for debugging Objective-C code.
8540130809Smarcel
8541130809Smarcel@menu
8542130809Smarcel* Method Names in Commands::
8543130809Smarcel* The Print Command with Objective-C::
8544130809Smarcel@end menu
8545130809Smarcel
8546130809Smarcel@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
8547130809Smarcel@subsubsection Method Names in Commands
8548130809Smarcel
8549130809SmarcelThe following commands have been extended to accept Objective-C method
8550130809Smarcelnames as line specifications:
8551130809Smarcel
8552130809Smarcel@kindex clear@r{, and Objective-C}
8553130809Smarcel@kindex break@r{, and Objective-C}
8554130809Smarcel@kindex info line@r{, and Objective-C}
8555130809Smarcel@kindex jump@r{, and Objective-C}
8556130809Smarcel@kindex list@r{, and Objective-C}
8557130809Smarcel@itemize
8558130809Smarcel@item @code{clear}
8559130809Smarcel@item @code{break}
8560130809Smarcel@item @code{info line}
8561130809Smarcel@item @code{jump}
8562130809Smarcel@item @code{list}
8563130809Smarcel@end itemize
8564130809Smarcel
8565130809SmarcelA fully qualified Objective-C method name is specified as
8566130809Smarcel
8567130809Smarcel@smallexample
8568130809Smarcel-[@var{Class} @var{methodName}]
8569130809Smarcel@end smallexample
8570130809Smarcel
8571130809Smarcelwhere the minus sign is used to indicate an instance method and a
8572130809Smarcelplus sign (not shown) is used to indicate a class method.  The class
8573130809Smarcelname @var{Class} and method name @var{methodName} are enclosed in
8574130809Smarcelbrackets, similar to the way messages are specified in Objective-C
8575130809Smarcelsource code.  For example, to set a breakpoint at the @code{create}
8576130809Smarcelinstance method of class @code{Fruit} in the program currently being
8577130809Smarceldebugged, enter:
8578130809Smarcel
8579130809Smarcel@smallexample
8580130809Smarcelbreak -[Fruit create]
8581130809Smarcel@end smallexample
8582130809Smarcel
8583130809SmarcelTo list ten program lines around the @code{initialize} class method,
8584130809Smarcelenter:
8585130809Smarcel
8586130809Smarcel@smallexample
8587130809Smarcellist +[NSText initialize]
8588130809Smarcel@end smallexample
8589130809Smarcel
8590130809SmarcelIn the current version of @value{GDBN}, the plus or minus sign is
8591130809Smarcelrequired.  In future versions of @value{GDBN}, the plus or minus
8592130809Smarcelsign will be optional, but you can use it to narrow the search.  It
8593130809Smarcelis also possible to specify just a method name:
8594130809Smarcel
8595130809Smarcel@smallexample
8596130809Smarcelbreak create
8597130809Smarcel@end smallexample
8598130809Smarcel
8599130809SmarcelYou must specify the complete method name, including any colons.  If
8600130809Smarcelyour program's source files contain more than one @code{create} method,
8601130809Smarcelyou'll be presented with a numbered list of classes that implement that
8602130809Smarcelmethod.  Indicate your choice by number, or type @samp{0} to exit if
8603130809Smarcelnone apply.
8604130809Smarcel
8605130809SmarcelAs another example, to clear a breakpoint established at the
8606130809Smarcel@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
8607130809Smarcel
8608130809Smarcel@smallexample
8609130809Smarcelclear -[NSWindow makeKeyAndOrderFront:]
8610130809Smarcel@end smallexample
8611130809Smarcel
8612130809Smarcel@node The Print Command with Objective-C
8613130809Smarcel@subsubsection The Print Command With Objective-C
8614130809Smarcel@kindex print-object
8615130809Smarcel@kindex po @r{(@code{print-object})}
8616130809Smarcel
8617130809SmarcelThe print command has also been extended to accept methods.  For example:
8618130809Smarcel
8619130809Smarcel@smallexample
8620130809Smarcelprint -[@var{object} hash]
8621130809Smarcel@end smallexample
8622130809Smarcel
8623130809Smarcel@cindex print an Objective-C object description
8624130809Smarcel@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
8625130809Smarcel@noindent
8626130809Smarcelwill tell @value{GDBN} to send the @code{hash} message to @var{object}
8627130809Smarceland print the result.  Also, an additional command has been added,
8628130809Smarcel@code{print-object} or @code{po} for short, which is meant to print
8629130809Smarcelthe description of an object.  However, this command may only work
8630130809Smarcelwith certain Objective-C libraries that have a particular hook
8631130809Smarcelfunction, @code{_NSPrintForDebugger}, defined.
8632130809Smarcel
8633130809Smarcel@node Modula-2,  , Objective-C, Support
863419370Spst@subsection Modula-2
863519370Spst
863698948Sobrien@cindex Modula-2, @value{GDBN} support
863798948Sobrien
863819370SpstThe extensions made to @value{GDBN} to support Modula-2 only support
863919370Spstoutput from the @sc{gnu} Modula-2 compiler (which is currently being
864019370Spstdeveloped).  Other Modula-2 compilers are not currently supported, and
864119370Spstattempting to debug executables produced by them is most likely
864219370Spstto give an error as @value{GDBN} reads in the executable's symbol
864319370Spsttable.
864419370Spst
864519370Spst@cindex expressions in Modula-2
864619370Spst@menu
864719370Spst* M2 Operators::                Built-in operators
864846289Sdfr* Built-In Func/Proc::          Built-in functions and procedures
864919370Spst* M2 Constants::                Modula-2 constants
865019370Spst* M2 Defaults::                 Default settings for Modula-2
865119370Spst* Deviations::                  Deviations from standard Modula-2
865219370Spst* M2 Checks::                   Modula-2 type and range checks
865319370Spst* M2 Scope::                    The scope operators @code{::} and @code{.}
865419370Spst* GDB/M2::                      @value{GDBN} and Modula-2
865519370Spst@end menu
865619370Spst
865798948Sobrien@node M2 Operators
865819370Spst@subsubsection Operators
865919370Spst@cindex Modula-2 operators
866019370Spst
866119370SpstOperators must be defined on values of specific types.  For instance,
866219370Spst@code{+} is defined on numbers, but not on structures.  Operators are
866319370Spstoften defined on groups of types.  For the purposes of Modula-2, the
866419370Spstfollowing definitions hold:
866519370Spst
866619370Spst@itemize @bullet
866719370Spst
866819370Spst@item
866919370Spst@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
867019370Spsttheir subranges.
867119370Spst
867219370Spst@item
867319370Spst@emph{Character types} consist of @code{CHAR} and its subranges.
867419370Spst
867519370Spst@item
867619370Spst@emph{Floating-point types} consist of @code{REAL}.
867719370Spst
867819370Spst@item
867919370Spst@emph{Pointer types} consist of anything declared as @code{POINTER TO
868019370Spst@var{type}}.
868119370Spst
868219370Spst@item
868319370Spst@emph{Scalar types} consist of all of the above.
868419370Spst
868519370Spst@item
868619370Spst@emph{Set types} consist of @code{SET} and @code{BITSET} types.
868719370Spst
868819370Spst@item
868919370Spst@emph{Boolean types} consist of @code{BOOLEAN}.
869019370Spst@end itemize
869119370Spst
869219370Spst@noindent
869319370SpstThe following operators are supported, and appear in order of
869419370Spstincreasing precedence:
869519370Spst
869619370Spst@table @code
869719370Spst@item ,
869819370SpstFunction argument or array index separator.
869919370Spst
870019370Spst@item :=
870119370SpstAssignment.  The value of @var{var} @code{:=} @var{value} is
870219370Spst@var{value}.
870319370Spst
870419370Spst@item <@r{, }>
870519370SpstLess than, greater than on integral, floating-point, or enumerated
870619370Spsttypes.
870719370Spst
870819370Spst@item <=@r{, }>=
870998948SobrienLess than or equal to, greater than or equal to
871019370Spston integral, floating-point and enumerated types, or set inclusion on
871119370Spstset types.  Same precedence as @code{<}.
871219370Spst
871319370Spst@item =@r{, }<>@r{, }#
871419370SpstEquality and two ways of expressing inequality, valid on scalar types.
871519370SpstSame precedence as @code{<}.  In @value{GDBN} scripts, only @code{<>} is
871619370Spstavailable for inequality, since @code{#} conflicts with the script
871719370Spstcomment character.
871819370Spst
871919370Spst@item IN
872019370SpstSet membership.  Defined on set types and the types of their members.
872119370SpstSame precedence as @code{<}.
872219370Spst
872319370Spst@item OR
872419370SpstBoolean disjunction.  Defined on boolean types.
872519370Spst
872619370Spst@item AND@r{, }&
872798948SobrienBoolean conjunction.  Defined on boolean types.
872819370Spst
872919370Spst@item @@
873019370SpstThe @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
873119370Spst
873219370Spst@item +@r{, }-
873319370SpstAddition and subtraction on integral and floating-point types, or union
873419370Spstand difference on set types.
873519370Spst
873619370Spst@item *
873719370SpstMultiplication on integral and floating-point types, or set intersection
873819370Spston set types.
873919370Spst
874019370Spst@item /
874119370SpstDivision on floating-point types, or symmetric set difference on set
874219370Spsttypes.  Same precedence as @code{*}.
874319370Spst
874419370Spst@item DIV@r{, }MOD
874519370SpstInteger division and remainder.  Defined on integral types.  Same
874619370Spstprecedence as @code{*}.
874719370Spst
874819370Spst@item -
874919370SpstNegative. Defined on @code{INTEGER} and @code{REAL} data.
875019370Spst
875119370Spst@item ^
875219370SpstPointer dereferencing.  Defined on pointer types.
875319370Spst
875419370Spst@item NOT
875519370SpstBoolean negation.  Defined on boolean types.  Same precedence as
875619370Spst@code{^}.
875719370Spst
875819370Spst@item .
875919370Spst@code{RECORD} field selector.  Defined on @code{RECORD} data.  Same
876019370Spstprecedence as @code{^}.
876119370Spst
876219370Spst@item []
876319370SpstArray indexing.  Defined on @code{ARRAY} data.  Same precedence as @code{^}.
876419370Spst
876519370Spst@item ()
876619370SpstProcedure argument list.  Defined on @code{PROCEDURE} objects.  Same precedence
876719370Spstas @code{^}.
876819370Spst
876919370Spst@item ::@r{, }.
877019370Spst@value{GDBN} and Modula-2 scope operators.
877119370Spst@end table
877219370Spst
877319370Spst@quotation
877419370Spst@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
877519370Spsttreats the use of the operator @code{IN}, or the use of operators
877619370Spst@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
877719370Spst@code{<=}, and @code{>=} on sets as an error.
877819370Spst@end quotation
877919370Spst
878098948Sobrien
878198948Sobrien@node Built-In Func/Proc
878298948Sobrien@subsubsection Built-in functions and procedures
878319370Spst@cindex Modula-2 built-ins
878419370Spst
878519370SpstModula-2 also makes available several built-in procedures and functions.
878619370SpstIn describing these, the following metavariables are used:
878719370Spst
878819370Spst@table @var
878919370Spst
879019370Spst@item a
879119370Spstrepresents an @code{ARRAY} variable.
879219370Spst
879319370Spst@item c
879419370Spstrepresents a @code{CHAR} constant or variable.
879519370Spst
879619370Spst@item i
879719370Spstrepresents a variable or constant of integral type.
879819370Spst
879919370Spst@item m
880019370Spstrepresents an identifier that belongs to a set.  Generally used in the
880119370Spstsame function with the metavariable @var{s}.  The type of @var{s} should
880219370Spstbe @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
880319370Spst
880419370Spst@item n
880519370Spstrepresents a variable or constant of integral or floating-point type.
880619370Spst
880719370Spst@item r
880819370Spstrepresents a variable or constant of floating-point type.
880919370Spst
881019370Spst@item t
881119370Spstrepresents a type.
881219370Spst
881319370Spst@item v
881419370Spstrepresents a variable.
881519370Spst
881619370Spst@item x
881719370Spstrepresents a variable or constant of one of many types.  See the
881819370Spstexplanation of the function for details.
881919370Spst@end table
882019370Spst
882119370SpstAll Modula-2 built-in procedures also return a result, described below.
882219370Spst
882319370Spst@table @code
882419370Spst@item ABS(@var{n})
882519370SpstReturns the absolute value of @var{n}.
882619370Spst
882719370Spst@item CAP(@var{c})
882819370SpstIf @var{c} is a lower case letter, it returns its upper case
882998948Sobrienequivalent, otherwise it returns its argument.
883019370Spst
883119370Spst@item CHR(@var{i})
883219370SpstReturns the character whose ordinal value is @var{i}.
883319370Spst
883419370Spst@item DEC(@var{v})
883598948SobrienDecrements the value in the variable @var{v} by one.  Returns the new value.
883619370Spst
883719370Spst@item DEC(@var{v},@var{i})
883819370SpstDecrements the value in the variable @var{v} by @var{i}.  Returns the
883919370Spstnew value.
884019370Spst
884119370Spst@item EXCL(@var{m},@var{s})
884219370SpstRemoves the element @var{m} from the set @var{s}.  Returns the new
884319370Spstset.
884419370Spst
884519370Spst@item FLOAT(@var{i})
884619370SpstReturns the floating point equivalent of the integer @var{i}.
884719370Spst
884819370Spst@item HIGH(@var{a})
884919370SpstReturns the index of the last member of @var{a}.
885019370Spst
885119370Spst@item INC(@var{v})
885298948SobrienIncrements the value in the variable @var{v} by one.  Returns the new value.
885319370Spst
885419370Spst@item INC(@var{v},@var{i})
885519370SpstIncrements the value in the variable @var{v} by @var{i}.  Returns the
885619370Spstnew value.
885719370Spst
885819370Spst@item INCL(@var{m},@var{s})
885919370SpstAdds the element @var{m} to the set @var{s} if it is not already
886019370Spstthere.  Returns the new set.
886119370Spst
886219370Spst@item MAX(@var{t})
886319370SpstReturns the maximum value of the type @var{t}.
886419370Spst
886519370Spst@item MIN(@var{t})
886619370SpstReturns the minimum value of the type @var{t}.
886719370Spst
886819370Spst@item ODD(@var{i})
886919370SpstReturns boolean TRUE if @var{i} is an odd number.
887019370Spst
887119370Spst@item ORD(@var{x})
887219370SpstReturns the ordinal value of its argument.  For example, the ordinal
887398948Sobrienvalue of a character is its @sc{ascii} value (on machines supporting the
887498948Sobrien@sc{ascii} character set).  @var{x} must be of an ordered type, which include
887519370Spstintegral, character and enumerated types.
887619370Spst
887719370Spst@item SIZE(@var{x})
887819370SpstReturns the size of its argument.  @var{x} can be a variable or a type.
887919370Spst
888019370Spst@item TRUNC(@var{r})
888119370SpstReturns the integral part of @var{r}.
888219370Spst
888319370Spst@item VAL(@var{t},@var{i})
888419370SpstReturns the member of the type @var{t} whose ordinal value is @var{i}.
888519370Spst@end table
888619370Spst
888719370Spst@quotation
888819370Spst@emph{Warning:}  Sets and their operations are not yet supported, so
888919370Spst@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
889019370Spstan error.
889119370Spst@end quotation
889219370Spst
889319370Spst@cindex Modula-2 constants
889498948Sobrien@node M2 Constants
889519370Spst@subsubsection Constants
889619370Spst
889719370Spst@value{GDBN} allows you to express the constants of Modula-2 in the following
889819370Spstways:
889919370Spst
890019370Spst@itemize @bullet
890119370Spst
890219370Spst@item
890319370SpstInteger constants are simply a sequence of digits.  When used in an
890419370Spstexpression, a constant is interpreted to be type-compatible with the
890519370Spstrest of the expression.  Hexadecimal integers are specified by a
890619370Spsttrailing @samp{H}, and octal integers by a trailing @samp{B}.
890719370Spst
890819370Spst@item
890919370SpstFloating point constants appear as a sequence of digits, followed by a
891019370Spstdecimal point and another sequence of digits.  An optional exponent can
891119370Spstthen be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
891219370Spst@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent.  All of the
891319370Spstdigits of the floating point constant must be valid decimal (base 10)
891419370Spstdigits.
891519370Spst
891619370Spst@item
891719370SpstCharacter constants consist of a single character enclosed by a pair of
891819370Spstlike quotes, either single (@code{'}) or double (@code{"}).  They may
891998948Sobrienalso be expressed by their ordinal value (their @sc{ascii} value, usually)
892019370Spstfollowed by a @samp{C}.
892119370Spst
892219370Spst@item
892319370SpstString constants consist of a sequence of characters enclosed by a
892419370Spstpair of like quotes, either single (@code{'}) or double (@code{"}).
892519370SpstEscape sequences in the style of C are also allowed.  @xref{C
892698948SobrienConstants, ,C and C@t{++} constants}, for a brief explanation of escape
892719370Spstsequences.
892819370Spst
892919370Spst@item
893019370SpstEnumerated constants consist of an enumerated identifier.
893119370Spst
893219370Spst@item
893319370SpstBoolean constants consist of the identifiers @code{TRUE} and
893419370Spst@code{FALSE}.
893519370Spst
893619370Spst@item
893719370SpstPointer constants consist of integral values only.
893819370Spst
893919370Spst@item
894019370SpstSet constants are not yet supported.
894119370Spst@end itemize
894219370Spst
894398948Sobrien@node M2 Defaults
894419370Spst@subsubsection Modula-2 defaults
894519370Spst@cindex Modula-2 defaults
894619370Spst
894719370SpstIf type and range checking are set automatically by @value{GDBN}, they
894819370Spstboth default to @code{on} whenever the working language changes to
894998948SobrienModula-2.  This happens regardless of whether you or @value{GDBN}
895019370Spstselected the working language.
895119370Spst
895219370SpstIf you allow @value{GDBN} to set the language automatically, then entering
895319370Spstcode compiled from a file whose name ends with @file{.mod} sets the
895498948Sobrienworking language to Modula-2.  @xref{Automatically, ,Having @value{GDBN} set
895519370Spstthe language automatically}, for further details.
895619370Spst
895798948Sobrien@node Deviations
895819370Spst@subsubsection Deviations from standard Modula-2
895919370Spst@cindex Modula-2, deviations from
896019370Spst
896119370SpstA few changes have been made to make Modula-2 programs easier to debug.
896219370SpstThis is done primarily via loosening its type strictness:
896319370Spst
896419370Spst@itemize @bullet
896519370Spst@item
896619370SpstUnlike in standard Modula-2, pointer constants can be formed by
896719370Spstintegers.  This allows you to modify pointer variables during
896819370Spstdebugging.  (In standard Modula-2, the actual address contained in a
896919370Spstpointer variable is hidden from you; it can only be modified
897019370Spstthrough direct assignment to another pointer variable or expression that
897119370Spstreturned a pointer.)
897219370Spst
897319370Spst@item
897419370SpstC escape sequences can be used in strings and characters to represent
897519370Spstnon-printable characters.  @value{GDBN} prints out strings with these
897619370Spstescape sequences embedded.  Single non-printable characters are
897719370Spstprinted using the @samp{CHR(@var{nnn})} format.
897819370Spst
897919370Spst@item
898019370SpstThe assignment operator (@code{:=}) returns the value of its right-hand
898119370Spstargument.
898219370Spst
898319370Spst@item
898419370SpstAll built-in procedures both modify @emph{and} return their argument.
898519370Spst@end itemize
898619370Spst
898798948Sobrien@node M2 Checks
898819370Spst@subsubsection Modula-2 type and range checks
898919370Spst@cindex Modula-2 checks
899019370Spst
899119370Spst@quotation
899219370Spst@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
899319370Spstrange checking.
899419370Spst@end quotation
899519370Spst@c FIXME remove warning when type/range checks added
899619370Spst
899719370Spst@value{GDBN} considers two Modula-2 variables type equivalent if:
899819370Spst
899919370Spst@itemize @bullet
900019370Spst@item
900119370SpstThey are of types that have been declared equivalent via a @code{TYPE
900219370Spst@var{t1} = @var{t2}} statement
900319370Spst
900419370Spst@item
900519370SpstThey have been declared on the same line.  (Note:  This is true of the
900619370Spst@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
900719370Spst@end itemize
900819370Spst
900919370SpstAs long as type checking is enabled, any attempt to combine variables
901019370Spstwhose types are not equivalent is an error.
901119370Spst
901219370SpstRange checking is done on all mathematical operations, assignment, array
901319370Spstindex bounds, and all built-in functions and procedures.
901419370Spst
901598948Sobrien@node M2 Scope
901619370Spst@subsubsection The scope operators @code{::} and @code{.}
901719370Spst@cindex scope
901898948Sobrien@cindex @code{.}, Modula-2 scope operator
901919370Spst@cindex colon, doubled as scope operator
902019370Spst@ifinfo
902198948Sobrien@vindex colon-colon@r{, in Modula-2}
902219370Spst@c Info cannot handle :: but TeX can.
902319370Spst@end ifinfo
902419370Spst@iftex
902598948Sobrien@vindex ::@r{, in Modula-2}
902619370Spst@end iftex
902719370Spst
902819370SpstThere are a few subtle differences between the Modula-2 scope operator
902919370Spst(@code{.}) and the @value{GDBN} scope operator (@code{::}).  The two have
903019370Spstsimilar syntax:
903119370Spst
9032130809Smarcel@smallexample
903319370Spst
903419370Spst@var{module} . @var{id}
903519370Spst@var{scope} :: @var{id}
9036130809Smarcel@end smallexample
903719370Spst
903819370Spst@noindent
903919370Spstwhere @var{scope} is the name of a module or a procedure,
904019370Spst@var{module} the name of a module, and @var{id} is any declared
904119370Spstidentifier within your program, except another module.
904219370Spst
904319370SpstUsing the @code{::} operator makes @value{GDBN} search the scope
904419370Spstspecified by @var{scope} for the identifier @var{id}.  If it is not
904519370Spstfound in the specified scope, then @value{GDBN} searches all scopes
904619370Spstenclosing the one specified by @var{scope}.
904719370Spst
904819370SpstUsing the @code{.} operator makes @value{GDBN} search the current scope for
904919370Spstthe identifier specified by @var{id} that was imported from the
905019370Spstdefinition module specified by @var{module}.  With this operator, it is
905119370Spstan error if the identifier @var{id} was not imported from definition
905219370Spstmodule @var{module}, or if @var{id} is not an identifier in
905319370Spst@var{module}.
905419370Spst
905598948Sobrien@node GDB/M2
905619370Spst@subsubsection @value{GDBN} and Modula-2
905719370Spst
905819370SpstSome @value{GDBN} commands have little use when debugging Modula-2 programs.
905919370SpstFive subcommands of @code{set print} and @code{show print} apply
906098948Sobrienspecifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
906119370Spst@samp{asm-demangle}, @samp{object}, and @samp{union}.  The first four
906298948Sobrienapply to C@t{++}, and the last to the C @code{union} type, which has no direct
906319370Spstanalogue in Modula-2.
906419370Spst
906519370SpstThe @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
906698948Sobrienwith any language, is not useful with Modula-2.  Its
906719370Spstintent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
906898948Sobriencreated in Modula-2 as they can in C or C@t{++}.  However, because an
906919370Spstaddress can be specified by an integral constant, the construct
907098948Sobrien@samp{@{@var{type}@}@var{adrexp}} is still useful.
907119370Spst
907219370Spst@cindex @code{#} in Modula-2
907319370SpstIn @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
907419370Spstinterpreted as the beginning of a comment.  Use @code{<>} instead.
907519370Spst
9076130809Smarcel@node Unsupported languages
9077130809Smarcel@section Unsupported languages
907898948Sobrien
9079130809Smarcel@cindex unsupported languages
9080130809Smarcel@cindex minimal language
9081130809SmarcelIn addition to the other fully-supported programming languages,
9082130809Smarcel@value{GDBN} also provides a pseudo-language, called @code{minimal}.
9083130809SmarcelIt does not represent a real programming language, but provides a set
9084130809Smarcelof capabilities close to what the C or assembly languages provide.
9085130809SmarcelThis should allow most simple operations to be performed while debugging
9086130809Smarcelan application that uses a language currently not supported by @value{GDBN}.
908798948Sobrien
9088130809SmarcelIf the language is set to @code{auto}, @value{GDBN} will automatically
9089130809Smarcelselect this language if the current frame corresponds to an unsupported
9090130809Smarcellanguage.
909198948Sobrien
909298948Sobrien@node Symbols
909319370Spst@chapter Examining the Symbol Table
909419370Spst
909598948SobrienThe commands described in this chapter allow you to inquire about the
909619370Spstsymbols (names of variables, functions and types) defined in your
909719370Spstprogram.  This information is inherent in the text of your program and
909819370Spstdoes not change as your program executes.  @value{GDBN} finds it in your
909919370Spstprogram's symbol table, in the file indicated when you started @value{GDBN}
910019370Spst(@pxref{File Options, ,Choosing files}), or by one of the
910119370Spstfile-management commands (@pxref{Files, ,Commands to specify files}).
910219370Spst
910319370Spst@cindex symbol names
910419370Spst@cindex names of symbols
910519370Spst@cindex quoting names
910619370SpstOccasionally, you may need to refer to symbols that contain unusual
910719370Spstcharacters, which @value{GDBN} ordinarily treats as word delimiters.  The
910819370Spstmost frequent case is in referring to static variables in other
910919370Spstsource files (@pxref{Variables,,Program variables}).  File names
911019370Spstare recorded in object files as debugging symbols, but @value{GDBN} would
911119370Spstordinarily parse a typical file name, like @file{foo.c}, as the three words
911219370Spst@samp{foo} @samp{.} @samp{c}.  To allow @value{GDBN} to recognize
911319370Spst@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
911419370Spst
9115130809Smarcel@smallexample
911619370Spstp 'foo.c'::x
9117130809Smarcel@end smallexample
911819370Spst
911919370Spst@noindent
912019370Spstlooks up the value of @code{x} in the scope of the file @file{foo.c}.
912119370Spst
912219370Spst@table @code
912319370Spst@kindex info address
912498948Sobrien@cindex address of a symbol
912519370Spst@item info address @var{symbol}
912619370SpstDescribe where the data for @var{symbol} is stored.  For a register
912719370Spstvariable, this says which register it is kept in.  For a non-register
912819370Spstlocal variable, this prints the stack-frame offset at which the variable
912919370Spstis always stored.
913019370Spst
913119370SpstNote the contrast with @samp{print &@var{symbol}}, which does not work
913219370Spstat all for a register variable, and for a stack local variable prints
913319370Spstthe exact address of the current instantiation of the variable.
913419370Spst
913598948Sobrien@kindex info symbol
913698948Sobrien@cindex symbol from address
913798948Sobrien@item info symbol @var{addr}
913898948SobrienPrint the name of a symbol which is stored at the address @var{addr}.
913998948SobrienIf no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
914098948Sobriennearest symbol and an offset from it:
914198948Sobrien
9142130809Smarcel@smallexample
914398948Sobrien(@value{GDBP}) info symbol 0x54320
914498948Sobrien_initialize_vx + 396 in section .text
9145130809Smarcel@end smallexample
914698948Sobrien
914798948Sobrien@noindent
914898948SobrienThis is the opposite of the @code{info address} command.  You can use
914998948Sobrienit to find out the name of a variable or a function given its address.
915098948Sobrien
915119370Spst@kindex whatis
915298948Sobrien@item whatis @var{expr}
915398948SobrienPrint the data type of expression @var{expr}.  @var{expr} is not
915419370Spstactually evaluated, and any side-effecting operations (such as
915519370Spstassignments or function calls) inside it do not take place.
915619370Spst@xref{Expressions, ,Expressions}.
915719370Spst
915819370Spst@item whatis
915919370SpstPrint the data type of @code{$}, the last value in the value history.
916019370Spst
916119370Spst@kindex ptype
916219370Spst@item ptype @var{typename}
916319370SpstPrint a description of data type @var{typename}.  @var{typename} may be
916498948Sobrienthe name of a type, or for C code it may have the form @samp{class
916598948Sobrien@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
916698948Sobrien@var{union-tag}} or @samp{enum @var{enum-tag}}.
916719370Spst
916898948Sobrien@item ptype @var{expr}
916919370Spst@itemx ptype
917098948SobrienPrint a description of the type of expression @var{expr}.  @code{ptype}
917119370Spstdiffers from @code{whatis} by printing a detailed description, instead
917219370Spstof just the name of the type.
917319370Spst
917419370SpstFor example, for this variable declaration:
917519370Spst
9176130809Smarcel@smallexample
917719370Spststruct complex @{double real; double imag;@} v;
9178130809Smarcel@end smallexample
917919370Spst
918019370Spst@noindent
918119370Spstthe two commands give this output:
918219370Spst
9183130809Smarcel@smallexample
918419370Spst@group
918519370Spst(@value{GDBP}) whatis v
918619370Spsttype = struct complex
918719370Spst(@value{GDBP}) ptype v
918819370Spsttype = struct complex @{
918919370Spst    double real;
919019370Spst    double imag;
919119370Spst@}
919219370Spst@end group
9193130809Smarcel@end smallexample
919419370Spst
919519370Spst@noindent
919619370SpstAs with @code{whatis}, using @code{ptype} without an argument refers to
919719370Spstthe type of @code{$}, the last value in the value history.
919819370Spst
919919370Spst@kindex info types
920019370Spst@item info types @var{regexp}
920119370Spst@itemx info types
920298948SobrienPrint a brief description of all types whose names match @var{regexp}
920319370Spst(or all types in your program, if you supply no argument).  Each
920419370Spstcomplete typename is matched as though it were a complete line; thus,
920519370Spst@samp{i type value} gives information on all types in your program whose
920698948Sobriennames include the string @code{value}, but @samp{i type ^value$} gives
920719370Spstinformation only on types whose complete name is @code{value}.
920819370Spst
920919370SpstThis command differs from @code{ptype} in two ways: first, like
921019370Spst@code{whatis}, it does not print a detailed description; second, it
921119370Spstlists all source files where a type is defined.
921219370Spst
921398948Sobrien@kindex info scope
921498948Sobrien@cindex local variables
921598948Sobrien@item info scope @var{addr}
921698948SobrienList all the variables local to a particular scope.  This command
921798948Sobrienaccepts a location---a function name, a source line, or an address
921898948Sobrienpreceded by a @samp{*}, and prints all the variables local to the
921998948Sobrienscope defined by that location.  For example:
922098948Sobrien
922198948Sobrien@smallexample
922298948Sobrien(@value{GDBP}) @b{info scope command_line_handler}
922398948SobrienScope for command_line_handler:
922498948SobrienSymbol rl is an argument at stack/frame offset 8, length 4.
922598948SobrienSymbol linebuffer is in static storage at address 0x150a18, length 4.
922698948SobrienSymbol linelength is in static storage at address 0x150a1c, length 4.
922798948SobrienSymbol p is a local variable in register $esi, length 4.
922898948SobrienSymbol p1 is a local variable in register $ebx, length 4.
922998948SobrienSymbol nline is a local variable in register $edx, length 4.
923098948SobrienSymbol repeat is a local variable at frame offset -8, length 4.
923198948Sobrien@end smallexample
923298948Sobrien
923398948Sobrien@noindent
923498948SobrienThis command is especially useful for determining what data to collect
923598948Sobrienduring a @dfn{trace experiment}, see @ref{Tracepoint Actions,
923698948Sobriencollect}.
923798948Sobrien
923819370Spst@kindex info source
923919370Spst@item info source
9240130809SmarcelShow information about the current source file---that is, the source file for
9241130809Smarcelthe function containing the current point of execution:
9242130809Smarcel@itemize @bullet
9243130809Smarcel@item
9244130809Smarcelthe name of the source file, and the directory containing it,
9245130809Smarcel@item
9246130809Smarcelthe directory it was compiled in,
9247130809Smarcel@item
9248130809Smarcelits length, in lines,
9249130809Smarcel@item
9250130809Smarcelwhich programming language it is written in,
9251130809Smarcel@item
9252130809Smarcelwhether the executable includes debugging information for that file, and
9253130809Smarcelif so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
9254130809Smarcel@item
9255130809Smarcelwhether the debugging information includes information about
9256130809Smarcelpreprocessor macros.
9257130809Smarcel@end itemize
925819370Spst
9259130809Smarcel
926019370Spst@kindex info sources
926119370Spst@item info sources
926219370SpstPrint the names of all source files in your program for which there is
926319370Spstdebugging information, organized into two lists: files whose symbols
926419370Spsthave already been read, and files whose symbols will be read when needed.
926519370Spst
926619370Spst@kindex info functions
926719370Spst@item info functions
926819370SpstPrint the names and data types of all defined functions.
926919370Spst
927019370Spst@item info functions @var{regexp}
927119370SpstPrint the names and data types of all defined functions
927219370Spstwhose names contain a match for regular expression @var{regexp}.
927319370SpstThus, @samp{info fun step} finds all functions whose names
927419370Spstinclude @code{step}; @samp{info fun ^step} finds those whose names
9275130809Smarcelstart with @code{step}.  If a function name contains characters
9276130809Smarcelthat conflict with the regular expression language (eg.
927798948Sobrien@samp{operator*()}), they may be quoted with a backslash.
927819370Spst
927919370Spst@kindex info variables
928019370Spst@item info variables
928119370SpstPrint the names and data types of all variables that are declared
928298948Sobrienoutside of functions (i.e.@: excluding local variables).
928319370Spst
928419370Spst@item info variables @var{regexp}
928519370SpstPrint the names and data types of all variables (except for local
928619370Spstvariables) whose names contain a match for regular expression
928719370Spst@var{regexp}.
928819370Spst
9289130809Smarcel@kindex info classes
9290130809Smarcel@item info classes
9291130809Smarcel@itemx info classes @var{regexp}
9292130809SmarcelDisplay all Objective-C classes in your program, or
9293130809Smarcel(with the @var{regexp} argument) all those matching a particular regular
9294130809Smarcelexpression.
9295130809Smarcel
9296130809Smarcel@kindex info selectors
9297130809Smarcel@item info selectors
9298130809Smarcel@itemx info selectors @var{regexp}
9299130809SmarcelDisplay all Objective-C selectors in your program, or
9300130809Smarcel(with the @var{regexp} argument) all those matching a particular regular
9301130809Smarcelexpression.
9302130809Smarcel
930319370Spst@ignore
930419370SpstThis was never implemented.
930519370Spst@kindex info methods
930619370Spst@item info methods
930719370Spst@itemx info methods @var{regexp}
930819370SpstThe @code{info methods} command permits the user to examine all defined
930998948Sobrienmethods within C@t{++} program, or (with the @var{regexp} argument) a
931098948Sobrienspecific set of methods found in the various C@t{++} classes.  Many
931198948SobrienC@t{++} classes provide a large number of methods.  Thus, the output
931219370Spstfrom the @code{ptype} command can be overwhelming and hard to use.  The
931319370Spst@code{info-methods} command filters the methods, printing only those
931419370Spstwhich match the regular-expression @var{regexp}.
931519370Spst@end ignore
931619370Spst
931719370Spst@cindex reloading symbols
931819370SpstSome systems allow individual object files that make up your program to
931998948Sobrienbe replaced without stopping and restarting your program.  For example,
932098948Sobrienin VxWorks you can simply recompile a defective object file and keep on
932198948Sobrienrunning.  If you are running on one of these systems, you can allow
932298948Sobrien@value{GDBN} to reload the symbols for automatically relinked modules:
932319370Spst
932419370Spst@table @code
932519370Spst@kindex set symbol-reloading
932619370Spst@item set symbol-reloading on
932719370SpstReplace symbol definitions for the corresponding source file when an
932819370Spstobject file with a particular name is seen again.
932919370Spst
933019370Spst@item set symbol-reloading off
933198948SobrienDo not replace symbol definitions when encountering object files of the
933298948Sobriensame name more than once.  This is the default state; if you are not
933398948Sobrienrunning on a system that permits automatic relinking of modules, you
933498948Sobrienshould leave @code{symbol-reloading} off, since otherwise @value{GDBN}
933598948Sobrienmay discard symbols when linking large programs, that may contain
933698948Sobrienseveral modules (from different directories or libraries) with the same
933798948Sobrienname.
933819370Spst
933919370Spst@kindex show symbol-reloading
934019370Spst@item show symbol-reloading
934119370SpstShow the current @code{on} or @code{off} setting.
934219370Spst@end table
934319370Spst
934446289Sdfr@kindex set opaque-type-resolution
934546289Sdfr@item set opaque-type-resolution on
934646289SdfrTell @value{GDBN} to resolve opaque types.  An opaque type is a type
934746289Sdfrdeclared as a pointer to a @code{struct}, @code{class}, or
934846289Sdfr@code{union}---for example, @code{struct MyType *}---that is used in one
934946289Sdfrsource file although the full declaration of @code{struct MyType} is in
935046289Sdfranother source file.  The default is on.
935146289Sdfr
935246289SdfrA change in the setting of this subcommand will not take effect until
935346289Sdfrthe next time symbols for a file are loaded.
935446289Sdfr
935546289Sdfr@item set opaque-type-resolution off
935646289SdfrTell @value{GDBN} not to resolve opaque types.  In this case, the type
935746289Sdfris printed as follows:
935846289Sdfr@smallexample
935946289Sdfr@{<no data fields>@}
936046289Sdfr@end smallexample
936146289Sdfr
936246289Sdfr@kindex show opaque-type-resolution
936346289Sdfr@item show opaque-type-resolution
936446289SdfrShow whether opaque types are resolved or not.
936546289Sdfr
936619370Spst@kindex maint print symbols
936719370Spst@cindex symbol dump
936819370Spst@kindex maint print psymbols
936919370Spst@cindex partial symbol dump
937019370Spst@item maint print symbols @var{filename}
937119370Spst@itemx maint print psymbols @var{filename}
937219370Spst@itemx maint print msymbols @var{filename}
937319370SpstWrite a dump of debugging symbol data into the file @var{filename}.
937419370SpstThese commands are used to debug the @value{GDBN} symbol-reading code.  Only
937519370Spstsymbols with debugging data are included.  If you use @samp{maint print
937619370Spstsymbols}, @value{GDBN} includes all the symbols for which it has already
937719370Spstcollected full details: that is, @var{filename} reflects symbols for
937819370Spstonly those files whose symbols @value{GDBN} has read.  You can use the
937919370Spstcommand @code{info sources} to find out which files these are.  If you
938019370Spstuse @samp{maint print psymbols} instead, the dump shows information about
938119370Spstsymbols that @value{GDBN} only knows partially---that is, symbols defined in
938219370Spstfiles that @value{GDBN} has skimmed, but not yet read completely.  Finally,
938319370Spst@samp{maint print msymbols} dumps just the minimal symbol information
938419370Spstrequired for each object file from which @value{GDBN} has read some symbols.
938519370Spst@xref{Files, ,Commands to specify files}, for a discussion of how
938619370Spst@value{GDBN} reads symbols (in the description of @code{symbol-file}).
9387130809Smarcel
9388130809Smarcel@kindex maint info symtabs
9389130809Smarcel@kindex maint info psymtabs
9390130809Smarcel@cindex listing @value{GDBN}'s internal symbol tables
9391130809Smarcel@cindex symbol tables, listing @value{GDBN}'s internal
9392130809Smarcel@cindex full symbol tables, listing @value{GDBN}'s internal
9393130809Smarcel@cindex partial symbol tables, listing @value{GDBN}'s internal
9394130809Smarcel@item maint info symtabs @r{[} @var{regexp} @r{]}
9395130809Smarcel@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
9396130809Smarcel
9397130809SmarcelList the @code{struct symtab} or @code{struct partial_symtab}
9398130809Smarcelstructures whose names match @var{regexp}.  If @var{regexp} is not
9399130809Smarcelgiven, list them all.  The output includes expressions which you can
9400130809Smarcelcopy into a @value{GDBN} debugging this one to examine a particular
9401130809Smarcelstructure in more detail.  For example:
9402130809Smarcel
9403130809Smarcel@smallexample
9404130809Smarcel(@value{GDBP}) maint info psymtabs dwarf2read
9405130809Smarcel@{ objfile /home/gnu/build/gdb/gdb
9406130809Smarcel  ((struct objfile *) 0x82e69d0)
9407130809Smarcel  @{ psymtab /home/gnu/src/gdb/dwarf2read.c
9408130809Smarcel    ((struct partial_symtab *) 0x8474b10)
9409130809Smarcel    readin no
9410130809Smarcel    fullname (null)
9411130809Smarcel    text addresses 0x814d3c8 -- 0x8158074
9412130809Smarcel    globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
9413130809Smarcel    statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
9414130809Smarcel    dependencies (none)
9415130809Smarcel  @}
9416130809Smarcel@}
9417130809Smarcel(@value{GDBP}) maint info symtabs
9418130809Smarcel(@value{GDBP})
9419130809Smarcel@end smallexample
9420130809Smarcel@noindent
9421130809SmarcelWe see that there is one partial symbol table whose filename contains
9422130809Smarcelthe string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
9423130809Smarceland we see that @value{GDBN} has not read in any symtabs yet at all.
9424130809SmarcelIf we set a breakpoint on a function, that will cause @value{GDBN} to
9425130809Smarcelread the symtab for the compilation unit containing that function:
9426130809Smarcel
9427130809Smarcel@smallexample
9428130809Smarcel(@value{GDBP}) break dwarf2_psymtab_to_symtab
9429130809SmarcelBreakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
9430130809Smarcelline 1574.
9431130809Smarcel(@value{GDBP}) maint info symtabs
9432130809Smarcel@{ objfile /home/gnu/build/gdb/gdb
9433130809Smarcel  ((struct objfile *) 0x82e69d0)
9434130809Smarcel  @{ symtab /home/gnu/src/gdb/dwarf2read.c
9435130809Smarcel    ((struct symtab *) 0x86c1f38)
9436130809Smarcel    dirname (null)
9437130809Smarcel    fullname (null)
9438130809Smarcel    blockvector ((struct blockvector *) 0x86c1bd0) (primary)
9439130809Smarcel    debugformat DWARF 2
9440130809Smarcel  @}
9441130809Smarcel@}
9442130809Smarcel(@value{GDBP})
9443130809Smarcel@end smallexample
944419370Spst@end table
944519370Spst
9446130809Smarcel
944798948Sobrien@node Altering
944819370Spst@chapter Altering Execution
944919370Spst
945019370SpstOnce you think you have found an error in your program, you might want to
945119370Spstfind out for certain whether correcting the apparent error would lead to
945219370Spstcorrect results in the rest of the run.  You can find the answer by
945319370Spstexperiment, using the @value{GDBN} features for altering execution of the
945419370Spstprogram.
945519370Spst
945619370SpstFor example, you can store new values into variables or memory
945798948Sobrienlocations, give your program a signal, restart it at a different
945898948Sobrienaddress, or even return prematurely from a function.
945919370Spst
946019370Spst@menu
946119370Spst* Assignment::                  Assignment to variables
946219370Spst* Jumping::                     Continuing at a different address
946319370Spst* Signaling::                   Giving your program a signal
946419370Spst* Returning::                   Returning from a function
946519370Spst* Calling::                     Calling your program's functions
946619370Spst* Patching::                    Patching your program
946719370Spst@end menu
946819370Spst
946998948Sobrien@node Assignment
947019370Spst@section Assignment to variables
947119370Spst
947219370Spst@cindex assignment
947319370Spst@cindex setting variables
947419370SpstTo alter the value of a variable, evaluate an assignment expression.
947519370Spst@xref{Expressions, ,Expressions}.  For example,
947619370Spst
9477130809Smarcel@smallexample
947819370Spstprint x=4
9479130809Smarcel@end smallexample
948019370Spst
948119370Spst@noindent
948219370Spststores the value 4 into the variable @code{x}, and then prints the
948398948Sobrienvalue of the assignment expression (which is 4).
948419370Spst@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
948519370Spstinformation on operators in supported languages.
948619370Spst
948719370Spst@kindex set variable
948819370Spst@cindex variables, setting
948919370SpstIf you are not interested in seeing the value of the assignment, use the
949019370Spst@code{set} command instead of the @code{print} command.  @code{set} is
949119370Spstreally the same as @code{print} except that the expression's value is
949219370Spstnot printed and is not put in the value history (@pxref{Value History,
949319370Spst,Value history}).  The expression is evaluated only for its effects.
949419370Spst
949519370SpstIf the beginning of the argument string of the @code{set} command
949619370Spstappears identical to a @code{set} subcommand, use the @code{set
949719370Spstvariable} command instead of just @code{set}.  This command is identical
949846289Sdfrto @code{set} except for its lack of subcommands.  For example, if your
949946289Sdfrprogram has a variable @code{width}, you get an error if you try to set
950046289Sdfra new value with just @samp{set width=13}, because @value{GDBN} has the
950146289Sdfrcommand @code{set width}:
950219370Spst
9503130809Smarcel@smallexample
950419370Spst(@value{GDBP}) whatis width
950519370Spsttype = double
950619370Spst(@value{GDBP}) p width
950719370Spst$4 = 13
950819370Spst(@value{GDBP}) set width=47
950919370SpstInvalid syntax in expression.
9510130809Smarcel@end smallexample
951119370Spst
951219370Spst@noindent
951319370SpstThe invalid expression, of course, is @samp{=47}.  In
951419370Spstorder to actually set the program's variable @code{width}, use
951519370Spst
9516130809Smarcel@smallexample
951719370Spst(@value{GDBP}) set var width=47
9518130809Smarcel@end smallexample
951998948Sobrien
952046289SdfrBecause the @code{set} command has many subcommands that can conflict
952146289Sdfrwith the names of program variables, it is a good idea to use the
952246289Sdfr@code{set variable} command instead of just @code{set}.  For example, if
952346289Sdfryour program has a variable @code{g}, you run into problems if you try
952446289Sdfrto set a new value with just @samp{set g=4}, because @value{GDBN} has
952546289Sdfrthe command @code{set gnutarget}, abbreviated @code{set g}:
952619370Spst
9527130809Smarcel@smallexample
952846289Sdfr@group
952946289Sdfr(@value{GDBP}) whatis g
953046289Sdfrtype = double
953146289Sdfr(@value{GDBP}) p g
953246289Sdfr$1 = 1
953346289Sdfr(@value{GDBP}) set g=4
953498948Sobrien(@value{GDBP}) p g
953546289Sdfr$2 = 1
953646289Sdfr(@value{GDBP}) r
953746289SdfrThe program being debugged has been started already.
953846289SdfrStart it from the beginning? (y or n) y
953946289SdfrStarting program: /home/smith/cc_progs/a.out
954098948Sobrien"/home/smith/cc_progs/a.out": can't open to read symbols:
954198948Sobrien                                 Invalid bfd target.
954246289Sdfr(@value{GDBP}) show g
954346289SdfrThe current BFD target is "=4".
954446289Sdfr@end group
9545130809Smarcel@end smallexample
954646289Sdfr
954746289Sdfr@noindent
954846289SdfrThe program variable @code{g} did not change, and you silently set the
954946289Sdfr@code{gnutarget} to an invalid value.  In order to set the variable
955046289Sdfr@code{g}, use
955146289Sdfr
9552130809Smarcel@smallexample
955346289Sdfr(@value{GDBP}) set var g=4
9554130809Smarcel@end smallexample
955546289Sdfr
955619370Spst@value{GDBN} allows more implicit conversions in assignments than C; you can
955719370Spstfreely store an integer value into a pointer variable or vice versa,
955819370Spstand you can convert any structure to any other structure that is the
955919370Spstsame length or shorter.
956019370Spst@comment FIXME: how do structs align/pad in these conversions?
956119370Spst@comment        /doc@cygnus.com 18dec1990
956219370Spst
956319370SpstTo store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
956419370Spstconstruct to generate a value of specified type at a specified address
956519370Spst(@pxref{Expressions, ,Expressions}).  For example, @code{@{int@}0x83040} refers
956619370Spstto memory location @code{0x83040} as an integer (which implies a certain size
956719370Spstand representation in memory), and
956819370Spst
9569130809Smarcel@smallexample
957019370Spstset @{int@}0x83040 = 4
9571130809Smarcel@end smallexample
957219370Spst
957319370Spst@noindent
957419370Spststores the value 4 into that memory location.
957519370Spst
957698948Sobrien@node Jumping
957719370Spst@section Continuing at a different address
957819370Spst
957919370SpstOrdinarily, when you continue your program, you do so at the place where
958019370Spstit stopped, with the @code{continue} command.  You can instead continue at
958119370Spstan address of your own choosing, with the following commands:
958219370Spst
958319370Spst@table @code
958419370Spst@kindex jump
958519370Spst@item jump @var{linespec}
958619370SpstResume execution at line @var{linespec}.  Execution stops again
958719370Spstimmediately if there is a breakpoint there.  @xref{List, ,Printing
958819370Spstsource lines}, for a description of the different forms of
958946289Sdfr@var{linespec}.  It is common practice to use the @code{tbreak} command
959046289Sdfrin conjunction with @code{jump}.  @xref{Set Breaks, ,Setting
959146289Sdfrbreakpoints}.
959219370Spst
959319370SpstThe @code{jump} command does not change the current stack frame, or
959419370Spstthe stack pointer, or the contents of any memory location or any
959519370Spstregister other than the program counter.  If line @var{linespec} is in
959619370Spsta different function from the one currently executing, the results may
959719370Spstbe bizarre if the two functions expect different patterns of arguments or
959819370Spstof local variables.  For this reason, the @code{jump} command requests
959919370Spstconfirmation if the specified line is not in the function currently
960019370Spstexecuting.  However, even bizarre results are predictable if you are
960119370Spstwell acquainted with the machine-language code of your program.
960219370Spst
960319370Spst@item jump *@var{address}
960419370SpstResume execution at the instruction at address @var{address}.
960519370Spst@end table
960619370Spst
960746289Sdfr@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
960898948SobrienOn many systems, you can get much the same effect as the @code{jump}
960998948Sobriencommand by storing a new value into the register @code{$pc}.  The
961098948Sobriendifference is that this does not start your program running; it only
961198948Sobrienchanges the address of where it @emph{will} run when you continue.  For
961298948Sobrienexample,
961319370Spst
9614130809Smarcel@smallexample
961519370Spstset $pc = 0x485
9616130809Smarcel@end smallexample
961719370Spst
961819370Spst@noindent
961919370Spstmakes the next @code{continue} command or stepping command execute at
962019370Spstaddress @code{0x485}, rather than at the address where your program stopped.
962119370Spst@xref{Continuing and Stepping, ,Continuing and stepping}.
962219370Spst
962346289SdfrThe most common occasion to use the @code{jump} command is to back
962446289Sdfrup---perhaps with more breakpoints set---over a portion of a program
962546289Sdfrthat has already executed, in order to examine its execution in more
962646289Sdfrdetail.
962719370Spst
962819370Spst@c @group
962998948Sobrien@node Signaling
963019370Spst@section Giving your program a signal
963119370Spst
963219370Spst@table @code
963319370Spst@kindex signal
963419370Spst@item signal @var{signal}
963519370SpstResume execution where your program stopped, but immediately give it the
963619370Spstsignal @var{signal}.  @var{signal} can be the name or the number of a
963719370Spstsignal.  For example, on many systems @code{signal 2} and @code{signal
963819370SpstSIGINT} are both ways of sending an interrupt signal.
963919370Spst
964019370SpstAlternatively, if @var{signal} is zero, continue execution without
964119370Spstgiving a signal.  This is useful when your program stopped on account of
964219370Spsta signal and would ordinary see the signal when resumed with the
964319370Spst@code{continue} command; @samp{signal 0} causes it to resume without a
964419370Spstsignal.
964519370Spst
964619370Spst@code{signal} does not repeat when you press @key{RET} a second time
964719370Spstafter executing the command.
964819370Spst@end table
964919370Spst@c @end group
965019370Spst
965119370SpstInvoking the @code{signal} command is not the same as invoking the
965219370Spst@code{kill} utility from the shell.  Sending a signal with @code{kill}
965319370Spstcauses @value{GDBN} to decide what to do with the signal depending on
965419370Spstthe signal handling tables (@pxref{Signals}).  The @code{signal} command
965519370Spstpasses the signal directly to your program.
965619370Spst
965719370Spst
965898948Sobrien@node Returning
965919370Spst@section Returning from a function
966019370Spst
966119370Spst@table @code
966219370Spst@cindex returning from a function
966319370Spst@kindex return
966419370Spst@item return
966519370Spst@itemx return @var{expression}
966619370SpstYou can cancel execution of a function call with the @code{return}
966719370Spstcommand.  If you give an
966819370Spst@var{expression} argument, its value is used as the function's return
966919370Spstvalue.
967019370Spst@end table
967119370Spst
967219370SpstWhen you use @code{return}, @value{GDBN} discards the selected stack frame
967319370Spst(and all frames within it).  You can think of this as making the
967419370Spstdiscarded frame return prematurely.  If you wish to specify a value to
967519370Spstbe returned, give that value as the argument to @code{return}.
967619370Spst
967719370SpstThis pops the selected stack frame (@pxref{Selection, ,Selecting a
967819370Spstframe}), and any other frames inside of it, leaving its caller as the
967919370Spstinnermost remaining frame.  That frame becomes selected.  The
968019370Spstspecified value is stored in the registers used for returning values
968119370Spstof functions.
968219370Spst
968319370SpstThe @code{return} command does not resume execution; it leaves the
968419370Spstprogram stopped in the state that would exist if the function had just
968519370Spstreturned.  In contrast, the @code{finish} command (@pxref{Continuing
968619370Spstand Stepping, ,Continuing and stepping}) resumes execution until the
968719370Spstselected stack frame returns naturally.
968819370Spst
968998948Sobrien@node Calling
969019370Spst@section Calling program functions
969119370Spst
969219370Spst@cindex calling functions
969319370Spst@kindex call
969419370Spst@table @code
969519370Spst@item call @var{expr}
969619370SpstEvaluate the expression @var{expr} without displaying @code{void}
969719370Spstreturned values.
969819370Spst@end table
969919370Spst
970019370SpstYou can use this variant of the @code{print} command if you want to
970119370Spstexecute a function from your program, but without cluttering the output
970298948Sobrienwith @code{void} returned values.  If the result is not void, it
970398948Sobrienis printed and saved in the value history.
970419370Spst
970598948Sobrien@node Patching
970619370Spst@section Patching programs
970798948Sobrien
970819370Spst@cindex patching binaries
970919370Spst@cindex writing into executables
971019370Spst@cindex writing into corefiles
971119370Spst
971298948SobrienBy default, @value{GDBN} opens the file containing your program's
971398948Sobrienexecutable code (or the corefile) read-only.  This prevents accidental
971498948Sobrienalterations to machine code; but it also prevents you from intentionally
971598948Sobrienpatching your program's binary.
971619370Spst
971719370SpstIf you'd like to be able to patch the binary, you can specify that
971819370Spstexplicitly with the @code{set write} command.  For example, you might
971919370Spstwant to turn on internal debugging flags, or even to make emergency
972019370Spstrepairs.
972119370Spst
972219370Spst@table @code
972319370Spst@kindex set write
972419370Spst@item set write on
972519370Spst@itemx set write off
972698948SobrienIf you specify @samp{set write on}, @value{GDBN} opens executable and
972798948Sobriencore files for both reading and writing; if you specify @samp{set write
972819370Spstoff} (the default), @value{GDBN} opens them read-only.
972919370Spst
973019370SpstIf you have already loaded a file, you must load it again (using the
973198948Sobrien@code{exec-file} or @code{core-file} command) after changing @code{set
973298948Sobrienwrite}, for your new setting to take effect.
973319370Spst
973419370Spst@item show write
973519370Spst@kindex show write
973698948SobrienDisplay whether executable files and core files are opened for writing
973798948Sobrienas well as reading.
973819370Spst@end table
973919370Spst
974098948Sobrien@node GDB Files
974119370Spst@chapter @value{GDBN} Files
974219370Spst
974398948Sobrien@value{GDBN} needs to know the file name of the program to be debugged,
974498948Sobrienboth in order to read its symbol table and in order to start your
974598948Sobrienprogram.  To debug a core dump of a previous run, you must also tell
974698948Sobrien@value{GDBN} the name of the core dump file.
974719370Spst
974819370Spst@menu
974919370Spst* Files::                       Commands to specify files
9750130809Smarcel* Separate Debug Files::        Debugging information in separate files
975119370Spst* Symbol Errors::               Errors reading symbol files
975219370Spst@end menu
975319370Spst
975498948Sobrien@node Files
975519370Spst@section Commands to specify files
975698948Sobrien
975719370Spst@cindex symbol table
975819370Spst@cindex core dump file
975919370Spst
976098948SobrienYou may want to specify executable and core dump file names.  The usual
976198948Sobrienway to do this is at start-up time, using the arguments to
976298948Sobrien@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
976398948SobrienOut of @value{GDBN}}).
976498948Sobrien
976519370SpstOccasionally it is necessary to change to a different file during a
976619370Spst@value{GDBN} session.  Or you may run @value{GDBN} and forget to specify
976719370Spsta file you want to use.  In these situations the @value{GDBN} commands
976819370Spstto specify new files are useful.
976919370Spst
977019370Spst@table @code
977119370Spst@cindex executable file
977219370Spst@kindex file
977319370Spst@item file @var{filename}
977419370SpstUse @var{filename} as the program to be debugged.  It is read for its
977519370Spstsymbols and for the contents of pure memory.  It is also the program
977619370Spstexecuted when you use the @code{run} command.  If you do not specify a
977798948Sobriendirectory and the file is not found in the @value{GDBN} working directory,
977898948Sobrien@value{GDBN} uses the environment variable @code{PATH} as a list of
977998948Sobriendirectories to search, just as the shell does when looking for a program
978098948Sobriento run.  You can change the value of this variable, for both @value{GDBN}
978119370Spstand your program, using the @code{path} command.
978219370Spst
978398948SobrienOn systems with memory-mapped files, an auxiliary file named
978419370Spst@file{@var{filename}.syms} may hold symbol table information for
978519370Spst@var{filename}.  If so, @value{GDBN} maps in the symbol table from
978619370Spst@file{@var{filename}.syms}, starting up more quickly.  See the
978719370Spstdescriptions of the file options @samp{-mapped} and @samp{-readnow}
978819370Spst(available on the command line, and with the commands @code{file},
978998948Sobrien@code{symbol-file}, or @code{add-symbol-file}, described below),
979019370Spstfor more information.
979119370Spst
979219370Spst@item file
979319370Spst@code{file} with no argument makes @value{GDBN} discard any information it
979419370Spsthas on both executable file and the symbol table.
979519370Spst
979619370Spst@kindex exec-file
979719370Spst@item exec-file @r{[} @var{filename} @r{]}
979819370SpstSpecify that the program to be run (but not the symbol table) is found
979919370Spstin @var{filename}.  @value{GDBN} searches the environment variable @code{PATH}
980019370Spstif necessary to locate your program.  Omitting @var{filename} means to
980119370Spstdiscard information on the executable file.
980219370Spst
980319370Spst@kindex symbol-file
980419370Spst@item symbol-file @r{[} @var{filename} @r{]}
980519370SpstRead symbol table information from file @var{filename}.  @code{PATH} is
980619370Spstsearched when necessary.  Use the @code{file} command to get both symbol
980719370Spsttable and program to run from the same file.
980819370Spst
980919370Spst@code{symbol-file} with no argument clears out @value{GDBN} information on your
981019370Spstprogram's symbol table.
981119370Spst
981298948SobrienThe @code{symbol-file} command causes @value{GDBN} to forget the contents
981319370Spstof its convenience variables, the value history, and all breakpoints and
981419370Spstauto-display expressions.  This is because they may contain pointers to
981519370Spstthe internal data recording symbols and data types, which are part of
981619370Spstthe old symbol table data being discarded inside @value{GDBN}.
981719370Spst
981819370Spst@code{symbol-file} does not repeat if you press @key{RET} again after
981919370Spstexecuting it once.
982019370Spst
982119370SpstWhen @value{GDBN} is configured for a particular environment, it
982219370Spstunderstands debugging information in whatever format is the standard
982319370Spstgenerated for that environment; you may use either a @sc{gnu} compiler, or
982446289Sdfrother compilers that adhere to the local conventions.
982546289SdfrBest results are usually obtained from @sc{gnu} compilers; for example,
982646289Sdfrusing @code{@value{GCC}} you can generate debugging information for
982746289Sdfroptimized code.
982819370Spst
982946289SdfrFor most kinds of object files, with the exception of old SVR3 systems
983046289Sdfrusing COFF, the @code{symbol-file} command does not normally read the
983146289Sdfrsymbol table in full right away.  Instead, it scans the symbol table
983246289Sdfrquickly to find which source files and which symbols are present.  The
983346289Sdfrdetails are read later, one source file at a time, as they are needed.
983419370Spst
983546289SdfrThe purpose of this two-stage reading strategy is to make @value{GDBN}
983646289Sdfrstart up faster.  For the most part, it is invisible except for
983746289Sdfroccasional pauses while the symbol table details for a particular source
983846289Sdfrfile are being read.  (The @code{set verbose} command can turn these
983946289Sdfrpauses into messages if desired.  @xref{Messages/Warnings, ,Optional
984046289Sdfrwarnings and messages}.)
984119370Spst
984219370SpstWe have not implemented the two-stage strategy for COFF yet.  When the
984319370Spstsymbol table is stored in COFF format, @code{symbol-file} reads the
984446289Sdfrsymbol table data in full right away.  Note that ``stabs-in-COFF''
984546289Sdfrstill does the two-stage strategy, since the debug info is actually
984646289Sdfrin stabs format.
984719370Spst
984819370Spst@kindex readnow
984919370Spst@cindex reading symbols immediately
985019370Spst@cindex symbols, reading immediately
985119370Spst@kindex mapped
985219370Spst@cindex memory-mapped symbol file
985319370Spst@cindex saving symbol table
985419370Spst@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
985519370Spst@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
985619370SpstYou can override the @value{GDBN} two-stage strategy for reading symbol
985719370Spsttables by using the @samp{-readnow} option with any of the commands that
985819370Spstload symbol table information, if you want to be sure @value{GDBN} has the
985998948Sobrienentire symbol table available.
986019370Spst
986119370SpstIf memory-mapped files are available on your system through the
986219370Spst@code{mmap} system call, you can use another option, @samp{-mapped}, to
986319370Spstcause @value{GDBN} to write the symbols for your program into a reusable
986419370Spstfile.  Future @value{GDBN} debugging sessions map in symbol information
986519370Spstfrom this auxiliary symbol file (if the program has not changed), rather
986619370Spstthan spending time reading the symbol table from the executable
986719370Spstprogram.  Using the @samp{-mapped} option has the same effect as
986819370Spststarting @value{GDBN} with the @samp{-mapped} command-line option.
986919370Spst
987019370SpstYou can use both options together, to make sure the auxiliary symbol
987119370Spstfile has all the symbol information for your program.
987219370Spst
987319370SpstThe auxiliary symbol file for a program called @var{myprog} is called
987419370Spst@samp{@var{myprog}.syms}.  Once this file exists (so long as it is newer
987519370Spstthan the corresponding executable), @value{GDBN} always attempts to use
987619370Spstit when you debug @var{myprog}; no special options or commands are
987719370Spstneeded.
987819370Spst
987919370SpstThe @file{.syms} file is specific to the host machine where you run
988019370Spst@value{GDBN}.  It holds an exact image of the internal @value{GDBN}
988119370Spstsymbol table.  It cannot be shared across multiple host platforms.
988219370Spst
988319370Spst@c FIXME: for now no mention of directories, since this seems to be in
988419370Spst@c flux.  13mar1992 status is that in theory GDB would look either in
988519370Spst@c current dir or in same dir as myprog; but issues like competing
988619370Spst@c GDB's, or clutter in system dirs, mean that in practice right now
988719370Spst@c only current dir is used.  FFish says maybe a special GDB hierarchy
988819370Spst@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
988919370Spst@c files.
989019370Spst
989119370Spst@kindex core
989219370Spst@kindex core-file
989319370Spst@item core-file @r{[} @var{filename} @r{]}
989419370SpstSpecify the whereabouts of a core dump file to be used as the ``contents
989519370Spstof memory''.  Traditionally, core files contain only some parts of the
989619370Spstaddress space of the process that generated them; @value{GDBN} can access the
989719370Spstexecutable file itself for other parts.
989819370Spst
989919370Spst@code{core-file} with no argument specifies that no core file is
990019370Spstto be used.
990119370Spst
990219370SpstNote that the core file is ignored when your program is actually running
990398948Sobrienunder @value{GDBN}.  So, if you have been running your program and you
990498948Sobrienwish to debug a core file instead, you must kill the subprocess in which
990598948Sobrienthe program is running.  To do this, use the @code{kill} command
990619370Spst(@pxref{Kill Process, ,Killing the child process}).
990719370Spst
990819370Spst@kindex add-symbol-file
990919370Spst@cindex dynamic linking
991019370Spst@item add-symbol-file @var{filename} @var{address}
991119370Spst@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
991298948Sobrien@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
991398948SobrienThe @code{add-symbol-file} command reads additional symbol table
991498948Sobrieninformation from the file @var{filename}.  You would use this command
991598948Sobrienwhen @var{filename} has been dynamically loaded (by some other means)
991698948Sobrieninto the program that is running.  @var{address} should be the memory
991798948Sobrienaddress at which the file has been loaded; @value{GDBN} cannot figure
991898948Sobrienthis out for itself.  You can additionally specify an arbitrary number
991998948Sobrienof @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
992098948Sobriensection name and base address for that section.  You can specify any
992198948Sobrien@var{address} as an expression.
992219370Spst
992319370SpstThe symbol table of the file @var{filename} is added to the symbol table
992419370Spstoriginally read with the @code{symbol-file} command.  You can use the
992598948Sobrien@code{add-symbol-file} command any number of times; the new symbol data
992698948Sobrienthus read keeps adding to the old.  To discard all old symbol data
992798948Sobrieninstead, use the @code{symbol-file} command without any arguments.
992819370Spst
992998948Sobrien@cindex relocatable object files, reading symbols from
993098948Sobrien@cindex object files, relocatable, reading symbols from
993198948Sobrien@cindex reading symbols from relocatable object files
993298948Sobrien@cindex symbols, reading from relocatable object files
993398948Sobrien@cindex @file{.o} files, reading symbols from
993498948SobrienAlthough @var{filename} is typically a shared library file, an
993598948Sobrienexecutable file, or some other object file which has been fully
993698948Sobrienrelocated for loading into a process, you can also load symbolic
993798948Sobrieninformation from relocatable @file{.o} files, as long as:
993898948Sobrien
993998948Sobrien@itemize @bullet
994098948Sobrien@item
994198948Sobrienthe file's symbolic information refers only to linker symbols defined in
994298948Sobrienthat file, not to symbols defined by other object files,
994398948Sobrien@item
994498948Sobrienevery section the file's symbolic information refers to has actually
994598948Sobrienbeen loaded into the inferior, as it appears in the file, and
994698948Sobrien@item
994798948Sobrienyou can determine the address at which every section was loaded, and
994898948Sobrienprovide these to the @code{add-symbol-file} command.
994998948Sobrien@end itemize
995098948Sobrien
995198948Sobrien@noindent
995298948SobrienSome embedded operating systems, like Sun Chorus and VxWorks, can load
995398948Sobrienrelocatable files into an already running program; such systems
995498948Sobrientypically make the requirements above easy to meet.  However, it's
995598948Sobrienimportant to recognize that many native systems use complex link
9956130809Smarcelprocedures (@code{.linkonce} section factoring and C@t{++} constructor table
995798948Sobrienassembly, for example) that make the requirements difficult to meet.  In
995898948Sobriengeneral, one cannot assume that using @code{add-symbol-file} to read a
995998948Sobrienrelocatable object file's symbolic information will have the same effect
996098948Sobrienas linking the relocatable object file into the program in the normal
996198948Sobrienway.
996298948Sobrien
996319370Spst@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
996419370Spst
996519370SpstYou can use the @samp{-mapped} and @samp{-readnow} options just as with
996619370Spstthe @code{symbol-file} command, to change how @value{GDBN} manages the symbol
996719370Spsttable information for @var{filename}.
996819370Spst
996919370Spst@kindex add-shared-symbol-file
997019370Spst@item add-shared-symbol-file
997119370SpstThe @code{add-shared-symbol-file} command can be used only under Harris' CXUX
997298948Sobrienoperating system for the Motorola 88k.  @value{GDBN} automatically looks for
997398948Sobrienshared libraries, however if @value{GDBN} does not find yours, you can run
997419370Spst@code{add-shared-symbol-file}.  It takes no arguments.
997519370Spst
997619370Spst@kindex section
997719370Spst@item section
997898948SobrienThe @code{section} command changes the base address of section SECTION of
997998948Sobrienthe exec file to ADDR.  This can be used if the exec file does not contain
998098948Sobriensection addresses, (such as in the a.out format), or when the addresses
998198948Sobrienspecified in the file itself are wrong.  Each section must be changed
998298948Sobrienseparately.  The @code{info files} command, described below, lists all
998398948Sobrienthe sections and their addresses.
998419370Spst
998519370Spst@kindex info files
998619370Spst@kindex info target
998719370Spst@item info files
998819370Spst@itemx info target
998998948Sobrien@code{info files} and @code{info target} are synonymous; both print the
999098948Sobriencurrent target (@pxref{Targets, ,Specifying a Debugging Target}),
999198948Sobrienincluding the names of the executable and core dump files currently in
999298948Sobrienuse by @value{GDBN}, and the files from which symbols were loaded.  The
999398948Sobriencommand @code{help target} lists all possible targets rather than
999498948Sobriencurrent ones.
999598948Sobrien
999698948Sobrien@kindex maint info sections
999798948Sobrien@item maint info sections
999898948SobrienAnother command that can give you extra information about program sections
999998948Sobrienis @code{maint info sections}.  In addition to the section information
1000098948Sobriendisplayed by @code{info files}, this command displays the flags and file
1000198948Sobrienoffset of each section in the executable and core dump files.  In addition,
1000298948Sobrien@code{maint info sections} provides the following command options (which
1000398948Sobrienmay be arbitrarily combined):
1000498948Sobrien
1000598948Sobrien@table @code
1000698948Sobrien@item ALLOBJ
1000798948SobrienDisplay sections for all loaded object files, including shared libraries.
1000898948Sobrien@item @var{sections}
1000998948SobrienDisplay info only for named @var{sections}.
1001098948Sobrien@item @var{section-flags}
1001198948SobrienDisplay info only for sections for which @var{section-flags} are true.
1001298948SobrienThe section flags that @value{GDBN} currently knows about are:
1001398948Sobrien@table @code
1001498948Sobrien@item ALLOC
1001598948SobrienSection will have space allocated in the process when loaded.
1001698948SobrienSet for all sections except those containing debug information.
1001798948Sobrien@item LOAD
1001898948SobrienSection will be loaded from the file into the child process memory.
1001998948SobrienSet for pre-initialized code and data, clear for @code{.bss} sections.
1002098948Sobrien@item RELOC
1002198948SobrienSection needs to be relocated before loading.
1002298948Sobrien@item READONLY
1002398948SobrienSection cannot be modified by the child process.
1002498948Sobrien@item CODE
1002598948SobrienSection contains executable code only.
1002698948Sobrien@item DATA
1002798948SobrienSection contains data only (no executable code).
1002898948Sobrien@item ROM
1002998948SobrienSection will reside in ROM.
1003098948Sobrien@item CONSTRUCTOR
1003198948SobrienSection contains data for constructor/destructor lists.
1003298948Sobrien@item HAS_CONTENTS
1003398948SobrienSection is not empty.
1003498948Sobrien@item NEVER_LOAD
1003598948SobrienAn instruction to the linker to not output the section.
1003698948Sobrien@item COFF_SHARED_LIBRARY
1003798948SobrienA notification to the linker that the section contains
1003898948SobrienCOFF shared library information.
1003998948Sobrien@item IS_COMMON
1004098948SobrienSection contains common symbols.
1004119370Spst@end table
1004298948Sobrien@end table
1004398948Sobrien@kindex set trust-readonly-sections
1004498948Sobrien@item set trust-readonly-sections on
1004598948SobrienTell @value{GDBN} that readonly sections in your object file
1004698948Sobrienreally are read-only (i.e.@: that their contents will not change).
1004798948SobrienIn that case, @value{GDBN} can fetch values from these sections
1004898948Sobrienout of the object file, rather than from the target program.
1004998948SobrienFor some targets (notably embedded ones), this can be a significant
1005098948Sobrienenhancement to debugging performance.
1005119370Spst
1005298948SobrienThe default is off.
1005398948Sobrien
1005498948Sobrien@item set trust-readonly-sections off
1005598948SobrienTell @value{GDBN} not to trust readonly sections.  This means that
1005698948Sobrienthe contents of the section might change while the program is running,
1005798948Sobrienand must therefore be fetched from the target when needed.
1005898948Sobrien@end table
1005998948Sobrien
1006019370SpstAll file-specifying commands allow both absolute and relative file names
1006119370Spstas arguments.  @value{GDBN} always converts the file name to an absolute file
1006219370Spstname and remembers it that way.
1006319370Spst
1006419370Spst@cindex shared libraries
1006546289Sdfr@value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
1006646289Sdfrlibraries.
1006798948Sobrien
1006819370Spst@value{GDBN} automatically loads symbol definitions from shared libraries
1006919370Spstwhen you use the @code{run} command, or when you examine a core file.
1007019370Spst(Before you issue the @code{run} command, @value{GDBN} does not understand
1007119370Spstreferences to a function in a shared library, however---unless you are
1007219370Spstdebugging a core file).
1007398948Sobrien
1007498948SobrienOn HP-UX, if the program loads a library explicitly, @value{GDBN}
1007598948Sobrienautomatically loads the symbols at the time of the @code{shl_load} call.
1007698948Sobrien
1007719370Spst@c FIXME: some @value{GDBN} release may permit some refs to undef
1007819370Spst@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
1007919370Spst@c FIXME...lib; check this from time to time when updating manual
1008019370Spst
1008198948SobrienThere are times, however, when you may wish to not automatically load
1008298948Sobriensymbol definitions from shared libraries, such as when they are
1008398948Sobrienparticularly large or there are many of them.
1008498948Sobrien
1008598948SobrienTo control the automatic loading of shared library symbols, use the
1008698948Sobriencommands:
1008798948Sobrien
1008819370Spst@table @code
1008998948Sobrien@kindex set auto-solib-add
1009098948Sobrien@item set auto-solib-add @var{mode}
1009198948SobrienIf @var{mode} is @code{on}, symbols from all shared object libraries
1009298948Sobrienwill be loaded automatically when the inferior begins execution, you
1009398948Sobrienattach to an independently started inferior, or when the dynamic linker
1009498948Sobrieninforms @value{GDBN} that a new library has been loaded.  If @var{mode}
1009598948Sobrienis @code{off}, symbols must be loaded manually, using the
1009698948Sobrien@code{sharedlibrary} command.  The default value is @code{on}.
1009798948Sobrien
1009898948Sobrien@kindex show auto-solib-add
1009998948Sobrien@item show auto-solib-add
1010098948SobrienDisplay the current autoloading mode.
1010198948Sobrien@end table
1010298948Sobrien
1010398948SobrienTo explicitly load shared library symbols, use the @code{sharedlibrary}
1010498948Sobriencommand:
1010598948Sobrien
1010698948Sobrien@table @code
1010719370Spst@kindex info sharedlibrary
1010819370Spst@kindex info share
1010919370Spst@item info share
1011019370Spst@itemx info sharedlibrary
1011119370SpstPrint the names of the shared libraries which are currently loaded.
1011219370Spst
1011319370Spst@kindex sharedlibrary
1011419370Spst@kindex share
1011519370Spst@item sharedlibrary @var{regex}
1011619370Spst@itemx share @var{regex}
1011719370SpstLoad shared object library symbols for files matching a
1011819370SpstUnix regular expression.
1011919370SpstAs with files loaded automatically, it only loads shared libraries
1012019370Spstrequired by your program for a core file or after typing @code{run}.  If
1012119370Spst@var{regex} is omitted all shared libraries required by your program are
1012219370Spstloaded.
1012319370Spst@end table
1012446289Sdfr
1012598948SobrienOn some systems, such as HP-UX systems, @value{GDBN} supports
1012698948Sobrienautoloading shared library symbols until a limiting threshold size is
1012798948Sobrienreached.  This provides the benefit of allowing autoloading to remain on
1012898948Sobrienby default, but avoids autoloading excessively large shared libraries,
1012998948Sobrienup to a threshold that is initially set, but which you can modify if you
1013098948Sobrienwish.
1013146289Sdfr
1013246289SdfrBeyond that threshold, symbols from shared libraries must be explicitly
1013398948Sobrienloaded.  To load these symbols, use the command @code{sharedlibrary
1013498948Sobrien@var{filename}}.  The base address of the shared library is determined
1013546289Sdfrautomatically by @value{GDBN} and need not be specified.
1013646289Sdfr
1013746289SdfrTo display or set the threshold, use the commands:
1013846289Sdfr
1013946289Sdfr@table @code
1014098948Sobrien@kindex set auto-solib-limit
1014198948Sobrien@item set auto-solib-limit @var{threshold}
1014298948SobrienSet the autoloading size threshold, in an integral number of megabytes.
1014398948SobrienIf @var{threshold} is nonzero and shared library autoloading is enabled,
1014498948Sobriensymbols from all shared object libraries will be loaded until the total
1014598948Sobriensize of the loaded shared library symbols exceeds this threshold.
1014646289SdfrOtherwise, symbols must be loaded manually, using the
1014798948Sobrien@code{sharedlibrary} command.  The default threshold is 100 (i.e.@: 100
1014898948SobrienMb).
1014946289Sdfr
1015098948Sobrien@kindex show auto-solib-limit
1015198948Sobrien@item show auto-solib-limit
1015246289SdfrDisplay the current autoloading size threshold, in megabytes.
1015346289Sdfr@end table
1015446289Sdfr
10155130809SmarcelShared libraries are also supported in many cross or remote debugging
10156130809Smarcelconfigurations.  A copy of the target's libraries need to be present on the
10157130809Smarcelhost system; they need to be the same as the target libraries, although the
10158130809Smarcelcopies on the target can be stripped as long as the copies on the host are
10159130809Smarcelnot.
10160130809Smarcel
10161130809SmarcelYou need to tell @value{GDBN} where the target libraries are, so that it can
10162130809Smarcelload the correct copies---otherwise, it may try to load the host's libraries.
10163130809Smarcel@value{GDBN} has two variables to specify the search directories for target
10164130809Smarcellibraries.
10165130809Smarcel
10166130809Smarcel@table @code
10167130809Smarcel@kindex set solib-absolute-prefix
10168130809Smarcel@item set solib-absolute-prefix @var{path}
10169130809SmarcelIf this variable is set, @var{path} will be used as a prefix for any
10170130809Smarcelabsolute shared library paths; many runtime loaders store the absolute
10171130809Smarcelpaths to the shared library in the target program's memory.  If you use
10172130809Smarcel@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
10173130809Smarcelout in the same way that they are on the target, with e.g.@: a
10174130809Smarcel@file{/usr/lib} hierarchy under @var{path}.
10175130809Smarcel
10176130809SmarcelYou can set the default value of @samp{solib-absolute-prefix} by using the
10177130809Smarcelconfigure-time @samp{--with-sysroot} option.
10178130809Smarcel
10179130809Smarcel@kindex show solib-absolute-prefix
10180130809Smarcel@item show solib-absolute-prefix
10181130809SmarcelDisplay the current shared library prefix.
10182130809Smarcel
10183130809Smarcel@kindex set solib-search-path
10184130809Smarcel@item set solib-search-path @var{path}
10185130809SmarcelIf this variable is set, @var{path} is a colon-separated list of directories
10186130809Smarcelto search for shared libraries.  @samp{solib-search-path} is used after
10187130809Smarcel@samp{solib-absolute-prefix} fails to locate the library, or if the path to
10188130809Smarcelthe library is relative instead of absolute.  If you want to use
10189130809Smarcel@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
10190130809Smarcelset @samp{solib-absolute-prefix} to a nonexistant directory to prevent
10191130809Smarcel@value{GDBN} from finding your host's libraries.
10192130809Smarcel
10193130809Smarcel@kindex show solib-search-path
10194130809Smarcel@item show solib-search-path
10195130809SmarcelDisplay the current shared library search path.
10196130809Smarcel@end table
10197130809Smarcel
10198130809Smarcel
10199130809Smarcel@node Separate Debug Files
10200130809Smarcel@section Debugging Information in Separate Files
10201130809Smarcel@cindex separate debugging information files
10202130809Smarcel@cindex debugging information in separate files
10203130809Smarcel@cindex @file{.debug} subdirectories
10204130809Smarcel@cindex debugging information directory, global
10205130809Smarcel@cindex global debugging information directory
10206130809Smarcel
10207130809Smarcel@value{GDBN} allows you to put a program's debugging information in a
10208130809Smarcelfile separate from the executable itself, in a way that allows
10209130809Smarcel@value{GDBN} to find and load the debugging information automatically.
10210130809SmarcelSince debugging information can be very large --- sometimes larger
10211130809Smarcelthan the executable code itself --- some systems distribute debugging
10212130809Smarcelinformation for their executables in separate files, which users can
10213130809Smarcelinstall only when they need to debug a problem.
10214130809Smarcel
10215130809SmarcelIf an executable's debugging information has been extracted to a
10216130809Smarcelseparate file, the executable should contain a @dfn{debug link} giving
10217130809Smarcelthe name of the debugging information file (with no directory
10218130809Smarcelcomponents), and a checksum of its contents.  (The exact form of a
10219130809Smarceldebug link is described below.)  If the full name of the directory
10220130809Smarcelcontaining the executable is @var{execdir}, and the executable has a
10221130809Smarceldebug link that specifies the name @var{debugfile}, then @value{GDBN}
10222130809Smarcelwill automatically search for the debugging information file in three
10223130809Smarcelplaces:
10224130809Smarcel
10225130809Smarcel@itemize @bullet
10226130809Smarcel@item
10227130809Smarcelthe directory containing the executable file (that is, it will look
10228130809Smarcelfor a file named @file{@var{execdir}/@var{debugfile}},
10229130809Smarcel@item
10230130809Smarcela subdirectory of that directory named @file{.debug} (that is, the
10231130809Smarcelfile @file{@var{execdir}/.debug/@var{debugfile}}, and
10232130809Smarcel@item
10233130809Smarcela subdirectory of the global debug file directory that includes the
10234130809Smarcelexecutable's full path, and the name from the link (that is, the file
10235130809Smarcel@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
10236130809Smarcel@var{globaldebugdir} is the global debug file directory, and
10237130809Smarcel@var{execdir} has been turned into a relative path).
10238130809Smarcel@end itemize
10239130809Smarcel@noindent
10240130809Smarcel@value{GDBN} checks under each of these names for a debugging
10241130809Smarcelinformation file whose checksum matches that given in the link, and
10242130809Smarcelreads the debugging information from the first one it finds.
10243130809Smarcel
10244130809SmarcelSo, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
10245130809Smarcelwhich has a link containing the name @file{ls.debug}, and the global
10246130809Smarceldebug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
10247130809Smarcelfor debug information in @file{/usr/bin/ls.debug},
10248130809Smarcel@file{/usr/bin/.debug/ls.debug}, and
10249130809Smarcel@file{/usr/lib/debug/usr/bin/ls.debug}.
10250130809Smarcel
10251130809SmarcelYou can set the global debugging info directory's name, and view the
10252130809Smarcelname @value{GDBN} is currently using.
10253130809Smarcel
10254130809Smarcel@table @code
10255130809Smarcel
10256130809Smarcel@kindex set debug-file-directory
10257130809Smarcel@item set debug-file-directory @var{directory}
10258130809SmarcelSet the directory which @value{GDBN} searches for separate debugging
10259130809Smarcelinformation files to @var{directory}.
10260130809Smarcel
10261130809Smarcel@kindex show debug-file-directory
10262130809Smarcel@item show debug-file-directory
10263130809SmarcelShow the directory @value{GDBN} searches for separate debugging
10264130809Smarcelinformation files.
10265130809Smarcel
10266130809Smarcel@end table
10267130809Smarcel
10268130809Smarcel@cindex @code{.gnu_debuglink} sections
10269130809Smarcel@cindex debug links
10270130809SmarcelA debug link is a special section of the executable file named
10271130809Smarcel@code{.gnu_debuglink}.  The section must contain:
10272130809Smarcel
10273130809Smarcel@itemize
10274130809Smarcel@item
10275130809SmarcelA filename, with any leading directory components removed, followed by
10276130809Smarcela zero byte,
10277130809Smarcel@item
10278130809Smarcelzero to three bytes of padding, as needed to reach the next four-byte
10279130809Smarcelboundary within the section, and
10280130809Smarcel@item
10281130809Smarcela four-byte CRC checksum, stored in the same endianness used for the
10282130809Smarcelexecutable file itself.  The checksum is computed on the debugging
10283130809Smarcelinformation file's full contents by the function given below, passing
10284130809Smarcelzero as the @var{crc} argument.
10285130809Smarcel@end itemize
10286130809Smarcel
10287130809SmarcelAny executable file format can carry a debug link, as long as it can
10288130809Smarcelcontain a section named @code{.gnu_debuglink} with the contents
10289130809Smarceldescribed above.
10290130809Smarcel
10291130809SmarcelThe debugging information file itself should be an ordinary
10292130809Smarcelexecutable, containing a full set of linker symbols, sections, and
10293130809Smarceldebugging information.  The sections of the debugging information file
10294130809Smarcelshould have the same names, addresses and sizes as the original file,
10295130809Smarcelbut they need not contain any data --- much like a @code{.bss} section
10296130809Smarcelin an ordinary executable.
10297130809Smarcel
10298130809SmarcelAs of December 2002, there is no standard GNU utility to produce
10299130809Smarcelseparated executable / debugging information file pairs.  Ulrich
10300130809SmarcelDrepper's @file{elfutils} package, starting with version 0.53,
10301130809Smarcelcontains a version of the @code{strip} command such that the command
10302130809Smarcel@kbd{strip foo -f foo.debug} removes the debugging information from
10303130809Smarcelthe executable file @file{foo}, places it in the file
10304130809Smarcel@file{foo.debug}, and leaves behind a debug link in @file{foo}.
10305130809Smarcel
10306130809SmarcelSince there are many different ways to compute CRC's (different
10307130809Smarcelpolynomials, reversals, byte ordering, etc.), the simplest way to
10308130809Smarceldescribe the CRC used in @code{.gnu_debuglink} sections is to give the
10309130809Smarcelcomplete code for a function that computes it:
10310130809Smarcel
10311130809Smarcel@kindex @code{gnu_debuglink_crc32}
10312130809Smarcel@smallexample
10313130809Smarcelunsigned long
10314130809Smarcelgnu_debuglink_crc32 (unsigned long crc,
10315130809Smarcel                     unsigned char *buf, size_t len)
10316130809Smarcel@{
10317130809Smarcel  static const unsigned long crc32_table[256] =
10318130809Smarcel    @{
10319130809Smarcel      0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10320130809Smarcel      0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10321130809Smarcel      0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10322130809Smarcel      0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10323130809Smarcel      0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10324130809Smarcel      0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10325130809Smarcel      0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10326130809Smarcel      0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10327130809Smarcel      0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10328130809Smarcel      0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10329130809Smarcel      0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10330130809Smarcel      0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10331130809Smarcel      0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10332130809Smarcel      0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10333130809Smarcel      0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10334130809Smarcel      0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10335130809Smarcel      0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10336130809Smarcel      0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10337130809Smarcel      0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10338130809Smarcel      0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10339130809Smarcel      0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10340130809Smarcel      0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10341130809Smarcel      0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10342130809Smarcel      0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10343130809Smarcel      0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10344130809Smarcel      0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10345130809Smarcel      0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10346130809Smarcel      0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10347130809Smarcel      0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10348130809Smarcel      0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10349130809Smarcel      0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10350130809Smarcel      0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10351130809Smarcel      0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10352130809Smarcel      0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10353130809Smarcel      0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10354130809Smarcel      0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10355130809Smarcel      0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10356130809Smarcel      0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10357130809Smarcel      0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10358130809Smarcel      0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10359130809Smarcel      0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10360130809Smarcel      0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10361130809Smarcel      0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10362130809Smarcel      0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10363130809Smarcel      0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10364130809Smarcel      0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10365130809Smarcel      0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10366130809Smarcel      0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10367130809Smarcel      0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10368130809Smarcel      0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10369130809Smarcel      0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10370130809Smarcel      0x2d02ef8d
10371130809Smarcel    @};
10372130809Smarcel  unsigned char *end;
10373130809Smarcel
10374130809Smarcel  crc = ~crc & 0xffffffff;
10375130809Smarcel  for (end = buf + len; buf < end; ++buf)
10376130809Smarcel    crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
10377130809Smarcel  return ~crc & 0xffffffff;
10378130809Smarcel@}
10379130809Smarcel@end smallexample
10380130809Smarcel
10381130809Smarcel
1038298948Sobrien@node Symbol Errors
1038319370Spst@section Errors reading symbol files
1038419370Spst
1038519370SpstWhile reading a symbol file, @value{GDBN} occasionally encounters problems,
1038619370Spstsuch as symbol types it does not recognize, or known bugs in compiler
1038719370Spstoutput.  By default, @value{GDBN} does not notify you of such problems, since
1038819370Spstthey are relatively common and primarily of interest to people
1038919370Spstdebugging compilers.  If you are interested in seeing information
1039019370Spstabout ill-constructed symbol tables, you can either ask @value{GDBN} to print
1039119370Spstonly one message about each such type of problem, no matter how many
1039219370Spsttimes the problem occurs; or you can ask @value{GDBN} to print more messages,
1039319370Spstto see how many times the problems occur, with the @code{set
1039419370Spstcomplaints} command (@pxref{Messages/Warnings, ,Optional warnings and
1039519370Spstmessages}).
1039619370Spst
1039719370SpstThe messages currently printed, and their meanings, include:
1039819370Spst
1039919370Spst@table @code
1040019370Spst@item inner block not inside outer block in @var{symbol}
1040119370Spst
1040219370SpstThe symbol information shows where symbol scopes begin and end
1040319370Spst(such as at the start of a function or a block of statements).  This
1040419370Spsterror indicates that an inner scope block is not fully contained
1040519370Spstin its outer scope blocks.
1040619370Spst
1040719370Spst@value{GDBN} circumvents the problem by treating the inner block as if it had
1040819370Spstthe same scope as the outer block.  In the error message, @var{symbol}
1040919370Spstmay be shown as ``@code{(don't know)}'' if the outer block is not a
1041019370Spstfunction.
1041119370Spst
1041219370Spst@item block at @var{address} out of order
1041319370Spst
1041419370SpstThe symbol information for symbol scope blocks should occur in
1041519370Spstorder of increasing addresses.  This error indicates that it does not
1041619370Spstdo so.
1041719370Spst
1041819370Spst@value{GDBN} does not circumvent this problem, and has trouble
1041919370Spstlocating symbols in the source file whose symbols it is reading.  (You
1042019370Spstcan often determine what source file is affected by specifying
1042119370Spst@code{set verbose on}.  @xref{Messages/Warnings, ,Optional warnings and
1042219370Spstmessages}.)
1042319370Spst
1042419370Spst@item bad block start address patched
1042519370Spst
1042619370SpstThe symbol information for a symbol scope block has a start address
1042719370Spstsmaller than the address of the preceding source line.  This is known
1042819370Spstto occur in the SunOS 4.1.1 (and earlier) C compiler.
1042919370Spst
1043019370Spst@value{GDBN} circumvents the problem by treating the symbol scope block as
1043119370Spststarting on the previous source line.
1043219370Spst
1043319370Spst@item bad string table offset in symbol @var{n}
1043419370Spst
1043519370Spst@cindex foo
1043619370SpstSymbol number @var{n} contains a pointer into the string table which is
1043719370Spstlarger than the size of the string table.
1043819370Spst
1043919370Spst@value{GDBN} circumvents the problem by considering the symbol to have the
1044019370Spstname @code{foo}, which may cause other problems if many symbols end up
1044119370Spstwith this name.
1044219370Spst
1044319370Spst@item unknown symbol type @code{0x@var{nn}}
1044419370Spst
1044598948SobrienThe symbol information contains new data types that @value{GDBN} does
1044698948Sobriennot yet know how to read.  @code{0x@var{nn}} is the symbol type of the
1044798948Sobrienuncomprehended information, in hexadecimal.
1044819370Spst
1044998948Sobrien@value{GDBN} circumvents the error by ignoring this symbol information.
1045098948SobrienThis usually allows you to debug your program, though certain symbols
1045119370Spstare not accessible.  If you encounter such a problem and feel like
1045298948Sobriendebugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
1045398948Sobrienon @code{complain}, then go up to the function @code{read_dbx_symtab}
1045498948Sobrienand examine @code{*bufp} to see the symbol.
1045519370Spst
1045619370Spst@item stub type has NULL name
1045719370Spst
1045898948Sobrien@value{GDBN} could not find the full definition for a struct or class.
1045998948Sobrien
1046019370Spst@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
1046198948SobrienThe symbol information for a C@t{++} member function is missing some
1046298948Sobrieninformation that recent versions of the compiler should have output for
1046398948Sobrienit.
1046419370Spst
1046519370Spst@item info mismatch between compiler and debugger
1046619370Spst
1046719370Spst@value{GDBN} could not parse a type specification output by the compiler.
1046898948Sobrien
1046919370Spst@end table
1047019370Spst
1047198948Sobrien@node Targets
1047219370Spst@chapter Specifying a Debugging Target
1047398948Sobrien
1047419370Spst@cindex debugging target
1047519370Spst@kindex target
1047619370Spst
1047719370SpstA @dfn{target} is the execution environment occupied by your program.
1047898948Sobrien
1047998948SobrienOften, @value{GDBN} runs in the same host environment as your program;
1048098948Sobrienin that case, the debugging target is specified as a side effect when
1048198948Sobrienyou use the @code{file} or @code{core} commands.  When you need more
1048219370Spstflexibility---for example, running @value{GDBN} on a physically separate
1048319370Spsthost, or controlling a standalone system over a serial port or a
1048498948Sobrienrealtime system over a TCP/IP connection---you can use the @code{target}
1048598948Sobriencommand to specify one of the target types configured for @value{GDBN}
1048698948Sobrien(@pxref{Target Commands, ,Commands for managing targets}).
1048746289Sdfr
1048819370Spst@menu
1048919370Spst* Active Targets::              Active targets
1049019370Spst* Target Commands::             Commands for managing targets
1049146289Sdfr* Byte Order::                  Choosing target byte order
1049219370Spst* Remote::                      Remote debugging
1049398948Sobrien* KOD::                         Kernel Object Display
1049446289Sdfr
1049519370Spst@end menu
1049619370Spst
1049798948Sobrien@node Active Targets
1049819370Spst@section Active targets
1049998948Sobrien
1050019370Spst@cindex stacking targets
1050119370Spst@cindex active targets
1050219370Spst@cindex multiple targets
1050319370Spst
1050419370SpstThere are three classes of targets: processes, core files, and
1050598948Sobrienexecutable files.  @value{GDBN} can work concurrently on up to three
1050698948Sobrienactive targets, one in each class.  This allows you to (for example)
1050798948Sobrienstart a process and inspect its activity without abandoning your work on
1050898948Sobriena core file.
1050919370Spst
1051019370SpstFor example, if you execute @samp{gdb a.out}, then the executable file
1051119370Spst@code{a.out} is the only active target.  If you designate a core file as
1051219370Spstwell---presumably from a prior run that crashed and coredumped---then
1051319370Spst@value{GDBN} has two active targets and uses them in tandem, looking
1051419370Spstfirst in the corefile target, then in the executable file, to satisfy
1051519370Spstrequests for memory addresses.  (Typically, these two classes of target
1051619370Spstare complementary, since core files contain only a program's
1051719370Spstread-write memory---variables and so on---plus machine status, while
1051819370Spstexecutable files contain only the program text and initialized data.)
1051919370Spst
1052019370SpstWhen you type @code{run}, your executable file becomes an active process
1052198948Sobrientarget as well.  When a process target is active, all @value{GDBN}
1052298948Sobriencommands requesting memory addresses refer to that target; addresses in
1052398948Sobrienan active core file or executable file target are obscured while the
1052498948Sobrienprocess target is active.
1052519370Spst
1052698948SobrienUse the @code{core-file} and @code{exec-file} commands to select a new
1052798948Sobriencore file or executable target (@pxref{Files, ,Commands to specify
1052819370Spstfiles}).  To specify as a target a process that is already running, use
1052998948Sobrienthe @code{attach} command (@pxref{Attach, ,Debugging an already-running
1053098948Sobrienprocess}).
1053119370Spst
1053298948Sobrien@node Target Commands
1053319370Spst@section Commands for managing targets
1053419370Spst
1053519370Spst@table @code
1053619370Spst@item target @var{type} @var{parameters}
1053798948SobrienConnects the @value{GDBN} host environment to a target machine or
1053898948Sobrienprocess.  A target is typically a protocol for talking to debugging
1053998948Sobrienfacilities.  You use the argument @var{type} to specify the type or
1054098948Sobrienprotocol of the target machine.
1054119370Spst
1054219370SpstFurther @var{parameters} are interpreted by the target protocol, but
1054319370Spsttypically include things like device names or host names to connect
1054419370Spstwith, process numbers, and baud rates.
1054519370Spst
1054619370SpstThe @code{target} command does not repeat if you press @key{RET} again
1054719370Spstafter executing the command.
1054819370Spst
1054919370Spst@kindex help target
1055019370Spst@item help target
1055119370SpstDisplays the names of all targets available.  To display targets
1055219370Spstcurrently selected, use either @code{info target} or @code{info files}
1055319370Spst(@pxref{Files, ,Commands to specify files}).
1055419370Spst
1055519370Spst@item help target @var{name}
1055619370SpstDescribe a particular target, including any parameters necessary to
1055719370Spstselect it.
1055819370Spst
1055919370Spst@kindex set gnutarget
1056019370Spst@item set gnutarget @var{args}
1056198948Sobrien@value{GDBN} uses its own library BFD to read your files.  @value{GDBN}
1056219370Spstknows whether it is reading an @dfn{executable},
1056398948Sobriena @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
1056498948Sobrienwith the @code{set gnutarget} command.  Unlike most @code{target} commands,
1056519370Spstwith @code{gnutarget} the @code{target} refers to a program, not a machine.
1056619370Spst
1056798948Sobrien@quotation
1056819370Spst@emph{Warning:} To specify a file format with @code{set gnutarget},
1056946289Sdfryou must know the actual BFD name.
1057098948Sobrien@end quotation
1057119370Spst
1057298948Sobrien@noindent
1057398948Sobrien@xref{Files, , Commands to specify files}.
1057419370Spst
1057598948Sobrien@kindex show gnutarget
1057619370Spst@item show gnutarget
1057719370SpstUse the @code{show gnutarget} command to display what file format
1057819370Spst@code{gnutarget} is set to read.  If you have not set @code{gnutarget},
1057946289Sdfr@value{GDBN} will determine the file format for each file automatically,
1058046289Sdfrand @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
1058119370Spst@end table
1058219370Spst
1058319370SpstHere are some common targets (available, or not, depending on the GDB
1058419370Spstconfiguration):
1058519370Spst
1058619370Spst@table @code
1058719370Spst@kindex target exec
1058819370Spst@item target exec @var{program}
1058919370SpstAn executable file.  @samp{target exec @var{program}} is the same as
1059019370Spst@samp{exec-file @var{program}}.
1059119370Spst
1059219370Spst@kindex target core
1059319370Spst@item target core @var{filename}
1059419370SpstA core dump file.  @samp{target core @var{filename}} is the same as
1059519370Spst@samp{core-file @var{filename}}.
1059619370Spst
1059719370Spst@kindex target remote
1059819370Spst@item target remote @var{dev}
1059919370SpstRemote serial target in GDB-specific protocol.  The argument @var{dev}
1060019370Spstspecifies what serial device to use for the connection (e.g.
1060119370Spst@file{/dev/ttya}). @xref{Remote, ,Remote debugging}.  @code{target remote}
1060298948Sobriensupports the @code{load} command.  This is only useful if you have
1060319370Spstsome other way of getting the stub to the target system, and you can put
1060419370Spstit somewhere in memory where it won't get clobbered by the download.
1060519370Spst
1060619370Spst@kindex target sim
1060719370Spst@item target sim
1060898948SobrienBuiltin CPU simulator.  @value{GDBN} includes simulators for most architectures.
1060998948SobrienIn general,
10610130809Smarcel@smallexample
1061198948Sobrien        target sim
1061298948Sobrien        load
1061398948Sobrien        run
10614130809Smarcel@end smallexample
1061598948Sobrien@noindent
1061698948Sobrienworks; however, you cannot assume that a specific memory map, device
1061798948Sobriendrivers, or even basic I/O is available, although some simulators do
1061898948Sobrienprovide these.  For info about any processor-specific simulator details,
1061998948Sobriensee the appropriate section in @ref{Embedded Processors, ,Embedded
1062098948SobrienProcessors}.
1062198948Sobrien
1062246289Sdfr@end table
1062319370Spst
1062498948SobrienSome configurations may include these targets as well:
1062519370Spst
1062646289Sdfr@table @code
1062746289Sdfr
1062846289Sdfr@kindex target nrom
1062946289Sdfr@item target nrom @var{dev}
1063046289SdfrNetROM ROM emulator.  This target only supports downloading.
1063146289Sdfr
1063219370Spst@end table
1063319370Spst
1063498948SobrienDifferent targets are available on different configurations of @value{GDBN};
1063519370Spstyour configuration may have more or fewer targets.
1063619370Spst
1063746289SdfrMany remote targets require you to download the executable's code
1063846289Sdfronce you've successfully established a connection.
1063946289Sdfr
1064046289Sdfr@table @code
1064146289Sdfr
1064246289Sdfr@kindex load @var{filename}
1064346289Sdfr@item load @var{filename}
1064446289SdfrDepending on what remote debugging facilities are configured into
1064546289Sdfr@value{GDBN}, the @code{load} command may be available.  Where it exists, it
1064646289Sdfris meant to make @var{filename} (an executable) available for debugging
1064746289Sdfron the remote system---by downloading, or dynamic linking, for example.
1064846289Sdfr@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
1064946289Sdfrthe @code{add-symbol-file} command.
1065046289Sdfr
1065146289SdfrIf your @value{GDBN} does not have a @code{load} command, attempting to
1065246289Sdfrexecute it gets the error message ``@code{You can't do that when your
1065346289Sdfrtarget is @dots{}}''
1065446289Sdfr
1065546289SdfrThe file is loaded at whatever address is specified in the executable.
1065646289SdfrFor some object file formats, you can specify the load address when you
1065746289Sdfrlink the program; for other formats, like a.out, the object file format
1065846289Sdfrspecifies a fixed address.
1065946289Sdfr@c FIXME! This would be a good place for an xref to the GNU linker doc.
1066046289Sdfr
1066146289Sdfr@code{load} does not repeat if you press @key{RET} again after using it.
1066246289Sdfr@end table
1066346289Sdfr
1066498948Sobrien@node Byte Order
1066519370Spst@section Choosing target byte order
1066698948Sobrien
1066719370Spst@cindex choosing target byte order
1066819370Spst@cindex target byte order
1066919370Spst
10670130809SmarcelSome types of processors, such as the MIPS, PowerPC, and Renesas SH,
1067146289Sdfroffer the ability to run either big-endian or little-endian byte
1067246289Sdfrorders.  Usually the executable or symbol will include a bit to
1067346289Sdfrdesignate the endian-ness, and you will not need to worry about
1067446289Sdfrwhich to use.  However, you may still find it useful to adjust
1067598948Sobrien@value{GDBN}'s idea of processor endian-ness manually.
1067619370Spst
1067746289Sdfr@table @code
1067846289Sdfr@kindex set endian big
1067946289Sdfr@item set endian big
1068046289SdfrInstruct @value{GDBN} to assume the target is big-endian.
1068146289Sdfr
1068246289Sdfr@kindex set endian little
1068346289Sdfr@item set endian little
1068446289SdfrInstruct @value{GDBN} to assume the target is little-endian.
1068546289Sdfr
1068646289Sdfr@kindex set endian auto
1068746289Sdfr@item set endian auto
1068846289SdfrInstruct @value{GDBN} to use the byte order associated with the
1068946289Sdfrexecutable.
1069046289Sdfr
1069146289Sdfr@item show endian
1069246289SdfrDisplay @value{GDBN}'s current idea of the target byte order.
1069346289Sdfr
1069446289Sdfr@end table
1069546289Sdfr
1069646289SdfrNote that these commands merely adjust interpretation of symbolic
1069746289Sdfrdata on the host, and that they have absolutely no effect on the
1069846289Sdfrtarget system.
1069946289Sdfr
1070098948Sobrien@node Remote
1070119370Spst@section Remote debugging
1070219370Spst@cindex remote debugging
1070319370Spst
1070419370SpstIf you are trying to debug a program running on a machine that cannot run
1070598948Sobrien@value{GDBN} in the usual way, it is often useful to use remote debugging.
1070698948SobrienFor example, you might use remote debugging on an operating system kernel,
1070719370Spstor on a small system which does not have a general purpose operating system
1070819370Spstpowerful enough to run a full-featured debugger.
1070919370Spst
1071019370SpstSome configurations of @value{GDBN} have special serial or TCP/IP interfaces
1071119370Spstto make this work with particular debugging targets.  In addition,
1071298948Sobrien@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
1071319370Spstbut not specific to any particular target system) which you can use if you
1071419370Spstwrite the remote stubs---the code that runs on the remote system to
1071519370Spstcommunicate with @value{GDBN}.
1071619370Spst
1071719370SpstOther remote targets may be available in your
1071819370Spstconfiguration of @value{GDBN}; use @code{help target} to list them.
1071919370Spst
1072098948Sobrien@node KOD
1072198948Sobrien@section Kernel Object Display
1072298948Sobrien@cindex kernel object display
1072398948Sobrien@cindex KOD
1072498948Sobrien
1072598948SobrienSome targets support kernel object display.  Using this facility,
1072698948Sobrien@value{GDBN} communicates specially with the underlying operating system
1072798948Sobrienand can display information about operating system-level objects such as
1072898948Sobrienmutexes and other synchronization objects.  Exactly which objects can be
1072998948Sobriendisplayed is determined on a per-OS basis.
1073098948Sobrien
10731130809Smarcel@kindex set os
1073298948SobrienUse the @code{set os} command to set the operating system.  This tells
1073398948Sobrien@value{GDBN} which kernel object display module to initialize:
1073498948Sobrien
10735130809Smarcel@smallexample
1073698948Sobrien(@value{GDBP}) set os cisco
10737130809Smarcel@end smallexample
1073898948Sobrien
10739130809Smarcel@kindex show os
10740130809SmarcelThe associated command @code{show os} displays the operating system
10741130809Smarcelset with the @code{set os} command; if no operating system has been
10742130809Smarcelset, @code{show os} will display an empty string @samp{""}.
10743130809Smarcel
1074498948SobrienIf @code{set os} succeeds, @value{GDBN} will display some information
1074598948Sobrienabout the operating system, and will create a new @code{info} command
1074698948Sobrienwhich can be used to query the target.  The @code{info} command is named
1074798948Sobrienafter the operating system:
1074898948Sobrien
10749130809Smarcel@kindex info cisco
10750130809Smarcel@smallexample
1075198948Sobrien(@value{GDBP}) info cisco
1075298948SobrienList of Cisco Kernel Objects
1075398948SobrienObject     Description
1075498948Sobrienany        Any and all objects
10755130809Smarcel@end smallexample
1075698948Sobrien
1075798948SobrienFurther subcommands can be used to query about particular objects known
1075898948Sobrienby the kernel.
1075998948Sobrien
10760130809SmarcelThere is currently no way to determine whether a given operating
10761130809Smarcelsystem is supported other than to try setting it with @kbd{set os
10762130809Smarcel@var{name}}, where @var{name} is the name of the operating system you
10763130809Smarcelwant to try.
1076498948Sobrien
1076598948Sobrien
1076698948Sobrien@node Remote Debugging
1076798948Sobrien@chapter Debugging remote programs
1076898948Sobrien
1076919370Spst@menu
10770130809Smarcel* Connecting::                  Connecting to a remote target
1077198948Sobrien* Server::	                Using the gdbserver program
1077298948Sobrien* NetWare::                     Using the gdbserve.nlm program
10773130809Smarcel* Remote configuration::        Remote configuration
1077498948Sobrien* remote stub::                 Implementing a remote stub
1077519370Spst@end menu
1077619370Spst
10777130809Smarcel@node Connecting
10778130809Smarcel@section Connecting to a remote target
10779130809Smarcel
10780130809SmarcelOn the @value{GDBN} host machine, you will need an unstripped copy of
10781130809Smarcelyour program, since @value{GDBN} needs symobl and debugging information.
10782130809SmarcelStart up @value{GDBN} as usual, using the name of the local copy of your
10783130809Smarcelprogram as the first argument.
10784130809Smarcel
10785130809Smarcel@cindex serial line, @code{target remote}
10786130809SmarcelIf you're using a serial line, you may want to give @value{GDBN} the
10787130809Smarcel@w{@samp{--baud}} option, or use the @code{set remotebaud} command
10788130809Smarcelbefore the @code{target} command.
10789130809Smarcel
10790130809SmarcelAfter that, use @code{target remote} to establish communications with
10791130809Smarcelthe target machine.  Its argument specifies how to communicate---either
10792130809Smarcelvia a devicename attached to a direct serial line, or a TCP or UDP port
10793130809Smarcel(possibly to a terminal server which in turn has a serial line to the
10794130809Smarceltarget).  For example, to use a serial line connected to the device
10795130809Smarcelnamed @file{/dev/ttyb}:
10796130809Smarcel
10797130809Smarcel@smallexample
10798130809Smarceltarget remote /dev/ttyb
10799130809Smarcel@end smallexample
10800130809Smarcel
10801130809Smarcel@cindex TCP port, @code{target remote}
10802130809SmarcelTo use a TCP connection, use an argument of the form
10803130809Smarcel@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
10804130809SmarcelFor example, to connect to port 2828 on a
10805130809Smarcelterminal server named @code{manyfarms}:
10806130809Smarcel
10807130809Smarcel@smallexample
10808130809Smarceltarget remote manyfarms:2828
10809130809Smarcel@end smallexample
10810130809Smarcel
10811130809SmarcelIf your remote target is actually running on the same machine as
10812130809Smarcelyour debugger session (e.g.@: a simulator of your target running on
10813130809Smarcelthe same host), you can omit the hostname.  For example, to connect
10814130809Smarcelto port 1234 on your local machine:
10815130809Smarcel
10816130809Smarcel@smallexample
10817130809Smarceltarget remote :1234
10818130809Smarcel@end smallexample
10819130809Smarcel@noindent
10820130809Smarcel
10821130809SmarcelNote that the colon is still required here.
10822130809Smarcel
10823130809Smarcel@cindex UDP port, @code{target remote}
10824130809SmarcelTo use a UDP connection, use an argument of the form
10825130809Smarcel@code{udp:@var{host}:@var{port}}.  For example, to connect to UDP port 2828
10826130809Smarcelon a terminal server named @code{manyfarms}:
10827130809Smarcel
10828130809Smarcel@smallexample
10829130809Smarceltarget remote udp:manyfarms:2828
10830130809Smarcel@end smallexample
10831130809Smarcel
10832130809SmarcelWhen using a UDP connection for remote debugging, you should keep in mind
10833130809Smarcelthat the `U' stands for ``Unreliable''.  UDP can silently drop packets on
10834130809Smarcelbusy or unreliable networks, which will cause havoc with your debugging
10835130809Smarcelsession.
10836130809Smarcel
10837130809SmarcelNow you can use all the usual commands to examine and change data and to
10838130809Smarcelstep and continue the remote program.
10839130809Smarcel
10840130809Smarcel@cindex interrupting remote programs
10841130809Smarcel@cindex remote programs, interrupting
10842130809SmarcelWhenever @value{GDBN} is waiting for the remote program, if you type the
10843130809Smarcelinterrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
10844130809Smarcelprogram.  This may or may not succeed, depending in part on the hardware
10845130809Smarceland the serial drivers the remote system uses.  If you type the
10846130809Smarcelinterrupt character once again, @value{GDBN} displays this prompt:
10847130809Smarcel
10848130809Smarcel@smallexample
10849130809SmarcelInterrupted while waiting for the program.
10850130809SmarcelGive up (and stop debugging it)?  (y or n)
10851130809Smarcel@end smallexample
10852130809Smarcel
10853130809SmarcelIf you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
10854130809Smarcel(If you decide you want to try again later, you can use @samp{target
10855130809Smarcelremote} again to connect once more.)  If you type @kbd{n}, @value{GDBN}
10856130809Smarcelgoes back to waiting.
10857130809Smarcel
10858130809Smarcel@table @code
10859130809Smarcel@kindex detach (remote)
10860130809Smarcel@item detach
10861130809SmarcelWhen you have finished debugging the remote program, you can use the
10862130809Smarcel@code{detach} command to release it from @value{GDBN} control.
10863130809SmarcelDetaching from the target normally resumes its execution, but the results
10864130809Smarcelwill depend on your particular remote stub.  After the @code{detach}
10865130809Smarcelcommand, @value{GDBN} is free to connect to another target.
10866130809Smarcel
10867130809Smarcel@kindex disconnect
10868130809Smarcel@item disconnect
10869130809SmarcelThe @code{disconnect} command behaves like @code{detach}, except that
10870130809Smarcelthe target is generally not resumed.  It will wait for @value{GDBN}
10871130809Smarcel(this instance or another one) to connect and continue debugging.  After
10872130809Smarcelthe @code{disconnect} command, @value{GDBN} is again free to connect to
10873130809Smarcelanother target.
10874130809Smarcel@end table
10875130809Smarcel
1087698948Sobrien@node Server
1087798948Sobrien@section Using the @code{gdbserver} program
1087819370Spst
1087998948Sobrien@kindex gdbserver
1088098948Sobrien@cindex remote connection without stubs
1088198948Sobrien@code{gdbserver} is a control program for Unix-like systems, which
1088298948Sobrienallows you to connect your program with a remote @value{GDBN} via
1088398948Sobrien@code{target remote}---but without linking in the usual debugging stub.
1088498948Sobrien
1088598948Sobrien@code{gdbserver} is not a complete replacement for the debugging stubs,
1088698948Sobrienbecause it requires essentially the same operating-system facilities
1088798948Sobrienthat @value{GDBN} itself does.  In fact, a system that can run
1088898948Sobrien@code{gdbserver} to connect to a remote @value{GDBN} could also run
1088998948Sobrien@value{GDBN} locally!  @code{gdbserver} is sometimes useful nevertheless,
1089098948Sobrienbecause it is a much smaller program than @value{GDBN} itself.  It is
1089198948Sobrienalso easier to port than all of @value{GDBN}, so you may be able to get
1089298948Sobrienstarted more quickly on a new system by using @code{gdbserver}.
1089398948SobrienFinally, if you develop code for real-time systems, you may find that
1089498948Sobrienthe tradeoffs involved in real-time operation make it more convenient to
1089598948Sobriendo as much development work as possible on another system, for example
1089698948Sobrienby cross-compiling.  You can use @code{gdbserver} to make a similar
1089798948Sobrienchoice for debugging.
1089898948Sobrien
1089998948Sobrien@value{GDBN} and @code{gdbserver} communicate via either a serial line
1090098948Sobrienor a TCP connection, using the standard @value{GDBN} remote serial
1090198948Sobrienprotocol.
1090298948Sobrien
1090398948Sobrien@table @emph
1090498948Sobrien@item On the target machine,
1090598948Sobrienyou need to have a copy of the program you want to debug.
1090698948Sobrien@code{gdbserver} does not need your program's symbol table, so you can
1090798948Sobrienstrip the program if necessary to save space.  @value{GDBN} on the host
1090898948Sobriensystem does all the symbol handling.
1090998948Sobrien
1091098948SobrienTo use the server, you must tell it how to communicate with @value{GDBN};
1091198948Sobrienthe name of your program; and the arguments for your program.  The usual
1091298948Sobriensyntax is:
1091398948Sobrien
1091498948Sobrien@smallexample
1091598948Sobrientarget> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
1091698948Sobrien@end smallexample
1091798948Sobrien
1091898948Sobrien@var{comm} is either a device name (to use a serial line) or a TCP
1091998948Sobrienhostname and portnumber.  For example, to debug Emacs with the argument
1092098948Sobrien@samp{foo.txt} and communicate with @value{GDBN} over the serial port
1092198948Sobrien@file{/dev/com1}:
1092298948Sobrien
1092398948Sobrien@smallexample
1092498948Sobrientarget> gdbserver /dev/com1 emacs foo.txt
1092598948Sobrien@end smallexample
1092698948Sobrien
1092798948Sobrien@code{gdbserver} waits passively for the host @value{GDBN} to communicate
1092898948Sobrienwith it.
1092998948Sobrien
1093098948SobrienTo use a TCP connection instead of a serial line:
1093198948Sobrien
1093298948Sobrien@smallexample
1093398948Sobrientarget> gdbserver host:2345 emacs foo.txt
1093498948Sobrien@end smallexample
1093598948Sobrien
1093698948SobrienThe only difference from the previous example is the first argument,
1093798948Sobrienspecifying that you are communicating with the host @value{GDBN} via
1093898948SobrienTCP.  The @samp{host:2345} argument means that @code{gdbserver} is to
1093998948Sobrienexpect a TCP connection from machine @samp{host} to local TCP port 2345.
1094098948Sobrien(Currently, the @samp{host} part is ignored.)  You can choose any number
1094198948Sobrienyou want for the port number as long as it does not conflict with any
1094298948SobrienTCP ports already in use on the target system (for example, @code{23} is
1094398948Sobrienreserved for @code{telnet}).@footnote{If you choose a port number that
1094498948Sobrienconflicts with another service, @code{gdbserver} prints an error message
1094598948Sobrienand exits.}  You must use the same port number with the host @value{GDBN}
1094698948Sobrien@code{target remote} command.
1094798948Sobrien
1094898948SobrienOn some targets, @code{gdbserver} can also attach to running programs.
1094998948SobrienThis is accomplished via the @code{--attach} argument.  The syntax is:
1095098948Sobrien
1095198948Sobrien@smallexample
1095298948Sobrientarget> gdbserver @var{comm} --attach @var{pid}
1095398948Sobrien@end smallexample
1095498948Sobrien
1095598948Sobrien@var{pid} is the process ID of a currently running process.  It isn't necessary
1095698948Sobriento point @code{gdbserver} at a binary for the running process.
1095798948Sobrien
10958130809Smarcel@pindex pidof
10959130809Smarcel@cindex attach to a program by name
10960130809SmarcelYou can debug processes by name instead of process ID if your target has the
10961130809Smarcel@code{pidof} utility:
1096298948Sobrien
1096398948Sobrien@smallexample
10964130809Smarceltarget> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
1096598948Sobrien@end smallexample
1096698948Sobrien
10967130809SmarcelIn case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
10968130809Smarcelhas multiple threads, most versions of @code{pidof} support the
10969130809Smarcel@code{-s} option to only return the first process ID.
1097098948Sobrien
10971130809Smarcel@item On the host machine,
10972130809Smarcelconnect to your target (@pxref{Connecting,,Connecting to a remote target}).
1097398948SobrienFor TCP connections, you must start up @code{gdbserver} prior to using
1097498948Sobrienthe @code{target remote} command.  Otherwise you may get an error whose
1097598948Sobrientext depends on the host system, but which usually looks something like
10976130809Smarcel@samp{Connection refused}.  You don't need to use the @code{load}
10977130809Smarcelcommand in @value{GDBN} when using gdbserver, since the program is
10978130809Smarcelalready on the target.
10979130809Smarcel
1098098948Sobrien@end table
1098198948Sobrien
1098298948Sobrien@node NetWare
1098398948Sobrien@section Using the @code{gdbserve.nlm} program
1098498948Sobrien
1098598948Sobrien@kindex gdbserve.nlm
1098698948Sobrien@code{gdbserve.nlm} is a control program for NetWare systems, which
1098798948Sobrienallows you to connect your program with a remote @value{GDBN} via
1098898948Sobrien@code{target remote}.
1098998948Sobrien
1099098948Sobrien@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
1099198948Sobrienusing the standard @value{GDBN} remote serial protocol.
1099298948Sobrien
1099398948Sobrien@table @emph
1099498948Sobrien@item On the target machine,
1099598948Sobrienyou need to have a copy of the program you want to debug.
1099698948Sobrien@code{gdbserve.nlm} does not need your program's symbol table, so you
1099798948Sobriencan strip the program if necessary to save space.  @value{GDBN} on the
1099898948Sobrienhost system does all the symbol handling.
1099998948Sobrien
1100098948SobrienTo use the server, you must tell it how to communicate with
1100198948Sobrien@value{GDBN}; the name of your program; and the arguments for your
1100298948Sobrienprogram.  The syntax is:
1100398948Sobrien
1100498948Sobrien@smallexample
1100598948Sobrienload gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
1100698948Sobrien              [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
1100798948Sobrien@end smallexample
1100898948Sobrien
1100998948Sobrien@var{board} and @var{port} specify the serial line; @var{baud} specifies
1101098948Sobrienthe baud rate used by the connection.  @var{port} and @var{node} default
1101198948Sobriento 0, @var{baud} defaults to 9600@dmn{bps}.
1101298948Sobrien
1101398948SobrienFor example, to debug Emacs with the argument @samp{foo.txt}and
1101498948Sobriencommunicate with @value{GDBN} over serial port number 2 or board 1
1101598948Sobrienusing a 19200@dmn{bps} connection:
1101698948Sobrien
1101798948Sobrien@smallexample
1101898948Sobrienload gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
1101998948Sobrien@end smallexample
1102098948Sobrien
11021130809Smarcel@item
11022130809SmarcelOn the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
11023130809SmarcelConnecting to a remote target}).
1102498948Sobrien
11025130809Smarcel@end table
1102698948Sobrien
11027130809Smarcel@node Remote configuration
11028130809Smarcel@section Remote configuration
11029130809Smarcel
11030130809SmarcelThe following configuration options are available when debugging remote
11031130809Smarcelprograms:
11032130809Smarcel
11033130809Smarcel@table @code
11034130809Smarcel@kindex set remote hardware-watchpoint-limit
11035130809Smarcel@kindex set remote hardware-breakpoint-limit
11036130809Smarcel@anchor{set remote hardware-watchpoint-limit}
11037130809Smarcel@anchor{set remote hardware-breakpoint-limit}
11038130809Smarcel@item set remote hardware-watchpoint-limit @var{limit}
11039130809Smarcel@itemx set remote hardware-breakpoint-limit @var{limit}
11040130809SmarcelRestrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
11041130809Smarcelwatchpoints.  A limit of -1, the default, is treated as unlimited.
1104298948Sobrien@end table
1104398948Sobrien
1104498948Sobrien@node remote stub
1104598948Sobrien@section Implementing a remote stub
1104698948Sobrien
1104798948Sobrien@cindex debugging stub, example
1104898948Sobrien@cindex remote stub, example
1104998948Sobrien@cindex stub example, remote debugging
1105098948SobrienThe stub files provided with @value{GDBN} implement the target side of the
1105198948Sobriencommunication protocol, and the @value{GDBN} side is implemented in the
1105298948Sobrien@value{GDBN} source file @file{remote.c}.  Normally, you can simply allow
1105398948Sobrienthese subroutines to communicate, and ignore the details.  (If you're
1105498948Sobrienimplementing your own stub file, you can still ignore the details: start
1105598948Sobrienwith one of the existing stub files.  @file{sparc-stub.c} is the best
1105698948Sobrienorganized, and therefore the easiest to read.)
1105798948Sobrien
1105898948Sobrien@cindex remote serial debugging, overview
1105998948SobrienTo debug a program running on another machine (the debugging
1106098948Sobrien@dfn{target} machine), you must first arrange for all the usual
1106198948Sobrienprerequisites for the program to run by itself.  For example, for a C
1106298948Sobrienprogram, you need:
1106398948Sobrien
1106498948Sobrien@enumerate
1106598948Sobrien@item
1106698948SobrienA startup routine to set up the C runtime environment; these usually
1106798948Sobrienhave a name like @file{crt0}.  The startup routine may be supplied by
1106898948Sobrienyour hardware supplier, or you may have to write your own.
1106998948Sobrien
1107098948Sobrien@item
1107198948SobrienA C subroutine library to support your program's
1107298948Sobriensubroutine calls, notably managing input and output.
1107398948Sobrien
1107498948Sobrien@item
1107598948SobrienA way of getting your program to the other machine---for example, a
1107698948Sobriendownload program.  These are often supplied by the hardware
1107798948Sobrienmanufacturer, but you may have to write your own from hardware
1107898948Sobriendocumentation.
1107998948Sobrien@end enumerate
1108098948Sobrien
1108198948SobrienThe next step is to arrange for your program to use a serial port to
1108298948Sobriencommunicate with the machine where @value{GDBN} is running (the @dfn{host}
1108398948Sobrienmachine).  In general terms, the scheme looks like this:
1108498948Sobrien
1108598948Sobrien@table @emph
1108698948Sobrien@item On the host,
1108798948Sobrien@value{GDBN} already understands how to use this protocol; when everything
1108898948Sobrienelse is set up, you can simply use the @samp{target remote} command
1108998948Sobrien(@pxref{Targets,,Specifying a Debugging Target}).
1109098948Sobrien
1109198948Sobrien@item On the target,
1109298948Sobrienyou must link with your program a few special-purpose subroutines that
1109398948Sobrienimplement the @value{GDBN} remote serial protocol.  The file containing these
1109498948Sobriensubroutines is called  a @dfn{debugging stub}.
1109598948Sobrien
1109698948SobrienOn certain remote targets, you can use an auxiliary program
1109798948Sobrien@code{gdbserver} instead of linking a stub into your program.
1109898948Sobrien@xref{Server,,Using the @code{gdbserver} program}, for details.
1109998948Sobrien@end table
1110098948Sobrien
1110198948SobrienThe debugging stub is specific to the architecture of the remote
1110298948Sobrienmachine; for example, use @file{sparc-stub.c} to debug programs on
1110398948Sobrien@sc{sparc} boards.
1110498948Sobrien
1110598948Sobrien@cindex remote serial stub list
1110698948SobrienThese working remote stubs are distributed with @value{GDBN}:
1110798948Sobrien
1110898948Sobrien@table @code
1110998948Sobrien
1111098948Sobrien@item i386-stub.c
1111198948Sobrien@cindex @file{i386-stub.c}
1111298948Sobrien@cindex Intel
1111398948Sobrien@cindex i386
1111498948SobrienFor Intel 386 and compatible architectures.
1111598948Sobrien
1111698948Sobrien@item m68k-stub.c
1111798948Sobrien@cindex @file{m68k-stub.c}
1111898948Sobrien@cindex Motorola 680x0
1111998948Sobrien@cindex m680x0
1112098948SobrienFor Motorola 680x0 architectures.
1112198948Sobrien
1112298948Sobrien@item sh-stub.c
1112398948Sobrien@cindex @file{sh-stub.c}
11124130809Smarcel@cindex Renesas
1112598948Sobrien@cindex SH
11126130809SmarcelFor Renesas SH architectures.
1112798948Sobrien
1112898948Sobrien@item sparc-stub.c
1112998948Sobrien@cindex @file{sparc-stub.c}
1113098948Sobrien@cindex Sparc
1113198948SobrienFor @sc{sparc} architectures.
1113298948Sobrien
1113398948Sobrien@item sparcl-stub.c
1113498948Sobrien@cindex @file{sparcl-stub.c}
1113598948Sobrien@cindex Fujitsu
1113698948Sobrien@cindex SparcLite
1113798948SobrienFor Fujitsu @sc{sparclite} architectures.
1113898948Sobrien
1113998948Sobrien@end table
1114098948Sobrien
1114198948SobrienThe @file{README} file in the @value{GDBN} distribution may list other
1114298948Sobrienrecently added stubs.
1114398948Sobrien
1114498948Sobrien@menu
1114598948Sobrien* Stub Contents::       What the stub can do for you
1114698948Sobrien* Bootstrapping::       What you must do for the stub
1114798948Sobrien* Debug Session::       Putting it all together
1114898948Sobrien@end menu
1114998948Sobrien
1115098948Sobrien@node Stub Contents
1115198948Sobrien@subsection What the stub can do for you
1115298948Sobrien
1115398948Sobrien@cindex remote serial stub
1115498948SobrienThe debugging stub for your architecture supplies these three
1115598948Sobriensubroutines:
1115698948Sobrien
1115798948Sobrien@table @code
1115898948Sobrien@item set_debug_traps
1115998948Sobrien@kindex set_debug_traps
1116098948Sobrien@cindex remote serial stub, initialization
1116198948SobrienThis routine arranges for @code{handle_exception} to run when your
1116298948Sobrienprogram stops.  You must call this subroutine explicitly near the
1116398948Sobrienbeginning of your program.
1116498948Sobrien
1116598948Sobrien@item handle_exception
1116698948Sobrien@kindex handle_exception
1116798948Sobrien@cindex remote serial stub, main routine
1116898948SobrienThis is the central workhorse, but your program never calls it
1116998948Sobrienexplicitly---the setup code arranges for @code{handle_exception} to
1117098948Sobrienrun when a trap is triggered.
1117198948Sobrien
1117298948Sobrien@code{handle_exception} takes control when your program stops during
1117398948Sobrienexecution (for example, on a breakpoint), and mediates communications
1117498948Sobrienwith @value{GDBN} on the host machine.  This is where the communications
1117598948Sobrienprotocol is implemented; @code{handle_exception} acts as the @value{GDBN}
1117698948Sobrienrepresentative on the target machine.  It begins by sending summary
1117798948Sobrieninformation on the state of your program, then continues to execute,
1117898948Sobrienretrieving and transmitting any information @value{GDBN} needs, until you
1117998948Sobrienexecute a @value{GDBN} command that makes your program resume; at that point,
1118098948Sobrien@code{handle_exception} returns control to your own code on the target
1118198948Sobrienmachine.
1118298948Sobrien
1118398948Sobrien@item breakpoint
1118498948Sobrien@cindex @code{breakpoint} subroutine, remote
1118598948SobrienUse this auxiliary subroutine to make your program contain a
1118698948Sobrienbreakpoint.  Depending on the particular situation, this may be the only
1118798948Sobrienway for @value{GDBN} to get control.  For instance, if your target
1118898948Sobrienmachine has some sort of interrupt button, you won't need to call this;
1118998948Sobrienpressing the interrupt button transfers control to
1119098948Sobrien@code{handle_exception}---in effect, to @value{GDBN}.  On some machines,
1119198948Sobriensimply receiving characters on the serial port may also trigger a trap;
1119298948Sobrienagain, in that situation, you don't need to call @code{breakpoint} from
1119398948Sobrienyour own program---simply running @samp{target remote} from the host
1119498948Sobrien@value{GDBN} session gets control.
1119598948Sobrien
1119698948SobrienCall @code{breakpoint} if none of these is true, or if you simply want
1119798948Sobriento make certain your program stops at a predetermined point for the
1119898948Sobrienstart of your debugging session.
1119998948Sobrien@end table
1120098948Sobrien
1120198948Sobrien@node Bootstrapping
1120298948Sobrien@subsection What you must do for the stub
1120398948Sobrien
1120498948Sobrien@cindex remote stub, support routines
1120598948SobrienThe debugging stubs that come with @value{GDBN} are set up for a particular
1120698948Sobrienchip architecture, but they have no information about the rest of your
1120798948Sobriendebugging target machine.
1120898948Sobrien
1120998948SobrienFirst of all you need to tell the stub how to communicate with the
1121098948Sobrienserial port.
1121198948Sobrien
1121298948Sobrien@table @code
1121398948Sobrien@item int getDebugChar()
1121498948Sobrien@kindex getDebugChar
1121598948SobrienWrite this subroutine to read a single character from the serial port.
1121698948SobrienIt may be identical to @code{getchar} for your target system; a
1121798948Sobriendifferent name is used to allow you to distinguish the two if you wish.
1121898948Sobrien
1121998948Sobrien@item void putDebugChar(int)
1122098948Sobrien@kindex putDebugChar
1122198948SobrienWrite this subroutine to write a single character to the serial port.
1122298948SobrienIt may be identical to @code{putchar} for your target system; a
1122398948Sobriendifferent name is used to allow you to distinguish the two if you wish.
1122498948Sobrien@end table
1122598948Sobrien
1122698948Sobrien@cindex control C, and remote debugging
1122798948Sobrien@cindex interrupting remote targets
1122898948SobrienIf you want @value{GDBN} to be able to stop your program while it is
1122998948Sobrienrunning, you need to use an interrupt-driven serial driver, and arrange
1123098948Sobrienfor it to stop when it receives a @code{^C} (@samp{\003}, the control-C
1123198948Sobriencharacter).  That is the character which @value{GDBN} uses to tell the
1123298948Sobrienremote system to stop.
1123398948Sobrien
1123498948SobrienGetting the debugging target to return the proper status to @value{GDBN}
1123598948Sobrienprobably requires changes to the standard stub; one quick and dirty way
1123698948Sobrienis to just execute a breakpoint instruction (the ``dirty'' part is that
1123798948Sobrien@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
1123898948Sobrien
1123998948SobrienOther routines you need to supply are:
1124098948Sobrien
1124198948Sobrien@table @code
1124298948Sobrien@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
1124398948Sobrien@kindex exceptionHandler
1124498948SobrienWrite this function to install @var{exception_address} in the exception
1124598948Sobrienhandling tables.  You need to do this because the stub does not have any
1124698948Sobrienway of knowing what the exception handling tables on your target system
1124798948Sobrienare like (for example, the processor's table might be in @sc{rom},
1124898948Sobriencontaining entries which point to a table in @sc{ram}).
1124998948Sobrien@var{exception_number} is the exception number which should be changed;
1125098948Sobrienits meaning is architecture-dependent (for example, different numbers
1125198948Sobrienmight represent divide by zero, misaligned access, etc).  When this
1125298948Sobrienexception occurs, control should be transferred directly to
1125398948Sobrien@var{exception_address}, and the processor state (stack, registers,
1125498948Sobrienand so on) should be just as it is when a processor exception occurs.  So if
1125598948Sobrienyou want to use a jump instruction to reach @var{exception_address}, it
1125698948Sobrienshould be a simple jump, not a jump to subroutine.
1125798948Sobrien
1125898948SobrienFor the 386, @var{exception_address} should be installed as an interrupt
1125998948Sobriengate so that interrupts are masked while the handler runs.  The gate
1126098948Sobrienshould be at privilege level 0 (the most privileged level).  The
1126198948Sobrien@sc{sparc} and 68k stubs are able to mask interrupts themselves without
1126298948Sobrienhelp from @code{exceptionHandler}.
1126398948Sobrien
1126498948Sobrien@item void flush_i_cache()
1126598948Sobrien@kindex flush_i_cache
1126698948SobrienOn @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
1126798948Sobrieninstruction cache, if any, on your target machine.  If there is no
1126898948Sobrieninstruction cache, this subroutine may be a no-op.
1126998948Sobrien
1127098948SobrienOn target machines that have instruction caches, @value{GDBN} requires this
1127198948Sobrienfunction to make certain that the state of your program is stable.
1127298948Sobrien@end table
1127398948Sobrien
1127498948Sobrien@noindent
1127598948SobrienYou must also make sure this library routine is available:
1127698948Sobrien
1127798948Sobrien@table @code
1127898948Sobrien@item void *memset(void *, int, int)
1127998948Sobrien@kindex memset
1128098948SobrienThis is the standard library function @code{memset} that sets an area of
1128198948Sobrienmemory to a known value.  If you have one of the free versions of
1128298948Sobrien@code{libc.a}, @code{memset} can be found there; otherwise, you must
1128398948Sobrieneither obtain it from your hardware manufacturer, or write your own.
1128498948Sobrien@end table
1128598948Sobrien
1128698948SobrienIf you do not use the GNU C compiler, you may need other standard
1128798948Sobrienlibrary subroutines as well; this varies from one stub to another,
1128898948Sobrienbut in general the stubs are likely to use any of the common library
1128998948Sobriensubroutines which @code{@value{GCC}} generates as inline code.
1129098948Sobrien
1129198948Sobrien
1129298948Sobrien@node Debug Session
1129398948Sobrien@subsection Putting it all together
1129498948Sobrien
1129598948Sobrien@cindex remote serial debugging summary
1129698948SobrienIn summary, when your program is ready to debug, you must follow these
1129798948Sobriensteps.
1129898948Sobrien
1129998948Sobrien@enumerate
1130098948Sobrien@item
1130198948SobrienMake sure you have defined the supporting low-level routines
1130298948Sobrien(@pxref{Bootstrapping,,What you must do for the stub}):
1130398948Sobrien@display
1130498948Sobrien@code{getDebugChar}, @code{putDebugChar},
1130598948Sobrien@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
1130698948Sobrien@end display
1130798948Sobrien
1130898948Sobrien@item
1130998948SobrienInsert these lines near the top of your program:
1131098948Sobrien
11311130809Smarcel@smallexample
1131298948Sobrienset_debug_traps();
1131398948Sobrienbreakpoint();
11314130809Smarcel@end smallexample
1131598948Sobrien
1131698948Sobrien@item
1131798948SobrienFor the 680x0 stub only, you need to provide a variable called
1131898948Sobrien@code{exceptionHook}.  Normally you just use:
1131998948Sobrien
11320130809Smarcel@smallexample
1132198948Sobrienvoid (*exceptionHook)() = 0;
11322130809Smarcel@end smallexample
1132398948Sobrien
1132498948Sobrien@noindent
1132598948Sobrienbut if before calling @code{set_debug_traps}, you set it to point to a
1132698948Sobrienfunction in your program, that function is called when
1132798948Sobrien@code{@value{GDBN}} continues after stopping on a trap (for example, bus
1132898948Sobrienerror).  The function indicated by @code{exceptionHook} is called with
1132998948Sobrienone parameter: an @code{int} which is the exception number.
1133098948Sobrien
1133198948Sobrien@item
1133298948SobrienCompile and link together: your program, the @value{GDBN} debugging stub for
1133398948Sobrienyour target architecture, and the supporting subroutines.
1133498948Sobrien
1133598948Sobrien@item
1133698948SobrienMake sure you have a serial connection between your target machine and
1133798948Sobrienthe @value{GDBN} host, and identify the serial port on the host.
1133898948Sobrien
1133998948Sobrien@item
1134098948Sobrien@c The "remote" target now provides a `load' command, so we should
1134198948Sobrien@c document that.  FIXME.
1134298948SobrienDownload your program to your target machine (or get it there by
1134398948Sobrienwhatever means the manufacturer provides), and start it.
1134498948Sobrien
1134598948Sobrien@item
11346130809SmarcelStart @value{GDBN} on the host, and connect to the target
11347130809Smarcel(@pxref{Connecting,,Connecting to a remote target}).
1134898948Sobrien
1134998948Sobrien@end enumerate
1135098948Sobrien
1135198948Sobrien@node Configurations
1135298948Sobrien@chapter Configuration-Specific Information
1135398948Sobrien
1135498948SobrienWhile nearly all @value{GDBN} commands are available for all native and
1135598948Sobriencross versions of the debugger, there are some exceptions.  This chapter
1135698948Sobriendescribes things that are only available in certain configurations.
1135798948Sobrien
1135898948SobrienThere are three major categories of configurations: native
1135998948Sobrienconfigurations, where the host and target are the same, embedded
1136098948Sobrienoperating system configurations, which are usually the same for several
1136198948Sobriendifferent processor architectures, and bare embedded processors, which
1136298948Sobrienare quite different from each other.
1136398948Sobrien
1136498948Sobrien@menu
1136598948Sobrien* Native::
1136698948Sobrien* Embedded OS::
1136798948Sobrien* Embedded Processors::
1136898948Sobrien* Architectures::
1136998948Sobrien@end menu
1137098948Sobrien
1137198948Sobrien@node Native
1137298948Sobrien@section Native
1137398948Sobrien
1137498948SobrienThis section describes details specific to particular native
1137598948Sobrienconfigurations.
1137698948Sobrien
1137798948Sobrien@menu
1137898948Sobrien* HP-UX::                       HP-UX
1137998948Sobrien* SVR4 Process Information::    SVR4 process information
1138098948Sobrien* DJGPP Native::                Features specific to the DJGPP port
1138198948Sobrien* Cygwin Native::		Features specific to the Cygwin port
1138298948Sobrien@end menu
1138398948Sobrien
1138498948Sobrien@node HP-UX
1138598948Sobrien@subsection HP-UX
1138698948Sobrien
1138798948SobrienOn HP-UX systems, if you refer to a function or variable name that
1138898948Sobrienbegins with a dollar sign, @value{GDBN} searches for a user or system
1138998948Sobrienname first, before it searches for a convenience variable.
1139098948Sobrien
1139198948Sobrien@node SVR4 Process Information
1139298948Sobrien@subsection SVR4 process information
1139398948Sobrien
1139498948Sobrien@kindex /proc
1139598948Sobrien@cindex process image
1139698948Sobrien
1139798948SobrienMany versions of SVR4 provide a facility called @samp{/proc} that can be
1139898948Sobrienused to examine the image of a running process using file-system
1139998948Sobriensubroutines.  If @value{GDBN} is configured for an operating system with
1140098948Sobrienthis facility, the command @code{info proc} is available to report on
1140198948Sobrienseveral kinds of information about the process running your program.
1140298948Sobrien@code{info proc} works only on SVR4 systems that include the
1140398948Sobrien@code{procfs} code.  This includes OSF/1 (Digital Unix), Solaris, Irix,
11404130809Smarceland Unixware, but not HP-UX or @sc{gnu}/Linux, for example.
1140598948Sobrien
1140698948Sobrien@table @code
1140798948Sobrien@kindex info proc
1140898948Sobrien@item info proc
1140998948SobrienSummarize available information about the process.
1141098948Sobrien
1141198948Sobrien@kindex info proc mappings
1141298948Sobrien@item info proc mappings
1141398948SobrienReport on the address ranges accessible in the program, with information
1141498948Sobrienon whether your program may read, write, or execute each range.
1141598948Sobrien@ignore
1141698948Sobrien@comment These sub-options of 'info proc' were not included when
1141798948Sobrien@comment procfs.c was re-written.  Keep their descriptions around
1141898948Sobrien@comment against the day when someone finds the time to put them back in.
1141998948Sobrien@kindex info proc times
1142098948Sobrien@item info proc times
1142198948SobrienStarting time, user CPU time, and system CPU time for your program and
1142298948Sobrienits children.
1142398948Sobrien
1142498948Sobrien@kindex info proc id
1142598948Sobrien@item info proc id
1142698948SobrienReport on the process IDs related to your program: its own process ID,
1142798948Sobrienthe ID of its parent, the process group ID, and the session ID.
1142898948Sobrien
1142998948Sobrien@kindex info proc status
1143098948Sobrien@item info proc status
1143198948SobrienGeneral information on the state of the process.  If the process is
1143298948Sobrienstopped, this report includes the reason for stopping, and any signal
1143398948Sobrienreceived.
1143498948Sobrien
1143598948Sobrien@item info proc all
1143698948SobrienShow all the above information about the process.
1143798948Sobrien@end ignore
1143898948Sobrien@end table
1143998948Sobrien
1144098948Sobrien@node DJGPP Native
1144198948Sobrien@subsection Features for Debugging @sc{djgpp} Programs
1144298948Sobrien@cindex @sc{djgpp} debugging
1144398948Sobrien@cindex native @sc{djgpp} debugging
1144498948Sobrien@cindex MS-DOS-specific commands
1144598948Sobrien
1144698948Sobrien@sc{djgpp} is the port of @sc{gnu} development tools to MS-DOS and
1144798948SobrienMS-Windows.  @sc{djgpp} programs are 32-bit protected-mode programs
1144898948Sobrienthat use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
1144998948Sobrientop of real-mode DOS systems and their emulations.
1145098948Sobrien
1145198948Sobrien@value{GDBN} supports native debugging of @sc{djgpp} programs, and
1145298948Sobriendefines a few commands specific to the @sc{djgpp} port.  This
1145398948Sobriensubsection describes those commands.
1145498948Sobrien
1145598948Sobrien@table @code
1145698948Sobrien@kindex info dos
1145798948Sobrien@item info dos
1145898948SobrienThis is a prefix of @sc{djgpp}-specific commands which print
1145998948Sobrieninformation about the target system and important OS structures.
1146098948Sobrien
1146198948Sobrien@kindex sysinfo
1146298948Sobrien@cindex MS-DOS system info
1146398948Sobrien@cindex free memory information (MS-DOS)
1146498948Sobrien@item info dos sysinfo
1146598948SobrienThis command displays assorted information about the underlying
1146698948Sobrienplatform: the CPU type and features, the OS version and flavor, the
1146798948SobrienDPMI version, and the available conventional and DPMI memory.
1146898948Sobrien
1146998948Sobrien@cindex GDT
1147098948Sobrien@cindex LDT
1147198948Sobrien@cindex IDT
1147298948Sobrien@cindex segment descriptor tables
1147398948Sobrien@cindex descriptor tables display
1147498948Sobrien@item info dos gdt
1147598948Sobrien@itemx info dos ldt
1147698948Sobrien@itemx info dos idt
1147798948SobrienThese 3 commands display entries from, respectively, Global, Local,
1147898948Sobrienand Interrupt Descriptor Tables (GDT, LDT, and IDT).  The descriptor
1147998948Sobrientables are data structures which store a descriptor for each segment
1148098948Sobrienthat is currently in use.  The segment's selector is an index into a
1148198948Sobriendescriptor table; the table entry for that index holds the
1148298948Sobriendescriptor's base address and limit, and its attributes and access
1148398948Sobrienrights.
1148498948Sobrien
1148598948SobrienA typical @sc{djgpp} program uses 3 segments: a code segment, a data
1148698948Sobriensegment (used for both data and the stack), and a DOS segment (which
1148798948Sobrienallows access to DOS/BIOS data structures and absolute addresses in
1148898948Sobrienconventional memory).  However, the DPMI host will usually define
1148998948Sobrienadditional segments in order to support the DPMI environment.
1149098948Sobrien
1149198948Sobrien@cindex garbled pointers
1149298948SobrienThese commands allow to display entries from the descriptor tables.
1149398948SobrienWithout an argument, all entries from the specified table are
1149498948Sobriendisplayed.  An argument, which should be an integer expression, means
1149598948Sobriendisplay a single entry whose index is given by the argument.  For
1149698948Sobrienexample, here's a convenient way to display information about the
1149798948Sobriendebugged program's data segment:
1149898948Sobrien
1149998948Sobrien@smallexample
1150098948Sobrien@exdent @code{(@value{GDBP}) info dos ldt $ds}
1150198948Sobrien@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
1150298948Sobrien@end smallexample
1150398948Sobrien
1150498948Sobrien@noindent
1150598948SobrienThis comes in handy when you want to see whether a pointer is outside
1150698948Sobrienthe data segment's limit (i.e.@: @dfn{garbled}).
1150798948Sobrien
1150898948Sobrien@cindex page tables display (MS-DOS)
1150998948Sobrien@item info dos pde
1151098948Sobrien@itemx info dos pte
1151198948SobrienThese two commands display entries from, respectively, the Page
1151298948SobrienDirectory and the Page Tables.  Page Directories and Page Tables are
1151398948Sobriendata structures which control how virtual memory addresses are mapped
1151498948Sobrieninto physical addresses.  A Page Table includes an entry for every
1151598948Sobrienpage of memory that is mapped into the program's address space; there
1151698948Sobrienmay be several Page Tables, each one holding up to 4096 entries.  A
1151798948SobrienPage Directory has up to 4096 entries, one each for every Page Table
1151898948Sobrienthat is currently in use.
1151998948Sobrien
1152098948SobrienWithout an argument, @kbd{info dos pde} displays the entire Page
1152198948SobrienDirectory, and @kbd{info dos pte} displays all the entries in all of
1152298948Sobrienthe Page Tables.  An argument, an integer expression, given to the
1152398948Sobrien@kbd{info dos pde} command means display only that entry from the Page
1152498948SobrienDirectory table.  An argument given to the @kbd{info dos pte} command
1152598948Sobrienmeans display entries from a single Page Table, the one pointed to by
1152698948Sobrienthe specified entry in the Page Directory.
1152798948Sobrien
1152898948Sobrien@cindex direct memory access (DMA) on MS-DOS
1152998948SobrienThese commands are useful when your program uses @dfn{DMA} (Direct
1153098948SobrienMemory Access), which needs physical addresses to program the DMA
1153198948Sobriencontroller.
1153298948Sobrien
1153398948SobrienThese commands are supported only with some DPMI servers.
1153498948Sobrien
1153598948Sobrien@cindex physical address from linear address
1153698948Sobrien@item info dos address-pte @var{addr}
1153798948SobrienThis command displays the Page Table entry for a specified linear
1153898948Sobrienaddress.  The argument linear address @var{addr} should already have the
1153998948Sobrienappropriate segment's base address added to it, because this command
1154098948Sobrienaccepts addresses which may belong to @emph{any} segment.  For
1154198948Sobrienexample, here's how to display the Page Table entry for the page where
1154298948Sobrienthe variable @code{i} is stored:
1154398948Sobrien
11544130809Smarcel@smallexample
1154598948Sobrien@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
1154698948Sobrien@exdent @code{Page Table entry for address 0x11a00d30:}
11547130809Smarcel@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
1154898948Sobrien@end smallexample
1154998948Sobrien
1155098948Sobrien@noindent
1155198948SobrienThis says that @code{i} is stored at offset @code{0xd30} from the page
1155298948Sobrienwhose physical base address is @code{0x02698000}, and prints all the
1155398948Sobrienattributes of that page.
1155498948Sobrien
1155598948SobrienNote that you must cast the addresses of variables to a @code{char *},
1155698948Sobriensince otherwise the value of @code{__djgpp_base_address}, the base
1155798948Sobrienaddress of all variables and functions in a @sc{djgpp} program, will
1155898948Sobrienbe added using the rules of C pointer arithmetics: if @code{i} is
1155998948Sobriendeclared an @code{int}, @value{GDBN} will add 4 times the value of
1156098948Sobrien@code{__djgpp_base_address} to the address of @code{i}.
1156198948Sobrien
1156298948SobrienHere's another example, it displays the Page Table entry for the
1156398948Sobrientransfer buffer:
1156498948Sobrien
1156598948Sobrien@smallexample
1156698948Sobrien@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
1156798948Sobrien@exdent @code{Page Table entry for address 0x29110:}
1156898948Sobrien@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
1156998948Sobrien@end smallexample
1157098948Sobrien
1157198948Sobrien@noindent
1157298948Sobrien(The @code{+ 3} offset is because the transfer buffer's address is the
1157398948Sobrien3rd member of the @code{_go32_info_block} structure.)  The output of
1157498948Sobrienthis command clearly shows that addresses in conventional memory are
1157598948Sobrienmapped 1:1, i.e.@: the physical and linear addresses are identical.
1157698948Sobrien
1157798948SobrienThis command is supported only with some DPMI servers.
1157898948Sobrien@end table
1157998948Sobrien
1158098948Sobrien@node Cygwin Native
1158198948Sobrien@subsection Features for Debugging MS Windows PE executables
1158298948Sobrien@cindex MS Windows debugging
1158398948Sobrien@cindex native Cygwin debugging
1158498948Sobrien@cindex Cygwin-specific commands
1158598948Sobrien
11586130809Smarcel@value{GDBN} supports native debugging of MS Windows programs, including
11587130809SmarcelDLLs with and without symbolic debugging information. There are various
11588130809Smarceladditional Cygwin-specific commands, described in this subsection.  The
11589130809Smarcelsubsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
11590130809Smarcelthat have no debugging symbols.
1159198948Sobrien
11592130809Smarcel
1159398948Sobrien@table @code
1159498948Sobrien@kindex info w32
1159598948Sobrien@item info w32
1159698948SobrienThis is a prefix of MS Windows specific commands which print
1159798948Sobrieninformation about the target system and important OS structures.
1159898948Sobrien
1159998948Sobrien@item info w32 selector
1160098948SobrienThis command displays information returned by
1160198948Sobrienthe Win32 API @code{GetThreadSelectorEntry} function.
1160298948SobrienIt takes an optional argument that is evaluated to
1160398948Sobriena long value to give the information about this given selector.
1160498948SobrienWithout argument, this command displays information
1160598948Sobrienabout the the six segment registers.
1160698948Sobrien
1160798948Sobrien@kindex info dll
1160898948Sobrien@item info dll
1160998948SobrienThis is a Cygwin specific alias of info shared.
1161098948Sobrien
1161198948Sobrien@kindex dll-symbols
1161298948Sobrien@item dll-symbols
1161398948SobrienThis command loads symbols from a dll similarly to
1161498948Sobrienadd-sym command but without the need to specify a base address.
1161598948Sobrien
11616130809Smarcel@kindex set new-console
1161798948Sobrien@item set new-console @var{mode}
11618130809SmarcelIf @var{mode} is @code{on} the debuggee will
1161998948Sobrienbe started in a new console on next start.
1162098948SobrienIf @var{mode} is @code{off}i, the debuggee will
1162198948Sobrienbe started in the same console as the debugger.
1162298948Sobrien
1162398948Sobrien@kindex show new-console
1162498948Sobrien@item show new-console
1162598948SobrienDisplays whether a new console is used
1162698948Sobrienwhen the debuggee is started.
1162798948Sobrien
1162898948Sobrien@kindex set new-group
1162998948Sobrien@item set new-group @var{mode}
1163098948SobrienThis boolean value controls whether the debuggee should
1163198948Sobrienstart a new group or stay in the same group as the debugger.
1163298948SobrienThis affects the way the Windows OS handles
1163398948SobrienCtrl-C.
1163498948Sobrien
1163598948Sobrien@kindex show new-group
1163698948Sobrien@item show new-group
1163798948SobrienDisplays current value of new-group boolean.
1163898948Sobrien
1163998948Sobrien@kindex set debugevents
1164098948Sobrien@item set debugevents
1164198948SobrienThis boolean value adds debug output concerning events seen by the debugger.
1164298948Sobrien
1164398948Sobrien@kindex set debugexec
1164498948Sobrien@item set debugexec
11645130809SmarcelThis boolean value adds debug output concerning execute events
1164698948Sobrienseen by the debugger.
1164798948Sobrien
1164898948Sobrien@kindex set debugexceptions
1164998948Sobrien@item set debugexceptions
11650130809SmarcelThis boolean value adds debug ouptut concerning exception events
1165198948Sobrienseen by the debugger.
1165298948Sobrien
1165398948Sobrien@kindex set debugmemory
1165498948Sobrien@item set debugmemory
11655130809SmarcelThis boolean value adds debug ouptut concerning memory events
1165698948Sobrienseen by the debugger.
1165798948Sobrien
1165898948Sobrien@kindex set shell
1165998948Sobrien@item set shell
1166098948SobrienThis boolean values specifies whether the debuggee is called
1166198948Sobrienvia a shell or directly (default value is on).
1166298948Sobrien
1166398948Sobrien@kindex show shell
1166498948Sobrien@item show shell
1166598948SobrienDisplays if the debuggee will be started with a shell.
1166698948Sobrien
1166798948Sobrien@end table
1166898948Sobrien
11669130809Smarcel@menu
11670130809Smarcel* Non-debug DLL symbols::  Support for DLLs without debugging symbols
11671130809Smarcel@end menu
11672130809Smarcel
11673130809Smarcel@node Non-debug DLL symbols
11674130809Smarcel@subsubsection Support for DLLs without debugging symbols
11675130809Smarcel@cindex DLLs with no debugging symbols
11676130809Smarcel@cindex Minimal symbols and DLLs
11677130809Smarcel
11678130809SmarcelVery often on windows, some of the DLLs that your program relies on do
11679130809Smarcelnot include symbolic debugging information (for example,
11680130809Smarcel@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
11681130809Smarcelsymbols in a DLL, it relies on the minimal amount of symbolic
11682130809Smarcelinformation contained in the DLL's export table. This subsubsection
11683130809Smarceldescribes working with such symbols, known internally to @value{GDBN} as
11684130809Smarcel``minimal symbols''.
11685130809Smarcel
11686130809SmarcelNote that before the debugged program has started execution, no DLLs
11687130809Smarcelwill have been loaded. The easiest way around this problem is simply to
11688130809Smarcelstart the program --- either by setting a breakpoint or letting the
11689130809Smarcelprogram run once to completion. It is also possible to force
11690130809Smarcel@value{GDBN} to load a particular DLL before starting the executable ---
11691130809Smarcelsee the shared library information in @pxref{Files} or the
11692130809Smarcel@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
11693130809Smarcelexplicitly loading symbols from a DLL with no debugging information will
11694130809Smarcelcause the symbol names to be duplicated in @value{GDBN}'s lookup table,
11695130809Smarcelwhich may adversely affect symbol lookup performance.
11696130809Smarcel
11697130809Smarcel@subsubsection DLL name prefixes
11698130809Smarcel
11699130809SmarcelIn keeping with the naming conventions used by the Microsoft debugging
11700130809Smarceltools, DLL export symbols are made available with a prefix based on the
11701130809SmarcelDLL name, for instance @code{KERNEL32!CreateFileA}.  The plain name is
11702130809Smarcelalso entered into the symbol table, so @code{CreateFileA} is often
11703130809Smarcelsufficient. In some cases there will be name clashes within a program
11704130809Smarcel(particularly if the executable itself includes full debugging symbols)
11705130809Smarcelnecessitating the use of the fully qualified name when referring to the
11706130809Smarcelcontents of the DLL. Use single-quotes around the name to avoid the
11707130809Smarcelexclamation mark (``!'')  being interpreted as a language operator.
11708130809Smarcel
11709130809SmarcelNote that the internal name of the DLL may be all upper-case, even
11710130809Smarcelthough the file name of the DLL is lower-case, or vice-versa. Since
11711130809Smarcelsymbols within @value{GDBN} are @emph{case-sensitive} this may cause
11712130809Smarcelsome confusion. If in doubt, try the @code{info functions} and
11713130809Smarcel@code{info variables} commands or even @code{maint print msymbols} (see
11714130809Smarcel@pxref{Symbols}). Here's an example:
11715130809Smarcel
11716130809Smarcel@smallexample
11717130809Smarcel(gdb) info function CreateFileA
11718130809SmarcelAll functions matching regular expression "CreateFileA":
11719130809Smarcel
11720130809SmarcelNon-debugging symbols:
11721130809Smarcel0x77e885f4  CreateFileA
11722130809Smarcel0x77e885f4  KERNEL32!CreateFileA
11723130809Smarcel@end smallexample
11724130809Smarcel
11725130809Smarcel@smallexample
11726130809Smarcel(gdb) info function !
11727130809SmarcelAll functions matching regular expression "!":
11728130809Smarcel
11729130809SmarcelNon-debugging symbols:
11730130809Smarcel0x6100114c  cygwin1!__assert
11731130809Smarcel0x61004034  cygwin1!_dll_crt0@@0
11732130809Smarcel0x61004240  cygwin1!dll_crt0(per_process *)
11733130809Smarcel[etc...]
11734130809Smarcel@end smallexample
11735130809Smarcel
11736130809Smarcel@subsubsection Working with minimal symbols
11737130809Smarcel
11738130809SmarcelSymbols extracted from a DLL's export table do not contain very much
11739130809Smarceltype information. All that @value{GDBN} can do is guess whether a symbol
11740130809Smarcelrefers to a function or variable depending on the linker section that
11741130809Smarcelcontains the symbol. Also note that the actual contents of the memory
11742130809Smarcelcontained in a DLL are not available unless the program is running. This
11743130809Smarcelmeans that you cannot examine the contents of a variable or disassemble
11744130809Smarcela function within a DLL without a running program.
11745130809Smarcel
11746130809SmarcelVariables are generally treated as pointers and dereferenced
11747130809Smarcelautomatically. For this reason, it is often necessary to prefix a
11748130809Smarcelvariable name with the address-of operator (``&'') and provide explicit
11749130809Smarceltype information in the command. Here's an example of the type of
11750130809Smarcelproblem:
11751130809Smarcel
11752130809Smarcel@smallexample
11753130809Smarcel(gdb) print 'cygwin1!__argv'
11754130809Smarcel$1 = 268572168
11755130809Smarcel@end smallexample
11756130809Smarcel
11757130809Smarcel@smallexample
11758130809Smarcel(gdb) x 'cygwin1!__argv'
11759130809Smarcel0x10021610:      "\230y\""
11760130809Smarcel@end smallexample
11761130809Smarcel
11762130809SmarcelAnd two possible solutions:
11763130809Smarcel
11764130809Smarcel@smallexample
11765130809Smarcel(gdb) print ((char **)'cygwin1!__argv')[0]
11766130809Smarcel$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
11767130809Smarcel@end smallexample
11768130809Smarcel
11769130809Smarcel@smallexample
11770130809Smarcel(gdb) x/2x &'cygwin1!__argv'
11771130809Smarcel0x610c0aa8 <cygwin1!__argv>:    0x10021608      0x00000000
11772130809Smarcel(gdb) x/x 0x10021608
11773130809Smarcel0x10021608:     0x0022fd98
11774130809Smarcel(gdb) x/s 0x0022fd98
11775130809Smarcel0x22fd98:        "/cygdrive/c/mydirectory/myprogram"
11776130809Smarcel@end smallexample
11777130809Smarcel
11778130809SmarcelSetting a break point within a DLL is possible even before the program
11779130809Smarcelstarts execution. However, under these circumstances, @value{GDBN} can't
11780130809Smarcelexamine the initial instructions of the function in order to skip the
11781130809Smarcelfunction's frame set-up code. You can work around this by using ``*&''
11782130809Smarcelto set the breakpoint at a raw memory address:
11783130809Smarcel
11784130809Smarcel@smallexample
11785130809Smarcel(gdb) break *&'python22!PyOS_Readline'
11786130809SmarcelBreakpoint 1 at 0x1e04eff0
11787130809Smarcel@end smallexample
11788130809Smarcel
11789130809SmarcelThe author of these extensions is not entirely convinced that setting a
11790130809Smarcelbreak point within a shared DLL like @file{kernel32.dll} is completely
11791130809Smarcelsafe.
11792130809Smarcel
1179398948Sobrien@node Embedded OS
1179498948Sobrien@section Embedded Operating Systems
1179598948Sobrien
1179698948SobrienThis section describes configurations involving the debugging of
1179798948Sobrienembedded operating systems that are available for several different
1179898948Sobrienarchitectures.
1179998948Sobrien
1180098948Sobrien@menu
1180198948Sobrien* VxWorks::                     Using @value{GDBN} with VxWorks
1180298948Sobrien@end menu
1180398948Sobrien
1180498948Sobrien@value{GDBN} includes the ability to debug programs running on
1180598948Sobrienvarious real-time operating systems.
1180698948Sobrien
1180798948Sobrien@node VxWorks
1180898948Sobrien@subsection Using @value{GDBN} with VxWorks
1180998948Sobrien
1181098948Sobrien@cindex VxWorks
1181198948Sobrien
1181298948Sobrien@table @code
1181398948Sobrien
1181498948Sobrien@kindex target vxworks
1181598948Sobrien@item target vxworks @var{machinename}
1181698948SobrienA VxWorks system, attached via TCP/IP.  The argument @var{machinename}
1181798948Sobrienis the target system's machine name or IP address.
1181898948Sobrien
1181998948Sobrien@end table
1182098948Sobrien
1182198948SobrienOn VxWorks, @code{load} links @var{filename} dynamically on the
1182298948Sobriencurrent target system as well as adding its symbols in @value{GDBN}.
1182398948Sobrien
1182498948Sobrien@value{GDBN} enables developers to spawn and debug tasks running on networked
1182598948SobrienVxWorks targets from a Unix host.  Already-running tasks spawned from
1182698948Sobrienthe VxWorks shell can also be debugged.  @value{GDBN} uses code that runs on
1182798948Sobrienboth the Unix host and on the VxWorks target.  The program
1182898948Sobrien@code{@value{GDBP}} is installed and executed on the Unix host.  (It may be
1182998948Sobrieninstalled with the name @code{vxgdb}, to distinguish it from a
1183098948Sobrien@value{GDBN} for debugging programs on the host itself.)
1183198948Sobrien
1183298948Sobrien@table @code
1183398948Sobrien@item VxWorks-timeout @var{args}
1183498948Sobrien@kindex vxworks-timeout
1183598948SobrienAll VxWorks-based targets now support the option @code{vxworks-timeout}.
1183698948SobrienThis option is set by the user, and  @var{args} represents the number of
1183798948Sobrienseconds @value{GDBN} waits for responses to rpc's.  You might use this if
1183898948Sobrienyour VxWorks target is a slow software simulator or is on the far side
1183998948Sobrienof a thin network line.
1184098948Sobrien@end table
1184198948Sobrien
1184298948SobrienThe following information on connecting to VxWorks was current when
1184398948Sobrienthis manual was produced; newer releases of VxWorks may use revised
1184498948Sobrienprocedures.
1184598948Sobrien
1184698948Sobrien@kindex INCLUDE_RDB
1184798948SobrienTo use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
1184898948Sobriento include the remote debugging interface routines in the VxWorks
1184998948Sobrienlibrary @file{rdb.a}.  To do this, define @code{INCLUDE_RDB} in the
1185098948SobrienVxWorks configuration file @file{configAll.h} and rebuild your VxWorks
1185198948Sobrienkernel.  The resulting kernel contains @file{rdb.a}, and spawns the
1185298948Sobriensource debugging task @code{tRdbTask} when VxWorks is booted.  For more
1185398948Sobrieninformation on configuring and remaking VxWorks, see the manufacturer's
1185498948Sobrienmanual.
1185598948Sobrien@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
1185698948Sobrien
1185798948SobrienOnce you have included @file{rdb.a} in your VxWorks system image and set
1185898948Sobrienyour Unix execution search path to find @value{GDBN}, you are ready to
1185998948Sobrienrun @value{GDBN}.  From your Unix host, run @code{@value{GDBP}} (or
1186098948Sobrien@code{vxgdb}, depending on your installation).
1186198948Sobrien
1186298948Sobrien@value{GDBN} comes up showing the prompt:
1186398948Sobrien
11864130809Smarcel@smallexample
1186598948Sobrien(vxgdb)
11866130809Smarcel@end smallexample
1186798948Sobrien
1186898948Sobrien@menu
1186998948Sobrien* VxWorks Connection::          Connecting to VxWorks
1187098948Sobrien* VxWorks Download::            VxWorks download
1187198948Sobrien* VxWorks Attach::              Running tasks
1187298948Sobrien@end menu
1187398948Sobrien
1187498948Sobrien@node VxWorks Connection
1187598948Sobrien@subsubsection Connecting to VxWorks
1187698948Sobrien
1187798948SobrienThe @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
1187898948Sobriennetwork.  To connect to a target whose host name is ``@code{tt}'', type:
1187998948Sobrien
11880130809Smarcel@smallexample
1188198948Sobrien(vxgdb) target vxworks tt
11882130809Smarcel@end smallexample
1188398948Sobrien
1188498948Sobrien@need 750
1188598948Sobrien@value{GDBN} displays messages like these:
1188698948Sobrien
1188798948Sobrien@smallexample
1188898948SobrienAttaching remote machine across net...
1188998948SobrienConnected to tt.
1189098948Sobrien@end smallexample
1189198948Sobrien
1189298948Sobrien@need 1000
1189398948Sobrien@value{GDBN} then attempts to read the symbol tables of any object modules
1189498948Sobrienloaded into the VxWorks target since it was last booted.  @value{GDBN} locates
1189598948Sobrienthese files by searching the directories listed in the command search
1189698948Sobrienpath (@pxref{Environment, ,Your program's environment}); if it fails
1189798948Sobriento find an object file, it displays a message such as:
1189898948Sobrien
11899130809Smarcel@smallexample
1190098948Sobrienprog.o: No such file or directory.
11901130809Smarcel@end smallexample
1190298948Sobrien
1190398948SobrienWhen this happens, add the appropriate directory to the search path with
1190498948Sobrienthe @value{GDBN} command @code{path}, and execute the @code{target}
1190598948Sobriencommand again.
1190698948Sobrien
1190798948Sobrien@node VxWorks Download
1190898948Sobrien@subsubsection VxWorks download
1190998948Sobrien
1191098948Sobrien@cindex download to VxWorks
1191198948SobrienIf you have connected to the VxWorks target and you want to debug an
1191298948Sobrienobject that has not yet been loaded, you can use the @value{GDBN}
1191398948Sobrien@code{load} command to download a file from Unix to VxWorks
1191498948Sobrienincrementally.  The object file given as an argument to the @code{load}
1191598948Sobriencommand is actually opened twice: first by the VxWorks target in order
1191698948Sobriento download the code, then by @value{GDBN} in order to read the symbol
1191798948Sobrientable.  This can lead to problems if the current working directories on
1191898948Sobrienthe two systems differ.  If both systems have NFS mounted the same
1191998948Sobrienfilesystems, you can avoid these problems by using absolute paths.
1192098948SobrienOtherwise, it is simplest to set the working directory on both systems
1192198948Sobriento the directory in which the object file resides, and then to reference
1192298948Sobrienthe file by its name, without any path.  For instance, a program
1192398948Sobrien@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
1192498948Sobrienand in @file{@var{hostpath}/vw/demo/rdb} on the host.  To load this
1192598948Sobrienprogram, type this on VxWorks:
1192698948Sobrien
11927130809Smarcel@smallexample
1192898948Sobrien-> cd "@var{vxpath}/vw/demo/rdb"
11929130809Smarcel@end smallexample
1193098948Sobrien
1193198948Sobrien@noindent
1193298948SobrienThen, in @value{GDBN}, type:
1193398948Sobrien
11934130809Smarcel@smallexample
1193598948Sobrien(vxgdb) cd @var{hostpath}/vw/demo/rdb
1193698948Sobrien(vxgdb) load prog.o
11937130809Smarcel@end smallexample
1193898948Sobrien
1193998948Sobrien@value{GDBN} displays a response similar to this:
1194098948Sobrien
1194198948Sobrien@smallexample
1194298948SobrienReading symbol data from wherever/vw/demo/rdb/prog.o... done.
1194398948Sobrien@end smallexample
1194498948Sobrien
1194598948SobrienYou can also use the @code{load} command to reload an object module
1194698948Sobrienafter editing and recompiling the corresponding source file.  Note that
1194798948Sobrienthis makes @value{GDBN} delete all currently-defined breakpoints,
1194898948Sobrienauto-displays, and convenience variables, and to clear the value
1194998948Sobrienhistory.  (This is necessary in order to preserve the integrity of
1195098948Sobriendebugger's data structures that reference the target system's symbol
1195198948Sobrientable.)
1195298948Sobrien
1195398948Sobrien@node VxWorks Attach
1195498948Sobrien@subsubsection Running tasks
1195598948Sobrien
1195698948Sobrien@cindex running VxWorks tasks
1195798948SobrienYou can also attach to an existing task using the @code{attach} command as
1195898948Sobrienfollows:
1195998948Sobrien
11960130809Smarcel@smallexample
1196198948Sobrien(vxgdb) attach @var{task}
11962130809Smarcel@end smallexample
1196398948Sobrien
1196498948Sobrien@noindent
1196598948Sobrienwhere @var{task} is the VxWorks hexadecimal task ID.  The task can be running
1196698948Sobrienor suspended when you attach to it.  Running tasks are suspended at
1196798948Sobrienthe time of attachment.
1196898948Sobrien
1196998948Sobrien@node Embedded Processors
1197098948Sobrien@section Embedded Processors
1197198948Sobrien
1197298948SobrienThis section goes into details specific to particular embedded
1197398948Sobrienconfigurations.
1197498948Sobrien
1197598948Sobrien
1197698948Sobrien@menu
1197798948Sobrien* ARM::                         ARM
11978130809Smarcel* H8/300::                      Renesas H8/300
11979130809Smarcel* H8/500::                      Renesas H8/500
11980130809Smarcel* M32R/D::                      Renesas M32R/D
1198198948Sobrien* M68K::                        Motorola M68K
1198298948Sobrien* MIPS Embedded::               MIPS Embedded
11983130809Smarcel* OpenRISC 1000::               OpenRisc 1000
1198498948Sobrien* PA::                          HP PA Embedded
1198598948Sobrien* PowerPC:                      PowerPC
11986130809Smarcel* SH::                          Renesas SH
1198798948Sobrien* Sparclet::                    Tsqware Sparclet
1198898948Sobrien* Sparclite::                   Fujitsu Sparclite
1198998948Sobrien* ST2000::                      Tandem ST2000
1199098948Sobrien* Z8000::                       Zilog Z8000
1199198948Sobrien@end menu
1199298948Sobrien
1199398948Sobrien@node ARM
1199498948Sobrien@subsection ARM
1199598948Sobrien
1199698948Sobrien@table @code
1199798948Sobrien
1199898948Sobrien@kindex target rdi
1199998948Sobrien@item target rdi @var{dev}
1200098948SobrienARM Angel monitor, via RDI library interface to ADP protocol.  You may
1200198948Sobrienuse this target to communicate with both boards running the Angel
1200298948Sobrienmonitor, or with the EmbeddedICE JTAG debug device.
1200398948Sobrien
1200498948Sobrien@kindex target rdp
1200598948Sobrien@item target rdp @var{dev}
1200698948SobrienARM Demon monitor.
1200798948Sobrien
1200898948Sobrien@end table
1200998948Sobrien
1201098948Sobrien@node H8/300
12011130809Smarcel@subsection Renesas H8/300
1201298948Sobrien
1201398948Sobrien@table @code
1201498948Sobrien
1201598948Sobrien@kindex target hms@r{, with H8/300}
1201698948Sobrien@item target hms @var{dev}
12017130809SmarcelA Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
1201898948SobrienUse special commands @code{device} and @code{speed} to control the serial
1201998948Sobrienline and the communications speed used.
1202098948Sobrien
1202198948Sobrien@kindex target e7000@r{, with H8/300}
1202298948Sobrien@item target e7000 @var{dev}
12023130809SmarcelE7000 emulator for Renesas H8 and SH.
1202498948Sobrien
1202598948Sobrien@kindex target sh3@r{, with H8/300}
1202698948Sobrien@kindex target sh3e@r{, with H8/300}
1202798948Sobrien@item target sh3 @var{dev}
1202898948Sobrien@itemx target sh3e @var{dev}
12029130809SmarcelRenesas SH-3 and SH-3E target systems.
1203098948Sobrien
1203198948Sobrien@end table
1203298948Sobrien
1203398948Sobrien@cindex download to H8/300 or H8/500
1203498948Sobrien@cindex H8/300 or H8/500 download
12035130809Smarcel@cindex download to Renesas SH
12036130809Smarcel@cindex Renesas SH download
12037130809SmarcelWhen you select remote debugging to a Renesas SH, H8/300, or H8/500
12038130809Smarcelboard, the @code{load} command downloads your program to the Renesas
1203998948Sobrienboard and also opens it as the current executable target for
1204098948Sobrien@value{GDBN} on your host (like the @code{file} command).
1204198948Sobrien
1204298948Sobrien@value{GDBN} needs to know these things to talk to your
12043130809SmarcelRenesas SH, H8/300, or H8/500:
1204498948Sobrien
1204598948Sobrien@enumerate
1204698948Sobrien@item
1204798948Sobrienthat you want to use @samp{target hms}, the remote debugging interface
12048130809Smarcelfor Renesas microprocessors, or @samp{target e7000}, the in-circuit
12049130809Smarcelemulator for the Renesas SH and the Renesas 300H.  (@samp{target hms} is
12050130809Smarcelthe default when @value{GDBN} is configured specifically for the Renesas SH,
1205198948SobrienH8/300, or H8/500.)
1205298948Sobrien
1205398948Sobrien@item
12054130809Smarcelwhat serial device connects your host to your Renesas board (the first
1205598948Sobrienserial device available on your host is the default).
1205698948Sobrien
1205798948Sobrien@item
1205898948Sobrienwhat speed to use over the serial device.
1205998948Sobrien@end enumerate
1206098948Sobrien
1206198948Sobrien@menu
12062130809Smarcel* Renesas Boards::      Connecting to Renesas boards.
12063130809Smarcel* Renesas ICE::         Using the E7000 In-Circuit Emulator.
12064130809Smarcel* Renesas Special::     Special @value{GDBN} commands for Renesas micros.
1206598948Sobrien@end menu
1206698948Sobrien
12067130809Smarcel@node Renesas Boards
12068130809Smarcel@subsubsection Connecting to Renesas boards
1206998948Sobrien
1207098948Sobrien@c only for Unix hosts
1207198948Sobrien@kindex device
12072130809Smarcel@cindex serial device, Renesas micros
1207398948SobrienUse the special @code{@value{GDBN}} command @samp{device @var{port}} if you
1207498948Sobrienneed to explicitly set the serial device.  The default @var{port} is the
1207598948Sobrienfirst available port on your host.  This is only necessary on Unix
1207698948Sobrienhosts, where it is typically something like @file{/dev/ttya}.
1207798948Sobrien
1207898948Sobrien@kindex speed
12079130809Smarcel@cindex serial line speed, Renesas micros
1208098948Sobrien@code{@value{GDBN}} has another special command to set the communications
1208198948Sobrienspeed: @samp{speed @var{bps}}.  This command also is only used from Unix
1208298948Sobrienhosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
1208398948Sobrienthe DOS @code{mode} command (for instance,
1208498948Sobrien@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
1208598948Sobrien
1208698948SobrienThe @samp{device} and @samp{speed} commands are available only when you
12087130809Smarceluse a Unix host to debug your Renesas microprocessor programs.  If you
1208898948Sobrienuse a DOS host,
1208998948Sobrien@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
1209098948Sobriencalled @code{asynctsr} to communicate with the development board
1209198948Sobrienthrough a PC serial port.  You must also use the DOS @code{mode} command
1209298948Sobriento set up the serial port on the DOS side.
1209398948Sobrien
1209498948SobrienThe following sample session illustrates the steps needed to start a
1209598948Sobrienprogram under @value{GDBN} control on an H8/300.  The example uses a
1209698948Sobriensample H8/300 program called @file{t.x}.  The procedure is the same for
12097130809Smarcelthe Renesas SH and the H8/500.
1209898948Sobrien
1209998948SobrienFirst hook up your development board.  In this example, we use a
1210098948Sobrienboard attached to serial port @code{COM2}; if you use a different serial
1210198948Sobrienport, substitute its name in the argument of the @code{mode} command.
1210298948SobrienWhen you call @code{asynctsr}, the auxiliary comms program used by the
1210398948Sobriendebugger, you give it just the numeric part of the serial port's name;
1210498948Sobrienfor example, @samp{asyncstr 2} below runs @code{asyncstr} on
1210598948Sobrien@code{COM2}.
1210698948Sobrien
12107130809Smarcel@smallexample
1210898948SobrienC:\H8300\TEST> asynctsr 2
1210998948SobrienC:\H8300\TEST> mode com2:9600,n,8,1,p
1211098948Sobrien
1211198948SobrienResident portion of MODE loaded
1211298948Sobrien
1211398948SobrienCOM2: 9600, n, 8, 1, p
1211498948Sobrien
12115130809Smarcel@end smallexample
1211698948Sobrien
1211798948Sobrien@quotation
1211898948Sobrien@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
1211998948Sobrien@code{asynctsr}.  If you also run PC-NFS on your DOS host, you may need to
1212098948Sobriendisable it, or even boot without it, to use @code{asynctsr} to control
1212198948Sobrienyour development board.
1212298948Sobrien@end quotation
1212398948Sobrien
1212498948Sobrien@kindex target hms@r{, and serial protocol}
1212598948SobrienNow that serial communications are set up, and the development board is
1212698948Sobrienconnected, you can start up @value{GDBN}.  Call @code{@value{GDBP}} with
1212798948Sobrienthe name of your program as the argument.  @code{@value{GDBN}} prompts
1212898948Sobrienyou, as usual, with the prompt @samp{(@value{GDBP})}.  Use two special
1212998948Sobriencommands to begin your debugging session: @samp{target hms} to specify
12130130809Smarcelcross-debugging to the Renesas board, and the @code{load} command to
1213198948Sobriendownload your program to the board.  @code{load} displays the names of
1213298948Sobrienthe program's sections, and a @samp{*} for each 2K of data downloaded.
1213398948Sobrien(If you want to refresh @value{GDBN} data on symbols or on the
1213498948Sobrienexecutable file without downloading, use the @value{GDBN} commands
1213598948Sobrien@code{file} or @code{symbol-file}.  These commands, and @code{load}
1213698948Sobrienitself, are described in @ref{Files,,Commands to specify files}.)
1213798948Sobrien
1213898948Sobrien@smallexample
1213998948Sobrien(eg-C:\H8300\TEST) @value{GDBP} t.x
1214098948Sobrien@value{GDBN} is free software and you are welcome to distribute copies
1214198948Sobrien of it under certain conditions; type "show copying" to see
1214298948Sobrien the conditions.
1214398948SobrienThere is absolutely no warranty for @value{GDBN}; type "show warranty"
1214498948Sobrienfor details.
1214598948Sobrien@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
1214698948Sobrien(@value{GDBP}) target hms
1214798948SobrienConnected to remote H8/300 HMS system.
1214898948Sobrien(@value{GDBP}) load t.x
1214998948Sobrien.text   : 0x8000 .. 0xabde ***********
1215098948Sobrien.data   : 0xabde .. 0xad30 *
1215198948Sobrien.stack  : 0xf000 .. 0xf014 *
1215298948Sobrien@end smallexample
1215398948Sobrien
1215498948SobrienAt this point, you're ready to run or debug your program.  From here on,
1215598948Sobrienyou can use all the usual @value{GDBN} commands.  The @code{break} command
1215698948Sobriensets breakpoints; the @code{run} command starts your program;
1215798948Sobrien@code{print} or @code{x} display data; the @code{continue} command
1215898948Sobrienresumes execution after stopping at a breakpoint.  You can use the
1215998948Sobrien@code{help} command at any time to find out more about @value{GDBN} commands.
1216098948Sobrien
1216198948SobrienRemember, however, that @emph{operating system} facilities aren't
1216298948Sobrienavailable on your development board; for example, if your program hangs,
1216398948Sobrienyou can't send an interrupt---but you can press the @sc{reset} switch!
1216498948Sobrien
1216598948SobrienUse the @sc{reset} button on the development board
1216698948Sobrien@itemize @bullet
1216798948Sobrien@item
1216898948Sobriento interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
1216998948Sobrienno way to pass an interrupt signal to the development board); and
1217098948Sobrien
1217198948Sobrien@item
1217298948Sobriento return to the @value{GDBN} command prompt after your program finishes
1217398948Sobriennormally.  The communications protocol provides no other way for @value{GDBN}
1217498948Sobriento detect program completion.
1217598948Sobrien@end itemize
1217698948Sobrien
1217798948SobrienIn either case, @value{GDBN} sees the effect of a @sc{reset} on the
1217898948Sobriendevelopment board as a ``normal exit'' of your program.
1217998948Sobrien
12180130809Smarcel@node Renesas ICE
1218198948Sobrien@subsubsection Using the E7000 in-circuit emulator
1218298948Sobrien
12183130809Smarcel@kindex target e7000@r{, with Renesas ICE}
1218498948SobrienYou can use the E7000 in-circuit emulator to develop code for either the
12185130809SmarcelRenesas SH or the H8/300H.  Use one of these forms of the @samp{target
1218698948Sobriene7000} command to connect @value{GDBN} to your E7000:
1218798948Sobrien
1218898948Sobrien@table @code
1218998948Sobrien@item target e7000 @var{port} @var{speed}
1219098948SobrienUse this form if your E7000 is connected to a serial port.  The
1219198948Sobrien@var{port} argument identifies what serial port to use (for example,
1219298948Sobrien@samp{com2}).  The third argument is the line speed in bits per second
1219398948Sobrien(for example, @samp{9600}).
1219498948Sobrien
1219598948Sobrien@item target e7000 @var{hostname}
1219698948SobrienIf your E7000 is installed as a host on a TCP/IP network, you can just
1219798948Sobrienspecify its hostname; @value{GDBN} uses @code{telnet} to connect.
1219898948Sobrien@end table
1219998948Sobrien
12200130809Smarcel@node Renesas Special
12201130809Smarcel@subsubsection Special @value{GDBN} commands for Renesas micros
1220298948Sobrien
1220398948SobrienSome @value{GDBN} commands are available only for the H8/300:
1220498948Sobrien
1220598948Sobrien@table @code
1220698948Sobrien
1220798948Sobrien@kindex set machine
1220898948Sobrien@kindex show machine
1220998948Sobrien@item set machine h8300
1221098948Sobrien@itemx set machine h8300h
1221198948SobrienCondition @value{GDBN} for one of the two variants of the H8/300
1221298948Sobrienarchitecture with @samp{set machine}.  You can use @samp{show machine}
1221398948Sobriento check which variant is currently in effect.
1221498948Sobrien
1221598948Sobrien@end table
1221698948Sobrien
1221798948Sobrien@node H8/500
1221898948Sobrien@subsection H8/500
1221998948Sobrien
1222098948Sobrien@table @code
1222198948Sobrien
1222298948Sobrien@kindex set memory @var{mod}
1222398948Sobrien@cindex memory models, H8/500
1222498948Sobrien@item set memory @var{mod}
1222598948Sobrien@itemx show memory
1222698948SobrienSpecify which H8/500 memory model (@var{mod}) you are using with
1222798948Sobrien@samp{set memory}; check which memory model is in effect with @samp{show
1222898948Sobrienmemory}.  The accepted values for @var{mod} are @code{small},
1222998948Sobrien@code{big}, @code{medium}, and @code{compact}.
1223098948Sobrien
1223198948Sobrien@end table
1223298948Sobrien
1223398948Sobrien@node M32R/D
12234130809Smarcel@subsection Renesas M32R/D
1223598948Sobrien
1223698948Sobrien@table @code
1223798948Sobrien
1223898948Sobrien@kindex target m32r
1223998948Sobrien@item target m32r @var{dev}
12240130809SmarcelRenesas M32R/D ROM monitor.
1224198948Sobrien
12242130809Smarcel@kindex target m32rsdi
12243130809Smarcel@item target m32rsdi @var{dev}
12244130809SmarcelRenesas M32R SDI server, connected via parallel port to the board.
12245130809Smarcel
1224698948Sobrien@end table
1224798948Sobrien
1224898948Sobrien@node M68K
1224998948Sobrien@subsection M68k
1225098948Sobrien
1225198948SobrienThe Motorola m68k configuration includes ColdFire support, and
1225298948Sobrientarget command for the following ROM monitors.
1225398948Sobrien
1225498948Sobrien@table @code
1225598948Sobrien
1225698948Sobrien@kindex target abug
1225798948Sobrien@item target abug @var{dev}
1225898948SobrienABug ROM monitor for M68K.
1225998948Sobrien
1226098948Sobrien@kindex target cpu32bug
1226198948Sobrien@item target cpu32bug @var{dev}
1226298948SobrienCPU32BUG monitor, running on a CPU32 (M68K) board.
1226398948Sobrien
1226498948Sobrien@kindex target dbug
1226598948Sobrien@item target dbug @var{dev}
1226698948SobriendBUG ROM monitor for Motorola ColdFire.
1226798948Sobrien
1226898948Sobrien@kindex target est
1226998948Sobrien@item target est @var{dev}
1227098948SobrienEST-300 ICE monitor, running on a CPU32 (M68K) board.
1227198948Sobrien
1227298948Sobrien@kindex target rom68k
1227398948Sobrien@item target rom68k @var{dev}
1227498948SobrienROM 68K monitor, running on an M68K IDP board.
1227598948Sobrien
1227698948Sobrien@end table
1227798948Sobrien
1227898948Sobrien@table @code
1227998948Sobrien
1228098948Sobrien@kindex target rombug
1228198948Sobrien@item target rombug @var{dev}
1228298948SobrienROMBUG ROM monitor for OS/9000.
1228398948Sobrien
1228498948Sobrien@end table
1228598948Sobrien
1228698948Sobrien@node MIPS Embedded
1228798948Sobrien@subsection MIPS Embedded
1228898948Sobrien
1228998948Sobrien@cindex MIPS boards
1229098948Sobrien@value{GDBN} can use the MIPS remote debugging protocol to talk to a
1229198948SobrienMIPS board attached to a serial line.  This is available when
1229298948Sobrienyou configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
1229398948Sobrien
1229498948Sobrien@need 1000
1229598948SobrienUse these @value{GDBN} commands to specify the connection to your target board:
1229698948Sobrien
1229798948Sobrien@table @code
1229898948Sobrien@item target mips @var{port}
1229998948Sobrien@kindex target mips @var{port}
1230098948SobrienTo run a program on the board, start up @code{@value{GDBP}} with the
1230198948Sobrienname of your program as the argument.  To connect to the board, use the
1230298948Sobriencommand @samp{target mips @var{port}}, where @var{port} is the name of
1230398948Sobrienthe serial port connected to the board.  If the program has not already
1230498948Sobrienbeen downloaded to the board, you may use the @code{load} command to
1230598948Sobriendownload it.  You can then use all the usual @value{GDBN} commands.
1230698948Sobrien
1230798948SobrienFor example, this sequence connects to the target board through a serial
1230898948Sobrienport, and loads and runs a program called @var{prog} through the
1230998948Sobriendebugger:
1231098948Sobrien
12311130809Smarcel@smallexample
1231298948Sobrienhost$ @value{GDBP} @var{prog}
1231398948Sobrien@value{GDBN} is free software and @dots{}
1231498948Sobrien(@value{GDBP}) target mips /dev/ttyb
1231598948Sobrien(@value{GDBP}) load @var{prog}
1231698948Sobrien(@value{GDBP}) run
12317130809Smarcel@end smallexample
1231898948Sobrien
1231998948Sobrien@item target mips @var{hostname}:@var{portnumber}
1232098948SobrienOn some @value{GDBN} host configurations, you can specify a TCP
1232198948Sobrienconnection (for instance, to a serial line managed by a terminal
1232298948Sobrienconcentrator) instead of a serial port, using the syntax
1232398948Sobrien@samp{@var{hostname}:@var{portnumber}}.
1232498948Sobrien
1232598948Sobrien@item target pmon @var{port}
1232698948Sobrien@kindex target pmon @var{port}
1232798948SobrienPMON ROM monitor.
1232898948Sobrien
1232998948Sobrien@item target ddb @var{port}
1233098948Sobrien@kindex target ddb @var{port}
1233198948SobrienNEC's DDB variant of PMON for Vr4300.
1233298948Sobrien
1233398948Sobrien@item target lsi @var{port}
1233498948Sobrien@kindex target lsi @var{port}
1233598948SobrienLSI variant of PMON.
1233698948Sobrien
1233798948Sobrien@kindex target r3900
1233898948Sobrien@item target r3900 @var{dev}
1233998948SobrienDensan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
1234098948Sobrien
1234198948Sobrien@kindex target array
1234298948Sobrien@item target array @var{dev}
1234398948SobrienArray Tech LSI33K RAID controller board.
1234498948Sobrien
1234598948Sobrien@end table
1234698948Sobrien
1234798948Sobrien
1234898948Sobrien@noindent
1234998948Sobrien@value{GDBN} also supports these special commands for MIPS targets:
1235098948Sobrien
1235198948Sobrien@table @code
1235298948Sobrien@item set processor @var{args}
1235398948Sobrien@itemx show processor
1235498948Sobrien@kindex set processor @var{args}
1235598948Sobrien@kindex show processor
1235698948SobrienUse the @code{set processor} command to set the type of MIPS
1235798948Sobrienprocessor when you want to access processor-type-specific registers.
1235898948SobrienFor example, @code{set processor @var{r3041}} tells @value{GDBN}
1235998948Sobriento use the CPU registers appropriate for the 3041 chip.
1236098948SobrienUse the @code{show processor} command to see what MIPS processor @value{GDBN}
1236198948Sobrienis using.  Use the @code{info reg} command to see what registers
1236298948Sobrien@value{GDBN} is using.
1236398948Sobrien
1236498948Sobrien@item set mipsfpu double
1236598948Sobrien@itemx set mipsfpu single
1236698948Sobrien@itemx set mipsfpu none
1236798948Sobrien@itemx show mipsfpu
1236898948Sobrien@kindex set mipsfpu
1236998948Sobrien@kindex show mipsfpu
1237098948Sobrien@cindex MIPS remote floating point
1237198948Sobrien@cindex floating point, MIPS remote
1237298948SobrienIf your target board does not support the MIPS floating point
1237398948Sobriencoprocessor, you should use the command @samp{set mipsfpu none} (if you
1237498948Sobrienneed this, you may wish to put the command in your @value{GDBN} init
1237598948Sobrienfile).  This tells @value{GDBN} how to find the return value of
1237698948Sobrienfunctions which return floating point values.  It also allows
1237798948Sobrien@value{GDBN} to avoid saving the floating point registers when calling
1237898948Sobrienfunctions on the board.  If you are using a floating point coprocessor
1237998948Sobrienwith only single precision floating point support, as on the @sc{r4650}
1238098948Sobrienprocessor, use the command @samp{set mipsfpu single}.  The default
1238198948Sobriendouble precision floating point coprocessor may be selected using
1238298948Sobrien@samp{set mipsfpu double}.
1238398948Sobrien
1238498948SobrienIn previous versions the only choices were double precision or no
1238598948Sobrienfloating point, so @samp{set mipsfpu on} will select double precision
1238698948Sobrienand @samp{set mipsfpu off} will select no floating point.
1238798948Sobrien
1238898948SobrienAs usual, you can inquire about the @code{mipsfpu} variable with
1238998948Sobrien@samp{show mipsfpu}.
1239098948Sobrien
1239198948Sobrien@item set remotedebug @var{n}
1239298948Sobrien@itemx show remotedebug
1239398948Sobrien@kindex set remotedebug@r{, MIPS protocol}
1239498948Sobrien@kindex show remotedebug@r{, MIPS protocol}
1239598948Sobrien@cindex @code{remotedebug}, MIPS protocol
1239698948Sobrien@cindex MIPS @code{remotedebug} protocol
1239798948Sobrien@c FIXME! For this to be useful, you must know something about the MIPS
1239898948Sobrien@c FIXME...protocol.  Where is it described?
1239998948SobrienYou can see some debugging information about communications with the board
1240098948Sobrienby setting the @code{remotedebug} variable.  If you set it to @code{1} using
1240198948Sobrien@samp{set remotedebug 1}, every packet is displayed.  If you set it
1240298948Sobriento @code{2}, every character is displayed.  You can check the current value
1240398948Sobrienat any time with the command @samp{show remotedebug}.
1240498948Sobrien
1240598948Sobrien@item set timeout @var{seconds}
1240698948Sobrien@itemx set retransmit-timeout @var{seconds}
1240798948Sobrien@itemx show timeout
1240898948Sobrien@itemx show retransmit-timeout
1240998948Sobrien@cindex @code{timeout}, MIPS protocol
1241098948Sobrien@cindex @code{retransmit-timeout}, MIPS protocol
1241198948Sobrien@kindex set timeout
1241298948Sobrien@kindex show timeout
1241398948Sobrien@kindex set retransmit-timeout
1241498948Sobrien@kindex show retransmit-timeout
1241598948SobrienYou can control the timeout used while waiting for a packet, in the MIPS
1241698948Sobrienremote protocol, with the @code{set timeout @var{seconds}} command.  The
1241798948Sobriendefault is 5 seconds.  Similarly, you can control the timeout used while
1241898948Sobrienwaiting for an acknowledgement of a packet with the @code{set
1241998948Sobrienretransmit-timeout @var{seconds}} command.  The default is 3 seconds.
1242098948SobrienYou can inspect both values with @code{show timeout} and @code{show
1242198948Sobrienretransmit-timeout}.  (These commands are @emph{only} available when
1242298948Sobrien@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
1242398948Sobrien
1242498948SobrienThe timeout set by @code{set timeout} does not apply when @value{GDBN}
1242598948Sobrienis waiting for your program to stop.  In that case, @value{GDBN} waits
1242698948Sobrienforever because it has no way of knowing how long the program is going
1242798948Sobriento run before stopping.
1242898948Sobrien@end table
1242998948Sobrien
12430130809Smarcel@node OpenRISC 1000
12431130809Smarcel@subsection OpenRISC 1000
12432130809Smarcel@cindex OpenRISC 1000
12433130809Smarcel
12434130809Smarcel@cindex or1k boards
12435130809SmarcelSee OR1k Architecture document (@uref{www.opencores.org}) for more information
12436130809Smarcelabout platform and commands.
12437130809Smarcel
12438130809Smarcel@table @code
12439130809Smarcel
12440130809Smarcel@kindex target jtag
12441130809Smarcel@item target jtag jtag://@var{host}:@var{port}
12442130809Smarcel
12443130809SmarcelConnects to remote JTAG server.
12444130809SmarcelJTAG remote server can be either an or1ksim or JTAG server,
12445130809Smarcelconnected via parallel port to the board.
12446130809Smarcel
12447130809SmarcelExample: @code{target jtag jtag://localhost:9999}
12448130809Smarcel
12449130809Smarcel@kindex or1ksim
12450130809Smarcel@item or1ksim @var{command}
12451130809SmarcelIf connected to @code{or1ksim} OpenRISC 1000 Architectural
12452130809SmarcelSimulator, proprietary commands can be executed.
12453130809Smarcel
12454130809Smarcel@kindex info or1k spr
12455130809Smarcel@item info or1k spr
12456130809SmarcelDisplays spr groups.
12457130809Smarcel
12458130809Smarcel@item info or1k spr @var{group}
12459130809Smarcel@itemx info or1k spr @var{groupno}
12460130809SmarcelDisplays register names in selected group.
12461130809Smarcel
12462130809Smarcel@item info or1k spr @var{group} @var{register}
12463130809Smarcel@itemx info or1k spr @var{register}
12464130809Smarcel@itemx info or1k spr @var{groupno} @var{registerno}
12465130809Smarcel@itemx info or1k spr @var{registerno}
12466130809SmarcelShows information about specified spr register.
12467130809Smarcel
12468130809Smarcel@kindex spr
12469130809Smarcel@item spr @var{group} @var{register} @var{value}
12470130809Smarcel@itemx spr @var{register @var{value}}
12471130809Smarcel@itemx spr @var{groupno} @var{registerno @var{value}}
12472130809Smarcel@itemx spr @var{registerno @var{value}}
12473130809SmarcelWrites @var{value} to specified spr register.
12474130809Smarcel@end table
12475130809Smarcel
12476130809SmarcelSome implementations of OpenRISC 1000 Architecture also have hardware trace.
12477130809SmarcelIt is very similar to @value{GDBN} trace, except it does not interfere with normal
12478130809Smarcelprogram execution and is thus much faster.  Hardware breakpoints/watchpoint
12479130809Smarceltriggers can be set using:
12480130809Smarcel@table @code
12481130809Smarcel@item $LEA/$LDATA
12482130809SmarcelLoad effective address/data
12483130809Smarcel@item $SEA/$SDATA
12484130809SmarcelStore effective address/data
12485130809Smarcel@item $AEA/$ADATA
12486130809SmarcelAccess effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
12487130809Smarcel@item $FETCH
12488130809SmarcelFetch data
12489130809Smarcel@end table
12490130809Smarcel
12491130809SmarcelWhen triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
12492130809Smarcel@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
12493130809Smarcel
12494130809Smarcel@code{htrace} commands:
12495130809Smarcel@cindex OpenRISC 1000 htrace
12496130809Smarcel@table @code
12497130809Smarcel@kindex hwatch
12498130809Smarcel@item hwatch @var{conditional}
12499130809SmarcelSet hardware watchpoint on combination of Load/Store Effecive Address(es)
12500130809Smarcelor Data.  For example:
12501130809Smarcel
12502130809Smarcel@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
12503130809Smarcel
12504130809Smarcel@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
12505130809Smarcel
12506130809Smarcel@kindex htrace info
12507130809Smarcel@item htrace info
12508130809SmarcelDisplay information about current HW trace configuration.
12509130809Smarcel
12510130809Smarcel@kindex htrace trigger
12511130809Smarcel@item htrace trigger @var{conditional}
12512130809SmarcelSet starting criteria for HW trace.
12513130809Smarcel
12514130809Smarcel@kindex htrace qualifier
12515130809Smarcel@item htrace qualifier @var{conditional}
12516130809SmarcelSet acquisition qualifier for HW trace.
12517130809Smarcel
12518130809Smarcel@kindex htrace stop
12519130809Smarcel@item htrace stop @var{conditional}
12520130809SmarcelSet HW trace stopping criteria.
12521130809Smarcel
12522130809Smarcel@kindex htrace record
12523130809Smarcel@item htrace record [@var{data}]*
12524130809SmarcelSelects the data to be recorded, when qualifier is met and HW trace was
12525130809Smarceltriggered.
12526130809Smarcel
12527130809Smarcel@kindex htrace enable
12528130809Smarcel@item htrace enable
12529130809Smarcel@kindex htrace disable
12530130809Smarcel@itemx htrace disable
12531130809SmarcelEnables/disables the HW trace.
12532130809Smarcel
12533130809Smarcel@kindex htrace rewind
12534130809Smarcel@item htrace rewind [@var{filename}]
12535130809SmarcelClears currently recorded trace data.
12536130809Smarcel
12537130809SmarcelIf filename is specified, new trace file is made and any newly collected data
12538130809Smarcelwill be written there.
12539130809Smarcel
12540130809Smarcel@kindex htrace print
12541130809Smarcel@item htrace print [@var{start} [@var{len}]]
12542130809SmarcelPrints trace buffer, using current record configuration.
12543130809Smarcel
12544130809Smarcel@kindex htrace mode continuous
12545130809Smarcel@item htrace mode continuous
12546130809SmarcelSet continuous trace mode.
12547130809Smarcel
12548130809Smarcel@kindex htrace mode suspend
12549130809Smarcel@item htrace mode suspend
12550130809SmarcelSet suspend trace mode.
12551130809Smarcel
12552130809Smarcel@end table
12553130809Smarcel
1255498948Sobrien@node PowerPC
1255598948Sobrien@subsection PowerPC
1255698948Sobrien
1255798948Sobrien@table @code
1255898948Sobrien
1255998948Sobrien@kindex target dink32
1256098948Sobrien@item target dink32 @var{dev}
1256198948SobrienDINK32 ROM monitor.
1256298948Sobrien
1256398948Sobrien@kindex target ppcbug
1256498948Sobrien@item target ppcbug @var{dev}
1256598948Sobrien@kindex target ppcbug1
1256698948Sobrien@item target ppcbug1 @var{dev}
1256798948SobrienPPCBUG ROM monitor for PowerPC.
1256898948Sobrien
1256998948Sobrien@kindex target sds
1257098948Sobrien@item target sds @var{dev}
1257198948SobrienSDS monitor, running on a PowerPC board (such as Motorola's ADS).
1257298948Sobrien
1257398948Sobrien@end table
1257498948Sobrien
1257598948Sobrien@node PA
1257698948Sobrien@subsection HP PA Embedded
1257798948Sobrien
1257898948Sobrien@table @code
1257998948Sobrien
1258098948Sobrien@kindex target op50n
1258198948Sobrien@item target op50n @var{dev}
1258298948SobrienOP50N monitor, running on an OKI HPPA board.
1258398948Sobrien
1258498948Sobrien@kindex target w89k
1258598948Sobrien@item target w89k @var{dev}
1258698948SobrienW89K monitor, running on a Winbond HPPA board.
1258798948Sobrien
1258898948Sobrien@end table
1258998948Sobrien
1259098948Sobrien@node SH
12591130809Smarcel@subsection Renesas SH
1259298948Sobrien
1259398948Sobrien@table @code
1259498948Sobrien
12595130809Smarcel@kindex target hms@r{, with Renesas SH}
1259698948Sobrien@item target hms @var{dev}
12597130809SmarcelA Renesas SH board attached via serial line to your host.  Use special
1259898948Sobriencommands @code{device} and @code{speed} to control the serial line and
1259998948Sobrienthe communications speed used.
1260098948Sobrien
12601130809Smarcel@kindex target e7000@r{, with Renesas SH}
1260298948Sobrien@item target e7000 @var{dev}
12603130809SmarcelE7000 emulator for Renesas SH.
1260498948Sobrien
1260598948Sobrien@kindex target sh3@r{, with SH}
1260698948Sobrien@kindex target sh3e@r{, with SH}
1260798948Sobrien@item target sh3 @var{dev}
1260898948Sobrien@item target sh3e @var{dev}
12609130809SmarcelRenesas SH-3 and SH-3E target systems.
1261098948Sobrien
1261198948Sobrien@end table
1261298948Sobrien
1261398948Sobrien@node Sparclet
1261498948Sobrien@subsection Tsqware Sparclet
1261598948Sobrien
1261698948Sobrien@cindex Sparclet
1261798948Sobrien
1261898948Sobrien@value{GDBN} enables developers to debug tasks running on
1261998948SobrienSparclet targets from a Unix host.
1262098948Sobrien@value{GDBN} uses code that runs on
1262198948Sobrienboth the Unix host and on the Sparclet target.  The program
1262298948Sobrien@code{@value{GDBP}} is installed and executed on the Unix host.
1262398948Sobrien
1262498948Sobrien@table @code
1262598948Sobrien@item remotetimeout @var{args}
1262698948Sobrien@kindex remotetimeout
1262798948Sobrien@value{GDBN} supports the option @code{remotetimeout}.
1262898948SobrienThis option is set by the user, and  @var{args} represents the number of
1262998948Sobrienseconds @value{GDBN} waits for responses.
1263098948Sobrien@end table
1263198948Sobrien
1263298948Sobrien@cindex compiling, on Sparclet
1263398948SobrienWhen compiling for debugging, include the options @samp{-g} to get debug
1263498948Sobrieninformation and @samp{-Ttext} to relocate the program to where you wish to
1263598948Sobrienload it on the target.  You may also want to add the options @samp{-n} or
1263698948Sobrien@samp{-N} in order to reduce the size of the sections.  Example:
1263798948Sobrien
12638130809Smarcel@smallexample
1263998948Sobriensparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
12640130809Smarcel@end smallexample
1264198948Sobrien
1264298948SobrienYou can use @code{objdump} to verify that the addresses are what you intended:
1264398948Sobrien
12644130809Smarcel@smallexample
1264598948Sobriensparclet-aout-objdump --headers --syms prog
12646130809Smarcel@end smallexample
1264798948Sobrien
1264898948Sobrien@cindex running, on Sparclet
1264998948SobrienOnce you have set
1265098948Sobrienyour Unix execution search path to find @value{GDBN}, you are ready to
1265198948Sobrienrun @value{GDBN}.  From your Unix host, run @code{@value{GDBP}}
1265298948Sobrien(or @code{sparclet-aout-gdb}, depending on your installation).
1265398948Sobrien
1265498948Sobrien@value{GDBN} comes up showing the prompt:
1265598948Sobrien
12656130809Smarcel@smallexample
1265798948Sobrien(gdbslet)
12658130809Smarcel@end smallexample
1265998948Sobrien
1266098948Sobrien@menu
1266198948Sobrien* Sparclet File::                Setting the file to debug
1266298948Sobrien* Sparclet Connection::          Connecting to Sparclet
1266398948Sobrien* Sparclet Download::            Sparclet download
1266498948Sobrien* Sparclet Execution::           Running and debugging
1266598948Sobrien@end menu
1266698948Sobrien
1266798948Sobrien@node Sparclet File
1266898948Sobrien@subsubsection Setting file to debug
1266998948Sobrien
1267098948SobrienThe @value{GDBN} command @code{file} lets you choose with program to debug.
1267198948Sobrien
12672130809Smarcel@smallexample
1267398948Sobrien(gdbslet) file prog
12674130809Smarcel@end smallexample
1267598948Sobrien
1267698948Sobrien@need 1000
1267798948Sobrien@value{GDBN} then attempts to read the symbol table of @file{prog}.
1267898948Sobrien@value{GDBN} locates
1267998948Sobrienthe file by searching the directories listed in the command search
1268098948Sobrienpath.
1268198948SobrienIf the file was compiled with debug information (option "-g"), source
1268298948Sobrienfiles will be searched as well.
1268398948Sobrien@value{GDBN} locates
1268498948Sobrienthe source files by searching the directories listed in the directory search
1268598948Sobrienpath (@pxref{Environment, ,Your program's environment}).
1268698948SobrienIf it fails
1268798948Sobriento find a file, it displays a message such as:
1268898948Sobrien
12689130809Smarcel@smallexample
1269098948Sobrienprog: No such file or directory.
12691130809Smarcel@end smallexample
1269298948Sobrien
1269398948SobrienWhen this happens, add the appropriate directories to the search paths with
1269498948Sobrienthe @value{GDBN} commands @code{path} and @code{dir}, and execute the
1269598948Sobrien@code{target} command again.
1269698948Sobrien
1269798948Sobrien@node Sparclet Connection
1269898948Sobrien@subsubsection Connecting to Sparclet
1269998948Sobrien
1270098948SobrienThe @value{GDBN} command @code{target} lets you connect to a Sparclet target.
1270198948SobrienTo connect to a target on serial port ``@code{ttya}'', type:
1270298948Sobrien
12703130809Smarcel@smallexample
1270498948Sobrien(gdbslet) target sparclet /dev/ttya
1270598948SobrienRemote target sparclet connected to /dev/ttya
1270698948Sobrienmain () at ../prog.c:3
12707130809Smarcel@end smallexample
1270898948Sobrien
1270998948Sobrien@need 750
1271098948Sobrien@value{GDBN} displays messages like these:
1271198948Sobrien
12712130809Smarcel@smallexample
1271398948SobrienConnected to ttya.
12714130809Smarcel@end smallexample
1271598948Sobrien
1271698948Sobrien@node Sparclet Download
1271798948Sobrien@subsubsection Sparclet download
1271898948Sobrien
1271998948Sobrien@cindex download to Sparclet
1272098948SobrienOnce connected to the Sparclet target,
1272198948Sobrienyou can use the @value{GDBN}
1272298948Sobrien@code{load} command to download the file from the host to the target.
1272398948SobrienThe file name and load offset should be given as arguments to the @code{load}
1272498948Sobriencommand.
1272598948SobrienSince the file format is aout, the program must be loaded to the starting
1272698948Sobrienaddress.  You can use @code{objdump} to find out what this value is.  The load
1272798948Sobrienoffset is an offset which is added to the VMA (virtual memory address)
1272898948Sobrienof each of the file's sections.
1272998948SobrienFor instance, if the program
1273098948Sobrien@file{prog} was linked to text address 0x1201000, with data at 0x12010160
1273198948Sobrienand bss at 0x12010170, in @value{GDBN}, type:
1273298948Sobrien
12733130809Smarcel@smallexample
1273498948Sobrien(gdbslet) load prog 0x12010000
1273598948SobrienLoading section .text, size 0xdb0 vma 0x12010000
12736130809Smarcel@end smallexample
1273798948Sobrien
1273898948SobrienIf the code is loaded at a different address then what the program was linked
1273998948Sobriento, you may need to use the @code{section} and @code{add-symbol-file} commands
1274098948Sobriento tell @value{GDBN} where to map the symbol table.
1274198948Sobrien
1274298948Sobrien@node Sparclet Execution
1274398948Sobrien@subsubsection Running and debugging
1274498948Sobrien
1274598948Sobrien@cindex running and debugging Sparclet programs
1274698948SobrienYou can now begin debugging the task using @value{GDBN}'s execution control
1274798948Sobriencommands, @code{b}, @code{step}, @code{run}, etc.  See the @value{GDBN}
1274898948Sobrienmanual for the list of commands.
1274998948Sobrien
12750130809Smarcel@smallexample
1275198948Sobrien(gdbslet) b main
1275298948SobrienBreakpoint 1 at 0x12010000: file prog.c, line 3.
1275398948Sobrien(gdbslet) run
1275498948SobrienStarting program: prog
1275598948SobrienBreakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
1275698948Sobrien3        char *symarg = 0;
1275798948Sobrien(gdbslet) step
1275898948Sobrien4        char *execarg = "hello!";
1275998948Sobrien(gdbslet)
12760130809Smarcel@end smallexample
1276198948Sobrien
1276298948Sobrien@node Sparclite
1276398948Sobrien@subsection Fujitsu Sparclite
1276498948Sobrien
1276598948Sobrien@table @code
1276698948Sobrien
1276798948Sobrien@kindex target sparclite
1276898948Sobrien@item target sparclite @var{dev}
1276998948SobrienFujitsu sparclite boards, used only for the purpose of loading.
1277098948SobrienYou must use an additional command to debug the program.
1277198948SobrienFor example: target remote @var{dev} using @value{GDBN} standard
1277298948Sobrienremote protocol.
1277398948Sobrien
1277498948Sobrien@end table
1277598948Sobrien
1277698948Sobrien@node ST2000
1277798948Sobrien@subsection Tandem ST2000
1277898948Sobrien
1277998948Sobrien@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
1278098948SobrienSTDBUG protocol.
1278198948Sobrien
1278298948SobrienTo connect your ST2000 to the host system, see the manufacturer's
1278398948Sobrienmanual.  Once the ST2000 is physically attached, you can run:
1278498948Sobrien
12785130809Smarcel@smallexample
1278698948Sobrientarget st2000 @var{dev} @var{speed}
12787130809Smarcel@end smallexample
1278898948Sobrien
1278998948Sobrien@noindent
1279098948Sobriento establish it as your debugging environment.  @var{dev} is normally
1279198948Sobrienthe name of a serial device, such as @file{/dev/ttya}, connected to the
1279298948SobrienST2000 via a serial line.  You can instead specify @var{dev} as a TCP
1279398948Sobrienconnection (for example, to a serial line attached via a terminal
1279498948Sobrienconcentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
1279598948Sobrien
1279698948SobrienThe @code{load} and @code{attach} commands are @emph{not} defined for
1279798948Sobrienthis target; you must load your program into the ST2000 as you normally
1279898948Sobrienwould for standalone operation.  @value{GDBN} reads debugging information
1279998948Sobrien(such as symbols) from a separate, debugging version of the program
1280098948Sobrienavailable on your host computer.
1280198948Sobrien@c FIXME!! This is terribly vague; what little content is here is
1280298948Sobrien@c basically hearsay.
1280398948Sobrien
1280498948Sobrien@cindex ST2000 auxiliary commands
1280598948SobrienThese auxiliary @value{GDBN} commands are available to help you with the ST2000
1280698948Sobrienenvironment:
1280798948Sobrien
1280898948Sobrien@table @code
1280998948Sobrien@item st2000 @var{command}
1281098948Sobrien@kindex st2000 @var{cmd}
1281198948Sobrien@cindex STDBUG commands (ST2000)
1281298948Sobrien@cindex commands to STDBUG (ST2000)
1281398948SobrienSend a @var{command} to the STDBUG monitor.  See the manufacturer's
1281498948Sobrienmanual for available commands.
1281598948Sobrien
1281698948Sobrien@item connect
1281798948Sobrien@cindex connect (to STDBUG)
1281898948SobrienConnect the controlling terminal to the STDBUG command monitor.  When
1281998948Sobrienyou are done interacting with STDBUG, typing either of two character
1282098948Sobriensequences gets you back to the @value{GDBN} command prompt:
1282198948Sobrien@kbd{@key{RET}~.} (Return, followed by tilde and period) or
1282298948Sobrien@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
1282398948Sobrien@end table
1282498948Sobrien
1282598948Sobrien@node Z8000
1282698948Sobrien@subsection Zilog Z8000
1282798948Sobrien
1282898948Sobrien@cindex Z8000
1282998948Sobrien@cindex simulator, Z8000
1283098948Sobrien@cindex Zilog Z8000 simulator
1283198948Sobrien
1283298948SobrienWhen configured for debugging Zilog Z8000 targets, @value{GDBN} includes
1283398948Sobriena Z8000 simulator.
1283498948Sobrien
1283598948SobrienFor the Z8000 family, @samp{target sim} simulates either the Z8002 (the
1283698948Sobrienunsegmented variant of the Z8000 architecture) or the Z8001 (the
1283798948Sobriensegmented variant).  The simulator recognizes which architecture is
1283898948Sobrienappropriate by inspecting the object code.
1283998948Sobrien
1284098948Sobrien@table @code
1284198948Sobrien@item target sim @var{args}
1284298948Sobrien@kindex sim
1284398948Sobrien@kindex target sim@r{, with Z8000}
1284498948SobrienDebug programs on a simulated CPU.  If the simulator supports setup
1284598948Sobrienoptions, specify them via @var{args}.
1284698948Sobrien@end table
1284798948Sobrien
1284898948Sobrien@noindent
1284998948SobrienAfter specifying this target, you can debug programs for the simulated
1285098948SobrienCPU in the same style as programs for your host computer; use the
1285198948Sobrien@code{file} command to load a new program image, the @code{run} command
1285298948Sobriento run your program, and so on.
1285398948Sobrien
1285498948SobrienAs well as making available all the usual machine registers
1285598948Sobrien(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
1285698948Sobrienadditional items of information as specially named registers:
1285798948Sobrien
1285898948Sobrien@table @code
1285998948Sobrien
1286098948Sobrien@item cycles
1286198948SobrienCounts clock-ticks in the simulator.
1286298948Sobrien
1286398948Sobrien@item insts
1286498948SobrienCounts instructions run in the simulator.
1286598948Sobrien
1286698948Sobrien@item time
1286798948SobrienExecution time in 60ths of a second.
1286898948Sobrien
1286998948Sobrien@end table
1287098948Sobrien
1287198948SobrienYou can refer to these values in @value{GDBN} expressions with the usual
1287298948Sobrienconventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
1287398948Sobrienconditional breakpoint that suspends only after at least 5000
1287498948Sobriensimulated clock ticks.
1287598948Sobrien
1287698948Sobrien@node Architectures
1287798948Sobrien@section Architectures
1287898948Sobrien
1287998948SobrienThis section describes characteristics of architectures that affect
1288098948Sobrienall uses of @value{GDBN} with the architecture, both native and cross.
1288198948Sobrien
1288298948Sobrien@menu
1288398948Sobrien* A29K::
1288498948Sobrien* Alpha::
1288598948Sobrien* MIPS::
1288698948Sobrien@end menu
1288798948Sobrien
1288898948Sobrien@node A29K
1288998948Sobrien@subsection A29K
1289098948Sobrien
1289198948Sobrien@table @code
1289298948Sobrien
1289398948Sobrien@kindex set rstack_high_address
1289498948Sobrien@cindex AMD 29K register stack
1289598948Sobrien@cindex register stack, AMD29K
1289698948Sobrien@item set rstack_high_address @var{address}
1289798948SobrienOn AMD 29000 family processors, registers are saved in a separate
1289898948Sobrien@dfn{register stack}.  There is no way for @value{GDBN} to determine the
1289998948Sobrienextent of this stack.  Normally, @value{GDBN} just assumes that the
1290098948Sobrienstack is ``large enough''.  This may result in @value{GDBN} referencing
1290198948Sobrienmemory locations that do not exist.  If necessary, you can get around
1290298948Sobrienthis problem by specifying the ending address of the register stack with
1290398948Sobrienthe @code{set rstack_high_address} command.  The argument should be an
1290498948Sobrienaddress, which you probably want to precede with @samp{0x} to specify in
1290598948Sobrienhexadecimal.
1290698948Sobrien
1290798948Sobrien@kindex show rstack_high_address
1290898948Sobrien@item show rstack_high_address
1290998948SobrienDisplay the current limit of the register stack, on AMD 29000 family
1291098948Sobrienprocessors.
1291198948Sobrien
1291298948Sobrien@end table
1291398948Sobrien
1291498948Sobrien@node Alpha
1291598948Sobrien@subsection Alpha
1291698948Sobrien
1291798948SobrienSee the following section.
1291898948Sobrien
1291998948Sobrien@node MIPS
1292098948Sobrien@subsection MIPS
1292198948Sobrien
1292298948Sobrien@cindex stack on Alpha
1292398948Sobrien@cindex stack on MIPS
1292498948Sobrien@cindex Alpha stack
1292598948Sobrien@cindex MIPS stack
1292698948SobrienAlpha- and MIPS-based computers use an unusual stack frame, which
1292798948Sobriensometimes requires @value{GDBN} to search backward in the object code to
1292898948Sobrienfind the beginning of a function.
1292998948Sobrien
1293098948Sobrien@cindex response time, MIPS debugging
1293198948SobrienTo improve response time (especially for embedded applications, where
1293298948Sobrien@value{GDBN} may be restricted to a slow serial line for this search)
1293398948Sobrienyou may want to limit the size of this search, using one of these
1293498948Sobriencommands:
1293598948Sobrien
1293698948Sobrien@table @code
1293798948Sobrien@cindex @code{heuristic-fence-post} (Alpha, MIPS)
1293898948Sobrien@item set heuristic-fence-post @var{limit}
1293998948SobrienRestrict @value{GDBN} to examining at most @var{limit} bytes in its
1294098948Sobriensearch for the beginning of a function.  A value of @var{0} (the
1294198948Sobriendefault) means there is no limit.  However, except for @var{0}, the
1294298948Sobrienlarger the limit the more bytes @code{heuristic-fence-post} must search
1294398948Sobrienand therefore the longer it takes to run.
1294498948Sobrien
1294598948Sobrien@item show heuristic-fence-post
1294698948SobrienDisplay the current limit.
1294798948Sobrien@end table
1294898948Sobrien
1294998948Sobrien@noindent
1295098948SobrienThese commands are available @emph{only} when @value{GDBN} is configured
1295198948Sobrienfor debugging programs on Alpha or MIPS processors.
1295298948Sobrien
1295398948Sobrien
1295419370Spst@node Controlling GDB
1295519370Spst@chapter Controlling @value{GDBN}
1295619370Spst
1295798948SobrienYou can alter the way @value{GDBN} interacts with you by using the
1295898948Sobrien@code{set} command.  For commands controlling how @value{GDBN} displays
1295998948Sobriendata, see @ref{Print Settings, ,Print settings}.  Other settings are
1296098948Sobriendescribed here.
1296119370Spst
1296219370Spst@menu
1296319370Spst* Prompt::                      Prompt
1296419370Spst* Editing::                     Command editing
1296519370Spst* History::                     Command history
1296619370Spst* Screen Size::                 Screen size
1296719370Spst* Numbers::                     Numbers
12968130809Smarcel* ABI::                         Configuring the current ABI
1296919370Spst* Messages/Warnings::           Optional warnings and messages
1297098948Sobrien* Debugging Output::            Optional messages about internal happenings
1297119370Spst@end menu
1297219370Spst
1297398948Sobrien@node Prompt
1297419370Spst@section Prompt
1297519370Spst
1297619370Spst@cindex prompt
1297719370Spst
1297819370Spst@value{GDBN} indicates its readiness to read a command by printing a string
1297919370Spstcalled the @dfn{prompt}.  This string is normally @samp{(@value{GDBP})}.  You
1298019370Spstcan change the prompt string with the @code{set prompt} command.  For
1298119370Spstinstance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
1298298948Sobrienthe prompt in one of the @value{GDBN} sessions so that you can always tell
1298319370Spstwhich one you are talking to.
1298419370Spst
1298598948Sobrien@emph{Note:}  @code{set prompt} does not add a space for you after the
1298619370Spstprompt you set.  This allows you to set a prompt which ends in a space
1298719370Spstor a prompt that does not.
1298819370Spst
1298919370Spst@table @code
1299019370Spst@kindex set prompt
1299119370Spst@item set prompt @var{newprompt}
1299219370SpstDirects @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
1299319370Spst
1299419370Spst@kindex show prompt
1299519370Spst@item show prompt
1299619370SpstPrints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
1299719370Spst@end table
1299819370Spst
1299998948Sobrien@node Editing
1300019370Spst@section Command editing
1300119370Spst@cindex readline
1300219370Spst@cindex command line editing
1300319370Spst
1300419370Spst@value{GDBN} reads its input commands via the @dfn{readline} interface.  This
1300519370Spst@sc{gnu} library provides consistent behavior for programs which provide a
1300619370Spstcommand line interface to the user.  Advantages are @sc{gnu} Emacs-style
1300719370Spstor @dfn{vi}-style inline editing of commands, @code{csh}-like history
1300819370Spstsubstitution, and a storage and recall of command history across
1300919370Spstdebugging sessions.
1301019370Spst
1301119370SpstYou may control the behavior of command line editing in @value{GDBN} with the
1301219370Spstcommand @code{set}.
1301319370Spst
1301419370Spst@table @code
1301519370Spst@kindex set editing
1301619370Spst@cindex editing
1301719370Spst@item set editing
1301819370Spst@itemx set editing on
1301919370SpstEnable command line editing (enabled by default).
1302019370Spst
1302119370Spst@item set editing off
1302219370SpstDisable command line editing.
1302319370Spst
1302419370Spst@kindex show editing
1302519370Spst@item show editing
1302619370SpstShow whether command line editing is enabled.
1302719370Spst@end table
1302819370Spst
1302998948Sobrien@node History
1303019370Spst@section Command history
1303119370Spst
1303219370Spst@value{GDBN} can keep track of the commands you type during your
1303319370Spstdebugging sessions, so that you can be certain of precisely what
1303419370Spsthappened.  Use these commands to manage the @value{GDBN} command
1303519370Spsthistory facility.
1303619370Spst
1303719370Spst@table @code
1303819370Spst@cindex history substitution
1303919370Spst@cindex history file
1304019370Spst@kindex set history filename
1304119370Spst@kindex GDBHISTFILE
1304219370Spst@item set history filename @var{fname}
1304319370SpstSet the name of the @value{GDBN} command history file to @var{fname}.
1304419370SpstThis is the file where @value{GDBN} reads an initial command history
1304519370Spstlist, and where it writes the command history from this session when it
1304619370Spstexits.  You can access this list through history expansion or through
1304719370Spstthe history command editing characters listed below.  This file defaults
1304819370Spstto the value of the environment variable @code{GDBHISTFILE}, or to
1304998948Sobrien@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
1305098948Sobrienis not set.
1305119370Spst
1305219370Spst@cindex history save
1305319370Spst@kindex set history save
1305419370Spst@item set history save
1305519370Spst@itemx set history save on
1305619370SpstRecord command history in a file, whose name may be specified with the
1305719370Spst@code{set history filename} command.  By default, this option is disabled.
1305819370Spst
1305919370Spst@item set history save off
1306019370SpstStop recording command history in a file.
1306119370Spst
1306219370Spst@cindex history size
1306319370Spst@kindex set history size
1306419370Spst@item set history size @var{size}
1306519370SpstSet the number of commands which @value{GDBN} keeps in its history list.
1306619370SpstThis defaults to the value of the environment variable
1306719370Spst@code{HISTSIZE}, or to 256 if this variable is not set.
1306819370Spst@end table
1306919370Spst
1307019370Spst@cindex history expansion
1307119370SpstHistory expansion assigns special meaning to the character @kbd{!}.
1307219370Spst@ifset have-readline-appendices
1307319370Spst@xref{Event Designators}.
1307419370Spst@end ifset
1307519370Spst
1307619370SpstSince @kbd{!} is also the logical not operator in C, history expansion
1307719370Spstis off by default. If you decide to enable history expansion with the
1307819370Spst@code{set history expansion on} command, you may sometimes need to
1307919370Spstfollow @kbd{!} (when it is used as logical not, in an expression) with
1308019370Spsta space or a tab to prevent it from being expanded.  The readline
1308119370Spsthistory facilities do not attempt substitution on the strings
1308219370Spst@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
1308319370Spst
1308419370SpstThe commands to control history expansion are:
1308519370Spst
1308619370Spst@table @code
1308719370Spst@kindex set history expansion
1308819370Spst@item set history expansion on
1308919370Spst@itemx set history expansion
1309019370SpstEnable history expansion.  History expansion is off by default.
1309119370Spst
1309219370Spst@item set history expansion off
1309319370SpstDisable history expansion.
1309419370Spst
1309519370SpstThe readline code comes with more complete documentation of
1309619370Spstediting and history expansion features.  Users unfamiliar with @sc{gnu} Emacs
1309719370Spstor @code{vi} may wish to read it.
1309819370Spst@ifset have-readline-appendices
1309919370Spst@xref{Command Line Editing}.
1310019370Spst@end ifset
1310119370Spst
1310219370Spst@c @group
1310319370Spst@kindex show history
1310419370Spst@item show history
1310519370Spst@itemx show history filename
1310619370Spst@itemx show history save
1310719370Spst@itemx show history size
1310819370Spst@itemx show history expansion
1310919370SpstThese commands display the state of the @value{GDBN} history parameters.
1311019370Spst@code{show history} by itself displays all four states.
1311119370Spst@c @end group
1311219370Spst@end table
1311319370Spst
1311419370Spst@table @code
1311598948Sobrien@kindex shows
1311619370Spst@item show commands
1311719370SpstDisplay the last ten commands in the command history.
1311819370Spst
1311919370Spst@item show commands @var{n}
1312019370SpstPrint ten commands centered on command number @var{n}.
1312119370Spst
1312219370Spst@item show commands +
1312319370SpstPrint ten commands just after the commands last printed.
1312419370Spst@end table
1312519370Spst
1312698948Sobrien@node Screen Size
1312719370Spst@section Screen size
1312819370Spst@cindex size of screen
1312919370Spst@cindex pauses in output
1313019370Spst
1313119370SpstCertain commands to @value{GDBN} may produce large amounts of
1313219370Spstinformation output to the screen.  To help you read all of it,
1313319370Spst@value{GDBN} pauses and asks you for input at the end of each page of
1313419370Spstoutput.  Type @key{RET} when you want to continue the output, or @kbd{q}
1313519370Spstto discard the remaining output.  Also, the screen width setting
1313619370Spstdetermines when to wrap lines of output.  Depending on what is being
1313719370Spstprinted, @value{GDBN} tries to break the line at a readable place,
1313819370Spstrather than simply letting it overflow onto the following line.
1313919370Spst
1314098948SobrienNormally @value{GDBN} knows the size of the screen from the terminal
1314198948Sobriendriver software.  For example, on Unix @value{GDBN} uses the termcap data base
1314219370Spsttogether with the value of the @code{TERM} environment variable and the
1314398948Sobrien@code{stty rows} and @code{stty cols} settings.  If this is not correct,
1314419370Spstyou can override it with the @code{set height} and @code{set
1314519370Spstwidth} commands:
1314619370Spst
1314719370Spst@table @code
1314819370Spst@kindex set height
1314919370Spst@kindex set width
1315019370Spst@kindex show width
1315119370Spst@kindex show height
1315219370Spst@item set height @var{lpp}
1315319370Spst@itemx show height
1315419370Spst@itemx set width @var{cpl}
1315519370Spst@itemx show width
1315619370SpstThese @code{set} commands specify a screen height of @var{lpp} lines and
1315719370Spsta screen width of @var{cpl} characters.  The associated @code{show}
1315819370Spstcommands display the current settings.
1315919370Spst
1316098948SobrienIf you specify a height of zero lines, @value{GDBN} does not pause during
1316198948Sobrienoutput no matter how long the output is.  This is useful if output is to a
1316219370Spstfile or to an editor buffer.
1316319370Spst
1316419370SpstLikewise, you can specify @samp{set width 0} to prevent @value{GDBN}
1316519370Spstfrom wrapping its output.
1316619370Spst@end table
1316719370Spst
1316898948Sobrien@node Numbers
1316919370Spst@section Numbers
1317019370Spst@cindex number representation
1317119370Spst@cindex entering numbers
1317219370Spst
1317398948SobrienYou can always enter numbers in octal, decimal, or hexadecimal in
1317498948Sobrien@value{GDBN} by the usual conventions: octal numbers begin with
1317598948Sobrien@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
1317698948Sobrienbegin with @samp{0x}.  Numbers that begin with none of these are, by
1317798948Sobriendefault, entered in base 10; likewise, the default display for
1317898948Sobriennumbers---when no particular format is specified---is base 10.  You can
1317998948Sobrienchange the default base for both input and output with the @code{set
1318098948Sobrienradix} command.
1318119370Spst
1318219370Spst@table @code
1318319370Spst@kindex set input-radix
1318419370Spst@item set input-radix @var{base}
1318519370SpstSet the default base for numeric input.  Supported choices
1318619370Spstfor @var{base} are decimal 8, 10, or 16.  @var{base} must itself be
1318719370Spstspecified either unambiguously or using the current default radix; for
1318819370Spstexample, any of
1318919370Spst
1319019370Spst@smallexample
1319119370Spstset radix 012
1319219370Spstset radix 10.
1319319370Spstset radix 0xa
1319419370Spst@end smallexample
1319519370Spst
1319619370Spst@noindent
1319719370Spstsets the base to decimal.  On the other hand, @samp{set radix 10}
1319819370Spstleaves the radix unchanged no matter what it was.
1319919370Spst
1320019370Spst@kindex set output-radix
1320119370Spst@item set output-radix @var{base}
1320219370SpstSet the default base for numeric display.  Supported choices
1320319370Spstfor @var{base} are decimal 8, 10, or 16.  @var{base} must itself be
1320419370Spstspecified either unambiguously or using the current default radix.
1320519370Spst
1320619370Spst@kindex show input-radix
1320719370Spst@item show input-radix
1320819370SpstDisplay the current default base for numeric input.
1320919370Spst
1321019370Spst@kindex show output-radix
1321119370Spst@item show output-radix
1321219370SpstDisplay the current default base for numeric display.
1321319370Spst@end table
1321419370Spst
13215130809Smarcel@node ABI
13216130809Smarcel@section Configuring the current ABI
13217130809Smarcel
13218130809Smarcel@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
13219130809Smarcelapplication automatically.  However, sometimes you need to override its
13220130809Smarcelconclusions.  Use these commands to manage @value{GDBN}'s view of the
13221130809Smarcelcurrent ABI.
13222130809Smarcel
13223130809Smarcel@cindex OS ABI
13224130809Smarcel@kindex set osabi
13225130809Smarcel@kindex show osabi
13226130809Smarcel
13227130809SmarcelOne @value{GDBN} configuration can debug binaries for multiple operating
13228130809Smarcelsystem targets, either via remote debugging or native emulation.
13229130809Smarcel@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
13230130809Smarcelbut you can override its conclusion using the @code{set osabi} command.
13231130809SmarcelOne example where this is useful is in debugging of binaries which use
13232130809Smarcelan alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
13233130809Smarcelnot have the same identifying marks that the standard C library for your
13234130809Smarcelplatform provides.
13235130809Smarcel
13236130809Smarcel@table @code
13237130809Smarcel@item show osabi
13238130809SmarcelShow the OS ABI currently in use.
13239130809Smarcel
13240130809Smarcel@item set osabi
13241130809SmarcelWith no argument, show the list of registered available OS ABI's.
13242130809Smarcel
13243130809Smarcel@item set osabi @var{abi}
13244130809SmarcelSet the current OS ABI to @var{abi}.
13245130809Smarcel@end table
13246130809Smarcel
13247130809Smarcel@cindex float promotion
13248130809Smarcel@kindex set coerce-float-to-double
13249130809Smarcel
13250130809SmarcelGenerally, the way that an argument of type @code{float} is passed to a
13251130809Smarcelfunction depends on whether the function is prototyped.  For a prototyped
13252130809Smarcel(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
13253130809Smarcelaccording to the architecture's convention for @code{float}.  For unprototyped
13254130809Smarcel(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
13255130809Smarcel@code{double} and then passed.
13256130809Smarcel
13257130809SmarcelUnfortunately, some forms of debug information do not reliably indicate whether
13258130809Smarcela function is prototyped.  If @value{GDBN} calls a function that is not marked
13259130809Smarcelas prototyped, it consults @kbd{set coerce-float-to-double}.
13260130809Smarcel
13261130809Smarcel@table @code
13262130809Smarcel@item set coerce-float-to-double
13263130809Smarcel@itemx set coerce-float-to-double on
13264130809SmarcelArguments of type @code{float} will be promoted to @code{double} when passed
13265130809Smarcelto an unprototyped function.  This is the default setting.
13266130809Smarcel
13267130809Smarcel@item set coerce-float-to-double off
13268130809SmarcelArguments of type @code{float} will be passed directly to unprototyped
13269130809Smarcelfunctions.
13270130809Smarcel@end table
13271130809Smarcel
13272130809Smarcel@kindex set cp-abi
13273130809Smarcel@kindex show cp-abi
13274130809Smarcel@value{GDBN} needs to know the ABI used for your program's C@t{++}
13275130809Smarcelobjects.  The correct C@t{++} ABI depends on which C@t{++} compiler was
13276130809Smarcelused to build your application.  @value{GDBN} only fully supports
13277130809Smarcelprograms with a single C@t{++} ABI; if your program contains code using
13278130809Smarcelmultiple C@t{++} ABI's or if @value{GDBN} can not identify your
13279130809Smarcelprogram's ABI correctly, you can tell @value{GDBN} which ABI to use.
13280130809SmarcelCurrently supported ABI's include ``gnu-v2'', for @code{g++} versions
13281130809Smarcelbefore 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
13282130809Smarcel``hpaCC'' for the HP ANSI C@t{++} compiler.  Other C@t{++} compilers may
13283130809Smarceluse the ``gnu-v2'' or ``gnu-v3'' ABI's as well.  The default setting is
13284130809Smarcel``auto''.
13285130809Smarcel
13286130809Smarcel@table @code
13287130809Smarcel@item show cp-abi
13288130809SmarcelShow the C@t{++} ABI currently in use.
13289130809Smarcel
13290130809Smarcel@item set cp-abi
13291130809SmarcelWith no argument, show the list of supported C@t{++} ABI's.
13292130809Smarcel
13293130809Smarcel@item set cp-abi @var{abi}
13294130809Smarcel@itemx set cp-abi auto
13295130809SmarcelSet the current C@t{++} ABI to @var{abi}, or return to automatic detection.
13296130809Smarcel@end table
13297130809Smarcel
1329898948Sobrien@node Messages/Warnings
1329919370Spst@section Optional warnings and messages
1330019370Spst
1330198948SobrienBy default, @value{GDBN} is silent about its inner workings.  If you are
1330298948Sobrienrunning on a slow machine, you may want to use the @code{set verbose}
1330398948Sobriencommand.  This makes @value{GDBN} tell you when it does a lengthy
1330498948Sobrieninternal operation, so you will not think it has crashed.
1330519370Spst
1330619370SpstCurrently, the messages controlled by @code{set verbose} are those
1330719370Spstwhich announce that the symbol table for a source file is being read;
1330819370Spstsee @code{symbol-file} in @ref{Files, ,Commands to specify files}.
1330919370Spst
1331019370Spst@table @code
1331119370Spst@kindex set verbose
1331219370Spst@item set verbose on
1331319370SpstEnables @value{GDBN} output of certain informational messages.
1331419370Spst
1331519370Spst@item set verbose off
1331619370SpstDisables @value{GDBN} output of certain informational messages.
1331719370Spst
1331819370Spst@kindex show verbose
1331919370Spst@item show verbose
1332019370SpstDisplays whether @code{set verbose} is on or off.
1332119370Spst@end table
1332219370Spst
1332398948SobrienBy default, if @value{GDBN} encounters bugs in the symbol table of an
1332498948Sobrienobject file, it is silent; but if you are debugging a compiler, you may
1332598948Sobrienfind this information useful (@pxref{Symbol Errors, ,Errors reading
1332698948Sobriensymbol files}).
1332719370Spst
1332819370Spst@table @code
1332998948Sobrien
1333019370Spst@kindex set complaints
1333119370Spst@item set complaints @var{limit}
1333298948SobrienPermits @value{GDBN} to output @var{limit} complaints about each type of
1333398948Sobrienunusual symbols before becoming silent about the problem.  Set
1333498948Sobrien@var{limit} to zero to suppress all complaints; set it to a large number
1333598948Sobriento prevent complaints from being suppressed.
1333619370Spst
1333719370Spst@kindex show complaints
1333819370Spst@item show complaints
1333919370SpstDisplays how many symbol complaints @value{GDBN} is permitted to produce.
1334098948Sobrien
1334119370Spst@end table
1334219370Spst
1334319370SpstBy default, @value{GDBN} is cautious, and asks what sometimes seems to be a
1334419370Spstlot of stupid questions to confirm certain commands.  For example, if
1334519370Spstyou try to run a program which is already running:
1334619370Spst
13347130809Smarcel@smallexample
1334819370Spst(@value{GDBP}) run
1334919370SpstThe program being debugged has been started already.
1335019370SpstStart it from the beginning? (y or n)
13351130809Smarcel@end smallexample
1335219370Spst
1335319370SpstIf you are willing to unflinchingly face the consequences of your own
1335419370Spstcommands, you can disable this ``feature'':
1335519370Spst
1335619370Spst@table @code
1335798948Sobrien
1335819370Spst@kindex set confirm
1335919370Spst@cindex flinching
1336019370Spst@cindex confirmation
1336119370Spst@cindex stupid questions
1336219370Spst@item set confirm off
1336319370SpstDisables confirmation requests.
1336419370Spst
1336519370Spst@item set confirm on
1336619370SpstEnables confirmation requests (the default).
1336719370Spst
1336819370Spst@kindex show confirm
1336919370Spst@item show confirm
1337019370SpstDisplays state of confirmation requests.
1337198948Sobrien
1337219370Spst@end table
1337319370Spst
1337498948Sobrien@node Debugging Output
1337598948Sobrien@section Optional messages about internal happenings
1337698948Sobrien@table @code
1337798948Sobrien@kindex set debug arch
1337898948Sobrien@item set debug arch
1337998948SobrienTurns on or off display of gdbarch debugging info. The default is off
1338098948Sobrien@kindex show debug arch
1338198948Sobrien@item show debug arch
1338298948SobrienDisplays the current state of displaying gdbarch debugging info.
1338398948Sobrien@kindex set debug event
1338498948Sobrien@item set debug event
1338598948SobrienTurns on or off display of @value{GDBN} event debugging info. The
1338698948Sobriendefault is off.
1338798948Sobrien@kindex show debug event
1338898948Sobrien@item show debug event
1338998948SobrienDisplays the current state of displaying @value{GDBN} event debugging
1339098948Sobrieninfo.
1339198948Sobrien@kindex set debug expression
1339298948Sobrien@item set debug expression
1339398948SobrienTurns on or off display of @value{GDBN} expression debugging info. The
1339498948Sobriendefault is off.
1339598948Sobrien@kindex show debug expression
1339698948Sobrien@item show debug expression
1339798948SobrienDisplays the current state of displaying @value{GDBN} expression
1339898948Sobriendebugging info.
13399130809Smarcel@kindex set debug frame
13400130809Smarcel@item set debug frame
13401130809SmarcelTurns on or off display of @value{GDBN} frame debugging info.  The
13402130809Smarceldefault is off.
13403130809Smarcel@kindex show debug frame
13404130809Smarcel@item show debug frame
13405130809SmarcelDisplays the current state of displaying @value{GDBN} frame debugging
13406130809Smarcelinfo.
1340798948Sobrien@kindex set debug overload
1340898948Sobrien@item set debug overload
1340998948SobrienTurns on or off display of @value{GDBN} C@t{++} overload debugging
1341098948Sobrieninfo. This includes info such as ranking of functions, etc. The default
1341198948Sobrienis off.
1341298948Sobrien@kindex show debug overload
1341398948Sobrien@item show debug overload
1341498948SobrienDisplays the current state of displaying @value{GDBN} C@t{++} overload
1341598948Sobriendebugging info.
1341698948Sobrien@kindex set debug remote
1341798948Sobrien@cindex packets, reporting on stdout
1341898948Sobrien@cindex serial connections, debugging
1341998948Sobrien@item set debug remote
1342098948SobrienTurns on or off display of reports on all packets sent back and forth across
1342198948Sobrienthe serial line to the remote machine.  The info is printed on the
1342298948Sobrien@value{GDBN} standard output stream. The default is off.
1342398948Sobrien@kindex show debug remote
1342498948Sobrien@item show debug remote
1342598948SobrienDisplays the state of display of remote packets.
1342698948Sobrien@kindex set debug serial
1342798948Sobrien@item set debug serial
1342898948SobrienTurns on or off display of @value{GDBN} serial debugging info. The
1342998948Sobriendefault is off.
1343098948Sobrien@kindex show debug serial
1343198948Sobrien@item show debug serial
1343298948SobrienDisplays the current state of displaying @value{GDBN} serial debugging
1343398948Sobrieninfo.
1343498948Sobrien@kindex set debug target
1343598948Sobrien@item set debug target
1343698948SobrienTurns on or off display of @value{GDBN} target debugging info. This info
1343798948Sobrienincludes what is going on at the target level of GDB, as it happens. The
1343898948Sobriendefault is off.
1343998948Sobrien@kindex show debug target
1344098948Sobrien@item show debug target
1344198948SobrienDisplays the current state of displaying @value{GDBN} target debugging
1344298948Sobrieninfo.
1344398948Sobrien@kindex set debug varobj
1344498948Sobrien@item set debug varobj
1344598948SobrienTurns on or off display of @value{GDBN} variable object debugging
1344698948Sobrieninfo. The default is off.
1344798948Sobrien@kindex show debug varobj
1344898948Sobrien@item show debug varobj
1344998948SobrienDisplays the current state of displaying @value{GDBN} variable object
1345098948Sobriendebugging info.
1345198948Sobrien@end table
1345298948Sobrien
1345398948Sobrien@node Sequences
1345419370Spst@chapter Canned Sequences of Commands
1345519370Spst
1345619370SpstAside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
1345798948Sobriencommand lists}), @value{GDBN} provides two ways to store sequences of
1345898948Sobriencommands for execution as a unit: user-defined commands and command
1345998948Sobrienfiles.
1346019370Spst
1346119370Spst@menu
1346219370Spst* Define::                      User-defined commands
1346346289Sdfr* Hooks::                       User-defined command hooks
1346419370Spst* Command Files::               Command files
1346519370Spst* Output::                      Commands for controlled output
1346619370Spst@end menu
1346719370Spst
1346898948Sobrien@node Define
1346919370Spst@section User-defined commands
1347019370Spst
1347119370Spst@cindex user-defined command
1347298948SobrienA @dfn{user-defined command} is a sequence of @value{GDBN} commands to
1347398948Sobrienwhich you assign a new name as a command.  This is done with the
1347498948Sobrien@code{define} command.  User commands may accept up to 10 arguments
1347598948Sobrienseparated by whitespace.  Arguments are accessed within the user command
1347698948Sobrienvia @var{$arg0@dots{}$arg9}.  A trivial example:
1347719370Spst
1347819370Spst@smallexample
1347919370Spstdefine adder
1348019370Spst  print $arg0 + $arg1 + $arg2
1348119370Spst@end smallexample
1348219370Spst
1348398948Sobrien@noindent
1348498948SobrienTo execute the command use:
1348519370Spst
1348619370Spst@smallexample
1348719370Spstadder 1 2 3
1348819370Spst@end smallexample
1348919370Spst
1349098948Sobrien@noindent
1349198948SobrienThis defines the command @code{adder}, which prints the sum of
1349298948Sobrienits three arguments.  Note the arguments are text substitutions, so they may
1349319370Spstreference variables, use complex expressions, or even perform inferior
1349419370Spstfunctions calls.
1349519370Spst
1349619370Spst@table @code
1349798948Sobrien
1349819370Spst@kindex define
1349919370Spst@item define @var{commandname}
1350019370SpstDefine a command named @var{commandname}.  If there is already a command
1350119370Spstby that name, you are asked to confirm that you want to redefine it.
1350219370Spst
1350319370SpstThe definition of the command is made up of other @value{GDBN} command lines,
1350419370Spstwhich are given following the @code{define} command.  The end of these
1350519370Spstcommands is marked by a line containing @code{end}.
1350619370Spst
1350719370Spst@kindex if
1350819370Spst@kindex else
1350919370Spst@item if
1351019370SpstTakes a single argument, which is an expression to evaluate.
1351119370SpstIt is followed by a series of commands that are executed
1351219370Spstonly if the expression is true (nonzero).
1351319370SpstThere can then optionally be a line @code{else}, followed
1351419370Spstby a series of commands that are only executed if the expression
1351519370Spstwas false.  The end of the list is marked by a line containing @code{end}.
1351619370Spst
1351719370Spst@kindex while
1351819370Spst@item while
1351919370SpstThe syntax is similar to @code{if}: the command takes a single argument,
1352019370Spstwhich is an expression to evaluate, and must be followed by the commands to
1352119370Spstexecute, one per line, terminated by an @code{end}.
1352219370SpstThe commands are executed repeatedly as long as the expression
1352319370Spstevaluates to true.
1352419370Spst
1352519370Spst@kindex document
1352619370Spst@item document @var{commandname}
1352719370SpstDocument the user-defined command @var{commandname}, so that it can be
1352898948Sobrienaccessed by @code{help}.  The command @var{commandname} must already be
1352998948Sobriendefined.  This command reads lines of documentation just as @code{define}
1353098948Sobrienreads the lines of the command definition, ending with @code{end}.
1353198948SobrienAfter the @code{document} command is finished, @code{help} on command
1353219370Spst@var{commandname} displays the documentation you have written.
1353319370Spst
1353419370SpstYou may use the @code{document} command again to change the
1353519370Spstdocumentation of a command.  Redefining the command with @code{define}
1353619370Spstdoes not change the documentation.
1353719370Spst
1353819370Spst@kindex help user-defined
1353919370Spst@item help user-defined
1354019370SpstList all user-defined commands, with the first line of the documentation
1354119370Spst(if any) for each.
1354219370Spst
1354319370Spst@kindex show user
1354419370Spst@item show user
1354519370Spst@itemx show user @var{commandname}
1354698948SobrienDisplay the @value{GDBN} commands used to define @var{commandname} (but
1354798948Sobriennot its documentation).  If no @var{commandname} is given, display the
1354819370Spstdefinitions for all user-defined commands.
1354998948Sobrien
13550130809Smarcel@kindex show max-user-call-depth
13551130809Smarcel@kindex set max-user-call-depth
13552130809Smarcel@item show max-user-call-depth
13553130809Smarcel@itemx set max-user-call-depth
13554130809SmarcelThe value of @code{max-user-call-depth} controls how many recursion
13555130809Smarcellevels are allowed in user-defined commands before GDB suspects an
13556130809Smarcelinfinite recursion and aborts the command.
13557130809Smarcel
1355819370Spst@end table
1355919370Spst
1356019370SpstWhen user-defined commands are executed, the
1356119370Spstcommands of the definition are not printed.  An error in any command
1356219370Spststops execution of the user-defined command.
1356319370Spst
1356419370SpstIf used interactively, commands that would ask for confirmation proceed
1356598948Sobrienwithout asking when used inside a user-defined command.  Many @value{GDBN}
1356698948Sobriencommands that normally print messages to say what they are doing omit the
1356719370Spstmessages when used in a user-defined command.
1356819370Spst
1356998948Sobrien@node Hooks
1357019370Spst@section User-defined command hooks
1357198948Sobrien@cindex command hooks
1357298948Sobrien@cindex hooks, for commands
1357398948Sobrien@cindex hooks, pre-command
1357419370Spst
1357598948Sobrien@kindex hook
1357698948Sobrien@kindex hook-
1357798948SobrienYou may define @dfn{hooks}, which are a special kind of user-defined
1357819370Spstcommand.  Whenever you run the command @samp{foo}, if the user-defined
1357919370Spstcommand @samp{hook-foo} exists, it is executed (with no arguments)
1358019370Spstbefore that command.
1358119370Spst
1358298948Sobrien@cindex hooks, post-command
1358398948Sobrien@kindex hookpost
1358498948Sobrien@kindex hookpost-
1358598948SobrienA hook may also be defined which is run after the command you executed.
1358698948SobrienWhenever you run the command @samp{foo}, if the user-defined command
1358798948Sobrien@samp{hookpost-foo} exists, it is executed (with no arguments) after
1358898948Sobrienthat command.  Post-execution hooks may exist simultaneously with
1358998948Sobrienpre-execution hooks, for the same command.
1359098948Sobrien
1359198948SobrienIt is valid for a hook to call the command which it hooks.  If this
1359298948Sobrienoccurs, the hook is not re-executed, thereby avoiding infinte recursion.
1359398948Sobrien
1359498948Sobrien@c It would be nice if hookpost could be passed a parameter indicating
1359598948Sobrien@c if the command it hooks executed properly or not.  FIXME!
1359698948Sobrien
1359798948Sobrien@kindex stop@r{, a pseudo-command}
1359819370SpstIn addition, a pseudo-command, @samp{stop} exists.  Defining
1359919370Spst(@samp{hook-stop}) makes the associated commands execute every time
1360019370Spstexecution stops in your program: before breakpoint commands are run,
1360119370Spstdisplays are printed, or the stack frame is printed.
1360219370Spst
1360319370SpstFor example, to ignore @code{SIGALRM} signals while
1360419370Spstsingle-stepping, but treat them normally during normal execution,
1360519370Spstyou could define:
1360619370Spst
13607130809Smarcel@smallexample
1360819370Spstdefine hook-stop
1360919370Spsthandle SIGALRM nopass
1361019370Spstend
1361119370Spst
1361219370Spstdefine hook-run
1361319370Spsthandle SIGALRM pass
1361419370Spstend
1361519370Spst
1361619370Spstdefine hook-continue
1361719370Spsthandle SIGLARM pass
1361819370Spstend
13619130809Smarcel@end smallexample
1362019370Spst
1362198948SobrienAs a further example, to hook at the begining and end of the @code{echo}
13622130809Smarcelcommand, and to add extra text to the beginning and end of the message,
1362398948Sobrienyou could define:
1362498948Sobrien
13625130809Smarcel@smallexample
1362698948Sobriendefine hook-echo
1362798948Sobrienecho <<<---
1362898948Sobrienend
1362998948Sobrien
1363098948Sobriendefine hookpost-echo
1363198948Sobrienecho --->>>\n
1363298948Sobrienend
1363398948Sobrien
1363498948Sobrien(@value{GDBP}) echo Hello World
1363598948Sobrien<<<---Hello World--->>>
1363698948Sobrien(@value{GDBP})
1363798948Sobrien
13638130809Smarcel@end smallexample
1363998948Sobrien
1364019370SpstYou can define a hook for any single-word command in @value{GDBN}, but
1364119370Spstnot for command aliases; you should define a hook for the basic command
1364219370Spstname, e.g.  @code{backtrace} rather than @code{bt}.
1364319370Spst@c FIXME!  So how does Joe User discover whether a command is an alias
1364419370Spst@c or not?
1364519370SpstIf an error occurs during the execution of your hook, execution of
1364619370Spst@value{GDBN} commands stops and @value{GDBN} issues a prompt
1364719370Spst(before the command that you actually typed had a chance to run).
1364819370Spst
1364919370SpstIf you try to define a hook which does not match any known command, you
1365019370Spstget a warning from the @code{define} command.
1365119370Spst
1365298948Sobrien@node Command Files
1365319370Spst@section Command files
1365419370Spst
1365519370Spst@cindex command files
1365698948SobrienA command file for @value{GDBN} is a file of lines that are @value{GDBN}
1365798948Sobriencommands.  Comments (lines starting with @kbd{#}) may also be included.
1365898948SobrienAn empty line in a command file does nothing; it does not mean to repeat
1365919370Spstthe last command, as it would from the terminal.
1366019370Spst
1366119370Spst@cindex init file
1366246289Sdfr@cindex @file{.gdbinit}
1366398948Sobrien@cindex @file{gdb.ini}
1366419370SpstWhen you start @value{GDBN}, it automatically executes commands from its
1366598948Sobrien@dfn{init files}, normally called @file{.gdbinit}@footnote{The DJGPP
1366698948Sobrienport of @value{GDBN} uses the name @file{gdb.ini} instead, due to the
1366798948Sobrienlimitations of file names imposed by DOS filesystems.}.
1366898948SobrienDuring startup, @value{GDBN} does the following:
1366919370Spst
1367098948Sobrien@enumerate
1367198948Sobrien@item
1367298948SobrienReads the init file (if any) in your home directory@footnote{On
1367398948SobrienDOS/Windows systems, the home directory is the one pointed to by the
1367498948Sobrien@code{HOME} environment variable.}.
1367598948Sobrien
1367698948Sobrien@item
1367798948SobrienProcesses command line options and operands.
1367898948Sobrien
1367998948Sobrien@item
1368098948SobrienReads the init file (if any) in the current working directory.
1368198948Sobrien
1368298948Sobrien@item
1368398948SobrienReads command files specified by the @samp{-x} option.
1368498948Sobrien@end enumerate
1368598948Sobrien
1368698948SobrienThe init file in your home directory can set options (such as @samp{set
1368798948Sobriencomplaints}) that affect subsequent processing of command line options
1368898948Sobrienand operands.  Init files are not executed if you use the @samp{-nx}
1368998948Sobrienoption (@pxref{Mode Options, ,Choosing modes}).
1369098948Sobrien
1369119370Spst@cindex init file name
1369219370SpstOn some configurations of @value{GDBN}, the init file is known by a
1369319370Spstdifferent name (these are typically environments where a specialized
1369446289Sdfrform of @value{GDBN} may need to coexist with other forms, hence a
1369546289Sdfrdifferent name for the specialized version's init file).  These are the
1369646289Sdfrenvironments with special init file names:
1369719370Spst
1369898948Sobrien@cindex @file{.vxgdbinit}
1369919370Spst@itemize @bullet
1370019370Spst@item
1370198948SobrienVxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
1370219370Spst
1370398948Sobrien@cindex @file{.os68gdbinit}
1370419370Spst@item
1370598948SobrienOS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
1370619370Spst
1370798948Sobrien@cindex @file{.esgdbinit}
1370819370Spst@item
1370998948SobrienES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
1371019370Spst@end itemize
1371119370Spst
1371219370SpstYou can also request the execution of a command file with the
1371319370Spst@code{source} command:
1371419370Spst
1371519370Spst@table @code
1371619370Spst@kindex source
1371719370Spst@item source @var{filename}
1371819370SpstExecute the command file @var{filename}.
1371919370Spst@end table
1372019370Spst
1372119370SpstThe lines in a command file are executed sequentially.  They are not
13722130809Smarcelprinted as they are executed.  An error in any command terminates
13723130809Smarcelexecution of the command file and control is returned to the console.
1372419370Spst
1372519370SpstCommands that would ask for confirmation if used interactively proceed
1372619370Spstwithout asking when used in a command file.  Many @value{GDBN} commands that
1372719370Spstnormally print messages to say what they are doing omit the messages
1372819370Spstwhen called from command files.
1372919370Spst
1373098948Sobrien@value{GDBN} also accepts command input from standard input.  In this
1373198948Sobrienmode, normal output goes to standard output and error output goes to
1373298948Sobrienstandard error.  Errors in a command file supplied on standard input do
1373398948Sobriennot terminate execution of the command file --- execution continues with
1373498948Sobrienthe next command.
1373598948Sobrien
13736130809Smarcel@smallexample
1373798948Sobriengdb < cmds > log 2>&1
13738130809Smarcel@end smallexample
1373998948Sobrien
1374098948Sobrien(The syntax above will vary depending on the shell used.) This example
1374198948Sobrienwill execute commands from the file @file{cmds}. All output and errors
1374298948Sobrienwould be directed to @file{log}.
1374398948Sobrien
1374498948Sobrien@node Output
1374519370Spst@section Commands for controlled output
1374619370Spst
1374719370SpstDuring the execution of a command file or a user-defined command, normal
1374819370Spst@value{GDBN} output is suppressed; the only output that appears is what is
1374919370Spstexplicitly printed by the commands in the definition.  This section
1375019370Spstdescribes three commands useful for generating exactly the output you
1375119370Spstwant.
1375219370Spst
1375319370Spst@table @code
1375419370Spst@kindex echo
1375519370Spst@item echo @var{text}
1375619370Spst@c I do not consider backslash-space a standard C escape sequence
1375719370Spst@c because it is not in ANSI.
1375819370SpstPrint @var{text}.  Nonprinting characters can be included in
1375919370Spst@var{text} using C escape sequences, such as @samp{\n} to print a
1376019370Spstnewline.  @strong{No newline is printed unless you specify one.}
1376119370SpstIn addition to the standard C escape sequences, a backslash followed
1376219370Spstby a space stands for a space.  This is useful for displaying a
1376319370Spststring with spaces at the beginning or the end, since leading and
1376498948Sobrientrailing spaces are otherwise trimmed from all arguments.
1376519370SpstTo print @samp{@w{ }and foo =@w{ }}, use the command
1376619370Spst@samp{echo \@w{ }and foo = \@w{ }}.
1376719370Spst
1376819370SpstA backslash at the end of @var{text} can be used, as in C, to continue
1376919370Spstthe command onto subsequent lines.  For example,
1377019370Spst
13771130809Smarcel@smallexample
1377219370Spstecho This is some text\n\
1377319370Spstwhich is continued\n\
1377419370Spstonto several lines.\n
13775130809Smarcel@end smallexample
1377619370Spst
1377719370Spstproduces the same output as
1377819370Spst
13779130809Smarcel@smallexample
1378019370Spstecho This is some text\n
1378119370Spstecho which is continued\n
1378219370Spstecho onto several lines.\n
13783130809Smarcel@end smallexample
1378419370Spst
1378519370Spst@kindex output
1378619370Spst@item output @var{expression}
1378719370SpstPrint the value of @var{expression} and nothing but that value: no
1378819370Spstnewlines, no @samp{$@var{nn} = }.  The value is not entered in the
1378998948Sobrienvalue history either.  @xref{Expressions, ,Expressions}, for more information
1379019370Spston expressions.
1379119370Spst
1379219370Spst@item output/@var{fmt} @var{expression}
1379319370SpstPrint the value of @var{expression} in format @var{fmt}.  You can use
1379419370Spstthe same formats as for @code{print}.  @xref{Output Formats,,Output
1379519370Spstformats}, for more information.
1379619370Spst
1379719370Spst@kindex printf
1379819370Spst@item printf @var{string}, @var{expressions}@dots{}
1379919370SpstPrint the values of the @var{expressions} under the control of
1380019370Spst@var{string}.  The @var{expressions} are separated by commas and may be
1380119370Spsteither numbers or pointers.  Their values are printed as specified by
1380219370Spst@var{string}, exactly as if your program were to execute the C
1380319370Spstsubroutine
1380498948Sobrien@c FIXME: the above implies that at least all ANSI C formats are
1380598948Sobrien@c supported, but it isn't true: %E and %G don't work (or so it seems).
1380698948Sobrien@c Either this is a bug, or the manual should document what formats are
1380798948Sobrien@c supported.
1380819370Spst
13809130809Smarcel@smallexample
1381019370Spstprintf (@var{string}, @var{expressions}@dots{});
13811130809Smarcel@end smallexample
1381219370Spst
1381319370SpstFor example, you can print two values in hex like this:
1381419370Spst
1381519370Spst@smallexample
1381619370Spstprintf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
1381719370Spst@end smallexample
1381819370Spst
1381919370SpstThe only backslash-escape sequences that you can use in the format
1382019370Spststring are the simple ones that consist of backslash followed by a
1382119370Spstletter.
1382219370Spst@end table
1382319370Spst
13824130809Smarcel@node Interpreters
13825130809Smarcel@chapter Command Interpreters
13826130809Smarcel@cindex command interpreters
13827130809Smarcel
13828130809Smarcel@value{GDBN} supports multiple command interpreters, and some command
13829130809Smarcelinfrastructure to allow users or user interface writers to switch
13830130809Smarcelbetween interpreters or run commands in other interpreters.
13831130809Smarcel
13832130809Smarcel@value{GDBN} currently supports two command interpreters, the console
13833130809Smarcelinterpreter (sometimes called the command-line interpreter or @sc{cli})
13834130809Smarceland the machine interface interpreter (or @sc{gdb/mi}).  This manual
13835130809Smarceldescribes both of these interfaces in great detail.
13836130809Smarcel
13837130809SmarcelBy default, @value{GDBN} will start with the console interpreter.
13838130809SmarcelHowever, the user may choose to start @value{GDBN} with another
13839130809Smarcelinterpreter by specifying the @option{-i} or @option{--interpreter}
13840130809Smarcelstartup options.  Defined interpreters include:
13841130809Smarcel
13842130809Smarcel@table @code
13843130809Smarcel@item console
13844130809Smarcel@cindex console interpreter
13845130809SmarcelThe traditional console or command-line interpreter.  This is the most often
13846130809Smarcelused interpreter with @value{GDBN}. With no interpreter specified at runtime,
13847130809Smarcel@value{GDBN} will use this interpreter.
13848130809Smarcel
13849130809Smarcel@item mi
13850130809Smarcel@cindex mi interpreter
13851130809SmarcelThe newest @sc{gdb/mi} interface (currently @code{mi2}).  Used primarily
13852130809Smarcelby programs wishing to use @value{GDBN} as a backend for a debugger GUI
13853130809Smarcelor an IDE.  For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
13854130809SmarcelInterface}.
13855130809Smarcel
13856130809Smarcel@item mi2
13857130809Smarcel@cindex mi2 interpreter
13858130809SmarcelThe current @sc{gdb/mi} interface.
13859130809Smarcel
13860130809Smarcel@item mi1
13861130809Smarcel@cindex mi1 interpreter
13862130809SmarcelThe @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
13863130809Smarcel
13864130809Smarcel@end table
13865130809Smarcel
13866130809Smarcel@cindex invoke another interpreter
13867130809SmarcelThe interpreter being used by @value{GDBN} may not be dynamically
13868130809Smarcelswitched at runtime.  Although possible, this could lead to a very
13869130809Smarcelprecarious situation.  Consider an IDE using @sc{gdb/mi}.  If a user
13870130809Smarcelenters the command "interpreter-set console" in a console view,
13871130809Smarcel@value{GDBN} would switch to using the console interpreter, rendering
13872130809Smarcelthe IDE inoperable!
13873130809Smarcel
13874130809Smarcel@kindex interpreter-exec
13875130809SmarcelAlthough you may only choose a single interpreter at startup, you may execute
13876130809Smarcelcommands in any interpreter from the current interpreter using the appropriate
13877130809Smarcelcommand.  If you are running the console interpreter, simply use the
13878130809Smarcel@code{interpreter-exec} command:
13879130809Smarcel
13880130809Smarcel@smallexample
13881130809Smarcelinterpreter-exec mi "-data-list-register-names"
13882130809Smarcel@end smallexample
13883130809Smarcel
13884130809Smarcel@sc{gdb/mi} has a similar command, although it is only available in versions of
13885130809Smarcel@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
13886130809Smarcel
1388798948Sobrien@node TUI
1388898948Sobrien@chapter @value{GDBN} Text User Interface
1388998948Sobrien@cindex TUI
13890130809Smarcel@cindex Text User Interface
1389198948Sobrien
1389298948Sobrien@menu
1389398948Sobrien* TUI Overview::                TUI overview
1389498948Sobrien* TUI Keys::                    TUI key bindings
13895130809Smarcel* TUI Single Key Mode::         TUI single key mode
1389698948Sobrien* TUI Commands::                TUI specific commands
1389798948Sobrien* TUI Configuration::           TUI configuration variables
1389898948Sobrien@end menu
1389998948Sobrien
13900130809SmarcelThe @value{GDBN} Text User Interface, TUI in short, is a terminal
13901130809Smarcelinterface which uses the @code{curses} library to show the source
13902130809Smarcelfile, the assembly output, the program registers and @value{GDBN}
13903130809Smarcelcommands in separate text windows.
1390498948Sobrien
13905130809SmarcelThe TUI is enabled by invoking @value{GDBN} using either
13906130809Smarcel@pindex gdbtui
13907130809Smarcel@samp{gdbtui} or @samp{gdb -tui}.
13908130809Smarcel
1390998948Sobrien@node TUI Overview
1391098948Sobrien@section TUI overview
1391198948Sobrien
1391298948SobrienThe TUI has two display modes that can be switched while
1391398948Sobrien@value{GDBN} runs:
1391498948Sobrien
1391598948Sobrien@itemize @bullet
1391698948Sobrien@item
1391798948SobrienA curses (or TUI) mode in which it displays several text
1391898948Sobrienwindows on the terminal.
1391998948Sobrien
1392098948Sobrien@item
1392198948SobrienA standard mode which corresponds to the @value{GDBN} configured without
1392298948Sobrienthe TUI.
1392398948Sobrien@end itemize
1392498948Sobrien
1392598948SobrienIn the TUI mode, @value{GDBN} can display several text window
1392698948Sobrienon the terminal:
1392798948Sobrien
1392898948Sobrien@table @emph
1392998948Sobrien@item command
1393098948SobrienThis window is the @value{GDBN} command window with the @value{GDBN}
1393198948Sobrienprompt and the @value{GDBN} outputs.  The @value{GDBN} input is still
1393298948Sobrienmanaged using readline but through the TUI.  The @emph{command}
1393398948Sobrienwindow is always visible.
1393498948Sobrien
1393598948Sobrien@item source
1393698948SobrienThe source window shows the source file of the program.  The current
1393798948Sobrienline as well as active breakpoints are displayed in this window.
1393898948Sobrien
1393998948Sobrien@item assembly
1394098948SobrienThe assembly window shows the disassembly output of the program.
1394198948Sobrien
1394298948Sobrien@item register
1394398948SobrienThis window shows the processor registers.  It detects when
1394498948Sobriena register is changed and when this is the case, registers that have
13945130809Smarcelchanged are highlighted.  
1394698948Sobrien
1394798948Sobrien@end table
1394898948Sobrien
13949130809SmarcelThe source and assembly windows show the current program position
13950130809Smarcelby highlighting the current line and marking them with the @samp{>} marker.
13951130809SmarcelBreakpoints are also indicated with two markers.  A first one
13952130809Smarcelindicates the breakpoint type:
13953130809Smarcel
13954130809Smarcel@table @code
13955130809Smarcel@item B
13956130809SmarcelBreakpoint which was hit at least once.
13957130809Smarcel
13958130809Smarcel@item b
13959130809SmarcelBreakpoint which was never hit.
13960130809Smarcel
13961130809Smarcel@item H
13962130809SmarcelHardware breakpoint which was hit at least once.
13963130809Smarcel
13964130809Smarcel@item h
13965130809SmarcelHardware breakpoint which was never hit.
13966130809Smarcel
13967130809Smarcel@end table
13968130809Smarcel
13969130809SmarcelThe second marker indicates whether the breakpoint is enabled or not:
13970130809Smarcel
13971130809Smarcel@table @code
13972130809Smarcel@item +
13973130809SmarcelBreakpoint is enabled.
13974130809Smarcel
13975130809Smarcel@item -
13976130809SmarcelBreakpoint is disabled.
13977130809Smarcel
13978130809Smarcel@end table
13979130809Smarcel
1398098948SobrienThe source, assembly and register windows are attached to the thread
1398198948Sobrienand the frame position.  They are updated when the current thread
1398298948Sobrienchanges, when the frame changes or when the program counter changes.
1398398948SobrienThese three windows are arranged by the TUI according to several
1398498948Sobrienlayouts.  The layout defines which of these three windows are visible.
1398598948SobrienThe following layouts are available:
1398698948Sobrien
1398798948Sobrien@itemize @bullet
1398898948Sobrien@item
1398998948Sobriensource
1399098948Sobrien
1399198948Sobrien@item
1399298948Sobrienassembly
1399398948Sobrien
1399498948Sobrien@item
1399598948Sobriensource and assembly
1399698948Sobrien
1399798948Sobrien@item
1399898948Sobriensource and registers
1399998948Sobrien
1400098948Sobrien@item
1400198948Sobrienassembly and registers
1400298948Sobrien
1400398948Sobrien@end itemize
1400498948Sobrien
14005130809SmarcelOn top of the command window a status line gives various information
14006130809Smarcelconcerning the current process begin debugged.  The status line is
14007130809Smarcelupdated when the information it shows changes.  The following fields
14008130809Smarcelare displayed:
14009130809Smarcel
14010130809Smarcel@table @emph
14011130809Smarcel@item target
14012130809SmarcelIndicates the current gdb target
14013130809Smarcel(@pxref{Targets, ,Specifying a Debugging Target}).
14014130809Smarcel
14015130809Smarcel@item process
14016130809SmarcelGives information about the current process or thread number.
14017130809SmarcelWhen no process is being debugged, this field is set to @code{No process}.
14018130809Smarcel
14019130809Smarcel@item function
14020130809SmarcelGives the current function name for the selected frame.
14021130809SmarcelThe name is demangled if demangling is turned on (@pxref{Print Settings}).
14022130809SmarcelWhen there is no symbol corresponding to the current program counter
14023130809Smarcelthe string @code{??} is displayed.
14024130809Smarcel
14025130809Smarcel@item line
14026130809SmarcelIndicates the current line number for the selected frame.
14027130809SmarcelWhen the current line number is not known the string @code{??} is displayed.
14028130809Smarcel
14029130809Smarcel@item pc
14030130809SmarcelIndicates the current program counter address.
14031130809Smarcel
14032130809Smarcel@end table
14033130809Smarcel
1403498948Sobrien@node TUI Keys
1403598948Sobrien@section TUI Key Bindings
1403698948Sobrien@cindex TUI key bindings
1403798948Sobrien
1403898948SobrienThe TUI installs several key bindings in the readline keymaps
1403998948Sobrien(@pxref{Command Line Editing}).
1404098948SobrienThey allow to leave or enter in the TUI mode or they operate
14041130809Smarceldirectly on the TUI layout and windows.  The TUI also provides
14042130809Smarcela @emph{SingleKey} keymap which binds several keys directly to
14043130809Smarcel@value{GDBN} commands.  The following key bindings
1404498948Sobrienare installed for both TUI mode and the @value{GDBN} standard mode.
1404598948Sobrien
1404698948Sobrien@table @kbd
1404798948Sobrien@kindex C-x C-a
1404898948Sobrien@item C-x C-a
1404998948Sobrien@kindex C-x a
1405098948Sobrien@itemx C-x a
1405198948Sobrien@kindex C-x A
1405298948Sobrien@itemx C-x A
1405398948SobrienEnter or leave the TUI mode.  When the TUI mode is left,
1405498948Sobrienthe curses window management is left and @value{GDBN} operates using
1405598948Sobrienits standard mode writing on the terminal directly.  When the TUI
1405698948Sobrienmode is entered, the control is given back to the curses windows.
1405798948SobrienThe screen is then refreshed.
1405898948Sobrien
1405998948Sobrien@kindex C-x 1
1406098948Sobrien@item C-x 1
1406198948SobrienUse a TUI layout with only one window.  The layout will
1406298948Sobrieneither be @samp{source} or @samp{assembly}.  When the TUI mode
1406398948Sobrienis not active, it will switch to the TUI mode.
1406498948Sobrien
1406598948SobrienThink of this key binding as the Emacs @kbd{C-x 1} binding.
1406698948Sobrien
1406798948Sobrien@kindex C-x 2
1406898948Sobrien@item C-x 2
1406998948SobrienUse a TUI layout with at least two windows.  When the current
1407098948Sobrienlayout shows already two windows, a next layout with two windows is used.
1407198948SobrienWhen a new layout is chosen, one window will always be common to the
1407298948Sobrienprevious layout and the new one.
1407398948Sobrien
1407498948SobrienThink of it as the Emacs @kbd{C-x 2} binding.
1407598948Sobrien
14076130809Smarcel@kindex C-x o
14077130809Smarcel@item C-x o
14078130809SmarcelChange the active window.  The TUI associates several key bindings
14079130809Smarcel(like scrolling and arrow keys) to the active window. This command
14080130809Smarcelgives the focus to the next TUI window.
14081130809Smarcel
14082130809SmarcelThink of it as the Emacs @kbd{C-x o} binding.
14083130809Smarcel
14084130809Smarcel@kindex C-x s
14085130809Smarcel@item C-x s
14086130809SmarcelUse the TUI @emph{SingleKey} keymap that binds single key to gdb commands
14087130809Smarcel(@pxref{TUI Single Key Mode}).
14088130809Smarcel
1408998948Sobrien@end table
1409098948Sobrien
1409198948SobrienThe following key bindings are handled only by the TUI mode:
1409298948Sobrien
1409398948Sobrien@table @key
1409498948Sobrien@kindex PgUp
1409598948Sobrien@item PgUp
1409698948SobrienScroll the active window one page up.
1409798948Sobrien
1409898948Sobrien@kindex PgDn
1409998948Sobrien@item PgDn
1410098948SobrienScroll the active window one page down.
1410198948Sobrien
1410298948Sobrien@kindex Up
1410398948Sobrien@item Up
1410498948SobrienScroll the active window one line up.
1410598948Sobrien
1410698948Sobrien@kindex Down
1410798948Sobrien@item Down
1410898948SobrienScroll the active window one line down.
1410998948Sobrien
1411098948Sobrien@kindex Left
1411198948Sobrien@item Left
1411298948SobrienScroll the active window one column left.
1411398948Sobrien
1411498948Sobrien@kindex Right
1411598948Sobrien@item Right
1411698948SobrienScroll the active window one column right.
1411798948Sobrien
1411898948Sobrien@kindex C-L
1411998948Sobrien@item C-L
1412098948SobrienRefresh the screen.
1412198948Sobrien
1412298948Sobrien@end table
1412398948Sobrien
1412498948SobrienIn the TUI mode, the arrow keys are used by the active window
14125130809Smarcelfor scrolling.  This means they are available for readline when the
14126130809Smarcelactive window is the command window.  When the command window
14127130809Smarceldoes not have the focus, it is necessary to use other readline
14128130809Smarcelkey bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
1412998948Sobrien
14130130809Smarcel@node TUI Single Key Mode
14131130809Smarcel@section TUI Single Key Mode
14132130809Smarcel@cindex TUI single key mode
14133130809Smarcel
14134130809SmarcelThe TUI provides a @emph{SingleKey} mode in which it installs a particular
14135130809Smarcelkey binding in the readline keymaps to connect single keys to
14136130809Smarcelsome gdb commands.
14137130809Smarcel
14138130809Smarcel@table @kbd
14139130809Smarcel@kindex c @r{(SingleKey TUI key)}
14140130809Smarcel@item c
14141130809Smarcelcontinue
14142130809Smarcel
14143130809Smarcel@kindex d @r{(SingleKey TUI key)}
14144130809Smarcel@item d
14145130809Smarceldown
14146130809Smarcel
14147130809Smarcel@kindex f @r{(SingleKey TUI key)}
14148130809Smarcel@item f
14149130809Smarcelfinish
14150130809Smarcel
14151130809Smarcel@kindex n @r{(SingleKey TUI key)}
14152130809Smarcel@item n
14153130809Smarcelnext
14154130809Smarcel
14155130809Smarcel@kindex q @r{(SingleKey TUI key)}
14156130809Smarcel@item q
14157130809Smarcelexit the @emph{SingleKey} mode.
14158130809Smarcel
14159130809Smarcel@kindex r @r{(SingleKey TUI key)}
14160130809Smarcel@item r
14161130809Smarcelrun
14162130809Smarcel
14163130809Smarcel@kindex s @r{(SingleKey TUI key)}
14164130809Smarcel@item s
14165130809Smarcelstep
14166130809Smarcel
14167130809Smarcel@kindex u @r{(SingleKey TUI key)}
14168130809Smarcel@item u
14169130809Smarcelup
14170130809Smarcel
14171130809Smarcel@kindex v @r{(SingleKey TUI key)}
14172130809Smarcel@item v
14173130809Smarcelinfo locals
14174130809Smarcel
14175130809Smarcel@kindex w @r{(SingleKey TUI key)}
14176130809Smarcel@item w
14177130809Smarcelwhere
14178130809Smarcel
14179130809Smarcel@end table
14180130809Smarcel
14181130809SmarcelOther keys temporarily switch to the @value{GDBN} command prompt.
14182130809SmarcelThe key that was pressed is inserted in the editing buffer so that
14183130809Smarcelit is possible to type most @value{GDBN} commands without interaction
14184130809Smarcelwith the TUI @emph{SingleKey} mode.  Once the command is entered the TUI
14185130809Smarcel@emph{SingleKey} mode is restored.  The only way to permanently leave
14186130809Smarcelthis mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
14187130809Smarcel
14188130809Smarcel
1418998948Sobrien@node TUI Commands
1419098948Sobrien@section TUI specific commands
1419198948Sobrien@cindex TUI commands
1419298948Sobrien
1419398948SobrienThe TUI has specific commands to control the text windows.
1419498948SobrienThese commands are always available, that is they do not depend on
1419598948Sobrienthe current terminal mode in which @value{GDBN} runs.  When @value{GDBN}
1419698948Sobrienis in the standard mode, using these commands will automatically switch
1419798948Sobrienin the TUI mode.
1419898948Sobrien
1419998948Sobrien@table @code
14200130809Smarcel@item info win
14201130809Smarcel@kindex info win
14202130809SmarcelList and give the size of all displayed windows.
14203130809Smarcel
1420498948Sobrien@item layout next
1420598948Sobrien@kindex layout next
1420698948SobrienDisplay the next layout.
1420798948Sobrien
1420898948Sobrien@item layout prev
1420998948Sobrien@kindex layout prev
1421098948SobrienDisplay the previous layout.
1421198948Sobrien
1421298948Sobrien@item layout src
1421398948Sobrien@kindex layout src
1421498948SobrienDisplay the source window only.
1421598948Sobrien
1421698948Sobrien@item layout asm
1421798948Sobrien@kindex layout asm
1421898948SobrienDisplay the assembly window only.
1421998948Sobrien
1422098948Sobrien@item layout split
1422198948Sobrien@kindex layout split
1422298948SobrienDisplay the source and assembly window.
1422398948Sobrien
1422498948Sobrien@item layout regs
1422598948Sobrien@kindex layout regs
1422698948SobrienDisplay the register window together with the source or assembly window.
1422798948Sobrien
1422898948Sobrien@item focus next | prev | src | asm | regs | split
1422998948Sobrien@kindex focus
1423098948SobrienSet the focus to the named window.
1423198948SobrienThis command allows to change the active window so that scrolling keys
1423298948Sobriencan be affected to another window.
1423398948Sobrien
1423498948Sobrien@item refresh
1423598948Sobrien@kindex refresh
1423698948SobrienRefresh the screen.  This is similar to using @key{C-L} key.
1423798948Sobrien
14238130809Smarcel@item tui reg float
14239130809Smarcel@kindex tui reg
14240130809SmarcelShow the floating point registers in the register window.
14241130809Smarcel
14242130809Smarcel@item tui reg general
14243130809SmarcelShow the general registers in the register window.
14244130809Smarcel
14245130809Smarcel@item tui reg next
14246130809SmarcelShow the next register group.  The list of register groups as well as
14247130809Smarceltheir order is target specific.  The predefined register groups are the
14248130809Smarcelfollowing: @code{general}, @code{float}, @code{system}, @code{vector},
14249130809Smarcel@code{all}, @code{save}, @code{restore}.
14250130809Smarcel
14251130809Smarcel@item tui reg system
14252130809SmarcelShow the system registers in the register window.
14253130809Smarcel
1425498948Sobrien@item update
1425598948Sobrien@kindex update
1425698948SobrienUpdate the source window and the current execution point.
1425798948Sobrien
1425898948Sobrien@item winheight @var{name} +@var{count}
1425998948Sobrien@itemx winheight @var{name} -@var{count}
1426098948Sobrien@kindex winheight
1426198948SobrienChange the height of the window @var{name} by @var{count}
1426298948Sobrienlines.  Positive counts increase the height, while negative counts
1426398948Sobriendecrease it.
1426498948Sobrien
1426598948Sobrien@end table
1426698948Sobrien
1426798948Sobrien@node TUI Configuration
1426898948Sobrien@section TUI configuration variables
1426998948Sobrien@cindex TUI configuration variables
1427098948Sobrien
1427198948SobrienThe TUI has several configuration variables that control the
1427298948Sobrienappearance of windows on the terminal.
1427398948Sobrien
1427498948Sobrien@table @code
1427598948Sobrien@item set tui border-kind @var{kind}
1427698948Sobrien@kindex set tui border-kind
1427798948SobrienSelect the border appearance for the source, assembly and register windows.
1427898948SobrienThe possible values are the following:
1427998948Sobrien@table @code
1428098948Sobrien@item space
1428198948SobrienUse a space character to draw the border.
1428298948Sobrien
1428398948Sobrien@item ascii
1428498948SobrienUse ascii characters + - and | to draw the border.
1428598948Sobrien
1428698948Sobrien@item acs
1428798948SobrienUse the Alternate Character Set to draw the border.  The border is
1428898948Sobriendrawn using character line graphics if the terminal supports them.
1428998948Sobrien
1429098948Sobrien@end table
1429198948Sobrien
1429298948Sobrien@item set tui active-border-mode @var{mode}
1429398948Sobrien@kindex set tui active-border-mode
1429498948SobrienSelect the attributes to display the border of the active window.
1429598948SobrienThe possible values are @code{normal}, @code{standout}, @code{reverse},
1429698948Sobrien@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
1429798948Sobrien
1429898948Sobrien@item set tui border-mode @var{mode}
1429998948Sobrien@kindex set tui border-mode
1430098948SobrienSelect the attributes to display the border of other windows.
1430198948SobrienThe @var{mode} can be one of the following:
1430298948Sobrien@table @code
1430398948Sobrien@item normal
1430498948SobrienUse normal attributes to display the border.
1430598948Sobrien
1430698948Sobrien@item standout
1430798948SobrienUse standout mode.
1430898948Sobrien
1430998948Sobrien@item reverse
1431098948SobrienUse reverse video mode.
1431198948Sobrien
1431298948Sobrien@item half
1431398948SobrienUse half bright mode.
1431498948Sobrien
1431598948Sobrien@item half-standout
1431698948SobrienUse half bright and standout mode.
1431798948Sobrien
1431898948Sobrien@item bold
1431998948SobrienUse extra bright or bold mode.
1432098948Sobrien
1432198948Sobrien@item bold-standout
1432298948SobrienUse extra bright or bold and standout mode.
1432398948Sobrien
1432498948Sobrien@end table
1432598948Sobrien
1432698948Sobrien@end table
1432798948Sobrien
1432898948Sobrien@node Emacs
1432919370Spst@chapter Using @value{GDBN} under @sc{gnu} Emacs
1433019370Spst
1433119370Spst@cindex Emacs
1433219370Spst@cindex @sc{gnu} Emacs
1433319370SpstA special interface allows you to use @sc{gnu} Emacs to view (and
1433419370Spstedit) the source files for the program you are debugging with
1433519370Spst@value{GDBN}.
1433619370Spst
1433719370SpstTo use this interface, use the command @kbd{M-x gdb} in Emacs.  Give the
1433819370Spstexecutable file you want to debug as an argument.  This command starts
1433919370Spst@value{GDBN} as a subprocess of Emacs, with input and output through a newly
1434019370Spstcreated Emacs buffer.
1434198948Sobrien@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
1434219370Spst
1434319370SpstUsing @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
1434419370Spstthings:
1434519370Spst
1434619370Spst@itemize @bullet
1434719370Spst@item
1434819370SpstAll ``terminal'' input and output goes through the Emacs buffer.
1434919370Spst@end itemize
1435019370Spst
1435119370SpstThis applies both to @value{GDBN} commands and their output, and to the input
1435219370Spstand output done by the program you are debugging.
1435319370Spst
1435419370SpstThis is useful because it means that you can copy the text of previous
1435519370Spstcommands and input them again; you can even use parts of the output
1435619370Spstin this way.
1435719370Spst
1435819370SpstAll the facilities of Emacs' Shell mode are available for interacting
1435919370Spstwith your program.  In particular, you can send signals the usual
1436019370Spstway---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
1436119370Spststop.
1436219370Spst
1436319370Spst@itemize @bullet
1436419370Spst@item
1436519370Spst@value{GDBN} displays source code through Emacs.
1436619370Spst@end itemize
1436719370Spst
1436819370SpstEach time @value{GDBN} displays a stack frame, Emacs automatically finds the
1436919370Spstsource file for that frame and puts an arrow (@samp{=>}) at the
1437019370Spstleft margin of the current line.  Emacs uses a separate buffer for
1437119370Spstsource display, and splits the screen to show both your @value{GDBN} session
1437219370Spstand the source.
1437319370Spst
1437419370SpstExplicit @value{GDBN} @code{list} or search commands still produce output as
1437519370Spstusual, but you probably have no reason to use them from Emacs.
1437619370Spst
14377130809SmarcelIf you specify an absolute file name when prompted for the @kbd{M-x
14378130809Smarcelgdb} argument, then Emacs sets your current working directory to where
14379130809Smarcelyour program resides.  If you only specify the file name, then Emacs
14380130809Smarcelsets your current working directory to to the directory associated
14381130809Smarcelwith the previous buffer.  In this case, @value{GDBN} may find your
14382130809Smarcelprogram by searching your environment's @code{PATH} variable, but on
14383130809Smarcelsome operating systems it might not find the source.  So, although the
14384130809Smarcel@value{GDBN} input and output session proceeds normally, the auxiliary
14385130809Smarcelbuffer does not display the current source and line of execution.
1438619370Spst
14387130809SmarcelThe initial working directory of @value{GDBN} is printed on the top
14388130809Smarcelline of the @value{GDBN} I/O buffer and this serves as a default for
14389130809Smarcelthe commands that specify files for @value{GDBN} to operate
14390130809Smarcelon.  @xref{Files, ,Commands to specify files}.
1439119370Spst
14392130809SmarcelBy default, @kbd{M-x gdb} calls the program called @file{gdb}.  If you
14393130809Smarcelneed to call @value{GDBN} by a different name (for example, if you
14394130809Smarcelkeep several configurations around, with different names) you can
14395130809Smarcelcustomize the Emacs variable @code{gud-gdb-command-name} to run the
14396130809Smarcelone you want.
1439719370Spst
1439819370SpstIn the @value{GDBN} I/O buffer, you can use these special Emacs commands in
1439919370Spstaddition to the standard Shell mode commands:
1440019370Spst
1440119370Spst@table @kbd
1440219370Spst@item C-h m
1440319370SpstDescribe the features of Emacs' @value{GDBN} Mode.
1440419370Spst
14405130809Smarcel@item C-c C-s
1440619370SpstExecute to another source line, like the @value{GDBN} @code{step} command; also
1440719370Spstupdate the display window to show the current file and location.
1440819370Spst
14409130809Smarcel@item C-c C-n
1441019370SpstExecute to next source line in this function, skipping all function
1441119370Spstcalls, like the @value{GDBN} @code{next} command.  Then update the display window
1441219370Spstto show the current file and location.
1441319370Spst
14414130809Smarcel@item C-c C-i
1441519370SpstExecute one instruction, like the @value{GDBN} @code{stepi} command; update
1441619370Spstdisplay window accordingly.
1441719370Spst
1441819370Spst@item C-c C-f
1441919370SpstExecute until exit from the selected stack frame, like the @value{GDBN}
1442019370Spst@code{finish} command.
1442119370Spst
14422130809Smarcel@item C-c C-r
1442319370SpstContinue execution of your program, like the @value{GDBN} @code{continue}
1442419370Spstcommand.
1442519370Spst
14426130809Smarcel@item C-c <
1442719370SpstGo up the number of frames indicated by the numeric argument
1442819370Spst(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
1442919370Spstlike the @value{GDBN} @code{up} command.
1443019370Spst
14431130809Smarcel@item C-c >
1443219370SpstGo down the number of frames indicated by the numeric argument, like the
1443319370Spst@value{GDBN} @code{down} command.
1443419370Spst@end table
1443519370Spst
14436130809SmarcelIn any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
1443719370Spsttells @value{GDBN} to set a breakpoint on the source line point is on.
1443819370Spst
14439130809SmarcelIf you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
14440130809Smarcelshows a backtrace when the @value{GDBN} I/O buffer is current.  Move
14441130809Smarcelpoint to any frame in the stack and type @key{RET} to make it become the
14442130809Smarcelcurrent frame and display the associated source in the source buffer.
14443130809SmarcelAlternatively, click @kbd{Mouse-2} to make the selected frame become the
14444130809Smarcelcurrent one.
14445130809Smarcel
1444619370SpstIf you accidentally delete the source-display buffer, an easy way to get
1444719370Spstit back is to type the command @code{f} in the @value{GDBN} buffer, to
1444819370Spstrequest a frame display; when you run under Emacs, this recreates
1444919370Spstthe source buffer if necessary to show you the context of the current
1445019370Spstframe.
1445119370Spst
1445219370SpstThe source files displayed in Emacs are in ordinary Emacs buffers
1445319370Spstwhich are visiting the source files in the usual way.  You can edit
1445419370Spstthe files with these buffers if you wish; but keep in mind that @value{GDBN}
1445519370Spstcommunicates with Emacs in terms of line numbers.  If you add or
1445619370Spstdelete lines from the text, the line numbers that @value{GDBN} knows cease
1445719370Spstto correspond properly with the code.
1445819370Spst
14459130809SmarcelThe description given here is for GNU Emacs version 21.3 and a more
14460130809Smarceldetailed description of its interaction with @value{GDBN} is given in
14461130809Smarcelthe Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
14462130809Smarcel
1446319370Spst@c The following dropped because Epoch is nonstandard.  Reactivate
1446419370Spst@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
1446519370Spst@ignore
1446619370Spst@kindex Emacs Epoch environment
1446719370Spst@kindex Epoch
1446819370Spst@kindex inspect
1446919370Spst
1447098948SobrienVersion 18 of @sc{gnu} Emacs has a built-in window system
1447119370Spstcalled the @code{epoch}
1447219370Spstenvironment.  Users of this environment can use a new command,
1447319370Spst@code{inspect} which performs identically to @code{print} except that
1447419370Spsteach value is printed in its own window.
1447519370Spst@end ignore
1447619370Spst
1447798948Sobrien
14478130809Smarcel@node GDB/MI
14479130809Smarcel@chapter The @sc{gdb/mi} Interface
14480130809Smarcel
14481130809Smarcel@unnumberedsec Function and Purpose
14482130809Smarcel
14483130809Smarcel@cindex @sc{gdb/mi}, its purpose
14484130809Smarcel@sc{gdb/mi} is a line based machine oriented text interface to @value{GDBN}.  It is
14485130809Smarcelspecifically intended to support the development of systems which use
14486130809Smarcelthe debugger as just one small component of a larger system.
14487130809Smarcel
14488130809SmarcelThis chapter is a specification of the @sc{gdb/mi} interface.  It is written
14489130809Smarcelin the form of a reference manual.
14490130809Smarcel
14491130809SmarcelNote that @sc{gdb/mi} is still under construction, so some of the
14492130809Smarcelfeatures described below are incomplete and subject to change.
14493130809Smarcel
14494130809Smarcel@unnumberedsec Notation and Terminology
14495130809Smarcel
14496130809Smarcel@cindex notational conventions, for @sc{gdb/mi}
14497130809SmarcelThis chapter uses the following notation:
14498130809Smarcel
14499130809Smarcel@itemize @bullet
14500130809Smarcel@item
14501130809Smarcel@code{|} separates two alternatives.
14502130809Smarcel
14503130809Smarcel@item
14504130809Smarcel@code{[ @var{something} ]} indicates that @var{something} is optional:
14505130809Smarcelit may or may not be given.
14506130809Smarcel
14507130809Smarcel@item
14508130809Smarcel@code{( @var{group} )*} means that @var{group} inside the parentheses
14509130809Smarcelmay repeat zero or more times.
14510130809Smarcel
14511130809Smarcel@item
14512130809Smarcel@code{( @var{group} )+} means that @var{group} inside the parentheses
14513130809Smarcelmay repeat one or more times.
14514130809Smarcel
14515130809Smarcel@item
14516130809Smarcel@code{"@var{string}"} means a literal @var{string}.
14517130809Smarcel@end itemize
14518130809Smarcel
14519130809Smarcel@ignore
14520130809Smarcel@heading Dependencies
14521130809Smarcel@end ignore
14522130809Smarcel
14523130809Smarcel@heading Acknowledgments
14524130809Smarcel
14525130809SmarcelIn alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
14526130809SmarcelElena Zannoni.
14527130809Smarcel
14528130809Smarcel@menu
14529130809Smarcel* GDB/MI Command Syntax::
14530130809Smarcel* GDB/MI Compatibility with CLI::
14531130809Smarcel* GDB/MI Output Records::
14532130809Smarcel* GDB/MI Command Description Format::
14533130809Smarcel* GDB/MI Breakpoint Table Commands::
14534130809Smarcel* GDB/MI Data Manipulation::
14535130809Smarcel* GDB/MI Program Control::
14536130809Smarcel* GDB/MI Miscellaneous Commands::
14537130809Smarcel@ignore
14538130809Smarcel* GDB/MI Kod Commands::
14539130809Smarcel* GDB/MI Memory Overlay Commands::
14540130809Smarcel* GDB/MI Signal Handling Commands::
14541130809Smarcel@end ignore
14542130809Smarcel* GDB/MI Stack Manipulation::
14543130809Smarcel* GDB/MI Symbol Query::
14544130809Smarcel* GDB/MI Target Manipulation::
14545130809Smarcel* GDB/MI Thread Commands::
14546130809Smarcel* GDB/MI Tracepoint Commands::
14547130809Smarcel* GDB/MI Variable Objects::
14548130809Smarcel@end menu
14549130809Smarcel
14550130809Smarcel@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14551130809Smarcel@node GDB/MI Command Syntax
14552130809Smarcel@section @sc{gdb/mi} Command Syntax
14553130809Smarcel
14554130809Smarcel@menu
14555130809Smarcel* GDB/MI Input Syntax::
14556130809Smarcel* GDB/MI Output Syntax::
14557130809Smarcel* GDB/MI Simple Examples::
14558130809Smarcel@end menu
14559130809Smarcel
14560130809Smarcel@node GDB/MI Input Syntax
14561130809Smarcel@subsection @sc{gdb/mi} Input Syntax
14562130809Smarcel
14563130809Smarcel@cindex input syntax for @sc{gdb/mi}
14564130809Smarcel@cindex @sc{gdb/mi}, input syntax
14565130809Smarcel@table @code
14566130809Smarcel@item @var{command} @expansion{}
14567130809Smarcel@code{@var{cli-command} | @var{mi-command}}
14568130809Smarcel
14569130809Smarcel@item @var{cli-command} @expansion{}
14570130809Smarcel@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
14571130809Smarcel@var{cli-command} is any existing @value{GDBN} CLI command.
14572130809Smarcel
14573130809Smarcel@item @var{mi-command} @expansion{}
14574130809Smarcel@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
14575130809Smarcel@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
14576130809Smarcel
14577130809Smarcel@item @var{token} @expansion{}
14578130809Smarcel"any sequence of digits"
14579130809Smarcel
14580130809Smarcel@item @var{option} @expansion{}
14581130809Smarcel@code{"-" @var{parameter} [ " " @var{parameter} ]}
14582130809Smarcel
14583130809Smarcel@item @var{parameter} @expansion{}
14584130809Smarcel@code{@var{non-blank-sequence} | @var{c-string}}
14585130809Smarcel
14586130809Smarcel@item @var{operation} @expansion{}
14587130809Smarcel@emph{any of the operations described in this chapter}
14588130809Smarcel
14589130809Smarcel@item @var{non-blank-sequence} @expansion{}
14590130809Smarcel@emph{anything, provided it doesn't contain special characters such as
14591130809Smarcel"-", @var{nl}, """ and of course " "}
14592130809Smarcel
14593130809Smarcel@item @var{c-string} @expansion{}
14594130809Smarcel@code{""" @var{seven-bit-iso-c-string-content} """}
14595130809Smarcel
14596130809Smarcel@item @var{nl} @expansion{}
14597130809Smarcel@code{CR | CR-LF}
14598130809Smarcel@end table
14599130809Smarcel
14600130809Smarcel@noindent
14601130809SmarcelNotes:
14602130809Smarcel
14603130809Smarcel@itemize @bullet
14604130809Smarcel@item
14605130809SmarcelThe CLI commands are still handled by the @sc{mi} interpreter; their
14606130809Smarceloutput is described below.
14607130809Smarcel
14608130809Smarcel@item
14609130809SmarcelThe @code{@var{token}}, when present, is passed back when the command
14610130809Smarcelfinishes.
14611130809Smarcel
14612130809Smarcel@item
14613130809SmarcelSome @sc{mi} commands accept optional arguments as part of the parameter
14614130809Smarcellist.  Each option is identified by a leading @samp{-} (dash) and may be
14615130809Smarcelfollowed by an optional argument parameter.  Options occur first in the
14616130809Smarcelparameter list and can be delimited from normal parameters using
14617130809Smarcel@samp{--} (this is useful when some parameters begin with a dash).
14618130809Smarcel@end itemize
14619130809Smarcel
14620130809SmarcelPragmatics:
14621130809Smarcel
14622130809Smarcel@itemize @bullet
14623130809Smarcel@item
14624130809SmarcelWe want easy access to the existing CLI syntax (for debugging).
14625130809Smarcel
14626130809Smarcel@item
14627130809SmarcelWe want it to be easy to spot a @sc{mi} operation.
14628130809Smarcel@end itemize
14629130809Smarcel
14630130809Smarcel@node GDB/MI Output Syntax
14631130809Smarcel@subsection @sc{gdb/mi} Output Syntax
14632130809Smarcel
14633130809Smarcel@cindex output syntax of @sc{gdb/mi}
14634130809Smarcel@cindex @sc{gdb/mi}, output syntax
14635130809SmarcelThe output from @sc{gdb/mi} consists of zero or more out-of-band records
14636130809Smarcelfollowed, optionally, by a single result record.  This result record
14637130809Smarcelis for the most recent command.  The sequence of output records is
14638130809Smarcelterminated by @samp{(@value{GDBP})}.
14639130809Smarcel
14640130809SmarcelIf an input command was prefixed with a @code{@var{token}} then the
14641130809Smarcelcorresponding output for that command will also be prefixed by that same
14642130809Smarcel@var{token}.
14643130809Smarcel
14644130809Smarcel@table @code
14645130809Smarcel@item @var{output} @expansion{}
14646130809Smarcel@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
14647130809Smarcel
14648130809Smarcel@item @var{result-record} @expansion{}
14649130809Smarcel@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
14650130809Smarcel
14651130809Smarcel@item @var{out-of-band-record} @expansion{}
14652130809Smarcel@code{@var{async-record} | @var{stream-record}}
14653130809Smarcel
14654130809Smarcel@item @var{async-record} @expansion{}
14655130809Smarcel@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
14656130809Smarcel
14657130809Smarcel@item @var{exec-async-output} @expansion{}
14658130809Smarcel@code{[ @var{token} ] "*" @var{async-output}}
14659130809Smarcel
14660130809Smarcel@item @var{status-async-output} @expansion{}
14661130809Smarcel@code{[ @var{token} ] "+" @var{async-output}}
14662130809Smarcel
14663130809Smarcel@item @var{notify-async-output} @expansion{}
14664130809Smarcel@code{[ @var{token} ] "=" @var{async-output}}
14665130809Smarcel
14666130809Smarcel@item @var{async-output} @expansion{}
14667130809Smarcel@code{@var{async-class} ( "," @var{result} )* @var{nl}}
14668130809Smarcel
14669130809Smarcel@item @var{result-class} @expansion{}
14670130809Smarcel@code{"done" | "running" | "connected" | "error" | "exit"}
14671130809Smarcel
14672130809Smarcel@item @var{async-class} @expansion{}
14673130809Smarcel@code{"stopped" | @var{others}} (where @var{others} will be added
14674130809Smarceldepending on the needs---this is still in development).
14675130809Smarcel
14676130809Smarcel@item @var{result} @expansion{}
14677130809Smarcel@code{ @var{variable} "=" @var{value}}
14678130809Smarcel
14679130809Smarcel@item @var{variable} @expansion{}
14680130809Smarcel@code{ @var{string} }
14681130809Smarcel
14682130809Smarcel@item @var{value} @expansion{}
14683130809Smarcel@code{ @var{const} | @var{tuple} | @var{list} }
14684130809Smarcel
14685130809Smarcel@item @var{const} @expansion{}
14686130809Smarcel@code{@var{c-string}}
14687130809Smarcel
14688130809Smarcel@item @var{tuple} @expansion{}
14689130809Smarcel@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
14690130809Smarcel
14691130809Smarcel@item @var{list} @expansion{}
14692130809Smarcel@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
14693130809Smarcel@var{result} ( "," @var{result} )* "]" }
14694130809Smarcel
14695130809Smarcel@item @var{stream-record} @expansion{}
14696130809Smarcel@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
14697130809Smarcel
14698130809Smarcel@item @var{console-stream-output} @expansion{}
14699130809Smarcel@code{"~" @var{c-string}}
14700130809Smarcel
14701130809Smarcel@item @var{target-stream-output} @expansion{}
14702130809Smarcel@code{"@@" @var{c-string}}
14703130809Smarcel
14704130809Smarcel@item @var{log-stream-output} @expansion{}
14705130809Smarcel@code{"&" @var{c-string}}
14706130809Smarcel
14707130809Smarcel@item @var{nl} @expansion{}
14708130809Smarcel@code{CR | CR-LF}
14709130809Smarcel
14710130809Smarcel@item @var{token} @expansion{}
14711130809Smarcel@emph{any sequence of digits}.
14712130809Smarcel@end table
14713130809Smarcel
14714130809Smarcel@noindent
14715130809SmarcelNotes:
14716130809Smarcel
14717130809Smarcel@itemize @bullet
14718130809Smarcel@item
14719130809SmarcelAll output sequences end in a single line containing a period.
14720130809Smarcel
14721130809Smarcel@item
14722130809SmarcelThe @code{@var{token}} is from the corresponding request.  If an execution
14723130809Smarcelcommand is interrupted by the @samp{-exec-interrupt} command, the
14724130809Smarcel@var{token} associated with the @samp{*stopped} message is the one of the
14725130809Smarceloriginal execution command, not the one of the interrupt command.
14726130809Smarcel
14727130809Smarcel@item
14728130809Smarcel@cindex status output in @sc{gdb/mi}
14729130809Smarcel@var{status-async-output} contains on-going status information about the
14730130809Smarcelprogress of a slow operation.  It can be discarded.  All status output is
14731130809Smarcelprefixed by @samp{+}.
14732130809Smarcel
14733130809Smarcel@item
14734130809Smarcel@cindex async output in @sc{gdb/mi}
14735130809Smarcel@var{exec-async-output} contains asynchronous state change on the target
14736130809Smarcel(stopped, started, disappeared).  All async output is prefixed by
14737130809Smarcel@samp{*}.
14738130809Smarcel
14739130809Smarcel@item
14740130809Smarcel@cindex notify output in @sc{gdb/mi}
14741130809Smarcel@var{notify-async-output} contains supplementary information that the
14742130809Smarcelclient should handle (e.g., a new breakpoint information).  All notify
14743130809Smarceloutput is prefixed by @samp{=}.
14744130809Smarcel
14745130809Smarcel@item
14746130809Smarcel@cindex console output in @sc{gdb/mi}
14747130809Smarcel@var{console-stream-output} is output that should be displayed as is in the
14748130809Smarcelconsole.  It is the textual response to a CLI command.  All the console
14749130809Smarceloutput is prefixed by @samp{~}.
14750130809Smarcel
14751130809Smarcel@item
14752130809Smarcel@cindex target output in @sc{gdb/mi}
14753130809Smarcel@var{target-stream-output} is the output produced by the target program.
14754130809SmarcelAll the target output is prefixed by @samp{@@}.
14755130809Smarcel
14756130809Smarcel@item
14757130809Smarcel@cindex log output in @sc{gdb/mi}
14758130809Smarcel@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
14759130809Smarcelinstance messages that should be displayed as part of an error log.  All
14760130809Smarcelthe log output is prefixed by @samp{&}.
14761130809Smarcel
14762130809Smarcel@item
14763130809Smarcel@cindex list output in @sc{gdb/mi}
14764130809SmarcelNew @sc{gdb/mi} commands should only output @var{lists} containing
14765130809Smarcel@var{values}.
14766130809Smarcel
14767130809Smarcel
14768130809Smarcel@end itemize
14769130809Smarcel
14770130809Smarcel@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
14771130809Smarceldetails about the various output records.
14772130809Smarcel
14773130809Smarcel@node GDB/MI Simple Examples
14774130809Smarcel@subsection Simple Examples of @sc{gdb/mi} Interaction
14775130809Smarcel@cindex @sc{gdb/mi}, simple examples
14776130809Smarcel
14777130809SmarcelThis subsection presents several simple examples of interaction using
14778130809Smarcelthe @sc{gdb/mi} interface.  In these examples, @samp{->} means that the
14779130809Smarcelfollowing line is passed to @sc{gdb/mi} as input, while @samp{<-} means
14780130809Smarcelthe output received from @sc{gdb/mi}.
14781130809Smarcel
14782130809Smarcel@subsubheading Target Stop
14783130809Smarcel@c Ummm... There is no "-stop" command. This assumes async, no?
14784130809SmarcelHere's an example of stopping the inferior process:
14785130809Smarcel
14786130809Smarcel@smallexample
14787130809Smarcel-> -stop
14788130809Smarcel<- (@value{GDBP})
14789130809Smarcel@end smallexample
14790130809Smarcel
14791130809Smarcel@noindent
14792130809Smarceland later:
14793130809Smarcel
14794130809Smarcel@smallexample
14795130809Smarcel<- *stop,reason="stop",address="0x123",source="a.c:123"
14796130809Smarcel<- (@value{GDBP})
14797130809Smarcel@end smallexample
14798130809Smarcel
14799130809Smarcel@subsubheading Simple CLI Command
14800130809Smarcel
14801130809SmarcelHere's an example of a simple CLI command being passed through
14802130809Smarcel@sc{gdb/mi} and on to the CLI.
14803130809Smarcel
14804130809Smarcel@smallexample
14805130809Smarcel-> print 1+2
14806130809Smarcel<- &"print 1+2\n"
14807130809Smarcel<- ~"$1 = 3\n"
14808130809Smarcel<- ^done
14809130809Smarcel<- (@value{GDBP})
14810130809Smarcel@end smallexample
14811130809Smarcel
14812130809Smarcel@subsubheading Command With Side Effects
14813130809Smarcel
14814130809Smarcel@smallexample
14815130809Smarcel-> -symbol-file xyz.exe
14816130809Smarcel<- *breakpoint,nr="3",address="0x123",source="a.c:123"
14817130809Smarcel<- (@value{GDBP})
14818130809Smarcel@end smallexample
14819130809Smarcel
14820130809Smarcel@subsubheading A Bad Command
14821130809Smarcel
14822130809SmarcelHere's what happens if you pass a non-existent command:
14823130809Smarcel
14824130809Smarcel@smallexample
14825130809Smarcel-> -rubbish
14826130809Smarcel<- ^error,msg="Undefined MI command: rubbish"
14827130809Smarcel<- (@value{GDBP})
14828130809Smarcel@end smallexample
14829130809Smarcel
14830130809Smarcel@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14831130809Smarcel@node GDB/MI Compatibility with CLI
14832130809Smarcel@section @sc{gdb/mi} Compatibility with CLI
14833130809Smarcel
14834130809Smarcel@cindex compatibility, @sc{gdb/mi} and CLI
14835130809Smarcel@cindex @sc{gdb/mi}, compatibility with CLI
14836130809SmarcelTo help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
14837130809Smarcelaccepts existing CLI commands.  As specified by the syntax, such
14838130809Smarcelcommands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
14839130809Smarcelrespond.
14840130809Smarcel
14841130809SmarcelThis mechanism is provided as an aid to developers of @sc{gdb/mi}
14842130809Smarcelclients and not as a reliable interface into the CLI.  Since the command
14843130809Smarcelis being interpreteted in an environment that assumes @sc{gdb/mi}
14844130809Smarcelbehaviour, the exact output of such commands is likely to end up being
14845130809Smarcelan un-supported hybrid of @sc{gdb/mi} and CLI output.
14846130809Smarcel
14847130809Smarcel@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14848130809Smarcel@node GDB/MI Output Records
14849130809Smarcel@section @sc{gdb/mi} Output Records
14850130809Smarcel
14851130809Smarcel@menu
14852130809Smarcel* GDB/MI Result Records::
14853130809Smarcel* GDB/MI Stream Records::
14854130809Smarcel* GDB/MI Out-of-band Records::
14855130809Smarcel@end menu
14856130809Smarcel
14857130809Smarcel@node GDB/MI Result Records
14858130809Smarcel@subsection @sc{gdb/mi} Result Records
14859130809Smarcel
14860130809Smarcel@cindex result records in @sc{gdb/mi}
14861130809Smarcel@cindex @sc{gdb/mi}, result records
14862130809SmarcelIn addition to a number of out-of-band notifications, the response to a
14863130809Smarcel@sc{gdb/mi} command includes one of the following result indications:
14864130809Smarcel
14865130809Smarcel@table @code
14866130809Smarcel@findex ^done
14867130809Smarcel@item "^done" [ "," @var{results} ]
14868130809SmarcelThe synchronous operation was successful, @code{@var{results}} are the return
14869130809Smarcelvalues.
14870130809Smarcel
14871130809Smarcel@item "^running"
14872130809Smarcel@findex ^running
14873130809Smarcel@c Is this one correct?  Should it be an out-of-band notification?
14874130809SmarcelThe asynchronous operation was successfully started.  The target is
14875130809Smarcelrunning.
14876130809Smarcel
14877130809Smarcel@item "^error" "," @var{c-string}
14878130809Smarcel@findex ^error
14879130809SmarcelThe operation failed.  The @code{@var{c-string}} contains the corresponding
14880130809Smarcelerror message.
14881130809Smarcel@end table
14882130809Smarcel
14883130809Smarcel@node GDB/MI Stream Records
14884130809Smarcel@subsection @sc{gdb/mi} Stream Records
14885130809Smarcel
14886130809Smarcel@cindex @sc{gdb/mi}, stream records
14887130809Smarcel@cindex stream records in @sc{gdb/mi}
14888130809Smarcel@value{GDBN} internally maintains a number of output streams: the console, the
14889130809Smarceltarget, and the log.  The output intended for each of these streams is
14890130809Smarcelfunneled through the @sc{gdb/mi} interface using @dfn{stream records}.
14891130809Smarcel
14892130809SmarcelEach stream record begins with a unique @dfn{prefix character} which
14893130809Smarcelidentifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
14894130809SmarcelSyntax}).  In addition to the prefix, each stream record contains a
14895130809Smarcel@code{@var{string-output}}.  This is either raw text (with an implicit new
14896130809Smarcelline) or a quoted C string (which does not contain an implicit newline).
14897130809Smarcel
14898130809Smarcel@table @code
14899130809Smarcel@item "~" @var{string-output}
14900130809SmarcelThe console output stream contains text that should be displayed in the
14901130809SmarcelCLI console window.  It contains the textual responses to CLI commands.
14902130809Smarcel
14903130809Smarcel@item "@@" @var{string-output}
14904130809SmarcelThe target output stream contains any textual output from the running
14905130809Smarceltarget.
14906130809Smarcel
14907130809Smarcel@item "&" @var{string-output}
14908130809SmarcelThe log stream contains debugging messages being produced by @value{GDBN}'s
14909130809Smarcelinternals.
14910130809Smarcel@end table
14911130809Smarcel
14912130809Smarcel@node GDB/MI Out-of-band Records
14913130809Smarcel@subsection @sc{gdb/mi} Out-of-band Records
14914130809Smarcel
14915130809Smarcel@cindex out-of-band records in @sc{gdb/mi}
14916130809Smarcel@cindex @sc{gdb/mi}, out-of-band records
14917130809Smarcel@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
14918130809Smarceladditional changes that have occurred.  Those changes can either be a
14919130809Smarcelconsequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
14920130809Smarceltarget activity (e.g., target stopped).
14921130809Smarcel
14922130809SmarcelThe following is a preliminary list of possible out-of-band records.
14923130809Smarcel
14924130809Smarcel@table @code
14925130809Smarcel@item "*" "stop"
14926130809Smarcel@end table
14927130809Smarcel
14928130809Smarcel
14929130809Smarcel@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14930130809Smarcel@node GDB/MI Command Description Format
14931130809Smarcel@section @sc{gdb/mi} Command Description Format
14932130809Smarcel
14933130809SmarcelThe remaining sections describe blocks of commands.  Each block of
14934130809Smarcelcommands is laid out in a fashion similar to this section.
14935130809Smarcel
14936130809SmarcelNote the the line breaks shown in the examples are here only for
14937130809Smarcelreadability.  They don't appear in the real output.
14938130809SmarcelAlso note that the commands with a non-available example (N.A.@:) are
14939130809Smarcelnot yet implemented.
14940130809Smarcel
14941130809Smarcel@subheading Motivation
14942130809Smarcel
14943130809SmarcelThe motivation for this collection of commands.
14944130809Smarcel
14945130809Smarcel@subheading Introduction
14946130809Smarcel
14947130809SmarcelA brief introduction to this collection of commands as a whole.
14948130809Smarcel
14949130809Smarcel@subheading Commands
14950130809Smarcel
14951130809SmarcelFor each command in the block, the following is described:
14952130809Smarcel
14953130809Smarcel@subsubheading Synopsis
14954130809Smarcel
14955130809Smarcel@smallexample
14956130809Smarcel -command @var{args}@dots{}
14957130809Smarcel@end smallexample
14958130809Smarcel
14959130809Smarcel@subsubheading @value{GDBN} Command
14960130809Smarcel
14961130809SmarcelThe corresponding @value{GDBN} CLI command.
14962130809Smarcel
14963130809Smarcel@subsubheading Result
14964130809Smarcel
14965130809Smarcel@subsubheading Out-of-band
14966130809Smarcel
14967130809Smarcel@subsubheading Notes
14968130809Smarcel
14969130809Smarcel@subsubheading Example
14970130809Smarcel
14971130809Smarcel
14972130809Smarcel@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14973130809Smarcel@node GDB/MI Breakpoint Table Commands
14974130809Smarcel@section @sc{gdb/mi} Breakpoint table commands
14975130809Smarcel
14976130809Smarcel@cindex breakpoint commands for @sc{gdb/mi}
14977130809Smarcel@cindex @sc{gdb/mi}, breakpoint commands
14978130809SmarcelThis section documents @sc{gdb/mi} commands for manipulating
14979130809Smarcelbreakpoints.
14980130809Smarcel
14981130809Smarcel@subheading The @code{-break-after} Command
14982130809Smarcel@findex -break-after
14983130809Smarcel
14984130809Smarcel@subsubheading Synopsis
14985130809Smarcel
14986130809Smarcel@smallexample
14987130809Smarcel -break-after @var{number} @var{count}
14988130809Smarcel@end smallexample
14989130809Smarcel
14990130809SmarcelThe breakpoint number @var{number} is not in effect until it has been
14991130809Smarcelhit @var{count} times.  To see how this is reflected in the output of
14992130809Smarcelthe @samp{-break-list} command, see the description of the
14993130809Smarcel@samp{-break-list} command below.
14994130809Smarcel
14995130809Smarcel@subsubheading @value{GDBN} Command
14996130809Smarcel
14997130809SmarcelThe corresponding @value{GDBN} command is @samp{ignore}.
14998130809Smarcel
14999130809Smarcel@subsubheading Example
15000130809Smarcel
15001130809Smarcel@smallexample
15002130809Smarcel(@value{GDBP})
15003130809Smarcel-break-insert main
15004130809Smarcel^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
15005130809Smarcel(@value{GDBP})
15006130809Smarcel-break-after 1 3
15007130809Smarcel~
15008130809Smarcel^done
15009130809Smarcel(@value{GDBP})
15010130809Smarcel-break-list
15011130809Smarcel^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15012130809Smarcelhdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15013130809Smarcel@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15014130809Smarcel@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15015130809Smarcel@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15016130809Smarcel@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15017130809Smarcel@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15018130809Smarcelbody=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15019130809Smarceladdr="0x000100d0",func="main",file="hello.c",line="5",times="0",
15020130809Smarcelignore="3"@}]@}
15021130809Smarcel(@value{GDBP})
15022130809Smarcel@end smallexample
15023130809Smarcel
15024130809Smarcel@ignore
15025130809Smarcel@subheading The @code{-break-catch} Command
15026130809Smarcel@findex -break-catch
15027130809Smarcel
15028130809Smarcel@subheading The @code{-break-commands} Command
15029130809Smarcel@findex -break-commands
15030130809Smarcel@end ignore
15031130809Smarcel
15032130809Smarcel
15033130809Smarcel@subheading The @code{-break-condition} Command
15034130809Smarcel@findex -break-condition
15035130809Smarcel
15036130809Smarcel@subsubheading Synopsis
15037130809Smarcel
15038130809Smarcel@smallexample
15039130809Smarcel -break-condition @var{number} @var{expr}
15040130809Smarcel@end smallexample
15041130809Smarcel
15042130809SmarcelBreakpoint @var{number} will stop the program only if the condition in
15043130809Smarcel@var{expr} is true.  The condition becomes part of the
15044130809Smarcel@samp{-break-list} output (see the description of the @samp{-break-list}
15045130809Smarcelcommand below).
15046130809Smarcel
15047130809Smarcel@subsubheading @value{GDBN} Command
15048130809Smarcel
15049130809SmarcelThe corresponding @value{GDBN} command is @samp{condition}.
15050130809Smarcel
15051130809Smarcel@subsubheading Example
15052130809Smarcel
15053130809Smarcel@smallexample
15054130809Smarcel(@value{GDBP})
15055130809Smarcel-break-condition 1 1
15056130809Smarcel^done
15057130809Smarcel(@value{GDBP})
15058130809Smarcel-break-list
15059130809Smarcel^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15060130809Smarcelhdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15061130809Smarcel@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15062130809Smarcel@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15063130809Smarcel@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15064130809Smarcel@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15065130809Smarcel@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15066130809Smarcelbody=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15067130809Smarceladdr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
15068130809Smarceltimes="0",ignore="3"@}]@}
15069130809Smarcel(@value{GDBP})
15070130809Smarcel@end smallexample
15071130809Smarcel
15072130809Smarcel@subheading The @code{-break-delete} Command
15073130809Smarcel@findex -break-delete
15074130809Smarcel
15075130809Smarcel@subsubheading Synopsis
15076130809Smarcel
15077130809Smarcel@smallexample
15078130809Smarcel -break-delete ( @var{breakpoint} )+
15079130809Smarcel@end smallexample
15080130809Smarcel
15081130809SmarcelDelete the breakpoint(s) whose number(s) are specified in the argument
15082130809Smarcellist.  This is obviously reflected in the breakpoint list.
15083130809Smarcel
15084130809Smarcel@subsubheading @value{GDBN} command
15085130809Smarcel
15086130809SmarcelThe corresponding @value{GDBN} command is @samp{delete}.
15087130809Smarcel
15088130809Smarcel@subsubheading Example
15089130809Smarcel
15090130809Smarcel@smallexample
15091130809Smarcel(@value{GDBP})
15092130809Smarcel-break-delete 1
15093130809Smarcel^done
15094130809Smarcel(@value{GDBP})
15095130809Smarcel-break-list
15096130809Smarcel^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
15097130809Smarcelhdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15098130809Smarcel@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15099130809Smarcel@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15100130809Smarcel@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15101130809Smarcel@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15102130809Smarcel@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15103130809Smarcelbody=[]@}
15104130809Smarcel(@value{GDBP})
15105130809Smarcel@end smallexample
15106130809Smarcel
15107130809Smarcel@subheading The @code{-break-disable} Command
15108130809Smarcel@findex -break-disable
15109130809Smarcel
15110130809Smarcel@subsubheading Synopsis
15111130809Smarcel
15112130809Smarcel@smallexample
15113130809Smarcel -break-disable ( @var{breakpoint} )+
15114130809Smarcel@end smallexample
15115130809Smarcel
15116130809SmarcelDisable the named @var{breakpoint}(s).  The field @samp{enabled} in the
15117130809Smarcelbreak list is now set to @samp{n} for the named @var{breakpoint}(s).
15118130809Smarcel
15119130809Smarcel@subsubheading @value{GDBN} Command
15120130809Smarcel
15121130809SmarcelThe corresponding @value{GDBN} command is @samp{disable}.
15122130809Smarcel
15123130809Smarcel@subsubheading Example
15124130809Smarcel
15125130809Smarcel@smallexample
15126130809Smarcel(@value{GDBP})
15127130809Smarcel-break-disable 2
15128130809Smarcel^done
15129130809Smarcel(@value{GDBP})
15130130809Smarcel-break-list
15131130809Smarcel^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15132130809Smarcelhdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15133130809Smarcel@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15134130809Smarcel@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15135130809Smarcel@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15136130809Smarcel@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15137130809Smarcel@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15138130809Smarcelbody=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
15139130809Smarceladdr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
15140130809Smarcel(@value{GDBP})
15141130809Smarcel@end smallexample
15142130809Smarcel
15143130809Smarcel@subheading The @code{-break-enable} Command
15144130809Smarcel@findex -break-enable
15145130809Smarcel
15146130809Smarcel@subsubheading Synopsis
15147130809Smarcel
15148130809Smarcel@smallexample
15149130809Smarcel -break-enable ( @var{breakpoint} )+
15150130809Smarcel@end smallexample
15151130809Smarcel
15152130809SmarcelEnable (previously disabled) @var{breakpoint}(s).
15153130809Smarcel
15154130809Smarcel@subsubheading @value{GDBN} Command
15155130809Smarcel
15156130809SmarcelThe corresponding @value{GDBN} command is @samp{enable}.
15157130809Smarcel
15158130809Smarcel@subsubheading Example
15159130809Smarcel
15160130809Smarcel@smallexample
15161130809Smarcel(@value{GDBP})
15162130809Smarcel-break-enable 2
15163130809Smarcel^done
15164130809Smarcel(@value{GDBP})
15165130809Smarcel-break-list
15166130809Smarcel^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15167130809Smarcelhdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15168130809Smarcel@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15169130809Smarcel@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15170130809Smarcel@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15171130809Smarcel@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15172130809Smarcel@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15173130809Smarcelbody=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
15174130809Smarceladdr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
15175130809Smarcel(@value{GDBP})
15176130809Smarcel@end smallexample
15177130809Smarcel
15178130809Smarcel@subheading The @code{-break-info} Command
15179130809Smarcel@findex -break-info
15180130809Smarcel
15181130809Smarcel@subsubheading Synopsis
15182130809Smarcel
15183130809Smarcel@smallexample
15184130809Smarcel -break-info @var{breakpoint}
15185130809Smarcel@end smallexample
15186130809Smarcel
15187130809Smarcel@c REDUNDANT???
15188130809SmarcelGet information about a single breakpoint.
15189130809Smarcel
15190130809Smarcel@subsubheading @value{GDBN} command
15191130809Smarcel
15192130809SmarcelThe corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
15193130809Smarcel
15194130809Smarcel@subsubheading Example
15195130809SmarcelN.A.
15196130809Smarcel
15197130809Smarcel@subheading The @code{-break-insert} Command
15198130809Smarcel@findex -break-insert
15199130809Smarcel
15200130809Smarcel@subsubheading Synopsis
15201130809Smarcel
15202130809Smarcel@smallexample
15203130809Smarcel -break-insert [ -t ] [ -h ] [ -r ]
15204130809Smarcel    [ -c @var{condition} ] [ -i @var{ignore-count} ]
15205130809Smarcel    [ -p @var{thread} ] [ @var{line} | @var{addr} ]
15206130809Smarcel@end smallexample
15207130809Smarcel
15208130809Smarcel@noindent
15209130809SmarcelIf specified, @var{line}, can be one of:
15210130809Smarcel
15211130809Smarcel@itemize @bullet
15212130809Smarcel@item function
15213130809Smarcel@c @item +offset
15214130809Smarcel@c @item -offset
15215130809Smarcel@c @item linenum
15216130809Smarcel@item filename:linenum
15217130809Smarcel@item filename:function
15218130809Smarcel@item *address
15219130809Smarcel@end itemize
15220130809Smarcel
15221130809SmarcelThe possible optional parameters of this command are:
15222130809Smarcel
15223130809Smarcel@table @samp
15224130809Smarcel@item -t
15225130809SmarcelInsert a tempoary breakpoint.
15226130809Smarcel@item -h
15227130809SmarcelInsert a hardware breakpoint.
15228130809Smarcel@item -c @var{condition}
15229130809SmarcelMake the breakpoint conditional on @var{condition}.
15230130809Smarcel@item -i @var{ignore-count}
15231130809SmarcelInitialize the @var{ignore-count}.
15232130809Smarcel@item -r
15233130809SmarcelInsert a regular breakpoint in all the functions whose names match the
15234130809Smarcelgiven regular expression.  Other flags are not applicable to regular
15235130809Smarcelexpresson.
15236130809Smarcel@end table
15237130809Smarcel
15238130809Smarcel@subsubheading Result
15239130809Smarcel
15240130809SmarcelThe result is in the form:
15241130809Smarcel
15242130809Smarcel@smallexample
15243130809Smarcel ^done,bkptno="@var{number}",func="@var{funcname}",
15244130809Smarcel  file="@var{filename}",line="@var{lineno}"
15245130809Smarcel@end smallexample
15246130809Smarcel
15247130809Smarcel@noindent
15248130809Smarcelwhere @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
15249130809Smarcelis the name of the function where the breakpoint was inserted,
15250130809Smarcel@var{filename} is the name of the source file which contains this
15251130809Smarcelfunction, and @var{lineno} is the source line number within that file.
15252130809Smarcel
15253130809SmarcelNote: this format is open to change.
15254130809Smarcel@c An out-of-band breakpoint instead of part of the result?
15255130809Smarcel
15256130809Smarcel@subsubheading @value{GDBN} Command
15257130809Smarcel
15258130809SmarcelThe corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
15259130809Smarcel@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
15260130809Smarcel
15261130809Smarcel@subsubheading Example
15262130809Smarcel
15263130809Smarcel@smallexample
15264130809Smarcel(@value{GDBP})
15265130809Smarcel-break-insert main
15266130809Smarcel^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
15267130809Smarcel(@value{GDBP})
15268130809Smarcel-break-insert -t foo
15269130809Smarcel^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
15270130809Smarcel(@value{GDBP})
15271130809Smarcel-break-list
15272130809Smarcel^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15273130809Smarcelhdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15274130809Smarcel@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15275130809Smarcel@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15276130809Smarcel@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15277130809Smarcel@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15278130809Smarcel@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15279130809Smarcelbody=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15280130809Smarceladdr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
15281130809Smarcelbkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
15282130809Smarceladdr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
15283130809Smarcel(@value{GDBP})
15284130809Smarcel-break-insert -r foo.*
15285130809Smarcel~int foo(int, int);
15286130809Smarcel^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
15287130809Smarcel(@value{GDBP})
15288130809Smarcel@end smallexample
15289130809Smarcel
15290130809Smarcel@subheading The @code{-break-list} Command
15291130809Smarcel@findex -break-list
15292130809Smarcel
15293130809Smarcel@subsubheading Synopsis
15294130809Smarcel
15295130809Smarcel@smallexample
15296130809Smarcel -break-list
15297130809Smarcel@end smallexample
15298130809Smarcel
15299130809SmarcelDisplays the list of inserted breakpoints, showing the following fields:
15300130809Smarcel
15301130809Smarcel@table @samp
15302130809Smarcel@item Number
15303130809Smarcelnumber of the breakpoint
15304130809Smarcel@item Type
15305130809Smarceltype of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
15306130809Smarcel@item Disposition
15307130809Smarcelshould the breakpoint be deleted or disabled when it is hit: @samp{keep}
15308130809Smarcelor @samp{nokeep}
15309130809Smarcel@item Enabled
15310130809Smarcelis the breakpoint enabled or no: @samp{y} or @samp{n}
15311130809Smarcel@item Address
15312130809Smarcelmemory location at which the breakpoint is set
15313130809Smarcel@item What
15314130809Smarcellogical location of the breakpoint, expressed by function name, file
15315130809Smarcelname, line number
15316130809Smarcel@item Times
15317130809Smarcelnumber of times the breakpoint has been hit
15318130809Smarcel@end table
15319130809Smarcel
15320130809SmarcelIf there are no breakpoints or watchpoints, the @code{BreakpointTable}
15321130809Smarcel@code{body} field is an empty list.
15322130809Smarcel
15323130809Smarcel@subsubheading @value{GDBN} Command
15324130809Smarcel
15325130809SmarcelThe corresponding @value{GDBN} command is @samp{info break}.
15326130809Smarcel
15327130809Smarcel@subsubheading Example
15328130809Smarcel
15329130809Smarcel@smallexample
15330130809Smarcel(@value{GDBP})
15331130809Smarcel-break-list
15332130809Smarcel^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15333130809Smarcelhdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15334130809Smarcel@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15335130809Smarcel@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15336130809Smarcel@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15337130809Smarcel@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15338130809Smarcel@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15339130809Smarcelbody=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15340130809Smarceladdr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
15341130809Smarcelbkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
15342130809Smarceladdr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
15343130809Smarcel(@value{GDBP})
15344130809Smarcel@end smallexample
15345130809Smarcel
15346130809SmarcelHere's an example of the result when there are no breakpoints:
15347130809Smarcel
15348130809Smarcel@smallexample
15349130809Smarcel(@value{GDBP})
15350130809Smarcel-break-list
15351130809Smarcel^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
15352130809Smarcelhdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15353130809Smarcel@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15354130809Smarcel@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15355130809Smarcel@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15356130809Smarcel@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15357130809Smarcel@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15358130809Smarcelbody=[]@}
15359130809Smarcel(@value{GDBP})
15360130809Smarcel@end smallexample
15361130809Smarcel
15362130809Smarcel@subheading The @code{-break-watch} Command
15363130809Smarcel@findex -break-watch
15364130809Smarcel
15365130809Smarcel@subsubheading Synopsis
15366130809Smarcel
15367130809Smarcel@smallexample
15368130809Smarcel -break-watch [ -a | -r ]
15369130809Smarcel@end smallexample
15370130809Smarcel
15371130809SmarcelCreate a watchpoint.  With the @samp{-a} option it will create an
15372130809Smarcel@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
15373130809Smarcelread from or on a write to the memory location.  With the @samp{-r}
15374130809Smarceloption, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
15375130809Smarceltrigger only when the memory location is accessed for reading.  Without
15376130809Smarceleither of the options, the watchpoint created is a regular watchpoint,
15377130809Smarceli.e. it will trigger when the memory location is accessed for writing.
15378130809Smarcel@xref{Set Watchpoints, , Setting watchpoints}.
15379130809Smarcel
15380130809SmarcelNote that @samp{-break-list} will report a single list of watchpoints and
15381130809Smarcelbreakpoints inserted.
15382130809Smarcel
15383130809Smarcel@subsubheading @value{GDBN} Command
15384130809Smarcel
15385130809SmarcelThe corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
15386130809Smarcel@samp{rwatch}.
15387130809Smarcel
15388130809Smarcel@subsubheading Example
15389130809Smarcel
15390130809SmarcelSetting a watchpoint on a variable in the @code{main} function:
15391130809Smarcel
15392130809Smarcel@smallexample
15393130809Smarcel(@value{GDBP})
15394130809Smarcel-break-watch x
15395130809Smarcel^done,wpt=@{number="2",exp="x"@}
15396130809Smarcel(@value{GDBP})
15397130809Smarcel-exec-continue
15398130809Smarcel^running
15399130809Smarcel^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
15400130809Smarcelvalue=@{old="-268439212",new="55"@},
15401130809Smarcelframe=@{func="main",args=[],file="recursive2.c",line="5"@}
15402130809Smarcel(@value{GDBP})
15403130809Smarcel@end smallexample
15404130809Smarcel
15405130809SmarcelSetting a watchpoint on a variable local to a function.  @value{GDBN} will stop
15406130809Smarcelthe program execution twice: first for the variable changing value, then
15407130809Smarcelfor the watchpoint going out of scope.
15408130809Smarcel
15409130809Smarcel@smallexample
15410130809Smarcel(@value{GDBP})
15411130809Smarcel-break-watch C
15412130809Smarcel^done,wpt=@{number="5",exp="C"@}
15413130809Smarcel(@value{GDBP})
15414130809Smarcel-exec-continue
15415130809Smarcel^running
15416130809Smarcel^done,reason="watchpoint-trigger",
15417130809Smarcelwpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
15418130809Smarcelframe=@{func="callee4",args=[],
15419130809Smarcelfile="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
15420130809Smarcel(@value{GDBP})
15421130809Smarcel-exec-continue
15422130809Smarcel^running
15423130809Smarcel^done,reason="watchpoint-scope",wpnum="5",
15424130809Smarcelframe=@{func="callee3",args=[@{name="strarg",
15425130809Smarcelvalue="0x11940 \"A string argument.\""@}],
15426130809Smarcelfile="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
15427130809Smarcel(@value{GDBP})
15428130809Smarcel@end smallexample
15429130809Smarcel
15430130809SmarcelListing breakpoints and watchpoints, at different points in the program
15431130809Smarcelexecution.  Note that once the watchpoint goes out of scope, it is
15432130809Smarceldeleted.
15433130809Smarcel
15434130809Smarcel@smallexample
15435130809Smarcel(@value{GDBP})
15436130809Smarcel-break-watch C
15437130809Smarcel^done,wpt=@{number="2",exp="C"@}
15438130809Smarcel(@value{GDBP})
15439130809Smarcel-break-list
15440130809Smarcel^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15441130809Smarcelhdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15442130809Smarcel@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15443130809Smarcel@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15444130809Smarcel@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15445130809Smarcel@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15446130809Smarcel@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15447130809Smarcelbody=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15448130809Smarceladdr="0x00010734",func="callee4",
15449130809Smarcelfile="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
15450130809Smarcelbkpt=@{number="2",type="watchpoint",disp="keep",
15451130809Smarcelenabled="y",addr="",what="C",times="0"@}]@}
15452130809Smarcel(@value{GDBP})
15453130809Smarcel-exec-continue
15454130809Smarcel^running
15455130809Smarcel^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
15456130809Smarcelvalue=@{old="-276895068",new="3"@},
15457130809Smarcelframe=@{func="callee4",args=[],
15458130809Smarcelfile="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
15459130809Smarcel(@value{GDBP})
15460130809Smarcel-break-list
15461130809Smarcel^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15462130809Smarcelhdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15463130809Smarcel@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15464130809Smarcel@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15465130809Smarcel@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15466130809Smarcel@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15467130809Smarcel@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15468130809Smarcelbody=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15469130809Smarceladdr="0x00010734",func="callee4",
15470130809Smarcelfile="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
15471130809Smarcelbkpt=@{number="2",type="watchpoint",disp="keep",
15472130809Smarcelenabled="y",addr="",what="C",times="-5"@}]@}
15473130809Smarcel(@value{GDBP})
15474130809Smarcel-exec-continue
15475130809Smarcel^running
15476130809Smarcel^done,reason="watchpoint-scope",wpnum="2",
15477130809Smarcelframe=@{func="callee3",args=[@{name="strarg",
15478130809Smarcelvalue="0x11940 \"A string argument.\""@}],
15479130809Smarcelfile="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
15480130809Smarcel(@value{GDBP})
15481130809Smarcel-break-list
15482130809Smarcel^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15483130809Smarcelhdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15484130809Smarcel@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15485130809Smarcel@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15486130809Smarcel@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15487130809Smarcel@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15488130809Smarcel@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15489130809Smarcelbody=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15490130809Smarceladdr="0x00010734",func="callee4",
15491130809Smarcelfile="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
15492130809Smarcel(@value{GDBP})
15493130809Smarcel@end smallexample
15494130809Smarcel
15495130809Smarcel@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15496130809Smarcel@node GDB/MI Data Manipulation
15497130809Smarcel@section @sc{gdb/mi} Data Manipulation
15498130809Smarcel
15499130809Smarcel@cindex data manipulation, in @sc{gdb/mi}
15500130809Smarcel@cindex @sc{gdb/mi}, data manipulation
15501130809SmarcelThis section describes the @sc{gdb/mi} commands that manipulate data:
15502130809Smarcelexamine memory and registers, evaluate expressions, etc.
15503130809Smarcel
15504130809Smarcel@c REMOVED FROM THE INTERFACE.
15505130809Smarcel@c @subheading -data-assign
15506130809Smarcel@c Change the value of a program variable. Plenty of side effects.
15507130809Smarcel@c @subsubheading GDB command
15508130809Smarcel@c set variable
15509130809Smarcel@c @subsubheading Example
15510130809Smarcel@c N.A.
15511130809Smarcel
15512130809Smarcel@subheading The @code{-data-disassemble} Command
15513130809Smarcel@findex -data-disassemble
15514130809Smarcel
15515130809Smarcel@subsubheading Synopsis
15516130809Smarcel
15517130809Smarcel@smallexample
15518130809Smarcel -data-disassemble
15519130809Smarcel    [ -s @var{start-addr} -e @var{end-addr} ]
15520130809Smarcel  | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
15521130809Smarcel  -- @var{mode}
15522130809Smarcel@end smallexample
15523130809Smarcel
15524130809Smarcel@noindent
15525130809SmarcelWhere:
15526130809Smarcel
15527130809Smarcel@table @samp
15528130809Smarcel@item @var{start-addr}
15529130809Smarcelis the beginning address (or @code{$pc})
15530130809Smarcel@item @var{end-addr}
15531130809Smarcelis the end address
15532130809Smarcel@item @var{filename}
15533130809Smarcelis the name of the file to disassemble
15534130809Smarcel@item @var{linenum}
15535130809Smarcelis the line number to disassemble around
15536130809Smarcel@item @var{lines}
15537130809Smarcelis the the number of disassembly lines to be produced.  If it is -1,
15538130809Smarcelthe whole function will be disassembled, in case no @var{end-addr} is
15539130809Smarcelspecified.  If @var{end-addr} is specified as a non-zero value, and
15540130809Smarcel@var{lines} is lower than the number of disassembly lines between
15541130809Smarcel@var{start-addr} and @var{end-addr}, only @var{lines} lines are
15542130809Smarceldisplayed; if @var{lines} is higher than the number of lines between
15543130809Smarcel@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
15544130809Smarcelare displayed.
15545130809Smarcel@item @var{mode}
15546130809Smarcelis either 0 (meaning only disassembly) or 1 (meaning mixed source and
15547130809Smarceldisassembly).
15548130809Smarcel@end table
15549130809Smarcel
15550130809Smarcel@subsubheading Result
15551130809Smarcel
15552130809SmarcelThe output for each instruction is composed of four fields:
15553130809Smarcel
15554130809Smarcel@itemize @bullet
15555130809Smarcel@item Address
15556130809Smarcel@item Func-name
15557130809Smarcel@item Offset
15558130809Smarcel@item Instruction
15559130809Smarcel@end itemize
15560130809Smarcel
15561130809SmarcelNote that whatever included in the instruction field, is not manipulated
15562130809Smarceldirectely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
15563130809Smarcel
15564130809Smarcel@subsubheading @value{GDBN} Command
15565130809Smarcel
15566130809SmarcelThere's no direct mapping from this command to the CLI.
15567130809Smarcel
15568130809Smarcel@subsubheading Example
15569130809Smarcel
15570130809SmarcelDisassemble from the current value of @code{$pc} to @code{$pc + 20}:
15571130809Smarcel
15572130809Smarcel@smallexample
15573130809Smarcel(@value{GDBP})
15574130809Smarcel-data-disassemble -s $pc -e "$pc + 20" -- 0
15575130809Smarcel^done,
15576130809Smarcelasm_insns=[
15577130809Smarcel@{address="0x000107c0",func-name="main",offset="4",
15578130809Smarcelinst="mov  2, %o0"@},
15579130809Smarcel@{address="0x000107c4",func-name="main",offset="8",
15580130809Smarcelinst="sethi  %hi(0x11800), %o2"@},
15581130809Smarcel@{address="0x000107c8",func-name="main",offset="12",
15582130809Smarcelinst="or  %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
15583130809Smarcel@{address="0x000107cc",func-name="main",offset="16",
15584130809Smarcelinst="sethi  %hi(0x11800), %o2"@},
15585130809Smarcel@{address="0x000107d0",func-name="main",offset="20",
15586130809Smarcelinst="or  %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
15587130809Smarcel(@value{GDBP})
15588130809Smarcel@end smallexample
15589130809Smarcel
15590130809SmarcelDisassemble the whole @code{main} function.  Line 32 is part of
15591130809Smarcel@code{main}.
15592130809Smarcel
15593130809Smarcel@smallexample
15594130809Smarcel-data-disassemble -f basics.c -l 32 -- 0
15595130809Smarcel^done,asm_insns=[
15596130809Smarcel@{address="0x000107bc",func-name="main",offset="0",
15597130809Smarcelinst="save  %sp, -112, %sp"@},
15598130809Smarcel@{address="0x000107c0",func-name="main",offset="4",
15599130809Smarcelinst="mov   2, %o0"@},
15600130809Smarcel@{address="0x000107c4",func-name="main",offset="8",
15601130809Smarcelinst="sethi %hi(0x11800), %o2"@},
15602130809Smarcel[@dots{}]
15603130809Smarcel@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
15604130809Smarcel@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
15605130809Smarcel(@value{GDBP})
15606130809Smarcel@end smallexample
15607130809Smarcel
15608130809SmarcelDisassemble 3 instructions from the start of @code{main}:
15609130809Smarcel
15610130809Smarcel@smallexample
15611130809Smarcel(@value{GDBP})
15612130809Smarcel-data-disassemble -f basics.c -l 32 -n 3 -- 0
15613130809Smarcel^done,asm_insns=[
15614130809Smarcel@{address="0x000107bc",func-name="main",offset="0",
15615130809Smarcelinst="save  %sp, -112, %sp"@},
15616130809Smarcel@{address="0x000107c0",func-name="main",offset="4",
15617130809Smarcelinst="mov  2, %o0"@},
15618130809Smarcel@{address="0x000107c4",func-name="main",offset="8",
15619130809Smarcelinst="sethi  %hi(0x11800), %o2"@}]
15620130809Smarcel(@value{GDBP})
15621130809Smarcel@end smallexample
15622130809Smarcel
15623130809SmarcelDisassemble 3 instructions from the start of @code{main} in mixed mode:
15624130809Smarcel
15625130809Smarcel@smallexample
15626130809Smarcel(@value{GDBP})
15627130809Smarcel-data-disassemble -f basics.c -l 32 -n 3 -- 1
15628130809Smarcel^done,asm_insns=[
15629130809Smarcelsrc_and_asm_line=@{line="31",
15630130809Smarcelfile="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
15631130809Smarcel  testsuite/gdb.mi/basics.c",line_asm_insn=[
15632130809Smarcel@{address="0x000107bc",func-name="main",offset="0",
15633130809Smarcelinst="save  %sp, -112, %sp"@}]@},
15634130809Smarcelsrc_and_asm_line=@{line="32",
15635130809Smarcelfile="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
15636130809Smarcel  testsuite/gdb.mi/basics.c",line_asm_insn=[
15637130809Smarcel@{address="0x000107c0",func-name="main",offset="4",
15638130809Smarcelinst="mov  2, %o0"@},
15639130809Smarcel@{address="0x000107c4",func-name="main",offset="8",
15640130809Smarcelinst="sethi  %hi(0x11800), %o2"@}]@}]
15641130809Smarcel(@value{GDBP})
15642130809Smarcel@end smallexample
15643130809Smarcel
15644130809Smarcel
15645130809Smarcel@subheading The @code{-data-evaluate-expression} Command
15646130809Smarcel@findex -data-evaluate-expression
15647130809Smarcel
15648130809Smarcel@subsubheading Synopsis
15649130809Smarcel
15650130809Smarcel@smallexample
15651130809Smarcel -data-evaluate-expression @var{expr}
15652130809Smarcel@end smallexample
15653130809Smarcel
15654130809SmarcelEvaluate @var{expr} as an expression.  The expression could contain an
15655130809Smarcelinferior function call.  The function call will execute synchronously.
15656130809SmarcelIf the expression contains spaces, it must be enclosed in double quotes.
15657130809Smarcel
15658130809Smarcel@subsubheading @value{GDBN} Command
15659130809Smarcel
15660130809SmarcelThe corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
15661130809Smarcel@samp{call}.  In @code{gdbtk} only, there's a corresponding
15662130809Smarcel@samp{gdb_eval} command.
15663130809Smarcel
15664130809Smarcel@subsubheading Example
15665130809Smarcel
15666130809SmarcelIn the following example, the numbers that precede the commands are the
15667130809Smarcel@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
15668130809SmarcelCommand Syntax}.  Notice how @sc{gdb/mi} returns the same tokens in its
15669130809Smarceloutput.
15670130809Smarcel
15671130809Smarcel@smallexample
15672130809Smarcel211-data-evaluate-expression A
15673130809Smarcel211^done,value="1"
15674130809Smarcel(@value{GDBP})
15675130809Smarcel311-data-evaluate-expression &A
15676130809Smarcel311^done,value="0xefffeb7c"
15677130809Smarcel(@value{GDBP})
15678130809Smarcel411-data-evaluate-expression A+3
15679130809Smarcel411^done,value="4"
15680130809Smarcel(@value{GDBP})
15681130809Smarcel511-data-evaluate-expression "A + 3"
15682130809Smarcel511^done,value="4"
15683130809Smarcel(@value{GDBP})
15684130809Smarcel@end smallexample
15685130809Smarcel
15686130809Smarcel
15687130809Smarcel@subheading The @code{-data-list-changed-registers} Command
15688130809Smarcel@findex -data-list-changed-registers
15689130809Smarcel
15690130809Smarcel@subsubheading Synopsis
15691130809Smarcel
15692130809Smarcel@smallexample
15693130809Smarcel -data-list-changed-registers
15694130809Smarcel@end smallexample
15695130809Smarcel
15696130809SmarcelDisplay a list of the registers that have changed.
15697130809Smarcel
15698130809Smarcel@subsubheading @value{GDBN} Command
15699130809Smarcel
15700130809Smarcel@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
15701130809Smarcelhas the corresponding command @samp{gdb_changed_register_list}.
15702130809Smarcel
15703130809Smarcel@subsubheading Example
15704130809Smarcel
15705130809SmarcelOn a PPC MBX board:
15706130809Smarcel
15707130809Smarcel@smallexample
15708130809Smarcel(@value{GDBP})
15709130809Smarcel-exec-continue
15710130809Smarcel^running
15711130809Smarcel
15712130809Smarcel(@value{GDBP})
15713130809Smarcel*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
15714130809Smarcelargs=[],file="try.c",line="5"@}
15715130809Smarcel(@value{GDBP})
15716130809Smarcel-data-list-changed-registers
15717130809Smarcel^done,changed-registers=["0","1","2","4","5","6","7","8","9",
15718130809Smarcel"10","11","13","14","15","16","17","18","19","20","21","22","23",
15719130809Smarcel"24","25","26","27","28","30","31","64","65","66","67","69"]
15720130809Smarcel(@value{GDBP})
15721130809Smarcel@end smallexample
15722130809Smarcel
15723130809Smarcel
15724130809Smarcel@subheading The @code{-data-list-register-names} Command
15725130809Smarcel@findex -data-list-register-names
15726130809Smarcel
15727130809Smarcel@subsubheading Synopsis
15728130809Smarcel
15729130809Smarcel@smallexample
15730130809Smarcel -data-list-register-names [ ( @var{regno} )+ ]
15731130809Smarcel@end smallexample
15732130809Smarcel
15733130809SmarcelShow a list of register names for the current target.  If no arguments
15734130809Smarcelare given, it shows a list of the names of all the registers.  If
15735130809Smarcelinteger numbers are given as arguments, it will print a list of the
15736130809Smarcelnames of the registers corresponding to the arguments.  To ensure
15737130809Smarcelconsistency between a register name and its number, the output list may
15738130809Smarcelinclude empty register names.
15739130809Smarcel
15740130809Smarcel@subsubheading @value{GDBN} Command
15741130809Smarcel
15742130809Smarcel@value{GDBN} does not have a command which corresponds to
15743130809Smarcel@samp{-data-list-register-names}.  In @code{gdbtk} there is a
15744130809Smarcelcorresponding command @samp{gdb_regnames}.
15745130809Smarcel
15746130809Smarcel@subsubheading Example
15747130809Smarcel
15748130809SmarcelFor the PPC MBX board:
15749130809Smarcel@smallexample
15750130809Smarcel(@value{GDBP})
15751130809Smarcel-data-list-register-names
15752130809Smarcel^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
15753130809Smarcel"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
15754130809Smarcel"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
15755130809Smarcel"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
15756130809Smarcel"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
15757130809Smarcel"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
15758130809Smarcel"", "pc","ps","cr","lr","ctr","xer"]
15759130809Smarcel(@value{GDBP})
15760130809Smarcel-data-list-register-names 1 2 3
15761130809Smarcel^done,register-names=["r1","r2","r3"]
15762130809Smarcel(@value{GDBP})
15763130809Smarcel@end smallexample
15764130809Smarcel
15765130809Smarcel@subheading The @code{-data-list-register-values} Command
15766130809Smarcel@findex -data-list-register-values
15767130809Smarcel
15768130809Smarcel@subsubheading Synopsis
15769130809Smarcel
15770130809Smarcel@smallexample
15771130809Smarcel -data-list-register-values @var{fmt} [ ( @var{regno} )*]
15772130809Smarcel@end smallexample
15773130809Smarcel
15774130809SmarcelDisplay the registers' contents.  @var{fmt} is the format according to
15775130809Smarcelwhich the registers' contents are to be returned, followed by an optional
15776130809Smarcellist of numbers specifying the registers to display.  A missing list of
15777130809Smarcelnumbers indicates that the contents of all the registers must be returned.
15778130809Smarcel
15779130809SmarcelAllowed formats for @var{fmt} are:
15780130809Smarcel
15781130809Smarcel@table @code
15782130809Smarcel@item x
15783130809SmarcelHexadecimal
15784130809Smarcel@item o
15785130809SmarcelOctal
15786130809Smarcel@item t
15787130809SmarcelBinary
15788130809Smarcel@item d
15789130809SmarcelDecimal
15790130809Smarcel@item r
15791130809SmarcelRaw
15792130809Smarcel@item N
15793130809SmarcelNatural
15794130809Smarcel@end table
15795130809Smarcel
15796130809Smarcel@subsubheading @value{GDBN} Command
15797130809Smarcel
15798130809SmarcelThe corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
15799130809Smarcelall-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
15800130809Smarcel
15801130809Smarcel@subsubheading Example
15802130809Smarcel
15803130809SmarcelFor a PPC MBX board (note: line breaks are for readability only, they
15804130809Smarceldon't appear in the actual output):
15805130809Smarcel
15806130809Smarcel@smallexample
15807130809Smarcel(@value{GDBP})
15808130809Smarcel-data-list-register-values r 64 65
15809130809Smarcel^done,register-values=[@{number="64",value="0xfe00a300"@},
15810130809Smarcel@{number="65",value="0x00029002"@}]
15811130809Smarcel(@value{GDBP})
15812130809Smarcel-data-list-register-values x
15813130809Smarcel^done,register-values=[@{number="0",value="0xfe0043c8"@},
15814130809Smarcel@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
15815130809Smarcel@{number="3",value="0x0"@},@{number="4",value="0xa"@},
15816130809Smarcel@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
15817130809Smarcel@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
15818130809Smarcel@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
15819130809Smarcel@{number="11",value="0x1"@},@{number="12",value="0x0"@},
15820130809Smarcel@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
15821130809Smarcel@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
15822130809Smarcel@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
15823130809Smarcel@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
15824130809Smarcel@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
15825130809Smarcel@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
15826130809Smarcel@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
15827130809Smarcel@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
15828130809Smarcel@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
15829130809Smarcel@{number="31",value="0x0"@},@{number="32",value="0x0"@},
15830130809Smarcel@{number="33",value="0x0"@},@{number="34",value="0x0"@},
15831130809Smarcel@{number="35",value="0x0"@},@{number="36",value="0x0"@},
15832130809Smarcel@{number="37",value="0x0"@},@{number="38",value="0x0"@},
15833130809Smarcel@{number="39",value="0x0"@},@{number="40",value="0x0"@},
15834130809Smarcel@{number="41",value="0x0"@},@{number="42",value="0x0"@},
15835130809Smarcel@{number="43",value="0x0"@},@{number="44",value="0x0"@},
15836130809Smarcel@{number="45",value="0x0"@},@{number="46",value="0x0"@},
15837130809Smarcel@{number="47",value="0x0"@},@{number="48",value="0x0"@},
15838130809Smarcel@{number="49",value="0x0"@},@{number="50",value="0x0"@},
15839130809Smarcel@{number="51",value="0x0"@},@{number="52",value="0x0"@},
15840130809Smarcel@{number="53",value="0x0"@},@{number="54",value="0x0"@},
15841130809Smarcel@{number="55",value="0x0"@},@{number="56",value="0x0"@},
15842130809Smarcel@{number="57",value="0x0"@},@{number="58",value="0x0"@},
15843130809Smarcel@{number="59",value="0x0"@},@{number="60",value="0x0"@},
15844130809Smarcel@{number="61",value="0x0"@},@{number="62",value="0x0"@},
15845130809Smarcel@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
15846130809Smarcel@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
15847130809Smarcel@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
15848130809Smarcel@{number="69",value="0x20002b03"@}]
15849130809Smarcel(@value{GDBP})
15850130809Smarcel@end smallexample
15851130809Smarcel
15852130809Smarcel
15853130809Smarcel@subheading The @code{-data-read-memory} Command
15854130809Smarcel@findex -data-read-memory
15855130809Smarcel
15856130809Smarcel@subsubheading Synopsis
15857130809Smarcel
15858130809Smarcel@smallexample
15859130809Smarcel -data-read-memory [ -o @var{byte-offset} ]
15860130809Smarcel   @var{address} @var{word-format} @var{word-size}
15861130809Smarcel   @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
15862130809Smarcel@end smallexample
15863130809Smarcel
15864130809Smarcel@noindent
15865130809Smarcelwhere:
15866130809Smarcel
15867130809Smarcel@table @samp
15868130809Smarcel@item @var{address}
15869130809SmarcelAn expression specifying the address of the first memory word to be
15870130809Smarcelread.  Complex expressions containing embedded white space should be
15871130809Smarcelquoted using the C convention.
15872130809Smarcel
15873130809Smarcel@item @var{word-format}
15874130809SmarcelThe format to be used to print the memory words.  The notation is the
15875130809Smarcelsame as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
15876130809Smarcel,Output formats}).
15877130809Smarcel
15878130809Smarcel@item @var{word-size}
15879130809SmarcelThe size of each memory word in bytes.
15880130809Smarcel
15881130809Smarcel@item @var{nr-rows}
15882130809SmarcelThe number of rows in the output table.
15883130809Smarcel
15884130809Smarcel@item @var{nr-cols}
15885130809SmarcelThe number of columns in the output table.
15886130809Smarcel
15887130809Smarcel@item @var{aschar}
15888130809SmarcelIf present, indicates that each row should include an @sc{ascii} dump.  The
15889130809Smarcelvalue of @var{aschar} is used as a padding character when a byte is not a
15890130809Smarcelmember of the printable @sc{ascii} character set (printable @sc{ascii}
15891130809Smarcelcharacters are those whose code is between 32 and 126, inclusively).
15892130809Smarcel
15893130809Smarcel@item @var{byte-offset}
15894130809SmarcelAn offset to add to the @var{address} before fetching memory.
15895130809Smarcel@end table
15896130809Smarcel
15897130809SmarcelThis command displays memory contents as a table of @var{nr-rows} by
15898130809Smarcel@var{nr-cols} words, each word being @var{word-size} bytes.  In total,
15899130809Smarcel@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
15900130809Smarcel(returned as @samp{total-bytes}).  Should less than the requested number
15901130809Smarcelof bytes be returned by the target, the missing words are identified
15902130809Smarcelusing @samp{N/A}.  The number of bytes read from the target is returned
15903130809Smarcelin @samp{nr-bytes} and the starting address used to read memory in
15904130809Smarcel@samp{addr}.
15905130809Smarcel
15906130809SmarcelThe address of the next/previous row or page is available in
15907130809Smarcel@samp{next-row} and @samp{prev-row}, @samp{next-page} and
15908130809Smarcel@samp{prev-page}.
15909130809Smarcel
15910130809Smarcel@subsubheading @value{GDBN} Command
15911130809Smarcel
15912130809SmarcelThe corresponding @value{GDBN} command is @samp{x}.  @code{gdbtk} has
15913130809Smarcel@samp{gdb_get_mem} memory read command.
15914130809Smarcel
15915130809Smarcel@subsubheading Example
15916130809Smarcel
15917130809SmarcelRead six bytes of memory starting at @code{bytes+6} but then offset by
15918130809Smarcel@code{-6} bytes.  Format as three rows of two columns.  One byte per
15919130809Smarcelword.  Display each word in hex.
15920130809Smarcel
15921130809Smarcel@smallexample
15922130809Smarcel(@value{GDBP})
15923130809Smarcel9-data-read-memory -o -6 -- bytes+6 x 1 3 2
15924130809Smarcel9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
15925130809Smarcelnext-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
15926130809Smarcelprev-page="0x0000138a",memory=[
15927130809Smarcel@{addr="0x00001390",data=["0x00","0x01"]@},
15928130809Smarcel@{addr="0x00001392",data=["0x02","0x03"]@},
15929130809Smarcel@{addr="0x00001394",data=["0x04","0x05"]@}]
15930130809Smarcel(@value{GDBP})
15931130809Smarcel@end smallexample
15932130809Smarcel
15933130809SmarcelRead two bytes of memory starting at address @code{shorts + 64} and
15934130809Smarceldisplay as a single word formatted in decimal.
15935130809Smarcel
15936130809Smarcel@smallexample
15937130809Smarcel(@value{GDBP})
15938130809Smarcel5-data-read-memory shorts+64 d 2 1 1
15939130809Smarcel5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
15940130809Smarcelnext-row="0x00001512",prev-row="0x0000150e",
15941130809Smarcelnext-page="0x00001512",prev-page="0x0000150e",memory=[
15942130809Smarcel@{addr="0x00001510",data=["128"]@}]
15943130809Smarcel(@value{GDBP})
15944130809Smarcel@end smallexample
15945130809Smarcel
15946130809SmarcelRead thirty two bytes of memory starting at @code{bytes+16} and format
15947130809Smarcelas eight rows of four columns.  Include a string encoding with @samp{x}
15948130809Smarcelused as the non-printable character.
15949130809Smarcel
15950130809Smarcel@smallexample
15951130809Smarcel(@value{GDBP})
15952130809Smarcel4-data-read-memory bytes+16 x 1 8 4 x
15953130809Smarcel4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
15954130809Smarcelnext-row="0x000013c0",prev-row="0x0000139c",
15955130809Smarcelnext-page="0x000013c0",prev-page="0x00001380",memory=[
15956130809Smarcel@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
15957130809Smarcel@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
15958130809Smarcel@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
15959130809Smarcel@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
15960130809Smarcel@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
15961130809Smarcel@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
15962130809Smarcel@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
15963130809Smarcel@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
15964130809Smarcel(@value{GDBP})
15965130809Smarcel@end smallexample
15966130809Smarcel
15967130809Smarcel@subheading The @code{-display-delete} Command
15968130809Smarcel@findex -display-delete
15969130809Smarcel
15970130809Smarcel@subsubheading Synopsis
15971130809Smarcel
15972130809Smarcel@smallexample
15973130809Smarcel -display-delete @var{number}
15974130809Smarcel@end smallexample
15975130809Smarcel
15976130809SmarcelDelete the display @var{number}.
15977130809Smarcel
15978130809Smarcel@subsubheading @value{GDBN} Command
15979130809Smarcel
15980130809SmarcelThe corresponding @value{GDBN} command is @samp{delete display}.
15981130809Smarcel
15982130809Smarcel@subsubheading Example
15983130809SmarcelN.A.
15984130809Smarcel
15985130809Smarcel
15986130809Smarcel@subheading The @code{-display-disable} Command
15987130809Smarcel@findex -display-disable
15988130809Smarcel
15989130809Smarcel@subsubheading Synopsis
15990130809Smarcel
15991130809Smarcel@smallexample
15992130809Smarcel -display-disable @var{number}
15993130809Smarcel@end smallexample
15994130809Smarcel
15995130809SmarcelDisable display @var{number}.
15996130809Smarcel
15997130809Smarcel@subsubheading @value{GDBN} Command
15998130809Smarcel
15999130809SmarcelThe corresponding @value{GDBN} command is @samp{disable display}.
16000130809Smarcel
16001130809Smarcel@subsubheading Example
16002130809SmarcelN.A.
16003130809Smarcel
16004130809Smarcel
16005130809Smarcel@subheading The @code{-display-enable} Command
16006130809Smarcel@findex -display-enable
16007130809Smarcel
16008130809Smarcel@subsubheading Synopsis
16009130809Smarcel
16010130809Smarcel@smallexample
16011130809Smarcel -display-enable @var{number}
16012130809Smarcel@end smallexample
16013130809Smarcel
16014130809SmarcelEnable display @var{number}.
16015130809Smarcel
16016130809Smarcel@subsubheading @value{GDBN} Command
16017130809Smarcel
16018130809SmarcelThe corresponding @value{GDBN} command is @samp{enable display}.
16019130809Smarcel
16020130809Smarcel@subsubheading Example
16021130809SmarcelN.A.
16022130809Smarcel
16023130809Smarcel
16024130809Smarcel@subheading The @code{-display-insert} Command
16025130809Smarcel@findex -display-insert
16026130809Smarcel
16027130809Smarcel@subsubheading Synopsis
16028130809Smarcel
16029130809Smarcel@smallexample
16030130809Smarcel -display-insert @var{expression}
16031130809Smarcel@end smallexample
16032130809Smarcel
16033130809SmarcelDisplay @var{expression} every time the program stops.
16034130809Smarcel
16035130809Smarcel@subsubheading @value{GDBN} Command
16036130809Smarcel
16037130809SmarcelThe corresponding @value{GDBN} command is @samp{display}.
16038130809Smarcel
16039130809Smarcel@subsubheading Example
16040130809SmarcelN.A.
16041130809Smarcel
16042130809Smarcel
16043130809Smarcel@subheading The @code{-display-list} Command
16044130809Smarcel@findex -display-list
16045130809Smarcel
16046130809Smarcel@subsubheading Synopsis
16047130809Smarcel
16048130809Smarcel@smallexample
16049130809Smarcel -display-list
16050130809Smarcel@end smallexample
16051130809Smarcel
16052130809SmarcelList the displays.  Do not show the current values.
16053130809Smarcel
16054130809Smarcel@subsubheading @value{GDBN} Command
16055130809Smarcel
16056130809SmarcelThe corresponding @value{GDBN} command is @samp{info display}.
16057130809Smarcel
16058130809Smarcel@subsubheading Example
16059130809SmarcelN.A.
16060130809Smarcel
16061130809Smarcel
16062130809Smarcel@subheading The @code{-environment-cd} Command
16063130809Smarcel@findex -environment-cd
16064130809Smarcel
16065130809Smarcel@subsubheading Synopsis
16066130809Smarcel
16067130809Smarcel@smallexample
16068130809Smarcel -environment-cd @var{pathdir}
16069130809Smarcel@end smallexample
16070130809Smarcel
16071130809SmarcelSet @value{GDBN}'s working directory.
16072130809Smarcel
16073130809Smarcel@subsubheading @value{GDBN} Command
16074130809Smarcel
16075130809SmarcelThe corresponding @value{GDBN} command is @samp{cd}.
16076130809Smarcel
16077130809Smarcel@subsubheading Example
16078130809Smarcel
16079130809Smarcel@smallexample
16080130809Smarcel(@value{GDBP})
16081130809Smarcel-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
16082130809Smarcel^done
16083130809Smarcel(@value{GDBP})
16084130809Smarcel@end smallexample
16085130809Smarcel
16086130809Smarcel
16087130809Smarcel@subheading The @code{-environment-directory} Command
16088130809Smarcel@findex -environment-directory
16089130809Smarcel
16090130809Smarcel@subsubheading Synopsis
16091130809Smarcel
16092130809Smarcel@smallexample
16093130809Smarcel -environment-directory [ -r ] [ @var{pathdir} ]+
16094130809Smarcel@end smallexample
16095130809Smarcel
16096130809SmarcelAdd directories @var{pathdir} to beginning of search path for source files.
16097130809SmarcelIf the @samp{-r} option is used, the search path is reset to the default
16098130809Smarcelsearch path.  If directories @var{pathdir} are supplied in addition to the
16099130809Smarcel@samp{-r} option, the search path is first reset and then addition
16100130809Smarceloccurs as normal.
16101130809SmarcelMultiple directories may be specified, separated by blanks.  Specifying
16102130809Smarcelmultiple directories in a single command
16103130809Smarcelresults in the directories added to the beginning of the
16104130809Smarcelsearch path in the same order they were presented in the command.
16105130809SmarcelIf blanks are needed as
16106130809Smarcelpart of a directory name, double-quotes should be used around
16107130809Smarcelthe name.  In the command output, the path will show up separated
16108130809Smarcelby the system directory-separator character.  The directory-seperator
16109130809Smarcelcharacter must not be used
16110130809Smarcelin any directory name.
16111130809SmarcelIf no directories are specified, the current search path is displayed.
16112130809Smarcel
16113130809Smarcel@subsubheading @value{GDBN} Command
16114130809Smarcel
16115130809SmarcelThe corresponding @value{GDBN} command is @samp{dir}.
16116130809Smarcel
16117130809Smarcel@subsubheading Example
16118130809Smarcel
16119130809Smarcel@smallexample
16120130809Smarcel(@value{GDBP})
16121130809Smarcel-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
16122130809Smarcel^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
16123130809Smarcel(@value{GDBP})
16124130809Smarcel-environment-directory ""
16125130809Smarcel^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
16126130809Smarcel(@value{GDBP})
16127130809Smarcel-environment-directory -r /home/jjohnstn/src/gdb /usr/src
16128130809Smarcel^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
16129130809Smarcel(@value{GDBP})
16130130809Smarcel-environment-directory -r
16131130809Smarcel^done,source-path="$cdir:$cwd"
16132130809Smarcel(@value{GDBP})
16133130809Smarcel@end smallexample
16134130809Smarcel
16135130809Smarcel
16136130809Smarcel@subheading The @code{-environment-path} Command
16137130809Smarcel@findex -environment-path
16138130809Smarcel
16139130809Smarcel@subsubheading Synopsis
16140130809Smarcel
16141130809Smarcel@smallexample
16142130809Smarcel -environment-path [ -r ] [ @var{pathdir} ]+
16143130809Smarcel@end smallexample
16144130809Smarcel
16145130809SmarcelAdd directories @var{pathdir} to beginning of search path for object files.
16146130809SmarcelIf the @samp{-r} option is used, the search path is reset to the original
16147130809Smarcelsearch path that existed at gdb start-up.  If directories @var{pathdir} are
16148130809Smarcelsupplied in addition to the
16149130809Smarcel@samp{-r} option, the search path is first reset and then addition
16150130809Smarceloccurs as normal.
16151130809SmarcelMultiple directories may be specified, separated by blanks.  Specifying
16152130809Smarcelmultiple directories in a single command
16153130809Smarcelresults in the directories added to the beginning of the
16154130809Smarcelsearch path in the same order they were presented in the command.
16155130809SmarcelIf blanks are needed as
16156130809Smarcelpart of a directory name, double-quotes should be used around
16157130809Smarcelthe name.  In the command output, the path will show up separated
16158130809Smarcelby the system directory-separator character.  The directory-seperator
16159130809Smarcelcharacter must not be used
16160130809Smarcelin any directory name.
16161130809SmarcelIf no directories are specified, the current path is displayed.
16162130809Smarcel
16163130809Smarcel
16164130809Smarcel@subsubheading @value{GDBN} Command
16165130809Smarcel
16166130809SmarcelThe corresponding @value{GDBN} command is @samp{path}.
16167130809Smarcel
16168130809Smarcel@subsubheading Example
16169130809Smarcel
16170130809Smarcel@smallexample
16171130809Smarcel(@value{GDBP})
16172130809Smarcel-environment-path
16173130809Smarcel^done,path="/usr/bin"
16174130809Smarcel(@value{GDBP})
16175130809Smarcel-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
16176130809Smarcel^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
16177130809Smarcel(@value{GDBP})
16178130809Smarcel-environment-path -r /usr/local/bin
16179130809Smarcel^done,path="/usr/local/bin:/usr/bin"
16180130809Smarcel(@value{GDBP})
16181130809Smarcel@end smallexample
16182130809Smarcel
16183130809Smarcel
16184130809Smarcel@subheading The @code{-environment-pwd} Command
16185130809Smarcel@findex -environment-pwd
16186130809Smarcel
16187130809Smarcel@subsubheading Synopsis
16188130809Smarcel
16189130809Smarcel@smallexample
16190130809Smarcel -environment-pwd
16191130809Smarcel@end smallexample
16192130809Smarcel
16193130809SmarcelShow the current working directory.
16194130809Smarcel
16195130809Smarcel@subsubheading @value{GDBN} command
16196130809Smarcel
16197130809SmarcelThe corresponding @value{GDBN} command is @samp{pwd}.
16198130809Smarcel
16199130809Smarcel@subsubheading Example
16200130809Smarcel
16201130809Smarcel@smallexample
16202130809Smarcel(@value{GDBP})
16203130809Smarcel-environment-pwd
16204130809Smarcel^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
16205130809Smarcel(@value{GDBP})
16206130809Smarcel@end smallexample
16207130809Smarcel
16208130809Smarcel@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16209130809Smarcel@node GDB/MI Program Control
16210130809Smarcel@section @sc{gdb/mi} Program control
16211130809Smarcel
16212130809Smarcel@subsubheading Program termination
16213130809Smarcel
16214130809SmarcelAs a result of execution, the inferior program can run to completion, if
16215130809Smarcelit doesn't encounter any breakpoints.  In this case the output will
16216130809Smarcelinclude an exit code, if the program has exited exceptionally.
16217130809Smarcel
16218130809Smarcel@subsubheading Examples
16219130809Smarcel
16220130809Smarcel@noindent
16221130809SmarcelProgram exited normally:
16222130809Smarcel
16223130809Smarcel@smallexample
16224130809Smarcel(@value{GDBP})
16225130809Smarcel-exec-run
16226130809Smarcel^running
16227130809Smarcel(@value{GDBP})
16228130809Smarcelx = 55
16229130809Smarcel*stopped,reason="exited-normally"
16230130809Smarcel(@value{GDBP})
16231130809Smarcel@end smallexample
16232130809Smarcel
16233130809Smarcel@noindent
16234130809SmarcelProgram exited exceptionally:
16235130809Smarcel
16236130809Smarcel@smallexample
16237130809Smarcel(@value{GDBP})
16238130809Smarcel-exec-run
16239130809Smarcel^running
16240130809Smarcel(@value{GDBP})
16241130809Smarcelx = 55
16242130809Smarcel*stopped,reason="exited",exit-code="01"
16243130809Smarcel(@value{GDBP})
16244130809Smarcel@end smallexample
16245130809Smarcel
16246130809SmarcelAnother way the program can terminate is if it receives a signal such as
16247130809Smarcel@code{SIGINT}.  In this case, @sc{gdb/mi} displays this:
16248130809Smarcel
16249130809Smarcel@smallexample
16250130809Smarcel(@value{GDBP})
16251130809Smarcel*stopped,reason="exited-signalled",signal-name="SIGINT",
16252130809Smarcelsignal-meaning="Interrupt"
16253130809Smarcel@end smallexample
16254130809Smarcel
16255130809Smarcel
16256130809Smarcel@subheading The @code{-exec-abort} Command
16257130809Smarcel@findex -exec-abort
16258130809Smarcel
16259130809Smarcel@subsubheading Synopsis
16260130809Smarcel
16261130809Smarcel@smallexample
16262130809Smarcel -exec-abort
16263130809Smarcel@end smallexample
16264130809Smarcel
16265130809SmarcelKill the inferior running program.
16266130809Smarcel
16267130809Smarcel@subsubheading @value{GDBN} Command
16268130809Smarcel
16269130809SmarcelThe corresponding @value{GDBN} command is @samp{kill}.
16270130809Smarcel
16271130809Smarcel@subsubheading Example
16272130809SmarcelN.A.
16273130809Smarcel
16274130809Smarcel
16275130809Smarcel@subheading The @code{-exec-arguments} Command
16276130809Smarcel@findex -exec-arguments
16277130809Smarcel
16278130809Smarcel@subsubheading Synopsis
16279130809Smarcel
16280130809Smarcel@smallexample
16281130809Smarcel -exec-arguments @var{args}
16282130809Smarcel@end smallexample
16283130809Smarcel
16284130809SmarcelSet the inferior program arguments, to be used in the next
16285130809Smarcel@samp{-exec-run}.
16286130809Smarcel
16287130809Smarcel@subsubheading @value{GDBN} Command
16288130809Smarcel
16289130809SmarcelThe corresponding @value{GDBN} command is @samp{set args}.
16290130809Smarcel
16291130809Smarcel@subsubheading Example
16292130809Smarcel
16293130809Smarcel@c FIXME!
16294130809SmarcelDon't have one around.
16295130809Smarcel
16296130809Smarcel
16297130809Smarcel@subheading The @code{-exec-continue} Command
16298130809Smarcel@findex -exec-continue
16299130809Smarcel
16300130809Smarcel@subsubheading Synopsis
16301130809Smarcel
16302130809Smarcel@smallexample
16303130809Smarcel -exec-continue
16304130809Smarcel@end smallexample
16305130809Smarcel
16306130809SmarcelAsynchronous command.  Resumes the execution of the inferior program
16307130809Smarceluntil a breakpoint is encountered, or until the inferior exits.
16308130809Smarcel
16309130809Smarcel@subsubheading @value{GDBN} Command
16310130809Smarcel
16311130809SmarcelThe corresponding @value{GDBN} corresponding is @samp{continue}.
16312130809Smarcel
16313130809Smarcel@subsubheading Example
16314130809Smarcel
16315130809Smarcel@smallexample
16316130809Smarcel-exec-continue
16317130809Smarcel^running
16318130809Smarcel(@value{GDBP})
16319130809Smarcel@@Hello world
16320130809Smarcel*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
16321130809Smarcelfile="hello.c",line="13"@}
16322130809Smarcel(@value{GDBP})
16323130809Smarcel@end smallexample
16324130809Smarcel
16325130809Smarcel
16326130809Smarcel@subheading The @code{-exec-finish} Command
16327130809Smarcel@findex -exec-finish
16328130809Smarcel
16329130809Smarcel@subsubheading Synopsis
16330130809Smarcel
16331130809Smarcel@smallexample
16332130809Smarcel -exec-finish
16333130809Smarcel@end smallexample
16334130809Smarcel
16335130809SmarcelAsynchronous command.  Resumes the execution of the inferior program
16336130809Smarceluntil the current function is exited.  Displays the results returned by
16337130809Smarcelthe function.
16338130809Smarcel
16339130809Smarcel@subsubheading @value{GDBN} Command
16340130809Smarcel
16341130809SmarcelThe corresponding @value{GDBN} command is @samp{finish}.
16342130809Smarcel
16343130809Smarcel@subsubheading Example
16344130809Smarcel
16345130809SmarcelFunction returning @code{void}.
16346130809Smarcel
16347130809Smarcel@smallexample
16348130809Smarcel-exec-finish
16349130809Smarcel^running
16350130809Smarcel(@value{GDBP})
16351130809Smarcel@@hello from foo
16352130809Smarcel*stopped,reason="function-finished",frame=@{func="main",args=[],
16353130809Smarcelfile="hello.c",line="7"@}
16354130809Smarcel(@value{GDBP})
16355130809Smarcel@end smallexample
16356130809Smarcel
16357130809SmarcelFunction returning other than @code{void}.  The name of the internal
16358130809Smarcel@value{GDBN} variable storing the result is printed, together with the
16359130809Smarcelvalue itself.
16360130809Smarcel
16361130809Smarcel@smallexample
16362130809Smarcel-exec-finish
16363130809Smarcel^running
16364130809Smarcel(@value{GDBP})
16365130809Smarcel*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
16366130809Smarcelargs=[@{name="a",value="1"],@{name="b",value="9"@}@},
16367130809Smarcelfile="recursive2.c",line="14"@},
16368130809Smarcelgdb-result-var="$1",return-value="0"
16369130809Smarcel(@value{GDBP})
16370130809Smarcel@end smallexample
16371130809Smarcel
16372130809Smarcel
16373130809Smarcel@subheading The @code{-exec-interrupt} Command
16374130809Smarcel@findex -exec-interrupt
16375130809Smarcel
16376130809Smarcel@subsubheading Synopsis
16377130809Smarcel
16378130809Smarcel@smallexample
16379130809Smarcel -exec-interrupt
16380130809Smarcel@end smallexample
16381130809Smarcel
16382130809SmarcelAsynchronous command.  Interrupts the background execution of the target.
16383130809SmarcelNote how the token associated with the stop message is the one for the
16384130809Smarcelexecution command that has been interrupted.  The token for the interrupt
16385130809Smarcelitself only appears in the @samp{^done} output.  If the user is trying to
16386130809Smarcelinterrupt a non-running program, an error message will be printed.
16387130809Smarcel
16388130809Smarcel@subsubheading @value{GDBN} Command
16389130809Smarcel
16390130809SmarcelThe corresponding @value{GDBN} command is @samp{interrupt}.
16391130809Smarcel
16392130809Smarcel@subsubheading Example
16393130809Smarcel
16394130809Smarcel@smallexample
16395130809Smarcel(@value{GDBP})
16396130809Smarcel111-exec-continue
16397130809Smarcel111^running
16398130809Smarcel
16399130809Smarcel(@value{GDBP})
16400130809Smarcel222-exec-interrupt
16401130809Smarcel222^done
16402130809Smarcel(@value{GDBP})
16403130809Smarcel111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
16404130809Smarcelframe=@{addr="0x00010140",func="foo",args=[],file="try.c",line="13"@}
16405130809Smarcel(@value{GDBP})
16406130809Smarcel
16407130809Smarcel(@value{GDBP})
16408130809Smarcel-exec-interrupt
16409130809Smarcel^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
16410130809Smarcel(@value{GDBP})
16411130809Smarcel@end smallexample
16412130809Smarcel
16413130809Smarcel
16414130809Smarcel@subheading The @code{-exec-next} Command
16415130809Smarcel@findex -exec-next
16416130809Smarcel
16417130809Smarcel@subsubheading Synopsis
16418130809Smarcel
16419130809Smarcel@smallexample
16420130809Smarcel -exec-next
16421130809Smarcel@end smallexample
16422130809Smarcel
16423130809SmarcelAsynchronous command.  Resumes execution of the inferior program, stopping
16424130809Smarcelwhen the beginning of the next source line is reached.
16425130809Smarcel
16426130809Smarcel@subsubheading @value{GDBN} Command
16427130809Smarcel
16428130809SmarcelThe corresponding @value{GDBN} command is @samp{next}.
16429130809Smarcel
16430130809Smarcel@subsubheading Example
16431130809Smarcel
16432130809Smarcel@smallexample
16433130809Smarcel-exec-next
16434130809Smarcel^running
16435130809Smarcel(@value{GDBP})
16436130809Smarcel*stopped,reason="end-stepping-range",line="8",file="hello.c"
16437130809Smarcel(@value{GDBP})
16438130809Smarcel@end smallexample
16439130809Smarcel
16440130809Smarcel
16441130809Smarcel@subheading The @code{-exec-next-instruction} Command
16442130809Smarcel@findex -exec-next-instruction
16443130809Smarcel
16444130809Smarcel@subsubheading Synopsis
16445130809Smarcel
16446130809Smarcel@smallexample
16447130809Smarcel -exec-next-instruction
16448130809Smarcel@end smallexample
16449130809Smarcel
16450130809SmarcelAsynchronous command.  Executes one machine instruction.  If the
16451130809Smarcelinstruction is a function call continues until the function returns.  If
16452130809Smarcelthe program stops at an instruction in the middle of a source line, the
16453130809Smarceladdress will be printed as well.
16454130809Smarcel
16455130809Smarcel@subsubheading @value{GDBN} Command
16456130809Smarcel
16457130809SmarcelThe corresponding @value{GDBN} command is @samp{nexti}.
16458130809Smarcel
16459130809Smarcel@subsubheading Example
16460130809Smarcel
16461130809Smarcel@smallexample
16462130809Smarcel(@value{GDBP})
16463130809Smarcel-exec-next-instruction
16464130809Smarcel^running
16465130809Smarcel
16466130809Smarcel(@value{GDBP})
16467130809Smarcel*stopped,reason="end-stepping-range",
16468130809Smarceladdr="0x000100d4",line="5",file="hello.c"
16469130809Smarcel(@value{GDBP})
16470130809Smarcel@end smallexample
16471130809Smarcel
16472130809Smarcel
16473130809Smarcel@subheading The @code{-exec-return} Command
16474130809Smarcel@findex -exec-return
16475130809Smarcel
16476130809Smarcel@subsubheading Synopsis
16477130809Smarcel
16478130809Smarcel@smallexample
16479130809Smarcel -exec-return
16480130809Smarcel@end smallexample
16481130809Smarcel
16482130809SmarcelMakes current function return immediately.  Doesn't execute the inferior.
16483130809SmarcelDisplays the new current frame.
16484130809Smarcel
16485130809Smarcel@subsubheading @value{GDBN} Command
16486130809Smarcel
16487130809SmarcelThe corresponding @value{GDBN} command is @samp{return}.
16488130809Smarcel
16489130809Smarcel@subsubheading Example
16490130809Smarcel
16491130809Smarcel@smallexample
16492130809Smarcel(@value{GDBP})
16493130809Smarcel200-break-insert callee4
16494130809Smarcel200^done,bkpt=@{number="1",addr="0x00010734",
16495130809Smarcelfile="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
16496130809Smarcel(@value{GDBP})
16497130809Smarcel000-exec-run
16498130809Smarcel000^running
16499130809Smarcel(@value{GDBP})
16500130809Smarcel000*stopped,reason="breakpoint-hit",bkptno="1",
16501130809Smarcelframe=@{func="callee4",args=[],
16502130809Smarcelfile="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
16503130809Smarcel(@value{GDBP})
16504130809Smarcel205-break-delete
16505130809Smarcel205^done
16506130809Smarcel(@value{GDBP})
16507130809Smarcel111-exec-return
16508130809Smarcel111^done,frame=@{level="0",func="callee3",
16509130809Smarcelargs=[@{name="strarg",
16510130809Smarcelvalue="0x11940 \"A string argument.\""@}],
16511130809Smarcelfile="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
16512130809Smarcel(@value{GDBP})
16513130809Smarcel@end smallexample
16514130809Smarcel
16515130809Smarcel
16516130809Smarcel@subheading The @code{-exec-run} Command
16517130809Smarcel@findex -exec-run
16518130809Smarcel
16519130809Smarcel@subsubheading Synopsis
16520130809Smarcel
16521130809Smarcel@smallexample
16522130809Smarcel -exec-run
16523130809Smarcel@end smallexample
16524130809Smarcel
16525130809SmarcelAsynchronous command.  Starts execution of the inferior from the
16526130809Smarcelbeginning.  The inferior executes until either a breakpoint is
16527130809Smarcelencountered or the program exits.
16528130809Smarcel
16529130809Smarcel@subsubheading @value{GDBN} Command
16530130809Smarcel
16531130809SmarcelThe corresponding @value{GDBN} command is @samp{run}.
16532130809Smarcel
16533130809Smarcel@subsubheading Example
16534130809Smarcel
16535130809Smarcel@smallexample
16536130809Smarcel(@value{GDBP})
16537130809Smarcel-break-insert main
16538130809Smarcel^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
16539130809Smarcel(@value{GDBP})
16540130809Smarcel-exec-run
16541130809Smarcel^running
16542130809Smarcel(@value{GDBP})
16543130809Smarcel*stopped,reason="breakpoint-hit",bkptno="1",
16544130809Smarcelframe=@{func="main",args=[],file="recursive2.c",line="4"@}
16545130809Smarcel(@value{GDBP})
16546130809Smarcel@end smallexample
16547130809Smarcel
16548130809Smarcel
16549130809Smarcel@subheading The @code{-exec-show-arguments} Command
16550130809Smarcel@findex -exec-show-arguments
16551130809Smarcel
16552130809Smarcel@subsubheading Synopsis
16553130809Smarcel
16554130809Smarcel@smallexample
16555130809Smarcel -exec-show-arguments
16556130809Smarcel@end smallexample
16557130809Smarcel
16558130809SmarcelPrint the arguments of the program.
16559130809Smarcel
16560130809Smarcel@subsubheading @value{GDBN} Command
16561130809Smarcel
16562130809SmarcelThe corresponding @value{GDBN} command is @samp{show args}.
16563130809Smarcel
16564130809Smarcel@subsubheading Example
16565130809SmarcelN.A.
16566130809Smarcel
16567130809Smarcel@c @subheading -exec-signal
16568130809Smarcel
16569130809Smarcel@subheading The @code{-exec-step} Command
16570130809Smarcel@findex -exec-step
16571130809Smarcel
16572130809Smarcel@subsubheading Synopsis
16573130809Smarcel
16574130809Smarcel@smallexample
16575130809Smarcel -exec-step
16576130809Smarcel@end smallexample
16577130809Smarcel
16578130809SmarcelAsynchronous command.  Resumes execution of the inferior program, stopping
16579130809Smarcelwhen the beginning of the next source line is reached, if the next
16580130809Smarcelsource line is not a function call.  If it is, stop at the first
16581130809Smarcelinstruction of the called function.
16582130809Smarcel
16583130809Smarcel@subsubheading @value{GDBN} Command
16584130809Smarcel
16585130809SmarcelThe corresponding @value{GDBN} command is @samp{step}.
16586130809Smarcel
16587130809Smarcel@subsubheading Example
16588130809Smarcel
16589130809SmarcelStepping into a function:
16590130809Smarcel
16591130809Smarcel@smallexample
16592130809Smarcel-exec-step
16593130809Smarcel^running
16594130809Smarcel(@value{GDBP})
16595130809Smarcel*stopped,reason="end-stepping-range",
16596130809Smarcelframe=@{func="foo",args=[@{name="a",value="10"@},
16597130809Smarcel@{name="b",value="0"@}],file="recursive2.c",line="11"@}
16598130809Smarcel(@value{GDBP})
16599130809Smarcel@end smallexample
16600130809Smarcel
16601130809SmarcelRegular stepping:
16602130809Smarcel
16603130809Smarcel@smallexample
16604130809Smarcel-exec-step
16605130809Smarcel^running
16606130809Smarcel(@value{GDBP})
16607130809Smarcel*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
16608130809Smarcel(@value{GDBP})
16609130809Smarcel@end smallexample
16610130809Smarcel
16611130809Smarcel
16612130809Smarcel@subheading The @code{-exec-step-instruction} Command
16613130809Smarcel@findex -exec-step-instruction
16614130809Smarcel
16615130809Smarcel@subsubheading Synopsis
16616130809Smarcel
16617130809Smarcel@smallexample
16618130809Smarcel -exec-step-instruction
16619130809Smarcel@end smallexample
16620130809Smarcel
16621130809SmarcelAsynchronous command.  Resumes the inferior which executes one machine
16622130809Smarcelinstruction.  The output, once @value{GDBN} has stopped, will vary depending on
16623130809Smarcelwhether we have stopped in the middle of a source line or not.  In the
16624130809Smarcelformer case, the address at which the program stopped will be printed as
16625130809Smarcelwell.
16626130809Smarcel
16627130809Smarcel@subsubheading @value{GDBN} Command
16628130809Smarcel
16629130809SmarcelThe corresponding @value{GDBN} command is @samp{stepi}.
16630130809Smarcel
16631130809Smarcel@subsubheading Example
16632130809Smarcel
16633130809Smarcel@smallexample
16634130809Smarcel(@value{GDBP})
16635130809Smarcel-exec-step-instruction
16636130809Smarcel^running
16637130809Smarcel
16638130809Smarcel(@value{GDBP})
16639130809Smarcel*stopped,reason="end-stepping-range",
16640130809Smarcelframe=@{func="foo",args=[],file="try.c",line="10"@}
16641130809Smarcel(@value{GDBP})
16642130809Smarcel-exec-step-instruction
16643130809Smarcel^running
16644130809Smarcel
16645130809Smarcel(@value{GDBP})
16646130809Smarcel*stopped,reason="end-stepping-range",
16647130809Smarcelframe=@{addr="0x000100f4",func="foo",args=[],file="try.c",line="10"@}
16648130809Smarcel(@value{GDBP})
16649130809Smarcel@end smallexample
16650130809Smarcel
16651130809Smarcel
16652130809Smarcel@subheading The @code{-exec-until} Command
16653130809Smarcel@findex -exec-until
16654130809Smarcel
16655130809Smarcel@subsubheading Synopsis
16656130809Smarcel
16657130809Smarcel@smallexample
16658130809Smarcel -exec-until [ @var{location} ]
16659130809Smarcel@end smallexample
16660130809Smarcel
16661130809SmarcelAsynchronous command.  Executes the inferior until the @var{location}
16662130809Smarcelspecified in the argument is reached.  If there is no argument, the inferior
16663130809Smarcelexecutes until a source line greater than the current one is reached.
16664130809SmarcelThe reason for stopping in this case will be @samp{location-reached}.
16665130809Smarcel
16666130809Smarcel@subsubheading @value{GDBN} Command
16667130809Smarcel
16668130809SmarcelThe corresponding @value{GDBN} command is @samp{until}.
16669130809Smarcel
16670130809Smarcel@subsubheading Example
16671130809Smarcel
16672130809Smarcel@smallexample
16673130809Smarcel(@value{GDBP})
16674130809Smarcel-exec-until recursive2.c:6
16675130809Smarcel^running
16676130809Smarcel(@value{GDBP})
16677130809Smarcelx = 55
16678130809Smarcel*stopped,reason="location-reached",frame=@{func="main",args=[],
16679130809Smarcelfile="recursive2.c",line="6"@}
16680130809Smarcel(@value{GDBP})
16681130809Smarcel@end smallexample
16682130809Smarcel
16683130809Smarcel@ignore
16684130809Smarcel@subheading -file-clear
16685130809SmarcelIs this going away????
16686130809Smarcel@end ignore
16687130809Smarcel
16688130809Smarcel
16689130809Smarcel@subheading The @code{-file-exec-and-symbols} Command
16690130809Smarcel@findex -file-exec-and-symbols
16691130809Smarcel
16692130809Smarcel@subsubheading Synopsis
16693130809Smarcel
16694130809Smarcel@smallexample
16695130809Smarcel -file-exec-and-symbols @var{file}
16696130809Smarcel@end smallexample
16697130809Smarcel
16698130809SmarcelSpecify the executable file to be debugged.  This file is the one from
16699130809Smarcelwhich the symbol table is also read.  If no file is specified, the
16700130809Smarcelcommand clears the executable and symbol information.  If breakpoints
16701130809Smarcelare set when using this command with no arguments, @value{GDBN} will produce
16702130809Smarcelerror messages.  Otherwise, no output is produced, except a completion
16703130809Smarcelnotification.
16704130809Smarcel
16705130809Smarcel@subsubheading @value{GDBN} Command
16706130809Smarcel
16707130809SmarcelThe corresponding @value{GDBN} command is @samp{file}.
16708130809Smarcel
16709130809Smarcel@subsubheading Example
16710130809Smarcel
16711130809Smarcel@smallexample
16712130809Smarcel(@value{GDBP})
16713130809Smarcel-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
16714130809Smarcel^done
16715130809Smarcel(@value{GDBP})
16716130809Smarcel@end smallexample
16717130809Smarcel
16718130809Smarcel
16719130809Smarcel@subheading The @code{-file-exec-file} Command
16720130809Smarcel@findex -file-exec-file
16721130809Smarcel
16722130809Smarcel@subsubheading Synopsis
16723130809Smarcel
16724130809Smarcel@smallexample
16725130809Smarcel -file-exec-file @var{file}
16726130809Smarcel@end smallexample
16727130809Smarcel
16728130809SmarcelSpecify the executable file to be debugged.  Unlike
16729130809Smarcel@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
16730130809Smarcelfrom this file.  If used without argument, @value{GDBN} clears the information
16731130809Smarcelabout the executable file.  No output is produced, except a completion
16732130809Smarcelnotification.
16733130809Smarcel
16734130809Smarcel@subsubheading @value{GDBN} Command
16735130809Smarcel
16736130809SmarcelThe corresponding @value{GDBN} command is @samp{exec-file}.
16737130809Smarcel
16738130809Smarcel@subsubheading Example
16739130809Smarcel
16740130809Smarcel@smallexample
16741130809Smarcel(@value{GDBP})
16742130809Smarcel-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
16743130809Smarcel^done
16744130809Smarcel(@value{GDBP})
16745130809Smarcel@end smallexample
16746130809Smarcel
16747130809Smarcel
16748130809Smarcel@subheading The @code{-file-list-exec-sections} Command
16749130809Smarcel@findex -file-list-exec-sections
16750130809Smarcel
16751130809Smarcel@subsubheading Synopsis
16752130809Smarcel
16753130809Smarcel@smallexample
16754130809Smarcel -file-list-exec-sections
16755130809Smarcel@end smallexample
16756130809Smarcel
16757130809SmarcelList the sections of the current executable file.
16758130809Smarcel
16759130809Smarcel@subsubheading @value{GDBN} Command
16760130809Smarcel
16761130809SmarcelThe @value{GDBN} command @samp{info file} shows, among the rest, the same
16762130809Smarcelinformation as this command.  @code{gdbtk} has a corresponding command
16763130809Smarcel@samp{gdb_load_info}.
16764130809Smarcel
16765130809Smarcel@subsubheading Example
16766130809SmarcelN.A.
16767130809Smarcel
16768130809Smarcel
16769130809Smarcel@subheading The @code{-file-list-exec-source-file} Command
16770130809Smarcel@findex -file-list-exec-source-file
16771130809Smarcel
16772130809Smarcel@subsubheading Synopsis
16773130809Smarcel
16774130809Smarcel@smallexample
16775130809Smarcel -file-list-exec-source-file
16776130809Smarcel@end smallexample
16777130809Smarcel
16778130809SmarcelList the line number, the current source file, and the absolute path
16779130809Smarcelto the current source file for the current executable.
16780130809Smarcel
16781130809Smarcel@subsubheading @value{GDBN} Command
16782130809Smarcel
16783130809SmarcelThere's no @value{GDBN} command which directly corresponds to this one.
16784130809Smarcel
16785130809Smarcel@subsubheading Example
16786130809Smarcel
16787130809Smarcel@smallexample
16788130809Smarcel(@value{GDBP})
16789130809Smarcel123-file-list-exec-source-file
16790130809Smarcel123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
16791130809Smarcel(@value{GDBP})
16792130809Smarcel@end smallexample
16793130809Smarcel
16794130809Smarcel
16795130809Smarcel@subheading The @code{-file-list-exec-source-files} Command
16796130809Smarcel@findex -file-list-exec-source-files
16797130809Smarcel
16798130809Smarcel@subsubheading Synopsis
16799130809Smarcel
16800130809Smarcel@smallexample
16801130809Smarcel -file-list-exec-source-files
16802130809Smarcel@end smallexample
16803130809Smarcel
16804130809SmarcelList the source files for the current executable.
16805130809Smarcel
16806130809Smarcel@subsubheading @value{GDBN} Command
16807130809Smarcel
16808130809SmarcelThere's no @value{GDBN} command which directly corresponds to this one.
16809130809Smarcel@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
16810130809Smarcel
16811130809Smarcel@subsubheading Example
16812130809SmarcelN.A.
16813130809Smarcel
16814130809Smarcel
16815130809Smarcel@subheading The @code{-file-list-shared-libraries} Command
16816130809Smarcel@findex -file-list-shared-libraries
16817130809Smarcel
16818130809Smarcel@subsubheading Synopsis
16819130809Smarcel
16820130809Smarcel@smallexample
16821130809Smarcel -file-list-shared-libraries
16822130809Smarcel@end smallexample
16823130809Smarcel
16824130809SmarcelList the shared libraries in the program.
16825130809Smarcel
16826130809Smarcel@subsubheading @value{GDBN} Command
16827130809Smarcel
16828130809SmarcelThe corresponding @value{GDBN} command is @samp{info shared}.
16829130809Smarcel
16830130809Smarcel@subsubheading Example
16831130809SmarcelN.A.
16832130809Smarcel
16833130809Smarcel
16834130809Smarcel@subheading The @code{-file-list-symbol-files} Command
16835130809Smarcel@findex -file-list-symbol-files
16836130809Smarcel
16837130809Smarcel@subsubheading Synopsis
16838130809Smarcel
16839130809Smarcel@smallexample
16840130809Smarcel -file-list-symbol-files
16841130809Smarcel@end smallexample
16842130809Smarcel
16843130809SmarcelList symbol files.
16844130809Smarcel
16845130809Smarcel@subsubheading @value{GDBN} Command
16846130809Smarcel
16847130809SmarcelThe corresponding @value{GDBN} command is @samp{info file} (part of it).
16848130809Smarcel
16849130809Smarcel@subsubheading Example
16850130809SmarcelN.A.
16851130809Smarcel
16852130809Smarcel
16853130809Smarcel@subheading The @code{-file-symbol-file} Command
16854130809Smarcel@findex -file-symbol-file
16855130809Smarcel
16856130809Smarcel@subsubheading Synopsis
16857130809Smarcel
16858130809Smarcel@smallexample
16859130809Smarcel -file-symbol-file @var{file}
16860130809Smarcel@end smallexample
16861130809Smarcel
16862130809SmarcelRead symbol table info from the specified @var{file} argument.  When
16863130809Smarcelused without arguments, clears @value{GDBN}'s symbol table info.  No output is
16864130809Smarcelproduced, except for a completion notification.
16865130809Smarcel
16866130809Smarcel@subsubheading @value{GDBN} Command
16867130809Smarcel
16868130809SmarcelThe corresponding @value{GDBN} command is @samp{symbol-file}.
16869130809Smarcel
16870130809Smarcel@subsubheading Example
16871130809Smarcel
16872130809Smarcel@smallexample
16873130809Smarcel(@value{GDBP})
16874130809Smarcel-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
16875130809Smarcel^done
16876130809Smarcel(@value{GDBP})
16877130809Smarcel@end smallexample
16878130809Smarcel
16879130809Smarcel@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16880130809Smarcel@node GDB/MI Miscellaneous Commands
16881130809Smarcel@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
16882130809Smarcel
16883130809Smarcel@c @subheading -gdb-complete
16884130809Smarcel
16885130809Smarcel@subheading The @code{-gdb-exit} Command
16886130809Smarcel@findex -gdb-exit
16887130809Smarcel
16888130809Smarcel@subsubheading Synopsis
16889130809Smarcel
16890130809Smarcel@smallexample
16891130809Smarcel -gdb-exit
16892130809Smarcel@end smallexample
16893130809Smarcel
16894130809SmarcelExit @value{GDBN} immediately.
16895130809Smarcel
16896130809Smarcel@subsubheading @value{GDBN} Command
16897130809Smarcel
16898130809SmarcelApproximately corresponds to @samp{quit}.
16899130809Smarcel
16900130809Smarcel@subsubheading Example
16901130809Smarcel
16902130809Smarcel@smallexample
16903130809Smarcel(@value{GDBP})
16904130809Smarcel-gdb-exit
16905130809Smarcel@end smallexample
16906130809Smarcel
16907130809Smarcel@subheading The @code{-gdb-set} Command
16908130809Smarcel@findex -gdb-set
16909130809Smarcel
16910130809Smarcel@subsubheading Synopsis
16911130809Smarcel
16912130809Smarcel@smallexample
16913130809Smarcel -gdb-set
16914130809Smarcel@end smallexample
16915130809Smarcel
16916130809SmarcelSet an internal @value{GDBN} variable.
16917130809Smarcel@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
16918130809Smarcel
16919130809Smarcel@subsubheading @value{GDBN} Command
16920130809Smarcel
16921130809SmarcelThe corresponding @value{GDBN} command is @samp{set}.
16922130809Smarcel
16923130809Smarcel@subsubheading Example
16924130809Smarcel
16925130809Smarcel@smallexample
16926130809Smarcel(@value{GDBP})
16927130809Smarcel-gdb-set $foo=3
16928130809Smarcel^done
16929130809Smarcel(@value{GDBP})
16930130809Smarcel@end smallexample
16931130809Smarcel
16932130809Smarcel
16933130809Smarcel@subheading The @code{-gdb-show} Command
16934130809Smarcel@findex -gdb-show
16935130809Smarcel
16936130809Smarcel@subsubheading Synopsis
16937130809Smarcel
16938130809Smarcel@smallexample
16939130809Smarcel -gdb-show
16940130809Smarcel@end smallexample
16941130809Smarcel
16942130809SmarcelShow the current value of a @value{GDBN} variable.
16943130809Smarcel
16944130809Smarcel@subsubheading @value{GDBN} command
16945130809Smarcel
16946130809SmarcelThe corresponding @value{GDBN} command is @samp{show}.
16947130809Smarcel
16948130809Smarcel@subsubheading Example
16949130809Smarcel
16950130809Smarcel@smallexample
16951130809Smarcel(@value{GDBP})
16952130809Smarcel-gdb-show annotate
16953130809Smarcel^done,value="0"
16954130809Smarcel(@value{GDBP})
16955130809Smarcel@end smallexample
16956130809Smarcel
16957130809Smarcel@c @subheading -gdb-source
16958130809Smarcel
16959130809Smarcel
16960130809Smarcel@subheading The @code{-gdb-version} Command
16961130809Smarcel@findex -gdb-version
16962130809Smarcel
16963130809Smarcel@subsubheading Synopsis
16964130809Smarcel
16965130809Smarcel@smallexample
16966130809Smarcel -gdb-version
16967130809Smarcel@end smallexample
16968130809Smarcel
16969130809SmarcelShow version information for @value{GDBN}.  Used mostly in testing.
16970130809Smarcel
16971130809Smarcel@subsubheading @value{GDBN} Command
16972130809Smarcel
16973130809SmarcelThere's no equivalent @value{GDBN} command.  @value{GDBN} by default shows this
16974130809Smarcelinformation when you start an interactive session.
16975130809Smarcel
16976130809Smarcel@subsubheading Example
16977130809Smarcel
16978130809Smarcel@c This example modifies the actual output from GDB to avoid overfull
16979130809Smarcel@c box in TeX.
16980130809Smarcel@smallexample
16981130809Smarcel(@value{GDBP})
16982130809Smarcel-gdb-version
16983130809Smarcel~GNU gdb 5.2.1
16984130809Smarcel~Copyright 2000 Free Software Foundation, Inc.
16985130809Smarcel~GDB is free software, covered by the GNU General Public License, and
16986130809Smarcel~you are welcome to change it and/or distribute copies of it under
16987130809Smarcel~ certain conditions.
16988130809Smarcel~Type "show copying" to see the conditions.
16989130809Smarcel~There is absolutely no warranty for GDB.  Type "show warranty" for
16990130809Smarcel~ details.
16991130809Smarcel~This GDB was configured as
16992130809Smarcel "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
16993130809Smarcel^done
16994130809Smarcel(@value{GDBP})
16995130809Smarcel@end smallexample
16996130809Smarcel
16997130809Smarcel@subheading The @code{-interpreter-exec} Command
16998130809Smarcel@findex -interpreter-exec
16999130809Smarcel
17000130809Smarcel@subheading Synopsis
17001130809Smarcel
17002130809Smarcel@smallexample
17003130809Smarcel-interpreter-exec @var{interpreter} @var{command}
17004130809Smarcel@end smallexample
17005130809Smarcel
17006130809SmarcelExecute the specified @var{command} in the given @var{interpreter}.
17007130809Smarcel
17008130809Smarcel@subheading @value{GDBN} Command
17009130809Smarcel
17010130809SmarcelThe corresponding @value{GDBN} command is @samp{interpreter-exec}.
17011130809Smarcel
17012130809Smarcel@subheading Example
17013130809Smarcel
17014130809Smarcel@smallexample
17015130809Smarcel(@value{GDBP})
17016130809Smarcel-interpreter-exec console "break main"
17017130809Smarcel&"During symbol reading, couldn't parse type; debugger out of date?.\n"
17018130809Smarcel&"During symbol reading, bad structure-type format.\n"
17019130809Smarcel~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
17020130809Smarcel^done
17021130809Smarcel(@value{GDBP})
17022130809Smarcel@end smallexample
17023130809Smarcel
17024130809Smarcel@ignore
17025130809Smarcel@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17026130809Smarcel@node GDB/MI Kod Commands
17027130809Smarcel@section @sc{gdb/mi} Kod Commands
17028130809Smarcel
17029130809SmarcelThe Kod commands are not implemented.
17030130809Smarcel
17031130809Smarcel@c @subheading -kod-info
17032130809Smarcel
17033130809Smarcel@c @subheading -kod-list
17034130809Smarcel
17035130809Smarcel@c @subheading -kod-list-object-types
17036130809Smarcel
17037130809Smarcel@c @subheading -kod-show
17038130809Smarcel
17039130809Smarcel@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17040130809Smarcel@node GDB/MI Memory Overlay Commands
17041130809Smarcel@section @sc{gdb/mi} Memory Overlay Commands
17042130809Smarcel
17043130809SmarcelThe memory overlay commands are not implemented.
17044130809Smarcel
17045130809Smarcel@c @subheading -overlay-auto
17046130809Smarcel
17047130809Smarcel@c @subheading -overlay-list-mapping-state
17048130809Smarcel
17049130809Smarcel@c @subheading -overlay-list-overlays
17050130809Smarcel
17051130809Smarcel@c @subheading -overlay-map
17052130809Smarcel
17053130809Smarcel@c @subheading -overlay-off
17054130809Smarcel
17055130809Smarcel@c @subheading -overlay-on
17056130809Smarcel
17057130809Smarcel@c @subheading -overlay-unmap
17058130809Smarcel
17059130809Smarcel@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17060130809Smarcel@node GDB/MI Signal Handling Commands
17061130809Smarcel@section @sc{gdb/mi} Signal Handling Commands
17062130809Smarcel
17063130809SmarcelSignal handling commands are not implemented.
17064130809Smarcel
17065130809Smarcel@c @subheading -signal-handle
17066130809Smarcel
17067130809Smarcel@c @subheading -signal-list-handle-actions
17068130809Smarcel
17069130809Smarcel@c @subheading -signal-list-signal-types
17070130809Smarcel@end ignore
17071130809Smarcel
17072130809Smarcel
17073130809Smarcel@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17074130809Smarcel@node GDB/MI Stack Manipulation
17075130809Smarcel@section @sc{gdb/mi} Stack Manipulation Commands
17076130809Smarcel
17077130809Smarcel
17078130809Smarcel@subheading The @code{-stack-info-frame} Command
17079130809Smarcel@findex -stack-info-frame
17080130809Smarcel
17081130809Smarcel@subsubheading Synopsis
17082130809Smarcel
17083130809Smarcel@smallexample
17084130809Smarcel -stack-info-frame
17085130809Smarcel@end smallexample
17086130809Smarcel
17087130809SmarcelGet info on the current frame.
17088130809Smarcel
17089130809Smarcel@subsubheading @value{GDBN} Command
17090130809Smarcel
17091130809SmarcelThe corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
17092130809Smarcel(without arguments).
17093130809Smarcel
17094130809Smarcel@subsubheading Example
17095130809SmarcelN.A.
17096130809Smarcel
17097130809Smarcel@subheading The @code{-stack-info-depth} Command
17098130809Smarcel@findex -stack-info-depth
17099130809Smarcel
17100130809Smarcel@subsubheading Synopsis
17101130809Smarcel
17102130809Smarcel@smallexample
17103130809Smarcel -stack-info-depth [ @var{max-depth} ]
17104130809Smarcel@end smallexample
17105130809Smarcel
17106130809SmarcelReturn the depth of the stack.  If the integer argument @var{max-depth}
17107130809Smarcelis specified, do not count beyond @var{max-depth} frames.
17108130809Smarcel
17109130809Smarcel@subsubheading @value{GDBN} Command
17110130809Smarcel
17111130809SmarcelThere's no equivalent @value{GDBN} command.
17112130809Smarcel
17113130809Smarcel@subsubheading Example
17114130809Smarcel
17115130809SmarcelFor a stack with frame levels 0 through 11:
17116130809Smarcel
17117130809Smarcel@smallexample
17118130809Smarcel(@value{GDBP})
17119130809Smarcel-stack-info-depth
17120130809Smarcel^done,depth="12"
17121130809Smarcel(@value{GDBP})
17122130809Smarcel-stack-info-depth 4
17123130809Smarcel^done,depth="4"
17124130809Smarcel(@value{GDBP})
17125130809Smarcel-stack-info-depth 12
17126130809Smarcel^done,depth="12"
17127130809Smarcel(@value{GDBP})
17128130809Smarcel-stack-info-depth 11
17129130809Smarcel^done,depth="11"
17130130809Smarcel(@value{GDBP})
17131130809Smarcel-stack-info-depth 13
17132130809Smarcel^done,depth="12"
17133130809Smarcel(@value{GDBP})
17134130809Smarcel@end smallexample
17135130809Smarcel
17136130809Smarcel@subheading The @code{-stack-list-arguments} Command
17137130809Smarcel@findex -stack-list-arguments
17138130809Smarcel
17139130809Smarcel@subsubheading Synopsis
17140130809Smarcel
17141130809Smarcel@smallexample
17142130809Smarcel -stack-list-arguments @var{show-values}
17143130809Smarcel    [ @var{low-frame} @var{high-frame} ]
17144130809Smarcel@end smallexample
17145130809Smarcel
17146130809SmarcelDisplay a list of the arguments for the frames between @var{low-frame}
17147130809Smarceland @var{high-frame} (inclusive).  If @var{low-frame} and
17148130809Smarcel@var{high-frame} are not provided, list the arguments for the whole call
17149130809Smarcelstack.
17150130809Smarcel
17151130809SmarcelThe @var{show-values} argument must have a value of 0 or 1.  A value of
17152130809Smarcel0 means that only the names of the arguments are listed, a value of 1
17153130809Smarcelmeans that both names and values of the arguments are printed.
17154130809Smarcel
17155130809Smarcel@subsubheading @value{GDBN} Command
17156130809Smarcel
17157130809Smarcel@value{GDBN} does not have an equivalent command.  @code{gdbtk} has a
17158130809Smarcel@samp{gdb_get_args} command which partially overlaps with the
17159130809Smarcelfunctionality of @samp{-stack-list-arguments}.
17160130809Smarcel
17161130809Smarcel@subsubheading Example
17162130809Smarcel
17163130809Smarcel@smallexample
17164130809Smarcel(@value{GDBP})
17165130809Smarcel-stack-list-frames
17166130809Smarcel^done,
17167130809Smarcelstack=[
17168130809Smarcelframe=@{level="0",addr="0x00010734",func="callee4",
17169130809Smarcelfile="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
17170130809Smarcelframe=@{level="1",addr="0x0001076c",func="callee3",
17171130809Smarcelfile="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
17172130809Smarcelframe=@{level="2",addr="0x0001078c",func="callee2",
17173130809Smarcelfile="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
17174130809Smarcelframe=@{level="3",addr="0x000107b4",func="callee1",
17175130809Smarcelfile="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
17176130809Smarcelframe=@{level="4",addr="0x000107e0",func="main",
17177130809Smarcelfile="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
17178130809Smarcel(@value{GDBP})
17179130809Smarcel-stack-list-arguments 0
17180130809Smarcel^done,
17181130809Smarcelstack-args=[
17182130809Smarcelframe=@{level="0",args=[]@},
17183130809Smarcelframe=@{level="1",args=[name="strarg"]@},
17184130809Smarcelframe=@{level="2",args=[name="intarg",name="strarg"]@},
17185130809Smarcelframe=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
17186130809Smarcelframe=@{level="4",args=[]@}]
17187130809Smarcel(@value{GDBP})
17188130809Smarcel-stack-list-arguments 1
17189130809Smarcel^done,
17190130809Smarcelstack-args=[
17191130809Smarcelframe=@{level="0",args=[]@},
17192130809Smarcelframe=@{level="1",
17193130809Smarcel args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
17194130809Smarcelframe=@{level="2",args=[
17195130809Smarcel@{name="intarg",value="2"@},
17196130809Smarcel@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
17197130809Smarcel@{frame=@{level="3",args=[
17198130809Smarcel@{name="intarg",value="2"@},
17199130809Smarcel@{name="strarg",value="0x11940 \"A string argument.\""@},
17200130809Smarcel@{name="fltarg",value="3.5"@}]@},
17201130809Smarcelframe=@{level="4",args=[]@}]
17202130809Smarcel(@value{GDBP})
17203130809Smarcel-stack-list-arguments 0 2 2
17204130809Smarcel^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
17205130809Smarcel(@value{GDBP})
17206130809Smarcel-stack-list-arguments 1 2 2
17207130809Smarcel^done,stack-args=[frame=@{level="2",
17208130809Smarcelargs=[@{name="intarg",value="2"@},
17209130809Smarcel@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
17210130809Smarcel(@value{GDBP})
17211130809Smarcel@end smallexample
17212130809Smarcel
17213130809Smarcel@c @subheading -stack-list-exception-handlers
17214130809Smarcel
17215130809Smarcel
17216130809Smarcel@subheading The @code{-stack-list-frames} Command
17217130809Smarcel@findex -stack-list-frames
17218130809Smarcel
17219130809Smarcel@subsubheading Synopsis
17220130809Smarcel
17221130809Smarcel@smallexample
17222130809Smarcel -stack-list-frames [ @var{low-frame} @var{high-frame} ]
17223130809Smarcel@end smallexample
17224130809Smarcel
17225130809SmarcelList the frames currently on the stack.  For each frame it displays the
17226130809Smarcelfollowing info:
17227130809Smarcel
17228130809Smarcel@table @samp
17229130809Smarcel@item @var{level}
17230130809SmarcelThe frame number, 0 being the topmost frame, i.e. the innermost function.
17231130809Smarcel@item @var{addr}
17232130809SmarcelThe @code{$pc} value for that frame.
17233130809Smarcel@item @var{func}
17234130809SmarcelFunction name.
17235130809Smarcel@item @var{file}
17236130809SmarcelFile name of the source file where the function lives.
17237130809Smarcel@item @var{line}
17238130809SmarcelLine number corresponding to the @code{$pc}.
17239130809Smarcel@end table
17240130809Smarcel
17241130809SmarcelIf invoked without arguments, this command prints a backtrace for the
17242130809Smarcelwhole stack.  If given two integer arguments, it shows the frames whose
17243130809Smarcellevels are between the two arguments (inclusive).  If the two arguments
17244130809Smarcelare equal, it shows the single frame at the corresponding level.
17245130809Smarcel
17246130809Smarcel@subsubheading @value{GDBN} Command
17247130809Smarcel
17248130809SmarcelThe corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
17249130809Smarcel
17250130809Smarcel@subsubheading Example
17251130809Smarcel
17252130809SmarcelFull stack backtrace:
17253130809Smarcel
17254130809Smarcel@smallexample
17255130809Smarcel(@value{GDBP})
17256130809Smarcel-stack-list-frames
17257130809Smarcel^done,stack=
17258130809Smarcel[frame=@{level="0",addr="0x0001076c",func="foo",
17259130809Smarcel  file="recursive2.c",line="11"@},
17260130809Smarcelframe=@{level="1",addr="0x000107a4",func="foo",
17261130809Smarcel  file="recursive2.c",line="14"@},
17262130809Smarcelframe=@{level="2",addr="0x000107a4",func="foo",
17263130809Smarcel  file="recursive2.c",line="14"@},
17264130809Smarcelframe=@{level="3",addr="0x000107a4",func="foo",
17265130809Smarcel  file="recursive2.c",line="14"@},
17266130809Smarcelframe=@{level="4",addr="0x000107a4",func="foo",
17267130809Smarcel  file="recursive2.c",line="14"@},
17268130809Smarcelframe=@{level="5",addr="0x000107a4",func="foo",
17269130809Smarcel  file="recursive2.c",line="14"@},
17270130809Smarcelframe=@{level="6",addr="0x000107a4",func="foo",
17271130809Smarcel  file="recursive2.c",line="14"@},
17272130809Smarcelframe=@{level="7",addr="0x000107a4",func="foo",
17273130809Smarcel  file="recursive2.c",line="14"@},
17274130809Smarcelframe=@{level="8",addr="0x000107a4",func="foo",
17275130809Smarcel  file="recursive2.c",line="14"@},
17276130809Smarcelframe=@{level="9",addr="0x000107a4",func="foo",
17277130809Smarcel  file="recursive2.c",line="14"@},
17278130809Smarcelframe=@{level="10",addr="0x000107a4",func="foo",
17279130809Smarcel  file="recursive2.c",line="14"@},
17280130809Smarcelframe=@{level="11",addr="0x00010738",func="main",
17281130809Smarcel  file="recursive2.c",line="4"@}]
17282130809Smarcel(@value{GDBP})
17283130809Smarcel@end smallexample
17284130809Smarcel
17285130809SmarcelShow frames between @var{low_frame} and @var{high_frame}:
17286130809Smarcel
17287130809Smarcel@smallexample
17288130809Smarcel(@value{GDBP})
17289130809Smarcel-stack-list-frames 3 5
17290130809Smarcel^done,stack=
17291130809Smarcel[frame=@{level="3",addr="0x000107a4",func="foo",
17292130809Smarcel  file="recursive2.c",line="14"@},
17293130809Smarcelframe=@{level="4",addr="0x000107a4",func="foo",
17294130809Smarcel  file="recursive2.c",line="14"@},
17295130809Smarcelframe=@{level="5",addr="0x000107a4",func="foo",
17296130809Smarcel  file="recursive2.c",line="14"@}]
17297130809Smarcel(@value{GDBP})
17298130809Smarcel@end smallexample
17299130809Smarcel
17300130809SmarcelShow a single frame:
17301130809Smarcel
17302130809Smarcel@smallexample
17303130809Smarcel(@value{GDBP})
17304130809Smarcel-stack-list-frames 3 3
17305130809Smarcel^done,stack=
17306130809Smarcel[frame=@{level="3",addr="0x000107a4",func="foo",
17307130809Smarcel  file="recursive2.c",line="14"@}]
17308130809Smarcel(@value{GDBP})
17309130809Smarcel@end smallexample
17310130809Smarcel
17311130809Smarcel
17312130809Smarcel@subheading The @code{-stack-list-locals} Command
17313130809Smarcel@findex -stack-list-locals
17314130809Smarcel
17315130809Smarcel@subsubheading Synopsis
17316130809Smarcel
17317130809Smarcel@smallexample
17318130809Smarcel -stack-list-locals @var{print-values}
17319130809Smarcel@end smallexample
17320130809Smarcel
17321130809SmarcelDisplay the local variable names for the current frame.  With an
17322130809Smarcelargument of 0 or @code{--no-values}, prints only the names of the variables.
17323130809SmarcelWith argument of 1 or @code{--all-values}, prints also their values.  With
17324130809Smarcelargument of 2 or @code{--simple-values}, prints the name, type and value for
17325130809Smarcelsimple data types and the name and type for arrays, structures and
17326130809Smarcelunions.  In this last case, the idea is that the user can see the
17327130809Smarcelvalue of simple data types immediately and he can create variable
17328130809Smarcelobjects for other data types if he wishes to explore their values in
17329130809Smarcelmore detail.
17330130809Smarcel
17331130809Smarcel@subsubheading @value{GDBN} Command
17332130809Smarcel
17333130809Smarcel@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
17334130809Smarcel
17335130809Smarcel@subsubheading Example
17336130809Smarcel
17337130809Smarcel@smallexample
17338130809Smarcel(@value{GDBP})
17339130809Smarcel-stack-list-locals 0
17340130809Smarcel^done,locals=[name="A",name="B",name="C"]
17341130809Smarcel(@value{GDBP})
17342130809Smarcel-stack-list-locals --all-values
17343130809Smarcel^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
17344130809Smarcel  @{name="C",value="@{1, 2, 3@}"@}]
17345130809Smarcel-stack-list-locals --simple-values
17346130809Smarcel^done,locals=[@{name="A",type="int",value="1"@},
17347130809Smarcel  @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
17348130809Smarcel(@value{GDBP})
17349130809Smarcel@end smallexample
17350130809Smarcel
17351130809Smarcel
17352130809Smarcel@subheading The @code{-stack-select-frame} Command
17353130809Smarcel@findex -stack-select-frame
17354130809Smarcel
17355130809Smarcel@subsubheading Synopsis
17356130809Smarcel
17357130809Smarcel@smallexample
17358130809Smarcel -stack-select-frame @var{framenum}
17359130809Smarcel@end smallexample
17360130809Smarcel
17361130809SmarcelChange the current frame.  Select a different frame @var{framenum} on
17362130809Smarcelthe stack.
17363130809Smarcel
17364130809Smarcel@subsubheading @value{GDBN} Command
17365130809Smarcel
17366130809SmarcelThe corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
17367130809Smarcel@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
17368130809Smarcel
17369130809Smarcel@subsubheading Example
17370130809Smarcel
17371130809Smarcel@smallexample
17372130809Smarcel(@value{GDBP})
17373130809Smarcel-stack-select-frame 2
17374130809Smarcel^done
17375130809Smarcel(@value{GDBP})
17376130809Smarcel@end smallexample
17377130809Smarcel
17378130809Smarcel@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17379130809Smarcel@node GDB/MI Symbol Query
17380130809Smarcel@section @sc{gdb/mi} Symbol Query Commands
17381130809Smarcel
17382130809Smarcel
17383130809Smarcel@subheading The @code{-symbol-info-address} Command
17384130809Smarcel@findex -symbol-info-address
17385130809Smarcel
17386130809Smarcel@subsubheading Synopsis
17387130809Smarcel
17388130809Smarcel@smallexample
17389130809Smarcel -symbol-info-address @var{symbol}
17390130809Smarcel@end smallexample
17391130809Smarcel
17392130809SmarcelDescribe where @var{symbol} is stored.
17393130809Smarcel
17394130809Smarcel@subsubheading @value{GDBN} Command
17395130809Smarcel
17396130809SmarcelThe corresponding @value{GDBN} command is @samp{info address}.
17397130809Smarcel
17398130809Smarcel@subsubheading Example
17399130809SmarcelN.A.
17400130809Smarcel
17401130809Smarcel
17402130809Smarcel@subheading The @code{-symbol-info-file} Command
17403130809Smarcel@findex -symbol-info-file
17404130809Smarcel
17405130809Smarcel@subsubheading Synopsis
17406130809Smarcel
17407130809Smarcel@smallexample
17408130809Smarcel -symbol-info-file
17409130809Smarcel@end smallexample
17410130809Smarcel
17411130809SmarcelShow the file for the symbol.
17412130809Smarcel
17413130809Smarcel@subsubheading @value{GDBN} Command
17414130809Smarcel
17415130809SmarcelThere's no equivalent @value{GDBN} command.  @code{gdbtk} has
17416130809Smarcel@samp{gdb_find_file}.
17417130809Smarcel
17418130809Smarcel@subsubheading Example
17419130809SmarcelN.A.
17420130809Smarcel
17421130809Smarcel
17422130809Smarcel@subheading The @code{-symbol-info-function} Command
17423130809Smarcel@findex -symbol-info-function
17424130809Smarcel
17425130809Smarcel@subsubheading Synopsis
17426130809Smarcel
17427130809Smarcel@smallexample
17428130809Smarcel -symbol-info-function
17429130809Smarcel@end smallexample
17430130809Smarcel
17431130809SmarcelShow which function the symbol lives in.
17432130809Smarcel
17433130809Smarcel@subsubheading @value{GDBN} Command
17434130809Smarcel
17435130809Smarcel@samp{gdb_get_function} in @code{gdbtk}.
17436130809Smarcel
17437130809Smarcel@subsubheading Example
17438130809SmarcelN.A.
17439130809Smarcel
17440130809Smarcel
17441130809Smarcel@subheading The @code{-symbol-info-line} Command
17442130809Smarcel@findex -symbol-info-line
17443130809Smarcel
17444130809Smarcel@subsubheading Synopsis
17445130809Smarcel
17446130809Smarcel@smallexample
17447130809Smarcel -symbol-info-line
17448130809Smarcel@end smallexample
17449130809Smarcel
17450130809SmarcelShow the core addresses of the code for a source line.
17451130809Smarcel
17452130809Smarcel@subsubheading @value{GDBN} Command
17453130809Smarcel
17454130809SmarcelThe corresponding @value{GDBN} command is @samp{info line}.
17455130809Smarcel@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
17456130809Smarcel
17457130809Smarcel@subsubheading Example
17458130809SmarcelN.A.
17459130809Smarcel
17460130809Smarcel
17461130809Smarcel@subheading The @code{-symbol-info-symbol} Command
17462130809Smarcel@findex -symbol-info-symbol
17463130809Smarcel
17464130809Smarcel@subsubheading Synopsis
17465130809Smarcel
17466130809Smarcel@smallexample
17467130809Smarcel -symbol-info-symbol @var{addr}
17468130809Smarcel@end smallexample
17469130809Smarcel
17470130809SmarcelDescribe what symbol is at location @var{addr}.
17471130809Smarcel
17472130809Smarcel@subsubheading @value{GDBN} Command
17473130809Smarcel
17474130809SmarcelThe corresponding @value{GDBN} command is @samp{info symbol}.
17475130809Smarcel
17476130809Smarcel@subsubheading Example
17477130809SmarcelN.A.
17478130809Smarcel
17479130809Smarcel
17480130809Smarcel@subheading The @code{-symbol-list-functions} Command
17481130809Smarcel@findex -symbol-list-functions
17482130809Smarcel
17483130809Smarcel@subsubheading Synopsis
17484130809Smarcel
17485130809Smarcel@smallexample
17486130809Smarcel -symbol-list-functions
17487130809Smarcel@end smallexample
17488130809Smarcel
17489130809SmarcelList the functions in the executable.
17490130809Smarcel
17491130809Smarcel@subsubheading @value{GDBN} Command
17492130809Smarcel
17493130809Smarcel@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
17494130809Smarcel@samp{gdb_search} in @code{gdbtk}.
17495130809Smarcel
17496130809Smarcel@subsubheading Example
17497130809SmarcelN.A.
17498130809Smarcel
17499130809Smarcel
17500130809Smarcel@subheading The @code{-symbol-list-lines} Command
17501130809Smarcel@findex -symbol-list-lines
17502130809Smarcel
17503130809Smarcel@subsubheading Synopsis
17504130809Smarcel
17505130809Smarcel@smallexample
17506130809Smarcel -symbol-list-lines @var{filename}
17507130809Smarcel@end smallexample
17508130809Smarcel
17509130809SmarcelPrint the list of lines that contain code and their associated program
17510130809Smarceladdresses for the given source filename.  The entries are sorted in
17511130809Smarcelascending PC order.
17512130809Smarcel
17513130809Smarcel@subsubheading @value{GDBN} Command
17514130809Smarcel
17515130809SmarcelThere is no corresponding @value{GDBN} command.
17516130809Smarcel
17517130809Smarcel@subsubheading Example
17518130809Smarcel@smallexample
17519130809Smarcel(@value{GDBP})
17520130809Smarcel-symbol-list-lines basics.c
17521130809Smarcel^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
17522130809Smarcel(@value{GDBP})
17523130809Smarcel@end smallexample
17524130809Smarcel
17525130809Smarcel
17526130809Smarcel@subheading The @code{-symbol-list-types} Command
17527130809Smarcel@findex -symbol-list-types
17528130809Smarcel
17529130809Smarcel@subsubheading Synopsis
17530130809Smarcel
17531130809Smarcel@smallexample
17532130809Smarcel -symbol-list-types
17533130809Smarcel@end smallexample
17534130809Smarcel
17535130809SmarcelList all the type names.
17536130809Smarcel
17537130809Smarcel@subsubheading @value{GDBN} Command
17538130809Smarcel
17539130809SmarcelThe corresponding commands are @samp{info types} in @value{GDBN},
17540130809Smarcel@samp{gdb_search} in @code{gdbtk}.
17541130809Smarcel
17542130809Smarcel@subsubheading Example
17543130809SmarcelN.A.
17544130809Smarcel
17545130809Smarcel
17546130809Smarcel@subheading The @code{-symbol-list-variables} Command
17547130809Smarcel@findex -symbol-list-variables
17548130809Smarcel
17549130809Smarcel@subsubheading Synopsis
17550130809Smarcel
17551130809Smarcel@smallexample
17552130809Smarcel -symbol-list-variables
17553130809Smarcel@end smallexample
17554130809Smarcel
17555130809SmarcelList all the global and static variable names.
17556130809Smarcel
17557130809Smarcel@subsubheading @value{GDBN} Command
17558130809Smarcel
17559130809Smarcel@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
17560130809Smarcel
17561130809Smarcel@subsubheading Example
17562130809SmarcelN.A.
17563130809Smarcel
17564130809Smarcel
17565130809Smarcel@subheading The @code{-symbol-locate} Command
17566130809Smarcel@findex -symbol-locate
17567130809Smarcel
17568130809Smarcel@subsubheading Synopsis
17569130809Smarcel
17570130809Smarcel@smallexample
17571130809Smarcel -symbol-locate
17572130809Smarcel@end smallexample
17573130809Smarcel
17574130809Smarcel@subsubheading @value{GDBN} Command
17575130809Smarcel
17576130809Smarcel@samp{gdb_loc} in @code{gdbtk}.
17577130809Smarcel
17578130809Smarcel@subsubheading Example
17579130809SmarcelN.A.
17580130809Smarcel
17581130809Smarcel
17582130809Smarcel@subheading The @code{-symbol-type} Command
17583130809Smarcel@findex -symbol-type
17584130809Smarcel
17585130809Smarcel@subsubheading Synopsis
17586130809Smarcel
17587130809Smarcel@smallexample
17588130809Smarcel -symbol-type @var{variable}
17589130809Smarcel@end smallexample
17590130809Smarcel
17591130809SmarcelShow type of @var{variable}.
17592130809Smarcel
17593130809Smarcel@subsubheading @value{GDBN} Command
17594130809Smarcel
17595130809SmarcelThe corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
17596130809Smarcel@samp{gdb_obj_variable}.
17597130809Smarcel
17598130809Smarcel@subsubheading Example
17599130809SmarcelN.A.
17600130809Smarcel
17601130809Smarcel
17602130809Smarcel@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17603130809Smarcel@node GDB/MI Target Manipulation
17604130809Smarcel@section @sc{gdb/mi} Target Manipulation Commands
17605130809Smarcel
17606130809Smarcel
17607130809Smarcel@subheading The @code{-target-attach} Command
17608130809Smarcel@findex -target-attach
17609130809Smarcel
17610130809Smarcel@subsubheading Synopsis
17611130809Smarcel
17612130809Smarcel@smallexample
17613130809Smarcel -target-attach @var{pid} | @var{file}
17614130809Smarcel@end smallexample
17615130809Smarcel
17616130809SmarcelAttach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
17617130809Smarcel
17618130809Smarcel@subsubheading @value{GDBN} command
17619130809Smarcel
17620130809SmarcelThe corresponding @value{GDBN} command is @samp{attach}.
17621130809Smarcel
17622130809Smarcel@subsubheading Example
17623130809SmarcelN.A.
17624130809Smarcel
17625130809Smarcel
17626130809Smarcel@subheading The @code{-target-compare-sections} Command
17627130809Smarcel@findex -target-compare-sections
17628130809Smarcel
17629130809Smarcel@subsubheading Synopsis
17630130809Smarcel
17631130809Smarcel@smallexample
17632130809Smarcel -target-compare-sections [ @var{section} ]
17633130809Smarcel@end smallexample
17634130809Smarcel
17635130809SmarcelCompare data of section @var{section} on target to the exec file.
17636130809SmarcelWithout the argument, all sections are compared.
17637130809Smarcel
17638130809Smarcel@subsubheading @value{GDBN} Command
17639130809Smarcel
17640130809SmarcelThe @value{GDBN} equivalent is @samp{compare-sections}.
17641130809Smarcel
17642130809Smarcel@subsubheading Example
17643130809SmarcelN.A.
17644130809Smarcel
17645130809Smarcel
17646130809Smarcel@subheading The @code{-target-detach} Command
17647130809Smarcel@findex -target-detach
17648130809Smarcel
17649130809Smarcel@subsubheading Synopsis
17650130809Smarcel
17651130809Smarcel@smallexample
17652130809Smarcel -target-detach
17653130809Smarcel@end smallexample
17654130809Smarcel
17655130809SmarcelDisconnect from the remote target.  There's no output.
17656130809Smarcel
17657130809Smarcel@subsubheading @value{GDBN} command
17658130809Smarcel
17659130809SmarcelThe corresponding @value{GDBN} command is @samp{detach}.
17660130809Smarcel
17661130809Smarcel@subsubheading Example
17662130809Smarcel
17663130809Smarcel@smallexample
17664130809Smarcel(@value{GDBP})
17665130809Smarcel-target-detach
17666130809Smarcel^done
17667130809Smarcel(@value{GDBP})
17668130809Smarcel@end smallexample
17669130809Smarcel
17670130809Smarcel
17671130809Smarcel@subheading The @code{-target-disconnect} Command
17672130809Smarcel@findex -target-disconnect
17673130809Smarcel
17674130809Smarcel@subsubheading Synopsis
17675130809Smarcel
17676130809Smarcel@example
17677130809Smarcel -target-disconnect
17678130809Smarcel@end example
17679130809Smarcel
17680130809SmarcelDisconnect from the remote target.  There's no output.
17681130809Smarcel
17682130809Smarcel@subsubheading @value{GDBN} command
17683130809Smarcel
17684130809SmarcelThe corresponding @value{GDBN} command is @samp{disconnect}.
17685130809Smarcel
17686130809Smarcel@subsubheading Example
17687130809Smarcel
17688130809Smarcel@smallexample
17689130809Smarcel(@value{GDBP})
17690130809Smarcel-target-disconnect
17691130809Smarcel^done
17692130809Smarcel(@value{GDBP})
17693130809Smarcel@end smallexample
17694130809Smarcel
17695130809Smarcel
17696130809Smarcel@subheading The @code{-target-download} Command
17697130809Smarcel@findex -target-download
17698130809Smarcel
17699130809Smarcel@subsubheading Synopsis
17700130809Smarcel
17701130809Smarcel@smallexample
17702130809Smarcel -target-download
17703130809Smarcel@end smallexample
17704130809Smarcel
17705130809SmarcelLoads the executable onto the remote target.
17706130809SmarcelIt prints out an update message every half second, which includes the fields:
17707130809Smarcel
17708130809Smarcel@table @samp
17709130809Smarcel@item section
17710130809SmarcelThe name of the section.
17711130809Smarcel@item section-sent
17712130809SmarcelThe size of what has been sent so far for that section.
17713130809Smarcel@item section-size
17714130809SmarcelThe size of the section.
17715130809Smarcel@item total-sent
17716130809SmarcelThe total size of what was sent so far (the current and the previous sections).
17717130809Smarcel@item total-size
17718130809SmarcelThe size of the overall executable to download.
17719130809Smarcel@end table
17720130809Smarcel
17721130809Smarcel@noindent
17722130809SmarcelEach message is sent as status record (@pxref{GDB/MI Output Syntax, ,
17723130809Smarcel@sc{gdb/mi} Output Syntax}).
17724130809Smarcel
17725130809SmarcelIn addition, it prints the name and size of the sections, as they are
17726130809Smarceldownloaded.  These messages include the following fields:
17727130809Smarcel
17728130809Smarcel@table @samp
17729130809Smarcel@item section
17730130809SmarcelThe name of the section.
17731130809Smarcel@item section-size
17732130809SmarcelThe size of the section.
17733130809Smarcel@item total-size
17734130809SmarcelThe size of the overall executable to download.
17735130809Smarcel@end table
17736130809Smarcel
17737130809Smarcel@noindent
17738130809SmarcelAt the end, a summary is printed.
17739130809Smarcel
17740130809Smarcel@subsubheading @value{GDBN} Command
17741130809Smarcel
17742130809SmarcelThe corresponding @value{GDBN} command is @samp{load}.
17743130809Smarcel
17744130809Smarcel@subsubheading Example
17745130809Smarcel
17746130809SmarcelNote: each status message appears on a single line.  Here the messages
17747130809Smarcelhave been broken down so that they can fit onto a page.
17748130809Smarcel
17749130809Smarcel@smallexample
17750130809Smarcel(@value{GDBP})
17751130809Smarcel-target-download
17752130809Smarcel+download,@{section=".text",section-size="6668",total-size="9880"@}
17753130809Smarcel+download,@{section=".text",section-sent="512",section-size="6668",
17754130809Smarceltotal-sent="512",total-size="9880"@}
17755130809Smarcel+download,@{section=".text",section-sent="1024",section-size="6668",
17756130809Smarceltotal-sent="1024",total-size="9880"@}
17757130809Smarcel+download,@{section=".text",section-sent="1536",section-size="6668",
17758130809Smarceltotal-sent="1536",total-size="9880"@}
17759130809Smarcel+download,@{section=".text",section-sent="2048",section-size="6668",
17760130809Smarceltotal-sent="2048",total-size="9880"@}
17761130809Smarcel+download,@{section=".text",section-sent="2560",section-size="6668",
17762130809Smarceltotal-sent="2560",total-size="9880"@}
17763130809Smarcel+download,@{section=".text",section-sent="3072",section-size="6668",
17764130809Smarceltotal-sent="3072",total-size="9880"@}
17765130809Smarcel+download,@{section=".text",section-sent="3584",section-size="6668",
17766130809Smarceltotal-sent="3584",total-size="9880"@}
17767130809Smarcel+download,@{section=".text",section-sent="4096",section-size="6668",
17768130809Smarceltotal-sent="4096",total-size="9880"@}
17769130809Smarcel+download,@{section=".text",section-sent="4608",section-size="6668",
17770130809Smarceltotal-sent="4608",total-size="9880"@}
17771130809Smarcel+download,@{section=".text",section-sent="5120",section-size="6668",
17772130809Smarceltotal-sent="5120",total-size="9880"@}
17773130809Smarcel+download,@{section=".text",section-sent="5632",section-size="6668",
17774130809Smarceltotal-sent="5632",total-size="9880"@}
17775130809Smarcel+download,@{section=".text",section-sent="6144",section-size="6668",
17776130809Smarceltotal-sent="6144",total-size="9880"@}
17777130809Smarcel+download,@{section=".text",section-sent="6656",section-size="6668",
17778130809Smarceltotal-sent="6656",total-size="9880"@}
17779130809Smarcel+download,@{section=".init",section-size="28",total-size="9880"@}
17780130809Smarcel+download,@{section=".fini",section-size="28",total-size="9880"@}
17781130809Smarcel+download,@{section=".data",section-size="3156",total-size="9880"@}
17782130809Smarcel+download,@{section=".data",section-sent="512",section-size="3156",
17783130809Smarceltotal-sent="7236",total-size="9880"@}
17784130809Smarcel+download,@{section=".data",section-sent="1024",section-size="3156",
17785130809Smarceltotal-sent="7748",total-size="9880"@}
17786130809Smarcel+download,@{section=".data",section-sent="1536",section-size="3156",
17787130809Smarceltotal-sent="8260",total-size="9880"@}
17788130809Smarcel+download,@{section=".data",section-sent="2048",section-size="3156",
17789130809Smarceltotal-sent="8772",total-size="9880"@}
17790130809Smarcel+download,@{section=".data",section-sent="2560",section-size="3156",
17791130809Smarceltotal-sent="9284",total-size="9880"@}
17792130809Smarcel+download,@{section=".data",section-sent="3072",section-size="3156",
17793130809Smarceltotal-sent="9796",total-size="9880"@}
17794130809Smarcel^done,address="0x10004",load-size="9880",transfer-rate="6586",
17795130809Smarcelwrite-rate="429"
17796130809Smarcel(@value{GDBP})
17797130809Smarcel@end smallexample
17798130809Smarcel
17799130809Smarcel
17800130809Smarcel@subheading The @code{-target-exec-status} Command
17801130809Smarcel@findex -target-exec-status
17802130809Smarcel
17803130809Smarcel@subsubheading Synopsis
17804130809Smarcel
17805130809Smarcel@smallexample
17806130809Smarcel -target-exec-status
17807130809Smarcel@end smallexample
17808130809Smarcel
17809130809SmarcelProvide information on the state of the target (whether it is running or
17810130809Smarcelnot, for instance).
17811130809Smarcel
17812130809Smarcel@subsubheading @value{GDBN} Command
17813130809Smarcel
17814130809SmarcelThere's no equivalent @value{GDBN} command.
17815130809Smarcel
17816130809Smarcel@subsubheading Example
17817130809SmarcelN.A.
17818130809Smarcel
17819130809Smarcel
17820130809Smarcel@subheading The @code{-target-list-available-targets} Command
17821130809Smarcel@findex -target-list-available-targets
17822130809Smarcel
17823130809Smarcel@subsubheading Synopsis
17824130809Smarcel
17825130809Smarcel@smallexample
17826130809Smarcel -target-list-available-targets
17827130809Smarcel@end smallexample
17828130809Smarcel
17829130809SmarcelList the possible targets to connect to.
17830130809Smarcel
17831130809Smarcel@subsubheading @value{GDBN} Command
17832130809Smarcel
17833130809SmarcelThe corresponding @value{GDBN} command is @samp{help target}.
17834130809Smarcel
17835130809Smarcel@subsubheading Example
17836130809SmarcelN.A.
17837130809Smarcel
17838130809Smarcel
17839130809Smarcel@subheading The @code{-target-list-current-targets} Command
17840130809Smarcel@findex -target-list-current-targets
17841130809Smarcel
17842130809Smarcel@subsubheading Synopsis
17843130809Smarcel
17844130809Smarcel@smallexample
17845130809Smarcel -target-list-current-targets
17846130809Smarcel@end smallexample
17847130809Smarcel
17848130809SmarcelDescribe the current target.
17849130809Smarcel
17850130809Smarcel@subsubheading @value{GDBN} Command
17851130809Smarcel
17852130809SmarcelThe corresponding information is printed by @samp{info file} (among
17853130809Smarcelother things).
17854130809Smarcel
17855130809Smarcel@subsubheading Example
17856130809SmarcelN.A.
17857130809Smarcel
17858130809Smarcel
17859130809Smarcel@subheading The @code{-target-list-parameters} Command
17860130809Smarcel@findex -target-list-parameters
17861130809Smarcel
17862130809Smarcel@subsubheading Synopsis
17863130809Smarcel
17864130809Smarcel@smallexample
17865130809Smarcel -target-list-parameters
17866130809Smarcel@end smallexample
17867130809Smarcel
17868130809Smarcel@c ????
17869130809Smarcel
17870130809Smarcel@subsubheading @value{GDBN} Command
17871130809Smarcel
17872130809SmarcelNo equivalent.
17873130809Smarcel
17874130809Smarcel@subsubheading Example
17875130809SmarcelN.A.
17876130809Smarcel
17877130809Smarcel
17878130809Smarcel@subheading The @code{-target-select} Command
17879130809Smarcel@findex -target-select
17880130809Smarcel
17881130809Smarcel@subsubheading Synopsis
17882130809Smarcel
17883130809Smarcel@smallexample
17884130809Smarcel -target-select @var{type} @var{parameters @dots{}}
17885130809Smarcel@end smallexample
17886130809Smarcel
17887130809SmarcelConnect @value{GDBN} to the remote target.  This command takes two args:
17888130809Smarcel
17889130809Smarcel@table @samp
17890130809Smarcel@item @var{type}
17891130809SmarcelThe type of target, for instance @samp{async}, @samp{remote}, etc.
17892130809Smarcel@item @var{parameters}
17893130809SmarcelDevice names, host names and the like.  @xref{Target Commands, ,
17894130809SmarcelCommands for managing targets}, for more details.
17895130809Smarcel@end table
17896130809Smarcel
17897130809SmarcelThe output is a connection notification, followed by the address at
17898130809Smarcelwhich the target program is, in the following form:
17899130809Smarcel
17900130809Smarcel@smallexample
17901130809Smarcel^connected,addr="@var{address}",func="@var{function name}",
17902130809Smarcel  args=[@var{arg list}]
17903130809Smarcel@end smallexample
17904130809Smarcel
17905130809Smarcel@subsubheading @value{GDBN} Command
17906130809Smarcel
17907130809SmarcelThe corresponding @value{GDBN} command is @samp{target}.
17908130809Smarcel
17909130809Smarcel@subsubheading Example
17910130809Smarcel
17911130809Smarcel@smallexample
17912130809Smarcel(@value{GDBP})
17913130809Smarcel-target-select async /dev/ttya
17914130809Smarcel^connected,addr="0xfe00a300",func="??",args=[]
17915130809Smarcel(@value{GDBP})
17916130809Smarcel@end smallexample
17917130809Smarcel
17918130809Smarcel@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17919130809Smarcel@node GDB/MI Thread Commands
17920130809Smarcel@section @sc{gdb/mi} Thread Commands
17921130809Smarcel
17922130809Smarcel
17923130809Smarcel@subheading The @code{-thread-info} Command
17924130809Smarcel@findex -thread-info
17925130809Smarcel
17926130809Smarcel@subsubheading Synopsis
17927130809Smarcel
17928130809Smarcel@smallexample
17929130809Smarcel -thread-info
17930130809Smarcel@end smallexample
17931130809Smarcel
17932130809Smarcel@subsubheading @value{GDBN} command
17933130809Smarcel
17934130809SmarcelNo equivalent.
17935130809Smarcel
17936130809Smarcel@subsubheading Example
17937130809SmarcelN.A.
17938130809Smarcel
17939130809Smarcel
17940130809Smarcel@subheading The @code{-thread-list-all-threads} Command
17941130809Smarcel@findex -thread-list-all-threads
17942130809Smarcel
17943130809Smarcel@subsubheading Synopsis
17944130809Smarcel
17945130809Smarcel@smallexample
17946130809Smarcel -thread-list-all-threads
17947130809Smarcel@end smallexample
17948130809Smarcel
17949130809Smarcel@subsubheading @value{GDBN} Command
17950130809Smarcel
17951130809SmarcelThe equivalent @value{GDBN} command is @samp{info threads}.
17952130809Smarcel
17953130809Smarcel@subsubheading Example
17954130809SmarcelN.A.
17955130809Smarcel
17956130809Smarcel
17957130809Smarcel@subheading The @code{-thread-list-ids} Command
17958130809Smarcel@findex -thread-list-ids
17959130809Smarcel
17960130809Smarcel@subsubheading Synopsis
17961130809Smarcel
17962130809Smarcel@smallexample
17963130809Smarcel -thread-list-ids
17964130809Smarcel@end smallexample
17965130809Smarcel
17966130809SmarcelProduces a list of the currently known @value{GDBN} thread ids.  At the
17967130809Smarcelend of the list it also prints the total number of such threads.
17968130809Smarcel
17969130809Smarcel@subsubheading @value{GDBN} Command
17970130809Smarcel
17971130809SmarcelPart of @samp{info threads} supplies the same information.
17972130809Smarcel
17973130809Smarcel@subsubheading Example
17974130809Smarcel
17975130809SmarcelNo threads present, besides the main process:
17976130809Smarcel
17977130809Smarcel@smallexample
17978130809Smarcel(@value{GDBP})
17979130809Smarcel-thread-list-ids
17980130809Smarcel^done,thread-ids=@{@},number-of-threads="0"
17981130809Smarcel(@value{GDBP})
17982130809Smarcel@end smallexample
17983130809Smarcel
17984130809Smarcel
17985130809SmarcelSeveral threads:
17986130809Smarcel
17987130809Smarcel@smallexample
17988130809Smarcel(@value{GDBP})
17989130809Smarcel-thread-list-ids
17990130809Smarcel^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
17991130809Smarcelnumber-of-threads="3"
17992130809Smarcel(@value{GDBP})
17993130809Smarcel@end smallexample
17994130809Smarcel
17995130809Smarcel
17996130809Smarcel@subheading The @code{-thread-select} Command
17997130809Smarcel@findex -thread-select
17998130809Smarcel
17999130809Smarcel@subsubheading Synopsis
18000130809Smarcel
18001130809Smarcel@smallexample
18002130809Smarcel -thread-select @var{threadnum}
18003130809Smarcel@end smallexample
18004130809Smarcel
18005130809SmarcelMake @var{threadnum} the current thread.  It prints the number of the new
18006130809Smarcelcurrent thread, and the topmost frame for that thread.
18007130809Smarcel
18008130809Smarcel@subsubheading @value{GDBN} Command
18009130809Smarcel
18010130809SmarcelThe corresponding @value{GDBN} command is @samp{thread}.
18011130809Smarcel
18012130809Smarcel@subsubheading Example
18013130809Smarcel
18014130809Smarcel@smallexample
18015130809Smarcel(@value{GDBP})
18016130809Smarcel-exec-next
18017130809Smarcel^running
18018130809Smarcel(@value{GDBP})
18019130809Smarcel*stopped,reason="end-stepping-range",thread-id="2",line="187",
18020130809Smarcelfile="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
18021130809Smarcel(@value{GDBP})
18022130809Smarcel-thread-list-ids
18023130809Smarcel^done,
18024130809Smarcelthread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
18025130809Smarcelnumber-of-threads="3"
18026130809Smarcel(@value{GDBP})
18027130809Smarcel-thread-select 3
18028130809Smarcel^done,new-thread-id="3",
18029130809Smarcelframe=@{level="0",func="vprintf",
18030130809Smarcelargs=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
18031130809Smarcel@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
18032130809Smarcel(@value{GDBP})
18033130809Smarcel@end smallexample
18034130809Smarcel
18035130809Smarcel@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18036130809Smarcel@node GDB/MI Tracepoint Commands
18037130809Smarcel@section @sc{gdb/mi} Tracepoint Commands
18038130809Smarcel
18039130809SmarcelThe tracepoint commands are not yet implemented.
18040130809Smarcel
18041130809Smarcel@c @subheading -trace-actions
18042130809Smarcel
18043130809Smarcel@c @subheading -trace-delete
18044130809Smarcel
18045130809Smarcel@c @subheading -trace-disable
18046130809Smarcel
18047130809Smarcel@c @subheading -trace-dump
18048130809Smarcel
18049130809Smarcel@c @subheading -trace-enable
18050130809Smarcel
18051130809Smarcel@c @subheading -trace-exists
18052130809Smarcel
18053130809Smarcel@c @subheading -trace-find
18054130809Smarcel
18055130809Smarcel@c @subheading -trace-frame-number
18056130809Smarcel
18057130809Smarcel@c @subheading -trace-info
18058130809Smarcel
18059130809Smarcel@c @subheading -trace-insert
18060130809Smarcel
18061130809Smarcel@c @subheading -trace-list
18062130809Smarcel
18063130809Smarcel@c @subheading -trace-pass-count
18064130809Smarcel
18065130809Smarcel@c @subheading -trace-save
18066130809Smarcel
18067130809Smarcel@c @subheading -trace-start
18068130809Smarcel
18069130809Smarcel@c @subheading -trace-stop
18070130809Smarcel
18071130809Smarcel
18072130809Smarcel@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18073130809Smarcel@node GDB/MI Variable Objects
18074130809Smarcel@section @sc{gdb/mi} Variable Objects
18075130809Smarcel
18076130809Smarcel
18077130809Smarcel@subheading Motivation for Variable Objects in @sc{gdb/mi}
18078130809Smarcel
18079130809SmarcelFor the implementation of a variable debugger window (locals, watched
18080130809Smarcelexpressions, etc.), we are proposing the adaptation of the existing code
18081130809Smarcelused by @code{Insight}.
18082130809Smarcel
18083130809SmarcelThe two main reasons for that are:
18084130809Smarcel
18085130809Smarcel@enumerate 1
18086130809Smarcel@item
18087130809SmarcelIt has been proven in practice (it is already on its second generation).
18088130809Smarcel
18089130809Smarcel@item
18090130809SmarcelIt will shorten development time (needless to say how important it is
18091130809Smarcelnow).
18092130809Smarcel@end enumerate
18093130809Smarcel
18094130809SmarcelThe original interface was designed to be used by Tcl code, so it was
18095130809Smarcelslightly changed so it could be used through @sc{gdb/mi}.  This section
18096130809Smarceldescribes the @sc{gdb/mi} operations that will be available and gives some
18097130809Smarcelhints about their use.
18098130809Smarcel
18099130809Smarcel@emph{Note}: In addition to the set of operations described here, we
18100130809Smarcelexpect the @sc{gui} implementation of a variable window to require, at
18101130809Smarcelleast, the following operations:
18102130809Smarcel
18103130809Smarcel@itemize @bullet
18104130809Smarcel@item @code{-gdb-show} @code{output-radix}
18105130809Smarcel@item @code{-stack-list-arguments}
18106130809Smarcel@item @code{-stack-list-locals}
18107130809Smarcel@item @code{-stack-select-frame}
18108130809Smarcel@end itemize
18109130809Smarcel
18110130809Smarcel@subheading Introduction to Variable Objects in @sc{gdb/mi}
18111130809Smarcel
18112130809Smarcel@cindex variable objects in @sc{gdb/mi}
18113130809SmarcelThe basic idea behind variable objects is the creation of a named object
18114130809Smarcelto represent a variable, an expression, a memory location or even a CPU
18115130809Smarcelregister.  For each object created, a set of operations is available for
18116130809Smarcelexamining or changing its properties.
18117130809Smarcel
18118130809SmarcelFurthermore, complex data types, such as C structures, are represented
18119130809Smarcelin a tree format.  For instance, the @code{struct} type variable is the
18120130809Smarcelroot and the children will represent the struct members.  If a child
18121130809Smarcelis itself of a complex type, it will also have children of its own.
18122130809SmarcelAppropriate language differences are handled for C, C@t{++} and Java.
18123130809Smarcel
18124130809SmarcelWhen returning the actual values of the objects, this facility allows
18125130809Smarcelfor the individual selection of the display format used in the result
18126130809Smarcelcreation.  It can be chosen among: binary, decimal, hexadecimal, octal
18127130809Smarceland natural.  Natural refers to a default format automatically
18128130809Smarcelchosen based on the variable type (like decimal for an @code{int}, hex
18129130809Smarcelfor pointers, etc.).
18130130809Smarcel
18131130809SmarcelThe following is the complete set of @sc{gdb/mi} operations defined to
18132130809Smarcelaccess this functionality:
18133130809Smarcel
18134130809Smarcel@multitable @columnfractions .4 .6
18135130809Smarcel@item @strong{Operation}
18136130809Smarcel@tab @strong{Description}
18137130809Smarcel
18138130809Smarcel@item @code{-var-create}
18139130809Smarcel@tab create a variable object
18140130809Smarcel@item @code{-var-delete}
18141130809Smarcel@tab delete the variable object and its children
18142130809Smarcel@item @code{-var-set-format}
18143130809Smarcel@tab set the display format of this variable
18144130809Smarcel@item @code{-var-show-format}
18145130809Smarcel@tab show the display format of this variable
18146130809Smarcel@item @code{-var-info-num-children}
18147130809Smarcel@tab tells how many children this object has
18148130809Smarcel@item @code{-var-list-children}
18149130809Smarcel@tab return a list of the object's children
18150130809Smarcel@item @code{-var-info-type}
18151130809Smarcel@tab show the type of this variable object
18152130809Smarcel@item @code{-var-info-expression}
18153130809Smarcel@tab print what this variable object represents
18154130809Smarcel@item @code{-var-show-attributes}
18155130809Smarcel@tab is this variable editable? does it exist here?
18156130809Smarcel@item @code{-var-evaluate-expression}
18157130809Smarcel@tab get the value of this variable
18158130809Smarcel@item @code{-var-assign}
18159130809Smarcel@tab set the value of this variable
18160130809Smarcel@item @code{-var-update}
18161130809Smarcel@tab update the variable and its children
18162130809Smarcel@end multitable
18163130809Smarcel
18164130809SmarcelIn the next subsection we describe each operation in detail and suggest
18165130809Smarcelhow it can be used.
18166130809Smarcel
18167130809Smarcel@subheading Description And Use of Operations on Variable Objects
18168130809Smarcel
18169130809Smarcel@subheading The @code{-var-create} Command
18170130809Smarcel@findex -var-create
18171130809Smarcel
18172130809Smarcel@subsubheading Synopsis
18173130809Smarcel
18174130809Smarcel@smallexample
18175130809Smarcel -var-create @{@var{name} | "-"@}
18176130809Smarcel    @{@var{frame-addr} | "*"@} @var{expression}
18177130809Smarcel@end smallexample
18178130809Smarcel
18179130809SmarcelThis operation creates a variable object, which allows the monitoring of
18180130809Smarcela variable, the result of an expression, a memory cell or a CPU
18181130809Smarcelregister.
18182130809Smarcel
18183130809SmarcelThe @var{name} parameter is the string by which the object can be
18184130809Smarcelreferenced.  It must be unique.  If @samp{-} is specified, the varobj
18185130809Smarcelsystem will generate a string ``varNNNNNN'' automatically.  It will be
18186130809Smarcelunique provided that one does not specify @var{name} on that format.
18187130809SmarcelThe command fails if a duplicate name is found.
18188130809Smarcel
18189130809SmarcelThe frame under which the expression should be evaluated can be
18190130809Smarcelspecified by @var{frame-addr}.  A @samp{*} indicates that the current
18191130809Smarcelframe should be used.
18192130809Smarcel
18193130809Smarcel@var{expression} is any expression valid on the current language set (must not
18194130809Smarcelbegin with a @samp{*}), or one of the following:
18195130809Smarcel
18196130809Smarcel@itemize @bullet
18197130809Smarcel@item
18198130809Smarcel@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
18199130809Smarcel
18200130809Smarcel@item
18201130809Smarcel@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
18202130809Smarcel
18203130809Smarcel@item
18204130809Smarcel@samp{$@var{regname}} --- a CPU register name
18205130809Smarcel@end itemize
18206130809Smarcel
18207130809Smarcel@subsubheading Result
18208130809Smarcel
18209130809SmarcelThis operation returns the name, number of children and the type of the
18210130809Smarcelobject created.  Type is returned as a string as the ones generated by
18211130809Smarcelthe @value{GDBN} CLI:
18212130809Smarcel
18213130809Smarcel@smallexample
18214130809Smarcel name="@var{name}",numchild="N",type="@var{type}"
18215130809Smarcel@end smallexample
18216130809Smarcel
18217130809Smarcel
18218130809Smarcel@subheading The @code{-var-delete} Command
18219130809Smarcel@findex -var-delete
18220130809Smarcel
18221130809Smarcel@subsubheading Synopsis
18222130809Smarcel
18223130809Smarcel@smallexample
18224130809Smarcel -var-delete @var{name}
18225130809Smarcel@end smallexample
18226130809Smarcel
18227130809SmarcelDeletes a previously created variable object and all of its children.
18228130809Smarcel
18229130809SmarcelReturns an error if the object @var{name} is not found.
18230130809Smarcel
18231130809Smarcel
18232130809Smarcel@subheading The @code{-var-set-format} Command
18233130809Smarcel@findex -var-set-format
18234130809Smarcel
18235130809Smarcel@subsubheading Synopsis
18236130809Smarcel
18237130809Smarcel@smallexample
18238130809Smarcel -var-set-format @var{name} @var{format-spec}
18239130809Smarcel@end smallexample
18240130809Smarcel
18241130809SmarcelSets the output format for the value of the object @var{name} to be
18242130809Smarcel@var{format-spec}.
18243130809Smarcel
18244130809SmarcelThe syntax for the @var{format-spec} is as follows:
18245130809Smarcel
18246130809Smarcel@smallexample
18247130809Smarcel @var{format-spec} @expansion{}
18248130809Smarcel @{binary | decimal | hexadecimal | octal | natural@}
18249130809Smarcel@end smallexample
18250130809Smarcel
18251130809Smarcel
18252130809Smarcel@subheading The @code{-var-show-format} Command
18253130809Smarcel@findex -var-show-format
18254130809Smarcel
18255130809Smarcel@subsubheading Synopsis
18256130809Smarcel
18257130809Smarcel@smallexample
18258130809Smarcel -var-show-format @var{name}
18259130809Smarcel@end smallexample
18260130809Smarcel
18261130809SmarcelReturns the format used to display the value of the object @var{name}.
18262130809Smarcel
18263130809Smarcel@smallexample
18264130809Smarcel @var{format} @expansion{}
18265130809Smarcel @var{format-spec}
18266130809Smarcel@end smallexample
18267130809Smarcel
18268130809Smarcel
18269130809Smarcel@subheading The @code{-var-info-num-children} Command
18270130809Smarcel@findex -var-info-num-children
18271130809Smarcel
18272130809Smarcel@subsubheading Synopsis
18273130809Smarcel
18274130809Smarcel@smallexample
18275130809Smarcel -var-info-num-children @var{name}
18276130809Smarcel@end smallexample
18277130809Smarcel
18278130809SmarcelReturns the number of children of a variable object @var{name}:
18279130809Smarcel
18280130809Smarcel@smallexample
18281130809Smarcel numchild=@var{n}
18282130809Smarcel@end smallexample
18283130809Smarcel
18284130809Smarcel
18285130809Smarcel@subheading The @code{-var-list-children} Command
18286130809Smarcel@findex -var-list-children
18287130809Smarcel
18288130809Smarcel@subsubheading Synopsis
18289130809Smarcel
18290130809Smarcel@smallexample
18291130809Smarcel -var-list-children [@var{print-values}] @var{name}
18292130809Smarcel@end smallexample
18293130809Smarcel
18294130809SmarcelReturns a list of the children of the specified variable object.  With
18295130809Smarceljust the variable object name as an argument or with an optional
18296130809Smarcelpreceding argument of 0 or @code{--no-values}, prints only the names of the
18297130809Smarcelvariables.  With an optional preceding argument of 1 or @code{--all-values},
18298130809Smarcelalso prints their values.
18299130809Smarcel
18300130809Smarcel@subsubheading Example
18301130809Smarcel
18302130809Smarcel@smallexample
18303130809Smarcel(@value{GDBP})
18304130809Smarcel -var-list-children n
18305130809Smarcel numchild=@var{n},children=[@{name=@var{name},
18306130809Smarcel numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
18307130809Smarcel(@value{GDBP})
18308130809Smarcel -var-list-children --all-values n
18309130809Smarcel numchild=@var{n},children=[@{name=@var{name},
18310130809Smarcel numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
18311130809Smarcel@end smallexample
18312130809Smarcel
18313130809Smarcel
18314130809Smarcel@subheading The @code{-var-info-type} Command
18315130809Smarcel@findex -var-info-type
18316130809Smarcel
18317130809Smarcel@subsubheading Synopsis
18318130809Smarcel
18319130809Smarcel@smallexample
18320130809Smarcel -var-info-type @var{name}
18321130809Smarcel@end smallexample
18322130809Smarcel
18323130809SmarcelReturns the type of the specified variable @var{name}.  The type is
18324130809Smarcelreturned as a string in the same format as it is output by the
18325130809Smarcel@value{GDBN} CLI:
18326130809Smarcel
18327130809Smarcel@smallexample
18328130809Smarcel type=@var{typename}
18329130809Smarcel@end smallexample
18330130809Smarcel
18331130809Smarcel
18332130809Smarcel@subheading The @code{-var-info-expression} Command
18333130809Smarcel@findex -var-info-expression
18334130809Smarcel
18335130809Smarcel@subsubheading Synopsis
18336130809Smarcel
18337130809Smarcel@smallexample
18338130809Smarcel -var-info-expression @var{name}
18339130809Smarcel@end smallexample
18340130809Smarcel
18341130809SmarcelReturns what is represented by the variable object @var{name}:
18342130809Smarcel
18343130809Smarcel@smallexample
18344130809Smarcel lang=@var{lang-spec},exp=@var{expression}
18345130809Smarcel@end smallexample
18346130809Smarcel
18347130809Smarcel@noindent
18348130809Smarcelwhere @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
18349130809Smarcel
18350130809Smarcel@subheading The @code{-var-show-attributes} Command
18351130809Smarcel@findex -var-show-attributes
18352130809Smarcel
18353130809Smarcel@subsubheading Synopsis
18354130809Smarcel
18355130809Smarcel@smallexample
18356130809Smarcel -var-show-attributes @var{name}
18357130809Smarcel@end smallexample
18358130809Smarcel
18359130809SmarcelList attributes of the specified variable object @var{name}:
18360130809Smarcel
18361130809Smarcel@smallexample
18362130809Smarcel status=@var{attr} [ ( ,@var{attr} )* ]
18363130809Smarcel@end smallexample
18364130809Smarcel
18365130809Smarcel@noindent
18366130809Smarcelwhere @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
18367130809Smarcel
18368130809Smarcel@subheading The @code{-var-evaluate-expression} Command
18369130809Smarcel@findex -var-evaluate-expression
18370130809Smarcel
18371130809Smarcel@subsubheading Synopsis
18372130809Smarcel
18373130809Smarcel@smallexample
18374130809Smarcel -var-evaluate-expression @var{name}
18375130809Smarcel@end smallexample
18376130809Smarcel
18377130809SmarcelEvaluates the expression that is represented by the specified variable
18378130809Smarcelobject and returns its value as a string in the current format specified
18379130809Smarcelfor the object:
18380130809Smarcel
18381130809Smarcel@smallexample
18382130809Smarcel value=@var{value}
18383130809Smarcel@end smallexample
18384130809Smarcel
18385130809SmarcelNote that one must invoke @code{-var-list-children} for a variable
18386130809Smarcelbefore the value of a child variable can be evaluated.
18387130809Smarcel
18388130809Smarcel@subheading The @code{-var-assign} Command
18389130809Smarcel@findex -var-assign
18390130809Smarcel
18391130809Smarcel@subsubheading Synopsis
18392130809Smarcel
18393130809Smarcel@smallexample
18394130809Smarcel -var-assign @var{name} @var{expression}
18395130809Smarcel@end smallexample
18396130809Smarcel
18397130809SmarcelAssigns the value of @var{expression} to the variable object specified
18398130809Smarcelby @var{name}.  The object must be @samp{editable}.  If the variable's
18399130809Smarcelvalue is altered by the assign, the variable will show up in any
18400130809Smarcelsubsequent @code{-var-update} list.
18401130809Smarcel
18402130809Smarcel@subsubheading Example
18403130809Smarcel
18404130809Smarcel@smallexample
18405130809Smarcel(@value{GDBP})
18406130809Smarcel-var-assign var1 3
18407130809Smarcel^done,value="3"
18408130809Smarcel(@value{GDBP})
18409130809Smarcel-var-update *
18410130809Smarcel^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
18411130809Smarcel(@value{GDBP})
18412130809Smarcel@end smallexample
18413130809Smarcel
18414130809Smarcel@subheading The @code{-var-update} Command
18415130809Smarcel@findex -var-update
18416130809Smarcel
18417130809Smarcel@subsubheading Synopsis
18418130809Smarcel
18419130809Smarcel@smallexample
18420130809Smarcel -var-update @{@var{name} | "*"@}
18421130809Smarcel@end smallexample
18422130809Smarcel
18423130809SmarcelUpdate the value of the variable object @var{name} by evaluating its
18424130809Smarcelexpression after fetching all the new values from memory or registers.
18425130809SmarcelA @samp{*} causes all existing variable objects to be updated.
18426130809Smarcel
18427130809Smarcel
18428130809Smarcel@node Annotations
18429130809Smarcel@chapter @value{GDBN} Annotations
18430130809Smarcel
18431130809SmarcelThis chapter describes annotations in @value{GDBN}.  Annotations were
18432130809Smarceldesigned to interface @value{GDBN} to graphical user interfaces or other
18433130809Smarcelsimilar programs which want to interact with @value{GDBN} at a
18434130809Smarcelrelatively high level.
18435130809Smarcel
18436130809SmarcelThe annotation mechanism has largely been superseeded by @sc{gdb/mi}
18437130809Smarcel(@pxref{GDB/MI}).
18438130809Smarcel
18439130809Smarcel@ignore
18440130809SmarcelThis is Edition @value{EDITION}, @value{DATE}.
18441130809Smarcel@end ignore
18442130809Smarcel
18443130809Smarcel@menu
18444130809Smarcel* Annotations Overview::  What annotations are; the general syntax.
18445130809Smarcel* Server Prefix::       Issuing a command without affecting user state.
18446130809Smarcel* Prompting::           Annotations marking @value{GDBN}'s need for input.
18447130809Smarcel* Errors::              Annotations for error messages.
18448130809Smarcel* Invalidation::        Some annotations describe things now invalid.
18449130809Smarcel* Annotations for Running::
18450130809Smarcel                        Whether the program is running, how it stopped, etc.
18451130809Smarcel* Source Annotations::  Annotations describing source code.
18452130809Smarcel@end menu
18453130809Smarcel
18454130809Smarcel@node Annotations Overview
18455130809Smarcel@section What is an Annotation?
18456130809Smarcel@cindex annotations
18457130809Smarcel
18458130809SmarcelAnnotations start with a newline character, two @samp{control-z}
18459130809Smarcelcharacters, and the name of the annotation.  If there is no additional
18460130809Smarcelinformation associated with this annotation, the name of the annotation
18461130809Smarcelis followed immediately by a newline.  If there is additional
18462130809Smarcelinformation, the name of the annotation is followed by a space, the
18463130809Smarceladditional information, and a newline.  The additional information
18464130809Smarcelcannot contain newline characters.
18465130809Smarcel
18466130809SmarcelAny output not beginning with a newline and two @samp{control-z}
18467130809Smarcelcharacters denotes literal output from @value{GDBN}.  Currently there is
18468130809Smarcelno need for @value{GDBN} to output a newline followed by two
18469130809Smarcel@samp{control-z} characters, but if there was such a need, the
18470130809Smarcelannotations could be extended with an @samp{escape} annotation which
18471130809Smarcelmeans those three characters as output.
18472130809Smarcel
18473130809SmarcelThe annotation @var{level}, which is specified using the
18474130809Smarcel@option{--annotate} command line option (@pxref{Mode Options}), controls
18475130809Smarcelhow much information @value{GDBN} prints together with its prompt,
18476130809Smarcelvalues of expressions, source lines, and other types of output.  Level 0
18477130809Smarcelis for no anntations, level 1 is for use when @value{GDBN} is run as a
18478130809Smarcelsubprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
18479130809Smarcelfor programs that control @value{GDBN}, and level 2 annotations have
18480130809Smarcelbeen made obsolete (@pxref{Limitations, , Limitations of the Annotation
18481130809SmarcelInterface, annotate, GDB's Obsolete Annotations}).  This chapter
18482130809Smarceldescribes level 3 annotations.
18483130809Smarcel
18484130809SmarcelA simple example of starting up @value{GDBN} with annotations is:
18485130809Smarcel
18486130809Smarcel@smallexample
18487130809Smarcel$ @kbd{gdb --annotate=3}
18488130809SmarcelGNU gdb 6.0
18489130809SmarcelCopyright 2003 Free Software Foundation, Inc.
18490130809SmarcelGDB is free software, covered by the GNU General Public License,
18491130809Smarceland you are welcome to change it and/or distribute copies of it
18492130809Smarcelunder certain conditions.
18493130809SmarcelType "show copying" to see the conditions.
18494130809SmarcelThere is absolutely no warranty for GDB.  Type "show warranty"
18495130809Smarcelfor details.
18496130809SmarcelThis GDB was configured as "i386-pc-linux-gnu"
18497130809Smarcel
18498130809Smarcel^Z^Zpre-prompt
18499130809Smarcel(gdb)
18500130809Smarcel^Z^Zprompt
18501130809Smarcel@kbd{quit}
18502130809Smarcel
18503130809Smarcel^Z^Zpost-prompt
18504130809Smarcel$
18505130809Smarcel@end smallexample
18506130809Smarcel
18507130809SmarcelHere @samp{quit} is input to @value{GDBN}; the rest is output from
18508130809Smarcel@value{GDBN}.  The three lines beginning @samp{^Z^Z} (where @samp{^Z}
18509130809Smarceldenotes a @samp{control-z} character) are annotations; the rest is
18510130809Smarceloutput from @value{GDBN}.
18511130809Smarcel
18512130809Smarcel@node Server Prefix
18513130809Smarcel@section The Server Prefix
18514130809Smarcel@cindex server prefix for annotations
18515130809Smarcel
18516130809SmarcelTo issue a command to @value{GDBN} without affecting certain aspects of
18517130809Smarcelthe state which is seen by users, prefix it with @samp{server }.  This
18518130809Smarcelmeans that this command will not affect the command history, nor will it
18519130809Smarcelaffect @value{GDBN}'s notion of which command to repeat if @key{RET} is
18520130809Smarcelpressed on a line by itself.
18521130809Smarcel
18522130809SmarcelThe server prefix does not affect the recording of values into the value
18523130809Smarcelhistory; to print a value without recording it into the value history,
18524130809Smarceluse the @code{output} command instead of the @code{print} command.
18525130809Smarcel
18526130809Smarcel@node Prompting
18527130809Smarcel@section Annotation for @value{GDBN} Input
18528130809Smarcel
18529130809Smarcel@cindex annotations for prompts
18530130809SmarcelWhen @value{GDBN} prompts for input, it annotates this fact so it is possible
18531130809Smarcelto know when to send output, when the output from a given command is
18532130809Smarcelover, etc.
18533130809Smarcel
18534130809SmarcelDifferent kinds of input each have a different @dfn{input type}.  Each
18535130809Smarcelinput type has three annotations: a @code{pre-} annotation, which
18536130809Smarceldenotes the beginning of any prompt which is being output, a plain
18537130809Smarcelannotation, which denotes the end of the prompt, and then a @code{post-}
18538130809Smarcelannotation which denotes the end of any echo which may (or may not) be
18539130809Smarcelassociated with the input.  For example, the @code{prompt} input type
18540130809Smarcelfeatures the following annotations:
18541130809Smarcel
18542130809Smarcel@smallexample
18543130809Smarcel^Z^Zpre-prompt
18544130809Smarcel^Z^Zprompt
18545130809Smarcel^Z^Zpost-prompt
18546130809Smarcel@end smallexample
18547130809Smarcel
18548130809SmarcelThe input types are
18549130809Smarcel
18550130809Smarcel@table @code
18551130809Smarcel@findex pre-prompt
18552130809Smarcel@findex prompt
18553130809Smarcel@findex post-prompt
18554130809Smarcel@item prompt
18555130809SmarcelWhen @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
18556130809Smarcel
18557130809Smarcel@findex pre-commands
18558130809Smarcel@findex commands
18559130809Smarcel@findex post-commands
18560130809Smarcel@item commands
18561130809SmarcelWhen @value{GDBN} prompts for a set of commands, like in the @code{commands}
18562130809Smarcelcommand.  The annotations are repeated for each command which is input.
18563130809Smarcel
18564130809Smarcel@findex pre-overload-choice
18565130809Smarcel@findex overload-choice
18566130809Smarcel@findex post-overload-choice
18567130809Smarcel@item overload-choice
18568130809SmarcelWhen @value{GDBN} wants the user to select between various overloaded functions.
18569130809Smarcel
18570130809Smarcel@findex pre-query
18571130809Smarcel@findex query
18572130809Smarcel@findex post-query
18573130809Smarcel@item query
18574130809SmarcelWhen @value{GDBN} wants the user to confirm a potentially dangerous operation.
18575130809Smarcel
18576130809Smarcel@findex pre-prompt-for-continue
18577130809Smarcel@findex prompt-for-continue
18578130809Smarcel@findex post-prompt-for-continue
18579130809Smarcel@item prompt-for-continue
18580130809SmarcelWhen @value{GDBN} is asking the user to press return to continue.  Note: Don't
18581130809Smarcelexpect this to work well; instead use @code{set height 0} to disable
18582130809Smarcelprompting.  This is because the counting of lines is buggy in the
18583130809Smarcelpresence of annotations.
18584130809Smarcel@end table
18585130809Smarcel
18586130809Smarcel@node Errors
18587130809Smarcel@section Errors
18588130809Smarcel@cindex annotations for errors, warnings and interrupts
18589130809Smarcel
18590130809Smarcel@findex quit
18591130809Smarcel@smallexample
18592130809Smarcel^Z^Zquit
18593130809Smarcel@end smallexample
18594130809Smarcel
18595130809SmarcelThis annotation occurs right before @value{GDBN} responds to an interrupt.
18596130809Smarcel
18597130809Smarcel@findex error
18598130809Smarcel@smallexample
18599130809Smarcel^Z^Zerror
18600130809Smarcel@end smallexample
18601130809Smarcel
18602130809SmarcelThis annotation occurs right before @value{GDBN} responds to an error.
18603130809Smarcel
18604130809SmarcelQuit and error annotations indicate that any annotations which @value{GDBN} was
18605130809Smarcelin the middle of may end abruptly.  For example, if a
18606130809Smarcel@code{value-history-begin} annotation is followed by a @code{error}, one
18607130809Smarcelcannot expect to receive the matching @code{value-history-end}.  One
18608130809Smarcelcannot expect not to receive it either, however; an error annotation
18609130809Smarceldoes not necessarily mean that @value{GDBN} is immediately returning all the way
18610130809Smarcelto the top level.
18611130809Smarcel
18612130809Smarcel@findex error-begin
18613130809SmarcelA quit or error annotation may be preceded by
18614130809Smarcel
18615130809Smarcel@smallexample
18616130809Smarcel^Z^Zerror-begin
18617130809Smarcel@end smallexample
18618130809Smarcel
18619130809SmarcelAny output between that and the quit or error annotation is the error
18620130809Smarcelmessage.
18621130809Smarcel
18622130809SmarcelWarning messages are not yet annotated.
18623130809Smarcel@c If we want to change that, need to fix warning(), type_error(),
18624130809Smarcel@c range_error(), and possibly other places.
18625130809Smarcel
18626130809Smarcel@node Invalidation
18627130809Smarcel@section Invalidation Notices
18628130809Smarcel
18629130809Smarcel@cindex annotations for invalidation messages
18630130809SmarcelThe following annotations say that certain pieces of state may have
18631130809Smarcelchanged.
18632130809Smarcel
18633130809Smarcel@table @code
18634130809Smarcel@findex frames-invalid
18635130809Smarcel@item ^Z^Zframes-invalid
18636130809Smarcel
18637130809SmarcelThe frames (for example, output from the @code{backtrace} command) may
18638130809Smarcelhave changed.
18639130809Smarcel
18640130809Smarcel@findex breakpoints-invalid
18641130809Smarcel@item ^Z^Zbreakpoints-invalid
18642130809Smarcel
18643130809SmarcelThe breakpoints may have changed.  For example, the user just added or
18644130809Smarceldeleted a breakpoint.
18645130809Smarcel@end table
18646130809Smarcel
18647130809Smarcel@node Annotations for Running
18648130809Smarcel@section Running the Program
18649130809Smarcel@cindex annotations for running programs
18650130809Smarcel
18651130809Smarcel@findex starting
18652130809Smarcel@findex stopping
18653130809SmarcelWhen the program starts executing due to a @value{GDBN} command such as
18654130809Smarcel@code{step} or @code{continue},
18655130809Smarcel
18656130809Smarcel@smallexample
18657130809Smarcel^Z^Zstarting
18658130809Smarcel@end smallexample
18659130809Smarcel
18660130809Smarcelis output.  When the program stops,
18661130809Smarcel
18662130809Smarcel@smallexample
18663130809Smarcel^Z^Zstopped
18664130809Smarcel@end smallexample
18665130809Smarcel
18666130809Smarcelis output.  Before the @code{stopped} annotation, a variety of
18667130809Smarcelannotations describe how the program stopped.
18668130809Smarcel
18669130809Smarcel@table @code
18670130809Smarcel@findex exited
18671130809Smarcel@item ^Z^Zexited @var{exit-status}
18672130809SmarcelThe program exited, and @var{exit-status} is the exit status (zero for
18673130809Smarcelsuccessful exit, otherwise nonzero).
18674130809Smarcel
18675130809Smarcel@findex signalled
18676130809Smarcel@findex signal-name
18677130809Smarcel@findex signal-name-end
18678130809Smarcel@findex signal-string
18679130809Smarcel@findex signal-string-end
18680130809Smarcel@item ^Z^Zsignalled
18681130809SmarcelThe program exited with a signal.  After the @code{^Z^Zsignalled}, the
18682130809Smarcelannotation continues:
18683130809Smarcel
18684130809Smarcel@smallexample
18685130809Smarcel@var{intro-text}
18686130809Smarcel^Z^Zsignal-name
18687130809Smarcel@var{name}
18688130809Smarcel^Z^Zsignal-name-end
18689130809Smarcel@var{middle-text}
18690130809Smarcel^Z^Zsignal-string
18691130809Smarcel@var{string}
18692130809Smarcel^Z^Zsignal-string-end
18693130809Smarcel@var{end-text}
18694130809Smarcel@end smallexample
18695130809Smarcel
18696130809Smarcel@noindent
18697130809Smarcelwhere @var{name} is the name of the signal, such as @code{SIGILL} or
18698130809Smarcel@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
18699130809Smarcelas @code{Illegal Instruction} or @code{Segmentation fault}.
18700130809Smarcel@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
18701130809Smarceluser's benefit and have no particular format.
18702130809Smarcel
18703130809Smarcel@findex signal
18704130809Smarcel@item ^Z^Zsignal
18705130809SmarcelThe syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
18706130809Smarceljust saying that the program received the signal, not that it was
18707130809Smarcelterminated with it.
18708130809Smarcel
18709130809Smarcel@findex breakpoint
18710130809Smarcel@item ^Z^Zbreakpoint @var{number}
18711130809SmarcelThe program hit breakpoint number @var{number}.
18712130809Smarcel
18713130809Smarcel@findex watchpoint
18714130809Smarcel@item ^Z^Zwatchpoint @var{number}
18715130809SmarcelThe program hit watchpoint number @var{number}.
18716130809Smarcel@end table
18717130809Smarcel
18718130809Smarcel@node Source Annotations
18719130809Smarcel@section Displaying Source
18720130809Smarcel@cindex annotations for source display
18721130809Smarcel
18722130809Smarcel@findex source
18723130809SmarcelThe following annotation is used instead of displaying source code:
18724130809Smarcel
18725130809Smarcel@smallexample
18726130809Smarcel^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
18727130809Smarcel@end smallexample
18728130809Smarcel
18729130809Smarcelwhere @var{filename} is an absolute file name indicating which source
18730130809Smarcelfile, @var{line} is the line number within that file (where 1 is the
18731130809Smarcelfirst line in the file), @var{character} is the character position
18732130809Smarcelwithin the file (where 0 is the first character in the file) (for most
18733130809Smarceldebug formats this will necessarily point to the beginning of a line),
18734130809Smarcel@var{middle} is @samp{middle} if @var{addr} is in the middle of the
18735130809Smarcelline, or @samp{beg} if @var{addr} is at the beginning of the line, and
18736130809Smarcel@var{addr} is the address in the target program associated with the
18737130809Smarcelsource which is being displayed.  @var{addr} is in the form @samp{0x}
18738130809Smarcelfollowed by one or more lowercase hex digits (note that this does not
18739130809Smarceldepend on the language).
18740130809Smarcel
1874119370Spst@node GDB Bugs
1874219370Spst@chapter Reporting Bugs in @value{GDBN}
1874319370Spst@cindex bugs in @value{GDBN}
1874419370Spst@cindex reporting bugs in @value{GDBN}
1874519370Spst
1874619370SpstYour bug reports play an essential role in making @value{GDBN} reliable.
1874719370Spst
1874819370SpstReporting a bug may help you by bringing a solution to your problem, or it
1874919370Spstmay not.  But in any case the principal function of a bug report is to help
1875019370Spstthe entire community by making the next version of @value{GDBN} work better.  Bug
1875119370Spstreports are your contribution to the maintenance of @value{GDBN}.
1875219370Spst
1875319370SpstIn order for a bug report to serve its purpose, you must include the
1875419370Spstinformation that enables us to fix the bug.
1875519370Spst
1875619370Spst@menu
1875719370Spst* Bug Criteria::                Have you found a bug?
1875819370Spst* Bug Reporting::               How to report bugs
1875919370Spst@end menu
1876019370Spst
1876198948Sobrien@node Bug Criteria
1876219370Spst@section Have you found a bug?
1876319370Spst@cindex bug criteria
1876419370Spst
1876519370SpstIf you are not sure whether you have found a bug, here are some guidelines:
1876619370Spst
1876719370Spst@itemize @bullet
1876819370Spst@cindex fatal signal
1876919370Spst@cindex debugger crash
1877019370Spst@cindex crash of debugger
1877119370Spst@item
1877219370SpstIf the debugger gets a fatal signal, for any input whatever, that is a
1877319370Spst@value{GDBN} bug.  Reliable debuggers never crash.
1877419370Spst
1877519370Spst@cindex error on valid input
1877619370Spst@item
1877746289SdfrIf @value{GDBN} produces an error message for valid input, that is a
1877846289Sdfrbug.  (Note that if you're cross debugging, the problem may also be
1877946289Sdfrsomewhere in the connection to the target.)
1878019370Spst
1878119370Spst@cindex invalid input
1878219370Spst@item
1878319370SpstIf @value{GDBN} does not produce an error message for invalid input,
1878419370Spstthat is a bug.  However, you should note that your idea of
1878519370Spst``invalid input'' might be our idea of ``an extension'' or ``support
1878619370Spstfor traditional practice''.
1878719370Spst
1878819370Spst@item
1878919370SpstIf you are an experienced user of debugging tools, your suggestions
1879019370Spstfor improvement of @value{GDBN} are welcome in any case.
1879119370Spst@end itemize
1879219370Spst
1879398948Sobrien@node Bug Reporting
1879419370Spst@section How to report bugs
1879519370Spst@cindex bug reports
1879619370Spst@cindex @value{GDBN} bugs, reporting
1879719370Spst
1879819370SpstA number of companies and individuals offer support for @sc{gnu} products.
1879919370SpstIf you obtained @value{GDBN} from a support organization, we recommend you
1880019370Spstcontact that organization first.
1880119370Spst
1880219370SpstYou can find contact information for many support companies and
1880319370Spstindividuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
1880419370Spstdistribution.
1880546289Sdfr@c should add a web page ref...
1880619370Spst
1880798948SobrienIn any event, we also recommend that you submit bug reports for
1880898948Sobrien@value{GDBN}.  The prefered method is to submit them directly using
1880998948Sobrien@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
1881098948Sobrienpage}.  Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
1881198948Sobrienbe used.
1881219370Spst
1881319370Spst@strong{Do not send bug reports to @samp{info-gdb}, or to
1881498948Sobrien@samp{help-gdb}, or to any newsgroups.}  Most users of @value{GDBN} do
1881546289Sdfrnot want to receive bug reports.  Those that do have arranged to receive
1881646289Sdfr@samp{bug-gdb}.
1881719370Spst
1881819370SpstThe mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
1881919370Spstserves as a repeater.  The mailing list and the newsgroup carry exactly
1882019370Spstthe same messages.  Often people think of posting bug reports to the
1882119370Spstnewsgroup instead of mailing them.  This appears to work, but it has one
1882219370Spstproblem which can be crucial: a newsgroup posting often lacks a mail
1882319370Spstpath back to the sender.  Thus, if we need to ask for more information,
1882419370Spstwe may be unable to reach you.  For this reason, it is better to send
1882519370Spstbug reports to the mailing list.
1882619370Spst
1882719370SpstThe fundamental principle of reporting bugs usefully is this:
1882819370Spst@strong{report all the facts}.  If you are not sure whether to state a
1882919370Spstfact or leave it out, state it!
1883019370Spst
1883119370SpstOften people omit facts because they think they know what causes the
1883219370Spstproblem and assume that some details do not matter.  Thus, you might
1883319370Spstassume that the name of the variable you use in an example does not matter.
1883419370SpstWell, probably it does not, but one cannot be sure.  Perhaps the bug is a
1883519370Spststray memory reference which happens to fetch from the location where that
1883619370Spstname is stored in memory; perhaps, if the name were different, the contents
1883719370Spstof that location would fool the debugger into doing the right thing despite
1883819370Spstthe bug.  Play it safe and give a specific, complete example.  That is the
1883919370Spsteasiest thing for you to do, and the most helpful.
1884019370Spst
1884146289SdfrKeep in mind that the purpose of a bug report is to enable us to fix the
1884246289Sdfrbug.  It may be that the bug has been reported previously, but neither
1884346289Sdfryou nor we can know that unless your bug report is complete and
1884446289Sdfrself-contained.
1884519370Spst
1884619370SpstSometimes people give a few sketchy facts and ask, ``Does this ring a
1884719370Spstbell?''  Those bug reports are useless, and we urge everyone to
1884819370Spst@emph{refuse to respond to them} except to chide the sender to report
1884919370Spstbugs properly.
1885019370Spst
1885119370SpstTo enable us to fix the bug, you should include all these things:
1885219370Spst
1885319370Spst@itemize @bullet
1885419370Spst@item
1885546289SdfrThe version of @value{GDBN}.  @value{GDBN} announces it if you start
1885646289Sdfrwith no arguments; you can also print it at any time using @code{show
1885746289Sdfrversion}.
1885819370Spst
1885919370SpstWithout this, we will not know whether there is any point in looking for
1886019370Spstthe bug in the current version of @value{GDBN}.
1886119370Spst
1886219370Spst@item
1886319370SpstThe type of machine you are using, and the operating system name and
1886419370Spstversion number.
1886519370Spst
1886619370Spst@item
1886719370SpstWhat compiler (and its version) was used to compile @value{GDBN}---e.g.
1886846289Sdfr``@value{GCC}--2.8.1''.
1886919370Spst
1887019370Spst@item
1887146289SdfrWhat compiler (and its version) was used to compile the program you are
1887246289Sdfrdebugging---e.g.  ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
1887346289SdfrC Compiler''.  For GCC, you can say @code{gcc --version} to get this
1887446289Sdfrinformation; for other compilers, see the documentation for those
1887546289Sdfrcompilers.
1887619370Spst
1887719370Spst@item
1887819370SpstThe command arguments you gave the compiler to compile your example and
1887919370Spstobserve the bug.  For example, did you use @samp{-O}?  To guarantee
1888019370Spstyou will not omit something important, list them all.  A copy of the
1888119370SpstMakefile (or the output from make) is sufficient.
1888219370Spst
1888319370SpstIf we were to try to guess the arguments, we would probably guess wrong
1888419370Spstand then we might not encounter the bug.
1888519370Spst
1888619370Spst@item
1888719370SpstA complete input script, and all necessary source files, that will
1888819370Spstreproduce the bug.
1888919370Spst
1889019370Spst@item
1889119370SpstA description of what behavior you observe that you believe is
1889219370Spstincorrect.  For example, ``It gets a fatal signal.''
1889319370Spst
1889446289SdfrOf course, if the bug is that @value{GDBN} gets a fatal signal, then we
1889546289Sdfrwill certainly notice it.  But if the bug is incorrect output, we might
1889646289Sdfrnot notice unless it is glaringly wrong.  You might as well not give us
1889746289Sdfra chance to make a mistake.
1889819370Spst
1889919370SpstEven if the problem you experience is a fatal signal, you should still
1890046289Sdfrsay so explicitly.  Suppose something strange is going on, such as, your
1890146289Sdfrcopy of @value{GDBN} is out of synch, or you have encountered a bug in
1890246289Sdfrthe C library on your system.  (This has happened!)  Your copy might
1890346289Sdfrcrash and ours would not.  If you told us to expect a crash, then when
1890446289Sdfrours fails to crash, we would know that the bug was not happening for
1890546289Sdfrus.  If you had not told us to expect a crash, then we would not be able
1890646289Sdfrto draw any conclusion from our observations.
1890719370Spst
1890819370Spst@item
1890919370SpstIf you wish to suggest changes to the @value{GDBN} source, send us context
1891019370Spstdiffs.  If you even discuss something in the @value{GDBN} source, refer to
1891119370Spstit by context, not by line number.
1891219370Spst
1891319370SpstThe line numbers in our development sources will not match those in your
1891419370Spstsources.  Your line numbers would convey no useful information to us.
1891598948Sobrien
1891619370Spst@end itemize
1891719370Spst
1891819370SpstHere are some things that are not necessary:
1891919370Spst
1892019370Spst@itemize @bullet
1892119370Spst@item
1892219370SpstA description of the envelope of the bug.
1892319370Spst
1892419370SpstOften people who encounter a bug spend a lot of time investigating
1892519370Spstwhich changes to the input file will make the bug go away and which
1892619370Spstchanges will not affect it.
1892719370Spst
1892819370SpstThis is often time consuming and not very useful, because the way we
1892919370Spstwill find the bug is by running a single example under the debugger
1893019370Spstwith breakpoints, not by pure deduction from a series of examples.
1893119370SpstWe recommend that you save your time for something else.
1893219370Spst
1893319370SpstOf course, if you can find a simpler example to report @emph{instead}
1893419370Spstof the original one, that is a convenience for us.  Errors in the
1893519370Spstoutput will be easier to spot, running under the debugger will take
1893619370Spstless time, and so on.
1893719370Spst
1893819370SpstHowever, simplification is not vital; if you do not want to do this,
1893919370Spstreport the bug anyway and send us the entire test case you used.
1894019370Spst
1894119370Spst@item
1894219370SpstA patch for the bug.
1894319370Spst
1894419370SpstA patch for the bug does help us if it is a good one.  But do not omit
1894519370Spstthe necessary information, such as the test case, on the assumption that
1894619370Spsta patch is all we need.  We might see problems with your patch and decide
1894719370Spstto fix the problem another way, or we might not understand it at all.
1894819370Spst
1894919370SpstSometimes with a program as complicated as @value{GDBN} it is very hard to
1895019370Spstconstruct an example that will make the program follow a certain path
1895119370Spstthrough the code.  If you do not send us the example, we will not be able
1895219370Spstto construct one, so we will not be able to verify that the bug is fixed.
1895319370Spst
1895419370SpstAnd if we cannot understand what bug you are trying to fix, or why your
1895519370Spstpatch should be an improvement, we will not install it.  A test case will
1895619370Spsthelp us to understand.
1895719370Spst
1895819370Spst@item
1895919370SpstA guess about what the bug is or what it depends on.
1896019370Spst
1896119370SpstSuch guesses are usually wrong.  Even we cannot guess right about such
1896219370Spstthings without first using the debugger to find the facts.
1896319370Spst@end itemize
1896419370Spst
1896598948Sobrien@c The readline documentation is distributed with the readline code
1896619370Spst@c and consists of the two following files:
1896719370Spst@c     rluser.texinfo
1896898948Sobrien@c     inc-hist.texinfo
1896919370Spst@c Use -I with makeinfo to point to the appropriate directory,
1897019370Spst@c environment var TEXINPUTS with TeX.
1897119370Spst@include rluser.texinfo
1897298948Sobrien@include inc-hist.texinfo
1897319370Spst
1897419370Spst
1897519370Spst@node Formatting Documentation
1897619370Spst@appendix Formatting Documentation
1897719370Spst
1897819370Spst@cindex @value{GDBN} reference card
1897919370Spst@cindex reference card
1898019370SpstThe @value{GDBN} 4 release includes an already-formatted reference card, ready
1898119370Spstfor printing with PostScript or Ghostscript, in the @file{gdb}
1898219370Spstsubdirectory of the main source directory@footnote{In
1898319370Spst@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
1898419370Spstrelease.}.  If you can use PostScript or Ghostscript with your printer,
1898519370Spstyou can print the reference card immediately with @file{refcard.ps}.
1898619370Spst
1898719370SpstThe release also includes the source for the reference card.  You
1898819370Spstcan format it, using @TeX{}, by typing:
1898919370Spst
18990130809Smarcel@smallexample
1899119370Spstmake refcard.dvi
18992130809Smarcel@end smallexample
1899319370Spst
1899498948SobrienThe @value{GDBN} reference card is designed to print in @dfn{landscape}
1899598948Sobrienmode on US ``letter'' size paper;
1899619370Spstthat is, on a sheet 11 inches wide by 8.5 inches
1899719370Spsthigh.  You will need to specify this form of printing as an option to
1899819370Spstyour @sc{dvi} output program.
1899919370Spst
1900019370Spst@cindex documentation
1900119370Spst
1900219370SpstAll the documentation for @value{GDBN} comes as part of the machine-readable
1900319370Spstdistribution.  The documentation is written in Texinfo format, which is
1900419370Spsta documentation system that uses a single source file to produce both
1900519370Spston-line information and a printed manual.  You can use one of the Info
1900619370Spstformatting commands to create the on-line version of the documentation
1900719370Spstand @TeX{} (or @code{texi2roff}) to typeset the printed version.
1900819370Spst
1900946289Sdfr@value{GDBN} includes an already formatted copy of the on-line Info
1901046289Sdfrversion of this manual in the @file{gdb} subdirectory.  The main Info
1901146289Sdfrfile is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
1901219370Spstsubordinate files matching @samp{gdb.info*} in the same directory.  If
1901319370Spstnecessary, you can print out these files, or read them with any editor;
1901446289Sdfrbut they are easier to read using the @code{info} subsystem in @sc{gnu}
1901546289SdfrEmacs or the standalone @code{info} program, available as part of the
1901646289Sdfr@sc{gnu} Texinfo distribution.
1901719370Spst
1901819370SpstIf you want to format these Info files yourself, you need one of the
1901919370SpstInfo formatting programs, such as @code{texinfo-format-buffer} or
1902019370Spst@code{makeinfo}.
1902119370Spst
1902246289SdfrIf you have @code{makeinfo} installed, and are in the top level
1902346289Sdfr@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
1902446289Sdfrversion @value{GDBVN}), you can make the Info file by typing:
1902519370Spst
19026130809Smarcel@smallexample
1902719370Spstcd gdb
1902819370Spstmake gdb.info
19029130809Smarcel@end smallexample
1903019370Spst
1903119370SpstIf you want to typeset and print copies of this manual, you need @TeX{},
1903219370Spsta program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
1903319370SpstTexinfo definitions file.
1903419370Spst
1903519370Spst@TeX{} is a typesetting program; it does not print files directly, but
1903619370Spstproduces output files called @sc{dvi} files.  To print a typeset
1903719370Spstdocument, you need a program to print @sc{dvi} files.  If your system
1903819370Spsthas @TeX{} installed, chances are it has such a program.  The precise
1903919370Spstcommand to use depends on your system; @kbd{lpr -d} is common; another
1904019370Spst(for PostScript devices) is @kbd{dvips}.  The @sc{dvi} print command may
1904119370Spstrequire a file name without any extension or a @samp{.dvi} extension.
1904219370Spst
1904319370Spst@TeX{} also requires a macro definitions file called
1904419370Spst@file{texinfo.tex}.  This file tells @TeX{} how to typeset a document
1904519370Spstwritten in Texinfo format.  On its own, @TeX{} cannot either read or
1904619370Spsttypeset a Texinfo file.  @file{texinfo.tex} is distributed with GDB
1904719370Spstand is located in the @file{gdb-@var{version-number}/texinfo}
1904819370Spstdirectory.
1904919370Spst
1905019370SpstIf you have @TeX{} and a @sc{dvi} printer program installed, you can
1905119370Spsttypeset and print this manual.  First switch to the the @file{gdb}
1905219370Spstsubdirectory of the main source directory (for example, to
1905346289Sdfr@file{gdb-@value{GDBVN}/gdb}) and type:
1905419370Spst
19055130809Smarcel@smallexample
1905619370Spstmake gdb.dvi
19057130809Smarcel@end smallexample
1905819370Spst
1905946289SdfrThen give @file{gdb.dvi} to your @sc{dvi} printing program.
1906046289Sdfr
1906198948Sobrien@node Installing GDB
1906219370Spst@appendix Installing @value{GDBN}
1906319370Spst@cindex configuring @value{GDBN}
1906419370Spst@cindex installation
19065130809Smarcel@cindex configuring @value{GDBN}, and source tree subdirectories
1906619370Spst
1906719370Spst@value{GDBN} comes with a @code{configure} script that automates the process
1906819370Spstof preparing @value{GDBN} for installation; you can then use @code{make} to
1906919370Spstbuild the @code{gdb} program.
1907019370Spst@iftex
1907119370Spst@c irrelevant in info file; it's as current as the code it lives with.
1907219370Spst@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
1907319370Spstlook at the @file{README} file in the sources; we may have improved the
1907419370Spstinstallation procedures since publishing this manual.}
1907519370Spst@end iftex
1907619370Spst
1907798948SobrienThe @value{GDBN} distribution includes all the source code you need for
1907898948Sobrien@value{GDBN} in a single directory, whose name is usually composed by
1907919370Spstappending the version number to @samp{gdb}.
1908019370Spst
1908119370SpstFor example, the @value{GDBN} version @value{GDBVN} distribution is in the
1908219370Spst@file{gdb-@value{GDBVN}} directory.  That directory contains:
1908319370Spst
1908419370Spst@table @code
1908519370Spst@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
1908619370Spstscript for configuring @value{GDBN} and all its supporting libraries
1908719370Spst
1908819370Spst@item gdb-@value{GDBVN}/gdb
1908919370Spstthe source specific to @value{GDBN} itself
1909019370Spst
1909119370Spst@item gdb-@value{GDBVN}/bfd
1909219370Spstsource for the Binary File Descriptor library
1909319370Spst
1909419370Spst@item gdb-@value{GDBVN}/include
1909519370Spst@sc{gnu} include files
1909619370Spst
1909719370Spst@item gdb-@value{GDBVN}/libiberty
1909819370Spstsource for the @samp{-liberty} free software library
1909919370Spst
1910019370Spst@item gdb-@value{GDBVN}/opcodes
1910119370Spstsource for the library of opcode tables and disassemblers
1910219370Spst
1910319370Spst@item gdb-@value{GDBVN}/readline
1910419370Spstsource for the @sc{gnu} command-line interface
1910519370Spst
1910619370Spst@item gdb-@value{GDBVN}/glob
1910719370Spstsource for the @sc{gnu} filename pattern-matching subroutine
1910819370Spst
1910919370Spst@item gdb-@value{GDBVN}/mmalloc
1911019370Spstsource for the @sc{gnu} memory-mapped malloc package
1911119370Spst@end table
1911219370Spst
1911319370SpstThe simplest way to configure and build @value{GDBN} is to run @code{configure}
1911419370Spstfrom the @file{gdb-@var{version-number}} source directory, which in
1911519370Spstthis example is the @file{gdb-@value{GDBVN}} directory.
1911619370Spst
1911719370SpstFirst switch to the @file{gdb-@var{version-number}} source directory
1911819370Spstif you are not already in it; then run @code{configure}.  Pass the
1911919370Spstidentifier for the platform on which @value{GDBN} will run as an
1912019370Spstargument.
1912119370Spst
1912219370SpstFor example:
1912319370Spst
19124130809Smarcel@smallexample
1912519370Spstcd gdb-@value{GDBVN}
1912619370Spst./configure @var{host}
1912719370Spstmake
19128130809Smarcel@end smallexample
1912919370Spst
1913019370Spst@noindent
1913119370Spstwhere @var{host} is an identifier such as @samp{sun4} or
1913219370Spst@samp{decstation}, that identifies the platform where @value{GDBN} will run.
1913319370Spst(You can often leave off @var{host}; @code{configure} tries to guess the
1913419370Spstcorrect value by examining your system.)
1913519370Spst
1913619370SpstRunning @samp{configure @var{host}} and then running @code{make} builds the
1913719370Spst@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
1913819370Spstlibraries, then @code{gdb} itself.  The configured source files, and the
1913919370Spstbinaries, are left in the corresponding source directories.
1914019370Spst
1914119370Spst@need 750
1914219370Spst@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
1914319370Spstsystem does not recognize this automatically when you run a different
1914419370Spstshell, you may need to run @code{sh} on it explicitly:
1914519370Spst
19146130809Smarcel@smallexample
1914719370Spstsh configure @var{host}
19148130809Smarcel@end smallexample
1914919370Spst
1915019370SpstIf you run @code{configure} from a directory that contains source
1915119370Spstdirectories for multiple libraries or programs, such as the
1915219370Spst@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
1915319370Spstcreates configuration files for every directory level underneath (unless
1915419370Spstyou tell it not to, with the @samp{--norecursion} option).
1915519370Spst
19156130809SmarcelYou should run the @code{configure} script from the top directory in the
19157130809Smarcelsource tree, the @file{gdb-@var{version-number}} directory.  If you run
19158130809Smarcel@code{configure} from one of the subdirectories, you will configure only
19159130809Smarcelthat subdirectory.  That is usually not what you want.  In particular,
19160130809Smarcelif you run the first @code{configure} from the @file{gdb} subdirectory
19161130809Smarcelof the @file{gdb-@var{version-number}} directory, you will omit the
19162130809Smarcelconfiguration of @file{bfd}, @file{readline}, and other sibling
19163130809Smarceldirectories of the @file{gdb} subdirectory.  This leads to build errors
19164130809Smarcelabout missing include files such as @file{bfd/bfd.h}.
1916519370Spst
1916619370SpstYou can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
1916719370SpstHowever, you should make sure that the shell on your path (named by
1916819370Spstthe @samp{SHELL} environment variable) is publicly readable.  Remember
1916919370Spstthat @value{GDBN} uses the shell to start your program---some systems refuse to
1917019370Spstlet @value{GDBN} debug child processes whose programs are not readable.
1917119370Spst
1917219370Spst@menu
1917319370Spst* Separate Objdir::             Compiling @value{GDBN} in another directory
1917419370Spst* Config Names::                Specifying names for hosts and targets
1917546289Sdfr* Configure Options::           Summary of options for configure
1917619370Spst@end menu
1917719370Spst
1917898948Sobrien@node Separate Objdir
1917919370Spst@section Compiling @value{GDBN} in another directory
1918019370Spst
1918119370SpstIf you want to run @value{GDBN} versions for several host or target machines,
1918219370Spstyou need a different @code{gdb} compiled for each combination of
1918319370Spsthost and target.  @code{configure} is designed to make this easy by
1918419370Spstallowing you to generate each configuration in a separate subdirectory,
1918519370Spstrather than in the source directory.  If your @code{make} program
1918619370Spsthandles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
1918719370Spst@code{make} in each of these directories builds the @code{gdb}
1918819370Spstprogram specified there.
1918919370Spst
1919019370SpstTo build @code{gdb} in a separate directory, run @code{configure}
1919119370Spstwith the @samp{--srcdir} option to specify where to find the source.
1919219370Spst(You also need to specify a path to find @code{configure}
1919319370Spstitself from your working directory.  If the path to @code{configure}
1919419370Spstwould be the same as the argument to @samp{--srcdir}, you can leave out
1919519370Spstthe @samp{--srcdir} option; it is assumed.)
1919619370Spst
1919798948SobrienFor example, with version @value{GDBVN}, you can build @value{GDBN} in a
1919819370Spstseparate directory for a Sun 4 like this:
1919919370Spst
19200130809Smarcel@smallexample
1920119370Spst@group
1920219370Spstcd gdb-@value{GDBVN}
1920319370Spstmkdir ../gdb-sun4
1920419370Spstcd ../gdb-sun4
1920519370Spst../gdb-@value{GDBVN}/configure sun4
1920619370Spstmake
1920719370Spst@end group
19208130809Smarcel@end smallexample
1920919370Spst
1921019370SpstWhen @code{configure} builds a configuration using a remote source
1921119370Spstdirectory, it creates a tree for the binaries with the same structure
1921219370Spst(and using the same names) as the tree under the source directory.  In
1921319370Spstthe example, you'd find the Sun 4 library @file{libiberty.a} in the
1921419370Spstdirectory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
1921519370Spst@file{gdb-sun4/gdb}.
1921619370Spst
19217130809SmarcelMake sure that your path to the @file{configure} script has just one
19218130809Smarcelinstance of @file{gdb} in it.  If your path to @file{configure} looks
19219130809Smarcellike @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
19220130809Smarcelone subdirectory of @value{GDBN}, not the whole package.  This leads to
19221130809Smarcelbuild errors about missing include files such as @file{bfd/bfd.h}.
19222130809Smarcel
1922319370SpstOne popular reason to build several @value{GDBN} configurations in separate
1922498948Sobriendirectories is to configure @value{GDBN} for cross-compiling (where
1922598948Sobrien@value{GDBN} runs on one machine---the @dfn{host}---while debugging
1922698948Sobrienprograms that run on another machine---the @dfn{target}).
1922719370SpstYou specify a cross-debugging target by
1922819370Spstgiving the @samp{--target=@var{target}} option to @code{configure}.
1922919370Spst
1923019370SpstWhen you run @code{make} to build a program or library, you must run
1923119370Spstit in a configured directory---whatever directory you were in when you
1923219370Spstcalled @code{configure} (or one of its subdirectories).
1923319370Spst
1923419370SpstThe @code{Makefile} that @code{configure} generates in each source
1923519370Spstdirectory also runs recursively.  If you type @code{make} in a source
1923619370Spstdirectory such as @file{gdb-@value{GDBVN}} (or in a separate configured
1923719370Spstdirectory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
1923819370Spstwill build all the required libraries, and then build GDB.
1923919370Spst
1924019370SpstWhen you have multiple hosts or targets configured in separate
1924119370Spstdirectories, you can run @code{make} on them in parallel (for example,
1924219370Spstif they are NFS-mounted on each of the hosts); they will not interfere
1924319370Spstwith each other.
1924419370Spst
1924598948Sobrien@node Config Names
1924619370Spst@section Specifying names for hosts and targets
1924719370Spst
1924819370SpstThe specifications used for hosts and targets in the @code{configure}
1924919370Spstscript are based on a three-part naming scheme, but some short predefined
1925019370Spstaliases are also supported.  The full naming scheme encodes three pieces
1925119370Spstof information in the following pattern:
1925219370Spst
19253130809Smarcel@smallexample
1925419370Spst@var{architecture}-@var{vendor}-@var{os}
19255130809Smarcel@end smallexample
1925619370Spst
1925719370SpstFor example, you can use the alias @code{sun4} as a @var{host} argument,
1925819370Spstor as the value for @var{target} in a @code{--target=@var{target}}
1925919370Spstoption.  The equivalent full name is @samp{sparc-sun-sunos4}.
1926019370Spst
1926119370SpstThe @code{configure} script accompanying @value{GDBN} does not provide
1926219370Spstany query facility to list all supported host and target names or
1926319370Spstaliases.  @code{configure} calls the Bourne shell script
1926419370Spst@code{config.sub} to map abbreviations to full names; you can read the
1926519370Spstscript, if you wish, or you can use it to test your guesses on
1926619370Spstabbreviations---for example:
1926719370Spst
1926819370Spst@smallexample
1926946289Sdfr% sh config.sub i386-linux
1927046289Sdfri386-pc-linux-gnu
1927146289Sdfr% sh config.sub alpha-linux
1927246289Sdfralpha-unknown-linux-gnu
1927346289Sdfr% sh config.sub hp9k700
1927446289Sdfrhppa1.1-hp-hpux
1927519370Spst% sh config.sub sun4
1927619370Spstsparc-sun-sunos4.1.1
1927719370Spst% sh config.sub sun3
1927819370Spstm68k-sun-sunos4.1.1
1927946289Sdfr% sh config.sub i986v
1928046289SdfrInvalid configuration `i986v': machine `i986v' not recognized
1928119370Spst@end smallexample
1928219370Spst
1928319370Spst@noindent
1928419370Spst@code{config.sub} is also distributed in the @value{GDBN} source
1928519370Spstdirectory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
1928619370Spst
1928798948Sobrien@node Configure Options
1928819370Spst@section @code{configure} options
1928919370Spst
1929019370SpstHere is a summary of the @code{configure} options and arguments that
1929119370Spstare most often useful for building @value{GDBN}.  @code{configure} also has
1929219370Spstseveral other options not listed here.  @inforef{What Configure
1929319370SpstDoes,,configure.info}, for a full explanation of @code{configure}.
1929419370Spst
19295130809Smarcel@smallexample
1929619370Spstconfigure @r{[}--help@r{]}
1929719370Spst          @r{[}--prefix=@var{dir}@r{]}
1929846289Sdfr          @r{[}--exec-prefix=@var{dir}@r{]}
1929919370Spst          @r{[}--srcdir=@var{dirname}@r{]}
1930019370Spst          @r{[}--norecursion@r{]} @r{[}--rm@r{]}
1930146289Sdfr          @r{[}--target=@var{target}@r{]}
1930246289Sdfr          @var{host}
19303130809Smarcel@end smallexample
1930419370Spst
1930519370Spst@noindent
1930619370SpstYou may introduce options with a single @samp{-} rather than
1930719370Spst@samp{--} if you prefer; but you may abbreviate option names if you use
1930819370Spst@samp{--}.
1930919370Spst
1931019370Spst@table @code
1931119370Spst@item --help
1931219370SpstDisplay a quick summary of how to invoke @code{configure}.
1931319370Spst
1931446289Sdfr@item --prefix=@var{dir}
1931519370SpstConfigure the source to install programs and files under directory
1931619370Spst@file{@var{dir}}.
1931719370Spst
1931846289Sdfr@item --exec-prefix=@var{dir}
1931946289SdfrConfigure the source to install programs under directory
1932046289Sdfr@file{@var{dir}}.
1932146289Sdfr
1932219370Spst@c avoid splitting the warning from the explanation:
1932319370Spst@need 2000
1932419370Spst@item --srcdir=@var{dirname}
1932519370Spst@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
1932619370Spst@code{make} that implements the @code{VPATH} feature.}@*
1932719370SpstUse this option to make configurations in directories separate from the
1932819370Spst@value{GDBN} source directories.  Among other things, you can use this to
1932919370Spstbuild (or maintain) several configurations simultaneously, in separate
1933019370Spstdirectories.  @code{configure} writes configuration specific files in
1933119370Spstthe current directory, but arranges for them to use the source in the
1933219370Spstdirectory @var{dirname}.  @code{configure} creates directories under
1933319370Spstthe working directory in parallel to the source directories below
1933419370Spst@var{dirname}.
1933519370Spst
1933619370Spst@item --norecursion
1933719370SpstConfigure only the directory level where @code{configure} is executed; do not
1933819370Spstpropagate configuration to subdirectories.
1933919370Spst
1934019370Spst@item --target=@var{target}
1934119370SpstConfigure @value{GDBN} for cross-debugging programs running on the specified
1934219370Spst@var{target}.  Without this option, @value{GDBN} is configured to debug
1934319370Spstprograms that run on the same machine (@var{host}) as @value{GDBN} itself.
1934419370Spst
1934519370SpstThere is no convenient way to generate a list of all available targets.
1934619370Spst
1934719370Spst@item @var{host} @dots{}
1934819370SpstConfigure @value{GDBN} to run on the specified @var{host}.
1934919370Spst
1935019370SpstThere is no convenient way to generate a list of all available hosts.
1935119370Spst@end table
1935219370Spst
1935346289SdfrThere are many other options available as well, but they are generally
1935446289Sdfrneeded for special purposes only.
1935519370Spst
1935698948Sobrien@node Maintenance Commands
1935798948Sobrien@appendix Maintenance Commands
1935898948Sobrien@cindex maintenance commands
1935998948Sobrien@cindex internal commands
1936098948Sobrien
1936198948SobrienIn addition to commands intended for @value{GDBN} users, @value{GDBN}
1936298948Sobrienincludes a number of commands intended for @value{GDBN} developers.
1936398948SobrienThese commands are provided here for reference.
1936498948Sobrien
1936598948Sobrien@table @code
1936698948Sobrien@kindex maint info breakpoints
1936798948Sobrien@item @anchor{maint info breakpoints}maint info breakpoints
1936898948SobrienUsing the same format as @samp{info breakpoints}, display both the
1936998948Sobrienbreakpoints you've set explicitly, and those @value{GDBN} is using for
1937098948Sobrieninternal purposes.  Internal breakpoints are shown with negative
1937198948Sobrienbreakpoint numbers.  The type column identifies what kind of breakpoint
1937298948Sobrienis shown:
1937398948Sobrien
1937498948Sobrien@table @code
1937598948Sobrien@item breakpoint
1937698948SobrienNormal, explicitly set breakpoint.
1937798948Sobrien
1937898948Sobrien@item watchpoint
1937998948SobrienNormal, explicitly set watchpoint.
1938098948Sobrien
1938198948Sobrien@item longjmp
1938298948SobrienInternal breakpoint, used to handle correctly stepping through
1938398948Sobrien@code{longjmp} calls.
1938498948Sobrien
1938598948Sobrien@item longjmp resume
1938698948SobrienInternal breakpoint at the target of a @code{longjmp}.
1938798948Sobrien
1938898948Sobrien@item until
1938998948SobrienTemporary internal breakpoint used by the @value{GDBN} @code{until} command.
1939098948Sobrien
1939198948Sobrien@item finish
1939298948SobrienTemporary internal breakpoint used by the @value{GDBN} @code{finish} command.
1939398948Sobrien
1939498948Sobrien@item shlib events
1939598948SobrienShared library events.
1939698948Sobrien
1939798948Sobrien@end table
1939898948Sobrien
19399130809Smarcel@kindex maint internal-error
19400130809Smarcel@kindex maint internal-warning
19401130809Smarcel@item maint internal-error
19402130809Smarcel@itemx maint internal-warning
19403130809SmarcelCause @value{GDBN} to call the internal function @code{internal_error}
19404130809Smarcelor @code{internal_warning} and hence behave as though an internal error
19405130809Smarcelor internal warning has been detected.  In addition to reporting the
19406130809Smarcelinternal problem, these functions give the user the opportunity to
19407130809Smarceleither quit @value{GDBN} or create a core file of the current
19408130809Smarcel@value{GDBN} session.
19409130809Smarcel
19410130809Smarcel@smallexample
19411130809Smarcel(gdb) @kbd{maint internal-error testing, 1, 2}
19412130809Smarcel@dots{}/maint.c:121: internal-error: testing, 1, 2
19413130809SmarcelA problem internal to GDB has been detected.  Further
19414130809Smarceldebugging may prove unreliable.
19415130809SmarcelQuit this debugging session? (y or n) @kbd{n}
19416130809SmarcelCreate a core file? (y or n) @kbd{n}
19417130809Smarcel(gdb)
19418130809Smarcel@end smallexample
19419130809Smarcel
19420130809SmarcelTakes an optional parameter that is used as the text of the error or
19421130809Smarcelwarning message.
19422130809Smarcel
19423130809Smarcel@kindex maint print dummy-frames
19424130809Smarcel@item maint print dummy-frames
19425130809Smarcel
19426130809SmarcelPrints the contents of @value{GDBN}'s internal dummy-frame stack.
19427130809Smarcel
19428130809Smarcel@smallexample
19429130809Smarcel(gdb) @kbd{b add}
19430130809Smarcel@dots{}
19431130809Smarcel(gdb) @kbd{print add(2,3)}
19432130809SmarcelBreakpoint 2, add (a=2, b=3) at @dots{}
19433130809Smarcel58	  return (a + b);
19434130809SmarcelThe program being debugged stopped while in a function called from GDB.
19435130809Smarcel@dots{}
19436130809Smarcel(gdb) @kbd{maint print dummy-frames}
19437130809Smarcel0x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
19438130809Smarcel top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
19439130809Smarcel call_lo=0x01014000 call_hi=0x01014001
19440130809Smarcel(gdb)
19441130809Smarcel@end smallexample
19442130809Smarcel
19443130809SmarcelTakes an optional file parameter.
19444130809Smarcel
19445130809Smarcel@kindex maint print registers
19446130809Smarcel@kindex maint print raw-registers
19447130809Smarcel@kindex maint print cooked-registers
19448130809Smarcel@kindex maint print register-groups
19449130809Smarcel@item maint print registers
19450130809Smarcel@itemx maint print raw-registers
19451130809Smarcel@itemx maint print cooked-registers
19452130809Smarcel@itemx maint print register-groups
19453130809SmarcelPrint @value{GDBN}'s internal register data structures.
19454130809Smarcel
19455130809SmarcelThe command @code{maint print raw-registers} includes the contents of
19456130809Smarcelthe raw register cache; the command @code{maint print cooked-registers}
19457130809Smarcelincludes the (cooked) value of all registers; and the command
19458130809Smarcel@code{maint print register-groups} includes the groups that each
19459130809Smarcelregister is a member of.  @xref{Registers,, Registers, gdbint,
19460130809Smarcel@value{GDBN} Internals}.
19461130809Smarcel
19462130809SmarcelTakes an optional file parameter.
19463130809Smarcel
19464130809Smarcel@kindex maint print reggroups
19465130809Smarcel@item maint print reggroups
19466130809SmarcelPrint @value{GDBN}'s internal register group data structures.
19467130809Smarcel
19468130809SmarcelTakes an optional file parameter.
19469130809Smarcel
19470130809Smarcel@smallexample
19471130809Smarcel(gdb) @kbd{maint print reggroups}
19472130809Smarcel Group      Type
19473130809Smarcel general    user
19474130809Smarcel float      user
19475130809Smarcel all        user
19476130809Smarcel vector     user
19477130809Smarcel system     user
19478130809Smarcel save       internal
19479130809Smarcel restore    internal
19480130809Smarcel@end smallexample
19481130809Smarcel
19482130809Smarcel@kindex maint set profile
19483130809Smarcel@kindex maint show profile
19484130809Smarcel@cindex profiling GDB
19485130809Smarcel@item maint set profile
19486130809Smarcel@itemx maint show profile
19487130809SmarcelControl profiling of @value{GDBN}.
19488130809Smarcel
19489130809SmarcelProfiling will be disabled until you use the @samp{maint set profile}
19490130809Smarcelcommand to enable it.  When you enable profiling, the system will begin
19491130809Smarcelcollecting timing and execution count data; when you disable profiling or
19492130809Smarcelexit @value{GDBN}, the results will be written to a log file.  Remember that
19493130809Smarcelif you use profiling, @value{GDBN} will overwrite the profiling log file
19494130809Smarcel(often called @file{gmon.out}).  If you have a record of important profiling
19495130809Smarceldata in a @file{gmon.out} file, be sure to move it to a safe location.
19496130809Smarcel
19497130809SmarcelConfiguring with @samp{--enable-profiling} arranges for @value{GDBN} to be
19498130809Smarcelcompiled with the @samp{-pg} compiler option.
19499130809Smarcel
1950098948Sobrien@end table
1950198948Sobrien
1950298948Sobrien
1950398948Sobrien@node Remote Protocol
1950498948Sobrien@appendix @value{GDBN} Remote Serial Protocol
1950598948Sobrien
19506130809Smarcel@menu
19507130809Smarcel* Overview::
19508130809Smarcel* Packets::
19509130809Smarcel* Stop Reply Packets::
19510130809Smarcel* General Query Packets::
19511130809Smarcel* Register Packet Format::
19512130809Smarcel* Examples::
19513130809Smarcel* File-I/O remote protocol extension::
19514130809Smarcel@end menu
19515130809Smarcel
19516130809Smarcel@node Overview
19517130809Smarcel@section Overview
19518130809Smarcel
1951998948SobrienThere may be occasions when you need to know something about the
1952098948Sobrienprotocol---for example, if there is only one serial port to your target
1952198948Sobrienmachine, you might want your program to do something special if it
1952298948Sobrienrecognizes a packet meant for @value{GDBN}.
1952398948Sobrien
19524130809SmarcelIn the examples below, @samp{->} and @samp{<-} are used to indicate
1952598948Sobrientransmitted and received data respectfully.
1952698948Sobrien
1952798948Sobrien@cindex protocol, @value{GDBN} remote serial
1952898948Sobrien@cindex serial protocol, @value{GDBN} remote
1952998948Sobrien@cindex remote serial protocol
1953098948SobrienAll @value{GDBN} commands and responses (other than acknowledgments) are
1953198948Sobriensent as a @var{packet}.  A @var{packet} is introduced with the character
1953298948Sobrien@samp{$}, the actual @var{packet-data}, and the terminating character
1953398948Sobrien@samp{#} followed by a two-digit @var{checksum}:
1953498948Sobrien
19535130809Smarcel@smallexample
1953698948Sobrien@code{$}@var{packet-data}@code{#}@var{checksum}
19537130809Smarcel@end smallexample
1953898948Sobrien@noindent
1953998948Sobrien
1954098948Sobrien@cindex checksum, for @value{GDBN} remote
1954198948Sobrien@noindent
1954298948SobrienThe two-digit @var{checksum} is computed as the modulo 256 sum of all
1954398948Sobriencharacters between the leading @samp{$} and the trailing @samp{#} (an
1954498948Sobrieneight bit unsigned checksum).
1954598948Sobrien
1954698948SobrienImplementors should note that prior to @value{GDBN} 5.0 the protocol
1954798948Sobrienspecification also included an optional two-digit @var{sequence-id}:
1954898948Sobrien
19549130809Smarcel@smallexample
1955098948Sobrien@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
19551130809Smarcel@end smallexample
1955298948Sobrien
1955398948Sobrien@cindex sequence-id, for @value{GDBN} remote
1955498948Sobrien@noindent
1955598948SobrienThat @var{sequence-id} was appended to the acknowledgment.  @value{GDBN}
1955698948Sobrienhas never output @var{sequence-id}s.  Stubs that handle packets added
1955798948Sobriensince @value{GDBN} 5.0 must not accept @var{sequence-id}.
1955898948Sobrien
1955998948Sobrien@cindex acknowledgment, for @value{GDBN} remote
1956098948SobrienWhen either the host or the target machine receives a packet, the first
1956198948Sobrienresponse expected is an acknowledgment: either @samp{+} (to indicate
1956298948Sobrienthe package was received correctly) or @samp{-} (to request
1956398948Sobrienretransmission):
1956498948Sobrien
19565130809Smarcel@smallexample
19566130809Smarcel-> @code{$}@var{packet-data}@code{#}@var{checksum}
19567130809Smarcel<- @code{+}
19568130809Smarcel@end smallexample
1956998948Sobrien@noindent
1957098948Sobrien
1957198948SobrienThe host (@value{GDBN}) sends @var{command}s, and the target (the
1957298948Sobriendebugging stub incorporated in your program) sends a @var{response}.  In
1957398948Sobrienthe case of step and continue @var{command}s, the response is only sent
1957498948Sobrienwhen the operation has completed (the target has again stopped).
1957598948Sobrien
1957698948Sobrien@var{packet-data} consists of a sequence of characters with the
1957798948Sobrienexception of @samp{#} and @samp{$} (see @samp{X} packet for additional
1957898948Sobrienexceptions).
1957998948Sobrien
1958098948SobrienFields within the packet should be separated using @samp{,} @samp{;} or
19581130809Smarcel@cindex remote protocol, field separator
1958298948Sobrien@samp{:}.  Except where otherwise noted all numbers are represented in
19583130809Smarcel@sc{hex} with leading zeros suppressed.
1958498948Sobrien
1958598948SobrienImplementors should note that prior to @value{GDBN} 5.0, the character
1958698948Sobrien@samp{:} could not appear as the third character in a packet (as it
1958798948Sobrienwould potentially conflict with the @var{sequence-id}).
1958898948Sobrien
1958998948SobrienResponse @var{data} can be run-length encoded to save space.  A @samp{*}
1959098948Sobrienmeans that the next character is an @sc{ascii} encoding giving a repeat count
1959198948Sobrienwhich stands for that many repetitions of the character preceding the
1959298948Sobrien@samp{*}.  The encoding is @code{n+29}, yielding a printable character
1959398948Sobrienwhere @code{n >=3} (which is where rle starts to win).  The printable
1959498948Sobriencharacters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
1959598948Sobrienvalue greater than 126 should not be used.
1959698948Sobrien
1959798948SobrienSo:
19598130809Smarcel@smallexample
1959998948Sobrien"@code{0* }"
19600130809Smarcel@end smallexample
1960198948Sobrien@noindent
1960298948Sobrienmeans the same as "0000".
1960398948Sobrien
1960498948SobrienThe error response returned for some packets includes a two character
1960598948Sobrienerror number.  That number is not well defined.
1960698948Sobrien
1960798948SobrienFor any @var{command} not supported by the stub, an empty response
1960898948Sobrien(@samp{$#00}) should be returned.  That way it is possible to extend the
1960998948Sobrienprotocol.  A newer @value{GDBN} can tell if a packet is supported based
1961098948Sobrienon that response.
1961198948Sobrien
19612130809SmarcelA stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
19613130809Smarcel@samp{c}, and @samp{s} @var{command}s.  All other @var{command}s are
1961498948Sobrienoptional.
1961598948Sobrien
19616130809Smarcel@node Packets
19617130809Smarcel@section Packets
1961898948Sobrien
19619130809SmarcelThe following table provides a complete list of all currently defined
19620130809Smarcel@var{command}s and their corresponding response @var{data}.
19621130809Smarcel
19622130809Smarcel@table @r
19623130809Smarcel
19624130809Smarcel@item @code{!} --- extended mode
19625130809Smarcel@cindex @code{!} packet
19626130809Smarcel
1962798948SobrienEnable extended mode.  In extended mode, the remote server is made
1962898948Sobrienpersistent.  The @samp{R} packet is used to restart the program being
1962998948Sobriendebugged.
19630130809Smarcel
19631130809SmarcelReply:
19632130809Smarcel@table @samp
19633130809Smarcel@item OK
1963498948SobrienThe remote target both supports and has enabled extended mode.
19635130809Smarcel@end table
1963698948Sobrien
19637130809Smarcel@item @code{?} --- last signal
19638130809Smarcel@cindex @code{?} packet
1963998948Sobrien
19640130809SmarcelIndicate the reason the target halted.  The reply is the same as for
19641130809Smarcelstep and continue.
1964298948Sobrien
19643130809SmarcelReply:
19644130809Smarcel@xref{Stop Reply Packets}, for the reply specifications.
1964598948Sobrien
19646130809Smarcel@item @code{a} --- reserved
19647130809Smarcel
19648130809SmarcelReserved for future use.
19649130809Smarcel
19650130809Smarcel@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} ---  set program arguments @strong{(reserved)}
19651130809Smarcel@cindex @code{A} packet
19652130809Smarcel
1965398948SobrienInitialized @samp{argv[]} array passed into program. @var{arglen}
1965498948Sobrienspecifies the number of bytes in the hex encoded byte stream @var{arg}.
19655130809SmarcelSee @code{gdbserver} for more details.
1965698948Sobrien
19657130809SmarcelReply:
19658130809Smarcel@table @samp
19659130809Smarcel@item OK
19660130809Smarcel@item E@var{NN}
19661130809Smarcel@end table
1966298948Sobrien
19663130809Smarcel@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
19664130809Smarcel@cindex @code{b} packet
19665130809Smarcel
19666130809SmarcelChange the serial line speed to @var{baud}.
19667130809Smarcel
19668130809SmarcelJTC: @emph{When does the transport layer state change?  When it's
19669130809Smarcelreceived, or after the ACK is transmitted.  In either case, there are
19670130809Smarcelproblems if the command or the acknowledgment packet is dropped.}
19671130809Smarcel
19672130809SmarcelStan: @emph{If people really wanted to add something like this, and get
19673130809Smarcelit working for the first time, they ought to modify ser-unix.c to send
19674130809Smarcelsome kind of out-of-band message to a specially-setup stub and have the
19675130809Smarcelswitch happen "in between" packets, so that from remote protocol's point
19676130809Smarcelof view, nothing actually happened.}
19677130809Smarcel
19678130809Smarcel@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
19679130809Smarcel@cindex @code{B} packet
19680130809Smarcel
1968198948SobrienSet (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
19682130809Smarcelbreakpoint at @var{addr}.
1968398948Sobrien
19684130809SmarcelThis packet has been replaced by the @samp{Z} and @samp{z} packets
19685130809Smarcel(@pxref{insert breakpoint or watchpoint packet}).
19686130809Smarcel
19687130809Smarcel@item @code{c}@var{addr} --- continue
19688130809Smarcel@cindex @code{c} packet
19689130809Smarcel
19690130809Smarcel@var{addr} is address to resume.  If @var{addr} is omitted, resume at
1969198948Sobriencurrent address.
1969298948Sobrien
19693130809SmarcelReply:
19694130809Smarcel@xref{Stop Reply Packets}, for the reply specifications.
19695130809Smarcel
19696130809Smarcel@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
19697130809Smarcel@cindex @code{C} packet
19698130809Smarcel
1969998948SobrienContinue with signal @var{sig} (hex signal number).  If
1970098948Sobrien@code{;}@var{addr} is omitted, resume at same address.
1970198948Sobrien
19702130809SmarcelReply:
19703130809Smarcel@xref{Stop Reply Packets}, for the reply specifications.
1970498948Sobrien
19705130809Smarcel@item @code{d} --- toggle debug @strong{(deprecated)}
19706130809Smarcel@cindex @code{d} packet
19707130809Smarcel
19708130809SmarcelToggle debug flag.
19709130809Smarcel
19710130809Smarcel@item @code{D} --- detach
19711130809Smarcel@cindex @code{D} packet
19712130809Smarcel
19713130809SmarcelDetach @value{GDBN} from the remote system.  Sent to the remote target
19714130809Smarcelbefore @value{GDBN} disconnects via the @code{detach} command.
19715130809Smarcel
19716130809SmarcelReply:
19717130809Smarcel@table @samp
19718130809Smarcel@item @emph{no response}
1971998948Sobrien@value{GDBN} does not check for any response after sending this packet.
19720130809Smarcel@end table
1972198948Sobrien
19722130809Smarcel@item @code{e} --- reserved
1972398948Sobrien
19724130809SmarcelReserved for future use.
1972598948Sobrien
19726130809Smarcel@item @code{E} --- reserved
1972798948Sobrien
19728130809SmarcelReserved for future use.
1972998948Sobrien
19730130809Smarcel@item @code{f} --- reserved
19731130809Smarcel
19732130809SmarcelReserved for future use.
19733130809Smarcel
19734130809Smarcel@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
19735130809Smarcel@cindex @code{F} packet
19736130809Smarcel
19737130809SmarcelThis packet is send by @value{GDBN} as reply to a @code{F} request packet
19738130809Smarcelsent by the target.  This is part of the File-I/O protocol extension.
19739130809Smarcel@xref{File-I/O remote protocol extension}, for the specification.
19740130809Smarcel
19741130809Smarcel@item @code{g} --- read registers
19742130809Smarcel@anchor{read registers packet}
19743130809Smarcel@cindex @code{g} packet
19744130809Smarcel
19745130809SmarcelRead general registers.
19746130809Smarcel
19747130809SmarcelReply:
19748130809Smarcel@table @samp
19749130809Smarcel@item @var{XX@dots{}}
1975098948SobrienEach byte of register data is described by two hex digits.  The bytes
1975198948Sobrienwith the register are transmitted in target byte order.  The size of
1975298948Sobrieneach register and their position within the @samp{g} @var{packet} are
19753130809Smarceldetermined by the @value{GDBN} internal macros
19754130809Smarcel@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros.  The
19755130809Smarcelspecification of several standard @code{g} packets is specified below.
19756130809Smarcel@item E@var{NN}
19757130809Smarcelfor an error.
19758130809Smarcel@end table
1975998948Sobrien
19760130809Smarcel@item @code{G}@var{XX@dots{}} --- write regs
19761130809Smarcel@cindex @code{G} packet
1976298948Sobrien
19763130809Smarcel@xref{read registers packet}, for a description of the @var{XX@dots{}}
19764130809Smarceldata.
1976598948Sobrien
19766130809SmarcelReply:
19767130809Smarcel@table @samp
19768130809Smarcel@item OK
19769130809Smarcelfor success
19770130809Smarcel@item E@var{NN}
19771130809Smarcelfor an error
19772130809Smarcel@end table
19773130809Smarcel
19774130809Smarcel@item @code{h} --- reserved
19775130809Smarcel
19776130809SmarcelReserved for future use.
19777130809Smarcel
19778130809Smarcel@item @code{H}@var{c}@var{t@dots{}} --- set thread
19779130809Smarcel@cindex @code{H} packet
19780130809Smarcel
1978198948SobrienSet thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
19782130809Smarcel@samp{G}, et.al.).  @var{c} depends on the operation to be performed: it
19783130809Smarcelshould be @samp{c} for step and continue operations, @samp{g} for other
19784130809Smarceloperations.  The thread designator @var{t@dots{}} may be -1, meaning all
19785130809Smarcelthe threads, a thread number, or zero which means pick any thread.
1978698948Sobrien
19787130809SmarcelReply:
19788130809Smarcel@table @samp
19789130809Smarcel@item OK
19790130809Smarcelfor success
19791130809Smarcel@item E@var{NN}
19792130809Smarcelfor an error
19793130809Smarcel@end table
19794130809Smarcel
1979598948Sobrien@c FIXME: JTC:
1979698948Sobrien@c   'H': How restrictive (or permissive) is the thread model.  If a
1979798948Sobrien@c        thread is selected and stopped, are other threads allowed
1979898948Sobrien@c        to continue to execute?  As I mentioned above, I think the
1979998948Sobrien@c        semantics of each command when a thread is selected must be
1980098948Sobrien@c        described.  For example:
1980198948Sobrien@c
1980298948Sobrien@c        'g':    If the stub supports threads and a specific thread is
1980398948Sobrien@c                selected, returns the register block from that thread;
1980498948Sobrien@c                otherwise returns current registers.
1980598948Sobrien@c
1980698948Sobrien@c        'G'     If the stub supports threads and a specific thread is
1980798948Sobrien@c                selected, sets the registers of the register block of
1980898948Sobrien@c                that thread; otherwise sets current registers.
1980998948Sobrien
19810130809Smarcel@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
19811130809Smarcel@anchor{cycle step packet}
19812130809Smarcel@cindex @code{i} packet
19813130809Smarcel
1981498948SobrienStep the remote target by a single clock cycle.  If @code{,}@var{nnn} is
1981598948Sobrienpresent, cycle step @var{nnn} cycles.  If @var{addr} is present, cycle
1981698948Sobrienstep starting at that address.
1981798948Sobrien
19818130809Smarcel@item @code{I} --- signal then cycle step @strong{(reserved)}
19819130809Smarcel@cindex @code{I} packet
1982098948Sobrien
19821130809Smarcel@xref{step with signal packet}.  @xref{cycle step packet}.
1982298948Sobrien
19823130809Smarcel@item @code{j} --- reserved
1982498948Sobrien
19825130809SmarcelReserved for future use.
19826130809Smarcel
19827130809Smarcel@item @code{J} --- reserved
19828130809Smarcel
19829130809SmarcelReserved for future use.
19830130809Smarcel
19831130809Smarcel@item @code{k} --- kill request
19832130809Smarcel@cindex @code{k} packet
19833130809Smarcel
1983498948SobrienFIXME: @emph{There is no description of how to operate when a specific
19835130809Smarcelthread context has been selected (i.e.@: does 'k' kill only that
19836130809Smarcelthread?)}.
1983798948Sobrien
19838130809Smarcel@item @code{K} --- reserved
1983998948Sobrien
19840130809SmarcelReserved for future use.
1984198948Sobrien
19842130809Smarcel@item @code{l} --- reserved
19843130809Smarcel
19844130809SmarcelReserved for future use.
19845130809Smarcel
19846130809Smarcel@item @code{L} --- reserved
19847130809Smarcel
19848130809SmarcelReserved for future use.
19849130809Smarcel
19850130809Smarcel@item @code{m}@var{addr}@code{,}@var{length} --- read memory
19851130809Smarcel@cindex @code{m} packet
19852130809Smarcel
1985398948SobrienRead @var{length} bytes of memory starting at address @var{addr}.
19854130809SmarcelNeither @value{GDBN} nor the stub assume that sized memory transfers are
19855130809Smarcelassumed using word aligned accesses. FIXME: @emph{A word aligned memory
1985698948Sobrientransfer mechanism is needed.}
1985798948Sobrien
19858130809SmarcelReply:
19859130809Smarcel@table @samp
19860130809Smarcel@item @var{XX@dots{}}
19861130809Smarcel@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
19862130809Smarcelto read only part of the data.  Neither @value{GDBN} nor the stub assume
19863130809Smarcelthat sized memory transfers are assumed using word aligned
19864130809Smarcelaccesses. FIXME: @emph{A word aligned memory transfer mechanism is
19865130809Smarcelneeded.}
19866130809Smarcel@item E@var{NN}
19867130809Smarcel@var{NN} is errno
19868130809Smarcel@end table
19869130809Smarcel
19870130809Smarcel@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
19871130809Smarcel@cindex @code{M} packet
19872130809Smarcel
1987398948SobrienWrite @var{length} bytes of memory starting at address @var{addr}.
19874130809Smarcel@var{XX@dots{}} is the data.
19875130809Smarcel
19876130809SmarcelReply:
19877130809Smarcel@table @samp
19878130809Smarcel@item OK
19879130809Smarcelfor success
19880130809Smarcel@item E@var{NN}
1988198948Sobrienfor an error (this includes the case where only part of the data was
1988298948Sobrienwritten).
19883130809Smarcel@end table
1988498948Sobrien
19885130809Smarcel@item @code{n} --- reserved
1988698948Sobrien
19887130809SmarcelReserved for future use.
1988898948Sobrien
19889130809Smarcel@item @code{N} --- reserved
1989098948Sobrien
19891130809SmarcelReserved for future use.
1989298948Sobrien
19893130809Smarcel@item @code{o} --- reserved
1989498948Sobrien
19895130809SmarcelReserved for future use.
19896130809Smarcel
19897130809Smarcel@item @code{O} --- reserved
19898130809Smarcel
19899130809SmarcelReserved for future use.
19900130809Smarcel
19901130809Smarcel@item @code{p}@var{n@dots{}} --- read reg @strong{(reserved)}
19902130809Smarcel@cindex @code{p} packet
19903130809Smarcel
19904130809Smarcel@xref{write register packet}.
19905130809Smarcel
19906130809SmarcelReply:
19907130809Smarcel@table @samp
19908130809Smarcel@item @var{r@dots{}.}
19909130809SmarcelThe hex encoded value of the register in target byte order.
19910130809Smarcel@end table
19911130809Smarcel
19912130809Smarcel@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
19913130809Smarcel@anchor{write register packet}
19914130809Smarcel@cindex @code{P} packet
19915130809Smarcel
19916130809SmarcelWrite register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
1991798948Sobriendigits for each byte in the register (target byte order).
1991898948Sobrien
19919130809SmarcelReply:
19920130809Smarcel@table @samp
19921130809Smarcel@item OK
19922130809Smarcelfor success
19923130809Smarcel@item E@var{NN}
19924130809Smarcelfor an error
19925130809Smarcel@end table
19926130809Smarcel
19927130809Smarcel@item @code{q}@var{query} --- general query
19928130809Smarcel@anchor{general query packet}
19929130809Smarcel@cindex @code{q} packet
19930130809Smarcel
19931130809SmarcelRequest info about @var{query}.  In general @value{GDBN} queries have a
19932130809Smarcelleading upper case letter.  Custom vendor queries should use a company
19933130809Smarcelprefix (in lower case) ex: @samp{qfsf.var}.  @var{query} may optionally
19934130809Smarcelbe followed by a @samp{,} or @samp{;} separated list.  Stubs must ensure
19935130809Smarcelthat they match the full @var{query} name.
19936130809Smarcel
19937130809SmarcelReply:
19938130809Smarcel@table @samp
19939130809Smarcel@item @var{XX@dots{}}
19940130809SmarcelHex encoded data from query.  The reply can not be empty.
19941130809Smarcel@item E@var{NN}
19942130809Smarcelerror reply
1994398948Sobrien@item
19944130809SmarcelIndicating an unrecognized @var{query}.
19945130809Smarcel@end table
1994698948Sobrien
19947130809Smarcel@item @code{Q}@var{var}@code{=}@var{val} --- general set
19948130809Smarcel@cindex @code{Q} packet
1994998948Sobrien
19950130809SmarcelSet value of @var{var} to @var{val}.
19951130809Smarcel
19952130809Smarcel@xref{general query packet}, for a discussion of naming conventions.
19953130809Smarcel
19954130809Smarcel@item @code{r} --- reset @strong{(deprecated)}
19955130809Smarcel@cindex @code{r} packet
19956130809Smarcel
1995798948SobrienReset the entire system.
1995898948Sobrien
19959130809Smarcel@item @code{R}@var{XX} --- remote restart
19960130809Smarcel@cindex @code{R} packet
19961130809Smarcel
1996298948SobrienRestart the program being debugged.  @var{XX}, while needed, is ignored.
1996398948SobrienThis packet is only available in extended mode.
19964130809Smarcel
19965130809SmarcelReply:
19966130809Smarcel@table @samp
19967130809Smarcel@item @emph{no reply}
1996898948SobrienThe @samp{R} packet has no reply.
19969130809Smarcel@end table
1997098948Sobrien
19971130809Smarcel@item @code{s}@var{addr} --- step
19972130809Smarcel@cindex @code{s} packet
19973130809Smarcel
1997498948Sobrien@var{addr} is address to resume.  If @var{addr} is omitted, resume at
1997598948Sobriensame address.
1997698948Sobrien
19977130809SmarcelReply:
19978130809Smarcel@xref{Stop Reply Packets}, for the reply specifications.
19979130809Smarcel
19980130809Smarcel@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
19981130809Smarcel@anchor{step with signal packet}
19982130809Smarcel@cindex @code{S} packet
19983130809Smarcel
1998498948SobrienLike @samp{C} but step not continue.
1998598948Sobrien
19986130809SmarcelReply:
19987130809Smarcel@xref{Stop Reply Packets}, for the reply specifications.
19988130809Smarcel
19989130809Smarcel@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
19990130809Smarcel@cindex @code{t} packet
19991130809Smarcel
1999298948SobrienSearch backwards starting at address @var{addr} for a match with pattern
19993130809Smarcel@var{PP} and mask @var{MM}.  @var{PP} and @var{MM} are 4 bytes.
19994130809Smarcel@var{addr} must be at least 3 digits.
1999598948Sobrien
19996130809Smarcel@item @code{T}@var{XX} --- thread alive
19997130809Smarcel@cindex @code{T} packet
19998130809Smarcel
19999130809SmarcelFind out if the thread XX is alive.
20000130809Smarcel
20001130809SmarcelReply:
20002130809Smarcel@table @samp
20003130809Smarcel@item OK
20004130809Smarcelthread is still alive
20005130809Smarcel@item E@var{NN}
20006130809Smarcelthread is dead
20007130809Smarcel@end table
20008130809Smarcel
20009130809Smarcel@item @code{u} --- reserved
20010130809Smarcel
20011130809SmarcelReserved for future use.
20012130809Smarcel
20013130809Smarcel@item @code{U} --- reserved
20014130809Smarcel
20015130809SmarcelReserved for future use.
20016130809Smarcel
20017130809Smarcel@item @code{v} --- verbose packet prefix
20018130809Smarcel
20019130809SmarcelPackets starting with @code{v} are identified by a multi-letter name,
20020130809Smarcelup to the first @code{;} or @code{?} (or the end of the packet).
20021130809Smarcel
20022130809Smarcel@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
20023130809Smarcel@cindex @code{vCont} packet
20024130809Smarcel
20025130809SmarcelResume the inferior.  Different actions may be specified for each thread.
20026130809SmarcelIf an action is specified with no @var{tid}, then it is applied to any
20027130809Smarcelthreads that don't have a specific action specified; if no default action is
20028130809Smarcelspecified then other threads should remain stopped.  Specifying multiple
20029130809Smarceldefault actions is an error; specifying no actions is also an error.
20030130809SmarcelThread IDs are specified in hexadecimal.  Currently supported actions are:
20031130809Smarcel
20032130809Smarcel@table @code
20033130809Smarcel@item c
20034130809SmarcelContinue.
20035130809Smarcel@item C@var{sig}
20036130809SmarcelContinue with signal @var{sig}.  @var{sig} should be two hex digits.
20037130809Smarcel@item s
20038130809SmarcelStep.
20039130809Smarcel@item S@var{sig}
20040130809SmarcelStep with signal @var{sig}.  @var{sig} should be two hex digits.
20041130809Smarcel@end table
20042130809Smarcel
20043130809SmarcelThe optional @var{addr} argument normally associated with these packets is
20044130809Smarcelnot supported in @code{vCont}.
20045130809Smarcel
20046130809SmarcelReply:
20047130809Smarcel@xref{Stop Reply Packets}, for the reply specifications.
20048130809Smarcel
20049130809Smarcel@item @code{vCont?} --- extended resume query
20050130809Smarcel@cindex @code{vCont?} packet
20051130809Smarcel
20052130809SmarcelQuery support for the @code{vCont} packet.
20053130809Smarcel
20054130809SmarcelReply:
20055130809Smarcel@table @samp
20056130809Smarcel@item @code{vCont}[;@var{action}]...
20057130809SmarcelThe @code{vCont} packet is supported.  Each @var{action} is a supported
20058130809Smarcelcommand in the @code{vCont} packet.
2005998948Sobrien@item
20060130809SmarcelThe @code{vCont} packet is not supported.
20061130809Smarcel@end table
2006298948Sobrien
20063130809Smarcel@item @code{V} --- reserved
2006498948Sobrien
20065130809SmarcelReserved for future use.
2006698948Sobrien
20067130809Smarcel@item @code{w} --- reserved
2006898948Sobrien
20069130809SmarcelReserved for future use.
2007098948Sobrien
20071130809Smarcel@item @code{W} --- reserved
2007298948Sobrien
20073130809SmarcelReserved for future use.
2007498948Sobrien
20075130809Smarcel@item @code{x} --- reserved
2007698948Sobrien
20077130809SmarcelReserved for future use.
20078130809Smarcel
20079130809Smarcel@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
20080130809Smarcel@cindex @code{X} packet
20081130809Smarcel
20082130809Smarcel@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
20083130809Smarcelis binary data.  The characters @code{$}, @code{#}, and @code{0x7d} are
2008498948Sobrienescaped using @code{0x7d}.
20085130809Smarcel
20086130809SmarcelReply:
20087130809Smarcel@table @samp
20088130809Smarcel@item OK
20089130809Smarcelfor success
20090130809Smarcel@item E@var{NN}
20091130809Smarcelfor an error
20092130809Smarcel@end table
20093130809Smarcel
20094130809Smarcel@item @code{y} --- reserved
20095130809Smarcel
20096130809SmarcelReserved for future use.
20097130809Smarcel
20098130809Smarcel@item @code{Y} reserved
20099130809Smarcel
20100130809SmarcelReserved for future use.
20101130809Smarcel
20102130809Smarcel@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
20103130809Smarcel@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
20104130809Smarcel@anchor{insert breakpoint or watchpoint packet}
20105130809Smarcel@cindex @code{z} packet
20106130809Smarcel@cindex @code{Z} packets
20107130809Smarcel
20108130809SmarcelInsert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
20109130809Smarcelwatchpoint starting at address @var{address} and covering the next
20110130809Smarcel@var{length} bytes.
20111130809Smarcel
20112130809SmarcelEach breakpoint and watchpoint packet @var{type} is documented
20113130809Smarcelseparately.
20114130809Smarcel
20115130809Smarcel@emph{Implementation notes: A remote target shall return an empty string
20116130809Smarcelfor an unrecognized breakpoint or watchpoint packet @var{type}.  A
20117130809Smarcelremote target shall support either both or neither of a given
20118130809Smarcel@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair.  To
20119130809Smarcelavoid potential problems with duplicate packets, the operations should
20120130809Smarcelbe implemented in an idempotent way.}
20121130809Smarcel
20122130809Smarcel@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
20123130809Smarcel@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
20124130809Smarcel@cindex @code{z0} packet
20125130809Smarcel@cindex @code{Z0} packet
20126130809Smarcel
20127130809SmarcelInsert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
20128130809Smarcel@code{addr} of size @code{length}.
20129130809Smarcel
20130130809SmarcelA memory breakpoint is implemented by replacing the instruction at
20131130809Smarcel@var{addr} with a software breakpoint or trap instruction.  The
20132130809Smarcel@code{length} is used by targets that indicates the size of the
20133130809Smarcelbreakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
20134130809Smarcel@sc{mips} can insert either a 2 or 4 byte breakpoint).
20135130809Smarcel
20136130809Smarcel@emph{Implementation note: It is possible for a target to copy or move
20137130809Smarcelcode that contains memory breakpoints (e.g., when implementing
20138130809Smarceloverlays).  The behavior of this packet, in the presence of such a
20139130809Smarceltarget, is not defined.}
20140130809Smarcel
20141130809SmarcelReply:
20142130809Smarcel@table @samp
20143130809Smarcel@item OK
20144130809Smarcelsuccess
2014598948Sobrien@item
20146130809Smarcelnot supported
20147130809Smarcel@item E@var{NN}
20148130809Smarcelfor an error
20149130809Smarcel@end table
2015098948Sobrien
20151130809Smarcel@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
20152130809Smarcel@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
20153130809Smarcel@cindex @code{z1} packet
20154130809Smarcel@cindex @code{Z1} packet
2015598948Sobrien
20156130809SmarcelInsert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
20157130809Smarceladdress @code{addr} of size @code{length}.
2015898948Sobrien
20159130809SmarcelA hardware breakpoint is implemented using a mechanism that is not
20160130809Smarceldependant on being able to modify the target's memory.
2016198948Sobrien
20162130809Smarcel@emph{Implementation note: A hardware breakpoint is not affected by code
20163130809Smarcelmovement.}
20164130809Smarcel
20165130809SmarcelReply:
20166130809Smarcel@table @samp
20167130809Smarcel@item OK
20168130809Smarcelsuccess
2016998948Sobrien@item
20170130809Smarcelnot supported
20171130809Smarcel@item E@var{NN}
20172130809Smarcelfor an error
20173130809Smarcel@end table
20174130809Smarcel
20175130809Smarcel@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
20176130809Smarcel@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
20177130809Smarcel@cindex @code{z2} packet
20178130809Smarcel@cindex @code{Z2} packet
20179130809Smarcel
20180130809SmarcelInsert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
20181130809Smarcel
20182130809SmarcelReply:
20183130809Smarcel@table @samp
20184130809Smarcel@item OK
20185130809Smarcelsuccess
2018698948Sobrien@item
20187130809Smarcelnot supported
20188130809Smarcel@item E@var{NN}
20189130809Smarcelfor an error
20190130809Smarcel@end table
20191130809Smarcel
20192130809Smarcel@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
20193130809Smarcel@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
20194130809Smarcel@cindex @code{z3} packet
20195130809Smarcel@cindex @code{Z3} packet
20196130809Smarcel
20197130809SmarcelInsert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
20198130809Smarcel
20199130809SmarcelReply:
20200130809Smarcel@table @samp
20201130809Smarcel@item OK
20202130809Smarcelsuccess
2020398948Sobrien@item
20204130809Smarcelnot supported
20205130809Smarcel@item E@var{NN}
20206130809Smarcelfor an error
20207130809Smarcel@end table
2020898948Sobrien
20209130809Smarcel@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
20210130809Smarcel@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
20211130809Smarcel@cindex @code{z4} packet
20212130809Smarcel@cindex @code{Z4} packet
2021398948Sobrien
20214130809SmarcelInsert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
2021598948Sobrien
20216130809SmarcelReply:
20217130809Smarcel@table @samp
20218130809Smarcel@item OK
20219130809Smarcelsuccess
20220130809Smarcel@item
20221130809Smarcelnot supported
20222130809Smarcel@item E@var{NN}
20223130809Smarcelfor an error
20224130809Smarcel@end table
20225130809Smarcel
20226130809Smarcel@end table
20227130809Smarcel
20228130809Smarcel@node Stop Reply Packets
20229130809Smarcel@section Stop Reply Packets
20230130809Smarcel@cindex stop reply packets
20231130809Smarcel
2023298948SobrienThe @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
2023398948Sobrienreceive any of the below as a reply.  In the case of the @samp{C},
2023498948Sobrien@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
2023598948Sobrienwhen the target halts.  In the below the exact meaning of @samp{signal
2023698948Sobriennumber} is poorly defined.  In general one of the UNIX signal numbering
2023798948Sobrienconventions is used.
2023898948Sobrien
20239130809Smarcel@table @samp
2024098948Sobrien
20241130809Smarcel@item S@var{AA}
20242130809Smarcel@var{AA} is the signal number
2024398948Sobrien
2024498948Sobrien@item @code{T}@var{AA}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}
20245130809Smarcel@cindex @code{T} packet reply
20246130809Smarcel
2024798948Sobrien@var{AA} = two hex digit signal number; @var{n...} = register number
2024898948Sobrien(hex), @var{r...}  = target byte ordered register contents, size defined
20249130809Smarcelby @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
20250130809Smarcel@var{r...} = thread process ID, this is a hex integer; @var{n...} =
20251130809Smarcel(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
20252130809Smarceladdress, this is a hex integer; @var{n...} = other string not starting
20253130809Smarcelwith valid hex digit.  @value{GDBN} should ignore this @var{n...},
20254130809Smarcel@var{r...} pair and go on to the next.  This way we can extend the
20255130809Smarcelprotocol.
2025698948Sobrien
20257130809Smarcel@item W@var{AA}
20258130809Smarcel
2025998948SobrienThe process exited, and @var{AA} is the exit status.  This is only
20260130809Smarcelapplicable to certain targets.
2026198948Sobrien
20262130809Smarcel@item X@var{AA}
20263130809Smarcel
2026498948SobrienThe process terminated with signal @var{AA}.
2026598948Sobrien
20266130809Smarcel@item O@var{XX@dots{}}
2026798948Sobrien
20268130809Smarcel@var{XX@dots{}} is hex encoding of @sc{ascii} data.  This can happen at
20269130809Smarcelany time while the program is running and the debugger should continue
20270130809Smarcelto wait for @samp{W}, @samp{T}, etc.
2027198948Sobrien
20272130809Smarcel@item F@var{call-id}@code{,}@var{parameter@dots{}}
2027398948Sobrien
20274130809Smarcel@var{call-id} is the identifier which says which host system call should
20275130809Smarcelbe called.  This is just the name of the function.  Translation into the
20276130809Smarcelcorrect system call is only applicable as it's defined in @value{GDBN}.
20277130809Smarcel@xref{File-I/O remote protocol extension}, for a list of implemented
20278130809Smarcelsystem calls.
20279130809Smarcel
20280130809Smarcel@var{parameter@dots{}} is a list of parameters as defined for this very
20281130809Smarcelsystem call.
20282130809Smarcel
20283130809SmarcelThe target replies with this packet when it expects @value{GDBN} to call
20284130809Smarcela host system call on behalf of the target.  @value{GDBN} replies with
20285130809Smarcelan appropriate @code{F} packet and keeps up waiting for the next reply
20286130809Smarcelpacket from the target.  The latest @samp{C}, @samp{c}, @samp{S} or
20287130809Smarcel@samp{s} action is expected to be continued.
20288130809Smarcel@xref{File-I/O remote protocol extension}, for more details.
20289130809Smarcel
20290130809Smarcel@end table
20291130809Smarcel
20292130809Smarcel@node General Query Packets
20293130809Smarcel@section General Query Packets
20294130809Smarcel
2029598948SobrienThe following set and query packets have already been defined.
2029698948Sobrien
20297130809Smarcel@table @r
2029898948Sobrien
20299130809Smarcel@item @code{q}@code{C} --- current thread
20300130809Smarcel
20301130809SmarcelReturn the current thread id.
20302130809Smarcel
20303130809SmarcelReply:
20304130809Smarcel@table @samp
20305130809Smarcel@item @code{QC}@var{pid}
2030698948SobrienWhere @var{pid} is a HEX encoded 16 bit process id.
20307130809Smarcel@item *
20308130809SmarcelAny other reply implies the old pid.
20309130809Smarcel@end table
2031098948Sobrien
20311130809Smarcel@item @code{q}@code{fThreadInfo} -- all thread ids
20312130809Smarcel
20313130809Smarcel@code{q}@code{sThreadInfo}
20314130809Smarcel
2031598948SobrienObtain a list of active thread ids from the target (OS).  Since there
2031698948Sobrienmay be too many active threads to fit into one reply packet, this query
2031798948Sobrienworks iteratively: it may require more than one query/reply sequence to
2031898948Sobrienobtain the entire list of threads.  The first query of the sequence will
2031998948Sobrienbe the @code{qf}@code{ThreadInfo} query; subsequent queries in the
2032098948Sobriensequence will be the @code{qs}@code{ThreadInfo} query.
20321130809Smarcel
20322130809SmarcelNOTE: replaces the @code{qL} query (see below).
20323130809Smarcel
20324130809SmarcelReply:
20325130809Smarcel@table @samp
20326130809Smarcel@item @code{m}@var{id}
20327130809SmarcelA single thread id
20328130809Smarcel@item @code{m}@var{id},@var{id}@dots{}
20329130809Smarcela comma-separated list of thread ids
20330130809Smarcel@item @code{l}
20331130809Smarcel(lower case 'el') denotes end of list.
20332130809Smarcel@end table
20333130809Smarcel
20334130809SmarcelIn response to each query, the target will reply with a list of one or
20335130809Smarcelmore thread ids, in big-endian hex, separated by commas.  @value{GDBN}
20336130809Smarcelwill respond to each reply with a request for more thread ids (using the
2033798948Sobrien@code{qs} form of the query), until the target responds with @code{l}
2033898948Sobrien(lower-case el, for @code{'last'}).
2033998948Sobrien
20340130809Smarcel@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
20341130809Smarcel
20342130809SmarcelWhere @var{id} is a thread-id in big-endian hex.  Obtain a printable
20343130809Smarcelstring description of a thread's attributes from the target OS.  This
20344130809Smarcelstring may contain anything that the target OS thinks is interesting for
20345130809Smarcel@value{GDBN} to tell the user about the thread.  The string is displayed
20346130809Smarcelin @value{GDBN}'s @samp{info threads} display.  Some examples of
20347130809Smarcelpossible thread extra info strings are ``Runnable'', or ``Blocked on
20348130809SmarcelMutex''.
20349130809Smarcel
20350130809SmarcelReply:
20351130809Smarcel@table @samp
20352130809Smarcel@item @var{XX@dots{}}
20353130809SmarcelWhere @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
20354130809Smarcelthe printable string containing the extra information about the thread's
2035598948Sobrienattributes.
20356130809Smarcel@end table
2035798948Sobrien
20358130809Smarcel@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
20359130809Smarcel
2036098948SobrienObtain thread information from RTOS.  Where: @var{startflag} (one hex
2036198948Sobriendigit) is one to indicate the first query and zero to indicate a
2036298948Sobriensubsequent query; @var{threadcount} (two hex digits) is the maximum
2036398948Sobriennumber of threads the response packet can contain; and @var{nextthread}
2036498948Sobrien(eight hex digits), for subsequent queries (@var{startflag} is zero), is
2036598948Sobrienreturned in the response as @var{argthread}.
20366130809Smarcel
20367130809SmarcelNOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
20368130809Smarcel(see above).
20369130809Smarcel
20370130809SmarcelReply:
20371130809Smarcel@table @samp
20372130809Smarcel@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
2037398948SobrienWhere: @var{count} (two hex digits) is the number of threads being
2037498948Sobrienreturned; @var{done} (one hex digit) is zero to indicate more threads
2037598948Sobrienand one indicates no further threads; @var{argthreadid} (eight hex
20376130809Smarceldigits) is @var{nextthread} from the request packet; @var{thread@dots{}}
20377130809Smarcelis a sequence of thread IDs from the target.  @var{threadid} (eight hex
2037898948Sobriendigits).  See @code{remote.c:parse_threadlist_response()}.
20379130809Smarcel@end table
2038098948Sobrien
20381130809Smarcel@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
2038298948Sobrien
20383130809SmarcelReply:
20384130809Smarcel@table @samp
20385130809Smarcel@item @code{E}@var{NN}
20386130809SmarcelAn error (such as memory fault)
20387130809Smarcel@item @code{C}@var{CRC32}
20388130809SmarcelA 32 bit cyclic redundancy check of the specified memory region.
20389130809Smarcel@end table
20390130809Smarcel
20391130809Smarcel@item @code{q}@code{Offsets} --- query sect offs
20392130809Smarcel
2039398948SobrienGet section offsets that the target used when re-locating the downloaded
2039498948Sobrienimage.  @emph{Note: while a @code{Bss} offset is included in the
2039598948Sobrienresponse, @value{GDBN} ignores this and instead applies the @code{Data}
2039698948Sobrienoffset to the @code{Bss} section.}
2039798948Sobrien
20398130809SmarcelReply:
20399130809Smarcel@table @samp
20400130809Smarcel@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
20401130809Smarcel@end table
20402130809Smarcel
20403130809Smarcel@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
20404130809Smarcel
2040598948SobrienReturns information on @var{threadid}.  Where: @var{mode} is a hex
2040698948Sobrienencoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
20407130809Smarcel
20408130809SmarcelReply:
20409130809Smarcel@table @samp
20410130809Smarcel@item *
20411130809Smarcel@end table
20412130809Smarcel
2041398948SobrienSee @code{remote.c:remote_unpack_thread_info_response()}.
2041498948Sobrien
20415130809Smarcel@item @code{q}@code{Rcmd,}@var{command} --- remote command
20416130809Smarcel
20417130809Smarcel@var{command} (hex encoded) is passed to the local interpreter for
2041898948Sobrienexecution.  Invalid commands should be reported using the output string.
2041998948SobrienBefore the final result packet, the target may also respond with a
20420130809Smarcelnumber of intermediate @code{O}@var{output} console output packets.
20421130809Smarcel@emph{Implementors should note that providing access to a stubs's
20422130809Smarcelinterpreter may have security implications}.
20423130809Smarcel
20424130809SmarcelReply:
20425130809Smarcel@table @samp
20426130809Smarcel@item OK
2042798948SobrienA command response with no output.
20428130809Smarcel@item @var{OUTPUT}
2042998948SobrienA command response with the hex encoded output string @var{OUTPUT}.
20430130809Smarcel@item @code{E}@var{NN}
2043198948SobrienIndicate a badly formed request.
20432130809Smarcel@item @samp{}
2043398948SobrienWhen @samp{q}@samp{Rcmd} is not recognized.
20434130809Smarcel@end table
2043598948Sobrien
20436130809Smarcel@item @code{qSymbol::} --- symbol lookup
20437130809Smarcel
2043898948SobrienNotify the target that @value{GDBN} is prepared to serve symbol lookup
2043998948Sobrienrequests.  Accept requests from the target for the values of symbols.
20440130809Smarcel
20441130809SmarcelReply:
20442130809Smarcel@table @samp
20443130809Smarcel@item @code{OK}
2044498948SobrienThe target does not need to look up any (more) symbols.
20445130809Smarcel@item @code{qSymbol:}@var{sym_name}
20446130809SmarcelThe target requests the value of symbol @var{sym_name} (hex encoded).
20447130809Smarcel@value{GDBN} may provide the value by using the
20448130809Smarcel@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
20449130809Smarcel@end table
2045098948Sobrien
20451130809Smarcel@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
20452130809Smarcel
20453130809SmarcelSet the value of @var{sym_name} to @var{sym_value}.
20454130809Smarcel
20455130809Smarcel@var{sym_name} (hex encoded) is the name of a symbol whose value the
20456130809Smarceltarget has previously requested.
20457130809Smarcel
20458130809Smarcel@var{sym_value} (hex) is the value for symbol @var{sym_name}.  If
20459130809Smarcel@value{GDBN} cannot supply a value for @var{sym_name}, then this field
20460130809Smarcelwill be empty.
20461130809Smarcel
20462130809SmarcelReply:
20463130809Smarcel@table @samp
20464130809Smarcel@item @code{OK}
2046598948SobrienThe target does not need to look up any (more) symbols.
20466130809Smarcel@item @code{qSymbol:}@var{sym_name}
20467130809SmarcelThe target requests the value of a new symbol @var{sym_name} (hex
20468130809Smarcelencoded).  @value{GDBN} will continue to supply the values of symbols
20469130809Smarcel(if available), until the target ceases to request them.
20470130809Smarcel@end table
2047198948Sobrien
20472130809Smarcel@item @code{qPart}:@var{object}:@code{read}:@var{annex}:@var{offset},@var{length} --- read special data
2047398948Sobrien
20474130809SmarcelRead uninterpreted bytes from the target's special data area
20475130809Smarcelidentified by the keyword @code{object}.
20476130809SmarcelRequest @var{length} bytes starting at @var{offset} bytes into the data.
20477130809SmarcelThe content and encoding of @var{annex} is specific to the object;
20478130809Smarcelit can supply additional details about what data to access.
20479130809Smarcel
20480130809SmarcelHere are the specific requests of this form defined so far.
20481130809SmarcelAll @samp{@code{qPart}:@var{object}:@code{read}:@dots{}}
20482130809Smarcelrequests use the same reply formats, listed below.
20483130809Smarcel
20484130809Smarcel@table @asis
20485130809Smarcel@item @code{qPart}:@code{auxv}:@code{read}::@var{offset},@var{length}
20486130809SmarcelAccess the target's @dfn{auxiliary vector}.  @xref{Auxiliary Vector}.
20487130809SmarcelNote @var{annex} must be empty.
20488130809Smarcel@end table
20489130809Smarcel
20490130809SmarcelReply:
20491130809Smarcel@table @asis
20492130809Smarcel@item @code{OK}
20493130809SmarcelThe @var{offset} in the request is at the end of the data.
20494130809SmarcelThere is no more data to be read.
20495130809Smarcel
20496130809Smarcel@item @var{XX@dots{}}
20497130809SmarcelHex encoded data bytes read.
20498130809SmarcelThis may be fewer bytes than the @var{length} in the request.
20499130809Smarcel
20500130809Smarcel@item @code{E00}
20501130809SmarcelThe request was malformed, or @var{annex} was invalid.
20502130809Smarcel
20503130809Smarcel@item @code{E}@var{nn}
20504130809SmarcelThe offset was invalid, or there was an error encountered reading the data.
20505130809Smarcel@var{nn} is a hex-encoded @code{errno} value.
20506130809Smarcel
20507130809Smarcel@item @code{""} (empty)
20508130809SmarcelAn empty reply indicates the @var{object} or @var{annex} string was not
20509130809Smarcelrecognized by the stub.
20510130809Smarcel@end table
20511130809Smarcel
20512130809Smarcel@item @code{qPart}:@var{object}:@code{write}:@var{annex}:@var{offset}:@var{data@dots{}}
20513130809Smarcel
20514130809SmarcelWrite uninterpreted bytes into the target's special data area
20515130809Smarcelidentified by the keyword @code{object},
20516130809Smarcelstarting at @var{offset} bytes into the data.
20517130809Smarcel@var{data@dots{}} is the hex-encoded data to be written.
20518130809SmarcelThe content and encoding of @var{annex} is specific to the object;
20519130809Smarcelit can supply additional details about what data to access.
20520130809Smarcel
20521130809SmarcelNo requests of this form are presently in use.  This specification
20522130809Smarcelserves as a placeholder to document the common format that new
20523130809Smarcelspecific request specifications ought to use.
20524130809Smarcel
20525130809SmarcelReply:
20526130809Smarcel@table @asis
20527130809Smarcel@item @var{nn}
20528130809Smarcel@var{nn} (hex encoded) is the number of bytes written.
20529130809SmarcelThis may be fewer bytes than supplied in the request.
20530130809Smarcel
20531130809Smarcel@item @code{E00}
20532130809SmarcelThe request was malformed, or @var{annex} was invalid.
20533130809Smarcel
20534130809Smarcel@item @code{E}@var{nn}
20535130809SmarcelThe offset was invalid, or there was an error encountered writing the data.
20536130809Smarcel@var{nn} is a hex-encoded @code{errno} value.
20537130809Smarcel
20538130809Smarcel@item @code{""} (empty)
20539130809SmarcelAn empty reply indicates the @var{object} or @var{annex} string was not
20540130809Smarcelrecognized by the stub, or that the object does not support writing.
20541130809Smarcel@end table
20542130809Smarcel
20543130809Smarcel@item @code{qPart}:@var{object}:@var{operation}:@dots{}
20544130809SmarcelRequests of this form may be added in the future.  When a stub does
20545130809Smarcelnot recognize the @var{object} keyword, or its support for
20546130809Smarcel@var{object} does not recognize the @var{operation} keyword,
20547130809Smarcelthe stub must respond with an empty packet.
20548130809Smarcel@end table
20549130809Smarcel
20550130809Smarcel@node Register Packet Format
20551130809Smarcel@section Register Packet Format
20552130809Smarcel
2055398948SobrienThe following @samp{g}/@samp{G} packets have previously been defined.
20554130809SmarcelIn the below, some thirty-two bit registers are transferred as
20555130809Smarcelsixty-four bits.  Those registers should be zero/sign extended (which?)
20556130809Smarcelto fill the space allocated.  Register bytes are transfered in target
20557130809Smarcelbyte order.  The two nibbles within a register byte are transfered
20558130809Smarcelmost-significant - least-significant.
2055998948Sobrien
20560130809Smarcel@table @r
2056198948Sobrien
2056298948Sobrien@item MIPS32
20563130809Smarcel
2056498948SobrienAll registers are transfered as thirty-two bit quantities in the order:
2056598948Sobrien32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
2056698948Sobrienregisters; fsr; fir; fp.
2056798948Sobrien
2056898948Sobrien@item MIPS64
20569130809Smarcel
2057098948SobrienAll registers are transfered as sixty-four bit quantities (including
2057198948Sobrienthirty-two bit registers such as @code{sr}).  The ordering is the same
2057298948Sobrienas @code{MIPS32}.
2057398948Sobrien
20574130809Smarcel@end table
2057598948Sobrien
20576130809Smarcel@node Examples
20577130809Smarcel@section Examples
20578130809Smarcel
2057998948SobrienExample sequence of a target being re-started.  Notice how the restart
2058098948Sobriendoes not get any direct output:
2058198948Sobrien
20582130809Smarcel@smallexample
20583130809Smarcel-> @code{R00}
20584130809Smarcel<- @code{+}
2058598948Sobrien@emph{target restarts}
20586130809Smarcel-> @code{?}
20587130809Smarcel<- @code{+}
20588130809Smarcel<- @code{T001:1234123412341234}
2058998948Sobrien-> @code{+}
20590130809Smarcel@end smallexample
2059198948Sobrien
2059298948SobrienExample sequence of a target being stepped by a single instruction:
2059398948Sobrien
20594130809Smarcel@smallexample
20595130809Smarcel-> @code{G1445@dots{}}
20596130809Smarcel<- @code{+}
20597130809Smarcel-> @code{s}
20598130809Smarcel<- @code{+}
20599130809Smarcel@emph{time passes}
20600130809Smarcel<- @code{T001:1234123412341234}
2060198948Sobrien-> @code{+}
20602130809Smarcel-> @code{g}
2060398948Sobrien<- @code{+}
20604130809Smarcel<- @code{1455@dots{}}
2060598948Sobrien-> @code{+}
20606130809Smarcel@end smallexample
2060798948Sobrien
20608130809Smarcel@node File-I/O remote protocol extension
20609130809Smarcel@section File-I/O remote protocol extension
20610130809Smarcel@cindex File-I/O remote protocol extension
20611130809Smarcel
20612130809Smarcel@menu
20613130809Smarcel* File-I/O Overview::
20614130809Smarcel* Protocol basics::
20615130809Smarcel* The F request packet::
20616130809Smarcel* The F reply packet::
20617130809Smarcel* Memory transfer::
20618130809Smarcel* The Ctrl-C message::
20619130809Smarcel* Console I/O::
20620130809Smarcel* The isatty call::
20621130809Smarcel* The system call::
20622130809Smarcel* List of supported calls::
20623130809Smarcel* Protocol specific representation of datatypes::
20624130809Smarcel* Constants::
20625130809Smarcel* File-I/O Examples::
20626130809Smarcel@end menu
20627130809Smarcel
20628130809Smarcel@node File-I/O Overview
20629130809Smarcel@subsection File-I/O Overview
20630130809Smarcel@cindex file-i/o overview
20631130809Smarcel
20632130809SmarcelThe File I/O remote protocol extension (short: File-I/O) allows the
20633130809Smarceltarget to use the hosts file system and console I/O when calling various
20634130809Smarcelsystem calls.  System calls on the target system are translated into a
20635130809Smarcelremote protocol packet to the host system which then performs the needed
20636130809Smarcelactions and returns with an adequate response packet to the target system.
20637130809SmarcelThis simulates file system operations even on targets that lack file systems.
20638130809Smarcel
20639130809SmarcelThe protocol is defined host- and target-system independent.  It uses
20640130809Smarcelit's own independent representation of datatypes and values.  Both,
20641130809Smarcel@value{GDBN} and the target's @value{GDBN} stub are responsible for
20642130809Smarceltranslating the system dependent values into the unified protocol values
20643130809Smarcelwhen data is transmitted.
20644130809Smarcel
20645130809SmarcelThe communication is synchronous.  A system call is possible only
20646130809Smarcelwhen GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
20647130809Smarcelpackets.  While @value{GDBN} handles the request for a system call,
20648130809Smarcelthe target is stopped to allow deterministic access to the target's
20649130809Smarcelmemory.  Therefore File-I/O is not interuptible by target signals.  It
20650130809Smarcelis possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
20651130809Smarcel
20652130809SmarcelThe target's request to perform a host system call does not finish
20653130809Smarcelthe latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action.  That means,
20654130809Smarcelafter finishing the system call, the target returns to continuing the
20655130809Smarcelprevious activity (continue, step).  No additional continue or step
20656130809Smarcelrequest from @value{GDBN} is required.
20657130809Smarcel
20658130809Smarcel@smallexample
20659130809Smarcel(gdb) continue
20660130809Smarcel  <- target requests 'system call X'
20661130809Smarcel  target is stopped, @value{GDBN} executes system call
20662130809Smarcel  -> GDB returns result
20663130809Smarcel  ... target continues, GDB returns to wait for the target
20664130809Smarcel  <- target hits breakpoint and sends a Txx packet
20665130809Smarcel@end smallexample
20666130809Smarcel
20667130809SmarcelThe protocol is only used for files on the host file system and
20668130809Smarcelfor I/O on the console.  Character or block special devices, pipes,
20669130809Smarcelnamed pipes or sockets or any other communication method on the host
20670130809Smarcelsystem are not supported by this protocol.
20671130809Smarcel
20672130809Smarcel@node Protocol basics
20673130809Smarcel@subsection Protocol basics
20674130809Smarcel@cindex protocol basics, file-i/o
20675130809Smarcel
20676130809SmarcelThe File-I/O protocol uses the @code{F} packet, as request as well
20677130809Smarcelas as reply packet.  Since a File-I/O system call can only occur when
20678130809Smarcel@value{GDBN} is waiting for the continuing or stepping target, the
20679130809SmarcelFile-I/O request is a reply that @value{GDBN} has to expect as a result
20680130809Smarcelof a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
20681130809SmarcelThis @code{F} packet contains all information needed to allow @value{GDBN}
20682130809Smarcelto call the appropriate host system call:
20683130809Smarcel
20684130809Smarcel@itemize @bullet
20685130809Smarcel@item
20686130809SmarcelA unique identifier for the requested system call.
20687130809Smarcel
20688130809Smarcel@item
20689130809SmarcelAll parameters to the system call.  Pointers are given as addresses
20690130809Smarcelin the target memory address space.  Pointers to strings are given as
20691130809Smarcelpointer/length pair.  Numerical values are given as they are.
20692130809SmarcelNumerical control values are given in a protocol specific representation.
20693130809Smarcel
20694130809Smarcel@end itemize
20695130809Smarcel
20696130809SmarcelAt that point @value{GDBN} has to perform the following actions.
20697130809Smarcel
20698130809Smarcel@itemize @bullet
20699130809Smarcel@item
20700130809SmarcelIf parameter pointer values are given, which point to data needed as input
20701130809Smarcelto a system call, @value{GDBN} requests this data from the target with a
20702130809Smarcelstandard @code{m} packet request.  This additional communication has to be
20703130809Smarcelexpected by the target implementation and is handled as any other @code{m}
20704130809Smarcelpacket.
20705130809Smarcel
20706130809Smarcel@item
20707130809Smarcel@value{GDBN} translates all value from protocol representation to host
20708130809Smarcelrepresentation as needed.  Datatypes are coerced into the host types.
20709130809Smarcel
20710130809Smarcel@item
20711130809Smarcel@value{GDBN} calls the system call
20712130809Smarcel
20713130809Smarcel@item
20714130809SmarcelIt then coerces datatypes back to protocol representation.
20715130809Smarcel
20716130809Smarcel@item
20717130809SmarcelIf pointer parameters in the request packet point to buffer space in which
20718130809Smarcela system call is expected to copy data to, the data is transmitted to the
20719130809Smarceltarget using a @code{M} or @code{X} packet.  This packet has to be expected
20720130809Smarcelby the target implementation and is handled as any other @code{M} or @code{X}
20721130809Smarcelpacket.
20722130809Smarcel
20723130809Smarcel@end itemize
20724130809Smarcel
20725130809SmarcelEventually @value{GDBN} replies with another @code{F} packet which contains all
20726130809Smarcelnecessary information for the target to continue.  This at least contains
20727130809Smarcel
20728130809Smarcel@itemize @bullet
20729130809Smarcel@item
20730130809SmarcelReturn value.
20731130809Smarcel
20732130809Smarcel@item
20733130809Smarcel@code{errno}, if has been changed by the system call.
20734130809Smarcel
20735130809Smarcel@item
20736130809Smarcel``Ctrl-C'' flag.
20737130809Smarcel
20738130809Smarcel@end itemize
20739130809Smarcel
20740130809SmarcelAfter having done the needed type and value coercion, the target continues
20741130809Smarcelthe latest continue or step action.
20742130809Smarcel
20743130809Smarcel@node The F request packet
20744130809Smarcel@subsection The @code{F} request packet
20745130809Smarcel@cindex file-i/o request packet
20746130809Smarcel@cindex @code{F} request packet
20747130809Smarcel
20748130809SmarcelThe @code{F} request packet has the following format:
20749130809Smarcel
20750130809Smarcel@table @samp
20751130809Smarcel
20752130809Smarcel@smallexample
20753130809Smarcel@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
20754130809Smarcel@end smallexample
20755130809Smarcel
20756130809Smarcel@var{call-id} is the identifier to indicate the host system call to be called.
20757130809SmarcelThis is just the name of the function.
20758130809Smarcel
20759130809Smarcel@var{parameter@dots{}} are the parameters to the system call.
20760130809Smarcel
20761130809Smarcel@end table
20762130809Smarcel
20763130809SmarcelParameters are hexadecimal integer values, either the real values in case
20764130809Smarcelof scalar datatypes, as pointers to target buffer space in case of compound
20765130809Smarceldatatypes and unspecified memory areas or as pointer/length pairs in case
20766130809Smarcelof string parameters.  These are appended to the call-id, each separated
20767130809Smarcelfrom its predecessor by a comma.  All values are transmitted in ASCII
20768130809Smarcelstring representation, pointer/length pairs separated by a slash.
20769130809Smarcel
20770130809Smarcel@node The F reply packet
20771130809Smarcel@subsection The @code{F} reply packet
20772130809Smarcel@cindex file-i/o reply packet
20773130809Smarcel@cindex @code{F} reply packet
20774130809Smarcel
20775130809SmarcelThe @code{F} reply packet has the following format:
20776130809Smarcel
20777130809Smarcel@table @samp
20778130809Smarcel
20779130809Smarcel@smallexample
20780130809Smarcel@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
20781130809Smarcel@end smallexample
20782130809Smarcel
20783130809Smarcel@var{retcode} is the return code of the system call as hexadecimal value.
20784130809Smarcel
20785130809Smarcel@var{errno} is the errno set by the call, in protocol specific representation.
20786130809SmarcelThis parameter can be omitted if the call was successful.
20787130809Smarcel
20788130809Smarcel@var{Ctrl-C flag} is only send if the user requested a break.  In this
20789130809Smarcelcase, @var{errno} must be send as well, even if the call was successful.
20790130809SmarcelThe @var{Ctrl-C flag} itself consists of the character 'C':
20791130809Smarcel
20792130809Smarcel@smallexample
20793130809SmarcelF0,0,C
20794130809Smarcel@end smallexample
20795130809Smarcel
20796130809Smarcel@noindent
20797130809Smarcelor, if the call was interupted before the host call has been performed:
20798130809Smarcel
20799130809Smarcel@smallexample
20800130809SmarcelF-1,4,C
20801130809Smarcel@end smallexample
20802130809Smarcel
20803130809Smarcel@noindent
20804130809Smarcelassuming 4 is the protocol specific representation of @code{EINTR}.
20805130809Smarcel
20806130809Smarcel@end table
20807130809Smarcel
20808130809Smarcel@node Memory transfer
20809130809Smarcel@subsection Memory transfer
20810130809Smarcel@cindex memory transfer, in file-i/o protocol
20811130809Smarcel
20812130809SmarcelStructured data which is transferred using a memory read or write as e.g.@:
20813130809Smarcela @code{struct stat} is expected to be in a protocol specific format with
20814130809Smarcelall scalar multibyte datatypes being big endian.  This should be done by
20815130809Smarcelthe target before the @code{F} packet is sent resp.@: by @value{GDBN} before
20816130809Smarcelit transfers memory to the target.  Transferred pointers to structured
20817130809Smarceldata should point to the already coerced data at any time.
20818130809Smarcel
20819130809Smarcel@node The Ctrl-C message
20820130809Smarcel@subsection The Ctrl-C message
20821130809Smarcel@cindex ctrl-c message, in file-i/o protocol
20822130809Smarcel
20823130809SmarcelA special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
20824130809Smarcelreply packet.  In this case the target should behave, as if it had
20825130809Smarcelgotten a break message.  The meaning for the target is ``system call
20826130809Smarcelinterupted by @code{SIGINT}''.  Consequentially, the target should actually stop
20827130809Smarcel(as with a break message) and return to @value{GDBN} with a @code{T02}
20828130809Smarcelpacket.  In this case, it's important for the target to know, in which
20829130809Smarcelstate the system call was interrupted.  Since this action is by design
20830130809Smarcelnot an atomic operation, we have to differ between two cases:
20831130809Smarcel
20832130809Smarcel@itemize @bullet
20833130809Smarcel@item
20834130809SmarcelThe system call hasn't been performed on the host yet.
20835130809Smarcel
20836130809Smarcel@item
20837130809SmarcelThe system call on the host has been finished.
20838130809Smarcel
20839130809Smarcel@end itemize
20840130809Smarcel
20841130809SmarcelThese two states can be distinguished by the target by the value of the
20842130809Smarcelreturned @code{errno}.  If it's the protocol representation of @code{EINTR}, the system
20843130809Smarcelcall hasn't been performed.  This is equivalent to the @code{EINTR} handling
20844130809Smarcelon POSIX systems.  In any other case, the target may presume that the
20845130809Smarcelsystem call has been finished --- successful or not --- and should behave
20846130809Smarcelas if the break message arrived right after the system call.
20847130809Smarcel
20848130809Smarcel@value{GDBN} must behave reliable.  If the system call has not been called
20849130809Smarcelyet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
20850130809Smarcel@code{errno} in the packet.  If the system call on the host has been finished
20851130809Smarcelbefore the user requests a break, the full action must be finshed by
20852130809Smarcel@value{GDBN}.  This requires sending @code{M} or @code{X} packets as they fit.
20853130809SmarcelThe @code{F} packet may only be send when either nothing has happened
20854130809Smarcelor the full action has been completed.
20855130809Smarcel
20856130809Smarcel@node Console I/O
20857130809Smarcel@subsection Console I/O
20858130809Smarcel@cindex console i/o as part of file-i/o
20859130809Smarcel
20860130809SmarcelBy default and if not explicitely closed by the target system, the file
20861130809Smarceldescriptors 0, 1 and 2 are connected to the @value{GDBN} console.  Output
20862130809Smarcelon the @value{GDBN} console is handled as any other file output operation
20863130809Smarcel(@code{write(1, @dots{})} or @code{write(2, @dots{})}).  Console input is handled
20864130809Smarcelby @value{GDBN} so that after the target read request from file descriptor
20865130809Smarcel0 all following typing is buffered until either one of the following
20866130809Smarcelconditions is met:
20867130809Smarcel
20868130809Smarcel@itemize @bullet
20869130809Smarcel@item
20870130809SmarcelThe user presses @kbd{Ctrl-C}.  The behaviour is as explained above, the
20871130809Smarcel@code{read}
20872130809Smarcelsystem call is treated as finished.
20873130809Smarcel
20874130809Smarcel@item
20875130809SmarcelThe user presses @kbd{Enter}.  This is treated as end of input with a trailing
20876130809Smarcelline feed.
20877130809Smarcel
20878130809Smarcel@item
20879130809SmarcelThe user presses @kbd{Ctrl-D}.  This is treated as end of input.  No trailing
20880130809Smarcelcharacter, especially no Ctrl-D is appended to the input.
20881130809Smarcel
20882130809Smarcel@end itemize
20883130809Smarcel
20884130809SmarcelIf the user has typed more characters as fit in the buffer given to
20885130809Smarcelthe read call, the trailing characters are buffered in @value{GDBN} until
20886130809Smarceleither another @code{read(0, @dots{})} is requested by the target or debugging
20887130809Smarcelis stopped on users request.
20888130809Smarcel
20889130809Smarcel@node The isatty call
20890130809Smarcel@subsection The isatty(3) call
20891130809Smarcel@cindex isatty call, file-i/o protocol
20892130809Smarcel
20893130809SmarcelA special case in this protocol is the library call @code{isatty} which
20894130809Smarcelis implemented as it's own call inside of this protocol.  It returns
20895130809Smarcel1 to the target if the file descriptor given as parameter is attached
20896130809Smarcelto the @value{GDBN} console, 0 otherwise.  Implementing through system calls
20897130809Smarcelwould require implementing @code{ioctl} and would be more complex than
20898130809Smarcelneeded.
20899130809Smarcel
20900130809Smarcel@node The system call
20901130809Smarcel@subsection The system(3) call
20902130809Smarcel@cindex system call, file-i/o protocol
20903130809Smarcel
20904130809SmarcelThe other special case in this protocol is the @code{system} call which
20905130809Smarcelis implemented as it's own call, too.  @value{GDBN} is taking over the full
20906130809Smarceltask of calling the necessary host calls to perform the @code{system}
20907130809Smarcelcall.  The return value of @code{system} is simplified before it's returned
20908130809Smarcelto the target.  Basically, the only signal transmitted back is @code{EINTR}
20909130809Smarcelin case the user pressed @kbd{Ctrl-C}.  Otherwise the return value consists
20910130809Smarcelentirely of the exit status of the called command.
20911130809Smarcel
20912130809SmarcelDue to security concerns, the @code{system} call is refused to be called
20913130809Smarcelby @value{GDBN} by default.  The user has to allow this call explicitly by
20914130809Smarcelentering
20915130809Smarcel
20916130809Smarcel@table @samp
20917130809Smarcel@kindex set remote system-call-allowed 1
20918130809Smarcel@item @code{set remote system-call-allowed 1}
20919130809Smarcel@end table
20920130809Smarcel
20921130809SmarcelDisabling the @code{system} call is done by
20922130809Smarcel
20923130809Smarcel@table @samp
20924130809Smarcel@kindex set remote system-call-allowed 0
20925130809Smarcel@item @code{set remote system-call-allowed 0}
20926130809Smarcel@end table
20927130809Smarcel
20928130809SmarcelThe current setting is shown by typing
20929130809Smarcel
20930130809Smarcel@table @samp
20931130809Smarcel@kindex show remote system-call-allowed
20932130809Smarcel@item @code{show remote system-call-allowed}
20933130809Smarcel@end table
20934130809Smarcel
20935130809Smarcel@node List of supported calls
20936130809Smarcel@subsection List of supported calls
20937130809Smarcel@cindex list of supported file-i/o calls
20938130809Smarcel
20939130809Smarcel@menu
20940130809Smarcel* open::
20941130809Smarcel* close::
20942130809Smarcel* read::
20943130809Smarcel* write::
20944130809Smarcel* lseek::
20945130809Smarcel* rename::
20946130809Smarcel* unlink::
20947130809Smarcel* stat/fstat::
20948130809Smarcel* gettimeofday::
20949130809Smarcel* isatty::
20950130809Smarcel* system::
20951130809Smarcel@end menu
20952130809Smarcel
20953130809Smarcel@node open
20954130809Smarcel@unnumberedsubsubsec open
20955130809Smarcel@cindex open, file-i/o system call
20956130809Smarcel
20957130809Smarcel@smallexample
20958130809Smarcel@exdent Synopsis:
20959130809Smarcelint open(const char *pathname, int flags);
20960130809Smarcelint open(const char *pathname, int flags, mode_t mode);
20961130809Smarcel
20962130809Smarcel@exdent Request:
20963130809SmarcelFopen,pathptr/len,flags,mode
20964130809Smarcel@end smallexample
20965130809Smarcel
20966130809Smarcel@noindent
20967130809Smarcel@code{flags} is the bitwise or of the following values:
20968130809Smarcel
20969130809Smarcel@table @code
20970130809Smarcel@item O_CREAT
20971130809SmarcelIf the file does not exist it will be created.  The host
20972130809Smarcelrules apply as far as file ownership and time stamps
20973130809Smarcelare concerned.
20974130809Smarcel
20975130809Smarcel@item O_EXCL
20976130809SmarcelWhen used with O_CREAT, if the file already exists it is
20977130809Smarcelan error and open() fails.
20978130809Smarcel
20979130809Smarcel@item O_TRUNC
20980130809SmarcelIf the file already exists and the open mode allows
20981130809Smarcelwriting (O_RDWR or O_WRONLY is given) it will be
20982130809Smarceltruncated to length 0.
20983130809Smarcel
20984130809Smarcel@item O_APPEND
20985130809SmarcelThe file is opened in append mode.
20986130809Smarcel
20987130809Smarcel@item O_RDONLY
20988130809SmarcelThe file is opened for reading only.
20989130809Smarcel
20990130809Smarcel@item O_WRONLY
20991130809SmarcelThe file is opened for writing only.
20992130809Smarcel
20993130809Smarcel@item O_RDWR
20994130809SmarcelThe file is opened for reading and writing.
20995130809Smarcel
20996130809Smarcel@noindent
20997130809SmarcelEach other bit is silently ignored.
20998130809Smarcel
20999130809Smarcel@end table
21000130809Smarcel
21001130809Smarcel@noindent
21002130809Smarcel@code{mode} is the bitwise or of the following values:
21003130809Smarcel
21004130809Smarcel@table @code
21005130809Smarcel@item S_IRUSR
21006130809SmarcelUser has read permission.
21007130809Smarcel
21008130809Smarcel@item S_IWUSR
21009130809SmarcelUser has write permission.
21010130809Smarcel
21011130809Smarcel@item S_IRGRP
21012130809SmarcelGroup has read permission.
21013130809Smarcel
21014130809Smarcel@item S_IWGRP
21015130809SmarcelGroup has write permission.
21016130809Smarcel
21017130809Smarcel@item S_IROTH
21018130809SmarcelOthers have read permission.
21019130809Smarcel
21020130809Smarcel@item S_IWOTH
21021130809SmarcelOthers have write permission.
21022130809Smarcel
21023130809Smarcel@noindent
21024130809SmarcelEach other bit is silently ignored.
21025130809Smarcel
21026130809Smarcel@end table
21027130809Smarcel
21028130809Smarcel@smallexample
21029130809Smarcel@exdent Return value:
21030130809Smarcelopen returns the new file descriptor or -1 if an error
21031130809Smarceloccured.
21032130809Smarcel
21033130809Smarcel@exdent Errors:
21034130809Smarcel@end smallexample
21035130809Smarcel
21036130809Smarcel@table @code
21037130809Smarcel@item EEXIST
21038130809Smarcelpathname already exists and O_CREAT and O_EXCL were used.
21039130809Smarcel
21040130809Smarcel@item EISDIR
21041130809Smarcelpathname refers to a directory.
21042130809Smarcel
21043130809Smarcel@item EACCES
21044130809SmarcelThe requested access is not allowed.
21045130809Smarcel
21046130809Smarcel@item ENAMETOOLONG
21047130809Smarcelpathname was too long.
21048130809Smarcel
21049130809Smarcel@item ENOENT
21050130809SmarcelA directory component in pathname does not exist.
21051130809Smarcel
21052130809Smarcel@item ENODEV
21053130809Smarcelpathname refers to a device, pipe, named pipe or socket.
21054130809Smarcel
21055130809Smarcel@item EROFS
21056130809Smarcelpathname refers to a file on a read-only filesystem and
21057130809Smarcelwrite access was requested.
21058130809Smarcel
21059130809Smarcel@item EFAULT
21060130809Smarcelpathname is an invalid pointer value.
21061130809Smarcel
21062130809Smarcel@item ENOSPC
21063130809SmarcelNo space on device to create the file.
21064130809Smarcel
21065130809Smarcel@item EMFILE
21066130809SmarcelThe process already has the maximum number of files open.
21067130809Smarcel
21068130809Smarcel@item ENFILE
21069130809SmarcelThe limit on the total number of files open on the system
21070130809Smarcelhas been reached.
21071130809Smarcel
21072130809Smarcel@item EINTR
21073130809SmarcelThe call was interrupted by the user.
21074130809Smarcel@end table
21075130809Smarcel
21076130809Smarcel@node close
21077130809Smarcel@unnumberedsubsubsec close
21078130809Smarcel@cindex close, file-i/o system call
21079130809Smarcel
21080130809Smarcel@smallexample
21081130809Smarcel@exdent Synopsis:
21082130809Smarcelint close(int fd);
21083130809Smarcel
21084130809Smarcel@exdent Request:
21085130809SmarcelFclose,fd
21086130809Smarcel
21087130809Smarcel@exdent Return value:
21088130809Smarcelclose returns zero on success, or -1 if an error occurred.
21089130809Smarcel
21090130809Smarcel@exdent Errors:
21091130809Smarcel@end smallexample
21092130809Smarcel
21093130809Smarcel@table @code
21094130809Smarcel@item EBADF
21095130809Smarcelfd isn't a valid open file descriptor.
21096130809Smarcel
21097130809Smarcel@item EINTR
21098130809SmarcelThe call was interrupted by the user.
21099130809Smarcel@end table
21100130809Smarcel
21101130809Smarcel@node read
21102130809Smarcel@unnumberedsubsubsec read
21103130809Smarcel@cindex read, file-i/o system call
21104130809Smarcel
21105130809Smarcel@smallexample
21106130809Smarcel@exdent Synopsis:
21107130809Smarcelint read(int fd, void *buf, unsigned int count);
21108130809Smarcel
21109130809Smarcel@exdent Request:
21110130809SmarcelFread,fd,bufptr,count
21111130809Smarcel
21112130809Smarcel@exdent Return value:
21113130809SmarcelOn success, the number of bytes read is returned.
21114130809SmarcelZero indicates end of file.  If count is zero, read
21115130809Smarcelreturns zero as well.  On error, -1 is returned.
21116130809Smarcel
21117130809Smarcel@exdent Errors:
21118130809Smarcel@end smallexample
21119130809Smarcel
21120130809Smarcel@table @code
21121130809Smarcel@item EBADF
21122130809Smarcelfd is not a valid file descriptor or is not open for
21123130809Smarcelreading.
21124130809Smarcel
21125130809Smarcel@item EFAULT
21126130809Smarcelbuf is an invalid pointer value.
21127130809Smarcel
21128130809Smarcel@item EINTR
21129130809SmarcelThe call was interrupted by the user.
21130130809Smarcel@end table
21131130809Smarcel
21132130809Smarcel@node write
21133130809Smarcel@unnumberedsubsubsec write
21134130809Smarcel@cindex write, file-i/o system call
21135130809Smarcel
21136130809Smarcel@smallexample
21137130809Smarcel@exdent Synopsis:
21138130809Smarcelint write(int fd, const void *buf, unsigned int count);
21139130809Smarcel
21140130809Smarcel@exdent Request:
21141130809SmarcelFwrite,fd,bufptr,count
21142130809Smarcel
21143130809Smarcel@exdent Return value:
21144130809SmarcelOn success, the number of bytes written are returned.
21145130809SmarcelZero indicates nothing was written.  On error, -1
21146130809Smarcelis returned.
21147130809Smarcel
21148130809Smarcel@exdent Errors:
21149130809Smarcel@end smallexample
21150130809Smarcel
21151130809Smarcel@table @code
21152130809Smarcel@item EBADF
21153130809Smarcelfd is not a valid file descriptor or is not open for
21154130809Smarcelwriting.
21155130809Smarcel
21156130809Smarcel@item EFAULT
21157130809Smarcelbuf is an invalid pointer value.
21158130809Smarcel
21159130809Smarcel@item EFBIG
21160130809SmarcelAn attempt was made to write a file that exceeds the
21161130809Smarcelhost specific maximum file size allowed.
21162130809Smarcel
21163130809Smarcel@item ENOSPC
21164130809SmarcelNo space on device to write the data.
21165130809Smarcel
21166130809Smarcel@item EINTR
21167130809SmarcelThe call was interrupted by the user.
21168130809Smarcel@end table
21169130809Smarcel
21170130809Smarcel@node lseek
21171130809Smarcel@unnumberedsubsubsec lseek
21172130809Smarcel@cindex lseek, file-i/o system call
21173130809Smarcel
21174130809Smarcel@smallexample
21175130809Smarcel@exdent Synopsis:
21176130809Smarcellong lseek (int fd, long offset, int flag);
21177130809Smarcel
21178130809Smarcel@exdent Request:
21179130809SmarcelFlseek,fd,offset,flag
21180130809Smarcel@end smallexample
21181130809Smarcel
21182130809Smarcel@code{flag} is one of:
21183130809Smarcel
21184130809Smarcel@table @code
21185130809Smarcel@item SEEK_SET
21186130809SmarcelThe offset is set to offset bytes.
21187130809Smarcel
21188130809Smarcel@item SEEK_CUR
21189130809SmarcelThe offset is set to its current location plus offset
21190130809Smarcelbytes.
21191130809Smarcel
21192130809Smarcel@item SEEK_END
21193130809SmarcelThe offset is set to the size of the file plus offset
21194130809Smarcelbytes.
21195130809Smarcel@end table
21196130809Smarcel
21197130809Smarcel@smallexample
21198130809Smarcel@exdent Return value:
21199130809SmarcelOn success, the resulting unsigned offset in bytes from
21200130809Smarcelthe beginning of the file is returned.  Otherwise, a
21201130809Smarcelvalue of -1 is returned.
21202130809Smarcel
21203130809Smarcel@exdent Errors:
21204130809Smarcel@end smallexample
21205130809Smarcel
21206130809Smarcel@table @code
21207130809Smarcel@item EBADF
21208130809Smarcelfd is not a valid open file descriptor.
21209130809Smarcel
21210130809Smarcel@item ESPIPE
21211130809Smarcelfd is associated with the @value{GDBN} console.
21212130809Smarcel
21213130809Smarcel@item EINVAL
21214130809Smarcelflag is not a proper value.
21215130809Smarcel
21216130809Smarcel@item EINTR
21217130809SmarcelThe call was interrupted by the user.
21218130809Smarcel@end table
21219130809Smarcel
21220130809Smarcel@node rename
21221130809Smarcel@unnumberedsubsubsec rename
21222130809Smarcel@cindex rename, file-i/o system call
21223130809Smarcel
21224130809Smarcel@smallexample
21225130809Smarcel@exdent Synopsis:
21226130809Smarcelint rename(const char *oldpath, const char *newpath);
21227130809Smarcel
21228130809Smarcel@exdent Request:
21229130809SmarcelFrename,oldpathptr/len,newpathptr/len
21230130809Smarcel
21231130809Smarcel@exdent Return value:
21232130809SmarcelOn success, zero is returned.  On error, -1 is returned.
21233130809Smarcel
21234130809Smarcel@exdent Errors:
21235130809Smarcel@end smallexample
21236130809Smarcel
21237130809Smarcel@table @code
21238130809Smarcel@item EISDIR
21239130809Smarcelnewpath is an existing directory, but oldpath is not a
21240130809Smarceldirectory.
21241130809Smarcel
21242130809Smarcel@item EEXIST
21243130809Smarcelnewpath is a non-empty directory.
21244130809Smarcel
21245130809Smarcel@item EBUSY
21246130809Smarceloldpath or newpath is a directory that is in use by some
21247130809Smarcelprocess.
21248130809Smarcel
21249130809Smarcel@item EINVAL
21250130809SmarcelAn attempt was made to make a directory a subdirectory
21251130809Smarcelof itself.
21252130809Smarcel
21253130809Smarcel@item ENOTDIR
21254130809SmarcelA  component used as a directory in oldpath or new
21255130809Smarcelpath is not a directory.  Or oldpath is a directory
21256130809Smarceland newpath exists but is not a directory.
21257130809Smarcel
21258130809Smarcel@item EFAULT
21259130809Smarceloldpathptr or newpathptr are invalid pointer values.
21260130809Smarcel
21261130809Smarcel@item EACCES
21262130809SmarcelNo access to the file or the path of the file.
21263130809Smarcel
21264130809Smarcel@item ENAMETOOLONG
21265130809Smarcel
21266130809Smarceloldpath or newpath was too long.
21267130809Smarcel
21268130809Smarcel@item ENOENT
21269130809SmarcelA directory component in oldpath or newpath does not exist.
21270130809Smarcel
21271130809Smarcel@item EROFS
21272130809SmarcelThe file is on a read-only filesystem.
21273130809Smarcel
21274130809Smarcel@item ENOSPC
21275130809SmarcelThe device containing the file has no room for the new
21276130809Smarceldirectory entry.
21277130809Smarcel
21278130809Smarcel@item EINTR
21279130809SmarcelThe call was interrupted by the user.
21280130809Smarcel@end table
21281130809Smarcel
21282130809Smarcel@node unlink
21283130809Smarcel@unnumberedsubsubsec unlink
21284130809Smarcel@cindex unlink, file-i/o system call
21285130809Smarcel
21286130809Smarcel@smallexample
21287130809Smarcel@exdent Synopsis:
21288130809Smarcelint unlink(const char *pathname);
21289130809Smarcel
21290130809Smarcel@exdent Request:
21291130809SmarcelFunlink,pathnameptr/len
21292130809Smarcel
21293130809Smarcel@exdent Return value:
21294130809SmarcelOn success, zero is returned.  On error, -1 is returned.
21295130809Smarcel
21296130809Smarcel@exdent Errors:
21297130809Smarcel@end smallexample
21298130809Smarcel
21299130809Smarcel@table @code
21300130809Smarcel@item EACCES
21301130809SmarcelNo access to the file or the path of the file.
21302130809Smarcel
21303130809Smarcel@item EPERM
21304130809SmarcelThe system does not allow unlinking of directories.
21305130809Smarcel
21306130809Smarcel@item EBUSY
21307130809SmarcelThe file pathname cannot be unlinked because it's
21308130809Smarcelbeing used by another process.
21309130809Smarcel
21310130809Smarcel@item EFAULT
21311130809Smarcelpathnameptr is an invalid pointer value.
21312130809Smarcel
21313130809Smarcel@item ENAMETOOLONG
21314130809Smarcelpathname was too long.
21315130809Smarcel
21316130809Smarcel@item ENOENT
21317130809SmarcelA directory component in pathname does not exist.
21318130809Smarcel
21319130809Smarcel@item ENOTDIR
21320130809SmarcelA component of the path is not a directory.
21321130809Smarcel
21322130809Smarcel@item EROFS
21323130809SmarcelThe file is on a read-only filesystem.
21324130809Smarcel
21325130809Smarcel@item EINTR
21326130809SmarcelThe call was interrupted by the user.
21327130809Smarcel@end table
21328130809Smarcel
21329130809Smarcel@node stat/fstat
21330130809Smarcel@unnumberedsubsubsec stat/fstat
21331130809Smarcel@cindex fstat, file-i/o system call
21332130809Smarcel@cindex stat, file-i/o system call
21333130809Smarcel
21334130809Smarcel@smallexample
21335130809Smarcel@exdent Synopsis:
21336130809Smarcelint stat(const char *pathname, struct stat *buf);
21337130809Smarcelint fstat(int fd, struct stat *buf);
21338130809Smarcel
21339130809Smarcel@exdent Request:
21340130809SmarcelFstat,pathnameptr/len,bufptr
21341130809SmarcelFfstat,fd,bufptr
21342130809Smarcel
21343130809Smarcel@exdent Return value:
21344130809SmarcelOn success, zero is returned.  On error, -1 is returned.
21345130809Smarcel
21346130809Smarcel@exdent Errors:
21347130809Smarcel@end smallexample
21348130809Smarcel
21349130809Smarcel@table @code
21350130809Smarcel@item EBADF
21351130809Smarcelfd is not a valid open file.
21352130809Smarcel
21353130809Smarcel@item ENOENT
21354130809SmarcelA directory component in pathname does not exist or the
21355130809Smarcelpath is an empty string.
21356130809Smarcel
21357130809Smarcel@item ENOTDIR
21358130809SmarcelA component of the path is not a directory.
21359130809Smarcel
21360130809Smarcel@item EFAULT
21361130809Smarcelpathnameptr is an invalid pointer value.
21362130809Smarcel
21363130809Smarcel@item EACCES
21364130809SmarcelNo access to the file or the path of the file.
21365130809Smarcel
21366130809Smarcel@item ENAMETOOLONG
21367130809Smarcelpathname was too long.
21368130809Smarcel
21369130809Smarcel@item EINTR
21370130809SmarcelThe call was interrupted by the user.
21371130809Smarcel@end table
21372130809Smarcel
21373130809Smarcel@node gettimeofday
21374130809Smarcel@unnumberedsubsubsec gettimeofday
21375130809Smarcel@cindex gettimeofday, file-i/o system call
21376130809Smarcel
21377130809Smarcel@smallexample
21378130809Smarcel@exdent Synopsis:
21379130809Smarcelint gettimeofday(struct timeval *tv, void *tz);
21380130809Smarcel
21381130809Smarcel@exdent Request:
21382130809SmarcelFgettimeofday,tvptr,tzptr
21383130809Smarcel
21384130809Smarcel@exdent Return value:
21385130809SmarcelOn success, 0 is returned, -1 otherwise.
21386130809Smarcel
21387130809Smarcel@exdent Errors:
21388130809Smarcel@end smallexample
21389130809Smarcel
21390130809Smarcel@table @code
21391130809Smarcel@item EINVAL
21392130809Smarceltz is a non-NULL pointer.
21393130809Smarcel
21394130809Smarcel@item EFAULT
21395130809Smarceltvptr and/or tzptr is an invalid pointer value.
21396130809Smarcel@end table
21397130809Smarcel
21398130809Smarcel@node isatty
21399130809Smarcel@unnumberedsubsubsec isatty
21400130809Smarcel@cindex isatty, file-i/o system call
21401130809Smarcel
21402130809Smarcel@smallexample
21403130809Smarcel@exdent Synopsis:
21404130809Smarcelint isatty(int fd);
21405130809Smarcel
21406130809Smarcel@exdent Request:
21407130809SmarcelFisatty,fd
21408130809Smarcel
21409130809Smarcel@exdent Return value:
21410130809SmarcelReturns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
21411130809Smarcel
21412130809Smarcel@exdent Errors:
21413130809Smarcel@end smallexample
21414130809Smarcel
21415130809Smarcel@table @code
21416130809Smarcel@item EINTR
21417130809SmarcelThe call was interrupted by the user.
21418130809Smarcel@end table
21419130809Smarcel
21420130809Smarcel@node system
21421130809Smarcel@unnumberedsubsubsec system
21422130809Smarcel@cindex system, file-i/o system call
21423130809Smarcel
21424130809Smarcel@smallexample
21425130809Smarcel@exdent Synopsis:
21426130809Smarcelint system(const char *command);
21427130809Smarcel
21428130809Smarcel@exdent Request:
21429130809SmarcelFsystem,commandptr/len
21430130809Smarcel
21431130809Smarcel@exdent Return value:
21432130809SmarcelThe value returned is -1 on error and the return status
21433130809Smarcelof the command otherwise.  Only the exit status of the
21434130809Smarcelcommand is returned, which is extracted from the hosts
21435130809Smarcelsystem return value by calling WEXITSTATUS(retval).
21436130809SmarcelIn case /bin/sh could not be executed, 127 is returned.
21437130809Smarcel
21438130809Smarcel@exdent Errors:
21439130809Smarcel@end smallexample
21440130809Smarcel
21441130809Smarcel@table @code
21442130809Smarcel@item EINTR
21443130809SmarcelThe call was interrupted by the user.
21444130809Smarcel@end table
21445130809Smarcel
21446130809Smarcel@node Protocol specific representation of datatypes
21447130809Smarcel@subsection Protocol specific representation of datatypes
21448130809Smarcel@cindex protocol specific representation of datatypes, in file-i/o protocol
21449130809Smarcel
21450130809Smarcel@menu
21451130809Smarcel* Integral datatypes::
21452130809Smarcel* Pointer values::
21453130809Smarcel* struct stat::
21454130809Smarcel* struct timeval::
21455130809Smarcel@end menu
21456130809Smarcel
21457130809Smarcel@node Integral datatypes
21458130809Smarcel@unnumberedsubsubsec Integral datatypes
21459130809Smarcel@cindex integral datatypes, in file-i/o protocol
21460130809Smarcel
21461130809SmarcelThe integral datatypes used in the system calls are
21462130809Smarcel
21463130809Smarcel@smallexample
21464130809Smarcelint@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
21465130809Smarcel@end smallexample
21466130809Smarcel
21467130809Smarcel@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
21468130809Smarcelimplemented as 32 bit values in this protocol.
21469130809Smarcel
21470130809Smarcel@code{Long} and @code{unsigned long} are implemented as 64 bit types.
21471130809Smarcel
21472130809Smarcel@xref{Limits}, for corresponding MIN and MAX values (similar to those
21473130809Smarcelin @file{limits.h}) to allow range checking on host and target.
21474130809Smarcel
21475130809Smarcel@code{time_t} datatypes are defined as seconds since the Epoch.
21476130809Smarcel
21477130809SmarcelAll integral datatypes transferred as part of a memory read or write of a
21478130809Smarcelstructured datatype e.g.@: a @code{struct stat} have to be given in big endian
21479130809Smarcelbyte order.
21480130809Smarcel
21481130809Smarcel@node Pointer values
21482130809Smarcel@unnumberedsubsubsec Pointer values
21483130809Smarcel@cindex pointer values, in file-i/o protocol
21484130809Smarcel
21485130809SmarcelPointers to target data are transmitted as they are.  An exception
21486130809Smarcelis made for pointers to buffers for which the length isn't
21487130809Smarceltransmitted as part of the function call, namely strings.  Strings
21488130809Smarcelare transmitted as a pointer/length pair, both as hex values, e.g.@:
21489130809Smarcel
21490130809Smarcel@smallexample
21491130809Smarcel@code{1aaf/12}
21492130809Smarcel@end smallexample
21493130809Smarcel
21494130809Smarcel@noindent
21495130809Smarcelwhich is a pointer to data of length 18 bytes at position 0x1aaf.
21496130809SmarcelThe length is defined as the full string length in bytes, including
21497130809Smarcelthe trailing null byte.  Example:
21498130809Smarcel
21499130809Smarcel@smallexample
21500130809Smarcel``hello, world'' at address 0x123456
21501130809Smarcel@end smallexample
21502130809Smarcel
21503130809Smarcel@noindent
21504130809Smarcelis transmitted as
21505130809Smarcel
21506130809Smarcel@smallexample
21507130809Smarcel@code{123456/d}
21508130809Smarcel@end smallexample
21509130809Smarcel
21510130809Smarcel@node struct stat
21511130809Smarcel@unnumberedsubsubsec struct stat
21512130809Smarcel@cindex struct stat, in file-i/o protocol
21513130809Smarcel
21514130809SmarcelThe buffer of type struct stat used by the target and @value{GDBN} is defined
21515130809Smarcelas follows:
21516130809Smarcel
21517130809Smarcel@smallexample
21518130809Smarcelstruct stat @{
21519130809Smarcel    unsigned int  st_dev;      /* device */
21520130809Smarcel    unsigned int  st_ino;      /* inode */
21521130809Smarcel    mode_t        st_mode;     /* protection */
21522130809Smarcel    unsigned int  st_nlink;    /* number of hard links */
21523130809Smarcel    unsigned int  st_uid;      /* user ID of owner */
21524130809Smarcel    unsigned int  st_gid;      /* group ID of owner */
21525130809Smarcel    unsigned int  st_rdev;     /* device type (if inode device) */
21526130809Smarcel    unsigned long st_size;     /* total size, in bytes */
21527130809Smarcel    unsigned long st_blksize;  /* blocksize for filesystem I/O */
21528130809Smarcel    unsigned long st_blocks;   /* number of blocks allocated */
21529130809Smarcel    time_t        st_atime;    /* time of last access */
21530130809Smarcel    time_t        st_mtime;    /* time of last modification */
21531130809Smarcel    time_t        st_ctime;    /* time of last change */
21532130809Smarcel@};
21533130809Smarcel@end smallexample
21534130809Smarcel
21535130809SmarcelThe integral datatypes are conforming to the definitions given in the
21536130809Smarcelapproriate section (see @ref{Integral datatypes}, for details) so this
21537130809Smarcelstructure is of size 64 bytes.
21538130809Smarcel
21539130809SmarcelThe values of several fields have a restricted meaning and/or
21540130809Smarcelrange of values.
21541130809Smarcel
21542130809Smarcel@smallexample
21543130809Smarcelst_dev:     0       file
21544130809Smarcel            1       console
21545130809Smarcel
21546130809Smarcelst_ino:     No valid meaning for the target.  Transmitted unchanged.
21547130809Smarcel
21548130809Smarcelst_mode:    Valid mode bits are described in Appendix C.  Any other
21549130809Smarcel            bits have currently no meaning for the target.
21550130809Smarcel
21551130809Smarcelst_uid:     No valid meaning for the target.  Transmitted unchanged.
21552130809Smarcel
21553130809Smarcelst_gid:     No valid meaning for the target.  Transmitted unchanged.
21554130809Smarcel
21555130809Smarcelst_rdev:    No valid meaning for the target.  Transmitted unchanged.
21556130809Smarcel
21557130809Smarcelst_atime, st_mtime, st_ctime:
21558130809Smarcel            These values have a host and file system dependent
21559130809Smarcel            accuracy.  Especially on Windows hosts the file systems
21560130809Smarcel            don't support exact timing values.
21561130809Smarcel@end smallexample
21562130809Smarcel
21563130809SmarcelThe target gets a struct stat of the above representation and is
21564130809Smarcelresponsible to coerce it to the target representation before
21565130809Smarcelcontinuing.
21566130809Smarcel
21567130809SmarcelNote that due to size differences between the host and target
21568130809Smarcelrepresentation of stat members, these members could eventually
21569130809Smarcelget truncated on the target.
21570130809Smarcel
21571130809Smarcel@node struct timeval
21572130809Smarcel@unnumberedsubsubsec struct timeval
21573130809Smarcel@cindex struct timeval, in file-i/o protocol
21574130809Smarcel
21575130809SmarcelThe buffer of type struct timeval used by the target and @value{GDBN}
21576130809Smarcelis defined as follows:
21577130809Smarcel
21578130809Smarcel@smallexample
21579130809Smarcelstruct timeval @{
21580130809Smarcel    time_t tv_sec;  /* second */
21581130809Smarcel    long   tv_usec; /* microsecond */
21582130809Smarcel@};
21583130809Smarcel@end smallexample
21584130809Smarcel
21585130809SmarcelThe integral datatypes are conforming to the definitions given in the
21586130809Smarcelapproriate section (see @ref{Integral datatypes}, for details) so this
21587130809Smarcelstructure is of size 8 bytes.
21588130809Smarcel
21589130809Smarcel@node Constants
21590130809Smarcel@subsection Constants
21591130809Smarcel@cindex constants, in file-i/o protocol
21592130809Smarcel
21593130809SmarcelThe following values are used for the constants inside of the
21594130809Smarcelprotocol.  @value{GDBN} and target are resposible to translate these
21595130809Smarcelvalues before and after the call as needed.
21596130809Smarcel
21597130809Smarcel@menu
21598130809Smarcel* Open flags::
21599130809Smarcel* mode_t values::
21600130809Smarcel* Errno values::
21601130809Smarcel* Lseek flags::
21602130809Smarcel* Limits::
21603130809Smarcel@end menu
21604130809Smarcel
21605130809Smarcel@node Open flags
21606130809Smarcel@unnumberedsubsubsec Open flags
21607130809Smarcel@cindex open flags, in file-i/o protocol
21608130809Smarcel
21609130809SmarcelAll values are given in hexadecimal representation.
21610130809Smarcel
21611130809Smarcel@smallexample
21612130809Smarcel  O_RDONLY        0x0
21613130809Smarcel  O_WRONLY        0x1
21614130809Smarcel  O_RDWR          0x2
21615130809Smarcel  O_APPEND        0x8
21616130809Smarcel  O_CREAT       0x200
21617130809Smarcel  O_TRUNC       0x400
21618130809Smarcel  O_EXCL        0x800
21619130809Smarcel@end smallexample
21620130809Smarcel
21621130809Smarcel@node mode_t values
21622130809Smarcel@unnumberedsubsubsec mode_t values
21623130809Smarcel@cindex mode_t values, in file-i/o protocol
21624130809Smarcel
21625130809SmarcelAll values are given in octal representation.
21626130809Smarcel
21627130809Smarcel@smallexample
21628130809Smarcel  S_IFREG       0100000
21629130809Smarcel  S_IFDIR        040000
21630130809Smarcel  S_IRUSR          0400
21631130809Smarcel  S_IWUSR          0200
21632130809Smarcel  S_IXUSR          0100
21633130809Smarcel  S_IRGRP           040
21634130809Smarcel  S_IWGRP           020
21635130809Smarcel  S_IXGRP           010
21636130809Smarcel  S_IROTH            04
21637130809Smarcel  S_IWOTH            02
21638130809Smarcel  S_IXOTH            01
21639130809Smarcel@end smallexample
21640130809Smarcel
21641130809Smarcel@node Errno values
21642130809Smarcel@unnumberedsubsubsec Errno values
21643130809Smarcel@cindex errno values, in file-i/o protocol
21644130809Smarcel
21645130809SmarcelAll values are given in decimal representation.
21646130809Smarcel
21647130809Smarcel@smallexample
21648130809Smarcel  EPERM           1
21649130809Smarcel  ENOENT          2
21650130809Smarcel  EINTR           4
21651130809Smarcel  EBADF           9
21652130809Smarcel  EACCES         13
21653130809Smarcel  EFAULT         14
21654130809Smarcel  EBUSY          16
21655130809Smarcel  EEXIST         17
21656130809Smarcel  ENODEV         19
21657130809Smarcel  ENOTDIR        20
21658130809Smarcel  EISDIR         21
21659130809Smarcel  EINVAL         22
21660130809Smarcel  ENFILE         23
21661130809Smarcel  EMFILE         24
21662130809Smarcel  EFBIG          27
21663130809Smarcel  ENOSPC         28
21664130809Smarcel  ESPIPE         29
21665130809Smarcel  EROFS          30
21666130809Smarcel  ENAMETOOLONG   91
21667130809Smarcel  EUNKNOWN       9999
21668130809Smarcel@end smallexample
21669130809Smarcel
21670130809Smarcel  EUNKNOWN is used as a fallback error value if a host system returns
21671130809Smarcel  any error value not in the list of supported error numbers.
21672130809Smarcel
21673130809Smarcel@node Lseek flags
21674130809Smarcel@unnumberedsubsubsec Lseek flags
21675130809Smarcel@cindex lseek flags, in file-i/o protocol
21676130809Smarcel
21677130809Smarcel@smallexample
21678130809Smarcel  SEEK_SET      0
21679130809Smarcel  SEEK_CUR      1
21680130809Smarcel  SEEK_END      2
21681130809Smarcel@end smallexample
21682130809Smarcel
21683130809Smarcel@node Limits
21684130809Smarcel@unnumberedsubsubsec Limits
21685130809Smarcel@cindex limits, in file-i/o protocol
21686130809Smarcel
21687130809SmarcelAll values are given in decimal representation.
21688130809Smarcel
21689130809Smarcel@smallexample
21690130809Smarcel  INT_MIN       -2147483648
21691130809Smarcel  INT_MAX        2147483647
21692130809Smarcel  UINT_MAX       4294967295
21693130809Smarcel  LONG_MIN      -9223372036854775808
21694130809Smarcel  LONG_MAX       9223372036854775807
21695130809Smarcel  ULONG_MAX      18446744073709551615
21696130809Smarcel@end smallexample
21697130809Smarcel
21698130809Smarcel@node File-I/O Examples
21699130809Smarcel@subsection File-I/O Examples
21700130809Smarcel@cindex file-i/o examples
21701130809Smarcel
21702130809SmarcelExample sequence of a write call, file descriptor 3, buffer is at target
21703130809Smarceladdress 0x1234, 6 bytes should be written:
21704130809Smarcel
21705130809Smarcel@smallexample
21706130809Smarcel<- @code{Fwrite,3,1234,6}
21707130809Smarcel@emph{request memory read from target}
21708130809Smarcel-> @code{m1234,6}
21709130809Smarcel<- XXXXXX
21710130809Smarcel@emph{return "6 bytes written"}
21711130809Smarcel-> @code{F6}
21712130809Smarcel@end smallexample
21713130809Smarcel
21714130809SmarcelExample sequence of a read call, file descriptor 3, buffer is at target
21715130809Smarceladdress 0x1234, 6 bytes should be read:
21716130809Smarcel
21717130809Smarcel@smallexample
21718130809Smarcel<- @code{Fread,3,1234,6}
21719130809Smarcel@emph{request memory write to target}
21720130809Smarcel-> @code{X1234,6:XXXXXX}
21721130809Smarcel@emph{return "6 bytes read"}
21722130809Smarcel-> @code{F6}
21723130809Smarcel@end smallexample
21724130809Smarcel
21725130809SmarcelExample sequence of a read call, call fails on the host due to invalid
21726130809Smarcelfile descriptor (EBADF):
21727130809Smarcel
21728130809Smarcel@smallexample
21729130809Smarcel<- @code{Fread,3,1234,6}
21730130809Smarcel-> @code{F-1,9}
21731130809Smarcel@end smallexample
21732130809Smarcel
21733130809SmarcelExample sequence of a read call, user presses Ctrl-C before syscall on
21734130809Smarcelhost is called:
21735130809Smarcel
21736130809Smarcel@smallexample
21737130809Smarcel<- @code{Fread,3,1234,6}
21738130809Smarcel-> @code{F-1,4,C}
21739130809Smarcel<- @code{T02}
21740130809Smarcel@end smallexample
21741130809Smarcel
21742130809SmarcelExample sequence of a read call, user presses Ctrl-C after syscall on
21743130809Smarcelhost is called:
21744130809Smarcel
21745130809Smarcel@smallexample
21746130809Smarcel<- @code{Fread,3,1234,6}
21747130809Smarcel-> @code{X1234,6:XXXXXX}
21748130809Smarcel<- @code{T02}
21749130809Smarcel@end smallexample
21750130809Smarcel
21751130809Smarcel@include agentexpr.texi
21752130809Smarcel
2175398948Sobrien@include gpl.texi
2175498948Sobrien
21755130809Smarcel@raisesections
2175698948Sobrien@include fdl.texi
21757130809Smarcel@lowersections
2175898948Sobrien
2175998948Sobrien@node Index
2176019370Spst@unnumbered Index
2176119370Spst
2176219370Spst@printindex cp
2176319370Spst
2176419370Spst@tex
2176519370Spst% I think something like @colophon should be in texinfo.  In the
2176619370Spst% meantime:
2176719370Spst\long\def\colophon{\hbox to0pt{}\vfill
2176819370Spst\centerline{The body of this manual is set in}
2176919370Spst\centerline{\fontname\tenrm,}
2177019370Spst\centerline{with headings in {\bf\fontname\tenbf}}
2177119370Spst\centerline{and examples in {\tt\fontname\tentt}.}
2177219370Spst\centerline{{\it\fontname\tenit\/},}
2177319370Spst\centerline{{\bf\fontname\tenbf}, and}
2177419370Spst\centerline{{\sl\fontname\tensl\/}}
2177519370Spst\centerline{are used for emphasis.}\vfill}
2177619370Spst\page\colophon
2177719370Spst% Blame: doc@cygnus.com, 1991.
2177819370Spst@end tex
2177919370Spst
2178019370Spst@bye
21781