* ChangeLog: Fix typos.
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
b6ba6518 2@c Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
1e698235 3@c 1999, 2000, 2001, 2002, 2003
c906108c
SS
4@c Free Software Foundation, Inc.
5@c
5d161b24 6@c %**start of header
c906108c
SS
7@c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
8@c of @set vars. However, you can override filename with makeinfo -o.
9@setfilename gdb.info
10@c
11@include gdb-cfg.texi
12@c
c906108c 13@settitle Debugging with @value{GDBN}
c906108c
SS
14@setchapternewpage odd
15@c %**end of header
16
17@iftex
18@c @smallbook
19@c @cropmarks
20@end iftex
21
22@finalout
23@syncodeindex ky cp
24
41afff9a 25@c readline appendices use @vindex, @findex and @ftable,
48e934c6 26@c annotate.texi and gdbmi use @findex.
c906108c 27@syncodeindex vr cp
41afff9a 28@syncodeindex fn cp
c906108c
SS
29
30@c !!set GDB manual's edition---not the same as GDB version!
9fe8321b 31@c This is updated by GNU Press.
e9c75b65 32@set EDITION Ninth
c906108c 33
87885426
FN
34@c !!set GDB edit command default editor
35@set EDITOR /bin/ex
c906108c 36
6c0e9fb3 37@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
c906108c 38
c906108c 39@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 40@c manuals to an info tree.
96a2c332
SS
41@dircategory Programming & development tools.
42@direntry
c906108c 43* Gdb: (gdb). The @sc{gnu} debugger.
96a2c332
SS
44@end direntry
45
c906108c
SS
46@ifinfo
47This file documents the @sc{gnu} debugger @value{GDBN}.
48
49
9fe8321b
AC
50This is the @value{EDITION} Edition, of @cite{Debugging with
51@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
52Version @value{GDBVN}.
c906108c 53
8a037dd7 54Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,@*
1e698235 55 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
c906108c 56
e9c75b65
EZ
57Permission is granted to copy, distribute and/or modify this document
58under the terms of the GNU Free Documentation License, Version 1.1 or
59any later version published by the Free Software Foundation; with the
959acfd1
EZ
60Invariant Sections being ``Free Software'' and ``Free Software Needs
61Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
62and with the Back-Cover Texts as in (a) below.
c906108c 63
6826cf00
EZ
64(a) The Free Software Foundation's Back-Cover Text is: ``You have
65freedom to copy and modify this GNU Manual, like GNU software. Copies
66published by the Free Software Foundation raise funds for GNU
67development.''
c906108c
SS
68@end ifinfo
69
70@titlepage
71@title Debugging with @value{GDBN}
72@subtitle The @sc{gnu} Source-Level Debugger
c906108c 73@sp 1
c906108c 74@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
9e9c5ae7 75@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 76@page
c906108c
SS
77@tex
78{\parskip=0pt
53a5351d 79\hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
c906108c
SS
80\hfill {\it Debugging with @value{GDBN}}\par
81\hfill \TeX{}info \texinfoversion\par
82}
83@end tex
53a5351d 84
c906108c 85@vskip 0pt plus 1filll
8a037dd7 86Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
1e698235 871996, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
c906108c 88@sp 2
c906108c
SS
89Published by the Free Software Foundation @*
9059 Temple Place - Suite 330, @*
91Boston, MA 02111-1307 USA @*
6d2ebf8b 92ISBN 1-882114-77-9 @*
e9c75b65
EZ
93
94Permission is granted to copy, distribute and/or modify this document
95under the terms of the GNU Free Documentation License, Version 1.1 or
96any later version published by the Free Software Foundation; with the
959acfd1
EZ
97Invariant Sections being ``Free Software'' and ``Free Software Needs
98Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
99and with the Back-Cover Texts as in (a) below.
e9c75b65 100
6826cf00
EZ
101(a) The Free Software Foundation's Back-Cover Text is: ``You have
102freedom to copy and modify this GNU Manual, like GNU software. Copies
103published by the Free Software Foundation raise funds for GNU
104development.''
c906108c
SS
105@end titlepage
106@page
107
6c0e9fb3 108@ifnottex
6d2ebf8b
SS
109@node Top, Summary, (dir), (dir)
110
c906108c
SS
111@top Debugging with @value{GDBN}
112
113This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
114
9fe8321b 115This is the @value{EDITION} Edition, for @value{GDBN} Version
c906108c
SS
116@value{GDBVN}.
117
1e698235 118Copyright (C) 1988-2003 Free Software Foundation, Inc.
6d2ebf8b
SS
119
120@menu
121* Summary:: Summary of @value{GDBN}
122* Sample Session:: A sample @value{GDBN} session
123
124* Invocation:: Getting in and out of @value{GDBN}
125* Commands:: @value{GDBN} commands
126* Running:: Running programs under @value{GDBN}
127* Stopping:: Stopping and continuing
128* Stack:: Examining the stack
129* Source:: Examining source files
130* Data:: Examining data
e2e0bcd1 131* Macros:: Preprocessor Macros
b37052ae 132* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 133* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
134
135* Languages:: Using @value{GDBN} with different languages
136
137* Symbols:: Examining the symbol table
138* Altering:: Altering execution
139* GDB Files:: @value{GDBN} files
140* Targets:: Specifying a debugging target
6b2f586d 141* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
142* Configurations:: Configuration-specific information
143* Controlling GDB:: Controlling @value{GDBN}
144* Sequences:: Canned sequences of commands
c4555f82 145* TUI:: @value{GDBN} Text User Interface
21c294e6 146* Interpreters:: Command Interpreters
6d2ebf8b
SS
147* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
148* Annotations:: @value{GDBN}'s annotation interface.
7162c0ca 149* GDB/MI:: @value{GDBN}'s Machine Interface.
6d2ebf8b
SS
150
151* GDB Bugs:: Reporting bugs in @value{GDBN}
152* Formatting Documentation:: How to format and print @value{GDBN} documentation
153
154* Command Line Editing:: Command Line Editing
155* Using History Interactively:: Using History Interactively
156* Installing GDB:: Installing GDB
eb12ee30 157* Maintenance Commands:: Maintenance Commands
e0ce93ac 158* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 159* Agent Expressions:: The GDB Agent Expression Mechanism
aab4e0ec
AC
160* Copying:: GNU General Public License says
161 how you can copy and share GDB
6826cf00 162* GNU Free Documentation License:: The license for this documentation
6d2ebf8b
SS
163* Index:: Index
164@end menu
165
6c0e9fb3 166@end ifnottex
c906108c 167
449f3b6c 168@contents
449f3b6c 169
6d2ebf8b 170@node Summary
c906108c
SS
171@unnumbered Summary of @value{GDBN}
172
173The purpose of a debugger such as @value{GDBN} is to allow you to see what is
174going on ``inside'' another program while it executes---or what another
175program was doing at the moment it crashed.
176
177@value{GDBN} can do four main kinds of things (plus other things in support of
178these) to help you catch bugs in the act:
179
180@itemize @bullet
181@item
182Start your program, specifying anything that might affect its behavior.
183
184@item
185Make your program stop on specified conditions.
186
187@item
188Examine what has happened, when your program has stopped.
189
190@item
191Change things in your program, so you can experiment with correcting the
192effects of one bug and go on to learn about another.
193@end itemize
194
cce74817 195You can use @value{GDBN} to debug programs written in C and C++.
c906108c 196For more information, see @ref{Support,,Supported languages}.
c906108c
SS
197For more information, see @ref{C,,C and C++}.
198
cce74817 199@cindex Modula-2
e632838e
AC
200Support for Modula-2 is partial. For information on Modula-2, see
201@ref{Modula-2,,Modula-2}.
c906108c 202
cce74817
JM
203@cindex Pascal
204Debugging Pascal programs which use sets, subranges, file variables, or
205nested functions does not currently work. @value{GDBN} does not support
206entering expressions, printing values, or similar features using Pascal
207syntax.
c906108c 208
c906108c
SS
209@cindex Fortran
210@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 211it may be necessary to refer to some variables with a trailing
cce74817 212underscore.
c906108c 213
b37303ee
AF
214@value{GDBN} can be used to debug programs written in Objective-C,
215using either the Apple/NeXT or the GNU Objective-C runtime.
216
c906108c
SS
217@menu
218* Free Software:: Freely redistributable software
219* Contributors:: Contributors to GDB
220@end menu
221
6d2ebf8b 222@node Free Software
c906108c
SS
223@unnumberedsec Free software
224
5d161b24 225@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
226General Public License
227(GPL). The GPL gives you the freedom to copy or adapt a licensed
228program---but every person getting a copy also gets with it the
229freedom to modify that copy (which means that they must get access to
230the source code), and the freedom to distribute further copies.
231Typical software companies use copyrights to limit your freedoms; the
232Free Software Foundation uses the GPL to preserve these freedoms.
233
234Fundamentally, the General Public License is a license which says that
235you have these freedoms and that you cannot take these freedoms away
236from anyone else.
237
2666264b 238@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
239
240The biggest deficiency in the free software community today is not in
241the software---it is the lack of good free documentation that we can
242include with the free software. Many of our most important
243programs do not come with free reference manuals and free introductory
244texts. Documentation is an essential part of any software package;
245when an important free software package does not come with a free
246manual and a free tutorial, that is a major gap. We have many such
247gaps today.
248
249Consider Perl, for instance. The tutorial manuals that people
250normally use are non-free. How did this come about? Because the
251authors of those manuals published them with restrictive terms---no
252copying, no modification, source files not available---which exclude
253them from the free software world.
254
255That wasn't the first time this sort of thing happened, and it was far
256from the last. Many times we have heard a GNU user eagerly describe a
257manual that he is writing, his intended contribution to the community,
258only to learn that he had ruined everything by signing a publication
259contract to make it non-free.
260
261Free documentation, like free software, is a matter of freedom, not
262price. The problem with the non-free manual is not that publishers
263charge a price for printed copies---that in itself is fine. (The Free
264Software Foundation sells printed copies of manuals, too.) The
265problem is the restrictions on the use of the manual. Free manuals
266are available in source code form, and give you permission to copy and
267modify. Non-free manuals do not allow this.
268
269The criteria of freedom for a free manual are roughly the same as for
270free software. Redistribution (including the normal kinds of
271commercial redistribution) must be permitted, so that the manual can
272accompany every copy of the program, both on-line and on paper.
273
274Permission for modification of the technical content is crucial too.
275When people modify the software, adding or changing features, if they
276are conscientious they will change the manual too---so they can
277provide accurate and clear documentation for the modified program. A
278manual that leaves you no choice but to write a new manual to document
279a changed version of the program is not really available to our
280community.
281
282Some kinds of limits on the way modification is handled are
283acceptable. For example, requirements to preserve the original
284author's copyright notice, the distribution terms, or the list of
285authors, are ok. It is also no problem to require modified versions
286to include notice that they were modified. Even entire sections that
287may not be deleted or changed are acceptable, as long as they deal
288with nontechnical topics (like this one). These kinds of restrictions
289are acceptable because they don't obstruct the community's normal use
290of the manual.
291
292However, it must be possible to modify all the @emph{technical}
293content of the manual, and then distribute the result in all the usual
294media, through all the usual channels. Otherwise, the restrictions
295obstruct the use of the manual, it is not free, and we need another
296manual to replace it.
297
298Please spread the word about this issue. Our community continues to
299lose manuals to proprietary publishing. If we spread the word that
300free software needs free reference manuals and free tutorials, perhaps
301the next person who wants to contribute by writing documentation will
302realize, before it is too late, that only free manuals contribute to
303the free software community.
304
305If you are writing documentation, please insist on publishing it under
306the GNU Free Documentation License or another free documentation
307license. Remember that this decision requires your approval---you
308don't have to let the publisher decide. Some commercial publishers
309will use a free license if you insist, but they will not propose the
310option; it is up to you to raise the issue and say firmly that this is
311what you want. If the publisher you are dealing with refuses, please
312try other publishers. If you're not sure whether a proposed license
42584a72 313is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
314
315You can encourage commercial publishers to sell more free, copylefted
316manuals and tutorials by buying them, and particularly by buying
317copies from the publishers that paid for their writing or for major
318improvements. Meanwhile, try to avoid buying non-free documentation
319at all. Check the distribution terms of a manual before you buy it,
320and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
321Check the history of the book, and try to reward the publishers that
322have paid or pay the authors to work on it.
959acfd1
EZ
323
324The Free Software Foundation maintains a list of free documentation
325published by other publishers, at
326@url{http://www.fsf.org/doc/other-free-books.html}.
327
6d2ebf8b 328@node Contributors
96a2c332
SS
329@unnumberedsec Contributors to @value{GDBN}
330
331Richard Stallman was the original author of @value{GDBN}, and of many
332other @sc{gnu} programs. Many others have contributed to its
333development. This section attempts to credit major contributors. One
334of the virtues of free software is that everyone is free to contribute
335to it; with regret, we cannot actually acknowledge everyone here. The
336file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
337blow-by-blow account.
338
339Changes much prior to version 2.0 are lost in the mists of time.
340
341@quotation
342@emph{Plea:} Additions to this section are particularly welcome. If you
343or your friends (or enemies, to be evenhanded) have been unfairly
344omitted from this list, we would like to add your names!
345@end quotation
346
347So that they may not regard their many labors as thankless, we
348particularly thank those who shepherded @value{GDBN} through major
349releases:
f2c06f52 350Andrew Cagney (releases 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
351Jim Blandy (release 4.18);
352Jason Molenda (release 4.17);
353Stan Shebs (release 4.14);
354Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
355Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
356John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
357Jim Kingdon (releases 3.5, 3.4, and 3.3);
358and Randy Smith (releases 3.2, 3.1, and 3.0).
359
360Richard Stallman, assisted at various times by Peter TerMaat, Chris
361Hanson, and Richard Mlynarik, handled releases through 2.8.
362
b37052ae
EZ
363Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
364in @value{GDBN}, with significant additional contributions from Per
365Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
366demangler. Early work on C@t{++} was by Peter TerMaat (who also did
367much general update work leading to release 3.0).
c906108c 368
b37052ae 369@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
370object-file formats; BFD was a joint project of David V.
371Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
372
373David Johnson wrote the original COFF support; Pace Willison did
374the original support for encapsulated COFF.
375
0179ffac 376Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
377
378Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
379Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
380support.
381Jean-Daniel Fekete contributed Sun 386i support.
382Chris Hanson improved the HP9000 support.
383Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
384David Johnson contributed Encore Umax support.
385Jyrki Kuoppala contributed Altos 3068 support.
386Jeff Law contributed HP PA and SOM support.
387Keith Packard contributed NS32K support.
388Doug Rabson contributed Acorn Risc Machine support.
389Bob Rusk contributed Harris Nighthawk CX-UX support.
390Chris Smith contributed Convex support (and Fortran debugging).
391Jonathan Stone contributed Pyramid support.
392Michael Tiemann contributed SPARC support.
393Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
394Pace Willison contributed Intel 386 support.
395Jay Vosburgh contributed Symmetry support.
a37295f9 396Marko Mlinar contributed OpenRISC 1000 support.
c906108c 397
1104b9e7 398Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
399
400Rich Schaefer and Peter Schauer helped with support of SunOS shared
401libraries.
402
403Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
404about several machine instruction sets.
405
406Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
407remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
408contributed remote debugging modules for the i960, VxWorks, A29K UDI,
409and RDI targets, respectively.
410
411Brian Fox is the author of the readline libraries providing
412command-line editing and command history.
413
7a292a7a
SS
414Andrew Beers of SUNY Buffalo wrote the language-switching code, the
415Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 416
5d161b24 417Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 418He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 419symbols.
c906108c 420
f24c5e49
KI
421Hitachi America (now Renesas America), Ltd. sponsored the support for
422H8/300, H8/500, and Super-H processors.
c906108c
SS
423
424NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
425
f24c5e49
KI
426Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
427processors.
c906108c
SS
428
429Toshiba sponsored the support for the TX39 Mips processor.
430
431Matsushita sponsored the support for the MN10200 and MN10300 processors.
432
96a2c332 433Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
434
435Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
436watchpoints.
437
438Michael Snyder added support for tracepoints.
439
440Stu Grossman wrote gdbserver.
441
442Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 443nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
444
445The following people at the Hewlett-Packard Company contributed
446support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 447(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
c906108c
SS
448compiler, and the terminal user interface: Ben Krepp, Richard Title,
449John Bishop, Susan Macchia, Kathy Mann, Satish Pai, India Paul, Steve
450Rehrauer, and Elena Zannoni. Kim Haase provided HP-specific
451information in this manual.
452
b37052ae
EZ
453DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
454Robert Hoehne made significant contributions to the DJGPP port.
455
96a2c332
SS
456Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
457development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
458fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
459Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
460Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
461Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
462Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
463addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
464JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
465Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
466Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
467Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
468Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
469Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
470Zuhn have made contributions both large and small.
c906108c 471
e2e0bcd1
JB
472Jim Blandy added support for preprocessor macros, while working for Red
473Hat.
c906108c 474
6d2ebf8b 475@node Sample Session
c906108c
SS
476@chapter A Sample @value{GDBN} Session
477
478You can use this manual at your leisure to read all about @value{GDBN}.
479However, a handful of commands are enough to get started using the
480debugger. This chapter illustrates those commands.
481
482@iftex
483In this sample session, we emphasize user input like this: @b{input},
484to make it easier to pick out from the surrounding output.
485@end iftex
486
487@c FIXME: this example may not be appropriate for some configs, where
488@c FIXME...primary interest is in remote use.
489
490One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
491processor) exhibits the following bug: sometimes, when we change its
492quote strings from the default, the commands used to capture one macro
493definition within another stop working. In the following short @code{m4}
494session, we define a macro @code{foo} which expands to @code{0000}; we
495then use the @code{m4} built-in @code{defn} to define @code{bar} as the
496same thing. However, when we change the open quote string to
497@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
498procedure fails to define a new synonym @code{baz}:
499
500@smallexample
501$ @b{cd gnu/m4}
502$ @b{./m4}
503@b{define(foo,0000)}
504
505@b{foo}
5060000
507@b{define(bar,defn(`foo'))}
508
509@b{bar}
5100000
511@b{changequote(<QUOTE>,<UNQUOTE>)}
512
513@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
514@b{baz}
515@b{C-d}
516m4: End of input: 0: fatal error: EOF in string
517@end smallexample
518
519@noindent
520Let us use @value{GDBN} to try to see what is going on.
521
c906108c
SS
522@smallexample
523$ @b{@value{GDBP} m4}
524@c FIXME: this falsifies the exact text played out, to permit smallbook
525@c FIXME... format to come out better.
526@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 527 of it under certain conditions; type "show copying" to see
c906108c 528 the conditions.
5d161b24 529There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
530 for details.
531
532@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
533(@value{GDBP})
534@end smallexample
c906108c
SS
535
536@noindent
537@value{GDBN} reads only enough symbol data to know where to find the
538rest when needed; as a result, the first prompt comes up very quickly.
539We now tell @value{GDBN} to use a narrower display width than usual, so
540that examples fit in this manual.
541
542@smallexample
543(@value{GDBP}) @b{set width 70}
544@end smallexample
545
546@noindent
547We need to see how the @code{m4} built-in @code{changequote} works.
548Having looked at the source, we know the relevant subroutine is
549@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
550@code{break} command.
551
552@smallexample
553(@value{GDBP}) @b{break m4_changequote}
554Breakpoint 1 at 0x62f4: file builtin.c, line 879.
555@end smallexample
556
557@noindent
558Using the @code{run} command, we start @code{m4} running under @value{GDBN}
559control; as long as control does not reach the @code{m4_changequote}
560subroutine, the program runs as usual:
561
562@smallexample
563(@value{GDBP}) @b{run}
564Starting program: /work/Editorial/gdb/gnu/m4/m4
565@b{define(foo,0000)}
566
567@b{foo}
5680000
569@end smallexample
570
571@noindent
572To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
573suspends execution of @code{m4}, displaying information about the
574context where it stops.
575
576@smallexample
577@b{changequote(<QUOTE>,<UNQUOTE>)}
578
5d161b24 579Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
580 at builtin.c:879
581879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
582@end smallexample
583
584@noindent
585Now we use the command @code{n} (@code{next}) to advance execution to
586the next line of the current function.
587
588@smallexample
589(@value{GDBP}) @b{n}
590882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
591 : nil,
592@end smallexample
593
594@noindent
595@code{set_quotes} looks like a promising subroutine. We can go into it
596by using the command @code{s} (@code{step}) instead of @code{next}.
597@code{step} goes to the next line to be executed in @emph{any}
598subroutine, so it steps into @code{set_quotes}.
599
600@smallexample
601(@value{GDBP}) @b{s}
602set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
603 at input.c:530
604530 if (lquote != def_lquote)
605@end smallexample
606
607@noindent
608The display that shows the subroutine where @code{m4} is now
609suspended (and its arguments) is called a stack frame display. It
610shows a summary of the stack. We can use the @code{backtrace}
611command (which can also be spelled @code{bt}), to see where we are
612in the stack as a whole: the @code{backtrace} command displays a
613stack frame for each active subroutine.
614
615@smallexample
616(@value{GDBP}) @b{bt}
617#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
618 at input.c:530
5d161b24 619#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
620 at builtin.c:882
621#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
622#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
623 at macro.c:71
624#4 0x79dc in expand_input () at macro.c:40
625#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
626@end smallexample
627
628@noindent
629We step through a few more lines to see what happens. The first two
630times, we can use @samp{s}; the next two times we use @code{n} to avoid
631falling into the @code{xstrdup} subroutine.
632
633@smallexample
634(@value{GDBP}) @b{s}
6350x3b5c 532 if (rquote != def_rquote)
636(@value{GDBP}) @b{s}
6370x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
638def_lquote : xstrdup(lq);
639(@value{GDBP}) @b{n}
640536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
641 : xstrdup(rq);
642(@value{GDBP}) @b{n}
643538 len_lquote = strlen(rquote);
644@end smallexample
645
646@noindent
647The last line displayed looks a little odd; we can examine the variables
648@code{lquote} and @code{rquote} to see if they are in fact the new left
649and right quotes we specified. We use the command @code{p}
650(@code{print}) to see their values.
651
652@smallexample
653(@value{GDBP}) @b{p lquote}
654$1 = 0x35d40 "<QUOTE>"
655(@value{GDBP}) @b{p rquote}
656$2 = 0x35d50 "<UNQUOTE>"
657@end smallexample
658
659@noindent
660@code{lquote} and @code{rquote} are indeed the new left and right quotes.
661To look at some context, we can display ten lines of source
662surrounding the current line with the @code{l} (@code{list}) command.
663
664@smallexample
665(@value{GDBP}) @b{l}
666533 xfree(rquote);
667534
668535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
669 : xstrdup (lq);
670536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
671 : xstrdup (rq);
672537
673538 len_lquote = strlen(rquote);
674539 len_rquote = strlen(lquote);
675540 @}
676541
677542 void
678@end smallexample
679
680@noindent
681Let us step past the two lines that set @code{len_lquote} and
682@code{len_rquote}, and then examine the values of those variables.
683
684@smallexample
685(@value{GDBP}) @b{n}
686539 len_rquote = strlen(lquote);
687(@value{GDBP}) @b{n}
688540 @}
689(@value{GDBP}) @b{p len_lquote}
690$3 = 9
691(@value{GDBP}) @b{p len_rquote}
692$4 = 7
693@end smallexample
694
695@noindent
696That certainly looks wrong, assuming @code{len_lquote} and
697@code{len_rquote} are meant to be the lengths of @code{lquote} and
698@code{rquote} respectively. We can set them to better values using
699the @code{p} command, since it can print the value of
700any expression---and that expression can include subroutine calls and
701assignments.
702
703@smallexample
704(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
705$5 = 7
706(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
707$6 = 9
708@end smallexample
709
710@noindent
711Is that enough to fix the problem of using the new quotes with the
712@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
713executing with the @code{c} (@code{continue}) command, and then try the
714example that caused trouble initially:
715
716@smallexample
717(@value{GDBP}) @b{c}
718Continuing.
719
720@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
721
722baz
7230000
724@end smallexample
725
726@noindent
727Success! The new quotes now work just as well as the default ones. The
728problem seems to have been just the two typos defining the wrong
729lengths. We allow @code{m4} exit by giving it an EOF as input:
730
731@smallexample
732@b{C-d}
733Program exited normally.
734@end smallexample
735
736@noindent
737The message @samp{Program exited normally.} is from @value{GDBN}; it
738indicates @code{m4} has finished executing. We can end our @value{GDBN}
739session with the @value{GDBN} @code{quit} command.
740
741@smallexample
742(@value{GDBP}) @b{quit}
743@end smallexample
c906108c 744
6d2ebf8b 745@node Invocation
c906108c
SS
746@chapter Getting In and Out of @value{GDBN}
747
748This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 749The essentials are:
c906108c 750@itemize @bullet
5d161b24 751@item
53a5351d 752type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 753@item
c906108c
SS
754type @kbd{quit} or @kbd{C-d} to exit.
755@end itemize
756
757@menu
758* Invoking GDB:: How to start @value{GDBN}
759* Quitting GDB:: How to quit @value{GDBN}
760* Shell Commands:: How to use shell commands inside @value{GDBN}
0fac0b41 761* Logging output:: How to log @value{GDBN}'s output to a file
c906108c
SS
762@end menu
763
6d2ebf8b 764@node Invoking GDB
c906108c
SS
765@section Invoking @value{GDBN}
766
c906108c
SS
767Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
768@value{GDBN} reads commands from the terminal until you tell it to exit.
769
770You can also run @code{@value{GDBP}} with a variety of arguments and options,
771to specify more of your debugging environment at the outset.
772
c906108c
SS
773The command-line options described here are designed
774to cover a variety of situations; in some environments, some of these
5d161b24 775options may effectively be unavailable.
c906108c
SS
776
777The most usual way to start @value{GDBN} is with one argument,
778specifying an executable program:
779
474c8240 780@smallexample
c906108c 781@value{GDBP} @var{program}
474c8240 782@end smallexample
c906108c 783
c906108c
SS
784@noindent
785You can also start with both an executable program and a core file
786specified:
787
474c8240 788@smallexample
c906108c 789@value{GDBP} @var{program} @var{core}
474c8240 790@end smallexample
c906108c
SS
791
792You can, instead, specify a process ID as a second argument, if you want
793to debug a running process:
794
474c8240 795@smallexample
c906108c 796@value{GDBP} @var{program} 1234
474c8240 797@end smallexample
c906108c
SS
798
799@noindent
800would attach @value{GDBN} to process @code{1234} (unless you also have a file
801named @file{1234}; @value{GDBN} does check for a core file first).
802
c906108c 803Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
804complete operating system; when you use @value{GDBN} as a remote
805debugger attached to a bare board, there may not be any notion of
806``process'', and there is often no way to get a core dump. @value{GDBN}
807will warn you if it is unable to attach or to read core dumps.
c906108c 808
aa26fa3a
TT
809You can optionally have @code{@value{GDBP}} pass any arguments after the
810executable file to the inferior using @code{--args}. This option stops
811option processing.
474c8240 812@smallexample
aa26fa3a 813gdb --args gcc -O2 -c foo.c
474c8240 814@end smallexample
aa26fa3a
TT
815This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
816@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
817
96a2c332 818You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
819@value{GDBN}'s non-warranty, by specifying @code{-silent}:
820
821@smallexample
822@value{GDBP} -silent
823@end smallexample
824
825@noindent
826You can further control how @value{GDBN} starts up by using command-line
827options. @value{GDBN} itself can remind you of the options available.
828
829@noindent
830Type
831
474c8240 832@smallexample
c906108c 833@value{GDBP} -help
474c8240 834@end smallexample
c906108c
SS
835
836@noindent
837to display all available options and briefly describe their use
838(@samp{@value{GDBP} -h} is a shorter equivalent).
839
840All options and command line arguments you give are processed
841in sequential order. The order makes a difference when the
842@samp{-x} option is used.
843
844
845@menu
c906108c
SS
846* File Options:: Choosing files
847* Mode Options:: Choosing modes
848@end menu
849
6d2ebf8b 850@node File Options
c906108c
SS
851@subsection Choosing files
852
2df3850c 853When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
854specifying an executable file and core file (or process ID). This is
855the same as if the arguments were specified by the @samp{-se} and
19837790
MS
856@samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
857first argument that does not have an associated option flag as
858equivalent to the @samp{-se} option followed by that argument; and the
859second argument that does not have an associated option flag, if any, as
860equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
861If the second argument begins with a decimal digit, @value{GDBN} will
862first attempt to attach to it as a process, and if that fails, attempt
863to open it as a corefile. If you have a corefile whose name begins with
864a digit, you can prevent @value{GDBN} from treating it as a pid by
79f12247 865prefixing it with @file{./}, eg. @file{./12345}.
7a292a7a
SS
866
867If @value{GDBN} has not been configured to included core file support,
868such as for most embedded targets, then it will complain about a second
869argument and ignore it.
c906108c
SS
870
871Many options have both long and short forms; both are shown in the
872following list. @value{GDBN} also recognizes the long forms if you truncate
873them, so long as enough of the option is present to be unambiguous.
874(If you prefer, you can flag option arguments with @samp{--} rather
875than @samp{-}, though we illustrate the more usual convention.)
876
d700128c
EZ
877@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
878@c way, both those who look for -foo and --foo in the index, will find
879@c it.
880
c906108c
SS
881@table @code
882@item -symbols @var{file}
883@itemx -s @var{file}
d700128c
EZ
884@cindex @code{--symbols}
885@cindex @code{-s}
c906108c
SS
886Read symbol table from file @var{file}.
887
888@item -exec @var{file}
889@itemx -e @var{file}
d700128c
EZ
890@cindex @code{--exec}
891@cindex @code{-e}
7a292a7a
SS
892Use file @var{file} as the executable file to execute when appropriate,
893and for examining pure data in conjunction with a core dump.
c906108c
SS
894
895@item -se @var{file}
d700128c 896@cindex @code{--se}
c906108c
SS
897Read symbol table from file @var{file} and use it as the executable
898file.
899
c906108c
SS
900@item -core @var{file}
901@itemx -c @var{file}
d700128c
EZ
902@cindex @code{--core}
903@cindex @code{-c}
19837790 904Use file @var{file} as a core dump to examine.
c906108c
SS
905
906@item -c @var{number}
19837790
MS
907@item -pid @var{number}
908@itemx -p @var{number}
909@cindex @code{--pid}
910@cindex @code{-p}
911Connect to process ID @var{number}, as with the @code{attach} command.
912If there is no such process, @value{GDBN} will attempt to open a core
913file named @var{number}.
c906108c
SS
914
915@item -command @var{file}
916@itemx -x @var{file}
d700128c
EZ
917@cindex @code{--command}
918@cindex @code{-x}
c906108c
SS
919Execute @value{GDBN} commands from file @var{file}. @xref{Command
920Files,, Command files}.
921
922@item -directory @var{directory}
923@itemx -d @var{directory}
d700128c
EZ
924@cindex @code{--directory}
925@cindex @code{-d}
c906108c
SS
926Add @var{directory} to the path to search for source files.
927
c906108c
SS
928@item -m
929@itemx -mapped
d700128c
EZ
930@cindex @code{--mapped}
931@cindex @code{-m}
c906108c
SS
932@emph{Warning: this option depends on operating system facilities that are not
933supported on all systems.}@*
934If memory-mapped files are available on your system through the @code{mmap}
5d161b24 935system call, you can use this option
c906108c
SS
936to have @value{GDBN} write the symbols from your
937program into a reusable file in the current directory. If the program you are debugging is
96a2c332 938called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
c906108c
SS
939Future @value{GDBN} debugging sessions notice the presence of this file,
940and can quickly map in symbol information from it, rather than reading
941the symbol table from the executable program.
942
943The @file{.syms} file is specific to the host machine where @value{GDBN}
944is run. It holds an exact image of the internal @value{GDBN} symbol
945table. It cannot be shared across multiple host platforms.
c906108c 946
c906108c
SS
947@item -r
948@itemx -readnow
d700128c
EZ
949@cindex @code{--readnow}
950@cindex @code{-r}
c906108c
SS
951Read each symbol file's entire symbol table immediately, rather than
952the default, which is to read it incrementally as it is needed.
953This makes startup slower, but makes future operations faster.
53a5351d 954
c906108c
SS
955@end table
956
2df3850c 957You typically combine the @code{-mapped} and @code{-readnow} options in
c906108c 958order to build a @file{.syms} file that contains complete symbol
2df3850c
JM
959information. (@xref{Files,,Commands to specify files}, for information
960on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
961but build a @file{.syms} file for future use is:
c906108c 962
474c8240 963@smallexample
2df3850c 964gdb -batch -nx -mapped -readnow programname
474c8240 965@end smallexample
c906108c 966
6d2ebf8b 967@node Mode Options
c906108c
SS
968@subsection Choosing modes
969
970You can run @value{GDBN} in various alternative modes---for example, in
971batch mode or quiet mode.
972
973@table @code
974@item -nx
975@itemx -n
d700128c
EZ
976@cindex @code{--nx}
977@cindex @code{-n}
96565e91 978Do not execute commands found in any initialization files. Normally,
2df3850c
JM
979@value{GDBN} executes the commands in these files after all the command
980options and arguments have been processed. @xref{Command Files,,Command
981files}.
c906108c
SS
982
983@item -quiet
d700128c 984@itemx -silent
c906108c 985@itemx -q
d700128c
EZ
986@cindex @code{--quiet}
987@cindex @code{--silent}
988@cindex @code{-q}
c906108c
SS
989``Quiet''. Do not print the introductory and copyright messages. These
990messages are also suppressed in batch mode.
991
992@item -batch
d700128c 993@cindex @code{--batch}
c906108c
SS
994Run in batch mode. Exit with status @code{0} after processing all the
995command files specified with @samp{-x} (and all commands from
996initialization files, if not inhibited with @samp{-n}). Exit with
997nonzero status if an error occurs in executing the @value{GDBN} commands
998in the command files.
999
2df3850c
JM
1000Batch mode may be useful for running @value{GDBN} as a filter, for
1001example to download and run a program on another computer; in order to
1002make this more useful, the message
c906108c 1003
474c8240 1004@smallexample
c906108c 1005Program exited normally.
474c8240 1006@end smallexample
c906108c
SS
1007
1008@noindent
2df3850c
JM
1009(which is ordinarily issued whenever a program running under
1010@value{GDBN} control terminates) is not issued when running in batch
1011mode.
1012
1013@item -nowindows
1014@itemx -nw
d700128c
EZ
1015@cindex @code{--nowindows}
1016@cindex @code{-nw}
2df3850c 1017``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1018(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1019interface. If no GUI is available, this option has no effect.
1020
1021@item -windows
1022@itemx -w
d700128c
EZ
1023@cindex @code{--windows}
1024@cindex @code{-w}
2df3850c
JM
1025If @value{GDBN} includes a GUI, then this option requires it to be
1026used if possible.
c906108c
SS
1027
1028@item -cd @var{directory}
d700128c 1029@cindex @code{--cd}
c906108c
SS
1030Run @value{GDBN} using @var{directory} as its working directory,
1031instead of the current directory.
1032
c906108c
SS
1033@item -fullname
1034@itemx -f
d700128c
EZ
1035@cindex @code{--fullname}
1036@cindex @code{-f}
7a292a7a
SS
1037@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1038subprocess. It tells @value{GDBN} to output the full file name and line
1039number in a standard, recognizable fashion each time a stack frame is
1040displayed (which includes each time your program stops). This
1041recognizable format looks like two @samp{\032} characters, followed by
1042the file name, line number and character position separated by colons,
1043and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1044@samp{\032} characters as a signal to display the source code for the
1045frame.
c906108c 1046
d700128c
EZ
1047@item -epoch
1048@cindex @code{--epoch}
1049The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1050@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1051routines so as to allow Epoch to display values of expressions in a
1052separate window.
1053
1054@item -annotate @var{level}
1055@cindex @code{--annotate}
1056This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1057effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1058(@pxref{Annotations}). The annotation @var{level} controls how much
1059information @value{GDBN} prints together with its prompt, values of
1060expressions, source lines, and other types of output. Level 0 is the
1061normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1062@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1063that control @value{GDBN}, and level 2 has been deprecated.
1064
1065The annotation mechanism has largely been superseeded by @sc{gdb/mi}
1066(@pxref{GDB/MI}).
d700128c
EZ
1067
1068@item -async
1069@cindex @code{--async}
1070Use the asynchronous event loop for the command-line interface.
1071@value{GDBN} processes all events, such as user keyboard input, via a
1072special event loop. This allows @value{GDBN} to accept and process user
1073commands in parallel with the debugged process being
1074run@footnote{@value{GDBN} built with @sc{djgpp} tools for
1075MS-DOS/MS-Windows supports this mode of operation, but the event loop is
1076suspended when the debuggee runs.}, so you don't need to wait for
1077control to return to @value{GDBN} before you type the next command.
b37052ae 1078(@emph{Note:} as of version 5.1, the target side of the asynchronous
d700128c
EZ
1079operation is not yet in place, so @samp{-async} does not work fully
1080yet.)
1081@c FIXME: when the target side of the event loop is done, the above NOTE
1082@c should be removed.
1083
1084When the standard input is connected to a terminal device, @value{GDBN}
1085uses the asynchronous event loop by default, unless disabled by the
1086@samp{-noasync} option.
1087
1088@item -noasync
1089@cindex @code{--noasync}
1090Disable the asynchronous event loop for the command-line interface.
1091
aa26fa3a
TT
1092@item --args
1093@cindex @code{--args}
1094Change interpretation of command line so that arguments following the
1095executable file are passed as command line arguments to the inferior.
1096This option stops option processing.
1097
2df3850c
JM
1098@item -baud @var{bps}
1099@itemx -b @var{bps}
d700128c
EZ
1100@cindex @code{--baud}
1101@cindex @code{-b}
c906108c
SS
1102Set the line speed (baud rate or bits per second) of any serial
1103interface used by @value{GDBN} for remote debugging.
c906108c
SS
1104
1105@item -tty @var{device}
d700128c
EZ
1106@itemx -t @var{device}
1107@cindex @code{--tty}
1108@cindex @code{-t}
c906108c
SS
1109Run using @var{device} for your program's standard input and output.
1110@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1111
53a5351d 1112@c resolve the situation of these eventually
c4555f82
SC
1113@item -tui
1114@cindex @code{--tui}
1115Activate the Terminal User Interface when starting.
1116The Terminal User Interface manages several text windows on the terminal,
1117showing source, assembly, registers and @value{GDBN} command outputs
1118(@pxref{TUI, ,@value{GDBN} Text User Interface}).
1119Do not use this option if you run @value{GDBN} from Emacs
1120(@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1121
1122@c @item -xdb
d700128c 1123@c @cindex @code{--xdb}
53a5351d
JM
1124@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1125@c For information, see the file @file{xdb_trans.html}, which is usually
1126@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1127@c systems.
1128
d700128c
EZ
1129@item -interpreter @var{interp}
1130@cindex @code{--interpreter}
1131Use the interpreter @var{interp} for interface with the controlling
1132program or device. This option is meant to be set by programs which
94bbb2c0 1133communicate with @value{GDBN} using it as a back end.
21c294e6 1134@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1135
da0f9dcd 1136@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0
AC
1137@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
1138The @sc{gdb/mi} Interface}) included in @var{GDBN} version 6.0. The
1139previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3,
1140can be selected with @samp{--interpreter=mi1}. Earlier @sc{gdb/mi}
1141interfaces are not supported.
d700128c
EZ
1142
1143@item -write
1144@cindex @code{--write}
1145Open the executable and core files for both reading and writing. This
1146is equivalent to the @samp{set write on} command inside @value{GDBN}
1147(@pxref{Patching}).
1148
1149@item -statistics
1150@cindex @code{--statistics}
1151This option causes @value{GDBN} to print statistics about time and
1152memory usage after it completes each command and returns to the prompt.
1153
1154@item -version
1155@cindex @code{--version}
1156This option causes @value{GDBN} to print its version number and
1157no-warranty blurb, and exit.
1158
c906108c
SS
1159@end table
1160
6d2ebf8b 1161@node Quitting GDB
c906108c
SS
1162@section Quitting @value{GDBN}
1163@cindex exiting @value{GDBN}
1164@cindex leaving @value{GDBN}
1165
1166@table @code
1167@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1168@kindex q @r{(@code{quit})}
96a2c332
SS
1169@item quit @r{[}@var{expression}@r{]}
1170@itemx q
1171To exit @value{GDBN}, use the @code{quit} command (abbreviated
1172@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1173do not supply @var{expression}, @value{GDBN} will terminate normally;
1174otherwise it will terminate using the result of @var{expression} as the
1175error code.
c906108c
SS
1176@end table
1177
1178@cindex interrupt
1179An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1180terminates the action of any @value{GDBN} command that is in progress and
1181returns to @value{GDBN} command level. It is safe to type the interrupt
1182character at any time because @value{GDBN} does not allow it to take effect
1183until a time when it is safe.
1184
c906108c
SS
1185If you have been using @value{GDBN} to control an attached process or
1186device, you can release it with the @code{detach} command
1187(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1188
6d2ebf8b 1189@node Shell Commands
c906108c
SS
1190@section Shell commands
1191
1192If you need to execute occasional shell commands during your
1193debugging session, there is no need to leave or suspend @value{GDBN}; you can
1194just use the @code{shell} command.
1195
1196@table @code
1197@kindex shell
1198@cindex shell escape
1199@item shell @var{command string}
1200Invoke a standard shell to execute @var{command string}.
c906108c 1201If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1202shell to run. Otherwise @value{GDBN} uses the default shell
1203(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1204@end table
1205
1206The utility @code{make} is often needed in development environments.
1207You do not have to use the @code{shell} command for this purpose in
1208@value{GDBN}:
1209
1210@table @code
1211@kindex make
1212@cindex calling make
1213@item make @var{make-args}
1214Execute the @code{make} program with the specified
1215arguments. This is equivalent to @samp{shell make @var{make-args}}.
1216@end table
1217
0fac0b41
DJ
1218@node Logging output
1219@section Logging output
1220@cindex logging @value{GDBN} output
1221
1222You may want to save the output of @value{GDBN} commands to a file.
1223There are several commands to control @value{GDBN}'s logging.
1224
1225@table @code
1226@kindex set logging
1227@item set logging on
1228Enable logging.
1229@item set logging off
1230Disable logging.
1231@item set logging file @var{file}
1232Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1233@item set logging overwrite [on|off]
1234By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1235you want @code{set logging on} to overwrite the logfile instead.
1236@item set logging redirect [on|off]
1237By default, @value{GDBN} output will go to both the terminal and the logfile.
1238Set @code{redirect} if you want output to go only to the log file.
1239@kindex show logging
1240@item show logging
1241Show the current values of the logging settings.
1242@end table
1243
6d2ebf8b 1244@node Commands
c906108c
SS
1245@chapter @value{GDBN} Commands
1246
1247You can abbreviate a @value{GDBN} command to the first few letters of the command
1248name, if that abbreviation is unambiguous; and you can repeat certain
1249@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1250key to get @value{GDBN} to fill out the rest of a word in a command (or to
1251show you the alternatives available, if there is more than one possibility).
1252
1253@menu
1254* Command Syntax:: How to give commands to @value{GDBN}
1255* Completion:: Command completion
1256* Help:: How to ask @value{GDBN} for help
1257@end menu
1258
6d2ebf8b 1259@node Command Syntax
c906108c
SS
1260@section Command syntax
1261
1262A @value{GDBN} command is a single line of input. There is no limit on
1263how long it can be. It starts with a command name, which is followed by
1264arguments whose meaning depends on the command name. For example, the
1265command @code{step} accepts an argument which is the number of times to
1266step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1267with no arguments. Some commands do not allow any arguments.
c906108c
SS
1268
1269@cindex abbreviation
1270@value{GDBN} command names may always be truncated if that abbreviation is
1271unambiguous. Other possible command abbreviations are listed in the
1272documentation for individual commands. In some cases, even ambiguous
1273abbreviations are allowed; for example, @code{s} is specially defined as
1274equivalent to @code{step} even though there are other commands whose
1275names start with @code{s}. You can test abbreviations by using them as
1276arguments to the @code{help} command.
1277
1278@cindex repeating commands
41afff9a 1279@kindex RET @r{(repeat last command)}
c906108c 1280A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1281repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1282will not repeat this way; these are commands whose unintentional
1283repetition might cause trouble and which you are unlikely to want to
1284repeat.
1285
1286The @code{list} and @code{x} commands, when you repeat them with
1287@key{RET}, construct new arguments rather than repeating
1288exactly as typed. This permits easy scanning of source or memory.
1289
1290@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1291output, in a way similar to the common utility @code{more}
1292(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1293@key{RET} too many in this situation, @value{GDBN} disables command
1294repetition after any command that generates this sort of display.
1295
41afff9a 1296@kindex # @r{(a comment)}
c906108c
SS
1297@cindex comment
1298Any text from a @kbd{#} to the end of the line is a comment; it does
1299nothing. This is useful mainly in command files (@pxref{Command
1300Files,,Command files}).
1301
88118b3a
TT
1302@cindex repeating command sequences
1303@kindex C-o @r{(operate-and-get-next)}
1304The @kbd{C-o} binding is useful for repeating a complex sequence of
1305commands. This command accepts the current line, like @kbd{RET}, and
1306then fetches the next line relative to the current line from the history
1307for editing.
1308
6d2ebf8b 1309@node Completion
c906108c
SS
1310@section Command completion
1311
1312@cindex completion
1313@cindex word completion
1314@value{GDBN} can fill in the rest of a word in a command for you, if there is
1315only one possibility; it can also show you what the valid possibilities
1316are for the next word in a command, at any time. This works for @value{GDBN}
1317commands, @value{GDBN} subcommands, and the names of symbols in your program.
1318
1319Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1320of a word. If there is only one possibility, @value{GDBN} fills in the
1321word, and waits for you to finish the command (or press @key{RET} to
1322enter it). For example, if you type
1323
1324@c FIXME "@key" does not distinguish its argument sufficiently to permit
1325@c complete accuracy in these examples; space introduced for clarity.
1326@c If texinfo enhancements make it unnecessary, it would be nice to
1327@c replace " @key" by "@key" in the following...
474c8240 1328@smallexample
c906108c 1329(@value{GDBP}) info bre @key{TAB}
474c8240 1330@end smallexample
c906108c
SS
1331
1332@noindent
1333@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1334the only @code{info} subcommand beginning with @samp{bre}:
1335
474c8240 1336@smallexample
c906108c 1337(@value{GDBP}) info breakpoints
474c8240 1338@end smallexample
c906108c
SS
1339
1340@noindent
1341You can either press @key{RET} at this point, to run the @code{info
1342breakpoints} command, or backspace and enter something else, if
1343@samp{breakpoints} does not look like the command you expected. (If you
1344were sure you wanted @code{info breakpoints} in the first place, you
1345might as well just type @key{RET} immediately after @samp{info bre},
1346to exploit command abbreviations rather than command completion).
1347
1348If there is more than one possibility for the next word when you press
1349@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1350characters and try again, or just press @key{TAB} a second time;
1351@value{GDBN} displays all the possible completions for that word. For
1352example, you might want to set a breakpoint on a subroutine whose name
1353begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1354just sounds the bell. Typing @key{TAB} again displays all the
1355function names in your program that begin with those characters, for
1356example:
1357
474c8240 1358@smallexample
c906108c
SS
1359(@value{GDBP}) b make_ @key{TAB}
1360@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1361make_a_section_from_file make_environ
1362make_abs_section make_function_type
1363make_blockvector make_pointer_type
1364make_cleanup make_reference_type
c906108c
SS
1365make_command make_symbol_completion_list
1366(@value{GDBP}) b make_
474c8240 1367@end smallexample
c906108c
SS
1368
1369@noindent
1370After displaying the available possibilities, @value{GDBN} copies your
1371partial input (@samp{b make_} in the example) so you can finish the
1372command.
1373
1374If you just want to see the list of alternatives in the first place, you
b37052ae 1375can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1376means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1377key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1378one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1379
1380@cindex quotes in commands
1381@cindex completion of quoted strings
1382Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1383parentheses or other characters that @value{GDBN} normally excludes from
1384its notion of a word. To permit word completion to work in this
1385situation, you may enclose words in @code{'} (single quote marks) in
1386@value{GDBN} commands.
c906108c 1387
c906108c 1388The most likely situation where you might need this is in typing the
b37052ae
EZ
1389name of a C@t{++} function. This is because C@t{++} allows function
1390overloading (multiple definitions of the same function, distinguished
1391by argument type). For example, when you want to set a breakpoint you
1392may need to distinguish whether you mean the version of @code{name}
1393that takes an @code{int} parameter, @code{name(int)}, or the version
1394that takes a @code{float} parameter, @code{name(float)}. To use the
1395word-completion facilities in this situation, type a single quote
1396@code{'} at the beginning of the function name. This alerts
1397@value{GDBN} that it may need to consider more information than usual
1398when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1399
474c8240 1400@smallexample
96a2c332 1401(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1402bubble(double,double) bubble(int,int)
1403(@value{GDBP}) b 'bubble(
474c8240 1404@end smallexample
c906108c
SS
1405
1406In some cases, @value{GDBN} can tell that completing a name requires using
1407quotes. When this happens, @value{GDBN} inserts the quote for you (while
1408completing as much as it can) if you do not type the quote in the first
1409place:
1410
474c8240 1411@smallexample
c906108c
SS
1412(@value{GDBP}) b bub @key{TAB}
1413@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1414(@value{GDBP}) b 'bubble(
474c8240 1415@end smallexample
c906108c
SS
1416
1417@noindent
1418In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1419you have not yet started typing the argument list when you ask for
1420completion on an overloaded symbol.
1421
d4f3574e 1422For more information about overloaded functions, see @ref{C plus plus
b37052ae 1423expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1424overload-resolution off} to disable overload resolution;
b37052ae 1425see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1426
1427
6d2ebf8b 1428@node Help
c906108c
SS
1429@section Getting help
1430@cindex online documentation
1431@kindex help
1432
5d161b24 1433You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1434using the command @code{help}.
1435
1436@table @code
41afff9a 1437@kindex h @r{(@code{help})}
c906108c
SS
1438@item help
1439@itemx h
1440You can use @code{help} (abbreviated @code{h}) with no arguments to
1441display a short list of named classes of commands:
1442
1443@smallexample
1444(@value{GDBP}) help
1445List of classes of commands:
1446
2df3850c 1447aliases -- Aliases of other commands
c906108c 1448breakpoints -- Making program stop at certain points
2df3850c 1449data -- Examining data
c906108c 1450files -- Specifying and examining files
2df3850c
JM
1451internals -- Maintenance commands
1452obscure -- Obscure features
1453running -- Running the program
1454stack -- Examining the stack
c906108c
SS
1455status -- Status inquiries
1456support -- Support facilities
96a2c332
SS
1457tracepoints -- Tracing of program execution without@*
1458 stopping the program
c906108c 1459user-defined -- User-defined commands
c906108c 1460
5d161b24 1461Type "help" followed by a class name for a list of
c906108c 1462commands in that class.
5d161b24 1463Type "help" followed by command name for full
c906108c
SS
1464documentation.
1465Command name abbreviations are allowed if unambiguous.
1466(@value{GDBP})
1467@end smallexample
96a2c332 1468@c the above line break eliminates huge line overfull...
c906108c
SS
1469
1470@item help @var{class}
1471Using one of the general help classes as an argument, you can get a
1472list of the individual commands in that class. For example, here is the
1473help display for the class @code{status}:
1474
1475@smallexample
1476(@value{GDBP}) help status
1477Status inquiries.
1478
1479List of commands:
1480
1481@c Line break in "show" line falsifies real output, but needed
1482@c to fit in smallbook page size.
2df3850c
JM
1483info -- Generic command for showing things
1484 about the program being debugged
1485show -- Generic command for showing things
1486 about the debugger
c906108c 1487
5d161b24 1488Type "help" followed by command name for full
c906108c
SS
1489documentation.
1490Command name abbreviations are allowed if unambiguous.
1491(@value{GDBP})
1492@end smallexample
1493
1494@item help @var{command}
1495With a command name as @code{help} argument, @value{GDBN} displays a
1496short paragraph on how to use that command.
1497
6837a0a2
DB
1498@kindex apropos
1499@item apropos @var{args}
1500The @code{apropos @var{args}} command searches through all of the @value{GDBN}
1501commands, and their documentation, for the regular expression specified in
1502@var{args}. It prints out all matches found. For example:
1503
1504@smallexample
1505apropos reload
1506@end smallexample
1507
b37052ae
EZ
1508@noindent
1509results in:
6837a0a2
DB
1510
1511@smallexample
6d2ebf8b
SS
1512@c @group
1513set symbol-reloading -- Set dynamic symbol table reloading
1514 multiple times in one run
1515show symbol-reloading -- Show dynamic symbol table reloading
1516 multiple times in one run
1517@c @end group
6837a0a2
DB
1518@end smallexample
1519
c906108c
SS
1520@kindex complete
1521@item complete @var{args}
1522The @code{complete @var{args}} command lists all the possible completions
1523for the beginning of a command. Use @var{args} to specify the beginning of the
1524command you want completed. For example:
1525
1526@smallexample
1527complete i
1528@end smallexample
1529
1530@noindent results in:
1531
1532@smallexample
1533@group
2df3850c
JM
1534if
1535ignore
c906108c
SS
1536info
1537inspect
c906108c
SS
1538@end group
1539@end smallexample
1540
1541@noindent This is intended for use by @sc{gnu} Emacs.
1542@end table
1543
1544In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1545and @code{show} to inquire about the state of your program, or the state
1546of @value{GDBN} itself. Each command supports many topics of inquiry; this
1547manual introduces each of them in the appropriate context. The listings
1548under @code{info} and under @code{show} in the Index point to
1549all the sub-commands. @xref{Index}.
1550
1551@c @group
1552@table @code
1553@kindex info
41afff9a 1554@kindex i @r{(@code{info})}
c906108c
SS
1555@item info
1556This command (abbreviated @code{i}) is for describing the state of your
1557program. For example, you can list the arguments given to your program
1558with @code{info args}, list the registers currently in use with @code{info
1559registers}, or list the breakpoints you have set with @code{info breakpoints}.
1560You can get a complete list of the @code{info} sub-commands with
1561@w{@code{help info}}.
1562
1563@kindex set
1564@item set
5d161b24 1565You can assign the result of an expression to an environment variable with
c906108c
SS
1566@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1567@code{set prompt $}.
1568
1569@kindex show
1570@item show
5d161b24 1571In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1572@value{GDBN} itself.
1573You can change most of the things you can @code{show}, by using the
1574related command @code{set}; for example, you can control what number
1575system is used for displays with @code{set radix}, or simply inquire
1576which is currently in use with @code{show radix}.
1577
1578@kindex info set
1579To display all the settable parameters and their current
1580values, you can use @code{show} with no arguments; you may also use
1581@code{info set}. Both commands produce the same display.
1582@c FIXME: "info set" violates the rule that "info" is for state of
1583@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1584@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1585@end table
1586@c @end group
1587
1588Here are three miscellaneous @code{show} subcommands, all of which are
1589exceptional in lacking corresponding @code{set} commands:
1590
1591@table @code
1592@kindex show version
1593@cindex version number
1594@item show version
1595Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1596information in @value{GDBN} bug-reports. If multiple versions of
1597@value{GDBN} are in use at your site, you may need to determine which
1598version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1599commands are introduced, and old ones may wither away. Also, many
1600system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1601variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1602The version number is the same as the one announced when you start
1603@value{GDBN}.
c906108c
SS
1604
1605@kindex show copying
1606@item show copying
1607Display information about permission for copying @value{GDBN}.
1608
1609@kindex show warranty
1610@item show warranty
2df3850c 1611Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1612if your version of @value{GDBN} comes with one.
2df3850c 1613
c906108c
SS
1614@end table
1615
6d2ebf8b 1616@node Running
c906108c
SS
1617@chapter Running Programs Under @value{GDBN}
1618
1619When you run a program under @value{GDBN}, you must first generate
1620debugging information when you compile it.
7a292a7a
SS
1621
1622You may start @value{GDBN} with its arguments, if any, in an environment
1623of your choice. If you are doing native debugging, you may redirect
1624your program's input and output, debug an already running process, or
1625kill a child process.
c906108c
SS
1626
1627@menu
1628* Compilation:: Compiling for debugging
1629* Starting:: Starting your program
c906108c
SS
1630* Arguments:: Your program's arguments
1631* Environment:: Your program's environment
c906108c
SS
1632
1633* Working Directory:: Your program's working directory
1634* Input/Output:: Your program's input and output
1635* Attach:: Debugging an already-running process
1636* Kill Process:: Killing the child process
c906108c
SS
1637
1638* Threads:: Debugging programs with multiple threads
1639* Processes:: Debugging programs with multiple processes
1640@end menu
1641
6d2ebf8b 1642@node Compilation
c906108c
SS
1643@section Compiling for debugging
1644
1645In order to debug a program effectively, you need to generate
1646debugging information when you compile it. This debugging information
1647is stored in the object file; it describes the data type of each
1648variable or function and the correspondence between source line numbers
1649and addresses in the executable code.
1650
1651To request debugging information, specify the @samp{-g} option when you run
1652the compiler.
1653
e2e0bcd1
JB
1654Most compilers do not include information about preprocessor macros in
1655the debugging information if you specify the @option{-g} flag alone,
1656because this information is rather large. Version 3.1 of @value{NGCC},
1657the @sc{gnu} C compiler, provides macro information if you specify the
1658options @option{-gdwarf-2} and @option{-g3}; the former option requests
1659debugging information in the Dwarf 2 format, and the latter requests
1660``extra information''. In the future, we hope to find more compact ways
1661to represent macro information, so that it can be included with
1662@option{-g} alone.
1663
c906108c
SS
1664Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1665options together. Using those compilers, you cannot generate optimized
1666executables containing debugging information.
1667
53a5351d
JM
1668@value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1669without @samp{-O}, making it possible to debug optimized code. We
1670recommend that you @emph{always} use @samp{-g} whenever you compile a
1671program. You may think your program is correct, but there is no sense
1672in pushing your luck.
c906108c
SS
1673
1674@cindex optimized code, debugging
1675@cindex debugging optimized code
1676When you debug a program compiled with @samp{-g -O}, remember that the
1677optimizer is rearranging your code; the debugger shows you what is
1678really there. Do not be too surprised when the execution path does not
1679exactly match your source file! An extreme example: if you define a
1680variable, but never use it, @value{GDBN} never sees that
1681variable---because the compiler optimizes it out of existence.
1682
1683Some things do not work as well with @samp{-g -O} as with just
1684@samp{-g}, particularly on machines with instruction scheduling. If in
1685doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1686please report it to us as a bug (including a test case!).
1687
1688Older versions of the @sc{gnu} C compiler permitted a variant option
1689@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1690format; if your @sc{gnu} C compiler has this option, do not use it.
1691
1692@need 2000
6d2ebf8b 1693@node Starting
c906108c
SS
1694@section Starting your program
1695@cindex starting
1696@cindex running
1697
1698@table @code
1699@kindex run
41afff9a 1700@kindex r @r{(@code{run})}
c906108c
SS
1701@item run
1702@itemx r
7a292a7a
SS
1703Use the @code{run} command to start your program under @value{GDBN}.
1704You must first specify the program name (except on VxWorks) with an
1705argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1706@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1707(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1708
1709@end table
1710
c906108c
SS
1711If you are running your program in an execution environment that
1712supports processes, @code{run} creates an inferior process and makes
1713that process run your program. (In environments without processes,
1714@code{run} jumps to the start of your program.)
1715
1716The execution of a program is affected by certain information it
1717receives from its superior. @value{GDBN} provides ways to specify this
1718information, which you must do @emph{before} starting your program. (You
1719can change it after starting your program, but such changes only affect
1720your program the next time you start it.) This information may be
1721divided into four categories:
1722
1723@table @asis
1724@item The @emph{arguments.}
1725Specify the arguments to give your program as the arguments of the
1726@code{run} command. If a shell is available on your target, the shell
1727is used to pass the arguments, so that you may use normal conventions
1728(such as wildcard expansion or variable substitution) in describing
1729the arguments.
1730In Unix systems, you can control which shell is used with the
1731@code{SHELL} environment variable.
1732@xref{Arguments, ,Your program's arguments}.
1733
1734@item The @emph{environment.}
1735Your program normally inherits its environment from @value{GDBN}, but you can
1736use the @value{GDBN} commands @code{set environment} and @code{unset
1737environment} to change parts of the environment that affect
1738your program. @xref{Environment, ,Your program's environment}.
1739
1740@item The @emph{working directory.}
1741Your program inherits its working directory from @value{GDBN}. You can set
1742the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1743@xref{Working Directory, ,Your program's working directory}.
1744
1745@item The @emph{standard input and output.}
1746Your program normally uses the same device for standard input and
1747standard output as @value{GDBN} is using. You can redirect input and output
1748in the @code{run} command line, or you can use the @code{tty} command to
1749set a different device for your program.
1750@xref{Input/Output, ,Your program's input and output}.
1751
1752@cindex pipes
1753@emph{Warning:} While input and output redirection work, you cannot use
1754pipes to pass the output of the program you are debugging to another
1755program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1756wrong program.
1757@end table
c906108c
SS
1758
1759When you issue the @code{run} command, your program begins to execute
1760immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1761of how to arrange for your program to stop. Once your program has
1762stopped, you may call functions in your program, using the @code{print}
1763or @code{call} commands. @xref{Data, ,Examining Data}.
1764
1765If the modification time of your symbol file has changed since the last
1766time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1767table, and reads it again. When it does this, @value{GDBN} tries to retain
1768your current breakpoints.
1769
6d2ebf8b 1770@node Arguments
c906108c
SS
1771@section Your program's arguments
1772
1773@cindex arguments (to your program)
1774The arguments to your program can be specified by the arguments of the
5d161b24 1775@code{run} command.
c906108c
SS
1776They are passed to a shell, which expands wildcard characters and
1777performs redirection of I/O, and thence to your program. Your
1778@code{SHELL} environment variable (if it exists) specifies what shell
1779@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1780the default shell (@file{/bin/sh} on Unix).
1781
1782On non-Unix systems, the program is usually invoked directly by
1783@value{GDBN}, which emulates I/O redirection via the appropriate system
1784calls, and the wildcard characters are expanded by the startup code of
1785the program, not by the shell.
c906108c
SS
1786
1787@code{run} with no arguments uses the same arguments used by the previous
1788@code{run}, or those set by the @code{set args} command.
1789
c906108c 1790@table @code
41afff9a 1791@kindex set args
c906108c
SS
1792@item set args
1793Specify the arguments to be used the next time your program is run. If
1794@code{set args} has no arguments, @code{run} executes your program
1795with no arguments. Once you have run your program with arguments,
1796using @code{set args} before the next @code{run} is the only way to run
1797it again without arguments.
1798
1799@kindex show args
1800@item show args
1801Show the arguments to give your program when it is started.
1802@end table
1803
6d2ebf8b 1804@node Environment
c906108c
SS
1805@section Your program's environment
1806
1807@cindex environment (of your program)
1808The @dfn{environment} consists of a set of environment variables and
1809their values. Environment variables conventionally record such things as
1810your user name, your home directory, your terminal type, and your search
1811path for programs to run. Usually you set up environment variables with
1812the shell and they are inherited by all the other programs you run. When
1813debugging, it can be useful to try running your program with a modified
1814environment without having to start @value{GDBN} over again.
1815
1816@table @code
1817@kindex path
1818@item path @var{directory}
1819Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1820(the search path for executables) that will be passed to your program.
1821The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1822You may specify several directory names, separated by whitespace or by a
1823system-dependent separator character (@samp{:} on Unix, @samp{;} on
1824MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1825is moved to the front, so it is searched sooner.
c906108c
SS
1826
1827You can use the string @samp{$cwd} to refer to whatever is the current
1828working directory at the time @value{GDBN} searches the path. If you
1829use @samp{.} instead, it refers to the directory where you executed the
1830@code{path} command. @value{GDBN} replaces @samp{.} in the
1831@var{directory} argument (with the current path) before adding
1832@var{directory} to the search path.
1833@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1834@c document that, since repeating it would be a no-op.
1835
1836@kindex show paths
1837@item show paths
1838Display the list of search paths for executables (the @code{PATH}
1839environment variable).
1840
1841@kindex show environment
1842@item show environment @r{[}@var{varname}@r{]}
1843Print the value of environment variable @var{varname} to be given to
1844your program when it starts. If you do not supply @var{varname},
1845print the names and values of all environment variables to be given to
1846your program. You can abbreviate @code{environment} as @code{env}.
1847
1848@kindex set environment
53a5351d 1849@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1850Set environment variable @var{varname} to @var{value}. The value
1851changes for your program only, not for @value{GDBN} itself. @var{value} may
1852be any string; the values of environment variables are just strings, and
1853any interpretation is supplied by your program itself. The @var{value}
1854parameter is optional; if it is eliminated, the variable is set to a
1855null value.
1856@c "any string" here does not include leading, trailing
1857@c blanks. Gnu asks: does anyone care?
1858
1859For example, this command:
1860
474c8240 1861@smallexample
c906108c 1862set env USER = foo
474c8240 1863@end smallexample
c906108c
SS
1864
1865@noindent
d4f3574e 1866tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1867@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1868are not actually required.)
1869
1870@kindex unset environment
1871@item unset environment @var{varname}
1872Remove variable @var{varname} from the environment to be passed to your
1873program. This is different from @samp{set env @var{varname} =};
1874@code{unset environment} removes the variable from the environment,
1875rather than assigning it an empty value.
1876@end table
1877
d4f3574e
SS
1878@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1879the shell indicated
c906108c
SS
1880by your @code{SHELL} environment variable if it exists (or
1881@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1882that runs an initialization file---such as @file{.cshrc} for C-shell, or
1883@file{.bashrc} for BASH---any variables you set in that file affect
1884your program. You may wish to move setting of environment variables to
1885files that are only run when you sign on, such as @file{.login} or
1886@file{.profile}.
1887
6d2ebf8b 1888@node Working Directory
c906108c
SS
1889@section Your program's working directory
1890
1891@cindex working directory (of your program)
1892Each time you start your program with @code{run}, it inherits its
1893working directory from the current working directory of @value{GDBN}.
1894The @value{GDBN} working directory is initially whatever it inherited
1895from its parent process (typically the shell), but you can specify a new
1896working directory in @value{GDBN} with the @code{cd} command.
1897
1898The @value{GDBN} working directory also serves as a default for the commands
1899that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1900specify files}.
1901
1902@table @code
1903@kindex cd
1904@item cd @var{directory}
1905Set the @value{GDBN} working directory to @var{directory}.
1906
1907@kindex pwd
1908@item pwd
1909Print the @value{GDBN} working directory.
1910@end table
1911
6d2ebf8b 1912@node Input/Output
c906108c
SS
1913@section Your program's input and output
1914
1915@cindex redirection
1916@cindex i/o
1917@cindex terminal
1918By default, the program you run under @value{GDBN} does input and output to
5d161b24 1919the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
1920to its own terminal modes to interact with you, but it records the terminal
1921modes your program was using and switches back to them when you continue
1922running your program.
1923
1924@table @code
1925@kindex info terminal
1926@item info terminal
1927Displays information recorded by @value{GDBN} about the terminal modes your
1928program is using.
1929@end table
1930
1931You can redirect your program's input and/or output using shell
1932redirection with the @code{run} command. For example,
1933
474c8240 1934@smallexample
c906108c 1935run > outfile
474c8240 1936@end smallexample
c906108c
SS
1937
1938@noindent
1939starts your program, diverting its output to the file @file{outfile}.
1940
1941@kindex tty
1942@cindex controlling terminal
1943Another way to specify where your program should do input and output is
1944with the @code{tty} command. This command accepts a file name as
1945argument, and causes this file to be the default for future @code{run}
1946commands. It also resets the controlling terminal for the child
1947process, for future @code{run} commands. For example,
1948
474c8240 1949@smallexample
c906108c 1950tty /dev/ttyb
474c8240 1951@end smallexample
c906108c
SS
1952
1953@noindent
1954directs that processes started with subsequent @code{run} commands
1955default to do input and output on the terminal @file{/dev/ttyb} and have
1956that as their controlling terminal.
1957
1958An explicit redirection in @code{run} overrides the @code{tty} command's
1959effect on the input/output device, but not its effect on the controlling
1960terminal.
1961
1962When you use the @code{tty} command or redirect input in the @code{run}
1963command, only the input @emph{for your program} is affected. The input
1964for @value{GDBN} still comes from your terminal.
1965
6d2ebf8b 1966@node Attach
c906108c
SS
1967@section Debugging an already-running process
1968@kindex attach
1969@cindex attach
1970
1971@table @code
1972@item attach @var{process-id}
1973This command attaches to a running process---one that was started
1974outside @value{GDBN}. (@code{info files} shows your active
1975targets.) The command takes as argument a process ID. The usual way to
1976find out the process-id of a Unix process is with the @code{ps} utility,
1977or with the @samp{jobs -l} shell command.
1978
1979@code{attach} does not repeat if you press @key{RET} a second time after
1980executing the command.
1981@end table
1982
1983To use @code{attach}, your program must be running in an environment
1984which supports processes; for example, @code{attach} does not work for
1985programs on bare-board targets that lack an operating system. You must
1986also have permission to send the process a signal.
1987
1988When you use @code{attach}, the debugger finds the program running in
1989the process first by looking in the current working directory, then (if
1990the program is not found) by using the source file search path
1991(@pxref{Source Path, ,Specifying source directories}). You can also use
1992the @code{file} command to load the program. @xref{Files, ,Commands to
1993Specify Files}.
1994
1995The first thing @value{GDBN} does after arranging to debug the specified
1996process is to stop it. You can examine and modify an attached process
53a5351d
JM
1997with all the @value{GDBN} commands that are ordinarily available when
1998you start processes with @code{run}. You can insert breakpoints; you
1999can step and continue; you can modify storage. If you would rather the
2000process continue running, you may use the @code{continue} command after
c906108c
SS
2001attaching @value{GDBN} to the process.
2002
2003@table @code
2004@kindex detach
2005@item detach
2006When you have finished debugging the attached process, you can use the
2007@code{detach} command to release it from @value{GDBN} control. Detaching
2008the process continues its execution. After the @code{detach} command,
2009that process and @value{GDBN} become completely independent once more, and you
2010are ready to @code{attach} another process or start one with @code{run}.
2011@code{detach} does not repeat if you press @key{RET} again after
2012executing the command.
2013@end table
2014
2015If you exit @value{GDBN} or use the @code{run} command while you have an
2016attached process, you kill that process. By default, @value{GDBN} asks
2017for confirmation if you try to do either of these things; you can
2018control whether or not you need to confirm by using the @code{set
2019confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2020messages}).
2021
6d2ebf8b 2022@node Kill Process
c906108c 2023@section Killing the child process
c906108c
SS
2024
2025@table @code
2026@kindex kill
2027@item kill
2028Kill the child process in which your program is running under @value{GDBN}.
2029@end table
2030
2031This command is useful if you wish to debug a core dump instead of a
2032running process. @value{GDBN} ignores any core dump file while your program
2033is running.
2034
2035On some operating systems, a program cannot be executed outside @value{GDBN}
2036while you have breakpoints set on it inside @value{GDBN}. You can use the
2037@code{kill} command in this situation to permit running your program
2038outside the debugger.
2039
2040The @code{kill} command is also useful if you wish to recompile and
2041relink your program, since on many systems it is impossible to modify an
2042executable file while it is running in a process. In this case, when you
2043next type @code{run}, @value{GDBN} notices that the file has changed, and
2044reads the symbol table again (while trying to preserve your current
2045breakpoint settings).
2046
6d2ebf8b 2047@node Threads
c906108c 2048@section Debugging programs with multiple threads
c906108c
SS
2049
2050@cindex threads of execution
2051@cindex multiple threads
2052@cindex switching threads
2053In some operating systems, such as HP-UX and Solaris, a single program
2054may have more than one @dfn{thread} of execution. The precise semantics
2055of threads differ from one operating system to another, but in general
2056the threads of a single program are akin to multiple processes---except
2057that they share one address space (that is, they can all examine and
2058modify the same variables). On the other hand, each thread has its own
2059registers and execution stack, and perhaps private memory.
2060
2061@value{GDBN} provides these facilities for debugging multi-thread
2062programs:
2063
2064@itemize @bullet
2065@item automatic notification of new threads
2066@item @samp{thread @var{threadno}}, a command to switch among threads
2067@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2068@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2069a command to apply a command to a list of threads
2070@item thread-specific breakpoints
2071@end itemize
2072
c906108c
SS
2073@quotation
2074@emph{Warning:} These facilities are not yet available on every
2075@value{GDBN} configuration where the operating system supports threads.
2076If your @value{GDBN} does not support threads, these commands have no
2077effect. For example, a system without thread support shows no output
2078from @samp{info threads}, and always rejects the @code{thread} command,
2079like this:
2080
2081@smallexample
2082(@value{GDBP}) info threads
2083(@value{GDBP}) thread 1
2084Thread ID 1 not known. Use the "info threads" command to
2085see the IDs of currently known threads.
2086@end smallexample
2087@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2088@c doesn't support threads"?
2089@end quotation
c906108c
SS
2090
2091@cindex focus of debugging
2092@cindex current thread
2093The @value{GDBN} thread debugging facility allows you to observe all
2094threads while your program runs---but whenever @value{GDBN} takes
2095control, one thread in particular is always the focus of debugging.
2096This thread is called the @dfn{current thread}. Debugging commands show
2097program information from the perspective of the current thread.
2098
41afff9a 2099@cindex @code{New} @var{systag} message
c906108c
SS
2100@cindex thread identifier (system)
2101@c FIXME-implementors!! It would be more helpful if the [New...] message
2102@c included GDB's numeric thread handle, so you could just go to that
2103@c thread without first checking `info threads'.
2104Whenever @value{GDBN} detects a new thread in your program, it displays
2105the target system's identification for the thread with a message in the
2106form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2107whose form varies depending on the particular system. For example, on
2108LynxOS, you might see
2109
474c8240 2110@smallexample
c906108c 2111[New process 35 thread 27]
474c8240 2112@end smallexample
c906108c
SS
2113
2114@noindent
2115when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2116the @var{systag} is simply something like @samp{process 368}, with no
2117further qualifier.
2118
2119@c FIXME!! (1) Does the [New...] message appear even for the very first
2120@c thread of a program, or does it only appear for the
6ca652b0 2121@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2122@c program?
2123@c (2) *Is* there necessarily a first thread always? Or do some
2124@c multithread systems permit starting a program with multiple
5d161b24 2125@c threads ab initio?
c906108c
SS
2126
2127@cindex thread number
2128@cindex thread identifier (GDB)
2129For debugging purposes, @value{GDBN} associates its own thread
2130number---always a single integer---with each thread in your program.
2131
2132@table @code
2133@kindex info threads
2134@item info threads
2135Display a summary of all threads currently in your
2136program. @value{GDBN} displays for each thread (in this order):
2137
2138@enumerate
2139@item the thread number assigned by @value{GDBN}
2140
2141@item the target system's thread identifier (@var{systag})
2142
2143@item the current stack frame summary for that thread
2144@end enumerate
2145
2146@noindent
2147An asterisk @samp{*} to the left of the @value{GDBN} thread number
2148indicates the current thread.
2149
5d161b24 2150For example,
c906108c
SS
2151@end table
2152@c end table here to get a little more width for example
2153
2154@smallexample
2155(@value{GDBP}) info threads
2156 3 process 35 thread 27 0x34e5 in sigpause ()
2157 2 process 35 thread 23 0x34e5 in sigpause ()
2158* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2159 at threadtest.c:68
2160@end smallexample
53a5351d
JM
2161
2162On HP-UX systems:
c906108c
SS
2163
2164@cindex thread number
2165@cindex thread identifier (GDB)
2166For debugging purposes, @value{GDBN} associates its own thread
2167number---a small integer assigned in thread-creation order---with each
2168thread in your program.
2169
41afff9a
EZ
2170@cindex @code{New} @var{systag} message, on HP-UX
2171@cindex thread identifier (system), on HP-UX
c906108c
SS
2172@c FIXME-implementors!! It would be more helpful if the [New...] message
2173@c included GDB's numeric thread handle, so you could just go to that
2174@c thread without first checking `info threads'.
2175Whenever @value{GDBN} detects a new thread in your program, it displays
2176both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2177form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2178whose form varies depending on the particular system. For example, on
2179HP-UX, you see
2180
474c8240 2181@smallexample
c906108c 2182[New thread 2 (system thread 26594)]
474c8240 2183@end smallexample
c906108c
SS
2184
2185@noindent
5d161b24 2186when @value{GDBN} notices a new thread.
c906108c
SS
2187
2188@table @code
2189@kindex info threads
2190@item info threads
2191Display a summary of all threads currently in your
2192program. @value{GDBN} displays for each thread (in this order):
2193
2194@enumerate
2195@item the thread number assigned by @value{GDBN}
2196
2197@item the target system's thread identifier (@var{systag})
2198
2199@item the current stack frame summary for that thread
2200@end enumerate
2201
2202@noindent
2203An asterisk @samp{*} to the left of the @value{GDBN} thread number
2204indicates the current thread.
2205
5d161b24 2206For example,
c906108c
SS
2207@end table
2208@c end table here to get a little more width for example
2209
474c8240 2210@smallexample
c906108c 2211(@value{GDBP}) info threads
6d2ebf8b
SS
2212 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2213 at quicksort.c:137
2214 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2215 from /usr/lib/libc.2
2216 1 system thread 27905 0x7b003498 in _brk () \@*
2217 from /usr/lib/libc.2
474c8240 2218@end smallexample
c906108c
SS
2219
2220@table @code
2221@kindex thread @var{threadno}
2222@item thread @var{threadno}
2223Make thread number @var{threadno} the current thread. The command
2224argument @var{threadno} is the internal @value{GDBN} thread number, as
2225shown in the first field of the @samp{info threads} display.
2226@value{GDBN} responds by displaying the system identifier of the thread
2227you selected, and its current stack frame summary:
2228
2229@smallexample
2230@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2231(@value{GDBP}) thread 2
c906108c 2232[Switching to process 35 thread 23]
c906108c
SS
22330x34e5 in sigpause ()
2234@end smallexample
2235
2236@noindent
2237As with the @samp{[New @dots{}]} message, the form of the text after
2238@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2239threads.
c906108c
SS
2240
2241@kindex thread apply
2242@item thread apply [@var{threadno}] [@var{all}] @var{args}
2243The @code{thread apply} command allows you to apply a command to one or
2244more threads. Specify the numbers of the threads that you want affected
2245with the command argument @var{threadno}. @var{threadno} is the internal
2246@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2247threads} display. To apply a command to all threads, use
2248@code{thread apply all} @var{args}.
c906108c
SS
2249@end table
2250
2251@cindex automatic thread selection
2252@cindex switching threads automatically
2253@cindex threads, automatic switching
2254Whenever @value{GDBN} stops your program, due to a breakpoint or a
2255signal, it automatically selects the thread where that breakpoint or
2256signal happened. @value{GDBN} alerts you to the context switch with a
2257message of the form @samp{[Switching to @var{systag}]} to identify the
2258thread.
2259
2260@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2261more information about how @value{GDBN} behaves when you stop and start
2262programs with multiple threads.
2263
2264@xref{Set Watchpoints,,Setting watchpoints}, for information about
2265watchpoints in programs with multiple threads.
c906108c 2266
6d2ebf8b 2267@node Processes
c906108c
SS
2268@section Debugging programs with multiple processes
2269
2270@cindex fork, debugging programs which call
2271@cindex multiple processes
2272@cindex processes, multiple
53a5351d
JM
2273On most systems, @value{GDBN} has no special support for debugging
2274programs which create additional processes using the @code{fork}
2275function. When a program forks, @value{GDBN} will continue to debug the
2276parent process and the child process will run unimpeded. If you have
2277set a breakpoint in any code which the child then executes, the child
2278will get a @code{SIGTRAP} signal which (unless it catches the signal)
2279will cause it to terminate.
c906108c
SS
2280
2281However, if you want to debug the child process there is a workaround
2282which isn't too painful. Put a call to @code{sleep} in the code which
2283the child process executes after the fork. It may be useful to sleep
2284only if a certain environment variable is set, or a certain file exists,
2285so that the delay need not occur when you don't want to run @value{GDBN}
2286on the child. While the child is sleeping, use the @code{ps} program to
2287get its process ID. Then tell @value{GDBN} (a new invocation of
2288@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2289the child process (@pxref{Attach}). From that point on you can debug
c906108c 2290the child process just like any other process which you attached to.
c906108c 2291
53a5351d
JM
2292On HP-UX (11.x and later only?), @value{GDBN} provides support for
2293debugging programs that create additional processes using the
2294@code{fork} or @code{vfork} function.
c906108c
SS
2295
2296By default, when a program forks, @value{GDBN} will continue to debug
2297the parent process and the child process will run unimpeded.
2298
2299If you want to follow the child process instead of the parent process,
2300use the command @w{@code{set follow-fork-mode}}.
2301
2302@table @code
2303@kindex set follow-fork-mode
2304@item set follow-fork-mode @var{mode}
2305Set the debugger response to a program call of @code{fork} or
2306@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2307process. The @var{mode} can be:
2308
2309@table @code
2310@item parent
2311The original process is debugged after a fork. The child process runs
2df3850c 2312unimpeded. This is the default.
c906108c
SS
2313
2314@item child
2315The new process is debugged after a fork. The parent process runs
2316unimpeded.
2317
2318@item ask
2319The debugger will ask for one of the above choices.
2320@end table
2321
2322@item show follow-fork-mode
2df3850c 2323Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2324@end table
2325
2326If you ask to debug a child process and a @code{vfork} is followed by an
2327@code{exec}, @value{GDBN} executes the new target up to the first
2328breakpoint in the new target. If you have a breakpoint set on
2329@code{main} in your original program, the breakpoint will also be set on
2330the child process's @code{main}.
2331
2332When a child process is spawned by @code{vfork}, you cannot debug the
2333child or parent until an @code{exec} call completes.
2334
2335If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2336call executes, the new target restarts. To restart the parent process,
2337use the @code{file} command with the parent executable name as its
2338argument.
2339
2340You can use the @code{catch} command to make @value{GDBN} stop whenever
2341a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2342Catchpoints, ,Setting catchpoints}.
c906108c 2343
6d2ebf8b 2344@node Stopping
c906108c
SS
2345@chapter Stopping and Continuing
2346
2347The principal purposes of using a debugger are so that you can stop your
2348program before it terminates; or so that, if your program runs into
2349trouble, you can investigate and find out why.
2350
7a292a7a
SS
2351Inside @value{GDBN}, your program may stop for any of several reasons,
2352such as a signal, a breakpoint, or reaching a new line after a
2353@value{GDBN} command such as @code{step}. You may then examine and
2354change variables, set new breakpoints or remove old ones, and then
2355continue execution. Usually, the messages shown by @value{GDBN} provide
2356ample explanation of the status of your program---but you can also
2357explicitly request this information at any time.
c906108c
SS
2358
2359@table @code
2360@kindex info program
2361@item info program
2362Display information about the status of your program: whether it is
7a292a7a 2363running or not, what process it is, and why it stopped.
c906108c
SS
2364@end table
2365
2366@menu
2367* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2368* Continuing and Stepping:: Resuming execution
c906108c 2369* Signals:: Signals
c906108c 2370* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2371@end menu
2372
6d2ebf8b 2373@node Breakpoints
c906108c
SS
2374@section Breakpoints, watchpoints, and catchpoints
2375
2376@cindex breakpoints
2377A @dfn{breakpoint} makes your program stop whenever a certain point in
2378the program is reached. For each breakpoint, you can add conditions to
2379control in finer detail whether your program stops. You can set
2380breakpoints with the @code{break} command and its variants (@pxref{Set
2381Breaks, ,Setting breakpoints}), to specify the place where your program
2382should stop by line number, function name or exact address in the
2383program.
2384
2385In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2386breakpoints in shared libraries before the executable is run. There is
2387a minor limitation on HP-UX systems: you must wait until the executable
2388is run in order to set breakpoints in shared library routines that are
2389not called directly by the program (for example, routines that are
2390arguments in a @code{pthread_create} call).
2391
2392@cindex watchpoints
2393@cindex memory tracing
2394@cindex breakpoint on memory address
2395@cindex breakpoint on variable modification
2396A @dfn{watchpoint} is a special breakpoint that stops your program
2397when the value of an expression changes. You must use a different
2398command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2399watchpoints}), but aside from that, you can manage a watchpoint like
2400any other breakpoint: you enable, disable, and delete both breakpoints
2401and watchpoints using the same commands.
2402
2403You can arrange to have values from your program displayed automatically
2404whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2405Automatic display}.
2406
2407@cindex catchpoints
2408@cindex breakpoint on events
2409A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2410when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2411exception or the loading of a library. As with watchpoints, you use a
2412different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2413catchpoints}), but aside from that, you can manage a catchpoint like any
2414other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2415@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2416
2417@cindex breakpoint numbers
2418@cindex numbers for breakpoints
2419@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2420catchpoint when you create it; these numbers are successive integers
2421starting with one. In many of the commands for controlling various
2422features of breakpoints you use the breakpoint number to say which
2423breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2424@dfn{disabled}; if disabled, it has no effect on your program until you
2425enable it again.
2426
c5394b80
JM
2427@cindex breakpoint ranges
2428@cindex ranges of breakpoints
2429Some @value{GDBN} commands accept a range of breakpoints on which to
2430operate. A breakpoint range is either a single breakpoint number, like
2431@samp{5}, or two such numbers, in increasing order, separated by a
2432hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2433all breakpoint in that range are operated on.
2434
c906108c
SS
2435@menu
2436* Set Breaks:: Setting breakpoints
2437* Set Watchpoints:: Setting watchpoints
2438* Set Catchpoints:: Setting catchpoints
2439* Delete Breaks:: Deleting breakpoints
2440* Disabling:: Disabling breakpoints
2441* Conditions:: Break conditions
2442* Break Commands:: Breakpoint command lists
c906108c 2443* Breakpoint Menus:: Breakpoint menus
d4f3574e 2444* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2445* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2446@end menu
2447
6d2ebf8b 2448@node Set Breaks
c906108c
SS
2449@subsection Setting breakpoints
2450
5d161b24 2451@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2452@c consider in particular declaration with/without initialization.
2453@c
2454@c FIXME 2 is there stuff on this already? break at fun start, already init?
2455
2456@kindex break
41afff9a
EZ
2457@kindex b @r{(@code{break})}
2458@vindex $bpnum@r{, convenience variable}
c906108c
SS
2459@cindex latest breakpoint
2460Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2461@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2462number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2463Vars,, Convenience variables}, for a discussion of what you can do with
2464convenience variables.
2465
2466You have several ways to say where the breakpoint should go.
2467
2468@table @code
2469@item break @var{function}
5d161b24 2470Set a breakpoint at entry to function @var{function}.
c906108c 2471When using source languages that permit overloading of symbols, such as
b37052ae 2472C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2473@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2474
2475@item break +@var{offset}
2476@itemx break -@var{offset}
2477Set a breakpoint some number of lines forward or back from the position
d4f3574e 2478at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2479(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2480
2481@item break @var{linenum}
2482Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2483The current source file is the last file whose source text was printed.
2484The breakpoint will stop your program just before it executes any of the
c906108c
SS
2485code on that line.
2486
2487@item break @var{filename}:@var{linenum}
2488Set a breakpoint at line @var{linenum} in source file @var{filename}.
2489
2490@item break @var{filename}:@var{function}
2491Set a breakpoint at entry to function @var{function} found in file
2492@var{filename}. Specifying a file name as well as a function name is
2493superfluous except when multiple files contain similarly named
2494functions.
2495
2496@item break *@var{address}
2497Set a breakpoint at address @var{address}. You can use this to set
2498breakpoints in parts of your program which do not have debugging
2499information or source files.
2500
2501@item break
2502When called without any arguments, @code{break} sets a breakpoint at
2503the next instruction to be executed in the selected stack frame
2504(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2505innermost, this makes your program stop as soon as control
2506returns to that frame. This is similar to the effect of a
2507@code{finish} command in the frame inside the selected frame---except
2508that @code{finish} does not leave an active breakpoint. If you use
2509@code{break} without an argument in the innermost frame, @value{GDBN} stops
2510the next time it reaches the current location; this may be useful
2511inside loops.
2512
2513@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2514least one instruction has been executed. If it did not do this, you
2515would be unable to proceed past a breakpoint without first disabling the
2516breakpoint. This rule applies whether or not the breakpoint already
2517existed when your program stopped.
2518
2519@item break @dots{} if @var{cond}
2520Set a breakpoint with condition @var{cond}; evaluate the expression
2521@var{cond} each time the breakpoint is reached, and stop only if the
2522value is nonzero---that is, if @var{cond} evaluates as true.
2523@samp{@dots{}} stands for one of the possible arguments described
2524above (or no argument) specifying where to break. @xref{Conditions,
2525,Break conditions}, for more information on breakpoint conditions.
2526
2527@kindex tbreak
2528@item tbreak @var{args}
2529Set a breakpoint enabled only for one stop. @var{args} are the
2530same as for the @code{break} command, and the breakpoint is set in the same
2531way, but the breakpoint is automatically deleted after the first time your
2532program stops there. @xref{Disabling, ,Disabling breakpoints}.
2533
c906108c
SS
2534@kindex hbreak
2535@item hbreak @var{args}
d4f3574e
SS
2536Set a hardware-assisted breakpoint. @var{args} are the same as for the
2537@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2538breakpoint requires hardware support and some target hardware may not
2539have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2540debugging, so you can set a breakpoint at an instruction without
2541changing the instruction. This can be used with the new trap-generation
2542provided by SPARClite DSU and some x86-based targets. These targets
2543will generate traps when a program accesses some data or instruction
2544address that is assigned to the debug registers. However the hardware
2545breakpoint registers can take a limited number of breakpoints. For
2546example, on the DSU, only two data breakpoints can be set at a time, and
2547@value{GDBN} will reject this command if more than two are used. Delete
2548or disable unused hardware breakpoints before setting new ones
2549(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
501eef12
AC
2550@xref{set remote hardware-breakpoint-limit}.
2551
c906108c
SS
2552
2553@kindex thbreak
2554@item thbreak @var{args}
2555Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2556are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2557the same way. However, like the @code{tbreak} command,
c906108c
SS
2558the breakpoint is automatically deleted after the
2559first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2560command, the breakpoint requires hardware support and some target hardware
2561may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2562See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2563
2564@kindex rbreak
2565@cindex regular expression
2566@item rbreak @var{regex}
c906108c 2567Set breakpoints on all functions matching the regular expression
11cf8741
JM
2568@var{regex}. This command sets an unconditional breakpoint on all
2569matches, printing a list of all breakpoints it set. Once these
2570breakpoints are set, they are treated just like the breakpoints set with
2571the @code{break} command. You can delete them, disable them, or make
2572them conditional the same way as any other breakpoint.
2573
2574The syntax of the regular expression is the standard one used with tools
2575like @file{grep}. Note that this is different from the syntax used by
2576shells, so for instance @code{foo*} matches all functions that include
2577an @code{fo} followed by zero or more @code{o}s. There is an implicit
2578@code{.*} leading and trailing the regular expression you supply, so to
2579match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2580
b37052ae 2581When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2582breakpoints on overloaded functions that are not members of any special
2583classes.
c906108c
SS
2584
2585@kindex info breakpoints
2586@cindex @code{$_} and @code{info breakpoints}
2587@item info breakpoints @r{[}@var{n}@r{]}
2588@itemx info break @r{[}@var{n}@r{]}
2589@itemx info watchpoints @r{[}@var{n}@r{]}
2590Print a table of all breakpoints, watchpoints, and catchpoints set and
2591not deleted, with the following columns for each breakpoint:
2592
2593@table @emph
2594@item Breakpoint Numbers
2595@item Type
2596Breakpoint, watchpoint, or catchpoint.
2597@item Disposition
2598Whether the breakpoint is marked to be disabled or deleted when hit.
2599@item Enabled or Disabled
2600Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2601that are not enabled.
2602@item Address
2df3850c 2603Where the breakpoint is in your program, as a memory address.
c906108c
SS
2604@item What
2605Where the breakpoint is in the source for your program, as a file and
2606line number.
2607@end table
2608
2609@noindent
2610If a breakpoint is conditional, @code{info break} shows the condition on
2611the line following the affected breakpoint; breakpoint commands, if any,
2612are listed after that.
2613
2614@noindent
2615@code{info break} with a breakpoint
2616number @var{n} as argument lists only that breakpoint. The
2617convenience variable @code{$_} and the default examining-address for
2618the @code{x} command are set to the address of the last breakpoint
5d161b24 2619listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2620
2621@noindent
2622@code{info break} displays a count of the number of times the breakpoint
2623has been hit. This is especially useful in conjunction with the
2624@code{ignore} command. You can ignore a large number of breakpoint
2625hits, look at the breakpoint info to see how many times the breakpoint
2626was hit, and then run again, ignoring one less than that number. This
2627will get you quickly to the last hit of that breakpoint.
2628@end table
2629
2630@value{GDBN} allows you to set any number of breakpoints at the same place in
2631your program. There is nothing silly or meaningless about this. When
2632the breakpoints are conditional, this is even useful
2633(@pxref{Conditions, ,Break conditions}).
2634
2635@cindex negative breakpoint numbers
2636@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2637@value{GDBN} itself sometimes sets breakpoints in your program for
2638special purposes, such as proper handling of @code{longjmp} (in C
2639programs). These internal breakpoints are assigned negative numbers,
2640starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2641You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2642@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2643
2644
6d2ebf8b 2645@node Set Watchpoints
c906108c
SS
2646@subsection Setting watchpoints
2647
2648@cindex setting watchpoints
2649@cindex software watchpoints
2650@cindex hardware watchpoints
2651You can use a watchpoint to stop execution whenever the value of an
2652expression changes, without having to predict a particular place where
2653this may happen.
2654
2655Depending on your system, watchpoints may be implemented in software or
2df3850c 2656hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2657program and testing the variable's value each time, which is hundreds of
2658times slower than normal execution. (But this may still be worth it, to
2659catch errors where you have no clue what part of your program is the
2660culprit.)
2661
1104b9e7 2662On some systems, such as HP-UX, @sc{gnu}/Linux and some other x86-based targets,
2df3850c 2663@value{GDBN} includes support for
c906108c
SS
2664hardware watchpoints, which do not slow down the running of your
2665program.
2666
2667@table @code
2668@kindex watch
2669@item watch @var{expr}
2670Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2671is written into by the program and its value changes.
2672
2673@kindex rwatch
2674@item rwatch @var{expr}
2675Set a watchpoint that will break when watch @var{expr} is read by the program.
c906108c
SS
2676
2677@kindex awatch
2678@item awatch @var{expr}
2df3850c 2679Set a watchpoint that will break when @var{expr} is either read or written into
7be570e7 2680by the program.
c906108c
SS
2681
2682@kindex info watchpoints
2683@item info watchpoints
2684This command prints a list of watchpoints, breakpoints, and catchpoints;
2685it is the same as @code{info break}.
2686@end table
2687
2688@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2689watchpoints execute very quickly, and the debugger reports a change in
2690value at the exact instruction where the change occurs. If @value{GDBN}
2691cannot set a hardware watchpoint, it sets a software watchpoint, which
2692executes more slowly and reports the change in value at the next
2693statement, not the instruction, after the change occurs.
2694
2695When you issue the @code{watch} command, @value{GDBN} reports
2696
474c8240 2697@smallexample
c906108c 2698Hardware watchpoint @var{num}: @var{expr}
474c8240 2699@end smallexample
c906108c
SS
2700
2701@noindent
2702if it was able to set a hardware watchpoint.
2703
7be570e7
JM
2704Currently, the @code{awatch} and @code{rwatch} commands can only set
2705hardware watchpoints, because accesses to data that don't change the
2706value of the watched expression cannot be detected without examining
2707every instruction as it is being executed, and @value{GDBN} does not do
2708that currently. If @value{GDBN} finds that it is unable to set a
2709hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2710will print a message like this:
2711
2712@smallexample
2713Expression cannot be implemented with read/access watchpoint.
2714@end smallexample
2715
2716Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2717data type of the watched expression is wider than what a hardware
2718watchpoint on the target machine can handle. For example, some systems
2719can only watch regions that are up to 4 bytes wide; on such systems you
2720cannot set hardware watchpoints for an expression that yields a
2721double-precision floating-point number (which is typically 8 bytes
2722wide). As a work-around, it might be possible to break the large region
2723into a series of smaller ones and watch them with separate watchpoints.
2724
2725If you set too many hardware watchpoints, @value{GDBN} might be unable
2726to insert all of them when you resume the execution of your program.
2727Since the precise number of active watchpoints is unknown until such
2728time as the program is about to be resumed, @value{GDBN} might not be
2729able to warn you about this when you set the watchpoints, and the
2730warning will be printed only when the program is resumed:
2731
2732@smallexample
2733Hardware watchpoint @var{num}: Could not insert watchpoint
2734@end smallexample
2735
2736@noindent
2737If this happens, delete or disable some of the watchpoints.
2738
2739The SPARClite DSU will generate traps when a program accesses some data
2740or instruction address that is assigned to the debug registers. For the
2741data addresses, DSU facilitates the @code{watch} command. However the
2742hardware breakpoint registers can only take two data watchpoints, and
2743both watchpoints must be the same kind. For example, you can set two
2744watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2745@strong{or} two with @code{awatch} commands, but you cannot set one
2746watchpoint with one command and the other with a different command.
c906108c
SS
2747@value{GDBN} will reject the command if you try to mix watchpoints.
2748Delete or disable unused watchpoint commands before setting new ones.
2749
2750If you call a function interactively using @code{print} or @code{call},
2df3850c 2751any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2752kind of breakpoint or the call completes.
2753
7be570e7
JM
2754@value{GDBN} automatically deletes watchpoints that watch local
2755(automatic) variables, or expressions that involve such variables, when
2756they go out of scope, that is, when the execution leaves the block in
2757which these variables were defined. In particular, when the program
2758being debugged terminates, @emph{all} local variables go out of scope,
2759and so only watchpoints that watch global variables remain set. If you
2760rerun the program, you will need to set all such watchpoints again. One
2761way of doing that would be to set a code breakpoint at the entry to the
2762@code{main} function and when it breaks, set all the watchpoints.
2763
c906108c
SS
2764@quotation
2765@cindex watchpoints and threads
2766@cindex threads and watchpoints
c906108c
SS
2767@emph{Warning:} In multi-thread programs, watchpoints have only limited
2768usefulness. With the current watchpoint implementation, @value{GDBN}
2769can only watch the value of an expression @emph{in a single thread}. If
2770you are confident that the expression can only change due to the current
2771thread's activity (and if you are also confident that no other thread
2772can become current), then you can use watchpoints as usual. However,
2773@value{GDBN} may not notice when a non-current thread's activity changes
2774the expression.
53a5351d 2775
d4f3574e 2776@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
2777@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2778have only limited usefulness. If @value{GDBN} creates a software
2779watchpoint, it can only watch the value of an expression @emph{in a
2780single thread}. If you are confident that the expression can only
2781change due to the current thread's activity (and if you are also
2782confident that no other thread can become current), then you can use
2783software watchpoints as usual. However, @value{GDBN} may not notice
2784when a non-current thread's activity changes the expression. (Hardware
2785watchpoints, in contrast, watch an expression in all threads.)
c906108c 2786@end quotation
c906108c 2787
501eef12
AC
2788@xref{set remote hardware-watchpoint-limit}.
2789
6d2ebf8b 2790@node Set Catchpoints
c906108c 2791@subsection Setting catchpoints
d4f3574e 2792@cindex catchpoints, setting
c906108c
SS
2793@cindex exception handlers
2794@cindex event handling
2795
2796You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 2797kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
2798shared library. Use the @code{catch} command to set a catchpoint.
2799
2800@table @code
2801@kindex catch
2802@item catch @var{event}
2803Stop when @var{event} occurs. @var{event} can be any of the following:
2804@table @code
2805@item throw
2806@kindex catch throw
b37052ae 2807The throwing of a C@t{++} exception.
c906108c
SS
2808
2809@item catch
2810@kindex catch catch
b37052ae 2811The catching of a C@t{++} exception.
c906108c
SS
2812
2813@item exec
2814@kindex catch exec
2815A call to @code{exec}. This is currently only available for HP-UX.
2816
2817@item fork
2818@kindex catch fork
2819A call to @code{fork}. This is currently only available for HP-UX.
2820
2821@item vfork
2822@kindex catch vfork
2823A call to @code{vfork}. This is currently only available for HP-UX.
2824
2825@item load
2826@itemx load @var{libname}
2827@kindex catch load
2828The dynamic loading of any shared library, or the loading of the library
2829@var{libname}. This is currently only available for HP-UX.
2830
2831@item unload
2832@itemx unload @var{libname}
2833@kindex catch unload
2834The unloading of any dynamically loaded shared library, or the unloading
2835of the library @var{libname}. This is currently only available for HP-UX.
2836@end table
2837
2838@item tcatch @var{event}
2839Set a catchpoint that is enabled only for one stop. The catchpoint is
2840automatically deleted after the first time the event is caught.
2841
2842@end table
2843
2844Use the @code{info break} command to list the current catchpoints.
2845
b37052ae 2846There are currently some limitations to C@t{++} exception handling
c906108c
SS
2847(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2848
2849@itemize @bullet
2850@item
2851If you call a function interactively, @value{GDBN} normally returns
2852control to you when the function has finished executing. If the call
2853raises an exception, however, the call may bypass the mechanism that
2854returns control to you and cause your program either to abort or to
2855simply continue running until it hits a breakpoint, catches a signal
2856that @value{GDBN} is listening for, or exits. This is the case even if
2857you set a catchpoint for the exception; catchpoints on exceptions are
2858disabled within interactive calls.
2859
2860@item
2861You cannot raise an exception interactively.
2862
2863@item
2864You cannot install an exception handler interactively.
2865@end itemize
2866
2867@cindex raise exceptions
2868Sometimes @code{catch} is not the best way to debug exception handling:
2869if you need to know exactly where an exception is raised, it is better to
2870stop @emph{before} the exception handler is called, since that way you
2871can see the stack before any unwinding takes place. If you set a
2872breakpoint in an exception handler instead, it may not be easy to find
2873out where the exception was raised.
2874
2875To stop just before an exception handler is called, you need some
b37052ae 2876knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
2877raised by calling a library function named @code{__raise_exception}
2878which has the following ANSI C interface:
2879
474c8240 2880@smallexample
c906108c 2881 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
2882 @var{id} is the exception identifier. */
2883 void __raise_exception (void **addr, void *id);
474c8240 2884@end smallexample
c906108c
SS
2885
2886@noindent
2887To make the debugger catch all exceptions before any stack
2888unwinding takes place, set a breakpoint on @code{__raise_exception}
2889(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2890
2891With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2892that depends on the value of @var{id}, you can stop your program when
2893a specific exception is raised. You can use multiple conditional
2894breakpoints to stop your program when any of a number of exceptions are
2895raised.
2896
2897
6d2ebf8b 2898@node Delete Breaks
c906108c
SS
2899@subsection Deleting breakpoints
2900
2901@cindex clearing breakpoints, watchpoints, catchpoints
2902@cindex deleting breakpoints, watchpoints, catchpoints
2903It is often necessary to eliminate a breakpoint, watchpoint, or
2904catchpoint once it has done its job and you no longer want your program
2905to stop there. This is called @dfn{deleting} the breakpoint. A
2906breakpoint that has been deleted no longer exists; it is forgotten.
2907
2908With the @code{clear} command you can delete breakpoints according to
2909where they are in your program. With the @code{delete} command you can
2910delete individual breakpoints, watchpoints, or catchpoints by specifying
2911their breakpoint numbers.
2912
2913It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2914automatically ignores breakpoints on the first instruction to be executed
2915when you continue execution without changing the execution address.
2916
2917@table @code
2918@kindex clear
2919@item clear
2920Delete any breakpoints at the next instruction to be executed in the
2921selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2922the innermost frame is selected, this is a good way to delete a
2923breakpoint where your program just stopped.
2924
2925@item clear @var{function}
2926@itemx clear @var{filename}:@var{function}
2927Delete any breakpoints set at entry to the function @var{function}.
2928
2929@item clear @var{linenum}
2930@itemx clear @var{filename}:@var{linenum}
2931Delete any breakpoints set at or within the code of the specified line.
2932
2933@cindex delete breakpoints
2934@kindex delete
41afff9a 2935@kindex d @r{(@code{delete})}
c5394b80
JM
2936@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
2937Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
2938ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
2939breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
2940confirm off}). You can abbreviate this command as @code{d}.
2941@end table
2942
6d2ebf8b 2943@node Disabling
c906108c
SS
2944@subsection Disabling breakpoints
2945
2946@kindex disable breakpoints
2947@kindex enable breakpoints
2948Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2949prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
2950it had been deleted, but remembers the information on the breakpoint so
2951that you can @dfn{enable} it again later.
2952
2953You disable and enable breakpoints, watchpoints, and catchpoints with
2954the @code{enable} and @code{disable} commands, optionally specifying one
2955or more breakpoint numbers as arguments. Use @code{info break} or
2956@code{info watch} to print a list of breakpoints, watchpoints, and
2957catchpoints if you do not know which numbers to use.
2958
2959A breakpoint, watchpoint, or catchpoint can have any of four different
2960states of enablement:
2961
2962@itemize @bullet
2963@item
2964Enabled. The breakpoint stops your program. A breakpoint set
2965with the @code{break} command starts out in this state.
2966@item
2967Disabled. The breakpoint has no effect on your program.
2968@item
2969Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 2970disabled.
c906108c
SS
2971@item
2972Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
2973immediately after it does so it is deleted permanently. A breakpoint
2974set with the @code{tbreak} command starts out in this state.
c906108c
SS
2975@end itemize
2976
2977You can use the following commands to enable or disable breakpoints,
2978watchpoints, and catchpoints:
2979
2980@table @code
2981@kindex disable breakpoints
2982@kindex disable
41afff9a 2983@kindex dis @r{(@code{disable})}
c5394b80 2984@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
2985Disable the specified breakpoints---or all breakpoints, if none are
2986listed. A disabled breakpoint has no effect but is not forgotten. All
2987options such as ignore-counts, conditions and commands are remembered in
2988case the breakpoint is enabled again later. You may abbreviate
2989@code{disable} as @code{dis}.
2990
2991@kindex enable breakpoints
2992@kindex enable
c5394b80 2993@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
2994Enable the specified breakpoints (or all defined breakpoints). They
2995become effective once again in stopping your program.
2996
c5394b80 2997@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
2998Enable the specified breakpoints temporarily. @value{GDBN} disables any
2999of these breakpoints immediately after stopping your program.
3000
c5394b80 3001@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3002Enable the specified breakpoints to work once, then die. @value{GDBN}
3003deletes any of these breakpoints as soon as your program stops there.
3004@end table
3005
d4f3574e
SS
3006@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3007@c confusing: tbreak is also initially enabled.
c906108c
SS
3008Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3009,Setting breakpoints}), breakpoints that you set are initially enabled;
3010subsequently, they become disabled or enabled only when you use one of
3011the commands above. (The command @code{until} can set and delete a
3012breakpoint of its own, but it does not change the state of your other
3013breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3014stepping}.)
3015
6d2ebf8b 3016@node Conditions
c906108c
SS
3017@subsection Break conditions
3018@cindex conditional breakpoints
3019@cindex breakpoint conditions
3020
3021@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3022@c in particular for a watchpoint?
c906108c
SS
3023The simplest sort of breakpoint breaks every time your program reaches a
3024specified place. You can also specify a @dfn{condition} for a
3025breakpoint. A condition is just a Boolean expression in your
3026programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3027a condition evaluates the expression each time your program reaches it,
3028and your program stops only if the condition is @emph{true}.
3029
3030This is the converse of using assertions for program validation; in that
3031situation, you want to stop when the assertion is violated---that is,
3032when the condition is false. In C, if you want to test an assertion expressed
3033by the condition @var{assert}, you should set the condition
3034@samp{! @var{assert}} on the appropriate breakpoint.
3035
3036Conditions are also accepted for watchpoints; you may not need them,
3037since a watchpoint is inspecting the value of an expression anyhow---but
3038it might be simpler, say, to just set a watchpoint on a variable name,
3039and specify a condition that tests whether the new value is an interesting
3040one.
3041
3042Break conditions can have side effects, and may even call functions in
3043your program. This can be useful, for example, to activate functions
3044that log program progress, or to use your own print functions to
3045format special data structures. The effects are completely predictable
3046unless there is another enabled breakpoint at the same address. (In
3047that case, @value{GDBN} might see the other breakpoint first and stop your
3048program without checking the condition of this one.) Note that
d4f3574e
SS
3049breakpoint commands are usually more convenient and flexible than break
3050conditions for the
c906108c
SS
3051purpose of performing side effects when a breakpoint is reached
3052(@pxref{Break Commands, ,Breakpoint command lists}).
3053
3054Break conditions can be specified when a breakpoint is set, by using
3055@samp{if} in the arguments to the @code{break} command. @xref{Set
3056Breaks, ,Setting breakpoints}. They can also be changed at any time
3057with the @code{condition} command.
53a5351d 3058
c906108c
SS
3059You can also use the @code{if} keyword with the @code{watch} command.
3060The @code{catch} command does not recognize the @code{if} keyword;
3061@code{condition} is the only way to impose a further condition on a
3062catchpoint.
c906108c
SS
3063
3064@table @code
3065@kindex condition
3066@item condition @var{bnum} @var{expression}
3067Specify @var{expression} as the break condition for breakpoint,
3068watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3069breakpoint @var{bnum} stops your program only if the value of
3070@var{expression} is true (nonzero, in C). When you use
3071@code{condition}, @value{GDBN} checks @var{expression} immediately for
3072syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3073referents in the context of your breakpoint. If @var{expression} uses
3074symbols not referenced in the context of the breakpoint, @value{GDBN}
3075prints an error message:
3076
474c8240 3077@smallexample
d4f3574e 3078No symbol "foo" in current context.
474c8240 3079@end smallexample
d4f3574e
SS
3080
3081@noindent
c906108c
SS
3082@value{GDBN} does
3083not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3084command (or a command that sets a breakpoint with a condition, like
3085@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3086
3087@item condition @var{bnum}
3088Remove the condition from breakpoint number @var{bnum}. It becomes
3089an ordinary unconditional breakpoint.
3090@end table
3091
3092@cindex ignore count (of breakpoint)
3093A special case of a breakpoint condition is to stop only when the
3094breakpoint has been reached a certain number of times. This is so
3095useful that there is a special way to do it, using the @dfn{ignore
3096count} of the breakpoint. Every breakpoint has an ignore count, which
3097is an integer. Most of the time, the ignore count is zero, and
3098therefore has no effect. But if your program reaches a breakpoint whose
3099ignore count is positive, then instead of stopping, it just decrements
3100the ignore count by one and continues. As a result, if the ignore count
3101value is @var{n}, the breakpoint does not stop the next @var{n} times
3102your program reaches it.
3103
3104@table @code
3105@kindex ignore
3106@item ignore @var{bnum} @var{count}
3107Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3108The next @var{count} times the breakpoint is reached, your program's
3109execution does not stop; other than to decrement the ignore count, @value{GDBN}
3110takes no action.
3111
3112To make the breakpoint stop the next time it is reached, specify
3113a count of zero.
3114
3115When you use @code{continue} to resume execution of your program from a
3116breakpoint, you can specify an ignore count directly as an argument to
3117@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3118Stepping,,Continuing and stepping}.
3119
3120If a breakpoint has a positive ignore count and a condition, the
3121condition is not checked. Once the ignore count reaches zero,
3122@value{GDBN} resumes checking the condition.
3123
3124You could achieve the effect of the ignore count with a condition such
3125as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3126is decremented each time. @xref{Convenience Vars, ,Convenience
3127variables}.
3128@end table
3129
3130Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3131
3132
6d2ebf8b 3133@node Break Commands
c906108c
SS
3134@subsection Breakpoint command lists
3135
3136@cindex breakpoint commands
3137You can give any breakpoint (or watchpoint or catchpoint) a series of
3138commands to execute when your program stops due to that breakpoint. For
3139example, you might want to print the values of certain expressions, or
3140enable other breakpoints.
3141
3142@table @code
3143@kindex commands
3144@kindex end
3145@item commands @r{[}@var{bnum}@r{]}
3146@itemx @dots{} @var{command-list} @dots{}
3147@itemx end
3148Specify a list of commands for breakpoint number @var{bnum}. The commands
3149themselves appear on the following lines. Type a line containing just
3150@code{end} to terminate the commands.
3151
3152To remove all commands from a breakpoint, type @code{commands} and
3153follow it immediately with @code{end}; that is, give no commands.
3154
3155With no @var{bnum} argument, @code{commands} refers to the last
3156breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3157recently encountered).
3158@end table
3159
3160Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3161disabled within a @var{command-list}.
3162
3163You can use breakpoint commands to start your program up again. Simply
3164use the @code{continue} command, or @code{step}, or any other command
3165that resumes execution.
3166
3167Any other commands in the command list, after a command that resumes
3168execution, are ignored. This is because any time you resume execution
3169(even with a simple @code{next} or @code{step}), you may encounter
3170another breakpoint---which could have its own command list, leading to
3171ambiguities about which list to execute.
3172
3173@kindex silent
3174If the first command you specify in a command list is @code{silent}, the
3175usual message about stopping at a breakpoint is not printed. This may
3176be desirable for breakpoints that are to print a specific message and
3177then continue. If none of the remaining commands print anything, you
3178see no sign that the breakpoint was reached. @code{silent} is
3179meaningful only at the beginning of a breakpoint command list.
3180
3181The commands @code{echo}, @code{output}, and @code{printf} allow you to
3182print precisely controlled output, and are often useful in silent
3183breakpoints. @xref{Output, ,Commands for controlled output}.
3184
3185For example, here is how you could use breakpoint commands to print the
3186value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3187
474c8240 3188@smallexample
c906108c
SS
3189break foo if x>0
3190commands
3191silent
3192printf "x is %d\n",x
3193cont
3194end
474c8240 3195@end smallexample
c906108c
SS
3196
3197One application for breakpoint commands is to compensate for one bug so
3198you can test for another. Put a breakpoint just after the erroneous line
3199of code, give it a condition to detect the case in which something
3200erroneous has been done, and give it commands to assign correct values
3201to any variables that need them. End with the @code{continue} command
3202so that your program does not stop, and start with the @code{silent}
3203command so that no output is produced. Here is an example:
3204
474c8240 3205@smallexample
c906108c
SS
3206break 403
3207commands
3208silent
3209set x = y + 4
3210cont
3211end
474c8240 3212@end smallexample
c906108c 3213
6d2ebf8b 3214@node Breakpoint Menus
c906108c
SS
3215@subsection Breakpoint menus
3216@cindex overloading
3217@cindex symbol overloading
3218
b37303ee
AF
3219Some programming languages (notably C@t{++} and Objective-C) permit a
3220single function name
c906108c
SS
3221to be defined several times, for application in different contexts.
3222This is called @dfn{overloading}. When a function name is overloaded,
3223@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3224a breakpoint. If you realize this is a problem, you can use
3225something like @samp{break @var{function}(@var{types})} to specify which
3226particular version of the function you want. Otherwise, @value{GDBN} offers
3227you a menu of numbered choices for different possible breakpoints, and
3228waits for your selection with the prompt @samp{>}. The first two
3229options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3230sets a breakpoint at each definition of @var{function}, and typing
3231@kbd{0} aborts the @code{break} command without setting any new
3232breakpoints.
3233
3234For example, the following session excerpt shows an attempt to set a
3235breakpoint at the overloaded symbol @code{String::after}.
3236We choose three particular definitions of that function name:
3237
3238@c FIXME! This is likely to change to show arg type lists, at least
3239@smallexample
3240@group
3241(@value{GDBP}) b String::after
3242[0] cancel
3243[1] all
3244[2] file:String.cc; line number:867
3245[3] file:String.cc; line number:860
3246[4] file:String.cc; line number:875
3247[5] file:String.cc; line number:853
3248[6] file:String.cc; line number:846
3249[7] file:String.cc; line number:735
3250> 2 4 6
3251Breakpoint 1 at 0xb26c: file String.cc, line 867.
3252Breakpoint 2 at 0xb344: file String.cc, line 875.
3253Breakpoint 3 at 0xafcc: file String.cc, line 846.
3254Multiple breakpoints were set.
3255Use the "delete" command to delete unwanted
3256 breakpoints.
3257(@value{GDBP})
3258@end group
3259@end smallexample
c906108c
SS
3260
3261@c @ifclear BARETARGET
6d2ebf8b 3262@node Error in Breakpoints
d4f3574e 3263@subsection ``Cannot insert breakpoints''
c906108c
SS
3264@c
3265@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3266@c
d4f3574e
SS
3267Under some operating systems, breakpoints cannot be used in a program if
3268any other process is running that program. In this situation,
5d161b24 3269attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3270@value{GDBN} to print an error message:
3271
474c8240 3272@smallexample
d4f3574e
SS
3273Cannot insert breakpoints.
3274The same program may be running in another process.
474c8240 3275@end smallexample
d4f3574e
SS
3276
3277When this happens, you have three ways to proceed:
3278
3279@enumerate
3280@item
3281Remove or disable the breakpoints, then continue.
3282
3283@item
5d161b24 3284Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3285name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3286that @value{GDBN} should run your program under that name.
d4f3574e
SS
3287Then start your program again.
3288
3289@item
3290Relink your program so that the text segment is nonsharable, using the
3291linker option @samp{-N}. The operating system limitation may not apply
3292to nonsharable executables.
3293@end enumerate
c906108c
SS
3294@c @end ifclear
3295
d4f3574e
SS
3296A similar message can be printed if you request too many active
3297hardware-assisted breakpoints and watchpoints:
3298
3299@c FIXME: the precise wording of this message may change; the relevant
3300@c source change is not committed yet (Sep 3, 1999).
3301@smallexample
3302Stopped; cannot insert breakpoints.
3303You may have requested too many hardware breakpoints and watchpoints.
3304@end smallexample
3305
3306@noindent
3307This message is printed when you attempt to resume the program, since
3308only then @value{GDBN} knows exactly how many hardware breakpoints and
3309watchpoints it needs to insert.
3310
3311When this message is printed, you need to disable or remove some of the
3312hardware-assisted breakpoints and watchpoints, and then continue.
3313
1485d690
KB
3314@node Breakpoint related warnings
3315@subsection ``Breakpoint address adjusted...''
3316@cindex breakpoint address adjusted
3317
3318Some processor architectures place constraints on the addresses at
3319which breakpoints may be placed. For architectures thus constrained,
3320@value{GDBN} will attempt to adjust the breakpoint's address to comply
3321with the constraints dictated by the architecture.
3322
3323One example of such an architecture is the Fujitsu FR-V. The FR-V is
3324a VLIW architecture in which a number of RISC-like instructions may be
3325bundled together for parallel execution. The FR-V architecture
3326constrains the location of a breakpoint instruction within such a
3327bundle to the instruction with the lowest address. @value{GDBN}
3328honors this constraint by adjusting a breakpoint's address to the
3329first in the bundle.
3330
3331It is not uncommon for optimized code to have bundles which contain
3332instructions from different source statements, thus it may happen that
3333a breakpoint's address will be adjusted from one source statement to
3334another. Since this adjustment may significantly alter @value{GDBN}'s
3335breakpoint related behavior from what the user expects, a warning is
3336printed when the breakpoint is first set and also when the breakpoint
3337is hit.
3338
3339A warning like the one below is printed when setting a breakpoint
3340that's been subject to address adjustment:
3341
3342@smallexample
3343warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3344@end smallexample
3345
3346Such warnings are printed both for user settable and @value{GDBN}'s
3347internal breakpoints. If you see one of these warnings, you should
3348verify that a breakpoint set at the adjusted address will have the
3349desired affect. If not, the breakpoint in question may be removed and
3350other breakpoints may be set which will have the desired behavior.
3351E.g., it may be sufficient to place the breakpoint at a later
3352instruction. A conditional breakpoint may also be useful in some
3353cases to prevent the breakpoint from triggering too often.
3354
3355@value{GDBN} will also issue a warning when stopping at one of these
3356adjusted breakpoints:
3357
3358@smallexample
3359warning: Breakpoint 1 address previously adjusted from 0x00010414
3360to 0x00010410.
3361@end smallexample
3362
3363When this warning is encountered, it may be too late to take remedial
3364action except in cases where the breakpoint is hit earlier or more
3365frequently than expected.
d4f3574e 3366
6d2ebf8b 3367@node Continuing and Stepping
c906108c
SS
3368@section Continuing and stepping
3369
3370@cindex stepping
3371@cindex continuing
3372@cindex resuming execution
3373@dfn{Continuing} means resuming program execution until your program
3374completes normally. In contrast, @dfn{stepping} means executing just
3375one more ``step'' of your program, where ``step'' may mean either one
3376line of source code, or one machine instruction (depending on what
7a292a7a
SS
3377particular command you use). Either when continuing or when stepping,
3378your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3379it stops due to a signal, you may want to use @code{handle}, or use
3380@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3381
3382@table @code
3383@kindex continue
41afff9a
EZ
3384@kindex c @r{(@code{continue})}
3385@kindex fg @r{(resume foreground execution)}
c906108c
SS
3386@item continue @r{[}@var{ignore-count}@r{]}
3387@itemx c @r{[}@var{ignore-count}@r{]}
3388@itemx fg @r{[}@var{ignore-count}@r{]}
3389Resume program execution, at the address where your program last stopped;
3390any breakpoints set at that address are bypassed. The optional argument
3391@var{ignore-count} allows you to specify a further number of times to
3392ignore a breakpoint at this location; its effect is like that of
3393@code{ignore} (@pxref{Conditions, ,Break conditions}).
3394
3395The argument @var{ignore-count} is meaningful only when your program
3396stopped due to a breakpoint. At other times, the argument to
3397@code{continue} is ignored.
3398
d4f3574e
SS
3399The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3400debugged program is deemed to be the foreground program) are provided
3401purely for convenience, and have exactly the same behavior as
3402@code{continue}.
c906108c
SS
3403@end table
3404
3405To resume execution at a different place, you can use @code{return}
3406(@pxref{Returning, ,Returning from a function}) to go back to the
3407calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3408different address}) to go to an arbitrary location in your program.
3409
3410A typical technique for using stepping is to set a breakpoint
3411(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3412beginning of the function or the section of your program where a problem
3413is believed to lie, run your program until it stops at that breakpoint,
3414and then step through the suspect area, examining the variables that are
3415interesting, until you see the problem happen.
3416
3417@table @code
3418@kindex step
41afff9a 3419@kindex s @r{(@code{step})}
c906108c
SS
3420@item step
3421Continue running your program until control reaches a different source
3422line, then stop it and return control to @value{GDBN}. This command is
3423abbreviated @code{s}.
3424
3425@quotation
3426@c "without debugging information" is imprecise; actually "without line
3427@c numbers in the debugging information". (gcc -g1 has debugging info but
3428@c not line numbers). But it seems complex to try to make that
3429@c distinction here.
3430@emph{Warning:} If you use the @code{step} command while control is
3431within a function that was compiled without debugging information,
3432execution proceeds until control reaches a function that does have
3433debugging information. Likewise, it will not step into a function which
3434is compiled without debugging information. To step through functions
3435without debugging information, use the @code{stepi} command, described
3436below.
3437@end quotation
3438
4a92d011
EZ
3439The @code{step} command only stops at the first instruction of a source
3440line. This prevents the multiple stops that could otherwise occur in
3441@code{switch} statements, @code{for} loops, etc. @code{step} continues
3442to stop if a function that has debugging information is called within
3443the line. In other words, @code{step} @emph{steps inside} any functions
3444called within the line.
c906108c 3445
d4f3574e
SS
3446Also, the @code{step} command only enters a function if there is line
3447number information for the function. Otherwise it acts like the
5d161b24 3448@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3449on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3450was any debugging information about the routine.
c906108c
SS
3451
3452@item step @var{count}
3453Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3454breakpoint is reached, or a signal not related to stepping occurs before
3455@var{count} steps, stepping stops right away.
c906108c
SS
3456
3457@kindex next
41afff9a 3458@kindex n @r{(@code{next})}
c906108c
SS
3459@item next @r{[}@var{count}@r{]}
3460Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3461This is similar to @code{step}, but function calls that appear within
3462the line of code are executed without stopping. Execution stops when
3463control reaches a different line of code at the original stack level
3464that was executing when you gave the @code{next} command. This command
3465is abbreviated @code{n}.
c906108c
SS
3466
3467An argument @var{count} is a repeat count, as for @code{step}.
3468
3469
3470@c FIX ME!! Do we delete this, or is there a way it fits in with
3471@c the following paragraph? --- Vctoria
3472@c
3473@c @code{next} within a function that lacks debugging information acts like
3474@c @code{step}, but any function calls appearing within the code of the
3475@c function are executed without stopping.
3476
d4f3574e
SS
3477The @code{next} command only stops at the first instruction of a
3478source line. This prevents multiple stops that could otherwise occur in
4a92d011 3479@code{switch} statements, @code{for} loops, etc.
c906108c 3480
b90a5f51
CF
3481@kindex set step-mode
3482@item set step-mode
3483@cindex functions without line info, and stepping
3484@cindex stepping into functions with no line info
3485@itemx set step-mode on
4a92d011 3486The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3487stop at the first instruction of a function which contains no debug line
3488information rather than stepping over it.
3489
4a92d011
EZ
3490This is useful in cases where you may be interested in inspecting the
3491machine instructions of a function which has no symbolic info and do not
3492want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3493
3494@item set step-mode off
4a92d011 3495Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3496debug information. This is the default.
3497
c906108c
SS
3498@kindex finish
3499@item finish
3500Continue running until just after function in the selected stack frame
3501returns. Print the returned value (if any).
3502
3503Contrast this with the @code{return} command (@pxref{Returning,
3504,Returning from a function}).
3505
3506@kindex until
41afff9a 3507@kindex u @r{(@code{until})}
c906108c
SS
3508@item until
3509@itemx u
3510Continue running until a source line past the current line, in the
3511current stack frame, is reached. This command is used to avoid single
3512stepping through a loop more than once. It is like the @code{next}
3513command, except that when @code{until} encounters a jump, it
3514automatically continues execution until the program counter is greater
3515than the address of the jump.
3516
3517This means that when you reach the end of a loop after single stepping
3518though it, @code{until} makes your program continue execution until it
3519exits the loop. In contrast, a @code{next} command at the end of a loop
3520simply steps back to the beginning of the loop, which forces you to step
3521through the next iteration.
3522
3523@code{until} always stops your program if it attempts to exit the current
3524stack frame.
3525
3526@code{until} may produce somewhat counterintuitive results if the order
3527of machine code does not match the order of the source lines. For
3528example, in the following excerpt from a debugging session, the @code{f}
3529(@code{frame}) command shows that execution is stopped at line
3530@code{206}; yet when we use @code{until}, we get to line @code{195}:
3531
474c8240 3532@smallexample
c906108c
SS
3533(@value{GDBP}) f
3534#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3535206 expand_input();
3536(@value{GDBP}) until
3537195 for ( ; argc > 0; NEXTARG) @{
474c8240 3538@end smallexample
c906108c
SS
3539
3540This happened because, for execution efficiency, the compiler had
3541generated code for the loop closure test at the end, rather than the
3542start, of the loop---even though the test in a C @code{for}-loop is
3543written before the body of the loop. The @code{until} command appeared
3544to step back to the beginning of the loop when it advanced to this
3545expression; however, it has not really gone to an earlier
3546statement---not in terms of the actual machine code.
3547
3548@code{until} with no argument works by means of single
3549instruction stepping, and hence is slower than @code{until} with an
3550argument.
3551
3552@item until @var{location}
3553@itemx u @var{location}
3554Continue running your program until either the specified location is
3555reached, or the current stack frame returns. @var{location} is any of
3556the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
3557,Setting breakpoints}). This form of the command uses breakpoints, and
3558hence is quicker than @code{until} without an argument. The specified
3559location is actually reached only if it is in the current frame. This
3560implies that @code{until} can be used to skip over recursive function
3561invocations. For instance in the code below, if the current location is
3562line @code{96}, issuing @code{until 99} will execute the program up to
3563line @code{99} in the same invocation of factorial, i.e. after the inner
3564invocations have returned.
3565
3566@smallexample
356794 int factorial (int value)
356895 @{
356996 if (value > 1) @{
357097 value *= factorial (value - 1);
357198 @}
357299 return (value);
3573100 @}
3574@end smallexample
3575
3576
3577@kindex advance @var{location}
3578@itemx advance @var{location}
3579Continue running the program up to the given location. An argument is
3580required, anything of the same form as arguments for the @code{break}
3581command. Execution will also stop upon exit from the current stack
3582frame. This command is similar to @code{until}, but @code{advance} will
3583not skip over recursive function calls, and the target location doesn't
3584have to be in the same frame as the current one.
3585
c906108c
SS
3586
3587@kindex stepi
41afff9a 3588@kindex si @r{(@code{stepi})}
c906108c 3589@item stepi
96a2c332 3590@itemx stepi @var{arg}
c906108c
SS
3591@itemx si
3592Execute one machine instruction, then stop and return to the debugger.
3593
3594It is often useful to do @samp{display/i $pc} when stepping by machine
3595instructions. This makes @value{GDBN} automatically display the next
3596instruction to be executed, each time your program stops. @xref{Auto
3597Display,, Automatic display}.
3598
3599An argument is a repeat count, as in @code{step}.
3600
3601@need 750
3602@kindex nexti
41afff9a 3603@kindex ni @r{(@code{nexti})}
c906108c 3604@item nexti
96a2c332 3605@itemx nexti @var{arg}
c906108c
SS
3606@itemx ni
3607Execute one machine instruction, but if it is a function call,
3608proceed until the function returns.
3609
3610An argument is a repeat count, as in @code{next}.
3611@end table
3612
6d2ebf8b 3613@node Signals
c906108c
SS
3614@section Signals
3615@cindex signals
3616
3617A signal is an asynchronous event that can happen in a program. The
3618operating system defines the possible kinds of signals, and gives each
3619kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3620signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3621@code{SIGSEGV} is the signal a program gets from referencing a place in
3622memory far away from all the areas in use; @code{SIGALRM} occurs when
3623the alarm clock timer goes off (which happens only if your program has
3624requested an alarm).
3625
3626@cindex fatal signals
3627Some signals, including @code{SIGALRM}, are a normal part of the
3628functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3629errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3630program has not specified in advance some other way to handle the signal.
3631@code{SIGINT} does not indicate an error in your program, but it is normally
3632fatal so it can carry out the purpose of the interrupt: to kill the program.
3633
3634@value{GDBN} has the ability to detect any occurrence of a signal in your
3635program. You can tell @value{GDBN} in advance what to do for each kind of
3636signal.
3637
3638@cindex handling signals
24f93129
EZ
3639Normally, @value{GDBN} is set up to let the non-erroneous signals like
3640@code{SIGALRM} be silently passed to your program
3641(so as not to interfere with their role in the program's functioning)
c906108c
SS
3642but to stop your program immediately whenever an error signal happens.
3643You can change these settings with the @code{handle} command.
3644
3645@table @code
3646@kindex info signals
3647@item info signals
96a2c332 3648@itemx info handle
c906108c
SS
3649Print a table of all the kinds of signals and how @value{GDBN} has been told to
3650handle each one. You can use this to see the signal numbers of all
3651the defined types of signals.
3652
d4f3574e 3653@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3654
3655@kindex handle
3656@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3657Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3658can be the number of a signal or its name (with or without the
24f93129 3659@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3660@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3661known signals. The @var{keywords} say what change to make.
c906108c
SS
3662@end table
3663
3664@c @group
3665The keywords allowed by the @code{handle} command can be abbreviated.
3666Their full names are:
3667
3668@table @code
3669@item nostop
3670@value{GDBN} should not stop your program when this signal happens. It may
3671still print a message telling you that the signal has come in.
3672
3673@item stop
3674@value{GDBN} should stop your program when this signal happens. This implies
3675the @code{print} keyword as well.
3676
3677@item print
3678@value{GDBN} should print a message when this signal happens.
3679
3680@item noprint
3681@value{GDBN} should not mention the occurrence of the signal at all. This
3682implies the @code{nostop} keyword as well.
3683
3684@item pass
5ece1a18 3685@itemx noignore
c906108c
SS
3686@value{GDBN} should allow your program to see this signal; your program
3687can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3688and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3689
3690@item nopass
5ece1a18 3691@itemx ignore
c906108c 3692@value{GDBN} should not allow your program to see this signal.
5ece1a18 3693@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3694@end table
3695@c @end group
3696
d4f3574e
SS
3697When a signal stops your program, the signal is not visible to the
3698program until you
c906108c
SS
3699continue. Your program sees the signal then, if @code{pass} is in
3700effect for the signal in question @emph{at that time}. In other words,
3701after @value{GDBN} reports a signal, you can use the @code{handle}
3702command with @code{pass} or @code{nopass} to control whether your
3703program sees that signal when you continue.
3704
24f93129
EZ
3705The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3706non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3707@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3708erroneous signals.
3709
c906108c
SS
3710You can also use the @code{signal} command to prevent your program from
3711seeing a signal, or cause it to see a signal it normally would not see,
3712or to give it any signal at any time. For example, if your program stopped
3713due to some sort of memory reference error, you might store correct
3714values into the erroneous variables and continue, hoping to see more
3715execution; but your program would probably terminate immediately as
3716a result of the fatal signal once it saw the signal. To prevent this,
3717you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3718program a signal}.
c906108c 3719
6d2ebf8b 3720@node Thread Stops
c906108c
SS
3721@section Stopping and starting multi-thread programs
3722
3723When your program has multiple threads (@pxref{Threads,, Debugging
3724programs with multiple threads}), you can choose whether to set
3725breakpoints on all threads, or on a particular thread.
3726
3727@table @code
3728@cindex breakpoints and threads
3729@cindex thread breakpoints
3730@kindex break @dots{} thread @var{threadno}
3731@item break @var{linespec} thread @var{threadno}
3732@itemx break @var{linespec} thread @var{threadno} if @dots{}
3733@var{linespec} specifies source lines; there are several ways of
3734writing them, but the effect is always to specify some source line.
3735
3736Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3737to specify that you only want @value{GDBN} to stop the program when a
3738particular thread reaches this breakpoint. @var{threadno} is one of the
3739numeric thread identifiers assigned by @value{GDBN}, shown in the first
3740column of the @samp{info threads} display.
3741
3742If you do not specify @samp{thread @var{threadno}} when you set a
3743breakpoint, the breakpoint applies to @emph{all} threads of your
3744program.
3745
3746You can use the @code{thread} qualifier on conditional breakpoints as
3747well; in this case, place @samp{thread @var{threadno}} before the
3748breakpoint condition, like this:
3749
3750@smallexample
2df3850c 3751(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3752@end smallexample
3753
3754@end table
3755
3756@cindex stopped threads
3757@cindex threads, stopped
3758Whenever your program stops under @value{GDBN} for any reason,
3759@emph{all} threads of execution stop, not just the current thread. This
3760allows you to examine the overall state of the program, including
3761switching between threads, without worrying that things may change
3762underfoot.
3763
3764@cindex continuing threads
3765@cindex threads, continuing
3766Conversely, whenever you restart the program, @emph{all} threads start
3767executing. @emph{This is true even when single-stepping} with commands
5d161b24 3768like @code{step} or @code{next}.
c906108c
SS
3769
3770In particular, @value{GDBN} cannot single-step all threads in lockstep.
3771Since thread scheduling is up to your debugging target's operating
3772system (not controlled by @value{GDBN}), other threads may
3773execute more than one statement while the current thread completes a
3774single step. Moreover, in general other threads stop in the middle of a
3775statement, rather than at a clean statement boundary, when the program
3776stops.
3777
3778You might even find your program stopped in another thread after
3779continuing or even single-stepping. This happens whenever some other
3780thread runs into a breakpoint, a signal, or an exception before the
3781first thread completes whatever you requested.
3782
3783On some OSes, you can lock the OS scheduler and thus allow only a single
3784thread to run.
3785
3786@table @code
3787@item set scheduler-locking @var{mode}
3788Set the scheduler locking mode. If it is @code{off}, then there is no
3789locking and any thread may run at any time. If @code{on}, then only the
3790current thread may run when the inferior is resumed. The @code{step}
3791mode optimizes for single-stepping. It stops other threads from
3792``seizing the prompt'' by preempting the current thread while you are
3793stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 3794when you step. They are more likely to run when you @samp{next} over a
c906108c 3795function call, and they are completely free to run when you use commands
d4f3574e 3796like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 3797thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 3798@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
3799
3800@item show scheduler-locking
3801Display the current scheduler locking mode.
3802@end table
3803
c906108c 3804
6d2ebf8b 3805@node Stack
c906108c
SS
3806@chapter Examining the Stack
3807
3808When your program has stopped, the first thing you need to know is where it
3809stopped and how it got there.
3810
3811@cindex call stack
5d161b24
DB
3812Each time your program performs a function call, information about the call
3813is generated.
3814That information includes the location of the call in your program,
3815the arguments of the call,
c906108c 3816and the local variables of the function being called.
5d161b24 3817The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
3818The stack frames are allocated in a region of memory called the @dfn{call
3819stack}.
3820
3821When your program stops, the @value{GDBN} commands for examining the
3822stack allow you to see all of this information.
3823
3824@cindex selected frame
3825One of the stack frames is @dfn{selected} by @value{GDBN} and many
3826@value{GDBN} commands refer implicitly to the selected frame. In
3827particular, whenever you ask @value{GDBN} for the value of a variable in
3828your program, the value is found in the selected frame. There are
3829special @value{GDBN} commands to select whichever frame you are
3830interested in. @xref{Selection, ,Selecting a frame}.
3831
3832When your program stops, @value{GDBN} automatically selects the
5d161b24 3833currently executing frame and describes it briefly, similar to the
c906108c
SS
3834@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3835
3836@menu
3837* Frames:: Stack frames
3838* Backtrace:: Backtraces
3839* Selection:: Selecting a frame
3840* Frame Info:: Information on a frame
c906108c
SS
3841
3842@end menu
3843
6d2ebf8b 3844@node Frames
c906108c
SS
3845@section Stack frames
3846
d4f3574e 3847@cindex frame, definition
c906108c
SS
3848@cindex stack frame
3849The call stack is divided up into contiguous pieces called @dfn{stack
3850frames}, or @dfn{frames} for short; each frame is the data associated
3851with one call to one function. The frame contains the arguments given
3852to the function, the function's local variables, and the address at
3853which the function is executing.
3854
3855@cindex initial frame
3856@cindex outermost frame
3857@cindex innermost frame
3858When your program is started, the stack has only one frame, that of the
3859function @code{main}. This is called the @dfn{initial} frame or the
3860@dfn{outermost} frame. Each time a function is called, a new frame is
3861made. Each time a function returns, the frame for that function invocation
3862is eliminated. If a function is recursive, there can be many frames for
3863the same function. The frame for the function in which execution is
3864actually occurring is called the @dfn{innermost} frame. This is the most
3865recently created of all the stack frames that still exist.
3866
3867@cindex frame pointer
3868Inside your program, stack frames are identified by their addresses. A
3869stack frame consists of many bytes, each of which has its own address; each
3870kind of computer has a convention for choosing one byte whose
3871address serves as the address of the frame. Usually this address is kept
3872in a register called the @dfn{frame pointer register} while execution is
3873going on in that frame.
3874
3875@cindex frame number
3876@value{GDBN} assigns numbers to all existing stack frames, starting with
3877zero for the innermost frame, one for the frame that called it,
3878and so on upward. These numbers do not really exist in your program;
3879they are assigned by @value{GDBN} to give you a way of designating stack
3880frames in @value{GDBN} commands.
3881
6d2ebf8b
SS
3882@c The -fomit-frame-pointer below perennially causes hbox overflow
3883@c underflow problems.
c906108c
SS
3884@cindex frameless execution
3885Some compilers provide a way to compile functions so that they operate
6d2ebf8b 3886without stack frames. (For example, the @value{GCC} option
474c8240 3887@smallexample
6d2ebf8b 3888@samp{-fomit-frame-pointer}
474c8240 3889@end smallexample
6d2ebf8b 3890generates functions without a frame.)
c906108c
SS
3891This is occasionally done with heavily used library functions to save
3892the frame setup time. @value{GDBN} has limited facilities for dealing
3893with these function invocations. If the innermost function invocation
3894has no stack frame, @value{GDBN} nevertheless regards it as though
3895it had a separate frame, which is numbered zero as usual, allowing
3896correct tracing of the function call chain. However, @value{GDBN} has
3897no provision for frameless functions elsewhere in the stack.
3898
3899@table @code
d4f3574e 3900@kindex frame@r{, command}
41afff9a 3901@cindex current stack frame
c906108c 3902@item frame @var{args}
5d161b24 3903The @code{frame} command allows you to move from one stack frame to another,
c906108c 3904and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
3905address of the frame or the stack frame number. Without an argument,
3906@code{frame} prints the current stack frame.
c906108c
SS
3907
3908@kindex select-frame
41afff9a 3909@cindex selecting frame silently
c906108c
SS
3910@item select-frame
3911The @code{select-frame} command allows you to move from one stack frame
3912to another without printing the frame. This is the silent version of
3913@code{frame}.
3914@end table
3915
6d2ebf8b 3916@node Backtrace
c906108c
SS
3917@section Backtraces
3918
3919@cindex backtraces
3920@cindex tracebacks
3921@cindex stack traces
3922A backtrace is a summary of how your program got where it is. It shows one
3923line per frame, for many frames, starting with the currently executing
3924frame (frame zero), followed by its caller (frame one), and on up the
3925stack.
3926
3927@table @code
3928@kindex backtrace
41afff9a 3929@kindex bt @r{(@code{backtrace})}
c906108c
SS
3930@item backtrace
3931@itemx bt
3932Print a backtrace of the entire stack: one line per frame for all
3933frames in the stack.
3934
3935You can stop the backtrace at any time by typing the system interrupt
3936character, normally @kbd{C-c}.
3937
3938@item backtrace @var{n}
3939@itemx bt @var{n}
3940Similar, but print only the innermost @var{n} frames.
3941
3942@item backtrace -@var{n}
3943@itemx bt -@var{n}
3944Similar, but print only the outermost @var{n} frames.
3945@end table
3946
3947@kindex where
3948@kindex info stack
41afff9a 3949@kindex info s @r{(@code{info stack})}
c906108c
SS
3950The names @code{where} and @code{info stack} (abbreviated @code{info s})
3951are additional aliases for @code{backtrace}.
3952
3953Each line in the backtrace shows the frame number and the function name.
3954The program counter value is also shown---unless you use @code{set
3955print address off}. The backtrace also shows the source file name and
3956line number, as well as the arguments to the function. The program
3957counter value is omitted if it is at the beginning of the code for that
3958line number.
3959
3960Here is an example of a backtrace. It was made with the command
3961@samp{bt 3}, so it shows the innermost three frames.
3962
3963@smallexample
3964@group
5d161b24 3965#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
3966 at builtin.c:993
3967#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3968#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3969 at macro.c:71
3970(More stack frames follow...)
3971@end group
3972@end smallexample
3973
3974@noindent
3975The display for frame zero does not begin with a program counter
3976value, indicating that your program has stopped at the beginning of the
3977code for line @code{993} of @code{builtin.c}.
3978
25d29d70
AC
3979@kindex set backtrace past-main
3980@kindex show backtrace past-main
3981@kindex set backtrace limit
3982@kindex show backtrace limit
b4e9345d 3983
25d29d70
AC
3984Most programs have a standard user entry point---a place where system
3985libraries and startup code transition into user code. For C this is
3986@code{main}. When @value{GDBN} finds the entry function in a backtrace
3987it will terminate the backtrace, to avoid tracing into highly
3988system-specific (and generally uninteresting) code.
3989
3990If you need to examine the startup code, or limit the number of levels
3991in a backtrace, you can change this behavior:
95f90d25
DJ
3992
3993@table @code
25d29d70
AC
3994@item set backtrace past-main
3995@itemx set backtrace past-main on
3996Backtraces will continue past the user entry point.
3997
3998@item set backtrace past-main off
95f90d25
DJ
3999Backtraces will stop when they encounter the user entry point. This is the
4000default.
4001
25d29d70
AC
4002@item show backtrace past-main
4003Display the current user entry point backtrace policy.
4004
4005@item set backtrace limit @var{n}
4006@itemx set backtrace limit 0
4007@cindex backtrace limit
4008Limit the backtrace to @var{n} levels. A value of zero means
4009unlimited.
95f90d25 4010
25d29d70
AC
4011@item show backtrace limit
4012Display the current limit on backtrace levels.
95f90d25
DJ
4013@end table
4014
6d2ebf8b 4015@node Selection
c906108c
SS
4016@section Selecting a frame
4017
4018Most commands for examining the stack and other data in your program work on
4019whichever stack frame is selected at the moment. Here are the commands for
4020selecting a stack frame; all of them finish by printing a brief description
4021of the stack frame just selected.
4022
4023@table @code
d4f3574e 4024@kindex frame@r{, selecting}
41afff9a 4025@kindex f @r{(@code{frame})}
c906108c
SS
4026@item frame @var{n}
4027@itemx f @var{n}
4028Select frame number @var{n}. Recall that frame zero is the innermost
4029(currently executing) frame, frame one is the frame that called the
4030innermost one, and so on. The highest-numbered frame is the one for
4031@code{main}.
4032
4033@item frame @var{addr}
4034@itemx f @var{addr}
4035Select the frame at address @var{addr}. This is useful mainly if the
4036chaining of stack frames has been damaged by a bug, making it
4037impossible for @value{GDBN} to assign numbers properly to all frames. In
4038addition, this can be useful when your program has multiple stacks and
4039switches between them.
4040
c906108c
SS
4041On the SPARC architecture, @code{frame} needs two addresses to
4042select an arbitrary frame: a frame pointer and a stack pointer.
4043
4044On the MIPS and Alpha architecture, it needs two addresses: a stack
4045pointer and a program counter.
4046
4047On the 29k architecture, it needs three addresses: a register stack
4048pointer, a program counter, and a memory stack pointer.
4049@c note to future updaters: this is conditioned on a flag
4050@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
4051@c as of 27 Jan 1994.
c906108c
SS
4052
4053@kindex up
4054@item up @var{n}
4055Move @var{n} frames up the stack. For positive numbers @var{n}, this
4056advances toward the outermost frame, to higher frame numbers, to frames
4057that have existed longer. @var{n} defaults to one.
4058
4059@kindex down
41afff9a 4060@kindex do @r{(@code{down})}
c906108c
SS
4061@item down @var{n}
4062Move @var{n} frames down the stack. For positive numbers @var{n}, this
4063advances toward the innermost frame, to lower frame numbers, to frames
4064that were created more recently. @var{n} defaults to one. You may
4065abbreviate @code{down} as @code{do}.
4066@end table
4067
4068All of these commands end by printing two lines of output describing the
4069frame. The first line shows the frame number, the function name, the
4070arguments, and the source file and line number of execution in that
5d161b24 4071frame. The second line shows the text of that source line.
c906108c
SS
4072
4073@need 1000
4074For example:
4075
4076@smallexample
4077@group
4078(@value{GDBP}) up
4079#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4080 at env.c:10
408110 read_input_file (argv[i]);
4082@end group
4083@end smallexample
4084
4085After such a printout, the @code{list} command with no arguments
4086prints ten lines centered on the point of execution in the frame.
87885426
FN
4087You can also edit the program at the point of execution with your favorite
4088editing program by typing @code{edit}.
4089@xref{List, ,Printing source lines},
4090for details.
c906108c
SS
4091
4092@table @code
4093@kindex down-silently
4094@kindex up-silently
4095@item up-silently @var{n}
4096@itemx down-silently @var{n}
4097These two commands are variants of @code{up} and @code{down},
4098respectively; they differ in that they do their work silently, without
4099causing display of the new frame. They are intended primarily for use
4100in @value{GDBN} command scripts, where the output might be unnecessary and
4101distracting.
4102@end table
4103
6d2ebf8b 4104@node Frame Info
c906108c
SS
4105@section Information about a frame
4106
4107There are several other commands to print information about the selected
4108stack frame.
4109
4110@table @code
4111@item frame
4112@itemx f
4113When used without any argument, this command does not change which
4114frame is selected, but prints a brief description of the currently
4115selected stack frame. It can be abbreviated @code{f}. With an
4116argument, this command is used to select a stack frame.
4117@xref{Selection, ,Selecting a frame}.
4118
4119@kindex info frame
41afff9a 4120@kindex info f @r{(@code{info frame})}
c906108c
SS
4121@item info frame
4122@itemx info f
4123This command prints a verbose description of the selected stack frame,
4124including:
4125
4126@itemize @bullet
5d161b24
DB
4127@item
4128the address of the frame
c906108c
SS
4129@item
4130the address of the next frame down (called by this frame)
4131@item
4132the address of the next frame up (caller of this frame)
4133@item
4134the language in which the source code corresponding to this frame is written
4135@item
4136the address of the frame's arguments
4137@item
d4f3574e
SS
4138the address of the frame's local variables
4139@item
c906108c
SS
4140the program counter saved in it (the address of execution in the caller frame)
4141@item
4142which registers were saved in the frame
4143@end itemize
4144
4145@noindent The verbose description is useful when
4146something has gone wrong that has made the stack format fail to fit
4147the usual conventions.
4148
4149@item info frame @var{addr}
4150@itemx info f @var{addr}
4151Print a verbose description of the frame at address @var{addr}, without
4152selecting that frame. The selected frame remains unchanged by this
4153command. This requires the same kind of address (more than one for some
4154architectures) that you specify in the @code{frame} command.
4155@xref{Selection, ,Selecting a frame}.
4156
4157@kindex info args
4158@item info args
4159Print the arguments of the selected frame, each on a separate line.
4160
4161@item info locals
4162@kindex info locals
4163Print the local variables of the selected frame, each on a separate
4164line. These are all variables (declared either static or automatic)
4165accessible at the point of execution of the selected frame.
4166
c906108c 4167@kindex info catch
d4f3574e
SS
4168@cindex catch exceptions, list active handlers
4169@cindex exception handlers, how to list
c906108c
SS
4170@item info catch
4171Print a list of all the exception handlers that are active in the
4172current stack frame at the current point of execution. To see other
4173exception handlers, visit the associated frame (using the @code{up},
4174@code{down}, or @code{frame} commands); then type @code{info catch}.
4175@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4176
c906108c
SS
4177@end table
4178
c906108c 4179
6d2ebf8b 4180@node Source
c906108c
SS
4181@chapter Examining Source Files
4182
4183@value{GDBN} can print parts of your program's source, since the debugging
4184information recorded in the program tells @value{GDBN} what source files were
4185used to build it. When your program stops, @value{GDBN} spontaneously prints
4186the line where it stopped. Likewise, when you select a stack frame
4187(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4188execution in that frame has stopped. You can print other portions of
4189source files by explicit command.
4190
7a292a7a 4191If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4192prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4193@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4194
4195@menu
4196* List:: Printing source lines
87885426 4197* Edit:: Editing source files
c906108c 4198* Search:: Searching source files
c906108c
SS
4199* Source Path:: Specifying source directories
4200* Machine Code:: Source and machine code
4201@end menu
4202
6d2ebf8b 4203@node List
c906108c
SS
4204@section Printing source lines
4205
4206@kindex list
41afff9a 4207@kindex l @r{(@code{list})}
c906108c 4208To print lines from a source file, use the @code{list} command
5d161b24 4209(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4210There are several ways to specify what part of the file you want to print.
4211
4212Here are the forms of the @code{list} command most commonly used:
4213
4214@table @code
4215@item list @var{linenum}
4216Print lines centered around line number @var{linenum} in the
4217current source file.
4218
4219@item list @var{function}
4220Print lines centered around the beginning of function
4221@var{function}.
4222
4223@item list
4224Print more lines. If the last lines printed were printed with a
4225@code{list} command, this prints lines following the last lines
4226printed; however, if the last line printed was a solitary line printed
4227as part of displaying a stack frame (@pxref{Stack, ,Examining the
4228Stack}), this prints lines centered around that line.
4229
4230@item list -
4231Print lines just before the lines last printed.
4232@end table
4233
4234By default, @value{GDBN} prints ten source lines with any of these forms of
4235the @code{list} command. You can change this using @code{set listsize}:
4236
4237@table @code
4238@kindex set listsize
4239@item set listsize @var{count}
4240Make the @code{list} command display @var{count} source lines (unless
4241the @code{list} argument explicitly specifies some other number).
4242
4243@kindex show listsize
4244@item show listsize
4245Display the number of lines that @code{list} prints.
4246@end table
4247
4248Repeating a @code{list} command with @key{RET} discards the argument,
4249so it is equivalent to typing just @code{list}. This is more useful
4250than listing the same lines again. An exception is made for an
4251argument of @samp{-}; that argument is preserved in repetition so that
4252each repetition moves up in the source file.
4253
4254@cindex linespec
4255In general, the @code{list} command expects you to supply zero, one or two
4256@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4257of writing them, but the effect is always to specify some source line.
c906108c
SS
4258Here is a complete description of the possible arguments for @code{list}:
4259
4260@table @code
4261@item list @var{linespec}
4262Print lines centered around the line specified by @var{linespec}.
4263
4264@item list @var{first},@var{last}
4265Print lines from @var{first} to @var{last}. Both arguments are
4266linespecs.
4267
4268@item list ,@var{last}
4269Print lines ending with @var{last}.
4270
4271@item list @var{first},
4272Print lines starting with @var{first}.
4273
4274@item list +
4275Print lines just after the lines last printed.
4276
4277@item list -
4278Print lines just before the lines last printed.
4279
4280@item list
4281As described in the preceding table.
4282@end table
4283
4284Here are the ways of specifying a single source line---all the
4285kinds of linespec.
4286
4287@table @code
4288@item @var{number}
4289Specifies line @var{number} of the current source file.
4290When a @code{list} command has two linespecs, this refers to
4291the same source file as the first linespec.
4292
4293@item +@var{offset}
4294Specifies the line @var{offset} lines after the last line printed.
4295When used as the second linespec in a @code{list} command that has
4296two, this specifies the line @var{offset} lines down from the
4297first linespec.
4298
4299@item -@var{offset}
4300Specifies the line @var{offset} lines before the last line printed.
4301
4302@item @var{filename}:@var{number}
4303Specifies line @var{number} in the source file @var{filename}.
4304
4305@item @var{function}
4306Specifies the line that begins the body of the function @var{function}.
4307For example: in C, this is the line with the open brace.
4308
4309@item @var{filename}:@var{function}
4310Specifies the line of the open-brace that begins the body of the
4311function @var{function} in the file @var{filename}. You only need the
4312file name with a function name to avoid ambiguity when there are
4313identically named functions in different source files.
4314
4315@item *@var{address}
4316Specifies the line containing the program address @var{address}.
4317@var{address} may be any expression.
4318@end table
4319
87885426
FN
4320@node Edit
4321@section Editing source files
4322@cindex editing source files
4323
4324@kindex edit
4325@kindex e @r{(@code{edit})}
4326To edit the lines in a source file, use the @code{edit} command.
4327The editing program of your choice
4328is invoked with the current line set to
4329the active line in the program.
4330Alternatively, there are several ways to specify what part of the file you
4331want to print if you want to see other parts of the program.
4332
4333Here are the forms of the @code{edit} command most commonly used:
4334
4335@table @code
4336@item edit
4337Edit the current source file at the active line number in the program.
4338
4339@item edit @var{number}
4340Edit the current source file with @var{number} as the active line number.
4341
4342@item edit @var{function}
4343Edit the file containing @var{function} at the beginning of its definition.
4344
4345@item edit @var{filename}:@var{number}
4346Specifies line @var{number} in the source file @var{filename}.
4347
4348@item edit @var{filename}:@var{function}
4349Specifies the line that begins the body of the
4350function @var{function} in the file @var{filename}. You only need the
4351file name with a function name to avoid ambiguity when there are
4352identically named functions in different source files.
4353
4354@item edit *@var{address}
4355Specifies the line containing the program address @var{address}.
4356@var{address} may be any expression.
4357@end table
4358
4359@subsection Choosing your editor
4360You can customize @value{GDBN} to use any editor you want
4361@footnote{
4362The only restriction is that your editor (say @code{ex}), recognizes the
4363following command-line syntax:
10998722 4364@smallexample
87885426 4365ex +@var{number} file
10998722
AC
4366@end smallexample
4367The optional numeric value +@var{number} designates the active line in
4368the file.}. By default, it is @value{EDITOR}, but you can change this
4369by setting the environment variable @code{EDITOR} before using
4370@value{GDBN}. For example, to configure @value{GDBN} to use the
4371@code{vi} editor, you could use these commands with the @code{sh} shell:
4372@smallexample
87885426
FN
4373EDITOR=/usr/bin/vi
4374export EDITOR
4375gdb ...
10998722 4376@end smallexample
87885426 4377or in the @code{csh} shell,
10998722 4378@smallexample
87885426
FN
4379setenv EDITOR /usr/bin/vi
4380gdb ...
10998722 4381@end smallexample
87885426 4382
6d2ebf8b 4383@node Search
c906108c
SS
4384@section Searching source files
4385@cindex searching
4386@kindex reverse-search
4387
4388There are two commands for searching through the current source file for a
4389regular expression.
4390
4391@table @code
4392@kindex search
4393@kindex forward-search
4394@item forward-search @var{regexp}
4395@itemx search @var{regexp}
4396The command @samp{forward-search @var{regexp}} checks each line,
4397starting with the one following the last line listed, for a match for
5d161b24 4398@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4399synonym @samp{search @var{regexp}} or abbreviate the command name as
4400@code{fo}.
4401
4402@item reverse-search @var{regexp}
4403The command @samp{reverse-search @var{regexp}} checks each line, starting
4404with the one before the last line listed and going backward, for a match
4405for @var{regexp}. It lists the line that is found. You can abbreviate
4406this command as @code{rev}.
4407@end table
c906108c 4408
6d2ebf8b 4409@node Source Path
c906108c
SS
4410@section Specifying source directories
4411
4412@cindex source path
4413@cindex directories for source files
4414Executable programs sometimes do not record the directories of the source
4415files from which they were compiled, just the names. Even when they do,
4416the directories could be moved between the compilation and your debugging
4417session. @value{GDBN} has a list of directories to search for source files;
4418this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4419it tries all the directories in the list, in the order they are present
4420in the list, until it finds a file with the desired name. Note that
4421the executable search path is @emph{not} used for this purpose. Neither is
4422the current working directory, unless it happens to be in the source
4423path.
4424
4425If @value{GDBN} cannot find a source file in the source path, and the
4426object program records a directory, @value{GDBN} tries that directory
4427too. If the source path is empty, and there is no record of the
4428compilation directory, @value{GDBN} looks in the current directory as a
4429last resort.
4430
4431Whenever you reset or rearrange the source path, @value{GDBN} clears out
4432any information it has cached about where source files are found and where
4433each line is in the file.
4434
4435@kindex directory
4436@kindex dir
d4f3574e
SS
4437When you start @value{GDBN}, its source path includes only @samp{cdir}
4438and @samp{cwd}, in that order.
c906108c
SS
4439To add other directories, use the @code{directory} command.
4440
4441@table @code
4442@item directory @var{dirname} @dots{}
4443@item dir @var{dirname} @dots{}
4444Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4445directory names may be given to this command, separated by @samp{:}
4446(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4447part of absolute file names) or
c906108c
SS
4448whitespace. You may specify a directory that is already in the source
4449path; this moves it forward, so @value{GDBN} searches it sooner.
4450
4451@kindex cdir
4452@kindex cwd
41afff9a
EZ
4453@vindex $cdir@r{, convenience variable}
4454@vindex $cwdr@r{, convenience variable}
c906108c
SS
4455@cindex compilation directory
4456@cindex current directory
4457@cindex working directory
4458@cindex directory, current
4459@cindex directory, compilation
4460You can use the string @samp{$cdir} to refer to the compilation
4461directory (if one is recorded), and @samp{$cwd} to refer to the current
4462working directory. @samp{$cwd} is not the same as @samp{.}---the former
4463tracks the current working directory as it changes during your @value{GDBN}
4464session, while the latter is immediately expanded to the current
4465directory at the time you add an entry to the source path.
4466
4467@item directory
4468Reset the source path to empty again. This requires confirmation.
4469
4470@c RET-repeat for @code{directory} is explicitly disabled, but since
4471@c repeating it would be a no-op we do not say that. (thanks to RMS)
4472
4473@item show directories
4474@kindex show directories
4475Print the source path: show which directories it contains.
4476@end table
4477
4478If your source path is cluttered with directories that are no longer of
4479interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4480versions of source. You can correct the situation as follows:
4481
4482@enumerate
4483@item
4484Use @code{directory} with no argument to reset the source path to empty.
4485
4486@item
4487Use @code{directory} with suitable arguments to reinstall the
4488directories you want in the source path. You can add all the
4489directories in one command.
4490@end enumerate
4491
6d2ebf8b 4492@node Machine Code
c906108c
SS
4493@section Source and machine code
4494
4495You can use the command @code{info line} to map source lines to program
4496addresses (and vice versa), and the command @code{disassemble} to display
4497a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4498mode, the @code{info line} command causes the arrow to point to the
5d161b24 4499line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4500well as hex.
4501
4502@table @code
4503@kindex info line
4504@item info line @var{linespec}
4505Print the starting and ending addresses of the compiled code for
4506source line @var{linespec}. You can specify source lines in any of
4507the ways understood by the @code{list} command (@pxref{List, ,Printing
4508source lines}).
4509@end table
4510
4511For example, we can use @code{info line} to discover the location of
4512the object code for the first line of function
4513@code{m4_changequote}:
4514
d4f3574e
SS
4515@c FIXME: I think this example should also show the addresses in
4516@c symbolic form, as they usually would be displayed.
c906108c 4517@smallexample
96a2c332 4518(@value{GDBP}) info line m4_changequote
c906108c
SS
4519Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4520@end smallexample
4521
4522@noindent
4523We can also inquire (using @code{*@var{addr}} as the form for
4524@var{linespec}) what source line covers a particular address:
4525@smallexample
4526(@value{GDBP}) info line *0x63ff
4527Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4528@end smallexample
4529
4530@cindex @code{$_} and @code{info line}
41afff9a 4531@kindex x@r{(examine), and} info line
c906108c
SS
4532After @code{info line}, the default address for the @code{x} command
4533is changed to the starting address of the line, so that @samp{x/i} is
4534sufficient to begin examining the machine code (@pxref{Memory,
4535,Examining memory}). Also, this address is saved as the value of the
4536convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4537variables}).
4538
4539@table @code
4540@kindex disassemble
4541@cindex assembly instructions
4542@cindex instructions, assembly
4543@cindex machine instructions
4544@cindex listing machine instructions
4545@item disassemble
4546This specialized command dumps a range of memory as machine
4547instructions. The default memory range is the function surrounding the
4548program counter of the selected frame. A single argument to this
4549command is a program counter value; @value{GDBN} dumps the function
4550surrounding this value. Two arguments specify a range of addresses
4551(first inclusive, second exclusive) to dump.
4552@end table
4553
c906108c
SS
4554The following example shows the disassembly of a range of addresses of
4555HP PA-RISC 2.0 code:
4556
4557@smallexample
4558(@value{GDBP}) disas 0x32c4 0x32e4
4559Dump of assembler code from 0x32c4 to 0x32e4:
45600x32c4 <main+204>: addil 0,dp
45610x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
45620x32cc <main+212>: ldil 0x3000,r31
45630x32d0 <main+216>: ble 0x3f8(sr4,r31)
45640x32d4 <main+220>: ldo 0(r31),rp
45650x32d8 <main+224>: addil -0x800,dp
45660x32dc <main+228>: ldo 0x588(r1),r26
45670x32e0 <main+232>: ldil 0x3000,r31
4568End of assembler dump.
4569@end smallexample
c906108c
SS
4570
4571Some architectures have more than one commonly-used set of instruction
4572mnemonics or other syntax.
4573
4574@table @code
d4f3574e 4575@kindex set disassembly-flavor
c906108c
SS
4576@cindex assembly instructions
4577@cindex instructions, assembly
4578@cindex machine instructions
4579@cindex listing machine instructions
d4f3574e
SS
4580@cindex Intel disassembly flavor
4581@cindex AT&T disassembly flavor
4582@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4583Select the instruction set to use when disassembling the
4584program via the @code{disassemble} or @code{x/i} commands.
4585
4586Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4587can set @var{instruction-set} to either @code{intel} or @code{att}.
4588The default is @code{att}, the AT&T flavor used by default by Unix
4589assemblers for x86-based targets.
c906108c
SS
4590@end table
4591
4592
6d2ebf8b 4593@node Data
c906108c
SS
4594@chapter Examining Data
4595
4596@cindex printing data
4597@cindex examining data
4598@kindex print
4599@kindex inspect
4600@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4601@c document because it is nonstandard... Under Epoch it displays in a
4602@c different window or something like that.
4603The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4604command (abbreviated @code{p}), or its synonym @code{inspect}. It
4605evaluates and prints the value of an expression of the language your
4606program is written in (@pxref{Languages, ,Using @value{GDBN} with
4607Different Languages}).
c906108c
SS
4608
4609@table @code
d4f3574e
SS
4610@item print @var{expr}
4611@itemx print /@var{f} @var{expr}
4612@var{expr} is an expression (in the source language). By default the
4613value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4614you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4615@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4616formats}.
4617
4618@item print
4619@itemx print /@var{f}
d4f3574e 4620If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4621@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4622conveniently inspect the same value in an alternative format.
4623@end table
4624
4625A more low-level way of examining data is with the @code{x} command.
4626It examines data in memory at a specified address and prints it in a
4627specified format. @xref{Memory, ,Examining memory}.
4628
7a292a7a 4629If you are interested in information about types, or about how the
d4f3574e
SS
4630fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4631command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4632Table}.
c906108c
SS
4633
4634@menu
4635* Expressions:: Expressions
4636* Variables:: Program variables
4637* Arrays:: Artificial arrays
4638* Output Formats:: Output formats
4639* Memory:: Examining memory
4640* Auto Display:: Automatic display
4641* Print Settings:: Print settings
4642* Value History:: Value history
4643* Convenience Vars:: Convenience variables
4644* Registers:: Registers
c906108c 4645* Floating Point Hardware:: Floating point hardware
53c69bd7 4646* Vector Unit:: Vector Unit
29e57380 4647* Memory Region Attributes:: Memory region attributes
16d9dec6 4648* Dump/Restore Files:: Copy between memory and a file
a0eb71c5
KB
4649* Character Sets:: Debugging programs that use a different
4650 character set than GDB does
c906108c
SS
4651@end menu
4652
6d2ebf8b 4653@node Expressions
c906108c
SS
4654@section Expressions
4655
4656@cindex expressions
4657@code{print} and many other @value{GDBN} commands accept an expression and
4658compute its value. Any kind of constant, variable or operator defined
4659by the programming language you are using is valid in an expression in
e2e0bcd1
JB
4660@value{GDBN}. This includes conditional expressions, function calls,
4661casts, and string constants. It also includes preprocessor macros, if
4662you compiled your program to include this information; see
4663@ref{Compilation}.
c906108c 4664
d4f3574e
SS
4665@value{GDBN} supports array constants in expressions input by
4666the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 4667you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 4668memory that is @code{malloc}ed in the target program.
c906108c 4669
c906108c
SS
4670Because C is so widespread, most of the expressions shown in examples in
4671this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4672Languages}, for information on how to use expressions in other
4673languages.
4674
4675In this section, we discuss operators that you can use in @value{GDBN}
4676expressions regardless of your programming language.
4677
4678Casts are supported in all languages, not just in C, because it is so
4679useful to cast a number into a pointer in order to examine a structure
4680at that address in memory.
4681@c FIXME: casts supported---Mod2 true?
c906108c
SS
4682
4683@value{GDBN} supports these operators, in addition to those common
4684to programming languages:
4685
4686@table @code
4687@item @@
4688@samp{@@} is a binary operator for treating parts of memory as arrays.
4689@xref{Arrays, ,Artificial arrays}, for more information.
4690
4691@item ::
4692@samp{::} allows you to specify a variable in terms of the file or
4693function where it is defined. @xref{Variables, ,Program variables}.
4694
4695@cindex @{@var{type}@}
4696@cindex type casting memory
4697@cindex memory, viewing as typed object
4698@cindex casts, to view memory
4699@item @{@var{type}@} @var{addr}
4700Refers to an object of type @var{type} stored at address @var{addr} in
4701memory. @var{addr} may be any expression whose value is an integer or
4702pointer (but parentheses are required around binary operators, just as in
4703a cast). This construct is allowed regardless of what kind of data is
4704normally supposed to reside at @var{addr}.
4705@end table
4706
6d2ebf8b 4707@node Variables
c906108c
SS
4708@section Program variables
4709
4710The most common kind of expression to use is the name of a variable
4711in your program.
4712
4713Variables in expressions are understood in the selected stack frame
4714(@pxref{Selection, ,Selecting a frame}); they must be either:
4715
4716@itemize @bullet
4717@item
4718global (or file-static)
4719@end itemize
4720
5d161b24 4721@noindent or
c906108c
SS
4722
4723@itemize @bullet
4724@item
4725visible according to the scope rules of the
4726programming language from the point of execution in that frame
5d161b24 4727@end itemize
c906108c
SS
4728
4729@noindent This means that in the function
4730
474c8240 4731@smallexample
c906108c
SS
4732foo (a)
4733 int a;
4734@{
4735 bar (a);
4736 @{
4737 int b = test ();
4738 bar (b);
4739 @}
4740@}
474c8240 4741@end smallexample
c906108c
SS
4742
4743@noindent
4744you can examine and use the variable @code{a} whenever your program is
4745executing within the function @code{foo}, but you can only use or
4746examine the variable @code{b} while your program is executing inside
4747the block where @code{b} is declared.
4748
4749@cindex variable name conflict
4750There is an exception: you can refer to a variable or function whose
4751scope is a single source file even if the current execution point is not
4752in this file. But it is possible to have more than one such variable or
4753function with the same name (in different source files). If that
4754happens, referring to that name has unpredictable effects. If you wish,
4755you can specify a static variable in a particular function or file,
4756using the colon-colon notation:
4757
d4f3574e 4758@cindex colon-colon, context for variables/functions
c906108c
SS
4759@iftex
4760@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 4761@cindex @code{::}, context for variables/functions
c906108c 4762@end iftex
474c8240 4763@smallexample
c906108c
SS
4764@var{file}::@var{variable}
4765@var{function}::@var{variable}
474c8240 4766@end smallexample
c906108c
SS
4767
4768@noindent
4769Here @var{file} or @var{function} is the name of the context for the
4770static @var{variable}. In the case of file names, you can use quotes to
4771make sure @value{GDBN} parses the file name as a single word---for example,
4772to print a global value of @code{x} defined in @file{f2.c}:
4773
474c8240 4774@smallexample
c906108c 4775(@value{GDBP}) p 'f2.c'::x
474c8240 4776@end smallexample
c906108c 4777
b37052ae 4778@cindex C@t{++} scope resolution
c906108c 4779This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 4780use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
4781scope resolution operator in @value{GDBN} expressions.
4782@c FIXME: Um, so what happens in one of those rare cases where it's in
4783@c conflict?? --mew
c906108c
SS
4784
4785@cindex wrong values
4786@cindex variable values, wrong
4787@quotation
4788@emph{Warning:} Occasionally, a local variable may appear to have the
4789wrong value at certain points in a function---just after entry to a new
4790scope, and just before exit.
4791@end quotation
4792You may see this problem when you are stepping by machine instructions.
4793This is because, on most machines, it takes more than one instruction to
4794set up a stack frame (including local variable definitions); if you are
4795stepping by machine instructions, variables may appear to have the wrong
4796values until the stack frame is completely built. On exit, it usually
4797also takes more than one machine instruction to destroy a stack frame;
4798after you begin stepping through that group of instructions, local
4799variable definitions may be gone.
4800
4801This may also happen when the compiler does significant optimizations.
4802To be sure of always seeing accurate values, turn off all optimization
4803when compiling.
4804
d4f3574e
SS
4805@cindex ``No symbol "foo" in current context''
4806Another possible effect of compiler optimizations is to optimize
4807unused variables out of existence, or assign variables to registers (as
4808opposed to memory addresses). Depending on the support for such cases
4809offered by the debug info format used by the compiler, @value{GDBN}
4810might not be able to display values for such local variables. If that
4811happens, @value{GDBN} will print a message like this:
4812
474c8240 4813@smallexample
d4f3574e 4814No symbol "foo" in current context.
474c8240 4815@end smallexample
d4f3574e
SS
4816
4817To solve such problems, either recompile without optimizations, or use a
4818different debug info format, if the compiler supports several such
0179ffac
DC
4819formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler
4820usually supports the @option{-gstabs+} option. @option{-gstabs+}
4821produces debug info in a format that is superior to formats such as
4822COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
4823an effective form for debug info. @xref{Debugging Options,,Options
4824for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
d4f3574e
SS
4825
4826
6d2ebf8b 4827@node Arrays
c906108c
SS
4828@section Artificial arrays
4829
4830@cindex artificial array
41afff9a 4831@kindex @@@r{, referencing memory as an array}
c906108c
SS
4832It is often useful to print out several successive objects of the
4833same type in memory; a section of an array, or an array of
4834dynamically determined size for which only a pointer exists in the
4835program.
4836
4837You can do this by referring to a contiguous span of memory as an
4838@dfn{artificial array}, using the binary operator @samp{@@}. The left
4839operand of @samp{@@} should be the first element of the desired array
4840and be an individual object. The right operand should be the desired length
4841of the array. The result is an array value whose elements are all of
4842the type of the left argument. The first element is actually the left
4843argument; the second element comes from bytes of memory immediately
4844following those that hold the first element, and so on. Here is an
4845example. If a program says
4846
474c8240 4847@smallexample
c906108c 4848int *array = (int *) malloc (len * sizeof (int));
474c8240 4849@end smallexample
c906108c
SS
4850
4851@noindent
4852you can print the contents of @code{array} with
4853
474c8240 4854@smallexample
c906108c 4855p *array@@len
474c8240 4856@end smallexample
c906108c
SS
4857
4858The left operand of @samp{@@} must reside in memory. Array values made
4859with @samp{@@} in this way behave just like other arrays in terms of
4860subscripting, and are coerced to pointers when used in expressions.
4861Artificial arrays most often appear in expressions via the value history
4862(@pxref{Value History, ,Value history}), after printing one out.
4863
4864Another way to create an artificial array is to use a cast.
4865This re-interprets a value as if it were an array.
4866The value need not be in memory:
474c8240 4867@smallexample
c906108c
SS
4868(@value{GDBP}) p/x (short[2])0x12345678
4869$1 = @{0x1234, 0x5678@}
474c8240 4870@end smallexample
c906108c
SS
4871
4872As a convenience, if you leave the array length out (as in
c3f6f71d 4873@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 4874the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 4875@smallexample
c906108c
SS
4876(@value{GDBP}) p/x (short[])0x12345678
4877$2 = @{0x1234, 0x5678@}
474c8240 4878@end smallexample
c906108c
SS
4879
4880Sometimes the artificial array mechanism is not quite enough; in
4881moderately complex data structures, the elements of interest may not
4882actually be adjacent---for example, if you are interested in the values
4883of pointers in an array. One useful work-around in this situation is
4884to use a convenience variable (@pxref{Convenience Vars, ,Convenience
4885variables}) as a counter in an expression that prints the first
4886interesting value, and then repeat that expression via @key{RET}. For
4887instance, suppose you have an array @code{dtab} of pointers to
4888structures, and you are interested in the values of a field @code{fv}
4889in each structure. Here is an example of what you might type:
4890
474c8240 4891@smallexample
c906108c
SS
4892set $i = 0
4893p dtab[$i++]->fv
4894@key{RET}
4895@key{RET}
4896@dots{}
474c8240 4897@end smallexample
c906108c 4898
6d2ebf8b 4899@node Output Formats
c906108c
SS
4900@section Output formats
4901
4902@cindex formatted output
4903@cindex output formats
4904By default, @value{GDBN} prints a value according to its data type. Sometimes
4905this is not what you want. For example, you might want to print a number
4906in hex, or a pointer in decimal. Or you might want to view data in memory
4907at a certain address as a character string or as an instruction. To do
4908these things, specify an @dfn{output format} when you print a value.
4909
4910The simplest use of output formats is to say how to print a value
4911already computed. This is done by starting the arguments of the
4912@code{print} command with a slash and a format letter. The format
4913letters supported are:
4914
4915@table @code
4916@item x
4917Regard the bits of the value as an integer, and print the integer in
4918hexadecimal.
4919
4920@item d
4921Print as integer in signed decimal.
4922
4923@item u
4924Print as integer in unsigned decimal.
4925
4926@item o
4927Print as integer in octal.
4928
4929@item t
4930Print as integer in binary. The letter @samp{t} stands for ``two''.
4931@footnote{@samp{b} cannot be used because these format letters are also
4932used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 4933see @ref{Memory,,Examining memory}.}
c906108c
SS
4934
4935@item a
4936@cindex unknown address, locating
3d67e040 4937@cindex locate address
c906108c
SS
4938Print as an address, both absolute in hexadecimal and as an offset from
4939the nearest preceding symbol. You can use this format used to discover
4940where (in what function) an unknown address is located:
4941
474c8240 4942@smallexample
c906108c
SS
4943(@value{GDBP}) p/a 0x54320
4944$3 = 0x54320 <_initialize_vx+396>
474c8240 4945@end smallexample
c906108c 4946
3d67e040
EZ
4947@noindent
4948The command @code{info symbol 0x54320} yields similar results.
4949@xref{Symbols, info symbol}.
4950
c906108c
SS
4951@item c
4952Regard as an integer and print it as a character constant.
4953
4954@item f
4955Regard the bits of the value as a floating point number and print
4956using typical floating point syntax.
4957@end table
4958
4959For example, to print the program counter in hex (@pxref{Registers}), type
4960
474c8240 4961@smallexample
c906108c 4962p/x $pc
474c8240 4963@end smallexample
c906108c
SS
4964
4965@noindent
4966Note that no space is required before the slash; this is because command
4967names in @value{GDBN} cannot contain a slash.
4968
4969To reprint the last value in the value history with a different format,
4970you can use the @code{print} command with just a format and no
4971expression. For example, @samp{p/x} reprints the last value in hex.
4972
6d2ebf8b 4973@node Memory
c906108c
SS
4974@section Examining memory
4975
4976You can use the command @code{x} (for ``examine'') to examine memory in
4977any of several formats, independently of your program's data types.
4978
4979@cindex examining memory
4980@table @code
41afff9a 4981@kindex x @r{(examine memory)}
c906108c
SS
4982@item x/@var{nfu} @var{addr}
4983@itemx x @var{addr}
4984@itemx x
4985Use the @code{x} command to examine memory.
4986@end table
4987
4988@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
4989much memory to display and how to format it; @var{addr} is an
4990expression giving the address where you want to start displaying memory.
4991If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
4992Several commands set convenient defaults for @var{addr}.
4993
4994@table @r
4995@item @var{n}, the repeat count
4996The repeat count is a decimal integer; the default is 1. It specifies
4997how much memory (counting by units @var{u}) to display.
4998@c This really is **decimal**; unaffected by 'set radix' as of GDB
4999@c 4.1.2.
5000
5001@item @var{f}, the display format
5002The display format is one of the formats used by @code{print},
5003@samp{s} (null-terminated string), or @samp{i} (machine instruction).
5004The default is @samp{x} (hexadecimal) initially.
5005The default changes each time you use either @code{x} or @code{print}.
5006
5007@item @var{u}, the unit size
5008The unit size is any of
5009
5010@table @code
5011@item b
5012Bytes.
5013@item h
5014Halfwords (two bytes).
5015@item w
5016Words (four bytes). This is the initial default.
5017@item g
5018Giant words (eight bytes).
5019@end table
5020
5021Each time you specify a unit size with @code{x}, that size becomes the
5022default unit the next time you use @code{x}. (For the @samp{s} and
5023@samp{i} formats, the unit size is ignored and is normally not written.)
5024
5025@item @var{addr}, starting display address
5026@var{addr} is the address where you want @value{GDBN} to begin displaying
5027memory. The expression need not have a pointer value (though it may);
5028it is always interpreted as an integer address of a byte of memory.
5029@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5030@var{addr} is usually just after the last address examined---but several
5031other commands also set the default address: @code{info breakpoints} (to
5032the address of the last breakpoint listed), @code{info line} (to the
5033starting address of a line), and @code{print} (if you use it to display
5034a value from memory).
5035@end table
5036
5037For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5038(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5039starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5040words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5041@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5042
5043Since the letters indicating unit sizes are all distinct from the
5044letters specifying output formats, you do not have to remember whether
5045unit size or format comes first; either order works. The output
5046specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5047(However, the count @var{n} must come first; @samp{wx4} does not work.)
5048
5049Even though the unit size @var{u} is ignored for the formats @samp{s}
5050and @samp{i}, you might still want to use a count @var{n}; for example,
5051@samp{3i} specifies that you want to see three machine instructions,
5052including any operands. The command @code{disassemble} gives an
d4f3574e 5053alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5054Code,,Source and machine code}.
5055
5056All the defaults for the arguments to @code{x} are designed to make it
5057easy to continue scanning memory with minimal specifications each time
5058you use @code{x}. For example, after you have inspected three machine
5059instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5060with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5061the repeat count @var{n} is used again; the other arguments default as
5062for successive uses of @code{x}.
5063
5064@cindex @code{$_}, @code{$__}, and value history
5065The addresses and contents printed by the @code{x} command are not saved
5066in the value history because there is often too much of them and they
5067would get in the way. Instead, @value{GDBN} makes these values available for
5068subsequent use in expressions as values of the convenience variables
5069@code{$_} and @code{$__}. After an @code{x} command, the last address
5070examined is available for use in expressions in the convenience variable
5071@code{$_}. The contents of that address, as examined, are available in
5072the convenience variable @code{$__}.
5073
5074If the @code{x} command has a repeat count, the address and contents saved
5075are from the last memory unit printed; this is not the same as the last
5076address printed if several units were printed on the last line of output.
5077
6d2ebf8b 5078@node Auto Display
c906108c
SS
5079@section Automatic display
5080@cindex automatic display
5081@cindex display of expressions
5082
5083If you find that you want to print the value of an expression frequently
5084(to see how it changes), you might want to add it to the @dfn{automatic
5085display list} so that @value{GDBN} prints its value each time your program stops.
5086Each expression added to the list is given a number to identify it;
5087to remove an expression from the list, you specify that number.
5088The automatic display looks like this:
5089
474c8240 5090@smallexample
c906108c
SS
50912: foo = 38
50923: bar[5] = (struct hack *) 0x3804
474c8240 5093@end smallexample
c906108c
SS
5094
5095@noindent
5096This display shows item numbers, expressions and their current values. As with
5097displays you request manually using @code{x} or @code{print}, you can
5098specify the output format you prefer; in fact, @code{display} decides
5099whether to use @code{print} or @code{x} depending on how elaborate your
5100format specification is---it uses @code{x} if you specify a unit size,
5101or one of the two formats (@samp{i} and @samp{s}) that are only
5102supported by @code{x}; otherwise it uses @code{print}.
5103
5104@table @code
5105@kindex display
d4f3574e
SS
5106@item display @var{expr}
5107Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5108each time your program stops. @xref{Expressions, ,Expressions}.
5109
5110@code{display} does not repeat if you press @key{RET} again after using it.
5111
d4f3574e 5112@item display/@var{fmt} @var{expr}
c906108c 5113For @var{fmt} specifying only a display format and not a size or
d4f3574e 5114count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5115arrange to display it each time in the specified format @var{fmt}.
5116@xref{Output Formats,,Output formats}.
5117
5118@item display/@var{fmt} @var{addr}
5119For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5120number of units, add the expression @var{addr} as a memory address to
5121be examined each time your program stops. Examining means in effect
5122doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5123@end table
5124
5125For example, @samp{display/i $pc} can be helpful, to see the machine
5126instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5127is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5128
5129@table @code
5130@kindex delete display
5131@kindex undisplay
5132@item undisplay @var{dnums}@dots{}
5133@itemx delete display @var{dnums}@dots{}
5134Remove item numbers @var{dnums} from the list of expressions to display.
5135
5136@code{undisplay} does not repeat if you press @key{RET} after using it.
5137(Otherwise you would just get the error @samp{No display number @dots{}}.)
5138
5139@kindex disable display
5140@item disable display @var{dnums}@dots{}
5141Disable the display of item numbers @var{dnums}. A disabled display
5142item is not printed automatically, but is not forgotten. It may be
5143enabled again later.
5144
5145@kindex enable display
5146@item enable display @var{dnums}@dots{}
5147Enable display of item numbers @var{dnums}. It becomes effective once
5148again in auto display of its expression, until you specify otherwise.
5149
5150@item display
5151Display the current values of the expressions on the list, just as is
5152done when your program stops.
5153
5154@kindex info display
5155@item info display
5156Print the list of expressions previously set up to display
5157automatically, each one with its item number, but without showing the
5158values. This includes disabled expressions, which are marked as such.
5159It also includes expressions which would not be displayed right now
5160because they refer to automatic variables not currently available.
5161@end table
5162
5163If a display expression refers to local variables, then it does not make
5164sense outside the lexical context for which it was set up. Such an
5165expression is disabled when execution enters a context where one of its
5166variables is not defined. For example, if you give the command
5167@code{display last_char} while inside a function with an argument
5168@code{last_char}, @value{GDBN} displays this argument while your program
5169continues to stop inside that function. When it stops elsewhere---where
5170there is no variable @code{last_char}---the display is disabled
5171automatically. The next time your program stops where @code{last_char}
5172is meaningful, you can enable the display expression once again.
5173
6d2ebf8b 5174@node Print Settings
c906108c
SS
5175@section Print settings
5176
5177@cindex format options
5178@cindex print settings
5179@value{GDBN} provides the following ways to control how arrays, structures,
5180and symbols are printed.
5181
5182@noindent
5183These settings are useful for debugging programs in any language:
5184
5185@table @code
5186@kindex set print address
5187@item set print address
5188@itemx set print address on
5189@value{GDBN} prints memory addresses showing the location of stack
5190traces, structure values, pointer values, breakpoints, and so forth,
5191even when it also displays the contents of those addresses. The default
5192is @code{on}. For example, this is what a stack frame display looks like with
5193@code{set print address on}:
5194
5195@smallexample
5196@group
5197(@value{GDBP}) f
5198#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5199 at input.c:530
5200530 if (lquote != def_lquote)
5201@end group
5202@end smallexample
5203
5204@item set print address off
5205Do not print addresses when displaying their contents. For example,
5206this is the same stack frame displayed with @code{set print address off}:
5207
5208@smallexample
5209@group
5210(@value{GDBP}) set print addr off
5211(@value{GDBP}) f
5212#0 set_quotes (lq="<<", rq=">>") at input.c:530
5213530 if (lquote != def_lquote)
5214@end group
5215@end smallexample
5216
5217You can use @samp{set print address off} to eliminate all machine
5218dependent displays from the @value{GDBN} interface. For example, with
5219@code{print address off}, you should get the same text for backtraces on
5220all machines---whether or not they involve pointer arguments.
5221
5222@kindex show print address
5223@item show print address
5224Show whether or not addresses are to be printed.
5225@end table
5226
5227When @value{GDBN} prints a symbolic address, it normally prints the
5228closest earlier symbol plus an offset. If that symbol does not uniquely
5229identify the address (for example, it is a name whose scope is a single
5230source file), you may need to clarify. One way to do this is with
5231@code{info line}, for example @samp{info line *0x4537}. Alternately,
5232you can set @value{GDBN} to print the source file and line number when
5233it prints a symbolic address:
5234
5235@table @code
5236@kindex set print symbol-filename
5237@item set print symbol-filename on
5238Tell @value{GDBN} to print the source file name and line number of a
5239symbol in the symbolic form of an address.
5240
5241@item set print symbol-filename off
5242Do not print source file name and line number of a symbol. This is the
5243default.
5244
5245@kindex show print symbol-filename
5246@item show print symbol-filename
5247Show whether or not @value{GDBN} will print the source file name and
5248line number of a symbol in the symbolic form of an address.
5249@end table
5250
5251Another situation where it is helpful to show symbol filenames and line
5252numbers is when disassembling code; @value{GDBN} shows you the line
5253number and source file that corresponds to each instruction.
5254
5255Also, you may wish to see the symbolic form only if the address being
5256printed is reasonably close to the closest earlier symbol:
5257
5258@table @code
5259@kindex set print max-symbolic-offset
5260@item set print max-symbolic-offset @var{max-offset}
5261Tell @value{GDBN} to only display the symbolic form of an address if the
5262offset between the closest earlier symbol and the address is less than
5d161b24 5263@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5264to always print the symbolic form of an address if any symbol precedes it.
5265
5266@kindex show print max-symbolic-offset
5267@item show print max-symbolic-offset
5268Ask how large the maximum offset is that @value{GDBN} prints in a
5269symbolic address.
5270@end table
5271
5272@cindex wild pointer, interpreting
5273@cindex pointer, finding referent
5274If you have a pointer and you are not sure where it points, try
5275@samp{set print symbol-filename on}. Then you can determine the name
5276and source file location of the variable where it points, using
5277@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5278For example, here @value{GDBN} shows that a variable @code{ptt} points
5279at another variable @code{t}, defined in @file{hi2.c}:
5280
474c8240 5281@smallexample
c906108c
SS
5282(@value{GDBP}) set print symbol-filename on
5283(@value{GDBP}) p/a ptt
5284$4 = 0xe008 <t in hi2.c>
474c8240 5285@end smallexample
c906108c
SS
5286
5287@quotation
5288@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5289does not show the symbol name and filename of the referent, even with
5290the appropriate @code{set print} options turned on.
5291@end quotation
5292
5293Other settings control how different kinds of objects are printed:
5294
5295@table @code
5296@kindex set print array
5297@item set print array
5298@itemx set print array on
5299Pretty print arrays. This format is more convenient to read,
5300but uses more space. The default is off.
5301
5302@item set print array off
5303Return to compressed format for arrays.
5304
5305@kindex show print array
5306@item show print array
5307Show whether compressed or pretty format is selected for displaying
5308arrays.
5309
5310@kindex set print elements
5311@item set print elements @var{number-of-elements}
5312Set a limit on how many elements of an array @value{GDBN} will print.
5313If @value{GDBN} is printing a large array, it stops printing after it has
5314printed the number of elements set by the @code{set print elements} command.
5315This limit also applies to the display of strings.
d4f3574e 5316When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5317Setting @var{number-of-elements} to zero means that the printing is unlimited.
5318
5319@kindex show print elements
5320@item show print elements
5321Display the number of elements of a large array that @value{GDBN} will print.
5322If the number is 0, then the printing is unlimited.
5323
5324@kindex set print null-stop
5325@item set print null-stop
5326Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5327@sc{null} is encountered. This is useful when large arrays actually
c906108c 5328contain only short strings.
d4f3574e 5329The default is off.
c906108c
SS
5330
5331@kindex set print pretty
5332@item set print pretty on
5d161b24 5333Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5334per line, like this:
5335
5336@smallexample
5337@group
5338$1 = @{
5339 next = 0x0,
5340 flags = @{
5341 sweet = 1,
5342 sour = 1
5343 @},
5344 meat = 0x54 "Pork"
5345@}
5346@end group
5347@end smallexample
5348
5349@item set print pretty off
5350Cause @value{GDBN} to print structures in a compact format, like this:
5351
5352@smallexample
5353@group
5354$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5355meat = 0x54 "Pork"@}
5356@end group
5357@end smallexample
5358
5359@noindent
5360This is the default format.
5361
5362@kindex show print pretty
5363@item show print pretty
5364Show which format @value{GDBN} is using to print structures.
5365
5366@kindex set print sevenbit-strings
5367@item set print sevenbit-strings on
5368Print using only seven-bit characters; if this option is set,
5369@value{GDBN} displays any eight-bit characters (in strings or
5370character values) using the notation @code{\}@var{nnn}. This setting is
5371best if you are working in English (@sc{ascii}) and you use the
5372high-order bit of characters as a marker or ``meta'' bit.
5373
5374@item set print sevenbit-strings off
5375Print full eight-bit characters. This allows the use of more
5376international character sets, and is the default.
5377
5378@kindex show print sevenbit-strings
5379@item show print sevenbit-strings
5380Show whether or not @value{GDBN} is printing only seven-bit characters.
5381
5382@kindex set print union
5383@item set print union on
5d161b24 5384Tell @value{GDBN} to print unions which are contained in structures. This
c906108c
SS
5385is the default setting.
5386
5387@item set print union off
5388Tell @value{GDBN} not to print unions which are contained in structures.
5389
5390@kindex show print union
5391@item show print union
5392Ask @value{GDBN} whether or not it will print unions which are contained in
5393structures.
5394
5395For example, given the declarations
5396
5397@smallexample
5398typedef enum @{Tree, Bug@} Species;
5399typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5400typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5401 Bug_forms;
5402
5403struct thing @{
5404 Species it;
5405 union @{
5406 Tree_forms tree;
5407 Bug_forms bug;
5408 @} form;
5409@};
5410
5411struct thing foo = @{Tree, @{Acorn@}@};
5412@end smallexample
5413
5414@noindent
5415with @code{set print union on} in effect @samp{p foo} would print
5416
5417@smallexample
5418$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5419@end smallexample
5420
5421@noindent
5422and with @code{set print union off} in effect it would print
5423
5424@smallexample
5425$1 = @{it = Tree, form = @{...@}@}
5426@end smallexample
5427@end table
5428
c906108c
SS
5429@need 1000
5430@noindent
b37052ae 5431These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5432
5433@table @code
5434@cindex demangling
5435@kindex set print demangle
5436@item set print demangle
5437@itemx set print demangle on
b37052ae 5438Print C@t{++} names in their source form rather than in the encoded
c906108c 5439(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5440linkage. The default is on.
c906108c
SS
5441
5442@kindex show print demangle
5443@item show print demangle
b37052ae 5444Show whether C@t{++} names are printed in mangled or demangled form.
c906108c
SS
5445
5446@kindex set print asm-demangle
5447@item set print asm-demangle
5448@itemx set print asm-demangle on
b37052ae 5449Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5450in assembler code printouts such as instruction disassemblies.
5451The default is off.
5452
5453@kindex show print asm-demangle
5454@item show print asm-demangle
b37052ae 5455Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5456or demangled form.
5457
5458@kindex set demangle-style
b37052ae
EZ
5459@cindex C@t{++} symbol decoding style
5460@cindex symbol decoding style, C@t{++}
c906108c
SS
5461@item set demangle-style @var{style}
5462Choose among several encoding schemes used by different compilers to
b37052ae 5463represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5464
5465@table @code
5466@item auto
5467Allow @value{GDBN} to choose a decoding style by inspecting your program.
5468
5469@item gnu
b37052ae 5470Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5471This is the default.
c906108c
SS
5472
5473@item hp
b37052ae 5474Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5475
5476@item lucid
b37052ae 5477Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5478
5479@item arm
b37052ae 5480Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5481@strong{Warning:} this setting alone is not sufficient to allow
5482debugging @code{cfront}-generated executables. @value{GDBN} would
5483require further enhancement to permit that.
5484
5485@end table
5486If you omit @var{style}, you will see a list of possible formats.
5487
5488@kindex show demangle-style
5489@item show demangle-style
b37052ae 5490Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c
SS
5491
5492@kindex set print object
5493@item set print object
5494@itemx set print object on
5495When displaying a pointer to an object, identify the @emph{actual}
5496(derived) type of the object rather than the @emph{declared} type, using
5497the virtual function table.
5498
5499@item set print object off
5500Display only the declared type of objects, without reference to the
5501virtual function table. This is the default setting.
5502
5503@kindex show print object
5504@item show print object
5505Show whether actual, or declared, object types are displayed.
5506
5507@kindex set print static-members
5508@item set print static-members
5509@itemx set print static-members on
b37052ae 5510Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5511
5512@item set print static-members off
b37052ae 5513Do not print static members when displaying a C@t{++} object.
c906108c
SS
5514
5515@kindex show print static-members
5516@item show print static-members
b37052ae 5517Show whether C@t{++} static members are printed, or not.
c906108c
SS
5518
5519@c These don't work with HP ANSI C++ yet.
5520@kindex set print vtbl
5521@item set print vtbl
5522@itemx set print vtbl on
b37052ae 5523Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5524(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5525ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5526
5527@item set print vtbl off
b37052ae 5528Do not pretty print C@t{++} virtual function tables.
c906108c
SS
5529
5530@kindex show print vtbl
5531@item show print vtbl
b37052ae 5532Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5533@end table
c906108c 5534
6d2ebf8b 5535@node Value History
c906108c
SS
5536@section Value history
5537
5538@cindex value history
5d161b24
DB
5539Values printed by the @code{print} command are saved in the @value{GDBN}
5540@dfn{value history}. This allows you to refer to them in other expressions.
5541Values are kept until the symbol table is re-read or discarded
5542(for example with the @code{file} or @code{symbol-file} commands).
5543When the symbol table changes, the value history is discarded,
5544since the values may contain pointers back to the types defined in the
c906108c
SS
5545symbol table.
5546
5547@cindex @code{$}
5548@cindex @code{$$}
5549@cindex history number
5550The values printed are given @dfn{history numbers} by which you can
5551refer to them. These are successive integers starting with one.
5552@code{print} shows you the history number assigned to a value by
5553printing @samp{$@var{num} = } before the value; here @var{num} is the
5554history number.
5555
5556To refer to any previous value, use @samp{$} followed by the value's
5557history number. The way @code{print} labels its output is designed to
5558remind you of this. Just @code{$} refers to the most recent value in
5559the history, and @code{$$} refers to the value before that.
5560@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5561is the value just prior to @code{$$}, @code{$$1} is equivalent to
5562@code{$$}, and @code{$$0} is equivalent to @code{$}.
5563
5564For example, suppose you have just printed a pointer to a structure and
5565want to see the contents of the structure. It suffices to type
5566
474c8240 5567@smallexample
c906108c 5568p *$
474c8240 5569@end smallexample
c906108c
SS
5570
5571If you have a chain of structures where the component @code{next} points
5572to the next one, you can print the contents of the next one with this:
5573
474c8240 5574@smallexample
c906108c 5575p *$.next
474c8240 5576@end smallexample
c906108c
SS
5577
5578@noindent
5579You can print successive links in the chain by repeating this
5580command---which you can do by just typing @key{RET}.
5581
5582Note that the history records values, not expressions. If the value of
5583@code{x} is 4 and you type these commands:
5584
474c8240 5585@smallexample
c906108c
SS
5586print x
5587set x=5
474c8240 5588@end smallexample
c906108c
SS
5589
5590@noindent
5591then the value recorded in the value history by the @code{print} command
5592remains 4 even though the value of @code{x} has changed.
5593
5594@table @code
5595@kindex show values
5596@item show values
5597Print the last ten values in the value history, with their item numbers.
5598This is like @samp{p@ $$9} repeated ten times, except that @code{show
5599values} does not change the history.
5600
5601@item show values @var{n}
5602Print ten history values centered on history item number @var{n}.
5603
5604@item show values +
5605Print ten history values just after the values last printed. If no more
5606values are available, @code{show values +} produces no display.
5607@end table
5608
5609Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5610same effect as @samp{show values +}.
5611
6d2ebf8b 5612@node Convenience Vars
c906108c
SS
5613@section Convenience variables
5614
5615@cindex convenience variables
5616@value{GDBN} provides @dfn{convenience variables} that you can use within
5617@value{GDBN} to hold on to a value and refer to it later. These variables
5618exist entirely within @value{GDBN}; they are not part of your program, and
5619setting a convenience variable has no direct effect on further execution
5620of your program. That is why you can use them freely.
5621
5622Convenience variables are prefixed with @samp{$}. Any name preceded by
5623@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 5624the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
5625(Value history references, in contrast, are @emph{numbers} preceded
5626by @samp{$}. @xref{Value History, ,Value history}.)
5627
5628You can save a value in a convenience variable with an assignment
5629expression, just as you would set a variable in your program.
5630For example:
5631
474c8240 5632@smallexample
c906108c 5633set $foo = *object_ptr
474c8240 5634@end smallexample
c906108c
SS
5635
5636@noindent
5637would save in @code{$foo} the value contained in the object pointed to by
5638@code{object_ptr}.
5639
5640Using a convenience variable for the first time creates it, but its
5641value is @code{void} until you assign a new value. You can alter the
5642value with another assignment at any time.
5643
5644Convenience variables have no fixed types. You can assign a convenience
5645variable any type of value, including structures and arrays, even if
5646that variable already has a value of a different type. The convenience
5647variable, when used as an expression, has the type of its current value.
5648
5649@table @code
5650@kindex show convenience
5651@item show convenience
5652Print a list of convenience variables used so far, and their values.
d4f3574e 5653Abbreviated @code{show conv}.
c906108c
SS
5654@end table
5655
5656One of the ways to use a convenience variable is as a counter to be
5657incremented or a pointer to be advanced. For example, to print
5658a field from successive elements of an array of structures:
5659
474c8240 5660@smallexample
c906108c
SS
5661set $i = 0
5662print bar[$i++]->contents
474c8240 5663@end smallexample
c906108c 5664
d4f3574e
SS
5665@noindent
5666Repeat that command by typing @key{RET}.
c906108c
SS
5667
5668Some convenience variables are created automatically by @value{GDBN} and given
5669values likely to be useful.
5670
5671@table @code
41afff9a 5672@vindex $_@r{, convenience variable}
c906108c
SS
5673@item $_
5674The variable @code{$_} is automatically set by the @code{x} command to
5675the last address examined (@pxref{Memory, ,Examining memory}). Other
5676commands which provide a default address for @code{x} to examine also
5677set @code{$_} to that address; these commands include @code{info line}
5678and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5679except when set by the @code{x} command, in which case it is a pointer
5680to the type of @code{$__}.
5681
41afff9a 5682@vindex $__@r{, convenience variable}
c906108c
SS
5683@item $__
5684The variable @code{$__} is automatically set by the @code{x} command
5685to the value found in the last address examined. Its type is chosen
5686to match the format in which the data was printed.
5687
5688@item $_exitcode
41afff9a 5689@vindex $_exitcode@r{, convenience variable}
c906108c
SS
5690The variable @code{$_exitcode} is automatically set to the exit code when
5691the program being debugged terminates.
5692@end table
5693
53a5351d
JM
5694On HP-UX systems, if you refer to a function or variable name that
5695begins with a dollar sign, @value{GDBN} searches for a user or system
5696name first, before it searches for a convenience variable.
c906108c 5697
6d2ebf8b 5698@node Registers
c906108c
SS
5699@section Registers
5700
5701@cindex registers
5702You can refer to machine register contents, in expressions, as variables
5703with names starting with @samp{$}. The names of registers are different
5704for each machine; use @code{info registers} to see the names used on
5705your machine.
5706
5707@table @code
5708@kindex info registers
5709@item info registers
5710Print the names and values of all registers except floating-point
c85508ee 5711and vector registers (in the selected stack frame).
c906108c
SS
5712
5713@kindex info all-registers
5714@cindex floating point registers
5715@item info all-registers
5716Print the names and values of all registers, including floating-point
c85508ee 5717and vector registers (in the selected stack frame).
c906108c
SS
5718
5719@item info registers @var{regname} @dots{}
5720Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
5721As discussed in detail below, register values are normally relative to
5722the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
5723the machine you are using, with or without the initial @samp{$}.
5724@end table
5725
5726@value{GDBN} has four ``standard'' register names that are available (in
5727expressions) on most machines---whenever they do not conflict with an
5728architecture's canonical mnemonics for registers. The register names
5729@code{$pc} and @code{$sp} are used for the program counter register and
5730the stack pointer. @code{$fp} is used for a register that contains a
5731pointer to the current stack frame, and @code{$ps} is used for a
5732register that contains the processor status. For example,
5733you could print the program counter in hex with
5734
474c8240 5735@smallexample
c906108c 5736p/x $pc
474c8240 5737@end smallexample
c906108c
SS
5738
5739@noindent
5740or print the instruction to be executed next with
5741
474c8240 5742@smallexample
c906108c 5743x/i $pc
474c8240 5744@end smallexample
c906108c
SS
5745
5746@noindent
5747or add four to the stack pointer@footnote{This is a way of removing
5748one word from the stack, on machines where stacks grow downward in
5749memory (most machines, nowadays). This assumes that the innermost
5750stack frame is selected; setting @code{$sp} is not allowed when other
5751stack frames are selected. To pop entire frames off the stack,
5752regardless of machine architecture, use @code{return};
d4f3574e 5753see @ref{Returning, ,Returning from a function}.} with
c906108c 5754
474c8240 5755@smallexample
c906108c 5756set $sp += 4
474c8240 5757@end smallexample
c906108c
SS
5758
5759Whenever possible, these four standard register names are available on
5760your machine even though the machine has different canonical mnemonics,
5761so long as there is no conflict. The @code{info registers} command
5762shows the canonical names. For example, on the SPARC, @code{info
5763registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
5764can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
5765is an alias for the @sc{eflags} register.
c906108c
SS
5766
5767@value{GDBN} always considers the contents of an ordinary register as an
5768integer when the register is examined in this way. Some machines have
5769special registers which can hold nothing but floating point; these
5770registers are considered to have floating point values. There is no way
5771to refer to the contents of an ordinary register as floating point value
5772(although you can @emph{print} it as a floating point value with
5773@samp{print/f $@var{regname}}).
5774
5775Some registers have distinct ``raw'' and ``virtual'' data formats. This
5776means that the data format in which the register contents are saved by
5777the operating system is not the same one that your program normally
5778sees. For example, the registers of the 68881 floating point
5779coprocessor are always saved in ``extended'' (raw) format, but all C
5780programs expect to work with ``double'' (virtual) format. In such
5d161b24 5781cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
5782that makes sense for your program), but the @code{info registers} command
5783prints the data in both formats.
5784
5785Normally, register values are relative to the selected stack frame
5786(@pxref{Selection, ,Selecting a frame}). This means that you get the
5787value that the register would contain if all stack frames farther in
5788were exited and their saved registers restored. In order to see the
5789true contents of hardware registers, you must select the innermost
5790frame (with @samp{frame 0}).
5791
5792However, @value{GDBN} must deduce where registers are saved, from the machine
5793code generated by your compiler. If some registers are not saved, or if
5794@value{GDBN} is unable to locate the saved registers, the selected stack
5795frame makes no difference.
5796
6d2ebf8b 5797@node Floating Point Hardware
c906108c
SS
5798@section Floating point hardware
5799@cindex floating point
5800
5801Depending on the configuration, @value{GDBN} may be able to give
5802you more information about the status of the floating point hardware.
5803
5804@table @code
5805@kindex info float
5806@item info float
5807Display hardware-dependent information about the floating
5808point unit. The exact contents and layout vary depending on the
5809floating point chip. Currently, @samp{info float} is supported on
5810the ARM and x86 machines.
5811@end table
c906108c 5812
e76f1f2e
AC
5813@node Vector Unit
5814@section Vector Unit
5815@cindex vector unit
5816
5817Depending on the configuration, @value{GDBN} may be able to give you
5818more information about the status of the vector unit.
5819
5820@table @code
5821@kindex info vector
5822@item info vector
5823Display information about the vector unit. The exact contents and
5824layout vary depending on the hardware.
5825@end table
5826
29e57380 5827@node Memory Region Attributes
16d9dec6 5828@section Memory region attributes
29e57380
C
5829@cindex memory region attributes
5830
5831@dfn{Memory region attributes} allow you to describe special handling
5832required by regions of your target's memory. @value{GDBN} uses attributes
5833to determine whether to allow certain types of memory accesses; whether to
5834use specific width accesses; and whether to cache target memory.
5835
5836Defined memory regions can be individually enabled and disabled. When a
5837memory region is disabled, @value{GDBN} uses the default attributes when
5838accessing memory in that region. Similarly, if no memory regions have
5839been defined, @value{GDBN} uses the default attributes when accessing
5840all memory.
5841
5842When a memory region is defined, it is given a number to identify it;
5843to enable, disable, or remove a memory region, you specify that number.
5844
5845@table @code
5846@kindex mem
bfac230e
DH
5847@item mem @var{lower} @var{upper} @var{attributes}@dots{}
5848Define memory region bounded by @var{lower} and @var{upper} with
5849attributes @var{attributes}@dots{}. Note that @var{upper} == 0 is a
5850special case: it is treated as the the target's maximum memory address.
5851(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
5852
5853@kindex delete mem
5854@item delete mem @var{nums}@dots{}
59649f2e 5855Remove memory regions @var{nums}@dots{}.
29e57380
C
5856
5857@kindex disable mem
5858@item disable mem @var{nums}@dots{}
59649f2e 5859Disable memory regions @var{nums}@dots{}.
29e57380
C
5860A disabled memory region is not forgotten.
5861It may be enabled again later.
5862
5863@kindex enable mem
5864@item enable mem @var{nums}@dots{}
59649f2e 5865Enable memory regions @var{nums}@dots{}.
29e57380
C
5866
5867@kindex info mem
5868@item info mem
5869Print a table of all defined memory regions, with the following columns
5870for each region.
5871
5872@table @emph
5873@item Memory Region Number
5874@item Enabled or Disabled.
5875Enabled memory regions are marked with @samp{y}.
5876Disabled memory regions are marked with @samp{n}.
5877
5878@item Lo Address
5879The address defining the inclusive lower bound of the memory region.
5880
5881@item Hi Address
5882The address defining the exclusive upper bound of the memory region.
5883
5884@item Attributes
5885The list of attributes set for this memory region.
5886@end table
5887@end table
5888
5889
5890@subsection Attributes
5891
5892@subsubsection Memory Access Mode
5893The access mode attributes set whether @value{GDBN} may make read or
5894write accesses to a memory region.
5895
5896While these attributes prevent @value{GDBN} from performing invalid
5897memory accesses, they do nothing to prevent the target system, I/O DMA,
5898etc. from accessing memory.
5899
5900@table @code
5901@item ro
5902Memory is read only.
5903@item wo
5904Memory is write only.
5905@item rw
6ca652b0 5906Memory is read/write. This is the default.
29e57380
C
5907@end table
5908
5909@subsubsection Memory Access Size
5910The acccess size attributes tells @value{GDBN} to use specific sized
5911accesses in the memory region. Often memory mapped device registers
5912require specific sized accesses. If no access size attribute is
5913specified, @value{GDBN} may use accesses of any size.
5914
5915@table @code
5916@item 8
5917Use 8 bit memory accesses.
5918@item 16
5919Use 16 bit memory accesses.
5920@item 32
5921Use 32 bit memory accesses.
5922@item 64
5923Use 64 bit memory accesses.
5924@end table
5925
5926@c @subsubsection Hardware/Software Breakpoints
5927@c The hardware/software breakpoint attributes set whether @value{GDBN}
5928@c will use hardware or software breakpoints for the internal breakpoints
5929@c used by the step, next, finish, until, etc. commands.
5930@c
5931@c @table @code
5932@c @item hwbreak
5933@c Always use hardware breakpoints
5934@c @item swbreak (default)
5935@c @end table
5936
5937@subsubsection Data Cache
5938The data cache attributes set whether @value{GDBN} will cache target
5939memory. While this generally improves performance by reducing debug
5940protocol overhead, it can lead to incorrect results because @value{GDBN}
5941does not know about volatile variables or memory mapped device
5942registers.
5943
5944@table @code
5945@item cache
5946Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
5947@item nocache
5948Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
5949@end table
5950
5951@c @subsubsection Memory Write Verification
5952@c The memory write verification attributes set whether @value{GDBN}
5953@c will re-reads data after each write to verify the write was successful.
5954@c
5955@c @table @code
5956@c @item verify
5957@c @item noverify (default)
5958@c @end table
5959
16d9dec6
MS
5960@node Dump/Restore Files
5961@section Copy between memory and a file
5962@cindex dump/restore files
5963@cindex append data to a file
5964@cindex dump data to a file
5965@cindex restore data from a file
16d9dec6 5966
df5215a6
JB
5967You can use the commands @code{dump}, @code{append}, and
5968@code{restore} to copy data between target memory and a file. The
5969@code{dump} and @code{append} commands write data to a file, and the
5970@code{restore} command reads data from a file back into the inferior's
5971memory. Files may be in binary, Motorola S-record, Intel hex, or
5972Tektronix Hex format; however, @value{GDBN} can only append to binary
5973files.
5974
5975@table @code
5976
5977@kindex dump
5978@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
5979@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
5980Dump the contents of memory from @var{start_addr} to @var{end_addr},
5981or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 5982
df5215a6 5983The @var{format} parameter may be any one of:
16d9dec6 5984@table @code
df5215a6
JB
5985@item binary
5986Raw binary form.
5987@item ihex
5988Intel hex format.
5989@item srec
5990Motorola S-record format.
5991@item tekhex
5992Tektronix Hex format.
5993@end table
5994
5995@value{GDBN} uses the same definitions of these formats as the
5996@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
5997@var{format} is omitted, @value{GDBN} dumps the data in raw binary
5998form.
5999
6000@kindex append
6001@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6002@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6003Append the contents of memory from @var{start_addr} to @var{end_addr},
6004or the value of @var{expr}, to @var{filename}, in raw binary form.
6005(@value{GDBN} can only append data to files in raw binary form.)
6006
6007@kindex restore
6008@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6009Restore the contents of file @var{filename} into memory. The
6010@code{restore} command can automatically recognize any known @sc{bfd}
6011file format, except for raw binary. To restore a raw binary file you
6012must specify the optional keyword @code{binary} after the filename.
16d9dec6
MS
6013
6014If @var{bias} is non-zero, its value will be added to the addresses
6015contained in the file. Binary files always start at address zero, so
6016they will be restored at address @var{bias}. Other bfd files have
6017a built-in location; they will be restored at offset @var{bias}
6018from that location.
6019
6020If @var{start} and/or @var{end} are non-zero, then only data between
6021file offset @var{start} and file offset @var{end} will be restored.
6022These offsets are relative to the addresses in the file, before
6023the @var{bias} argument is applied.
6024
6025@end table
6026
a0eb71c5
KB
6027@node Character Sets
6028@section Character Sets
6029@cindex character sets
6030@cindex charset
6031@cindex translating between character sets
6032@cindex host character set
6033@cindex target character set
6034
6035If the program you are debugging uses a different character set to
6036represent characters and strings than the one @value{GDBN} uses itself,
6037@value{GDBN} can automatically translate between the character sets for
6038you. The character set @value{GDBN} uses we call the @dfn{host
6039character set}; the one the inferior program uses we call the
6040@dfn{target character set}.
6041
6042For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6043uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6044remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6045running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6046then the host character set is Latin-1, and the target character set is
6047@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6048target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6049@sc{ebcdic} and Latin 1 as you print character or string values, or use
6050character and string literals in expressions.
6051
6052@value{GDBN} has no way to automatically recognize which character set
6053the inferior program uses; you must tell it, using the @code{set
6054target-charset} command, described below.
6055
6056Here are the commands for controlling @value{GDBN}'s character set
6057support:
6058
6059@table @code
6060@item set target-charset @var{charset}
6061@kindex set target-charset
6062Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6063character set names @value{GDBN} recognizes below, but if you type
6064@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6065list the target character sets it supports.
a0eb71c5
KB
6066@end table
6067
6068@table @code
6069@item set host-charset @var{charset}
6070@kindex set host-charset
6071Set the current host character set to @var{charset}.
6072
6073By default, @value{GDBN} uses a host character set appropriate to the
6074system it is running on; you can override that default using the
6075@code{set host-charset} command.
6076
6077@value{GDBN} can only use certain character sets as its host character
6078set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6079indicate which can be host character sets, but if you type
6080@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6081list the host character sets it supports.
a0eb71c5
KB
6082
6083@item set charset @var{charset}
6084@kindex set charset
e33d66ec
EZ
6085Set the current host and target character sets to @var{charset}. As
6086above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6087@value{GDBN} will list the name of the character sets that can be used
6088for both host and target.
6089
a0eb71c5
KB
6090
6091@item show charset
a0eb71c5 6092@kindex show charset
e33d66ec
EZ
6093Show the names of the current host and target charsets.
6094
6095@itemx show host-charset
a0eb71c5 6096@kindex show host-charset
e33d66ec
EZ
6097Show the name of the current host charset.
6098
6099@itemx show target-charset
a0eb71c5 6100@kindex show target-charset
e33d66ec 6101Show the name of the current target charset.
a0eb71c5
KB
6102
6103@end table
6104
6105@value{GDBN} currently includes support for the following character
6106sets:
6107
6108@table @code
6109
6110@item ASCII
6111@cindex ASCII character set
6112Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6113character set.
6114
6115@item ISO-8859-1
6116@cindex ISO 8859-1 character set
6117@cindex ISO Latin 1 character set
e33d66ec 6118The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6119characters needed for French, German, and Spanish. @value{GDBN} can use
6120this as its host character set.
6121
6122@item EBCDIC-US
6123@itemx IBM1047
6124@cindex EBCDIC character set
6125@cindex IBM1047 character set
6126Variants of the @sc{ebcdic} character set, used on some of IBM's
6127mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6128@value{GDBN} cannot use these as its host character set.
6129
6130@end table
6131
6132Note that these are all single-byte character sets. More work inside
6133GDB is needed to support multi-byte or variable-width character
6134encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6135
6136Here is an example of @value{GDBN}'s character set support in action.
6137Assume that the following source code has been placed in the file
6138@file{charset-test.c}:
6139
6140@smallexample
6141#include <stdio.h>
6142
6143char ascii_hello[]
6144 = @{72, 101, 108, 108, 111, 44, 32, 119,
6145 111, 114, 108, 100, 33, 10, 0@};
6146char ibm1047_hello[]
6147 = @{200, 133, 147, 147, 150, 107, 64, 166,
6148 150, 153, 147, 132, 90, 37, 0@};
6149
6150main ()
6151@{
6152 printf ("Hello, world!\n");
6153@}
10998722 6154@end smallexample
a0eb71c5
KB
6155
6156In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6157containing the string @samp{Hello, world!} followed by a newline,
6158encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6159
6160We compile the program, and invoke the debugger on it:
6161
6162@smallexample
6163$ gcc -g charset-test.c -o charset-test
6164$ gdb -nw charset-test
6165GNU gdb 2001-12-19-cvs
6166Copyright 2001 Free Software Foundation, Inc.
6167@dots{}
6168(gdb)
10998722 6169@end smallexample
a0eb71c5
KB
6170
6171We can use the @code{show charset} command to see what character sets
6172@value{GDBN} is currently using to interpret and display characters and
6173strings:
6174
6175@smallexample
6176(gdb) show charset
e33d66ec 6177The current host and target character set is `ISO-8859-1'.
a0eb71c5 6178(gdb)
10998722 6179@end smallexample
a0eb71c5
KB
6180
6181For the sake of printing this manual, let's use @sc{ascii} as our
6182initial character set:
6183@smallexample
e33d66ec 6184(gdb) set charset ASCII
a0eb71c5 6185(gdb) show charset
e33d66ec 6186The current host and target character set is `ASCII'.
a0eb71c5 6187(gdb)
10998722 6188@end smallexample
a0eb71c5
KB
6189
6190Let's assume that @sc{ascii} is indeed the correct character set for our
6191host system --- in other words, let's assume that if @value{GDBN} prints
6192characters using the @sc{ascii} character set, our terminal will display
6193them properly. Since our current target character set is also
6194@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6195
6196@smallexample
6197(gdb) print ascii_hello
6198$1 = 0x401698 "Hello, world!\n"
6199(gdb) print ascii_hello[0]
6200$2 = 72 'H'
6201(gdb)
10998722 6202@end smallexample
a0eb71c5
KB
6203
6204@value{GDBN} uses the target character set for character and string
6205literals you use in expressions:
6206
6207@smallexample
6208(gdb) print '+'
6209$3 = 43 '+'
6210(gdb)
10998722 6211@end smallexample
a0eb71c5
KB
6212
6213The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6214character.
6215
6216@value{GDBN} relies on the user to tell it which character set the
6217target program uses. If we print @code{ibm1047_hello} while our target
6218character set is still @sc{ascii}, we get jibberish:
6219
6220@smallexample
6221(gdb) print ibm1047_hello
6222$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
6223(gdb) print ibm1047_hello[0]
6224$5 = 200 '\310'
6225(gdb)
10998722 6226@end smallexample
a0eb71c5 6227
e33d66ec 6228If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6229@value{GDBN} tells us the character sets it supports:
6230
6231@smallexample
6232(gdb) set target-charset
e33d66ec
EZ
6233ASCII EBCDIC-US IBM1047 ISO-8859-1
6234(gdb) set target-charset
10998722 6235@end smallexample
a0eb71c5
KB
6236
6237We can select @sc{ibm1047} as our target character set, and examine the
6238program's strings again. Now the @sc{ascii} string is wrong, but
6239@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6240target character set, @sc{ibm1047}, to the host character set,
6241@sc{ascii}, and they display correctly:
6242
6243@smallexample
e33d66ec 6244(gdb) set target-charset IBM1047
a0eb71c5 6245(gdb) show charset
e33d66ec
EZ
6246The current host character set is `ASCII'.
6247The current target character set is `IBM1047'.
a0eb71c5
KB
6248(gdb) print ascii_hello
6249$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
6250(gdb) print ascii_hello[0]
6251$7 = 72 '\110'
6252(gdb) print ibm1047_hello
6253$8 = 0x4016a8 "Hello, world!\n"
6254(gdb) print ibm1047_hello[0]
6255$9 = 200 'H'
6256(gdb)
10998722 6257@end smallexample
a0eb71c5
KB
6258
6259As above, @value{GDBN} uses the target character set for character and
6260string literals you use in expressions:
6261
6262@smallexample
6263(gdb) print '+'
6264$10 = 78 '+'
6265(gdb)
10998722 6266@end smallexample
a0eb71c5 6267
e33d66ec 6268The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6269character.
6270
6271
e2e0bcd1
JB
6272@node Macros
6273@chapter C Preprocessor Macros
6274
6275Some languages, such as C and C++, provide a way to define and invoke
6276``preprocessor macros'' which expand into strings of tokens.
6277@value{GDBN} can evaluate expressions containing macro invocations, show
6278the result of macro expansion, and show a macro's definition, including
6279where it was defined.
6280
6281You may need to compile your program specially to provide @value{GDBN}
6282with information about preprocessor macros. Most compilers do not
6283include macros in their debugging information, even when you compile
6284with the @option{-g} flag. @xref{Compilation}.
6285
6286A program may define a macro at one point, remove that definition later,
6287and then provide a different definition after that. Thus, at different
6288points in the program, a macro may have different definitions, or have
6289no definition at all. If there is a current stack frame, @value{GDBN}
6290uses the macros in scope at that frame's source code line. Otherwise,
6291@value{GDBN} uses the macros in scope at the current listing location;
6292see @ref{List}.
6293
6294At the moment, @value{GDBN} does not support the @code{##}
6295token-splicing operator, the @code{#} stringification operator, or
6296variable-arity macros.
6297
6298Whenever @value{GDBN} evaluates an expression, it always expands any
6299macro invocations present in the expression. @value{GDBN} also provides
6300the following commands for working with macros explicitly.
6301
6302@table @code
6303
6304@kindex macro expand
6305@cindex macro expansion, showing the results of preprocessor
6306@cindex preprocessor macro expansion, showing the results of
6307@cindex expanding preprocessor macros
6308@item macro expand @var{expression}
6309@itemx macro exp @var{expression}
6310Show the results of expanding all preprocessor macro invocations in
6311@var{expression}. Since @value{GDBN} simply expands macros, but does
6312not parse the result, @var{expression} need not be a valid expression;
6313it can be any string of tokens.
6314
6315@kindex macro expand-once
6316@item macro expand-once @var{expression}
6317@itemx macro exp1 @var{expression}
6318@i{(This command is not yet implemented.)} Show the results of
6319expanding those preprocessor macro invocations that appear explicitly in
6320@var{expression}. Macro invocations appearing in that expansion are
6321left unchanged. This command allows you to see the effect of a
6322particular macro more clearly, without being confused by further
6323expansions. Since @value{GDBN} simply expands macros, but does not
6324parse the result, @var{expression} need not be a valid expression; it
6325can be any string of tokens.
6326
475b0867 6327@kindex info macro
e2e0bcd1
JB
6328@cindex macro definition, showing
6329@cindex definition, showing a macro's
475b0867 6330@item info macro @var{macro}
e2e0bcd1
JB
6331Show the definition of the macro named @var{macro}, and describe the
6332source location where that definition was established.
6333
6334@kindex macro define
6335@cindex user-defined macros
6336@cindex defining macros interactively
6337@cindex macros, user-defined
6338@item macro define @var{macro} @var{replacement-list}
6339@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6340@i{(This command is not yet implemented.)} Introduce a definition for a
6341preprocessor macro named @var{macro}, invocations of which are replaced
6342by the tokens given in @var{replacement-list}. The first form of this
6343command defines an ``object-like'' macro, which takes no arguments; the
6344second form defines a ``function-like'' macro, which takes the arguments
6345given in @var{arglist}.
6346
6347A definition introduced by this command is in scope in every expression
6348evaluated in @value{GDBN}, until it is removed with the @command{macro
6349undef} command, described below. The definition overrides all
6350definitions for @var{macro} present in the program being debugged, as
6351well as any previous user-supplied definition.
6352
6353@kindex macro undef
6354@item macro undef @var{macro}
6355@i{(This command is not yet implemented.)} Remove any user-supplied
6356definition for the macro named @var{macro}. This command only affects
6357definitions provided with the @command{macro define} command, described
6358above; it cannot remove definitions present in the program being
6359debugged.
6360
6361@end table
6362
6363@cindex macros, example of debugging with
6364Here is a transcript showing the above commands in action. First, we
6365show our source files:
6366
6367@smallexample
6368$ cat sample.c
6369#include <stdio.h>
6370#include "sample.h"
6371
6372#define M 42
6373#define ADD(x) (M + x)
6374
6375main ()
6376@{
6377#define N 28
6378 printf ("Hello, world!\n");
6379#undef N
6380 printf ("We're so creative.\n");
6381#define N 1729
6382 printf ("Goodbye, world!\n");
6383@}
6384$ cat sample.h
6385#define Q <
6386$
6387@end smallexample
6388
6389Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6390We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6391compiler includes information about preprocessor macros in the debugging
6392information.
6393
6394@smallexample
6395$ gcc -gdwarf-2 -g3 sample.c -o sample
6396$
6397@end smallexample
6398
6399Now, we start @value{GDBN} on our sample program:
6400
6401@smallexample
6402$ gdb -nw sample
6403GNU gdb 2002-05-06-cvs
6404Copyright 2002 Free Software Foundation, Inc.
6405GDB is free software, @dots{}
6406(gdb)
6407@end smallexample
6408
6409We can expand macros and examine their definitions, even when the
6410program is not running. @value{GDBN} uses the current listing position
6411to decide which macro definitions are in scope:
6412
6413@smallexample
6414(gdb) list main
64153
64164 #define M 42
64175 #define ADD(x) (M + x)
64186
64197 main ()
64208 @{
64219 #define N 28
642210 printf ("Hello, world!\n");
642311 #undef N
642412 printf ("We're so creative.\n");
475b0867 6425(gdb) info macro ADD
e2e0bcd1
JB
6426Defined at /home/jimb/gdb/macros/play/sample.c:5
6427#define ADD(x) (M + x)
475b0867 6428(gdb) info macro Q
e2e0bcd1
JB
6429Defined at /home/jimb/gdb/macros/play/sample.h:1
6430 included at /home/jimb/gdb/macros/play/sample.c:2
6431#define Q <
6432(gdb) macro expand ADD(1)
6433expands to: (42 + 1)
6434(gdb) macro expand-once ADD(1)
6435expands to: once (M + 1)
6436(gdb)
6437@end smallexample
6438
6439In the example above, note that @command{macro expand-once} expands only
6440the macro invocation explicit in the original text --- the invocation of
6441@code{ADD} --- but does not expand the invocation of the macro @code{M},
6442which was introduced by @code{ADD}.
6443
6444Once the program is running, GDB uses the macro definitions in force at
6445the source line of the current stack frame:
6446
6447@smallexample
6448(gdb) break main
6449Breakpoint 1 at 0x8048370: file sample.c, line 10.
6450(gdb) run
6451Starting program: /home/jimb/gdb/macros/play/sample
6452
6453Breakpoint 1, main () at sample.c:10
645410 printf ("Hello, world!\n");
6455(gdb)
6456@end smallexample
6457
6458At line 10, the definition of the macro @code{N} at line 9 is in force:
6459
6460@smallexample
475b0867 6461(gdb) info macro N
e2e0bcd1
JB
6462Defined at /home/jimb/gdb/macros/play/sample.c:9
6463#define N 28
6464(gdb) macro expand N Q M
6465expands to: 28 < 42
6466(gdb) print N Q M
6467$1 = 1
6468(gdb)
6469@end smallexample
6470
6471As we step over directives that remove @code{N}'s definition, and then
6472give it a new definition, @value{GDBN} finds the definition (or lack
6473thereof) in force at each point:
6474
6475@smallexample
6476(gdb) next
6477Hello, world!
647812 printf ("We're so creative.\n");
475b0867 6479(gdb) info macro N
e2e0bcd1
JB
6480The symbol `N' has no definition as a C/C++ preprocessor macro
6481at /home/jimb/gdb/macros/play/sample.c:12
6482(gdb) next
6483We're so creative.
648414 printf ("Goodbye, world!\n");
475b0867 6485(gdb) info macro N
e2e0bcd1
JB
6486Defined at /home/jimb/gdb/macros/play/sample.c:13
6487#define N 1729
6488(gdb) macro expand N Q M
6489expands to: 1729 < 42
6490(gdb) print N Q M
6491$2 = 0
6492(gdb)
6493@end smallexample
6494
6495
b37052ae
EZ
6496@node Tracepoints
6497@chapter Tracepoints
6498@c This chapter is based on the documentation written by Michael
6499@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
6500
6501@cindex tracepoints
6502In some applications, it is not feasible for the debugger to interrupt
6503the program's execution long enough for the developer to learn
6504anything helpful about its behavior. If the program's correctness
6505depends on its real-time behavior, delays introduced by a debugger
6506might cause the program to change its behavior drastically, or perhaps
6507fail, even when the code itself is correct. It is useful to be able
6508to observe the program's behavior without interrupting it.
6509
6510Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
6511specify locations in the program, called @dfn{tracepoints}, and
6512arbitrary expressions to evaluate when those tracepoints are reached.
6513Later, using the @code{tfind} command, you can examine the values
6514those expressions had when the program hit the tracepoints. The
6515expressions may also denote objects in memory---structures or arrays,
6516for example---whose values @value{GDBN} should record; while visiting
6517a particular tracepoint, you may inspect those objects as if they were
6518in memory at that moment. However, because @value{GDBN} records these
6519values without interacting with you, it can do so quickly and
6520unobtrusively, hopefully not disturbing the program's behavior.
6521
6522The tracepoint facility is currently available only for remote
2c0069bb
EZ
6523targets. @xref{Targets}. In addition, your remote target must know how
6524to collect trace data. This functionality is implemented in the remote
6525stub; however, none of the stubs distributed with @value{GDBN} support
6526tracepoints as of this writing.
b37052ae
EZ
6527
6528This chapter describes the tracepoint commands and features.
6529
6530@menu
6531* Set Tracepoints::
6532* Analyze Collected Data::
6533* Tracepoint Variables::
6534@end menu
6535
6536@node Set Tracepoints
6537@section Commands to Set Tracepoints
6538
6539Before running such a @dfn{trace experiment}, an arbitrary number of
6540tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
6541tracepoint has a number assigned to it by @value{GDBN}. Like with
6542breakpoints, tracepoint numbers are successive integers starting from
6543one. Many of the commands associated with tracepoints take the
6544tracepoint number as their argument, to identify which tracepoint to
6545work on.
6546
6547For each tracepoint, you can specify, in advance, some arbitrary set
6548of data that you want the target to collect in the trace buffer when
6549it hits that tracepoint. The collected data can include registers,
6550local variables, or global data. Later, you can use @value{GDBN}
6551commands to examine the values these data had at the time the
6552tracepoint was hit.
6553
6554This section describes commands to set tracepoints and associated
6555conditions and actions.
6556
6557@menu
6558* Create and Delete Tracepoints::
6559* Enable and Disable Tracepoints::
6560* Tracepoint Passcounts::
6561* Tracepoint Actions::
6562* Listing Tracepoints::
6563* Starting and Stopping Trace Experiment::
6564@end menu
6565
6566@node Create and Delete Tracepoints
6567@subsection Create and Delete Tracepoints
6568
6569@table @code
6570@cindex set tracepoint
6571@kindex trace
6572@item trace
6573The @code{trace} command is very similar to the @code{break} command.
6574Its argument can be a source line, a function name, or an address in
6575the target program. @xref{Set Breaks}. The @code{trace} command
6576defines a tracepoint, which is a point in the target program where the
6577debugger will briefly stop, collect some data, and then allow the
6578program to continue. Setting a tracepoint or changing its commands
6579doesn't take effect until the next @code{tstart} command; thus, you
6580cannot change the tracepoint attributes once a trace experiment is
6581running.
6582
6583Here are some examples of using the @code{trace} command:
6584
6585@smallexample
6586(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
6587
6588(@value{GDBP}) @b{trace +2} // 2 lines forward
6589
6590(@value{GDBP}) @b{trace my_function} // first source line of function
6591
6592(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
6593
6594(@value{GDBP}) @b{trace *0x2117c4} // an address
6595@end smallexample
6596
6597@noindent
6598You can abbreviate @code{trace} as @code{tr}.
6599
6600@vindex $tpnum
6601@cindex last tracepoint number
6602@cindex recent tracepoint number
6603@cindex tracepoint number
6604The convenience variable @code{$tpnum} records the tracepoint number
6605of the most recently set tracepoint.
6606
6607@kindex delete tracepoint
6608@cindex tracepoint deletion
6609@item delete tracepoint @r{[}@var{num}@r{]}
6610Permanently delete one or more tracepoints. With no argument, the
6611default is to delete all tracepoints.
6612
6613Examples:
6614
6615@smallexample
6616(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
6617
6618(@value{GDBP}) @b{delete trace} // remove all tracepoints
6619@end smallexample
6620
6621@noindent
6622You can abbreviate this command as @code{del tr}.
6623@end table
6624
6625@node Enable and Disable Tracepoints
6626@subsection Enable and Disable Tracepoints
6627
6628@table @code
6629@kindex disable tracepoint
6630@item disable tracepoint @r{[}@var{num}@r{]}
6631Disable tracepoint @var{num}, or all tracepoints if no argument
6632@var{num} is given. A disabled tracepoint will have no effect during
6633the next trace experiment, but it is not forgotten. You can re-enable
6634a disabled tracepoint using the @code{enable tracepoint} command.
6635
6636@kindex enable tracepoint
6637@item enable tracepoint @r{[}@var{num}@r{]}
6638Enable tracepoint @var{num}, or all tracepoints. The enabled
6639tracepoints will become effective the next time a trace experiment is
6640run.
6641@end table
6642
6643@node Tracepoint Passcounts
6644@subsection Tracepoint Passcounts
6645
6646@table @code
6647@kindex passcount
6648@cindex tracepoint pass count
6649@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
6650Set the @dfn{passcount} of a tracepoint. The passcount is a way to
6651automatically stop a trace experiment. If a tracepoint's passcount is
6652@var{n}, then the trace experiment will be automatically stopped on
6653the @var{n}'th time that tracepoint is hit. If the tracepoint number
6654@var{num} is not specified, the @code{passcount} command sets the
6655passcount of the most recently defined tracepoint. If no passcount is
6656given, the trace experiment will run until stopped explicitly by the
6657user.
6658
6659Examples:
6660
6661@smallexample
6826cf00
EZ
6662(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6663@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
6664
6665(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 6666@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
6667(@value{GDBP}) @b{trace foo}
6668(@value{GDBP}) @b{pass 3}
6669(@value{GDBP}) @b{trace bar}
6670(@value{GDBP}) @b{pass 2}
6671(@value{GDBP}) @b{trace baz}
6672(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
6673@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
6674@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
6675@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
6676@end smallexample
6677@end table
6678
6679@node Tracepoint Actions
6680@subsection Tracepoint Action Lists
6681
6682@table @code
6683@kindex actions
6684@cindex tracepoint actions
6685@item actions @r{[}@var{num}@r{]}
6686This command will prompt for a list of actions to be taken when the
6687tracepoint is hit. If the tracepoint number @var{num} is not
6688specified, this command sets the actions for the one that was most
6689recently defined (so that you can define a tracepoint and then say
6690@code{actions} without bothering about its number). You specify the
6691actions themselves on the following lines, one action at a time, and
6692terminate the actions list with a line containing just @code{end}. So
6693far, the only defined actions are @code{collect} and
6694@code{while-stepping}.
6695
6696@cindex remove actions from a tracepoint
6697To remove all actions from a tracepoint, type @samp{actions @var{num}}
6698and follow it immediately with @samp{end}.
6699
6700@smallexample
6701(@value{GDBP}) @b{collect @var{data}} // collect some data
6702
6826cf00 6703(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 6704
6826cf00 6705(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
6706@end smallexample
6707
6708In the following example, the action list begins with @code{collect}
6709commands indicating the things to be collected when the tracepoint is
6710hit. Then, in order to single-step and collect additional data
6711following the tracepoint, a @code{while-stepping} command is used,
6712followed by the list of things to be collected while stepping. The
6713@code{while-stepping} command is terminated by its own separate
6714@code{end} command. Lastly, the action list is terminated by an
6715@code{end} command.
6716
6717@smallexample
6718(@value{GDBP}) @b{trace foo}
6719(@value{GDBP}) @b{actions}
6720Enter actions for tracepoint 1, one per line:
6721> collect bar,baz
6722> collect $regs
6723> while-stepping 12
6724 > collect $fp, $sp
6725 > end
6726end
6727@end smallexample
6728
6729@kindex collect @r{(tracepoints)}
6730@item collect @var{expr1}, @var{expr2}, @dots{}
6731Collect values of the given expressions when the tracepoint is hit.
6732This command accepts a comma-separated list of any valid expressions.
6733In addition to global, static, or local variables, the following
6734special arguments are supported:
6735
6736@table @code
6737@item $regs
6738collect all registers
6739
6740@item $args
6741collect all function arguments
6742
6743@item $locals
6744collect all local variables.
6745@end table
6746
6747You can give several consecutive @code{collect} commands, each one
6748with a single argument, or one @code{collect} command with several
6749arguments separated by commas: the effect is the same.
6750
f5c37c66
EZ
6751The command @code{info scope} (@pxref{Symbols, info scope}) is
6752particularly useful for figuring out what data to collect.
6753
b37052ae
EZ
6754@kindex while-stepping @r{(tracepoints)}
6755@item while-stepping @var{n}
6756Perform @var{n} single-step traces after the tracepoint, collecting
6757new data at each step. The @code{while-stepping} command is
6758followed by the list of what to collect while stepping (followed by
6759its own @code{end} command):
6760
6761@smallexample
6762> while-stepping 12
6763 > collect $regs, myglobal
6764 > end
6765>
6766@end smallexample
6767
6768@noindent
6769You may abbreviate @code{while-stepping} as @code{ws} or
6770@code{stepping}.
6771@end table
6772
6773@node Listing Tracepoints
6774@subsection Listing Tracepoints
6775
6776@table @code
6777@kindex info tracepoints
6778@cindex information about tracepoints
6779@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 6780Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 6781a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
6782defined so far. For each tracepoint, the following information is
6783shown:
6784
6785@itemize @bullet
6786@item
6787its number
6788@item
6789whether it is enabled or disabled
6790@item
6791its address
6792@item
6793its passcount as given by the @code{passcount @var{n}} command
6794@item
6795its step count as given by the @code{while-stepping @var{n}} command
6796@item
6797where in the source files is the tracepoint set
6798@item
6799its action list as given by the @code{actions} command
6800@end itemize
6801
6802@smallexample
6803(@value{GDBP}) @b{info trace}
6804Num Enb Address PassC StepC What
68051 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
68062 y 0x0020dc64 0 0 in g_test at g_test.c:1375
68073 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
6808(@value{GDBP})
6809@end smallexample
6810
6811@noindent
6812This command can be abbreviated @code{info tp}.
6813@end table
6814
6815@node Starting and Stopping Trace Experiment
6816@subsection Starting and Stopping Trace Experiment
6817
6818@table @code
6819@kindex tstart
6820@cindex start a new trace experiment
6821@cindex collected data discarded
6822@item tstart
6823This command takes no arguments. It starts the trace experiment, and
6824begins collecting data. This has the side effect of discarding all
6825the data collected in the trace buffer during the previous trace
6826experiment.
6827
6828@kindex tstop
6829@cindex stop a running trace experiment
6830@item tstop
6831This command takes no arguments. It ends the trace experiment, and
6832stops collecting data.
6833
6834@strong{Note:} a trace experiment and data collection may stop
6835automatically if any tracepoint's passcount is reached
6836(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
6837
6838@kindex tstatus
6839@cindex status of trace data collection
6840@cindex trace experiment, status of
6841@item tstatus
6842This command displays the status of the current trace data
6843collection.
6844@end table
6845
6846Here is an example of the commands we described so far:
6847
6848@smallexample
6849(@value{GDBP}) @b{trace gdb_c_test}
6850(@value{GDBP}) @b{actions}
6851Enter actions for tracepoint #1, one per line.
6852> collect $regs,$locals,$args
6853> while-stepping 11
6854 > collect $regs
6855 > end
6856> end
6857(@value{GDBP}) @b{tstart}
6858 [time passes @dots{}]
6859(@value{GDBP}) @b{tstop}
6860@end smallexample
6861
6862
6863@node Analyze Collected Data
6864@section Using the collected data
6865
6866After the tracepoint experiment ends, you use @value{GDBN} commands
6867for examining the trace data. The basic idea is that each tracepoint
6868collects a trace @dfn{snapshot} every time it is hit and another
6869snapshot every time it single-steps. All these snapshots are
6870consecutively numbered from zero and go into a buffer, and you can
6871examine them later. The way you examine them is to @dfn{focus} on a
6872specific trace snapshot. When the remote stub is focused on a trace
6873snapshot, it will respond to all @value{GDBN} requests for memory and
6874registers by reading from the buffer which belongs to that snapshot,
6875rather than from @emph{real} memory or registers of the program being
6876debugged. This means that @strong{all} @value{GDBN} commands
6877(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
6878behave as if we were currently debugging the program state as it was
6879when the tracepoint occurred. Any requests for data that are not in
6880the buffer will fail.
6881
6882@menu
6883* tfind:: How to select a trace snapshot
6884* tdump:: How to display all data for a snapshot
6885* save-tracepoints:: How to save tracepoints for a future run
6886@end menu
6887
6888@node tfind
6889@subsection @code{tfind @var{n}}
6890
6891@kindex tfind
6892@cindex select trace snapshot
6893@cindex find trace snapshot
6894The basic command for selecting a trace snapshot from the buffer is
6895@code{tfind @var{n}}, which finds trace snapshot number @var{n},
6896counting from zero. If no argument @var{n} is given, the next
6897snapshot is selected.
6898
6899Here are the various forms of using the @code{tfind} command.
6900
6901@table @code
6902@item tfind start
6903Find the first snapshot in the buffer. This is a synonym for
6904@code{tfind 0} (since 0 is the number of the first snapshot).
6905
6906@item tfind none
6907Stop debugging trace snapshots, resume @emph{live} debugging.
6908
6909@item tfind end
6910Same as @samp{tfind none}.
6911
6912@item tfind
6913No argument means find the next trace snapshot.
6914
6915@item tfind -
6916Find the previous trace snapshot before the current one. This permits
6917retracing earlier steps.
6918
6919@item tfind tracepoint @var{num}
6920Find the next snapshot associated with tracepoint @var{num}. Search
6921proceeds forward from the last examined trace snapshot. If no
6922argument @var{num} is given, it means find the next snapshot collected
6923for the same tracepoint as the current snapshot.
6924
6925@item tfind pc @var{addr}
6926Find the next snapshot associated with the value @var{addr} of the
6927program counter. Search proceeds forward from the last examined trace
6928snapshot. If no argument @var{addr} is given, it means find the next
6929snapshot with the same value of PC as the current snapshot.
6930
6931@item tfind outside @var{addr1}, @var{addr2}
6932Find the next snapshot whose PC is outside the given range of
6933addresses.
6934
6935@item tfind range @var{addr1}, @var{addr2}
6936Find the next snapshot whose PC is between @var{addr1} and
6937@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
6938
6939@item tfind line @r{[}@var{file}:@r{]}@var{n}
6940Find the next snapshot associated with the source line @var{n}. If
6941the optional argument @var{file} is given, refer to line @var{n} in
6942that source file. Search proceeds forward from the last examined
6943trace snapshot. If no argument @var{n} is given, it means find the
6944next line other than the one currently being examined; thus saying
6945@code{tfind line} repeatedly can appear to have the same effect as
6946stepping from line to line in a @emph{live} debugging session.
6947@end table
6948
6949The default arguments for the @code{tfind} commands are specifically
6950designed to make it easy to scan through the trace buffer. For
6951instance, @code{tfind} with no argument selects the next trace
6952snapshot, and @code{tfind -} with no argument selects the previous
6953trace snapshot. So, by giving one @code{tfind} command, and then
6954simply hitting @key{RET} repeatedly you can examine all the trace
6955snapshots in order. Or, by saying @code{tfind -} and then hitting
6956@key{RET} repeatedly you can examine the snapshots in reverse order.
6957The @code{tfind line} command with no argument selects the snapshot
6958for the next source line executed. The @code{tfind pc} command with
6959no argument selects the next snapshot with the same program counter
6960(PC) as the current frame. The @code{tfind tracepoint} command with
6961no argument selects the next trace snapshot collected by the same
6962tracepoint as the current one.
6963
6964In addition to letting you scan through the trace buffer manually,
6965these commands make it easy to construct @value{GDBN} scripts that
6966scan through the trace buffer and print out whatever collected data
6967you are interested in. Thus, if we want to examine the PC, FP, and SP
6968registers from each trace frame in the buffer, we can say this:
6969
6970@smallexample
6971(@value{GDBP}) @b{tfind start}
6972(@value{GDBP}) @b{while ($trace_frame != -1)}
6973> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
6974 $trace_frame, $pc, $sp, $fp
6975> tfind
6976> end
6977
6978Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
6979Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
6980Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
6981Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
6982Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
6983Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
6984Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
6985Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
6986Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
6987Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
6988Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
6989@end smallexample
6990
6991Or, if we want to examine the variable @code{X} at each source line in
6992the buffer:
6993
6994@smallexample
6995(@value{GDBP}) @b{tfind start}
6996(@value{GDBP}) @b{while ($trace_frame != -1)}
6997> printf "Frame %d, X == %d\n", $trace_frame, X
6998> tfind line
6999> end
7000
7001Frame 0, X = 1
7002Frame 7, X = 2
7003Frame 13, X = 255
7004@end smallexample
7005
7006@node tdump
7007@subsection @code{tdump}
7008@kindex tdump
7009@cindex dump all data collected at tracepoint
7010@cindex tracepoint data, display
7011
7012This command takes no arguments. It prints all the data collected at
7013the current trace snapshot.
7014
7015@smallexample
7016(@value{GDBP}) @b{trace 444}
7017(@value{GDBP}) @b{actions}
7018Enter actions for tracepoint #2, one per line:
7019> collect $regs, $locals, $args, gdb_long_test
7020> end
7021
7022(@value{GDBP}) @b{tstart}
7023
7024(@value{GDBP}) @b{tfind line 444}
7025#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7026at gdb_test.c:444
7027444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7028
7029(@value{GDBP}) @b{tdump}
7030Data collected at tracepoint 2, trace frame 1:
7031d0 0xc4aa0085 -995491707
7032d1 0x18 24
7033d2 0x80 128
7034d3 0x33 51
7035d4 0x71aea3d 119204413
7036d5 0x22 34
7037d6 0xe0 224
7038d7 0x380035 3670069
7039a0 0x19e24a 1696330
7040a1 0x3000668 50333288
7041a2 0x100 256
7042a3 0x322000 3284992
7043a4 0x3000698 50333336
7044a5 0x1ad3cc 1758156
7045fp 0x30bf3c 0x30bf3c
7046sp 0x30bf34 0x30bf34
7047ps 0x0 0
7048pc 0x20b2c8 0x20b2c8
7049fpcontrol 0x0 0
7050fpstatus 0x0 0
7051fpiaddr 0x0 0
7052p = 0x20e5b4 "gdb-test"
7053p1 = (void *) 0x11
7054p2 = (void *) 0x22
7055p3 = (void *) 0x33
7056p4 = (void *) 0x44
7057p5 = (void *) 0x55
7058p6 = (void *) 0x66
7059gdb_long_test = 17 '\021'
7060
7061(@value{GDBP})
7062@end smallexample
7063
7064@node save-tracepoints
7065@subsection @code{save-tracepoints @var{filename}}
7066@kindex save-tracepoints
7067@cindex save tracepoints for future sessions
7068
7069This command saves all current tracepoint definitions together with
7070their actions and passcounts, into a file @file{@var{filename}}
7071suitable for use in a later debugging session. To read the saved
7072tracepoint definitions, use the @code{source} command (@pxref{Command
7073Files}).
7074
7075@node Tracepoint Variables
7076@section Convenience Variables for Tracepoints
7077@cindex tracepoint variables
7078@cindex convenience variables for tracepoints
7079
7080@table @code
7081@vindex $trace_frame
7082@item (int) $trace_frame
7083The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7084snapshot is selected.
7085
7086@vindex $tracepoint
7087@item (int) $tracepoint
7088The tracepoint for the current trace snapshot.
7089
7090@vindex $trace_line
7091@item (int) $trace_line
7092The line number for the current trace snapshot.
7093
7094@vindex $trace_file
7095@item (char []) $trace_file
7096The source file for the current trace snapshot.
7097
7098@vindex $trace_func
7099@item (char []) $trace_func
7100The name of the function containing @code{$tracepoint}.
7101@end table
7102
7103Note: @code{$trace_file} is not suitable for use in @code{printf},
7104use @code{output} instead.
7105
7106Here's a simple example of using these convenience variables for
7107stepping through all the trace snapshots and printing some of their
7108data.
7109
7110@smallexample
7111(@value{GDBP}) @b{tfind start}
7112
7113(@value{GDBP}) @b{while $trace_frame != -1}
7114> output $trace_file
7115> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7116> tfind
7117> end
7118@end smallexample
7119
df0cd8c5
JB
7120@node Overlays
7121@chapter Debugging Programs That Use Overlays
7122@cindex overlays
7123
7124If your program is too large to fit completely in your target system's
7125memory, you can sometimes use @dfn{overlays} to work around this
7126problem. @value{GDBN} provides some support for debugging programs that
7127use overlays.
7128
7129@menu
7130* How Overlays Work:: A general explanation of overlays.
7131* Overlay Commands:: Managing overlays in @value{GDBN}.
7132* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7133 mapped by asking the inferior.
7134* Overlay Sample Program:: A sample program using overlays.
7135@end menu
7136
7137@node How Overlays Work
7138@section How Overlays Work
7139@cindex mapped overlays
7140@cindex unmapped overlays
7141@cindex load address, overlay's
7142@cindex mapped address
7143@cindex overlay area
7144
7145Suppose you have a computer whose instruction address space is only 64
7146kilobytes long, but which has much more memory which can be accessed by
7147other means: special instructions, segment registers, or memory
7148management hardware, for example. Suppose further that you want to
7149adapt a program which is larger than 64 kilobytes to run on this system.
7150
7151One solution is to identify modules of your program which are relatively
7152independent, and need not call each other directly; call these modules
7153@dfn{overlays}. Separate the overlays from the main program, and place
7154their machine code in the larger memory. Place your main program in
7155instruction memory, but leave at least enough space there to hold the
7156largest overlay as well.
7157
7158Now, to call a function located in an overlay, you must first copy that
7159overlay's machine code from the large memory into the space set aside
7160for it in the instruction memory, and then jump to its entry point
7161there.
7162
c928edc0
AC
7163@c NB: In the below the mapped area's size is greater or equal to the
7164@c size of all overlays. This is intentional to remind the developer
7165@c that overlays don't necessarily need to be the same size.
7166
474c8240 7167@smallexample
df0cd8c5 7168@group
c928edc0
AC
7169 Data Instruction Larger
7170Address Space Address Space Address Space
7171+-----------+ +-----------+ +-----------+
7172| | | | | |
7173+-----------+ +-----------+ +-----------+<-- overlay 1
7174| program | | main | .----| overlay 1 | load address
7175| variables | | program | | +-----------+
7176| and heap | | | | | |
7177+-----------+ | | | +-----------+<-- overlay 2
7178| | +-----------+ | | | load address
7179+-----------+ | | | .-| overlay 2 |
7180 | | | | | |
7181 mapped --->+-----------+ | | +-----------+
7182 address | | | | | |
7183 | overlay | <-' | | |
7184 | area | <---' +-----------+<-- overlay 3
7185 | | <---. | | load address
7186 +-----------+ `--| overlay 3 |
7187 | | | |
7188 +-----------+ | |
7189 +-----------+
7190 | |
7191 +-----------+
7192
7193 @anchor{A code overlay}A code overlay
df0cd8c5 7194@end group
474c8240 7195@end smallexample
df0cd8c5 7196
c928edc0
AC
7197The diagram (@pxref{A code overlay}) shows a system with separate data
7198and instruction address spaces. To map an overlay, the program copies
7199its code from the larger address space to the instruction address space.
7200Since the overlays shown here all use the same mapped address, only one
7201may be mapped at a time. For a system with a single address space for
7202data and instructions, the diagram would be similar, except that the
7203program variables and heap would share an address space with the main
7204program and the overlay area.
df0cd8c5
JB
7205
7206An overlay loaded into instruction memory and ready for use is called a
7207@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7208instruction memory. An overlay not present (or only partially present)
7209in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7210is its address in the larger memory. The mapped address is also called
7211the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7212called the @dfn{load memory address}, or @dfn{LMA}.
7213
7214Unfortunately, overlays are not a completely transparent way to adapt a
7215program to limited instruction memory. They introduce a new set of
7216global constraints you must keep in mind as you design your program:
7217
7218@itemize @bullet
7219
7220@item
7221Before calling or returning to a function in an overlay, your program
7222must make sure that overlay is actually mapped. Otherwise, the call or
7223return will transfer control to the right address, but in the wrong
7224overlay, and your program will probably crash.
7225
7226@item
7227If the process of mapping an overlay is expensive on your system, you
7228will need to choose your overlays carefully to minimize their effect on
7229your program's performance.
7230
7231@item
7232The executable file you load onto your system must contain each
7233overlay's instructions, appearing at the overlay's load address, not its
7234mapped address. However, each overlay's instructions must be relocated
7235and its symbols defined as if the overlay were at its mapped address.
7236You can use GNU linker scripts to specify different load and relocation
7237addresses for pieces of your program; see @ref{Overlay Description,,,
7238ld.info, Using ld: the GNU linker}.
7239
7240@item
7241The procedure for loading executable files onto your system must be able
7242to load their contents into the larger address space as well as the
7243instruction and data spaces.
7244
7245@end itemize
7246
7247The overlay system described above is rather simple, and could be
7248improved in many ways:
7249
7250@itemize @bullet
7251
7252@item
7253If your system has suitable bank switch registers or memory management
7254hardware, you could use those facilities to make an overlay's load area
7255contents simply appear at their mapped address in instruction space.
7256This would probably be faster than copying the overlay to its mapped
7257area in the usual way.
7258
7259@item
7260If your overlays are small enough, you could set aside more than one
7261overlay area, and have more than one overlay mapped at a time.
7262
7263@item
7264You can use overlays to manage data, as well as instructions. In
7265general, data overlays are even less transparent to your design than
7266code overlays: whereas code overlays only require care when you call or
7267return to functions, data overlays require care every time you access
7268the data. Also, if you change the contents of a data overlay, you
7269must copy its contents back out to its load address before you can copy a
7270different data overlay into the same mapped area.
7271
7272@end itemize
7273
7274
7275@node Overlay Commands
7276@section Overlay Commands
7277
7278To use @value{GDBN}'s overlay support, each overlay in your program must
7279correspond to a separate section of the executable file. The section's
7280virtual memory address and load memory address must be the overlay's
7281mapped and load addresses. Identifying overlays with sections allows
7282@value{GDBN} to determine the appropriate address of a function or
7283variable, depending on whether the overlay is mapped or not.
7284
7285@value{GDBN}'s overlay commands all start with the word @code{overlay};
7286you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7287
7288@table @code
7289@item overlay off
7290@kindex overlay off
7291Disable @value{GDBN}'s overlay support. When overlay support is
7292disabled, @value{GDBN} assumes that all functions and variables are
7293always present at their mapped addresses. By default, @value{GDBN}'s
7294overlay support is disabled.
7295
7296@item overlay manual
7297@kindex overlay manual
7298@cindex manual overlay debugging
7299Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7300relies on you to tell it which overlays are mapped, and which are not,
7301using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7302commands described below.
7303
7304@item overlay map-overlay @var{overlay}
7305@itemx overlay map @var{overlay}
7306@kindex overlay map-overlay
7307@cindex map an overlay
7308Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7309be the name of the object file section containing the overlay. When an
7310overlay is mapped, @value{GDBN} assumes it can find the overlay's
7311functions and variables at their mapped addresses. @value{GDBN} assumes
7312that any other overlays whose mapped ranges overlap that of
7313@var{overlay} are now unmapped.
7314
7315@item overlay unmap-overlay @var{overlay}
7316@itemx overlay unmap @var{overlay}
7317@kindex overlay unmap-overlay
7318@cindex unmap an overlay
7319Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7320must be the name of the object file section containing the overlay.
7321When an overlay is unmapped, @value{GDBN} assumes it can find the
7322overlay's functions and variables at their load addresses.
7323
7324@item overlay auto
7325@kindex overlay auto
7326Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7327consults a data structure the overlay manager maintains in the inferior
7328to see which overlays are mapped. For details, see @ref{Automatic
7329Overlay Debugging}.
7330
7331@item overlay load-target
7332@itemx overlay load
7333@kindex overlay load-target
7334@cindex reloading the overlay table
7335Re-read the overlay table from the inferior. Normally, @value{GDBN}
7336re-reads the table @value{GDBN} automatically each time the inferior
7337stops, so this command should only be necessary if you have changed the
7338overlay mapping yourself using @value{GDBN}. This command is only
7339useful when using automatic overlay debugging.
7340
7341@item overlay list-overlays
7342@itemx overlay list
7343@cindex listing mapped overlays
7344Display a list of the overlays currently mapped, along with their mapped
7345addresses, load addresses, and sizes.
7346
7347@end table
7348
7349Normally, when @value{GDBN} prints a code address, it includes the name
7350of the function the address falls in:
7351
474c8240 7352@smallexample
df0cd8c5
JB
7353(gdb) print main
7354$3 = @{int ()@} 0x11a0 <main>
474c8240 7355@end smallexample
df0cd8c5
JB
7356@noindent
7357When overlay debugging is enabled, @value{GDBN} recognizes code in
7358unmapped overlays, and prints the names of unmapped functions with
7359asterisks around them. For example, if @code{foo} is a function in an
7360unmapped overlay, @value{GDBN} prints it this way:
7361
474c8240 7362@smallexample
df0cd8c5
JB
7363(gdb) overlay list
7364No sections are mapped.
7365(gdb) print foo
7366$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7367@end smallexample
df0cd8c5
JB
7368@noindent
7369When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7370name normally:
7371
474c8240 7372@smallexample
df0cd8c5
JB
7373(gdb) overlay list
7374Section .ov.foo.text, loaded at 0x100000 - 0x100034,
7375 mapped at 0x1016 - 0x104a
7376(gdb) print foo
7377$6 = @{int (int)@} 0x1016 <foo>
474c8240 7378@end smallexample
df0cd8c5
JB
7379
7380When overlay debugging is enabled, @value{GDBN} can find the correct
7381address for functions and variables in an overlay, whether or not the
7382overlay is mapped. This allows most @value{GDBN} commands, like
7383@code{break} and @code{disassemble}, to work normally, even on unmapped
7384code. However, @value{GDBN}'s breakpoint support has some limitations:
7385
7386@itemize @bullet
7387@item
7388@cindex breakpoints in overlays
7389@cindex overlays, setting breakpoints in
7390You can set breakpoints in functions in unmapped overlays, as long as
7391@value{GDBN} can write to the overlay at its load address.
7392@item
7393@value{GDBN} can not set hardware or simulator-based breakpoints in
7394unmapped overlays. However, if you set a breakpoint at the end of your
7395overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7396you are using manual overlay management), @value{GDBN} will re-set its
7397breakpoints properly.
7398@end itemize
7399
7400
7401@node Automatic Overlay Debugging
7402@section Automatic Overlay Debugging
7403@cindex automatic overlay debugging
7404
7405@value{GDBN} can automatically track which overlays are mapped and which
7406are not, given some simple co-operation from the overlay manager in the
7407inferior. If you enable automatic overlay debugging with the
7408@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7409looks in the inferior's memory for certain variables describing the
7410current state of the overlays.
7411
7412Here are the variables your overlay manager must define to support
7413@value{GDBN}'s automatic overlay debugging:
7414
7415@table @asis
7416
7417@item @code{_ovly_table}:
7418This variable must be an array of the following structures:
7419
474c8240 7420@smallexample
df0cd8c5
JB
7421struct
7422@{
7423 /* The overlay's mapped address. */
7424 unsigned long vma;
7425
7426 /* The size of the overlay, in bytes. */
7427 unsigned long size;
7428
7429 /* The overlay's load address. */
7430 unsigned long lma;
7431
7432 /* Non-zero if the overlay is currently mapped;
7433 zero otherwise. */
7434 unsigned long mapped;
7435@}
474c8240 7436@end smallexample
df0cd8c5
JB
7437
7438@item @code{_novlys}:
7439This variable must be a four-byte signed integer, holding the total
7440number of elements in @code{_ovly_table}.
7441
7442@end table
7443
7444To decide whether a particular overlay is mapped or not, @value{GDBN}
7445looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
7446@code{lma} members equal the VMA and LMA of the overlay's section in the
7447executable file. When @value{GDBN} finds a matching entry, it consults
7448the entry's @code{mapped} member to determine whether the overlay is
7449currently mapped.
7450
81d46470 7451In addition, your overlay manager may define a function called
def71bfa 7452@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
7453will silently set a breakpoint there. If the overlay manager then
7454calls this function whenever it has changed the overlay table, this
7455will enable @value{GDBN} to accurately keep track of which overlays
7456are in program memory, and update any breakpoints that may be set
7457in overlays. This will allow breakpoints to work even if the
7458overlays are kept in ROM or other non-writable memory while they
7459are not being executed.
df0cd8c5
JB
7460
7461@node Overlay Sample Program
7462@section Overlay Sample Program
7463@cindex overlay example program
7464
7465When linking a program which uses overlays, you must place the overlays
7466at their load addresses, while relocating them to run at their mapped
7467addresses. To do this, you must write a linker script (@pxref{Overlay
7468Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
7469since linker scripts are specific to a particular host system, target
7470architecture, and target memory layout, this manual cannot provide
7471portable sample code demonstrating @value{GDBN}'s overlay support.
7472
7473However, the @value{GDBN} source distribution does contain an overlaid
7474program, with linker scripts for a few systems, as part of its test
7475suite. The program consists of the following files from
7476@file{gdb/testsuite/gdb.base}:
7477
7478@table @file
7479@item overlays.c
7480The main program file.
7481@item ovlymgr.c
7482A simple overlay manager, used by @file{overlays.c}.
7483@item foo.c
7484@itemx bar.c
7485@itemx baz.c
7486@itemx grbx.c
7487Overlay modules, loaded and used by @file{overlays.c}.
7488@item d10v.ld
7489@itemx m32r.ld
7490Linker scripts for linking the test program on the @code{d10v-elf}
7491and @code{m32r-elf} targets.
7492@end table
7493
7494You can build the test program using the @code{d10v-elf} GCC
7495cross-compiler like this:
7496
474c8240 7497@smallexample
df0cd8c5
JB
7498$ d10v-elf-gcc -g -c overlays.c
7499$ d10v-elf-gcc -g -c ovlymgr.c
7500$ d10v-elf-gcc -g -c foo.c
7501$ d10v-elf-gcc -g -c bar.c
7502$ d10v-elf-gcc -g -c baz.c
7503$ d10v-elf-gcc -g -c grbx.c
7504$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
7505 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 7506@end smallexample
df0cd8c5
JB
7507
7508The build process is identical for any other architecture, except that
7509you must substitute the appropriate compiler and linker script for the
7510target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
7511
7512
6d2ebf8b 7513@node Languages
c906108c
SS
7514@chapter Using @value{GDBN} with Different Languages
7515@cindex languages
7516
c906108c
SS
7517Although programming languages generally have common aspects, they are
7518rarely expressed in the same manner. For instance, in ANSI C,
7519dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
7520Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 7521represented (and displayed) differently. Hex numbers in C appear as
c906108c 7522@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
7523
7524@cindex working language
7525Language-specific information is built into @value{GDBN} for some languages,
7526allowing you to express operations like the above in your program's
7527native language, and allowing @value{GDBN} to output values in a manner
7528consistent with the syntax of your program's native language. The
7529language you use to build expressions is called the @dfn{working
7530language}.
7531
7532@menu
7533* Setting:: Switching between source languages
7534* Show:: Displaying the language
c906108c 7535* Checks:: Type and range checks
c906108c 7536* Support:: Supported languages
4e562065 7537* Unsupported languages:: Unsupported languages
c906108c
SS
7538@end menu
7539
6d2ebf8b 7540@node Setting
c906108c
SS
7541@section Switching between source languages
7542
7543There are two ways to control the working language---either have @value{GDBN}
7544set it automatically, or select it manually yourself. You can use the
7545@code{set language} command for either purpose. On startup, @value{GDBN}
7546defaults to setting the language automatically. The working language is
7547used to determine how expressions you type are interpreted, how values
7548are printed, etc.
7549
7550In addition to the working language, every source file that
7551@value{GDBN} knows about has its own working language. For some object
7552file formats, the compiler might indicate which language a particular
7553source file is in. However, most of the time @value{GDBN} infers the
7554language from the name of the file. The language of a source file
b37052ae 7555controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 7556show each frame appropriately for its own language. There is no way to
d4f3574e
SS
7557set the language of a source file from within @value{GDBN}, but you can
7558set the language associated with a filename extension. @xref{Show, ,
7559Displaying the language}.
c906108c
SS
7560
7561This is most commonly a problem when you use a program, such
5d161b24 7562as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
7563another language. In that case, make the
7564program use @code{#line} directives in its C output; that way
7565@value{GDBN} will know the correct language of the source code of the original
7566program, and will display that source code, not the generated C code.
7567
7568@menu
7569* Filenames:: Filename extensions and languages.
7570* Manually:: Setting the working language manually
7571* Automatically:: Having @value{GDBN} infer the source language
7572@end menu
7573
6d2ebf8b 7574@node Filenames
c906108c
SS
7575@subsection List of filename extensions and languages
7576
7577If a source file name ends in one of the following extensions, then
7578@value{GDBN} infers that its language is the one indicated.
7579
7580@table @file
7581
7582@item .c
7583C source file
7584
7585@item .C
7586@itemx .cc
7587@itemx .cp
7588@itemx .cpp
7589@itemx .cxx
7590@itemx .c++
b37052ae 7591C@t{++} source file
c906108c 7592
b37303ee
AF
7593@item .m
7594Objective-C source file
7595
c906108c
SS
7596@item .f
7597@itemx .F
7598Fortran source file
7599
c906108c
SS
7600@item .mod
7601Modula-2 source file
c906108c
SS
7602
7603@item .s
7604@itemx .S
7605Assembler source file. This actually behaves almost like C, but
7606@value{GDBN} does not skip over function prologues when stepping.
7607@end table
7608
7609In addition, you may set the language associated with a filename
7610extension. @xref{Show, , Displaying the language}.
7611
6d2ebf8b 7612@node Manually
c906108c
SS
7613@subsection Setting the working language
7614
7615If you allow @value{GDBN} to set the language automatically,
7616expressions are interpreted the same way in your debugging session and
7617your program.
7618
7619@kindex set language
7620If you wish, you may set the language manually. To do this, issue the
7621command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 7622a language, such as
c906108c 7623@code{c} or @code{modula-2}.
c906108c
SS
7624For a list of the supported languages, type @samp{set language}.
7625
c906108c
SS
7626Setting the language manually prevents @value{GDBN} from updating the working
7627language automatically. This can lead to confusion if you try
7628to debug a program when the working language is not the same as the
7629source language, when an expression is acceptable to both
7630languages---but means different things. For instance, if the current
7631source file were written in C, and @value{GDBN} was parsing Modula-2, a
7632command such as:
7633
474c8240 7634@smallexample
c906108c 7635print a = b + c
474c8240 7636@end smallexample
c906108c
SS
7637
7638@noindent
7639might not have the effect you intended. In C, this means to add
7640@code{b} and @code{c} and place the result in @code{a}. The result
7641printed would be the value of @code{a}. In Modula-2, this means to compare
7642@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 7643
6d2ebf8b 7644@node Automatically
c906108c
SS
7645@subsection Having @value{GDBN} infer the source language
7646
7647To have @value{GDBN} set the working language automatically, use
7648@samp{set language local} or @samp{set language auto}. @value{GDBN}
7649then infers the working language. That is, when your program stops in a
7650frame (usually by encountering a breakpoint), @value{GDBN} sets the
7651working language to the language recorded for the function in that
7652frame. If the language for a frame is unknown (that is, if the function
7653or block corresponding to the frame was defined in a source file that
7654does not have a recognized extension), the current working language is
7655not changed, and @value{GDBN} issues a warning.
7656
7657This may not seem necessary for most programs, which are written
7658entirely in one source language. However, program modules and libraries
7659written in one source language can be used by a main program written in
7660a different source language. Using @samp{set language auto} in this
7661case frees you from having to set the working language manually.
7662
6d2ebf8b 7663@node Show
c906108c 7664@section Displaying the language
c906108c
SS
7665
7666The following commands help you find out which language is the
7667working language, and also what language source files were written in.
7668
7669@kindex show language
d4f3574e
SS
7670@kindex info frame@r{, show the source language}
7671@kindex info source@r{, show the source language}
c906108c
SS
7672@table @code
7673@item show language
7674Display the current working language. This is the
7675language you can use with commands such as @code{print} to
7676build and compute expressions that may involve variables in your program.
7677
7678@item info frame
5d161b24 7679Display the source language for this frame. This language becomes the
c906108c 7680working language if you use an identifier from this frame.
5d161b24 7681@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
7682information listed here.
7683
7684@item info source
7685Display the source language of this source file.
5d161b24 7686@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
7687information listed here.
7688@end table
7689
7690In unusual circumstances, you may have source files with extensions
7691not in the standard list. You can then set the extension associated
7692with a language explicitly:
7693
7694@kindex set extension-language
7695@kindex info extensions
7696@table @code
7697@item set extension-language @var{.ext} @var{language}
7698Set source files with extension @var{.ext} to be assumed to be in
7699the source language @var{language}.
7700
7701@item info extensions
7702List all the filename extensions and the associated languages.
7703@end table
7704
6d2ebf8b 7705@node Checks
c906108c
SS
7706@section Type and range checking
7707
7708@quotation
7709@emph{Warning:} In this release, the @value{GDBN} commands for type and range
7710checking are included, but they do not yet have any effect. This
7711section documents the intended facilities.
7712@end quotation
7713@c FIXME remove warning when type/range code added
7714
7715Some languages are designed to guard you against making seemingly common
7716errors through a series of compile- and run-time checks. These include
7717checking the type of arguments to functions and operators, and making
7718sure mathematical overflows are caught at run time. Checks such as
7719these help to ensure a program's correctness once it has been compiled
7720by eliminating type mismatches, and providing active checks for range
7721errors when your program is running.
7722
7723@value{GDBN} can check for conditions like the above if you wish.
7724Although @value{GDBN} does not check the statements in your program, it
7725can check expressions entered directly into @value{GDBN} for evaluation via
7726the @code{print} command, for example. As with the working language,
7727@value{GDBN} can also decide whether or not to check automatically based on
7728your program's source language. @xref{Support, ,Supported languages},
7729for the default settings of supported languages.
7730
7731@menu
7732* Type Checking:: An overview of type checking
7733* Range Checking:: An overview of range checking
7734@end menu
7735
7736@cindex type checking
7737@cindex checks, type
6d2ebf8b 7738@node Type Checking
c906108c
SS
7739@subsection An overview of type checking
7740
7741Some languages, such as Modula-2, are strongly typed, meaning that the
7742arguments to operators and functions have to be of the correct type,
7743otherwise an error occurs. These checks prevent type mismatch
7744errors from ever causing any run-time problems. For example,
7745
7746@smallexample
77471 + 2 @result{} 3
7748@exdent but
7749@error{} 1 + 2.3
7750@end smallexample
7751
7752The second example fails because the @code{CARDINAL} 1 is not
7753type-compatible with the @code{REAL} 2.3.
7754
5d161b24
DB
7755For the expressions you use in @value{GDBN} commands, you can tell the
7756@value{GDBN} type checker to skip checking;
7757to treat any mismatches as errors and abandon the expression;
7758or to only issue warnings when type mismatches occur,
c906108c
SS
7759but evaluate the expression anyway. When you choose the last of
7760these, @value{GDBN} evaluates expressions like the second example above, but
7761also issues a warning.
7762
5d161b24
DB
7763Even if you turn type checking off, there may be other reasons
7764related to type that prevent @value{GDBN} from evaluating an expression.
7765For instance, @value{GDBN} does not know how to add an @code{int} and
7766a @code{struct foo}. These particular type errors have nothing to do
7767with the language in use, and usually arise from expressions, such as
c906108c
SS
7768the one described above, which make little sense to evaluate anyway.
7769
7770Each language defines to what degree it is strict about type. For
7771instance, both Modula-2 and C require the arguments to arithmetical
7772operators to be numbers. In C, enumerated types and pointers can be
7773represented as numbers, so that they are valid arguments to mathematical
7774operators. @xref{Support, ,Supported languages}, for further
7775details on specific languages.
7776
7777@value{GDBN} provides some additional commands for controlling the type checker:
7778
d4f3574e 7779@kindex set check@r{, type}
c906108c
SS
7780@kindex set check type
7781@kindex show check type
7782@table @code
7783@item set check type auto
7784Set type checking on or off based on the current working language.
7785@xref{Support, ,Supported languages}, for the default settings for
7786each language.
7787
7788@item set check type on
7789@itemx set check type off
7790Set type checking on or off, overriding the default setting for the
7791current working language. Issue a warning if the setting does not
7792match the language default. If any type mismatches occur in
d4f3574e 7793evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
7794message and aborts evaluation of the expression.
7795
7796@item set check type warn
7797Cause the type checker to issue warnings, but to always attempt to
7798evaluate the expression. Evaluating the expression may still
7799be impossible for other reasons. For example, @value{GDBN} cannot add
7800numbers and structures.
7801
7802@item show type
5d161b24 7803Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
7804is setting it automatically.
7805@end table
7806
7807@cindex range checking
7808@cindex checks, range
6d2ebf8b 7809@node Range Checking
c906108c
SS
7810@subsection An overview of range checking
7811
7812In some languages (such as Modula-2), it is an error to exceed the
7813bounds of a type; this is enforced with run-time checks. Such range
7814checking is meant to ensure program correctness by making sure
7815computations do not overflow, or indices on an array element access do
7816not exceed the bounds of the array.
7817
7818For expressions you use in @value{GDBN} commands, you can tell
7819@value{GDBN} to treat range errors in one of three ways: ignore them,
7820always treat them as errors and abandon the expression, or issue
7821warnings but evaluate the expression anyway.
7822
7823A range error can result from numerical overflow, from exceeding an
7824array index bound, or when you type a constant that is not a member
7825of any type. Some languages, however, do not treat overflows as an
7826error. In many implementations of C, mathematical overflow causes the
7827result to ``wrap around'' to lower values---for example, if @var{m} is
7828the largest integer value, and @var{s} is the smallest, then
7829
474c8240 7830@smallexample
c906108c 7831@var{m} + 1 @result{} @var{s}
474c8240 7832@end smallexample
c906108c
SS
7833
7834This, too, is specific to individual languages, and in some cases
7835specific to individual compilers or machines. @xref{Support, ,
7836Supported languages}, for further details on specific languages.
7837
7838@value{GDBN} provides some additional commands for controlling the range checker:
7839
d4f3574e 7840@kindex set check@r{, range}
c906108c
SS
7841@kindex set check range
7842@kindex show check range
7843@table @code
7844@item set check range auto
7845Set range checking on or off based on the current working language.
7846@xref{Support, ,Supported languages}, for the default settings for
7847each language.
7848
7849@item set check range on
7850@itemx set check range off
7851Set range checking on or off, overriding the default setting for the
7852current working language. A warning is issued if the setting does not
c3f6f71d
JM
7853match the language default. If a range error occurs and range checking is on,
7854then a message is printed and evaluation of the expression is aborted.
c906108c
SS
7855
7856@item set check range warn
7857Output messages when the @value{GDBN} range checker detects a range error,
7858but attempt to evaluate the expression anyway. Evaluating the
7859expression may still be impossible for other reasons, such as accessing
7860memory that the process does not own (a typical example from many Unix
7861systems).
7862
7863@item show range
7864Show the current setting of the range checker, and whether or not it is
7865being set automatically by @value{GDBN}.
7866@end table
c906108c 7867
6d2ebf8b 7868@node Support
c906108c 7869@section Supported languages
c906108c 7870
b37303ee 7871@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, assembly, and Modula-2.
cce74817 7872@c This is false ...
c906108c
SS
7873Some @value{GDBN} features may be used in expressions regardless of the
7874language you use: the @value{GDBN} @code{@@} and @code{::} operators,
7875and the @samp{@{type@}addr} construct (@pxref{Expressions,
7876,Expressions}) can be used with the constructs of any supported
7877language.
7878
7879The following sections detail to what degree each source language is
7880supported by @value{GDBN}. These sections are not meant to be language
7881tutorials or references, but serve only as a reference guide to what the
7882@value{GDBN} expression parser accepts, and what input and output
7883formats should look like for different languages. There are many good
7884books written on each of these languages; please look to these for a
7885language reference or tutorial.
7886
c906108c 7887@menu
b37303ee
AF
7888* C:: C and C@t{++}
7889* Objective-C:: Objective-C
7890* Modula-2:: Modula-2
c906108c
SS
7891@end menu
7892
6d2ebf8b 7893@node C
b37052ae 7894@subsection C and C@t{++}
7a292a7a 7895
b37052ae
EZ
7896@cindex C and C@t{++}
7897@cindex expressions in C or C@t{++}
c906108c 7898
b37052ae 7899Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
7900to both languages. Whenever this is the case, we discuss those languages
7901together.
7902
41afff9a
EZ
7903@cindex C@t{++}
7904@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
7905@cindex @sc{gnu} C@t{++}
7906The C@t{++} debugging facilities are jointly implemented by the C@t{++}
7907compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
7908effectively, you must compile your C@t{++} programs with a supported
7909C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
7910compiler (@code{aCC}).
7911
0179ffac
DC
7912For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
7913format; if it doesn't work on your system, try the stabs+ debugging
7914format. You can select those formats explicitly with the @code{g++}
7915command-line options @option{-gdwarf-2} and @option{-gstabs+}.
7916@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
7917CC, gcc.info, Using @sc{gnu} CC}.
c906108c 7918
c906108c 7919@menu
b37052ae
EZ
7920* C Operators:: C and C@t{++} operators
7921* C Constants:: C and C@t{++} constants
7922* C plus plus expressions:: C@t{++} expressions
7923* C Defaults:: Default settings for C and C@t{++}
7924* C Checks:: C and C@t{++} type and range checks
c906108c 7925* Debugging C:: @value{GDBN} and C
b37052ae 7926* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 7927@end menu
c906108c 7928
6d2ebf8b 7929@node C Operators
b37052ae 7930@subsubsection C and C@t{++} operators
7a292a7a 7931
b37052ae 7932@cindex C and C@t{++} operators
c906108c
SS
7933
7934Operators must be defined on values of specific types. For instance,
7935@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 7936often defined on groups of types.
c906108c 7937
b37052ae 7938For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
7939
7940@itemize @bullet
53a5351d 7941
c906108c 7942@item
c906108c 7943@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 7944specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
7945
7946@item
d4f3574e
SS
7947@emph{Floating-point types} include @code{float}, @code{double}, and
7948@code{long double} (if supported by the target platform).
c906108c
SS
7949
7950@item
53a5351d 7951@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
7952
7953@item
7954@emph{Scalar types} include all of the above.
53a5351d 7955
c906108c
SS
7956@end itemize
7957
7958@noindent
7959The following operators are supported. They are listed here
7960in order of increasing precedence:
7961
7962@table @code
7963@item ,
7964The comma or sequencing operator. Expressions in a comma-separated list
7965are evaluated from left to right, with the result of the entire
7966expression being the last expression evaluated.
7967
7968@item =
7969Assignment. The value of an assignment expression is the value
7970assigned. Defined on scalar types.
7971
7972@item @var{op}=
7973Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
7974and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 7975@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
7976@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
7977@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
7978
7979@item ?:
7980The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
7981of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
7982integral type.
7983
7984@item ||
7985Logical @sc{or}. Defined on integral types.
7986
7987@item &&
7988Logical @sc{and}. Defined on integral types.
7989
7990@item |
7991Bitwise @sc{or}. Defined on integral types.
7992
7993@item ^
7994Bitwise exclusive-@sc{or}. Defined on integral types.
7995
7996@item &
7997Bitwise @sc{and}. Defined on integral types.
7998
7999@item ==@r{, }!=
8000Equality and inequality. Defined on scalar types. The value of these
8001expressions is 0 for false and non-zero for true.
8002
8003@item <@r{, }>@r{, }<=@r{, }>=
8004Less than, greater than, less than or equal, greater than or equal.
8005Defined on scalar types. The value of these expressions is 0 for false
8006and non-zero for true.
8007
8008@item <<@r{, }>>
8009left shift, and right shift. Defined on integral types.
8010
8011@item @@
8012The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8013
8014@item +@r{, }-
8015Addition and subtraction. Defined on integral types, floating-point types and
8016pointer types.
8017
8018@item *@r{, }/@r{, }%
8019Multiplication, division, and modulus. Multiplication and division are
8020defined on integral and floating-point types. Modulus is defined on
8021integral types.
8022
8023@item ++@r{, }--
8024Increment and decrement. When appearing before a variable, the
8025operation is performed before the variable is used in an expression;
8026when appearing after it, the variable's value is used before the
8027operation takes place.
8028
8029@item *
8030Pointer dereferencing. Defined on pointer types. Same precedence as
8031@code{++}.
8032
8033@item &
8034Address operator. Defined on variables. Same precedence as @code{++}.
8035
b37052ae
EZ
8036For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8037allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8038(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8039where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8040stored.
c906108c
SS
8041
8042@item -
8043Negative. Defined on integral and floating-point types. Same
8044precedence as @code{++}.
8045
8046@item !
8047Logical negation. Defined on integral types. Same precedence as
8048@code{++}.
8049
8050@item ~
8051Bitwise complement operator. Defined on integral types. Same precedence as
8052@code{++}.
8053
8054
8055@item .@r{, }->
8056Structure member, and pointer-to-structure member. For convenience,
8057@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8058pointer based on the stored type information.
8059Defined on @code{struct} and @code{union} data.
8060
c906108c
SS
8061@item .*@r{, }->*
8062Dereferences of pointers to members.
c906108c
SS
8063
8064@item []
8065Array indexing. @code{@var{a}[@var{i}]} is defined as
8066@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8067
8068@item ()
8069Function parameter list. Same precedence as @code{->}.
8070
c906108c 8071@item ::
b37052ae 8072C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8073and @code{class} types.
c906108c
SS
8074
8075@item ::
7a292a7a
SS
8076Doubled colons also represent the @value{GDBN} scope operator
8077(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8078above.
c906108c
SS
8079@end table
8080
c906108c
SS
8081If an operator is redefined in the user code, @value{GDBN} usually
8082attempts to invoke the redefined version instead of using the operator's
8083predefined meaning.
c906108c 8084
c906108c 8085@menu
5d161b24 8086* C Constants::
c906108c
SS
8087@end menu
8088
6d2ebf8b 8089@node C Constants
b37052ae 8090@subsubsection C and C@t{++} constants
c906108c 8091
b37052ae 8092@cindex C and C@t{++} constants
c906108c 8093
b37052ae 8094@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8095following ways:
c906108c
SS
8096
8097@itemize @bullet
8098@item
8099Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8100specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8101by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8102@samp{l}, specifying that the constant should be treated as a
8103@code{long} value.
8104
8105@item
8106Floating point constants are a sequence of digits, followed by a decimal
8107point, followed by a sequence of digits, and optionally followed by an
8108exponent. An exponent is of the form:
8109@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8110sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8111A floating-point constant may also end with a letter @samp{f} or
8112@samp{F}, specifying that the constant should be treated as being of
8113the @code{float} (as opposed to the default @code{double}) type; or with
8114a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8115constant.
c906108c
SS
8116
8117@item
8118Enumerated constants consist of enumerated identifiers, or their
8119integral equivalents.
8120
8121@item
8122Character constants are a single character surrounded by single quotes
8123(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8124(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8125be represented by a letter or by @dfn{escape sequences}, which are of
8126the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8127of the character's ordinal value; or of the form @samp{\@var{x}}, where
8128@samp{@var{x}} is a predefined special character---for example,
8129@samp{\n} for newline.
8130
8131@item
96a2c332
SS
8132String constants are a sequence of character constants surrounded by
8133double quotes (@code{"}). Any valid character constant (as described
8134above) may appear. Double quotes within the string must be preceded by
8135a backslash, so for instance @samp{"a\"b'c"} is a string of five
8136characters.
c906108c
SS
8137
8138@item
8139Pointer constants are an integral value. You can also write pointers
8140to constants using the C operator @samp{&}.
8141
8142@item
8143Array constants are comma-separated lists surrounded by braces @samp{@{}
8144and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8145integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8146and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8147@end itemize
8148
c906108c 8149@menu
5d161b24
DB
8150* C plus plus expressions::
8151* C Defaults::
8152* C Checks::
c906108c 8153
5d161b24 8154* Debugging C::
c906108c
SS
8155@end menu
8156
6d2ebf8b 8157@node C plus plus expressions
b37052ae
EZ
8158@subsubsection C@t{++} expressions
8159
8160@cindex expressions in C@t{++}
8161@value{GDBN} expression handling can interpret most C@t{++} expressions.
8162
0179ffac
DC
8163@cindex debugging C@t{++} programs
8164@cindex C@t{++} compilers
8165@cindex debug formats and C@t{++}
8166@cindex @value{NGCC} and C@t{++}
c906108c 8167@quotation
b37052ae 8168@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8169proper compiler and the proper debug format. Currently, @value{GDBN}
8170works best when debugging C@t{++} code that is compiled with
8171@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8172@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8173stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8174stabs+ as their default debug format, so you usually don't need to
8175specify a debug format explicitly. Other compilers and/or debug formats
8176are likely to work badly or not at all when using @value{GDBN} to debug
8177C@t{++} code.
c906108c 8178@end quotation
c906108c
SS
8179
8180@enumerate
8181
8182@cindex member functions
8183@item
8184Member function calls are allowed; you can use expressions like
8185
474c8240 8186@smallexample
c906108c 8187count = aml->GetOriginal(x, y)
474c8240 8188@end smallexample
c906108c 8189
41afff9a 8190@vindex this@r{, inside C@t{++} member functions}
b37052ae 8191@cindex namespace in C@t{++}
c906108c
SS
8192@item
8193While a member function is active (in the selected stack frame), your
8194expressions have the same namespace available as the member function;
8195that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8196pointer @code{this} following the same rules as C@t{++}.
c906108c 8197
c906108c 8198@cindex call overloaded functions
d4f3574e 8199@cindex overloaded functions, calling
b37052ae 8200@cindex type conversions in C@t{++}
c906108c
SS
8201@item
8202You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8203call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8204perform overload resolution involving user-defined type conversions,
8205calls to constructors, or instantiations of templates that do not exist
8206in the program. It also cannot handle ellipsis argument lists or
8207default arguments.
8208
8209It does perform integral conversions and promotions, floating-point
8210promotions, arithmetic conversions, pointer conversions, conversions of
8211class objects to base classes, and standard conversions such as those of
8212functions or arrays to pointers; it requires an exact match on the
8213number of function arguments.
8214
8215Overload resolution is always performed, unless you have specified
8216@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8217,@value{GDBN} features for C@t{++}}.
c906108c 8218
d4f3574e 8219You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8220explicit function signature to call an overloaded function, as in
8221@smallexample
8222p 'foo(char,int)'('x', 13)
8223@end smallexample
d4f3574e 8224
c906108c 8225The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8226see @ref{Completion, ,Command completion}.
c906108c 8227
c906108c
SS
8228@cindex reference declarations
8229@item
b37052ae
EZ
8230@value{GDBN} understands variables declared as C@t{++} references; you can use
8231them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8232dereferenced.
8233
8234In the parameter list shown when @value{GDBN} displays a frame, the values of
8235reference variables are not displayed (unlike other variables); this
8236avoids clutter, since references are often used for large structures.
8237The @emph{address} of a reference variable is always shown, unless
8238you have specified @samp{set print address off}.
8239
8240@item
b37052ae 8241@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8242expressions can use it just as expressions in your program do. Since
8243one scope may be defined in another, you can use @code{::} repeatedly if
8244necessary, for example in an expression like
8245@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8246resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8247debugging (@pxref{Variables, ,Program variables}).
8248@end enumerate
8249
b37052ae 8250In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8251calling virtual functions correctly, printing out virtual bases of
8252objects, calling functions in a base subobject, casting objects, and
8253invoking user-defined operators.
c906108c 8254
6d2ebf8b 8255@node C Defaults
b37052ae 8256@subsubsection C and C@t{++} defaults
7a292a7a 8257
b37052ae 8258@cindex C and C@t{++} defaults
c906108c 8259
c906108c
SS
8260If you allow @value{GDBN} to set type and range checking automatically, they
8261both default to @code{off} whenever the working language changes to
b37052ae 8262C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8263selects the working language.
c906108c
SS
8264
8265If you allow @value{GDBN} to set the language automatically, it
8266recognizes source files whose names end with @file{.c}, @file{.C}, or
8267@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8268these files, it sets the working language to C or C@t{++}.
c906108c
SS
8269@xref{Automatically, ,Having @value{GDBN} infer the source language},
8270for further details.
8271
c906108c
SS
8272@c Type checking is (a) primarily motivated by Modula-2, and (b)
8273@c unimplemented. If (b) changes, it might make sense to let this node
8274@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8275
6d2ebf8b 8276@node C Checks
b37052ae 8277@subsubsection C and C@t{++} type and range checks
7a292a7a 8278
b37052ae 8279@cindex C and C@t{++} checks
c906108c 8280
b37052ae 8281By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8282is not used. However, if you turn type checking on, @value{GDBN}
8283considers two variables type equivalent if:
8284
8285@itemize @bullet
8286@item
8287The two variables are structured and have the same structure, union, or
8288enumerated tag.
8289
8290@item
8291The two variables have the same type name, or types that have been
8292declared equivalent through @code{typedef}.
8293
8294@ignore
8295@c leaving this out because neither J Gilmore nor R Pesch understand it.
8296@c FIXME--beers?
8297@item
8298The two @code{struct}, @code{union}, or @code{enum} variables are
8299declared in the same declaration. (Note: this may not be true for all C
8300compilers.)
8301@end ignore
8302@end itemize
8303
8304Range checking, if turned on, is done on mathematical operations. Array
8305indices are not checked, since they are often used to index a pointer
8306that is not itself an array.
c906108c 8307
6d2ebf8b 8308@node Debugging C
c906108c 8309@subsubsection @value{GDBN} and C
c906108c
SS
8310
8311The @code{set print union} and @code{show print union} commands apply to
8312the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8313inside a @code{struct} or @code{class} is also printed. Otherwise, it
8314appears as @samp{@{...@}}.
c906108c
SS
8315
8316The @code{@@} operator aids in the debugging of dynamic arrays, formed
8317with pointers and a memory allocation function. @xref{Expressions,
8318,Expressions}.
8319
c906108c 8320@menu
5d161b24 8321* Debugging C plus plus::
c906108c
SS
8322@end menu
8323
6d2ebf8b 8324@node Debugging C plus plus
b37052ae 8325@subsubsection @value{GDBN} features for C@t{++}
c906108c 8326
b37052ae 8327@cindex commands for C@t{++}
7a292a7a 8328
b37052ae
EZ
8329Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8330designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8331
8332@table @code
8333@cindex break in overloaded functions
8334@item @r{breakpoint menus}
8335When you want a breakpoint in a function whose name is overloaded,
8336@value{GDBN} breakpoint menus help you specify which function definition
8337you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8338
b37052ae 8339@cindex overloading in C@t{++}
c906108c
SS
8340@item rbreak @var{regex}
8341Setting breakpoints using regular expressions is helpful for setting
8342breakpoints on overloaded functions that are not members of any special
8343classes.
8344@xref{Set Breaks, ,Setting breakpoints}.
8345
b37052ae 8346@cindex C@t{++} exception handling
c906108c
SS
8347@item catch throw
8348@itemx catch catch
b37052ae 8349Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8350Catchpoints, , Setting catchpoints}.
8351
8352@cindex inheritance
8353@item ptype @var{typename}
8354Print inheritance relationships as well as other information for type
8355@var{typename}.
8356@xref{Symbols, ,Examining the Symbol Table}.
8357
b37052ae 8358@cindex C@t{++} symbol display
c906108c
SS
8359@item set print demangle
8360@itemx show print demangle
8361@itemx set print asm-demangle
8362@itemx show print asm-demangle
b37052ae
EZ
8363Control whether C@t{++} symbols display in their source form, both when
8364displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8365@xref{Print Settings, ,Print settings}.
8366
8367@item set print object
8368@itemx show print object
8369Choose whether to print derived (actual) or declared types of objects.
8370@xref{Print Settings, ,Print settings}.
8371
8372@item set print vtbl
8373@itemx show print vtbl
8374Control the format for printing virtual function tables.
8375@xref{Print Settings, ,Print settings}.
c906108c 8376(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8377ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8378
8379@kindex set overload-resolution
d4f3574e 8380@cindex overloaded functions, overload resolution
c906108c 8381@item set overload-resolution on
b37052ae 8382Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8383is on. For overloaded functions, @value{GDBN} evaluates the arguments
8384and searches for a function whose signature matches the argument types,
b37052ae 8385using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8386expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8387message.
8388
8389@item set overload-resolution off
b37052ae 8390Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8391overloaded functions that are not class member functions, @value{GDBN}
8392chooses the first function of the specified name that it finds in the
8393symbol table, whether or not its arguments are of the correct type. For
8394overloaded functions that are class member functions, @value{GDBN}
8395searches for a function whose signature @emph{exactly} matches the
8396argument types.
c906108c
SS
8397
8398@item @r{Overloaded symbol names}
8399You can specify a particular definition of an overloaded symbol, using
b37052ae 8400the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
8401@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8402also use the @value{GDBN} command-line word completion facilities to list the
8403available choices, or to finish the type list for you.
8404@xref{Completion,, Command completion}, for details on how to do this.
8405@end table
c906108c 8406
b37303ee
AF
8407@node Objective-C
8408@subsection Objective-C
8409
8410@cindex Objective-C
8411This section provides information about some commands and command
8412options that are useful for debugging Objective-C code.
8413
8414@menu
8415* Method Names in Commands::
8416* The Print Command with Objective-C::
8417@end menu
8418
8419@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
8420@subsubsection Method Names in Commands
8421
8422The following commands have been extended to accept Objective-C method
8423names as line specifications:
8424
8425@kindex clear@r{, and Objective-C}
8426@kindex break@r{, and Objective-C}
8427@kindex info line@r{, and Objective-C}
8428@kindex jump@r{, and Objective-C}
8429@kindex list@r{, and Objective-C}
8430@itemize
8431@item @code{clear}
8432@item @code{break}
8433@item @code{info line}
8434@item @code{jump}
8435@item @code{list}
8436@end itemize
8437
8438A fully qualified Objective-C method name is specified as
8439
8440@smallexample
8441-[@var{Class} @var{methodName}]
8442@end smallexample
8443
8444where the minus sign is used to indicate an instance method and a plus
8445sign (not shown) is used to indicate a class method. The
8446class name @var{Class} and method name @var{methoName} are enclosed in
8447brackets, similar to the way messages are specified in Objective-C source
8448code. For example, to set a breakpoint at the @code{create} instance method of
8449class @code{Fruit} in the program currently being debugged, enter:
8450
8451@smallexample
8452break -[Fruit create]
8453@end smallexample
8454
8455To list ten program lines around the @code{initialize} class method,
8456enter:
8457
8458@smallexample
8459list +[NSText initialize]
8460@end smallexample
8461
8462In the current version of GDB, the plus or minus sign is required. In
8463future versions of GDB, the plus or minus sign will be optional, but you
8464can use it to narrow the search. It is also possible to specify just a
8465method name:
8466
8467@smallexample
8468break create
8469@end smallexample
8470
8471You must specify the complete method name, including any colons. If
8472your program's source files contain more than one @code{create} method,
8473you'll be presented with a numbered list of classes that implement that
8474method. Indicate your choice by number, or type @samp{0} to exit if
8475none apply.
8476
8477As another example, to clear a breakpoint established at the
8478@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
8479
8480@smallexample
8481clear -[NSWindow makeKeyAndOrderFront:]
8482@end smallexample
8483
8484@node The Print Command with Objective-C
8485@subsubsection The Print Command With Objective-C
8486
8487The print command has also been extended to accept methods. For example:
8488
8489@smallexample
8490print -[object hash]
8491@end smallexample
8492
8493@cindex print an Objective-C object description
8494will tell gdb to send the -hash message to object and print the
8495result. Also an additional command has been added, @code{print-object}
8496or @code{po} for short, which is meant to print the description of an
8497object. However, this command may only work with certain Objective-C
8498libraries that have a particular hook function, called
8499@code{_NSPrintForDebugger} defined.
8500
8501@node Modula-2, , Objective-C, Support
c906108c 8502@subsection Modula-2
7a292a7a 8503
d4f3574e 8504@cindex Modula-2, @value{GDBN} support
c906108c
SS
8505
8506The extensions made to @value{GDBN} to support Modula-2 only support
8507output from the @sc{gnu} Modula-2 compiler (which is currently being
8508developed). Other Modula-2 compilers are not currently supported, and
8509attempting to debug executables produced by them is most likely
8510to give an error as @value{GDBN} reads in the executable's symbol
8511table.
8512
8513@cindex expressions in Modula-2
8514@menu
8515* M2 Operators:: Built-in operators
8516* Built-In Func/Proc:: Built-in functions and procedures
8517* M2 Constants:: Modula-2 constants
8518* M2 Defaults:: Default settings for Modula-2
8519* Deviations:: Deviations from standard Modula-2
8520* M2 Checks:: Modula-2 type and range checks
8521* M2 Scope:: The scope operators @code{::} and @code{.}
8522* GDB/M2:: @value{GDBN} and Modula-2
8523@end menu
8524
6d2ebf8b 8525@node M2 Operators
c906108c
SS
8526@subsubsection Operators
8527@cindex Modula-2 operators
8528
8529Operators must be defined on values of specific types. For instance,
8530@code{+} is defined on numbers, but not on structures. Operators are
8531often defined on groups of types. For the purposes of Modula-2, the
8532following definitions hold:
8533
8534@itemize @bullet
8535
8536@item
8537@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
8538their subranges.
8539
8540@item
8541@emph{Character types} consist of @code{CHAR} and its subranges.
8542
8543@item
8544@emph{Floating-point types} consist of @code{REAL}.
8545
8546@item
8547@emph{Pointer types} consist of anything declared as @code{POINTER TO
8548@var{type}}.
8549
8550@item
8551@emph{Scalar types} consist of all of the above.
8552
8553@item
8554@emph{Set types} consist of @code{SET} and @code{BITSET} types.
8555
8556@item
8557@emph{Boolean types} consist of @code{BOOLEAN}.
8558@end itemize
8559
8560@noindent
8561The following operators are supported, and appear in order of
8562increasing precedence:
8563
8564@table @code
8565@item ,
8566Function argument or array index separator.
8567
8568@item :=
8569Assignment. The value of @var{var} @code{:=} @var{value} is
8570@var{value}.
8571
8572@item <@r{, }>
8573Less than, greater than on integral, floating-point, or enumerated
8574types.
8575
8576@item <=@r{, }>=
96a2c332 8577Less than or equal to, greater than or equal to
c906108c
SS
8578on integral, floating-point and enumerated types, or set inclusion on
8579set types. Same precedence as @code{<}.
8580
8581@item =@r{, }<>@r{, }#
8582Equality and two ways of expressing inequality, valid on scalar types.
8583Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
8584available for inequality, since @code{#} conflicts with the script
8585comment character.
8586
8587@item IN
8588Set membership. Defined on set types and the types of their members.
8589Same precedence as @code{<}.
8590
8591@item OR
8592Boolean disjunction. Defined on boolean types.
8593
8594@item AND@r{, }&
d4f3574e 8595Boolean conjunction. Defined on boolean types.
c906108c
SS
8596
8597@item @@
8598The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8599
8600@item +@r{, }-
8601Addition and subtraction on integral and floating-point types, or union
8602and difference on set types.
8603
8604@item *
8605Multiplication on integral and floating-point types, or set intersection
8606on set types.
8607
8608@item /
8609Division on floating-point types, or symmetric set difference on set
8610types. Same precedence as @code{*}.
8611
8612@item DIV@r{, }MOD
8613Integer division and remainder. Defined on integral types. Same
8614precedence as @code{*}.
8615
8616@item -
8617Negative. Defined on @code{INTEGER} and @code{REAL} data.
8618
8619@item ^
8620Pointer dereferencing. Defined on pointer types.
8621
8622@item NOT
8623Boolean negation. Defined on boolean types. Same precedence as
8624@code{^}.
8625
8626@item .
8627@code{RECORD} field selector. Defined on @code{RECORD} data. Same
8628precedence as @code{^}.
8629
8630@item []
8631Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
8632
8633@item ()
8634Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
8635as @code{^}.
8636
8637@item ::@r{, }.
8638@value{GDBN} and Modula-2 scope operators.
8639@end table
8640
8641@quotation
8642@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
8643treats the use of the operator @code{IN}, or the use of operators
8644@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
8645@code{<=}, and @code{>=} on sets as an error.
8646@end quotation
8647
cb51c4e0 8648
6d2ebf8b 8649@node Built-In Func/Proc
c906108c 8650@subsubsection Built-in functions and procedures
cb51c4e0 8651@cindex Modula-2 built-ins
c906108c
SS
8652
8653Modula-2 also makes available several built-in procedures and functions.
8654In describing these, the following metavariables are used:
8655
8656@table @var
8657
8658@item a
8659represents an @code{ARRAY} variable.
8660
8661@item c
8662represents a @code{CHAR} constant or variable.
8663
8664@item i
8665represents a variable or constant of integral type.
8666
8667@item m
8668represents an identifier that belongs to a set. Generally used in the
8669same function with the metavariable @var{s}. The type of @var{s} should
8670be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
8671
8672@item n
8673represents a variable or constant of integral or floating-point type.
8674
8675@item r
8676represents a variable or constant of floating-point type.
8677
8678@item t
8679represents a type.
8680
8681@item v
8682represents a variable.
8683
8684@item x
8685represents a variable or constant of one of many types. See the
8686explanation of the function for details.
8687@end table
8688
8689All Modula-2 built-in procedures also return a result, described below.
8690
8691@table @code
8692@item ABS(@var{n})
8693Returns the absolute value of @var{n}.
8694
8695@item CAP(@var{c})
8696If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 8697equivalent, otherwise it returns its argument.
c906108c
SS
8698
8699@item CHR(@var{i})
8700Returns the character whose ordinal value is @var{i}.
8701
8702@item DEC(@var{v})
c3f6f71d 8703Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
8704
8705@item DEC(@var{v},@var{i})
8706Decrements the value in the variable @var{v} by @var{i}. Returns the
8707new value.
8708
8709@item EXCL(@var{m},@var{s})
8710Removes the element @var{m} from the set @var{s}. Returns the new
8711set.
8712
8713@item FLOAT(@var{i})
8714Returns the floating point equivalent of the integer @var{i}.
8715
8716@item HIGH(@var{a})
8717Returns the index of the last member of @var{a}.
8718
8719@item INC(@var{v})
c3f6f71d 8720Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
8721
8722@item INC(@var{v},@var{i})
8723Increments the value in the variable @var{v} by @var{i}. Returns the
8724new value.
8725
8726@item INCL(@var{m},@var{s})
8727Adds the element @var{m} to the set @var{s} if it is not already
8728there. Returns the new set.
8729
8730@item MAX(@var{t})
8731Returns the maximum value of the type @var{t}.
8732
8733@item MIN(@var{t})
8734Returns the minimum value of the type @var{t}.
8735
8736@item ODD(@var{i})
8737Returns boolean TRUE if @var{i} is an odd number.
8738
8739@item ORD(@var{x})
8740Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
8741value of a character is its @sc{ascii} value (on machines supporting the
8742@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
8743integral, character and enumerated types.
8744
8745@item SIZE(@var{x})
8746Returns the size of its argument. @var{x} can be a variable or a type.
8747
8748@item TRUNC(@var{r})
8749Returns the integral part of @var{r}.
8750
8751@item VAL(@var{t},@var{i})
8752Returns the member of the type @var{t} whose ordinal value is @var{i}.
8753@end table
8754
8755@quotation
8756@emph{Warning:} Sets and their operations are not yet supported, so
8757@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
8758an error.
8759@end quotation
8760
8761@cindex Modula-2 constants
6d2ebf8b 8762@node M2 Constants
c906108c
SS
8763@subsubsection Constants
8764
8765@value{GDBN} allows you to express the constants of Modula-2 in the following
8766ways:
8767
8768@itemize @bullet
8769
8770@item
8771Integer constants are simply a sequence of digits. When used in an
8772expression, a constant is interpreted to be type-compatible with the
8773rest of the expression. Hexadecimal integers are specified by a
8774trailing @samp{H}, and octal integers by a trailing @samp{B}.
8775
8776@item
8777Floating point constants appear as a sequence of digits, followed by a
8778decimal point and another sequence of digits. An optional exponent can
8779then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
8780@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
8781digits of the floating point constant must be valid decimal (base 10)
8782digits.
8783
8784@item
8785Character constants consist of a single character enclosed by a pair of
8786like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 8787also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
8788followed by a @samp{C}.
8789
8790@item
8791String constants consist of a sequence of characters enclosed by a
8792pair of like quotes, either single (@code{'}) or double (@code{"}).
8793Escape sequences in the style of C are also allowed. @xref{C
b37052ae 8794Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
8795sequences.
8796
8797@item
8798Enumerated constants consist of an enumerated identifier.
8799
8800@item
8801Boolean constants consist of the identifiers @code{TRUE} and
8802@code{FALSE}.
8803
8804@item
8805Pointer constants consist of integral values only.
8806
8807@item
8808Set constants are not yet supported.
8809@end itemize
8810
6d2ebf8b 8811@node M2 Defaults
c906108c
SS
8812@subsubsection Modula-2 defaults
8813@cindex Modula-2 defaults
8814
8815If type and range checking are set automatically by @value{GDBN}, they
8816both default to @code{on} whenever the working language changes to
d4f3574e 8817Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
8818selected the working language.
8819
8820If you allow @value{GDBN} to set the language automatically, then entering
8821code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 8822working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
8823the language automatically}, for further details.
8824
6d2ebf8b 8825@node Deviations
c906108c
SS
8826@subsubsection Deviations from standard Modula-2
8827@cindex Modula-2, deviations from
8828
8829A few changes have been made to make Modula-2 programs easier to debug.
8830This is done primarily via loosening its type strictness:
8831
8832@itemize @bullet
8833@item
8834Unlike in standard Modula-2, pointer constants can be formed by
8835integers. This allows you to modify pointer variables during
8836debugging. (In standard Modula-2, the actual address contained in a
8837pointer variable is hidden from you; it can only be modified
8838through direct assignment to another pointer variable or expression that
8839returned a pointer.)
8840
8841@item
8842C escape sequences can be used in strings and characters to represent
8843non-printable characters. @value{GDBN} prints out strings with these
8844escape sequences embedded. Single non-printable characters are
8845printed using the @samp{CHR(@var{nnn})} format.
8846
8847@item
8848The assignment operator (@code{:=}) returns the value of its right-hand
8849argument.
8850
8851@item
8852All built-in procedures both modify @emph{and} return their argument.
8853@end itemize
8854
6d2ebf8b 8855@node M2 Checks
c906108c
SS
8856@subsubsection Modula-2 type and range checks
8857@cindex Modula-2 checks
8858
8859@quotation
8860@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
8861range checking.
8862@end quotation
8863@c FIXME remove warning when type/range checks added
8864
8865@value{GDBN} considers two Modula-2 variables type equivalent if:
8866
8867@itemize @bullet
8868@item
8869They are of types that have been declared equivalent via a @code{TYPE
8870@var{t1} = @var{t2}} statement
8871
8872@item
8873They have been declared on the same line. (Note: This is true of the
8874@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
8875@end itemize
8876
8877As long as type checking is enabled, any attempt to combine variables
8878whose types are not equivalent is an error.
8879
8880Range checking is done on all mathematical operations, assignment, array
8881index bounds, and all built-in functions and procedures.
8882
6d2ebf8b 8883@node M2 Scope
c906108c
SS
8884@subsubsection The scope operators @code{::} and @code{.}
8885@cindex scope
41afff9a 8886@cindex @code{.}, Modula-2 scope operator
c906108c
SS
8887@cindex colon, doubled as scope operator
8888@ifinfo
41afff9a 8889@vindex colon-colon@r{, in Modula-2}
c906108c
SS
8890@c Info cannot handle :: but TeX can.
8891@end ifinfo
8892@iftex
41afff9a 8893@vindex ::@r{, in Modula-2}
c906108c
SS
8894@end iftex
8895
8896There are a few subtle differences between the Modula-2 scope operator
8897(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
8898similar syntax:
8899
474c8240 8900@smallexample
c906108c
SS
8901
8902@var{module} . @var{id}
8903@var{scope} :: @var{id}
474c8240 8904@end smallexample
c906108c
SS
8905
8906@noindent
8907where @var{scope} is the name of a module or a procedure,
8908@var{module} the name of a module, and @var{id} is any declared
8909identifier within your program, except another module.
8910
8911Using the @code{::} operator makes @value{GDBN} search the scope
8912specified by @var{scope} for the identifier @var{id}. If it is not
8913found in the specified scope, then @value{GDBN} searches all scopes
8914enclosing the one specified by @var{scope}.
8915
8916Using the @code{.} operator makes @value{GDBN} search the current scope for
8917the identifier specified by @var{id} that was imported from the
8918definition module specified by @var{module}. With this operator, it is
8919an error if the identifier @var{id} was not imported from definition
8920module @var{module}, or if @var{id} is not an identifier in
8921@var{module}.
8922
6d2ebf8b 8923@node GDB/M2
c906108c
SS
8924@subsubsection @value{GDBN} and Modula-2
8925
8926Some @value{GDBN} commands have little use when debugging Modula-2 programs.
8927Five subcommands of @code{set print} and @code{show print} apply
b37052ae 8928specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 8929@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 8930apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
8931analogue in Modula-2.
8932
8933The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 8934with any language, is not useful with Modula-2. Its
c906108c 8935intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 8936created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 8937address can be specified by an integral constant, the construct
d4f3574e 8938@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
8939
8940@cindex @code{#} in Modula-2
8941In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
8942interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 8943
4e562065
JB
8944@node Unsupported languages
8945@section Unsupported languages
8946
8947@cindex unsupported languages
8948@cindex minimal language
8949In addition to the other fully-supported programming languages,
8950@value{GDBN} also provides a pseudo-language, called @code{minimal}.
8951It does not represent a real programming language, but provides a set
8952of capabilities close to what the C or assembly languages provide.
8953This should allow most simple operations to be performed while debugging
8954an application that uses a language currently not supported by @value{GDBN}.
8955
8956If the language is set to @code{auto}, @value{GDBN} will automatically
8957select this language if the current frame corresponds to an unsupported
8958language.
8959
6d2ebf8b 8960@node Symbols
c906108c
SS
8961@chapter Examining the Symbol Table
8962
d4f3574e 8963The commands described in this chapter allow you to inquire about the
c906108c
SS
8964symbols (names of variables, functions and types) defined in your
8965program. This information is inherent in the text of your program and
8966does not change as your program executes. @value{GDBN} finds it in your
8967program's symbol table, in the file indicated when you started @value{GDBN}
8968(@pxref{File Options, ,Choosing files}), or by one of the
8969file-management commands (@pxref{Files, ,Commands to specify files}).
8970
8971@cindex symbol names
8972@cindex names of symbols
8973@cindex quoting names
8974Occasionally, you may need to refer to symbols that contain unusual
8975characters, which @value{GDBN} ordinarily treats as word delimiters. The
8976most frequent case is in referring to static variables in other
8977source files (@pxref{Variables,,Program variables}). File names
8978are recorded in object files as debugging symbols, but @value{GDBN} would
8979ordinarily parse a typical file name, like @file{foo.c}, as the three words
8980@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
8981@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
8982
474c8240 8983@smallexample
c906108c 8984p 'foo.c'::x
474c8240 8985@end smallexample
c906108c
SS
8986
8987@noindent
8988looks up the value of @code{x} in the scope of the file @file{foo.c}.
8989
8990@table @code
8991@kindex info address
b37052ae 8992@cindex address of a symbol
c906108c
SS
8993@item info address @var{symbol}
8994Describe where the data for @var{symbol} is stored. For a register
8995variable, this says which register it is kept in. For a non-register
8996local variable, this prints the stack-frame offset at which the variable
8997is always stored.
8998
8999Note the contrast with @samp{print &@var{symbol}}, which does not work
9000at all for a register variable, and for a stack local variable prints
9001the exact address of the current instantiation of the variable.
9002
3d67e040 9003@kindex info symbol
b37052ae 9004@cindex symbol from address
3d67e040
EZ
9005@item info symbol @var{addr}
9006Print the name of a symbol which is stored at the address @var{addr}.
9007If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
9008nearest symbol and an offset from it:
9009
474c8240 9010@smallexample
3d67e040
EZ
9011(@value{GDBP}) info symbol 0x54320
9012_initialize_vx + 396 in section .text
474c8240 9013@end smallexample
3d67e040
EZ
9014
9015@noindent
9016This is the opposite of the @code{info address} command. You can use
9017it to find out the name of a variable or a function given its address.
9018
c906108c 9019@kindex whatis
d4f3574e
SS
9020@item whatis @var{expr}
9021Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
9022actually evaluated, and any side-effecting operations (such as
9023assignments or function calls) inside it do not take place.
9024@xref{Expressions, ,Expressions}.
9025
9026@item whatis
9027Print the data type of @code{$}, the last value in the value history.
9028
9029@kindex ptype
9030@item ptype @var{typename}
9031Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
9032the name of a type, or for C code it may have the form @samp{class
9033@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
9034@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 9035
d4f3574e 9036@item ptype @var{expr}
c906108c 9037@itemx ptype
d4f3574e 9038Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
9039differs from @code{whatis} by printing a detailed description, instead
9040of just the name of the type.
9041
9042For example, for this variable declaration:
9043
474c8240 9044@smallexample
c906108c 9045struct complex @{double real; double imag;@} v;
474c8240 9046@end smallexample
c906108c
SS
9047
9048@noindent
9049the two commands give this output:
9050
474c8240 9051@smallexample
c906108c
SS
9052@group
9053(@value{GDBP}) whatis v
9054type = struct complex
9055(@value{GDBP}) ptype v
9056type = struct complex @{
9057 double real;
9058 double imag;
9059@}
9060@end group
474c8240 9061@end smallexample
c906108c
SS
9062
9063@noindent
9064As with @code{whatis}, using @code{ptype} without an argument refers to
9065the type of @code{$}, the last value in the value history.
9066
9067@kindex info types
9068@item info types @var{regexp}
9069@itemx info types
d4f3574e 9070Print a brief description of all types whose names match @var{regexp}
c906108c
SS
9071(or all types in your program, if you supply no argument). Each
9072complete typename is matched as though it were a complete line; thus,
9073@samp{i type value} gives information on all types in your program whose
d4f3574e 9074names include the string @code{value}, but @samp{i type ^value$} gives
c906108c
SS
9075information only on types whose complete name is @code{value}.
9076
9077This command differs from @code{ptype} in two ways: first, like
9078@code{whatis}, it does not print a detailed description; second, it
9079lists all source files where a type is defined.
9080
b37052ae
EZ
9081@kindex info scope
9082@cindex local variables
9083@item info scope @var{addr}
9084List all the variables local to a particular scope. This command
9085accepts a location---a function name, a source line, or an address
9086preceded by a @samp{*}, and prints all the variables local to the
9087scope defined by that location. For example:
9088
9089@smallexample
9090(@value{GDBP}) @b{info scope command_line_handler}
9091Scope for command_line_handler:
9092Symbol rl is an argument at stack/frame offset 8, length 4.
9093Symbol linebuffer is in static storage at address 0x150a18, length 4.
9094Symbol linelength is in static storage at address 0x150a1c, length 4.
9095Symbol p is a local variable in register $esi, length 4.
9096Symbol p1 is a local variable in register $ebx, length 4.
9097Symbol nline is a local variable in register $edx, length 4.
9098Symbol repeat is a local variable at frame offset -8, length 4.
9099@end smallexample
9100
f5c37c66
EZ
9101@noindent
9102This command is especially useful for determining what data to collect
9103during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
9104collect}.
9105
c906108c
SS
9106@kindex info source
9107@item info source
919d772c
JB
9108Show information about the current source file---that is, the source file for
9109the function containing the current point of execution:
9110@itemize @bullet
9111@item
9112the name of the source file, and the directory containing it,
9113@item
9114the directory it was compiled in,
9115@item
9116its length, in lines,
9117@item
9118which programming language it is written in,
9119@item
9120whether the executable includes debugging information for that file, and
9121if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
9122@item
9123whether the debugging information includes information about
9124preprocessor macros.
9125@end itemize
9126
c906108c
SS
9127
9128@kindex info sources
9129@item info sources
9130Print the names of all source files in your program for which there is
9131debugging information, organized into two lists: files whose symbols
9132have already been read, and files whose symbols will be read when needed.
9133
9134@kindex info functions
9135@item info functions
9136Print the names and data types of all defined functions.
9137
9138@item info functions @var{regexp}
9139Print the names and data types of all defined functions
9140whose names contain a match for regular expression @var{regexp}.
9141Thus, @samp{info fun step} finds all functions whose names
9142include @code{step}; @samp{info fun ^step} finds those whose names
1c5dfdad
MS
9143start with @code{step}. If a function name contains characters
9144that conflict with the regular expression language (eg.
9145@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
9146
9147@kindex info variables
9148@item info variables
9149Print the names and data types of all variables that are declared
6ca652b0 9150outside of functions (i.e.@: excluding local variables).
c906108c
SS
9151
9152@item info variables @var{regexp}
9153Print the names and data types of all variables (except for local
9154variables) whose names contain a match for regular expression
9155@var{regexp}.
9156
b37303ee
AF
9157@kindex info classes
9158@item info classes
9159@itemx info classes @var{regexp}
9160Display all Objective-C classes in your program, or
9161(with the @var{regexp} argument) all those matching a particular regular
9162expression.
9163
9164@kindex info selectors
9165@item info selectors
9166@itemx info selectors @var{regexp}
9167Display all Objective-C selectors in your program, or
9168(with the @var{regexp} argument) all those matching a particular regular
9169expression.
9170
c906108c
SS
9171@ignore
9172This was never implemented.
9173@kindex info methods
9174@item info methods
9175@itemx info methods @var{regexp}
9176The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
9177methods within C@t{++} program, or (with the @var{regexp} argument) a
9178specific set of methods found in the various C@t{++} classes. Many
9179C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
9180from the @code{ptype} command can be overwhelming and hard to use. The
9181@code{info-methods} command filters the methods, printing only those
9182which match the regular-expression @var{regexp}.
9183@end ignore
9184
c906108c
SS
9185@cindex reloading symbols
9186Some systems allow individual object files that make up your program to
7a292a7a
SS
9187be replaced without stopping and restarting your program. For example,
9188in VxWorks you can simply recompile a defective object file and keep on
9189running. If you are running on one of these systems, you can allow
9190@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
9191
9192@table @code
9193@kindex set symbol-reloading
9194@item set symbol-reloading on
9195Replace symbol definitions for the corresponding source file when an
9196object file with a particular name is seen again.
9197
9198@item set symbol-reloading off
6d2ebf8b
SS
9199Do not replace symbol definitions when encountering object files of the
9200same name more than once. This is the default state; if you are not
9201running on a system that permits automatic relinking of modules, you
9202should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
9203may discard symbols when linking large programs, that may contain
9204several modules (from different directories or libraries) with the same
9205name.
c906108c
SS
9206
9207@kindex show symbol-reloading
9208@item show symbol-reloading
9209Show the current @code{on} or @code{off} setting.
9210@end table
c906108c 9211
c906108c
SS
9212@kindex set opaque-type-resolution
9213@item set opaque-type-resolution on
9214Tell @value{GDBN} to resolve opaque types. An opaque type is a type
9215declared as a pointer to a @code{struct}, @code{class}, or
9216@code{union}---for example, @code{struct MyType *}---that is used in one
9217source file although the full declaration of @code{struct MyType} is in
9218another source file. The default is on.
9219
9220A change in the setting of this subcommand will not take effect until
9221the next time symbols for a file are loaded.
9222
9223@item set opaque-type-resolution off
9224Tell @value{GDBN} not to resolve opaque types. In this case, the type
9225is printed as follows:
9226@smallexample
9227@{<no data fields>@}
9228@end smallexample
9229
9230@kindex show opaque-type-resolution
9231@item show opaque-type-resolution
9232Show whether opaque types are resolved or not.
c906108c
SS
9233
9234@kindex maint print symbols
9235@cindex symbol dump
9236@kindex maint print psymbols
9237@cindex partial symbol dump
9238@item maint print symbols @var{filename}
9239@itemx maint print psymbols @var{filename}
9240@itemx maint print msymbols @var{filename}
9241Write a dump of debugging symbol data into the file @var{filename}.
9242These commands are used to debug the @value{GDBN} symbol-reading code. Only
9243symbols with debugging data are included. If you use @samp{maint print
9244symbols}, @value{GDBN} includes all the symbols for which it has already
9245collected full details: that is, @var{filename} reflects symbols for
9246only those files whose symbols @value{GDBN} has read. You can use the
9247command @code{info sources} to find out which files these are. If you
9248use @samp{maint print psymbols} instead, the dump shows information about
9249symbols that @value{GDBN} only knows partially---that is, symbols defined in
9250files that @value{GDBN} has skimmed, but not yet read completely. Finally,
9251@samp{maint print msymbols} dumps just the minimal symbol information
9252required for each object file from which @value{GDBN} has read some symbols.
9253@xref{Files, ,Commands to specify files}, for a discussion of how
9254@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 9255
5e7b2f39
JB
9256@kindex maint info symtabs
9257@kindex maint info psymtabs
44ea7b70
JB
9258@cindex listing @value{GDBN}'s internal symbol tables
9259@cindex symbol tables, listing @value{GDBN}'s internal
9260@cindex full symbol tables, listing @value{GDBN}'s internal
9261@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
9262@item maint info symtabs @r{[} @var{regexp} @r{]}
9263@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
9264
9265List the @code{struct symtab} or @code{struct partial_symtab}
9266structures whose names match @var{regexp}. If @var{regexp} is not
9267given, list them all. The output includes expressions which you can
9268copy into a @value{GDBN} debugging this one to examine a particular
9269structure in more detail. For example:
9270
9271@smallexample
5e7b2f39 9272(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
9273@{ objfile /home/gnu/build/gdb/gdb
9274 ((struct objfile *) 0x82e69d0)
9275 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
9276 ((struct partial_symtab *) 0x8474b10)
9277 readin no
9278 fullname (null)
9279 text addresses 0x814d3c8 -- 0x8158074
9280 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
9281 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
9282 dependencies (none)
9283 @}
9284@}
5e7b2f39 9285(@value{GDBP}) maint info symtabs
44ea7b70
JB
9286(@value{GDBP})
9287@end smallexample
9288@noindent
9289We see that there is one partial symbol table whose filename contains
9290the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
9291and we see that @value{GDBN} has not read in any symtabs yet at all.
9292If we set a breakpoint on a function, that will cause @value{GDBN} to
9293read the symtab for the compilation unit containing that function:
9294
9295@smallexample
9296(@value{GDBP}) break dwarf2_psymtab_to_symtab
9297Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
9298line 1574.
5e7b2f39 9299(@value{GDBP}) maint info symtabs
44ea7b70
JB
9300@{ objfile /home/gnu/build/gdb/gdb
9301 ((struct objfile *) 0x82e69d0)
9302 @{ symtab /home/gnu/src/gdb/dwarf2read.c
9303 ((struct symtab *) 0x86c1f38)
9304 dirname (null)
9305 fullname (null)
9306 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
9307 debugformat DWARF 2
9308 @}
9309@}
9310(@value{GDBP})
9311@end smallexample
c906108c
SS
9312@end table
9313
44ea7b70 9314
6d2ebf8b 9315@node Altering
c906108c
SS
9316@chapter Altering Execution
9317
9318Once you think you have found an error in your program, you might want to
9319find out for certain whether correcting the apparent error would lead to
9320correct results in the rest of the run. You can find the answer by
9321experiment, using the @value{GDBN} features for altering execution of the
9322program.
9323
9324For example, you can store new values into variables or memory
7a292a7a
SS
9325locations, give your program a signal, restart it at a different
9326address, or even return prematurely from a function.
c906108c
SS
9327
9328@menu
9329* Assignment:: Assignment to variables
9330* Jumping:: Continuing at a different address
c906108c 9331* Signaling:: Giving your program a signal
c906108c
SS
9332* Returning:: Returning from a function
9333* Calling:: Calling your program's functions
9334* Patching:: Patching your program
9335@end menu
9336
6d2ebf8b 9337@node Assignment
c906108c
SS
9338@section Assignment to variables
9339
9340@cindex assignment
9341@cindex setting variables
9342To alter the value of a variable, evaluate an assignment expression.
9343@xref{Expressions, ,Expressions}. For example,
9344
474c8240 9345@smallexample
c906108c 9346print x=4
474c8240 9347@end smallexample
c906108c
SS
9348
9349@noindent
9350stores the value 4 into the variable @code{x}, and then prints the
5d161b24 9351value of the assignment expression (which is 4).
c906108c
SS
9352@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
9353information on operators in supported languages.
c906108c
SS
9354
9355@kindex set variable
9356@cindex variables, setting
9357If you are not interested in seeing the value of the assignment, use the
9358@code{set} command instead of the @code{print} command. @code{set} is
9359really the same as @code{print} except that the expression's value is
9360not printed and is not put in the value history (@pxref{Value History,
9361,Value history}). The expression is evaluated only for its effects.
9362
c906108c
SS
9363If the beginning of the argument string of the @code{set} command
9364appears identical to a @code{set} subcommand, use the @code{set
9365variable} command instead of just @code{set}. This command is identical
9366to @code{set} except for its lack of subcommands. For example, if your
9367program has a variable @code{width}, you get an error if you try to set
9368a new value with just @samp{set width=13}, because @value{GDBN} has the
9369command @code{set width}:
9370
474c8240 9371@smallexample
c906108c
SS
9372(@value{GDBP}) whatis width
9373type = double
9374(@value{GDBP}) p width
9375$4 = 13
9376(@value{GDBP}) set width=47
9377Invalid syntax in expression.
474c8240 9378@end smallexample
c906108c
SS
9379
9380@noindent
9381The invalid expression, of course, is @samp{=47}. In
9382order to actually set the program's variable @code{width}, use
9383
474c8240 9384@smallexample
c906108c 9385(@value{GDBP}) set var width=47
474c8240 9386@end smallexample
53a5351d 9387
c906108c
SS
9388Because the @code{set} command has many subcommands that can conflict
9389with the names of program variables, it is a good idea to use the
9390@code{set variable} command instead of just @code{set}. For example, if
9391your program has a variable @code{g}, you run into problems if you try
9392to set a new value with just @samp{set g=4}, because @value{GDBN} has
9393the command @code{set gnutarget}, abbreviated @code{set g}:
9394
474c8240 9395@smallexample
c906108c
SS
9396@group
9397(@value{GDBP}) whatis g
9398type = double
9399(@value{GDBP}) p g
9400$1 = 1
9401(@value{GDBP}) set g=4
2df3850c 9402(@value{GDBP}) p g
c906108c
SS
9403$2 = 1
9404(@value{GDBP}) r
9405The program being debugged has been started already.
9406Start it from the beginning? (y or n) y
9407Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
9408"/home/smith/cc_progs/a.out": can't open to read symbols:
9409 Invalid bfd target.
c906108c
SS
9410(@value{GDBP}) show g
9411The current BFD target is "=4".
9412@end group
474c8240 9413@end smallexample
c906108c
SS
9414
9415@noindent
9416The program variable @code{g} did not change, and you silently set the
9417@code{gnutarget} to an invalid value. In order to set the variable
9418@code{g}, use
9419
474c8240 9420@smallexample
c906108c 9421(@value{GDBP}) set var g=4
474c8240 9422@end smallexample
c906108c
SS
9423
9424@value{GDBN} allows more implicit conversions in assignments than C; you can
9425freely store an integer value into a pointer variable or vice versa,
9426and you can convert any structure to any other structure that is the
9427same length or shorter.
9428@comment FIXME: how do structs align/pad in these conversions?
9429@comment /doc@cygnus.com 18dec1990
9430
9431To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
9432construct to generate a value of specified type at a specified address
9433(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
9434to memory location @code{0x83040} as an integer (which implies a certain size
9435and representation in memory), and
9436
474c8240 9437@smallexample
c906108c 9438set @{int@}0x83040 = 4
474c8240 9439@end smallexample
c906108c
SS
9440
9441@noindent
9442stores the value 4 into that memory location.
9443
6d2ebf8b 9444@node Jumping
c906108c
SS
9445@section Continuing at a different address
9446
9447Ordinarily, when you continue your program, you do so at the place where
9448it stopped, with the @code{continue} command. You can instead continue at
9449an address of your own choosing, with the following commands:
9450
9451@table @code
9452@kindex jump
9453@item jump @var{linespec}
9454Resume execution at line @var{linespec}. Execution stops again
9455immediately if there is a breakpoint there. @xref{List, ,Printing
9456source lines}, for a description of the different forms of
9457@var{linespec}. It is common practice to use the @code{tbreak} command
9458in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
9459breakpoints}.
9460
9461The @code{jump} command does not change the current stack frame, or
9462the stack pointer, or the contents of any memory location or any
9463register other than the program counter. If line @var{linespec} is in
9464a different function from the one currently executing, the results may
9465be bizarre if the two functions expect different patterns of arguments or
9466of local variables. For this reason, the @code{jump} command requests
9467confirmation if the specified line is not in the function currently
9468executing. However, even bizarre results are predictable if you are
9469well acquainted with the machine-language code of your program.
9470
9471@item jump *@var{address}
9472Resume execution at the instruction at address @var{address}.
9473@end table
9474
c906108c 9475@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
9476On many systems, you can get much the same effect as the @code{jump}
9477command by storing a new value into the register @code{$pc}. The
9478difference is that this does not start your program running; it only
9479changes the address of where it @emph{will} run when you continue. For
9480example,
c906108c 9481
474c8240 9482@smallexample
c906108c 9483set $pc = 0x485
474c8240 9484@end smallexample
c906108c
SS
9485
9486@noindent
9487makes the next @code{continue} command or stepping command execute at
9488address @code{0x485}, rather than at the address where your program stopped.
9489@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
9490
9491The most common occasion to use the @code{jump} command is to back
9492up---perhaps with more breakpoints set---over a portion of a program
9493that has already executed, in order to examine its execution in more
9494detail.
9495
c906108c 9496@c @group
6d2ebf8b 9497@node Signaling
c906108c
SS
9498@section Giving your program a signal
9499
9500@table @code
9501@kindex signal
9502@item signal @var{signal}
9503Resume execution where your program stopped, but immediately give it the
9504signal @var{signal}. @var{signal} can be the name or the number of a
9505signal. For example, on many systems @code{signal 2} and @code{signal
9506SIGINT} are both ways of sending an interrupt signal.
9507
9508Alternatively, if @var{signal} is zero, continue execution without
9509giving a signal. This is useful when your program stopped on account of
9510a signal and would ordinary see the signal when resumed with the
9511@code{continue} command; @samp{signal 0} causes it to resume without a
9512signal.
9513
9514@code{signal} does not repeat when you press @key{RET} a second time
9515after executing the command.
9516@end table
9517@c @end group
9518
9519Invoking the @code{signal} command is not the same as invoking the
9520@code{kill} utility from the shell. Sending a signal with @code{kill}
9521causes @value{GDBN} to decide what to do with the signal depending on
9522the signal handling tables (@pxref{Signals}). The @code{signal} command
9523passes the signal directly to your program.
9524
c906108c 9525
6d2ebf8b 9526@node Returning
c906108c
SS
9527@section Returning from a function
9528
9529@table @code
9530@cindex returning from a function
9531@kindex return
9532@item return
9533@itemx return @var{expression}
9534You can cancel execution of a function call with the @code{return}
9535command. If you give an
9536@var{expression} argument, its value is used as the function's return
9537value.
9538@end table
9539
9540When you use @code{return}, @value{GDBN} discards the selected stack frame
9541(and all frames within it). You can think of this as making the
9542discarded frame return prematurely. If you wish to specify a value to
9543be returned, give that value as the argument to @code{return}.
9544
9545This pops the selected stack frame (@pxref{Selection, ,Selecting a
9546frame}), and any other frames inside of it, leaving its caller as the
9547innermost remaining frame. That frame becomes selected. The
9548specified value is stored in the registers used for returning values
9549of functions.
9550
9551The @code{return} command does not resume execution; it leaves the
9552program stopped in the state that would exist if the function had just
9553returned. In contrast, the @code{finish} command (@pxref{Continuing
9554and Stepping, ,Continuing and stepping}) resumes execution until the
9555selected stack frame returns naturally.
9556
6d2ebf8b 9557@node Calling
c906108c
SS
9558@section Calling program functions
9559
9560@cindex calling functions
9561@kindex call
9562@table @code
9563@item call @var{expr}
9564Evaluate the expression @var{expr} without displaying @code{void}
9565returned values.
9566@end table
9567
9568You can use this variant of the @code{print} command if you want to
9569execute a function from your program, but without cluttering the output
5d161b24
DB
9570with @code{void} returned values. If the result is not void, it
9571is printed and saved in the value history.
c906108c 9572
6d2ebf8b 9573@node Patching
c906108c 9574@section Patching programs
7a292a7a 9575
c906108c
SS
9576@cindex patching binaries
9577@cindex writing into executables
c906108c 9578@cindex writing into corefiles
c906108c 9579
7a292a7a
SS
9580By default, @value{GDBN} opens the file containing your program's
9581executable code (or the corefile) read-only. This prevents accidental
9582alterations to machine code; but it also prevents you from intentionally
9583patching your program's binary.
c906108c
SS
9584
9585If you'd like to be able to patch the binary, you can specify that
9586explicitly with the @code{set write} command. For example, you might
9587want to turn on internal debugging flags, or even to make emergency
9588repairs.
9589
9590@table @code
9591@kindex set write
9592@item set write on
9593@itemx set write off
7a292a7a
SS
9594If you specify @samp{set write on}, @value{GDBN} opens executable and
9595core files for both reading and writing; if you specify @samp{set write
c906108c
SS
9596off} (the default), @value{GDBN} opens them read-only.
9597
9598If you have already loaded a file, you must load it again (using the
7a292a7a
SS
9599@code{exec-file} or @code{core-file} command) after changing @code{set
9600write}, for your new setting to take effect.
c906108c
SS
9601
9602@item show write
9603@kindex show write
7a292a7a
SS
9604Display whether executable files and core files are opened for writing
9605as well as reading.
c906108c
SS
9606@end table
9607
6d2ebf8b 9608@node GDB Files
c906108c
SS
9609@chapter @value{GDBN} Files
9610
7a292a7a
SS
9611@value{GDBN} needs to know the file name of the program to be debugged,
9612both in order to read its symbol table and in order to start your
9613program. To debug a core dump of a previous run, you must also tell
9614@value{GDBN} the name of the core dump file.
c906108c
SS
9615
9616@menu
9617* Files:: Commands to specify files
5b5d99cf 9618* Separate Debug Files:: Debugging information in separate files
c906108c
SS
9619* Symbol Errors:: Errors reading symbol files
9620@end menu
9621
6d2ebf8b 9622@node Files
c906108c 9623@section Commands to specify files
c906108c 9624
7a292a7a 9625@cindex symbol table
c906108c 9626@cindex core dump file
7a292a7a
SS
9627
9628You may want to specify executable and core dump file names. The usual
9629way to do this is at start-up time, using the arguments to
9630@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
9631Out of @value{GDBN}}).
c906108c
SS
9632
9633Occasionally it is necessary to change to a different file during a
9634@value{GDBN} session. Or you may run @value{GDBN} and forget to specify
9635a file you want to use. In these situations the @value{GDBN} commands
9636to specify new files are useful.
9637
9638@table @code
9639@cindex executable file
9640@kindex file
9641@item file @var{filename}
9642Use @var{filename} as the program to be debugged. It is read for its
9643symbols and for the contents of pure memory. It is also the program
9644executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
9645directory and the file is not found in the @value{GDBN} working directory,
9646@value{GDBN} uses the environment variable @code{PATH} as a list of
9647directories to search, just as the shell does when looking for a program
9648to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
9649and your program, using the @code{path} command.
9650
6d2ebf8b 9651On systems with memory-mapped files, an auxiliary file named
c906108c
SS
9652@file{@var{filename}.syms} may hold symbol table information for
9653@var{filename}. If so, @value{GDBN} maps in the symbol table from
9654@file{@var{filename}.syms}, starting up more quickly. See the
9655descriptions of the file options @samp{-mapped} and @samp{-readnow}
9656(available on the command line, and with the commands @code{file},
5d161b24 9657@code{symbol-file}, or @code{add-symbol-file}, described below),
c906108c 9658for more information.
c906108c
SS
9659
9660@item file
9661@code{file} with no argument makes @value{GDBN} discard any information it
9662has on both executable file and the symbol table.
9663
9664@kindex exec-file
9665@item exec-file @r{[} @var{filename} @r{]}
9666Specify that the program to be run (but not the symbol table) is found
9667in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
9668if necessary to locate your program. Omitting @var{filename} means to
9669discard information on the executable file.
9670
9671@kindex symbol-file
9672@item symbol-file @r{[} @var{filename} @r{]}
9673Read symbol table information from file @var{filename}. @code{PATH} is
9674searched when necessary. Use the @code{file} command to get both symbol
9675table and program to run from the same file.
9676
9677@code{symbol-file} with no argument clears out @value{GDBN} information on your
9678program's symbol table.
9679
5d161b24 9680The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
9681of its convenience variables, the value history, and all breakpoints and
9682auto-display expressions. This is because they may contain pointers to
9683the internal data recording symbols and data types, which are part of
9684the old symbol table data being discarded inside @value{GDBN}.
9685
9686@code{symbol-file} does not repeat if you press @key{RET} again after
9687executing it once.
9688
9689When @value{GDBN} is configured for a particular environment, it
9690understands debugging information in whatever format is the standard
9691generated for that environment; you may use either a @sc{gnu} compiler, or
9692other compilers that adhere to the local conventions.
c906108c
SS
9693Best results are usually obtained from @sc{gnu} compilers; for example,
9694using @code{@value{GCC}} you can generate debugging information for
9695optimized code.
c906108c
SS
9696
9697For most kinds of object files, with the exception of old SVR3 systems
9698using COFF, the @code{symbol-file} command does not normally read the
9699symbol table in full right away. Instead, it scans the symbol table
9700quickly to find which source files and which symbols are present. The
9701details are read later, one source file at a time, as they are needed.
9702
9703The purpose of this two-stage reading strategy is to make @value{GDBN}
9704start up faster. For the most part, it is invisible except for
9705occasional pauses while the symbol table details for a particular source
9706file are being read. (The @code{set verbose} command can turn these
9707pauses into messages if desired. @xref{Messages/Warnings, ,Optional
9708warnings and messages}.)
9709
c906108c
SS
9710We have not implemented the two-stage strategy for COFF yet. When the
9711symbol table is stored in COFF format, @code{symbol-file} reads the
9712symbol table data in full right away. Note that ``stabs-in-COFF''
9713still does the two-stage strategy, since the debug info is actually
9714in stabs format.
9715
9716@kindex readnow
9717@cindex reading symbols immediately
9718@cindex symbols, reading immediately
9719@kindex mapped
9720@cindex memory-mapped symbol file
9721@cindex saving symbol table
9722@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
9723@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
9724You can override the @value{GDBN} two-stage strategy for reading symbol
9725tables by using the @samp{-readnow} option with any of the commands that
9726load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 9727entire symbol table available.
c906108c 9728
c906108c
SS
9729If memory-mapped files are available on your system through the
9730@code{mmap} system call, you can use another option, @samp{-mapped}, to
9731cause @value{GDBN} to write the symbols for your program into a reusable
9732file. Future @value{GDBN} debugging sessions map in symbol information
9733from this auxiliary symbol file (if the program has not changed), rather
9734than spending time reading the symbol table from the executable
9735program. Using the @samp{-mapped} option has the same effect as
9736starting @value{GDBN} with the @samp{-mapped} command-line option.
9737
9738You can use both options together, to make sure the auxiliary symbol
9739file has all the symbol information for your program.
9740
9741The auxiliary symbol file for a program called @var{myprog} is called
9742@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
9743than the corresponding executable), @value{GDBN} always attempts to use
9744it when you debug @var{myprog}; no special options or commands are
9745needed.
9746
9747The @file{.syms} file is specific to the host machine where you run
9748@value{GDBN}. It holds an exact image of the internal @value{GDBN}
9749symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
9750
9751@c FIXME: for now no mention of directories, since this seems to be in
9752@c flux. 13mar1992 status is that in theory GDB would look either in
9753@c current dir or in same dir as myprog; but issues like competing
9754@c GDB's, or clutter in system dirs, mean that in practice right now
9755@c only current dir is used. FFish says maybe a special GDB hierarchy
9756@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
9757@c files.
9758
9759@kindex core
9760@kindex core-file
9761@item core-file @r{[} @var{filename} @r{]}
9762Specify the whereabouts of a core dump file to be used as the ``contents
9763of memory''. Traditionally, core files contain only some parts of the
9764address space of the process that generated them; @value{GDBN} can access the
9765executable file itself for other parts.
9766
9767@code{core-file} with no argument specifies that no core file is
9768to be used.
9769
9770Note that the core file is ignored when your program is actually running
7a292a7a
SS
9771under @value{GDBN}. So, if you have been running your program and you
9772wish to debug a core file instead, you must kill the subprocess in which
9773the program is running. To do this, use the @code{kill} command
c906108c 9774(@pxref{Kill Process, ,Killing the child process}).
c906108c 9775
c906108c
SS
9776@kindex add-symbol-file
9777@cindex dynamic linking
9778@item add-symbol-file @var{filename} @var{address}
9779@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
17d9d558 9780@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
9781The @code{add-symbol-file} command reads additional symbol table
9782information from the file @var{filename}. You would use this command
9783when @var{filename} has been dynamically loaded (by some other means)
9784into the program that is running. @var{address} should be the memory
9785address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
9786this out for itself. You can additionally specify an arbitrary number
9787of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
9788section name and base address for that section. You can specify any
9789@var{address} as an expression.
c906108c
SS
9790
9791The symbol table of the file @var{filename} is added to the symbol table
9792originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
9793@code{add-symbol-file} command any number of times; the new symbol data
9794thus read keeps adding to the old. To discard all old symbol data
9795instead, use the @code{symbol-file} command without any arguments.
c906108c 9796
17d9d558
JB
9797@cindex relocatable object files, reading symbols from
9798@cindex object files, relocatable, reading symbols from
9799@cindex reading symbols from relocatable object files
9800@cindex symbols, reading from relocatable object files
9801@cindex @file{.o} files, reading symbols from
9802Although @var{filename} is typically a shared library file, an
9803executable file, or some other object file which has been fully
9804relocated for loading into a process, you can also load symbolic
9805information from relocatable @file{.o} files, as long as:
9806
9807@itemize @bullet
9808@item
9809the file's symbolic information refers only to linker symbols defined in
9810that file, not to symbols defined by other object files,
9811@item
9812every section the file's symbolic information refers to has actually
9813been loaded into the inferior, as it appears in the file, and
9814@item
9815you can determine the address at which every section was loaded, and
9816provide these to the @code{add-symbol-file} command.
9817@end itemize
9818
9819@noindent
9820Some embedded operating systems, like Sun Chorus and VxWorks, can load
9821relocatable files into an already running program; such systems
9822typically make the requirements above easy to meet. However, it's
9823important to recognize that many native systems use complex link
9824procedures (@code{.linkonce} section factoring and C++ constructor table
9825assembly, for example) that make the requirements difficult to meet. In
9826general, one cannot assume that using @code{add-symbol-file} to read a
9827relocatable object file's symbolic information will have the same effect
9828as linking the relocatable object file into the program in the normal
9829way.
9830
c906108c
SS
9831@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
9832
9833You can use the @samp{-mapped} and @samp{-readnow} options just as with
9834the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
9835table information for @var{filename}.
9836
9837@kindex add-shared-symbol-file
9838@item add-shared-symbol-file
9839The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
5d161b24
DB
9840operating system for the Motorola 88k. @value{GDBN} automatically looks for
9841shared libraries, however if @value{GDBN} does not find yours, you can run
c906108c 9842@code{add-shared-symbol-file}. It takes no arguments.
c906108c 9843
c906108c
SS
9844@kindex section
9845@item section
5d161b24
DB
9846The @code{section} command changes the base address of section SECTION of
9847the exec file to ADDR. This can be used if the exec file does not contain
9848section addresses, (such as in the a.out format), or when the addresses
9849specified in the file itself are wrong. Each section must be changed
d4f3574e
SS
9850separately. The @code{info files} command, described below, lists all
9851the sections and their addresses.
c906108c
SS
9852
9853@kindex info files
9854@kindex info target
9855@item info files
9856@itemx info target
7a292a7a
SS
9857@code{info files} and @code{info target} are synonymous; both print the
9858current target (@pxref{Targets, ,Specifying a Debugging Target}),
9859including the names of the executable and core dump files currently in
9860use by @value{GDBN}, and the files from which symbols were loaded. The
9861command @code{help target} lists all possible targets rather than
9862current ones.
9863
fe95c787
MS
9864@kindex maint info sections
9865@item maint info sections
9866Another command that can give you extra information about program sections
9867is @code{maint info sections}. In addition to the section information
9868displayed by @code{info files}, this command displays the flags and file
9869offset of each section in the executable and core dump files. In addition,
9870@code{maint info sections} provides the following command options (which
9871may be arbitrarily combined):
9872
9873@table @code
9874@item ALLOBJ
9875Display sections for all loaded object files, including shared libraries.
9876@item @var{sections}
6600abed 9877Display info only for named @var{sections}.
fe95c787
MS
9878@item @var{section-flags}
9879Display info only for sections for which @var{section-flags} are true.
9880The section flags that @value{GDBN} currently knows about are:
9881@table @code
9882@item ALLOC
9883Section will have space allocated in the process when loaded.
9884Set for all sections except those containing debug information.
9885@item LOAD
9886Section will be loaded from the file into the child process memory.
9887Set for pre-initialized code and data, clear for @code{.bss} sections.
9888@item RELOC
9889Section needs to be relocated before loading.
9890@item READONLY
9891Section cannot be modified by the child process.
9892@item CODE
9893Section contains executable code only.
6600abed 9894@item DATA
fe95c787
MS
9895Section contains data only (no executable code).
9896@item ROM
9897Section will reside in ROM.
9898@item CONSTRUCTOR
9899Section contains data for constructor/destructor lists.
9900@item HAS_CONTENTS
9901Section is not empty.
9902@item NEVER_LOAD
9903An instruction to the linker to not output the section.
9904@item COFF_SHARED_LIBRARY
9905A notification to the linker that the section contains
9906COFF shared library information.
9907@item IS_COMMON
9908Section contains common symbols.
9909@end table
9910@end table
6763aef9
MS
9911@kindex set trust-readonly-sections
9912@item set trust-readonly-sections on
9913Tell @value{GDBN} that readonly sections in your object file
6ca652b0 9914really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
9915In that case, @value{GDBN} can fetch values from these sections
9916out of the object file, rather than from the target program.
9917For some targets (notably embedded ones), this can be a significant
9918enhancement to debugging performance.
9919
9920The default is off.
9921
9922@item set trust-readonly-sections off
15110bc3 9923Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
9924the contents of the section might change while the program is running,
9925and must therefore be fetched from the target when needed.
c906108c
SS
9926@end table
9927
9928All file-specifying commands allow both absolute and relative file names
9929as arguments. @value{GDBN} always converts the file name to an absolute file
9930name and remembers it that way.
9931
c906108c 9932@cindex shared libraries
c906108c
SS
9933@value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
9934libraries.
53a5351d 9935
c906108c
SS
9936@value{GDBN} automatically loads symbol definitions from shared libraries
9937when you use the @code{run} command, or when you examine a core file.
9938(Before you issue the @code{run} command, @value{GDBN} does not understand
9939references to a function in a shared library, however---unless you are
9940debugging a core file).
53a5351d
JM
9941
9942On HP-UX, if the program loads a library explicitly, @value{GDBN}
9943automatically loads the symbols at the time of the @code{shl_load} call.
9944
c906108c
SS
9945@c FIXME: some @value{GDBN} release may permit some refs to undef
9946@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
9947@c FIXME...lib; check this from time to time when updating manual
9948
b7209cb4
FF
9949There are times, however, when you may wish to not automatically load
9950symbol definitions from shared libraries, such as when they are
9951particularly large or there are many of them.
9952
9953To control the automatic loading of shared library symbols, use the
9954commands:
9955
9956@table @code
9957@kindex set auto-solib-add
9958@item set auto-solib-add @var{mode}
9959If @var{mode} is @code{on}, symbols from all shared object libraries
9960will be loaded automatically when the inferior begins execution, you
9961attach to an independently started inferior, or when the dynamic linker
9962informs @value{GDBN} that a new library has been loaded. If @var{mode}
9963is @code{off}, symbols must be loaded manually, using the
9964@code{sharedlibrary} command. The default value is @code{on}.
9965
9966@kindex show auto-solib-add
9967@item show auto-solib-add
9968Display the current autoloading mode.
9969@end table
9970
9971To explicitly load shared library symbols, use the @code{sharedlibrary}
9972command:
9973
c906108c
SS
9974@table @code
9975@kindex info sharedlibrary
9976@kindex info share
9977@item info share
9978@itemx info sharedlibrary
9979Print the names of the shared libraries which are currently loaded.
9980
9981@kindex sharedlibrary
9982@kindex share
9983@item sharedlibrary @var{regex}
9984@itemx share @var{regex}
c906108c
SS
9985Load shared object library symbols for files matching a
9986Unix regular expression.
9987As with files loaded automatically, it only loads shared libraries
9988required by your program for a core file or after typing @code{run}. If
9989@var{regex} is omitted all shared libraries required by your program are
9990loaded.
9991@end table
9992
b7209cb4
FF
9993On some systems, such as HP-UX systems, @value{GDBN} supports
9994autoloading shared library symbols until a limiting threshold size is
9995reached. This provides the benefit of allowing autoloading to remain on
9996by default, but avoids autoloading excessively large shared libraries,
9997up to a threshold that is initially set, but which you can modify if you
9998wish.
c906108c
SS
9999
10000Beyond that threshold, symbols from shared libraries must be explicitly
d4f3574e
SS
10001loaded. To load these symbols, use the command @code{sharedlibrary
10002@var{filename}}. The base address of the shared library is determined
c906108c
SS
10003automatically by @value{GDBN} and need not be specified.
10004
10005To display or set the threshold, use the commands:
10006
10007@table @code
b7209cb4
FF
10008@kindex set auto-solib-limit
10009@item set auto-solib-limit @var{threshold}
10010Set the autoloading size threshold, in an integral number of megabytes.
10011If @var{threshold} is nonzero and shared library autoloading is enabled,
10012symbols from all shared object libraries will be loaded until the total
10013size of the loaded shared library symbols exceeds this threshold.
c906108c 10014Otherwise, symbols must be loaded manually, using the
6ca652b0 10015@code{sharedlibrary} command. The default threshold is 100 (i.e.@: 100
b7209cb4 10016Mb).
c906108c 10017
b7209cb4
FF
10018@kindex show auto-solib-limit
10019@item show auto-solib-limit
c906108c
SS
10020Display the current autoloading size threshold, in megabytes.
10021@end table
c906108c 10022
f5ebfba0
DJ
10023Shared libraries are also supported in many cross or remote debugging
10024configurations. A copy of the target's libraries need to be present on the
10025host system; they need to be the same as the target libraries, although the
10026copies on the target can be stripped as long as the copies on the host are
10027not.
10028
10029You need to tell @value{GDBN} where the target libraries are, so that it can
10030load the correct copies---otherwise, it may try to load the host's libraries.
10031@value{GDBN} has two variables to specify the search directories for target
10032libraries.
10033
10034@table @code
10035@kindex set solib-absolute-prefix
10036@item set solib-absolute-prefix @var{path}
10037If this variable is set, @var{path} will be used as a prefix for any
10038absolute shared library paths; many runtime loaders store the absolute
10039paths to the shared library in the target program's memory. If you use
10040@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
10041out in the same way that they are on the target, with e.g.@: a
10042@file{/usr/lib} hierarchy under @var{path}.
10043
10044You can set the default value of @samp{solib-absolute-prefix} by using the
10045configure-time @samp{--with-sysroot} option.
10046
10047@kindex show solib-absolute-prefix
10048@item show solib-absolute-prefix
10049Display the current shared library prefix.
10050
10051@kindex set solib-search-path
10052@item set solib-search-path @var{path}
10053If this variable is set, @var{path} is a colon-separated list of directories
10054to search for shared libraries. @samp{solib-search-path} is used after
10055@samp{solib-absolute-prefix} fails to locate the library, or if the path to
10056the library is relative instead of absolute. If you want to use
10057@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
10058set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
10059@value{GDBN} from finding your host's libraries.
10060
10061@kindex show solib-search-path
10062@item show solib-search-path
10063Display the current shared library search path.
10064@end table
10065
5b5d99cf
JB
10066
10067@node Separate Debug Files
10068@section Debugging Information in Separate Files
10069@cindex separate debugging information files
10070@cindex debugging information in separate files
10071@cindex @file{.debug} subdirectories
10072@cindex debugging information directory, global
10073@cindex global debugging information directory
10074
10075@value{GDBN} allows you to put a program's debugging information in a
10076file separate from the executable itself, in a way that allows
10077@value{GDBN} to find and load the debugging information automatically.
10078Since debugging information can be very large --- sometimes larger
10079than the executable code itself --- some systems distribute debugging
10080information for their executables in separate files, which users can
10081install only when they need to debug a problem.
10082
10083If an executable's debugging information has been extracted to a
10084separate file, the executable should contain a @dfn{debug link} giving
10085the name of the debugging information file (with no directory
10086components), and a checksum of its contents. (The exact form of a
10087debug link is described below.) If the full name of the directory
10088containing the executable is @var{execdir}, and the executable has a
10089debug link that specifies the name @var{debugfile}, then @value{GDBN}
10090will automatically search for the debugging information file in three
10091places:
10092
10093@itemize @bullet
10094@item
10095the directory containing the executable file (that is, it will look
10096for a file named @file{@var{execdir}/@var{debugfile}},
10097@item
10098a subdirectory of that directory named @file{.debug} (that is, the
10099file @file{@var{execdir}/.debug/@var{debugfile}}, and
10100@item
10101a subdirectory of the global debug file directory that includes the
10102executable's full path, and the name from the link (that is, the file
10103@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
10104@var{globaldebugdir} is the global debug file directory, and
10105@var{execdir} has been turned into a relative path).
10106@end itemize
10107@noindent
10108@value{GDBN} checks under each of these names for a debugging
10109information file whose checksum matches that given in the link, and
10110reads the debugging information from the first one it finds.
10111
10112So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
10113which has a link containing the name @file{ls.debug}, and the global
10114debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
10115for debug information in @file{/usr/bin/ls.debug},
10116@file{/usr/bin/.debug/ls.debug}, and
10117@file{/usr/lib/debug/usr/bin/ls.debug}.
10118
10119You can set the global debugging info directory's name, and view the
10120name @value{GDBN} is currently using.
10121
10122@table @code
10123
10124@kindex set debug-file-directory
10125@item set debug-file-directory @var{directory}
10126Set the directory which @value{GDBN} searches for separate debugging
10127information files to @var{directory}.
10128
10129@kindex show debug-file-directory
10130@item show debug-file-directory
10131Show the directory @value{GDBN} searches for separate debugging
10132information files.
10133
10134@end table
10135
10136@cindex @code{.gnu_debuglink} sections
10137@cindex debug links
10138A debug link is a special section of the executable file named
10139@code{.gnu_debuglink}. The section must contain:
10140
10141@itemize
10142@item
10143A filename, with any leading directory components removed, followed by
10144a zero byte,
10145@item
10146zero to three bytes of padding, as needed to reach the next four-byte
10147boundary within the section, and
10148@item
10149a four-byte CRC checksum, stored in the same endianness used for the
10150executable file itself. The checksum is computed on the debugging
10151information file's full contents by the function given below, passing
10152zero as the @var{crc} argument.
10153@end itemize
10154
10155Any executable file format can carry a debug link, as long as it can
10156contain a section named @code{.gnu_debuglink} with the contents
10157described above.
10158
10159The debugging information file itself should be an ordinary
10160executable, containing a full set of linker symbols, sections, and
10161debugging information. The sections of the debugging information file
10162should have the same names, addresses and sizes as the original file,
10163but they need not contain any data --- much like a @code{.bss} section
10164in an ordinary executable.
10165
10166As of December 2002, there is no standard GNU utility to produce
10167separated executable / debugging information file pairs. Ulrich
10168Drepper's @file{elfutils} package, starting with version 0.53,
10169contains a version of the @code{strip} command such that the command
10170@kbd{strip foo -f foo.debug} removes the debugging information from
10171the executable file @file{foo}, places it in the file
10172@file{foo.debug}, and leaves behind a debug link in @file{foo}.
10173
10174Since there are many different ways to compute CRC's (different
10175polynomials, reversals, byte ordering, etc.), the simplest way to
10176describe the CRC used in @code{.gnu_debuglink} sections is to give the
10177complete code for a function that computes it:
10178
10179@kindex @code{gnu_debuglink_crc32}
10180@smallexample
10181unsigned long
10182gnu_debuglink_crc32 (unsigned long crc,
10183 unsigned char *buf, size_t len)
10184@{
10185 static const unsigned long crc32_table[256] =
10186 @{
10187 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10188 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10189 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10190 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10191 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10192 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10193 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10194 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10195 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10196 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10197 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10198 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10199 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10200 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10201 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10202 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10203 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10204 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10205 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10206 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10207 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10208 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10209 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10210 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10211 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10212 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10213 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10214 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10215 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10216 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10217 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10218 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10219 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10220 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10221 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10222 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10223 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10224 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10225 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10226 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10227 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10228 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10229 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10230 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10231 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10232 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10233 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10234 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10235 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10236 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10237 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10238 0x2d02ef8d
10239 @};
10240 unsigned char *end;
10241
10242 crc = ~crc & 0xffffffff;
10243 for (end = buf + len; buf < end; ++buf)
10244 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 10245 return ~crc & 0xffffffff;
5b5d99cf
JB
10246@}
10247@end smallexample
10248
10249
6d2ebf8b 10250@node Symbol Errors
c906108c
SS
10251@section Errors reading symbol files
10252
10253While reading a symbol file, @value{GDBN} occasionally encounters problems,
10254such as symbol types it does not recognize, or known bugs in compiler
10255output. By default, @value{GDBN} does not notify you of such problems, since
10256they are relatively common and primarily of interest to people
10257debugging compilers. If you are interested in seeing information
10258about ill-constructed symbol tables, you can either ask @value{GDBN} to print
10259only one message about each such type of problem, no matter how many
10260times the problem occurs; or you can ask @value{GDBN} to print more messages,
10261to see how many times the problems occur, with the @code{set
10262complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
10263messages}).
10264
10265The messages currently printed, and their meanings, include:
10266
10267@table @code
10268@item inner block not inside outer block in @var{symbol}
10269
10270The symbol information shows where symbol scopes begin and end
10271(such as at the start of a function or a block of statements). This
10272error indicates that an inner scope block is not fully contained
10273in its outer scope blocks.
10274
10275@value{GDBN} circumvents the problem by treating the inner block as if it had
10276the same scope as the outer block. In the error message, @var{symbol}
10277may be shown as ``@code{(don't know)}'' if the outer block is not a
10278function.
10279
10280@item block at @var{address} out of order
10281
10282The symbol information for symbol scope blocks should occur in
10283order of increasing addresses. This error indicates that it does not
10284do so.
10285
10286@value{GDBN} does not circumvent this problem, and has trouble
10287locating symbols in the source file whose symbols it is reading. (You
10288can often determine what source file is affected by specifying
10289@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
10290messages}.)
10291
10292@item bad block start address patched
10293
10294The symbol information for a symbol scope block has a start address
10295smaller than the address of the preceding source line. This is known
10296to occur in the SunOS 4.1.1 (and earlier) C compiler.
10297
10298@value{GDBN} circumvents the problem by treating the symbol scope block as
10299starting on the previous source line.
10300
10301@item bad string table offset in symbol @var{n}
10302
10303@cindex foo
10304Symbol number @var{n} contains a pointer into the string table which is
10305larger than the size of the string table.
10306
10307@value{GDBN} circumvents the problem by considering the symbol to have the
10308name @code{foo}, which may cause other problems if many symbols end up
10309with this name.
10310
10311@item unknown symbol type @code{0x@var{nn}}
10312
7a292a7a
SS
10313The symbol information contains new data types that @value{GDBN} does
10314not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 10315uncomprehended information, in hexadecimal.
c906108c 10316
7a292a7a
SS
10317@value{GDBN} circumvents the error by ignoring this symbol information.
10318This usually allows you to debug your program, though certain symbols
c906108c 10319are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
10320debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
10321on @code{complain}, then go up to the function @code{read_dbx_symtab}
10322and examine @code{*bufp} to see the symbol.
c906108c
SS
10323
10324@item stub type has NULL name
c906108c 10325
7a292a7a 10326@value{GDBN} could not find the full definition for a struct or class.
c906108c 10327
7a292a7a 10328@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 10329The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
10330information that recent versions of the compiler should have output for
10331it.
c906108c
SS
10332
10333@item info mismatch between compiler and debugger
10334
10335@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 10336
c906108c
SS
10337@end table
10338
6d2ebf8b 10339@node Targets
c906108c 10340@chapter Specifying a Debugging Target
7a292a7a 10341
c906108c
SS
10342@cindex debugging target
10343@kindex target
10344
10345A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
10346
10347Often, @value{GDBN} runs in the same host environment as your program;
10348in that case, the debugging target is specified as a side effect when
10349you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
10350flexibility---for example, running @value{GDBN} on a physically separate
10351host, or controlling a standalone system over a serial port or a
53a5351d
JM
10352realtime system over a TCP/IP connection---you can use the @code{target}
10353command to specify one of the target types configured for @value{GDBN}
10354(@pxref{Target Commands, ,Commands for managing targets}).
c906108c
SS
10355
10356@menu
10357* Active Targets:: Active targets
10358* Target Commands:: Commands for managing targets
c906108c
SS
10359* Byte Order:: Choosing target byte order
10360* Remote:: Remote debugging
96baa820 10361* KOD:: Kernel Object Display
c906108c
SS
10362
10363@end menu
10364
6d2ebf8b 10365@node Active Targets
c906108c 10366@section Active targets
7a292a7a 10367
c906108c
SS
10368@cindex stacking targets
10369@cindex active targets
10370@cindex multiple targets
10371
c906108c 10372There are three classes of targets: processes, core files, and
7a292a7a
SS
10373executable files. @value{GDBN} can work concurrently on up to three
10374active targets, one in each class. This allows you to (for example)
10375start a process and inspect its activity without abandoning your work on
10376a core file.
c906108c
SS
10377
10378For example, if you execute @samp{gdb a.out}, then the executable file
10379@code{a.out} is the only active target. If you designate a core file as
10380well---presumably from a prior run that crashed and coredumped---then
10381@value{GDBN} has two active targets and uses them in tandem, looking
10382first in the corefile target, then in the executable file, to satisfy
10383requests for memory addresses. (Typically, these two classes of target
10384are complementary, since core files contain only a program's
10385read-write memory---variables and so on---plus machine status, while
10386executable files contain only the program text and initialized data.)
c906108c
SS
10387
10388When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
10389target as well. When a process target is active, all @value{GDBN}
10390commands requesting memory addresses refer to that target; addresses in
10391an active core file or executable file target are obscured while the
10392process target is active.
c906108c 10393
7a292a7a
SS
10394Use the @code{core-file} and @code{exec-file} commands to select a new
10395core file or executable target (@pxref{Files, ,Commands to specify
c906108c 10396files}). To specify as a target a process that is already running, use
7a292a7a
SS
10397the @code{attach} command (@pxref{Attach, ,Debugging an already-running
10398process}).
c906108c 10399
6d2ebf8b 10400@node Target Commands
c906108c
SS
10401@section Commands for managing targets
10402
10403@table @code
10404@item target @var{type} @var{parameters}
7a292a7a
SS
10405Connects the @value{GDBN} host environment to a target machine or
10406process. A target is typically a protocol for talking to debugging
10407facilities. You use the argument @var{type} to specify the type or
10408protocol of the target machine.
c906108c
SS
10409
10410Further @var{parameters} are interpreted by the target protocol, but
10411typically include things like device names or host names to connect
10412with, process numbers, and baud rates.
c906108c
SS
10413
10414The @code{target} command does not repeat if you press @key{RET} again
10415after executing the command.
10416
10417@kindex help target
10418@item help target
10419Displays the names of all targets available. To display targets
10420currently selected, use either @code{info target} or @code{info files}
10421(@pxref{Files, ,Commands to specify files}).
10422
10423@item help target @var{name}
10424Describe a particular target, including any parameters necessary to
10425select it.
10426
10427@kindex set gnutarget
10428@item set gnutarget @var{args}
5d161b24 10429@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 10430knows whether it is reading an @dfn{executable},
5d161b24
DB
10431a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
10432with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
10433with @code{gnutarget} the @code{target} refers to a program, not a machine.
10434
d4f3574e 10435@quotation
c906108c
SS
10436@emph{Warning:} To specify a file format with @code{set gnutarget},
10437you must know the actual BFD name.
d4f3574e 10438@end quotation
c906108c 10439
d4f3574e
SS
10440@noindent
10441@xref{Files, , Commands to specify files}.
c906108c 10442
5d161b24 10443@kindex show gnutarget
c906108c
SS
10444@item show gnutarget
10445Use the @code{show gnutarget} command to display what file format
10446@code{gnutarget} is set to read. If you have not set @code{gnutarget},
10447@value{GDBN} will determine the file format for each file automatically,
10448and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
10449@end table
10450
c906108c
SS
10451Here are some common targets (available, or not, depending on the GDB
10452configuration):
c906108c
SS
10453
10454@table @code
10455@kindex target exec
10456@item target exec @var{program}
10457An executable file. @samp{target exec @var{program}} is the same as
10458@samp{exec-file @var{program}}.
10459
c906108c
SS
10460@kindex target core
10461@item target core @var{filename}
10462A core dump file. @samp{target core @var{filename}} is the same as
10463@samp{core-file @var{filename}}.
c906108c
SS
10464
10465@kindex target remote
10466@item target remote @var{dev}
10467Remote serial target in GDB-specific protocol. The argument @var{dev}
10468specifies what serial device to use for the connection (e.g.
10469@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 10470supports the @code{load} command. This is only useful if you have
c906108c
SS
10471some other way of getting the stub to the target system, and you can put
10472it somewhere in memory where it won't get clobbered by the download.
10473
c906108c
SS
10474@kindex target sim
10475@item target sim
2df3850c 10476Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 10477In general,
474c8240 10478@smallexample
104c1213
JM
10479 target sim
10480 load
10481 run
474c8240 10482@end smallexample
d4f3574e 10483@noindent
104c1213 10484works; however, you cannot assume that a specific memory map, device
d4f3574e 10485drivers, or even basic I/O is available, although some simulators do
104c1213
JM
10486provide these. For info about any processor-specific simulator details,
10487see the appropriate section in @ref{Embedded Processors, ,Embedded
10488Processors}.
10489
c906108c
SS
10490@end table
10491
104c1213 10492Some configurations may include these targets as well:
c906108c
SS
10493
10494@table @code
10495
c906108c
SS
10496@kindex target nrom
10497@item target nrom @var{dev}
10498NetROM ROM emulator. This target only supports downloading.
10499
c906108c
SS
10500@end table
10501
5d161b24 10502Different targets are available on different configurations of @value{GDBN};
c906108c 10503your configuration may have more or fewer targets.
c906108c
SS
10504
10505Many remote targets require you to download the executable's code
10506once you've successfully established a connection.
10507
10508@table @code
10509
10510@kindex load @var{filename}
10511@item load @var{filename}
c906108c
SS
10512Depending on what remote debugging facilities are configured into
10513@value{GDBN}, the @code{load} command may be available. Where it exists, it
10514is meant to make @var{filename} (an executable) available for debugging
10515on the remote system---by downloading, or dynamic linking, for example.
10516@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
10517the @code{add-symbol-file} command.
10518
10519If your @value{GDBN} does not have a @code{load} command, attempting to
10520execute it gets the error message ``@code{You can't do that when your
10521target is @dots{}}''
c906108c
SS
10522
10523The file is loaded at whatever address is specified in the executable.
10524For some object file formats, you can specify the load address when you
10525link the program; for other formats, like a.out, the object file format
10526specifies a fixed address.
10527@c FIXME! This would be a good place for an xref to the GNU linker doc.
10528
c906108c
SS
10529@code{load} does not repeat if you press @key{RET} again after using it.
10530@end table
10531
6d2ebf8b 10532@node Byte Order
c906108c 10533@section Choosing target byte order
7a292a7a 10534
c906108c
SS
10535@cindex choosing target byte order
10536@cindex target byte order
c906108c 10537
172c2a43 10538Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
10539offer the ability to run either big-endian or little-endian byte
10540orders. Usually the executable or symbol will include a bit to
10541designate the endian-ness, and you will not need to worry about
10542which to use. However, you may still find it useful to adjust
d4f3574e 10543@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
10544
10545@table @code
10546@kindex set endian big
10547@item set endian big
10548Instruct @value{GDBN} to assume the target is big-endian.
10549
10550@kindex set endian little
10551@item set endian little
10552Instruct @value{GDBN} to assume the target is little-endian.
10553
10554@kindex set endian auto
10555@item set endian auto
10556Instruct @value{GDBN} to use the byte order associated with the
10557executable.
10558
10559@item show endian
10560Display @value{GDBN}'s current idea of the target byte order.
10561
10562@end table
10563
10564Note that these commands merely adjust interpretation of symbolic
10565data on the host, and that they have absolutely no effect on the
10566target system.
10567
6d2ebf8b 10568@node Remote
c906108c
SS
10569@section Remote debugging
10570@cindex remote debugging
10571
10572If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
10573@value{GDBN} in the usual way, it is often useful to use remote debugging.
10574For example, you might use remote debugging on an operating system kernel,
c906108c
SS
10575or on a small system which does not have a general purpose operating system
10576powerful enough to run a full-featured debugger.
10577
10578Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
10579to make this work with particular debugging targets. In addition,
5d161b24 10580@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
10581but not specific to any particular target system) which you can use if you
10582write the remote stubs---the code that runs on the remote system to
10583communicate with @value{GDBN}.
10584
10585Other remote targets may be available in your
10586configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 10587
6f05cf9f
AC
10588@node KOD
10589@section Kernel Object Display
10590
10591@cindex kernel object display
10592@cindex kernel object
10593@cindex KOD
10594
10595Some targets support kernel object display. Using this facility,
10596@value{GDBN} communicates specially with the underlying operating system
10597and can display information about operating system-level objects such as
10598mutexes and other synchronization objects. Exactly which objects can be
10599displayed is determined on a per-OS basis.
10600
10601Use the @code{set os} command to set the operating system. This tells
10602@value{GDBN} which kernel object display module to initialize:
10603
474c8240 10604@smallexample
6f05cf9f 10605(@value{GDBP}) set os cisco
474c8240 10606@end smallexample
6f05cf9f
AC
10607
10608If @code{set os} succeeds, @value{GDBN} will display some information
10609about the operating system, and will create a new @code{info} command
10610which can be used to query the target. The @code{info} command is named
10611after the operating system:
c906108c 10612
474c8240 10613@smallexample
6f05cf9f
AC
10614(@value{GDBP}) info cisco
10615List of Cisco Kernel Objects
10616Object Description
10617any Any and all objects
474c8240 10618@end smallexample
6f05cf9f
AC
10619
10620Further subcommands can be used to query about particular objects known
10621by the kernel.
10622
10623There is currently no way to determine whether a given operating system
10624is supported other than to try it.
10625
10626
10627@node Remote Debugging
10628@chapter Debugging remote programs
10629
6b2f586d 10630@menu
07f31aa6 10631* Connecting:: Connecting to a remote target
6b2f586d
AC
10632* Server:: Using the gdbserver program
10633* NetWare:: Using the gdbserve.nlm program
501eef12 10634* Remote configuration:: Remote configuration
6b2f586d 10635* remote stub:: Implementing a remote stub
6b2f586d
AC
10636@end menu
10637
07f31aa6
DJ
10638@node Connecting
10639@section Connecting to a remote target
10640
10641On the @value{GDBN} host machine, you will need an unstripped copy of
10642your program, since @value{GDBN} needs symobl and debugging information.
10643Start up @value{GDBN} as usual, using the name of the local copy of your
10644program as the first argument.
10645
10646@cindex serial line, @code{target remote}
10647If you're using a serial line, you may want to give @value{GDBN} the
10648@w{@samp{--baud}} option, or use the @code{set remotebaud} command
10649before the @code{target} command.
10650
10651After that, use @code{target remote} to establish communications with
10652the target machine. Its argument specifies how to communicate---either
10653via a devicename attached to a direct serial line, or a TCP or UDP port
10654(possibly to a terminal server which in turn has a serial line to the
10655target). For example, to use a serial line connected to the device
10656named @file{/dev/ttyb}:
10657
10658@smallexample
10659target remote /dev/ttyb
10660@end smallexample
10661
10662@cindex TCP port, @code{target remote}
10663To use a TCP connection, use an argument of the form
10664@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
10665For example, to connect to port 2828 on a
10666terminal server named @code{manyfarms}:
10667
10668@smallexample
10669target remote manyfarms:2828
10670@end smallexample
10671
10672If your remote target is actually running on the same machine as
10673your debugger session (e.g.@: a simulator of your target running on
10674the same host), you can omit the hostname. For example, to connect
10675to port 1234 on your local machine:
10676
10677@smallexample
10678target remote :1234
10679@end smallexample
10680@noindent
10681
10682Note that the colon is still required here.
10683
10684@cindex UDP port, @code{target remote}
10685To use a UDP connection, use an argument of the form
10686@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
10687on a terminal server named @code{manyfarms}:
10688
10689@smallexample
10690target remote udp:manyfarms:2828
10691@end smallexample
10692
10693When using a UDP connection for remote debugging, you should keep in mind
10694that the `U' stands for ``Unreliable''. UDP can silently drop packets on
10695busy or unreliable networks, which will cause havoc with your debugging
10696session.
10697
10698Now you can use all the usual commands to examine and change data and to
10699step and continue the remote program.
10700
10701@cindex interrupting remote programs
10702@cindex remote programs, interrupting
10703Whenever @value{GDBN} is waiting for the remote program, if you type the
10704interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
10705program. This may or may not succeed, depending in part on the hardware
10706and the serial drivers the remote system uses. If you type the
10707interrupt character once again, @value{GDBN} displays this prompt:
10708
10709@smallexample
10710Interrupted while waiting for the program.
10711Give up (and stop debugging it)? (y or n)
10712@end smallexample
10713
10714If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
10715(If you decide you want to try again later, you can use @samp{target
10716remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
10717goes back to waiting.
10718
10719@table @code
10720@kindex detach (remote)
10721@item detach
10722When you have finished debugging the remote program, you can use the
10723@code{detach} command to release it from @value{GDBN} control.
10724Detaching from the target normally resumes its execution, but the results
10725will depend on your particular remote stub. After the @code{detach}
10726command, @value{GDBN} is free to connect to another target.
10727
10728@kindex disconnect
10729@item disconnect
10730The @code{disconnect} command behaves like @code{detach}, except that
10731the target is generally not resumed. It will wait for @value{GDBN}
10732(this instance or another one) to connect and continue debugging. After
10733the @code{disconnect} command, @value{GDBN} is again free to connect to
10734another target.
10735@end table
10736
6f05cf9f
AC
10737@node Server
10738@section Using the @code{gdbserver} program
10739
10740@kindex gdbserver
10741@cindex remote connection without stubs
10742@code{gdbserver} is a control program for Unix-like systems, which
10743allows you to connect your program with a remote @value{GDBN} via
10744@code{target remote}---but without linking in the usual debugging stub.
10745
10746@code{gdbserver} is not a complete replacement for the debugging stubs,
10747because it requires essentially the same operating-system facilities
10748that @value{GDBN} itself does. In fact, a system that can run
10749@code{gdbserver} to connect to a remote @value{GDBN} could also run
10750@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
10751because it is a much smaller program than @value{GDBN} itself. It is
10752also easier to port than all of @value{GDBN}, so you may be able to get
10753started more quickly on a new system by using @code{gdbserver}.
10754Finally, if you develop code for real-time systems, you may find that
10755the tradeoffs involved in real-time operation make it more convenient to
10756do as much development work as possible on another system, for example
10757by cross-compiling. You can use @code{gdbserver} to make a similar
10758choice for debugging.
10759
10760@value{GDBN} and @code{gdbserver} communicate via either a serial line
10761or a TCP connection, using the standard @value{GDBN} remote serial
10762protocol.
10763
10764@table @emph
10765@item On the target machine,
10766you need to have a copy of the program you want to debug.
10767@code{gdbserver} does not need your program's symbol table, so you can
10768strip the program if necessary to save space. @value{GDBN} on the host
10769system does all the symbol handling.
10770
10771To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 10772the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
10773syntax is:
10774
10775@smallexample
10776target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
10777@end smallexample
10778
10779@var{comm} is either a device name (to use a serial line) or a TCP
10780hostname and portnumber. For example, to debug Emacs with the argument
10781@samp{foo.txt} and communicate with @value{GDBN} over the serial port
10782@file{/dev/com1}:
10783
10784@smallexample
10785target> gdbserver /dev/com1 emacs foo.txt
10786@end smallexample
10787
10788@code{gdbserver} waits passively for the host @value{GDBN} to communicate
10789with it.
10790
10791To use a TCP connection instead of a serial line:
10792
10793@smallexample
10794target> gdbserver host:2345 emacs foo.txt
10795@end smallexample
10796
10797The only difference from the previous example is the first argument,
10798specifying that you are communicating with the host @value{GDBN} via
10799TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
10800expect a TCP connection from machine @samp{host} to local TCP port 2345.
10801(Currently, the @samp{host} part is ignored.) You can choose any number
10802you want for the port number as long as it does not conflict with any
10803TCP ports already in use on the target system (for example, @code{23} is
10804reserved for @code{telnet}).@footnote{If you choose a port number that
10805conflicts with another service, @code{gdbserver} prints an error message
10806and exits.} You must use the same port number with the host @value{GDBN}
10807@code{target remote} command.
10808
56460a61
DJ
10809On some targets, @code{gdbserver} can also attach to running programs.
10810This is accomplished via the @code{--attach} argument. The syntax is:
10811
10812@smallexample
10813target> gdbserver @var{comm} --attach @var{pid}
10814@end smallexample
10815
10816@var{pid} is the process ID of a currently running process. It isn't necessary
10817to point @code{gdbserver} at a binary for the running process.
10818
b1fe9455
DJ
10819@pindex pidof
10820@cindex attach to a program by name
10821You can debug processes by name instead of process ID if your target has the
10822@code{pidof} utility:
10823
10824@smallexample
10825target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
10826@end smallexample
10827
10828In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
10829has multiple threads, most versions of @code{pidof} support the
10830@code{-s} option to only return the first process ID.
10831
07f31aa6
DJ
10832@item On the host machine,
10833connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
10834For TCP connections, you must start up @code{gdbserver} prior to using
10835the @code{target remote} command. Otherwise you may get an error whose
10836text depends on the host system, but which usually looks something like
07f31aa6
DJ
10837@samp{Connection refused}. You don't need to use the @code{load}
10838command in @value{GDBN} when using gdbserver, since the program is
10839already on the target.
10840
6f05cf9f
AC
10841@end table
10842
10843@node NetWare
10844@section Using the @code{gdbserve.nlm} program
10845
10846@kindex gdbserve.nlm
10847@code{gdbserve.nlm} is a control program for NetWare systems, which
10848allows you to connect your program with a remote @value{GDBN} via
10849@code{target remote}.
10850
10851@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
10852using the standard @value{GDBN} remote serial protocol.
10853
10854@table @emph
10855@item On the target machine,
10856you need to have a copy of the program you want to debug.
10857@code{gdbserve.nlm} does not need your program's symbol table, so you
10858can strip the program if necessary to save space. @value{GDBN} on the
10859host system does all the symbol handling.
10860
10861To use the server, you must tell it how to communicate with
10862@value{GDBN}; the name of your program; and the arguments for your
10863program. The syntax is:
10864
10865@smallexample
10866load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
10867 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
10868@end smallexample
10869
10870@var{board} and @var{port} specify the serial line; @var{baud} specifies
10871the baud rate used by the connection. @var{port} and @var{node} default
10872to 0, @var{baud} defaults to 9600@dmn{bps}.
10873
10874For example, to debug Emacs with the argument @samp{foo.txt}and
10875communicate with @value{GDBN} over serial port number 2 or board 1
10876using a 19200@dmn{bps} connection:
10877
10878@smallexample
10879load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
10880@end smallexample
10881
07f31aa6
DJ
10882@item
10883On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
10884Connecting to a remote target}).
6f05cf9f 10885
6f05cf9f
AC
10886@end table
10887
501eef12
AC
10888@node Remote configuration
10889@section Remote configuration
10890
10891The following configuration options are available when debugging remote
10892programs:
10893
10894@table @code
10895@kindex set remote hardware-watchpoint-limit
10896@kindex set remote hardware-breakpoint-limit
10897@anchor{set remote hardware-watchpoint-limit}
10898@anchor{set remote hardware-breakpoint-limit}
10899@item set remote hardware-watchpoint-limit @var{limit}
10900@itemx set remote hardware-breakpoint-limit @var{limit}
10901Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
10902watchpoints. A limit of -1, the default, is treated as unlimited.
10903@end table
10904
6f05cf9f
AC
10905@node remote stub
10906@section Implementing a remote stub
7a292a7a 10907
8e04817f
AC
10908@cindex debugging stub, example
10909@cindex remote stub, example
10910@cindex stub example, remote debugging
10911The stub files provided with @value{GDBN} implement the target side of the
10912communication protocol, and the @value{GDBN} side is implemented in the
10913@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
10914these subroutines to communicate, and ignore the details. (If you're
10915implementing your own stub file, you can still ignore the details: start
10916with one of the existing stub files. @file{sparc-stub.c} is the best
10917organized, and therefore the easiest to read.)
10918
104c1213
JM
10919@cindex remote serial debugging, overview
10920To debug a program running on another machine (the debugging
10921@dfn{target} machine), you must first arrange for all the usual
10922prerequisites for the program to run by itself. For example, for a C
10923program, you need:
c906108c 10924
104c1213
JM
10925@enumerate
10926@item
10927A startup routine to set up the C runtime environment; these usually
10928have a name like @file{crt0}. The startup routine may be supplied by
10929your hardware supplier, or you may have to write your own.
96baa820 10930
5d161b24 10931@item
d4f3574e 10932A C subroutine library to support your program's
104c1213 10933subroutine calls, notably managing input and output.
96baa820 10934
104c1213
JM
10935@item
10936A way of getting your program to the other machine---for example, a
10937download program. These are often supplied by the hardware
10938manufacturer, but you may have to write your own from hardware
10939documentation.
10940@end enumerate
96baa820 10941
104c1213
JM
10942The next step is to arrange for your program to use a serial port to
10943communicate with the machine where @value{GDBN} is running (the @dfn{host}
10944machine). In general terms, the scheme looks like this:
96baa820 10945
104c1213
JM
10946@table @emph
10947@item On the host,
10948@value{GDBN} already understands how to use this protocol; when everything
10949else is set up, you can simply use the @samp{target remote} command
10950(@pxref{Targets,,Specifying a Debugging Target}).
10951
10952@item On the target,
10953you must link with your program a few special-purpose subroutines that
10954implement the @value{GDBN} remote serial protocol. The file containing these
10955subroutines is called a @dfn{debugging stub}.
10956
10957On certain remote targets, you can use an auxiliary program
10958@code{gdbserver} instead of linking a stub into your program.
10959@xref{Server,,Using the @code{gdbserver} program}, for details.
10960@end table
96baa820 10961
104c1213
JM
10962The debugging stub is specific to the architecture of the remote
10963machine; for example, use @file{sparc-stub.c} to debug programs on
10964@sc{sparc} boards.
96baa820 10965
104c1213
JM
10966@cindex remote serial stub list
10967These working remote stubs are distributed with @value{GDBN}:
96baa820 10968
104c1213
JM
10969@table @code
10970
10971@item i386-stub.c
41afff9a 10972@cindex @file{i386-stub.c}
104c1213
JM
10973@cindex Intel
10974@cindex i386
10975For Intel 386 and compatible architectures.
10976
10977@item m68k-stub.c
41afff9a 10978@cindex @file{m68k-stub.c}
104c1213
JM
10979@cindex Motorola 680x0
10980@cindex m680x0
10981For Motorola 680x0 architectures.
10982
10983@item sh-stub.c
41afff9a 10984@cindex @file{sh-stub.c}
172c2a43 10985@cindex Renesas
104c1213 10986@cindex SH
172c2a43 10987For Renesas SH architectures.
104c1213
JM
10988
10989@item sparc-stub.c
41afff9a 10990@cindex @file{sparc-stub.c}
104c1213
JM
10991@cindex Sparc
10992For @sc{sparc} architectures.
10993
10994@item sparcl-stub.c
41afff9a 10995@cindex @file{sparcl-stub.c}
104c1213
JM
10996@cindex Fujitsu
10997@cindex SparcLite
10998For Fujitsu @sc{sparclite} architectures.
10999
11000@end table
11001
11002The @file{README} file in the @value{GDBN} distribution may list other
11003recently added stubs.
11004
11005@menu
11006* Stub Contents:: What the stub can do for you
11007* Bootstrapping:: What you must do for the stub
11008* Debug Session:: Putting it all together
104c1213
JM
11009@end menu
11010
6d2ebf8b 11011@node Stub Contents
6f05cf9f 11012@subsection What the stub can do for you
104c1213
JM
11013
11014@cindex remote serial stub
11015The debugging stub for your architecture supplies these three
11016subroutines:
11017
11018@table @code
11019@item set_debug_traps
11020@kindex set_debug_traps
11021@cindex remote serial stub, initialization
11022This routine arranges for @code{handle_exception} to run when your
11023program stops. You must call this subroutine explicitly near the
11024beginning of your program.
11025
11026@item handle_exception
11027@kindex handle_exception
11028@cindex remote serial stub, main routine
11029This is the central workhorse, but your program never calls it
11030explicitly---the setup code arranges for @code{handle_exception} to
11031run when a trap is triggered.
11032
11033@code{handle_exception} takes control when your program stops during
11034execution (for example, on a breakpoint), and mediates communications
11035with @value{GDBN} on the host machine. This is where the communications
11036protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 11037representative on the target machine. It begins by sending summary
104c1213
JM
11038information on the state of your program, then continues to execute,
11039retrieving and transmitting any information @value{GDBN} needs, until you
11040execute a @value{GDBN} command that makes your program resume; at that point,
11041@code{handle_exception} returns control to your own code on the target
5d161b24 11042machine.
104c1213
JM
11043
11044@item breakpoint
11045@cindex @code{breakpoint} subroutine, remote
11046Use this auxiliary subroutine to make your program contain a
11047breakpoint. Depending on the particular situation, this may be the only
11048way for @value{GDBN} to get control. For instance, if your target
11049machine has some sort of interrupt button, you won't need to call this;
11050pressing the interrupt button transfers control to
11051@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
11052simply receiving characters on the serial port may also trigger a trap;
11053again, in that situation, you don't need to call @code{breakpoint} from
11054your own program---simply running @samp{target remote} from the host
5d161b24 11055@value{GDBN} session gets control.
104c1213
JM
11056
11057Call @code{breakpoint} if none of these is true, or if you simply want
11058to make certain your program stops at a predetermined point for the
11059start of your debugging session.
11060@end table
11061
6d2ebf8b 11062@node Bootstrapping
6f05cf9f 11063@subsection What you must do for the stub
104c1213
JM
11064
11065@cindex remote stub, support routines
11066The debugging stubs that come with @value{GDBN} are set up for a particular
11067chip architecture, but they have no information about the rest of your
11068debugging target machine.
11069
11070First of all you need to tell the stub how to communicate with the
11071serial port.
11072
11073@table @code
11074@item int getDebugChar()
11075@kindex getDebugChar
11076Write this subroutine to read a single character from the serial port.
11077It may be identical to @code{getchar} for your target system; a
11078different name is used to allow you to distinguish the two if you wish.
11079
11080@item void putDebugChar(int)
11081@kindex putDebugChar
11082Write this subroutine to write a single character to the serial port.
5d161b24 11083It may be identical to @code{putchar} for your target system; a
104c1213
JM
11084different name is used to allow you to distinguish the two if you wish.
11085@end table
11086
11087@cindex control C, and remote debugging
11088@cindex interrupting remote targets
11089If you want @value{GDBN} to be able to stop your program while it is
11090running, you need to use an interrupt-driven serial driver, and arrange
11091for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
11092character). That is the character which @value{GDBN} uses to tell the
11093remote system to stop.
11094
11095Getting the debugging target to return the proper status to @value{GDBN}
11096probably requires changes to the standard stub; one quick and dirty way
11097is to just execute a breakpoint instruction (the ``dirty'' part is that
11098@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
11099
11100Other routines you need to supply are:
11101
11102@table @code
11103@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
11104@kindex exceptionHandler
11105Write this function to install @var{exception_address} in the exception
11106handling tables. You need to do this because the stub does not have any
11107way of knowing what the exception handling tables on your target system
11108are like (for example, the processor's table might be in @sc{rom},
11109containing entries which point to a table in @sc{ram}).
11110@var{exception_number} is the exception number which should be changed;
11111its meaning is architecture-dependent (for example, different numbers
11112might represent divide by zero, misaligned access, etc). When this
11113exception occurs, control should be transferred directly to
11114@var{exception_address}, and the processor state (stack, registers,
11115and so on) should be just as it is when a processor exception occurs. So if
11116you want to use a jump instruction to reach @var{exception_address}, it
11117should be a simple jump, not a jump to subroutine.
11118
11119For the 386, @var{exception_address} should be installed as an interrupt
11120gate so that interrupts are masked while the handler runs. The gate
11121should be at privilege level 0 (the most privileged level). The
11122@sc{sparc} and 68k stubs are able to mask interrupts themselves without
11123help from @code{exceptionHandler}.
11124
11125@item void flush_i_cache()
11126@kindex flush_i_cache
d4f3574e 11127On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
11128instruction cache, if any, on your target machine. If there is no
11129instruction cache, this subroutine may be a no-op.
11130
11131On target machines that have instruction caches, @value{GDBN} requires this
11132function to make certain that the state of your program is stable.
11133@end table
11134
11135@noindent
11136You must also make sure this library routine is available:
11137
11138@table @code
11139@item void *memset(void *, int, int)
11140@kindex memset
11141This is the standard library function @code{memset} that sets an area of
11142memory to a known value. If you have one of the free versions of
11143@code{libc.a}, @code{memset} can be found there; otherwise, you must
11144either obtain it from your hardware manufacturer, or write your own.
11145@end table
11146
11147If you do not use the GNU C compiler, you may need other standard
11148library subroutines as well; this varies from one stub to another,
11149but in general the stubs are likely to use any of the common library
d4f3574e 11150subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
11151
11152
6d2ebf8b 11153@node Debug Session
6f05cf9f 11154@subsection Putting it all together
104c1213
JM
11155
11156@cindex remote serial debugging summary
11157In summary, when your program is ready to debug, you must follow these
11158steps.
11159
11160@enumerate
11161@item
6d2ebf8b 11162Make sure you have defined the supporting low-level routines
104c1213
JM
11163(@pxref{Bootstrapping,,What you must do for the stub}):
11164@display
11165@code{getDebugChar}, @code{putDebugChar},
11166@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
11167@end display
11168
11169@item
11170Insert these lines near the top of your program:
11171
474c8240 11172@smallexample
104c1213
JM
11173set_debug_traps();
11174breakpoint();
474c8240 11175@end smallexample
104c1213
JM
11176
11177@item
11178For the 680x0 stub only, you need to provide a variable called
11179@code{exceptionHook}. Normally you just use:
11180
474c8240 11181@smallexample
104c1213 11182void (*exceptionHook)() = 0;
474c8240 11183@end smallexample
104c1213 11184
d4f3574e 11185@noindent
104c1213 11186but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 11187function in your program, that function is called when
104c1213
JM
11188@code{@value{GDBN}} continues after stopping on a trap (for example, bus
11189error). The function indicated by @code{exceptionHook} is called with
11190one parameter: an @code{int} which is the exception number.
11191
11192@item
11193Compile and link together: your program, the @value{GDBN} debugging stub for
11194your target architecture, and the supporting subroutines.
11195
11196@item
11197Make sure you have a serial connection between your target machine and
11198the @value{GDBN} host, and identify the serial port on the host.
11199
11200@item
11201@c The "remote" target now provides a `load' command, so we should
11202@c document that. FIXME.
11203Download your program to your target machine (or get it there by
11204whatever means the manufacturer provides), and start it.
11205
11206@item
07f31aa6
DJ
11207Start @value{GDBN} on the host, and connect to the target
11208(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 11209
104c1213
JM
11210@end enumerate
11211
8e04817f
AC
11212@node Configurations
11213@chapter Configuration-Specific Information
104c1213 11214
8e04817f
AC
11215While nearly all @value{GDBN} commands are available for all native and
11216cross versions of the debugger, there are some exceptions. This chapter
11217describes things that are only available in certain configurations.
104c1213 11218
8e04817f
AC
11219There are three major categories of configurations: native
11220configurations, where the host and target are the same, embedded
11221operating system configurations, which are usually the same for several
11222different processor architectures, and bare embedded processors, which
11223are quite different from each other.
104c1213 11224
8e04817f
AC
11225@menu
11226* Native::
11227* Embedded OS::
11228* Embedded Processors::
11229* Architectures::
11230@end menu
104c1213 11231
8e04817f
AC
11232@node Native
11233@section Native
104c1213 11234
8e04817f
AC
11235This section describes details specific to particular native
11236configurations.
6cf7e474 11237
8e04817f
AC
11238@menu
11239* HP-UX:: HP-UX
11240* SVR4 Process Information:: SVR4 process information
11241* DJGPP Native:: Features specific to the DJGPP port
78c47bea 11242* Cygwin Native:: Features specific to the Cygwin port
8e04817f 11243@end menu
6cf7e474 11244
8e04817f
AC
11245@node HP-UX
11246@subsection HP-UX
104c1213 11247
8e04817f
AC
11248On HP-UX systems, if you refer to a function or variable name that
11249begins with a dollar sign, @value{GDBN} searches for a user or system
11250name first, before it searches for a convenience variable.
104c1213 11251
8e04817f
AC
11252@node SVR4 Process Information
11253@subsection SVR4 process information
104c1213 11254
8e04817f
AC
11255@kindex /proc
11256@cindex process image
104c1213 11257
8e04817f
AC
11258Many versions of SVR4 provide a facility called @samp{/proc} that can be
11259used to examine the image of a running process using file-system
11260subroutines. If @value{GDBN} is configured for an operating system with
11261this facility, the command @code{info proc} is available to report on
11262several kinds of information about the process running your program.
11263@code{info proc} works only on SVR4 systems that include the
11264@code{procfs} code. This includes OSF/1 (Digital Unix), Solaris, Irix,
1104b9e7 11265and Unixware, but not HP-UX or @sc{gnu}/Linux, for example.
104c1213 11266
8e04817f
AC
11267@table @code
11268@kindex info proc
11269@item info proc
11270Summarize available information about the process.
6cf7e474 11271
8e04817f
AC
11272@kindex info proc mappings
11273@item info proc mappings
11274Report on the address ranges accessible in the program, with information
11275on whether your program may read, write, or execute each range.
11276@ignore
11277@comment These sub-options of 'info proc' were not included when
11278@comment procfs.c was re-written. Keep their descriptions around
11279@comment against the day when someone finds the time to put them back in.
11280@kindex info proc times
11281@item info proc times
11282Starting time, user CPU time, and system CPU time for your program and
11283its children.
6cf7e474 11284
8e04817f
AC
11285@kindex info proc id
11286@item info proc id
11287Report on the process IDs related to your program: its own process ID,
11288the ID of its parent, the process group ID, and the session ID.
104c1213 11289
8e04817f
AC
11290@kindex info proc status
11291@item info proc status
11292General information on the state of the process. If the process is
11293stopped, this report includes the reason for stopping, and any signal
11294received.
d4f3574e 11295
8e04817f
AC
11296@item info proc all
11297Show all the above information about the process.
11298@end ignore
11299@end table
104c1213 11300
8e04817f
AC
11301@node DJGPP Native
11302@subsection Features for Debugging @sc{djgpp} Programs
11303@cindex @sc{djgpp} debugging
11304@cindex native @sc{djgpp} debugging
11305@cindex MS-DOS-specific commands
104c1213 11306
8e04817f
AC
11307@sc{djgpp} is the port of @sc{gnu} development tools to MS-DOS and
11308MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
11309that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
11310top of real-mode DOS systems and their emulations.
104c1213 11311
8e04817f
AC
11312@value{GDBN} supports native debugging of @sc{djgpp} programs, and
11313defines a few commands specific to the @sc{djgpp} port. This
11314subsection describes those commands.
104c1213 11315
8e04817f
AC
11316@table @code
11317@kindex info dos
11318@item info dos
11319This is a prefix of @sc{djgpp}-specific commands which print
11320information about the target system and important OS structures.
f1251bdd 11321
8e04817f
AC
11322@kindex sysinfo
11323@cindex MS-DOS system info
11324@cindex free memory information (MS-DOS)
11325@item info dos sysinfo
11326This command displays assorted information about the underlying
11327platform: the CPU type and features, the OS version and flavor, the
11328DPMI version, and the available conventional and DPMI memory.
104c1213 11329
8e04817f
AC
11330@cindex GDT
11331@cindex LDT
11332@cindex IDT
11333@cindex segment descriptor tables
11334@cindex descriptor tables display
11335@item info dos gdt
11336@itemx info dos ldt
11337@itemx info dos idt
11338These 3 commands display entries from, respectively, Global, Local,
11339and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
11340tables are data structures which store a descriptor for each segment
11341that is currently in use. The segment's selector is an index into a
11342descriptor table; the table entry for that index holds the
11343descriptor's base address and limit, and its attributes and access
11344rights.
104c1213 11345
8e04817f
AC
11346A typical @sc{djgpp} program uses 3 segments: a code segment, a data
11347segment (used for both data and the stack), and a DOS segment (which
11348allows access to DOS/BIOS data structures and absolute addresses in
11349conventional memory). However, the DPMI host will usually define
11350additional segments in order to support the DPMI environment.
d4f3574e 11351
8e04817f
AC
11352@cindex garbled pointers
11353These commands allow to display entries from the descriptor tables.
11354Without an argument, all entries from the specified table are
11355displayed. An argument, which should be an integer expression, means
11356display a single entry whose index is given by the argument. For
11357example, here's a convenient way to display information about the
11358debugged program's data segment:
104c1213 11359
8e04817f
AC
11360@smallexample
11361@exdent @code{(@value{GDBP}) info dos ldt $ds}
11362@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
11363@end smallexample
104c1213 11364
8e04817f
AC
11365@noindent
11366This comes in handy when you want to see whether a pointer is outside
11367the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 11368
8e04817f
AC
11369@cindex page tables display (MS-DOS)
11370@item info dos pde
11371@itemx info dos pte
11372These two commands display entries from, respectively, the Page
11373Directory and the Page Tables. Page Directories and Page Tables are
11374data structures which control how virtual memory addresses are mapped
11375into physical addresses. A Page Table includes an entry for every
11376page of memory that is mapped into the program's address space; there
11377may be several Page Tables, each one holding up to 4096 entries. A
11378Page Directory has up to 4096 entries, one each for every Page Table
11379that is currently in use.
104c1213 11380
8e04817f
AC
11381Without an argument, @kbd{info dos pde} displays the entire Page
11382Directory, and @kbd{info dos pte} displays all the entries in all of
11383the Page Tables. An argument, an integer expression, given to the
11384@kbd{info dos pde} command means display only that entry from the Page
11385Directory table. An argument given to the @kbd{info dos pte} command
11386means display entries from a single Page Table, the one pointed to by
11387the specified entry in the Page Directory.
104c1213 11388
8e04817f
AC
11389@cindex direct memory access (DMA) on MS-DOS
11390These commands are useful when your program uses @dfn{DMA} (Direct
11391Memory Access), which needs physical addresses to program the DMA
11392controller.
104c1213 11393
8e04817f 11394These commands are supported only with some DPMI servers.
104c1213 11395
8e04817f
AC
11396@cindex physical address from linear address
11397@item info dos address-pte @var{addr}
11398This command displays the Page Table entry for a specified linear
11399address. The argument linear address @var{addr} should already have the
11400appropriate segment's base address added to it, because this command
11401accepts addresses which may belong to @emph{any} segment. For
11402example, here's how to display the Page Table entry for the page where
11403the variable @code{i} is stored:
104c1213 11404
8e04817f
AC
11405@smallexample
11406@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
11407@exdent @code{Page Table entry for address 0x11a00d30:}
11408@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
11409@end smallexample
104c1213 11410
8e04817f
AC
11411@noindent
11412This says that @code{i} is stored at offset @code{0xd30} from the page
11413whose physical base address is @code{0x02698000}, and prints all the
11414attributes of that page.
104c1213 11415
8e04817f
AC
11416Note that you must cast the addresses of variables to a @code{char *},
11417since otherwise the value of @code{__djgpp_base_address}, the base
11418address of all variables and functions in a @sc{djgpp} program, will
11419be added using the rules of C pointer arithmetics: if @code{i} is
11420declared an @code{int}, @value{GDBN} will add 4 times the value of
11421@code{__djgpp_base_address} to the address of @code{i}.
104c1213 11422
8e04817f
AC
11423Here's another example, it displays the Page Table entry for the
11424transfer buffer:
104c1213 11425
8e04817f
AC
11426@smallexample
11427@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
11428@exdent @code{Page Table entry for address 0x29110:}
11429@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
11430@end smallexample
104c1213 11431
8e04817f
AC
11432@noindent
11433(The @code{+ 3} offset is because the transfer buffer's address is the
114343rd member of the @code{_go32_info_block} structure.) The output of
11435this command clearly shows that addresses in conventional memory are
11436mapped 1:1, i.e.@: the physical and linear addresses are identical.
104c1213 11437
8e04817f
AC
11438This command is supported only with some DPMI servers.
11439@end table
104c1213 11440
78c47bea
PM
11441@node Cygwin Native
11442@subsection Features for Debugging MS Windows PE executables
11443@cindex MS Windows debugging
11444@cindex native Cygwin debugging
11445@cindex Cygwin-specific commands
11446
be448670
CF
11447@value{GDBN} supports native debugging of MS Windows programs, including
11448DLLs with and without symbolic debugging information. There are various
11449additional Cygwin-specific commands, described in this subsection. The
11450subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
11451that have no debugging symbols.
11452
78c47bea
PM
11453
11454@table @code
11455@kindex info w32
11456@item info w32
11457This is a prefix of MS Windows specific commands which print
11458information about the target system and important OS structures.
11459
11460@item info w32 selector
11461This command displays information returned by
11462the Win32 API @code{GetThreadSelectorEntry} function.
11463It takes an optional argument that is evaluated to
11464a long value to give the information about this given selector.
11465Without argument, this command displays information
11466about the the six segment registers.
11467
11468@kindex info dll
11469@item info dll
11470This is a Cygwin specific alias of info shared.
11471
11472@kindex dll-symbols
11473@item dll-symbols
11474This command loads symbols from a dll similarly to
11475add-sym command but without the need to specify a base address.
11476
11477@kindex set new-console
11478@item set new-console @var{mode}
11479If @var{mode} is @code{on} the debuggee will
11480be started in a new console on next start.
11481If @var{mode} is @code{off}i, the debuggee will
11482be started in the same console as the debugger.
11483
11484@kindex show new-console
11485@item show new-console
11486Displays whether a new console is used
11487when the debuggee is started.
11488
11489@kindex set new-group
11490@item set new-group @var{mode}
11491This boolean value controls whether the debuggee should
11492start a new group or stay in the same group as the debugger.
11493This affects the way the Windows OS handles
11494Ctrl-C.
11495
11496@kindex show new-group
11497@item show new-group
11498Displays current value of new-group boolean.
11499
11500@kindex set debugevents
11501@item set debugevents
11502This boolean value adds debug output concerning events seen by the debugger.
11503
11504@kindex set debugexec
11505@item set debugexec
11506This boolean value adds debug output concerning execute events
11507seen by the debugger.
11508
11509@kindex set debugexceptions
11510@item set debugexceptions
11511This boolean value adds debug ouptut concerning exception events
11512seen by the debugger.
11513
11514@kindex set debugmemory
11515@item set debugmemory
11516This boolean value adds debug ouptut concerning memory events
11517seen by the debugger.
11518
11519@kindex set shell
11520@item set shell
11521This boolean values specifies whether the debuggee is called
11522via a shell or directly (default value is on).
11523
11524@kindex show shell
11525@item show shell
11526Displays if the debuggee will be started with a shell.
11527
11528@end table
11529
be448670
CF
11530@menu
11531* Non-debug DLL symbols:: Support for DLLs without debugging symbols
11532@end menu
11533
11534@node Non-debug DLL symbols
11535@subsubsection Support for DLLs without debugging symbols
11536@cindex DLLs with no debugging symbols
11537@cindex Minimal symbols and DLLs
11538
11539Very often on windows, some of the DLLs that your program relies on do
11540not include symbolic debugging information (for example,
11541@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
11542symbols in a DLL, it relies on the minimal amount of symbolic
11543information contained in the DLL's export table. This subsubsection
11544describes working with such symbols, known internally to @value{GDBN} as
11545``minimal symbols''.
11546
11547Note that before the debugged program has started execution, no DLLs
11548will have been loaded. The easiest way around this problem is simply to
11549start the program --- either by setting a breakpoint or letting the
11550program run once to completion. It is also possible to force
11551@value{GDBN} to load a particular DLL before starting the executable ---
11552see the shared library information in @pxref{Files} or the
11553@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
11554explicitly loading symbols from a DLL with no debugging information will
11555cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
11556which may adversely affect symbol lookup performance.
11557
11558@subsubsection DLL name prefixes
11559
11560In keeping with the naming conventions used by the Microsoft debugging
11561tools, DLL export symbols are made available with a prefix based on the
11562DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
11563also entered into the symbol table, so @code{CreateFileA} is often
11564sufficient. In some cases there will be name clashes within a program
11565(particularly if the executable itself includes full debugging symbols)
11566necessitating the use of the fully qualified name when referring to the
11567contents of the DLL. Use single-quotes around the name to avoid the
11568exclamation mark (``!'') being interpreted as a language operator.
11569
11570Note that the internal name of the DLL may be all upper-case, even
11571though the file name of the DLL is lower-case, or vice-versa. Since
11572symbols within @value{GDBN} are @emph{case-sensitive} this may cause
11573some confusion. If in doubt, try the @code{info functions} and
11574@code{info variables} commands or even @code{maint print msymbols} (see
11575@pxref{Symbols}). Here's an example:
11576
11577@smallexample
11578(gdb) info function CreateFileA
11579All functions matching regular expression "CreateFileA":
11580
11581Non-debugging symbols:
115820x77e885f4 CreateFileA
115830x77e885f4 KERNEL32!CreateFileA
11584@end smallexample
11585
11586@smallexample
11587(gdb) info function !
11588All functions matching regular expression "!":
11589
11590Non-debugging symbols:
115910x6100114c cygwin1!__assert
115920x61004034 cygwin1!_dll_crt0@@0
115930x61004240 cygwin1!dll_crt0(per_process *)
11594[etc...]
11595@end smallexample
11596
11597@subsubsection Working with minimal symbols
11598
11599Symbols extracted from a DLL's export table do not contain very much
11600type information. All that @value{GDBN} can do is guess whether a symbol
11601refers to a function or variable depending on the linker section that
11602contains the symbol. Also note that the actual contents of the memory
11603contained in a DLL are not available unless the program is running. This
11604means that you cannot examine the contents of a variable or disassemble
11605a function within a DLL without a running program.
11606
11607Variables are generally treated as pointers and dereferenced
11608automatically. For this reason, it is often necessary to prefix a
11609variable name with the address-of operator (``&'') and provide explicit
11610type information in the command. Here's an example of the type of
11611problem:
11612
11613@smallexample
11614(gdb) print 'cygwin1!__argv'
11615$1 = 268572168
11616@end smallexample
11617
11618@smallexample
11619(gdb) x 'cygwin1!__argv'
116200x10021610: "\230y\""
11621@end smallexample
11622
11623And two possible solutions:
11624
11625@smallexample
11626(gdb) print ((char **)'cygwin1!__argv')[0]
11627$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
11628@end smallexample
11629
11630@smallexample
11631(gdb) x/2x &'cygwin1!__argv'
116320x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
11633(gdb) x/x 0x10021608
116340x10021608: 0x0022fd98
11635(gdb) x/s 0x0022fd98
116360x22fd98: "/cygdrive/c/mydirectory/myprogram"
11637@end smallexample
11638
11639Setting a break point within a DLL is possible even before the program
11640starts execution. However, under these circumstances, @value{GDBN} can't
11641examine the initial instructions of the function in order to skip the
11642function's frame set-up code. You can work around this by using ``*&''
11643to set the breakpoint at a raw memory address:
11644
11645@smallexample
11646(gdb) break *&'python22!PyOS_Readline'
11647Breakpoint 1 at 0x1e04eff0
11648@end smallexample
11649
11650The author of these extensions is not entirely convinced that setting a
11651break point within a shared DLL like @file{kernel32.dll} is completely
11652safe.
11653
8e04817f
AC
11654@node Embedded OS
11655@section Embedded Operating Systems
104c1213 11656
8e04817f
AC
11657This section describes configurations involving the debugging of
11658embedded operating systems that are available for several different
11659architectures.
d4f3574e 11660
8e04817f
AC
11661@menu
11662* VxWorks:: Using @value{GDBN} with VxWorks
11663@end menu
104c1213 11664
8e04817f
AC
11665@value{GDBN} includes the ability to debug programs running on
11666various real-time operating systems.
104c1213 11667
8e04817f
AC
11668@node VxWorks
11669@subsection Using @value{GDBN} with VxWorks
104c1213 11670
8e04817f 11671@cindex VxWorks
104c1213 11672
8e04817f 11673@table @code
104c1213 11674
8e04817f
AC
11675@kindex target vxworks
11676@item target vxworks @var{machinename}
11677A VxWorks system, attached via TCP/IP. The argument @var{machinename}
11678is the target system's machine name or IP address.
104c1213 11679
8e04817f 11680@end table
104c1213 11681
8e04817f
AC
11682On VxWorks, @code{load} links @var{filename} dynamically on the
11683current target system as well as adding its symbols in @value{GDBN}.
104c1213 11684
8e04817f
AC
11685@value{GDBN} enables developers to spawn and debug tasks running on networked
11686VxWorks targets from a Unix host. Already-running tasks spawned from
11687the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
11688both the Unix host and on the VxWorks target. The program
11689@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
11690installed with the name @code{vxgdb}, to distinguish it from a
11691@value{GDBN} for debugging programs on the host itself.)
104c1213 11692
8e04817f
AC
11693@table @code
11694@item VxWorks-timeout @var{args}
11695@kindex vxworks-timeout
11696All VxWorks-based targets now support the option @code{vxworks-timeout}.
11697This option is set by the user, and @var{args} represents the number of
11698seconds @value{GDBN} waits for responses to rpc's. You might use this if
11699your VxWorks target is a slow software simulator or is on the far side
11700of a thin network line.
11701@end table
104c1213 11702
8e04817f
AC
11703The following information on connecting to VxWorks was current when
11704this manual was produced; newer releases of VxWorks may use revised
11705procedures.
104c1213 11706
8e04817f
AC
11707@kindex INCLUDE_RDB
11708To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
11709to include the remote debugging interface routines in the VxWorks
11710library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
11711VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
11712kernel. The resulting kernel contains @file{rdb.a}, and spawns the
11713source debugging task @code{tRdbTask} when VxWorks is booted. For more
11714information on configuring and remaking VxWorks, see the manufacturer's
11715manual.
11716@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 11717
8e04817f
AC
11718Once you have included @file{rdb.a} in your VxWorks system image and set
11719your Unix execution search path to find @value{GDBN}, you are ready to
11720run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
11721@code{vxgdb}, depending on your installation).
104c1213 11722
8e04817f 11723@value{GDBN} comes up showing the prompt:
104c1213 11724
474c8240 11725@smallexample
8e04817f 11726(vxgdb)
474c8240 11727@end smallexample
104c1213 11728
8e04817f
AC
11729@menu
11730* VxWorks Connection:: Connecting to VxWorks
11731* VxWorks Download:: VxWorks download
11732* VxWorks Attach:: Running tasks
11733@end menu
104c1213 11734
8e04817f
AC
11735@node VxWorks Connection
11736@subsubsection Connecting to VxWorks
104c1213 11737
8e04817f
AC
11738The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
11739network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 11740
474c8240 11741@smallexample
8e04817f 11742(vxgdb) target vxworks tt
474c8240 11743@end smallexample
104c1213 11744
8e04817f
AC
11745@need 750
11746@value{GDBN} displays messages like these:
104c1213 11747
8e04817f
AC
11748@smallexample
11749Attaching remote machine across net...
11750Connected to tt.
11751@end smallexample
104c1213 11752
8e04817f
AC
11753@need 1000
11754@value{GDBN} then attempts to read the symbol tables of any object modules
11755loaded into the VxWorks target since it was last booted. @value{GDBN} locates
11756these files by searching the directories listed in the command search
11757path (@pxref{Environment, ,Your program's environment}); if it fails
11758to find an object file, it displays a message such as:
5d161b24 11759
474c8240 11760@smallexample
8e04817f 11761prog.o: No such file or directory.
474c8240 11762@end smallexample
104c1213 11763
8e04817f
AC
11764When this happens, add the appropriate directory to the search path with
11765the @value{GDBN} command @code{path}, and execute the @code{target}
11766command again.
104c1213 11767
8e04817f
AC
11768@node VxWorks Download
11769@subsubsection VxWorks download
104c1213 11770
8e04817f
AC
11771@cindex download to VxWorks
11772If you have connected to the VxWorks target and you want to debug an
11773object that has not yet been loaded, you can use the @value{GDBN}
11774@code{load} command to download a file from Unix to VxWorks
11775incrementally. The object file given as an argument to the @code{load}
11776command is actually opened twice: first by the VxWorks target in order
11777to download the code, then by @value{GDBN} in order to read the symbol
11778table. This can lead to problems if the current working directories on
11779the two systems differ. If both systems have NFS mounted the same
11780filesystems, you can avoid these problems by using absolute paths.
11781Otherwise, it is simplest to set the working directory on both systems
11782to the directory in which the object file resides, and then to reference
11783the file by its name, without any path. For instance, a program
11784@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
11785and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
11786program, type this on VxWorks:
104c1213 11787
474c8240 11788@smallexample
8e04817f 11789-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 11790@end smallexample
104c1213 11791
8e04817f
AC
11792@noindent
11793Then, in @value{GDBN}, type:
104c1213 11794
474c8240 11795@smallexample
8e04817f
AC
11796(vxgdb) cd @var{hostpath}/vw/demo/rdb
11797(vxgdb) load prog.o
474c8240 11798@end smallexample
104c1213 11799
8e04817f 11800@value{GDBN} displays a response similar to this:
104c1213 11801
8e04817f
AC
11802@smallexample
11803Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
11804@end smallexample
104c1213 11805
8e04817f
AC
11806You can also use the @code{load} command to reload an object module
11807after editing and recompiling the corresponding source file. Note that
11808this makes @value{GDBN} delete all currently-defined breakpoints,
11809auto-displays, and convenience variables, and to clear the value
11810history. (This is necessary in order to preserve the integrity of
11811debugger's data structures that reference the target system's symbol
11812table.)
104c1213 11813
8e04817f
AC
11814@node VxWorks Attach
11815@subsubsection Running tasks
104c1213
JM
11816
11817@cindex running VxWorks tasks
11818You can also attach to an existing task using the @code{attach} command as
11819follows:
11820
474c8240 11821@smallexample
104c1213 11822(vxgdb) attach @var{task}
474c8240 11823@end smallexample
104c1213
JM
11824
11825@noindent
11826where @var{task} is the VxWorks hexadecimal task ID. The task can be running
11827or suspended when you attach to it. Running tasks are suspended at
11828the time of attachment.
11829
6d2ebf8b 11830@node Embedded Processors
104c1213
JM
11831@section Embedded Processors
11832
11833This section goes into details specific to particular embedded
11834configurations.
11835
7d86b5d5 11836
104c1213 11837@menu
104c1213 11838* ARM:: ARM
172c2a43
KI
11839* H8/300:: Renesas H8/300
11840* H8/500:: Renesas H8/500
11841* M32R/D:: Renesas M32R/D
104c1213 11842* M68K:: Motorola M68K
104c1213 11843* MIPS Embedded:: MIPS Embedded
a37295f9 11844* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
11845* PA:: HP PA Embedded
11846* PowerPC: PowerPC
172c2a43 11847* SH:: Renesas SH
104c1213
JM
11848* Sparclet:: Tsqware Sparclet
11849* Sparclite:: Fujitsu Sparclite
11850* ST2000:: Tandem ST2000
11851* Z8000:: Zilog Z8000
11852@end menu
11853
6d2ebf8b 11854@node ARM
104c1213
JM
11855@subsection ARM
11856
11857@table @code
11858
8e04817f
AC
11859@kindex target rdi
11860@item target rdi @var{dev}
11861ARM Angel monitor, via RDI library interface to ADP protocol. You may
11862use this target to communicate with both boards running the Angel
11863monitor, or with the EmbeddedICE JTAG debug device.
11864
11865@kindex target rdp
11866@item target rdp @var{dev}
11867ARM Demon monitor.
11868
11869@end table
11870
11871@node H8/300
172c2a43 11872@subsection Renesas H8/300
8e04817f
AC
11873
11874@table @code
11875
11876@kindex target hms@r{, with H8/300}
11877@item target hms @var{dev}
172c2a43 11878A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
11879Use special commands @code{device} and @code{speed} to control the serial
11880line and the communications speed used.
11881
11882@kindex target e7000@r{, with H8/300}
11883@item target e7000 @var{dev}
172c2a43 11884E7000 emulator for Renesas H8 and SH.
8e04817f
AC
11885
11886@kindex target sh3@r{, with H8/300}
11887@kindex target sh3e@r{, with H8/300}
11888@item target sh3 @var{dev}
11889@itemx target sh3e @var{dev}
172c2a43 11890Renesas SH-3 and SH-3E target systems.
8e04817f
AC
11891
11892@end table
11893
11894@cindex download to H8/300 or H8/500
11895@cindex H8/300 or H8/500 download
172c2a43
KI
11896@cindex download to Renesas SH
11897@cindex Renesas SH download
11898When you select remote debugging to a Renesas SH, H8/300, or H8/500
11899board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
11900board and also opens it as the current executable target for
11901@value{GDBN} on your host (like the @code{file} command).
11902
11903@value{GDBN} needs to know these things to talk to your
172c2a43 11904Renesas SH, H8/300, or H8/500:
8e04817f
AC
11905
11906@enumerate
11907@item
11908that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
11909for Renesas microprocessors, or @samp{target e7000}, the in-circuit
11910emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
11911the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
11912H8/300, or H8/500.)
11913
11914@item
172c2a43 11915what serial device connects your host to your Renesas board (the first
8e04817f
AC
11916serial device available on your host is the default).
11917
11918@item
11919what speed to use over the serial device.
11920@end enumerate
11921
11922@menu
172c2a43
KI
11923* Renesas Boards:: Connecting to Renesas boards.
11924* Renesas ICE:: Using the E7000 In-Circuit Emulator.
11925* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
11926@end menu
11927
172c2a43
KI
11928@node Renesas Boards
11929@subsubsection Connecting to Renesas boards
8e04817f
AC
11930
11931@c only for Unix hosts
11932@kindex device
172c2a43 11933@cindex serial device, Renesas micros
8e04817f
AC
11934Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
11935need to explicitly set the serial device. The default @var{port} is the
11936first available port on your host. This is only necessary on Unix
11937hosts, where it is typically something like @file{/dev/ttya}.
11938
11939@kindex speed
172c2a43 11940@cindex serial line speed, Renesas micros
8e04817f
AC
11941@code{@value{GDBN}} has another special command to set the communications
11942speed: @samp{speed @var{bps}}. This command also is only used from Unix
11943hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
11944the DOS @code{mode} command (for instance,
11945@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
11946
11947The @samp{device} and @samp{speed} commands are available only when you
172c2a43 11948use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
11949use a DOS host,
11950@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
11951called @code{asynctsr} to communicate with the development board
11952through a PC serial port. You must also use the DOS @code{mode} command
11953to set up the serial port on the DOS side.
11954
11955The following sample session illustrates the steps needed to start a
11956program under @value{GDBN} control on an H8/300. The example uses a
11957sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 11958the Renesas SH and the H8/500.
8e04817f
AC
11959
11960First hook up your development board. In this example, we use a
11961board attached to serial port @code{COM2}; if you use a different serial
11962port, substitute its name in the argument of the @code{mode} command.
11963When you call @code{asynctsr}, the auxiliary comms program used by the
11964debugger, you give it just the numeric part of the serial port's name;
11965for example, @samp{asyncstr 2} below runs @code{asyncstr} on
11966@code{COM2}.
11967
474c8240 11968@smallexample
8e04817f
AC
11969C:\H8300\TEST> asynctsr 2
11970C:\H8300\TEST> mode com2:9600,n,8,1,p
11971
11972Resident portion of MODE loaded
11973
11974COM2: 9600, n, 8, 1, p
11975
474c8240 11976@end smallexample
8e04817f
AC
11977
11978@quotation
11979@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
11980@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
11981disable it, or even boot without it, to use @code{asynctsr} to control
11982your development board.
11983@end quotation
11984
11985@kindex target hms@r{, and serial protocol}
11986Now that serial communications are set up, and the development board is
11987connected, you can start up @value{GDBN}. Call @code{@value{GDBP}} with
11988the name of your program as the argument. @code{@value{GDBN}} prompts
11989you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
11990commands to begin your debugging session: @samp{target hms} to specify
172c2a43 11991cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
11992download your program to the board. @code{load} displays the names of
11993the program's sections, and a @samp{*} for each 2K of data downloaded.
11994(If you want to refresh @value{GDBN} data on symbols or on the
11995executable file without downloading, use the @value{GDBN} commands
11996@code{file} or @code{symbol-file}. These commands, and @code{load}
11997itself, are described in @ref{Files,,Commands to specify files}.)
11998
11999@smallexample
12000(eg-C:\H8300\TEST) @value{GDBP} t.x
12001@value{GDBN} is free software and you are welcome to distribute copies
12002 of it under certain conditions; type "show copying" to see
12003 the conditions.
12004There is absolutely no warranty for @value{GDBN}; type "show warranty"
12005for details.
12006@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
12007(@value{GDBP}) target hms
12008Connected to remote H8/300 HMS system.
12009(@value{GDBP}) load t.x
12010.text : 0x8000 .. 0xabde ***********
12011.data : 0xabde .. 0xad30 *
12012.stack : 0xf000 .. 0xf014 *
12013@end smallexample
12014
12015At this point, you're ready to run or debug your program. From here on,
12016you can use all the usual @value{GDBN} commands. The @code{break} command
12017sets breakpoints; the @code{run} command starts your program;
12018@code{print} or @code{x} display data; the @code{continue} command
12019resumes execution after stopping at a breakpoint. You can use the
12020@code{help} command at any time to find out more about @value{GDBN} commands.
12021
12022Remember, however, that @emph{operating system} facilities aren't
12023available on your development board; for example, if your program hangs,
12024you can't send an interrupt---but you can press the @sc{reset} switch!
12025
12026Use the @sc{reset} button on the development board
12027@itemize @bullet
12028@item
12029to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
12030no way to pass an interrupt signal to the development board); and
12031
12032@item
12033to return to the @value{GDBN} command prompt after your program finishes
12034normally. The communications protocol provides no other way for @value{GDBN}
12035to detect program completion.
12036@end itemize
12037
12038In either case, @value{GDBN} sees the effect of a @sc{reset} on the
12039development board as a ``normal exit'' of your program.
12040
172c2a43 12041@node Renesas ICE
8e04817f
AC
12042@subsubsection Using the E7000 in-circuit emulator
12043
172c2a43 12044@kindex target e7000@r{, with Renesas ICE}
8e04817f 12045You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 12046Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
12047e7000} command to connect @value{GDBN} to your E7000:
12048
12049@table @code
12050@item target e7000 @var{port} @var{speed}
12051Use this form if your E7000 is connected to a serial port. The
12052@var{port} argument identifies what serial port to use (for example,
12053@samp{com2}). The third argument is the line speed in bits per second
12054(for example, @samp{9600}).
12055
12056@item target e7000 @var{hostname}
12057If your E7000 is installed as a host on a TCP/IP network, you can just
12058specify its hostname; @value{GDBN} uses @code{telnet} to connect.
12059@end table
12060
172c2a43
KI
12061@node Renesas Special
12062@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
12063
12064Some @value{GDBN} commands are available only for the H8/300:
12065
12066@table @code
12067
12068@kindex set machine
12069@kindex show machine
12070@item set machine h8300
12071@itemx set machine h8300h
12072Condition @value{GDBN} for one of the two variants of the H8/300
12073architecture with @samp{set machine}. You can use @samp{show machine}
12074to check which variant is currently in effect.
104c1213
JM
12075
12076@end table
12077
8e04817f
AC
12078@node H8/500
12079@subsection H8/500
104c1213
JM
12080
12081@table @code
12082
8e04817f
AC
12083@kindex set memory @var{mod}
12084@cindex memory models, H8/500
12085@item set memory @var{mod}
12086@itemx show memory
12087Specify which H8/500 memory model (@var{mod}) you are using with
12088@samp{set memory}; check which memory model is in effect with @samp{show
12089memory}. The accepted values for @var{mod} are @code{small},
12090@code{big}, @code{medium}, and @code{compact}.
104c1213 12091
8e04817f 12092@end table
104c1213 12093
8e04817f 12094@node M32R/D
172c2a43 12095@subsection Renesas M32R/D
8e04817f
AC
12096
12097@table @code
12098
12099@kindex target m32r
12100@item target m32r @var{dev}
172c2a43 12101Renesas M32R/D ROM monitor.
8e04817f 12102
fb3e19c0
KI
12103@kindex target m32rsdi
12104@item target m32rsdi @var{dev}
12105Renesas M32R SDI server, connected via parallel port to the board.
12106
8e04817f
AC
12107@end table
12108
12109@node M68K
12110@subsection M68k
12111
12112The Motorola m68k configuration includes ColdFire support, and
12113target command for the following ROM monitors.
12114
12115@table @code
12116
12117@kindex target abug
12118@item target abug @var{dev}
12119ABug ROM monitor for M68K.
12120
12121@kindex target cpu32bug
12122@item target cpu32bug @var{dev}
12123CPU32BUG monitor, running on a CPU32 (M68K) board.
12124
12125@kindex target dbug
12126@item target dbug @var{dev}
12127dBUG ROM monitor for Motorola ColdFire.
12128
12129@kindex target est
12130@item target est @var{dev}
12131EST-300 ICE monitor, running on a CPU32 (M68K) board.
12132
12133@kindex target rom68k
12134@item target rom68k @var{dev}
12135ROM 68K monitor, running on an M68K IDP board.
12136
12137@end table
12138
8e04817f
AC
12139@table @code
12140
12141@kindex target rombug
12142@item target rombug @var{dev}
12143ROMBUG ROM monitor for OS/9000.
12144
12145@end table
12146
8e04817f
AC
12147@node MIPS Embedded
12148@subsection MIPS Embedded
12149
12150@cindex MIPS boards
12151@value{GDBN} can use the MIPS remote debugging protocol to talk to a
12152MIPS board attached to a serial line. This is available when
12153you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 12154
8e04817f
AC
12155@need 1000
12156Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 12157
8e04817f
AC
12158@table @code
12159@item target mips @var{port}
12160@kindex target mips @var{port}
12161To run a program on the board, start up @code{@value{GDBP}} with the
12162name of your program as the argument. To connect to the board, use the
12163command @samp{target mips @var{port}}, where @var{port} is the name of
12164the serial port connected to the board. If the program has not already
12165been downloaded to the board, you may use the @code{load} command to
12166download it. You can then use all the usual @value{GDBN} commands.
104c1213 12167
8e04817f
AC
12168For example, this sequence connects to the target board through a serial
12169port, and loads and runs a program called @var{prog} through the
12170debugger:
104c1213 12171
474c8240 12172@smallexample
8e04817f
AC
12173host$ @value{GDBP} @var{prog}
12174@value{GDBN} is free software and @dots{}
12175(@value{GDBP}) target mips /dev/ttyb
12176(@value{GDBP}) load @var{prog}
12177(@value{GDBP}) run
474c8240 12178@end smallexample
104c1213 12179
8e04817f
AC
12180@item target mips @var{hostname}:@var{portnumber}
12181On some @value{GDBN} host configurations, you can specify a TCP
12182connection (for instance, to a serial line managed by a terminal
12183concentrator) instead of a serial port, using the syntax
12184@samp{@var{hostname}:@var{portnumber}}.
104c1213 12185
8e04817f
AC
12186@item target pmon @var{port}
12187@kindex target pmon @var{port}
12188PMON ROM monitor.
104c1213 12189
8e04817f
AC
12190@item target ddb @var{port}
12191@kindex target ddb @var{port}
12192NEC's DDB variant of PMON for Vr4300.
104c1213 12193
8e04817f
AC
12194@item target lsi @var{port}
12195@kindex target lsi @var{port}
12196LSI variant of PMON.
104c1213 12197
8e04817f
AC
12198@kindex target r3900
12199@item target r3900 @var{dev}
12200Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 12201
8e04817f
AC
12202@kindex target array
12203@item target array @var{dev}
12204Array Tech LSI33K RAID controller board.
104c1213 12205
8e04817f 12206@end table
104c1213 12207
104c1213 12208
8e04817f
AC
12209@noindent
12210@value{GDBN} also supports these special commands for MIPS targets:
104c1213 12211
8e04817f
AC
12212@table @code
12213@item set processor @var{args}
12214@itemx show processor
12215@kindex set processor @var{args}
12216@kindex show processor
12217Use the @code{set processor} command to set the type of MIPS
12218processor when you want to access processor-type-specific registers.
12219For example, @code{set processor @var{r3041}} tells @value{GDBN}
12220to use the CPU registers appropriate for the 3041 chip.
12221Use the @code{show processor} command to see what MIPS processor @value{GDBN}
12222is using. Use the @code{info reg} command to see what registers
12223@value{GDBN} is using.
104c1213 12224
8e04817f
AC
12225@item set mipsfpu double
12226@itemx set mipsfpu single
12227@itemx set mipsfpu none
12228@itemx show mipsfpu
12229@kindex set mipsfpu
12230@kindex show mipsfpu
12231@cindex MIPS remote floating point
12232@cindex floating point, MIPS remote
12233If your target board does not support the MIPS floating point
12234coprocessor, you should use the command @samp{set mipsfpu none} (if you
12235need this, you may wish to put the command in your @value{GDBN} init
12236file). This tells @value{GDBN} how to find the return value of
12237functions which return floating point values. It also allows
12238@value{GDBN} to avoid saving the floating point registers when calling
12239functions on the board. If you are using a floating point coprocessor
12240with only single precision floating point support, as on the @sc{r4650}
12241processor, use the command @samp{set mipsfpu single}. The default
12242double precision floating point coprocessor may be selected using
12243@samp{set mipsfpu double}.
104c1213 12244
8e04817f
AC
12245In previous versions the only choices were double precision or no
12246floating point, so @samp{set mipsfpu on} will select double precision
12247and @samp{set mipsfpu off} will select no floating point.
104c1213 12248
8e04817f
AC
12249As usual, you can inquire about the @code{mipsfpu} variable with
12250@samp{show mipsfpu}.
104c1213 12251
8e04817f
AC
12252@item set remotedebug @var{n}
12253@itemx show remotedebug
12254@kindex set remotedebug@r{, MIPS protocol}
12255@kindex show remotedebug@r{, MIPS protocol}
12256@cindex @code{remotedebug}, MIPS protocol
12257@cindex MIPS @code{remotedebug} protocol
12258@c FIXME! For this to be useful, you must know something about the MIPS
12259@c FIXME...protocol. Where is it described?
12260You can see some debugging information about communications with the board
12261by setting the @code{remotedebug} variable. If you set it to @code{1} using
12262@samp{set remotedebug 1}, every packet is displayed. If you set it
12263to @code{2}, every character is displayed. You can check the current value
12264at any time with the command @samp{show remotedebug}.
104c1213 12265
8e04817f
AC
12266@item set timeout @var{seconds}
12267@itemx set retransmit-timeout @var{seconds}
12268@itemx show timeout
12269@itemx show retransmit-timeout
12270@cindex @code{timeout}, MIPS protocol
12271@cindex @code{retransmit-timeout}, MIPS protocol
12272@kindex set timeout
12273@kindex show timeout
12274@kindex set retransmit-timeout
12275@kindex show retransmit-timeout
12276You can control the timeout used while waiting for a packet, in the MIPS
12277remote protocol, with the @code{set timeout @var{seconds}} command. The
12278default is 5 seconds. Similarly, you can control the timeout used while
12279waiting for an acknowledgement of a packet with the @code{set
12280retransmit-timeout @var{seconds}} command. The default is 3 seconds.
12281You can inspect both values with @code{show timeout} and @code{show
12282retransmit-timeout}. (These commands are @emph{only} available when
12283@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 12284
8e04817f
AC
12285The timeout set by @code{set timeout} does not apply when @value{GDBN}
12286is waiting for your program to stop. In that case, @value{GDBN} waits
12287forever because it has no way of knowing how long the program is going
12288to run before stopping.
12289@end table
104c1213 12290
a37295f9
MM
12291@node OpenRISC 1000
12292@subsection OpenRISC 1000
12293@cindex OpenRISC 1000
12294
12295@cindex or1k boards
12296See OR1k Architecture document (@uref{www.opencores.org}) for more information
12297about platform and commands.
12298
12299@table @code
12300
12301@kindex target jtag
12302@item target jtag jtag://@var{host}:@var{port}
12303
12304Connects to remote JTAG server.
12305JTAG remote server can be either an or1ksim or JTAG server,
12306connected via parallel port to the board.
12307
12308Example: @code{target jtag jtag://localhost:9999}
12309
12310@kindex or1ksim
12311@item or1ksim @var{command}
12312If connected to @code{or1ksim} OpenRISC 1000 Architectural
12313Simulator, proprietary commands can be executed.
12314
12315@kindex info or1k spr
12316@item info or1k spr
12317Displays spr groups.
12318
12319@item info or1k spr @var{group}
12320@itemx info or1k spr @var{groupno}
12321Displays register names in selected group.
12322
12323@item info or1k spr @var{group} @var{register}
12324@itemx info or1k spr @var{register}
12325@itemx info or1k spr @var{groupno} @var{registerno}
12326@itemx info or1k spr @var{registerno}
12327Shows information about specified spr register.
12328
12329@kindex spr
12330@item spr @var{group} @var{register} @var{value}
12331@itemx spr @var{register @var{value}}
12332@itemx spr @var{groupno} @var{registerno @var{value}}
12333@itemx spr @var{registerno @var{value}}
12334Writes @var{value} to specified spr register.
12335@end table
12336
12337Some implementations of OpenRISC 1000 Architecture also have hardware trace.
12338It is very similar to @value{GDBN} trace, except it does not interfere with normal
12339program execution and is thus much faster. Hardware breakpoints/watchpoint
12340triggers can be set using:
12341@table @code
12342@item $LEA/$LDATA
12343Load effective address/data
12344@item $SEA/$SDATA
12345Store effective address/data
12346@item $AEA/$ADATA
12347Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
12348@item $FETCH
12349Fetch data
12350@end table
12351
12352When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
12353@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
12354
12355@code{htrace} commands:
12356@cindex OpenRISC 1000 htrace
12357@table @code
12358@kindex hwatch
12359@item hwatch @var{conditional}
12360Set hardware watchpoint on combination of Load/Store Effecive Address(es)
12361or Data. For example:
12362
12363@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
12364
12365@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
12366
12367@kindex htrace info
12368@item htrace info
12369Display information about current HW trace configuration.
12370
12371@kindex htrace trigger
12372@item htrace trigger @var{conditional}
12373Set starting criteria for HW trace.
12374
12375@kindex htrace qualifier
12376@item htrace qualifier @var{conditional}
12377Set acquisition qualifier for HW trace.
12378
12379@kindex htrace stop
12380@item htrace stop @var{conditional}
12381Set HW trace stopping criteria.
12382
12383@kindex htrace record
f153cc92 12384@item htrace record [@var{data}]*
a37295f9
MM
12385Selects the data to be recorded, when qualifier is met and HW trace was
12386triggered.
12387
12388@kindex htrace enable
12389@item htrace enable
12390@kindex htrace disable
12391@itemx htrace disable
12392Enables/disables the HW trace.
12393
12394@kindex htrace rewind
f153cc92 12395@item htrace rewind [@var{filename}]
a37295f9
MM
12396Clears currently recorded trace data.
12397
12398If filename is specified, new trace file is made and any newly collected data
12399will be written there.
12400
12401@kindex htrace print
f153cc92 12402@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
12403Prints trace buffer, using current record configuration.
12404
12405@kindex htrace mode continuous
12406@item htrace mode continuous
12407Set continuous trace mode.
12408
12409@kindex htrace mode suspend
12410@item htrace mode suspend
12411Set suspend trace mode.
12412
12413@end table
12414
8e04817f
AC
12415@node PowerPC
12416@subsection PowerPC
104c1213
JM
12417
12418@table @code
104c1213 12419
8e04817f
AC
12420@kindex target dink32
12421@item target dink32 @var{dev}
12422DINK32 ROM monitor.
104c1213 12423
8e04817f
AC
12424@kindex target ppcbug
12425@item target ppcbug @var{dev}
12426@kindex target ppcbug1
12427@item target ppcbug1 @var{dev}
12428PPCBUG ROM monitor for PowerPC.
104c1213 12429
8e04817f
AC
12430@kindex target sds
12431@item target sds @var{dev}
12432SDS monitor, running on a PowerPC board (such as Motorola's ADS).
12433
12434@end table
12435
12436@node PA
12437@subsection HP PA Embedded
104c1213
JM
12438
12439@table @code
12440
8e04817f
AC
12441@kindex target op50n
12442@item target op50n @var{dev}
12443OP50N monitor, running on an OKI HPPA board.
12444
12445@kindex target w89k
12446@item target w89k @var{dev}
12447W89K monitor, running on a Winbond HPPA board.
104c1213
JM
12448
12449@end table
12450
8e04817f 12451@node SH
172c2a43 12452@subsection Renesas SH
104c1213
JM
12453
12454@table @code
12455
172c2a43 12456@kindex target hms@r{, with Renesas SH}
8e04817f 12457@item target hms @var{dev}
172c2a43 12458A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
12459commands @code{device} and @code{speed} to control the serial line and
12460the communications speed used.
104c1213 12461
172c2a43 12462@kindex target e7000@r{, with Renesas SH}
8e04817f 12463@item target e7000 @var{dev}
172c2a43 12464E7000 emulator for Renesas SH.
104c1213 12465
8e04817f
AC
12466@kindex target sh3@r{, with SH}
12467@kindex target sh3e@r{, with SH}
12468@item target sh3 @var{dev}
12469@item target sh3e @var{dev}
172c2a43 12470Renesas SH-3 and SH-3E target systems.
104c1213 12471
8e04817f 12472@end table
104c1213 12473
8e04817f
AC
12474@node Sparclet
12475@subsection Tsqware Sparclet
104c1213 12476
8e04817f
AC
12477@cindex Sparclet
12478
12479@value{GDBN} enables developers to debug tasks running on
12480Sparclet targets from a Unix host.
12481@value{GDBN} uses code that runs on
12482both the Unix host and on the Sparclet target. The program
12483@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 12484
8e04817f
AC
12485@table @code
12486@item remotetimeout @var{args}
12487@kindex remotetimeout
12488@value{GDBN} supports the option @code{remotetimeout}.
12489This option is set by the user, and @var{args} represents the number of
12490seconds @value{GDBN} waits for responses.
104c1213
JM
12491@end table
12492
8e04817f
AC
12493@cindex compiling, on Sparclet
12494When compiling for debugging, include the options @samp{-g} to get debug
12495information and @samp{-Ttext} to relocate the program to where you wish to
12496load it on the target. You may also want to add the options @samp{-n} or
12497@samp{-N} in order to reduce the size of the sections. Example:
104c1213 12498
474c8240 12499@smallexample
8e04817f 12500sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 12501@end smallexample
104c1213 12502
8e04817f 12503You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 12504
474c8240 12505@smallexample
8e04817f 12506sparclet-aout-objdump --headers --syms prog
474c8240 12507@end smallexample
104c1213 12508
8e04817f
AC
12509@cindex running, on Sparclet
12510Once you have set
12511your Unix execution search path to find @value{GDBN}, you are ready to
12512run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
12513(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 12514
8e04817f
AC
12515@value{GDBN} comes up showing the prompt:
12516
474c8240 12517@smallexample
8e04817f 12518(gdbslet)
474c8240 12519@end smallexample
104c1213
JM
12520
12521@menu
8e04817f
AC
12522* Sparclet File:: Setting the file to debug
12523* Sparclet Connection:: Connecting to Sparclet
12524* Sparclet Download:: Sparclet download
12525* Sparclet Execution:: Running and debugging
104c1213
JM
12526@end menu
12527
8e04817f
AC
12528@node Sparclet File
12529@subsubsection Setting file to debug
104c1213 12530
8e04817f 12531The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 12532
474c8240 12533@smallexample
8e04817f 12534(gdbslet) file prog
474c8240 12535@end smallexample
104c1213 12536
8e04817f
AC
12537@need 1000
12538@value{GDBN} then attempts to read the symbol table of @file{prog}.
12539@value{GDBN} locates
12540the file by searching the directories listed in the command search
12541path.
12542If the file was compiled with debug information (option "-g"), source
12543files will be searched as well.
12544@value{GDBN} locates
12545the source files by searching the directories listed in the directory search
12546path (@pxref{Environment, ,Your program's environment}).
12547If it fails
12548to find a file, it displays a message such as:
104c1213 12549
474c8240 12550@smallexample
8e04817f 12551prog: No such file or directory.
474c8240 12552@end smallexample
104c1213 12553
8e04817f
AC
12554When this happens, add the appropriate directories to the search paths with
12555the @value{GDBN} commands @code{path} and @code{dir}, and execute the
12556@code{target} command again.
104c1213 12557
8e04817f
AC
12558@node Sparclet Connection
12559@subsubsection Connecting to Sparclet
104c1213 12560
8e04817f
AC
12561The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
12562To connect to a target on serial port ``@code{ttya}'', type:
104c1213 12563
474c8240 12564@smallexample
8e04817f
AC
12565(gdbslet) target sparclet /dev/ttya
12566Remote target sparclet connected to /dev/ttya
12567main () at ../prog.c:3
474c8240 12568@end smallexample
104c1213 12569
8e04817f
AC
12570@need 750
12571@value{GDBN} displays messages like these:
104c1213 12572
474c8240 12573@smallexample
8e04817f 12574Connected to ttya.
474c8240 12575@end smallexample
104c1213 12576
8e04817f
AC
12577@node Sparclet Download
12578@subsubsection Sparclet download
104c1213 12579
8e04817f
AC
12580@cindex download to Sparclet
12581Once connected to the Sparclet target,
12582you can use the @value{GDBN}
12583@code{load} command to download the file from the host to the target.
12584The file name and load offset should be given as arguments to the @code{load}
12585command.
12586Since the file format is aout, the program must be loaded to the starting
12587address. You can use @code{objdump} to find out what this value is. The load
12588offset is an offset which is added to the VMA (virtual memory address)
12589of each of the file's sections.
12590For instance, if the program
12591@file{prog} was linked to text address 0x1201000, with data at 0x12010160
12592and bss at 0x12010170, in @value{GDBN}, type:
104c1213 12593
474c8240 12594@smallexample
8e04817f
AC
12595(gdbslet) load prog 0x12010000
12596Loading section .text, size 0xdb0 vma 0x12010000
474c8240 12597@end smallexample
104c1213 12598
8e04817f
AC
12599If the code is loaded at a different address then what the program was linked
12600to, you may need to use the @code{section} and @code{add-symbol-file} commands
12601to tell @value{GDBN} where to map the symbol table.
12602
12603@node Sparclet Execution
12604@subsubsection Running and debugging
12605
12606@cindex running and debugging Sparclet programs
12607You can now begin debugging the task using @value{GDBN}'s execution control
12608commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
12609manual for the list of commands.
12610
474c8240 12611@smallexample
8e04817f
AC
12612(gdbslet) b main
12613Breakpoint 1 at 0x12010000: file prog.c, line 3.
12614(gdbslet) run
12615Starting program: prog
12616Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
126173 char *symarg = 0;
12618(gdbslet) step
126194 char *execarg = "hello!";
12620(gdbslet)
474c8240 12621@end smallexample
8e04817f
AC
12622
12623@node Sparclite
12624@subsection Fujitsu Sparclite
104c1213
JM
12625
12626@table @code
12627
8e04817f
AC
12628@kindex target sparclite
12629@item target sparclite @var{dev}
12630Fujitsu sparclite boards, used only for the purpose of loading.
12631You must use an additional command to debug the program.
12632For example: target remote @var{dev} using @value{GDBN} standard
12633remote protocol.
104c1213
JM
12634
12635@end table
12636
8e04817f
AC
12637@node ST2000
12638@subsection Tandem ST2000
104c1213 12639
8e04817f
AC
12640@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
12641STDBUG protocol.
104c1213 12642
8e04817f
AC
12643To connect your ST2000 to the host system, see the manufacturer's
12644manual. Once the ST2000 is physically attached, you can run:
104c1213 12645
474c8240 12646@smallexample
8e04817f 12647target st2000 @var{dev} @var{speed}
474c8240 12648@end smallexample
104c1213 12649
8e04817f
AC
12650@noindent
12651to establish it as your debugging environment. @var{dev} is normally
12652the name of a serial device, such as @file{/dev/ttya}, connected to the
12653ST2000 via a serial line. You can instead specify @var{dev} as a TCP
12654connection (for example, to a serial line attached via a terminal
12655concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 12656
8e04817f
AC
12657The @code{load} and @code{attach} commands are @emph{not} defined for
12658this target; you must load your program into the ST2000 as you normally
12659would for standalone operation. @value{GDBN} reads debugging information
12660(such as symbols) from a separate, debugging version of the program
12661available on your host computer.
12662@c FIXME!! This is terribly vague; what little content is here is
12663@c basically hearsay.
104c1213 12664
8e04817f
AC
12665@cindex ST2000 auxiliary commands
12666These auxiliary @value{GDBN} commands are available to help you with the ST2000
12667environment:
104c1213 12668
8e04817f
AC
12669@table @code
12670@item st2000 @var{command}
12671@kindex st2000 @var{cmd}
12672@cindex STDBUG commands (ST2000)
12673@cindex commands to STDBUG (ST2000)
12674Send a @var{command} to the STDBUG monitor. See the manufacturer's
12675manual for available commands.
104c1213 12676
8e04817f
AC
12677@item connect
12678@cindex connect (to STDBUG)
12679Connect the controlling terminal to the STDBUG command monitor. When
12680you are done interacting with STDBUG, typing either of two character
12681sequences gets you back to the @value{GDBN} command prompt:
12682@kbd{@key{RET}~.} (Return, followed by tilde and period) or
12683@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
12684@end table
12685
8e04817f
AC
12686@node Z8000
12687@subsection Zilog Z8000
104c1213 12688
8e04817f
AC
12689@cindex Z8000
12690@cindex simulator, Z8000
12691@cindex Zilog Z8000 simulator
104c1213 12692
8e04817f
AC
12693When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
12694a Z8000 simulator.
12695
12696For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
12697unsegmented variant of the Z8000 architecture) or the Z8001 (the
12698segmented variant). The simulator recognizes which architecture is
12699appropriate by inspecting the object code.
104c1213 12700
8e04817f
AC
12701@table @code
12702@item target sim @var{args}
12703@kindex sim
12704@kindex target sim@r{, with Z8000}
12705Debug programs on a simulated CPU. If the simulator supports setup
12706options, specify them via @var{args}.
104c1213
JM
12707@end table
12708
8e04817f
AC
12709@noindent
12710After specifying this target, you can debug programs for the simulated
12711CPU in the same style as programs for your host computer; use the
12712@code{file} command to load a new program image, the @code{run} command
12713to run your program, and so on.
12714
12715As well as making available all the usual machine registers
12716(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
12717additional items of information as specially named registers:
104c1213
JM
12718
12719@table @code
12720
8e04817f
AC
12721@item cycles
12722Counts clock-ticks in the simulator.
104c1213 12723
8e04817f
AC
12724@item insts
12725Counts instructions run in the simulator.
104c1213 12726
8e04817f
AC
12727@item time
12728Execution time in 60ths of a second.
104c1213 12729
8e04817f 12730@end table
104c1213 12731
8e04817f
AC
12732You can refer to these values in @value{GDBN} expressions with the usual
12733conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
12734conditional breakpoint that suspends only after at least 5000
12735simulated clock ticks.
104c1213 12736
8e04817f
AC
12737@node Architectures
12738@section Architectures
104c1213 12739
8e04817f
AC
12740This section describes characteristics of architectures that affect
12741all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 12742
8e04817f
AC
12743@menu
12744* A29K::
12745* Alpha::
12746* MIPS::
12747@end menu
104c1213 12748
8e04817f
AC
12749@node A29K
12750@subsection A29K
104c1213
JM
12751
12752@table @code
104c1213 12753
8e04817f
AC
12754@kindex set rstack_high_address
12755@cindex AMD 29K register stack
12756@cindex register stack, AMD29K
12757@item set rstack_high_address @var{address}
12758On AMD 29000 family processors, registers are saved in a separate
12759@dfn{register stack}. There is no way for @value{GDBN} to determine the
12760extent of this stack. Normally, @value{GDBN} just assumes that the
12761stack is ``large enough''. This may result in @value{GDBN} referencing
12762memory locations that do not exist. If necessary, you can get around
12763this problem by specifying the ending address of the register stack with
12764the @code{set rstack_high_address} command. The argument should be an
12765address, which you probably want to precede with @samp{0x} to specify in
12766hexadecimal.
104c1213 12767
8e04817f
AC
12768@kindex show rstack_high_address
12769@item show rstack_high_address
12770Display the current limit of the register stack, on AMD 29000 family
12771processors.
104c1213 12772
8e04817f 12773@end table
104c1213 12774
8e04817f
AC
12775@node Alpha
12776@subsection Alpha
104c1213 12777
8e04817f 12778See the following section.
104c1213 12779
8e04817f
AC
12780@node MIPS
12781@subsection MIPS
104c1213 12782
8e04817f
AC
12783@cindex stack on Alpha
12784@cindex stack on MIPS
12785@cindex Alpha stack
12786@cindex MIPS stack
12787Alpha- and MIPS-based computers use an unusual stack frame, which
12788sometimes requires @value{GDBN} to search backward in the object code to
12789find the beginning of a function.
104c1213 12790
8e04817f
AC
12791@cindex response time, MIPS debugging
12792To improve response time (especially for embedded applications, where
12793@value{GDBN} may be restricted to a slow serial line for this search)
12794you may want to limit the size of this search, using one of these
12795commands:
104c1213 12796
8e04817f
AC
12797@table @code
12798@cindex @code{heuristic-fence-post} (Alpha, MIPS)
12799@item set heuristic-fence-post @var{limit}
12800Restrict @value{GDBN} to examining at most @var{limit} bytes in its
12801search for the beginning of a function. A value of @var{0} (the
12802default) means there is no limit. However, except for @var{0}, the
12803larger the limit the more bytes @code{heuristic-fence-post} must search
12804and therefore the longer it takes to run.
104c1213 12805
8e04817f
AC
12806@item show heuristic-fence-post
12807Display the current limit.
12808@end table
104c1213
JM
12809
12810@noindent
8e04817f
AC
12811These commands are available @emph{only} when @value{GDBN} is configured
12812for debugging programs on Alpha or MIPS processors.
104c1213 12813
104c1213 12814
8e04817f
AC
12815@node Controlling GDB
12816@chapter Controlling @value{GDBN}
12817
12818You can alter the way @value{GDBN} interacts with you by using the
12819@code{set} command. For commands controlling how @value{GDBN} displays
12820data, see @ref{Print Settings, ,Print settings}. Other settings are
12821described here.
12822
12823@menu
12824* Prompt:: Prompt
12825* Editing:: Command editing
12826* History:: Command history
12827* Screen Size:: Screen size
12828* Numbers:: Numbers
1e698235 12829* ABI:: Configuring the current ABI
8e04817f
AC
12830* Messages/Warnings:: Optional warnings and messages
12831* Debugging Output:: Optional messages about internal happenings
12832@end menu
12833
12834@node Prompt
12835@section Prompt
104c1213 12836
8e04817f 12837@cindex prompt
104c1213 12838
8e04817f
AC
12839@value{GDBN} indicates its readiness to read a command by printing a string
12840called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
12841can change the prompt string with the @code{set prompt} command. For
12842instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
12843the prompt in one of the @value{GDBN} sessions so that you can always tell
12844which one you are talking to.
104c1213 12845
8e04817f
AC
12846@emph{Note:} @code{set prompt} does not add a space for you after the
12847prompt you set. This allows you to set a prompt which ends in a space
12848or a prompt that does not.
104c1213 12849
8e04817f
AC
12850@table @code
12851@kindex set prompt
12852@item set prompt @var{newprompt}
12853Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 12854
8e04817f
AC
12855@kindex show prompt
12856@item show prompt
12857Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
12858@end table
12859
8e04817f
AC
12860@node Editing
12861@section Command editing
12862@cindex readline
12863@cindex command line editing
104c1213 12864
8e04817f
AC
12865@value{GDBN} reads its input commands via the @dfn{readline} interface. This
12866@sc{gnu} library provides consistent behavior for programs which provide a
12867command line interface to the user. Advantages are @sc{gnu} Emacs-style
12868or @dfn{vi}-style inline editing of commands, @code{csh}-like history
12869substitution, and a storage and recall of command history across
12870debugging sessions.
104c1213 12871
8e04817f
AC
12872You may control the behavior of command line editing in @value{GDBN} with the
12873command @code{set}.
104c1213 12874
8e04817f
AC
12875@table @code
12876@kindex set editing
12877@cindex editing
12878@item set editing
12879@itemx set editing on
12880Enable command line editing (enabled by default).
104c1213 12881
8e04817f
AC
12882@item set editing off
12883Disable command line editing.
104c1213 12884
8e04817f
AC
12885@kindex show editing
12886@item show editing
12887Show whether command line editing is enabled.
104c1213
JM
12888@end table
12889
8e04817f
AC
12890@node History
12891@section Command history
12892
12893@value{GDBN} can keep track of the commands you type during your
12894debugging sessions, so that you can be certain of precisely what
12895happened. Use these commands to manage the @value{GDBN} command
12896history facility.
104c1213
JM
12897
12898@table @code
8e04817f
AC
12899@cindex history substitution
12900@cindex history file
12901@kindex set history filename
12902@kindex GDBHISTFILE
12903@item set history filename @var{fname}
12904Set the name of the @value{GDBN} command history file to @var{fname}.
12905This is the file where @value{GDBN} reads an initial command history
12906list, and where it writes the command history from this session when it
12907exits. You can access this list through history expansion or through
12908the history command editing characters listed below. This file defaults
12909to the value of the environment variable @code{GDBHISTFILE}, or to
12910@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
12911is not set.
104c1213 12912
8e04817f
AC
12913@cindex history save
12914@kindex set history save
12915@item set history save
12916@itemx set history save on
12917Record command history in a file, whose name may be specified with the
12918@code{set history filename} command. By default, this option is disabled.
104c1213 12919
8e04817f
AC
12920@item set history save off
12921Stop recording command history in a file.
104c1213 12922
8e04817f
AC
12923@cindex history size
12924@kindex set history size
12925@item set history size @var{size}
12926Set the number of commands which @value{GDBN} keeps in its history list.
12927This defaults to the value of the environment variable
12928@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
12929@end table
12930
8e04817f
AC
12931@cindex history expansion
12932History expansion assigns special meaning to the character @kbd{!}.
12933@ifset have-readline-appendices
12934@xref{Event Designators}.
12935@end ifset
12936
12937Since @kbd{!} is also the logical not operator in C, history expansion
12938is off by default. If you decide to enable history expansion with the
12939@code{set history expansion on} command, you may sometimes need to
12940follow @kbd{!} (when it is used as logical not, in an expression) with
12941a space or a tab to prevent it from being expanded. The readline
12942history facilities do not attempt substitution on the strings
12943@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
12944
12945The commands to control history expansion are:
104c1213
JM
12946
12947@table @code
8e04817f
AC
12948@kindex set history expansion
12949@item set history expansion on
12950@itemx set history expansion
12951Enable history expansion. History expansion is off by default.
104c1213 12952
8e04817f
AC
12953@item set history expansion off
12954Disable history expansion.
104c1213 12955
8e04817f
AC
12956The readline code comes with more complete documentation of
12957editing and history expansion features. Users unfamiliar with @sc{gnu} Emacs
12958or @code{vi} may wish to read it.
12959@ifset have-readline-appendices
12960@xref{Command Line Editing}.
12961@end ifset
104c1213 12962
8e04817f
AC
12963@c @group
12964@kindex show history
12965@item show history
12966@itemx show history filename
12967@itemx show history save
12968@itemx show history size
12969@itemx show history expansion
12970These commands display the state of the @value{GDBN} history parameters.
12971@code{show history} by itself displays all four states.
12972@c @end group
12973@end table
12974
12975@table @code
12976@kindex shows
12977@item show commands
12978Display the last ten commands in the command history.
104c1213 12979
8e04817f
AC
12980@item show commands @var{n}
12981Print ten commands centered on command number @var{n}.
12982
12983@item show commands +
12984Print ten commands just after the commands last printed.
104c1213
JM
12985@end table
12986
8e04817f
AC
12987@node Screen Size
12988@section Screen size
12989@cindex size of screen
12990@cindex pauses in output
104c1213 12991
8e04817f
AC
12992Certain commands to @value{GDBN} may produce large amounts of
12993information output to the screen. To help you read all of it,
12994@value{GDBN} pauses and asks you for input at the end of each page of
12995output. Type @key{RET} when you want to continue the output, or @kbd{q}
12996to discard the remaining output. Also, the screen width setting
12997determines when to wrap lines of output. Depending on what is being
12998printed, @value{GDBN} tries to break the line at a readable place,
12999rather than simply letting it overflow onto the following line.
13000
13001Normally @value{GDBN} knows the size of the screen from the terminal
13002driver software. For example, on Unix @value{GDBN} uses the termcap data base
13003together with the value of the @code{TERM} environment variable and the
13004@code{stty rows} and @code{stty cols} settings. If this is not correct,
13005you can override it with the @code{set height} and @code{set
13006width} commands:
13007
13008@table @code
13009@kindex set height
13010@kindex set width
13011@kindex show width
13012@kindex show height
13013@item set height @var{lpp}
13014@itemx show height
13015@itemx set width @var{cpl}
13016@itemx show width
13017These @code{set} commands specify a screen height of @var{lpp} lines and
13018a screen width of @var{cpl} characters. The associated @code{show}
13019commands display the current settings.
104c1213 13020
8e04817f
AC
13021If you specify a height of zero lines, @value{GDBN} does not pause during
13022output no matter how long the output is. This is useful if output is to a
13023file or to an editor buffer.
104c1213 13024
8e04817f
AC
13025Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
13026from wrapping its output.
104c1213
JM
13027@end table
13028
8e04817f
AC
13029@node Numbers
13030@section Numbers
13031@cindex number representation
13032@cindex entering numbers
104c1213 13033
8e04817f
AC
13034You can always enter numbers in octal, decimal, or hexadecimal in
13035@value{GDBN} by the usual conventions: octal numbers begin with
13036@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
13037begin with @samp{0x}. Numbers that begin with none of these are, by
13038default, entered in base 10; likewise, the default display for
13039numbers---when no particular format is specified---is base 10. You can
13040change the default base for both input and output with the @code{set
13041radix} command.
104c1213 13042
8e04817f
AC
13043@table @code
13044@kindex set input-radix
13045@item set input-radix @var{base}
13046Set the default base for numeric input. Supported choices
13047for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
13048specified either unambiguously or using the current default radix; for
13049example, any of
104c1213 13050
8e04817f
AC
13051@smallexample
13052set radix 012
13053set radix 10.
13054set radix 0xa
13055@end smallexample
104c1213 13056
8e04817f
AC
13057@noindent
13058sets the base to decimal. On the other hand, @samp{set radix 10}
13059leaves the radix unchanged no matter what it was.
104c1213 13060
8e04817f
AC
13061@kindex set output-radix
13062@item set output-radix @var{base}
13063Set the default base for numeric display. Supported choices
13064for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
13065specified either unambiguously or using the current default radix.
104c1213 13066
8e04817f
AC
13067@kindex show input-radix
13068@item show input-radix
13069Display the current default base for numeric input.
104c1213 13070
8e04817f
AC
13071@kindex show output-radix
13072@item show output-radix
13073Display the current default base for numeric display.
13074@end table
104c1213 13075
1e698235
DJ
13076@node ABI
13077@section Configuring the current ABI
13078
13079@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
13080application automatically. However, sometimes you need to override its
13081conclusions. Use these commands to manage @value{GDBN}'s view of the
13082current ABI.
13083
98b45e30
DJ
13084@cindex OS ABI
13085@kindex set osabi
b4e9345d 13086@kindex show osabi
98b45e30
DJ
13087
13088One @value{GDBN} configuration can debug binaries for multiple operating
13089system targets, either via remote debugging or native emulation.
13090@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
13091but you can override its conclusion using the @code{set osabi} command.
13092One example where this is useful is in debugging of binaries which use
13093an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
13094not have the same identifying marks that the standard C library for your
13095platform provides.
13096
13097@table @code
13098@item show osabi
13099Show the OS ABI currently in use.
13100
13101@item set osabi
13102With no argument, show the list of registered available OS ABI's.
13103
13104@item set osabi @var{abi}
13105Set the current OS ABI to @var{abi}.
13106@end table
13107
1e698235
DJ
13108@cindex float promotion
13109@kindex set coerce-float-to-double
13110
13111Generally, the way that an argument of type @code{float} is passed to a
13112function depends on whether the function is prototyped. For a prototyped
13113(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
13114according to the architecture's convention for @code{float}. For unprototyped
13115(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
13116@code{double} and then passed.
13117
13118Unfortunately, some forms of debug information do not reliably indicate whether
13119a function is prototyped. If @value{GDBN} calls a function that is not marked
13120as prototyped, it consults @kbd{set coerce-float-to-double}.
13121
13122@table @code
13123@item set coerce-float-to-double
13124@itemx set coerce-float-to-double on
13125Arguments of type @code{float} will be promoted to @code{double} when passed
13126to an unprototyped function. This is the default setting.
13127
13128@item set coerce-float-to-double off
13129Arguments of type @code{float} will be passed directly to unprototyped
13130functions.
13131@end table
13132
f1212245
DJ
13133@kindex set cp-abi
13134@kindex show cp-abi
13135@value{GDBN} needs to know the ABI used for your program's C@t{++}
13136objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
13137used to build your application. @value{GDBN} only fully supports
13138programs with a single C@t{++} ABI; if your program contains code using
13139multiple C@t{++} ABI's or if @value{GDBN} can not identify your
13140program's ABI correctly, you can tell @value{GDBN} which ABI to use.
13141Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
13142before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
13143``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
13144use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
13145``auto''.
13146
13147@table @code
13148@item show cp-abi
13149Show the C@t{++} ABI currently in use.
13150
13151@item set cp-abi
13152With no argument, show the list of supported C@t{++} ABI's.
13153
13154@item set cp-abi @var{abi}
13155@itemx set cp-abi auto
13156Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
13157@end table
13158
8e04817f
AC
13159@node Messages/Warnings
13160@section Optional warnings and messages
104c1213 13161
8e04817f
AC
13162By default, @value{GDBN} is silent about its inner workings. If you are
13163running on a slow machine, you may want to use the @code{set verbose}
13164command. This makes @value{GDBN} tell you when it does a lengthy
13165internal operation, so you will not think it has crashed.
104c1213 13166
8e04817f
AC
13167Currently, the messages controlled by @code{set verbose} are those
13168which announce that the symbol table for a source file is being read;
13169see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 13170
8e04817f
AC
13171@table @code
13172@kindex set verbose
13173@item set verbose on
13174Enables @value{GDBN} output of certain informational messages.
104c1213 13175
8e04817f
AC
13176@item set verbose off
13177Disables @value{GDBN} output of certain informational messages.
104c1213 13178
8e04817f
AC
13179@kindex show verbose
13180@item show verbose
13181Displays whether @code{set verbose} is on or off.
13182@end table
104c1213 13183
8e04817f
AC
13184By default, if @value{GDBN} encounters bugs in the symbol table of an
13185object file, it is silent; but if you are debugging a compiler, you may
13186find this information useful (@pxref{Symbol Errors, ,Errors reading
13187symbol files}).
104c1213 13188
8e04817f 13189@table @code
104c1213 13190
8e04817f
AC
13191@kindex set complaints
13192@item set complaints @var{limit}
13193Permits @value{GDBN} to output @var{limit} complaints about each type of
13194unusual symbols before becoming silent about the problem. Set
13195@var{limit} to zero to suppress all complaints; set it to a large number
13196to prevent complaints from being suppressed.
104c1213 13197
8e04817f
AC
13198@kindex show complaints
13199@item show complaints
13200Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 13201
8e04817f 13202@end table
104c1213 13203
8e04817f
AC
13204By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
13205lot of stupid questions to confirm certain commands. For example, if
13206you try to run a program which is already running:
104c1213 13207
474c8240 13208@smallexample
8e04817f
AC
13209(@value{GDBP}) run
13210The program being debugged has been started already.
13211Start it from the beginning? (y or n)
474c8240 13212@end smallexample
104c1213 13213
8e04817f
AC
13214If you are willing to unflinchingly face the consequences of your own
13215commands, you can disable this ``feature'':
104c1213 13216
8e04817f 13217@table @code
104c1213 13218
8e04817f
AC
13219@kindex set confirm
13220@cindex flinching
13221@cindex confirmation
13222@cindex stupid questions
13223@item set confirm off
13224Disables confirmation requests.
104c1213 13225
8e04817f
AC
13226@item set confirm on
13227Enables confirmation requests (the default).
104c1213 13228
8e04817f
AC
13229@kindex show confirm
13230@item show confirm
13231Displays state of confirmation requests.
13232
13233@end table
104c1213 13234
8e04817f
AC
13235@node Debugging Output
13236@section Optional messages about internal happenings
104c1213 13237@table @code
8e04817f
AC
13238@kindex set debug arch
13239@item set debug arch
13240Turns on or off display of gdbarch debugging info. The default is off
13241@kindex show debug arch
13242@item show debug arch
13243Displays the current state of displaying gdbarch debugging info.
13244@kindex set debug event
13245@item set debug event
13246Turns on or off display of @value{GDBN} event debugging info. The
13247default is off.
13248@kindex show debug event
13249@item show debug event
13250Displays the current state of displaying @value{GDBN} event debugging
13251info.
13252@kindex set debug expression
13253@item set debug expression
13254Turns on or off display of @value{GDBN} expression debugging info. The
13255default is off.
13256@kindex show debug expression
13257@item show debug expression
13258Displays the current state of displaying @value{GDBN} expression
13259debugging info.
7453dc06
AC
13260@kindex set debug frame
13261@item set debug frame
13262Turns on or off display of @value{GDBN} frame debugging info. The
13263default is off.
13264@kindex show debug frame
13265@item show debug frame
13266Displays the current state of displaying @value{GDBN} frame debugging
13267info.
8e04817f
AC
13268@kindex set debug overload
13269@item set debug overload
13270Turns on or off display of @value{GDBN} C@t{++} overload debugging
13271info. This includes info such as ranking of functions, etc. The default
13272is off.
13273@kindex show debug overload
13274@item show debug overload
13275Displays the current state of displaying @value{GDBN} C@t{++} overload
13276debugging info.
13277@kindex set debug remote
13278@cindex packets, reporting on stdout
13279@cindex serial connections, debugging
13280@item set debug remote
13281Turns on or off display of reports on all packets sent back and forth across
13282the serial line to the remote machine. The info is printed on the
13283@value{GDBN} standard output stream. The default is off.
13284@kindex show debug remote
13285@item show debug remote
13286Displays the state of display of remote packets.
13287@kindex set debug serial
13288@item set debug serial
13289Turns on or off display of @value{GDBN} serial debugging info. The
13290default is off.
13291@kindex show debug serial
13292@item show debug serial
13293Displays the current state of displaying @value{GDBN} serial debugging
13294info.
13295@kindex set debug target
13296@item set debug target
13297Turns on or off display of @value{GDBN} target debugging info. This info
13298includes what is going on at the target level of GDB, as it happens. The
13299default is off.
13300@kindex show debug target
13301@item show debug target
13302Displays the current state of displaying @value{GDBN} target debugging
13303info.
13304@kindex set debug varobj
13305@item set debug varobj
13306Turns on or off display of @value{GDBN} variable object debugging
13307info. The default is off.
13308@kindex show debug varobj
13309@item show debug varobj
13310Displays the current state of displaying @value{GDBN} variable object
13311debugging info.
13312@end table
104c1213 13313
8e04817f
AC
13314@node Sequences
13315@chapter Canned Sequences of Commands
104c1213 13316
8e04817f
AC
13317Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
13318command lists}), @value{GDBN} provides two ways to store sequences of
13319commands for execution as a unit: user-defined commands and command
13320files.
104c1213 13321
8e04817f
AC
13322@menu
13323* Define:: User-defined commands
13324* Hooks:: User-defined command hooks
13325* Command Files:: Command files
13326* Output:: Commands for controlled output
13327@end menu
104c1213 13328
8e04817f
AC
13329@node Define
13330@section User-defined commands
104c1213 13331
8e04817f
AC
13332@cindex user-defined command
13333A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
13334which you assign a new name as a command. This is done with the
13335@code{define} command. User commands may accept up to 10 arguments
13336separated by whitespace. Arguments are accessed within the user command
13337via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 13338
8e04817f
AC
13339@smallexample
13340define adder
13341 print $arg0 + $arg1 + $arg2
13342@end smallexample
104c1213
JM
13343
13344@noindent
8e04817f 13345To execute the command use:
104c1213 13346
8e04817f
AC
13347@smallexample
13348adder 1 2 3
13349@end smallexample
104c1213 13350
8e04817f
AC
13351@noindent
13352This defines the command @code{adder}, which prints the sum of
13353its three arguments. Note the arguments are text substitutions, so they may
13354reference variables, use complex expressions, or even perform inferior
13355functions calls.
104c1213
JM
13356
13357@table @code
104c1213 13358
8e04817f
AC
13359@kindex define
13360@item define @var{commandname}
13361Define a command named @var{commandname}. If there is already a command
13362by that name, you are asked to confirm that you want to redefine it.
104c1213 13363
8e04817f
AC
13364The definition of the command is made up of other @value{GDBN} command lines,
13365which are given following the @code{define} command. The end of these
13366commands is marked by a line containing @code{end}.
104c1213 13367
8e04817f
AC
13368@kindex if
13369@kindex else
13370@item if
13371Takes a single argument, which is an expression to evaluate.
13372It is followed by a series of commands that are executed
13373only if the expression is true (nonzero).
13374There can then optionally be a line @code{else}, followed
13375by a series of commands that are only executed if the expression
13376was false. The end of the list is marked by a line containing @code{end}.
104c1213 13377
8e04817f
AC
13378@kindex while
13379@item while
13380The syntax is similar to @code{if}: the command takes a single argument,
13381which is an expression to evaluate, and must be followed by the commands to
13382execute, one per line, terminated by an @code{end}.
13383The commands are executed repeatedly as long as the expression
13384evaluates to true.
104c1213 13385
8e04817f
AC
13386@kindex document
13387@item document @var{commandname}
13388Document the user-defined command @var{commandname}, so that it can be
13389accessed by @code{help}. The command @var{commandname} must already be
13390defined. This command reads lines of documentation just as @code{define}
13391reads the lines of the command definition, ending with @code{end}.
13392After the @code{document} command is finished, @code{help} on command
13393@var{commandname} displays the documentation you have written.
104c1213 13394
8e04817f
AC
13395You may use the @code{document} command again to change the
13396documentation of a command. Redefining the command with @code{define}
13397does not change the documentation.
104c1213 13398
8e04817f
AC
13399@kindex help user-defined
13400@item help user-defined
13401List all user-defined commands, with the first line of the documentation
13402(if any) for each.
104c1213 13403
8e04817f
AC
13404@kindex show user
13405@item show user
13406@itemx show user @var{commandname}
13407Display the @value{GDBN} commands used to define @var{commandname} (but
13408not its documentation). If no @var{commandname} is given, display the
13409definitions for all user-defined commands.
104c1213 13410
20f01a46
DH
13411@kindex show max-user-call-depth
13412@kindex set max-user-call-depth
13413@item show max-user-call-depth
5ca0cb28
DH
13414@itemx set max-user-call-depth
13415The value of @code{max-user-call-depth} controls how many recursion
13416levels are allowed in user-defined commands before GDB suspects an
13417infinite recursion and aborts the command.
20f01a46 13418
104c1213
JM
13419@end table
13420
8e04817f
AC
13421When user-defined commands are executed, the
13422commands of the definition are not printed. An error in any command
13423stops execution of the user-defined command.
104c1213 13424
8e04817f
AC
13425If used interactively, commands that would ask for confirmation proceed
13426without asking when used inside a user-defined command. Many @value{GDBN}
13427commands that normally print messages to say what they are doing omit the
13428messages when used in a user-defined command.
104c1213 13429
8e04817f
AC
13430@node Hooks
13431@section User-defined command hooks
13432@cindex command hooks
13433@cindex hooks, for commands
13434@cindex hooks, pre-command
104c1213 13435
8e04817f
AC
13436@kindex hook
13437@kindex hook-
13438You may define @dfn{hooks}, which are a special kind of user-defined
13439command. Whenever you run the command @samp{foo}, if the user-defined
13440command @samp{hook-foo} exists, it is executed (with no arguments)
13441before that command.
104c1213 13442
8e04817f
AC
13443@cindex hooks, post-command
13444@kindex hookpost
13445@kindex hookpost-
13446A hook may also be defined which is run after the command you executed.
13447Whenever you run the command @samp{foo}, if the user-defined command
13448@samp{hookpost-foo} exists, it is executed (with no arguments) after
13449that command. Post-execution hooks may exist simultaneously with
13450pre-execution hooks, for the same command.
104c1213 13451
8e04817f
AC
13452It is valid for a hook to call the command which it hooks. If this
13453occurs, the hook is not re-executed, thereby avoiding infinte recursion.
104c1213 13454
8e04817f
AC
13455@c It would be nice if hookpost could be passed a parameter indicating
13456@c if the command it hooks executed properly or not. FIXME!
104c1213 13457
8e04817f
AC
13458@kindex stop@r{, a pseudo-command}
13459In addition, a pseudo-command, @samp{stop} exists. Defining
13460(@samp{hook-stop}) makes the associated commands execute every time
13461execution stops in your program: before breakpoint commands are run,
13462displays are printed, or the stack frame is printed.
104c1213 13463
8e04817f
AC
13464For example, to ignore @code{SIGALRM} signals while
13465single-stepping, but treat them normally during normal execution,
13466you could define:
104c1213 13467
474c8240 13468@smallexample
8e04817f
AC
13469define hook-stop
13470handle SIGALRM nopass
13471end
104c1213 13472
8e04817f
AC
13473define hook-run
13474handle SIGALRM pass
13475end
104c1213 13476
8e04817f
AC
13477define hook-continue
13478handle SIGLARM pass
13479end
474c8240 13480@end smallexample
104c1213 13481
8e04817f
AC
13482As a further example, to hook at the begining and end of the @code{echo}
13483command, and to add extra text to the beginning and end of the message,
13484you could define:
104c1213 13485
474c8240 13486@smallexample
8e04817f
AC
13487define hook-echo
13488echo <<<---
13489end
104c1213 13490
8e04817f
AC
13491define hookpost-echo
13492echo --->>>\n
13493end
104c1213 13494
8e04817f
AC
13495(@value{GDBP}) echo Hello World
13496<<<---Hello World--->>>
13497(@value{GDBP})
104c1213 13498
474c8240 13499@end smallexample
104c1213 13500
8e04817f
AC
13501You can define a hook for any single-word command in @value{GDBN}, but
13502not for command aliases; you should define a hook for the basic command
13503name, e.g. @code{backtrace} rather than @code{bt}.
13504@c FIXME! So how does Joe User discover whether a command is an alias
13505@c or not?
13506If an error occurs during the execution of your hook, execution of
13507@value{GDBN} commands stops and @value{GDBN} issues a prompt
13508(before the command that you actually typed had a chance to run).
104c1213 13509
8e04817f
AC
13510If you try to define a hook which does not match any known command, you
13511get a warning from the @code{define} command.
c906108c 13512
8e04817f
AC
13513@node Command Files
13514@section Command files
c906108c 13515
8e04817f
AC
13516@cindex command files
13517A command file for @value{GDBN} is a file of lines that are @value{GDBN}
13518commands. Comments (lines starting with @kbd{#}) may also be included.
13519An empty line in a command file does nothing; it does not mean to repeat
13520the last command, as it would from the terminal.
c906108c 13521
8e04817f
AC
13522@cindex init file
13523@cindex @file{.gdbinit}
13524@cindex @file{gdb.ini}
13525When you start @value{GDBN}, it automatically executes commands from its
13526@dfn{init files}, normally called @file{.gdbinit}@footnote{The DJGPP
13527port of @value{GDBN} uses the name @file{gdb.ini} instead, due to the
13528limitations of file names imposed by DOS filesystems.}.
13529During startup, @value{GDBN} does the following:
c906108c 13530
8e04817f
AC
13531@enumerate
13532@item
13533Reads the init file (if any) in your home directory@footnote{On
13534DOS/Windows systems, the home directory is the one pointed to by the
13535@code{HOME} environment variable.}.
c906108c 13536
8e04817f
AC
13537@item
13538Processes command line options and operands.
c906108c 13539
8e04817f
AC
13540@item
13541Reads the init file (if any) in the current working directory.
c906108c 13542
8e04817f
AC
13543@item
13544Reads command files specified by the @samp{-x} option.
13545@end enumerate
c906108c 13546
8e04817f
AC
13547The init file in your home directory can set options (such as @samp{set
13548complaints}) that affect subsequent processing of command line options
13549and operands. Init files are not executed if you use the @samp{-nx}
13550option (@pxref{Mode Options, ,Choosing modes}).
c906108c 13551
8e04817f
AC
13552@cindex init file name
13553On some configurations of @value{GDBN}, the init file is known by a
13554different name (these are typically environments where a specialized
13555form of @value{GDBN} may need to coexist with other forms, hence a
13556different name for the specialized version's init file). These are the
13557environments with special init file names:
c906108c 13558
8e04817f
AC
13559@cindex @file{.vxgdbinit}
13560@itemize @bullet
13561@item
13562VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
c906108c 13563
8e04817f
AC
13564@cindex @file{.os68gdbinit}
13565@item
13566OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
c906108c 13567
8e04817f
AC
13568@cindex @file{.esgdbinit}
13569@item
13570ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
13571@end itemize
c906108c 13572
8e04817f
AC
13573You can also request the execution of a command file with the
13574@code{source} command:
c906108c 13575
8e04817f
AC
13576@table @code
13577@kindex source
13578@item source @var{filename}
13579Execute the command file @var{filename}.
c906108c
SS
13580@end table
13581
8e04817f 13582The lines in a command file are executed sequentially. They are not
a71ec265
DH
13583printed as they are executed. An error in any command terminates
13584execution of the command file and control is returned to the console.
c906108c 13585
8e04817f
AC
13586Commands that would ask for confirmation if used interactively proceed
13587without asking when used in a command file. Many @value{GDBN} commands that
13588normally print messages to say what they are doing omit the messages
13589when called from command files.
c906108c 13590
8e04817f
AC
13591@value{GDBN} also accepts command input from standard input. In this
13592mode, normal output goes to standard output and error output goes to
13593standard error. Errors in a command file supplied on standard input do
13594not terminate execution of the command file --- execution continues with
13595the next command.
c906108c 13596
474c8240 13597@smallexample
8e04817f 13598gdb < cmds > log 2>&1
474c8240 13599@end smallexample
c906108c 13600
8e04817f
AC
13601(The syntax above will vary depending on the shell used.) This example
13602will execute commands from the file @file{cmds}. All output and errors
13603would be directed to @file{log}.
c906108c 13604
8e04817f
AC
13605@node Output
13606@section Commands for controlled output
c906108c 13607
8e04817f
AC
13608During the execution of a command file or a user-defined command, normal
13609@value{GDBN} output is suppressed; the only output that appears is what is
13610explicitly printed by the commands in the definition. This section
13611describes three commands useful for generating exactly the output you
13612want.
c906108c
SS
13613
13614@table @code
8e04817f
AC
13615@kindex echo
13616@item echo @var{text}
13617@c I do not consider backslash-space a standard C escape sequence
13618@c because it is not in ANSI.
13619Print @var{text}. Nonprinting characters can be included in
13620@var{text} using C escape sequences, such as @samp{\n} to print a
13621newline. @strong{No newline is printed unless you specify one.}
13622In addition to the standard C escape sequences, a backslash followed
13623by a space stands for a space. This is useful for displaying a
13624string with spaces at the beginning or the end, since leading and
13625trailing spaces are otherwise trimmed from all arguments.
13626To print @samp{@w{ }and foo =@w{ }}, use the command
13627@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 13628
8e04817f
AC
13629A backslash at the end of @var{text} can be used, as in C, to continue
13630the command onto subsequent lines. For example,
c906108c 13631
474c8240 13632@smallexample
8e04817f
AC
13633echo This is some text\n\
13634which is continued\n\
13635onto several lines.\n
474c8240 13636@end smallexample
c906108c 13637
8e04817f 13638produces the same output as
c906108c 13639
474c8240 13640@smallexample
8e04817f
AC
13641echo This is some text\n
13642echo which is continued\n
13643echo onto several lines.\n
474c8240 13644@end smallexample
c906108c 13645
8e04817f
AC
13646@kindex output
13647@item output @var{expression}
13648Print the value of @var{expression} and nothing but that value: no
13649newlines, no @samp{$@var{nn} = }. The value is not entered in the
13650value history either. @xref{Expressions, ,Expressions}, for more information
13651on expressions.
c906108c 13652
8e04817f
AC
13653@item output/@var{fmt} @var{expression}
13654Print the value of @var{expression} in format @var{fmt}. You can use
13655the same formats as for @code{print}. @xref{Output Formats,,Output
13656formats}, for more information.
c906108c 13657
8e04817f
AC
13658@kindex printf
13659@item printf @var{string}, @var{expressions}@dots{}
13660Print the values of the @var{expressions} under the control of
13661@var{string}. The @var{expressions} are separated by commas and may be
13662either numbers or pointers. Their values are printed as specified by
13663@var{string}, exactly as if your program were to execute the C
13664subroutine
13665@c FIXME: the above implies that at least all ANSI C formats are
13666@c supported, but it isn't true: %E and %G don't work (or so it seems).
13667@c Either this is a bug, or the manual should document what formats are
13668@c supported.
c906108c 13669
474c8240 13670@smallexample
8e04817f 13671printf (@var{string}, @var{expressions}@dots{});
474c8240 13672@end smallexample
c906108c 13673
8e04817f 13674For example, you can print two values in hex like this:
c906108c 13675
8e04817f
AC
13676@smallexample
13677printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
13678@end smallexample
c906108c 13679
8e04817f
AC
13680The only backslash-escape sequences that you can use in the format
13681string are the simple ones that consist of backslash followed by a
13682letter.
c906108c
SS
13683@end table
13684
21c294e6
AC
13685@node Interpreters
13686@chapter Command Interpreters
13687@cindex command interpreters
13688
13689@value{GDBN} supports multiple command interpreters, and some command
13690infrastructure to allow users or user interface writers to switch
13691between interpreters or run commands in other interpreters.
13692
13693@value{GDBN} currently supports two command interpreters, the console
13694interpreter (sometimes called the command-line interpreter or @sc{cli})
13695and the machine interface interpreter (or @sc{gdb/mi}). This manual
13696describes both of these interfaces in great detail.
13697
13698By default, @value{GDBN} will start with the console interpreter.
13699However, the user may choose to start @value{GDBN} with another
13700interpreter by specifying the @option{-i} or @option{--interpreter}
13701startup options. Defined interpreters include:
13702
13703@table @code
13704@item console
13705@cindex console interpreter
13706The traditional console or command-line interpreter. This is the most often
13707used interpreter with @value{GDBN}. With no interpreter specified at runtime,
13708@value{GDBN} will use this interpreter.
13709
13710@item mi
13711@cindex mi interpreter
13712The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
13713by programs wishing to use @value{GDBN} as a backend for a debugger GUI
13714or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
13715Interface}.
13716
13717@item mi2
13718@cindex mi2 interpreter
13719The current @sc{gdb/mi} interface.
13720
13721@item mi1
13722@cindex mi1 interpreter
13723The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
13724
13725@end table
13726
13727@cindex invoke another interpreter
13728The interpreter being used by @value{GDBN} may not be dynamically
13729switched at runtime. Although possible, this could lead to a very
13730precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
13731enters the command "interpreter-set console" in a console view,
13732@value{GDBN} would switch to using the console interpreter, rendering
13733the IDE inoperable!
13734
13735@kindex interpreter-exec
13736Although you may only choose a single interpreter at startup, you may execute
13737commands in any interpreter from the current interpreter using the appropriate
13738command. If you are running the console interpreter, simply use the
13739@code{interpreter-exec} command:
13740
13741@smallexample
13742interpreter-exec mi "-data-list-register-names"
13743@end smallexample
13744
13745@sc{gdb/mi} has a similar command, although it is only available in versions of
13746@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
13747
8e04817f
AC
13748@node TUI
13749@chapter @value{GDBN} Text User Interface
13750@cindex TUI
c906108c 13751
8e04817f
AC
13752@menu
13753* TUI Overview:: TUI overview
13754* TUI Keys:: TUI key bindings
7cf36c78 13755* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
13756* TUI Commands:: TUI specific commands
13757* TUI Configuration:: TUI configuration variables
13758@end menu
c906108c 13759
8e04817f
AC
13760The @value{GDBN} Text User Interface, TUI in short,
13761is a terminal interface which uses the @code{curses} library
13762to show the source file, the assembly output, the program registers
13763and @value{GDBN} commands in separate text windows.
13764The TUI is available only when @value{GDBN} is configured
13765with the @code{--enable-tui} configure option (@pxref{Configure Options}).
c906108c 13766
8e04817f
AC
13767@node TUI Overview
13768@section TUI overview
c906108c 13769
8e04817f
AC
13770The TUI has two display modes that can be switched while
13771@value{GDBN} runs:
c906108c 13772
8e04817f
AC
13773@itemize @bullet
13774@item
13775A curses (or TUI) mode in which it displays several text
13776windows on the terminal.
c906108c 13777
8e04817f
AC
13778@item
13779A standard mode which corresponds to the @value{GDBN} configured without
13780the TUI.
13781@end itemize
c906108c 13782
8e04817f
AC
13783In the TUI mode, @value{GDBN} can display several text window
13784on the terminal:
c906108c 13785
8e04817f
AC
13786@table @emph
13787@item command
13788This window is the @value{GDBN} command window with the @value{GDBN}
13789prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
13790managed using readline but through the TUI. The @emph{command}
13791window is always visible.
c906108c 13792
8e04817f
AC
13793@item source
13794The source window shows the source file of the program. The current
13795line as well as active breakpoints are displayed in this window.
c906108c 13796
8e04817f
AC
13797@item assembly
13798The assembly window shows the disassembly output of the program.
c906108c 13799
8e04817f
AC
13800@item register
13801This window shows the processor registers. It detects when
13802a register is changed and when this is the case, registers that have
13803changed are highlighted.
c906108c 13804
c906108c
SS
13805@end table
13806
269c21fe
SC
13807The source and assembly windows show the current program position
13808by highlighting the current line and marking them with the @samp{>} marker.
13809Breakpoints are also indicated with two markers. A first one
13810indicates the breakpoint type:
13811
13812@table @code
13813@item B
13814Breakpoint which was hit at least once.
13815
13816@item b
13817Breakpoint which was never hit.
13818
13819@item H
13820Hardware breakpoint which was hit at least once.
13821
13822@item h
13823Hardware breakpoint which was never hit.
13824
13825@end table
13826
13827The second marker indicates whether the breakpoint is enabled or not:
13828
13829@table @code
13830@item +
13831Breakpoint is enabled.
13832
13833@item -
13834Breakpoint is disabled.
13835
13836@end table
13837
8e04817f
AC
13838The source, assembly and register windows are attached to the thread
13839and the frame position. They are updated when the current thread
13840changes, when the frame changes or when the program counter changes.
13841These three windows are arranged by the TUI according to several
13842layouts. The layout defines which of these three windows are visible.
13843The following layouts are available:
c906108c 13844
8e04817f
AC
13845@itemize @bullet
13846@item
13847source
2df3850c 13848
8e04817f
AC
13849@item
13850assembly
13851
13852@item
13853source and assembly
13854
13855@item
13856source and registers
c906108c 13857
8e04817f
AC
13858@item
13859assembly and registers
2df3850c 13860
8e04817f 13861@end itemize
c906108c 13862
b7bb15bc
SC
13863On top of the command window a status line gives various information
13864concerning the current process begin debugged. The status line is
13865updated when the information it shows changes. The following fields
13866are displayed:
13867
13868@table @emph
13869@item target
13870Indicates the current gdb target
13871(@pxref{Targets, ,Specifying a Debugging Target}).
13872
13873@item process
13874Gives information about the current process or thread number.
13875When no process is being debugged, this field is set to @code{No process}.
13876
13877@item function
13878Gives the current function name for the selected frame.
13879The name is demangled if demangling is turned on (@pxref{Print Settings}).
13880When there is no symbol corresponding to the current program counter
13881the string @code{??} is displayed.
13882
13883@item line
13884Indicates the current line number for the selected frame.
13885When the current line number is not known the string @code{??} is displayed.
13886
13887@item pc
13888Indicates the current program counter address.
13889
13890@end table
13891
8e04817f
AC
13892@node TUI Keys
13893@section TUI Key Bindings
13894@cindex TUI key bindings
c906108c 13895
8e04817f
AC
13896The TUI installs several key bindings in the readline keymaps
13897(@pxref{Command Line Editing}).
13898They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
13899directly on the TUI layout and windows. The TUI also provides
13900a @emph{SingleKey} keymap which binds several keys directly to
13901@value{GDBN} commands. The following key bindings
8e04817f 13902are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 13903
8e04817f
AC
13904@table @kbd
13905@kindex C-x C-a
13906@item C-x C-a
13907@kindex C-x a
13908@itemx C-x a
13909@kindex C-x A
13910@itemx C-x A
13911Enter or leave the TUI mode. When the TUI mode is left,
13912the curses window management is left and @value{GDBN} operates using
13913its standard mode writing on the terminal directly. When the TUI
13914mode is entered, the control is given back to the curses windows.
13915The screen is then refreshed.
c906108c 13916
8e04817f
AC
13917@kindex C-x 1
13918@item C-x 1
13919Use a TUI layout with only one window. The layout will
13920either be @samp{source} or @samp{assembly}. When the TUI mode
13921is not active, it will switch to the TUI mode.
2df3850c 13922
8e04817f 13923Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 13924
8e04817f
AC
13925@kindex C-x 2
13926@item C-x 2
13927Use a TUI layout with at least two windows. When the current
13928layout shows already two windows, a next layout with two windows is used.
13929When a new layout is chosen, one window will always be common to the
13930previous layout and the new one.
c906108c 13931
8e04817f 13932Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 13933
72ffddc9
SC
13934@kindex C-x o
13935@item C-x o
13936Change the active window. The TUI associates several key bindings
13937(like scrolling and arrow keys) to the active window. This command
13938gives the focus to the next TUI window.
13939
13940Think of it as the Emacs @kbd{C-x o} binding.
13941
7cf36c78
SC
13942@kindex C-x s
13943@item C-x s
13944Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
13945(@pxref{TUI Single Key Mode}).
13946
c906108c
SS
13947@end table
13948
8e04817f 13949The following key bindings are handled only by the TUI mode:
5d161b24 13950
8e04817f
AC
13951@table @key
13952@kindex PgUp
13953@item PgUp
13954Scroll the active window one page up.
c906108c 13955
8e04817f
AC
13956@kindex PgDn
13957@item PgDn
13958Scroll the active window one page down.
c906108c 13959
8e04817f
AC
13960@kindex Up
13961@item Up
13962Scroll the active window one line up.
c906108c 13963
8e04817f
AC
13964@kindex Down
13965@item Down
13966Scroll the active window one line down.
c906108c 13967
8e04817f
AC
13968@kindex Left
13969@item Left
13970Scroll the active window one column left.
c906108c 13971
8e04817f
AC
13972@kindex Right
13973@item Right
13974Scroll the active window one column right.
c906108c 13975
8e04817f
AC
13976@kindex C-L
13977@item C-L
13978Refresh the screen.
c906108c 13979
8e04817f 13980@end table
c906108c 13981
8e04817f 13982In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
13983for scrolling. This means they are available for readline when the
13984active window is the command window. When the command window
13985does not have the focus, it is necessary to use other readline
13986key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 13987
7cf36c78
SC
13988@node TUI Single Key Mode
13989@section TUI Single Key Mode
13990@cindex TUI single key mode
13991
13992The TUI provides a @emph{SingleKey} mode in which it installs a particular
13993key binding in the readline keymaps to connect single keys to
13994some gdb commands.
13995
13996@table @kbd
13997@kindex c @r{(SingleKey TUI key)}
13998@item c
13999continue
14000
14001@kindex d @r{(SingleKey TUI key)}
14002@item d
14003down
14004
14005@kindex f @r{(SingleKey TUI key)}
14006@item f
14007finish
14008
14009@kindex n @r{(SingleKey TUI key)}
14010@item n
14011next
14012
14013@kindex q @r{(SingleKey TUI key)}
14014@item q
14015exit the @emph{SingleKey} mode.
14016
14017@kindex r @r{(SingleKey TUI key)}
14018@item r
14019run
14020
14021@kindex s @r{(SingleKey TUI key)}
14022@item s
14023step
14024
14025@kindex u @r{(SingleKey TUI key)}
14026@item u
14027up
14028
14029@kindex v @r{(SingleKey TUI key)}
14030@item v
14031info locals
14032
14033@kindex w @r{(SingleKey TUI key)}
14034@item w
14035where
14036
14037@end table
14038
14039Other keys temporarily switch to the @value{GDBN} command prompt.
14040The key that was pressed is inserted in the editing buffer so that
14041it is possible to type most @value{GDBN} commands without interaction
14042with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
14043@emph{SingleKey} mode is restored. The only way to permanently leave
14044this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
14045
14046
8e04817f
AC
14047@node TUI Commands
14048@section TUI specific commands
14049@cindex TUI commands
14050
14051The TUI has specific commands to control the text windows.
14052These commands are always available, that is they do not depend on
14053the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
14054is in the standard mode, using these commands will automatically switch
14055in the TUI mode.
c906108c
SS
14056
14057@table @code
3d757584
SC
14058@item info win
14059@kindex info win
14060List and give the size of all displayed windows.
14061
8e04817f
AC
14062@item layout next
14063@kindex layout next
14064Display the next layout.
2df3850c 14065
8e04817f
AC
14066@item layout prev
14067@kindex layout prev
14068Display the previous layout.
c906108c 14069
8e04817f
AC
14070@item layout src
14071@kindex layout src
14072Display the source window only.
c906108c 14073
8e04817f
AC
14074@item layout asm
14075@kindex layout asm
14076Display the assembly window only.
c906108c 14077
8e04817f
AC
14078@item layout split
14079@kindex layout split
14080Display the source and assembly window.
c906108c 14081
8e04817f
AC
14082@item layout regs
14083@kindex layout regs
14084Display the register window together with the source or assembly window.
14085
14086@item focus next | prev | src | asm | regs | split
14087@kindex focus
14088Set the focus to the named window.
14089This command allows to change the active window so that scrolling keys
14090can be affected to another window.
c906108c 14091
8e04817f
AC
14092@item refresh
14093@kindex refresh
14094Refresh the screen. This is similar to using @key{C-L} key.
c906108c 14095
8e04817f
AC
14096@item update
14097@kindex update
14098Update the source window and the current execution point.
c906108c 14099
8e04817f
AC
14100@item winheight @var{name} +@var{count}
14101@itemx winheight @var{name} -@var{count}
14102@kindex winheight
14103Change the height of the window @var{name} by @var{count}
14104lines. Positive counts increase the height, while negative counts
14105decrease it.
2df3850c 14106
c906108c
SS
14107@end table
14108
8e04817f
AC
14109@node TUI Configuration
14110@section TUI configuration variables
14111@cindex TUI configuration variables
c906108c 14112
8e04817f
AC
14113The TUI has several configuration variables that control the
14114appearance of windows on the terminal.
c906108c 14115
8e04817f
AC
14116@table @code
14117@item set tui border-kind @var{kind}
14118@kindex set tui border-kind
14119Select the border appearance for the source, assembly and register windows.
14120The possible values are the following:
14121@table @code
14122@item space
14123Use a space character to draw the border.
c906108c 14124
8e04817f
AC
14125@item ascii
14126Use ascii characters + - and | to draw the border.
c906108c 14127
8e04817f
AC
14128@item acs
14129Use the Alternate Character Set to draw the border. The border is
14130drawn using character line graphics if the terminal supports them.
c78b4128 14131
8e04817f 14132@end table
c78b4128 14133
8e04817f
AC
14134@item set tui active-border-mode @var{mode}
14135@kindex set tui active-border-mode
14136Select the attributes to display the border of the active window.
14137The possible values are @code{normal}, @code{standout}, @code{reverse},
14138@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 14139
8e04817f
AC
14140@item set tui border-mode @var{mode}
14141@kindex set tui border-mode
14142Select the attributes to display the border of other windows.
14143The @var{mode} can be one of the following:
14144@table @code
14145@item normal
14146Use normal attributes to display the border.
c906108c 14147
8e04817f
AC
14148@item standout
14149Use standout mode.
c906108c 14150
8e04817f
AC
14151@item reverse
14152Use reverse video mode.
c906108c 14153
8e04817f
AC
14154@item half
14155Use half bright mode.
c906108c 14156
8e04817f
AC
14157@item half-standout
14158Use half bright and standout mode.
c906108c 14159
8e04817f
AC
14160@item bold
14161Use extra bright or bold mode.
c78b4128 14162
8e04817f
AC
14163@item bold-standout
14164Use extra bright or bold and standout mode.
c78b4128 14165
8e04817f 14166@end table
c78b4128 14167
8e04817f 14168@end table
c78b4128 14169
8e04817f
AC
14170@node Emacs
14171@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 14172
8e04817f
AC
14173@cindex Emacs
14174@cindex @sc{gnu} Emacs
14175A special interface allows you to use @sc{gnu} Emacs to view (and
14176edit) the source files for the program you are debugging with
14177@value{GDBN}.
c906108c 14178
8e04817f
AC
14179To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
14180executable file you want to debug as an argument. This command starts
14181@value{GDBN} as a subprocess of Emacs, with input and output through a newly
14182created Emacs buffer.
14183@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 14184
8e04817f
AC
14185Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
14186things:
c906108c 14187
8e04817f
AC
14188@itemize @bullet
14189@item
14190All ``terminal'' input and output goes through the Emacs buffer.
14191@end itemize
c906108c 14192
8e04817f
AC
14193This applies both to @value{GDBN} commands and their output, and to the input
14194and output done by the program you are debugging.
bf0184be 14195
8e04817f
AC
14196This is useful because it means that you can copy the text of previous
14197commands and input them again; you can even use parts of the output
14198in this way.
bf0184be 14199
8e04817f
AC
14200All the facilities of Emacs' Shell mode are available for interacting
14201with your program. In particular, you can send signals the usual
14202way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
14203stop.
bf0184be 14204
8e04817f 14205@itemize @bullet
bf0184be 14206@item
8e04817f
AC
14207@value{GDBN} displays source code through Emacs.
14208@end itemize
bf0184be 14209
8e04817f
AC
14210Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
14211source file for that frame and puts an arrow (@samp{=>}) at the
14212left margin of the current line. Emacs uses a separate buffer for
14213source display, and splits the screen to show both your @value{GDBN} session
14214and the source.
bf0184be 14215
8e04817f
AC
14216Explicit @value{GDBN} @code{list} or search commands still produce output as
14217usual, but you probably have no reason to use them from Emacs.
c906108c 14218
64fabec2
AC
14219If you specify an absolute file name when prompted for the @kbd{M-x
14220gdb} argument, then Emacs sets your current working directory to where
14221your program resides. If you only specify the file name, then Emacs
14222sets your current working directory to to the directory associated
14223with the previous buffer. In this case, @value{GDBN} may find your
14224program by searching your environment's @code{PATH} variable, but on
14225some operating systems it might not find the source. So, although the
14226@value{GDBN} input and output session proceeds normally, the auxiliary
14227buffer does not display the current source and line of execution.
14228
14229The initial working directory of @value{GDBN} is printed on the top
14230line of the @value{GDBN} I/O buffer and this serves as a default for
14231the commands that specify files for @value{GDBN} to operate
14232on. @xref{Files, ,Commands to specify files}.
14233
14234By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
14235need to call @value{GDBN} by a different name (for example, if you
14236keep several configurations around, with different names) you can
14237customize the Emacs variable @code{gud-gdb-command-name} to run the
14238one you want.
8e04817f
AC
14239
14240In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
14241addition to the standard Shell mode commands:
c906108c 14242
8e04817f
AC
14243@table @kbd
14244@item C-h m
14245Describe the features of Emacs' @value{GDBN} Mode.
c906108c 14246
64fabec2 14247@item C-c C-s
8e04817f
AC
14248Execute to another source line, like the @value{GDBN} @code{step} command; also
14249update the display window to show the current file and location.
c906108c 14250
64fabec2 14251@item C-c C-n
8e04817f
AC
14252Execute to next source line in this function, skipping all function
14253calls, like the @value{GDBN} @code{next} command. Then update the display window
14254to show the current file and location.
c906108c 14255
64fabec2 14256@item C-c C-i
8e04817f
AC
14257Execute one instruction, like the @value{GDBN} @code{stepi} command; update
14258display window accordingly.
c906108c 14259
8e04817f
AC
14260@item C-c C-f
14261Execute until exit from the selected stack frame, like the @value{GDBN}
14262@code{finish} command.
c906108c 14263
64fabec2 14264@item C-c C-r
8e04817f
AC
14265Continue execution of your program, like the @value{GDBN} @code{continue}
14266command.
b433d00b 14267
64fabec2 14268@item C-c <
8e04817f
AC
14269Go up the number of frames indicated by the numeric argument
14270(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
14271like the @value{GDBN} @code{up} command.
b433d00b 14272
64fabec2 14273@item C-c >
8e04817f
AC
14274Go down the number of frames indicated by the numeric argument, like the
14275@value{GDBN} @code{down} command.
8e04817f 14276@end table
c906108c 14277
64fabec2 14278In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 14279tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 14280
64fabec2
AC
14281If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
14282shows a backtrace when the @value{GDBN} I/O buffer is current. Move
14283point to any frame in the stack and type @key{RET} to make it become the
14284current frame and display the associated source in the source buffer.
14285Alternatively, click @kbd{Mouse-2} to make the selected frame become the
14286current one.
14287
8e04817f
AC
14288If you accidentally delete the source-display buffer, an easy way to get
14289it back is to type the command @code{f} in the @value{GDBN} buffer, to
14290request a frame display; when you run under Emacs, this recreates
14291the source buffer if necessary to show you the context of the current
14292frame.
c906108c 14293
8e04817f
AC
14294The source files displayed in Emacs are in ordinary Emacs buffers
14295which are visiting the source files in the usual way. You can edit
14296the files with these buffers if you wish; but keep in mind that @value{GDBN}
14297communicates with Emacs in terms of line numbers. If you add or
14298delete lines from the text, the line numbers that @value{GDBN} knows cease
14299to correspond properly with the code.
64fabec2
AC
14300
14301The description given here is for GNU Emacs version 21.3 and a more
14302detailed description of its interaction with @value{GDBN} is given in
14303the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 14304
8e04817f
AC
14305@c The following dropped because Epoch is nonstandard. Reactivate
14306@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
14307@ignore
14308@kindex Emacs Epoch environment
14309@kindex Epoch
14310@kindex inspect
c906108c 14311
8e04817f
AC
14312Version 18 of @sc{gnu} Emacs has a built-in window system
14313called the @code{epoch}
14314environment. Users of this environment can use a new command,
14315@code{inspect} which performs identically to @code{print} except that
14316each value is printed in its own window.
14317@end ignore
c906108c 14318
922fbb7b
AC
14319
14320@node GDB/MI
14321@chapter The @sc{gdb/mi} Interface
14322
14323@unnumberedsec Function and Purpose
14324
14325@cindex @sc{gdb/mi}, its purpose
14326@sc{gdb/mi} is a line based machine oriented text interface to @value{GDBN}. It is
14327specifically intended to support the development of systems which use
14328the debugger as just one small component of a larger system.
14329
14330This chapter is a specification of the @sc{gdb/mi} interface. It is written
14331in the form of a reference manual.
14332
14333Note that @sc{gdb/mi} is still under construction, so some of the
14334features described below are incomplete and subject to change.
14335
14336@unnumberedsec Notation and Terminology
14337
14338@cindex notational conventions, for @sc{gdb/mi}
14339This chapter uses the following notation:
14340
14341@itemize @bullet
14342@item
14343@code{|} separates two alternatives.
14344
14345@item
14346@code{[ @var{something} ]} indicates that @var{something} is optional:
14347it may or may not be given.
14348
14349@item
14350@code{( @var{group} )*} means that @var{group} inside the parentheses
14351may repeat zero or more times.
14352
14353@item
14354@code{( @var{group} )+} means that @var{group} inside the parentheses
14355may repeat one or more times.
14356
14357@item
14358@code{"@var{string}"} means a literal @var{string}.
14359@end itemize
14360
14361@ignore
14362@heading Dependencies
14363@end ignore
14364
14365@heading Acknowledgments
14366
14367In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
14368Elena Zannoni.
14369
14370@menu
14371* GDB/MI Command Syntax::
14372* GDB/MI Compatibility with CLI::
14373* GDB/MI Output Records::
14374* GDB/MI Command Description Format::
14375* GDB/MI Breakpoint Table Commands::
14376* GDB/MI Data Manipulation::
14377* GDB/MI Program Control::
14378* GDB/MI Miscellaneous Commands::
14379@ignore
14380* GDB/MI Kod Commands::
14381* GDB/MI Memory Overlay Commands::
14382* GDB/MI Signal Handling Commands::
14383@end ignore
14384* GDB/MI Stack Manipulation::
14385* GDB/MI Symbol Query::
14386* GDB/MI Target Manipulation::
14387* GDB/MI Thread Commands::
14388* GDB/MI Tracepoint Commands::
14389* GDB/MI Variable Objects::
14390@end menu
14391
14392@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14393@node GDB/MI Command Syntax
14394@section @sc{gdb/mi} Command Syntax
14395
14396@menu
14397* GDB/MI Input Syntax::
14398* GDB/MI Output Syntax::
14399* GDB/MI Simple Examples::
14400@end menu
14401
14402@node GDB/MI Input Syntax
14403@subsection @sc{gdb/mi} Input Syntax
14404
14405@cindex input syntax for @sc{gdb/mi}
14406@cindex @sc{gdb/mi}, input syntax
14407@table @code
14408@item @var{command} @expansion{}
14409@code{@var{cli-command} | @var{mi-command}}
14410
14411@item @var{cli-command} @expansion{}
14412@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
14413@var{cli-command} is any existing @value{GDBN} CLI command.
14414
14415@item @var{mi-command} @expansion{}
14416@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
14417@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
14418
14419@item @var{token} @expansion{}
14420"any sequence of digits"
14421
14422@item @var{option} @expansion{}
14423@code{"-" @var{parameter} [ " " @var{parameter} ]}
14424
14425@item @var{parameter} @expansion{}
14426@code{@var{non-blank-sequence} | @var{c-string}}
14427
14428@item @var{operation} @expansion{}
14429@emph{any of the operations described in this chapter}
14430
14431@item @var{non-blank-sequence} @expansion{}
14432@emph{anything, provided it doesn't contain special characters such as
14433"-", @var{nl}, """ and of course " "}
14434
14435@item @var{c-string} @expansion{}
14436@code{""" @var{seven-bit-iso-c-string-content} """}
14437
14438@item @var{nl} @expansion{}
14439@code{CR | CR-LF}
14440@end table
14441
14442@noindent
14443Notes:
14444
14445@itemize @bullet
14446@item
14447The CLI commands are still handled by the @sc{mi} interpreter; their
14448output is described below.
14449
14450@item
14451The @code{@var{token}}, when present, is passed back when the command
14452finishes.
14453
14454@item
14455Some @sc{mi} commands accept optional arguments as part of the parameter
14456list. Each option is identified by a leading @samp{-} (dash) and may be
14457followed by an optional argument parameter. Options occur first in the
14458parameter list and can be delimited from normal parameters using
14459@samp{--} (this is useful when some parameters begin with a dash).
14460@end itemize
14461
14462Pragmatics:
14463
14464@itemize @bullet
14465@item
14466We want easy access to the existing CLI syntax (for debugging).
14467
14468@item
14469We want it to be easy to spot a @sc{mi} operation.
14470@end itemize
14471
14472@node GDB/MI Output Syntax
14473@subsection @sc{gdb/mi} Output Syntax
14474
14475@cindex output syntax of @sc{gdb/mi}
14476@cindex @sc{gdb/mi}, output syntax
14477The output from @sc{gdb/mi} consists of zero or more out-of-band records
14478followed, optionally, by a single result record. This result record
14479is for the most recent command. The sequence of output records is
14480terminated by @samp{(@value{GDBP})}.
14481
14482If an input command was prefixed with a @code{@var{token}} then the
14483corresponding output for that command will also be prefixed by that same
14484@var{token}.
14485
14486@table @code
14487@item @var{output} @expansion{}
14488@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
14489
14490@item @var{result-record} @expansion{}
14491@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
14492
14493@item @var{out-of-band-record} @expansion{}
14494@code{@var{async-record} | @var{stream-record}}
14495
14496@item @var{async-record} @expansion{}
14497@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
14498
14499@item @var{exec-async-output} @expansion{}
14500@code{[ @var{token} ] "*" @var{async-output}}
14501
14502@item @var{status-async-output} @expansion{}
14503@code{[ @var{token} ] "+" @var{async-output}}
14504
14505@item @var{notify-async-output} @expansion{}
14506@code{[ @var{token} ] "=" @var{async-output}}
14507
14508@item @var{async-output} @expansion{}
14509@code{@var{async-class} ( "," @var{result} )* @var{nl}}
14510
14511@item @var{result-class} @expansion{}
14512@code{"done" | "running" | "connected" | "error" | "exit"}
14513
14514@item @var{async-class} @expansion{}
14515@code{"stopped" | @var{others}} (where @var{others} will be added
14516depending on the needs---this is still in development).
14517
14518@item @var{result} @expansion{}
14519@code{ @var{variable} "=" @var{value}}
14520
14521@item @var{variable} @expansion{}
14522@code{ @var{string} }
14523
14524@item @var{value} @expansion{}
14525@code{ @var{const} | @var{tuple} | @var{list} }
14526
14527@item @var{const} @expansion{}
14528@code{@var{c-string}}
14529
14530@item @var{tuple} @expansion{}
14531@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
14532
14533@item @var{list} @expansion{}
14534@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
14535@var{result} ( "," @var{result} )* "]" }
14536
14537@item @var{stream-record} @expansion{}
14538@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
14539
14540@item @var{console-stream-output} @expansion{}
14541@code{"~" @var{c-string}}
14542
14543@item @var{target-stream-output} @expansion{}
14544@code{"@@" @var{c-string}}
14545
14546@item @var{log-stream-output} @expansion{}
14547@code{"&" @var{c-string}}
14548
14549@item @var{nl} @expansion{}
14550@code{CR | CR-LF}
14551
14552@item @var{token} @expansion{}
14553@emph{any sequence of digits}.
14554@end table
14555
14556@noindent
14557Notes:
14558
14559@itemize @bullet
14560@item
14561All output sequences end in a single line containing a period.
14562
14563@item
14564The @code{@var{token}} is from the corresponding request. If an execution
14565command is interrupted by the @samp{-exec-interrupt} command, the
14566@var{token} associated with the @samp{*stopped} message is the one of the
14567original execution command, not the one of the interrupt command.
14568
14569@item
14570@cindex status output in @sc{gdb/mi}
14571@var{status-async-output} contains on-going status information about the
14572progress of a slow operation. It can be discarded. All status output is
14573prefixed by @samp{+}.
14574
14575@item
14576@cindex async output in @sc{gdb/mi}
14577@var{exec-async-output} contains asynchronous state change on the target
14578(stopped, started, disappeared). All async output is prefixed by
14579@samp{*}.
14580
14581@item
14582@cindex notify output in @sc{gdb/mi}
14583@var{notify-async-output} contains supplementary information that the
14584client should handle (e.g., a new breakpoint information). All notify
14585output is prefixed by @samp{=}.
14586
14587@item
14588@cindex console output in @sc{gdb/mi}
14589@var{console-stream-output} is output that should be displayed as is in the
14590console. It is the textual response to a CLI command. All the console
14591output is prefixed by @samp{~}.
14592
14593@item
14594@cindex target output in @sc{gdb/mi}
14595@var{target-stream-output} is the output produced by the target program.
14596All the target output is prefixed by @samp{@@}.
14597
14598@item
14599@cindex log output in @sc{gdb/mi}
14600@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
14601instance messages that should be displayed as part of an error log. All
14602the log output is prefixed by @samp{&}.
14603
14604@item
14605@cindex list output in @sc{gdb/mi}
14606New @sc{gdb/mi} commands should only output @var{lists} containing
14607@var{values}.
14608
14609
14610@end itemize
14611
14612@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
14613details about the various output records.
14614
14615@node GDB/MI Simple Examples
14616@subsection Simple Examples of @sc{gdb/mi} Interaction
14617@cindex @sc{gdb/mi}, simple examples
14618
14619This subsection presents several simple examples of interaction using
14620the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
14621following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
14622the output received from @sc{gdb/mi}.
14623
14624@subsubheading Target Stop
14625@c Ummm... There is no "-stop" command. This assumes async, no?
14626Here's an example of stopping the inferior process:
14627
14628@smallexample
14629-> -stop
14630<- (@value{GDBP})
14631@end smallexample
14632
14633@noindent
14634and later:
14635
14636@smallexample
14637<- *stop,reason="stop",address="0x123",source="a.c:123"
14638<- (@value{GDBP})
14639@end smallexample
14640
14641@subsubheading Simple CLI Command
14642
14643Here's an example of a simple CLI command being passed through
14644@sc{gdb/mi} and on to the CLI.
14645
14646@smallexample
14647-> print 1+2
14648<- &"print 1+2\n"
14649<- ~"$1 = 3\n"
14650<- ^done
14651<- (@value{GDBP})
14652@end smallexample
14653
14654@subsubheading Command With Side Effects
14655
14656@smallexample
14657-> -symbol-file xyz.exe
14658<- *breakpoint,nr="3",address="0x123",source="a.c:123"
14659<- (@value{GDBP})
14660@end smallexample
14661
14662@subsubheading A Bad Command
14663
14664Here's what happens if you pass a non-existent command:
14665
14666@smallexample
14667-> -rubbish
14668<- ^error,msg="Undefined MI command: rubbish"
14669<- (@value{GDBP})
14670@end smallexample
14671
14672@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14673@node GDB/MI Compatibility with CLI
14674@section @sc{gdb/mi} Compatibility with CLI
14675
14676@cindex compatibility, @sc{gdb/mi} and CLI
14677@cindex @sc{gdb/mi}, compatibility with CLI
14678To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
14679accepts existing CLI commands. As specified by the syntax, such
14680commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
14681respond.
14682
14683This mechanism is provided as an aid to developers of @sc{gdb/mi}
14684clients and not as a reliable interface into the CLI. Since the command
14685is being interpreteted in an environment that assumes @sc{gdb/mi}
14686behaviour, the exact output of such commands is likely to end up being
14687an un-supported hybrid of @sc{gdb/mi} and CLI output.
14688
14689@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14690@node GDB/MI Output Records
14691@section @sc{gdb/mi} Output Records
14692
14693@menu
14694* GDB/MI Result Records::
14695* GDB/MI Stream Records::
14696* GDB/MI Out-of-band Records::
14697@end menu
14698
14699@node GDB/MI Result Records
14700@subsection @sc{gdb/mi} Result Records
14701
14702@cindex result records in @sc{gdb/mi}
14703@cindex @sc{gdb/mi}, result records
14704In addition to a number of out-of-band notifications, the response to a
14705@sc{gdb/mi} command includes one of the following result indications:
14706
14707@table @code
14708@findex ^done
14709@item "^done" [ "," @var{results} ]
14710The synchronous operation was successful, @code{@var{results}} are the return
14711values.
14712
14713@item "^running"
14714@findex ^running
14715@c Is this one correct? Should it be an out-of-band notification?
14716The asynchronous operation was successfully started. The target is
14717running.
14718
14719@item "^error" "," @var{c-string}
14720@findex ^error
14721The operation failed. The @code{@var{c-string}} contains the corresponding
14722error message.
14723@end table
14724
14725@node GDB/MI Stream Records
14726@subsection @sc{gdb/mi} Stream Records
14727
14728@cindex @sc{gdb/mi}, stream records
14729@cindex stream records in @sc{gdb/mi}
14730@value{GDBN} internally maintains a number of output streams: the console, the
14731target, and the log. The output intended for each of these streams is
14732funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
14733
14734Each stream record begins with a unique @dfn{prefix character} which
14735identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
14736Syntax}). In addition to the prefix, each stream record contains a
14737@code{@var{string-output}}. This is either raw text (with an implicit new
14738line) or a quoted C string (which does not contain an implicit newline).
14739
14740@table @code
14741@item "~" @var{string-output}
14742The console output stream contains text that should be displayed in the
14743CLI console window. It contains the textual responses to CLI commands.
14744
14745@item "@@" @var{string-output}
14746The target output stream contains any textual output from the running
14747target.
14748
14749@item "&" @var{string-output}
14750The log stream contains debugging messages being produced by @value{GDBN}'s
14751internals.
14752@end table
14753
14754@node GDB/MI Out-of-band Records
14755@subsection @sc{gdb/mi} Out-of-band Records
14756
14757@cindex out-of-band records in @sc{gdb/mi}
14758@cindex @sc{gdb/mi}, out-of-band records
14759@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
14760additional changes that have occurred. Those changes can either be a
14761consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
14762target activity (e.g., target stopped).
14763
14764The following is a preliminary list of possible out-of-band records.
14765
14766@table @code
14767@item "*" "stop"
14768@end table
14769
14770
14771@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14772@node GDB/MI Command Description Format
14773@section @sc{gdb/mi} Command Description Format
14774
14775The remaining sections describe blocks of commands. Each block of
14776commands is laid out in a fashion similar to this section.
14777
14778Note the the line breaks shown in the examples are here only for
14779readability. They don't appear in the real output.
14780Also note that the commands with a non-available example (N.A.@:) are
14781not yet implemented.
14782
14783@subheading Motivation
14784
14785The motivation for this collection of commands.
14786
14787@subheading Introduction
14788
14789A brief introduction to this collection of commands as a whole.
14790
14791@subheading Commands
14792
14793For each command in the block, the following is described:
14794
14795@subsubheading Synopsis
14796
14797@smallexample
14798 -command @var{args}@dots{}
14799@end smallexample
14800
14801@subsubheading @value{GDBN} Command
14802
14803The corresponding @value{GDBN} CLI command.
14804
14805@subsubheading Result
14806
14807@subsubheading Out-of-band
14808
14809@subsubheading Notes
14810
14811@subsubheading Example
14812
14813
14814@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14815@node GDB/MI Breakpoint Table Commands
14816@section @sc{gdb/mi} Breakpoint table commands
14817
14818@cindex breakpoint commands for @sc{gdb/mi}
14819@cindex @sc{gdb/mi}, breakpoint commands
14820This section documents @sc{gdb/mi} commands for manipulating
14821breakpoints.
14822
14823@subheading The @code{-break-after} Command
14824@findex -break-after
14825
14826@subsubheading Synopsis
14827
14828@smallexample
14829 -break-after @var{number} @var{count}
14830@end smallexample
14831
14832The breakpoint number @var{number} is not in effect until it has been
14833hit @var{count} times. To see how this is reflected in the output of
14834the @samp{-break-list} command, see the description of the
14835@samp{-break-list} command below.
14836
14837@subsubheading @value{GDBN} Command
14838
14839The corresponding @value{GDBN} command is @samp{ignore}.
14840
14841@subsubheading Example
14842
14843@smallexample
14844(@value{GDBP})
14845-break-insert main
14846^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
14847(@value{GDBP})
14848-break-after 1 3
14849~
14850^done
14851(@value{GDBP})
14852-break-list
14853^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
14854hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
14855@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
14856@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
14857@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
14858@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
14859@{width="40",alignment="2",col_name="what",colhdr="What"@}],
14860body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
14861addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
14862ignore="3"@}]@}
14863(@value{GDBP})
14864@end smallexample
14865
14866@ignore
14867@subheading The @code{-break-catch} Command
14868@findex -break-catch
14869
14870@subheading The @code{-break-commands} Command
14871@findex -break-commands
14872@end ignore
14873
14874
14875@subheading The @code{-break-condition} Command
14876@findex -break-condition
14877
14878@subsubheading Synopsis
14879
14880@smallexample
14881 -break-condition @var{number} @var{expr}
14882@end smallexample
14883
14884Breakpoint @var{number} will stop the program only if the condition in
14885@var{expr} is true. The condition becomes part of the
14886@samp{-break-list} output (see the description of the @samp{-break-list}
14887command below).
14888
14889@subsubheading @value{GDBN} Command
14890
14891The corresponding @value{GDBN} command is @samp{condition}.
14892
14893@subsubheading Example
14894
14895@smallexample
14896(@value{GDBP})
14897-break-condition 1 1
14898^done
14899(@value{GDBP})
14900-break-list
14901^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
14902hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
14903@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
14904@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
14905@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
14906@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
14907@{width="40",alignment="2",col_name="what",colhdr="What"@}],
14908body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
14909addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
14910times="0",ignore="3"@}]@}
14911(@value{GDBP})
14912@end smallexample
14913
14914@subheading The @code{-break-delete} Command
14915@findex -break-delete
14916
14917@subsubheading Synopsis
14918
14919@smallexample
14920 -break-delete ( @var{breakpoint} )+
14921@end smallexample
14922
14923Delete the breakpoint(s) whose number(s) are specified in the argument
14924list. This is obviously reflected in the breakpoint list.
14925
14926@subsubheading @value{GDBN} command
14927
14928The corresponding @value{GDBN} command is @samp{delete}.
14929
14930@subsubheading Example
14931
14932@smallexample
14933(@value{GDBP})
14934-break-delete 1
14935^done
14936(@value{GDBP})
14937-break-list
14938^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
14939hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
14940@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
14941@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
14942@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
14943@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
14944@{width="40",alignment="2",col_name="what",colhdr="What"@}],
14945body=[]@}
14946(@value{GDBP})
14947@end smallexample
14948
14949@subheading The @code{-break-disable} Command
14950@findex -break-disable
14951
14952@subsubheading Synopsis
14953
14954@smallexample
14955 -break-disable ( @var{breakpoint} )+
14956@end smallexample
14957
14958Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
14959break list is now set to @samp{n} for the named @var{breakpoint}(s).
14960
14961@subsubheading @value{GDBN} Command
14962
14963The corresponding @value{GDBN} command is @samp{disable}.
14964
14965@subsubheading Example
14966
14967@smallexample
14968(@value{GDBP})
14969-break-disable 2
14970^done
14971(@value{GDBP})
14972-break-list
14973^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
14974hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
14975@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
14976@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
14977@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
14978@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
14979@{width="40",alignment="2",col_name="what",colhdr="What"@}],
14980body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
14981addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
14982(@value{GDBP})
14983@end smallexample
14984
14985@subheading The @code{-break-enable} Command
14986@findex -break-enable
14987
14988@subsubheading Synopsis
14989
14990@smallexample
14991 -break-enable ( @var{breakpoint} )+
14992@end smallexample
14993
14994Enable (previously disabled) @var{breakpoint}(s).
14995
14996@subsubheading @value{GDBN} Command
14997
14998The corresponding @value{GDBN} command is @samp{enable}.
14999
15000@subsubheading Example
15001
15002@smallexample
15003(@value{GDBP})
15004-break-enable 2
15005^done
15006(@value{GDBP})
15007-break-list
15008^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15009hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15010@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15011@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15012@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15013@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15014@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15015body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
15016addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
15017(@value{GDBP})
15018@end smallexample
15019
15020@subheading The @code{-break-info} Command
15021@findex -break-info
15022
15023@subsubheading Synopsis
15024
15025@smallexample
15026 -break-info @var{breakpoint}
15027@end smallexample
15028
15029@c REDUNDANT???
15030Get information about a single breakpoint.
15031
15032@subsubheading @value{GDBN} command
15033
15034The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
15035
15036@subsubheading Example
15037N.A.
15038
15039@subheading The @code{-break-insert} Command
15040@findex -break-insert
15041
15042@subsubheading Synopsis
15043
15044@smallexample
15045 -break-insert [ -t ] [ -h ] [ -r ]
15046 [ -c @var{condition} ] [ -i @var{ignore-count} ]
15047 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
15048@end smallexample
15049
15050@noindent
15051If specified, @var{line}, can be one of:
15052
15053@itemize @bullet
15054@item function
15055@c @item +offset
15056@c @item -offset
15057@c @item linenum
15058@item filename:linenum
15059@item filename:function
15060@item *address
15061@end itemize
15062
15063The possible optional parameters of this command are:
15064
15065@table @samp
15066@item -t
15067Insert a tempoary breakpoint.
15068@item -h
15069Insert a hardware breakpoint.
15070@item -c @var{condition}
15071Make the breakpoint conditional on @var{condition}.
15072@item -i @var{ignore-count}
15073Initialize the @var{ignore-count}.
15074@item -r
15075Insert a regular breakpoint in all the functions whose names match the
15076given regular expression. Other flags are not applicable to regular
15077expresson.
15078@end table
15079
15080@subsubheading Result
15081
15082The result is in the form:
15083
15084@smallexample
15085 ^done,bkptno="@var{number}",func="@var{funcname}",
15086 file="@var{filename}",line="@var{lineno}"
15087@end smallexample
15088
15089@noindent
15090where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
15091is the name of the function where the breakpoint was inserted,
15092@var{filename} is the name of the source file which contains this
15093function, and @var{lineno} is the source line number within that file.
15094
15095Note: this format is open to change.
15096@c An out-of-band breakpoint instead of part of the result?
15097
15098@subsubheading @value{GDBN} Command
15099
15100The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
15101@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
15102
15103@subsubheading Example
15104
15105@smallexample
15106(@value{GDBP})
15107-break-insert main
15108^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
15109(@value{GDBP})
15110-break-insert -t foo
15111^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
15112(@value{GDBP})
15113-break-list
15114^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15115hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15116@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15117@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15118@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15119@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15120@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15121body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15122addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
15123bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
15124addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
15125(@value{GDBP})
15126-break-insert -r foo.*
15127~int foo(int, int);
15128^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
15129(@value{GDBP})
15130@end smallexample
15131
15132@subheading The @code{-break-list} Command
15133@findex -break-list
15134
15135@subsubheading Synopsis
15136
15137@smallexample
15138 -break-list
15139@end smallexample
15140
15141Displays the list of inserted breakpoints, showing the following fields:
15142
15143@table @samp
15144@item Number
15145number of the breakpoint
15146@item Type
15147type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
15148@item Disposition
15149should the breakpoint be deleted or disabled when it is hit: @samp{keep}
15150or @samp{nokeep}
15151@item Enabled
15152is the breakpoint enabled or no: @samp{y} or @samp{n}
15153@item Address
15154memory location at which the breakpoint is set
15155@item What
15156logical location of the breakpoint, expressed by function name, file
15157name, line number
15158@item Times
15159number of times the breakpoint has been hit
15160@end table
15161
15162If there are no breakpoints or watchpoints, the @code{BreakpointTable}
15163@code{body} field is an empty list.
15164
15165@subsubheading @value{GDBN} Command
15166
15167The corresponding @value{GDBN} command is @samp{info break}.
15168
15169@subsubheading Example
15170
15171@smallexample
15172(@value{GDBP})
15173-break-list
15174^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15175hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15176@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15177@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15178@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15179@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15180@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15181body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15182addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
15183bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
15184addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
15185(@value{GDBP})
15186@end smallexample
15187
15188Here's an example of the result when there are no breakpoints:
15189
15190@smallexample
15191(@value{GDBP})
15192-break-list
15193^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
15194hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15195@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15196@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15197@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15198@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15199@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15200body=[]@}
15201(@value{GDBP})
15202@end smallexample
15203
15204@subheading The @code{-break-watch} Command
15205@findex -break-watch
15206
15207@subsubheading Synopsis
15208
15209@smallexample
15210 -break-watch [ -a | -r ]
15211@end smallexample
15212
15213Create a watchpoint. With the @samp{-a} option it will create an
15214@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
15215read from or on a write to the memory location. With the @samp{-r}
15216option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
15217trigger only when the memory location is accessed for reading. Without
15218either of the options, the watchpoint created is a regular watchpoint,
15219i.e. it will trigger when the memory location is accessed for writing.
15220@xref{Set Watchpoints, , Setting watchpoints}.
15221
15222Note that @samp{-break-list} will report a single list of watchpoints and
15223breakpoints inserted.
15224
15225@subsubheading @value{GDBN} Command
15226
15227The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
15228@samp{rwatch}.
15229
15230@subsubheading Example
15231
15232Setting a watchpoint on a variable in the @code{main} function:
15233
15234@smallexample
15235(@value{GDBP})
15236-break-watch x
15237^done,wpt=@{number="2",exp="x"@}
15238(@value{GDBP})
15239-exec-continue
15240^running
15241^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
15242value=@{old="-268439212",new="55"@},
15243frame=@{func="main",args=[],file="recursive2.c",line="5"@}
15244(@value{GDBP})
15245@end smallexample
15246
15247Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
15248the program execution twice: first for the variable changing value, then
15249for the watchpoint going out of scope.
15250
15251@smallexample
15252(@value{GDBP})
15253-break-watch C
15254^done,wpt=@{number="5",exp="C"@}
15255(@value{GDBP})
15256-exec-continue
15257^running
15258^done,reason="watchpoint-trigger",
15259wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
15260frame=@{func="callee4",args=[],
15261file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
15262(@value{GDBP})
15263-exec-continue
15264^running
15265^done,reason="watchpoint-scope",wpnum="5",
15266frame=@{func="callee3",args=[@{name="strarg",
15267value="0x11940 \"A string argument.\""@}],
15268file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
15269(@value{GDBP})
15270@end smallexample
15271
15272Listing breakpoints and watchpoints, at different points in the program
15273execution. Note that once the watchpoint goes out of scope, it is
15274deleted.
15275
15276@smallexample
15277(@value{GDBP})
15278-break-watch C
15279^done,wpt=@{number="2",exp="C"@}
15280(@value{GDBP})
15281-break-list
15282^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15283hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15284@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15285@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15286@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15287@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15288@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15289body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15290addr="0x00010734",func="callee4",
15291file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
15292bkpt=@{number="2",type="watchpoint",disp="keep",
15293enabled="y",addr="",what="C",times="0"@}]@}
15294(@value{GDBP})
15295-exec-continue
15296^running
15297^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
15298value=@{old="-276895068",new="3"@},
15299frame=@{func="callee4",args=[],
15300file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
15301(@value{GDBP})
15302-break-list
15303^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15304hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15305@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15306@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15307@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15308@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15309@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15310body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15311addr="0x00010734",func="callee4",
15312file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
15313bkpt=@{number="2",type="watchpoint",disp="keep",
15314enabled="y",addr="",what="C",times="-5"@}]@}
15315(@value{GDBP})
15316-exec-continue
15317^running
15318^done,reason="watchpoint-scope",wpnum="2",
15319frame=@{func="callee3",args=[@{name="strarg",
15320value="0x11940 \"A string argument.\""@}],
15321file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
15322(@value{GDBP})
15323-break-list
15324^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15325hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15326@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15327@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15328@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15329@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15330@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15331body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15332addr="0x00010734",func="callee4",
15333file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
15334(@value{GDBP})
15335@end smallexample
15336
15337@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15338@node GDB/MI Data Manipulation
15339@section @sc{gdb/mi} Data Manipulation
15340
15341@cindex data manipulation, in @sc{gdb/mi}
15342@cindex @sc{gdb/mi}, data manipulation
15343This section describes the @sc{gdb/mi} commands that manipulate data:
15344examine memory and registers, evaluate expressions, etc.
15345
15346@c REMOVED FROM THE INTERFACE.
15347@c @subheading -data-assign
15348@c Change the value of a program variable. Plenty of side effects.
15349@c @subsubheading GDB command
15350@c set variable
15351@c @subsubheading Example
15352@c N.A.
15353
15354@subheading The @code{-data-disassemble} Command
15355@findex -data-disassemble
15356
15357@subsubheading Synopsis
15358
15359@smallexample
15360 -data-disassemble
15361 [ -s @var{start-addr} -e @var{end-addr} ]
15362 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
15363 -- @var{mode}
15364@end smallexample
15365
15366@noindent
15367Where:
15368
15369@table @samp
15370@item @var{start-addr}
15371is the beginning address (or @code{$pc})
15372@item @var{end-addr}
15373is the end address
15374@item @var{filename}
15375is the name of the file to disassemble
15376@item @var{linenum}
15377is the line number to disassemble around
15378@item @var{lines}
15379is the the number of disassembly lines to be produced. If it is -1,
15380the whole function will be disassembled, in case no @var{end-addr} is
15381specified. If @var{end-addr} is specified as a non-zero value, and
15382@var{lines} is lower than the number of disassembly lines between
15383@var{start-addr} and @var{end-addr}, only @var{lines} lines are
15384displayed; if @var{lines} is higher than the number of lines between
15385@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
15386are displayed.
15387@item @var{mode}
15388is either 0 (meaning only disassembly) or 1 (meaning mixed source and
15389disassembly).
15390@end table
15391
15392@subsubheading Result
15393
15394The output for each instruction is composed of four fields:
15395
15396@itemize @bullet
15397@item Address
15398@item Func-name
15399@item Offset
15400@item Instruction
15401@end itemize
15402
15403Note that whatever included in the instruction field, is not manipulated
15404directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
15405
15406@subsubheading @value{GDBN} Command
15407
15408There's no direct mapping from this command to the CLI.
15409
15410@subsubheading Example
15411
15412Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
15413
15414@smallexample
15415(@value{GDBP})
15416-data-disassemble -s $pc -e "$pc + 20" -- 0
15417^done,
15418asm_insns=[
15419@{address="0x000107c0",func-name="main",offset="4",
15420inst="mov 2, %o0"@},
15421@{address="0x000107c4",func-name="main",offset="8",
15422inst="sethi %hi(0x11800), %o2"@},
15423@{address="0x000107c8",func-name="main",offset="12",
15424inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
15425@{address="0x000107cc",func-name="main",offset="16",
15426inst="sethi %hi(0x11800), %o2"@},
15427@{address="0x000107d0",func-name="main",offset="20",
15428inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
15429(@value{GDBP})
15430@end smallexample
15431
15432Disassemble the whole @code{main} function. Line 32 is part of
15433@code{main}.
15434
15435@smallexample
15436-data-disassemble -f basics.c -l 32 -- 0
15437^done,asm_insns=[
15438@{address="0x000107bc",func-name="main",offset="0",
15439inst="save %sp, -112, %sp"@},
15440@{address="0x000107c0",func-name="main",offset="4",
15441inst="mov 2, %o0"@},
15442@{address="0x000107c4",func-name="main",offset="8",
15443inst="sethi %hi(0x11800), %o2"@},
15444[@dots{}]
15445@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
15446@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
15447(@value{GDBP})
15448@end smallexample
15449
15450Disassemble 3 instructions from the start of @code{main}:
15451
15452@smallexample
15453(@value{GDBP})
15454-data-disassemble -f basics.c -l 32 -n 3 -- 0
15455^done,asm_insns=[
15456@{address="0x000107bc",func-name="main",offset="0",
15457inst="save %sp, -112, %sp"@},
15458@{address="0x000107c0",func-name="main",offset="4",
15459inst="mov 2, %o0"@},
15460@{address="0x000107c4",func-name="main",offset="8",
15461inst="sethi %hi(0x11800), %o2"@}]
15462(@value{GDBP})
15463@end smallexample
15464
15465Disassemble 3 instructions from the start of @code{main} in mixed mode:
15466
15467@smallexample
15468(@value{GDBP})
15469-data-disassemble -f basics.c -l 32 -n 3 -- 1
15470^done,asm_insns=[
15471src_and_asm_line=@{line="31",
15472file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
15473 testsuite/gdb.mi/basics.c",line_asm_insn=[
15474@{address="0x000107bc",func-name="main",offset="0",
15475inst="save %sp, -112, %sp"@}]@},
15476src_and_asm_line=@{line="32",
15477file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
15478 testsuite/gdb.mi/basics.c",line_asm_insn=[
15479@{address="0x000107c0",func-name="main",offset="4",
15480inst="mov 2, %o0"@},
15481@{address="0x000107c4",func-name="main",offset="8",
15482inst="sethi %hi(0x11800), %o2"@}]@}]
15483(@value{GDBP})
15484@end smallexample
15485
15486
15487@subheading The @code{-data-evaluate-expression} Command
15488@findex -data-evaluate-expression
15489
15490@subsubheading Synopsis
15491
15492@smallexample
15493 -data-evaluate-expression @var{expr}
15494@end smallexample
15495
15496Evaluate @var{expr} as an expression. The expression could contain an
15497inferior function call. The function call will execute synchronously.
15498If the expression contains spaces, it must be enclosed in double quotes.
15499
15500@subsubheading @value{GDBN} Command
15501
15502The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
15503@samp{call}. In @code{gdbtk} only, there's a corresponding
15504@samp{gdb_eval} command.
15505
15506@subsubheading Example
15507
15508In the following example, the numbers that precede the commands are the
15509@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
15510Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
15511output.
15512
15513@smallexample
15514211-data-evaluate-expression A
15515211^done,value="1"
15516(@value{GDBP})
15517311-data-evaluate-expression &A
15518311^done,value="0xefffeb7c"
15519(@value{GDBP})
15520411-data-evaluate-expression A+3
15521411^done,value="4"
15522(@value{GDBP})
15523511-data-evaluate-expression "A + 3"
15524511^done,value="4"
15525(@value{GDBP})
15526@end smallexample
15527
15528
15529@subheading The @code{-data-list-changed-registers} Command
15530@findex -data-list-changed-registers
15531
15532@subsubheading Synopsis
15533
15534@smallexample
15535 -data-list-changed-registers
15536@end smallexample
15537
15538Display a list of the registers that have changed.
15539
15540@subsubheading @value{GDBN} Command
15541
15542@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
15543has the corresponding command @samp{gdb_changed_register_list}.
15544
15545@subsubheading Example
15546
15547On a PPC MBX board:
15548
15549@smallexample
15550(@value{GDBP})
15551-exec-continue
15552^running
15553
15554(@value{GDBP})
15555*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
15556args=[],file="try.c",line="5"@}
15557(@value{GDBP})
15558-data-list-changed-registers
15559^done,changed-registers=["0","1","2","4","5","6","7","8","9",
15560"10","11","13","14","15","16","17","18","19","20","21","22","23",
15561"24","25","26","27","28","30","31","64","65","66","67","69"]
15562(@value{GDBP})
15563@end smallexample
15564
15565
15566@subheading The @code{-data-list-register-names} Command
15567@findex -data-list-register-names
15568
15569@subsubheading Synopsis
15570
15571@smallexample
15572 -data-list-register-names [ ( @var{regno} )+ ]
15573@end smallexample
15574
15575Show a list of register names for the current target. If no arguments
15576are given, it shows a list of the names of all the registers. If
15577integer numbers are given as arguments, it will print a list of the
15578names of the registers corresponding to the arguments. To ensure
15579consistency between a register name and its number, the output list may
15580include empty register names.
15581
15582@subsubheading @value{GDBN} Command
15583
15584@value{GDBN} does not have a command which corresponds to
15585@samp{-data-list-register-names}. In @code{gdbtk} there is a
15586corresponding command @samp{gdb_regnames}.
15587
15588@subsubheading Example
15589
15590For the PPC MBX board:
15591@smallexample
15592(@value{GDBP})
15593-data-list-register-names
15594^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
15595"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
15596"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
15597"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
15598"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
15599"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
15600"", "pc","ps","cr","lr","ctr","xer"]
15601(@value{GDBP})
15602-data-list-register-names 1 2 3
15603^done,register-names=["r1","r2","r3"]
15604(@value{GDBP})
15605@end smallexample
15606
15607@subheading The @code{-data-list-register-values} Command
15608@findex -data-list-register-values
15609
15610@subsubheading Synopsis
15611
15612@smallexample
15613 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
15614@end smallexample
15615
15616Display the registers' contents. @var{fmt} is the format according to
15617which the registers' contents are to be returned, followed by an optional
15618list of numbers specifying the registers to display. A missing list of
15619numbers indicates that the contents of all the registers must be returned.
15620
15621Allowed formats for @var{fmt} are:
15622
15623@table @code
15624@item x
15625Hexadecimal
15626@item o
15627Octal
15628@item t
15629Binary
15630@item d
15631Decimal
15632@item r
15633Raw
15634@item N
15635Natural
15636@end table
15637
15638@subsubheading @value{GDBN} Command
15639
15640The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
15641all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
15642
15643@subsubheading Example
15644
15645For a PPC MBX board (note: line breaks are for readability only, they
15646don't appear in the actual output):
15647
15648@smallexample
15649(@value{GDBP})
15650-data-list-register-values r 64 65
15651^done,register-values=[@{number="64",value="0xfe00a300"@},
15652@{number="65",value="0x00029002"@}]
15653(@value{GDBP})
15654-data-list-register-values x
15655^done,register-values=[@{number="0",value="0xfe0043c8"@},
15656@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
15657@{number="3",value="0x0"@},@{number="4",value="0xa"@},
15658@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
15659@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
15660@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
15661@{number="11",value="0x1"@},@{number="12",value="0x0"@},
15662@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
15663@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
15664@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
15665@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
15666@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
15667@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
15668@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
15669@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
15670@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
15671@{number="31",value="0x0"@},@{number="32",value="0x0"@},
15672@{number="33",value="0x0"@},@{number="34",value="0x0"@},
15673@{number="35",value="0x0"@},@{number="36",value="0x0"@},
15674@{number="37",value="0x0"@},@{number="38",value="0x0"@},
15675@{number="39",value="0x0"@},@{number="40",value="0x0"@},
15676@{number="41",value="0x0"@},@{number="42",value="0x0"@},
15677@{number="43",value="0x0"@},@{number="44",value="0x0"@},
15678@{number="45",value="0x0"@},@{number="46",value="0x0"@},
15679@{number="47",value="0x0"@},@{number="48",value="0x0"@},
15680@{number="49",value="0x0"@},@{number="50",value="0x0"@},
15681@{number="51",value="0x0"@},@{number="52",value="0x0"@},
15682@{number="53",value="0x0"@},@{number="54",value="0x0"@},
15683@{number="55",value="0x0"@},@{number="56",value="0x0"@},
15684@{number="57",value="0x0"@},@{number="58",value="0x0"@},
15685@{number="59",value="0x0"@},@{number="60",value="0x0"@},
15686@{number="61",value="0x0"@},@{number="62",value="0x0"@},
15687@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
15688@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
15689@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
15690@{number="69",value="0x20002b03"@}]
15691(@value{GDBP})
15692@end smallexample
15693
15694
15695@subheading The @code{-data-read-memory} Command
15696@findex -data-read-memory
15697
15698@subsubheading Synopsis
15699
15700@smallexample
15701 -data-read-memory [ -o @var{byte-offset} ]
15702 @var{address} @var{word-format} @var{word-size}
15703 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
15704@end smallexample
15705
15706@noindent
15707where:
15708
15709@table @samp
15710@item @var{address}
15711An expression specifying the address of the first memory word to be
15712read. Complex expressions containing embedded white space should be
15713quoted using the C convention.
15714
15715@item @var{word-format}
15716The format to be used to print the memory words. The notation is the
15717same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
15718,Output formats}).
15719
15720@item @var{word-size}
15721The size of each memory word in bytes.
15722
15723@item @var{nr-rows}
15724The number of rows in the output table.
15725
15726@item @var{nr-cols}
15727The number of columns in the output table.
15728
15729@item @var{aschar}
15730If present, indicates that each row should include an @sc{ascii} dump. The
15731value of @var{aschar} is used as a padding character when a byte is not a
15732member of the printable @sc{ascii} character set (printable @sc{ascii}
15733characters are those whose code is between 32 and 126, inclusively).
15734
15735@item @var{byte-offset}
15736An offset to add to the @var{address} before fetching memory.
15737@end table
15738
15739This command displays memory contents as a table of @var{nr-rows} by
15740@var{nr-cols} words, each word being @var{word-size} bytes. In total,
15741@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
15742(returned as @samp{total-bytes}). Should less than the requested number
15743of bytes be returned by the target, the missing words are identified
15744using @samp{N/A}. The number of bytes read from the target is returned
15745in @samp{nr-bytes} and the starting address used to read memory in
15746@samp{addr}.
15747
15748The address of the next/previous row or page is available in
15749@samp{next-row} and @samp{prev-row}, @samp{next-page} and
15750@samp{prev-page}.
15751
15752@subsubheading @value{GDBN} Command
15753
15754The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
15755@samp{gdb_get_mem} memory read command.
15756
15757@subsubheading Example
15758
15759Read six bytes of memory starting at @code{bytes+6} but then offset by
15760@code{-6} bytes. Format as three rows of two columns. One byte per
15761word. Display each word in hex.
15762
15763@smallexample
15764(@value{GDBP})
157659-data-read-memory -o -6 -- bytes+6 x 1 3 2
157669^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
15767next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
15768prev-page="0x0000138a",memory=[
15769@{addr="0x00001390",data=["0x00","0x01"]@},
15770@{addr="0x00001392",data=["0x02","0x03"]@},
15771@{addr="0x00001394",data=["0x04","0x05"]@}]
15772(@value{GDBP})
15773@end smallexample
15774
15775Read two bytes of memory starting at address @code{shorts + 64} and
15776display as a single word formatted in decimal.
15777
15778@smallexample
15779(@value{GDBP})
157805-data-read-memory shorts+64 d 2 1 1
157815^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
15782next-row="0x00001512",prev-row="0x0000150e",
15783next-page="0x00001512",prev-page="0x0000150e",memory=[
15784@{addr="0x00001510",data=["128"]@}]
15785(@value{GDBP})
15786@end smallexample
15787
15788Read thirty two bytes of memory starting at @code{bytes+16} and format
15789as eight rows of four columns. Include a string encoding with @samp{x}
15790used as the non-printable character.
15791
15792@smallexample
15793(@value{GDBP})
157944-data-read-memory bytes+16 x 1 8 4 x
157954^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
15796next-row="0x000013c0",prev-row="0x0000139c",
15797next-page="0x000013c0",prev-page="0x00001380",memory=[
15798@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
15799@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
15800@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
15801@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
15802@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
15803@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
15804@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
15805@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
15806(@value{GDBP})
15807@end smallexample
15808
15809@subheading The @code{-display-delete} Command
15810@findex -display-delete
15811
15812@subsubheading Synopsis
15813
15814@smallexample
15815 -display-delete @var{number}
15816@end smallexample
15817
15818Delete the display @var{number}.
15819
15820@subsubheading @value{GDBN} Command
15821
15822The corresponding @value{GDBN} command is @samp{delete display}.
15823
15824@subsubheading Example
15825N.A.
15826
15827
15828@subheading The @code{-display-disable} Command
15829@findex -display-disable
15830
15831@subsubheading Synopsis
15832
15833@smallexample
15834 -display-disable @var{number}
15835@end smallexample
15836
15837Disable display @var{number}.
15838
15839@subsubheading @value{GDBN} Command
15840
15841The corresponding @value{GDBN} command is @samp{disable display}.
15842
15843@subsubheading Example
15844N.A.
15845
15846
15847@subheading The @code{-display-enable} Command
15848@findex -display-enable
15849
15850@subsubheading Synopsis
15851
15852@smallexample
15853 -display-enable @var{number}
15854@end smallexample
15855
15856Enable display @var{number}.
15857
15858@subsubheading @value{GDBN} Command
15859
15860The corresponding @value{GDBN} command is @samp{enable display}.
15861
15862@subsubheading Example
15863N.A.
15864
15865
15866@subheading The @code{-display-insert} Command
15867@findex -display-insert
15868
15869@subsubheading Synopsis
15870
15871@smallexample
15872 -display-insert @var{expression}
15873@end smallexample
15874
15875Display @var{expression} every time the program stops.
15876
15877@subsubheading @value{GDBN} Command
15878
15879The corresponding @value{GDBN} command is @samp{display}.
15880
15881@subsubheading Example
15882N.A.
15883
15884
15885@subheading The @code{-display-list} Command
15886@findex -display-list
15887
15888@subsubheading Synopsis
15889
15890@smallexample
15891 -display-list
15892@end smallexample
15893
15894List the displays. Do not show the current values.
15895
15896@subsubheading @value{GDBN} Command
15897
15898The corresponding @value{GDBN} command is @samp{info display}.
15899
15900@subsubheading Example
15901N.A.
15902
15903
15904@subheading The @code{-environment-cd} Command
15905@findex -environment-cd
15906
15907@subsubheading Synopsis
15908
15909@smallexample
15910 -environment-cd @var{pathdir}
15911@end smallexample
15912
15913Set @value{GDBN}'s working directory.
15914
15915@subsubheading @value{GDBN} Command
15916
15917The corresponding @value{GDBN} command is @samp{cd}.
15918
15919@subsubheading Example
15920
15921@smallexample
15922(@value{GDBP})
15923-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
15924^done
15925(@value{GDBP})
15926@end smallexample
15927
15928
15929@subheading The @code{-environment-directory} Command
15930@findex -environment-directory
15931
15932@subsubheading Synopsis
15933
15934@smallexample
15935 -environment-directory [ -r ] [ @var{pathdir} ]+
15936@end smallexample
15937
15938Add directories @var{pathdir} to beginning of search path for source files.
15939If the @samp{-r} option is used, the search path is reset to the default
15940search path. If directories @var{pathdir} are supplied in addition to the
15941@samp{-r} option, the search path is first reset and then addition
15942occurs as normal.
15943Multiple directories may be specified, separated by blanks. Specifying
15944multiple directories in a single command
15945results in the directories added to the beginning of the
15946search path in the same order they were presented in the command.
15947If blanks are needed as
15948part of a directory name, double-quotes should be used around
15949the name. In the command output, the path will show up separated
15950by the system directory-separator character. The directory-seperator
15951character must not be used
15952in any directory name.
15953If no directories are specified, the current search path is displayed.
15954
15955@subsubheading @value{GDBN} Command
15956
15957The corresponding @value{GDBN} command is @samp{dir}.
15958
15959@subsubheading Example
15960
15961@smallexample
15962(@value{GDBP})
15963-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
15964^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
15965(@value{GDBP})
15966-environment-directory ""
15967^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
15968(@value{GDBP})
15969-environment-directory -r /home/jjohnstn/src/gdb /usr/src
15970^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
15971(@value{GDBP})
15972-environment-directory -r
15973^done,source-path="$cdir:$cwd"
15974(@value{GDBP})
15975@end smallexample
15976
15977
15978@subheading The @code{-environment-path} Command
15979@findex -environment-path
15980
15981@subsubheading Synopsis
15982
15983@smallexample
15984 -environment-path [ -r ] [ @var{pathdir} ]+
15985@end smallexample
15986
15987Add directories @var{pathdir} to beginning of search path for object files.
15988If the @samp{-r} option is used, the search path is reset to the original
15989search path that existed at gdb start-up. If directories @var{pathdir} are
15990supplied in addition to the
15991@samp{-r} option, the search path is first reset and then addition
15992occurs as normal.
15993Multiple directories may be specified, separated by blanks. Specifying
15994multiple directories in a single command
15995results in the directories added to the beginning of the
15996search path in the same order they were presented in the command.
15997If blanks are needed as
15998part of a directory name, double-quotes should be used around
15999the name. In the command output, the path will show up separated
16000by the system directory-separator character. The directory-seperator
16001character must not be used
16002in any directory name.
16003If no directories are specified, the current path is displayed.
16004
16005
16006@subsubheading @value{GDBN} Command
16007
16008The corresponding @value{GDBN} command is @samp{path}.
16009
16010@subsubheading Example
16011
16012@smallexample
16013(@value{GDBP})
16014-environment-path
16015^done,path="/usr/bin"
16016(@value{GDBP})
16017-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
16018^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
16019(@value{GDBP})
16020-environment-path -r /usr/local/bin
16021^done,path="/usr/local/bin:/usr/bin"
16022(@value{GDBP})
16023@end smallexample
16024
16025
16026@subheading The @code{-environment-pwd} Command
16027@findex -environment-pwd
16028
16029@subsubheading Synopsis
16030
16031@smallexample
16032 -environment-pwd
16033@end smallexample
16034
16035Show the current working directory.
16036
16037@subsubheading @value{GDBN} command
16038
16039The corresponding @value{GDBN} command is @samp{pwd}.
16040
16041@subsubheading Example
16042
16043@smallexample
16044(@value{GDBP})
16045-environment-pwd
16046^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
16047(@value{GDBP})
16048@end smallexample
16049
16050@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16051@node GDB/MI Program Control
16052@section @sc{gdb/mi} Program control
16053
16054@subsubheading Program termination
16055
16056As a result of execution, the inferior program can run to completion, if
16057it doesn't encounter any breakpoints. In this case the output will
16058include an exit code, if the program has exited exceptionally.
16059
16060@subsubheading Examples
16061
16062@noindent
16063Program exited normally:
16064
16065@smallexample
16066(@value{GDBP})
16067-exec-run
16068^running
16069(@value{GDBP})
16070x = 55
16071*stopped,reason="exited-normally"
16072(@value{GDBP})
16073@end smallexample
16074
16075@noindent
16076Program exited exceptionally:
16077
16078@smallexample
16079(@value{GDBP})
16080-exec-run
16081^running
16082(@value{GDBP})
16083x = 55
16084*stopped,reason="exited",exit-code="01"
16085(@value{GDBP})
16086@end smallexample
16087
16088Another way the program can terminate is if it receives a signal such as
16089@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
16090
16091@smallexample
16092(@value{GDBP})
16093*stopped,reason="exited-signalled",signal-name="SIGINT",
16094signal-meaning="Interrupt"
16095@end smallexample
16096
16097
16098@subheading The @code{-exec-abort} Command
16099@findex -exec-abort
16100
16101@subsubheading Synopsis
16102
16103@smallexample
16104 -exec-abort
16105@end smallexample
16106
16107Kill the inferior running program.
16108
16109@subsubheading @value{GDBN} Command
16110
16111The corresponding @value{GDBN} command is @samp{kill}.
16112
16113@subsubheading Example
16114N.A.
16115
16116
16117@subheading The @code{-exec-arguments} Command
16118@findex -exec-arguments
16119
16120@subsubheading Synopsis
16121
16122@smallexample
16123 -exec-arguments @var{args}
16124@end smallexample
16125
16126Set the inferior program arguments, to be used in the next
16127@samp{-exec-run}.
16128
16129@subsubheading @value{GDBN} Command
16130
16131The corresponding @value{GDBN} command is @samp{set args}.
16132
16133@subsubheading Example
16134
16135@c FIXME!
16136Don't have one around.
16137
16138
16139@subheading The @code{-exec-continue} Command
16140@findex -exec-continue
16141
16142@subsubheading Synopsis
16143
16144@smallexample
16145 -exec-continue
16146@end smallexample
16147
16148Asynchronous command. Resumes the execution of the inferior program
16149until a breakpoint is encountered, or until the inferior exits.
16150
16151@subsubheading @value{GDBN} Command
16152
16153The corresponding @value{GDBN} corresponding is @samp{continue}.
16154
16155@subsubheading Example
16156
16157@smallexample
16158-exec-continue
16159^running
16160(@value{GDBP})
16161@@Hello world
16162*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
16163file="hello.c",line="13"@}
16164(@value{GDBP})
16165@end smallexample
16166
16167
16168@subheading The @code{-exec-finish} Command
16169@findex -exec-finish
16170
16171@subsubheading Synopsis
16172
16173@smallexample
16174 -exec-finish
16175@end smallexample
16176
16177Asynchronous command. Resumes the execution of the inferior program
16178until the current function is exited. Displays the results returned by
16179the function.
16180
16181@subsubheading @value{GDBN} Command
16182
16183The corresponding @value{GDBN} command is @samp{finish}.
16184
16185@subsubheading Example
16186
16187Function returning @code{void}.
16188
16189@smallexample
16190-exec-finish
16191^running
16192(@value{GDBP})
16193@@hello from foo
16194*stopped,reason="function-finished",frame=@{func="main",args=[],
16195file="hello.c",line="7"@}
16196(@value{GDBP})
16197@end smallexample
16198
16199Function returning other than @code{void}. The name of the internal
16200@value{GDBN} variable storing the result is printed, together with the
16201value itself.
16202
16203@smallexample
16204-exec-finish
16205^running
16206(@value{GDBP})
16207*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
16208args=[@{name="a",value="1"],@{name="b",value="9"@}@},
16209file="recursive2.c",line="14"@},
16210gdb-result-var="$1",return-value="0"
16211(@value{GDBP})
16212@end smallexample
16213
16214
16215@subheading The @code{-exec-interrupt} Command
16216@findex -exec-interrupt
16217
16218@subsubheading Synopsis
16219
16220@smallexample
16221 -exec-interrupt
16222@end smallexample
16223
16224Asynchronous command. Interrupts the background execution of the target.
16225Note how the token associated with the stop message is the one for the
16226execution command that has been interrupted. The token for the interrupt
16227itself only appears in the @samp{^done} output. If the user is trying to
16228interrupt a non-running program, an error message will be printed.
16229
16230@subsubheading @value{GDBN} Command
16231
16232The corresponding @value{GDBN} command is @samp{interrupt}.
16233
16234@subsubheading Example
16235
16236@smallexample
16237(@value{GDBP})
16238111-exec-continue
16239111^running
16240
16241(@value{GDBP})
16242222-exec-interrupt
16243222^done
16244(@value{GDBP})
16245111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
16246frame=@{addr="0x00010140",func="foo",args=[],file="try.c",line="13"@}
16247(@value{GDBP})
16248
16249(@value{GDBP})
16250-exec-interrupt
16251^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
16252(@value{GDBP})
16253@end smallexample
16254
16255
16256@subheading The @code{-exec-next} Command
16257@findex -exec-next
16258
16259@subsubheading Synopsis
16260
16261@smallexample
16262 -exec-next
16263@end smallexample
16264
16265Asynchronous command. Resumes execution of the inferior program, stopping
16266when the beginning of the next source line is reached.
16267
16268@subsubheading @value{GDBN} Command
16269
16270The corresponding @value{GDBN} command is @samp{next}.
16271
16272@subsubheading Example
16273
16274@smallexample
16275-exec-next
16276^running
16277(@value{GDBP})
16278*stopped,reason="end-stepping-range",line="8",file="hello.c"
16279(@value{GDBP})
16280@end smallexample
16281
16282
16283@subheading The @code{-exec-next-instruction} Command
16284@findex -exec-next-instruction
16285
16286@subsubheading Synopsis
16287
16288@smallexample
16289 -exec-next-instruction
16290@end smallexample
16291
16292Asynchronous command. Executes one machine instruction. If the
16293instruction is a function call continues until the function returns. If
16294the program stops at an instruction in the middle of a source line, the
16295address will be printed as well.
16296
16297@subsubheading @value{GDBN} Command
16298
16299The corresponding @value{GDBN} command is @samp{nexti}.
16300
16301@subsubheading Example
16302
16303@smallexample
16304(@value{GDBP})
16305-exec-next-instruction
16306^running
16307
16308(@value{GDBP})
16309*stopped,reason="end-stepping-range",
16310addr="0x000100d4",line="5",file="hello.c"
16311(@value{GDBP})
16312@end smallexample
16313
16314
16315@subheading The @code{-exec-return} Command
16316@findex -exec-return
16317
16318@subsubheading Synopsis
16319
16320@smallexample
16321 -exec-return
16322@end smallexample
16323
16324Makes current function return immediately. Doesn't execute the inferior.
16325Displays the new current frame.
16326
16327@subsubheading @value{GDBN} Command
16328
16329The corresponding @value{GDBN} command is @samp{return}.
16330
16331@subsubheading Example
16332
16333@smallexample
16334(@value{GDBP})
16335200-break-insert callee4
16336200^done,bkpt=@{number="1",addr="0x00010734",
16337file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
16338(@value{GDBP})
16339000-exec-run
16340000^running
16341(@value{GDBP})
16342000*stopped,reason="breakpoint-hit",bkptno="1",
16343frame=@{func="callee4",args=[],
16344file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
16345(@value{GDBP})
16346205-break-delete
16347205^done
16348(@value{GDBP})
16349111-exec-return
16350111^done,frame=@{level="0",func="callee3",
16351args=[@{name="strarg",
16352value="0x11940 \"A string argument.\""@}],
16353file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
16354(@value{GDBP})
16355@end smallexample
16356
16357
16358@subheading The @code{-exec-run} Command
16359@findex -exec-run
16360
16361@subsubheading Synopsis
16362
16363@smallexample
16364 -exec-run
16365@end smallexample
16366
16367Asynchronous command. Starts execution of the inferior from the
16368beginning. The inferior executes until either a breakpoint is
16369encountered or the program exits.
16370
16371@subsubheading @value{GDBN} Command
16372
16373The corresponding @value{GDBN} command is @samp{run}.
16374
16375@subsubheading Example
16376
16377@smallexample
16378(@value{GDBP})
16379-break-insert main
16380^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
16381(@value{GDBP})
16382-exec-run
16383^running
16384(@value{GDBP})
16385*stopped,reason="breakpoint-hit",bkptno="1",
16386frame=@{func="main",args=[],file="recursive2.c",line="4"@}
16387(@value{GDBP})
16388@end smallexample
16389
16390
16391@subheading The @code{-exec-show-arguments} Command
16392@findex -exec-show-arguments
16393
16394@subsubheading Synopsis
16395
16396@smallexample
16397 -exec-show-arguments
16398@end smallexample
16399
16400Print the arguments of the program.
16401
16402@subsubheading @value{GDBN} Command
16403
16404The corresponding @value{GDBN} command is @samp{show args}.
16405
16406@subsubheading Example
16407N.A.
16408
16409@c @subheading -exec-signal
16410
16411@subheading The @code{-exec-step} Command
16412@findex -exec-step
16413
16414@subsubheading Synopsis
16415
16416@smallexample
16417 -exec-step
16418@end smallexample
16419
16420Asynchronous command. Resumes execution of the inferior program, stopping
16421when the beginning of the next source line is reached, if the next
16422source line is not a function call. If it is, stop at the first
16423instruction of the called function.
16424
16425@subsubheading @value{GDBN} Command
16426
16427The corresponding @value{GDBN} command is @samp{step}.
16428
16429@subsubheading Example
16430
16431Stepping into a function:
16432
16433@smallexample
16434-exec-step
16435^running
16436(@value{GDBP})
16437*stopped,reason="end-stepping-range",
16438frame=@{func="foo",args=[@{name="a",value="10"@},
16439@{name="b",value="0"@}],file="recursive2.c",line="11"@}
16440(@value{GDBP})
16441@end smallexample
16442
16443Regular stepping:
16444
16445@smallexample
16446-exec-step
16447^running
16448(@value{GDBP})
16449*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
16450(@value{GDBP})
16451@end smallexample
16452
16453
16454@subheading The @code{-exec-step-instruction} Command
16455@findex -exec-step-instruction
16456
16457@subsubheading Synopsis
16458
16459@smallexample
16460 -exec-step-instruction
16461@end smallexample
16462
16463Asynchronous command. Resumes the inferior which executes one machine
16464instruction. The output, once @value{GDBN} has stopped, will vary depending on
16465whether we have stopped in the middle of a source line or not. In the
16466former case, the address at which the program stopped will be printed as
16467well.
16468
16469@subsubheading @value{GDBN} Command
16470
16471The corresponding @value{GDBN} command is @samp{stepi}.
16472
16473@subsubheading Example
16474
16475@smallexample
16476(@value{GDBP})
16477-exec-step-instruction
16478^running
16479
16480(@value{GDBP})
16481*stopped,reason="end-stepping-range",
16482frame=@{func="foo",args=[],file="try.c",line="10"@}
16483(@value{GDBP})
16484-exec-step-instruction
16485^running
16486
16487(@value{GDBP})
16488*stopped,reason="end-stepping-range",
16489frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",line="10"@}
16490(@value{GDBP})
16491@end smallexample
16492
16493
16494@subheading The @code{-exec-until} Command
16495@findex -exec-until
16496
16497@subsubheading Synopsis
16498
16499@smallexample
16500 -exec-until [ @var{location} ]
16501@end smallexample
16502
16503Asynchronous command. Executes the inferior until the @var{location}
16504specified in the argument is reached. If there is no argument, the inferior
16505executes until a source line greater than the current one is reached.
16506The reason for stopping in this case will be @samp{location-reached}.
16507
16508@subsubheading @value{GDBN} Command
16509
16510The corresponding @value{GDBN} command is @samp{until}.
16511
16512@subsubheading Example
16513
16514@smallexample
16515(@value{GDBP})
16516-exec-until recursive2.c:6
16517^running
16518(@value{GDBP})
16519x = 55
16520*stopped,reason="location-reached",frame=@{func="main",args=[],
16521file="recursive2.c",line="6"@}
16522(@value{GDBP})
16523@end smallexample
16524
16525@ignore
16526@subheading -file-clear
16527Is this going away????
16528@end ignore
16529
16530
16531@subheading The @code{-file-exec-and-symbols} Command
16532@findex -file-exec-and-symbols
16533
16534@subsubheading Synopsis
16535
16536@smallexample
16537 -file-exec-and-symbols @var{file}
16538@end smallexample
16539
16540Specify the executable file to be debugged. This file is the one from
16541which the symbol table is also read. If no file is specified, the
16542command clears the executable and symbol information. If breakpoints
16543are set when using this command with no arguments, @value{GDBN} will produce
16544error messages. Otherwise, no output is produced, except a completion
16545notification.
16546
16547@subsubheading @value{GDBN} Command
16548
16549The corresponding @value{GDBN} command is @samp{file}.
16550
16551@subsubheading Example
16552
16553@smallexample
16554(@value{GDBP})
16555-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
16556^done
16557(@value{GDBP})
16558@end smallexample
16559
16560
16561@subheading The @code{-file-exec-file} Command
16562@findex -file-exec-file
16563
16564@subsubheading Synopsis
16565
16566@smallexample
16567 -file-exec-file @var{file}
16568@end smallexample
16569
16570Specify the executable file to be debugged. Unlike
16571@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
16572from this file. If used without argument, @value{GDBN} clears the information
16573about the executable file. No output is produced, except a completion
16574notification.
16575
16576@subsubheading @value{GDBN} Command
16577
16578The corresponding @value{GDBN} command is @samp{exec-file}.
16579
16580@subsubheading Example
16581
16582@smallexample
16583(@value{GDBP})
16584-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
16585^done
16586(@value{GDBP})
16587@end smallexample
16588
16589
16590@subheading The @code{-file-list-exec-sections} Command
16591@findex -file-list-exec-sections
16592
16593@subsubheading Synopsis
16594
16595@smallexample
16596 -file-list-exec-sections
16597@end smallexample
16598
16599List the sections of the current executable file.
16600
16601@subsubheading @value{GDBN} Command
16602
16603The @value{GDBN} command @samp{info file} shows, among the rest, the same
16604information as this command. @code{gdbtk} has a corresponding command
16605@samp{gdb_load_info}.
16606
16607@subsubheading Example
16608N.A.
16609
16610
1abaf70c
BR
16611@subheading The @code{-file-list-exec-source-file} Command
16612@findex -file-list-exec-source-file
16613
16614@subsubheading Synopsis
16615
16616@smallexample
16617 -file-list-exec-source-file
16618@end smallexample
16619
16620List the line number, the current source file, and the absolute path
16621to the current source file for the current executable.
16622
16623@subsubheading @value{GDBN} Command
16624
16625There's no @value{GDBN} command which directly corresponds to this one.
16626
16627@subsubheading Example
16628
16629@smallexample
16630(@value{GDBP})
16631123-file-list-exec-source-file
16632123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
16633(@value{GDBP})
16634@end smallexample
16635
16636
922fbb7b
AC
16637@subheading The @code{-file-list-exec-source-files} Command
16638@findex -file-list-exec-source-files
16639
16640@subsubheading Synopsis
16641
16642@smallexample
16643 -file-list-exec-source-files
16644@end smallexample
16645
16646List the source files for the current executable.
16647
16648@subsubheading @value{GDBN} Command
16649
16650There's no @value{GDBN} command which directly corresponds to this one.
16651@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
16652
16653@subsubheading Example
16654N.A.
16655
16656
16657@subheading The @code{-file-list-shared-libraries} Command
16658@findex -file-list-shared-libraries
16659
16660@subsubheading Synopsis
16661
16662@smallexample
16663 -file-list-shared-libraries
16664@end smallexample
16665
16666List the shared libraries in the program.
16667
16668@subsubheading @value{GDBN} Command
16669
16670The corresponding @value{GDBN} command is @samp{info shared}.
16671
16672@subsubheading Example
16673N.A.
16674
16675
16676@subheading The @code{-file-list-symbol-files} Command
16677@findex -file-list-symbol-files
16678
16679@subsubheading Synopsis
16680
16681@smallexample
16682 -file-list-symbol-files
16683@end smallexample
16684
16685List symbol files.
16686
16687@subsubheading @value{GDBN} Command
16688
16689The corresponding @value{GDBN} command is @samp{info file} (part of it).
16690
16691@subsubheading Example
16692N.A.
16693
16694
16695@subheading The @code{-file-symbol-file} Command
16696@findex -file-symbol-file
16697
16698@subsubheading Synopsis
16699
16700@smallexample
16701 -file-symbol-file @var{file}
16702@end smallexample
16703
16704Read symbol table info from the specified @var{file} argument. When
16705used without arguments, clears @value{GDBN}'s symbol table info. No output is
16706produced, except for a completion notification.
16707
16708@subsubheading @value{GDBN} Command
16709
16710The corresponding @value{GDBN} command is @samp{symbol-file}.
16711
16712@subsubheading Example
16713
16714@smallexample
16715(@value{GDBP})
16716-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
16717^done
16718(@value{GDBP})
16719@end smallexample
16720
16721@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16722@node GDB/MI Miscellaneous Commands
16723@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
16724
16725@c @subheading -gdb-complete
16726
16727@subheading The @code{-gdb-exit} Command
16728@findex -gdb-exit
16729
16730@subsubheading Synopsis
16731
16732@smallexample
16733 -gdb-exit
16734@end smallexample
16735
16736Exit @value{GDBN} immediately.
16737
16738@subsubheading @value{GDBN} Command
16739
16740Approximately corresponds to @samp{quit}.
16741
16742@subsubheading Example
16743
16744@smallexample
16745(@value{GDBP})
16746-gdb-exit
16747@end smallexample
16748
16749@subheading The @code{-gdb-set} Command
16750@findex -gdb-set
16751
16752@subsubheading Synopsis
16753
16754@smallexample
16755 -gdb-set
16756@end smallexample
16757
16758Set an internal @value{GDBN} variable.
16759@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
16760
16761@subsubheading @value{GDBN} Command
16762
16763The corresponding @value{GDBN} command is @samp{set}.
16764
16765@subsubheading Example
16766
16767@smallexample
16768(@value{GDBP})
16769-gdb-set $foo=3
16770^done
16771(@value{GDBP})
16772@end smallexample
16773
16774
16775@subheading The @code{-gdb-show} Command
16776@findex -gdb-show
16777
16778@subsubheading Synopsis
16779
16780@smallexample
16781 -gdb-show
16782@end smallexample
16783
16784Show the current value of a @value{GDBN} variable.
16785
16786@subsubheading @value{GDBN} command
16787
16788The corresponding @value{GDBN} command is @samp{show}.
16789
16790@subsubheading Example
16791
16792@smallexample
16793(@value{GDBP})
16794-gdb-show annotate
16795^done,value="0"
16796(@value{GDBP})
16797@end smallexample
16798
16799@c @subheading -gdb-source
16800
16801
16802@subheading The @code{-gdb-version} Command
16803@findex -gdb-version
16804
16805@subsubheading Synopsis
16806
16807@smallexample
16808 -gdb-version
16809@end smallexample
16810
16811Show version information for @value{GDBN}. Used mostly in testing.
16812
16813@subsubheading @value{GDBN} Command
16814
16815There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
16816information when you start an interactive session.
16817
16818@subsubheading Example
16819
16820@c This example modifies the actual output from GDB to avoid overfull
16821@c box in TeX.
16822@smallexample
16823(@value{GDBP})
16824-gdb-version
16825~GNU gdb 5.2.1
16826~Copyright 2000 Free Software Foundation, Inc.
16827~GDB is free software, covered by the GNU General Public License, and
16828~you are welcome to change it and/or distribute copies of it under
16829~ certain conditions.
16830~Type "show copying" to see the conditions.
16831~There is absolutely no warranty for GDB. Type "show warranty" for
16832~ details.
16833~This GDB was configured as
16834 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
16835^done
16836(@value{GDBP})
16837@end smallexample
16838
16839@subheading The @code{-interpreter-exec} Command
16840@findex -interpreter-exec
16841
16842@subheading Synopsis
16843
16844@smallexample
16845-interpreter-exec @var{interpreter} @var{command}
16846@end smallexample
16847
16848Execute the specified @var{command} in the given @var{interpreter}.
16849
16850@subheading @value{GDBN} Command
16851
16852The corresponding @value{GDBN} command is @samp{interpreter-exec}.
16853
16854@subheading Example
16855
16856@smallexample
16857(@value{GDBP})
16858-interpreter-exec console "break main"
16859&"During symbol reading, couldn't parse type; debugger out of date?.\n"
16860&"During symbol reading, bad structure-type format.\n"
16861~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
16862^done
16863(@value{GDBP})
16864@end smallexample
16865
16866@ignore
16867@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16868@node GDB/MI Kod Commands
16869@section @sc{gdb/mi} Kod Commands
16870
16871The Kod commands are not implemented.
16872
16873@c @subheading -kod-info
16874
16875@c @subheading -kod-list
16876
16877@c @subheading -kod-list-object-types
16878
16879@c @subheading -kod-show
16880
16881@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16882@node GDB/MI Memory Overlay Commands
16883@section @sc{gdb/mi} Memory Overlay Commands
16884
16885The memory overlay commands are not implemented.
16886
16887@c @subheading -overlay-auto
16888
16889@c @subheading -overlay-list-mapping-state
16890
16891@c @subheading -overlay-list-overlays
16892
16893@c @subheading -overlay-map
16894
16895@c @subheading -overlay-off
16896
16897@c @subheading -overlay-on
16898
16899@c @subheading -overlay-unmap
16900
16901@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16902@node GDB/MI Signal Handling Commands
16903@section @sc{gdb/mi} Signal Handling Commands
16904
16905Signal handling commands are not implemented.
16906
16907@c @subheading -signal-handle
16908
16909@c @subheading -signal-list-handle-actions
16910
16911@c @subheading -signal-list-signal-types
16912@end ignore
16913
16914
16915@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16916@node GDB/MI Stack Manipulation
16917@section @sc{gdb/mi} Stack Manipulation Commands
16918
16919
16920@subheading The @code{-stack-info-frame} Command
16921@findex -stack-info-frame
16922
16923@subsubheading Synopsis
16924
16925@smallexample
16926 -stack-info-frame
16927@end smallexample
16928
16929Get info on the current frame.
16930
16931@subsubheading @value{GDBN} Command
16932
16933The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
16934(without arguments).
16935
16936@subsubheading Example
16937N.A.
16938
16939@subheading The @code{-stack-info-depth} Command
16940@findex -stack-info-depth
16941
16942@subsubheading Synopsis
16943
16944@smallexample
16945 -stack-info-depth [ @var{max-depth} ]
16946@end smallexample
16947
16948Return the depth of the stack. If the integer argument @var{max-depth}
16949is specified, do not count beyond @var{max-depth} frames.
16950
16951@subsubheading @value{GDBN} Command
16952
16953There's no equivalent @value{GDBN} command.
16954
16955@subsubheading Example
16956
16957For a stack with frame levels 0 through 11:
16958
16959@smallexample
16960(@value{GDBP})
16961-stack-info-depth
16962^done,depth="12"
16963(@value{GDBP})
16964-stack-info-depth 4
16965^done,depth="4"
16966(@value{GDBP})
16967-stack-info-depth 12
16968^done,depth="12"
16969(@value{GDBP})
16970-stack-info-depth 11
16971^done,depth="11"
16972(@value{GDBP})
16973-stack-info-depth 13
16974^done,depth="12"
16975(@value{GDBP})
16976@end smallexample
16977
16978@subheading The @code{-stack-list-arguments} Command
16979@findex -stack-list-arguments
16980
16981@subsubheading Synopsis
16982
16983@smallexample
16984 -stack-list-arguments @var{show-values}
16985 [ @var{low-frame} @var{high-frame} ]
16986@end smallexample
16987
16988Display a list of the arguments for the frames between @var{low-frame}
16989and @var{high-frame} (inclusive). If @var{low-frame} and
16990@var{high-frame} are not provided, list the arguments for the whole call
16991stack.
16992
16993The @var{show-values} argument must have a value of 0 or 1. A value of
169940 means that only the names of the arguments are listed, a value of 1
16995means that both names and values of the arguments are printed.
16996
16997@subsubheading @value{GDBN} Command
16998
16999@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
17000@samp{gdb_get_args} command which partially overlaps with the
17001functionality of @samp{-stack-list-arguments}.
17002
17003@subsubheading Example
17004
17005@smallexample
17006(@value{GDBP})
17007-stack-list-frames
17008^done,
17009stack=[
17010frame=@{level="0",addr="0x00010734",func="callee4",
17011file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
17012frame=@{level="1",addr="0x0001076c",func="callee3",
17013file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
17014frame=@{level="2",addr="0x0001078c",func="callee2",
17015file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
17016frame=@{level="3",addr="0x000107b4",func="callee1",
17017file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
17018frame=@{level="4",addr="0x000107e0",func="main",
17019file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
17020(@value{GDBP})
17021-stack-list-arguments 0
17022^done,
17023stack-args=[
17024frame=@{level="0",args=[]@},
17025frame=@{level="1",args=[name="strarg"]@},
17026frame=@{level="2",args=[name="intarg",name="strarg"]@},
17027frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
17028frame=@{level="4",args=[]@}]
17029(@value{GDBP})
17030-stack-list-arguments 1
17031^done,
17032stack-args=[
17033frame=@{level="0",args=[]@},
17034frame=@{level="1",
17035 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
17036frame=@{level="2",args=[
17037@{name="intarg",value="2"@},
17038@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
17039@{frame=@{level="3",args=[
17040@{name="intarg",value="2"@},
17041@{name="strarg",value="0x11940 \"A string argument.\""@},
17042@{name="fltarg",value="3.5"@}]@},
17043frame=@{level="4",args=[]@}]
17044(@value{GDBP})
17045-stack-list-arguments 0 2 2
17046^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
17047(@value{GDBP})
17048-stack-list-arguments 1 2 2
17049^done,stack-args=[frame=@{level="2",
17050args=[@{name="intarg",value="2"@},
17051@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
17052(@value{GDBP})
17053@end smallexample
17054
17055@c @subheading -stack-list-exception-handlers
17056
17057
17058@subheading The @code{-stack-list-frames} Command
17059@findex -stack-list-frames
17060
17061@subsubheading Synopsis
17062
17063@smallexample
17064 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
17065@end smallexample
17066
17067List the frames currently on the stack. For each frame it displays the
17068following info:
17069
17070@table @samp
17071@item @var{level}
17072The frame number, 0 being the topmost frame, i.e. the innermost function.
17073@item @var{addr}
17074The @code{$pc} value for that frame.
17075@item @var{func}
17076Function name.
17077@item @var{file}
17078File name of the source file where the function lives.
17079@item @var{line}
17080Line number corresponding to the @code{$pc}.
17081@end table
17082
17083If invoked without arguments, this command prints a backtrace for the
17084whole stack. If given two integer arguments, it shows the frames whose
17085levels are between the two arguments (inclusive). If the two arguments
17086are equal, it shows the single frame at the corresponding level.
17087
17088@subsubheading @value{GDBN} Command
17089
17090The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
17091
17092@subsubheading Example
17093
17094Full stack backtrace:
17095
17096@smallexample
17097(@value{GDBP})
17098-stack-list-frames
17099^done,stack=
17100[frame=@{level="0",addr="0x0001076c",func="foo",
17101 file="recursive2.c",line="11"@},
17102frame=@{level="1",addr="0x000107a4",func="foo",
17103 file="recursive2.c",line="14"@},
17104frame=@{level="2",addr="0x000107a4",func="foo",
17105 file="recursive2.c",line="14"@},
17106frame=@{level="3",addr="0x000107a4",func="foo",
17107 file="recursive2.c",line="14"@},
17108frame=@{level="4",addr="0x000107a4",func="foo",
17109 file="recursive2.c",line="14"@},
17110frame=@{level="5",addr="0x000107a4",func="foo",
17111 file="recursive2.c",line="14"@},
17112frame=@{level="6",addr="0x000107a4",func="foo",
17113 file="recursive2.c",line="14"@},
17114frame=@{level="7",addr="0x000107a4",func="foo",
17115 file="recursive2.c",line="14"@},
17116frame=@{level="8",addr="0x000107a4",func="foo",
17117 file="recursive2.c",line="14"@},
17118frame=@{level="9",addr="0x000107a4",func="foo",
17119 file="recursive2.c",line="14"@},
17120frame=@{level="10",addr="0x000107a4",func="foo",
17121 file="recursive2.c",line="14"@},
17122frame=@{level="11",addr="0x00010738",func="main",
17123 file="recursive2.c",line="4"@}]
17124(@value{GDBP})
17125@end smallexample
17126
17127Show frames between @var{low_frame} and @var{high_frame}:
17128
17129@smallexample
17130(@value{GDBP})
17131-stack-list-frames 3 5
17132^done,stack=
17133[frame=@{level="3",addr="0x000107a4",func="foo",
17134 file="recursive2.c",line="14"@},
17135frame=@{level="4",addr="0x000107a4",func="foo",
17136 file="recursive2.c",line="14"@},
17137frame=@{level="5",addr="0x000107a4",func="foo",
17138 file="recursive2.c",line="14"@}]
17139(@value{GDBP})
17140@end smallexample
17141
17142Show a single frame:
17143
17144@smallexample
17145(@value{GDBP})
17146-stack-list-frames 3 3
17147^done,stack=
17148[frame=@{level="3",addr="0x000107a4",func="foo",
17149 file="recursive2.c",line="14"@}]
17150(@value{GDBP})
17151@end smallexample
17152
17153
17154@subheading The @code{-stack-list-locals} Command
17155@findex -stack-list-locals
17156
17157@subsubheading Synopsis
17158
17159@smallexample
17160 -stack-list-locals @var{print-values}
17161@end smallexample
17162
17163Display the local variable names for the current frame. With an
17164argument of 0 prints only the names of the variables, with argument of 1
17165prints also their values.
17166
17167@subsubheading @value{GDBN} Command
17168
17169@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
17170
17171@subsubheading Example
17172
17173@smallexample
17174(@value{GDBP})
17175-stack-list-locals 0
17176^done,locals=[name="A",name="B",name="C"]
17177(@value{GDBP})
17178-stack-list-locals 1
17179^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
17180 @{name="C",value="3"@}]
17181(@value{GDBP})
17182@end smallexample
17183
17184
17185@subheading The @code{-stack-select-frame} Command
17186@findex -stack-select-frame
17187
17188@subsubheading Synopsis
17189
17190@smallexample
17191 -stack-select-frame @var{framenum}
17192@end smallexample
17193
17194Change the current frame. Select a different frame @var{framenum} on
17195the stack.
17196
17197@subsubheading @value{GDBN} Command
17198
17199The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
17200@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
17201
17202@subsubheading Example
17203
17204@smallexample
17205(@value{GDBP})
17206-stack-select-frame 2
17207^done
17208(@value{GDBP})
17209@end smallexample
17210
17211@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17212@node GDB/MI Symbol Query
17213@section @sc{gdb/mi} Symbol Query Commands
17214
17215
17216@subheading The @code{-symbol-info-address} Command
17217@findex -symbol-info-address
17218
17219@subsubheading Synopsis
17220
17221@smallexample
17222 -symbol-info-address @var{symbol}
17223@end smallexample
17224
17225Describe where @var{symbol} is stored.
17226
17227@subsubheading @value{GDBN} Command
17228
17229The corresponding @value{GDBN} command is @samp{info address}.
17230
17231@subsubheading Example
17232N.A.
17233
17234
17235@subheading The @code{-symbol-info-file} Command
17236@findex -symbol-info-file
17237
17238@subsubheading Synopsis
17239
17240@smallexample
17241 -symbol-info-file
17242@end smallexample
17243
17244Show the file for the symbol.
17245
17246@subsubheading @value{GDBN} Command
17247
17248There's no equivalent @value{GDBN} command. @code{gdbtk} has
17249@samp{gdb_find_file}.
17250
17251@subsubheading Example
17252N.A.
17253
17254
17255@subheading The @code{-symbol-info-function} Command
17256@findex -symbol-info-function
17257
17258@subsubheading Synopsis
17259
17260@smallexample
17261 -symbol-info-function
17262@end smallexample
17263
17264Show which function the symbol lives in.
17265
17266@subsubheading @value{GDBN} Command
17267
17268@samp{gdb_get_function} in @code{gdbtk}.
17269
17270@subsubheading Example
17271N.A.
17272
17273
17274@subheading The @code{-symbol-info-line} Command
17275@findex -symbol-info-line
17276
17277@subsubheading Synopsis
17278
17279@smallexample
17280 -symbol-info-line
17281@end smallexample
17282
17283Show the core addresses of the code for a source line.
17284
17285@subsubheading @value{GDBN} Command
17286
71952f4c 17287The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
17288@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
17289
17290@subsubheading Example
17291N.A.
17292
17293
17294@subheading The @code{-symbol-info-symbol} Command
17295@findex -symbol-info-symbol
17296
17297@subsubheading Synopsis
17298
17299@smallexample
17300 -symbol-info-symbol @var{addr}
17301@end smallexample
17302
17303Describe what symbol is at location @var{addr}.
17304
17305@subsubheading @value{GDBN} Command
17306
17307The corresponding @value{GDBN} command is @samp{info symbol}.
17308
17309@subsubheading Example
17310N.A.
17311
17312
17313@subheading The @code{-symbol-list-functions} Command
17314@findex -symbol-list-functions
17315
17316@subsubheading Synopsis
17317
17318@smallexample
17319 -symbol-list-functions
17320@end smallexample
17321
17322List the functions in the executable.
17323
17324@subsubheading @value{GDBN} Command
17325
17326@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
17327@samp{gdb_search} in @code{gdbtk}.
17328
17329@subsubheading Example
17330N.A.
17331
17332
32e7087d
JB
17333@subheading The @code{-symbol-list-lines} Command
17334@findex -symbol-list-lines
17335
17336@subsubheading Synopsis
17337
17338@smallexample
17339 -symbol-list-lines @var{filename}
17340@end smallexample
17341
17342Print the list of lines that contain code and their associated program
17343addresses for the given source filename. The entries are sorted in
17344ascending PC order.
17345
17346@subsubheading @value{GDBN} Command
17347
17348There is no corresponding @value{GDBN} command.
17349
17350@subsubheading Example
17351@smallexample
17352(@value{GDBP})
17353-symbol-list-lines basics.c
54ff5908 17354^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
17355(@value{GDBP})
17356@end smallexample
17357
17358
922fbb7b
AC
17359@subheading The @code{-symbol-list-types} Command
17360@findex -symbol-list-types
17361
17362@subsubheading Synopsis
17363
17364@smallexample
17365 -symbol-list-types
17366@end smallexample
17367
17368List all the type names.
17369
17370@subsubheading @value{GDBN} Command
17371
17372The corresponding commands are @samp{info types} in @value{GDBN},
17373@samp{gdb_search} in @code{gdbtk}.
17374
17375@subsubheading Example
17376N.A.
17377
17378
17379@subheading The @code{-symbol-list-variables} Command
17380@findex -symbol-list-variables
17381
17382@subsubheading Synopsis
17383
17384@smallexample
17385 -symbol-list-variables
17386@end smallexample
17387
17388List all the global and static variable names.
17389
17390@subsubheading @value{GDBN} Command
17391
17392@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
17393
17394@subsubheading Example
17395N.A.
17396
17397
17398@subheading The @code{-symbol-locate} Command
17399@findex -symbol-locate
17400
17401@subsubheading Synopsis
17402
17403@smallexample
17404 -symbol-locate
17405@end smallexample
17406
17407@subsubheading @value{GDBN} Command
17408
17409@samp{gdb_loc} in @code{gdbtk}.
17410
17411@subsubheading Example
17412N.A.
17413
17414
17415@subheading The @code{-symbol-type} Command
17416@findex -symbol-type
17417
17418@subsubheading Synopsis
17419
17420@smallexample
17421 -symbol-type @var{variable}
17422@end smallexample
17423
17424Show type of @var{variable}.
17425
17426@subsubheading @value{GDBN} Command
17427
17428The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
17429@samp{gdb_obj_variable}.
17430
17431@subsubheading Example
17432N.A.
17433
17434
17435@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17436@node GDB/MI Target Manipulation
17437@section @sc{gdb/mi} Target Manipulation Commands
17438
17439
17440@subheading The @code{-target-attach} Command
17441@findex -target-attach
17442
17443@subsubheading Synopsis
17444
17445@smallexample
17446 -target-attach @var{pid} | @var{file}
17447@end smallexample
17448
17449Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
17450
17451@subsubheading @value{GDBN} command
17452
17453The corresponding @value{GDBN} command is @samp{attach}.
17454
17455@subsubheading Example
17456N.A.
17457
17458
17459@subheading The @code{-target-compare-sections} Command
17460@findex -target-compare-sections
17461
17462@subsubheading Synopsis
17463
17464@smallexample
17465 -target-compare-sections [ @var{section} ]
17466@end smallexample
17467
17468Compare data of section @var{section} on target to the exec file.
17469Without the argument, all sections are compared.
17470
17471@subsubheading @value{GDBN} Command
17472
17473The @value{GDBN} equivalent is @samp{compare-sections}.
17474
17475@subsubheading Example
17476N.A.
17477
17478
17479@subheading The @code{-target-detach} Command
17480@findex -target-detach
17481
17482@subsubheading Synopsis
17483
17484@smallexample
17485 -target-detach
17486@end smallexample
17487
17488Disconnect from the remote target. There's no output.
17489
17490@subsubheading @value{GDBN} command
17491
17492The corresponding @value{GDBN} command is @samp{detach}.
17493
17494@subsubheading Example
17495
17496@smallexample
17497(@value{GDBP})
17498-target-detach
17499^done
17500(@value{GDBP})
17501@end smallexample
17502
17503
07f31aa6
DJ
17504@subheading The @code{-target-disconnect} Command
17505@findex -target-disconnect
17506
17507@subsubheading Synopsis
17508
17509@example
17510 -target-disconnect
17511@end example
17512
17513Disconnect from the remote target. There's no output.
17514
17515@subsubheading @value{GDBN} command
17516
17517The corresponding @value{GDBN} command is @samp{disconnect}.
17518
17519@subsubheading Example
17520
17521@smallexample
17522(@value{GDBP})
17523-target-disconnect
17524^done
17525(@value{GDBP})
17526@end smallexample
17527
17528
922fbb7b
AC
17529@subheading The @code{-target-download} Command
17530@findex -target-download
17531
17532@subsubheading Synopsis
17533
17534@smallexample
17535 -target-download
17536@end smallexample
17537
17538Loads the executable onto the remote target.
17539It prints out an update message every half second, which includes the fields:
17540
17541@table @samp
17542@item section
17543The name of the section.
17544@item section-sent
17545The size of what has been sent so far for that section.
17546@item section-size
17547The size of the section.
17548@item total-sent
17549The total size of what was sent so far (the current and the previous sections).
17550@item total-size
17551The size of the overall executable to download.
17552@end table
17553
17554@noindent
17555Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
17556@sc{gdb/mi} Output Syntax}).
17557
17558In addition, it prints the name and size of the sections, as they are
17559downloaded. These messages include the following fields:
17560
17561@table @samp
17562@item section
17563The name of the section.
17564@item section-size
17565The size of the section.
17566@item total-size
17567The size of the overall executable to download.
17568@end table
17569
17570@noindent
17571At the end, a summary is printed.
17572
17573@subsubheading @value{GDBN} Command
17574
17575The corresponding @value{GDBN} command is @samp{load}.
17576
17577@subsubheading Example
17578
17579Note: each status message appears on a single line. Here the messages
17580have been broken down so that they can fit onto a page.
17581
17582@smallexample
17583(@value{GDBP})
17584-target-download
17585+download,@{section=".text",section-size="6668",total-size="9880"@}
17586+download,@{section=".text",section-sent="512",section-size="6668",
17587total-sent="512",total-size="9880"@}
17588+download,@{section=".text",section-sent="1024",section-size="6668",
17589total-sent="1024",total-size="9880"@}
17590+download,@{section=".text",section-sent="1536",section-size="6668",
17591total-sent="1536",total-size="9880"@}
17592+download,@{section=".text",section-sent="2048",section-size="6668",
17593total-sent="2048",total-size="9880"@}
17594+download,@{section=".text",section-sent="2560",section-size="6668",
17595total-sent="2560",total-size="9880"@}
17596+download,@{section=".text",section-sent="3072",section-size="6668",
17597total-sent="3072",total-size="9880"@}
17598+download,@{section=".text",section-sent="3584",section-size="6668",
17599total-sent="3584",total-size="9880"@}
17600+download,@{section=".text",section-sent="4096",section-size="6668",
17601total-sent="4096",total-size="9880"@}
17602+download,@{section=".text",section-sent="4608",section-size="6668",
17603total-sent="4608",total-size="9880"@}
17604+download,@{section=".text",section-sent="5120",section-size="6668",
17605total-sent="5120",total-size="9880"@}
17606+download,@{section=".text",section-sent="5632",section-size="6668",
17607total-sent="5632",total-size="9880"@}
17608+download,@{section=".text",section-sent="6144",section-size="6668",
17609total-sent="6144",total-size="9880"@}
17610+download,@{section=".text",section-sent="6656",section-size="6668",
17611total-sent="6656",total-size="9880"@}
17612+download,@{section=".init",section-size="28",total-size="9880"@}
17613+download,@{section=".fini",section-size="28",total-size="9880"@}
17614+download,@{section=".data",section-size="3156",total-size="9880"@}
17615+download,@{section=".data",section-sent="512",section-size="3156",
17616total-sent="7236",total-size="9880"@}
17617+download,@{section=".data",section-sent="1024",section-size="3156",
17618total-sent="7748",total-size="9880"@}
17619+download,@{section=".data",section-sent="1536",section-size="3156",
17620total-sent="8260",total-size="9880"@}
17621+download,@{section=".data",section-sent="2048",section-size="3156",
17622total-sent="8772",total-size="9880"@}
17623+download,@{section=".data",section-sent="2560",section-size="3156",
17624total-sent="9284",total-size="9880"@}
17625+download,@{section=".data",section-sent="3072",section-size="3156",
17626total-sent="9796",total-size="9880"@}
17627^done,address="0x10004",load-size="9880",transfer-rate="6586",
17628write-rate="429"
17629(@value{GDBP})
17630@end smallexample
17631
17632
17633@subheading The @code{-target-exec-status} Command
17634@findex -target-exec-status
17635
17636@subsubheading Synopsis
17637
17638@smallexample
17639 -target-exec-status
17640@end smallexample
17641
17642Provide information on the state of the target (whether it is running or
17643not, for instance).
17644
17645@subsubheading @value{GDBN} Command
17646
17647There's no equivalent @value{GDBN} command.
17648
17649@subsubheading Example
17650N.A.
17651
17652
17653@subheading The @code{-target-list-available-targets} Command
17654@findex -target-list-available-targets
17655
17656@subsubheading Synopsis
17657
17658@smallexample
17659 -target-list-available-targets
17660@end smallexample
17661
17662List the possible targets to connect to.
17663
17664@subsubheading @value{GDBN} Command
17665
17666The corresponding @value{GDBN} command is @samp{help target}.
17667
17668@subsubheading Example
17669N.A.
17670
17671
17672@subheading The @code{-target-list-current-targets} Command
17673@findex -target-list-current-targets
17674
17675@subsubheading Synopsis
17676
17677@smallexample
17678 -target-list-current-targets
17679@end smallexample
17680
17681Describe the current target.
17682
17683@subsubheading @value{GDBN} Command
17684
17685The corresponding information is printed by @samp{info file} (among
17686other things).
17687
17688@subsubheading Example
17689N.A.
17690
17691
17692@subheading The @code{-target-list-parameters} Command
17693@findex -target-list-parameters
17694
17695@subsubheading Synopsis
17696
17697@smallexample
17698 -target-list-parameters
17699@end smallexample
17700
17701@c ????
17702
17703@subsubheading @value{GDBN} Command
17704
17705No equivalent.
17706
17707@subsubheading Example
17708N.A.
17709
17710
17711@subheading The @code{-target-select} Command
17712@findex -target-select
17713
17714@subsubheading Synopsis
17715
17716@smallexample
17717 -target-select @var{type} @var{parameters @dots{}}
17718@end smallexample
17719
17720Connect @value{GDBN} to the remote target. This command takes two args:
17721
17722@table @samp
17723@item @var{type}
17724The type of target, for instance @samp{async}, @samp{remote}, etc.
17725@item @var{parameters}
17726Device names, host names and the like. @xref{Target Commands, ,
17727Commands for managing targets}, for more details.
17728@end table
17729
17730The output is a connection notification, followed by the address at
17731which the target program is, in the following form:
17732
17733@smallexample
17734^connected,addr="@var{address}",func="@var{function name}",
17735 args=[@var{arg list}]
17736@end smallexample
17737
17738@subsubheading @value{GDBN} Command
17739
17740The corresponding @value{GDBN} command is @samp{target}.
17741
17742@subsubheading Example
17743
17744@smallexample
17745(@value{GDBP})
17746-target-select async /dev/ttya
17747^connected,addr="0xfe00a300",func="??",args=[]
17748(@value{GDBP})
17749@end smallexample
17750
17751@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17752@node GDB/MI Thread Commands
17753@section @sc{gdb/mi} Thread Commands
17754
17755
17756@subheading The @code{-thread-info} Command
17757@findex -thread-info
17758
17759@subsubheading Synopsis
17760
17761@smallexample
17762 -thread-info
17763@end smallexample
17764
17765@subsubheading @value{GDBN} command
17766
17767No equivalent.
17768
17769@subsubheading Example
17770N.A.
17771
17772
17773@subheading The @code{-thread-list-all-threads} Command
17774@findex -thread-list-all-threads
17775
17776@subsubheading Synopsis
17777
17778@smallexample
17779 -thread-list-all-threads
17780@end smallexample
17781
17782@subsubheading @value{GDBN} Command
17783
17784The equivalent @value{GDBN} command is @samp{info threads}.
17785
17786@subsubheading Example
17787N.A.
17788
17789
17790@subheading The @code{-thread-list-ids} Command
17791@findex -thread-list-ids
17792
17793@subsubheading Synopsis
17794
17795@smallexample
17796 -thread-list-ids
17797@end smallexample
17798
17799Produces a list of the currently known @value{GDBN} thread ids. At the
17800end of the list it also prints the total number of such threads.
17801
17802@subsubheading @value{GDBN} Command
17803
17804Part of @samp{info threads} supplies the same information.
17805
17806@subsubheading Example
17807
17808No threads present, besides the main process:
17809
17810@smallexample
17811(@value{GDBP})
17812-thread-list-ids
17813^done,thread-ids=@{@},number-of-threads="0"
17814(@value{GDBP})
17815@end smallexample
17816
17817
17818Several threads:
17819
17820@smallexample
17821(@value{GDBP})
17822-thread-list-ids
17823^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
17824number-of-threads="3"
17825(@value{GDBP})
17826@end smallexample
17827
17828
17829@subheading The @code{-thread-select} Command
17830@findex -thread-select
17831
17832@subsubheading Synopsis
17833
17834@smallexample
17835 -thread-select @var{threadnum}
17836@end smallexample
17837
17838Make @var{threadnum} the current thread. It prints the number of the new
17839current thread, and the topmost frame for that thread.
17840
17841@subsubheading @value{GDBN} Command
17842
17843The corresponding @value{GDBN} command is @samp{thread}.
17844
17845@subsubheading Example
17846
17847@smallexample
17848(@value{GDBP})
17849-exec-next
17850^running
17851(@value{GDBP})
17852*stopped,reason="end-stepping-range",thread-id="2",line="187",
17853file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
17854(@value{GDBP})
17855-thread-list-ids
17856^done,
17857thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
17858number-of-threads="3"
17859(@value{GDBP})
17860-thread-select 3
17861^done,new-thread-id="3",
17862frame=@{level="0",func="vprintf",
17863args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
17864@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
17865(@value{GDBP})
17866@end smallexample
17867
17868@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17869@node GDB/MI Tracepoint Commands
17870@section @sc{gdb/mi} Tracepoint Commands
17871
17872The tracepoint commands are not yet implemented.
17873
17874@c @subheading -trace-actions
17875
17876@c @subheading -trace-delete
17877
17878@c @subheading -trace-disable
17879
17880@c @subheading -trace-dump
17881
17882@c @subheading -trace-enable
17883
17884@c @subheading -trace-exists
17885
17886@c @subheading -trace-find
17887
17888@c @subheading -trace-frame-number
17889
17890@c @subheading -trace-info
17891
17892@c @subheading -trace-insert
17893
17894@c @subheading -trace-list
17895
17896@c @subheading -trace-pass-count
17897
17898@c @subheading -trace-save
17899
17900@c @subheading -trace-start
17901
17902@c @subheading -trace-stop
17903
17904
17905@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17906@node GDB/MI Variable Objects
17907@section @sc{gdb/mi} Variable Objects
17908
17909
17910@subheading Motivation for Variable Objects in @sc{gdb/mi}
17911
17912For the implementation of a variable debugger window (locals, watched
17913expressions, etc.), we are proposing the adaptation of the existing code
17914used by @code{Insight}.
17915
17916The two main reasons for that are:
17917
17918@enumerate 1
17919@item
17920It has been proven in practice (it is already on its second generation).
17921
17922@item
17923It will shorten development time (needless to say how important it is
17924now).
17925@end enumerate
17926
17927The original interface was designed to be used by Tcl code, so it was
17928slightly changed so it could be used through @sc{gdb/mi}. This section
17929describes the @sc{gdb/mi} operations that will be available and gives some
17930hints about their use.
17931
17932@emph{Note}: In addition to the set of operations described here, we
17933expect the @sc{gui} implementation of a variable window to require, at
17934least, the following operations:
17935
17936@itemize @bullet
17937@item @code{-gdb-show} @code{output-radix}
17938@item @code{-stack-list-arguments}
17939@item @code{-stack-list-locals}
17940@item @code{-stack-select-frame}
17941@end itemize
17942
17943@subheading Introduction to Variable Objects in @sc{gdb/mi}
17944
17945@cindex variable objects in @sc{gdb/mi}
17946The basic idea behind variable objects is the creation of a named object
17947to represent a variable, an expression, a memory location or even a CPU
17948register. For each object created, a set of operations is available for
17949examining or changing its properties.
17950
17951Furthermore, complex data types, such as C structures, are represented
17952in a tree format. For instance, the @code{struct} type variable is the
17953root and the children will represent the struct members. If a child
17954is itself of a complex type, it will also have children of its own.
17955Appropriate language differences are handled for C, C@t{++} and Java.
17956
17957When returning the actual values of the objects, this facility allows
17958for the individual selection of the display format used in the result
17959creation. It can be chosen among: binary, decimal, hexadecimal, octal
17960and natural. Natural refers to a default format automatically
17961chosen based on the variable type (like decimal for an @code{int}, hex
17962for pointers, etc.).
17963
17964The following is the complete set of @sc{gdb/mi} operations defined to
17965access this functionality:
17966
17967@multitable @columnfractions .4 .6
17968@item @strong{Operation}
17969@tab @strong{Description}
17970
17971@item @code{-var-create}
17972@tab create a variable object
17973@item @code{-var-delete}
17974@tab delete the variable object and its children
17975@item @code{-var-set-format}
17976@tab set the display format of this variable
17977@item @code{-var-show-format}
17978@tab show the display format of this variable
17979@item @code{-var-info-num-children}
17980@tab tells how many children this object has
17981@item @code{-var-list-children}
17982@tab return a list of the object's children
17983@item @code{-var-info-type}
17984@tab show the type of this variable object
17985@item @code{-var-info-expression}
17986@tab print what this variable object represents
17987@item @code{-var-show-attributes}
17988@tab is this variable editable? does it exist here?
17989@item @code{-var-evaluate-expression}
17990@tab get the value of this variable
17991@item @code{-var-assign}
17992@tab set the value of this variable
17993@item @code{-var-update}
17994@tab update the variable and its children
17995@end multitable
17996
17997In the next subsection we describe each operation in detail and suggest
17998how it can be used.
17999
18000@subheading Description And Use of Operations on Variable Objects
18001
18002@subheading The @code{-var-create} Command
18003@findex -var-create
18004
18005@subsubheading Synopsis
18006
18007@smallexample
18008 -var-create @{@var{name} | "-"@}
18009 @{@var{frame-addr} | "*"@} @var{expression}
18010@end smallexample
18011
18012This operation creates a variable object, which allows the monitoring of
18013a variable, the result of an expression, a memory cell or a CPU
18014register.
18015
18016The @var{name} parameter is the string by which the object can be
18017referenced. It must be unique. If @samp{-} is specified, the varobj
18018system will generate a string ``varNNNNNN'' automatically. It will be
18019unique provided that one does not specify @var{name} on that format.
18020The command fails if a duplicate name is found.
18021
18022The frame under which the expression should be evaluated can be
18023specified by @var{frame-addr}. A @samp{*} indicates that the current
18024frame should be used.
18025
18026@var{expression} is any expression valid on the current language set (must not
18027begin with a @samp{*}), or one of the following:
18028
18029@itemize @bullet
18030@item
18031@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
18032
18033@item
18034@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
18035
18036@item
18037@samp{$@var{regname}} --- a CPU register name
18038@end itemize
18039
18040@subsubheading Result
18041
18042This operation returns the name, number of children and the type of the
18043object created. Type is returned as a string as the ones generated by
18044the @value{GDBN} CLI:
18045
18046@smallexample
18047 name="@var{name}",numchild="N",type="@var{type}"
18048@end smallexample
18049
18050
18051@subheading The @code{-var-delete} Command
18052@findex -var-delete
18053
18054@subsubheading Synopsis
18055
18056@smallexample
18057 -var-delete @var{name}
18058@end smallexample
18059
18060Deletes a previously created variable object and all of its children.
18061
18062Returns an error if the object @var{name} is not found.
18063
18064
18065@subheading The @code{-var-set-format} Command
18066@findex -var-set-format
18067
18068@subsubheading Synopsis
18069
18070@smallexample
18071 -var-set-format @var{name} @var{format-spec}
18072@end smallexample
18073
18074Sets the output format for the value of the object @var{name} to be
18075@var{format-spec}.
18076
18077The syntax for the @var{format-spec} is as follows:
18078
18079@smallexample
18080 @var{format-spec} @expansion{}
18081 @{binary | decimal | hexadecimal | octal | natural@}
18082@end smallexample
18083
18084
18085@subheading The @code{-var-show-format} Command
18086@findex -var-show-format
18087
18088@subsubheading Synopsis
18089
18090@smallexample
18091 -var-show-format @var{name}
18092@end smallexample
18093
18094Returns the format used to display the value of the object @var{name}.
18095
18096@smallexample
18097 @var{format} @expansion{}
18098 @var{format-spec}
18099@end smallexample
18100
18101
18102@subheading The @code{-var-info-num-children} Command
18103@findex -var-info-num-children
18104
18105@subsubheading Synopsis
18106
18107@smallexample
18108 -var-info-num-children @var{name}
18109@end smallexample
18110
18111Returns the number of children of a variable object @var{name}:
18112
18113@smallexample
18114 numchild=@var{n}
18115@end smallexample
18116
18117
18118@subheading The @code{-var-list-children} Command
18119@findex -var-list-children
18120
18121@subsubheading Synopsis
18122
18123@smallexample
18124 -var-list-children @var{name}
18125@end smallexample
18126
18127Returns a list of the children of the specified variable object:
18128
18129@smallexample
18130 numchild=@var{n},children=[@{name=@var{name},
18131 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
18132@end smallexample
18133
18134
18135@subheading The @code{-var-info-type} Command
18136@findex -var-info-type
18137
18138@subsubheading Synopsis
18139
18140@smallexample
18141 -var-info-type @var{name}
18142@end smallexample
18143
18144Returns the type of the specified variable @var{name}. The type is
18145returned as a string in the same format as it is output by the
18146@value{GDBN} CLI:
18147
18148@smallexample
18149 type=@var{typename}
18150@end smallexample
18151
18152
18153@subheading The @code{-var-info-expression} Command
18154@findex -var-info-expression
18155
18156@subsubheading Synopsis
18157
18158@smallexample
18159 -var-info-expression @var{name}
18160@end smallexample
18161
18162Returns what is represented by the variable object @var{name}:
18163
18164@smallexample
18165 lang=@var{lang-spec},exp=@var{expression}
18166@end smallexample
18167
18168@noindent
18169where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
18170
18171@subheading The @code{-var-show-attributes} Command
18172@findex -var-show-attributes
18173
18174@subsubheading Synopsis
18175
18176@smallexample
18177 -var-show-attributes @var{name}
18178@end smallexample
18179
18180List attributes of the specified variable object @var{name}:
18181
18182@smallexample
18183 status=@var{attr} [ ( ,@var{attr} )* ]
18184@end smallexample
18185
18186@noindent
18187where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
18188
18189@subheading The @code{-var-evaluate-expression} Command
18190@findex -var-evaluate-expression
18191
18192@subsubheading Synopsis
18193
18194@smallexample
18195 -var-evaluate-expression @var{name}
18196@end smallexample
18197
18198Evaluates the expression that is represented by the specified variable
18199object and returns its value as a string in the current format specified
18200for the object:
18201
18202@smallexample
18203 value=@var{value}
18204@end smallexample
18205
18206Note that one must invoke @code{-var-list-children} for a variable
18207before the value of a child variable can be evaluated.
18208
18209@subheading The @code{-var-assign} Command
18210@findex -var-assign
18211
18212@subsubheading Synopsis
18213
18214@smallexample
18215 -var-assign @var{name} @var{expression}
18216@end smallexample
18217
18218Assigns the value of @var{expression} to the variable object specified
18219by @var{name}. The object must be @samp{editable}. If the variable's
18220value is altered by the assign, the variable will show up in any
18221subsequent @code{-var-update} list.
18222
18223@subsubheading Example
18224
18225@smallexample
18226(@value{GDBP})
18227-var-assign var1 3
18228^done,value="3"
18229(@value{GDBP})
18230-var-update *
18231^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
18232(@value{GDBP})
18233@end smallexample
18234
18235@subheading The @code{-var-update} Command
18236@findex -var-update
18237
18238@subsubheading Synopsis
18239
18240@smallexample
18241 -var-update @{@var{name} | "*"@}
18242@end smallexample
18243
18244Update the value of the variable object @var{name} by evaluating its
18245expression after fetching all the new values from memory or registers.
18246A @samp{*} causes all existing variable objects to be updated.
18247
18248
18249@node Annotations
18250@chapter @value{GDBN} Annotations
18251
086432e2
AC
18252This chapter describes annotations in @value{GDBN}. Annotations were
18253designed to interface @value{GDBN} to graphical user interfaces or other
18254similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
18255relatively high level.
18256
086432e2
AC
18257The annotation mechanism has largely been superseeded by @sc{gdb/mi}
18258(@pxref{GDB/MI}).
18259
922fbb7b
AC
18260@ignore
18261This is Edition @value{EDITION}, @value{DATE}.
18262@end ignore
18263
18264@menu
18265* Annotations Overview:: What annotations are; the general syntax.
18266* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
18267* Prompting:: Annotations marking @value{GDBN}'s need for input.
18268* Errors:: Annotations for error messages.
922fbb7b
AC
18269* Invalidation:: Some annotations describe things now invalid.
18270* Annotations for Running::
18271 Whether the program is running, how it stopped, etc.
18272* Source Annotations:: Annotations describing source code.
922fbb7b
AC
18273@end menu
18274
18275@node Annotations Overview
18276@section What is an Annotation?
18277@cindex annotations
18278
922fbb7b
AC
18279Annotations start with a newline character, two @samp{control-z}
18280characters, and the name of the annotation. If there is no additional
18281information associated with this annotation, the name of the annotation
18282is followed immediately by a newline. If there is additional
18283information, the name of the annotation is followed by a space, the
18284additional information, and a newline. The additional information
18285cannot contain newline characters.
18286
18287Any output not beginning with a newline and two @samp{control-z}
18288characters denotes literal output from @value{GDBN}. Currently there is
18289no need for @value{GDBN} to output a newline followed by two
18290@samp{control-z} characters, but if there was such a need, the
18291annotations could be extended with an @samp{escape} annotation which
18292means those three characters as output.
18293
086432e2
AC
18294The annotation @var{level}, which is specified using the
18295@option{--annotate} command line option (@pxref{Mode Options}), controls
18296how much information @value{GDBN} prints together with its prompt,
18297values of expressions, source lines, and other types of output. Level 0
18298is for no anntations, level 1 is for use when @value{GDBN} is run as a
18299subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
18300for programs that control @value{GDBN}, and level 2 annotations have
18301been made obsolete (@pxref{Limitations, , Limitations of the Annotation
18302Interface, annotate, GDB's Obsolete Annotations}). This chapter
18303describes level 3 annotations.
18304
922fbb7b
AC
18305A simple example of starting up @value{GDBN} with annotations is:
18306
18307@smallexample
086432e2
AC
18308$ @kbd{gdb --annotate=3}
18309GNU gdb 6.0
18310Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
18311GDB is free software, covered by the GNU General Public License,
18312and you are welcome to change it and/or distribute copies of it
18313under certain conditions.
18314Type "show copying" to see the conditions.
18315There is absolutely no warranty for GDB. Type "show warranty"
18316for details.
086432e2 18317This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
18318
18319^Z^Zpre-prompt
18320(gdb)
18321^Z^Zprompt
086432e2 18322@kbd{quit}
922fbb7b
AC
18323
18324^Z^Zpost-prompt
18325$
18326@end smallexample
18327
18328Here @samp{quit} is input to @value{GDBN}; the rest is output from
18329@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
18330denotes a @samp{control-z} character) are annotations; the rest is
18331output from @value{GDBN}.
18332
18333@node Server Prefix
18334@section The Server Prefix
18335@cindex server prefix for annotations
18336
18337To issue a command to @value{GDBN} without affecting certain aspects of
18338the state which is seen by users, prefix it with @samp{server }. This
18339means that this command will not affect the command history, nor will it
18340affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
18341pressed on a line by itself.
18342
18343The server prefix does not affect the recording of values into the value
18344history; to print a value without recording it into the value history,
18345use the @code{output} command instead of the @code{print} command.
18346
922fbb7b
AC
18347@node Prompting
18348@section Annotation for @value{GDBN} Input
18349
18350@cindex annotations for prompts
18351When @value{GDBN} prompts for input, it annotates this fact so it is possible
18352to know when to send output, when the output from a given command is
18353over, etc.
18354
18355Different kinds of input each have a different @dfn{input type}. Each
18356input type has three annotations: a @code{pre-} annotation, which
18357denotes the beginning of any prompt which is being output, a plain
18358annotation, which denotes the end of the prompt, and then a @code{post-}
18359annotation which denotes the end of any echo which may (or may not) be
18360associated with the input. For example, the @code{prompt} input type
18361features the following annotations:
18362
18363@smallexample
18364^Z^Zpre-prompt
18365^Z^Zprompt
18366^Z^Zpost-prompt
18367@end smallexample
18368
18369The input types are
18370
18371@table @code
18372@findex pre-prompt
18373@findex prompt
18374@findex post-prompt
18375@item prompt
18376When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
18377
18378@findex pre-commands
18379@findex commands
18380@findex post-commands
18381@item commands
18382When @value{GDBN} prompts for a set of commands, like in the @code{commands}
18383command. The annotations are repeated for each command which is input.
18384
18385@findex pre-overload-choice
18386@findex overload-choice
18387@findex post-overload-choice
18388@item overload-choice
18389When @value{GDBN} wants the user to select between various overloaded functions.
18390
18391@findex pre-query
18392@findex query
18393@findex post-query
18394@item query
18395When @value{GDBN} wants the user to confirm a potentially dangerous operation.
18396
18397@findex pre-prompt-for-continue
18398@findex prompt-for-continue
18399@findex post-prompt-for-continue
18400@item prompt-for-continue
18401When @value{GDBN} is asking the user to press return to continue. Note: Don't
18402expect this to work well; instead use @code{set height 0} to disable
18403prompting. This is because the counting of lines is buggy in the
18404presence of annotations.
18405@end table
18406
18407@node Errors
18408@section Errors
18409@cindex annotations for errors, warnings and interrupts
18410
18411@findex quit
18412@smallexample
18413^Z^Zquit
18414@end smallexample
18415
18416This annotation occurs right before @value{GDBN} responds to an interrupt.
18417
18418@findex error
18419@smallexample
18420^Z^Zerror
18421@end smallexample
18422
18423This annotation occurs right before @value{GDBN} responds to an error.
18424
18425Quit and error annotations indicate that any annotations which @value{GDBN} was
18426in the middle of may end abruptly. For example, if a
18427@code{value-history-begin} annotation is followed by a @code{error}, one
18428cannot expect to receive the matching @code{value-history-end}. One
18429cannot expect not to receive it either, however; an error annotation
18430does not necessarily mean that @value{GDBN} is immediately returning all the way
18431to the top level.
18432
18433@findex error-begin
18434A quit or error annotation may be preceded by
18435
18436@smallexample
18437^Z^Zerror-begin
18438@end smallexample
18439
18440Any output between that and the quit or error annotation is the error
18441message.
18442
18443Warning messages are not yet annotated.
18444@c If we want to change that, need to fix warning(), type_error(),
18445@c range_error(), and possibly other places.
18446
922fbb7b
AC
18447@node Invalidation
18448@section Invalidation Notices
18449
18450@cindex annotations for invalidation messages
18451The following annotations say that certain pieces of state may have
18452changed.
18453
18454@table @code
18455@findex frames-invalid
18456@item ^Z^Zframes-invalid
18457
18458The frames (for example, output from the @code{backtrace} command) may
18459have changed.
18460
18461@findex breakpoints-invalid
18462@item ^Z^Zbreakpoints-invalid
18463
18464The breakpoints may have changed. For example, the user just added or
18465deleted a breakpoint.
18466@end table
18467
18468@node Annotations for Running
18469@section Running the Program
18470@cindex annotations for running programs
18471
18472@findex starting
18473@findex stopping
18474When the program starts executing due to a @value{GDBN} command such as
18475@code{step} or @code{continue},
18476
18477@smallexample
18478^Z^Zstarting
18479@end smallexample
18480
18481is output. When the program stops,
18482
18483@smallexample
18484^Z^Zstopped
18485@end smallexample
18486
18487is output. Before the @code{stopped} annotation, a variety of
18488annotations describe how the program stopped.
18489
18490@table @code
18491@findex exited
18492@item ^Z^Zexited @var{exit-status}
18493The program exited, and @var{exit-status} is the exit status (zero for
18494successful exit, otherwise nonzero).
18495
18496@findex signalled
18497@findex signal-name
18498@findex signal-name-end
18499@findex signal-string
18500@findex signal-string-end
18501@item ^Z^Zsignalled
18502The program exited with a signal. After the @code{^Z^Zsignalled}, the
18503annotation continues:
18504
18505@smallexample
18506@var{intro-text}
18507^Z^Zsignal-name
18508@var{name}
18509^Z^Zsignal-name-end
18510@var{middle-text}
18511^Z^Zsignal-string
18512@var{string}
18513^Z^Zsignal-string-end
18514@var{end-text}
18515@end smallexample
18516
18517@noindent
18518where @var{name} is the name of the signal, such as @code{SIGILL} or
18519@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
18520as @code{Illegal Instruction} or @code{Segmentation fault}.
18521@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
18522user's benefit and have no particular format.
18523
18524@findex signal
18525@item ^Z^Zsignal
18526The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
18527just saying that the program received the signal, not that it was
18528terminated with it.
18529
18530@findex breakpoint
18531@item ^Z^Zbreakpoint @var{number}
18532The program hit breakpoint number @var{number}.
18533
18534@findex watchpoint
18535@item ^Z^Zwatchpoint @var{number}
18536The program hit watchpoint number @var{number}.
18537@end table
18538
18539@node Source Annotations
18540@section Displaying Source
18541@cindex annotations for source display
18542
18543@findex source
18544The following annotation is used instead of displaying source code:
18545
18546@smallexample
18547^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
18548@end smallexample
18549
18550where @var{filename} is an absolute file name indicating which source
18551file, @var{line} is the line number within that file (where 1 is the
18552first line in the file), @var{character} is the character position
18553within the file (where 0 is the first character in the file) (for most
18554debug formats this will necessarily point to the beginning of a line),
18555@var{middle} is @samp{middle} if @var{addr} is in the middle of the
18556line, or @samp{beg} if @var{addr} is at the beginning of the line, and
18557@var{addr} is the address in the target program associated with the
18558source which is being displayed. @var{addr} is in the form @samp{0x}
18559followed by one or more lowercase hex digits (note that this does not
18560depend on the language).
18561
8e04817f
AC
18562@node GDB Bugs
18563@chapter Reporting Bugs in @value{GDBN}
18564@cindex bugs in @value{GDBN}
18565@cindex reporting bugs in @value{GDBN}
c906108c 18566
8e04817f 18567Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 18568
8e04817f
AC
18569Reporting a bug may help you by bringing a solution to your problem, or it
18570may not. But in any case the principal function of a bug report is to help
18571the entire community by making the next version of @value{GDBN} work better. Bug
18572reports are your contribution to the maintenance of @value{GDBN}.
c906108c 18573
8e04817f
AC
18574In order for a bug report to serve its purpose, you must include the
18575information that enables us to fix the bug.
c4555f82
SC
18576
18577@menu
8e04817f
AC
18578* Bug Criteria:: Have you found a bug?
18579* Bug Reporting:: How to report bugs
c4555f82
SC
18580@end menu
18581
8e04817f
AC
18582@node Bug Criteria
18583@section Have you found a bug?
18584@cindex bug criteria
c4555f82 18585
8e04817f 18586If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
18587
18588@itemize @bullet
8e04817f
AC
18589@cindex fatal signal
18590@cindex debugger crash
18591@cindex crash of debugger
c4555f82 18592@item
8e04817f
AC
18593If the debugger gets a fatal signal, for any input whatever, that is a
18594@value{GDBN} bug. Reliable debuggers never crash.
18595
18596@cindex error on valid input
18597@item
18598If @value{GDBN} produces an error message for valid input, that is a
18599bug. (Note that if you're cross debugging, the problem may also be
18600somewhere in the connection to the target.)
c4555f82 18601
8e04817f 18602@cindex invalid input
c4555f82 18603@item
8e04817f
AC
18604If @value{GDBN} does not produce an error message for invalid input,
18605that is a bug. However, you should note that your idea of
18606``invalid input'' might be our idea of ``an extension'' or ``support
18607for traditional practice''.
18608
18609@item
18610If you are an experienced user of debugging tools, your suggestions
18611for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
18612@end itemize
18613
8e04817f
AC
18614@node Bug Reporting
18615@section How to report bugs
18616@cindex bug reports
18617@cindex @value{GDBN} bugs, reporting
18618
18619A number of companies and individuals offer support for @sc{gnu} products.
18620If you obtained @value{GDBN} from a support organization, we recommend you
18621contact that organization first.
18622
18623You can find contact information for many support companies and
18624individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
18625distribution.
18626@c should add a web page ref...
18627
129188f6
AC
18628In any event, we also recommend that you submit bug reports for
18629@value{GDBN}. The prefered method is to submit them directly using
18630@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
18631page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
18632be used.
8e04817f
AC
18633
18634@strong{Do not send bug reports to @samp{info-gdb}, or to
18635@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
18636not want to receive bug reports. Those that do have arranged to receive
18637@samp{bug-gdb}.
18638
18639The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
18640serves as a repeater. The mailing list and the newsgroup carry exactly
18641the same messages. Often people think of posting bug reports to the
18642newsgroup instead of mailing them. This appears to work, but it has one
18643problem which can be crucial: a newsgroup posting often lacks a mail
18644path back to the sender. Thus, if we need to ask for more information,
18645we may be unable to reach you. For this reason, it is better to send
18646bug reports to the mailing list.
c4555f82 18647
8e04817f
AC
18648The fundamental principle of reporting bugs usefully is this:
18649@strong{report all the facts}. If you are not sure whether to state a
18650fact or leave it out, state it!
c4555f82 18651
8e04817f
AC
18652Often people omit facts because they think they know what causes the
18653problem and assume that some details do not matter. Thus, you might
18654assume that the name of the variable you use in an example does not matter.
18655Well, probably it does not, but one cannot be sure. Perhaps the bug is a
18656stray memory reference which happens to fetch from the location where that
18657name is stored in memory; perhaps, if the name were different, the contents
18658of that location would fool the debugger into doing the right thing despite
18659the bug. Play it safe and give a specific, complete example. That is the
18660easiest thing for you to do, and the most helpful.
c4555f82 18661
8e04817f
AC
18662Keep in mind that the purpose of a bug report is to enable us to fix the
18663bug. It may be that the bug has been reported previously, but neither
18664you nor we can know that unless your bug report is complete and
18665self-contained.
c4555f82 18666
8e04817f
AC
18667Sometimes people give a few sketchy facts and ask, ``Does this ring a
18668bell?'' Those bug reports are useless, and we urge everyone to
18669@emph{refuse to respond to them} except to chide the sender to report
18670bugs properly.
18671
18672To enable us to fix the bug, you should include all these things:
c4555f82
SC
18673
18674@itemize @bullet
18675@item
8e04817f
AC
18676The version of @value{GDBN}. @value{GDBN} announces it if you start
18677with no arguments; you can also print it at any time using @code{show
18678version}.
c4555f82 18679
8e04817f
AC
18680Without this, we will not know whether there is any point in looking for
18681the bug in the current version of @value{GDBN}.
c4555f82
SC
18682
18683@item
8e04817f
AC
18684The type of machine you are using, and the operating system name and
18685version number.
c4555f82
SC
18686
18687@item
8e04817f
AC
18688What compiler (and its version) was used to compile @value{GDBN}---e.g.
18689``@value{GCC}--2.8.1''.
c4555f82
SC
18690
18691@item
8e04817f
AC
18692What compiler (and its version) was used to compile the program you are
18693debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
18694C Compiler''. For GCC, you can say @code{gcc --version} to get this
18695information; for other compilers, see the documentation for those
18696compilers.
c4555f82 18697
8e04817f
AC
18698@item
18699The command arguments you gave the compiler to compile your example and
18700observe the bug. For example, did you use @samp{-O}? To guarantee
18701you will not omit something important, list them all. A copy of the
18702Makefile (or the output from make) is sufficient.
c4555f82 18703
8e04817f
AC
18704If we were to try to guess the arguments, we would probably guess wrong
18705and then we might not encounter the bug.
c4555f82 18706
8e04817f
AC
18707@item
18708A complete input script, and all necessary source files, that will
18709reproduce the bug.
c4555f82 18710
8e04817f
AC
18711@item
18712A description of what behavior you observe that you believe is
18713incorrect. For example, ``It gets a fatal signal.''
c4555f82 18714
8e04817f
AC
18715Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
18716will certainly notice it. But if the bug is incorrect output, we might
18717not notice unless it is glaringly wrong. You might as well not give us
18718a chance to make a mistake.
c4555f82 18719
8e04817f
AC
18720Even if the problem you experience is a fatal signal, you should still
18721say so explicitly. Suppose something strange is going on, such as, your
18722copy of @value{GDBN} is out of synch, or you have encountered a bug in
18723the C library on your system. (This has happened!) Your copy might
18724crash and ours would not. If you told us to expect a crash, then when
18725ours fails to crash, we would know that the bug was not happening for
18726us. If you had not told us to expect a crash, then we would not be able
18727to draw any conclusion from our observations.
c4555f82 18728
8e04817f
AC
18729@item
18730If you wish to suggest changes to the @value{GDBN} source, send us context
18731diffs. If you even discuss something in the @value{GDBN} source, refer to
18732it by context, not by line number.
c4555f82 18733
8e04817f
AC
18734The line numbers in our development sources will not match those in your
18735sources. Your line numbers would convey no useful information to us.
c4555f82 18736
8e04817f 18737@end itemize
c4555f82 18738
8e04817f 18739Here are some things that are not necessary:
c4555f82 18740
8e04817f
AC
18741@itemize @bullet
18742@item
18743A description of the envelope of the bug.
c4555f82 18744
8e04817f
AC
18745Often people who encounter a bug spend a lot of time investigating
18746which changes to the input file will make the bug go away and which
18747changes will not affect it.
c4555f82 18748
8e04817f
AC
18749This is often time consuming and not very useful, because the way we
18750will find the bug is by running a single example under the debugger
18751with breakpoints, not by pure deduction from a series of examples.
18752We recommend that you save your time for something else.
c4555f82 18753
8e04817f
AC
18754Of course, if you can find a simpler example to report @emph{instead}
18755of the original one, that is a convenience for us. Errors in the
18756output will be easier to spot, running under the debugger will take
18757less time, and so on.
c4555f82 18758
8e04817f
AC
18759However, simplification is not vital; if you do not want to do this,
18760report the bug anyway and send us the entire test case you used.
c4555f82 18761
8e04817f
AC
18762@item
18763A patch for the bug.
c4555f82 18764
8e04817f
AC
18765A patch for the bug does help us if it is a good one. But do not omit
18766the necessary information, such as the test case, on the assumption that
18767a patch is all we need. We might see problems with your patch and decide
18768to fix the problem another way, or we might not understand it at all.
c4555f82 18769
8e04817f
AC
18770Sometimes with a program as complicated as @value{GDBN} it is very hard to
18771construct an example that will make the program follow a certain path
18772through the code. If you do not send us the example, we will not be able
18773to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 18774
8e04817f
AC
18775And if we cannot understand what bug you are trying to fix, or why your
18776patch should be an improvement, we will not install it. A test case will
18777help us to understand.
c4555f82 18778
8e04817f
AC
18779@item
18780A guess about what the bug is or what it depends on.
c4555f82 18781
8e04817f
AC
18782Such guesses are usually wrong. Even we cannot guess right about such
18783things without first using the debugger to find the facts.
18784@end itemize
c4555f82 18785
8e04817f
AC
18786@c The readline documentation is distributed with the readline code
18787@c and consists of the two following files:
18788@c rluser.texinfo
18789@c inc-hist.texinfo
18790@c Use -I with makeinfo to point to the appropriate directory,
18791@c environment var TEXINPUTS with TeX.
18792@include rluser.texinfo
18793@include inc-hist.texinfo
c4555f82 18794
c4555f82 18795
8e04817f
AC
18796@node Formatting Documentation
18797@appendix Formatting Documentation
c4555f82 18798
8e04817f
AC
18799@cindex @value{GDBN} reference card
18800@cindex reference card
18801The @value{GDBN} 4 release includes an already-formatted reference card, ready
18802for printing with PostScript or Ghostscript, in the @file{gdb}
18803subdirectory of the main source directory@footnote{In
18804@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
18805release.}. If you can use PostScript or Ghostscript with your printer,
18806you can print the reference card immediately with @file{refcard.ps}.
c4555f82 18807
8e04817f
AC
18808The release also includes the source for the reference card. You
18809can format it, using @TeX{}, by typing:
c4555f82 18810
474c8240 18811@smallexample
8e04817f 18812make refcard.dvi
474c8240 18813@end smallexample
c4555f82 18814
8e04817f
AC
18815The @value{GDBN} reference card is designed to print in @dfn{landscape}
18816mode on US ``letter'' size paper;
18817that is, on a sheet 11 inches wide by 8.5 inches
18818high. You will need to specify this form of printing as an option to
18819your @sc{dvi} output program.
c4555f82 18820
8e04817f 18821@cindex documentation
c4555f82 18822
8e04817f
AC
18823All the documentation for @value{GDBN} comes as part of the machine-readable
18824distribution. The documentation is written in Texinfo format, which is
18825a documentation system that uses a single source file to produce both
18826on-line information and a printed manual. You can use one of the Info
18827formatting commands to create the on-line version of the documentation
18828and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 18829
8e04817f
AC
18830@value{GDBN} includes an already formatted copy of the on-line Info
18831version of this manual in the @file{gdb} subdirectory. The main Info
18832file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
18833subordinate files matching @samp{gdb.info*} in the same directory. If
18834necessary, you can print out these files, or read them with any editor;
18835but they are easier to read using the @code{info} subsystem in @sc{gnu}
18836Emacs or the standalone @code{info} program, available as part of the
18837@sc{gnu} Texinfo distribution.
c4555f82 18838
8e04817f
AC
18839If you want to format these Info files yourself, you need one of the
18840Info formatting programs, such as @code{texinfo-format-buffer} or
18841@code{makeinfo}.
c4555f82 18842
8e04817f
AC
18843If you have @code{makeinfo} installed, and are in the top level
18844@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
18845version @value{GDBVN}), you can make the Info file by typing:
c4555f82 18846
474c8240 18847@smallexample
8e04817f
AC
18848cd gdb
18849make gdb.info
474c8240 18850@end smallexample
c4555f82 18851
8e04817f
AC
18852If you want to typeset and print copies of this manual, you need @TeX{},
18853a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
18854Texinfo definitions file.
c4555f82 18855
8e04817f
AC
18856@TeX{} is a typesetting program; it does not print files directly, but
18857produces output files called @sc{dvi} files. To print a typeset
18858document, you need a program to print @sc{dvi} files. If your system
18859has @TeX{} installed, chances are it has such a program. The precise
18860command to use depends on your system; @kbd{lpr -d} is common; another
18861(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
18862require a file name without any extension or a @samp{.dvi} extension.
c4555f82 18863
8e04817f
AC
18864@TeX{} also requires a macro definitions file called
18865@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
18866written in Texinfo format. On its own, @TeX{} cannot either read or
18867typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
18868and is located in the @file{gdb-@var{version-number}/texinfo}
18869directory.
c4555f82 18870
8e04817f
AC
18871If you have @TeX{} and a @sc{dvi} printer program installed, you can
18872typeset and print this manual. First switch to the the @file{gdb}
18873subdirectory of the main source directory (for example, to
18874@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 18875
474c8240 18876@smallexample
8e04817f 18877make gdb.dvi
474c8240 18878@end smallexample
c4555f82 18879
8e04817f 18880Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 18881
8e04817f
AC
18882@node Installing GDB
18883@appendix Installing @value{GDBN}
18884@cindex configuring @value{GDBN}
18885@cindex installation
94e91d6d 18886@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 18887
8e04817f
AC
18888@value{GDBN} comes with a @code{configure} script that automates the process
18889of preparing @value{GDBN} for installation; you can then use @code{make} to
18890build the @code{gdb} program.
18891@iftex
18892@c irrelevant in info file; it's as current as the code it lives with.
18893@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
18894look at the @file{README} file in the sources; we may have improved the
18895installation procedures since publishing this manual.}
18896@end iftex
c4555f82 18897
8e04817f
AC
18898The @value{GDBN} distribution includes all the source code you need for
18899@value{GDBN} in a single directory, whose name is usually composed by
18900appending the version number to @samp{gdb}.
c4555f82 18901
8e04817f
AC
18902For example, the @value{GDBN} version @value{GDBVN} distribution is in the
18903@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 18904
8e04817f
AC
18905@table @code
18906@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
18907script for configuring @value{GDBN} and all its supporting libraries
c4555f82 18908
8e04817f
AC
18909@item gdb-@value{GDBVN}/gdb
18910the source specific to @value{GDBN} itself
c4555f82 18911
8e04817f
AC
18912@item gdb-@value{GDBVN}/bfd
18913source for the Binary File Descriptor library
c906108c 18914
8e04817f
AC
18915@item gdb-@value{GDBVN}/include
18916@sc{gnu} include files
c906108c 18917
8e04817f
AC
18918@item gdb-@value{GDBVN}/libiberty
18919source for the @samp{-liberty} free software library
c906108c 18920
8e04817f
AC
18921@item gdb-@value{GDBVN}/opcodes
18922source for the library of opcode tables and disassemblers
c906108c 18923
8e04817f
AC
18924@item gdb-@value{GDBVN}/readline
18925source for the @sc{gnu} command-line interface
c906108c 18926
8e04817f
AC
18927@item gdb-@value{GDBVN}/glob
18928source for the @sc{gnu} filename pattern-matching subroutine
c906108c 18929
8e04817f
AC
18930@item gdb-@value{GDBVN}/mmalloc
18931source for the @sc{gnu} memory-mapped malloc package
18932@end table
c906108c 18933
8e04817f
AC
18934The simplest way to configure and build @value{GDBN} is to run @code{configure}
18935from the @file{gdb-@var{version-number}} source directory, which in
18936this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 18937
8e04817f
AC
18938First switch to the @file{gdb-@var{version-number}} source directory
18939if you are not already in it; then run @code{configure}. Pass the
18940identifier for the platform on which @value{GDBN} will run as an
18941argument.
c906108c 18942
8e04817f 18943For example:
c906108c 18944
474c8240 18945@smallexample
8e04817f
AC
18946cd gdb-@value{GDBVN}
18947./configure @var{host}
18948make
474c8240 18949@end smallexample
c906108c 18950
8e04817f
AC
18951@noindent
18952where @var{host} is an identifier such as @samp{sun4} or
18953@samp{decstation}, that identifies the platform where @value{GDBN} will run.
18954(You can often leave off @var{host}; @code{configure} tries to guess the
18955correct value by examining your system.)
c906108c 18956
8e04817f
AC
18957Running @samp{configure @var{host}} and then running @code{make} builds the
18958@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
18959libraries, then @code{gdb} itself. The configured source files, and the
18960binaries, are left in the corresponding source directories.
c906108c 18961
8e04817f
AC
18962@need 750
18963@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
18964system does not recognize this automatically when you run a different
18965shell, you may need to run @code{sh} on it explicitly:
c906108c 18966
474c8240 18967@smallexample
8e04817f 18968sh configure @var{host}
474c8240 18969@end smallexample
c906108c 18970
8e04817f
AC
18971If you run @code{configure} from a directory that contains source
18972directories for multiple libraries or programs, such as the
18973@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
18974creates configuration files for every directory level underneath (unless
18975you tell it not to, with the @samp{--norecursion} option).
18976
94e91d6d
MC
18977You should run the @code{configure} script from the top directory in the
18978source tree, the @file{gdb-@var{version-number}} directory. If you run
18979@code{configure} from one of the subdirectories, you will configure only
18980that subdirectory. That is usually not what you want. In particular,
18981if you run the first @code{configure} from the @file{gdb} subdirectory
18982of the @file{gdb-@var{version-number}} directory, you will omit the
18983configuration of @file{bfd}, @file{readline}, and other sibling
18984directories of the @file{gdb} subdirectory. This leads to build errors
18985about missing include files such as @file{bfd/bfd.h}.
c906108c 18986
8e04817f
AC
18987You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
18988However, you should make sure that the shell on your path (named by
18989the @samp{SHELL} environment variable) is publicly readable. Remember
18990that @value{GDBN} uses the shell to start your program---some systems refuse to
18991let @value{GDBN} debug child processes whose programs are not readable.
c906108c 18992
8e04817f
AC
18993@menu
18994* Separate Objdir:: Compiling @value{GDBN} in another directory
18995* Config Names:: Specifying names for hosts and targets
18996* Configure Options:: Summary of options for configure
18997@end menu
c906108c 18998
8e04817f
AC
18999@node Separate Objdir
19000@section Compiling @value{GDBN} in another directory
c906108c 19001
8e04817f
AC
19002If you want to run @value{GDBN} versions for several host or target machines,
19003you need a different @code{gdb} compiled for each combination of
19004host and target. @code{configure} is designed to make this easy by
19005allowing you to generate each configuration in a separate subdirectory,
19006rather than in the source directory. If your @code{make} program
19007handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
19008@code{make} in each of these directories builds the @code{gdb}
19009program specified there.
c906108c 19010
8e04817f
AC
19011To build @code{gdb} in a separate directory, run @code{configure}
19012with the @samp{--srcdir} option to specify where to find the source.
19013(You also need to specify a path to find @code{configure}
19014itself from your working directory. If the path to @code{configure}
19015would be the same as the argument to @samp{--srcdir}, you can leave out
19016the @samp{--srcdir} option; it is assumed.)
c906108c 19017
8e04817f
AC
19018For example, with version @value{GDBVN}, you can build @value{GDBN} in a
19019separate directory for a Sun 4 like this:
c906108c 19020
474c8240 19021@smallexample
8e04817f
AC
19022@group
19023cd gdb-@value{GDBVN}
19024mkdir ../gdb-sun4
19025cd ../gdb-sun4
19026../gdb-@value{GDBVN}/configure sun4
19027make
19028@end group
474c8240 19029@end smallexample
c906108c 19030
8e04817f
AC
19031When @code{configure} builds a configuration using a remote source
19032directory, it creates a tree for the binaries with the same structure
19033(and using the same names) as the tree under the source directory. In
19034the example, you'd find the Sun 4 library @file{libiberty.a} in the
19035directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
19036@file{gdb-sun4/gdb}.
c906108c 19037
94e91d6d
MC
19038Make sure that your path to the @file{configure} script has just one
19039instance of @file{gdb} in it. If your path to @file{configure} looks
19040like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
19041one subdirectory of @value{GDBN}, not the whole package. This leads to
19042build errors about missing include files such as @file{bfd/bfd.h}.
19043
8e04817f
AC
19044One popular reason to build several @value{GDBN} configurations in separate
19045directories is to configure @value{GDBN} for cross-compiling (where
19046@value{GDBN} runs on one machine---the @dfn{host}---while debugging
19047programs that run on another machine---the @dfn{target}).
19048You specify a cross-debugging target by
19049giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 19050
8e04817f
AC
19051When you run @code{make} to build a program or library, you must run
19052it in a configured directory---whatever directory you were in when you
19053called @code{configure} (or one of its subdirectories).
c906108c 19054
8e04817f
AC
19055The @code{Makefile} that @code{configure} generates in each source
19056directory also runs recursively. If you type @code{make} in a source
19057directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
19058directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
19059will build all the required libraries, and then build GDB.
c906108c 19060
8e04817f
AC
19061When you have multiple hosts or targets configured in separate
19062directories, you can run @code{make} on them in parallel (for example,
19063if they are NFS-mounted on each of the hosts); they will not interfere
19064with each other.
c906108c 19065
8e04817f
AC
19066@node Config Names
19067@section Specifying names for hosts and targets
c906108c 19068
8e04817f
AC
19069The specifications used for hosts and targets in the @code{configure}
19070script are based on a three-part naming scheme, but some short predefined
19071aliases are also supported. The full naming scheme encodes three pieces
19072of information in the following pattern:
c906108c 19073
474c8240 19074@smallexample
8e04817f 19075@var{architecture}-@var{vendor}-@var{os}
474c8240 19076@end smallexample
c906108c 19077
8e04817f
AC
19078For example, you can use the alias @code{sun4} as a @var{host} argument,
19079or as the value for @var{target} in a @code{--target=@var{target}}
19080option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 19081
8e04817f
AC
19082The @code{configure} script accompanying @value{GDBN} does not provide
19083any query facility to list all supported host and target names or
19084aliases. @code{configure} calls the Bourne shell script
19085@code{config.sub} to map abbreviations to full names; you can read the
19086script, if you wish, or you can use it to test your guesses on
19087abbreviations---for example:
c906108c 19088
8e04817f
AC
19089@smallexample
19090% sh config.sub i386-linux
19091i386-pc-linux-gnu
19092% sh config.sub alpha-linux
19093alpha-unknown-linux-gnu
19094% sh config.sub hp9k700
19095hppa1.1-hp-hpux
19096% sh config.sub sun4
19097sparc-sun-sunos4.1.1
19098% sh config.sub sun3
19099m68k-sun-sunos4.1.1
19100% sh config.sub i986v
19101Invalid configuration `i986v': machine `i986v' not recognized
19102@end smallexample
c906108c 19103
8e04817f
AC
19104@noindent
19105@code{config.sub} is also distributed in the @value{GDBN} source
19106directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 19107
8e04817f
AC
19108@node Configure Options
19109@section @code{configure} options
c906108c 19110
8e04817f
AC
19111Here is a summary of the @code{configure} options and arguments that
19112are most often useful for building @value{GDBN}. @code{configure} also has
19113several other options not listed here. @inforef{What Configure
19114Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 19115
474c8240 19116@smallexample
8e04817f
AC
19117configure @r{[}--help@r{]}
19118 @r{[}--prefix=@var{dir}@r{]}
19119 @r{[}--exec-prefix=@var{dir}@r{]}
19120 @r{[}--srcdir=@var{dirname}@r{]}
19121 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
19122 @r{[}--target=@var{target}@r{]}
19123 @var{host}
474c8240 19124@end smallexample
c906108c 19125
8e04817f
AC
19126@noindent
19127You may introduce options with a single @samp{-} rather than
19128@samp{--} if you prefer; but you may abbreviate option names if you use
19129@samp{--}.
c906108c 19130
8e04817f
AC
19131@table @code
19132@item --help
19133Display a quick summary of how to invoke @code{configure}.
c906108c 19134
8e04817f
AC
19135@item --prefix=@var{dir}
19136Configure the source to install programs and files under directory
19137@file{@var{dir}}.
c906108c 19138
8e04817f
AC
19139@item --exec-prefix=@var{dir}
19140Configure the source to install programs under directory
19141@file{@var{dir}}.
c906108c 19142
8e04817f
AC
19143@c avoid splitting the warning from the explanation:
19144@need 2000
19145@item --srcdir=@var{dirname}
19146@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
19147@code{make} that implements the @code{VPATH} feature.}@*
19148Use this option to make configurations in directories separate from the
19149@value{GDBN} source directories. Among other things, you can use this to
19150build (or maintain) several configurations simultaneously, in separate
19151directories. @code{configure} writes configuration specific files in
19152the current directory, but arranges for them to use the source in the
19153directory @var{dirname}. @code{configure} creates directories under
19154the working directory in parallel to the source directories below
19155@var{dirname}.
c906108c 19156
8e04817f
AC
19157@item --norecursion
19158Configure only the directory level where @code{configure} is executed; do not
19159propagate configuration to subdirectories.
c906108c 19160
8e04817f
AC
19161@item --target=@var{target}
19162Configure @value{GDBN} for cross-debugging programs running on the specified
19163@var{target}. Without this option, @value{GDBN} is configured to debug
19164programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 19165
8e04817f 19166There is no convenient way to generate a list of all available targets.
c906108c 19167
8e04817f
AC
19168@item @var{host} @dots{}
19169Configure @value{GDBN} to run on the specified @var{host}.
c906108c 19170
8e04817f
AC
19171There is no convenient way to generate a list of all available hosts.
19172@end table
c906108c 19173
8e04817f
AC
19174There are many other options available as well, but they are generally
19175needed for special purposes only.
c906108c 19176
8e04817f
AC
19177@node Maintenance Commands
19178@appendix Maintenance Commands
19179@cindex maintenance commands
19180@cindex internal commands
c906108c 19181
8e04817f
AC
19182In addition to commands intended for @value{GDBN} users, @value{GDBN}
19183includes a number of commands intended for @value{GDBN} developers.
19184These commands are provided here for reference.
c906108c 19185
8e04817f
AC
19186@table @code
19187@kindex maint info breakpoints
19188@item @anchor{maint info breakpoints}maint info breakpoints
19189Using the same format as @samp{info breakpoints}, display both the
19190breakpoints you've set explicitly, and those @value{GDBN} is using for
19191internal purposes. Internal breakpoints are shown with negative
19192breakpoint numbers. The type column identifies what kind of breakpoint
19193is shown:
c906108c 19194
8e04817f
AC
19195@table @code
19196@item breakpoint
19197Normal, explicitly set breakpoint.
c906108c 19198
8e04817f
AC
19199@item watchpoint
19200Normal, explicitly set watchpoint.
c906108c 19201
8e04817f
AC
19202@item longjmp
19203Internal breakpoint, used to handle correctly stepping through
19204@code{longjmp} calls.
c906108c 19205
8e04817f
AC
19206@item longjmp resume
19207Internal breakpoint at the target of a @code{longjmp}.
c906108c 19208
8e04817f
AC
19209@item until
19210Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 19211
8e04817f
AC
19212@item finish
19213Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 19214
8e04817f
AC
19215@item shlib events
19216Shared library events.
c906108c 19217
8e04817f 19218@end table
c906108c 19219
8d30a00d
AC
19220@kindex maint internal-error
19221@kindex maint internal-warning
19222@item maint internal-error
19223@itemx maint internal-warning
19224Cause @value{GDBN} to call the internal function @code{internal_error}
19225or @code{internal_warning} and hence behave as though an internal error
19226or internal warning has been detected. In addition to reporting the
19227internal problem, these functions give the user the opportunity to
19228either quit @value{GDBN} or create a core file of the current
19229@value{GDBN} session.
19230
19231@smallexample
19232(gdb) @kbd{maint internal-error testing, 1, 2}
19233@dots{}/maint.c:121: internal-error: testing, 1, 2
19234A problem internal to GDB has been detected. Further
19235debugging may prove unreliable.
19236Quit this debugging session? (y or n) @kbd{n}
19237Create a core file? (y or n) @kbd{n}
19238(gdb)
19239@end smallexample
19240
19241Takes an optional parameter that is used as the text of the error or
19242warning message.
19243
00905d52
AC
19244@kindex maint print dummy-frames
19245@item maint print dummy-frames
19246
19247Prints the contents of @value{GDBN}'s internal dummy-frame stack.
19248
19249@smallexample
19250(gdb) @kbd{b add}
19251@dots{}
19252(gdb) @kbd{print add(2,3)}
19253Breakpoint 2, add (a=2, b=3) at @dots{}
1925458 return (a + b);
19255The program being debugged stopped while in a function called from GDB.
19256@dots{}
19257(gdb) @kbd{maint print dummy-frames}
192580x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
19259 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
19260 call_lo=0x01014000 call_hi=0x01014001
19261(gdb)
19262@end smallexample
19263
19264Takes an optional file parameter.
19265
0680b120
AC
19266@kindex maint print registers
19267@kindex maint print raw-registers
19268@kindex maint print cooked-registers
617073a9 19269@kindex maint print register-groups
0680b120
AC
19270@item maint print registers
19271@itemx maint print raw-registers
19272@itemx maint print cooked-registers
617073a9 19273@itemx maint print register-groups
0680b120
AC
19274Print @value{GDBN}'s internal register data structures.
19275
617073a9
AC
19276The command @code{maint print raw-registers} includes the contents of
19277the raw register cache; the command @code{maint print cooked-registers}
19278includes the (cooked) value of all registers; and the command
19279@code{maint print register-groups} includes the groups that each
19280register is a member of. @xref{Registers,, Registers, gdbint,
19281@value{GDBN} Internals}.
0680b120
AC
19282
19283Takes an optional file parameter.
19284
617073a9
AC
19285@kindex maint print reggroups
19286@item maint print reggroups
19287Print @value{GDBN}'s internal register group data structures.
19288
19289Takes an optional file parameter.
19290
19291@smallexample
19292(gdb) @kbd{maint print reggroups}
19293 Group Type
19294 general user
19295 float user
19296 all user
19297 vector user
19298 system user
19299 save internal
19300 restore internal
19301@end smallexample
19302
e7ba9c65
DJ
19303@kindex maint set profile
19304@kindex maint show profile
19305@cindex profiling GDB
19306@item maint set profile
19307@itemx maint show profile
19308Control profiling of @value{GDBN}.
19309
19310Profiling will be disabled until you use the @samp{maint set profile}
19311command to enable it. When you enable profiling, the system will begin
19312collecting timing and execution count data; when you disable profiling or
19313exit @value{GDBN}, the results will be written to a log file. Remember that
19314if you use profiling, @value{GDBN} will overwrite the profiling log file
19315(often called @file{gmon.out}). If you have a record of important profiling
19316data in a @file{gmon.out} file, be sure to move it to a safe location.
19317
19318Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
19319compiled with the @samp{-pg} compiler option.
19320
8e04817f 19321@end table
c906108c 19322
c906108c 19323
e0ce93ac 19324@node Remote Protocol
8e04817f 19325@appendix @value{GDBN} Remote Serial Protocol
c906108c 19326
ee2d5c50
AC
19327@menu
19328* Overview::
19329* Packets::
19330* Stop Reply Packets::
19331* General Query Packets::
19332* Register Packet Format::
19333* Examples::
0ce1b118 19334* File-I/O remote protocol extension::
ee2d5c50
AC
19335@end menu
19336
19337@node Overview
19338@section Overview
19339
8e04817f
AC
19340There may be occasions when you need to know something about the
19341protocol---for example, if there is only one serial port to your target
19342machine, you might want your program to do something special if it
19343recognizes a packet meant for @value{GDBN}.
c906108c 19344
d2c6833e 19345In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 19346transmitted and received data respectfully.
c906108c 19347
8e04817f
AC
19348@cindex protocol, @value{GDBN} remote serial
19349@cindex serial protocol, @value{GDBN} remote
19350@cindex remote serial protocol
19351All @value{GDBN} commands and responses (other than acknowledgments) are
19352sent as a @var{packet}. A @var{packet} is introduced with the character
19353@samp{$}, the actual @var{packet-data}, and the terminating character
19354@samp{#} followed by a two-digit @var{checksum}:
c906108c 19355
474c8240 19356@smallexample
8e04817f 19357@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 19358@end smallexample
8e04817f 19359@noindent
c906108c 19360
8e04817f
AC
19361@cindex checksum, for @value{GDBN} remote
19362@noindent
19363The two-digit @var{checksum} is computed as the modulo 256 sum of all
19364characters between the leading @samp{$} and the trailing @samp{#} (an
19365eight bit unsigned checksum).
c906108c 19366
8e04817f
AC
19367Implementors should note that prior to @value{GDBN} 5.0 the protocol
19368specification also included an optional two-digit @var{sequence-id}:
c906108c 19369
474c8240 19370@smallexample
8e04817f 19371@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 19372@end smallexample
c906108c 19373
8e04817f
AC
19374@cindex sequence-id, for @value{GDBN} remote
19375@noindent
19376That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
19377has never output @var{sequence-id}s. Stubs that handle packets added
19378since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 19379
8e04817f
AC
19380@cindex acknowledgment, for @value{GDBN} remote
19381When either the host or the target machine receives a packet, the first
19382response expected is an acknowledgment: either @samp{+} (to indicate
19383the package was received correctly) or @samp{-} (to request
19384retransmission):
c906108c 19385
474c8240 19386@smallexample
d2c6833e
AC
19387-> @code{$}@var{packet-data}@code{#}@var{checksum}
19388<- @code{+}
474c8240 19389@end smallexample
8e04817f 19390@noindent
53a5351d 19391
8e04817f
AC
19392The host (@value{GDBN}) sends @var{command}s, and the target (the
19393debugging stub incorporated in your program) sends a @var{response}. In
19394the case of step and continue @var{command}s, the response is only sent
19395when the operation has completed (the target has again stopped).
c906108c 19396
8e04817f
AC
19397@var{packet-data} consists of a sequence of characters with the
19398exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
19399exceptions).
c906108c 19400
8e04817f 19401Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 19402@cindex remote protocol, field separator
8e04817f 19403@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 19404@sc{hex} with leading zeros suppressed.
c906108c 19405
8e04817f
AC
19406Implementors should note that prior to @value{GDBN} 5.0, the character
19407@samp{:} could not appear as the third character in a packet (as it
19408would potentially conflict with the @var{sequence-id}).
c906108c 19409
8e04817f
AC
19410Response @var{data} can be run-length encoded to save space. A @samp{*}
19411means that the next character is an @sc{ascii} encoding giving a repeat count
19412which stands for that many repetitions of the character preceding the
19413@samp{*}. The encoding is @code{n+29}, yielding a printable character
19414where @code{n >=3} (which is where rle starts to win). The printable
19415characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
19416value greater than 126 should not be used.
c906108c 19417
8e04817f
AC
19418Some remote systems have used a different run-length encoding mechanism
19419loosely refered to as the cisco encoding. Following the @samp{*}
19420character are two hex digits that indicate the size of the packet.
c906108c 19421
8e04817f 19422So:
474c8240 19423@smallexample
8e04817f 19424"@code{0* }"
474c8240 19425@end smallexample
8e04817f
AC
19426@noindent
19427means the same as "0000".
c906108c 19428
8e04817f
AC
19429The error response returned for some packets includes a two character
19430error number. That number is not well defined.
c906108c 19431
8e04817f
AC
19432For any @var{command} not supported by the stub, an empty response
19433(@samp{$#00}) should be returned. That way it is possible to extend the
19434protocol. A newer @value{GDBN} can tell if a packet is supported based
19435on that response.
c906108c 19436
8e04817f
AC
19437A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
19438@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
19439optional.
c906108c 19440
ee2d5c50
AC
19441@node Packets
19442@section Packets
19443
19444The following table provides a complete list of all currently defined
19445@var{command}s and their corresponding response @var{data}.
19446
19447@table @r
19448
19449@item @code{!} --- extended mode
19450@cindex @code{!} packet
19451
8e04817f
AC
19452Enable extended mode. In extended mode, the remote server is made
19453persistent. The @samp{R} packet is used to restart the program being
19454debugged.
ee2d5c50
AC
19455
19456Reply:
19457@table @samp
19458@item OK
8e04817f 19459The remote target both supports and has enabled extended mode.
ee2d5c50 19460@end table
c906108c 19461
ee2d5c50
AC
19462@item @code{?} --- last signal
19463@cindex @code{?} packet
c906108c 19464
ee2d5c50
AC
19465Indicate the reason the target halted. The reply is the same as for
19466step and continue.
c906108c 19467
ee2d5c50
AC
19468Reply:
19469@xref{Stop Reply Packets}, for the reply specifications.
19470
19471@item @code{a} --- reserved
19472
19473Reserved for future use.
19474
19475@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
19476@cindex @code{A} packet
c906108c 19477
8e04817f
AC
19478Initialized @samp{argv[]} array passed into program. @var{arglen}
19479specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
19480See @code{gdbserver} for more details.
19481
19482Reply:
19483@table @samp
19484@item OK
19485@item E@var{NN}
19486@end table
19487
19488@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
19489@cindex @code{b} packet
19490
19491Change the serial line speed to @var{baud}.
19492
19493JTC: @emph{When does the transport layer state change? When it's
19494received, or after the ACK is transmitted. In either case, there are
19495problems if the command or the acknowledgment packet is dropped.}
19496
19497Stan: @emph{If people really wanted to add something like this, and get
19498it working for the first time, they ought to modify ser-unix.c to send
19499some kind of out-of-band message to a specially-setup stub and have the
19500switch happen "in between" packets, so that from remote protocol's point
19501of view, nothing actually happened.}
19502
19503@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
19504@cindex @code{B} packet
19505
8e04817f 19506Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
19507breakpoint at @var{addr}.
19508
19509This packet has been replaced by the @samp{Z} and @samp{z} packets
19510(@pxref{insert breakpoint or watchpoint packet}).
c906108c 19511
ee2d5c50
AC
19512@item @code{c}@var{addr} --- continue
19513@cindex @code{c} packet
19514
19515@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 19516current address.
c906108c 19517
ee2d5c50
AC
19518Reply:
19519@xref{Stop Reply Packets}, for the reply specifications.
19520
19521@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
19522@cindex @code{C} packet
19523
8e04817f
AC
19524Continue with signal @var{sig} (hex signal number). If
19525@code{;}@var{addr} is omitted, resume at same address.
c906108c 19526
ee2d5c50
AC
19527Reply:
19528@xref{Stop Reply Packets}, for the reply specifications.
c906108c 19529
ee2d5c50
AC
19530@item @code{d} --- toggle debug @strong{(deprecated)}
19531@cindex @code{d} packet
19532
19533Toggle debug flag.
19534
19535@item @code{D} --- detach
19536@cindex @code{D} packet
19537
19538Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 19539before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
19540
19541Reply:
19542@table @samp
19543@item @emph{no response}
8e04817f 19544@value{GDBN} does not check for any response after sending this packet.
ee2d5c50 19545@end table
c906108c 19546
ee2d5c50 19547@item @code{e} --- reserved
c906108c 19548
ee2d5c50 19549Reserved for future use.
c906108c 19550
ee2d5c50 19551@item @code{E} --- reserved
c906108c 19552
ee2d5c50 19553Reserved for future use.
c906108c 19554
ee2d5c50
AC
19555@item @code{f} --- reserved
19556
19557Reserved for future use.
19558
0ce1b118
CV
19559@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
19560@cindex @code{F} packet
ee2d5c50 19561
0ce1b118
CV
19562This packet is send by @value{GDBN} as reply to a @code{F} request packet
19563sent by the target. This is part of the File-I/O protocol extension.
19564@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
19565
19566@item @code{g} --- read registers
19567@anchor{read registers packet}
19568@cindex @code{g} packet
19569
19570Read general registers.
19571
19572Reply:
19573@table @samp
19574@item @var{XX@dots{}}
8e04817f
AC
19575Each byte of register data is described by two hex digits. The bytes
19576with the register are transmitted in target byte order. The size of
19577each register and their position within the @samp{g} @var{packet} are
12c266ea
AC
19578determined by the @value{GDBN} internal macros
19579@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
19580specification of several standard @code{g} packets is specified below.
ee2d5c50
AC
19581@item E@var{NN}
19582for an error.
19583@end table
c906108c 19584
ee2d5c50
AC
19585@item @code{G}@var{XX@dots{}} --- write regs
19586@cindex @code{G} packet
c906108c 19587
ee2d5c50
AC
19588@xref{read registers packet}, for a description of the @var{XX@dots{}}
19589data.
19590
19591Reply:
19592@table @samp
19593@item OK
19594for success
19595@item E@var{NN}
19596for an error
19597@end table
19598
19599@item @code{h} --- reserved
19600
19601Reserved for future use.
19602
19603@item @code{H}@var{c}@var{t@dots{}} --- set thread
19604@cindex @code{H} packet
c906108c 19605
8e04817f 19606Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
19607@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
19608should be @samp{c} for step and continue operations, @samp{g} for other
19609operations. The thread designator @var{t@dots{}} may be -1, meaning all
19610the threads, a thread number, or zero which means pick any thread.
19611
19612Reply:
19613@table @samp
19614@item OK
19615for success
19616@item E@var{NN}
19617for an error
19618@end table
c906108c 19619
8e04817f
AC
19620@c FIXME: JTC:
19621@c 'H': How restrictive (or permissive) is the thread model. If a
19622@c thread is selected and stopped, are other threads allowed
19623@c to continue to execute? As I mentioned above, I think the
19624@c semantics of each command when a thread is selected must be
19625@c described. For example:
19626@c
19627@c 'g': If the stub supports threads and a specific thread is
19628@c selected, returns the register block from that thread;
19629@c otherwise returns current registers.
19630@c
19631@c 'G' If the stub supports threads and a specific thread is
19632@c selected, sets the registers of the register block of
19633@c that thread; otherwise sets current registers.
c906108c 19634
ee2d5c50
AC
19635@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
19636@anchor{cycle step packet}
19637@cindex @code{i} packet
19638
8e04817f
AC
19639Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
19640present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
19641step starting at that address.
c906108c 19642
ee2d5c50
AC
19643@item @code{I} --- signal then cycle step @strong{(reserved)}
19644@cindex @code{I} packet
19645
19646@xref{step with signal packet}. @xref{cycle step packet}.
19647
19648@item @code{j} --- reserved
19649
19650Reserved for future use.
19651
19652@item @code{J} --- reserved
c906108c 19653
ee2d5c50 19654Reserved for future use.
c906108c 19655
ee2d5c50
AC
19656@item @code{k} --- kill request
19657@cindex @code{k} packet
c906108c 19658
ac282366 19659FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
19660thread context has been selected (i.e.@: does 'k' kill only that
19661thread?)}.
c906108c 19662
ee2d5c50 19663@item @code{K} --- reserved
c906108c 19664
ee2d5c50
AC
19665Reserved for future use.
19666
19667@item @code{l} --- reserved
19668
19669Reserved for future use.
19670
19671@item @code{L} --- reserved
19672
19673Reserved for future use.
19674
19675@item @code{m}@var{addr}@code{,}@var{length} --- read memory
19676@cindex @code{m} packet
c906108c 19677
8e04817f 19678Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 19679Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 19680assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 19681transfer mechanism is needed.}
c906108c 19682
ee2d5c50
AC
19683Reply:
19684@table @samp
19685@item @var{XX@dots{}}
19686@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
19687to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 19688that sized memory transfers are assumed using word aligned
ee2d5c50
AC
19689accesses. FIXME: @emph{A word aligned memory transfer mechanism is
19690needed.}
19691@item E@var{NN}
19692@var{NN} is errno
19693@end table
19694
19695@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
19696@cindex @code{M} packet
19697
8e04817f 19698Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
19699@var{XX@dots{}} is the data.
19700
19701Reply:
19702@table @samp
19703@item OK
19704for success
19705@item E@var{NN}
8e04817f
AC
19706for an error (this includes the case where only part of the data was
19707written).
ee2d5c50 19708@end table
c906108c 19709
ee2d5c50 19710@item @code{n} --- reserved
c906108c 19711
ee2d5c50 19712Reserved for future use.
c906108c 19713
ee2d5c50 19714@item @code{N} --- reserved
c906108c 19715
ee2d5c50 19716Reserved for future use.
c906108c 19717
ee2d5c50
AC
19718@item @code{o} --- reserved
19719
19720Reserved for future use.
19721
19722@item @code{O} --- reserved
19723
19724Reserved for future use.
c906108c 19725
ee2d5c50
AC
19726@item @code{p}@var{n@dots{}} --- read reg @strong{(reserved)}
19727@cindex @code{p} packet
19728
19729@xref{write register packet}.
19730
19731Reply:
19732@table @samp
19733@item @var{r@dots{}.}
19734The hex encoded value of the register in target byte order.
19735@end table
19736
19737@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
19738@anchor{write register packet}
19739@cindex @code{P} packet
19740
19741Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 19742digits for each byte in the register (target byte order).
c906108c 19743
ee2d5c50
AC
19744Reply:
19745@table @samp
19746@item OK
19747for success
19748@item E@var{NN}
19749for an error
19750@end table
19751
19752@item @code{q}@var{query} --- general query
19753@anchor{general query packet}
19754@cindex @code{q} packet
19755
19756Request info about @var{query}. In general @value{GDBN} queries have a
19757leading upper case letter. Custom vendor queries should use a company
19758prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
19759be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
19760that they match the full @var{query} name.
19761
19762Reply:
19763@table @samp
19764@item @var{XX@dots{}}
19765Hex encoded data from query. The reply can not be empty.
19766@item E@var{NN}
19767error reply
8e04817f 19768@item
ee2d5c50
AC
19769Indicating an unrecognized @var{query}.
19770@end table
19771
19772@item @code{Q}@var{var}@code{=}@var{val} --- general set
19773@cindex @code{Q} packet
19774
19775Set value of @var{var} to @var{val}.
19776
19777@xref{general query packet}, for a discussion of naming conventions.
c906108c 19778
ee2d5c50
AC
19779@item @code{r} --- reset @strong{(deprecated)}
19780@cindex @code{r} packet
c906108c 19781
8e04817f 19782Reset the entire system.
c906108c 19783
ee2d5c50
AC
19784@item @code{R}@var{XX} --- remote restart
19785@cindex @code{R} packet
19786
8e04817f
AC
19787Restart the program being debugged. @var{XX}, while needed, is ignored.
19788This packet is only available in extended mode.
ee2d5c50
AC
19789
19790Reply:
19791@table @samp
19792@item @emph{no reply}
8e04817f 19793The @samp{R} packet has no reply.
ee2d5c50
AC
19794@end table
19795
19796@item @code{s}@var{addr} --- step
19797@cindex @code{s} packet
c906108c 19798
8e04817f
AC
19799@var{addr} is address to resume. If @var{addr} is omitted, resume at
19800same address.
c906108c 19801
ee2d5c50
AC
19802Reply:
19803@xref{Stop Reply Packets}, for the reply specifications.
19804
19805@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
19806@anchor{step with signal packet}
19807@cindex @code{S} packet
19808
8e04817f 19809Like @samp{C} but step not continue.
c906108c 19810
ee2d5c50
AC
19811Reply:
19812@xref{Stop Reply Packets}, for the reply specifications.
19813
19814@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
19815@cindex @code{t} packet
19816
8e04817f 19817Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
19818@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
19819@var{addr} must be at least 3 digits.
c906108c 19820
ee2d5c50
AC
19821@item @code{T}@var{XX} --- thread alive
19822@cindex @code{T} packet
c906108c 19823
ee2d5c50 19824Find out if the thread XX is alive.
c906108c 19825
ee2d5c50
AC
19826Reply:
19827@table @samp
19828@item OK
19829thread is still alive
19830@item E@var{NN}
19831thread is dead
19832@end table
19833
19834@item @code{u} --- reserved
19835
19836Reserved for future use.
19837
19838@item @code{U} --- reserved
19839
19840Reserved for future use.
19841
86d30acc 19842@item @code{v} --- verbose packet prefix
ee2d5c50 19843
86d30acc
DJ
19844Packets starting with @code{v} are identified by a multi-letter name,
19845up to the first @code{;} or @code{?} (or the end of the packet).
19846
19847@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
19848@cindex @code{vCont} packet
19849
19850Resume the inferior. Different actions may be specified for each thread.
19851If an action is specified with no @var{tid}, then it is applied to any
19852threads that don't have a specific action specified; if no default action is
19853specified then other threads should remain stopped. Specifying multiple
19854default actions is an error; specifying no actions is also an error.
19855Thread IDs are specified in hexadecimal. Currently supported actions are:
19856
19857@table @code
19858@item c
19859Continue.
19860@item C@var{sig}
19861Continue with signal @var{sig}. @var{sig} should be two hex digits.
19862@item s
19863Step.
19864@item S@var{sig}
19865Step with signal @var{sig}. @var{sig} should be two hex digits.
19866@end table
19867
19868The optional @var{addr} argument normally associated with these packets is
19869not supported in @code{vCont}.
19870
19871Reply:
19872@xref{Stop Reply Packets}, for the reply specifications.
19873
19874@item @code{vCont?} --- extended resume query
19875@cindex @code{vCont?} packet
19876
19877Query support for the @code{vCont} packet.
19878
19879Reply:
19880@table @samp
19881@item @code{vCont}[;@var{action}]...
19882The @code{vCont} packet is supported. Each @var{action} is a supported
19883command in the @code{vCont} packet.
19884@item
19885The @code{vCont} packet is not supported.
19886@end table
ee2d5c50
AC
19887
19888@item @code{V} --- reserved
c906108c 19889
ee2d5c50 19890Reserved for future use.
c906108c 19891
ee2d5c50 19892@item @code{w} --- reserved
c906108c 19893
ee2d5c50 19894Reserved for future use.
c906108c 19895
ee2d5c50 19896@item @code{W} --- reserved
c906108c 19897
ee2d5c50 19898Reserved for future use.
c906108c 19899
ee2d5c50
AC
19900@item @code{x} --- reserved
19901
19902Reserved for future use.
19903
19904@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
19905@cindex @code{X} packet
19906
19907@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
19908is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
8e04817f 19909escaped using @code{0x7d}.
c906108c 19910
ee2d5c50
AC
19911Reply:
19912@table @samp
19913@item OK
19914for success
19915@item E@var{NN}
19916for an error
19917@end table
19918
19919@item @code{y} --- reserved
c906108c 19920
ee2d5c50 19921Reserved for future use.
c906108c 19922
ee2d5c50
AC
19923@item @code{Y} reserved
19924
19925Reserved for future use.
19926
2f870471
AC
19927@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
19928@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
19929@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 19930@cindex @code{z} packet
2f870471 19931@cindex @code{Z} packets
ee2d5c50 19932
2f870471
AC
19933Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
19934watchpoint starting at address @var{address} and covering the next
19935@var{length} bytes.
ee2d5c50 19936
2f870471
AC
19937Each breakpoint and watchpoint packet @var{type} is documented
19938separately.
19939
512217c7
AC
19940@emph{Implementation notes: A remote target shall return an empty string
19941for an unrecognized breakpoint or watchpoint packet @var{type}. A
19942remote target shall support either both or neither of a given
2f870471
AC
19943@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
19944avoid potential problems with duplicate packets, the operations should
19945be implemented in an idempotent way.}
19946
19947@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
19948@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
19949@cindex @code{z0} packet
19950@cindex @code{Z0} packet
19951
19952Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
19953@code{addr} of size @code{length}.
19954
19955A memory breakpoint is implemented by replacing the instruction at
19956@var{addr} with a software breakpoint or trap instruction. The
19957@code{length} is used by targets that indicates the size of the
19958breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
19959@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 19960
2f870471
AC
19961@emph{Implementation note: It is possible for a target to copy or move
19962code that contains memory breakpoints (e.g., when implementing
19963overlays). The behavior of this packet, in the presence of such a
19964target, is not defined.}
c906108c 19965
ee2d5c50
AC
19966Reply:
19967@table @samp
2f870471
AC
19968@item OK
19969success
19970@item
19971not supported
ee2d5c50
AC
19972@item E@var{NN}
19973for an error
2f870471
AC
19974@end table
19975
19976@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
19977@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
19978@cindex @code{z1} packet
19979@cindex @code{Z1} packet
19980
19981Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
19982address @code{addr} of size @code{length}.
19983
19984A hardware breakpoint is implemented using a mechanism that is not
19985dependant on being able to modify the target's memory.
19986
19987@emph{Implementation note: A hardware breakpoint is not affected by code
19988movement.}
19989
19990Reply:
19991@table @samp
ee2d5c50 19992@item OK
2f870471
AC
19993success
19994@item
19995not supported
19996@item E@var{NN}
19997for an error
19998@end table
19999
20000@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
20001@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
20002@cindex @code{z2} packet
20003@cindex @code{Z2} packet
20004
20005Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
20006
20007Reply:
20008@table @samp
20009@item OK
20010success
20011@item
20012not supported
20013@item E@var{NN}
20014for an error
20015@end table
20016
20017@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
20018@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
20019@cindex @code{z3} packet
20020@cindex @code{Z3} packet
20021
2e834e49 20022Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
20023
20024Reply:
20025@table @samp
20026@item OK
20027success
20028@item
20029not supported
20030@item E@var{NN}
20031for an error
20032@end table
20033
2e834e49
HPN
20034@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
20035@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
20036@cindex @code{z4} packet
20037@cindex @code{Z4} packet
20038
20039Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
20040
20041Reply:
20042@table @samp
20043@item OK
20044success
20045@item
20046not supported
20047@item E@var{NN}
20048for an error
ee2d5c50
AC
20049@end table
20050
20051@end table
c906108c 20052
ee2d5c50
AC
20053@node Stop Reply Packets
20054@section Stop Reply Packets
20055@cindex stop reply packets
c906108c 20056
8e04817f
AC
20057The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
20058receive any of the below as a reply. In the case of the @samp{C},
20059@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
20060when the target halts. In the below the exact meaning of @samp{signal
20061number} is poorly defined. In general one of the UNIX signal numbering
20062conventions is used.
c906108c 20063
ee2d5c50 20064@table @samp
c906108c 20065
ee2d5c50
AC
20066@item S@var{AA}
20067@var{AA} is the signal number
c906108c 20068
8e04817f 20069@item @code{T}@var{AA}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}
ee2d5c50
AC
20070@cindex @code{T} packet reply
20071
8e04817f
AC
20072@var{AA} = two hex digit signal number; @var{n...} = register number
20073(hex), @var{r...} = target byte ordered register contents, size defined
12c266ea
AC
20074by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
20075@var{r...} = thread process ID, this is a hex integer; @var{n...} =
20076(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
20077address, this is a hex integer; @var{n...} = other string not starting
20078with valid hex digit. @value{GDBN} should ignore this @var{n...},
20079@var{r...} pair and go on to the next. This way we can extend the
20080protocol.
c906108c 20081
ee2d5c50
AC
20082@item W@var{AA}
20083
8e04817f 20084The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
20085applicable to certain targets.
20086
20087@item X@var{AA}
c906108c 20088
8e04817f 20089The process terminated with signal @var{AA}.
c906108c 20090
ee2d5c50
AC
20091@item N@var{AA};@var{t@dots{}};@var{d@dots{}};@var{b@dots{}} @strong{(obsolete)}
20092
20093@var{AA} = signal number; @var{t@dots{}} = address of symbol
20094@code{_start}; @var{d@dots{}} = base of data section; @var{b@dots{}} =
20095base of bss section. @emph{Note: only used by Cisco Systems targets.
20096The difference between this reply and the @samp{qOffsets} query is that
20097the @samp{N} packet may arrive spontaneously whereas the @samp{qOffsets}
20098is a query initiated by the host debugger.}
c906108c 20099
ee2d5c50 20100@item O@var{XX@dots{}}
c906108c 20101
ee2d5c50
AC
20102@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
20103any time while the program is running and the debugger should continue
20104to wait for @samp{W}, @samp{T}, etc.
20105
0ce1b118
CV
20106@item F@var{call-id}@code{,}@var{parameter@dots{}}
20107
20108@var{call-id} is the identifier which says which host system call should
20109be called. This is just the name of the function. Translation into the
20110correct system call is only applicable as it's defined in @value{GDBN}.
20111@xref{File-I/O remote protocol extension}, for a list of implemented
20112system calls.
20113
20114@var{parameter@dots{}} is a list of parameters as defined for this very
20115system call.
20116
20117The target replies with this packet when it expects @value{GDBN} to call
20118a host system call on behalf of the target. @value{GDBN} replies with
20119an appropriate @code{F} packet and keeps up waiting for the next reply
20120packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
20121@samp{s} action is expected to be continued.
20122@xref{File-I/O remote protocol extension}, for more details.
20123
ee2d5c50
AC
20124@end table
20125
20126@node General Query Packets
20127@section General Query Packets
c906108c 20128
8e04817f 20129The following set and query packets have already been defined.
c906108c 20130
ee2d5c50 20131@table @r
c906108c 20132
ee2d5c50
AC
20133@item @code{q}@code{C} --- current thread
20134
20135Return the current thread id.
20136
20137Reply:
20138@table @samp
20139@item @code{QC}@var{pid}
8e04817f 20140Where @var{pid} is a HEX encoded 16 bit process id.
ee2d5c50
AC
20141@item *
20142Any other reply implies the old pid.
20143@end table
20144
20145@item @code{q}@code{fThreadInfo} -- all thread ids
20146
20147@code{q}@code{sThreadInfo}
c906108c 20148
8e04817f
AC
20149Obtain a list of active thread ids from the target (OS). Since there
20150may be too many active threads to fit into one reply packet, this query
20151works iteratively: it may require more than one query/reply sequence to
20152obtain the entire list of threads. The first query of the sequence will
20153be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
20154sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
20155
20156NOTE: replaces the @code{qL} query (see below).
20157
20158Reply:
20159@table @samp
20160@item @code{m}@var{id}
20161A single thread id
20162@item @code{m}@var{id},@var{id}@dots{}
20163a comma-separated list of thread ids
20164@item @code{l}
20165(lower case 'el') denotes end of list.
20166@end table
20167
20168In response to each query, the target will reply with a list of one or
20169more thread ids, in big-endian hex, separated by commas. @value{GDBN}
20170will respond to each reply with a request for more thread ids (using the
8e04817f
AC
20171@code{qs} form of the query), until the target responds with @code{l}
20172(lower-case el, for @code{'last'}).
c906108c 20173
ee2d5c50
AC
20174@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
20175
20176Where @var{id} is a thread-id in big-endian hex. Obtain a printable
20177string description of a thread's attributes from the target OS. This
20178string may contain anything that the target OS thinks is interesting for
20179@value{GDBN} to tell the user about the thread. The string is displayed
20180in @value{GDBN}'s @samp{info threads} display. Some examples of
20181possible thread extra info strings are ``Runnable'', or ``Blocked on
20182Mutex''.
20183
20184Reply:
20185@table @samp
20186@item @var{XX@dots{}}
20187Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
20188the printable string containing the extra information about the thread's
8e04817f 20189attributes.
ee2d5c50
AC
20190@end table
20191
20192@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 20193
8e04817f
AC
20194Obtain thread information from RTOS. Where: @var{startflag} (one hex
20195digit) is one to indicate the first query and zero to indicate a
20196subsequent query; @var{threadcount} (two hex digits) is the maximum
20197number of threads the response packet can contain; and @var{nextthread}
20198(eight hex digits), for subsequent queries (@var{startflag} is zero), is
20199returned in the response as @var{argthread}.
ee2d5c50
AC
20200
20201NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
20202(see above).
20203
20204Reply:
20205@table @samp
20206@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
20207Where: @var{count} (two hex digits) is the number of threads being
20208returned; @var{done} (one hex digit) is zero to indicate more threads
20209and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
20210digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
20211is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 20212digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 20213@end table
c906108c 20214
ee2d5c50
AC
20215@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
20216
20217Reply:
20218@table @samp
20219@item @code{E}@var{NN}
20220An error (such as memory fault)
20221@item @code{C}@var{CRC32}
20222A 32 bit cyclic redundancy check of the specified memory region.
20223@end table
20224
20225@item @code{q}@code{Offsets} --- query sect offs
c906108c 20226
8e04817f
AC
20227Get section offsets that the target used when re-locating the downloaded
20228image. @emph{Note: while a @code{Bss} offset is included in the
20229response, @value{GDBN} ignores this and instead applies the @code{Data}
20230offset to the @code{Bss} section.}
c906108c 20231
ee2d5c50
AC
20232Reply:
20233@table @samp
20234@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
20235@end table
20236
20237@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
20238
8e04817f
AC
20239Returns information on @var{threadid}. Where: @var{mode} is a hex
20240encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
20241
20242Reply:
20243@table @samp
20244@item *
20245@end table
20246
8e04817f 20247See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 20248
ee2d5c50
AC
20249@item @code{q}@code{Rcmd,}@var{command} --- remote command
20250
20251@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
20252execution. Invalid commands should be reported using the output string.
20253Before the final result packet, the target may also respond with a
ee2d5c50
AC
20254number of intermediate @code{O}@var{output} console output packets.
20255@emph{Implementors should note that providing access to a stubs's
20256interpreter may have security implications}.
20257
20258Reply:
20259@table @samp
20260@item OK
8e04817f 20261A command response with no output.
ee2d5c50 20262@item @var{OUTPUT}
8e04817f 20263A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 20264@item @code{E}@var{NN}
8e04817f 20265Indicate a badly formed request.
ee2d5c50 20266@item @samp{}
8e04817f 20267When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50
AC
20268@end table
20269
20270@item @code{qSymbol::} --- symbol lookup
c906108c 20271
8e04817f
AC
20272Notify the target that @value{GDBN} is prepared to serve symbol lookup
20273requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
20274
20275Reply:
20276@table @samp
20277@item @code{OK}
8e04817f 20278The target does not need to look up any (more) symbols.
ee2d5c50
AC
20279@item @code{qSymbol:}@var{sym_name}
20280The target requests the value of symbol @var{sym_name} (hex encoded).
20281@value{GDBN} may provide the value by using the
20282@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
20283@end table
20284
20285@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
20286
20287Set the value of @var{sym_name} to @var{sym_value}.
20288
20289@var{sym_name} (hex encoded) is the name of a symbol whose value the
20290target has previously requested.
20291
20292@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
20293@value{GDBN} cannot supply a value for @var{sym_name}, then this field
20294will be empty.
20295
20296Reply:
20297@table @samp
20298@item @code{OK}
8e04817f 20299The target does not need to look up any (more) symbols.
ee2d5c50
AC
20300@item @code{qSymbol:}@var{sym_name}
20301The target requests the value of a new symbol @var{sym_name} (hex
20302encoded). @value{GDBN} will continue to supply the values of symbols
20303(if available), until the target ceases to request them.
20304@end table
eb12ee30 20305
ee2d5c50
AC
20306@end table
20307
20308@node Register Packet Format
20309@section Register Packet Format
eb12ee30 20310
8e04817f 20311The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
20312In the below, some thirty-two bit registers are transferred as
20313sixty-four bits. Those registers should be zero/sign extended (which?)
20314to fill the space allocated. Register bytes are transfered in target
20315byte order. The two nibbles within a register byte are transfered
20316most-significant - least-significant.
eb12ee30 20317
ee2d5c50 20318@table @r
eb12ee30 20319
8e04817f 20320@item MIPS32
ee2d5c50 20321
8e04817f
AC
20322All registers are transfered as thirty-two bit quantities in the order:
2032332 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
20324registers; fsr; fir; fp.
eb12ee30 20325
8e04817f 20326@item MIPS64
ee2d5c50 20327
8e04817f
AC
20328All registers are transfered as sixty-four bit quantities (including
20329thirty-two bit registers such as @code{sr}). The ordering is the same
20330as @code{MIPS32}.
eb12ee30 20331
ee2d5c50
AC
20332@end table
20333
20334@node Examples
20335@section Examples
eb12ee30 20336
8e04817f
AC
20337Example sequence of a target being re-started. Notice how the restart
20338does not get any direct output:
eb12ee30 20339
474c8240 20340@smallexample
d2c6833e
AC
20341-> @code{R00}
20342<- @code{+}
8e04817f 20343@emph{target restarts}
d2c6833e 20344-> @code{?}
8e04817f 20345<- @code{+}
d2c6833e
AC
20346<- @code{T001:1234123412341234}
20347-> @code{+}
474c8240 20348@end smallexample
eb12ee30 20349
8e04817f 20350Example sequence of a target being stepped by a single instruction:
eb12ee30 20351
474c8240 20352@smallexample
d2c6833e 20353-> @code{G1445@dots{}}
8e04817f 20354<- @code{+}
d2c6833e
AC
20355-> @code{s}
20356<- @code{+}
20357@emph{time passes}
20358<- @code{T001:1234123412341234}
8e04817f 20359-> @code{+}
d2c6833e 20360-> @code{g}
8e04817f 20361<- @code{+}
d2c6833e
AC
20362<- @code{1455@dots{}}
20363-> @code{+}
474c8240 20364@end smallexample
eb12ee30 20365
0ce1b118
CV
20366@node File-I/O remote protocol extension
20367@section File-I/O remote protocol extension
20368@cindex File-I/O remote protocol extension
20369
20370@menu
20371* File-I/O Overview::
20372* Protocol basics::
20373* The `F' request packet::
20374* The `F' reply packet::
20375* Memory transfer::
20376* The Ctrl-C message::
20377* Console I/O::
20378* The isatty call::
20379* The system call::
20380* List of supported calls::
20381* Protocol specific representation of datatypes::
20382* Constants::
20383* File-I/O Examples::
20384@end menu
20385
20386@node File-I/O Overview
20387@subsection File-I/O Overview
20388@cindex file-i/o overview
20389
20390The File I/O remote protocol extension (short: File-I/O) allows the
20391target to use the hosts file system and console I/O when calling various
20392system calls. System calls on the target system are translated into a
20393remote protocol packet to the host system which then performs the needed
20394actions and returns with an adequate response packet to the target system.
20395This simulates file system operations even on targets that lack file systems.
20396
20397The protocol is defined host- and target-system independent. It uses
20398it's own independent representation of datatypes and values. Both,
20399@value{GDBN} and the target's @value{GDBN} stub are responsible for
20400translating the system dependent values into the unified protocol values
20401when data is transmitted.
20402
20403The communication is synchronous. A system call is possible only
20404when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
20405packets. While @value{GDBN} handles the request for a system call,
20406the target is stopped to allow deterministic access to the target's
20407memory. Therefore File-I/O is not interuptible by target signals. It
20408is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
20409
20410The target's request to perform a host system call does not finish
20411the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
20412after finishing the system call, the target returns to continuing the
20413previous activity (continue, step). No additional continue or step
20414request from @value{GDBN} is required.
20415
20416@smallexample
20417(gdb) continue
20418 <- target requests 'system call X'
20419 target is stopped, @value{GDBN} executes system call
20420 -> GDB returns result
20421 ... target continues, GDB returns to wait for the target
20422 <- target hits breakpoint and sends a Txx packet
20423@end smallexample
20424
20425The protocol is only used for files on the host file system and
20426for I/O on the console. Character or block special devices, pipes,
20427named pipes or sockets or any other communication method on the host
20428system are not supported by this protocol.
20429
20430@node Protocol basics
20431@subsection Protocol basics
20432@cindex protocol basics, file-i/o
20433
20434The File-I/O protocol uses the @code{F} packet, as request as well
20435as as reply packet. Since a File-I/O system call can only occur when
20436@value{GDBN} is waiting for the continuing or stepping target, the
20437File-I/O request is a reply that @value{GDBN} has to expect as a result
20438of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
20439This @code{F} packet contains all information needed to allow @value{GDBN}
20440to call the appropriate host system call:
20441
20442@itemize @bullet
20443@item
20444A unique identifier for the requested system call.
20445
20446@item
20447All parameters to the system call. Pointers are given as addresses
20448in the target memory address space. Pointers to strings are given as
20449pointer/length pair. Numerical values are given as they are.
20450Numerical control values are given in a protocol specific representation.
20451
20452@end itemize
20453
20454At that point @value{GDBN} has to perform the following actions.
20455
20456@itemize @bullet
20457@item
20458If parameter pointer values are given, which point to data needed as input
20459to a system call, @value{GDBN} requests this data from the target with a
20460standard @code{m} packet request. This additional communication has to be
20461expected by the target implementation and is handled as any other @code{m}
20462packet.
20463
20464@item
20465@value{GDBN} translates all value from protocol representation to host
20466representation as needed. Datatypes are coerced into the host types.
20467
20468@item
20469@value{GDBN} calls the system call
20470
20471@item
20472It then coerces datatypes back to protocol representation.
20473
20474@item
20475If pointer parameters in the request packet point to buffer space in which
20476a system call is expected to copy data to, the data is transmitted to the
20477target using a @code{M} or @code{X} packet. This packet has to be expected
20478by the target implementation and is handled as any other @code{M} or @code{X}
20479packet.
20480
20481@end itemize
20482
20483Eventually @value{GDBN} replies with another @code{F} packet which contains all
20484necessary information for the target to continue. This at least contains
20485
20486@itemize @bullet
20487@item
20488Return value.
20489
20490@item
20491@code{errno}, if has been changed by the system call.
20492
20493@item
20494``Ctrl-C'' flag.
20495
20496@end itemize
20497
20498After having done the needed type and value coercion, the target continues
20499the latest continue or step action.
20500
20501@node The `F' request packet
20502@subsection The @code{F} request packet
20503@cindex file-i/o request packet
20504@cindex @code{F} request packet
20505
20506The @code{F} request packet has the following format:
20507
20508@table @samp
20509
20510@smallexample
20511@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
20512@end smallexample
20513
20514@var{call-id} is the identifier to indicate the host system call to be called.
20515This is just the name of the function.
20516
20517@var{parameter@dots{}} are the parameters to the system call.
20518
20519@end table
20520
20521Parameters are hexadecimal integer values, either the real values in case
20522of scalar datatypes, as pointers to target buffer space in case of compound
20523datatypes and unspecified memory areas or as pointer/length pairs in case
20524of string parameters. These are appended to the call-id, each separated
20525from its predecessor by a comma. All values are transmitted in ASCII
20526string representation, pointer/length pairs separated by a slash.
20527
20528@node The `F' reply packet
20529@subsection The @code{F} reply packet
20530@cindex file-i/o reply packet
20531@cindex @code{F} reply packet
20532
20533The @code{F} reply packet has the following format:
20534
20535@table @samp
20536
20537@smallexample
20538@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
20539@end smallexample
20540
20541@var{retcode} is the return code of the system call as hexadecimal value.
20542
20543@var{errno} is the errno set by the call, in protocol specific representation.
20544This parameter can be omitted if the call was successful.
20545
20546@var{Ctrl-C flag} is only send if the user requested a break. In this
20547case, @var{errno} must be send as well, even if the call was successful.
20548The @var{Ctrl-C flag} itself consists of the character 'C':
20549
20550@smallexample
20551F0,0,C
20552@end smallexample
20553
20554@noindent
20555or, if the call was interupted before the host call has been performed:
20556
20557@smallexample
20558F-1,4,C
20559@end smallexample
20560
20561@noindent
20562assuming 4 is the protocol specific representation of @code{EINTR}.
20563
20564@end table
20565
20566@node Memory transfer
20567@subsection Memory transfer
20568@cindex memory transfer, in file-i/o protocol
20569
20570Structured data which is transferred using a memory read or write as e.g.@:
20571a @code{struct stat} is expected to be in a protocol specific format with
20572all scalar multibyte datatypes being big endian. This should be done by
20573the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
20574it transfers memory to the target. Transferred pointers to structured
20575data should point to the already coerced data at any time.
20576
20577@node The Ctrl-C message
20578@subsection The Ctrl-C message
20579@cindex ctrl-c message, in file-i/o protocol
20580
20581A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
20582reply packet. In this case the target should behave, as if it had
20583gotten a break message. The meaning for the target is ``system call
20584interupted by @code{SIGINT}''. Consequentially, the target should actually stop
20585(as with a break message) and return to @value{GDBN} with a @code{T02}
20586packet. In this case, it's important for the target to know, in which
20587state the system call was interrupted. Since this action is by design
20588not an atomic operation, we have to differ between two cases:
20589
20590@itemize @bullet
20591@item
20592The system call hasn't been performed on the host yet.
20593
20594@item
20595The system call on the host has been finished.
20596
20597@end itemize
20598
20599These two states can be distinguished by the target by the value of the
20600returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
20601call hasn't been performed. This is equivalent to the @code{EINTR} handling
20602on POSIX systems. In any other case, the target may presume that the
20603system call has been finished --- successful or not --- and should behave
20604as if the break message arrived right after the system call.
20605
20606@value{GDBN} must behave reliable. If the system call has not been called
20607yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
20608@code{errno} in the packet. If the system call on the host has been finished
20609before the user requests a break, the full action must be finshed by
20610@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
20611The @code{F} packet may only be send when either nothing has happened
20612or the full action has been completed.
20613
20614@node Console I/O
20615@subsection Console I/O
20616@cindex console i/o as part of file-i/o
20617
20618By default and if not explicitely closed by the target system, the file
20619descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
20620on the @value{GDBN} console is handled as any other file output operation
20621(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
20622by @value{GDBN} so that after the target read request from file descriptor
206230 all following typing is buffered until either one of the following
20624conditions is met:
20625
20626@itemize @bullet
20627@item
20628The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
20629@code{read}
20630system call is treated as finished.
20631
20632@item
20633The user presses @kbd{Enter}. This is treated as end of input with a trailing
20634line feed.
20635
20636@item
20637The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
20638character, especially no Ctrl-D is appended to the input.
20639
20640@end itemize
20641
20642If the user has typed more characters as fit in the buffer given to
20643the read call, the trailing characters are buffered in @value{GDBN} until
20644either another @code{read(0, @dots{})} is requested by the target or debugging
20645is stopped on users request.
20646
20647@node The isatty call
20648@subsection The isatty(3) call
20649@cindex isatty call, file-i/o protocol
20650
20651A special case in this protocol is the library call @code{isatty} which
20652is implemented as it's own call inside of this protocol. It returns
206531 to the target if the file descriptor given as parameter is attached
20654to the @value{GDBN} console, 0 otherwise. Implementing through system calls
20655would require implementing @code{ioctl} and would be more complex than
20656needed.
20657
20658@node The system call
20659@subsection The system(3) call
20660@cindex system call, file-i/o protocol
20661
20662The other special case in this protocol is the @code{system} call which
20663is implemented as it's own call, too. @value{GDBN} is taking over the full
20664task of calling the necessary host calls to perform the @code{system}
20665call. The return value of @code{system} is simplified before it's returned
20666to the target. Basically, the only signal transmitted back is @code{EINTR}
20667in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
20668entirely of the exit status of the called command.
20669
20670Due to security concerns, the @code{system} call is refused to be called
20671by @value{GDBN} by default. The user has to allow this call explicitly by
20672entering
20673
20674@table @samp
20675@kindex set remote system-call-allowed 1
20676@item @code{set remote system-call-allowed 1}
20677@end table
20678
20679Disabling the @code{system} call is done by
20680
20681@table @samp
20682@kindex set remote system-call-allowed 0
20683@item @code{set remote system-call-allowed 0}
20684@end table
20685
20686The current setting is shown by typing
20687
20688@table @samp
20689@kindex show remote system-call-allowed
20690@item @code{show remote system-call-allowed}
20691@end table
20692
20693@node List of supported calls
20694@subsection List of supported calls
20695@cindex list of supported file-i/o calls
20696
20697@menu
20698* open::
20699* close::
20700* read::
20701* write::
20702* lseek::
20703* rename::
20704* unlink::
20705* stat/fstat::
20706* gettimeofday::
20707* isatty::
20708* system::
20709@end menu
20710
20711@node open
20712@unnumberedsubsubsec open
20713@cindex open, file-i/o system call
20714
20715@smallexample
20716@exdent Synopsis:
20717int open(const char *pathname, int flags);
20718int open(const char *pathname, int flags, mode_t mode);
20719
20720@exdent Request:
20721Fopen,pathptr/len,flags,mode
20722@end smallexample
20723
20724@noindent
20725@code{flags} is the bitwise or of the following values:
20726
20727@table @code
20728@item O_CREAT
20729If the file does not exist it will be created. The host
20730rules apply as far as file ownership and time stamps
20731are concerned.
20732
20733@item O_EXCL
20734When used with O_CREAT, if the file already exists it is
20735an error and open() fails.
20736
20737@item O_TRUNC
20738If the file already exists and the open mode allows
20739writing (O_RDWR or O_WRONLY is given) it will be
20740truncated to length 0.
20741
20742@item O_APPEND
20743The file is opened in append mode.
20744
20745@item O_RDONLY
20746The file is opened for reading only.
20747
20748@item O_WRONLY
20749The file is opened for writing only.
20750
20751@item O_RDWR
20752The file is opened for reading and writing.
20753
20754@noindent
20755Each other bit is silently ignored.
20756
20757@end table
20758
20759@noindent
20760@code{mode} is the bitwise or of the following values:
20761
20762@table @code
20763@item S_IRUSR
20764User has read permission.
20765
20766@item S_IWUSR
20767User has write permission.
20768
20769@item S_IRGRP
20770Group has read permission.
20771
20772@item S_IWGRP
20773Group has write permission.
20774
20775@item S_IROTH
20776Others have read permission.
20777
20778@item S_IWOTH
20779Others have write permission.
20780
20781@noindent
20782Each other bit is silently ignored.
20783
20784@end table
20785
20786@smallexample
20787@exdent Return value:
20788open returns the new file descriptor or -1 if an error
20789occured.
20790
20791@exdent Errors:
20792@end smallexample
20793
20794@table @code
20795@item EEXIST
20796pathname already exists and O_CREAT and O_EXCL were used.
20797
20798@item EISDIR
20799pathname refers to a directory.
20800
20801@item EACCES
20802The requested access is not allowed.
20803
20804@item ENAMETOOLONG
20805pathname was too long.
20806
20807@item ENOENT
20808A directory component in pathname does not exist.
20809
20810@item ENODEV
20811pathname refers to a device, pipe, named pipe or socket.
20812
20813@item EROFS
20814pathname refers to a file on a read-only filesystem and
20815write access was requested.
20816
20817@item EFAULT
20818pathname is an invalid pointer value.
20819
20820@item ENOSPC
20821No space on device to create the file.
20822
20823@item EMFILE
20824The process already has the maximum number of files open.
20825
20826@item ENFILE
20827The limit on the total number of files open on the system
20828has been reached.
20829
20830@item EINTR
20831The call was interrupted by the user.
20832@end table
20833
20834@node close
20835@unnumberedsubsubsec close
20836@cindex close, file-i/o system call
20837
20838@smallexample
20839@exdent Synopsis:
20840int close(int fd);
20841
20842@exdent Request:
20843Fclose,fd
20844
20845@exdent Return value:
20846close returns zero on success, or -1 if an error occurred.
20847
20848@exdent Errors:
20849@end smallexample
20850
20851@table @code
20852@item EBADF
20853fd isn't a valid open file descriptor.
20854
20855@item EINTR
20856The call was interrupted by the user.
20857@end table
20858
20859@node read
20860@unnumberedsubsubsec read
20861@cindex read, file-i/o system call
20862
20863@smallexample
20864@exdent Synopsis:
20865int read(int fd, void *buf, unsigned int count);
20866
20867@exdent Request:
20868Fread,fd,bufptr,count
20869
20870@exdent Return value:
20871On success, the number of bytes read is returned.
20872Zero indicates end of file. If count is zero, read
20873returns zero as well. On error, -1 is returned.
20874
20875@exdent Errors:
20876@end smallexample
20877
20878@table @code
20879@item EBADF
20880fd is not a valid file descriptor or is not open for
20881reading.
20882
20883@item EFAULT
20884buf is an invalid pointer value.
20885
20886@item EINTR
20887The call was interrupted by the user.
20888@end table
20889
20890@node write
20891@unnumberedsubsubsec write
20892@cindex write, file-i/o system call
20893
20894@smallexample
20895@exdent Synopsis:
20896int write(int fd, const void *buf, unsigned int count);
20897
20898@exdent Request:
20899Fwrite,fd,bufptr,count
20900
20901@exdent Return value:
20902On success, the number of bytes written are returned.
20903Zero indicates nothing was written. On error, -1
20904is returned.
20905
20906@exdent Errors:
20907@end smallexample
20908
20909@table @code
20910@item EBADF
20911fd is not a valid file descriptor or is not open for
20912writing.
20913
20914@item EFAULT
20915buf is an invalid pointer value.
20916
20917@item EFBIG
20918An attempt was made to write a file that exceeds the
20919host specific maximum file size allowed.
20920
20921@item ENOSPC
20922No space on device to write the data.
20923
20924@item EINTR
20925The call was interrupted by the user.
20926@end table
20927
20928@node lseek
20929@unnumberedsubsubsec lseek
20930@cindex lseek, file-i/o system call
20931
20932@smallexample
20933@exdent Synopsis:
20934long lseek (int fd, long offset, int flag);
20935
20936@exdent Request:
20937Flseek,fd,offset,flag
20938@end smallexample
20939
20940@code{flag} is one of:
20941
20942@table @code
20943@item SEEK_SET
20944The offset is set to offset bytes.
20945
20946@item SEEK_CUR
20947The offset is set to its current location plus offset
20948bytes.
20949
20950@item SEEK_END
20951The offset is set to the size of the file plus offset
20952bytes.
20953@end table
20954
20955@smallexample
20956@exdent Return value:
20957On success, the resulting unsigned offset in bytes from
20958the beginning of the file is returned. Otherwise, a
20959value of -1 is returned.
20960
20961@exdent Errors:
20962@end smallexample
20963
20964@table @code
20965@item EBADF
20966fd is not a valid open file descriptor.
20967
20968@item ESPIPE
20969fd is associated with the @value{GDBN} console.
20970
20971@item EINVAL
20972flag is not a proper value.
20973
20974@item EINTR
20975The call was interrupted by the user.
20976@end table
20977
20978@node rename
20979@unnumberedsubsubsec rename
20980@cindex rename, file-i/o system call
20981
20982@smallexample
20983@exdent Synopsis:
20984int rename(const char *oldpath, const char *newpath);
20985
20986@exdent Request:
20987Frename,oldpathptr/len,newpathptr/len
20988
20989@exdent Return value:
20990On success, zero is returned. On error, -1 is returned.
20991
20992@exdent Errors:
20993@end smallexample
20994
20995@table @code
20996@item EISDIR
20997newpath is an existing directory, but oldpath is not a
20998directory.
20999
21000@item EEXIST
21001newpath is a non-empty directory.
21002
21003@item EBUSY
21004oldpath or newpath is a directory that is in use by some
21005process.
21006
21007@item EINVAL
21008An attempt was made to make a directory a subdirectory
21009of itself.
21010
21011@item ENOTDIR
21012A component used as a directory in oldpath or new
21013path is not a directory. Or oldpath is a directory
21014and newpath exists but is not a directory.
21015
21016@item EFAULT
21017oldpathptr or newpathptr are invalid pointer values.
21018
21019@item EACCES
21020No access to the file or the path of the file.
21021
21022@item ENAMETOOLONG
21023
21024oldpath or newpath was too long.
21025
21026@item ENOENT
21027A directory component in oldpath or newpath does not exist.
21028
21029@item EROFS
21030The file is on a read-only filesystem.
21031
21032@item ENOSPC
21033The device containing the file has no room for the new
21034directory entry.
21035
21036@item EINTR
21037The call was interrupted by the user.
21038@end table
21039
21040@node unlink
21041@unnumberedsubsubsec unlink
21042@cindex unlink, file-i/o system call
21043
21044@smallexample
21045@exdent Synopsis:
21046int unlink(const char *pathname);
21047
21048@exdent Request:
21049Funlink,pathnameptr/len
21050
21051@exdent Return value:
21052On success, zero is returned. On error, -1 is returned.
21053
21054@exdent Errors:
21055@end smallexample
21056
21057@table @code
21058@item EACCES
21059No access to the file or the path of the file.
21060
21061@item EPERM
21062The system does not allow unlinking of directories.
21063
21064@item EBUSY
21065The file pathname cannot be unlinked because it's
21066being used by another process.
21067
21068@item EFAULT
21069pathnameptr is an invalid pointer value.
21070
21071@item ENAMETOOLONG
21072pathname was too long.
21073
21074@item ENOENT
21075A directory component in pathname does not exist.
21076
21077@item ENOTDIR
21078A component of the path is not a directory.
21079
21080@item EROFS
21081The file is on a read-only filesystem.
21082
21083@item EINTR
21084The call was interrupted by the user.
21085@end table
21086
21087@node stat/fstat
21088@unnumberedsubsubsec stat/fstat
21089@cindex fstat, file-i/o system call
21090@cindex stat, file-i/o system call
21091
21092@smallexample
21093@exdent Synopsis:
21094int stat(const char *pathname, struct stat *buf);
21095int fstat(int fd, struct stat *buf);
21096
21097@exdent Request:
21098Fstat,pathnameptr/len,bufptr
21099Ffstat,fd,bufptr
21100
21101@exdent Return value:
21102On success, zero is returned. On error, -1 is returned.
21103
21104@exdent Errors:
21105@end smallexample
21106
21107@table @code
21108@item EBADF
21109fd is not a valid open file.
21110
21111@item ENOENT
21112A directory component in pathname does not exist or the
21113path is an empty string.
21114
21115@item ENOTDIR
21116A component of the path is not a directory.
21117
21118@item EFAULT
21119pathnameptr is an invalid pointer value.
21120
21121@item EACCES
21122No access to the file or the path of the file.
21123
21124@item ENAMETOOLONG
21125pathname was too long.
21126
21127@item EINTR
21128The call was interrupted by the user.
21129@end table
21130
21131@node gettimeofday
21132@unnumberedsubsubsec gettimeofday
21133@cindex gettimeofday, file-i/o system call
21134
21135@smallexample
21136@exdent Synopsis:
21137int gettimeofday(struct timeval *tv, void *tz);
21138
21139@exdent Request:
21140Fgettimeofday,tvptr,tzptr
21141
21142@exdent Return value:
21143On success, 0 is returned, -1 otherwise.
21144
21145@exdent Errors:
21146@end smallexample
21147
21148@table @code
21149@item EINVAL
21150tz is a non-NULL pointer.
21151
21152@item EFAULT
21153tvptr and/or tzptr is an invalid pointer value.
21154@end table
21155
21156@node isatty
21157@unnumberedsubsubsec isatty
21158@cindex isatty, file-i/o system call
21159
21160@smallexample
21161@exdent Synopsis:
21162int isatty(int fd);
21163
21164@exdent Request:
21165Fisatty,fd
21166
21167@exdent Return value:
21168Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
21169
21170@exdent Errors:
21171@end smallexample
21172
21173@table @code
21174@item EINTR
21175The call was interrupted by the user.
21176@end table
21177
21178@node system
21179@unnumberedsubsubsec system
21180@cindex system, file-i/o system call
21181
21182@smallexample
21183@exdent Synopsis:
21184int system(const char *command);
21185
21186@exdent Request:
21187Fsystem,commandptr/len
21188
21189@exdent Return value:
21190The value returned is -1 on error and the return status
21191of the command otherwise. Only the exit status of the
21192command is returned, which is extracted from the hosts
21193system return value by calling WEXITSTATUS(retval).
21194In case /bin/sh could not be executed, 127 is returned.
21195
21196@exdent Errors:
21197@end smallexample
21198
21199@table @code
21200@item EINTR
21201The call was interrupted by the user.
21202@end table
21203
21204@node Protocol specific representation of datatypes
21205@subsection Protocol specific representation of datatypes
21206@cindex protocol specific representation of datatypes, in file-i/o protocol
21207
21208@menu
21209* Integral datatypes::
21210* Pointer values::
21211* struct stat::
21212* struct timeval::
21213@end menu
21214
21215@node Integral datatypes
21216@unnumberedsubsubsec Integral datatypes
21217@cindex integral datatypes, in file-i/o protocol
21218
21219The integral datatypes used in the system calls are
21220
21221@smallexample
21222int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
21223@end smallexample
21224
21225@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
21226implemented as 32 bit values in this protocol.
21227
21228@code{Long} and @code{unsigned long} are implemented as 64 bit types.
21229
21230@xref{Limits}, for corresponding MIN and MAX values (similar to those
21231in @file{limits.h}) to allow range checking on host and target.
21232
21233@code{time_t} datatypes are defined as seconds since the Epoch.
21234
21235All integral datatypes transferred as part of a memory read or write of a
21236structured datatype e.g.@: a @code{struct stat} have to be given in big endian
21237byte order.
21238
21239@node Pointer values
21240@unnumberedsubsubsec Pointer values
21241@cindex pointer values, in file-i/o protocol
21242
21243Pointers to target data are transmitted as they are. An exception
21244is made for pointers to buffers for which the length isn't
21245transmitted as part of the function call, namely strings. Strings
21246are transmitted as a pointer/length pair, both as hex values, e.g.@:
21247
21248@smallexample
21249@code{1aaf/12}
21250@end smallexample
21251
21252@noindent
21253which is a pointer to data of length 18 bytes at position 0x1aaf.
21254The length is defined as the full string length in bytes, including
21255the trailing null byte. Example:
21256
21257@smallexample
21258``hello, world'' at address 0x123456
21259@end smallexample
21260
21261@noindent
21262is transmitted as
21263
21264@smallexample
21265@code{123456/d}
21266@end smallexample
21267
21268@node struct stat
21269@unnumberedsubsubsec struct stat
21270@cindex struct stat, in file-i/o protocol
21271
21272The buffer of type struct stat used by the target and @value{GDBN} is defined
21273as follows:
21274
21275@smallexample
21276struct stat @{
21277 unsigned int st_dev; /* device */
21278 unsigned int st_ino; /* inode */
21279 mode_t st_mode; /* protection */
21280 unsigned int st_nlink; /* number of hard links */
21281 unsigned int st_uid; /* user ID of owner */
21282 unsigned int st_gid; /* group ID of owner */
21283 unsigned int st_rdev; /* device type (if inode device) */
21284 unsigned long st_size; /* total size, in bytes */
21285 unsigned long st_blksize; /* blocksize for filesystem I/O */
21286 unsigned long st_blocks; /* number of blocks allocated */
21287 time_t st_atime; /* time of last access */
21288 time_t st_mtime; /* time of last modification */
21289 time_t st_ctime; /* time of last change */
21290@};
21291@end smallexample
21292
21293The integral datatypes are conforming to the definitions given in the
21294approriate section (see @ref{Integral datatypes}, for details) so this
21295structure is of size 64 bytes.
21296
21297The values of several fields have a restricted meaning and/or
21298range of values.
21299
21300@smallexample
21301st_dev: 0 file
21302 1 console
21303
21304st_ino: No valid meaning for the target. Transmitted unchanged.
21305
21306st_mode: Valid mode bits are described in Appendix C. Any other
21307 bits have currently no meaning for the target.
21308
21309st_uid: No valid meaning for the target. Transmitted unchanged.
21310
21311st_gid: No valid meaning for the target. Transmitted unchanged.
21312
21313st_rdev: No valid meaning for the target. Transmitted unchanged.
21314
21315st_atime, st_mtime, st_ctime:
21316 These values have a host and file system dependent
21317 accuracy. Especially on Windows hosts the file systems
21318 don't support exact timing values.
21319@end smallexample
21320
21321The target gets a struct stat of the above representation and is
21322responsible to coerce it to the target representation before
21323continuing.
21324
21325Note that due to size differences between the host and target
21326representation of stat members, these members could eventually
21327get truncated on the target.
21328
21329@node struct timeval
21330@unnumberedsubsubsec struct timeval
21331@cindex struct timeval, in file-i/o protocol
21332
21333The buffer of type struct timeval used by the target and @value{GDBN}
21334is defined as follows:
21335
21336@smallexample
21337struct timeval @{
21338 time_t tv_sec; /* second */
21339 long tv_usec; /* microsecond */
21340@};
21341@end smallexample
21342
21343The integral datatypes are conforming to the definitions given in the
21344approriate section (see @ref{Integral datatypes}, for details) so this
21345structure is of size 8 bytes.
21346
21347@node Constants
21348@subsection Constants
21349@cindex constants, in file-i/o protocol
21350
21351The following values are used for the constants inside of the
21352protocol. @value{GDBN} and target are resposible to translate these
21353values before and after the call as needed.
21354
21355@menu
21356* Open flags::
21357* mode_t values::
21358* Errno values::
21359* Lseek flags::
21360* Limits::
21361@end menu
21362
21363@node Open flags
21364@unnumberedsubsubsec Open flags
21365@cindex open flags, in file-i/o protocol
21366
21367All values are given in hexadecimal representation.
21368
21369@smallexample
21370 O_RDONLY 0x0
21371 O_WRONLY 0x1
21372 O_RDWR 0x2
21373 O_APPEND 0x8
21374 O_CREAT 0x200
21375 O_TRUNC 0x400
21376 O_EXCL 0x800
21377@end smallexample
21378
21379@node mode_t values
21380@unnumberedsubsubsec mode_t values
21381@cindex mode_t values, in file-i/o protocol
21382
21383All values are given in octal representation.
21384
21385@smallexample
21386 S_IFREG 0100000
21387 S_IFDIR 040000
21388 S_IRUSR 0400
21389 S_IWUSR 0200
21390 S_IXUSR 0100
21391 S_IRGRP 040
21392 S_IWGRP 020
21393 S_IXGRP 010
21394 S_IROTH 04
21395 S_IWOTH 02
21396 S_IXOTH 01
21397@end smallexample
21398
21399@node Errno values
21400@unnumberedsubsubsec Errno values
21401@cindex errno values, in file-i/o protocol
21402
21403All values are given in decimal representation.
21404
21405@smallexample
21406 EPERM 1
21407 ENOENT 2
21408 EINTR 4
21409 EBADF 9
21410 EACCES 13
21411 EFAULT 14
21412 EBUSY 16
21413 EEXIST 17
21414 ENODEV 19
21415 ENOTDIR 20
21416 EISDIR 21
21417 EINVAL 22
21418 ENFILE 23
21419 EMFILE 24
21420 EFBIG 27
21421 ENOSPC 28
21422 ESPIPE 29
21423 EROFS 30
21424 ENAMETOOLONG 91
21425 EUNKNOWN 9999
21426@end smallexample
21427
21428 EUNKNOWN is used as a fallback error value if a host system returns
21429 any error value not in the list of supported error numbers.
21430
21431@node Lseek flags
21432@unnumberedsubsubsec Lseek flags
21433@cindex lseek flags, in file-i/o protocol
21434
21435@smallexample
21436 SEEK_SET 0
21437 SEEK_CUR 1
21438 SEEK_END 2
21439@end smallexample
21440
21441@node Limits
21442@unnumberedsubsubsec Limits
21443@cindex limits, in file-i/o protocol
21444
21445All values are given in decimal representation.
21446
21447@smallexample
21448 INT_MIN -2147483648
21449 INT_MAX 2147483647
21450 UINT_MAX 4294967295
21451 LONG_MIN -9223372036854775808
21452 LONG_MAX 9223372036854775807
21453 ULONG_MAX 18446744073709551615
21454@end smallexample
21455
21456@node File-I/O Examples
21457@subsection File-I/O Examples
21458@cindex file-i/o examples
21459
21460Example sequence of a write call, file descriptor 3, buffer is at target
21461address 0x1234, 6 bytes should be written:
21462
21463@smallexample
21464<- @code{Fwrite,3,1234,6}
21465@emph{request memory read from target}
21466-> @code{m1234,6}
21467<- XXXXXX
21468@emph{return "6 bytes written"}
21469-> @code{F6}
21470@end smallexample
21471
21472Example sequence of a read call, file descriptor 3, buffer is at target
21473address 0x1234, 6 bytes should be read:
21474
21475@smallexample
21476<- @code{Fread,3,1234,6}
21477@emph{request memory write to target}
21478-> @code{X1234,6:XXXXXX}
21479@emph{return "6 bytes read"}
21480-> @code{F6}
21481@end smallexample
21482
21483Example sequence of a read call, call fails on the host due to invalid
21484file descriptor (EBADF):
21485
21486@smallexample
21487<- @code{Fread,3,1234,6}
21488-> @code{F-1,9}
21489@end smallexample
21490
21491Example sequence of a read call, user presses Ctrl-C before syscall on
21492host is called:
21493
21494@smallexample
21495<- @code{Fread,3,1234,6}
21496-> @code{F-1,4,C}
21497<- @code{T02}
21498@end smallexample
21499
21500Example sequence of a read call, user presses Ctrl-C after syscall on
21501host is called:
21502
21503@smallexample
21504<- @code{Fread,3,1234,6}
21505-> @code{X1234,6:XXXXXX}
21506<- @code{T02}
21507@end smallexample
21508
f418dd93
DJ
21509@include agentexpr.texi
21510
aab4e0ec 21511@include gpl.texi
eb12ee30 21512
6826cf00
EZ
21513@include fdl.texi
21514
6d2ebf8b 21515@node Index
c906108c
SS
21516@unnumbered Index
21517
21518@printindex cp
21519
21520@tex
21521% I think something like @colophon should be in texinfo. In the
21522% meantime:
21523\long\def\colophon{\hbox to0pt{}\vfill
21524\centerline{The body of this manual is set in}
21525\centerline{\fontname\tenrm,}
21526\centerline{with headings in {\bf\fontname\tenbf}}
21527\centerline{and examples in {\tt\fontname\tentt}.}
21528\centerline{{\it\fontname\tenit\/},}
21529\centerline{{\bf\fontname\tenbf}, and}
21530\centerline{{\sl\fontname\tensl\/}}
21531\centerline{are used for emphasis.}\vfill}
21532\page\colophon
21533% Blame: doc@cygnus.com, 1991.
21534@end tex
21535
c906108c 21536@bye
This page took 1.91395 seconds and 4 git commands to generate.